]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #1120 from donaldsharp/branch_million
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
718e3744 37
38#include "bgpd/bgpd.h"
4bf6a362 39#include "bgpd/bgp_advertise.h"
718e3744 40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_aspath.h"
42#include "bgpd/bgp_community.h"
4bf6a362 43#include "bgpd/bgp_ecommunity.h"
57d187bc 44#include "bgpd/bgp_lcommunity.h"
4bf6a362 45#include "bgpd/bgp_damp.h"
718e3744 46#include "bgpd/bgp_debug.h"
e0701b79 47#include "bgpd/bgp_fsm.h"
4bf6a362 48#include "bgpd/bgp_nexthop.h"
718e3744 49#include "bgpd/bgp_open.h"
4bf6a362 50#include "bgpd/bgp_regex.h"
718e3744 51#include "bgpd/bgp_route.h"
c016b6c7 52#include "bgpd/bgp_mplsvpn.h"
718e3744 53#include "bgpd/bgp_zebra.h"
fee0f4c6 54#include "bgpd/bgp_table.h"
94f2b392 55#include "bgpd/bgp_vty.h"
165b5fff 56#include "bgpd/bgp_mpath.h"
cb1faec9 57#include "bgpd/bgp_packet.h"
3f9c7369 58#include "bgpd/bgp_updgrp.h"
c43ed2e4 59#include "bgpd/bgp_bfd.h"
718e3744 60
d62a17ae 61static struct peer_group *listen_range_exists(struct bgp *bgp,
62 struct prefix *range, int exact);
63
64static enum node_type bgp_node_type(afi_t afi, safi_t safi)
65{
66 switch (afi) {
67 case AFI_IP:
68 switch (safi) {
69 case SAFI_UNICAST:
70 return BGP_IPV4_NODE;
71 break;
72 case SAFI_MULTICAST:
73 return BGP_IPV4M_NODE;
74 break;
75 case SAFI_LABELED_UNICAST:
76 return BGP_IPV4L_NODE;
77 break;
78 case SAFI_MPLS_VPN:
79 return BGP_VPNV4_NODE;
80 break;
5c525538
RW
81 default:
82 /* not expected */
83 return BGP_IPV4_NODE;
84 break;
d62a17ae 85 }
86 break;
87 case AFI_IP6:
88 switch (safi) {
89 case SAFI_UNICAST:
90 return BGP_IPV6_NODE;
91 break;
92 case SAFI_MULTICAST:
93 return BGP_IPV6M_NODE;
94 break;
95 case SAFI_LABELED_UNICAST:
96 return BGP_IPV6L_NODE;
97 break;
98 case SAFI_MPLS_VPN:
99 return BGP_VPNV6_NODE;
100 break;
5c525538
RW
101 default:
102 /* not expected */
103 return BGP_IPV4_NODE;
104 break;
d62a17ae 105 }
106 break;
107 case AFI_L2VPN:
108 return BGP_EVPN_NODE;
109 break;
110 case AFI_MAX:
111 // We should never be here but to clarify the switch statement..
112 return BGP_IPV4_NODE;
113 break;
114 }
115
116 // Impossible to happen
117 return BGP_IPV4_NODE;
f51bae9c 118}
20eb8864 119
718e3744 120/* Utility function to get address family from current node. */
d62a17ae 121afi_t bgp_node_afi(struct vty *vty)
122{
123 afi_t afi;
124 switch (vty->node) {
125 case BGP_IPV6_NODE:
126 case BGP_IPV6M_NODE:
127 case BGP_IPV6L_NODE:
128 case BGP_VPNV6_NODE:
129 afi = AFI_IP6;
130 break;
131 case BGP_EVPN_NODE:
132 afi = AFI_L2VPN;
133 break;
134 default:
135 afi = AFI_IP;
136 break;
137 }
138 return afi;
718e3744 139}
140
141/* Utility function to get subsequent address family from current
142 node. */
d62a17ae 143safi_t bgp_node_safi(struct vty *vty)
144{
145 safi_t safi;
146 switch (vty->node) {
147 case BGP_VPNV4_NODE:
148 case BGP_VPNV6_NODE:
149 safi = SAFI_MPLS_VPN;
150 break;
151 case BGP_IPV4M_NODE:
152 case BGP_IPV6M_NODE:
153 safi = SAFI_MULTICAST;
154 break;
155 case BGP_EVPN_NODE:
156 safi = SAFI_EVPN;
157 break;
158 case BGP_IPV4L_NODE:
159 case BGP_IPV6L_NODE:
160 safi = SAFI_LABELED_UNICAST;
161 break;
162 default:
163 safi = SAFI_UNICAST;
164 break;
165 }
166 return safi;
718e3744 167}
168
55f91488
QY
169/**
170 * Converts an AFI in string form to afi_t
171 *
172 * @param afi string, one of
173 * - "ipv4"
174 * - "ipv6"
175 * @return the corresponding afi_t
176 */
d62a17ae 177afi_t bgp_vty_afi_from_str(const char *afi_str)
178{
179 afi_t afi = AFI_MAX; /* unknown */
180 if (strmatch(afi_str, "ipv4"))
181 afi = AFI_IP;
182 else if (strmatch(afi_str, "ipv6"))
183 afi = AFI_IP6;
184 return afi;
185}
186
187int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
188 afi_t *afi)
189{
190 int ret = 0;
191 if (argv_find(argv, argc, "ipv4", index)) {
192 ret = 1;
193 if (afi)
194 *afi = AFI_IP;
195 } else if (argv_find(argv, argc, "ipv6", index)) {
196 ret = 1;
197 if (afi)
198 *afi = AFI_IP6;
199 }
200 return ret;
46f296b4
LB
201}
202
375a2e67 203/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 204safi_t bgp_vty_safi_from_str(const char *safi_str)
205{
206 safi_t safi = SAFI_MAX; /* unknown */
207 if (strmatch(safi_str, "multicast"))
208 safi = SAFI_MULTICAST;
209 else if (strmatch(safi_str, "unicast"))
210 safi = SAFI_UNICAST;
211 else if (strmatch(safi_str, "vpn"))
212 safi = SAFI_MPLS_VPN;
213 else if (strmatch(safi_str, "labeled-unicast"))
214 safi = SAFI_LABELED_UNICAST;
215 return safi;
216}
217
218int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
219 safi_t *safi)
220{
221 int ret = 0;
222 if (argv_find(argv, argc, "unicast", index)) {
223 ret = 1;
224 if (safi)
225 *safi = SAFI_UNICAST;
226 } else if (argv_find(argv, argc, "multicast", index)) {
227 ret = 1;
228 if (safi)
229 *safi = SAFI_MULTICAST;
230 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
231 ret = 1;
232 if (safi)
233 *safi = SAFI_LABELED_UNICAST;
234 } else if (argv_find(argv, argc, "vpn", index)) {
235 ret = 1;
236 if (safi)
237 *safi = SAFI_MPLS_VPN;
238 }
239 return ret;
46f296b4
LB
240}
241
7eeee51e 242/*
f212a857 243 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 244 *
f212a857
DS
245 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
246 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
247 * to appropriate values for the calling function. This is to allow the
248 * calling function to make decisions appropriate for the show command
249 * that is being parsed.
250 *
251 * The show commands are generally of the form:
d62a17ae 252 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
253 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
254 *
255 * Since we use argv_find if the show command in particular doesn't have:
256 * [ip]
18c57037 257 * [<view|vrf> VIEWVRFNAME]
375a2e67 258 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
259 * The command parsing should still be ok.
260 *
261 * vty -> The vty for the command so we can output some useful data in
262 * the event of a parse error in the vrf.
263 * argv -> The command tokens
264 * argc -> How many command tokens we have
d62a17ae 265 * idx -> The current place in the command, generally should be 0 for this
266 * function
7eeee51e
DS
267 * afi -> The parsed afi if it was included in the show command, returned here
268 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 269 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
270 *
271 * The function returns the correct location in the parse tree for the
272 * last token found.
0e37c258
DS
273 *
274 * Returns 0 for failure to parse correctly, else the idx position of where
275 * it found the last token.
7eeee51e 276 */
d62a17ae 277int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
278 struct cmd_token **argv, int argc,
279 int *idx, afi_t *afi, safi_t *safi,
280 struct bgp **bgp)
281{
282 char *vrf_name = NULL;
283
284 assert(afi);
285 assert(safi);
286 assert(bgp);
287
288 if (argv_find(argv, argc, "ip", idx))
289 *afi = AFI_IP;
290
291 if (argv_find(argv, argc, "view", idx)
292 || argv_find(argv, argc, "vrf", idx)) {
293 vrf_name = argv[*idx + 1]->arg;
294
295 if (strmatch(vrf_name, "all"))
296 *bgp = NULL;
297 else {
298 *bgp = bgp_lookup_by_name(vrf_name);
299 if (!*bgp) {
300 vty_out(vty,
301 "View/Vrf specified is unknown: %s\n",
302 vrf_name);
303 *idx = 0;
304 return 0;
305 }
306 }
307 } else {
308 *bgp = bgp_get_default();
309 if (!*bgp) {
310 vty_out(vty, "Unable to find default BGP instance\n");
311 *idx = 0;
312 return 0;
313 }
314 }
315
316 if (argv_find_and_parse_afi(argv, argc, idx, afi))
317 argv_find_and_parse_safi(argv, argc, idx, safi);
318
319 *idx += 1;
320 return *idx;
321}
322
323static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
324{
325 struct interface *ifp = NULL;
326
327 if (su->sa.sa_family == AF_INET)
328 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
329 else if (su->sa.sa_family == AF_INET6)
330 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
331 su->sin6.sin6_scope_id,
332 bgp->vrf_id);
333
334 if (ifp)
335 return 1;
336
337 return 0;
718e3744 338}
339
340/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
341/* This is used only for configuration, so disallow if attempted on
342 * a dynamic neighbor.
343 */
d62a17ae 344static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
345{
346 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
347 int ret;
348 union sockunion su;
349 struct peer *peer;
350
351 if (!bgp) {
352 return NULL;
353 }
354
355 ret = str2sockunion(ip_str, &su);
356 if (ret < 0) {
357 peer = peer_lookup_by_conf_if(bgp, ip_str);
358 if (!peer) {
359 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
360 == NULL) {
361 vty_out(vty,
362 "%% Malformed address or name: %s\n",
363 ip_str);
364 return NULL;
365 }
366 }
367 } else {
368 peer = peer_lookup(bgp, &su);
369 if (!peer) {
370 vty_out(vty,
371 "%% Specify remote-as or peer-group commands first\n");
372 return NULL;
373 }
374 if (peer_dynamic_neighbor(peer)) {
375 vty_out(vty,
376 "%% Operation not allowed on a dynamic neighbor\n");
377 return NULL;
378 }
379 }
380 return peer;
718e3744 381}
382
383/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
384/* This is used only for configuration, so disallow if attempted on
385 * a dynamic neighbor.
386 */
d62a17ae 387struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
388{
389 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
390 int ret;
391 union sockunion su;
392 struct peer *peer = NULL;
393 struct peer_group *group = NULL;
394
395 if (!bgp) {
396 return NULL;
397 }
398
399 ret = str2sockunion(peer_str, &su);
400 if (ret == 0) {
401 /* IP address, locate peer. */
402 peer = peer_lookup(bgp, &su);
403 } else {
404 /* Not IP, could match either peer configured on interface or a
405 * group. */
406 peer = peer_lookup_by_conf_if(bgp, peer_str);
407 if (!peer)
408 group = peer_group_lookup(bgp, peer_str);
409 }
410
411 if (peer) {
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417
418 return peer;
419 }
420
421 if (group)
422 return group->conf;
423
424 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
425
426 return NULL;
427}
428
429int bgp_vty_return(struct vty *vty, int ret)
430{
431 const char *str = NULL;
432
433 switch (ret) {
434 case BGP_ERR_INVALID_VALUE:
435 str = "Invalid value";
436 break;
437 case BGP_ERR_INVALID_FLAG:
438 str = "Invalid flag";
439 break;
440 case BGP_ERR_PEER_GROUP_SHUTDOWN:
441 str = "Peer-group has been shutdown. Activate the peer-group first";
442 break;
443 case BGP_ERR_PEER_FLAG_CONFLICT:
444 str = "Can't set override-capability and strict-capability-match at the same time";
445 break;
446 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
447 str = "Specify remote-as or peer-group remote AS first";
448 break;
449 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
450 str = "Cannot change the peer-group. Deconfigure first";
451 break;
452 case BGP_ERR_PEER_GROUP_MISMATCH:
453 str = "Peer is not a member of this peer-group";
454 break;
455 case BGP_ERR_PEER_FILTER_CONFLICT:
456 str = "Prefix/distribute list can not co-exist";
457 break;
458 case BGP_ERR_NOT_INTERNAL_PEER:
459 str = "Invalid command. Not an internal neighbor";
460 break;
461 case BGP_ERR_REMOVE_PRIVATE_AS:
462 str = "remove-private-AS cannot be configured for IBGP peers";
463 break;
464 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
465 str = "Local-AS allowed only for EBGP peers";
466 break;
467 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
468 str = "Cannot have local-as same as BGP AS number";
469 break;
470 case BGP_ERR_TCPSIG_FAILED:
471 str = "Error while applying TCP-Sig to session(s)";
472 break;
473 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
474 str = "ebgp-multihop and ttl-security cannot be configured together";
475 break;
476 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
477 str = "ttl-security only allowed for EBGP peers";
478 break;
479 case BGP_ERR_AS_OVERRIDE:
480 str = "as-override cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
483 str = "Invalid limit for number of dynamic neighbors";
484 break;
485 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
486 str = "Dynamic neighbor listen range already exists";
487 break;
488 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
489 str = "Operation not allowed on a dynamic neighbor";
490 break;
491 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
492 str = "Operation not allowed on a directly connected neighbor";
493 break;
494 case BGP_ERR_PEER_SAFI_CONFLICT:
495 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
496 break;
497 }
498 if (str) {
499 vty_out(vty, "%% %s\n", str);
500 return CMD_WARNING_CONFIG_FAILED;
501 }
502 return CMD_SUCCESS;
718e3744 503}
504
7aafcaca 505/* BGP clear sort. */
d62a17ae 506enum clear_sort {
507 clear_all,
508 clear_peer,
509 clear_group,
510 clear_external,
511 clear_as
7aafcaca
DS
512};
513
d62a17ae 514static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
515 safi_t safi, int error)
516{
517 switch (error) {
518 case BGP_ERR_AF_UNCONFIGURED:
519 vty_out(vty,
520 "%%BGP: Enable %s address family for the neighbor %s\n",
521 afi_safi_print(afi, safi), peer->host);
522 break;
523 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
524 vty_out(vty,
525 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
526 peer->host);
527 break;
528 default:
529 break;
530 }
7aafcaca
DS
531}
532
533/* `clear ip bgp' functions. */
d62a17ae 534static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
535 enum clear_sort sort, enum bgp_clear_type stype,
536 const char *arg)
537{
538 int ret;
539 struct peer *peer;
540 struct listnode *node, *nnode;
541
542 /* Clear all neighbors. */
543 /*
544 * Pass along pointer to next node to peer_clear() when walking all
545 * nodes
546 * on the BGP instance as that may get freed if it is a doppelganger
547 */
548 if (sort == clear_all) {
549 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
550 if (stype == BGP_CLEAR_SOFT_NONE)
551 ret = peer_clear(peer, &nnode);
552 else if (peer->afc[afi][safi])
553 ret = peer_clear_soft(peer, afi, safi, stype);
554 else
555 ret = 0;
556
557 if (ret < 0)
558 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 559 }
d62a17ae 560
561 /* This is to apply read-only mode on this clear. */
562 if (stype == BGP_CLEAR_SOFT_NONE)
563 bgp->update_delay_over = 0;
564
565 return CMD_SUCCESS;
7aafcaca
DS
566 }
567
d62a17ae 568 /* Clear specified neighbors. */
569 if (sort == clear_peer) {
570 union sockunion su;
571 int ret;
572
573 /* Make sockunion for lookup. */
574 ret = str2sockunion(arg, &su);
575 if (ret < 0) {
576 peer = peer_lookup_by_conf_if(bgp, arg);
577 if (!peer) {
578 peer = peer_lookup_by_hostname(bgp, arg);
579 if (!peer) {
580 vty_out(vty,
581 "Malformed address or name: %s\n",
582 arg);
583 return CMD_WARNING;
584 }
585 }
586 } else {
587 peer = peer_lookup(bgp, &su);
588 if (!peer) {
589 vty_out(vty,
590 "%%BGP: Unknown neighbor - \"%s\"\n",
591 arg);
592 return CMD_WARNING;
593 }
594 }
7aafcaca 595
d62a17ae 596 if (stype == BGP_CLEAR_SOFT_NONE)
597 ret = peer_clear(peer, NULL);
598 else
599 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 600
d62a17ae 601 if (ret < 0)
602 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 603
d62a17ae 604 return CMD_SUCCESS;
7aafcaca 605 }
7aafcaca 606
d62a17ae 607 /* Clear all peer-group members. */
608 if (sort == clear_group) {
609 struct peer_group *group;
7aafcaca 610
d62a17ae 611 group = peer_group_lookup(bgp, arg);
612 if (!group) {
613 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
614 return CMD_WARNING;
615 }
616
617 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
618 if (stype == BGP_CLEAR_SOFT_NONE) {
619 peer_clear(peer, NULL);
620 continue;
621 }
622
623 if (!peer->afc[afi][safi])
624 continue;
625
626 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 627
d62a17ae 628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
630 }
631 return CMD_SUCCESS;
7aafcaca 632 }
7aafcaca 633
d62a17ae 634 if (sort == clear_external) {
635 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
636 if (peer->sort == BGP_PEER_IBGP)
637 continue;
7aafcaca 638
d62a17ae 639 if (stype == BGP_CLEAR_SOFT_NONE)
640 ret = peer_clear(peer, &nnode);
641 else
642 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 643
d62a17ae 644 if (ret < 0)
645 bgp_clear_vty_error(vty, peer, afi, safi, ret);
646 }
647 return CMD_SUCCESS;
648 }
649
650 if (sort == clear_as) {
651 as_t as;
652 int find = 0;
653
654 as = strtoul(arg, NULL, 10);
655
656 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
657 if (peer->as != as)
658 continue;
659
660 find = 1;
661 if (stype == BGP_CLEAR_SOFT_NONE)
662 ret = peer_clear(peer, &nnode);
663 else
664 ret = peer_clear_soft(peer, afi, safi, stype);
665
666 if (ret < 0)
667 bgp_clear_vty_error(vty, peer, afi, safi, ret);
668 }
669 if (!find)
670 vty_out(vty,
671 "%%BGP: No peer is configured with AS %s\n",
672 arg);
673 return CMD_SUCCESS;
674 }
675
676 return CMD_SUCCESS;
677}
678
679static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
680 safi_t safi, enum clear_sort sort,
681 enum bgp_clear_type stype, const char *arg)
682{
683 struct bgp *bgp;
684
685 /* BGP structure lookup. */
686 if (name) {
687 bgp = bgp_lookup_by_name(name);
688 if (bgp == NULL) {
689 vty_out(vty, "Can't find BGP instance %s\n", name);
690 return CMD_WARNING;
691 }
692 } else {
693 bgp = bgp_get_default();
694 if (bgp == NULL) {
695 vty_out(vty, "No BGP process is configured\n");
696 return CMD_WARNING;
697 }
698 }
699
700 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
701}
702
703/* clear soft inbound */
d62a17ae 704static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 705{
d62a17ae 706 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
707 BGP_CLEAR_SOFT_IN, NULL);
708 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
709 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
710}
711
712/* clear soft outbound */
d62a17ae 713static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 714{
d62a17ae 715 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
716 BGP_CLEAR_SOFT_OUT, NULL);
717 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
718 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
719}
720
721
f787d7a0
DL
722#ifndef VTYSH_EXTRACT_PL
723#include "bgp_vty_clippy.c"
724#endif
725
718e3744 726/* BGP global configuration. */
727
728DEFUN (bgp_multiple_instance_func,
729 bgp_multiple_instance_cmd,
730 "bgp multiple-instance",
731 BGP_STR
732 "Enable bgp multiple instance\n")
733{
d62a17ae 734 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
735 return CMD_SUCCESS;
718e3744 736}
737
738DEFUN (no_bgp_multiple_instance,
739 no_bgp_multiple_instance_cmd,
740 "no bgp multiple-instance",
741 NO_STR
742 BGP_STR
743 "BGP multiple instance\n")
744{
d62a17ae 745 int ret;
718e3744 746
d62a17ae 747 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
748 if (ret < 0) {
749 vty_out(vty, "%% There are more than two BGP instances\n");
750 return CMD_WARNING_CONFIG_FAILED;
751 }
752 return CMD_SUCCESS;
718e3744 753}
754
755DEFUN (bgp_config_type,
756 bgp_config_type_cmd,
6147e2c6 757 "bgp config-type <cisco|zebra>",
718e3744 758 BGP_STR
759 "Configuration type\n"
760 "cisco\n"
761 "zebra\n")
762{
d62a17ae 763 int idx = 0;
764 if (argv_find(argv, argc, "cisco", &idx))
765 bgp_option_set(BGP_OPT_CONFIG_CISCO);
766 else
767 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 768
d62a17ae 769 return CMD_SUCCESS;
718e3744 770}
771
772DEFUN (no_bgp_config_type,
773 no_bgp_config_type_cmd,
c7178fe7 774 "no bgp config-type [<cisco|zebra>]",
718e3744 775 NO_STR
776 BGP_STR
838758ac
DW
777 "Display configuration type\n"
778 "cisco\n"
779 "zebra\n")
718e3744 780{
d62a17ae 781 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
782 return CMD_SUCCESS;
718e3744 783}
784
813d4307 785
718e3744 786DEFUN (no_synchronization,
787 no_synchronization_cmd,
788 "no synchronization",
789 NO_STR
790 "Perform IGP synchronization\n")
791{
d62a17ae 792 return CMD_SUCCESS;
718e3744 793}
794
795DEFUN (no_auto_summary,
796 no_auto_summary_cmd,
797 "no auto-summary",
798 NO_STR
799 "Enable automatic network number summarization\n")
800{
d62a17ae 801 return CMD_SUCCESS;
718e3744 802}
3d515fd9 803
718e3744 804/* "router bgp" commands. */
505e5056 805DEFUN_NOSH (router_bgp,
f412b39a 806 router_bgp_cmd,
18c57037 807 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 808 ROUTER_STR
809 BGP_STR
31500417
DW
810 AS_STR
811 BGP_INSTANCE_HELP_STR)
718e3744 812{
d62a17ae 813 int idx_asn = 2;
814 int idx_view_vrf = 3;
815 int idx_vrf = 4;
816 int ret;
817 as_t as;
818 struct bgp *bgp;
819 const char *name = NULL;
820 enum bgp_instance_type inst_type;
821
822 // "router bgp" without an ASN
823 if (argc == 2) {
824 // Pending: Make VRF option available for ASN less config
825 bgp = bgp_get_default();
826
827 if (bgp == NULL) {
828 vty_out(vty, "%% No BGP process is configured\n");
829 return CMD_WARNING_CONFIG_FAILED;
830 }
831
832 if (listcount(bm->bgp) > 1) {
833 vty_out(vty,
834 "%% Multiple BGP processes are configured\n");
835 return CMD_WARNING_CONFIG_FAILED;
836 }
837 }
838
839 // "router bgp X"
840 else {
841 as = strtoul(argv[idx_asn]->arg, NULL, 10);
842
843 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
844 if (argc > 3) {
845 name = argv[idx_vrf]->arg;
846
847 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
848 inst_type = BGP_INSTANCE_TYPE_VRF;
849 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
850 inst_type = BGP_INSTANCE_TYPE_VIEW;
851 }
852
853 ret = bgp_get(&bgp, &as, name, inst_type);
854 switch (ret) {
855 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
856 vty_out(vty,
857 "Please specify 'bgp multiple-instance' first\n");
858 return CMD_WARNING_CONFIG_FAILED;
859 case BGP_ERR_AS_MISMATCH:
860 vty_out(vty, "BGP is already running; AS is %u\n", as);
861 return CMD_WARNING_CONFIG_FAILED;
862 case BGP_ERR_INSTANCE_MISMATCH:
863 vty_out(vty,
864 "BGP instance name and AS number mismatch\n");
865 vty_out(vty,
866 "BGP instance is already running; AS is %u\n",
867 as);
868 return CMD_WARNING_CONFIG_FAILED;
869 }
870
871 /* Pending: handle when user tries to change a view to vrf n vv.
872 */
873 }
874
875 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
876
877 return CMD_SUCCESS;
718e3744 878}
879
718e3744 880/* "no router bgp" commands. */
881DEFUN (no_router_bgp,
882 no_router_bgp_cmd,
18c57037 883 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 884 NO_STR
885 ROUTER_STR
886 BGP_STR
31500417
DW
887 AS_STR
888 BGP_INSTANCE_HELP_STR)
718e3744 889{
d62a17ae 890 int idx_asn = 3;
891 int idx_vrf = 5;
892 as_t as;
893 struct bgp *bgp;
894 const char *name = NULL;
718e3744 895
d62a17ae 896 // "no router bgp" without an ASN
897 if (argc == 3) {
898 // Pending: Make VRF option available for ASN less config
899 bgp = bgp_get_default();
718e3744 900
d62a17ae 901 if (bgp == NULL) {
902 vty_out(vty, "%% No BGP process is configured\n");
903 return CMD_WARNING_CONFIG_FAILED;
904 }
7fb21a9f 905
d62a17ae 906 if (listcount(bm->bgp) > 1) {
907 vty_out(vty,
908 "%% Multiple BGP processes are configured\n");
909 return CMD_WARNING_CONFIG_FAILED;
910 }
911 } else {
912 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 913
d62a17ae 914 if (argc > 4)
915 name = argv[idx_vrf]->arg;
7fb21a9f 916
d62a17ae 917 /* Lookup bgp structure. */
918 bgp = bgp_lookup(as, name);
919 if (!bgp) {
920 vty_out(vty, "%% Can't find BGP instance\n");
921 return CMD_WARNING_CONFIG_FAILED;
922 }
923 }
718e3744 924
d62a17ae 925 bgp_delete(bgp);
718e3744 926
d62a17ae 927 return CMD_SUCCESS;
718e3744 928}
929
6b0655a2 930
718e3744 931/* BGP router-id. */
932
f787d7a0 933DEFPY (bgp_router_id,
718e3744 934 bgp_router_id_cmd,
935 "bgp router-id A.B.C.D",
936 BGP_STR
937 "Override configured router identifier\n"
938 "Manually configured router identifier\n")
939{
d62a17ae 940 VTY_DECLVAR_CONTEXT(bgp, bgp);
941 bgp_router_id_static_set(bgp, router_id);
942 return CMD_SUCCESS;
718e3744 943}
944
f787d7a0 945DEFPY (no_bgp_router_id,
718e3744 946 no_bgp_router_id_cmd,
31500417 947 "no bgp router-id [A.B.C.D]",
718e3744 948 NO_STR
949 BGP_STR
31500417
DW
950 "Override configured router identifier\n"
951 "Manually configured router identifier\n")
718e3744 952{
d62a17ae 953 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 954
d62a17ae 955 if (router_id_str) {
956 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
957 vty_out(vty, "%% BGP router-id doesn't match\n");
958 return CMD_WARNING_CONFIG_FAILED;
959 }
e018c7cc 960 }
718e3744 961
d62a17ae 962 router_id.s_addr = 0;
963 bgp_router_id_static_set(bgp, router_id);
718e3744 964
d62a17ae 965 return CMD_SUCCESS;
718e3744 966}
967
6b0655a2 968
718e3744 969/* BGP Cluster ID. */
718e3744 970DEFUN (bgp_cluster_id,
971 bgp_cluster_id_cmd,
838758ac 972 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 973 BGP_STR
974 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
975 "Route-Reflector Cluster-id in IP address format\n"
976 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 977{
d62a17ae 978 VTY_DECLVAR_CONTEXT(bgp, bgp);
979 int idx_ipv4 = 2;
980 int ret;
981 struct in_addr cluster;
718e3744 982
d62a17ae 983 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
984 if (!ret) {
985 vty_out(vty, "%% Malformed bgp cluster identifier\n");
986 return CMD_WARNING_CONFIG_FAILED;
987 }
718e3744 988
d62a17ae 989 bgp_cluster_id_set(bgp, &cluster);
990 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 991
d62a17ae 992 return CMD_SUCCESS;
718e3744 993}
994
718e3744 995DEFUN (no_bgp_cluster_id,
996 no_bgp_cluster_id_cmd,
c7178fe7 997 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 998 NO_STR
999 BGP_STR
838758ac
DW
1000 "Configure Route-Reflector Cluster-id\n"
1001 "Route-Reflector Cluster-id in IP address format\n"
1002 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1003{
d62a17ae 1004 VTY_DECLVAR_CONTEXT(bgp, bgp);
1005 bgp_cluster_id_unset(bgp);
1006 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1007
d62a17ae 1008 return CMD_SUCCESS;
718e3744 1009}
1010
718e3744 1011DEFUN (bgp_confederation_identifier,
1012 bgp_confederation_identifier_cmd,
9ccf14f7 1013 "bgp confederation identifier (1-4294967295)",
718e3744 1014 "BGP specific commands\n"
1015 "AS confederation parameters\n"
1016 "AS number\n"
1017 "Set routing domain confederation AS\n")
1018{
d62a17ae 1019 VTY_DECLVAR_CONTEXT(bgp, bgp);
1020 int idx_number = 3;
1021 as_t as;
718e3744 1022
d62a17ae 1023 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1024
d62a17ae 1025 bgp_confederation_id_set(bgp, as);
718e3744 1026
d62a17ae 1027 return CMD_SUCCESS;
718e3744 1028}
1029
1030DEFUN (no_bgp_confederation_identifier,
1031 no_bgp_confederation_identifier_cmd,
838758ac 1032 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1033 NO_STR
1034 "BGP specific commands\n"
1035 "AS confederation parameters\n"
3a2d747c
QY
1036 "AS number\n"
1037 "Set routing domain confederation AS\n")
718e3744 1038{
d62a17ae 1039 VTY_DECLVAR_CONTEXT(bgp, bgp);
1040 bgp_confederation_id_unset(bgp);
718e3744 1041
d62a17ae 1042 return CMD_SUCCESS;
718e3744 1043}
1044
718e3744 1045DEFUN (bgp_confederation_peers,
1046 bgp_confederation_peers_cmd,
12dcf78e 1047 "bgp confederation peers (1-4294967295)...",
718e3744 1048 "BGP specific commands\n"
1049 "AS confederation parameters\n"
1050 "Peer ASs in BGP confederation\n"
1051 AS_STR)
1052{
d62a17ae 1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054 int idx_asn = 3;
1055 as_t as;
1056 int i;
718e3744 1057
d62a17ae 1058 for (i = idx_asn; i < argc; i++) {
1059 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1060
d62a17ae 1061 if (bgp->as == as) {
1062 vty_out(vty,
1063 "%% Local member-AS not allowed in confed peer list\n");
1064 continue;
1065 }
718e3744 1066
d62a17ae 1067 bgp_confederation_peers_add(bgp, as);
1068 }
1069 return CMD_SUCCESS;
718e3744 1070}
1071
1072DEFUN (no_bgp_confederation_peers,
1073 no_bgp_confederation_peers_cmd,
e83a9414 1074 "no bgp confederation peers (1-4294967295)...",
718e3744 1075 NO_STR
1076 "BGP specific commands\n"
1077 "AS confederation parameters\n"
1078 "Peer ASs in BGP confederation\n"
1079 AS_STR)
1080{
d62a17ae 1081 VTY_DECLVAR_CONTEXT(bgp, bgp);
1082 int idx_asn = 4;
1083 as_t as;
1084 int i;
718e3744 1085
d62a17ae 1086 for (i = idx_asn; i < argc; i++) {
1087 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1088
d62a17ae 1089 bgp_confederation_peers_remove(bgp, as);
1090 }
1091 return CMD_SUCCESS;
718e3744 1092}
6b0655a2 1093
5e242b0d
DS
1094/**
1095 * Central routine for maximum-paths configuration.
1096 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1097 * @set: 1 for setting values, 0 for removing the max-paths config.
1098 */
d62a17ae 1099static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1100 const char *mpaths, u_int16_t options,
1101 int set)
1102{
1103 VTY_DECLVAR_CONTEXT(bgp, bgp);
1104 u_int16_t maxpaths = 0;
1105 int ret;
1106 afi_t afi;
1107 safi_t safi;
1108
1109 afi = bgp_node_afi(vty);
1110 safi = bgp_node_safi(vty);
1111
1112 if (set) {
1113 maxpaths = strtol(mpaths, NULL, 10);
1114 if (maxpaths > multipath_num) {
1115 vty_out(vty,
1116 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1117 maxpaths, multipath_num);
1118 return CMD_WARNING_CONFIG_FAILED;
1119 }
1120 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1121 options);
1122 } else
1123 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1124
1125 if (ret < 0) {
1126 vty_out(vty,
1127 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1128 (set == 1) ? "" : "un",
1129 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1130 maxpaths, afi, safi);
1131 return CMD_WARNING_CONFIG_FAILED;
1132 }
1133
1134 bgp_recalculate_all_bestpaths(bgp);
1135
1136 return CMD_SUCCESS;
165b5fff
JB
1137}
1138
abc920f8
DS
1139DEFUN (bgp_maxmed_admin,
1140 bgp_maxmed_admin_cmd,
1141 "bgp max-med administrative ",
1142 BGP_STR
1143 "Advertise routes with max-med\n"
1144 "Administratively applied, for an indefinite period\n")
1145{
d62a17ae 1146 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1147
d62a17ae 1148 bgp->v_maxmed_admin = 1;
1149 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1150
d62a17ae 1151 bgp_maxmed_update(bgp);
abc920f8 1152
d62a17ae 1153 return CMD_SUCCESS;
abc920f8
DS
1154}
1155
1156DEFUN (bgp_maxmed_admin_medv,
1157 bgp_maxmed_admin_medv_cmd,
4668a151 1158 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1159 BGP_STR
1160 "Advertise routes with max-med\n"
1161 "Administratively applied, for an indefinite period\n"
1162 "Max MED value to be used\n")
1163{
d62a17ae 1164 VTY_DECLVAR_CONTEXT(bgp, bgp);
1165 int idx_number = 3;
abc920f8 1166
d62a17ae 1167 bgp->v_maxmed_admin = 1;
1168 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1169
d62a17ae 1170 bgp_maxmed_update(bgp);
abc920f8 1171
d62a17ae 1172 return CMD_SUCCESS;
abc920f8
DS
1173}
1174
1175DEFUN (no_bgp_maxmed_admin,
1176 no_bgp_maxmed_admin_cmd,
4668a151 1177 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1178 NO_STR
1179 BGP_STR
1180 "Advertise routes with max-med\n"
838758ac
DW
1181 "Administratively applied, for an indefinite period\n"
1182 "Max MED value to be used\n")
abc920f8 1183{
d62a17ae 1184 VTY_DECLVAR_CONTEXT(bgp, bgp);
1185 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1186 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1187 bgp_maxmed_update(bgp);
abc920f8 1188
d62a17ae 1189 return CMD_SUCCESS;
abc920f8
DS
1190}
1191
abc920f8
DS
1192DEFUN (bgp_maxmed_onstartup,
1193 bgp_maxmed_onstartup_cmd,
4668a151 1194 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1195 BGP_STR
1196 "Advertise routes with max-med\n"
1197 "Effective on a startup\n"
1198 "Time (seconds) period for max-med\n"
1199 "Max MED value to be used\n")
1200{
d62a17ae 1201 VTY_DECLVAR_CONTEXT(bgp, bgp);
1202 int idx = 0;
4668a151 1203
d62a17ae 1204 argv_find(argv, argc, "(5-86400)", &idx);
1205 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1206 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1207 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1208 else
1209 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1210
d62a17ae 1211 bgp_maxmed_update(bgp);
abc920f8 1212
d62a17ae 1213 return CMD_SUCCESS;
abc920f8
DS
1214}
1215
1216DEFUN (no_bgp_maxmed_onstartup,
1217 no_bgp_maxmed_onstartup_cmd,
4668a151 1218 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1219 NO_STR
1220 BGP_STR
1221 "Advertise routes with max-med\n"
838758ac
DW
1222 "Effective on a startup\n"
1223 "Time (seconds) period for max-med\n"
1224 "Max MED value to be used\n")
abc920f8 1225{
d62a17ae 1226 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1227
d62a17ae 1228 /* Cancel max-med onstartup if its on */
1229 if (bgp->t_maxmed_onstartup) {
1230 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1231 bgp->maxmed_onstartup_over = 1;
1232 }
abc920f8 1233
d62a17ae 1234 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1235 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1236
d62a17ae 1237 bgp_maxmed_update(bgp);
abc920f8 1238
d62a17ae 1239 return CMD_SUCCESS;
abc920f8
DS
1240}
1241
d62a17ae 1242static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1243 const char *wait)
f188f2c4 1244{
d62a17ae 1245 VTY_DECLVAR_CONTEXT(bgp, bgp);
1246 u_int16_t update_delay;
1247 u_int16_t establish_wait;
f188f2c4 1248
d62a17ae 1249 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1250
d62a17ae 1251 if (!wait) /* update-delay <delay> */
1252 {
1253 bgp->v_update_delay = update_delay;
1254 bgp->v_establish_wait = bgp->v_update_delay;
1255 return CMD_SUCCESS;
1256 }
f188f2c4 1257
d62a17ae 1258 /* update-delay <delay> <establish-wait> */
1259 establish_wait = atoi(wait);
1260 if (update_delay < establish_wait) {
1261 vty_out(vty,
1262 "%%Failed: update-delay less than the establish-wait!\n");
1263 return CMD_WARNING_CONFIG_FAILED;
1264 }
f188f2c4 1265
d62a17ae 1266 bgp->v_update_delay = update_delay;
1267 bgp->v_establish_wait = establish_wait;
f188f2c4 1268
d62a17ae 1269 return CMD_SUCCESS;
f188f2c4
DS
1270}
1271
d62a17ae 1272static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1273{
d62a17ae 1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1275
d62a17ae 1276 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1277 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1278
d62a17ae 1279 return CMD_SUCCESS;
f188f2c4
DS
1280}
1281
2b791107 1282void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1283{
d62a17ae 1284 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1285 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1286 if (bgp->v_update_delay != bgp->v_establish_wait)
1287 vty_out(vty, " %d", bgp->v_establish_wait);
1288 vty_out(vty, "\n");
1289 }
f188f2c4
DS
1290}
1291
1292
1293/* Update-delay configuration */
1294DEFUN (bgp_update_delay,
1295 bgp_update_delay_cmd,
6147e2c6 1296 "update-delay (0-3600)",
f188f2c4
DS
1297 "Force initial delay for best-path and updates\n"
1298 "Seconds\n")
1299{
d62a17ae 1300 int idx_number = 1;
1301 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1302}
1303
1304DEFUN (bgp_update_delay_establish_wait,
1305 bgp_update_delay_establish_wait_cmd,
6147e2c6 1306 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1307 "Force initial delay for best-path and updates\n"
1308 "Seconds\n"
f188f2c4
DS
1309 "Seconds\n")
1310{
d62a17ae 1311 int idx_number = 1;
1312 int idx_number_2 = 2;
1313 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1314 argv[idx_number_2]->arg);
f188f2c4
DS
1315}
1316
1317/* Update-delay deconfiguration */
1318DEFUN (no_bgp_update_delay,
1319 no_bgp_update_delay_cmd,
838758ac
DW
1320 "no update-delay [(0-3600) [(1-3600)]]",
1321 NO_STR
f188f2c4 1322 "Force initial delay for best-path and updates\n"
838758ac 1323 "Seconds\n"
7111c1a0 1324 "Seconds\n")
f188f2c4 1325{
d62a17ae 1326 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1327}
1328
5e242b0d 1329
d62a17ae 1330static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1331 char set)
cb1faec9 1332{
d62a17ae 1333 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1334
d62a17ae 1335 if (set)
1336 bgp->wpkt_quanta = strtoul(num, NULL, 10);
1337 else
1338 bgp->wpkt_quanta = BGP_WRITE_PACKET_MAX;
cb1faec9 1339
d62a17ae 1340 return CMD_SUCCESS;
cb1faec9
DS
1341}
1342
2b791107 1343void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1344{
d62a17ae 1345 if (bgp->wpkt_quanta != BGP_WRITE_PACKET_MAX)
1346 vty_out(vty, " write-quanta %d\n", bgp->wpkt_quanta);
cb1faec9
DS
1347}
1348
1349
1350/* Update-delay configuration */
1351DEFUN (bgp_wpkt_quanta,
1352 bgp_wpkt_quanta_cmd,
6147e2c6 1353 "write-quanta (1-10000)",
cb1faec9
DS
1354 "How many packets to write to peer socket per run\n"
1355 "Number of packets\n")
1356{
d62a17ae 1357 int idx_number = 1;
1358 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1359}
1360
1361/* Update-delay deconfiguration */
1362DEFUN (no_bgp_wpkt_quanta,
1363 no_bgp_wpkt_quanta_cmd,
6147e2c6 1364 "no write-quanta (1-10000)",
d7fa34c1 1365 NO_STR
cb1faec9
DS
1366 "How many packets to write to peer socket per run\n"
1367 "Number of packets\n")
1368{
d62a17ae 1369 int idx_number = 2;
1370 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1371}
1372
2b791107 1373void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1374{
d62a17ae 1375 if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
1376 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1377}
1378
1379
1380DEFUN (bgp_coalesce_time,
1381 bgp_coalesce_time_cmd,
6147e2c6 1382 "coalesce-time (0-4294967295)",
3f9c7369
DS
1383 "Subgroup coalesce timer\n"
1384 "Subgroup coalesce timer value (in ms)\n")
1385{
d62a17ae 1386 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1387
d62a17ae 1388 int idx = 0;
1389 argv_find(argv, argc, "(0-4294967295)", &idx);
1390 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1391 return CMD_SUCCESS;
3f9c7369
DS
1392}
1393
1394DEFUN (no_bgp_coalesce_time,
1395 no_bgp_coalesce_time_cmd,
6147e2c6 1396 "no coalesce-time (0-4294967295)",
3a2d747c 1397 NO_STR
3f9c7369
DS
1398 "Subgroup coalesce timer\n"
1399 "Subgroup coalesce timer value (in ms)\n")
1400{
d62a17ae 1401 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1402
d62a17ae 1403 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1404 return CMD_SUCCESS;
3f9c7369
DS
1405}
1406
5e242b0d
DS
1407/* Maximum-paths configuration */
1408DEFUN (bgp_maxpaths,
1409 bgp_maxpaths_cmd,
6319fd63 1410 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1411 "Forward packets over multiple paths\n"
1412 "Number of paths\n")
1413{
d62a17ae 1414 int idx_number = 1;
1415 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1416 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1417}
1418
d62a17ae 1419ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1420 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1421 "Forward packets over multiple paths\n"
1422 "Number of paths\n")
596c17ba 1423
165b5fff
JB
1424DEFUN (bgp_maxpaths_ibgp,
1425 bgp_maxpaths_ibgp_cmd,
6319fd63 1426 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1427 "Forward packets over multiple paths\n"
1428 "iBGP-multipath\n"
1429 "Number of paths\n")
1430{
d62a17ae 1431 int idx_number = 2;
1432 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1433 argv[idx_number]->arg, 0, 1);
5e242b0d 1434}
165b5fff 1435
d62a17ae 1436ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1437 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1438 "Forward packets over multiple paths\n"
1439 "iBGP-multipath\n"
1440 "Number of paths\n")
596c17ba 1441
5e242b0d
DS
1442DEFUN (bgp_maxpaths_ibgp_cluster,
1443 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1444 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1445 "Forward packets over multiple paths\n"
1446 "iBGP-multipath\n"
1447 "Number of paths\n"
1448 "Match the cluster length\n")
1449{
d62a17ae 1450 int idx_number = 2;
1451 return bgp_maxpaths_config_vty(
1452 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1453 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1454}
1455
d62a17ae 1456ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1457 "maximum-paths ibgp " CMD_RANGE_STR(
1458 1, MULTIPATH_NUM) " equal-cluster-length",
1459 "Forward packets over multiple paths\n"
1460 "iBGP-multipath\n"
1461 "Number of paths\n"
1462 "Match the cluster length\n")
596c17ba 1463
165b5fff
JB
1464DEFUN (no_bgp_maxpaths,
1465 no_bgp_maxpaths_cmd,
6319fd63 1466 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1467 NO_STR
1468 "Forward packets over multiple paths\n"
1469 "Number of paths\n")
1470{
d62a17ae 1471 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1472}
1473
d62a17ae 1474ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
9d303b37 1475 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1476 "Forward packets over multiple paths\n"
1477 "Number of paths\n")
596c17ba 1478
165b5fff
JB
1479DEFUN (no_bgp_maxpaths_ibgp,
1480 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1481 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1482 NO_STR
1483 "Forward packets over multiple paths\n"
1484 "iBGP-multipath\n"
838758ac
DW
1485 "Number of paths\n"
1486 "Match the cluster length\n")
165b5fff 1487{
d62a17ae 1488 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1489}
1490
d62a17ae 1491ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1492 "no maximum-paths ibgp [" CMD_RANGE_STR(
1493 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1494 NO_STR
1495 "Forward packets over multiple paths\n"
1496 "iBGP-multipath\n"
1497 "Number of paths\n"
1498 "Match the cluster length\n")
596c17ba 1499
2b791107 1500void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1501 safi_t safi)
165b5fff 1502{
d62a17ae 1503 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1504 vty_out(vty, " maximum-paths %d\n",
1505 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1506 }
165b5fff 1507
d62a17ae 1508 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1509 vty_out(vty, " maximum-paths ibgp %d",
1510 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1511 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1512 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1513 vty_out(vty, " equal-cluster-length");
1514 vty_out(vty, "\n");
1515 }
165b5fff 1516}
6b0655a2 1517
718e3744 1518/* BGP timers. */
1519
1520DEFUN (bgp_timers,
1521 bgp_timers_cmd,
6147e2c6 1522 "timers bgp (0-65535) (0-65535)",
718e3744 1523 "Adjust routing timers\n"
1524 "BGP timers\n"
1525 "Keepalive interval\n"
1526 "Holdtime\n")
1527{
d62a17ae 1528 VTY_DECLVAR_CONTEXT(bgp, bgp);
1529 int idx_number = 2;
1530 int idx_number_2 = 3;
1531 unsigned long keepalive = 0;
1532 unsigned long holdtime = 0;
718e3744 1533
d62a17ae 1534 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1535 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1536
d62a17ae 1537 /* Holdtime value check. */
1538 if (holdtime < 3 && holdtime != 0) {
1539 vty_out(vty,
1540 "%% hold time value must be either 0 or greater than 3\n");
1541 return CMD_WARNING_CONFIG_FAILED;
1542 }
718e3744 1543
d62a17ae 1544 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1545
d62a17ae 1546 return CMD_SUCCESS;
718e3744 1547}
1548
1549DEFUN (no_bgp_timers,
1550 no_bgp_timers_cmd,
838758ac 1551 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1552 NO_STR
1553 "Adjust routing timers\n"
838758ac
DW
1554 "BGP timers\n"
1555 "Keepalive interval\n"
1556 "Holdtime\n")
718e3744 1557{
d62a17ae 1558 VTY_DECLVAR_CONTEXT(bgp, bgp);
1559 bgp_timers_unset(bgp);
718e3744 1560
d62a17ae 1561 return CMD_SUCCESS;
718e3744 1562}
1563
6b0655a2 1564
718e3744 1565DEFUN (bgp_client_to_client_reflection,
1566 bgp_client_to_client_reflection_cmd,
1567 "bgp client-to-client reflection",
1568 "BGP specific commands\n"
1569 "Configure client to client route reflection\n"
1570 "reflection of routes allowed\n")
1571{
d62a17ae 1572 VTY_DECLVAR_CONTEXT(bgp, bgp);
1573 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1574 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1575
d62a17ae 1576 return CMD_SUCCESS;
718e3744 1577}
1578
1579DEFUN (no_bgp_client_to_client_reflection,
1580 no_bgp_client_to_client_reflection_cmd,
1581 "no bgp client-to-client reflection",
1582 NO_STR
1583 "BGP specific commands\n"
1584 "Configure client to client route reflection\n"
1585 "reflection of routes allowed\n")
1586{
d62a17ae 1587 VTY_DECLVAR_CONTEXT(bgp, bgp);
1588 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1589 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1590
d62a17ae 1591 return CMD_SUCCESS;
718e3744 1592}
1593
1594/* "bgp always-compare-med" configuration. */
1595DEFUN (bgp_always_compare_med,
1596 bgp_always_compare_med_cmd,
1597 "bgp always-compare-med",
1598 "BGP specific commands\n"
1599 "Allow comparing MED from different neighbors\n")
1600{
d62a17ae 1601 VTY_DECLVAR_CONTEXT(bgp, bgp);
1602 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1603 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1604
d62a17ae 1605 return CMD_SUCCESS;
718e3744 1606}
1607
1608DEFUN (no_bgp_always_compare_med,
1609 no_bgp_always_compare_med_cmd,
1610 "no bgp always-compare-med",
1611 NO_STR
1612 "BGP specific commands\n"
1613 "Allow comparing MED from different neighbors\n")
1614{
d62a17ae 1615 VTY_DECLVAR_CONTEXT(bgp, bgp);
1616 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1617 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1618
d62a17ae 1619 return CMD_SUCCESS;
718e3744 1620}
6b0655a2 1621
718e3744 1622/* "bgp deterministic-med" configuration. */
1623DEFUN (bgp_deterministic_med,
1624 bgp_deterministic_med_cmd,
1625 "bgp deterministic-med",
1626 "BGP specific commands\n"
1627 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1628{
d62a17ae 1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1630
d62a17ae 1631 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1632 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1633 bgp_recalculate_all_bestpaths(bgp);
1634 }
7aafcaca 1635
d62a17ae 1636 return CMD_SUCCESS;
718e3744 1637}
1638
1639DEFUN (no_bgp_deterministic_med,
1640 no_bgp_deterministic_med_cmd,
1641 "no bgp deterministic-med",
1642 NO_STR
1643 "BGP specific commands\n"
1644 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1645{
d62a17ae 1646 VTY_DECLVAR_CONTEXT(bgp, bgp);
1647 int bestpath_per_as_used;
1648 afi_t afi;
1649 safi_t safi;
1650 struct peer *peer;
1651 struct listnode *node, *nnode;
1652
1653 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1654 bestpath_per_as_used = 0;
1655
1656 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1657 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1658 for (safi = SAFI_UNICAST; safi < SAFI_MAX;
1659 safi++)
1660 if (CHECK_FLAG(
1661 peer->af_flags[afi][safi],
1662 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1663 bestpath_per_as_used = 1;
1664 break;
1665 }
1666
1667 if (bestpath_per_as_used)
1668 break;
1669 }
1670
1671 if (bestpath_per_as_used) {
1672 vty_out(vty,
1673 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1674 return CMD_WARNING_CONFIG_FAILED;
1675 } else {
1676 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1677 bgp_recalculate_all_bestpaths(bgp);
1678 }
1679 }
1680
1681 return CMD_SUCCESS;
718e3744 1682}
538621f2 1683
1684/* "bgp graceful-restart" configuration. */
1685DEFUN (bgp_graceful_restart,
1686 bgp_graceful_restart_cmd,
1687 "bgp graceful-restart",
1688 "BGP specific commands\n"
1689 "Graceful restart capability parameters\n")
1690{
d62a17ae 1691 VTY_DECLVAR_CONTEXT(bgp, bgp);
1692 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1693 return CMD_SUCCESS;
538621f2 1694}
1695
1696DEFUN (no_bgp_graceful_restart,
1697 no_bgp_graceful_restart_cmd,
1698 "no bgp graceful-restart",
1699 NO_STR
1700 "BGP specific commands\n"
1701 "Graceful restart capability parameters\n")
1702{
d62a17ae 1703 VTY_DECLVAR_CONTEXT(bgp, bgp);
1704 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1705 return CMD_SUCCESS;
538621f2 1706}
1707
93406d87 1708DEFUN (bgp_graceful_restart_stalepath_time,
1709 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1710 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1711 "BGP specific commands\n"
1712 "Graceful restart capability parameters\n"
1713 "Set the max time to hold onto restarting peer's stale paths\n"
1714 "Delay value (seconds)\n")
1715{
d62a17ae 1716 VTY_DECLVAR_CONTEXT(bgp, bgp);
1717 int idx_number = 3;
1718 u_int32_t stalepath;
93406d87 1719
d62a17ae 1720 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1721 bgp->stalepath_time = stalepath;
1722 return CMD_SUCCESS;
93406d87 1723}
1724
eb6f1b41
PG
1725DEFUN (bgp_graceful_restart_restart_time,
1726 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1727 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1728 "BGP specific commands\n"
1729 "Graceful restart capability parameters\n"
1730 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1731 "Delay value (seconds)\n")
1732{
d62a17ae 1733 VTY_DECLVAR_CONTEXT(bgp, bgp);
1734 int idx_number = 3;
1735 u_int32_t restart;
eb6f1b41 1736
d62a17ae 1737 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1738 bgp->restart_time = restart;
1739 return CMD_SUCCESS;
eb6f1b41
PG
1740}
1741
93406d87 1742DEFUN (no_bgp_graceful_restart_stalepath_time,
1743 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1744 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1745 NO_STR
1746 "BGP specific commands\n"
1747 "Graceful restart capability parameters\n"
838758ac
DW
1748 "Set the max time to hold onto restarting peer's stale paths\n"
1749 "Delay value (seconds)\n")
93406d87 1750{
d62a17ae 1751 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1752
d62a17ae 1753 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1754 return CMD_SUCCESS;
93406d87 1755}
1756
eb6f1b41
PG
1757DEFUN (no_bgp_graceful_restart_restart_time,
1758 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1759 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1760 NO_STR
1761 "BGP specific commands\n"
1762 "Graceful restart capability parameters\n"
838758ac
DW
1763 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1764 "Delay value (seconds)\n")
eb6f1b41 1765{
d62a17ae 1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1767
d62a17ae 1768 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1769 return CMD_SUCCESS;
eb6f1b41
PG
1770}
1771
43fc21b3
JC
1772DEFUN (bgp_graceful_restart_preserve_fw,
1773 bgp_graceful_restart_preserve_fw_cmd,
1774 "bgp graceful-restart preserve-fw-state",
1775 "BGP specific commands\n"
1776 "Graceful restart capability parameters\n"
1777 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1778{
d62a17ae 1779 VTY_DECLVAR_CONTEXT(bgp, bgp);
1780 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1781 return CMD_SUCCESS;
43fc21b3
JC
1782}
1783
1784DEFUN (no_bgp_graceful_restart_preserve_fw,
1785 no_bgp_graceful_restart_preserve_fw_cmd,
1786 "no bgp graceful-restart preserve-fw-state",
1787 NO_STR
1788 "BGP specific commands\n"
1789 "Graceful restart capability parameters\n"
1790 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1791{
d62a17ae 1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1794 return CMD_SUCCESS;
43fc21b3
JC
1795}
1796
7f323236
DW
1797static void bgp_redistribute_redo(struct bgp *bgp)
1798{
1799 afi_t afi;
1800 int i;
1801 struct list *red_list;
1802 struct listnode *node;
1803 struct bgp_redist *red;
1804
1805 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1806 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1807
1808 red_list = bgp->redist[afi][i];
1809 if (!red_list)
1810 continue;
1811
1812 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1813 bgp_redistribute_resend(bgp, afi, i,
1814 red->instance);
1815 }
1816 }
1817 }
1818}
1819
1820/* "bgp graceful-shutdown" configuration */
1821DEFUN (bgp_graceful_shutdown,
1822 bgp_graceful_shutdown_cmd,
1823 "bgp graceful-shutdown",
1824 BGP_STR
1825 "Graceful shutdown parameters\n")
1826{
1827 VTY_DECLVAR_CONTEXT(bgp, bgp);
1828
1829 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1830 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1831 bgp_static_redo_import_check(bgp);
1832 bgp_redistribute_redo(bgp);
1833 bgp_clear_star_soft_out(vty, bgp->name);
1834 bgp_clear_star_soft_in(vty, bgp->name);
1835 }
1836
1837 return CMD_SUCCESS;
1838}
1839
1840DEFUN (no_bgp_graceful_shutdown,
1841 no_bgp_graceful_shutdown_cmd,
1842 "no bgp graceful-shutdown",
1843 NO_STR
1844 BGP_STR
1845 "Graceful shutdown parameters\n")
1846{
1847 VTY_DECLVAR_CONTEXT(bgp, bgp);
1848
1849 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1850 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1851 bgp_static_redo_import_check(bgp);
1852 bgp_redistribute_redo(bgp);
1853 bgp_clear_star_soft_out(vty, bgp->name);
1854 bgp_clear_star_soft_in(vty, bgp->name);
1855 }
1856
1857 return CMD_SUCCESS;
1858}
1859
718e3744 1860/* "bgp fast-external-failover" configuration. */
1861DEFUN (bgp_fast_external_failover,
1862 bgp_fast_external_failover_cmd,
1863 "bgp fast-external-failover",
1864 BGP_STR
1865 "Immediately reset session if a link to a directly connected external peer goes down\n")
1866{
d62a17ae 1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1869 return CMD_SUCCESS;
718e3744 1870}
1871
1872DEFUN (no_bgp_fast_external_failover,
1873 no_bgp_fast_external_failover_cmd,
1874 "no bgp fast-external-failover",
1875 NO_STR
1876 BGP_STR
1877 "Immediately reset session if a link to a directly connected external peer goes down\n")
1878{
d62a17ae 1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1881 return CMD_SUCCESS;
718e3744 1882}
6b0655a2 1883
718e3744 1884/* "bgp enforce-first-as" configuration. */
1885DEFUN (bgp_enforce_first_as,
1886 bgp_enforce_first_as_cmd,
1887 "bgp enforce-first-as",
1888 BGP_STR
1889 "Enforce the first AS for EBGP routes\n")
1890{
d62a17ae 1891 VTY_DECLVAR_CONTEXT(bgp, bgp);
1892 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1893 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1894
d62a17ae 1895 return CMD_SUCCESS;
718e3744 1896}
1897
1898DEFUN (no_bgp_enforce_first_as,
1899 no_bgp_enforce_first_as_cmd,
1900 "no bgp enforce-first-as",
1901 NO_STR
1902 BGP_STR
1903 "Enforce the first AS for EBGP routes\n")
1904{
d62a17ae 1905 VTY_DECLVAR_CONTEXT(bgp, bgp);
1906 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1907 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1908
d62a17ae 1909 return CMD_SUCCESS;
718e3744 1910}
6b0655a2 1911
718e3744 1912/* "bgp bestpath compare-routerid" configuration. */
1913DEFUN (bgp_bestpath_compare_router_id,
1914 bgp_bestpath_compare_router_id_cmd,
1915 "bgp bestpath compare-routerid",
1916 "BGP specific commands\n"
1917 "Change the default bestpath selection\n"
1918 "Compare router-id for identical EBGP paths\n")
1919{
d62a17ae 1920 VTY_DECLVAR_CONTEXT(bgp, bgp);
1921 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1922 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1923
d62a17ae 1924 return CMD_SUCCESS;
718e3744 1925}
1926
1927DEFUN (no_bgp_bestpath_compare_router_id,
1928 no_bgp_bestpath_compare_router_id_cmd,
1929 "no bgp bestpath compare-routerid",
1930 NO_STR
1931 "BGP specific commands\n"
1932 "Change the default bestpath selection\n"
1933 "Compare router-id for identical EBGP paths\n")
1934{
d62a17ae 1935 VTY_DECLVAR_CONTEXT(bgp, bgp);
1936 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1937 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1938
d62a17ae 1939 return CMD_SUCCESS;
718e3744 1940}
6b0655a2 1941
718e3744 1942/* "bgp bestpath as-path ignore" configuration. */
1943DEFUN (bgp_bestpath_aspath_ignore,
1944 bgp_bestpath_aspath_ignore_cmd,
1945 "bgp bestpath as-path ignore",
1946 "BGP specific commands\n"
1947 "Change the default bestpath selection\n"
1948 "AS-path attribute\n"
1949 "Ignore as-path length in selecting a route\n")
1950{
d62a17ae 1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
1952 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
1953 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1954
d62a17ae 1955 return CMD_SUCCESS;
718e3744 1956}
1957
1958DEFUN (no_bgp_bestpath_aspath_ignore,
1959 no_bgp_bestpath_aspath_ignore_cmd,
1960 "no bgp bestpath as-path ignore",
1961 NO_STR
1962 "BGP specific commands\n"
1963 "Change the default bestpath selection\n"
1964 "AS-path attribute\n"
1965 "Ignore as-path length in selecting a route\n")
1966{
d62a17ae 1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
1968 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
1969 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1970
d62a17ae 1971 return CMD_SUCCESS;
718e3744 1972}
6b0655a2 1973
6811845b 1974/* "bgp bestpath as-path confed" configuration. */
1975DEFUN (bgp_bestpath_aspath_confed,
1976 bgp_bestpath_aspath_confed_cmd,
1977 "bgp bestpath as-path confed",
1978 "BGP specific commands\n"
1979 "Change the default bestpath selection\n"
1980 "AS-path attribute\n"
1981 "Compare path lengths including confederation sets & sequences in selecting a route\n")
1982{
d62a17ae 1983 VTY_DECLVAR_CONTEXT(bgp, bgp);
1984 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
1985 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1986
d62a17ae 1987 return CMD_SUCCESS;
6811845b 1988}
1989
1990DEFUN (no_bgp_bestpath_aspath_confed,
1991 no_bgp_bestpath_aspath_confed_cmd,
1992 "no bgp bestpath as-path confed",
1993 NO_STR
1994 "BGP specific commands\n"
1995 "Change the default bestpath selection\n"
1996 "AS-path attribute\n"
1997 "Compare path lengths including confederation sets & sequences in selecting a route\n")
1998{
d62a17ae 1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2001 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2002
d62a17ae 2003 return CMD_SUCCESS;
6811845b 2004}
6b0655a2 2005
2fdd455c
PM
2006/* "bgp bestpath as-path multipath-relax" configuration. */
2007DEFUN (bgp_bestpath_aspath_multipath_relax,
2008 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2009 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2010 "BGP specific commands\n"
2011 "Change the default bestpath selection\n"
2012 "AS-path attribute\n"
2013 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2014 "Generate an AS_SET\n"
16fc1eec
DS
2015 "Do not generate an AS_SET\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 int idx = 0;
2019 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2020
d62a17ae 2021 /* no-as-set is now the default behavior so we can silently
2022 * ignore it */
2023 if (argv_find(argv, argc, "as-set", &idx))
2024 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2025 else
2026 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2027
d62a17ae 2028 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2029
d62a17ae 2030 return CMD_SUCCESS;
16fc1eec
DS
2031}
2032
219178b6
DW
2033DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2034 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2035 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2036 NO_STR
2037 "BGP specific commands\n"
2038 "Change the default bestpath selection\n"
2039 "AS-path attribute\n"
2040 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2041 "Generate an AS_SET\n"
16fc1eec
DS
2042 "Do not generate an AS_SET\n")
2043{
d62a17ae 2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2046 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2047 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2048
d62a17ae 2049 return CMD_SUCCESS;
2fdd455c 2050}
6b0655a2 2051
848973c7 2052/* "bgp log-neighbor-changes" configuration. */
2053DEFUN (bgp_log_neighbor_changes,
2054 bgp_log_neighbor_changes_cmd,
2055 "bgp log-neighbor-changes",
2056 "BGP specific commands\n"
2057 "Log neighbor up/down and reset reason\n")
2058{
d62a17ae 2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2061 return CMD_SUCCESS;
848973c7 2062}
2063
2064DEFUN (no_bgp_log_neighbor_changes,
2065 no_bgp_log_neighbor_changes_cmd,
2066 "no bgp log-neighbor-changes",
2067 NO_STR
2068 "BGP specific commands\n"
2069 "Log neighbor up/down and reset reason\n")
2070{
d62a17ae 2071 VTY_DECLVAR_CONTEXT(bgp, bgp);
2072 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2073 return CMD_SUCCESS;
848973c7 2074}
6b0655a2 2075
718e3744 2076/* "bgp bestpath med" configuration. */
2077DEFUN (bgp_bestpath_med,
2078 bgp_bestpath_med_cmd,
2d8c1a4d 2079 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2080 "BGP specific commands\n"
2081 "Change the default bestpath selection\n"
2082 "MED attribute\n"
2083 "Compare MED among confederation paths\n"
838758ac
DW
2084 "Treat missing MED as the least preferred one\n"
2085 "Treat missing MED as the least preferred one\n"
2086 "Compare MED among confederation paths\n")
718e3744 2087{
d62a17ae 2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2089
d62a17ae 2090 int idx = 0;
2091 if (argv_find(argv, argc, "confed", &idx))
2092 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2093 idx = 0;
2094 if (argv_find(argv, argc, "missing-as-worst", &idx))
2095 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2096
d62a17ae 2097 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2098
d62a17ae 2099 return CMD_SUCCESS;
718e3744 2100}
2101
718e3744 2102DEFUN (no_bgp_bestpath_med,
2103 no_bgp_bestpath_med_cmd,
2d8c1a4d 2104 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2105 NO_STR
2106 "BGP specific commands\n"
2107 "Change the default bestpath selection\n"
2108 "MED attribute\n"
2109 "Compare MED among confederation paths\n"
3a2d747c
QY
2110 "Treat missing MED as the least preferred one\n"
2111 "Treat missing MED as the least preferred one\n"
2112 "Compare MED among confederation paths\n")
718e3744 2113{
d62a17ae 2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2115
d62a17ae 2116 int idx = 0;
2117 if (argv_find(argv, argc, "confed", &idx))
2118 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2119 idx = 0;
2120 if (argv_find(argv, argc, "missing-as-worst", &idx))
2121 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2122
d62a17ae 2123 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2124
d62a17ae 2125 return CMD_SUCCESS;
718e3744 2126}
2127
718e3744 2128/* "no bgp default ipv4-unicast". */
2129DEFUN (no_bgp_default_ipv4_unicast,
2130 no_bgp_default_ipv4_unicast_cmd,
2131 "no bgp default ipv4-unicast",
2132 NO_STR
2133 "BGP specific commands\n"
2134 "Configure BGP defaults\n"
2135 "Activate ipv4-unicast for a peer by default\n")
2136{
d62a17ae 2137 VTY_DECLVAR_CONTEXT(bgp, bgp);
2138 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2139 return CMD_SUCCESS;
718e3744 2140}
2141
2142DEFUN (bgp_default_ipv4_unicast,
2143 bgp_default_ipv4_unicast_cmd,
2144 "bgp default ipv4-unicast",
2145 "BGP specific commands\n"
2146 "Configure BGP defaults\n"
2147 "Activate ipv4-unicast for a peer by default\n")
2148{
d62a17ae 2149 VTY_DECLVAR_CONTEXT(bgp, bgp);
2150 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2151 return CMD_SUCCESS;
718e3744 2152}
6b0655a2 2153
04b6bdc0
DW
2154/* Display hostname in certain command outputs */
2155DEFUN (bgp_default_show_hostname,
2156 bgp_default_show_hostname_cmd,
2157 "bgp default show-hostname",
2158 "BGP specific commands\n"
2159 "Configure BGP defaults\n"
2160 "Show hostname in certain command ouputs\n")
2161{
d62a17ae 2162 VTY_DECLVAR_CONTEXT(bgp, bgp);
2163 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2164 return CMD_SUCCESS;
04b6bdc0
DW
2165}
2166
2167DEFUN (no_bgp_default_show_hostname,
2168 no_bgp_default_show_hostname_cmd,
2169 "no bgp default show-hostname",
2170 NO_STR
2171 "BGP specific commands\n"
2172 "Configure BGP defaults\n"
2173 "Show hostname in certain command ouputs\n")
2174{
d62a17ae 2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2177 return CMD_SUCCESS;
04b6bdc0
DW
2178}
2179
8233ef81 2180/* "bgp network import-check" configuration. */
718e3744 2181DEFUN (bgp_network_import_check,
2182 bgp_network_import_check_cmd,
5623e905 2183 "bgp network import-check",
718e3744 2184 "BGP specific commands\n"
2185 "BGP network command\n"
5623e905 2186 "Check BGP network route exists in IGP\n")
718e3744 2187{
d62a17ae 2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2190 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2191 bgp_static_redo_import_check(bgp);
2192 }
078430f6 2193
d62a17ae 2194 return CMD_SUCCESS;
718e3744 2195}
2196
d62a17ae 2197ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2198 "bgp network import-check exact",
2199 "BGP specific commands\n"
2200 "BGP network command\n"
2201 "Check BGP network route exists in IGP\n"
2202 "Match route precisely\n")
8233ef81 2203
718e3744 2204DEFUN (no_bgp_network_import_check,
2205 no_bgp_network_import_check_cmd,
5623e905 2206 "no bgp network import-check",
718e3744 2207 NO_STR
2208 "BGP specific commands\n"
2209 "BGP network command\n"
2210 "Check BGP network route exists in IGP\n")
2211{
d62a17ae 2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2214 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2215 bgp_static_redo_import_check(bgp);
2216 }
5623e905 2217
d62a17ae 2218 return CMD_SUCCESS;
718e3744 2219}
6b0655a2 2220
718e3744 2221DEFUN (bgp_default_local_preference,
2222 bgp_default_local_preference_cmd,
6147e2c6 2223 "bgp default local-preference (0-4294967295)",
718e3744 2224 "BGP specific commands\n"
2225 "Configure BGP defaults\n"
2226 "local preference (higher=more preferred)\n"
2227 "Configure default local preference value\n")
2228{
d62a17ae 2229 VTY_DECLVAR_CONTEXT(bgp, bgp);
2230 int idx_number = 3;
2231 u_int32_t local_pref;
718e3744 2232
d62a17ae 2233 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2234
d62a17ae 2235 bgp_default_local_preference_set(bgp, local_pref);
2236 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2237
d62a17ae 2238 return CMD_SUCCESS;
718e3744 2239}
2240
2241DEFUN (no_bgp_default_local_preference,
2242 no_bgp_default_local_preference_cmd,
838758ac 2243 "no bgp default local-preference [(0-4294967295)]",
718e3744 2244 NO_STR
2245 "BGP specific commands\n"
2246 "Configure BGP defaults\n"
838758ac
DW
2247 "local preference (higher=more preferred)\n"
2248 "Configure default local preference value\n")
718e3744 2249{
d62a17ae 2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
2251 bgp_default_local_preference_unset(bgp);
2252 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2253
d62a17ae 2254 return CMD_SUCCESS;
718e3744 2255}
2256
6b0655a2 2257
3f9c7369
DS
2258DEFUN (bgp_default_subgroup_pkt_queue_max,
2259 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2260 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2261 "BGP specific commands\n"
2262 "Configure BGP defaults\n"
2263 "subgroup-pkt-queue-max\n"
2264 "Configure subgroup packet queue max\n")
8bd9d948 2265{
d62a17ae 2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 int idx_number = 3;
2268 u_int32_t max_size;
8bd9d948 2269
d62a17ae 2270 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2271
d62a17ae 2272 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2273
d62a17ae 2274 return CMD_SUCCESS;
3f9c7369
DS
2275}
2276
2277DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2278 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2279 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2280 NO_STR
2281 "BGP specific commands\n"
2282 "Configure BGP defaults\n"
838758ac
DW
2283 "subgroup-pkt-queue-max\n"
2284 "Configure subgroup packet queue max\n")
3f9c7369 2285{
d62a17ae 2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2288 return CMD_SUCCESS;
8bd9d948
DS
2289}
2290
813d4307 2291
8bd9d948
DS
2292DEFUN (bgp_rr_allow_outbound_policy,
2293 bgp_rr_allow_outbound_policy_cmd,
2294 "bgp route-reflector allow-outbound-policy",
2295 "BGP specific commands\n"
2296 "Allow modifications made by out route-map\n"
2297 "on ibgp neighbors\n")
2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2300
d62a17ae 2301 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2302 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2303 update_group_announce_rrclients(bgp);
2304 bgp_clear_star_soft_out(vty, bgp->name);
2305 }
8bd9d948 2306
d62a17ae 2307 return CMD_SUCCESS;
8bd9d948
DS
2308}
2309
2310DEFUN (no_bgp_rr_allow_outbound_policy,
2311 no_bgp_rr_allow_outbound_policy_cmd,
2312 "no bgp route-reflector allow-outbound-policy",
2313 NO_STR
2314 "BGP specific commands\n"
2315 "Allow modifications made by out route-map\n"
2316 "on ibgp neighbors\n")
2317{
d62a17ae 2318 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2319
d62a17ae 2320 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2321 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2322 update_group_announce_rrclients(bgp);
2323 bgp_clear_star_soft_out(vty, bgp->name);
2324 }
8bd9d948 2325
d62a17ae 2326 return CMD_SUCCESS;
8bd9d948
DS
2327}
2328
f14e6fdb
DS
2329DEFUN (bgp_listen_limit,
2330 bgp_listen_limit_cmd,
9ccf14f7 2331 "bgp listen limit (1-5000)",
f14e6fdb
DS
2332 "BGP specific commands\n"
2333 "Configure BGP defaults\n"
2334 "maximum number of BGP Dynamic Neighbors that can be created\n"
2335 "Configure Dynamic Neighbors listen limit value\n")
2336{
d62a17ae 2337 VTY_DECLVAR_CONTEXT(bgp, bgp);
2338 int idx_number = 3;
2339 int listen_limit;
f14e6fdb 2340
d62a17ae 2341 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2342
d62a17ae 2343 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2344
d62a17ae 2345 return CMD_SUCCESS;
f14e6fdb
DS
2346}
2347
2348DEFUN (no_bgp_listen_limit,
2349 no_bgp_listen_limit_cmd,
838758ac 2350 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2351 "BGP specific commands\n"
2352 "Configure BGP defaults\n"
2353 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2354 "Configure Dynamic Neighbors listen limit value to default\n"
2355 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2356{
d62a17ae 2357 VTY_DECLVAR_CONTEXT(bgp, bgp);
2358 bgp_listen_limit_unset(bgp);
2359 return CMD_SUCCESS;
f14e6fdb
DS
2360}
2361
2362
20eb8864 2363/*
2364 * Check if this listen range is already configured. Check for exact
2365 * match or overlap based on input.
2366 */
d62a17ae 2367static struct peer_group *listen_range_exists(struct bgp *bgp,
2368 struct prefix *range, int exact)
2369{
2370 struct listnode *node, *nnode;
2371 struct listnode *node1, *nnode1;
2372 struct peer_group *group;
2373 struct prefix *lr;
2374 afi_t afi;
2375 int match;
2376
2377 afi = family2afi(range->family);
2378 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2379 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2380 lr)) {
2381 if (exact)
2382 match = prefix_same(range, lr);
2383 else
2384 match = (prefix_match(range, lr)
2385 || prefix_match(lr, range));
2386 if (match)
2387 return group;
2388 }
2389 }
2390
2391 return NULL;
20eb8864 2392}
2393
f14e6fdb
DS
2394DEFUN (bgp_listen_range,
2395 bgp_listen_range_cmd,
9ccf14f7 2396 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2397 "BGP specific commands\n"
d7fa34c1
QY
2398 "Configure BGP dynamic neighbors listen range\n"
2399 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2400 NEIGHBOR_ADDR_STR
2401 "Member of the peer-group\n"
2402 "Peer-group name\n")
f14e6fdb 2403{
d62a17ae 2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 struct prefix range;
2406 struct peer_group *group, *existing_group;
2407 afi_t afi;
2408 int ret;
2409 int idx = 0;
2410
2411 argv_find(argv, argc, "A.B.C.D/M", &idx);
2412 argv_find(argv, argc, "X:X::X:X/M", &idx);
2413 char *prefix = argv[idx]->arg;
2414 argv_find(argv, argc, "WORD", &idx);
2415 char *peergroup = argv[idx]->arg;
2416
2417 /* Convert IP prefix string to struct prefix. */
2418 ret = str2prefix(prefix, &range);
2419 if (!ret) {
2420 vty_out(vty, "%% Malformed listen range\n");
2421 return CMD_WARNING_CONFIG_FAILED;
2422 }
2423
2424 afi = family2afi(range.family);
2425
2426 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2427 vty_out(vty,
2428 "%% Malformed listen range (link-local address)\n");
2429 return CMD_WARNING_CONFIG_FAILED;
2430 }
2431
2432 apply_mask(&range);
2433
2434 /* Check if same listen range is already configured. */
2435 existing_group = listen_range_exists(bgp, &range, 1);
2436 if (existing_group) {
2437 if (strcmp(existing_group->name, peergroup) == 0)
2438 return CMD_SUCCESS;
2439 else {
2440 vty_out(vty,
2441 "%% Same listen range is attached to peer-group %s\n",
2442 existing_group->name);
2443 return CMD_WARNING_CONFIG_FAILED;
2444 }
2445 }
2446
2447 /* Check if an overlapping listen range exists. */
2448 if (listen_range_exists(bgp, &range, 0)) {
2449 vty_out(vty,
2450 "%% Listen range overlaps with existing listen range\n");
2451 return CMD_WARNING_CONFIG_FAILED;
2452 }
2453
2454 group = peer_group_lookup(bgp, peergroup);
2455 if (!group) {
2456 vty_out(vty, "%% Configure the peer-group first\n");
2457 return CMD_WARNING_CONFIG_FAILED;
2458 }
2459
2460 ret = peer_group_listen_range_add(group, &range);
2461 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2462}
2463
2464DEFUN (no_bgp_listen_range,
2465 no_bgp_listen_range_cmd,
d7fa34c1
QY
2466 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2467 NO_STR
f14e6fdb 2468 "BGP specific commands\n"
d7fa34c1
QY
2469 "Unconfigure BGP dynamic neighbors listen range\n"
2470 "Unconfigure BGP dynamic neighbors listen range\n"
2471 NEIGHBOR_ADDR_STR
2472 "Member of the peer-group\n"
2473 "Peer-group name\n")
f14e6fdb 2474{
d62a17ae 2475 VTY_DECLVAR_CONTEXT(bgp, bgp);
2476 struct prefix range;
2477 struct peer_group *group;
2478 afi_t afi;
2479 int ret;
2480 int idx = 0;
2481
2482 argv_find(argv, argc, "A.B.C.D/M", &idx);
2483 argv_find(argv, argc, "X:X::X:X/M", &idx);
2484 char *prefix = argv[idx]->arg;
2485 argv_find(argv, argc, "WORD", &idx);
2486 char *peergroup = argv[idx]->arg;
2487
2488 /* Convert IP prefix string to struct prefix. */
2489 ret = str2prefix(prefix, &range);
2490 if (!ret) {
2491 vty_out(vty, "%% Malformed listen range\n");
2492 return CMD_WARNING_CONFIG_FAILED;
2493 }
2494
2495 afi = family2afi(range.family);
2496
2497 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2498 vty_out(vty,
2499 "%% Malformed listen range (link-local address)\n");
2500 return CMD_WARNING_CONFIG_FAILED;
2501 }
2502
2503 apply_mask(&range);
2504
2505 group = peer_group_lookup(bgp, peergroup);
2506 if (!group) {
2507 vty_out(vty, "%% Peer-group does not exist\n");
2508 return CMD_WARNING_CONFIG_FAILED;
2509 }
2510
2511 ret = peer_group_listen_range_del(group, &range);
2512 return bgp_vty_return(vty, ret);
2513}
2514
2b791107 2515void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2516{
2517 struct peer_group *group;
2518 struct listnode *node, *nnode, *rnode, *nrnode;
2519 struct prefix *range;
2520 afi_t afi;
2521 char buf[PREFIX2STR_BUFFER];
2522
2523 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2524 vty_out(vty, " bgp listen limit %d\n",
2525 bgp->dynamic_neighbors_limit);
2526
2527 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2528 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2529 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2530 nrnode, range)) {
2531 prefix2str(range, buf, sizeof(buf));
2532 vty_out(vty,
2533 " bgp listen range %s peer-group %s\n",
2534 buf, group->name);
2535 }
2536 }
2537 }
f14e6fdb
DS
2538}
2539
2540
907f92c8
DS
2541DEFUN (bgp_disable_connected_route_check,
2542 bgp_disable_connected_route_check_cmd,
2543 "bgp disable-ebgp-connected-route-check",
2544 "BGP specific commands\n"
2545 "Disable checking if nexthop is connected on ebgp sessions\n")
2546{
d62a17ae 2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
2548 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2549 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2550
d62a17ae 2551 return CMD_SUCCESS;
907f92c8
DS
2552}
2553
2554DEFUN (no_bgp_disable_connected_route_check,
2555 no_bgp_disable_connected_route_check_cmd,
2556 "no bgp disable-ebgp-connected-route-check",
2557 NO_STR
2558 "BGP specific commands\n"
2559 "Disable checking if nexthop is connected on ebgp sessions\n")
2560{
d62a17ae 2561 VTY_DECLVAR_CONTEXT(bgp, bgp);
2562 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2563 bgp_clear_star_soft_in(vty, bgp->name);
2564
2565 return CMD_SUCCESS;
2566}
2567
2568
2569static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2570 const char *as_str, afi_t afi, safi_t safi)
2571{
2572 VTY_DECLVAR_CONTEXT(bgp, bgp);
2573 int ret;
2574 as_t as;
2575 int as_type = AS_SPECIFIED;
2576 union sockunion su;
2577
2578 if (as_str[0] == 'i') {
2579 as = 0;
2580 as_type = AS_INTERNAL;
2581 } else if (as_str[0] == 'e') {
2582 as = 0;
2583 as_type = AS_EXTERNAL;
2584 } else {
2585 /* Get AS number. */
2586 as = strtoul(as_str, NULL, 10);
2587 }
2588
2589 /* If peer is peer group, call proper function. */
2590 ret = str2sockunion(peer_str, &su);
2591 if (ret < 0) {
2592 /* Check for peer by interface */
2593 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2594 safi);
2595 if (ret < 0) {
2596 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2597 if (ret < 0) {
2598 vty_out(vty,
2599 "%% Create the peer-group or interface first\n");
2600 return CMD_WARNING_CONFIG_FAILED;
2601 }
2602 return CMD_SUCCESS;
2603 }
2604 } else {
2605 if (peer_address_self_check(bgp, &su)) {
2606 vty_out(vty,
2607 "%% Can not configure the local system as neighbor\n");
2608 return CMD_WARNING_CONFIG_FAILED;
2609 }
2610 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2611 }
2612
2613 /* This peer belongs to peer group. */
2614 switch (ret) {
2615 case BGP_ERR_PEER_GROUP_MEMBER:
2616 vty_out(vty,
2617 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2618 as);
2619 return CMD_WARNING_CONFIG_FAILED;
2620 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2621 vty_out(vty,
2622 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2623 as, as_str);
2624 return CMD_WARNING_CONFIG_FAILED;
2625 }
2626 return bgp_vty_return(vty, ret);
718e3744 2627}
2628
2629DEFUN (neighbor_remote_as,
2630 neighbor_remote_as_cmd,
3a2d747c 2631 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2632 NEIGHBOR_STR
2633 NEIGHBOR_ADDR_STR2
2634 "Specify a BGP neighbor\n"
d7fa34c1 2635 AS_STR
3a2d747c
QY
2636 "Internal BGP peer\n"
2637 "External BGP peer\n")
718e3744 2638{
d62a17ae 2639 int idx_peer = 1;
2640 int idx_remote_as = 3;
2641 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2642 argv[idx_remote_as]->arg, AFI_IP,
2643 SAFI_UNICAST);
2644}
2645
2646static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2647 afi_t afi, safi_t safi, int v6only,
2648 const char *peer_group_name,
2649 const char *as_str)
2650{
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 as_t as = 0;
2653 int as_type = AS_UNSPECIFIED;
2654 struct peer *peer;
2655 struct peer_group *group;
2656 int ret = 0;
2657 union sockunion su;
2658
2659 group = peer_group_lookup(bgp, conf_if);
2660
2661 if (group) {
2662 vty_out(vty, "%% Name conflict with peer-group \n");
2663 return CMD_WARNING_CONFIG_FAILED;
2664 }
2665
2666 if (as_str) {
2667 if (as_str[0] == 'i') {
2668 as_type = AS_INTERNAL;
2669 } else if (as_str[0] == 'e') {
2670 as_type = AS_EXTERNAL;
2671 } else {
2672 /* Get AS number. */
2673 as = strtoul(as_str, NULL, 10);
2674 as_type = AS_SPECIFIED;
2675 }
2676 }
2677
2678 peer = peer_lookup_by_conf_if(bgp, conf_if);
2679 if (peer) {
2680 if (as_str)
2681 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2682 afi, safi);
2683 } else {
2684 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2685 && afi == AFI_IP && safi == SAFI_UNICAST)
2686 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2687 as_type, 0, 0, NULL);
2688 else
2689 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2690 as_type, afi, safi, NULL);
2691
2692 if (!peer) {
2693 vty_out(vty, "%% BGP failed to create peer\n");
2694 return CMD_WARNING_CONFIG_FAILED;
2695 }
2696
2697 if (v6only)
2698 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2699
2700 /* Request zebra to initiate IPv6 RAs on this interface. We do
2701 * this
2702 * any unnumbered peer in order to not worry about run-time
2703 * transitions
2704 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2705 * address
2706 * gets deleted later etc.)
2707 */
2708 if (peer->ifp)
2709 bgp_zebra_initiate_radv(bgp, peer);
2710 }
2711
2712 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2713 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2714 if (v6only)
2715 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2716 else
2717 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2718
2719 /* v6only flag changed. Reset bgp seesion */
2720 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2721 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2722 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2723 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2724 } else
2725 bgp_session_reset(peer);
2726 }
2727
2728 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2729 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2730
2731 if (peer_group_name) {
2732 group = peer_group_lookup(bgp, peer_group_name);
2733 if (!group) {
2734 vty_out(vty, "%% Configure the peer-group first\n");
2735 return CMD_WARNING_CONFIG_FAILED;
2736 }
2737
2738 ret = peer_group_bind(bgp, &su, peer, group, &as);
2739 }
2740
2741 return bgp_vty_return(vty, ret);
a80beece
DS
2742}
2743
4c48cf63
DW
2744DEFUN (neighbor_interface_config,
2745 neighbor_interface_config_cmd,
31500417 2746 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2747 NEIGHBOR_STR
2748 "Interface name or neighbor tag\n"
31500417
DW
2749 "Enable BGP on interface\n"
2750 "Member of the peer-group\n"
16cedbb0 2751 "Peer-group name\n")
4c48cf63 2752{
d62a17ae 2753 int idx_word = 1;
2754 int idx_peer_group_word = 4;
31500417 2755
d62a17ae 2756 if (argc > idx_peer_group_word)
2757 return peer_conf_interface_get(
2758 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2759 argv[idx_peer_group_word]->arg, NULL);
2760 else
2761 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2762 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2763}
2764
4c48cf63
DW
2765DEFUN (neighbor_interface_config_v6only,
2766 neighbor_interface_config_v6only_cmd,
31500417 2767 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2768 NEIGHBOR_STR
2769 "Interface name or neighbor tag\n"
2770 "Enable BGP on interface\n"
31500417
DW
2771 "Enable BGP with v6 link-local only\n"
2772 "Member of the peer-group\n"
16cedbb0 2773 "Peer-group name\n")
4c48cf63 2774{
d62a17ae 2775 int idx_word = 1;
2776 int idx_peer_group_word = 5;
31500417 2777
d62a17ae 2778 if (argc > idx_peer_group_word)
2779 return peer_conf_interface_get(
2780 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2781 argv[idx_peer_group_word]->arg, NULL);
31500417 2782
d62a17ae 2783 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2784 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2785}
2786
a80beece 2787
b3a39dc5
DD
2788DEFUN (neighbor_interface_config_remote_as,
2789 neighbor_interface_config_remote_as_cmd,
3a2d747c 2790 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2791 NEIGHBOR_STR
2792 "Interface name or neighbor tag\n"
2793 "Enable BGP on interface\n"
3a2d747c 2794 "Specify a BGP neighbor\n"
d7fa34c1 2795 AS_STR
3a2d747c
QY
2796 "Internal BGP peer\n"
2797 "External BGP peer\n")
b3a39dc5 2798{
d62a17ae 2799 int idx_word = 1;
2800 int idx_remote_as = 4;
2801 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2802 SAFI_UNICAST, 0, NULL,
2803 argv[idx_remote_as]->arg);
b3a39dc5
DD
2804}
2805
2806DEFUN (neighbor_interface_v6only_config_remote_as,
2807 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2808 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2809 NEIGHBOR_STR
2810 "Interface name or neighbor tag\n"
3a2d747c 2811 "Enable BGP with v6 link-local only\n"
b3a39dc5 2812 "Enable BGP on interface\n"
3a2d747c 2813 "Specify a BGP neighbor\n"
d7fa34c1 2814 AS_STR
3a2d747c
QY
2815 "Internal BGP peer\n"
2816 "External BGP peer\n")
b3a39dc5 2817{
d62a17ae 2818 int idx_word = 1;
2819 int idx_remote_as = 5;
2820 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2821 SAFI_UNICAST, 1, NULL,
2822 argv[idx_remote_as]->arg);
b3a39dc5
DD
2823}
2824
718e3744 2825DEFUN (neighbor_peer_group,
2826 neighbor_peer_group_cmd,
2827 "neighbor WORD peer-group",
2828 NEIGHBOR_STR
a80beece 2829 "Interface name or neighbor tag\n"
718e3744 2830 "Configure peer-group\n")
2831{
d62a17ae 2832 VTY_DECLVAR_CONTEXT(bgp, bgp);
2833 int idx_word = 1;
2834 struct peer *peer;
2835 struct peer_group *group;
718e3744 2836
d62a17ae 2837 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2838 if (peer) {
2839 vty_out(vty, "%% Name conflict with interface: \n");
2840 return CMD_WARNING_CONFIG_FAILED;
2841 }
718e3744 2842
d62a17ae 2843 group = peer_group_get(bgp, argv[idx_word]->arg);
2844 if (!group) {
2845 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2846 return CMD_WARNING_CONFIG_FAILED;
2847 }
718e3744 2848
d62a17ae 2849 return CMD_SUCCESS;
718e3744 2850}
2851
2852DEFUN (no_neighbor,
2853 no_neighbor_cmd,
dab8cd00 2854 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2855 NO_STR
2856 NEIGHBOR_STR
3a2d747c
QY
2857 NEIGHBOR_ADDR_STR2
2858 "Specify a BGP neighbor\n"
2859 AS_STR
2860 "Internal BGP peer\n"
2861 "External BGP peer\n")
718e3744 2862{
d62a17ae 2863 VTY_DECLVAR_CONTEXT(bgp, bgp);
2864 int idx_peer = 2;
2865 int ret;
2866 union sockunion su;
2867 struct peer_group *group;
2868 struct peer *peer;
2869 struct peer *other;
2870
2871 ret = str2sockunion(argv[idx_peer]->arg, &su);
2872 if (ret < 0) {
2873 /* look up for neighbor by interface name config. */
2874 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2875 if (peer) {
2876 /* Request zebra to terminate IPv6 RAs on this
2877 * interface. */
2878 if (peer->ifp)
2879 bgp_zebra_terminate_radv(peer->bgp, peer);
2880 peer_delete(peer);
2881 return CMD_SUCCESS;
2882 }
f14e6fdb 2883
d62a17ae 2884 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2885 if (group)
2886 peer_group_delete(group);
2887 else {
2888 vty_out(vty, "%% Create the peer-group first\n");
2889 return CMD_WARNING_CONFIG_FAILED;
2890 }
2891 } else {
2892 peer = peer_lookup(bgp, &su);
2893 if (peer) {
2894 if (peer_dynamic_neighbor(peer)) {
2895 vty_out(vty,
2896 "%% Operation not allowed on a dynamic neighbor\n");
2897 return CMD_WARNING_CONFIG_FAILED;
2898 }
2899
2900 other = peer->doppelganger;
2901 peer_delete(peer);
2902 if (other && other->status != Deleted)
2903 peer_delete(other);
2904 }
1ff9a340 2905 }
718e3744 2906
d62a17ae 2907 return CMD_SUCCESS;
718e3744 2908}
2909
a80beece
DS
2910DEFUN (no_neighbor_interface_config,
2911 no_neighbor_interface_config_cmd,
31500417 2912 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2913 NO_STR
2914 NEIGHBOR_STR
2915 "Interface name\n"
31500417
DW
2916 "Configure BGP on interface\n"
2917 "Enable BGP with v6 link-local only\n"
2918 "Member of the peer-group\n"
16cedbb0 2919 "Peer-group name\n"
3a2d747c
QY
2920 "Specify a BGP neighbor\n"
2921 AS_STR
2922 "Internal BGP peer\n"
2923 "External BGP peer\n")
a80beece 2924{
d62a17ae 2925 VTY_DECLVAR_CONTEXT(bgp, bgp);
2926 int idx_word = 2;
2927 struct peer *peer;
2928
2929 /* look up for neighbor by interface name config. */
2930 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2931 if (peer) {
2932 /* Request zebra to terminate IPv6 RAs on this interface. */
2933 if (peer->ifp)
2934 bgp_zebra_terminate_radv(peer->bgp, peer);
2935 peer_delete(peer);
2936 } else {
2937 vty_out(vty, "%% Create the bgp interface first\n");
2938 return CMD_WARNING_CONFIG_FAILED;
2939 }
2940 return CMD_SUCCESS;
a80beece
DS
2941}
2942
718e3744 2943DEFUN (no_neighbor_peer_group,
2944 no_neighbor_peer_group_cmd,
2945 "no neighbor WORD peer-group",
2946 NO_STR
2947 NEIGHBOR_STR
2948 "Neighbor tag\n"
2949 "Configure peer-group\n")
2950{
d62a17ae 2951 VTY_DECLVAR_CONTEXT(bgp, bgp);
2952 int idx_word = 2;
2953 struct peer_group *group;
718e3744 2954
d62a17ae 2955 group = peer_group_lookup(bgp, argv[idx_word]->arg);
2956 if (group)
2957 peer_group_delete(group);
2958 else {
2959 vty_out(vty, "%% Create the peer-group first\n");
2960 return CMD_WARNING_CONFIG_FAILED;
2961 }
2962 return CMD_SUCCESS;
718e3744 2963}
2964
a80beece
DS
2965DEFUN (no_neighbor_interface_peer_group_remote_as,
2966 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 2967 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 2968 NO_STR
2969 NEIGHBOR_STR
a80beece 2970 "Interface name or neighbor tag\n"
718e3744 2971 "Specify a BGP neighbor\n"
3a2d747c
QY
2972 AS_STR
2973 "Internal BGP peer\n"
2974 "External BGP peer\n")
718e3744 2975{
d62a17ae 2976 VTY_DECLVAR_CONTEXT(bgp, bgp);
2977 int idx_word = 2;
2978 struct peer_group *group;
2979 struct peer *peer;
2980
2981 /* look up for neighbor by interface name config. */
2982 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2983 if (peer) {
2984 peer_as_change(peer, 0, AS_SPECIFIED);
2985 return CMD_SUCCESS;
2986 }
2987
2988 group = peer_group_lookup(bgp, argv[idx_word]->arg);
2989 if (group)
2990 peer_group_remote_as_delete(group);
2991 else {
2992 vty_out(vty, "%% Create the peer-group or interface first\n");
2993 return CMD_WARNING_CONFIG_FAILED;
2994 }
2995 return CMD_SUCCESS;
718e3744 2996}
6b0655a2 2997
718e3744 2998DEFUN (neighbor_local_as,
2999 neighbor_local_as_cmd,
9ccf14f7 3000 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3001 NEIGHBOR_STR
3002 NEIGHBOR_ADDR_STR2
3003 "Specify a local-as number\n"
3004 "AS number used as local AS\n")
3005{
d62a17ae 3006 int idx_peer = 1;
3007 int idx_number = 3;
3008 struct peer *peer;
3009 int ret;
3010 as_t as;
718e3744 3011
d62a17ae 3012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3013 if (!peer)
3014 return CMD_WARNING_CONFIG_FAILED;
718e3744 3015
d62a17ae 3016 as = strtoul(argv[idx_number]->arg, NULL, 10);
3017 ret = peer_local_as_set(peer, as, 0, 0);
3018 return bgp_vty_return(vty, ret);
718e3744 3019}
3020
3021DEFUN (neighbor_local_as_no_prepend,
3022 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3023 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3024 NEIGHBOR_STR
3025 NEIGHBOR_ADDR_STR2
3026 "Specify a local-as number\n"
3027 "AS number used as local AS\n"
3028 "Do not prepend local-as to updates from ebgp peers\n")
3029{
d62a17ae 3030 int idx_peer = 1;
3031 int idx_number = 3;
3032 struct peer *peer;
3033 int ret;
3034 as_t as;
718e3744 3035
d62a17ae 3036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3037 if (!peer)
3038 return CMD_WARNING_CONFIG_FAILED;
718e3744 3039
d62a17ae 3040 as = strtoul(argv[idx_number]->arg, NULL, 10);
3041 ret = peer_local_as_set(peer, as, 1, 0);
3042 return bgp_vty_return(vty, ret);
718e3744 3043}
3044
9d3f9705
AC
3045DEFUN (neighbor_local_as_no_prepend_replace_as,
3046 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3047 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3048 NEIGHBOR_STR
3049 NEIGHBOR_ADDR_STR2
3050 "Specify a local-as number\n"
3051 "AS number used as local AS\n"
3052 "Do not prepend local-as to updates from ebgp peers\n"
3053 "Do not prepend local-as to updates from ibgp peers\n")
3054{
d62a17ae 3055 int idx_peer = 1;
3056 int idx_number = 3;
3057 struct peer *peer;
3058 int ret;
3059 as_t as;
9d3f9705 3060
d62a17ae 3061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3062 if (!peer)
3063 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3064
d62a17ae 3065 as = strtoul(argv[idx_number]->arg, NULL, 10);
3066 ret = peer_local_as_set(peer, as, 1, 1);
3067 return bgp_vty_return(vty, ret);
9d3f9705
AC
3068}
3069
718e3744 3070DEFUN (no_neighbor_local_as,
3071 no_neighbor_local_as_cmd,
a636c635 3072 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3073 NO_STR
3074 NEIGHBOR_STR
3075 NEIGHBOR_ADDR_STR2
a636c635
DW
3076 "Specify a local-as number\n"
3077 "AS number used as local AS\n"
3078 "Do not prepend local-as to updates from ebgp peers\n"
3079 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3080{
d62a17ae 3081 int idx_peer = 2;
3082 struct peer *peer;
3083 int ret;
718e3744 3084
d62a17ae 3085 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3086 if (!peer)
3087 return CMD_WARNING_CONFIG_FAILED;
718e3744 3088
d62a17ae 3089 ret = peer_local_as_unset(peer);
3090 return bgp_vty_return(vty, ret);
718e3744 3091}
3092
718e3744 3093
3f9c7369
DS
3094DEFUN (neighbor_solo,
3095 neighbor_solo_cmd,
9ccf14f7 3096 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3097 NEIGHBOR_STR
3098 NEIGHBOR_ADDR_STR2
3099 "Solo peer - part of its own update group\n")
3100{
d62a17ae 3101 int idx_peer = 1;
3102 struct peer *peer;
3103 int ret;
3f9c7369 3104
d62a17ae 3105 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3106 if (!peer)
3107 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3108
d62a17ae 3109 ret = update_group_adjust_soloness(peer, 1);
3110 return bgp_vty_return(vty, ret);
3f9c7369
DS
3111}
3112
3113DEFUN (no_neighbor_solo,
3114 no_neighbor_solo_cmd,
9ccf14f7 3115 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3116 NO_STR
3117 NEIGHBOR_STR
3118 NEIGHBOR_ADDR_STR2
3119 "Solo peer - part of its own update group\n")
3120{
d62a17ae 3121 int idx_peer = 2;
3122 struct peer *peer;
3123 int ret;
3f9c7369 3124
d62a17ae 3125 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3126 if (!peer)
3127 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3128
d62a17ae 3129 ret = update_group_adjust_soloness(peer, 0);
3130 return bgp_vty_return(vty, ret);
3f9c7369
DS
3131}
3132
0df7c91f
PJ
3133DEFUN (neighbor_password,
3134 neighbor_password_cmd,
9ccf14f7 3135 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3136 NEIGHBOR_STR
3137 NEIGHBOR_ADDR_STR2
3138 "Set a password\n"
3139 "The password\n")
3140{
d62a17ae 3141 int idx_peer = 1;
3142 int idx_line = 3;
3143 struct peer *peer;
3144 int ret;
0df7c91f 3145
d62a17ae 3146 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3147 if (!peer)
3148 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3149
d62a17ae 3150 ret = peer_password_set(peer, argv[idx_line]->arg);
3151 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3152}
3153
3154DEFUN (no_neighbor_password,
3155 no_neighbor_password_cmd,
a636c635 3156 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3157 NO_STR
3158 NEIGHBOR_STR
3159 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3160 "Set a password\n"
3161 "The password\n")
0df7c91f 3162{
d62a17ae 3163 int idx_peer = 2;
3164 struct peer *peer;
3165 int ret;
0df7c91f 3166
d62a17ae 3167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3168 if (!peer)
3169 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3170
d62a17ae 3171 ret = peer_password_unset(peer);
3172 return bgp_vty_return(vty, ret);
0df7c91f 3173}
6b0655a2 3174
813d4307 3175
718e3744 3176DEFUN (neighbor_activate,
3177 neighbor_activate_cmd,
9ccf14f7 3178 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3179 NEIGHBOR_STR
3180 NEIGHBOR_ADDR_STR2
3181 "Enable the Address Family for this Neighbor\n")
3182{
d62a17ae 3183 int idx_peer = 1;
3184 int ret;
3185 struct peer *peer;
718e3744 3186
d62a17ae 3187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3188 if (!peer)
3189 return CMD_WARNING_CONFIG_FAILED;
718e3744 3190
d62a17ae 3191 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3192 return bgp_vty_return(vty, ret);
718e3744 3193}
3194
d62a17ae 3195ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3196 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3197 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3198 "Enable the Address Family for this Neighbor\n")
596c17ba 3199
718e3744 3200DEFUN (no_neighbor_activate,
3201 no_neighbor_activate_cmd,
9ccf14f7 3202 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3203 NO_STR
3204 NEIGHBOR_STR
3205 NEIGHBOR_ADDR_STR2
3206 "Enable the Address Family for this Neighbor\n")
3207{
d62a17ae 3208 int idx_peer = 2;
3209 int ret;
3210 struct peer *peer;
718e3744 3211
d62a17ae 3212 /* Lookup peer. */
3213 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3214 if (!peer)
3215 return CMD_WARNING_CONFIG_FAILED;
718e3744 3216
d62a17ae 3217 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3218 return bgp_vty_return(vty, ret);
718e3744 3219}
6b0655a2 3220
d62a17ae 3221ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3222 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3223 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3224 "Enable the Address Family for this Neighbor\n")
596c17ba 3225
718e3744 3226DEFUN (neighbor_set_peer_group,
3227 neighbor_set_peer_group_cmd,
9ccf14f7 3228 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3229 NEIGHBOR_STR
a80beece 3230 NEIGHBOR_ADDR_STR2
718e3744 3231 "Member of the peer-group\n"
16cedbb0 3232 "Peer-group name\n")
718e3744 3233{
d62a17ae 3234 VTY_DECLVAR_CONTEXT(bgp, bgp);
3235 int idx_peer = 1;
3236 int idx_word = 3;
3237 int ret;
3238 as_t as;
3239 union sockunion su;
3240 struct peer *peer;
3241 struct peer_group *group;
3242
3243 peer = NULL;
3244
3245 ret = str2sockunion(argv[idx_peer]->arg, &su);
3246 if (ret < 0) {
3247 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3248 if (!peer) {
3249 vty_out(vty, "%% Malformed address or name: %s\n",
3250 argv[idx_peer]->arg);
3251 return CMD_WARNING_CONFIG_FAILED;
3252 }
3253 } else {
3254 if (peer_address_self_check(bgp, &su)) {
3255 vty_out(vty,
3256 "%% Can not configure the local system as neighbor\n");
3257 return CMD_WARNING_CONFIG_FAILED;
3258 }
3259
3260 /* Disallow for dynamic neighbor. */
3261 peer = peer_lookup(bgp, &su);
3262 if (peer && peer_dynamic_neighbor(peer)) {
3263 vty_out(vty,
3264 "%% Operation not allowed on a dynamic neighbor\n");
3265 return CMD_WARNING_CONFIG_FAILED;
3266 }
3267 }
3268
3269 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3270 if (!group) {
3271 vty_out(vty, "%% Configure the peer-group first\n");
3272 return CMD_WARNING_CONFIG_FAILED;
3273 }
3274
3275 ret = peer_group_bind(bgp, &su, peer, group, &as);
3276
3277 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3278 vty_out(vty,
3279 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3280 as);
3281 return CMD_WARNING_CONFIG_FAILED;
3282 }
3283
3284 return bgp_vty_return(vty, ret);
3285}
3286
3287ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3288 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3290 "Member of the peer-group\n"
3291 "Peer-group name\n")
596c17ba 3292
718e3744 3293DEFUN (no_neighbor_set_peer_group,
3294 no_neighbor_set_peer_group_cmd,
9ccf14f7 3295 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3296 NO_STR
3297 NEIGHBOR_STR
a80beece 3298 NEIGHBOR_ADDR_STR2
718e3744 3299 "Member of the peer-group\n"
16cedbb0 3300 "Peer-group name\n")
718e3744 3301{
d62a17ae 3302 VTY_DECLVAR_CONTEXT(bgp, bgp);
3303 int idx_peer = 2;
3304 int idx_word = 4;
3305 int ret;
3306 struct peer *peer;
3307 struct peer_group *group;
3308
3309 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3310 if (!peer)
3311 return CMD_WARNING_CONFIG_FAILED;
3312
3313 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3314 if (!group) {
3315 vty_out(vty, "%% Configure the peer-group first\n");
3316 return CMD_WARNING_CONFIG_FAILED;
3317 }
718e3744 3318
d62a17ae 3319 ret = peer_group_unbind(bgp, peer, group);
718e3744 3320
d62a17ae 3321 return bgp_vty_return(vty, ret);
718e3744 3322}
6b0655a2 3323
d62a17ae 3324ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3325 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3326 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3327 "Member of the peer-group\n"
3328 "Peer-group name\n")
596c17ba 3329
d62a17ae 3330static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3331 u_int16_t flag, int set)
718e3744 3332{
d62a17ae 3333 int ret;
3334 struct peer *peer;
718e3744 3335
d62a17ae 3336 peer = peer_and_group_lookup_vty(vty, ip_str);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
718e3744 3339
d62a17ae 3340 /*
3341 * If 'neighbor <interface>', then this is for directly connected peers,
3342 * we should not accept disable-connected-check.
3343 */
3344 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3345 vty_out(vty,
3346 "%s is directly connected peer, cannot accept disable-"
3347 "connected-check\n",
3348 ip_str);
3349 return CMD_WARNING_CONFIG_FAILED;
3350 }
8cdabf90 3351
d62a17ae 3352 if (!set && flag == PEER_FLAG_SHUTDOWN)
3353 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3354
d62a17ae 3355 if (set)
3356 ret = peer_flag_set(peer, flag);
3357 else
3358 ret = peer_flag_unset(peer, flag);
718e3744 3359
d62a17ae 3360 return bgp_vty_return(vty, ret);
718e3744 3361}
3362
d62a17ae 3363static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3364 u_int16_t flag)
718e3744 3365{
d62a17ae 3366 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3367}
3368
d62a17ae 3369static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3370 u_int16_t flag)
718e3744 3371{
d62a17ae 3372 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3373}
3374
3375/* neighbor passive. */
3376DEFUN (neighbor_passive,
3377 neighbor_passive_cmd,
9ccf14f7 3378 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3379 NEIGHBOR_STR
3380 NEIGHBOR_ADDR_STR2
3381 "Don't send open messages to this neighbor\n")
3382{
d62a17ae 3383 int idx_peer = 1;
3384 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3385}
3386
3387DEFUN (no_neighbor_passive,
3388 no_neighbor_passive_cmd,
9ccf14f7 3389 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3390 NO_STR
3391 NEIGHBOR_STR
3392 NEIGHBOR_ADDR_STR2
3393 "Don't send open messages to this neighbor\n")
3394{
d62a17ae 3395 int idx_peer = 2;
3396 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3397}
6b0655a2 3398
718e3744 3399/* neighbor shutdown. */
73d70fa6
DL
3400DEFUN (neighbor_shutdown_msg,
3401 neighbor_shutdown_msg_cmd,
3402 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3403 NEIGHBOR_STR
3404 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3405 "Administratively shut down this neighbor\n"
3406 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3407 "Shutdown message\n")
718e3744 3408{
d62a17ae 3409 int idx_peer = 1;
73d70fa6 3410
d62a17ae 3411 if (argc >= 5) {
3412 struct peer *peer =
3413 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3414 char *message;
73d70fa6 3415
d62a17ae 3416 if (!peer)
3417 return CMD_WARNING_CONFIG_FAILED;
3418 message = argv_concat(argv, argc, 4);
3419 peer_tx_shutdown_message_set(peer, message);
3420 XFREE(MTYPE_TMP, message);
3421 }
73d70fa6 3422
d62a17ae 3423 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3424}
3425
d62a17ae 3426ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3427 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3428 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3429 "Administratively shut down this neighbor\n")
73d70fa6
DL
3430
3431DEFUN (no_neighbor_shutdown_msg,
3432 no_neighbor_shutdown_msg_cmd,
3433 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3434 NO_STR
3435 NEIGHBOR_STR
3436 NEIGHBOR_ADDR_STR2
3437 "Administratively shut down this neighbor\n"
3438 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3439 "Shutdown message\n")
718e3744 3440{
d62a17ae 3441 int idx_peer = 2;
73d70fa6 3442
d62a17ae 3443 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3444 PEER_FLAG_SHUTDOWN);
718e3744 3445}
6b0655a2 3446
d62a17ae 3447ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3448 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3449 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3450 "Administratively shut down this neighbor\n")
73d70fa6 3451
718e3744 3452/* neighbor capability dynamic. */
3453DEFUN (neighbor_capability_dynamic,
3454 neighbor_capability_dynamic_cmd,
9ccf14f7 3455 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3456 NEIGHBOR_STR
3457 NEIGHBOR_ADDR_STR2
3458 "Advertise capability to the peer\n"
3459 "Advertise dynamic capability to this neighbor\n")
3460{
d62a17ae 3461 int idx_peer = 1;
3462 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3463 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3464}
3465
3466DEFUN (no_neighbor_capability_dynamic,
3467 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3468 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3469 NO_STR
3470 NEIGHBOR_STR
3471 NEIGHBOR_ADDR_STR2
3472 "Advertise capability to the peer\n"
3473 "Advertise dynamic capability to this neighbor\n")
3474{
d62a17ae 3475 int idx_peer = 2;
3476 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3477 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3478}
6b0655a2 3479
718e3744 3480/* neighbor dont-capability-negotiate */
3481DEFUN (neighbor_dont_capability_negotiate,
3482 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3483 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
3486 "Do not perform capability negotiation\n")
3487{
d62a17ae 3488 int idx_peer = 1;
3489 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3490 PEER_FLAG_DONT_CAPABILITY);
718e3744 3491}
3492
3493DEFUN (no_neighbor_dont_capability_negotiate,
3494 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3495 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3496 NO_STR
3497 NEIGHBOR_STR
3498 NEIGHBOR_ADDR_STR2
3499 "Do not perform capability negotiation\n")
3500{
d62a17ae 3501 int idx_peer = 2;
3502 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3503 PEER_FLAG_DONT_CAPABILITY);
718e3744 3504}
6b0655a2 3505
8a92a8a0
DS
3506/* neighbor capability extended next hop encoding */
3507DEFUN (neighbor_capability_enhe,
3508 neighbor_capability_enhe_cmd,
9ccf14f7 3509 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3510 NEIGHBOR_STR
3511 NEIGHBOR_ADDR_STR2
3512 "Advertise capability to the peer\n"
3513 "Advertise extended next-hop capability to the peer\n")
3514{
d62a17ae 3515 int idx_peer = 1;
3516 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3517 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3518}
3519
3520DEFUN (no_neighbor_capability_enhe,
3521 no_neighbor_capability_enhe_cmd,
9ccf14f7 3522 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3523 NO_STR
3524 NEIGHBOR_STR
3525 NEIGHBOR_ADDR_STR2
3526 "Advertise capability to the peer\n"
3527 "Advertise extended next-hop capability to the peer\n")
3528{
d62a17ae 3529 int idx_peer = 2;
3530 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3531 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3532}
3533
d62a17ae 3534static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3535 afi_t afi, safi_t safi, u_int32_t flag,
3536 int set)
718e3744 3537{
d62a17ae 3538 int ret;
3539 struct peer *peer;
718e3744 3540
d62a17ae 3541 peer = peer_and_group_lookup_vty(vty, peer_str);
3542 if (!peer)
3543 return CMD_WARNING_CONFIG_FAILED;
718e3744 3544
d62a17ae 3545 if (set)
3546 ret = peer_af_flag_set(peer, afi, safi, flag);
3547 else
3548 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3549
d62a17ae 3550 return bgp_vty_return(vty, ret);
718e3744 3551}
3552
d62a17ae 3553static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3554 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3555{
d62a17ae 3556 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3557}
3558
d62a17ae 3559static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3560 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3561{
d62a17ae 3562 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3563}
6b0655a2 3564
718e3744 3565/* neighbor capability orf prefix-list. */
3566DEFUN (neighbor_capability_orf_prefix,
3567 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3568 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3569 NEIGHBOR_STR
3570 NEIGHBOR_ADDR_STR2
3571 "Advertise capability to the peer\n"
3572 "Advertise ORF capability to the peer\n"
3573 "Advertise prefixlist ORF capability to this neighbor\n"
3574 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3575 "Capability to RECEIVE the ORF from this neighbor\n"
3576 "Capability to SEND the ORF to this neighbor\n")
3577{
d62a17ae 3578 int idx_peer = 1;
3579 int idx_send_recv = 5;
3580 u_int16_t flag = 0;
3581
3582 if (strmatch(argv[idx_send_recv]->text, "send"))
3583 flag = PEER_FLAG_ORF_PREFIX_SM;
3584 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3585 flag = PEER_FLAG_ORF_PREFIX_RM;
3586 else if (strmatch(argv[idx_send_recv]->text, "both"))
3587 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3588 else {
3589 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3590 return CMD_WARNING_CONFIG_FAILED;
3591 }
3592
3593 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3594 bgp_node_safi(vty), flag);
3595}
3596
3597ALIAS_HIDDEN(
3598 neighbor_capability_orf_prefix,
3599 neighbor_capability_orf_prefix_hidden_cmd,
3600 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3601 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3602 "Advertise capability to the peer\n"
3603 "Advertise ORF capability to the peer\n"
3604 "Advertise prefixlist ORF capability to this neighbor\n"
3605 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3606 "Capability to RECEIVE the ORF from this neighbor\n"
3607 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3608
718e3744 3609DEFUN (no_neighbor_capability_orf_prefix,
3610 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3611 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3612 NO_STR
3613 NEIGHBOR_STR
3614 NEIGHBOR_ADDR_STR2
3615 "Advertise capability to the peer\n"
3616 "Advertise ORF capability to the peer\n"
3617 "Advertise prefixlist ORF capability to this neighbor\n"
3618 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3619 "Capability to RECEIVE the ORF from this neighbor\n"
3620 "Capability to SEND the ORF to this neighbor\n")
3621{
d62a17ae 3622 int idx_peer = 2;
3623 int idx_send_recv = 6;
3624 u_int16_t flag = 0;
3625
3626 if (strmatch(argv[idx_send_recv]->text, "send"))
3627 flag = PEER_FLAG_ORF_PREFIX_SM;
3628 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3629 flag = PEER_FLAG_ORF_PREFIX_RM;
3630 else if (strmatch(argv[idx_send_recv]->text, "both"))
3631 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3632 else {
3633 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3634 return CMD_WARNING_CONFIG_FAILED;
3635 }
3636
3637 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3638 bgp_node_afi(vty), bgp_node_safi(vty),
3639 flag);
3640}
3641
3642ALIAS_HIDDEN(
3643 no_neighbor_capability_orf_prefix,
3644 no_neighbor_capability_orf_prefix_hidden_cmd,
3645 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3646 NO_STR NEIGHBOR_STR 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")
596c17ba 3653
718e3744 3654/* neighbor next-hop-self. */
3655DEFUN (neighbor_nexthop_self,
3656 neighbor_nexthop_self_cmd,
9ccf14f7 3657 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3658 NEIGHBOR_STR
3659 NEIGHBOR_ADDR_STR2
a538debe 3660 "Disable the next hop calculation for this neighbor\n")
718e3744 3661{
d62a17ae 3662 int idx_peer = 1;
3663 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3664 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3665}
9e7a53c1 3666
d62a17ae 3667ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3668 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3670 "Disable the next hop calculation for this neighbor\n")
596c17ba 3671
a538debe
DS
3672/* neighbor next-hop-self. */
3673DEFUN (neighbor_nexthop_self_force,
3674 neighbor_nexthop_self_force_cmd,
9ccf14f7 3675 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3676 NEIGHBOR_STR
3677 NEIGHBOR_ADDR_STR2
3678 "Disable the next hop calculation for this neighbor\n"
3679 "Set the next hop to self for reflected routes\n")
3680{
d62a17ae 3681 int idx_peer = 1;
3682 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3683 bgp_node_safi(vty),
3684 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3685}
3686
d62a17ae 3687ALIAS_HIDDEN(neighbor_nexthop_self_force,
3688 neighbor_nexthop_self_force_hidden_cmd,
3689 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3690 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3691 "Disable the next hop calculation for this neighbor\n"
3692 "Set the next hop to self for reflected routes\n")
596c17ba 3693
718e3744 3694DEFUN (no_neighbor_nexthop_self,
3695 no_neighbor_nexthop_self_cmd,
9ccf14f7 3696 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3697 NO_STR
3698 NEIGHBOR_STR
3699 NEIGHBOR_ADDR_STR2
a538debe 3700 "Disable the next hop calculation for this neighbor\n")
718e3744 3701{
d62a17ae 3702 int idx_peer = 2;
3703 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3704 bgp_node_afi(vty), bgp_node_safi(vty),
3705 PEER_FLAG_NEXTHOP_SELF);
718e3744 3706}
6b0655a2 3707
d62a17ae 3708ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3709 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3710 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3711 "Disable the next hop calculation for this neighbor\n")
596c17ba 3712
88b8ed8d 3713DEFUN (no_neighbor_nexthop_self_force,
a538debe 3714 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3715 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3716 NO_STR
3717 NEIGHBOR_STR
3718 NEIGHBOR_ADDR_STR2
3719 "Disable the next hop calculation for this neighbor\n"
3720 "Set the next hop to self for reflected routes\n")
88b8ed8d 3721{
d62a17ae 3722 int idx_peer = 2;
3723 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3724 bgp_node_afi(vty), bgp_node_safi(vty),
3725 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3726}
a538debe 3727
d62a17ae 3728ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3729 no_neighbor_nexthop_self_force_hidden_cmd,
3730 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3731 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3732 "Disable the next hop calculation for this neighbor\n"
3733 "Set the next hop to self for reflected routes\n")
596c17ba 3734
c7122e14
DS
3735/* neighbor as-override */
3736DEFUN (neighbor_as_override,
3737 neighbor_as_override_cmd,
9ccf14f7 3738 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3739 NEIGHBOR_STR
3740 NEIGHBOR_ADDR_STR2
3741 "Override ASNs in outbound updates if aspath equals remote-as\n")
3742{
d62a17ae 3743 int idx_peer = 1;
3744 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3745 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3746}
3747
d62a17ae 3748ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3749 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3751 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3752
c7122e14
DS
3753DEFUN (no_neighbor_as_override,
3754 no_neighbor_as_override_cmd,
9ccf14f7 3755 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3756 NO_STR
3757 NEIGHBOR_STR
3758 NEIGHBOR_ADDR_STR2
3759 "Override ASNs in outbound updates if aspath equals remote-as\n")
3760{
d62a17ae 3761 int idx_peer = 2;
3762 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3763 bgp_node_afi(vty), bgp_node_safi(vty),
3764 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3765}
3766
d62a17ae 3767ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3768 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3769 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3770 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3771
718e3744 3772/* neighbor remove-private-AS. */
3773DEFUN (neighbor_remove_private_as,
3774 neighbor_remove_private_as_cmd,
9ccf14f7 3775 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
5000f21c 3778 "Remove private ASNs in outbound updates\n")
718e3744 3779{
d62a17ae 3780 int idx_peer = 1;
3781 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3782 bgp_node_safi(vty),
3783 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3784}
3785
d62a17ae 3786ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3787 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3788 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3789 "Remove private ASNs in outbound updates\n")
596c17ba 3790
5000f21c
DS
3791DEFUN (neighbor_remove_private_as_all,
3792 neighbor_remove_private_as_all_cmd,
9ccf14f7 3793 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3794 NEIGHBOR_STR
3795 NEIGHBOR_ADDR_STR2
3796 "Remove private ASNs in outbound updates\n"
3797 "Apply to all AS numbers")
3798{
d62a17ae 3799 int idx_peer = 1;
3800 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3801 bgp_node_safi(vty),
3802 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3803}
3804
d62a17ae 3805ALIAS_HIDDEN(neighbor_remove_private_as_all,
3806 neighbor_remove_private_as_all_hidden_cmd,
3807 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3808 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3809 "Remove private ASNs in outbound updates\n"
3810 "Apply to all AS numbers")
596c17ba 3811
5000f21c
DS
3812DEFUN (neighbor_remove_private_as_replace_as,
3813 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3814 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Remove private ASNs in outbound updates\n"
3818 "Replace private ASNs with our ASN in outbound updates\n")
3819{
d62a17ae 3820 int idx_peer = 1;
3821 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3822 bgp_node_safi(vty),
3823 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3824}
3825
d62a17ae 3826ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3827 neighbor_remove_private_as_replace_as_hidden_cmd,
3828 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3829 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3830 "Remove private ASNs in outbound updates\n"
3831 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3832
5000f21c
DS
3833DEFUN (neighbor_remove_private_as_all_replace_as,
3834 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3835 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3836 NEIGHBOR_STR
3837 NEIGHBOR_ADDR_STR2
3838 "Remove private ASNs in outbound updates\n"
16cedbb0 3839 "Apply to all AS numbers\n"
5000f21c
DS
3840 "Replace private ASNs with our ASN in outbound updates\n")
3841{
d62a17ae 3842 int idx_peer = 1;
3843 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3844 bgp_node_safi(vty),
3845 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3846}
3847
d62a17ae 3848ALIAS_HIDDEN(
3849 neighbor_remove_private_as_all_replace_as,
3850 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3851 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3852 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3853 "Remove private ASNs in outbound updates\n"
3854 "Apply to all AS numbers\n"
3855 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3856
718e3744 3857DEFUN (no_neighbor_remove_private_as,
3858 no_neighbor_remove_private_as_cmd,
9ccf14f7 3859 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3860 NO_STR
3861 NEIGHBOR_STR
3862 NEIGHBOR_ADDR_STR2
5000f21c 3863 "Remove private ASNs in outbound updates\n")
718e3744 3864{
d62a17ae 3865 int idx_peer = 2;
3866 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3867 bgp_node_afi(vty), bgp_node_safi(vty),
3868 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3869}
6b0655a2 3870
d62a17ae 3871ALIAS_HIDDEN(no_neighbor_remove_private_as,
3872 no_neighbor_remove_private_as_hidden_cmd,
3873 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3874 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3875 "Remove private ASNs in outbound updates\n")
596c17ba 3876
88b8ed8d 3877DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3878 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3879 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3880 NO_STR
3881 NEIGHBOR_STR
3882 NEIGHBOR_ADDR_STR2
3883 "Remove private ASNs in outbound updates\n"
16cedbb0 3884 "Apply to all AS numbers\n")
88b8ed8d 3885{
d62a17ae 3886 int idx_peer = 2;
3887 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3888 bgp_node_afi(vty), bgp_node_safi(vty),
3889 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3890}
5000f21c 3891
d62a17ae 3892ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3893 no_neighbor_remove_private_as_all_hidden_cmd,
3894 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3895 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3896 "Remove private ASNs in outbound updates\n"
3897 "Apply to all AS numbers\n")
596c17ba 3898
88b8ed8d 3899DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3900 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3901 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3902 NO_STR
3903 NEIGHBOR_STR
3904 NEIGHBOR_ADDR_STR2
3905 "Remove private ASNs in outbound updates\n"
3906 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3907{
d62a17ae 3908 int idx_peer = 2;
3909 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3910 bgp_node_afi(vty), bgp_node_safi(vty),
3911 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3912}
5000f21c 3913
d62a17ae 3914ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3915 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Remove private ASNs in outbound updates\n"
3919 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3920
88b8ed8d 3921DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 3922 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3923 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3924 NO_STR
3925 NEIGHBOR_STR
3926 NEIGHBOR_ADDR_STR2
3927 "Remove private ASNs in outbound updates\n"
16cedbb0 3928 "Apply to all AS numbers\n"
5000f21c 3929 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3930{
d62a17ae 3931 int idx_peer = 2;
3932 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3933 bgp_node_afi(vty), bgp_node_safi(vty),
3934 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 3935}
5000f21c 3936
d62a17ae 3937ALIAS_HIDDEN(
3938 no_neighbor_remove_private_as_all_replace_as,
3939 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
3940 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3941 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3942 "Remove private ASNs in outbound updates\n"
3943 "Apply to all AS numbers\n"
3944 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3945
5000f21c 3946
718e3744 3947/* neighbor send-community. */
3948DEFUN (neighbor_send_community,
3949 neighbor_send_community_cmd,
9ccf14f7 3950 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 3951 NEIGHBOR_STR
3952 NEIGHBOR_ADDR_STR2
3953 "Send Community attribute to this neighbor\n")
3954{
d62a17ae 3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3957 bgp_node_safi(vty),
3958 PEER_FLAG_SEND_COMMUNITY);
718e3744 3959}
3960
d62a17ae 3961ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
3962 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3963 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3964 "Send Community attribute to this neighbor\n")
596c17ba 3965
718e3744 3966DEFUN (no_neighbor_send_community,
3967 no_neighbor_send_community_cmd,
9ccf14f7 3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 3969 NO_STR
3970 NEIGHBOR_STR
3971 NEIGHBOR_ADDR_STR2
3972 "Send Community attribute to this neighbor\n")
3973{
d62a17ae 3974 int idx_peer = 2;
3975 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3976 bgp_node_afi(vty), bgp_node_safi(vty),
3977 PEER_FLAG_SEND_COMMUNITY);
718e3744 3978}
6b0655a2 3979
d62a17ae 3980ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
3981 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3983 "Send Community attribute to this neighbor\n")
596c17ba 3984
718e3744 3985/* neighbor send-community extended. */
3986DEFUN (neighbor_send_community_type,
3987 neighbor_send_community_type_cmd,
57d187bc 3988 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 3989 NEIGHBOR_STR
3990 NEIGHBOR_ADDR_STR2
3991 "Send Community attribute to this neighbor\n"
3992 "Send Standard and Extended Community attributes\n"
57d187bc 3993 "Send Standard, Large and Extended Community attributes\n"
718e3744 3994 "Send Extended Community attributes\n"
57d187bc
JS
3995 "Send Standard Community attributes\n"
3996 "Send Large Community attributes\n")
718e3744 3997{
d62a17ae 3998 int idx = 0;
3999 u_int32_t flag = 0;
4000
4001 char *peer = argv[1]->arg;
4002
4003 if (argv_find(argv, argc, "standard", &idx))
4004 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4005 else if (argv_find(argv, argc, "extended", &idx))
4006 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4007 else if (argv_find(argv, argc, "large", &idx))
4008 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4009 else if (argv_find(argv, argc, "both", &idx)) {
4010 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4011 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4012 } else {
4013 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4014 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4015 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4016 }
4017
4018 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4019 bgp_node_safi(vty), flag);
4020}
4021
4022ALIAS_HIDDEN(
4023 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4024 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4025 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4026 "Send Community attribute to this neighbor\n"
4027 "Send Standard and Extended Community attributes\n"
4028 "Send Standard, Large and Extended Community attributes\n"
4029 "Send Extended Community attributes\n"
4030 "Send Standard Community attributes\n"
4031 "Send Large Community attributes\n")
596c17ba 4032
718e3744 4033DEFUN (no_neighbor_send_community_type,
4034 no_neighbor_send_community_type_cmd,
57d187bc 4035 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4036 NO_STR
4037 NEIGHBOR_STR
4038 NEIGHBOR_ADDR_STR2
4039 "Send Community attribute to this neighbor\n"
4040 "Send Standard and Extended Community attributes\n"
57d187bc 4041 "Send Standard, Large and Extended Community attributes\n"
718e3744 4042 "Send Extended Community attributes\n"
57d187bc
JS
4043 "Send Standard Community attributes\n"
4044 "Send Large Community attributes\n")
718e3744 4045{
d62a17ae 4046 int idx_peer = 2;
4047
4048 const char *type = argv[argc - 1]->text;
4049
4050 if (strmatch(type, "standard"))
4051 return peer_af_flag_unset_vty(
4052 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4054 if (strmatch(type, "extended"))
4055 return peer_af_flag_unset_vty(
4056 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4057 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4058 if (strmatch(type, "large"))
4059 return peer_af_flag_unset_vty(
4060 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4061 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4062 if (strmatch(type, "both"))
4063 return peer_af_flag_unset_vty(
4064 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4065 bgp_node_safi(vty),
4066 PEER_FLAG_SEND_COMMUNITY
4067 | PEER_FLAG_SEND_EXT_COMMUNITY);
4068
4069 /* if (strmatch (type, "all")) */
4070 return peer_af_flag_unset_vty(
4071 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4072 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4073 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4074}
4075
4076ALIAS_HIDDEN(
4077 no_neighbor_send_community_type,
4078 no_neighbor_send_community_type_hidden_cmd,
4079 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4080 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4081 "Send Community attribute to this neighbor\n"
4082 "Send Standard and Extended Community attributes\n"
4083 "Send Standard, Large and Extended Community attributes\n"
4084 "Send Extended Community attributes\n"
4085 "Send Standard Community attributes\n"
4086 "Send Large Community attributes\n")
596c17ba 4087
718e3744 4088/* neighbor soft-reconfig. */
4089DEFUN (neighbor_soft_reconfiguration,
4090 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4091 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4092 NEIGHBOR_STR
4093 NEIGHBOR_ADDR_STR2
4094 "Per neighbor soft reconfiguration\n"
4095 "Allow inbound soft reconfiguration for this neighbor\n")
4096{
d62a17ae 4097 int idx_peer = 1;
4098 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4099 bgp_node_safi(vty),
4100 PEER_FLAG_SOFT_RECONFIG);
718e3744 4101}
4102
d62a17ae 4103ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4104 neighbor_soft_reconfiguration_hidden_cmd,
4105 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4107 "Per neighbor soft reconfiguration\n"
4108 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4109
718e3744 4110DEFUN (no_neighbor_soft_reconfiguration,
4111 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4112 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4113 NO_STR
4114 NEIGHBOR_STR
4115 NEIGHBOR_ADDR_STR2
4116 "Per neighbor soft reconfiguration\n"
4117 "Allow inbound soft reconfiguration for this neighbor\n")
4118{
d62a17ae 4119 int idx_peer = 2;
4120 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4121 bgp_node_afi(vty), bgp_node_safi(vty),
4122 PEER_FLAG_SOFT_RECONFIG);
718e3744 4123}
6b0655a2 4124
d62a17ae 4125ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4126 no_neighbor_soft_reconfiguration_hidden_cmd,
4127 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4128 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4129 "Per neighbor soft reconfiguration\n"
4130 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4131
718e3744 4132DEFUN (neighbor_route_reflector_client,
4133 neighbor_route_reflector_client_cmd,
9ccf14f7 4134 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4135 NEIGHBOR_STR
4136 NEIGHBOR_ADDR_STR2
4137 "Configure a neighbor as Route Reflector client\n")
4138{
d62a17ae 4139 int idx_peer = 1;
4140 struct peer *peer;
718e3744 4141
4142
d62a17ae 4143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4144 if (!peer)
4145 return CMD_WARNING_CONFIG_FAILED;
718e3744 4146
d62a17ae 4147 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4148 bgp_node_safi(vty),
4149 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4150}
4151
d62a17ae 4152ALIAS_HIDDEN(neighbor_route_reflector_client,
4153 neighbor_route_reflector_client_hidden_cmd,
4154 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4156 "Configure a neighbor as Route Reflector client\n")
596c17ba 4157
718e3744 4158DEFUN (no_neighbor_route_reflector_client,
4159 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4160 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4161 NO_STR
4162 NEIGHBOR_STR
4163 NEIGHBOR_ADDR_STR2
4164 "Configure a neighbor as Route Reflector client\n")
4165{
d62a17ae 4166 int idx_peer = 2;
4167 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4168 bgp_node_afi(vty), bgp_node_safi(vty),
4169 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4170}
6b0655a2 4171
d62a17ae 4172ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4173 no_neighbor_route_reflector_client_hidden_cmd,
4174 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4175 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4176 "Configure a neighbor as Route Reflector client\n")
596c17ba 4177
718e3744 4178/* neighbor route-server-client. */
4179DEFUN (neighbor_route_server_client,
4180 neighbor_route_server_client_cmd,
9ccf14f7 4181 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4182 NEIGHBOR_STR
4183 NEIGHBOR_ADDR_STR2
4184 "Configure a neighbor as Route Server client\n")
4185{
d62a17ae 4186 int idx_peer = 1;
4187 struct peer *peer;
2a3d5731 4188
d62a17ae 4189 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4190 if (!peer)
4191 return CMD_WARNING_CONFIG_FAILED;
4192 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4193 bgp_node_safi(vty),
4194 PEER_FLAG_RSERVER_CLIENT);
718e3744 4195}
4196
d62a17ae 4197ALIAS_HIDDEN(neighbor_route_server_client,
4198 neighbor_route_server_client_hidden_cmd,
4199 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4200 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4201 "Configure a neighbor as Route Server client\n")
596c17ba 4202
718e3744 4203DEFUN (no_neighbor_route_server_client,
4204 no_neighbor_route_server_client_cmd,
9ccf14f7 4205 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4206 NO_STR
4207 NEIGHBOR_STR
4208 NEIGHBOR_ADDR_STR2
4209 "Configure a neighbor as Route Server client\n")
fee0f4c6 4210{
d62a17ae 4211 int idx_peer = 2;
4212 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4213 bgp_node_afi(vty), bgp_node_safi(vty),
4214 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4215}
6b0655a2 4216
d62a17ae 4217ALIAS_HIDDEN(no_neighbor_route_server_client,
4218 no_neighbor_route_server_client_hidden_cmd,
4219 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4221 "Configure a neighbor as Route Server client\n")
596c17ba 4222
fee0f4c6 4223DEFUN (neighbor_nexthop_local_unchanged,
4224 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4225 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4226 NEIGHBOR_STR
4227 NEIGHBOR_ADDR_STR2
4228 "Configure treatment of outgoing link-local nexthop attribute\n"
4229 "Leave link-local nexthop unchanged for this peer\n")
4230{
d62a17ae 4231 int idx_peer = 1;
4232 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4233 bgp_node_safi(vty),
4234 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4235}
6b0655a2 4236
fee0f4c6 4237DEFUN (no_neighbor_nexthop_local_unchanged,
4238 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4239 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4240 NO_STR
4241 NEIGHBOR_STR
4242 NEIGHBOR_ADDR_STR2
4243 "Configure treatment of outgoing link-local-nexthop attribute\n"
4244 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4245{
d62a17ae 4246 int idx_peer = 2;
4247 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4248 bgp_node_afi(vty), bgp_node_safi(vty),
4249 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4250}
6b0655a2 4251
718e3744 4252DEFUN (neighbor_attr_unchanged,
4253 neighbor_attr_unchanged_cmd,
a8206004 4254 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4255 NEIGHBOR_STR
4256 NEIGHBOR_ADDR_STR2
4257 "BGP attribute is propagated unchanged to this neighbor\n"
4258 "As-path attribute\n"
4259 "Nexthop attribute\n"
a8206004 4260 "Med attribute\n")
718e3744 4261{
d62a17ae 4262 int idx = 0;
8eeb0335
DW
4263 char *peer_str = argv[1]->arg;
4264 struct peer *peer;
d62a17ae 4265 u_int16_t flags = 0;
8eeb0335
DW
4266 afi_t afi = bgp_node_afi(vty);
4267 safi_t safi = bgp_node_safi(vty);
4268
4269 peer = peer_and_group_lookup_vty(vty, peer_str);
4270 if (!peer)
4271 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4272
4273 if (argv_find(argv, argc, "as-path", &idx))
4274 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4275 idx = 0;
4276 if (argv_find(argv, argc, "next-hop", &idx))
4277 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4278 idx = 0;
4279 if (argv_find(argv, argc, "med", &idx))
4280 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4281
8eeb0335
DW
4282 /* no flags means all of them! */
4283 if (!flags) {
d62a17ae 4284 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4285 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4286 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335
DW
4287 } else {
4288 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) &&
4289 peer_af_flag_check(peer, afi, safi,
4290 PEER_FLAG_AS_PATH_UNCHANGED)) {
4291 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4292 PEER_FLAG_AS_PATH_UNCHANGED);
4293 }
4294
4295 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) &&
4296 peer_af_flag_check(peer, afi, safi,
4297 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4298 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4299 PEER_FLAG_NEXTHOP_UNCHANGED);
4300 }
4301
4302 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) &&
4303 peer_af_flag_check(peer, afi, safi,
4304 PEER_FLAG_MED_UNCHANGED)) {
4305 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4306 PEER_FLAG_MED_UNCHANGED);
4307 }
d62a17ae 4308 }
4309
8eeb0335 4310 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4311}
4312
4313ALIAS_HIDDEN(
4314 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4315 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4316 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4317 "BGP attribute is propagated unchanged to this neighbor\n"
4318 "As-path attribute\n"
4319 "Nexthop attribute\n"
4320 "Med attribute\n")
596c17ba 4321
718e3744 4322DEFUN (no_neighbor_attr_unchanged,
4323 no_neighbor_attr_unchanged_cmd,
a8206004 4324 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4325 NO_STR
718e3744 4326 NEIGHBOR_STR
4327 NEIGHBOR_ADDR_STR2
31500417
DW
4328 "BGP attribute is propagated unchanged to this neighbor\n"
4329 "As-path attribute\n"
40e718b5 4330 "Nexthop attribute\n"
a8206004 4331 "Med attribute\n")
718e3744 4332{
d62a17ae 4333 int idx = 0;
4334 char *peer = argv[2]->arg;
4335 u_int16_t flags = 0;
4336
4337 if (argv_find(argv, argc, "as-path", &idx))
4338 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4339 idx = 0;
4340 if (argv_find(argv, argc, "next-hop", &idx))
4341 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4342 idx = 0;
4343 if (argv_find(argv, argc, "med", &idx))
4344 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4345
4346 if (!flags) // no flags means all of them!
4347 {
4348 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4349 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4350 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4351 }
4352
4353 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4354 bgp_node_safi(vty), flags);
4355}
4356
4357ALIAS_HIDDEN(
4358 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4360 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4361 "BGP attribute is propagated unchanged to this neighbor\n"
4362 "As-path attribute\n"
4363 "Nexthop attribute\n"
4364 "Med attribute\n")
718e3744 4365
718e3744 4366/* EBGP multihop configuration. */
d62a17ae 4367static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4368 const char *ttl_str)
718e3744 4369{
d62a17ae 4370 struct peer *peer;
4371 unsigned int ttl;
718e3744 4372
d62a17ae 4373 peer = peer_and_group_lookup_vty(vty, ip_str);
4374 if (!peer)
4375 return CMD_WARNING_CONFIG_FAILED;
718e3744 4376
d62a17ae 4377 if (peer->conf_if)
4378 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4379
d62a17ae 4380 if (!ttl_str)
4381 ttl = MAXTTL;
4382 else
4383 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4384
d62a17ae 4385 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4386}
4387
d62a17ae 4388static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4389{
d62a17ae 4390 struct peer *peer;
718e3744 4391
d62a17ae 4392 peer = peer_and_group_lookup_vty(vty, ip_str);
4393 if (!peer)
4394 return CMD_WARNING_CONFIG_FAILED;
718e3744 4395
d62a17ae 4396 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4397}
4398
4399/* neighbor ebgp-multihop. */
4400DEFUN (neighbor_ebgp_multihop,
4401 neighbor_ebgp_multihop_cmd,
9ccf14f7 4402 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4403 NEIGHBOR_STR
4404 NEIGHBOR_ADDR_STR2
4405 "Allow EBGP neighbors not on directly connected networks\n")
4406{
d62a17ae 4407 int idx_peer = 1;
4408 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4409}
4410
4411DEFUN (neighbor_ebgp_multihop_ttl,
4412 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4413 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4414 NEIGHBOR_STR
4415 NEIGHBOR_ADDR_STR2
4416 "Allow EBGP neighbors not on directly connected networks\n"
4417 "maximum hop count\n")
4418{
d62a17ae 4419 int idx_peer = 1;
4420 int idx_number = 3;
4421 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4422 argv[idx_number]->arg);
718e3744 4423}
4424
4425DEFUN (no_neighbor_ebgp_multihop,
4426 no_neighbor_ebgp_multihop_cmd,
a636c635 4427 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4428 NO_STR
4429 NEIGHBOR_STR
4430 NEIGHBOR_ADDR_STR2
a636c635
DW
4431 "Allow EBGP neighbors not on directly connected networks\n"
4432 "maximum hop count\n")
718e3744 4433{
d62a17ae 4434 int idx_peer = 2;
4435 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4436}
4437
6b0655a2 4438
6ffd2079 4439/* disable-connected-check */
4440DEFUN (neighbor_disable_connected_check,
4441 neighbor_disable_connected_check_cmd,
a636c635 4442 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4443 NEIGHBOR_STR
4444 NEIGHBOR_ADDR_STR2
a636c635
DW
4445 "one-hop away EBGP peer using loopback address\n"
4446 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4447{
d62a17ae 4448 int idx_peer = 1;
4449 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4450 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4451}
4452
4453DEFUN (no_neighbor_disable_connected_check,
4454 no_neighbor_disable_connected_check_cmd,
a636c635 4455 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4456 NO_STR
4457 NEIGHBOR_STR
4458 NEIGHBOR_ADDR_STR2
a636c635
DW
4459 "one-hop away EBGP peer using loopback address\n"
4460 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4461{
d62a17ae 4462 int idx_peer = 2;
4463 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4464 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4465}
4466
718e3744 4467DEFUN (neighbor_description,
4468 neighbor_description_cmd,
e961923c 4469 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4470 NEIGHBOR_STR
4471 NEIGHBOR_ADDR_STR2
4472 "Neighbor specific description\n"
4473 "Up to 80 characters describing this neighbor\n")
4474{
d62a17ae 4475 int idx_peer = 1;
4476 int idx_line = 3;
4477 struct peer *peer;
4478 char *str;
718e3744 4479
d62a17ae 4480 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4481 if (!peer)
4482 return CMD_WARNING_CONFIG_FAILED;
718e3744 4483
d62a17ae 4484 str = argv_concat(argv, argc, idx_line);
718e3744 4485
d62a17ae 4486 peer_description_set(peer, str);
718e3744 4487
d62a17ae 4488 XFREE(MTYPE_TMP, str);
718e3744 4489
d62a17ae 4490 return CMD_SUCCESS;
718e3744 4491}
4492
4493DEFUN (no_neighbor_description,
4494 no_neighbor_description_cmd,
a636c635 4495 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4496 NO_STR
4497 NEIGHBOR_STR
4498 NEIGHBOR_ADDR_STR2
a636c635
DW
4499 "Neighbor specific description\n"
4500 "Up to 80 characters describing this neighbor\n")
718e3744 4501{
d62a17ae 4502 int idx_peer = 2;
4503 struct peer *peer;
718e3744 4504
d62a17ae 4505 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4506 if (!peer)
4507 return CMD_WARNING_CONFIG_FAILED;
718e3744 4508
d62a17ae 4509 peer_description_unset(peer);
718e3744 4510
d62a17ae 4511 return CMD_SUCCESS;
718e3744 4512}
4513
6b0655a2 4514
718e3744 4515/* Neighbor update-source. */
d62a17ae 4516static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4517 const char *source_str)
4518{
4519 struct peer *peer;
4520 struct prefix p;
4521
4522 peer = peer_and_group_lookup_vty(vty, peer_str);
4523 if (!peer)
4524 return CMD_WARNING_CONFIG_FAILED;
4525
4526 if (peer->conf_if)
4527 return CMD_WARNING;
4528
4529 if (source_str) {
4530 union sockunion su;
4531 int ret = str2sockunion(source_str, &su);
4532
4533 if (ret == 0)
4534 peer_update_source_addr_set(peer, &su);
4535 else {
4536 if (str2prefix(source_str, &p)) {
4537 vty_out(vty,
4538 "%% Invalid update-source, remove prefix length \n");
4539 return CMD_WARNING_CONFIG_FAILED;
4540 } else
4541 peer_update_source_if_set(peer, source_str);
4542 }
4543 } else
4544 peer_update_source_unset(peer);
4545
4546 return CMD_SUCCESS;
4547}
4548
4549#define BGP_UPDATE_SOURCE_HELP_STR \
4550 "IPv4 address\n" \
4551 "IPv6 address\n" \
4552 "Interface name (requires zebra to be running)\n"
369688c0 4553
718e3744 4554DEFUN (neighbor_update_source,
4555 neighbor_update_source_cmd,
9ccf14f7 4556 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4557 NEIGHBOR_STR
4558 NEIGHBOR_ADDR_STR2
4559 "Source of routing updates\n"
369688c0 4560 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4561{
d62a17ae 4562 int idx_peer = 1;
4563 int idx_peer_2 = 3;
4564 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4565 argv[idx_peer_2]->arg);
718e3744 4566}
4567
4568DEFUN (no_neighbor_update_source,
4569 no_neighbor_update_source_cmd,
c7178fe7 4570 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4571 NO_STR
4572 NEIGHBOR_STR
4573 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4574 "Source of routing updates\n"
4575 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4576{
d62a17ae 4577 int idx_peer = 2;
4578 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4579}
6b0655a2 4580
d62a17ae 4581static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4582 afi_t afi, safi_t safi,
4583 const char *rmap, int set)
718e3744 4584{
d62a17ae 4585 int ret;
4586 struct peer *peer;
718e3744 4587
d62a17ae 4588 peer = peer_and_group_lookup_vty(vty, peer_str);
4589 if (!peer)
4590 return CMD_WARNING_CONFIG_FAILED;
718e3744 4591
d62a17ae 4592 if (set)
4593 ret = peer_default_originate_set(peer, afi, safi, rmap);
4594 else
4595 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4596
d62a17ae 4597 return bgp_vty_return(vty, ret);
718e3744 4598}
4599
4600/* neighbor default-originate. */
4601DEFUN (neighbor_default_originate,
4602 neighbor_default_originate_cmd,
9ccf14f7 4603 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4604 NEIGHBOR_STR
4605 NEIGHBOR_ADDR_STR2
4606 "Originate default route to this neighbor\n")
4607{
d62a17ae 4608 int idx_peer = 1;
4609 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4610 bgp_node_afi(vty),
4611 bgp_node_safi(vty), NULL, 1);
718e3744 4612}
4613
d62a17ae 4614ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4615 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4616 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4617 "Originate default route to this neighbor\n")
596c17ba 4618
718e3744 4619DEFUN (neighbor_default_originate_rmap,
4620 neighbor_default_originate_rmap_cmd,
9ccf14f7 4621 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4622 NEIGHBOR_STR
4623 NEIGHBOR_ADDR_STR2
4624 "Originate default route to this neighbor\n"
4625 "Route-map to specify criteria to originate default\n"
4626 "route-map name\n")
4627{
d62a17ae 4628 int idx_peer = 1;
4629 int idx_word = 4;
4630 return peer_default_originate_set_vty(
4631 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4632 argv[idx_word]->arg, 1);
718e3744 4633}
4634
d62a17ae 4635ALIAS_HIDDEN(
4636 neighbor_default_originate_rmap,
4637 neighbor_default_originate_rmap_hidden_cmd,
4638 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4639 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4640 "Originate default route to this neighbor\n"
4641 "Route-map to specify criteria to originate default\n"
4642 "route-map name\n")
596c17ba 4643
718e3744 4644DEFUN (no_neighbor_default_originate,
4645 no_neighbor_default_originate_cmd,
a636c635 4646 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4647 NO_STR
4648 NEIGHBOR_STR
4649 NEIGHBOR_ADDR_STR2
a636c635
DW
4650 "Originate default route to this neighbor\n"
4651 "Route-map to specify criteria to originate default\n"
4652 "route-map name\n")
718e3744 4653{
d62a17ae 4654 int idx_peer = 2;
4655 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4656 bgp_node_afi(vty),
4657 bgp_node_safi(vty), NULL, 0);
718e3744 4658}
4659
d62a17ae 4660ALIAS_HIDDEN(
4661 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4662 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4664 "Originate default route to this neighbor\n"
4665 "Route-map to specify criteria to originate default\n"
4666 "route-map name\n")
596c17ba 4667
6b0655a2 4668
718e3744 4669/* Set neighbor's BGP port. */
d62a17ae 4670static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4671 const char *port_str)
4672{
4673 struct peer *peer;
4674 u_int16_t port;
4675 struct servent *sp;
4676
4677 peer = peer_lookup_vty(vty, ip_str);
4678 if (!peer)
4679 return CMD_WARNING_CONFIG_FAILED;
4680
4681 if (!port_str) {
4682 sp = getservbyname("bgp", "tcp");
4683 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4684 } else {
4685 port = strtoul(port_str, NULL, 10);
4686 }
718e3744 4687
d62a17ae 4688 peer_port_set(peer, port);
718e3744 4689
d62a17ae 4690 return CMD_SUCCESS;
718e3744 4691}
4692
f418446b 4693/* Set specified peer's BGP port. */
718e3744 4694DEFUN (neighbor_port,
4695 neighbor_port_cmd,
9ccf14f7 4696 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4697 NEIGHBOR_STR
4698 NEIGHBOR_ADDR_STR
4699 "Neighbor's BGP port\n"
4700 "TCP port number\n")
4701{
d62a17ae 4702 int idx_ip = 1;
4703 int idx_number = 3;
4704 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4705 argv[idx_number]->arg);
718e3744 4706}
4707
4708DEFUN (no_neighbor_port,
4709 no_neighbor_port_cmd,
9ccf14f7 4710 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4711 NO_STR
4712 NEIGHBOR_STR
4713 NEIGHBOR_ADDR_STR
8334fd5a
DW
4714 "Neighbor's BGP port\n"
4715 "TCP port number\n")
718e3744 4716{
d62a17ae 4717 int idx_ip = 2;
4718 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4719}
4720
6b0655a2 4721
718e3744 4722/* neighbor weight. */
d62a17ae 4723static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4724 safi_t safi, const char *weight_str)
718e3744 4725{
d62a17ae 4726 int ret;
4727 struct peer *peer;
4728 unsigned long weight;
718e3744 4729
d62a17ae 4730 peer = peer_and_group_lookup_vty(vty, ip_str);
4731 if (!peer)
4732 return CMD_WARNING_CONFIG_FAILED;
718e3744 4733
d62a17ae 4734 weight = strtoul(weight_str, NULL, 10);
718e3744 4735
d62a17ae 4736 ret = peer_weight_set(peer, afi, safi, weight);
4737 return bgp_vty_return(vty, ret);
718e3744 4738}
4739
d62a17ae 4740static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4741 safi_t safi)
718e3744 4742{
d62a17ae 4743 int ret;
4744 struct peer *peer;
718e3744 4745
d62a17ae 4746 peer = peer_and_group_lookup_vty(vty, ip_str);
4747 if (!peer)
4748 return CMD_WARNING_CONFIG_FAILED;
718e3744 4749
d62a17ae 4750 ret = peer_weight_unset(peer, afi, safi);
4751 return bgp_vty_return(vty, ret);
718e3744 4752}
4753
4754DEFUN (neighbor_weight,
4755 neighbor_weight_cmd,
9ccf14f7 4756 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4757 NEIGHBOR_STR
4758 NEIGHBOR_ADDR_STR2
4759 "Set default weight for routes from this neighbor\n"
4760 "default weight\n")
4761{
d62a17ae 4762 int idx_peer = 1;
4763 int idx_number = 3;
4764 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4765 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4766}
4767
d62a17ae 4768ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4769 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4770 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4771 "Set default weight for routes from this neighbor\n"
4772 "default weight\n")
596c17ba 4773
718e3744 4774DEFUN (no_neighbor_weight,
4775 no_neighbor_weight_cmd,
9ccf14f7 4776 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4777 NO_STR
4778 NEIGHBOR_STR
4779 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4780 "Set default weight for routes from this neighbor\n"
4781 "default weight\n")
718e3744 4782{
d62a17ae 4783 int idx_peer = 2;
4784 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4785 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4786}
4787
d62a17ae 4788ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4789 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4790 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4791 "Set default weight for routes from this neighbor\n"
4792 "default weight\n")
596c17ba 4793
6b0655a2 4794
718e3744 4795/* Override capability negotiation. */
4796DEFUN (neighbor_override_capability,
4797 neighbor_override_capability_cmd,
9ccf14f7 4798 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4799 NEIGHBOR_STR
4800 NEIGHBOR_ADDR_STR2
4801 "Override capability negotiation result\n")
4802{
d62a17ae 4803 int idx_peer = 1;
4804 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4805 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4806}
4807
4808DEFUN (no_neighbor_override_capability,
4809 no_neighbor_override_capability_cmd,
9ccf14f7 4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4811 NO_STR
4812 NEIGHBOR_STR
4813 NEIGHBOR_ADDR_STR2
4814 "Override capability negotiation result\n")
4815{
d62a17ae 4816 int idx_peer = 2;
4817 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4818 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4819}
6b0655a2 4820
718e3744 4821DEFUN (neighbor_strict_capability,
4822 neighbor_strict_capability_cmd,
9ccf14f7 4823 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4824 NEIGHBOR_STR
4825 NEIGHBOR_ADDR_STR
4826 "Strict capability negotiation match\n")
4827{
d62a17ae 4828 int idx_ip = 1;
4829 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4830 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4831}
4832
4833DEFUN (no_neighbor_strict_capability,
4834 no_neighbor_strict_capability_cmd,
9ccf14f7 4835 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4836 NO_STR
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR
4839 "Strict capability negotiation match\n")
4840{
d62a17ae 4841 int idx_ip = 2;
4842 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4843 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4844}
6b0655a2 4845
d62a17ae 4846static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4847 const char *keep_str, const char *hold_str)
718e3744 4848{
d62a17ae 4849 int ret;
4850 struct peer *peer;
4851 u_int32_t keepalive;
4852 u_int32_t holdtime;
718e3744 4853
d62a17ae 4854 peer = peer_and_group_lookup_vty(vty, ip_str);
4855 if (!peer)
4856 return CMD_WARNING_CONFIG_FAILED;
718e3744 4857
d62a17ae 4858 keepalive = strtoul(keep_str, NULL, 10);
4859 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4860
d62a17ae 4861 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4862
d62a17ae 4863 return bgp_vty_return(vty, ret);
718e3744 4864}
6b0655a2 4865
d62a17ae 4866static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4867{
d62a17ae 4868 int ret;
4869 struct peer *peer;
718e3744 4870
d62a17ae 4871 peer = peer_and_group_lookup_vty(vty, ip_str);
4872 if (!peer)
4873 return CMD_WARNING_CONFIG_FAILED;
718e3744 4874
d62a17ae 4875 ret = peer_timers_unset(peer);
718e3744 4876
d62a17ae 4877 return bgp_vty_return(vty, ret);
718e3744 4878}
4879
4880DEFUN (neighbor_timers,
4881 neighbor_timers_cmd,
9ccf14f7 4882 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4883 NEIGHBOR_STR
4884 NEIGHBOR_ADDR_STR2
4885 "BGP per neighbor timers\n"
4886 "Keepalive interval\n"
4887 "Holdtime\n")
4888{
d62a17ae 4889 int idx_peer = 1;
4890 int idx_number = 3;
4891 int idx_number_2 = 4;
4892 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4893 argv[idx_number]->arg,
4894 argv[idx_number_2]->arg);
718e3744 4895}
4896
4897DEFUN (no_neighbor_timers,
4898 no_neighbor_timers_cmd,
9ccf14f7 4899 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4900 NO_STR
4901 NEIGHBOR_STR
4902 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4903 "BGP per neighbor timers\n"
4904 "Keepalive interval\n"
4905 "Holdtime\n")
718e3744 4906{
d62a17ae 4907 int idx_peer = 2;
4908 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4909}
6b0655a2 4910
813d4307 4911
d62a17ae 4912static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4913 const char *time_str)
718e3744 4914{
d62a17ae 4915 int ret;
4916 struct peer *peer;
4917 u_int32_t connect;
718e3744 4918
d62a17ae 4919 peer = peer_and_group_lookup_vty(vty, ip_str);
4920 if (!peer)
4921 return CMD_WARNING_CONFIG_FAILED;
718e3744 4922
d62a17ae 4923 connect = strtoul(time_str, NULL, 10);
718e3744 4924
d62a17ae 4925 ret = peer_timers_connect_set(peer, connect);
718e3744 4926
d62a17ae 4927 return bgp_vty_return(vty, ret);
718e3744 4928}
4929
d62a17ae 4930static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4931{
d62a17ae 4932 int ret;
4933 struct peer *peer;
718e3744 4934
d62a17ae 4935 peer = peer_and_group_lookup_vty(vty, ip_str);
4936 if (!peer)
4937 return CMD_WARNING_CONFIG_FAILED;
718e3744 4938
d62a17ae 4939 ret = peer_timers_connect_unset(peer);
718e3744 4940
d62a17ae 4941 return bgp_vty_return(vty, ret);
718e3744 4942}
4943
4944DEFUN (neighbor_timers_connect,
4945 neighbor_timers_connect_cmd,
9ccf14f7 4946 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 4947 NEIGHBOR_STR
966f821c 4948 NEIGHBOR_ADDR_STR2
718e3744 4949 "BGP per neighbor timers\n"
4950 "BGP connect timer\n"
4951 "Connect timer\n")
4952{
d62a17ae 4953 int idx_peer = 1;
4954 int idx_number = 4;
4955 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
4956 argv[idx_number]->arg);
718e3744 4957}
4958
4959DEFUN (no_neighbor_timers_connect,
4960 no_neighbor_timers_connect_cmd,
9ccf14f7 4961 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 4962 NO_STR
4963 NEIGHBOR_STR
966f821c 4964 NEIGHBOR_ADDR_STR2
718e3744 4965 "BGP per neighbor timers\n"
8334fd5a
DW
4966 "BGP connect timer\n"
4967 "Connect timer\n")
718e3744 4968{
d62a17ae 4969 int idx_peer = 2;
4970 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4971}
4972
6b0655a2 4973
d62a17ae 4974static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
4975 const char *time_str, int set)
718e3744 4976{
d62a17ae 4977 int ret;
4978 struct peer *peer;
4979 u_int32_t routeadv = 0;
718e3744 4980
d62a17ae 4981 peer = peer_and_group_lookup_vty(vty, ip_str);
4982 if (!peer)
4983 return CMD_WARNING_CONFIG_FAILED;
718e3744 4984
d62a17ae 4985 if (time_str)
4986 routeadv = strtoul(time_str, NULL, 10);
718e3744 4987
d62a17ae 4988 if (set)
4989 ret = peer_advertise_interval_set(peer, routeadv);
4990 else
4991 ret = peer_advertise_interval_unset(peer);
718e3744 4992
d62a17ae 4993 return bgp_vty_return(vty, ret);
718e3744 4994}
4995
4996DEFUN (neighbor_advertise_interval,
4997 neighbor_advertise_interval_cmd,
9ccf14f7 4998 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 4999 NEIGHBOR_STR
966f821c 5000 NEIGHBOR_ADDR_STR2
718e3744 5001 "Minimum interval between sending BGP routing updates\n"
5002 "time in seconds\n")
5003{
d62a17ae 5004 int idx_peer = 1;
5005 int idx_number = 3;
5006 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5007 argv[idx_number]->arg, 1);
718e3744 5008}
5009
5010DEFUN (no_neighbor_advertise_interval,
5011 no_neighbor_advertise_interval_cmd,
9ccf14f7 5012 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5013 NO_STR
5014 NEIGHBOR_STR
966f821c 5015 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5016 "Minimum interval between sending BGP routing updates\n"
5017 "time in seconds\n")
718e3744 5018{
d62a17ae 5019 int idx_peer = 2;
5020 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5021}
5022
6b0655a2 5023
518f0eb1
DS
5024/* Time to wait before processing route-map updates */
5025DEFUN (bgp_set_route_map_delay_timer,
5026 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5027 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5028 SET_STR
5029 "BGP route-map delay timer\n"
5030 "Time in secs to wait before processing route-map changes\n"
f414725f 5031 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5032{
d62a17ae 5033 int idx_number = 3;
5034 u_int32_t rmap_delay_timer;
5035
5036 if (argv[idx_number]->arg) {
5037 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5038 bm->rmap_update_timer = rmap_delay_timer;
5039
5040 /* if the dynamic update handling is being disabled, and a timer
5041 * is
5042 * running, stop the timer and act as if the timer has already
5043 * fired.
5044 */
5045 if (!rmap_delay_timer && bm->t_rmap_update) {
5046 BGP_TIMER_OFF(bm->t_rmap_update);
5047 thread_execute(bm->master, bgp_route_map_update_timer,
5048 NULL, 0);
5049 }
5050 return CMD_SUCCESS;
5051 } else {
5052 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5053 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5054 }
518f0eb1
DS
5055}
5056
5057DEFUN (no_bgp_set_route_map_delay_timer,
5058 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5059 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5060 NO_STR
3a2d747c 5061 BGP_STR
518f0eb1 5062 "Default BGP route-map delay timer\n"
8334fd5a
DW
5063 "Reset to default time to wait for processing route-map changes\n"
5064 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5065{
518f0eb1 5066
d62a17ae 5067 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5068
d62a17ae 5069 return CMD_SUCCESS;
518f0eb1
DS
5070}
5071
f414725f 5072
718e3744 5073/* neighbor interface */
d62a17ae 5074static int peer_interface_vty(struct vty *vty, const char *ip_str,
5075 const char *str)
718e3744 5076{
d62a17ae 5077 struct peer *peer;
718e3744 5078
d62a17ae 5079 peer = peer_lookup_vty(vty, ip_str);
5080 if (!peer || peer->conf_if) {
5081 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5082 return CMD_WARNING_CONFIG_FAILED;
5083 }
718e3744 5084
d62a17ae 5085 if (str)
5086 peer_interface_set(peer, str);
5087 else
5088 peer_interface_unset(peer);
718e3744 5089
d62a17ae 5090 return CMD_SUCCESS;
718e3744 5091}
5092
5093DEFUN (neighbor_interface,
5094 neighbor_interface_cmd,
9ccf14f7 5095 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5096 NEIGHBOR_STR
5097 NEIGHBOR_ADDR_STR
5098 "Interface\n"
5099 "Interface name\n")
5100{
d62a17ae 5101 int idx_ip = 1;
5102 int idx_word = 3;
5103 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5104}
5105
5106DEFUN (no_neighbor_interface,
5107 no_neighbor_interface_cmd,
9ccf14f7 5108 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5109 NO_STR
5110 NEIGHBOR_STR
16cedbb0 5111 NEIGHBOR_ADDR_STR2
718e3744 5112 "Interface\n"
5113 "Interface name\n")
5114{
d62a17ae 5115 int idx_peer = 2;
5116 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5117}
6b0655a2 5118
718e3744 5119DEFUN (neighbor_distribute_list,
5120 neighbor_distribute_list_cmd,
9ccf14f7 5121 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5122 NEIGHBOR_STR
5123 NEIGHBOR_ADDR_STR2
5124 "Filter updates to/from this neighbor\n"
5125 "IP access-list number\n"
5126 "IP access-list number (expanded range)\n"
5127 "IP Access-list name\n"
5128 "Filter incoming updates\n"
5129 "Filter outgoing updates\n")
5130{
d62a17ae 5131 int idx_peer = 1;
5132 int idx_acl = 3;
5133 int direct, ret;
5134 struct peer *peer;
a8206004 5135
d62a17ae 5136 const char *pstr = argv[idx_peer]->arg;
5137 const char *acl = argv[idx_acl]->arg;
5138 const char *inout = argv[argc - 1]->text;
a8206004 5139
d62a17ae 5140 peer = peer_and_group_lookup_vty(vty, pstr);
5141 if (!peer)
5142 return CMD_WARNING_CONFIG_FAILED;
a8206004 5143
d62a17ae 5144 /* Check filter direction. */
5145 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5146 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5147 direct, acl);
a8206004 5148
d62a17ae 5149 return bgp_vty_return(vty, ret);
718e3744 5150}
5151
d62a17ae 5152ALIAS_HIDDEN(
5153 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5154 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5156 "Filter updates to/from this neighbor\n"
5157 "IP access-list number\n"
5158 "IP access-list number (expanded range)\n"
5159 "IP Access-list name\n"
5160 "Filter incoming updates\n"
5161 "Filter outgoing updates\n")
596c17ba 5162
718e3744 5163DEFUN (no_neighbor_distribute_list,
5164 no_neighbor_distribute_list_cmd,
9ccf14f7 5165 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5166 NO_STR
5167 NEIGHBOR_STR
5168 NEIGHBOR_ADDR_STR2
5169 "Filter updates to/from this neighbor\n"
5170 "IP access-list number\n"
5171 "IP access-list number (expanded range)\n"
5172 "IP Access-list name\n"
5173 "Filter incoming updates\n"
5174 "Filter outgoing updates\n")
5175{
d62a17ae 5176 int idx_peer = 2;
5177 int direct, ret;
5178 struct peer *peer;
a8206004 5179
d62a17ae 5180 const char *pstr = argv[idx_peer]->arg;
5181 const char *inout = argv[argc - 1]->text;
a8206004 5182
d62a17ae 5183 peer = peer_and_group_lookup_vty(vty, pstr);
5184 if (!peer)
5185 return CMD_WARNING_CONFIG_FAILED;
a8206004 5186
d62a17ae 5187 /* Check filter direction. */
5188 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5189 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5190 direct);
a8206004 5191
d62a17ae 5192 return bgp_vty_return(vty, ret);
718e3744 5193}
6b0655a2 5194
d62a17ae 5195ALIAS_HIDDEN(
5196 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5199 "Filter updates to/from this neighbor\n"
5200 "IP access-list number\n"
5201 "IP access-list number (expanded range)\n"
5202 "IP Access-list name\n"
5203 "Filter incoming updates\n"
5204 "Filter outgoing updates\n")
596c17ba 5205
718e3744 5206/* Set prefix list to the peer. */
d62a17ae 5207static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5208 afi_t afi, safi_t safi,
5209 const char *name_str,
5210 const char *direct_str)
718e3744 5211{
d62a17ae 5212 int ret;
5213 struct peer *peer;
5214 int direct = FILTER_IN;
718e3744 5215
d62a17ae 5216 peer = peer_and_group_lookup_vty(vty, ip_str);
5217 if (!peer)
5218 return CMD_WARNING_CONFIG_FAILED;
718e3744 5219
d62a17ae 5220 /* Check filter direction. */
5221 if (strncmp(direct_str, "i", 1) == 0)
5222 direct = FILTER_IN;
5223 else if (strncmp(direct_str, "o", 1) == 0)
5224 direct = FILTER_OUT;
718e3744 5225
d62a17ae 5226 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5227
d62a17ae 5228 return bgp_vty_return(vty, ret);
718e3744 5229}
5230
d62a17ae 5231static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5232 afi_t afi, safi_t safi,
5233 const char *direct_str)
718e3744 5234{
d62a17ae 5235 int ret;
5236 struct peer *peer;
5237 int direct = FILTER_IN;
718e3744 5238
d62a17ae 5239 peer = peer_and_group_lookup_vty(vty, ip_str);
5240 if (!peer)
5241 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5242
d62a17ae 5243 /* Check filter direction. */
5244 if (strncmp(direct_str, "i", 1) == 0)
5245 direct = FILTER_IN;
5246 else if (strncmp(direct_str, "o", 1) == 0)
5247 direct = FILTER_OUT;
718e3744 5248
d62a17ae 5249 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5250
d62a17ae 5251 return bgp_vty_return(vty, ret);
718e3744 5252}
5253
5254DEFUN (neighbor_prefix_list,
5255 neighbor_prefix_list_cmd,
9ccf14f7 5256 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Filter updates to/from this neighbor\n"
5260 "Name of a prefix list\n"
5261 "Filter incoming updates\n"
5262 "Filter outgoing updates\n")
5263{
d62a17ae 5264 int idx_peer = 1;
5265 int idx_word = 3;
5266 int idx_in_out = 4;
5267 return peer_prefix_list_set_vty(
5268 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5269 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5270}
5271
d62a17ae 5272ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5273 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5275 "Filter updates to/from this neighbor\n"
5276 "Name of a prefix list\n"
5277 "Filter incoming updates\n"
5278 "Filter outgoing updates\n")
596c17ba 5279
718e3744 5280DEFUN (no_neighbor_prefix_list,
5281 no_neighbor_prefix_list_cmd,
9ccf14f7 5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5283 NO_STR
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Filter updates to/from this neighbor\n"
5287 "Name of a prefix list\n"
5288 "Filter incoming updates\n"
5289 "Filter outgoing updates\n")
5290{
d62a17ae 5291 int idx_peer = 2;
5292 int idx_in_out = 5;
5293 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5294 bgp_node_afi(vty), bgp_node_safi(vty),
5295 argv[idx_in_out]->arg);
718e3744 5296}
6b0655a2 5297
d62a17ae 5298ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5299 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5300 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5301 "Filter updates to/from this neighbor\n"
5302 "Name of a prefix list\n"
5303 "Filter incoming updates\n"
5304 "Filter outgoing updates\n")
596c17ba 5305
d62a17ae 5306static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5307 safi_t safi, const char *name_str,
5308 const char *direct_str)
718e3744 5309{
d62a17ae 5310 int ret;
5311 struct peer *peer;
5312 int direct = FILTER_IN;
718e3744 5313
d62a17ae 5314 peer = peer_and_group_lookup_vty(vty, ip_str);
5315 if (!peer)
5316 return CMD_WARNING_CONFIG_FAILED;
718e3744 5317
d62a17ae 5318 /* Check filter direction. */
5319 if (strncmp(direct_str, "i", 1) == 0)
5320 direct = FILTER_IN;
5321 else if (strncmp(direct_str, "o", 1) == 0)
5322 direct = FILTER_OUT;
718e3744 5323
d62a17ae 5324 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5325
d62a17ae 5326 return bgp_vty_return(vty, ret);
718e3744 5327}
5328
d62a17ae 5329static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5330 safi_t safi, const char *direct_str)
718e3744 5331{
d62a17ae 5332 int ret;
5333 struct peer *peer;
5334 int direct = FILTER_IN;
718e3744 5335
d62a17ae 5336 peer = peer_and_group_lookup_vty(vty, ip_str);
5337 if (!peer)
5338 return CMD_WARNING_CONFIG_FAILED;
718e3744 5339
d62a17ae 5340 /* Check filter direction. */
5341 if (strncmp(direct_str, "i", 1) == 0)
5342 direct = FILTER_IN;
5343 else if (strncmp(direct_str, "o", 1) == 0)
5344 direct = FILTER_OUT;
718e3744 5345
d62a17ae 5346 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5347
d62a17ae 5348 return bgp_vty_return(vty, ret);
718e3744 5349}
5350
5351DEFUN (neighbor_filter_list,
5352 neighbor_filter_list_cmd,
9ccf14f7 5353 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5354 NEIGHBOR_STR
5355 NEIGHBOR_ADDR_STR2
5356 "Establish BGP filters\n"
5357 "AS path access-list name\n"
5358 "Filter incoming routes\n"
5359 "Filter outgoing routes\n")
5360{
d62a17ae 5361 int idx_peer = 1;
5362 int idx_word = 3;
5363 int idx_in_out = 4;
5364 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5365 bgp_node_safi(vty), argv[idx_word]->arg,
5366 argv[idx_in_out]->arg);
718e3744 5367}
5368
d62a17ae 5369ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5370 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5371 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5372 "Establish BGP filters\n"
5373 "AS path access-list name\n"
5374 "Filter incoming routes\n"
5375 "Filter outgoing routes\n")
596c17ba 5376
718e3744 5377DEFUN (no_neighbor_filter_list,
5378 no_neighbor_filter_list_cmd,
9ccf14f7 5379 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5380 NO_STR
5381 NEIGHBOR_STR
5382 NEIGHBOR_ADDR_STR2
5383 "Establish BGP filters\n"
5384 "AS path access-list name\n"
5385 "Filter incoming routes\n"
5386 "Filter outgoing routes\n")
5387{
d62a17ae 5388 int idx_peer = 2;
5389 int idx_in_out = 5;
5390 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5391 bgp_node_afi(vty), bgp_node_safi(vty),
5392 argv[idx_in_out]->arg);
718e3744 5393}
6b0655a2 5394
d62a17ae 5395ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5396 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5397 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5398 "Establish BGP filters\n"
5399 "AS path access-list name\n"
5400 "Filter incoming routes\n"
5401 "Filter outgoing routes\n")
596c17ba 5402
718e3744 5403/* Set route-map to the peer. */
d62a17ae 5404static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5405 afi_t afi, safi_t safi, const char *name_str,
5406 const char *direct_str)
718e3744 5407{
d62a17ae 5408 int ret;
5409 struct peer *peer;
5410 int direct = RMAP_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, "in", 2) == 0)
5418 direct = RMAP_IN;
5419 else if (strncmp(direct_str, "o", 1) == 0)
5420 direct = RMAP_OUT;
718e3744 5421
d62a17ae 5422 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5423
d62a17ae 5424 return bgp_vty_return(vty, ret);
718e3744 5425}
5426
d62a17ae 5427static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5428 afi_t afi, safi_t safi,
5429 const char *direct_str)
718e3744 5430{
d62a17ae 5431 int ret;
5432 struct peer *peer;
5433 int direct = RMAP_IN;
718e3744 5434
d62a17ae 5435 peer = peer_and_group_lookup_vty(vty, ip_str);
5436 if (!peer)
5437 return CMD_WARNING_CONFIG_FAILED;
718e3744 5438
d62a17ae 5439 /* Check filter direction. */
5440 if (strncmp(direct_str, "in", 2) == 0)
5441 direct = RMAP_IN;
5442 else if (strncmp(direct_str, "o", 1) == 0)
5443 direct = RMAP_OUT;
718e3744 5444
d62a17ae 5445 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5446
d62a17ae 5447 return bgp_vty_return(vty, ret);
718e3744 5448}
5449
5450DEFUN (neighbor_route_map,
5451 neighbor_route_map_cmd,
9ccf14f7 5452 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5453 NEIGHBOR_STR
5454 NEIGHBOR_ADDR_STR2
5455 "Apply route map to neighbor\n"
5456 "Name of route map\n"
5457 "Apply map to incoming routes\n"
2a3d5731 5458 "Apply map to outbound routes\n")
718e3744 5459{
d62a17ae 5460 int idx_peer = 1;
5461 int idx_word = 3;
5462 int idx_in_out = 4;
5463 return peer_route_map_set_vty(
5464 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5465 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5466}
5467
d62a17ae 5468ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5469 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5470 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5471 "Apply route map to neighbor\n"
5472 "Name of route map\n"
5473 "Apply map to incoming routes\n"
5474 "Apply map to outbound routes\n")
596c17ba 5475
718e3744 5476DEFUN (no_neighbor_route_map,
5477 no_neighbor_route_map_cmd,
9ccf14f7 5478 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5479 NO_STR
5480 NEIGHBOR_STR
5481 NEIGHBOR_ADDR_STR2
5482 "Apply route map to neighbor\n"
5483 "Name of route map\n"
5484 "Apply map to incoming routes\n"
2a3d5731 5485 "Apply map to outbound routes\n")
718e3744 5486{
d62a17ae 5487 int idx_peer = 2;
5488 int idx_in_out = 5;
5489 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5490 bgp_node_afi(vty), bgp_node_safi(vty),
5491 argv[idx_in_out]->arg);
718e3744 5492}
6b0655a2 5493
d62a17ae 5494ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5495 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5496 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5497 "Apply route map to neighbor\n"
5498 "Name of route map\n"
5499 "Apply map to incoming routes\n"
5500 "Apply map to outbound routes\n")
596c17ba 5501
718e3744 5502/* Set unsuppress-map to the peer. */
d62a17ae 5503static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5504 afi_t afi, safi_t safi,
5505 const char *name_str)
718e3744 5506{
d62a17ae 5507 int ret;
5508 struct peer *peer;
718e3744 5509
d62a17ae 5510 peer = peer_and_group_lookup_vty(vty, ip_str);
5511 if (!peer)
5512 return CMD_WARNING_CONFIG_FAILED;
718e3744 5513
d62a17ae 5514 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5515
d62a17ae 5516 return bgp_vty_return(vty, ret);
718e3744 5517}
5518
5519/* Unset route-map from the peer. */
d62a17ae 5520static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5521 afi_t afi, safi_t safi)
718e3744 5522{
d62a17ae 5523 int ret;
5524 struct peer *peer;
718e3744 5525
d62a17ae 5526 peer = peer_and_group_lookup_vty(vty, ip_str);
5527 if (!peer)
5528 return CMD_WARNING_CONFIG_FAILED;
718e3744 5529
d62a17ae 5530 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5531
d62a17ae 5532 return bgp_vty_return(vty, ret);
718e3744 5533}
5534
5535DEFUN (neighbor_unsuppress_map,
5536 neighbor_unsuppress_map_cmd,
9ccf14f7 5537 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5538 NEIGHBOR_STR
5539 NEIGHBOR_ADDR_STR2
5540 "Route-map to selectively unsuppress suppressed routes\n"
5541 "Name of route map\n")
5542{
d62a17ae 5543 int idx_peer = 1;
5544 int idx_word = 3;
5545 return peer_unsuppress_map_set_vty(
5546 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5547 argv[idx_word]->arg);
718e3744 5548}
5549
d62a17ae 5550ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5551 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5552 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5553 "Route-map to selectively unsuppress suppressed routes\n"
5554 "Name of route map\n")
596c17ba 5555
718e3744 5556DEFUN (no_neighbor_unsuppress_map,
5557 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5558 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5559 NO_STR
5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Route-map to selectively unsuppress suppressed routes\n"
5563 "Name of route map\n")
5564{
d62a17ae 5565 int idx_peer = 2;
5566 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5567 bgp_node_afi(vty),
5568 bgp_node_safi(vty));
718e3744 5569}
6b0655a2 5570
d62a17ae 5571ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5572 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5573 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5574 "Route-map to selectively unsuppress suppressed routes\n"
5575 "Name of route map\n")
596c17ba 5576
d62a17ae 5577static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5578 afi_t afi, safi_t safi,
5579 const char *num_str,
5580 const char *threshold_str, int warning,
5581 const char *restart_str)
718e3744 5582{
d62a17ae 5583 int ret;
5584 struct peer *peer;
5585 u_int32_t max;
5586 u_char threshold;
5587 u_int16_t restart;
718e3744 5588
d62a17ae 5589 peer = peer_and_group_lookup_vty(vty, ip_str);
5590 if (!peer)
5591 return CMD_WARNING_CONFIG_FAILED;
718e3744 5592
d62a17ae 5593 max = strtoul(num_str, NULL, 10);
5594 if (threshold_str)
5595 threshold = atoi(threshold_str);
5596 else
5597 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5598
d62a17ae 5599 if (restart_str)
5600 restart = atoi(restart_str);
5601 else
5602 restart = 0;
0a486e5f 5603
d62a17ae 5604 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5605 restart);
718e3744 5606
d62a17ae 5607 return bgp_vty_return(vty, ret);
718e3744 5608}
5609
d62a17ae 5610static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5611 afi_t afi, safi_t safi)
718e3744 5612{
d62a17ae 5613 int ret;
5614 struct peer *peer;
718e3744 5615
d62a17ae 5616 peer = peer_and_group_lookup_vty(vty, ip_str);
5617 if (!peer)
5618 return CMD_WARNING_CONFIG_FAILED;
718e3744 5619
d62a17ae 5620 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5621
d62a17ae 5622 return bgp_vty_return(vty, ret);
718e3744 5623}
5624
5625/* Maximum number of prefix configuration. prefix count is different
5626 for each peer configuration. So this configuration can be set for
5627 each peer configuration. */
5628DEFUN (neighbor_maximum_prefix,
5629 neighbor_maximum_prefix_cmd,
9ccf14f7 5630 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5631 NEIGHBOR_STR
5632 NEIGHBOR_ADDR_STR2
5633 "Maximum number of prefix accept from this peer\n"
5634 "maximum no. of prefix limit\n")
5635{
d62a17ae 5636 int idx_peer = 1;
5637 int idx_number = 3;
5638 return peer_maximum_prefix_set_vty(
5639 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5640 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5641}
5642
d62a17ae 5643ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Maximum number of prefix accept from this peer\n"
5647 "maximum no. of prefix limit\n")
596c17ba 5648
e0701b79 5649DEFUN (neighbor_maximum_prefix_threshold,
5650 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5651 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Maximum number of prefix accept from this peer\n"
5655 "maximum no. of prefix limit\n"
5656 "Threshold value (%) at which to generate a warning msg\n")
5657{
d62a17ae 5658 int idx_peer = 1;
5659 int idx_number = 3;
5660 int idx_number_2 = 4;
5661 return peer_maximum_prefix_set_vty(
5662 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5663 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5664}
e0701b79 5665
d62a17ae 5666ALIAS_HIDDEN(
5667 neighbor_maximum_prefix_threshold,
5668 neighbor_maximum_prefix_threshold_hidden_cmd,
5669 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5671 "Maximum number of prefix accept from this peer\n"
5672 "maximum no. of prefix limit\n"
5673 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5674
718e3744 5675DEFUN (neighbor_maximum_prefix_warning,
5676 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5677 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5678 NEIGHBOR_STR
5679 NEIGHBOR_ADDR_STR2
5680 "Maximum number of prefix accept from this peer\n"
5681 "maximum no. of prefix limit\n"
5682 "Only give warning message when limit is exceeded\n")
5683{
d62a17ae 5684 int idx_peer = 1;
5685 int idx_number = 3;
5686 return peer_maximum_prefix_set_vty(
5687 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5688 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5689}
5690
d62a17ae 5691ALIAS_HIDDEN(
5692 neighbor_maximum_prefix_warning,
5693 neighbor_maximum_prefix_warning_hidden_cmd,
5694 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5696 "Maximum number of prefix accept from this peer\n"
5697 "maximum no. of prefix limit\n"
5698 "Only give warning message when limit is exceeded\n")
596c17ba 5699
e0701b79 5700DEFUN (neighbor_maximum_prefix_threshold_warning,
5701 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5702 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5703 NEIGHBOR_STR
5704 NEIGHBOR_ADDR_STR2
5705 "Maximum number of prefix accept from this peer\n"
5706 "maximum no. of prefix limit\n"
5707 "Threshold value (%) at which to generate a warning msg\n"
5708 "Only give warning message when limit is exceeded\n")
5709{
d62a17ae 5710 int idx_peer = 1;
5711 int idx_number = 3;
5712 int idx_number_2 = 4;
5713 return peer_maximum_prefix_set_vty(
5714 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5715 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5716}
5717
d62a17ae 5718ALIAS_HIDDEN(
5719 neighbor_maximum_prefix_threshold_warning,
5720 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5721 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5723 "Maximum number of prefix accept from this peer\n"
5724 "maximum no. of prefix limit\n"
5725 "Threshold value (%) at which to generate a warning msg\n"
5726 "Only give warning message when limit is exceeded\n")
596c17ba 5727
0a486e5f 5728DEFUN (neighbor_maximum_prefix_restart,
5729 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5730 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5731 NEIGHBOR_STR
5732 NEIGHBOR_ADDR_STR2
5733 "Maximum number of prefix accept from this peer\n"
5734 "maximum no. of prefix limit\n"
5735 "Restart bgp connection after limit is exceeded\n"
5736 "Restart interval in minutes")
5737{
d62a17ae 5738 int idx_peer = 1;
5739 int idx_number = 3;
5740 int idx_number_2 = 5;
5741 return peer_maximum_prefix_set_vty(
5742 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5743 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5744}
5745
d62a17ae 5746ALIAS_HIDDEN(
5747 neighbor_maximum_prefix_restart,
5748 neighbor_maximum_prefix_restart_hidden_cmd,
5749 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5751 "Maximum number of prefix accept from this peer\n"
5752 "maximum no. of prefix limit\n"
5753 "Restart bgp connection after limit is exceeded\n"
5754 "Restart interval in minutes")
596c17ba 5755
0a486e5f 5756DEFUN (neighbor_maximum_prefix_threshold_restart,
5757 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5758 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5759 NEIGHBOR_STR
5760 NEIGHBOR_ADDR_STR2
16cedbb0 5761 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5762 "maximum no. of prefix limit\n"
5763 "Threshold value (%) at which to generate a warning msg\n"
5764 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5765 "Restart interval in minutes\n")
0a486e5f 5766{
d62a17ae 5767 int idx_peer = 1;
5768 int idx_number = 3;
5769 int idx_number_2 = 4;
5770 int idx_number_3 = 6;
5771 return peer_maximum_prefix_set_vty(
5772 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5773 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5774 argv[idx_number_3]->arg);
5775}
5776
5777ALIAS_HIDDEN(
5778 neighbor_maximum_prefix_threshold_restart,
5779 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5780 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5781 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5782 "Maximum number of prefixes to accept from this peer\n"
5783 "maximum no. of prefix limit\n"
5784 "Threshold value (%) at which to generate a warning msg\n"
5785 "Restart bgp connection after limit is exceeded\n"
5786 "Restart interval in minutes\n")
596c17ba 5787
718e3744 5788DEFUN (no_neighbor_maximum_prefix,
5789 no_neighbor_maximum_prefix_cmd,
d04c479d 5790 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5791 NO_STR
5792 NEIGHBOR_STR
5793 NEIGHBOR_ADDR_STR2
16cedbb0 5794 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5795 "maximum no. of prefix limit\n"
5796 "Threshold value (%) at which to generate a warning msg\n"
5797 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5798 "Restart interval in minutes\n"
31500417 5799 "Only give warning message when limit is exceeded\n")
718e3744 5800{
d62a17ae 5801 int idx_peer = 2;
5802 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5803 bgp_node_afi(vty),
5804 bgp_node_safi(vty));
718e3744 5805}
e52702f2 5806
d62a17ae 5807ALIAS_HIDDEN(
5808 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5809 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5810 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5811 "Maximum number of prefixes to accept from this peer\n"
5812 "maximum no. of prefix limit\n"
5813 "Threshold value (%) at which to generate a warning msg\n"
5814 "Restart bgp connection after limit is exceeded\n"
5815 "Restart interval in minutes\n"
5816 "Only give warning message when limit is exceeded\n")
596c17ba 5817
718e3744 5818
718e3744 5819/* "neighbor allowas-in" */
5820DEFUN (neighbor_allowas_in,
5821 neighbor_allowas_in_cmd,
fd8503f5 5822 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
31500417 5825 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5826 "Number of occurances of AS number\n"
5827 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5828{
d62a17ae 5829 int idx_peer = 1;
5830 int idx_number_origin = 3;
5831 int ret;
5832 int origin = 0;
5833 struct peer *peer;
5834 int allow_num = 0;
5835
5836 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5837 if (!peer)
5838 return CMD_WARNING_CONFIG_FAILED;
5839
5840 if (argc <= idx_number_origin)
5841 allow_num = 3;
5842 else {
5843 if (argv[idx_number_origin]->type == WORD_TKN)
5844 origin = 1;
5845 else
5846 allow_num = atoi(argv[idx_number_origin]->arg);
5847 }
5848
5849 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5850 allow_num, origin);
5851
5852 return bgp_vty_return(vty, ret);
5853}
5854
5855ALIAS_HIDDEN(
5856 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5857 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5858 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5859 "Accept as-path with my AS present in it\n"
5860 "Number of occurances of AS number\n"
5861 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5862
718e3744 5863DEFUN (no_neighbor_allowas_in,
5864 no_neighbor_allowas_in_cmd,
fd8503f5 5865 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5866 NO_STR
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
8334fd5a 5869 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5870 "Number of occurances of AS number\n"
5871 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5872{
d62a17ae 5873 int idx_peer = 2;
5874 int ret;
5875 struct peer *peer;
718e3744 5876
d62a17ae 5877 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5878 if (!peer)
5879 return CMD_WARNING_CONFIG_FAILED;
718e3744 5880
d62a17ae 5881 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5882 bgp_node_safi(vty));
718e3744 5883
d62a17ae 5884 return bgp_vty_return(vty, ret);
718e3744 5885}
6b0655a2 5886
d62a17ae 5887ALIAS_HIDDEN(
5888 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5889 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5890 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5891 "allow local ASN appears in aspath attribute\n"
5892 "Number of occurances of AS number\n"
5893 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5894
fa411a21
NH
5895DEFUN (neighbor_ttl_security,
5896 neighbor_ttl_security_cmd,
9ccf14f7 5897 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
16cedbb0 5900 "BGP ttl-security parameters\n"
d7fa34c1
QY
5901 "Specify the maximum number of hops to the BGP peer\n"
5902 "Number of hops to BGP peer\n")
fa411a21 5903{
d62a17ae 5904 int idx_peer = 1;
5905 int idx_number = 4;
5906 struct peer *peer;
5907 int gtsm_hops;
5908
5909 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5910 if (!peer)
5911 return CMD_WARNING_CONFIG_FAILED;
5912
5913 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5914
5915 /*
5916 * If 'neighbor swpX', then this is for directly connected peers,
5917 * we should not accept a ttl-security hops value greater than 1.
5918 */
5919 if (peer->conf_if && (gtsm_hops > 1)) {
5920 vty_out(vty,
5921 "%s is directly connected peer, hops cannot exceed 1\n",
5922 argv[idx_peer]->arg);
5923 return CMD_WARNING_CONFIG_FAILED;
5924 }
8cdabf90 5925
d62a17ae 5926 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
5927}
5928
5929DEFUN (no_neighbor_ttl_security,
5930 no_neighbor_ttl_security_cmd,
9ccf14f7 5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
16cedbb0 5935 "BGP ttl-security parameters\n"
3a2d747c
QY
5936 "Specify the maximum number of hops to the BGP peer\n"
5937 "Number of hops to BGP peer\n")
fa411a21 5938{
d62a17ae 5939 int idx_peer = 2;
5940 struct peer *peer;
fa411a21 5941
d62a17ae 5942 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5943 if (!peer)
5944 return CMD_WARNING_CONFIG_FAILED;
fa411a21 5945
d62a17ae 5946 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 5947}
6b0655a2 5948
adbac85e
DW
5949DEFUN (neighbor_addpath_tx_all_paths,
5950 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 5951 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Use addpath to advertise all paths to a neighbor\n")
5955{
d62a17ae 5956 int idx_peer = 1;
5957 struct peer *peer;
adbac85e 5958
d62a17ae 5959 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5960 if (!peer)
5961 return CMD_WARNING_CONFIG_FAILED;
adbac85e 5962
d62a17ae 5963 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5964 bgp_node_safi(vty),
5965 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
5966}
5967
d62a17ae 5968ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
5969 neighbor_addpath_tx_all_paths_hidden_cmd,
5970 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5971 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5972 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 5973
adbac85e
DW
5974DEFUN (no_neighbor_addpath_tx_all_paths,
5975 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 5976 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
5977 NO_STR
5978 NEIGHBOR_STR
5979 NEIGHBOR_ADDR_STR2
5980 "Use addpath to advertise all paths to a neighbor\n")
5981{
d62a17ae 5982 int idx_peer = 2;
5983 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5984 bgp_node_afi(vty), bgp_node_safi(vty),
5985 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
5986}
5987
d62a17ae 5988ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
5989 no_neighbor_addpath_tx_all_paths_hidden_cmd,
5990 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5991 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5992 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 5993
06370dac
DW
5994DEFUN (neighbor_addpath_tx_bestpath_per_as,
5995 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 5996 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
5997 NEIGHBOR_STR
5998 NEIGHBOR_ADDR_STR2
5999 "Use addpath to advertise the bestpath per each neighboring AS\n")
6000{
d62a17ae 6001 int idx_peer = 1;
6002 struct peer *peer;
06370dac 6003
d62a17ae 6004 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6005 if (!peer)
6006 return CMD_WARNING_CONFIG_FAILED;
06370dac 6007
d62a17ae 6008 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6009 bgp_node_safi(vty),
6010 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6011}
6012
d62a17ae 6013ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6014 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6017 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6018
06370dac
DW
6019DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6020 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6022 NO_STR
6023 NEIGHBOR_STR
6024 NEIGHBOR_ADDR_STR2
6025 "Use addpath to advertise the bestpath per each neighboring AS\n")
6026{
d62a17ae 6027 int idx_peer = 2;
6028 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6029 bgp_node_afi(vty), bgp_node_safi(vty),
6030 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6031}
6032
d62a17ae 6033ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6034 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6036 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6037 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6038
505e5056 6039DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6040 address_family_ipv4_safi_cmd,
5b1f0f29 6041 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6042 "Enter Address Family command mode\n"
8c3deaae 6043 "Address Family\n"
b6ab5a3a 6044 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6045{
f51bae9c 6046
d62a17ae 6047 if (argc == 3) {
6048 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6049 vty->node = bgp_node_type(AFI_IP, safi);
6050 } else
6051 vty->node = BGP_IPV4_NODE;
718e3744 6052
d62a17ae 6053 return CMD_SUCCESS;
718e3744 6054}
6055
505e5056 6056DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6057 address_family_ipv6_safi_cmd,
5b1f0f29 6058 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6059 "Enter Address Family command mode\n"
8c3deaae 6060 "Address Family\n"
b6ab5a3a 6061 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6062{
d62a17ae 6063 if (argc == 3) {
6064 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6065 vty->node = bgp_node_type(AFI_IP6, safi);
6066 } else
6067 vty->node = BGP_IPV6_NODE;
25ffbdc1 6068
d62a17ae 6069 return CMD_SUCCESS;
25ffbdc1 6070}
718e3744 6071
d6902373 6072#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6073DEFUN_NOSH (address_family_vpnv4,
718e3744 6074 address_family_vpnv4_cmd,
8334fd5a 6075 "address-family vpnv4 [unicast]",
718e3744 6076 "Enter Address Family command mode\n"
8c3deaae 6077 "Address Family\n"
3a2d747c 6078 "Address Family modifier\n")
718e3744 6079{
d62a17ae 6080 vty->node = BGP_VPNV4_NODE;
6081 return CMD_SUCCESS;
718e3744 6082}
6083
505e5056 6084DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6085 address_family_vpnv6_cmd,
8334fd5a 6086 "address-family vpnv6 [unicast]",
8ecd3266 6087 "Enter Address Family command mode\n"
8c3deaae 6088 "Address Family\n"
3a2d747c 6089 "Address Family modifier\n")
8ecd3266 6090{
d62a17ae 6091 vty->node = BGP_VPNV6_NODE;
6092 return CMD_SUCCESS;
8ecd3266 6093}
c016b6c7 6094#endif
d6902373 6095
505e5056 6096DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6097 address_family_evpn_cmd,
7111c1a0 6098 "address-family l2vpn evpn",
4e0b7b6d 6099 "Enter Address Family command mode\n"
7111c1a0
QY
6100 "Address Family\n"
6101 "Address Family modifier\n")
4e0b7b6d 6102{
d62a17ae 6103 vty->node = BGP_EVPN_NODE;
6104 return CMD_SUCCESS;
4e0b7b6d
PG
6105}
6106
505e5056 6107DEFUN_NOSH (exit_address_family,
718e3744 6108 exit_address_family_cmd,
6109 "exit-address-family",
6110 "Exit from Address Family configuration mode\n")
6111{
d62a17ae 6112 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6113 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6114 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6115 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6116 || vty->node == BGP_EVPN_NODE)
6117 vty->node = BGP_NODE;
6118 return CMD_SUCCESS;
718e3744 6119}
6b0655a2 6120
8ad7271d 6121/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6122static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6123 const char *ip_str, afi_t afi, safi_t safi,
6124 struct prefix_rd *prd)
6125{
6126 int ret;
6127 struct prefix match;
6128 struct bgp_node *rn;
6129 struct bgp_node *rm;
6130 struct bgp *bgp;
6131 struct bgp_table *table;
6132 struct bgp_table *rib;
6133
6134 /* BGP structure lookup. */
6135 if (view_name) {
6136 bgp = bgp_lookup_by_name(view_name);
6137 if (bgp == NULL) {
6138 vty_out(vty, "%% Can't find BGP instance %s\n",
6139 view_name);
6140 return CMD_WARNING;
6141 }
6142 } else {
6143 bgp = bgp_get_default();
6144 if (bgp == NULL) {
6145 vty_out(vty, "%% No BGP process is configured\n");
6146 return CMD_WARNING;
6147 }
6148 }
6149
6150 /* Check IP address argument. */
6151 ret = str2prefix(ip_str, &match);
6152 if (!ret) {
6153 vty_out(vty, "%% address is malformed\n");
6154 return CMD_WARNING;
6155 }
6156
6157 match.family = afi2family(afi);
6158 rib = bgp->rib[afi][safi];
6159
6160 if (safi == SAFI_MPLS_VPN) {
6161 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6162 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6163 continue;
6164
6165 if ((table = rn->info) != NULL) {
6166 if ((rm = bgp_node_match(table, &match))
6167 != NULL) {
6168 if (rm->p.prefixlen
6169 == match.prefixlen) {
6170 SET_FLAG(rn->flags,
6171 BGP_NODE_USER_CLEAR);
6172 bgp_process(bgp, rm, afi, safi);
6173 }
6174 bgp_unlock_node(rm);
6175 }
6176 }
6177 }
6178 } else {
6179 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6180 if (rn->p.prefixlen == match.prefixlen) {
6181 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6182 bgp_process(bgp, rn, afi, safi);
6183 }
6184 bgp_unlock_node(rn);
6185 }
6186 }
6187
6188 return CMD_SUCCESS;
8ad7271d
DS
6189}
6190
b09b5ae0 6191/* one clear bgp command to rule them all */
718e3744 6192DEFUN (clear_ip_bgp_all,
6193 clear_ip_bgp_all_cmd,
c1a44e43 6194 "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 6195 CLEAR_STR
6196 IP_STR
6197 BGP_STR
838758ac 6198 BGP_INSTANCE_HELP_STR
510afcd6
DS
6199 BGP_AFI_HELP_STR
6200 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6201 "Clear all peers\n"
6202 "BGP neighbor address to clear\n"
a80beece 6203 "BGP IPv6 neighbor to clear\n"
838758ac 6204 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6205 "Clear peers with the AS number\n"
6206 "Clear all external peers\n"
718e3744 6207 "Clear all members of peer-group\n"
b09b5ae0 6208 "BGP peer-group name\n"
b09b5ae0
DW
6209 BGP_SOFT_STR
6210 BGP_SOFT_IN_STR
b09b5ae0
DW
6211 BGP_SOFT_OUT_STR
6212 BGP_SOFT_IN_STR
6213 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6214 BGP_SOFT_OUT_STR)
718e3744 6215{
d62a17ae 6216 char *vrf = NULL;
6217
6218 afi_t afi = AFI_IP6;
6219 safi_t safi = SAFI_UNICAST;
6220 enum clear_sort clr_sort = clear_peer;
6221 enum bgp_clear_type clr_type;
6222 char *clr_arg = NULL;
6223
6224 int idx = 0;
6225
6226 /* clear [ip] bgp */
6227 if (argv_find(argv, argc, "ip", &idx))
6228 afi = AFI_IP;
6229
6230 /* [<view|vrf> VIEWVRFNAME] */
6231 if (argv_find(argv, argc, "view", &idx)
6232 || argv_find(argv, argc, "vrf", &idx)) {
6233 vrf = argv[idx + 1]->arg;
6234 idx += 2;
6235 }
6236
6237 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6238 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6239 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6240
6241 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6242 if (argv_find(argv, argc, "*", &idx)) {
6243 clr_sort = clear_all;
6244 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6245 clr_sort = clear_peer;
6246 clr_arg = argv[idx]->arg;
6247 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6248 clr_sort = clear_peer;
6249 clr_arg = argv[idx]->arg;
6250 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6251 clr_sort = clear_group;
6252 idx++;
6253 clr_arg = argv[idx]->arg;
6254 } else if (argv_find(argv, argc, "WORD", &idx)) {
6255 clr_sort = clear_peer;
6256 clr_arg = argv[idx]->arg;
6257 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6258 clr_sort = clear_as;
6259 clr_arg = argv[idx]->arg;
6260 } else if (argv_find(argv, argc, "external", &idx)) {
6261 clr_sort = clear_external;
6262 }
6263
6264 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6265 if (argv_find(argv, argc, "soft", &idx)) {
6266 if (argv_find(argv, argc, "in", &idx)
6267 || argv_find(argv, argc, "out", &idx))
6268 clr_type = strmatch(argv[idx]->text, "in")
6269 ? BGP_CLEAR_SOFT_IN
6270 : BGP_CLEAR_SOFT_OUT;
6271 else
6272 clr_type = BGP_CLEAR_SOFT_BOTH;
6273 } else if (argv_find(argv, argc, "in", &idx)) {
6274 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6275 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6276 : BGP_CLEAR_SOFT_IN;
6277 } else if (argv_find(argv, argc, "out", &idx)) {
6278 clr_type = BGP_CLEAR_SOFT_OUT;
6279 } else
6280 clr_type = BGP_CLEAR_SOFT_NONE;
6281
6282 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6283}
01080f7c 6284
8ad7271d
DS
6285DEFUN (clear_ip_bgp_prefix,
6286 clear_ip_bgp_prefix_cmd,
18c57037 6287 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6288 CLEAR_STR
6289 IP_STR
6290 BGP_STR
838758ac 6291 BGP_INSTANCE_HELP_STR
8ad7271d 6292 "Clear bestpath and re-advertise\n"
0c7b1b01 6293 "IPv4 prefix\n")
8ad7271d 6294{
d62a17ae 6295 char *vrf = NULL;
6296 char *prefix = NULL;
8ad7271d 6297
d62a17ae 6298 int idx = 0;
01080f7c 6299
d62a17ae 6300 /* [<view|vrf> VIEWVRFNAME] */
6301 if (argv_find(argv, argc, "WORD", &idx))
6302 vrf = argv[idx]->arg;
0c7b1b01 6303
d62a17ae 6304 prefix = argv[argc - 1]->arg;
8ad7271d 6305
d62a17ae 6306 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6307}
8ad7271d 6308
b09b5ae0
DW
6309DEFUN (clear_bgp_ipv6_safi_prefix,
6310 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6311 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6312 CLEAR_STR
3a2d747c 6313 IP_STR
718e3744 6314 BGP_STR
8c3deaae 6315 "Address Family\n"
46f296b4 6316 BGP_SAFI_HELP_STR
b09b5ae0 6317 "Clear bestpath and re-advertise\n"
0c7b1b01 6318 "IPv6 prefix\n")
718e3744 6319{
d62a17ae 6320 int idx_safi = 3;
6321 int idx_ipv6_prefixlen = 5;
6322 return bgp_clear_prefix(
6323 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6324 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
838758ac 6325}
01080f7c 6326
b09b5ae0
DW
6327DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6328 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6329 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6330 CLEAR_STR
3a2d747c 6331 IP_STR
718e3744 6332 BGP_STR
838758ac 6333 BGP_INSTANCE_HELP_STR
8c3deaae 6334 "Address Family\n"
46f296b4 6335 BGP_SAFI_HELP_STR
b09b5ae0 6336 "Clear bestpath and re-advertise\n"
0c7b1b01 6337 "IPv6 prefix\n")
718e3744 6338{
d62a17ae 6339 int idx_word = 3;
6340 int idx_safi = 5;
6341 int idx_ipv6_prefixlen = 7;
6342 return bgp_clear_prefix(
6343 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6344 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
718e3744 6345}
6346
b09b5ae0
DW
6347DEFUN (show_bgp_views,
6348 show_bgp_views_cmd,
d6e3c605 6349 "show [ip] bgp views",
b09b5ae0 6350 SHOW_STR
d6e3c605 6351 IP_STR
01080f7c 6352 BGP_STR
b09b5ae0 6353 "Show the defined BGP views\n")
01080f7c 6354{
d62a17ae 6355 struct list *inst = bm->bgp;
6356 struct listnode *node;
6357 struct bgp *bgp;
01080f7c 6358
d62a17ae 6359 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6360 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6361 return CMD_WARNING;
6362 }
e52702f2 6363
d62a17ae 6364 vty_out(vty, "Defined BGP views:\n");
6365 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6366 /* Skip VRFs. */
6367 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6368 continue;
6369 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6370 bgp->as);
6371 }
e52702f2 6372
d62a17ae 6373 return CMD_SUCCESS;
e0081f70
ML
6374}
6375
8386ac43 6376DEFUN (show_bgp_vrfs,
6377 show_bgp_vrfs_cmd,
d6e3c605 6378 "show [ip] bgp vrfs [json]",
8386ac43 6379 SHOW_STR
d6e3c605 6380 IP_STR
8386ac43 6381 BGP_STR
6382 "Show BGP VRFs\n"
9973d184 6383 JSON_STR)
8386ac43 6384{
d62a17ae 6385 struct list *inst = bm->bgp;
6386 struct listnode *node;
6387 struct bgp *bgp;
6388 u_char uj = use_json(argc, argv);
6389 json_object *json = NULL;
6390 json_object *json_vrfs = NULL;
6391 int count = 0;
6392 static char header[] =
6393 "Type Id RouterId #PeersCfg #PeersEstb Name";
6394
6395 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6396 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6397 return CMD_WARNING;
6398 }
6399
6400 if (uj) {
6401 json = json_object_new_object();
6402 json_vrfs = json_object_new_object();
6403 }
6404
6405 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6406 const char *name, *type;
6407 struct peer *peer;
6408 struct listnode *node, *nnode;
6409 int peers_cfg, peers_estb;
6410 json_object *json_vrf = NULL;
6411 int vrf_id_ui;
6412
6413 /* Skip Views. */
6414 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6415 continue;
6416
6417 count++;
6418 if (!uj && count == 1)
6419 vty_out(vty, "%s\n", header);
6420
6421 peers_cfg = peers_estb = 0;
6422 if (uj)
6423 json_vrf = json_object_new_object();
6424
6425
6426 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6427 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6428 continue;
6429 peers_cfg++;
6430 if (peer->status == Established)
6431 peers_estb++;
6432 }
6433
6434 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6435 name = "Default";
6436 type = "DFLT";
6437 } else {
6438 name = bgp->name;
6439 type = "VRF";
6440 }
6441
6442 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6443 if (uj) {
6444 json_object_string_add(json_vrf, "type", type);
6445 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6446 json_object_string_add(json_vrf, "routerId",
6447 inet_ntoa(bgp->router_id));
6448 json_object_int_add(json_vrf, "numConfiguredPeers",
6449 peers_cfg);
6450 json_object_int_add(json_vrf, "numEstablishedPeers",
6451 peers_estb);
6452
6453 json_object_object_add(json_vrfs, name, json_vrf);
6454 } else
6455 vty_out(vty, "%4s %-5d %-16s %9u %10u %s\n", type,
6456 vrf_id_ui, inet_ntoa(bgp->router_id), peers_cfg,
6457 peers_estb, name);
6458 }
6459
6460 if (uj) {
6461 json_object_object_add(json, "vrfs", json_vrfs);
6462
6463 json_object_int_add(json, "totalVrfs", count);
6464
9d303b37
DL
6465 vty_out(vty, "%s\n", json_object_to_json_string_ext(
6466 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 6467 json_object_free(json);
6468 } else {
6469 if (count)
6470 vty_out(vty,
6471 "\nTotal number of VRFs (including default): %d\n",
6472 count);
6473 }
6474
6475 return CMD_SUCCESS;
8386ac43 6476}
6477
acf71666
MK
6478static void show_address_entry(struct hash_backet *backet, void *args)
6479{
60466a63
QY
6480 struct vty *vty = (struct vty *)args;
6481 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 6482
60466a63 6483 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
6484 addr->refcnt);
6485}
6486
6487static void show_tip_entry(struct hash_backet *backet, void *args)
6488{
0291c246 6489 struct vty *vty = (struct vty *)args;
60466a63 6490 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 6491
60466a63 6492 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
6493 tip->refcnt);
6494}
6495
6496static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6497{
6498 vty_out(vty, "self nexthop database:\n");
6499 hash_iterate(bgp->address_hash,
6500 (void (*)(struct hash_backet *, void *))show_address_entry,
6501 vty);
6502
6503 vty_out(vty, "Tunnel-ip database:\n");
6504 hash_iterate(bgp->tip_hash,
6505 (void (*)(struct hash_backet *, void *))show_tip_entry,
6506 vty);
6507}
6508
60466a63
QY
6509DEFUN(show_bgp_martian_nexthop_db,
6510 show_bgp_martian_nexthop_db_cmd,
6511 "show bgp martian next-hop",
6512 SHOW_STR
6513 BGP_STR
6514 "martian next-hops\n"
6515 "martian next-hop database\n")
acf71666 6516{
0291c246 6517 struct bgp *bgp = NULL;
acf71666
MK
6518
6519 bgp = bgp_get_default();
6520 if (!bgp) {
6521 vty_out(vty, "%% No BGP process is configured\n");
6522 return CMD_WARNING;
6523 }
6524 bgp_show_martian_nexthops(vty, bgp);
6525
6526 return CMD_SUCCESS;
6527}
6528
f412b39a 6529DEFUN (show_bgp_memory,
4bf6a362 6530 show_bgp_memory_cmd,
7fa12b13 6531 "show [ip] bgp memory",
4bf6a362 6532 SHOW_STR
3a2d747c 6533 IP_STR
4bf6a362
PJ
6534 BGP_STR
6535 "Global BGP memory statistics\n")
6536{
d62a17ae 6537 char memstrbuf[MTYPE_MEMSTR_LEN];
6538 unsigned long count;
6539
6540 /* RIB related usage stats */
6541 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6542 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6543 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6544 count * sizeof(struct bgp_node)));
6545
6546 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6547 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6548 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6549 count * sizeof(struct bgp_info)));
6550 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6551 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6552 count,
6553 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6554 count * sizeof(struct bgp_info_extra)));
6555
6556 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6557 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6558 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6559 count * sizeof(struct bgp_static)));
6560
6561 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6562 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6563 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6564 count * sizeof(struct bpacket)));
6565
6566 /* Adj-In/Out */
6567 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6568 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6569 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6570 count * sizeof(struct bgp_adj_in)));
6571 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6572 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6574 count * sizeof(struct bgp_adj_out)));
6575
6576 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6577 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6578 count,
6579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6580 count * sizeof(struct bgp_nexthop_cache)));
6581
6582 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6583 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6584 count,
6585 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6586 count * sizeof(struct bgp_damp_info)));
6587
6588 /* Attributes */
6589 count = attr_count();
6590 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6591 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6592 count * sizeof(struct attr)));
6593
6594 if ((count = attr_unknown_count()))
6595 vty_out(vty, "%ld unknown attributes\n", count);
6596
6597 /* AS_PATH attributes */
6598 count = aspath_count();
6599 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6600 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6601 count * sizeof(struct aspath)));
6602
6603 count = mtype_stats_alloc(MTYPE_AS_SEG);
6604 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6605 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6606 count * sizeof(struct assegment)));
6607
6608 /* Other attributes */
6609 if ((count = community_count()))
6610 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6611 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6612 count * sizeof(struct community)));
d62a17ae 6613 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6614 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6615 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6616 count * sizeof(struct ecommunity)));
d62a17ae 6617 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6618 vty_out(vty,
6619 "%ld BGP large-community entries, using %s of memory\n",
9d303b37
DL
6620 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6621 count * sizeof(struct lcommunity)));
d62a17ae 6622
6623 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6624 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6625 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6626 count * sizeof(struct cluster_list)));
6627
6628 /* Peer related usage */
6629 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6630 vty_out(vty, "%ld peers, using %s of memory\n", count,
6631 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6632 count * sizeof(struct peer)));
6633
6634 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6635 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6636 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6637 count * sizeof(struct peer_group)));
6638
6639 /* Other */
6640 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6641 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6642 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6643 count * sizeof(struct hash)));
6644 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6645 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6646 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6647 count * sizeof(struct hash_backet)));
6648 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6649 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9d303b37
DL
6650 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6651 count * sizeof(regex_t)));
d62a17ae 6652 return CMD_SUCCESS;
4bf6a362 6653}
fee0f4c6 6654
718e3744 6655/* Show BGP peer's summary information. */
d62a17ae 6656static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6657 u_char use_json, json_object *json)
6658{
6659 struct peer *peer;
6660 struct listnode *node, *nnode;
6661 unsigned int count = 0, dn_count = 0;
6662 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6663 char neighbor_buf[VTY_BUFSIZ];
6664 int neighbor_col_default_width = 16;
6665 int len;
6666 int max_neighbor_width = 0;
6667 int pfx_rcd_safi;
6668 json_object *json_peer = NULL;
6669 json_object *json_peers = NULL;
6670
6671 /* labeled-unicast routes are installed in the unicast table so in order
6672 * to
6673 * display the correct PfxRcd value we must look at SAFI_UNICAST
6674 */
6675 if (safi == SAFI_LABELED_UNICAST)
6676 pfx_rcd_safi = SAFI_UNICAST;
6677 else
6678 pfx_rcd_safi = safi;
6679
6680 if (use_json) {
6681 if (json == NULL)
6682 json = json_object_new_object();
6683
6684 json_peers = json_object_new_object();
6685 } else {
6686 /* Loop over all neighbors that will be displayed to determine
6687 * how many
6688 * characters are needed for the Neighbor column
6689 */
6690 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6691 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6692 continue;
6693
6694 if (peer->afc[afi][safi]) {
6695 memset(dn_flag, '\0', sizeof(dn_flag));
6696 if (peer_dynamic_neighbor(peer))
6697 dn_flag[0] = '*';
6698
6699 if (peer->hostname
6700 && bgp_flag_check(bgp,
6701 BGP_FLAG_SHOW_HOSTNAME))
6702 sprintf(neighbor_buf, "%s%s(%s) ",
6703 dn_flag, peer->hostname,
6704 peer->host);
6705 else
6706 sprintf(neighbor_buf, "%s%s ", dn_flag,
6707 peer->host);
6708
6709 len = strlen(neighbor_buf);
6710
6711 if (len > max_neighbor_width)
6712 max_neighbor_width = len;
6713 }
6714 }
f933309e 6715
d62a17ae 6716 /* Originally we displayed the Neighbor column as 16
6717 * characters wide so make that the default
6718 */
6719 if (max_neighbor_width < neighbor_col_default_width)
6720 max_neighbor_width = neighbor_col_default_width;
6721 }
f933309e 6722
d62a17ae 6723 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6724 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6725 continue;
6726
ea47320b
DL
6727 if (!peer->afc[afi][safi])
6728 continue;
d62a17ae 6729
ea47320b
DL
6730 if (!count) {
6731 unsigned long ents;
6732 char memstrbuf[MTYPE_MEMSTR_LEN];
6733 int vrf_id_ui;
d62a17ae 6734
60466a63
QY
6735 vrf_id_ui =
6736 (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
ea47320b
DL
6737
6738 /* Usage summary and header */
6739 if (use_json) {
6740 json_object_string_add(
6741 json, "routerId",
6742 inet_ntoa(bgp->router_id));
60466a63
QY
6743 json_object_int_add(json, "as", bgp->as);
6744 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
6745 json_object_string_add(
6746 json, "vrfName",
6747 (bgp->inst_type
6748 == BGP_INSTANCE_TYPE_DEFAULT)
6749 ? "Default"
6750 : bgp->name);
6751 } else {
6752 vty_out(vty,
6753 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63
QY
6754 inet_ntoa(bgp->router_id), bgp->as,
6755 vrf_id_ui);
ea47320b
DL
6756 vty_out(vty, "\n");
6757 }
d62a17ae 6758
ea47320b 6759 if (bgp_update_delay_configured(bgp)) {
d62a17ae 6760 if (use_json) {
ea47320b 6761 json_object_int_add(
60466a63 6762 json, "updateDelayLimit",
ea47320b 6763 bgp->v_update_delay);
d62a17ae 6764
ea47320b
DL
6765 if (bgp->v_update_delay
6766 != bgp->v_establish_wait)
d62a17ae 6767 json_object_int_add(
6768 json,
ea47320b
DL
6769 "updateDelayEstablishWait",
6770 bgp->v_establish_wait);
d62a17ae 6771
60466a63 6772 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6773 json_object_string_add(
6774 json,
6775 "updateDelayFirstNeighbor",
6776 bgp->update_delay_begin_time);
6777 json_object_boolean_true_add(
6778 json,
6779 "updateDelayInProgress");
6780 } else {
6781 if (bgp->update_delay_over) {
d62a17ae 6782 json_object_string_add(
6783 json,
6784 "updateDelayFirstNeighbor",
6785 bgp->update_delay_begin_time);
ea47320b 6786 json_object_string_add(
d62a17ae 6787 json,
ea47320b
DL
6788 "updateDelayBestpathResumed",
6789 bgp->update_delay_end_time);
6790 json_object_string_add(
d62a17ae 6791 json,
ea47320b
DL
6792 "updateDelayZebraUpdateResume",
6793 bgp->update_delay_zebra_resume_time);
6794 json_object_string_add(
6795 json,
6796 "updateDelayPeerUpdateResume",
6797 bgp->update_delay_peers_resume_time);
d62a17ae 6798 }
ea47320b
DL
6799 }
6800 } else {
6801 vty_out(vty,
6802 "Read-only mode update-delay limit: %d seconds\n",
6803 bgp->v_update_delay);
6804 if (bgp->v_update_delay
6805 != bgp->v_establish_wait)
d62a17ae 6806 vty_out(vty,
ea47320b
DL
6807 " Establish wait: %d seconds\n",
6808 bgp->v_establish_wait);
d62a17ae 6809
60466a63 6810 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6811 vty_out(vty,
6812 " First neighbor established: %s\n",
6813 bgp->update_delay_begin_time);
6814 vty_out(vty,
6815 " Delay in progress\n");
6816 } else {
6817 if (bgp->update_delay_over) {
d62a17ae 6818 vty_out(vty,
6819 " First neighbor established: %s\n",
6820 bgp->update_delay_begin_time);
6821 vty_out(vty,
ea47320b
DL
6822 " Best-paths resumed: %s\n",
6823 bgp->update_delay_end_time);
6824 vty_out(vty,
6825 " zebra update resumed: %s\n",
6826 bgp->update_delay_zebra_resume_time);
6827 vty_out(vty,
6828 " peers update resumed: %s\n",
6829 bgp->update_delay_peers_resume_time);
d62a17ae 6830 }
6831 }
6832 }
ea47320b 6833 }
d62a17ae 6834
ea47320b
DL
6835 if (use_json) {
6836 if (bgp_maxmed_onstartup_configured(bgp)
6837 && bgp->maxmed_active)
6838 json_object_boolean_true_add(
60466a63 6839 json, "maxMedOnStartup");
ea47320b
DL
6840 if (bgp->v_maxmed_admin)
6841 json_object_boolean_true_add(
60466a63 6842 json, "maxMedAdministrative");
d62a17ae 6843
ea47320b
DL
6844 json_object_int_add(
6845 json, "tableVersion",
60466a63 6846 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 6847
60466a63
QY
6848 ents = bgp_table_count(bgp->rib[afi][safi]);
6849 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
6850 json_object_int_add(
6851 json, "ribMemory",
6852 ents * sizeof(struct bgp_node));
d62a17ae 6853
ea47320b 6854 ents = listcount(bgp->peer);
60466a63
QY
6855 json_object_int_add(json, "peerCount", ents);
6856 json_object_int_add(json, "peerMemory",
6857 ents * sizeof(struct peer));
d62a17ae 6858
ea47320b
DL
6859 if ((ents = listcount(bgp->group))) {
6860 json_object_int_add(
60466a63 6861 json, "peerGroupCount", ents);
ea47320b
DL
6862 json_object_int_add(
6863 json, "peerGroupMemory",
6864 ents * sizeof(struct
6865 peer_group));
6866 }
d62a17ae 6867
ea47320b
DL
6868 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6869 BGP_CONFIG_DAMPENING))
6870 json_object_boolean_true_add(
60466a63 6871 json, "dampeningEnabled");
ea47320b
DL
6872 } else {
6873 if (bgp_maxmed_onstartup_configured(bgp)
6874 && bgp->maxmed_active)
d62a17ae 6875 vty_out(vty,
ea47320b
DL
6876 "Max-med on-startup active\n");
6877 if (bgp->v_maxmed_admin)
d62a17ae 6878 vty_out(vty,
ea47320b 6879 "Max-med administrative active\n");
d62a17ae 6880
60466a63
QY
6881 vty_out(vty, "BGP table version %" PRIu64 "\n",
6882 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 6883
60466a63 6884 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
6885 vty_out(vty,
6886 "RIB entries %ld, using %s of memory\n",
6887 ents,
60466a63
QY
6888 mtype_memstr(memstrbuf,
6889 sizeof(memstrbuf),
6890 ents * sizeof(struct
6891 bgp_node)));
ea47320b
DL
6892
6893 /* Peer related usage */
6894 ents = listcount(bgp->peer);
60466a63 6895 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
6896 ents,
6897 mtype_memstr(
60466a63
QY
6898 memstrbuf, sizeof(memstrbuf),
6899 ents * sizeof(struct peer)));
ea47320b
DL
6900
6901 if ((ents = listcount(bgp->group)))
d62a17ae 6902 vty_out(vty,
ea47320b 6903 "Peer groups %ld, using %s of memory\n",
d62a17ae 6904 ents,
6905 mtype_memstr(
6906 memstrbuf,
6907 sizeof(memstrbuf),
9d303b37 6908 ents * sizeof(struct
ea47320b 6909 peer_group)));
d62a17ae 6910
ea47320b
DL
6911 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6912 BGP_CONFIG_DAMPENING))
60466a63 6913 vty_out(vty, "Dampening enabled.\n");
ea47320b 6914 vty_out(vty, "\n");
d62a17ae 6915
ea47320b
DL
6916 /* Subtract 8 here because 'Neighbor' is
6917 * 8 characters */
6918 vty_out(vty, "Neighbor");
60466a63
QY
6919 vty_out(vty, "%*s", max_neighbor_width - 8,
6920 " ");
ea47320b
DL
6921 vty_out(vty,
6922 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 6923 }
ea47320b 6924 }
d62a17ae 6925
ea47320b 6926 count++;
d62a17ae 6927
ea47320b
DL
6928 if (use_json) {
6929 json_peer = json_object_new_object();
d62a17ae 6930
ea47320b 6931 if (peer_dynamic_neighbor(peer))
60466a63
QY
6932 json_object_boolean_true_add(json_peer,
6933 "dynamicPeer");
d62a17ae 6934
ea47320b 6935 if (peer->hostname)
60466a63 6936 json_object_string_add(json_peer, "hostname",
ea47320b 6937 peer->hostname);
d62a17ae 6938
ea47320b 6939 if (peer->domainname)
60466a63
QY
6940 json_object_string_add(json_peer, "domainname",
6941 peer->domainname);
d62a17ae 6942
60466a63 6943 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 6944 json_object_int_add(json_peer, "version", 4);
60466a63
QY
6945 json_object_int_add(json_peer, "msgRcvd",
6946 peer->open_in + peer->update_in
6947 + peer->keepalive_in
6948 + peer->notify_in
6949 + peer->refresh_in
6950 + peer->dynamic_cap_in);
6951 json_object_int_add(json_peer, "msgSent",
6952 peer->open_out + peer->update_out
6953 + peer->keepalive_out
6954 + peer->notify_out
6955 + peer->refresh_out
6956 + peer->dynamic_cap_out);
ea47320b
DL
6957
6958 json_object_int_add(json_peer, "tableVersion",
6959 peer->version[afi][safi]);
6960 json_object_int_add(json_peer, "outq",
6961 peer->obuf->count);
6962 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
6963 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
6964 use_json, json_peer);
6965 json_object_int_add(json_peer, "prefixReceivedCount",
6966 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 6967
ea47320b 6968 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 6969 json_object_string_add(json_peer, "state",
ea47320b 6970 "Idle (Admin)");
60466a63
QY
6971 else if (CHECK_FLAG(peer->sflags,
6972 PEER_STATUS_PREFIX_OVERFLOW))
6973 json_object_string_add(json_peer, "state",
ea47320b
DL
6974 "Idle (PfxCt)");
6975 else
6976 json_object_string_add(
6977 json_peer, "state",
60466a63
QY
6978 lookup_msg(bgp_status_msg, peer->status,
6979 NULL));
ea47320b
DL
6980
6981 if (peer->conf_if)
60466a63 6982 json_object_string_add(json_peer, "idType",
ea47320b
DL
6983 "interface");
6984 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
6985 json_object_string_add(json_peer, "idType",
6986 "ipv4");
ea47320b 6987 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
6988 json_object_string_add(json_peer, "idType",
6989 "ipv6");
d62a17ae 6990
ea47320b
DL
6991 json_object_object_add(json_peers, peer->host,
6992 json_peer);
6993 } else {
6994 memset(dn_flag, '\0', sizeof(dn_flag));
6995 if (peer_dynamic_neighbor(peer)) {
6996 dn_count++;
6997 dn_flag[0] = '*';
6998 }
d62a17ae 6999
ea47320b 7000 if (peer->hostname
60466a63 7001 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7002 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7003 peer->hostname, peer->host);
ea47320b 7004 else
60466a63 7005 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7006
7007 /* pad the neighbor column with spaces */
7008 if (len < max_neighbor_width)
60466a63
QY
7009 vty_out(vty, "%*s", max_neighbor_width - len,
7010 " ");
ea47320b 7011
60466a63 7012 vty_out(vty, "4 %10u %7d %7d %8" PRIu64 " %4d %4zd %8s",
ea47320b
DL
7013 peer->as,
7014 peer->open_in + peer->update_in
60466a63 7015 + peer->keepalive_in + peer->notify_in
ea47320b
DL
7016 + peer->refresh_in
7017 + peer->dynamic_cap_in,
7018 peer->open_out + peer->update_out
60466a63 7019 + peer->keepalive_out + peer->notify_out
ea47320b
DL
7020 + peer->refresh_out
7021 + peer->dynamic_cap_out,
60466a63 7022 peer->version[afi][safi], 0, peer->obuf->count,
d62a17ae 7023 peer_uptime(peer->uptime, timebuf,
ea47320b 7024 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7025
ea47320b
DL
7026 if (peer->status == Established)
7027 vty_out(vty, " %12ld",
60466a63 7028 peer->pcount[afi][pfx_rcd_safi]);
ea47320b 7029 else {
60466a63 7030 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7031 vty_out(vty, " Idle (Admin)");
60466a63
QY
7032 else if (CHECK_FLAG(
7033 peer->sflags,
7034 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7035 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7036 else
ea47320b 7037 vty_out(vty, " %12s",
60466a63
QY
7038 lookup_msg(bgp_status_msg,
7039 peer->status, NULL));
d62a17ae 7040 }
ea47320b 7041 vty_out(vty, "\n");
d62a17ae 7042 }
7043 }
f933309e 7044
d62a17ae 7045 if (use_json) {
7046 json_object_object_add(json, "peers", json_peers);
7047
7048 json_object_int_add(json, "totalPeers", count);
7049 json_object_int_add(json, "dynamicPeers", dn_count);
7050
9d303b37
DL
7051 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7052 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7053 json_object_free(json);
7054 } else {
7055 if (count)
7056 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7057 else {
7058 if (use_json)
7059 vty_out(vty,
7060 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7061 afi_safi_print(afi, safi));
7062 else
7063 vty_out(vty, "No %s neighbor is configured\n",
7064 afi_safi_print(afi, safi));
7065 }
b05a1c8b 7066
d62a17ae 7067 if (dn_count && !use_json) {
7068 vty_out(vty, "* - dynamic neighbor\n");
7069 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7070 dn_count, bgp->dynamic_neighbors_limit);
7071 }
7072 }
1ff9a340 7073
d62a17ae 7074 return CMD_SUCCESS;
718e3744 7075}
7076
d62a17ae 7077static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7078 int safi, u_char use_json,
7079 json_object *json)
7080{
7081 int is_first = 1;
7082 int afi_wildcard = (afi == AFI_MAX);
7083 int safi_wildcard = (safi == SAFI_MAX);
7084 int is_wildcard = (afi_wildcard || safi_wildcard);
7085 bool json_output = false;
7086
7087 if (use_json && is_wildcard)
7088 vty_out(vty, "{\n");
7089 if (afi_wildcard)
7090 afi = 1; /* AFI_IP */
7091 while (afi < AFI_MAX) {
7092 if (safi_wildcard)
7093 safi = 1; /* SAFI_UNICAST */
7094 while (safi < SAFI_MAX) {
318cac96 7095 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7096 json_output = true;
7097 if (is_wildcard) {
7098 /*
7099 * So limit output to those afi/safi
7100 * pairs that
7101 * actualy have something interesting in
7102 * them
7103 */
7104 if (use_json) {
7105 json = json_object_new_object();
7106
7107 if (!is_first)
7108 vty_out(vty, ",\n");
7109 else
7110 is_first = 0;
7111
7112 vty_out(vty, "\"%s\":",
7113 afi_safi_json(afi,
7114 safi));
7115 } else {
7116 vty_out(vty, "\n%s Summary:\n",
7117 afi_safi_print(afi,
7118 safi));
7119 }
7120 }
7121 bgp_show_summary(vty, bgp, afi, safi, use_json,
7122 json);
7123 }
7124 safi++;
d62a17ae 7125 if (!safi_wildcard)
7126 safi = SAFI_MAX;
7127 }
7128 afi++;
7129 if (!afi_wildcard
7130 || afi == AFI_L2VPN) /* special case, not handled yet */
7131 afi = AFI_MAX;
7132 }
7133
7134 if (use_json && is_wildcard)
7135 vty_out(vty, "}\n");
7136 else if (use_json && !json_output)
7137 vty_out(vty, "{}\n");
7138}
7139
7140static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7141 safi_t safi, u_char use_json)
7142{
7143 struct listnode *node, *nnode;
7144 struct bgp *bgp;
7145 json_object *json = NULL;
7146 int is_first = 1;
7147
7148 if (use_json)
7149 vty_out(vty, "{\n");
7150
7151 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7152 if (use_json) {
7153 json = json_object_new_object();
7154
7155 if (!is_first)
7156 vty_out(vty, ",\n");
7157 else
7158 is_first = 0;
7159
7160 vty_out(vty, "\"%s\":",
7161 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7162 ? "Default"
7163 : bgp->name);
7164 } else {
7165 vty_out(vty, "\nInstance %s:\n",
7166 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7167 ? "Default"
7168 : bgp->name);
7169 }
7170 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7171 }
7172
7173 if (use_json)
7174 vty_out(vty, "}\n");
7175}
7176
7177int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7178 safi_t safi, u_char use_json)
7179{
7180 struct bgp *bgp;
7181
7182 if (name) {
7183 if (strmatch(name, "all")) {
7184 bgp_show_all_instances_summary_vty(vty, afi, safi,
7185 use_json);
7186 return CMD_SUCCESS;
7187 } else {
7188 bgp = bgp_lookup_by_name(name);
7189
7190 if (!bgp) {
7191 if (use_json)
7192 vty_out(vty, "{}\n");
7193 else
7194 vty_out(vty,
7195 "%% No such BGP instance exist\n");
7196 return CMD_WARNING;
7197 }
7198
7199 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7200 NULL);
7201 return CMD_SUCCESS;
7202 }
7203 }
7204
7205 bgp = bgp_get_default();
7206
7207 if (bgp)
7208 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7209
7210 return CMD_SUCCESS;
4fb25c53
DW
7211}
7212
716b2d8a 7213/* `show [ip] bgp summary' commands. */
47fc97cc 7214DEFUN (show_ip_bgp_summary,
718e3744 7215 show_ip_bgp_summary_cmd,
dd6bd0f1 7216 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7217 SHOW_STR
7218 IP_STR
7219 BGP_STR
8386ac43 7220 BGP_INSTANCE_HELP_STR
46f296b4 7221 BGP_AFI_HELP_STR
dd6bd0f1 7222 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7223 "Summary of BGP neighbor status\n"
9973d184 7224 JSON_STR)
718e3744 7225{
d62a17ae 7226 char *vrf = NULL;
7227 afi_t afi = AFI_MAX;
7228 safi_t safi = SAFI_MAX;
7229
7230 int idx = 0;
7231
7232 /* show [ip] bgp */
7233 if (argv_find(argv, argc, "ip", &idx))
7234 afi = AFI_IP;
7235 /* [<view|vrf> VIEWVRFNAME] */
7236 if (argv_find(argv, argc, "view", &idx)
7237 || argv_find(argv, argc, "vrf", &idx))
7238 vrf = argv[++idx]->arg;
7239 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7240 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7241 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7242 }
7243
7244 int uj = use_json(argc, argv);
7245
7246 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7247}
7248
7249const char *afi_safi_print(afi_t afi, safi_t safi)
7250{
7251 if (afi == AFI_IP && safi == SAFI_UNICAST)
7252 return "IPv4 Unicast";
7253 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7254 return "IPv4 Multicast";
7255 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7256 return "IPv4 Labeled Unicast";
7257 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7258 return "IPv4 VPN";
7259 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7260 return "IPv4 Encap";
7261 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7262 return "IPv6 Unicast";
7263 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7264 return "IPv6 Multicast";
7265 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7266 return "IPv6 Labeled Unicast";
7267 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7268 return "IPv6 VPN";
7269 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7270 return "IPv6 Encap";
7271 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7272 return "L2VPN EVPN";
7273 else
7274 return "Unknown";
538621f2 7275}
7276
b9f77ec8
DS
7277/*
7278 * Please note that we have intentionally camelCased
7279 * the return strings here. So if you want
7280 * to use this function, please ensure you
7281 * are doing this within json output
7282 */
d62a17ae 7283const char *afi_safi_json(afi_t afi, safi_t safi)
7284{
7285 if (afi == AFI_IP && safi == SAFI_UNICAST)
7286 return "ipv4Unicast";
7287 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7288 return "ipv4Multicast";
7289 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7290 return "ipv4LabeledUnicast";
7291 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7292 return "ipv4Vpn";
7293 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7294 return "ipv4Encap";
7295 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7296 return "ipv6Unicast";
7297 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7298 return "ipv6Multicast";
7299 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7300 return "ipv6LabeledUnicast";
7301 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7302 return "ipv6Vpn";
7303 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7304 return "ipv6Encap";
7305 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7306 return "l2VpnEvpn";
7307 else
7308 return "Unknown";
27162734
LB
7309}
7310
718e3744 7311/* Show BGP peer's information. */
d62a17ae 7312enum show_type { show_all, show_peer };
7313
7314static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7315 afi_t afi, safi_t safi,
7316 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7317 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7318 u_char use_json, json_object *json_pref)
7319{
7320 /* Send-Mode */
7321 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7322 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7323 if (use_json) {
7324 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7325 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7326 json_object_string_add(json_pref, "sendMode",
7327 "advertisedAndReceived");
7328 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7329 json_object_string_add(json_pref, "sendMode",
7330 "advertised");
7331 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7332 json_object_string_add(json_pref, "sendMode",
7333 "received");
7334 } else {
7335 vty_out(vty, " Send-mode: ");
7336 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7337 vty_out(vty, "advertised");
7338 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7339 vty_out(vty, "%sreceived",
7340 CHECK_FLAG(p->af_cap[afi][safi],
7341 adv_smcap)
7342 ? ", "
7343 : "");
7344 vty_out(vty, "\n");
7345 }
7346 }
7347
7348 /* Receive-Mode */
7349 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7350 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7351 if (use_json) {
7352 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7353 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7354 json_object_string_add(json_pref, "recvMode",
7355 "advertisedAndReceived");
7356 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7357 json_object_string_add(json_pref, "recvMode",
7358 "advertised");
7359 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7360 json_object_string_add(json_pref, "recvMode",
7361 "received");
7362 } else {
7363 vty_out(vty, " Receive-mode: ");
7364 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7365 vty_out(vty, "advertised");
7366 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7367 vty_out(vty, "%sreceived",
7368 CHECK_FLAG(p->af_cap[afi][safi],
7369 adv_rmcap)
7370 ? ", "
7371 : "");
7372 vty_out(vty, "\n");
7373 }
7374 }
7375}
7376
7377static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7378 safi_t safi, u_char use_json,
7379 json_object *json_neigh)
7380{
0291c246
MK
7381 struct bgp_filter *filter;
7382 struct peer_af *paf;
7383 char orf_pfx_name[BUFSIZ];
7384 int orf_pfx_count;
7385 json_object *json_af = NULL;
7386 json_object *json_prefA = NULL;
7387 json_object *json_prefB = NULL;
7388 json_object *json_addr = NULL;
d62a17ae 7389
7390 if (use_json) {
7391 json_addr = json_object_new_object();
7392 json_af = json_object_new_object();
7393 filter = &p->filter[afi][safi];
7394
7395 if (peer_group_active(p))
7396 json_object_string_add(json_addr, "peerGroupMember",
7397 p->group->name);
7398
7399 paf = peer_af_find(p, afi, safi);
7400 if (paf && PAF_SUBGRP(paf)) {
7401 json_object_int_add(json_addr, "updateGroupId",
7402 PAF_UPDGRP(paf)->id);
7403 json_object_int_add(json_addr, "subGroupId",
7404 PAF_SUBGRP(paf)->id);
7405 json_object_int_add(json_addr, "packetQueueLength",
7406 bpacket_queue_virtual_length(paf));
7407 }
7408
7409 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7410 || CHECK_FLAG(p->af_cap[afi][safi],
7411 PEER_CAP_ORF_PREFIX_SM_RCV)
7412 || CHECK_FLAG(p->af_cap[afi][safi],
7413 PEER_CAP_ORF_PREFIX_RM_ADV)
7414 || CHECK_FLAG(p->af_cap[afi][safi],
7415 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7416 json_object_int_add(json_af, "orfType",
7417 ORF_TYPE_PREFIX);
7418 json_prefA = json_object_new_object();
7419 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7420 PEER_CAP_ORF_PREFIX_SM_ADV,
7421 PEER_CAP_ORF_PREFIX_RM_ADV,
7422 PEER_CAP_ORF_PREFIX_SM_RCV,
7423 PEER_CAP_ORF_PREFIX_RM_RCV,
7424 use_json, json_prefA);
7425 json_object_object_add(json_af, "orfPrefixList",
7426 json_prefA);
7427 }
7428
7429 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7430 || CHECK_FLAG(p->af_cap[afi][safi],
7431 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7432 || CHECK_FLAG(p->af_cap[afi][safi],
7433 PEER_CAP_ORF_PREFIX_RM_ADV)
7434 || CHECK_FLAG(p->af_cap[afi][safi],
7435 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7436 json_object_int_add(json_af, "orfOldType",
7437 ORF_TYPE_PREFIX_OLD);
7438 json_prefB = json_object_new_object();
7439 bgp_show_peer_afi_orf_cap(
7440 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7441 PEER_CAP_ORF_PREFIX_RM_ADV,
7442 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7443 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7444 json_prefB);
7445 json_object_object_add(json_af, "orfOldPrefixList",
7446 json_prefB);
7447 }
7448
7449 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7450 || CHECK_FLAG(p->af_cap[afi][safi],
7451 PEER_CAP_ORF_PREFIX_SM_RCV)
7452 || CHECK_FLAG(p->af_cap[afi][safi],
7453 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7454 || CHECK_FLAG(p->af_cap[afi][safi],
7455 PEER_CAP_ORF_PREFIX_RM_ADV)
7456 || CHECK_FLAG(p->af_cap[afi][safi],
7457 PEER_CAP_ORF_PREFIX_RM_RCV)
7458 || CHECK_FLAG(p->af_cap[afi][safi],
7459 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7460 json_object_object_add(json_addr, "afDependentCap",
7461 json_af);
7462 else
7463 json_object_free(json_af);
7464
7465 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7466 orf_pfx_count = prefix_bgp_show_prefix_list(
7467 NULL, afi, orf_pfx_name, use_json);
7468
7469 if (CHECK_FLAG(p->af_sflags[afi][safi],
7470 PEER_STATUS_ORF_PREFIX_SEND)
7471 || orf_pfx_count) {
7472 if (CHECK_FLAG(p->af_sflags[afi][safi],
7473 PEER_STATUS_ORF_PREFIX_SEND))
7474 json_object_boolean_true_add(json_neigh,
7475 "orfSent");
7476 if (orf_pfx_count)
7477 json_object_int_add(json_addr, "orfRecvCounter",
7478 orf_pfx_count);
7479 }
7480 if (CHECK_FLAG(p->af_sflags[afi][safi],
7481 PEER_STATUS_ORF_WAIT_REFRESH))
7482 json_object_string_add(
7483 json_addr, "orfFirstUpdate",
7484 "deferredUntilORFOrRouteRefreshRecvd");
7485
7486 if (CHECK_FLAG(p->af_flags[afi][safi],
7487 PEER_FLAG_REFLECTOR_CLIENT))
7488 json_object_boolean_true_add(json_addr,
7489 "routeReflectorClient");
7490 if (CHECK_FLAG(p->af_flags[afi][safi],
7491 PEER_FLAG_RSERVER_CLIENT))
7492 json_object_boolean_true_add(json_addr,
7493 "routeServerClient");
7494 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7495 json_object_boolean_true_add(json_addr,
7496 "inboundSoftConfigPermit");
7497
7498 if (CHECK_FLAG(p->af_flags[afi][safi],
7499 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7500 json_object_boolean_true_add(
7501 json_addr,
7502 "privateAsNumsAllReplacedInUpdatesToNbr");
7503 else if (CHECK_FLAG(p->af_flags[afi][safi],
7504 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7505 json_object_boolean_true_add(
7506 json_addr,
7507 "privateAsNumsReplacedInUpdatesToNbr");
7508 else if (CHECK_FLAG(p->af_flags[afi][safi],
7509 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7510 json_object_boolean_true_add(
7511 json_addr,
7512 "privateAsNumsAllRemovedInUpdatesToNbr");
7513 else if (CHECK_FLAG(p->af_flags[afi][safi],
7514 PEER_FLAG_REMOVE_PRIVATE_AS))
7515 json_object_boolean_true_add(
7516 json_addr,
7517 "privateAsNumsRemovedInUpdatesToNbr");
7518
7519 if (CHECK_FLAG(p->af_flags[afi][safi],
7520 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7521 json_object_boolean_true_add(json_addr,
7522 "addpathTxAllPaths");
7523
7524 if (CHECK_FLAG(p->af_flags[afi][safi],
7525 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7526 json_object_boolean_true_add(json_addr,
7527 "addpathTxBestpathPerAS");
7528
7529 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7530 json_object_string_add(json_addr,
7531 "overrideASNsInOutboundUpdates",
7532 "ifAspathEqualRemoteAs");
7533
7534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7535 || CHECK_FLAG(p->af_flags[afi][safi],
7536 PEER_FLAG_FORCE_NEXTHOP_SELF))
7537 json_object_boolean_true_add(json_addr,
7538 "routerAlwaysNextHop");
7539 if (CHECK_FLAG(p->af_flags[afi][safi],
7540 PEER_FLAG_AS_PATH_UNCHANGED))
7541 json_object_boolean_true_add(
7542 json_addr, "unchangedAsPathPropogatedToNbr");
7543 if (CHECK_FLAG(p->af_flags[afi][safi],
7544 PEER_FLAG_NEXTHOP_UNCHANGED))
7545 json_object_boolean_true_add(
7546 json_addr, "unchangedNextHopPropogatedToNbr");
7547 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7548 json_object_boolean_true_add(
7549 json_addr, "unchangedMedPropogatedToNbr");
7550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7551 || CHECK_FLAG(p->af_flags[afi][safi],
7552 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7553 if (CHECK_FLAG(p->af_flags[afi][safi],
7554 PEER_FLAG_SEND_COMMUNITY)
7555 && CHECK_FLAG(p->af_flags[afi][safi],
7556 PEER_FLAG_SEND_EXT_COMMUNITY))
7557 json_object_string_add(json_addr,
7558 "commAttriSentToNbr",
7559 "extendedAndStandard");
7560 else if (CHECK_FLAG(p->af_flags[afi][safi],
7561 PEER_FLAG_SEND_EXT_COMMUNITY))
7562 json_object_string_add(json_addr,
7563 "commAttriSentToNbr",
7564 "extended");
7565 else
7566 json_object_string_add(json_addr,
7567 "commAttriSentToNbr",
7568 "standard");
7569 }
7570 if (CHECK_FLAG(p->af_flags[afi][safi],
7571 PEER_FLAG_DEFAULT_ORIGINATE)) {
7572 if (p->default_rmap[afi][safi].name)
7573 json_object_string_add(
7574 json_addr, "defaultRouteMap",
7575 p->default_rmap[afi][safi].name);
7576
7577 if (paf && PAF_SUBGRP(paf)
7578 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7579 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7580 json_object_boolean_true_add(json_addr,
7581 "defaultSent");
7582 else
7583 json_object_boolean_true_add(json_addr,
7584 "defaultNotSent");
7585 }
7586
dff8f48d
MK
7587 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7588 if (p->bgp->advertise_all_vni)
60466a63
QY
7589 json_object_boolean_true_add(
7590 json_addr, "advertiseAllVnis");
dff8f48d
MK
7591 }
7592
d62a17ae 7593 if (filter->plist[FILTER_IN].name
7594 || filter->dlist[FILTER_IN].name
7595 || filter->aslist[FILTER_IN].name
7596 || filter->map[RMAP_IN].name)
7597 json_object_boolean_true_add(json_addr,
7598 "inboundPathPolicyConfig");
7599 if (filter->plist[FILTER_OUT].name
7600 || filter->dlist[FILTER_OUT].name
7601 || filter->aslist[FILTER_OUT].name
7602 || filter->map[RMAP_OUT].name || filter->usmap.name)
7603 json_object_boolean_true_add(
7604 json_addr, "outboundPathPolicyConfig");
7605
7606 /* prefix-list */
7607 if (filter->plist[FILTER_IN].name)
7608 json_object_string_add(json_addr,
7609 "incomingUpdatePrefixFilterList",
7610 filter->plist[FILTER_IN].name);
7611 if (filter->plist[FILTER_OUT].name)
7612 json_object_string_add(json_addr,
7613 "outgoingUpdatePrefixFilterList",
7614 filter->plist[FILTER_OUT].name);
7615
7616 /* distribute-list */
7617 if (filter->dlist[FILTER_IN].name)
7618 json_object_string_add(
7619 json_addr, "incomingUpdateNetworkFilterList",
7620 filter->dlist[FILTER_IN].name);
7621 if (filter->dlist[FILTER_OUT].name)
7622 json_object_string_add(
7623 json_addr, "outgoingUpdateNetworkFilterList",
7624 filter->dlist[FILTER_OUT].name);
7625
7626 /* filter-list. */
7627 if (filter->aslist[FILTER_IN].name)
7628 json_object_string_add(json_addr,
7629 "incomingUpdateAsPathFilterList",
7630 filter->aslist[FILTER_IN].name);
7631 if (filter->aslist[FILTER_OUT].name)
7632 json_object_string_add(json_addr,
7633 "outgoingUpdateAsPathFilterList",
7634 filter->aslist[FILTER_OUT].name);
7635
7636 /* route-map. */
7637 if (filter->map[RMAP_IN].name)
7638 json_object_string_add(
7639 json_addr, "routeMapForIncomingAdvertisements",
7640 filter->map[RMAP_IN].name);
7641 if (filter->map[RMAP_OUT].name)
7642 json_object_string_add(
7643 json_addr, "routeMapForOutgoingAdvertisements",
7644 filter->map[RMAP_OUT].name);
7645
7646 /* unsuppress-map */
7647 if (filter->usmap.name)
7648 json_object_string_add(json_addr,
7649 "selectiveUnsuppressRouteMap",
7650 filter->usmap.name);
7651
7652 /* Receive prefix count */
7653 json_object_int_add(json_addr, "acceptedPrefixCounter",
7654 p->pcount[afi][safi]);
7655
7656 /* Maximum prefix */
7657 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7658 json_object_int_add(json_addr, "prefixAllowedMax",
7659 p->pmax[afi][safi]);
7660 if (CHECK_FLAG(p->af_flags[afi][safi],
7661 PEER_FLAG_MAX_PREFIX_WARNING))
7662 json_object_boolean_true_add(
7663 json_addr, "prefixAllowedMaxWarning");
7664 json_object_int_add(json_addr,
7665 "prefixAllowedWarningThresh",
7666 p->pmax_threshold[afi][safi]);
7667 if (p->pmax_restart[afi][safi])
7668 json_object_int_add(
7669 json_addr,
7670 "prefixAllowedRestartIntervalMsecs",
7671 p->pmax_restart[afi][safi] * 60000);
7672 }
7673 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7674 json_addr);
7675
7676 } else {
7677 filter = &p->filter[afi][safi];
7678
7679 vty_out(vty, " For address family: %s\n",
7680 afi_safi_print(afi, safi));
7681
7682 if (peer_group_active(p))
7683 vty_out(vty, " %s peer-group member\n",
7684 p->group->name);
7685
7686 paf = peer_af_find(p, afi, safi);
7687 if (paf && PAF_SUBGRP(paf)) {
9d303b37
DL
7688 vty_out(vty, " Update group %" PRIu64
7689 ", subgroup %" PRIu64 "\n",
d62a17ae 7690 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7691 vty_out(vty, " Packet Queue length %d\n",
7692 bpacket_queue_virtual_length(paf));
7693 } else {
7694 vty_out(vty, " Not part of any update group\n");
7695 }
7696 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7697 || CHECK_FLAG(p->af_cap[afi][safi],
7698 PEER_CAP_ORF_PREFIX_SM_RCV)
7699 || CHECK_FLAG(p->af_cap[afi][safi],
7700 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7701 || CHECK_FLAG(p->af_cap[afi][safi],
7702 PEER_CAP_ORF_PREFIX_RM_ADV)
7703 || CHECK_FLAG(p->af_cap[afi][safi],
7704 PEER_CAP_ORF_PREFIX_RM_RCV)
7705 || CHECK_FLAG(p->af_cap[afi][safi],
7706 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7707 vty_out(vty, " AF-dependant capabilities:\n");
7708
7709 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7710 || CHECK_FLAG(p->af_cap[afi][safi],
7711 PEER_CAP_ORF_PREFIX_SM_RCV)
7712 || CHECK_FLAG(p->af_cap[afi][safi],
7713 PEER_CAP_ORF_PREFIX_RM_ADV)
7714 || CHECK_FLAG(p->af_cap[afi][safi],
7715 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7716 vty_out(vty,
7717 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7718 ORF_TYPE_PREFIX);
7719 bgp_show_peer_afi_orf_cap(
7720 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7721 PEER_CAP_ORF_PREFIX_RM_ADV,
7722 PEER_CAP_ORF_PREFIX_SM_RCV,
7723 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7724 }
7725 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7726 || CHECK_FLAG(p->af_cap[afi][safi],
7727 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7728 || CHECK_FLAG(p->af_cap[afi][safi],
7729 PEER_CAP_ORF_PREFIX_RM_ADV)
7730 || CHECK_FLAG(p->af_cap[afi][safi],
7731 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7732 vty_out(vty,
7733 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7734 ORF_TYPE_PREFIX_OLD);
7735 bgp_show_peer_afi_orf_cap(
7736 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7737 PEER_CAP_ORF_PREFIX_RM_ADV,
7738 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7739 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7740 }
7741
7742 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7743 orf_pfx_count = prefix_bgp_show_prefix_list(
7744 NULL, afi, orf_pfx_name, use_json);
7745
7746 if (CHECK_FLAG(p->af_sflags[afi][safi],
7747 PEER_STATUS_ORF_PREFIX_SEND)
7748 || orf_pfx_count) {
7749 vty_out(vty, " Outbound Route Filter (ORF):");
7750 if (CHECK_FLAG(p->af_sflags[afi][safi],
7751 PEER_STATUS_ORF_PREFIX_SEND))
7752 vty_out(vty, " sent;");
7753 if (orf_pfx_count)
7754 vty_out(vty, " received (%d entries)",
7755 orf_pfx_count);
7756 vty_out(vty, "\n");
7757 }
7758 if (CHECK_FLAG(p->af_sflags[afi][safi],
7759 PEER_STATUS_ORF_WAIT_REFRESH))
7760 vty_out(vty,
7761 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7762
7763 if (CHECK_FLAG(p->af_flags[afi][safi],
7764 PEER_FLAG_REFLECTOR_CLIENT))
7765 vty_out(vty, " Route-Reflector Client\n");
7766 if (CHECK_FLAG(p->af_flags[afi][safi],
7767 PEER_FLAG_RSERVER_CLIENT))
7768 vty_out(vty, " Route-Server Client\n");
7769 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7770 vty_out(vty,
7771 " Inbound soft reconfiguration allowed\n");
7772
7773 if (CHECK_FLAG(p->af_flags[afi][safi],
7774 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7775 vty_out(vty,
7776 " Private AS numbers (all) replaced in updates to this neighbor\n");
7777 else if (CHECK_FLAG(p->af_flags[afi][safi],
7778 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7779 vty_out(vty,
7780 " Private AS numbers replaced in updates to this neighbor\n");
7781 else if (CHECK_FLAG(p->af_flags[afi][safi],
7782 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7783 vty_out(vty,
7784 " Private AS numbers (all) removed in updates to this neighbor\n");
7785 else if (CHECK_FLAG(p->af_flags[afi][safi],
7786 PEER_FLAG_REMOVE_PRIVATE_AS))
7787 vty_out(vty,
7788 " Private AS numbers removed in updates to this neighbor\n");
7789
7790 if (CHECK_FLAG(p->af_flags[afi][safi],
7791 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7792 vty_out(vty, " Advertise all paths via addpath\n");
7793
7794 if (CHECK_FLAG(p->af_flags[afi][safi],
7795 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7796 vty_out(vty,
7797 " Advertise bestpath per AS via addpath\n");
7798
7799 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7800 vty_out(vty,
7801 " Override ASNs in outbound updates if aspath equals remote-as\n");
7802
7803 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7804 || CHECK_FLAG(p->af_flags[afi][safi],
7805 PEER_FLAG_FORCE_NEXTHOP_SELF))
7806 vty_out(vty, " NEXT_HOP is always this router\n");
7807 if (CHECK_FLAG(p->af_flags[afi][safi],
7808 PEER_FLAG_AS_PATH_UNCHANGED))
7809 vty_out(vty,
7810 " AS_PATH is propagated unchanged to this neighbor\n");
7811 if (CHECK_FLAG(p->af_flags[afi][safi],
7812 PEER_FLAG_NEXTHOP_UNCHANGED))
7813 vty_out(vty,
7814 " NEXT_HOP is propagated unchanged to this neighbor\n");
7815 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7816 vty_out(vty,
7817 " MED is propagated unchanged to this neighbor\n");
7818 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7819 || CHECK_FLAG(p->af_flags[afi][safi],
7820 PEER_FLAG_SEND_EXT_COMMUNITY)
7821 || CHECK_FLAG(p->af_flags[afi][safi],
7822 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7823 vty_out(vty,
7824 " Community attribute sent to this neighbor");
7825 if (CHECK_FLAG(p->af_flags[afi][safi],
7826 PEER_FLAG_SEND_COMMUNITY)
7827 && CHECK_FLAG(p->af_flags[afi][safi],
7828 PEER_FLAG_SEND_EXT_COMMUNITY)
7829 && CHECK_FLAG(p->af_flags[afi][safi],
7830 PEER_FLAG_SEND_LARGE_COMMUNITY))
7831 vty_out(vty, "(all)\n");
7832 else if (CHECK_FLAG(p->af_flags[afi][safi],
7833 PEER_FLAG_SEND_LARGE_COMMUNITY))
7834 vty_out(vty, "(large)\n");
7835 else if (CHECK_FLAG(p->af_flags[afi][safi],
7836 PEER_FLAG_SEND_EXT_COMMUNITY))
7837 vty_out(vty, "(extended)\n");
7838 else
7839 vty_out(vty, "(standard)\n");
7840 }
7841 if (CHECK_FLAG(p->af_flags[afi][safi],
7842 PEER_FLAG_DEFAULT_ORIGINATE)) {
7843 vty_out(vty, " Default information originate,");
7844
7845 if (p->default_rmap[afi][safi].name)
7846 vty_out(vty, " default route-map %s%s,",
7847 p->default_rmap[afi][safi].map ? "*"
7848 : "",
7849 p->default_rmap[afi][safi].name);
7850 if (paf && PAF_SUBGRP(paf)
7851 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7852 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7853 vty_out(vty, " default sent\n");
7854 else
7855 vty_out(vty, " default not sent\n");
7856 }
7857
dff8f48d
MK
7858 /* advertise-vni-all */
7859 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7860 if (p->bgp->advertise_all_vni)
7861 vty_out(vty, " advertise-all-vni\n");
7862 }
7863
d62a17ae 7864 if (filter->plist[FILTER_IN].name
7865 || filter->dlist[FILTER_IN].name
7866 || filter->aslist[FILTER_IN].name
7867 || filter->map[RMAP_IN].name)
7868 vty_out(vty, " Inbound path policy configured\n");
7869 if (filter->plist[FILTER_OUT].name
7870 || filter->dlist[FILTER_OUT].name
7871 || filter->aslist[FILTER_OUT].name
7872 || filter->map[RMAP_OUT].name || filter->usmap.name)
7873 vty_out(vty, " Outbound path policy configured\n");
7874
7875 /* prefix-list */
7876 if (filter->plist[FILTER_IN].name)
7877 vty_out(vty,
7878 " Incoming update prefix filter list is %s%s\n",
7879 filter->plist[FILTER_IN].plist ? "*" : "",
7880 filter->plist[FILTER_IN].name);
7881 if (filter->plist[FILTER_OUT].name)
7882 vty_out(vty,
7883 " Outgoing update prefix filter list is %s%s\n",
7884 filter->plist[FILTER_OUT].plist ? "*" : "",
7885 filter->plist[FILTER_OUT].name);
7886
7887 /* distribute-list */
7888 if (filter->dlist[FILTER_IN].name)
7889 vty_out(vty,
7890 " Incoming update network filter list is %s%s\n",
7891 filter->dlist[FILTER_IN].alist ? "*" : "",
7892 filter->dlist[FILTER_IN].name);
7893 if (filter->dlist[FILTER_OUT].name)
7894 vty_out(vty,
7895 " Outgoing update network filter list is %s%s\n",
7896 filter->dlist[FILTER_OUT].alist ? "*" : "",
7897 filter->dlist[FILTER_OUT].name);
7898
7899 /* filter-list. */
7900 if (filter->aslist[FILTER_IN].name)
7901 vty_out(vty,
7902 " Incoming update AS path filter list is %s%s\n",
7903 filter->aslist[FILTER_IN].aslist ? "*" : "",
7904 filter->aslist[FILTER_IN].name);
7905 if (filter->aslist[FILTER_OUT].name)
7906 vty_out(vty,
7907 " Outgoing update AS path filter list is %s%s\n",
7908 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7909 filter->aslist[FILTER_OUT].name);
7910
7911 /* route-map. */
7912 if (filter->map[RMAP_IN].name)
7913 vty_out(vty,
7914 " Route map for incoming advertisements is %s%s\n",
7915 filter->map[RMAP_IN].map ? "*" : "",
7916 filter->map[RMAP_IN].name);
7917 if (filter->map[RMAP_OUT].name)
7918 vty_out(vty,
7919 " Route map for outgoing advertisements is %s%s\n",
7920 filter->map[RMAP_OUT].map ? "*" : "",
7921 filter->map[RMAP_OUT].name);
7922
7923 /* unsuppress-map */
7924 if (filter->usmap.name)
7925 vty_out(vty,
7926 " Route map for selective unsuppress is %s%s\n",
7927 filter->usmap.map ? "*" : "",
7928 filter->usmap.name);
7929
7930 /* Receive prefix count */
7931 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
7932
7933 /* Maximum prefix */
7934 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7935 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
7936 p->pmax[afi][safi],
7937 CHECK_FLAG(p->af_flags[afi][safi],
7938 PEER_FLAG_MAX_PREFIX_WARNING)
7939 ? " (warning-only)"
7940 : "");
7941 vty_out(vty, " Threshold for warning message %d%%",
7942 p->pmax_threshold[afi][safi]);
7943 if (p->pmax_restart[afi][safi])
7944 vty_out(vty, ", restart interval %d min",
7945 p->pmax_restart[afi][safi]);
7946 vty_out(vty, "\n");
7947 }
7948
7949 vty_out(vty, "\n");
7950 }
7951}
7952
7953static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
7954 json_object *json)
718e3744 7955{
d62a17ae 7956 struct bgp *bgp;
7957 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
7958 char timebuf[BGP_UPTIME_LEN];
7959 char dn_flag[2];
7960 const char *subcode_str;
7961 const char *code_str;
7962 afi_t afi;
7963 safi_t safi;
7964 u_int16_t i;
7965 u_char *msg;
7966 json_object *json_neigh = NULL;
7967 time_t epoch_tbuf;
718e3744 7968
d62a17ae 7969 bgp = p->bgp;
7970
7971 if (use_json)
7972 json_neigh = json_object_new_object();
7973
7974 memset(dn_flag, '\0', sizeof(dn_flag));
7975 if (!p->conf_if && peer_dynamic_neighbor(p))
7976 dn_flag[0] = '*';
7977
7978 if (!use_json) {
7979 if (p->conf_if) /* Configured interface name. */
7980 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
7981 BGP_PEER_SU_UNSPEC(p)
7982 ? "None"
7983 : sockunion2str(&p->su, buf,
7984 SU_ADDRSTRLEN));
7985 else /* Configured IP address. */
7986 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
7987 p->host);
7988 }
7989
7990 if (use_json) {
7991 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
7992 json_object_string_add(json_neigh, "bgpNeighborAddr",
7993 "none");
7994 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
7995 json_object_string_add(
7996 json_neigh, "bgpNeighborAddr",
7997 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
7998
7999 json_object_int_add(json_neigh, "remoteAs", p->as);
8000
8001 if (p->change_local_as)
8002 json_object_int_add(json_neigh, "localAs",
8003 p->change_local_as);
8004 else
8005 json_object_int_add(json_neigh, "localAs", p->local_as);
8006
8007 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8008 json_object_boolean_true_add(json_neigh,
8009 "localAsNoPrepend");
8010
8011 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8012 json_object_boolean_true_add(json_neigh,
8013 "localAsReplaceAs");
8014 } else {
8015 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8016 || (p->as_type == AS_INTERNAL))
8017 vty_out(vty, "remote AS %u, ", p->as);
8018 else
8019 vty_out(vty, "remote AS Unspecified, ");
8020 vty_out(vty, "local AS %u%s%s, ",
8021 p->change_local_as ? p->change_local_as : p->local_as,
8022 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8023 ? " no-prepend"
8024 : "",
8025 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8026 ? " replace-as"
8027 : "");
8028 }
8029 /* peer type internal, external, confed-internal or confed-external */
8030 if (p->as == p->local_as) {
8031 if (use_json) {
8032 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8033 json_object_boolean_true_add(
8034 json_neigh, "nbrConfedInternalLink");
8035 else
8036 json_object_boolean_true_add(json_neigh,
8037 "nbrInternalLink");
8038 } else {
8039 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8040 vty_out(vty, "confed-internal link\n");
8041 else
8042 vty_out(vty, "internal link\n");
8043 }
8044 } else {
8045 if (use_json) {
8046 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8047 json_object_boolean_true_add(
8048 json_neigh, "nbrConfedExternalLink");
8049 else
8050 json_object_boolean_true_add(json_neigh,
8051 "nbrExternalLink");
8052 } else {
8053 if (bgp_confederation_peers_check(bgp, p->as))
8054 vty_out(vty, "confed-external link\n");
8055 else
8056 vty_out(vty, "external link\n");
8057 }
8058 }
8059
8060 /* Description. */
8061 if (p->desc) {
8062 if (use_json)
8063 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8064 else
8065 vty_out(vty, " Description: %s\n", p->desc);
8066 }
8067
8068 if (p->hostname) {
8069 if (use_json) {
8070 if (p->hostname)
8071 json_object_string_add(json_neigh, "hostname",
8072 p->hostname);
8073
8074 if (p->domainname)
8075 json_object_string_add(json_neigh, "domainname",
8076 p->domainname);
8077 } else {
8078 if (p->domainname && (p->domainname[0] != '\0'))
8079 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8080 p->domainname);
8081 else
8082 vty_out(vty, "Hostname: %s\n", p->hostname);
8083 }
8084 }
8085
8086 /* Peer-group */
8087 if (p->group) {
8088 if (use_json) {
8089 json_object_string_add(json_neigh, "peerGroup",
8090 p->group->name);
8091
8092 if (dn_flag[0]) {
8093 struct prefix prefix, *range = NULL;
8094
8095 sockunion2hostprefix(&(p->su), &prefix);
8096 range = peer_group_lookup_dynamic_neighbor_range(
8097 p->group, &prefix);
8098
8099 if (range) {
8100 prefix2str(range, buf1, sizeof(buf1));
8101 json_object_string_add(
8102 json_neigh,
8103 "peerSubnetRangeGroup", buf1);
8104 }
8105 }
8106 } else {
8107 vty_out(vty,
8108 " Member of peer-group %s for session parameters\n",
8109 p->group->name);
8110
8111 if (dn_flag[0]) {
8112 struct prefix prefix, *range = NULL;
8113
8114 sockunion2hostprefix(&(p->su), &prefix);
8115 range = peer_group_lookup_dynamic_neighbor_range(
8116 p->group, &prefix);
8117
8118 if (range) {
8119 prefix2str(range, buf1, sizeof(buf1));
8120 vty_out(vty,
8121 " Belongs to the subnet range group: %s\n",
8122 buf1);
8123 }
8124 }
8125 }
8126 }
8127
8128 if (use_json) {
8129 /* Administrative shutdown. */
8130 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8131 json_object_boolean_true_add(json_neigh,
8132 "adminShutDown");
8133
8134 /* BGP Version. */
8135 json_object_int_add(json_neigh, "bgpVersion", 4);
8136 json_object_string_add(
8137 json_neigh, "remoteRouterId",
8138 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8139
8140 /* Confederation */
8141 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8142 && bgp_confederation_peers_check(bgp, p->as))
8143 json_object_boolean_true_add(json_neigh,
8144 "nbrCommonAdmin");
8145
8146 /* Status. */
8147 json_object_string_add(
8148 json_neigh, "bgpState",
8149 lookup_msg(bgp_status_msg, p->status, NULL));
8150
8151 if (p->status == Established) {
8152 time_t uptime;
8153 struct tm *tm;
8154
8155 uptime = bgp_clock();
8156 uptime -= p->uptime;
8157 tm = gmtime(&uptime);
8158 epoch_tbuf = time(NULL) - uptime;
8159
8160 json_object_int_add(json_neigh, "bgpTimerUp",
8161 (tm->tm_sec * 1000)
8162 + (tm->tm_min * 60000)
8163 + (tm->tm_hour * 3600000));
8164 json_object_string_add(json_neigh, "bgpTimerUpString",
8165 peer_uptime(p->uptime, timebuf,
8166 BGP_UPTIME_LEN, 0,
8167 NULL));
8168 json_object_int_add(json_neigh,
8169 "bgpTimerUpEstablishedEpoch",
8170 epoch_tbuf);
8171 }
8172
8173 else if (p->status == Active) {
8174 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8175 json_object_string_add(json_neigh, "bgpStateIs",
8176 "passive");
8177 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8178 json_object_string_add(json_neigh, "bgpStateIs",
8179 "passiveNSF");
8180 }
8181
8182 /* read timer */
8183 time_t uptime;
8184 struct tm *tm;
8185
8186 uptime = bgp_clock();
8187 uptime -= p->readtime;
8188 tm = gmtime(&uptime);
8189 json_object_int_add(json_neigh, "bgpTimerLastRead",
8190 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8191 + (tm->tm_hour * 3600000));
8192
8193 uptime = bgp_clock();
8194 uptime -= p->last_write;
8195 tm = gmtime(&uptime);
8196 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8197 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8198 + (tm->tm_hour * 3600000));
8199
8200 uptime = bgp_clock();
8201 uptime -= p->update_time;
8202 tm = gmtime(&uptime);
8203 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8204 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8205 + (tm->tm_hour * 3600000));
8206
8207 /* Configured timer values. */
8208 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8209 p->v_holdtime * 1000);
8210 json_object_int_add(json_neigh,
8211 "bgpTimerKeepAliveIntervalMsecs",
8212 p->v_keepalive * 1000);
8213
8214 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8215 json_object_int_add(json_neigh,
8216 "bgpTimerConfiguredHoldTimeMsecs",
8217 p->holdtime * 1000);
8218 json_object_int_add(
8219 json_neigh,
8220 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8221 p->keepalive * 1000);
8222 }
8223 } else {
8224 /* Administrative shutdown. */
8225 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8226 vty_out(vty, " Administratively shut down\n");
8227
8228 /* BGP Version. */
8229 vty_out(vty, " BGP version 4");
8230 vty_out(vty, ", remote router ID %s\n",
8231 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8232
8233 /* Confederation */
8234 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8235 && bgp_confederation_peers_check(bgp, p->as))
8236 vty_out(vty,
8237 " Neighbor under common administration\n");
8238
8239 /* Status. */
8240 vty_out(vty, " BGP state = %s",
8241 lookup_msg(bgp_status_msg, p->status, NULL));
8242
8243 if (p->status == Established)
8244 vty_out(vty, ", up for %8s",
8245 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8246 0, NULL));
8247
8248 else if (p->status == Active) {
8249 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8250 vty_out(vty, " (passive)");
8251 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8252 vty_out(vty, " (NSF passive)");
8253 }
8254 vty_out(vty, "\n");
8255
8256 /* read timer */
8257 vty_out(vty, " Last read %s",
8258 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8259 NULL));
8260 vty_out(vty, ", Last write %s\n",
8261 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8262 NULL));
8263
8264 /* Configured timer values. */
8265 vty_out(vty,
8266 " Hold time is %d, keepalive interval is %d seconds\n",
8267 p->v_holdtime, p->v_keepalive);
8268 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8269 vty_out(vty, " Configured hold time is %d",
8270 p->holdtime);
8271 vty_out(vty, ", keepalive interval is %d seconds\n",
8272 p->keepalive);
8273 }
8274 }
8275 /* Capability. */
8276 if (p->status == Established) {
8277 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8278 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8279 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8280 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8281 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8282 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8283 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8284 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8285 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8286 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8287 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8288 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8289 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8290 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8291 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8292 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8293 if (use_json) {
8294 json_object *json_cap = NULL;
8295
8296 json_cap = json_object_new_object();
8297
8298 /* AS4 */
8299 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8300 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8301 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8302 && CHECK_FLAG(p->cap,
8303 PEER_CAP_AS4_RCV))
8304 json_object_string_add(
8305 json_cap, "4byteAs",
8306 "advertisedAndReceived");
8307 else if (CHECK_FLAG(p->cap,
8308 PEER_CAP_AS4_ADV))
8309 json_object_string_add(
8310 json_cap, "4byteAs",
8311 "advertised");
8312 else if (CHECK_FLAG(p->cap,
8313 PEER_CAP_AS4_RCV))
8314 json_object_string_add(
8315 json_cap, "4byteAs",
8316 "received");
8317 }
8318
8319 /* AddPath */
8320 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8321 || CHECK_FLAG(p->cap,
8322 PEER_CAP_ADDPATH_ADV)) {
8323 json_object *json_add = NULL;
8324 const char *print_store;
8325
8326 json_add = json_object_new_object();
8327
8328 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8329 for (safi = SAFI_UNICAST;
8330 safi < SAFI_MAX; safi++) {
8331 json_object *json_sub =
8332 NULL;
8333 json_sub =
8334 json_object_new_object();
8335 print_store =
8336 afi_safi_print(
8337 afi,
8338 safi);
8339
8340 if (CHECK_FLAG(
8341 p->af_cap
8342 [afi]
8343 [safi],
8344 PEER_CAP_ADDPATH_AF_TX_ADV)
8345 || CHECK_FLAG(
8346 p->af_cap
8347 [afi]
8348 [safi],
8349 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8350 if (CHECK_FLAG(
8351 p->af_cap
8352 [afi]
8353 [safi],
8354 PEER_CAP_ADDPATH_AF_TX_ADV)
8355 && CHECK_FLAG(
8356 p->af_cap
8357 [afi]
8358 [safi],
8359 PEER_CAP_ADDPATH_AF_TX_RCV))
8360 json_object_boolean_true_add(
8361 json_sub,
8362 "txAdvertisedAndReceived");
8363 else if (
8364 CHECK_FLAG(
8365 p->af_cap
8366 [afi]
8367 [safi],
8368 PEER_CAP_ADDPATH_AF_TX_ADV))
8369 json_object_boolean_true_add(
8370 json_sub,
8371 "txAdvertised");
8372 else if (
8373 CHECK_FLAG(
8374 p->af_cap
8375 [afi]
8376 [safi],
8377 PEER_CAP_ADDPATH_AF_TX_RCV))
8378 json_object_boolean_true_add(
8379 json_sub,
8380 "txReceived");
8381 }
8382
8383 if (CHECK_FLAG(
8384 p->af_cap
8385 [afi]
8386 [safi],
8387 PEER_CAP_ADDPATH_AF_RX_ADV)
8388 || CHECK_FLAG(
8389 p->af_cap
8390 [afi]
8391 [safi],
8392 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8393 if (CHECK_FLAG(
8394 p->af_cap
8395 [afi]
8396 [safi],
8397 PEER_CAP_ADDPATH_AF_RX_ADV)
8398 && CHECK_FLAG(
8399 p->af_cap
8400 [afi]
8401 [safi],
8402 PEER_CAP_ADDPATH_AF_RX_RCV))
8403 json_object_boolean_true_add(
8404 json_sub,
8405 "rxAdvertisedAndReceived");
8406 else if (
8407 CHECK_FLAG(
8408 p->af_cap
8409 [afi]
8410 [safi],
8411 PEER_CAP_ADDPATH_AF_RX_ADV))
8412 json_object_boolean_true_add(
8413 json_sub,
8414 "rxAdvertised");
8415 else if (
8416 CHECK_FLAG(
8417 p->af_cap
8418 [afi]
8419 [safi],
8420 PEER_CAP_ADDPATH_AF_RX_RCV))
8421 json_object_boolean_true_add(
8422 json_sub,
8423 "rxReceived");
8424 }
8425
8426 if (CHECK_FLAG(
8427 p->af_cap
8428 [afi]
8429 [safi],
8430 PEER_CAP_ADDPATH_AF_TX_ADV)
8431 || CHECK_FLAG(
8432 p->af_cap
8433 [afi]
8434 [safi],
8435 PEER_CAP_ADDPATH_AF_TX_RCV)
8436 || CHECK_FLAG(
8437 p->af_cap
8438 [afi]
8439 [safi],
8440 PEER_CAP_ADDPATH_AF_RX_ADV)
8441 || CHECK_FLAG(
8442 p->af_cap
8443 [afi]
8444 [safi],
8445 PEER_CAP_ADDPATH_AF_RX_RCV))
8446 json_object_object_add(
8447 json_add,
8448 print_store,
8449 json_sub);
8450 else
8451 json_object_free(
8452 json_sub);
8453 }
8454
8455 json_object_object_add(
8456 json_cap, "addPath", json_add);
8457 }
8458
8459 /* Dynamic */
8460 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8461 || CHECK_FLAG(p->cap,
8462 PEER_CAP_DYNAMIC_ADV)) {
8463 if (CHECK_FLAG(p->cap,
8464 PEER_CAP_DYNAMIC_ADV)
8465 && CHECK_FLAG(p->cap,
8466 PEER_CAP_DYNAMIC_RCV))
8467 json_object_string_add(
8468 json_cap, "dynamic",
8469 "advertisedAndReceived");
8470 else if (CHECK_FLAG(
8471 p->cap,
8472 PEER_CAP_DYNAMIC_ADV))
8473 json_object_string_add(
8474 json_cap, "dynamic",
8475 "advertised");
8476 else if (CHECK_FLAG(
8477 p->cap,
8478 PEER_CAP_DYNAMIC_RCV))
8479 json_object_string_add(
8480 json_cap, "dynamic",
8481 "received");
8482 }
8483
8484 /* Extended nexthop */
8485 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8486 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8487 json_object *json_nxt = NULL;
8488 const char *print_store;
8489
8490
8491 if (CHECK_FLAG(p->cap,
8492 PEER_CAP_ENHE_ADV)
8493 && CHECK_FLAG(p->cap,
8494 PEER_CAP_ENHE_RCV))
8495 json_object_string_add(
8496 json_cap,
8497 "extendedNexthop",
8498 "advertisedAndReceived");
8499 else if (CHECK_FLAG(p->cap,
8500 PEER_CAP_ENHE_ADV))
8501 json_object_string_add(
8502 json_cap,
8503 "extendedNexthop",
8504 "advertised");
8505 else if (CHECK_FLAG(p->cap,
8506 PEER_CAP_ENHE_RCV))
8507 json_object_string_add(
8508 json_cap,
8509 "extendedNexthop",
8510 "received");
8511
8512 if (CHECK_FLAG(p->cap,
8513 PEER_CAP_ENHE_RCV)) {
8514 json_nxt =
8515 json_object_new_object();
8516
8517 for (safi = SAFI_UNICAST;
8518 safi < SAFI_MAX; safi++) {
8519 if (CHECK_FLAG(
8520 p->af_cap
8521 [AFI_IP]
8522 [safi],
8523 PEER_CAP_ENHE_AF_RCV)) {
8524 print_store = afi_safi_print(
8525 AFI_IP,
8526 safi);
8527 json_object_string_add(
8528 json_nxt,
8529 print_store,
8530 "recieved");
8531 }
8532 }
8533 json_object_object_add(
8534 json_cap,
8535 "extendedNexthopFamililesByPeer",
8536 json_nxt);
8537 }
8538 }
8539
8540 /* Route Refresh */
8541 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8542 || CHECK_FLAG(p->cap,
8543 PEER_CAP_REFRESH_NEW_RCV)
8544 || CHECK_FLAG(p->cap,
8545 PEER_CAP_REFRESH_OLD_RCV)) {
8546 if (CHECK_FLAG(p->cap,
8547 PEER_CAP_REFRESH_ADV)
8548 && (CHECK_FLAG(
8549 p->cap,
8550 PEER_CAP_REFRESH_NEW_RCV)
8551 || CHECK_FLAG(
8552 p->cap,
8553 PEER_CAP_REFRESH_OLD_RCV))) {
8554 if (CHECK_FLAG(
8555 p->cap,
8556 PEER_CAP_REFRESH_OLD_RCV)
8557 && CHECK_FLAG(
8558 p->cap,
8559 PEER_CAP_REFRESH_NEW_RCV))
8560 json_object_string_add(
8561 json_cap,
8562 "routeRefresh",
8563 "advertisedAndReceivedOldNew");
8564 else {
8565 if (CHECK_FLAG(
8566 p->cap,
8567 PEER_CAP_REFRESH_OLD_RCV))
8568 json_object_string_add(
8569 json_cap,
8570 "routeRefresh",
8571 "advertisedAndReceivedOld");
8572 else
8573 json_object_string_add(
8574 json_cap,
8575 "routeRefresh",
8576 "advertisedAndReceivedNew");
8577 }
8578 } else if (
8579 CHECK_FLAG(
8580 p->cap,
8581 PEER_CAP_REFRESH_ADV))
8582 json_object_string_add(
8583 json_cap,
8584 "routeRefresh",
8585 "advertised");
8586 else if (
8587 CHECK_FLAG(
8588 p->cap,
8589 PEER_CAP_REFRESH_NEW_RCV)
8590 || CHECK_FLAG(
8591 p->cap,
8592 PEER_CAP_REFRESH_OLD_RCV))
8593 json_object_string_add(
8594 json_cap,
8595 "routeRefresh",
8596 "received");
8597 }
8598
8599 /* Multiprotocol Extensions */
8600 json_object *json_multi = NULL;
8601 json_multi = json_object_new_object();
8602
8603 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
8604 for (safi = SAFI_UNICAST;
8605 safi < SAFI_MAX; safi++) {
8606 if (p->afc_adv[afi][safi]
8607 || p->afc_recv[afi][safi]) {
8608 json_object
8609 *json_exten =
8610 NULL;
8611 json_exten =
8612 json_object_new_object();
8613
8614 if (p->afc_adv[afi]
8615 [safi]
8616 && p->afc_recv
8617 [afi]
8618 [safi])
8619 json_object_boolean_true_add(
8620 json_exten,
8621 "advertisedAndReceived");
8622 else if (p->afc_adv
8623 [afi]
8624 [safi])
8625 json_object_boolean_true_add(
8626 json_exten,
8627 "advertised");
8628 else if (p->afc_recv
8629 [afi]
8630 [safi])
8631 json_object_boolean_true_add(
8632 json_exten,
8633 "received");
8634
8635 json_object_object_add(
8636 json_multi,
8637 afi_safi_print(
8638 afi,
8639 safi),
8640 json_exten);
8641 }
8642 }
8643 }
8644 json_object_object_add(
8645 json_cap, "multiprotocolExtensions",
8646 json_multi);
8647
d77114b7 8648 /* Hostname capabilities */
60466a63 8649 json_object *json_hname = NULL;
d77114b7
MK
8650
8651 json_hname = json_object_new_object();
8652
8653 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8654 json_object_string_add(
60466a63
QY
8655 json_hname, "advHostName",
8656 bgp->peer_self->hostname
8657 ? bgp->peer_self
8658 ->hostname
d77114b7
MK
8659 : "n/a");
8660 json_object_string_add(
60466a63
QY
8661 json_hname, "advDomainName",
8662 bgp->peer_self->domainname
8663 ? bgp->peer_self
8664 ->domainname
d77114b7
MK
8665 : "n/a");
8666 }
8667
8668
8669 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8670 json_object_string_add(
60466a63
QY
8671 json_hname, "rcvHostName",
8672 p->hostname ? p->hostname
8673 : "n/a");
d77114b7 8674 json_object_string_add(
60466a63
QY
8675 json_hname, "rcvDomainName",
8676 p->domainname ? p->domainname
8677 : "n/a");
d77114b7
MK
8678 }
8679
60466a63 8680 json_object_object_add(json_cap, "hostName",
d77114b7
MK
8681 json_hname);
8682
d62a17ae 8683 /* Gracefull Restart */
8684 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8685 || CHECK_FLAG(p->cap,
8686 PEER_CAP_RESTART_ADV)) {
8687 if (CHECK_FLAG(p->cap,
8688 PEER_CAP_RESTART_ADV)
8689 && CHECK_FLAG(p->cap,
8690 PEER_CAP_RESTART_RCV))
8691 json_object_string_add(
8692 json_cap,
8693 "gracefulRestart",
8694 "advertisedAndReceived");
8695 else if (CHECK_FLAG(
8696 p->cap,
8697 PEER_CAP_RESTART_ADV))
8698 json_object_string_add(
8699 json_cap,
8700 "gracefulRestartCapability",
8701 "advertised");
8702 else if (CHECK_FLAG(
8703 p->cap,
8704 PEER_CAP_RESTART_RCV))
8705 json_object_string_add(
8706 json_cap,
8707 "gracefulRestartCapability",
8708 "received");
8709
8710 if (CHECK_FLAG(p->cap,
8711 PEER_CAP_RESTART_RCV)) {
8712 int restart_af_count = 0;
8713 json_object *json_restart =
8714 NULL;
8715 json_restart =
8716 json_object_new_object();
8717
8718 json_object_int_add(
8719 json_cap,
8720 "gracefulRestartRemoteTimerMsecs",
8721 p->v_gr_restart * 1000);
8722
8723 for (afi = AFI_IP;
8724 afi < AFI_MAX; afi++) {
8725 for (safi = SAFI_UNICAST;
8726 safi < SAFI_MAX;
8727 safi++) {
8728 if (CHECK_FLAG(
8729 p->af_cap
8730 [afi]
8731 [safi],
8732 PEER_CAP_RESTART_AF_RCV)) {
8733 json_object *json_sub =
8734 NULL;
8735 json_sub =
8736 json_object_new_object();
8737
8738 if (CHECK_FLAG(
8739 p->af_cap
8740 [afi]
8741 [safi],
8742 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8743 json_object_boolean_true_add(
8744 json_sub,
8745 "preserved");
8746 restart_af_count++;
8747 json_object_object_add(
8748 json_restart,
8749 afi_safi_print(
8750 afi,
8751 safi),
8752 json_sub);
8753 }
8754 }
8755 }
8756 if (!restart_af_count) {
8757 json_object_string_add(
8758 json_cap,
8759 "addressFamiliesByPeer",
8760 "none");
8761 json_object_free(
8762 json_restart);
8763 } else
8764 json_object_object_add(
8765 json_cap,
8766 "addressFamiliesByPeer",
8767 json_restart);
8768 }
8769 }
8770 json_object_object_add(json_neigh,
8771 "neighborCapabilities",
8772 json_cap);
8773 } else {
8774 vty_out(vty, " Neighbor capabilities:\n");
8775
8776 /* AS4 */
8777 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8778 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8779 vty_out(vty, " 4 Byte AS:");
8780 if (CHECK_FLAG(p->cap,
8781 PEER_CAP_AS4_ADV))
8782 vty_out(vty, " advertised");
8783 if (CHECK_FLAG(p->cap,
8784 PEER_CAP_AS4_RCV))
8785 vty_out(vty, " %sreceived",
8786 CHECK_FLAG(
8787 p->cap,
8788 PEER_CAP_AS4_ADV)
8789 ? "and "
8790 : "");
8791 vty_out(vty, "\n");
8792 }
8793
8794 /* AddPath */
8795 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8796 || CHECK_FLAG(p->cap,
8797 PEER_CAP_ADDPATH_ADV)) {
8798 vty_out(vty, " AddPath:\n");
8799
8800 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8801 for (safi = SAFI_UNICAST;
8802 safi < SAFI_MAX; safi++) {
8803 if (CHECK_FLAG(
8804 p->af_cap
8805 [afi]
8806 [safi],
8807 PEER_CAP_ADDPATH_AF_TX_ADV)
8808 || CHECK_FLAG(
8809 p->af_cap
8810 [afi]
8811 [safi],
8812 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8813 vty_out(vty,
8814 " %s: TX ",
8815 afi_safi_print(
8816 afi,
8817 safi));
8818
8819 if (CHECK_FLAG(
8820 p->af_cap
8821 [afi]
8822 [safi],
8823 PEER_CAP_ADDPATH_AF_TX_ADV))
8824 vty_out(vty,
8825 "advertised %s",
8826 afi_safi_print(
8827 afi,
8828 safi));
8829
8830 if (CHECK_FLAG(
8831 p->af_cap
8832 [afi]
8833 [safi],
8834 PEER_CAP_ADDPATH_AF_TX_RCV))
8835 vty_out(vty,
8836 "%sreceived",
8837 CHECK_FLAG(
8838 p->af_cap
8839 [afi]
8840 [safi],
8841 PEER_CAP_ADDPATH_AF_TX_ADV)
8842 ? " and "
8843 : "");
8844
8845 vty_out(vty,
8846 "\n");
8847 }
8848
8849 if (CHECK_FLAG(
8850 p->af_cap
8851 [afi]
8852 [safi],
8853 PEER_CAP_ADDPATH_AF_RX_ADV)
8854 || CHECK_FLAG(
8855 p->af_cap
8856 [afi]
8857 [safi],
8858 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8859 vty_out(vty,
8860 " %s: RX ",
8861 afi_safi_print(
8862 afi,
8863 safi));
8864
8865 if (CHECK_FLAG(
8866 p->af_cap
8867 [afi]
8868 [safi],
8869 PEER_CAP_ADDPATH_AF_RX_ADV))
8870 vty_out(vty,
8871 "advertised %s",
8872 afi_safi_print(
8873 afi,
8874 safi));
8875
8876 if (CHECK_FLAG(
8877 p->af_cap
8878 [afi]
8879 [safi],
8880 PEER_CAP_ADDPATH_AF_RX_RCV))
8881 vty_out(vty,
8882 "%sreceived",
8883 CHECK_FLAG(
8884 p->af_cap
8885 [afi]
8886 [safi],
8887 PEER_CAP_ADDPATH_AF_RX_ADV)
8888 ? " and "
8889 : "");
8890
8891 vty_out(vty,
8892 "\n");
8893 }
8894 }
8895 }
8896
8897 /* Dynamic */
8898 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8899 || CHECK_FLAG(p->cap,
8900 PEER_CAP_DYNAMIC_ADV)) {
8901 vty_out(vty, " Dynamic:");
8902 if (CHECK_FLAG(p->cap,
8903 PEER_CAP_DYNAMIC_ADV))
8904 vty_out(vty, " advertised");
8905 if (CHECK_FLAG(p->cap,
8906 PEER_CAP_DYNAMIC_RCV))
8907 vty_out(vty, " %sreceived",
8908 CHECK_FLAG(
8909 p->cap,
8910 PEER_CAP_DYNAMIC_ADV)
8911 ? "and "
8912 : "");
8913 vty_out(vty, "\n");
8914 }
8915
8916 /* Extended nexthop */
8917 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8918 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8919 vty_out(vty, " Extended nexthop:");
8920 if (CHECK_FLAG(p->cap,
8921 PEER_CAP_ENHE_ADV))
8922 vty_out(vty, " advertised");
8923 if (CHECK_FLAG(p->cap,
8924 PEER_CAP_ENHE_RCV))
8925 vty_out(vty, " %sreceived",
8926 CHECK_FLAG(
8927 p->cap,
8928 PEER_CAP_ENHE_ADV)
8929 ? "and "
8930 : "");
8931 vty_out(vty, "\n");
8932
8933 if (CHECK_FLAG(p->cap,
8934 PEER_CAP_ENHE_RCV)) {
8935 vty_out(vty,
8936 " Address families by peer:\n ");
8937 for (safi = SAFI_UNICAST;
8938 safi < SAFI_MAX; safi++)
8939 if (CHECK_FLAG(
8940 p->af_cap
8941 [AFI_IP]
8942 [safi],
8943 PEER_CAP_ENHE_AF_RCV))
8944 vty_out(vty,
8945 " %s\n",
8946 afi_safi_print(
8947 AFI_IP,
8948 safi));
8949 }
8950 }
8951
8952 /* Route Refresh */
8953 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8954 || CHECK_FLAG(p->cap,
8955 PEER_CAP_REFRESH_NEW_RCV)
8956 || CHECK_FLAG(p->cap,
8957 PEER_CAP_REFRESH_OLD_RCV)) {
8958 vty_out(vty, " Route refresh:");
8959 if (CHECK_FLAG(p->cap,
8960 PEER_CAP_REFRESH_ADV))
8961 vty_out(vty, " advertised");
8962 if (CHECK_FLAG(p->cap,
8963 PEER_CAP_REFRESH_NEW_RCV)
8964 || CHECK_FLAG(
8965 p->cap,
8966 PEER_CAP_REFRESH_OLD_RCV))
8967 vty_out(vty, " %sreceived(%s)",
8968 CHECK_FLAG(
8969 p->cap,
8970 PEER_CAP_REFRESH_ADV)
8971 ? "and "
8972 : "",
8973 (CHECK_FLAG(
8974 p->cap,
8975 PEER_CAP_REFRESH_OLD_RCV)
8976 && CHECK_FLAG(
8977 p->cap,
8978 PEER_CAP_REFRESH_NEW_RCV))
8979 ? "old & new"
8980 : CHECK_FLAG(
8981 p->cap,
8982 PEER_CAP_REFRESH_OLD_RCV)
8983 ? "old"
8984 : "new");
8985
8986 vty_out(vty, "\n");
8987 }
8988
8989 /* Multiprotocol Extensions */
8990 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8991 for (safi = SAFI_UNICAST;
8992 safi < SAFI_MAX; safi++)
8993 if (p->afc_adv[afi][safi]
8994 || p->afc_recv[afi][safi]) {
8995 vty_out(vty,
8996 " Address Family %s:",
8997 afi_safi_print(
8998 afi,
8999 safi));
9000 if (p->afc_adv[afi]
9001 [safi])
9002 vty_out(vty,
9003 " advertised");
9004 if (p->afc_recv[afi]
9005 [safi])
9006 vty_out(vty,
9007 " %sreceived",
9008 p->afc_adv[afi]
9009 [safi]
9010 ? "and "
9011 : "");
9012 vty_out(vty, "\n");
9013 }
9014
9015 /* Hostname capability */
60466a63 9016 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9017
9018 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9019 vty_out(vty,
9020 " advertised (name: %s,domain name: %s)",
60466a63
QY
9021 bgp->peer_self->hostname
9022 ? bgp->peer_self
9023 ->hostname
d77114b7 9024 : "n/a",
60466a63
QY
9025 bgp->peer_self->domainname
9026 ? bgp->peer_self
9027 ->domainname
d77114b7
MK
9028 : "n/a");
9029 } else {
9030 vty_out(vty, " not advertised");
d62a17ae 9031 }
9032
d77114b7 9033 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9034 vty_out(vty,
9035 " received (name: %s,domain name: %s)",
60466a63
QY
9036 p->hostname ? p->hostname
9037 : "n/a",
9038 p->domainname ? p->domainname
9039 : "n/a");
d77114b7
MK
9040 } else {
9041 vty_out(vty, " not received");
9042 }
9043
9044 vty_out(vty, "\n");
9045
d62a17ae 9046 /* Gracefull Restart */
9047 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9048 || CHECK_FLAG(p->cap,
9049 PEER_CAP_RESTART_ADV)) {
9050 vty_out(vty,
9051 " Graceful Restart Capabilty:");
9052 if (CHECK_FLAG(p->cap,
9053 PEER_CAP_RESTART_ADV))
9054 vty_out(vty, " advertised");
9055 if (CHECK_FLAG(p->cap,
9056 PEER_CAP_RESTART_RCV))
9057 vty_out(vty, " %sreceived",
9058 CHECK_FLAG(
9059 p->cap,
9060 PEER_CAP_RESTART_ADV)
9061 ? "and "
9062 : "");
9063 vty_out(vty, "\n");
9064
9065 if (CHECK_FLAG(p->cap,
9066 PEER_CAP_RESTART_RCV)) {
9067 int restart_af_count = 0;
9068
9069 vty_out(vty,
9070 " Remote Restart timer is %d seconds\n",
9071 p->v_gr_restart);
9072 vty_out(vty,
9073 " Address families by peer:\n ");
9074
9075 for (afi = AFI_IP;
9076 afi < AFI_MAX; afi++)
9077 for (safi = SAFI_UNICAST;
9078 safi < SAFI_MAX;
9079 safi++)
9080 if (CHECK_FLAG(
9081 p->af_cap
9082 [afi]
9083 [safi],
9084 PEER_CAP_RESTART_AF_RCV)) {
9085 vty_out(vty,
9086 "%s%s(%s)",
9087 restart_af_count
9088 ? ", "
9089 : "",
9090 afi_safi_print(
9091 afi,
9092 safi),
9093 CHECK_FLAG(
9094 p->af_cap
9095 [afi]
9096 [safi],
9097 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9098 ? "preserved"
9099 : "not preserved");
9100 restart_af_count++;
9101 }
9102 if (!restart_af_count)
9103 vty_out(vty, "none");
9104 vty_out(vty, "\n");
9105 }
9106 }
9107 }
9108 }
9109 }
9110
9111 /* graceful restart information */
9112 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9113 || p->t_gr_stale) {
9114 json_object *json_grace = NULL;
9115 json_object *json_grace_send = NULL;
9116 json_object *json_grace_recv = NULL;
9117 int eor_send_af_count = 0;
9118 int eor_receive_af_count = 0;
9119
9120 if (use_json) {
9121 json_grace = json_object_new_object();
9122 json_grace_send = json_object_new_object();
9123 json_grace_recv = json_object_new_object();
9124
9125 if (p->status == Established) {
9126 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9127 for (safi = SAFI_UNICAST;
9128 safi < SAFI_MAX; safi++) {
9129 if (CHECK_FLAG(
9130 p->af_sflags[afi]
9131 [safi],
9132 PEER_STATUS_EOR_SEND)) {
9133 json_object_boolean_true_add(
9134 json_grace_send,
9135 afi_safi_print(
9136 afi,
9137 safi));
9138 eor_send_af_count++;
9139 }
9140 }
9141 }
9142 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9143 for (safi = SAFI_UNICAST;
9144 safi < SAFI_MAX; safi++) {
9145 if (CHECK_FLAG(
9146 p->af_sflags[afi]
9147 [safi],
9148 PEER_STATUS_EOR_RECEIVED)) {
9149 json_object_boolean_true_add(
9150 json_grace_recv,
9151 afi_safi_print(
9152 afi,
9153 safi));
9154 eor_receive_af_count++;
9155 }
9156 }
9157 }
9158 }
9159
9160 json_object_object_add(json_grace, "endOfRibSend",
9161 json_grace_send);
9162 json_object_object_add(json_grace, "endOfRibRecv",
9163 json_grace_recv);
9164
9165 if (p->t_gr_restart)
9166 json_object_int_add(json_grace,
9167 "gracefulRestartTimerMsecs",
9168 thread_timer_remain_second(
9169 p->t_gr_restart)
9170 * 1000);
9171
9172 if (p->t_gr_stale)
9173 json_object_int_add(
9174 json_grace,
9175 "gracefulStalepathTimerMsecs",
9176 thread_timer_remain_second(
9177 p->t_gr_stale)
9178 * 1000);
9179
9180 json_object_object_add(
9181 json_neigh, "gracefulRestartInfo", json_grace);
9182 } else {
9183 vty_out(vty, " Graceful restart informations:\n");
9184 if (p->status == Established) {
9185 vty_out(vty, " End-of-RIB send: ");
9186 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9187 for (safi = SAFI_UNICAST;
9188 safi < SAFI_MAX; safi++) {
9189 if (CHECK_FLAG(
9190 p->af_sflags[afi]
9191 [safi],
9192 PEER_STATUS_EOR_SEND)) {
9193 vty_out(vty, "%s%s",
9194 eor_send_af_count
9195 ? ", "
9196 : "",
9197 afi_safi_print(
9198 afi,
9199 safi));
9200 eor_send_af_count++;
9201 }
9202 }
9203 }
9204 vty_out(vty, "\n");
9205 vty_out(vty, " End-of-RIB received: ");
9206 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9207 for (safi = SAFI_UNICAST;
9208 safi < SAFI_MAX; safi++) {
9209 if (CHECK_FLAG(
9210 p->af_sflags[afi]
9211 [safi],
9212 PEER_STATUS_EOR_RECEIVED)) {
9213 vty_out(vty, "%s%s",
9214 eor_receive_af_count
9215 ? ", "
9216 : "",
9217 afi_safi_print(
9218 afi,
9219 safi));
9220 eor_receive_af_count++;
9221 }
9222 }
9223 }
9224 vty_out(vty, "\n");
9225 }
9226
9227 if (p->t_gr_restart)
9228 vty_out(vty,
9229 " The remaining time of restart timer is %ld\n",
9230 thread_timer_remain_second(
9231 p->t_gr_restart));
9232
9233 if (p->t_gr_stale)
9234 vty_out(vty,
9235 " The remaining time of stalepath timer is %ld\n",
9236 thread_timer_remain_second(
9237 p->t_gr_stale));
9238 }
9239 }
9240 if (use_json) {
9241 json_object *json_stat = NULL;
9242 json_stat = json_object_new_object();
9243 /* Packet counts. */
9244 json_object_int_add(json_stat, "depthInq", 0);
9245 json_object_int_add(json_stat, "depthOutq",
9246 (unsigned long)p->obuf->count);
9247 json_object_int_add(json_stat, "opensSent", p->open_out);
9248 json_object_int_add(json_stat, "opensRecv", p->open_in);
9249 json_object_int_add(json_stat, "notificationsSent",
9250 p->notify_out);
9251 json_object_int_add(json_stat, "notificationsRecv",
9252 p->notify_in);
9253 json_object_int_add(json_stat, "updatesSent", p->update_out);
9254 json_object_int_add(json_stat, "updatesRecv", p->update_in);
9255 json_object_int_add(json_stat, "keepalivesSent",
9256 p->keepalive_out);
9257 json_object_int_add(json_stat, "keepalivesRecv",
9258 p->keepalive_in);
9259 json_object_int_add(json_stat, "routeRefreshSent",
9260 p->refresh_out);
9261 json_object_int_add(json_stat, "routeRefreshRecv",
9262 p->refresh_in);
9263 json_object_int_add(json_stat, "capabilitySent",
9264 p->dynamic_cap_out);
9265 json_object_int_add(json_stat, "capabilityRecv",
9266 p->dynamic_cap_in);
9267 json_object_int_add(json_stat, "totalSent",
9268 p->open_out + p->notify_out + p->update_out
9269 + p->keepalive_out + p->refresh_out
9270 + p->dynamic_cap_out);
9271 json_object_int_add(json_stat, "totalRecv",
9272 p->open_in + p->notify_in + p->update_in
9273 + p->keepalive_in + p->refresh_in
9274 + p->dynamic_cap_in);
9275 json_object_object_add(json_neigh, "messageStats", json_stat);
9276 } else {
9277 /* Packet counts. */
9278 vty_out(vty, " Message statistics:\n");
9279 vty_out(vty, " Inq depth is 0\n");
9280 vty_out(vty, " Outq depth is %lu\n",
9281 (unsigned long)p->obuf->count);
9282 vty_out(vty, " Sent Rcvd\n");
9283 vty_out(vty, " Opens: %10d %10d\n", p->open_out,
9284 p->open_in);
9285 vty_out(vty, " Notifications: %10d %10d\n", p->notify_out,
9286 p->notify_in);
9287 vty_out(vty, " Updates: %10d %10d\n", p->update_out,
9288 p->update_in);
9289 vty_out(vty, " Keepalives: %10d %10d\n", p->keepalive_out,
9290 p->keepalive_in);
9291 vty_out(vty, " Route Refresh: %10d %10d\n", p->refresh_out,
9292 p->refresh_in);
9293 vty_out(vty, " Capability: %10d %10d\n",
9294 p->dynamic_cap_out, p->dynamic_cap_in);
9295 vty_out(vty, " Total: %10d %10d\n",
9296 p->open_out + p->notify_out + p->update_out
9297 + p->keepalive_out + p->refresh_out
9298 + p->dynamic_cap_out,
9299 p->open_in + p->notify_in + p->update_in
9300 + p->keepalive_in + p->refresh_in
9301 + p->dynamic_cap_in);
9302 }
9303
9304 if (use_json) {
9305 /* advertisement-interval */
9306 json_object_int_add(json_neigh,
9307 "minBtwnAdvertisementRunsTimerMsecs",
9308 p->v_routeadv * 1000);
9309
9310 /* Update-source. */
9311 if (p->update_if || p->update_source) {
9312 if (p->update_if)
9313 json_object_string_add(json_neigh,
9314 "updateSource",
9315 p->update_if);
9316 else if (p->update_source)
9317 json_object_string_add(
9318 json_neigh, "updateSource",
9319 sockunion2str(p->update_source, buf1,
9320 SU_ADDRSTRLEN));
9321 }
9322 } else {
9323 /* advertisement-interval */
9324 vty_out(vty,
9325 " Minimum time between advertisement runs is %d seconds\n",
9326 p->v_routeadv);
9327
9328 /* Update-source. */
9329 if (p->update_if || p->update_source) {
9330 vty_out(vty, " Update source is ");
9331 if (p->update_if)
9332 vty_out(vty, "%s", p->update_if);
9333 else if (p->update_source)
9334 vty_out(vty, "%s",
9335 sockunion2str(p->update_source, buf1,
9336 SU_ADDRSTRLEN));
9337 vty_out(vty, "\n");
9338 }
9339
9340 vty_out(vty, "\n");
9341 }
9342
9343 /* Address Family Information */
9344 json_object *json_hold = NULL;
9345
9346 if (use_json)
9347 json_hold = json_object_new_object();
9348
9349 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9350 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
9351 if (p->afc[afi][safi])
9352 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9353 json_hold);
9354
9355 if (use_json) {
9356 json_object_object_add(json_neigh, "addressFamilyInfo",
9357 json_hold);
9358 json_object_int_add(json_neigh, "connectionsEstablished",
9359 p->established);
9360 json_object_int_add(json_neigh, "connectionsDropped",
9361 p->dropped);
9362 } else
9363 vty_out(vty, " Connections established %d; dropped %d\n",
9364 p->established, p->dropped);
9365
9366 if (!p->last_reset) {
9367 if (use_json)
9368 json_object_string_add(json_neigh, "lastReset",
9369 "never");
9370 else
9371 vty_out(vty, " Last reset never\n");
9372 } else {
9373 if (use_json) {
9374 time_t uptime;
9375 struct tm *tm;
9376
9377 uptime = bgp_clock();
9378 uptime -= p->resettime;
9379 tm = gmtime(&uptime);
9380 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9381 (tm->tm_sec * 1000)
9382 + (tm->tm_min * 60000)
9383 + (tm->tm_hour * 3600000));
9384 json_object_string_add(
9385 json_neigh, "lastResetDueTo",
9386 peer_down_str[(int)p->last_reset]);
9387 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9388 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9389 char errorcodesubcode_hexstr[5];
9390 char errorcodesubcode_str[256];
9391
9392 code_str = bgp_notify_code_str(p->notify.code);
9393 subcode_str = bgp_notify_subcode_str(
9394 p->notify.code, p->notify.subcode);
9395
9396 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9397 p->notify.code, p->notify.subcode);
9398 json_object_string_add(json_neigh,
9399 "lastErrorCodeSubcode",
9400 errorcodesubcode_hexstr);
9401 snprintf(errorcodesubcode_str, 255, "%s%s",
9402 code_str, subcode_str);
9403 json_object_string_add(json_neigh,
9404 "lastNotificationReason",
9405 errorcodesubcode_str);
9406 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9407 && p->notify.code == BGP_NOTIFY_CEASE
9408 && (p->notify.subcode
9409 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9410 || p->notify.subcode
9411 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9412 && p->notify.length) {
9413 char msgbuf[1024];
9414 const char *msg_str;
9415
9416 msg_str = bgp_notify_admin_message(
9417 msgbuf, sizeof(msgbuf),
9418 (u_char *)p->notify.data,
9419 p->notify.length);
9420 if (msg_str)
9421 json_object_string_add(
9422 json_neigh,
9423 "lastShutdownDescription",
9424 msg_str);
9425 }
9426 }
9427 } else {
9428 vty_out(vty, " Last reset %s, ",
9429 peer_uptime(p->resettime, timebuf,
9430 BGP_UPTIME_LEN, 0, NULL));
9431
9432 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9433 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9434 code_str = bgp_notify_code_str(p->notify.code);
9435 subcode_str = bgp_notify_subcode_str(
9436 p->notify.code, p->notify.subcode);
9437 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9438 p->last_reset == PEER_DOWN_NOTIFY_SEND
9439 ? "sent"
9440 : "received",
9441 code_str, subcode_str);
9442 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9443 && p->notify.code == BGP_NOTIFY_CEASE
9444 && (p->notify.subcode
9445 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9446 || p->notify.subcode
9447 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9448 && p->notify.length) {
9449 char msgbuf[1024];
9450 const char *msg_str;
9451
9452 msg_str = bgp_notify_admin_message(
9453 msgbuf, sizeof(msgbuf),
9454 (u_char *)p->notify.data,
9455 p->notify.length);
9456 if (msg_str)
9457 vty_out(vty,
9458 " Message: \"%s\"\n",
9459 msg_str);
9460 }
9461 } else {
9462 vty_out(vty, "due to %s\n",
9463 peer_down_str[(int)p->last_reset]);
9464 }
9465
9466 if (p->last_reset_cause_size) {
9467 msg = p->last_reset_cause;
9468 vty_out(vty,
9469 " Message received that caused BGP to send a NOTIFICATION:\n ");
9470 for (i = 1; i <= p->last_reset_cause_size;
9471 i++) {
9472 vty_out(vty, "%02X", *msg++);
9473
9474 if (i != p->last_reset_cause_size) {
9475 if (i % 16 == 0) {
9476 vty_out(vty, "\n ");
9477 } else if (i % 4 == 0) {
9478 vty_out(vty, " ");
9479 }
9480 }
9481 }
9482 vty_out(vty, "\n");
9483 }
9484 }
9485 }
9486
9487 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9488 if (use_json)
9489 json_object_boolean_true_add(json_neigh,
9490 "prefixesConfigExceedMax");
9491 else
9492 vty_out(vty,
9493 " Peer had exceeded the max. no. of prefixes configured.\n");
9494
9495 if (p->t_pmax_restart) {
9496 if (use_json) {
9497 json_object_boolean_true_add(
9498 json_neigh, "reducePrefixNumFrom");
9499 json_object_int_add(json_neigh,
9500 "restartInTimerMsec",
9501 thread_timer_remain_second(
9502 p->t_pmax_restart)
9503 * 1000);
9504 } else
9505 vty_out(vty,
9506 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9d303b37
DL
9507 p->host, thread_timer_remain_second(
9508 p->t_pmax_restart));
d62a17ae 9509 } else {
9510 if (use_json)
9511 json_object_boolean_true_add(
9512 json_neigh,
9513 "reducePrefixNumAndClearIpBgp");
9514 else
9515 vty_out(vty,
9516 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9517 p->host);
9518 }
9519 }
9520
9521 /* EBGP Multihop and GTSM */
9522 if (p->sort != BGP_PEER_IBGP) {
9523 if (use_json) {
9524 if (p->gtsm_hops > 0)
9525 json_object_int_add(json_neigh,
9526 "externalBgpNbrMaxHopsAway",
9527 p->gtsm_hops);
9528 else if (p->ttl > 1)
9529 json_object_int_add(json_neigh,
9530 "externalBgpNbrMaxHopsAway",
9531 p->ttl);
9532 } else {
9533 if (p->gtsm_hops > 0)
9534 vty_out(vty,
9535 " External BGP neighbor may be up to %d hops away.\n",
9536 p->gtsm_hops);
9537 else if (p->ttl > 1)
9538 vty_out(vty,
9539 " External BGP neighbor may be up to %d hops away.\n",
9540 p->ttl);
9541 }
9542 } else {
9543 if (p->gtsm_hops > 0) {
9544 if (use_json)
9545 json_object_int_add(json_neigh,
9546 "internalBgpNbrMaxHopsAway",
9547 p->gtsm_hops);
9548 else
9549 vty_out(vty,
9550 " Internal BGP neighbor may be up to %d hops away.\n",
9551 p->gtsm_hops);
9552 }
9553 }
9554
9555 /* Local address. */
9556 if (p->su_local) {
9557 if (use_json) {
9558 json_object_string_add(json_neigh, "hostLocal",
9559 sockunion2str(p->su_local, buf1,
9560 SU_ADDRSTRLEN));
9561 json_object_int_add(json_neigh, "portLocal",
9562 ntohs(p->su_local->sin.sin_port));
9563 } else
9564 vty_out(vty, "Local host: %s, Local port: %d\n",
9565 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9566 ntohs(p->su_local->sin.sin_port));
9567 }
9568
9569 /* Remote address. */
9570 if (p->su_remote) {
9571 if (use_json) {
9572 json_object_string_add(json_neigh, "hostForeign",
9573 sockunion2str(p->su_remote, buf1,
9574 SU_ADDRSTRLEN));
9575 json_object_int_add(json_neigh, "portForeign",
9576 ntohs(p->su_remote->sin.sin_port));
9577 } else
9578 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9579 sockunion2str(p->su_remote, buf1,
9580 SU_ADDRSTRLEN),
9581 ntohs(p->su_remote->sin.sin_port));
9582 }
9583
9584 /* Nexthop display. */
9585 if (p->su_local) {
9586 if (use_json) {
9587 json_object_string_add(json_neigh, "nexthop",
9588 inet_ntop(AF_INET,
9589 &p->nexthop.v4, buf1,
9590 sizeof(buf1)));
9591 json_object_string_add(json_neigh, "nexthopGlobal",
9592 inet_ntop(AF_INET6,
9593 &p->nexthop.v6_global,
9594 buf1, sizeof(buf1)));
9595 json_object_string_add(json_neigh, "nexthopLocal",
9596 inet_ntop(AF_INET6,
9597 &p->nexthop.v6_local,
9598 buf1, sizeof(buf1)));
9599 if (p->shared_network)
9600 json_object_string_add(json_neigh,
9601 "bgpConnection",
9602 "sharedNetwork");
9603 else
9604 json_object_string_add(json_neigh,
9605 "bgpConnection",
9606 "nonSharedNetwork");
9607 } else {
9608 vty_out(vty, "Nexthop: %s\n",
9609 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9610 sizeof(buf1)));
9611 vty_out(vty, "Nexthop global: %s\n",
9612 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9613 sizeof(buf1)));
9614 vty_out(vty, "Nexthop local: %s\n",
9615 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9616 sizeof(buf1)));
9617 vty_out(vty, "BGP connection: %s\n",
9618 p->shared_network ? "shared network"
9619 : "non shared network");
9620 }
9621 }
9622
9623 /* Timer information. */
9624 if (use_json) {
9625 json_object_int_add(json_neigh, "connectRetryTimer",
9626 p->v_connect);
9627 if (p->status == Established && p->rtt)
9628 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9629 p->rtt);
9630 if (p->t_start)
9631 json_object_int_add(
9632 json_neigh, "nextStartTimerDueInMsecs",
9633 thread_timer_remain_second(p->t_start) * 1000);
9634 if (p->t_connect)
9635 json_object_int_add(
9636 json_neigh, "nextConnectTimerDueInMsecs",
9637 thread_timer_remain_second(p->t_connect)
9638 * 1000);
9639 if (p->t_routeadv) {
9640 json_object_int_add(json_neigh, "mraiInterval",
9641 p->v_routeadv);
9642 json_object_int_add(
9643 json_neigh, "mraiTimerExpireInMsecs",
9644 thread_timer_remain_second(p->t_routeadv)
9645 * 1000);
9646 }
9647 if (p->password)
9648 json_object_int_add(json_neigh, "authenticationEnabled",
9649 1);
9650
9651 if (p->t_read)
9652 json_object_string_add(json_neigh, "readThread", "on");
9653 else
9654 json_object_string_add(json_neigh, "readThread", "off");
9655 if (p->t_write)
9656 json_object_string_add(json_neigh, "writeThread", "on");
9657 else
9658 json_object_string_add(json_neigh, "writeThread",
9659 "off");
9660 } else {
9661 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9662 p->v_connect);
9663 if (p->status == Established && p->rtt)
9664 vty_out(vty, "Estimated round trip time: %d ms\n",
9665 p->rtt);
9666 if (p->t_start)
9667 vty_out(vty, "Next start timer due in %ld seconds\n",
9668 thread_timer_remain_second(p->t_start));
9669 if (p->t_connect)
9670 vty_out(vty, "Next connect timer due in %ld seconds\n",
9671 thread_timer_remain_second(p->t_connect));
9672 if (p->t_routeadv)
9673 vty_out(vty,
9674 "MRAI (interval %u) timer expires in %ld seconds\n",
9675 p->v_routeadv,
9676 thread_timer_remain_second(p->t_routeadv));
9677 if (p->password)
9678 vty_out(vty, "Peer Authentication Enabled\n");
9679
9680 vty_out(vty, "Read thread: %s Write thread: %s\n",
9681 p->t_read ? "on" : "off", p->t_write ? "on" : "off");
9682 }
9683
9684 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9685 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9686 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9687
9688 if (!use_json)
9689 vty_out(vty, "\n");
9690
9691 /* BFD information. */
9692 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9693
9694 if (use_json) {
9695 if (p->conf_if) /* Configured interface name. */
9696 json_object_object_add(json, p->conf_if, json_neigh);
9697 else /* Configured IP address. */
9698 json_object_object_add(json, p->host, json_neigh);
9699 }
9700}
9701
9702static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9703 enum show_type type, union sockunion *su,
9704 const char *conf_if, u_char use_json,
9705 json_object *json)
9706{
9707 struct listnode *node, *nnode;
9708 struct peer *peer;
9709 int find = 0;
9710
9711 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9712 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9713 continue;
9714
9715 switch (type) {
9716 case show_all:
9717 bgp_show_peer(vty, peer, use_json, json);
9718 break;
9719 case show_peer:
9720 if (conf_if) {
9721 if ((peer->conf_if
9722 && !strcmp(peer->conf_if, conf_if))
9723 || (peer->hostname
9724 && !strcmp(peer->hostname, conf_if))) {
9725 find = 1;
9726 bgp_show_peer(vty, peer, use_json,
9727 json);
9728 }
9729 } else {
9730 if (sockunion_same(&peer->su, su)) {
9731 find = 1;
9732 bgp_show_peer(vty, peer, use_json,
9733 json);
9734 }
9735 }
9736 break;
9737 }
9738 }
9739
9740 if (type == show_peer && !find) {
9741 if (use_json)
9742 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9743 else
9744 vty_out(vty, "%% No such neighbor\n");
9745 }
9746
9747 if (use_json) {
9d303b37
DL
9748 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9749 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9750 json_object_free(json);
9751 } else {
9752 vty_out(vty, "\n");
9753 }
9754
9755 return CMD_SUCCESS;
9756}
9757
9758static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9759 u_char use_json)
9760{
0291c246
MK
9761 struct listnode *node, *nnode;
9762 struct bgp *bgp;
9763 json_object *json = NULL;
9764 int is_first = 1;
d62a17ae 9765
9766 if (use_json)
9767 vty_out(vty, "{\n");
9768
9769 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9770 if (use_json) {
9771 if (!(json = json_object_new_object())) {
9772 zlog_err(
9773 "Unable to allocate memory for JSON object");
9774 vty_out(vty,
9775 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9776 return;
9777 }
9778
9779 json_object_int_add(json, "vrfId",
9780 (bgp->vrf_id == VRF_UNKNOWN)
9781 ? -1
9782 : bgp->vrf_id);
9783 json_object_string_add(
9784 json, "vrfName",
9785 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9786 ? "Default"
9787 : bgp->name);
9788
9789 if (!is_first)
9790 vty_out(vty, ",\n");
9791 else
9792 is_first = 0;
9793
9794 vty_out(vty, "\"%s\":",
9795 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9796 ? "Default"
9797 : bgp->name);
9798 } else {
9799 vty_out(vty, "\nInstance %s:\n",
9800 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9801 ? "Default"
9802 : bgp->name);
9803 }
9804 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL, use_json,
9805 json);
9806 }
9807
9808 if (use_json)
9809 vty_out(vty, "}\n");
9810}
9811
9812static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9813 enum show_type type, const char *ip_str,
9814 u_char use_json)
9815{
9816 int ret;
9817 struct bgp *bgp;
9818 union sockunion su;
9819 json_object *json = NULL;
9820
9821 if (name) {
9822 if (strmatch(name, "all")) {
9823 bgp_show_all_instances_neighbors_vty(vty, use_json);
9824 return CMD_SUCCESS;
9825 } else {
9826 bgp = bgp_lookup_by_name(name);
9827 if (!bgp) {
9828 if (use_json) {
9829 json = json_object_new_object();
9830 json_object_boolean_true_add(
9831 json, "bgpNoSuchInstance");
9832 vty_out(vty, "%s\n",
9833 json_object_to_json_string_ext(
9834 json,
9835 JSON_C_TO_STRING_PRETTY));
9836 json_object_free(json);
9837 } else
9838 vty_out(vty,
9839 "%% No such BGP instance exist\n");
9840
9841 return CMD_WARNING;
9842 }
9843 }
9844 } else {
9845 bgp = bgp_get_default();
9846 }
9847
9848 if (bgp) {
9849 json = json_object_new_object();
9850 if (ip_str) {
9851 ret = str2sockunion(ip_str, &su);
9852 if (ret < 0)
9853 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9854 use_json, json);
9855 else
9856 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9857 use_json, json);
9858 } else {
9859 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
9860 json);
9861 }
9862 json_object_free(json);
9863 }
9864
9865 return CMD_SUCCESS;
4fb25c53
DW
9866}
9867
716b2d8a 9868/* "show [ip] bgp neighbors" commands. */
718e3744 9869DEFUN (show_ip_bgp_neighbors,
9870 show_ip_bgp_neighbors_cmd,
24345e82 9871 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 9872 SHOW_STR
9873 IP_STR
9874 BGP_STR
f2a8972b 9875 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9876 "Address Family\n"
9877 "Address Family\n"
718e3744 9878 "Detailed information on TCP and BGP neighbor connections\n"
9879 "Neighbor to display information about\n"
a80beece 9880 "Neighbor to display information about\n"
91d37724 9881 "Neighbor on BGP configured interface\n"
9973d184 9882 JSON_STR)
718e3744 9883{
d62a17ae 9884 char *vrf = NULL;
9885 char *sh_arg = NULL;
9886 enum show_type sh_type;
718e3744 9887
d62a17ae 9888 u_char uj = use_json(argc, argv);
718e3744 9889
d62a17ae 9890 int idx = 0;
718e3744 9891
d62a17ae 9892 if (argv_find(argv, argc, "view", &idx)
9893 || argv_find(argv, argc, "vrf", &idx))
9894 vrf = argv[idx + 1]->arg;
718e3744 9895
d62a17ae 9896 idx++;
9897 if (argv_find(argv, argc, "A.B.C.D", &idx)
9898 || argv_find(argv, argc, "X:X::X:X", &idx)
9899 || argv_find(argv, argc, "WORD", &idx)) {
9900 sh_type = show_peer;
9901 sh_arg = argv[idx]->arg;
9902 } else
9903 sh_type = show_all;
856ca177 9904
d62a17ae 9905 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 9906}
9907
716b2d8a 9908/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 9909 paths' and `show ip mbgp paths'. Those functions results are the
9910 same.*/
f412b39a 9911DEFUN (show_ip_bgp_paths,
718e3744 9912 show_ip_bgp_paths_cmd,
46f296b4 9913 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
46f296b4 9917 BGP_SAFI_HELP_STR
718e3744 9918 "Path information\n")
9919{
d62a17ae 9920 vty_out(vty, "Address Refcnt Path\n");
9921 aspath_print_all_vty(vty);
9922 return CMD_SUCCESS;
718e3744 9923}
9924
718e3744 9925#include "hash.h"
9926
d62a17ae 9927static void community_show_all_iterator(struct hash_backet *backet,
9928 struct vty *vty)
718e3744 9929{
d62a17ae 9930 struct community *com;
718e3744 9931
d62a17ae 9932 com = (struct community *)backet->data;
3f65c5b1 9933 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
d62a17ae 9934 community_str(com));
718e3744 9935}
9936
9937/* Show BGP's community internal data. */
f412b39a 9938DEFUN (show_ip_bgp_community_info,
718e3744 9939 show_ip_bgp_community_info_cmd,
bec37ba5 9940 "show [ip] bgp community-info",
718e3744 9941 SHOW_STR
9942 IP_STR
9943 BGP_STR
9944 "List all bgp community information\n")
9945{
d62a17ae 9946 vty_out(vty, "Address Refcnt Community\n");
718e3744 9947
d62a17ae 9948 hash_iterate(community_hash(),
9949 (void (*)(struct hash_backet *,
9950 void *))community_show_all_iterator,
9951 vty);
718e3744 9952
d62a17ae 9953 return CMD_SUCCESS;
718e3744 9954}
9955
d62a17ae 9956static void lcommunity_show_all_iterator(struct hash_backet *backet,
9957 struct vty *vty)
57d187bc 9958{
d62a17ae 9959 struct lcommunity *lcom;
57d187bc 9960
d62a17ae 9961 lcom = (struct lcommunity *)backet->data;
3f65c5b1 9962 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 9963 lcommunity_str(lcom));
57d187bc
JS
9964}
9965
9966/* Show BGP's community internal data. */
9967DEFUN (show_ip_bgp_lcommunity_info,
9968 show_ip_bgp_lcommunity_info_cmd,
9969 "show ip bgp large-community-info",
9970 SHOW_STR
9971 IP_STR
9972 BGP_STR
9973 "List all bgp large-community information\n")
9974{
d62a17ae 9975 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 9976
d62a17ae 9977 hash_iterate(lcommunity_hash(),
9978 (void (*)(struct hash_backet *,
9979 void *))lcommunity_show_all_iterator,
9980 vty);
57d187bc 9981
d62a17ae 9982 return CMD_SUCCESS;
57d187bc
JS
9983}
9984
9985
f412b39a 9986DEFUN (show_ip_bgp_attr_info,
718e3744 9987 show_ip_bgp_attr_info_cmd,
bec37ba5 9988 "show [ip] bgp attribute-info",
718e3744 9989 SHOW_STR
9990 IP_STR
9991 BGP_STR
9992 "List all bgp attribute information\n")
9993{
d62a17ae 9994 attr_show_all(vty);
9995 return CMD_SUCCESS;
718e3744 9996}
6b0655a2 9997
d62a17ae 9998static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
9999 safi_t safi)
f186de26 10000{
d62a17ae 10001 struct listnode *node, *nnode;
10002 struct bgp *bgp;
f186de26 10003
d62a17ae 10004 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10005 vty_out(vty, "\nInstance %s:\n",
10006 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10007 ? "Default"
10008 : bgp->name);
10009 update_group_show(bgp, afi, safi, vty, 0);
10010 }
f186de26 10011}
10012
d62a17ae 10013static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10014 int safi, uint64_t subgrp_id)
4fb25c53 10015{
d62a17ae 10016 struct bgp *bgp;
4fb25c53 10017
d62a17ae 10018 if (name) {
10019 if (strmatch(name, "all")) {
10020 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10021 return CMD_SUCCESS;
10022 } else {
10023 bgp = bgp_lookup_by_name(name);
10024 }
10025 } else {
10026 bgp = bgp_get_default();
10027 }
4fb25c53 10028
d62a17ae 10029 if (bgp)
10030 update_group_show(bgp, afi, safi, vty, subgrp_id);
10031 return CMD_SUCCESS;
4fb25c53
DW
10032}
10033
8fe8a7f6
DS
10034DEFUN (show_ip_bgp_updgrps,
10035 show_ip_bgp_updgrps_cmd,
c1a44e43 10036 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10037 SHOW_STR
10038 IP_STR
10039 BGP_STR
10040 BGP_INSTANCE_HELP_STR
c9e571b4 10041 BGP_AFI_HELP_STR
9bedbb1e 10042 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10043 "Detailed info about dynamic update groups\n"
10044 "Specific subgroup to display detailed info for\n")
8386ac43 10045{
d62a17ae 10046 char *vrf = NULL;
10047 afi_t afi = AFI_IP6;
10048 safi_t safi = SAFI_UNICAST;
10049 uint64_t subgrp_id = 0;
10050
10051 int idx = 0;
10052
10053 /* show [ip] bgp */
10054 if (argv_find(argv, argc, "ip", &idx))
10055 afi = AFI_IP;
10056 /* [<view|vrf> VIEWVRFNAME] */
10057 if (argv_find(argv, argc, "view", &idx)
10058 || argv_find(argv, argc, "vrf", &idx))
10059 vrf = argv[++idx]->arg;
10060 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10061 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10062 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10063 }
5bf15956 10064
d62a17ae 10065 /* get subgroup id, if provided */
10066 idx = argc - 1;
10067 if (argv[idx]->type == VARIABLE_TKN)
10068 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10069
d62a17ae 10070 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10071}
10072
f186de26 10073DEFUN (show_bgp_instance_all_ipv6_updgrps,
10074 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10075 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10076 SHOW_STR
716b2d8a 10077 IP_STR
f186de26 10078 BGP_STR
10079 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10080 "Detailed info about dynamic update groups\n")
f186de26 10081{
d62a17ae 10082 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10083 return CMD_SUCCESS;
f186de26 10084}
10085
5bf15956
DW
10086DEFUN (show_bgp_updgrps_stats,
10087 show_bgp_updgrps_stats_cmd,
716b2d8a 10088 "show [ip] bgp update-groups statistics",
3f9c7369 10089 SHOW_STR
716b2d8a 10090 IP_STR
3f9c7369 10091 BGP_STR
0c7b1b01 10092 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10093 "Statistics\n")
10094{
d62a17ae 10095 struct bgp *bgp;
3f9c7369 10096
d62a17ae 10097 bgp = bgp_get_default();
10098 if (bgp)
10099 update_group_show_stats(bgp, vty);
3f9c7369 10100
d62a17ae 10101 return CMD_SUCCESS;
3f9c7369
DS
10102}
10103
8386ac43 10104DEFUN (show_bgp_instance_updgrps_stats,
10105 show_bgp_instance_updgrps_stats_cmd,
18c57037 10106 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10107 SHOW_STR
716b2d8a 10108 IP_STR
8386ac43 10109 BGP_STR
10110 BGP_INSTANCE_HELP_STR
0c7b1b01 10111 "Detailed info about dynamic update groups\n"
8386ac43 10112 "Statistics\n")
10113{
d62a17ae 10114 int idx_word = 3;
10115 struct bgp *bgp;
8386ac43 10116
d62a17ae 10117 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10118 if (bgp)
10119 update_group_show_stats(bgp, vty);
8386ac43 10120
d62a17ae 10121 return CMD_SUCCESS;
8386ac43 10122}
10123
d62a17ae 10124static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10125 afi_t afi, safi_t safi,
10126 const char *what, uint64_t subgrp_id)
3f9c7369 10127{
d62a17ae 10128 struct bgp *bgp;
8386ac43 10129
d62a17ae 10130 if (name)
10131 bgp = bgp_lookup_by_name(name);
10132 else
10133 bgp = bgp_get_default();
8386ac43 10134
d62a17ae 10135 if (bgp) {
10136 if (!strcmp(what, "advertise-queue"))
10137 update_group_show_adj_queue(bgp, afi, safi, vty,
10138 subgrp_id);
10139 else if (!strcmp(what, "advertised-routes"))
10140 update_group_show_advertised(bgp, afi, safi, vty,
10141 subgrp_id);
10142 else if (!strcmp(what, "packet-queue"))
10143 update_group_show_packet_queue(bgp, afi, safi, vty,
10144 subgrp_id);
10145 }
3f9c7369
DS
10146}
10147
10148DEFUN (show_ip_bgp_updgrps_adj,
10149 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10150 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10151 SHOW_STR
10152 IP_STR
10153 BGP_STR
0c7b1b01 10154 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10155 "Advertisement queue\n"
10156 "Announced routes\n"
10157 "Packet queue\n")
10158{
d62a17ae 10159 int idx_type = 4;
10160 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10161 argv[idx_type]->arg, 0);
10162 return CMD_SUCCESS;
8386ac43 10163}
10164
10165DEFUN (show_ip_bgp_instance_updgrps_adj,
10166 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10167 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10168 SHOW_STR
10169 IP_STR
10170 BGP_STR
10171 BGP_INSTANCE_HELP_STR
0c7b1b01 10172 "Detailed info about dynamic update groups\n"
8386ac43 10173 "Advertisement queue\n"
10174 "Announced routes\n"
10175 "Packet queue\n")
8386ac43 10176{
d62a17ae 10177 int idx_word = 4;
10178 int idx_type = 6;
10179 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10180 SAFI_UNICAST, argv[idx_type]->arg, 0);
10181 return CMD_SUCCESS;
3f9c7369
DS
10182}
10183
10184DEFUN (show_bgp_updgrps_afi_adj,
10185 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10186 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10187 SHOW_STR
716b2d8a 10188 IP_STR
3f9c7369 10189 BGP_STR
46f296b4 10190 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10191 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10192 "Advertisement queue\n"
10193 "Announced routes\n"
7111c1a0 10194 "Packet queue\n")
3f9c7369 10195{
d62a17ae 10196 int idx_afi = 2;
10197 int idx_safi = 3;
10198 int idx_type = 5;
10199 show_bgp_updgrps_adj_info_aux(
10200 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10201 bgp_vty_safi_from_str(argv[idx_safi]->text),
10202 argv[idx_type]->arg, 0);
10203 return CMD_SUCCESS;
3f9c7369
DS
10204}
10205
10206DEFUN (show_bgp_updgrps_adj,
10207 show_bgp_updgrps_adj_cmd,
716b2d8a 10208 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10209 SHOW_STR
716b2d8a 10210 IP_STR
3f9c7369 10211 BGP_STR
0c7b1b01 10212 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10213 "Advertisement queue\n"
10214 "Announced routes\n"
10215 "Packet queue\n")
10216{
d62a17ae 10217 int idx_type = 3;
10218 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10219 argv[idx_type]->arg, 0);
10220 return CMD_SUCCESS;
8386ac43 10221}
10222
10223DEFUN (show_bgp_instance_updgrps_adj,
10224 show_bgp_instance_updgrps_adj_cmd,
18c57037 10225 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10226 SHOW_STR
716b2d8a 10227 IP_STR
8386ac43 10228 BGP_STR
10229 BGP_INSTANCE_HELP_STR
0c7b1b01 10230 "Detailed info about dynamic update groups\n"
8386ac43 10231 "Advertisement queue\n"
10232 "Announced routes\n"
10233 "Packet queue\n")
10234{
d62a17ae 10235 int idx_word = 3;
10236 int idx_type = 5;
10237 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10238 SAFI_UNICAST, argv[idx_type]->arg, 0);
10239 return CMD_SUCCESS;
3f9c7369
DS
10240}
10241
10242DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10243 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10244 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10245 SHOW_STR
10246 IP_STR
10247 BGP_STR
0c7b1b01 10248 "Detailed info about dynamic update groups\n"
8fe8a7f6 10249 "Specific subgroup to display info for\n"
3f9c7369
DS
10250 "Advertisement queue\n"
10251 "Announced routes\n"
10252 "Packet queue\n")
3f9c7369 10253{
d62a17ae 10254 int idx_subgroup_id = 4;
10255 int idx_type = 5;
10256 uint64_t subgrp_id;
8fe8a7f6 10257
d62a17ae 10258 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10259
d62a17ae 10260 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10261 argv[idx_type]->arg, subgrp_id);
10262 return CMD_SUCCESS;
8386ac43 10263}
10264
10265DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10266 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10267 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10268 SHOW_STR
10269 IP_STR
10270 BGP_STR
10271 BGP_INSTANCE_HELP_STR
0c7b1b01 10272 "Detailed info about dynamic update groups\n"
8386ac43 10273 "Specific subgroup to display info for\n"
10274 "Advertisement queue\n"
10275 "Announced routes\n"
10276 "Packet queue\n")
8386ac43 10277{
d62a17ae 10278 int idx_vrf = 4;
10279 int idx_subgroup_id = 6;
10280 int idx_type = 7;
10281 uint64_t subgrp_id;
8386ac43 10282
d62a17ae 10283 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10284
d62a17ae 10285 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10286 SAFI_UNICAST, argv[idx_type]->arg,
10287 subgrp_id);
10288 return CMD_SUCCESS;
3f9c7369
DS
10289}
10290
8fe8a7f6
DS
10291DEFUN (show_bgp_updgrps_afi_adj_s,
10292 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10293 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10294 SHOW_STR
716b2d8a 10295 IP_STR
3f9c7369 10296 BGP_STR
46f296b4 10297 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10298 "Detailed info about dynamic update groups\n"
8fe8a7f6 10299 "Specific subgroup to display info for\n"
3f9c7369
DS
10300 "Advertisement queue\n"
10301 "Announced routes\n"
7111c1a0 10302 "Packet queue\n")
3f9c7369 10303{
d62a17ae 10304 int idx_afi = 2;
10305 int idx_safi = 3;
10306 int idx_subgroup_id = 5;
10307 int idx_type = 6;
10308 uint64_t subgrp_id;
3f9c7369 10309
d62a17ae 10310 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10311
d62a17ae 10312 show_bgp_updgrps_adj_info_aux(
10313 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10314 bgp_vty_safi_from_str(argv[idx_safi]->text),
10315 argv[idx_type]->arg, subgrp_id);
10316 return CMD_SUCCESS;
3f9c7369
DS
10317}
10318
8fe8a7f6
DS
10319DEFUN (show_bgp_updgrps_adj_s,
10320 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10321 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10322 SHOW_STR
716b2d8a 10323 IP_STR
8fe8a7f6 10324 BGP_STR
0c7b1b01 10325 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10326 "Specific subgroup to display info for\n"
10327 "Advertisement queue\n"
10328 "Announced routes\n"
10329 "Packet queue\n")
10330{
d62a17ae 10331 int idx_subgroup_id = 3;
10332 int idx_type = 4;
10333 uint64_t subgrp_id;
8fe8a7f6 10334
d62a17ae 10335 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10336
d62a17ae 10337 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10338 argv[idx_type]->arg, subgrp_id);
10339 return CMD_SUCCESS;
8fe8a7f6
DS
10340}
10341
8386ac43 10342DEFUN (show_bgp_instance_updgrps_adj_s,
10343 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10344 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10345 SHOW_STR
716b2d8a 10346 IP_STR
8386ac43 10347 BGP_STR
10348 BGP_INSTANCE_HELP_STR
0c7b1b01 10349 "Detailed info about dynamic update groups\n"
8386ac43 10350 "Specific subgroup to display info for\n"
10351 "Advertisement queue\n"
10352 "Announced routes\n"
10353 "Packet queue\n")
10354{
d62a17ae 10355 int idx_vrf = 3;
10356 int idx_subgroup_id = 5;
10357 int idx_type = 6;
10358 uint64_t subgrp_id;
10359
10360 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10361
10362 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10363 SAFI_UNICAST, argv[idx_type]->arg,
10364 subgrp_id);
10365 return CMD_SUCCESS;
10366}
10367
10368
10369static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10370{
10371 struct listnode *node, *nnode;
10372 struct prefix *range;
10373 struct peer *conf;
10374 struct peer *peer;
10375 char buf[PREFIX2STR_BUFFER];
10376 afi_t afi;
10377 safi_t safi;
10378 const char *peer_status;
10379 const char *af_str;
10380 int lr_count;
10381 int dynamic;
10382 int af_cfgd;
10383
10384 conf = group->conf;
10385
10386 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10387 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10388 conf->as);
10389 } else if (conf->as_type == AS_INTERNAL) {
10390 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10391 group->bgp->as);
10392 } else {
10393 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10394 }
f14e6fdb 10395
d62a17ae 10396 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10397 vty_out(vty, " Peer-group type is internal\n");
10398 else
10399 vty_out(vty, " Peer-group type is external\n");
10400
10401 /* Display AFs configured. */
10402 vty_out(vty, " Configured address-families:");
10403 for (afi = AFI_IP; afi < AFI_MAX; afi++)
10404 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
10405 if (conf->afc[afi][safi]) {
10406 af_cfgd = 1;
10407 vty_out(vty, " %s;", afi_safi_print(afi, safi));
10408 }
10409 }
10410 if (!af_cfgd)
10411 vty_out(vty, " none\n");
10412 else
10413 vty_out(vty, "\n");
10414
10415 /* Display listen ranges (for dynamic neighbors), if any */
10416 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10417 if (afi == AFI_IP)
10418 af_str = "IPv4";
10419 else if (afi == AFI_IP6)
10420 af_str = "IPv6";
10421 else
10422 af_str = "???";
10423 lr_count = listcount(group->listen_range[afi]);
10424 if (lr_count) {
10425 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10426 af_str);
10427
10428
10429 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10430 nnode, range)) {
10431 prefix2str(range, buf, sizeof(buf));
10432 vty_out(vty, " %s\n", buf);
10433 }
10434 }
10435 }
f14e6fdb 10436
d62a17ae 10437 /* Display group members and their status */
10438 if (listcount(group->peer)) {
10439 vty_out(vty, " Peer-group members:\n");
10440 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10441 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10442 peer_status = "Idle (Admin)";
10443 else if (CHECK_FLAG(peer->sflags,
10444 PEER_STATUS_PREFIX_OVERFLOW))
10445 peer_status = "Idle (PfxCt)";
10446 else
10447 peer_status = lookup_msg(bgp_status_msg,
10448 peer->status, NULL);
10449
10450 dynamic = peer_dynamic_neighbor(peer);
10451 vty_out(vty, " %s %s %s \n", peer->host,
10452 dynamic ? "(dynamic)" : "", peer_status);
10453 }
10454 }
f14e6fdb 10455
d62a17ae 10456 return CMD_SUCCESS;
10457}
10458
10459/* Show BGP peer group's information. */
10460enum show_group_type { show_all_groups, show_peer_group };
10461
10462static int bgp_show_peer_group(struct vty *vty, struct bgp *bgp,
10463 enum show_group_type type,
10464 const char *group_name)
10465{
10466 struct listnode *node, *nnode;
10467 struct peer_group *group;
10468 int find = 0;
10469
10470 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
10471 switch (type) {
10472 case show_all_groups:
10473 bgp_show_one_peer_group(vty, group);
10474 break;
10475 case show_peer_group:
10476 if (group_name
10477 && (strcmp(group->name, group_name) == 0)) {
10478 find = 1;
10479 bgp_show_one_peer_group(vty, group);
10480 }
10481 break;
10482 }
f14e6fdb 10483 }
f14e6fdb 10484
d62a17ae 10485 if (type == show_peer_group && !find)
10486 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10487
d62a17ae 10488 return CMD_SUCCESS;
f14e6fdb
DS
10489}
10490
d62a17ae 10491static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10492 enum show_group_type type,
10493 const char *group_name)
f14e6fdb 10494{
d62a17ae 10495 struct bgp *bgp;
10496 int ret = CMD_SUCCESS;
f14e6fdb 10497
d62a17ae 10498 if (name)
10499 bgp = bgp_lookup_by_name(name);
10500 else
10501 bgp = bgp_get_default();
f14e6fdb 10502
d62a17ae 10503 if (!bgp) {
10504 vty_out(vty, "%% No such BGP instance exist\n");
10505 return CMD_WARNING;
10506 }
f14e6fdb 10507
d62a17ae 10508 ret = bgp_show_peer_group(vty, bgp, type, group_name);
f14e6fdb 10509
d62a17ae 10510 return ret;
f14e6fdb
DS
10511}
10512
10513DEFUN (show_ip_bgp_peer_groups,
10514 show_ip_bgp_peer_groups_cmd,
18c57037 10515 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10516 SHOW_STR
10517 IP_STR
10518 BGP_STR
8386ac43 10519 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10520 "Detailed information on BGP peer groups\n"
10521 "Peer group name\n")
f14e6fdb 10522{
d62a17ae 10523 char *vrf, *pg;
10524 vrf = pg = NULL;
10525 int idx = 0;
f14e6fdb 10526
d62a17ae 10527 vrf = argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
10528 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10529
d62a17ae 10530 return bgp_show_peer_group_vty(vty, vrf, show_all_groups, pg);
f14e6fdb 10531}
3f9c7369 10532
d6e3c605 10533
718e3744 10534/* Redistribute VTY commands. */
10535
718e3744 10536DEFUN (bgp_redistribute_ipv4,
10537 bgp_redistribute_ipv4_cmd,
40d1cbfb 10538 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10539 "Redistribute information from another routing protocol\n"
ab0181ee 10540 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10541{
d62a17ae 10542 VTY_DECLVAR_CONTEXT(bgp, bgp);
10543 int idx_protocol = 1;
10544 int type;
718e3744 10545
d62a17ae 10546 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10547 if (type < 0) {
10548 vty_out(vty, "%% Invalid route type\n");
10549 return CMD_WARNING_CONFIG_FAILED;
10550 }
7f323236 10551
d62a17ae 10552 bgp_redist_add(bgp, AFI_IP, type, 0);
10553 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10554}
10555
d62a17ae 10556ALIAS_HIDDEN(
10557 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10558 "redistribute " FRR_IP_REDIST_STR_BGPD,
10559 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10560
718e3744 10561DEFUN (bgp_redistribute_ipv4_rmap,
10562 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10563 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10564 "Redistribute information from another routing protocol\n"
ab0181ee 10565 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10566 "Route map reference\n"
10567 "Pointer to route-map entries\n")
10568{
d62a17ae 10569 VTY_DECLVAR_CONTEXT(bgp, bgp);
10570 int idx_protocol = 1;
10571 int idx_word = 3;
10572 int type;
10573 struct bgp_redist *red;
718e3744 10574
d62a17ae 10575 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10576 if (type < 0) {
10577 vty_out(vty, "%% Invalid route type\n");
10578 return CMD_WARNING_CONFIG_FAILED;
10579 }
718e3744 10580
d62a17ae 10581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10582 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10583 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10584}
10585
d62a17ae 10586ALIAS_HIDDEN(
10587 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10588 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10589 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10590 "Route map reference\n"
10591 "Pointer to route-map entries\n")
596c17ba 10592
718e3744 10593DEFUN (bgp_redistribute_ipv4_metric,
10594 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10595 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10596 "Redistribute information from another routing protocol\n"
ab0181ee 10597 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10598 "Metric for redistributed routes\n"
10599 "Default metric\n")
10600{
d62a17ae 10601 VTY_DECLVAR_CONTEXT(bgp, bgp);
10602 int idx_protocol = 1;
10603 int idx_number = 3;
10604 int type;
10605 u_int32_t metric;
10606 struct bgp_redist *red;
10607
10608 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10609 if (type < 0) {
10610 vty_out(vty, "%% Invalid route type\n");
10611 return CMD_WARNING_CONFIG_FAILED;
10612 }
10613 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10614
10615 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10616 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10617 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10618}
10619
10620ALIAS_HIDDEN(
10621 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10622 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10623 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10624 "Metric for redistributed routes\n"
10625 "Default metric\n")
596c17ba 10626
718e3744 10627DEFUN (bgp_redistribute_ipv4_rmap_metric,
10628 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10629 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10630 "Redistribute information from another routing protocol\n"
ab0181ee 10631 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10632 "Route map reference\n"
10633 "Pointer to route-map entries\n"
10634 "Metric for redistributed routes\n"
10635 "Default metric\n")
10636{
d62a17ae 10637 VTY_DECLVAR_CONTEXT(bgp, bgp);
10638 int idx_protocol = 1;
10639 int idx_word = 3;
10640 int idx_number = 5;
10641 int type;
10642 u_int32_t metric;
10643 struct bgp_redist *red;
10644
10645 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10646 if (type < 0) {
10647 vty_out(vty, "%% Invalid route type\n");
10648 return CMD_WARNING_CONFIG_FAILED;
10649 }
10650 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10651
10652 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10653 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10654 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10655 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10656}
10657
10658ALIAS_HIDDEN(
10659 bgp_redistribute_ipv4_rmap_metric,
10660 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10661 "redistribute " FRR_IP_REDIST_STR_BGPD
10662 " route-map WORD metric (0-4294967295)",
10663 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10664 "Route map reference\n"
10665 "Pointer to route-map entries\n"
10666 "Metric for redistributed routes\n"
10667 "Default metric\n")
596c17ba 10668
718e3744 10669DEFUN (bgp_redistribute_ipv4_metric_rmap,
10670 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10671 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10672 "Redistribute information from another routing protocol\n"
ab0181ee 10673 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10674 "Metric for redistributed routes\n"
10675 "Default metric\n"
10676 "Route map reference\n"
10677 "Pointer to route-map entries\n")
10678{
d62a17ae 10679 VTY_DECLVAR_CONTEXT(bgp, bgp);
10680 int idx_protocol = 1;
10681 int idx_number = 3;
10682 int idx_word = 5;
10683 int type;
10684 u_int32_t metric;
10685 struct bgp_redist *red;
10686
10687 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10688 if (type < 0) {
10689 vty_out(vty, "%% Invalid route type\n");
10690 return CMD_WARNING_CONFIG_FAILED;
10691 }
10692 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10693
10694 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10695 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10696 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10697 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10698}
10699
10700ALIAS_HIDDEN(
10701 bgp_redistribute_ipv4_metric_rmap,
10702 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10703 "redistribute " FRR_IP_REDIST_STR_BGPD
10704 " metric (0-4294967295) route-map WORD",
10705 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10706 "Metric for redistributed routes\n"
10707 "Default metric\n"
10708 "Route map reference\n"
10709 "Pointer to route-map entries\n")
596c17ba 10710
7c8ff89e
DS
10711DEFUN (bgp_redistribute_ipv4_ospf,
10712 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10713 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10714 "Redistribute information from another routing protocol\n"
10715 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10716 "Non-main Kernel Routing Table\n"
10717 "Instance ID/Table ID\n")
7c8ff89e 10718{
d62a17ae 10719 VTY_DECLVAR_CONTEXT(bgp, bgp);
10720 int idx_ospf_table = 1;
10721 int idx_number = 2;
10722 u_short instance;
10723 u_short protocol;
7c8ff89e 10724
d62a17ae 10725 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10726
d62a17ae 10727 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10728 protocol = ZEBRA_ROUTE_OSPF;
10729 else
10730 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10731
d62a17ae 10732 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10733 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10734}
10735
d62a17ae 10736ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10737 "redistribute <ospf|table> (1-65535)",
10738 "Redistribute information from another routing protocol\n"
10739 "Open Shortest Path First (OSPFv2)\n"
10740 "Non-main Kernel Routing Table\n"
10741 "Instance ID/Table ID\n")
596c17ba 10742
7c8ff89e
DS
10743DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10744 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10745 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10746 "Redistribute information from another routing protocol\n"
10747 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10748 "Non-main Kernel Routing Table\n"
10749 "Instance ID/Table ID\n"
7c8ff89e
DS
10750 "Route map reference\n"
10751 "Pointer to route-map entries\n")
10752{
d62a17ae 10753 VTY_DECLVAR_CONTEXT(bgp, bgp);
10754 int idx_ospf_table = 1;
10755 int idx_number = 2;
10756 int idx_word = 4;
10757 struct bgp_redist *red;
10758 u_short instance;
10759 int protocol;
10760
10761 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10762 protocol = ZEBRA_ROUTE_OSPF;
10763 else
10764 protocol = ZEBRA_ROUTE_TABLE;
10765
10766 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10767 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10768 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10769 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10770}
10771
10772ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10773 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10774 "redistribute <ospf|table> (1-65535) route-map WORD",
10775 "Redistribute information from another routing protocol\n"
10776 "Open Shortest Path First (OSPFv2)\n"
10777 "Non-main Kernel Routing Table\n"
10778 "Instance ID/Table ID\n"
10779 "Route map reference\n"
10780 "Pointer to route-map entries\n")
596c17ba 10781
7c8ff89e
DS
10782DEFUN (bgp_redistribute_ipv4_ospf_metric,
10783 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10784 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10785 "Redistribute information from another routing protocol\n"
10786 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10787 "Non-main Kernel Routing Table\n"
10788 "Instance ID/Table ID\n"
7c8ff89e
DS
10789 "Metric for redistributed routes\n"
10790 "Default metric\n")
10791{
d62a17ae 10792 VTY_DECLVAR_CONTEXT(bgp, bgp);
10793 int idx_ospf_table = 1;
10794 int idx_number = 2;
10795 int idx_number_2 = 4;
10796 u_int32_t metric;
10797 struct bgp_redist *red;
10798 u_short instance;
10799 int protocol;
10800
10801 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10802 protocol = ZEBRA_ROUTE_OSPF;
10803 else
10804 protocol = ZEBRA_ROUTE_TABLE;
10805
10806 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10807 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10808
10809 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10810 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10811 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10812}
10813
10814ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10815 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10816 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10817 "Redistribute information from another routing protocol\n"
10818 "Open Shortest Path First (OSPFv2)\n"
10819 "Non-main Kernel Routing Table\n"
10820 "Instance ID/Table ID\n"
10821 "Metric for redistributed routes\n"
10822 "Default metric\n")
596c17ba 10823
7c8ff89e
DS
10824DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10825 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10826 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10827 "Redistribute information from another routing protocol\n"
10828 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10829 "Non-main Kernel Routing Table\n"
10830 "Instance ID/Table ID\n"
7c8ff89e
DS
10831 "Route map reference\n"
10832 "Pointer to route-map entries\n"
10833 "Metric for redistributed routes\n"
10834 "Default metric\n")
10835{
d62a17ae 10836 VTY_DECLVAR_CONTEXT(bgp, bgp);
10837 int idx_ospf_table = 1;
10838 int idx_number = 2;
10839 int idx_word = 4;
10840 int idx_number_2 = 6;
10841 u_int32_t metric;
10842 struct bgp_redist *red;
10843 u_short instance;
10844 int protocol;
10845
10846 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10847 protocol = ZEBRA_ROUTE_OSPF;
10848 else
10849 protocol = ZEBRA_ROUTE_TABLE;
10850
10851 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10852 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10853
10854 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10855 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10856 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10857 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10858}
10859
10860ALIAS_HIDDEN(
10861 bgp_redistribute_ipv4_ospf_rmap_metric,
10862 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10863 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10864 "Redistribute information from another routing protocol\n"
10865 "Open Shortest Path First (OSPFv2)\n"
10866 "Non-main Kernel Routing Table\n"
10867 "Instance ID/Table ID\n"
10868 "Route map reference\n"
10869 "Pointer to route-map entries\n"
10870 "Metric for redistributed routes\n"
10871 "Default metric\n")
596c17ba 10872
7c8ff89e
DS
10873DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10874 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10875 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10876 "Redistribute information from another routing protocol\n"
10877 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10878 "Non-main Kernel Routing Table\n"
10879 "Instance ID/Table ID\n"
7c8ff89e
DS
10880 "Metric for redistributed routes\n"
10881 "Default metric\n"
10882 "Route map reference\n"
10883 "Pointer to route-map entries\n")
10884{
d62a17ae 10885 VTY_DECLVAR_CONTEXT(bgp, bgp);
10886 int idx_ospf_table = 1;
10887 int idx_number = 2;
10888 int idx_number_2 = 4;
10889 int idx_word = 6;
10890 u_int32_t metric;
10891 struct bgp_redist *red;
10892 u_short instance;
10893 int protocol;
10894
10895 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10896 protocol = ZEBRA_ROUTE_OSPF;
10897 else
10898 protocol = ZEBRA_ROUTE_TABLE;
10899
10900 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10901 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10902
10903 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10904 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10905 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10906 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10907}
10908
10909ALIAS_HIDDEN(
10910 bgp_redistribute_ipv4_ospf_metric_rmap,
10911 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10912 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10913 "Redistribute information from another routing protocol\n"
10914 "Open Shortest Path First (OSPFv2)\n"
10915 "Non-main Kernel Routing Table\n"
10916 "Instance ID/Table ID\n"
10917 "Metric for redistributed routes\n"
10918 "Default metric\n"
10919 "Route map reference\n"
10920 "Pointer to route-map entries\n")
596c17ba 10921
7c8ff89e
DS
10922DEFUN (no_bgp_redistribute_ipv4_ospf,
10923 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 10924 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
10925 NO_STR
10926 "Redistribute information from another routing protocol\n"
10927 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 10928 "Non-main Kernel Routing Table\n"
31500417
DW
10929 "Instance ID/Table ID\n"
10930 "Metric for redistributed routes\n"
10931 "Default metric\n"
10932 "Route map reference\n"
10933 "Pointer to route-map entries\n")
7c8ff89e 10934{
d62a17ae 10935 VTY_DECLVAR_CONTEXT(bgp, bgp);
10936 int idx_ospf_table = 2;
10937 int idx_number = 3;
10938 u_short instance;
10939 int protocol;
10940
10941 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10942 protocol = ZEBRA_ROUTE_OSPF;
10943 else
10944 protocol = ZEBRA_ROUTE_TABLE;
10945
10946 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10947 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
10948}
10949
10950ALIAS_HIDDEN(
10951 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
10952 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10953 NO_STR
10954 "Redistribute information from another routing protocol\n"
10955 "Open Shortest Path First (OSPFv2)\n"
10956 "Non-main Kernel Routing Table\n"
10957 "Instance ID/Table ID\n"
10958 "Metric for redistributed routes\n"
10959 "Default metric\n"
10960 "Route map reference\n"
10961 "Pointer to route-map entries\n")
596c17ba 10962
718e3744 10963DEFUN (no_bgp_redistribute_ipv4,
10964 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 10965 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 10966 NO_STR
10967 "Redistribute information from another routing protocol\n"
3b14d86e 10968 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
10969 "Metric for redistributed routes\n"
10970 "Default metric\n"
10971 "Route map reference\n"
10972 "Pointer to route-map entries\n")
718e3744 10973{
d62a17ae 10974 VTY_DECLVAR_CONTEXT(bgp, bgp);
10975 int idx_protocol = 2;
10976 int type;
10977
10978 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10979 if (type < 0) {
10980 vty_out(vty, "%% Invalid route type\n");
10981 return CMD_WARNING_CONFIG_FAILED;
10982 }
10983 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
10984}
10985
10986ALIAS_HIDDEN(
10987 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
10988 "no redistribute " FRR_IP_REDIST_STR_BGPD
10989 " [metric (0-4294967295)] [route-map WORD]",
10990 NO_STR
10991 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10992 "Metric for redistributed routes\n"
10993 "Default metric\n"
10994 "Route map reference\n"
10995 "Pointer to route-map entries\n")
596c17ba 10996
718e3744 10997DEFUN (bgp_redistribute_ipv6,
10998 bgp_redistribute_ipv6_cmd,
40d1cbfb 10999 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11000 "Redistribute information from another routing protocol\n"
ab0181ee 11001 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11002{
d62a17ae 11003 VTY_DECLVAR_CONTEXT(bgp, bgp);
11004 int idx_protocol = 1;
11005 int type;
718e3744 11006
d62a17ae 11007 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11008 if (type < 0) {
11009 vty_out(vty, "%% Invalid route type\n");
11010 return CMD_WARNING_CONFIG_FAILED;
11011 }
718e3744 11012
d62a17ae 11013 bgp_redist_add(bgp, AFI_IP6, type, 0);
11014 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11015}
11016
11017DEFUN (bgp_redistribute_ipv6_rmap,
11018 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11019 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11020 "Redistribute information from another routing protocol\n"
ab0181ee 11021 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11022 "Route map reference\n"
11023 "Pointer to route-map entries\n")
11024{
d62a17ae 11025 VTY_DECLVAR_CONTEXT(bgp, bgp);
11026 int idx_protocol = 1;
11027 int idx_word = 3;
11028 int type;
11029 struct bgp_redist *red;
718e3744 11030
d62a17ae 11031 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11032 if (type < 0) {
11033 vty_out(vty, "%% Invalid route type\n");
11034 return CMD_WARNING_CONFIG_FAILED;
11035 }
718e3744 11036
d62a17ae 11037 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11038 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11039 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11040}
11041
11042DEFUN (bgp_redistribute_ipv6_metric,
11043 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11044 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11045 "Redistribute information from another routing protocol\n"
ab0181ee 11046 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11047 "Metric for redistributed routes\n"
11048 "Default metric\n")
11049{
d62a17ae 11050 VTY_DECLVAR_CONTEXT(bgp, bgp);
11051 int idx_protocol = 1;
11052 int idx_number = 3;
11053 int type;
11054 u_int32_t metric;
11055 struct bgp_redist *red;
11056
11057 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11058 if (type < 0) {
11059 vty_out(vty, "%% Invalid route type\n");
11060 return CMD_WARNING_CONFIG_FAILED;
11061 }
11062 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11063
d62a17ae 11064 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11065 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11066 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11067}
11068
11069DEFUN (bgp_redistribute_ipv6_rmap_metric,
11070 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11071 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11072 "Redistribute information from another routing protocol\n"
ab0181ee 11073 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11074 "Route map reference\n"
11075 "Pointer to route-map entries\n"
11076 "Metric for redistributed routes\n"
11077 "Default metric\n")
11078{
d62a17ae 11079 VTY_DECLVAR_CONTEXT(bgp, bgp);
11080 int idx_protocol = 1;
11081 int idx_word = 3;
11082 int idx_number = 5;
11083 int type;
11084 u_int32_t metric;
11085 struct bgp_redist *red;
11086
11087 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11088 if (type < 0) {
11089 vty_out(vty, "%% Invalid route type\n");
11090 return CMD_WARNING_CONFIG_FAILED;
11091 }
11092 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11093
d62a17ae 11094 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11095 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11096 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11097 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11098}
11099
11100DEFUN (bgp_redistribute_ipv6_metric_rmap,
11101 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11102 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11103 "Redistribute information from another routing protocol\n"
ab0181ee 11104 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11105 "Metric for redistributed routes\n"
11106 "Default metric\n"
11107 "Route map reference\n"
11108 "Pointer to route-map entries\n")
11109{
d62a17ae 11110 VTY_DECLVAR_CONTEXT(bgp, bgp);
11111 int idx_protocol = 1;
11112 int idx_number = 3;
11113 int idx_word = 5;
11114 int type;
11115 u_int32_t metric;
11116 struct bgp_redist *red;
11117
11118 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11119 if (type < 0) {
11120 vty_out(vty, "%% Invalid route type\n");
11121 return CMD_WARNING_CONFIG_FAILED;
11122 }
11123 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11124
d62a17ae 11125 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11126 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11127 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11128 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11129}
11130
11131DEFUN (no_bgp_redistribute_ipv6,
11132 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11133 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11134 NO_STR
11135 "Redistribute information from another routing protocol\n"
3b14d86e 11136 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11137 "Metric for redistributed routes\n"
11138 "Default metric\n"
11139 "Route map reference\n"
11140 "Pointer to route-map entries\n")
718e3744 11141{
d62a17ae 11142 VTY_DECLVAR_CONTEXT(bgp, bgp);
11143 int idx_protocol = 2;
11144 int type;
718e3744 11145
d62a17ae 11146 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11147 if (type < 0) {
11148 vty_out(vty, "%% Invalid route type\n");
11149 return CMD_WARNING_CONFIG_FAILED;
11150 }
718e3744 11151
d62a17ae 11152 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11153}
11154
2b791107 11155void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11156 safi_t safi)
d62a17ae 11157{
11158 int i;
11159
11160 /* Unicast redistribution only. */
11161 if (safi != SAFI_UNICAST)
2b791107 11162 return;
d62a17ae 11163
11164 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11165 /* Redistribute BGP does not make sense. */
11166 if (i != ZEBRA_ROUTE_BGP) {
11167 struct list *red_list;
11168 struct listnode *node;
11169 struct bgp_redist *red;
11170
11171 red_list = bgp->redist[afi][i];
11172 if (!red_list)
11173 continue;
11174
11175 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11176 /* "redistribute" configuration. */
11177 vty_out(vty, " redistribute %s",
11178 zebra_route_string(i));
11179 if (red->instance)
11180 vty_out(vty, " %d", red->instance);
11181 if (red->redist_metric_flag)
11182 vty_out(vty, " metric %u",
11183 red->redist_metric);
11184 if (red->rmap.name)
11185 vty_out(vty, " route-map %s",
11186 red->rmap.name);
11187 vty_out(vty, "\n");
11188 }
11189 }
11190 }
718e3744 11191}
6b0655a2 11192
718e3744 11193/* BGP node structure. */
d62a17ae 11194static struct cmd_node bgp_node = {
9d303b37 11195 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11196};
11197
d62a17ae 11198static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11199 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11200};
11201
d62a17ae 11202static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11203 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11204};
11205
d62a17ae 11206static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11207 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11208};
11209
d62a17ae 11210static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11211 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11212};
11213
d62a17ae 11214static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11215 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11216};
11217
d62a17ae 11218static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11219 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11220};
11221
d62a17ae 11222static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11223 "%s(config-router-af)# ", 1};
6b0655a2 11224
d62a17ae 11225static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11226 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11227
d62a17ae 11228static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11229 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11230
d62a17ae 11231static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11232 "%s(config-router-af-vni)# ", 1};
90e60aa7 11233
d62a17ae 11234static void community_list_vty(void);
1f8ae70b 11235
d62a17ae 11236static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11237{
d62a17ae 11238 struct bgp *bgp;
11239 struct peer *peer;
11240 struct peer_group *group;
11241 struct listnode *lnbgp, *lnpeer;
b8a815e5 11242
d62a17ae 11243 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11244 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11245 /* only provide suggestions on the appropriate input
11246 * token type,
11247 * they'll otherwise show up multiple times */
11248 enum cmd_token_type match_type;
11249 char *name = peer->host;
d48ed3e0 11250
d62a17ae 11251 if (peer->conf_if) {
11252 match_type = VARIABLE_TKN;
11253 name = peer->conf_if;
11254 } else if (strchr(peer->host, ':'))
11255 match_type = IPV6_TKN;
11256 else
11257 match_type = IPV4_TKN;
d48ed3e0 11258
d62a17ae 11259 if (token->type != match_type)
11260 continue;
d48ed3e0 11261
d62a17ae 11262 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11263 }
d48ed3e0 11264
d62a17ae 11265 if (token->type == VARIABLE_TKN)
11266 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11267 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11268 group->name));
11269 }
b8a815e5
DL
11270}
11271
11272static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11273 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11274 {.varname = "neighbors", .completions = bgp_ac_neighbor},
11275 {.completions = NULL}};
11276
11277void bgp_vty_init(void)
11278{
11279 cmd_variable_handler_register(bgp_var_neighbor);
11280
11281 /* Install bgp top node. */
11282 install_node(&bgp_node, bgp_config_write);
11283 install_node(&bgp_ipv4_unicast_node, NULL);
11284 install_node(&bgp_ipv4_multicast_node, NULL);
11285 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11286 install_node(&bgp_ipv6_unicast_node, NULL);
11287 install_node(&bgp_ipv6_multicast_node, NULL);
11288 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11289 install_node(&bgp_vpnv4_node, NULL);
11290 install_node(&bgp_vpnv6_node, NULL);
11291 install_node(&bgp_evpn_node, NULL);
11292 install_node(&bgp_evpn_vni_node, NULL);
11293
11294 /* Install default VTY commands to new nodes. */
11295 install_default(BGP_NODE);
11296 install_default(BGP_IPV4_NODE);
11297 install_default(BGP_IPV4M_NODE);
11298 install_default(BGP_IPV4L_NODE);
11299 install_default(BGP_IPV6_NODE);
11300 install_default(BGP_IPV6M_NODE);
11301 install_default(BGP_IPV6L_NODE);
11302 install_default(BGP_VPNV4_NODE);
11303 install_default(BGP_VPNV6_NODE);
11304 install_default(BGP_EVPN_NODE);
11305 install_default(BGP_EVPN_VNI_NODE);
11306
11307 /* "bgp multiple-instance" commands. */
11308 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11309 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11310
11311 /* "bgp config-type" commands. */
11312 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11313 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11314
11315 /* bgp route-map delay-timer commands. */
11316 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11317 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11318
11319 /* Dummy commands (Currently not supported) */
11320 install_element(BGP_NODE, &no_synchronization_cmd);
11321 install_element(BGP_NODE, &no_auto_summary_cmd);
11322
11323 /* "router bgp" commands. */
11324 install_element(CONFIG_NODE, &router_bgp_cmd);
11325
11326 /* "no router bgp" commands. */
11327 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11328
11329 /* "bgp router-id" commands. */
11330 install_element(BGP_NODE, &bgp_router_id_cmd);
11331 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11332
11333 /* "bgp cluster-id" commands. */
11334 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11335 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11336
11337 /* "bgp confederation" commands. */
11338 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11339 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11340
11341 /* "bgp confederation peers" commands. */
11342 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11343 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11344
11345 /* bgp max-med command */
11346 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11347 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11348 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11349 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11350 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11351
11352 /* bgp disable-ebgp-connected-nh-check */
11353 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11354 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11355
11356 /* bgp update-delay command */
11357 install_element(BGP_NODE, &bgp_update_delay_cmd);
11358 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11359 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11360
11361 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11362 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11363
11364 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11365 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11366
11367 /* "maximum-paths" commands. */
11368 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11369 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11370 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11371 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11372 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11373 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11374 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11375 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11376 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11377 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11378 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11379 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11380 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11381 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11382 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11383
11384 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11385 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11386 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11387 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11388 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11389
11390 /* "timers bgp" commands. */
11391 install_element(BGP_NODE, &bgp_timers_cmd);
11392 install_element(BGP_NODE, &no_bgp_timers_cmd);
11393
11394 /* route-map delay-timer commands - per instance for backwards compat.
11395 */
11396 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11397 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11398
11399 /* "bgp client-to-client reflection" commands */
11400 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11401 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11402
11403 /* "bgp always-compare-med" commands */
11404 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11405 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11406
11407 /* "bgp deterministic-med" commands */
11408 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11409 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11410
11411 /* "bgp graceful-restart" commands */
11412 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11413 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11414 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11415 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11416 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11417 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11418
11419 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11420 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11421
7f323236
DW
11422 /* "bgp graceful-shutdown" commands */
11423 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11424 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11425
d62a17ae 11426 /* "bgp fast-external-failover" commands */
11427 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11428 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11429
11430 /* "bgp enforce-first-as" commands */
11431 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11432 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11433
11434 /* "bgp bestpath compare-routerid" commands */
11435 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11436 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11437
11438 /* "bgp bestpath as-path ignore" commands */
11439 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11440 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11441
11442 /* "bgp bestpath as-path confed" commands */
11443 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11444 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11445
11446 /* "bgp bestpath as-path multipath-relax" commands */
11447 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11448 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11449
11450 /* "bgp log-neighbor-changes" commands */
11451 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11452 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11453
11454 /* "bgp bestpath med" commands */
11455 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11456 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11457
11458 /* "no bgp default ipv4-unicast" commands. */
11459 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11460 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11461
11462 /* "bgp network import-check" commands. */
11463 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11464 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11465 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11466
11467 /* "bgp default local-preference" commands. */
11468 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11469 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11470
11471 /* bgp default show-hostname */
11472 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11473 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11474
11475 /* "bgp default subgroup-pkt-queue-max" commands. */
11476 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11477 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11478
11479 /* bgp ibgp-allow-policy-mods command */
11480 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11481 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11482
11483 /* "bgp listen limit" commands. */
11484 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11485 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11486
11487 /* "bgp listen range" commands. */
11488 install_element(BGP_NODE, &bgp_listen_range_cmd);
11489 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11490
11491 /* "neighbor remote-as" commands. */
11492 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11493 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11494 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11495 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11496 install_element(BGP_NODE,
11497 &neighbor_interface_v6only_config_remote_as_cmd);
11498 install_element(BGP_NODE, &no_neighbor_cmd);
11499 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11500
11501 /* "neighbor peer-group" commands. */
11502 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11503 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11504 install_element(BGP_NODE,
11505 &no_neighbor_interface_peer_group_remote_as_cmd);
11506
11507 /* "neighbor local-as" commands. */
11508 install_element(BGP_NODE, &neighbor_local_as_cmd);
11509 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11510 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11511 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11512
11513 /* "neighbor solo" commands. */
11514 install_element(BGP_NODE, &neighbor_solo_cmd);
11515 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11516
11517 /* "neighbor password" commands. */
11518 install_element(BGP_NODE, &neighbor_password_cmd);
11519 install_element(BGP_NODE, &no_neighbor_password_cmd);
11520
11521 /* "neighbor activate" commands. */
11522 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11523 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11524 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11525 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11526 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11527 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11528 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11529 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11530 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11531 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11532
11533 /* "no neighbor activate" commands. */
11534 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11535 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11536 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11537 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11538 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11539 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11540 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11541 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11542 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11543 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11544
11545 /* "neighbor peer-group" set commands. */
11546 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11547 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11548 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11549 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11550 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11551 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11552 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11553 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11554
11555 /* "no neighbor peer-group unset" commands. */
11556 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11557 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11558 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11559 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11560 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11561 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11562 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11563 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11564
11565 /* "neighbor softreconfiguration inbound" commands.*/
11566 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11567 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11568 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11569 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11570 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11571 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11572 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11573 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11574 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11575 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11576 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11577 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11578 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11579 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11580 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11581 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11582 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11583 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11584
11585 /* "neighbor attribute-unchanged" commands. */
11586 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11587 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11588 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11589 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11590 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11591 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11592 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11593 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11594 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11595 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11596 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11597 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11598 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11599 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11600 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11601 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11602 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11603 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11604
11605 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11606 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11607
11608 /* "nexthop-local unchanged" commands */
11609 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11610 install_element(BGP_IPV6_NODE,
11611 &no_neighbor_nexthop_local_unchanged_cmd);
11612
11613 /* "neighbor next-hop-self" commands. */
11614 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11615 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11616 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11617 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11618 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11619 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11620 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11621 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11622 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11623 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11624 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11625 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11626 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11627 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11628 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11629 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11630 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11631 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11632
11633 /* "neighbor next-hop-self force" commands. */
11634 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11635 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11636 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11637 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11638 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11639 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11640 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11641 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11642 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11643 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11644 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11645 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11646 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11647 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11648 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11649 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11650 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11651 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11652
11653 /* "neighbor as-override" commands. */
11654 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11655 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11656 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11657 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11658 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11659 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11660 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11661 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11662 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11663 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11664 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11665 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11666 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11667 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11668 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11669 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11670 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11671 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11672
11673 /* "neighbor remove-private-AS" commands. */
11674 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11675 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11676 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11677 install_element(BGP_NODE,
11678 &no_neighbor_remove_private_as_all_hidden_cmd);
11679 install_element(BGP_NODE,
11680 &neighbor_remove_private_as_replace_as_hidden_cmd);
11681 install_element(BGP_NODE,
11682 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11683 install_element(BGP_NODE,
11684 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11685 install_element(
11686 BGP_NODE,
11687 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11688 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11689 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11690 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11691 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11692 install_element(BGP_IPV4_NODE,
11693 &neighbor_remove_private_as_replace_as_cmd);
11694 install_element(BGP_IPV4_NODE,
11695 &no_neighbor_remove_private_as_replace_as_cmd);
11696 install_element(BGP_IPV4_NODE,
11697 &neighbor_remove_private_as_all_replace_as_cmd);
11698 install_element(BGP_IPV4_NODE,
11699 &no_neighbor_remove_private_as_all_replace_as_cmd);
11700 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11701 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11702 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11703 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11704 install_element(BGP_IPV4M_NODE,
11705 &neighbor_remove_private_as_replace_as_cmd);
11706 install_element(BGP_IPV4M_NODE,
11707 &no_neighbor_remove_private_as_replace_as_cmd);
11708 install_element(BGP_IPV4M_NODE,
11709 &neighbor_remove_private_as_all_replace_as_cmd);
11710 install_element(BGP_IPV4M_NODE,
11711 &no_neighbor_remove_private_as_all_replace_as_cmd);
11712 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11713 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11714 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11715 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11716 install_element(BGP_IPV4L_NODE,
11717 &neighbor_remove_private_as_replace_as_cmd);
11718 install_element(BGP_IPV4L_NODE,
11719 &no_neighbor_remove_private_as_replace_as_cmd);
11720 install_element(BGP_IPV4L_NODE,
11721 &neighbor_remove_private_as_all_replace_as_cmd);
11722 install_element(BGP_IPV4L_NODE,
11723 &no_neighbor_remove_private_as_all_replace_as_cmd);
11724 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11725 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11726 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11727 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11728 install_element(BGP_IPV6_NODE,
11729 &neighbor_remove_private_as_replace_as_cmd);
11730 install_element(BGP_IPV6_NODE,
11731 &no_neighbor_remove_private_as_replace_as_cmd);
11732 install_element(BGP_IPV6_NODE,
11733 &neighbor_remove_private_as_all_replace_as_cmd);
11734 install_element(BGP_IPV6_NODE,
11735 &no_neighbor_remove_private_as_all_replace_as_cmd);
11736 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11737 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11738 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11739 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11740 install_element(BGP_IPV6M_NODE,
11741 &neighbor_remove_private_as_replace_as_cmd);
11742 install_element(BGP_IPV6M_NODE,
11743 &no_neighbor_remove_private_as_replace_as_cmd);
11744 install_element(BGP_IPV6M_NODE,
11745 &neighbor_remove_private_as_all_replace_as_cmd);
11746 install_element(BGP_IPV6M_NODE,
11747 &no_neighbor_remove_private_as_all_replace_as_cmd);
11748 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11749 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11750 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11751 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11752 install_element(BGP_IPV6L_NODE,
11753 &neighbor_remove_private_as_replace_as_cmd);
11754 install_element(BGP_IPV6L_NODE,
11755 &no_neighbor_remove_private_as_replace_as_cmd);
11756 install_element(BGP_IPV6L_NODE,
11757 &neighbor_remove_private_as_all_replace_as_cmd);
11758 install_element(BGP_IPV6L_NODE,
11759 &no_neighbor_remove_private_as_all_replace_as_cmd);
11760 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11761 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11762 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11763 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11764 install_element(BGP_VPNV4_NODE,
11765 &neighbor_remove_private_as_replace_as_cmd);
11766 install_element(BGP_VPNV4_NODE,
11767 &no_neighbor_remove_private_as_replace_as_cmd);
11768 install_element(BGP_VPNV4_NODE,
11769 &neighbor_remove_private_as_all_replace_as_cmd);
11770 install_element(BGP_VPNV4_NODE,
11771 &no_neighbor_remove_private_as_all_replace_as_cmd);
11772 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11773 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11774 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11775 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11776 install_element(BGP_VPNV6_NODE,
11777 &neighbor_remove_private_as_replace_as_cmd);
11778 install_element(BGP_VPNV6_NODE,
11779 &no_neighbor_remove_private_as_replace_as_cmd);
11780 install_element(BGP_VPNV6_NODE,
11781 &neighbor_remove_private_as_all_replace_as_cmd);
11782 install_element(BGP_VPNV6_NODE,
11783 &no_neighbor_remove_private_as_all_replace_as_cmd);
11784
11785 /* "neighbor send-community" commands.*/
11786 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11787 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11788 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11789 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11790 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11791 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11792 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11793 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11794 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11795 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11796 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11797 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11798 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11799 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11800 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11801 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11802 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11803 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11804 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11805 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11806 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11807 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11808 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11809 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11810 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11811 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11812 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11813 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11814 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11815 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11816 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11817 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11818 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11819 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11820 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11821 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11822
11823 /* "neighbor route-reflector" commands.*/
11824 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11825 install_element(BGP_NODE,
11826 &no_neighbor_route_reflector_client_hidden_cmd);
11827 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11828 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11829 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11830 install_element(BGP_IPV4M_NODE,
11831 &no_neighbor_route_reflector_client_cmd);
11832 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11833 install_element(BGP_IPV4L_NODE,
11834 &no_neighbor_route_reflector_client_cmd);
11835 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11836 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11837 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11838 install_element(BGP_IPV6M_NODE,
11839 &no_neighbor_route_reflector_client_cmd);
11840 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11841 install_element(BGP_IPV6L_NODE,
11842 &no_neighbor_route_reflector_client_cmd);
11843 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11844 install_element(BGP_VPNV4_NODE,
11845 &no_neighbor_route_reflector_client_cmd);
11846 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11847 install_element(BGP_VPNV6_NODE,
11848 &no_neighbor_route_reflector_client_cmd);
11849 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11850 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11851
11852 /* "neighbor route-server" commands.*/
11853 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11854 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11855 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11856 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11857 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11858 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11859 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11860 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11861 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11862 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11863 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11864 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11865 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11866 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11867 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11868 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11869 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11870 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11871
11872 /* "neighbor addpath-tx-all-paths" commands.*/
11873 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11874 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11875 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11876 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11877 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11878 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11879 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11880 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11881 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11882 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11883 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11884 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11885 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11886 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11887 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11888 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11889 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11890 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11891
11892 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11893 install_element(BGP_NODE,
11894 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11895 install_element(BGP_NODE,
11896 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11897 install_element(BGP_IPV4_NODE,
11898 &neighbor_addpath_tx_bestpath_per_as_cmd);
11899 install_element(BGP_IPV4_NODE,
11900 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11901 install_element(BGP_IPV4M_NODE,
11902 &neighbor_addpath_tx_bestpath_per_as_cmd);
11903 install_element(BGP_IPV4M_NODE,
11904 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11905 install_element(BGP_IPV4L_NODE,
11906 &neighbor_addpath_tx_bestpath_per_as_cmd);
11907 install_element(BGP_IPV4L_NODE,
11908 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11909 install_element(BGP_IPV6_NODE,
11910 &neighbor_addpath_tx_bestpath_per_as_cmd);
11911 install_element(BGP_IPV6_NODE,
11912 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11913 install_element(BGP_IPV6M_NODE,
11914 &neighbor_addpath_tx_bestpath_per_as_cmd);
11915 install_element(BGP_IPV6M_NODE,
11916 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11917 install_element(BGP_IPV6L_NODE,
11918 &neighbor_addpath_tx_bestpath_per_as_cmd);
11919 install_element(BGP_IPV6L_NODE,
11920 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11921 install_element(BGP_VPNV4_NODE,
11922 &neighbor_addpath_tx_bestpath_per_as_cmd);
11923 install_element(BGP_VPNV4_NODE,
11924 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11925 install_element(BGP_VPNV6_NODE,
11926 &neighbor_addpath_tx_bestpath_per_as_cmd);
11927 install_element(BGP_VPNV6_NODE,
11928 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11929
11930 /* "neighbor passive" commands. */
11931 install_element(BGP_NODE, &neighbor_passive_cmd);
11932 install_element(BGP_NODE, &no_neighbor_passive_cmd);
11933
11934
11935 /* "neighbor shutdown" commands. */
11936 install_element(BGP_NODE, &neighbor_shutdown_cmd);
11937 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
11938 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
11939 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
11940
11941 /* "neighbor capability extended-nexthop" commands.*/
11942 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
11943 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
11944
11945 /* "neighbor capability orf prefix-list" commands.*/
11946 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
11947 install_element(BGP_NODE,
11948 &no_neighbor_capability_orf_prefix_hidden_cmd);
11949 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
11950 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
11951 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
11952 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11953 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
11954 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11955 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
11956 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
11957 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
11958 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11959 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
11960 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11961
11962 /* "neighbor capability dynamic" commands.*/
11963 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
11964 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
11965
11966 /* "neighbor dont-capability-negotiate" commands. */
11967 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
11968 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
11969
11970 /* "neighbor ebgp-multihop" commands. */
11971 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
11972 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
11973 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
11974
11975 /* "neighbor disable-connected-check" commands. */
11976 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
11977 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
11978
11979 /* "neighbor description" commands. */
11980 install_element(BGP_NODE, &neighbor_description_cmd);
11981 install_element(BGP_NODE, &no_neighbor_description_cmd);
11982
11983 /* "neighbor update-source" commands. "*/
11984 install_element(BGP_NODE, &neighbor_update_source_cmd);
11985 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
11986
11987 /* "neighbor default-originate" commands. */
11988 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
11989 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
11990 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
11991 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
11992 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
11993 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
11994 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
11995 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
11996 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
11997 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
11998 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
11999 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12000 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12001 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12002 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12003 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12004 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12005 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12006 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12007 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12008 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12009
12010 /* "neighbor port" commands. */
12011 install_element(BGP_NODE, &neighbor_port_cmd);
12012 install_element(BGP_NODE, &no_neighbor_port_cmd);
12013
12014 /* "neighbor weight" commands. */
12015 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12016 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12017
12018 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12019 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12020 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12021 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12022 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12023 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12024 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12025 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12026 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12027 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12028 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12029 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12030 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12031 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12032 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12033 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12034
12035 /* "neighbor override-capability" commands. */
12036 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12037 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12038
12039 /* "neighbor strict-capability-match" commands. */
12040 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12041 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12042
12043 /* "neighbor timers" commands. */
12044 install_element(BGP_NODE, &neighbor_timers_cmd);
12045 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12046
12047 /* "neighbor timers connect" commands. */
12048 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12049 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12050
12051 /* "neighbor advertisement-interval" commands. */
12052 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12053 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12054
12055 /* "neighbor interface" commands. */
12056 install_element(BGP_NODE, &neighbor_interface_cmd);
12057 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12058
12059 /* "neighbor distribute" commands. */
12060 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12061 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12062 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12063 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12064 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12065 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12066 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12067 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12068 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12069 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12070 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12071 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12072 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12073 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12074 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12075 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12076 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12077 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12078
12079 /* "neighbor prefix-list" commands. */
12080 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12081 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12082 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12083 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12084 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12085 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12086 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12087 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12088 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12089 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12090 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12091 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12092 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12093 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12094 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12095 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12096 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12097 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12098
12099 /* "neighbor filter-list" commands. */
12100 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12101 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12102 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12103 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12104 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12105 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12106 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12107 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12108 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12109 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12110 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12111 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12112 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12113 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12114 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12115 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12116 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12117 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12118
12119 /* "neighbor route-map" commands. */
12120 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12121 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12122 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12123 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12124 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12125 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12126 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12127 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12128 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12129 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12130 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12131 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12132 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12133 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12134 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12135 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12136 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12137 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12138 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12139 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12140
12141 /* "neighbor unsuppress-map" commands. */
12142 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12143 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12144 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12145 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12146 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12147 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12148 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12149 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12150 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12151 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12152 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12153 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12154 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12155 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12156 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12157 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12158 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12159 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12160
12161 /* "neighbor maximum-prefix" commands. */
12162 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12163 install_element(BGP_NODE,
12164 &neighbor_maximum_prefix_threshold_hidden_cmd);
12165 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12166 install_element(BGP_NODE,
12167 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12168 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12169 install_element(BGP_NODE,
12170 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12171 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12172 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12173 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12174 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12175 install_element(BGP_IPV4_NODE,
12176 &neighbor_maximum_prefix_threshold_warning_cmd);
12177 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12178 install_element(BGP_IPV4_NODE,
12179 &neighbor_maximum_prefix_threshold_restart_cmd);
12180 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12181 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12182 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12183 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12184 install_element(BGP_IPV4M_NODE,
12185 &neighbor_maximum_prefix_threshold_warning_cmd);
12186 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12187 install_element(BGP_IPV4M_NODE,
12188 &neighbor_maximum_prefix_threshold_restart_cmd);
12189 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12190 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12191 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12192 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12193 install_element(BGP_IPV4L_NODE,
12194 &neighbor_maximum_prefix_threshold_warning_cmd);
12195 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12196 install_element(BGP_IPV4L_NODE,
12197 &neighbor_maximum_prefix_threshold_restart_cmd);
12198 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12199 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12200 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12201 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12202 install_element(BGP_IPV6_NODE,
12203 &neighbor_maximum_prefix_threshold_warning_cmd);
12204 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12205 install_element(BGP_IPV6_NODE,
12206 &neighbor_maximum_prefix_threshold_restart_cmd);
12207 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12208 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12209 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12210 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12211 install_element(BGP_IPV6M_NODE,
12212 &neighbor_maximum_prefix_threshold_warning_cmd);
12213 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12214 install_element(BGP_IPV6M_NODE,
12215 &neighbor_maximum_prefix_threshold_restart_cmd);
12216 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12217 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12218 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12219 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12220 install_element(BGP_IPV6L_NODE,
12221 &neighbor_maximum_prefix_threshold_warning_cmd);
12222 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12223 install_element(BGP_IPV6L_NODE,
12224 &neighbor_maximum_prefix_threshold_restart_cmd);
12225 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12226 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12227 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12228 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12229 install_element(BGP_VPNV4_NODE,
12230 &neighbor_maximum_prefix_threshold_warning_cmd);
12231 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12232 install_element(BGP_VPNV4_NODE,
12233 &neighbor_maximum_prefix_threshold_restart_cmd);
12234 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12235 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12236 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12237 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12238 install_element(BGP_VPNV6_NODE,
12239 &neighbor_maximum_prefix_threshold_warning_cmd);
12240 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12241 install_element(BGP_VPNV6_NODE,
12242 &neighbor_maximum_prefix_threshold_restart_cmd);
12243 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12244
12245 /* "neighbor allowas-in" */
12246 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12247 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12248 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12249 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12250 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12251 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12252 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12253 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12254 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12255 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12256 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12257 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12258 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12259 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12260 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12261 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12262 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12263 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12264 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12265 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12266
12267 /* address-family commands. */
12268 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12269 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12270#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12271 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12272 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12273#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12274
d62a17ae 12275 install_element(BGP_NODE, &address_family_evpn_cmd);
12276
12277 /* "exit-address-family" command. */
12278 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12279 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12280 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12281 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12282 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12283 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12284 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12285 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12286 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12287
12288 /* "clear ip bgp commands" */
12289 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12290
12291 /* clear ip bgp prefix */
12292 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12293 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12294 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12295
12296 /* "show [ip] bgp summary" commands. */
12297 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12298 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12299 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12300 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12301 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12302 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12303 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12304 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12305 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12306 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12307 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12308 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12309 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12310 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12311 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12312
12313 /* "show [ip] bgp neighbors" commands. */
12314 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12315
12316 /* "show [ip] bgp peer-group" commands. */
12317 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12318
12319 /* "show [ip] bgp paths" commands. */
12320 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12321
12322 /* "show [ip] bgp community" commands. */
12323 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12324
12325 /* "show ip bgp large-community" commands. */
12326 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12327 /* "show [ip] bgp attribute-info" commands. */
12328 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12329
12330 /* "redistribute" commands. */
12331 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12332 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12333 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12334 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12335 install_element(BGP_NODE,
12336 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12337 install_element(BGP_NODE,
12338 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12339 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12340 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12341 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12342 install_element(BGP_NODE,
12343 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12344 install_element(BGP_NODE,
12345 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12346 install_element(BGP_NODE,
12347 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12348 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12349 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12350 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12351 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12352 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12353 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12354 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12355 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12356 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12357 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12358 install_element(BGP_IPV4_NODE,
12359 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12360 install_element(BGP_IPV4_NODE,
12361 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12362 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12363 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12364 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12365 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12366 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12367 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12368
12369 /* ttl_security commands */
12370 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12371 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12372
12373 /* "show [ip] bgp memory" commands. */
12374 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12375
acf71666
MK
12376 /* "show bgp martian next-hop" */
12377 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12378
d62a17ae 12379 /* "show [ip] bgp views" commands. */
12380 install_element(VIEW_NODE, &show_bgp_views_cmd);
12381
12382 /* "show [ip] bgp vrfs" commands. */
12383 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12384
12385 /* Community-list. */
12386 community_list_vty();
718e3744 12387}
6b0655a2 12388
718e3744 12389#include "memory.h"
12390#include "bgp_regex.h"
12391#include "bgp_clist.h"
12392#include "bgp_ecommunity.h"
12393
12394/* VTY functions. */
12395
12396/* Direction value to string conversion. */
d62a17ae 12397static const char *community_direct_str(int direct)
12398{
12399 switch (direct) {
12400 case COMMUNITY_DENY:
12401 return "deny";
12402 case COMMUNITY_PERMIT:
12403 return "permit";
12404 default:
12405 return "unknown";
12406 }
718e3744 12407}
12408
12409/* Display error string. */
d62a17ae 12410static void community_list_perror(struct vty *vty, int ret)
12411{
12412 switch (ret) {
12413 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12414 vty_out(vty, "%% Can't find community-list\n");
12415 break;
12416 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12417 vty_out(vty, "%% Malformed community-list value\n");
12418 break;
12419 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12420 vty_out(vty,
12421 "%% Community name conflict, previously defined as standard community\n");
12422 break;
12423 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12424 vty_out(vty,
12425 "%% Community name conflict, previously defined as expanded community\n");
12426 break;
12427 }
718e3744 12428}
12429
5bf15956
DW
12430/* "community-list" keyword help string. */
12431#define COMMUNITY_LIST_STR "Add a community list entry\n"
12432
5bf15956 12433/* ip community-list standard */
718e3744 12434DEFUN (ip_community_list_standard,
12435 ip_community_list_standard_cmd,
e961923c 12436 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12437 IP_STR
12438 COMMUNITY_LIST_STR
12439 "Community list number (standard)\n"
5bf15956 12440 "Add an standard community-list entry\n"
718e3744 12441 "Community list name\n"
12442 "Specify community to reject\n"
12443 "Specify community to accept\n"
12444 COMMUNITY_VAL_STR)
12445{
d62a17ae 12446 char *cl_name_or_number = NULL;
12447 int direct = 0;
12448 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12449
d62a17ae 12450 int idx = 0;
12451 argv_find(argv, argc, "(1-99)", &idx);
12452 argv_find(argv, argc, "WORD", &idx);
12453 cl_name_or_number = argv[idx]->arg;
12454 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12455 : COMMUNITY_DENY;
12456 argv_find(argv, argc, "AA:NN", &idx);
12457 char *str = argv_concat(argv, argc, idx);
42f914d4 12458
d62a17ae 12459 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12460 style);
42f914d4 12461
d62a17ae 12462 XFREE(MTYPE_TMP, str);
42f914d4 12463
d62a17ae 12464 if (ret < 0) {
12465 /* Display error string. */
12466 community_list_perror(vty, ret);
12467 return CMD_WARNING_CONFIG_FAILED;
12468 }
42f914d4 12469
d62a17ae 12470 return CMD_SUCCESS;
718e3744 12471}
12472
fee6e4e4 12473DEFUN (no_ip_community_list_standard_all,
12474 no_ip_community_list_standard_all_cmd,
e961923c 12475 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12476 NO_STR
12477 IP_STR
12478 COMMUNITY_LIST_STR
12479 "Community list number (standard)\n"
5bf15956
DW
12480 "Add an standard community-list entry\n"
12481 "Community list name\n"
718e3744 12482 "Specify community to reject\n"
12483 "Specify community to accept\n"
12484 COMMUNITY_VAL_STR)
12485{
d62a17ae 12486 int delete_all = 0;
42f914d4 12487
d62a17ae 12488 char *cl_name_or_number = NULL;
12489 int direct = 0;
12490 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12491
d62a17ae 12492 int idx = 0;
12493 argv_find(argv, argc, "(1-99)", &idx);
12494 argv_find(argv, argc, "WORD", &idx);
12495 cl_name_or_number = argv[idx]->arg;
12496 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12497 : COMMUNITY_DENY;
12498 argv_find(argv, argc, "AA:NN", &idx);
12499 char *str = argv_concat(argv, argc, idx);
42f914d4 12500
d62a17ae 12501 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12502 direct, style, delete_all);
42f914d4 12503
d62a17ae 12504 XFREE(MTYPE_TMP, str);
daf9ddbb 12505
d62a17ae 12506 if (ret < 0) {
12507 community_list_perror(vty, ret);
12508 return CMD_WARNING_CONFIG_FAILED;
12509 }
42f914d4 12510
d62a17ae 12511 return CMD_SUCCESS;
718e3744 12512}
12513
5bf15956
DW
12514/* ip community-list expanded */
12515DEFUN (ip_community_list_expanded_all,
12516 ip_community_list_expanded_all_cmd,
42f914d4 12517 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12518 IP_STR
12519 COMMUNITY_LIST_STR
12520 "Community list number (expanded)\n"
5bf15956 12521 "Add an expanded community-list entry\n"
718e3744 12522 "Community list name\n"
12523 "Specify community to reject\n"
12524 "Specify community to accept\n"
12525 COMMUNITY_VAL_STR)
12526{
d62a17ae 12527 char *cl_name_or_number = NULL;
12528 int direct = 0;
12529 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12530
d62a17ae 12531 int idx = 0;
12532 argv_find(argv, argc, "(100-500)", &idx);
12533 argv_find(argv, argc, "WORD", &idx);
12534 cl_name_or_number = argv[idx]->arg;
12535 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12536 : COMMUNITY_DENY;
12537 argv_find(argv, argc, "AA:NN", &idx);
12538 char *str = argv_concat(argv, argc, idx);
42f914d4 12539
d62a17ae 12540 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12541 style);
42f914d4 12542
d62a17ae 12543 XFREE(MTYPE_TMP, str);
42f914d4 12544
d62a17ae 12545 if (ret < 0) {
12546 /* Display error string. */
12547 community_list_perror(vty, ret);
12548 return CMD_WARNING_CONFIG_FAILED;
12549 }
42f914d4 12550
d62a17ae 12551 return CMD_SUCCESS;
718e3744 12552}
12553
5bf15956
DW
12554DEFUN (no_ip_community_list_expanded_all,
12555 no_ip_community_list_expanded_all_cmd,
42f914d4 12556 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12557 NO_STR
12558 IP_STR
12559 COMMUNITY_LIST_STR
5bf15956
DW
12560 "Community list number (expanded)\n"
12561 "Add an expanded community-list entry\n"
718e3744 12562 "Community list name\n"
12563 "Specify community to reject\n"
12564 "Specify community to accept\n"
5bf15956 12565 COMMUNITY_VAL_STR)
718e3744 12566{
d62a17ae 12567 int delete_all = 0;
42f914d4 12568
d62a17ae 12569 char *cl_name_or_number = NULL;
12570 int direct = 0;
12571 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12572
d62a17ae 12573 int idx = 0;
12574 argv_find(argv, argc, "(100-500)", &idx);
12575 argv_find(argv, argc, "WORD", &idx);
12576 cl_name_or_number = argv[idx]->arg;
12577 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12578 : COMMUNITY_DENY;
12579 argv_find(argv, argc, "AA:NN", &idx);
12580 char *str = argv_concat(argv, argc, idx);
42f914d4 12581
d62a17ae 12582 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12583 direct, style, delete_all);
42f914d4 12584
d62a17ae 12585 XFREE(MTYPE_TMP, str);
daf9ddbb 12586
d62a17ae 12587 if (ret < 0) {
12588 community_list_perror(vty, ret);
12589 return CMD_WARNING_CONFIG_FAILED;
12590 }
42f914d4 12591
d62a17ae 12592 return CMD_SUCCESS;
718e3744 12593}
12594
d62a17ae 12595static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12596{
d62a17ae 12597 struct community_entry *entry;
718e3744 12598
d62a17ae 12599 for (entry = list->head; entry; entry = entry->next) {
12600 if (entry == list->head) {
12601 if (all_digit(list->name))
12602 vty_out(vty, "Community %s list %s\n",
12603 entry->style == COMMUNITY_LIST_STANDARD
12604 ? "standard"
12605 : "(expanded) access",
12606 list->name);
12607 else
12608 vty_out(vty, "Named Community %s list %s\n",
12609 entry->style == COMMUNITY_LIST_STANDARD
12610 ? "standard"
12611 : "expanded",
12612 list->name);
12613 }
12614 if (entry->any)
12615 vty_out(vty, " %s\n",
12616 community_direct_str(entry->direct));
12617 else
12618 vty_out(vty, " %s %s\n",
12619 community_direct_str(entry->direct),
12620 entry->style == COMMUNITY_LIST_STANDARD
12621 ? community_str(entry->u.com)
12622 : entry->config);
12623 }
718e3744 12624}
12625
12626DEFUN (show_ip_community_list,
12627 show_ip_community_list_cmd,
12628 "show ip community-list",
12629 SHOW_STR
12630 IP_STR
12631 "List community-list\n")
12632{
d62a17ae 12633 struct community_list *list;
12634 struct community_list_master *cm;
718e3744 12635
d62a17ae 12636 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12637 if (!cm)
12638 return CMD_SUCCESS;
718e3744 12639
d62a17ae 12640 for (list = cm->num.head; list; list = list->next)
12641 community_list_show(vty, list);
718e3744 12642
d62a17ae 12643 for (list = cm->str.head; list; list = list->next)
12644 community_list_show(vty, list);
718e3744 12645
d62a17ae 12646 return CMD_SUCCESS;
718e3744 12647}
12648
12649DEFUN (show_ip_community_list_arg,
12650 show_ip_community_list_arg_cmd,
6147e2c6 12651 "show ip community-list <(1-500)|WORD>",
718e3744 12652 SHOW_STR
12653 IP_STR
12654 "List community-list\n"
12655 "Community-list number\n"
12656 "Community-list name\n")
12657{
d62a17ae 12658 int idx_comm_list = 3;
12659 struct community_list *list;
718e3744 12660
d62a17ae 12661 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12662 COMMUNITY_LIST_MASTER);
12663 if (!list) {
12664 vty_out(vty, "%% Can't find community-list\n");
12665 return CMD_WARNING;
12666 }
718e3744 12667
d62a17ae 12668 community_list_show(vty, list);
718e3744 12669
d62a17ae 12670 return CMD_SUCCESS;
718e3744 12671}
6b0655a2 12672
57d187bc
JS
12673/*
12674 * Large Community code.
12675 */
d62a17ae 12676static int lcommunity_list_set_vty(struct vty *vty, int argc,
12677 struct cmd_token **argv, int style,
12678 int reject_all_digit_name)
12679{
12680 int ret;
12681 int direct;
12682 char *str;
12683 int idx = 0;
12684 char *cl_name;
12685
12686 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12687 : COMMUNITY_DENY;
12688
12689 /* All digit name check. */
12690 idx = 0;
12691 argv_find(argv, argc, "WORD", &idx);
12692 argv_find(argv, argc, "(1-99)", &idx);
12693 argv_find(argv, argc, "(100-500)", &idx);
12694 cl_name = argv[idx]->arg;
12695 if (reject_all_digit_name && all_digit(cl_name)) {
12696 vty_out(vty, "%% Community name cannot have all digits\n");
12697 return CMD_WARNING_CONFIG_FAILED;
12698 }
12699
12700 idx = 0;
12701 argv_find(argv, argc, "AA:BB:CC", &idx);
12702 argv_find(argv, argc, "LINE", &idx);
12703 /* Concat community string argument. */
12704 if (idx)
12705 str = argv_concat(argv, argc, idx);
12706 else
12707 str = NULL;
12708
12709 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12710
12711 /* Free temporary community list string allocated by
12712 argv_concat(). */
12713 if (str)
12714 XFREE(MTYPE_TMP, str);
12715
12716 if (ret < 0) {
12717 community_list_perror(vty, ret);
12718 return CMD_WARNING_CONFIG_FAILED;
12719 }
12720 return CMD_SUCCESS;
12721}
12722
12723static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12724 struct cmd_token **argv, int style)
12725{
12726 int ret;
12727 int direct = 0;
12728 char *str = NULL;
12729 int idx = 0;
12730
12731 argv_find(argv, argc, "permit", &idx);
12732 argv_find(argv, argc, "deny", &idx);
12733
12734 if (idx) {
12735 /* Check the list direct. */
12736 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12737 direct = COMMUNITY_PERMIT;
12738 else
12739 direct = COMMUNITY_DENY;
12740
12741 idx = 0;
12742 argv_find(argv, argc, "LINE", &idx);
12743 argv_find(argv, argc, "AA:AA:NN", &idx);
12744 /* Concat community string argument. */
12745 str = argv_concat(argv, argc, idx);
12746 }
12747
12748 idx = 0;
12749 argv_find(argv, argc, "(1-99)", &idx);
12750 argv_find(argv, argc, "(100-500)", &idx);
12751 argv_find(argv, argc, "WORD", &idx);
12752
12753 /* Unset community list. */
12754 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12755 style);
12756
12757 /* Free temporary community list string allocated by
12758 argv_concat(). */
12759 if (str)
12760 XFREE(MTYPE_TMP, str);
12761
12762 if (ret < 0) {
12763 community_list_perror(vty, ret);
12764 return CMD_WARNING_CONFIG_FAILED;
12765 }
12766
12767 return CMD_SUCCESS;
57d187bc
JS
12768}
12769
12770/* "large-community-list" keyword help string. */
12771#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12772#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12773
12774DEFUN (ip_lcommunity_list_standard,
12775 ip_lcommunity_list_standard_cmd,
52951b63
DS
12776 "ip large-community-list (1-99) <deny|permit>",
12777 IP_STR
12778 LCOMMUNITY_LIST_STR
12779 "Large Community list number (standard)\n"
12780 "Specify large community to reject\n"
7111c1a0 12781 "Specify large community to accept\n")
52951b63 12782{
d62a17ae 12783 return lcommunity_list_set_vty(vty, argc, argv,
12784 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12785}
12786
12787DEFUN (ip_lcommunity_list_standard1,
12788 ip_lcommunity_list_standard1_cmd,
12789 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12790 IP_STR
12791 LCOMMUNITY_LIST_STR
12792 "Large Community list number (standard)\n"
12793 "Specify large community to reject\n"
12794 "Specify large community to accept\n"
12795 LCOMMUNITY_VAL_STR)
12796{
d62a17ae 12797 return lcommunity_list_set_vty(vty, argc, argv,
12798 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12799}
12800
12801DEFUN (ip_lcommunity_list_expanded,
12802 ip_lcommunity_list_expanded_cmd,
12803 "ip large-community-list (100-500) <deny|permit> LINE...",
12804 IP_STR
12805 LCOMMUNITY_LIST_STR
12806 "Large Community list number (expanded)\n"
12807 "Specify large community to reject\n"
12808 "Specify large community to accept\n"
12809 "An ordered list as a regular-expression\n")
12810{
d62a17ae 12811 return lcommunity_list_set_vty(vty, argc, argv,
12812 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12813}
12814
12815DEFUN (ip_lcommunity_list_name_standard,
12816 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12817 "ip large-community-list standard WORD <deny|permit>",
12818 IP_STR
12819 LCOMMUNITY_LIST_STR
12820 "Specify standard large-community-list\n"
12821 "Large Community list name\n"
12822 "Specify large community to reject\n"
12823 "Specify large community to accept\n")
12824{
d62a17ae 12825 return lcommunity_list_set_vty(vty, argc, argv,
12826 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12827}
12828
12829DEFUN (ip_lcommunity_list_name_standard1,
12830 ip_lcommunity_list_name_standard1_cmd,
12831 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12832 IP_STR
12833 LCOMMUNITY_LIST_STR
12834 "Specify standard large-community-list\n"
12835 "Large Community list name\n"
12836 "Specify large community to reject\n"
12837 "Specify large community to accept\n"
12838 LCOMMUNITY_VAL_STR)
12839{
d62a17ae 12840 return lcommunity_list_set_vty(vty, argc, argv,
12841 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12842}
12843
12844DEFUN (ip_lcommunity_list_name_expanded,
12845 ip_lcommunity_list_name_expanded_cmd,
12846 "ip large-community-list expanded WORD <deny|permit> LINE...",
12847 IP_STR
12848 LCOMMUNITY_LIST_STR
12849 "Specify expanded large-community-list\n"
12850 "Large Community list name\n"
12851 "Specify large community to reject\n"
12852 "Specify large community to accept\n"
12853 "An ordered list as a regular-expression\n")
12854{
d62a17ae 12855 return lcommunity_list_set_vty(vty, argc, argv,
12856 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12857}
12858
12859DEFUN (no_ip_lcommunity_list_standard_all,
12860 no_ip_lcommunity_list_standard_all_cmd,
12861 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12862 NO_STR
12863 IP_STR
12864 LCOMMUNITY_LIST_STR
12865 "Large Community list number (standard)\n"
12866 "Large Community list number (expanded)\n"
12867 "Large Community list name\n")
12868{
d62a17ae 12869 return lcommunity_list_unset_vty(vty, argc, argv,
12870 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12871}
12872
12873DEFUN (no_ip_lcommunity_list_name_expanded_all,
12874 no_ip_lcommunity_list_name_expanded_all_cmd,
12875 "no ip large-community-list expanded WORD",
12876 NO_STR
12877 IP_STR
12878 LCOMMUNITY_LIST_STR
12879 "Specify expanded large-community-list\n"
12880 "Large Community list name\n")
12881{
d62a17ae 12882 return lcommunity_list_unset_vty(vty, argc, argv,
12883 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12884}
12885
12886DEFUN (no_ip_lcommunity_list_standard,
12887 no_ip_lcommunity_list_standard_cmd,
12888 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12889 NO_STR
12890 IP_STR
12891 LCOMMUNITY_LIST_STR
12892 "Large Community list number (standard)\n"
12893 "Specify large community to reject\n"
12894 "Specify large community to accept\n"
12895 LCOMMUNITY_VAL_STR)
12896{
d62a17ae 12897 return lcommunity_list_unset_vty(vty, argc, argv,
12898 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12899}
12900
12901DEFUN (no_ip_lcommunity_list_expanded,
12902 no_ip_lcommunity_list_expanded_cmd,
12903 "no ip large-community-list (100-500) <deny|permit> LINE...",
12904 NO_STR
12905 IP_STR
12906 LCOMMUNITY_LIST_STR
12907 "Large Community list number (expanded)\n"
12908 "Specify large community to reject\n"
12909 "Specify large community to accept\n"
12910 "An ordered list as a regular-expression\n")
12911{
d62a17ae 12912 return lcommunity_list_unset_vty(vty, argc, argv,
12913 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12914}
12915
12916DEFUN (no_ip_lcommunity_list_name_standard,
12917 no_ip_lcommunity_list_name_standard_cmd,
12918 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12919 NO_STR
12920 IP_STR
12921 LCOMMUNITY_LIST_STR
12922 "Specify standard large-community-list\n"
12923 "Large Community list name\n"
12924 "Specify large community to reject\n"
12925 "Specify large community to accept\n"
12926 LCOMMUNITY_VAL_STR)
12927{
d62a17ae 12928 return lcommunity_list_unset_vty(vty, argc, argv,
12929 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12930}
12931
12932DEFUN (no_ip_lcommunity_list_name_expanded,
12933 no_ip_lcommunity_list_name_expanded_cmd,
12934 "no ip large-community-list expanded WORD <deny|permit> LINE...",
12935 NO_STR
12936 IP_STR
12937 LCOMMUNITY_LIST_STR
12938 "Specify expanded large-community-list\n"
12939 "Large community list name\n"
12940 "Specify large community to reject\n"
12941 "Specify large community to accept\n"
12942 "An ordered list as a regular-expression\n")
12943{
d62a17ae 12944 return lcommunity_list_unset_vty(vty, argc, argv,
12945 LARGE_COMMUNITY_LIST_EXPANDED);
12946}
12947
12948static void lcommunity_list_show(struct vty *vty, struct community_list *list)
12949{
12950 struct community_entry *entry;
12951
12952 for (entry = list->head; entry; entry = entry->next) {
12953 if (entry == list->head) {
12954 if (all_digit(list->name))
12955 vty_out(vty, "Large community %s list %s\n",
12956 entry->style == EXTCOMMUNITY_LIST_STANDARD
12957 ? "standard"
12958 : "(expanded) access",
12959 list->name);
12960 else
12961 vty_out(vty,
12962 "Named large community %s list %s\n",
12963 entry->style == EXTCOMMUNITY_LIST_STANDARD
12964 ? "standard"
12965 : "expanded",
12966 list->name);
12967 }
12968 if (entry->any)
12969 vty_out(vty, " %s\n",
12970 community_direct_str(entry->direct));
12971 else
12972 vty_out(vty, " %s %s\n",
12973 community_direct_str(entry->direct),
12974 entry->style == EXTCOMMUNITY_LIST_STANDARD
12975 ? entry->u.ecom->str
12976 : entry->config);
12977 }
57d187bc
JS
12978}
12979
12980DEFUN (show_ip_lcommunity_list,
12981 show_ip_lcommunity_list_cmd,
12982 "show ip large-community-list",
12983 SHOW_STR
12984 IP_STR
12985 "List large-community list\n")
12986{
d62a17ae 12987 struct community_list *list;
12988 struct community_list_master *cm;
57d187bc 12989
d62a17ae 12990 cm = community_list_master_lookup(bgp_clist,
12991 LARGE_COMMUNITY_LIST_MASTER);
12992 if (!cm)
12993 return CMD_SUCCESS;
57d187bc 12994
d62a17ae 12995 for (list = cm->num.head; list; list = list->next)
12996 lcommunity_list_show(vty, list);
57d187bc 12997
d62a17ae 12998 for (list = cm->str.head; list; list = list->next)
12999 lcommunity_list_show(vty, list);
57d187bc 13000
d62a17ae 13001 return CMD_SUCCESS;
57d187bc
JS
13002}
13003
13004DEFUN (show_ip_lcommunity_list_arg,
13005 show_ip_lcommunity_list_arg_cmd,
13006 "show ip large-community-list <(1-500)|WORD>",
13007 SHOW_STR
13008 IP_STR
13009 "List large-community list\n"
13010 "large-community-list number\n"
13011 "large-community-list name\n")
13012{
d62a17ae 13013 struct community_list *list;
57d187bc 13014
d62a17ae 13015 list = community_list_lookup(bgp_clist, argv[3]->arg,
13016 LARGE_COMMUNITY_LIST_MASTER);
13017 if (!list) {
13018 vty_out(vty, "%% Can't find extcommunity-list\n");
13019 return CMD_WARNING;
13020 }
57d187bc 13021
d62a17ae 13022 lcommunity_list_show(vty, list);
57d187bc 13023
d62a17ae 13024 return CMD_SUCCESS;
57d187bc
JS
13025}
13026
718e3744 13027/* "extcommunity-list" keyword help string. */
13028#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13029#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13030
13031DEFUN (ip_extcommunity_list_standard,
13032 ip_extcommunity_list_standard_cmd,
e961923c 13033 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13034 IP_STR
13035 EXTCOMMUNITY_LIST_STR
13036 "Extended Community list number (standard)\n"
718e3744 13037 "Specify standard extcommunity-list\n"
5bf15956 13038 "Community list name\n"
718e3744 13039 "Specify community to reject\n"
13040 "Specify community to accept\n"
13041 EXTCOMMUNITY_VAL_STR)
13042{
d62a17ae 13043 int style = EXTCOMMUNITY_LIST_STANDARD;
13044 int direct = 0;
13045 char *cl_number_or_name = NULL;
42f914d4 13046
d62a17ae 13047 int idx = 0;
13048 argv_find(argv, argc, "(1-99)", &idx);
13049 argv_find(argv, argc, "WORD", &idx);
13050 cl_number_or_name = argv[idx]->arg;
13051 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13052 : COMMUNITY_DENY;
13053 argv_find(argv, argc, "AA:NN", &idx);
13054 char *str = argv_concat(argv, argc, idx);
42f914d4 13055
d62a17ae 13056 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13057 direct, style);
42f914d4 13058
d62a17ae 13059 XFREE(MTYPE_TMP, str);
42f914d4 13060
d62a17ae 13061 if (ret < 0) {
13062 community_list_perror(vty, ret);
13063 return CMD_WARNING_CONFIG_FAILED;
13064 }
42f914d4 13065
d62a17ae 13066 return CMD_SUCCESS;
718e3744 13067}
13068
718e3744 13069DEFUN (ip_extcommunity_list_name_expanded,
13070 ip_extcommunity_list_name_expanded_cmd,
e961923c 13071 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13072 IP_STR
13073 EXTCOMMUNITY_LIST_STR
5bf15956 13074 "Extended Community list number (expanded)\n"
718e3744 13075 "Specify expanded extcommunity-list\n"
13076 "Extended Community list name\n"
13077 "Specify community to reject\n"
13078 "Specify community to accept\n"
13079 "An ordered list as a regular-expression\n")
13080{
d62a17ae 13081 int style = EXTCOMMUNITY_LIST_EXPANDED;
13082 int direct = 0;
13083 char *cl_number_or_name = NULL;
42f914d4 13084
d62a17ae 13085 int idx = 0;
13086 argv_find(argv, argc, "(100-500)", &idx);
13087 argv_find(argv, argc, "WORD", &idx);
13088 cl_number_or_name = argv[idx]->arg;
13089 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13090 : COMMUNITY_DENY;
13091 argv_find(argv, argc, "LINE", &idx);
13092 char *str = argv_concat(argv, argc, idx);
42f914d4 13093
d62a17ae 13094 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13095 direct, style);
42f914d4 13096
d62a17ae 13097 XFREE(MTYPE_TMP, str);
42f914d4 13098
d62a17ae 13099 if (ret < 0) {
13100 community_list_perror(vty, ret);
13101 return CMD_WARNING_CONFIG_FAILED;
13102 }
42f914d4 13103
d62a17ae 13104 return CMD_SUCCESS;
718e3744 13105}
13106
fee6e4e4 13107DEFUN (no_ip_extcommunity_list_standard_all,
13108 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13109 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13110 NO_STR
13111 IP_STR
13112 EXTCOMMUNITY_LIST_STR
13113 "Extended Community list number (standard)\n"
718e3744 13114 "Specify standard extcommunity-list\n"
5bf15956 13115 "Community list name\n"
718e3744 13116 "Specify community to reject\n"
13117 "Specify community to accept\n"
13118 EXTCOMMUNITY_VAL_STR)
13119{
d62a17ae 13120 int deleteall = 0;
42f914d4 13121
d62a17ae 13122 int style = EXTCOMMUNITY_LIST_STANDARD;
13123 int direct = 0;
13124 char *cl_number_or_name = NULL;
42f914d4 13125
d62a17ae 13126 int idx = 0;
13127 argv_find(argv, argc, "(1-99)", &idx);
13128 argv_find(argv, argc, "WORD", &idx);
13129 cl_number_or_name = argv[idx]->arg;
13130 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13131 : COMMUNITY_DENY;
13132 argv_find(argv, argc, "AA:NN", &idx);
13133 char *str = argv_concat(argv, argc, idx);
42f914d4 13134
d62a17ae 13135 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13136 direct, style, deleteall);
42f914d4 13137
d62a17ae 13138 XFREE(MTYPE_TMP, str);
42f914d4 13139
d62a17ae 13140 if (ret < 0) {
13141 community_list_perror(vty, ret);
13142 return CMD_WARNING_CONFIG_FAILED;
13143 }
42f914d4 13144
d62a17ae 13145 return CMD_SUCCESS;
718e3744 13146}
13147
5bf15956
DW
13148DEFUN (no_ip_extcommunity_list_expanded_all,
13149 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13150 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13151 NO_STR
13152 IP_STR
13153 EXTCOMMUNITY_LIST_STR
13154 "Extended Community list number (expanded)\n"
718e3744 13155 "Specify expanded extcommunity-list\n"
5bf15956 13156 "Extended Community list name\n"
718e3744 13157 "Specify community to reject\n"
13158 "Specify community to accept\n"
13159 "An ordered list as a regular-expression\n")
13160{
d62a17ae 13161 int deleteall = 0;
42f914d4 13162
d62a17ae 13163 int style = EXTCOMMUNITY_LIST_EXPANDED;
13164 int direct = 0;
13165 char *cl_number_or_name = NULL;
42f914d4 13166
d62a17ae 13167 int idx = 0;
13168 argv_find(argv, argc, "(100-500)", &idx);
13169 argv_find(argv, argc, "WORD", &idx);
13170 cl_number_or_name = argv[idx]->arg;
13171 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13172 : COMMUNITY_DENY;
13173 argv_find(argv, argc, "LINE", &idx);
13174 char *str = argv_concat(argv, argc, idx);
42f914d4 13175
d62a17ae 13176 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13177 direct, style, deleteall);
42f914d4 13178
d62a17ae 13179 XFREE(MTYPE_TMP, str);
42f914d4 13180
d62a17ae 13181 if (ret < 0) {
13182 community_list_perror(vty, ret);
13183 return CMD_WARNING_CONFIG_FAILED;
13184 }
42f914d4 13185
d62a17ae 13186 return CMD_SUCCESS;
718e3744 13187}
13188
d62a17ae 13189static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13190{
d62a17ae 13191 struct community_entry *entry;
718e3744 13192
d62a17ae 13193 for (entry = list->head; entry; entry = entry->next) {
13194 if (entry == list->head) {
13195 if (all_digit(list->name))
13196 vty_out(vty, "Extended community %s list %s\n",
13197 entry->style == EXTCOMMUNITY_LIST_STANDARD
13198 ? "standard"
13199 : "(expanded) access",
13200 list->name);
13201 else
13202 vty_out(vty,
13203 "Named extended community %s list %s\n",
13204 entry->style == EXTCOMMUNITY_LIST_STANDARD
13205 ? "standard"
13206 : "expanded",
13207 list->name);
13208 }
13209 if (entry->any)
13210 vty_out(vty, " %s\n",
13211 community_direct_str(entry->direct));
13212 else
13213 vty_out(vty, " %s %s\n",
13214 community_direct_str(entry->direct),
13215 entry->style == EXTCOMMUNITY_LIST_STANDARD
13216 ? entry->u.ecom->str
13217 : entry->config);
13218 }
718e3744 13219}
13220
13221DEFUN (show_ip_extcommunity_list,
13222 show_ip_extcommunity_list_cmd,
13223 "show ip extcommunity-list",
13224 SHOW_STR
13225 IP_STR
13226 "List extended-community list\n")
13227{
d62a17ae 13228 struct community_list *list;
13229 struct community_list_master *cm;
718e3744 13230
d62a17ae 13231 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13232 if (!cm)
13233 return CMD_SUCCESS;
718e3744 13234
d62a17ae 13235 for (list = cm->num.head; list; list = list->next)
13236 extcommunity_list_show(vty, list);
718e3744 13237
d62a17ae 13238 for (list = cm->str.head; list; list = list->next)
13239 extcommunity_list_show(vty, list);
718e3744 13240
d62a17ae 13241 return CMD_SUCCESS;
718e3744 13242}
13243
13244DEFUN (show_ip_extcommunity_list_arg,
13245 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13246 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13247 SHOW_STR
13248 IP_STR
13249 "List extended-community list\n"
13250 "Extcommunity-list number\n"
13251 "Extcommunity-list name\n")
13252{
d62a17ae 13253 int idx_comm_list = 3;
13254 struct community_list *list;
718e3744 13255
d62a17ae 13256 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13257 EXTCOMMUNITY_LIST_MASTER);
13258 if (!list) {
13259 vty_out(vty, "%% Can't find extcommunity-list\n");
13260 return CMD_WARNING;
13261 }
718e3744 13262
d62a17ae 13263 extcommunity_list_show(vty, list);
718e3744 13264
d62a17ae 13265 return CMD_SUCCESS;
718e3744 13266}
6b0655a2 13267
718e3744 13268/* Return configuration string of community-list entry. */
d62a17ae 13269static const char *community_list_config_str(struct community_entry *entry)
718e3744 13270{
d62a17ae 13271 const char *str;
718e3744 13272
d62a17ae 13273 if (entry->any)
13274 str = "";
13275 else {
13276 if (entry->style == COMMUNITY_LIST_STANDARD)
13277 str = community_str(entry->u.com);
13278 else
13279 str = entry->config;
13280 }
13281 return str;
718e3744 13282}
13283
13284/* Display community-list and extcommunity-list configuration. */
d62a17ae 13285static int community_list_config_write(struct vty *vty)
13286{
13287 struct community_list *list;
13288 struct community_entry *entry;
13289 struct community_list_master *cm;
13290 int write = 0;
13291
13292 /* Community-list. */
13293 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13294
13295 for (list = cm->num.head; list; list = list->next)
13296 for (entry = list->head; entry; entry = entry->next) {
13297 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13298 community_direct_str(entry->direct),
13299 community_list_config_str(entry));
13300 write++;
13301 }
13302 for (list = cm->str.head; list; list = list->next)
13303 for (entry = list->head; entry; entry = entry->next) {
13304 vty_out(vty, "ip community-list %s %s %s %s\n",
13305 entry->style == COMMUNITY_LIST_STANDARD
13306 ? "standard"
13307 : "expanded",
13308 list->name, community_direct_str(entry->direct),
13309 community_list_config_str(entry));
13310 write++;
13311 }
13312
13313 /* Extcommunity-list. */
13314 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13315
13316 for (list = cm->num.head; list; list = list->next)
13317 for (entry = list->head; entry; entry = entry->next) {
13318 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13319 list->name, community_direct_str(entry->direct),
13320 community_list_config_str(entry));
13321 write++;
13322 }
13323 for (list = cm->str.head; list; list = list->next)
13324 for (entry = list->head; entry; entry = entry->next) {
13325 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13326 entry->style == EXTCOMMUNITY_LIST_STANDARD
13327 ? "standard"
13328 : "expanded",
13329 list->name, community_direct_str(entry->direct),
13330 community_list_config_str(entry));
13331 write++;
13332 }
13333
13334
13335 /* lcommunity-list. */
13336 cm = community_list_master_lookup(bgp_clist,
13337 LARGE_COMMUNITY_LIST_MASTER);
13338
13339 for (list = cm->num.head; list; list = list->next)
13340 for (entry = list->head; entry; entry = entry->next) {
13341 vty_out(vty, "ip large-community-list %s %s %s\n",
13342 list->name, community_direct_str(entry->direct),
13343 community_list_config_str(entry));
13344 write++;
13345 }
13346 for (list = cm->str.head; list; list = list->next)
13347 for (entry = list->head; entry; entry = entry->next) {
13348 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13349 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13350 ? "standard"
13351 : "expanded",
13352 list->name, community_direct_str(entry->direct),
13353 community_list_config_str(entry));
13354 write++;
13355 }
13356
13357 return write;
13358}
13359
13360static struct cmd_node community_list_node = {
13361 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13362};
13363
d62a17ae 13364static void community_list_vty(void)
13365{
13366 install_node(&community_list_node, community_list_config_write);
13367
13368 /* Community-list. */
13369 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13370 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13371 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13372 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13373 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13374 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13375
13376 /* Extcommunity-list. */
13377 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13378 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13379 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13380 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13381 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13382 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13383
13384 /* Large Community List */
13385 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13386 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13387 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13388 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13389 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13390 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13391 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13392 install_element(CONFIG_NODE,
13393 &no_ip_lcommunity_list_name_expanded_all_cmd);
13394 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13395 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13396 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13397 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13398 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13399 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13400}