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