]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: static bgp_pthreads_init()
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
718e3744 37
38#include "bgpd/bgpd.h"
4bf6a362 39#include "bgpd/bgp_advertise.h"
718e3744 40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_aspath.h"
42#include "bgpd/bgp_community.h"
4bf6a362 43#include "bgpd/bgp_ecommunity.h"
57d187bc 44#include "bgpd/bgp_lcommunity.h"
4bf6a362 45#include "bgpd/bgp_damp.h"
718e3744 46#include "bgpd/bgp_debug.h"
e0701b79 47#include "bgpd/bgp_fsm.h"
4bf6a362 48#include "bgpd/bgp_nexthop.h"
718e3744 49#include "bgpd/bgp_open.h"
4bf6a362 50#include "bgpd/bgp_regex.h"
718e3744 51#include "bgpd/bgp_route.h"
c016b6c7 52#include "bgpd/bgp_mplsvpn.h"
718e3744 53#include "bgpd/bgp_zebra.h"
fee0f4c6 54#include "bgpd/bgp_table.h"
94f2b392 55#include "bgpd/bgp_vty.h"
165b5fff 56#include "bgpd/bgp_mpath.h"
cb1faec9 57#include "bgpd/bgp_packet.h"
3f9c7369 58#include "bgpd/bgp_updgrp.h"
c43ed2e4 59#include "bgpd/bgp_bfd.h"
555e09d4 60#include "bgpd/bgp_io.h"
718e3744 61
d62a17ae 62static struct peer_group *listen_range_exists(struct bgp *bgp,
63 struct prefix *range, int exact);
64
65static enum node_type bgp_node_type(afi_t afi, safi_t safi)
66{
67 switch (afi) {
68 case AFI_IP:
69 switch (safi) {
70 case SAFI_UNICAST:
71 return BGP_IPV4_NODE;
72 break;
73 case SAFI_MULTICAST:
74 return BGP_IPV4M_NODE;
75 break;
76 case SAFI_LABELED_UNICAST:
77 return BGP_IPV4L_NODE;
78 break;
79 case SAFI_MPLS_VPN:
80 return BGP_VPNV4_NODE;
81 break;
5c525538
RW
82 default:
83 /* not expected */
84 return BGP_IPV4_NODE;
85 break;
d62a17ae 86 }
87 break;
88 case AFI_IP6:
89 switch (safi) {
90 case SAFI_UNICAST:
91 return BGP_IPV6_NODE;
92 break;
93 case SAFI_MULTICAST:
94 return BGP_IPV6M_NODE;
95 break;
96 case SAFI_LABELED_UNICAST:
97 return BGP_IPV6L_NODE;
98 break;
99 case SAFI_MPLS_VPN:
100 return BGP_VPNV6_NODE;
101 break;
5c525538
RW
102 default:
103 /* not expected */
104 return BGP_IPV4_NODE;
105 break;
d62a17ae 106 }
107 break;
108 case AFI_L2VPN:
109 return BGP_EVPN_NODE;
110 break;
111 case AFI_MAX:
112 // We should never be here but to clarify the switch statement..
113 return BGP_IPV4_NODE;
114 break;
115 }
116
117 // Impossible to happen
118 return BGP_IPV4_NODE;
f51bae9c 119}
20eb8864 120
718e3744 121/* Utility function to get address family from current node. */
d62a17ae 122afi_t bgp_node_afi(struct vty *vty)
123{
124 afi_t afi;
125 switch (vty->node) {
126 case BGP_IPV6_NODE:
127 case BGP_IPV6M_NODE:
128 case BGP_IPV6L_NODE:
129 case BGP_VPNV6_NODE:
130 afi = AFI_IP6;
131 break;
132 case BGP_EVPN_NODE:
133 afi = AFI_L2VPN;
134 break;
135 default:
136 afi = AFI_IP;
137 break;
138 }
139 return afi;
718e3744 140}
141
142/* Utility function to get subsequent address family from current
143 node. */
d62a17ae 144safi_t bgp_node_safi(struct vty *vty)
145{
146 safi_t safi;
147 switch (vty->node) {
148 case BGP_VPNV4_NODE:
149 case BGP_VPNV6_NODE:
150 safi = SAFI_MPLS_VPN;
151 break;
152 case BGP_IPV4M_NODE:
153 case BGP_IPV6M_NODE:
154 safi = SAFI_MULTICAST;
155 break;
156 case BGP_EVPN_NODE:
157 safi = SAFI_EVPN;
158 break;
159 case BGP_IPV4L_NODE:
160 case BGP_IPV6L_NODE:
161 safi = SAFI_LABELED_UNICAST;
162 break;
163 default:
164 safi = SAFI_UNICAST;
165 break;
166 }
167 return safi;
718e3744 168}
169
55f91488
QY
170/**
171 * Converts an AFI in string form to afi_t
172 *
173 * @param afi string, one of
174 * - "ipv4"
175 * - "ipv6"
176 * @return the corresponding afi_t
177 */
d62a17ae 178afi_t bgp_vty_afi_from_str(const char *afi_str)
179{
180 afi_t afi = AFI_MAX; /* unknown */
181 if (strmatch(afi_str, "ipv4"))
182 afi = AFI_IP;
183 else if (strmatch(afi_str, "ipv6"))
184 afi = AFI_IP6;
185 return afi;
186}
187
188int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
189 afi_t *afi)
190{
191 int ret = 0;
192 if (argv_find(argv, argc, "ipv4", index)) {
193 ret = 1;
194 if (afi)
195 *afi = AFI_IP;
196 } else if (argv_find(argv, argc, "ipv6", index)) {
197 ret = 1;
198 if (afi)
199 *afi = AFI_IP6;
200 }
201 return ret;
46f296b4
LB
202}
203
375a2e67 204/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 205safi_t bgp_vty_safi_from_str(const char *safi_str)
206{
207 safi_t safi = SAFI_MAX; /* unknown */
208 if (strmatch(safi_str, "multicast"))
209 safi = SAFI_MULTICAST;
210 else if (strmatch(safi_str, "unicast"))
211 safi = SAFI_UNICAST;
212 else if (strmatch(safi_str, "vpn"))
213 safi = SAFI_MPLS_VPN;
214 else if (strmatch(safi_str, "labeled-unicast"))
215 safi = SAFI_LABELED_UNICAST;
216 return safi;
217}
218
219int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
220 safi_t *safi)
221{
222 int ret = 0;
223 if (argv_find(argv, argc, "unicast", index)) {
224 ret = 1;
225 if (safi)
226 *safi = SAFI_UNICAST;
227 } else if (argv_find(argv, argc, "multicast", index)) {
228 ret = 1;
229 if (safi)
230 *safi = SAFI_MULTICAST;
231 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
232 ret = 1;
233 if (safi)
234 *safi = SAFI_LABELED_UNICAST;
235 } else if (argv_find(argv, argc, "vpn", index)) {
236 ret = 1;
237 if (safi)
238 *safi = SAFI_MPLS_VPN;
239 }
240 return ret;
46f296b4
LB
241}
242
7eeee51e 243/*
f212a857 244 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 245 *
f212a857
DS
246 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
247 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
248 * to appropriate values for the calling function. This is to allow the
249 * calling function to make decisions appropriate for the show command
250 * that is being parsed.
251 *
252 * The show commands are generally of the form:
d62a17ae 253 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
254 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
255 *
256 * Since we use argv_find if the show command in particular doesn't have:
257 * [ip]
18c57037 258 * [<view|vrf> VIEWVRFNAME]
375a2e67 259 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
260 * The command parsing should still be ok.
261 *
262 * vty -> The vty for the command so we can output some useful data in
263 * the event of a parse error in the vrf.
264 * argv -> The command tokens
265 * argc -> How many command tokens we have
d62a17ae 266 * idx -> The current place in the command, generally should be 0 for this
267 * function
7eeee51e
DS
268 * afi -> The parsed afi if it was included in the show command, returned here
269 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 270 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
271 *
272 * The function returns the correct location in the parse tree for the
273 * last token found.
0e37c258
DS
274 *
275 * Returns 0 for failure to parse correctly, else the idx position of where
276 * it found the last token.
7eeee51e 277 */
d62a17ae 278int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
279 struct cmd_token **argv, int argc,
280 int *idx, afi_t *afi, safi_t *safi,
281 struct bgp **bgp)
282{
283 char *vrf_name = NULL;
284
285 assert(afi);
286 assert(safi);
287 assert(bgp);
288
289 if (argv_find(argv, argc, "ip", idx))
290 *afi = AFI_IP;
291
292 if (argv_find(argv, argc, "view", idx)
293 || argv_find(argv, argc, "vrf", idx)) {
294 vrf_name = argv[*idx + 1]->arg;
295
296 if (strmatch(vrf_name, "all"))
297 *bgp = NULL;
298 else {
299 *bgp = bgp_lookup_by_name(vrf_name);
300 if (!*bgp) {
301 vty_out(vty,
302 "View/Vrf specified is unknown: %s\n",
303 vrf_name);
304 *idx = 0;
305 return 0;
306 }
307 }
308 } else {
309 *bgp = bgp_get_default();
310 if (!*bgp) {
311 vty_out(vty, "Unable to find default BGP instance\n");
312 *idx = 0;
313 return 0;
314 }
315 }
316
317 if (argv_find_and_parse_afi(argv, argc, idx, afi))
318 argv_find_and_parse_safi(argv, argc, idx, safi);
319
320 *idx += 1;
321 return *idx;
322}
323
324static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
325{
326 struct interface *ifp = NULL;
327
328 if (su->sa.sa_family == AF_INET)
329 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
330 else if (su->sa.sa_family == AF_INET6)
331 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
332 su->sin6.sin6_scope_id,
333 bgp->vrf_id);
334
335 if (ifp)
336 return 1;
337
338 return 0;
718e3744 339}
340
341/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
342/* This is used only for configuration, so disallow if attempted on
343 * a dynamic neighbor.
344 */
d62a17ae 345static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
346{
347 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
348 int ret;
349 union sockunion su;
350 struct peer *peer;
351
352 if (!bgp) {
353 return NULL;
354 }
355
356 ret = str2sockunion(ip_str, &su);
357 if (ret < 0) {
358 peer = peer_lookup_by_conf_if(bgp, ip_str);
359 if (!peer) {
360 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
361 == NULL) {
362 vty_out(vty,
363 "%% Malformed address or name: %s\n",
364 ip_str);
365 return NULL;
366 }
367 }
368 } else {
369 peer = peer_lookup(bgp, &su);
370 if (!peer) {
371 vty_out(vty,
372 "%% Specify remote-as or peer-group commands first\n");
373 return NULL;
374 }
375 if (peer_dynamic_neighbor(peer)) {
376 vty_out(vty,
377 "%% Operation not allowed on a dynamic neighbor\n");
378 return NULL;
379 }
380 }
381 return peer;
718e3744 382}
383
384/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
385/* This is used only for configuration, so disallow if attempted on
386 * a dynamic neighbor.
387 */
d62a17ae 388struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
389{
390 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
391 int ret;
392 union sockunion su;
393 struct peer *peer = NULL;
394 struct peer_group *group = NULL;
395
396 if (!bgp) {
397 return NULL;
398 }
399
400 ret = str2sockunion(peer_str, &su);
401 if (ret == 0) {
402 /* IP address, locate peer. */
403 peer = peer_lookup(bgp, &su);
404 } else {
405 /* Not IP, could match either peer configured on interface or a
406 * group. */
407 peer = peer_lookup_by_conf_if(bgp, peer_str);
408 if (!peer)
409 group = peer_group_lookup(bgp, peer_str);
410 }
411
412 if (peer) {
413 if (peer_dynamic_neighbor(peer)) {
414 vty_out(vty,
415 "%% Operation not allowed on a dynamic neighbor\n");
416 return NULL;
417 }
418
419 return peer;
420 }
421
422 if (group)
423 return group->conf;
424
425 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
426
427 return NULL;
428}
429
430int bgp_vty_return(struct vty *vty, int ret)
431{
432 const char *str = NULL;
433
434 switch (ret) {
435 case BGP_ERR_INVALID_VALUE:
436 str = "Invalid value";
437 break;
438 case BGP_ERR_INVALID_FLAG:
439 str = "Invalid flag";
440 break;
441 case BGP_ERR_PEER_GROUP_SHUTDOWN:
442 str = "Peer-group has been shutdown. Activate the peer-group first";
443 break;
444 case BGP_ERR_PEER_FLAG_CONFLICT:
445 str = "Can't set override-capability and strict-capability-match at the same time";
446 break;
447 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
448 str = "Specify remote-as or peer-group remote AS first";
449 break;
450 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
451 str = "Cannot change the peer-group. Deconfigure first";
452 break;
453 case BGP_ERR_PEER_GROUP_MISMATCH:
454 str = "Peer is not a member of this peer-group";
455 break;
456 case BGP_ERR_PEER_FILTER_CONFLICT:
457 str = "Prefix/distribute list can not co-exist";
458 break;
459 case BGP_ERR_NOT_INTERNAL_PEER:
460 str = "Invalid command. Not an internal neighbor";
461 break;
462 case BGP_ERR_REMOVE_PRIVATE_AS:
463 str = "remove-private-AS cannot be configured for IBGP peers";
464 break;
465 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
466 str = "Local-AS allowed only for EBGP peers";
467 break;
468 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
469 str = "Cannot have local-as same as BGP AS number";
470 break;
471 case BGP_ERR_TCPSIG_FAILED:
472 str = "Error while applying TCP-Sig to session(s)";
473 break;
474 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
475 str = "ebgp-multihop and ttl-security cannot be configured together";
476 break;
477 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
478 str = "ttl-security only allowed for EBGP peers";
479 break;
480 case BGP_ERR_AS_OVERRIDE:
481 str = "as-override cannot be configured for IBGP peers";
482 break;
483 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
484 str = "Invalid limit for number of dynamic neighbors";
485 break;
486 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
487 str = "Dynamic neighbor listen range already exists";
488 break;
489 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
490 str = "Operation not allowed on a dynamic neighbor";
491 break;
492 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
493 str = "Operation not allowed on a directly connected neighbor";
494 break;
495 case BGP_ERR_PEER_SAFI_CONFLICT:
496 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
497 break;
498 }
499 if (str) {
500 vty_out(vty, "%% %s\n", str);
501 return CMD_WARNING_CONFIG_FAILED;
502 }
503 return CMD_SUCCESS;
718e3744 504}
505
7aafcaca 506/* BGP clear sort. */
d62a17ae 507enum clear_sort {
508 clear_all,
509 clear_peer,
510 clear_group,
511 clear_external,
512 clear_as
7aafcaca
DS
513};
514
d62a17ae 515static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
516 safi_t safi, int error)
517{
518 switch (error) {
519 case BGP_ERR_AF_UNCONFIGURED:
520 vty_out(vty,
521 "%%BGP: Enable %s address family for the neighbor %s\n",
522 afi_safi_print(afi, safi), peer->host);
523 break;
524 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
525 vty_out(vty,
526 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
527 peer->host);
528 break;
529 default:
530 break;
531 }
7aafcaca
DS
532}
533
534/* `clear ip bgp' functions. */
d62a17ae 535static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
536 enum clear_sort sort, enum bgp_clear_type stype,
537 const char *arg)
538{
539 int ret;
540 struct peer *peer;
541 struct listnode *node, *nnode;
542
543 /* Clear all neighbors. */
544 /*
545 * Pass along pointer to next node to peer_clear() when walking all
546 * nodes
547 * on the BGP instance as that may get freed if it is a doppelganger
548 */
549 if (sort == clear_all) {
550 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
551 if (stype == BGP_CLEAR_SOFT_NONE)
552 ret = peer_clear(peer, &nnode);
553 else if (peer->afc[afi][safi])
554 ret = peer_clear_soft(peer, afi, safi, stype);
555 else
556 ret = 0;
557
558 if (ret < 0)
559 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 560 }
d62a17ae 561
562 /* This is to apply read-only mode on this clear. */
563 if (stype == BGP_CLEAR_SOFT_NONE)
564 bgp->update_delay_over = 0;
565
566 return CMD_SUCCESS;
7aafcaca
DS
567 }
568
d62a17ae 569 /* Clear specified neighbors. */
570 if (sort == clear_peer) {
571 union sockunion su;
572 int ret;
573
574 /* Make sockunion for lookup. */
575 ret = str2sockunion(arg, &su);
576 if (ret < 0) {
577 peer = peer_lookup_by_conf_if(bgp, arg);
578 if (!peer) {
579 peer = peer_lookup_by_hostname(bgp, arg);
580 if (!peer) {
581 vty_out(vty,
582 "Malformed address or name: %s\n",
583 arg);
584 return CMD_WARNING;
585 }
586 }
587 } else {
588 peer = peer_lookup(bgp, &su);
589 if (!peer) {
590 vty_out(vty,
591 "%%BGP: Unknown neighbor - \"%s\"\n",
592 arg);
593 return CMD_WARNING;
594 }
595 }
7aafcaca 596
d62a17ae 597 if (stype == BGP_CLEAR_SOFT_NONE)
598 ret = peer_clear(peer, NULL);
599 else
600 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 601
d62a17ae 602 if (ret < 0)
603 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 604
d62a17ae 605 return CMD_SUCCESS;
7aafcaca 606 }
7aafcaca 607
d62a17ae 608 /* Clear all peer-group members. */
609 if (sort == clear_group) {
610 struct peer_group *group;
7aafcaca 611
d62a17ae 612 group = peer_group_lookup(bgp, arg);
613 if (!group) {
614 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
615 return CMD_WARNING;
616 }
617
618 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
619 if (stype == BGP_CLEAR_SOFT_NONE) {
620 peer_clear(peer, NULL);
621 continue;
622 }
623
624 if (!peer->afc[afi][safi])
625 continue;
626
627 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 628
d62a17ae 629 if (ret < 0)
630 bgp_clear_vty_error(vty, peer, afi, safi, ret);
631 }
632 return CMD_SUCCESS;
7aafcaca 633 }
7aafcaca 634
d62a17ae 635 if (sort == clear_external) {
636 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
637 if (peer->sort == BGP_PEER_IBGP)
638 continue;
7aafcaca 639
d62a17ae 640 if (stype == BGP_CLEAR_SOFT_NONE)
641 ret = peer_clear(peer, &nnode);
642 else
643 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 644
d62a17ae 645 if (ret < 0)
646 bgp_clear_vty_error(vty, peer, afi, safi, ret);
647 }
648 return CMD_SUCCESS;
649 }
650
651 if (sort == clear_as) {
652 as_t as;
653 int find = 0;
654
655 as = strtoul(arg, NULL, 10);
656
657 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
658 if (peer->as != as)
659 continue;
660
661 find = 1;
662 if (stype == BGP_CLEAR_SOFT_NONE)
663 ret = peer_clear(peer, &nnode);
664 else
665 ret = peer_clear_soft(peer, afi, safi, stype);
666
667 if (ret < 0)
668 bgp_clear_vty_error(vty, peer, afi, safi, ret);
669 }
670 if (!find)
671 vty_out(vty,
672 "%%BGP: No peer is configured with AS %s\n",
673 arg);
674 return CMD_SUCCESS;
675 }
676
677 return CMD_SUCCESS;
678}
679
680static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
681 safi_t safi, enum clear_sort sort,
682 enum bgp_clear_type stype, const char *arg)
683{
684 struct bgp *bgp;
685
686 /* BGP structure lookup. */
687 if (name) {
688 bgp = bgp_lookup_by_name(name);
689 if (bgp == NULL) {
690 vty_out(vty, "Can't find BGP instance %s\n", name);
691 return CMD_WARNING;
692 }
693 } else {
694 bgp = bgp_get_default();
695 if (bgp == NULL) {
696 vty_out(vty, "No BGP process is configured\n");
697 return CMD_WARNING;
698 }
699 }
700
701 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
702}
703
704/* clear soft inbound */
d62a17ae 705static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 706{
d62a17ae 707 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
708 BGP_CLEAR_SOFT_IN, NULL);
709 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
710 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
711}
712
713/* clear soft outbound */
d62a17ae 714static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 715{
d62a17ae 716 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
717 BGP_CLEAR_SOFT_OUT, NULL);
718 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
719 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
720}
721
722
f787d7a0
DL
723#ifndef VTYSH_EXTRACT_PL
724#include "bgp_vty_clippy.c"
725#endif
726
718e3744 727/* BGP global configuration. */
728
729DEFUN (bgp_multiple_instance_func,
730 bgp_multiple_instance_cmd,
731 "bgp multiple-instance",
732 BGP_STR
733 "Enable bgp multiple instance\n")
734{
d62a17ae 735 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
736 return CMD_SUCCESS;
718e3744 737}
738
739DEFUN (no_bgp_multiple_instance,
740 no_bgp_multiple_instance_cmd,
741 "no bgp multiple-instance",
742 NO_STR
743 BGP_STR
744 "BGP multiple instance\n")
745{
d62a17ae 746 int ret;
718e3744 747
d62a17ae 748 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
749 if (ret < 0) {
750 vty_out(vty, "%% There are more than two BGP instances\n");
751 return CMD_WARNING_CONFIG_FAILED;
752 }
753 return CMD_SUCCESS;
718e3744 754}
755
756DEFUN (bgp_config_type,
757 bgp_config_type_cmd,
6147e2c6 758 "bgp config-type <cisco|zebra>",
718e3744 759 BGP_STR
760 "Configuration type\n"
761 "cisco\n"
762 "zebra\n")
763{
d62a17ae 764 int idx = 0;
765 if (argv_find(argv, argc, "cisco", &idx))
766 bgp_option_set(BGP_OPT_CONFIG_CISCO);
767 else
768 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 769
d62a17ae 770 return CMD_SUCCESS;
718e3744 771}
772
773DEFUN (no_bgp_config_type,
774 no_bgp_config_type_cmd,
c7178fe7 775 "no bgp config-type [<cisco|zebra>]",
718e3744 776 NO_STR
777 BGP_STR
838758ac
DW
778 "Display configuration type\n"
779 "cisco\n"
780 "zebra\n")
718e3744 781{
d62a17ae 782 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
783 return CMD_SUCCESS;
718e3744 784}
785
813d4307 786
718e3744 787DEFUN (no_synchronization,
788 no_synchronization_cmd,
789 "no synchronization",
790 NO_STR
791 "Perform IGP synchronization\n")
792{
d62a17ae 793 return CMD_SUCCESS;
718e3744 794}
795
796DEFUN (no_auto_summary,
797 no_auto_summary_cmd,
798 "no auto-summary",
799 NO_STR
800 "Enable automatic network number summarization\n")
801{
d62a17ae 802 return CMD_SUCCESS;
718e3744 803}
3d515fd9 804
718e3744 805/* "router bgp" commands. */
505e5056 806DEFUN_NOSH (router_bgp,
f412b39a 807 router_bgp_cmd,
18c57037 808 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 809 ROUTER_STR
810 BGP_STR
31500417
DW
811 AS_STR
812 BGP_INSTANCE_HELP_STR)
718e3744 813{
d62a17ae 814 int idx_asn = 2;
815 int idx_view_vrf = 3;
816 int idx_vrf = 4;
817 int ret;
818 as_t as;
819 struct bgp *bgp;
820 const char *name = NULL;
821 enum bgp_instance_type inst_type;
822
823 // "router bgp" without an ASN
824 if (argc == 2) {
825 // Pending: Make VRF option available for ASN less config
826 bgp = bgp_get_default();
827
828 if (bgp == NULL) {
829 vty_out(vty, "%% No BGP process is configured\n");
830 return CMD_WARNING_CONFIG_FAILED;
831 }
832
833 if (listcount(bm->bgp) > 1) {
834 vty_out(vty,
835 "%% Multiple BGP processes are configured\n");
836 return CMD_WARNING_CONFIG_FAILED;
837 }
838 }
839
840 // "router bgp X"
841 else {
842 as = strtoul(argv[idx_asn]->arg, NULL, 10);
843
844 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
845 if (argc > 3) {
846 name = argv[idx_vrf]->arg;
847
848 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
849 inst_type = BGP_INSTANCE_TYPE_VRF;
850 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
851 inst_type = BGP_INSTANCE_TYPE_VIEW;
852 }
853
854 ret = bgp_get(&bgp, &as, name, inst_type);
855 switch (ret) {
856 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
857 vty_out(vty,
858 "Please specify 'bgp multiple-instance' first\n");
859 return CMD_WARNING_CONFIG_FAILED;
860 case BGP_ERR_AS_MISMATCH:
861 vty_out(vty, "BGP is already running; AS is %u\n", as);
862 return CMD_WARNING_CONFIG_FAILED;
863 case BGP_ERR_INSTANCE_MISMATCH:
864 vty_out(vty,
865 "BGP instance name and AS number mismatch\n");
866 vty_out(vty,
867 "BGP instance is already running; AS is %u\n",
868 as);
869 return CMD_WARNING_CONFIG_FAILED;
870 }
871
872 /* Pending: handle when user tries to change a view to vrf n vv.
873 */
874 }
875
876 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
877
878 return CMD_SUCCESS;
718e3744 879}
880
718e3744 881/* "no router bgp" commands. */
882DEFUN (no_router_bgp,
883 no_router_bgp_cmd,
18c57037 884 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 885 NO_STR
886 ROUTER_STR
887 BGP_STR
31500417
DW
888 AS_STR
889 BGP_INSTANCE_HELP_STR)
718e3744 890{
d62a17ae 891 int idx_asn = 3;
892 int idx_vrf = 5;
893 as_t as;
894 struct bgp *bgp;
895 const char *name = NULL;
718e3744 896
d62a17ae 897 // "no router bgp" without an ASN
898 if (argc == 3) {
899 // Pending: Make VRF option available for ASN less config
900 bgp = bgp_get_default();
718e3744 901
d62a17ae 902 if (bgp == NULL) {
903 vty_out(vty, "%% No BGP process is configured\n");
904 return CMD_WARNING_CONFIG_FAILED;
905 }
7fb21a9f 906
d62a17ae 907 if (listcount(bm->bgp) > 1) {
908 vty_out(vty,
909 "%% Multiple BGP processes are configured\n");
910 return CMD_WARNING_CONFIG_FAILED;
911 }
912 } else {
913 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 914
d62a17ae 915 if (argc > 4)
916 name = argv[idx_vrf]->arg;
7fb21a9f 917
d62a17ae 918 /* Lookup bgp structure. */
919 bgp = bgp_lookup(as, name);
920 if (!bgp) {
921 vty_out(vty, "%% Can't find BGP instance\n");
922 return CMD_WARNING_CONFIG_FAILED;
923 }
924 }
718e3744 925
d62a17ae 926 bgp_delete(bgp);
718e3744 927
d62a17ae 928 return CMD_SUCCESS;
718e3744 929}
930
6b0655a2 931
718e3744 932/* BGP router-id. */
933
f787d7a0 934DEFPY (bgp_router_id,
718e3744 935 bgp_router_id_cmd,
936 "bgp router-id A.B.C.D",
937 BGP_STR
938 "Override configured router identifier\n"
939 "Manually configured router identifier\n")
940{
d62a17ae 941 VTY_DECLVAR_CONTEXT(bgp, bgp);
942 bgp_router_id_static_set(bgp, router_id);
943 return CMD_SUCCESS;
718e3744 944}
945
f787d7a0 946DEFPY (no_bgp_router_id,
718e3744 947 no_bgp_router_id_cmd,
31500417 948 "no bgp router-id [A.B.C.D]",
718e3744 949 NO_STR
950 BGP_STR
31500417
DW
951 "Override configured router identifier\n"
952 "Manually configured router identifier\n")
718e3744 953{
d62a17ae 954 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 955
d62a17ae 956 if (router_id_str) {
957 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
958 vty_out(vty, "%% BGP router-id doesn't match\n");
959 return CMD_WARNING_CONFIG_FAILED;
960 }
e018c7cc 961 }
718e3744 962
d62a17ae 963 router_id.s_addr = 0;
964 bgp_router_id_static_set(bgp, router_id);
718e3744 965
d62a17ae 966 return CMD_SUCCESS;
718e3744 967}
968
6b0655a2 969
718e3744 970/* BGP Cluster ID. */
718e3744 971DEFUN (bgp_cluster_id,
972 bgp_cluster_id_cmd,
838758ac 973 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 974 BGP_STR
975 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
976 "Route-Reflector Cluster-id in IP address format\n"
977 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 978{
d62a17ae 979 VTY_DECLVAR_CONTEXT(bgp, bgp);
980 int idx_ipv4 = 2;
981 int ret;
982 struct in_addr cluster;
718e3744 983
d62a17ae 984 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
985 if (!ret) {
986 vty_out(vty, "%% Malformed bgp cluster identifier\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
718e3744 989
d62a17ae 990 bgp_cluster_id_set(bgp, &cluster);
991 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 992
d62a17ae 993 return CMD_SUCCESS;
718e3744 994}
995
718e3744 996DEFUN (no_bgp_cluster_id,
997 no_bgp_cluster_id_cmd,
c7178fe7 998 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 999 NO_STR
1000 BGP_STR
838758ac
DW
1001 "Configure Route-Reflector Cluster-id\n"
1002 "Route-Reflector Cluster-id in IP address format\n"
1003 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1004{
d62a17ae 1005 VTY_DECLVAR_CONTEXT(bgp, bgp);
1006 bgp_cluster_id_unset(bgp);
1007 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1008
d62a17ae 1009 return CMD_SUCCESS;
718e3744 1010}
1011
718e3744 1012DEFUN (bgp_confederation_identifier,
1013 bgp_confederation_identifier_cmd,
9ccf14f7 1014 "bgp confederation identifier (1-4294967295)",
718e3744 1015 "BGP specific commands\n"
1016 "AS confederation parameters\n"
1017 "AS number\n"
1018 "Set routing domain confederation AS\n")
1019{
d62a17ae 1020 VTY_DECLVAR_CONTEXT(bgp, bgp);
1021 int idx_number = 3;
1022 as_t as;
718e3744 1023
d62a17ae 1024 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1025
d62a17ae 1026 bgp_confederation_id_set(bgp, as);
718e3744 1027
d62a17ae 1028 return CMD_SUCCESS;
718e3744 1029}
1030
1031DEFUN (no_bgp_confederation_identifier,
1032 no_bgp_confederation_identifier_cmd,
838758ac 1033 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1034 NO_STR
1035 "BGP specific commands\n"
1036 "AS confederation parameters\n"
3a2d747c
QY
1037 "AS number\n"
1038 "Set routing domain confederation AS\n")
718e3744 1039{
d62a17ae 1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
1041 bgp_confederation_id_unset(bgp);
718e3744 1042
d62a17ae 1043 return CMD_SUCCESS;
718e3744 1044}
1045
718e3744 1046DEFUN (bgp_confederation_peers,
1047 bgp_confederation_peers_cmd,
12dcf78e 1048 "bgp confederation peers (1-4294967295)...",
718e3744 1049 "BGP specific commands\n"
1050 "AS confederation parameters\n"
1051 "Peer ASs in BGP confederation\n"
1052 AS_STR)
1053{
d62a17ae 1054 VTY_DECLVAR_CONTEXT(bgp, bgp);
1055 int idx_asn = 3;
1056 as_t as;
1057 int i;
718e3744 1058
d62a17ae 1059 for (i = idx_asn; i < argc; i++) {
1060 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1061
d62a17ae 1062 if (bgp->as == as) {
1063 vty_out(vty,
1064 "%% Local member-AS not allowed in confed peer list\n");
1065 continue;
1066 }
718e3744 1067
d62a17ae 1068 bgp_confederation_peers_add(bgp, as);
1069 }
1070 return CMD_SUCCESS;
718e3744 1071}
1072
1073DEFUN (no_bgp_confederation_peers,
1074 no_bgp_confederation_peers_cmd,
e83a9414 1075 "no bgp confederation peers (1-4294967295)...",
718e3744 1076 NO_STR
1077 "BGP specific commands\n"
1078 "AS confederation parameters\n"
1079 "Peer ASs in BGP confederation\n"
1080 AS_STR)
1081{
d62a17ae 1082 VTY_DECLVAR_CONTEXT(bgp, bgp);
1083 int idx_asn = 4;
1084 as_t as;
1085 int i;
718e3744 1086
d62a17ae 1087 for (i = idx_asn; i < argc; i++) {
1088 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1089
d62a17ae 1090 bgp_confederation_peers_remove(bgp, as);
1091 }
1092 return CMD_SUCCESS;
718e3744 1093}
6b0655a2 1094
5e242b0d
DS
1095/**
1096 * Central routine for maximum-paths configuration.
1097 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1098 * @set: 1 for setting values, 0 for removing the max-paths config.
1099 */
d62a17ae 1100static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1101 const char *mpaths, u_int16_t options,
1102 int set)
1103{
1104 VTY_DECLVAR_CONTEXT(bgp, bgp);
1105 u_int16_t maxpaths = 0;
1106 int ret;
1107 afi_t afi;
1108 safi_t safi;
1109
1110 afi = bgp_node_afi(vty);
1111 safi = bgp_node_safi(vty);
1112
1113 if (set) {
1114 maxpaths = strtol(mpaths, NULL, 10);
1115 if (maxpaths > multipath_num) {
1116 vty_out(vty,
1117 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1118 maxpaths, multipath_num);
1119 return CMD_WARNING_CONFIG_FAILED;
1120 }
1121 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1122 options);
1123 } else
1124 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1125
1126 if (ret < 0) {
1127 vty_out(vty,
1128 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1129 (set == 1) ? "" : "un",
1130 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1131 maxpaths, afi, safi);
1132 return CMD_WARNING_CONFIG_FAILED;
1133 }
1134
1135 bgp_recalculate_all_bestpaths(bgp);
1136
1137 return CMD_SUCCESS;
165b5fff
JB
1138}
1139
abc920f8
DS
1140DEFUN (bgp_maxmed_admin,
1141 bgp_maxmed_admin_cmd,
1142 "bgp max-med administrative ",
1143 BGP_STR
1144 "Advertise routes with max-med\n"
1145 "Administratively applied, for an indefinite period\n")
1146{
d62a17ae 1147 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1148
d62a17ae 1149 bgp->v_maxmed_admin = 1;
1150 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1151
d62a17ae 1152 bgp_maxmed_update(bgp);
abc920f8 1153
d62a17ae 1154 return CMD_SUCCESS;
abc920f8
DS
1155}
1156
1157DEFUN (bgp_maxmed_admin_medv,
1158 bgp_maxmed_admin_medv_cmd,
4668a151 1159 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1160 BGP_STR
1161 "Advertise routes with max-med\n"
1162 "Administratively applied, for an indefinite period\n"
1163 "Max MED value to be used\n")
1164{
d62a17ae 1165 VTY_DECLVAR_CONTEXT(bgp, bgp);
1166 int idx_number = 3;
abc920f8 1167
d62a17ae 1168 bgp->v_maxmed_admin = 1;
1169 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1170
d62a17ae 1171 bgp_maxmed_update(bgp);
abc920f8 1172
d62a17ae 1173 return CMD_SUCCESS;
abc920f8
DS
1174}
1175
1176DEFUN (no_bgp_maxmed_admin,
1177 no_bgp_maxmed_admin_cmd,
4668a151 1178 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1179 NO_STR
1180 BGP_STR
1181 "Advertise routes with max-med\n"
838758ac
DW
1182 "Administratively applied, for an indefinite period\n"
1183 "Max MED value to be used\n")
abc920f8 1184{
d62a17ae 1185 VTY_DECLVAR_CONTEXT(bgp, bgp);
1186 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1187 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1188 bgp_maxmed_update(bgp);
abc920f8 1189
d62a17ae 1190 return CMD_SUCCESS;
abc920f8
DS
1191}
1192
abc920f8
DS
1193DEFUN (bgp_maxmed_onstartup,
1194 bgp_maxmed_onstartup_cmd,
4668a151 1195 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1196 BGP_STR
1197 "Advertise routes with max-med\n"
1198 "Effective on a startup\n"
1199 "Time (seconds) period for max-med\n"
1200 "Max MED value to be used\n")
1201{
d62a17ae 1202 VTY_DECLVAR_CONTEXT(bgp, bgp);
1203 int idx = 0;
4668a151 1204
d62a17ae 1205 argv_find(argv, argc, "(5-86400)", &idx);
1206 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1207 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1208 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1209 else
1210 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1211
d62a17ae 1212 bgp_maxmed_update(bgp);
abc920f8 1213
d62a17ae 1214 return CMD_SUCCESS;
abc920f8
DS
1215}
1216
1217DEFUN (no_bgp_maxmed_onstartup,
1218 no_bgp_maxmed_onstartup_cmd,
4668a151 1219 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1220 NO_STR
1221 BGP_STR
1222 "Advertise routes with max-med\n"
838758ac
DW
1223 "Effective on a startup\n"
1224 "Time (seconds) period for max-med\n"
1225 "Max MED value to be used\n")
abc920f8 1226{
d62a17ae 1227 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1228
d62a17ae 1229 /* Cancel max-med onstartup if its on */
1230 if (bgp->t_maxmed_onstartup) {
1231 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1232 bgp->maxmed_onstartup_over = 1;
1233 }
abc920f8 1234
d62a17ae 1235 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1236 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1237
d62a17ae 1238 bgp_maxmed_update(bgp);
abc920f8 1239
d62a17ae 1240 return CMD_SUCCESS;
abc920f8
DS
1241}
1242
d62a17ae 1243static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1244 const char *wait)
f188f2c4 1245{
d62a17ae 1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
1247 u_int16_t update_delay;
1248 u_int16_t establish_wait;
f188f2c4 1249
d62a17ae 1250 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1251
d62a17ae 1252 if (!wait) /* update-delay <delay> */
1253 {
1254 bgp->v_update_delay = update_delay;
1255 bgp->v_establish_wait = bgp->v_update_delay;
1256 return CMD_SUCCESS;
1257 }
f188f2c4 1258
d62a17ae 1259 /* update-delay <delay> <establish-wait> */
1260 establish_wait = atoi(wait);
1261 if (update_delay < establish_wait) {
1262 vty_out(vty,
1263 "%%Failed: update-delay less than the establish-wait!\n");
1264 return CMD_WARNING_CONFIG_FAILED;
1265 }
f188f2c4 1266
d62a17ae 1267 bgp->v_update_delay = update_delay;
1268 bgp->v_establish_wait = establish_wait;
f188f2c4 1269
d62a17ae 1270 return CMD_SUCCESS;
f188f2c4
DS
1271}
1272
d62a17ae 1273static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1274{
d62a17ae 1275 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1276
d62a17ae 1277 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1278 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1279
d62a17ae 1280 return CMD_SUCCESS;
f188f2c4
DS
1281}
1282
2b791107 1283void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1284{
d62a17ae 1285 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1286 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1287 if (bgp->v_update_delay != bgp->v_establish_wait)
1288 vty_out(vty, " %d", bgp->v_establish_wait);
1289 vty_out(vty, "\n");
1290 }
f188f2c4
DS
1291}
1292
1293
1294/* Update-delay configuration */
1295DEFUN (bgp_update_delay,
1296 bgp_update_delay_cmd,
6147e2c6 1297 "update-delay (0-3600)",
f188f2c4
DS
1298 "Force initial delay for best-path and updates\n"
1299 "Seconds\n")
1300{
d62a17ae 1301 int idx_number = 1;
1302 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1303}
1304
1305DEFUN (bgp_update_delay_establish_wait,
1306 bgp_update_delay_establish_wait_cmd,
6147e2c6 1307 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1308 "Force initial delay for best-path and updates\n"
1309 "Seconds\n"
f188f2c4
DS
1310 "Seconds\n")
1311{
d62a17ae 1312 int idx_number = 1;
1313 int idx_number_2 = 2;
1314 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1315 argv[idx_number_2]->arg);
f188f2c4
DS
1316}
1317
1318/* Update-delay deconfiguration */
1319DEFUN (no_bgp_update_delay,
1320 no_bgp_update_delay_cmd,
838758ac
DW
1321 "no update-delay [(0-3600) [(1-3600)]]",
1322 NO_STR
f188f2c4 1323 "Force initial delay for best-path and updates\n"
838758ac 1324 "Seconds\n"
7111c1a0 1325 "Seconds\n")
f188f2c4 1326{
d62a17ae 1327 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1328}
1329
5e242b0d 1330
d62a17ae 1331static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1332 char set)
cb1faec9 1333{
d62a17ae 1334 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1335
555e09d4
QY
1336 if (set) {
1337 uint32_t quanta = strtoul(num, NULL, 10);
1338 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1339 memory_order_relaxed);
1340 } else {
1341 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1342 memory_order_relaxed);
1343 }
1344
1345 return CMD_SUCCESS;
1346}
1347
1348static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1349 char set)
1350{
1351 VTY_DECLVAR_CONTEXT(bgp, bgp);
1352
1353 if (set) {
1354 uint32_t quanta = strtoul(num, NULL, 10);
1355 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1356 memory_order_relaxed);
1357 } else {
1358 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1359 memory_order_relaxed);
1360 }
cb1faec9 1361
d62a17ae 1362 return CMD_SUCCESS;
cb1faec9
DS
1363}
1364
2b791107 1365void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1366{
555e09d4
QY
1367 uint32_t quanta =
1368 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1369 if (quanta != BGP_WRITE_PACKET_MAX)
1370 vty_out(vty, " write-quanta %d%s", quanta, VTY_NEWLINE);
cb1faec9
DS
1371}
1372
555e09d4
QY
1373void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1374{
1375 uint32_t quanta =
1376 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1377 if (quanta != BGP_READ_PACKET_MAX)
1378 vty_out(vty, " read-quanta %d%s", quanta, VTY_NEWLINE);
1379}
cb1faec9 1380
555e09d4 1381/* Packet quanta configuration */
cb1faec9
DS
1382DEFUN (bgp_wpkt_quanta,
1383 bgp_wpkt_quanta_cmd,
555e09d4 1384 "write-quanta (1-10)",
cb1faec9
DS
1385 "How many packets to write to peer socket per run\n"
1386 "Number of packets\n")
1387{
d62a17ae 1388 int idx_number = 1;
1389 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1390}
1391
cb1faec9
DS
1392DEFUN (no_bgp_wpkt_quanta,
1393 no_bgp_wpkt_quanta_cmd,
555e09d4 1394 "no write-quanta (1-10)",
d7fa34c1 1395 NO_STR
555e09d4 1396 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1397 "Number of packets\n")
1398{
d62a17ae 1399 int idx_number = 2;
1400 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1401}
1402
555e09d4
QY
1403DEFUN (bgp_rpkt_quanta,
1404 bgp_rpkt_quanta_cmd,
1405 "read-quanta (1-10)",
1406 "How many packets to read from peer socket per I/O cycle\n"
1407 "Number of packets\n")
1408{
1409 int idx_number = 1;
1410 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1411}
1412
1413DEFUN (no_bgp_rpkt_quanta,
1414 no_bgp_rpkt_quanta_cmd,
1415 "no read-quanta (1-10)",
1416 NO_STR
1417 "How many packets to read from peer socket per I/O cycle\n"
1418 "Number of packets\n")
1419{
1420 int idx_number = 2;
1421 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1422}
1423
2b791107 1424void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1425{
d62a17ae 1426 if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
1427 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1428}
1429
1430
1431DEFUN (bgp_coalesce_time,
1432 bgp_coalesce_time_cmd,
6147e2c6 1433 "coalesce-time (0-4294967295)",
3f9c7369
DS
1434 "Subgroup coalesce timer\n"
1435 "Subgroup coalesce timer value (in ms)\n")
1436{
d62a17ae 1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1438
d62a17ae 1439 int idx = 0;
1440 argv_find(argv, argc, "(0-4294967295)", &idx);
1441 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1442 return CMD_SUCCESS;
3f9c7369
DS
1443}
1444
1445DEFUN (no_bgp_coalesce_time,
1446 no_bgp_coalesce_time_cmd,
6147e2c6 1447 "no coalesce-time (0-4294967295)",
3a2d747c 1448 NO_STR
3f9c7369
DS
1449 "Subgroup coalesce timer\n"
1450 "Subgroup coalesce timer value (in ms)\n")
1451{
d62a17ae 1452 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1453
d62a17ae 1454 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1455 return CMD_SUCCESS;
3f9c7369
DS
1456}
1457
5e242b0d
DS
1458/* Maximum-paths configuration */
1459DEFUN (bgp_maxpaths,
1460 bgp_maxpaths_cmd,
6319fd63 1461 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1462 "Forward packets over multiple paths\n"
1463 "Number of paths\n")
1464{
d62a17ae 1465 int idx_number = 1;
1466 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1467 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1468}
1469
d62a17ae 1470ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1471 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1472 "Forward packets over multiple paths\n"
1473 "Number of paths\n")
596c17ba 1474
165b5fff
JB
1475DEFUN (bgp_maxpaths_ibgp,
1476 bgp_maxpaths_ibgp_cmd,
6319fd63 1477 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1478 "Forward packets over multiple paths\n"
1479 "iBGP-multipath\n"
1480 "Number of paths\n")
1481{
d62a17ae 1482 int idx_number = 2;
1483 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1484 argv[idx_number]->arg, 0, 1);
5e242b0d 1485}
165b5fff 1486
d62a17ae 1487ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1488 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1489 "Forward packets over multiple paths\n"
1490 "iBGP-multipath\n"
1491 "Number of paths\n")
596c17ba 1492
5e242b0d
DS
1493DEFUN (bgp_maxpaths_ibgp_cluster,
1494 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1495 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1496 "Forward packets over multiple paths\n"
1497 "iBGP-multipath\n"
1498 "Number of paths\n"
1499 "Match the cluster length\n")
1500{
d62a17ae 1501 int idx_number = 2;
1502 return bgp_maxpaths_config_vty(
1503 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1504 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1505}
1506
d62a17ae 1507ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1508 "maximum-paths ibgp " CMD_RANGE_STR(
1509 1, MULTIPATH_NUM) " equal-cluster-length",
1510 "Forward packets over multiple paths\n"
1511 "iBGP-multipath\n"
1512 "Number of paths\n"
1513 "Match the cluster length\n")
596c17ba 1514
165b5fff
JB
1515DEFUN (no_bgp_maxpaths,
1516 no_bgp_maxpaths_cmd,
6319fd63 1517 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1518 NO_STR
1519 "Forward packets over multiple paths\n"
1520 "Number of paths\n")
1521{
d62a17ae 1522 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1523}
1524
d62a17ae 1525ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
9d303b37 1526 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1527 "Forward packets over multiple paths\n"
1528 "Number of paths\n")
596c17ba 1529
165b5fff
JB
1530DEFUN (no_bgp_maxpaths_ibgp,
1531 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1532 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1533 NO_STR
1534 "Forward packets over multiple paths\n"
1535 "iBGP-multipath\n"
838758ac
DW
1536 "Number of paths\n"
1537 "Match the cluster length\n")
165b5fff 1538{
d62a17ae 1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1540}
1541
d62a17ae 1542ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1543 "no maximum-paths ibgp [" CMD_RANGE_STR(
1544 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1545 NO_STR
1546 "Forward packets over multiple paths\n"
1547 "iBGP-multipath\n"
1548 "Number of paths\n"
1549 "Match the cluster length\n")
596c17ba 1550
2b791107 1551void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1552 safi_t safi)
165b5fff 1553{
d62a17ae 1554 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1555 vty_out(vty, " maximum-paths %d\n",
1556 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1557 }
165b5fff 1558
d62a17ae 1559 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1560 vty_out(vty, " maximum-paths ibgp %d",
1561 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1562 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1563 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1564 vty_out(vty, " equal-cluster-length");
1565 vty_out(vty, "\n");
1566 }
165b5fff 1567}
6b0655a2 1568
718e3744 1569/* BGP timers. */
1570
1571DEFUN (bgp_timers,
1572 bgp_timers_cmd,
6147e2c6 1573 "timers bgp (0-65535) (0-65535)",
718e3744 1574 "Adjust routing timers\n"
1575 "BGP timers\n"
1576 "Keepalive interval\n"
1577 "Holdtime\n")
1578{
d62a17ae 1579 VTY_DECLVAR_CONTEXT(bgp, bgp);
1580 int idx_number = 2;
1581 int idx_number_2 = 3;
1582 unsigned long keepalive = 0;
1583 unsigned long holdtime = 0;
718e3744 1584
d62a17ae 1585 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1586 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1587
d62a17ae 1588 /* Holdtime value check. */
1589 if (holdtime < 3 && holdtime != 0) {
1590 vty_out(vty,
1591 "%% hold time value must be either 0 or greater than 3\n");
1592 return CMD_WARNING_CONFIG_FAILED;
1593 }
718e3744 1594
d62a17ae 1595 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1596
d62a17ae 1597 return CMD_SUCCESS;
718e3744 1598}
1599
1600DEFUN (no_bgp_timers,
1601 no_bgp_timers_cmd,
838758ac 1602 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1603 NO_STR
1604 "Adjust routing timers\n"
838758ac
DW
1605 "BGP timers\n"
1606 "Keepalive interval\n"
1607 "Holdtime\n")
718e3744 1608{
d62a17ae 1609 VTY_DECLVAR_CONTEXT(bgp, bgp);
1610 bgp_timers_unset(bgp);
718e3744 1611
d62a17ae 1612 return CMD_SUCCESS;
718e3744 1613}
1614
6b0655a2 1615
718e3744 1616DEFUN (bgp_client_to_client_reflection,
1617 bgp_client_to_client_reflection_cmd,
1618 "bgp client-to-client reflection",
1619 "BGP specific commands\n"
1620 "Configure client to client route reflection\n"
1621 "reflection of routes allowed\n")
1622{
d62a17ae 1623 VTY_DECLVAR_CONTEXT(bgp, bgp);
1624 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1625 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1626
d62a17ae 1627 return CMD_SUCCESS;
718e3744 1628}
1629
1630DEFUN (no_bgp_client_to_client_reflection,
1631 no_bgp_client_to_client_reflection_cmd,
1632 "no bgp client-to-client reflection",
1633 NO_STR
1634 "BGP specific commands\n"
1635 "Configure client to client route reflection\n"
1636 "reflection of routes allowed\n")
1637{
d62a17ae 1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1640 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1641
d62a17ae 1642 return CMD_SUCCESS;
718e3744 1643}
1644
1645/* "bgp always-compare-med" configuration. */
1646DEFUN (bgp_always_compare_med,
1647 bgp_always_compare_med_cmd,
1648 "bgp always-compare-med",
1649 "BGP specific commands\n"
1650 "Allow comparing MED from different neighbors\n")
1651{
d62a17ae 1652 VTY_DECLVAR_CONTEXT(bgp, bgp);
1653 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1654 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1655
d62a17ae 1656 return CMD_SUCCESS;
718e3744 1657}
1658
1659DEFUN (no_bgp_always_compare_med,
1660 no_bgp_always_compare_med_cmd,
1661 "no bgp always-compare-med",
1662 NO_STR
1663 "BGP specific commands\n"
1664 "Allow comparing MED from different neighbors\n")
1665{
d62a17ae 1666 VTY_DECLVAR_CONTEXT(bgp, bgp);
1667 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1668 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1669
d62a17ae 1670 return CMD_SUCCESS;
718e3744 1671}
6b0655a2 1672
718e3744 1673/* "bgp deterministic-med" configuration. */
1674DEFUN (bgp_deterministic_med,
1675 bgp_deterministic_med_cmd,
1676 "bgp deterministic-med",
1677 "BGP specific commands\n"
1678 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1679{
d62a17ae 1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1681
d62a17ae 1682 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1683 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1684 bgp_recalculate_all_bestpaths(bgp);
1685 }
7aafcaca 1686
d62a17ae 1687 return CMD_SUCCESS;
718e3744 1688}
1689
1690DEFUN (no_bgp_deterministic_med,
1691 no_bgp_deterministic_med_cmd,
1692 "no bgp deterministic-med",
1693 NO_STR
1694 "BGP specific commands\n"
1695 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1696{
d62a17ae 1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 int bestpath_per_as_used;
1699 afi_t afi;
1700 safi_t safi;
1701 struct peer *peer;
1702 struct listnode *node, *nnode;
1703
1704 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1705 bestpath_per_as_used = 0;
1706
1707 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1708 FOREACH_AFI_SAFI (afi, safi)
1709 if (CHECK_FLAG(
1710 peer->af_flags[afi][safi],
1711 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1712 bestpath_per_as_used = 1;
1713 break;
1714 }
d62a17ae 1715
1716 if (bestpath_per_as_used)
1717 break;
1718 }
1719
1720 if (bestpath_per_as_used) {
1721 vty_out(vty,
1722 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1723 return CMD_WARNING_CONFIG_FAILED;
1724 } else {
1725 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1726 bgp_recalculate_all_bestpaths(bgp);
1727 }
1728 }
1729
1730 return CMD_SUCCESS;
718e3744 1731}
538621f2 1732
1733/* "bgp graceful-restart" configuration. */
1734DEFUN (bgp_graceful_restart,
1735 bgp_graceful_restart_cmd,
1736 "bgp graceful-restart",
1737 "BGP specific commands\n"
1738 "Graceful restart capability parameters\n")
1739{
d62a17ae 1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1742 return CMD_SUCCESS;
538621f2 1743}
1744
1745DEFUN (no_bgp_graceful_restart,
1746 no_bgp_graceful_restart_cmd,
1747 "no bgp graceful-restart",
1748 NO_STR
1749 "BGP specific commands\n"
1750 "Graceful restart capability parameters\n")
1751{
d62a17ae 1752 VTY_DECLVAR_CONTEXT(bgp, bgp);
1753 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1754 return CMD_SUCCESS;
538621f2 1755}
1756
93406d87 1757DEFUN (bgp_graceful_restart_stalepath_time,
1758 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1759 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1760 "BGP specific commands\n"
1761 "Graceful restart capability parameters\n"
1762 "Set the max time to hold onto restarting peer's stale paths\n"
1763 "Delay value (seconds)\n")
1764{
d62a17ae 1765 VTY_DECLVAR_CONTEXT(bgp, bgp);
1766 int idx_number = 3;
1767 u_int32_t stalepath;
93406d87 1768
d62a17ae 1769 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1770 bgp->stalepath_time = stalepath;
1771 return CMD_SUCCESS;
93406d87 1772}
1773
eb6f1b41
PG
1774DEFUN (bgp_graceful_restart_restart_time,
1775 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1776 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1777 "BGP specific commands\n"
1778 "Graceful restart capability parameters\n"
1779 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1780 "Delay value (seconds)\n")
1781{
d62a17ae 1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 int idx_number = 3;
1784 u_int32_t restart;
eb6f1b41 1785
d62a17ae 1786 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1787 bgp->restart_time = restart;
1788 return CMD_SUCCESS;
eb6f1b41
PG
1789}
1790
93406d87 1791DEFUN (no_bgp_graceful_restart_stalepath_time,
1792 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1793 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1794 NO_STR
1795 "BGP specific commands\n"
1796 "Graceful restart capability parameters\n"
838758ac
DW
1797 "Set the max time to hold onto restarting peer's stale paths\n"
1798 "Delay value (seconds)\n")
93406d87 1799{
d62a17ae 1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1801
d62a17ae 1802 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1803 return CMD_SUCCESS;
93406d87 1804}
1805
eb6f1b41
PG
1806DEFUN (no_bgp_graceful_restart_restart_time,
1807 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1808 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1809 NO_STR
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n"
838758ac
DW
1812 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1813 "Delay value (seconds)\n")
eb6f1b41 1814{
d62a17ae 1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1816
d62a17ae 1817 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1818 return CMD_SUCCESS;
eb6f1b41
PG
1819}
1820
43fc21b3
JC
1821DEFUN (bgp_graceful_restart_preserve_fw,
1822 bgp_graceful_restart_preserve_fw_cmd,
1823 "bgp graceful-restart preserve-fw-state",
1824 "BGP specific commands\n"
1825 "Graceful restart capability parameters\n"
1826 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1830 return CMD_SUCCESS;
43fc21b3
JC
1831}
1832
1833DEFUN (no_bgp_graceful_restart_preserve_fw,
1834 no_bgp_graceful_restart_preserve_fw_cmd,
1835 "no bgp graceful-restart preserve-fw-state",
1836 NO_STR
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n"
1839 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1840{
d62a17ae 1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1843 return CMD_SUCCESS;
43fc21b3
JC
1844}
1845
7f323236
DW
1846static void bgp_redistribute_redo(struct bgp *bgp)
1847{
1848 afi_t afi;
1849 int i;
1850 struct list *red_list;
1851 struct listnode *node;
1852 struct bgp_redist *red;
1853
1854 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1855 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1856
1857 red_list = bgp->redist[afi][i];
1858 if (!red_list)
1859 continue;
1860
1861 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1862 bgp_redistribute_resend(bgp, afi, i,
1863 red->instance);
1864 }
1865 }
1866 }
1867}
1868
1869/* "bgp graceful-shutdown" configuration */
1870DEFUN (bgp_graceful_shutdown,
1871 bgp_graceful_shutdown_cmd,
1872 "bgp graceful-shutdown",
1873 BGP_STR
1874 "Graceful shutdown parameters\n")
1875{
1876 VTY_DECLVAR_CONTEXT(bgp, bgp);
1877
1878 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1879 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1880 bgp_static_redo_import_check(bgp);
1881 bgp_redistribute_redo(bgp);
1882 bgp_clear_star_soft_out(vty, bgp->name);
1883 bgp_clear_star_soft_in(vty, bgp->name);
1884 }
1885
1886 return CMD_SUCCESS;
1887}
1888
1889DEFUN (no_bgp_graceful_shutdown,
1890 no_bgp_graceful_shutdown_cmd,
1891 "no bgp graceful-shutdown",
1892 NO_STR
1893 BGP_STR
1894 "Graceful shutdown parameters\n")
1895{
1896 VTY_DECLVAR_CONTEXT(bgp, bgp);
1897
1898 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1899 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1900 bgp_static_redo_import_check(bgp);
1901 bgp_redistribute_redo(bgp);
1902 bgp_clear_star_soft_out(vty, bgp->name);
1903 bgp_clear_star_soft_in(vty, bgp->name);
1904 }
1905
1906 return CMD_SUCCESS;
1907}
1908
718e3744 1909/* "bgp fast-external-failover" configuration. */
1910DEFUN (bgp_fast_external_failover,
1911 bgp_fast_external_failover_cmd,
1912 "bgp fast-external-failover",
1913 BGP_STR
1914 "Immediately reset session if a link to a directly connected external peer goes down\n")
1915{
d62a17ae 1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1918 return CMD_SUCCESS;
718e3744 1919}
1920
1921DEFUN (no_bgp_fast_external_failover,
1922 no_bgp_fast_external_failover_cmd,
1923 "no bgp fast-external-failover",
1924 NO_STR
1925 BGP_STR
1926 "Immediately reset session if a link to a directly connected external peer goes down\n")
1927{
d62a17ae 1928 VTY_DECLVAR_CONTEXT(bgp, bgp);
1929 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1930 return CMD_SUCCESS;
718e3744 1931}
6b0655a2 1932
718e3744 1933/* "bgp enforce-first-as" configuration. */
1934DEFUN (bgp_enforce_first_as,
1935 bgp_enforce_first_as_cmd,
1936 "bgp enforce-first-as",
1937 BGP_STR
1938 "Enforce the first AS for EBGP routes\n")
1939{
d62a17ae 1940 VTY_DECLVAR_CONTEXT(bgp, bgp);
1941 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1942 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1943
d62a17ae 1944 return CMD_SUCCESS;
718e3744 1945}
1946
1947DEFUN (no_bgp_enforce_first_as,
1948 no_bgp_enforce_first_as_cmd,
1949 "no bgp enforce-first-as",
1950 NO_STR
1951 BGP_STR
1952 "Enforce the first AS for EBGP routes\n")
1953{
d62a17ae 1954 VTY_DECLVAR_CONTEXT(bgp, bgp);
1955 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1956 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1957
d62a17ae 1958 return CMD_SUCCESS;
718e3744 1959}
6b0655a2 1960
718e3744 1961/* "bgp bestpath compare-routerid" configuration. */
1962DEFUN (bgp_bestpath_compare_router_id,
1963 bgp_bestpath_compare_router_id_cmd,
1964 "bgp bestpath compare-routerid",
1965 "BGP specific commands\n"
1966 "Change the default bestpath selection\n"
1967 "Compare router-id for identical EBGP paths\n")
1968{
d62a17ae 1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1971 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1972
d62a17ae 1973 return CMD_SUCCESS;
718e3744 1974}
1975
1976DEFUN (no_bgp_bestpath_compare_router_id,
1977 no_bgp_bestpath_compare_router_id_cmd,
1978 "no bgp bestpath compare-routerid",
1979 NO_STR
1980 "BGP specific commands\n"
1981 "Change the default bestpath selection\n"
1982 "Compare router-id for identical EBGP paths\n")
1983{
d62a17ae 1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1986 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1987
d62a17ae 1988 return CMD_SUCCESS;
718e3744 1989}
6b0655a2 1990
718e3744 1991/* "bgp bestpath as-path ignore" configuration. */
1992DEFUN (bgp_bestpath_aspath_ignore,
1993 bgp_bestpath_aspath_ignore_cmd,
1994 "bgp bestpath as-path ignore",
1995 "BGP specific commands\n"
1996 "Change the default bestpath selection\n"
1997 "AS-path attribute\n"
1998 "Ignore as-path length in selecting a route\n")
1999{
d62a17ae 2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2002 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2003
d62a17ae 2004 return CMD_SUCCESS;
718e3744 2005}
2006
2007DEFUN (no_bgp_bestpath_aspath_ignore,
2008 no_bgp_bestpath_aspath_ignore_cmd,
2009 "no bgp bestpath as-path ignore",
2010 NO_STR
2011 "BGP specific commands\n"
2012 "Change the default bestpath selection\n"
2013 "AS-path attribute\n"
2014 "Ignore as-path length in selecting a route\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2018 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2019
d62a17ae 2020 return CMD_SUCCESS;
718e3744 2021}
6b0655a2 2022
6811845b 2023/* "bgp bestpath as-path confed" configuration. */
2024DEFUN (bgp_bestpath_aspath_confed,
2025 bgp_bestpath_aspath_confed_cmd,
2026 "bgp bestpath as-path confed",
2027 "BGP specific commands\n"
2028 "Change the default bestpath selection\n"
2029 "AS-path attribute\n"
2030 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2031{
d62a17ae 2032 VTY_DECLVAR_CONTEXT(bgp, bgp);
2033 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2034 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2035
d62a17ae 2036 return CMD_SUCCESS;
6811845b 2037}
2038
2039DEFUN (no_bgp_bestpath_aspath_confed,
2040 no_bgp_bestpath_aspath_confed_cmd,
2041 "no bgp bestpath as-path confed",
2042 NO_STR
2043 "BGP specific commands\n"
2044 "Change the default bestpath selection\n"
2045 "AS-path attribute\n"
2046 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2047{
d62a17ae 2048 VTY_DECLVAR_CONTEXT(bgp, bgp);
2049 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2050 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2051
d62a17ae 2052 return CMD_SUCCESS;
6811845b 2053}
6b0655a2 2054
2fdd455c
PM
2055/* "bgp bestpath as-path multipath-relax" configuration. */
2056DEFUN (bgp_bestpath_aspath_multipath_relax,
2057 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2058 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2059 "BGP specific commands\n"
2060 "Change the default bestpath selection\n"
2061 "AS-path attribute\n"
2062 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2063 "Generate an AS_SET\n"
16fc1eec
DS
2064 "Do not generate an AS_SET\n")
2065{
d62a17ae 2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 int idx = 0;
2068 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2069
d62a17ae 2070 /* no-as-set is now the default behavior so we can silently
2071 * ignore it */
2072 if (argv_find(argv, argc, "as-set", &idx))
2073 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2074 else
2075 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2076
d62a17ae 2077 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2078
d62a17ae 2079 return CMD_SUCCESS;
16fc1eec
DS
2080}
2081
219178b6
DW
2082DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2083 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2084 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2085 NO_STR
2086 "BGP specific commands\n"
2087 "Change the default bestpath selection\n"
2088 "AS-path attribute\n"
2089 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2090 "Generate an AS_SET\n"
16fc1eec
DS
2091 "Do not generate an AS_SET\n")
2092{
d62a17ae 2093 VTY_DECLVAR_CONTEXT(bgp, bgp);
2094 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2095 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2096 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2097
d62a17ae 2098 return CMD_SUCCESS;
2fdd455c 2099}
6b0655a2 2100
848973c7 2101/* "bgp log-neighbor-changes" configuration. */
2102DEFUN (bgp_log_neighbor_changes,
2103 bgp_log_neighbor_changes_cmd,
2104 "bgp log-neighbor-changes",
2105 "BGP specific commands\n"
2106 "Log neighbor up/down and reset reason\n")
2107{
d62a17ae 2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2110 return CMD_SUCCESS;
848973c7 2111}
2112
2113DEFUN (no_bgp_log_neighbor_changes,
2114 no_bgp_log_neighbor_changes_cmd,
2115 "no bgp log-neighbor-changes",
2116 NO_STR
2117 "BGP specific commands\n"
2118 "Log neighbor up/down and reset reason\n")
2119{
d62a17ae 2120 VTY_DECLVAR_CONTEXT(bgp, bgp);
2121 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2122 return CMD_SUCCESS;
848973c7 2123}
6b0655a2 2124
718e3744 2125/* "bgp bestpath med" configuration. */
2126DEFUN (bgp_bestpath_med,
2127 bgp_bestpath_med_cmd,
2d8c1a4d 2128 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2129 "BGP specific commands\n"
2130 "Change the default bestpath selection\n"
2131 "MED attribute\n"
2132 "Compare MED among confederation paths\n"
838758ac
DW
2133 "Treat missing MED as the least preferred one\n"
2134 "Treat missing MED as the least preferred one\n"
2135 "Compare MED among confederation paths\n")
718e3744 2136{
d62a17ae 2137 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2138
d62a17ae 2139 int idx = 0;
2140 if (argv_find(argv, argc, "confed", &idx))
2141 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2142 idx = 0;
2143 if (argv_find(argv, argc, "missing-as-worst", &idx))
2144 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2145
d62a17ae 2146 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2147
d62a17ae 2148 return CMD_SUCCESS;
718e3744 2149}
2150
718e3744 2151DEFUN (no_bgp_bestpath_med,
2152 no_bgp_bestpath_med_cmd,
2d8c1a4d 2153 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2154 NO_STR
2155 "BGP specific commands\n"
2156 "Change the default bestpath selection\n"
2157 "MED attribute\n"
2158 "Compare MED among confederation paths\n"
3a2d747c
QY
2159 "Treat missing MED as the least preferred one\n"
2160 "Treat missing MED as the least preferred one\n"
2161 "Compare MED among confederation paths\n")
718e3744 2162{
d62a17ae 2163 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2164
d62a17ae 2165 int idx = 0;
2166 if (argv_find(argv, argc, "confed", &idx))
2167 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2168 idx = 0;
2169 if (argv_find(argv, argc, "missing-as-worst", &idx))
2170 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2171
d62a17ae 2172 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2173
d62a17ae 2174 return CMD_SUCCESS;
718e3744 2175}
2176
718e3744 2177/* "no bgp default ipv4-unicast". */
2178DEFUN (no_bgp_default_ipv4_unicast,
2179 no_bgp_default_ipv4_unicast_cmd,
2180 "no bgp default ipv4-unicast",
2181 NO_STR
2182 "BGP specific commands\n"
2183 "Configure BGP defaults\n"
2184 "Activate ipv4-unicast for a peer by default\n")
2185{
d62a17ae 2186 VTY_DECLVAR_CONTEXT(bgp, bgp);
2187 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2188 return CMD_SUCCESS;
718e3744 2189}
2190
2191DEFUN (bgp_default_ipv4_unicast,
2192 bgp_default_ipv4_unicast_cmd,
2193 "bgp default ipv4-unicast",
2194 "BGP specific commands\n"
2195 "Configure BGP defaults\n"
2196 "Activate ipv4-unicast for a peer by default\n")
2197{
d62a17ae 2198 VTY_DECLVAR_CONTEXT(bgp, bgp);
2199 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2200 return CMD_SUCCESS;
718e3744 2201}
6b0655a2 2202
04b6bdc0
DW
2203/* Display hostname in certain command outputs */
2204DEFUN (bgp_default_show_hostname,
2205 bgp_default_show_hostname_cmd,
2206 "bgp default show-hostname",
2207 "BGP specific commands\n"
2208 "Configure BGP defaults\n"
2209 "Show hostname in certain command ouputs\n")
2210{
d62a17ae 2211 VTY_DECLVAR_CONTEXT(bgp, bgp);
2212 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2213 return CMD_SUCCESS;
04b6bdc0
DW
2214}
2215
2216DEFUN (no_bgp_default_show_hostname,
2217 no_bgp_default_show_hostname_cmd,
2218 "no bgp default show-hostname",
2219 NO_STR
2220 "BGP specific commands\n"
2221 "Configure BGP defaults\n"
2222 "Show hostname in certain command ouputs\n")
2223{
d62a17ae 2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
2225 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2226 return CMD_SUCCESS;
04b6bdc0
DW
2227}
2228
8233ef81 2229/* "bgp network import-check" configuration. */
718e3744 2230DEFUN (bgp_network_import_check,
2231 bgp_network_import_check_cmd,
5623e905 2232 "bgp network import-check",
718e3744 2233 "BGP specific commands\n"
2234 "BGP network command\n"
5623e905 2235 "Check BGP network route exists in IGP\n")
718e3744 2236{
d62a17ae 2237 VTY_DECLVAR_CONTEXT(bgp, bgp);
2238 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2239 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2240 bgp_static_redo_import_check(bgp);
2241 }
078430f6 2242
d62a17ae 2243 return CMD_SUCCESS;
718e3744 2244}
2245
d62a17ae 2246ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2247 "bgp network import-check exact",
2248 "BGP specific commands\n"
2249 "BGP network command\n"
2250 "Check BGP network route exists in IGP\n"
2251 "Match route precisely\n")
8233ef81 2252
718e3744 2253DEFUN (no_bgp_network_import_check,
2254 no_bgp_network_import_check_cmd,
5623e905 2255 "no bgp network import-check",
718e3744 2256 NO_STR
2257 "BGP specific commands\n"
2258 "BGP network command\n"
2259 "Check BGP network route exists in IGP\n")
2260{
d62a17ae 2261 VTY_DECLVAR_CONTEXT(bgp, bgp);
2262 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2263 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2264 bgp_static_redo_import_check(bgp);
2265 }
5623e905 2266
d62a17ae 2267 return CMD_SUCCESS;
718e3744 2268}
6b0655a2 2269
718e3744 2270DEFUN (bgp_default_local_preference,
2271 bgp_default_local_preference_cmd,
6147e2c6 2272 "bgp default local-preference (0-4294967295)",
718e3744 2273 "BGP specific commands\n"
2274 "Configure BGP defaults\n"
2275 "local preference (higher=more preferred)\n"
2276 "Configure default local preference value\n")
2277{
d62a17ae 2278 VTY_DECLVAR_CONTEXT(bgp, bgp);
2279 int idx_number = 3;
2280 u_int32_t local_pref;
718e3744 2281
d62a17ae 2282 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2283
d62a17ae 2284 bgp_default_local_preference_set(bgp, local_pref);
2285 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2286
d62a17ae 2287 return CMD_SUCCESS;
718e3744 2288}
2289
2290DEFUN (no_bgp_default_local_preference,
2291 no_bgp_default_local_preference_cmd,
838758ac 2292 "no bgp default local-preference [(0-4294967295)]",
718e3744 2293 NO_STR
2294 "BGP specific commands\n"
2295 "Configure BGP defaults\n"
838758ac
DW
2296 "local preference (higher=more preferred)\n"
2297 "Configure default local preference value\n")
718e3744 2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_default_local_preference_unset(bgp);
2301 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2302
d62a17ae 2303 return CMD_SUCCESS;
718e3744 2304}
2305
6b0655a2 2306
3f9c7369
DS
2307DEFUN (bgp_default_subgroup_pkt_queue_max,
2308 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2309 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2310 "BGP specific commands\n"
2311 "Configure BGP defaults\n"
2312 "subgroup-pkt-queue-max\n"
2313 "Configure subgroup packet queue max\n")
8bd9d948 2314{
d62a17ae 2315 VTY_DECLVAR_CONTEXT(bgp, bgp);
2316 int idx_number = 3;
2317 u_int32_t max_size;
8bd9d948 2318
d62a17ae 2319 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2320
d62a17ae 2321 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2322
d62a17ae 2323 return CMD_SUCCESS;
3f9c7369
DS
2324}
2325
2326DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2327 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2328 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2329 NO_STR
2330 "BGP specific commands\n"
2331 "Configure BGP defaults\n"
838758ac
DW
2332 "subgroup-pkt-queue-max\n"
2333 "Configure subgroup packet queue max\n")
3f9c7369 2334{
d62a17ae 2335 VTY_DECLVAR_CONTEXT(bgp, bgp);
2336 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2337 return CMD_SUCCESS;
8bd9d948
DS
2338}
2339
813d4307 2340
8bd9d948
DS
2341DEFUN (bgp_rr_allow_outbound_policy,
2342 bgp_rr_allow_outbound_policy_cmd,
2343 "bgp route-reflector allow-outbound-policy",
2344 "BGP specific commands\n"
2345 "Allow modifications made by out route-map\n"
2346 "on ibgp neighbors\n")
2347{
d62a17ae 2348 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2349
d62a17ae 2350 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2351 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2352 update_group_announce_rrclients(bgp);
2353 bgp_clear_star_soft_out(vty, bgp->name);
2354 }
8bd9d948 2355
d62a17ae 2356 return CMD_SUCCESS;
8bd9d948
DS
2357}
2358
2359DEFUN (no_bgp_rr_allow_outbound_policy,
2360 no_bgp_rr_allow_outbound_policy_cmd,
2361 "no bgp route-reflector allow-outbound-policy",
2362 NO_STR
2363 "BGP specific commands\n"
2364 "Allow modifications made by out route-map\n"
2365 "on ibgp neighbors\n")
2366{
d62a17ae 2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2368
d62a17ae 2369 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2370 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2371 update_group_announce_rrclients(bgp);
2372 bgp_clear_star_soft_out(vty, bgp->name);
2373 }
8bd9d948 2374
d62a17ae 2375 return CMD_SUCCESS;
8bd9d948
DS
2376}
2377
f14e6fdb
DS
2378DEFUN (bgp_listen_limit,
2379 bgp_listen_limit_cmd,
9ccf14f7 2380 "bgp listen limit (1-5000)",
f14e6fdb
DS
2381 "BGP specific commands\n"
2382 "Configure BGP defaults\n"
2383 "maximum number of BGP Dynamic Neighbors that can be created\n"
2384 "Configure Dynamic Neighbors listen limit value\n")
2385{
d62a17ae 2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 int idx_number = 3;
2388 int listen_limit;
f14e6fdb 2389
d62a17ae 2390 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2391
d62a17ae 2392 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2393
d62a17ae 2394 return CMD_SUCCESS;
f14e6fdb
DS
2395}
2396
2397DEFUN (no_bgp_listen_limit,
2398 no_bgp_listen_limit_cmd,
838758ac 2399 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2403 "Configure Dynamic Neighbors listen limit value to default\n"
2404 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2405{
d62a17ae 2406 VTY_DECLVAR_CONTEXT(bgp, bgp);
2407 bgp_listen_limit_unset(bgp);
2408 return CMD_SUCCESS;
f14e6fdb
DS
2409}
2410
2411
20eb8864 2412/*
2413 * Check if this listen range is already configured. Check for exact
2414 * match or overlap based on input.
2415 */
d62a17ae 2416static struct peer_group *listen_range_exists(struct bgp *bgp,
2417 struct prefix *range, int exact)
2418{
2419 struct listnode *node, *nnode;
2420 struct listnode *node1, *nnode1;
2421 struct peer_group *group;
2422 struct prefix *lr;
2423 afi_t afi;
2424 int match;
2425
2426 afi = family2afi(range->family);
2427 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2428 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2429 lr)) {
2430 if (exact)
2431 match = prefix_same(range, lr);
2432 else
2433 match = (prefix_match(range, lr)
2434 || prefix_match(lr, range));
2435 if (match)
2436 return group;
2437 }
2438 }
2439
2440 return NULL;
20eb8864 2441}
2442
f14e6fdb
DS
2443DEFUN (bgp_listen_range,
2444 bgp_listen_range_cmd,
9ccf14f7 2445 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2446 "BGP specific commands\n"
d7fa34c1
QY
2447 "Configure BGP dynamic neighbors listen range\n"
2448 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2449 NEIGHBOR_ADDR_STR
2450 "Member of the peer-group\n"
2451 "Peer-group name\n")
f14e6fdb 2452{
d62a17ae 2453 VTY_DECLVAR_CONTEXT(bgp, bgp);
2454 struct prefix range;
2455 struct peer_group *group, *existing_group;
2456 afi_t afi;
2457 int ret;
2458 int idx = 0;
2459
2460 argv_find(argv, argc, "A.B.C.D/M", &idx);
2461 argv_find(argv, argc, "X:X::X:X/M", &idx);
2462 char *prefix = argv[idx]->arg;
2463 argv_find(argv, argc, "WORD", &idx);
2464 char *peergroup = argv[idx]->arg;
2465
2466 /* Convert IP prefix string to struct prefix. */
2467 ret = str2prefix(prefix, &range);
2468 if (!ret) {
2469 vty_out(vty, "%% Malformed listen range\n");
2470 return CMD_WARNING_CONFIG_FAILED;
2471 }
2472
2473 afi = family2afi(range.family);
2474
2475 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2476 vty_out(vty,
2477 "%% Malformed listen range (link-local address)\n");
2478 return CMD_WARNING_CONFIG_FAILED;
2479 }
2480
2481 apply_mask(&range);
2482
2483 /* Check if same listen range is already configured. */
2484 existing_group = listen_range_exists(bgp, &range, 1);
2485 if (existing_group) {
2486 if (strcmp(existing_group->name, peergroup) == 0)
2487 return CMD_SUCCESS;
2488 else {
2489 vty_out(vty,
2490 "%% Same listen range is attached to peer-group %s\n",
2491 existing_group->name);
2492 return CMD_WARNING_CONFIG_FAILED;
2493 }
2494 }
2495
2496 /* Check if an overlapping listen range exists. */
2497 if (listen_range_exists(bgp, &range, 0)) {
2498 vty_out(vty,
2499 "%% Listen range overlaps with existing listen range\n");
2500 return CMD_WARNING_CONFIG_FAILED;
2501 }
2502
2503 group = peer_group_lookup(bgp, peergroup);
2504 if (!group) {
2505 vty_out(vty, "%% Configure the peer-group first\n");
2506 return CMD_WARNING_CONFIG_FAILED;
2507 }
2508
2509 ret = peer_group_listen_range_add(group, &range);
2510 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2511}
2512
2513DEFUN (no_bgp_listen_range,
2514 no_bgp_listen_range_cmd,
d7fa34c1
QY
2515 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2516 NO_STR
f14e6fdb 2517 "BGP specific commands\n"
d7fa34c1
QY
2518 "Unconfigure BGP dynamic neighbors listen range\n"
2519 "Unconfigure BGP dynamic neighbors listen range\n"
2520 NEIGHBOR_ADDR_STR
2521 "Member of the peer-group\n"
2522 "Peer-group name\n")
f14e6fdb 2523{
d62a17ae 2524 VTY_DECLVAR_CONTEXT(bgp, bgp);
2525 struct prefix range;
2526 struct peer_group *group;
2527 afi_t afi;
2528 int ret;
2529 int idx = 0;
2530
2531 argv_find(argv, argc, "A.B.C.D/M", &idx);
2532 argv_find(argv, argc, "X:X::X:X/M", &idx);
2533 char *prefix = argv[idx]->arg;
2534 argv_find(argv, argc, "WORD", &idx);
2535 char *peergroup = argv[idx]->arg;
2536
2537 /* Convert IP prefix string to struct prefix. */
2538 ret = str2prefix(prefix, &range);
2539 if (!ret) {
2540 vty_out(vty, "%% Malformed listen range\n");
2541 return CMD_WARNING_CONFIG_FAILED;
2542 }
2543
2544 afi = family2afi(range.family);
2545
2546 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2547 vty_out(vty,
2548 "%% Malformed listen range (link-local address)\n");
2549 return CMD_WARNING_CONFIG_FAILED;
2550 }
2551
2552 apply_mask(&range);
2553
2554 group = peer_group_lookup(bgp, peergroup);
2555 if (!group) {
2556 vty_out(vty, "%% Peer-group does not exist\n");
2557 return CMD_WARNING_CONFIG_FAILED;
2558 }
2559
2560 ret = peer_group_listen_range_del(group, &range);
2561 return bgp_vty_return(vty, ret);
2562}
2563
2b791107 2564void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2565{
2566 struct peer_group *group;
2567 struct listnode *node, *nnode, *rnode, *nrnode;
2568 struct prefix *range;
2569 afi_t afi;
2570 char buf[PREFIX2STR_BUFFER];
2571
2572 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2573 vty_out(vty, " bgp listen limit %d\n",
2574 bgp->dynamic_neighbors_limit);
2575
2576 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2577 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2578 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2579 nrnode, range)) {
2580 prefix2str(range, buf, sizeof(buf));
2581 vty_out(vty,
2582 " bgp listen range %s peer-group %s\n",
2583 buf, group->name);
2584 }
2585 }
2586 }
f14e6fdb
DS
2587}
2588
2589
907f92c8
DS
2590DEFUN (bgp_disable_connected_route_check,
2591 bgp_disable_connected_route_check_cmd,
2592 "bgp disable-ebgp-connected-route-check",
2593 "BGP specific commands\n"
2594 "Disable checking if nexthop is connected on ebgp sessions\n")
2595{
d62a17ae 2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2598 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2599
d62a17ae 2600 return CMD_SUCCESS;
907f92c8
DS
2601}
2602
2603DEFUN (no_bgp_disable_connected_route_check,
2604 no_bgp_disable_connected_route_check_cmd,
2605 "no bgp disable-ebgp-connected-route-check",
2606 NO_STR
2607 "BGP specific commands\n"
2608 "Disable checking if nexthop is connected on ebgp sessions\n")
2609{
d62a17ae 2610 VTY_DECLVAR_CONTEXT(bgp, bgp);
2611 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2612 bgp_clear_star_soft_in(vty, bgp->name);
2613
2614 return CMD_SUCCESS;
2615}
2616
2617
2618static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2619 const char *as_str, afi_t afi, safi_t safi)
2620{
2621 VTY_DECLVAR_CONTEXT(bgp, bgp);
2622 int ret;
2623 as_t as;
2624 int as_type = AS_SPECIFIED;
2625 union sockunion su;
2626
2627 if (as_str[0] == 'i') {
2628 as = 0;
2629 as_type = AS_INTERNAL;
2630 } else if (as_str[0] == 'e') {
2631 as = 0;
2632 as_type = AS_EXTERNAL;
2633 } else {
2634 /* Get AS number. */
2635 as = strtoul(as_str, NULL, 10);
2636 }
2637
2638 /* If peer is peer group, call proper function. */
2639 ret = str2sockunion(peer_str, &su);
2640 if (ret < 0) {
2641 /* Check for peer by interface */
2642 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2643 safi);
2644 if (ret < 0) {
2645 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2646 if (ret < 0) {
2647 vty_out(vty,
2648 "%% Create the peer-group or interface first\n");
2649 return CMD_WARNING_CONFIG_FAILED;
2650 }
2651 return CMD_SUCCESS;
2652 }
2653 } else {
2654 if (peer_address_self_check(bgp, &su)) {
2655 vty_out(vty,
2656 "%% Can not configure the local system as neighbor\n");
2657 return CMD_WARNING_CONFIG_FAILED;
2658 }
2659 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2660 }
2661
2662 /* This peer belongs to peer group. */
2663 switch (ret) {
2664 case BGP_ERR_PEER_GROUP_MEMBER:
2665 vty_out(vty,
2666 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2667 as);
2668 return CMD_WARNING_CONFIG_FAILED;
2669 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2670 vty_out(vty,
2671 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2672 as, as_str);
2673 return CMD_WARNING_CONFIG_FAILED;
2674 }
2675 return bgp_vty_return(vty, ret);
718e3744 2676}
2677
2678DEFUN (neighbor_remote_as,
2679 neighbor_remote_as_cmd,
3a2d747c 2680 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2681 NEIGHBOR_STR
2682 NEIGHBOR_ADDR_STR2
2683 "Specify a BGP neighbor\n"
d7fa34c1 2684 AS_STR
3a2d747c
QY
2685 "Internal BGP peer\n"
2686 "External BGP peer\n")
718e3744 2687{
d62a17ae 2688 int idx_peer = 1;
2689 int idx_remote_as = 3;
2690 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2691 argv[idx_remote_as]->arg, AFI_IP,
2692 SAFI_UNICAST);
2693}
2694
2695static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2696 afi_t afi, safi_t safi, int v6only,
2697 const char *peer_group_name,
2698 const char *as_str)
2699{
2700 VTY_DECLVAR_CONTEXT(bgp, bgp);
2701 as_t as = 0;
2702 int as_type = AS_UNSPECIFIED;
2703 struct peer *peer;
2704 struct peer_group *group;
2705 int ret = 0;
2706 union sockunion su;
2707
2708 group = peer_group_lookup(bgp, conf_if);
2709
2710 if (group) {
2711 vty_out(vty, "%% Name conflict with peer-group \n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 if (as_str) {
2716 if (as_str[0] == 'i') {
2717 as_type = AS_INTERNAL;
2718 } else if (as_str[0] == 'e') {
2719 as_type = AS_EXTERNAL;
2720 } else {
2721 /* Get AS number. */
2722 as = strtoul(as_str, NULL, 10);
2723 as_type = AS_SPECIFIED;
2724 }
2725 }
2726
2727 peer = peer_lookup_by_conf_if(bgp, conf_if);
2728 if (peer) {
2729 if (as_str)
2730 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2731 afi, safi);
2732 } else {
2733 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2734 && afi == AFI_IP && safi == SAFI_UNICAST)
2735 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2736 as_type, 0, 0, NULL);
2737 else
2738 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2739 as_type, afi, safi, NULL);
2740
2741 if (!peer) {
2742 vty_out(vty, "%% BGP failed to create peer\n");
2743 return CMD_WARNING_CONFIG_FAILED;
2744 }
2745
2746 if (v6only)
2747 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2748
2749 /* Request zebra to initiate IPv6 RAs on this interface. We do
2750 * this
2751 * any unnumbered peer in order to not worry about run-time
2752 * transitions
2753 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2754 * address
2755 * gets deleted later etc.)
2756 */
2757 if (peer->ifp)
2758 bgp_zebra_initiate_radv(bgp, peer);
2759 }
2760
2761 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2762 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2763 if (v6only)
2764 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2765 else
2766 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2767
2768 /* v6only flag changed. Reset bgp seesion */
2769 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2770 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2771 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2772 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2773 } else
2774 bgp_session_reset(peer);
2775 }
2776
2777 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2778 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2779
2780 if (peer_group_name) {
2781 group = peer_group_lookup(bgp, peer_group_name);
2782 if (!group) {
2783 vty_out(vty, "%% Configure the peer-group first\n");
2784 return CMD_WARNING_CONFIG_FAILED;
2785 }
2786
2787 ret = peer_group_bind(bgp, &su, peer, group, &as);
2788 }
2789
2790 return bgp_vty_return(vty, ret);
a80beece
DS
2791}
2792
4c48cf63
DW
2793DEFUN (neighbor_interface_config,
2794 neighbor_interface_config_cmd,
31500417 2795 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2796 NEIGHBOR_STR
2797 "Interface name or neighbor tag\n"
31500417
DW
2798 "Enable BGP on interface\n"
2799 "Member of the peer-group\n"
16cedbb0 2800 "Peer-group name\n")
4c48cf63 2801{
d62a17ae 2802 int idx_word = 1;
2803 int idx_peer_group_word = 4;
31500417 2804
d62a17ae 2805 if (argc > idx_peer_group_word)
2806 return peer_conf_interface_get(
2807 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2808 argv[idx_peer_group_word]->arg, NULL);
2809 else
2810 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2811 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2812}
2813
4c48cf63
DW
2814DEFUN (neighbor_interface_config_v6only,
2815 neighbor_interface_config_v6only_cmd,
31500417 2816 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2817 NEIGHBOR_STR
2818 "Interface name or neighbor tag\n"
2819 "Enable BGP on interface\n"
31500417
DW
2820 "Enable BGP with v6 link-local only\n"
2821 "Member of the peer-group\n"
16cedbb0 2822 "Peer-group name\n")
4c48cf63 2823{
d62a17ae 2824 int idx_word = 1;
2825 int idx_peer_group_word = 5;
31500417 2826
d62a17ae 2827 if (argc > idx_peer_group_word)
2828 return peer_conf_interface_get(
2829 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2830 argv[idx_peer_group_word]->arg, NULL);
31500417 2831
d62a17ae 2832 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2833 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2834}
2835
a80beece 2836
b3a39dc5
DD
2837DEFUN (neighbor_interface_config_remote_as,
2838 neighbor_interface_config_remote_as_cmd,
3a2d747c 2839 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2840 NEIGHBOR_STR
2841 "Interface name or neighbor tag\n"
2842 "Enable BGP on interface\n"
3a2d747c 2843 "Specify a BGP neighbor\n"
d7fa34c1 2844 AS_STR
3a2d747c
QY
2845 "Internal BGP peer\n"
2846 "External BGP peer\n")
b3a39dc5 2847{
d62a17ae 2848 int idx_word = 1;
2849 int idx_remote_as = 4;
2850 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2851 SAFI_UNICAST, 0, NULL,
2852 argv[idx_remote_as]->arg);
b3a39dc5
DD
2853}
2854
2855DEFUN (neighbor_interface_v6only_config_remote_as,
2856 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2857 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2858 NEIGHBOR_STR
2859 "Interface name or neighbor tag\n"
3a2d747c 2860 "Enable BGP with v6 link-local only\n"
b3a39dc5 2861 "Enable BGP on interface\n"
3a2d747c 2862 "Specify a BGP neighbor\n"
d7fa34c1 2863 AS_STR
3a2d747c
QY
2864 "Internal BGP peer\n"
2865 "External BGP peer\n")
b3a39dc5 2866{
d62a17ae 2867 int idx_word = 1;
2868 int idx_remote_as = 5;
2869 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2870 SAFI_UNICAST, 1, NULL,
2871 argv[idx_remote_as]->arg);
b3a39dc5
DD
2872}
2873
718e3744 2874DEFUN (neighbor_peer_group,
2875 neighbor_peer_group_cmd,
2876 "neighbor WORD peer-group",
2877 NEIGHBOR_STR
a80beece 2878 "Interface name or neighbor tag\n"
718e3744 2879 "Configure peer-group\n")
2880{
d62a17ae 2881 VTY_DECLVAR_CONTEXT(bgp, bgp);
2882 int idx_word = 1;
2883 struct peer *peer;
2884 struct peer_group *group;
718e3744 2885
d62a17ae 2886 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2887 if (peer) {
2888 vty_out(vty, "%% Name conflict with interface: \n");
2889 return CMD_WARNING_CONFIG_FAILED;
2890 }
718e3744 2891
d62a17ae 2892 group = peer_group_get(bgp, argv[idx_word]->arg);
2893 if (!group) {
2894 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2895 return CMD_WARNING_CONFIG_FAILED;
2896 }
718e3744 2897
d62a17ae 2898 return CMD_SUCCESS;
718e3744 2899}
2900
2901DEFUN (no_neighbor,
2902 no_neighbor_cmd,
dab8cd00 2903 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2904 NO_STR
2905 NEIGHBOR_STR
3a2d747c
QY
2906 NEIGHBOR_ADDR_STR2
2907 "Specify a BGP neighbor\n"
2908 AS_STR
2909 "Internal BGP peer\n"
2910 "External BGP peer\n")
718e3744 2911{
d62a17ae 2912 VTY_DECLVAR_CONTEXT(bgp, bgp);
2913 int idx_peer = 2;
2914 int ret;
2915 union sockunion su;
2916 struct peer_group *group;
2917 struct peer *peer;
2918 struct peer *other;
2919
2920 ret = str2sockunion(argv[idx_peer]->arg, &su);
2921 if (ret < 0) {
2922 /* look up for neighbor by interface name config. */
2923 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2924 if (peer) {
2925 /* Request zebra to terminate IPv6 RAs on this
2926 * interface. */
2927 if (peer->ifp)
2928 bgp_zebra_terminate_radv(peer->bgp, peer);
2929 peer_delete(peer);
2930 return CMD_SUCCESS;
2931 }
f14e6fdb 2932
d62a17ae 2933 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2934 if (group)
2935 peer_group_delete(group);
2936 else {
2937 vty_out(vty, "%% Create the peer-group first\n");
2938 return CMD_WARNING_CONFIG_FAILED;
2939 }
2940 } else {
2941 peer = peer_lookup(bgp, &su);
2942 if (peer) {
2943 if (peer_dynamic_neighbor(peer)) {
2944 vty_out(vty,
2945 "%% Operation not allowed on a dynamic neighbor\n");
2946 return CMD_WARNING_CONFIG_FAILED;
2947 }
2948
2949 other = peer->doppelganger;
2950 peer_delete(peer);
2951 if (other && other->status != Deleted)
2952 peer_delete(other);
2953 }
1ff9a340 2954 }
718e3744 2955
d62a17ae 2956 return CMD_SUCCESS;
718e3744 2957}
2958
a80beece
DS
2959DEFUN (no_neighbor_interface_config,
2960 no_neighbor_interface_config_cmd,
31500417 2961 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2962 NO_STR
2963 NEIGHBOR_STR
2964 "Interface name\n"
31500417
DW
2965 "Configure BGP on interface\n"
2966 "Enable BGP with v6 link-local only\n"
2967 "Member of the peer-group\n"
16cedbb0 2968 "Peer-group name\n"
3a2d747c
QY
2969 "Specify a BGP neighbor\n"
2970 AS_STR
2971 "Internal BGP peer\n"
2972 "External BGP peer\n")
a80beece 2973{
d62a17ae 2974 VTY_DECLVAR_CONTEXT(bgp, bgp);
2975 int idx_word = 2;
2976 struct peer *peer;
2977
2978 /* look up for neighbor by interface name config. */
2979 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2980 if (peer) {
2981 /* Request zebra to terminate IPv6 RAs on this interface. */
2982 if (peer->ifp)
2983 bgp_zebra_terminate_radv(peer->bgp, peer);
2984 peer_delete(peer);
2985 } else {
2986 vty_out(vty, "%% Create the bgp interface first\n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
2989 return CMD_SUCCESS;
a80beece
DS
2990}
2991
718e3744 2992DEFUN (no_neighbor_peer_group,
2993 no_neighbor_peer_group_cmd,
2994 "no neighbor WORD peer-group",
2995 NO_STR
2996 NEIGHBOR_STR
2997 "Neighbor tag\n"
2998 "Configure peer-group\n")
2999{
d62a17ae 3000 VTY_DECLVAR_CONTEXT(bgp, bgp);
3001 int idx_word = 2;
3002 struct peer_group *group;
718e3744 3003
d62a17ae 3004 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3005 if (group)
3006 peer_group_delete(group);
3007 else {
3008 vty_out(vty, "%% Create the peer-group first\n");
3009 return CMD_WARNING_CONFIG_FAILED;
3010 }
3011 return CMD_SUCCESS;
718e3744 3012}
3013
a80beece
DS
3014DEFUN (no_neighbor_interface_peer_group_remote_as,
3015 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3016 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3017 NO_STR
3018 NEIGHBOR_STR
a80beece 3019 "Interface name or neighbor tag\n"
718e3744 3020 "Specify a BGP neighbor\n"
3a2d747c
QY
3021 AS_STR
3022 "Internal BGP peer\n"
3023 "External BGP peer\n")
718e3744 3024{
d62a17ae 3025 VTY_DECLVAR_CONTEXT(bgp, bgp);
3026 int idx_word = 2;
3027 struct peer_group *group;
3028 struct peer *peer;
3029
3030 /* look up for neighbor by interface name config. */
3031 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3032 if (peer) {
3033 peer_as_change(peer, 0, AS_SPECIFIED);
3034 return CMD_SUCCESS;
3035 }
3036
3037 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3038 if (group)
3039 peer_group_remote_as_delete(group);
3040 else {
3041 vty_out(vty, "%% Create the peer-group or interface first\n");
3042 return CMD_WARNING_CONFIG_FAILED;
3043 }
3044 return CMD_SUCCESS;
718e3744 3045}
6b0655a2 3046
718e3744 3047DEFUN (neighbor_local_as,
3048 neighbor_local_as_cmd,
9ccf14f7 3049 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3050 NEIGHBOR_STR
3051 NEIGHBOR_ADDR_STR2
3052 "Specify a local-as number\n"
3053 "AS number used as local AS\n")
3054{
d62a17ae 3055 int idx_peer = 1;
3056 int idx_number = 3;
3057 struct peer *peer;
3058 int ret;
3059 as_t as;
718e3744 3060
d62a17ae 3061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3062 if (!peer)
3063 return CMD_WARNING_CONFIG_FAILED;
718e3744 3064
d62a17ae 3065 as = strtoul(argv[idx_number]->arg, NULL, 10);
3066 ret = peer_local_as_set(peer, as, 0, 0);
3067 return bgp_vty_return(vty, ret);
718e3744 3068}
3069
3070DEFUN (neighbor_local_as_no_prepend,
3071 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3072 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3073 NEIGHBOR_STR
3074 NEIGHBOR_ADDR_STR2
3075 "Specify a local-as number\n"
3076 "AS number used as local AS\n"
3077 "Do not prepend local-as to updates from ebgp peers\n")
3078{
d62a17ae 3079 int idx_peer = 1;
3080 int idx_number = 3;
3081 struct peer *peer;
3082 int ret;
3083 as_t as;
718e3744 3084
d62a17ae 3085 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3086 if (!peer)
3087 return CMD_WARNING_CONFIG_FAILED;
718e3744 3088
d62a17ae 3089 as = strtoul(argv[idx_number]->arg, NULL, 10);
3090 ret = peer_local_as_set(peer, as, 1, 0);
3091 return bgp_vty_return(vty, ret);
718e3744 3092}
3093
9d3f9705
AC
3094DEFUN (neighbor_local_as_no_prepend_replace_as,
3095 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3096 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3097 NEIGHBOR_STR
3098 NEIGHBOR_ADDR_STR2
3099 "Specify a local-as number\n"
3100 "AS number used as local AS\n"
3101 "Do not prepend local-as to updates from ebgp peers\n"
3102 "Do not prepend local-as to updates from ibgp peers\n")
3103{
d62a17ae 3104 int idx_peer = 1;
3105 int idx_number = 3;
3106 struct peer *peer;
3107 int ret;
3108 as_t as;
9d3f9705 3109
d62a17ae 3110 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3111 if (!peer)
3112 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3113
d62a17ae 3114 as = strtoul(argv[idx_number]->arg, NULL, 10);
3115 ret = peer_local_as_set(peer, as, 1, 1);
3116 return bgp_vty_return(vty, ret);
9d3f9705
AC
3117}
3118
718e3744 3119DEFUN (no_neighbor_local_as,
3120 no_neighbor_local_as_cmd,
a636c635 3121 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3122 NO_STR
3123 NEIGHBOR_STR
3124 NEIGHBOR_ADDR_STR2
a636c635
DW
3125 "Specify a local-as number\n"
3126 "AS number used as local AS\n"
3127 "Do not prepend local-as to updates from ebgp peers\n"
3128 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3129{
d62a17ae 3130 int idx_peer = 2;
3131 struct peer *peer;
3132 int ret;
718e3744 3133
d62a17ae 3134 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3135 if (!peer)
3136 return CMD_WARNING_CONFIG_FAILED;
718e3744 3137
d62a17ae 3138 ret = peer_local_as_unset(peer);
3139 return bgp_vty_return(vty, ret);
718e3744 3140}
3141
718e3744 3142
3f9c7369
DS
3143DEFUN (neighbor_solo,
3144 neighbor_solo_cmd,
9ccf14f7 3145 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3146 NEIGHBOR_STR
3147 NEIGHBOR_ADDR_STR2
3148 "Solo peer - part of its own update group\n")
3149{
d62a17ae 3150 int idx_peer = 1;
3151 struct peer *peer;
3152 int ret;
3f9c7369 3153
d62a17ae 3154 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3155 if (!peer)
3156 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3157
d62a17ae 3158 ret = update_group_adjust_soloness(peer, 1);
3159 return bgp_vty_return(vty, ret);
3f9c7369
DS
3160}
3161
3162DEFUN (no_neighbor_solo,
3163 no_neighbor_solo_cmd,
9ccf14f7 3164 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3165 NO_STR
3166 NEIGHBOR_STR
3167 NEIGHBOR_ADDR_STR2
3168 "Solo peer - part of its own update group\n")
3169{
d62a17ae 3170 int idx_peer = 2;
3171 struct peer *peer;
3172 int ret;
3f9c7369 3173
d62a17ae 3174 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3175 if (!peer)
3176 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3177
d62a17ae 3178 ret = update_group_adjust_soloness(peer, 0);
3179 return bgp_vty_return(vty, ret);
3f9c7369
DS
3180}
3181
0df7c91f
PJ
3182DEFUN (neighbor_password,
3183 neighbor_password_cmd,
9ccf14f7 3184 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 "Set a password\n"
3188 "The password\n")
3189{
d62a17ae 3190 int idx_peer = 1;
3191 int idx_line = 3;
3192 struct peer *peer;
3193 int ret;
0df7c91f 3194
d62a17ae 3195 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3196 if (!peer)
3197 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3198
d62a17ae 3199 ret = peer_password_set(peer, argv[idx_line]->arg);
3200 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3201}
3202
3203DEFUN (no_neighbor_password,
3204 no_neighbor_password_cmd,
a636c635 3205 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3206 NO_STR
3207 NEIGHBOR_STR
3208 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3209 "Set a password\n"
3210 "The password\n")
0df7c91f 3211{
d62a17ae 3212 int idx_peer = 2;
3213 struct peer *peer;
3214 int ret;
0df7c91f 3215
d62a17ae 3216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3217 if (!peer)
3218 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3219
d62a17ae 3220 ret = peer_password_unset(peer);
3221 return bgp_vty_return(vty, ret);
0df7c91f 3222}
6b0655a2 3223
813d4307 3224
718e3744 3225DEFUN (neighbor_activate,
3226 neighbor_activate_cmd,
9ccf14f7 3227 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3228 NEIGHBOR_STR
3229 NEIGHBOR_ADDR_STR2
3230 "Enable the Address Family for this Neighbor\n")
3231{
d62a17ae 3232 int idx_peer = 1;
3233 int ret;
3234 struct peer *peer;
718e3744 3235
d62a17ae 3236 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3237 if (!peer)
3238 return CMD_WARNING_CONFIG_FAILED;
718e3744 3239
d62a17ae 3240 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3241 return bgp_vty_return(vty, ret);
718e3744 3242}
3243
d62a17ae 3244ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3245 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3246 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3247 "Enable the Address Family for this Neighbor\n")
596c17ba 3248
718e3744 3249DEFUN (no_neighbor_activate,
3250 no_neighbor_activate_cmd,
9ccf14f7 3251 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3252 NO_STR
3253 NEIGHBOR_STR
3254 NEIGHBOR_ADDR_STR2
3255 "Enable the Address Family for this Neighbor\n")
3256{
d62a17ae 3257 int idx_peer = 2;
3258 int ret;
3259 struct peer *peer;
718e3744 3260
d62a17ae 3261 /* Lookup peer. */
3262 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3263 if (!peer)
3264 return CMD_WARNING_CONFIG_FAILED;
718e3744 3265
d62a17ae 3266 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3267 return bgp_vty_return(vty, ret);
718e3744 3268}
6b0655a2 3269
d62a17ae 3270ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3271 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3272 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3273 "Enable the Address Family for this Neighbor\n")
596c17ba 3274
718e3744 3275DEFUN (neighbor_set_peer_group,
3276 neighbor_set_peer_group_cmd,
9ccf14f7 3277 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3278 NEIGHBOR_STR
a80beece 3279 NEIGHBOR_ADDR_STR2
718e3744 3280 "Member of the peer-group\n"
16cedbb0 3281 "Peer-group name\n")
718e3744 3282{
d62a17ae 3283 VTY_DECLVAR_CONTEXT(bgp, bgp);
3284 int idx_peer = 1;
3285 int idx_word = 3;
3286 int ret;
3287 as_t as;
3288 union sockunion su;
3289 struct peer *peer;
3290 struct peer_group *group;
3291
3292 peer = NULL;
3293
3294 ret = str2sockunion(argv[idx_peer]->arg, &su);
3295 if (ret < 0) {
3296 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3297 if (!peer) {
3298 vty_out(vty, "%% Malformed address or name: %s\n",
3299 argv[idx_peer]->arg);
3300 return CMD_WARNING_CONFIG_FAILED;
3301 }
3302 } else {
3303 if (peer_address_self_check(bgp, &su)) {
3304 vty_out(vty,
3305 "%% Can not configure the local system as neighbor\n");
3306 return CMD_WARNING_CONFIG_FAILED;
3307 }
3308
3309 /* Disallow for dynamic neighbor. */
3310 peer = peer_lookup(bgp, &su);
3311 if (peer && peer_dynamic_neighbor(peer)) {
3312 vty_out(vty,
3313 "%% Operation not allowed on a dynamic neighbor\n");
3314 return CMD_WARNING_CONFIG_FAILED;
3315 }
3316 }
3317
3318 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3319 if (!group) {
3320 vty_out(vty, "%% Configure the peer-group first\n");
3321 return CMD_WARNING_CONFIG_FAILED;
3322 }
3323
3324 ret = peer_group_bind(bgp, &su, peer, group, &as);
3325
3326 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3327 vty_out(vty,
3328 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3329 as);
3330 return CMD_WARNING_CONFIG_FAILED;
3331 }
3332
3333 return bgp_vty_return(vty, ret);
3334}
3335
3336ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3337 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3339 "Member of the peer-group\n"
3340 "Peer-group name\n")
596c17ba 3341
718e3744 3342DEFUN (no_neighbor_set_peer_group,
3343 no_neighbor_set_peer_group_cmd,
9ccf14f7 3344 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3345 NO_STR
3346 NEIGHBOR_STR
a80beece 3347 NEIGHBOR_ADDR_STR2
718e3744 3348 "Member of the peer-group\n"
16cedbb0 3349 "Peer-group name\n")
718e3744 3350{
d62a17ae 3351 VTY_DECLVAR_CONTEXT(bgp, bgp);
3352 int idx_peer = 2;
3353 int idx_word = 4;
3354 int ret;
3355 struct peer *peer;
3356 struct peer_group *group;
3357
3358 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3359 if (!peer)
3360 return CMD_WARNING_CONFIG_FAILED;
3361
3362 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3363 if (!group) {
3364 vty_out(vty, "%% Configure the peer-group first\n");
3365 return CMD_WARNING_CONFIG_FAILED;
3366 }
718e3744 3367
d62a17ae 3368 ret = peer_group_unbind(bgp, peer, group);
718e3744 3369
d62a17ae 3370 return bgp_vty_return(vty, ret);
718e3744 3371}
6b0655a2 3372
d62a17ae 3373ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3374 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3376 "Member of the peer-group\n"
3377 "Peer-group name\n")
596c17ba 3378
d62a17ae 3379static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3380 u_int16_t flag, int set)
718e3744 3381{
d62a17ae 3382 int ret;
3383 struct peer *peer;
718e3744 3384
d62a17ae 3385 peer = peer_and_group_lookup_vty(vty, ip_str);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
718e3744 3388
d62a17ae 3389 /*
3390 * If 'neighbor <interface>', then this is for directly connected peers,
3391 * we should not accept disable-connected-check.
3392 */
3393 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3394 vty_out(vty,
3395 "%s is directly connected peer, cannot accept disable-"
3396 "connected-check\n",
3397 ip_str);
3398 return CMD_WARNING_CONFIG_FAILED;
3399 }
8cdabf90 3400
d62a17ae 3401 if (!set && flag == PEER_FLAG_SHUTDOWN)
3402 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3403
d62a17ae 3404 if (set)
3405 ret = peer_flag_set(peer, flag);
3406 else
3407 ret = peer_flag_unset(peer, flag);
718e3744 3408
d62a17ae 3409 return bgp_vty_return(vty, ret);
718e3744 3410}
3411
d62a17ae 3412static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3413 u_int16_t flag)
718e3744 3414{
d62a17ae 3415 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3416}
3417
d62a17ae 3418static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3419 u_int16_t flag)
718e3744 3420{
d62a17ae 3421 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3422}
3423
3424/* neighbor passive. */
3425DEFUN (neighbor_passive,
3426 neighbor_passive_cmd,
9ccf14f7 3427 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3428 NEIGHBOR_STR
3429 NEIGHBOR_ADDR_STR2
3430 "Don't send open messages to this neighbor\n")
3431{
d62a17ae 3432 int idx_peer = 1;
3433 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3434}
3435
3436DEFUN (no_neighbor_passive,
3437 no_neighbor_passive_cmd,
9ccf14f7 3438 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3439 NO_STR
3440 NEIGHBOR_STR
3441 NEIGHBOR_ADDR_STR2
3442 "Don't send open messages to this neighbor\n")
3443{
d62a17ae 3444 int idx_peer = 2;
3445 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3446}
6b0655a2 3447
718e3744 3448/* neighbor shutdown. */
73d70fa6
DL
3449DEFUN (neighbor_shutdown_msg,
3450 neighbor_shutdown_msg_cmd,
3451 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3452 NEIGHBOR_STR
3453 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3454 "Administratively shut down this neighbor\n"
3455 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3456 "Shutdown message\n")
718e3744 3457{
d62a17ae 3458 int idx_peer = 1;
73d70fa6 3459
d62a17ae 3460 if (argc >= 5) {
3461 struct peer *peer =
3462 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3463 char *message;
73d70fa6 3464
d62a17ae 3465 if (!peer)
3466 return CMD_WARNING_CONFIG_FAILED;
3467 message = argv_concat(argv, argc, 4);
3468 peer_tx_shutdown_message_set(peer, message);
3469 XFREE(MTYPE_TMP, message);
3470 }
73d70fa6 3471
d62a17ae 3472 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3473}
3474
d62a17ae 3475ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3476 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3477 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3478 "Administratively shut down this neighbor\n")
73d70fa6
DL
3479
3480DEFUN (no_neighbor_shutdown_msg,
3481 no_neighbor_shutdown_msg_cmd,
3482 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3483 NO_STR
3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
3486 "Administratively shut down this neighbor\n"
3487 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3488 "Shutdown message\n")
718e3744 3489{
d62a17ae 3490 int idx_peer = 2;
73d70fa6 3491
d62a17ae 3492 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3493 PEER_FLAG_SHUTDOWN);
718e3744 3494}
6b0655a2 3495
d62a17ae 3496ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3497 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3498 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3499 "Administratively shut down this neighbor\n")
73d70fa6 3500
718e3744 3501/* neighbor capability dynamic. */
3502DEFUN (neighbor_capability_dynamic,
3503 neighbor_capability_dynamic_cmd,
9ccf14f7 3504 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3505 NEIGHBOR_STR
3506 NEIGHBOR_ADDR_STR2
3507 "Advertise capability to the peer\n"
3508 "Advertise dynamic capability to this neighbor\n")
3509{
d62a17ae 3510 int idx_peer = 1;
3511 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3512 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3513}
3514
3515DEFUN (no_neighbor_capability_dynamic,
3516 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3517 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3518 NO_STR
3519 NEIGHBOR_STR
3520 NEIGHBOR_ADDR_STR2
3521 "Advertise capability to the peer\n"
3522 "Advertise dynamic capability to this neighbor\n")
3523{
d62a17ae 3524 int idx_peer = 2;
3525 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3526 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3527}
6b0655a2 3528
718e3744 3529/* neighbor dont-capability-negotiate */
3530DEFUN (neighbor_dont_capability_negotiate,
3531 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3532 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3533 NEIGHBOR_STR
3534 NEIGHBOR_ADDR_STR2
3535 "Do not perform capability negotiation\n")
3536{
d62a17ae 3537 int idx_peer = 1;
3538 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3539 PEER_FLAG_DONT_CAPABILITY);
718e3744 3540}
3541
3542DEFUN (no_neighbor_dont_capability_negotiate,
3543 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3544 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3545 NO_STR
3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Do not perform capability negotiation\n")
3549{
d62a17ae 3550 int idx_peer = 2;
3551 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3552 PEER_FLAG_DONT_CAPABILITY);
718e3744 3553}
6b0655a2 3554
8a92a8a0
DS
3555/* neighbor capability extended next hop encoding */
3556DEFUN (neighbor_capability_enhe,
3557 neighbor_capability_enhe_cmd,
9ccf14f7 3558 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3559 NEIGHBOR_STR
3560 NEIGHBOR_ADDR_STR2
3561 "Advertise capability to the peer\n"
3562 "Advertise extended next-hop capability to the peer\n")
3563{
d62a17ae 3564 int idx_peer = 1;
3565 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3566 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3567}
3568
3569DEFUN (no_neighbor_capability_enhe,
3570 no_neighbor_capability_enhe_cmd,
9ccf14f7 3571 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3572 NO_STR
3573 NEIGHBOR_STR
3574 NEIGHBOR_ADDR_STR2
3575 "Advertise capability to the peer\n"
3576 "Advertise extended next-hop capability to the peer\n")
3577{
d62a17ae 3578 int idx_peer = 2;
3579 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3580 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3581}
3582
d62a17ae 3583static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3584 afi_t afi, safi_t safi, u_int32_t flag,
3585 int set)
718e3744 3586{
d62a17ae 3587 int ret;
3588 struct peer *peer;
718e3744 3589
d62a17ae 3590 peer = peer_and_group_lookup_vty(vty, peer_str);
3591 if (!peer)
3592 return CMD_WARNING_CONFIG_FAILED;
718e3744 3593
d62a17ae 3594 if (set)
3595 ret = peer_af_flag_set(peer, afi, safi, flag);
3596 else
3597 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3598
d62a17ae 3599 return bgp_vty_return(vty, ret);
718e3744 3600}
3601
d62a17ae 3602static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3603 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3604{
d62a17ae 3605 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3606}
3607
d62a17ae 3608static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3609 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3610{
d62a17ae 3611 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3612}
6b0655a2 3613
718e3744 3614/* neighbor capability orf prefix-list. */
3615DEFUN (neighbor_capability_orf_prefix,
3616 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3617 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3618 NEIGHBOR_STR
3619 NEIGHBOR_ADDR_STR2
3620 "Advertise capability to the peer\n"
3621 "Advertise ORF capability to the peer\n"
3622 "Advertise prefixlist ORF capability to this neighbor\n"
3623 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3624 "Capability to RECEIVE the ORF from this neighbor\n"
3625 "Capability to SEND the ORF to this neighbor\n")
3626{
d62a17ae 3627 int idx_peer = 1;
3628 int idx_send_recv = 5;
3629 u_int16_t flag = 0;
3630
3631 if (strmatch(argv[idx_send_recv]->text, "send"))
3632 flag = PEER_FLAG_ORF_PREFIX_SM;
3633 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3634 flag = PEER_FLAG_ORF_PREFIX_RM;
3635 else if (strmatch(argv[idx_send_recv]->text, "both"))
3636 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3637 else {
3638 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3639 return CMD_WARNING_CONFIG_FAILED;
3640 }
3641
3642 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3643 bgp_node_safi(vty), flag);
3644}
3645
3646ALIAS_HIDDEN(
3647 neighbor_capability_orf_prefix,
3648 neighbor_capability_orf_prefix_hidden_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3650 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3651 "Advertise capability to the peer\n"
3652 "Advertise ORF capability to the peer\n"
3653 "Advertise prefixlist ORF capability to this neighbor\n"
3654 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3655 "Capability to RECEIVE the ORF from this neighbor\n"
3656 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3657
718e3744 3658DEFUN (no_neighbor_capability_orf_prefix,
3659 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Advertise capability to the peer\n"
3665 "Advertise ORF capability to the peer\n"
3666 "Advertise prefixlist ORF capability to this neighbor\n"
3667 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3668 "Capability to RECEIVE the ORF from this neighbor\n"
3669 "Capability to SEND the ORF to this neighbor\n")
3670{
d62a17ae 3671 int idx_peer = 2;
3672 int idx_send_recv = 6;
3673 u_int16_t flag = 0;
3674
3675 if (strmatch(argv[idx_send_recv]->text, "send"))
3676 flag = PEER_FLAG_ORF_PREFIX_SM;
3677 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3678 flag = PEER_FLAG_ORF_PREFIX_RM;
3679 else if (strmatch(argv[idx_send_recv]->text, "both"))
3680 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3681 else {
3682 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3683 return CMD_WARNING_CONFIG_FAILED;
3684 }
3685
3686 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3687 bgp_node_afi(vty), bgp_node_safi(vty),
3688 flag);
3689}
3690
3691ALIAS_HIDDEN(
3692 no_neighbor_capability_orf_prefix,
3693 no_neighbor_capability_orf_prefix_hidden_cmd,
3694 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3696 "Advertise capability to the peer\n"
3697 "Advertise ORF capability to the peer\n"
3698 "Advertise prefixlist ORF capability to this neighbor\n"
3699 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3700 "Capability to RECEIVE the ORF from this neighbor\n"
3701 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3702
718e3744 3703/* neighbor next-hop-self. */
3704DEFUN (neighbor_nexthop_self,
3705 neighbor_nexthop_self_cmd,
9ccf14f7 3706 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3707 NEIGHBOR_STR
3708 NEIGHBOR_ADDR_STR2
a538debe 3709 "Disable the next hop calculation for this neighbor\n")
718e3744 3710{
d62a17ae 3711 int idx_peer = 1;
3712 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3713 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3714}
9e7a53c1 3715
d62a17ae 3716ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3717 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3718 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3719 "Disable the next hop calculation for this neighbor\n")
596c17ba 3720
a538debe
DS
3721/* neighbor next-hop-self. */
3722DEFUN (neighbor_nexthop_self_force,
3723 neighbor_nexthop_self_force_cmd,
9ccf14f7 3724 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3725 NEIGHBOR_STR
3726 NEIGHBOR_ADDR_STR2
3727 "Disable the next hop calculation for this neighbor\n"
3728 "Set the next hop to self for reflected routes\n")
3729{
d62a17ae 3730 int idx_peer = 1;
3731 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3732 bgp_node_safi(vty),
3733 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3734}
3735
d62a17ae 3736ALIAS_HIDDEN(neighbor_nexthop_self_force,
3737 neighbor_nexthop_self_force_hidden_cmd,
3738 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3739 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3740 "Disable the next hop calculation for this neighbor\n"
3741 "Set the next hop to self for reflected routes\n")
596c17ba 3742
718e3744 3743DEFUN (no_neighbor_nexthop_self,
3744 no_neighbor_nexthop_self_cmd,
9ccf14f7 3745 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3746 NO_STR
3747 NEIGHBOR_STR
3748 NEIGHBOR_ADDR_STR2
a538debe 3749 "Disable the next hop calculation for this neighbor\n")
718e3744 3750{
d62a17ae 3751 int idx_peer = 2;
3752 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3753 bgp_node_afi(vty), bgp_node_safi(vty),
3754 PEER_FLAG_NEXTHOP_SELF);
718e3744 3755}
6b0655a2 3756
d62a17ae 3757ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3758 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3759 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3760 "Disable the next hop calculation for this neighbor\n")
596c17ba 3761
88b8ed8d 3762DEFUN (no_neighbor_nexthop_self_force,
a538debe 3763 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Disable the next hop calculation for this neighbor\n"
3769 "Set the next hop to self for reflected routes\n")
88b8ed8d 3770{
d62a17ae 3771 int idx_peer = 2;
3772 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 bgp_node_afi(vty), bgp_node_safi(vty),
3774 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3775}
a538debe 3776
d62a17ae 3777ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3778 no_neighbor_nexthop_self_force_hidden_cmd,
3779 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3780 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3781 "Disable the next hop calculation for this neighbor\n"
3782 "Set the next hop to self for reflected routes\n")
596c17ba 3783
c7122e14
DS
3784/* neighbor as-override */
3785DEFUN (neighbor_as_override,
3786 neighbor_as_override_cmd,
9ccf14f7 3787 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3788 NEIGHBOR_STR
3789 NEIGHBOR_ADDR_STR2
3790 "Override ASNs in outbound updates if aspath equals remote-as\n")
3791{
d62a17ae 3792 int idx_peer = 1;
3793 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3794 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3795}
3796
d62a17ae 3797ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3798 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3800 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3801
c7122e14
DS
3802DEFUN (no_neighbor_as_override,
3803 no_neighbor_as_override_cmd,
9ccf14f7 3804 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3805 NO_STR
3806 NEIGHBOR_STR
3807 NEIGHBOR_ADDR_STR2
3808 "Override ASNs in outbound updates if aspath equals remote-as\n")
3809{
d62a17ae 3810 int idx_peer = 2;
3811 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3812 bgp_node_afi(vty), bgp_node_safi(vty),
3813 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3814}
3815
d62a17ae 3816ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3817 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3818 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3819 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3820
718e3744 3821/* neighbor remove-private-AS. */
3822DEFUN (neighbor_remove_private_as,
3823 neighbor_remove_private_as_cmd,
9ccf14f7 3824 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3825 NEIGHBOR_STR
3826 NEIGHBOR_ADDR_STR2
5000f21c 3827 "Remove private ASNs in outbound updates\n")
718e3744 3828{
d62a17ae 3829 int idx_peer = 1;
3830 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3831 bgp_node_safi(vty),
3832 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3833}
3834
d62a17ae 3835ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3836 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3837 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3838 "Remove private ASNs in outbound updates\n")
596c17ba 3839
5000f21c
DS
3840DEFUN (neighbor_remove_private_as_all,
3841 neighbor_remove_private_as_all_cmd,
9ccf14f7 3842 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3843 NEIGHBOR_STR
3844 NEIGHBOR_ADDR_STR2
3845 "Remove private ASNs in outbound updates\n"
efd7904e 3846 "Apply to all AS numbers\n")
5000f21c 3847{
d62a17ae 3848 int idx_peer = 1;
3849 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3850 bgp_node_safi(vty),
3851 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3852}
3853
d62a17ae 3854ALIAS_HIDDEN(neighbor_remove_private_as_all,
3855 neighbor_remove_private_as_all_hidden_cmd,
3856 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3858 "Remove private ASNs in outbound updates\n"
3859 "Apply to all AS numbers")
596c17ba 3860
5000f21c
DS
3861DEFUN (neighbor_remove_private_as_replace_as,
3862 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3863 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3864 NEIGHBOR_STR
3865 NEIGHBOR_ADDR_STR2
3866 "Remove private ASNs in outbound updates\n"
3867 "Replace private ASNs with our ASN in outbound updates\n")
3868{
d62a17ae 3869 int idx_peer = 1;
3870 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3871 bgp_node_safi(vty),
3872 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3873}
3874
d62a17ae 3875ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3876 neighbor_remove_private_as_replace_as_hidden_cmd,
3877 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3879 "Remove private ASNs in outbound updates\n"
3880 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3881
5000f21c
DS
3882DEFUN (neighbor_remove_private_as_all_replace_as,
3883 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3885 NEIGHBOR_STR
3886 NEIGHBOR_ADDR_STR2
3887 "Remove private ASNs in outbound updates\n"
16cedbb0 3888 "Apply to all AS numbers\n"
5000f21c
DS
3889 "Replace private ASNs with our ASN in outbound updates\n")
3890{
d62a17ae 3891 int idx_peer = 1;
3892 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3893 bgp_node_safi(vty),
3894 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3895}
3896
d62a17ae 3897ALIAS_HIDDEN(
3898 neighbor_remove_private_as_all_replace_as,
3899 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3900 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3901 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3902 "Remove private ASNs in outbound updates\n"
3903 "Apply to all AS numbers\n"
3904 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3905
718e3744 3906DEFUN (no_neighbor_remove_private_as,
3907 no_neighbor_remove_private_as_cmd,
9ccf14f7 3908 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3909 NO_STR
3910 NEIGHBOR_STR
3911 NEIGHBOR_ADDR_STR2
5000f21c 3912 "Remove private ASNs in outbound updates\n")
718e3744 3913{
d62a17ae 3914 int idx_peer = 2;
3915 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3916 bgp_node_afi(vty), bgp_node_safi(vty),
3917 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3918}
6b0655a2 3919
d62a17ae 3920ALIAS_HIDDEN(no_neighbor_remove_private_as,
3921 no_neighbor_remove_private_as_hidden_cmd,
3922 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3923 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3924 "Remove private ASNs in outbound updates\n")
596c17ba 3925
88b8ed8d 3926DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3927 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3928 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3929 NO_STR
3930 NEIGHBOR_STR
3931 NEIGHBOR_ADDR_STR2
3932 "Remove private ASNs in outbound updates\n"
16cedbb0 3933 "Apply to all AS numbers\n")
88b8ed8d 3934{
d62a17ae 3935 int idx_peer = 2;
3936 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3937 bgp_node_afi(vty), bgp_node_safi(vty),
3938 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3939}
5000f21c 3940
d62a17ae 3941ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3942 no_neighbor_remove_private_as_all_hidden_cmd,
3943 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3944 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3945 "Remove private ASNs in outbound updates\n"
3946 "Apply to all AS numbers\n")
596c17ba 3947
88b8ed8d 3948DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3949 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3950 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3951 NO_STR
3952 NEIGHBOR_STR
3953 NEIGHBOR_ADDR_STR2
3954 "Remove private ASNs in outbound updates\n"
3955 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3956{
d62a17ae 3957 int idx_peer = 2;
3958 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3959 bgp_node_afi(vty), bgp_node_safi(vty),
3960 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3961}
5000f21c 3962
d62a17ae 3963ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3964 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3965 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3966 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3967 "Remove private ASNs in outbound updates\n"
3968 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3969
88b8ed8d 3970DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 3971 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3973 NO_STR
3974 NEIGHBOR_STR
3975 NEIGHBOR_ADDR_STR2
3976 "Remove private ASNs in outbound updates\n"
16cedbb0 3977 "Apply to all AS numbers\n"
5000f21c 3978 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3979{
d62a17ae 3980 int idx_peer = 2;
3981 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3982 bgp_node_afi(vty), bgp_node_safi(vty),
3983 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 3984}
5000f21c 3985
d62a17ae 3986ALIAS_HIDDEN(
3987 no_neighbor_remove_private_as_all_replace_as,
3988 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
3989 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3991 "Remove private ASNs in outbound updates\n"
3992 "Apply to all AS numbers\n"
3993 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3994
5000f21c 3995
718e3744 3996/* neighbor send-community. */
3997DEFUN (neighbor_send_community,
3998 neighbor_send_community_cmd,
9ccf14f7 3999 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4000 NEIGHBOR_STR
4001 NEIGHBOR_ADDR_STR2
4002 "Send Community attribute to this neighbor\n")
4003{
d62a17ae 4004 int idx_peer = 1;
4005 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4006 bgp_node_safi(vty),
4007 PEER_FLAG_SEND_COMMUNITY);
718e3744 4008}
4009
d62a17ae 4010ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4011 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4013 "Send Community attribute to this neighbor\n")
596c17ba 4014
718e3744 4015DEFUN (no_neighbor_send_community,
4016 no_neighbor_send_community_cmd,
9ccf14f7 4017 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4018 NO_STR
4019 NEIGHBOR_STR
4020 NEIGHBOR_ADDR_STR2
4021 "Send Community attribute to this neighbor\n")
4022{
d62a17ae 4023 int idx_peer = 2;
4024 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4025 bgp_node_afi(vty), bgp_node_safi(vty),
4026 PEER_FLAG_SEND_COMMUNITY);
718e3744 4027}
6b0655a2 4028
d62a17ae 4029ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4030 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4032 "Send Community attribute to this neighbor\n")
596c17ba 4033
718e3744 4034/* neighbor send-community extended. */
4035DEFUN (neighbor_send_community_type,
4036 neighbor_send_community_type_cmd,
57d187bc 4037 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Send Community attribute to this neighbor\n"
4041 "Send Standard and Extended Community attributes\n"
57d187bc 4042 "Send Standard, Large and Extended Community attributes\n"
718e3744 4043 "Send Extended Community attributes\n"
57d187bc
JS
4044 "Send Standard Community attributes\n"
4045 "Send Large Community attributes\n")
718e3744 4046{
d62a17ae 4047 int idx = 0;
4048 u_int32_t flag = 0;
4049
4050 char *peer = argv[1]->arg;
4051
4052 if (argv_find(argv, argc, "standard", &idx))
4053 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4054 else if (argv_find(argv, argc, "extended", &idx))
4055 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4056 else if (argv_find(argv, argc, "large", &idx))
4057 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4058 else if (argv_find(argv, argc, "both", &idx)) {
4059 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4060 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4061 } else {
4062 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4063 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4064 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4065 }
4066
4067 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4068 bgp_node_safi(vty), flag);
4069}
4070
4071ALIAS_HIDDEN(
4072 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4073 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4075 "Send Community attribute to this neighbor\n"
4076 "Send Standard and Extended Community attributes\n"
4077 "Send Standard, Large and Extended Community attributes\n"
4078 "Send Extended Community attributes\n"
4079 "Send Standard Community attributes\n"
4080 "Send Large Community attributes\n")
596c17ba 4081
718e3744 4082DEFUN (no_neighbor_send_community_type,
4083 no_neighbor_send_community_type_cmd,
57d187bc 4084 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4085 NO_STR
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Send Community attribute to this neighbor\n"
4089 "Send Standard and Extended Community attributes\n"
57d187bc 4090 "Send Standard, Large and Extended Community attributes\n"
718e3744 4091 "Send Extended Community attributes\n"
57d187bc
JS
4092 "Send Standard Community attributes\n"
4093 "Send Large Community attributes\n")
718e3744 4094{
d62a17ae 4095 int idx_peer = 2;
4096
4097 const char *type = argv[argc - 1]->text;
4098
4099 if (strmatch(type, "standard"))
4100 return peer_af_flag_unset_vty(
4101 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4102 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4103 if (strmatch(type, "extended"))
4104 return peer_af_flag_unset_vty(
4105 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4106 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4107 if (strmatch(type, "large"))
4108 return peer_af_flag_unset_vty(
4109 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4110 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4111 if (strmatch(type, "both"))
4112 return peer_af_flag_unset_vty(
4113 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4114 bgp_node_safi(vty),
4115 PEER_FLAG_SEND_COMMUNITY
4116 | PEER_FLAG_SEND_EXT_COMMUNITY);
4117
4118 /* if (strmatch (type, "all")) */
4119 return peer_af_flag_unset_vty(
4120 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4121 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4122 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4123}
4124
4125ALIAS_HIDDEN(
4126 no_neighbor_send_community_type,
4127 no_neighbor_send_community_type_hidden_cmd,
4128 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4129 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4130 "Send Community attribute to this neighbor\n"
4131 "Send Standard and Extended Community attributes\n"
4132 "Send Standard, Large and Extended Community attributes\n"
4133 "Send Extended Community attributes\n"
4134 "Send Standard Community attributes\n"
4135 "Send Large Community attributes\n")
596c17ba 4136
718e3744 4137/* neighbor soft-reconfig. */
4138DEFUN (neighbor_soft_reconfiguration,
4139 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4140 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4141 NEIGHBOR_STR
4142 NEIGHBOR_ADDR_STR2
4143 "Per neighbor soft reconfiguration\n"
4144 "Allow inbound soft reconfiguration for this neighbor\n")
4145{
d62a17ae 4146 int idx_peer = 1;
4147 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4148 bgp_node_safi(vty),
4149 PEER_FLAG_SOFT_RECONFIG);
718e3744 4150}
4151
d62a17ae 4152ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4153 neighbor_soft_reconfiguration_hidden_cmd,
4154 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4155 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4156 "Per neighbor soft reconfiguration\n"
4157 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4158
718e3744 4159DEFUN (no_neighbor_soft_reconfiguration,
4160 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4161 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4162 NO_STR
4163 NEIGHBOR_STR
4164 NEIGHBOR_ADDR_STR2
4165 "Per neighbor soft reconfiguration\n"
4166 "Allow inbound soft reconfiguration for this neighbor\n")
4167{
d62a17ae 4168 int idx_peer = 2;
4169 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4170 bgp_node_afi(vty), bgp_node_safi(vty),
4171 PEER_FLAG_SOFT_RECONFIG);
718e3744 4172}
6b0655a2 4173
d62a17ae 4174ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4175 no_neighbor_soft_reconfiguration_hidden_cmd,
4176 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4177 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4178 "Per neighbor soft reconfiguration\n"
4179 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4180
718e3744 4181DEFUN (neighbor_route_reflector_client,
4182 neighbor_route_reflector_client_cmd,
9ccf14f7 4183 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4184 NEIGHBOR_STR
4185 NEIGHBOR_ADDR_STR2
4186 "Configure a neighbor as Route Reflector client\n")
4187{
d62a17ae 4188 int idx_peer = 1;
4189 struct peer *peer;
718e3744 4190
4191
d62a17ae 4192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4193 if (!peer)
4194 return CMD_WARNING_CONFIG_FAILED;
718e3744 4195
d62a17ae 4196 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4197 bgp_node_safi(vty),
4198 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4199}
4200
d62a17ae 4201ALIAS_HIDDEN(neighbor_route_reflector_client,
4202 neighbor_route_reflector_client_hidden_cmd,
4203 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4205 "Configure a neighbor as Route Reflector client\n")
596c17ba 4206
718e3744 4207DEFUN (no_neighbor_route_reflector_client,
4208 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4209 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4210 NO_STR
4211 NEIGHBOR_STR
4212 NEIGHBOR_ADDR_STR2
4213 "Configure a neighbor as Route Reflector client\n")
4214{
d62a17ae 4215 int idx_peer = 2;
4216 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4217 bgp_node_afi(vty), bgp_node_safi(vty),
4218 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4219}
6b0655a2 4220
d62a17ae 4221ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4222 no_neighbor_route_reflector_client_hidden_cmd,
4223 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4224 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4225 "Configure a neighbor as Route Reflector client\n")
596c17ba 4226
718e3744 4227/* neighbor route-server-client. */
4228DEFUN (neighbor_route_server_client,
4229 neighbor_route_server_client_cmd,
9ccf14f7 4230 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4231 NEIGHBOR_STR
4232 NEIGHBOR_ADDR_STR2
4233 "Configure a neighbor as Route Server client\n")
4234{
d62a17ae 4235 int idx_peer = 1;
4236 struct peer *peer;
2a3d5731 4237
d62a17ae 4238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4239 if (!peer)
4240 return CMD_WARNING_CONFIG_FAILED;
4241 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4242 bgp_node_safi(vty),
4243 PEER_FLAG_RSERVER_CLIENT);
718e3744 4244}
4245
d62a17ae 4246ALIAS_HIDDEN(neighbor_route_server_client,
4247 neighbor_route_server_client_hidden_cmd,
4248 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4250 "Configure a neighbor as Route Server client\n")
596c17ba 4251
718e3744 4252DEFUN (no_neighbor_route_server_client,
4253 no_neighbor_route_server_client_cmd,
9ccf14f7 4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4255 NO_STR
4256 NEIGHBOR_STR
4257 NEIGHBOR_ADDR_STR2
4258 "Configure a neighbor as Route Server client\n")
fee0f4c6 4259{
d62a17ae 4260 int idx_peer = 2;
4261 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4262 bgp_node_afi(vty), bgp_node_safi(vty),
4263 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4264}
6b0655a2 4265
d62a17ae 4266ALIAS_HIDDEN(no_neighbor_route_server_client,
4267 no_neighbor_route_server_client_hidden_cmd,
4268 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4269 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4270 "Configure a neighbor as Route Server client\n")
596c17ba 4271
fee0f4c6 4272DEFUN (neighbor_nexthop_local_unchanged,
4273 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4274 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
4277 "Configure treatment of outgoing link-local nexthop attribute\n"
4278 "Leave link-local nexthop unchanged for this peer\n")
4279{
d62a17ae 4280 int idx_peer = 1;
4281 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4282 bgp_node_safi(vty),
4283 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4284}
6b0655a2 4285
fee0f4c6 4286DEFUN (no_neighbor_nexthop_local_unchanged,
4287 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4288 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4289 NO_STR
4290 NEIGHBOR_STR
4291 NEIGHBOR_ADDR_STR2
4292 "Configure treatment of outgoing link-local-nexthop attribute\n"
4293 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4294{
d62a17ae 4295 int idx_peer = 2;
4296 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4297 bgp_node_afi(vty), bgp_node_safi(vty),
4298 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4299}
6b0655a2 4300
718e3744 4301DEFUN (neighbor_attr_unchanged,
4302 neighbor_attr_unchanged_cmd,
a8206004 4303 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4304 NEIGHBOR_STR
4305 NEIGHBOR_ADDR_STR2
4306 "BGP attribute is propagated unchanged to this neighbor\n"
4307 "As-path attribute\n"
4308 "Nexthop attribute\n"
a8206004 4309 "Med attribute\n")
718e3744 4310{
d62a17ae 4311 int idx = 0;
8eeb0335
DW
4312 char *peer_str = argv[1]->arg;
4313 struct peer *peer;
d62a17ae 4314 u_int16_t flags = 0;
8eeb0335
DW
4315 afi_t afi = bgp_node_afi(vty);
4316 safi_t safi = bgp_node_safi(vty);
4317
4318 peer = peer_and_group_lookup_vty(vty, peer_str);
4319 if (!peer)
4320 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4321
4322 if (argv_find(argv, argc, "as-path", &idx))
4323 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4324 idx = 0;
4325 if (argv_find(argv, argc, "next-hop", &idx))
4326 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4327 idx = 0;
4328 if (argv_find(argv, argc, "med", &idx))
4329 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4330
8eeb0335
DW
4331 /* no flags means all of them! */
4332 if (!flags) {
d62a17ae 4333 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4334 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4335 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335
DW
4336 } else {
4337 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) &&
4338 peer_af_flag_check(peer, afi, safi,
4339 PEER_FLAG_AS_PATH_UNCHANGED)) {
4340 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4341 PEER_FLAG_AS_PATH_UNCHANGED);
4342 }
4343
4344 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) &&
4345 peer_af_flag_check(peer, afi, safi,
4346 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4347 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4348 PEER_FLAG_NEXTHOP_UNCHANGED);
4349 }
4350
4351 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) &&
4352 peer_af_flag_check(peer, afi, safi,
4353 PEER_FLAG_MED_UNCHANGED)) {
4354 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4355 PEER_FLAG_MED_UNCHANGED);
4356 }
d62a17ae 4357 }
4358
8eeb0335 4359 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4360}
4361
4362ALIAS_HIDDEN(
4363 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4364 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4366 "BGP attribute is propagated unchanged to this neighbor\n"
4367 "As-path attribute\n"
4368 "Nexthop attribute\n"
4369 "Med attribute\n")
596c17ba 4370
718e3744 4371DEFUN (no_neighbor_attr_unchanged,
4372 no_neighbor_attr_unchanged_cmd,
a8206004 4373 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4374 NO_STR
718e3744 4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
31500417
DW
4377 "BGP attribute is propagated unchanged to this neighbor\n"
4378 "As-path attribute\n"
40e718b5 4379 "Nexthop attribute\n"
a8206004 4380 "Med attribute\n")
718e3744 4381{
d62a17ae 4382 int idx = 0;
4383 char *peer = argv[2]->arg;
4384 u_int16_t flags = 0;
4385
4386 if (argv_find(argv, argc, "as-path", &idx))
4387 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4388 idx = 0;
4389 if (argv_find(argv, argc, "next-hop", &idx))
4390 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4391 idx = 0;
4392 if (argv_find(argv, argc, "med", &idx))
4393 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4394
4395 if (!flags) // no flags means all of them!
4396 {
4397 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4398 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4399 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4400 }
4401
4402 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4403 bgp_node_safi(vty), flags);
4404}
4405
4406ALIAS_HIDDEN(
4407 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4408 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4409 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4410 "BGP attribute is propagated unchanged to this neighbor\n"
4411 "As-path attribute\n"
4412 "Nexthop attribute\n"
4413 "Med attribute\n")
718e3744 4414
718e3744 4415/* EBGP multihop configuration. */
d62a17ae 4416static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4417 const char *ttl_str)
718e3744 4418{
d62a17ae 4419 struct peer *peer;
4420 unsigned int ttl;
718e3744 4421
d62a17ae 4422 peer = peer_and_group_lookup_vty(vty, ip_str);
4423 if (!peer)
4424 return CMD_WARNING_CONFIG_FAILED;
718e3744 4425
d62a17ae 4426 if (peer->conf_if)
4427 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4428
d62a17ae 4429 if (!ttl_str)
4430 ttl = MAXTTL;
4431 else
4432 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4433
d62a17ae 4434 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4435}
4436
d62a17ae 4437static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4438{
d62a17ae 4439 struct peer *peer;
718e3744 4440
d62a17ae 4441 peer = peer_and_group_lookup_vty(vty, ip_str);
4442 if (!peer)
4443 return CMD_WARNING_CONFIG_FAILED;
718e3744 4444
d62a17ae 4445 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4446}
4447
4448/* neighbor ebgp-multihop. */
4449DEFUN (neighbor_ebgp_multihop,
4450 neighbor_ebgp_multihop_cmd,
9ccf14f7 4451 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4452 NEIGHBOR_STR
4453 NEIGHBOR_ADDR_STR2
4454 "Allow EBGP neighbors not on directly connected networks\n")
4455{
d62a17ae 4456 int idx_peer = 1;
4457 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4458}
4459
4460DEFUN (neighbor_ebgp_multihop_ttl,
4461 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4462 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4463 NEIGHBOR_STR
4464 NEIGHBOR_ADDR_STR2
4465 "Allow EBGP neighbors not on directly connected networks\n"
4466 "maximum hop count\n")
4467{
d62a17ae 4468 int idx_peer = 1;
4469 int idx_number = 3;
4470 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4471 argv[idx_number]->arg);
718e3744 4472}
4473
4474DEFUN (no_neighbor_ebgp_multihop,
4475 no_neighbor_ebgp_multihop_cmd,
a636c635 4476 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4477 NO_STR
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
a636c635
DW
4480 "Allow EBGP neighbors not on directly connected networks\n"
4481 "maximum hop count\n")
718e3744 4482{
d62a17ae 4483 int idx_peer = 2;
4484 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4485}
4486
6b0655a2 4487
6ffd2079 4488/* disable-connected-check */
4489DEFUN (neighbor_disable_connected_check,
4490 neighbor_disable_connected_check_cmd,
a636c635 4491 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
a636c635
DW
4494 "one-hop away EBGP peer using loopback address\n"
4495 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4496{
d62a17ae 4497 int idx_peer = 1;
4498 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4499 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4500}
4501
4502DEFUN (no_neighbor_disable_connected_check,
4503 no_neighbor_disable_connected_check_cmd,
a636c635 4504 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4505 NO_STR
4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
a636c635
DW
4508 "one-hop away EBGP peer using loopback address\n"
4509 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4510{
d62a17ae 4511 int idx_peer = 2;
4512 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4513 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4514}
4515
718e3744 4516DEFUN (neighbor_description,
4517 neighbor_description_cmd,
e961923c 4518 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4519 NEIGHBOR_STR
4520 NEIGHBOR_ADDR_STR2
4521 "Neighbor specific description\n"
4522 "Up to 80 characters describing this neighbor\n")
4523{
d62a17ae 4524 int idx_peer = 1;
4525 int idx_line = 3;
4526 struct peer *peer;
4527 char *str;
718e3744 4528
d62a17ae 4529 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4530 if (!peer)
4531 return CMD_WARNING_CONFIG_FAILED;
718e3744 4532
d62a17ae 4533 str = argv_concat(argv, argc, idx_line);
718e3744 4534
d62a17ae 4535 peer_description_set(peer, str);
718e3744 4536
d62a17ae 4537 XFREE(MTYPE_TMP, str);
718e3744 4538
d62a17ae 4539 return CMD_SUCCESS;
718e3744 4540}
4541
4542DEFUN (no_neighbor_description,
4543 no_neighbor_description_cmd,
a636c635 4544 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4545 NO_STR
4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
a636c635
DW
4548 "Neighbor specific description\n"
4549 "Up to 80 characters describing this neighbor\n")
718e3744 4550{
d62a17ae 4551 int idx_peer = 2;
4552 struct peer *peer;
718e3744 4553
d62a17ae 4554 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4555 if (!peer)
4556 return CMD_WARNING_CONFIG_FAILED;
718e3744 4557
d62a17ae 4558 peer_description_unset(peer);
718e3744 4559
d62a17ae 4560 return CMD_SUCCESS;
718e3744 4561}
4562
6b0655a2 4563
718e3744 4564/* Neighbor update-source. */
d62a17ae 4565static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4566 const char *source_str)
4567{
4568 struct peer *peer;
4569 struct prefix p;
4570
4571 peer = peer_and_group_lookup_vty(vty, peer_str);
4572 if (!peer)
4573 return CMD_WARNING_CONFIG_FAILED;
4574
4575 if (peer->conf_if)
4576 return CMD_WARNING;
4577
4578 if (source_str) {
4579 union sockunion su;
4580 int ret = str2sockunion(source_str, &su);
4581
4582 if (ret == 0)
4583 peer_update_source_addr_set(peer, &su);
4584 else {
4585 if (str2prefix(source_str, &p)) {
4586 vty_out(vty,
4587 "%% Invalid update-source, remove prefix length \n");
4588 return CMD_WARNING_CONFIG_FAILED;
4589 } else
4590 peer_update_source_if_set(peer, source_str);
4591 }
4592 } else
4593 peer_update_source_unset(peer);
4594
4595 return CMD_SUCCESS;
4596}
4597
4598#define BGP_UPDATE_SOURCE_HELP_STR \
4599 "IPv4 address\n" \
4600 "IPv6 address\n" \
4601 "Interface name (requires zebra to be running)\n"
369688c0 4602
718e3744 4603DEFUN (neighbor_update_source,
4604 neighbor_update_source_cmd,
9ccf14f7 4605 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4606 NEIGHBOR_STR
4607 NEIGHBOR_ADDR_STR2
4608 "Source of routing updates\n"
369688c0 4609 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4610{
d62a17ae 4611 int idx_peer = 1;
4612 int idx_peer_2 = 3;
4613 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4614 argv[idx_peer_2]->arg);
718e3744 4615}
4616
4617DEFUN (no_neighbor_update_source,
4618 no_neighbor_update_source_cmd,
c7178fe7 4619 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4620 NO_STR
4621 NEIGHBOR_STR
4622 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4623 "Source of routing updates\n"
4624 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4625{
d62a17ae 4626 int idx_peer = 2;
4627 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4628}
6b0655a2 4629
d62a17ae 4630static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4631 afi_t afi, safi_t safi,
4632 const char *rmap, int set)
718e3744 4633{
d62a17ae 4634 int ret;
4635 struct peer *peer;
718e3744 4636
d62a17ae 4637 peer = peer_and_group_lookup_vty(vty, peer_str);
4638 if (!peer)
4639 return CMD_WARNING_CONFIG_FAILED;
718e3744 4640
d62a17ae 4641 if (set)
4642 ret = peer_default_originate_set(peer, afi, safi, rmap);
4643 else
4644 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4645
d62a17ae 4646 return bgp_vty_return(vty, ret);
718e3744 4647}
4648
4649/* neighbor default-originate. */
4650DEFUN (neighbor_default_originate,
4651 neighbor_default_originate_cmd,
9ccf14f7 4652 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4653 NEIGHBOR_STR
4654 NEIGHBOR_ADDR_STR2
4655 "Originate default route to this neighbor\n")
4656{
d62a17ae 4657 int idx_peer = 1;
4658 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4659 bgp_node_afi(vty),
4660 bgp_node_safi(vty), NULL, 1);
718e3744 4661}
4662
d62a17ae 4663ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4664 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4665 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4666 "Originate default route to this neighbor\n")
596c17ba 4667
718e3744 4668DEFUN (neighbor_default_originate_rmap,
4669 neighbor_default_originate_rmap_cmd,
9ccf14f7 4670 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4671 NEIGHBOR_STR
4672 NEIGHBOR_ADDR_STR2
4673 "Originate default route to this neighbor\n"
4674 "Route-map to specify criteria to originate default\n"
4675 "route-map name\n")
4676{
d62a17ae 4677 int idx_peer = 1;
4678 int idx_word = 4;
4679 return peer_default_originate_set_vty(
4680 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4681 argv[idx_word]->arg, 1);
718e3744 4682}
4683
d62a17ae 4684ALIAS_HIDDEN(
4685 neighbor_default_originate_rmap,
4686 neighbor_default_originate_rmap_hidden_cmd,
4687 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4688 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4689 "Originate default route to this neighbor\n"
4690 "Route-map to specify criteria to originate default\n"
4691 "route-map name\n")
596c17ba 4692
718e3744 4693DEFUN (no_neighbor_default_originate,
4694 no_neighbor_default_originate_cmd,
a636c635 4695 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4696 NO_STR
4697 NEIGHBOR_STR
4698 NEIGHBOR_ADDR_STR2
a636c635
DW
4699 "Originate default route to this neighbor\n"
4700 "Route-map to specify criteria to originate default\n"
4701 "route-map name\n")
718e3744 4702{
d62a17ae 4703 int idx_peer = 2;
4704 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4705 bgp_node_afi(vty),
4706 bgp_node_safi(vty), NULL, 0);
718e3744 4707}
4708
d62a17ae 4709ALIAS_HIDDEN(
4710 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4711 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4713 "Originate default route to this neighbor\n"
4714 "Route-map to specify criteria to originate default\n"
4715 "route-map name\n")
596c17ba 4716
6b0655a2 4717
718e3744 4718/* Set neighbor's BGP port. */
d62a17ae 4719static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4720 const char *port_str)
4721{
4722 struct peer *peer;
4723 u_int16_t port;
4724 struct servent *sp;
4725
4726 peer = peer_lookup_vty(vty, ip_str);
4727 if (!peer)
4728 return CMD_WARNING_CONFIG_FAILED;
4729
4730 if (!port_str) {
4731 sp = getservbyname("bgp", "tcp");
4732 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4733 } else {
4734 port = strtoul(port_str, NULL, 10);
4735 }
718e3744 4736
d62a17ae 4737 peer_port_set(peer, port);
718e3744 4738
d62a17ae 4739 return CMD_SUCCESS;
718e3744 4740}
4741
f418446b 4742/* Set specified peer's BGP port. */
718e3744 4743DEFUN (neighbor_port,
4744 neighbor_port_cmd,
9ccf14f7 4745 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4746 NEIGHBOR_STR
4747 NEIGHBOR_ADDR_STR
4748 "Neighbor's BGP port\n"
4749 "TCP port number\n")
4750{
d62a17ae 4751 int idx_ip = 1;
4752 int idx_number = 3;
4753 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4754 argv[idx_number]->arg);
718e3744 4755}
4756
4757DEFUN (no_neighbor_port,
4758 no_neighbor_port_cmd,
9ccf14f7 4759 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4760 NO_STR
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR
8334fd5a
DW
4763 "Neighbor's BGP port\n"
4764 "TCP port number\n")
718e3744 4765{
d62a17ae 4766 int idx_ip = 2;
4767 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4768}
4769
6b0655a2 4770
718e3744 4771/* neighbor weight. */
d62a17ae 4772static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4773 safi_t safi, const char *weight_str)
718e3744 4774{
d62a17ae 4775 int ret;
4776 struct peer *peer;
4777 unsigned long weight;
718e3744 4778
d62a17ae 4779 peer = peer_and_group_lookup_vty(vty, ip_str);
4780 if (!peer)
4781 return CMD_WARNING_CONFIG_FAILED;
718e3744 4782
d62a17ae 4783 weight = strtoul(weight_str, NULL, 10);
718e3744 4784
d62a17ae 4785 ret = peer_weight_set(peer, afi, safi, weight);
4786 return bgp_vty_return(vty, ret);
718e3744 4787}
4788
d62a17ae 4789static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4790 safi_t safi)
718e3744 4791{
d62a17ae 4792 int ret;
4793 struct peer *peer;
718e3744 4794
d62a17ae 4795 peer = peer_and_group_lookup_vty(vty, ip_str);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
718e3744 4798
d62a17ae 4799 ret = peer_weight_unset(peer, afi, safi);
4800 return bgp_vty_return(vty, ret);
718e3744 4801}
4802
4803DEFUN (neighbor_weight,
4804 neighbor_weight_cmd,
9ccf14f7 4805 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Set default weight for routes from this neighbor\n"
4809 "default weight\n")
4810{
d62a17ae 4811 int idx_peer = 1;
4812 int idx_number = 3;
4813 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4814 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4815}
4816
d62a17ae 4817ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4818 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4819 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4820 "Set default weight for routes from this neighbor\n"
4821 "default weight\n")
596c17ba 4822
718e3744 4823DEFUN (no_neighbor_weight,
4824 no_neighbor_weight_cmd,
9ccf14f7 4825 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4826 NO_STR
4827 NEIGHBOR_STR
4828 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4829 "Set default weight for routes from this neighbor\n"
4830 "default weight\n")
718e3744 4831{
d62a17ae 4832 int idx_peer = 2;
4833 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4834 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4835}
4836
d62a17ae 4837ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4838 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4840 "Set default weight for routes from this neighbor\n"
4841 "default weight\n")
596c17ba 4842
6b0655a2 4843
718e3744 4844/* Override capability negotiation. */
4845DEFUN (neighbor_override_capability,
4846 neighbor_override_capability_cmd,
9ccf14f7 4847 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4848 NEIGHBOR_STR
4849 NEIGHBOR_ADDR_STR2
4850 "Override capability negotiation result\n")
4851{
d62a17ae 4852 int idx_peer = 1;
4853 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4854 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4855}
4856
4857DEFUN (no_neighbor_override_capability,
4858 no_neighbor_override_capability_cmd,
9ccf14f7 4859 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4860 NO_STR
4861 NEIGHBOR_STR
4862 NEIGHBOR_ADDR_STR2
4863 "Override capability negotiation result\n")
4864{
d62a17ae 4865 int idx_peer = 2;
4866 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4867 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4868}
6b0655a2 4869
718e3744 4870DEFUN (neighbor_strict_capability,
4871 neighbor_strict_capability_cmd,
9ccf14f7 4872 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4873 NEIGHBOR_STR
4874 NEIGHBOR_ADDR_STR
4875 "Strict capability negotiation match\n")
4876{
d62a17ae 4877 int idx_ip = 1;
4878 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4879 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4880}
4881
4882DEFUN (no_neighbor_strict_capability,
4883 no_neighbor_strict_capability_cmd,
9ccf14f7 4884 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4885 NO_STR
4886 NEIGHBOR_STR
4887 NEIGHBOR_ADDR_STR
4888 "Strict capability negotiation match\n")
4889{
d62a17ae 4890 int idx_ip = 2;
4891 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4892 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4893}
6b0655a2 4894
d62a17ae 4895static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4896 const char *keep_str, const char *hold_str)
718e3744 4897{
d62a17ae 4898 int ret;
4899 struct peer *peer;
4900 u_int32_t keepalive;
4901 u_int32_t holdtime;
718e3744 4902
d62a17ae 4903 peer = peer_and_group_lookup_vty(vty, ip_str);
4904 if (!peer)
4905 return CMD_WARNING_CONFIG_FAILED;
718e3744 4906
d62a17ae 4907 keepalive = strtoul(keep_str, NULL, 10);
4908 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4909
d62a17ae 4910 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4911
d62a17ae 4912 return bgp_vty_return(vty, ret);
718e3744 4913}
6b0655a2 4914
d62a17ae 4915static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4916{
d62a17ae 4917 int ret;
4918 struct peer *peer;
718e3744 4919
d62a17ae 4920 peer = peer_and_group_lookup_vty(vty, ip_str);
4921 if (!peer)
4922 return CMD_WARNING_CONFIG_FAILED;
718e3744 4923
d62a17ae 4924 ret = peer_timers_unset(peer);
718e3744 4925
d62a17ae 4926 return bgp_vty_return(vty, ret);
718e3744 4927}
4928
4929DEFUN (neighbor_timers,
4930 neighbor_timers_cmd,
9ccf14f7 4931 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4932 NEIGHBOR_STR
4933 NEIGHBOR_ADDR_STR2
4934 "BGP per neighbor timers\n"
4935 "Keepalive interval\n"
4936 "Holdtime\n")
4937{
d62a17ae 4938 int idx_peer = 1;
4939 int idx_number = 3;
4940 int idx_number_2 = 4;
4941 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4942 argv[idx_number]->arg,
4943 argv[idx_number_2]->arg);
718e3744 4944}
4945
4946DEFUN (no_neighbor_timers,
4947 no_neighbor_timers_cmd,
9ccf14f7 4948 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4949 NO_STR
4950 NEIGHBOR_STR
4951 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4952 "BGP per neighbor timers\n"
4953 "Keepalive interval\n"
4954 "Holdtime\n")
718e3744 4955{
d62a17ae 4956 int idx_peer = 2;
4957 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4958}
6b0655a2 4959
813d4307 4960
d62a17ae 4961static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4962 const char *time_str)
718e3744 4963{
d62a17ae 4964 int ret;
4965 struct peer *peer;
4966 u_int32_t connect;
718e3744 4967
d62a17ae 4968 peer = peer_and_group_lookup_vty(vty, ip_str);
4969 if (!peer)
4970 return CMD_WARNING_CONFIG_FAILED;
718e3744 4971
d62a17ae 4972 connect = strtoul(time_str, NULL, 10);
718e3744 4973
d62a17ae 4974 ret = peer_timers_connect_set(peer, connect);
718e3744 4975
d62a17ae 4976 return bgp_vty_return(vty, ret);
718e3744 4977}
4978
d62a17ae 4979static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4980{
d62a17ae 4981 int ret;
4982 struct peer *peer;
718e3744 4983
d62a17ae 4984 peer = peer_and_group_lookup_vty(vty, ip_str);
4985 if (!peer)
4986 return CMD_WARNING_CONFIG_FAILED;
718e3744 4987
d62a17ae 4988 ret = peer_timers_connect_unset(peer);
718e3744 4989
d62a17ae 4990 return bgp_vty_return(vty, ret);
718e3744 4991}
4992
4993DEFUN (neighbor_timers_connect,
4994 neighbor_timers_connect_cmd,
9ccf14f7 4995 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 4996 NEIGHBOR_STR
966f821c 4997 NEIGHBOR_ADDR_STR2
718e3744 4998 "BGP per neighbor timers\n"
4999 "BGP connect timer\n"
5000 "Connect timer\n")
5001{
d62a17ae 5002 int idx_peer = 1;
5003 int idx_number = 4;
5004 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5005 argv[idx_number]->arg);
718e3744 5006}
5007
5008DEFUN (no_neighbor_timers_connect,
5009 no_neighbor_timers_connect_cmd,
9ccf14f7 5010 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5011 NO_STR
5012 NEIGHBOR_STR
966f821c 5013 NEIGHBOR_ADDR_STR2
718e3744 5014 "BGP per neighbor timers\n"
8334fd5a
DW
5015 "BGP connect timer\n"
5016 "Connect timer\n")
718e3744 5017{
d62a17ae 5018 int idx_peer = 2;
5019 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5020}
5021
6b0655a2 5022
d62a17ae 5023static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5024 const char *time_str, int set)
718e3744 5025{
d62a17ae 5026 int ret;
5027 struct peer *peer;
5028 u_int32_t routeadv = 0;
718e3744 5029
d62a17ae 5030 peer = peer_and_group_lookup_vty(vty, ip_str);
5031 if (!peer)
5032 return CMD_WARNING_CONFIG_FAILED;
718e3744 5033
d62a17ae 5034 if (time_str)
5035 routeadv = strtoul(time_str, NULL, 10);
718e3744 5036
d62a17ae 5037 if (set)
5038 ret = peer_advertise_interval_set(peer, routeadv);
5039 else
5040 ret = peer_advertise_interval_unset(peer);
718e3744 5041
d62a17ae 5042 return bgp_vty_return(vty, ret);
718e3744 5043}
5044
5045DEFUN (neighbor_advertise_interval,
5046 neighbor_advertise_interval_cmd,
9ccf14f7 5047 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5048 NEIGHBOR_STR
966f821c 5049 NEIGHBOR_ADDR_STR2
718e3744 5050 "Minimum interval between sending BGP routing updates\n"
5051 "time in seconds\n")
5052{
d62a17ae 5053 int idx_peer = 1;
5054 int idx_number = 3;
5055 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5056 argv[idx_number]->arg, 1);
718e3744 5057}
5058
5059DEFUN (no_neighbor_advertise_interval,
5060 no_neighbor_advertise_interval_cmd,
9ccf14f7 5061 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5062 NO_STR
5063 NEIGHBOR_STR
966f821c 5064 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5065 "Minimum interval between sending BGP routing updates\n"
5066 "time in seconds\n")
718e3744 5067{
d62a17ae 5068 int idx_peer = 2;
5069 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5070}
5071
6b0655a2 5072
518f0eb1
DS
5073/* Time to wait before processing route-map updates */
5074DEFUN (bgp_set_route_map_delay_timer,
5075 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5076 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5077 SET_STR
5078 "BGP route-map delay timer\n"
5079 "Time in secs to wait before processing route-map changes\n"
f414725f 5080 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5081{
d62a17ae 5082 int idx_number = 3;
5083 u_int32_t rmap_delay_timer;
5084
5085 if (argv[idx_number]->arg) {
5086 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5087 bm->rmap_update_timer = rmap_delay_timer;
5088
5089 /* if the dynamic update handling is being disabled, and a timer
5090 * is
5091 * running, stop the timer and act as if the timer has already
5092 * fired.
5093 */
5094 if (!rmap_delay_timer && bm->t_rmap_update) {
5095 BGP_TIMER_OFF(bm->t_rmap_update);
5096 thread_execute(bm->master, bgp_route_map_update_timer,
5097 NULL, 0);
5098 }
5099 return CMD_SUCCESS;
5100 } else {
5101 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5102 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5103 }
518f0eb1
DS
5104}
5105
5106DEFUN (no_bgp_set_route_map_delay_timer,
5107 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5108 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5109 NO_STR
3a2d747c 5110 BGP_STR
518f0eb1 5111 "Default BGP route-map delay timer\n"
8334fd5a
DW
5112 "Reset to default time to wait for processing route-map changes\n"
5113 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5114{
518f0eb1 5115
d62a17ae 5116 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5117
d62a17ae 5118 return CMD_SUCCESS;
518f0eb1
DS
5119}
5120
f414725f 5121
718e3744 5122/* neighbor interface */
d62a17ae 5123static int peer_interface_vty(struct vty *vty, const char *ip_str,
5124 const char *str)
718e3744 5125{
d62a17ae 5126 struct peer *peer;
718e3744 5127
d62a17ae 5128 peer = peer_lookup_vty(vty, ip_str);
5129 if (!peer || peer->conf_if) {
5130 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5131 return CMD_WARNING_CONFIG_FAILED;
5132 }
718e3744 5133
d62a17ae 5134 if (str)
5135 peer_interface_set(peer, str);
5136 else
5137 peer_interface_unset(peer);
718e3744 5138
d62a17ae 5139 return CMD_SUCCESS;
718e3744 5140}
5141
5142DEFUN (neighbor_interface,
5143 neighbor_interface_cmd,
9ccf14f7 5144 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5145 NEIGHBOR_STR
5146 NEIGHBOR_ADDR_STR
5147 "Interface\n"
5148 "Interface name\n")
5149{
d62a17ae 5150 int idx_ip = 1;
5151 int idx_word = 3;
5152 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5153}
5154
5155DEFUN (no_neighbor_interface,
5156 no_neighbor_interface_cmd,
9ccf14f7 5157 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5158 NO_STR
5159 NEIGHBOR_STR
16cedbb0 5160 NEIGHBOR_ADDR_STR2
718e3744 5161 "Interface\n"
5162 "Interface name\n")
5163{
d62a17ae 5164 int idx_peer = 2;
5165 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5166}
6b0655a2 5167
718e3744 5168DEFUN (neighbor_distribute_list,
5169 neighbor_distribute_list_cmd,
9ccf14f7 5170 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
5173 "Filter updates to/from this neighbor\n"
5174 "IP access-list number\n"
5175 "IP access-list number (expanded range)\n"
5176 "IP Access-list name\n"
5177 "Filter incoming updates\n"
5178 "Filter outgoing updates\n")
5179{
d62a17ae 5180 int idx_peer = 1;
5181 int idx_acl = 3;
5182 int direct, ret;
5183 struct peer *peer;
a8206004 5184
d62a17ae 5185 const char *pstr = argv[idx_peer]->arg;
5186 const char *acl = argv[idx_acl]->arg;
5187 const char *inout = argv[argc - 1]->text;
a8206004 5188
d62a17ae 5189 peer = peer_and_group_lookup_vty(vty, pstr);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
a8206004 5192
d62a17ae 5193 /* Check filter direction. */
5194 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5195 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5196 direct, acl);
a8206004 5197
d62a17ae 5198 return bgp_vty_return(vty, ret);
718e3744 5199}
5200
d62a17ae 5201ALIAS_HIDDEN(
5202 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5203 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5204 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5205 "Filter updates to/from this neighbor\n"
5206 "IP access-list number\n"
5207 "IP access-list number (expanded range)\n"
5208 "IP Access-list name\n"
5209 "Filter incoming updates\n"
5210 "Filter outgoing updates\n")
596c17ba 5211
718e3744 5212DEFUN (no_neighbor_distribute_list,
5213 no_neighbor_distribute_list_cmd,
9ccf14f7 5214 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5215 NO_STR
5216 NEIGHBOR_STR
5217 NEIGHBOR_ADDR_STR2
5218 "Filter updates to/from this neighbor\n"
5219 "IP access-list number\n"
5220 "IP access-list number (expanded range)\n"
5221 "IP Access-list name\n"
5222 "Filter incoming updates\n"
5223 "Filter outgoing updates\n")
5224{
d62a17ae 5225 int idx_peer = 2;
5226 int direct, ret;
5227 struct peer *peer;
a8206004 5228
d62a17ae 5229 const char *pstr = argv[idx_peer]->arg;
5230 const char *inout = argv[argc - 1]->text;
a8206004 5231
d62a17ae 5232 peer = peer_and_group_lookup_vty(vty, pstr);
5233 if (!peer)
5234 return CMD_WARNING_CONFIG_FAILED;
a8206004 5235
d62a17ae 5236 /* Check filter direction. */
5237 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5238 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5239 direct);
a8206004 5240
d62a17ae 5241 return bgp_vty_return(vty, ret);
718e3744 5242}
6b0655a2 5243
d62a17ae 5244ALIAS_HIDDEN(
5245 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5246 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5247 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5248 "Filter updates to/from this neighbor\n"
5249 "IP access-list number\n"
5250 "IP access-list number (expanded range)\n"
5251 "IP Access-list name\n"
5252 "Filter incoming updates\n"
5253 "Filter outgoing updates\n")
596c17ba 5254
718e3744 5255/* Set prefix list to the peer. */
d62a17ae 5256static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5257 afi_t afi, safi_t safi,
5258 const char *name_str,
5259 const char *direct_str)
718e3744 5260{
d62a17ae 5261 int ret;
5262 struct peer *peer;
5263 int direct = FILTER_IN;
718e3744 5264
d62a17ae 5265 peer = peer_and_group_lookup_vty(vty, ip_str);
5266 if (!peer)
5267 return CMD_WARNING_CONFIG_FAILED;
718e3744 5268
d62a17ae 5269 /* Check filter direction. */
5270 if (strncmp(direct_str, "i", 1) == 0)
5271 direct = FILTER_IN;
5272 else if (strncmp(direct_str, "o", 1) == 0)
5273 direct = FILTER_OUT;
718e3744 5274
d62a17ae 5275 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5276
d62a17ae 5277 return bgp_vty_return(vty, ret);
718e3744 5278}
5279
d62a17ae 5280static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5281 afi_t afi, safi_t safi,
5282 const char *direct_str)
718e3744 5283{
d62a17ae 5284 int ret;
5285 struct peer *peer;
5286 int direct = FILTER_IN;
718e3744 5287
d62a17ae 5288 peer = peer_and_group_lookup_vty(vty, ip_str);
5289 if (!peer)
5290 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5291
d62a17ae 5292 /* Check filter direction. */
5293 if (strncmp(direct_str, "i", 1) == 0)
5294 direct = FILTER_IN;
5295 else if (strncmp(direct_str, "o", 1) == 0)
5296 direct = FILTER_OUT;
718e3744 5297
d62a17ae 5298 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5299
d62a17ae 5300 return bgp_vty_return(vty, ret);
718e3744 5301}
5302
5303DEFUN (neighbor_prefix_list,
5304 neighbor_prefix_list_cmd,
9ccf14f7 5305 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5306 NEIGHBOR_STR
5307 NEIGHBOR_ADDR_STR2
5308 "Filter updates to/from this neighbor\n"
5309 "Name of a prefix list\n"
5310 "Filter incoming updates\n"
5311 "Filter outgoing updates\n")
5312{
d62a17ae 5313 int idx_peer = 1;
5314 int idx_word = 3;
5315 int idx_in_out = 4;
5316 return peer_prefix_list_set_vty(
5317 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5318 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5319}
5320
d62a17ae 5321ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5322 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5323 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5324 "Filter updates to/from this neighbor\n"
5325 "Name of a prefix list\n"
5326 "Filter incoming updates\n"
5327 "Filter outgoing updates\n")
596c17ba 5328
718e3744 5329DEFUN (no_neighbor_prefix_list,
5330 no_neighbor_prefix_list_cmd,
9ccf14f7 5331 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5332 NO_STR
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Filter updates to/from this neighbor\n"
5336 "Name of a prefix list\n"
5337 "Filter incoming updates\n"
5338 "Filter outgoing updates\n")
5339{
d62a17ae 5340 int idx_peer = 2;
5341 int idx_in_out = 5;
5342 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5343 bgp_node_afi(vty), bgp_node_safi(vty),
5344 argv[idx_in_out]->arg);
718e3744 5345}
6b0655a2 5346
d62a17ae 5347ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5349 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5350 "Filter updates to/from this neighbor\n"
5351 "Name of a prefix list\n"
5352 "Filter incoming updates\n"
5353 "Filter outgoing updates\n")
596c17ba 5354
d62a17ae 5355static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5356 safi_t safi, const char *name_str,
5357 const char *direct_str)
718e3744 5358{
d62a17ae 5359 int ret;
5360 struct peer *peer;
5361 int direct = FILTER_IN;
718e3744 5362
d62a17ae 5363 peer = peer_and_group_lookup_vty(vty, ip_str);
5364 if (!peer)
5365 return CMD_WARNING_CONFIG_FAILED;
718e3744 5366
d62a17ae 5367 /* Check filter direction. */
5368 if (strncmp(direct_str, "i", 1) == 0)
5369 direct = FILTER_IN;
5370 else if (strncmp(direct_str, "o", 1) == 0)
5371 direct = FILTER_OUT;
718e3744 5372
d62a17ae 5373 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5374
d62a17ae 5375 return bgp_vty_return(vty, ret);
718e3744 5376}
5377
d62a17ae 5378static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5379 safi_t safi, const char *direct_str)
718e3744 5380{
d62a17ae 5381 int ret;
5382 struct peer *peer;
5383 int direct = FILTER_IN;
718e3744 5384
d62a17ae 5385 peer = peer_and_group_lookup_vty(vty, ip_str);
5386 if (!peer)
5387 return CMD_WARNING_CONFIG_FAILED;
718e3744 5388
d62a17ae 5389 /* Check filter direction. */
5390 if (strncmp(direct_str, "i", 1) == 0)
5391 direct = FILTER_IN;
5392 else if (strncmp(direct_str, "o", 1) == 0)
5393 direct = FILTER_OUT;
718e3744 5394
d62a17ae 5395 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5396
d62a17ae 5397 return bgp_vty_return(vty, ret);
718e3744 5398}
5399
5400DEFUN (neighbor_filter_list,
5401 neighbor_filter_list_cmd,
9ccf14f7 5402 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5403 NEIGHBOR_STR
5404 NEIGHBOR_ADDR_STR2
5405 "Establish BGP filters\n"
5406 "AS path access-list name\n"
5407 "Filter incoming routes\n"
5408 "Filter outgoing routes\n")
5409{
d62a17ae 5410 int idx_peer = 1;
5411 int idx_word = 3;
5412 int idx_in_out = 4;
5413 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5414 bgp_node_safi(vty), argv[idx_word]->arg,
5415 argv[idx_in_out]->arg);
718e3744 5416}
5417
d62a17ae 5418ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5420 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5421 "Establish BGP filters\n"
5422 "AS path access-list name\n"
5423 "Filter incoming routes\n"
5424 "Filter outgoing routes\n")
596c17ba 5425
718e3744 5426DEFUN (no_neighbor_filter_list,
5427 no_neighbor_filter_list_cmd,
9ccf14f7 5428 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5429 NO_STR
5430 NEIGHBOR_STR
5431 NEIGHBOR_ADDR_STR2
5432 "Establish BGP filters\n"
5433 "AS path access-list name\n"
5434 "Filter incoming routes\n"
5435 "Filter outgoing routes\n")
5436{
d62a17ae 5437 int idx_peer = 2;
5438 int idx_in_out = 5;
5439 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5440 bgp_node_afi(vty), bgp_node_safi(vty),
5441 argv[idx_in_out]->arg);
718e3744 5442}
6b0655a2 5443
d62a17ae 5444ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5446 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5447 "Establish BGP filters\n"
5448 "AS path access-list name\n"
5449 "Filter incoming routes\n"
5450 "Filter outgoing routes\n")
596c17ba 5451
718e3744 5452/* Set route-map to the peer. */
d62a17ae 5453static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5454 afi_t afi, safi_t safi, const char *name_str,
5455 const char *direct_str)
718e3744 5456{
d62a17ae 5457 int ret;
5458 struct peer *peer;
5459 int direct = RMAP_IN;
718e3744 5460
d62a17ae 5461 peer = peer_and_group_lookup_vty(vty, ip_str);
5462 if (!peer)
5463 return CMD_WARNING_CONFIG_FAILED;
718e3744 5464
d62a17ae 5465 /* Check filter direction. */
5466 if (strncmp(direct_str, "in", 2) == 0)
5467 direct = RMAP_IN;
5468 else if (strncmp(direct_str, "o", 1) == 0)
5469 direct = RMAP_OUT;
718e3744 5470
d62a17ae 5471 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5472
d62a17ae 5473 return bgp_vty_return(vty, ret);
718e3744 5474}
5475
d62a17ae 5476static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5477 afi_t afi, safi_t safi,
5478 const char *direct_str)
718e3744 5479{
d62a17ae 5480 int ret;
5481 struct peer *peer;
5482 int direct = RMAP_IN;
718e3744 5483
d62a17ae 5484 peer = peer_and_group_lookup_vty(vty, ip_str);
5485 if (!peer)
5486 return CMD_WARNING_CONFIG_FAILED;
718e3744 5487
d62a17ae 5488 /* Check filter direction. */
5489 if (strncmp(direct_str, "in", 2) == 0)
5490 direct = RMAP_IN;
5491 else if (strncmp(direct_str, "o", 1) == 0)
5492 direct = RMAP_OUT;
718e3744 5493
d62a17ae 5494 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5495
d62a17ae 5496 return bgp_vty_return(vty, ret);
718e3744 5497}
5498
5499DEFUN (neighbor_route_map,
5500 neighbor_route_map_cmd,
9ccf14f7 5501 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5502 NEIGHBOR_STR
5503 NEIGHBOR_ADDR_STR2
5504 "Apply route map to neighbor\n"
5505 "Name of route map\n"
5506 "Apply map to incoming routes\n"
2a3d5731 5507 "Apply map to outbound routes\n")
718e3744 5508{
d62a17ae 5509 int idx_peer = 1;
5510 int idx_word = 3;
5511 int idx_in_out = 4;
5512 return peer_route_map_set_vty(
5513 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5514 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5515}
5516
d62a17ae 5517ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5518 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5520 "Apply route map to neighbor\n"
5521 "Name of route map\n"
5522 "Apply map to incoming routes\n"
5523 "Apply map to outbound routes\n")
596c17ba 5524
718e3744 5525DEFUN (no_neighbor_route_map,
5526 no_neighbor_route_map_cmd,
9ccf14f7 5527 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5528 NO_STR
5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Apply route map to neighbor\n"
5532 "Name of route map\n"
5533 "Apply map to incoming routes\n"
2a3d5731 5534 "Apply map to outbound routes\n")
718e3744 5535{
d62a17ae 5536 int idx_peer = 2;
5537 int idx_in_out = 5;
5538 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5539 bgp_node_afi(vty), bgp_node_safi(vty),
5540 argv[idx_in_out]->arg);
718e3744 5541}
6b0655a2 5542
d62a17ae 5543ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5545 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Apply route map to neighbor\n"
5547 "Name of route map\n"
5548 "Apply map to incoming routes\n"
5549 "Apply map to outbound routes\n")
596c17ba 5550
718e3744 5551/* Set unsuppress-map to the peer. */
d62a17ae 5552static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5553 afi_t afi, safi_t safi,
5554 const char *name_str)
718e3744 5555{
d62a17ae 5556 int ret;
5557 struct peer *peer;
718e3744 5558
d62a17ae 5559 peer = peer_and_group_lookup_vty(vty, ip_str);
5560 if (!peer)
5561 return CMD_WARNING_CONFIG_FAILED;
718e3744 5562
d62a17ae 5563 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5564
d62a17ae 5565 return bgp_vty_return(vty, ret);
718e3744 5566}
5567
5568/* Unset route-map from the peer. */
d62a17ae 5569static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5570 afi_t afi, safi_t safi)
718e3744 5571{
d62a17ae 5572 int ret;
5573 struct peer *peer;
718e3744 5574
d62a17ae 5575 peer = peer_and_group_lookup_vty(vty, ip_str);
5576 if (!peer)
5577 return CMD_WARNING_CONFIG_FAILED;
718e3744 5578
d62a17ae 5579 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5580
d62a17ae 5581 return bgp_vty_return(vty, ret);
718e3744 5582}
5583
5584DEFUN (neighbor_unsuppress_map,
5585 neighbor_unsuppress_map_cmd,
9ccf14f7 5586 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5587 NEIGHBOR_STR
5588 NEIGHBOR_ADDR_STR2
5589 "Route-map to selectively unsuppress suppressed routes\n"
5590 "Name of route map\n")
5591{
d62a17ae 5592 int idx_peer = 1;
5593 int idx_word = 3;
5594 return peer_unsuppress_map_set_vty(
5595 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5596 argv[idx_word]->arg);
718e3744 5597}
5598
d62a17ae 5599ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5600 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5601 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5602 "Route-map to selectively unsuppress suppressed routes\n"
5603 "Name of route map\n")
596c17ba 5604
718e3744 5605DEFUN (no_neighbor_unsuppress_map,
5606 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5607 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5608 NO_STR
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Route-map to selectively unsuppress suppressed routes\n"
5612 "Name of route map\n")
5613{
d62a17ae 5614 int idx_peer = 2;
5615 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5616 bgp_node_afi(vty),
5617 bgp_node_safi(vty));
718e3744 5618}
6b0655a2 5619
d62a17ae 5620ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5621 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5622 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5623 "Route-map to selectively unsuppress suppressed routes\n"
5624 "Name of route map\n")
596c17ba 5625
d62a17ae 5626static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5627 afi_t afi, safi_t safi,
5628 const char *num_str,
5629 const char *threshold_str, int warning,
5630 const char *restart_str)
718e3744 5631{
d62a17ae 5632 int ret;
5633 struct peer *peer;
5634 u_int32_t max;
5635 u_char threshold;
5636 u_int16_t restart;
718e3744 5637
d62a17ae 5638 peer = peer_and_group_lookup_vty(vty, ip_str);
5639 if (!peer)
5640 return CMD_WARNING_CONFIG_FAILED;
718e3744 5641
d62a17ae 5642 max = strtoul(num_str, NULL, 10);
5643 if (threshold_str)
5644 threshold = atoi(threshold_str);
5645 else
5646 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5647
d62a17ae 5648 if (restart_str)
5649 restart = atoi(restart_str);
5650 else
5651 restart = 0;
0a486e5f 5652
d62a17ae 5653 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5654 restart);
718e3744 5655
d62a17ae 5656 return bgp_vty_return(vty, ret);
718e3744 5657}
5658
d62a17ae 5659static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5660 afi_t afi, safi_t safi)
718e3744 5661{
d62a17ae 5662 int ret;
5663 struct peer *peer;
718e3744 5664
d62a17ae 5665 peer = peer_and_group_lookup_vty(vty, ip_str);
5666 if (!peer)
5667 return CMD_WARNING_CONFIG_FAILED;
718e3744 5668
d62a17ae 5669 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5670
d62a17ae 5671 return bgp_vty_return(vty, ret);
718e3744 5672}
5673
5674/* Maximum number of prefix configuration. prefix count is different
5675 for each peer configuration. So this configuration can be set for
5676 each peer configuration. */
5677DEFUN (neighbor_maximum_prefix,
5678 neighbor_maximum_prefix_cmd,
9ccf14f7 5679 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5680 NEIGHBOR_STR
5681 NEIGHBOR_ADDR_STR2
5682 "Maximum number of prefix accept from this peer\n"
5683 "maximum no. of prefix limit\n")
5684{
d62a17ae 5685 int idx_peer = 1;
5686 int idx_number = 3;
5687 return peer_maximum_prefix_set_vty(
5688 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5689 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5690}
5691
d62a17ae 5692ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5693 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5695 "Maximum number of prefix accept from this peer\n"
5696 "maximum no. of prefix limit\n")
596c17ba 5697
e0701b79 5698DEFUN (neighbor_maximum_prefix_threshold,
5699 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5700 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
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{
d62a17ae 5707 int idx_peer = 1;
5708 int idx_number = 3;
5709 int idx_number_2 = 4;
5710 return peer_maximum_prefix_set_vty(
5711 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5712 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5713}
e0701b79 5714
d62a17ae 5715ALIAS_HIDDEN(
5716 neighbor_maximum_prefix_threshold,
5717 neighbor_maximum_prefix_threshold_hidden_cmd,
5718 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5719 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5720 "Maximum number of prefix accept from this peer\n"
5721 "maximum no. of prefix limit\n"
5722 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5723
718e3744 5724DEFUN (neighbor_maximum_prefix_warning,
5725 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5726 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5727 NEIGHBOR_STR
5728 NEIGHBOR_ADDR_STR2
5729 "Maximum number of prefix accept from this peer\n"
5730 "maximum no. of prefix limit\n"
5731 "Only give warning message when limit is exceeded\n")
5732{
d62a17ae 5733 int idx_peer = 1;
5734 int idx_number = 3;
5735 return peer_maximum_prefix_set_vty(
5736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5737 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5738}
5739
d62a17ae 5740ALIAS_HIDDEN(
5741 neighbor_maximum_prefix_warning,
5742 neighbor_maximum_prefix_warning_hidden_cmd,
5743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5745 "Maximum number of prefix accept from this peer\n"
5746 "maximum no. of prefix limit\n"
5747 "Only give warning message when limit is exceeded\n")
596c17ba 5748
e0701b79 5749DEFUN (neighbor_maximum_prefix_threshold_warning,
5750 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5751 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5752 NEIGHBOR_STR
5753 NEIGHBOR_ADDR_STR2
5754 "Maximum number of prefix accept from this peer\n"
5755 "maximum no. of prefix limit\n"
5756 "Threshold value (%) at which to generate a warning msg\n"
5757 "Only give warning message when limit is exceeded\n")
5758{
d62a17ae 5759 int idx_peer = 1;
5760 int idx_number = 3;
5761 int idx_number_2 = 4;
5762 return peer_maximum_prefix_set_vty(
5763 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5764 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5765}
5766
d62a17ae 5767ALIAS_HIDDEN(
5768 neighbor_maximum_prefix_threshold_warning,
5769 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Maximum number of prefix accept from this peer\n"
5773 "maximum no. of prefix limit\n"
5774 "Threshold value (%) at which to generate a warning msg\n"
5775 "Only give warning message when limit is exceeded\n")
596c17ba 5776
0a486e5f 5777DEFUN (neighbor_maximum_prefix_restart,
5778 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5779 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Maximum number of prefix accept from this peer\n"
5783 "maximum no. of prefix limit\n"
5784 "Restart bgp connection after limit is exceeded\n"
efd7904e 5785 "Restart interval in minutes\n")
0a486e5f 5786{
d62a17ae 5787 int idx_peer = 1;
5788 int idx_number = 3;
5789 int idx_number_2 = 5;
5790 return peer_maximum_prefix_set_vty(
5791 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5792 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5793}
5794
d62a17ae 5795ALIAS_HIDDEN(
5796 neighbor_maximum_prefix_restart,
5797 neighbor_maximum_prefix_restart_hidden_cmd,
5798 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5800 "Maximum number of prefix accept from this peer\n"
5801 "maximum no. of prefix limit\n"
5802 "Restart bgp connection after limit is exceeded\n"
efd7904e 5803 "Restart interval in minutes\n")
596c17ba 5804
0a486e5f 5805DEFUN (neighbor_maximum_prefix_threshold_restart,
5806 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5807 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5808 NEIGHBOR_STR
5809 NEIGHBOR_ADDR_STR2
16cedbb0 5810 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5811 "maximum no. of prefix limit\n"
5812 "Threshold value (%) at which to generate a warning msg\n"
5813 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5814 "Restart interval in minutes\n")
0a486e5f 5815{
d62a17ae 5816 int idx_peer = 1;
5817 int idx_number = 3;
5818 int idx_number_2 = 4;
5819 int idx_number_3 = 6;
5820 return peer_maximum_prefix_set_vty(
5821 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5822 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5823 argv[idx_number_3]->arg);
5824}
5825
5826ALIAS_HIDDEN(
5827 neighbor_maximum_prefix_threshold_restart,
5828 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefixes to accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n"
5834 "Restart bgp connection after limit is exceeded\n"
5835 "Restart interval in minutes\n")
596c17ba 5836
718e3744 5837DEFUN (no_neighbor_maximum_prefix,
5838 no_neighbor_maximum_prefix_cmd,
d04c479d 5839 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5840 NO_STR
5841 NEIGHBOR_STR
5842 NEIGHBOR_ADDR_STR2
16cedbb0 5843 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5844 "maximum no. of prefix limit\n"
5845 "Threshold value (%) at which to generate a warning msg\n"
5846 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5847 "Restart interval in minutes\n"
31500417 5848 "Only give warning message when limit is exceeded\n")
718e3744 5849{
d62a17ae 5850 int idx_peer = 2;
5851 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5852 bgp_node_afi(vty),
5853 bgp_node_safi(vty));
718e3744 5854}
e52702f2 5855
d62a17ae 5856ALIAS_HIDDEN(
5857 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5858 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5859 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Maximum number of prefixes to accept from this peer\n"
5861 "maximum no. of prefix limit\n"
5862 "Threshold value (%) at which to generate a warning msg\n"
5863 "Restart bgp connection after limit is exceeded\n"
5864 "Restart interval in minutes\n"
5865 "Only give warning message when limit is exceeded\n")
596c17ba 5866
718e3744 5867
718e3744 5868/* "neighbor allowas-in" */
5869DEFUN (neighbor_allowas_in,
5870 neighbor_allowas_in_cmd,
fd8503f5 5871 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5872 NEIGHBOR_STR
5873 NEIGHBOR_ADDR_STR2
31500417 5874 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5875 "Number of occurances of AS number\n"
5876 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5877{
d62a17ae 5878 int idx_peer = 1;
5879 int idx_number_origin = 3;
5880 int ret;
5881 int origin = 0;
5882 struct peer *peer;
5883 int allow_num = 0;
5884
5885 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5886 if (!peer)
5887 return CMD_WARNING_CONFIG_FAILED;
5888
5889 if (argc <= idx_number_origin)
5890 allow_num = 3;
5891 else {
5892 if (argv[idx_number_origin]->type == WORD_TKN)
5893 origin = 1;
5894 else
5895 allow_num = atoi(argv[idx_number_origin]->arg);
5896 }
5897
5898 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5899 allow_num, origin);
5900
5901 return bgp_vty_return(vty, ret);
5902}
5903
5904ALIAS_HIDDEN(
5905 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5908 "Accept as-path with my AS present in it\n"
5909 "Number of occurances of AS number\n"
5910 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5911
718e3744 5912DEFUN (no_neighbor_allowas_in,
5913 no_neighbor_allowas_in_cmd,
fd8503f5 5914 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5915 NO_STR
5916 NEIGHBOR_STR
5917 NEIGHBOR_ADDR_STR2
8334fd5a 5918 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5919 "Number of occurances of AS number\n"
5920 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5921{
d62a17ae 5922 int idx_peer = 2;
5923 int ret;
5924 struct peer *peer;
718e3744 5925
d62a17ae 5926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5927 if (!peer)
5928 return CMD_WARNING_CONFIG_FAILED;
718e3744 5929
d62a17ae 5930 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5931 bgp_node_safi(vty));
718e3744 5932
d62a17ae 5933 return bgp_vty_return(vty, ret);
718e3744 5934}
6b0655a2 5935
d62a17ae 5936ALIAS_HIDDEN(
5937 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5938 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5940 "allow local ASN appears in aspath attribute\n"
5941 "Number of occurances of AS number\n"
5942 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5943
fa411a21
NH
5944DEFUN (neighbor_ttl_security,
5945 neighbor_ttl_security_cmd,
9ccf14f7 5946 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5947 NEIGHBOR_STR
5948 NEIGHBOR_ADDR_STR2
16cedbb0 5949 "BGP ttl-security parameters\n"
d7fa34c1
QY
5950 "Specify the maximum number of hops to the BGP peer\n"
5951 "Number of hops to BGP peer\n")
fa411a21 5952{
d62a17ae 5953 int idx_peer = 1;
5954 int idx_number = 4;
5955 struct peer *peer;
5956 int gtsm_hops;
5957
5958 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5959 if (!peer)
5960 return CMD_WARNING_CONFIG_FAILED;
5961
5962 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5963
5964 /*
5965 * If 'neighbor swpX', then this is for directly connected peers,
5966 * we should not accept a ttl-security hops value greater than 1.
5967 */
5968 if (peer->conf_if && (gtsm_hops > 1)) {
5969 vty_out(vty,
5970 "%s is directly connected peer, hops cannot exceed 1\n",
5971 argv[idx_peer]->arg);
5972 return CMD_WARNING_CONFIG_FAILED;
5973 }
8cdabf90 5974
d62a17ae 5975 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
5976}
5977
5978DEFUN (no_neighbor_ttl_security,
5979 no_neighbor_ttl_security_cmd,
9ccf14f7 5980 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5981 NO_STR
5982 NEIGHBOR_STR
5983 NEIGHBOR_ADDR_STR2
16cedbb0 5984 "BGP ttl-security parameters\n"
3a2d747c
QY
5985 "Specify the maximum number of hops to the BGP peer\n"
5986 "Number of hops to BGP peer\n")
fa411a21 5987{
d62a17ae 5988 int idx_peer = 2;
5989 struct peer *peer;
fa411a21 5990
d62a17ae 5991 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5992 if (!peer)
5993 return CMD_WARNING_CONFIG_FAILED;
fa411a21 5994
d62a17ae 5995 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 5996}
6b0655a2 5997
adbac85e
DW
5998DEFUN (neighbor_addpath_tx_all_paths,
5999 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6000 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6001 NEIGHBOR_STR
6002 NEIGHBOR_ADDR_STR2
6003 "Use addpath to advertise all paths to a neighbor\n")
6004{
d62a17ae 6005 int idx_peer = 1;
6006 struct peer *peer;
adbac85e 6007
d62a17ae 6008 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6009 if (!peer)
6010 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6011
d62a17ae 6012 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6013 bgp_node_safi(vty),
6014 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6015}
6016
d62a17ae 6017ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6018 neighbor_addpath_tx_all_paths_hidden_cmd,
6019 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6020 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6021 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6022
adbac85e
DW
6023DEFUN (no_neighbor_addpath_tx_all_paths,
6024 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6026 NO_STR
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
6029 "Use addpath to advertise all paths to a neighbor\n")
6030{
d62a17ae 6031 int idx_peer = 2;
6032 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6033 bgp_node_afi(vty), bgp_node_safi(vty),
6034 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6035}
6036
d62a17ae 6037ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6038 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6039 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6041 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6042
06370dac
DW
6043DEFUN (neighbor_addpath_tx_bestpath_per_as,
6044 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6045 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6046 NEIGHBOR_STR
6047 NEIGHBOR_ADDR_STR2
6048 "Use addpath to advertise the bestpath per each neighboring AS\n")
6049{
d62a17ae 6050 int idx_peer = 1;
6051 struct peer *peer;
06370dac 6052
d62a17ae 6053 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6054 if (!peer)
6055 return CMD_WARNING_CONFIG_FAILED;
06370dac 6056
d62a17ae 6057 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6058 bgp_node_safi(vty),
6059 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6060}
6061
d62a17ae 6062ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6063 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6064 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6065 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6066 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6067
06370dac
DW
6068DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6069 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6070 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6071 NO_STR
6072 NEIGHBOR_STR
6073 NEIGHBOR_ADDR_STR2
6074 "Use addpath to advertise the bestpath per each neighboring AS\n")
6075{
d62a17ae 6076 int idx_peer = 2;
6077 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6078 bgp_node_afi(vty), bgp_node_safi(vty),
6079 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6080}
6081
d62a17ae 6082ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6083 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6084 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6085 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6086 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6087
505e5056 6088DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6089 address_family_ipv4_safi_cmd,
5b1f0f29 6090 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6091 "Enter Address Family command mode\n"
8c3deaae 6092 "Address Family\n"
b6ab5a3a 6093 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6094{
f51bae9c 6095
d62a17ae 6096 if (argc == 3) {
2131d5cf 6097 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6098 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
2131d5cf
LB
6099 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6100 safi != SAFI_UNICAST && safi != SAFI_MULTICAST) {
6101 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6102 return CMD_WARNING_CONFIG_FAILED;
6103 }
d62a17ae 6104 vty->node = bgp_node_type(AFI_IP, safi);
6105 } else
6106 vty->node = BGP_IPV4_NODE;
718e3744 6107
d62a17ae 6108 return CMD_SUCCESS;
718e3744 6109}
6110
505e5056 6111DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6112 address_family_ipv6_safi_cmd,
5b1f0f29 6113 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6114 "Enter Address Family command mode\n"
8c3deaae 6115 "Address Family\n"
b6ab5a3a 6116 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6117{
d62a17ae 6118 if (argc == 3) {
2131d5cf 6119 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6120 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
2131d5cf
LB
6121 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6122 safi != SAFI_UNICAST && safi != SAFI_MULTICAST) {
6123 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6124 return CMD_WARNING_CONFIG_FAILED;
6125 }
d62a17ae 6126 vty->node = bgp_node_type(AFI_IP6, safi);
6127 } else
6128 vty->node = BGP_IPV6_NODE;
25ffbdc1 6129
d62a17ae 6130 return CMD_SUCCESS;
25ffbdc1 6131}
718e3744 6132
d6902373 6133#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6134DEFUN_NOSH (address_family_vpnv4,
718e3744 6135 address_family_vpnv4_cmd,
8334fd5a 6136 "address-family vpnv4 [unicast]",
718e3744 6137 "Enter Address Family command mode\n"
8c3deaae 6138 "Address Family\n"
3a2d747c 6139 "Address Family modifier\n")
718e3744 6140{
d62a17ae 6141 vty->node = BGP_VPNV4_NODE;
6142 return CMD_SUCCESS;
718e3744 6143}
6144
505e5056 6145DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6146 address_family_vpnv6_cmd,
8334fd5a 6147 "address-family vpnv6 [unicast]",
8ecd3266 6148 "Enter Address Family command mode\n"
8c3deaae 6149 "Address Family\n"
3a2d747c 6150 "Address Family modifier\n")
8ecd3266 6151{
d62a17ae 6152 vty->node = BGP_VPNV6_NODE;
6153 return CMD_SUCCESS;
8ecd3266 6154}
c016b6c7 6155#endif
d6902373 6156
505e5056 6157DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6158 address_family_evpn_cmd,
7111c1a0 6159 "address-family l2vpn evpn",
4e0b7b6d 6160 "Enter Address Family command mode\n"
7111c1a0
QY
6161 "Address Family\n"
6162 "Address Family modifier\n")
4e0b7b6d 6163{
2131d5cf
LB
6164 VTY_DECLVAR_CONTEXT(bgp, bgp);
6165 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) {
6166 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6167 return CMD_WARNING_CONFIG_FAILED;
6168 }
d62a17ae 6169 vty->node = BGP_EVPN_NODE;
6170 return CMD_SUCCESS;
4e0b7b6d
PG
6171}
6172
505e5056 6173DEFUN_NOSH (exit_address_family,
718e3744 6174 exit_address_family_cmd,
6175 "exit-address-family",
6176 "Exit from Address Family configuration mode\n")
6177{
d62a17ae 6178 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6179 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6180 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6181 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6182 || vty->node == BGP_EVPN_NODE)
6183 vty->node = BGP_NODE;
6184 return CMD_SUCCESS;
718e3744 6185}
6b0655a2 6186
8ad7271d 6187/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6188static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6189 const char *ip_str, afi_t afi, safi_t safi,
6190 struct prefix_rd *prd)
6191{
6192 int ret;
6193 struct prefix match;
6194 struct bgp_node *rn;
6195 struct bgp_node *rm;
6196 struct bgp *bgp;
6197 struct bgp_table *table;
6198 struct bgp_table *rib;
6199
6200 /* BGP structure lookup. */
6201 if (view_name) {
6202 bgp = bgp_lookup_by_name(view_name);
6203 if (bgp == NULL) {
6204 vty_out(vty, "%% Can't find BGP instance %s\n",
6205 view_name);
6206 return CMD_WARNING;
6207 }
6208 } else {
6209 bgp = bgp_get_default();
6210 if (bgp == NULL) {
6211 vty_out(vty, "%% No BGP process is configured\n");
6212 return CMD_WARNING;
6213 }
6214 }
6215
6216 /* Check IP address argument. */
6217 ret = str2prefix(ip_str, &match);
6218 if (!ret) {
6219 vty_out(vty, "%% address is malformed\n");
6220 return CMD_WARNING;
6221 }
6222
6223 match.family = afi2family(afi);
6224 rib = bgp->rib[afi][safi];
6225
6226 if (safi == SAFI_MPLS_VPN) {
6227 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6228 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6229 continue;
6230
6231 if ((table = rn->info) != NULL) {
6232 if ((rm = bgp_node_match(table, &match))
6233 != NULL) {
6234 if (rm->p.prefixlen
6235 == match.prefixlen) {
6236 SET_FLAG(rn->flags,
6237 BGP_NODE_USER_CLEAR);
6238 bgp_process(bgp, rm, afi, safi);
6239 }
6240 bgp_unlock_node(rm);
6241 }
6242 }
6243 }
6244 } else {
6245 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6246 if (rn->p.prefixlen == match.prefixlen) {
6247 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6248 bgp_process(bgp, rn, afi, safi);
6249 }
6250 bgp_unlock_node(rn);
6251 }
6252 }
6253
6254 return CMD_SUCCESS;
8ad7271d
DS
6255}
6256
b09b5ae0 6257/* one clear bgp command to rule them all */
718e3744 6258DEFUN (clear_ip_bgp_all,
6259 clear_ip_bgp_all_cmd,
c1a44e43 6260 "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 6261 CLEAR_STR
6262 IP_STR
6263 BGP_STR
838758ac 6264 BGP_INSTANCE_HELP_STR
510afcd6
DS
6265 BGP_AFI_HELP_STR
6266 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6267 "Clear all peers\n"
6268 "BGP neighbor address to clear\n"
a80beece 6269 "BGP IPv6 neighbor to clear\n"
838758ac 6270 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6271 "Clear peers with the AS number\n"
6272 "Clear all external peers\n"
718e3744 6273 "Clear all members of peer-group\n"
b09b5ae0 6274 "BGP peer-group name\n"
b09b5ae0
DW
6275 BGP_SOFT_STR
6276 BGP_SOFT_IN_STR
b09b5ae0
DW
6277 BGP_SOFT_OUT_STR
6278 BGP_SOFT_IN_STR
6279 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6280 BGP_SOFT_OUT_STR)
718e3744 6281{
d62a17ae 6282 char *vrf = NULL;
6283
6284 afi_t afi = AFI_IP6;
6285 safi_t safi = SAFI_UNICAST;
6286 enum clear_sort clr_sort = clear_peer;
6287 enum bgp_clear_type clr_type;
6288 char *clr_arg = NULL;
6289
6290 int idx = 0;
6291
6292 /* clear [ip] bgp */
6293 if (argv_find(argv, argc, "ip", &idx))
6294 afi = AFI_IP;
6295
6296 /* [<view|vrf> VIEWVRFNAME] */
6297 if (argv_find(argv, argc, "view", &idx)
6298 || argv_find(argv, argc, "vrf", &idx)) {
6299 vrf = argv[idx + 1]->arg;
6300 idx += 2;
6301 }
6302
6303 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6304 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6305 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6306
6307 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6308 if (argv_find(argv, argc, "*", &idx)) {
6309 clr_sort = clear_all;
6310 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6311 clr_sort = clear_peer;
6312 clr_arg = argv[idx]->arg;
6313 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6314 clr_sort = clear_peer;
6315 clr_arg = argv[idx]->arg;
6316 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6317 clr_sort = clear_group;
6318 idx++;
6319 clr_arg = argv[idx]->arg;
6320 } else if (argv_find(argv, argc, "WORD", &idx)) {
6321 clr_sort = clear_peer;
6322 clr_arg = argv[idx]->arg;
6323 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6324 clr_sort = clear_as;
6325 clr_arg = argv[idx]->arg;
6326 } else if (argv_find(argv, argc, "external", &idx)) {
6327 clr_sort = clear_external;
6328 }
6329
6330 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6331 if (argv_find(argv, argc, "soft", &idx)) {
6332 if (argv_find(argv, argc, "in", &idx)
6333 || argv_find(argv, argc, "out", &idx))
6334 clr_type = strmatch(argv[idx]->text, "in")
6335 ? BGP_CLEAR_SOFT_IN
6336 : BGP_CLEAR_SOFT_OUT;
6337 else
6338 clr_type = BGP_CLEAR_SOFT_BOTH;
6339 } else if (argv_find(argv, argc, "in", &idx)) {
6340 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6341 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6342 : BGP_CLEAR_SOFT_IN;
6343 } else if (argv_find(argv, argc, "out", &idx)) {
6344 clr_type = BGP_CLEAR_SOFT_OUT;
6345 } else
6346 clr_type = BGP_CLEAR_SOFT_NONE;
6347
6348 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6349}
01080f7c 6350
8ad7271d
DS
6351DEFUN (clear_ip_bgp_prefix,
6352 clear_ip_bgp_prefix_cmd,
18c57037 6353 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6354 CLEAR_STR
6355 IP_STR
6356 BGP_STR
838758ac 6357 BGP_INSTANCE_HELP_STR
8ad7271d 6358 "Clear bestpath and re-advertise\n"
0c7b1b01 6359 "IPv4 prefix\n")
8ad7271d 6360{
d62a17ae 6361 char *vrf = NULL;
6362 char *prefix = NULL;
8ad7271d 6363
d62a17ae 6364 int idx = 0;
01080f7c 6365
d62a17ae 6366 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 6367 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 6368 vrf = argv[idx]->arg;
0c7b1b01 6369
d62a17ae 6370 prefix = argv[argc - 1]->arg;
8ad7271d 6371
d62a17ae 6372 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6373}
8ad7271d 6374
b09b5ae0
DW
6375DEFUN (clear_bgp_ipv6_safi_prefix,
6376 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6377 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6378 CLEAR_STR
3a2d747c 6379 IP_STR
718e3744 6380 BGP_STR
8c3deaae 6381 "Address Family\n"
46f296b4 6382 BGP_SAFI_HELP_STR
b09b5ae0 6383 "Clear bestpath and re-advertise\n"
0c7b1b01 6384 "IPv6 prefix\n")
718e3744 6385{
d62a17ae 6386 int idx_safi = 3;
6387 int idx_ipv6_prefixlen = 5;
6388 return bgp_clear_prefix(
6389 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6390 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
838758ac 6391}
01080f7c 6392
b09b5ae0
DW
6393DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6394 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6395 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6396 CLEAR_STR
3a2d747c 6397 IP_STR
718e3744 6398 BGP_STR
838758ac 6399 BGP_INSTANCE_HELP_STR
8c3deaae 6400 "Address Family\n"
46f296b4 6401 BGP_SAFI_HELP_STR
b09b5ae0 6402 "Clear bestpath and re-advertise\n"
0c7b1b01 6403 "IPv6 prefix\n")
718e3744 6404{
d62a17ae 6405 int idx_word = 3;
6406 int idx_safi = 5;
6407 int idx_ipv6_prefixlen = 7;
6408 return bgp_clear_prefix(
6409 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6410 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
718e3744 6411}
6412
b09b5ae0
DW
6413DEFUN (show_bgp_views,
6414 show_bgp_views_cmd,
d6e3c605 6415 "show [ip] bgp views",
b09b5ae0 6416 SHOW_STR
d6e3c605 6417 IP_STR
01080f7c 6418 BGP_STR
b09b5ae0 6419 "Show the defined BGP views\n")
01080f7c 6420{
d62a17ae 6421 struct list *inst = bm->bgp;
6422 struct listnode *node;
6423 struct bgp *bgp;
01080f7c 6424
d62a17ae 6425 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6426 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6427 return CMD_WARNING;
6428 }
e52702f2 6429
d62a17ae 6430 vty_out(vty, "Defined BGP views:\n");
6431 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6432 /* Skip VRFs. */
6433 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6434 continue;
6435 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6436 bgp->as);
6437 }
e52702f2 6438
d62a17ae 6439 return CMD_SUCCESS;
e0081f70
ML
6440}
6441
8386ac43 6442DEFUN (show_bgp_vrfs,
6443 show_bgp_vrfs_cmd,
d6e3c605 6444 "show [ip] bgp vrfs [json]",
8386ac43 6445 SHOW_STR
d6e3c605 6446 IP_STR
8386ac43 6447 BGP_STR
6448 "Show BGP VRFs\n"
9973d184 6449 JSON_STR)
8386ac43 6450{
d62a17ae 6451 struct list *inst = bm->bgp;
6452 struct listnode *node;
6453 struct bgp *bgp;
6454 u_char uj = use_json(argc, argv);
6455 json_object *json = NULL;
6456 json_object *json_vrfs = NULL;
6457 int count = 0;
6458 static char header[] =
6459 "Type Id RouterId #PeersCfg #PeersEstb Name";
6460
6461 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6462 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6463 return CMD_WARNING;
6464 }
6465
6466 if (uj) {
6467 json = json_object_new_object();
6468 json_vrfs = json_object_new_object();
6469 }
6470
6471 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6472 const char *name, *type;
6473 struct peer *peer;
6474 struct listnode *node, *nnode;
6475 int peers_cfg, peers_estb;
6476 json_object *json_vrf = NULL;
6477 int vrf_id_ui;
6478
6479 /* Skip Views. */
6480 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6481 continue;
6482
6483 count++;
6484 if (!uj && count == 1)
6485 vty_out(vty, "%s\n", header);
6486
6487 peers_cfg = peers_estb = 0;
6488 if (uj)
6489 json_vrf = json_object_new_object();
6490
6491
6492 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6493 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6494 continue;
6495 peers_cfg++;
6496 if (peer->status == Established)
6497 peers_estb++;
6498 }
6499
6500 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6501 name = "Default";
6502 type = "DFLT";
6503 } else {
6504 name = bgp->name;
6505 type = "VRF";
6506 }
6507
6508 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6509 if (uj) {
6510 json_object_string_add(json_vrf, "type", type);
6511 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6512 json_object_string_add(json_vrf, "routerId",
6513 inet_ntoa(bgp->router_id));
6514 json_object_int_add(json_vrf, "numConfiguredPeers",
6515 peers_cfg);
6516 json_object_int_add(json_vrf, "numEstablishedPeers",
6517 peers_estb);
6518
6519 json_object_object_add(json_vrfs, name, json_vrf);
6520 } else
6521 vty_out(vty, "%4s %-5d %-16s %9u %10u %s\n", type,
6522 vrf_id_ui, inet_ntoa(bgp->router_id), peers_cfg,
6523 peers_estb, name);
6524 }
6525
6526 if (uj) {
6527 json_object_object_add(json, "vrfs", json_vrfs);
6528
6529 json_object_int_add(json, "totalVrfs", count);
6530
9d303b37
DL
6531 vty_out(vty, "%s\n", json_object_to_json_string_ext(
6532 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 6533 json_object_free(json);
6534 } else {
6535 if (count)
6536 vty_out(vty,
6537 "\nTotal number of VRFs (including default): %d\n",
6538 count);
6539 }
6540
6541 return CMD_SUCCESS;
8386ac43 6542}
6543
acf71666
MK
6544static void show_address_entry(struct hash_backet *backet, void *args)
6545{
60466a63
QY
6546 struct vty *vty = (struct vty *)args;
6547 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 6548
60466a63 6549 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
6550 addr->refcnt);
6551}
6552
6553static void show_tip_entry(struct hash_backet *backet, void *args)
6554{
0291c246 6555 struct vty *vty = (struct vty *)args;
60466a63 6556 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 6557
60466a63 6558 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
6559 tip->refcnt);
6560}
6561
6562static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6563{
6564 vty_out(vty, "self nexthop database:\n");
6565 hash_iterate(bgp->address_hash,
6566 (void (*)(struct hash_backet *, void *))show_address_entry,
6567 vty);
6568
6569 vty_out(vty, "Tunnel-ip database:\n");
6570 hash_iterate(bgp->tip_hash,
6571 (void (*)(struct hash_backet *, void *))show_tip_entry,
6572 vty);
6573}
6574
60466a63
QY
6575DEFUN(show_bgp_martian_nexthop_db,
6576 show_bgp_martian_nexthop_db_cmd,
6577 "show bgp martian next-hop",
6578 SHOW_STR
6579 BGP_STR
6580 "martian next-hops\n"
6581 "martian next-hop database\n")
acf71666 6582{
0291c246 6583 struct bgp *bgp = NULL;
acf71666
MK
6584
6585 bgp = bgp_get_default();
6586 if (!bgp) {
6587 vty_out(vty, "%% No BGP process is configured\n");
6588 return CMD_WARNING;
6589 }
6590 bgp_show_martian_nexthops(vty, bgp);
6591
6592 return CMD_SUCCESS;
6593}
6594
f412b39a 6595DEFUN (show_bgp_memory,
4bf6a362 6596 show_bgp_memory_cmd,
7fa12b13 6597 "show [ip] bgp memory",
4bf6a362 6598 SHOW_STR
3a2d747c 6599 IP_STR
4bf6a362
PJ
6600 BGP_STR
6601 "Global BGP memory statistics\n")
6602{
d62a17ae 6603 char memstrbuf[MTYPE_MEMSTR_LEN];
6604 unsigned long count;
6605
6606 /* RIB related usage stats */
6607 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6608 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6609 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6610 count * sizeof(struct bgp_node)));
6611
6612 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6613 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6614 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6615 count * sizeof(struct bgp_info)));
6616 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6617 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6618 count,
6619 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6620 count * sizeof(struct bgp_info_extra)));
6621
6622 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6623 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6624 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6625 count * sizeof(struct bgp_static)));
6626
6627 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6628 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6629 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6630 count * sizeof(struct bpacket)));
6631
6632 /* Adj-In/Out */
6633 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6634 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6635 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6636 count * sizeof(struct bgp_adj_in)));
6637 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6638 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6639 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6640 count * sizeof(struct bgp_adj_out)));
6641
6642 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6643 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6644 count,
6645 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6646 count * sizeof(struct bgp_nexthop_cache)));
6647
6648 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6649 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6650 count,
6651 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6652 count * sizeof(struct bgp_damp_info)));
6653
6654 /* Attributes */
6655 count = attr_count();
6656 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6658 count * sizeof(struct attr)));
6659
6660 if ((count = attr_unknown_count()))
6661 vty_out(vty, "%ld unknown attributes\n", count);
6662
6663 /* AS_PATH attributes */
6664 count = aspath_count();
6665 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6666 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6667 count * sizeof(struct aspath)));
6668
6669 count = mtype_stats_alloc(MTYPE_AS_SEG);
6670 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6671 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6672 count * sizeof(struct assegment)));
6673
6674 /* Other attributes */
6675 if ((count = community_count()))
6676 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6677 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6678 count * sizeof(struct community)));
d62a17ae 6679 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6680 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6681 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6682 count * sizeof(struct ecommunity)));
d62a17ae 6683 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6684 vty_out(vty,
6685 "%ld BGP large-community entries, using %s of memory\n",
9d303b37
DL
6686 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6687 count * sizeof(struct lcommunity)));
d62a17ae 6688
6689 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6690 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6691 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6692 count * sizeof(struct cluster_list)));
6693
6694 /* Peer related usage */
6695 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6696 vty_out(vty, "%ld peers, using %s of memory\n", count,
6697 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6698 count * sizeof(struct peer)));
6699
6700 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6701 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6703 count * sizeof(struct peer_group)));
6704
6705 /* Other */
6706 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6707 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6708 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6709 count * sizeof(struct hash)));
6710 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6711 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6712 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6713 count * sizeof(struct hash_backet)));
6714 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6715 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9d303b37
DL
6716 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6717 count * sizeof(regex_t)));
d62a17ae 6718 return CMD_SUCCESS;
4bf6a362 6719}
fee0f4c6 6720
57a9c8a8
DS
6721static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
6722{
6723 json_object *bestpath = json_object_new_object();
6724
6725 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
6726 json_object_string_add(bestpath, "asPath", "ignore");
6727
6728 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
6729 json_object_string_add(bestpath, "asPath", "confed");
6730
6731 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
6732 if (bgp_flag_check(bgp,
6733 BGP_FLAG_MULTIPATH_RELAX_AS_SET))
6734 json_object_string_add(bestpath,
6735 "multiPathRelax",
6736 "as-set");
6737 else
6738 json_object_string_add(bestpath,
6739 "multiPathRelax",
6740 "true");
6741 } else
6742 json_object_string_add(bestpath,
6743 "multiPathRelax",
6744 "false");
6745
6746 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
6747 json_object_string_add(bestpath, "compareRouterId", "true");
6748 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
6749 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
6750 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
6751 json_object_string_add(bestpath, "med",
6752 "confed");
6753 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
6754 json_object_string_add(bestpath, "med",
6755 "missing-as-worst");
6756 else
6757 json_object_string_add(bestpath, "med", "true");
6758 }
6759
6760 json_object_object_add(json, "bestPath", bestpath);
6761}
6762
718e3744 6763/* Show BGP peer's summary information. */
d62a17ae 6764static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6765 u_char use_json, json_object *json)
6766{
6767 struct peer *peer;
6768 struct listnode *node, *nnode;
6769 unsigned int count = 0, dn_count = 0;
6770 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6771 char neighbor_buf[VTY_BUFSIZ];
6772 int neighbor_col_default_width = 16;
6773 int len;
6774 int max_neighbor_width = 0;
6775 int pfx_rcd_safi;
6776 json_object *json_peer = NULL;
6777 json_object *json_peers = NULL;
6778
6779 /* labeled-unicast routes are installed in the unicast table so in order
6780 * to
6781 * display the correct PfxRcd value we must look at SAFI_UNICAST
6782 */
6783 if (safi == SAFI_LABELED_UNICAST)
6784 pfx_rcd_safi = SAFI_UNICAST;
6785 else
6786 pfx_rcd_safi = safi;
6787
6788 if (use_json) {
6789 if (json == NULL)
6790 json = json_object_new_object();
6791
6792 json_peers = json_object_new_object();
6793 } else {
6794 /* Loop over all neighbors that will be displayed to determine
6795 * how many
6796 * characters are needed for the Neighbor column
6797 */
6798 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6799 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6800 continue;
6801
6802 if (peer->afc[afi][safi]) {
6803 memset(dn_flag, '\0', sizeof(dn_flag));
6804 if (peer_dynamic_neighbor(peer))
6805 dn_flag[0] = '*';
6806
6807 if (peer->hostname
6808 && bgp_flag_check(bgp,
6809 BGP_FLAG_SHOW_HOSTNAME))
6810 sprintf(neighbor_buf, "%s%s(%s) ",
6811 dn_flag, peer->hostname,
6812 peer->host);
6813 else
6814 sprintf(neighbor_buf, "%s%s ", dn_flag,
6815 peer->host);
6816
6817 len = strlen(neighbor_buf);
6818
6819 if (len > max_neighbor_width)
6820 max_neighbor_width = len;
6821 }
6822 }
f933309e 6823
d62a17ae 6824 /* Originally we displayed the Neighbor column as 16
6825 * characters wide so make that the default
6826 */
6827 if (max_neighbor_width < neighbor_col_default_width)
6828 max_neighbor_width = neighbor_col_default_width;
6829 }
f933309e 6830
d62a17ae 6831 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6832 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6833 continue;
6834
ea47320b
DL
6835 if (!peer->afc[afi][safi])
6836 continue;
d62a17ae 6837
ea47320b
DL
6838 if (!count) {
6839 unsigned long ents;
6840 char memstrbuf[MTYPE_MEMSTR_LEN];
6841 int vrf_id_ui;
d62a17ae 6842
60466a63
QY
6843 vrf_id_ui =
6844 (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
ea47320b
DL
6845
6846 /* Usage summary and header */
6847 if (use_json) {
6848 json_object_string_add(
6849 json, "routerId",
6850 inet_ntoa(bgp->router_id));
60466a63
QY
6851 json_object_int_add(json, "as", bgp->as);
6852 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
6853 json_object_string_add(
6854 json, "vrfName",
6855 (bgp->inst_type
6856 == BGP_INSTANCE_TYPE_DEFAULT)
6857 ? "Default"
6858 : bgp->name);
6859 } else {
6860 vty_out(vty,
6861 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63
QY
6862 inet_ntoa(bgp->router_id), bgp->as,
6863 vrf_id_ui);
ea47320b
DL
6864 vty_out(vty, "\n");
6865 }
d62a17ae 6866
ea47320b 6867 if (bgp_update_delay_configured(bgp)) {
d62a17ae 6868 if (use_json) {
ea47320b 6869 json_object_int_add(
60466a63 6870 json, "updateDelayLimit",
ea47320b 6871 bgp->v_update_delay);
d62a17ae 6872
ea47320b
DL
6873 if (bgp->v_update_delay
6874 != bgp->v_establish_wait)
d62a17ae 6875 json_object_int_add(
6876 json,
ea47320b
DL
6877 "updateDelayEstablishWait",
6878 bgp->v_establish_wait);
d62a17ae 6879
60466a63 6880 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6881 json_object_string_add(
6882 json,
6883 "updateDelayFirstNeighbor",
6884 bgp->update_delay_begin_time);
6885 json_object_boolean_true_add(
6886 json,
6887 "updateDelayInProgress");
6888 } else {
6889 if (bgp->update_delay_over) {
d62a17ae 6890 json_object_string_add(
6891 json,
6892 "updateDelayFirstNeighbor",
6893 bgp->update_delay_begin_time);
ea47320b 6894 json_object_string_add(
d62a17ae 6895 json,
ea47320b
DL
6896 "updateDelayBestpathResumed",
6897 bgp->update_delay_end_time);
6898 json_object_string_add(
d62a17ae 6899 json,
ea47320b
DL
6900 "updateDelayZebraUpdateResume",
6901 bgp->update_delay_zebra_resume_time);
6902 json_object_string_add(
6903 json,
6904 "updateDelayPeerUpdateResume",
6905 bgp->update_delay_peers_resume_time);
d62a17ae 6906 }
ea47320b
DL
6907 }
6908 } else {
6909 vty_out(vty,
6910 "Read-only mode update-delay limit: %d seconds\n",
6911 bgp->v_update_delay);
6912 if (bgp->v_update_delay
6913 != bgp->v_establish_wait)
d62a17ae 6914 vty_out(vty,
ea47320b
DL
6915 " Establish wait: %d seconds\n",
6916 bgp->v_establish_wait);
d62a17ae 6917
60466a63 6918 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6919 vty_out(vty,
6920 " First neighbor established: %s\n",
6921 bgp->update_delay_begin_time);
6922 vty_out(vty,
6923 " Delay in progress\n");
6924 } else {
6925 if (bgp->update_delay_over) {
d62a17ae 6926 vty_out(vty,
6927 " First neighbor established: %s\n",
6928 bgp->update_delay_begin_time);
6929 vty_out(vty,
ea47320b
DL
6930 " Best-paths resumed: %s\n",
6931 bgp->update_delay_end_time);
6932 vty_out(vty,
6933 " zebra update resumed: %s\n",
6934 bgp->update_delay_zebra_resume_time);
6935 vty_out(vty,
6936 " peers update resumed: %s\n",
6937 bgp->update_delay_peers_resume_time);
d62a17ae 6938 }
6939 }
6940 }
ea47320b 6941 }
d62a17ae 6942
ea47320b
DL
6943 if (use_json) {
6944 if (bgp_maxmed_onstartup_configured(bgp)
6945 && bgp->maxmed_active)
6946 json_object_boolean_true_add(
60466a63 6947 json, "maxMedOnStartup");
ea47320b
DL
6948 if (bgp->v_maxmed_admin)
6949 json_object_boolean_true_add(
60466a63 6950 json, "maxMedAdministrative");
d62a17ae 6951
ea47320b
DL
6952 json_object_int_add(
6953 json, "tableVersion",
60466a63 6954 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 6955
60466a63
QY
6956 ents = bgp_table_count(bgp->rib[afi][safi]);
6957 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
6958 json_object_int_add(
6959 json, "ribMemory",
6960 ents * sizeof(struct bgp_node));
d62a17ae 6961
ea47320b 6962 ents = listcount(bgp->peer);
60466a63
QY
6963 json_object_int_add(json, "peerCount", ents);
6964 json_object_int_add(json, "peerMemory",
6965 ents * sizeof(struct peer));
d62a17ae 6966
ea47320b
DL
6967 if ((ents = listcount(bgp->group))) {
6968 json_object_int_add(
60466a63 6969 json, "peerGroupCount", ents);
ea47320b
DL
6970 json_object_int_add(
6971 json, "peerGroupMemory",
6972 ents * sizeof(struct
6973 peer_group));
6974 }
d62a17ae 6975
ea47320b
DL
6976 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6977 BGP_CONFIG_DAMPENING))
6978 json_object_boolean_true_add(
60466a63 6979 json, "dampeningEnabled");
ea47320b
DL
6980 } else {
6981 if (bgp_maxmed_onstartup_configured(bgp)
6982 && bgp->maxmed_active)
d62a17ae 6983 vty_out(vty,
ea47320b
DL
6984 "Max-med on-startup active\n");
6985 if (bgp->v_maxmed_admin)
d62a17ae 6986 vty_out(vty,
ea47320b 6987 "Max-med administrative active\n");
d62a17ae 6988
60466a63
QY
6989 vty_out(vty, "BGP table version %" PRIu64 "\n",
6990 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 6991
60466a63 6992 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
6993 vty_out(vty,
6994 "RIB entries %ld, using %s of memory\n",
6995 ents,
60466a63
QY
6996 mtype_memstr(memstrbuf,
6997 sizeof(memstrbuf),
6998 ents * sizeof(struct
6999 bgp_node)));
ea47320b
DL
7000
7001 /* Peer related usage */
7002 ents = listcount(bgp->peer);
60466a63 7003 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7004 ents,
7005 mtype_memstr(
60466a63
QY
7006 memstrbuf, sizeof(memstrbuf),
7007 ents * sizeof(struct peer)));
ea47320b
DL
7008
7009 if ((ents = listcount(bgp->group)))
d62a17ae 7010 vty_out(vty,
ea47320b 7011 "Peer groups %ld, using %s of memory\n",
d62a17ae 7012 ents,
7013 mtype_memstr(
7014 memstrbuf,
7015 sizeof(memstrbuf),
9d303b37 7016 ents * sizeof(struct
ea47320b 7017 peer_group)));
d62a17ae 7018
ea47320b
DL
7019 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7020 BGP_CONFIG_DAMPENING))
60466a63 7021 vty_out(vty, "Dampening enabled.\n");
ea47320b 7022 vty_out(vty, "\n");
d62a17ae 7023
ea47320b
DL
7024 /* Subtract 8 here because 'Neighbor' is
7025 * 8 characters */
7026 vty_out(vty, "Neighbor");
60466a63
QY
7027 vty_out(vty, "%*s", max_neighbor_width - 8,
7028 " ");
ea47320b
DL
7029 vty_out(vty,
7030 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7031 }
ea47320b 7032 }
d62a17ae 7033
ea47320b 7034 count++;
d62a17ae 7035
ea47320b
DL
7036 if (use_json) {
7037 json_peer = json_object_new_object();
d62a17ae 7038
ea47320b 7039 if (peer_dynamic_neighbor(peer))
60466a63
QY
7040 json_object_boolean_true_add(json_peer,
7041 "dynamicPeer");
d62a17ae 7042
ea47320b 7043 if (peer->hostname)
60466a63 7044 json_object_string_add(json_peer, "hostname",
ea47320b 7045 peer->hostname);
d62a17ae 7046
ea47320b 7047 if (peer->domainname)
60466a63
QY
7048 json_object_string_add(json_peer, "domainname",
7049 peer->domainname);
d62a17ae 7050
60466a63 7051 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7052 json_object_int_add(json_peer, "version", 4);
60466a63
QY
7053 json_object_int_add(json_peer, "msgRcvd",
7054 peer->open_in + peer->update_in
7055 + peer->keepalive_in
7056 + peer->notify_in
7057 + peer->refresh_in
7058 + peer->dynamic_cap_in);
7059 json_object_int_add(json_peer, "msgSent",
7060 peer->open_out + peer->update_out
7061 + peer->keepalive_out
7062 + peer->notify_out
7063 + peer->refresh_out
7064 + peer->dynamic_cap_out);
ea47320b
DL
7065
7066 json_object_int_add(json_peer, "tableVersion",
7067 peer->version[afi][safi]);
7068 json_object_int_add(json_peer, "outq",
7069 peer->obuf->count);
7070 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7071 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7072 use_json, json_peer);
7073 json_object_int_add(json_peer, "prefixReceivedCount",
7074 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7075
ea47320b 7076 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7077 json_object_string_add(json_peer, "state",
ea47320b 7078 "Idle (Admin)");
60466a63
QY
7079 else if (CHECK_FLAG(peer->sflags,
7080 PEER_STATUS_PREFIX_OVERFLOW))
7081 json_object_string_add(json_peer, "state",
ea47320b
DL
7082 "Idle (PfxCt)");
7083 else
7084 json_object_string_add(
7085 json_peer, "state",
60466a63
QY
7086 lookup_msg(bgp_status_msg, peer->status,
7087 NULL));
ea47320b
DL
7088
7089 if (peer->conf_if)
60466a63 7090 json_object_string_add(json_peer, "idType",
ea47320b
DL
7091 "interface");
7092 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7093 json_object_string_add(json_peer, "idType",
7094 "ipv4");
ea47320b 7095 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7096 json_object_string_add(json_peer, "idType",
7097 "ipv6");
d62a17ae 7098
ea47320b
DL
7099 json_object_object_add(json_peers, peer->host,
7100 json_peer);
7101 } else {
7102 memset(dn_flag, '\0', sizeof(dn_flag));
7103 if (peer_dynamic_neighbor(peer)) {
7104 dn_count++;
7105 dn_flag[0] = '*';
7106 }
d62a17ae 7107
ea47320b 7108 if (peer->hostname
60466a63 7109 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7110 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7111 peer->hostname, peer->host);
ea47320b 7112 else
60466a63 7113 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7114
7115 /* pad the neighbor column with spaces */
7116 if (len < max_neighbor_width)
60466a63
QY
7117 vty_out(vty, "%*s", max_neighbor_width - len,
7118 " ");
ea47320b 7119
86a55b99 7120 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
ea47320b 7121 peer->as,
424ab01d
QY
7122 atomic_load_explicit(&peer->open_in,
7123 memory_order_relaxed)
7124 + atomic_load_explicit(
7125 &peer->update_in,
7126 memory_order_relaxed)
7127 + atomic_load_explicit(
7128 &peer->keepalive_in,
7129 memory_order_relaxed)
7130 + atomic_load_explicit(
7131 &peer->notify_in,
7132 memory_order_relaxed)
7133 + atomic_load_explicit(
7134 &peer->refresh_in,
7135 memory_order_relaxed)
7136 + atomic_load_explicit(
7137 &peer->dynamic_cap_in,
7138 memory_order_relaxed),
7139 atomic_load_explicit(&peer->open_out,
7140 memory_order_relaxed)
7141 + atomic_load_explicit(
7142 &peer->update_out,
7143 memory_order_relaxed)
7144 + atomic_load_explicit(
7145 &peer->keepalive_out,
7146 memory_order_relaxed)
7147 + atomic_load_explicit(
7148 &peer->notify_out,
7149 memory_order_relaxed)
7150 + atomic_load_explicit(
7151 &peer->refresh_out,
7152 memory_order_relaxed)
7153 + atomic_load_explicit(
7154 &peer->dynamic_cap_out,
7155 memory_order_relaxed),
60466a63 7156 peer->version[afi][safi], 0, peer->obuf->count,
d62a17ae 7157 peer_uptime(peer->uptime, timebuf,
ea47320b 7158 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7159
ea47320b
DL
7160 if (peer->status == Established)
7161 vty_out(vty, " %12ld",
60466a63 7162 peer->pcount[afi][pfx_rcd_safi]);
ea47320b 7163 else {
60466a63 7164 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7165 vty_out(vty, " Idle (Admin)");
60466a63
QY
7166 else if (CHECK_FLAG(
7167 peer->sflags,
7168 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7169 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7170 else
ea47320b 7171 vty_out(vty, " %12s",
60466a63
QY
7172 lookup_msg(bgp_status_msg,
7173 peer->status, NULL));
d62a17ae 7174 }
ea47320b 7175 vty_out(vty, "\n");
d62a17ae 7176 }
7177 }
f933309e 7178
d62a17ae 7179 if (use_json) {
7180 json_object_object_add(json, "peers", json_peers);
7181
7182 json_object_int_add(json, "totalPeers", count);
7183 json_object_int_add(json, "dynamicPeers", dn_count);
7184
57a9c8a8
DS
7185 bgp_show_bestpath_json(bgp, json);
7186
9d303b37
DL
7187 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7188 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7189 json_object_free(json);
7190 } else {
7191 if (count)
7192 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7193 else {
7194 if (use_json)
7195 vty_out(vty,
7196 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7197 afi_safi_print(afi, safi));
7198 else
7199 vty_out(vty, "No %s neighbor is configured\n",
7200 afi_safi_print(afi, safi));
7201 }
b05a1c8b 7202
d62a17ae 7203 if (dn_count && !use_json) {
7204 vty_out(vty, "* - dynamic neighbor\n");
7205 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7206 dn_count, bgp->dynamic_neighbors_limit);
7207 }
7208 }
1ff9a340 7209
d62a17ae 7210 return CMD_SUCCESS;
718e3744 7211}
7212
d62a17ae 7213static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7214 int safi, u_char use_json,
7215 json_object *json)
7216{
7217 int is_first = 1;
7218 int afi_wildcard = (afi == AFI_MAX);
7219 int safi_wildcard = (safi == SAFI_MAX);
7220 int is_wildcard = (afi_wildcard || safi_wildcard);
7221 bool json_output = false;
7222
7223 if (use_json && is_wildcard)
7224 vty_out(vty, "{\n");
7225 if (afi_wildcard)
7226 afi = 1; /* AFI_IP */
7227 while (afi < AFI_MAX) {
7228 if (safi_wildcard)
7229 safi = 1; /* SAFI_UNICAST */
7230 while (safi < SAFI_MAX) {
318cac96 7231 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7232 json_output = true;
7233 if (is_wildcard) {
7234 /*
7235 * So limit output to those afi/safi
7236 * pairs that
7237 * actualy have something interesting in
7238 * them
7239 */
7240 if (use_json) {
7241 json = json_object_new_object();
7242
7243 if (!is_first)
7244 vty_out(vty, ",\n");
7245 else
7246 is_first = 0;
7247
7248 vty_out(vty, "\"%s\":",
7249 afi_safi_json(afi,
7250 safi));
7251 } else {
7252 vty_out(vty, "\n%s Summary:\n",
7253 afi_safi_print(afi,
7254 safi));
7255 }
7256 }
7257 bgp_show_summary(vty, bgp, afi, safi, use_json,
7258 json);
7259 }
7260 safi++;
d62a17ae 7261 if (!safi_wildcard)
7262 safi = SAFI_MAX;
7263 }
7264 afi++;
7265 if (!afi_wildcard
7266 || afi == AFI_L2VPN) /* special case, not handled yet */
7267 afi = AFI_MAX;
7268 }
7269
7270 if (use_json && is_wildcard)
7271 vty_out(vty, "}\n");
7272 else if (use_json && !json_output)
7273 vty_out(vty, "{}\n");
7274}
7275
7276static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7277 safi_t safi, u_char use_json)
7278{
7279 struct listnode *node, *nnode;
7280 struct bgp *bgp;
7281 json_object *json = NULL;
7282 int is_first = 1;
7283
7284 if (use_json)
7285 vty_out(vty, "{\n");
7286
7287 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7288 if (use_json) {
7289 json = json_object_new_object();
7290
7291 if (!is_first)
7292 vty_out(vty, ",\n");
7293 else
7294 is_first = 0;
7295
7296 vty_out(vty, "\"%s\":",
7297 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7298 ? "Default"
7299 : bgp->name);
7300 } else {
7301 vty_out(vty, "\nInstance %s:\n",
7302 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7303 ? "Default"
7304 : bgp->name);
7305 }
7306 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7307 }
7308
7309 if (use_json)
7310 vty_out(vty, "}\n");
7311}
7312
7313int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7314 safi_t safi, u_char use_json)
7315{
7316 struct bgp *bgp;
7317
7318 if (name) {
7319 if (strmatch(name, "all")) {
7320 bgp_show_all_instances_summary_vty(vty, afi, safi,
7321 use_json);
7322 return CMD_SUCCESS;
7323 } else {
7324 bgp = bgp_lookup_by_name(name);
7325
7326 if (!bgp) {
7327 if (use_json)
7328 vty_out(vty, "{}\n");
7329 else
7330 vty_out(vty,
7331 "%% No such BGP instance exist\n");
7332 return CMD_WARNING;
7333 }
7334
7335 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7336 NULL);
7337 return CMD_SUCCESS;
7338 }
7339 }
7340
7341 bgp = bgp_get_default();
7342
7343 if (bgp)
7344 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7345
7346 return CMD_SUCCESS;
4fb25c53
DW
7347}
7348
716b2d8a 7349/* `show [ip] bgp summary' commands. */
47fc97cc 7350DEFUN (show_ip_bgp_summary,
718e3744 7351 show_ip_bgp_summary_cmd,
dd6bd0f1 7352 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7353 SHOW_STR
7354 IP_STR
7355 BGP_STR
8386ac43 7356 BGP_INSTANCE_HELP_STR
46f296b4 7357 BGP_AFI_HELP_STR
dd6bd0f1 7358 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7359 "Summary of BGP neighbor status\n"
9973d184 7360 JSON_STR)
718e3744 7361{
d62a17ae 7362 char *vrf = NULL;
7363 afi_t afi = AFI_MAX;
7364 safi_t safi = SAFI_MAX;
7365
7366 int idx = 0;
7367
7368 /* show [ip] bgp */
7369 if (argv_find(argv, argc, "ip", &idx))
7370 afi = AFI_IP;
7371 /* [<view|vrf> VIEWVRFNAME] */
7372 if (argv_find(argv, argc, "view", &idx)
7373 || argv_find(argv, argc, "vrf", &idx))
7374 vrf = argv[++idx]->arg;
7375 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7376 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7377 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7378 }
7379
7380 int uj = use_json(argc, argv);
7381
7382 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7383}
7384
7385const char *afi_safi_print(afi_t afi, safi_t safi)
7386{
7387 if (afi == AFI_IP && safi == SAFI_UNICAST)
7388 return "IPv4 Unicast";
7389 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7390 return "IPv4 Multicast";
7391 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7392 return "IPv4 Labeled Unicast";
7393 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7394 return "IPv4 VPN";
7395 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7396 return "IPv4 Encap";
7397 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7398 return "IPv6 Unicast";
7399 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7400 return "IPv6 Multicast";
7401 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7402 return "IPv6 Labeled Unicast";
7403 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7404 return "IPv6 VPN";
7405 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7406 return "IPv6 Encap";
7407 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7408 return "L2VPN EVPN";
7409 else
7410 return "Unknown";
538621f2 7411}
7412
b9f77ec8
DS
7413/*
7414 * Please note that we have intentionally camelCased
7415 * the return strings here. So if you want
7416 * to use this function, please ensure you
7417 * are doing this within json output
7418 */
d62a17ae 7419const char *afi_safi_json(afi_t afi, safi_t safi)
7420{
7421 if (afi == AFI_IP && safi == SAFI_UNICAST)
7422 return "ipv4Unicast";
7423 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7424 return "ipv4Multicast";
7425 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7426 return "ipv4LabeledUnicast";
7427 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7428 return "ipv4Vpn";
7429 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7430 return "ipv4Encap";
7431 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7432 return "ipv6Unicast";
7433 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7434 return "ipv6Multicast";
7435 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7436 return "ipv6LabeledUnicast";
7437 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7438 return "ipv6Vpn";
7439 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7440 return "ipv6Encap";
7441 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7442 return "l2VpnEvpn";
7443 else
7444 return "Unknown";
27162734
LB
7445}
7446
718e3744 7447/* Show BGP peer's information. */
d62a17ae 7448enum show_type { show_all, show_peer };
7449
7450static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7451 afi_t afi, safi_t safi,
7452 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7453 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7454 u_char use_json, json_object *json_pref)
7455{
7456 /* Send-Mode */
7457 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7458 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7459 if (use_json) {
7460 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7461 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7462 json_object_string_add(json_pref, "sendMode",
7463 "advertisedAndReceived");
7464 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7465 json_object_string_add(json_pref, "sendMode",
7466 "advertised");
7467 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7468 json_object_string_add(json_pref, "sendMode",
7469 "received");
7470 } else {
7471 vty_out(vty, " Send-mode: ");
7472 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7473 vty_out(vty, "advertised");
7474 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7475 vty_out(vty, "%sreceived",
7476 CHECK_FLAG(p->af_cap[afi][safi],
7477 adv_smcap)
7478 ? ", "
7479 : "");
7480 vty_out(vty, "\n");
7481 }
7482 }
7483
7484 /* Receive-Mode */
7485 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7486 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7487 if (use_json) {
7488 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7489 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7490 json_object_string_add(json_pref, "recvMode",
7491 "advertisedAndReceived");
7492 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7493 json_object_string_add(json_pref, "recvMode",
7494 "advertised");
7495 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7496 json_object_string_add(json_pref, "recvMode",
7497 "received");
7498 } else {
7499 vty_out(vty, " Receive-mode: ");
7500 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7501 vty_out(vty, "advertised");
7502 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7503 vty_out(vty, "%sreceived",
7504 CHECK_FLAG(p->af_cap[afi][safi],
7505 adv_rmcap)
7506 ? ", "
7507 : "");
7508 vty_out(vty, "\n");
7509 }
7510 }
7511}
7512
7513static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7514 safi_t safi, u_char use_json,
7515 json_object *json_neigh)
7516{
0291c246
MK
7517 struct bgp_filter *filter;
7518 struct peer_af *paf;
7519 char orf_pfx_name[BUFSIZ];
7520 int orf_pfx_count;
7521 json_object *json_af = NULL;
7522 json_object *json_prefA = NULL;
7523 json_object *json_prefB = NULL;
7524 json_object *json_addr = NULL;
d62a17ae 7525
7526 if (use_json) {
7527 json_addr = json_object_new_object();
7528 json_af = json_object_new_object();
7529 filter = &p->filter[afi][safi];
7530
7531 if (peer_group_active(p))
7532 json_object_string_add(json_addr, "peerGroupMember",
7533 p->group->name);
7534
7535 paf = peer_af_find(p, afi, safi);
7536 if (paf && PAF_SUBGRP(paf)) {
7537 json_object_int_add(json_addr, "updateGroupId",
7538 PAF_UPDGRP(paf)->id);
7539 json_object_int_add(json_addr, "subGroupId",
7540 PAF_SUBGRP(paf)->id);
7541 json_object_int_add(json_addr, "packetQueueLength",
7542 bpacket_queue_virtual_length(paf));
7543 }
7544
7545 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7546 || CHECK_FLAG(p->af_cap[afi][safi],
7547 PEER_CAP_ORF_PREFIX_SM_RCV)
7548 || CHECK_FLAG(p->af_cap[afi][safi],
7549 PEER_CAP_ORF_PREFIX_RM_ADV)
7550 || CHECK_FLAG(p->af_cap[afi][safi],
7551 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7552 json_object_int_add(json_af, "orfType",
7553 ORF_TYPE_PREFIX);
7554 json_prefA = json_object_new_object();
7555 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7556 PEER_CAP_ORF_PREFIX_SM_ADV,
7557 PEER_CAP_ORF_PREFIX_RM_ADV,
7558 PEER_CAP_ORF_PREFIX_SM_RCV,
7559 PEER_CAP_ORF_PREFIX_RM_RCV,
7560 use_json, json_prefA);
7561 json_object_object_add(json_af, "orfPrefixList",
7562 json_prefA);
7563 }
7564
7565 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7566 || CHECK_FLAG(p->af_cap[afi][safi],
7567 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7568 || CHECK_FLAG(p->af_cap[afi][safi],
7569 PEER_CAP_ORF_PREFIX_RM_ADV)
7570 || CHECK_FLAG(p->af_cap[afi][safi],
7571 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7572 json_object_int_add(json_af, "orfOldType",
7573 ORF_TYPE_PREFIX_OLD);
7574 json_prefB = json_object_new_object();
7575 bgp_show_peer_afi_orf_cap(
7576 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7577 PEER_CAP_ORF_PREFIX_RM_ADV,
7578 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7579 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7580 json_prefB);
7581 json_object_object_add(json_af, "orfOldPrefixList",
7582 json_prefB);
7583 }
7584
7585 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7586 || CHECK_FLAG(p->af_cap[afi][safi],
7587 PEER_CAP_ORF_PREFIX_SM_RCV)
7588 || CHECK_FLAG(p->af_cap[afi][safi],
7589 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7590 || CHECK_FLAG(p->af_cap[afi][safi],
7591 PEER_CAP_ORF_PREFIX_RM_ADV)
7592 || CHECK_FLAG(p->af_cap[afi][safi],
7593 PEER_CAP_ORF_PREFIX_RM_RCV)
7594 || CHECK_FLAG(p->af_cap[afi][safi],
7595 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7596 json_object_object_add(json_addr, "afDependentCap",
7597 json_af);
7598 else
7599 json_object_free(json_af);
7600
7601 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7602 orf_pfx_count = prefix_bgp_show_prefix_list(
7603 NULL, afi, orf_pfx_name, use_json);
7604
7605 if (CHECK_FLAG(p->af_sflags[afi][safi],
7606 PEER_STATUS_ORF_PREFIX_SEND)
7607 || orf_pfx_count) {
7608 if (CHECK_FLAG(p->af_sflags[afi][safi],
7609 PEER_STATUS_ORF_PREFIX_SEND))
7610 json_object_boolean_true_add(json_neigh,
7611 "orfSent");
7612 if (orf_pfx_count)
7613 json_object_int_add(json_addr, "orfRecvCounter",
7614 orf_pfx_count);
7615 }
7616 if (CHECK_FLAG(p->af_sflags[afi][safi],
7617 PEER_STATUS_ORF_WAIT_REFRESH))
7618 json_object_string_add(
7619 json_addr, "orfFirstUpdate",
7620 "deferredUntilORFOrRouteRefreshRecvd");
7621
7622 if (CHECK_FLAG(p->af_flags[afi][safi],
7623 PEER_FLAG_REFLECTOR_CLIENT))
7624 json_object_boolean_true_add(json_addr,
7625 "routeReflectorClient");
7626 if (CHECK_FLAG(p->af_flags[afi][safi],
7627 PEER_FLAG_RSERVER_CLIENT))
7628 json_object_boolean_true_add(json_addr,
7629 "routeServerClient");
7630 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7631 json_object_boolean_true_add(json_addr,
7632 "inboundSoftConfigPermit");
7633
7634 if (CHECK_FLAG(p->af_flags[afi][safi],
7635 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7636 json_object_boolean_true_add(
7637 json_addr,
7638 "privateAsNumsAllReplacedInUpdatesToNbr");
7639 else if (CHECK_FLAG(p->af_flags[afi][safi],
7640 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7641 json_object_boolean_true_add(
7642 json_addr,
7643 "privateAsNumsReplacedInUpdatesToNbr");
7644 else if (CHECK_FLAG(p->af_flags[afi][safi],
7645 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7646 json_object_boolean_true_add(
7647 json_addr,
7648 "privateAsNumsAllRemovedInUpdatesToNbr");
7649 else if (CHECK_FLAG(p->af_flags[afi][safi],
7650 PEER_FLAG_REMOVE_PRIVATE_AS))
7651 json_object_boolean_true_add(
7652 json_addr,
7653 "privateAsNumsRemovedInUpdatesToNbr");
7654
7655 if (CHECK_FLAG(p->af_flags[afi][safi],
7656 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7657 json_object_boolean_true_add(json_addr,
7658 "addpathTxAllPaths");
7659
7660 if (CHECK_FLAG(p->af_flags[afi][safi],
7661 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7662 json_object_boolean_true_add(json_addr,
7663 "addpathTxBestpathPerAS");
7664
7665 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7666 json_object_string_add(json_addr,
7667 "overrideASNsInOutboundUpdates",
7668 "ifAspathEqualRemoteAs");
7669
7670 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7671 || CHECK_FLAG(p->af_flags[afi][safi],
7672 PEER_FLAG_FORCE_NEXTHOP_SELF))
7673 json_object_boolean_true_add(json_addr,
7674 "routerAlwaysNextHop");
7675 if (CHECK_FLAG(p->af_flags[afi][safi],
7676 PEER_FLAG_AS_PATH_UNCHANGED))
7677 json_object_boolean_true_add(
7678 json_addr, "unchangedAsPathPropogatedToNbr");
7679 if (CHECK_FLAG(p->af_flags[afi][safi],
7680 PEER_FLAG_NEXTHOP_UNCHANGED))
7681 json_object_boolean_true_add(
7682 json_addr, "unchangedNextHopPropogatedToNbr");
7683 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7684 json_object_boolean_true_add(
7685 json_addr, "unchangedMedPropogatedToNbr");
7686 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7687 || CHECK_FLAG(p->af_flags[afi][safi],
7688 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7689 if (CHECK_FLAG(p->af_flags[afi][safi],
7690 PEER_FLAG_SEND_COMMUNITY)
7691 && CHECK_FLAG(p->af_flags[afi][safi],
7692 PEER_FLAG_SEND_EXT_COMMUNITY))
7693 json_object_string_add(json_addr,
7694 "commAttriSentToNbr",
7695 "extendedAndStandard");
7696 else if (CHECK_FLAG(p->af_flags[afi][safi],
7697 PEER_FLAG_SEND_EXT_COMMUNITY))
7698 json_object_string_add(json_addr,
7699 "commAttriSentToNbr",
7700 "extended");
7701 else
7702 json_object_string_add(json_addr,
7703 "commAttriSentToNbr",
7704 "standard");
7705 }
7706 if (CHECK_FLAG(p->af_flags[afi][safi],
7707 PEER_FLAG_DEFAULT_ORIGINATE)) {
7708 if (p->default_rmap[afi][safi].name)
7709 json_object_string_add(
7710 json_addr, "defaultRouteMap",
7711 p->default_rmap[afi][safi].name);
7712
7713 if (paf && PAF_SUBGRP(paf)
7714 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7715 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7716 json_object_boolean_true_add(json_addr,
7717 "defaultSent");
7718 else
7719 json_object_boolean_true_add(json_addr,
7720 "defaultNotSent");
7721 }
7722
dff8f48d
MK
7723 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7724 if (p->bgp->advertise_all_vni)
60466a63
QY
7725 json_object_boolean_true_add(
7726 json_addr, "advertiseAllVnis");
dff8f48d
MK
7727 }
7728
d62a17ae 7729 if (filter->plist[FILTER_IN].name
7730 || filter->dlist[FILTER_IN].name
7731 || filter->aslist[FILTER_IN].name
7732 || filter->map[RMAP_IN].name)
7733 json_object_boolean_true_add(json_addr,
7734 "inboundPathPolicyConfig");
7735 if (filter->plist[FILTER_OUT].name
7736 || filter->dlist[FILTER_OUT].name
7737 || filter->aslist[FILTER_OUT].name
7738 || filter->map[RMAP_OUT].name || filter->usmap.name)
7739 json_object_boolean_true_add(
7740 json_addr, "outboundPathPolicyConfig");
7741
7742 /* prefix-list */
7743 if (filter->plist[FILTER_IN].name)
7744 json_object_string_add(json_addr,
7745 "incomingUpdatePrefixFilterList",
7746 filter->plist[FILTER_IN].name);
7747 if (filter->plist[FILTER_OUT].name)
7748 json_object_string_add(json_addr,
7749 "outgoingUpdatePrefixFilterList",
7750 filter->plist[FILTER_OUT].name);
7751
7752 /* distribute-list */
7753 if (filter->dlist[FILTER_IN].name)
7754 json_object_string_add(
7755 json_addr, "incomingUpdateNetworkFilterList",
7756 filter->dlist[FILTER_IN].name);
7757 if (filter->dlist[FILTER_OUT].name)
7758 json_object_string_add(
7759 json_addr, "outgoingUpdateNetworkFilterList",
7760 filter->dlist[FILTER_OUT].name);
7761
7762 /* filter-list. */
7763 if (filter->aslist[FILTER_IN].name)
7764 json_object_string_add(json_addr,
7765 "incomingUpdateAsPathFilterList",
7766 filter->aslist[FILTER_IN].name);
7767 if (filter->aslist[FILTER_OUT].name)
7768 json_object_string_add(json_addr,
7769 "outgoingUpdateAsPathFilterList",
7770 filter->aslist[FILTER_OUT].name);
7771
7772 /* route-map. */
7773 if (filter->map[RMAP_IN].name)
7774 json_object_string_add(
7775 json_addr, "routeMapForIncomingAdvertisements",
7776 filter->map[RMAP_IN].name);
7777 if (filter->map[RMAP_OUT].name)
7778 json_object_string_add(
7779 json_addr, "routeMapForOutgoingAdvertisements",
7780 filter->map[RMAP_OUT].name);
7781
7782 /* unsuppress-map */
7783 if (filter->usmap.name)
7784 json_object_string_add(json_addr,
7785 "selectiveUnsuppressRouteMap",
7786 filter->usmap.name);
7787
7788 /* Receive prefix count */
7789 json_object_int_add(json_addr, "acceptedPrefixCounter",
7790 p->pcount[afi][safi]);
7791
7792 /* Maximum prefix */
7793 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7794 json_object_int_add(json_addr, "prefixAllowedMax",
7795 p->pmax[afi][safi]);
7796 if (CHECK_FLAG(p->af_flags[afi][safi],
7797 PEER_FLAG_MAX_PREFIX_WARNING))
7798 json_object_boolean_true_add(
7799 json_addr, "prefixAllowedMaxWarning");
7800 json_object_int_add(json_addr,
7801 "prefixAllowedWarningThresh",
7802 p->pmax_threshold[afi][safi]);
7803 if (p->pmax_restart[afi][safi])
7804 json_object_int_add(
7805 json_addr,
7806 "prefixAllowedRestartIntervalMsecs",
7807 p->pmax_restart[afi][safi] * 60000);
7808 }
7809 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7810 json_addr);
7811
7812 } else {
7813 filter = &p->filter[afi][safi];
7814
7815 vty_out(vty, " For address family: %s\n",
7816 afi_safi_print(afi, safi));
7817
7818 if (peer_group_active(p))
7819 vty_out(vty, " %s peer-group member\n",
7820 p->group->name);
7821
7822 paf = peer_af_find(p, afi, safi);
7823 if (paf && PAF_SUBGRP(paf)) {
9d303b37
DL
7824 vty_out(vty, " Update group %" PRIu64
7825 ", subgroup %" PRIu64 "\n",
d62a17ae 7826 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7827 vty_out(vty, " Packet Queue length %d\n",
7828 bpacket_queue_virtual_length(paf));
7829 } else {
7830 vty_out(vty, " Not part of any update group\n");
7831 }
7832 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7833 || CHECK_FLAG(p->af_cap[afi][safi],
7834 PEER_CAP_ORF_PREFIX_SM_RCV)
7835 || CHECK_FLAG(p->af_cap[afi][safi],
7836 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7837 || CHECK_FLAG(p->af_cap[afi][safi],
7838 PEER_CAP_ORF_PREFIX_RM_ADV)
7839 || CHECK_FLAG(p->af_cap[afi][safi],
7840 PEER_CAP_ORF_PREFIX_RM_RCV)
7841 || CHECK_FLAG(p->af_cap[afi][safi],
7842 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7843 vty_out(vty, " AF-dependant capabilities:\n");
7844
7845 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7846 || CHECK_FLAG(p->af_cap[afi][safi],
7847 PEER_CAP_ORF_PREFIX_SM_RCV)
7848 || CHECK_FLAG(p->af_cap[afi][safi],
7849 PEER_CAP_ORF_PREFIX_RM_ADV)
7850 || CHECK_FLAG(p->af_cap[afi][safi],
7851 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7852 vty_out(vty,
7853 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7854 ORF_TYPE_PREFIX);
7855 bgp_show_peer_afi_orf_cap(
7856 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7857 PEER_CAP_ORF_PREFIX_RM_ADV,
7858 PEER_CAP_ORF_PREFIX_SM_RCV,
7859 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7860 }
7861 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7862 || CHECK_FLAG(p->af_cap[afi][safi],
7863 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7864 || CHECK_FLAG(p->af_cap[afi][safi],
7865 PEER_CAP_ORF_PREFIX_RM_ADV)
7866 || CHECK_FLAG(p->af_cap[afi][safi],
7867 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7868 vty_out(vty,
7869 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7870 ORF_TYPE_PREFIX_OLD);
7871 bgp_show_peer_afi_orf_cap(
7872 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7873 PEER_CAP_ORF_PREFIX_RM_ADV,
7874 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7875 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7876 }
7877
7878 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7879 orf_pfx_count = prefix_bgp_show_prefix_list(
7880 NULL, afi, orf_pfx_name, use_json);
7881
7882 if (CHECK_FLAG(p->af_sflags[afi][safi],
7883 PEER_STATUS_ORF_PREFIX_SEND)
7884 || orf_pfx_count) {
7885 vty_out(vty, " Outbound Route Filter (ORF):");
7886 if (CHECK_FLAG(p->af_sflags[afi][safi],
7887 PEER_STATUS_ORF_PREFIX_SEND))
7888 vty_out(vty, " sent;");
7889 if (orf_pfx_count)
7890 vty_out(vty, " received (%d entries)",
7891 orf_pfx_count);
7892 vty_out(vty, "\n");
7893 }
7894 if (CHECK_FLAG(p->af_sflags[afi][safi],
7895 PEER_STATUS_ORF_WAIT_REFRESH))
7896 vty_out(vty,
7897 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7898
7899 if (CHECK_FLAG(p->af_flags[afi][safi],
7900 PEER_FLAG_REFLECTOR_CLIENT))
7901 vty_out(vty, " Route-Reflector Client\n");
7902 if (CHECK_FLAG(p->af_flags[afi][safi],
7903 PEER_FLAG_RSERVER_CLIENT))
7904 vty_out(vty, " Route-Server Client\n");
7905 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7906 vty_out(vty,
7907 " Inbound soft reconfiguration allowed\n");
7908
7909 if (CHECK_FLAG(p->af_flags[afi][safi],
7910 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7911 vty_out(vty,
7912 " Private AS numbers (all) replaced in updates to this neighbor\n");
7913 else if (CHECK_FLAG(p->af_flags[afi][safi],
7914 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7915 vty_out(vty,
7916 " Private AS numbers replaced in updates to this neighbor\n");
7917 else if (CHECK_FLAG(p->af_flags[afi][safi],
7918 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7919 vty_out(vty,
7920 " Private AS numbers (all) removed in updates to this neighbor\n");
7921 else if (CHECK_FLAG(p->af_flags[afi][safi],
7922 PEER_FLAG_REMOVE_PRIVATE_AS))
7923 vty_out(vty,
7924 " Private AS numbers removed in updates to this neighbor\n");
7925
7926 if (CHECK_FLAG(p->af_flags[afi][safi],
7927 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7928 vty_out(vty, " Advertise all paths via addpath\n");
7929
7930 if (CHECK_FLAG(p->af_flags[afi][safi],
7931 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7932 vty_out(vty,
7933 " Advertise bestpath per AS via addpath\n");
7934
7935 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7936 vty_out(vty,
7937 " Override ASNs in outbound updates if aspath equals remote-as\n");
7938
7939 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7940 || CHECK_FLAG(p->af_flags[afi][safi],
7941 PEER_FLAG_FORCE_NEXTHOP_SELF))
7942 vty_out(vty, " NEXT_HOP is always this router\n");
7943 if (CHECK_FLAG(p->af_flags[afi][safi],
7944 PEER_FLAG_AS_PATH_UNCHANGED))
7945 vty_out(vty,
7946 " AS_PATH is propagated unchanged to this neighbor\n");
7947 if (CHECK_FLAG(p->af_flags[afi][safi],
7948 PEER_FLAG_NEXTHOP_UNCHANGED))
7949 vty_out(vty,
7950 " NEXT_HOP is propagated unchanged to this neighbor\n");
7951 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7952 vty_out(vty,
7953 " MED is propagated unchanged to this neighbor\n");
7954 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7955 || CHECK_FLAG(p->af_flags[afi][safi],
7956 PEER_FLAG_SEND_EXT_COMMUNITY)
7957 || CHECK_FLAG(p->af_flags[afi][safi],
7958 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7959 vty_out(vty,
7960 " Community attribute sent to this neighbor");
7961 if (CHECK_FLAG(p->af_flags[afi][safi],
7962 PEER_FLAG_SEND_COMMUNITY)
7963 && CHECK_FLAG(p->af_flags[afi][safi],
7964 PEER_FLAG_SEND_EXT_COMMUNITY)
7965 && CHECK_FLAG(p->af_flags[afi][safi],
7966 PEER_FLAG_SEND_LARGE_COMMUNITY))
7967 vty_out(vty, "(all)\n");
7968 else if (CHECK_FLAG(p->af_flags[afi][safi],
7969 PEER_FLAG_SEND_LARGE_COMMUNITY))
7970 vty_out(vty, "(large)\n");
7971 else if (CHECK_FLAG(p->af_flags[afi][safi],
7972 PEER_FLAG_SEND_EXT_COMMUNITY))
7973 vty_out(vty, "(extended)\n");
7974 else
7975 vty_out(vty, "(standard)\n");
7976 }
7977 if (CHECK_FLAG(p->af_flags[afi][safi],
7978 PEER_FLAG_DEFAULT_ORIGINATE)) {
7979 vty_out(vty, " Default information originate,");
7980
7981 if (p->default_rmap[afi][safi].name)
7982 vty_out(vty, " default route-map %s%s,",
7983 p->default_rmap[afi][safi].map ? "*"
7984 : "",
7985 p->default_rmap[afi][safi].name);
7986 if (paf && PAF_SUBGRP(paf)
7987 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7988 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7989 vty_out(vty, " default sent\n");
7990 else
7991 vty_out(vty, " default not sent\n");
7992 }
7993
dff8f48d
MK
7994 /* advertise-vni-all */
7995 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7996 if (p->bgp->advertise_all_vni)
7997 vty_out(vty, " advertise-all-vni\n");
7998 }
7999
d62a17ae 8000 if (filter->plist[FILTER_IN].name
8001 || filter->dlist[FILTER_IN].name
8002 || filter->aslist[FILTER_IN].name
8003 || filter->map[RMAP_IN].name)
8004 vty_out(vty, " Inbound path policy configured\n");
8005 if (filter->plist[FILTER_OUT].name
8006 || filter->dlist[FILTER_OUT].name
8007 || filter->aslist[FILTER_OUT].name
8008 || filter->map[RMAP_OUT].name || filter->usmap.name)
8009 vty_out(vty, " Outbound path policy configured\n");
8010
8011 /* prefix-list */
8012 if (filter->plist[FILTER_IN].name)
8013 vty_out(vty,
8014 " Incoming update prefix filter list is %s%s\n",
8015 filter->plist[FILTER_IN].plist ? "*" : "",
8016 filter->plist[FILTER_IN].name);
8017 if (filter->plist[FILTER_OUT].name)
8018 vty_out(vty,
8019 " Outgoing update prefix filter list is %s%s\n",
8020 filter->plist[FILTER_OUT].plist ? "*" : "",
8021 filter->plist[FILTER_OUT].name);
8022
8023 /* distribute-list */
8024 if (filter->dlist[FILTER_IN].name)
8025 vty_out(vty,
8026 " Incoming update network filter list is %s%s\n",
8027 filter->dlist[FILTER_IN].alist ? "*" : "",
8028 filter->dlist[FILTER_IN].name);
8029 if (filter->dlist[FILTER_OUT].name)
8030 vty_out(vty,
8031 " Outgoing update network filter list is %s%s\n",
8032 filter->dlist[FILTER_OUT].alist ? "*" : "",
8033 filter->dlist[FILTER_OUT].name);
8034
8035 /* filter-list. */
8036 if (filter->aslist[FILTER_IN].name)
8037 vty_out(vty,
8038 " Incoming update AS path filter list is %s%s\n",
8039 filter->aslist[FILTER_IN].aslist ? "*" : "",
8040 filter->aslist[FILTER_IN].name);
8041 if (filter->aslist[FILTER_OUT].name)
8042 vty_out(vty,
8043 " Outgoing update AS path filter list is %s%s\n",
8044 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8045 filter->aslist[FILTER_OUT].name);
8046
8047 /* route-map. */
8048 if (filter->map[RMAP_IN].name)
8049 vty_out(vty,
8050 " Route map for incoming advertisements is %s%s\n",
8051 filter->map[RMAP_IN].map ? "*" : "",
8052 filter->map[RMAP_IN].name);
8053 if (filter->map[RMAP_OUT].name)
8054 vty_out(vty,
8055 " Route map for outgoing advertisements is %s%s\n",
8056 filter->map[RMAP_OUT].map ? "*" : "",
8057 filter->map[RMAP_OUT].name);
8058
8059 /* unsuppress-map */
8060 if (filter->usmap.name)
8061 vty_out(vty,
8062 " Route map for selective unsuppress is %s%s\n",
8063 filter->usmap.map ? "*" : "",
8064 filter->usmap.name);
8065
8066 /* Receive prefix count */
8067 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8068
8069 /* Maximum prefix */
8070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8071 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8072 p->pmax[afi][safi],
8073 CHECK_FLAG(p->af_flags[afi][safi],
8074 PEER_FLAG_MAX_PREFIX_WARNING)
8075 ? " (warning-only)"
8076 : "");
8077 vty_out(vty, " Threshold for warning message %d%%",
8078 p->pmax_threshold[afi][safi]);
8079 if (p->pmax_restart[afi][safi])
8080 vty_out(vty, ", restart interval %d min",
8081 p->pmax_restart[afi][safi]);
8082 vty_out(vty, "\n");
8083 }
8084
8085 vty_out(vty, "\n");
8086 }
8087}
8088
8089static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8090 json_object *json)
718e3744 8091{
d62a17ae 8092 struct bgp *bgp;
8093 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8094 char timebuf[BGP_UPTIME_LEN];
8095 char dn_flag[2];
8096 const char *subcode_str;
8097 const char *code_str;
8098 afi_t afi;
8099 safi_t safi;
8100 u_int16_t i;
8101 u_char *msg;
8102 json_object *json_neigh = NULL;
8103 time_t epoch_tbuf;
718e3744 8104
d62a17ae 8105 bgp = p->bgp;
8106
8107 if (use_json)
8108 json_neigh = json_object_new_object();
8109
8110 memset(dn_flag, '\0', sizeof(dn_flag));
8111 if (!p->conf_if && peer_dynamic_neighbor(p))
8112 dn_flag[0] = '*';
8113
8114 if (!use_json) {
8115 if (p->conf_if) /* Configured interface name. */
8116 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8117 BGP_PEER_SU_UNSPEC(p)
8118 ? "None"
8119 : sockunion2str(&p->su, buf,
8120 SU_ADDRSTRLEN));
8121 else /* Configured IP address. */
8122 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8123 p->host);
8124 }
8125
8126 if (use_json) {
8127 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8128 json_object_string_add(json_neigh, "bgpNeighborAddr",
8129 "none");
8130 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8131 json_object_string_add(
8132 json_neigh, "bgpNeighborAddr",
8133 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8134
8135 json_object_int_add(json_neigh, "remoteAs", p->as);
8136
8137 if (p->change_local_as)
8138 json_object_int_add(json_neigh, "localAs",
8139 p->change_local_as);
8140 else
8141 json_object_int_add(json_neigh, "localAs", p->local_as);
8142
8143 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8144 json_object_boolean_true_add(json_neigh,
8145 "localAsNoPrepend");
8146
8147 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8148 json_object_boolean_true_add(json_neigh,
8149 "localAsReplaceAs");
8150 } else {
8151 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8152 || (p->as_type == AS_INTERNAL))
8153 vty_out(vty, "remote AS %u, ", p->as);
8154 else
8155 vty_out(vty, "remote AS Unspecified, ");
8156 vty_out(vty, "local AS %u%s%s, ",
8157 p->change_local_as ? p->change_local_as : p->local_as,
8158 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8159 ? " no-prepend"
8160 : "",
8161 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8162 ? " replace-as"
8163 : "");
8164 }
8165 /* peer type internal, external, confed-internal or confed-external */
8166 if (p->as == p->local_as) {
8167 if (use_json) {
8168 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8169 json_object_boolean_true_add(
8170 json_neigh, "nbrConfedInternalLink");
8171 else
8172 json_object_boolean_true_add(json_neigh,
8173 "nbrInternalLink");
8174 } else {
8175 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8176 vty_out(vty, "confed-internal link\n");
8177 else
8178 vty_out(vty, "internal link\n");
8179 }
8180 } else {
8181 if (use_json) {
8182 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8183 json_object_boolean_true_add(
8184 json_neigh, "nbrConfedExternalLink");
8185 else
8186 json_object_boolean_true_add(json_neigh,
8187 "nbrExternalLink");
8188 } else {
8189 if (bgp_confederation_peers_check(bgp, p->as))
8190 vty_out(vty, "confed-external link\n");
8191 else
8192 vty_out(vty, "external link\n");
8193 }
8194 }
8195
8196 /* Description. */
8197 if (p->desc) {
8198 if (use_json)
8199 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8200 else
8201 vty_out(vty, " Description: %s\n", p->desc);
8202 }
8203
8204 if (p->hostname) {
8205 if (use_json) {
8206 if (p->hostname)
8207 json_object_string_add(json_neigh, "hostname",
8208 p->hostname);
8209
8210 if (p->domainname)
8211 json_object_string_add(json_neigh, "domainname",
8212 p->domainname);
8213 } else {
8214 if (p->domainname && (p->domainname[0] != '\0'))
8215 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8216 p->domainname);
8217 else
8218 vty_out(vty, "Hostname: %s\n", p->hostname);
8219 }
8220 }
8221
8222 /* Peer-group */
8223 if (p->group) {
8224 if (use_json) {
8225 json_object_string_add(json_neigh, "peerGroup",
8226 p->group->name);
8227
8228 if (dn_flag[0]) {
8229 struct prefix prefix, *range = NULL;
8230
8231 sockunion2hostprefix(&(p->su), &prefix);
8232 range = peer_group_lookup_dynamic_neighbor_range(
8233 p->group, &prefix);
8234
8235 if (range) {
8236 prefix2str(range, buf1, sizeof(buf1));
8237 json_object_string_add(
8238 json_neigh,
8239 "peerSubnetRangeGroup", buf1);
8240 }
8241 }
8242 } else {
8243 vty_out(vty,
8244 " Member of peer-group %s for session parameters\n",
8245 p->group->name);
8246
8247 if (dn_flag[0]) {
8248 struct prefix prefix, *range = NULL;
8249
8250 sockunion2hostprefix(&(p->su), &prefix);
8251 range = peer_group_lookup_dynamic_neighbor_range(
8252 p->group, &prefix);
8253
8254 if (range) {
8255 prefix2str(range, buf1, sizeof(buf1));
8256 vty_out(vty,
8257 " Belongs to the subnet range group: %s\n",
8258 buf1);
8259 }
8260 }
8261 }
8262 }
8263
8264 if (use_json) {
8265 /* Administrative shutdown. */
8266 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8267 json_object_boolean_true_add(json_neigh,
8268 "adminShutDown");
8269
8270 /* BGP Version. */
8271 json_object_int_add(json_neigh, "bgpVersion", 4);
8272 json_object_string_add(
8273 json_neigh, "remoteRouterId",
8274 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8275
8276 /* Confederation */
8277 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8278 && bgp_confederation_peers_check(bgp, p->as))
8279 json_object_boolean_true_add(json_neigh,
8280 "nbrCommonAdmin");
8281
8282 /* Status. */
8283 json_object_string_add(
8284 json_neigh, "bgpState",
8285 lookup_msg(bgp_status_msg, p->status, NULL));
8286
8287 if (p->status == Established) {
8288 time_t uptime;
8289 struct tm *tm;
8290
8291 uptime = bgp_clock();
8292 uptime -= p->uptime;
8293 tm = gmtime(&uptime);
8294 epoch_tbuf = time(NULL) - uptime;
8295
8296 json_object_int_add(json_neigh, "bgpTimerUp",
8297 (tm->tm_sec * 1000)
8298 + (tm->tm_min * 60000)
8299 + (tm->tm_hour * 3600000));
8300 json_object_string_add(json_neigh, "bgpTimerUpString",
8301 peer_uptime(p->uptime, timebuf,
8302 BGP_UPTIME_LEN, 0,
8303 NULL));
8304 json_object_int_add(json_neigh,
8305 "bgpTimerUpEstablishedEpoch",
8306 epoch_tbuf);
8307 }
8308
8309 else if (p->status == Active) {
8310 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8311 json_object_string_add(json_neigh, "bgpStateIs",
8312 "passive");
8313 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8314 json_object_string_add(json_neigh, "bgpStateIs",
8315 "passiveNSF");
8316 }
8317
8318 /* read timer */
8319 time_t uptime;
8320 struct tm *tm;
8321
8322 uptime = bgp_clock();
8323 uptime -= p->readtime;
8324 tm = gmtime(&uptime);
8325 json_object_int_add(json_neigh, "bgpTimerLastRead",
8326 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8327 + (tm->tm_hour * 3600000));
8328
8329 uptime = bgp_clock();
8330 uptime -= p->last_write;
8331 tm = gmtime(&uptime);
8332 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8333 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8334 + (tm->tm_hour * 3600000));
8335
8336 uptime = bgp_clock();
8337 uptime -= p->update_time;
8338 tm = gmtime(&uptime);
8339 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8340 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8341 + (tm->tm_hour * 3600000));
8342
8343 /* Configured timer values. */
8344 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8345 p->v_holdtime * 1000);
8346 json_object_int_add(json_neigh,
8347 "bgpTimerKeepAliveIntervalMsecs",
8348 p->v_keepalive * 1000);
8349
d25e4efc 8350 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8351 json_object_int_add(json_neigh,
8352 "bgpTimerConfiguredHoldTimeMsecs",
8353 p->holdtime * 1000);
8354 json_object_int_add(
8355 json_neigh,
8356 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8357 p->keepalive * 1000);
d25e4efc
DS
8358 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8359 || (bgp->default_keepalive !=
8360 BGP_DEFAULT_KEEPALIVE)) {
8361 json_object_int_add(json_neigh,
8362 "bgpTimerConfiguredHoldTimeMsecs",
8363 bgp->default_holdtime);
8364 json_object_int_add(
8365 json_neigh,
8366 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8367 bgp->default_keepalive);
d62a17ae 8368 }
8369 } else {
8370 /* Administrative shutdown. */
8371 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8372 vty_out(vty, " Administratively shut down\n");
8373
8374 /* BGP Version. */
8375 vty_out(vty, " BGP version 4");
8376 vty_out(vty, ", remote router ID %s\n",
8377 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8378
8379 /* Confederation */
8380 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8381 && bgp_confederation_peers_check(bgp, p->as))
8382 vty_out(vty,
8383 " Neighbor under common administration\n");
8384
8385 /* Status. */
8386 vty_out(vty, " BGP state = %s",
8387 lookup_msg(bgp_status_msg, p->status, NULL));
8388
8389 if (p->status == Established)
8390 vty_out(vty, ", up for %8s",
8391 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8392 0, NULL));
8393
8394 else if (p->status == Active) {
8395 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8396 vty_out(vty, " (passive)");
8397 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8398 vty_out(vty, " (NSF passive)");
8399 }
8400 vty_out(vty, "\n");
8401
8402 /* read timer */
8403 vty_out(vty, " Last read %s",
8404 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8405 NULL));
8406 vty_out(vty, ", Last write %s\n",
8407 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8408 NULL));
8409
8410 /* Configured timer values. */
8411 vty_out(vty,
8412 " Hold time is %d, keepalive interval is %d seconds\n",
8413 p->v_holdtime, p->v_keepalive);
d25e4efc 8414 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8415 vty_out(vty, " Configured hold time is %d",
8416 p->holdtime);
8417 vty_out(vty, ", keepalive interval is %d seconds\n",
8418 p->keepalive);
d25e4efc
DS
8419 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8420 || (bgp->default_keepalive !=
8421 BGP_DEFAULT_KEEPALIVE)) {
8422 vty_out(vty, " Configured hold time is %d",
8423 bgp->default_holdtime);
8424 vty_out(vty, ", keepalive interval is %d seconds\n",
8425 bgp->default_keepalive);
d62a17ae 8426 }
8427 }
8428 /* Capability. */
8429 if (p->status == Established) {
8430 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8431 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8432 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8433 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8434 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8435 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8436 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8437 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8438 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8439 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8440 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8441 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8442 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8443 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8444 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8445 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8446 if (use_json) {
8447 json_object *json_cap = NULL;
8448
8449 json_cap = json_object_new_object();
8450
8451 /* AS4 */
8452 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8453 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8454 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8455 && CHECK_FLAG(p->cap,
8456 PEER_CAP_AS4_RCV))
8457 json_object_string_add(
8458 json_cap, "4byteAs",
8459 "advertisedAndReceived");
8460 else if (CHECK_FLAG(p->cap,
8461 PEER_CAP_AS4_ADV))
8462 json_object_string_add(
8463 json_cap, "4byteAs",
8464 "advertised");
8465 else if (CHECK_FLAG(p->cap,
8466 PEER_CAP_AS4_RCV))
8467 json_object_string_add(
8468 json_cap, "4byteAs",
8469 "received");
8470 }
8471
8472 /* AddPath */
8473 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8474 || CHECK_FLAG(p->cap,
8475 PEER_CAP_ADDPATH_ADV)) {
8476 json_object *json_add = NULL;
8477 const char *print_store;
8478
8479 json_add = json_object_new_object();
8480
05c7a1cc
QY
8481 FOREACH_AFI_SAFI (afi, safi) {
8482 json_object *json_sub = NULL;
8483 json_sub =
8484 json_object_new_object();
8485 print_store = afi_safi_print(
8486 afi, safi);
d62a17ae 8487
05c7a1cc
QY
8488 if (CHECK_FLAG(
8489 p->af_cap[afi]
8490 [safi],
8491 PEER_CAP_ADDPATH_AF_TX_ADV)
8492 || CHECK_FLAG(
8493 p->af_cap[afi]
8494 [safi],
8495 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 8496 if (CHECK_FLAG(
8497 p->af_cap
8498 [afi]
8499 [safi],
8500 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 8501 && CHECK_FLAG(
d62a17ae 8502 p->af_cap
8503 [afi]
8504 [safi],
05c7a1cc
QY
8505 PEER_CAP_ADDPATH_AF_TX_RCV))
8506 json_object_boolean_true_add(
8507 json_sub,
8508 "txAdvertisedAndReceived");
8509 else if (
8510 CHECK_FLAG(
8511 p->af_cap
8512 [afi]
8513 [safi],
8514 PEER_CAP_ADDPATH_AF_TX_ADV))
8515 json_object_boolean_true_add(
8516 json_sub,
8517 "txAdvertised");
8518 else if (
8519 CHECK_FLAG(
8520 p->af_cap
8521 [afi]
8522 [safi],
8523 PEER_CAP_ADDPATH_AF_TX_RCV))
8524 json_object_boolean_true_add(
8525 json_sub,
8526 "txReceived");
8527 }
d62a17ae 8528
05c7a1cc
QY
8529 if (CHECK_FLAG(
8530 p->af_cap[afi]
8531 [safi],
8532 PEER_CAP_ADDPATH_AF_RX_ADV)
8533 || CHECK_FLAG(
8534 p->af_cap[afi]
8535 [safi],
8536 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 8537 if (CHECK_FLAG(
8538 p->af_cap
8539 [afi]
8540 [safi],
8541 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 8542 && CHECK_FLAG(
d62a17ae 8543 p->af_cap
8544 [afi]
8545 [safi],
8546 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
8547 json_object_boolean_true_add(
8548 json_sub,
8549 "rxAdvertisedAndReceived");
8550 else if (
8551 CHECK_FLAG(
8552 p->af_cap
8553 [afi]
8554 [safi],
8555 PEER_CAP_ADDPATH_AF_RX_ADV))
8556 json_object_boolean_true_add(
8557 json_sub,
8558 "rxAdvertised");
8559 else if (
8560 CHECK_FLAG(
8561 p->af_cap
8562 [afi]
8563 [safi],
8564 PEER_CAP_ADDPATH_AF_RX_RCV))
8565 json_object_boolean_true_add(
8566 json_sub,
8567 "rxReceived");
d62a17ae 8568 }
8569
05c7a1cc
QY
8570 if (CHECK_FLAG(
8571 p->af_cap[afi]
8572 [safi],
8573 PEER_CAP_ADDPATH_AF_TX_ADV)
8574 || CHECK_FLAG(
8575 p->af_cap[afi]
8576 [safi],
8577 PEER_CAP_ADDPATH_AF_TX_RCV)
8578 || CHECK_FLAG(
8579 p->af_cap[afi]
8580 [safi],
8581 PEER_CAP_ADDPATH_AF_RX_ADV)
8582 || CHECK_FLAG(
8583 p->af_cap[afi]
8584 [safi],
8585 PEER_CAP_ADDPATH_AF_RX_RCV))
8586 json_object_object_add(
8587 json_add,
8588 print_store,
8589 json_sub);
8590 else
8591 json_object_free(
8592 json_sub);
8593 }
8594
d62a17ae 8595 json_object_object_add(
8596 json_cap, "addPath", json_add);
8597 }
8598
8599 /* Dynamic */
8600 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8601 || CHECK_FLAG(p->cap,
8602 PEER_CAP_DYNAMIC_ADV)) {
8603 if (CHECK_FLAG(p->cap,
8604 PEER_CAP_DYNAMIC_ADV)
8605 && CHECK_FLAG(p->cap,
8606 PEER_CAP_DYNAMIC_RCV))
8607 json_object_string_add(
8608 json_cap, "dynamic",
8609 "advertisedAndReceived");
8610 else if (CHECK_FLAG(
8611 p->cap,
8612 PEER_CAP_DYNAMIC_ADV))
8613 json_object_string_add(
8614 json_cap, "dynamic",
8615 "advertised");
8616 else if (CHECK_FLAG(
8617 p->cap,
8618 PEER_CAP_DYNAMIC_RCV))
8619 json_object_string_add(
8620 json_cap, "dynamic",
8621 "received");
8622 }
8623
8624 /* Extended nexthop */
8625 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8626 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8627 json_object *json_nxt = NULL;
8628 const char *print_store;
8629
8630
8631 if (CHECK_FLAG(p->cap,
8632 PEER_CAP_ENHE_ADV)
8633 && CHECK_FLAG(p->cap,
8634 PEER_CAP_ENHE_RCV))
8635 json_object_string_add(
8636 json_cap,
8637 "extendedNexthop",
8638 "advertisedAndReceived");
8639 else if (CHECK_FLAG(p->cap,
8640 PEER_CAP_ENHE_ADV))
8641 json_object_string_add(
8642 json_cap,
8643 "extendedNexthop",
8644 "advertised");
8645 else if (CHECK_FLAG(p->cap,
8646 PEER_CAP_ENHE_RCV))
8647 json_object_string_add(
8648 json_cap,
8649 "extendedNexthop",
8650 "received");
8651
8652 if (CHECK_FLAG(p->cap,
8653 PEER_CAP_ENHE_RCV)) {
8654 json_nxt =
8655 json_object_new_object();
8656
8657 for (safi = SAFI_UNICAST;
8658 safi < SAFI_MAX; safi++) {
8659 if (CHECK_FLAG(
8660 p->af_cap
8661 [AFI_IP]
8662 [safi],
8663 PEER_CAP_ENHE_AF_RCV)) {
8664 print_store = afi_safi_print(
8665 AFI_IP,
8666 safi);
8667 json_object_string_add(
8668 json_nxt,
8669 print_store,
8670 "recieved");
8671 }
8672 }
8673 json_object_object_add(
8674 json_cap,
8675 "extendedNexthopFamililesByPeer",
8676 json_nxt);
8677 }
8678 }
8679
8680 /* Route Refresh */
8681 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8682 || CHECK_FLAG(p->cap,
8683 PEER_CAP_REFRESH_NEW_RCV)
8684 || CHECK_FLAG(p->cap,
8685 PEER_CAP_REFRESH_OLD_RCV)) {
8686 if (CHECK_FLAG(p->cap,
8687 PEER_CAP_REFRESH_ADV)
8688 && (CHECK_FLAG(
8689 p->cap,
8690 PEER_CAP_REFRESH_NEW_RCV)
8691 || CHECK_FLAG(
8692 p->cap,
8693 PEER_CAP_REFRESH_OLD_RCV))) {
8694 if (CHECK_FLAG(
8695 p->cap,
8696 PEER_CAP_REFRESH_OLD_RCV)
8697 && CHECK_FLAG(
8698 p->cap,
8699 PEER_CAP_REFRESH_NEW_RCV))
8700 json_object_string_add(
8701 json_cap,
8702 "routeRefresh",
8703 "advertisedAndReceivedOldNew");
8704 else {
8705 if (CHECK_FLAG(
8706 p->cap,
8707 PEER_CAP_REFRESH_OLD_RCV))
8708 json_object_string_add(
8709 json_cap,
8710 "routeRefresh",
8711 "advertisedAndReceivedOld");
8712 else
8713 json_object_string_add(
8714 json_cap,
8715 "routeRefresh",
8716 "advertisedAndReceivedNew");
8717 }
8718 } else if (
8719 CHECK_FLAG(
8720 p->cap,
8721 PEER_CAP_REFRESH_ADV))
8722 json_object_string_add(
8723 json_cap,
8724 "routeRefresh",
8725 "advertised");
8726 else if (
8727 CHECK_FLAG(
8728 p->cap,
8729 PEER_CAP_REFRESH_NEW_RCV)
8730 || CHECK_FLAG(
8731 p->cap,
8732 PEER_CAP_REFRESH_OLD_RCV))
8733 json_object_string_add(
8734 json_cap,
8735 "routeRefresh",
8736 "received");
8737 }
8738
8739 /* Multiprotocol Extensions */
8740 json_object *json_multi = NULL;
8741 json_multi = json_object_new_object();
8742
05c7a1cc
QY
8743 FOREACH_AFI_SAFI (afi, safi) {
8744 if (p->afc_adv[afi][safi]
8745 || p->afc_recv[afi][safi]) {
8746 json_object *json_exten = NULL;
8747 json_exten =
8748 json_object_new_object();
8749
d62a17ae 8750 if (p->afc_adv[afi][safi]
05c7a1cc
QY
8751 && p->afc_recv[afi][safi])
8752 json_object_boolean_true_add(
8753 json_exten,
8754 "advertisedAndReceived");
8755 else if (p->afc_adv[afi][safi])
8756 json_object_boolean_true_add(
8757 json_exten,
8758 "advertised");
8759 else if (p->afc_recv[afi][safi])
8760 json_object_boolean_true_add(
8761 json_exten,
8762 "received");
d62a17ae 8763
05c7a1cc
QY
8764 json_object_object_add(
8765 json_multi,
8766 afi_safi_print(afi,
8767 safi),
8768 json_exten);
d62a17ae 8769 }
8770 }
8771 json_object_object_add(
8772 json_cap, "multiprotocolExtensions",
8773 json_multi);
8774
d77114b7 8775 /* Hostname capabilities */
60466a63 8776 json_object *json_hname = NULL;
d77114b7
MK
8777
8778 json_hname = json_object_new_object();
8779
8780 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8781 json_object_string_add(
60466a63
QY
8782 json_hname, "advHostName",
8783 bgp->peer_self->hostname
8784 ? bgp->peer_self
8785 ->hostname
d77114b7
MK
8786 : "n/a");
8787 json_object_string_add(
60466a63
QY
8788 json_hname, "advDomainName",
8789 bgp->peer_self->domainname
8790 ? bgp->peer_self
8791 ->domainname
d77114b7
MK
8792 : "n/a");
8793 }
8794
8795
8796 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8797 json_object_string_add(
60466a63
QY
8798 json_hname, "rcvHostName",
8799 p->hostname ? p->hostname
8800 : "n/a");
d77114b7 8801 json_object_string_add(
60466a63
QY
8802 json_hname, "rcvDomainName",
8803 p->domainname ? p->domainname
8804 : "n/a");
d77114b7
MK
8805 }
8806
60466a63 8807 json_object_object_add(json_cap, "hostName",
d77114b7
MK
8808 json_hname);
8809
d62a17ae 8810 /* Gracefull Restart */
8811 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8812 || CHECK_FLAG(p->cap,
8813 PEER_CAP_RESTART_ADV)) {
8814 if (CHECK_FLAG(p->cap,
8815 PEER_CAP_RESTART_ADV)
8816 && CHECK_FLAG(p->cap,
8817 PEER_CAP_RESTART_RCV))
8818 json_object_string_add(
8819 json_cap,
8820 "gracefulRestart",
8821 "advertisedAndReceived");
8822 else if (CHECK_FLAG(
8823 p->cap,
8824 PEER_CAP_RESTART_ADV))
8825 json_object_string_add(
8826 json_cap,
8827 "gracefulRestartCapability",
8828 "advertised");
8829 else if (CHECK_FLAG(
8830 p->cap,
8831 PEER_CAP_RESTART_RCV))
8832 json_object_string_add(
8833 json_cap,
8834 "gracefulRestartCapability",
8835 "received");
8836
8837 if (CHECK_FLAG(p->cap,
8838 PEER_CAP_RESTART_RCV)) {
8839 int restart_af_count = 0;
8840 json_object *json_restart =
8841 NULL;
8842 json_restart =
8843 json_object_new_object();
8844
8845 json_object_int_add(
8846 json_cap,
8847 "gracefulRestartRemoteTimerMsecs",
8848 p->v_gr_restart * 1000);
8849
05c7a1cc
QY
8850 FOREACH_AFI_SAFI (afi, safi) {
8851 if (CHECK_FLAG(
8852 p->af_cap
8853 [afi]
8854 [safi],
8855 PEER_CAP_RESTART_AF_RCV)) {
8856 json_object *
8857 json_sub =
8858 NULL;
8859 json_sub =
8860 json_object_new_object();
8861
d62a17ae 8862 if (CHECK_FLAG(
8863 p->af_cap
8864 [afi]
8865 [safi],
05c7a1cc
QY
8866 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8867 json_object_boolean_true_add(
8868 json_sub,
8869 "preserved");
8870 restart_af_count++;
8871 json_object_object_add(
8872 json_restart,
8873 afi_safi_print(
8874 afi,
8875 safi),
8876 json_sub);
d62a17ae 8877 }
8878 }
8879 if (!restart_af_count) {
8880 json_object_string_add(
8881 json_cap,
8882 "addressFamiliesByPeer",
8883 "none");
8884 json_object_free(
8885 json_restart);
8886 } else
8887 json_object_object_add(
8888 json_cap,
8889 "addressFamiliesByPeer",
8890 json_restart);
8891 }
8892 }
8893 json_object_object_add(json_neigh,
8894 "neighborCapabilities",
8895 json_cap);
8896 } else {
8897 vty_out(vty, " Neighbor capabilities:\n");
8898
8899 /* AS4 */
8900 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8901 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8902 vty_out(vty, " 4 Byte AS:");
8903 if (CHECK_FLAG(p->cap,
8904 PEER_CAP_AS4_ADV))
8905 vty_out(vty, " advertised");
8906 if (CHECK_FLAG(p->cap,
8907 PEER_CAP_AS4_RCV))
8908 vty_out(vty, " %sreceived",
8909 CHECK_FLAG(
8910 p->cap,
8911 PEER_CAP_AS4_ADV)
8912 ? "and "
8913 : "");
8914 vty_out(vty, "\n");
8915 }
8916
8917 /* AddPath */
8918 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8919 || CHECK_FLAG(p->cap,
8920 PEER_CAP_ADDPATH_ADV)) {
8921 vty_out(vty, " AddPath:\n");
8922
05c7a1cc
QY
8923 FOREACH_AFI_SAFI (afi, safi) {
8924 if (CHECK_FLAG(
8925 p->af_cap[afi]
8926 [safi],
8927 PEER_CAP_ADDPATH_AF_TX_ADV)
8928 || CHECK_FLAG(
8929 p->af_cap[afi]
8930 [safi],
8931 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8932 vty_out(vty,
8933 " %s: TX ",
8934 afi_safi_print(
8935 afi,
8936 safi));
8937
d62a17ae 8938 if (CHECK_FLAG(
8939 p->af_cap
8940 [afi]
8941 [safi],
05c7a1cc 8942 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 8943 vty_out(vty,
05c7a1cc 8944 "advertised %s",
d62a17ae 8945 afi_safi_print(
8946 afi,
8947 safi));
8948
05c7a1cc
QY
8949 if (CHECK_FLAG(
8950 p->af_cap
8951 [afi]
8952 [safi],
8953 PEER_CAP_ADDPATH_AF_TX_RCV))
8954 vty_out(vty,
8955 "%sreceived",
8956 CHECK_FLAG(
8957 p->af_cap
8958 [afi]
8959 [safi],
8960 PEER_CAP_ADDPATH_AF_TX_ADV)
8961 ? " and "
8962 : "");
d62a17ae 8963
05c7a1cc
QY
8964 vty_out(vty, "\n");
8965 }
d62a17ae 8966
05c7a1cc
QY
8967 if (CHECK_FLAG(
8968 p->af_cap[afi]
8969 [safi],
8970 PEER_CAP_ADDPATH_AF_RX_ADV)
8971 || CHECK_FLAG(
8972 p->af_cap[afi]
8973 [safi],
8974 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8975 vty_out(vty,
8976 " %s: RX ",
8977 afi_safi_print(
8978 afi,
8979 safi));
d62a17ae 8980
8981 if (CHECK_FLAG(
8982 p->af_cap
8983 [afi]
8984 [safi],
05c7a1cc 8985 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 8986 vty_out(vty,
05c7a1cc 8987 "advertised %s",
d62a17ae 8988 afi_safi_print(
8989 afi,
8990 safi));
8991
05c7a1cc
QY
8992 if (CHECK_FLAG(
8993 p->af_cap
8994 [afi]
8995 [safi],
8996 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 8997 vty_out(vty,
05c7a1cc
QY
8998 "%sreceived",
8999 CHECK_FLAG(
9000 p->af_cap
9001 [afi]
9002 [safi],
9003 PEER_CAP_ADDPATH_AF_RX_ADV)
9004 ? " and "
9005 : "");
9006
9007 vty_out(vty, "\n");
d62a17ae 9008 }
05c7a1cc 9009 }
d62a17ae 9010 }
9011
9012 /* Dynamic */
9013 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9014 || CHECK_FLAG(p->cap,
9015 PEER_CAP_DYNAMIC_ADV)) {
9016 vty_out(vty, " Dynamic:");
9017 if (CHECK_FLAG(p->cap,
9018 PEER_CAP_DYNAMIC_ADV))
9019 vty_out(vty, " advertised");
9020 if (CHECK_FLAG(p->cap,
9021 PEER_CAP_DYNAMIC_RCV))
9022 vty_out(vty, " %sreceived",
9023 CHECK_FLAG(
9024 p->cap,
9025 PEER_CAP_DYNAMIC_ADV)
9026 ? "and "
9027 : "");
9028 vty_out(vty, "\n");
9029 }
9030
9031 /* Extended nexthop */
9032 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9033 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9034 vty_out(vty, " Extended nexthop:");
9035 if (CHECK_FLAG(p->cap,
9036 PEER_CAP_ENHE_ADV))
9037 vty_out(vty, " advertised");
9038 if (CHECK_FLAG(p->cap,
9039 PEER_CAP_ENHE_RCV))
9040 vty_out(vty, " %sreceived",
9041 CHECK_FLAG(
9042 p->cap,
9043 PEER_CAP_ENHE_ADV)
9044 ? "and "
9045 : "");
9046 vty_out(vty, "\n");
9047
9048 if (CHECK_FLAG(p->cap,
9049 PEER_CAP_ENHE_RCV)) {
9050 vty_out(vty,
9051 " Address families by peer:\n ");
9052 for (safi = SAFI_UNICAST;
9053 safi < SAFI_MAX; safi++)
9054 if (CHECK_FLAG(
9055 p->af_cap
9056 [AFI_IP]
9057 [safi],
9058 PEER_CAP_ENHE_AF_RCV))
9059 vty_out(vty,
9060 " %s\n",
9061 afi_safi_print(
9062 AFI_IP,
9063 safi));
9064 }
9065 }
9066
9067 /* Route Refresh */
9068 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9069 || CHECK_FLAG(p->cap,
9070 PEER_CAP_REFRESH_NEW_RCV)
9071 || CHECK_FLAG(p->cap,
9072 PEER_CAP_REFRESH_OLD_RCV)) {
9073 vty_out(vty, " Route refresh:");
9074 if (CHECK_FLAG(p->cap,
9075 PEER_CAP_REFRESH_ADV))
9076 vty_out(vty, " advertised");
9077 if (CHECK_FLAG(p->cap,
9078 PEER_CAP_REFRESH_NEW_RCV)
9079 || CHECK_FLAG(
9080 p->cap,
9081 PEER_CAP_REFRESH_OLD_RCV))
9082 vty_out(vty, " %sreceived(%s)",
9083 CHECK_FLAG(
9084 p->cap,
9085 PEER_CAP_REFRESH_ADV)
9086 ? "and "
9087 : "",
9088 (CHECK_FLAG(
9089 p->cap,
9090 PEER_CAP_REFRESH_OLD_RCV)
9091 && CHECK_FLAG(
9092 p->cap,
9093 PEER_CAP_REFRESH_NEW_RCV))
9094 ? "old & new"
9095 : CHECK_FLAG(
9096 p->cap,
9097 PEER_CAP_REFRESH_OLD_RCV)
9098 ? "old"
9099 : "new");
9100
9101 vty_out(vty, "\n");
9102 }
9103
9104 /* Multiprotocol Extensions */
05c7a1cc
QY
9105 FOREACH_AFI_SAFI (afi, safi)
9106 if (p->afc_adv[afi][safi]
9107 || p->afc_recv[afi][safi]) {
9108 vty_out(vty,
9109 " Address Family %s:",
9110 afi_safi_print(afi,
9111 safi));
9112 if (p->afc_adv[afi][safi])
d62a17ae 9113 vty_out(vty,
05c7a1cc
QY
9114 " advertised");
9115 if (p->afc_recv[afi][safi])
9116 vty_out(vty,
9117 " %sreceived",
9118 p->afc_adv[afi]
9119 [safi]
9120 ? "and "
9121 : "");
9122 vty_out(vty, "\n");
9123 }
d62a17ae 9124
9125 /* Hostname capability */
60466a63 9126 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9127
9128 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9129 vty_out(vty,
9130 " advertised (name: %s,domain name: %s)",
60466a63
QY
9131 bgp->peer_self->hostname
9132 ? bgp->peer_self
9133 ->hostname
d77114b7 9134 : "n/a",
60466a63
QY
9135 bgp->peer_self->domainname
9136 ? bgp->peer_self
9137 ->domainname
d77114b7
MK
9138 : "n/a");
9139 } else {
9140 vty_out(vty, " not advertised");
d62a17ae 9141 }
9142
d77114b7 9143 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9144 vty_out(vty,
9145 " received (name: %s,domain name: %s)",
60466a63
QY
9146 p->hostname ? p->hostname
9147 : "n/a",
9148 p->domainname ? p->domainname
9149 : "n/a");
d77114b7
MK
9150 } else {
9151 vty_out(vty, " not received");
9152 }
9153
9154 vty_out(vty, "\n");
9155
d62a17ae 9156 /* Gracefull Restart */
9157 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9158 || CHECK_FLAG(p->cap,
9159 PEER_CAP_RESTART_ADV)) {
9160 vty_out(vty,
9161 " Graceful Restart Capabilty:");
9162 if (CHECK_FLAG(p->cap,
9163 PEER_CAP_RESTART_ADV))
9164 vty_out(vty, " advertised");
9165 if (CHECK_FLAG(p->cap,
9166 PEER_CAP_RESTART_RCV))
9167 vty_out(vty, " %sreceived",
9168 CHECK_FLAG(
9169 p->cap,
9170 PEER_CAP_RESTART_ADV)
9171 ? "and "
9172 : "");
9173 vty_out(vty, "\n");
9174
9175 if (CHECK_FLAG(p->cap,
9176 PEER_CAP_RESTART_RCV)) {
9177 int restart_af_count = 0;
9178
9179 vty_out(vty,
9180 " Remote Restart timer is %d seconds\n",
9181 p->v_gr_restart);
9182 vty_out(vty,
9183 " Address families by peer:\n ");
9184
05c7a1cc
QY
9185 FOREACH_AFI_SAFI (afi, safi)
9186 if (CHECK_FLAG(
9187 p->af_cap
9188 [afi]
9189 [safi],
9190 PEER_CAP_RESTART_AF_RCV)) {
9191 vty_out(vty,
9192 "%s%s(%s)",
9193 restart_af_count
9194 ? ", "
9195 : "",
9196 afi_safi_print(
9197 afi,
9198 safi),
9199 CHECK_FLAG(
9200 p->af_cap
9201 [afi]
9202 [safi],
9203 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9204 ? "preserved"
9205 : "not preserved");
9206 restart_af_count++;
9207 }
d62a17ae 9208 if (!restart_af_count)
9209 vty_out(vty, "none");
9210 vty_out(vty, "\n");
9211 }
9212 }
9213 }
9214 }
9215 }
9216
9217 /* graceful restart information */
9218 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9219 || p->t_gr_stale) {
9220 json_object *json_grace = NULL;
9221 json_object *json_grace_send = NULL;
9222 json_object *json_grace_recv = NULL;
9223 int eor_send_af_count = 0;
9224 int eor_receive_af_count = 0;
9225
9226 if (use_json) {
9227 json_grace = json_object_new_object();
9228 json_grace_send = json_object_new_object();
9229 json_grace_recv = json_object_new_object();
9230
9231 if (p->status == Established) {
05c7a1cc
QY
9232 FOREACH_AFI_SAFI (afi, safi) {
9233 if (CHECK_FLAG(p->af_sflags[afi][safi],
9234 PEER_STATUS_EOR_SEND)) {
9235 json_object_boolean_true_add(
9236 json_grace_send,
9237 afi_safi_print(afi,
9238 safi));
9239 eor_send_af_count++;
d62a17ae 9240 }
9241 }
05c7a1cc
QY
9242 FOREACH_AFI_SAFI (afi, safi) {
9243 if (CHECK_FLAG(
9244 p->af_sflags[afi][safi],
9245 PEER_STATUS_EOR_RECEIVED)) {
9246 json_object_boolean_true_add(
9247 json_grace_recv,
9248 afi_safi_print(afi,
9249 safi));
9250 eor_receive_af_count++;
d62a17ae 9251 }
9252 }
9253 }
9254
9255 json_object_object_add(json_grace, "endOfRibSend",
9256 json_grace_send);
9257 json_object_object_add(json_grace, "endOfRibRecv",
9258 json_grace_recv);
9259
9260 if (p->t_gr_restart)
9261 json_object_int_add(json_grace,
9262 "gracefulRestartTimerMsecs",
9263 thread_timer_remain_second(
9264 p->t_gr_restart)
9265 * 1000);
9266
9267 if (p->t_gr_stale)
9268 json_object_int_add(
9269 json_grace,
9270 "gracefulStalepathTimerMsecs",
9271 thread_timer_remain_second(
9272 p->t_gr_stale)
9273 * 1000);
9274
9275 json_object_object_add(
9276 json_neigh, "gracefulRestartInfo", json_grace);
9277 } else {
9278 vty_out(vty, " Graceful restart informations:\n");
9279 if (p->status == Established) {
9280 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
9281 FOREACH_AFI_SAFI (afi, safi) {
9282 if (CHECK_FLAG(p->af_sflags[afi][safi],
9283 PEER_STATUS_EOR_SEND)) {
9284 vty_out(vty, "%s%s",
9285 eor_send_af_count ? ", "
9286 : "",
9287 afi_safi_print(afi,
9288 safi));
9289 eor_send_af_count++;
d62a17ae 9290 }
9291 }
9292 vty_out(vty, "\n");
9293 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
9294 FOREACH_AFI_SAFI (afi, safi) {
9295 if (CHECK_FLAG(
9296 p->af_sflags[afi][safi],
9297 PEER_STATUS_EOR_RECEIVED)) {
9298 vty_out(vty, "%s%s",
9299 eor_receive_af_count
9300 ? ", "
9301 : "",
9302 afi_safi_print(afi,
9303 safi));
9304 eor_receive_af_count++;
d62a17ae 9305 }
9306 }
9307 vty_out(vty, "\n");
9308 }
9309
9310 if (p->t_gr_restart)
9311 vty_out(vty,
9312 " The remaining time of restart timer is %ld\n",
9313 thread_timer_remain_second(
9314 p->t_gr_restart));
9315
9316 if (p->t_gr_stale)
9317 vty_out(vty,
9318 " The remaining time of stalepath timer is %ld\n",
9319 thread_timer_remain_second(
9320 p->t_gr_stale));
9321 }
9322 }
9323 if (use_json) {
9324 json_object *json_stat = NULL;
9325 json_stat = json_object_new_object();
9326 /* Packet counts. */
9327 json_object_int_add(json_stat, "depthInq", 0);
9328 json_object_int_add(json_stat, "depthOutq",
9329 (unsigned long)p->obuf->count);
9330 json_object_int_add(json_stat, "opensSent", p->open_out);
9331 json_object_int_add(json_stat, "opensRecv", p->open_in);
9332 json_object_int_add(json_stat, "notificationsSent",
9333 p->notify_out);
9334 json_object_int_add(json_stat, "notificationsRecv",
9335 p->notify_in);
9336 json_object_int_add(json_stat, "updatesSent", p->update_out);
9337 json_object_int_add(json_stat, "updatesRecv", p->update_in);
9338 json_object_int_add(json_stat, "keepalivesSent",
9339 p->keepalive_out);
9340 json_object_int_add(json_stat, "keepalivesRecv",
9341 p->keepalive_in);
9342 json_object_int_add(json_stat, "routeRefreshSent",
9343 p->refresh_out);
9344 json_object_int_add(json_stat, "routeRefreshRecv",
9345 p->refresh_in);
9346 json_object_int_add(json_stat, "capabilitySent",
9347 p->dynamic_cap_out);
9348 json_object_int_add(json_stat, "capabilityRecv",
9349 p->dynamic_cap_in);
9350 json_object_int_add(json_stat, "totalSent",
9351 p->open_out + p->notify_out + p->update_out
9352 + p->keepalive_out + p->refresh_out
9353 + p->dynamic_cap_out);
9354 json_object_int_add(json_stat, "totalRecv",
9355 p->open_in + p->notify_in + p->update_in
9356 + p->keepalive_in + p->refresh_in
9357 + p->dynamic_cap_in);
9358 json_object_object_add(json_neigh, "messageStats", json_stat);
9359 } else {
9360 /* Packet counts. */
9361 vty_out(vty, " Message statistics:\n");
9362 vty_out(vty, " Inq depth is 0\n");
9363 vty_out(vty, " Outq depth is %lu\n",
9364 (unsigned long)p->obuf->count);
9365 vty_out(vty, " Sent Rcvd\n");
9366 vty_out(vty, " Opens: %10d %10d\n", p->open_out,
9367 p->open_in);
9368 vty_out(vty, " Notifications: %10d %10d\n", p->notify_out,
9369 p->notify_in);
9370 vty_out(vty, " Updates: %10d %10d\n", p->update_out,
9371 p->update_in);
9372 vty_out(vty, " Keepalives: %10d %10d\n", p->keepalive_out,
9373 p->keepalive_in);
9374 vty_out(vty, " Route Refresh: %10d %10d\n", p->refresh_out,
9375 p->refresh_in);
9376 vty_out(vty, " Capability: %10d %10d\n",
9377 p->dynamic_cap_out, p->dynamic_cap_in);
9378 vty_out(vty, " Total: %10d %10d\n",
9379 p->open_out + p->notify_out + p->update_out
9380 + p->keepalive_out + p->refresh_out
9381 + p->dynamic_cap_out,
9382 p->open_in + p->notify_in + p->update_in
9383 + p->keepalive_in + p->refresh_in
9384 + p->dynamic_cap_in);
9385 }
9386
9387 if (use_json) {
9388 /* advertisement-interval */
9389 json_object_int_add(json_neigh,
9390 "minBtwnAdvertisementRunsTimerMsecs",
9391 p->v_routeadv * 1000);
9392
9393 /* Update-source. */
9394 if (p->update_if || p->update_source) {
9395 if (p->update_if)
9396 json_object_string_add(json_neigh,
9397 "updateSource",
9398 p->update_if);
9399 else if (p->update_source)
9400 json_object_string_add(
9401 json_neigh, "updateSource",
9402 sockunion2str(p->update_source, buf1,
9403 SU_ADDRSTRLEN));
9404 }
9405 } else {
9406 /* advertisement-interval */
9407 vty_out(vty,
9408 " Minimum time between advertisement runs is %d seconds\n",
9409 p->v_routeadv);
9410
9411 /* Update-source. */
9412 if (p->update_if || p->update_source) {
9413 vty_out(vty, " Update source is ");
9414 if (p->update_if)
9415 vty_out(vty, "%s", p->update_if);
9416 else if (p->update_source)
9417 vty_out(vty, "%s",
9418 sockunion2str(p->update_source, buf1,
9419 SU_ADDRSTRLEN));
9420 vty_out(vty, "\n");
9421 }
9422
9423 vty_out(vty, "\n");
9424 }
9425
9426 /* Address Family Information */
9427 json_object *json_hold = NULL;
9428
9429 if (use_json)
9430 json_hold = json_object_new_object();
9431
05c7a1cc
QY
9432 FOREACH_AFI_SAFI (afi, safi)
9433 if (p->afc[afi][safi])
9434 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9435 json_hold);
d62a17ae 9436
9437 if (use_json) {
9438 json_object_object_add(json_neigh, "addressFamilyInfo",
9439 json_hold);
9440 json_object_int_add(json_neigh, "connectionsEstablished",
9441 p->established);
9442 json_object_int_add(json_neigh, "connectionsDropped",
9443 p->dropped);
9444 } else
9445 vty_out(vty, " Connections established %d; dropped %d\n",
9446 p->established, p->dropped);
9447
9448 if (!p->last_reset) {
9449 if (use_json)
9450 json_object_string_add(json_neigh, "lastReset",
9451 "never");
9452 else
9453 vty_out(vty, " Last reset never\n");
9454 } else {
9455 if (use_json) {
9456 time_t uptime;
9457 struct tm *tm;
9458
9459 uptime = bgp_clock();
9460 uptime -= p->resettime;
9461 tm = gmtime(&uptime);
9462 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9463 (tm->tm_sec * 1000)
9464 + (tm->tm_min * 60000)
9465 + (tm->tm_hour * 3600000));
9466 json_object_string_add(
9467 json_neigh, "lastResetDueTo",
9468 peer_down_str[(int)p->last_reset]);
9469 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9470 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9471 char errorcodesubcode_hexstr[5];
9472 char errorcodesubcode_str[256];
9473
9474 code_str = bgp_notify_code_str(p->notify.code);
9475 subcode_str = bgp_notify_subcode_str(
9476 p->notify.code, p->notify.subcode);
9477
9478 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9479 p->notify.code, p->notify.subcode);
9480 json_object_string_add(json_neigh,
9481 "lastErrorCodeSubcode",
9482 errorcodesubcode_hexstr);
9483 snprintf(errorcodesubcode_str, 255, "%s%s",
9484 code_str, subcode_str);
9485 json_object_string_add(json_neigh,
9486 "lastNotificationReason",
9487 errorcodesubcode_str);
9488 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9489 && p->notify.code == BGP_NOTIFY_CEASE
9490 && (p->notify.subcode
9491 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9492 || p->notify.subcode
9493 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9494 && p->notify.length) {
9495 char msgbuf[1024];
9496 const char *msg_str;
9497
9498 msg_str = bgp_notify_admin_message(
9499 msgbuf, sizeof(msgbuf),
9500 (u_char *)p->notify.data,
9501 p->notify.length);
9502 if (msg_str)
9503 json_object_string_add(
9504 json_neigh,
9505 "lastShutdownDescription",
9506 msg_str);
9507 }
9508 }
9509 } else {
9510 vty_out(vty, " Last reset %s, ",
9511 peer_uptime(p->resettime, timebuf,
9512 BGP_UPTIME_LEN, 0, NULL));
9513
9514 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9515 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9516 code_str = bgp_notify_code_str(p->notify.code);
9517 subcode_str = bgp_notify_subcode_str(
9518 p->notify.code, p->notify.subcode);
9519 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9520 p->last_reset == PEER_DOWN_NOTIFY_SEND
9521 ? "sent"
9522 : "received",
9523 code_str, subcode_str);
9524 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9525 && p->notify.code == BGP_NOTIFY_CEASE
9526 && (p->notify.subcode
9527 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9528 || p->notify.subcode
9529 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9530 && p->notify.length) {
9531 char msgbuf[1024];
9532 const char *msg_str;
9533
9534 msg_str = bgp_notify_admin_message(
9535 msgbuf, sizeof(msgbuf),
9536 (u_char *)p->notify.data,
9537 p->notify.length);
9538 if (msg_str)
9539 vty_out(vty,
9540 " Message: \"%s\"\n",
9541 msg_str);
9542 }
9543 } else {
9544 vty_out(vty, "due to %s\n",
9545 peer_down_str[(int)p->last_reset]);
9546 }
9547
9548 if (p->last_reset_cause_size) {
9549 msg = p->last_reset_cause;
9550 vty_out(vty,
9551 " Message received that caused BGP to send a NOTIFICATION:\n ");
9552 for (i = 1; i <= p->last_reset_cause_size;
9553 i++) {
9554 vty_out(vty, "%02X", *msg++);
9555
9556 if (i != p->last_reset_cause_size) {
9557 if (i % 16 == 0) {
9558 vty_out(vty, "\n ");
9559 } else if (i % 4 == 0) {
9560 vty_out(vty, " ");
9561 }
9562 }
9563 }
9564 vty_out(vty, "\n");
9565 }
9566 }
9567 }
9568
9569 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9570 if (use_json)
9571 json_object_boolean_true_add(json_neigh,
9572 "prefixesConfigExceedMax");
9573 else
9574 vty_out(vty,
9575 " Peer had exceeded the max. no. of prefixes configured.\n");
9576
9577 if (p->t_pmax_restart) {
9578 if (use_json) {
9579 json_object_boolean_true_add(
9580 json_neigh, "reducePrefixNumFrom");
9581 json_object_int_add(json_neigh,
9582 "restartInTimerMsec",
9583 thread_timer_remain_second(
9584 p->t_pmax_restart)
9585 * 1000);
9586 } else
9587 vty_out(vty,
9588 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9d303b37
DL
9589 p->host, thread_timer_remain_second(
9590 p->t_pmax_restart));
d62a17ae 9591 } else {
9592 if (use_json)
9593 json_object_boolean_true_add(
9594 json_neigh,
9595 "reducePrefixNumAndClearIpBgp");
9596 else
9597 vty_out(vty,
9598 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9599 p->host);
9600 }
9601 }
9602
9603 /* EBGP Multihop and GTSM */
9604 if (p->sort != BGP_PEER_IBGP) {
9605 if (use_json) {
9606 if (p->gtsm_hops > 0)
9607 json_object_int_add(json_neigh,
9608 "externalBgpNbrMaxHopsAway",
9609 p->gtsm_hops);
9610 else if (p->ttl > 1)
9611 json_object_int_add(json_neigh,
9612 "externalBgpNbrMaxHopsAway",
9613 p->ttl);
9614 } else {
9615 if (p->gtsm_hops > 0)
9616 vty_out(vty,
9617 " External BGP neighbor may be up to %d hops away.\n",
9618 p->gtsm_hops);
9619 else if (p->ttl > 1)
9620 vty_out(vty,
9621 " External BGP neighbor may be up to %d hops away.\n",
9622 p->ttl);
9623 }
9624 } else {
9625 if (p->gtsm_hops > 0) {
9626 if (use_json)
9627 json_object_int_add(json_neigh,
9628 "internalBgpNbrMaxHopsAway",
9629 p->gtsm_hops);
9630 else
9631 vty_out(vty,
9632 " Internal BGP neighbor may be up to %d hops away.\n",
9633 p->gtsm_hops);
9634 }
9635 }
9636
9637 /* Local address. */
9638 if (p->su_local) {
9639 if (use_json) {
9640 json_object_string_add(json_neigh, "hostLocal",
9641 sockunion2str(p->su_local, buf1,
9642 SU_ADDRSTRLEN));
9643 json_object_int_add(json_neigh, "portLocal",
9644 ntohs(p->su_local->sin.sin_port));
9645 } else
9646 vty_out(vty, "Local host: %s, Local port: %d\n",
9647 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9648 ntohs(p->su_local->sin.sin_port));
9649 }
9650
9651 /* Remote address. */
9652 if (p->su_remote) {
9653 if (use_json) {
9654 json_object_string_add(json_neigh, "hostForeign",
9655 sockunion2str(p->su_remote, buf1,
9656 SU_ADDRSTRLEN));
9657 json_object_int_add(json_neigh, "portForeign",
9658 ntohs(p->su_remote->sin.sin_port));
9659 } else
9660 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9661 sockunion2str(p->su_remote, buf1,
9662 SU_ADDRSTRLEN),
9663 ntohs(p->su_remote->sin.sin_port));
9664 }
9665
9666 /* Nexthop display. */
9667 if (p->su_local) {
9668 if (use_json) {
9669 json_object_string_add(json_neigh, "nexthop",
9670 inet_ntop(AF_INET,
9671 &p->nexthop.v4, buf1,
9672 sizeof(buf1)));
9673 json_object_string_add(json_neigh, "nexthopGlobal",
9674 inet_ntop(AF_INET6,
9675 &p->nexthop.v6_global,
9676 buf1, sizeof(buf1)));
9677 json_object_string_add(json_neigh, "nexthopLocal",
9678 inet_ntop(AF_INET6,
9679 &p->nexthop.v6_local,
9680 buf1, sizeof(buf1)));
9681 if (p->shared_network)
9682 json_object_string_add(json_neigh,
9683 "bgpConnection",
9684 "sharedNetwork");
9685 else
9686 json_object_string_add(json_neigh,
9687 "bgpConnection",
9688 "nonSharedNetwork");
9689 } else {
9690 vty_out(vty, "Nexthop: %s\n",
9691 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9692 sizeof(buf1)));
9693 vty_out(vty, "Nexthop global: %s\n",
9694 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9695 sizeof(buf1)));
9696 vty_out(vty, "Nexthop local: %s\n",
9697 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9698 sizeof(buf1)));
9699 vty_out(vty, "BGP connection: %s\n",
9700 p->shared_network ? "shared network"
9701 : "non shared network");
9702 }
9703 }
9704
9705 /* Timer information. */
9706 if (use_json) {
9707 json_object_int_add(json_neigh, "connectRetryTimer",
9708 p->v_connect);
9709 if (p->status == Established && p->rtt)
9710 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9711 p->rtt);
9712 if (p->t_start)
9713 json_object_int_add(
9714 json_neigh, "nextStartTimerDueInMsecs",
9715 thread_timer_remain_second(p->t_start) * 1000);
9716 if (p->t_connect)
9717 json_object_int_add(
9718 json_neigh, "nextConnectTimerDueInMsecs",
9719 thread_timer_remain_second(p->t_connect)
9720 * 1000);
9721 if (p->t_routeadv) {
9722 json_object_int_add(json_neigh, "mraiInterval",
9723 p->v_routeadv);
9724 json_object_int_add(
9725 json_neigh, "mraiTimerExpireInMsecs",
9726 thread_timer_remain_second(p->t_routeadv)
9727 * 1000);
9728 }
9729 if (p->password)
9730 json_object_int_add(json_neigh, "authenticationEnabled",
9731 1);
9732
9733 if (p->t_read)
9734 json_object_string_add(json_neigh, "readThread", "on");
9735 else
9736 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
9737
9738 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 9739 json_object_string_add(json_neigh, "writeThread", "on");
9740 else
9741 json_object_string_add(json_neigh, "writeThread",
9742 "off");
9743 } else {
9744 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9745 p->v_connect);
9746 if (p->status == Established && p->rtt)
9747 vty_out(vty, "Estimated round trip time: %d ms\n",
9748 p->rtt);
9749 if (p->t_start)
9750 vty_out(vty, "Next start timer due in %ld seconds\n",
9751 thread_timer_remain_second(p->t_start));
9752 if (p->t_connect)
9753 vty_out(vty, "Next connect timer due in %ld seconds\n",
9754 thread_timer_remain_second(p->t_connect));
9755 if (p->t_routeadv)
9756 vty_out(vty,
9757 "MRAI (interval %u) timer expires in %ld seconds\n",
9758 p->v_routeadv,
9759 thread_timer_remain_second(p->t_routeadv));
9760 if (p->password)
9761 vty_out(vty, "Peer Authentication Enabled\n");
9762
9763 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
9764 p->t_read ? "on" : "off",
9765 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
9766 ? "on"
9767 : "off");
d62a17ae 9768 }
9769
9770 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9771 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9772 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9773
9774 if (!use_json)
9775 vty_out(vty, "\n");
9776
9777 /* BFD information. */
9778 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9779
9780 if (use_json) {
9781 if (p->conf_if) /* Configured interface name. */
9782 json_object_object_add(json, p->conf_if, json_neigh);
9783 else /* Configured IP address. */
9784 json_object_object_add(json, p->host, json_neigh);
9785 }
9786}
9787
9788static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9789 enum show_type type, union sockunion *su,
9790 const char *conf_if, u_char use_json,
9791 json_object *json)
9792{
9793 struct listnode *node, *nnode;
9794 struct peer *peer;
9795 int find = 0;
9796
9797 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9798 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9799 continue;
9800
9801 switch (type) {
9802 case show_all:
9803 bgp_show_peer(vty, peer, use_json, json);
9804 break;
9805 case show_peer:
9806 if (conf_if) {
9807 if ((peer->conf_if
9808 && !strcmp(peer->conf_if, conf_if))
9809 || (peer->hostname
9810 && !strcmp(peer->hostname, conf_if))) {
9811 find = 1;
9812 bgp_show_peer(vty, peer, use_json,
9813 json);
9814 }
9815 } else {
9816 if (sockunion_same(&peer->su, su)) {
9817 find = 1;
9818 bgp_show_peer(vty, peer, use_json,
9819 json);
9820 }
9821 }
9822 break;
9823 }
9824 }
9825
9826 if (type == show_peer && !find) {
9827 if (use_json)
9828 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9829 else
9830 vty_out(vty, "%% No such neighbor\n");
9831 }
9832
9833 if (use_json) {
57a9c8a8 9834 bgp_show_bestpath_json(bgp, json);
9d303b37
DL
9835 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9836 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9837 json_object_free(json);
9838 } else {
9839 vty_out(vty, "\n");
9840 }
9841
9842 return CMD_SUCCESS;
9843}
9844
9845static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9846 u_char use_json)
9847{
0291c246
MK
9848 struct listnode *node, *nnode;
9849 struct bgp *bgp;
9850 json_object *json = NULL;
9851 int is_first = 1;
d62a17ae 9852
9853 if (use_json)
9854 vty_out(vty, "{\n");
9855
9856 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9857 if (use_json) {
9858 if (!(json = json_object_new_object())) {
9859 zlog_err(
9860 "Unable to allocate memory for JSON object");
9861 vty_out(vty,
9862 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9863 return;
9864 }
9865
9866 json_object_int_add(json, "vrfId",
9867 (bgp->vrf_id == VRF_UNKNOWN)
9868 ? -1
9869 : bgp->vrf_id);
9870 json_object_string_add(
9871 json, "vrfName",
9872 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9873 ? "Default"
9874 : bgp->name);
9875
9876 if (!is_first)
9877 vty_out(vty, ",\n");
9878 else
9879 is_first = 0;
9880
9881 vty_out(vty, "\"%s\":",
9882 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9883 ? "Default"
9884 : bgp->name);
9885 } else {
9886 vty_out(vty, "\nInstance %s:\n",
9887 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9888 ? "Default"
9889 : bgp->name);
9890 }
9891 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL, use_json,
9892 json);
9893 }
9894
9895 if (use_json)
9896 vty_out(vty, "}\n");
9897}
9898
9899static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9900 enum show_type type, const char *ip_str,
9901 u_char use_json)
9902{
9903 int ret;
9904 struct bgp *bgp;
9905 union sockunion su;
9906 json_object *json = NULL;
9907
9908 if (name) {
9909 if (strmatch(name, "all")) {
9910 bgp_show_all_instances_neighbors_vty(vty, use_json);
9911 return CMD_SUCCESS;
9912 } else {
9913 bgp = bgp_lookup_by_name(name);
9914 if (!bgp) {
9915 if (use_json) {
9916 json = json_object_new_object();
9917 json_object_boolean_true_add(
9918 json, "bgpNoSuchInstance");
9919 vty_out(vty, "%s\n",
9920 json_object_to_json_string_ext(
9921 json,
9922 JSON_C_TO_STRING_PRETTY));
9923 json_object_free(json);
9924 } else
9925 vty_out(vty,
9926 "%% No such BGP instance exist\n");
9927
9928 return CMD_WARNING;
9929 }
9930 }
9931 } else {
9932 bgp = bgp_get_default();
9933 }
9934
9935 if (bgp) {
9936 json = json_object_new_object();
9937 if (ip_str) {
9938 ret = str2sockunion(ip_str, &su);
9939 if (ret < 0)
9940 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9941 use_json, json);
9942 else
9943 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9944 use_json, json);
9945 } else {
9946 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
9947 json);
9948 }
9949 json_object_free(json);
9950 }
9951
9952 return CMD_SUCCESS;
4fb25c53
DW
9953}
9954
716b2d8a 9955/* "show [ip] bgp neighbors" commands. */
718e3744 9956DEFUN (show_ip_bgp_neighbors,
9957 show_ip_bgp_neighbors_cmd,
24345e82 9958 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 9959 SHOW_STR
9960 IP_STR
9961 BGP_STR
f2a8972b 9962 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9963 "Address Family\n"
9964 "Address Family\n"
718e3744 9965 "Detailed information on TCP and BGP neighbor connections\n"
9966 "Neighbor to display information about\n"
a80beece 9967 "Neighbor to display information about\n"
91d37724 9968 "Neighbor on BGP configured interface\n"
9973d184 9969 JSON_STR)
718e3744 9970{
d62a17ae 9971 char *vrf = NULL;
9972 char *sh_arg = NULL;
9973 enum show_type sh_type;
718e3744 9974
d62a17ae 9975 u_char uj = use_json(argc, argv);
718e3744 9976
d62a17ae 9977 int idx = 0;
718e3744 9978
d62a17ae 9979 if (argv_find(argv, argc, "view", &idx)
9980 || argv_find(argv, argc, "vrf", &idx))
9981 vrf = argv[idx + 1]->arg;
718e3744 9982
d62a17ae 9983 idx++;
9984 if (argv_find(argv, argc, "A.B.C.D", &idx)
9985 || argv_find(argv, argc, "X:X::X:X", &idx)
9986 || argv_find(argv, argc, "WORD", &idx)) {
9987 sh_type = show_peer;
9988 sh_arg = argv[idx]->arg;
9989 } else
9990 sh_type = show_all;
856ca177 9991
d62a17ae 9992 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 9993}
9994
716b2d8a 9995/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 9996 paths' and `show ip mbgp paths'. Those functions results are the
9997 same.*/
f412b39a 9998DEFUN (show_ip_bgp_paths,
718e3744 9999 show_ip_bgp_paths_cmd,
46f296b4 10000 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10001 SHOW_STR
10002 IP_STR
10003 BGP_STR
46f296b4 10004 BGP_SAFI_HELP_STR
718e3744 10005 "Path information\n")
10006{
d62a17ae 10007 vty_out(vty, "Address Refcnt Path\n");
10008 aspath_print_all_vty(vty);
10009 return CMD_SUCCESS;
718e3744 10010}
10011
718e3744 10012#include "hash.h"
10013
d62a17ae 10014static void community_show_all_iterator(struct hash_backet *backet,
10015 struct vty *vty)
718e3744 10016{
d62a17ae 10017 struct community *com;
718e3744 10018
d62a17ae 10019 com = (struct community *)backet->data;
3f65c5b1 10020 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10021 community_str(com, false));
718e3744 10022}
10023
10024/* Show BGP's community internal data. */
f412b39a 10025DEFUN (show_ip_bgp_community_info,
718e3744 10026 show_ip_bgp_community_info_cmd,
bec37ba5 10027 "show [ip] bgp community-info",
718e3744 10028 SHOW_STR
10029 IP_STR
10030 BGP_STR
10031 "List all bgp community information\n")
10032{
d62a17ae 10033 vty_out(vty, "Address Refcnt Community\n");
718e3744 10034
d62a17ae 10035 hash_iterate(community_hash(),
10036 (void (*)(struct hash_backet *,
10037 void *))community_show_all_iterator,
10038 vty);
718e3744 10039
d62a17ae 10040 return CMD_SUCCESS;
718e3744 10041}
10042
d62a17ae 10043static void lcommunity_show_all_iterator(struct hash_backet *backet,
10044 struct vty *vty)
57d187bc 10045{
d62a17ae 10046 struct lcommunity *lcom;
57d187bc 10047
d62a17ae 10048 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10049 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10050 lcommunity_str(lcom));
57d187bc
JS
10051}
10052
10053/* Show BGP's community internal data. */
10054DEFUN (show_ip_bgp_lcommunity_info,
10055 show_ip_bgp_lcommunity_info_cmd,
10056 "show ip bgp large-community-info",
10057 SHOW_STR
10058 IP_STR
10059 BGP_STR
10060 "List all bgp large-community information\n")
10061{
d62a17ae 10062 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10063
d62a17ae 10064 hash_iterate(lcommunity_hash(),
10065 (void (*)(struct hash_backet *,
10066 void *))lcommunity_show_all_iterator,
10067 vty);
57d187bc 10068
d62a17ae 10069 return CMD_SUCCESS;
57d187bc
JS
10070}
10071
10072
f412b39a 10073DEFUN (show_ip_bgp_attr_info,
718e3744 10074 show_ip_bgp_attr_info_cmd,
bec37ba5 10075 "show [ip] bgp attribute-info",
718e3744 10076 SHOW_STR
10077 IP_STR
10078 BGP_STR
10079 "List all bgp attribute information\n")
10080{
d62a17ae 10081 attr_show_all(vty);
10082 return CMD_SUCCESS;
718e3744 10083}
6b0655a2 10084
d62a17ae 10085static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10086 safi_t safi)
f186de26 10087{
d62a17ae 10088 struct listnode *node, *nnode;
10089 struct bgp *bgp;
f186de26 10090
d62a17ae 10091 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10092 vty_out(vty, "\nInstance %s:\n",
10093 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10094 ? "Default"
10095 : bgp->name);
10096 update_group_show(bgp, afi, safi, vty, 0);
10097 }
f186de26 10098}
10099
d62a17ae 10100static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10101 int safi, uint64_t subgrp_id)
4fb25c53 10102{
d62a17ae 10103 struct bgp *bgp;
4fb25c53 10104
d62a17ae 10105 if (name) {
10106 if (strmatch(name, "all")) {
10107 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10108 return CMD_SUCCESS;
10109 } else {
10110 bgp = bgp_lookup_by_name(name);
10111 }
10112 } else {
10113 bgp = bgp_get_default();
10114 }
4fb25c53 10115
d62a17ae 10116 if (bgp)
10117 update_group_show(bgp, afi, safi, vty, subgrp_id);
10118 return CMD_SUCCESS;
4fb25c53
DW
10119}
10120
8fe8a7f6
DS
10121DEFUN (show_ip_bgp_updgrps,
10122 show_ip_bgp_updgrps_cmd,
c1a44e43 10123 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10124 SHOW_STR
10125 IP_STR
10126 BGP_STR
10127 BGP_INSTANCE_HELP_STR
c9e571b4 10128 BGP_AFI_HELP_STR
9bedbb1e 10129 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10130 "Detailed info about dynamic update groups\n"
10131 "Specific subgroup to display detailed info for\n")
8386ac43 10132{
d62a17ae 10133 char *vrf = NULL;
10134 afi_t afi = AFI_IP6;
10135 safi_t safi = SAFI_UNICAST;
10136 uint64_t subgrp_id = 0;
10137
10138 int idx = 0;
10139
10140 /* show [ip] bgp */
10141 if (argv_find(argv, argc, "ip", &idx))
10142 afi = AFI_IP;
10143 /* [<view|vrf> VIEWVRFNAME] */
10144 if (argv_find(argv, argc, "view", &idx)
10145 || argv_find(argv, argc, "vrf", &idx))
10146 vrf = argv[++idx]->arg;
10147 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10148 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10149 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10150 }
5bf15956 10151
d62a17ae 10152 /* get subgroup id, if provided */
10153 idx = argc - 1;
10154 if (argv[idx]->type == VARIABLE_TKN)
10155 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10156
d62a17ae 10157 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10158}
10159
f186de26 10160DEFUN (show_bgp_instance_all_ipv6_updgrps,
10161 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10162 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10163 SHOW_STR
716b2d8a 10164 IP_STR
f186de26 10165 BGP_STR
10166 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10167 "Detailed info about dynamic update groups\n")
f186de26 10168{
d62a17ae 10169 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10170 return CMD_SUCCESS;
f186de26 10171}
10172
5bf15956
DW
10173DEFUN (show_bgp_updgrps_stats,
10174 show_bgp_updgrps_stats_cmd,
716b2d8a 10175 "show [ip] bgp update-groups statistics",
3f9c7369 10176 SHOW_STR
716b2d8a 10177 IP_STR
3f9c7369 10178 BGP_STR
0c7b1b01 10179 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10180 "Statistics\n")
10181{
d62a17ae 10182 struct bgp *bgp;
3f9c7369 10183
d62a17ae 10184 bgp = bgp_get_default();
10185 if (bgp)
10186 update_group_show_stats(bgp, vty);
3f9c7369 10187
d62a17ae 10188 return CMD_SUCCESS;
3f9c7369
DS
10189}
10190
8386ac43 10191DEFUN (show_bgp_instance_updgrps_stats,
10192 show_bgp_instance_updgrps_stats_cmd,
18c57037 10193 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10194 SHOW_STR
716b2d8a 10195 IP_STR
8386ac43 10196 BGP_STR
10197 BGP_INSTANCE_HELP_STR
0c7b1b01 10198 "Detailed info about dynamic update groups\n"
8386ac43 10199 "Statistics\n")
10200{
d62a17ae 10201 int idx_word = 3;
10202 struct bgp *bgp;
8386ac43 10203
d62a17ae 10204 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10205 if (bgp)
10206 update_group_show_stats(bgp, vty);
8386ac43 10207
d62a17ae 10208 return CMD_SUCCESS;
8386ac43 10209}
10210
d62a17ae 10211static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10212 afi_t afi, safi_t safi,
10213 const char *what, uint64_t subgrp_id)
3f9c7369 10214{
d62a17ae 10215 struct bgp *bgp;
8386ac43 10216
d62a17ae 10217 if (name)
10218 bgp = bgp_lookup_by_name(name);
10219 else
10220 bgp = bgp_get_default();
8386ac43 10221
d62a17ae 10222 if (bgp) {
10223 if (!strcmp(what, "advertise-queue"))
10224 update_group_show_adj_queue(bgp, afi, safi, vty,
10225 subgrp_id);
10226 else if (!strcmp(what, "advertised-routes"))
10227 update_group_show_advertised(bgp, afi, safi, vty,
10228 subgrp_id);
10229 else if (!strcmp(what, "packet-queue"))
10230 update_group_show_packet_queue(bgp, afi, safi, vty,
10231 subgrp_id);
10232 }
3f9c7369
DS
10233}
10234
10235DEFUN (show_ip_bgp_updgrps_adj,
10236 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10237 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10238 SHOW_STR
10239 IP_STR
10240 BGP_STR
0c7b1b01 10241 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10242 "Advertisement queue\n"
10243 "Announced routes\n"
10244 "Packet queue\n")
10245{
d62a17ae 10246 int idx_type = 4;
10247 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10248 argv[idx_type]->arg, 0);
10249 return CMD_SUCCESS;
8386ac43 10250}
10251
10252DEFUN (show_ip_bgp_instance_updgrps_adj,
10253 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10254 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10255 SHOW_STR
10256 IP_STR
10257 BGP_STR
10258 BGP_INSTANCE_HELP_STR
0c7b1b01 10259 "Detailed info about dynamic update groups\n"
8386ac43 10260 "Advertisement queue\n"
10261 "Announced routes\n"
10262 "Packet queue\n")
8386ac43 10263{
d62a17ae 10264 int idx_word = 4;
10265 int idx_type = 6;
10266 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10267 SAFI_UNICAST, argv[idx_type]->arg, 0);
10268 return CMD_SUCCESS;
3f9c7369
DS
10269}
10270
10271DEFUN (show_bgp_updgrps_afi_adj,
10272 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10273 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10274 SHOW_STR
716b2d8a 10275 IP_STR
3f9c7369 10276 BGP_STR
46f296b4 10277 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10278 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10279 "Advertisement queue\n"
10280 "Announced routes\n"
7111c1a0 10281 "Packet queue\n")
3f9c7369 10282{
d62a17ae 10283 int idx_afi = 2;
10284 int idx_safi = 3;
10285 int idx_type = 5;
10286 show_bgp_updgrps_adj_info_aux(
10287 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10288 bgp_vty_safi_from_str(argv[idx_safi]->text),
10289 argv[idx_type]->arg, 0);
10290 return CMD_SUCCESS;
3f9c7369
DS
10291}
10292
10293DEFUN (show_bgp_updgrps_adj,
10294 show_bgp_updgrps_adj_cmd,
716b2d8a 10295 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10296 SHOW_STR
716b2d8a 10297 IP_STR
3f9c7369 10298 BGP_STR
0c7b1b01 10299 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10300 "Advertisement queue\n"
10301 "Announced routes\n"
10302 "Packet queue\n")
10303{
d62a17ae 10304 int idx_type = 3;
10305 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10306 argv[idx_type]->arg, 0);
10307 return CMD_SUCCESS;
8386ac43 10308}
10309
10310DEFUN (show_bgp_instance_updgrps_adj,
10311 show_bgp_instance_updgrps_adj_cmd,
18c57037 10312 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10313 SHOW_STR
716b2d8a 10314 IP_STR
8386ac43 10315 BGP_STR
10316 BGP_INSTANCE_HELP_STR
0c7b1b01 10317 "Detailed info about dynamic update groups\n"
8386ac43 10318 "Advertisement queue\n"
10319 "Announced routes\n"
10320 "Packet queue\n")
10321{
d62a17ae 10322 int idx_word = 3;
10323 int idx_type = 5;
10324 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10325 SAFI_UNICAST, argv[idx_type]->arg, 0);
10326 return CMD_SUCCESS;
3f9c7369
DS
10327}
10328
10329DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10330 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10331 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10332 SHOW_STR
10333 IP_STR
10334 BGP_STR
0c7b1b01 10335 "Detailed info about dynamic update groups\n"
8fe8a7f6 10336 "Specific subgroup to display info for\n"
3f9c7369
DS
10337 "Advertisement queue\n"
10338 "Announced routes\n"
10339 "Packet queue\n")
3f9c7369 10340{
d62a17ae 10341 int idx_subgroup_id = 4;
10342 int idx_type = 5;
10343 uint64_t subgrp_id;
8fe8a7f6 10344
d62a17ae 10345 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10346
d62a17ae 10347 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10348 argv[idx_type]->arg, subgrp_id);
10349 return CMD_SUCCESS;
8386ac43 10350}
10351
10352DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10353 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10354 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10355 SHOW_STR
10356 IP_STR
10357 BGP_STR
10358 BGP_INSTANCE_HELP_STR
0c7b1b01 10359 "Detailed info about dynamic update groups\n"
8386ac43 10360 "Specific subgroup to display info for\n"
10361 "Advertisement queue\n"
10362 "Announced routes\n"
10363 "Packet queue\n")
8386ac43 10364{
d62a17ae 10365 int idx_vrf = 4;
10366 int idx_subgroup_id = 6;
10367 int idx_type = 7;
10368 uint64_t subgrp_id;
8386ac43 10369
d62a17ae 10370 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10371
d62a17ae 10372 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10373 SAFI_UNICAST, argv[idx_type]->arg,
10374 subgrp_id);
10375 return CMD_SUCCESS;
3f9c7369
DS
10376}
10377
8fe8a7f6
DS
10378DEFUN (show_bgp_updgrps_afi_adj_s,
10379 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10380 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10381 SHOW_STR
716b2d8a 10382 IP_STR
3f9c7369 10383 BGP_STR
46f296b4 10384 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10385 "Detailed info about dynamic update groups\n"
8fe8a7f6 10386 "Specific subgroup to display info for\n"
3f9c7369
DS
10387 "Advertisement queue\n"
10388 "Announced routes\n"
7111c1a0 10389 "Packet queue\n")
3f9c7369 10390{
d62a17ae 10391 int idx_afi = 2;
10392 int idx_safi = 3;
10393 int idx_subgroup_id = 5;
10394 int idx_type = 6;
10395 uint64_t subgrp_id;
3f9c7369 10396
d62a17ae 10397 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10398
d62a17ae 10399 show_bgp_updgrps_adj_info_aux(
10400 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10401 bgp_vty_safi_from_str(argv[idx_safi]->text),
10402 argv[idx_type]->arg, subgrp_id);
10403 return CMD_SUCCESS;
3f9c7369
DS
10404}
10405
8fe8a7f6
DS
10406DEFUN (show_bgp_updgrps_adj_s,
10407 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10408 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10409 SHOW_STR
716b2d8a 10410 IP_STR
8fe8a7f6 10411 BGP_STR
0c7b1b01 10412 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10413 "Specific subgroup to display info for\n"
10414 "Advertisement queue\n"
10415 "Announced routes\n"
10416 "Packet queue\n")
10417{
d62a17ae 10418 int idx_subgroup_id = 3;
10419 int idx_type = 4;
10420 uint64_t subgrp_id;
8fe8a7f6 10421
d62a17ae 10422 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10423
d62a17ae 10424 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10425 argv[idx_type]->arg, subgrp_id);
10426 return CMD_SUCCESS;
8fe8a7f6
DS
10427}
10428
8386ac43 10429DEFUN (show_bgp_instance_updgrps_adj_s,
10430 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10431 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10432 SHOW_STR
716b2d8a 10433 IP_STR
8386ac43 10434 BGP_STR
10435 BGP_INSTANCE_HELP_STR
0c7b1b01 10436 "Detailed info about dynamic update groups\n"
8386ac43 10437 "Specific subgroup to display info for\n"
10438 "Advertisement queue\n"
10439 "Announced routes\n"
10440 "Packet queue\n")
10441{
d62a17ae 10442 int idx_vrf = 3;
10443 int idx_subgroup_id = 5;
10444 int idx_type = 6;
10445 uint64_t subgrp_id;
10446
10447 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10448
10449 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10450 SAFI_UNICAST, argv[idx_type]->arg,
10451 subgrp_id);
10452 return CMD_SUCCESS;
10453}
10454
10455
10456static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10457{
10458 struct listnode *node, *nnode;
10459 struct prefix *range;
10460 struct peer *conf;
10461 struct peer *peer;
10462 char buf[PREFIX2STR_BUFFER];
10463 afi_t afi;
10464 safi_t safi;
10465 const char *peer_status;
10466 const char *af_str;
10467 int lr_count;
10468 int dynamic;
10469 int af_cfgd;
10470
10471 conf = group->conf;
10472
10473 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10474 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10475 conf->as);
10476 } else if (conf->as_type == AS_INTERNAL) {
10477 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10478 group->bgp->as);
10479 } else {
10480 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10481 }
f14e6fdb 10482
d62a17ae 10483 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10484 vty_out(vty, " Peer-group type is internal\n");
10485 else
10486 vty_out(vty, " Peer-group type is external\n");
10487
10488 /* Display AFs configured. */
10489 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
10490 FOREACH_AFI_SAFI (afi, safi) {
10491 if (conf->afc[afi][safi]) {
10492 af_cfgd = 1;
10493 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 10494 }
05c7a1cc 10495 }
d62a17ae 10496 if (!af_cfgd)
10497 vty_out(vty, " none\n");
10498 else
10499 vty_out(vty, "\n");
10500
10501 /* Display listen ranges (for dynamic neighbors), if any */
10502 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10503 if (afi == AFI_IP)
10504 af_str = "IPv4";
10505 else if (afi == AFI_IP6)
10506 af_str = "IPv6";
10507 else
10508 af_str = "???";
10509 lr_count = listcount(group->listen_range[afi]);
10510 if (lr_count) {
10511 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10512 af_str);
10513
10514
10515 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10516 nnode, range)) {
10517 prefix2str(range, buf, sizeof(buf));
10518 vty_out(vty, " %s\n", buf);
10519 }
10520 }
10521 }
f14e6fdb 10522
d62a17ae 10523 /* Display group members and their status */
10524 if (listcount(group->peer)) {
10525 vty_out(vty, " Peer-group members:\n");
10526 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10527 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10528 peer_status = "Idle (Admin)";
10529 else if (CHECK_FLAG(peer->sflags,
10530 PEER_STATUS_PREFIX_OVERFLOW))
10531 peer_status = "Idle (PfxCt)";
10532 else
10533 peer_status = lookup_msg(bgp_status_msg,
10534 peer->status, NULL);
10535
10536 dynamic = peer_dynamic_neighbor(peer);
10537 vty_out(vty, " %s %s %s \n", peer->host,
10538 dynamic ? "(dynamic)" : "", peer_status);
10539 }
10540 }
f14e6fdb 10541
d62a17ae 10542 return CMD_SUCCESS;
10543}
10544
ff9959b0
QY
10545static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10546 const char *group_name)
d62a17ae 10547{
ff9959b0 10548 struct bgp *bgp;
d62a17ae 10549 struct listnode *node, *nnode;
10550 struct peer_group *group;
ff9959b0
QY
10551 bool found = false;
10552
10553 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10554
10555 if (!bgp) {
10556 vty_out(vty, "%% No such BGP instance exists\n");
10557 return CMD_WARNING;
10558 }
d62a17ae 10559
10560 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
10561 if (group_name) {
10562 if (strmatch(group->name, group_name)) {
d62a17ae 10563 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
10564 found = true;
10565 break;
d62a17ae 10566 }
ff9959b0
QY
10567 } else {
10568 bgp_show_one_peer_group(vty, group);
d62a17ae 10569 }
f14e6fdb 10570 }
f14e6fdb 10571
ff9959b0 10572 if (group_name && !found)
d62a17ae 10573 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10574
d62a17ae 10575 return CMD_SUCCESS;
f14e6fdb
DS
10576}
10577
f14e6fdb
DS
10578DEFUN (show_ip_bgp_peer_groups,
10579 show_ip_bgp_peer_groups_cmd,
18c57037 10580 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10581 SHOW_STR
10582 IP_STR
10583 BGP_STR
8386ac43 10584 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10585 "Detailed information on BGP peer groups\n"
10586 "Peer group name\n")
f14e6fdb 10587{
d62a17ae 10588 char *vrf, *pg;
10589 vrf = pg = NULL;
10590 int idx = 0;
f14e6fdb 10591
1d35f218 10592 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg : NULL;
d62a17ae 10593 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10594
ff9959b0 10595 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 10596}
3f9c7369 10597
d6e3c605 10598
718e3744 10599/* Redistribute VTY commands. */
10600
718e3744 10601DEFUN (bgp_redistribute_ipv4,
10602 bgp_redistribute_ipv4_cmd,
40d1cbfb 10603 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10604 "Redistribute information from another routing protocol\n"
ab0181ee 10605 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10606{
d62a17ae 10607 VTY_DECLVAR_CONTEXT(bgp, bgp);
10608 int idx_protocol = 1;
10609 int type;
718e3744 10610
d62a17ae 10611 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10612 if (type < 0) {
10613 vty_out(vty, "%% Invalid route type\n");
10614 return CMD_WARNING_CONFIG_FAILED;
10615 }
7f323236 10616
d62a17ae 10617 bgp_redist_add(bgp, AFI_IP, type, 0);
10618 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10619}
10620
d62a17ae 10621ALIAS_HIDDEN(
10622 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10623 "redistribute " FRR_IP_REDIST_STR_BGPD,
10624 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10625
718e3744 10626DEFUN (bgp_redistribute_ipv4_rmap,
10627 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10628 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10629 "Redistribute information from another routing protocol\n"
ab0181ee 10630 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10631 "Route map reference\n"
10632 "Pointer to route-map entries\n")
10633{
d62a17ae 10634 VTY_DECLVAR_CONTEXT(bgp, bgp);
10635 int idx_protocol = 1;
10636 int idx_word = 3;
10637 int type;
10638 struct bgp_redist *red;
718e3744 10639
d62a17ae 10640 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10641 if (type < 0) {
10642 vty_out(vty, "%% Invalid route type\n");
10643 return CMD_WARNING_CONFIG_FAILED;
10644 }
718e3744 10645
d62a17ae 10646 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10647 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10648 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10649}
10650
d62a17ae 10651ALIAS_HIDDEN(
10652 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10653 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10654 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10655 "Route map reference\n"
10656 "Pointer to route-map entries\n")
596c17ba 10657
718e3744 10658DEFUN (bgp_redistribute_ipv4_metric,
10659 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10660 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10661 "Redistribute information from another routing protocol\n"
ab0181ee 10662 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10663 "Metric for redistributed routes\n"
10664 "Default metric\n")
10665{
d62a17ae 10666 VTY_DECLVAR_CONTEXT(bgp, bgp);
10667 int idx_protocol = 1;
10668 int idx_number = 3;
10669 int type;
10670 u_int32_t metric;
10671 struct bgp_redist *red;
10672
10673 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10674 if (type < 0) {
10675 vty_out(vty, "%% Invalid route type\n");
10676 return CMD_WARNING_CONFIG_FAILED;
10677 }
10678 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10679
10680 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10681 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10682 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10683}
10684
10685ALIAS_HIDDEN(
10686 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10687 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10688 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10689 "Metric for redistributed routes\n"
10690 "Default metric\n")
596c17ba 10691
718e3744 10692DEFUN (bgp_redistribute_ipv4_rmap_metric,
10693 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10694 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10695 "Redistribute information from another routing protocol\n"
ab0181ee 10696 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10697 "Route map reference\n"
10698 "Pointer to route-map entries\n"
10699 "Metric for redistributed routes\n"
10700 "Default metric\n")
10701{
d62a17ae 10702 VTY_DECLVAR_CONTEXT(bgp, bgp);
10703 int idx_protocol = 1;
10704 int idx_word = 3;
10705 int idx_number = 5;
10706 int type;
10707 u_int32_t metric;
10708 struct bgp_redist *red;
10709
10710 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10711 if (type < 0) {
10712 vty_out(vty, "%% Invalid route type\n");
10713 return CMD_WARNING_CONFIG_FAILED;
10714 }
10715 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10716
10717 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10718 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10719 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10720 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10721}
10722
10723ALIAS_HIDDEN(
10724 bgp_redistribute_ipv4_rmap_metric,
10725 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10726 "redistribute " FRR_IP_REDIST_STR_BGPD
10727 " route-map WORD metric (0-4294967295)",
10728 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10729 "Route map reference\n"
10730 "Pointer to route-map entries\n"
10731 "Metric for redistributed routes\n"
10732 "Default metric\n")
596c17ba 10733
718e3744 10734DEFUN (bgp_redistribute_ipv4_metric_rmap,
10735 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10736 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10737 "Redistribute information from another routing protocol\n"
ab0181ee 10738 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10739 "Metric for redistributed routes\n"
10740 "Default metric\n"
10741 "Route map reference\n"
10742 "Pointer to route-map entries\n")
10743{
d62a17ae 10744 VTY_DECLVAR_CONTEXT(bgp, bgp);
10745 int idx_protocol = 1;
10746 int idx_number = 3;
10747 int idx_word = 5;
10748 int type;
10749 u_int32_t metric;
10750 struct bgp_redist *red;
10751
10752 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10753 if (type < 0) {
10754 vty_out(vty, "%% Invalid route type\n");
10755 return CMD_WARNING_CONFIG_FAILED;
10756 }
10757 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10758
10759 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10760 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10761 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10762 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10763}
10764
10765ALIAS_HIDDEN(
10766 bgp_redistribute_ipv4_metric_rmap,
10767 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10768 "redistribute " FRR_IP_REDIST_STR_BGPD
10769 " metric (0-4294967295) route-map WORD",
10770 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10771 "Metric for redistributed routes\n"
10772 "Default metric\n"
10773 "Route map reference\n"
10774 "Pointer to route-map entries\n")
596c17ba 10775
7c8ff89e
DS
10776DEFUN (bgp_redistribute_ipv4_ospf,
10777 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10778 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10779 "Redistribute information from another routing protocol\n"
10780 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10781 "Non-main Kernel Routing Table\n"
10782 "Instance ID/Table ID\n")
7c8ff89e 10783{
d62a17ae 10784 VTY_DECLVAR_CONTEXT(bgp, bgp);
10785 int idx_ospf_table = 1;
10786 int idx_number = 2;
10787 u_short instance;
10788 u_short protocol;
7c8ff89e 10789
d62a17ae 10790 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10791
d62a17ae 10792 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10793 protocol = ZEBRA_ROUTE_OSPF;
10794 else
10795 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10796
d62a17ae 10797 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10798 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10799}
10800
d62a17ae 10801ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10802 "redistribute <ospf|table> (1-65535)",
10803 "Redistribute information from another routing protocol\n"
10804 "Open Shortest Path First (OSPFv2)\n"
10805 "Non-main Kernel Routing Table\n"
10806 "Instance ID/Table ID\n")
596c17ba 10807
7c8ff89e
DS
10808DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10809 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10810 "redistribute <ospf|table> (1-65535) route-map WORD",
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{
d62a17ae 10818 VTY_DECLVAR_CONTEXT(bgp, bgp);
10819 int idx_ospf_table = 1;
10820 int idx_number = 2;
10821 int idx_word = 4;
10822 struct bgp_redist *red;
10823 u_short instance;
10824 int protocol;
10825
10826 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10827 protocol = ZEBRA_ROUTE_OSPF;
10828 else
10829 protocol = ZEBRA_ROUTE_TABLE;
10830
10831 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10832 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10833 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10834 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10835}
10836
10837ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10838 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10839 "redistribute <ospf|table> (1-65535) route-map WORD",
10840 "Redistribute information from another routing protocol\n"
10841 "Open Shortest Path First (OSPFv2)\n"
10842 "Non-main Kernel Routing Table\n"
10843 "Instance ID/Table ID\n"
10844 "Route map reference\n"
10845 "Pointer to route-map entries\n")
596c17ba 10846
7c8ff89e
DS
10847DEFUN (bgp_redistribute_ipv4_ospf_metric,
10848 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10849 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10850 "Redistribute information from another routing protocol\n"
10851 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10852 "Non-main Kernel Routing Table\n"
10853 "Instance ID/Table ID\n"
7c8ff89e
DS
10854 "Metric for redistributed routes\n"
10855 "Default metric\n")
10856{
d62a17ae 10857 VTY_DECLVAR_CONTEXT(bgp, bgp);
10858 int idx_ospf_table = 1;
10859 int idx_number = 2;
10860 int idx_number_2 = 4;
10861 u_int32_t metric;
10862 struct bgp_redist *red;
10863 u_short instance;
10864 int protocol;
10865
10866 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10867 protocol = ZEBRA_ROUTE_OSPF;
10868 else
10869 protocol = ZEBRA_ROUTE_TABLE;
10870
10871 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10872 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10873
10874 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10875 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10876 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10877}
10878
10879ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10880 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10881 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10882 "Redistribute information from another routing protocol\n"
10883 "Open Shortest Path First (OSPFv2)\n"
10884 "Non-main Kernel Routing Table\n"
10885 "Instance ID/Table ID\n"
10886 "Metric for redistributed routes\n"
10887 "Default metric\n")
596c17ba 10888
7c8ff89e
DS
10889DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10890 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10891 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10892 "Redistribute information from another routing protocol\n"
10893 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10894 "Non-main Kernel Routing Table\n"
10895 "Instance ID/Table ID\n"
7c8ff89e
DS
10896 "Route map reference\n"
10897 "Pointer to route-map entries\n"
10898 "Metric for redistributed routes\n"
10899 "Default metric\n")
10900{
d62a17ae 10901 VTY_DECLVAR_CONTEXT(bgp, bgp);
10902 int idx_ospf_table = 1;
10903 int idx_number = 2;
10904 int idx_word = 4;
10905 int idx_number_2 = 6;
10906 u_int32_t metric;
10907 struct bgp_redist *red;
10908 u_short instance;
10909 int protocol;
10910
10911 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10912 protocol = ZEBRA_ROUTE_OSPF;
10913 else
10914 protocol = ZEBRA_ROUTE_TABLE;
10915
10916 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10917 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10918
10919 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10920 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10921 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10922 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10923}
10924
10925ALIAS_HIDDEN(
10926 bgp_redistribute_ipv4_ospf_rmap_metric,
10927 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10928 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10929 "Redistribute information from another routing protocol\n"
10930 "Open Shortest Path First (OSPFv2)\n"
10931 "Non-main Kernel Routing Table\n"
10932 "Instance ID/Table ID\n"
10933 "Route map reference\n"
10934 "Pointer to route-map entries\n"
10935 "Metric for redistributed routes\n"
10936 "Default metric\n")
596c17ba 10937
7c8ff89e
DS
10938DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10939 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10940 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10941 "Redistribute information from another routing protocol\n"
10942 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10943 "Non-main Kernel Routing Table\n"
10944 "Instance ID/Table ID\n"
7c8ff89e
DS
10945 "Metric for redistributed routes\n"
10946 "Default metric\n"
10947 "Route map reference\n"
10948 "Pointer to route-map entries\n")
10949{
d62a17ae 10950 VTY_DECLVAR_CONTEXT(bgp, bgp);
10951 int idx_ospf_table = 1;
10952 int idx_number = 2;
10953 int idx_number_2 = 4;
10954 int idx_word = 6;
10955 u_int32_t metric;
10956 struct bgp_redist *red;
10957 u_short instance;
10958 int protocol;
10959
10960 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10961 protocol = ZEBRA_ROUTE_OSPF;
10962 else
10963 protocol = ZEBRA_ROUTE_TABLE;
10964
10965 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10966 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10967
10968 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10969 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10970 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10971 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10972}
10973
10974ALIAS_HIDDEN(
10975 bgp_redistribute_ipv4_ospf_metric_rmap,
10976 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10977 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10978 "Redistribute information from another routing protocol\n"
10979 "Open Shortest Path First (OSPFv2)\n"
10980 "Non-main Kernel Routing Table\n"
10981 "Instance ID/Table ID\n"
10982 "Metric for redistributed routes\n"
10983 "Default metric\n"
10984 "Route map reference\n"
10985 "Pointer to route-map entries\n")
596c17ba 10986
7c8ff89e
DS
10987DEFUN (no_bgp_redistribute_ipv4_ospf,
10988 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 10989 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
10990 NO_STR
10991 "Redistribute information from another routing protocol\n"
10992 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 10993 "Non-main Kernel Routing Table\n"
31500417
DW
10994 "Instance ID/Table ID\n"
10995 "Metric for redistributed routes\n"
10996 "Default metric\n"
10997 "Route map reference\n"
10998 "Pointer to route-map entries\n")
7c8ff89e 10999{
d62a17ae 11000 VTY_DECLVAR_CONTEXT(bgp, bgp);
11001 int idx_ospf_table = 2;
11002 int idx_number = 3;
11003 u_short instance;
11004 int protocol;
11005
11006 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11007 protocol = ZEBRA_ROUTE_OSPF;
11008 else
11009 protocol = ZEBRA_ROUTE_TABLE;
11010
11011 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11012 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11013}
11014
11015ALIAS_HIDDEN(
11016 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11017 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11018 NO_STR
11019 "Redistribute information from another routing protocol\n"
11020 "Open Shortest Path First (OSPFv2)\n"
11021 "Non-main Kernel Routing Table\n"
11022 "Instance ID/Table ID\n"
11023 "Metric for redistributed routes\n"
11024 "Default metric\n"
11025 "Route map reference\n"
11026 "Pointer to route-map entries\n")
596c17ba 11027
718e3744 11028DEFUN (no_bgp_redistribute_ipv4,
11029 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11030 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11031 NO_STR
11032 "Redistribute information from another routing protocol\n"
3b14d86e 11033 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11034 "Metric for redistributed routes\n"
11035 "Default metric\n"
11036 "Route map reference\n"
11037 "Pointer to route-map entries\n")
718e3744 11038{
d62a17ae 11039 VTY_DECLVAR_CONTEXT(bgp, bgp);
11040 int idx_protocol = 2;
11041 int type;
11042
11043 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11044 if (type < 0) {
11045 vty_out(vty, "%% Invalid route type\n");
11046 return CMD_WARNING_CONFIG_FAILED;
11047 }
11048 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11049}
11050
11051ALIAS_HIDDEN(
11052 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11053 "no redistribute " FRR_IP_REDIST_STR_BGPD
11054 " [metric (0-4294967295)] [route-map WORD]",
11055 NO_STR
11056 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11057 "Metric for redistributed routes\n"
11058 "Default metric\n"
11059 "Route map reference\n"
11060 "Pointer to route-map entries\n")
596c17ba 11061
718e3744 11062DEFUN (bgp_redistribute_ipv6,
11063 bgp_redistribute_ipv6_cmd,
40d1cbfb 11064 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11065 "Redistribute information from another routing protocol\n"
ab0181ee 11066 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11067{
d62a17ae 11068 VTY_DECLVAR_CONTEXT(bgp, bgp);
11069 int idx_protocol = 1;
11070 int type;
718e3744 11071
d62a17ae 11072 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11073 if (type < 0) {
11074 vty_out(vty, "%% Invalid route type\n");
11075 return CMD_WARNING_CONFIG_FAILED;
11076 }
718e3744 11077
d62a17ae 11078 bgp_redist_add(bgp, AFI_IP6, type, 0);
11079 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11080}
11081
11082DEFUN (bgp_redistribute_ipv6_rmap,
11083 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11084 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11085 "Redistribute information from another routing protocol\n"
ab0181ee 11086 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11087 "Route map reference\n"
11088 "Pointer to route-map entries\n")
11089{
d62a17ae 11090 VTY_DECLVAR_CONTEXT(bgp, bgp);
11091 int idx_protocol = 1;
11092 int idx_word = 3;
11093 int type;
11094 struct bgp_redist *red;
718e3744 11095
d62a17ae 11096 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11097 if (type < 0) {
11098 vty_out(vty, "%% Invalid route type\n");
11099 return CMD_WARNING_CONFIG_FAILED;
11100 }
718e3744 11101
d62a17ae 11102 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11103 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11104 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11105}
11106
11107DEFUN (bgp_redistribute_ipv6_metric,
11108 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11109 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11110 "Redistribute information from another routing protocol\n"
ab0181ee 11111 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11112 "Metric for redistributed routes\n"
11113 "Default metric\n")
11114{
d62a17ae 11115 VTY_DECLVAR_CONTEXT(bgp, bgp);
11116 int idx_protocol = 1;
11117 int idx_number = 3;
11118 int type;
11119 u_int32_t metric;
11120 struct bgp_redist *red;
11121
11122 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11123 if (type < 0) {
11124 vty_out(vty, "%% Invalid route type\n");
11125 return CMD_WARNING_CONFIG_FAILED;
11126 }
11127 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11128
d62a17ae 11129 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11130 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11131 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11132}
11133
11134DEFUN (bgp_redistribute_ipv6_rmap_metric,
11135 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11136 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11137 "Redistribute information from another routing protocol\n"
ab0181ee 11138 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11139 "Route map reference\n"
11140 "Pointer to route-map entries\n"
11141 "Metric for redistributed routes\n"
11142 "Default metric\n")
11143{
d62a17ae 11144 VTY_DECLVAR_CONTEXT(bgp, bgp);
11145 int idx_protocol = 1;
11146 int idx_word = 3;
11147 int idx_number = 5;
11148 int type;
11149 u_int32_t metric;
11150 struct bgp_redist *red;
11151
11152 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11153 if (type < 0) {
11154 vty_out(vty, "%% Invalid route type\n");
11155 return CMD_WARNING_CONFIG_FAILED;
11156 }
11157 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11158
d62a17ae 11159 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11160 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11161 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11162 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11163}
11164
11165DEFUN (bgp_redistribute_ipv6_metric_rmap,
11166 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11167 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11168 "Redistribute information from another routing protocol\n"
ab0181ee 11169 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11170 "Metric for redistributed routes\n"
11171 "Default metric\n"
11172 "Route map reference\n"
11173 "Pointer to route-map entries\n")
11174{
d62a17ae 11175 VTY_DECLVAR_CONTEXT(bgp, bgp);
11176 int idx_protocol = 1;
11177 int idx_number = 3;
11178 int idx_word = 5;
11179 int type;
11180 u_int32_t metric;
11181 struct bgp_redist *red;
11182
11183 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11184 if (type < 0) {
11185 vty_out(vty, "%% Invalid route type\n");
11186 return CMD_WARNING_CONFIG_FAILED;
11187 }
11188 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11189
d62a17ae 11190 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11191 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11192 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11193 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11194}
11195
11196DEFUN (no_bgp_redistribute_ipv6,
11197 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11198 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11199 NO_STR
11200 "Redistribute information from another routing protocol\n"
3b14d86e 11201 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11202 "Metric for redistributed routes\n"
11203 "Default metric\n"
11204 "Route map reference\n"
11205 "Pointer to route-map entries\n")
718e3744 11206{
d62a17ae 11207 VTY_DECLVAR_CONTEXT(bgp, bgp);
11208 int idx_protocol = 2;
11209 int type;
718e3744 11210
d62a17ae 11211 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11212 if (type < 0) {
11213 vty_out(vty, "%% Invalid route type\n");
11214 return CMD_WARNING_CONFIG_FAILED;
11215 }
718e3744 11216
d62a17ae 11217 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11218}
11219
2b791107 11220void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11221 safi_t safi)
d62a17ae 11222{
11223 int i;
11224
11225 /* Unicast redistribution only. */
11226 if (safi != SAFI_UNICAST)
2b791107 11227 return;
d62a17ae 11228
11229 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11230 /* Redistribute BGP does not make sense. */
11231 if (i != ZEBRA_ROUTE_BGP) {
11232 struct list *red_list;
11233 struct listnode *node;
11234 struct bgp_redist *red;
11235
11236 red_list = bgp->redist[afi][i];
11237 if (!red_list)
11238 continue;
11239
11240 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11241 /* "redistribute" configuration. */
11242 vty_out(vty, " redistribute %s",
11243 zebra_route_string(i));
11244 if (red->instance)
11245 vty_out(vty, " %d", red->instance);
11246 if (red->redist_metric_flag)
11247 vty_out(vty, " metric %u",
11248 red->redist_metric);
11249 if (red->rmap.name)
11250 vty_out(vty, " route-map %s",
11251 red->rmap.name);
11252 vty_out(vty, "\n");
11253 }
11254 }
11255 }
718e3744 11256}
6b0655a2 11257
718e3744 11258/* BGP node structure. */
d62a17ae 11259static struct cmd_node bgp_node = {
9d303b37 11260 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11261};
11262
d62a17ae 11263static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11264 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11265};
11266
d62a17ae 11267static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11268 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11269};
11270
d62a17ae 11271static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11272 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11273};
11274
d62a17ae 11275static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11276 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11277};
11278
d62a17ae 11279static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11280 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11281};
11282
d62a17ae 11283static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11284 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11285};
11286
d62a17ae 11287static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11288 "%s(config-router-af)# ", 1};
6b0655a2 11289
d62a17ae 11290static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11291 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11292
d62a17ae 11293static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11294 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11295
d62a17ae 11296static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11297 "%s(config-router-af-vni)# ", 1};
90e60aa7 11298
d62a17ae 11299static void community_list_vty(void);
1f8ae70b 11300
d62a17ae 11301static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11302{
d62a17ae 11303 struct bgp *bgp;
11304 struct peer *peer;
11305 struct peer_group *group;
11306 struct listnode *lnbgp, *lnpeer;
b8a815e5 11307
d62a17ae 11308 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11309 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11310 /* only provide suggestions on the appropriate input
11311 * token type,
11312 * they'll otherwise show up multiple times */
11313 enum cmd_token_type match_type;
11314 char *name = peer->host;
d48ed3e0 11315
d62a17ae 11316 if (peer->conf_if) {
11317 match_type = VARIABLE_TKN;
11318 name = peer->conf_if;
11319 } else if (strchr(peer->host, ':'))
11320 match_type = IPV6_TKN;
11321 else
11322 match_type = IPV4_TKN;
d48ed3e0 11323
d62a17ae 11324 if (token->type != match_type)
11325 continue;
d48ed3e0 11326
d62a17ae 11327 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11328 }
d48ed3e0 11329
d62a17ae 11330 if (token->type == VARIABLE_TKN)
11331 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11332 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11333 group->name));
11334 }
b8a815e5
DL
11335}
11336
11337static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11338 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11339 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 11340 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 11341 {.completions = NULL}};
11342
11343void bgp_vty_init(void)
11344{
11345 cmd_variable_handler_register(bgp_var_neighbor);
11346
11347 /* Install bgp top node. */
11348 install_node(&bgp_node, bgp_config_write);
11349 install_node(&bgp_ipv4_unicast_node, NULL);
11350 install_node(&bgp_ipv4_multicast_node, NULL);
11351 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11352 install_node(&bgp_ipv6_unicast_node, NULL);
11353 install_node(&bgp_ipv6_multicast_node, NULL);
11354 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11355 install_node(&bgp_vpnv4_node, NULL);
11356 install_node(&bgp_vpnv6_node, NULL);
11357 install_node(&bgp_evpn_node, NULL);
11358 install_node(&bgp_evpn_vni_node, NULL);
11359
11360 /* Install default VTY commands to new nodes. */
11361 install_default(BGP_NODE);
11362 install_default(BGP_IPV4_NODE);
11363 install_default(BGP_IPV4M_NODE);
11364 install_default(BGP_IPV4L_NODE);
11365 install_default(BGP_IPV6_NODE);
11366 install_default(BGP_IPV6M_NODE);
11367 install_default(BGP_IPV6L_NODE);
11368 install_default(BGP_VPNV4_NODE);
11369 install_default(BGP_VPNV6_NODE);
11370 install_default(BGP_EVPN_NODE);
11371 install_default(BGP_EVPN_VNI_NODE);
11372
11373 /* "bgp multiple-instance" commands. */
11374 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11375 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11376
11377 /* "bgp config-type" commands. */
11378 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11379 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11380
11381 /* bgp route-map delay-timer commands. */
11382 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11383 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11384
11385 /* Dummy commands (Currently not supported) */
11386 install_element(BGP_NODE, &no_synchronization_cmd);
11387 install_element(BGP_NODE, &no_auto_summary_cmd);
11388
11389 /* "router bgp" commands. */
11390 install_element(CONFIG_NODE, &router_bgp_cmd);
11391
11392 /* "no router bgp" commands. */
11393 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11394
11395 /* "bgp router-id" commands. */
11396 install_element(BGP_NODE, &bgp_router_id_cmd);
11397 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11398
11399 /* "bgp cluster-id" commands. */
11400 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11401 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11402
11403 /* "bgp confederation" commands. */
11404 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11405 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11406
11407 /* "bgp confederation peers" commands. */
11408 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11409 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11410
11411 /* bgp max-med command */
11412 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11413 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11414 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11415 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11416 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11417
11418 /* bgp disable-ebgp-connected-nh-check */
11419 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11420 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11421
11422 /* bgp update-delay command */
11423 install_element(BGP_NODE, &bgp_update_delay_cmd);
11424 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11425 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11426
11427 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11428 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
11429 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11430 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 11431
11432 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11433 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11434
11435 /* "maximum-paths" commands. */
11436 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11437 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11438 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11439 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11440 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11441 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11442 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11443 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11444 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11445 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11446 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11447 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11448 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11449 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11450 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11451
11452 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11453 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11454 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11455 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11456 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11457
11458 /* "timers bgp" commands. */
11459 install_element(BGP_NODE, &bgp_timers_cmd);
11460 install_element(BGP_NODE, &no_bgp_timers_cmd);
11461
11462 /* route-map delay-timer commands - per instance for backwards compat.
11463 */
11464 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11465 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11466
11467 /* "bgp client-to-client reflection" commands */
11468 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11469 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11470
11471 /* "bgp always-compare-med" commands */
11472 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11473 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11474
11475 /* "bgp deterministic-med" commands */
11476 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11477 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11478
11479 /* "bgp graceful-restart" commands */
11480 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11481 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11482 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11483 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11484 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11485 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11486
11487 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11488 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11489
7f323236
DW
11490 /* "bgp graceful-shutdown" commands */
11491 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11492 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11493
d62a17ae 11494 /* "bgp fast-external-failover" commands */
11495 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11496 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11497
11498 /* "bgp enforce-first-as" commands */
11499 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11500 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11501
11502 /* "bgp bestpath compare-routerid" commands */
11503 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11504 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11505
11506 /* "bgp bestpath as-path ignore" commands */
11507 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11508 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11509
11510 /* "bgp bestpath as-path confed" commands */
11511 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11512 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11513
11514 /* "bgp bestpath as-path multipath-relax" commands */
11515 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11516 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11517
11518 /* "bgp log-neighbor-changes" commands */
11519 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11520 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11521
11522 /* "bgp bestpath med" commands */
11523 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11524 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11525
11526 /* "no bgp default ipv4-unicast" commands. */
11527 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11528 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11529
11530 /* "bgp network import-check" commands. */
11531 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11532 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11533 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11534
11535 /* "bgp default local-preference" commands. */
11536 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11537 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11538
11539 /* bgp default show-hostname */
11540 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11541 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11542
11543 /* "bgp default subgroup-pkt-queue-max" commands. */
11544 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11545 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11546
11547 /* bgp ibgp-allow-policy-mods command */
11548 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11549 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11550
11551 /* "bgp listen limit" commands. */
11552 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11553 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11554
11555 /* "bgp listen range" commands. */
11556 install_element(BGP_NODE, &bgp_listen_range_cmd);
11557 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11558
11559 /* "neighbor remote-as" commands. */
11560 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11561 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11562 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11563 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11564 install_element(BGP_NODE,
11565 &neighbor_interface_v6only_config_remote_as_cmd);
11566 install_element(BGP_NODE, &no_neighbor_cmd);
11567 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11568
11569 /* "neighbor peer-group" commands. */
11570 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11571 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11572 install_element(BGP_NODE,
11573 &no_neighbor_interface_peer_group_remote_as_cmd);
11574
11575 /* "neighbor local-as" commands. */
11576 install_element(BGP_NODE, &neighbor_local_as_cmd);
11577 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11578 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11579 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11580
11581 /* "neighbor solo" commands. */
11582 install_element(BGP_NODE, &neighbor_solo_cmd);
11583 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11584
11585 /* "neighbor password" commands. */
11586 install_element(BGP_NODE, &neighbor_password_cmd);
11587 install_element(BGP_NODE, &no_neighbor_password_cmd);
11588
11589 /* "neighbor activate" commands. */
11590 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11591 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11592 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11593 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11594 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11595 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11596 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11597 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11598 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11599 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11600
11601 /* "no neighbor activate" commands. */
11602 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11603 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11604 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11605 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11606 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11607 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11608 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11609 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11610 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11611 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11612
11613 /* "neighbor peer-group" set commands. */
11614 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11615 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11616 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11617 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11618 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11619 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11620 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11621 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11622
11623 /* "no neighbor peer-group unset" commands. */
11624 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11625 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11626 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11627 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11628 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11629 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11630 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11631 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11632
11633 /* "neighbor softreconfiguration inbound" commands.*/
11634 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11635 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11636 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11637 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11638 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11639 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11640 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11641 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11642 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11643 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11644 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11645 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11646 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11647 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11648 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11649 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11650 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11651 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11652
11653 /* "neighbor attribute-unchanged" commands. */
11654 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11655 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11656 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11657 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11658 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11659 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11660 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11661 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11662 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11663 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11664 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11665 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11666 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11667 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11668 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11669 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11670 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11671 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11672
11673 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11674 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11675
11676 /* "nexthop-local unchanged" commands */
11677 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11678 install_element(BGP_IPV6_NODE,
11679 &no_neighbor_nexthop_local_unchanged_cmd);
11680
11681 /* "neighbor next-hop-self" commands. */
11682 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11683 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11684 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11685 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11686 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11687 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11688 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11689 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11690 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11691 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11692 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11693 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11694 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11695 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11696 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11697 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11698 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11699 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11700
11701 /* "neighbor next-hop-self force" commands. */
11702 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11703 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11704 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11705 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11706 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11707 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11708 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11709 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11710 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11711 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11712 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11713 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11714 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11715 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11716 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11717 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11718 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11719 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11720
11721 /* "neighbor as-override" commands. */
11722 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11723 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11724 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11725 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11726 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11727 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11728 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11729 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11730 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11731 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11732 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11733 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11734 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11735 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11736 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11737 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11738 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11739 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11740
11741 /* "neighbor remove-private-AS" commands. */
11742 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11743 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11744 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11745 install_element(BGP_NODE,
11746 &no_neighbor_remove_private_as_all_hidden_cmd);
11747 install_element(BGP_NODE,
11748 &neighbor_remove_private_as_replace_as_hidden_cmd);
11749 install_element(BGP_NODE,
11750 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11751 install_element(BGP_NODE,
11752 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11753 install_element(
11754 BGP_NODE,
11755 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11756 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11757 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11758 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11759 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11760 install_element(BGP_IPV4_NODE,
11761 &neighbor_remove_private_as_replace_as_cmd);
11762 install_element(BGP_IPV4_NODE,
11763 &no_neighbor_remove_private_as_replace_as_cmd);
11764 install_element(BGP_IPV4_NODE,
11765 &neighbor_remove_private_as_all_replace_as_cmd);
11766 install_element(BGP_IPV4_NODE,
11767 &no_neighbor_remove_private_as_all_replace_as_cmd);
11768 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11769 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11770 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11771 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11772 install_element(BGP_IPV4M_NODE,
11773 &neighbor_remove_private_as_replace_as_cmd);
11774 install_element(BGP_IPV4M_NODE,
11775 &no_neighbor_remove_private_as_replace_as_cmd);
11776 install_element(BGP_IPV4M_NODE,
11777 &neighbor_remove_private_as_all_replace_as_cmd);
11778 install_element(BGP_IPV4M_NODE,
11779 &no_neighbor_remove_private_as_all_replace_as_cmd);
11780 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11781 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11782 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11783 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11784 install_element(BGP_IPV4L_NODE,
11785 &neighbor_remove_private_as_replace_as_cmd);
11786 install_element(BGP_IPV4L_NODE,
11787 &no_neighbor_remove_private_as_replace_as_cmd);
11788 install_element(BGP_IPV4L_NODE,
11789 &neighbor_remove_private_as_all_replace_as_cmd);
11790 install_element(BGP_IPV4L_NODE,
11791 &no_neighbor_remove_private_as_all_replace_as_cmd);
11792 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11793 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11794 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11795 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11796 install_element(BGP_IPV6_NODE,
11797 &neighbor_remove_private_as_replace_as_cmd);
11798 install_element(BGP_IPV6_NODE,
11799 &no_neighbor_remove_private_as_replace_as_cmd);
11800 install_element(BGP_IPV6_NODE,
11801 &neighbor_remove_private_as_all_replace_as_cmd);
11802 install_element(BGP_IPV6_NODE,
11803 &no_neighbor_remove_private_as_all_replace_as_cmd);
11804 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11805 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11806 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11807 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11808 install_element(BGP_IPV6M_NODE,
11809 &neighbor_remove_private_as_replace_as_cmd);
11810 install_element(BGP_IPV6M_NODE,
11811 &no_neighbor_remove_private_as_replace_as_cmd);
11812 install_element(BGP_IPV6M_NODE,
11813 &neighbor_remove_private_as_all_replace_as_cmd);
11814 install_element(BGP_IPV6M_NODE,
11815 &no_neighbor_remove_private_as_all_replace_as_cmd);
11816 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11817 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11818 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11819 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11820 install_element(BGP_IPV6L_NODE,
11821 &neighbor_remove_private_as_replace_as_cmd);
11822 install_element(BGP_IPV6L_NODE,
11823 &no_neighbor_remove_private_as_replace_as_cmd);
11824 install_element(BGP_IPV6L_NODE,
11825 &neighbor_remove_private_as_all_replace_as_cmd);
11826 install_element(BGP_IPV6L_NODE,
11827 &no_neighbor_remove_private_as_all_replace_as_cmd);
11828 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11829 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11830 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11831 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11832 install_element(BGP_VPNV4_NODE,
11833 &neighbor_remove_private_as_replace_as_cmd);
11834 install_element(BGP_VPNV4_NODE,
11835 &no_neighbor_remove_private_as_replace_as_cmd);
11836 install_element(BGP_VPNV4_NODE,
11837 &neighbor_remove_private_as_all_replace_as_cmd);
11838 install_element(BGP_VPNV4_NODE,
11839 &no_neighbor_remove_private_as_all_replace_as_cmd);
11840 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11841 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11842 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11843 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11844 install_element(BGP_VPNV6_NODE,
11845 &neighbor_remove_private_as_replace_as_cmd);
11846 install_element(BGP_VPNV6_NODE,
11847 &no_neighbor_remove_private_as_replace_as_cmd);
11848 install_element(BGP_VPNV6_NODE,
11849 &neighbor_remove_private_as_all_replace_as_cmd);
11850 install_element(BGP_VPNV6_NODE,
11851 &no_neighbor_remove_private_as_all_replace_as_cmd);
11852
11853 /* "neighbor send-community" commands.*/
11854 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11855 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11856 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11857 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11858 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11859 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11860 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11861 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11862 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11863 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11864 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11865 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11866 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11867 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11868 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11869 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11870 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11871 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11872 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11873 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11874 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11875 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11876 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11877 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11878 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11879 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11880 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11881 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11882 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11883 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11884 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11885 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11886 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11887 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11888 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11889 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11890
11891 /* "neighbor route-reflector" commands.*/
11892 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11893 install_element(BGP_NODE,
11894 &no_neighbor_route_reflector_client_hidden_cmd);
11895 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11896 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11897 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11898 install_element(BGP_IPV4M_NODE,
11899 &no_neighbor_route_reflector_client_cmd);
11900 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11901 install_element(BGP_IPV4L_NODE,
11902 &no_neighbor_route_reflector_client_cmd);
11903 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11904 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11905 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11906 install_element(BGP_IPV6M_NODE,
11907 &no_neighbor_route_reflector_client_cmd);
11908 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11909 install_element(BGP_IPV6L_NODE,
11910 &no_neighbor_route_reflector_client_cmd);
11911 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11912 install_element(BGP_VPNV4_NODE,
11913 &no_neighbor_route_reflector_client_cmd);
11914 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11915 install_element(BGP_VPNV6_NODE,
11916 &no_neighbor_route_reflector_client_cmd);
11917 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11918 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11919
11920 /* "neighbor route-server" commands.*/
11921 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11922 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11923 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11924 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11925 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11926 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11927 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11928 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11929 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11930 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11931 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11932 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11933 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11934 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11935 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11936 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11937 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11938 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11939
11940 /* "neighbor addpath-tx-all-paths" commands.*/
11941 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11942 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11943 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11944 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11945 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11946 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11947 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11948 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11949 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11950 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11951 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11952 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11953 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11954 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11955 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11956 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11957 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11958 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11959
11960 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11961 install_element(BGP_NODE,
11962 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11963 install_element(BGP_NODE,
11964 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11965 install_element(BGP_IPV4_NODE,
11966 &neighbor_addpath_tx_bestpath_per_as_cmd);
11967 install_element(BGP_IPV4_NODE,
11968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11969 install_element(BGP_IPV4M_NODE,
11970 &neighbor_addpath_tx_bestpath_per_as_cmd);
11971 install_element(BGP_IPV4M_NODE,
11972 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11973 install_element(BGP_IPV4L_NODE,
11974 &neighbor_addpath_tx_bestpath_per_as_cmd);
11975 install_element(BGP_IPV4L_NODE,
11976 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11977 install_element(BGP_IPV6_NODE,
11978 &neighbor_addpath_tx_bestpath_per_as_cmd);
11979 install_element(BGP_IPV6_NODE,
11980 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11981 install_element(BGP_IPV6M_NODE,
11982 &neighbor_addpath_tx_bestpath_per_as_cmd);
11983 install_element(BGP_IPV6M_NODE,
11984 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11985 install_element(BGP_IPV6L_NODE,
11986 &neighbor_addpath_tx_bestpath_per_as_cmd);
11987 install_element(BGP_IPV6L_NODE,
11988 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11989 install_element(BGP_VPNV4_NODE,
11990 &neighbor_addpath_tx_bestpath_per_as_cmd);
11991 install_element(BGP_VPNV4_NODE,
11992 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11993 install_element(BGP_VPNV6_NODE,
11994 &neighbor_addpath_tx_bestpath_per_as_cmd);
11995 install_element(BGP_VPNV6_NODE,
11996 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11997
11998 /* "neighbor passive" commands. */
11999 install_element(BGP_NODE, &neighbor_passive_cmd);
12000 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12001
12002
12003 /* "neighbor shutdown" commands. */
12004 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12005 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12006 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12007 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12008
12009 /* "neighbor capability extended-nexthop" commands.*/
12010 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12011 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12012
12013 /* "neighbor capability orf prefix-list" commands.*/
12014 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12015 install_element(BGP_NODE,
12016 &no_neighbor_capability_orf_prefix_hidden_cmd);
12017 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12018 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12019 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12020 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12021 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12022 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12023 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12024 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12025 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12026 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12027 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12028 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12029
12030 /* "neighbor capability dynamic" commands.*/
12031 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12032 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12033
12034 /* "neighbor dont-capability-negotiate" commands. */
12035 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12036 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12037
12038 /* "neighbor ebgp-multihop" commands. */
12039 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12040 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12041 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12042
12043 /* "neighbor disable-connected-check" commands. */
12044 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12045 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12046
12047 /* "neighbor description" commands. */
12048 install_element(BGP_NODE, &neighbor_description_cmd);
12049 install_element(BGP_NODE, &no_neighbor_description_cmd);
12050
12051 /* "neighbor update-source" commands. "*/
12052 install_element(BGP_NODE, &neighbor_update_source_cmd);
12053 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12054
12055 /* "neighbor default-originate" commands. */
12056 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12057 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12058 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12059 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12060 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12061 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12062 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12063 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12064 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12065 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12066 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12067 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12068 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12069 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12070 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12071 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12072 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12073 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12074 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12075 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12076 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12077
12078 /* "neighbor port" commands. */
12079 install_element(BGP_NODE, &neighbor_port_cmd);
12080 install_element(BGP_NODE, &no_neighbor_port_cmd);
12081
12082 /* "neighbor weight" commands. */
12083 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12084 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12085
12086 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12087 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12088 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12089 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12090 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12091 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12092 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12093 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12094 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12095 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12096 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12097 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12098 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12099 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12100 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12101 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12102
12103 /* "neighbor override-capability" commands. */
12104 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12105 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12106
12107 /* "neighbor strict-capability-match" commands. */
12108 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12109 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12110
12111 /* "neighbor timers" commands. */
12112 install_element(BGP_NODE, &neighbor_timers_cmd);
12113 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12114
12115 /* "neighbor timers connect" commands. */
12116 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12117 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12118
12119 /* "neighbor advertisement-interval" commands. */
12120 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12121 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12122
12123 /* "neighbor interface" commands. */
12124 install_element(BGP_NODE, &neighbor_interface_cmd);
12125 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12126
12127 /* "neighbor distribute" commands. */
12128 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12129 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12130 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12131 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12132 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12133 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12134 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12135 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12136 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12137 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12138 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12139 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12140 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12141 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12142 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12143 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12144 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12145 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12146
12147 /* "neighbor prefix-list" commands. */
12148 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12149 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12150 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12151 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12152 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12153 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12154 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12155 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12156 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12157 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12158 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12159 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12160 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12161 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12162 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12163 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12164 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12165 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12166
12167 /* "neighbor filter-list" commands. */
12168 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12169 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12170 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12171 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12172 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12173 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12174 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12175 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12176 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12177 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12178 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12179 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12180 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12181 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12182 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12183 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12184 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12185 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12186
12187 /* "neighbor route-map" commands. */
12188 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12189 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12190 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12191 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12192 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12193 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12194 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12195 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12196 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12197 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12198 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12199 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12200 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12201 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12202 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12203 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12204 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12205 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12206 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12207 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12208
12209 /* "neighbor unsuppress-map" commands. */
12210 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12211 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12212 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12213 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12214 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12215 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12216 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12217 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12218 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12219 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12220 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12221 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12222 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12223 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12224 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12225 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12226 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12227 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12228
12229 /* "neighbor maximum-prefix" commands. */
12230 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12231 install_element(BGP_NODE,
12232 &neighbor_maximum_prefix_threshold_hidden_cmd);
12233 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12234 install_element(BGP_NODE,
12235 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12236 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12237 install_element(BGP_NODE,
12238 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12239 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12240 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12242 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12243 install_element(BGP_IPV4_NODE,
12244 &neighbor_maximum_prefix_threshold_warning_cmd);
12245 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12246 install_element(BGP_IPV4_NODE,
12247 &neighbor_maximum_prefix_threshold_restart_cmd);
12248 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12249 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12251 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12252 install_element(BGP_IPV4M_NODE,
12253 &neighbor_maximum_prefix_threshold_warning_cmd);
12254 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12255 install_element(BGP_IPV4M_NODE,
12256 &neighbor_maximum_prefix_threshold_restart_cmd);
12257 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12258 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12260 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12261 install_element(BGP_IPV4L_NODE,
12262 &neighbor_maximum_prefix_threshold_warning_cmd);
12263 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12264 install_element(BGP_IPV4L_NODE,
12265 &neighbor_maximum_prefix_threshold_restart_cmd);
12266 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12267 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12269 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12270 install_element(BGP_IPV6_NODE,
12271 &neighbor_maximum_prefix_threshold_warning_cmd);
12272 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12273 install_element(BGP_IPV6_NODE,
12274 &neighbor_maximum_prefix_threshold_restart_cmd);
12275 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12276 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12278 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12279 install_element(BGP_IPV6M_NODE,
12280 &neighbor_maximum_prefix_threshold_warning_cmd);
12281 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12282 install_element(BGP_IPV6M_NODE,
12283 &neighbor_maximum_prefix_threshold_restart_cmd);
12284 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12285 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12287 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12288 install_element(BGP_IPV6L_NODE,
12289 &neighbor_maximum_prefix_threshold_warning_cmd);
12290 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12291 install_element(BGP_IPV6L_NODE,
12292 &neighbor_maximum_prefix_threshold_restart_cmd);
12293 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12294 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12296 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12297 install_element(BGP_VPNV4_NODE,
12298 &neighbor_maximum_prefix_threshold_warning_cmd);
12299 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12300 install_element(BGP_VPNV4_NODE,
12301 &neighbor_maximum_prefix_threshold_restart_cmd);
12302 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12303 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12305 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12306 install_element(BGP_VPNV6_NODE,
12307 &neighbor_maximum_prefix_threshold_warning_cmd);
12308 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12309 install_element(BGP_VPNV6_NODE,
12310 &neighbor_maximum_prefix_threshold_restart_cmd);
12311 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12312
12313 /* "neighbor allowas-in" */
12314 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12315 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12316 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12317 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12318 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12319 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12320 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12321 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12322 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12323 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12324 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12325 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12326 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12327 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12328 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12329 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12330 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12331 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12332 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12333 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12334
12335 /* address-family commands. */
12336 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12337 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12338#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12339 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12340 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12341#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12342
d62a17ae 12343 install_element(BGP_NODE, &address_family_evpn_cmd);
12344
12345 /* "exit-address-family" command. */
12346 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12347 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12348 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12349 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12350 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12351 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12352 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12353 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12354 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12355
12356 /* "clear ip bgp commands" */
12357 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12358
12359 /* clear ip bgp prefix */
12360 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12361 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12362 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12363
12364 /* "show [ip] bgp summary" commands. */
12365 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12366 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12367 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12368 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12369 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12370 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12371 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12372 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12373 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12374 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12375 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12376 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12377 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12378 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12379 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12380
12381 /* "show [ip] bgp neighbors" commands. */
12382 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12383
12384 /* "show [ip] bgp peer-group" commands. */
12385 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12386
12387 /* "show [ip] bgp paths" commands. */
12388 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12389
12390 /* "show [ip] bgp community" commands. */
12391 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12392
12393 /* "show ip bgp large-community" commands. */
12394 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12395 /* "show [ip] bgp attribute-info" commands. */
12396 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12397
12398 /* "redistribute" commands. */
12399 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12400 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12401 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12402 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12403 install_element(BGP_NODE,
12404 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12405 install_element(BGP_NODE,
12406 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12407 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12408 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12409 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12410 install_element(BGP_NODE,
12411 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12412 install_element(BGP_NODE,
12413 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12414 install_element(BGP_NODE,
12415 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12417 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12418 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12419 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12420 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12421 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12422 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12423 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12424 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12425 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12426 install_element(BGP_IPV4_NODE,
12427 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12428 install_element(BGP_IPV4_NODE,
12429 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12430 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12431 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12432 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12433 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12434 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12435 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12436
12437 /* ttl_security commands */
12438 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12439 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12440
12441 /* "show [ip] bgp memory" commands. */
12442 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12443
acf71666
MK
12444 /* "show bgp martian next-hop" */
12445 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12446
d62a17ae 12447 /* "show [ip] bgp views" commands. */
12448 install_element(VIEW_NODE, &show_bgp_views_cmd);
12449
12450 /* "show [ip] bgp vrfs" commands. */
12451 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12452
12453 /* Community-list. */
12454 community_list_vty();
718e3744 12455}
6b0655a2 12456
718e3744 12457#include "memory.h"
12458#include "bgp_regex.h"
12459#include "bgp_clist.h"
12460#include "bgp_ecommunity.h"
12461
12462/* VTY functions. */
12463
12464/* Direction value to string conversion. */
d62a17ae 12465static const char *community_direct_str(int direct)
12466{
12467 switch (direct) {
12468 case COMMUNITY_DENY:
12469 return "deny";
12470 case COMMUNITY_PERMIT:
12471 return "permit";
12472 default:
12473 return "unknown";
12474 }
718e3744 12475}
12476
12477/* Display error string. */
d62a17ae 12478static void community_list_perror(struct vty *vty, int ret)
12479{
12480 switch (ret) {
12481 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12482 vty_out(vty, "%% Can't find community-list\n");
12483 break;
12484 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12485 vty_out(vty, "%% Malformed community-list value\n");
12486 break;
12487 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12488 vty_out(vty,
12489 "%% Community name conflict, previously defined as standard community\n");
12490 break;
12491 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12492 vty_out(vty,
12493 "%% Community name conflict, previously defined as expanded community\n");
12494 break;
12495 }
718e3744 12496}
12497
5bf15956
DW
12498/* "community-list" keyword help string. */
12499#define COMMUNITY_LIST_STR "Add a community list entry\n"
12500
5bf15956 12501/* ip community-list standard */
718e3744 12502DEFUN (ip_community_list_standard,
12503 ip_community_list_standard_cmd,
e961923c 12504 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12505 IP_STR
12506 COMMUNITY_LIST_STR
12507 "Community list number (standard)\n"
5bf15956 12508 "Add an standard community-list entry\n"
718e3744 12509 "Community list name\n"
12510 "Specify community to reject\n"
12511 "Specify community to accept\n"
12512 COMMUNITY_VAL_STR)
12513{
d62a17ae 12514 char *cl_name_or_number = NULL;
12515 int direct = 0;
12516 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12517
d62a17ae 12518 int idx = 0;
12519 argv_find(argv, argc, "(1-99)", &idx);
12520 argv_find(argv, argc, "WORD", &idx);
12521 cl_name_or_number = argv[idx]->arg;
12522 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12523 : COMMUNITY_DENY;
12524 argv_find(argv, argc, "AA:NN", &idx);
12525 char *str = argv_concat(argv, argc, idx);
42f914d4 12526
d62a17ae 12527 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12528 style);
42f914d4 12529
d62a17ae 12530 XFREE(MTYPE_TMP, str);
42f914d4 12531
d62a17ae 12532 if (ret < 0) {
12533 /* Display error string. */
12534 community_list_perror(vty, ret);
12535 return CMD_WARNING_CONFIG_FAILED;
12536 }
42f914d4 12537
d62a17ae 12538 return CMD_SUCCESS;
718e3744 12539}
12540
fee6e4e4 12541DEFUN (no_ip_community_list_standard_all,
12542 no_ip_community_list_standard_all_cmd,
e961923c 12543 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12544 NO_STR
12545 IP_STR
12546 COMMUNITY_LIST_STR
12547 "Community list number (standard)\n"
5bf15956
DW
12548 "Add an standard community-list entry\n"
12549 "Community list name\n"
718e3744 12550 "Specify community to reject\n"
12551 "Specify community to accept\n"
12552 COMMUNITY_VAL_STR)
12553{
d62a17ae 12554 int delete_all = 0;
42f914d4 12555
d62a17ae 12556 char *cl_name_or_number = NULL;
12557 int direct = 0;
12558 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12559
d62a17ae 12560 int idx = 0;
12561 argv_find(argv, argc, "(1-99)", &idx);
12562 argv_find(argv, argc, "WORD", &idx);
12563 cl_name_or_number = argv[idx]->arg;
12564 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12565 : COMMUNITY_DENY;
12566 argv_find(argv, argc, "AA:NN", &idx);
12567 char *str = argv_concat(argv, argc, idx);
42f914d4 12568
d62a17ae 12569 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12570 direct, style, delete_all);
42f914d4 12571
d62a17ae 12572 XFREE(MTYPE_TMP, str);
daf9ddbb 12573
d62a17ae 12574 if (ret < 0) {
12575 community_list_perror(vty, ret);
12576 return CMD_WARNING_CONFIG_FAILED;
12577 }
42f914d4 12578
d62a17ae 12579 return CMD_SUCCESS;
718e3744 12580}
12581
5bf15956
DW
12582/* ip community-list expanded */
12583DEFUN (ip_community_list_expanded_all,
12584 ip_community_list_expanded_all_cmd,
42f914d4 12585 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12586 IP_STR
12587 COMMUNITY_LIST_STR
12588 "Community list number (expanded)\n"
5bf15956 12589 "Add an expanded community-list entry\n"
718e3744 12590 "Community list name\n"
12591 "Specify community to reject\n"
12592 "Specify community to accept\n"
12593 COMMUNITY_VAL_STR)
12594{
d62a17ae 12595 char *cl_name_or_number = NULL;
12596 int direct = 0;
12597 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12598
d62a17ae 12599 int idx = 0;
12600 argv_find(argv, argc, "(100-500)", &idx);
12601 argv_find(argv, argc, "WORD", &idx);
12602 cl_name_or_number = argv[idx]->arg;
12603 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12604 : COMMUNITY_DENY;
12605 argv_find(argv, argc, "AA:NN", &idx);
12606 char *str = argv_concat(argv, argc, idx);
42f914d4 12607
d62a17ae 12608 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12609 style);
42f914d4 12610
d62a17ae 12611 XFREE(MTYPE_TMP, str);
42f914d4 12612
d62a17ae 12613 if (ret < 0) {
12614 /* Display error string. */
12615 community_list_perror(vty, ret);
12616 return CMD_WARNING_CONFIG_FAILED;
12617 }
42f914d4 12618
d62a17ae 12619 return CMD_SUCCESS;
718e3744 12620}
12621
5bf15956
DW
12622DEFUN (no_ip_community_list_expanded_all,
12623 no_ip_community_list_expanded_all_cmd,
42f914d4 12624 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12625 NO_STR
12626 IP_STR
12627 COMMUNITY_LIST_STR
5bf15956
DW
12628 "Community list number (expanded)\n"
12629 "Add an expanded community-list entry\n"
718e3744 12630 "Community list name\n"
12631 "Specify community to reject\n"
12632 "Specify community to accept\n"
5bf15956 12633 COMMUNITY_VAL_STR)
718e3744 12634{
d62a17ae 12635 int delete_all = 0;
42f914d4 12636
d62a17ae 12637 char *cl_name_or_number = NULL;
12638 int direct = 0;
12639 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12640
d62a17ae 12641 int idx = 0;
12642 argv_find(argv, argc, "(100-500)", &idx);
12643 argv_find(argv, argc, "WORD", &idx);
12644 cl_name_or_number = argv[idx]->arg;
12645 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12646 : COMMUNITY_DENY;
12647 argv_find(argv, argc, "AA:NN", &idx);
12648 char *str = argv_concat(argv, argc, idx);
42f914d4 12649
d62a17ae 12650 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12651 direct, style, delete_all);
42f914d4 12652
d62a17ae 12653 XFREE(MTYPE_TMP, str);
daf9ddbb 12654
d62a17ae 12655 if (ret < 0) {
12656 community_list_perror(vty, ret);
12657 return CMD_WARNING_CONFIG_FAILED;
12658 }
42f914d4 12659
d62a17ae 12660 return CMD_SUCCESS;
718e3744 12661}
12662
d62a17ae 12663static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12664{
d62a17ae 12665 struct community_entry *entry;
718e3744 12666
d62a17ae 12667 for (entry = list->head; entry; entry = entry->next) {
12668 if (entry == list->head) {
12669 if (all_digit(list->name))
12670 vty_out(vty, "Community %s list %s\n",
12671 entry->style == COMMUNITY_LIST_STANDARD
12672 ? "standard"
12673 : "(expanded) access",
12674 list->name);
12675 else
12676 vty_out(vty, "Named Community %s list %s\n",
12677 entry->style == COMMUNITY_LIST_STANDARD
12678 ? "standard"
12679 : "expanded",
12680 list->name);
12681 }
12682 if (entry->any)
12683 vty_out(vty, " %s\n",
12684 community_direct_str(entry->direct));
12685 else
12686 vty_out(vty, " %s %s\n",
12687 community_direct_str(entry->direct),
12688 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 12689 ? community_str(entry->u.com, false)
d62a17ae 12690 : entry->config);
12691 }
718e3744 12692}
12693
12694DEFUN (show_ip_community_list,
12695 show_ip_community_list_cmd,
12696 "show ip community-list",
12697 SHOW_STR
12698 IP_STR
12699 "List community-list\n")
12700{
d62a17ae 12701 struct community_list *list;
12702 struct community_list_master *cm;
718e3744 12703
d62a17ae 12704 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12705 if (!cm)
12706 return CMD_SUCCESS;
718e3744 12707
d62a17ae 12708 for (list = cm->num.head; list; list = list->next)
12709 community_list_show(vty, list);
718e3744 12710
d62a17ae 12711 for (list = cm->str.head; list; list = list->next)
12712 community_list_show(vty, list);
718e3744 12713
d62a17ae 12714 return CMD_SUCCESS;
718e3744 12715}
12716
12717DEFUN (show_ip_community_list_arg,
12718 show_ip_community_list_arg_cmd,
6147e2c6 12719 "show ip community-list <(1-500)|WORD>",
718e3744 12720 SHOW_STR
12721 IP_STR
12722 "List community-list\n"
12723 "Community-list number\n"
12724 "Community-list name\n")
12725{
d62a17ae 12726 int idx_comm_list = 3;
12727 struct community_list *list;
718e3744 12728
d62a17ae 12729 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12730 COMMUNITY_LIST_MASTER);
12731 if (!list) {
12732 vty_out(vty, "%% Can't find community-list\n");
12733 return CMD_WARNING;
12734 }
718e3744 12735
d62a17ae 12736 community_list_show(vty, list);
718e3744 12737
d62a17ae 12738 return CMD_SUCCESS;
718e3744 12739}
6b0655a2 12740
57d187bc
JS
12741/*
12742 * Large Community code.
12743 */
d62a17ae 12744static int lcommunity_list_set_vty(struct vty *vty, int argc,
12745 struct cmd_token **argv, int style,
12746 int reject_all_digit_name)
12747{
12748 int ret;
12749 int direct;
12750 char *str;
12751 int idx = 0;
12752 char *cl_name;
12753
12754 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12755 : COMMUNITY_DENY;
12756
12757 /* All digit name check. */
12758 idx = 0;
12759 argv_find(argv, argc, "WORD", &idx);
12760 argv_find(argv, argc, "(1-99)", &idx);
12761 argv_find(argv, argc, "(100-500)", &idx);
12762 cl_name = argv[idx]->arg;
12763 if (reject_all_digit_name && all_digit(cl_name)) {
12764 vty_out(vty, "%% Community name cannot have all digits\n");
12765 return CMD_WARNING_CONFIG_FAILED;
12766 }
12767
12768 idx = 0;
12769 argv_find(argv, argc, "AA:BB:CC", &idx);
12770 argv_find(argv, argc, "LINE", &idx);
12771 /* Concat community string argument. */
12772 if (idx)
12773 str = argv_concat(argv, argc, idx);
12774 else
12775 str = NULL;
12776
12777 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12778
12779 /* Free temporary community list string allocated by
12780 argv_concat(). */
12781 if (str)
12782 XFREE(MTYPE_TMP, str);
12783
12784 if (ret < 0) {
12785 community_list_perror(vty, ret);
12786 return CMD_WARNING_CONFIG_FAILED;
12787 }
12788 return CMD_SUCCESS;
12789}
12790
12791static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12792 struct cmd_token **argv, int style)
12793{
12794 int ret;
12795 int direct = 0;
12796 char *str = NULL;
12797 int idx = 0;
12798
12799 argv_find(argv, argc, "permit", &idx);
12800 argv_find(argv, argc, "deny", &idx);
12801
12802 if (idx) {
12803 /* Check the list direct. */
12804 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12805 direct = COMMUNITY_PERMIT;
12806 else
12807 direct = COMMUNITY_DENY;
12808
12809 idx = 0;
12810 argv_find(argv, argc, "LINE", &idx);
12811 argv_find(argv, argc, "AA:AA:NN", &idx);
12812 /* Concat community string argument. */
12813 str = argv_concat(argv, argc, idx);
12814 }
12815
12816 idx = 0;
12817 argv_find(argv, argc, "(1-99)", &idx);
12818 argv_find(argv, argc, "(100-500)", &idx);
12819 argv_find(argv, argc, "WORD", &idx);
12820
12821 /* Unset community list. */
12822 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12823 style);
12824
12825 /* Free temporary community list string allocated by
12826 argv_concat(). */
12827 if (str)
12828 XFREE(MTYPE_TMP, str);
12829
12830 if (ret < 0) {
12831 community_list_perror(vty, ret);
12832 return CMD_WARNING_CONFIG_FAILED;
12833 }
12834
12835 return CMD_SUCCESS;
57d187bc
JS
12836}
12837
12838/* "large-community-list" keyword help string. */
12839#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12840#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12841
12842DEFUN (ip_lcommunity_list_standard,
12843 ip_lcommunity_list_standard_cmd,
52951b63
DS
12844 "ip large-community-list (1-99) <deny|permit>",
12845 IP_STR
12846 LCOMMUNITY_LIST_STR
12847 "Large Community list number (standard)\n"
12848 "Specify large community to reject\n"
7111c1a0 12849 "Specify large community to accept\n")
52951b63 12850{
d62a17ae 12851 return lcommunity_list_set_vty(vty, argc, argv,
12852 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12853}
12854
12855DEFUN (ip_lcommunity_list_standard1,
12856 ip_lcommunity_list_standard1_cmd,
12857 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12858 IP_STR
12859 LCOMMUNITY_LIST_STR
12860 "Large Community list number (standard)\n"
12861 "Specify large community to reject\n"
12862 "Specify large community to accept\n"
12863 LCOMMUNITY_VAL_STR)
12864{
d62a17ae 12865 return lcommunity_list_set_vty(vty, argc, argv,
12866 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12867}
12868
12869DEFUN (ip_lcommunity_list_expanded,
12870 ip_lcommunity_list_expanded_cmd,
12871 "ip large-community-list (100-500) <deny|permit> LINE...",
12872 IP_STR
12873 LCOMMUNITY_LIST_STR
12874 "Large Community list number (expanded)\n"
12875 "Specify large community to reject\n"
12876 "Specify large community to accept\n"
12877 "An ordered list as a regular-expression\n")
12878{
d62a17ae 12879 return lcommunity_list_set_vty(vty, argc, argv,
12880 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12881}
12882
12883DEFUN (ip_lcommunity_list_name_standard,
12884 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12885 "ip large-community-list standard WORD <deny|permit>",
12886 IP_STR
12887 LCOMMUNITY_LIST_STR
12888 "Specify standard large-community-list\n"
12889 "Large Community list name\n"
12890 "Specify large community to reject\n"
12891 "Specify large community to accept\n")
12892{
d62a17ae 12893 return lcommunity_list_set_vty(vty, argc, argv,
12894 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12895}
12896
12897DEFUN (ip_lcommunity_list_name_standard1,
12898 ip_lcommunity_list_name_standard1_cmd,
12899 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12900 IP_STR
12901 LCOMMUNITY_LIST_STR
12902 "Specify standard large-community-list\n"
12903 "Large Community list name\n"
12904 "Specify large community to reject\n"
12905 "Specify large community to accept\n"
12906 LCOMMUNITY_VAL_STR)
12907{
d62a17ae 12908 return lcommunity_list_set_vty(vty, argc, argv,
12909 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12910}
12911
12912DEFUN (ip_lcommunity_list_name_expanded,
12913 ip_lcommunity_list_name_expanded_cmd,
12914 "ip large-community-list expanded WORD <deny|permit> LINE...",
12915 IP_STR
12916 LCOMMUNITY_LIST_STR
12917 "Specify expanded large-community-list\n"
12918 "Large Community list name\n"
12919 "Specify large community to reject\n"
12920 "Specify large community to accept\n"
12921 "An ordered list as a regular-expression\n")
12922{
d62a17ae 12923 return lcommunity_list_set_vty(vty, argc, argv,
12924 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12925}
12926
12927DEFUN (no_ip_lcommunity_list_standard_all,
12928 no_ip_lcommunity_list_standard_all_cmd,
12929 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12930 NO_STR
12931 IP_STR
12932 LCOMMUNITY_LIST_STR
12933 "Large Community list number (standard)\n"
12934 "Large Community list number (expanded)\n"
12935 "Large Community list name\n")
12936{
d62a17ae 12937 return lcommunity_list_unset_vty(vty, argc, argv,
12938 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12939}
12940
12941DEFUN (no_ip_lcommunity_list_name_expanded_all,
12942 no_ip_lcommunity_list_name_expanded_all_cmd,
12943 "no ip large-community-list expanded WORD",
12944 NO_STR
12945 IP_STR
12946 LCOMMUNITY_LIST_STR
12947 "Specify expanded large-community-list\n"
12948 "Large Community list name\n")
12949{
d62a17ae 12950 return lcommunity_list_unset_vty(vty, argc, argv,
12951 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12952}
12953
12954DEFUN (no_ip_lcommunity_list_standard,
12955 no_ip_lcommunity_list_standard_cmd,
12956 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12957 NO_STR
12958 IP_STR
12959 LCOMMUNITY_LIST_STR
12960 "Large Community list number (standard)\n"
12961 "Specify large community to reject\n"
12962 "Specify large community to accept\n"
12963 LCOMMUNITY_VAL_STR)
12964{
d62a17ae 12965 return lcommunity_list_unset_vty(vty, argc, argv,
12966 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12967}
12968
12969DEFUN (no_ip_lcommunity_list_expanded,
12970 no_ip_lcommunity_list_expanded_cmd,
12971 "no ip large-community-list (100-500) <deny|permit> LINE...",
12972 NO_STR
12973 IP_STR
12974 LCOMMUNITY_LIST_STR
12975 "Large Community list number (expanded)\n"
12976 "Specify large community to reject\n"
12977 "Specify large community to accept\n"
12978 "An ordered list as a regular-expression\n")
12979{
d62a17ae 12980 return lcommunity_list_unset_vty(vty, argc, argv,
12981 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12982}
12983
12984DEFUN (no_ip_lcommunity_list_name_standard,
12985 no_ip_lcommunity_list_name_standard_cmd,
12986 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12987 NO_STR
12988 IP_STR
12989 LCOMMUNITY_LIST_STR
12990 "Specify standard large-community-list\n"
12991 "Large Community list name\n"
12992 "Specify large community to reject\n"
12993 "Specify large community to accept\n"
12994 LCOMMUNITY_VAL_STR)
12995{
d62a17ae 12996 return lcommunity_list_unset_vty(vty, argc, argv,
12997 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12998}
12999
13000DEFUN (no_ip_lcommunity_list_name_expanded,
13001 no_ip_lcommunity_list_name_expanded_cmd,
13002 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13003 NO_STR
13004 IP_STR
13005 LCOMMUNITY_LIST_STR
13006 "Specify expanded large-community-list\n"
13007 "Large community list name\n"
13008 "Specify large community to reject\n"
13009 "Specify large community to accept\n"
13010 "An ordered list as a regular-expression\n")
13011{
d62a17ae 13012 return lcommunity_list_unset_vty(vty, argc, argv,
13013 LARGE_COMMUNITY_LIST_EXPANDED);
13014}
13015
13016static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13017{
13018 struct community_entry *entry;
13019
13020 for (entry = list->head; entry; entry = entry->next) {
13021 if (entry == list->head) {
13022 if (all_digit(list->name))
13023 vty_out(vty, "Large community %s list %s\n",
13024 entry->style == EXTCOMMUNITY_LIST_STANDARD
13025 ? "standard"
13026 : "(expanded) access",
13027 list->name);
13028 else
13029 vty_out(vty,
13030 "Named large community %s list %s\n",
13031 entry->style == EXTCOMMUNITY_LIST_STANDARD
13032 ? "standard"
13033 : "expanded",
13034 list->name);
13035 }
13036 if (entry->any)
13037 vty_out(vty, " %s\n",
13038 community_direct_str(entry->direct));
13039 else
13040 vty_out(vty, " %s %s\n",
13041 community_direct_str(entry->direct),
13042 entry->style == EXTCOMMUNITY_LIST_STANDARD
13043 ? entry->u.ecom->str
13044 : entry->config);
13045 }
57d187bc
JS
13046}
13047
13048DEFUN (show_ip_lcommunity_list,
13049 show_ip_lcommunity_list_cmd,
13050 "show ip large-community-list",
13051 SHOW_STR
13052 IP_STR
13053 "List large-community list\n")
13054{
d62a17ae 13055 struct community_list *list;
13056 struct community_list_master *cm;
57d187bc 13057
d62a17ae 13058 cm = community_list_master_lookup(bgp_clist,
13059 LARGE_COMMUNITY_LIST_MASTER);
13060 if (!cm)
13061 return CMD_SUCCESS;
57d187bc 13062
d62a17ae 13063 for (list = cm->num.head; list; list = list->next)
13064 lcommunity_list_show(vty, list);
57d187bc 13065
d62a17ae 13066 for (list = cm->str.head; list; list = list->next)
13067 lcommunity_list_show(vty, list);
57d187bc 13068
d62a17ae 13069 return CMD_SUCCESS;
57d187bc
JS
13070}
13071
13072DEFUN (show_ip_lcommunity_list_arg,
13073 show_ip_lcommunity_list_arg_cmd,
13074 "show ip large-community-list <(1-500)|WORD>",
13075 SHOW_STR
13076 IP_STR
13077 "List large-community list\n"
13078 "large-community-list number\n"
13079 "large-community-list name\n")
13080{
d62a17ae 13081 struct community_list *list;
57d187bc 13082
d62a17ae 13083 list = community_list_lookup(bgp_clist, argv[3]->arg,
13084 LARGE_COMMUNITY_LIST_MASTER);
13085 if (!list) {
13086 vty_out(vty, "%% Can't find extcommunity-list\n");
13087 return CMD_WARNING;
13088 }
57d187bc 13089
d62a17ae 13090 lcommunity_list_show(vty, list);
57d187bc 13091
d62a17ae 13092 return CMD_SUCCESS;
57d187bc
JS
13093}
13094
718e3744 13095/* "extcommunity-list" keyword help string. */
13096#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13097#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13098
13099DEFUN (ip_extcommunity_list_standard,
13100 ip_extcommunity_list_standard_cmd,
e961923c 13101 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13102 IP_STR
13103 EXTCOMMUNITY_LIST_STR
13104 "Extended Community list number (standard)\n"
718e3744 13105 "Specify standard extcommunity-list\n"
5bf15956 13106 "Community list name\n"
718e3744 13107 "Specify community to reject\n"
13108 "Specify community to accept\n"
13109 EXTCOMMUNITY_VAL_STR)
13110{
d62a17ae 13111 int style = EXTCOMMUNITY_LIST_STANDARD;
13112 int direct = 0;
13113 char *cl_number_or_name = NULL;
42f914d4 13114
d62a17ae 13115 int idx = 0;
13116 argv_find(argv, argc, "(1-99)", &idx);
13117 argv_find(argv, argc, "WORD", &idx);
13118 cl_number_or_name = argv[idx]->arg;
13119 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13120 : COMMUNITY_DENY;
13121 argv_find(argv, argc, "AA:NN", &idx);
13122 char *str = argv_concat(argv, argc, idx);
42f914d4 13123
d62a17ae 13124 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13125 direct, style);
42f914d4 13126
d62a17ae 13127 XFREE(MTYPE_TMP, str);
42f914d4 13128
d62a17ae 13129 if (ret < 0) {
13130 community_list_perror(vty, ret);
13131 return CMD_WARNING_CONFIG_FAILED;
13132 }
42f914d4 13133
d62a17ae 13134 return CMD_SUCCESS;
718e3744 13135}
13136
718e3744 13137DEFUN (ip_extcommunity_list_name_expanded,
13138 ip_extcommunity_list_name_expanded_cmd,
e961923c 13139 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13140 IP_STR
13141 EXTCOMMUNITY_LIST_STR
5bf15956 13142 "Extended Community list number (expanded)\n"
718e3744 13143 "Specify expanded extcommunity-list\n"
13144 "Extended Community list name\n"
13145 "Specify community to reject\n"
13146 "Specify community to accept\n"
13147 "An ordered list as a regular-expression\n")
13148{
d62a17ae 13149 int style = EXTCOMMUNITY_LIST_EXPANDED;
13150 int direct = 0;
13151 char *cl_number_or_name = NULL;
42f914d4 13152
d62a17ae 13153 int idx = 0;
13154 argv_find(argv, argc, "(100-500)", &idx);
13155 argv_find(argv, argc, "WORD", &idx);
13156 cl_number_or_name = argv[idx]->arg;
13157 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13158 : COMMUNITY_DENY;
13159 argv_find(argv, argc, "LINE", &idx);
13160 char *str = argv_concat(argv, argc, idx);
42f914d4 13161
d62a17ae 13162 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13163 direct, style);
42f914d4 13164
d62a17ae 13165 XFREE(MTYPE_TMP, str);
42f914d4 13166
d62a17ae 13167 if (ret < 0) {
13168 community_list_perror(vty, ret);
13169 return CMD_WARNING_CONFIG_FAILED;
13170 }
42f914d4 13171
d62a17ae 13172 return CMD_SUCCESS;
718e3744 13173}
13174
fee6e4e4 13175DEFUN (no_ip_extcommunity_list_standard_all,
13176 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13177 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13178 NO_STR
13179 IP_STR
13180 EXTCOMMUNITY_LIST_STR
13181 "Extended Community list number (standard)\n"
718e3744 13182 "Specify standard extcommunity-list\n"
5bf15956 13183 "Community list name\n"
718e3744 13184 "Specify community to reject\n"
13185 "Specify community to accept\n"
13186 EXTCOMMUNITY_VAL_STR)
13187{
d62a17ae 13188 int deleteall = 0;
42f914d4 13189
d62a17ae 13190 int style = EXTCOMMUNITY_LIST_STANDARD;
13191 int direct = 0;
13192 char *cl_number_or_name = NULL;
42f914d4 13193
d62a17ae 13194 int idx = 0;
13195 argv_find(argv, argc, "(1-99)", &idx);
13196 argv_find(argv, argc, "WORD", &idx);
13197 cl_number_or_name = argv[idx]->arg;
13198 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13199 : COMMUNITY_DENY;
13200 argv_find(argv, argc, "AA:NN", &idx);
13201 char *str = argv_concat(argv, argc, idx);
42f914d4 13202
d62a17ae 13203 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13204 direct, style, deleteall);
42f914d4 13205
d62a17ae 13206 XFREE(MTYPE_TMP, str);
42f914d4 13207
d62a17ae 13208 if (ret < 0) {
13209 community_list_perror(vty, ret);
13210 return CMD_WARNING_CONFIG_FAILED;
13211 }
42f914d4 13212
d62a17ae 13213 return CMD_SUCCESS;
718e3744 13214}
13215
5bf15956
DW
13216DEFUN (no_ip_extcommunity_list_expanded_all,
13217 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13218 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13219 NO_STR
13220 IP_STR
13221 EXTCOMMUNITY_LIST_STR
13222 "Extended Community list number (expanded)\n"
718e3744 13223 "Specify expanded extcommunity-list\n"
5bf15956 13224 "Extended Community list name\n"
718e3744 13225 "Specify community to reject\n"
13226 "Specify community to accept\n"
13227 "An ordered list as a regular-expression\n")
13228{
d62a17ae 13229 int deleteall = 0;
42f914d4 13230
d62a17ae 13231 int style = EXTCOMMUNITY_LIST_EXPANDED;
13232 int direct = 0;
13233 char *cl_number_or_name = NULL;
42f914d4 13234
d62a17ae 13235 int idx = 0;
13236 argv_find(argv, argc, "(100-500)", &idx);
13237 argv_find(argv, argc, "WORD", &idx);
13238 cl_number_or_name = argv[idx]->arg;
13239 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13240 : COMMUNITY_DENY;
13241 argv_find(argv, argc, "LINE", &idx);
13242 char *str = argv_concat(argv, argc, idx);
42f914d4 13243
d62a17ae 13244 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13245 direct, style, deleteall);
42f914d4 13246
d62a17ae 13247 XFREE(MTYPE_TMP, str);
42f914d4 13248
d62a17ae 13249 if (ret < 0) {
13250 community_list_perror(vty, ret);
13251 return CMD_WARNING_CONFIG_FAILED;
13252 }
42f914d4 13253
d62a17ae 13254 return CMD_SUCCESS;
718e3744 13255}
13256
d62a17ae 13257static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13258{
d62a17ae 13259 struct community_entry *entry;
718e3744 13260
d62a17ae 13261 for (entry = list->head; entry; entry = entry->next) {
13262 if (entry == list->head) {
13263 if (all_digit(list->name))
13264 vty_out(vty, "Extended community %s list %s\n",
13265 entry->style == EXTCOMMUNITY_LIST_STANDARD
13266 ? "standard"
13267 : "(expanded) access",
13268 list->name);
13269 else
13270 vty_out(vty,
13271 "Named extended community %s list %s\n",
13272 entry->style == EXTCOMMUNITY_LIST_STANDARD
13273 ? "standard"
13274 : "expanded",
13275 list->name);
13276 }
13277 if (entry->any)
13278 vty_out(vty, " %s\n",
13279 community_direct_str(entry->direct));
13280 else
13281 vty_out(vty, " %s %s\n",
13282 community_direct_str(entry->direct),
13283 entry->style == EXTCOMMUNITY_LIST_STANDARD
13284 ? entry->u.ecom->str
13285 : entry->config);
13286 }
718e3744 13287}
13288
13289DEFUN (show_ip_extcommunity_list,
13290 show_ip_extcommunity_list_cmd,
13291 "show ip extcommunity-list",
13292 SHOW_STR
13293 IP_STR
13294 "List extended-community list\n")
13295{
d62a17ae 13296 struct community_list *list;
13297 struct community_list_master *cm;
718e3744 13298
d62a17ae 13299 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13300 if (!cm)
13301 return CMD_SUCCESS;
718e3744 13302
d62a17ae 13303 for (list = cm->num.head; list; list = list->next)
13304 extcommunity_list_show(vty, list);
718e3744 13305
d62a17ae 13306 for (list = cm->str.head; list; list = list->next)
13307 extcommunity_list_show(vty, list);
718e3744 13308
d62a17ae 13309 return CMD_SUCCESS;
718e3744 13310}
13311
13312DEFUN (show_ip_extcommunity_list_arg,
13313 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13314 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13315 SHOW_STR
13316 IP_STR
13317 "List extended-community list\n"
13318 "Extcommunity-list number\n"
13319 "Extcommunity-list name\n")
13320{
d62a17ae 13321 int idx_comm_list = 3;
13322 struct community_list *list;
718e3744 13323
d62a17ae 13324 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13325 EXTCOMMUNITY_LIST_MASTER);
13326 if (!list) {
13327 vty_out(vty, "%% Can't find extcommunity-list\n");
13328 return CMD_WARNING;
13329 }
718e3744 13330
d62a17ae 13331 extcommunity_list_show(vty, list);
718e3744 13332
d62a17ae 13333 return CMD_SUCCESS;
718e3744 13334}
6b0655a2 13335
718e3744 13336/* Return configuration string of community-list entry. */
d62a17ae 13337static const char *community_list_config_str(struct community_entry *entry)
718e3744 13338{
d62a17ae 13339 const char *str;
718e3744 13340
d62a17ae 13341 if (entry->any)
13342 str = "";
13343 else {
13344 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 13345 str = community_str(entry->u.com, false);
d62a17ae 13346 else
13347 str = entry->config;
13348 }
13349 return str;
718e3744 13350}
13351
13352/* Display community-list and extcommunity-list configuration. */
d62a17ae 13353static int community_list_config_write(struct vty *vty)
13354{
13355 struct community_list *list;
13356 struct community_entry *entry;
13357 struct community_list_master *cm;
13358 int write = 0;
13359
13360 /* Community-list. */
13361 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13362
13363 for (list = cm->num.head; list; list = list->next)
13364 for (entry = list->head; entry; entry = entry->next) {
13365 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13366 community_direct_str(entry->direct),
13367 community_list_config_str(entry));
13368 write++;
13369 }
13370 for (list = cm->str.head; list; list = list->next)
13371 for (entry = list->head; entry; entry = entry->next) {
13372 vty_out(vty, "ip community-list %s %s %s %s\n",
13373 entry->style == COMMUNITY_LIST_STANDARD
13374 ? "standard"
13375 : "expanded",
13376 list->name, community_direct_str(entry->direct),
13377 community_list_config_str(entry));
13378 write++;
13379 }
13380
13381 /* Extcommunity-list. */
13382 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13383
13384 for (list = cm->num.head; list; list = list->next)
13385 for (entry = list->head; entry; entry = entry->next) {
13386 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13387 list->name, community_direct_str(entry->direct),
13388 community_list_config_str(entry));
13389 write++;
13390 }
13391 for (list = cm->str.head; list; list = list->next)
13392 for (entry = list->head; entry; entry = entry->next) {
13393 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13394 entry->style == EXTCOMMUNITY_LIST_STANDARD
13395 ? "standard"
13396 : "expanded",
13397 list->name, community_direct_str(entry->direct),
13398 community_list_config_str(entry));
13399 write++;
13400 }
13401
13402
13403 /* lcommunity-list. */
13404 cm = community_list_master_lookup(bgp_clist,
13405 LARGE_COMMUNITY_LIST_MASTER);
13406
13407 for (list = cm->num.head; list; list = list->next)
13408 for (entry = list->head; entry; entry = entry->next) {
13409 vty_out(vty, "ip large-community-list %s %s %s\n",
13410 list->name, community_direct_str(entry->direct),
13411 community_list_config_str(entry));
13412 write++;
13413 }
13414 for (list = cm->str.head; list; list = list->next)
13415 for (entry = list->head; entry; entry = entry->next) {
13416 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13417 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13418 ? "standard"
13419 : "expanded",
13420 list->name, community_direct_str(entry->direct),
13421 community_list_config_str(entry));
13422 write++;
13423 }
13424
13425 return write;
13426}
13427
13428static struct cmd_node community_list_node = {
13429 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13430};
13431
d62a17ae 13432static void community_list_vty(void)
13433{
13434 install_node(&community_list_node, community_list_config_write);
13435
13436 /* Community-list. */
13437 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13438 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13439 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13440 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13441 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13442 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13443
13444 /* Extcommunity-list. */
13445 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13446 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13447 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13448 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13449 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13450 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13451
13452 /* Large Community List */
13453 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13454 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13455 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13456 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13457 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13458 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13459 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13460 install_element(CONFIG_NODE,
13461 &no_ip_lcommunity_list_name_expanded_all_cmd);
13462 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13463 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13464 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13465 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13466 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13467 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13468}