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