]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
staticd: Do not ready prefix for printing till it's decoded
[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"
5d5ba018 37#include "frrstr.h"
718e3744 38
39#include "bgpd/bgpd.h"
4bf6a362 40#include "bgpd/bgp_advertise.h"
718e3744 41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_aspath.h"
43#include "bgpd/bgp_community.h"
4bf6a362 44#include "bgpd/bgp_ecommunity.h"
57d187bc 45#include "bgpd/bgp_lcommunity.h"
4bf6a362 46#include "bgpd/bgp_damp.h"
718e3744 47#include "bgpd/bgp_debug.h"
14454c9f 48#include "bgpd/bgp_errors.h"
e0701b79 49#include "bgpd/bgp_fsm.h"
4bf6a362 50#include "bgpd/bgp_nexthop.h"
718e3744 51#include "bgpd/bgp_open.h"
4bf6a362 52#include "bgpd/bgp_regex.h"
718e3744 53#include "bgpd/bgp_route.h"
c016b6c7 54#include "bgpd/bgp_mplsvpn.h"
718e3744 55#include "bgpd/bgp_zebra.h"
fee0f4c6 56#include "bgpd/bgp_table.h"
94f2b392 57#include "bgpd/bgp_vty.h"
165b5fff 58#include "bgpd/bgp_mpath.h"
cb1faec9 59#include "bgpd/bgp_packet.h"
3f9c7369 60#include "bgpd/bgp_updgrp.h"
c43ed2e4 61#include "bgpd/bgp_bfd.h"
555e09d4 62#include "bgpd/bgp_io.h"
94c2f693 63#include "bgpd/bgp_evpn.h"
dcc68b5e 64#include "bgpd/bgp_addpath.h"
718e3744 65
d62a17ae 66static struct peer_group *listen_range_exists(struct bgp *bgp,
67 struct prefix *range, int exact);
68
69static enum node_type bgp_node_type(afi_t afi, safi_t safi)
70{
71 switch (afi) {
72 case AFI_IP:
73 switch (safi) {
74 case SAFI_UNICAST:
75 return BGP_IPV4_NODE;
76 break;
77 case SAFI_MULTICAST:
78 return BGP_IPV4M_NODE;
79 break;
80 case SAFI_LABELED_UNICAST:
81 return BGP_IPV4L_NODE;
82 break;
83 case SAFI_MPLS_VPN:
84 return BGP_VPNV4_NODE;
85 break;
7c40bf39 86 case SAFI_FLOWSPEC:
87 return BGP_FLOWSPECV4_NODE;
5c525538
RW
88 default:
89 /* not expected */
90 return BGP_IPV4_NODE;
91 break;
d62a17ae 92 }
93 break;
94 case AFI_IP6:
95 switch (safi) {
96 case SAFI_UNICAST:
97 return BGP_IPV6_NODE;
98 break;
99 case SAFI_MULTICAST:
100 return BGP_IPV6M_NODE;
101 break;
102 case SAFI_LABELED_UNICAST:
103 return BGP_IPV6L_NODE;
104 break;
105 case SAFI_MPLS_VPN:
106 return BGP_VPNV6_NODE;
107 break;
7c40bf39 108 case SAFI_FLOWSPEC:
109 return BGP_FLOWSPECV6_NODE;
5c525538
RW
110 default:
111 /* not expected */
112 return BGP_IPV4_NODE;
113 break;
d62a17ae 114 }
115 break;
116 case AFI_L2VPN:
117 return BGP_EVPN_NODE;
118 break;
119 case AFI_MAX:
120 // We should never be here but to clarify the switch statement..
121 return BGP_IPV4_NODE;
122 break;
123 }
124
125 // Impossible to happen
126 return BGP_IPV4_NODE;
f51bae9c 127}
20eb8864 128
718e3744 129/* Utility function to get address family from current node. */
d62a17ae 130afi_t bgp_node_afi(struct vty *vty)
131{
132 afi_t afi;
133 switch (vty->node) {
134 case BGP_IPV6_NODE:
135 case BGP_IPV6M_NODE:
136 case BGP_IPV6L_NODE:
137 case BGP_VPNV6_NODE:
7c40bf39 138 case BGP_FLOWSPECV6_NODE:
d62a17ae 139 afi = AFI_IP6;
140 break;
141 case BGP_EVPN_NODE:
142 afi = AFI_L2VPN;
143 break;
144 default:
145 afi = AFI_IP;
146 break;
147 }
148 return afi;
718e3744 149}
150
151/* Utility function to get subsequent address family from current
152 node. */
d62a17ae 153safi_t bgp_node_safi(struct vty *vty)
154{
155 safi_t safi;
156 switch (vty->node) {
157 case BGP_VPNV4_NODE:
158 case BGP_VPNV6_NODE:
159 safi = SAFI_MPLS_VPN;
160 break;
161 case BGP_IPV4M_NODE:
162 case BGP_IPV6M_NODE:
163 safi = SAFI_MULTICAST;
164 break;
165 case BGP_EVPN_NODE:
166 safi = SAFI_EVPN;
167 break;
168 case BGP_IPV4L_NODE:
169 case BGP_IPV6L_NODE:
170 safi = SAFI_LABELED_UNICAST;
171 break;
7c40bf39 172 case BGP_FLOWSPECV4_NODE:
173 case BGP_FLOWSPECV6_NODE:
174 safi = SAFI_FLOWSPEC;
175 break;
d62a17ae 176 default:
177 safi = SAFI_UNICAST;
178 break;
179 }
180 return safi;
718e3744 181}
182
55f91488
QY
183/**
184 * Converts an AFI in string form to afi_t
185 *
186 * @param afi string, one of
187 * - "ipv4"
188 * - "ipv6"
81cf0de5 189 * - "l2vpn"
55f91488
QY
190 * @return the corresponding afi_t
191 */
d62a17ae 192afi_t bgp_vty_afi_from_str(const char *afi_str)
193{
194 afi_t afi = AFI_MAX; /* unknown */
195 if (strmatch(afi_str, "ipv4"))
196 afi = AFI_IP;
197 else if (strmatch(afi_str, "ipv6"))
198 afi = AFI_IP6;
81cf0de5
CS
199 else if (strmatch(afi_str, "l2vpn"))
200 afi = AFI_L2VPN;
d62a17ae 201 return afi;
202}
203
204int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
205 afi_t *afi)
206{
207 int ret = 0;
208 if (argv_find(argv, argc, "ipv4", index)) {
209 ret = 1;
210 if (afi)
211 *afi = AFI_IP;
212 } else if (argv_find(argv, argc, "ipv6", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP6;
216 }
217 return ret;
46f296b4
LB
218}
219
375a2e67 220/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 221safi_t bgp_vty_safi_from_str(const char *safi_str)
222{
223 safi_t safi = SAFI_MAX; /* unknown */
224 if (strmatch(safi_str, "multicast"))
225 safi = SAFI_MULTICAST;
226 else if (strmatch(safi_str, "unicast"))
227 safi = SAFI_UNICAST;
228 else if (strmatch(safi_str, "vpn"))
229 safi = SAFI_MPLS_VPN;
81cf0de5
CS
230 else if (strmatch(safi_str, "evpn"))
231 safi = SAFI_EVPN;
d62a17ae 232 else if (strmatch(safi_str, "labeled-unicast"))
233 safi = SAFI_LABELED_UNICAST;
7c40bf39 234 else if (strmatch(safi_str, "flowspec"))
235 safi = SAFI_FLOWSPEC;
d62a17ae 236 return safi;
237}
238
239int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
240 safi_t *safi)
241{
242 int ret = 0;
243 if (argv_find(argv, argc, "unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_UNICAST;
247 } else if (argv_find(argv, argc, "multicast", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MULTICAST;
251 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_LABELED_UNICAST;
255 } else if (argv_find(argv, argc, "vpn", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MPLS_VPN;
7c40bf39 259 } else if (argv_find(argv, argc, "flowspec", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_FLOWSPEC;
d62a17ae 263 }
264 return ret;
46f296b4
LB
265}
266
7eeee51e 267/*
f212a857 268 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 269 *
f212a857
DS
270 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
271 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
272 * to appropriate values for the calling function. This is to allow the
273 * calling function to make decisions appropriate for the show command
274 * that is being parsed.
275 *
276 * The show commands are generally of the form:
d62a17ae 277 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
278 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
279 *
280 * Since we use argv_find if the show command in particular doesn't have:
281 * [ip]
18c57037 282 * [<view|vrf> VIEWVRFNAME]
375a2e67 283 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
284 * The command parsing should still be ok.
285 *
286 * vty -> The vty for the command so we can output some useful data in
287 * the event of a parse error in the vrf.
288 * argv -> The command tokens
289 * argc -> How many command tokens we have
d62a17ae 290 * idx -> The current place in the command, generally should be 0 for this
291 * function
7eeee51e
DS
292 * afi -> The parsed afi if it was included in the show command, returned here
293 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 294 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
295 *
296 * The function returns the correct location in the parse tree for the
297 * last token found.
0e37c258
DS
298 *
299 * Returns 0 for failure to parse correctly, else the idx position of where
300 * it found the last token.
7eeee51e 301 */
d62a17ae 302int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
303 struct cmd_token **argv, int argc,
304 int *idx, afi_t *afi, safi_t *safi,
9f049418 305 struct bgp **bgp, bool use_json)
d62a17ae 306{
307 char *vrf_name = NULL;
308
309 assert(afi);
310 assert(safi);
311 assert(bgp);
312
313 if (argv_find(argv, argc, "ip", idx))
314 *afi = AFI_IP;
315
9a8bdf1c 316 if (argv_find(argv, argc, "view", idx))
d62a17ae 317 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
318 else if (argv_find(argv, argc, "vrf", idx)) {
319 vrf_name = argv[*idx + 1]->arg;
320 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
321 vrf_name = NULL;
322 }
323 if (vrf_name) {
d62a17ae 324 if (strmatch(vrf_name, "all"))
325 *bgp = NULL;
326 else {
327 *bgp = bgp_lookup_by_name(vrf_name);
328 if (!*bgp) {
ca61fd25
DS
329 if (use_json)
330 vty_out(vty, "{}\n");
331 else
332 vty_out(vty, "View/Vrf %s is unknown\n",
333 vrf_name);
d62a17ae 334 *idx = 0;
335 return 0;
336 }
337 }
338 } else {
339 *bgp = bgp_get_default();
340 if (!*bgp) {
ca61fd25
DS
341 if (use_json)
342 vty_out(vty, "{}\n");
343 else
344 vty_out(vty,
345 "Default BGP instance not found\n");
d62a17ae 346 *idx = 0;
347 return 0;
348 }
349 }
350
351 if (argv_find_and_parse_afi(argv, argc, idx, afi))
352 argv_find_and_parse_safi(argv, argc, idx, safi);
353
354 *idx += 1;
355 return *idx;
356}
357
358static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
359{
360 struct interface *ifp = NULL;
361
362 if (su->sa.sa_family == AF_INET)
363 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
364 else if (su->sa.sa_family == AF_INET6)
365 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
366 su->sin6.sin6_scope_id,
367 bgp->vrf_id);
368
369 if (ifp)
370 return 1;
371
372 return 0;
718e3744 373}
374
375/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
376/* This is used only for configuration, so disallow if attempted on
377 * a dynamic neighbor.
378 */
d62a17ae 379static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
380{
381 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
382 int ret;
383 union sockunion su;
384 struct peer *peer;
385
386 if (!bgp) {
387 return NULL;
388 }
389
390 ret = str2sockunion(ip_str, &su);
391 if (ret < 0) {
392 peer = peer_lookup_by_conf_if(bgp, ip_str);
393 if (!peer) {
394 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
395 == NULL) {
396 vty_out(vty,
397 "%% Malformed address or name: %s\n",
398 ip_str);
399 return NULL;
400 }
401 }
402 } else {
403 peer = peer_lookup(bgp, &su);
404 if (!peer) {
405 vty_out(vty,
406 "%% Specify remote-as or peer-group commands first\n");
407 return NULL;
408 }
409 if (peer_dynamic_neighbor(peer)) {
410 vty_out(vty,
411 "%% Operation not allowed on a dynamic neighbor\n");
412 return NULL;
413 }
414 }
415 return peer;
718e3744 416}
417
418/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
419/* This is used only for configuration, so disallow if attempted on
420 * a dynamic neighbor.
421 */
d62a17ae 422struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
423{
424 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
425 int ret;
426 union sockunion su;
427 struct peer *peer = NULL;
428 struct peer_group *group = NULL;
429
430 if (!bgp) {
431 return NULL;
432 }
433
434 ret = str2sockunion(peer_str, &su);
435 if (ret == 0) {
436 /* IP address, locate peer. */
437 peer = peer_lookup(bgp, &su);
438 } else {
439 /* Not IP, could match either peer configured on interface or a
440 * group. */
441 peer = peer_lookup_by_conf_if(bgp, peer_str);
442 if (!peer)
443 group = peer_group_lookup(bgp, peer_str);
444 }
445
446 if (peer) {
447 if (peer_dynamic_neighbor(peer)) {
448 vty_out(vty,
449 "%% Operation not allowed on a dynamic neighbor\n");
450 return NULL;
451 }
452
453 return peer;
454 }
455
456 if (group)
457 return group->conf;
458
459 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
460
461 return NULL;
462}
463
464int bgp_vty_return(struct vty *vty, int ret)
465{
466 const char *str = NULL;
467
468 switch (ret) {
469 case BGP_ERR_INVALID_VALUE:
470 str = "Invalid value";
471 break;
472 case BGP_ERR_INVALID_FLAG:
473 str = "Invalid flag";
474 break;
475 case BGP_ERR_PEER_GROUP_SHUTDOWN:
476 str = "Peer-group has been shutdown. Activate the peer-group first";
477 break;
478 case BGP_ERR_PEER_FLAG_CONFLICT:
479 str = "Can't set override-capability and strict-capability-match at the same time";
480 break;
481 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
482 str = "Specify remote-as or peer-group remote AS first";
483 break;
484 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
485 str = "Cannot change the peer-group. Deconfigure first";
486 break;
487 case BGP_ERR_PEER_GROUP_MISMATCH:
488 str = "Peer is not a member of this peer-group";
489 break;
490 case BGP_ERR_PEER_FILTER_CONFLICT:
491 str = "Prefix/distribute list can not co-exist";
492 break;
493 case BGP_ERR_NOT_INTERNAL_PEER:
494 str = "Invalid command. Not an internal neighbor";
495 break;
496 case BGP_ERR_REMOVE_PRIVATE_AS:
497 str = "remove-private-AS cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
500 str = "Local-AS allowed only for EBGP peers";
501 break;
502 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
503 str = "Cannot have local-as same as BGP AS number";
504 break;
505 case BGP_ERR_TCPSIG_FAILED:
506 str = "Error while applying TCP-Sig to session(s)";
507 break;
508 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
509 str = "ebgp-multihop and ttl-security cannot be configured together";
510 break;
511 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
512 str = "ttl-security only allowed for EBGP peers";
513 break;
514 case BGP_ERR_AS_OVERRIDE:
515 str = "as-override cannot be configured for IBGP peers";
516 break;
517 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
518 str = "Invalid limit for number of dynamic neighbors";
519 break;
520 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
521 str = "Dynamic neighbor listen range already exists";
522 break;
523 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
524 str = "Operation not allowed on a dynamic neighbor";
525 break;
526 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
527 str = "Operation not allowed on a directly connected neighbor";
528 break;
529 case BGP_ERR_PEER_SAFI_CONFLICT:
530 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
531 break;
532 }
533 if (str) {
534 vty_out(vty, "%% %s\n", str);
535 return CMD_WARNING_CONFIG_FAILED;
536 }
537 return CMD_SUCCESS;
718e3744 538}
539
7aafcaca 540/* BGP clear sort. */
d62a17ae 541enum clear_sort {
542 clear_all,
543 clear_peer,
544 clear_group,
545 clear_external,
546 clear_as
7aafcaca
DS
547};
548
d62a17ae 549static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
550 safi_t safi, int error)
551{
552 switch (error) {
553 case BGP_ERR_AF_UNCONFIGURED:
554 vty_out(vty,
555 "%%BGP: Enable %s address family for the neighbor %s\n",
556 afi_safi_print(afi, safi), peer->host);
557 break;
558 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
559 vty_out(vty,
560 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
561 peer->host);
562 break;
563 default:
564 break;
565 }
7aafcaca
DS
566}
567
568/* `clear ip bgp' functions. */
d62a17ae 569static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
570 enum clear_sort sort, enum bgp_clear_type stype,
571 const char *arg)
572{
573 int ret;
3ae8bfa5 574 bool found = false;
d62a17ae 575 struct peer *peer;
576 struct listnode *node, *nnode;
577
578 /* Clear all neighbors. */
579 /*
580 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
581 * nodes on the BGP instance as that may get freed if it is a
582 * doppelganger
d62a17ae 583 */
584 if (sort == clear_all) {
585 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
586 if (!peer->afc[afi][safi])
587 continue;
588
d62a17ae 589 if (stype == BGP_CLEAR_SOFT_NONE)
590 ret = peer_clear(peer, &nnode);
d62a17ae 591 else
3ae8bfa5 592 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 593
594 if (ret < 0)
595 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
596 else
597 found = true;
04b6bdc0 598 }
d62a17ae 599
600 /* This is to apply read-only mode on this clear. */
601 if (stype == BGP_CLEAR_SOFT_NONE)
602 bgp->update_delay_over = 0;
603
3ae8bfa5 604 if (!found)
3702f84d 605 vty_out(vty, "%%BGP: No %s peer configured\n",
3ae8bfa5
PM
606 afi_safi_print(afi, safi));
607
d62a17ae 608 return CMD_SUCCESS;
7aafcaca
DS
609 }
610
3ae8bfa5 611 /* Clear specified neighbor. */
d62a17ae 612 if (sort == clear_peer) {
613 union sockunion su;
d62a17ae 614
615 /* Make sockunion for lookup. */
616 ret = str2sockunion(arg, &su);
617 if (ret < 0) {
618 peer = peer_lookup_by_conf_if(bgp, arg);
619 if (!peer) {
620 peer = peer_lookup_by_hostname(bgp, arg);
621 if (!peer) {
622 vty_out(vty,
623 "Malformed address or name: %s\n",
624 arg);
625 return CMD_WARNING;
626 }
627 }
628 } else {
629 peer = peer_lookup(bgp, &su);
630 if (!peer) {
631 vty_out(vty,
632 "%%BGP: Unknown neighbor - \"%s\"\n",
633 arg);
634 return CMD_WARNING;
635 }
636 }
7aafcaca 637
3ae8bfa5
PM
638 if (!peer->afc[afi][safi])
639 ret = BGP_ERR_AF_UNCONFIGURED;
640 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 641 ret = peer_clear(peer, NULL);
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);
7aafcaca 647
d62a17ae 648 return CMD_SUCCESS;
7aafcaca 649 }
7aafcaca 650
3ae8bfa5 651 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 652 if (sort == clear_group) {
653 struct peer_group *group;
7aafcaca 654
d62a17ae 655 group = peer_group_lookup(bgp, arg);
656 if (!group) {
657 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
658 return CMD_WARNING;
659 }
660
661 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 662 if (!peer->afc[afi][safi])
663 continue;
664
3ae8bfa5
PM
665 if (stype == BGP_CLEAR_SOFT_NONE)
666 ret = peer_clear(peer, NULL);
667 else
668 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 669
d62a17ae 670 if (ret < 0)
671 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
672 else
673 found = true;
d62a17ae 674 }
3ae8bfa5
PM
675
676 if (!found)
677 vty_out(vty,
678 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
679 afi_safi_print(afi, safi), arg);
680
d62a17ae 681 return CMD_SUCCESS;
7aafcaca 682 }
7aafcaca 683
3ae8bfa5 684 /* Clear all external (eBGP) neighbors. */
d62a17ae 685 if (sort == clear_external) {
686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
687 if (peer->sort == BGP_PEER_IBGP)
688 continue;
7aafcaca 689
3ae8bfa5
PM
690 if (!peer->afc[afi][safi])
691 continue;
692
d62a17ae 693 if (stype == BGP_CLEAR_SOFT_NONE)
694 ret = peer_clear(peer, &nnode);
695 else
696 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 697
d62a17ae 698 if (ret < 0)
699 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
700 else
701 found = true;
d62a17ae 702 }
3ae8bfa5
PM
703
704 if (!found)
705 vty_out(vty,
706 "%%BGP: No external %s peer is configured\n",
707 afi_safi_print(afi, safi));
708
d62a17ae 709 return CMD_SUCCESS;
710 }
711
3ae8bfa5 712 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 713 if (sort == clear_as) {
3ae8bfa5 714 as_t as = strtoul(arg, NULL, 10);
d62a17ae 715
716 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
717 if (peer->as != as)
718 continue;
719
3ae8bfa5
PM
720 if (!peer->afc[afi][safi])
721 ret = BGP_ERR_AF_UNCONFIGURED;
722 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 723 ret = peer_clear(peer, &nnode);
724 else
725 ret = peer_clear_soft(peer, afi, safi, stype);
726
727 if (ret < 0)
728 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
729 else
730 found = true;
d62a17ae 731 }
3ae8bfa5
PM
732
733 if (!found)
d62a17ae 734 vty_out(vty,
3ae8bfa5
PM
735 "%%BGP: No %s peer is configured with AS %s\n",
736 afi_safi_print(afi, safi), arg);
737
d62a17ae 738 return CMD_SUCCESS;
739 }
740
741 return CMD_SUCCESS;
742}
743
744static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
745 safi_t safi, enum clear_sort sort,
746 enum bgp_clear_type stype, const char *arg)
747{
748 struct bgp *bgp;
749
750 /* BGP structure lookup. */
751 if (name) {
752 bgp = bgp_lookup_by_name(name);
753 if (bgp == NULL) {
754 vty_out(vty, "Can't find BGP instance %s\n", name);
755 return CMD_WARNING;
756 }
757 } else {
758 bgp = bgp_get_default();
759 if (bgp == NULL) {
760 vty_out(vty, "No BGP process is configured\n");
761 return CMD_WARNING;
762 }
763 }
764
765 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
766}
767
768/* clear soft inbound */
d62a17ae 769static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 770{
d62a17ae 771 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
772 BGP_CLEAR_SOFT_IN, NULL);
773 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
774 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
775}
776
777/* clear soft outbound */
d62a17ae 778static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 779{
d62a17ae 780 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
781 BGP_CLEAR_SOFT_OUT, NULL);
782 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
783 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
784}
785
786
f787d7a0 787#ifndef VTYSH_EXTRACT_PL
2e4c2296 788#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
789#endif
790
718e3744 791/* BGP global configuration. */
bee57a7a 792#if (CONFDATE > 20190601)
1cc40660
DS
793CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
794CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
795#endif
796DEFUN_HIDDEN (bgp_multiple_instance_func,
797 bgp_multiple_instance_cmd,
798 "bgp multiple-instance",
799 BGP_STR
800 "Enable bgp multiple instance\n")
718e3744 801{
d62a17ae 802 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
803 return CMD_SUCCESS;
718e3744 804}
805
1cc40660 806DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 807 no_bgp_multiple_instance_cmd,
808 "no bgp multiple-instance",
809 NO_STR
810 BGP_STR
811 "BGP multiple instance\n")
812{
d62a17ae 813 int ret;
718e3744 814
1cc40660
DS
815 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
816 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 817 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 818 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
819 if (ret < 0) {
820 vty_out(vty, "%% There are more than two BGP instances\n");
821 return CMD_WARNING_CONFIG_FAILED;
822 }
823 return CMD_SUCCESS;
718e3744 824}
825
8029b216
AK
826DEFUN_HIDDEN (bgp_local_mac,
827 bgp_local_mac_cmd,
093e3f23 828 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
829 BGP_STR
830 "Local MAC config\n"
831 "VxLAN Network Identifier\n"
832 "VNI number\n"
833 "local mac\n"
834 "mac address\n"
835 "mac-mobility sequence\n"
836 "seq number\n")
837{
838 int rv;
839 vni_t vni;
840 struct ethaddr mac;
841 struct ipaddr ip;
842 uint32_t seq;
843 struct bgp *bgp;
844
845 vni = strtoul(argv[3]->arg, NULL, 10);
846 if (!prefix_str2mac(argv[5]->arg, &mac)) {
847 vty_out(vty, "%% Malformed MAC address\n");
848 return CMD_WARNING;
849 }
850 memset(&ip, 0, sizeof(ip));
851 seq = strtoul(argv[7]->arg, NULL, 10);
852
853 bgp = bgp_get_default();
854 if (!bgp) {
855 vty_out(vty, "Default BGP instance is not there\n");
856 return CMD_WARNING;
857 }
858
859 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
860 if (rv < 0) {
861 vty_out(vty, "Internal error\n");
862 return CMD_WARNING;
863 }
864
865 return CMD_SUCCESS;
866}
867
868DEFUN_HIDDEN (no_bgp_local_mac,
869 no_bgp_local_mac_cmd,
093e3f23 870 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
871 NO_STR
872 BGP_STR
873 "Local MAC config\n"
874 "VxLAN Network Identifier\n"
875 "VNI number\n"
876 "local mac\n"
877 "mac address\n")
878{
879 int rv;
880 vni_t vni;
881 struct ethaddr mac;
882 struct ipaddr ip;
883 struct bgp *bgp;
884
885 vni = strtoul(argv[4]->arg, NULL, 10);
886 if (!prefix_str2mac(argv[6]->arg, &mac)) {
887 vty_out(vty, "%% Malformed MAC address\n");
888 return CMD_WARNING;
889 }
890 memset(&ip, 0, sizeof(ip));
891
892 bgp = bgp_get_default();
893 if (!bgp) {
894 vty_out(vty, "Default BGP instance is not there\n");
895 return CMD_WARNING;
896 }
897
898 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip);
899 if (rv < 0) {
900 vty_out(vty, "Internal error\n");
901 return CMD_WARNING;
902 }
903
904 return CMD_SUCCESS;
905}
906
bee57a7a 907#if (CONFDATE > 20190601)
798467a2
DS
908CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
909CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
910#endif
911DEFUN_HIDDEN (bgp_config_type,
912 bgp_config_type_cmd,
913 "bgp config-type <cisco|zebra>",
914 BGP_STR
915 "Configuration type\n"
916 "cisco\n"
917 "zebra\n")
718e3744 918{
d62a17ae 919 int idx = 0;
798467a2
DS
920 if (argv_find(argv, argc, "cisco", &idx)) {
921 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
922 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 923 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 924 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 925 } else
d62a17ae 926 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 927
d62a17ae 928 return CMD_SUCCESS;
718e3744 929}
930
798467a2
DS
931DEFUN_HIDDEN (no_bgp_config_type,
932 no_bgp_config_type_cmd,
933 "no bgp config-type [<cisco|zebra>]",
934 NO_STR
935 BGP_STR
936 "Display configuration type\n"
937 "cisco\n"
938 "zebra\n")
718e3744 939{
d62a17ae 940 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
941 return CMD_SUCCESS;
718e3744 942}
943
813d4307 944
718e3744 945DEFUN (no_synchronization,
946 no_synchronization_cmd,
947 "no synchronization",
948 NO_STR
949 "Perform IGP synchronization\n")
950{
d62a17ae 951 return CMD_SUCCESS;
718e3744 952}
953
954DEFUN (no_auto_summary,
955 no_auto_summary_cmd,
956 "no auto-summary",
957 NO_STR
958 "Enable automatic network number summarization\n")
959{
d62a17ae 960 return CMD_SUCCESS;
718e3744 961}
3d515fd9 962
718e3744 963/* "router bgp" commands. */
505e5056 964DEFUN_NOSH (router_bgp,
f412b39a 965 router_bgp_cmd,
18c57037 966 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 967 ROUTER_STR
968 BGP_STR
31500417
DW
969 AS_STR
970 BGP_INSTANCE_HELP_STR)
718e3744 971{
d62a17ae 972 int idx_asn = 2;
973 int idx_view_vrf = 3;
974 int idx_vrf = 4;
ecec9495 975 int is_new_bgp = 0;
d62a17ae 976 int ret;
977 as_t as;
978 struct bgp *bgp;
979 const char *name = NULL;
980 enum bgp_instance_type inst_type;
981
982 // "router bgp" without an ASN
983 if (argc == 2) {
984 // Pending: Make VRF option available for ASN less config
985 bgp = bgp_get_default();
986
987 if (bgp == NULL) {
988 vty_out(vty, "%% No BGP process is configured\n");
989 return CMD_WARNING_CONFIG_FAILED;
990 }
991
992 if (listcount(bm->bgp) > 1) {
996c9314 993 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 994 return CMD_WARNING_CONFIG_FAILED;
995 }
996 }
997
998 // "router bgp X"
999 else {
1000 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1001
1002 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1003 if (argc > 3) {
1004 name = argv[idx_vrf]->arg;
1005
9a8bdf1c
PG
1006 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1007 if (strmatch(name, VRF_DEFAULT_NAME))
1008 name = NULL;
1009 else
1010 inst_type = BGP_INSTANCE_TYPE_VRF;
1011 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1012 inst_type = BGP_INSTANCE_TYPE_VIEW;
1013 }
1014
ecec9495
AD
1015 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1016 is_new_bgp = (bgp_lookup(as, name) == NULL);
1017
d62a17ae 1018 ret = bgp_get(&bgp, &as, name, inst_type);
1019 switch (ret) {
1020 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1021 vty_out(vty,
1022 "Please specify 'bgp multiple-instance' first\n");
1023 return CMD_WARNING_CONFIG_FAILED;
1024 case BGP_ERR_AS_MISMATCH:
1025 vty_out(vty, "BGP is already running; AS is %u\n", as);
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_INSTANCE_MISMATCH:
1028 vty_out(vty,
1029 "BGP instance name and AS number mismatch\n");
1030 vty_out(vty,
1031 "BGP instance is already running; AS is %u\n",
1032 as);
1033 return CMD_WARNING_CONFIG_FAILED;
1034 }
1035
3bd70bf8
PZ
1036 /*
1037 * If we just instantiated the default instance, complete
1038 * any pending VRF-VPN leaking that was configured via
1039 * earlier "router bgp X vrf FOO" blocks.
1040 */
ecec9495 1041 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1042 vpn_leak_postchange_all();
1043
d62a17ae 1044 /* Pending: handle when user tries to change a view to vrf n vv.
1045 */
1046 }
1047
0b5131c9
MK
1048 /* unset the auto created flag as the user config is now present */
1049 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1050 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1051
1052 return CMD_SUCCESS;
718e3744 1053}
1054
718e3744 1055/* "no router bgp" commands. */
1056DEFUN (no_router_bgp,
1057 no_router_bgp_cmd,
18c57037 1058 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 1059 NO_STR
1060 ROUTER_STR
1061 BGP_STR
31500417
DW
1062 AS_STR
1063 BGP_INSTANCE_HELP_STR)
718e3744 1064{
d62a17ae 1065 int idx_asn = 3;
1066 int idx_vrf = 5;
1067 as_t as;
1068 struct bgp *bgp;
1069 const char *name = NULL;
718e3744 1070
d62a17ae 1071 // "no router bgp" without an ASN
1072 if (argc == 3) {
1073 // Pending: Make VRF option available for ASN less config
1074 bgp = bgp_get_default();
718e3744 1075
d62a17ae 1076 if (bgp == NULL) {
1077 vty_out(vty, "%% No BGP process is configured\n");
1078 return CMD_WARNING_CONFIG_FAILED;
1079 }
7fb21a9f 1080
d62a17ae 1081 if (listcount(bm->bgp) > 1) {
996c9314 1082 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1083 return CMD_WARNING_CONFIG_FAILED;
1084 }
0b5131c9
MK
1085
1086 if (bgp->l3vni) {
1087 vty_out(vty, "%% Please unconfigure l3vni %u",
1088 bgp->l3vni);
1089 return CMD_WARNING_CONFIG_FAILED;
1090 }
d62a17ae 1091 } else {
1092 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1093
d62a17ae 1094 if (argc > 4)
1095 name = argv[idx_vrf]->arg;
7fb21a9f 1096
d62a17ae 1097 /* Lookup bgp structure. */
1098 bgp = bgp_lookup(as, name);
1099 if (!bgp) {
1100 vty_out(vty, "%% Can't find BGP instance\n");
1101 return CMD_WARNING_CONFIG_FAILED;
1102 }
0b5131c9
MK
1103
1104 if (bgp->l3vni) {
1105 vty_out(vty, "%% Please unconfigure l3vni %u",
1106 bgp->l3vni);
1107 return CMD_WARNING_CONFIG_FAILED;
1108 }
d62a17ae 1109 }
718e3744 1110
d62a17ae 1111 bgp_delete(bgp);
718e3744 1112
d62a17ae 1113 return CMD_SUCCESS;
718e3744 1114}
1115
6b0655a2 1116
718e3744 1117/* BGP router-id. */
1118
f787d7a0 1119DEFPY (bgp_router_id,
718e3744 1120 bgp_router_id_cmd,
1121 "bgp router-id A.B.C.D",
1122 BGP_STR
1123 "Override configured router identifier\n"
1124 "Manually configured router identifier\n")
1125{
d62a17ae 1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 bgp_router_id_static_set(bgp, router_id);
1128 return CMD_SUCCESS;
718e3744 1129}
1130
f787d7a0 1131DEFPY (no_bgp_router_id,
718e3744 1132 no_bgp_router_id_cmd,
31500417 1133 "no bgp router-id [A.B.C.D]",
718e3744 1134 NO_STR
1135 BGP_STR
31500417
DW
1136 "Override configured router identifier\n"
1137 "Manually configured router identifier\n")
718e3744 1138{
d62a17ae 1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1140
d62a17ae 1141 if (router_id_str) {
1142 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1143 vty_out(vty, "%% BGP router-id doesn't match\n");
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
e018c7cc 1146 }
718e3744 1147
d62a17ae 1148 router_id.s_addr = 0;
1149 bgp_router_id_static_set(bgp, router_id);
718e3744 1150
d62a17ae 1151 return CMD_SUCCESS;
718e3744 1152}
1153
6b0655a2 1154
718e3744 1155/* BGP Cluster ID. */
718e3744 1156DEFUN (bgp_cluster_id,
1157 bgp_cluster_id_cmd,
838758ac 1158 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1159 BGP_STR
1160 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1161 "Route-Reflector Cluster-id in IP address format\n"
1162 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1163{
d62a17ae 1164 VTY_DECLVAR_CONTEXT(bgp, bgp);
1165 int idx_ipv4 = 2;
1166 int ret;
1167 struct in_addr cluster;
718e3744 1168
d62a17ae 1169 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1170 if (!ret) {
1171 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1172 return CMD_WARNING_CONFIG_FAILED;
1173 }
718e3744 1174
d62a17ae 1175 bgp_cluster_id_set(bgp, &cluster);
1176 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1177
d62a17ae 1178 return CMD_SUCCESS;
718e3744 1179}
1180
718e3744 1181DEFUN (no_bgp_cluster_id,
1182 no_bgp_cluster_id_cmd,
c7178fe7 1183 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1184 NO_STR
1185 BGP_STR
838758ac
DW
1186 "Configure Route-Reflector Cluster-id\n"
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1189{
d62a17ae 1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 bgp_cluster_id_unset(bgp);
1192 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1193
d62a17ae 1194 return CMD_SUCCESS;
718e3744 1195}
1196
718e3744 1197DEFUN (bgp_confederation_identifier,
1198 bgp_confederation_identifier_cmd,
9ccf14f7 1199 "bgp confederation identifier (1-4294967295)",
718e3744 1200 "BGP specific commands\n"
1201 "AS confederation parameters\n"
1202 "AS number\n"
1203 "Set routing domain confederation AS\n")
1204{
d62a17ae 1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
1206 int idx_number = 3;
1207 as_t as;
718e3744 1208
d62a17ae 1209 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1210
d62a17ae 1211 bgp_confederation_id_set(bgp, as);
718e3744 1212
d62a17ae 1213 return CMD_SUCCESS;
718e3744 1214}
1215
1216DEFUN (no_bgp_confederation_identifier,
1217 no_bgp_confederation_identifier_cmd,
838758ac 1218 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1219 NO_STR
1220 "BGP specific commands\n"
1221 "AS confederation parameters\n"
3a2d747c
QY
1222 "AS number\n"
1223 "Set routing domain confederation AS\n")
718e3744 1224{
d62a17ae 1225 VTY_DECLVAR_CONTEXT(bgp, bgp);
1226 bgp_confederation_id_unset(bgp);
718e3744 1227
d62a17ae 1228 return CMD_SUCCESS;
718e3744 1229}
1230
718e3744 1231DEFUN (bgp_confederation_peers,
1232 bgp_confederation_peers_cmd,
12dcf78e 1233 "bgp confederation peers (1-4294967295)...",
718e3744 1234 "BGP specific commands\n"
1235 "AS confederation parameters\n"
1236 "Peer ASs in BGP confederation\n"
1237 AS_STR)
1238{
d62a17ae 1239 VTY_DECLVAR_CONTEXT(bgp, bgp);
1240 int idx_asn = 3;
1241 as_t as;
1242 int i;
718e3744 1243
d62a17ae 1244 for (i = idx_asn; i < argc; i++) {
1245 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1246
d62a17ae 1247 if (bgp->as == as) {
1248 vty_out(vty,
1249 "%% Local member-AS not allowed in confed peer list\n");
1250 continue;
1251 }
718e3744 1252
d62a17ae 1253 bgp_confederation_peers_add(bgp, as);
1254 }
1255 return CMD_SUCCESS;
718e3744 1256}
1257
1258DEFUN (no_bgp_confederation_peers,
1259 no_bgp_confederation_peers_cmd,
e83a9414 1260 "no bgp confederation peers (1-4294967295)...",
718e3744 1261 NO_STR
1262 "BGP specific commands\n"
1263 "AS confederation parameters\n"
1264 "Peer ASs in BGP confederation\n"
1265 AS_STR)
1266{
d62a17ae 1267 VTY_DECLVAR_CONTEXT(bgp, bgp);
1268 int idx_asn = 4;
1269 as_t as;
1270 int i;
718e3744 1271
d62a17ae 1272 for (i = idx_asn; i < argc; i++) {
1273 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1274
d62a17ae 1275 bgp_confederation_peers_remove(bgp, as);
1276 }
1277 return CMD_SUCCESS;
718e3744 1278}
6b0655a2 1279
5e242b0d
DS
1280/**
1281 * Central routine for maximum-paths configuration.
1282 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1283 * @set: 1 for setting values, 0 for removing the max-paths config.
1284 */
d62a17ae 1285static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1286 const char *mpaths, uint16_t options,
d62a17ae 1287 int set)
1288{
1289 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1290 uint16_t maxpaths = 0;
d62a17ae 1291 int ret;
1292 afi_t afi;
1293 safi_t safi;
1294
1295 afi = bgp_node_afi(vty);
1296 safi = bgp_node_safi(vty);
1297
1298 if (set) {
1299 maxpaths = strtol(mpaths, NULL, 10);
1300 if (maxpaths > multipath_num) {
1301 vty_out(vty,
1302 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1303 maxpaths, multipath_num);
1304 return CMD_WARNING_CONFIG_FAILED;
1305 }
1306 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1307 options);
1308 } else
1309 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1310
1311 if (ret < 0) {
1312 vty_out(vty,
1313 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1314 (set == 1) ? "" : "un",
1315 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1316 maxpaths, afi, safi);
1317 return CMD_WARNING_CONFIG_FAILED;
1318 }
1319
1320 bgp_recalculate_all_bestpaths(bgp);
1321
1322 return CMD_SUCCESS;
165b5fff
JB
1323}
1324
abc920f8
DS
1325DEFUN (bgp_maxmed_admin,
1326 bgp_maxmed_admin_cmd,
1327 "bgp max-med administrative ",
1328 BGP_STR
1329 "Advertise routes with max-med\n"
1330 "Administratively applied, for an indefinite period\n")
1331{
d62a17ae 1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1333
d62a17ae 1334 bgp->v_maxmed_admin = 1;
1335 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1336
d62a17ae 1337 bgp_maxmed_update(bgp);
abc920f8 1338
d62a17ae 1339 return CMD_SUCCESS;
abc920f8
DS
1340}
1341
1342DEFUN (bgp_maxmed_admin_medv,
1343 bgp_maxmed_admin_medv_cmd,
4668a151 1344 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1345 BGP_STR
1346 "Advertise routes with max-med\n"
1347 "Administratively applied, for an indefinite period\n"
1348 "Max MED value to be used\n")
1349{
d62a17ae 1350 VTY_DECLVAR_CONTEXT(bgp, bgp);
1351 int idx_number = 3;
abc920f8 1352
d62a17ae 1353 bgp->v_maxmed_admin = 1;
1354 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1355
d62a17ae 1356 bgp_maxmed_update(bgp);
abc920f8 1357
d62a17ae 1358 return CMD_SUCCESS;
abc920f8
DS
1359}
1360
1361DEFUN (no_bgp_maxmed_admin,
1362 no_bgp_maxmed_admin_cmd,
4668a151 1363 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1364 NO_STR
1365 BGP_STR
1366 "Advertise routes with max-med\n"
838758ac
DW
1367 "Administratively applied, for an indefinite period\n"
1368 "Max MED value to be used\n")
abc920f8 1369{
d62a17ae 1370 VTY_DECLVAR_CONTEXT(bgp, bgp);
1371 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1372 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1373 bgp_maxmed_update(bgp);
abc920f8 1374
d62a17ae 1375 return CMD_SUCCESS;
abc920f8
DS
1376}
1377
abc920f8
DS
1378DEFUN (bgp_maxmed_onstartup,
1379 bgp_maxmed_onstartup_cmd,
4668a151 1380 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1381 BGP_STR
1382 "Advertise routes with max-med\n"
1383 "Effective on a startup\n"
1384 "Time (seconds) period for max-med\n"
1385 "Max MED value to be used\n")
1386{
d62a17ae 1387 VTY_DECLVAR_CONTEXT(bgp, bgp);
1388 int idx = 0;
4668a151 1389
d62a17ae 1390 argv_find(argv, argc, "(5-86400)", &idx);
1391 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1392 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1393 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1394 else
1395 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1396
d62a17ae 1397 bgp_maxmed_update(bgp);
abc920f8 1398
d62a17ae 1399 return CMD_SUCCESS;
abc920f8
DS
1400}
1401
1402DEFUN (no_bgp_maxmed_onstartup,
1403 no_bgp_maxmed_onstartup_cmd,
4668a151 1404 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1405 NO_STR
1406 BGP_STR
1407 "Advertise routes with max-med\n"
838758ac
DW
1408 "Effective on a startup\n"
1409 "Time (seconds) period for max-med\n"
1410 "Max MED value to be used\n")
abc920f8 1411{
d62a17ae 1412 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1413
d62a17ae 1414 /* Cancel max-med onstartup if its on */
1415 if (bgp->t_maxmed_onstartup) {
1416 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1417 bgp->maxmed_onstartup_over = 1;
1418 }
abc920f8 1419
d62a17ae 1420 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1422
d62a17ae 1423 bgp_maxmed_update(bgp);
abc920f8 1424
d62a17ae 1425 return CMD_SUCCESS;
abc920f8
DS
1426}
1427
d62a17ae 1428static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1429 const char *wait)
f188f2c4 1430{
d62a17ae 1431 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1432 uint16_t update_delay;
1433 uint16_t establish_wait;
f188f2c4 1434
d62a17ae 1435 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1436
d62a17ae 1437 if (!wait) /* update-delay <delay> */
1438 {
1439 bgp->v_update_delay = update_delay;
1440 bgp->v_establish_wait = bgp->v_update_delay;
1441 return CMD_SUCCESS;
1442 }
f188f2c4 1443
d62a17ae 1444 /* update-delay <delay> <establish-wait> */
1445 establish_wait = atoi(wait);
1446 if (update_delay < establish_wait) {
1447 vty_out(vty,
1448 "%%Failed: update-delay less than the establish-wait!\n");
1449 return CMD_WARNING_CONFIG_FAILED;
1450 }
f188f2c4 1451
d62a17ae 1452 bgp->v_update_delay = update_delay;
1453 bgp->v_establish_wait = establish_wait;
f188f2c4 1454
d62a17ae 1455 return CMD_SUCCESS;
f188f2c4
DS
1456}
1457
d62a17ae 1458static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1459{
d62a17ae 1460 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1461
d62a17ae 1462 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1463 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1464
d62a17ae 1465 return CMD_SUCCESS;
f188f2c4
DS
1466}
1467
2b791107 1468void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1469{
d62a17ae 1470 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1471 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1472 if (bgp->v_update_delay != bgp->v_establish_wait)
1473 vty_out(vty, " %d", bgp->v_establish_wait);
1474 vty_out(vty, "\n");
1475 }
f188f2c4
DS
1476}
1477
1478
1479/* Update-delay configuration */
1480DEFUN (bgp_update_delay,
1481 bgp_update_delay_cmd,
6147e2c6 1482 "update-delay (0-3600)",
f188f2c4
DS
1483 "Force initial delay for best-path and updates\n"
1484 "Seconds\n")
1485{
d62a17ae 1486 int idx_number = 1;
1487 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1488}
1489
1490DEFUN (bgp_update_delay_establish_wait,
1491 bgp_update_delay_establish_wait_cmd,
6147e2c6 1492 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1493 "Force initial delay for best-path and updates\n"
1494 "Seconds\n"
f188f2c4
DS
1495 "Seconds\n")
1496{
d62a17ae 1497 int idx_number = 1;
1498 int idx_number_2 = 2;
1499 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1500 argv[idx_number_2]->arg);
f188f2c4
DS
1501}
1502
1503/* Update-delay deconfiguration */
1504DEFUN (no_bgp_update_delay,
1505 no_bgp_update_delay_cmd,
838758ac
DW
1506 "no update-delay [(0-3600) [(1-3600)]]",
1507 NO_STR
f188f2c4 1508 "Force initial delay for best-path and updates\n"
838758ac 1509 "Seconds\n"
7111c1a0 1510 "Seconds\n")
f188f2c4 1511{
d62a17ae 1512 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1513}
1514
5e242b0d 1515
d62a17ae 1516static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1517 char set)
cb1faec9 1518{
d62a17ae 1519 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1520
555e09d4
QY
1521 if (set) {
1522 uint32_t quanta = strtoul(num, NULL, 10);
1523 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1524 memory_order_relaxed);
1525 } else {
1526 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1527 memory_order_relaxed);
1528 }
1529
1530 return CMD_SUCCESS;
1531}
1532
1533static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1534 char set)
1535{
1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
1537
1538 if (set) {
1539 uint32_t quanta = strtoul(num, NULL, 10);
1540 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1541 memory_order_relaxed);
1542 } else {
1543 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1544 memory_order_relaxed);
1545 }
cb1faec9 1546
d62a17ae 1547 return CMD_SUCCESS;
cb1faec9
DS
1548}
1549
2b791107 1550void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1551{
555e09d4
QY
1552 uint32_t quanta =
1553 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1554 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1555 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1556}
1557
555e09d4
QY
1558void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1559{
1560 uint32_t quanta =
1561 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1562 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1563 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1564}
cb1faec9 1565
555e09d4 1566/* Packet quanta configuration */
cb1faec9
DS
1567DEFUN (bgp_wpkt_quanta,
1568 bgp_wpkt_quanta_cmd,
555e09d4 1569 "write-quanta (1-10)",
cb1faec9
DS
1570 "How many packets to write to peer socket per run\n"
1571 "Number of packets\n")
1572{
d62a17ae 1573 int idx_number = 1;
1574 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1575}
1576
cb1faec9
DS
1577DEFUN (no_bgp_wpkt_quanta,
1578 no_bgp_wpkt_quanta_cmd,
555e09d4 1579 "no write-quanta (1-10)",
d7fa34c1 1580 NO_STR
555e09d4 1581 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1582 "Number of packets\n")
1583{
d62a17ae 1584 int idx_number = 2;
1585 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1586}
1587
555e09d4
QY
1588DEFUN (bgp_rpkt_quanta,
1589 bgp_rpkt_quanta_cmd,
1590 "read-quanta (1-10)",
1591 "How many packets to read from peer socket per I/O cycle\n"
1592 "Number of packets\n")
1593{
1594 int idx_number = 1;
1595 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1596}
1597
1598DEFUN (no_bgp_rpkt_quanta,
1599 no_bgp_rpkt_quanta_cmd,
1600 "no read-quanta (1-10)",
1601 NO_STR
1602 "How many packets to read from peer socket per I/O cycle\n"
1603 "Number of packets\n")
1604{
1605 int idx_number = 2;
1606 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1607}
1608
2b791107 1609void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1610{
37a333fe 1611 if (!bgp->heuristic_coalesce)
d62a17ae 1612 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1613}
1614
1615
1616DEFUN (bgp_coalesce_time,
1617 bgp_coalesce_time_cmd,
6147e2c6 1618 "coalesce-time (0-4294967295)",
3f9c7369
DS
1619 "Subgroup coalesce timer\n"
1620 "Subgroup coalesce timer value (in ms)\n")
1621{
d62a17ae 1622 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1623
d62a17ae 1624 int idx = 0;
1625 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1626 bgp->heuristic_coalesce = false;
d62a17ae 1627 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1628 return CMD_SUCCESS;
3f9c7369
DS
1629}
1630
1631DEFUN (no_bgp_coalesce_time,
1632 no_bgp_coalesce_time_cmd,
6147e2c6 1633 "no coalesce-time (0-4294967295)",
3a2d747c 1634 NO_STR
3f9c7369
DS
1635 "Subgroup coalesce timer\n"
1636 "Subgroup coalesce timer value (in ms)\n")
1637{
d62a17ae 1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1639
37a333fe 1640 bgp->heuristic_coalesce = true;
d62a17ae 1641 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1642 return CMD_SUCCESS;
3f9c7369
DS
1643}
1644
5e242b0d
DS
1645/* Maximum-paths configuration */
1646DEFUN (bgp_maxpaths,
1647 bgp_maxpaths_cmd,
6319fd63 1648 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1649 "Forward packets over multiple paths\n"
1650 "Number of paths\n")
1651{
d62a17ae 1652 int idx_number = 1;
1653 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1654 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1655}
1656
d62a17ae 1657ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1658 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1659 "Forward packets over multiple paths\n"
1660 "Number of paths\n")
596c17ba 1661
165b5fff
JB
1662DEFUN (bgp_maxpaths_ibgp,
1663 bgp_maxpaths_ibgp_cmd,
6319fd63 1664 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1665 "Forward packets over multiple paths\n"
1666 "iBGP-multipath\n"
1667 "Number of paths\n")
1668{
d62a17ae 1669 int idx_number = 2;
1670 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1671 argv[idx_number]->arg, 0, 1);
5e242b0d 1672}
165b5fff 1673
d62a17ae 1674ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1675 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1676 "Forward packets over multiple paths\n"
1677 "iBGP-multipath\n"
1678 "Number of paths\n")
596c17ba 1679
5e242b0d
DS
1680DEFUN (bgp_maxpaths_ibgp_cluster,
1681 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1682 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1683 "Forward packets over multiple paths\n"
1684 "iBGP-multipath\n"
1685 "Number of paths\n"
1686 "Match the cluster length\n")
1687{
d62a17ae 1688 int idx_number = 2;
1689 return bgp_maxpaths_config_vty(
1690 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1691 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1692}
1693
d62a17ae 1694ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1695 "maximum-paths ibgp " CMD_RANGE_STR(
1696 1, MULTIPATH_NUM) " equal-cluster-length",
1697 "Forward packets over multiple paths\n"
1698 "iBGP-multipath\n"
1699 "Number of paths\n"
1700 "Match the cluster length\n")
596c17ba 1701
165b5fff
JB
1702DEFUN (no_bgp_maxpaths,
1703 no_bgp_maxpaths_cmd,
6319fd63 1704 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1705 NO_STR
1706 "Forward packets over multiple paths\n"
1707 "Number of paths\n")
1708{
d62a17ae 1709 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1710}
1711
d62a17ae 1712ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1713 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1714 "Forward packets over multiple paths\n"
1715 "Number of paths\n")
596c17ba 1716
165b5fff
JB
1717DEFUN (no_bgp_maxpaths_ibgp,
1718 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1719 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1720 NO_STR
1721 "Forward packets over multiple paths\n"
1722 "iBGP-multipath\n"
838758ac
DW
1723 "Number of paths\n"
1724 "Match the cluster length\n")
165b5fff 1725{
d62a17ae 1726 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1727}
1728
d62a17ae 1729ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1730 "no maximum-paths ibgp [" CMD_RANGE_STR(
1731 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1732 NO_STR
1733 "Forward packets over multiple paths\n"
1734 "iBGP-multipath\n"
1735 "Number of paths\n"
1736 "Match the cluster length\n")
596c17ba 1737
2b791107 1738void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1739 safi_t safi)
165b5fff 1740{
d62a17ae 1741 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1742 vty_out(vty, " maximum-paths %d\n",
1743 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1744 }
165b5fff 1745
d62a17ae 1746 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1747 vty_out(vty, " maximum-paths ibgp %d",
1748 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1749 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1750 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1751 vty_out(vty, " equal-cluster-length");
1752 vty_out(vty, "\n");
1753 }
165b5fff 1754}
6b0655a2 1755
718e3744 1756/* BGP timers. */
1757
1758DEFUN (bgp_timers,
1759 bgp_timers_cmd,
6147e2c6 1760 "timers bgp (0-65535) (0-65535)",
718e3744 1761 "Adjust routing timers\n"
1762 "BGP timers\n"
1763 "Keepalive interval\n"
1764 "Holdtime\n")
1765{
d62a17ae 1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
1767 int idx_number = 2;
1768 int idx_number_2 = 3;
1769 unsigned long keepalive = 0;
1770 unsigned long holdtime = 0;
718e3744 1771
d62a17ae 1772 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1773 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1774
d62a17ae 1775 /* Holdtime value check. */
1776 if (holdtime < 3 && holdtime != 0) {
1777 vty_out(vty,
1778 "%% hold time value must be either 0 or greater than 3\n");
1779 return CMD_WARNING_CONFIG_FAILED;
1780 }
718e3744 1781
d62a17ae 1782 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1783
d62a17ae 1784 return CMD_SUCCESS;
718e3744 1785}
1786
1787DEFUN (no_bgp_timers,
1788 no_bgp_timers_cmd,
838758ac 1789 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1790 NO_STR
1791 "Adjust routing timers\n"
838758ac
DW
1792 "BGP timers\n"
1793 "Keepalive interval\n"
1794 "Holdtime\n")
718e3744 1795{
d62a17ae 1796 VTY_DECLVAR_CONTEXT(bgp, bgp);
1797 bgp_timers_unset(bgp);
718e3744 1798
d62a17ae 1799 return CMD_SUCCESS;
718e3744 1800}
1801
6b0655a2 1802
718e3744 1803DEFUN (bgp_client_to_client_reflection,
1804 bgp_client_to_client_reflection_cmd,
1805 "bgp client-to-client reflection",
1806 "BGP specific commands\n"
1807 "Configure client to client route reflection\n"
1808 "reflection of routes allowed\n")
1809{
d62a17ae 1810 VTY_DECLVAR_CONTEXT(bgp, bgp);
1811 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1812 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1813
d62a17ae 1814 return CMD_SUCCESS;
718e3744 1815}
1816
1817DEFUN (no_bgp_client_to_client_reflection,
1818 no_bgp_client_to_client_reflection_cmd,
1819 "no bgp client-to-client reflection",
1820 NO_STR
1821 "BGP specific commands\n"
1822 "Configure client to client route reflection\n"
1823 "reflection of routes allowed\n")
1824{
d62a17ae 1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1827 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1828
d62a17ae 1829 return CMD_SUCCESS;
718e3744 1830}
1831
1832/* "bgp always-compare-med" configuration. */
1833DEFUN (bgp_always_compare_med,
1834 bgp_always_compare_med_cmd,
1835 "bgp always-compare-med",
1836 "BGP specific commands\n"
1837 "Allow comparing MED from different neighbors\n")
1838{
d62a17ae 1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1841 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1842
d62a17ae 1843 return CMD_SUCCESS;
718e3744 1844}
1845
1846DEFUN (no_bgp_always_compare_med,
1847 no_bgp_always_compare_med_cmd,
1848 "no bgp always-compare-med",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Allow comparing MED from different neighbors\n")
1852{
d62a17ae 1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1855 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1856
d62a17ae 1857 return CMD_SUCCESS;
718e3744 1858}
6b0655a2 1859
718e3744 1860/* "bgp deterministic-med" configuration. */
1861DEFUN (bgp_deterministic_med,
1862 bgp_deterministic_med_cmd,
1863 "bgp deterministic-med",
1864 "BGP specific commands\n"
1865 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1866{
d62a17ae 1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1868
d62a17ae 1869 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1870 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1871 bgp_recalculate_all_bestpaths(bgp);
1872 }
7aafcaca 1873
d62a17ae 1874 return CMD_SUCCESS;
718e3744 1875}
1876
1877DEFUN (no_bgp_deterministic_med,
1878 no_bgp_deterministic_med_cmd,
1879 "no bgp deterministic-med",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1883{
d62a17ae 1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 int bestpath_per_as_used;
1886 afi_t afi;
1887 safi_t safi;
1888 struct peer *peer;
1889 struct listnode *node, *nnode;
1890
1891 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1892 bestpath_per_as_used = 0;
1893
1894 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1895 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1896 if (bgp_addpath_dmed_required(
1897 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1898 bestpath_per_as_used = 1;
1899 break;
1900 }
d62a17ae 1901
1902 if (bestpath_per_as_used)
1903 break;
1904 }
1905
1906 if (bestpath_per_as_used) {
1907 vty_out(vty,
1908 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1909 return CMD_WARNING_CONFIG_FAILED;
1910 } else {
1911 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1912 bgp_recalculate_all_bestpaths(bgp);
1913 }
1914 }
1915
1916 return CMD_SUCCESS;
718e3744 1917}
538621f2 1918
1919/* "bgp graceful-restart" configuration. */
1920DEFUN (bgp_graceful_restart,
1921 bgp_graceful_restart_cmd,
1922 "bgp graceful-restart",
1923 "BGP specific commands\n"
1924 "Graceful restart capability parameters\n")
1925{
d62a17ae 1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1928 return CMD_SUCCESS;
538621f2 1929}
1930
1931DEFUN (no_bgp_graceful_restart,
1932 no_bgp_graceful_restart_cmd,
1933 "no bgp graceful-restart",
1934 NO_STR
1935 "BGP specific commands\n"
1936 "Graceful restart capability parameters\n")
1937{
d62a17ae 1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
1939 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1940 return CMD_SUCCESS;
538621f2 1941}
1942
93406d87 1943DEFUN (bgp_graceful_restart_stalepath_time,
1944 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1945 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1946 "BGP specific commands\n"
1947 "Graceful restart capability parameters\n"
1948 "Set the max time to hold onto restarting peer's stale paths\n"
1949 "Delay value (seconds)\n")
1950{
d62a17ae 1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
1952 int idx_number = 3;
d7c0a89a 1953 uint32_t stalepath;
93406d87 1954
d62a17ae 1955 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1956 bgp->stalepath_time = stalepath;
1957 return CMD_SUCCESS;
93406d87 1958}
1959
eb6f1b41
PG
1960DEFUN (bgp_graceful_restart_restart_time,
1961 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1962 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1963 "BGP specific commands\n"
1964 "Graceful restart capability parameters\n"
1965 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1966 "Delay value (seconds)\n")
1967{
d62a17ae 1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 int idx_number = 3;
d7c0a89a 1970 uint32_t restart;
eb6f1b41 1971
d62a17ae 1972 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1973 bgp->restart_time = restart;
1974 return CMD_SUCCESS;
eb6f1b41
PG
1975}
1976
93406d87 1977DEFUN (no_bgp_graceful_restart_stalepath_time,
1978 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1979 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1980 NO_STR
1981 "BGP specific commands\n"
1982 "Graceful restart capability parameters\n"
838758ac
DW
1983 "Set the max time to hold onto restarting peer's stale paths\n"
1984 "Delay value (seconds)\n")
93406d87 1985{
d62a17ae 1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1987
d62a17ae 1988 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1989 return CMD_SUCCESS;
93406d87 1990}
1991
eb6f1b41
PG
1992DEFUN (no_bgp_graceful_restart_restart_time,
1993 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1994 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Graceful restart capability parameters\n"
838758ac
DW
1998 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1999 "Delay value (seconds)\n")
eb6f1b41 2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2002
d62a17ae 2003 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2004 return CMD_SUCCESS;
eb6f1b41
PG
2005}
2006
43fc21b3
JC
2007DEFUN (bgp_graceful_restart_preserve_fw,
2008 bgp_graceful_restart_preserve_fw_cmd,
2009 "bgp graceful-restart preserve-fw-state",
2010 "BGP specific commands\n"
2011 "Graceful restart capability parameters\n"
2012 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2013{
d62a17ae 2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2016 return CMD_SUCCESS;
43fc21b3
JC
2017}
2018
2019DEFUN (no_bgp_graceful_restart_preserve_fw,
2020 no_bgp_graceful_restart_preserve_fw_cmd,
2021 "no bgp graceful-restart preserve-fw-state",
2022 NO_STR
2023 "BGP specific commands\n"
2024 "Graceful restart capability parameters\n"
2025 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2026{
d62a17ae 2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2029 return CMD_SUCCESS;
43fc21b3
JC
2030}
2031
7f323236
DW
2032static void bgp_redistribute_redo(struct bgp *bgp)
2033{
2034 afi_t afi;
2035 int i;
2036 struct list *red_list;
2037 struct listnode *node;
2038 struct bgp_redist *red;
2039
a4d82a8a
PZ
2040 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2041 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 2042
a4d82a8a
PZ
2043 red_list = bgp->redist[afi][i];
2044 if (!red_list)
2045 continue;
7f323236 2046
a4d82a8a 2047 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
2048 bgp_redistribute_resend(bgp, afi, i,
2049 red->instance);
2050 }
2051 }
2052 }
2053}
2054
2055/* "bgp graceful-shutdown" configuration */
2056DEFUN (bgp_graceful_shutdown,
2057 bgp_graceful_shutdown_cmd,
2058 "bgp graceful-shutdown",
2059 BGP_STR
2060 "Graceful shutdown parameters\n")
2061{
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063
2064 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2065 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2066 bgp_static_redo_import_check(bgp);
2067 bgp_redistribute_redo(bgp);
2068 bgp_clear_star_soft_out(vty, bgp->name);
2069 bgp_clear_star_soft_in(vty, bgp->name);
2070 }
2071
2072 return CMD_SUCCESS;
2073}
2074
2075DEFUN (no_bgp_graceful_shutdown,
2076 no_bgp_graceful_shutdown_cmd,
2077 "no bgp graceful-shutdown",
2078 NO_STR
2079 BGP_STR
2080 "Graceful shutdown parameters\n")
2081{
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2085 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2086 bgp_static_redo_import_check(bgp);
2087 bgp_redistribute_redo(bgp);
2088 bgp_clear_star_soft_out(vty, bgp->name);
2089 bgp_clear_star_soft_in(vty, bgp->name);
2090 }
2091
2092 return CMD_SUCCESS;
2093}
2094
718e3744 2095/* "bgp fast-external-failover" configuration. */
2096DEFUN (bgp_fast_external_failover,
2097 bgp_fast_external_failover_cmd,
2098 "bgp fast-external-failover",
2099 BGP_STR
2100 "Immediately reset session if a link to a directly connected external peer goes down\n")
2101{
d62a17ae 2102 VTY_DECLVAR_CONTEXT(bgp, bgp);
2103 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2104 return CMD_SUCCESS;
718e3744 2105}
2106
2107DEFUN (no_bgp_fast_external_failover,
2108 no_bgp_fast_external_failover_cmd,
2109 "no bgp fast-external-failover",
2110 NO_STR
2111 BGP_STR
2112 "Immediately reset session if a link to a directly connected external peer goes down\n")
2113{
d62a17ae 2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2116 return CMD_SUCCESS;
718e3744 2117}
6b0655a2 2118
718e3744 2119/* "bgp enforce-first-as" configuration. */
ec4f0750 2120#if CONFDATE > 20190517
47cbc09b
PM
2121CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2122#endif
2123
f07e1c4f
QY
2124DEFUN_HIDDEN (bgp_enforce_first_as,
2125 bgp_enforce_first_as_cmd,
2126 "[no] bgp enforce-first-as",
2127 NO_STR
2128 BGP_STR
2129 "Enforce the first AS for EBGP routes\n")
718e3744 2130{
d62a17ae 2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2132
f07e1c4f
QY
2133 if (strmatch(argv[0]->text, "no"))
2134 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2135 else
2136 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2137
d62a17ae 2138 return CMD_SUCCESS;
718e3744 2139}
6b0655a2 2140
718e3744 2141/* "bgp bestpath compare-routerid" configuration. */
2142DEFUN (bgp_bestpath_compare_router_id,
2143 bgp_bestpath_compare_router_id_cmd,
2144 "bgp bestpath compare-routerid",
2145 "BGP specific commands\n"
2146 "Change the default bestpath selection\n"
2147 "Compare router-id for identical EBGP paths\n")
2148{
d62a17ae 2149 VTY_DECLVAR_CONTEXT(bgp, bgp);
2150 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2151 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2152
d62a17ae 2153 return CMD_SUCCESS;
718e3744 2154}
2155
2156DEFUN (no_bgp_bestpath_compare_router_id,
2157 no_bgp_bestpath_compare_router_id_cmd,
2158 "no bgp bestpath compare-routerid",
2159 NO_STR
2160 "BGP specific commands\n"
2161 "Change the default bestpath selection\n"
2162 "Compare router-id for identical EBGP paths\n")
2163{
d62a17ae 2164 VTY_DECLVAR_CONTEXT(bgp, bgp);
2165 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2166 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2167
d62a17ae 2168 return CMD_SUCCESS;
718e3744 2169}
6b0655a2 2170
718e3744 2171/* "bgp bestpath as-path ignore" configuration. */
2172DEFUN (bgp_bestpath_aspath_ignore,
2173 bgp_bestpath_aspath_ignore_cmd,
2174 "bgp bestpath as-path ignore",
2175 "BGP specific commands\n"
2176 "Change the default bestpath selection\n"
2177 "AS-path attribute\n"
2178 "Ignore as-path length in selecting a route\n")
2179{
d62a17ae 2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2182 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2183
d62a17ae 2184 return CMD_SUCCESS;
718e3744 2185}
2186
2187DEFUN (no_bgp_bestpath_aspath_ignore,
2188 no_bgp_bestpath_aspath_ignore_cmd,
2189 "no bgp bestpath as-path ignore",
2190 NO_STR
2191 "BGP specific commands\n"
2192 "Change the default bestpath selection\n"
2193 "AS-path attribute\n"
2194 "Ignore as-path length in selecting a route\n")
2195{
d62a17ae 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2198 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2199
d62a17ae 2200 return CMD_SUCCESS;
718e3744 2201}
6b0655a2 2202
6811845b 2203/* "bgp bestpath as-path confed" configuration. */
2204DEFUN (bgp_bestpath_aspath_confed,
2205 bgp_bestpath_aspath_confed_cmd,
2206 "bgp bestpath as-path confed",
2207 "BGP specific commands\n"
2208 "Change the default bestpath selection\n"
2209 "AS-path attribute\n"
2210 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2211{
d62a17ae 2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2214 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2215
d62a17ae 2216 return CMD_SUCCESS;
6811845b 2217}
2218
2219DEFUN (no_bgp_bestpath_aspath_confed,
2220 no_bgp_bestpath_aspath_confed_cmd,
2221 "no bgp bestpath as-path confed",
2222 NO_STR
2223 "BGP specific commands\n"
2224 "Change the default bestpath selection\n"
2225 "AS-path attribute\n"
2226 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2227{
d62a17ae 2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2230 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2231
d62a17ae 2232 return CMD_SUCCESS;
6811845b 2233}
6b0655a2 2234
2fdd455c
PM
2235/* "bgp bestpath as-path multipath-relax" configuration. */
2236DEFUN (bgp_bestpath_aspath_multipath_relax,
2237 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2238 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2239 "BGP specific commands\n"
2240 "Change the default bestpath selection\n"
2241 "AS-path attribute\n"
2242 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2243 "Generate an AS_SET\n"
16fc1eec
DS
2244 "Do not generate an AS_SET\n")
2245{
d62a17ae 2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx = 0;
2248 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2249
d62a17ae 2250 /* no-as-set is now the default behavior so we can silently
2251 * ignore it */
2252 if (argv_find(argv, argc, "as-set", &idx))
2253 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2254 else
2255 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2256
d62a17ae 2257 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2258
d62a17ae 2259 return CMD_SUCCESS;
16fc1eec
DS
2260}
2261
219178b6
DW
2262DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2263 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2264 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2265 NO_STR
2266 "BGP specific commands\n"
2267 "Change the default bestpath selection\n"
2268 "AS-path attribute\n"
2269 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2270 "Generate an AS_SET\n"
16fc1eec
DS
2271 "Do not generate an AS_SET\n")
2272{
d62a17ae 2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2276 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2277
d62a17ae 2278 return CMD_SUCCESS;
2fdd455c 2279}
6b0655a2 2280
848973c7 2281/* "bgp log-neighbor-changes" configuration. */
2282DEFUN (bgp_log_neighbor_changes,
2283 bgp_log_neighbor_changes_cmd,
2284 "bgp log-neighbor-changes",
2285 "BGP specific commands\n"
2286 "Log neighbor up/down and reset reason\n")
2287{
d62a17ae 2288 VTY_DECLVAR_CONTEXT(bgp, bgp);
2289 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2290 return CMD_SUCCESS;
848973c7 2291}
2292
2293DEFUN (no_bgp_log_neighbor_changes,
2294 no_bgp_log_neighbor_changes_cmd,
2295 "no bgp log-neighbor-changes",
2296 NO_STR
2297 "BGP specific commands\n"
2298 "Log neighbor up/down and reset reason\n")
2299{
d62a17ae 2300 VTY_DECLVAR_CONTEXT(bgp, bgp);
2301 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2302 return CMD_SUCCESS;
848973c7 2303}
6b0655a2 2304
718e3744 2305/* "bgp bestpath med" configuration. */
2306DEFUN (bgp_bestpath_med,
2307 bgp_bestpath_med_cmd,
2d8c1a4d 2308 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2309 "BGP specific commands\n"
2310 "Change the default bestpath selection\n"
2311 "MED attribute\n"
2312 "Compare MED among confederation paths\n"
838758ac
DW
2313 "Treat missing MED as the least preferred one\n"
2314 "Treat missing MED as the least preferred one\n"
2315 "Compare MED among confederation paths\n")
718e3744 2316{
d62a17ae 2317 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2318
d62a17ae 2319 int idx = 0;
2320 if (argv_find(argv, argc, "confed", &idx))
2321 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2322 idx = 0;
2323 if (argv_find(argv, argc, "missing-as-worst", &idx))
2324 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2325
d62a17ae 2326 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2327
d62a17ae 2328 return CMD_SUCCESS;
718e3744 2329}
2330
718e3744 2331DEFUN (no_bgp_bestpath_med,
2332 no_bgp_bestpath_med_cmd,
2d8c1a4d 2333 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2334 NO_STR
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
3a2d747c
QY
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
718e3744 2342{
d62a17ae 2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2344
d62a17ae 2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2351
d62a17ae 2352 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2353
d62a17ae 2354 return CMD_SUCCESS;
718e3744 2355}
2356
718e3744 2357/* "no bgp default ipv4-unicast". */
2358DEFUN (no_bgp_default_ipv4_unicast,
2359 no_bgp_default_ipv4_unicast_cmd,
2360 "no bgp default ipv4-unicast",
2361 NO_STR
2362 "BGP specific commands\n"
2363 "Configure BGP defaults\n"
2364 "Activate ipv4-unicast for a peer by default\n")
2365{
d62a17ae 2366 VTY_DECLVAR_CONTEXT(bgp, bgp);
2367 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2368 return CMD_SUCCESS;
718e3744 2369}
2370
2371DEFUN (bgp_default_ipv4_unicast,
2372 bgp_default_ipv4_unicast_cmd,
2373 "bgp default ipv4-unicast",
2374 "BGP specific commands\n"
2375 "Configure BGP defaults\n"
2376 "Activate ipv4-unicast for a peer by default\n")
2377{
d62a17ae 2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2380 return CMD_SUCCESS;
718e3744 2381}
6b0655a2 2382
04b6bdc0
DW
2383/* Display hostname in certain command outputs */
2384DEFUN (bgp_default_show_hostname,
2385 bgp_default_show_hostname_cmd,
2386 "bgp default show-hostname",
2387 "BGP specific commands\n"
2388 "Configure BGP defaults\n"
0437e105 2389 "Show hostname in certain command outputs\n")
04b6bdc0 2390{
d62a17ae 2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2393 return CMD_SUCCESS;
04b6bdc0
DW
2394}
2395
2396DEFUN (no_bgp_default_show_hostname,
2397 no_bgp_default_show_hostname_cmd,
2398 "no bgp default show-hostname",
2399 NO_STR
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
0437e105 2402 "Show hostname in certain command outputs\n")
04b6bdc0 2403{
d62a17ae 2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2406 return CMD_SUCCESS;
04b6bdc0
DW
2407}
2408
8233ef81 2409/* "bgp network import-check" configuration. */
718e3744 2410DEFUN (bgp_network_import_check,
2411 bgp_network_import_check_cmd,
5623e905 2412 "bgp network import-check",
718e3744 2413 "BGP specific commands\n"
2414 "BGP network command\n"
5623e905 2415 "Check BGP network route exists in IGP\n")
718e3744 2416{
d62a17ae 2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2419 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2420 bgp_static_redo_import_check(bgp);
2421 }
078430f6 2422
d62a17ae 2423 return CMD_SUCCESS;
718e3744 2424}
2425
d62a17ae 2426ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2427 "bgp network import-check exact",
2428 "BGP specific commands\n"
2429 "BGP network command\n"
2430 "Check BGP network route exists in IGP\n"
2431 "Match route precisely\n")
8233ef81 2432
718e3744 2433DEFUN (no_bgp_network_import_check,
2434 no_bgp_network_import_check_cmd,
5623e905 2435 "no bgp network import-check",
718e3744 2436 NO_STR
2437 "BGP specific commands\n"
2438 "BGP network command\n"
2439 "Check BGP network route exists in IGP\n")
2440{
d62a17ae 2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
2442 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2443 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2444 bgp_static_redo_import_check(bgp);
2445 }
5623e905 2446
d62a17ae 2447 return CMD_SUCCESS;
718e3744 2448}
6b0655a2 2449
718e3744 2450DEFUN (bgp_default_local_preference,
2451 bgp_default_local_preference_cmd,
6147e2c6 2452 "bgp default local-preference (0-4294967295)",
718e3744 2453 "BGP specific commands\n"
2454 "Configure BGP defaults\n"
2455 "local preference (higher=more preferred)\n"
2456 "Configure default local preference value\n")
2457{
d62a17ae 2458 VTY_DECLVAR_CONTEXT(bgp, bgp);
2459 int idx_number = 3;
d7c0a89a 2460 uint32_t local_pref;
718e3744 2461
d62a17ae 2462 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2463
d62a17ae 2464 bgp_default_local_preference_set(bgp, local_pref);
2465 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2466
d62a17ae 2467 return CMD_SUCCESS;
718e3744 2468}
2469
2470DEFUN (no_bgp_default_local_preference,
2471 no_bgp_default_local_preference_cmd,
838758ac 2472 "no bgp default local-preference [(0-4294967295)]",
718e3744 2473 NO_STR
2474 "BGP specific commands\n"
2475 "Configure BGP defaults\n"
838758ac
DW
2476 "local preference (higher=more preferred)\n"
2477 "Configure default local preference value\n")
718e3744 2478{
d62a17ae 2479 VTY_DECLVAR_CONTEXT(bgp, bgp);
2480 bgp_default_local_preference_unset(bgp);
2481 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2482
d62a17ae 2483 return CMD_SUCCESS;
718e3744 2484}
2485
6b0655a2 2486
3f9c7369
DS
2487DEFUN (bgp_default_subgroup_pkt_queue_max,
2488 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2489 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2490 "BGP specific commands\n"
2491 "Configure BGP defaults\n"
2492 "subgroup-pkt-queue-max\n"
2493 "Configure subgroup packet queue max\n")
8bd9d948 2494{
d62a17ae 2495 VTY_DECLVAR_CONTEXT(bgp, bgp);
2496 int idx_number = 3;
d7c0a89a 2497 uint32_t max_size;
8bd9d948 2498
d62a17ae 2499 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2500
d62a17ae 2501 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2502
d62a17ae 2503 return CMD_SUCCESS;
3f9c7369
DS
2504}
2505
2506DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2507 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2508 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2509 NO_STR
2510 "BGP specific commands\n"
2511 "Configure BGP defaults\n"
838758ac
DW
2512 "subgroup-pkt-queue-max\n"
2513 "Configure subgroup packet queue max\n")
3f9c7369 2514{
d62a17ae 2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2517 return CMD_SUCCESS;
8bd9d948
DS
2518}
2519
813d4307 2520
8bd9d948
DS
2521DEFUN (bgp_rr_allow_outbound_policy,
2522 bgp_rr_allow_outbound_policy_cmd,
2523 "bgp route-reflector allow-outbound-policy",
2524 "BGP specific commands\n"
2525 "Allow modifications made by out route-map\n"
2526 "on ibgp neighbors\n")
2527{
d62a17ae 2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2529
d62a17ae 2530 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2531 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2532 update_group_announce_rrclients(bgp);
2533 bgp_clear_star_soft_out(vty, bgp->name);
2534 }
8bd9d948 2535
d62a17ae 2536 return CMD_SUCCESS;
8bd9d948
DS
2537}
2538
2539DEFUN (no_bgp_rr_allow_outbound_policy,
2540 no_bgp_rr_allow_outbound_policy_cmd,
2541 "no bgp route-reflector allow-outbound-policy",
2542 NO_STR
2543 "BGP specific commands\n"
2544 "Allow modifications made by out route-map\n"
2545 "on ibgp neighbors\n")
2546{
d62a17ae 2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2548
d62a17ae 2549 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2550 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2551 update_group_announce_rrclients(bgp);
2552 bgp_clear_star_soft_out(vty, bgp->name);
2553 }
8bd9d948 2554
d62a17ae 2555 return CMD_SUCCESS;
8bd9d948
DS
2556}
2557
f14e6fdb
DS
2558DEFUN (bgp_listen_limit,
2559 bgp_listen_limit_cmd,
9ccf14f7 2560 "bgp listen limit (1-5000)",
f14e6fdb
DS
2561 "BGP specific commands\n"
2562 "Configure BGP defaults\n"
2563 "maximum number of BGP Dynamic Neighbors that can be created\n"
2564 "Configure Dynamic Neighbors listen limit value\n")
2565{
d62a17ae 2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 int idx_number = 3;
2568 int listen_limit;
f14e6fdb 2569
d62a17ae 2570 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2571
d62a17ae 2572 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2573
d62a17ae 2574 return CMD_SUCCESS;
f14e6fdb
DS
2575}
2576
2577DEFUN (no_bgp_listen_limit,
2578 no_bgp_listen_limit_cmd,
838758ac 2579 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2580 "BGP specific commands\n"
2581 "Configure BGP defaults\n"
2582 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2583 "Configure Dynamic Neighbors listen limit value to default\n"
2584 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2585{
d62a17ae 2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 bgp_listen_limit_unset(bgp);
2588 return CMD_SUCCESS;
f14e6fdb
DS
2589}
2590
2591
20eb8864 2592/*
2593 * Check if this listen range is already configured. Check for exact
2594 * match or overlap based on input.
2595 */
d62a17ae 2596static struct peer_group *listen_range_exists(struct bgp *bgp,
2597 struct prefix *range, int exact)
2598{
2599 struct listnode *node, *nnode;
2600 struct listnode *node1, *nnode1;
2601 struct peer_group *group;
2602 struct prefix *lr;
2603 afi_t afi;
2604 int match;
2605
2606 afi = family2afi(range->family);
2607 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2608 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2609 lr)) {
2610 if (exact)
2611 match = prefix_same(range, lr);
2612 else
2613 match = (prefix_match(range, lr)
2614 || prefix_match(lr, range));
2615 if (match)
2616 return group;
2617 }
2618 }
2619
2620 return NULL;
20eb8864 2621}
2622
f14e6fdb
DS
2623DEFUN (bgp_listen_range,
2624 bgp_listen_range_cmd,
9ccf14f7 2625 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2626 "BGP specific commands\n"
d7fa34c1
QY
2627 "Configure BGP dynamic neighbors listen range\n"
2628 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2629 NEIGHBOR_ADDR_STR
2630 "Member of the peer-group\n"
2631 "Peer-group name\n")
f14e6fdb 2632{
d62a17ae 2633 VTY_DECLVAR_CONTEXT(bgp, bgp);
2634 struct prefix range;
2635 struct peer_group *group, *existing_group;
2636 afi_t afi;
2637 int ret;
2638 int idx = 0;
2639
2640 argv_find(argv, argc, "A.B.C.D/M", &idx);
2641 argv_find(argv, argc, "X:X::X:X/M", &idx);
2642 char *prefix = argv[idx]->arg;
2643 argv_find(argv, argc, "WORD", &idx);
2644 char *peergroup = argv[idx]->arg;
2645
2646 /* Convert IP prefix string to struct prefix. */
2647 ret = str2prefix(prefix, &range);
2648 if (!ret) {
2649 vty_out(vty, "%% Malformed listen range\n");
2650 return CMD_WARNING_CONFIG_FAILED;
2651 }
2652
2653 afi = family2afi(range.family);
2654
2655 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2656 vty_out(vty,
2657 "%% Malformed listen range (link-local address)\n");
2658 return CMD_WARNING_CONFIG_FAILED;
2659 }
2660
2661 apply_mask(&range);
2662
2663 /* Check if same listen range is already configured. */
2664 existing_group = listen_range_exists(bgp, &range, 1);
2665 if (existing_group) {
2666 if (strcmp(existing_group->name, peergroup) == 0)
2667 return CMD_SUCCESS;
2668 else {
2669 vty_out(vty,
2670 "%% Same listen range is attached to peer-group %s\n",
2671 existing_group->name);
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674 }
2675
2676 /* Check if an overlapping listen range exists. */
2677 if (listen_range_exists(bgp, &range, 0)) {
2678 vty_out(vty,
2679 "%% Listen range overlaps with existing listen range\n");
2680 return CMD_WARNING_CONFIG_FAILED;
2681 }
2682
2683 group = peer_group_lookup(bgp, peergroup);
2684 if (!group) {
2685 vty_out(vty, "%% Configure the peer-group first\n");
2686 return CMD_WARNING_CONFIG_FAILED;
2687 }
2688
2689 ret = peer_group_listen_range_add(group, &range);
2690 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2691}
2692
2693DEFUN (no_bgp_listen_range,
2694 no_bgp_listen_range_cmd,
d7fa34c1
QY
2695 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2696 NO_STR
f14e6fdb 2697 "BGP specific commands\n"
d7fa34c1
QY
2698 "Unconfigure BGP dynamic neighbors listen range\n"
2699 "Unconfigure BGP dynamic neighbors listen range\n"
2700 NEIGHBOR_ADDR_STR
2701 "Member of the peer-group\n"
2702 "Peer-group name\n")
f14e6fdb 2703{
d62a17ae 2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705 struct prefix range;
2706 struct peer_group *group;
2707 afi_t afi;
2708 int ret;
2709 int idx = 0;
2710
2711 argv_find(argv, argc, "A.B.C.D/M", &idx);
2712 argv_find(argv, argc, "X:X::X:X/M", &idx);
2713 char *prefix = argv[idx]->arg;
2714 argv_find(argv, argc, "WORD", &idx);
2715 char *peergroup = argv[idx]->arg;
2716
2717 /* Convert IP prefix string to struct prefix. */
2718 ret = str2prefix(prefix, &range);
2719 if (!ret) {
2720 vty_out(vty, "%% Malformed listen range\n");
2721 return CMD_WARNING_CONFIG_FAILED;
2722 }
2723
2724 afi = family2afi(range.family);
2725
2726 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2727 vty_out(vty,
2728 "%% Malformed listen range (link-local address)\n");
2729 return CMD_WARNING_CONFIG_FAILED;
2730 }
2731
2732 apply_mask(&range);
2733
2734 group = peer_group_lookup(bgp, peergroup);
2735 if (!group) {
2736 vty_out(vty, "%% Peer-group does not exist\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 ret = peer_group_listen_range_del(group, &range);
2741 return bgp_vty_return(vty, ret);
2742}
2743
2b791107 2744void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2745{
2746 struct peer_group *group;
2747 struct listnode *node, *nnode, *rnode, *nrnode;
2748 struct prefix *range;
2749 afi_t afi;
2750 char buf[PREFIX2STR_BUFFER];
2751
2752 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2753 vty_out(vty, " bgp listen limit %d\n",
2754 bgp->dynamic_neighbors_limit);
2755
2756 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2757 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2758 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2759 nrnode, range)) {
2760 prefix2str(range, buf, sizeof(buf));
2761 vty_out(vty,
2762 " bgp listen range %s peer-group %s\n",
2763 buf, group->name);
2764 }
2765 }
2766 }
f14e6fdb
DS
2767}
2768
2769
907f92c8
DS
2770DEFUN (bgp_disable_connected_route_check,
2771 bgp_disable_connected_route_check_cmd,
2772 "bgp disable-ebgp-connected-route-check",
2773 "BGP specific commands\n"
2774 "Disable checking if nexthop is connected on ebgp sessions\n")
2775{
d62a17ae 2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2778 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2779
d62a17ae 2780 return CMD_SUCCESS;
907f92c8
DS
2781}
2782
2783DEFUN (no_bgp_disable_connected_route_check,
2784 no_bgp_disable_connected_route_check_cmd,
2785 "no bgp disable-ebgp-connected-route-check",
2786 NO_STR
2787 "BGP specific commands\n"
2788 "Disable checking if nexthop is connected on ebgp sessions\n")
2789{
d62a17ae 2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2792 bgp_clear_star_soft_in(vty, bgp->name);
2793
2794 return CMD_SUCCESS;
2795}
2796
2797
2798static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2799 const char *as_str, afi_t afi, safi_t safi)
2800{
2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
2802 int ret;
2803 as_t as;
2804 int as_type = AS_SPECIFIED;
2805 union sockunion su;
2806
2807 if (as_str[0] == 'i') {
2808 as = 0;
2809 as_type = AS_INTERNAL;
2810 } else if (as_str[0] == 'e') {
2811 as = 0;
2812 as_type = AS_EXTERNAL;
2813 } else {
2814 /* Get AS number. */
2815 as = strtoul(as_str, NULL, 10);
2816 }
2817
2818 /* If peer is peer group, call proper function. */
2819 ret = str2sockunion(peer_str, &su);
2820 if (ret < 0) {
2821 /* Check for peer by interface */
2822 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2823 safi);
2824 if (ret < 0) {
2825 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2826 if (ret < 0) {
2827 vty_out(vty,
d762bcc3
DS
2828 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2829 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
d62a17ae 2830 return CMD_WARNING_CONFIG_FAILED;
2831 }
2832 return CMD_SUCCESS;
2833 }
2834 } else {
2835 if (peer_address_self_check(bgp, &su)) {
2836 vty_out(vty,
2837 "%% Can not configure the local system as neighbor\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2841 }
2842
2843 /* This peer belongs to peer group. */
2844 switch (ret) {
2845 case BGP_ERR_PEER_GROUP_MEMBER:
2846 vty_out(vty,
2847 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2848 as);
2849 return CMD_WARNING_CONFIG_FAILED;
2850 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2851 vty_out(vty,
2852 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2853 as, as_str);
2854 return CMD_WARNING_CONFIG_FAILED;
2855 }
2856 return bgp_vty_return(vty, ret);
718e3744 2857}
2858
f26845f9
QY
2859DEFUN (bgp_default_shutdown,
2860 bgp_default_shutdown_cmd,
2861 "[no] bgp default shutdown",
2862 NO_STR
2863 BGP_STR
2864 "Configure BGP defaults\n"
b012cbe2 2865 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2866{
2867 VTY_DECLVAR_CONTEXT(bgp, bgp);
2868 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2869 return CMD_SUCCESS;
2870}
2871
718e3744 2872DEFUN (neighbor_remote_as,
2873 neighbor_remote_as_cmd,
3a2d747c 2874 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2875 NEIGHBOR_STR
2876 NEIGHBOR_ADDR_STR2
2877 "Specify a BGP neighbor\n"
d7fa34c1 2878 AS_STR
3a2d747c
QY
2879 "Internal BGP peer\n"
2880 "External BGP peer\n")
718e3744 2881{
d62a17ae 2882 int idx_peer = 1;
2883 int idx_remote_as = 3;
2884 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2885 argv[idx_remote_as]->arg, AFI_IP,
2886 SAFI_UNICAST);
2887}
2888
2889static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2890 afi_t afi, safi_t safi, int v6only,
2891 const char *peer_group_name,
2892 const char *as_str)
2893{
2894 VTY_DECLVAR_CONTEXT(bgp, bgp);
2895 as_t as = 0;
2896 int as_type = AS_UNSPECIFIED;
2897 struct peer *peer;
2898 struct peer_group *group;
2899 int ret = 0;
2900 union sockunion su;
2901
2902 group = peer_group_lookup(bgp, conf_if);
2903
2904 if (group) {
2905 vty_out(vty, "%% Name conflict with peer-group \n");
2906 return CMD_WARNING_CONFIG_FAILED;
2907 }
2908
2909 if (as_str) {
2910 if (as_str[0] == 'i') {
2911 as_type = AS_INTERNAL;
2912 } else if (as_str[0] == 'e') {
2913 as_type = AS_EXTERNAL;
2914 } else {
2915 /* Get AS number. */
2916 as = strtoul(as_str, NULL, 10);
2917 as_type = AS_SPECIFIED;
2918 }
2919 }
2920
2921 peer = peer_lookup_by_conf_if(bgp, conf_if);
2922 if (peer) {
2923 if (as_str)
cc4d4ce8 2924 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2925 afi, safi);
2926 } else {
2927 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2928 && afi == AFI_IP && safi == SAFI_UNICAST)
2929 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2930 as_type, 0, 0, NULL);
2931 else
2932 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2933 as_type, afi, safi, NULL);
2934
2935 if (!peer) {
2936 vty_out(vty, "%% BGP failed to create peer\n");
2937 return CMD_WARNING_CONFIG_FAILED;
2938 }
2939
2940 if (v6only)
527de3dc 2941 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2942
2943 /* Request zebra to initiate IPv6 RAs on this interface. We do
2944 * this
2945 * any unnumbered peer in order to not worry about run-time
2946 * transitions
2947 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2948 * address
2949 * gets deleted later etc.)
2950 */
2951 if (peer->ifp)
2952 bgp_zebra_initiate_radv(bgp, peer);
2953 }
2954
2955 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2956 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2957 if (v6only)
527de3dc 2958 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2959 else
527de3dc 2960 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2961
2962 /* v6only flag changed. Reset bgp seesion */
2963 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2964 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2965 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2966 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2967 } else
2968 bgp_session_reset(peer);
2969 }
2970
9fb964de
PM
2971 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2972 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2973 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2974 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2975 }
d62a17ae 2976
2977 if (peer_group_name) {
2978 group = peer_group_lookup(bgp, peer_group_name);
2979 if (!group) {
2980 vty_out(vty, "%% Configure the peer-group first\n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983
2984 ret = peer_group_bind(bgp, &su, peer, group, &as);
2985 }
2986
2987 return bgp_vty_return(vty, ret);
a80beece
DS
2988}
2989
4c48cf63
DW
2990DEFUN (neighbor_interface_config,
2991 neighbor_interface_config_cmd,
31500417 2992 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2993 NEIGHBOR_STR
2994 "Interface name or neighbor tag\n"
31500417
DW
2995 "Enable BGP on interface\n"
2996 "Member of the peer-group\n"
16cedbb0 2997 "Peer-group name\n")
4c48cf63 2998{
d62a17ae 2999 int idx_word = 1;
3000 int idx_peer_group_word = 4;
31500417 3001
d62a17ae 3002 if (argc > idx_peer_group_word)
3003 return peer_conf_interface_get(
3004 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3005 argv[idx_peer_group_word]->arg, NULL);
3006 else
3007 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3008 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3009}
3010
4c48cf63
DW
3011DEFUN (neighbor_interface_config_v6only,
3012 neighbor_interface_config_v6only_cmd,
31500417 3013 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
3014 NEIGHBOR_STR
3015 "Interface name or neighbor tag\n"
3016 "Enable BGP on interface\n"
31500417
DW
3017 "Enable BGP with v6 link-local only\n"
3018 "Member of the peer-group\n"
16cedbb0 3019 "Peer-group name\n")
4c48cf63 3020{
d62a17ae 3021 int idx_word = 1;
3022 int idx_peer_group_word = 5;
31500417 3023
d62a17ae 3024 if (argc > idx_peer_group_word)
3025 return peer_conf_interface_get(
3026 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3027 argv[idx_peer_group_word]->arg, NULL);
31500417 3028
d62a17ae 3029 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3030 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3031}
3032
a80beece 3033
b3a39dc5
DD
3034DEFUN (neighbor_interface_config_remote_as,
3035 neighbor_interface_config_remote_as_cmd,
3a2d747c 3036 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3037 NEIGHBOR_STR
3038 "Interface name or neighbor tag\n"
3039 "Enable BGP on interface\n"
3a2d747c 3040 "Specify a BGP neighbor\n"
d7fa34c1 3041 AS_STR
3a2d747c
QY
3042 "Internal BGP peer\n"
3043 "External BGP peer\n")
b3a39dc5 3044{
d62a17ae 3045 int idx_word = 1;
3046 int idx_remote_as = 4;
3047 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3048 SAFI_UNICAST, 0, NULL,
3049 argv[idx_remote_as]->arg);
b3a39dc5
DD
3050}
3051
3052DEFUN (neighbor_interface_v6only_config_remote_as,
3053 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3054 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3055 NEIGHBOR_STR
3056 "Interface name or neighbor tag\n"
3a2d747c 3057 "Enable BGP with v6 link-local only\n"
b3a39dc5 3058 "Enable BGP on interface\n"
3a2d747c 3059 "Specify a BGP neighbor\n"
d7fa34c1 3060 AS_STR
3a2d747c
QY
3061 "Internal BGP peer\n"
3062 "External BGP peer\n")
b3a39dc5 3063{
d62a17ae 3064 int idx_word = 1;
3065 int idx_remote_as = 5;
3066 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3067 SAFI_UNICAST, 1, NULL,
3068 argv[idx_remote_as]->arg);
b3a39dc5
DD
3069}
3070
718e3744 3071DEFUN (neighbor_peer_group,
3072 neighbor_peer_group_cmd,
3073 "neighbor WORD peer-group",
3074 NEIGHBOR_STR
a80beece 3075 "Interface name or neighbor tag\n"
718e3744 3076 "Configure peer-group\n")
3077{
d62a17ae 3078 VTY_DECLVAR_CONTEXT(bgp, bgp);
3079 int idx_word = 1;
3080 struct peer *peer;
3081 struct peer_group *group;
718e3744 3082
d62a17ae 3083 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3084 if (peer) {
3085 vty_out(vty, "%% Name conflict with interface: \n");
3086 return CMD_WARNING_CONFIG_FAILED;
3087 }
718e3744 3088
d62a17ae 3089 group = peer_group_get(bgp, argv[idx_word]->arg);
3090 if (!group) {
3091 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3092 return CMD_WARNING_CONFIG_FAILED;
3093 }
718e3744 3094
d62a17ae 3095 return CMD_SUCCESS;
718e3744 3096}
3097
3098DEFUN (no_neighbor,
3099 no_neighbor_cmd,
dab8cd00 3100 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3101 NO_STR
3102 NEIGHBOR_STR
3a2d747c
QY
3103 NEIGHBOR_ADDR_STR2
3104 "Specify a BGP neighbor\n"
3105 AS_STR
3106 "Internal BGP peer\n"
3107 "External BGP peer\n")
718e3744 3108{
d62a17ae 3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 int idx_peer = 2;
3111 int ret;
3112 union sockunion su;
3113 struct peer_group *group;
3114 struct peer *peer;
3115 struct peer *other;
3116
3117 ret = str2sockunion(argv[idx_peer]->arg, &su);
3118 if (ret < 0) {
3119 /* look up for neighbor by interface name config. */
3120 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3121 if (peer) {
3122 /* Request zebra to terminate IPv6 RAs on this
3123 * interface. */
3124 if (peer->ifp)
3125 bgp_zebra_terminate_radv(peer->bgp, peer);
3126 peer_delete(peer);
3127 return CMD_SUCCESS;
3128 }
f14e6fdb 3129
d62a17ae 3130 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3131 if (group)
3132 peer_group_delete(group);
3133 else {
3134 vty_out(vty, "%% Create the peer-group first\n");
3135 return CMD_WARNING_CONFIG_FAILED;
3136 }
3137 } else {
3138 peer = peer_lookup(bgp, &su);
3139 if (peer) {
3140 if (peer_dynamic_neighbor(peer)) {
3141 vty_out(vty,
3142 "%% Operation not allowed on a dynamic neighbor\n");
3143 return CMD_WARNING_CONFIG_FAILED;
3144 }
3145
3146 other = peer->doppelganger;
3147 peer_delete(peer);
3148 if (other && other->status != Deleted)
3149 peer_delete(other);
3150 }
1ff9a340 3151 }
718e3744 3152
d62a17ae 3153 return CMD_SUCCESS;
718e3744 3154}
3155
a80beece
DS
3156DEFUN (no_neighbor_interface_config,
3157 no_neighbor_interface_config_cmd,
31500417 3158 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3159 NO_STR
3160 NEIGHBOR_STR
3161 "Interface name\n"
31500417
DW
3162 "Configure BGP on interface\n"
3163 "Enable BGP with v6 link-local only\n"
3164 "Member of the peer-group\n"
16cedbb0 3165 "Peer-group name\n"
3a2d747c
QY
3166 "Specify a BGP neighbor\n"
3167 AS_STR
3168 "Internal BGP peer\n"
3169 "External BGP peer\n")
a80beece 3170{
d62a17ae 3171 VTY_DECLVAR_CONTEXT(bgp, bgp);
3172 int idx_word = 2;
3173 struct peer *peer;
3174
3175 /* look up for neighbor by interface name config. */
3176 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3177 if (peer) {
3178 /* Request zebra to terminate IPv6 RAs on this interface. */
3179 if (peer->ifp)
3180 bgp_zebra_terminate_radv(peer->bgp, peer);
3181 peer_delete(peer);
3182 } else {
3183 vty_out(vty, "%% Create the bgp interface first\n");
3184 return CMD_WARNING_CONFIG_FAILED;
3185 }
3186 return CMD_SUCCESS;
a80beece
DS
3187}
3188
718e3744 3189DEFUN (no_neighbor_peer_group,
3190 no_neighbor_peer_group_cmd,
3191 "no neighbor WORD peer-group",
3192 NO_STR
3193 NEIGHBOR_STR
3194 "Neighbor tag\n"
3195 "Configure peer-group\n")
3196{
d62a17ae 3197 VTY_DECLVAR_CONTEXT(bgp, bgp);
3198 int idx_word = 2;
3199 struct peer_group *group;
718e3744 3200
d62a17ae 3201 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3202 if (group)
3203 peer_group_delete(group);
3204 else {
3205 vty_out(vty, "%% Create the peer-group first\n");
3206 return CMD_WARNING_CONFIG_FAILED;
3207 }
3208 return CMD_SUCCESS;
718e3744 3209}
3210
a80beece
DS
3211DEFUN (no_neighbor_interface_peer_group_remote_as,
3212 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3213 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3214 NO_STR
3215 NEIGHBOR_STR
a80beece 3216 "Interface name or neighbor tag\n"
718e3744 3217 "Specify a BGP neighbor\n"
3a2d747c
QY
3218 AS_STR
3219 "Internal BGP peer\n"
3220 "External BGP peer\n")
718e3744 3221{
d62a17ae 3222 VTY_DECLVAR_CONTEXT(bgp, bgp);
3223 int idx_word = 2;
3224 struct peer_group *group;
3225 struct peer *peer;
3226
3227 /* look up for neighbor by interface name config. */
3228 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3229 if (peer) {
3230 peer_as_change(peer, 0, AS_SPECIFIED);
3231 return CMD_SUCCESS;
3232 }
3233
3234 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3235 if (group)
3236 peer_group_remote_as_delete(group);
3237 else {
3238 vty_out(vty, "%% Create the peer-group or interface first\n");
3239 return CMD_WARNING_CONFIG_FAILED;
3240 }
3241 return CMD_SUCCESS;
718e3744 3242}
6b0655a2 3243
718e3744 3244DEFUN (neighbor_local_as,
3245 neighbor_local_as_cmd,
9ccf14f7 3246 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 "Specify a local-as number\n"
3250 "AS number used as local AS\n")
3251{
d62a17ae 3252 int idx_peer = 1;
3253 int idx_number = 3;
3254 struct peer *peer;
3255 int ret;
3256 as_t as;
718e3744 3257
d62a17ae 3258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
718e3744 3261
d62a17ae 3262 as = strtoul(argv[idx_number]->arg, NULL, 10);
3263 ret = peer_local_as_set(peer, as, 0, 0);
3264 return bgp_vty_return(vty, ret);
718e3744 3265}
3266
3267DEFUN (neighbor_local_as_no_prepend,
3268 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3269 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Specify a local-as number\n"
3273 "AS number used as local AS\n"
3274 "Do not prepend local-as to updates from ebgp peers\n")
3275{
d62a17ae 3276 int idx_peer = 1;
3277 int idx_number = 3;
3278 struct peer *peer;
3279 int ret;
3280 as_t as;
718e3744 3281
d62a17ae 3282 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3283 if (!peer)
3284 return CMD_WARNING_CONFIG_FAILED;
718e3744 3285
d62a17ae 3286 as = strtoul(argv[idx_number]->arg, NULL, 10);
3287 ret = peer_local_as_set(peer, as, 1, 0);
3288 return bgp_vty_return(vty, ret);
718e3744 3289}
3290
9d3f9705
AC
3291DEFUN (neighbor_local_as_no_prepend_replace_as,
3292 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3293 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3294 NEIGHBOR_STR
3295 NEIGHBOR_ADDR_STR2
3296 "Specify a local-as number\n"
3297 "AS number used as local AS\n"
3298 "Do not prepend local-as to updates from ebgp peers\n"
3299 "Do not prepend local-as to updates from ibgp peers\n")
3300{
d62a17ae 3301 int idx_peer = 1;
3302 int idx_number = 3;
3303 struct peer *peer;
3304 int ret;
3305 as_t as;
9d3f9705 3306
d62a17ae 3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3310
d62a17ae 3311 as = strtoul(argv[idx_number]->arg, NULL, 10);
3312 ret = peer_local_as_set(peer, as, 1, 1);
3313 return bgp_vty_return(vty, ret);
9d3f9705
AC
3314}
3315
718e3744 3316DEFUN (no_neighbor_local_as,
3317 no_neighbor_local_as_cmd,
a636c635 3318 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3319 NO_STR
3320 NEIGHBOR_STR
3321 NEIGHBOR_ADDR_STR2
a636c635
DW
3322 "Specify a local-as number\n"
3323 "AS number used as local AS\n"
3324 "Do not prepend local-as to updates from ebgp peers\n"
3325 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3326{
d62a17ae 3327 int idx_peer = 2;
3328 struct peer *peer;
3329 int ret;
718e3744 3330
d62a17ae 3331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3332 if (!peer)
3333 return CMD_WARNING_CONFIG_FAILED;
718e3744 3334
d62a17ae 3335 ret = peer_local_as_unset(peer);
3336 return bgp_vty_return(vty, ret);
718e3744 3337}
3338
718e3744 3339
3f9c7369
DS
3340DEFUN (neighbor_solo,
3341 neighbor_solo_cmd,
9ccf14f7 3342 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
3345 "Solo peer - part of its own update group\n")
3346{
d62a17ae 3347 int idx_peer = 1;
3348 struct peer *peer;
3349 int ret;
3f9c7369 3350
d62a17ae 3351 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3352 if (!peer)
3353 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3354
d62a17ae 3355 ret = update_group_adjust_soloness(peer, 1);
3356 return bgp_vty_return(vty, ret);
3f9c7369
DS
3357}
3358
3359DEFUN (no_neighbor_solo,
3360 no_neighbor_solo_cmd,
9ccf14f7 3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Solo peer - part of its own update group\n")
3366{
d62a17ae 3367 int idx_peer = 2;
3368 struct peer *peer;
3369 int ret;
3f9c7369 3370
d62a17ae 3371 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3372 if (!peer)
3373 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3374
d62a17ae 3375 ret = update_group_adjust_soloness(peer, 0);
3376 return bgp_vty_return(vty, ret);
3f9c7369
DS
3377}
3378
0df7c91f
PJ
3379DEFUN (neighbor_password,
3380 neighbor_password_cmd,
9ccf14f7 3381 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3382 NEIGHBOR_STR
3383 NEIGHBOR_ADDR_STR2
3384 "Set a password\n"
3385 "The password\n")
3386{
d62a17ae 3387 int idx_peer = 1;
3388 int idx_line = 3;
3389 struct peer *peer;
3390 int ret;
0df7c91f 3391
d62a17ae 3392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3393 if (!peer)
3394 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3395
d62a17ae 3396 ret = peer_password_set(peer, argv[idx_line]->arg);
3397 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3398}
3399
3400DEFUN (no_neighbor_password,
3401 no_neighbor_password_cmd,
a636c635 3402 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3403 NO_STR
3404 NEIGHBOR_STR
3405 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3406 "Set a password\n"
3407 "The password\n")
0df7c91f 3408{
d62a17ae 3409 int idx_peer = 2;
3410 struct peer *peer;
3411 int ret;
0df7c91f 3412
d62a17ae 3413 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3414 if (!peer)
3415 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3416
d62a17ae 3417 ret = peer_password_unset(peer);
3418 return bgp_vty_return(vty, ret);
0df7c91f 3419}
6b0655a2 3420
718e3744 3421DEFUN (neighbor_activate,
3422 neighbor_activate_cmd,
9ccf14f7 3423 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3424 NEIGHBOR_STR
3425 NEIGHBOR_ADDR_STR2
3426 "Enable the Address Family for this Neighbor\n")
3427{
d62a17ae 3428 int idx_peer = 1;
3429 int ret;
3430 struct peer *peer;
718e3744 3431
d62a17ae 3432 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3433 if (!peer)
3434 return CMD_WARNING_CONFIG_FAILED;
718e3744 3435
d62a17ae 3436 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3437 return bgp_vty_return(vty, ret);
718e3744 3438}
3439
d62a17ae 3440ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3441 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3443 "Enable the Address Family for this Neighbor\n")
596c17ba 3444
718e3744 3445DEFUN (no_neighbor_activate,
3446 no_neighbor_activate_cmd,
9ccf14f7 3447 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3448 NO_STR
3449 NEIGHBOR_STR
3450 NEIGHBOR_ADDR_STR2
3451 "Enable the Address Family for this Neighbor\n")
3452{
d62a17ae 3453 int idx_peer = 2;
3454 int ret;
3455 struct peer *peer;
718e3744 3456
d62a17ae 3457 /* Lookup peer. */
3458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3459 if (!peer)
3460 return CMD_WARNING_CONFIG_FAILED;
718e3744 3461
d62a17ae 3462 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3463 return bgp_vty_return(vty, ret);
718e3744 3464}
6b0655a2 3465
d62a17ae 3466ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3467 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3469 "Enable the Address Family for this Neighbor\n")
596c17ba 3470
718e3744 3471DEFUN (neighbor_set_peer_group,
3472 neighbor_set_peer_group_cmd,
9ccf14f7 3473 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3474 NEIGHBOR_STR
a80beece 3475 NEIGHBOR_ADDR_STR2
718e3744 3476 "Member of the peer-group\n"
16cedbb0 3477 "Peer-group name\n")
718e3744 3478{
d62a17ae 3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 int idx_peer = 1;
3481 int idx_word = 3;
3482 int ret;
3483 as_t as;
3484 union sockunion su;
3485 struct peer *peer;
3486 struct peer_group *group;
3487
d62a17ae 3488 ret = str2sockunion(argv[idx_peer]->arg, &su);
3489 if (ret < 0) {
3490 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3491 if (!peer) {
3492 vty_out(vty, "%% Malformed address or name: %s\n",
3493 argv[idx_peer]->arg);
3494 return CMD_WARNING_CONFIG_FAILED;
3495 }
3496 } else {
3497 if (peer_address_self_check(bgp, &su)) {
3498 vty_out(vty,
3499 "%% Can not configure the local system as neighbor\n");
3500 return CMD_WARNING_CONFIG_FAILED;
3501 }
3502
3503 /* Disallow for dynamic neighbor. */
3504 peer = peer_lookup(bgp, &su);
3505 if (peer && peer_dynamic_neighbor(peer)) {
3506 vty_out(vty,
3507 "%% Operation not allowed on a dynamic neighbor\n");
3508 return CMD_WARNING_CONFIG_FAILED;
3509 }
3510 }
3511
3512 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3513 if (!group) {
3514 vty_out(vty, "%% Configure the peer-group first\n");
3515 return CMD_WARNING_CONFIG_FAILED;
3516 }
3517
3518 ret = peer_group_bind(bgp, &su, peer, group, &as);
3519
3520 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3521 vty_out(vty,
3522 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3523 as);
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526
3527 return bgp_vty_return(vty, ret);
3528}
3529
3530ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3531 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3532 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3533 "Member of the peer-group\n"
3534 "Peer-group name\n")
596c17ba 3535
718e3744 3536DEFUN (no_neighbor_set_peer_group,
3537 no_neighbor_set_peer_group_cmd,
9ccf14f7 3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3539 NO_STR
3540 NEIGHBOR_STR
a80beece 3541 NEIGHBOR_ADDR_STR2
718e3744 3542 "Member of the peer-group\n"
16cedbb0 3543 "Peer-group name\n")
718e3744 3544{
d62a17ae 3545 VTY_DECLVAR_CONTEXT(bgp, bgp);
3546 int idx_peer = 2;
3547 int idx_word = 4;
3548 int ret;
3549 struct peer *peer;
3550 struct peer_group *group;
3551
3552 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3553 if (!peer)
3554 return CMD_WARNING_CONFIG_FAILED;
3555
3556 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3557 if (!group) {
3558 vty_out(vty, "%% Configure the peer-group first\n");
3559 return CMD_WARNING_CONFIG_FAILED;
3560 }
718e3744 3561
827ed707 3562 ret = peer_delete(peer);
718e3744 3563
d62a17ae 3564 return bgp_vty_return(vty, ret);
718e3744 3565}
6b0655a2 3566
d62a17ae 3567ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3570 "Member of the peer-group\n"
3571 "Peer-group name\n")
596c17ba 3572
d62a17ae 3573static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3574 uint32_t flag, int set)
718e3744 3575{
d62a17ae 3576 int ret;
3577 struct peer *peer;
718e3744 3578
d62a17ae 3579 peer = peer_and_group_lookup_vty(vty, ip_str);
3580 if (!peer)
3581 return CMD_WARNING_CONFIG_FAILED;
718e3744 3582
7ebe625c
QY
3583 /*
3584 * If 'neighbor <interface>', then this is for directly connected peers,
3585 * we should not accept disable-connected-check.
3586 */
3587 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3588 vty_out(vty,
3589 "%s is directly connected peer, cannot accept disable-"
3590 "connected-check\n",
3591 ip_str);
3592 return CMD_WARNING_CONFIG_FAILED;
3593 }
3594
d62a17ae 3595 if (!set && flag == PEER_FLAG_SHUTDOWN)
3596 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3597
d62a17ae 3598 if (set)
3599 ret = peer_flag_set(peer, flag);
3600 else
3601 ret = peer_flag_unset(peer, flag);
718e3744 3602
d62a17ae 3603 return bgp_vty_return(vty, ret);
718e3744 3604}
3605
47cbc09b 3606static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3607{
d62a17ae 3608 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3609}
3610
d62a17ae 3611static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3612 uint32_t flag)
718e3744 3613{
d62a17ae 3614 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3615}
3616
3617/* neighbor passive. */
3618DEFUN (neighbor_passive,
3619 neighbor_passive_cmd,
9ccf14f7 3620 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3621 NEIGHBOR_STR
3622 NEIGHBOR_ADDR_STR2
3623 "Don't send open messages to this neighbor\n")
3624{
d62a17ae 3625 int idx_peer = 1;
3626 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3627}
3628
3629DEFUN (no_neighbor_passive,
3630 no_neighbor_passive_cmd,
9ccf14f7 3631 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3632 NO_STR
3633 NEIGHBOR_STR
3634 NEIGHBOR_ADDR_STR2
3635 "Don't send open messages to this neighbor\n")
3636{
d62a17ae 3637 int idx_peer = 2;
3638 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3639}
6b0655a2 3640
718e3744 3641/* neighbor shutdown. */
73d70fa6
DL
3642DEFUN (neighbor_shutdown_msg,
3643 neighbor_shutdown_msg_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3647 "Administratively shut down this neighbor\n"
3648 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3649 "Shutdown message\n")
718e3744 3650{
d62a17ae 3651 int idx_peer = 1;
73d70fa6 3652
d62a17ae 3653 if (argc >= 5) {
3654 struct peer *peer =
3655 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3656 char *message;
73d70fa6 3657
d62a17ae 3658 if (!peer)
3659 return CMD_WARNING_CONFIG_FAILED;
3660 message = argv_concat(argv, argc, 4);
3661 peer_tx_shutdown_message_set(peer, message);
3662 XFREE(MTYPE_TMP, message);
3663 }
73d70fa6 3664
d62a17ae 3665 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3666}
3667
d62a17ae 3668ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3669 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3671 "Administratively shut down this neighbor\n")
73d70fa6
DL
3672
3673DEFUN (no_neighbor_shutdown_msg,
3674 no_neighbor_shutdown_msg_cmd,
3675 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3676 NO_STR
3677 NEIGHBOR_STR
3678 NEIGHBOR_ADDR_STR2
3679 "Administratively shut down this neighbor\n"
3680 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3681 "Shutdown message\n")
718e3744 3682{
d62a17ae 3683 int idx_peer = 2;
73d70fa6 3684
d62a17ae 3685 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3686 PEER_FLAG_SHUTDOWN);
718e3744 3687}
6b0655a2 3688
d62a17ae 3689ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3692 "Administratively shut down this neighbor\n")
73d70fa6 3693
718e3744 3694/* neighbor capability dynamic. */
3695DEFUN (neighbor_capability_dynamic,
3696 neighbor_capability_dynamic_cmd,
9ccf14f7 3697 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3698 NEIGHBOR_STR
3699 NEIGHBOR_ADDR_STR2
3700 "Advertise capability to the peer\n"
3701 "Advertise dynamic capability to this neighbor\n")
3702{
d62a17ae 3703 int idx_peer = 1;
3704 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3705 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3706}
3707
3708DEFUN (no_neighbor_capability_dynamic,
3709 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3710 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3711 NO_STR
3712 NEIGHBOR_STR
3713 NEIGHBOR_ADDR_STR2
3714 "Advertise capability to the peer\n"
3715 "Advertise dynamic capability to this neighbor\n")
3716{
d62a17ae 3717 int idx_peer = 2;
3718 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3719 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3720}
6b0655a2 3721
718e3744 3722/* neighbor dont-capability-negotiate */
3723DEFUN (neighbor_dont_capability_negotiate,
3724 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3725 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3726 NEIGHBOR_STR
3727 NEIGHBOR_ADDR_STR2
3728 "Do not perform capability negotiation\n")
3729{
d62a17ae 3730 int idx_peer = 1;
3731 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3732 PEER_FLAG_DONT_CAPABILITY);
718e3744 3733}
3734
3735DEFUN (no_neighbor_dont_capability_negotiate,
3736 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3737 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3738 NO_STR
3739 NEIGHBOR_STR
3740 NEIGHBOR_ADDR_STR2
3741 "Do not perform capability negotiation\n")
3742{
d62a17ae 3743 int idx_peer = 2;
3744 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3745 PEER_FLAG_DONT_CAPABILITY);
718e3744 3746}
6b0655a2 3747
8a92a8a0
DS
3748/* neighbor capability extended next hop encoding */
3749DEFUN (neighbor_capability_enhe,
3750 neighbor_capability_enhe_cmd,
9ccf14f7 3751 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise extended next-hop capability to the peer\n")
3756{
d62a17ae 3757 int idx_peer = 1;
3758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3760}
3761
3762DEFUN (no_neighbor_capability_enhe,
3763 no_neighbor_capability_enhe_cmd,
9ccf14f7 3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Advertise capability to the peer\n"
3769 "Advertise extended next-hop capability to the peer\n")
3770{
d62a17ae 3771 int idx_peer = 2;
3772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3774}
3775
d62a17ae 3776static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3777 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3778 int set)
718e3744 3779{
d62a17ae 3780 int ret;
3781 struct peer *peer;
718e3744 3782
d62a17ae 3783 peer = peer_and_group_lookup_vty(vty, peer_str);
3784 if (!peer)
3785 return CMD_WARNING_CONFIG_FAILED;
718e3744 3786
d62a17ae 3787 if (set)
3788 ret = peer_af_flag_set(peer, afi, safi, flag);
3789 else
3790 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3791
d62a17ae 3792 return bgp_vty_return(vty, ret);
718e3744 3793}
3794
d62a17ae 3795static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3796 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3797{
d62a17ae 3798 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3799}
3800
d62a17ae 3801static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3802 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3803{
d62a17ae 3804 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3805}
6b0655a2 3806
718e3744 3807/* neighbor capability orf prefix-list. */
3808DEFUN (neighbor_capability_orf_prefix,
3809 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3810 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3811 NEIGHBOR_STR
3812 NEIGHBOR_ADDR_STR2
3813 "Advertise capability to the peer\n"
3814 "Advertise ORF capability to the peer\n"
3815 "Advertise prefixlist ORF capability to this neighbor\n"
3816 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3817 "Capability to RECEIVE the ORF from this neighbor\n"
3818 "Capability to SEND the ORF to this neighbor\n")
3819{
d62a17ae 3820 int idx_peer = 1;
3821 int idx_send_recv = 5;
d7c0a89a 3822 uint16_t flag = 0;
d62a17ae 3823
3824 if (strmatch(argv[idx_send_recv]->text, "send"))
3825 flag = PEER_FLAG_ORF_PREFIX_SM;
3826 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3827 flag = PEER_FLAG_ORF_PREFIX_RM;
3828 else if (strmatch(argv[idx_send_recv]->text, "both"))
3829 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3830 else {
3831 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3832 return CMD_WARNING_CONFIG_FAILED;
3833 }
3834
3835 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3836 bgp_node_safi(vty), flag);
3837}
3838
3839ALIAS_HIDDEN(
3840 neighbor_capability_orf_prefix,
3841 neighbor_capability_orf_prefix_hidden_cmd,
3842 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3844 "Advertise capability to the peer\n"
3845 "Advertise ORF capability to the peer\n"
3846 "Advertise prefixlist ORF capability to this neighbor\n"
3847 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3848 "Capability to RECEIVE the ORF from this neighbor\n"
3849 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3850
718e3744 3851DEFUN (no_neighbor_capability_orf_prefix,
3852 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3853 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3854 NO_STR
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Advertise capability to the peer\n"
3858 "Advertise ORF capability to the peer\n"
3859 "Advertise prefixlist ORF capability to this neighbor\n"
3860 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3861 "Capability to RECEIVE the ORF from this neighbor\n"
3862 "Capability to SEND the ORF to this neighbor\n")
3863{
d62a17ae 3864 int idx_peer = 2;
3865 int idx_send_recv = 6;
d7c0a89a 3866 uint16_t flag = 0;
d62a17ae 3867
3868 if (strmatch(argv[idx_send_recv]->text, "send"))
3869 flag = PEER_FLAG_ORF_PREFIX_SM;
3870 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3871 flag = PEER_FLAG_ORF_PREFIX_RM;
3872 else if (strmatch(argv[idx_send_recv]->text, "both"))
3873 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3874 else {
3875 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3876 return CMD_WARNING_CONFIG_FAILED;
3877 }
3878
3879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3880 bgp_node_afi(vty), bgp_node_safi(vty),
3881 flag);
3882}
3883
3884ALIAS_HIDDEN(
3885 no_neighbor_capability_orf_prefix,
3886 no_neighbor_capability_orf_prefix_hidden_cmd,
3887 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3889 "Advertise capability to the peer\n"
3890 "Advertise ORF capability to the peer\n"
3891 "Advertise prefixlist ORF capability to this neighbor\n"
3892 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3893 "Capability to RECEIVE the ORF from this neighbor\n"
3894 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3895
718e3744 3896/* neighbor next-hop-self. */
3897DEFUN (neighbor_nexthop_self,
3898 neighbor_nexthop_self_cmd,
9ccf14f7 3899 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
a538debe 3902 "Disable the next hop calculation for this neighbor\n")
718e3744 3903{
d62a17ae 3904 int idx_peer = 1;
3905 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3906 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3907}
9e7a53c1 3908
d62a17ae 3909ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3910 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3912 "Disable the next hop calculation for this neighbor\n")
596c17ba 3913
a538debe
DS
3914/* neighbor next-hop-self. */
3915DEFUN (neighbor_nexthop_self_force,
3916 neighbor_nexthop_self_force_cmd,
9ccf14f7 3917 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3918 NEIGHBOR_STR
3919 NEIGHBOR_ADDR_STR2
3920 "Disable the next hop calculation for this neighbor\n"
3921 "Set the next hop to self for reflected routes\n")
3922{
d62a17ae 3923 int idx_peer = 1;
3924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3925 bgp_node_safi(vty),
3926 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3927}
3928
d62a17ae 3929ALIAS_HIDDEN(neighbor_nexthop_self_force,
3930 neighbor_nexthop_self_force_hidden_cmd,
3931 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3933 "Disable the next hop calculation for this neighbor\n"
3934 "Set the next hop to self for reflected routes\n")
596c17ba 3935
718e3744 3936DEFUN (no_neighbor_nexthop_self,
3937 no_neighbor_nexthop_self_cmd,
9ccf14f7 3938 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3939 NO_STR
3940 NEIGHBOR_STR
3941 NEIGHBOR_ADDR_STR2
a538debe 3942 "Disable the next hop calculation for this neighbor\n")
718e3744 3943{
d62a17ae 3944 int idx_peer = 2;
3945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3946 bgp_node_afi(vty), bgp_node_safi(vty),
3947 PEER_FLAG_NEXTHOP_SELF);
718e3744 3948}
6b0655a2 3949
d62a17ae 3950ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3951 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3953 "Disable the next hop calculation for this neighbor\n")
596c17ba 3954
88b8ed8d 3955DEFUN (no_neighbor_nexthop_self_force,
a538debe 3956 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3957 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3958 NO_STR
3959 NEIGHBOR_STR
3960 NEIGHBOR_ADDR_STR2
3961 "Disable the next hop calculation for this neighbor\n"
3962 "Set the next hop to self for reflected routes\n")
88b8ed8d 3963{
d62a17ae 3964 int idx_peer = 2;
3965 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3966 bgp_node_afi(vty), bgp_node_safi(vty),
3967 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3968}
a538debe 3969
d62a17ae 3970ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3971 no_neighbor_nexthop_self_force_hidden_cmd,
3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3974 "Disable the next hop calculation for this neighbor\n"
3975 "Set the next hop to self for reflected routes\n")
596c17ba 3976
c7122e14
DS
3977/* neighbor as-override */
3978DEFUN (neighbor_as_override,
3979 neighbor_as_override_cmd,
9ccf14f7 3980 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
3983 "Override ASNs in outbound updates if aspath equals remote-as\n")
3984{
d62a17ae 3985 int idx_peer = 1;
3986 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3987 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3988}
3989
d62a17ae 3990ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3991 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3993 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3994
c7122e14
DS
3995DEFUN (no_neighbor_as_override,
3996 no_neighbor_as_override_cmd,
9ccf14f7 3997 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3998 NO_STR
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
4001 "Override ASNs in outbound updates if aspath equals remote-as\n")
4002{
d62a17ae 4003 int idx_peer = 2;
4004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4005 bgp_node_afi(vty), bgp_node_safi(vty),
4006 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4007}
4008
d62a17ae 4009ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4013
718e3744 4014/* neighbor remove-private-AS. */
4015DEFUN (neighbor_remove_private_as,
4016 neighbor_remove_private_as_cmd,
9ccf14f7 4017 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
5000f21c 4020 "Remove private ASNs in outbound updates\n")
718e3744 4021{
d62a17ae 4022 int idx_peer = 1;
4023 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4024 bgp_node_safi(vty),
4025 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4026}
4027
d62a17ae 4028ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4029 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n")
596c17ba 4032
5000f21c
DS
4033DEFUN (neighbor_remove_private_as_all,
4034 neighbor_remove_private_as_all_cmd,
9ccf14f7 4035 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
efd7904e 4039 "Apply to all AS numbers\n")
5000f21c 4040{
d62a17ae 4041 int idx_peer = 1;
4042 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4043 bgp_node_safi(vty),
4044 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4045}
4046
d62a17ae 4047ALIAS_HIDDEN(neighbor_remove_private_as_all,
4048 neighbor_remove_private_as_all_hidden_cmd,
4049 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4051 "Remove private ASNs in outbound updates\n"
4052 "Apply to all AS numbers")
596c17ba 4053
5000f21c
DS
4054DEFUN (neighbor_remove_private_as_replace_as,
4055 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4056 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4057 NEIGHBOR_STR
4058 NEIGHBOR_ADDR_STR2
4059 "Remove private ASNs in outbound updates\n"
4060 "Replace private ASNs with our ASN in outbound updates\n")
4061{
d62a17ae 4062 int idx_peer = 1;
4063 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4064 bgp_node_safi(vty),
4065 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4066}
4067
d62a17ae 4068ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4069 neighbor_remove_private_as_replace_as_hidden_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4072 "Remove private ASNs in outbound updates\n"
4073 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4074
5000f21c
DS
4075DEFUN (neighbor_remove_private_as_all_replace_as,
4076 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4077 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4078 NEIGHBOR_STR
4079 NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
16cedbb0 4081 "Apply to all AS numbers\n"
5000f21c
DS
4082 "Replace private ASNs with our ASN in outbound updates\n")
4083{
d62a17ae 4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4088}
4089
d62a17ae 4090ALIAS_HIDDEN(
4091 neighbor_remove_private_as_all_replace_as,
4092 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4093 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4095 "Remove private ASNs in outbound updates\n"
4096 "Apply to all AS numbers\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4098
718e3744 4099DEFUN (no_neighbor_remove_private_as,
4100 no_neighbor_remove_private_as_cmd,
9ccf14f7 4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4102 NO_STR
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
5000f21c 4105 "Remove private ASNs in outbound updates\n")
718e3744 4106{
d62a17ae 4107 int idx_peer = 2;
4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4111}
6b0655a2 4112
d62a17ae 4113ALIAS_HIDDEN(no_neighbor_remove_private_as,
4114 no_neighbor_remove_private_as_hidden_cmd,
4115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4117 "Remove private ASNs in outbound updates\n")
596c17ba 4118
88b8ed8d 4119DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4120 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4121 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4122 NO_STR
4123 NEIGHBOR_STR
4124 NEIGHBOR_ADDR_STR2
4125 "Remove private ASNs in outbound updates\n"
16cedbb0 4126 "Apply to all AS numbers\n")
88b8ed8d 4127{
d62a17ae 4128 int idx_peer = 2;
4129 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4130 bgp_node_afi(vty), bgp_node_safi(vty),
4131 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4132}
5000f21c 4133
d62a17ae 4134ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4135 no_neighbor_remove_private_as_all_hidden_cmd,
4136 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4137 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n")
596c17ba 4140
88b8ed8d 4141DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4142 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4143 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4144 NO_STR
4145 NEIGHBOR_STR
4146 NEIGHBOR_ADDR_STR2
4147 "Remove private ASNs in outbound updates\n"
4148 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4149{
d62a17ae 4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4154}
5000f21c 4155
d62a17ae 4156ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4157 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n"
4161 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4162
88b8ed8d 4163DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4164 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4166 NO_STR
4167 NEIGHBOR_STR
4168 NEIGHBOR_ADDR_STR2
4169 "Remove private ASNs in outbound updates\n"
16cedbb0 4170 "Apply to all AS numbers\n"
5000f21c 4171 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4172{
d62a17ae 4173 int idx_peer = 2;
4174 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4175 bgp_node_afi(vty), bgp_node_safi(vty),
4176 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4177}
5000f21c 4178
d62a17ae 4179ALIAS_HIDDEN(
4180 no_neighbor_remove_private_as_all_replace_as,
4181 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Apply to all AS numbers\n"
4186 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4187
5000f21c 4188
718e3744 4189/* neighbor send-community. */
4190DEFUN (neighbor_send_community,
4191 neighbor_send_community_cmd,
9ccf14f7 4192 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4193 NEIGHBOR_STR
4194 NEIGHBOR_ADDR_STR2
4195 "Send Community attribute to this neighbor\n")
4196{
d62a17ae 4197 int idx_peer = 1;
27c05d4d 4198
d62a17ae 4199 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4200 bgp_node_safi(vty),
4201 PEER_FLAG_SEND_COMMUNITY);
718e3744 4202}
4203
d62a17ae 4204ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4205 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4207 "Send Community attribute to this neighbor\n")
596c17ba 4208
718e3744 4209DEFUN (no_neighbor_send_community,
4210 no_neighbor_send_community_cmd,
9ccf14f7 4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4212 NO_STR
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Send Community attribute to this neighbor\n")
4216{
d62a17ae 4217 int idx_peer = 2;
27c05d4d 4218
d62a17ae 4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_SEND_COMMUNITY);
718e3744 4222}
6b0655a2 4223
d62a17ae 4224ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Send Community attribute to this neighbor\n")
596c17ba 4228
718e3744 4229/* neighbor send-community extended. */
4230DEFUN (neighbor_send_community_type,
4231 neighbor_send_community_type_cmd,
57d187bc 4232 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4233 NEIGHBOR_STR
4234 NEIGHBOR_ADDR_STR2
4235 "Send Community attribute to this neighbor\n"
4236 "Send Standard and Extended Community attributes\n"
57d187bc 4237 "Send Standard, Large and Extended Community attributes\n"
718e3744 4238 "Send Extended Community attributes\n"
57d187bc
JS
4239 "Send Standard Community attributes\n"
4240 "Send Large Community attributes\n")
718e3744 4241{
27c05d4d 4242 int idx_peer = 1;
d7c0a89a 4243 uint32_t flag = 0;
27c05d4d 4244 const char *type = argv[argc - 1]->text;
d62a17ae 4245
27c05d4d 4246 if (strmatch(type, "standard")) {
d62a17ae 4247 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4248 } else if (strmatch(type, "extended")) {
d62a17ae 4249 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4250 } else if (strmatch(type, "large")) {
d62a17ae 4251 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4252 } else if (strmatch(type, "both")) {
d62a17ae 4253 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4254 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4255 } else { /* if (strmatch(type, "all")) */
d62a17ae 4256 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4257 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4258 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4259 }
4260
27c05d4d 4261 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4262 bgp_node_safi(vty), flag);
4263}
4264
4265ALIAS_HIDDEN(
4266 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4267 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4268 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4269 "Send Community attribute to this neighbor\n"
4270 "Send Standard and Extended Community attributes\n"
4271 "Send Standard, Large and Extended Community attributes\n"
4272 "Send Extended Community attributes\n"
4273 "Send Standard Community attributes\n"
4274 "Send Large Community attributes\n")
596c17ba 4275
718e3744 4276DEFUN (no_neighbor_send_community_type,
4277 no_neighbor_send_community_type_cmd,
57d187bc 4278 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4279 NO_STR
4280 NEIGHBOR_STR
4281 NEIGHBOR_ADDR_STR2
4282 "Send Community attribute to this neighbor\n"
4283 "Send Standard and Extended Community attributes\n"
57d187bc 4284 "Send Standard, Large and Extended Community attributes\n"
718e3744 4285 "Send Extended Community attributes\n"
57d187bc
JS
4286 "Send Standard Community attributes\n"
4287 "Send Large Community attributes\n")
718e3744 4288{
d62a17ae 4289 int idx_peer = 2;
27c05d4d 4290 uint32_t flag = 0;
d62a17ae 4291 const char *type = argv[argc - 1]->text;
4292
27c05d4d
PM
4293 if (strmatch(type, "standard")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4295 } else if (strmatch(type, "extended")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4297 } else if (strmatch(type, "large")) {
4298 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4299 } else if (strmatch(type, "both")) {
4300 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4302 } else { /* if (strmatch(type, "all")) */
4303 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4304 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4305 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4306 }
4307
4308 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4309 bgp_node_afi(vty), bgp_node_safi(vty),
4310 flag);
d62a17ae 4311}
4312
4313ALIAS_HIDDEN(
4314 no_neighbor_send_community_type,
4315 no_neighbor_send_community_type_hidden_cmd,
4316 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4317 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4318 "Send Community attribute to this neighbor\n"
4319 "Send Standard and Extended Community attributes\n"
4320 "Send Standard, Large and Extended Community attributes\n"
4321 "Send Extended Community attributes\n"
4322 "Send Standard Community attributes\n"
4323 "Send Large Community attributes\n")
596c17ba 4324
718e3744 4325/* neighbor soft-reconfig. */
4326DEFUN (neighbor_soft_reconfiguration,
4327 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4328 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4329 NEIGHBOR_STR
4330 NEIGHBOR_ADDR_STR2
4331 "Per neighbor soft reconfiguration\n"
4332 "Allow inbound soft reconfiguration for this neighbor\n")
4333{
d62a17ae 4334 int idx_peer = 1;
4335 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4336 bgp_node_safi(vty),
4337 PEER_FLAG_SOFT_RECONFIG);
718e3744 4338}
4339
d62a17ae 4340ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4341 neighbor_soft_reconfiguration_hidden_cmd,
4342 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4344 "Per neighbor soft reconfiguration\n"
4345 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4346
718e3744 4347DEFUN (no_neighbor_soft_reconfiguration,
4348 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4349 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4350 NO_STR
4351 NEIGHBOR_STR
4352 NEIGHBOR_ADDR_STR2
4353 "Per neighbor soft reconfiguration\n"
4354 "Allow inbound soft reconfiguration for this neighbor\n")
4355{
d62a17ae 4356 int idx_peer = 2;
4357 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4358 bgp_node_afi(vty), bgp_node_safi(vty),
4359 PEER_FLAG_SOFT_RECONFIG);
718e3744 4360}
6b0655a2 4361
d62a17ae 4362ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4363 no_neighbor_soft_reconfiguration_hidden_cmd,
4364 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4366 "Per neighbor soft reconfiguration\n"
4367 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4368
718e3744 4369DEFUN (neighbor_route_reflector_client,
4370 neighbor_route_reflector_client_cmd,
9ccf14f7 4371 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Configure a neighbor as Route Reflector client\n")
4375{
d62a17ae 4376 int idx_peer = 1;
4377 struct peer *peer;
718e3744 4378
4379
d62a17ae 4380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4381 if (!peer)
4382 return CMD_WARNING_CONFIG_FAILED;
718e3744 4383
d62a17ae 4384 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4385 bgp_node_safi(vty),
4386 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4387}
4388
d62a17ae 4389ALIAS_HIDDEN(neighbor_route_reflector_client,
4390 neighbor_route_reflector_client_hidden_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4393 "Configure a neighbor as Route Reflector client\n")
596c17ba 4394
718e3744 4395DEFUN (no_neighbor_route_reflector_client,
4396 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4397 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4398 NO_STR
4399 NEIGHBOR_STR
4400 NEIGHBOR_ADDR_STR2
4401 "Configure a neighbor as Route Reflector client\n")
4402{
d62a17ae 4403 int idx_peer = 2;
4404 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4405 bgp_node_afi(vty), bgp_node_safi(vty),
4406 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4407}
6b0655a2 4408
d62a17ae 4409ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4410 no_neighbor_route_reflector_client_hidden_cmd,
4411 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4413 "Configure a neighbor as Route Reflector client\n")
596c17ba 4414
718e3744 4415/* neighbor route-server-client. */
4416DEFUN (neighbor_route_server_client,
4417 neighbor_route_server_client_cmd,
9ccf14f7 4418 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Configure a neighbor as Route Server client\n")
4422{
d62a17ae 4423 int idx_peer = 1;
4424 struct peer *peer;
2a3d5731 4425
d62a17ae 4426 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4427 if (!peer)
4428 return CMD_WARNING_CONFIG_FAILED;
4429 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4430 bgp_node_safi(vty),
4431 PEER_FLAG_RSERVER_CLIENT);
718e3744 4432}
4433
d62a17ae 4434ALIAS_HIDDEN(neighbor_route_server_client,
4435 neighbor_route_server_client_hidden_cmd,
4436 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4438 "Configure a neighbor as Route Server client\n")
596c17ba 4439
718e3744 4440DEFUN (no_neighbor_route_server_client,
4441 no_neighbor_route_server_client_cmd,
9ccf14f7 4442 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4443 NO_STR
4444 NEIGHBOR_STR
4445 NEIGHBOR_ADDR_STR2
4446 "Configure a neighbor as Route Server client\n")
fee0f4c6 4447{
d62a17ae 4448 int idx_peer = 2;
4449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4450 bgp_node_afi(vty), bgp_node_safi(vty),
4451 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4452}
6b0655a2 4453
d62a17ae 4454ALIAS_HIDDEN(no_neighbor_route_server_client,
4455 no_neighbor_route_server_client_hidden_cmd,
4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4458 "Configure a neighbor as Route Server client\n")
596c17ba 4459
fee0f4c6 4460DEFUN (neighbor_nexthop_local_unchanged,
4461 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4462 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4463 NEIGHBOR_STR
4464 NEIGHBOR_ADDR_STR2
4465 "Configure treatment of outgoing link-local nexthop attribute\n"
4466 "Leave link-local nexthop unchanged for this peer\n")
4467{
d62a17ae 4468 int idx_peer = 1;
4469 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4470 bgp_node_safi(vty),
4471 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4472}
6b0655a2 4473
fee0f4c6 4474DEFUN (no_neighbor_nexthop_local_unchanged,
4475 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4476 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4477 NO_STR
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "Configure treatment of outgoing link-local-nexthop attribute\n"
4481 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4482{
d62a17ae 4483 int idx_peer = 2;
4484 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4485 bgp_node_afi(vty), bgp_node_safi(vty),
4486 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4487}
6b0655a2 4488
718e3744 4489DEFUN (neighbor_attr_unchanged,
4490 neighbor_attr_unchanged_cmd,
a8206004 4491 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "BGP attribute is propagated unchanged to this neighbor\n"
4495 "As-path attribute\n"
4496 "Nexthop attribute\n"
a8206004 4497 "Med attribute\n")
718e3744 4498{
d62a17ae 4499 int idx = 0;
8eeb0335
DW
4500 char *peer_str = argv[1]->arg;
4501 struct peer *peer;
d7c0a89a 4502 uint16_t flags = 0;
8eeb0335
DW
4503 afi_t afi = bgp_node_afi(vty);
4504 safi_t safi = bgp_node_safi(vty);
4505
4506 peer = peer_and_group_lookup_vty(vty, peer_str);
4507 if (!peer)
4508 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4509
4510 if (argv_find(argv, argc, "as-path", &idx))
4511 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4512 idx = 0;
4513 if (argv_find(argv, argc, "next-hop", &idx))
4514 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4515 idx = 0;
4516 if (argv_find(argv, argc, "med", &idx))
4517 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4518
8eeb0335
DW
4519 /* no flags means all of them! */
4520 if (!flags) {
d62a17ae 4521 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4522 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4523 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4524 } else {
a4d82a8a
PZ
4525 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4526 && peer_af_flag_check(peer, afi, safi,
4527 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4528 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4529 PEER_FLAG_AS_PATH_UNCHANGED);
4530 }
4531
a4d82a8a
PZ
4532 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4533 && peer_af_flag_check(peer, afi, safi,
4534 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4535 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4536 PEER_FLAG_NEXTHOP_UNCHANGED);
4537 }
4538
a4d82a8a
PZ
4539 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4540 && peer_af_flag_check(peer, afi, safi,
4541 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4542 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4543 PEER_FLAG_MED_UNCHANGED);
4544 }
d62a17ae 4545 }
4546
8eeb0335 4547 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4548}
4549
4550ALIAS_HIDDEN(
4551 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4552 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4554 "BGP attribute is propagated unchanged to this neighbor\n"
4555 "As-path attribute\n"
4556 "Nexthop attribute\n"
4557 "Med attribute\n")
596c17ba 4558
718e3744 4559DEFUN (no_neighbor_attr_unchanged,
4560 no_neighbor_attr_unchanged_cmd,
a8206004 4561 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4562 NO_STR
718e3744 4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
31500417
DW
4565 "BGP attribute is propagated unchanged to this neighbor\n"
4566 "As-path attribute\n"
40e718b5 4567 "Nexthop attribute\n"
a8206004 4568 "Med attribute\n")
718e3744 4569{
d62a17ae 4570 int idx = 0;
4571 char *peer = argv[2]->arg;
d7c0a89a 4572 uint16_t flags = 0;
d62a17ae 4573
4574 if (argv_find(argv, argc, "as-path", &idx))
4575 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4576 idx = 0;
4577 if (argv_find(argv, argc, "next-hop", &idx))
4578 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4579 idx = 0;
4580 if (argv_find(argv, argc, "med", &idx))
4581 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4582
4583 if (!flags) // no flags means all of them!
4584 {
4585 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4586 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4587 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4588 }
4589
4590 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4591 bgp_node_safi(vty), flags);
4592}
4593
4594ALIAS_HIDDEN(
4595 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4596 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4597 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4598 "BGP attribute is propagated unchanged to this neighbor\n"
4599 "As-path attribute\n"
4600 "Nexthop attribute\n"
4601 "Med attribute\n")
718e3744 4602
718e3744 4603/* EBGP multihop configuration. */
d62a17ae 4604static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4605 const char *ttl_str)
718e3744 4606{
d62a17ae 4607 struct peer *peer;
4608 unsigned int ttl;
718e3744 4609
d62a17ae 4610 peer = peer_and_group_lookup_vty(vty, ip_str);
4611 if (!peer)
4612 return CMD_WARNING_CONFIG_FAILED;
718e3744 4613
d62a17ae 4614 if (peer->conf_if)
4615 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4616
d62a17ae 4617 if (!ttl_str)
4618 ttl = MAXTTL;
4619 else
4620 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4621
d62a17ae 4622 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4623}
4624
d62a17ae 4625static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4626{
d62a17ae 4627 struct peer *peer;
718e3744 4628
d62a17ae 4629 peer = peer_and_group_lookup_vty(vty, ip_str);
4630 if (!peer)
4631 return CMD_WARNING_CONFIG_FAILED;
718e3744 4632
d62a17ae 4633 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4634}
4635
4636/* neighbor ebgp-multihop. */
4637DEFUN (neighbor_ebgp_multihop,
4638 neighbor_ebgp_multihop_cmd,
9ccf14f7 4639 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4640 NEIGHBOR_STR
4641 NEIGHBOR_ADDR_STR2
4642 "Allow EBGP neighbors not on directly connected networks\n")
4643{
d62a17ae 4644 int idx_peer = 1;
4645 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4646}
4647
4648DEFUN (neighbor_ebgp_multihop_ttl,
4649 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4650 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
4653 "Allow EBGP neighbors not on directly connected networks\n"
4654 "maximum hop count\n")
4655{
d62a17ae 4656 int idx_peer = 1;
4657 int idx_number = 3;
4658 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4659 argv[idx_number]->arg);
718e3744 4660}
4661
4662DEFUN (no_neighbor_ebgp_multihop,
4663 no_neighbor_ebgp_multihop_cmd,
a636c635 4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4665 NO_STR
4666 NEIGHBOR_STR
4667 NEIGHBOR_ADDR_STR2
a636c635
DW
4668 "Allow EBGP neighbors not on directly connected networks\n"
4669 "maximum hop count\n")
718e3744 4670{
d62a17ae 4671 int idx_peer = 2;
4672 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4673}
4674
6b0655a2 4675
6ffd2079 4676/* disable-connected-check */
4677DEFUN (neighbor_disable_connected_check,
4678 neighbor_disable_connected_check_cmd,
7ebe625c 4679 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4680 NEIGHBOR_STR
7ebe625c 4681 NEIGHBOR_ADDR_STR2
a636c635
DW
4682 "one-hop away EBGP peer using loopback address\n"
4683 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4684{
d62a17ae 4685 int idx_peer = 1;
4686 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4687 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4688}
4689
4690DEFUN (no_neighbor_disable_connected_check,
4691 no_neighbor_disable_connected_check_cmd,
7ebe625c 4692 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4693 NO_STR
4694 NEIGHBOR_STR
7ebe625c 4695 NEIGHBOR_ADDR_STR2
a636c635
DW
4696 "one-hop away EBGP peer using loopback address\n"
4697 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4698{
d62a17ae 4699 int idx_peer = 2;
4700 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4701 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4702}
4703
47cbc09b
PM
4704
4705/* enforce-first-as */
4706DEFUN (neighbor_enforce_first_as,
4707 neighbor_enforce_first_as_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Enforce the first AS for EBGP routes\n")
4712{
4713 int idx_peer = 1;
4714
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_ENFORCE_FIRST_AS);
4717}
4718
4719DEFUN (no_neighbor_enforce_first_as,
4720 no_neighbor_enforce_first_as_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Enforce the first AS for EBGP routes\n")
4726{
4727 int idx_peer = 2;
4728
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_ENFORCE_FIRST_AS);
4731}
4732
4733
718e3744 4734DEFUN (neighbor_description,
4735 neighbor_description_cmd,
e961923c 4736 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "Neighbor specific description\n"
4740 "Up to 80 characters describing this neighbor\n")
4741{
d62a17ae 4742 int idx_peer = 1;
4743 int idx_line = 3;
4744 struct peer *peer;
4745 char *str;
718e3744 4746
d62a17ae 4747 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4748 if (!peer)
4749 return CMD_WARNING_CONFIG_FAILED;
718e3744 4750
d62a17ae 4751 str = argv_concat(argv, argc, idx_line);
718e3744 4752
d62a17ae 4753 peer_description_set(peer, str);
718e3744 4754
d62a17ae 4755 XFREE(MTYPE_TMP, str);
718e3744 4756
d62a17ae 4757 return CMD_SUCCESS;
718e3744 4758}
4759
4760DEFUN (no_neighbor_description,
4761 no_neighbor_description_cmd,
a14810f4 4762 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4763 NO_STR
4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
a14810f4 4766 "Neighbor specific description\n")
718e3744 4767{
d62a17ae 4768 int idx_peer = 2;
4769 struct peer *peer;
718e3744 4770
d62a17ae 4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
718e3744 4774
d62a17ae 4775 peer_description_unset(peer);
718e3744 4776
d62a17ae 4777 return CMD_SUCCESS;
718e3744 4778}
4779
a14810f4
PM
4780ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4781 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4783 "Neighbor specific description\n"
4784 "Up to 80 characters describing this neighbor\n")
6b0655a2 4785
718e3744 4786/* Neighbor update-source. */
d62a17ae 4787static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4788 const char *source_str)
4789{
4790 struct peer *peer;
4791 struct prefix p;
a14810f4 4792 union sockunion su;
d62a17ae 4793
4794 peer = peer_and_group_lookup_vty(vty, peer_str);
4795 if (!peer)
4796 return CMD_WARNING_CONFIG_FAILED;
4797
4798 if (peer->conf_if)
4799 return CMD_WARNING;
4800
4801 if (source_str) {
a14810f4 4802 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4803 peer_update_source_addr_set(peer, &su);
4804 else {
4805 if (str2prefix(source_str, &p)) {
4806 vty_out(vty,
4807 "%% Invalid update-source, remove prefix length \n");
4808 return CMD_WARNING_CONFIG_FAILED;
4809 } else
4810 peer_update_source_if_set(peer, source_str);
4811 }
4812 } else
4813 peer_update_source_unset(peer);
4814
4815 return CMD_SUCCESS;
4816}
4817
4818#define BGP_UPDATE_SOURCE_HELP_STR \
4819 "IPv4 address\n" \
4820 "IPv6 address\n" \
4821 "Interface name (requires zebra to be running)\n"
369688c0 4822
718e3744 4823DEFUN (neighbor_update_source,
4824 neighbor_update_source_cmd,
9ccf14f7 4825 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4826 NEIGHBOR_STR
4827 NEIGHBOR_ADDR_STR2
4828 "Source of routing updates\n"
369688c0 4829 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4830{
d62a17ae 4831 int idx_peer = 1;
4832 int idx_peer_2 = 3;
4833 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4834 argv[idx_peer_2]->arg);
718e3744 4835}
4836
4837DEFUN (no_neighbor_update_source,
4838 no_neighbor_update_source_cmd,
c7178fe7 4839 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4840 NO_STR
4841 NEIGHBOR_STR
4842 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4843 "Source of routing updates\n"
4844 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4845{
d62a17ae 4846 int idx_peer = 2;
4847 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4848}
6b0655a2 4849
d62a17ae 4850static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4851 afi_t afi, safi_t safi,
4852 const char *rmap, int set)
718e3744 4853{
d62a17ae 4854 int ret;
4855 struct peer *peer;
1de27621 4856 struct route_map *route_map;
718e3744 4857
d62a17ae 4858 peer = peer_and_group_lookup_vty(vty, peer_str);
4859 if (!peer)
4860 return CMD_WARNING_CONFIG_FAILED;
718e3744 4861
1de27621
DA
4862 if (set) {
4863 route_map = route_map_lookup_warn_noexist(vty, rmap);
4864 ret = peer_default_originate_set(peer, afi, safi,
4865 rmap, route_map);
4866 } else
d62a17ae 4867 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4868
d62a17ae 4869 return bgp_vty_return(vty, ret);
718e3744 4870}
4871
4872/* neighbor default-originate. */
4873DEFUN (neighbor_default_originate,
4874 neighbor_default_originate_cmd,
9ccf14f7 4875 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR2
4878 "Originate default route to this neighbor\n")
4879{
d62a17ae 4880 int idx_peer = 1;
4881 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4882 bgp_node_afi(vty),
4883 bgp_node_safi(vty), NULL, 1);
718e3744 4884}
4885
d62a17ae 4886ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4887 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4889 "Originate default route to this neighbor\n")
596c17ba 4890
718e3744 4891DEFUN (neighbor_default_originate_rmap,
4892 neighbor_default_originate_rmap_cmd,
9ccf14f7 4893 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Originate default route to this neighbor\n"
4897 "Route-map to specify criteria to originate default\n"
4898 "route-map name\n")
4899{
d62a17ae 4900 int idx_peer = 1;
4901 int idx_word = 4;
4902 return peer_default_originate_set_vty(
4903 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4904 argv[idx_word]->arg, 1);
718e3744 4905}
4906
d62a17ae 4907ALIAS_HIDDEN(
4908 neighbor_default_originate_rmap,
4909 neighbor_default_originate_rmap_hidden_cmd,
4910 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4912 "Originate default route to this neighbor\n"
4913 "Route-map to specify criteria to originate default\n"
4914 "route-map name\n")
596c17ba 4915
718e3744 4916DEFUN (no_neighbor_default_originate,
4917 no_neighbor_default_originate_cmd,
a636c635 4918 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4919 NO_STR
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
a636c635
DW
4922 "Originate default route to this neighbor\n"
4923 "Route-map to specify criteria to originate default\n"
4924 "route-map name\n")
718e3744 4925{
d62a17ae 4926 int idx_peer = 2;
4927 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4928 bgp_node_afi(vty),
4929 bgp_node_safi(vty), NULL, 0);
718e3744 4930}
4931
d62a17ae 4932ALIAS_HIDDEN(
4933 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Originate default route to this neighbor\n"
4937 "Route-map to specify criteria to originate default\n"
4938 "route-map name\n")
596c17ba 4939
6b0655a2 4940
718e3744 4941/* Set neighbor's BGP port. */
d62a17ae 4942static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4943 const char *port_str)
4944{
4945 struct peer *peer;
d7c0a89a 4946 uint16_t port;
d62a17ae 4947 struct servent *sp;
4948
4949 peer = peer_lookup_vty(vty, ip_str);
4950 if (!peer)
4951 return CMD_WARNING_CONFIG_FAILED;
4952
4953 if (!port_str) {
4954 sp = getservbyname("bgp", "tcp");
4955 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4956 } else {
4957 port = strtoul(port_str, NULL, 10);
4958 }
718e3744 4959
d62a17ae 4960 peer_port_set(peer, port);
718e3744 4961
d62a17ae 4962 return CMD_SUCCESS;
718e3744 4963}
4964
f418446b 4965/* Set specified peer's BGP port. */
718e3744 4966DEFUN (neighbor_port,
4967 neighbor_port_cmd,
9ccf14f7 4968 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR
4971 "Neighbor's BGP port\n"
4972 "TCP port number\n")
4973{
d62a17ae 4974 int idx_ip = 1;
4975 int idx_number = 3;
4976 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4977 argv[idx_number]->arg);
718e3744 4978}
4979
4980DEFUN (no_neighbor_port,
4981 no_neighbor_port_cmd,
9ccf14f7 4982 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4983 NO_STR
4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR
8334fd5a
DW
4986 "Neighbor's BGP port\n"
4987 "TCP port number\n")
718e3744 4988{
d62a17ae 4989 int idx_ip = 2;
4990 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4991}
4992
6b0655a2 4993
718e3744 4994/* neighbor weight. */
d62a17ae 4995static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4996 safi_t safi, const char *weight_str)
718e3744 4997{
d62a17ae 4998 int ret;
4999 struct peer *peer;
5000 unsigned long weight;
718e3744 5001
d62a17ae 5002 peer = peer_and_group_lookup_vty(vty, ip_str);
5003 if (!peer)
5004 return CMD_WARNING_CONFIG_FAILED;
718e3744 5005
d62a17ae 5006 weight = strtoul(weight_str, NULL, 10);
718e3744 5007
d62a17ae 5008 ret = peer_weight_set(peer, afi, safi, weight);
5009 return bgp_vty_return(vty, ret);
718e3744 5010}
5011
d62a17ae 5012static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5013 safi_t safi)
718e3744 5014{
d62a17ae 5015 int ret;
5016 struct peer *peer;
718e3744 5017
d62a17ae 5018 peer = peer_and_group_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
718e3744 5021
d62a17ae 5022 ret = peer_weight_unset(peer, afi, safi);
5023 return bgp_vty_return(vty, ret);
718e3744 5024}
5025
5026DEFUN (neighbor_weight,
5027 neighbor_weight_cmd,
9ccf14f7 5028 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Set default weight for routes from this neighbor\n"
5032 "default weight\n")
5033{
d62a17ae 5034 int idx_peer = 1;
5035 int idx_number = 3;
5036 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5037 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5038}
5039
d62a17ae 5040ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5041 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5043 "Set default weight for routes from this neighbor\n"
5044 "default weight\n")
596c17ba 5045
718e3744 5046DEFUN (no_neighbor_weight,
5047 no_neighbor_weight_cmd,
9ccf14f7 5048 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5049 NO_STR
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5052 "Set default weight for routes from this neighbor\n"
5053 "default weight\n")
718e3744 5054{
d62a17ae 5055 int idx_peer = 2;
5056 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5057 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5058}
5059
d62a17ae 5060ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5061 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5063 "Set default weight for routes from this neighbor\n"
5064 "default weight\n")
596c17ba 5065
6b0655a2 5066
718e3744 5067/* Override capability negotiation. */
5068DEFUN (neighbor_override_capability,
5069 neighbor_override_capability_cmd,
9ccf14f7 5070 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Override capability negotiation result\n")
5074{
d62a17ae 5075 int idx_peer = 1;
5076 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5077 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5078}
5079
5080DEFUN (no_neighbor_override_capability,
5081 no_neighbor_override_capability_cmd,
9ccf14f7 5082 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5083 NO_STR
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Override capability negotiation result\n")
5087{
d62a17ae 5088 int idx_peer = 2;
5089 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5090 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5091}
6b0655a2 5092
718e3744 5093DEFUN (neighbor_strict_capability,
5094 neighbor_strict_capability_cmd,
9fb964de 5095 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5096 NEIGHBOR_STR
9fb964de 5097 NEIGHBOR_ADDR_STR2
718e3744 5098 "Strict capability negotiation match\n")
5099{
9fb964de
PM
5100 int idx_peer = 1;
5101
5102 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5103 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5104}
5105
5106DEFUN (no_neighbor_strict_capability,
5107 no_neighbor_strict_capability_cmd,
9fb964de 5108 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5109 NO_STR
5110 NEIGHBOR_STR
9fb964de 5111 NEIGHBOR_ADDR_STR2
718e3744 5112 "Strict capability negotiation match\n")
5113{
9fb964de
PM
5114 int idx_peer = 2;
5115
5116 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5117 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5118}
6b0655a2 5119
d62a17ae 5120static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5121 const char *keep_str, const char *hold_str)
718e3744 5122{
d62a17ae 5123 int ret;
5124 struct peer *peer;
d7c0a89a
QY
5125 uint32_t keepalive;
5126 uint32_t holdtime;
718e3744 5127
d62a17ae 5128 peer = peer_and_group_lookup_vty(vty, ip_str);
5129 if (!peer)
5130 return CMD_WARNING_CONFIG_FAILED;
718e3744 5131
d62a17ae 5132 keepalive = strtoul(keep_str, NULL, 10);
5133 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5134
d62a17ae 5135 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5136
d62a17ae 5137 return bgp_vty_return(vty, ret);
718e3744 5138}
6b0655a2 5139
d62a17ae 5140static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5141{
d62a17ae 5142 int ret;
5143 struct peer *peer;
718e3744 5144
d62a17ae 5145 peer = peer_and_group_lookup_vty(vty, ip_str);
5146 if (!peer)
5147 return CMD_WARNING_CONFIG_FAILED;
718e3744 5148
d62a17ae 5149 ret = peer_timers_unset(peer);
718e3744 5150
d62a17ae 5151 return bgp_vty_return(vty, ret);
718e3744 5152}
5153
5154DEFUN (neighbor_timers,
5155 neighbor_timers_cmd,
9ccf14f7 5156 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "BGP per neighbor timers\n"
5160 "Keepalive interval\n"
5161 "Holdtime\n")
5162{
d62a17ae 5163 int idx_peer = 1;
5164 int idx_number = 3;
5165 int idx_number_2 = 4;
5166 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg,
5168 argv[idx_number_2]->arg);
718e3744 5169}
5170
5171DEFUN (no_neighbor_timers,
5172 no_neighbor_timers_cmd,
9ccf14f7 5173 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5174 NO_STR
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5177 "BGP per neighbor timers\n"
5178 "Keepalive interval\n"
5179 "Holdtime\n")
718e3744 5180{
d62a17ae 5181 int idx_peer = 2;
5182 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5183}
6b0655a2 5184
813d4307 5185
d62a17ae 5186static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5187 const char *time_str)
718e3744 5188{
d62a17ae 5189 int ret;
5190 struct peer *peer;
d7c0a89a 5191 uint32_t connect;
718e3744 5192
d62a17ae 5193 peer = peer_and_group_lookup_vty(vty, ip_str);
5194 if (!peer)
5195 return CMD_WARNING_CONFIG_FAILED;
718e3744 5196
d62a17ae 5197 connect = strtoul(time_str, NULL, 10);
718e3744 5198
d62a17ae 5199 ret = peer_timers_connect_set(peer, connect);
718e3744 5200
d62a17ae 5201 return bgp_vty_return(vty, ret);
718e3744 5202}
5203
d62a17ae 5204static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5205{
d62a17ae 5206 int ret;
5207 struct peer *peer;
718e3744 5208
d62a17ae 5209 peer = peer_and_group_lookup_vty(vty, ip_str);
5210 if (!peer)
5211 return CMD_WARNING_CONFIG_FAILED;
718e3744 5212
d62a17ae 5213 ret = peer_timers_connect_unset(peer);
718e3744 5214
d62a17ae 5215 return bgp_vty_return(vty, ret);
718e3744 5216}
5217
5218DEFUN (neighbor_timers_connect,
5219 neighbor_timers_connect_cmd,
9ccf14f7 5220 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5221 NEIGHBOR_STR
966f821c 5222 NEIGHBOR_ADDR_STR2
718e3744 5223 "BGP per neighbor timers\n"
5224 "BGP connect timer\n"
5225 "Connect timer\n")
5226{
d62a17ae 5227 int idx_peer = 1;
5228 int idx_number = 4;
5229 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5230 argv[idx_number]->arg);
718e3744 5231}
5232
5233DEFUN (no_neighbor_timers_connect,
5234 no_neighbor_timers_connect_cmd,
9ccf14f7 5235 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5236 NO_STR
5237 NEIGHBOR_STR
966f821c 5238 NEIGHBOR_ADDR_STR2
718e3744 5239 "BGP per neighbor timers\n"
8334fd5a
DW
5240 "BGP connect timer\n"
5241 "Connect timer\n")
718e3744 5242{
d62a17ae 5243 int idx_peer = 2;
5244 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5245}
5246
6b0655a2 5247
d62a17ae 5248static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5249 const char *time_str, int set)
718e3744 5250{
d62a17ae 5251 int ret;
5252 struct peer *peer;
d7c0a89a 5253 uint32_t routeadv = 0;
718e3744 5254
d62a17ae 5255 peer = peer_and_group_lookup_vty(vty, ip_str);
5256 if (!peer)
5257 return CMD_WARNING_CONFIG_FAILED;
718e3744 5258
d62a17ae 5259 if (time_str)
5260 routeadv = strtoul(time_str, NULL, 10);
718e3744 5261
d62a17ae 5262 if (set)
5263 ret = peer_advertise_interval_set(peer, routeadv);
5264 else
5265 ret = peer_advertise_interval_unset(peer);
718e3744 5266
d62a17ae 5267 return bgp_vty_return(vty, ret);
718e3744 5268}
5269
5270DEFUN (neighbor_advertise_interval,
5271 neighbor_advertise_interval_cmd,
9ccf14f7 5272 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5273 NEIGHBOR_STR
966f821c 5274 NEIGHBOR_ADDR_STR2
718e3744 5275 "Minimum interval between sending BGP routing updates\n"
5276 "time in seconds\n")
5277{
d62a17ae 5278 int idx_peer = 1;
5279 int idx_number = 3;
5280 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5281 argv[idx_number]->arg, 1);
718e3744 5282}
5283
5284DEFUN (no_neighbor_advertise_interval,
5285 no_neighbor_advertise_interval_cmd,
9ccf14f7 5286 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5287 NO_STR
5288 NEIGHBOR_STR
966f821c 5289 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5290 "Minimum interval between sending BGP routing updates\n"
5291 "time in seconds\n")
718e3744 5292{
d62a17ae 5293 int idx_peer = 2;
5294 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5295}
5296
6b0655a2 5297
518f0eb1
DS
5298/* Time to wait before processing route-map updates */
5299DEFUN (bgp_set_route_map_delay_timer,
5300 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5301 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5302 SET_STR
5303 "BGP route-map delay timer\n"
5304 "Time in secs to wait before processing route-map changes\n"
f414725f 5305 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5306{
d62a17ae 5307 int idx_number = 3;
d7c0a89a 5308 uint32_t rmap_delay_timer;
d62a17ae 5309
5310 if (argv[idx_number]->arg) {
5311 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5312 bm->rmap_update_timer = rmap_delay_timer;
5313
5314 /* if the dynamic update handling is being disabled, and a timer
5315 * is
5316 * running, stop the timer and act as if the timer has already
5317 * fired.
5318 */
5319 if (!rmap_delay_timer && bm->t_rmap_update) {
5320 BGP_TIMER_OFF(bm->t_rmap_update);
5321 thread_execute(bm->master, bgp_route_map_update_timer,
5322 NULL, 0);
5323 }
5324 return CMD_SUCCESS;
5325 } else {
5326 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5327 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5328 }
518f0eb1
DS
5329}
5330
5331DEFUN (no_bgp_set_route_map_delay_timer,
5332 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5333 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5334 NO_STR
3a2d747c 5335 BGP_STR
518f0eb1 5336 "Default BGP route-map delay timer\n"
8334fd5a
DW
5337 "Reset to default time to wait for processing route-map changes\n"
5338 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5339{
518f0eb1 5340
d62a17ae 5341 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5342
d62a17ae 5343 return CMD_SUCCESS;
518f0eb1
DS
5344}
5345
f414725f 5346
718e3744 5347/* neighbor interface */
d62a17ae 5348static int peer_interface_vty(struct vty *vty, const char *ip_str,
5349 const char *str)
718e3744 5350{
d62a17ae 5351 struct peer *peer;
718e3744 5352
d62a17ae 5353 peer = peer_lookup_vty(vty, ip_str);
5354 if (!peer || peer->conf_if) {
5355 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
718e3744 5358
d62a17ae 5359 if (str)
5360 peer_interface_set(peer, str);
5361 else
5362 peer_interface_unset(peer);
718e3744 5363
d62a17ae 5364 return CMD_SUCCESS;
718e3744 5365}
5366
5367DEFUN (neighbor_interface,
5368 neighbor_interface_cmd,
9ccf14f7 5369 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5370 NEIGHBOR_STR
5371 NEIGHBOR_ADDR_STR
5372 "Interface\n"
5373 "Interface name\n")
5374{
d62a17ae 5375 int idx_ip = 1;
5376 int idx_word = 3;
5377 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5378}
5379
5380DEFUN (no_neighbor_interface,
5381 no_neighbor_interface_cmd,
9ccf14f7 5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5383 NO_STR
5384 NEIGHBOR_STR
16cedbb0 5385 NEIGHBOR_ADDR_STR2
718e3744 5386 "Interface\n"
5387 "Interface name\n")
5388{
d62a17ae 5389 int idx_peer = 2;
5390 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5391}
6b0655a2 5392
718e3744 5393DEFUN (neighbor_distribute_list,
5394 neighbor_distribute_list_cmd,
9ccf14f7 5395 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR2
5398 "Filter updates to/from this neighbor\n"
5399 "IP access-list number\n"
5400 "IP access-list number (expanded range)\n"
5401 "IP Access-list name\n"
5402 "Filter incoming updates\n"
5403 "Filter outgoing updates\n")
5404{
d62a17ae 5405 int idx_peer = 1;
5406 int idx_acl = 3;
5407 int direct, ret;
5408 struct peer *peer;
a8206004 5409
d62a17ae 5410 const char *pstr = argv[idx_peer]->arg;
5411 const char *acl = argv[idx_acl]->arg;
5412 const char *inout = argv[argc - 1]->text;
a8206004 5413
d62a17ae 5414 peer = peer_and_group_lookup_vty(vty, pstr);
5415 if (!peer)
5416 return CMD_WARNING_CONFIG_FAILED;
a8206004 5417
d62a17ae 5418 /* Check filter direction. */
5419 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5420 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5421 direct, acl);
a8206004 5422
d62a17ae 5423 return bgp_vty_return(vty, ret);
718e3744 5424}
5425
d62a17ae 5426ALIAS_HIDDEN(
5427 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5428 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5430 "Filter updates to/from this neighbor\n"
5431 "IP access-list number\n"
5432 "IP access-list number (expanded range)\n"
5433 "IP Access-list name\n"
5434 "Filter incoming updates\n"
5435 "Filter outgoing updates\n")
596c17ba 5436
718e3744 5437DEFUN (no_neighbor_distribute_list,
5438 no_neighbor_distribute_list_cmd,
9ccf14f7 5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5440 NO_STR
5441 NEIGHBOR_STR
5442 NEIGHBOR_ADDR_STR2
5443 "Filter updates to/from this neighbor\n"
5444 "IP access-list number\n"
5445 "IP access-list number (expanded range)\n"
5446 "IP Access-list name\n"
5447 "Filter incoming updates\n"
5448 "Filter outgoing updates\n")
5449{
d62a17ae 5450 int idx_peer = 2;
5451 int direct, ret;
5452 struct peer *peer;
a8206004 5453
d62a17ae 5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *inout = argv[argc - 1]->text;
a8206004 5456
d62a17ae 5457 peer = peer_and_group_lookup_vty(vty, pstr);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
a8206004 5460
d62a17ae 5461 /* Check filter direction. */
5462 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5463 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5464 direct);
a8206004 5465
d62a17ae 5466 return bgp_vty_return(vty, ret);
718e3744 5467}
6b0655a2 5468
d62a17ae 5469ALIAS_HIDDEN(
5470 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "IP access-list number\n"
5475 "IP access-list number (expanded range)\n"
5476 "IP Access-list name\n"
5477 "Filter incoming updates\n"
5478 "Filter outgoing updates\n")
596c17ba 5479
718e3744 5480/* Set prefix list to the peer. */
d62a17ae 5481static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5482 afi_t afi, safi_t safi,
5483 const char *name_str,
5484 const char *direct_str)
718e3744 5485{
d62a17ae 5486 int ret;
d62a17ae 5487 int direct = FILTER_IN;
cf9ac8bf 5488 struct peer *peer;
718e3744 5489
d62a17ae 5490 peer = peer_and_group_lookup_vty(vty, ip_str);
5491 if (!peer)
5492 return CMD_WARNING_CONFIG_FAILED;
718e3744 5493
d62a17ae 5494 /* Check filter direction. */
5495 if (strncmp(direct_str, "i", 1) == 0)
5496 direct = FILTER_IN;
5497 else if (strncmp(direct_str, "o", 1) == 0)
5498 direct = FILTER_OUT;
718e3744 5499
d62a17ae 5500 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5501
d62a17ae 5502 return bgp_vty_return(vty, ret);
718e3744 5503}
5504
d62a17ae 5505static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *direct_str)
718e3744 5508{
d62a17ae 5509 int ret;
5510 struct peer *peer;
5511 int direct = FILTER_IN;
718e3744 5512
d62a17ae 5513 peer = peer_and_group_lookup_vty(vty, ip_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5516
d62a17ae 5517 /* Check filter direction. */
5518 if (strncmp(direct_str, "i", 1) == 0)
5519 direct = FILTER_IN;
5520 else if (strncmp(direct_str, "o", 1) == 0)
5521 direct = FILTER_OUT;
718e3744 5522
d62a17ae 5523 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5524
d62a17ae 5525 return bgp_vty_return(vty, ret);
718e3744 5526}
5527
5528DEFUN (neighbor_prefix_list,
5529 neighbor_prefix_list_cmd,
9ccf14f7 5530 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Filter updates to/from this neighbor\n"
5534 "Name of a prefix list\n"
5535 "Filter incoming updates\n"
5536 "Filter outgoing updates\n")
5537{
d62a17ae 5538 int idx_peer = 1;
5539 int idx_word = 3;
5540 int idx_in_out = 4;
5541 return peer_prefix_list_set_vty(
5542 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5543 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5544}
5545
d62a17ae 5546ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5547 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Filter updates to/from this neighbor\n"
5550 "Name of a prefix list\n"
5551 "Filter incoming updates\n"
5552 "Filter outgoing updates\n")
596c17ba 5553
718e3744 5554DEFUN (no_neighbor_prefix_list,
5555 no_neighbor_prefix_list_cmd,
9ccf14f7 5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Filter updates to/from this neighbor\n"
5561 "Name of a prefix list\n"
5562 "Filter incoming updates\n"
5563 "Filter outgoing updates\n")
5564{
d62a17ae 5565 int idx_peer = 2;
5566 int idx_in_out = 5;
5567 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5568 bgp_node_afi(vty), bgp_node_safi(vty),
5569 argv[idx_in_out]->arg);
718e3744 5570}
6b0655a2 5571
d62a17ae 5572ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5573 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5575 "Filter updates to/from this neighbor\n"
5576 "Name of a prefix list\n"
5577 "Filter incoming updates\n"
5578 "Filter outgoing updates\n")
596c17ba 5579
d62a17ae 5580static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5581 safi_t safi, const char *name_str,
5582 const char *direct_str)
718e3744 5583{
d62a17ae 5584 int ret;
5585 struct peer *peer;
5586 int direct = FILTER_IN;
718e3744 5587
d62a17ae 5588 peer = peer_and_group_lookup_vty(vty, ip_str);
5589 if (!peer)
5590 return CMD_WARNING_CONFIG_FAILED;
718e3744 5591
d62a17ae 5592 /* Check filter direction. */
5593 if (strncmp(direct_str, "i", 1) == 0)
5594 direct = FILTER_IN;
5595 else if (strncmp(direct_str, "o", 1) == 0)
5596 direct = FILTER_OUT;
718e3744 5597
d62a17ae 5598 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5599
d62a17ae 5600 return bgp_vty_return(vty, ret);
718e3744 5601}
5602
d62a17ae 5603static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5604 safi_t safi, const char *direct_str)
718e3744 5605{
d62a17ae 5606 int ret;
5607 struct peer *peer;
5608 int direct = FILTER_IN;
718e3744 5609
d62a17ae 5610 peer = peer_and_group_lookup_vty(vty, ip_str);
5611 if (!peer)
5612 return CMD_WARNING_CONFIG_FAILED;
718e3744 5613
d62a17ae 5614 /* Check filter direction. */
5615 if (strncmp(direct_str, "i", 1) == 0)
5616 direct = FILTER_IN;
5617 else if (strncmp(direct_str, "o", 1) == 0)
5618 direct = FILTER_OUT;
718e3744 5619
d62a17ae 5620 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5621
d62a17ae 5622 return bgp_vty_return(vty, ret);
718e3744 5623}
5624
5625DEFUN (neighbor_filter_list,
5626 neighbor_filter_list_cmd,
9ccf14f7 5627 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Establish BGP filters\n"
5631 "AS path access-list name\n"
5632 "Filter incoming routes\n"
5633 "Filter outgoing routes\n")
5634{
d62a17ae 5635 int idx_peer = 1;
5636 int idx_word = 3;
5637 int idx_in_out = 4;
5638 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5639 bgp_node_safi(vty), argv[idx_word]->arg,
5640 argv[idx_in_out]->arg);
718e3744 5641}
5642
d62a17ae 5643ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Establish BGP filters\n"
5647 "AS path access-list name\n"
5648 "Filter incoming routes\n"
5649 "Filter outgoing routes\n")
596c17ba 5650
718e3744 5651DEFUN (no_neighbor_filter_list,
5652 no_neighbor_filter_list_cmd,
9ccf14f7 5653 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5654 NO_STR
5655 NEIGHBOR_STR
5656 NEIGHBOR_ADDR_STR2
5657 "Establish BGP filters\n"
5658 "AS path access-list name\n"
5659 "Filter incoming routes\n"
5660 "Filter outgoing routes\n")
5661{
d62a17ae 5662 int idx_peer = 2;
5663 int idx_in_out = 5;
5664 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5665 bgp_node_afi(vty), bgp_node_safi(vty),
5666 argv[idx_in_out]->arg);
718e3744 5667}
6b0655a2 5668
d62a17ae 5669ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Establish BGP filters\n"
5673 "AS path access-list name\n"
5674 "Filter incoming routes\n"
5675 "Filter outgoing routes\n")
596c17ba 5676
718e3744 5677/* Set route-map to the peer. */
d62a17ae 5678static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5679 afi_t afi, safi_t safi, const char *name_str,
5680 const char *direct_str)
718e3744 5681{
d62a17ae 5682 int ret;
5683 struct peer *peer;
5684 int direct = RMAP_IN;
1de27621 5685 struct route_map *route_map;
718e3744 5686
d62a17ae 5687 peer = peer_and_group_lookup_vty(vty, ip_str);
5688 if (!peer)
5689 return CMD_WARNING_CONFIG_FAILED;
718e3744 5690
d62a17ae 5691 /* Check filter direction. */
5692 if (strncmp(direct_str, "in", 2) == 0)
5693 direct = RMAP_IN;
5694 else if (strncmp(direct_str, "o", 1) == 0)
5695 direct = RMAP_OUT;
718e3744 5696
1de27621
DA
5697 route_map = route_map_lookup_warn_noexist(vty, name_str);
5698 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5699
d62a17ae 5700 return bgp_vty_return(vty, ret);
718e3744 5701}
5702
d62a17ae 5703static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5704 afi_t afi, safi_t safi,
5705 const char *direct_str)
718e3744 5706{
d62a17ae 5707 int ret;
5708 struct peer *peer;
5709 int direct = RMAP_IN;
718e3744 5710
d62a17ae 5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
718e3744 5714
d62a17ae 5715 /* Check filter direction. */
5716 if (strncmp(direct_str, "in", 2) == 0)
5717 direct = RMAP_IN;
5718 else if (strncmp(direct_str, "o", 1) == 0)
5719 direct = RMAP_OUT;
718e3744 5720
d62a17ae 5721 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5722
d62a17ae 5723 return bgp_vty_return(vty, ret);
718e3744 5724}
5725
5726DEFUN (neighbor_route_map,
5727 neighbor_route_map_cmd,
9ccf14f7 5728 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5729 NEIGHBOR_STR
5730 NEIGHBOR_ADDR_STR2
5731 "Apply route map to neighbor\n"
5732 "Name of route map\n"
5733 "Apply map to incoming routes\n"
2a3d5731 5734 "Apply map to outbound routes\n")
718e3744 5735{
d62a17ae 5736 int idx_peer = 1;
5737 int idx_word = 3;
5738 int idx_in_out = 4;
5739 return peer_route_map_set_vty(
5740 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5741 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5742}
5743
d62a17ae 5744ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Apply route map to neighbor\n"
5748 "Name of route map\n"
5749 "Apply map to incoming routes\n"
5750 "Apply map to outbound routes\n")
596c17ba 5751
718e3744 5752DEFUN (no_neighbor_route_map,
5753 no_neighbor_route_map_cmd,
9ccf14f7 5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5755 NO_STR
5756 NEIGHBOR_STR
5757 NEIGHBOR_ADDR_STR2
5758 "Apply route map to neighbor\n"
5759 "Name of route map\n"
5760 "Apply map to incoming routes\n"
2a3d5731 5761 "Apply map to outbound routes\n")
718e3744 5762{
d62a17ae 5763 int idx_peer = 2;
5764 int idx_in_out = 5;
5765 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5766 bgp_node_afi(vty), bgp_node_safi(vty),
5767 argv[idx_in_out]->arg);
718e3744 5768}
6b0655a2 5769
d62a17ae 5770ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5771 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5773 "Apply route map to neighbor\n"
5774 "Name of route map\n"
5775 "Apply map to incoming routes\n"
5776 "Apply map to outbound routes\n")
596c17ba 5777
718e3744 5778/* Set unsuppress-map to the peer. */
d62a17ae 5779static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5780 afi_t afi, safi_t safi,
5781 const char *name_str)
718e3744 5782{
d62a17ae 5783 int ret;
5784 struct peer *peer;
1de27621 5785 struct route_map *route_map;
718e3744 5786
d62a17ae 5787 peer = peer_and_group_lookup_vty(vty, ip_str);
5788 if (!peer)
5789 return CMD_WARNING_CONFIG_FAILED;
718e3744 5790
1de27621
DA
5791 route_map = route_map_lookup_warn_noexist(vty, name_str);
5792 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5793
d62a17ae 5794 return bgp_vty_return(vty, ret);
718e3744 5795}
5796
5797/* Unset route-map from the peer. */
d62a17ae 5798static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5799 afi_t afi, safi_t safi)
718e3744 5800{
d62a17ae 5801 int ret;
5802 struct peer *peer;
718e3744 5803
d62a17ae 5804 peer = peer_and_group_lookup_vty(vty, ip_str);
5805 if (!peer)
5806 return CMD_WARNING_CONFIG_FAILED;
718e3744 5807
d62a17ae 5808 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5809
d62a17ae 5810 return bgp_vty_return(vty, ret);
718e3744 5811}
5812
5813DEFUN (neighbor_unsuppress_map,
5814 neighbor_unsuppress_map_cmd,
9ccf14f7 5815 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Route-map to selectively unsuppress suppressed routes\n"
5819 "Name of route map\n")
5820{
d62a17ae 5821 int idx_peer = 1;
5822 int idx_word = 3;
5823 return peer_unsuppress_map_set_vty(
5824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5825 argv[idx_word]->arg);
718e3744 5826}
5827
d62a17ae 5828ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Route-map to selectively unsuppress suppressed routes\n"
5832 "Name of route map\n")
596c17ba 5833
718e3744 5834DEFUN (no_neighbor_unsuppress_map,
5835 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5836 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5837 NO_STR
5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Route-map to selectively unsuppress suppressed routes\n"
5841 "Name of route map\n")
5842{
d62a17ae 5843 int idx_peer = 2;
5844 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5845 bgp_node_afi(vty),
5846 bgp_node_safi(vty));
718e3744 5847}
6b0655a2 5848
d62a17ae 5849ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5850 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Route-map to selectively unsuppress suppressed routes\n"
5853 "Name of route map\n")
596c17ba 5854
d62a17ae 5855static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5856 afi_t afi, safi_t safi,
5857 const char *num_str,
5858 const char *threshold_str, int warning,
5859 const char *restart_str)
718e3744 5860{
d62a17ae 5861 int ret;
5862 struct peer *peer;
d7c0a89a
QY
5863 uint32_t max;
5864 uint8_t threshold;
5865 uint16_t restart;
718e3744 5866
d62a17ae 5867 peer = peer_and_group_lookup_vty(vty, ip_str);
5868 if (!peer)
5869 return CMD_WARNING_CONFIG_FAILED;
718e3744 5870
d62a17ae 5871 max = strtoul(num_str, NULL, 10);
5872 if (threshold_str)
5873 threshold = atoi(threshold_str);
5874 else
5875 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5876
d62a17ae 5877 if (restart_str)
5878 restart = atoi(restart_str);
5879 else
5880 restart = 0;
0a486e5f 5881
d62a17ae 5882 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5883 restart);
718e3744 5884
d62a17ae 5885 return bgp_vty_return(vty, ret);
718e3744 5886}
5887
d62a17ae 5888static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5889 afi_t afi, safi_t safi)
718e3744 5890{
d62a17ae 5891 int ret;
5892 struct peer *peer;
718e3744 5893
d62a17ae 5894 peer = peer_and_group_lookup_vty(vty, ip_str);
5895 if (!peer)
5896 return CMD_WARNING_CONFIG_FAILED;
718e3744 5897
d62a17ae 5898 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5899
d62a17ae 5900 return bgp_vty_return(vty, ret);
718e3744 5901}
5902
5903/* Maximum number of prefix configuration. prefix count is different
5904 for each peer configuration. So this configuration can be set for
5905 each peer configuration. */
5906DEFUN (neighbor_maximum_prefix,
5907 neighbor_maximum_prefix_cmd,
9ccf14f7 5908 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n")
5913{
d62a17ae 5914 int idx_peer = 1;
5915 int idx_number = 3;
5916 return peer_maximum_prefix_set_vty(
5917 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5918 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5919}
5920
d62a17ae 5921ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5922 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5924 "Maximum number of prefix accept from this peer\n"
5925 "maximum no. of prefix limit\n")
596c17ba 5926
e0701b79 5927DEFUN (neighbor_maximum_prefix_threshold,
5928 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5929 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Maximum number of prefix accept from this peer\n"
5933 "maximum no. of prefix limit\n"
5934 "Threshold value (%) at which to generate a warning msg\n")
5935{
d62a17ae 5936 int idx_peer = 1;
5937 int idx_number = 3;
5938 int idx_number_2 = 4;
5939 return peer_maximum_prefix_set_vty(
5940 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5941 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5942}
e0701b79 5943
d62a17ae 5944ALIAS_HIDDEN(
5945 neighbor_maximum_prefix_threshold,
5946 neighbor_maximum_prefix_threshold_hidden_cmd,
5947 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Maximum number of prefix accept from this peer\n"
5950 "maximum no. of prefix limit\n"
5951 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5952
718e3744 5953DEFUN (neighbor_maximum_prefix_warning,
5954 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5955 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Maximum number of prefix accept from this peer\n"
5959 "maximum no. of prefix limit\n"
5960 "Only give warning message when limit is exceeded\n")
5961{
d62a17ae 5962 int idx_peer = 1;
5963 int idx_number = 3;
5964 return peer_maximum_prefix_set_vty(
5965 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5966 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5967}
5968
d62a17ae 5969ALIAS_HIDDEN(
5970 neighbor_maximum_prefix_warning,
5971 neighbor_maximum_prefix_warning_hidden_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5974 "Maximum number of prefix accept from this peer\n"
5975 "maximum no. of prefix limit\n"
5976 "Only give warning message when limit is exceeded\n")
596c17ba 5977
e0701b79 5978DEFUN (neighbor_maximum_prefix_threshold_warning,
5979 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5980 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5981 NEIGHBOR_STR
5982 NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefix accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Threshold value (%) at which to generate a warning msg\n"
5986 "Only give warning message when limit is exceeded\n")
5987{
d62a17ae 5988 int idx_peer = 1;
5989 int idx_number = 3;
5990 int idx_number_2 = 4;
5991 return peer_maximum_prefix_set_vty(
5992 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5993 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5994}
5995
d62a17ae 5996ALIAS_HIDDEN(
5997 neighbor_maximum_prefix_threshold_warning,
5998 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Threshold value (%) at which to generate a warning msg\n"
6004 "Only give warning message when limit is exceeded\n")
596c17ba 6005
0a486e5f 6006DEFUN (neighbor_maximum_prefix_restart,
6007 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6008 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Maximum number of prefix accept from this peer\n"
6012 "maximum no. of prefix limit\n"
6013 "Restart bgp connection after limit is exceeded\n"
efd7904e 6014 "Restart interval in minutes\n")
0a486e5f 6015{
d62a17ae 6016 int idx_peer = 1;
6017 int idx_number = 3;
6018 int idx_number_2 = 5;
6019 return peer_maximum_prefix_set_vty(
6020 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6021 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6022}
6023
d62a17ae 6024ALIAS_HIDDEN(
6025 neighbor_maximum_prefix_restart,
6026 neighbor_maximum_prefix_restart_hidden_cmd,
6027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Maximum number of prefix accept from this peer\n"
6030 "maximum no. of prefix limit\n"
6031 "Restart bgp connection after limit is exceeded\n"
efd7904e 6032 "Restart interval in minutes\n")
596c17ba 6033
0a486e5f 6034DEFUN (neighbor_maximum_prefix_threshold_restart,
6035 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6036 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
16cedbb0 6039 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6040 "maximum no. of prefix limit\n"
6041 "Threshold value (%) at which to generate a warning msg\n"
6042 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6043 "Restart interval in minutes\n")
0a486e5f 6044{
d62a17ae 6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 4;
6048 int idx_number_3 = 6;
6049 return peer_maximum_prefix_set_vty(
6050 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6051 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6052 argv[idx_number_3]->arg);
6053}
6054
6055ALIAS_HIDDEN(
6056 neighbor_maximum_prefix_threshold_restart,
6057 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6060 "Maximum number of prefixes to accept from this peer\n"
6061 "maximum no. of prefix limit\n"
6062 "Threshold value (%) at which to generate a warning msg\n"
6063 "Restart bgp connection after limit is exceeded\n"
6064 "Restart interval in minutes\n")
596c17ba 6065
718e3744 6066DEFUN (no_neighbor_maximum_prefix,
6067 no_neighbor_maximum_prefix_cmd,
d04c479d 6068 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6069 NO_STR
6070 NEIGHBOR_STR
6071 NEIGHBOR_ADDR_STR2
16cedbb0 6072 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6073 "maximum no. of prefix limit\n"
6074 "Threshold value (%) at which to generate a warning msg\n"
6075 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6076 "Restart interval in minutes\n"
31500417 6077 "Only give warning message when limit is exceeded\n")
718e3744 6078{
d62a17ae 6079 int idx_peer = 2;
6080 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6081 bgp_node_afi(vty),
6082 bgp_node_safi(vty));
718e3744 6083}
e52702f2 6084
d62a17ae 6085ALIAS_HIDDEN(
6086 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6087 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n"
6094 "Only give warning message when limit is exceeded\n")
596c17ba 6095
718e3744 6096
718e3744 6097/* "neighbor allowas-in" */
6098DEFUN (neighbor_allowas_in,
6099 neighbor_allowas_in_cmd,
fd8503f5 6100 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
31500417 6103 "Accept as-path with my AS present in it\n"
0437e105 6104 "Number of occurences of AS number\n"
fd8503f5 6105 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6106{
d62a17ae 6107 int idx_peer = 1;
6108 int idx_number_origin = 3;
6109 int ret;
6110 int origin = 0;
6111 struct peer *peer;
6112 int allow_num = 0;
6113
6114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
6117
6118 if (argc <= idx_number_origin)
6119 allow_num = 3;
6120 else {
6121 if (argv[idx_number_origin]->type == WORD_TKN)
6122 origin = 1;
6123 else
6124 allow_num = atoi(argv[idx_number_origin]->arg);
6125 }
6126
6127 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6128 allow_num, origin);
6129
6130 return bgp_vty_return(vty, ret);
6131}
6132
6133ALIAS_HIDDEN(
6134 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Accept as-path with my AS present in it\n"
0437e105 6138 "Number of occurences of AS number\n"
d62a17ae 6139 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6140
718e3744 6141DEFUN (no_neighbor_allowas_in,
6142 no_neighbor_allowas_in_cmd,
fd8503f5 6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6144 NO_STR
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
8334fd5a 6147 "allow local ASN appears in aspath attribute\n"
0437e105 6148 "Number of occurences of AS number\n"
fd8503f5 6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6150{
d62a17ae 6151 int idx_peer = 2;
6152 int ret;
6153 struct peer *peer;
718e3744 6154
d62a17ae 6155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6156 if (!peer)
6157 return CMD_WARNING_CONFIG_FAILED;
718e3744 6158
d62a17ae 6159 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6160 bgp_node_safi(vty));
718e3744 6161
d62a17ae 6162 return bgp_vty_return(vty, ret);
718e3744 6163}
6b0655a2 6164
d62a17ae 6165ALIAS_HIDDEN(
6166 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "allow local ASN appears in aspath attribute\n"
0437e105 6170 "Number of occurences of AS number\n"
d62a17ae 6171 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6172
fa411a21
NH
6173DEFUN (neighbor_ttl_security,
6174 neighbor_ttl_security_cmd,
7ebe625c 6175 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6176 NEIGHBOR_STR
7ebe625c 6177 NEIGHBOR_ADDR_STR2
16cedbb0 6178 "BGP ttl-security parameters\n"
d7fa34c1
QY
6179 "Specify the maximum number of hops to the BGP peer\n"
6180 "Number of hops to BGP peer\n")
fa411a21 6181{
d62a17ae 6182 int idx_peer = 1;
6183 int idx_number = 4;
6184 struct peer *peer;
6185 int gtsm_hops;
6186
6187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6188 if (!peer)
6189 return CMD_WARNING_CONFIG_FAILED;
6190
6191 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6192
7ebe625c
QY
6193 /*
6194 * If 'neighbor swpX', then this is for directly connected peers,
6195 * we should not accept a ttl-security hops value greater than 1.
6196 */
6197 if (peer->conf_if && (gtsm_hops > 1)) {
6198 vty_out(vty,
6199 "%s is directly connected peer, hops cannot exceed 1\n",
6200 argv[idx_peer]->arg);
6201 return CMD_WARNING_CONFIG_FAILED;
6202 }
6203
d62a17ae 6204 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6205}
6206
6207DEFUN (no_neighbor_ttl_security,
6208 no_neighbor_ttl_security_cmd,
7ebe625c 6209 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6210 NO_STR
6211 NEIGHBOR_STR
7ebe625c 6212 NEIGHBOR_ADDR_STR2
16cedbb0 6213 "BGP ttl-security parameters\n"
3a2d747c
QY
6214 "Specify the maximum number of hops to the BGP peer\n"
6215 "Number of hops to BGP peer\n")
fa411a21 6216{
d62a17ae 6217 int idx_peer = 2;
6218 struct peer *peer;
fa411a21 6219
d62a17ae 6220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6221 if (!peer)
6222 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6223
d62a17ae 6224 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6225}
6b0655a2 6226
adbac85e
DW
6227DEFUN (neighbor_addpath_tx_all_paths,
6228 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6229 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Use addpath to advertise all paths to a neighbor\n")
6233{
d62a17ae 6234 int idx_peer = 1;
6235 struct peer *peer;
adbac85e 6236
d62a17ae 6237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6238 if (!peer)
6239 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6240
dcc68b5e
MS
6241 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6242 BGP_ADDPATH_ALL);
6243 return CMD_SUCCESS;
adbac85e
DW
6244}
6245
d62a17ae 6246ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6247 neighbor_addpath_tx_all_paths_hidden_cmd,
6248 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6251
adbac85e
DW
6252DEFUN (no_neighbor_addpath_tx_all_paths,
6253 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6254 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6255 NO_STR
6256 NEIGHBOR_STR
6257 NEIGHBOR_ADDR_STR2
6258 "Use addpath to advertise all paths to a neighbor\n")
6259{
d62a17ae 6260 int idx_peer = 2;
dcc68b5e
MS
6261 struct peer *peer;
6262
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
6265 return CMD_WARNING_CONFIG_FAILED;
6266
6267 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6268 != BGP_ADDPATH_ALL) {
6269 vty_out(vty,
6270 "%% Peer not currently configured to transmit all paths.");
6271 return CMD_WARNING_CONFIG_FAILED;
6272 }
6273
6274 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6275 BGP_ADDPATH_NONE);
6276
6277 return CMD_SUCCESS;
adbac85e
DW
6278}
6279
d62a17ae 6280ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6281 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6283 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6285
06370dac
DW
6286DEFUN (neighbor_addpath_tx_bestpath_per_as,
6287 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6288 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6289 NEIGHBOR_STR
6290 NEIGHBOR_ADDR_STR2
6291 "Use addpath to advertise the bestpath per each neighboring AS\n")
6292{
d62a17ae 6293 int idx_peer = 1;
6294 struct peer *peer;
06370dac 6295
d62a17ae 6296 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6297 if (!peer)
6298 return CMD_WARNING_CONFIG_FAILED;
06370dac 6299
dcc68b5e
MS
6300 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6301 BGP_ADDPATH_BEST_PER_AS);
6302
6303 return CMD_SUCCESS;
06370dac
DW
6304}
6305
d62a17ae 6306ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6307 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6308 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6310 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6311
06370dac
DW
6312DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6313 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6315 NO_STR
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Use addpath to advertise the bestpath per each neighboring AS\n")
6319{
d62a17ae 6320 int idx_peer = 2;
dcc68b5e
MS
6321 struct peer *peer;
6322
6323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6324 if (!peer)
6325 return CMD_WARNING_CONFIG_FAILED;
6326
6327 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6328 != BGP_ADDPATH_BEST_PER_AS) {
6329 vty_out(vty,
6330 "%% Peer not currently configured to transmit all best path per as.");
6331 return CMD_WARNING_CONFIG_FAILED;
6332 }
6333
6334 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6335 BGP_ADDPATH_NONE);
6336
6337 return CMD_SUCCESS;
06370dac
DW
6338}
6339
d62a17ae 6340ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6341 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6342 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6343 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6344 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6345
b9c7bc5a
PZ
6346static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6347 struct ecommunity **list)
ddb5b488 6348{
b9c7bc5a
PZ
6349 struct ecommunity *ecom = NULL;
6350 struct ecommunity *ecomadd;
ddb5b488 6351
b9c7bc5a 6352 for (; argc; --argc, ++argv) {
ddb5b488 6353
b9c7bc5a
PZ
6354 ecomadd = ecommunity_str2com(argv[0]->arg,
6355 ECOMMUNITY_ROUTE_TARGET, 0);
6356 if (!ecomadd) {
6357 vty_out(vty, "Malformed community-list value\n");
6358 if (ecom)
6359 ecommunity_free(&ecom);
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
ddb5b488 6362
b9c7bc5a
PZ
6363 if (ecom) {
6364 ecommunity_merge(ecom, ecomadd);
6365 ecommunity_free(&ecomadd);
6366 } else {
6367 ecom = ecomadd;
6368 }
6369 }
6370
6371 if (*list) {
6372 ecommunity_free(&*list);
ddb5b488 6373 }
b9c7bc5a
PZ
6374 *list = ecom;
6375
6376 return CMD_SUCCESS;
ddb5b488
PZ
6377}
6378
0ca70ba5
DS
6379/*
6380 * v2vimport is true if we are handling a `import vrf ...` command
6381 */
6382static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6383{
0ca70ba5
DS
6384 afi_t afi;
6385
ddb5b488 6386 switch (vty->node) {
b9c7bc5a 6387 case BGP_IPV4_NODE:
0ca70ba5
DS
6388 afi = AFI_IP;
6389 break;
b9c7bc5a 6390 case BGP_IPV6_NODE:
0ca70ba5
DS
6391 afi = AFI_IP6;
6392 break;
ddb5b488
PZ
6393 default:
6394 vty_out(vty,
b9c7bc5a 6395 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6396 return AFI_MAX;
ddb5b488 6397 }
69b07479 6398
0ca70ba5
DS
6399 if (!v2vimport) {
6400 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6401 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6402 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6403 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6404 vty_out(vty,
6405 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6406 return AFI_MAX;
6407 }
6408 } else {
6409 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6410 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6411 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6412 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6413 vty_out(vty,
6414 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6415 return AFI_MAX;
6416 }
6417 }
6418 return afi;
ddb5b488
PZ
6419}
6420
b9c7bc5a
PZ
6421DEFPY (af_rd_vpn_export,
6422 af_rd_vpn_export_cmd,
6423 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6424 NO_STR
ddb5b488 6425 "Specify route distinguisher\n"
b9c7bc5a
PZ
6426 "Between current address-family and vpn\n"
6427 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6428 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6429{
6430 VTY_DECLVAR_CONTEXT(bgp, bgp);
6431 struct prefix_rd prd;
6432 int ret;
ddb5b488 6433 afi_t afi;
b9c7bc5a
PZ
6434 int idx = 0;
6435 int yes = 1;
ddb5b488 6436
b9c7bc5a 6437 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6438 yes = 0;
b9c7bc5a
PZ
6439
6440 if (yes) {
6441 ret = str2prefix_rd(rd_str, &prd);
6442 if (!ret) {
6443 vty_out(vty, "%% Malformed rd\n");
6444 return CMD_WARNING_CONFIG_FAILED;
6445 }
ddb5b488
PZ
6446 }
6447
0ca70ba5 6448 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6449 if (afi == AFI_MAX)
6450 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6451
69b07479
DS
6452 /*
6453 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6454 */
6455 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6456 bgp_get_default(), bgp);
ddb5b488 6457
69b07479
DS
6458 if (yes) {
6459 bgp->vpn_policy[afi].tovpn_rd = prd;
6460 SET_FLAG(bgp->vpn_policy[afi].flags,
6461 BGP_VPN_POLICY_TOVPN_RD_SET);
6462 } else {
6463 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6464 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6465 }
6466
69b07479
DS
6467 /* post-change: re-export vpn routes */
6468 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6469 bgp_get_default(), bgp);
6470
ddb5b488
PZ
6471 return CMD_SUCCESS;
6472}
6473
b9c7bc5a
PZ
6474ALIAS (af_rd_vpn_export,
6475 af_no_rd_vpn_export_cmd,
6476 "no rd vpn export",
ddb5b488 6477 NO_STR
b9c7bc5a
PZ
6478 "Specify route distinguisher\n"
6479 "Between current address-family and vpn\n"
6480 "For routes leaked from current address-family to vpn\n")
ddb5b488 6481
b9c7bc5a
PZ
6482DEFPY (af_label_vpn_export,
6483 af_label_vpn_export_cmd,
e70e9f8e 6484 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6485 NO_STR
ddb5b488 6486 "label value for VRF\n"
b9c7bc5a
PZ
6487 "Between current address-family and vpn\n"
6488 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6489 "Label Value <0-1048575>\n"
6490 "Automatically assign a label\n")
ddb5b488
PZ
6491{
6492 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6493 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6494 afi_t afi;
b9c7bc5a
PZ
6495 int idx = 0;
6496 int yes = 1;
6497
6498 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6499 yes = 0;
ddb5b488 6500
21a16cc2
PZ
6501 /* If "no ...", squash trailing parameter */
6502 if (!yes)
6503 label_auto = NULL;
6504
e70e9f8e
PZ
6505 if (yes) {
6506 if (!label_auto)
6507 label = label_val; /* parser should force unsigned */
6508 }
ddb5b488 6509
0ca70ba5 6510 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6511 if (afi == AFI_MAX)
6512 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6513
e70e9f8e 6514
69b07479
DS
6515 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6516 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6517 /* no change */
6518 return CMD_SUCCESS;
e70e9f8e 6519
69b07479
DS
6520 /*
6521 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6522 */
6523 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6524 bgp_get_default(), bgp);
6525
6526 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6527 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6528
6529 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6530
6531 /*
6532 * label has previously been automatically
6533 * assigned by labelpool: release it
6534 *
6535 * NB if tovpn_label == MPLS_LABEL_NONE it
6536 * means the automatic assignment is in flight
6537 * and therefore the labelpool callback must
6538 * detect that the auto label is not needed.
6539 */
6540
6541 bgp_lp_release(LP_TYPE_VRF,
6542 &bgp->vpn_policy[afi],
6543 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6544 }
69b07479
DS
6545 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6546 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6547 }
ddb5b488 6548
69b07479
DS
6549 bgp->vpn_policy[afi].tovpn_label = label;
6550 if (label_auto) {
6551 SET_FLAG(bgp->vpn_policy[afi].flags,
6552 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6553 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6554 vpn_leak_label_callback);
ddb5b488
PZ
6555 }
6556
69b07479
DS
6557 /* post-change: re-export vpn routes */
6558 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6559 bgp_get_default(), bgp);
6560
ddb5b488
PZ
6561 return CMD_SUCCESS;
6562}
6563
b9c7bc5a
PZ
6564ALIAS (af_label_vpn_export,
6565 af_no_label_vpn_export_cmd,
6566 "no label vpn export",
6567 NO_STR
6568 "label value for VRF\n"
6569 "Between current address-family and vpn\n"
6570 "For routes leaked from current address-family to vpn\n")
ddb5b488 6571
b9c7bc5a
PZ
6572DEFPY (af_nexthop_vpn_export,
6573 af_nexthop_vpn_export_cmd,
6574 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6575 NO_STR
ddb5b488 6576 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6577 "Between current address-family and vpn\n"
6578 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6579 "IPv4 prefix\n"
6580 "IPv6 prefix\n")
6581{
6582 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6583 afi_t afi;
ddb5b488 6584 struct prefix p;
b9c7bc5a
PZ
6585 int idx = 0;
6586 int yes = 1;
ddb5b488 6587
b9c7bc5a 6588 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6589 yes = 0;
b9c7bc5a
PZ
6590
6591 if (yes) {
6592 if (!sockunion2hostprefix(nexthop_str, &p))
6593 return CMD_WARNING_CONFIG_FAILED;
6594 }
ddb5b488 6595
0ca70ba5 6596 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6597 if (afi == AFI_MAX)
6598 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6599
69b07479
DS
6600 /*
6601 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6602 */
6603 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6604 bgp_get_default(), bgp);
ddb5b488 6605
69b07479
DS
6606 if (yes) {
6607 bgp->vpn_policy[afi].tovpn_nexthop = p;
6608 SET_FLAG(bgp->vpn_policy[afi].flags,
6609 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6610 } else {
6611 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6612 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6613 }
6614
69b07479
DS
6615 /* post-change: re-export vpn routes */
6616 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6617 bgp_get_default(), bgp);
6618
ddb5b488
PZ
6619 return CMD_SUCCESS;
6620}
6621
b9c7bc5a
PZ
6622ALIAS (af_nexthop_vpn_export,
6623 af_no_nexthop_vpn_export_cmd,
6624 "no nexthop vpn export",
ddb5b488 6625 NO_STR
b9c7bc5a
PZ
6626 "Specify next hop to use for VRF advertised prefixes\n"
6627 "Between current address-family and vpn\n"
6628 "For routes leaked from current address-family to vpn\n")
ddb5b488 6629
b9c7bc5a 6630static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6631{
b9c7bc5a
PZ
6632 if (!strcmp(dstr, "import")) {
6633 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6634 } else if (!strcmp(dstr, "export")) {
6635 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6636 } else if (!strcmp(dstr, "both")) {
6637 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6638 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6639 } else {
6640 vty_out(vty, "%% direction parse error\n");
6641 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6642 }
ddb5b488
PZ
6643 return CMD_SUCCESS;
6644}
6645
b9c7bc5a
PZ
6646DEFPY (af_rt_vpn_imexport,
6647 af_rt_vpn_imexport_cmd,
6648 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6649 NO_STR
6650 "Specify route target list\n"
ddb5b488 6651 "Specify route target list\n"
b9c7bc5a
PZ
6652 "Between current address-family and vpn\n"
6653 "For routes leaked from vpn to current address-family: match any\n"
6654 "For routes leaked from current address-family to vpn: set\n"
6655 "both import: match any and export: set\n"
ddb5b488
PZ
6656 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6657{
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
6659 int ret;
6660 struct ecommunity *ecom = NULL;
6661 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6662 vpn_policy_direction_t dir;
6663 afi_t afi;
6664 int idx = 0;
b9c7bc5a 6665 int yes = 1;
ddb5b488 6666
b9c7bc5a 6667 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6668 yes = 0;
b9c7bc5a 6669
0ca70ba5 6670 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6671 if (afi == AFI_MAX)
6672 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6673
b9c7bc5a 6674 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6675 if (ret != CMD_SUCCESS)
6676 return ret;
6677
b9c7bc5a
PZ
6678 if (yes) {
6679 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6680 vty_out(vty, "%% Missing RTLIST\n");
6681 return CMD_WARNING_CONFIG_FAILED;
6682 }
6683 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6684 if (ret != CMD_SUCCESS) {
6685 return ret;
6686 }
ddb5b488
PZ
6687 }
6688
69b07479
DS
6689 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6690 if (!dodir[dir])
ddb5b488 6691 continue;
ddb5b488 6692
69b07479 6693 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6694
69b07479
DS
6695 if (yes) {
6696 if (bgp->vpn_policy[afi].rtlist[dir])
6697 ecommunity_free(
6698 &bgp->vpn_policy[afi].rtlist[dir]);
6699 bgp->vpn_policy[afi].rtlist[dir] =
6700 ecommunity_dup(ecom);
6701 } else {
6702 if (bgp->vpn_policy[afi].rtlist[dir])
6703 ecommunity_free(
6704 &bgp->vpn_policy[afi].rtlist[dir]);
6705 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6706 }
69b07479
DS
6707
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6709 }
69b07479 6710
d555f3e9
PZ
6711 if (ecom)
6712 ecommunity_free(&ecom);
ddb5b488
PZ
6713
6714 return CMD_SUCCESS;
6715}
6716
b9c7bc5a
PZ
6717ALIAS (af_rt_vpn_imexport,
6718 af_no_rt_vpn_imexport_cmd,
6719 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6720 NO_STR
6721 "Specify route target list\n"
b9c7bc5a
PZ
6722 "Specify route target list\n"
6723 "Between current address-family and vpn\n"
6724 "For routes leaked from vpn to current address-family\n"
6725 "For routes leaked from current address-family to vpn\n"
6726 "both import and export\n")
6727
6728DEFPY (af_route_map_vpn_imexport,
6729 af_route_map_vpn_imexport_cmd,
6730/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6731 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6732 NO_STR
ddb5b488 6733 "Specify route map\n"
b9c7bc5a
PZ
6734 "Between current address-family and vpn\n"
6735 "For routes leaked from vpn to current address-family\n"
6736 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6737 "name of route-map\n")
6738{
6739 VTY_DECLVAR_CONTEXT(bgp, bgp);
6740 int ret;
6741 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6742 vpn_policy_direction_t dir;
6743 afi_t afi;
ddb5b488 6744 int idx = 0;
b9c7bc5a 6745 int yes = 1;
ddb5b488 6746
b9c7bc5a 6747 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6748 yes = 0;
b9c7bc5a 6749
0ca70ba5 6750 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6751 if (afi == AFI_MAX)
6752 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6753
b9c7bc5a 6754 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6755 if (ret != CMD_SUCCESS)
6756 return ret;
6757
69b07479
DS
6758 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6759 if (!dodir[dir])
ddb5b488 6760 continue;
ddb5b488 6761
69b07479 6762 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6763
69b07479
DS
6764 if (yes) {
6765 if (bgp->vpn_policy[afi].rmap_name[dir])
6766 XFREE(MTYPE_ROUTE_MAP_NAME,
6767 bgp->vpn_policy[afi].rmap_name[dir]);
6768 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6769 MTYPE_ROUTE_MAP_NAME, rmap_str);
6770 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6771 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6772 if (!bgp->vpn_policy[afi].rmap[dir])
6773 return CMD_SUCCESS;
6774 } else {
6775 if (bgp->vpn_policy[afi].rmap_name[dir])
6776 XFREE(MTYPE_ROUTE_MAP_NAME,
6777 bgp->vpn_policy[afi].rmap_name[dir]);
6778 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6779 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6780 }
69b07479
DS
6781
6782 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6783 }
6784
6785 return CMD_SUCCESS;
6786}
6787
b9c7bc5a
PZ
6788ALIAS (af_route_map_vpn_imexport,
6789 af_no_route_map_vpn_imexport_cmd,
6790 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6791 NO_STR
6792 "Specify route map\n"
b9c7bc5a
PZ
6793 "Between current address-family and vpn\n"
6794 "For routes leaked from vpn to current address-family\n"
6795 "For routes leaked from current address-family to vpn\n")
6796
bb4f6190
DS
6797DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6798 "[no] import vrf route-map RMAP$rmap_str",
6799 NO_STR
6800 "Import routes from another VRF\n"
6801 "Vrf routes being filtered\n"
6802 "Specify route map\n"
6803 "name of route-map\n")
6804{
6805 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6806 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6807 afi_t afi;
6808 int idx = 0;
6809 int yes = 1;
6810 struct bgp *bgp_default;
6811
6812 if (argv_find(argv, argc, "no", &idx))
6813 yes = 0;
6814
0ca70ba5 6815 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6816 if (afi == AFI_MAX)
6817 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6818
6819 bgp_default = bgp_get_default();
6820 if (!bgp_default) {
6821 int32_t ret;
6822 as_t as = bgp->as;
6823
6824 /* Auto-create assuming the same AS */
6825 ret = bgp_get(&bgp_default, &as, NULL,
6826 BGP_INSTANCE_TYPE_DEFAULT);
6827
6828 if (ret) {
6829 vty_out(vty,
6830 "VRF default is not configured as a bgp instance\n");
6831 return CMD_WARNING;
6832 }
6833 }
6834
69b07479 6835 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6836
69b07479
DS
6837 if (yes) {
6838 if (bgp->vpn_policy[afi].rmap_name[dir])
6839 XFREE(MTYPE_ROUTE_MAP_NAME,
6840 bgp->vpn_policy[afi].rmap_name[dir]);
6841 bgp->vpn_policy[afi].rmap_name[dir] =
6842 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6843 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6844 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6845 if (!bgp->vpn_policy[afi].rmap[dir])
6846 return CMD_SUCCESS;
6847 } else {
6848 if (bgp->vpn_policy[afi].rmap_name[dir])
6849 XFREE(MTYPE_ROUTE_MAP_NAME,
6850 bgp->vpn_policy[afi].rmap_name[dir]);
6851 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6852 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6853 }
6854
69b07479
DS
6855 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6856
bb4f6190
DS
6857 return CMD_SUCCESS;
6858}
6859
6860ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6861 "no import vrf route-map",
6862 NO_STR
6863 "Import routes from another VRF\n"
6864 "Vrf routes being filtered\n"
6865 "Specify route map\n")
6866
4d1b335c
DA
6867DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6868 "[no] import vrf VIEWVRFNAME$import_name",
6869 NO_STR
6870 "Import routes from another VRF\n"
6871 "VRF to import from\n"
6872 "The name of the VRF\n")
12a844a5
DS
6873{
6874 VTY_DECLVAR_CONTEXT(bgp, bgp);
6875 struct listnode *node;
79ef8664
DS
6876 struct bgp *vrf_bgp, *bgp_default;
6877 int32_t ret = 0;
6878 as_t as = bgp->as;
12a844a5
DS
6879 bool remove = false;
6880 int32_t idx = 0;
6881 char *vname;
a8dadcf6 6882 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6883 safi_t safi;
6884 afi_t afi;
6885
867f0cca 6886 if (import_name == NULL) {
6887 vty_out(vty, "%% Missing import name\n");
6888 return CMD_WARNING;
6889 }
6890
12a844a5
DS
6891 if (argv_find(argv, argc, "no", &idx))
6892 remove = true;
6893
0ca70ba5
DS
6894 afi = vpn_policy_getafi(vty, bgp, true);
6895 if (afi == AFI_MAX)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
12a844a5
DS
6898 safi = bgp_node_safi(vty);
6899
25679caa 6900 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6901 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6902 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6903 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6904 remove ? "unimport" : "import", import_name);
6905 return CMD_WARNING;
6906 }
6907
79ef8664
DS
6908 bgp_default = bgp_get_default();
6909 if (!bgp_default) {
6910 /* Auto-create assuming the same AS */
6911 ret = bgp_get(&bgp_default, &as, NULL,
6912 BGP_INSTANCE_TYPE_DEFAULT);
6913
6914 if (ret) {
6915 vty_out(vty,
6916 "VRF default is not configured as a bgp instance\n");
6917 return CMD_WARNING;
6918 }
6919 }
6920
12a844a5
DS
6921 vrf_bgp = bgp_lookup_by_name(import_name);
6922 if (!vrf_bgp) {
5742e42b 6923 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6924 vrf_bgp = bgp_default;
6925 else
0fb8d6e6
DS
6926 /* Auto-create assuming the same AS */
6927 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6928
6e2c7fe6 6929 if (ret) {
020a3f60
DS
6930 vty_out(vty,
6931 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6932 import_name);
6933 return CMD_WARNING;
6934 }
12a844a5
DS
6935 }
6936
12a844a5 6937 if (remove) {
44338987 6938 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6939 } else {
44338987 6940 /* Already importing from "import_vrf"? */
12a844a5
DS
6941 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6942 vname)) {
6943 if (strcmp(vname, import_name) == 0)
6944 return CMD_WARNING;
6945 }
6946
44338987 6947 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6948 }
6949
6950 return CMD_SUCCESS;
6951}
6952
b9c7bc5a
PZ
6953/* This command is valid only in a bgp vrf instance or the default instance */
6954DEFPY (bgp_imexport_vpn,
6955 bgp_imexport_vpn_cmd,
6956 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6957 NO_STR
6958 "Import routes to this address-family\n"
6959 "Export routes from this address-family\n"
6960 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6961{
6962 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6963 int previous_state;
ddb5b488 6964 afi_t afi;
b9c7bc5a 6965 safi_t safi;
ddb5b488 6966 int idx = 0;
b9c7bc5a
PZ
6967 int yes = 1;
6968 int flag;
6969 vpn_policy_direction_t dir;
ddb5b488 6970
b9c7bc5a 6971 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6972 yes = 0;
ddb5b488 6973
b9c7bc5a
PZ
6974 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6975 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6976
b9c7bc5a
PZ
6977 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6978 return CMD_WARNING_CONFIG_FAILED;
6979 }
ddb5b488 6980
b9c7bc5a
PZ
6981 afi = bgp_node_afi(vty);
6982 safi = bgp_node_safi(vty);
6983 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6984 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6985 return CMD_WARNING_CONFIG_FAILED;
6986 }
ddb5b488 6987
b9c7bc5a
PZ
6988 if (!strcmp(direction_str, "import")) {
6989 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6990 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6991 } else if (!strcmp(direction_str, "export")) {
6992 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6993 dir = BGP_VPN_POLICY_DIR_TOVPN;
6994 } else {
6995 vty_out(vty, "%% unknown direction %s\n", direction_str);
6996 return CMD_WARNING_CONFIG_FAILED;
6997 }
6998
6999 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7000
b9c7bc5a
PZ
7001 if (yes) {
7002 SET_FLAG(bgp->af_flags[afi][safi], flag);
7003 if (!previous_state) {
7004 /* trigger export current vrf */
ddb5b488
PZ
7005 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7006 }
b9c7bc5a
PZ
7007 } else {
7008 if (previous_state) {
7009 /* trigger un-export current vrf */
7010 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7011 }
7012 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7013 }
7014
7015 return CMD_SUCCESS;
7016}
7017
301ad80a
PG
7018DEFPY (af_routetarget_import,
7019 af_routetarget_import_cmd,
7020 "[no] <rt|route-target> redirect import RTLIST...",
7021 NO_STR
7022 "Specify route target list\n"
7023 "Specify route target list\n"
7024 "Flow-spec redirect type route target\n"
7025 "Import routes to this address-family\n"
7026 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7027{
7028 VTY_DECLVAR_CONTEXT(bgp, bgp);
7029 int ret;
7030 struct ecommunity *ecom = NULL;
301ad80a
PG
7031 afi_t afi;
7032 int idx = 0;
7033 int yes = 1;
7034
7035 if (argv_find(argv, argc, "no", &idx))
7036 yes = 0;
7037
0ca70ba5 7038 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7039 if (afi == AFI_MAX)
7040 return CMD_WARNING_CONFIG_FAILED;
7041
301ad80a
PG
7042 if (yes) {
7043 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7044 vty_out(vty, "%% Missing RTLIST\n");
7045 return CMD_WARNING_CONFIG_FAILED;
7046 }
7047 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7048 if (ret != CMD_SUCCESS)
7049 return ret;
7050 }
69b07479
DS
7051
7052 if (yes) {
7053 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7054 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7055 .import_redirect_rtlist);
69b07479
DS
7056 bgp->vpn_policy[afi].import_redirect_rtlist =
7057 ecommunity_dup(ecom);
7058 } else {
7059 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7060 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7061 .import_redirect_rtlist);
69b07479 7062 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7063 }
69b07479 7064
301ad80a
PG
7065 if (ecom)
7066 ecommunity_free(&ecom);
7067
7068 return CMD_SUCCESS;
7069}
7070
505e5056 7071DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7072 address_family_ipv4_safi_cmd,
7073 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7074 "Enter Address Family command mode\n"
7075 "Address Family\n"
7076 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7077{
f51bae9c 7078
d62a17ae 7079 if (argc == 3) {
2131d5cf 7080 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7081 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7082 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7083 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7084 && safi != SAFI_EVPN) {
31947174
MK
7085 vty_out(vty,
7086 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7087 return CMD_WARNING_CONFIG_FAILED;
7088 }
d62a17ae 7089 vty->node = bgp_node_type(AFI_IP, safi);
7090 } else
7091 vty->node = BGP_IPV4_NODE;
718e3744 7092
d62a17ae 7093 return CMD_SUCCESS;
718e3744 7094}
7095
505e5056 7096DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7097 address_family_ipv6_safi_cmd,
7098 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7099 "Enter Address Family command mode\n"
7100 "Address Family\n"
7101 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7102{
d62a17ae 7103 if (argc == 3) {
2131d5cf 7104 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7108 && safi != SAFI_EVPN) {
31947174
MK
7109 vty_out(vty,
7110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
d62a17ae 7113 vty->node = bgp_node_type(AFI_IP6, safi);
7114 } else
7115 vty->node = BGP_IPV6_NODE;
25ffbdc1 7116
d62a17ae 7117 return CMD_SUCCESS;
25ffbdc1 7118}
718e3744 7119
d6902373 7120#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7121DEFUN_NOSH (address_family_vpnv4,
718e3744 7122 address_family_vpnv4_cmd,
8334fd5a 7123 "address-family vpnv4 [unicast]",
718e3744 7124 "Enter Address Family command mode\n"
8c3deaae 7125 "Address Family\n"
3a2d747c 7126 "Address Family modifier\n")
718e3744 7127{
d62a17ae 7128 vty->node = BGP_VPNV4_NODE;
7129 return CMD_SUCCESS;
718e3744 7130}
7131
505e5056 7132DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7133 address_family_vpnv6_cmd,
8334fd5a 7134 "address-family vpnv6 [unicast]",
8ecd3266 7135 "Enter Address Family command mode\n"
8c3deaae 7136 "Address Family\n"
3a2d747c 7137 "Address Family modifier\n")
8ecd3266 7138{
d62a17ae 7139 vty->node = BGP_VPNV6_NODE;
7140 return CMD_SUCCESS;
8ecd3266 7141}
c016b6c7 7142#endif
d6902373 7143
505e5056 7144DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7145 address_family_evpn_cmd,
7111c1a0 7146 "address-family l2vpn evpn",
4e0b7b6d 7147 "Enter Address Family command mode\n"
7111c1a0
QY
7148 "Address Family\n"
7149 "Address Family modifier\n")
4e0b7b6d 7150{
2131d5cf 7151 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7152 vty->node = BGP_EVPN_NODE;
7153 return CMD_SUCCESS;
4e0b7b6d
PG
7154}
7155
505e5056 7156DEFUN_NOSH (exit_address_family,
718e3744 7157 exit_address_family_cmd,
7158 "exit-address-family",
7159 "Exit from Address Family configuration mode\n")
7160{
d62a17ae 7161 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7162 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7163 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7164 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7165 || vty->node == BGP_EVPN_NODE
7166 || vty->node == BGP_FLOWSPECV4_NODE
7167 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7168 vty->node = BGP_NODE;
7169 return CMD_SUCCESS;
718e3744 7170}
6b0655a2 7171
8ad7271d 7172/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7173static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7174 const char *ip_str, afi_t afi, safi_t safi,
7175 struct prefix_rd *prd)
7176{
7177 int ret;
7178 struct prefix match;
7179 struct bgp_node *rn;
7180 struct bgp_node *rm;
7181 struct bgp *bgp;
7182 struct bgp_table *table;
7183 struct bgp_table *rib;
7184
7185 /* BGP structure lookup. */
7186 if (view_name) {
7187 bgp = bgp_lookup_by_name(view_name);
7188 if (bgp == NULL) {
7189 vty_out(vty, "%% Can't find BGP instance %s\n",
7190 view_name);
7191 return CMD_WARNING;
7192 }
7193 } else {
7194 bgp = bgp_get_default();
7195 if (bgp == NULL) {
7196 vty_out(vty, "%% No BGP process is configured\n");
7197 return CMD_WARNING;
7198 }
7199 }
7200
7201 /* Check IP address argument. */
7202 ret = str2prefix(ip_str, &match);
7203 if (!ret) {
7204 vty_out(vty, "%% address is malformed\n");
7205 return CMD_WARNING;
7206 }
7207
7208 match.family = afi2family(afi);
7209 rib = bgp->rib[afi][safi];
7210
7211 if (safi == SAFI_MPLS_VPN) {
7212 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7213 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7214 continue;
7215
67009e22
DS
7216 table = bgp_node_get_bgp_table_info(rn);
7217 if (table != NULL) {
7218
d62a17ae 7219 if ((rm = bgp_node_match(table, &match))
7220 != NULL) {
7221 if (rm->p.prefixlen
7222 == match.prefixlen) {
343cdb61 7223 SET_FLAG(rm->flags,
d62a17ae 7224 BGP_NODE_USER_CLEAR);
7225 bgp_process(bgp, rm, afi, safi);
7226 }
7227 bgp_unlock_node(rm);
7228 }
7229 }
7230 }
7231 } else {
7232 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7233 if (rn->p.prefixlen == match.prefixlen) {
7234 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7235 bgp_process(bgp, rn, afi, safi);
7236 }
7237 bgp_unlock_node(rn);
7238 }
7239 }
7240
7241 return CMD_SUCCESS;
8ad7271d
DS
7242}
7243
b09b5ae0 7244/* one clear bgp command to rule them all */
718e3744 7245DEFUN (clear_ip_bgp_all,
7246 clear_ip_bgp_all_cmd,
c1a44e43 7247 "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 7248 CLEAR_STR
7249 IP_STR
7250 BGP_STR
838758ac 7251 BGP_INSTANCE_HELP_STR
510afcd6
DS
7252 BGP_AFI_HELP_STR
7253 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7254 "Clear all peers\n"
7255 "BGP neighbor address to clear\n"
a80beece 7256 "BGP IPv6 neighbor to clear\n"
838758ac 7257 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7258 "Clear peers with the AS number\n"
7259 "Clear all external peers\n"
718e3744 7260 "Clear all members of peer-group\n"
b09b5ae0 7261 "BGP peer-group name\n"
b09b5ae0
DW
7262 BGP_SOFT_STR
7263 BGP_SOFT_IN_STR
b09b5ae0
DW
7264 BGP_SOFT_OUT_STR
7265 BGP_SOFT_IN_STR
7266 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7267 BGP_SOFT_OUT_STR)
718e3744 7268{
d62a17ae 7269 char *vrf = NULL;
7270
7271 afi_t afi = AFI_IP6;
7272 safi_t safi = SAFI_UNICAST;
7273 enum clear_sort clr_sort = clear_peer;
7274 enum bgp_clear_type clr_type;
7275 char *clr_arg = NULL;
7276
7277 int idx = 0;
7278
7279 /* clear [ip] bgp */
7280 if (argv_find(argv, argc, "ip", &idx))
7281 afi = AFI_IP;
7282
9a8bdf1c
PG
7283 /* [<vrf> VIEWVRFNAME] */
7284 if (argv_find(argv, argc, "vrf", &idx)) {
7285 vrf = argv[idx + 1]->arg;
7286 idx += 2;
7287 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7288 vrf = NULL;
7289 } else if (argv_find(argv, argc, "view", &idx)) {
7290 /* [<view> VIEWVRFNAME] */
d62a17ae 7291 vrf = argv[idx + 1]->arg;
7292 idx += 2;
7293 }
d62a17ae 7294 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7295 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7296 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7297
7298 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7299 if (argv_find(argv, argc, "*", &idx)) {
7300 clr_sort = clear_all;
7301 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7302 clr_sort = clear_peer;
7303 clr_arg = argv[idx]->arg;
7304 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7305 clr_sort = clear_peer;
7306 clr_arg = argv[idx]->arg;
7307 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7308 clr_sort = clear_group;
7309 idx++;
7310 clr_arg = argv[idx]->arg;
7311 } else if (argv_find(argv, argc, "WORD", &idx)) {
7312 clr_sort = clear_peer;
7313 clr_arg = argv[idx]->arg;
7314 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7315 clr_sort = clear_as;
7316 clr_arg = argv[idx]->arg;
7317 } else if (argv_find(argv, argc, "external", &idx)) {
7318 clr_sort = clear_external;
7319 }
7320
7321 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7322 if (argv_find(argv, argc, "soft", &idx)) {
7323 if (argv_find(argv, argc, "in", &idx)
7324 || argv_find(argv, argc, "out", &idx))
7325 clr_type = strmatch(argv[idx]->text, "in")
7326 ? BGP_CLEAR_SOFT_IN
7327 : BGP_CLEAR_SOFT_OUT;
7328 else
7329 clr_type = BGP_CLEAR_SOFT_BOTH;
7330 } else if (argv_find(argv, argc, "in", &idx)) {
7331 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7332 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7333 : BGP_CLEAR_SOFT_IN;
7334 } else if (argv_find(argv, argc, "out", &idx)) {
7335 clr_type = BGP_CLEAR_SOFT_OUT;
7336 } else
7337 clr_type = BGP_CLEAR_SOFT_NONE;
7338
7339 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7340}
01080f7c 7341
8ad7271d
DS
7342DEFUN (clear_ip_bgp_prefix,
7343 clear_ip_bgp_prefix_cmd,
18c57037 7344 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7345 CLEAR_STR
7346 IP_STR
7347 BGP_STR
838758ac 7348 BGP_INSTANCE_HELP_STR
8ad7271d 7349 "Clear bestpath and re-advertise\n"
0c7b1b01 7350 "IPv4 prefix\n")
8ad7271d 7351{
d62a17ae 7352 char *vrf = NULL;
7353 char *prefix = NULL;
8ad7271d 7354
d62a17ae 7355 int idx = 0;
01080f7c 7356
d62a17ae 7357 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7358 if (argv_find(argv, argc, "vrf", &idx)) {
7359 vrf = argv[idx + 1]->arg;
7360 idx += 2;
7361 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7362 vrf = NULL;
7363 } else if (argv_find(argv, argc, "view", &idx)) {
7364 /* [<view> VIEWVRFNAME] */
7365 vrf = argv[idx + 1]->arg;
7366 idx += 2;
7367 }
0c7b1b01 7368
d62a17ae 7369 prefix = argv[argc - 1]->arg;
8ad7271d 7370
d62a17ae 7371 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7372}
8ad7271d 7373
b09b5ae0
DW
7374DEFUN (clear_bgp_ipv6_safi_prefix,
7375 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7376 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7377 CLEAR_STR
3a2d747c 7378 IP_STR
718e3744 7379 BGP_STR
8c3deaae 7380 "Address Family\n"
46f296b4 7381 BGP_SAFI_HELP_STR
b09b5ae0 7382 "Clear bestpath and re-advertise\n"
0c7b1b01 7383 "IPv6 prefix\n")
718e3744 7384{
9b475e76
PG
7385 int idx_safi = 0;
7386 int idx_ipv6_prefix = 0;
7387 safi_t safi = SAFI_UNICAST;
7388 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7389 argv[idx_ipv6_prefix]->arg : NULL;
7390
7391 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7392 return bgp_clear_prefix(
9b475e76
PG
7393 vty, NULL, prefix, AFI_IP6,
7394 safi, NULL);
838758ac 7395}
01080f7c 7396
b09b5ae0
DW
7397DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7398 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7399 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7400 CLEAR_STR
3a2d747c 7401 IP_STR
718e3744 7402 BGP_STR
838758ac 7403 BGP_INSTANCE_HELP_STR
8c3deaae 7404 "Address Family\n"
46f296b4 7405 BGP_SAFI_HELP_STR
b09b5ae0 7406 "Clear bestpath and re-advertise\n"
0c7b1b01 7407 "IPv6 prefix\n")
718e3744 7408{
9b475e76 7409 int idx_safi = 0;
9a8bdf1c 7410 int idx_vrfview = 0;
9b475e76
PG
7411 int idx_ipv6_prefix = 0;
7412 safi_t safi = SAFI_UNICAST;
7413 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7414 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7415 char *vrfview = NULL;
9b475e76 7416
9a8bdf1c
PG
7417 /* [<view|vrf> VIEWVRFNAME] */
7418 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7419 vrfview = argv[idx_vrfview + 1]->arg;
7420 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7421 vrfview = NULL;
7422 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7423 /* [<view> VIEWVRFNAME] */
7424 vrfview = argv[idx_vrfview + 1]->arg;
7425 }
9b475e76
PG
7426 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7427
d62a17ae 7428 return bgp_clear_prefix(
9b475e76
PG
7429 vty, vrfview, prefix,
7430 AFI_IP6, safi, NULL);
718e3744 7431}
7432
b09b5ae0
DW
7433DEFUN (show_bgp_views,
7434 show_bgp_views_cmd,
d6e3c605 7435 "show [ip] bgp views",
b09b5ae0 7436 SHOW_STR
d6e3c605 7437 IP_STR
01080f7c 7438 BGP_STR
b09b5ae0 7439 "Show the defined BGP views\n")
01080f7c 7440{
d62a17ae 7441 struct list *inst = bm->bgp;
7442 struct listnode *node;
7443 struct bgp *bgp;
01080f7c 7444
d62a17ae 7445 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7446 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7447 return CMD_WARNING;
7448 }
e52702f2 7449
d62a17ae 7450 vty_out(vty, "Defined BGP views:\n");
7451 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7452 /* Skip VRFs. */
7453 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7454 continue;
7455 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7456 bgp->as);
7457 }
e52702f2 7458
d62a17ae 7459 return CMD_SUCCESS;
e0081f70
ML
7460}
7461
8386ac43 7462DEFUN (show_bgp_vrfs,
7463 show_bgp_vrfs_cmd,
d6e3c605 7464 "show [ip] bgp vrfs [json]",
8386ac43 7465 SHOW_STR
d6e3c605 7466 IP_STR
8386ac43 7467 BGP_STR
7468 "Show BGP VRFs\n"
9973d184 7469 JSON_STR)
8386ac43 7470{
fe1dc5a3 7471 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7472 struct list *inst = bm->bgp;
7473 struct listnode *node;
7474 struct bgp *bgp;
9f049418 7475 bool uj = use_json(argc, argv);
d62a17ae 7476 json_object *json = NULL;
7477 json_object *json_vrfs = NULL;
7478 int count = 0;
d62a17ae 7479
7480 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7481 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7482 return CMD_WARNING;
7483 }
7484
7485 if (uj) {
7486 json = json_object_new_object();
7487 json_vrfs = json_object_new_object();
7488 }
7489
7490 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7491 const char *name, *type;
7492 struct peer *peer;
7fe96307 7493 struct listnode *node2, *nnode2;
d62a17ae 7494 int peers_cfg, peers_estb;
7495 json_object *json_vrf = NULL;
d62a17ae 7496
7497 /* Skip Views. */
7498 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7499 continue;
7500
7501 count++;
7502 if (!uj && count == 1)
fe1dc5a3
MK
7503 vty_out(vty,
7504 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7505 "Type", "Id", "routerId", "#PeersVfg",
7506 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7507
7508 peers_cfg = peers_estb = 0;
7509 if (uj)
7510 json_vrf = json_object_new_object();
7511
7512
7fe96307 7513 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7514 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7515 continue;
7516 peers_cfg++;
7517 if (peer->status == Established)
7518 peers_estb++;
7519 }
7520
7521 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7522 name = VRF_DEFAULT_NAME;
d62a17ae 7523 type = "DFLT";
7524 } else {
7525 name = bgp->name;
7526 type = "VRF";
7527 }
7528
a8bf7d9c 7529
d62a17ae 7530 if (uj) {
a4d82a8a
PZ
7531 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7532 ? -1
7533 : (int64_t)bgp->vrf_id;
d62a17ae 7534 json_object_string_add(json_vrf, "type", type);
7535 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7536 json_object_string_add(json_vrf, "routerId",
7537 inet_ntoa(bgp->router_id));
7538 json_object_int_add(json_vrf, "numConfiguredPeers",
7539 peers_cfg);
7540 json_object_int_add(json_vrf, "numEstablishedPeers",
7541 peers_estb);
7542
fe1dc5a3 7543 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7544 json_object_string_add(
7545 json_vrf, "rmac",
7546 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7547 json_object_object_add(json_vrfs, name, json_vrf);
7548 } else
fe1dc5a3
MK
7549 vty_out(vty,
7550 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7551 type,
7552 bgp->vrf_id == VRF_UNKNOWN ? -1
7553 : (int)bgp->vrf_id,
7554 inet_ntoa(bgp->router_id), peers_cfg,
7555 peers_estb, name, bgp->l3vni,
fe1dc5a3 7556 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7557 }
7558
7559 if (uj) {
7560 json_object_object_add(json, "vrfs", json_vrfs);
7561
7562 json_object_int_add(json, "totalVrfs", count);
7563
996c9314
LB
7564 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7565 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7566 json_object_free(json);
7567 } else {
7568 if (count)
7569 vty_out(vty,
7570 "\nTotal number of VRFs (including default): %d\n",
7571 count);
7572 }
7573
7574 return CMD_SUCCESS;
8386ac43 7575}
7576
acf71666
MK
7577
7578static void show_tip_entry(struct hash_backet *backet, void *args)
7579{
0291c246 7580 struct vty *vty = (struct vty *)args;
60466a63 7581 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7582
60466a63 7583 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7584 tip->refcnt);
7585}
7586
7587static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7588{
7589 vty_out(vty, "self nexthop database:\n");
af97a18b 7590 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7591
7592 vty_out(vty, "Tunnel-ip database:\n");
7593 hash_iterate(bgp->tip_hash,
7594 (void (*)(struct hash_backet *, void *))show_tip_entry,
7595 vty);
7596}
7597
15c81ca4
DS
7598DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7599 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7600 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7601 "martian next-hops\n"
7602 "martian next-hop database\n")
acf71666 7603{
0291c246 7604 struct bgp *bgp = NULL;
15c81ca4 7605 int idx = 0;
9a8bdf1c
PG
7606 char *name = NULL;
7607
7608 /* [<vrf> VIEWVRFNAME] */
7609 if (argv_find(argv, argc, "vrf", &idx)) {
7610 name = argv[idx + 1]->arg;
7611 if (name && strmatch(name, VRF_DEFAULT_NAME))
7612 name = NULL;
7613 } else if (argv_find(argv, argc, "view", &idx))
7614 /* [<view> VIEWVRFNAME] */
7615 name = argv[idx + 1]->arg;
7616 if (name)
7617 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7618 else
7619 bgp = bgp_get_default();
acf71666 7620
acf71666
MK
7621 if (!bgp) {
7622 vty_out(vty, "%% No BGP process is configured\n");
7623 return CMD_WARNING;
7624 }
7625 bgp_show_martian_nexthops(vty, bgp);
7626
7627 return CMD_SUCCESS;
7628}
7629
f412b39a 7630DEFUN (show_bgp_memory,
4bf6a362 7631 show_bgp_memory_cmd,
7fa12b13 7632 "show [ip] bgp memory",
4bf6a362 7633 SHOW_STR
3a2d747c 7634 IP_STR
4bf6a362
PJ
7635 BGP_STR
7636 "Global BGP memory statistics\n")
7637{
d62a17ae 7638 char memstrbuf[MTYPE_MEMSTR_LEN];
7639 unsigned long count;
7640
7641 /* RIB related usage stats */
7642 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7643 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7644 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7645 count * sizeof(struct bgp_node)));
7646
7647 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7648 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7649 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7650 count * sizeof(struct bgp_path_info)));
d62a17ae 7651 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7652 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7653 count,
4b7e6066
DS
7654 mtype_memstr(
7655 memstrbuf, sizeof(memstrbuf),
7656 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7657
7658 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7659 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7660 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7661 count * sizeof(struct bgp_static)));
7662
7663 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7664 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7666 count * sizeof(struct bpacket)));
7667
7668 /* Adj-In/Out */
7669 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7670 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7671 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7672 count * sizeof(struct bgp_adj_in)));
7673 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7674 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7676 count * sizeof(struct bgp_adj_out)));
7677
7678 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7679 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7680 count,
7681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7682 count * sizeof(struct bgp_nexthop_cache)));
7683
7684 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7685 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7686 count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_damp_info)));
7689
7690 /* Attributes */
7691 count = attr_count();
7692 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7693 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct attr)));
7695
7696 if ((count = attr_unknown_count()))
7697 vty_out(vty, "%ld unknown attributes\n", count);
7698
7699 /* AS_PATH attributes */
7700 count = aspath_count();
7701 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7703 count * sizeof(struct aspath)));
7704
7705 count = mtype_stats_alloc(MTYPE_AS_SEG);
7706 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct assegment)));
7709
7710 /* Other attributes */
7711 if ((count = community_count()))
7712 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7713 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct community)));
d62a17ae 7715 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7716 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7717 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7718 count * sizeof(struct ecommunity)));
d62a17ae 7719 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7720 vty_out(vty,
7721 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7722 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7723 count * sizeof(struct lcommunity)));
d62a17ae 7724
7725 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7726 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct cluster_list)));
7729
7730 /* Peer related usage */
7731 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7732 vty_out(vty, "%ld peers, using %s of memory\n", count,
7733 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct peer)));
7735
7736 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7737 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7738 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct peer_group)));
7740
7741 /* Other */
7742 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7743 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7744 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7745 count * sizeof(struct hash)));
7746 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7747 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7748 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7749 count * sizeof(struct hash_backet)));
7750 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7751 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7752 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7753 count * sizeof(regex_t)));
d62a17ae 7754 return CMD_SUCCESS;
4bf6a362 7755}
fee0f4c6 7756
57a9c8a8
DS
7757static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7758{
7759 json_object *bestpath = json_object_new_object();
7760
7761 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7762 json_object_string_add(bestpath, "asPath", "ignore");
7763
7764 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7765 json_object_string_add(bestpath, "asPath", "confed");
7766
7767 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7768 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7769 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7770 "as-set");
7771 else
a4d82a8a 7772 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7773 "true");
7774 } else
a4d82a8a 7775 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7776
7777 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7778 json_object_string_add(bestpath, "compareRouterId", "true");
7779 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7780 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7781 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7782 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7783 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7784 json_object_string_add(bestpath, "med",
7785 "missing-as-worst");
7786 else
7787 json_object_string_add(bestpath, "med", "true");
7788 }
7789
7790 json_object_object_add(json, "bestPath", bestpath);
7791}
7792
718e3744 7793/* Show BGP peer's summary information. */
d62a17ae 7794static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7795 bool use_json, json_object *json)
d62a17ae 7796{
7797 struct peer *peer;
7798 struct listnode *node, *nnode;
7799 unsigned int count = 0, dn_count = 0;
7800 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7801 char neighbor_buf[VTY_BUFSIZ];
7802 int neighbor_col_default_width = 16;
7803 int len;
7804 int max_neighbor_width = 0;
7805 int pfx_rcd_safi;
7806 json_object *json_peer = NULL;
7807 json_object *json_peers = NULL;
50e05855 7808 struct peer_af *paf;
d62a17ae 7809
7810 /* labeled-unicast routes are installed in the unicast table so in order
7811 * to
7812 * display the correct PfxRcd value we must look at SAFI_UNICAST
7813 */
7814 if (safi == SAFI_LABELED_UNICAST)
7815 pfx_rcd_safi = SAFI_UNICAST;
7816 else
7817 pfx_rcd_safi = safi;
7818
7819 if (use_json) {
7820 if (json == NULL)
7821 json = json_object_new_object();
7822
7823 json_peers = json_object_new_object();
7824 } else {
7825 /* Loop over all neighbors that will be displayed to determine
7826 * how many
7827 * characters are needed for the Neighbor column
7828 */
7829 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7830 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7831 continue;
7832
7833 if (peer->afc[afi][safi]) {
7834 memset(dn_flag, '\0', sizeof(dn_flag));
7835 if (peer_dynamic_neighbor(peer))
7836 dn_flag[0] = '*';
7837
7838 if (peer->hostname
7839 && bgp_flag_check(bgp,
7840 BGP_FLAG_SHOW_HOSTNAME))
7841 sprintf(neighbor_buf, "%s%s(%s) ",
7842 dn_flag, peer->hostname,
7843 peer->host);
7844 else
7845 sprintf(neighbor_buf, "%s%s ", dn_flag,
7846 peer->host);
7847
7848 len = strlen(neighbor_buf);
7849
7850 if (len > max_neighbor_width)
7851 max_neighbor_width = len;
7852 }
7853 }
f933309e 7854
d62a17ae 7855 /* Originally we displayed the Neighbor column as 16
7856 * characters wide so make that the default
7857 */
7858 if (max_neighbor_width < neighbor_col_default_width)
7859 max_neighbor_width = neighbor_col_default_width;
7860 }
f933309e 7861
d62a17ae 7862 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7863 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7864 continue;
7865
ea47320b
DL
7866 if (!peer->afc[afi][safi])
7867 continue;
d62a17ae 7868
ea47320b
DL
7869 if (!count) {
7870 unsigned long ents;
7871 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7872 int64_t vrf_id_ui;
d62a17ae 7873
a4d82a8a
PZ
7874 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7875 ? -1
7876 : (int64_t)bgp->vrf_id;
ea47320b
DL
7877
7878 /* Usage summary and header */
7879 if (use_json) {
7880 json_object_string_add(
7881 json, "routerId",
7882 inet_ntoa(bgp->router_id));
60466a63
QY
7883 json_object_int_add(json, "as", bgp->as);
7884 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7885 json_object_string_add(
7886 json, "vrfName",
7887 (bgp->inst_type
7888 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7889 ? VRF_DEFAULT_NAME
ea47320b
DL
7890 : bgp->name);
7891 } else {
7892 vty_out(vty,
7893 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7894 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7895 bgp->vrf_id == VRF_UNKNOWN
7896 ? -1
7897 : (int)bgp->vrf_id);
ea47320b
DL
7898 vty_out(vty, "\n");
7899 }
d62a17ae 7900
ea47320b 7901 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7902 if (use_json) {
ea47320b 7903 json_object_int_add(
60466a63 7904 json, "updateDelayLimit",
ea47320b 7905 bgp->v_update_delay);
d62a17ae 7906
ea47320b
DL
7907 if (bgp->v_update_delay
7908 != bgp->v_establish_wait)
d62a17ae 7909 json_object_int_add(
7910 json,
ea47320b
DL
7911 "updateDelayEstablishWait",
7912 bgp->v_establish_wait);
d62a17ae 7913
60466a63 7914 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7915 json_object_string_add(
7916 json,
7917 "updateDelayFirstNeighbor",
7918 bgp->update_delay_begin_time);
7919 json_object_boolean_true_add(
7920 json,
7921 "updateDelayInProgress");
7922 } else {
7923 if (bgp->update_delay_over) {
d62a17ae 7924 json_object_string_add(
7925 json,
7926 "updateDelayFirstNeighbor",
7927 bgp->update_delay_begin_time);
ea47320b 7928 json_object_string_add(
d62a17ae 7929 json,
ea47320b
DL
7930 "updateDelayBestpathResumed",
7931 bgp->update_delay_end_time);
7932 json_object_string_add(
d62a17ae 7933 json,
ea47320b
DL
7934 "updateDelayZebraUpdateResume",
7935 bgp->update_delay_zebra_resume_time);
7936 json_object_string_add(
7937 json,
7938 "updateDelayPeerUpdateResume",
7939 bgp->update_delay_peers_resume_time);
d62a17ae 7940 }
ea47320b
DL
7941 }
7942 } else {
7943 vty_out(vty,
7944 "Read-only mode update-delay limit: %d seconds\n",
7945 bgp->v_update_delay);
7946 if (bgp->v_update_delay
7947 != bgp->v_establish_wait)
d62a17ae 7948 vty_out(vty,
ea47320b
DL
7949 " Establish wait: %d seconds\n",
7950 bgp->v_establish_wait);
d62a17ae 7951
60466a63 7952 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7953 vty_out(vty,
7954 " First neighbor established: %s\n",
7955 bgp->update_delay_begin_time);
7956 vty_out(vty,
7957 " Delay in progress\n");
7958 } else {
7959 if (bgp->update_delay_over) {
d62a17ae 7960 vty_out(vty,
7961 " First neighbor established: %s\n",
7962 bgp->update_delay_begin_time);
7963 vty_out(vty,
ea47320b
DL
7964 " Best-paths resumed: %s\n",
7965 bgp->update_delay_end_time);
7966 vty_out(vty,
7967 " zebra update resumed: %s\n",
7968 bgp->update_delay_zebra_resume_time);
7969 vty_out(vty,
7970 " peers update resumed: %s\n",
7971 bgp->update_delay_peers_resume_time);
d62a17ae 7972 }
7973 }
7974 }
ea47320b 7975 }
d62a17ae 7976
ea47320b
DL
7977 if (use_json) {
7978 if (bgp_maxmed_onstartup_configured(bgp)
7979 && bgp->maxmed_active)
7980 json_object_boolean_true_add(
60466a63 7981 json, "maxMedOnStartup");
ea47320b
DL
7982 if (bgp->v_maxmed_admin)
7983 json_object_boolean_true_add(
60466a63 7984 json, "maxMedAdministrative");
d62a17ae 7985
ea47320b
DL
7986 json_object_int_add(
7987 json, "tableVersion",
60466a63 7988 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7989
60466a63
QY
7990 ents = bgp_table_count(bgp->rib[afi][safi]);
7991 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7992 json_object_int_add(
7993 json, "ribMemory",
7994 ents * sizeof(struct bgp_node));
d62a17ae 7995
ea47320b 7996 ents = listcount(bgp->peer);
60466a63
QY
7997 json_object_int_add(json, "peerCount", ents);
7998 json_object_int_add(json, "peerMemory",
7999 ents * sizeof(struct peer));
d62a17ae 8000
ea47320b
DL
8001 if ((ents = listcount(bgp->group))) {
8002 json_object_int_add(
60466a63 8003 json, "peerGroupCount", ents);
ea47320b
DL
8004 json_object_int_add(
8005 json, "peerGroupMemory",
996c9314
LB
8006 ents * sizeof(struct
8007 peer_group));
ea47320b 8008 }
d62a17ae 8009
ea47320b
DL
8010 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8011 BGP_CONFIG_DAMPENING))
8012 json_object_boolean_true_add(
60466a63 8013 json, "dampeningEnabled");
ea47320b
DL
8014 } else {
8015 if (bgp_maxmed_onstartup_configured(bgp)
8016 && bgp->maxmed_active)
d62a17ae 8017 vty_out(vty,
ea47320b
DL
8018 "Max-med on-startup active\n");
8019 if (bgp->v_maxmed_admin)
d62a17ae 8020 vty_out(vty,
ea47320b 8021 "Max-med administrative active\n");
d62a17ae 8022
60466a63
QY
8023 vty_out(vty, "BGP table version %" PRIu64 "\n",
8024 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8025
60466a63 8026 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8027 vty_out(vty,
8028 "RIB entries %ld, using %s of memory\n",
8029 ents,
996c9314
LB
8030 mtype_memstr(memstrbuf,
8031 sizeof(memstrbuf),
8032 ents * sizeof(struct
8033 bgp_node)));
ea47320b
DL
8034
8035 /* Peer related usage */
8036 ents = listcount(bgp->peer);
60466a63 8037 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8038 ents,
8039 mtype_memstr(
60466a63
QY
8040 memstrbuf, sizeof(memstrbuf),
8041 ents * sizeof(struct peer)));
ea47320b
DL
8042
8043 if ((ents = listcount(bgp->group)))
d62a17ae 8044 vty_out(vty,
ea47320b 8045 "Peer groups %ld, using %s of memory\n",
d62a17ae 8046 ents,
8047 mtype_memstr(
8048 memstrbuf,
8049 sizeof(memstrbuf),
996c9314
LB
8050 ents * sizeof(struct
8051 peer_group)));
d62a17ae 8052
ea47320b
DL
8053 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8054 BGP_CONFIG_DAMPENING))
60466a63 8055 vty_out(vty, "Dampening enabled.\n");
ea47320b 8056 vty_out(vty, "\n");
d62a17ae 8057
ea47320b
DL
8058 /* Subtract 8 here because 'Neighbor' is
8059 * 8 characters */
8060 vty_out(vty, "Neighbor");
60466a63
QY
8061 vty_out(vty, "%*s", max_neighbor_width - 8,
8062 " ");
ea47320b
DL
8063 vty_out(vty,
8064 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8065 }
ea47320b 8066 }
d62a17ae 8067
ea47320b 8068 count++;
d62a17ae 8069
ea47320b
DL
8070 if (use_json) {
8071 json_peer = json_object_new_object();
d62a17ae 8072
b4e9dcba
DD
8073 if (peer_dynamic_neighbor(peer)) {
8074 dn_count++;
60466a63
QY
8075 json_object_boolean_true_add(json_peer,
8076 "dynamicPeer");
b4e9dcba 8077 }
d62a17ae 8078
ea47320b 8079 if (peer->hostname)
60466a63 8080 json_object_string_add(json_peer, "hostname",
ea47320b 8081 peer->hostname);
d62a17ae 8082
ea47320b 8083 if (peer->domainname)
60466a63
QY
8084 json_object_string_add(json_peer, "domainname",
8085 peer->domainname);
d62a17ae 8086
60466a63 8087 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8088 json_object_int_add(json_peer, "version", 4);
60466a63 8089 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8090 PEER_TOTAL_RX(peer));
60466a63 8091 json_object_int_add(json_peer, "msgSent",
0112e9e0 8092 PEER_TOTAL_TX(peer));
ea47320b
DL
8093
8094 json_object_int_add(json_peer, "tableVersion",
8095 peer->version[afi][safi]);
8096 json_object_int_add(json_peer, "outq",
8097 peer->obuf->count);
8098 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8099 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8100 use_json, json_peer);
50e05855
AD
8101
8102 /*
8103 * Adding "pfxRcd" field to match with the corresponding
8104 * CLI. "prefixReceivedCount" will be deprecated in
8105 * future.
8106 */
60466a63
QY
8107 json_object_int_add(json_peer, "prefixReceivedCount",
8108 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8109 json_object_int_add(json_peer, "pfxRcd",
8110 peer->pcount[afi][pfx_rcd_safi]);
8111
8112 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8113 if (paf && PAF_SUBGRP(paf))
8114 json_object_int_add(json_peer,
8115 "pfxSnt",
8116 (PAF_SUBGRP(paf))->scount);
d62a17ae 8117
ea47320b 8118 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8119 json_object_string_add(json_peer, "state",
ea47320b 8120 "Idle (Admin)");
9199a725
TM
8121 else if (peer->afc_recv[afi][safi])
8122 json_object_string_add(
8123 json_peer, "state",
8124 lookup_msg(bgp_status_msg, peer->status,
8125 NULL));
60466a63
QY
8126 else if (CHECK_FLAG(peer->sflags,
8127 PEER_STATUS_PREFIX_OVERFLOW))
8128 json_object_string_add(json_peer, "state",
ea47320b
DL
8129 "Idle (PfxCt)");
8130 else
8131 json_object_string_add(
8132 json_peer, "state",
60466a63
QY
8133 lookup_msg(bgp_status_msg, peer->status,
8134 NULL));
ea47320b
DL
8135
8136 if (peer->conf_if)
60466a63 8137 json_object_string_add(json_peer, "idType",
ea47320b
DL
8138 "interface");
8139 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8140 json_object_string_add(json_peer, "idType",
8141 "ipv4");
ea47320b 8142 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8143 json_object_string_add(json_peer, "idType",
8144 "ipv6");
d62a17ae 8145
ea47320b
DL
8146 json_object_object_add(json_peers, peer->host,
8147 json_peer);
8148 } else {
8149 memset(dn_flag, '\0', sizeof(dn_flag));
8150 if (peer_dynamic_neighbor(peer)) {
8151 dn_count++;
8152 dn_flag[0] = '*';
8153 }
d62a17ae 8154
ea47320b 8155 if (peer->hostname
60466a63 8156 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8157 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8158 peer->hostname, peer->host);
ea47320b 8159 else
60466a63 8160 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8161
8162 /* pad the neighbor column with spaces */
8163 if (len < max_neighbor_width)
60466a63
QY
8164 vty_out(vty, "%*s", max_neighbor_width - len,
8165 " ");
ea47320b 8166
86a55b99 8167 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8168 peer->as, PEER_TOTAL_RX(peer),
8169 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8170 0, peer->obuf->count,
d62a17ae 8171 peer_uptime(peer->uptime, timebuf,
ea47320b 8172 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8173
ea47320b 8174 if (peer->status == Established)
2f8f4f10 8175 if (peer->afc_recv[afi][safi])
95077abf 8176 vty_out(vty, " %12ld",
a4d82a8a
PZ
8177 peer->pcount[afi]
8178 [pfx_rcd_safi]);
95077abf
DW
8179 else
8180 vty_out(vty, " NoNeg");
ea47320b 8181 else {
60466a63 8182 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8183 vty_out(vty, " Idle (Admin)");
60466a63
QY
8184 else if (CHECK_FLAG(
8185 peer->sflags,
8186 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8187 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8188 else
ea47320b 8189 vty_out(vty, " %12s",
60466a63
QY
8190 lookup_msg(bgp_status_msg,
8191 peer->status, NULL));
d62a17ae 8192 }
ea47320b 8193 vty_out(vty, "\n");
d62a17ae 8194 }
8195 }
f933309e 8196
d62a17ae 8197 if (use_json) {
8198 json_object_object_add(json, "peers", json_peers);
8199
8200 json_object_int_add(json, "totalPeers", count);
8201 json_object_int_add(json, "dynamicPeers", dn_count);
8202
57a9c8a8
DS
8203 bgp_show_bestpath_json(bgp, json);
8204
996c9314
LB
8205 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8206 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8207 json_object_free(json);
8208 } else {
8209 if (count)
8210 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8211 else {
d6ceaca3 8212 vty_out(vty, "No %s neighbor is configured\n",
8213 afi_safi_print(afi, safi));
d62a17ae 8214 }
b05a1c8b 8215
d6ceaca3 8216 if (dn_count) {
d62a17ae 8217 vty_out(vty, "* - dynamic neighbor\n");
8218 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8219 dn_count, bgp->dynamic_neighbors_limit);
8220 }
8221 }
1ff9a340 8222
d62a17ae 8223 return CMD_SUCCESS;
718e3744 8224}
8225
d62a17ae 8226static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8227 int safi, bool use_json,
d62a17ae 8228 json_object *json)
8229{
8230 int is_first = 1;
8231 int afi_wildcard = (afi == AFI_MAX);
8232 int safi_wildcard = (safi == SAFI_MAX);
8233 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8234 bool nbr_output = false;
d62a17ae 8235
8236 if (use_json && is_wildcard)
8237 vty_out(vty, "{\n");
8238 if (afi_wildcard)
8239 afi = 1; /* AFI_IP */
8240 while (afi < AFI_MAX) {
8241 if (safi_wildcard)
8242 safi = 1; /* SAFI_UNICAST */
8243 while (safi < SAFI_MAX) {
318cac96 8244 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8245 nbr_output = true;
d62a17ae 8246 if (is_wildcard) {
8247 /*
8248 * So limit output to those afi/safi
8249 * pairs that
8250 * actualy have something interesting in
8251 * them
8252 */
8253 if (use_json) {
8254 json = json_object_new_object();
8255
8256 if (!is_first)
8257 vty_out(vty, ",\n");
8258 else
8259 is_first = 0;
8260
8261 vty_out(vty, "\"%s\":",
8262 afi_safi_json(afi,
8263 safi));
8264 } else {
8265 vty_out(vty, "\n%s Summary:\n",
8266 afi_safi_print(afi,
8267 safi));
8268 }
8269 }
8270 bgp_show_summary(vty, bgp, afi, safi, use_json,
8271 json);
8272 }
8273 safi++;
d62a17ae 8274 if (!safi_wildcard)
8275 safi = SAFI_MAX;
8276 }
8277 afi++;
ee851c8c 8278 if (!afi_wildcard)
d62a17ae 8279 afi = AFI_MAX;
8280 }
8281
8282 if (use_json && is_wildcard)
8283 vty_out(vty, "}\n");
ca61fd25
DS
8284 else if (!nbr_output) {
8285 if (use_json)
8286 vty_out(vty, "{}\n");
8287 else
8288 vty_out(vty, "%% No BGP neighbors found\n");
8289 }
d62a17ae 8290}
8291
8292static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8293 safi_t safi, bool use_json)
d62a17ae 8294{
8295 struct listnode *node, *nnode;
8296 struct bgp *bgp;
8297 json_object *json = NULL;
8298 int is_first = 1;
9f049418 8299 bool nbr_output = false;
d62a17ae 8300
8301 if (use_json)
8302 vty_out(vty, "{\n");
8303
8304 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8305 nbr_output = true;
d62a17ae 8306 if (use_json) {
8307 json = json_object_new_object();
8308
8309 if (!is_first)
8310 vty_out(vty, ",\n");
8311 else
8312 is_first = 0;
8313
8314 vty_out(vty, "\"%s\":",
8315 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8316 ? VRF_DEFAULT_NAME
d62a17ae 8317 : bgp->name);
8318 } else {
8319 vty_out(vty, "\nInstance %s:\n",
8320 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8321 ? VRF_DEFAULT_NAME
d62a17ae 8322 : bgp->name);
8323 }
8324 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8325 }
8326
8327 if (use_json)
8328 vty_out(vty, "}\n");
9f049418
DS
8329 else if (!nbr_output)
8330 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8331}
8332
8333int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8334 safi_t safi, bool use_json)
d62a17ae 8335{
8336 struct bgp *bgp;
8337
8338 if (name) {
8339 if (strmatch(name, "all")) {
8340 bgp_show_all_instances_summary_vty(vty, afi, safi,
8341 use_json);
8342 return CMD_SUCCESS;
8343 } else {
8344 bgp = bgp_lookup_by_name(name);
8345
8346 if (!bgp) {
8347 if (use_json)
8348 vty_out(vty, "{}\n");
8349 else
8350 vty_out(vty,
ca61fd25 8351 "%% BGP instance not found\n");
d62a17ae 8352 return CMD_WARNING;
8353 }
8354
8355 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8356 NULL);
8357 return CMD_SUCCESS;
8358 }
8359 }
8360
8361 bgp = bgp_get_default();
8362
8363 if (bgp)
8364 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8365 else {
ca61fd25
DS
8366 if (use_json)
8367 vty_out(vty, "{}\n");
8368 else
8369 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8370 return CMD_WARNING;
8371 }
d62a17ae 8372
8373 return CMD_SUCCESS;
4fb25c53
DW
8374}
8375
716b2d8a 8376/* `show [ip] bgp summary' commands. */
47fc97cc 8377DEFUN (show_ip_bgp_summary,
718e3744 8378 show_ip_bgp_summary_cmd,
dd6bd0f1 8379 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8380 SHOW_STR
8381 IP_STR
8382 BGP_STR
8386ac43 8383 BGP_INSTANCE_HELP_STR
46f296b4 8384 BGP_AFI_HELP_STR
dd6bd0f1 8385 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8386 "Summary of BGP neighbor status\n"
9973d184 8387 JSON_STR)
718e3744 8388{
d62a17ae 8389 char *vrf = NULL;
8390 afi_t afi = AFI_MAX;
8391 safi_t safi = SAFI_MAX;
8392
8393 int idx = 0;
8394
8395 /* show [ip] bgp */
8396 if (argv_find(argv, argc, "ip", &idx))
8397 afi = AFI_IP;
9a8bdf1c
PG
8398 /* [<vrf> VIEWVRFNAME] */
8399 if (argv_find(argv, argc, "vrf", &idx)) {
8400 vrf = argv[idx + 1]->arg;
8401 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8402 vrf = NULL;
8403 } else if (argv_find(argv, argc, "view", &idx))
8404 /* [<view> VIEWVRFNAME] */
8405 vrf = argv[idx + 1]->arg;
d62a17ae 8406 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8407 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8408 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8409 }
8410
9f049418 8411 bool uj = use_json(argc, argv);
d62a17ae 8412
8413 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8414}
8415
8416const char *afi_safi_print(afi_t afi, safi_t safi)
8417{
8418 if (afi == AFI_IP && safi == SAFI_UNICAST)
8419 return "IPv4 Unicast";
8420 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8421 return "IPv4 Multicast";
8422 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8423 return "IPv4 Labeled Unicast";
8424 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8425 return "IPv4 VPN";
8426 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8427 return "IPv4 Encap";
7c40bf39 8428 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8429 return "IPv4 Flowspec";
d62a17ae 8430 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8431 return "IPv6 Unicast";
8432 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8433 return "IPv6 Multicast";
8434 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8435 return "IPv6 Labeled Unicast";
8436 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8437 return "IPv6 VPN";
8438 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8439 return "IPv6 Encap";
7c40bf39 8440 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8441 return "IPv6 Flowspec";
d62a17ae 8442 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8443 return "L2VPN EVPN";
8444 else
8445 return "Unknown";
538621f2 8446}
8447
b9f77ec8
DS
8448/*
8449 * Please note that we have intentionally camelCased
8450 * the return strings here. So if you want
8451 * to use this function, please ensure you
8452 * are doing this within json output
8453 */
d62a17ae 8454const char *afi_safi_json(afi_t afi, safi_t safi)
8455{
8456 if (afi == AFI_IP && safi == SAFI_UNICAST)
8457 return "ipv4Unicast";
8458 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8459 return "ipv4Multicast";
8460 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8461 return "ipv4LabeledUnicast";
8462 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8463 return "ipv4Vpn";
8464 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8465 return "ipv4Encap";
7c40bf39 8466 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8467 return "ipv4Flowspec";
d62a17ae 8468 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8469 return "ipv6Unicast";
8470 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8471 return "ipv6Multicast";
8472 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8473 return "ipv6LabeledUnicast";
8474 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8475 return "ipv6Vpn";
8476 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8477 return "ipv6Encap";
7c40bf39 8478 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8479 return "ipv6Flowspec";
d62a17ae 8480 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8481 return "l2VpnEvpn";
8482 else
8483 return "Unknown";
27162734
LB
8484}
8485
718e3744 8486/* Show BGP peer's information. */
d62a17ae 8487enum show_type { show_all, show_peer };
8488
8489static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8490 afi_t afi, safi_t safi,
d7c0a89a
QY
8491 uint16_t adv_smcap, uint16_t adv_rmcap,
8492 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8493 bool use_json, json_object *json_pref)
d62a17ae 8494{
8495 /* Send-Mode */
8496 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8497 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8498 if (use_json) {
8499 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8500 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8501 json_object_string_add(json_pref, "sendMode",
8502 "advertisedAndReceived");
8503 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8504 json_object_string_add(json_pref, "sendMode",
8505 "advertised");
8506 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8507 json_object_string_add(json_pref, "sendMode",
8508 "received");
8509 } else {
8510 vty_out(vty, " Send-mode: ");
8511 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8512 vty_out(vty, "advertised");
8513 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8514 vty_out(vty, "%sreceived",
8515 CHECK_FLAG(p->af_cap[afi][safi],
8516 adv_smcap)
8517 ? ", "
8518 : "");
8519 vty_out(vty, "\n");
8520 }
8521 }
8522
8523 /* Receive-Mode */
8524 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8525 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8526 if (use_json) {
8527 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8528 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8529 json_object_string_add(json_pref, "recvMode",
8530 "advertisedAndReceived");
8531 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8532 json_object_string_add(json_pref, "recvMode",
8533 "advertised");
8534 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8535 json_object_string_add(json_pref, "recvMode",
8536 "received");
8537 } else {
8538 vty_out(vty, " Receive-mode: ");
8539 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8540 vty_out(vty, "advertised");
8541 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8542 vty_out(vty, "%sreceived",
8543 CHECK_FLAG(p->af_cap[afi][safi],
8544 adv_rmcap)
8545 ? ", "
8546 : "");
8547 vty_out(vty, "\n");
8548 }
8549 }
8550}
8551
8552static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8553 safi_t safi, bool use_json,
d62a17ae 8554 json_object *json_neigh)
8555{
0291c246
MK
8556 struct bgp_filter *filter;
8557 struct peer_af *paf;
8558 char orf_pfx_name[BUFSIZ];
8559 int orf_pfx_count;
8560 json_object *json_af = NULL;
8561 json_object *json_prefA = NULL;
8562 json_object *json_prefB = NULL;
8563 json_object *json_addr = NULL;
d62a17ae 8564
8565 if (use_json) {
8566 json_addr = json_object_new_object();
8567 json_af = json_object_new_object();
8568 filter = &p->filter[afi][safi];
8569
8570 if (peer_group_active(p))
8571 json_object_string_add(json_addr, "peerGroupMember",
8572 p->group->name);
8573
8574 paf = peer_af_find(p, afi, safi);
8575 if (paf && PAF_SUBGRP(paf)) {
8576 json_object_int_add(json_addr, "updateGroupId",
8577 PAF_UPDGRP(paf)->id);
8578 json_object_int_add(json_addr, "subGroupId",
8579 PAF_SUBGRP(paf)->id);
8580 json_object_int_add(json_addr, "packetQueueLength",
8581 bpacket_queue_virtual_length(paf));
8582 }
8583
8584 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8585 || CHECK_FLAG(p->af_cap[afi][safi],
8586 PEER_CAP_ORF_PREFIX_SM_RCV)
8587 || CHECK_FLAG(p->af_cap[afi][safi],
8588 PEER_CAP_ORF_PREFIX_RM_ADV)
8589 || CHECK_FLAG(p->af_cap[afi][safi],
8590 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8591 json_object_int_add(json_af, "orfType",
8592 ORF_TYPE_PREFIX);
8593 json_prefA = json_object_new_object();
8594 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8595 PEER_CAP_ORF_PREFIX_SM_ADV,
8596 PEER_CAP_ORF_PREFIX_RM_ADV,
8597 PEER_CAP_ORF_PREFIX_SM_RCV,
8598 PEER_CAP_ORF_PREFIX_RM_RCV,
8599 use_json, json_prefA);
8600 json_object_object_add(json_af, "orfPrefixList",
8601 json_prefA);
8602 }
8603
8604 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8611 json_object_int_add(json_af, "orfOldType",
8612 ORF_TYPE_PREFIX_OLD);
8613 json_prefB = json_object_new_object();
8614 bgp_show_peer_afi_orf_cap(
8615 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8616 PEER_CAP_ORF_PREFIX_RM_ADV,
8617 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8618 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8619 json_prefB);
8620 json_object_object_add(json_af, "orfOldPrefixList",
8621 json_prefB);
8622 }
8623
8624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_SM_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_ADV)
8631 || CHECK_FLAG(p->af_cap[afi][safi],
8632 PEER_CAP_ORF_PREFIX_RM_RCV)
8633 || CHECK_FLAG(p->af_cap[afi][safi],
8634 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8635 json_object_object_add(json_addr, "afDependentCap",
8636 json_af);
8637 else
8638 json_object_free(json_af);
8639
8640 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8641 orf_pfx_count = prefix_bgp_show_prefix_list(
8642 NULL, afi, orf_pfx_name, use_json);
8643
8644 if (CHECK_FLAG(p->af_sflags[afi][safi],
8645 PEER_STATUS_ORF_PREFIX_SEND)
8646 || orf_pfx_count) {
8647 if (CHECK_FLAG(p->af_sflags[afi][safi],
8648 PEER_STATUS_ORF_PREFIX_SEND))
8649 json_object_boolean_true_add(json_neigh,
8650 "orfSent");
8651 if (orf_pfx_count)
8652 json_object_int_add(json_addr, "orfRecvCounter",
8653 orf_pfx_count);
8654 }
8655 if (CHECK_FLAG(p->af_sflags[afi][safi],
8656 PEER_STATUS_ORF_WAIT_REFRESH))
8657 json_object_string_add(
8658 json_addr, "orfFirstUpdate",
8659 "deferredUntilORFOrRouteRefreshRecvd");
8660
8661 if (CHECK_FLAG(p->af_flags[afi][safi],
8662 PEER_FLAG_REFLECTOR_CLIENT))
8663 json_object_boolean_true_add(json_addr,
8664 "routeReflectorClient");
8665 if (CHECK_FLAG(p->af_flags[afi][safi],
8666 PEER_FLAG_RSERVER_CLIENT))
8667 json_object_boolean_true_add(json_addr,
8668 "routeServerClient");
8669 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8670 json_object_boolean_true_add(json_addr,
8671 "inboundSoftConfigPermit");
8672
8673 if (CHECK_FLAG(p->af_flags[afi][safi],
8674 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8675 json_object_boolean_true_add(
8676 json_addr,
8677 "privateAsNumsAllReplacedInUpdatesToNbr");
8678 else if (CHECK_FLAG(p->af_flags[afi][safi],
8679 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8680 json_object_boolean_true_add(
8681 json_addr,
8682 "privateAsNumsReplacedInUpdatesToNbr");
8683 else if (CHECK_FLAG(p->af_flags[afi][safi],
8684 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8685 json_object_boolean_true_add(
8686 json_addr,
8687 "privateAsNumsAllRemovedInUpdatesToNbr");
8688 else if (CHECK_FLAG(p->af_flags[afi][safi],
8689 PEER_FLAG_REMOVE_PRIVATE_AS))
8690 json_object_boolean_true_add(
8691 json_addr,
8692 "privateAsNumsRemovedInUpdatesToNbr");
8693
dcc68b5e
MS
8694 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8695 json_object_boolean_true_add(
8696 json_addr,
8697 bgp_addpath_names(p->addpath_type[afi][safi])
8698 ->type_json_name);
d62a17ae 8699
8700 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8701 json_object_string_add(json_addr,
8702 "overrideASNsInOutboundUpdates",
8703 "ifAspathEqualRemoteAs");
8704
8705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8706 || CHECK_FLAG(p->af_flags[afi][safi],
8707 PEER_FLAG_FORCE_NEXTHOP_SELF))
8708 json_object_boolean_true_add(json_addr,
8709 "routerAlwaysNextHop");
8710 if (CHECK_FLAG(p->af_flags[afi][safi],
8711 PEER_FLAG_AS_PATH_UNCHANGED))
8712 json_object_boolean_true_add(
8713 json_addr, "unchangedAsPathPropogatedToNbr");
8714 if (CHECK_FLAG(p->af_flags[afi][safi],
8715 PEER_FLAG_NEXTHOP_UNCHANGED))
8716 json_object_boolean_true_add(
8717 json_addr, "unchangedNextHopPropogatedToNbr");
8718 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8719 json_object_boolean_true_add(
8720 json_addr, "unchangedMedPropogatedToNbr");
8721 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8722 || CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8724 if (CHECK_FLAG(p->af_flags[afi][safi],
8725 PEER_FLAG_SEND_COMMUNITY)
8726 && CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_SEND_EXT_COMMUNITY))
8728 json_object_string_add(json_addr,
8729 "commAttriSentToNbr",
8730 "extendedAndStandard");
8731 else if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_SEND_EXT_COMMUNITY))
8733 json_object_string_add(json_addr,
8734 "commAttriSentToNbr",
8735 "extended");
8736 else
8737 json_object_string_add(json_addr,
8738 "commAttriSentToNbr",
8739 "standard");
8740 }
8741 if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_DEFAULT_ORIGINATE)) {
8743 if (p->default_rmap[afi][safi].name)
8744 json_object_string_add(
8745 json_addr, "defaultRouteMap",
8746 p->default_rmap[afi][safi].name);
8747
8748 if (paf && PAF_SUBGRP(paf)
8749 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8750 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8751 json_object_boolean_true_add(json_addr,
8752 "defaultSent");
8753 else
8754 json_object_boolean_true_add(json_addr,
8755 "defaultNotSent");
8756 }
8757
dff8f48d 8758 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8759 if (is_evpn_enabled())
60466a63
QY
8760 json_object_boolean_true_add(
8761 json_addr, "advertiseAllVnis");
dff8f48d
MK
8762 }
8763
d62a17ae 8764 if (filter->plist[FILTER_IN].name
8765 || filter->dlist[FILTER_IN].name
8766 || filter->aslist[FILTER_IN].name
8767 || filter->map[RMAP_IN].name)
8768 json_object_boolean_true_add(json_addr,
8769 "inboundPathPolicyConfig");
8770 if (filter->plist[FILTER_OUT].name
8771 || filter->dlist[FILTER_OUT].name
8772 || filter->aslist[FILTER_OUT].name
8773 || filter->map[RMAP_OUT].name || filter->usmap.name)
8774 json_object_boolean_true_add(
8775 json_addr, "outboundPathPolicyConfig");
8776
8777 /* prefix-list */
8778 if (filter->plist[FILTER_IN].name)
8779 json_object_string_add(json_addr,
8780 "incomingUpdatePrefixFilterList",
8781 filter->plist[FILTER_IN].name);
8782 if (filter->plist[FILTER_OUT].name)
8783 json_object_string_add(json_addr,
8784 "outgoingUpdatePrefixFilterList",
8785 filter->plist[FILTER_OUT].name);
8786
8787 /* distribute-list */
8788 if (filter->dlist[FILTER_IN].name)
8789 json_object_string_add(
8790 json_addr, "incomingUpdateNetworkFilterList",
8791 filter->dlist[FILTER_IN].name);
8792 if (filter->dlist[FILTER_OUT].name)
8793 json_object_string_add(
8794 json_addr, "outgoingUpdateNetworkFilterList",
8795 filter->dlist[FILTER_OUT].name);
8796
8797 /* filter-list. */
8798 if (filter->aslist[FILTER_IN].name)
8799 json_object_string_add(json_addr,
8800 "incomingUpdateAsPathFilterList",
8801 filter->aslist[FILTER_IN].name);
8802 if (filter->aslist[FILTER_OUT].name)
8803 json_object_string_add(json_addr,
8804 "outgoingUpdateAsPathFilterList",
8805 filter->aslist[FILTER_OUT].name);
8806
8807 /* route-map. */
8808 if (filter->map[RMAP_IN].name)
8809 json_object_string_add(
8810 json_addr, "routeMapForIncomingAdvertisements",
8811 filter->map[RMAP_IN].name);
8812 if (filter->map[RMAP_OUT].name)
8813 json_object_string_add(
8814 json_addr, "routeMapForOutgoingAdvertisements",
8815 filter->map[RMAP_OUT].name);
8816
8817 /* unsuppress-map */
8818 if (filter->usmap.name)
8819 json_object_string_add(json_addr,
8820 "selectiveUnsuppressRouteMap",
8821 filter->usmap.name);
8822
8823 /* Receive prefix count */
8824 json_object_int_add(json_addr, "acceptedPrefixCounter",
8825 p->pcount[afi][safi]);
50e05855
AD
8826 if (paf && PAF_SUBGRP(paf))
8827 json_object_int_add(json_addr, "sentPrefixCounter",
8828 (PAF_SUBGRP(paf))->scount);
d62a17ae 8829
8830 /* Maximum prefix */
8831 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8832 json_object_int_add(json_addr, "prefixAllowedMax",
8833 p->pmax[afi][safi]);
8834 if (CHECK_FLAG(p->af_flags[afi][safi],
8835 PEER_FLAG_MAX_PREFIX_WARNING))
8836 json_object_boolean_true_add(
8837 json_addr, "prefixAllowedMaxWarning");
8838 json_object_int_add(json_addr,
8839 "prefixAllowedWarningThresh",
8840 p->pmax_threshold[afi][safi]);
8841 if (p->pmax_restart[afi][safi])
8842 json_object_int_add(
8843 json_addr,
8844 "prefixAllowedRestartIntervalMsecs",
8845 p->pmax_restart[afi][safi] * 60000);
8846 }
8847 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8848 json_addr);
8849
8850 } else {
8851 filter = &p->filter[afi][safi];
8852
8853 vty_out(vty, " For address family: %s\n",
8854 afi_safi_print(afi, safi));
8855
8856 if (peer_group_active(p))
8857 vty_out(vty, " %s peer-group member\n",
8858 p->group->name);
8859
8860 paf = peer_af_find(p, afi, safi);
8861 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8862 vty_out(vty, " Update group %" PRIu64
8863 ", subgroup %" PRIu64 "\n",
d62a17ae 8864 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8865 vty_out(vty, " Packet Queue length %d\n",
8866 bpacket_queue_virtual_length(paf));
8867 } else {
8868 vty_out(vty, " Not part of any update group\n");
8869 }
8870 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_SM_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8875 || CHECK_FLAG(p->af_cap[afi][safi],
8876 PEER_CAP_ORF_PREFIX_RM_ADV)
8877 || CHECK_FLAG(p->af_cap[afi][safi],
8878 PEER_CAP_ORF_PREFIX_RM_RCV)
8879 || CHECK_FLAG(p->af_cap[afi][safi],
8880 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8881 vty_out(vty, " AF-dependant capabilities:\n");
8882
8883 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8884 || CHECK_FLAG(p->af_cap[afi][safi],
8885 PEER_CAP_ORF_PREFIX_SM_RCV)
8886 || CHECK_FLAG(p->af_cap[afi][safi],
8887 PEER_CAP_ORF_PREFIX_RM_ADV)
8888 || CHECK_FLAG(p->af_cap[afi][safi],
8889 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8890 vty_out(vty,
8891 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8892 ORF_TYPE_PREFIX);
8893 bgp_show_peer_afi_orf_cap(
8894 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8895 PEER_CAP_ORF_PREFIX_RM_ADV,
8896 PEER_CAP_ORF_PREFIX_SM_RCV,
8897 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8898 }
8899 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8900 || CHECK_FLAG(p->af_cap[afi][safi],
8901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8902 || CHECK_FLAG(p->af_cap[afi][safi],
8903 PEER_CAP_ORF_PREFIX_RM_ADV)
8904 || CHECK_FLAG(p->af_cap[afi][safi],
8905 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8906 vty_out(vty,
8907 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8908 ORF_TYPE_PREFIX_OLD);
8909 bgp_show_peer_afi_orf_cap(
8910 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8911 PEER_CAP_ORF_PREFIX_RM_ADV,
8912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8913 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8914 }
8915
8916 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8917 orf_pfx_count = prefix_bgp_show_prefix_list(
8918 NULL, afi, orf_pfx_name, use_json);
8919
8920 if (CHECK_FLAG(p->af_sflags[afi][safi],
8921 PEER_STATUS_ORF_PREFIX_SEND)
8922 || orf_pfx_count) {
8923 vty_out(vty, " Outbound Route Filter (ORF):");
8924 if (CHECK_FLAG(p->af_sflags[afi][safi],
8925 PEER_STATUS_ORF_PREFIX_SEND))
8926 vty_out(vty, " sent;");
8927 if (orf_pfx_count)
8928 vty_out(vty, " received (%d entries)",
8929 orf_pfx_count);
8930 vty_out(vty, "\n");
8931 }
8932 if (CHECK_FLAG(p->af_sflags[afi][safi],
8933 PEER_STATUS_ORF_WAIT_REFRESH))
8934 vty_out(vty,
8935 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8936
8937 if (CHECK_FLAG(p->af_flags[afi][safi],
8938 PEER_FLAG_REFLECTOR_CLIENT))
8939 vty_out(vty, " Route-Reflector Client\n");
8940 if (CHECK_FLAG(p->af_flags[afi][safi],
8941 PEER_FLAG_RSERVER_CLIENT))
8942 vty_out(vty, " Route-Server Client\n");
8943 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8944 vty_out(vty,
8945 " Inbound soft reconfiguration allowed\n");
8946
8947 if (CHECK_FLAG(p->af_flags[afi][safi],
8948 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8949 vty_out(vty,
8950 " Private AS numbers (all) replaced in updates to this neighbor\n");
8951 else if (CHECK_FLAG(p->af_flags[afi][safi],
8952 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8953 vty_out(vty,
8954 " Private AS numbers replaced in updates to this neighbor\n");
8955 else if (CHECK_FLAG(p->af_flags[afi][safi],
8956 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8957 vty_out(vty,
8958 " Private AS numbers (all) removed in updates to this neighbor\n");
8959 else if (CHECK_FLAG(p->af_flags[afi][safi],
8960 PEER_FLAG_REMOVE_PRIVATE_AS))
8961 vty_out(vty,
8962 " Private AS numbers removed in updates to this neighbor\n");
8963
dcc68b5e
MS
8964 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8965 vty_out(vty, " %s\n",
8966 bgp_addpath_names(p->addpath_type[afi][safi])
8967 ->human_description);
d62a17ae 8968
8969 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8970 vty_out(vty,
8971 " Override ASNs in outbound updates if aspath equals remote-as\n");
8972
8973 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8974 || CHECK_FLAG(p->af_flags[afi][safi],
8975 PEER_FLAG_FORCE_NEXTHOP_SELF))
8976 vty_out(vty, " NEXT_HOP is always this router\n");
8977 if (CHECK_FLAG(p->af_flags[afi][safi],
8978 PEER_FLAG_AS_PATH_UNCHANGED))
8979 vty_out(vty,
8980 " AS_PATH is propagated unchanged to this neighbor\n");
8981 if (CHECK_FLAG(p->af_flags[afi][safi],
8982 PEER_FLAG_NEXTHOP_UNCHANGED))
8983 vty_out(vty,
8984 " NEXT_HOP is propagated unchanged to this neighbor\n");
8985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8986 vty_out(vty,
8987 " MED is propagated unchanged to this neighbor\n");
8988 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8989 || CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_EXT_COMMUNITY)
8991 || CHECK_FLAG(p->af_flags[afi][safi],
8992 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8993 vty_out(vty,
8994 " Community attribute sent to this neighbor");
8995 if (CHECK_FLAG(p->af_flags[afi][safi],
8996 PEER_FLAG_SEND_COMMUNITY)
8997 && CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_SEND_EXT_COMMUNITY)
8999 && CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_SEND_LARGE_COMMUNITY))
9001 vty_out(vty, "(all)\n");
9002 else if (CHECK_FLAG(p->af_flags[afi][safi],
9003 PEER_FLAG_SEND_LARGE_COMMUNITY))
9004 vty_out(vty, "(large)\n");
9005 else if (CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_SEND_EXT_COMMUNITY))
9007 vty_out(vty, "(extended)\n");
9008 else
9009 vty_out(vty, "(standard)\n");
9010 }
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_DEFAULT_ORIGINATE)) {
9013 vty_out(vty, " Default information originate,");
9014
9015 if (p->default_rmap[afi][safi].name)
9016 vty_out(vty, " default route-map %s%s,",
9017 p->default_rmap[afi][safi].map ? "*"
9018 : "",
9019 p->default_rmap[afi][safi].name);
9020 if (paf && PAF_SUBGRP(paf)
9021 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9022 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9023 vty_out(vty, " default sent\n");
9024 else
9025 vty_out(vty, " default not sent\n");
9026 }
9027
dff8f48d
MK
9028 /* advertise-vni-all */
9029 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9030 if (is_evpn_enabled())
dff8f48d
MK
9031 vty_out(vty, " advertise-all-vni\n");
9032 }
9033
d62a17ae 9034 if (filter->plist[FILTER_IN].name
9035 || filter->dlist[FILTER_IN].name
9036 || filter->aslist[FILTER_IN].name
9037 || filter->map[RMAP_IN].name)
9038 vty_out(vty, " Inbound path policy configured\n");
9039 if (filter->plist[FILTER_OUT].name
9040 || filter->dlist[FILTER_OUT].name
9041 || filter->aslist[FILTER_OUT].name
9042 || filter->map[RMAP_OUT].name || filter->usmap.name)
9043 vty_out(vty, " Outbound path policy configured\n");
9044
9045 /* prefix-list */
9046 if (filter->plist[FILTER_IN].name)
9047 vty_out(vty,
9048 " Incoming update prefix filter list is %s%s\n",
9049 filter->plist[FILTER_IN].plist ? "*" : "",
9050 filter->plist[FILTER_IN].name);
9051 if (filter->plist[FILTER_OUT].name)
9052 vty_out(vty,
9053 " Outgoing update prefix filter list is %s%s\n",
9054 filter->plist[FILTER_OUT].plist ? "*" : "",
9055 filter->plist[FILTER_OUT].name);
9056
9057 /* distribute-list */
9058 if (filter->dlist[FILTER_IN].name)
9059 vty_out(vty,
9060 " Incoming update network filter list is %s%s\n",
9061 filter->dlist[FILTER_IN].alist ? "*" : "",
9062 filter->dlist[FILTER_IN].name);
9063 if (filter->dlist[FILTER_OUT].name)
9064 vty_out(vty,
9065 " Outgoing update network filter list is %s%s\n",
9066 filter->dlist[FILTER_OUT].alist ? "*" : "",
9067 filter->dlist[FILTER_OUT].name);
9068
9069 /* filter-list. */
9070 if (filter->aslist[FILTER_IN].name)
9071 vty_out(vty,
9072 " Incoming update AS path filter list is %s%s\n",
9073 filter->aslist[FILTER_IN].aslist ? "*" : "",
9074 filter->aslist[FILTER_IN].name);
9075 if (filter->aslist[FILTER_OUT].name)
9076 vty_out(vty,
9077 " Outgoing update AS path filter list is %s%s\n",
9078 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9079 filter->aslist[FILTER_OUT].name);
9080
9081 /* route-map. */
9082 if (filter->map[RMAP_IN].name)
9083 vty_out(vty,
9084 " Route map for incoming advertisements is %s%s\n",
9085 filter->map[RMAP_IN].map ? "*" : "",
9086 filter->map[RMAP_IN].name);
9087 if (filter->map[RMAP_OUT].name)
9088 vty_out(vty,
9089 " Route map for outgoing advertisements is %s%s\n",
9090 filter->map[RMAP_OUT].map ? "*" : "",
9091 filter->map[RMAP_OUT].name);
9092
9093 /* unsuppress-map */
9094 if (filter->usmap.name)
9095 vty_out(vty,
9096 " Route map for selective unsuppress is %s%s\n",
9097 filter->usmap.map ? "*" : "",
9098 filter->usmap.name);
9099
9100 /* Receive prefix count */
9101 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9102
9103 /* Maximum prefix */
9104 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9105 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9106 p->pmax[afi][safi],
9107 CHECK_FLAG(p->af_flags[afi][safi],
9108 PEER_FLAG_MAX_PREFIX_WARNING)
9109 ? " (warning-only)"
9110 : "");
9111 vty_out(vty, " Threshold for warning message %d%%",
9112 p->pmax_threshold[afi][safi]);
9113 if (p->pmax_restart[afi][safi])
9114 vty_out(vty, ", restart interval %d min",
9115 p->pmax_restart[afi][safi]);
9116 vty_out(vty, "\n");
9117 }
9118
9119 vty_out(vty, "\n");
9120 }
9121}
9122
9f049418 9123static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9124 json_object *json)
718e3744 9125{
d62a17ae 9126 struct bgp *bgp;
9127 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9128 char timebuf[BGP_UPTIME_LEN];
9129 char dn_flag[2];
9130 const char *subcode_str;
9131 const char *code_str;
9132 afi_t afi;
9133 safi_t safi;
d7c0a89a
QY
9134 uint16_t i;
9135 uint8_t *msg;
d62a17ae 9136 json_object *json_neigh = NULL;
9137 time_t epoch_tbuf;
718e3744 9138
d62a17ae 9139 bgp = p->bgp;
9140
9141 if (use_json)
9142 json_neigh = json_object_new_object();
9143
9144 memset(dn_flag, '\0', sizeof(dn_flag));
9145 if (!p->conf_if && peer_dynamic_neighbor(p))
9146 dn_flag[0] = '*';
9147
9148 if (!use_json) {
9149 if (p->conf_if) /* Configured interface name. */
9150 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9151 BGP_PEER_SU_UNSPEC(p)
9152 ? "None"
9153 : sockunion2str(&p->su, buf,
9154 SU_ADDRSTRLEN));
9155 else /* Configured IP address. */
9156 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9157 p->host);
9158 }
9159
9160 if (use_json) {
9161 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9162 json_object_string_add(json_neigh, "bgpNeighborAddr",
9163 "none");
9164 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9165 json_object_string_add(
9166 json_neigh, "bgpNeighborAddr",
9167 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9168
9169 json_object_int_add(json_neigh, "remoteAs", p->as);
9170
9171 if (p->change_local_as)
9172 json_object_int_add(json_neigh, "localAs",
9173 p->change_local_as);
9174 else
9175 json_object_int_add(json_neigh, "localAs", p->local_as);
9176
9177 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9178 json_object_boolean_true_add(json_neigh,
9179 "localAsNoPrepend");
9180
9181 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9182 json_object_boolean_true_add(json_neigh,
9183 "localAsReplaceAs");
9184 } else {
9185 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9186 || (p->as_type == AS_INTERNAL))
9187 vty_out(vty, "remote AS %u, ", p->as);
9188 else
9189 vty_out(vty, "remote AS Unspecified, ");
9190 vty_out(vty, "local AS %u%s%s, ",
9191 p->change_local_as ? p->change_local_as : p->local_as,
9192 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9193 ? " no-prepend"
9194 : "",
9195 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9196 ? " replace-as"
9197 : "");
9198 }
9199 /* peer type internal, external, confed-internal or confed-external */
9200 if (p->as == p->local_as) {
9201 if (use_json) {
9202 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9203 json_object_boolean_true_add(
9204 json_neigh, "nbrConfedInternalLink");
9205 else
9206 json_object_boolean_true_add(json_neigh,
9207 "nbrInternalLink");
9208 } else {
9209 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9210 vty_out(vty, "confed-internal link\n");
9211 else
9212 vty_out(vty, "internal link\n");
9213 }
9214 } else {
9215 if (use_json) {
9216 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9217 json_object_boolean_true_add(
9218 json_neigh, "nbrConfedExternalLink");
9219 else
9220 json_object_boolean_true_add(json_neigh,
9221 "nbrExternalLink");
9222 } else {
9223 if (bgp_confederation_peers_check(bgp, p->as))
9224 vty_out(vty, "confed-external link\n");
9225 else
9226 vty_out(vty, "external link\n");
9227 }
9228 }
9229
9230 /* Description. */
9231 if (p->desc) {
9232 if (use_json)
9233 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9234 else
9235 vty_out(vty, " Description: %s\n", p->desc);
9236 }
9237
9238 if (p->hostname) {
9239 if (use_json) {
9240 if (p->hostname)
9241 json_object_string_add(json_neigh, "hostname",
9242 p->hostname);
9243
9244 if (p->domainname)
9245 json_object_string_add(json_neigh, "domainname",
9246 p->domainname);
9247 } else {
9248 if (p->domainname && (p->domainname[0] != '\0'))
9249 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9250 p->domainname);
9251 else
9252 vty_out(vty, "Hostname: %s\n", p->hostname);
9253 }
9254 }
9255
9256 /* Peer-group */
9257 if (p->group) {
9258 if (use_json) {
9259 json_object_string_add(json_neigh, "peerGroup",
9260 p->group->name);
9261
9262 if (dn_flag[0]) {
9263 struct prefix prefix, *range = NULL;
9264
9265 sockunion2hostprefix(&(p->su), &prefix);
9266 range = peer_group_lookup_dynamic_neighbor_range(
9267 p->group, &prefix);
9268
9269 if (range) {
9270 prefix2str(range, buf1, sizeof(buf1));
9271 json_object_string_add(
9272 json_neigh,
9273 "peerSubnetRangeGroup", buf1);
9274 }
9275 }
9276 } else {
9277 vty_out(vty,
9278 " Member of peer-group %s for session parameters\n",
9279 p->group->name);
9280
9281 if (dn_flag[0]) {
9282 struct prefix prefix, *range = NULL;
9283
9284 sockunion2hostprefix(&(p->su), &prefix);
9285 range = peer_group_lookup_dynamic_neighbor_range(
9286 p->group, &prefix);
9287
9288 if (range) {
9289 prefix2str(range, buf1, sizeof(buf1));
9290 vty_out(vty,
9291 " Belongs to the subnet range group: %s\n",
9292 buf1);
9293 }
9294 }
9295 }
9296 }
9297
9298 if (use_json) {
9299 /* Administrative shutdown. */
9300 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9301 json_object_boolean_true_add(json_neigh,
9302 "adminShutDown");
9303
9304 /* BGP Version. */
9305 json_object_int_add(json_neigh, "bgpVersion", 4);
9306 json_object_string_add(
9307 json_neigh, "remoteRouterId",
9308 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9309 json_object_string_add(
9310 json_neigh, "localRouterId",
9311 inet_ntop(AF_INET, &bgp->router_id, buf1,
9312 sizeof(buf1)));
d62a17ae 9313
9314 /* Confederation */
9315 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9316 && bgp_confederation_peers_check(bgp, p->as))
9317 json_object_boolean_true_add(json_neigh,
9318 "nbrCommonAdmin");
9319
9320 /* Status. */
9321 json_object_string_add(
9322 json_neigh, "bgpState",
9323 lookup_msg(bgp_status_msg, p->status, NULL));
9324
9325 if (p->status == Established) {
9326 time_t uptime;
d62a17ae 9327
9328 uptime = bgp_clock();
9329 uptime -= p->uptime;
d62a17ae 9330 epoch_tbuf = time(NULL) - uptime;
9331
bee57a7a 9332#if CONFDATE > 20200101
a4d82a8a
PZ
9333 CPP_NOTICE(
9334 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9335#endif
9336 /*
9337 * bgpTimerUp was miliseconds that was accurate
9338 * up to 1 day, then the value returned
9339 * became garbage. So in order to provide
9340 * some level of backwards compatability,
9341 * we still provde the data, but now
9342 * we are returning the correct value
9343 * and also adding a new bgpTimerUpMsec
9344 * which will allow us to deprecate
9345 * this eventually
9346 */
d62a17ae 9347 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9348 uptime * 1000);
d3c7efed
DS
9349 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9350 uptime * 1000);
d62a17ae 9351 json_object_string_add(json_neigh, "bgpTimerUpString",
9352 peer_uptime(p->uptime, timebuf,
9353 BGP_UPTIME_LEN, 0,
9354 NULL));
9355 json_object_int_add(json_neigh,
9356 "bgpTimerUpEstablishedEpoch",
9357 epoch_tbuf);
9358 }
9359
9360 else if (p->status == Active) {
9361 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9362 json_object_string_add(json_neigh, "bgpStateIs",
9363 "passive");
9364 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9365 json_object_string_add(json_neigh, "bgpStateIs",
9366 "passiveNSF");
9367 }
9368
9369 /* read timer */
9370 time_t uptime;
9371 struct tm *tm;
9372
9373 uptime = bgp_clock();
9374 uptime -= p->readtime;
9375 tm = gmtime(&uptime);
9376 json_object_int_add(json_neigh, "bgpTimerLastRead",
9377 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9378 + (tm->tm_hour * 3600000));
9379
9380 uptime = bgp_clock();
9381 uptime -= p->last_write;
9382 tm = gmtime(&uptime);
9383 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9384 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9385 + (tm->tm_hour * 3600000));
9386
9387 uptime = bgp_clock();
9388 uptime -= p->update_time;
9389 tm = gmtime(&uptime);
9390 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9391 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9392 + (tm->tm_hour * 3600000));
9393
9394 /* Configured timer values. */
9395 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9396 p->v_holdtime * 1000);
9397 json_object_int_add(json_neigh,
9398 "bgpTimerKeepAliveIntervalMsecs",
9399 p->v_keepalive * 1000);
b90a8e13 9400 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9401 json_object_int_add(json_neigh,
9402 "bgpTimerConfiguredHoldTimeMsecs",
9403 p->holdtime * 1000);
9404 json_object_int_add(
9405 json_neigh,
9406 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9407 p->keepalive * 1000);
d25e4efc 9408 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9409 || (bgp->default_keepalive
9410 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9411 json_object_int_add(json_neigh,
9412 "bgpTimerConfiguredHoldTimeMsecs",
9413 bgp->default_holdtime);
9414 json_object_int_add(
9415 json_neigh,
9416 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9417 bgp->default_keepalive);
d62a17ae 9418 }
9419 } else {
9420 /* Administrative shutdown. */
9421 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9422 vty_out(vty, " Administratively shut down\n");
9423
9424 /* BGP Version. */
9425 vty_out(vty, " BGP version 4");
0e38aeb4 9426 vty_out(vty, ", remote router ID %s",
d62a17ae 9427 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9428 vty_out(vty, ", local router ID %s\n",
9429 inet_ntop(AF_INET, &bgp->router_id, buf1,
9430 sizeof(buf1)));
d62a17ae 9431
9432 /* Confederation */
9433 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9434 && bgp_confederation_peers_check(bgp, p->as))
9435 vty_out(vty,
9436 " Neighbor under common administration\n");
9437
9438 /* Status. */
9439 vty_out(vty, " BGP state = %s",
9440 lookup_msg(bgp_status_msg, p->status, NULL));
9441
9442 if (p->status == Established)
9443 vty_out(vty, ", up for %8s",
9444 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9445 0, NULL));
9446
9447 else if (p->status == Active) {
9448 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9449 vty_out(vty, " (passive)");
9450 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9451 vty_out(vty, " (NSF passive)");
9452 }
9453 vty_out(vty, "\n");
9454
9455 /* read timer */
9456 vty_out(vty, " Last read %s",
9457 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9458 NULL));
9459 vty_out(vty, ", Last write %s\n",
9460 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9461 NULL));
9462
9463 /* Configured timer values. */
9464 vty_out(vty,
9465 " Hold time is %d, keepalive interval is %d seconds\n",
9466 p->v_holdtime, p->v_keepalive);
b90a8e13 9467 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9468 vty_out(vty, " Configured hold time is %d",
9469 p->holdtime);
9470 vty_out(vty, ", keepalive interval is %d seconds\n",
9471 p->keepalive);
d25e4efc 9472 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9473 || (bgp->default_keepalive
9474 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9475 vty_out(vty, " Configured hold time is %d",
9476 bgp->default_holdtime);
9477 vty_out(vty, ", keepalive interval is %d seconds\n",
9478 bgp->default_keepalive);
d62a17ae 9479 }
9480 }
9481 /* Capability. */
9482 if (p->status == Established) {
9483 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9484 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9485 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9486 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9487 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9488 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9489 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9490 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9491 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9492 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9493 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9494 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9495 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9496 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9497 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9498 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9499 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9500 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9501 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9502 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9503 if (use_json) {
9504 json_object *json_cap = NULL;
9505
9506 json_cap = json_object_new_object();
9507
9508 /* AS4 */
9509 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9510 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9511 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9512 && CHECK_FLAG(p->cap,
9513 PEER_CAP_AS4_RCV))
9514 json_object_string_add(
9515 json_cap, "4byteAs",
9516 "advertisedAndReceived");
9517 else if (CHECK_FLAG(p->cap,
9518 PEER_CAP_AS4_ADV))
9519 json_object_string_add(
9520 json_cap, "4byteAs",
9521 "advertised");
9522 else if (CHECK_FLAG(p->cap,
9523 PEER_CAP_AS4_RCV))
9524 json_object_string_add(
9525 json_cap, "4byteAs",
9526 "received");
9527 }
9528
9529 /* AddPath */
9530 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9531 || CHECK_FLAG(p->cap,
9532 PEER_CAP_ADDPATH_ADV)) {
9533 json_object *json_add = NULL;
9534 const char *print_store;
9535
9536 json_add = json_object_new_object();
9537
05c7a1cc
QY
9538 FOREACH_AFI_SAFI (afi, safi) {
9539 json_object *json_sub = NULL;
9540 json_sub =
9541 json_object_new_object();
9542 print_store = afi_safi_print(
9543 afi, safi);
d62a17ae 9544
05c7a1cc
QY
9545 if (CHECK_FLAG(
9546 p->af_cap[afi]
9547 [safi],
9548 PEER_CAP_ADDPATH_AF_TX_ADV)
9549 || CHECK_FLAG(
9550 p->af_cap[afi]
9551 [safi],
9552 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9553 if (CHECK_FLAG(
9554 p->af_cap
9555 [afi]
9556 [safi],
9557 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9558 && CHECK_FLAG(
d62a17ae 9559 p->af_cap
9560 [afi]
9561 [safi],
05c7a1cc
QY
9562 PEER_CAP_ADDPATH_AF_TX_RCV))
9563 json_object_boolean_true_add(
9564 json_sub,
9565 "txAdvertisedAndReceived");
9566 else if (
9567 CHECK_FLAG(
9568 p->af_cap
9569 [afi]
9570 [safi],
9571 PEER_CAP_ADDPATH_AF_TX_ADV))
9572 json_object_boolean_true_add(
9573 json_sub,
9574 "txAdvertised");
9575 else if (
9576 CHECK_FLAG(
9577 p->af_cap
9578 [afi]
9579 [safi],
9580 PEER_CAP_ADDPATH_AF_TX_RCV))
9581 json_object_boolean_true_add(
9582 json_sub,
9583 "txReceived");
9584 }
d62a17ae 9585
05c7a1cc
QY
9586 if (CHECK_FLAG(
9587 p->af_cap[afi]
9588 [safi],
9589 PEER_CAP_ADDPATH_AF_RX_ADV)
9590 || CHECK_FLAG(
9591 p->af_cap[afi]
9592 [safi],
9593 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9594 if (CHECK_FLAG(
9595 p->af_cap
9596 [afi]
9597 [safi],
9598 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9599 && CHECK_FLAG(
d62a17ae 9600 p->af_cap
9601 [afi]
9602 [safi],
9603 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9604 json_object_boolean_true_add(
9605 json_sub,
9606 "rxAdvertisedAndReceived");
9607 else if (
9608 CHECK_FLAG(
9609 p->af_cap
9610 [afi]
9611 [safi],
9612 PEER_CAP_ADDPATH_AF_RX_ADV))
9613 json_object_boolean_true_add(
9614 json_sub,
9615 "rxAdvertised");
9616 else if (
9617 CHECK_FLAG(
9618 p->af_cap
9619 [afi]
9620 [safi],
9621 PEER_CAP_ADDPATH_AF_RX_RCV))
9622 json_object_boolean_true_add(
9623 json_sub,
9624 "rxReceived");
d62a17ae 9625 }
9626
05c7a1cc
QY
9627 if (CHECK_FLAG(
9628 p->af_cap[afi]
9629 [safi],
9630 PEER_CAP_ADDPATH_AF_TX_ADV)
9631 || CHECK_FLAG(
9632 p->af_cap[afi]
9633 [safi],
9634 PEER_CAP_ADDPATH_AF_TX_RCV)
9635 || CHECK_FLAG(
9636 p->af_cap[afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_RX_ADV)
9639 || CHECK_FLAG(
9640 p->af_cap[afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_RX_RCV))
9643 json_object_object_add(
9644 json_add,
9645 print_store,
9646 json_sub);
9647 else
9648 json_object_free(
9649 json_sub);
9650 }
9651
d62a17ae 9652 json_object_object_add(
9653 json_cap, "addPath", json_add);
9654 }
9655
9656 /* Dynamic */
9657 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9658 || CHECK_FLAG(p->cap,
9659 PEER_CAP_DYNAMIC_ADV)) {
9660 if (CHECK_FLAG(p->cap,
9661 PEER_CAP_DYNAMIC_ADV)
9662 && CHECK_FLAG(p->cap,
9663 PEER_CAP_DYNAMIC_RCV))
9664 json_object_string_add(
9665 json_cap, "dynamic",
9666 "advertisedAndReceived");
9667 else if (CHECK_FLAG(
9668 p->cap,
9669 PEER_CAP_DYNAMIC_ADV))
9670 json_object_string_add(
9671 json_cap, "dynamic",
9672 "advertised");
9673 else if (CHECK_FLAG(
9674 p->cap,
9675 PEER_CAP_DYNAMIC_RCV))
9676 json_object_string_add(
9677 json_cap, "dynamic",
9678 "received");
9679 }
9680
9681 /* Extended nexthop */
9682 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9683 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9684 json_object *json_nxt = NULL;
9685 const char *print_store;
9686
9687
9688 if (CHECK_FLAG(p->cap,
9689 PEER_CAP_ENHE_ADV)
9690 && CHECK_FLAG(p->cap,
9691 PEER_CAP_ENHE_RCV))
9692 json_object_string_add(
9693 json_cap,
9694 "extendedNexthop",
9695 "advertisedAndReceived");
9696 else if (CHECK_FLAG(p->cap,
9697 PEER_CAP_ENHE_ADV))
9698 json_object_string_add(
9699 json_cap,
9700 "extendedNexthop",
9701 "advertised");
9702 else if (CHECK_FLAG(p->cap,
9703 PEER_CAP_ENHE_RCV))
9704 json_object_string_add(
9705 json_cap,
9706 "extendedNexthop",
9707 "received");
9708
9709 if (CHECK_FLAG(p->cap,
9710 PEER_CAP_ENHE_RCV)) {
9711 json_nxt =
9712 json_object_new_object();
9713
9714 for (safi = SAFI_UNICAST;
9715 safi < SAFI_MAX; safi++) {
9716 if (CHECK_FLAG(
9717 p->af_cap
9718 [AFI_IP]
9719 [safi],
9720 PEER_CAP_ENHE_AF_RCV)) {
9721 print_store = afi_safi_print(
9722 AFI_IP,
9723 safi);
9724 json_object_string_add(
9725 json_nxt,
9726 print_store,
54f29523 9727 "recieved"); /* misspelled for compatibility */
d62a17ae 9728 }
9729 }
9730 json_object_object_add(
9731 json_cap,
9732 "extendedNexthopFamililesByPeer",
9733 json_nxt);
9734 }
9735 }
9736
9737 /* Route Refresh */
9738 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9739 || CHECK_FLAG(p->cap,
9740 PEER_CAP_REFRESH_NEW_RCV)
9741 || CHECK_FLAG(p->cap,
9742 PEER_CAP_REFRESH_OLD_RCV)) {
9743 if (CHECK_FLAG(p->cap,
9744 PEER_CAP_REFRESH_ADV)
9745 && (CHECK_FLAG(
9746 p->cap,
9747 PEER_CAP_REFRESH_NEW_RCV)
9748 || CHECK_FLAG(
9749 p->cap,
9750 PEER_CAP_REFRESH_OLD_RCV))) {
9751 if (CHECK_FLAG(
9752 p->cap,
9753 PEER_CAP_REFRESH_OLD_RCV)
9754 && CHECK_FLAG(
9755 p->cap,
9756 PEER_CAP_REFRESH_NEW_RCV))
9757 json_object_string_add(
9758 json_cap,
9759 "routeRefresh",
9760 "advertisedAndReceivedOldNew");
9761 else {
9762 if (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_REFRESH_OLD_RCV))
9765 json_object_string_add(
9766 json_cap,
9767 "routeRefresh",
9768 "advertisedAndReceivedOld");
9769 else
9770 json_object_string_add(
9771 json_cap,
9772 "routeRefresh",
9773 "advertisedAndReceivedNew");
9774 }
9775 } else if (
9776 CHECK_FLAG(
9777 p->cap,
9778 PEER_CAP_REFRESH_ADV))
9779 json_object_string_add(
9780 json_cap,
9781 "routeRefresh",
9782 "advertised");
9783 else if (
9784 CHECK_FLAG(
9785 p->cap,
9786 PEER_CAP_REFRESH_NEW_RCV)
9787 || CHECK_FLAG(
9788 p->cap,
9789 PEER_CAP_REFRESH_OLD_RCV))
9790 json_object_string_add(
9791 json_cap,
9792 "routeRefresh",
9793 "received");
9794 }
9795
9796 /* Multiprotocol Extensions */
9797 json_object *json_multi = NULL;
9798 json_multi = json_object_new_object();
9799
05c7a1cc
QY
9800 FOREACH_AFI_SAFI (afi, safi) {
9801 if (p->afc_adv[afi][safi]
9802 || p->afc_recv[afi][safi]) {
9803 json_object *json_exten = NULL;
9804 json_exten =
9805 json_object_new_object();
9806
d62a17ae 9807 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9808 && p->afc_recv[afi][safi])
9809 json_object_boolean_true_add(
9810 json_exten,
9811 "advertisedAndReceived");
9812 else if (p->afc_adv[afi][safi])
9813 json_object_boolean_true_add(
9814 json_exten,
9815 "advertised");
9816 else if (p->afc_recv[afi][safi])
9817 json_object_boolean_true_add(
9818 json_exten,
9819 "received");
d62a17ae 9820
05c7a1cc
QY
9821 json_object_object_add(
9822 json_multi,
9823 afi_safi_print(afi,
9824 safi),
9825 json_exten);
d62a17ae 9826 }
9827 }
9828 json_object_object_add(
9829 json_cap, "multiprotocolExtensions",
9830 json_multi);
9831
d77114b7 9832 /* Hostname capabilities */
60466a63 9833 json_object *json_hname = NULL;
d77114b7
MK
9834
9835 json_hname = json_object_new_object();
9836
9837 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9838 json_object_string_add(
60466a63
QY
9839 json_hname, "advHostName",
9840 bgp->peer_self->hostname
9841 ? bgp->peer_self
9842 ->hostname
d77114b7
MK
9843 : "n/a");
9844 json_object_string_add(
60466a63
QY
9845 json_hname, "advDomainName",
9846 bgp->peer_self->domainname
9847 ? bgp->peer_self
9848 ->domainname
d77114b7
MK
9849 : "n/a");
9850 }
9851
9852
9853 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9854 json_object_string_add(
60466a63
QY
9855 json_hname, "rcvHostName",
9856 p->hostname ? p->hostname
9857 : "n/a");
d77114b7 9858 json_object_string_add(
60466a63
QY
9859 json_hname, "rcvDomainName",
9860 p->domainname ? p->domainname
9861 : "n/a");
d77114b7
MK
9862 }
9863
60466a63 9864 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9865 json_hname);
9866
d62a17ae 9867 /* Gracefull Restart */
9868 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9869 || CHECK_FLAG(p->cap,
9870 PEER_CAP_RESTART_ADV)) {
9871 if (CHECK_FLAG(p->cap,
9872 PEER_CAP_RESTART_ADV)
9873 && CHECK_FLAG(p->cap,
9874 PEER_CAP_RESTART_RCV))
9875 json_object_string_add(
9876 json_cap,
9877 "gracefulRestart",
9878 "advertisedAndReceived");
9879 else if (CHECK_FLAG(
9880 p->cap,
9881 PEER_CAP_RESTART_ADV))
9882 json_object_string_add(
9883 json_cap,
9884 "gracefulRestartCapability",
9885 "advertised");
9886 else if (CHECK_FLAG(
9887 p->cap,
9888 PEER_CAP_RESTART_RCV))
9889 json_object_string_add(
9890 json_cap,
9891 "gracefulRestartCapability",
9892 "received");
9893
9894 if (CHECK_FLAG(p->cap,
9895 PEER_CAP_RESTART_RCV)) {
9896 int restart_af_count = 0;
9897 json_object *json_restart =
9898 NULL;
9899 json_restart =
9900 json_object_new_object();
9901
9902 json_object_int_add(
9903 json_cap,
9904 "gracefulRestartRemoteTimerMsecs",
9905 p->v_gr_restart * 1000);
9906
05c7a1cc
QY
9907 FOREACH_AFI_SAFI (afi, safi) {
9908 if (CHECK_FLAG(
9909 p->af_cap
9910 [afi]
9911 [safi],
9912 PEER_CAP_RESTART_AF_RCV)) {
9913 json_object *
9914 json_sub =
9915 NULL;
9916 json_sub =
9917 json_object_new_object();
9918
d62a17ae 9919 if (CHECK_FLAG(
9920 p->af_cap
9921 [afi]
9922 [safi],
05c7a1cc
QY
9923 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9924 json_object_boolean_true_add(
9925 json_sub,
9926 "preserved");
9927 restart_af_count++;
9928 json_object_object_add(
9929 json_restart,
9930 afi_safi_print(
9931 afi,
9932 safi),
9933 json_sub);
d62a17ae 9934 }
9935 }
9936 if (!restart_af_count) {
9937 json_object_string_add(
9938 json_cap,
9939 "addressFamiliesByPeer",
9940 "none");
9941 json_object_free(
9942 json_restart);
9943 } else
9944 json_object_object_add(
9945 json_cap,
9946 "addressFamiliesByPeer",
9947 json_restart);
9948 }
9949 }
9950 json_object_object_add(json_neigh,
9951 "neighborCapabilities",
9952 json_cap);
9953 } else {
9954 vty_out(vty, " Neighbor capabilities:\n");
9955
9956 /* AS4 */
9957 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9958 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9959 vty_out(vty, " 4 Byte AS:");
9960 if (CHECK_FLAG(p->cap,
9961 PEER_CAP_AS4_ADV))
9962 vty_out(vty, " advertised");
9963 if (CHECK_FLAG(p->cap,
9964 PEER_CAP_AS4_RCV))
9965 vty_out(vty, " %sreceived",
9966 CHECK_FLAG(
9967 p->cap,
9968 PEER_CAP_AS4_ADV)
9969 ? "and "
9970 : "");
9971 vty_out(vty, "\n");
9972 }
9973
9974 /* AddPath */
9975 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9976 || CHECK_FLAG(p->cap,
9977 PEER_CAP_ADDPATH_ADV)) {
9978 vty_out(vty, " AddPath:\n");
9979
05c7a1cc
QY
9980 FOREACH_AFI_SAFI (afi, safi) {
9981 if (CHECK_FLAG(
9982 p->af_cap[afi]
9983 [safi],
9984 PEER_CAP_ADDPATH_AF_TX_ADV)
9985 || CHECK_FLAG(
9986 p->af_cap[afi]
9987 [safi],
9988 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9989 vty_out(vty,
9990 " %s: TX ",
9991 afi_safi_print(
9992 afi,
9993 safi));
9994
d62a17ae 9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
05c7a1cc 9999 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10000 vty_out(vty,
05c7a1cc 10001 "advertised %s",
d62a17ae 10002 afi_safi_print(
10003 afi,
10004 safi));
10005
05c7a1cc
QY
10006 if (CHECK_FLAG(
10007 p->af_cap
10008 [afi]
10009 [safi],
10010 PEER_CAP_ADDPATH_AF_TX_RCV))
10011 vty_out(vty,
10012 "%sreceived",
10013 CHECK_FLAG(
10014 p->af_cap
10015 [afi]
10016 [safi],
10017 PEER_CAP_ADDPATH_AF_TX_ADV)
10018 ? " and "
10019 : "");
d62a17ae 10020
05c7a1cc
QY
10021 vty_out(vty, "\n");
10022 }
d62a17ae 10023
05c7a1cc
QY
10024 if (CHECK_FLAG(
10025 p->af_cap[afi]
10026 [safi],
10027 PEER_CAP_ADDPATH_AF_RX_ADV)
10028 || CHECK_FLAG(
10029 p->af_cap[afi]
10030 [safi],
10031 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10032 vty_out(vty,
10033 " %s: RX ",
10034 afi_safi_print(
10035 afi,
10036 safi));
d62a17ae 10037
10038 if (CHECK_FLAG(
10039 p->af_cap
10040 [afi]
10041 [safi],
05c7a1cc 10042 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10043 vty_out(vty,
05c7a1cc 10044 "advertised %s",
d62a17ae 10045 afi_safi_print(
10046 afi,
10047 safi));
10048
05c7a1cc
QY
10049 if (CHECK_FLAG(
10050 p->af_cap
10051 [afi]
10052 [safi],
10053 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10054 vty_out(vty,
05c7a1cc
QY
10055 "%sreceived",
10056 CHECK_FLAG(
10057 p->af_cap
10058 [afi]
10059 [safi],
10060 PEER_CAP_ADDPATH_AF_RX_ADV)
10061 ? " and "
10062 : "");
10063
10064 vty_out(vty, "\n");
d62a17ae 10065 }
05c7a1cc 10066 }
d62a17ae 10067 }
10068
10069 /* Dynamic */
10070 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10071 || CHECK_FLAG(p->cap,
10072 PEER_CAP_DYNAMIC_ADV)) {
10073 vty_out(vty, " Dynamic:");
10074 if (CHECK_FLAG(p->cap,
10075 PEER_CAP_DYNAMIC_ADV))
10076 vty_out(vty, " advertised");
10077 if (CHECK_FLAG(p->cap,
10078 PEER_CAP_DYNAMIC_RCV))
10079 vty_out(vty, " %sreceived",
10080 CHECK_FLAG(
10081 p->cap,
10082 PEER_CAP_DYNAMIC_ADV)
10083 ? "and "
10084 : "");
10085 vty_out(vty, "\n");
10086 }
10087
10088 /* Extended nexthop */
10089 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10090 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10091 vty_out(vty, " Extended nexthop:");
10092 if (CHECK_FLAG(p->cap,
10093 PEER_CAP_ENHE_ADV))
10094 vty_out(vty, " advertised");
10095 if (CHECK_FLAG(p->cap,
10096 PEER_CAP_ENHE_RCV))
10097 vty_out(vty, " %sreceived",
10098 CHECK_FLAG(
10099 p->cap,
10100 PEER_CAP_ENHE_ADV)
10101 ? "and "
10102 : "");
10103 vty_out(vty, "\n");
10104
10105 if (CHECK_FLAG(p->cap,
10106 PEER_CAP_ENHE_RCV)) {
10107 vty_out(vty,
10108 " Address families by peer:\n ");
10109 for (safi = SAFI_UNICAST;
10110 safi < SAFI_MAX; safi++)
10111 if (CHECK_FLAG(
10112 p->af_cap
10113 [AFI_IP]
10114 [safi],
10115 PEER_CAP_ENHE_AF_RCV))
10116 vty_out(vty,
10117 " %s\n",
10118 afi_safi_print(
10119 AFI_IP,
10120 safi));
10121 }
10122 }
10123
10124 /* Route Refresh */
10125 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10126 || CHECK_FLAG(p->cap,
10127 PEER_CAP_REFRESH_NEW_RCV)
10128 || CHECK_FLAG(p->cap,
10129 PEER_CAP_REFRESH_OLD_RCV)) {
10130 vty_out(vty, " Route refresh:");
10131 if (CHECK_FLAG(p->cap,
10132 PEER_CAP_REFRESH_ADV))
10133 vty_out(vty, " advertised");
10134 if (CHECK_FLAG(p->cap,
10135 PEER_CAP_REFRESH_NEW_RCV)
10136 || CHECK_FLAG(
10137 p->cap,
10138 PEER_CAP_REFRESH_OLD_RCV))
10139 vty_out(vty, " %sreceived(%s)",
10140 CHECK_FLAG(
10141 p->cap,
10142 PEER_CAP_REFRESH_ADV)
10143 ? "and "
10144 : "",
10145 (CHECK_FLAG(
10146 p->cap,
10147 PEER_CAP_REFRESH_OLD_RCV)
10148 && CHECK_FLAG(
10149 p->cap,
10150 PEER_CAP_REFRESH_NEW_RCV))
10151 ? "old & new"
10152 : CHECK_FLAG(
10153 p->cap,
10154 PEER_CAP_REFRESH_OLD_RCV)
10155 ? "old"
10156 : "new");
10157
10158 vty_out(vty, "\n");
10159 }
10160
10161 /* Multiprotocol Extensions */
05c7a1cc
QY
10162 FOREACH_AFI_SAFI (afi, safi)
10163 if (p->afc_adv[afi][safi]
10164 || p->afc_recv[afi][safi]) {
10165 vty_out(vty,
10166 " Address Family %s:",
10167 afi_safi_print(afi,
10168 safi));
10169 if (p->afc_adv[afi][safi])
d62a17ae 10170 vty_out(vty,
05c7a1cc
QY
10171 " advertised");
10172 if (p->afc_recv[afi][safi])
10173 vty_out(vty,
10174 " %sreceived",
10175 p->afc_adv[afi]
10176 [safi]
10177 ? "and "
10178 : "");
10179 vty_out(vty, "\n");
10180 }
d62a17ae 10181
10182 /* Hostname capability */
60466a63 10183 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10184
10185 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10186 vty_out(vty,
10187 " advertised (name: %s,domain name: %s)",
60466a63
QY
10188 bgp->peer_self->hostname
10189 ? bgp->peer_self
10190 ->hostname
d77114b7 10191 : "n/a",
60466a63
QY
10192 bgp->peer_self->domainname
10193 ? bgp->peer_self
10194 ->domainname
d77114b7
MK
10195 : "n/a");
10196 } else {
10197 vty_out(vty, " not advertised");
d62a17ae 10198 }
10199
d77114b7 10200 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10201 vty_out(vty,
10202 " received (name: %s,domain name: %s)",
60466a63
QY
10203 p->hostname ? p->hostname
10204 : "n/a",
10205 p->domainname ? p->domainname
10206 : "n/a");
d77114b7
MK
10207 } else {
10208 vty_out(vty, " not received");
10209 }
10210
10211 vty_out(vty, "\n");
10212
d62a17ae 10213 /* Gracefull Restart */
10214 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10215 || CHECK_FLAG(p->cap,
10216 PEER_CAP_RESTART_ADV)) {
10217 vty_out(vty,
10218 " Graceful Restart Capabilty:");
10219 if (CHECK_FLAG(p->cap,
10220 PEER_CAP_RESTART_ADV))
10221 vty_out(vty, " advertised");
10222 if (CHECK_FLAG(p->cap,
10223 PEER_CAP_RESTART_RCV))
10224 vty_out(vty, " %sreceived",
10225 CHECK_FLAG(
10226 p->cap,
10227 PEER_CAP_RESTART_ADV)
10228 ? "and "
10229 : "");
10230 vty_out(vty, "\n");
10231
10232 if (CHECK_FLAG(p->cap,
10233 PEER_CAP_RESTART_RCV)) {
10234 int restart_af_count = 0;
10235
10236 vty_out(vty,
10237 " Remote Restart timer is %d seconds\n",
10238 p->v_gr_restart);
10239 vty_out(vty,
10240 " Address families by peer:\n ");
10241
05c7a1cc
QY
10242 FOREACH_AFI_SAFI (afi, safi)
10243 if (CHECK_FLAG(
10244 p->af_cap
10245 [afi]
10246 [safi],
10247 PEER_CAP_RESTART_AF_RCV)) {
10248 vty_out(vty,
10249 "%s%s(%s)",
10250 restart_af_count
10251 ? ", "
10252 : "",
10253 afi_safi_print(
10254 afi,
10255 safi),
10256 CHECK_FLAG(
10257 p->af_cap
10258 [afi]
10259 [safi],
10260 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10261 ? "preserved"
10262 : "not preserved");
10263 restart_af_count++;
10264 }
d62a17ae 10265 if (!restart_af_count)
10266 vty_out(vty, "none");
10267 vty_out(vty, "\n");
10268 }
10269 }
10270 }
10271 }
10272 }
10273
10274 /* graceful restart information */
10275 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10276 || p->t_gr_stale) {
10277 json_object *json_grace = NULL;
10278 json_object *json_grace_send = NULL;
10279 json_object *json_grace_recv = NULL;
10280 int eor_send_af_count = 0;
10281 int eor_receive_af_count = 0;
10282
10283 if (use_json) {
10284 json_grace = json_object_new_object();
10285 json_grace_send = json_object_new_object();
10286 json_grace_recv = json_object_new_object();
10287
10288 if (p->status == Established) {
05c7a1cc
QY
10289 FOREACH_AFI_SAFI (afi, safi) {
10290 if (CHECK_FLAG(p->af_sflags[afi][safi],
10291 PEER_STATUS_EOR_SEND)) {
10292 json_object_boolean_true_add(
10293 json_grace_send,
10294 afi_safi_print(afi,
10295 safi));
10296 eor_send_af_count++;
d62a17ae 10297 }
10298 }
05c7a1cc
QY
10299 FOREACH_AFI_SAFI (afi, safi) {
10300 if (CHECK_FLAG(
10301 p->af_sflags[afi][safi],
10302 PEER_STATUS_EOR_RECEIVED)) {
10303 json_object_boolean_true_add(
10304 json_grace_recv,
10305 afi_safi_print(afi,
10306 safi));
10307 eor_receive_af_count++;
d62a17ae 10308 }
10309 }
10310 }
10311
10312 json_object_object_add(json_grace, "endOfRibSend",
10313 json_grace_send);
10314 json_object_object_add(json_grace, "endOfRibRecv",
10315 json_grace_recv);
10316
10317 if (p->t_gr_restart)
10318 json_object_int_add(json_grace,
10319 "gracefulRestartTimerMsecs",
10320 thread_timer_remain_second(
10321 p->t_gr_restart)
10322 * 1000);
10323
10324 if (p->t_gr_stale)
10325 json_object_int_add(
10326 json_grace,
10327 "gracefulStalepathTimerMsecs",
10328 thread_timer_remain_second(
10329 p->t_gr_stale)
10330 * 1000);
10331
10332 json_object_object_add(
10333 json_neigh, "gracefulRestartInfo", json_grace);
10334 } else {
0437e105 10335 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10336 if (p->status == Established) {
10337 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10338 FOREACH_AFI_SAFI (afi, safi) {
10339 if (CHECK_FLAG(p->af_sflags[afi][safi],
10340 PEER_STATUS_EOR_SEND)) {
10341 vty_out(vty, "%s%s",
10342 eor_send_af_count ? ", "
10343 : "",
10344 afi_safi_print(afi,
10345 safi));
10346 eor_send_af_count++;
d62a17ae 10347 }
10348 }
10349 vty_out(vty, "\n");
10350 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10351 FOREACH_AFI_SAFI (afi, safi) {
10352 if (CHECK_FLAG(
10353 p->af_sflags[afi][safi],
10354 PEER_STATUS_EOR_RECEIVED)) {
10355 vty_out(vty, "%s%s",
10356 eor_receive_af_count
10357 ? ", "
10358 : "",
10359 afi_safi_print(afi,
10360 safi));
10361 eor_receive_af_count++;
d62a17ae 10362 }
10363 }
10364 vty_out(vty, "\n");
10365 }
10366
10367 if (p->t_gr_restart)
10368 vty_out(vty,
10369 " The remaining time of restart timer is %ld\n",
10370 thread_timer_remain_second(
10371 p->t_gr_restart));
10372
10373 if (p->t_gr_stale)
10374 vty_out(vty,
10375 " The remaining time of stalepath timer is %ld\n",
10376 thread_timer_remain_second(
10377 p->t_gr_stale));
10378 }
10379 }
10380 if (use_json) {
10381 json_object *json_stat = NULL;
10382 json_stat = json_object_new_object();
10383 /* Packet counts. */
10384 json_object_int_add(json_stat, "depthInq", 0);
10385 json_object_int_add(json_stat, "depthOutq",
10386 (unsigned long)p->obuf->count);
0112e9e0
QY
10387 json_object_int_add(json_stat, "opensSent",
10388 atomic_load_explicit(&p->open_out,
10389 memory_order_relaxed));
10390 json_object_int_add(json_stat, "opensRecv",
10391 atomic_load_explicit(&p->open_in,
10392 memory_order_relaxed));
d62a17ae 10393 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10394 atomic_load_explicit(&p->notify_out,
10395 memory_order_relaxed));
d62a17ae 10396 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10397 atomic_load_explicit(&p->notify_in,
10398 memory_order_relaxed));
10399 json_object_int_add(json_stat, "updatesSent",
10400 atomic_load_explicit(&p->update_out,
10401 memory_order_relaxed));
10402 json_object_int_add(json_stat, "updatesRecv",
10403 atomic_load_explicit(&p->update_in,
10404 memory_order_relaxed));
d62a17ae 10405 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10406 atomic_load_explicit(&p->keepalive_out,
10407 memory_order_relaxed));
d62a17ae 10408 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10409 atomic_load_explicit(&p->keepalive_in,
10410 memory_order_relaxed));
d62a17ae 10411 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10412 atomic_load_explicit(&p->refresh_out,
10413 memory_order_relaxed));
d62a17ae 10414 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10415 atomic_load_explicit(&p->refresh_in,
10416 memory_order_relaxed));
d62a17ae 10417 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10418 atomic_load_explicit(&p->dynamic_cap_out,
10419 memory_order_relaxed));
d62a17ae 10420 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10421 atomic_load_explicit(&p->dynamic_cap_in,
10422 memory_order_relaxed));
10423 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10424 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10425 json_object_object_add(json_neigh, "messageStats", json_stat);
10426 } else {
10427 /* Packet counts. */
10428 vty_out(vty, " Message statistics:\n");
10429 vty_out(vty, " Inq depth is 0\n");
10430 vty_out(vty, " Outq depth is %lu\n",
10431 (unsigned long)p->obuf->count);
10432 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10433 vty_out(vty, " Opens: %10d %10d\n",
10434 atomic_load_explicit(&p->open_out,
10435 memory_order_relaxed),
10436 atomic_load_explicit(&p->open_in,
10437 memory_order_relaxed));
10438 vty_out(vty, " Notifications: %10d %10d\n",
10439 atomic_load_explicit(&p->notify_out,
10440 memory_order_relaxed),
10441 atomic_load_explicit(&p->notify_in,
10442 memory_order_relaxed));
10443 vty_out(vty, " Updates: %10d %10d\n",
10444 atomic_load_explicit(&p->update_out,
10445 memory_order_relaxed),
10446 atomic_load_explicit(&p->update_in,
10447 memory_order_relaxed));
10448 vty_out(vty, " Keepalives: %10d %10d\n",
10449 atomic_load_explicit(&p->keepalive_out,
10450 memory_order_relaxed),
10451 atomic_load_explicit(&p->keepalive_in,
10452 memory_order_relaxed));
10453 vty_out(vty, " Route Refresh: %10d %10d\n",
10454 atomic_load_explicit(&p->refresh_out,
10455 memory_order_relaxed),
10456 atomic_load_explicit(&p->refresh_in,
10457 memory_order_relaxed));
d62a17ae 10458 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10459 atomic_load_explicit(&p->dynamic_cap_out,
10460 memory_order_relaxed),
10461 atomic_load_explicit(&p->dynamic_cap_in,
10462 memory_order_relaxed));
10463 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10464 PEER_TOTAL_RX(p));
d62a17ae 10465 }
10466
10467 if (use_json) {
10468 /* advertisement-interval */
10469 json_object_int_add(json_neigh,
10470 "minBtwnAdvertisementRunsTimerMsecs",
10471 p->v_routeadv * 1000);
10472
10473 /* Update-source. */
10474 if (p->update_if || p->update_source) {
10475 if (p->update_if)
10476 json_object_string_add(json_neigh,
10477 "updateSource",
10478 p->update_if);
10479 else if (p->update_source)
10480 json_object_string_add(
10481 json_neigh, "updateSource",
10482 sockunion2str(p->update_source, buf1,
10483 SU_ADDRSTRLEN));
10484 }
10485 } else {
10486 /* advertisement-interval */
10487 vty_out(vty,
10488 " Minimum time between advertisement runs is %d seconds\n",
10489 p->v_routeadv);
10490
10491 /* Update-source. */
10492 if (p->update_if || p->update_source) {
10493 vty_out(vty, " Update source is ");
10494 if (p->update_if)
10495 vty_out(vty, "%s", p->update_if);
10496 else if (p->update_source)
10497 vty_out(vty, "%s",
10498 sockunion2str(p->update_source, buf1,
10499 SU_ADDRSTRLEN));
10500 vty_out(vty, "\n");
10501 }
10502
10503 vty_out(vty, "\n");
10504 }
10505
10506 /* Address Family Information */
10507 json_object *json_hold = NULL;
10508
10509 if (use_json)
10510 json_hold = json_object_new_object();
10511
05c7a1cc
QY
10512 FOREACH_AFI_SAFI (afi, safi)
10513 if (p->afc[afi][safi])
10514 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10515 json_hold);
d62a17ae 10516
10517 if (use_json) {
10518 json_object_object_add(json_neigh, "addressFamilyInfo",
10519 json_hold);
10520 json_object_int_add(json_neigh, "connectionsEstablished",
10521 p->established);
10522 json_object_int_add(json_neigh, "connectionsDropped",
10523 p->dropped);
10524 } else
10525 vty_out(vty, " Connections established %d; dropped %d\n",
10526 p->established, p->dropped);
10527
10528 if (!p->last_reset) {
10529 if (use_json)
10530 json_object_string_add(json_neigh, "lastReset",
10531 "never");
10532 else
10533 vty_out(vty, " Last reset never\n");
10534 } else {
10535 if (use_json) {
10536 time_t uptime;
10537 struct tm *tm;
10538
10539 uptime = bgp_clock();
10540 uptime -= p->resettime;
10541 tm = gmtime(&uptime);
10542 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10543 (tm->tm_sec * 1000)
10544 + (tm->tm_min * 60000)
10545 + (tm->tm_hour * 3600000));
10546 json_object_string_add(
10547 json_neigh, "lastResetDueTo",
10548 peer_down_str[(int)p->last_reset]);
10549 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10550 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10551 char errorcodesubcode_hexstr[5];
10552 char errorcodesubcode_str[256];
10553
10554 code_str = bgp_notify_code_str(p->notify.code);
10555 subcode_str = bgp_notify_subcode_str(
10556 p->notify.code, p->notify.subcode);
10557
10558 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10559 p->notify.code, p->notify.subcode);
10560 json_object_string_add(json_neigh,
10561 "lastErrorCodeSubcode",
10562 errorcodesubcode_hexstr);
10563 snprintf(errorcodesubcode_str, 255, "%s%s",
10564 code_str, subcode_str);
10565 json_object_string_add(json_neigh,
10566 "lastNotificationReason",
10567 errorcodesubcode_str);
10568 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10569 && p->notify.code == BGP_NOTIFY_CEASE
10570 && (p->notify.subcode
10571 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10572 || p->notify.subcode
10573 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10574 && p->notify.length) {
10575 char msgbuf[1024];
10576 const char *msg_str;
10577
10578 msg_str = bgp_notify_admin_message(
10579 msgbuf, sizeof(msgbuf),
d7c0a89a 10580 (uint8_t *)p->notify.data,
d62a17ae 10581 p->notify.length);
10582 if (msg_str)
10583 json_object_string_add(
10584 json_neigh,
10585 "lastShutdownDescription",
10586 msg_str);
10587 }
10588 }
10589 } else {
10590 vty_out(vty, " Last reset %s, ",
10591 peer_uptime(p->resettime, timebuf,
10592 BGP_UPTIME_LEN, 0, NULL));
10593
10594 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10595 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10596 code_str = bgp_notify_code_str(p->notify.code);
10597 subcode_str = bgp_notify_subcode_str(
10598 p->notify.code, p->notify.subcode);
10599 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10600 p->last_reset == PEER_DOWN_NOTIFY_SEND
10601 ? "sent"
10602 : "received",
10603 code_str, subcode_str);
10604 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10605 && p->notify.code == BGP_NOTIFY_CEASE
10606 && (p->notify.subcode
10607 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10608 || p->notify.subcode
10609 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10610 && p->notify.length) {
10611 char msgbuf[1024];
10612 const char *msg_str;
10613
10614 msg_str = bgp_notify_admin_message(
10615 msgbuf, sizeof(msgbuf),
d7c0a89a 10616 (uint8_t *)p->notify.data,
d62a17ae 10617 p->notify.length);
10618 if (msg_str)
10619 vty_out(vty,
10620 " Message: \"%s\"\n",
10621 msg_str);
10622 }
10623 } else {
10624 vty_out(vty, "due to %s\n",
10625 peer_down_str[(int)p->last_reset]);
10626 }
10627
10628 if (p->last_reset_cause_size) {
10629 msg = p->last_reset_cause;
10630 vty_out(vty,
10631 " Message received that caused BGP to send a NOTIFICATION:\n ");
10632 for (i = 1; i <= p->last_reset_cause_size;
10633 i++) {
10634 vty_out(vty, "%02X", *msg++);
10635
10636 if (i != p->last_reset_cause_size) {
10637 if (i % 16 == 0) {
10638 vty_out(vty, "\n ");
10639 } else if (i % 4 == 0) {
10640 vty_out(vty, " ");
10641 }
10642 }
10643 }
10644 vty_out(vty, "\n");
10645 }
10646 }
10647 }
10648
10649 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10650 if (use_json)
10651 json_object_boolean_true_add(json_neigh,
10652 "prefixesConfigExceedMax");
10653 else
10654 vty_out(vty,
10655 " Peer had exceeded the max. no. of prefixes configured.\n");
10656
10657 if (p->t_pmax_restart) {
10658 if (use_json) {
10659 json_object_boolean_true_add(
10660 json_neigh, "reducePrefixNumFrom");
10661 json_object_int_add(json_neigh,
10662 "restartInTimerMsec",
10663 thread_timer_remain_second(
10664 p->t_pmax_restart)
10665 * 1000);
10666 } else
10667 vty_out(vty,
10668 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10669 p->host, thread_timer_remain_second(
10670 p->t_pmax_restart));
d62a17ae 10671 } else {
10672 if (use_json)
10673 json_object_boolean_true_add(
10674 json_neigh,
10675 "reducePrefixNumAndClearIpBgp");
10676 else
10677 vty_out(vty,
10678 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10679 p->host);
10680 }
10681 }
10682
10683 /* EBGP Multihop and GTSM */
10684 if (p->sort != BGP_PEER_IBGP) {
10685 if (use_json) {
10686 if (p->gtsm_hops > 0)
10687 json_object_int_add(json_neigh,
10688 "externalBgpNbrMaxHopsAway",
10689 p->gtsm_hops);
10690 else if (p->ttl > 1)
10691 json_object_int_add(json_neigh,
10692 "externalBgpNbrMaxHopsAway",
10693 p->ttl);
10694 } else {
10695 if (p->gtsm_hops > 0)
10696 vty_out(vty,
10697 " External BGP neighbor may be up to %d hops away.\n",
10698 p->gtsm_hops);
10699 else if (p->ttl > 1)
10700 vty_out(vty,
10701 " External BGP neighbor may be up to %d hops away.\n",
10702 p->ttl);
10703 }
10704 } else {
10705 if (p->gtsm_hops > 0) {
10706 if (use_json)
10707 json_object_int_add(json_neigh,
10708 "internalBgpNbrMaxHopsAway",
10709 p->gtsm_hops);
10710 else
10711 vty_out(vty,
10712 " Internal BGP neighbor may be up to %d hops away.\n",
10713 p->gtsm_hops);
10714 }
10715 }
10716
10717 /* Local address. */
10718 if (p->su_local) {
10719 if (use_json) {
10720 json_object_string_add(json_neigh, "hostLocal",
10721 sockunion2str(p->su_local, buf1,
10722 SU_ADDRSTRLEN));
10723 json_object_int_add(json_neigh, "portLocal",
10724 ntohs(p->su_local->sin.sin_port));
10725 } else
10726 vty_out(vty, "Local host: %s, Local port: %d\n",
10727 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10728 ntohs(p->su_local->sin.sin_port));
10729 }
10730
10731 /* Remote address. */
10732 if (p->su_remote) {
10733 if (use_json) {
10734 json_object_string_add(json_neigh, "hostForeign",
10735 sockunion2str(p->su_remote, buf1,
10736 SU_ADDRSTRLEN));
10737 json_object_int_add(json_neigh, "portForeign",
10738 ntohs(p->su_remote->sin.sin_port));
10739 } else
10740 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10741 sockunion2str(p->su_remote, buf1,
10742 SU_ADDRSTRLEN),
10743 ntohs(p->su_remote->sin.sin_port));
10744 }
10745
10746 /* Nexthop display. */
10747 if (p->su_local) {
10748 if (use_json) {
10749 json_object_string_add(json_neigh, "nexthop",
10750 inet_ntop(AF_INET,
10751 &p->nexthop.v4, buf1,
10752 sizeof(buf1)));
10753 json_object_string_add(json_neigh, "nexthopGlobal",
10754 inet_ntop(AF_INET6,
10755 &p->nexthop.v6_global,
10756 buf1, sizeof(buf1)));
10757 json_object_string_add(json_neigh, "nexthopLocal",
10758 inet_ntop(AF_INET6,
10759 &p->nexthop.v6_local,
10760 buf1, sizeof(buf1)));
10761 if (p->shared_network)
10762 json_object_string_add(json_neigh,
10763 "bgpConnection",
10764 "sharedNetwork");
10765 else
10766 json_object_string_add(json_neigh,
10767 "bgpConnection",
10768 "nonSharedNetwork");
10769 } else {
10770 vty_out(vty, "Nexthop: %s\n",
10771 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10772 sizeof(buf1)));
10773 vty_out(vty, "Nexthop global: %s\n",
10774 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10775 sizeof(buf1)));
10776 vty_out(vty, "Nexthop local: %s\n",
10777 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10778 sizeof(buf1)));
10779 vty_out(vty, "BGP connection: %s\n",
10780 p->shared_network ? "shared network"
10781 : "non shared network");
10782 }
10783 }
10784
10785 /* Timer information. */
10786 if (use_json) {
10787 json_object_int_add(json_neigh, "connectRetryTimer",
10788 p->v_connect);
10789 if (p->status == Established && p->rtt)
10790 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10791 p->rtt);
10792 if (p->t_start)
10793 json_object_int_add(
10794 json_neigh, "nextStartTimerDueInMsecs",
10795 thread_timer_remain_second(p->t_start) * 1000);
10796 if (p->t_connect)
10797 json_object_int_add(
10798 json_neigh, "nextConnectTimerDueInMsecs",
10799 thread_timer_remain_second(p->t_connect)
10800 * 1000);
10801 if (p->t_routeadv) {
10802 json_object_int_add(json_neigh, "mraiInterval",
10803 p->v_routeadv);
10804 json_object_int_add(
10805 json_neigh, "mraiTimerExpireInMsecs",
10806 thread_timer_remain_second(p->t_routeadv)
10807 * 1000);
10808 }
10809 if (p->password)
10810 json_object_int_add(json_neigh, "authenticationEnabled",
10811 1);
10812
10813 if (p->t_read)
10814 json_object_string_add(json_neigh, "readThread", "on");
10815 else
10816 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10817
10818 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10819 json_object_string_add(json_neigh, "writeThread", "on");
10820 else
10821 json_object_string_add(json_neigh, "writeThread",
10822 "off");
10823 } else {
10824 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10825 p->v_connect);
10826 if (p->status == Established && p->rtt)
10827 vty_out(vty, "Estimated round trip time: %d ms\n",
10828 p->rtt);
10829 if (p->t_start)
10830 vty_out(vty, "Next start timer due in %ld seconds\n",
10831 thread_timer_remain_second(p->t_start));
10832 if (p->t_connect)
10833 vty_out(vty, "Next connect timer due in %ld seconds\n",
10834 thread_timer_remain_second(p->t_connect));
10835 if (p->t_routeadv)
10836 vty_out(vty,
10837 "MRAI (interval %u) timer expires in %ld seconds\n",
10838 p->v_routeadv,
10839 thread_timer_remain_second(p->t_routeadv));
10840 if (p->password)
10841 vty_out(vty, "Peer Authentication Enabled\n");
10842
10843 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10844 p->t_read ? "on" : "off",
10845 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10846 ? "on"
10847 : "off");
d62a17ae 10848 }
10849
10850 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10851 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10852 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10853
10854 if (!use_json)
10855 vty_out(vty, "\n");
10856
10857 /* BFD information. */
10858 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10859
10860 if (use_json) {
10861 if (p->conf_if) /* Configured interface name. */
10862 json_object_object_add(json, p->conf_if, json_neigh);
10863 else /* Configured IP address. */
10864 json_object_object_add(json, p->host, json_neigh);
10865 }
10866}
10867
10868static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10869 enum show_type type, union sockunion *su,
9f049418 10870 const char *conf_if, bool use_json,
d62a17ae 10871 json_object *json)
10872{
10873 struct listnode *node, *nnode;
10874 struct peer *peer;
10875 int find = 0;
9f049418 10876 bool nbr_output = false;
d62a17ae 10877
10878 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10879 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10880 continue;
10881
10882 switch (type) {
10883 case show_all:
10884 bgp_show_peer(vty, peer, use_json, json);
9f049418 10885 nbr_output = true;
d62a17ae 10886 break;
10887 case show_peer:
10888 if (conf_if) {
10889 if ((peer->conf_if
10890 && !strcmp(peer->conf_if, conf_if))
10891 || (peer->hostname
10892 && !strcmp(peer->hostname, conf_if))) {
10893 find = 1;
10894 bgp_show_peer(vty, peer, use_json,
10895 json);
10896 }
10897 } else {
10898 if (sockunion_same(&peer->su, su)) {
10899 find = 1;
10900 bgp_show_peer(vty, peer, use_json,
10901 json);
10902 }
10903 }
10904 break;
10905 }
10906 }
10907
10908 if (type == show_peer && !find) {
10909 if (use_json)
10910 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10911 else
88b7d255 10912 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10913 }
10914
9f049418 10915 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10916 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10917
d62a17ae 10918 if (use_json) {
996c9314
LB
10919 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10920 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10921 } else {
10922 vty_out(vty, "\n");
10923 }
10924
10925 return CMD_SUCCESS;
10926}
10927
10928static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10929 enum show_type type,
10930 const char *ip_str,
9f049418 10931 bool use_json)
d62a17ae 10932{
0291c246
MK
10933 struct listnode *node, *nnode;
10934 struct bgp *bgp;
71aedaa3 10935 union sockunion su;
0291c246 10936 json_object *json = NULL;
71aedaa3 10937 int ret, is_first = 1;
9f049418 10938 bool nbr_output = false;
d62a17ae 10939
10940 if (use_json)
10941 vty_out(vty, "{\n");
10942
10943 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10944 nbr_output = true;
d62a17ae 10945 if (use_json) {
10946 if (!(json = json_object_new_object())) {
af4c2728 10947 flog_err(
e50f7cfd 10948 EC_BGP_JSON_MEM_ERROR,
d62a17ae 10949 "Unable to allocate memory for JSON object");
10950 vty_out(vty,
10951 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10952 return;
10953 }
10954
10955 json_object_int_add(json, "vrfId",
10956 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10957 ? -1
10958 : (int64_t)bgp->vrf_id);
d62a17ae 10959 json_object_string_add(
10960 json, "vrfName",
10961 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10962 ? VRF_DEFAULT_NAME
d62a17ae 10963 : bgp->name);
10964
10965 if (!is_first)
10966 vty_out(vty, ",\n");
10967 else
10968 is_first = 0;
10969
10970 vty_out(vty, "\"%s\":",
10971 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10972 ? VRF_DEFAULT_NAME
d62a17ae 10973 : bgp->name);
10974 } else {
10975 vty_out(vty, "\nInstance %s:\n",
10976 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10977 ? VRF_DEFAULT_NAME
d62a17ae 10978 : bgp->name);
10979 }
71aedaa3
DS
10980
10981 if (type == show_peer) {
10982 ret = str2sockunion(ip_str, &su);
10983 if (ret < 0)
10984 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10985 use_json, json);
10986 else
10987 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10988 use_json, json);
10989 } else {
10990 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10991 use_json, json);
10992 }
d62a17ae 10993 }
10994
01cbfd04 10995 if (use_json) {
d62a17ae 10996 vty_out(vty, "}\n");
01cbfd04
QY
10997 json_object_free(json);
10998 }
9f049418
DS
10999 else if (!nbr_output)
11000 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11001}
11002
11003static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11004 enum show_type type, const char *ip_str,
9f049418 11005 bool use_json)
d62a17ae 11006{
11007 int ret;
11008 struct bgp *bgp;
11009 union sockunion su;
11010 json_object *json = NULL;
11011
11012 if (name) {
11013 if (strmatch(name, "all")) {
71aedaa3
DS
11014 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11015 use_json);
d62a17ae 11016 return CMD_SUCCESS;
11017 } else {
11018 bgp = bgp_lookup_by_name(name);
11019 if (!bgp) {
11020 if (use_json) {
11021 json = json_object_new_object();
d62a17ae 11022 vty_out(vty, "%s\n",
11023 json_object_to_json_string_ext(
11024 json,
11025 JSON_C_TO_STRING_PRETTY));
11026 json_object_free(json);
11027 } else
11028 vty_out(vty,
9f049418 11029 "%% BGP instance not found\n");
d62a17ae 11030
11031 return CMD_WARNING;
11032 }
11033 }
11034 } else {
11035 bgp = bgp_get_default();
11036 }
11037
11038 if (bgp) {
11039 json = json_object_new_object();
11040 if (ip_str) {
11041 ret = str2sockunion(ip_str, &su);
11042 if (ret < 0)
11043 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11044 use_json, json);
11045 else
11046 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11047 use_json, json);
11048 } else {
11049 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11050 json);
11051 }
11052 json_object_free(json);
ca61fd25
DS
11053 } else {
11054 if (use_json)
11055 vty_out(vty, "{}\n");
11056 else
11057 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11058 }
11059
11060 return CMD_SUCCESS;
4fb25c53
DW
11061}
11062
716b2d8a 11063/* "show [ip] bgp neighbors" commands. */
718e3744 11064DEFUN (show_ip_bgp_neighbors,
11065 show_ip_bgp_neighbors_cmd,
24345e82 11066 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11067 SHOW_STR
11068 IP_STR
11069 BGP_STR
f2a8972b 11070 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11071 "Address Family\n"
11072 "Address Family\n"
718e3744 11073 "Detailed information on TCP and BGP neighbor connections\n"
11074 "Neighbor to display information about\n"
a80beece 11075 "Neighbor to display information about\n"
91d37724 11076 "Neighbor on BGP configured interface\n"
9973d184 11077 JSON_STR)
718e3744 11078{
d62a17ae 11079 char *vrf = NULL;
11080 char *sh_arg = NULL;
11081 enum show_type sh_type;
718e3744 11082
9f049418 11083 bool uj = use_json(argc, argv);
718e3744 11084
d62a17ae 11085 int idx = 0;
718e3744 11086
9a8bdf1c
PG
11087 /* [<vrf> VIEWVRFNAME] */
11088 if (argv_find(argv, argc, "vrf", &idx)) {
11089 vrf = argv[idx + 1]->arg;
11090 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11091 vrf = NULL;
11092 } else if (argv_find(argv, argc, "view", &idx))
11093 /* [<view> VIEWVRFNAME] */
d62a17ae 11094 vrf = argv[idx + 1]->arg;
718e3744 11095
d62a17ae 11096 idx++;
11097 if (argv_find(argv, argc, "A.B.C.D", &idx)
11098 || argv_find(argv, argc, "X:X::X:X", &idx)
11099 || argv_find(argv, argc, "WORD", &idx)) {
11100 sh_type = show_peer;
11101 sh_arg = argv[idx]->arg;
11102 } else
11103 sh_type = show_all;
856ca177 11104
d62a17ae 11105 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11106}
11107
716b2d8a 11108/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11109 paths' and `show ip mbgp paths'. Those functions results are the
11110 same.*/
f412b39a 11111DEFUN (show_ip_bgp_paths,
718e3744 11112 show_ip_bgp_paths_cmd,
46f296b4 11113 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11114 SHOW_STR
11115 IP_STR
11116 BGP_STR
46f296b4 11117 BGP_SAFI_HELP_STR
718e3744 11118 "Path information\n")
11119{
d62a17ae 11120 vty_out(vty, "Address Refcnt Path\n");
11121 aspath_print_all_vty(vty);
11122 return CMD_SUCCESS;
718e3744 11123}
11124
718e3744 11125#include "hash.h"
11126
d62a17ae 11127static void community_show_all_iterator(struct hash_backet *backet,
11128 struct vty *vty)
718e3744 11129{
d62a17ae 11130 struct community *com;
718e3744 11131
d62a17ae 11132 com = (struct community *)backet->data;
3f65c5b1 11133 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11134 community_str(com, false));
718e3744 11135}
11136
11137/* Show BGP's community internal data. */
f412b39a 11138DEFUN (show_ip_bgp_community_info,
718e3744 11139 show_ip_bgp_community_info_cmd,
bec37ba5 11140 "show [ip] bgp community-info",
718e3744 11141 SHOW_STR
11142 IP_STR
11143 BGP_STR
11144 "List all bgp community information\n")
11145{
d62a17ae 11146 vty_out(vty, "Address Refcnt Community\n");
718e3744 11147
d62a17ae 11148 hash_iterate(community_hash(),
11149 (void (*)(struct hash_backet *,
11150 void *))community_show_all_iterator,
11151 vty);
718e3744 11152
d62a17ae 11153 return CMD_SUCCESS;
718e3744 11154}
11155
d62a17ae 11156static void lcommunity_show_all_iterator(struct hash_backet *backet,
11157 struct vty *vty)
57d187bc 11158{
d62a17ae 11159 struct lcommunity *lcom;
57d187bc 11160
d62a17ae 11161 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11162 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11163 lcommunity_str(lcom, false));
57d187bc
JS
11164}
11165
11166/* Show BGP's community internal data. */
11167DEFUN (show_ip_bgp_lcommunity_info,
11168 show_ip_bgp_lcommunity_info_cmd,
11169 "show ip bgp large-community-info",
11170 SHOW_STR
11171 IP_STR
11172 BGP_STR
11173 "List all bgp large-community information\n")
11174{
d62a17ae 11175 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11176
d62a17ae 11177 hash_iterate(lcommunity_hash(),
11178 (void (*)(struct hash_backet *,
11179 void *))lcommunity_show_all_iterator,
11180 vty);
57d187bc 11181
d62a17ae 11182 return CMD_SUCCESS;
57d187bc
JS
11183}
11184
11185
f412b39a 11186DEFUN (show_ip_bgp_attr_info,
718e3744 11187 show_ip_bgp_attr_info_cmd,
bec37ba5 11188 "show [ip] bgp attribute-info",
718e3744 11189 SHOW_STR
11190 IP_STR
11191 BGP_STR
11192 "List all bgp attribute information\n")
11193{
d62a17ae 11194 attr_show_all(vty);
11195 return CMD_SUCCESS;
718e3744 11196}
6b0655a2 11197
9f049418
DS
11198static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11199 safi_t safi, bool use_json)
53089bec 11200{
11201 struct bgp *bgp;
11202 struct listnode *node;
11203 char *vname;
11204 char buf1[INET6_ADDRSTRLEN];
11205 char *ecom_str;
11206 vpn_policy_direction_t dir;
11207
b46dfd20
DS
11208 if (use_json) {
11209 json_object *json = NULL;
11210 json_object *json_import_vrfs = NULL;
11211 json_object *json_export_vrfs = NULL;
11212
11213 json = json_object_new_object();
b46dfd20 11214
b46dfd20
DS
11215 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11216
53089bec 11217 if (!bgp) {
b46dfd20
DS
11218 vty_out(vty, "%s\n",
11219 json_object_to_json_string_ext(
11220 json,
11221 JSON_C_TO_STRING_PRETTY));
11222 json_object_free(json);
11223
53089bec 11224 return CMD_WARNING;
11225 }
b46dfd20 11226
94d4c685
DS
11227 /* Provide context for the block */
11228 json_object_string_add(json, "vrf", name ? name : "default");
11229 json_object_string_add(json, "afiSafi",
11230 afi_safi_print(afi, safi));
11231
b46dfd20
DS
11232 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11233 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11234 json_object_string_add(json, "importFromVrfs", "none");
11235 json_object_string_add(json, "importRts", "none");
11236 } else {
6ce24e52
DS
11237 json_import_vrfs = json_object_new_array();
11238
b46dfd20
DS
11239 for (ALL_LIST_ELEMENTS_RO(
11240 bgp->vpn_policy[afi].import_vrf,
11241 node, vname))
11242 json_object_array_add(json_import_vrfs,
11243 json_object_new_string(vname));
11244
11245 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11246 ecom_str = ecommunity_ecom2str(
11247 bgp->vpn_policy[afi].rtlist[dir],
11248 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11249 json_object_object_add(json, "importFromVrfs",
11250 json_import_vrfs);
11251 json_object_string_add(json, "importRts", ecom_str);
11252
11253 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11254 }
11255
11256 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11257 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11258 json_object_string_add(json, "exportToVrfs", "none");
11259 json_object_string_add(json, "routeDistinguisher",
11260 "none");
11261 json_object_string_add(json, "exportRts", "none");
11262 } else {
6ce24e52
DS
11263 json_export_vrfs = json_object_new_array();
11264
b46dfd20
DS
11265 for (ALL_LIST_ELEMENTS_RO(
11266 bgp->vpn_policy[afi].export_vrf,
11267 node, vname))
11268 json_object_array_add(json_export_vrfs,
11269 json_object_new_string(vname));
11270 json_object_object_add(json, "exportToVrfs",
11271 json_export_vrfs);
11272 json_object_string_add(json, "routeDistinguisher",
11273 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11274 buf1, RD_ADDRSTRLEN));
11275
11276 dir = BGP_VPN_POLICY_DIR_TOVPN;
11277 ecom_str = ecommunity_ecom2str(
11278 bgp->vpn_policy[afi].rtlist[dir],
11279 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11280 json_object_string_add(json, "exportRts", ecom_str);
11281
11282 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11283 }
11284
11285 vty_out(vty, "%s\n",
11286 json_object_to_json_string_ext(json,
11287 JSON_C_TO_STRING_PRETTY));
11288 json_object_free(json);
11289
53089bec 11290 } else {
b46dfd20
DS
11291 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11292
53089bec 11293 if (!bgp) {
b46dfd20 11294 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11295 return CMD_WARNING;
11296 }
53089bec 11297
b46dfd20
DS
11298 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11299 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11300 vty_out(vty,
11301 "This VRF is not importing %s routes from any other VRF\n",
11302 afi_safi_print(afi, safi));
11303 else {
11304 vty_out(vty,
11305 "This VRF is importing %s routes from the following VRFs:\n",
11306 afi_safi_print(afi, safi));
11307
11308 for (ALL_LIST_ELEMENTS_RO(
11309 bgp->vpn_policy[afi].import_vrf,
11310 node, vname))
11311 vty_out(vty, " %s\n", vname);
11312
11313 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11314 ecom_str = ecommunity_ecom2str(
11315 bgp->vpn_policy[afi].rtlist[dir],
11316 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11317 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11318
11319 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11320 }
53089bec 11321
b46dfd20
DS
11322 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11323 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11324 vty_out(vty,
11325 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11326 afi_safi_print(afi, safi));
b46dfd20
DS
11327 else {
11328 vty_out(vty,
04c9077f 11329 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11330 afi_safi_print(afi, safi));
b46dfd20
DS
11331
11332 for (ALL_LIST_ELEMENTS_RO(
11333 bgp->vpn_policy[afi].export_vrf,
11334 node, vname))
11335 vty_out(vty, " %s\n", vname);
11336
11337 vty_out(vty, "RD: %s\n",
11338 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11339 buf1, RD_ADDRSTRLEN));
11340
11341 dir = BGP_VPN_POLICY_DIR_TOVPN;
11342 ecom_str = ecommunity_ecom2str(
11343 bgp->vpn_policy[afi].rtlist[dir],
11344 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11345 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11346 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11347 }
53089bec 11348 }
11349
11350 return CMD_SUCCESS;
11351}
11352
11353/* "show [ip] bgp route-leak" command. */
11354DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11355 show_ip_bgp_route_leak_cmd,
11356 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11357 SHOW_STR
11358 IP_STR
11359 BGP_STR
11360 BGP_INSTANCE_HELP_STR
11361 BGP_AFI_HELP_STR
11362 BGP_SAFI_HELP_STR
11363 "Route leaking information\n"
11364 JSON_STR)
53089bec 11365{
11366 char *vrf = NULL;
11367 afi_t afi = AFI_MAX;
11368 safi_t safi = SAFI_MAX;
11369
9f049418 11370 bool uj = use_json(argc, argv);
53089bec 11371 int idx = 0;
11372
11373 /* show [ip] bgp */
11374 if (argv_find(argv, argc, "ip", &idx)) {
11375 afi = AFI_IP;
11376 safi = SAFI_UNICAST;
11377 }
11378 /* [vrf VIEWVRFNAME] */
11379 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11380 vty_out(vty,
11381 "%% This command is not applicable to BGP views\n");
53089bec 11382 return CMD_WARNING;
11383 }
11384
9a8bdf1c
PG
11385 if (argv_find(argv, argc, "vrf", &idx)) {
11386 vrf = argv[idx + 1]->arg;
11387 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11388 vrf = NULL;
11389 }
53089bec 11390 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11391 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11392 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11393 }
11394
11395 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11396 vty_out(vty,
11397 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11398 return CMD_WARNING;
11399 }
11400
b46dfd20 11401 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11402}
11403
d62a17ae 11404static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11405 safi_t safi)
f186de26 11406{
d62a17ae 11407 struct listnode *node, *nnode;
11408 struct bgp *bgp;
f186de26 11409
d62a17ae 11410 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11411 vty_out(vty, "\nInstance %s:\n",
11412 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11413 ? VRF_DEFAULT_NAME
d62a17ae 11414 : bgp->name);
11415 update_group_show(bgp, afi, safi, vty, 0);
11416 }
f186de26 11417}
11418
d62a17ae 11419static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11420 int safi, uint64_t subgrp_id)
4fb25c53 11421{
d62a17ae 11422 struct bgp *bgp;
4fb25c53 11423
d62a17ae 11424 if (name) {
11425 if (strmatch(name, "all")) {
11426 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11427 return CMD_SUCCESS;
11428 } else {
11429 bgp = bgp_lookup_by_name(name);
11430 }
11431 } else {
11432 bgp = bgp_get_default();
11433 }
4fb25c53 11434
d62a17ae 11435 if (bgp)
11436 update_group_show(bgp, afi, safi, vty, subgrp_id);
11437 return CMD_SUCCESS;
4fb25c53
DW
11438}
11439
8fe8a7f6
DS
11440DEFUN (show_ip_bgp_updgrps,
11441 show_ip_bgp_updgrps_cmd,
c1a44e43 11442 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11443 SHOW_STR
11444 IP_STR
11445 BGP_STR
11446 BGP_INSTANCE_HELP_STR
c9e571b4 11447 BGP_AFI_HELP_STR
9bedbb1e 11448 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11449 "Detailed info about dynamic update groups\n"
11450 "Specific subgroup to display detailed info for\n")
8386ac43 11451{
d62a17ae 11452 char *vrf = NULL;
11453 afi_t afi = AFI_IP6;
11454 safi_t safi = SAFI_UNICAST;
11455 uint64_t subgrp_id = 0;
11456
11457 int idx = 0;
11458
11459 /* show [ip] bgp */
11460 if (argv_find(argv, argc, "ip", &idx))
11461 afi = AFI_IP;
9a8bdf1c
PG
11462 /* [<vrf> VIEWVRFNAME] */
11463 if (argv_find(argv, argc, "vrf", &idx)) {
11464 vrf = argv[idx + 1]->arg;
11465 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11466 vrf = NULL;
11467 } else if (argv_find(argv, argc, "view", &idx))
11468 /* [<view> VIEWVRFNAME] */
11469 vrf = argv[idx + 1]->arg;
d62a17ae 11470 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11471 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11472 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11473 }
5bf15956 11474
d62a17ae 11475 /* get subgroup id, if provided */
11476 idx = argc - 1;
11477 if (argv[idx]->type == VARIABLE_TKN)
11478 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11479
d62a17ae 11480 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11481}
11482
f186de26 11483DEFUN (show_bgp_instance_all_ipv6_updgrps,
11484 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11485 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11486 SHOW_STR
716b2d8a 11487 IP_STR
f186de26 11488 BGP_STR
11489 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11490 "Detailed info about dynamic update groups\n")
f186de26 11491{
d62a17ae 11492 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11493 return CMD_SUCCESS;
f186de26 11494}
11495
43d3f4fc
DS
11496DEFUN (show_bgp_l2vpn_evpn_updgrps,
11497 show_bgp_l2vpn_evpn_updgrps_cmd,
11498 "show [ip] bgp l2vpn evpn update-groups",
11499 SHOW_STR
11500 IP_STR
11501 BGP_STR
11502 "l2vpn address family\n"
11503 "evpn sub-address family\n"
11504 "Detailed info about dynamic update groups\n")
11505{
11506 char *vrf = NULL;
11507 uint64_t subgrp_id = 0;
11508
11509 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11510 return CMD_SUCCESS;
11511}
11512
5bf15956
DW
11513DEFUN (show_bgp_updgrps_stats,
11514 show_bgp_updgrps_stats_cmd,
716b2d8a 11515 "show [ip] bgp update-groups statistics",
3f9c7369 11516 SHOW_STR
716b2d8a 11517 IP_STR
3f9c7369 11518 BGP_STR
0c7b1b01 11519 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11520 "Statistics\n")
11521{
d62a17ae 11522 struct bgp *bgp;
3f9c7369 11523
d62a17ae 11524 bgp = bgp_get_default();
11525 if (bgp)
11526 update_group_show_stats(bgp, vty);
3f9c7369 11527
d62a17ae 11528 return CMD_SUCCESS;
3f9c7369
DS
11529}
11530
8386ac43 11531DEFUN (show_bgp_instance_updgrps_stats,
11532 show_bgp_instance_updgrps_stats_cmd,
18c57037 11533 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11534 SHOW_STR
716b2d8a 11535 IP_STR
8386ac43 11536 BGP_STR
11537 BGP_INSTANCE_HELP_STR
0c7b1b01 11538 "Detailed info about dynamic update groups\n"
8386ac43 11539 "Statistics\n")
11540{
d62a17ae 11541 int idx_word = 3;
11542 struct bgp *bgp;
8386ac43 11543
d62a17ae 11544 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11545 if (bgp)
11546 update_group_show_stats(bgp, vty);
8386ac43 11547
d62a17ae 11548 return CMD_SUCCESS;
8386ac43 11549}
11550
d62a17ae 11551static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11552 afi_t afi, safi_t safi,
11553 const char *what, uint64_t subgrp_id)
3f9c7369 11554{
d62a17ae 11555 struct bgp *bgp;
8386ac43 11556
d62a17ae 11557 if (name)
11558 bgp = bgp_lookup_by_name(name);
11559 else
11560 bgp = bgp_get_default();
8386ac43 11561
d62a17ae 11562 if (bgp) {
11563 if (!strcmp(what, "advertise-queue"))
11564 update_group_show_adj_queue(bgp, afi, safi, vty,
11565 subgrp_id);
11566 else if (!strcmp(what, "advertised-routes"))
11567 update_group_show_advertised(bgp, afi, safi, vty,
11568 subgrp_id);
11569 else if (!strcmp(what, "packet-queue"))
11570 update_group_show_packet_queue(bgp, afi, safi, vty,
11571 subgrp_id);
11572 }
3f9c7369
DS
11573}
11574
dc64bdec
QY
11575DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11576 show_ip_bgp_instance_updgrps_adj_s_cmd,
11577 "show [ip]$ip bgp [<view|vrf> VIEWVRFNAME$vrf] [<ipv4|ipv6>$afi <unicast|multicast|vpn>$safi] update-groups [SUBGROUP-ID]$sgid <advertise-queue|advertised-routes|packet-queue>$rtq",
11578 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11579 BGP_SAFI_HELP_STR
11580 "Detailed info about dynamic update groups\n"
11581 "Specific subgroup to display info for\n"
11582 "Advertisement queue\n"
11583 "Announced routes\n"
11584 "Packet queue\n")
3f9c7369 11585{
dc64bdec
QY
11586 uint64_t subgrp_id = 0;
11587 afi_t afiz;
11588 safi_t safiz;
11589 if (sgid)
11590 subgrp_id = strtoull(sgid, NULL, 10);
11591
11592 if (!ip && !afi)
11593 afiz = AFI_IP6;
11594 if (!ip && afi)
11595 afiz = bgp_vty_afi_from_str(afi);
11596 if (ip && !afi)
11597 afiz = AFI_IP;
11598 if (ip && afi) {
11599 afiz = bgp_vty_afi_from_str(afi);
11600 if (afiz != AFI_IP)
11601 vty_out(vty,
11602 "%% Cannot specify both 'ip' and 'ipv6'\n");
11603 return CMD_WARNING;
11604 }
d62a17ae 11605
dc64bdec 11606 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11607
dc64bdec 11608 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11609 return CMD_SUCCESS;
11610}
11611
d62a17ae 11612static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11613{
11614 struct listnode *node, *nnode;
11615 struct prefix *range;
11616 struct peer *conf;
11617 struct peer *peer;
11618 char buf[PREFIX2STR_BUFFER];
11619 afi_t afi;
11620 safi_t safi;
11621 const char *peer_status;
11622 const char *af_str;
11623 int lr_count;
11624 int dynamic;
11625 int af_cfgd;
11626
11627 conf = group->conf;
11628
11629 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11630 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11631 conf->as);
11632 } else if (conf->as_type == AS_INTERNAL) {
11633 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11634 group->bgp->as);
11635 } else {
11636 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11637 }
f14e6fdb 11638
d62a17ae 11639 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11640 vty_out(vty, " Peer-group type is internal\n");
11641 else
11642 vty_out(vty, " Peer-group type is external\n");
11643
11644 /* Display AFs configured. */
11645 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11646 FOREACH_AFI_SAFI (afi, safi) {
11647 if (conf->afc[afi][safi]) {
11648 af_cfgd = 1;
11649 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11650 }
05c7a1cc 11651 }
d62a17ae 11652 if (!af_cfgd)
11653 vty_out(vty, " none\n");
11654 else
11655 vty_out(vty, "\n");
11656
11657 /* Display listen ranges (for dynamic neighbors), if any */
11658 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11659 if (afi == AFI_IP)
11660 af_str = "IPv4";
11661 else if (afi == AFI_IP6)
11662 af_str = "IPv6";
11663 else
11664 af_str = "???";
11665 lr_count = listcount(group->listen_range[afi]);
11666 if (lr_count) {
11667 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11668 af_str);
11669
11670
11671 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11672 nnode, range)) {
11673 prefix2str(range, buf, sizeof(buf));
11674 vty_out(vty, " %s\n", buf);
11675 }
11676 }
11677 }
f14e6fdb 11678
d62a17ae 11679 /* Display group members and their status */
11680 if (listcount(group->peer)) {
11681 vty_out(vty, " Peer-group members:\n");
11682 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11683 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11684 peer_status = "Idle (Admin)";
11685 else if (CHECK_FLAG(peer->sflags,
11686 PEER_STATUS_PREFIX_OVERFLOW))
11687 peer_status = "Idle (PfxCt)";
11688 else
11689 peer_status = lookup_msg(bgp_status_msg,
11690 peer->status, NULL);
11691
11692 dynamic = peer_dynamic_neighbor(peer);
11693 vty_out(vty, " %s %s %s \n", peer->host,
11694 dynamic ? "(dynamic)" : "", peer_status);
11695 }
11696 }
f14e6fdb 11697
d62a17ae 11698 return CMD_SUCCESS;
11699}
11700
ff9959b0
QY
11701static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11702 const char *group_name)
d62a17ae 11703{
ff9959b0 11704 struct bgp *bgp;
d62a17ae 11705 struct listnode *node, *nnode;
11706 struct peer_group *group;
ff9959b0
QY
11707 bool found = false;
11708
11709 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11710
11711 if (!bgp) {
9f049418 11712 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11713 return CMD_WARNING;
11714 }
d62a17ae 11715
11716 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11717 if (group_name) {
11718 if (strmatch(group->name, group_name)) {
d62a17ae 11719 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11720 found = true;
11721 break;
d62a17ae 11722 }
ff9959b0
QY
11723 } else {
11724 bgp_show_one_peer_group(vty, group);
d62a17ae 11725 }
f14e6fdb 11726 }
f14e6fdb 11727
ff9959b0 11728 if (group_name && !found)
d62a17ae 11729 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11730
d62a17ae 11731 return CMD_SUCCESS;
f14e6fdb
DS
11732}
11733
f14e6fdb
DS
11734DEFUN (show_ip_bgp_peer_groups,
11735 show_ip_bgp_peer_groups_cmd,
18c57037 11736 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11737 SHOW_STR
11738 IP_STR
11739 BGP_STR
8386ac43 11740 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11741 "Detailed information on BGP peer groups\n"
11742 "Peer group name\n")
f14e6fdb 11743{
d62a17ae 11744 char *vrf, *pg;
d62a17ae 11745 int idx = 0;
f14e6fdb 11746
a4d82a8a
PZ
11747 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11748 : NULL;
d62a17ae 11749 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11750
ff9959b0 11751 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11752}
3f9c7369 11753
d6e3c605 11754
718e3744 11755/* Redistribute VTY commands. */
11756
718e3744 11757DEFUN (bgp_redistribute_ipv4,
11758 bgp_redistribute_ipv4_cmd,
40d1cbfb 11759 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11760 "Redistribute information from another routing protocol\n"
ab0181ee 11761 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11762{
d62a17ae 11763 VTY_DECLVAR_CONTEXT(bgp, bgp);
11764 int idx_protocol = 1;
11765 int type;
718e3744 11766
d62a17ae 11767 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11768 if (type < 0) {
11769 vty_out(vty, "%% Invalid route type\n");
11770 return CMD_WARNING_CONFIG_FAILED;
11771 }
7f323236 11772
d62a17ae 11773 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11774 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11775}
11776
d62a17ae 11777ALIAS_HIDDEN(
11778 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11779 "redistribute " FRR_IP_REDIST_STR_BGPD,
11780 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11781
718e3744 11782DEFUN (bgp_redistribute_ipv4_rmap,
11783 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11784 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11785 "Redistribute information from another routing protocol\n"
ab0181ee 11786 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11787 "Route map reference\n"
11788 "Pointer to route-map entries\n")
11789{
d62a17ae 11790 VTY_DECLVAR_CONTEXT(bgp, bgp);
11791 int idx_protocol = 1;
11792 int idx_word = 3;
11793 int type;
11794 struct bgp_redist *red;
e923dd62 11795 bool changed;
1de27621
DA
11796 struct route_map *route_map = route_map_lookup_warn_noexist(
11797 vty, argv[idx_word]->arg);
718e3744 11798
d62a17ae 11799 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11800 if (type < 0) {
11801 vty_out(vty, "%% Invalid route type\n");
11802 return CMD_WARNING_CONFIG_FAILED;
11803 }
718e3744 11804
d62a17ae 11805 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11806 changed =
11807 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11808 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11809}
11810
d62a17ae 11811ALIAS_HIDDEN(
11812 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11813 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11814 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11815 "Route map reference\n"
11816 "Pointer to route-map entries\n")
596c17ba 11817
718e3744 11818DEFUN (bgp_redistribute_ipv4_metric,
11819 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11820 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11821 "Redistribute information from another routing protocol\n"
ab0181ee 11822 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11823 "Metric for redistributed routes\n"
11824 "Default metric\n")
11825{
d62a17ae 11826 VTY_DECLVAR_CONTEXT(bgp, bgp);
11827 int idx_protocol = 1;
11828 int idx_number = 3;
11829 int type;
d7c0a89a 11830 uint32_t metric;
d62a17ae 11831 struct bgp_redist *red;
e923dd62 11832 bool changed;
d62a17ae 11833
11834 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11835 if (type < 0) {
11836 vty_out(vty, "%% Invalid route type\n");
11837 return CMD_WARNING_CONFIG_FAILED;
11838 }
11839 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11840
11841 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11842 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11843 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11844}
11845
11846ALIAS_HIDDEN(
11847 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11848 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11849 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11850 "Metric for redistributed routes\n"
11851 "Default metric\n")
596c17ba 11852
718e3744 11853DEFUN (bgp_redistribute_ipv4_rmap_metric,
11854 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11855 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11856 "Redistribute information from another routing protocol\n"
ab0181ee 11857 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11858 "Route map reference\n"
11859 "Pointer to route-map entries\n"
11860 "Metric for redistributed routes\n"
11861 "Default metric\n")
11862{
d62a17ae 11863 VTY_DECLVAR_CONTEXT(bgp, bgp);
11864 int idx_protocol = 1;
11865 int idx_word = 3;
11866 int idx_number = 5;
11867 int type;
d7c0a89a 11868 uint32_t metric;
d62a17ae 11869 struct bgp_redist *red;
e923dd62 11870 bool changed;
1de27621
DA
11871 struct route_map *route_map =
11872 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11873
11874 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11875 if (type < 0) {
11876 vty_out(vty, "%% Invalid route type\n");
11877 return CMD_WARNING_CONFIG_FAILED;
11878 }
11879 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11880
11881 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11882 changed =
11883 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11884 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11885 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11886}
11887
11888ALIAS_HIDDEN(
11889 bgp_redistribute_ipv4_rmap_metric,
11890 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11891 "redistribute " FRR_IP_REDIST_STR_BGPD
11892 " route-map WORD metric (0-4294967295)",
11893 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11894 "Route map reference\n"
11895 "Pointer to route-map entries\n"
11896 "Metric for redistributed routes\n"
11897 "Default metric\n")
596c17ba 11898
718e3744 11899DEFUN (bgp_redistribute_ipv4_metric_rmap,
11900 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11901 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11902 "Redistribute information from another routing protocol\n"
ab0181ee 11903 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11904 "Metric for redistributed routes\n"
11905 "Default metric\n"
11906 "Route map reference\n"
11907 "Pointer to route-map entries\n")
11908{
d62a17ae 11909 VTY_DECLVAR_CONTEXT(bgp, bgp);
11910 int idx_protocol = 1;
11911 int idx_number = 3;
11912 int idx_word = 5;
11913 int type;
d7c0a89a 11914 uint32_t metric;
d62a17ae 11915 struct bgp_redist *red;
e923dd62 11916 bool changed;
1de27621
DA
11917 struct route_map *route_map =
11918 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11919
11920 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11921 if (type < 0) {
11922 vty_out(vty, "%% Invalid route type\n");
11923 return CMD_WARNING_CONFIG_FAILED;
11924 }
11925 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11926
11927 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11928 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
11929 changed |=
11930 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11931 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11932}
11933
11934ALIAS_HIDDEN(
11935 bgp_redistribute_ipv4_metric_rmap,
11936 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11937 "redistribute " FRR_IP_REDIST_STR_BGPD
11938 " metric (0-4294967295) route-map WORD",
11939 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11940 "Metric for redistributed routes\n"
11941 "Default metric\n"
11942 "Route map reference\n"
11943 "Pointer to route-map entries\n")
596c17ba 11944
7c8ff89e
DS
11945DEFUN (bgp_redistribute_ipv4_ospf,
11946 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11947 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11948 "Redistribute information from another routing protocol\n"
11949 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11950 "Non-main Kernel Routing Table\n"
11951 "Instance ID/Table ID\n")
7c8ff89e 11952{
d62a17ae 11953 VTY_DECLVAR_CONTEXT(bgp, bgp);
11954 int idx_ospf_table = 1;
11955 int idx_number = 2;
d7c0a89a
QY
11956 unsigned short instance;
11957 unsigned short protocol;
7c8ff89e 11958
d62a17ae 11959 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11960
d62a17ae 11961 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11962 protocol = ZEBRA_ROUTE_OSPF;
11963 else
11964 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11965
d62a17ae 11966 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11967 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11968}
11969
d62a17ae 11970ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11971 "redistribute <ospf|table> (1-65535)",
11972 "Redistribute information from another routing protocol\n"
11973 "Open Shortest Path First (OSPFv2)\n"
11974 "Non-main Kernel Routing Table\n"
11975 "Instance ID/Table ID\n")
596c17ba 11976
7c8ff89e
DS
11977DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11978 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11979 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11980 "Redistribute information from another routing protocol\n"
11981 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11982 "Non-main Kernel Routing Table\n"
11983 "Instance ID/Table ID\n"
7c8ff89e
DS
11984 "Route map reference\n"
11985 "Pointer to route-map entries\n")
11986{
d62a17ae 11987 VTY_DECLVAR_CONTEXT(bgp, bgp);
11988 int idx_ospf_table = 1;
11989 int idx_number = 2;
11990 int idx_word = 4;
11991 struct bgp_redist *red;
d7c0a89a 11992 unsigned short instance;
d62a17ae 11993 int protocol;
e923dd62 11994 bool changed;
1de27621
DA
11995 struct route_map *route_map =
11996 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11997
11998 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11999 protocol = ZEBRA_ROUTE_OSPF;
12000 else
12001 protocol = ZEBRA_ROUTE_TABLE;
12002
12003 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12004 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12005 changed =
12006 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12007 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12008}
12009
12010ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12011 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12012 "redistribute <ospf|table> (1-65535) route-map WORD",
12013 "Redistribute information from another routing protocol\n"
12014 "Open Shortest Path First (OSPFv2)\n"
12015 "Non-main Kernel Routing Table\n"
12016 "Instance ID/Table ID\n"
12017 "Route map reference\n"
12018 "Pointer to route-map entries\n")
596c17ba 12019
7c8ff89e
DS
12020DEFUN (bgp_redistribute_ipv4_ospf_metric,
12021 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12022 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12023 "Redistribute information from another routing protocol\n"
12024 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12025 "Non-main Kernel Routing Table\n"
12026 "Instance ID/Table ID\n"
7c8ff89e
DS
12027 "Metric for redistributed routes\n"
12028 "Default metric\n")
12029{
d62a17ae 12030 VTY_DECLVAR_CONTEXT(bgp, bgp);
12031 int idx_ospf_table = 1;
12032 int idx_number = 2;
12033 int idx_number_2 = 4;
d7c0a89a 12034 uint32_t metric;
d62a17ae 12035 struct bgp_redist *red;
d7c0a89a 12036 unsigned short instance;
d62a17ae 12037 int protocol;
e923dd62 12038 bool changed;
d62a17ae 12039
12040 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12041 protocol = ZEBRA_ROUTE_OSPF;
12042 else
12043 protocol = ZEBRA_ROUTE_TABLE;
12044
12045 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12046 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12047
12048 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12049 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12050 metric);
12051 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12052}
12053
12054ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12055 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12056 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12057 "Redistribute information from another routing protocol\n"
12058 "Open Shortest Path First (OSPFv2)\n"
12059 "Non-main Kernel Routing Table\n"
12060 "Instance ID/Table ID\n"
12061 "Metric for redistributed routes\n"
12062 "Default metric\n")
596c17ba 12063
7c8ff89e
DS
12064DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12065 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12066 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12067 "Redistribute information from another routing protocol\n"
12068 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12069 "Non-main Kernel Routing Table\n"
12070 "Instance ID/Table ID\n"
7c8ff89e
DS
12071 "Route map reference\n"
12072 "Pointer to route-map entries\n"
12073 "Metric for redistributed routes\n"
12074 "Default metric\n")
12075{
d62a17ae 12076 VTY_DECLVAR_CONTEXT(bgp, bgp);
12077 int idx_ospf_table = 1;
12078 int idx_number = 2;
12079 int idx_word = 4;
12080 int idx_number_2 = 6;
d7c0a89a 12081 uint32_t metric;
d62a17ae 12082 struct bgp_redist *red;
d7c0a89a 12083 unsigned short instance;
d62a17ae 12084 int protocol;
e923dd62 12085 bool changed;
1de27621
DA
12086 struct route_map *route_map =
12087 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12088
12089 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12090 protocol = ZEBRA_ROUTE_OSPF;
12091 else
12092 protocol = ZEBRA_ROUTE_TABLE;
12093
12094 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12095 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12096
12097 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12098 changed =
12099 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12100 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12101 metric);
12102 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12103}
12104
12105ALIAS_HIDDEN(
12106 bgp_redistribute_ipv4_ospf_rmap_metric,
12107 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12108 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12109 "Redistribute information from another routing protocol\n"
12110 "Open Shortest Path First (OSPFv2)\n"
12111 "Non-main Kernel Routing Table\n"
12112 "Instance ID/Table ID\n"
12113 "Route map reference\n"
12114 "Pointer to route-map entries\n"
12115 "Metric for redistributed routes\n"
12116 "Default metric\n")
596c17ba 12117
7c8ff89e
DS
12118DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12119 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12120 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12121 "Redistribute information from another routing protocol\n"
12122 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12123 "Non-main Kernel Routing Table\n"
12124 "Instance ID/Table ID\n"
7c8ff89e
DS
12125 "Metric for redistributed routes\n"
12126 "Default metric\n"
12127 "Route map reference\n"
12128 "Pointer to route-map entries\n")
12129{
d62a17ae 12130 VTY_DECLVAR_CONTEXT(bgp, bgp);
12131 int idx_ospf_table = 1;
12132 int idx_number = 2;
12133 int idx_number_2 = 4;
12134 int idx_word = 6;
d7c0a89a 12135 uint32_t metric;
d62a17ae 12136 struct bgp_redist *red;
d7c0a89a 12137 unsigned short instance;
d62a17ae 12138 int protocol;
e923dd62 12139 bool changed;
1de27621
DA
12140 struct route_map *route_map =
12141 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12142
12143 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12144 protocol = ZEBRA_ROUTE_OSPF;
12145 else
12146 protocol = ZEBRA_ROUTE_TABLE;
12147
12148 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12149 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12150
12151 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12152 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12153 metric);
1de27621
DA
12154 changed |=
12155 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12156 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12157}
12158
12159ALIAS_HIDDEN(
12160 bgp_redistribute_ipv4_ospf_metric_rmap,
12161 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12162 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12163 "Redistribute information from another routing protocol\n"
12164 "Open Shortest Path First (OSPFv2)\n"
12165 "Non-main Kernel Routing Table\n"
12166 "Instance ID/Table ID\n"
12167 "Metric for redistributed routes\n"
12168 "Default metric\n"
12169 "Route map reference\n"
12170 "Pointer to route-map entries\n")
596c17ba 12171
7c8ff89e
DS
12172DEFUN (no_bgp_redistribute_ipv4_ospf,
12173 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12174 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12175 NO_STR
12176 "Redistribute information from another routing protocol\n"
12177 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12178 "Non-main Kernel Routing Table\n"
31500417
DW
12179 "Instance ID/Table ID\n"
12180 "Metric for redistributed routes\n"
12181 "Default metric\n"
12182 "Route map reference\n"
12183 "Pointer to route-map entries\n")
7c8ff89e 12184{
d62a17ae 12185 VTY_DECLVAR_CONTEXT(bgp, bgp);
12186 int idx_ospf_table = 2;
12187 int idx_number = 3;
d7c0a89a 12188 unsigned short instance;
d62a17ae 12189 int protocol;
12190
12191 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12192 protocol = ZEBRA_ROUTE_OSPF;
12193 else
12194 protocol = ZEBRA_ROUTE_TABLE;
12195
12196 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12197 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12198}
12199
12200ALIAS_HIDDEN(
12201 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12202 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12203 NO_STR
12204 "Redistribute information from another routing protocol\n"
12205 "Open Shortest Path First (OSPFv2)\n"
12206 "Non-main Kernel Routing Table\n"
12207 "Instance ID/Table ID\n"
12208 "Metric for redistributed routes\n"
12209 "Default metric\n"
12210 "Route map reference\n"
12211 "Pointer to route-map entries\n")
596c17ba 12212
718e3744 12213DEFUN (no_bgp_redistribute_ipv4,
12214 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12215 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12216 NO_STR
12217 "Redistribute information from another routing protocol\n"
3b14d86e 12218 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12219 "Metric for redistributed routes\n"
12220 "Default metric\n"
12221 "Route map reference\n"
12222 "Pointer to route-map entries\n")
718e3744 12223{
d62a17ae 12224 VTY_DECLVAR_CONTEXT(bgp, bgp);
12225 int idx_protocol = 2;
12226 int type;
12227
12228 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12229 if (type < 0) {
12230 vty_out(vty, "%% Invalid route type\n");
12231 return CMD_WARNING_CONFIG_FAILED;
12232 }
12233 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12234}
12235
12236ALIAS_HIDDEN(
12237 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12238 "no redistribute " FRR_IP_REDIST_STR_BGPD
12239 " [metric (0-4294967295)] [route-map WORD]",
12240 NO_STR
12241 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12242 "Metric for redistributed routes\n"
12243 "Default metric\n"
12244 "Route map reference\n"
12245 "Pointer to route-map entries\n")
596c17ba 12246
718e3744 12247DEFUN (bgp_redistribute_ipv6,
12248 bgp_redistribute_ipv6_cmd,
40d1cbfb 12249 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12250 "Redistribute information from another routing protocol\n"
ab0181ee 12251 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12252{
d62a17ae 12253 VTY_DECLVAR_CONTEXT(bgp, bgp);
12254 int idx_protocol = 1;
12255 int type;
718e3744 12256
d62a17ae 12257 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12258 if (type < 0) {
12259 vty_out(vty, "%% Invalid route type\n");
12260 return CMD_WARNING_CONFIG_FAILED;
12261 }
718e3744 12262
d62a17ae 12263 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12264 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12265}
12266
12267DEFUN (bgp_redistribute_ipv6_rmap,
12268 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12269 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12270 "Redistribute information from another routing protocol\n"
ab0181ee 12271 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12272 "Route map reference\n"
12273 "Pointer to route-map entries\n")
12274{
d62a17ae 12275 VTY_DECLVAR_CONTEXT(bgp, bgp);
12276 int idx_protocol = 1;
12277 int idx_word = 3;
12278 int type;
12279 struct bgp_redist *red;
e923dd62 12280 bool changed;
1de27621
DA
12281 struct route_map *route_map =
12282 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12283
d62a17ae 12284 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12285 if (type < 0) {
12286 vty_out(vty, "%% Invalid route type\n");
12287 return CMD_WARNING_CONFIG_FAILED;
12288 }
718e3744 12289
d62a17ae 12290 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12291 changed =
12292 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12293 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12294}
12295
12296DEFUN (bgp_redistribute_ipv6_metric,
12297 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12298 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12299 "Redistribute information from another routing protocol\n"
ab0181ee 12300 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12301 "Metric for redistributed routes\n"
12302 "Default metric\n")
12303{
d62a17ae 12304 VTY_DECLVAR_CONTEXT(bgp, bgp);
12305 int idx_protocol = 1;
12306 int idx_number = 3;
12307 int type;
d7c0a89a 12308 uint32_t metric;
d62a17ae 12309 struct bgp_redist *red;
e923dd62 12310 bool changed;
d62a17ae 12311
12312 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12313 if (type < 0) {
12314 vty_out(vty, "%% Invalid route type\n");
12315 return CMD_WARNING_CONFIG_FAILED;
12316 }
12317 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12318
d62a17ae 12319 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12320 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12321 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12322}
12323
12324DEFUN (bgp_redistribute_ipv6_rmap_metric,
12325 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12326 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12327 "Redistribute information from another routing protocol\n"
ab0181ee 12328 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12329 "Route map reference\n"
12330 "Pointer to route-map entries\n"
12331 "Metric for redistributed routes\n"
12332 "Default metric\n")
12333{
d62a17ae 12334 VTY_DECLVAR_CONTEXT(bgp, bgp);
12335 int idx_protocol = 1;
12336 int idx_word = 3;
12337 int idx_number = 5;
12338 int type;
d7c0a89a 12339 uint32_t metric;
d62a17ae 12340 struct bgp_redist *red;
e923dd62 12341 bool changed;
1de27621
DA
12342 struct route_map *route_map =
12343 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12344
12345 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12346 if (type < 0) {
12347 vty_out(vty, "%% Invalid route type\n");
12348 return CMD_WARNING_CONFIG_FAILED;
12349 }
12350 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12351
d62a17ae 12352 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12353 changed =
12354 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12355 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12356 metric);
12357 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12358}
12359
12360DEFUN (bgp_redistribute_ipv6_metric_rmap,
12361 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12362 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12363 "Redistribute information from another routing protocol\n"
ab0181ee 12364 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12365 "Metric for redistributed routes\n"
12366 "Default metric\n"
12367 "Route map reference\n"
12368 "Pointer to route-map entries\n")
12369{
d62a17ae 12370 VTY_DECLVAR_CONTEXT(bgp, bgp);
12371 int idx_protocol = 1;
12372 int idx_number = 3;
12373 int idx_word = 5;
12374 int type;
d7c0a89a 12375 uint32_t metric;
d62a17ae 12376 struct bgp_redist *red;
e923dd62 12377 bool changed;
1de27621
DA
12378 struct route_map *route_map =
12379 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12380
12381 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12382 if (type < 0) {
12383 vty_out(vty, "%% Invalid route type\n");
12384 return CMD_WARNING_CONFIG_FAILED;
12385 }
12386 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12387
d62a17ae 12388 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12389 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12390 metric);
1de27621
DA
12391 changed |=
12392 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12393 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12394}
12395
12396DEFUN (no_bgp_redistribute_ipv6,
12397 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12398 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12399 NO_STR
12400 "Redistribute information from another routing protocol\n"
3b14d86e 12401 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12402 "Metric for redistributed routes\n"
12403 "Default metric\n"
12404 "Route map reference\n"
12405 "Pointer to route-map entries\n")
718e3744 12406{
d62a17ae 12407 VTY_DECLVAR_CONTEXT(bgp, bgp);
12408 int idx_protocol = 2;
12409 int type;
718e3744 12410
d62a17ae 12411 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12412 if (type < 0) {
12413 vty_out(vty, "%% Invalid route type\n");
12414 return CMD_WARNING_CONFIG_FAILED;
12415 }
718e3744 12416
d62a17ae 12417 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12418}
12419
2b791107 12420void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12421 safi_t safi)
d62a17ae 12422{
12423 int i;
12424
12425 /* Unicast redistribution only. */
12426 if (safi != SAFI_UNICAST)
2b791107 12427 return;
d62a17ae 12428
12429 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12430 /* Redistribute BGP does not make sense. */
12431 if (i != ZEBRA_ROUTE_BGP) {
12432 struct list *red_list;
12433 struct listnode *node;
12434 struct bgp_redist *red;
12435
12436 red_list = bgp->redist[afi][i];
12437 if (!red_list)
12438 continue;
12439
12440 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12441 /* "redistribute" configuration. */
12442 vty_out(vty, " redistribute %s",
12443 zebra_route_string(i));
12444 if (red->instance)
12445 vty_out(vty, " %d", red->instance);
12446 if (red->redist_metric_flag)
12447 vty_out(vty, " metric %u",
12448 red->redist_metric);
12449 if (red->rmap.name)
12450 vty_out(vty, " route-map %s",
12451 red->rmap.name);
12452 vty_out(vty, "\n");
12453 }
12454 }
12455 }
718e3744 12456}
6b0655a2 12457
b9c7bc5a
PZ
12458/* This is part of the address-family block (unicast only) */
12459void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12460 afi_t afi)
12461{
b9c7bc5a 12462 int indent = 2;
ddb5b488 12463
8a066a70
PG
12464 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12465 if (listcount(bgp->vpn_policy[afi].import_vrf))
12466 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12467 bgp->vpn_policy[afi]
bb4f6190 12468 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12469 else
12470 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12471 bgp->vpn_policy[afi]
12472 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12473 }
12a844a5
DS
12474 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12475 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12476 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12477 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12478 return;
12479
e70e9f8e
PZ
12480 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12481 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12482
12483 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12484
12485 } else {
12486 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12487 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12488 bgp->vpn_policy[afi].tovpn_label);
12489 }
ddb5b488
PZ
12490 }
12491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12492 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12493 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12494 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12495 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12496 sizeof(buf)));
12497 }
12498 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12499 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12500
12501 char buf[PREFIX_STRLEN];
12502 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12503 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12504 sizeof(buf))) {
12505
b9c7bc5a
PZ
12506 vty_out(vty, "%*snexthop vpn export %s\n",
12507 indent, "", buf);
ddb5b488
PZ
12508 }
12509 }
12510 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12511 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12512 && ecommunity_cmp(
12513 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12514 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12515
12516 char *b = ecommunity_ecom2str(
12517 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12518 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12519 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12520 XFREE(MTYPE_ECOMMUNITY_STR, b);
12521 } else {
12522 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12523 char *b = ecommunity_ecom2str(
12524 bgp->vpn_policy[afi]
12525 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12526 ECOMMUNITY_FORMAT_ROUTE_MAP,
12527 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12528 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12529 XFREE(MTYPE_ECOMMUNITY_STR, b);
12530 }
12531 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12532 char *b = ecommunity_ecom2str(
12533 bgp->vpn_policy[afi]
12534 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12535 ECOMMUNITY_FORMAT_ROUTE_MAP,
12536 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12537 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12538 XFREE(MTYPE_ECOMMUNITY_STR, b);
12539 }
12540 }
bb4f6190
DS
12541
12542 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12543 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12544 bgp->vpn_policy[afi]
12545 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12546
301ad80a
PG
12547 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12548 char *b = ecommunity_ecom2str(
12549 bgp->vpn_policy[afi]
12550 .import_redirect_rtlist,
12551 ECOMMUNITY_FORMAT_ROUTE_MAP,
12552 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12553
301ad80a
PG
12554 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12555 XFREE(MTYPE_ECOMMUNITY_STR, b);
12556 }
ddb5b488
PZ
12557}
12558
12559
718e3744 12560/* BGP node structure. */
d62a17ae 12561static struct cmd_node bgp_node = {
9d303b37 12562 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12563};
12564
d62a17ae 12565static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12566 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12567};
12568
d62a17ae 12569static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12570 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12571};
12572
d62a17ae 12573static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12574 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12575};
12576
d62a17ae 12577static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12578 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12579};
12580
d62a17ae 12581static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12582 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12583};
12584
d62a17ae 12585static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12586 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12587};
12588
d62a17ae 12589static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12590 "%s(config-router-af)# ", 1};
6b0655a2 12591
d62a17ae 12592static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12593 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12594
d62a17ae 12595static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12596 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12597
d62a17ae 12598static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12599 "%s(config-router-af-vni)# ", 1};
90e60aa7 12600
7c40bf39 12601static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12602 "%s(config-router-af)# ", 1};
12603
12604static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12605 "%s(config-router-af-vpnv6)# ", 1};
12606
d62a17ae 12607static void community_list_vty(void);
1f8ae70b 12608
d62a17ae 12609static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12610{
d62a17ae 12611 struct bgp *bgp;
12612 struct peer *peer;
d62a17ae 12613 struct listnode *lnbgp, *lnpeer;
b8a815e5 12614
d62a17ae 12615 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12616 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12617 /* only provide suggestions on the appropriate input
12618 * token type,
12619 * they'll otherwise show up multiple times */
12620 enum cmd_token_type match_type;
12621 char *name = peer->host;
d48ed3e0 12622
d62a17ae 12623 if (peer->conf_if) {
12624 match_type = VARIABLE_TKN;
12625 name = peer->conf_if;
12626 } else if (strchr(peer->host, ':'))
12627 match_type = IPV6_TKN;
12628 else
12629 match_type = IPV4_TKN;
d48ed3e0 12630
d62a17ae 12631 if (token->type != match_type)
12632 continue;
d48ed3e0 12633
d62a17ae 12634 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12635 }
d62a17ae 12636 }
b8a815e5
DL
12637}
12638
12639static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12640 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12641 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12642 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12643 {.completions = NULL}};
12644
47a306a0
DS
12645static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12646{
12647 struct bgp *bgp;
12648 struct peer_group *group;
12649 struct listnode *lnbgp, *lnpeer;
12650
12651 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12652 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12653 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12654 group->name));
12655 }
12656}
12657
12658static const struct cmd_variable_handler bgp_var_peergroup[] = {
12659 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12660 {.completions = NULL} };
12661
d62a17ae 12662void bgp_vty_init(void)
12663{
12664 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12665 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12666
12667 /* Install bgp top node. */
12668 install_node(&bgp_node, bgp_config_write);
12669 install_node(&bgp_ipv4_unicast_node, NULL);
12670 install_node(&bgp_ipv4_multicast_node, NULL);
12671 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12672 install_node(&bgp_ipv6_unicast_node, NULL);
12673 install_node(&bgp_ipv6_multicast_node, NULL);
12674 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12675 install_node(&bgp_vpnv4_node, NULL);
12676 install_node(&bgp_vpnv6_node, NULL);
12677 install_node(&bgp_evpn_node, NULL);
12678 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12679 install_node(&bgp_flowspecv4_node, NULL);
12680 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12681
12682 /* Install default VTY commands to new nodes. */
12683 install_default(BGP_NODE);
12684 install_default(BGP_IPV4_NODE);
12685 install_default(BGP_IPV4M_NODE);
12686 install_default(BGP_IPV4L_NODE);
12687 install_default(BGP_IPV6_NODE);
12688 install_default(BGP_IPV6M_NODE);
12689 install_default(BGP_IPV6L_NODE);
12690 install_default(BGP_VPNV4_NODE);
12691 install_default(BGP_VPNV6_NODE);
7c40bf39 12692 install_default(BGP_FLOWSPECV4_NODE);
12693 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12694 install_default(BGP_EVPN_NODE);
12695 install_default(BGP_EVPN_VNI_NODE);
12696
12697 /* "bgp multiple-instance" commands. */
12698 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12699 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12700
12701 /* "bgp config-type" commands. */
12702 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12703 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12704
8029b216
AK
12705 /* "bgp local-mac" hidden commands. */
12706 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12707 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12708
d62a17ae 12709 /* bgp route-map delay-timer commands. */
12710 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12711 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12712
12713 /* Dummy commands (Currently not supported) */
12714 install_element(BGP_NODE, &no_synchronization_cmd);
12715 install_element(BGP_NODE, &no_auto_summary_cmd);
12716
12717 /* "router bgp" commands. */
12718 install_element(CONFIG_NODE, &router_bgp_cmd);
12719
12720 /* "no router bgp" commands. */
12721 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12722
12723 /* "bgp router-id" commands. */
12724 install_element(BGP_NODE, &bgp_router_id_cmd);
12725 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12726
12727 /* "bgp cluster-id" commands. */
12728 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12729 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12730
12731 /* "bgp confederation" commands. */
12732 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12733 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12734
12735 /* "bgp confederation peers" commands. */
12736 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12737 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12738
12739 /* bgp max-med command */
12740 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12741 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12742 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12743 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12744 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12745
12746 /* bgp disable-ebgp-connected-nh-check */
12747 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12748 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12749
12750 /* bgp update-delay command */
12751 install_element(BGP_NODE, &bgp_update_delay_cmd);
12752 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12753 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12754
12755 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12756 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12757 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12758 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12759
12760 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12761 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12762
12763 /* "maximum-paths" commands. */
12764 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12765 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12766 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12767 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12768 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12769 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12770 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12771 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12772 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12773 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12774 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12775 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12776 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12777 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12778 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12779
12780 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12781 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12782 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12783 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12784 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12785
12786 /* "timers bgp" commands. */
12787 install_element(BGP_NODE, &bgp_timers_cmd);
12788 install_element(BGP_NODE, &no_bgp_timers_cmd);
12789
12790 /* route-map delay-timer commands - per instance for backwards compat.
12791 */
12792 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12793 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12794
12795 /* "bgp client-to-client reflection" commands */
12796 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12797 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12798
12799 /* "bgp always-compare-med" commands */
12800 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12801 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12802
12803 /* "bgp deterministic-med" commands */
12804 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12805 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12806
12807 /* "bgp graceful-restart" commands */
12808 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12809 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12810 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12811 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12812 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12813 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12814
12815 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12816 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12817
7f323236
DW
12818 /* "bgp graceful-shutdown" commands */
12819 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12820 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12821
d62a17ae 12822 /* "bgp fast-external-failover" commands */
12823 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12824 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12825
12826 /* "bgp enforce-first-as" commands */
12827 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12828
12829 /* "bgp bestpath compare-routerid" commands */
12830 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12831 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12832
12833 /* "bgp bestpath as-path ignore" commands */
12834 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12835 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12836
12837 /* "bgp bestpath as-path confed" commands */
12838 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12839 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12840
12841 /* "bgp bestpath as-path multipath-relax" commands */
12842 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12843 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12844
12845 /* "bgp log-neighbor-changes" commands */
12846 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12847 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12848
12849 /* "bgp bestpath med" commands */
12850 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12851 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12852
12853 /* "no bgp default ipv4-unicast" commands. */
12854 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12855 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12856
12857 /* "bgp network import-check" commands. */
12858 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12859 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12860 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12861
12862 /* "bgp default local-preference" commands. */
12863 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12864 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12865
12866 /* bgp default show-hostname */
12867 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12868 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12869
12870 /* "bgp default subgroup-pkt-queue-max" commands. */
12871 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12872 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12873
12874 /* bgp ibgp-allow-policy-mods command */
12875 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12876 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12877
12878 /* "bgp listen limit" commands. */
12879 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12880 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12881
12882 /* "bgp listen range" commands. */
12883 install_element(BGP_NODE, &bgp_listen_range_cmd);
12884 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12885
8175f54a 12886 /* "bgp default shutdown" command */
f26845f9
QY
12887 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12888
d62a17ae 12889 /* "neighbor remote-as" commands. */
12890 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12891 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12892 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12893 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12894 install_element(BGP_NODE,
12895 &neighbor_interface_v6only_config_remote_as_cmd);
12896 install_element(BGP_NODE, &no_neighbor_cmd);
12897 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12898
12899 /* "neighbor peer-group" commands. */
12900 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12901 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12902 install_element(BGP_NODE,
12903 &no_neighbor_interface_peer_group_remote_as_cmd);
12904
12905 /* "neighbor local-as" commands. */
12906 install_element(BGP_NODE, &neighbor_local_as_cmd);
12907 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12908 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12909 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12910
12911 /* "neighbor solo" commands. */
12912 install_element(BGP_NODE, &neighbor_solo_cmd);
12913 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12914
12915 /* "neighbor password" commands. */
12916 install_element(BGP_NODE, &neighbor_password_cmd);
12917 install_element(BGP_NODE, &no_neighbor_password_cmd);
12918
12919 /* "neighbor activate" commands. */
12920 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12921 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12922 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12923 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12924 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12925 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12926 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12927 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12928 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12929 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12930 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12931 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12932
12933 /* "no neighbor activate" commands. */
12934 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12935 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12936 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12937 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12938 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12939 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12940 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12941 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12942 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12943 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12944 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12945 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12946
12947 /* "neighbor peer-group" set commands. */
12948 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12949 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12950 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12951 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12952 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12953 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12954 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12955 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12956 install_element(BGP_FLOWSPECV4_NODE,
12957 &neighbor_set_peer_group_hidden_cmd);
12958 install_element(BGP_FLOWSPECV6_NODE,
12959 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12960
12961 /* "no neighbor peer-group unset" commands. */
12962 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12963 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12964 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12965 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12966 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12967 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12968 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12969 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12970 install_element(BGP_FLOWSPECV4_NODE,
12971 &no_neighbor_set_peer_group_hidden_cmd);
12972 install_element(BGP_FLOWSPECV6_NODE,
12973 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12974
12975 /* "neighbor softreconfiguration inbound" commands.*/
12976 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12977 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12978 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12979 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12980 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12981 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12982 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12983 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12984 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12985 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12986 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12987 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12988 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12989 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12990 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12991 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12992 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12993 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12994 install_element(BGP_FLOWSPECV4_NODE,
12995 &neighbor_soft_reconfiguration_cmd);
12996 install_element(BGP_FLOWSPECV4_NODE,
12997 &no_neighbor_soft_reconfiguration_cmd);
12998 install_element(BGP_FLOWSPECV6_NODE,
12999 &neighbor_soft_reconfiguration_cmd);
13000 install_element(BGP_FLOWSPECV6_NODE,
13001 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13002
13003 /* "neighbor attribute-unchanged" commands. */
13004 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13005 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13006 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13007 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13008 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13009 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13010 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13011 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13012 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13013 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13014 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13015 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13016 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13017 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13018 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13019 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13020 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13021 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13022
13023 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13024 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13025
13026 /* "nexthop-local unchanged" commands */
13027 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13028 install_element(BGP_IPV6_NODE,
13029 &no_neighbor_nexthop_local_unchanged_cmd);
13030
13031 /* "neighbor next-hop-self" commands. */
13032 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13033 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13034 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13035 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13036 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13037 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13038 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13039 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13040 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13041 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13042 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13043 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13044 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13045 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13046 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13047 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13048 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13049 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13050 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13051 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13052
13053 /* "neighbor next-hop-self force" commands. */
13054 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13055 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13056 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13057 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13058 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13059 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13060 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13061 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13062 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13063 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13064 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13065 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13066 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13067 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13068 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13069 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13070 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13071 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13072
13073 /* "neighbor as-override" commands. */
13074 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13075 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13076 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13077 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13078 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13079 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13080 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13081 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13082 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13083 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13084 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13085 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13086 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13087 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13088 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13089 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13090 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13091 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13092
13093 /* "neighbor remove-private-AS" commands. */
13094 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13095 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13096 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13097 install_element(BGP_NODE,
13098 &no_neighbor_remove_private_as_all_hidden_cmd);
13099 install_element(BGP_NODE,
13100 &neighbor_remove_private_as_replace_as_hidden_cmd);
13101 install_element(BGP_NODE,
13102 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13103 install_element(BGP_NODE,
13104 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13105 install_element(
13106 BGP_NODE,
13107 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13108 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13109 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13110 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13111 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13112 install_element(BGP_IPV4_NODE,
13113 &neighbor_remove_private_as_replace_as_cmd);
13114 install_element(BGP_IPV4_NODE,
13115 &no_neighbor_remove_private_as_replace_as_cmd);
13116 install_element(BGP_IPV4_NODE,
13117 &neighbor_remove_private_as_all_replace_as_cmd);
13118 install_element(BGP_IPV4_NODE,
13119 &no_neighbor_remove_private_as_all_replace_as_cmd);
13120 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13121 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13122 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13123 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13124 install_element(BGP_IPV4M_NODE,
13125 &neighbor_remove_private_as_replace_as_cmd);
13126 install_element(BGP_IPV4M_NODE,
13127 &no_neighbor_remove_private_as_replace_as_cmd);
13128 install_element(BGP_IPV4M_NODE,
13129 &neighbor_remove_private_as_all_replace_as_cmd);
13130 install_element(BGP_IPV4M_NODE,
13131 &no_neighbor_remove_private_as_all_replace_as_cmd);
13132 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13133 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13134 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13136 install_element(BGP_IPV4L_NODE,
13137 &neighbor_remove_private_as_replace_as_cmd);
13138 install_element(BGP_IPV4L_NODE,
13139 &no_neighbor_remove_private_as_replace_as_cmd);
13140 install_element(BGP_IPV4L_NODE,
13141 &neighbor_remove_private_as_all_replace_as_cmd);
13142 install_element(BGP_IPV4L_NODE,
13143 &no_neighbor_remove_private_as_all_replace_as_cmd);
13144 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13145 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13146 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13147 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13148 install_element(BGP_IPV6_NODE,
13149 &neighbor_remove_private_as_replace_as_cmd);
13150 install_element(BGP_IPV6_NODE,
13151 &no_neighbor_remove_private_as_replace_as_cmd);
13152 install_element(BGP_IPV6_NODE,
13153 &neighbor_remove_private_as_all_replace_as_cmd);
13154 install_element(BGP_IPV6_NODE,
13155 &no_neighbor_remove_private_as_all_replace_as_cmd);
13156 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13157 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13158 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13159 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13160 install_element(BGP_IPV6M_NODE,
13161 &neighbor_remove_private_as_replace_as_cmd);
13162 install_element(BGP_IPV6M_NODE,
13163 &no_neighbor_remove_private_as_replace_as_cmd);
13164 install_element(BGP_IPV6M_NODE,
13165 &neighbor_remove_private_as_all_replace_as_cmd);
13166 install_element(BGP_IPV6M_NODE,
13167 &no_neighbor_remove_private_as_all_replace_as_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13169 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13170 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13171 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13172 install_element(BGP_IPV6L_NODE,
13173 &neighbor_remove_private_as_replace_as_cmd);
13174 install_element(BGP_IPV6L_NODE,
13175 &no_neighbor_remove_private_as_replace_as_cmd);
13176 install_element(BGP_IPV6L_NODE,
13177 &neighbor_remove_private_as_all_replace_as_cmd);
13178 install_element(BGP_IPV6L_NODE,
13179 &no_neighbor_remove_private_as_all_replace_as_cmd);
13180 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13181 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13182 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13183 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13184 install_element(BGP_VPNV4_NODE,
13185 &neighbor_remove_private_as_replace_as_cmd);
13186 install_element(BGP_VPNV4_NODE,
13187 &no_neighbor_remove_private_as_replace_as_cmd);
13188 install_element(BGP_VPNV4_NODE,
13189 &neighbor_remove_private_as_all_replace_as_cmd);
13190 install_element(BGP_VPNV4_NODE,
13191 &no_neighbor_remove_private_as_all_replace_as_cmd);
13192 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13193 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13194 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13195 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13196 install_element(BGP_VPNV6_NODE,
13197 &neighbor_remove_private_as_replace_as_cmd);
13198 install_element(BGP_VPNV6_NODE,
13199 &no_neighbor_remove_private_as_replace_as_cmd);
13200 install_element(BGP_VPNV6_NODE,
13201 &neighbor_remove_private_as_all_replace_as_cmd);
13202 install_element(BGP_VPNV6_NODE,
13203 &no_neighbor_remove_private_as_all_replace_as_cmd);
13204
13205 /* "neighbor send-community" commands.*/
13206 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13207 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13208 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13209 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13210 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13211 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13212 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13213 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13214 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13215 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13216 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13217 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13218 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13219 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13220 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13221 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13222 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13223 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13224 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13225 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13226 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13227 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13228 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13229 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13230 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13231 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13232 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13233 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13234 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13235 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13236 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13237 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13238 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13239 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13240 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13241 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13242
13243 /* "neighbor route-reflector" commands.*/
13244 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13245 install_element(BGP_NODE,
13246 &no_neighbor_route_reflector_client_hidden_cmd);
13247 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13248 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13249 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13250 install_element(BGP_IPV4M_NODE,
13251 &no_neighbor_route_reflector_client_cmd);
13252 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13253 install_element(BGP_IPV4L_NODE,
13254 &no_neighbor_route_reflector_client_cmd);
13255 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13256 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13257 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13258 install_element(BGP_IPV6M_NODE,
13259 &no_neighbor_route_reflector_client_cmd);
13260 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13261 install_element(BGP_IPV6L_NODE,
13262 &no_neighbor_route_reflector_client_cmd);
13263 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13264 install_element(BGP_VPNV4_NODE,
13265 &no_neighbor_route_reflector_client_cmd);
13266 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13267 install_element(BGP_VPNV6_NODE,
13268 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13269 install_element(BGP_FLOWSPECV4_NODE,
13270 &neighbor_route_reflector_client_cmd);
13271 install_element(BGP_FLOWSPECV4_NODE,
13272 &no_neighbor_route_reflector_client_cmd);
13273 install_element(BGP_FLOWSPECV6_NODE,
13274 &neighbor_route_reflector_client_cmd);
13275 install_element(BGP_FLOWSPECV6_NODE,
13276 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13277 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13278 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13279
13280 /* "neighbor route-server" commands.*/
13281 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13282 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13283 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13284 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13285 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13286 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13287 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13288 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13289 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13290 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13291 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13292 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13293 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13294 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13296 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13297 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13298 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13299 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13300 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13301 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13302 install_element(BGP_FLOWSPECV4_NODE,
13303 &no_neighbor_route_server_client_cmd);
13304 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13305 install_element(BGP_FLOWSPECV6_NODE,
13306 &no_neighbor_route_server_client_cmd);
d62a17ae 13307
13308 /* "neighbor addpath-tx-all-paths" commands.*/
13309 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13310 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13311 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13312 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13313 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13314 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13315 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13316 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13317 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13318 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13319 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13320 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13321 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13322 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13323 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13324 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13325 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13326 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13327
13328 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13329 install_element(BGP_NODE,
13330 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13331 install_element(BGP_NODE,
13332 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13333 install_element(BGP_IPV4_NODE,
13334 &neighbor_addpath_tx_bestpath_per_as_cmd);
13335 install_element(BGP_IPV4_NODE,
13336 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13337 install_element(BGP_IPV4M_NODE,
13338 &neighbor_addpath_tx_bestpath_per_as_cmd);
13339 install_element(BGP_IPV4M_NODE,
13340 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13341 install_element(BGP_IPV4L_NODE,
13342 &neighbor_addpath_tx_bestpath_per_as_cmd);
13343 install_element(BGP_IPV4L_NODE,
13344 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13345 install_element(BGP_IPV6_NODE,
13346 &neighbor_addpath_tx_bestpath_per_as_cmd);
13347 install_element(BGP_IPV6_NODE,
13348 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13349 install_element(BGP_IPV6M_NODE,
13350 &neighbor_addpath_tx_bestpath_per_as_cmd);
13351 install_element(BGP_IPV6M_NODE,
13352 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13353 install_element(BGP_IPV6L_NODE,
13354 &neighbor_addpath_tx_bestpath_per_as_cmd);
13355 install_element(BGP_IPV6L_NODE,
13356 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13357 install_element(BGP_VPNV4_NODE,
13358 &neighbor_addpath_tx_bestpath_per_as_cmd);
13359 install_element(BGP_VPNV4_NODE,
13360 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13361 install_element(BGP_VPNV6_NODE,
13362 &neighbor_addpath_tx_bestpath_per_as_cmd);
13363 install_element(BGP_VPNV6_NODE,
13364 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13365
13366 /* "neighbor passive" commands. */
13367 install_element(BGP_NODE, &neighbor_passive_cmd);
13368 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13369
13370
13371 /* "neighbor shutdown" commands. */
13372 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13373 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13374 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13375 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13376
13377 /* "neighbor capability extended-nexthop" commands.*/
13378 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13379 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13380
13381 /* "neighbor capability orf prefix-list" commands.*/
13382 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13383 install_element(BGP_NODE,
13384 &no_neighbor_capability_orf_prefix_hidden_cmd);
13385 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13386 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13387 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13388 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13389 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13390 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13391 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13392 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13393 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13394 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13395 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13396 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13397
13398 /* "neighbor capability dynamic" commands.*/
13399 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13400 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13401
13402 /* "neighbor dont-capability-negotiate" commands. */
13403 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13404 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13405
13406 /* "neighbor ebgp-multihop" commands. */
13407 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13408 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13409 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13410
13411 /* "neighbor disable-connected-check" commands. */
13412 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13413 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13414
47cbc09b
PM
13415 /* "neighbor enforce-first-as" commands. */
13416 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13417 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13418
d62a17ae 13419 /* "neighbor description" commands. */
13420 install_element(BGP_NODE, &neighbor_description_cmd);
13421 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13422 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13423
13424 /* "neighbor update-source" commands. "*/
13425 install_element(BGP_NODE, &neighbor_update_source_cmd);
13426 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13427
13428 /* "neighbor default-originate" commands. */
13429 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13430 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13431 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13432 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13433 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13434 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13435 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13436 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13437 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13438 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13439 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13440 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13441 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13442 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13443 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13444 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13445 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13446 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13447 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13448 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13449 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13450
13451 /* "neighbor port" commands. */
13452 install_element(BGP_NODE, &neighbor_port_cmd);
13453 install_element(BGP_NODE, &no_neighbor_port_cmd);
13454
13455 /* "neighbor weight" commands. */
13456 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13457 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13458
13459 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13460 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13461 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13462 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13463 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13464 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13465 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13466 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13467 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13468 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13469 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13470 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13471 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13472 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13473 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13474 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13475
13476 /* "neighbor override-capability" commands. */
13477 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13478 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13479
13480 /* "neighbor strict-capability-match" commands. */
13481 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13482 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13483
13484 /* "neighbor timers" commands. */
13485 install_element(BGP_NODE, &neighbor_timers_cmd);
13486 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13487
13488 /* "neighbor timers connect" commands. */
13489 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13490 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13491
13492 /* "neighbor advertisement-interval" commands. */
13493 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13494 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13495
13496 /* "neighbor interface" commands. */
13497 install_element(BGP_NODE, &neighbor_interface_cmd);
13498 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13499
13500 /* "neighbor distribute" commands. */
13501 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13502 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13503 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13504 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13505 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13506 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13507 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13508 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13509 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13510 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13511 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13512 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13513 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13514 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13515 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13516 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13517 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13518 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13519
13520 /* "neighbor prefix-list" commands. */
13521 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13522 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13523 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13524 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13525 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13526 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13527 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13528 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13529 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13530 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13531 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13532 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13533 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13534 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13535 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13536 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13537 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13538 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13539 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13540 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13541 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13542 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13543
13544 /* "neighbor filter-list" commands. */
13545 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13546 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13547 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13548 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13549 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13550 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13551 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13552 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13553 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13554 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13555 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13556 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13557 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13558 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13559 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13560 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13561 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13562 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13563 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13564 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13565 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13566 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13567
13568 /* "neighbor route-map" commands. */
13569 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13570 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13571 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13572 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13573 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13574 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13575 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13576 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13577 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13578 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13579 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13580 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13581 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13582 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13583 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13584 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13585 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13586 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13587 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13588 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13589 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13590 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13591 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13592 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13593
13594 /* "neighbor unsuppress-map" commands. */
13595 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13596 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13597 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13598 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13599 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13600 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13601 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13602 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13603 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13604 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13605 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13606 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13607 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13608 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13609 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13610 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13611 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13612 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13613
13614 /* "neighbor maximum-prefix" commands. */
13615 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13616 install_element(BGP_NODE,
13617 &neighbor_maximum_prefix_threshold_hidden_cmd);
13618 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13619 install_element(BGP_NODE,
13620 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13621 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13622 install_element(BGP_NODE,
13623 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13624 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13625 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13627 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13628 install_element(BGP_IPV4_NODE,
13629 &neighbor_maximum_prefix_threshold_warning_cmd);
13630 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13631 install_element(BGP_IPV4_NODE,
13632 &neighbor_maximum_prefix_threshold_restart_cmd);
13633 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13634 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13635 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13637 install_element(BGP_IPV4M_NODE,
13638 &neighbor_maximum_prefix_threshold_warning_cmd);
13639 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13640 install_element(BGP_IPV4M_NODE,
13641 &neighbor_maximum_prefix_threshold_restart_cmd);
13642 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13643 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13644 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13645 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13646 install_element(BGP_IPV4L_NODE,
13647 &neighbor_maximum_prefix_threshold_warning_cmd);
13648 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13649 install_element(BGP_IPV4L_NODE,
13650 &neighbor_maximum_prefix_threshold_restart_cmd);
13651 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13652 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13653 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13654 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13655 install_element(BGP_IPV6_NODE,
13656 &neighbor_maximum_prefix_threshold_warning_cmd);
13657 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13658 install_element(BGP_IPV6_NODE,
13659 &neighbor_maximum_prefix_threshold_restart_cmd);
13660 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13661 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13662 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13663 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13664 install_element(BGP_IPV6M_NODE,
13665 &neighbor_maximum_prefix_threshold_warning_cmd);
13666 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13667 install_element(BGP_IPV6M_NODE,
13668 &neighbor_maximum_prefix_threshold_restart_cmd);
13669 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13670 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13671 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13672 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13673 install_element(BGP_IPV6L_NODE,
13674 &neighbor_maximum_prefix_threshold_warning_cmd);
13675 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13676 install_element(BGP_IPV6L_NODE,
13677 &neighbor_maximum_prefix_threshold_restart_cmd);
13678 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13679 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13680 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13681 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13682 install_element(BGP_VPNV4_NODE,
13683 &neighbor_maximum_prefix_threshold_warning_cmd);
13684 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13685 install_element(BGP_VPNV4_NODE,
13686 &neighbor_maximum_prefix_threshold_restart_cmd);
13687 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13688 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13689 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13690 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13691 install_element(BGP_VPNV6_NODE,
13692 &neighbor_maximum_prefix_threshold_warning_cmd);
13693 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13694 install_element(BGP_VPNV6_NODE,
13695 &neighbor_maximum_prefix_threshold_restart_cmd);
13696 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13697
13698 /* "neighbor allowas-in" */
13699 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13700 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13701 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13702 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13703 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13704 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13705 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13706 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13707 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13708 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13709 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13710 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13711 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13712 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13713 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13714 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13715 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13716 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13717 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13718 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13719
13720 /* address-family commands. */
13721 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13722 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13723#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13724 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13725 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13726#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13727
d62a17ae 13728 install_element(BGP_NODE, &address_family_evpn_cmd);
13729
13730 /* "exit-address-family" command. */
13731 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13732 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13733 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13734 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13735 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13736 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13737 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13738 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13739 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13740 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13741 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13742
13743 /* "clear ip bgp commands" */
13744 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13745
13746 /* clear ip bgp prefix */
13747 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13748 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13749 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13750
13751 /* "show [ip] bgp summary" commands. */
13752 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13753 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13754 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13755 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13756 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13757 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13758 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13759
13760 /* "show [ip] bgp neighbors" commands. */
13761 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13762
13763 /* "show [ip] bgp peer-group" commands. */
13764 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13765
13766 /* "show [ip] bgp paths" commands. */
13767 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13768
13769 /* "show [ip] bgp community" commands. */
13770 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13771
13772 /* "show ip bgp large-community" commands. */
13773 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13774 /* "show [ip] bgp attribute-info" commands. */
13775 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13776 /* "show [ip] bgp route-leak" command */
13777 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13778
13779 /* "redistribute" commands. */
13780 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13781 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13782 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13783 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13784 install_element(BGP_NODE,
13785 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13786 install_element(BGP_NODE,
13787 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13788 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13789 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13790 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13791 install_element(BGP_NODE,
13792 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13793 install_element(BGP_NODE,
13794 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13795 install_element(BGP_NODE,
13796 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13797 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13798 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13800 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13801 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13802 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13803 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13804 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13805 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13806 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13807 install_element(BGP_IPV4_NODE,
13808 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13809 install_element(BGP_IPV4_NODE,
13810 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13811 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13812 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13813 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13814 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13815 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13816 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13817
b9c7bc5a
PZ
13818 /* import|export vpn [route-map WORD] */
13819 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13820 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13821
12a844a5
DS
13822 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13823 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13824
d62a17ae 13825 /* ttl_security commands */
13826 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13827 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13828
13829 /* "show [ip] bgp memory" commands. */
13830 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13831
acf71666
MK
13832 /* "show bgp martian next-hop" */
13833 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13834
d62a17ae 13835 /* "show [ip] bgp views" commands. */
13836 install_element(VIEW_NODE, &show_bgp_views_cmd);
13837
13838 /* "show [ip] bgp vrfs" commands. */
13839 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13840
13841 /* Community-list. */
13842 community_list_vty();
ddb5b488
PZ
13843
13844 /* vpn-policy commands */
b9c7bc5a
PZ
13845 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13846 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13847 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13848 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13849 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13850 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13851 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13852 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13853 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13854 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13855 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13856 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13857
301ad80a
PG
13858 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13859 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13860
b9c7bc5a
PZ
13861 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13862 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13863 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13864 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13865 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13866 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13867 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13868 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13869 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13870 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13871 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13872 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13873}
6b0655a2 13874
718e3744 13875#include "memory.h"
13876#include "bgp_regex.h"
13877#include "bgp_clist.h"
13878#include "bgp_ecommunity.h"
13879
13880/* VTY functions. */
13881
13882/* Direction value to string conversion. */
d62a17ae 13883static const char *community_direct_str(int direct)
13884{
13885 switch (direct) {
13886 case COMMUNITY_DENY:
13887 return "deny";
13888 case COMMUNITY_PERMIT:
13889 return "permit";
13890 default:
13891 return "unknown";
13892 }
718e3744 13893}
13894
13895/* Display error string. */
d62a17ae 13896static void community_list_perror(struct vty *vty, int ret)
13897{
13898 switch (ret) {
13899 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13900 vty_out(vty, "%% Can't find community-list\n");
13901 break;
13902 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13903 vty_out(vty, "%% Malformed community-list value\n");
13904 break;
13905 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13906 vty_out(vty,
13907 "%% Community name conflict, previously defined as standard community\n");
13908 break;
13909 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13910 vty_out(vty,
13911 "%% Community name conflict, previously defined as expanded community\n");
13912 break;
13913 }
718e3744 13914}
13915
5bf15956
DW
13916/* "community-list" keyword help string. */
13917#define COMMUNITY_LIST_STR "Add a community list entry\n"
13918
7336e101
SP
13919/*community-list standard */
13920DEFUN (community_list_standard,
13921 bgp_community_list_standard_cmd,
13922 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13923 BGP_STR
718e3744 13924 COMMUNITY_LIST_STR
13925 "Community list number (standard)\n"
5bf15956 13926 "Add an standard community-list entry\n"
718e3744 13927 "Community list name\n"
13928 "Specify community to reject\n"
13929 "Specify community to accept\n"
13930 COMMUNITY_VAL_STR)
13931{
d62a17ae 13932 char *cl_name_or_number = NULL;
13933 int direct = 0;
13934 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13935
d62a17ae 13936 int idx = 0;
7336e101
SP
13937
13938 if (argv_find(argv, argc, "ip", &idx)) {
13939 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13940 vty_out(vty, "if you are using this please migrate to the below command.\n");
13941 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13942 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13943 }
13944
d62a17ae 13945 argv_find(argv, argc, "(1-99)", &idx);
13946 argv_find(argv, argc, "WORD", &idx);
13947 cl_name_or_number = argv[idx]->arg;
13948 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13949 : COMMUNITY_DENY;
13950 argv_find(argv, argc, "AA:NN", &idx);
13951 char *str = argv_concat(argv, argc, idx);
42f914d4 13952
d62a17ae 13953 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13954 style);
42f914d4 13955
d62a17ae 13956 XFREE(MTYPE_TMP, str);
42f914d4 13957
d62a17ae 13958 if (ret < 0) {
13959 /* Display error string. */
13960 community_list_perror(vty, ret);
13961 return CMD_WARNING_CONFIG_FAILED;
13962 }
42f914d4 13963
d62a17ae 13964 return CMD_SUCCESS;
718e3744 13965}
13966
7336e101
SP
13967#if CONFDATE > 20191005
13968CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13969#endif
13970ALIAS (community_list_standard,
13971 ip_community_list_standard_cmd,
13972 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13973 IP_STR
13974 COMMUNITY_LIST_STR
13975 "Community list number (standard)\n"
5bf15956
DW
13976 "Add an standard community-list entry\n"
13977 "Community list name\n"
718e3744 13978 "Specify community to reject\n"
13979 "Specify community to accept\n"
13980 COMMUNITY_VAL_STR)
7336e101
SP
13981
13982DEFUN (no_community_list_standard_all,
13983 no_bgp_community_list_standard_all_cmd,
13984 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13985 NO_STR
13986 BGP_STR
13987 COMMUNITY_LIST_STR
13988 "Community list number (standard)\n"
13989 "Add an standard community-list entry\n"
13990 "Community list name\n"
13991 "Specify community to reject\n"
13992 "Specify community to accept\n"
13993 COMMUNITY_VAL_STR)
718e3744 13994{
d62a17ae 13995 char *cl_name_or_number = NULL;
174b5cb9 13996 char *str = NULL;
d62a17ae 13997 int direct = 0;
13998 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13999
d62a17ae 14000 int idx = 0;
7336e101
SP
14001
14002 if (argv_find(argv, argc, "ip", &idx)) {
14003 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14004 vty_out(vty, "if you are using this please migrate to the below command.\n");
14005 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14006 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14007 }
14008
174b5cb9
DA
14009 argv_find(argv, argc, "permit", &idx);
14010 argv_find(argv, argc, "deny", &idx);
14011
14012 if (idx) {
14013 direct = argv_find(argv, argc, "permit", &idx)
14014 ? COMMUNITY_PERMIT
14015 : COMMUNITY_DENY;
14016
14017 idx = 0;
14018 argv_find(argv, argc, "AA:NN", &idx);
14019 str = argv_concat(argv, argc, idx);
14020 }
14021
14022 idx = 0;
d62a17ae 14023 argv_find(argv, argc, "(1-99)", &idx);
14024 argv_find(argv, argc, "WORD", &idx);
14025 cl_name_or_number = argv[idx]->arg;
42f914d4 14026
d62a17ae 14027 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14028 direct, style);
42f914d4 14029
d62a17ae 14030 XFREE(MTYPE_TMP, str);
daf9ddbb 14031
d62a17ae 14032 if (ret < 0) {
14033 community_list_perror(vty, ret);
14034 return CMD_WARNING_CONFIG_FAILED;
14035 }
42f914d4 14036
d62a17ae 14037 return CMD_SUCCESS;
718e3744 14038}
7336e101
SP
14039ALIAS (no_community_list_standard_all,
14040 no_ip_community_list_standard_all_cmd,
14041 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14042 NO_STR
718e3744 14043 IP_STR
14044 COMMUNITY_LIST_STR
7336e101
SP
14045 "Community list number (standard)\n"
14046 "Add an standard community-list entry\n"
14047 "Community list name\n"
14048 "Specify community to reject\n"
14049 "Specify community to accept\n"
14050 COMMUNITY_VAL_STR)
14051
174b5cb9
DA
14052ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14053 "no bgp community-list <(1-99)|standard WORD>",
14054 NO_STR BGP_STR COMMUNITY_LIST_STR
14055 "Community list number (standard)\n"
14056 "Add an standard community-list entry\n"
14057 "Community list name\n")
14058
14059ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14060 "no ip community-list <(1-99)|standard WORD>",
14061 NO_STR BGP_STR COMMUNITY_LIST_STR
14062 "Community list number (standard)\n"
14063 "Add an standard community-list entry\n"
14064 "Community list name\n")
14065
7336e101
SP
14066/*community-list expanded */
14067DEFUN (community_list_expanded_all,
14068 bgp_community_list_expanded_all_cmd,
14069 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14070 BGP_STR
14071 COMMUNITY_LIST_STR
718e3744 14072 "Community list number (expanded)\n"
5bf15956 14073 "Add an expanded community-list entry\n"
718e3744 14074 "Community list name\n"
14075 "Specify community to reject\n"
14076 "Specify community to accept\n"
14077 COMMUNITY_VAL_STR)
14078{
d62a17ae 14079 char *cl_name_or_number = NULL;
14080 int direct = 0;
14081 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14082
d62a17ae 14083 int idx = 0;
7336e101
SP
14084 if (argv_find(argv, argc, "ip", &idx)) {
14085 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14086 vty_out(vty, "if you are using this please migrate to the below command.\n");
14087 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14088 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14089 }
d62a17ae 14090 argv_find(argv, argc, "(100-500)", &idx);
14091 argv_find(argv, argc, "WORD", &idx);
14092 cl_name_or_number = argv[idx]->arg;
14093 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14094 : COMMUNITY_DENY;
14095 argv_find(argv, argc, "AA:NN", &idx);
14096 char *str = argv_concat(argv, argc, idx);
42f914d4 14097
d62a17ae 14098 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14099 style);
42f914d4 14100
d62a17ae 14101 XFREE(MTYPE_TMP, str);
42f914d4 14102
d62a17ae 14103 if (ret < 0) {
14104 /* Display error string. */
14105 community_list_perror(vty, ret);
14106 return CMD_WARNING_CONFIG_FAILED;
14107 }
42f914d4 14108
d62a17ae 14109 return CMD_SUCCESS;
718e3744 14110}
14111
7336e101
SP
14112ALIAS (community_list_expanded_all,
14113 ip_community_list_expanded_all_cmd,
14114 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14115 IP_STR
14116 COMMUNITY_LIST_STR
5bf15956
DW
14117 "Community list number (expanded)\n"
14118 "Add an expanded community-list entry\n"
718e3744 14119 "Community list name\n"
14120 "Specify community to reject\n"
14121 "Specify community to accept\n"
5bf15956 14122 COMMUNITY_VAL_STR)
7336e101
SP
14123
14124DEFUN (no_community_list_expanded_all,
14125 no_bgp_community_list_expanded_all_cmd,
14126 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14127 NO_STR
14128 BGP_STR
14129 COMMUNITY_LIST_STR
14130 "Community list number (expanded)\n"
14131 "Add an expanded community-list entry\n"
14132 "Community list name\n"
14133 "Specify community to reject\n"
14134 "Specify community to accept\n"
14135 COMMUNITY_VAL_STR)
718e3744 14136{
d62a17ae 14137 char *cl_name_or_number = NULL;
174b5cb9 14138 char *str = NULL;
d62a17ae 14139 int direct = 0;
14140 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14141
d62a17ae 14142 int idx = 0;
7336e101
SP
14143 if (argv_find(argv, argc, "ip", &idx)) {
14144 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14145 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14146 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14147 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14148 }
14149
3c4b8fe2 14150 idx = 0;
174b5cb9
DA
14151 argv_find(argv, argc, "permit", &idx);
14152 argv_find(argv, argc, "deny", &idx);
14153
14154 if (idx) {
14155 direct = argv_find(argv, argc, "permit", &idx)
14156 ? COMMUNITY_PERMIT
14157 : COMMUNITY_DENY;
14158
14159 idx = 0;
14160 argv_find(argv, argc, "AA:NN", &idx);
14161 str = argv_concat(argv, argc, idx);
7336e101 14162 }
174b5cb9
DA
14163
14164 idx = 0;
d62a17ae 14165 argv_find(argv, argc, "(100-500)", &idx);
14166 argv_find(argv, argc, "WORD", &idx);
14167 cl_name_or_number = argv[idx]->arg;
42f914d4 14168
d62a17ae 14169 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14170 direct, style);
42f914d4 14171
d62a17ae 14172 XFREE(MTYPE_TMP, str);
daf9ddbb 14173
d62a17ae 14174 if (ret < 0) {
14175 community_list_perror(vty, ret);
14176 return CMD_WARNING_CONFIG_FAILED;
14177 }
42f914d4 14178
d62a17ae 14179 return CMD_SUCCESS;
718e3744 14180}
14181
7336e101
SP
14182ALIAS (no_community_list_expanded_all,
14183 no_ip_community_list_expanded_all_cmd,
14184 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14185 NO_STR
14186 IP_STR
14187 COMMUNITY_LIST_STR
14188 "Community list number (expanded)\n"
14189 "Add an expanded community-list entry\n"
14190 "Community list name\n"
14191 "Specify community to reject\n"
14192 "Specify community to accept\n"
14193 COMMUNITY_VAL_STR)
14194
174b5cb9
DA
14195ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14196 "no bgp community-list <(100-500)|expanded WORD>",
14197 NO_STR IP_STR COMMUNITY_LIST_STR
14198 "Community list number (expanded)\n"
14199 "Add an expanded community-list entry\n"
14200 "Community list name\n")
14201
14202ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14203 "no ip community-list <(100-500)|expanded WORD>",
14204 NO_STR IP_STR COMMUNITY_LIST_STR
14205 "Community list number (expanded)\n"
14206 "Add an expanded community-list entry\n"
14207 "Community list name\n")
14208
8d9b8ed9
PM
14209/* Return configuration string of community-list entry. */
14210static const char *community_list_config_str(struct community_entry *entry)
14211{
14212 const char *str;
14213
14214 if (entry->any)
14215 str = "";
14216 else {
14217 if (entry->style == COMMUNITY_LIST_STANDARD)
14218 str = community_str(entry->u.com, false);
14219 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14220 str = lcommunity_str(entry->u.lcom, false);
14221 else
14222 str = entry->config;
14223 }
14224 return str;
14225}
14226
d62a17ae 14227static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14228{
d62a17ae 14229 struct community_entry *entry;
718e3744 14230
d62a17ae 14231 for (entry = list->head; entry; entry = entry->next) {
14232 if (entry == list->head) {
14233 if (all_digit(list->name))
14234 vty_out(vty, "Community %s list %s\n",
14235 entry->style == COMMUNITY_LIST_STANDARD
14236 ? "standard"
14237 : "(expanded) access",
14238 list->name);
14239 else
14240 vty_out(vty, "Named Community %s list %s\n",
14241 entry->style == COMMUNITY_LIST_STANDARD
14242 ? "standard"
14243 : "expanded",
14244 list->name);
14245 }
14246 if (entry->any)
14247 vty_out(vty, " %s\n",
14248 community_direct_str(entry->direct));
14249 else
14250 vty_out(vty, " %s %s\n",
14251 community_direct_str(entry->direct),
8d9b8ed9 14252 community_list_config_str(entry));
d62a17ae 14253 }
718e3744 14254}
14255
7336e101
SP
14256DEFUN (show_community_list,
14257 show_bgp_community_list_cmd,
14258 "show bgp community-list",
718e3744 14259 SHOW_STR
7336e101 14260 BGP_STR
718e3744 14261 "List community-list\n")
14262{
d62a17ae 14263 struct community_list *list;
14264 struct community_list_master *cm;
718e3744 14265
7336e101
SP
14266 int idx = 0;
14267 if (argv_find(argv, argc, "ip", &idx)) {
14268 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14269 vty_out(vty, "if you are using this please migrate to the below command.\n");
14270 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14271 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14272 }
d62a17ae 14273 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14274 if (!cm)
14275 return CMD_SUCCESS;
718e3744 14276
d62a17ae 14277 for (list = cm->num.head; list; list = list->next)
14278 community_list_show(vty, list);
718e3744 14279
d62a17ae 14280 for (list = cm->str.head; list; list = list->next)
14281 community_list_show(vty, list);
718e3744 14282
d62a17ae 14283 return CMD_SUCCESS;
718e3744 14284}
14285
7336e101
SP
14286ALIAS (show_community_list,
14287 show_ip_community_list_cmd,
14288 "show ip community-list",
718e3744 14289 SHOW_STR
14290 IP_STR
7336e101
SP
14291 "List community-list\n")
14292
14293DEFUN (show_community_list_arg,
14294 show_bgp_community_list_arg_cmd,
14295 "show bgp community-list <(1-500)|WORD>",
14296 SHOW_STR
14297 BGP_STR
718e3744 14298 "List community-list\n"
14299 "Community-list number\n"
14300 "Community-list name\n")
14301{
d62a17ae 14302 int idx_comm_list = 3;
14303 struct community_list *list;
718e3744 14304
7336e101
SP
14305 int idx = 0;
14306 if (argv_find(argv, argc, "ip", &idx)) {
14307 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14308 vty_out(vty, "if you are using this please migrate to the below command.\n");
14309 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14310 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14311 }
d62a17ae 14312 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14313 COMMUNITY_LIST_MASTER);
14314 if (!list) {
14315 vty_out(vty, "%% Can't find community-list\n");
14316 return CMD_WARNING;
14317 }
718e3744 14318
d62a17ae 14319 community_list_show(vty, list);
718e3744 14320
d62a17ae 14321 return CMD_SUCCESS;
718e3744 14322}
6b0655a2 14323
7336e101
SP
14324ALIAS (show_community_list_arg,
14325 show_ip_community_list_arg_cmd,
14326 "show ip community-list <(1-500)|WORD>",
14327 SHOW_STR
14328 IP_STR
14329 "List community-list\n"
14330 "Community-list number\n"
14331 "Community-list name\n")
14332
57d187bc
JS
14333/*
14334 * Large Community code.
14335 */
d62a17ae 14336static int lcommunity_list_set_vty(struct vty *vty, int argc,
14337 struct cmd_token **argv, int style,
14338 int reject_all_digit_name)
14339{
14340 int ret;
14341 int direct;
14342 char *str;
14343 int idx = 0;
14344 char *cl_name;
14345
7336e101
SP
14346 if (argv_find(argv, argc, "ip", &idx)) {
14347 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14348 vty_out(vty, "if you are using this please migrate to the below command.\n");
14349 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14350 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14351 }
d62a17ae 14352 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14353 : COMMUNITY_DENY;
14354
14355 /* All digit name check. */
14356 idx = 0;
14357 argv_find(argv, argc, "WORD", &idx);
14358 argv_find(argv, argc, "(1-99)", &idx);
14359 argv_find(argv, argc, "(100-500)", &idx);
14360 cl_name = argv[idx]->arg;
14361 if (reject_all_digit_name && all_digit(cl_name)) {
14362 vty_out(vty, "%% Community name cannot have all digits\n");
14363 return CMD_WARNING_CONFIG_FAILED;
14364 }
14365
14366 idx = 0;
14367 argv_find(argv, argc, "AA:BB:CC", &idx);
14368 argv_find(argv, argc, "LINE", &idx);
14369 /* Concat community string argument. */
14370 if (idx)
14371 str = argv_concat(argv, argc, idx);
14372 else
14373 str = NULL;
14374
14375 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14376
14377 /* Free temporary community list string allocated by
14378 argv_concat(). */
14379 if (str)
14380 XFREE(MTYPE_TMP, str);
14381
14382 if (ret < 0) {
14383 community_list_perror(vty, ret);
14384 return CMD_WARNING_CONFIG_FAILED;
14385 }
14386 return CMD_SUCCESS;
14387}
14388
14389static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14390 struct cmd_token **argv, int style)
14391{
14392 int ret;
14393 int direct = 0;
14394 char *str = NULL;
14395 int idx = 0;
14396
7336e101
SP
14397 if (argv_find(argv, argc, "ip", &idx)) {
14398 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14399 vty_out(vty, "if you are using this please migrate to the below command.\n");
14400 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14401 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14402 }
d62a17ae 14403 argv_find(argv, argc, "permit", &idx);
14404 argv_find(argv, argc, "deny", &idx);
14405
14406 if (idx) {
14407 /* Check the list direct. */
14408 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14409 direct = COMMUNITY_PERMIT;
14410 else
14411 direct = COMMUNITY_DENY;
14412
14413 idx = 0;
14414 argv_find(argv, argc, "LINE", &idx);
14415 argv_find(argv, argc, "AA:AA:NN", &idx);
14416 /* Concat community string argument. */
14417 str = argv_concat(argv, argc, idx);
14418 }
14419
14420 idx = 0;
14421 argv_find(argv, argc, "(1-99)", &idx);
14422 argv_find(argv, argc, "(100-500)", &idx);
14423 argv_find(argv, argc, "WORD", &idx);
14424
14425 /* Unset community list. */
14426 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14427 style);
14428
14429 /* Free temporary community list string allocated by
14430 argv_concat(). */
14431 if (str)
14432 XFREE(MTYPE_TMP, str);
14433
14434 if (ret < 0) {
14435 community_list_perror(vty, ret);
14436 return CMD_WARNING_CONFIG_FAILED;
14437 }
14438
14439 return CMD_SUCCESS;
57d187bc
JS
14440}
14441
14442/* "large-community-list" keyword help string. */
14443#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14444#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14445
7336e101
SP
14446#if CONFDATE > 20191005
14447CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14448#endif
14449DEFUN (lcommunity_list_standard,
14450 bgp_lcommunity_list_standard_cmd,
14451 "bgp large-community-list (1-99) <deny|permit>",
14452 BGP_STR
14453 LCOMMUNITY_LIST_STR
14454 "Large Community list number (standard)\n"
14455 "Specify large community to reject\n"
14456 "Specify large community to accept\n")
14457{
14458 return lcommunity_list_set_vty(vty, argc, argv,
14459 LARGE_COMMUNITY_LIST_STANDARD, 0);
14460}
14461
14462ALIAS (lcommunity_list_standard,
57d187bc 14463 ip_lcommunity_list_standard_cmd,
52951b63
DS
14464 "ip large-community-list (1-99) <deny|permit>",
14465 IP_STR
14466 LCOMMUNITY_LIST_STR
14467 "Large Community list number (standard)\n"
14468 "Specify large community to reject\n"
7111c1a0 14469 "Specify large community to accept\n")
7336e101
SP
14470
14471DEFUN (lcommunity_list_standard1,
14472 bgp_lcommunity_list_standard1_cmd,
14473 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14474 BGP_STR
14475 LCOMMUNITY_LIST_STR
14476 "Large Community list number (standard)\n"
14477 "Specify large community to reject\n"
14478 "Specify large community to accept\n"
14479 LCOMMUNITY_VAL_STR)
52951b63 14480{
d62a17ae 14481 return lcommunity_list_set_vty(vty, argc, argv,
14482 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14483}
14484
7336e101 14485ALIAS (lcommunity_list_standard1,
52951b63
DS
14486 ip_lcommunity_list_standard1_cmd,
14487 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14488 IP_STR
14489 LCOMMUNITY_LIST_STR
14490 "Large Community list number (standard)\n"
14491 "Specify large community to reject\n"
14492 "Specify large community to accept\n"
14493 LCOMMUNITY_VAL_STR)
7336e101
SP
14494
14495DEFUN (lcommunity_list_expanded,
14496 bgp_lcommunity_list_expanded_cmd,
14497 "bgp large-community-list (100-500) <deny|permit> LINE...",
14498 BGP_STR
14499 LCOMMUNITY_LIST_STR
14500 "Large Community list number (expanded)\n"
14501 "Specify large community to reject\n"
14502 "Specify large community to accept\n"
14503 "An ordered list as a regular-expression\n")
57d187bc 14504{
d62a17ae 14505 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14506 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14507}
14508
7336e101 14509ALIAS (lcommunity_list_expanded,
57d187bc
JS
14510 ip_lcommunity_list_expanded_cmd,
14511 "ip large-community-list (100-500) <deny|permit> LINE...",
14512 IP_STR
14513 LCOMMUNITY_LIST_STR
14514 "Large Community list number (expanded)\n"
14515 "Specify large community to reject\n"
14516 "Specify large community to accept\n"
14517 "An ordered list as a regular-expression\n")
7336e101
SP
14518
14519DEFUN (lcommunity_list_name_standard,
14520 bgp_lcommunity_list_name_standard_cmd,
14521 "bgp large-community-list standard WORD <deny|permit>",
14522 BGP_STR
14523 LCOMMUNITY_LIST_STR
14524 "Specify standard large-community-list\n"
14525 "Large Community list name\n"
14526 "Specify large community to reject\n"
14527 "Specify large community to accept\n")
57d187bc 14528{
d62a17ae 14529 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14530 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14531}
14532
7336e101 14533ALIAS (lcommunity_list_name_standard,
57d187bc 14534 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14535 "ip large-community-list standard WORD <deny|permit>",
14536 IP_STR
14537 LCOMMUNITY_LIST_STR
14538 "Specify standard large-community-list\n"
14539 "Large Community list name\n"
14540 "Specify large community to reject\n"
14541 "Specify large community to accept\n")
7336e101
SP
14542
14543DEFUN (lcommunity_list_name_standard1,
14544 bgp_lcommunity_list_name_standard1_cmd,
14545 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14546 BGP_STR
14547 LCOMMUNITY_LIST_STR
14548 "Specify standard large-community-list\n"
14549 "Large Community list name\n"
14550 "Specify large community to reject\n"
14551 "Specify large community to accept\n"
14552 LCOMMUNITY_VAL_STR)
52951b63 14553{
d62a17ae 14554 return lcommunity_list_set_vty(vty, argc, argv,
14555 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14556}
14557
7336e101 14558ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14559 ip_lcommunity_list_name_standard1_cmd,
14560 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14561 IP_STR
14562 LCOMMUNITY_LIST_STR
14563 "Specify standard large-community-list\n"
14564 "Large Community list name\n"
14565 "Specify large community to reject\n"
14566 "Specify large community to accept\n"
14567 LCOMMUNITY_VAL_STR)
7336e101
SP
14568
14569DEFUN (lcommunity_list_name_expanded,
14570 bgp_lcommunity_list_name_expanded_cmd,
14571 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14572 BGP_STR
14573 LCOMMUNITY_LIST_STR
14574 "Specify expanded large-community-list\n"
14575 "Large Community list name\n"
14576 "Specify large community to reject\n"
14577 "Specify large community to accept\n"
14578 "An ordered list as a regular-expression\n")
57d187bc 14579{
d62a17ae 14580 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14581 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14582}
14583
7336e101 14584ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14585 ip_lcommunity_list_name_expanded_cmd,
14586 "ip large-community-list expanded WORD <deny|permit> LINE...",
14587 IP_STR
14588 LCOMMUNITY_LIST_STR
14589 "Specify expanded large-community-list\n"
14590 "Large Community list name\n"
14591 "Specify large community to reject\n"
14592 "Specify large community to accept\n"
14593 "An ordered list as a regular-expression\n")
7336e101
SP
14594
14595DEFUN (no_lcommunity_list_standard_all,
14596 no_bgp_lcommunity_list_standard_all_cmd,
14597 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14598 NO_STR
14599 BGP_STR
14600 LCOMMUNITY_LIST_STR
14601 "Large Community list number (standard)\n"
14602 "Large Community list number (expanded)\n"
14603 "Large Community list name\n")
57d187bc 14604{
7336e101
SP
14605 return lcommunity_list_unset_vty(vty, argc, argv,
14606 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14607}
14608
7336e101 14609ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14610 no_ip_lcommunity_list_standard_all_cmd,
14611 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14612 NO_STR
14613 IP_STR
14614 LCOMMUNITY_LIST_STR
14615 "Large Community list number (standard)\n"
14616 "Large Community list number (expanded)\n"
14617 "Large Community list name\n")
7336e101
SP
14618
14619DEFUN (no_lcommunity_list_name_expanded_all,
14620 no_bgp_lcommunity_list_name_expanded_all_cmd,
14621 "no bgp large-community-list expanded WORD",
14622 NO_STR
14623 BGP_STR
14624 LCOMMUNITY_LIST_STR
14625 "Specify expanded large-community-list\n"
14626 "Large Community list name\n")
57d187bc 14627{
d62a17ae 14628 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14629 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14630}
14631
7336e101 14632ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14633 no_ip_lcommunity_list_name_expanded_all_cmd,
14634 "no ip large-community-list expanded WORD",
14635 NO_STR
14636 IP_STR
14637 LCOMMUNITY_LIST_STR
14638 "Specify expanded large-community-list\n"
14639 "Large Community list name\n")
7336e101
SP
14640
14641DEFUN (no_lcommunity_list_standard,
14642 no_bgp_lcommunity_list_standard_cmd,
14643 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14644 NO_STR
14645 BGP_STR
14646 LCOMMUNITY_LIST_STR
14647 "Large Community list number (standard)\n"
14648 "Specify large community to reject\n"
14649 "Specify large community to accept\n"
14650 LCOMMUNITY_VAL_STR)
57d187bc 14651{
d62a17ae 14652 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14653 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14654}
14655
7336e101 14656ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14657 no_ip_lcommunity_list_standard_cmd,
14658 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14659 NO_STR
14660 IP_STR
14661 LCOMMUNITY_LIST_STR
14662 "Large Community list number (standard)\n"
14663 "Specify large community to reject\n"
14664 "Specify large community to accept\n"
14665 LCOMMUNITY_VAL_STR)
7336e101
SP
14666
14667DEFUN (no_lcommunity_list_expanded,
14668 no_bgp_lcommunity_list_expanded_cmd,
14669 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14670 NO_STR
14671 BGP_STR
14672 LCOMMUNITY_LIST_STR
14673 "Large Community list number (expanded)\n"
14674 "Specify large community to reject\n"
14675 "Specify large community to accept\n"
14676 "An ordered list as a regular-expression\n")
57d187bc 14677{
d62a17ae 14678 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14679 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14680}
14681
7336e101 14682ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14683 no_ip_lcommunity_list_expanded_cmd,
14684 "no ip large-community-list (100-500) <deny|permit> LINE...",
14685 NO_STR
14686 IP_STR
14687 LCOMMUNITY_LIST_STR
14688 "Large Community list number (expanded)\n"
14689 "Specify large community to reject\n"
14690 "Specify large community to accept\n"
14691 "An ordered list as a regular-expression\n")
7336e101
SP
14692
14693DEFUN (no_lcommunity_list_name_standard,
14694 no_bgp_lcommunity_list_name_standard_cmd,
14695 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14696 NO_STR
14697 BGP_STR
14698 LCOMMUNITY_LIST_STR
14699 "Specify standard large-community-list\n"
14700 "Large Community list name\n"
14701 "Specify large community to reject\n"
14702 "Specify large community to accept\n"
14703 LCOMMUNITY_VAL_STR)
57d187bc 14704{
d62a17ae 14705 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14706 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14707}
14708
7336e101 14709ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14710 no_ip_lcommunity_list_name_standard_cmd,
14711 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14712 NO_STR
14713 IP_STR
14714 LCOMMUNITY_LIST_STR
14715 "Specify standard large-community-list\n"
14716 "Large Community list name\n"
14717 "Specify large community to reject\n"
14718 "Specify large community to accept\n"
14719 LCOMMUNITY_VAL_STR)
7336e101
SP
14720
14721DEFUN (no_lcommunity_list_name_expanded,
14722 no_bgp_lcommunity_list_name_expanded_cmd,
14723 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14724 NO_STR
14725 BGP_STR
14726 LCOMMUNITY_LIST_STR
14727 "Specify expanded large-community-list\n"
14728 "Large community list name\n"
14729 "Specify large community to reject\n"
14730 "Specify large community to accept\n"
14731 "An ordered list as a regular-expression\n")
57d187bc 14732{
d62a17ae 14733 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14734 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14735}
14736
7336e101 14737ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14738 no_ip_lcommunity_list_name_expanded_cmd,
14739 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14740 NO_STR
14741 IP_STR
14742 LCOMMUNITY_LIST_STR
14743 "Specify expanded large-community-list\n"
14744 "Large community list name\n"
14745 "Specify large community to reject\n"
14746 "Specify large community to accept\n"
14747 "An ordered list as a regular-expression\n")
d62a17ae 14748
14749static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14750{
14751 struct community_entry *entry;
14752
14753 for (entry = list->head; entry; entry = entry->next) {
14754 if (entry == list->head) {
14755 if (all_digit(list->name))
14756 vty_out(vty, "Large community %s list %s\n",
14757 entry->style == EXTCOMMUNITY_LIST_STANDARD
14758 ? "standard"
14759 : "(expanded) access",
14760 list->name);
14761 else
14762 vty_out(vty,
14763 "Named large community %s list %s\n",
14764 entry->style == EXTCOMMUNITY_LIST_STANDARD
14765 ? "standard"
14766 : "expanded",
14767 list->name);
14768 }
14769 if (entry->any)
14770 vty_out(vty, " %s\n",
14771 community_direct_str(entry->direct));
14772 else
14773 vty_out(vty, " %s %s\n",
14774 community_direct_str(entry->direct),
8d9b8ed9 14775 community_list_config_str(entry));
d62a17ae 14776 }
57d187bc
JS
14777}
14778
7336e101
SP
14779DEFUN (show_lcommunity_list,
14780 show_bgp_lcommunity_list_cmd,
14781 "show bgp large-community-list",
57d187bc 14782 SHOW_STR
7336e101 14783 BGP_STR
57d187bc
JS
14784 "List large-community list\n")
14785{
d62a17ae 14786 struct community_list *list;
14787 struct community_list_master *cm;
7336e101
SP
14788 int idx = 0;
14789
14790 if (argv_find(argv, argc, "ip", &idx)) {
14791 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14792 vty_out(vty, "if you are using this please migrate to the below command.\n");
14793 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14794 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14795 }
57d187bc 14796
d62a17ae 14797 cm = community_list_master_lookup(bgp_clist,
14798 LARGE_COMMUNITY_LIST_MASTER);
14799 if (!cm)
14800 return CMD_SUCCESS;
57d187bc 14801
d62a17ae 14802 for (list = cm->num.head; list; list = list->next)
14803 lcommunity_list_show(vty, list);
57d187bc 14804
d62a17ae 14805 for (list = cm->str.head; list; list = list->next)
14806 lcommunity_list_show(vty, list);
57d187bc 14807
d62a17ae 14808 return CMD_SUCCESS;
57d187bc
JS
14809}
14810
7336e101
SP
14811ALIAS (show_lcommunity_list,
14812 show_ip_lcommunity_list_cmd,
14813 "show ip large-community-list",
57d187bc
JS
14814 SHOW_STR
14815 IP_STR
7336e101
SP
14816 "List large-community list\n")
14817
14818DEFUN (show_lcommunity_list_arg,
14819 show_bgp_lcommunity_list_arg_cmd,
14820 "show bgp large-community-list <(1-500)|WORD>",
14821 SHOW_STR
14822 BGP_STR
57d187bc
JS
14823 "List large-community list\n"
14824 "large-community-list number\n"
14825 "large-community-list name\n")
14826{
d62a17ae 14827 struct community_list *list;
7336e101
SP
14828 int idx = 0;
14829
14830 if (argv_find(argv, argc, "ip", &idx)) {
14831 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14832 vty_out(vty, "if you are using this please migrate to the below command.\n");
14833 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14834 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14835 }
57d187bc 14836
d62a17ae 14837 list = community_list_lookup(bgp_clist, argv[3]->arg,
14838 LARGE_COMMUNITY_LIST_MASTER);
14839 if (!list) {
14840 vty_out(vty, "%% Can't find extcommunity-list\n");
14841 return CMD_WARNING;
14842 }
57d187bc 14843
d62a17ae 14844 lcommunity_list_show(vty, list);
57d187bc 14845
d62a17ae 14846 return CMD_SUCCESS;
57d187bc
JS
14847}
14848
7336e101
SP
14849ALIAS (show_lcommunity_list_arg,
14850 show_ip_lcommunity_list_arg_cmd,
14851 "show ip large-community-list <(1-500)|WORD>",
14852 SHOW_STR
14853 IP_STR
14854 "List large-community list\n"
14855 "large-community-list number\n"
14856 "large-community-list name\n")
14857
718e3744 14858/* "extcommunity-list" keyword help string. */
14859#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14860#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14861
7336e101
SP
14862DEFUN (extcommunity_list_standard,
14863 bgp_extcommunity_list_standard_cmd,
14864 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14865 BGP_STR
718e3744 14866 EXTCOMMUNITY_LIST_STR
14867 "Extended Community list number (standard)\n"
718e3744 14868 "Specify standard extcommunity-list\n"
5bf15956 14869 "Community list name\n"
718e3744 14870 "Specify community to reject\n"
14871 "Specify community to accept\n"
14872 EXTCOMMUNITY_VAL_STR)
14873{
d62a17ae 14874 int style = EXTCOMMUNITY_LIST_STANDARD;
14875 int direct = 0;
14876 char *cl_number_or_name = NULL;
42f914d4 14877
d62a17ae 14878 int idx = 0;
7336e101
SP
14879 if (argv_find(argv, argc, "ip", &idx)) {
14880 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14881 vty_out(vty, "if you are using this please migrate to the below command.\n");
14882 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14883 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14884 }
d62a17ae 14885 argv_find(argv, argc, "(1-99)", &idx);
14886 argv_find(argv, argc, "WORD", &idx);
14887 cl_number_or_name = argv[idx]->arg;
14888 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14889 : COMMUNITY_DENY;
14890 argv_find(argv, argc, "AA:NN", &idx);
14891 char *str = argv_concat(argv, argc, idx);
42f914d4 14892
d62a17ae 14893 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14894 direct, style);
42f914d4 14895
d62a17ae 14896 XFREE(MTYPE_TMP, str);
42f914d4 14897
d62a17ae 14898 if (ret < 0) {
14899 community_list_perror(vty, ret);
14900 return CMD_WARNING_CONFIG_FAILED;
14901 }
42f914d4 14902
d62a17ae 14903 return CMD_SUCCESS;
718e3744 14904}
14905
7336e101
SP
14906#if CONFDATE > 20191005
14907CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14908#endif
14909ALIAS (extcommunity_list_standard,
14910 ip_extcommunity_list_standard_cmd,
14911 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14912 IP_STR
14913 EXTCOMMUNITY_LIST_STR
7336e101
SP
14914 "Extended Community list number (standard)\n"
14915 "Specify standard extcommunity-list\n"
14916 "Community list name\n"
14917 "Specify community to reject\n"
14918 "Specify community to accept\n"
14919 EXTCOMMUNITY_VAL_STR)
14920
14921DEFUN (extcommunity_list_name_expanded,
14922 bgp_extcommunity_list_name_expanded_cmd,
14923 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14924 BGP_STR
14925 EXTCOMMUNITY_LIST_STR
5bf15956 14926 "Extended Community list number (expanded)\n"
718e3744 14927 "Specify expanded extcommunity-list\n"
14928 "Extended Community list name\n"
14929 "Specify community to reject\n"
14930 "Specify community to accept\n"
14931 "An ordered list as a regular-expression\n")
14932{
d62a17ae 14933 int style = EXTCOMMUNITY_LIST_EXPANDED;
14934 int direct = 0;
14935 char *cl_number_or_name = NULL;
42f914d4 14936
d62a17ae 14937 int idx = 0;
7336e101
SP
14938 if (argv_find(argv, argc, "ip", &idx)) {
14939 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14940 vty_out(vty, "if you are using this please migrate to the below command.\n");
14941 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14942 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14943 }
14944
d62a17ae 14945 argv_find(argv, argc, "(100-500)", &idx);
14946 argv_find(argv, argc, "WORD", &idx);
14947 cl_number_or_name = argv[idx]->arg;
14948 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14949 : COMMUNITY_DENY;
14950 argv_find(argv, argc, "LINE", &idx);
14951 char *str = argv_concat(argv, argc, idx);
42f914d4 14952
d62a17ae 14953 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14954 direct, style);
42f914d4 14955
d62a17ae 14956 XFREE(MTYPE_TMP, str);
42f914d4 14957
d62a17ae 14958 if (ret < 0) {
14959 community_list_perror(vty, ret);
14960 return CMD_WARNING_CONFIG_FAILED;
14961 }
42f914d4 14962
d62a17ae 14963 return CMD_SUCCESS;
718e3744 14964}
14965
7336e101
SP
14966ALIAS (extcommunity_list_name_expanded,
14967 ip_extcommunity_list_name_expanded_cmd,
14968 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
14969 IP_STR
14970 EXTCOMMUNITY_LIST_STR
7336e101
SP
14971 "Extended Community list number (expanded)\n"
14972 "Specify expanded extcommunity-list\n"
14973 "Extended Community list name\n"
14974 "Specify community to reject\n"
14975 "Specify community to accept\n"
14976 "An ordered list as a regular-expression\n")
14977
14978DEFUN (no_extcommunity_list_standard_all,
14979 no_bgp_extcommunity_list_standard_all_cmd,
14980 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14981 NO_STR
14982 BGP_STR
14983 EXTCOMMUNITY_LIST_STR
813d4307 14984 "Extended Community list number (standard)\n"
718e3744 14985 "Specify standard extcommunity-list\n"
5bf15956 14986 "Community list name\n"
718e3744 14987 "Specify community to reject\n"
14988 "Specify community to accept\n"
14989 EXTCOMMUNITY_VAL_STR)
14990{
d62a17ae 14991 int style = EXTCOMMUNITY_LIST_STANDARD;
14992 int direct = 0;
14993 char *cl_number_or_name = NULL;
d4455c89 14994 char *str = NULL;
42f914d4 14995
d62a17ae 14996 int idx = 0;
7336e101
SP
14997 if (argv_find(argv, argc, "ip", &idx)) {
14998 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14999 vty_out(vty, "if you are using this please migrate to the below command.\n");
15000 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15001 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15002 }
d4455c89
DA
15003
15004 idx = 0;
15005 argv_find(argv, argc, "permit", &idx);
15006 argv_find(argv, argc, "deny", &idx);
15007
15008 if (idx) {
15009 direct = argv_find(argv, argc, "permit", &idx)
15010 ? COMMUNITY_PERMIT
15011 : COMMUNITY_DENY;
15012
15013 idx = 0;
15014 argv_find(argv, argc, "AA:NN", &idx);
15015 str = argv_concat(argv, argc, idx);
15016 }
15017
15018 idx = 0;
d62a17ae 15019 argv_find(argv, argc, "(1-99)", &idx);
15020 argv_find(argv, argc, "WORD", &idx);
15021 cl_number_or_name = argv[idx]->arg;
42f914d4 15022
d62a17ae 15023 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15024 direct, style);
42f914d4 15025
d62a17ae 15026 XFREE(MTYPE_TMP, str);
42f914d4 15027
d62a17ae 15028 if (ret < 0) {
15029 community_list_perror(vty, ret);
15030 return CMD_WARNING_CONFIG_FAILED;
15031 }
42f914d4 15032
d62a17ae 15033 return CMD_SUCCESS;
718e3744 15034}
15035
7336e101
SP
15036ALIAS (no_extcommunity_list_standard_all,
15037 no_ip_extcommunity_list_standard_all_cmd,
15038 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15039 NO_STR
15040 IP_STR
15041 EXTCOMMUNITY_LIST_STR
7336e101
SP
15042 "Extended Community list number (standard)\n"
15043 "Specify standard extcommunity-list\n"
15044 "Community list name\n"
15045 "Specify community to reject\n"
15046 "Specify community to accept\n"
15047 EXTCOMMUNITY_VAL_STR)
15048
d4455c89
DA
15049ALIAS(no_extcommunity_list_standard_all,
15050 no_bgp_extcommunity_list_standard_all_list_cmd,
15051 "no bgp extcommunity-list <(1-99)|standard WORD>",
15052 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15053 "Extended Community list number (standard)\n"
15054 "Specify standard extcommunity-list\n"
15055 "Community list name\n")
15056
15057ALIAS(no_extcommunity_list_standard_all,
15058 no_ip_extcommunity_list_standard_all_list_cmd,
15059 "no ip extcommunity-list <(1-99)|standard WORD>",
15060 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15061 "Extended Community list number (standard)\n"
15062 "Specify standard extcommunity-list\n"
15063 "Community list name\n")
15064
7336e101
SP
15065DEFUN (no_extcommunity_list_expanded_all,
15066 no_bgp_extcommunity_list_expanded_all_cmd,
15067 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15068 NO_STR
15069 BGP_STR
15070 EXTCOMMUNITY_LIST_STR
718e3744 15071 "Extended Community list number (expanded)\n"
718e3744 15072 "Specify expanded extcommunity-list\n"
5bf15956 15073 "Extended Community list name\n"
718e3744 15074 "Specify community to reject\n"
15075 "Specify community to accept\n"
15076 "An ordered list as a regular-expression\n")
15077{
d62a17ae 15078 int style = EXTCOMMUNITY_LIST_EXPANDED;
15079 int direct = 0;
15080 char *cl_number_or_name = NULL;
d4455c89 15081 char *str = NULL;
42f914d4 15082
d62a17ae 15083 int idx = 0;
7336e101
SP
15084 if (argv_find(argv, argc, "ip", &idx)) {
15085 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15086 vty_out(vty, "if you are using this please migrate to the below command.\n");
15087 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15088 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15089 }
d4455c89
DA
15090
15091 idx = 0;
15092 argv_find(argv, argc, "permit", &idx);
15093 argv_find(argv, argc, "deny", &idx);
15094
15095 if (idx) {
15096 direct = argv_find(argv, argc, "permit", &idx)
15097 ? COMMUNITY_PERMIT
15098 : COMMUNITY_DENY;
15099
15100 idx = 0;
15101 argv_find(argv, argc, "LINE", &idx);
15102 str = argv_concat(argv, argc, idx);
15103 }
15104
15105 idx = 0;
d62a17ae 15106 argv_find(argv, argc, "(100-500)", &idx);
15107 argv_find(argv, argc, "WORD", &idx);
15108 cl_number_or_name = argv[idx]->arg;
42f914d4 15109
d62a17ae 15110 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15111 direct, style);
42f914d4 15112
d62a17ae 15113 XFREE(MTYPE_TMP, str);
42f914d4 15114
d62a17ae 15115 if (ret < 0) {
15116 community_list_perror(vty, ret);
15117 return CMD_WARNING_CONFIG_FAILED;
15118 }
42f914d4 15119
d62a17ae 15120 return CMD_SUCCESS;
718e3744 15121}
15122
7336e101
SP
15123ALIAS (no_extcommunity_list_expanded_all,
15124 no_ip_extcommunity_list_expanded_all_cmd,
15125 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15126 NO_STR
15127 IP_STR
15128 EXTCOMMUNITY_LIST_STR
15129 "Extended Community list number (expanded)\n"
15130 "Specify expanded extcommunity-list\n"
15131 "Extended Community list name\n"
15132 "Specify community to reject\n"
15133 "Specify community to accept\n"
15134 "An ordered list as a regular-expression\n")
15135
d4455c89
DA
15136ALIAS(no_extcommunity_list_expanded_all,
15137 no_ip_extcommunity_list_expanded_all_list_cmd,
15138 "no ip extcommunity-list <(100-500)|expanded WORD>",
15139 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15140 "Extended Community list number (expanded)\n"
15141 "Specify expanded extcommunity-list\n"
15142 "Extended Community list name\n")
15143
15144ALIAS(no_extcommunity_list_expanded_all,
15145 no_bgp_extcommunity_list_expanded_all_list_cmd,
15146 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15147 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15148 "Extended Community list number (expanded)\n"
15149 "Specify expanded extcommunity-list\n"
15150 "Extended Community list name\n")
15151
d62a17ae 15152static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15153{
d62a17ae 15154 struct community_entry *entry;
718e3744 15155
d62a17ae 15156 for (entry = list->head; entry; entry = entry->next) {
15157 if (entry == list->head) {
15158 if (all_digit(list->name))
15159 vty_out(vty, "Extended community %s list %s\n",
15160 entry->style == EXTCOMMUNITY_LIST_STANDARD
15161 ? "standard"
15162 : "(expanded) access",
15163 list->name);
15164 else
15165 vty_out(vty,
15166 "Named extended community %s list %s\n",
15167 entry->style == EXTCOMMUNITY_LIST_STANDARD
15168 ? "standard"
15169 : "expanded",
15170 list->name);
15171 }
15172 if (entry->any)
15173 vty_out(vty, " %s\n",
15174 community_direct_str(entry->direct));
15175 else
15176 vty_out(vty, " %s %s\n",
15177 community_direct_str(entry->direct),
8d9b8ed9 15178 community_list_config_str(entry));
d62a17ae 15179 }
718e3744 15180}
15181
7336e101
SP
15182DEFUN (show_extcommunity_list,
15183 show_bgp_extcommunity_list_cmd,
15184 "show bgp extcommunity-list",
718e3744 15185 SHOW_STR
7336e101 15186 BGP_STR
718e3744 15187 "List extended-community list\n")
15188{
d62a17ae 15189 struct community_list *list;
15190 struct community_list_master *cm;
7336e101 15191 int idx = 0;
718e3744 15192
7336e101
SP
15193 if (argv_find(argv, argc, "ip", &idx)) {
15194 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15195 vty_out(vty, "if you are using this please migrate to the below command.\n");
15196 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15197 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15198 }
d62a17ae 15199 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15200 if (!cm)
15201 return CMD_SUCCESS;
718e3744 15202
d62a17ae 15203 for (list = cm->num.head; list; list = list->next)
15204 extcommunity_list_show(vty, list);
718e3744 15205
d62a17ae 15206 for (list = cm->str.head; list; list = list->next)
15207 extcommunity_list_show(vty, list);
718e3744 15208
d62a17ae 15209 return CMD_SUCCESS;
718e3744 15210}
15211
7336e101
SP
15212ALIAS (show_extcommunity_list,
15213 show_ip_extcommunity_list_cmd,
15214 "show ip extcommunity-list",
718e3744 15215 SHOW_STR
15216 IP_STR
7336e101
SP
15217 "List extended-community list\n")
15218
15219DEFUN (show_extcommunity_list_arg,
15220 show_bgp_extcommunity_list_arg_cmd,
15221 "show bgp extcommunity-list <(1-500)|WORD>",
15222 SHOW_STR
15223 BGP_STR
718e3744 15224 "List extended-community list\n"
15225 "Extcommunity-list number\n"
15226 "Extcommunity-list name\n")
15227{
d62a17ae 15228 int idx_comm_list = 3;
15229 struct community_list *list;
7336e101 15230 int idx = 0;
718e3744 15231
7336e101
SP
15232 if (argv_find(argv, argc, "ip", &idx)) {
15233 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15234 vty_out(vty, "if you are using this please migrate to the below command.\n");
15235 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15236 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15237 }
d62a17ae 15238 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15239 EXTCOMMUNITY_LIST_MASTER);
15240 if (!list) {
15241 vty_out(vty, "%% Can't find extcommunity-list\n");
15242 return CMD_WARNING;
15243 }
718e3744 15244
d62a17ae 15245 extcommunity_list_show(vty, list);
718e3744 15246
d62a17ae 15247 return CMD_SUCCESS;
718e3744 15248}
6b0655a2 15249
7336e101
SP
15250ALIAS (show_extcommunity_list_arg,
15251 show_ip_extcommunity_list_arg_cmd,
15252 "show ip extcommunity-list <(1-500)|WORD>",
15253 SHOW_STR
15254 IP_STR
15255 "List extended-community list\n"
15256 "Extcommunity-list number\n"
15257 "Extcommunity-list name\n")
15258
718e3744 15259/* Display community-list and extcommunity-list configuration. */
d62a17ae 15260static int community_list_config_write(struct vty *vty)
15261{
15262 struct community_list *list;
15263 struct community_entry *entry;
15264 struct community_list_master *cm;
15265 int write = 0;
15266
15267 /* Community-list. */
15268 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15269
15270 for (list = cm->num.head; list; list = list->next)
15271 for (entry = list->head; entry; entry = entry->next) {
7336e101 15272 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15273 community_direct_str(entry->direct),
15274 community_list_config_str(entry));
15275 write++;
15276 }
15277 for (list = cm->str.head; list; list = list->next)
15278 for (entry = list->head; entry; entry = entry->next) {
7336e101 15279 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15280 entry->style == COMMUNITY_LIST_STANDARD
15281 ? "standard"
15282 : "expanded",
15283 list->name, community_direct_str(entry->direct),
15284 community_list_config_str(entry));
15285 write++;
15286 }
15287
15288 /* Extcommunity-list. */
15289 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15290
15291 for (list = cm->num.head; list; list = list->next)
15292 for (entry = list->head; entry; entry = entry->next) {
7336e101 15293 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15294 list->name, community_direct_str(entry->direct),
15295 community_list_config_str(entry));
15296 write++;
15297 }
15298 for (list = cm->str.head; list; list = list->next)
15299 for (entry = list->head; entry; entry = entry->next) {
7336e101 15300 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15301 entry->style == EXTCOMMUNITY_LIST_STANDARD
15302 ? "standard"
15303 : "expanded",
15304 list->name, community_direct_str(entry->direct),
15305 community_list_config_str(entry));
15306 write++;
15307 }
15308
15309
15310 /* lcommunity-list. */
15311 cm = community_list_master_lookup(bgp_clist,
15312 LARGE_COMMUNITY_LIST_MASTER);
15313
15314 for (list = cm->num.head; list; list = list->next)
15315 for (entry = list->head; entry; entry = entry->next) {
7336e101 15316 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15317 list->name, community_direct_str(entry->direct),
15318 community_list_config_str(entry));
15319 write++;
15320 }
15321 for (list = cm->str.head; list; list = list->next)
15322 for (entry = list->head; entry; entry = entry->next) {
7336e101 15323 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15324 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15325 ? "standard"
15326 : "expanded",
15327 list->name, community_direct_str(entry->direct),
15328 community_list_config_str(entry));
15329 write++;
15330 }
15331
15332 return write;
15333}
15334
15335static struct cmd_node community_list_node = {
15336 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15337};
15338
d62a17ae 15339static void community_list_vty(void)
15340{
15341 install_node(&community_list_node, community_list_config_write);
15342
15343 /* Community-list. */
7336e101
SP
15344 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15345 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15346 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15347 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15348 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15349 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15350 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15351 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15352 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15353 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15354 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15355 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15356 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15357 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15358 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15359 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15360
15361 /* Extcommunity-list. */
7336e101
SP
15362 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15363 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15364 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15365 install_element(CONFIG_NODE,
15366 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15367 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15368 install_element(CONFIG_NODE,
15369 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15370 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15371 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15372 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15373 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15374 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15375 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15376 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15377 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15378 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15379 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15380
15381 /* Large Community List */
7336e101
SP
15382 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15383 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15384 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15385 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15386 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15387 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15388 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15389 install_element(CONFIG_NODE,
15390 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15391 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15392 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15393 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15394 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15395 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15396 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15397 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15398 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15399 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15400 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15401 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15402 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15403 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15404 install_element(CONFIG_NODE,
15405 &no_ip_lcommunity_list_name_expanded_all_cmd);
15406 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15407 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15408 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15409 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15410 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15411 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15412}