]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd isisd lib: fix return on void functions
[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
PM
604 if (!found)
605 vty_out(vty, "%%BGP: No %s peer configured",
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;
975 int ret;
976 as_t as;
977 struct bgp *bgp;
978 const char *name = NULL;
979 enum bgp_instance_type inst_type;
980
981 // "router bgp" without an ASN
982 if (argc == 2) {
983 // Pending: Make VRF option available for ASN less config
984 bgp = bgp_get_default();
985
986 if (bgp == NULL) {
987 vty_out(vty, "%% No BGP process is configured\n");
988 return CMD_WARNING_CONFIG_FAILED;
989 }
990
991 if (listcount(bm->bgp) > 1) {
996c9314 992 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 993 return CMD_WARNING_CONFIG_FAILED;
994 }
995 }
996
997 // "router bgp X"
998 else {
999 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1000
1001 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1002 if (argc > 3) {
1003 name = argv[idx_vrf]->arg;
1004
9a8bdf1c
PG
1005 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1006 if (strmatch(name, VRF_DEFAULT_NAME))
1007 name = NULL;
1008 else
1009 inst_type = BGP_INSTANCE_TYPE_VRF;
1010 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1011 inst_type = BGP_INSTANCE_TYPE_VIEW;
1012 }
1013
1014 ret = bgp_get(&bgp, &as, name, inst_type);
1015 switch (ret) {
1016 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1017 vty_out(vty,
1018 "Please specify 'bgp multiple-instance' first\n");
1019 return CMD_WARNING_CONFIG_FAILED;
1020 case BGP_ERR_AS_MISMATCH:
1021 vty_out(vty, "BGP is already running; AS is %u\n", as);
1022 return CMD_WARNING_CONFIG_FAILED;
1023 case BGP_ERR_INSTANCE_MISMATCH:
1024 vty_out(vty,
1025 "BGP instance name and AS number mismatch\n");
1026 vty_out(vty,
1027 "BGP instance is already running; AS is %u\n",
1028 as);
1029 return CMD_WARNING_CONFIG_FAILED;
1030 }
1031
3bd70bf8
PZ
1032 /*
1033 * If we just instantiated the default instance, complete
1034 * any pending VRF-VPN leaking that was configured via
1035 * earlier "router bgp X vrf FOO" blocks.
1036 */
1037 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1038 vpn_leak_postchange_all();
1039
d62a17ae 1040 /* Pending: handle when user tries to change a view to vrf n vv.
1041 */
1042 }
1043
0b5131c9
MK
1044 /* unset the auto created flag as the user config is now present */
1045 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1046 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1047
1048 return CMD_SUCCESS;
718e3744 1049}
1050
718e3744 1051/* "no router bgp" commands. */
1052DEFUN (no_router_bgp,
1053 no_router_bgp_cmd,
18c57037 1054 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 1055 NO_STR
1056 ROUTER_STR
1057 BGP_STR
31500417
DW
1058 AS_STR
1059 BGP_INSTANCE_HELP_STR)
718e3744 1060{
d62a17ae 1061 int idx_asn = 3;
1062 int idx_vrf = 5;
1063 as_t as;
1064 struct bgp *bgp;
1065 const char *name = NULL;
718e3744 1066
d62a17ae 1067 // "no router bgp" without an ASN
1068 if (argc == 3) {
1069 // Pending: Make VRF option available for ASN less config
1070 bgp = bgp_get_default();
718e3744 1071
d62a17ae 1072 if (bgp == NULL) {
1073 vty_out(vty, "%% No BGP process is configured\n");
1074 return CMD_WARNING_CONFIG_FAILED;
1075 }
7fb21a9f 1076
d62a17ae 1077 if (listcount(bm->bgp) > 1) {
996c9314 1078 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1079 return CMD_WARNING_CONFIG_FAILED;
1080 }
0b5131c9
MK
1081
1082 if (bgp->l3vni) {
1083 vty_out(vty, "%% Please unconfigure l3vni %u",
1084 bgp->l3vni);
1085 return CMD_WARNING_CONFIG_FAILED;
1086 }
d62a17ae 1087 } else {
1088 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1089
d62a17ae 1090 if (argc > 4)
1091 name = argv[idx_vrf]->arg;
7fb21a9f 1092
d62a17ae 1093 /* Lookup bgp structure. */
1094 bgp = bgp_lookup(as, name);
1095 if (!bgp) {
1096 vty_out(vty, "%% Can't find BGP instance\n");
1097 return CMD_WARNING_CONFIG_FAILED;
1098 }
0b5131c9
MK
1099
1100 if (bgp->l3vni) {
1101 vty_out(vty, "%% Please unconfigure l3vni %u",
1102 bgp->l3vni);
1103 return CMD_WARNING_CONFIG_FAILED;
1104 }
d62a17ae 1105 }
718e3744 1106
d62a17ae 1107 bgp_delete(bgp);
718e3744 1108
d62a17ae 1109 return CMD_SUCCESS;
718e3744 1110}
1111
6b0655a2 1112
718e3744 1113/* BGP router-id. */
1114
f787d7a0 1115DEFPY (bgp_router_id,
718e3744 1116 bgp_router_id_cmd,
1117 "bgp router-id A.B.C.D",
1118 BGP_STR
1119 "Override configured router identifier\n"
1120 "Manually configured router identifier\n")
1121{
d62a17ae 1122 VTY_DECLVAR_CONTEXT(bgp, bgp);
1123 bgp_router_id_static_set(bgp, router_id);
1124 return CMD_SUCCESS;
718e3744 1125}
1126
f787d7a0 1127DEFPY (no_bgp_router_id,
718e3744 1128 no_bgp_router_id_cmd,
31500417 1129 "no bgp router-id [A.B.C.D]",
718e3744 1130 NO_STR
1131 BGP_STR
31500417
DW
1132 "Override configured router identifier\n"
1133 "Manually configured router identifier\n")
718e3744 1134{
d62a17ae 1135 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1136
d62a17ae 1137 if (router_id_str) {
1138 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1139 vty_out(vty, "%% BGP router-id doesn't match\n");
1140 return CMD_WARNING_CONFIG_FAILED;
1141 }
e018c7cc 1142 }
718e3744 1143
d62a17ae 1144 router_id.s_addr = 0;
1145 bgp_router_id_static_set(bgp, router_id);
718e3744 1146
d62a17ae 1147 return CMD_SUCCESS;
718e3744 1148}
1149
6b0655a2 1150
718e3744 1151/* BGP Cluster ID. */
718e3744 1152DEFUN (bgp_cluster_id,
1153 bgp_cluster_id_cmd,
838758ac 1154 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1155 BGP_STR
1156 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1157 "Route-Reflector Cluster-id in IP address format\n"
1158 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1159{
d62a17ae 1160 VTY_DECLVAR_CONTEXT(bgp, bgp);
1161 int idx_ipv4 = 2;
1162 int ret;
1163 struct in_addr cluster;
718e3744 1164
d62a17ae 1165 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1166 if (!ret) {
1167 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1168 return CMD_WARNING_CONFIG_FAILED;
1169 }
718e3744 1170
d62a17ae 1171 bgp_cluster_id_set(bgp, &cluster);
1172 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1173
d62a17ae 1174 return CMD_SUCCESS;
718e3744 1175}
1176
718e3744 1177DEFUN (no_bgp_cluster_id,
1178 no_bgp_cluster_id_cmd,
c7178fe7 1179 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1180 NO_STR
1181 BGP_STR
838758ac
DW
1182 "Configure Route-Reflector Cluster-id\n"
1183 "Route-Reflector Cluster-id in IP address format\n"
1184 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1185{
d62a17ae 1186 VTY_DECLVAR_CONTEXT(bgp, bgp);
1187 bgp_cluster_id_unset(bgp);
1188 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1189
d62a17ae 1190 return CMD_SUCCESS;
718e3744 1191}
1192
718e3744 1193DEFUN (bgp_confederation_identifier,
1194 bgp_confederation_identifier_cmd,
9ccf14f7 1195 "bgp confederation identifier (1-4294967295)",
718e3744 1196 "BGP specific commands\n"
1197 "AS confederation parameters\n"
1198 "AS number\n"
1199 "Set routing domain confederation AS\n")
1200{
d62a17ae 1201 VTY_DECLVAR_CONTEXT(bgp, bgp);
1202 int idx_number = 3;
1203 as_t as;
718e3744 1204
d62a17ae 1205 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1206
d62a17ae 1207 bgp_confederation_id_set(bgp, as);
718e3744 1208
d62a17ae 1209 return CMD_SUCCESS;
718e3744 1210}
1211
1212DEFUN (no_bgp_confederation_identifier,
1213 no_bgp_confederation_identifier_cmd,
838758ac 1214 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1215 NO_STR
1216 "BGP specific commands\n"
1217 "AS confederation parameters\n"
3a2d747c
QY
1218 "AS number\n"
1219 "Set routing domain confederation AS\n")
718e3744 1220{
d62a17ae 1221 VTY_DECLVAR_CONTEXT(bgp, bgp);
1222 bgp_confederation_id_unset(bgp);
718e3744 1223
d62a17ae 1224 return CMD_SUCCESS;
718e3744 1225}
1226
718e3744 1227DEFUN (bgp_confederation_peers,
1228 bgp_confederation_peers_cmd,
12dcf78e 1229 "bgp confederation peers (1-4294967295)...",
718e3744 1230 "BGP specific commands\n"
1231 "AS confederation parameters\n"
1232 "Peer ASs in BGP confederation\n"
1233 AS_STR)
1234{
d62a17ae 1235 VTY_DECLVAR_CONTEXT(bgp, bgp);
1236 int idx_asn = 3;
1237 as_t as;
1238 int i;
718e3744 1239
d62a17ae 1240 for (i = idx_asn; i < argc; i++) {
1241 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1242
d62a17ae 1243 if (bgp->as == as) {
1244 vty_out(vty,
1245 "%% Local member-AS not allowed in confed peer list\n");
1246 continue;
1247 }
718e3744 1248
d62a17ae 1249 bgp_confederation_peers_add(bgp, as);
1250 }
1251 return CMD_SUCCESS;
718e3744 1252}
1253
1254DEFUN (no_bgp_confederation_peers,
1255 no_bgp_confederation_peers_cmd,
e83a9414 1256 "no bgp confederation peers (1-4294967295)...",
718e3744 1257 NO_STR
1258 "BGP specific commands\n"
1259 "AS confederation parameters\n"
1260 "Peer ASs in BGP confederation\n"
1261 AS_STR)
1262{
d62a17ae 1263 VTY_DECLVAR_CONTEXT(bgp, bgp);
1264 int idx_asn = 4;
1265 as_t as;
1266 int i;
718e3744 1267
d62a17ae 1268 for (i = idx_asn; i < argc; i++) {
1269 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1270
d62a17ae 1271 bgp_confederation_peers_remove(bgp, as);
1272 }
1273 return CMD_SUCCESS;
718e3744 1274}
6b0655a2 1275
5e242b0d
DS
1276/**
1277 * Central routine for maximum-paths configuration.
1278 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1279 * @set: 1 for setting values, 0 for removing the max-paths config.
1280 */
d62a17ae 1281static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1282 const char *mpaths, uint16_t options,
d62a17ae 1283 int set)
1284{
1285 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1286 uint16_t maxpaths = 0;
d62a17ae 1287 int ret;
1288 afi_t afi;
1289 safi_t safi;
1290
1291 afi = bgp_node_afi(vty);
1292 safi = bgp_node_safi(vty);
1293
1294 if (set) {
1295 maxpaths = strtol(mpaths, NULL, 10);
1296 if (maxpaths > multipath_num) {
1297 vty_out(vty,
1298 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1299 maxpaths, multipath_num);
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
1302 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1303 options);
1304 } else
1305 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1306
1307 if (ret < 0) {
1308 vty_out(vty,
1309 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1310 (set == 1) ? "" : "un",
1311 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1312 maxpaths, afi, safi);
1313 return CMD_WARNING_CONFIG_FAILED;
1314 }
1315
1316 bgp_recalculate_all_bestpaths(bgp);
1317
1318 return CMD_SUCCESS;
165b5fff
JB
1319}
1320
abc920f8
DS
1321DEFUN (bgp_maxmed_admin,
1322 bgp_maxmed_admin_cmd,
1323 "bgp max-med administrative ",
1324 BGP_STR
1325 "Advertise routes with max-med\n"
1326 "Administratively applied, for an indefinite period\n")
1327{
d62a17ae 1328 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1329
d62a17ae 1330 bgp->v_maxmed_admin = 1;
1331 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1332
d62a17ae 1333 bgp_maxmed_update(bgp);
abc920f8 1334
d62a17ae 1335 return CMD_SUCCESS;
abc920f8
DS
1336}
1337
1338DEFUN (bgp_maxmed_admin_medv,
1339 bgp_maxmed_admin_medv_cmd,
4668a151 1340 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1341 BGP_STR
1342 "Advertise routes with max-med\n"
1343 "Administratively applied, for an indefinite period\n"
1344 "Max MED value to be used\n")
1345{
d62a17ae 1346 VTY_DECLVAR_CONTEXT(bgp, bgp);
1347 int idx_number = 3;
abc920f8 1348
d62a17ae 1349 bgp->v_maxmed_admin = 1;
1350 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1351
d62a17ae 1352 bgp_maxmed_update(bgp);
abc920f8 1353
d62a17ae 1354 return CMD_SUCCESS;
abc920f8
DS
1355}
1356
1357DEFUN (no_bgp_maxmed_admin,
1358 no_bgp_maxmed_admin_cmd,
4668a151 1359 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1360 NO_STR
1361 BGP_STR
1362 "Advertise routes with max-med\n"
838758ac
DW
1363 "Administratively applied, for an indefinite period\n"
1364 "Max MED value to be used\n")
abc920f8 1365{
d62a17ae 1366 VTY_DECLVAR_CONTEXT(bgp, bgp);
1367 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1368 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1369 bgp_maxmed_update(bgp);
abc920f8 1370
d62a17ae 1371 return CMD_SUCCESS;
abc920f8
DS
1372}
1373
abc920f8
DS
1374DEFUN (bgp_maxmed_onstartup,
1375 bgp_maxmed_onstartup_cmd,
4668a151 1376 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1377 BGP_STR
1378 "Advertise routes with max-med\n"
1379 "Effective on a startup\n"
1380 "Time (seconds) period for max-med\n"
1381 "Max MED value to be used\n")
1382{
d62a17ae 1383 VTY_DECLVAR_CONTEXT(bgp, bgp);
1384 int idx = 0;
4668a151 1385
d62a17ae 1386 argv_find(argv, argc, "(5-86400)", &idx);
1387 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1388 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1389 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1390 else
1391 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1392
d62a17ae 1393 bgp_maxmed_update(bgp);
abc920f8 1394
d62a17ae 1395 return CMD_SUCCESS;
abc920f8
DS
1396}
1397
1398DEFUN (no_bgp_maxmed_onstartup,
1399 no_bgp_maxmed_onstartup_cmd,
4668a151 1400 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1401 NO_STR
1402 BGP_STR
1403 "Advertise routes with max-med\n"
838758ac
DW
1404 "Effective on a startup\n"
1405 "Time (seconds) period for max-med\n"
1406 "Max MED value to be used\n")
abc920f8 1407{
d62a17ae 1408 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1409
d62a17ae 1410 /* Cancel max-med onstartup if its on */
1411 if (bgp->t_maxmed_onstartup) {
1412 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1413 bgp->maxmed_onstartup_over = 1;
1414 }
abc920f8 1415
d62a17ae 1416 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1417 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1418
d62a17ae 1419 bgp_maxmed_update(bgp);
abc920f8 1420
d62a17ae 1421 return CMD_SUCCESS;
abc920f8
DS
1422}
1423
d62a17ae 1424static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1425 const char *wait)
f188f2c4 1426{
d62a17ae 1427 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1428 uint16_t update_delay;
1429 uint16_t establish_wait;
f188f2c4 1430
d62a17ae 1431 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1432
d62a17ae 1433 if (!wait) /* update-delay <delay> */
1434 {
1435 bgp->v_update_delay = update_delay;
1436 bgp->v_establish_wait = bgp->v_update_delay;
1437 return CMD_SUCCESS;
1438 }
f188f2c4 1439
d62a17ae 1440 /* update-delay <delay> <establish-wait> */
1441 establish_wait = atoi(wait);
1442 if (update_delay < establish_wait) {
1443 vty_out(vty,
1444 "%%Failed: update-delay less than the establish-wait!\n");
1445 return CMD_WARNING_CONFIG_FAILED;
1446 }
f188f2c4 1447
d62a17ae 1448 bgp->v_update_delay = update_delay;
1449 bgp->v_establish_wait = establish_wait;
f188f2c4 1450
d62a17ae 1451 return CMD_SUCCESS;
f188f2c4
DS
1452}
1453
d62a17ae 1454static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1455{
d62a17ae 1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1457
d62a17ae 1458 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1459 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1460
d62a17ae 1461 return CMD_SUCCESS;
f188f2c4
DS
1462}
1463
2b791107 1464void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1465{
d62a17ae 1466 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1467 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1468 if (bgp->v_update_delay != bgp->v_establish_wait)
1469 vty_out(vty, " %d", bgp->v_establish_wait);
1470 vty_out(vty, "\n");
1471 }
f188f2c4
DS
1472}
1473
1474
1475/* Update-delay configuration */
1476DEFUN (bgp_update_delay,
1477 bgp_update_delay_cmd,
6147e2c6 1478 "update-delay (0-3600)",
f188f2c4
DS
1479 "Force initial delay for best-path and updates\n"
1480 "Seconds\n")
1481{
d62a17ae 1482 int idx_number = 1;
1483 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1484}
1485
1486DEFUN (bgp_update_delay_establish_wait,
1487 bgp_update_delay_establish_wait_cmd,
6147e2c6 1488 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1489 "Force initial delay for best-path and updates\n"
1490 "Seconds\n"
f188f2c4
DS
1491 "Seconds\n")
1492{
d62a17ae 1493 int idx_number = 1;
1494 int idx_number_2 = 2;
1495 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1496 argv[idx_number_2]->arg);
f188f2c4
DS
1497}
1498
1499/* Update-delay deconfiguration */
1500DEFUN (no_bgp_update_delay,
1501 no_bgp_update_delay_cmd,
838758ac
DW
1502 "no update-delay [(0-3600) [(1-3600)]]",
1503 NO_STR
f188f2c4 1504 "Force initial delay for best-path and updates\n"
838758ac 1505 "Seconds\n"
7111c1a0 1506 "Seconds\n")
f188f2c4 1507{
d62a17ae 1508 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1509}
1510
5e242b0d 1511
d62a17ae 1512static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1513 char set)
cb1faec9 1514{
d62a17ae 1515 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1516
555e09d4
QY
1517 if (set) {
1518 uint32_t quanta = strtoul(num, NULL, 10);
1519 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1520 memory_order_relaxed);
1521 } else {
1522 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1523 memory_order_relaxed);
1524 }
1525
1526 return CMD_SUCCESS;
1527}
1528
1529static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1530 char set)
1531{
1532 VTY_DECLVAR_CONTEXT(bgp, bgp);
1533
1534 if (set) {
1535 uint32_t quanta = strtoul(num, NULL, 10);
1536 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1537 memory_order_relaxed);
1538 } else {
1539 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1540 memory_order_relaxed);
1541 }
cb1faec9 1542
d62a17ae 1543 return CMD_SUCCESS;
cb1faec9
DS
1544}
1545
2b791107 1546void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1547{
555e09d4
QY
1548 uint32_t quanta =
1549 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1550 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1551 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1552}
1553
555e09d4
QY
1554void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1555{
1556 uint32_t quanta =
1557 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1558 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1559 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1560}
cb1faec9 1561
555e09d4 1562/* Packet quanta configuration */
cb1faec9
DS
1563DEFUN (bgp_wpkt_quanta,
1564 bgp_wpkt_quanta_cmd,
555e09d4 1565 "write-quanta (1-10)",
cb1faec9
DS
1566 "How many packets to write to peer socket per run\n"
1567 "Number of packets\n")
1568{
d62a17ae 1569 int idx_number = 1;
1570 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1571}
1572
cb1faec9
DS
1573DEFUN (no_bgp_wpkt_quanta,
1574 no_bgp_wpkt_quanta_cmd,
555e09d4 1575 "no write-quanta (1-10)",
d7fa34c1 1576 NO_STR
555e09d4 1577 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1578 "Number of packets\n")
1579{
d62a17ae 1580 int idx_number = 2;
1581 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1582}
1583
555e09d4
QY
1584DEFUN (bgp_rpkt_quanta,
1585 bgp_rpkt_quanta_cmd,
1586 "read-quanta (1-10)",
1587 "How many packets to read from peer socket per I/O cycle\n"
1588 "Number of packets\n")
1589{
1590 int idx_number = 1;
1591 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1592}
1593
1594DEFUN (no_bgp_rpkt_quanta,
1595 no_bgp_rpkt_quanta_cmd,
1596 "no read-quanta (1-10)",
1597 NO_STR
1598 "How many packets to read from peer socket per I/O cycle\n"
1599 "Number of packets\n")
1600{
1601 int idx_number = 2;
1602 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1603}
1604
2b791107 1605void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1606{
37a333fe 1607 if (!bgp->heuristic_coalesce)
d62a17ae 1608 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1609}
1610
1611
1612DEFUN (bgp_coalesce_time,
1613 bgp_coalesce_time_cmd,
6147e2c6 1614 "coalesce-time (0-4294967295)",
3f9c7369
DS
1615 "Subgroup coalesce timer\n"
1616 "Subgroup coalesce timer value (in ms)\n")
1617{
d62a17ae 1618 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1619
d62a17ae 1620 int idx = 0;
1621 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1622 bgp->heuristic_coalesce = false;
d62a17ae 1623 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1624 return CMD_SUCCESS;
3f9c7369
DS
1625}
1626
1627DEFUN (no_bgp_coalesce_time,
1628 no_bgp_coalesce_time_cmd,
6147e2c6 1629 "no coalesce-time (0-4294967295)",
3a2d747c 1630 NO_STR
3f9c7369
DS
1631 "Subgroup coalesce timer\n"
1632 "Subgroup coalesce timer value (in ms)\n")
1633{
d62a17ae 1634 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1635
37a333fe 1636 bgp->heuristic_coalesce = true;
d62a17ae 1637 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1638 return CMD_SUCCESS;
3f9c7369
DS
1639}
1640
5e242b0d
DS
1641/* Maximum-paths configuration */
1642DEFUN (bgp_maxpaths,
1643 bgp_maxpaths_cmd,
6319fd63 1644 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1645 "Forward packets over multiple paths\n"
1646 "Number of paths\n")
1647{
d62a17ae 1648 int idx_number = 1;
1649 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1650 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1651}
1652
d62a17ae 1653ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1654 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1655 "Forward packets over multiple paths\n"
1656 "Number of paths\n")
596c17ba 1657
165b5fff
JB
1658DEFUN (bgp_maxpaths_ibgp,
1659 bgp_maxpaths_ibgp_cmd,
6319fd63 1660 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1661 "Forward packets over multiple paths\n"
1662 "iBGP-multipath\n"
1663 "Number of paths\n")
1664{
d62a17ae 1665 int idx_number = 2;
1666 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1667 argv[idx_number]->arg, 0, 1);
5e242b0d 1668}
165b5fff 1669
d62a17ae 1670ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1671 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1672 "Forward packets over multiple paths\n"
1673 "iBGP-multipath\n"
1674 "Number of paths\n")
596c17ba 1675
5e242b0d
DS
1676DEFUN (bgp_maxpaths_ibgp_cluster,
1677 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1678 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1679 "Forward packets over multiple paths\n"
1680 "iBGP-multipath\n"
1681 "Number of paths\n"
1682 "Match the cluster length\n")
1683{
d62a17ae 1684 int idx_number = 2;
1685 return bgp_maxpaths_config_vty(
1686 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1687 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1688}
1689
d62a17ae 1690ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1691 "maximum-paths ibgp " CMD_RANGE_STR(
1692 1, MULTIPATH_NUM) " equal-cluster-length",
1693 "Forward packets over multiple paths\n"
1694 "iBGP-multipath\n"
1695 "Number of paths\n"
1696 "Match the cluster length\n")
596c17ba 1697
165b5fff
JB
1698DEFUN (no_bgp_maxpaths,
1699 no_bgp_maxpaths_cmd,
6319fd63 1700 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1701 NO_STR
1702 "Forward packets over multiple paths\n"
1703 "Number of paths\n")
1704{
d62a17ae 1705 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1706}
1707
d62a17ae 1708ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1709 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1710 "Forward packets over multiple paths\n"
1711 "Number of paths\n")
596c17ba 1712
165b5fff
JB
1713DEFUN (no_bgp_maxpaths_ibgp,
1714 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1715 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1716 NO_STR
1717 "Forward packets over multiple paths\n"
1718 "iBGP-multipath\n"
838758ac
DW
1719 "Number of paths\n"
1720 "Match the cluster length\n")
165b5fff 1721{
d62a17ae 1722 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1723}
1724
d62a17ae 1725ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1726 "no maximum-paths ibgp [" CMD_RANGE_STR(
1727 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1728 NO_STR
1729 "Forward packets over multiple paths\n"
1730 "iBGP-multipath\n"
1731 "Number of paths\n"
1732 "Match the cluster length\n")
596c17ba 1733
2b791107 1734void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1735 safi_t safi)
165b5fff 1736{
d62a17ae 1737 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1738 vty_out(vty, " maximum-paths %d\n",
1739 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1740 }
165b5fff 1741
d62a17ae 1742 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1743 vty_out(vty, " maximum-paths ibgp %d",
1744 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1745 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1746 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1747 vty_out(vty, " equal-cluster-length");
1748 vty_out(vty, "\n");
1749 }
165b5fff 1750}
6b0655a2 1751
718e3744 1752/* BGP timers. */
1753
1754DEFUN (bgp_timers,
1755 bgp_timers_cmd,
6147e2c6 1756 "timers bgp (0-65535) (0-65535)",
718e3744 1757 "Adjust routing timers\n"
1758 "BGP timers\n"
1759 "Keepalive interval\n"
1760 "Holdtime\n")
1761{
d62a17ae 1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1763 int idx_number = 2;
1764 int idx_number_2 = 3;
1765 unsigned long keepalive = 0;
1766 unsigned long holdtime = 0;
718e3744 1767
d62a17ae 1768 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1769 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1770
d62a17ae 1771 /* Holdtime value check. */
1772 if (holdtime < 3 && holdtime != 0) {
1773 vty_out(vty,
1774 "%% hold time value must be either 0 or greater than 3\n");
1775 return CMD_WARNING_CONFIG_FAILED;
1776 }
718e3744 1777
d62a17ae 1778 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1779
d62a17ae 1780 return CMD_SUCCESS;
718e3744 1781}
1782
1783DEFUN (no_bgp_timers,
1784 no_bgp_timers_cmd,
838758ac 1785 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1786 NO_STR
1787 "Adjust routing timers\n"
838758ac
DW
1788 "BGP timers\n"
1789 "Keepalive interval\n"
1790 "Holdtime\n")
718e3744 1791{
d62a17ae 1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 bgp_timers_unset(bgp);
718e3744 1794
d62a17ae 1795 return CMD_SUCCESS;
718e3744 1796}
1797
6b0655a2 1798
718e3744 1799DEFUN (bgp_client_to_client_reflection,
1800 bgp_client_to_client_reflection_cmd,
1801 "bgp client-to-client reflection",
1802 "BGP specific commands\n"
1803 "Configure client to client route reflection\n"
1804 "reflection of routes allowed\n")
1805{
d62a17ae 1806 VTY_DECLVAR_CONTEXT(bgp, bgp);
1807 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1808 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1809
d62a17ae 1810 return CMD_SUCCESS;
718e3744 1811}
1812
1813DEFUN (no_bgp_client_to_client_reflection,
1814 no_bgp_client_to_client_reflection_cmd,
1815 "no bgp client-to-client reflection",
1816 NO_STR
1817 "BGP specific commands\n"
1818 "Configure client to client route reflection\n"
1819 "reflection of routes allowed\n")
1820{
d62a17ae 1821 VTY_DECLVAR_CONTEXT(bgp, bgp);
1822 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1823 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1824
d62a17ae 1825 return CMD_SUCCESS;
718e3744 1826}
1827
1828/* "bgp always-compare-med" configuration. */
1829DEFUN (bgp_always_compare_med,
1830 bgp_always_compare_med_cmd,
1831 "bgp always-compare-med",
1832 "BGP specific commands\n"
1833 "Allow comparing MED from different neighbors\n")
1834{
d62a17ae 1835 VTY_DECLVAR_CONTEXT(bgp, bgp);
1836 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1837 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1838
d62a17ae 1839 return CMD_SUCCESS;
718e3744 1840}
1841
1842DEFUN (no_bgp_always_compare_med,
1843 no_bgp_always_compare_med_cmd,
1844 "no bgp always-compare-med",
1845 NO_STR
1846 "BGP specific commands\n"
1847 "Allow comparing MED from different neighbors\n")
1848{
d62a17ae 1849 VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1851 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1852
d62a17ae 1853 return CMD_SUCCESS;
718e3744 1854}
6b0655a2 1855
718e3744 1856/* "bgp deterministic-med" configuration. */
1857DEFUN (bgp_deterministic_med,
1858 bgp_deterministic_med_cmd,
1859 "bgp deterministic-med",
1860 "BGP specific commands\n"
1861 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1862{
d62a17ae 1863 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1864
d62a17ae 1865 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1866 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
1868 }
7aafcaca 1869
d62a17ae 1870 return CMD_SUCCESS;
718e3744 1871}
1872
1873DEFUN (no_bgp_deterministic_med,
1874 no_bgp_deterministic_med_cmd,
1875 "no bgp deterministic-med",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1879{
d62a17ae 1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 int bestpath_per_as_used;
1882 afi_t afi;
1883 safi_t safi;
1884 struct peer *peer;
1885 struct listnode *node, *nnode;
1886
1887 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1888 bestpath_per_as_used = 0;
1889
1890 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1891 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1892 if (bgp_addpath_dmed_required(
1893 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1894 bestpath_per_as_used = 1;
1895 break;
1896 }
d62a17ae 1897
1898 if (bestpath_per_as_used)
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used) {
1903 vty_out(vty,
1904 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1905 return CMD_WARNING_CONFIG_FAILED;
1906 } else {
1907 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1908 bgp_recalculate_all_bestpaths(bgp);
1909 }
1910 }
1911
1912 return CMD_SUCCESS;
718e3744 1913}
538621f2 1914
1915/* "bgp graceful-restart" configuration. */
1916DEFUN (bgp_graceful_restart,
1917 bgp_graceful_restart_cmd,
1918 "bgp graceful-restart",
1919 "BGP specific commands\n"
1920 "Graceful restart capability parameters\n")
1921{
d62a17ae 1922 VTY_DECLVAR_CONTEXT(bgp, bgp);
1923 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1924 return CMD_SUCCESS;
538621f2 1925}
1926
1927DEFUN (no_bgp_graceful_restart,
1928 no_bgp_graceful_restart_cmd,
1929 "no bgp graceful-restart",
1930 NO_STR
1931 "BGP specific commands\n"
1932 "Graceful restart capability parameters\n")
1933{
d62a17ae 1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1936 return CMD_SUCCESS;
538621f2 1937}
1938
93406d87 1939DEFUN (bgp_graceful_restart_stalepath_time,
1940 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1941 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1942 "BGP specific commands\n"
1943 "Graceful restart capability parameters\n"
1944 "Set the max time to hold onto restarting peer's stale paths\n"
1945 "Delay value (seconds)\n")
1946{
d62a17ae 1947 VTY_DECLVAR_CONTEXT(bgp, bgp);
1948 int idx_number = 3;
d7c0a89a 1949 uint32_t stalepath;
93406d87 1950
d62a17ae 1951 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1952 bgp->stalepath_time = stalepath;
1953 return CMD_SUCCESS;
93406d87 1954}
1955
eb6f1b41
PG
1956DEFUN (bgp_graceful_restart_restart_time,
1957 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1958 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1959 "BGP specific commands\n"
1960 "Graceful restart capability parameters\n"
1961 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1962 "Delay value (seconds)\n")
1963{
d62a17ae 1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 int idx_number = 3;
d7c0a89a 1966 uint32_t restart;
eb6f1b41 1967
d62a17ae 1968 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1969 bgp->restart_time = restart;
1970 return CMD_SUCCESS;
eb6f1b41
PG
1971}
1972
93406d87 1973DEFUN (no_bgp_graceful_restart_stalepath_time,
1974 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1975 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1976 NO_STR
1977 "BGP specific commands\n"
1978 "Graceful restart capability parameters\n"
838758ac
DW
1979 "Set the max time to hold onto restarting peer's stale paths\n"
1980 "Delay value (seconds)\n")
93406d87 1981{
d62a17ae 1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1983
d62a17ae 1984 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1985 return CMD_SUCCESS;
93406d87 1986}
1987
eb6f1b41
PG
1988DEFUN (no_bgp_graceful_restart_restart_time,
1989 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1990 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1991 NO_STR
1992 "BGP specific commands\n"
1993 "Graceful restart capability parameters\n"
838758ac
DW
1994 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1995 "Delay value (seconds)\n")
eb6f1b41 1996{
d62a17ae 1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1998
d62a17ae 1999 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2000 return CMD_SUCCESS;
eb6f1b41
PG
2001}
2002
43fc21b3
JC
2003DEFUN (bgp_graceful_restart_preserve_fw,
2004 bgp_graceful_restart_preserve_fw_cmd,
2005 "bgp graceful-restart preserve-fw-state",
2006 "BGP specific commands\n"
2007 "Graceful restart capability parameters\n"
2008 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2009{
d62a17ae 2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2012 return CMD_SUCCESS;
43fc21b3
JC
2013}
2014
2015DEFUN (no_bgp_graceful_restart_preserve_fw,
2016 no_bgp_graceful_restart_preserve_fw_cmd,
2017 "no bgp graceful-restart preserve-fw-state",
2018 NO_STR
2019 "BGP specific commands\n"
2020 "Graceful restart capability parameters\n"
2021 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2022{
d62a17ae 2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2025 return CMD_SUCCESS;
43fc21b3
JC
2026}
2027
7f323236
DW
2028static void bgp_redistribute_redo(struct bgp *bgp)
2029{
2030 afi_t afi;
2031 int i;
2032 struct list *red_list;
2033 struct listnode *node;
2034 struct bgp_redist *red;
2035
a4d82a8a
PZ
2036 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2037 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 2038
a4d82a8a
PZ
2039 red_list = bgp->redist[afi][i];
2040 if (!red_list)
2041 continue;
7f323236 2042
a4d82a8a 2043 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
2044 bgp_redistribute_resend(bgp, afi, i,
2045 red->instance);
2046 }
2047 }
2048 }
2049}
2050
2051/* "bgp graceful-shutdown" configuration */
2052DEFUN (bgp_graceful_shutdown,
2053 bgp_graceful_shutdown_cmd,
2054 "bgp graceful-shutdown",
2055 BGP_STR
2056 "Graceful shutdown parameters\n")
2057{
2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
2059
2060 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2061 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2062 bgp_static_redo_import_check(bgp);
2063 bgp_redistribute_redo(bgp);
2064 bgp_clear_star_soft_out(vty, bgp->name);
2065 bgp_clear_star_soft_in(vty, bgp->name);
2066 }
2067
2068 return CMD_SUCCESS;
2069}
2070
2071DEFUN (no_bgp_graceful_shutdown,
2072 no_bgp_graceful_shutdown_cmd,
2073 "no bgp graceful-shutdown",
2074 NO_STR
2075 BGP_STR
2076 "Graceful shutdown parameters\n")
2077{
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079
2080 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2081 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2082 bgp_static_redo_import_check(bgp);
2083 bgp_redistribute_redo(bgp);
2084 bgp_clear_star_soft_out(vty, bgp->name);
2085 bgp_clear_star_soft_in(vty, bgp->name);
2086 }
2087
2088 return CMD_SUCCESS;
2089}
2090
718e3744 2091/* "bgp fast-external-failover" configuration. */
2092DEFUN (bgp_fast_external_failover,
2093 bgp_fast_external_failover_cmd,
2094 "bgp fast-external-failover",
2095 BGP_STR
2096 "Immediately reset session if a link to a directly connected external peer goes down\n")
2097{
d62a17ae 2098 VTY_DECLVAR_CONTEXT(bgp, bgp);
2099 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2100 return CMD_SUCCESS;
718e3744 2101}
2102
2103DEFUN (no_bgp_fast_external_failover,
2104 no_bgp_fast_external_failover_cmd,
2105 "no bgp fast-external-failover",
2106 NO_STR
2107 BGP_STR
2108 "Immediately reset session if a link to a directly connected external peer goes down\n")
2109{
d62a17ae 2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2112 return CMD_SUCCESS;
718e3744 2113}
6b0655a2 2114
718e3744 2115/* "bgp enforce-first-as" configuration. */
ec4f0750 2116#if CONFDATE > 20190517
47cbc09b
PM
2117CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2118#endif
2119
f07e1c4f
QY
2120DEFUN_HIDDEN (bgp_enforce_first_as,
2121 bgp_enforce_first_as_cmd,
2122 "[no] bgp enforce-first-as",
2123 NO_STR
2124 BGP_STR
2125 "Enforce the first AS for EBGP routes\n")
718e3744 2126{
d62a17ae 2127 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2128
f07e1c4f
QY
2129 if (strmatch(argv[0]->text, "no"))
2130 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2131 else
2132 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2133
d62a17ae 2134 return CMD_SUCCESS;
718e3744 2135}
6b0655a2 2136
718e3744 2137/* "bgp bestpath compare-routerid" configuration. */
2138DEFUN (bgp_bestpath_compare_router_id,
2139 bgp_bestpath_compare_router_id_cmd,
2140 "bgp bestpath compare-routerid",
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "Compare router-id for identical EBGP paths\n")
2144{
d62a17ae 2145 VTY_DECLVAR_CONTEXT(bgp, bgp);
2146 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2147 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2148
d62a17ae 2149 return CMD_SUCCESS;
718e3744 2150}
2151
2152DEFUN (no_bgp_bestpath_compare_router_id,
2153 no_bgp_bestpath_compare_router_id_cmd,
2154 "no bgp bestpath compare-routerid",
2155 NO_STR
2156 "BGP specific commands\n"
2157 "Change the default bestpath selection\n"
2158 "Compare router-id for identical EBGP paths\n")
2159{
d62a17ae 2160 VTY_DECLVAR_CONTEXT(bgp, bgp);
2161 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2162 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2163
d62a17ae 2164 return CMD_SUCCESS;
718e3744 2165}
6b0655a2 2166
718e3744 2167/* "bgp bestpath as-path ignore" configuration. */
2168DEFUN (bgp_bestpath_aspath_ignore,
2169 bgp_bestpath_aspath_ignore_cmd,
2170 "bgp bestpath as-path ignore",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "AS-path attribute\n"
2174 "Ignore as-path length in selecting a route\n")
2175{
d62a17ae 2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2178 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2179
d62a17ae 2180 return CMD_SUCCESS;
718e3744 2181}
2182
2183DEFUN (no_bgp_bestpath_aspath_ignore,
2184 no_bgp_bestpath_aspath_ignore_cmd,
2185 "no bgp bestpath as-path ignore",
2186 NO_STR
2187 "BGP specific commands\n"
2188 "Change the default bestpath selection\n"
2189 "AS-path attribute\n"
2190 "Ignore as-path length in selecting a route\n")
2191{
d62a17ae 2192 VTY_DECLVAR_CONTEXT(bgp, bgp);
2193 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2194 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2195
d62a17ae 2196 return CMD_SUCCESS;
718e3744 2197}
6b0655a2 2198
6811845b 2199/* "bgp bestpath as-path confed" configuration. */
2200DEFUN (bgp_bestpath_aspath_confed,
2201 bgp_bestpath_aspath_confed_cmd,
2202 "bgp bestpath as-path confed",
2203 "BGP specific commands\n"
2204 "Change the default bestpath selection\n"
2205 "AS-path attribute\n"
2206 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2207{
d62a17ae 2208 VTY_DECLVAR_CONTEXT(bgp, bgp);
2209 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2210 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2211
d62a17ae 2212 return CMD_SUCCESS;
6811845b 2213}
2214
2215DEFUN (no_bgp_bestpath_aspath_confed,
2216 no_bgp_bestpath_aspath_confed_cmd,
2217 "no bgp bestpath as-path confed",
2218 NO_STR
2219 "BGP specific commands\n"
2220 "Change the default bestpath selection\n"
2221 "AS-path attribute\n"
2222 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2223{
d62a17ae 2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
2225 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2226 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2227
d62a17ae 2228 return CMD_SUCCESS;
6811845b 2229}
6b0655a2 2230
2fdd455c
PM
2231/* "bgp bestpath as-path multipath-relax" configuration. */
2232DEFUN (bgp_bestpath_aspath_multipath_relax,
2233 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2234 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2235 "BGP specific commands\n"
2236 "Change the default bestpath selection\n"
2237 "AS-path attribute\n"
2238 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2239 "Generate an AS_SET\n"
16fc1eec
DS
2240 "Do not generate an AS_SET\n")
2241{
d62a17ae 2242 VTY_DECLVAR_CONTEXT(bgp, bgp);
2243 int idx = 0;
2244 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2245
d62a17ae 2246 /* no-as-set is now the default behavior so we can silently
2247 * ignore it */
2248 if (argv_find(argv, argc, "as-set", &idx))
2249 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2250 else
2251 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2252
d62a17ae 2253 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2254
d62a17ae 2255 return CMD_SUCCESS;
16fc1eec
DS
2256}
2257
219178b6
DW
2258DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2259 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2260 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2261 NO_STR
2262 "BGP specific commands\n"
2263 "Change the default bestpath selection\n"
2264 "AS-path attribute\n"
2265 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2266 "Generate an AS_SET\n"
16fc1eec
DS
2267 "Do not generate an AS_SET\n")
2268{
d62a17ae 2269 VTY_DECLVAR_CONTEXT(bgp, bgp);
2270 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2271 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2272 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2273
d62a17ae 2274 return CMD_SUCCESS;
2fdd455c 2275}
6b0655a2 2276
848973c7 2277/* "bgp log-neighbor-changes" configuration. */
2278DEFUN (bgp_log_neighbor_changes,
2279 bgp_log_neighbor_changes_cmd,
2280 "bgp log-neighbor-changes",
2281 "BGP specific commands\n"
2282 "Log neighbor up/down and reset reason\n")
2283{
d62a17ae 2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2286 return CMD_SUCCESS;
848973c7 2287}
2288
2289DEFUN (no_bgp_log_neighbor_changes,
2290 no_bgp_log_neighbor_changes_cmd,
2291 "no bgp log-neighbor-changes",
2292 NO_STR
2293 "BGP specific commands\n"
2294 "Log neighbor up/down and reset reason\n")
2295{
d62a17ae 2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2298 return CMD_SUCCESS;
848973c7 2299}
6b0655a2 2300
718e3744 2301/* "bgp bestpath med" configuration. */
2302DEFUN (bgp_bestpath_med,
2303 bgp_bestpath_med_cmd,
2d8c1a4d 2304 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2305 "BGP specific commands\n"
2306 "Change the default bestpath selection\n"
2307 "MED attribute\n"
2308 "Compare MED among confederation paths\n"
838758ac
DW
2309 "Treat missing MED as the least preferred one\n"
2310 "Treat missing MED as the least preferred one\n"
2311 "Compare MED among confederation paths\n")
718e3744 2312{
d62a17ae 2313 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2314
d62a17ae 2315 int idx = 0;
2316 if (argv_find(argv, argc, "confed", &idx))
2317 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2318 idx = 0;
2319 if (argv_find(argv, argc, "missing-as-worst", &idx))
2320 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2321
d62a17ae 2322 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2323
d62a17ae 2324 return CMD_SUCCESS;
718e3744 2325}
2326
718e3744 2327DEFUN (no_bgp_bestpath_med,
2328 no_bgp_bestpath_med_cmd,
2d8c1a4d 2329 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2330 NO_STR
2331 "BGP specific commands\n"
2332 "Change the default bestpath selection\n"
2333 "MED attribute\n"
2334 "Compare MED among confederation paths\n"
3a2d747c
QY
2335 "Treat missing MED as the least preferred one\n"
2336 "Treat missing MED as the least preferred one\n"
2337 "Compare MED among confederation paths\n")
718e3744 2338{
d62a17ae 2339 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2340
d62a17ae 2341 int idx = 0;
2342 if (argv_find(argv, argc, "confed", &idx))
2343 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2344 idx = 0;
2345 if (argv_find(argv, argc, "missing-as-worst", &idx))
2346 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2347
d62a17ae 2348 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2349
d62a17ae 2350 return CMD_SUCCESS;
718e3744 2351}
2352
718e3744 2353/* "no bgp default ipv4-unicast". */
2354DEFUN (no_bgp_default_ipv4_unicast,
2355 no_bgp_default_ipv4_unicast_cmd,
2356 "no bgp default ipv4-unicast",
2357 NO_STR
2358 "BGP specific commands\n"
2359 "Configure BGP defaults\n"
2360 "Activate ipv4-unicast for a peer by default\n")
2361{
d62a17ae 2362 VTY_DECLVAR_CONTEXT(bgp, bgp);
2363 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2364 return CMD_SUCCESS;
718e3744 2365}
2366
2367DEFUN (bgp_default_ipv4_unicast,
2368 bgp_default_ipv4_unicast_cmd,
2369 "bgp default ipv4-unicast",
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
2372 "Activate ipv4-unicast for a peer by default\n")
2373{
d62a17ae 2374 VTY_DECLVAR_CONTEXT(bgp, bgp);
2375 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2376 return CMD_SUCCESS;
718e3744 2377}
6b0655a2 2378
04b6bdc0
DW
2379/* Display hostname in certain command outputs */
2380DEFUN (bgp_default_show_hostname,
2381 bgp_default_show_hostname_cmd,
2382 "bgp default show-hostname",
2383 "BGP specific commands\n"
2384 "Configure BGP defaults\n"
0437e105 2385 "Show hostname in certain command outputs\n")
04b6bdc0 2386{
d62a17ae 2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
2388 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2389 return CMD_SUCCESS;
04b6bdc0
DW
2390}
2391
2392DEFUN (no_bgp_default_show_hostname,
2393 no_bgp_default_show_hostname_cmd,
2394 "no bgp default show-hostname",
2395 NO_STR
2396 "BGP specific commands\n"
2397 "Configure BGP defaults\n"
0437e105 2398 "Show hostname in certain command outputs\n")
04b6bdc0 2399{
d62a17ae 2400 VTY_DECLVAR_CONTEXT(bgp, bgp);
2401 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2402 return CMD_SUCCESS;
04b6bdc0
DW
2403}
2404
8233ef81 2405/* "bgp network import-check" configuration. */
718e3744 2406DEFUN (bgp_network_import_check,
2407 bgp_network_import_check_cmd,
5623e905 2408 "bgp network import-check",
718e3744 2409 "BGP specific commands\n"
2410 "BGP network command\n"
5623e905 2411 "Check BGP network route exists in IGP\n")
718e3744 2412{
d62a17ae 2413 VTY_DECLVAR_CONTEXT(bgp, bgp);
2414 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2415 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2416 bgp_static_redo_import_check(bgp);
2417 }
078430f6 2418
d62a17ae 2419 return CMD_SUCCESS;
718e3744 2420}
2421
d62a17ae 2422ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2423 "bgp network import-check exact",
2424 "BGP specific commands\n"
2425 "BGP network command\n"
2426 "Check BGP network route exists in IGP\n"
2427 "Match route precisely\n")
8233ef81 2428
718e3744 2429DEFUN (no_bgp_network_import_check,
2430 no_bgp_network_import_check_cmd,
5623e905 2431 "no bgp network import-check",
718e3744 2432 NO_STR
2433 "BGP specific commands\n"
2434 "BGP network command\n"
2435 "Check BGP network route exists in IGP\n")
2436{
d62a17ae 2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2439 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2440 bgp_static_redo_import_check(bgp);
2441 }
5623e905 2442
d62a17ae 2443 return CMD_SUCCESS;
718e3744 2444}
6b0655a2 2445
718e3744 2446DEFUN (bgp_default_local_preference,
2447 bgp_default_local_preference_cmd,
6147e2c6 2448 "bgp default local-preference (0-4294967295)",
718e3744 2449 "BGP specific commands\n"
2450 "Configure BGP defaults\n"
2451 "local preference (higher=more preferred)\n"
2452 "Configure default local preference value\n")
2453{
d62a17ae 2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
2455 int idx_number = 3;
d7c0a89a 2456 uint32_t local_pref;
718e3744 2457
d62a17ae 2458 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2459
d62a17ae 2460 bgp_default_local_preference_set(bgp, local_pref);
2461 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2462
d62a17ae 2463 return CMD_SUCCESS;
718e3744 2464}
2465
2466DEFUN (no_bgp_default_local_preference,
2467 no_bgp_default_local_preference_cmd,
838758ac 2468 "no bgp default local-preference [(0-4294967295)]",
718e3744 2469 NO_STR
2470 "BGP specific commands\n"
2471 "Configure BGP defaults\n"
838758ac
DW
2472 "local preference (higher=more preferred)\n"
2473 "Configure default local preference value\n")
718e3744 2474{
d62a17ae 2475 VTY_DECLVAR_CONTEXT(bgp, bgp);
2476 bgp_default_local_preference_unset(bgp);
2477 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2478
d62a17ae 2479 return CMD_SUCCESS;
718e3744 2480}
2481
6b0655a2 2482
3f9c7369
DS
2483DEFUN (bgp_default_subgroup_pkt_queue_max,
2484 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2485 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2486 "BGP specific commands\n"
2487 "Configure BGP defaults\n"
2488 "subgroup-pkt-queue-max\n"
2489 "Configure subgroup packet queue max\n")
8bd9d948 2490{
d62a17ae 2491 VTY_DECLVAR_CONTEXT(bgp, bgp);
2492 int idx_number = 3;
d7c0a89a 2493 uint32_t max_size;
8bd9d948 2494
d62a17ae 2495 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2496
d62a17ae 2497 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2498
d62a17ae 2499 return CMD_SUCCESS;
3f9c7369
DS
2500}
2501
2502DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2503 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2504 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2505 NO_STR
2506 "BGP specific commands\n"
2507 "Configure BGP defaults\n"
838758ac
DW
2508 "subgroup-pkt-queue-max\n"
2509 "Configure subgroup packet queue max\n")
3f9c7369 2510{
d62a17ae 2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2513 return CMD_SUCCESS;
8bd9d948
DS
2514}
2515
813d4307 2516
8bd9d948
DS
2517DEFUN (bgp_rr_allow_outbound_policy,
2518 bgp_rr_allow_outbound_policy_cmd,
2519 "bgp route-reflector allow-outbound-policy",
2520 "BGP specific commands\n"
2521 "Allow modifications made by out route-map\n"
2522 "on ibgp neighbors\n")
2523{
d62a17ae 2524 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2525
d62a17ae 2526 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2527 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2528 update_group_announce_rrclients(bgp);
2529 bgp_clear_star_soft_out(vty, bgp->name);
2530 }
8bd9d948 2531
d62a17ae 2532 return CMD_SUCCESS;
8bd9d948
DS
2533}
2534
2535DEFUN (no_bgp_rr_allow_outbound_policy,
2536 no_bgp_rr_allow_outbound_policy_cmd,
2537 "no bgp route-reflector allow-outbound-policy",
2538 NO_STR
2539 "BGP specific commands\n"
2540 "Allow modifications made by out route-map\n"
2541 "on ibgp neighbors\n")
2542{
d62a17ae 2543 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2544
d62a17ae 2545 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2546 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2547 update_group_announce_rrclients(bgp);
2548 bgp_clear_star_soft_out(vty, bgp->name);
2549 }
8bd9d948 2550
d62a17ae 2551 return CMD_SUCCESS;
8bd9d948
DS
2552}
2553
f14e6fdb
DS
2554DEFUN (bgp_listen_limit,
2555 bgp_listen_limit_cmd,
9ccf14f7 2556 "bgp listen limit (1-5000)",
f14e6fdb
DS
2557 "BGP specific commands\n"
2558 "Configure BGP defaults\n"
2559 "maximum number of BGP Dynamic Neighbors that can be created\n"
2560 "Configure Dynamic Neighbors listen limit value\n")
2561{
d62a17ae 2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 int idx_number = 3;
2564 int listen_limit;
f14e6fdb 2565
d62a17ae 2566 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2567
d62a17ae 2568 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2569
d62a17ae 2570 return CMD_SUCCESS;
f14e6fdb
DS
2571}
2572
2573DEFUN (no_bgp_listen_limit,
2574 no_bgp_listen_limit_cmd,
838758ac 2575 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2576 "BGP specific commands\n"
2577 "Configure BGP defaults\n"
2578 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2579 "Configure Dynamic Neighbors listen limit value to default\n"
2580 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2581{
d62a17ae 2582 VTY_DECLVAR_CONTEXT(bgp, bgp);
2583 bgp_listen_limit_unset(bgp);
2584 return CMD_SUCCESS;
f14e6fdb
DS
2585}
2586
2587
20eb8864 2588/*
2589 * Check if this listen range is already configured. Check for exact
2590 * match or overlap based on input.
2591 */
d62a17ae 2592static struct peer_group *listen_range_exists(struct bgp *bgp,
2593 struct prefix *range, int exact)
2594{
2595 struct listnode *node, *nnode;
2596 struct listnode *node1, *nnode1;
2597 struct peer_group *group;
2598 struct prefix *lr;
2599 afi_t afi;
2600 int match;
2601
2602 afi = family2afi(range->family);
2603 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2604 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2605 lr)) {
2606 if (exact)
2607 match = prefix_same(range, lr);
2608 else
2609 match = (prefix_match(range, lr)
2610 || prefix_match(lr, range));
2611 if (match)
2612 return group;
2613 }
2614 }
2615
2616 return NULL;
20eb8864 2617}
2618
f14e6fdb
DS
2619DEFUN (bgp_listen_range,
2620 bgp_listen_range_cmd,
9ccf14f7 2621 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2622 "BGP specific commands\n"
d7fa34c1
QY
2623 "Configure BGP dynamic neighbors listen range\n"
2624 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2625 NEIGHBOR_ADDR_STR
2626 "Member of the peer-group\n"
2627 "Peer-group name\n")
f14e6fdb 2628{
d62a17ae 2629 VTY_DECLVAR_CONTEXT(bgp, bgp);
2630 struct prefix range;
2631 struct peer_group *group, *existing_group;
2632 afi_t afi;
2633 int ret;
2634 int idx = 0;
2635
2636 argv_find(argv, argc, "A.B.C.D/M", &idx);
2637 argv_find(argv, argc, "X:X::X:X/M", &idx);
2638 char *prefix = argv[idx]->arg;
2639 argv_find(argv, argc, "WORD", &idx);
2640 char *peergroup = argv[idx]->arg;
2641
2642 /* Convert IP prefix string to struct prefix. */
2643 ret = str2prefix(prefix, &range);
2644 if (!ret) {
2645 vty_out(vty, "%% Malformed listen range\n");
2646 return CMD_WARNING_CONFIG_FAILED;
2647 }
2648
2649 afi = family2afi(range.family);
2650
2651 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2652 vty_out(vty,
2653 "%% Malformed listen range (link-local address)\n");
2654 return CMD_WARNING_CONFIG_FAILED;
2655 }
2656
2657 apply_mask(&range);
2658
2659 /* Check if same listen range is already configured. */
2660 existing_group = listen_range_exists(bgp, &range, 1);
2661 if (existing_group) {
2662 if (strcmp(existing_group->name, peergroup) == 0)
2663 return CMD_SUCCESS;
2664 else {
2665 vty_out(vty,
2666 "%% Same listen range is attached to peer-group %s\n",
2667 existing_group->name);
2668 return CMD_WARNING_CONFIG_FAILED;
2669 }
2670 }
2671
2672 /* Check if an overlapping listen range exists. */
2673 if (listen_range_exists(bgp, &range, 0)) {
2674 vty_out(vty,
2675 "%% Listen range overlaps with existing listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 group = peer_group_lookup(bgp, peergroup);
2680 if (!group) {
2681 vty_out(vty, "%% Configure the peer-group first\n");
2682 return CMD_WARNING_CONFIG_FAILED;
2683 }
2684
2685 ret = peer_group_listen_range_add(group, &range);
2686 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2687}
2688
2689DEFUN (no_bgp_listen_range,
2690 no_bgp_listen_range_cmd,
d7fa34c1
QY
2691 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2692 NO_STR
f14e6fdb 2693 "BGP specific commands\n"
d7fa34c1
QY
2694 "Unconfigure BGP dynamic neighbors listen range\n"
2695 "Unconfigure BGP dynamic neighbors listen range\n"
2696 NEIGHBOR_ADDR_STR
2697 "Member of the peer-group\n"
2698 "Peer-group name\n")
f14e6fdb 2699{
d62a17ae 2700 VTY_DECLVAR_CONTEXT(bgp, bgp);
2701 struct prefix range;
2702 struct peer_group *group;
2703 afi_t afi;
2704 int ret;
2705 int idx = 0;
2706
2707 argv_find(argv, argc, "A.B.C.D/M", &idx);
2708 argv_find(argv, argc, "X:X::X:X/M", &idx);
2709 char *prefix = argv[idx]->arg;
2710 argv_find(argv, argc, "WORD", &idx);
2711 char *peergroup = argv[idx]->arg;
2712
2713 /* Convert IP prefix string to struct prefix. */
2714 ret = str2prefix(prefix, &range);
2715 if (!ret) {
2716 vty_out(vty, "%% Malformed listen range\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719
2720 afi = family2afi(range.family);
2721
2722 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2723 vty_out(vty,
2724 "%% Malformed listen range (link-local address)\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727
2728 apply_mask(&range);
2729
2730 group = peer_group_lookup(bgp, peergroup);
2731 if (!group) {
2732 vty_out(vty, "%% Peer-group does not exist\n");
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735
2736 ret = peer_group_listen_range_del(group, &range);
2737 return bgp_vty_return(vty, ret);
2738}
2739
2b791107 2740void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2741{
2742 struct peer_group *group;
2743 struct listnode *node, *nnode, *rnode, *nrnode;
2744 struct prefix *range;
2745 afi_t afi;
2746 char buf[PREFIX2STR_BUFFER];
2747
2748 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2749 vty_out(vty, " bgp listen limit %d\n",
2750 bgp->dynamic_neighbors_limit);
2751
2752 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2753 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2754 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2755 nrnode, range)) {
2756 prefix2str(range, buf, sizeof(buf));
2757 vty_out(vty,
2758 " bgp listen range %s peer-group %s\n",
2759 buf, group->name);
2760 }
2761 }
2762 }
f14e6fdb
DS
2763}
2764
2765
907f92c8
DS
2766DEFUN (bgp_disable_connected_route_check,
2767 bgp_disable_connected_route_check_cmd,
2768 "bgp disable-ebgp-connected-route-check",
2769 "BGP specific commands\n"
2770 "Disable checking if nexthop is connected on ebgp sessions\n")
2771{
d62a17ae 2772 VTY_DECLVAR_CONTEXT(bgp, bgp);
2773 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2774 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2775
d62a17ae 2776 return CMD_SUCCESS;
907f92c8
DS
2777}
2778
2779DEFUN (no_bgp_disable_connected_route_check,
2780 no_bgp_disable_connected_route_check_cmd,
2781 "no bgp disable-ebgp-connected-route-check",
2782 NO_STR
2783 "BGP specific commands\n"
2784 "Disable checking if nexthop is connected on ebgp sessions\n")
2785{
d62a17ae 2786 VTY_DECLVAR_CONTEXT(bgp, bgp);
2787 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2788 bgp_clear_star_soft_in(vty, bgp->name);
2789
2790 return CMD_SUCCESS;
2791}
2792
2793
2794static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2795 const char *as_str, afi_t afi, safi_t safi)
2796{
2797 VTY_DECLVAR_CONTEXT(bgp, bgp);
2798 int ret;
2799 as_t as;
2800 int as_type = AS_SPECIFIED;
2801 union sockunion su;
2802
2803 if (as_str[0] == 'i') {
2804 as = 0;
2805 as_type = AS_INTERNAL;
2806 } else if (as_str[0] == 'e') {
2807 as = 0;
2808 as_type = AS_EXTERNAL;
2809 } else {
2810 /* Get AS number. */
2811 as = strtoul(as_str, NULL, 10);
2812 }
2813
2814 /* If peer is peer group, call proper function. */
2815 ret = str2sockunion(peer_str, &su);
2816 if (ret < 0) {
2817 /* Check for peer by interface */
2818 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2819 safi);
2820 if (ret < 0) {
2821 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2822 if (ret < 0) {
2823 vty_out(vty,
d762bcc3
DS
2824 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2825 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
d62a17ae 2826 return CMD_WARNING_CONFIG_FAILED;
2827 }
2828 return CMD_SUCCESS;
2829 }
2830 } else {
2831 if (peer_address_self_check(bgp, &su)) {
2832 vty_out(vty,
2833 "%% Can not configure the local system as neighbor\n");
2834 return CMD_WARNING_CONFIG_FAILED;
2835 }
2836 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2837 }
2838
2839 /* This peer belongs to peer group. */
2840 switch (ret) {
2841 case BGP_ERR_PEER_GROUP_MEMBER:
2842 vty_out(vty,
2843 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2844 as);
2845 return CMD_WARNING_CONFIG_FAILED;
2846 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2847 vty_out(vty,
2848 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2849 as, as_str);
2850 return CMD_WARNING_CONFIG_FAILED;
2851 }
2852 return bgp_vty_return(vty, ret);
718e3744 2853}
2854
f26845f9
QY
2855DEFUN (bgp_default_shutdown,
2856 bgp_default_shutdown_cmd,
2857 "[no] bgp default shutdown",
2858 NO_STR
2859 BGP_STR
2860 "Configure BGP defaults\n"
b012cbe2 2861 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2862{
2863 VTY_DECLVAR_CONTEXT(bgp, bgp);
2864 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2865 return CMD_SUCCESS;
2866}
2867
718e3744 2868DEFUN (neighbor_remote_as,
2869 neighbor_remote_as_cmd,
3a2d747c 2870 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2871 NEIGHBOR_STR
2872 NEIGHBOR_ADDR_STR2
2873 "Specify a BGP neighbor\n"
d7fa34c1 2874 AS_STR
3a2d747c
QY
2875 "Internal BGP peer\n"
2876 "External BGP peer\n")
718e3744 2877{
d62a17ae 2878 int idx_peer = 1;
2879 int idx_remote_as = 3;
2880 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2881 argv[idx_remote_as]->arg, AFI_IP,
2882 SAFI_UNICAST);
2883}
2884
2885static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2886 afi_t afi, safi_t safi, int v6only,
2887 const char *peer_group_name,
2888 const char *as_str)
2889{
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891 as_t as = 0;
2892 int as_type = AS_UNSPECIFIED;
2893 struct peer *peer;
2894 struct peer_group *group;
2895 int ret = 0;
2896 union sockunion su;
2897
2898 group = peer_group_lookup(bgp, conf_if);
2899
2900 if (group) {
2901 vty_out(vty, "%% Name conflict with peer-group \n");
2902 return CMD_WARNING_CONFIG_FAILED;
2903 }
2904
2905 if (as_str) {
2906 if (as_str[0] == 'i') {
2907 as_type = AS_INTERNAL;
2908 } else if (as_str[0] == 'e') {
2909 as_type = AS_EXTERNAL;
2910 } else {
2911 /* Get AS number. */
2912 as = strtoul(as_str, NULL, 10);
2913 as_type = AS_SPECIFIED;
2914 }
2915 }
2916
2917 peer = peer_lookup_by_conf_if(bgp, conf_if);
2918 if (peer) {
2919 if (as_str)
cc4d4ce8 2920 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2921 afi, safi);
2922 } else {
2923 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2924 && afi == AFI_IP && safi == SAFI_UNICAST)
2925 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2926 as_type, 0, 0, NULL);
2927 else
2928 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2929 as_type, afi, safi, NULL);
2930
2931 if (!peer) {
2932 vty_out(vty, "%% BGP failed to create peer\n");
2933 return CMD_WARNING_CONFIG_FAILED;
2934 }
2935
2936 if (v6only)
527de3dc 2937 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2938
2939 /* Request zebra to initiate IPv6 RAs on this interface. We do
2940 * this
2941 * any unnumbered peer in order to not worry about run-time
2942 * transitions
2943 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2944 * address
2945 * gets deleted later etc.)
2946 */
2947 if (peer->ifp)
2948 bgp_zebra_initiate_radv(bgp, peer);
2949 }
2950
2951 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2952 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2953 if (v6only)
527de3dc 2954 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2955 else
527de3dc 2956 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2957
2958 /* v6only flag changed. Reset bgp seesion */
2959 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2960 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2961 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2962 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2963 } else
2964 bgp_session_reset(peer);
2965 }
2966
9fb964de
PM
2967 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2968 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2969 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2970 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2971 }
d62a17ae 2972
2973 if (peer_group_name) {
2974 group = peer_group_lookup(bgp, peer_group_name);
2975 if (!group) {
2976 vty_out(vty, "%% Configure the peer-group first\n");
2977 return CMD_WARNING_CONFIG_FAILED;
2978 }
2979
2980 ret = peer_group_bind(bgp, &su, peer, group, &as);
2981 }
2982
2983 return bgp_vty_return(vty, ret);
a80beece
DS
2984}
2985
4c48cf63
DW
2986DEFUN (neighbor_interface_config,
2987 neighbor_interface_config_cmd,
31500417 2988 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2989 NEIGHBOR_STR
2990 "Interface name or neighbor tag\n"
31500417
DW
2991 "Enable BGP on interface\n"
2992 "Member of the peer-group\n"
16cedbb0 2993 "Peer-group name\n")
4c48cf63 2994{
d62a17ae 2995 int idx_word = 1;
2996 int idx_peer_group_word = 4;
31500417 2997
d62a17ae 2998 if (argc > idx_peer_group_word)
2999 return peer_conf_interface_get(
3000 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3001 argv[idx_peer_group_word]->arg, NULL);
3002 else
3003 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3004 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3005}
3006
4c48cf63
DW
3007DEFUN (neighbor_interface_config_v6only,
3008 neighbor_interface_config_v6only_cmd,
31500417 3009 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
3010 NEIGHBOR_STR
3011 "Interface name or neighbor tag\n"
3012 "Enable BGP on interface\n"
31500417
DW
3013 "Enable BGP with v6 link-local only\n"
3014 "Member of the peer-group\n"
16cedbb0 3015 "Peer-group name\n")
4c48cf63 3016{
d62a17ae 3017 int idx_word = 1;
3018 int idx_peer_group_word = 5;
31500417 3019
d62a17ae 3020 if (argc > idx_peer_group_word)
3021 return peer_conf_interface_get(
3022 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3023 argv[idx_peer_group_word]->arg, NULL);
31500417 3024
d62a17ae 3025 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3026 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3027}
3028
a80beece 3029
b3a39dc5
DD
3030DEFUN (neighbor_interface_config_remote_as,
3031 neighbor_interface_config_remote_as_cmd,
3a2d747c 3032 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3033 NEIGHBOR_STR
3034 "Interface name or neighbor tag\n"
3035 "Enable BGP on interface\n"
3a2d747c 3036 "Specify a BGP neighbor\n"
d7fa34c1 3037 AS_STR
3a2d747c
QY
3038 "Internal BGP peer\n"
3039 "External BGP peer\n")
b3a39dc5 3040{
d62a17ae 3041 int idx_word = 1;
3042 int idx_remote_as = 4;
3043 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3044 SAFI_UNICAST, 0, NULL,
3045 argv[idx_remote_as]->arg);
b3a39dc5
DD
3046}
3047
3048DEFUN (neighbor_interface_v6only_config_remote_as,
3049 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3050 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3051 NEIGHBOR_STR
3052 "Interface name or neighbor tag\n"
3a2d747c 3053 "Enable BGP with v6 link-local only\n"
b3a39dc5 3054 "Enable BGP on interface\n"
3a2d747c 3055 "Specify a BGP neighbor\n"
d7fa34c1 3056 AS_STR
3a2d747c
QY
3057 "Internal BGP peer\n"
3058 "External BGP peer\n")
b3a39dc5 3059{
d62a17ae 3060 int idx_word = 1;
3061 int idx_remote_as = 5;
3062 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3063 SAFI_UNICAST, 1, NULL,
3064 argv[idx_remote_as]->arg);
b3a39dc5
DD
3065}
3066
718e3744 3067DEFUN (neighbor_peer_group,
3068 neighbor_peer_group_cmd,
3069 "neighbor WORD peer-group",
3070 NEIGHBOR_STR
a80beece 3071 "Interface name or neighbor tag\n"
718e3744 3072 "Configure peer-group\n")
3073{
d62a17ae 3074 VTY_DECLVAR_CONTEXT(bgp, bgp);
3075 int idx_word = 1;
3076 struct peer *peer;
3077 struct peer_group *group;
718e3744 3078
d62a17ae 3079 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3080 if (peer) {
3081 vty_out(vty, "%% Name conflict with interface: \n");
3082 return CMD_WARNING_CONFIG_FAILED;
3083 }
718e3744 3084
d62a17ae 3085 group = peer_group_get(bgp, argv[idx_word]->arg);
3086 if (!group) {
3087 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3088 return CMD_WARNING_CONFIG_FAILED;
3089 }
718e3744 3090
d62a17ae 3091 return CMD_SUCCESS;
718e3744 3092}
3093
3094DEFUN (no_neighbor,
3095 no_neighbor_cmd,
dab8cd00 3096 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3097 NO_STR
3098 NEIGHBOR_STR
3a2d747c
QY
3099 NEIGHBOR_ADDR_STR2
3100 "Specify a BGP neighbor\n"
3101 AS_STR
3102 "Internal BGP peer\n"
3103 "External BGP peer\n")
718e3744 3104{
d62a17ae 3105 VTY_DECLVAR_CONTEXT(bgp, bgp);
3106 int idx_peer = 2;
3107 int ret;
3108 union sockunion su;
3109 struct peer_group *group;
3110 struct peer *peer;
3111 struct peer *other;
3112
3113 ret = str2sockunion(argv[idx_peer]->arg, &su);
3114 if (ret < 0) {
3115 /* look up for neighbor by interface name config. */
3116 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3117 if (peer) {
3118 /* Request zebra to terminate IPv6 RAs on this
3119 * interface. */
3120 if (peer->ifp)
3121 bgp_zebra_terminate_radv(peer->bgp, peer);
3122 peer_delete(peer);
3123 return CMD_SUCCESS;
3124 }
f14e6fdb 3125
d62a17ae 3126 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3127 if (group)
3128 peer_group_delete(group);
3129 else {
3130 vty_out(vty, "%% Create the peer-group first\n");
3131 return CMD_WARNING_CONFIG_FAILED;
3132 }
3133 } else {
3134 peer = peer_lookup(bgp, &su);
3135 if (peer) {
3136 if (peer_dynamic_neighbor(peer)) {
3137 vty_out(vty,
3138 "%% Operation not allowed on a dynamic neighbor\n");
3139 return CMD_WARNING_CONFIG_FAILED;
3140 }
3141
3142 other = peer->doppelganger;
3143 peer_delete(peer);
3144 if (other && other->status != Deleted)
3145 peer_delete(other);
3146 }
1ff9a340 3147 }
718e3744 3148
d62a17ae 3149 return CMD_SUCCESS;
718e3744 3150}
3151
a80beece
DS
3152DEFUN (no_neighbor_interface_config,
3153 no_neighbor_interface_config_cmd,
31500417 3154 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3155 NO_STR
3156 NEIGHBOR_STR
3157 "Interface name\n"
31500417
DW
3158 "Configure BGP on interface\n"
3159 "Enable BGP with v6 link-local only\n"
3160 "Member of the peer-group\n"
16cedbb0 3161 "Peer-group name\n"
3a2d747c
QY
3162 "Specify a BGP neighbor\n"
3163 AS_STR
3164 "Internal BGP peer\n"
3165 "External BGP peer\n")
a80beece 3166{
d62a17ae 3167 VTY_DECLVAR_CONTEXT(bgp, bgp);
3168 int idx_word = 2;
3169 struct peer *peer;
3170
3171 /* look up for neighbor by interface name config. */
3172 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3173 if (peer) {
3174 /* Request zebra to terminate IPv6 RAs on this interface. */
3175 if (peer->ifp)
3176 bgp_zebra_terminate_radv(peer->bgp, peer);
3177 peer_delete(peer);
3178 } else {
3179 vty_out(vty, "%% Create the bgp interface first\n");
3180 return CMD_WARNING_CONFIG_FAILED;
3181 }
3182 return CMD_SUCCESS;
a80beece
DS
3183}
3184
718e3744 3185DEFUN (no_neighbor_peer_group,
3186 no_neighbor_peer_group_cmd,
3187 "no neighbor WORD peer-group",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Neighbor tag\n"
3191 "Configure peer-group\n")
3192{
d62a17ae 3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194 int idx_word = 2;
3195 struct peer_group *group;
718e3744 3196
d62a17ae 3197 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3198 if (group)
3199 peer_group_delete(group);
3200 else {
3201 vty_out(vty, "%% Create the peer-group first\n");
3202 return CMD_WARNING_CONFIG_FAILED;
3203 }
3204 return CMD_SUCCESS;
718e3744 3205}
3206
a80beece
DS
3207DEFUN (no_neighbor_interface_peer_group_remote_as,
3208 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3209 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3210 NO_STR
3211 NEIGHBOR_STR
a80beece 3212 "Interface name or neighbor tag\n"
718e3744 3213 "Specify a BGP neighbor\n"
3a2d747c
QY
3214 AS_STR
3215 "Internal BGP peer\n"
3216 "External BGP peer\n")
718e3744 3217{
d62a17ae 3218 VTY_DECLVAR_CONTEXT(bgp, bgp);
3219 int idx_word = 2;
3220 struct peer_group *group;
3221 struct peer *peer;
3222
3223 /* look up for neighbor by interface name config. */
3224 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3225 if (peer) {
3226 peer_as_change(peer, 0, AS_SPECIFIED);
3227 return CMD_SUCCESS;
3228 }
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_remote_as_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group or interface first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
718e3744 3238}
6b0655a2 3239
718e3744 3240DEFUN (neighbor_local_as,
3241 neighbor_local_as_cmd,
9ccf14f7 3242 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3243 NEIGHBOR_STR
3244 NEIGHBOR_ADDR_STR2
3245 "Specify a local-as number\n"
3246 "AS number used as local AS\n")
3247{
d62a17ae 3248 int idx_peer = 1;
3249 int idx_number = 3;
3250 struct peer *peer;
3251 int ret;
3252 as_t as;
718e3744 3253
d62a17ae 3254 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3255 if (!peer)
3256 return CMD_WARNING_CONFIG_FAILED;
718e3744 3257
d62a17ae 3258 as = strtoul(argv[idx_number]->arg, NULL, 10);
3259 ret = peer_local_as_set(peer, as, 0, 0);
3260 return bgp_vty_return(vty, ret);
718e3744 3261}
3262
3263DEFUN (neighbor_local_as_no_prepend,
3264 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3265 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3266 NEIGHBOR_STR
3267 NEIGHBOR_ADDR_STR2
3268 "Specify a local-as number\n"
3269 "AS number used as local AS\n"
3270 "Do not prepend local-as to updates from ebgp peers\n")
3271{
d62a17ae 3272 int idx_peer = 1;
3273 int idx_number = 3;
3274 struct peer *peer;
3275 int ret;
3276 as_t as;
718e3744 3277
d62a17ae 3278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
718e3744 3281
d62a17ae 3282 as = strtoul(argv[idx_number]->arg, NULL, 10);
3283 ret = peer_local_as_set(peer, as, 1, 0);
3284 return bgp_vty_return(vty, ret);
718e3744 3285}
3286
9d3f9705
AC
3287DEFUN (neighbor_local_as_no_prepend_replace_as,
3288 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3289 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3290 NEIGHBOR_STR
3291 NEIGHBOR_ADDR_STR2
3292 "Specify a local-as number\n"
3293 "AS number used as local AS\n"
3294 "Do not prepend local-as to updates from ebgp peers\n"
3295 "Do not prepend local-as to updates from ibgp peers\n")
3296{
d62a17ae 3297 int idx_peer = 1;
3298 int idx_number = 3;
3299 struct peer *peer;
3300 int ret;
3301 as_t as;
9d3f9705 3302
d62a17ae 3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304 if (!peer)
3305 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3306
d62a17ae 3307 as = strtoul(argv[idx_number]->arg, NULL, 10);
3308 ret = peer_local_as_set(peer, as, 1, 1);
3309 return bgp_vty_return(vty, ret);
9d3f9705
AC
3310}
3311
718e3744 3312DEFUN (no_neighbor_local_as,
3313 no_neighbor_local_as_cmd,
a636c635 3314 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3315 NO_STR
3316 NEIGHBOR_STR
3317 NEIGHBOR_ADDR_STR2
a636c635
DW
3318 "Specify a local-as number\n"
3319 "AS number used as local AS\n"
3320 "Do not prepend local-as to updates from ebgp peers\n"
3321 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3322{
d62a17ae 3323 int idx_peer = 2;
3324 struct peer *peer;
3325 int ret;
718e3744 3326
d62a17ae 3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
718e3744 3330
d62a17ae 3331 ret = peer_local_as_unset(peer);
3332 return bgp_vty_return(vty, ret);
718e3744 3333}
3334
718e3744 3335
3f9c7369
DS
3336DEFUN (neighbor_solo,
3337 neighbor_solo_cmd,
9ccf14f7 3338 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3339 NEIGHBOR_STR
3340 NEIGHBOR_ADDR_STR2
3341 "Solo peer - part of its own update group\n")
3342{
d62a17ae 3343 int idx_peer = 1;
3344 struct peer *peer;
3345 int ret;
3f9c7369 3346
d62a17ae 3347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3350
d62a17ae 3351 ret = update_group_adjust_soloness(peer, 1);
3352 return bgp_vty_return(vty, ret);
3f9c7369
DS
3353}
3354
3355DEFUN (no_neighbor_solo,
3356 no_neighbor_solo_cmd,
9ccf14f7 3357 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3358 NO_STR
3359 NEIGHBOR_STR
3360 NEIGHBOR_ADDR_STR2
3361 "Solo peer - part of its own update group\n")
3362{
d62a17ae 3363 int idx_peer = 2;
3364 struct peer *peer;
3365 int ret;
3f9c7369 3366
d62a17ae 3367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3368 if (!peer)
3369 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3370
d62a17ae 3371 ret = update_group_adjust_soloness(peer, 0);
3372 return bgp_vty_return(vty, ret);
3f9c7369
DS
3373}
3374
0df7c91f
PJ
3375DEFUN (neighbor_password,
3376 neighbor_password_cmd,
9ccf14f7 3377 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3378 NEIGHBOR_STR
3379 NEIGHBOR_ADDR_STR2
3380 "Set a password\n"
3381 "The password\n")
3382{
d62a17ae 3383 int idx_peer = 1;
3384 int idx_line = 3;
3385 struct peer *peer;
3386 int ret;
0df7c91f 3387
d62a17ae 3388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3389 if (!peer)
3390 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3391
d62a17ae 3392 ret = peer_password_set(peer, argv[idx_line]->arg);
3393 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3394}
3395
3396DEFUN (no_neighbor_password,
3397 no_neighbor_password_cmd,
a636c635 3398 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3399 NO_STR
3400 NEIGHBOR_STR
3401 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3402 "Set a password\n"
3403 "The password\n")
0df7c91f 3404{
d62a17ae 3405 int idx_peer = 2;
3406 struct peer *peer;
3407 int ret;
0df7c91f 3408
d62a17ae 3409 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3410 if (!peer)
3411 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3412
d62a17ae 3413 ret = peer_password_unset(peer);
3414 return bgp_vty_return(vty, ret);
0df7c91f 3415}
6b0655a2 3416
718e3744 3417DEFUN (neighbor_activate,
3418 neighbor_activate_cmd,
9ccf14f7 3419 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3420 NEIGHBOR_STR
3421 NEIGHBOR_ADDR_STR2
3422 "Enable the Address Family for this Neighbor\n")
3423{
d62a17ae 3424 int idx_peer = 1;
3425 int ret;
3426 struct peer *peer;
718e3744 3427
d62a17ae 3428 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3429 if (!peer)
3430 return CMD_WARNING_CONFIG_FAILED;
718e3744 3431
d62a17ae 3432 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3433 return bgp_vty_return(vty, ret);
718e3744 3434}
3435
d62a17ae 3436ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3437 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3439 "Enable the Address Family for this Neighbor\n")
596c17ba 3440
718e3744 3441DEFUN (no_neighbor_activate,
3442 no_neighbor_activate_cmd,
9ccf14f7 3443 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3444 NO_STR
3445 NEIGHBOR_STR
3446 NEIGHBOR_ADDR_STR2
3447 "Enable the Address Family for this Neighbor\n")
3448{
d62a17ae 3449 int idx_peer = 2;
3450 int ret;
3451 struct peer *peer;
718e3744 3452
d62a17ae 3453 /* Lookup peer. */
3454 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3455 if (!peer)
3456 return CMD_WARNING_CONFIG_FAILED;
718e3744 3457
d62a17ae 3458 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3459 return bgp_vty_return(vty, ret);
718e3744 3460}
6b0655a2 3461
d62a17ae 3462ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3463 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3465 "Enable the Address Family for this Neighbor\n")
596c17ba 3466
718e3744 3467DEFUN (neighbor_set_peer_group,
3468 neighbor_set_peer_group_cmd,
9ccf14f7 3469 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3470 NEIGHBOR_STR
a80beece 3471 NEIGHBOR_ADDR_STR2
718e3744 3472 "Member of the peer-group\n"
16cedbb0 3473 "Peer-group name\n")
718e3744 3474{
d62a17ae 3475 VTY_DECLVAR_CONTEXT(bgp, bgp);
3476 int idx_peer = 1;
3477 int idx_word = 3;
3478 int ret;
3479 as_t as;
3480 union sockunion su;
3481 struct peer *peer;
3482 struct peer_group *group;
3483
d62a17ae 3484 ret = str2sockunion(argv[idx_peer]->arg, &su);
3485 if (ret < 0) {
3486 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3487 if (!peer) {
3488 vty_out(vty, "%% Malformed address or name: %s\n",
3489 argv[idx_peer]->arg);
3490 return CMD_WARNING_CONFIG_FAILED;
3491 }
3492 } else {
3493 if (peer_address_self_check(bgp, &su)) {
3494 vty_out(vty,
3495 "%% Can not configure the local system as neighbor\n");
3496 return CMD_WARNING_CONFIG_FAILED;
3497 }
3498
3499 /* Disallow for dynamic neighbor. */
3500 peer = peer_lookup(bgp, &su);
3501 if (peer && peer_dynamic_neighbor(peer)) {
3502 vty_out(vty,
3503 "%% Operation not allowed on a dynamic neighbor\n");
3504 return CMD_WARNING_CONFIG_FAILED;
3505 }
3506 }
3507
3508 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3509 if (!group) {
3510 vty_out(vty, "%% Configure the peer-group first\n");
3511 return CMD_WARNING_CONFIG_FAILED;
3512 }
3513
3514 ret = peer_group_bind(bgp, &su, peer, group, &as);
3515
3516 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3517 vty_out(vty,
3518 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3519 as);
3520 return CMD_WARNING_CONFIG_FAILED;
3521 }
3522
3523 return bgp_vty_return(vty, ret);
3524}
3525
3526ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3527 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3528 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3529 "Member of the peer-group\n"
3530 "Peer-group name\n")
596c17ba 3531
718e3744 3532DEFUN (no_neighbor_set_peer_group,
3533 no_neighbor_set_peer_group_cmd,
9ccf14f7 3534 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3535 NO_STR
3536 NEIGHBOR_STR
a80beece 3537 NEIGHBOR_ADDR_STR2
718e3744 3538 "Member of the peer-group\n"
16cedbb0 3539 "Peer-group name\n")
718e3744 3540{
d62a17ae 3541 VTY_DECLVAR_CONTEXT(bgp, bgp);
3542 int idx_peer = 2;
3543 int idx_word = 4;
3544 int ret;
3545 struct peer *peer;
3546 struct peer_group *group;
3547
3548 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3549 if (!peer)
3550 return CMD_WARNING_CONFIG_FAILED;
3551
3552 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3553 if (!group) {
3554 vty_out(vty, "%% Configure the peer-group first\n");
3555 return CMD_WARNING_CONFIG_FAILED;
3556 }
718e3744 3557
827ed707 3558 ret = peer_delete(peer);
718e3744 3559
d62a17ae 3560 return bgp_vty_return(vty, ret);
718e3744 3561}
6b0655a2 3562
d62a17ae 3563ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3564 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3565 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3566 "Member of the peer-group\n"
3567 "Peer-group name\n")
596c17ba 3568
d62a17ae 3569static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3570 uint32_t flag, int set)
718e3744 3571{
d62a17ae 3572 int ret;
3573 struct peer *peer;
718e3744 3574
d62a17ae 3575 peer = peer_and_group_lookup_vty(vty, ip_str);
3576 if (!peer)
3577 return CMD_WARNING_CONFIG_FAILED;
718e3744 3578
7ebe625c
QY
3579 /*
3580 * If 'neighbor <interface>', then this is for directly connected peers,
3581 * we should not accept disable-connected-check.
3582 */
3583 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3584 vty_out(vty,
3585 "%s is directly connected peer, cannot accept disable-"
3586 "connected-check\n",
3587 ip_str);
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
d62a17ae 3591 if (!set && flag == PEER_FLAG_SHUTDOWN)
3592 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3593
d62a17ae 3594 if (set)
3595 ret = peer_flag_set(peer, flag);
3596 else
3597 ret = peer_flag_unset(peer, flag);
718e3744 3598
d62a17ae 3599 return bgp_vty_return(vty, ret);
718e3744 3600}
3601
47cbc09b 3602static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3603{
d62a17ae 3604 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3605}
3606
d62a17ae 3607static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3608 uint32_t flag)
718e3744 3609{
d62a17ae 3610 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3611}
3612
3613/* neighbor passive. */
3614DEFUN (neighbor_passive,
3615 neighbor_passive_cmd,
9ccf14f7 3616 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3617 NEIGHBOR_STR
3618 NEIGHBOR_ADDR_STR2
3619 "Don't send open messages to this neighbor\n")
3620{
d62a17ae 3621 int idx_peer = 1;
3622 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3623}
3624
3625DEFUN (no_neighbor_passive,
3626 no_neighbor_passive_cmd,
9ccf14f7 3627 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3628 NO_STR
3629 NEIGHBOR_STR
3630 NEIGHBOR_ADDR_STR2
3631 "Don't send open messages to this neighbor\n")
3632{
d62a17ae 3633 int idx_peer = 2;
3634 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3635}
6b0655a2 3636
718e3744 3637/* neighbor shutdown. */
73d70fa6
DL
3638DEFUN (neighbor_shutdown_msg,
3639 neighbor_shutdown_msg_cmd,
3640 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3641 NEIGHBOR_STR
3642 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3643 "Administratively shut down this neighbor\n"
3644 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3645 "Shutdown message\n")
718e3744 3646{
d62a17ae 3647 int idx_peer = 1;
73d70fa6 3648
d62a17ae 3649 if (argc >= 5) {
3650 struct peer *peer =
3651 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3652 char *message;
73d70fa6 3653
d62a17ae 3654 if (!peer)
3655 return CMD_WARNING_CONFIG_FAILED;
3656 message = argv_concat(argv, argc, 4);
3657 peer_tx_shutdown_message_set(peer, message);
3658 XFREE(MTYPE_TMP, message);
3659 }
73d70fa6 3660
d62a17ae 3661 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3662}
3663
d62a17ae 3664ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3665 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3666 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3667 "Administratively shut down this neighbor\n")
73d70fa6
DL
3668
3669DEFUN (no_neighbor_shutdown_msg,
3670 no_neighbor_shutdown_msg_cmd,
3671 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3672 NO_STR
3673 NEIGHBOR_STR
3674 NEIGHBOR_ADDR_STR2
3675 "Administratively shut down this neighbor\n"
3676 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3677 "Shutdown message\n")
718e3744 3678{
d62a17ae 3679 int idx_peer = 2;
73d70fa6 3680
d62a17ae 3681 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3682 PEER_FLAG_SHUTDOWN);
718e3744 3683}
6b0655a2 3684
d62a17ae 3685ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3686 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3687 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3688 "Administratively shut down this neighbor\n")
73d70fa6 3689
718e3744 3690/* neighbor capability dynamic. */
3691DEFUN (neighbor_capability_dynamic,
3692 neighbor_capability_dynamic_cmd,
9ccf14f7 3693 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3694 NEIGHBOR_STR
3695 NEIGHBOR_ADDR_STR2
3696 "Advertise capability to the peer\n"
3697 "Advertise dynamic capability to this neighbor\n")
3698{
d62a17ae 3699 int idx_peer = 1;
3700 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3701 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3702}
3703
3704DEFUN (no_neighbor_capability_dynamic,
3705 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3706 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3707 NO_STR
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Advertise capability to the peer\n"
3711 "Advertise dynamic capability to this neighbor\n")
3712{
d62a17ae 3713 int idx_peer = 2;
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3716}
6b0655a2 3717
718e3744 3718/* neighbor dont-capability-negotiate */
3719DEFUN (neighbor_dont_capability_negotiate,
3720 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3721 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3722 NEIGHBOR_STR
3723 NEIGHBOR_ADDR_STR2
3724 "Do not perform capability negotiation\n")
3725{
d62a17ae 3726 int idx_peer = 1;
3727 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3728 PEER_FLAG_DONT_CAPABILITY);
718e3744 3729}
3730
3731DEFUN (no_neighbor_dont_capability_negotiate,
3732 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3733 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3734 NO_STR
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Do not perform capability negotiation\n")
3738{
d62a17ae 3739 int idx_peer = 2;
3740 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3741 PEER_FLAG_DONT_CAPABILITY);
718e3744 3742}
6b0655a2 3743
8a92a8a0
DS
3744/* neighbor capability extended next hop encoding */
3745DEFUN (neighbor_capability_enhe,
3746 neighbor_capability_enhe_cmd,
9ccf14f7 3747 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Advertise capability to the peer\n"
3751 "Advertise extended next-hop capability to the peer\n")
3752{
d62a17ae 3753 int idx_peer = 1;
3754 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3755 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3756}
3757
3758DEFUN (no_neighbor_capability_enhe,
3759 no_neighbor_capability_enhe_cmd,
9ccf14f7 3760 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3761 NO_STR
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Advertise capability to the peer\n"
3765 "Advertise extended next-hop capability to the peer\n")
3766{
d62a17ae 3767 int idx_peer = 2;
3768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3769 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3770}
3771
d62a17ae 3772static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3773 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3774 int set)
718e3744 3775{
d62a17ae 3776 int ret;
3777 struct peer *peer;
718e3744 3778
d62a17ae 3779 peer = peer_and_group_lookup_vty(vty, peer_str);
3780 if (!peer)
3781 return CMD_WARNING_CONFIG_FAILED;
718e3744 3782
d62a17ae 3783 if (set)
3784 ret = peer_af_flag_set(peer, afi, safi, flag);
3785 else
3786 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3787
d62a17ae 3788 return bgp_vty_return(vty, ret);
718e3744 3789}
3790
d62a17ae 3791static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3792 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3793{
d62a17ae 3794 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3795}
3796
d62a17ae 3797static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3798 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3799{
d62a17ae 3800 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3801}
6b0655a2 3802
718e3744 3803/* neighbor capability orf prefix-list. */
3804DEFUN (neighbor_capability_orf_prefix,
3805 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3806 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Advertise capability to the peer\n"
3810 "Advertise ORF capability to the peer\n"
3811 "Advertise prefixlist ORF capability to this neighbor\n"
3812 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3813 "Capability to RECEIVE the ORF from this neighbor\n"
3814 "Capability to SEND the ORF to this neighbor\n")
3815{
d62a17ae 3816 int idx_peer = 1;
3817 int idx_send_recv = 5;
d7c0a89a 3818 uint16_t flag = 0;
d62a17ae 3819
3820 if (strmatch(argv[idx_send_recv]->text, "send"))
3821 flag = PEER_FLAG_ORF_PREFIX_SM;
3822 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3823 flag = PEER_FLAG_ORF_PREFIX_RM;
3824 else if (strmatch(argv[idx_send_recv]->text, "both"))
3825 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3826 else {
3827 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3828 return CMD_WARNING_CONFIG_FAILED;
3829 }
3830
3831 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3832 bgp_node_safi(vty), flag);
3833}
3834
3835ALIAS_HIDDEN(
3836 neighbor_capability_orf_prefix,
3837 neighbor_capability_orf_prefix_hidden_cmd,
3838 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3840 "Advertise capability to the peer\n"
3841 "Advertise ORF capability to the peer\n"
3842 "Advertise prefixlist ORF capability to this neighbor\n"
3843 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3844 "Capability to RECEIVE the ORF from this neighbor\n"
3845 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3846
718e3744 3847DEFUN (no_neighbor_capability_orf_prefix,
3848 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3849 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3850 NO_STR
3851 NEIGHBOR_STR
3852 NEIGHBOR_ADDR_STR2
3853 "Advertise capability to the peer\n"
3854 "Advertise ORF capability to the peer\n"
3855 "Advertise prefixlist ORF capability to this neighbor\n"
3856 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3857 "Capability to RECEIVE the ORF from this neighbor\n"
3858 "Capability to SEND the ORF to this neighbor\n")
3859{
d62a17ae 3860 int idx_peer = 2;
3861 int idx_send_recv = 6;
d7c0a89a 3862 uint16_t flag = 0;
d62a17ae 3863
3864 if (strmatch(argv[idx_send_recv]->text, "send"))
3865 flag = PEER_FLAG_ORF_PREFIX_SM;
3866 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3867 flag = PEER_FLAG_ORF_PREFIX_RM;
3868 else if (strmatch(argv[idx_send_recv]->text, "both"))
3869 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3870 else {
3871 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3872 return CMD_WARNING_CONFIG_FAILED;
3873 }
3874
3875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3876 bgp_node_afi(vty), bgp_node_safi(vty),
3877 flag);
3878}
3879
3880ALIAS_HIDDEN(
3881 no_neighbor_capability_orf_prefix,
3882 no_neighbor_capability_orf_prefix_hidden_cmd,
3883 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3884 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3885 "Advertise capability to the peer\n"
3886 "Advertise ORF capability to the peer\n"
3887 "Advertise prefixlist ORF capability to this neighbor\n"
3888 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3889 "Capability to RECEIVE the ORF from this neighbor\n"
3890 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3891
718e3744 3892/* neighbor next-hop-self. */
3893DEFUN (neighbor_nexthop_self,
3894 neighbor_nexthop_self_cmd,
9ccf14f7 3895 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
a538debe 3898 "Disable the next hop calculation for this neighbor\n")
718e3744 3899{
d62a17ae 3900 int idx_peer = 1;
3901 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3902 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3903}
9e7a53c1 3904
d62a17ae 3905ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3906 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3908 "Disable the next hop calculation for this neighbor\n")
596c17ba 3909
a538debe
DS
3910/* neighbor next-hop-self. */
3911DEFUN (neighbor_nexthop_self_force,
3912 neighbor_nexthop_self_force_cmd,
9ccf14f7 3913 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Disable the next hop calculation for this neighbor\n"
3917 "Set the next hop to self for reflected routes\n")
3918{
d62a17ae 3919 int idx_peer = 1;
3920 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3921 bgp_node_safi(vty),
3922 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3923}
3924
d62a17ae 3925ALIAS_HIDDEN(neighbor_nexthop_self_force,
3926 neighbor_nexthop_self_force_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Disable the next hop calculation for this neighbor\n"
3930 "Set the next hop to self for reflected routes\n")
596c17ba 3931
718e3744 3932DEFUN (no_neighbor_nexthop_self,
3933 no_neighbor_nexthop_self_cmd,
9ccf14f7 3934 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3935 NO_STR
3936 NEIGHBOR_STR
3937 NEIGHBOR_ADDR_STR2
a538debe 3938 "Disable the next hop calculation for this neighbor\n")
718e3744 3939{
d62a17ae 3940 int idx_peer = 2;
3941 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3942 bgp_node_afi(vty), bgp_node_safi(vty),
3943 PEER_FLAG_NEXTHOP_SELF);
718e3744 3944}
6b0655a2 3945
d62a17ae 3946ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3947 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n")
596c17ba 3950
88b8ed8d 3951DEFUN (no_neighbor_nexthop_self_force,
a538debe 3952 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3953 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3954 NO_STR
3955 NEIGHBOR_STR
3956 NEIGHBOR_ADDR_STR2
3957 "Disable the next hop calculation for this neighbor\n"
3958 "Set the next hop to self for reflected routes\n")
88b8ed8d 3959{
d62a17ae 3960 int idx_peer = 2;
3961 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3962 bgp_node_afi(vty), bgp_node_safi(vty),
3963 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3964}
a538debe 3965
d62a17ae 3966ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3967 no_neighbor_nexthop_self_force_hidden_cmd,
3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3970 "Disable the next hop calculation for this neighbor\n"
3971 "Set the next hop to self for reflected routes\n")
596c17ba 3972
c7122e14
DS
3973/* neighbor as-override */
3974DEFUN (neighbor_as_override,
3975 neighbor_as_override_cmd,
9ccf14f7 3976 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3977 NEIGHBOR_STR
3978 NEIGHBOR_ADDR_STR2
3979 "Override ASNs in outbound updates if aspath equals remote-as\n")
3980{
d62a17ae 3981 int idx_peer = 1;
3982 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3983 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3984}
3985
d62a17ae 3986ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3987 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3989 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3990
c7122e14
DS
3991DEFUN (no_neighbor_as_override,
3992 no_neighbor_as_override_cmd,
9ccf14f7 3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3994 NO_STR
3995 NEIGHBOR_STR
3996 NEIGHBOR_ADDR_STR2
3997 "Override ASNs in outbound updates if aspath equals remote-as\n")
3998{
d62a17ae 3999 int idx_peer = 2;
4000 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4001 bgp_node_afi(vty), bgp_node_safi(vty),
4002 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4003}
4004
d62a17ae 4005ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4006 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4007 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4008 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4009
718e3744 4010/* neighbor remove-private-AS. */
4011DEFUN (neighbor_remove_private_as,
4012 neighbor_remove_private_as_cmd,
9ccf14f7 4013 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4014 NEIGHBOR_STR
4015 NEIGHBOR_ADDR_STR2
5000f21c 4016 "Remove private ASNs in outbound updates\n")
718e3744 4017{
d62a17ae 4018 int idx_peer = 1;
4019 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4020 bgp_node_safi(vty),
4021 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4022}
4023
d62a17ae 4024ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4025 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4026 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n")
596c17ba 4028
5000f21c
DS
4029DEFUN (neighbor_remove_private_as_all,
4030 neighbor_remove_private_as_all_cmd,
9ccf14f7 4031 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4032 NEIGHBOR_STR
4033 NEIGHBOR_ADDR_STR2
4034 "Remove private ASNs in outbound updates\n"
efd7904e 4035 "Apply to all AS numbers\n")
5000f21c 4036{
d62a17ae 4037 int idx_peer = 1;
4038 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4039 bgp_node_safi(vty),
4040 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4041}
4042
d62a17ae 4043ALIAS_HIDDEN(neighbor_remove_private_as_all,
4044 neighbor_remove_private_as_all_hidden_cmd,
4045 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
4048 "Apply to all AS numbers")
596c17ba 4049
5000f21c
DS
4050DEFUN (neighbor_remove_private_as_replace_as,
4051 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4052 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4053 NEIGHBOR_STR
4054 NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n"
4056 "Replace private ASNs with our ASN in outbound updates\n")
4057{
d62a17ae 4058 int idx_peer = 1;
4059 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4060 bgp_node_safi(vty),
4061 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4062}
4063
d62a17ae 4064ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4065 neighbor_remove_private_as_replace_as_hidden_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4068 "Remove private ASNs in outbound updates\n"
4069 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4070
5000f21c
DS
4071DEFUN (neighbor_remove_private_as_all_replace_as,
4072 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4073 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4074 NEIGHBOR_STR
4075 NEIGHBOR_ADDR_STR2
4076 "Remove private ASNs in outbound updates\n"
16cedbb0 4077 "Apply to all AS numbers\n"
5000f21c
DS
4078 "Replace private ASNs with our ASN in outbound updates\n")
4079{
d62a17ae 4080 int idx_peer = 1;
4081 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4082 bgp_node_safi(vty),
4083 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4084}
4085
d62a17ae 4086ALIAS_HIDDEN(
4087 neighbor_remove_private_as_all_replace_as,
4088 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4089 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4090 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4091 "Remove private ASNs in outbound updates\n"
4092 "Apply to all AS numbers\n"
4093 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4094
718e3744 4095DEFUN (no_neighbor_remove_private_as,
4096 no_neighbor_remove_private_as_cmd,
9ccf14f7 4097 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4098 NO_STR
4099 NEIGHBOR_STR
4100 NEIGHBOR_ADDR_STR2
5000f21c 4101 "Remove private ASNs in outbound updates\n")
718e3744 4102{
d62a17ae 4103 int idx_peer = 2;
4104 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4105 bgp_node_afi(vty), bgp_node_safi(vty),
4106 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4107}
6b0655a2 4108
d62a17ae 4109ALIAS_HIDDEN(no_neighbor_remove_private_as,
4110 no_neighbor_remove_private_as_hidden_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4113 "Remove private ASNs in outbound updates\n")
596c17ba 4114
88b8ed8d 4115DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4116 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4117 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4118 NO_STR
4119 NEIGHBOR_STR
4120 NEIGHBOR_ADDR_STR2
4121 "Remove private ASNs in outbound updates\n"
16cedbb0 4122 "Apply to all AS numbers\n")
88b8ed8d 4123{
d62a17ae 4124 int idx_peer = 2;
4125 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4126 bgp_node_afi(vty), bgp_node_safi(vty),
4127 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4128}
5000f21c 4129
d62a17ae 4130ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4131 no_neighbor_remove_private_as_all_hidden_cmd,
4132 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4133 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4134 "Remove private ASNs in outbound updates\n"
4135 "Apply to all AS numbers\n")
596c17ba 4136
88b8ed8d 4137DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4138 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4140 NO_STR
4141 NEIGHBOR_STR
4142 NEIGHBOR_ADDR_STR2
4143 "Remove private ASNs in outbound updates\n"
4144 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4145{
d62a17ae 4146 int idx_peer = 2;
4147 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4148 bgp_node_afi(vty), bgp_node_safi(vty),
4149 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4150}
5000f21c 4151
d62a17ae 4152ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4153 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4156 "Remove private ASNs in outbound updates\n"
4157 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4158
88b8ed8d 4159DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4160 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4161 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4162 NO_STR
4163 NEIGHBOR_STR
4164 NEIGHBOR_ADDR_STR2
4165 "Remove private ASNs in outbound updates\n"
16cedbb0 4166 "Apply to all AS numbers\n"
5000f21c 4167 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4168{
d62a17ae 4169 int idx_peer = 2;
4170 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4171 bgp_node_afi(vty), bgp_node_safi(vty),
4172 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4173}
5000f21c 4174
d62a17ae 4175ALIAS_HIDDEN(
4176 no_neighbor_remove_private_as_all_replace_as,
4177 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4179 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4180 "Remove private ASNs in outbound updates\n"
4181 "Apply to all AS numbers\n"
4182 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4183
5000f21c 4184
718e3744 4185/* neighbor send-community. */
4186DEFUN (neighbor_send_community,
4187 neighbor_send_community_cmd,
9ccf14f7 4188 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4189 NEIGHBOR_STR
4190 NEIGHBOR_ADDR_STR2
4191 "Send Community attribute to this neighbor\n")
4192{
d62a17ae 4193 int idx_peer = 1;
27c05d4d 4194
d62a17ae 4195 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4196 bgp_node_safi(vty),
4197 PEER_FLAG_SEND_COMMUNITY);
718e3744 4198}
4199
d62a17ae 4200ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4201 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Send Community attribute to this neighbor\n")
596c17ba 4204
718e3744 4205DEFUN (no_neighbor_send_community,
4206 no_neighbor_send_community_cmd,
9ccf14f7 4207 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4208 NO_STR
4209 NEIGHBOR_STR
4210 NEIGHBOR_ADDR_STR2
4211 "Send Community attribute to this neighbor\n")
4212{
d62a17ae 4213 int idx_peer = 2;
27c05d4d 4214
d62a17ae 4215 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4216 bgp_node_afi(vty), bgp_node_safi(vty),
4217 PEER_FLAG_SEND_COMMUNITY);
718e3744 4218}
6b0655a2 4219
d62a17ae 4220ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4221 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4223 "Send Community attribute to this neighbor\n")
596c17ba 4224
718e3744 4225/* neighbor send-community extended. */
4226DEFUN (neighbor_send_community_type,
4227 neighbor_send_community_type_cmd,
57d187bc 4228 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4229 NEIGHBOR_STR
4230 NEIGHBOR_ADDR_STR2
4231 "Send Community attribute to this neighbor\n"
4232 "Send Standard and Extended Community attributes\n"
57d187bc 4233 "Send Standard, Large and Extended Community attributes\n"
718e3744 4234 "Send Extended Community attributes\n"
57d187bc
JS
4235 "Send Standard Community attributes\n"
4236 "Send Large Community attributes\n")
718e3744 4237{
27c05d4d 4238 int idx_peer = 1;
d7c0a89a 4239 uint32_t flag = 0;
27c05d4d 4240 const char *type = argv[argc - 1]->text;
d62a17ae 4241
27c05d4d 4242 if (strmatch(type, "standard")) {
d62a17ae 4243 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4244 } else if (strmatch(type, "extended")) {
d62a17ae 4245 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4246 } else if (strmatch(type, "large")) {
d62a17ae 4247 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4248 } else if (strmatch(type, "both")) {
d62a17ae 4249 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4250 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4251 } else { /* if (strmatch(type, "all")) */
d62a17ae 4252 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4253 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4254 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4255 }
4256
27c05d4d 4257 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4258 bgp_node_safi(vty), flag);
4259}
4260
4261ALIAS_HIDDEN(
4262 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4263 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4264 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4265 "Send Community attribute to this neighbor\n"
4266 "Send Standard and Extended Community attributes\n"
4267 "Send Standard, Large and Extended Community attributes\n"
4268 "Send Extended Community attributes\n"
4269 "Send Standard Community attributes\n"
4270 "Send Large Community attributes\n")
596c17ba 4271
718e3744 4272DEFUN (no_neighbor_send_community_type,
4273 no_neighbor_send_community_type_cmd,
57d187bc 4274 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4275 NO_STR
4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
4278 "Send Community attribute to this neighbor\n"
4279 "Send Standard and Extended Community attributes\n"
57d187bc 4280 "Send Standard, Large and Extended Community attributes\n"
718e3744 4281 "Send Extended Community attributes\n"
57d187bc
JS
4282 "Send Standard Community attributes\n"
4283 "Send Large Community attributes\n")
718e3744 4284{
d62a17ae 4285 int idx_peer = 2;
27c05d4d 4286 uint32_t flag = 0;
d62a17ae 4287 const char *type = argv[argc - 1]->text;
4288
27c05d4d
PM
4289 if (strmatch(type, "standard")) {
4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4291 } else if (strmatch(type, "extended")) {
4292 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4293 } else if (strmatch(type, "large")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4295 } else if (strmatch(type, "both")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4298 } else { /* if (strmatch(type, "all")) */
4299 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4300 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4302 }
4303
4304 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4305 bgp_node_afi(vty), bgp_node_safi(vty),
4306 flag);
d62a17ae 4307}
4308
4309ALIAS_HIDDEN(
4310 no_neighbor_send_community_type,
4311 no_neighbor_send_community_type_hidden_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Send Community attribute to this neighbor\n"
4315 "Send Standard and Extended Community attributes\n"
4316 "Send Standard, Large and Extended Community attributes\n"
4317 "Send Extended Community attributes\n"
4318 "Send Standard Community attributes\n"
4319 "Send Large Community attributes\n")
596c17ba 4320
718e3744 4321/* neighbor soft-reconfig. */
4322DEFUN (neighbor_soft_reconfiguration,
4323 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4324 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4325 NEIGHBOR_STR
4326 NEIGHBOR_ADDR_STR2
4327 "Per neighbor soft reconfiguration\n"
4328 "Allow inbound soft reconfiguration for this neighbor\n")
4329{
d62a17ae 4330 int idx_peer = 1;
4331 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4332 bgp_node_safi(vty),
4333 PEER_FLAG_SOFT_RECONFIG);
718e3744 4334}
4335
d62a17ae 4336ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4337 neighbor_soft_reconfiguration_hidden_cmd,
4338 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4340 "Per neighbor soft reconfiguration\n"
4341 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4342
718e3744 4343DEFUN (no_neighbor_soft_reconfiguration,
4344 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4346 NO_STR
4347 NEIGHBOR_STR
4348 NEIGHBOR_ADDR_STR2
4349 "Per neighbor soft reconfiguration\n"
4350 "Allow inbound soft reconfiguration for this neighbor\n")
4351{
d62a17ae 4352 int idx_peer = 2;
4353 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4354 bgp_node_afi(vty), bgp_node_safi(vty),
4355 PEER_FLAG_SOFT_RECONFIG);
718e3744 4356}
6b0655a2 4357
d62a17ae 4358ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4359 no_neighbor_soft_reconfiguration_hidden_cmd,
4360 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4362 "Per neighbor soft reconfiguration\n"
4363 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4364
718e3744 4365DEFUN (neighbor_route_reflector_client,
4366 neighbor_route_reflector_client_cmd,
9ccf14f7 4367 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4368 NEIGHBOR_STR
4369 NEIGHBOR_ADDR_STR2
4370 "Configure a neighbor as Route Reflector client\n")
4371{
d62a17ae 4372 int idx_peer = 1;
4373 struct peer *peer;
718e3744 4374
4375
d62a17ae 4376 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4377 if (!peer)
4378 return CMD_WARNING_CONFIG_FAILED;
718e3744 4379
d62a17ae 4380 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4381 bgp_node_safi(vty),
4382 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4383}
4384
d62a17ae 4385ALIAS_HIDDEN(neighbor_route_reflector_client,
4386 neighbor_route_reflector_client_hidden_cmd,
4387 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4389 "Configure a neighbor as Route Reflector client\n")
596c17ba 4390
718e3744 4391DEFUN (no_neighbor_route_reflector_client,
4392 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4393 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4394 NO_STR
4395 NEIGHBOR_STR
4396 NEIGHBOR_ADDR_STR2
4397 "Configure a neighbor as Route Reflector client\n")
4398{
d62a17ae 4399 int idx_peer = 2;
4400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4401 bgp_node_afi(vty), bgp_node_safi(vty),
4402 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4403}
6b0655a2 4404
d62a17ae 4405ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4406 no_neighbor_route_reflector_client_hidden_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4409 "Configure a neighbor as Route Reflector client\n")
596c17ba 4410
718e3744 4411/* neighbor route-server-client. */
4412DEFUN (neighbor_route_server_client,
4413 neighbor_route_server_client_cmd,
9ccf14f7 4414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4415 NEIGHBOR_STR
4416 NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Server client\n")
4418{
d62a17ae 4419 int idx_peer = 1;
4420 struct peer *peer;
2a3d5731 4421
d62a17ae 4422 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4423 if (!peer)
4424 return CMD_WARNING_CONFIG_FAILED;
4425 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4426 bgp_node_safi(vty),
4427 PEER_FLAG_RSERVER_CLIENT);
718e3744 4428}
4429
d62a17ae 4430ALIAS_HIDDEN(neighbor_route_server_client,
4431 neighbor_route_server_client_hidden_cmd,
4432 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4434 "Configure a neighbor as Route Server client\n")
596c17ba 4435
718e3744 4436DEFUN (no_neighbor_route_server_client,
4437 no_neighbor_route_server_client_cmd,
9ccf14f7 4438 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4439 NO_STR
4440 NEIGHBOR_STR
4441 NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Server client\n")
fee0f4c6 4443{
d62a17ae 4444 int idx_peer = 2;
4445 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4446 bgp_node_afi(vty), bgp_node_safi(vty),
4447 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4448}
6b0655a2 4449
d62a17ae 4450ALIAS_HIDDEN(no_neighbor_route_server_client,
4451 no_neighbor_route_server_client_hidden_cmd,
4452 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4453 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4454 "Configure a neighbor as Route Server client\n")
596c17ba 4455
fee0f4c6 4456DEFUN (neighbor_nexthop_local_unchanged,
4457 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4458 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "Configure treatment of outgoing link-local nexthop attribute\n"
4462 "Leave link-local nexthop unchanged for this peer\n")
4463{
d62a17ae 4464 int idx_peer = 1;
4465 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4466 bgp_node_safi(vty),
4467 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4468}
6b0655a2 4469
fee0f4c6 4470DEFUN (no_neighbor_nexthop_local_unchanged,
4471 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4472 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4473 NO_STR
4474 NEIGHBOR_STR
4475 NEIGHBOR_ADDR_STR2
4476 "Configure treatment of outgoing link-local-nexthop attribute\n"
4477 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4478{
d62a17ae 4479 int idx_peer = 2;
4480 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4481 bgp_node_afi(vty), bgp_node_safi(vty),
4482 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4483}
6b0655a2 4484
718e3744 4485DEFUN (neighbor_attr_unchanged,
4486 neighbor_attr_unchanged_cmd,
a8206004 4487 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4488 NEIGHBOR_STR
4489 NEIGHBOR_ADDR_STR2
4490 "BGP attribute is propagated unchanged to this neighbor\n"
4491 "As-path attribute\n"
4492 "Nexthop attribute\n"
a8206004 4493 "Med attribute\n")
718e3744 4494{
d62a17ae 4495 int idx = 0;
8eeb0335
DW
4496 char *peer_str = argv[1]->arg;
4497 struct peer *peer;
d7c0a89a 4498 uint16_t flags = 0;
8eeb0335
DW
4499 afi_t afi = bgp_node_afi(vty);
4500 safi_t safi = bgp_node_safi(vty);
4501
4502 peer = peer_and_group_lookup_vty(vty, peer_str);
4503 if (!peer)
4504 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4505
4506 if (argv_find(argv, argc, "as-path", &idx))
4507 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4508 idx = 0;
4509 if (argv_find(argv, argc, "next-hop", &idx))
4510 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4511 idx = 0;
4512 if (argv_find(argv, argc, "med", &idx))
4513 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4514
8eeb0335
DW
4515 /* no flags means all of them! */
4516 if (!flags) {
d62a17ae 4517 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4518 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4519 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4520 } else {
a4d82a8a
PZ
4521 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4522 && peer_af_flag_check(peer, afi, safi,
4523 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4524 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4525 PEER_FLAG_AS_PATH_UNCHANGED);
4526 }
4527
a4d82a8a
PZ
4528 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4529 && peer_af_flag_check(peer, afi, safi,
4530 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4531 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4532 PEER_FLAG_NEXTHOP_UNCHANGED);
4533 }
4534
a4d82a8a
PZ
4535 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4536 && peer_af_flag_check(peer, afi, safi,
4537 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4538 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4539 PEER_FLAG_MED_UNCHANGED);
4540 }
d62a17ae 4541 }
4542
8eeb0335 4543 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4544}
4545
4546ALIAS_HIDDEN(
4547 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4548 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4549 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4550 "BGP attribute is propagated unchanged to this neighbor\n"
4551 "As-path attribute\n"
4552 "Nexthop attribute\n"
4553 "Med attribute\n")
596c17ba 4554
718e3744 4555DEFUN (no_neighbor_attr_unchanged,
4556 no_neighbor_attr_unchanged_cmd,
a8206004 4557 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4558 NO_STR
718e3744 4559 NEIGHBOR_STR
4560 NEIGHBOR_ADDR_STR2
31500417
DW
4561 "BGP attribute is propagated unchanged to this neighbor\n"
4562 "As-path attribute\n"
40e718b5 4563 "Nexthop attribute\n"
a8206004 4564 "Med attribute\n")
718e3744 4565{
d62a17ae 4566 int idx = 0;
4567 char *peer = argv[2]->arg;
d7c0a89a 4568 uint16_t flags = 0;
d62a17ae 4569
4570 if (argv_find(argv, argc, "as-path", &idx))
4571 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4572 idx = 0;
4573 if (argv_find(argv, argc, "next-hop", &idx))
4574 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4575 idx = 0;
4576 if (argv_find(argv, argc, "med", &idx))
4577 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4578
4579 if (!flags) // no flags means all of them!
4580 {
4581 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4582 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4583 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4584 }
4585
4586 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4587 bgp_node_safi(vty), flags);
4588}
4589
4590ALIAS_HIDDEN(
4591 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4592 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4593 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4594 "BGP attribute is propagated unchanged to this neighbor\n"
4595 "As-path attribute\n"
4596 "Nexthop attribute\n"
4597 "Med attribute\n")
718e3744 4598
718e3744 4599/* EBGP multihop configuration. */
d62a17ae 4600static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4601 const char *ttl_str)
718e3744 4602{
d62a17ae 4603 struct peer *peer;
4604 unsigned int ttl;
718e3744 4605
d62a17ae 4606 peer = peer_and_group_lookup_vty(vty, ip_str);
4607 if (!peer)
4608 return CMD_WARNING_CONFIG_FAILED;
718e3744 4609
d62a17ae 4610 if (peer->conf_if)
4611 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4612
d62a17ae 4613 if (!ttl_str)
4614 ttl = MAXTTL;
4615 else
4616 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4617
d62a17ae 4618 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4619}
4620
d62a17ae 4621static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4622{
d62a17ae 4623 struct peer *peer;
718e3744 4624
d62a17ae 4625 peer = peer_and_group_lookup_vty(vty, ip_str);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
718e3744 4628
d62a17ae 4629 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4630}
4631
4632/* neighbor ebgp-multihop. */
4633DEFUN (neighbor_ebgp_multihop,
4634 neighbor_ebgp_multihop_cmd,
9ccf14f7 4635 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4636 NEIGHBOR_STR
4637 NEIGHBOR_ADDR_STR2
4638 "Allow EBGP neighbors not on directly connected networks\n")
4639{
d62a17ae 4640 int idx_peer = 1;
4641 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4642}
4643
4644DEFUN (neighbor_ebgp_multihop_ttl,
4645 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4646 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4647 NEIGHBOR_STR
4648 NEIGHBOR_ADDR_STR2
4649 "Allow EBGP neighbors not on directly connected networks\n"
4650 "maximum hop count\n")
4651{
d62a17ae 4652 int idx_peer = 1;
4653 int idx_number = 3;
4654 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4655 argv[idx_number]->arg);
718e3744 4656}
4657
4658DEFUN (no_neighbor_ebgp_multihop,
4659 no_neighbor_ebgp_multihop_cmd,
a636c635 4660 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4661 NO_STR
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
a636c635
DW
4664 "Allow EBGP neighbors not on directly connected networks\n"
4665 "maximum hop count\n")
718e3744 4666{
d62a17ae 4667 int idx_peer = 2;
4668 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4669}
4670
6b0655a2 4671
6ffd2079 4672/* disable-connected-check */
4673DEFUN (neighbor_disable_connected_check,
4674 neighbor_disable_connected_check_cmd,
7ebe625c 4675 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4676 NEIGHBOR_STR
7ebe625c 4677 NEIGHBOR_ADDR_STR2
a636c635
DW
4678 "one-hop away EBGP peer using loopback address\n"
4679 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4680{
d62a17ae 4681 int idx_peer = 1;
4682 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4683 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4684}
4685
4686DEFUN (no_neighbor_disable_connected_check,
4687 no_neighbor_disable_connected_check_cmd,
7ebe625c 4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4689 NO_STR
4690 NEIGHBOR_STR
7ebe625c 4691 NEIGHBOR_ADDR_STR2
a636c635
DW
4692 "one-hop away EBGP peer using loopback address\n"
4693 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4694{
d62a17ae 4695 int idx_peer = 2;
4696 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4697 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4698}
4699
47cbc09b
PM
4700
4701/* enforce-first-as */
4702DEFUN (neighbor_enforce_first_as,
4703 neighbor_enforce_first_as_cmd,
4704 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4705 NEIGHBOR_STR
4706 NEIGHBOR_ADDR_STR2
4707 "Enforce the first AS for EBGP routes\n")
4708{
4709 int idx_peer = 1;
4710
4711 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4712 PEER_FLAG_ENFORCE_FIRST_AS);
4713}
4714
4715DEFUN (no_neighbor_enforce_first_as,
4716 no_neighbor_enforce_first_as_cmd,
4717 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4718 NO_STR
4719 NEIGHBOR_STR
4720 NEIGHBOR_ADDR_STR2
4721 "Enforce the first AS for EBGP routes\n")
4722{
4723 int idx_peer = 2;
4724
4725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4726 PEER_FLAG_ENFORCE_FIRST_AS);
4727}
4728
4729
718e3744 4730DEFUN (neighbor_description,
4731 neighbor_description_cmd,
e961923c 4732 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Neighbor specific description\n"
4736 "Up to 80 characters describing this neighbor\n")
4737{
d62a17ae 4738 int idx_peer = 1;
4739 int idx_line = 3;
4740 struct peer *peer;
4741 char *str;
718e3744 4742
d62a17ae 4743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4744 if (!peer)
4745 return CMD_WARNING_CONFIG_FAILED;
718e3744 4746
d62a17ae 4747 str = argv_concat(argv, argc, idx_line);
718e3744 4748
d62a17ae 4749 peer_description_set(peer, str);
718e3744 4750
d62a17ae 4751 XFREE(MTYPE_TMP, str);
718e3744 4752
d62a17ae 4753 return CMD_SUCCESS;
718e3744 4754}
4755
4756DEFUN (no_neighbor_description,
4757 no_neighbor_description_cmd,
a14810f4 4758 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4759 NO_STR
4760 NEIGHBOR_STR
4761 NEIGHBOR_ADDR_STR2
a14810f4 4762 "Neighbor specific description\n")
718e3744 4763{
d62a17ae 4764 int idx_peer = 2;
4765 struct peer *peer;
718e3744 4766
d62a17ae 4767 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4768 if (!peer)
4769 return CMD_WARNING_CONFIG_FAILED;
718e3744 4770
d62a17ae 4771 peer_description_unset(peer);
718e3744 4772
d62a17ae 4773 return CMD_SUCCESS;
718e3744 4774}
4775
a14810f4
PM
4776ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4777 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4779 "Neighbor specific description\n"
4780 "Up to 80 characters describing this neighbor\n")
6b0655a2 4781
718e3744 4782/* Neighbor update-source. */
d62a17ae 4783static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4784 const char *source_str)
4785{
4786 struct peer *peer;
4787 struct prefix p;
a14810f4 4788 union sockunion su;
d62a17ae 4789
4790 peer = peer_and_group_lookup_vty(vty, peer_str);
4791 if (!peer)
4792 return CMD_WARNING_CONFIG_FAILED;
4793
4794 if (peer->conf_if)
4795 return CMD_WARNING;
4796
4797 if (source_str) {
a14810f4 4798 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4799 peer_update_source_addr_set(peer, &su);
4800 else {
4801 if (str2prefix(source_str, &p)) {
4802 vty_out(vty,
4803 "%% Invalid update-source, remove prefix length \n");
4804 return CMD_WARNING_CONFIG_FAILED;
4805 } else
4806 peer_update_source_if_set(peer, source_str);
4807 }
4808 } else
4809 peer_update_source_unset(peer);
4810
4811 return CMD_SUCCESS;
4812}
4813
4814#define BGP_UPDATE_SOURCE_HELP_STR \
4815 "IPv4 address\n" \
4816 "IPv6 address\n" \
4817 "Interface name (requires zebra to be running)\n"
369688c0 4818
718e3744 4819DEFUN (neighbor_update_source,
4820 neighbor_update_source_cmd,
9ccf14f7 4821 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4822 NEIGHBOR_STR
4823 NEIGHBOR_ADDR_STR2
4824 "Source of routing updates\n"
369688c0 4825 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4826{
d62a17ae 4827 int idx_peer = 1;
4828 int idx_peer_2 = 3;
4829 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4830 argv[idx_peer_2]->arg);
718e3744 4831}
4832
4833DEFUN (no_neighbor_update_source,
4834 no_neighbor_update_source_cmd,
c7178fe7 4835 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4836 NO_STR
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4839 "Source of routing updates\n"
4840 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4841{
d62a17ae 4842 int idx_peer = 2;
4843 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4844}
6b0655a2 4845
d62a17ae 4846static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4847 afi_t afi, safi_t safi,
4848 const char *rmap, int set)
718e3744 4849{
d62a17ae 4850 int ret;
4851 struct peer *peer;
1de27621 4852 struct route_map *route_map;
718e3744 4853
d62a17ae 4854 peer = peer_and_group_lookup_vty(vty, peer_str);
4855 if (!peer)
4856 return CMD_WARNING_CONFIG_FAILED;
718e3744 4857
1de27621
DA
4858 if (set) {
4859 route_map = route_map_lookup_warn_noexist(vty, rmap);
4860 ret = peer_default_originate_set(peer, afi, safi,
4861 rmap, route_map);
4862 } else
d62a17ae 4863 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4864
d62a17ae 4865 return bgp_vty_return(vty, ret);
718e3744 4866}
4867
4868/* neighbor default-originate. */
4869DEFUN (neighbor_default_originate,
4870 neighbor_default_originate_cmd,
9ccf14f7 4871 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR2
4874 "Originate default route to this neighbor\n")
4875{
d62a17ae 4876 int idx_peer = 1;
4877 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4878 bgp_node_afi(vty),
4879 bgp_node_safi(vty), NULL, 1);
718e3744 4880}
4881
d62a17ae 4882ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4883 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4885 "Originate default route to this neighbor\n")
596c17ba 4886
718e3744 4887DEFUN (neighbor_default_originate_rmap,
4888 neighbor_default_originate_rmap_cmd,
9ccf14f7 4889 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR2
4892 "Originate default route to this neighbor\n"
4893 "Route-map to specify criteria to originate default\n"
4894 "route-map name\n")
4895{
d62a17ae 4896 int idx_peer = 1;
4897 int idx_word = 4;
4898 return peer_default_originate_set_vty(
4899 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4900 argv[idx_word]->arg, 1);
718e3744 4901}
4902
d62a17ae 4903ALIAS_HIDDEN(
4904 neighbor_default_originate_rmap,
4905 neighbor_default_originate_rmap_hidden_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4908 "Originate default route to this neighbor\n"
4909 "Route-map to specify criteria to originate default\n"
4910 "route-map name\n")
596c17ba 4911
718e3744 4912DEFUN (no_neighbor_default_originate,
4913 no_neighbor_default_originate_cmd,
a636c635 4914 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4915 NO_STR
4916 NEIGHBOR_STR
4917 NEIGHBOR_ADDR_STR2
a636c635
DW
4918 "Originate default route to this neighbor\n"
4919 "Route-map to specify criteria to originate default\n"
4920 "route-map name\n")
718e3744 4921{
d62a17ae 4922 int idx_peer = 2;
4923 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4924 bgp_node_afi(vty),
4925 bgp_node_safi(vty), NULL, 0);
718e3744 4926}
4927
d62a17ae 4928ALIAS_HIDDEN(
4929 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4930 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4931 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4932 "Originate default route to this neighbor\n"
4933 "Route-map to specify criteria to originate default\n"
4934 "route-map name\n")
596c17ba 4935
6b0655a2 4936
718e3744 4937/* Set neighbor's BGP port. */
d62a17ae 4938static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4939 const char *port_str)
4940{
4941 struct peer *peer;
d7c0a89a 4942 uint16_t port;
d62a17ae 4943 struct servent *sp;
4944
4945 peer = peer_lookup_vty(vty, ip_str);
4946 if (!peer)
4947 return CMD_WARNING_CONFIG_FAILED;
4948
4949 if (!port_str) {
4950 sp = getservbyname("bgp", "tcp");
4951 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4952 } else {
4953 port = strtoul(port_str, NULL, 10);
4954 }
718e3744 4955
d62a17ae 4956 peer_port_set(peer, port);
718e3744 4957
d62a17ae 4958 return CMD_SUCCESS;
718e3744 4959}
4960
f418446b 4961/* Set specified peer's BGP port. */
718e3744 4962DEFUN (neighbor_port,
4963 neighbor_port_cmd,
9ccf14f7 4964 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR
4967 "Neighbor's BGP port\n"
4968 "TCP port number\n")
4969{
d62a17ae 4970 int idx_ip = 1;
4971 int idx_number = 3;
4972 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4973 argv[idx_number]->arg);
718e3744 4974}
4975
4976DEFUN (no_neighbor_port,
4977 no_neighbor_port_cmd,
9ccf14f7 4978 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR
8334fd5a
DW
4982 "Neighbor's BGP port\n"
4983 "TCP port number\n")
718e3744 4984{
d62a17ae 4985 int idx_ip = 2;
4986 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4987}
4988
6b0655a2 4989
718e3744 4990/* neighbor weight. */
d62a17ae 4991static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4992 safi_t safi, const char *weight_str)
718e3744 4993{
d62a17ae 4994 int ret;
4995 struct peer *peer;
4996 unsigned long weight;
718e3744 4997
d62a17ae 4998 peer = peer_and_group_lookup_vty(vty, ip_str);
4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
718e3744 5001
d62a17ae 5002 weight = strtoul(weight_str, NULL, 10);
718e3744 5003
d62a17ae 5004 ret = peer_weight_set(peer, afi, safi, weight);
5005 return bgp_vty_return(vty, ret);
718e3744 5006}
5007
d62a17ae 5008static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5009 safi_t safi)
718e3744 5010{
d62a17ae 5011 int ret;
5012 struct peer *peer;
718e3744 5013
d62a17ae 5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
718e3744 5017
d62a17ae 5018 ret = peer_weight_unset(peer, afi, safi);
5019 return bgp_vty_return(vty, ret);
718e3744 5020}
5021
5022DEFUN (neighbor_weight,
5023 neighbor_weight_cmd,
9ccf14f7 5024 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "Set default weight for routes from this neighbor\n"
5028 "default weight\n")
5029{
d62a17ae 5030 int idx_peer = 1;
5031 int idx_number = 3;
5032 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5033 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5034}
5035
d62a17ae 5036ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5037 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5039 "Set default weight for routes from this neighbor\n"
5040 "default weight\n")
596c17ba 5041
718e3744 5042DEFUN (no_neighbor_weight,
5043 no_neighbor_weight_cmd,
9ccf14f7 5044 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5045 NO_STR
5046 NEIGHBOR_STR
5047 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5048 "Set default weight for routes from this neighbor\n"
5049 "default weight\n")
718e3744 5050{
d62a17ae 5051 int idx_peer = 2;
5052 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5053 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5054}
5055
d62a17ae 5056ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5057 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5059 "Set default weight for routes from this neighbor\n"
5060 "default weight\n")
596c17ba 5061
6b0655a2 5062
718e3744 5063/* Override capability negotiation. */
5064DEFUN (neighbor_override_capability,
5065 neighbor_override_capability_cmd,
9ccf14f7 5066 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "Override capability negotiation result\n")
5070{
d62a17ae 5071 int idx_peer = 1;
5072 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5073 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5074}
5075
5076DEFUN (no_neighbor_override_capability,
5077 no_neighbor_override_capability_cmd,
9ccf14f7 5078 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5079 NO_STR
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Override capability negotiation result\n")
5083{
d62a17ae 5084 int idx_peer = 2;
5085 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5086 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5087}
6b0655a2 5088
718e3744 5089DEFUN (neighbor_strict_capability,
5090 neighbor_strict_capability_cmd,
9fb964de 5091 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5092 NEIGHBOR_STR
9fb964de 5093 NEIGHBOR_ADDR_STR2
718e3744 5094 "Strict capability negotiation match\n")
5095{
9fb964de
PM
5096 int idx_peer = 1;
5097
5098 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5099 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5100}
5101
5102DEFUN (no_neighbor_strict_capability,
5103 no_neighbor_strict_capability_cmd,
9fb964de 5104 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5105 NO_STR
5106 NEIGHBOR_STR
9fb964de 5107 NEIGHBOR_ADDR_STR2
718e3744 5108 "Strict capability negotiation match\n")
5109{
9fb964de
PM
5110 int idx_peer = 2;
5111
5112 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5113 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5114}
6b0655a2 5115
d62a17ae 5116static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5117 const char *keep_str, const char *hold_str)
718e3744 5118{
d62a17ae 5119 int ret;
5120 struct peer *peer;
d7c0a89a
QY
5121 uint32_t keepalive;
5122 uint32_t holdtime;
718e3744 5123
d62a17ae 5124 peer = peer_and_group_lookup_vty(vty, ip_str);
5125 if (!peer)
5126 return CMD_WARNING_CONFIG_FAILED;
718e3744 5127
d62a17ae 5128 keepalive = strtoul(keep_str, NULL, 10);
5129 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5130
d62a17ae 5131 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5132
d62a17ae 5133 return bgp_vty_return(vty, ret);
718e3744 5134}
6b0655a2 5135
d62a17ae 5136static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5137{
d62a17ae 5138 int ret;
5139 struct peer *peer;
718e3744 5140
d62a17ae 5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
718e3744 5144
d62a17ae 5145 ret = peer_timers_unset(peer);
718e3744 5146
d62a17ae 5147 return bgp_vty_return(vty, ret);
718e3744 5148}
5149
5150DEFUN (neighbor_timers,
5151 neighbor_timers_cmd,
9ccf14f7 5152 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "BGP per neighbor timers\n"
5156 "Keepalive interval\n"
5157 "Holdtime\n")
5158{
d62a17ae 5159 int idx_peer = 1;
5160 int idx_number = 3;
5161 int idx_number_2 = 4;
5162 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5163 argv[idx_number]->arg,
5164 argv[idx_number_2]->arg);
718e3744 5165}
5166
5167DEFUN (no_neighbor_timers,
5168 no_neighbor_timers_cmd,
9ccf14f7 5169 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5170 NO_STR
5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5173 "BGP per neighbor timers\n"
5174 "Keepalive interval\n"
5175 "Holdtime\n")
718e3744 5176{
d62a17ae 5177 int idx_peer = 2;
5178 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5179}
6b0655a2 5180
813d4307 5181
d62a17ae 5182static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5183 const char *time_str)
718e3744 5184{
d62a17ae 5185 int ret;
5186 struct peer *peer;
d7c0a89a 5187 uint32_t connect;
718e3744 5188
d62a17ae 5189 peer = peer_and_group_lookup_vty(vty, ip_str);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
718e3744 5192
d62a17ae 5193 connect = strtoul(time_str, NULL, 10);
718e3744 5194
d62a17ae 5195 ret = peer_timers_connect_set(peer, connect);
718e3744 5196
d62a17ae 5197 return bgp_vty_return(vty, ret);
718e3744 5198}
5199
d62a17ae 5200static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5201{
d62a17ae 5202 int ret;
5203 struct peer *peer;
718e3744 5204
d62a17ae 5205 peer = peer_and_group_lookup_vty(vty, ip_str);
5206 if (!peer)
5207 return CMD_WARNING_CONFIG_FAILED;
718e3744 5208
d62a17ae 5209 ret = peer_timers_connect_unset(peer);
718e3744 5210
d62a17ae 5211 return bgp_vty_return(vty, ret);
718e3744 5212}
5213
5214DEFUN (neighbor_timers_connect,
5215 neighbor_timers_connect_cmd,
9ccf14f7 5216 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5217 NEIGHBOR_STR
966f821c 5218 NEIGHBOR_ADDR_STR2
718e3744 5219 "BGP per neighbor timers\n"
5220 "BGP connect timer\n"
5221 "Connect timer\n")
5222{
d62a17ae 5223 int idx_peer = 1;
5224 int idx_number = 4;
5225 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5226 argv[idx_number]->arg);
718e3744 5227}
5228
5229DEFUN (no_neighbor_timers_connect,
5230 no_neighbor_timers_connect_cmd,
9ccf14f7 5231 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5232 NO_STR
5233 NEIGHBOR_STR
966f821c 5234 NEIGHBOR_ADDR_STR2
718e3744 5235 "BGP per neighbor timers\n"
8334fd5a
DW
5236 "BGP connect timer\n"
5237 "Connect timer\n")
718e3744 5238{
d62a17ae 5239 int idx_peer = 2;
5240 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5241}
5242
6b0655a2 5243
d62a17ae 5244static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5245 const char *time_str, int set)
718e3744 5246{
d62a17ae 5247 int ret;
5248 struct peer *peer;
d7c0a89a 5249 uint32_t routeadv = 0;
718e3744 5250
d62a17ae 5251 peer = peer_and_group_lookup_vty(vty, ip_str);
5252 if (!peer)
5253 return CMD_WARNING_CONFIG_FAILED;
718e3744 5254
d62a17ae 5255 if (time_str)
5256 routeadv = strtoul(time_str, NULL, 10);
718e3744 5257
d62a17ae 5258 if (set)
5259 ret = peer_advertise_interval_set(peer, routeadv);
5260 else
5261 ret = peer_advertise_interval_unset(peer);
718e3744 5262
d62a17ae 5263 return bgp_vty_return(vty, ret);
718e3744 5264}
5265
5266DEFUN (neighbor_advertise_interval,
5267 neighbor_advertise_interval_cmd,
9ccf14f7 5268 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5269 NEIGHBOR_STR
966f821c 5270 NEIGHBOR_ADDR_STR2
718e3744 5271 "Minimum interval between sending BGP routing updates\n"
5272 "time in seconds\n")
5273{
d62a17ae 5274 int idx_peer = 1;
5275 int idx_number = 3;
5276 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5277 argv[idx_number]->arg, 1);
718e3744 5278}
5279
5280DEFUN (no_neighbor_advertise_interval,
5281 no_neighbor_advertise_interval_cmd,
9ccf14f7 5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5283 NO_STR
5284 NEIGHBOR_STR
966f821c 5285 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5286 "Minimum interval between sending BGP routing updates\n"
5287 "time in seconds\n")
718e3744 5288{
d62a17ae 5289 int idx_peer = 2;
5290 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5291}
5292
6b0655a2 5293
518f0eb1
DS
5294/* Time to wait before processing route-map updates */
5295DEFUN (bgp_set_route_map_delay_timer,
5296 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5297 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5298 SET_STR
5299 "BGP route-map delay timer\n"
5300 "Time in secs to wait before processing route-map changes\n"
f414725f 5301 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5302{
d62a17ae 5303 int idx_number = 3;
d7c0a89a 5304 uint32_t rmap_delay_timer;
d62a17ae 5305
5306 if (argv[idx_number]->arg) {
5307 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5308 bm->rmap_update_timer = rmap_delay_timer;
5309
5310 /* if the dynamic update handling is being disabled, and a timer
5311 * is
5312 * running, stop the timer and act as if the timer has already
5313 * fired.
5314 */
5315 if (!rmap_delay_timer && bm->t_rmap_update) {
5316 BGP_TIMER_OFF(bm->t_rmap_update);
5317 thread_execute(bm->master, bgp_route_map_update_timer,
5318 NULL, 0);
5319 }
5320 return CMD_SUCCESS;
5321 } else {
5322 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5323 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5324 }
518f0eb1
DS
5325}
5326
5327DEFUN (no_bgp_set_route_map_delay_timer,
5328 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5329 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5330 NO_STR
3a2d747c 5331 BGP_STR
518f0eb1 5332 "Default BGP route-map delay timer\n"
8334fd5a
DW
5333 "Reset to default time to wait for processing route-map changes\n"
5334 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5335{
518f0eb1 5336
d62a17ae 5337 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5338
d62a17ae 5339 return CMD_SUCCESS;
518f0eb1
DS
5340}
5341
f414725f 5342
718e3744 5343/* neighbor interface */
d62a17ae 5344static int peer_interface_vty(struct vty *vty, const char *ip_str,
5345 const char *str)
718e3744 5346{
d62a17ae 5347 struct peer *peer;
718e3744 5348
d62a17ae 5349 peer = peer_lookup_vty(vty, ip_str);
5350 if (!peer || peer->conf_if) {
5351 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5352 return CMD_WARNING_CONFIG_FAILED;
5353 }
718e3744 5354
d62a17ae 5355 if (str)
5356 peer_interface_set(peer, str);
5357 else
5358 peer_interface_unset(peer);
718e3744 5359
d62a17ae 5360 return CMD_SUCCESS;
718e3744 5361}
5362
5363DEFUN (neighbor_interface,
5364 neighbor_interface_cmd,
9ccf14f7 5365 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5366 NEIGHBOR_STR
5367 NEIGHBOR_ADDR_STR
5368 "Interface\n"
5369 "Interface name\n")
5370{
d62a17ae 5371 int idx_ip = 1;
5372 int idx_word = 3;
5373 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5374}
5375
5376DEFUN (no_neighbor_interface,
5377 no_neighbor_interface_cmd,
9ccf14f7 5378 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5379 NO_STR
5380 NEIGHBOR_STR
16cedbb0 5381 NEIGHBOR_ADDR_STR2
718e3744 5382 "Interface\n"
5383 "Interface name\n")
5384{
d62a17ae 5385 int idx_peer = 2;
5386 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5387}
6b0655a2 5388
718e3744 5389DEFUN (neighbor_distribute_list,
5390 neighbor_distribute_list_cmd,
9ccf14f7 5391 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5392 NEIGHBOR_STR
5393 NEIGHBOR_ADDR_STR2
5394 "Filter updates to/from this neighbor\n"
5395 "IP access-list number\n"
5396 "IP access-list number (expanded range)\n"
5397 "IP Access-list name\n"
5398 "Filter incoming updates\n"
5399 "Filter outgoing updates\n")
5400{
d62a17ae 5401 int idx_peer = 1;
5402 int idx_acl = 3;
5403 int direct, ret;
5404 struct peer *peer;
a8206004 5405
d62a17ae 5406 const char *pstr = argv[idx_peer]->arg;
5407 const char *acl = argv[idx_acl]->arg;
5408 const char *inout = argv[argc - 1]->text;
a8206004 5409
d62a17ae 5410 peer = peer_and_group_lookup_vty(vty, pstr);
5411 if (!peer)
5412 return CMD_WARNING_CONFIG_FAILED;
a8206004 5413
d62a17ae 5414 /* Check filter direction. */
5415 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5416 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5417 direct, acl);
a8206004 5418
d62a17ae 5419 return bgp_vty_return(vty, ret);
718e3744 5420}
5421
d62a17ae 5422ALIAS_HIDDEN(
5423 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5425 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5426 "Filter updates to/from this neighbor\n"
5427 "IP access-list number\n"
5428 "IP access-list number (expanded range)\n"
5429 "IP Access-list name\n"
5430 "Filter incoming updates\n"
5431 "Filter outgoing updates\n")
596c17ba 5432
718e3744 5433DEFUN (no_neighbor_distribute_list,
5434 no_neighbor_distribute_list_cmd,
9ccf14f7 5435 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5436 NO_STR
5437 NEIGHBOR_STR
5438 NEIGHBOR_ADDR_STR2
5439 "Filter updates to/from this neighbor\n"
5440 "IP access-list number\n"
5441 "IP access-list number (expanded range)\n"
5442 "IP Access-list name\n"
5443 "Filter incoming updates\n"
5444 "Filter outgoing updates\n")
5445{
d62a17ae 5446 int idx_peer = 2;
5447 int direct, ret;
5448 struct peer *peer;
a8206004 5449
d62a17ae 5450 const char *pstr = argv[idx_peer]->arg;
5451 const char *inout = argv[argc - 1]->text;
a8206004 5452
d62a17ae 5453 peer = peer_and_group_lookup_vty(vty, pstr);
5454 if (!peer)
5455 return CMD_WARNING_CONFIG_FAILED;
a8206004 5456
d62a17ae 5457 /* Check filter direction. */
5458 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5459 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5460 direct);
a8206004 5461
d62a17ae 5462 return bgp_vty_return(vty, ret);
718e3744 5463}
6b0655a2 5464
d62a17ae 5465ALIAS_HIDDEN(
5466 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5467 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5469 "Filter updates to/from this neighbor\n"
5470 "IP access-list number\n"
5471 "IP access-list number (expanded range)\n"
5472 "IP Access-list name\n"
5473 "Filter incoming updates\n"
5474 "Filter outgoing updates\n")
596c17ba 5475
718e3744 5476/* Set prefix list to the peer. */
d62a17ae 5477static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5478 afi_t afi, safi_t safi,
5479 const char *name_str,
5480 const char *direct_str)
718e3744 5481{
d62a17ae 5482 int ret;
d62a17ae 5483 int direct = FILTER_IN;
cf9ac8bf 5484 struct peer *peer;
718e3744 5485
d62a17ae 5486 peer = peer_and_group_lookup_vty(vty, ip_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
718e3744 5489
d62a17ae 5490 /* Check filter direction. */
5491 if (strncmp(direct_str, "i", 1) == 0)
5492 direct = FILTER_IN;
5493 else if (strncmp(direct_str, "o", 1) == 0)
5494 direct = FILTER_OUT;
718e3744 5495
d62a17ae 5496 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5497
d62a17ae 5498 return bgp_vty_return(vty, ret);
718e3744 5499}
5500
d62a17ae 5501static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5502 afi_t afi, safi_t safi,
5503 const char *direct_str)
718e3744 5504{
d62a17ae 5505 int ret;
5506 struct peer *peer;
5507 int direct = FILTER_IN;
718e3744 5508
d62a17ae 5509 peer = peer_and_group_lookup_vty(vty, ip_str);
5510 if (!peer)
5511 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5512
d62a17ae 5513 /* Check filter direction. */
5514 if (strncmp(direct_str, "i", 1) == 0)
5515 direct = FILTER_IN;
5516 else if (strncmp(direct_str, "o", 1) == 0)
5517 direct = FILTER_OUT;
718e3744 5518
d62a17ae 5519 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5520
d62a17ae 5521 return bgp_vty_return(vty, ret);
718e3744 5522}
5523
5524DEFUN (neighbor_prefix_list,
5525 neighbor_prefix_list_cmd,
9ccf14f7 5526 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5527 NEIGHBOR_STR
5528 NEIGHBOR_ADDR_STR2
5529 "Filter updates to/from this neighbor\n"
5530 "Name of a prefix list\n"
5531 "Filter incoming updates\n"
5532 "Filter outgoing updates\n")
5533{
d62a17ae 5534 int idx_peer = 1;
5535 int idx_word = 3;
5536 int idx_in_out = 4;
5537 return peer_prefix_list_set_vty(
5538 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5539 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5540}
5541
d62a17ae 5542ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5543 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Filter updates to/from this neighbor\n"
5546 "Name of a prefix list\n"
5547 "Filter incoming updates\n"
5548 "Filter outgoing updates\n")
596c17ba 5549
718e3744 5550DEFUN (no_neighbor_prefix_list,
5551 no_neighbor_prefix_list_cmd,
9ccf14f7 5552 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5553 NO_STR
5554 NEIGHBOR_STR
5555 NEIGHBOR_ADDR_STR2
5556 "Filter updates to/from this neighbor\n"
5557 "Name of a prefix list\n"
5558 "Filter incoming updates\n"
5559 "Filter outgoing updates\n")
5560{
d62a17ae 5561 int idx_peer = 2;
5562 int idx_in_out = 5;
5563 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5564 bgp_node_afi(vty), bgp_node_safi(vty),
5565 argv[idx_in_out]->arg);
718e3744 5566}
6b0655a2 5567
d62a17ae 5568ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5569 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5570 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5571 "Filter updates to/from this neighbor\n"
5572 "Name of a prefix list\n"
5573 "Filter incoming updates\n"
5574 "Filter outgoing updates\n")
596c17ba 5575
d62a17ae 5576static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5577 safi_t safi, const char *name_str,
5578 const char *direct_str)
718e3744 5579{
d62a17ae 5580 int ret;
5581 struct peer *peer;
5582 int direct = FILTER_IN;
718e3744 5583
d62a17ae 5584 peer = peer_and_group_lookup_vty(vty, ip_str);
5585 if (!peer)
5586 return CMD_WARNING_CONFIG_FAILED;
718e3744 5587
d62a17ae 5588 /* Check filter direction. */
5589 if (strncmp(direct_str, "i", 1) == 0)
5590 direct = FILTER_IN;
5591 else if (strncmp(direct_str, "o", 1) == 0)
5592 direct = FILTER_OUT;
718e3744 5593
d62a17ae 5594 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5595
d62a17ae 5596 return bgp_vty_return(vty, ret);
718e3744 5597}
5598
d62a17ae 5599static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5600 safi_t safi, const char *direct_str)
718e3744 5601{
d62a17ae 5602 int ret;
5603 struct peer *peer;
5604 int direct = FILTER_IN;
718e3744 5605
d62a17ae 5606 peer = peer_and_group_lookup_vty(vty, ip_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
718e3744 5609
d62a17ae 5610 /* Check filter direction. */
5611 if (strncmp(direct_str, "i", 1) == 0)
5612 direct = FILTER_IN;
5613 else if (strncmp(direct_str, "o", 1) == 0)
5614 direct = FILTER_OUT;
718e3744 5615
d62a17ae 5616 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5617
d62a17ae 5618 return bgp_vty_return(vty, ret);
718e3744 5619}
5620
5621DEFUN (neighbor_filter_list,
5622 neighbor_filter_list_cmd,
9ccf14f7 5623 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5624 NEIGHBOR_STR
5625 NEIGHBOR_ADDR_STR2
5626 "Establish BGP filters\n"
5627 "AS path access-list name\n"
5628 "Filter incoming routes\n"
5629 "Filter outgoing routes\n")
5630{
d62a17ae 5631 int idx_peer = 1;
5632 int idx_word = 3;
5633 int idx_in_out = 4;
5634 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5635 bgp_node_safi(vty), argv[idx_word]->arg,
5636 argv[idx_in_out]->arg);
718e3744 5637}
5638
d62a17ae 5639ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Establish BGP filters\n"
5643 "AS path access-list name\n"
5644 "Filter incoming routes\n"
5645 "Filter outgoing routes\n")
596c17ba 5646
718e3744 5647DEFUN (no_neighbor_filter_list,
5648 no_neighbor_filter_list_cmd,
9ccf14f7 5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5650 NO_STR
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Establish BGP filters\n"
5654 "AS path access-list name\n"
5655 "Filter incoming routes\n"
5656 "Filter outgoing routes\n")
5657{
d62a17ae 5658 int idx_peer = 2;
5659 int idx_in_out = 5;
5660 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5661 bgp_node_afi(vty), bgp_node_safi(vty),
5662 argv[idx_in_out]->arg);
718e3744 5663}
6b0655a2 5664
d62a17ae 5665ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5666 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5667 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5668 "Establish BGP filters\n"
5669 "AS path access-list name\n"
5670 "Filter incoming routes\n"
5671 "Filter outgoing routes\n")
596c17ba 5672
718e3744 5673/* Set route-map to the peer. */
d62a17ae 5674static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5675 afi_t afi, safi_t safi, const char *name_str,
5676 const char *direct_str)
718e3744 5677{
d62a17ae 5678 int ret;
5679 struct peer *peer;
5680 int direct = RMAP_IN;
1de27621 5681 struct route_map *route_map;
718e3744 5682
d62a17ae 5683 peer = peer_and_group_lookup_vty(vty, ip_str);
5684 if (!peer)
5685 return CMD_WARNING_CONFIG_FAILED;
718e3744 5686
d62a17ae 5687 /* Check filter direction. */
5688 if (strncmp(direct_str, "in", 2) == 0)
5689 direct = RMAP_IN;
5690 else if (strncmp(direct_str, "o", 1) == 0)
5691 direct = RMAP_OUT;
718e3744 5692
1de27621
DA
5693 route_map = route_map_lookup_warn_noexist(vty, name_str);
5694 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5695
d62a17ae 5696 return bgp_vty_return(vty, ret);
718e3744 5697}
5698
d62a17ae 5699static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5700 afi_t afi, safi_t safi,
5701 const char *direct_str)
718e3744 5702{
d62a17ae 5703 int ret;
5704 struct peer *peer;
5705 int direct = RMAP_IN;
718e3744 5706
d62a17ae 5707 peer = peer_and_group_lookup_vty(vty, ip_str);
5708 if (!peer)
5709 return CMD_WARNING_CONFIG_FAILED;
718e3744 5710
d62a17ae 5711 /* Check filter direction. */
5712 if (strncmp(direct_str, "in", 2) == 0)
5713 direct = RMAP_IN;
5714 else if (strncmp(direct_str, "o", 1) == 0)
5715 direct = RMAP_OUT;
718e3744 5716
d62a17ae 5717 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5718
d62a17ae 5719 return bgp_vty_return(vty, ret);
718e3744 5720}
5721
5722DEFUN (neighbor_route_map,
5723 neighbor_route_map_cmd,
9ccf14f7 5724 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR2
5727 "Apply route map to neighbor\n"
5728 "Name of route map\n"
5729 "Apply map to incoming routes\n"
2a3d5731 5730 "Apply map to outbound routes\n")
718e3744 5731{
d62a17ae 5732 int idx_peer = 1;
5733 int idx_word = 3;
5734 int idx_in_out = 4;
5735 return peer_route_map_set_vty(
5736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5737 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5738}
5739
d62a17ae 5740ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5741 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5743 "Apply route map to neighbor\n"
5744 "Name of route map\n"
5745 "Apply map to incoming routes\n"
5746 "Apply map to outbound routes\n")
596c17ba 5747
718e3744 5748DEFUN (no_neighbor_route_map,
5749 no_neighbor_route_map_cmd,
9ccf14f7 5750 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5751 NO_STR
5752 NEIGHBOR_STR
5753 NEIGHBOR_ADDR_STR2
5754 "Apply route map to neighbor\n"
5755 "Name of route map\n"
5756 "Apply map to incoming routes\n"
2a3d5731 5757 "Apply map to outbound routes\n")
718e3744 5758{
d62a17ae 5759 int idx_peer = 2;
5760 int idx_in_out = 5;
5761 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5762 bgp_node_afi(vty), bgp_node_safi(vty),
5763 argv[idx_in_out]->arg);
718e3744 5764}
6b0655a2 5765
d62a17ae 5766ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5767 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5768 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5769 "Apply route map to neighbor\n"
5770 "Name of route map\n"
5771 "Apply map to incoming routes\n"
5772 "Apply map to outbound routes\n")
596c17ba 5773
718e3744 5774/* Set unsuppress-map to the peer. */
d62a17ae 5775static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5776 afi_t afi, safi_t safi,
5777 const char *name_str)
718e3744 5778{
d62a17ae 5779 int ret;
5780 struct peer *peer;
1de27621 5781 struct route_map *route_map;
718e3744 5782
d62a17ae 5783 peer = peer_and_group_lookup_vty(vty, ip_str);
5784 if (!peer)
5785 return CMD_WARNING_CONFIG_FAILED;
718e3744 5786
1de27621
DA
5787 route_map = route_map_lookup_warn_noexist(vty, name_str);
5788 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5789
d62a17ae 5790 return bgp_vty_return(vty, ret);
718e3744 5791}
5792
5793/* Unset route-map from the peer. */
d62a17ae 5794static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5795 afi_t afi, safi_t safi)
718e3744 5796{
d62a17ae 5797 int ret;
5798 struct peer *peer;
718e3744 5799
d62a17ae 5800 peer = peer_and_group_lookup_vty(vty, ip_str);
5801 if (!peer)
5802 return CMD_WARNING_CONFIG_FAILED;
718e3744 5803
d62a17ae 5804 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5805
d62a17ae 5806 return bgp_vty_return(vty, ret);
718e3744 5807}
5808
5809DEFUN (neighbor_unsuppress_map,
5810 neighbor_unsuppress_map_cmd,
9ccf14f7 5811 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Route-map to selectively unsuppress suppressed routes\n"
5815 "Name of route map\n")
5816{
d62a17ae 5817 int idx_peer = 1;
5818 int idx_word = 3;
5819 return peer_unsuppress_map_set_vty(
5820 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5821 argv[idx_word]->arg);
718e3744 5822}
5823
d62a17ae 5824ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Route-map to selectively unsuppress suppressed routes\n"
5828 "Name of route map\n")
596c17ba 5829
718e3744 5830DEFUN (no_neighbor_unsuppress_map,
5831 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5832 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5833 NO_STR
5834 NEIGHBOR_STR
5835 NEIGHBOR_ADDR_STR2
5836 "Route-map to selectively unsuppress suppressed routes\n"
5837 "Name of route map\n")
5838{
d62a17ae 5839 int idx_peer = 2;
5840 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5841 bgp_node_afi(vty),
5842 bgp_node_safi(vty));
718e3744 5843}
6b0655a2 5844
d62a17ae 5845ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5846 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Route-map to selectively unsuppress suppressed routes\n"
5849 "Name of route map\n")
596c17ba 5850
d62a17ae 5851static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5852 afi_t afi, safi_t safi,
5853 const char *num_str,
5854 const char *threshold_str, int warning,
5855 const char *restart_str)
718e3744 5856{
d62a17ae 5857 int ret;
5858 struct peer *peer;
d7c0a89a
QY
5859 uint32_t max;
5860 uint8_t threshold;
5861 uint16_t restart;
718e3744 5862
d62a17ae 5863 peer = peer_and_group_lookup_vty(vty, ip_str);
5864 if (!peer)
5865 return CMD_WARNING_CONFIG_FAILED;
718e3744 5866
d62a17ae 5867 max = strtoul(num_str, NULL, 10);
5868 if (threshold_str)
5869 threshold = atoi(threshold_str);
5870 else
5871 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5872
d62a17ae 5873 if (restart_str)
5874 restart = atoi(restart_str);
5875 else
5876 restart = 0;
0a486e5f 5877
d62a17ae 5878 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5879 restart);
718e3744 5880
d62a17ae 5881 return bgp_vty_return(vty, ret);
718e3744 5882}
5883
d62a17ae 5884static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi)
718e3744 5886{
d62a17ae 5887 int ret;
5888 struct peer *peer;
718e3744 5889
d62a17ae 5890 peer = peer_and_group_lookup_vty(vty, ip_str);
5891 if (!peer)
5892 return CMD_WARNING_CONFIG_FAILED;
718e3744 5893
d62a17ae 5894 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5895
d62a17ae 5896 return bgp_vty_return(vty, ret);
718e3744 5897}
5898
5899/* Maximum number of prefix configuration. prefix count is different
5900 for each peer configuration. So this configuration can be set for
5901 each peer configuration. */
5902DEFUN (neighbor_maximum_prefix,
5903 neighbor_maximum_prefix_cmd,
9ccf14f7 5904 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5905 NEIGHBOR_STR
5906 NEIGHBOR_ADDR_STR2
5907 "Maximum number of prefix accept from this peer\n"
5908 "maximum no. of prefix limit\n")
5909{
d62a17ae 5910 int idx_peer = 1;
5911 int idx_number = 3;
5912 return peer_maximum_prefix_set_vty(
5913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5914 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5915}
5916
d62a17ae 5917ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5920 "Maximum number of prefix accept from this peer\n"
5921 "maximum no. of prefix limit\n")
596c17ba 5922
e0701b79 5923DEFUN (neighbor_maximum_prefix_threshold,
5924 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5925 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Maximum number of prefix accept from this peer\n"
5929 "maximum no. of prefix limit\n"
5930 "Threshold value (%) at which to generate a warning msg\n")
5931{
d62a17ae 5932 int idx_peer = 1;
5933 int idx_number = 3;
5934 int idx_number_2 = 4;
5935 return peer_maximum_prefix_set_vty(
5936 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5937 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5938}
e0701b79 5939
d62a17ae 5940ALIAS_HIDDEN(
5941 neighbor_maximum_prefix_threshold,
5942 neighbor_maximum_prefix_threshold_hidden_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5944 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5945 "Maximum number of prefix accept from this peer\n"
5946 "maximum no. of prefix limit\n"
5947 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5948
718e3744 5949DEFUN (neighbor_maximum_prefix_warning,
5950 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefix accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Only give warning message when limit is exceeded\n")
5957{
d62a17ae 5958 int idx_peer = 1;
5959 int idx_number = 3;
5960 return peer_maximum_prefix_set_vty(
5961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5962 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5963}
5964
d62a17ae 5965ALIAS_HIDDEN(
5966 neighbor_maximum_prefix_warning,
5967 neighbor_maximum_prefix_warning_hidden_cmd,
5968 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5969 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "Maximum number of prefix accept from this peer\n"
5971 "maximum no. of prefix limit\n"
5972 "Only give warning message when limit is exceeded\n")
596c17ba 5973
e0701b79 5974DEFUN (neighbor_maximum_prefix_threshold_warning,
5975 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefix accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Threshold value (%) at which to generate a warning msg\n"
5982 "Only give warning message when limit is exceeded\n")
5983{
d62a17ae 5984 int idx_peer = 1;
5985 int idx_number = 3;
5986 int idx_number_2 = 4;
5987 return peer_maximum_prefix_set_vty(
5988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5989 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5990}
5991
d62a17ae 5992ALIAS_HIDDEN(
5993 neighbor_maximum_prefix_threshold_warning,
5994 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5995 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5997 "Maximum number of prefix accept from this peer\n"
5998 "maximum no. of prefix limit\n"
5999 "Threshold value (%) at which to generate a warning msg\n"
6000 "Only give warning message when limit is exceeded\n")
596c17ba 6001
0a486e5f 6002DEFUN (neighbor_maximum_prefix_restart,
6003 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Restart bgp connection after limit is exceeded\n"
efd7904e 6010 "Restart interval in minutes\n")
0a486e5f 6011{
d62a17ae 6012 int idx_peer = 1;
6013 int idx_number = 3;
6014 int idx_number_2 = 5;
6015 return peer_maximum_prefix_set_vty(
6016 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6017 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6018}
6019
d62a17ae 6020ALIAS_HIDDEN(
6021 neighbor_maximum_prefix_restart,
6022 neighbor_maximum_prefix_restart_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Maximum number of prefix accept from this peer\n"
6026 "maximum no. of prefix limit\n"
6027 "Restart bgp connection after limit is exceeded\n"
efd7904e 6028 "Restart interval in minutes\n")
596c17ba 6029
0a486e5f 6030DEFUN (neighbor_maximum_prefix_threshold_restart,
6031 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
16cedbb0 6035 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6036 "maximum no. of prefix limit\n"
6037 "Threshold value (%) at which to generate a warning msg\n"
6038 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6039 "Restart interval in minutes\n")
0a486e5f 6040{
d62a17ae 6041 int idx_peer = 1;
6042 int idx_number = 3;
6043 int idx_number_2 = 4;
6044 int idx_number_3 = 6;
6045 return peer_maximum_prefix_set_vty(
6046 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6047 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6048 argv[idx_number_3]->arg);
6049}
6050
6051ALIAS_HIDDEN(
6052 neighbor_maximum_prefix_threshold_restart,
6053 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6054 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6055 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6056 "Maximum number of prefixes to accept from this peer\n"
6057 "maximum no. of prefix limit\n"
6058 "Threshold value (%) at which to generate a warning msg\n"
6059 "Restart bgp connection after limit is exceeded\n"
6060 "Restart interval in minutes\n")
596c17ba 6061
718e3744 6062DEFUN (no_neighbor_maximum_prefix,
6063 no_neighbor_maximum_prefix_cmd,
d04c479d 6064 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6065 NO_STR
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
16cedbb0 6068 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6069 "maximum no. of prefix limit\n"
6070 "Threshold value (%) at which to generate a warning msg\n"
6071 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6072 "Restart interval in minutes\n"
31500417 6073 "Only give warning message when limit is exceeded\n")
718e3744 6074{
d62a17ae 6075 int idx_peer = 2;
6076 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6077 bgp_node_afi(vty),
6078 bgp_node_safi(vty));
718e3744 6079}
e52702f2 6080
d62a17ae 6081ALIAS_HIDDEN(
6082 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6085 "Maximum number of prefixes to accept from this peer\n"
6086 "maximum no. of prefix limit\n"
6087 "Threshold value (%) at which to generate a warning msg\n"
6088 "Restart bgp connection after limit is exceeded\n"
6089 "Restart interval in minutes\n"
6090 "Only give warning message when limit is exceeded\n")
596c17ba 6091
718e3744 6092
718e3744 6093/* "neighbor allowas-in" */
6094DEFUN (neighbor_allowas_in,
6095 neighbor_allowas_in_cmd,
fd8503f5 6096 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6097 NEIGHBOR_STR
6098 NEIGHBOR_ADDR_STR2
31500417 6099 "Accept as-path with my AS present in it\n"
0437e105 6100 "Number of occurences of AS number\n"
fd8503f5 6101 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6102{
d62a17ae 6103 int idx_peer = 1;
6104 int idx_number_origin = 3;
6105 int ret;
6106 int origin = 0;
6107 struct peer *peer;
6108 int allow_num = 0;
6109
6110 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6111 if (!peer)
6112 return CMD_WARNING_CONFIG_FAILED;
6113
6114 if (argc <= idx_number_origin)
6115 allow_num = 3;
6116 else {
6117 if (argv[idx_number_origin]->type == WORD_TKN)
6118 origin = 1;
6119 else
6120 allow_num = atoi(argv[idx_number_origin]->arg);
6121 }
6122
6123 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6124 allow_num, origin);
6125
6126 return bgp_vty_return(vty, ret);
6127}
6128
6129ALIAS_HIDDEN(
6130 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6131 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6132 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Accept as-path with my AS present in it\n"
0437e105 6134 "Number of occurences of AS number\n"
d62a17ae 6135 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6136
718e3744 6137DEFUN (no_neighbor_allowas_in,
6138 no_neighbor_allowas_in_cmd,
fd8503f5 6139 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6140 NO_STR
6141 NEIGHBOR_STR
6142 NEIGHBOR_ADDR_STR2
8334fd5a 6143 "allow local ASN appears in aspath attribute\n"
0437e105 6144 "Number of occurences of AS number\n"
fd8503f5 6145 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6146{
d62a17ae 6147 int idx_peer = 2;
6148 int ret;
6149 struct peer *peer;
718e3744 6150
d62a17ae 6151 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6152 if (!peer)
6153 return CMD_WARNING_CONFIG_FAILED;
718e3744 6154
d62a17ae 6155 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6156 bgp_node_safi(vty));
718e3744 6157
d62a17ae 6158 return bgp_vty_return(vty, ret);
718e3744 6159}
6b0655a2 6160
d62a17ae 6161ALIAS_HIDDEN(
6162 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6163 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6164 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6165 "allow local ASN appears in aspath attribute\n"
0437e105 6166 "Number of occurences of AS number\n"
d62a17ae 6167 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6168
fa411a21
NH
6169DEFUN (neighbor_ttl_security,
6170 neighbor_ttl_security_cmd,
7ebe625c 6171 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6172 NEIGHBOR_STR
7ebe625c 6173 NEIGHBOR_ADDR_STR2
16cedbb0 6174 "BGP ttl-security parameters\n"
d7fa34c1
QY
6175 "Specify the maximum number of hops to the BGP peer\n"
6176 "Number of hops to BGP peer\n")
fa411a21 6177{
d62a17ae 6178 int idx_peer = 1;
6179 int idx_number = 4;
6180 struct peer *peer;
6181 int gtsm_hops;
6182
6183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6184 if (!peer)
6185 return CMD_WARNING_CONFIG_FAILED;
6186
6187 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6188
7ebe625c
QY
6189 /*
6190 * If 'neighbor swpX', then this is for directly connected peers,
6191 * we should not accept a ttl-security hops value greater than 1.
6192 */
6193 if (peer->conf_if && (gtsm_hops > 1)) {
6194 vty_out(vty,
6195 "%s is directly connected peer, hops cannot exceed 1\n",
6196 argv[idx_peer]->arg);
6197 return CMD_WARNING_CONFIG_FAILED;
6198 }
6199
d62a17ae 6200 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6201}
6202
6203DEFUN (no_neighbor_ttl_security,
6204 no_neighbor_ttl_security_cmd,
7ebe625c 6205 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6206 NO_STR
6207 NEIGHBOR_STR
7ebe625c 6208 NEIGHBOR_ADDR_STR2
16cedbb0 6209 "BGP ttl-security parameters\n"
3a2d747c
QY
6210 "Specify the maximum number of hops to the BGP peer\n"
6211 "Number of hops to BGP peer\n")
fa411a21 6212{
d62a17ae 6213 int idx_peer = 2;
6214 struct peer *peer;
fa411a21 6215
d62a17ae 6216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6219
d62a17ae 6220 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6221}
6b0655a2 6222
adbac85e
DW
6223DEFUN (neighbor_addpath_tx_all_paths,
6224 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6225 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6226 NEIGHBOR_STR
6227 NEIGHBOR_ADDR_STR2
6228 "Use addpath to advertise all paths to a neighbor\n")
6229{
d62a17ae 6230 int idx_peer = 1;
6231 struct peer *peer;
adbac85e 6232
d62a17ae 6233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6234 if (!peer)
6235 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6236
dcc68b5e
MS
6237 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6238 BGP_ADDPATH_ALL);
6239 return CMD_SUCCESS;
adbac85e
DW
6240}
6241
d62a17ae 6242ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6243 neighbor_addpath_tx_all_paths_hidden_cmd,
6244 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6246 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6247
adbac85e
DW
6248DEFUN (no_neighbor_addpath_tx_all_paths,
6249 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6251 NO_STR
6252 NEIGHBOR_STR
6253 NEIGHBOR_ADDR_STR2
6254 "Use addpath to advertise all paths to a neighbor\n")
6255{
d62a17ae 6256 int idx_peer = 2;
dcc68b5e
MS
6257 struct peer *peer;
6258
6259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6260 if (!peer)
6261 return CMD_WARNING_CONFIG_FAILED;
6262
6263 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6264 != BGP_ADDPATH_ALL) {
6265 vty_out(vty,
6266 "%% Peer not currently configured to transmit all paths.");
6267 return CMD_WARNING_CONFIG_FAILED;
6268 }
6269
6270 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6271 BGP_ADDPATH_NONE);
6272
6273 return CMD_SUCCESS;
adbac85e
DW
6274}
6275
d62a17ae 6276ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6277 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6280 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6281
06370dac
DW
6282DEFUN (neighbor_addpath_tx_bestpath_per_as,
6283 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6284 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Use addpath to advertise the bestpath per each neighboring AS\n")
6288{
d62a17ae 6289 int idx_peer = 1;
6290 struct peer *peer;
06370dac 6291
d62a17ae 6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
06370dac 6295
dcc68b5e
MS
6296 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6297 BGP_ADDPATH_BEST_PER_AS);
6298
6299 return CMD_SUCCESS;
06370dac
DW
6300}
6301
d62a17ae 6302ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6303 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6304 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6305 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6306 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6307
06370dac
DW
6308DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6309 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6311 NO_STR
6312 NEIGHBOR_STR
6313 NEIGHBOR_ADDR_STR2
6314 "Use addpath to advertise the bestpath per each neighboring AS\n")
6315{
d62a17ae 6316 int idx_peer = 2;
dcc68b5e
MS
6317 struct peer *peer;
6318
6319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6320 if (!peer)
6321 return CMD_WARNING_CONFIG_FAILED;
6322
6323 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6324 != BGP_ADDPATH_BEST_PER_AS) {
6325 vty_out(vty,
6326 "%% Peer not currently configured to transmit all best path per as.");
6327 return CMD_WARNING_CONFIG_FAILED;
6328 }
6329
6330 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6331 BGP_ADDPATH_NONE);
6332
6333 return CMD_SUCCESS;
06370dac
DW
6334}
6335
d62a17ae 6336ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6337 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6338 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6339 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6340 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6341
b9c7bc5a
PZ
6342static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6343 struct ecommunity **list)
ddb5b488 6344{
b9c7bc5a
PZ
6345 struct ecommunity *ecom = NULL;
6346 struct ecommunity *ecomadd;
ddb5b488 6347
b9c7bc5a 6348 for (; argc; --argc, ++argv) {
ddb5b488 6349
b9c7bc5a
PZ
6350 ecomadd = ecommunity_str2com(argv[0]->arg,
6351 ECOMMUNITY_ROUTE_TARGET, 0);
6352 if (!ecomadd) {
6353 vty_out(vty, "Malformed community-list value\n");
6354 if (ecom)
6355 ecommunity_free(&ecom);
6356 return CMD_WARNING_CONFIG_FAILED;
6357 }
ddb5b488 6358
b9c7bc5a
PZ
6359 if (ecom) {
6360 ecommunity_merge(ecom, ecomadd);
6361 ecommunity_free(&ecomadd);
6362 } else {
6363 ecom = ecomadd;
6364 }
6365 }
6366
6367 if (*list) {
6368 ecommunity_free(&*list);
ddb5b488 6369 }
b9c7bc5a
PZ
6370 *list = ecom;
6371
6372 return CMD_SUCCESS;
ddb5b488
PZ
6373}
6374
0ca70ba5
DS
6375/*
6376 * v2vimport is true if we are handling a `import vrf ...` command
6377 */
6378static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6379{
0ca70ba5
DS
6380 afi_t afi;
6381
ddb5b488 6382 switch (vty->node) {
b9c7bc5a 6383 case BGP_IPV4_NODE:
0ca70ba5
DS
6384 afi = AFI_IP;
6385 break;
b9c7bc5a 6386 case BGP_IPV6_NODE:
0ca70ba5
DS
6387 afi = AFI_IP6;
6388 break;
ddb5b488
PZ
6389 default:
6390 vty_out(vty,
b9c7bc5a 6391 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6392 return AFI_MAX;
ddb5b488 6393 }
69b07479 6394
0ca70ba5
DS
6395 if (!v2vimport) {
6396 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6397 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6398 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6399 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6400 vty_out(vty,
6401 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6402 return AFI_MAX;
6403 }
6404 } else {
6405 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6406 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6407 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6408 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6409 vty_out(vty,
6410 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6411 return AFI_MAX;
6412 }
6413 }
6414 return afi;
ddb5b488
PZ
6415}
6416
b9c7bc5a
PZ
6417DEFPY (af_rd_vpn_export,
6418 af_rd_vpn_export_cmd,
6419 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6420 NO_STR
ddb5b488 6421 "Specify route distinguisher\n"
b9c7bc5a
PZ
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6424 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6425{
6426 VTY_DECLVAR_CONTEXT(bgp, bgp);
6427 struct prefix_rd prd;
6428 int ret;
ddb5b488 6429 afi_t afi;
b9c7bc5a
PZ
6430 int idx = 0;
6431 int yes = 1;
ddb5b488 6432
b9c7bc5a 6433 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6434 yes = 0;
b9c7bc5a
PZ
6435
6436 if (yes) {
6437 ret = str2prefix_rd(rd_str, &prd);
6438 if (!ret) {
6439 vty_out(vty, "%% Malformed rd\n");
6440 return CMD_WARNING_CONFIG_FAILED;
6441 }
ddb5b488
PZ
6442 }
6443
0ca70ba5 6444 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6445 if (afi == AFI_MAX)
6446 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6447
69b07479
DS
6448 /*
6449 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6450 */
6451 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6452 bgp_get_default(), bgp);
ddb5b488 6453
69b07479
DS
6454 if (yes) {
6455 bgp->vpn_policy[afi].tovpn_rd = prd;
6456 SET_FLAG(bgp->vpn_policy[afi].flags,
6457 BGP_VPN_POLICY_TOVPN_RD_SET);
6458 } else {
6459 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6460 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6461 }
6462
69b07479
DS
6463 /* post-change: re-export vpn routes */
6464 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6465 bgp_get_default(), bgp);
6466
ddb5b488
PZ
6467 return CMD_SUCCESS;
6468}
6469
b9c7bc5a
PZ
6470ALIAS (af_rd_vpn_export,
6471 af_no_rd_vpn_export_cmd,
6472 "no rd vpn export",
ddb5b488 6473 NO_STR
b9c7bc5a
PZ
6474 "Specify route distinguisher\n"
6475 "Between current address-family and vpn\n"
6476 "For routes leaked from current address-family to vpn\n")
ddb5b488 6477
b9c7bc5a
PZ
6478DEFPY (af_label_vpn_export,
6479 af_label_vpn_export_cmd,
e70e9f8e 6480 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6481 NO_STR
ddb5b488 6482 "label value for VRF\n"
b9c7bc5a
PZ
6483 "Between current address-family and vpn\n"
6484 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6485 "Label Value <0-1048575>\n"
6486 "Automatically assign a label\n")
ddb5b488
PZ
6487{
6488 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6489 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6490 afi_t afi;
b9c7bc5a
PZ
6491 int idx = 0;
6492 int yes = 1;
6493
6494 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6495 yes = 0;
ddb5b488 6496
21a16cc2
PZ
6497 /* If "no ...", squash trailing parameter */
6498 if (!yes)
6499 label_auto = NULL;
6500
e70e9f8e
PZ
6501 if (yes) {
6502 if (!label_auto)
6503 label = label_val; /* parser should force unsigned */
6504 }
ddb5b488 6505
0ca70ba5 6506 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6507 if (afi == AFI_MAX)
6508 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6509
e70e9f8e 6510
69b07479
DS
6511 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6512 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6513 /* no change */
6514 return CMD_SUCCESS;
e70e9f8e 6515
69b07479
DS
6516 /*
6517 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6518 */
6519 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6520 bgp_get_default(), bgp);
6521
6522 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6523 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6524
6525 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6526
6527 /*
6528 * label has previously been automatically
6529 * assigned by labelpool: release it
6530 *
6531 * NB if tovpn_label == MPLS_LABEL_NONE it
6532 * means the automatic assignment is in flight
6533 * and therefore the labelpool callback must
6534 * detect that the auto label is not needed.
6535 */
6536
6537 bgp_lp_release(LP_TYPE_VRF,
6538 &bgp->vpn_policy[afi],
6539 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6540 }
69b07479
DS
6541 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6542 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6543 }
ddb5b488 6544
69b07479
DS
6545 bgp->vpn_policy[afi].tovpn_label = label;
6546 if (label_auto) {
6547 SET_FLAG(bgp->vpn_policy[afi].flags,
6548 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6549 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6550 vpn_leak_label_callback);
ddb5b488
PZ
6551 }
6552
69b07479
DS
6553 /* post-change: re-export vpn routes */
6554 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6555 bgp_get_default(), bgp);
6556
ddb5b488
PZ
6557 return CMD_SUCCESS;
6558}
6559
b9c7bc5a
PZ
6560ALIAS (af_label_vpn_export,
6561 af_no_label_vpn_export_cmd,
6562 "no label vpn export",
6563 NO_STR
6564 "label value for VRF\n"
6565 "Between current address-family and vpn\n"
6566 "For routes leaked from current address-family to vpn\n")
ddb5b488 6567
b9c7bc5a
PZ
6568DEFPY (af_nexthop_vpn_export,
6569 af_nexthop_vpn_export_cmd,
6570 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6571 NO_STR
ddb5b488 6572 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6573 "Between current address-family and vpn\n"
6574 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6575 "IPv4 prefix\n"
6576 "IPv6 prefix\n")
6577{
6578 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6579 afi_t afi;
ddb5b488 6580 struct prefix p;
b9c7bc5a
PZ
6581 int idx = 0;
6582 int yes = 1;
ddb5b488 6583
b9c7bc5a 6584 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6585 yes = 0;
b9c7bc5a
PZ
6586
6587 if (yes) {
6588 if (!sockunion2hostprefix(nexthop_str, &p))
6589 return CMD_WARNING_CONFIG_FAILED;
6590 }
ddb5b488 6591
0ca70ba5 6592 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6593 if (afi == AFI_MAX)
6594 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6595
69b07479
DS
6596 /*
6597 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6598 */
6599 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6600 bgp_get_default(), bgp);
ddb5b488 6601
69b07479
DS
6602 if (yes) {
6603 bgp->vpn_policy[afi].tovpn_nexthop = p;
6604 SET_FLAG(bgp->vpn_policy[afi].flags,
6605 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6606 } else {
6607 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6608 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6609 }
6610
69b07479
DS
6611 /* post-change: re-export vpn routes */
6612 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6613 bgp_get_default(), bgp);
6614
ddb5b488
PZ
6615 return CMD_SUCCESS;
6616}
6617
b9c7bc5a
PZ
6618ALIAS (af_nexthop_vpn_export,
6619 af_no_nexthop_vpn_export_cmd,
6620 "no nexthop vpn export",
ddb5b488 6621 NO_STR
b9c7bc5a
PZ
6622 "Specify next hop to use for VRF advertised prefixes\n"
6623 "Between current address-family and vpn\n"
6624 "For routes leaked from current address-family to vpn\n")
ddb5b488 6625
b9c7bc5a 6626static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6627{
b9c7bc5a
PZ
6628 if (!strcmp(dstr, "import")) {
6629 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6630 } else if (!strcmp(dstr, "export")) {
6631 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6632 } else if (!strcmp(dstr, "both")) {
6633 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6634 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6635 } else {
6636 vty_out(vty, "%% direction parse error\n");
6637 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6638 }
ddb5b488
PZ
6639 return CMD_SUCCESS;
6640}
6641
b9c7bc5a
PZ
6642DEFPY (af_rt_vpn_imexport,
6643 af_rt_vpn_imexport_cmd,
6644 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6645 NO_STR
6646 "Specify route target list\n"
ddb5b488 6647 "Specify route target list\n"
b9c7bc5a
PZ
6648 "Between current address-family and vpn\n"
6649 "For routes leaked from vpn to current address-family: match any\n"
6650 "For routes leaked from current address-family to vpn: set\n"
6651 "both import: match any and export: set\n"
ddb5b488
PZ
6652 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6653{
6654 VTY_DECLVAR_CONTEXT(bgp, bgp);
6655 int ret;
6656 struct ecommunity *ecom = NULL;
6657 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6658 vpn_policy_direction_t dir;
6659 afi_t afi;
6660 int idx = 0;
b9c7bc5a 6661 int yes = 1;
ddb5b488 6662
b9c7bc5a 6663 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6664 yes = 0;
b9c7bc5a 6665
0ca70ba5 6666 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6667 if (afi == AFI_MAX)
6668 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6669
b9c7bc5a 6670 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6671 if (ret != CMD_SUCCESS)
6672 return ret;
6673
b9c7bc5a
PZ
6674 if (yes) {
6675 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6676 vty_out(vty, "%% Missing RTLIST\n");
6677 return CMD_WARNING_CONFIG_FAILED;
6678 }
6679 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6680 if (ret != CMD_SUCCESS) {
6681 return ret;
6682 }
ddb5b488
PZ
6683 }
6684
69b07479
DS
6685 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6686 if (!dodir[dir])
ddb5b488 6687 continue;
ddb5b488 6688
69b07479 6689 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6690
69b07479
DS
6691 if (yes) {
6692 if (bgp->vpn_policy[afi].rtlist[dir])
6693 ecommunity_free(
6694 &bgp->vpn_policy[afi].rtlist[dir]);
6695 bgp->vpn_policy[afi].rtlist[dir] =
6696 ecommunity_dup(ecom);
6697 } else {
6698 if (bgp->vpn_policy[afi].rtlist[dir])
6699 ecommunity_free(
6700 &bgp->vpn_policy[afi].rtlist[dir]);
6701 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6702 }
69b07479
DS
6703
6704 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6705 }
69b07479 6706
d555f3e9
PZ
6707 if (ecom)
6708 ecommunity_free(&ecom);
ddb5b488
PZ
6709
6710 return CMD_SUCCESS;
6711}
6712
b9c7bc5a
PZ
6713ALIAS (af_rt_vpn_imexport,
6714 af_no_rt_vpn_imexport_cmd,
6715 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6716 NO_STR
6717 "Specify route target list\n"
b9c7bc5a
PZ
6718 "Specify route target list\n"
6719 "Between current address-family and vpn\n"
6720 "For routes leaked from vpn to current address-family\n"
6721 "For routes leaked from current address-family to vpn\n"
6722 "both import and export\n")
6723
6724DEFPY (af_route_map_vpn_imexport,
6725 af_route_map_vpn_imexport_cmd,
6726/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6727 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6728 NO_STR
ddb5b488 6729 "Specify route map\n"
b9c7bc5a
PZ
6730 "Between current address-family and vpn\n"
6731 "For routes leaked from vpn to current address-family\n"
6732 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6733 "name of route-map\n")
6734{
6735 VTY_DECLVAR_CONTEXT(bgp, bgp);
6736 int ret;
6737 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6738 vpn_policy_direction_t dir;
6739 afi_t afi;
ddb5b488 6740 int idx = 0;
b9c7bc5a 6741 int yes = 1;
ddb5b488 6742
b9c7bc5a 6743 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6744 yes = 0;
b9c7bc5a 6745
0ca70ba5 6746 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6747 if (afi == AFI_MAX)
6748 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6749
b9c7bc5a 6750 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6751 if (ret != CMD_SUCCESS)
6752 return ret;
6753
69b07479
DS
6754 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6755 if (!dodir[dir])
ddb5b488 6756 continue;
ddb5b488 6757
69b07479 6758 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6759
69b07479
DS
6760 if (yes) {
6761 if (bgp->vpn_policy[afi].rmap_name[dir])
6762 XFREE(MTYPE_ROUTE_MAP_NAME,
6763 bgp->vpn_policy[afi].rmap_name[dir]);
6764 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6765 MTYPE_ROUTE_MAP_NAME, rmap_str);
6766 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6767 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6768 if (!bgp->vpn_policy[afi].rmap[dir])
6769 return CMD_SUCCESS;
6770 } else {
6771 if (bgp->vpn_policy[afi].rmap_name[dir])
6772 XFREE(MTYPE_ROUTE_MAP_NAME,
6773 bgp->vpn_policy[afi].rmap_name[dir]);
6774 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6775 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6776 }
69b07479
DS
6777
6778 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6779 }
6780
6781 return CMD_SUCCESS;
6782}
6783
b9c7bc5a
PZ
6784ALIAS (af_route_map_vpn_imexport,
6785 af_no_route_map_vpn_imexport_cmd,
6786 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6787 NO_STR
6788 "Specify route map\n"
b9c7bc5a
PZ
6789 "Between current address-family and vpn\n"
6790 "For routes leaked from vpn to current address-family\n"
6791 "For routes leaked from current address-family to vpn\n")
6792
bb4f6190
DS
6793DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6794 "[no] import vrf route-map RMAP$rmap_str",
6795 NO_STR
6796 "Import routes from another VRF\n"
6797 "Vrf routes being filtered\n"
6798 "Specify route map\n"
6799 "name of route-map\n")
6800{
6801 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6802 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6803 afi_t afi;
6804 int idx = 0;
6805 int yes = 1;
6806 struct bgp *bgp_default;
6807
6808 if (argv_find(argv, argc, "no", &idx))
6809 yes = 0;
6810
0ca70ba5 6811 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6812 if (afi == AFI_MAX)
6813 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6814
6815 bgp_default = bgp_get_default();
6816 if (!bgp_default) {
6817 int32_t ret;
6818 as_t as = bgp->as;
6819
6820 /* Auto-create assuming the same AS */
6821 ret = bgp_get(&bgp_default, &as, NULL,
6822 BGP_INSTANCE_TYPE_DEFAULT);
6823
6824 if (ret) {
6825 vty_out(vty,
6826 "VRF default is not configured as a bgp instance\n");
6827 return CMD_WARNING;
6828 }
6829 }
6830
69b07479 6831 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6832
69b07479
DS
6833 if (yes) {
6834 if (bgp->vpn_policy[afi].rmap_name[dir])
6835 XFREE(MTYPE_ROUTE_MAP_NAME,
6836 bgp->vpn_policy[afi].rmap_name[dir]);
6837 bgp->vpn_policy[afi].rmap_name[dir] =
6838 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6839 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6840 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6841 if (!bgp->vpn_policy[afi].rmap[dir])
6842 return CMD_SUCCESS;
6843 } else {
6844 if (bgp->vpn_policy[afi].rmap_name[dir])
6845 XFREE(MTYPE_ROUTE_MAP_NAME,
6846 bgp->vpn_policy[afi].rmap_name[dir]);
6847 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6848 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6849 }
6850
69b07479
DS
6851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6852
bb4f6190
DS
6853 return CMD_SUCCESS;
6854}
6855
6856ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6857 "no import vrf route-map",
6858 NO_STR
6859 "Import routes from another VRF\n"
6860 "Vrf routes being filtered\n"
6861 "Specify route map\n")
6862
4d1b335c
DA
6863DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6864 "[no] import vrf VIEWVRFNAME$import_name",
6865 NO_STR
6866 "Import routes from another VRF\n"
6867 "VRF to import from\n"
6868 "The name of the VRF\n")
12a844a5
DS
6869{
6870 VTY_DECLVAR_CONTEXT(bgp, bgp);
6871 struct listnode *node;
79ef8664
DS
6872 struct bgp *vrf_bgp, *bgp_default;
6873 int32_t ret = 0;
6874 as_t as = bgp->as;
12a844a5
DS
6875 bool remove = false;
6876 int32_t idx = 0;
6877 char *vname;
a8dadcf6 6878 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6879 safi_t safi;
6880 afi_t afi;
6881
867f0cca 6882 if (import_name == NULL) {
6883 vty_out(vty, "%% Missing import name\n");
6884 return CMD_WARNING;
6885 }
6886
12a844a5
DS
6887 if (argv_find(argv, argc, "no", &idx))
6888 remove = true;
6889
0ca70ba5
DS
6890 afi = vpn_policy_getafi(vty, bgp, true);
6891 if (afi == AFI_MAX)
6892 return CMD_WARNING_CONFIG_FAILED;
6893
12a844a5
DS
6894 safi = bgp_node_safi(vty);
6895
25679caa 6896 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6897 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6898 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6899 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6900 remove ? "unimport" : "import", import_name);
6901 return CMD_WARNING;
6902 }
6903
79ef8664
DS
6904 bgp_default = bgp_get_default();
6905 if (!bgp_default) {
6906 /* Auto-create assuming the same AS */
6907 ret = bgp_get(&bgp_default, &as, NULL,
6908 BGP_INSTANCE_TYPE_DEFAULT);
6909
6910 if (ret) {
6911 vty_out(vty,
6912 "VRF default is not configured as a bgp instance\n");
6913 return CMD_WARNING;
6914 }
6915 }
6916
12a844a5
DS
6917 vrf_bgp = bgp_lookup_by_name(import_name);
6918 if (!vrf_bgp) {
5742e42b 6919 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6920 vrf_bgp = bgp_default;
6921 else
0fb8d6e6
DS
6922 /* Auto-create assuming the same AS */
6923 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6924
6e2c7fe6 6925 if (ret) {
020a3f60
DS
6926 vty_out(vty,
6927 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6928 import_name);
6929 return CMD_WARNING;
6930 }
12a844a5
DS
6931 }
6932
12a844a5 6933 if (remove) {
44338987 6934 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6935 } else {
44338987 6936 /* Already importing from "import_vrf"? */
12a844a5
DS
6937 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6938 vname)) {
6939 if (strcmp(vname, import_name) == 0)
6940 return CMD_WARNING;
6941 }
6942
44338987 6943 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6944 }
6945
6946 return CMD_SUCCESS;
6947}
6948
b9c7bc5a
PZ
6949/* This command is valid only in a bgp vrf instance or the default instance */
6950DEFPY (bgp_imexport_vpn,
6951 bgp_imexport_vpn_cmd,
6952 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6953 NO_STR
6954 "Import routes to this address-family\n"
6955 "Export routes from this address-family\n"
6956 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6957{
6958 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6959 int previous_state;
ddb5b488 6960 afi_t afi;
b9c7bc5a 6961 safi_t safi;
ddb5b488 6962 int idx = 0;
b9c7bc5a
PZ
6963 int yes = 1;
6964 int flag;
6965 vpn_policy_direction_t dir;
ddb5b488 6966
b9c7bc5a 6967 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6968 yes = 0;
ddb5b488 6969
b9c7bc5a
PZ
6970 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6971 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6972
b9c7bc5a
PZ
6973 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6974 return CMD_WARNING_CONFIG_FAILED;
6975 }
ddb5b488 6976
b9c7bc5a
PZ
6977 afi = bgp_node_afi(vty);
6978 safi = bgp_node_safi(vty);
6979 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6980 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6981 return CMD_WARNING_CONFIG_FAILED;
6982 }
ddb5b488 6983
b9c7bc5a
PZ
6984 if (!strcmp(direction_str, "import")) {
6985 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6986 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6987 } else if (!strcmp(direction_str, "export")) {
6988 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6989 dir = BGP_VPN_POLICY_DIR_TOVPN;
6990 } else {
6991 vty_out(vty, "%% unknown direction %s\n", direction_str);
6992 return CMD_WARNING_CONFIG_FAILED;
6993 }
6994
6995 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6996
b9c7bc5a
PZ
6997 if (yes) {
6998 SET_FLAG(bgp->af_flags[afi][safi], flag);
6999 if (!previous_state) {
7000 /* trigger export current vrf */
ddb5b488
PZ
7001 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7002 }
b9c7bc5a
PZ
7003 } else {
7004 if (previous_state) {
7005 /* trigger un-export current vrf */
7006 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7007 }
7008 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7009 }
7010
7011 return CMD_SUCCESS;
7012}
7013
301ad80a
PG
7014DEFPY (af_routetarget_import,
7015 af_routetarget_import_cmd,
7016 "[no] <rt|route-target> redirect import RTLIST...",
7017 NO_STR
7018 "Specify route target list\n"
7019 "Specify route target list\n"
7020 "Flow-spec redirect type route target\n"
7021 "Import routes to this address-family\n"
7022 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7023{
7024 VTY_DECLVAR_CONTEXT(bgp, bgp);
7025 int ret;
7026 struct ecommunity *ecom = NULL;
301ad80a
PG
7027 afi_t afi;
7028 int idx = 0;
7029 int yes = 1;
7030
7031 if (argv_find(argv, argc, "no", &idx))
7032 yes = 0;
7033
0ca70ba5 7034 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7035 if (afi == AFI_MAX)
7036 return CMD_WARNING_CONFIG_FAILED;
7037
301ad80a
PG
7038 if (yes) {
7039 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7040 vty_out(vty, "%% Missing RTLIST\n");
7041 return CMD_WARNING_CONFIG_FAILED;
7042 }
7043 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7044 if (ret != CMD_SUCCESS)
7045 return ret;
7046 }
69b07479
DS
7047
7048 if (yes) {
7049 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7050 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7051 .import_redirect_rtlist);
69b07479
DS
7052 bgp->vpn_policy[afi].import_redirect_rtlist =
7053 ecommunity_dup(ecom);
7054 } else {
7055 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7056 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7057 .import_redirect_rtlist);
69b07479 7058 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7059 }
69b07479 7060
301ad80a
PG
7061 if (ecom)
7062 ecommunity_free(&ecom);
7063
7064 return CMD_SUCCESS;
7065}
7066
505e5056 7067DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7068 address_family_ipv4_safi_cmd,
7069 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7070 "Enter Address Family command mode\n"
7071 "Address Family\n"
7072 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7073{
f51bae9c 7074
d62a17ae 7075 if (argc == 3) {
2131d5cf 7076 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7077 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7078 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7079 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7080 && safi != SAFI_EVPN) {
31947174
MK
7081 vty_out(vty,
7082 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7083 return CMD_WARNING_CONFIG_FAILED;
7084 }
d62a17ae 7085 vty->node = bgp_node_type(AFI_IP, safi);
7086 } else
7087 vty->node = BGP_IPV4_NODE;
718e3744 7088
d62a17ae 7089 return CMD_SUCCESS;
718e3744 7090}
7091
505e5056 7092DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7093 address_family_ipv6_safi_cmd,
7094 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7095 "Enter Address Family command mode\n"
7096 "Address Family\n"
7097 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7098{
d62a17ae 7099 if (argc == 3) {
2131d5cf 7100 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7101 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7102 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7103 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7104 && safi != SAFI_EVPN) {
31947174
MK
7105 vty_out(vty,
7106 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7107 return CMD_WARNING_CONFIG_FAILED;
7108 }
d62a17ae 7109 vty->node = bgp_node_type(AFI_IP6, safi);
7110 } else
7111 vty->node = BGP_IPV6_NODE;
25ffbdc1 7112
d62a17ae 7113 return CMD_SUCCESS;
25ffbdc1 7114}
718e3744 7115
d6902373 7116#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7117DEFUN_NOSH (address_family_vpnv4,
718e3744 7118 address_family_vpnv4_cmd,
8334fd5a 7119 "address-family vpnv4 [unicast]",
718e3744 7120 "Enter Address Family command mode\n"
8c3deaae 7121 "Address Family\n"
3a2d747c 7122 "Address Family modifier\n")
718e3744 7123{
d62a17ae 7124 vty->node = BGP_VPNV4_NODE;
7125 return CMD_SUCCESS;
718e3744 7126}
7127
505e5056 7128DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7129 address_family_vpnv6_cmd,
8334fd5a 7130 "address-family vpnv6 [unicast]",
8ecd3266 7131 "Enter Address Family command mode\n"
8c3deaae 7132 "Address Family\n"
3a2d747c 7133 "Address Family modifier\n")
8ecd3266 7134{
d62a17ae 7135 vty->node = BGP_VPNV6_NODE;
7136 return CMD_SUCCESS;
8ecd3266 7137}
c016b6c7 7138#endif
d6902373 7139
505e5056 7140DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7141 address_family_evpn_cmd,
7111c1a0 7142 "address-family l2vpn evpn",
4e0b7b6d 7143 "Enter Address Family command mode\n"
7111c1a0
QY
7144 "Address Family\n"
7145 "Address Family modifier\n")
4e0b7b6d 7146{
2131d5cf 7147 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7148 vty->node = BGP_EVPN_NODE;
7149 return CMD_SUCCESS;
4e0b7b6d
PG
7150}
7151
505e5056 7152DEFUN_NOSH (exit_address_family,
718e3744 7153 exit_address_family_cmd,
7154 "exit-address-family",
7155 "Exit from Address Family configuration mode\n")
7156{
d62a17ae 7157 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7158 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7159 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7160 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7161 || vty->node == BGP_EVPN_NODE
7162 || vty->node == BGP_FLOWSPECV4_NODE
7163 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7164 vty->node = BGP_NODE;
7165 return CMD_SUCCESS;
718e3744 7166}
6b0655a2 7167
8ad7271d 7168/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7169static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7170 const char *ip_str, afi_t afi, safi_t safi,
7171 struct prefix_rd *prd)
7172{
7173 int ret;
7174 struct prefix match;
7175 struct bgp_node *rn;
7176 struct bgp_node *rm;
7177 struct bgp *bgp;
7178 struct bgp_table *table;
7179 struct bgp_table *rib;
7180
7181 /* BGP structure lookup. */
7182 if (view_name) {
7183 bgp = bgp_lookup_by_name(view_name);
7184 if (bgp == NULL) {
7185 vty_out(vty, "%% Can't find BGP instance %s\n",
7186 view_name);
7187 return CMD_WARNING;
7188 }
7189 } else {
7190 bgp = bgp_get_default();
7191 if (bgp == NULL) {
7192 vty_out(vty, "%% No BGP process is configured\n");
7193 return CMD_WARNING;
7194 }
7195 }
7196
7197 /* Check IP address argument. */
7198 ret = str2prefix(ip_str, &match);
7199 if (!ret) {
7200 vty_out(vty, "%% address is malformed\n");
7201 return CMD_WARNING;
7202 }
7203
7204 match.family = afi2family(afi);
7205 rib = bgp->rib[afi][safi];
7206
7207 if (safi == SAFI_MPLS_VPN) {
7208 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7209 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7210 continue;
7211
7212 if ((table = rn->info) != NULL) {
7213 if ((rm = bgp_node_match(table, &match))
7214 != NULL) {
7215 if (rm->p.prefixlen
7216 == match.prefixlen) {
343cdb61 7217 SET_FLAG(rm->flags,
d62a17ae 7218 BGP_NODE_USER_CLEAR);
7219 bgp_process(bgp, rm, afi, safi);
7220 }
7221 bgp_unlock_node(rm);
7222 }
7223 }
7224 }
7225 } else {
7226 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7227 if (rn->p.prefixlen == match.prefixlen) {
7228 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7229 bgp_process(bgp, rn, afi, safi);
7230 }
7231 bgp_unlock_node(rn);
7232 }
7233 }
7234
7235 return CMD_SUCCESS;
8ad7271d
DS
7236}
7237
b09b5ae0 7238/* one clear bgp command to rule them all */
718e3744 7239DEFUN (clear_ip_bgp_all,
7240 clear_ip_bgp_all_cmd,
c1a44e43 7241 "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 7242 CLEAR_STR
7243 IP_STR
7244 BGP_STR
838758ac 7245 BGP_INSTANCE_HELP_STR
510afcd6
DS
7246 BGP_AFI_HELP_STR
7247 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
7248 "Clear all peers\n"
7249 "BGP neighbor address to clear\n"
a80beece 7250 "BGP IPv6 neighbor to clear\n"
838758ac 7251 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7252 "Clear peers with the AS number\n"
7253 "Clear all external peers\n"
718e3744 7254 "Clear all members of peer-group\n"
b09b5ae0 7255 "BGP peer-group name\n"
b09b5ae0
DW
7256 BGP_SOFT_STR
7257 BGP_SOFT_IN_STR
b09b5ae0
DW
7258 BGP_SOFT_OUT_STR
7259 BGP_SOFT_IN_STR
7260 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7261 BGP_SOFT_OUT_STR)
718e3744 7262{
d62a17ae 7263 char *vrf = NULL;
7264
7265 afi_t afi = AFI_IP6;
7266 safi_t safi = SAFI_UNICAST;
7267 enum clear_sort clr_sort = clear_peer;
7268 enum bgp_clear_type clr_type;
7269 char *clr_arg = NULL;
7270
7271 int idx = 0;
7272
7273 /* clear [ip] bgp */
7274 if (argv_find(argv, argc, "ip", &idx))
7275 afi = AFI_IP;
7276
9a8bdf1c
PG
7277 /* [<vrf> VIEWVRFNAME] */
7278 if (argv_find(argv, argc, "vrf", &idx)) {
7279 vrf = argv[idx + 1]->arg;
7280 idx += 2;
7281 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7282 vrf = NULL;
7283 } else if (argv_find(argv, argc, "view", &idx)) {
7284 /* [<view> VIEWVRFNAME] */
d62a17ae 7285 vrf = argv[idx + 1]->arg;
7286 idx += 2;
7287 }
d62a17ae 7288 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7289 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7290 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7291
7292 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7293 if (argv_find(argv, argc, "*", &idx)) {
7294 clr_sort = clear_all;
7295 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7296 clr_sort = clear_peer;
7297 clr_arg = argv[idx]->arg;
7298 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7299 clr_sort = clear_peer;
7300 clr_arg = argv[idx]->arg;
7301 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7302 clr_sort = clear_group;
7303 idx++;
7304 clr_arg = argv[idx]->arg;
7305 } else if (argv_find(argv, argc, "WORD", &idx)) {
7306 clr_sort = clear_peer;
7307 clr_arg = argv[idx]->arg;
7308 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7309 clr_sort = clear_as;
7310 clr_arg = argv[idx]->arg;
7311 } else if (argv_find(argv, argc, "external", &idx)) {
7312 clr_sort = clear_external;
7313 }
7314
7315 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7316 if (argv_find(argv, argc, "soft", &idx)) {
7317 if (argv_find(argv, argc, "in", &idx)
7318 || argv_find(argv, argc, "out", &idx))
7319 clr_type = strmatch(argv[idx]->text, "in")
7320 ? BGP_CLEAR_SOFT_IN
7321 : BGP_CLEAR_SOFT_OUT;
7322 else
7323 clr_type = BGP_CLEAR_SOFT_BOTH;
7324 } else if (argv_find(argv, argc, "in", &idx)) {
7325 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7326 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7327 : BGP_CLEAR_SOFT_IN;
7328 } else if (argv_find(argv, argc, "out", &idx)) {
7329 clr_type = BGP_CLEAR_SOFT_OUT;
7330 } else
7331 clr_type = BGP_CLEAR_SOFT_NONE;
7332
7333 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7334}
01080f7c 7335
8ad7271d
DS
7336DEFUN (clear_ip_bgp_prefix,
7337 clear_ip_bgp_prefix_cmd,
18c57037 7338 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7339 CLEAR_STR
7340 IP_STR
7341 BGP_STR
838758ac 7342 BGP_INSTANCE_HELP_STR
8ad7271d 7343 "Clear bestpath and re-advertise\n"
0c7b1b01 7344 "IPv4 prefix\n")
8ad7271d 7345{
d62a17ae 7346 char *vrf = NULL;
7347 char *prefix = NULL;
8ad7271d 7348
d62a17ae 7349 int idx = 0;
01080f7c 7350
d62a17ae 7351 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7352 if (argv_find(argv, argc, "vrf", &idx)) {
7353 vrf = argv[idx + 1]->arg;
7354 idx += 2;
7355 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7356 vrf = NULL;
7357 } else if (argv_find(argv, argc, "view", &idx)) {
7358 /* [<view> VIEWVRFNAME] */
7359 vrf = argv[idx + 1]->arg;
7360 idx += 2;
7361 }
0c7b1b01 7362
d62a17ae 7363 prefix = argv[argc - 1]->arg;
8ad7271d 7364
d62a17ae 7365 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7366}
8ad7271d 7367
b09b5ae0
DW
7368DEFUN (clear_bgp_ipv6_safi_prefix,
7369 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7370 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7371 CLEAR_STR
3a2d747c 7372 IP_STR
718e3744 7373 BGP_STR
8c3deaae 7374 "Address Family\n"
46f296b4 7375 BGP_SAFI_HELP_STR
b09b5ae0 7376 "Clear bestpath and re-advertise\n"
0c7b1b01 7377 "IPv6 prefix\n")
718e3744 7378{
9b475e76
PG
7379 int idx_safi = 0;
7380 int idx_ipv6_prefix = 0;
7381 safi_t safi = SAFI_UNICAST;
7382 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7383 argv[idx_ipv6_prefix]->arg : NULL;
7384
7385 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7386 return bgp_clear_prefix(
9b475e76
PG
7387 vty, NULL, prefix, AFI_IP6,
7388 safi, NULL);
838758ac 7389}
01080f7c 7390
b09b5ae0
DW
7391DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7392 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7393 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7394 CLEAR_STR
3a2d747c 7395 IP_STR
718e3744 7396 BGP_STR
838758ac 7397 BGP_INSTANCE_HELP_STR
8c3deaae 7398 "Address Family\n"
46f296b4 7399 BGP_SAFI_HELP_STR
b09b5ae0 7400 "Clear bestpath and re-advertise\n"
0c7b1b01 7401 "IPv6 prefix\n")
718e3744 7402{
9b475e76 7403 int idx_safi = 0;
9a8bdf1c 7404 int idx_vrfview = 0;
9b475e76
PG
7405 int idx_ipv6_prefix = 0;
7406 safi_t safi = SAFI_UNICAST;
7407 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7408 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7409 char *vrfview = NULL;
9b475e76 7410
9a8bdf1c
PG
7411 /* [<view|vrf> VIEWVRFNAME] */
7412 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7413 vrfview = argv[idx_vrfview + 1]->arg;
7414 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7415 vrfview = NULL;
7416 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7417 /* [<view> VIEWVRFNAME] */
7418 vrfview = argv[idx_vrfview + 1]->arg;
7419 }
9b475e76
PG
7420 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7421
d62a17ae 7422 return bgp_clear_prefix(
9b475e76
PG
7423 vty, vrfview, prefix,
7424 AFI_IP6, safi, NULL);
718e3744 7425}
7426
b09b5ae0
DW
7427DEFUN (show_bgp_views,
7428 show_bgp_views_cmd,
d6e3c605 7429 "show [ip] bgp views",
b09b5ae0 7430 SHOW_STR
d6e3c605 7431 IP_STR
01080f7c 7432 BGP_STR
b09b5ae0 7433 "Show the defined BGP views\n")
01080f7c 7434{
d62a17ae 7435 struct list *inst = bm->bgp;
7436 struct listnode *node;
7437 struct bgp *bgp;
01080f7c 7438
d62a17ae 7439 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7440 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7441 return CMD_WARNING;
7442 }
e52702f2 7443
d62a17ae 7444 vty_out(vty, "Defined BGP views:\n");
7445 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7446 /* Skip VRFs. */
7447 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7448 continue;
7449 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7450 bgp->as);
7451 }
e52702f2 7452
d62a17ae 7453 return CMD_SUCCESS;
e0081f70
ML
7454}
7455
8386ac43 7456DEFUN (show_bgp_vrfs,
7457 show_bgp_vrfs_cmd,
d6e3c605 7458 "show [ip] bgp vrfs [json]",
8386ac43 7459 SHOW_STR
d6e3c605 7460 IP_STR
8386ac43 7461 BGP_STR
7462 "Show BGP VRFs\n"
9973d184 7463 JSON_STR)
8386ac43 7464{
fe1dc5a3 7465 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7466 struct list *inst = bm->bgp;
7467 struct listnode *node;
7468 struct bgp *bgp;
9f049418 7469 bool uj = use_json(argc, argv);
d62a17ae 7470 json_object *json = NULL;
7471 json_object *json_vrfs = NULL;
7472 int count = 0;
d62a17ae 7473
7474 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7475 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7476 return CMD_WARNING;
7477 }
7478
7479 if (uj) {
7480 json = json_object_new_object();
7481 json_vrfs = json_object_new_object();
7482 }
7483
7484 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7485 const char *name, *type;
7486 struct peer *peer;
7fe96307 7487 struct listnode *node2, *nnode2;
d62a17ae 7488 int peers_cfg, peers_estb;
7489 json_object *json_vrf = NULL;
d62a17ae 7490
7491 /* Skip Views. */
7492 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7493 continue;
7494
7495 count++;
7496 if (!uj && count == 1)
fe1dc5a3
MK
7497 vty_out(vty,
7498 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7499 "Type", "Id", "routerId", "#PeersVfg",
7500 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7501
7502 peers_cfg = peers_estb = 0;
7503 if (uj)
7504 json_vrf = json_object_new_object();
7505
7506
7fe96307 7507 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7508 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7509 continue;
7510 peers_cfg++;
7511 if (peer->status == Established)
7512 peers_estb++;
7513 }
7514
7515 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7516 name = VRF_DEFAULT_NAME;
d62a17ae 7517 type = "DFLT";
7518 } else {
7519 name = bgp->name;
7520 type = "VRF";
7521 }
7522
a8bf7d9c 7523
d62a17ae 7524 if (uj) {
a4d82a8a
PZ
7525 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7526 ? -1
7527 : (int64_t)bgp->vrf_id;
d62a17ae 7528 json_object_string_add(json_vrf, "type", type);
7529 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7530 json_object_string_add(json_vrf, "routerId",
7531 inet_ntoa(bgp->router_id));
7532 json_object_int_add(json_vrf, "numConfiguredPeers",
7533 peers_cfg);
7534 json_object_int_add(json_vrf, "numEstablishedPeers",
7535 peers_estb);
7536
fe1dc5a3 7537 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7538 json_object_string_add(
7539 json_vrf, "rmac",
7540 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7541 json_object_object_add(json_vrfs, name, json_vrf);
7542 } else
fe1dc5a3
MK
7543 vty_out(vty,
7544 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7545 type,
7546 bgp->vrf_id == VRF_UNKNOWN ? -1
7547 : (int)bgp->vrf_id,
7548 inet_ntoa(bgp->router_id), peers_cfg,
7549 peers_estb, name, bgp->l3vni,
fe1dc5a3 7550 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7551 }
7552
7553 if (uj) {
7554 json_object_object_add(json, "vrfs", json_vrfs);
7555
7556 json_object_int_add(json, "totalVrfs", count);
7557
996c9314
LB
7558 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7559 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7560 json_object_free(json);
7561 } else {
7562 if (count)
7563 vty_out(vty,
7564 "\nTotal number of VRFs (including default): %d\n",
7565 count);
7566 }
7567
7568 return CMD_SUCCESS;
8386ac43 7569}
7570
acf71666
MK
7571
7572static void show_tip_entry(struct hash_backet *backet, void *args)
7573{
0291c246 7574 struct vty *vty = (struct vty *)args;
60466a63 7575 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7576
60466a63 7577 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7578 tip->refcnt);
7579}
7580
7581static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7582{
7583 vty_out(vty, "self nexthop database:\n");
af97a18b 7584 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7585
7586 vty_out(vty, "Tunnel-ip database:\n");
7587 hash_iterate(bgp->tip_hash,
7588 (void (*)(struct hash_backet *, void *))show_tip_entry,
7589 vty);
7590}
7591
15c81ca4
DS
7592DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7593 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7594 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7595 "martian next-hops\n"
7596 "martian next-hop database\n")
acf71666 7597{
0291c246 7598 struct bgp *bgp = NULL;
15c81ca4 7599 int idx = 0;
9a8bdf1c
PG
7600 char *name = NULL;
7601
7602 /* [<vrf> VIEWVRFNAME] */
7603 if (argv_find(argv, argc, "vrf", &idx)) {
7604 name = argv[idx + 1]->arg;
7605 if (name && strmatch(name, VRF_DEFAULT_NAME))
7606 name = NULL;
7607 } else if (argv_find(argv, argc, "view", &idx))
7608 /* [<view> VIEWVRFNAME] */
7609 name = argv[idx + 1]->arg;
7610 if (name)
7611 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7612 else
7613 bgp = bgp_get_default();
acf71666 7614
acf71666
MK
7615 if (!bgp) {
7616 vty_out(vty, "%% No BGP process is configured\n");
7617 return CMD_WARNING;
7618 }
7619 bgp_show_martian_nexthops(vty, bgp);
7620
7621 return CMD_SUCCESS;
7622}
7623
f412b39a 7624DEFUN (show_bgp_memory,
4bf6a362 7625 show_bgp_memory_cmd,
7fa12b13 7626 "show [ip] bgp memory",
4bf6a362 7627 SHOW_STR
3a2d747c 7628 IP_STR
4bf6a362
PJ
7629 BGP_STR
7630 "Global BGP memory statistics\n")
7631{
d62a17ae 7632 char memstrbuf[MTYPE_MEMSTR_LEN];
7633 unsigned long count;
7634
7635 /* RIB related usage stats */
7636 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7637 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7638 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7639 count * sizeof(struct bgp_node)));
7640
7641 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7642 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7644 count * sizeof(struct bgp_path_info)));
d62a17ae 7645 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7646 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7647 count,
4b7e6066
DS
7648 mtype_memstr(
7649 memstrbuf, sizeof(memstrbuf),
7650 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7651
7652 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7653 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7655 count * sizeof(struct bgp_static)));
7656
7657 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7658 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7659 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7660 count * sizeof(struct bpacket)));
7661
7662 /* Adj-In/Out */
7663 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7664 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7666 count * sizeof(struct bgp_adj_in)));
7667 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7668 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7670 count * sizeof(struct bgp_adj_out)));
7671
7672 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7673 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7674 count,
7675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7676 count * sizeof(struct bgp_nexthop_cache)));
7677
7678 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7679 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7680 count,
7681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7682 count * sizeof(struct bgp_damp_info)));
7683
7684 /* Attributes */
7685 count = attr_count();
7686 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct attr)));
7689
7690 if ((count = attr_unknown_count()))
7691 vty_out(vty, "%ld unknown attributes\n", count);
7692
7693 /* AS_PATH attributes */
7694 count = aspath_count();
7695 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7696 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7697 count * sizeof(struct aspath)));
7698
7699 count = mtype_stats_alloc(MTYPE_AS_SEG);
7700 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7702 count * sizeof(struct assegment)));
7703
7704 /* Other attributes */
7705 if ((count = community_count()))
7706 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7707 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct community)));
d62a17ae 7709 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7710 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7711 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7712 count * sizeof(struct ecommunity)));
d62a17ae 7713 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7714 vty_out(vty,
7715 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7716 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7717 count * sizeof(struct lcommunity)));
d62a17ae 7718
7719 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7720 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7721 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7722 count * sizeof(struct cluster_list)));
7723
7724 /* Peer related usage */
7725 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7726 vty_out(vty, "%ld peers, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct peer)));
7729
7730 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7731 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7733 count * sizeof(struct peer_group)));
7734
7735 /* Other */
7736 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7737 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7738 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct hash)));
7740 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7741 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct hash_backet)));
7744 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7745 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7746 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7747 count * sizeof(regex_t)));
d62a17ae 7748 return CMD_SUCCESS;
4bf6a362 7749}
fee0f4c6 7750
57a9c8a8
DS
7751static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7752{
7753 json_object *bestpath = json_object_new_object();
7754
7755 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7756 json_object_string_add(bestpath, "asPath", "ignore");
7757
7758 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7759 json_object_string_add(bestpath, "asPath", "confed");
7760
7761 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7762 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7763 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7764 "as-set");
7765 else
a4d82a8a 7766 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7767 "true");
7768 } else
a4d82a8a 7769 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7770
7771 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7772 json_object_string_add(bestpath, "compareRouterId", "true");
7773 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7774 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7775 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7776 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7777 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7778 json_object_string_add(bestpath, "med",
7779 "missing-as-worst");
7780 else
7781 json_object_string_add(bestpath, "med", "true");
7782 }
7783
7784 json_object_object_add(json, "bestPath", bestpath);
7785}
7786
718e3744 7787/* Show BGP peer's summary information. */
d62a17ae 7788static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7789 bool use_json, json_object *json)
d62a17ae 7790{
7791 struct peer *peer;
7792 struct listnode *node, *nnode;
7793 unsigned int count = 0, dn_count = 0;
7794 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7795 char neighbor_buf[VTY_BUFSIZ];
7796 int neighbor_col_default_width = 16;
7797 int len;
7798 int max_neighbor_width = 0;
7799 int pfx_rcd_safi;
7800 json_object *json_peer = NULL;
7801 json_object *json_peers = NULL;
50e05855 7802 struct peer_af *paf;
d62a17ae 7803
7804 /* labeled-unicast routes are installed in the unicast table so in order
7805 * to
7806 * display the correct PfxRcd value we must look at SAFI_UNICAST
7807 */
7808 if (safi == SAFI_LABELED_UNICAST)
7809 pfx_rcd_safi = SAFI_UNICAST;
7810 else
7811 pfx_rcd_safi = safi;
7812
7813 if (use_json) {
7814 if (json == NULL)
7815 json = json_object_new_object();
7816
7817 json_peers = json_object_new_object();
7818 } else {
7819 /* Loop over all neighbors that will be displayed to determine
7820 * how many
7821 * characters are needed for the Neighbor column
7822 */
7823 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7824 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7825 continue;
7826
7827 if (peer->afc[afi][safi]) {
7828 memset(dn_flag, '\0', sizeof(dn_flag));
7829 if (peer_dynamic_neighbor(peer))
7830 dn_flag[0] = '*';
7831
7832 if (peer->hostname
7833 && bgp_flag_check(bgp,
7834 BGP_FLAG_SHOW_HOSTNAME))
7835 sprintf(neighbor_buf, "%s%s(%s) ",
7836 dn_flag, peer->hostname,
7837 peer->host);
7838 else
7839 sprintf(neighbor_buf, "%s%s ", dn_flag,
7840 peer->host);
7841
7842 len = strlen(neighbor_buf);
7843
7844 if (len > max_neighbor_width)
7845 max_neighbor_width = len;
7846 }
7847 }
f933309e 7848
d62a17ae 7849 /* Originally we displayed the Neighbor column as 16
7850 * characters wide so make that the default
7851 */
7852 if (max_neighbor_width < neighbor_col_default_width)
7853 max_neighbor_width = neighbor_col_default_width;
7854 }
f933309e 7855
d62a17ae 7856 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7857 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7858 continue;
7859
ea47320b
DL
7860 if (!peer->afc[afi][safi])
7861 continue;
d62a17ae 7862
ea47320b
DL
7863 if (!count) {
7864 unsigned long ents;
7865 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7866 int64_t vrf_id_ui;
d62a17ae 7867
a4d82a8a
PZ
7868 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7869 ? -1
7870 : (int64_t)bgp->vrf_id;
ea47320b
DL
7871
7872 /* Usage summary and header */
7873 if (use_json) {
7874 json_object_string_add(
7875 json, "routerId",
7876 inet_ntoa(bgp->router_id));
60466a63
QY
7877 json_object_int_add(json, "as", bgp->as);
7878 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7879 json_object_string_add(
7880 json, "vrfName",
7881 (bgp->inst_type
7882 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7883 ? VRF_DEFAULT_NAME
ea47320b
DL
7884 : bgp->name);
7885 } else {
7886 vty_out(vty,
7887 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7888 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7889 bgp->vrf_id == VRF_UNKNOWN
7890 ? -1
7891 : (int)bgp->vrf_id);
ea47320b
DL
7892 vty_out(vty, "\n");
7893 }
d62a17ae 7894
ea47320b 7895 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7896 if (use_json) {
ea47320b 7897 json_object_int_add(
60466a63 7898 json, "updateDelayLimit",
ea47320b 7899 bgp->v_update_delay);
d62a17ae 7900
ea47320b
DL
7901 if (bgp->v_update_delay
7902 != bgp->v_establish_wait)
d62a17ae 7903 json_object_int_add(
7904 json,
ea47320b
DL
7905 "updateDelayEstablishWait",
7906 bgp->v_establish_wait);
d62a17ae 7907
60466a63 7908 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7909 json_object_string_add(
7910 json,
7911 "updateDelayFirstNeighbor",
7912 bgp->update_delay_begin_time);
7913 json_object_boolean_true_add(
7914 json,
7915 "updateDelayInProgress");
7916 } else {
7917 if (bgp->update_delay_over) {
d62a17ae 7918 json_object_string_add(
7919 json,
7920 "updateDelayFirstNeighbor",
7921 bgp->update_delay_begin_time);
ea47320b 7922 json_object_string_add(
d62a17ae 7923 json,
ea47320b
DL
7924 "updateDelayBestpathResumed",
7925 bgp->update_delay_end_time);
7926 json_object_string_add(
d62a17ae 7927 json,
ea47320b
DL
7928 "updateDelayZebraUpdateResume",
7929 bgp->update_delay_zebra_resume_time);
7930 json_object_string_add(
7931 json,
7932 "updateDelayPeerUpdateResume",
7933 bgp->update_delay_peers_resume_time);
d62a17ae 7934 }
ea47320b
DL
7935 }
7936 } else {
7937 vty_out(vty,
7938 "Read-only mode update-delay limit: %d seconds\n",
7939 bgp->v_update_delay);
7940 if (bgp->v_update_delay
7941 != bgp->v_establish_wait)
d62a17ae 7942 vty_out(vty,
ea47320b
DL
7943 " Establish wait: %d seconds\n",
7944 bgp->v_establish_wait);
d62a17ae 7945
60466a63 7946 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7947 vty_out(vty,
7948 " First neighbor established: %s\n",
7949 bgp->update_delay_begin_time);
7950 vty_out(vty,
7951 " Delay in progress\n");
7952 } else {
7953 if (bgp->update_delay_over) {
d62a17ae 7954 vty_out(vty,
7955 " First neighbor established: %s\n",
7956 bgp->update_delay_begin_time);
7957 vty_out(vty,
ea47320b
DL
7958 " Best-paths resumed: %s\n",
7959 bgp->update_delay_end_time);
7960 vty_out(vty,
7961 " zebra update resumed: %s\n",
7962 bgp->update_delay_zebra_resume_time);
7963 vty_out(vty,
7964 " peers update resumed: %s\n",
7965 bgp->update_delay_peers_resume_time);
d62a17ae 7966 }
7967 }
7968 }
ea47320b 7969 }
d62a17ae 7970
ea47320b
DL
7971 if (use_json) {
7972 if (bgp_maxmed_onstartup_configured(bgp)
7973 && bgp->maxmed_active)
7974 json_object_boolean_true_add(
60466a63 7975 json, "maxMedOnStartup");
ea47320b
DL
7976 if (bgp->v_maxmed_admin)
7977 json_object_boolean_true_add(
60466a63 7978 json, "maxMedAdministrative");
d62a17ae 7979
ea47320b
DL
7980 json_object_int_add(
7981 json, "tableVersion",
60466a63 7982 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7983
60466a63
QY
7984 ents = bgp_table_count(bgp->rib[afi][safi]);
7985 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7986 json_object_int_add(
7987 json, "ribMemory",
7988 ents * sizeof(struct bgp_node));
d62a17ae 7989
ea47320b 7990 ents = listcount(bgp->peer);
60466a63
QY
7991 json_object_int_add(json, "peerCount", ents);
7992 json_object_int_add(json, "peerMemory",
7993 ents * sizeof(struct peer));
d62a17ae 7994
ea47320b
DL
7995 if ((ents = listcount(bgp->group))) {
7996 json_object_int_add(
60466a63 7997 json, "peerGroupCount", ents);
ea47320b
DL
7998 json_object_int_add(
7999 json, "peerGroupMemory",
996c9314
LB
8000 ents * sizeof(struct
8001 peer_group));
ea47320b 8002 }
d62a17ae 8003
ea47320b
DL
8004 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8005 BGP_CONFIG_DAMPENING))
8006 json_object_boolean_true_add(
60466a63 8007 json, "dampeningEnabled");
ea47320b
DL
8008 } else {
8009 if (bgp_maxmed_onstartup_configured(bgp)
8010 && bgp->maxmed_active)
d62a17ae 8011 vty_out(vty,
ea47320b
DL
8012 "Max-med on-startup active\n");
8013 if (bgp->v_maxmed_admin)
d62a17ae 8014 vty_out(vty,
ea47320b 8015 "Max-med administrative active\n");
d62a17ae 8016
60466a63
QY
8017 vty_out(vty, "BGP table version %" PRIu64 "\n",
8018 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8019
60466a63 8020 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8021 vty_out(vty,
8022 "RIB entries %ld, using %s of memory\n",
8023 ents,
996c9314
LB
8024 mtype_memstr(memstrbuf,
8025 sizeof(memstrbuf),
8026 ents * sizeof(struct
8027 bgp_node)));
ea47320b
DL
8028
8029 /* Peer related usage */
8030 ents = listcount(bgp->peer);
60466a63 8031 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8032 ents,
8033 mtype_memstr(
60466a63
QY
8034 memstrbuf, sizeof(memstrbuf),
8035 ents * sizeof(struct peer)));
ea47320b
DL
8036
8037 if ((ents = listcount(bgp->group)))
d62a17ae 8038 vty_out(vty,
ea47320b 8039 "Peer groups %ld, using %s of memory\n",
d62a17ae 8040 ents,
8041 mtype_memstr(
8042 memstrbuf,
8043 sizeof(memstrbuf),
996c9314
LB
8044 ents * sizeof(struct
8045 peer_group)));
d62a17ae 8046
ea47320b
DL
8047 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8048 BGP_CONFIG_DAMPENING))
60466a63 8049 vty_out(vty, "Dampening enabled.\n");
ea47320b 8050 vty_out(vty, "\n");
d62a17ae 8051
ea47320b
DL
8052 /* Subtract 8 here because 'Neighbor' is
8053 * 8 characters */
8054 vty_out(vty, "Neighbor");
60466a63
QY
8055 vty_out(vty, "%*s", max_neighbor_width - 8,
8056 " ");
ea47320b
DL
8057 vty_out(vty,
8058 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8059 }
ea47320b 8060 }
d62a17ae 8061
ea47320b 8062 count++;
d62a17ae 8063
ea47320b
DL
8064 if (use_json) {
8065 json_peer = json_object_new_object();
d62a17ae 8066
b4e9dcba
DD
8067 if (peer_dynamic_neighbor(peer)) {
8068 dn_count++;
60466a63
QY
8069 json_object_boolean_true_add(json_peer,
8070 "dynamicPeer");
b4e9dcba 8071 }
d62a17ae 8072
ea47320b 8073 if (peer->hostname)
60466a63 8074 json_object_string_add(json_peer, "hostname",
ea47320b 8075 peer->hostname);
d62a17ae 8076
ea47320b 8077 if (peer->domainname)
60466a63
QY
8078 json_object_string_add(json_peer, "domainname",
8079 peer->domainname);
d62a17ae 8080
60466a63 8081 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8082 json_object_int_add(json_peer, "version", 4);
60466a63 8083 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8084 PEER_TOTAL_RX(peer));
60466a63 8085 json_object_int_add(json_peer, "msgSent",
0112e9e0 8086 PEER_TOTAL_TX(peer));
ea47320b
DL
8087
8088 json_object_int_add(json_peer, "tableVersion",
8089 peer->version[afi][safi]);
8090 json_object_int_add(json_peer, "outq",
8091 peer->obuf->count);
8092 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8093 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8094 use_json, json_peer);
50e05855
AD
8095
8096 /*
8097 * Adding "pfxRcd" field to match with the corresponding
8098 * CLI. "prefixReceivedCount" will be deprecated in
8099 * future.
8100 */
60466a63
QY
8101 json_object_int_add(json_peer, "prefixReceivedCount",
8102 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8103 json_object_int_add(json_peer, "pfxRcd",
8104 peer->pcount[afi][pfx_rcd_safi]);
8105
8106 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8107 if (paf && PAF_SUBGRP(paf))
8108 json_object_int_add(json_peer,
8109 "pfxSnt",
8110 (PAF_SUBGRP(paf))->scount);
d62a17ae 8111
ea47320b 8112 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8113 json_object_string_add(json_peer, "state",
ea47320b 8114 "Idle (Admin)");
9199a725
TM
8115 else if (peer->afc_recv[afi][safi])
8116 json_object_string_add(
8117 json_peer, "state",
8118 lookup_msg(bgp_status_msg, peer->status,
8119 NULL));
60466a63
QY
8120 else if (CHECK_FLAG(peer->sflags,
8121 PEER_STATUS_PREFIX_OVERFLOW))
8122 json_object_string_add(json_peer, "state",
ea47320b
DL
8123 "Idle (PfxCt)");
8124 else
8125 json_object_string_add(
8126 json_peer, "state",
60466a63
QY
8127 lookup_msg(bgp_status_msg, peer->status,
8128 NULL));
ea47320b
DL
8129
8130 if (peer->conf_if)
60466a63 8131 json_object_string_add(json_peer, "idType",
ea47320b
DL
8132 "interface");
8133 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8134 json_object_string_add(json_peer, "idType",
8135 "ipv4");
ea47320b 8136 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8137 json_object_string_add(json_peer, "idType",
8138 "ipv6");
d62a17ae 8139
ea47320b
DL
8140 json_object_object_add(json_peers, peer->host,
8141 json_peer);
8142 } else {
8143 memset(dn_flag, '\0', sizeof(dn_flag));
8144 if (peer_dynamic_neighbor(peer)) {
8145 dn_count++;
8146 dn_flag[0] = '*';
8147 }
d62a17ae 8148
ea47320b 8149 if (peer->hostname
60466a63 8150 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8151 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8152 peer->hostname, peer->host);
ea47320b 8153 else
60466a63 8154 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8155
8156 /* pad the neighbor column with spaces */
8157 if (len < max_neighbor_width)
60466a63
QY
8158 vty_out(vty, "%*s", max_neighbor_width - len,
8159 " ");
ea47320b 8160
86a55b99 8161 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8162 peer->as, PEER_TOTAL_RX(peer),
8163 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8164 0, peer->obuf->count,
d62a17ae 8165 peer_uptime(peer->uptime, timebuf,
ea47320b 8166 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8167
ea47320b 8168 if (peer->status == Established)
2f8f4f10 8169 if (peer->afc_recv[afi][safi])
95077abf 8170 vty_out(vty, " %12ld",
a4d82a8a
PZ
8171 peer->pcount[afi]
8172 [pfx_rcd_safi]);
95077abf
DW
8173 else
8174 vty_out(vty, " NoNeg");
ea47320b 8175 else {
60466a63 8176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8177 vty_out(vty, " Idle (Admin)");
60466a63
QY
8178 else if (CHECK_FLAG(
8179 peer->sflags,
8180 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8181 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8182 else
ea47320b 8183 vty_out(vty, " %12s",
60466a63
QY
8184 lookup_msg(bgp_status_msg,
8185 peer->status, NULL));
d62a17ae 8186 }
ea47320b 8187 vty_out(vty, "\n");
d62a17ae 8188 }
8189 }
f933309e 8190
d62a17ae 8191 if (use_json) {
8192 json_object_object_add(json, "peers", json_peers);
8193
8194 json_object_int_add(json, "totalPeers", count);
8195 json_object_int_add(json, "dynamicPeers", dn_count);
8196
57a9c8a8
DS
8197 bgp_show_bestpath_json(bgp, json);
8198
996c9314
LB
8199 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8200 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8201 json_object_free(json);
8202 } else {
8203 if (count)
8204 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8205 else {
d6ceaca3 8206 vty_out(vty, "No %s neighbor is configured\n",
8207 afi_safi_print(afi, safi));
d62a17ae 8208 }
b05a1c8b 8209
d6ceaca3 8210 if (dn_count) {
d62a17ae 8211 vty_out(vty, "* - dynamic neighbor\n");
8212 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8213 dn_count, bgp->dynamic_neighbors_limit);
8214 }
8215 }
1ff9a340 8216
d62a17ae 8217 return CMD_SUCCESS;
718e3744 8218}
8219
d62a17ae 8220static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8221 int safi, bool use_json,
d62a17ae 8222 json_object *json)
8223{
8224 int is_first = 1;
8225 int afi_wildcard = (afi == AFI_MAX);
8226 int safi_wildcard = (safi == SAFI_MAX);
8227 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8228 bool nbr_output = false;
d62a17ae 8229
8230 if (use_json && is_wildcard)
8231 vty_out(vty, "{\n");
8232 if (afi_wildcard)
8233 afi = 1; /* AFI_IP */
8234 while (afi < AFI_MAX) {
8235 if (safi_wildcard)
8236 safi = 1; /* SAFI_UNICAST */
8237 while (safi < SAFI_MAX) {
318cac96 8238 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8239 nbr_output = true;
d62a17ae 8240 if (is_wildcard) {
8241 /*
8242 * So limit output to those afi/safi
8243 * pairs that
8244 * actualy have something interesting in
8245 * them
8246 */
8247 if (use_json) {
8248 json = json_object_new_object();
8249
8250 if (!is_first)
8251 vty_out(vty, ",\n");
8252 else
8253 is_first = 0;
8254
8255 vty_out(vty, "\"%s\":",
8256 afi_safi_json(afi,
8257 safi));
8258 } else {
8259 vty_out(vty, "\n%s Summary:\n",
8260 afi_safi_print(afi,
8261 safi));
8262 }
8263 }
8264 bgp_show_summary(vty, bgp, afi, safi, use_json,
8265 json);
8266 }
8267 safi++;
d62a17ae 8268 if (!safi_wildcard)
8269 safi = SAFI_MAX;
8270 }
8271 afi++;
ee851c8c 8272 if (!afi_wildcard)
d62a17ae 8273 afi = AFI_MAX;
8274 }
8275
8276 if (use_json && is_wildcard)
8277 vty_out(vty, "}\n");
ca61fd25
DS
8278 else if (!nbr_output) {
8279 if (use_json)
8280 vty_out(vty, "{}\n");
8281 else
8282 vty_out(vty, "%% No BGP neighbors found\n");
8283 }
d62a17ae 8284}
8285
8286static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8287 safi_t safi, bool use_json)
d62a17ae 8288{
8289 struct listnode *node, *nnode;
8290 struct bgp *bgp;
8291 json_object *json = NULL;
8292 int is_first = 1;
9f049418 8293 bool nbr_output = false;
d62a17ae 8294
8295 if (use_json)
8296 vty_out(vty, "{\n");
8297
8298 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8299 nbr_output = true;
d62a17ae 8300 if (use_json) {
8301 json = json_object_new_object();
8302
8303 if (!is_first)
8304 vty_out(vty, ",\n");
8305 else
8306 is_first = 0;
8307
8308 vty_out(vty, "\"%s\":",
8309 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8310 ? VRF_DEFAULT_NAME
d62a17ae 8311 : bgp->name);
8312 } else {
8313 vty_out(vty, "\nInstance %s:\n",
8314 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8315 ? VRF_DEFAULT_NAME
d62a17ae 8316 : bgp->name);
8317 }
8318 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8319 }
8320
8321 if (use_json)
8322 vty_out(vty, "}\n");
9f049418
DS
8323 else if (!nbr_output)
8324 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8325}
8326
8327int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8328 safi_t safi, bool use_json)
d62a17ae 8329{
8330 struct bgp *bgp;
8331
8332 if (name) {
8333 if (strmatch(name, "all")) {
8334 bgp_show_all_instances_summary_vty(vty, afi, safi,
8335 use_json);
8336 return CMD_SUCCESS;
8337 } else {
8338 bgp = bgp_lookup_by_name(name);
8339
8340 if (!bgp) {
8341 if (use_json)
8342 vty_out(vty, "{}\n");
8343 else
8344 vty_out(vty,
ca61fd25 8345 "%% BGP instance not found\n");
d62a17ae 8346 return CMD_WARNING;
8347 }
8348
8349 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8350 NULL);
8351 return CMD_SUCCESS;
8352 }
8353 }
8354
8355 bgp = bgp_get_default();
8356
8357 if (bgp)
8358 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8359 else {
ca61fd25
DS
8360 if (use_json)
8361 vty_out(vty, "{}\n");
8362 else
8363 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8364 return CMD_WARNING;
8365 }
d62a17ae 8366
8367 return CMD_SUCCESS;
4fb25c53
DW
8368}
8369
716b2d8a 8370/* `show [ip] bgp summary' commands. */
47fc97cc 8371DEFUN (show_ip_bgp_summary,
718e3744 8372 show_ip_bgp_summary_cmd,
dd6bd0f1 8373 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8374 SHOW_STR
8375 IP_STR
8376 BGP_STR
8386ac43 8377 BGP_INSTANCE_HELP_STR
46f296b4 8378 BGP_AFI_HELP_STR
dd6bd0f1 8379 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8380 "Summary of BGP neighbor status\n"
9973d184 8381 JSON_STR)
718e3744 8382{
d62a17ae 8383 char *vrf = NULL;
8384 afi_t afi = AFI_MAX;
8385 safi_t safi = SAFI_MAX;
8386
8387 int idx = 0;
8388
8389 /* show [ip] bgp */
8390 if (argv_find(argv, argc, "ip", &idx))
8391 afi = AFI_IP;
9a8bdf1c
PG
8392 /* [<vrf> VIEWVRFNAME] */
8393 if (argv_find(argv, argc, "vrf", &idx)) {
8394 vrf = argv[idx + 1]->arg;
8395 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8396 vrf = NULL;
8397 } else if (argv_find(argv, argc, "view", &idx))
8398 /* [<view> VIEWVRFNAME] */
8399 vrf = argv[idx + 1]->arg;
d62a17ae 8400 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8401 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8402 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8403 }
8404
9f049418 8405 bool uj = use_json(argc, argv);
d62a17ae 8406
8407 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8408}
8409
8410const char *afi_safi_print(afi_t afi, safi_t safi)
8411{
8412 if (afi == AFI_IP && safi == SAFI_UNICAST)
8413 return "IPv4 Unicast";
8414 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8415 return "IPv4 Multicast";
8416 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8417 return "IPv4 Labeled Unicast";
8418 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8419 return "IPv4 VPN";
8420 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8421 return "IPv4 Encap";
7c40bf39 8422 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8423 return "IPv4 Flowspec";
d62a17ae 8424 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8425 return "IPv6 Unicast";
8426 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8427 return "IPv6 Multicast";
8428 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8429 return "IPv6 Labeled Unicast";
8430 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8431 return "IPv6 VPN";
8432 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8433 return "IPv6 Encap";
7c40bf39 8434 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8435 return "IPv6 Flowspec";
d62a17ae 8436 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8437 return "L2VPN EVPN";
8438 else
8439 return "Unknown";
538621f2 8440}
8441
b9f77ec8
DS
8442/*
8443 * Please note that we have intentionally camelCased
8444 * the return strings here. So if you want
8445 * to use this function, please ensure you
8446 * are doing this within json output
8447 */
d62a17ae 8448const char *afi_safi_json(afi_t afi, safi_t safi)
8449{
8450 if (afi == AFI_IP && safi == SAFI_UNICAST)
8451 return "ipv4Unicast";
8452 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8453 return "ipv4Multicast";
8454 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8455 return "ipv4LabeledUnicast";
8456 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8457 return "ipv4Vpn";
8458 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8459 return "ipv4Encap";
7c40bf39 8460 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8461 return "ipv4Flowspec";
d62a17ae 8462 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8463 return "ipv6Unicast";
8464 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8465 return "ipv6Multicast";
8466 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8467 return "ipv6LabeledUnicast";
8468 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8469 return "ipv6Vpn";
8470 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8471 return "ipv6Encap";
7c40bf39 8472 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8473 return "ipv6Flowspec";
d62a17ae 8474 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8475 return "l2VpnEvpn";
8476 else
8477 return "Unknown";
27162734
LB
8478}
8479
718e3744 8480/* Show BGP peer's information. */
d62a17ae 8481enum show_type { show_all, show_peer };
8482
8483static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8484 afi_t afi, safi_t safi,
d7c0a89a
QY
8485 uint16_t adv_smcap, uint16_t adv_rmcap,
8486 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8487 bool use_json, json_object *json_pref)
d62a17ae 8488{
8489 /* Send-Mode */
8490 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8491 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8492 if (use_json) {
8493 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8494 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8495 json_object_string_add(json_pref, "sendMode",
8496 "advertisedAndReceived");
8497 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8498 json_object_string_add(json_pref, "sendMode",
8499 "advertised");
8500 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8501 json_object_string_add(json_pref, "sendMode",
8502 "received");
8503 } else {
8504 vty_out(vty, " Send-mode: ");
8505 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8506 vty_out(vty, "advertised");
8507 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8508 vty_out(vty, "%sreceived",
8509 CHECK_FLAG(p->af_cap[afi][safi],
8510 adv_smcap)
8511 ? ", "
8512 : "");
8513 vty_out(vty, "\n");
8514 }
8515 }
8516
8517 /* Receive-Mode */
8518 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8519 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8520 if (use_json) {
8521 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8522 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8523 json_object_string_add(json_pref, "recvMode",
8524 "advertisedAndReceived");
8525 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8526 json_object_string_add(json_pref, "recvMode",
8527 "advertised");
8528 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8529 json_object_string_add(json_pref, "recvMode",
8530 "received");
8531 } else {
8532 vty_out(vty, " Receive-mode: ");
8533 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8534 vty_out(vty, "advertised");
8535 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8536 vty_out(vty, "%sreceived",
8537 CHECK_FLAG(p->af_cap[afi][safi],
8538 adv_rmcap)
8539 ? ", "
8540 : "");
8541 vty_out(vty, "\n");
8542 }
8543 }
8544}
8545
8546static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8547 safi_t safi, bool use_json,
d62a17ae 8548 json_object *json_neigh)
8549{
0291c246
MK
8550 struct bgp_filter *filter;
8551 struct peer_af *paf;
8552 char orf_pfx_name[BUFSIZ];
8553 int orf_pfx_count;
8554 json_object *json_af = NULL;
8555 json_object *json_prefA = NULL;
8556 json_object *json_prefB = NULL;
8557 json_object *json_addr = NULL;
d62a17ae 8558
8559 if (use_json) {
8560 json_addr = json_object_new_object();
8561 json_af = json_object_new_object();
8562 filter = &p->filter[afi][safi];
8563
8564 if (peer_group_active(p))
8565 json_object_string_add(json_addr, "peerGroupMember",
8566 p->group->name);
8567
8568 paf = peer_af_find(p, afi, safi);
8569 if (paf && PAF_SUBGRP(paf)) {
8570 json_object_int_add(json_addr, "updateGroupId",
8571 PAF_UPDGRP(paf)->id);
8572 json_object_int_add(json_addr, "subGroupId",
8573 PAF_SUBGRP(paf)->id);
8574 json_object_int_add(json_addr, "packetQueueLength",
8575 bpacket_queue_virtual_length(paf));
8576 }
8577
8578 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8579 || CHECK_FLAG(p->af_cap[afi][safi],
8580 PEER_CAP_ORF_PREFIX_SM_RCV)
8581 || CHECK_FLAG(p->af_cap[afi][safi],
8582 PEER_CAP_ORF_PREFIX_RM_ADV)
8583 || CHECK_FLAG(p->af_cap[afi][safi],
8584 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8585 json_object_int_add(json_af, "orfType",
8586 ORF_TYPE_PREFIX);
8587 json_prefA = json_object_new_object();
8588 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8589 PEER_CAP_ORF_PREFIX_SM_ADV,
8590 PEER_CAP_ORF_PREFIX_RM_ADV,
8591 PEER_CAP_ORF_PREFIX_SM_RCV,
8592 PEER_CAP_ORF_PREFIX_RM_RCV,
8593 use_json, json_prefA);
8594 json_object_object_add(json_af, "orfPrefixList",
8595 json_prefA);
8596 }
8597
8598 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8599 || CHECK_FLAG(p->af_cap[afi][safi],
8600 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8601 || CHECK_FLAG(p->af_cap[afi][safi],
8602 PEER_CAP_ORF_PREFIX_RM_ADV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8605 json_object_int_add(json_af, "orfOldType",
8606 ORF_TYPE_PREFIX_OLD);
8607 json_prefB = json_object_new_object();
8608 bgp_show_peer_afi_orf_cap(
8609 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8610 PEER_CAP_ORF_PREFIX_RM_ADV,
8611 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8612 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8613 json_prefB);
8614 json_object_object_add(json_af, "orfOldPrefixList",
8615 json_prefB);
8616 }
8617
8618 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8619 || CHECK_FLAG(p->af_cap[afi][safi],
8620 PEER_CAP_ORF_PREFIX_SM_RCV)
8621 || CHECK_FLAG(p->af_cap[afi][safi],
8622 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_RM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_RM_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8629 json_object_object_add(json_addr, "afDependentCap",
8630 json_af);
8631 else
8632 json_object_free(json_af);
8633
8634 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8635 orf_pfx_count = prefix_bgp_show_prefix_list(
8636 NULL, afi, orf_pfx_name, use_json);
8637
8638 if (CHECK_FLAG(p->af_sflags[afi][safi],
8639 PEER_STATUS_ORF_PREFIX_SEND)
8640 || orf_pfx_count) {
8641 if (CHECK_FLAG(p->af_sflags[afi][safi],
8642 PEER_STATUS_ORF_PREFIX_SEND))
8643 json_object_boolean_true_add(json_neigh,
8644 "orfSent");
8645 if (orf_pfx_count)
8646 json_object_int_add(json_addr, "orfRecvCounter",
8647 orf_pfx_count);
8648 }
8649 if (CHECK_FLAG(p->af_sflags[afi][safi],
8650 PEER_STATUS_ORF_WAIT_REFRESH))
8651 json_object_string_add(
8652 json_addr, "orfFirstUpdate",
8653 "deferredUntilORFOrRouteRefreshRecvd");
8654
8655 if (CHECK_FLAG(p->af_flags[afi][safi],
8656 PEER_FLAG_REFLECTOR_CLIENT))
8657 json_object_boolean_true_add(json_addr,
8658 "routeReflectorClient");
8659 if (CHECK_FLAG(p->af_flags[afi][safi],
8660 PEER_FLAG_RSERVER_CLIENT))
8661 json_object_boolean_true_add(json_addr,
8662 "routeServerClient");
8663 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8664 json_object_boolean_true_add(json_addr,
8665 "inboundSoftConfigPermit");
8666
8667 if (CHECK_FLAG(p->af_flags[afi][safi],
8668 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8669 json_object_boolean_true_add(
8670 json_addr,
8671 "privateAsNumsAllReplacedInUpdatesToNbr");
8672 else if (CHECK_FLAG(p->af_flags[afi][safi],
8673 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8674 json_object_boolean_true_add(
8675 json_addr,
8676 "privateAsNumsReplacedInUpdatesToNbr");
8677 else if (CHECK_FLAG(p->af_flags[afi][safi],
8678 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8679 json_object_boolean_true_add(
8680 json_addr,
8681 "privateAsNumsAllRemovedInUpdatesToNbr");
8682 else if (CHECK_FLAG(p->af_flags[afi][safi],
8683 PEER_FLAG_REMOVE_PRIVATE_AS))
8684 json_object_boolean_true_add(
8685 json_addr,
8686 "privateAsNumsRemovedInUpdatesToNbr");
8687
dcc68b5e
MS
8688 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8689 json_object_boolean_true_add(
8690 json_addr,
8691 bgp_addpath_names(p->addpath_type[afi][safi])
8692 ->type_json_name);
d62a17ae 8693
8694 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8695 json_object_string_add(json_addr,
8696 "overrideASNsInOutboundUpdates",
8697 "ifAspathEqualRemoteAs");
8698
8699 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8700 || CHECK_FLAG(p->af_flags[afi][safi],
8701 PEER_FLAG_FORCE_NEXTHOP_SELF))
8702 json_object_boolean_true_add(json_addr,
8703 "routerAlwaysNextHop");
8704 if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_AS_PATH_UNCHANGED))
8706 json_object_boolean_true_add(
8707 json_addr, "unchangedAsPathPropogatedToNbr");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_NEXTHOP_UNCHANGED))
8710 json_object_boolean_true_add(
8711 json_addr, "unchangedNextHopPropogatedToNbr");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8713 json_object_boolean_true_add(
8714 json_addr, "unchangedMedPropogatedToNbr");
8715 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8716 || CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_SEND_COMMUNITY)
8720 && CHECK_FLAG(p->af_flags[afi][safi],
8721 PEER_FLAG_SEND_EXT_COMMUNITY))
8722 json_object_string_add(json_addr,
8723 "commAttriSentToNbr",
8724 "extendedAndStandard");
8725 else if (CHECK_FLAG(p->af_flags[afi][safi],
8726 PEER_FLAG_SEND_EXT_COMMUNITY))
8727 json_object_string_add(json_addr,
8728 "commAttriSentToNbr",
8729 "extended");
8730 else
8731 json_object_string_add(json_addr,
8732 "commAttriSentToNbr",
8733 "standard");
8734 }
8735 if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_DEFAULT_ORIGINATE)) {
8737 if (p->default_rmap[afi][safi].name)
8738 json_object_string_add(
8739 json_addr, "defaultRouteMap",
8740 p->default_rmap[afi][safi].name);
8741
8742 if (paf && PAF_SUBGRP(paf)
8743 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8744 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8745 json_object_boolean_true_add(json_addr,
8746 "defaultSent");
8747 else
8748 json_object_boolean_true_add(json_addr,
8749 "defaultNotSent");
8750 }
8751
dff8f48d 8752 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8753 if (is_evpn_enabled())
60466a63
QY
8754 json_object_boolean_true_add(
8755 json_addr, "advertiseAllVnis");
dff8f48d
MK
8756 }
8757
d62a17ae 8758 if (filter->plist[FILTER_IN].name
8759 || filter->dlist[FILTER_IN].name
8760 || filter->aslist[FILTER_IN].name
8761 || filter->map[RMAP_IN].name)
8762 json_object_boolean_true_add(json_addr,
8763 "inboundPathPolicyConfig");
8764 if (filter->plist[FILTER_OUT].name
8765 || filter->dlist[FILTER_OUT].name
8766 || filter->aslist[FILTER_OUT].name
8767 || filter->map[RMAP_OUT].name || filter->usmap.name)
8768 json_object_boolean_true_add(
8769 json_addr, "outboundPathPolicyConfig");
8770
8771 /* prefix-list */
8772 if (filter->plist[FILTER_IN].name)
8773 json_object_string_add(json_addr,
8774 "incomingUpdatePrefixFilterList",
8775 filter->plist[FILTER_IN].name);
8776 if (filter->plist[FILTER_OUT].name)
8777 json_object_string_add(json_addr,
8778 "outgoingUpdatePrefixFilterList",
8779 filter->plist[FILTER_OUT].name);
8780
8781 /* distribute-list */
8782 if (filter->dlist[FILTER_IN].name)
8783 json_object_string_add(
8784 json_addr, "incomingUpdateNetworkFilterList",
8785 filter->dlist[FILTER_IN].name);
8786 if (filter->dlist[FILTER_OUT].name)
8787 json_object_string_add(
8788 json_addr, "outgoingUpdateNetworkFilterList",
8789 filter->dlist[FILTER_OUT].name);
8790
8791 /* filter-list. */
8792 if (filter->aslist[FILTER_IN].name)
8793 json_object_string_add(json_addr,
8794 "incomingUpdateAsPathFilterList",
8795 filter->aslist[FILTER_IN].name);
8796 if (filter->aslist[FILTER_OUT].name)
8797 json_object_string_add(json_addr,
8798 "outgoingUpdateAsPathFilterList",
8799 filter->aslist[FILTER_OUT].name);
8800
8801 /* route-map. */
8802 if (filter->map[RMAP_IN].name)
8803 json_object_string_add(
8804 json_addr, "routeMapForIncomingAdvertisements",
8805 filter->map[RMAP_IN].name);
8806 if (filter->map[RMAP_OUT].name)
8807 json_object_string_add(
8808 json_addr, "routeMapForOutgoingAdvertisements",
8809 filter->map[RMAP_OUT].name);
8810
8811 /* unsuppress-map */
8812 if (filter->usmap.name)
8813 json_object_string_add(json_addr,
8814 "selectiveUnsuppressRouteMap",
8815 filter->usmap.name);
8816
8817 /* Receive prefix count */
8818 json_object_int_add(json_addr, "acceptedPrefixCounter",
8819 p->pcount[afi][safi]);
50e05855
AD
8820 if (paf && PAF_SUBGRP(paf))
8821 json_object_int_add(json_addr, "sentPrefixCounter",
8822 (PAF_SUBGRP(paf))->scount);
d62a17ae 8823
8824 /* Maximum prefix */
8825 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8826 json_object_int_add(json_addr, "prefixAllowedMax",
8827 p->pmax[afi][safi]);
8828 if (CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_MAX_PREFIX_WARNING))
8830 json_object_boolean_true_add(
8831 json_addr, "prefixAllowedMaxWarning");
8832 json_object_int_add(json_addr,
8833 "prefixAllowedWarningThresh",
8834 p->pmax_threshold[afi][safi]);
8835 if (p->pmax_restart[afi][safi])
8836 json_object_int_add(
8837 json_addr,
8838 "prefixAllowedRestartIntervalMsecs",
8839 p->pmax_restart[afi][safi] * 60000);
8840 }
8841 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8842 json_addr);
8843
8844 } else {
8845 filter = &p->filter[afi][safi];
8846
8847 vty_out(vty, " For address family: %s\n",
8848 afi_safi_print(afi, safi));
8849
8850 if (peer_group_active(p))
8851 vty_out(vty, " %s peer-group member\n",
8852 p->group->name);
8853
8854 paf = peer_af_find(p, afi, safi);
8855 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8856 vty_out(vty, " Update group %" PRIu64
8857 ", subgroup %" PRIu64 "\n",
d62a17ae 8858 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8859 vty_out(vty, " Packet Queue length %d\n",
8860 bpacket_queue_virtual_length(paf));
8861 } else {
8862 vty_out(vty, " Not part of any update group\n");
8863 }
8864 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8865 || CHECK_FLAG(p->af_cap[afi][safi],
8866 PEER_CAP_ORF_PREFIX_SM_RCV)
8867 || CHECK_FLAG(p->af_cap[afi][safi],
8868 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_RM_ADV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_RM_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8875 vty_out(vty, " AF-dependant capabilities:\n");
8876
8877 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8878 || CHECK_FLAG(p->af_cap[afi][safi],
8879 PEER_CAP_ORF_PREFIX_SM_RCV)
8880 || CHECK_FLAG(p->af_cap[afi][safi],
8881 PEER_CAP_ORF_PREFIX_RM_ADV)
8882 || CHECK_FLAG(p->af_cap[afi][safi],
8883 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8884 vty_out(vty,
8885 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8886 ORF_TYPE_PREFIX);
8887 bgp_show_peer_afi_orf_cap(
8888 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8889 PEER_CAP_ORF_PREFIX_RM_ADV,
8890 PEER_CAP_ORF_PREFIX_SM_RCV,
8891 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8892 }
8893 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8894 || CHECK_FLAG(p->af_cap[afi][safi],
8895 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8896 || CHECK_FLAG(p->af_cap[afi][safi],
8897 PEER_CAP_ORF_PREFIX_RM_ADV)
8898 || CHECK_FLAG(p->af_cap[afi][safi],
8899 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8900 vty_out(vty,
8901 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8902 ORF_TYPE_PREFIX_OLD);
8903 bgp_show_peer_afi_orf_cap(
8904 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8905 PEER_CAP_ORF_PREFIX_RM_ADV,
8906 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8907 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8908 }
8909
8910 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8911 orf_pfx_count = prefix_bgp_show_prefix_list(
8912 NULL, afi, orf_pfx_name, use_json);
8913
8914 if (CHECK_FLAG(p->af_sflags[afi][safi],
8915 PEER_STATUS_ORF_PREFIX_SEND)
8916 || orf_pfx_count) {
8917 vty_out(vty, " Outbound Route Filter (ORF):");
8918 if (CHECK_FLAG(p->af_sflags[afi][safi],
8919 PEER_STATUS_ORF_PREFIX_SEND))
8920 vty_out(vty, " sent;");
8921 if (orf_pfx_count)
8922 vty_out(vty, " received (%d entries)",
8923 orf_pfx_count);
8924 vty_out(vty, "\n");
8925 }
8926 if (CHECK_FLAG(p->af_sflags[afi][safi],
8927 PEER_STATUS_ORF_WAIT_REFRESH))
8928 vty_out(vty,
8929 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8930
8931 if (CHECK_FLAG(p->af_flags[afi][safi],
8932 PEER_FLAG_REFLECTOR_CLIENT))
8933 vty_out(vty, " Route-Reflector Client\n");
8934 if (CHECK_FLAG(p->af_flags[afi][safi],
8935 PEER_FLAG_RSERVER_CLIENT))
8936 vty_out(vty, " Route-Server Client\n");
8937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8938 vty_out(vty,
8939 " Inbound soft reconfiguration allowed\n");
8940
8941 if (CHECK_FLAG(p->af_flags[afi][safi],
8942 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8943 vty_out(vty,
8944 " Private AS numbers (all) replaced in updates to this neighbor\n");
8945 else if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8947 vty_out(vty,
8948 " Private AS numbers replaced in updates to this neighbor\n");
8949 else if (CHECK_FLAG(p->af_flags[afi][safi],
8950 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8951 vty_out(vty,
8952 " Private AS numbers (all) removed in updates to this neighbor\n");
8953 else if (CHECK_FLAG(p->af_flags[afi][safi],
8954 PEER_FLAG_REMOVE_PRIVATE_AS))
8955 vty_out(vty,
8956 " Private AS numbers removed in updates to this neighbor\n");
8957
dcc68b5e
MS
8958 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8959 vty_out(vty, " %s\n",
8960 bgp_addpath_names(p->addpath_type[afi][safi])
8961 ->human_description);
d62a17ae 8962
8963 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8964 vty_out(vty,
8965 " Override ASNs in outbound updates if aspath equals remote-as\n");
8966
8967 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8968 || CHECK_FLAG(p->af_flags[afi][safi],
8969 PEER_FLAG_FORCE_NEXTHOP_SELF))
8970 vty_out(vty, " NEXT_HOP is always this router\n");
8971 if (CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_AS_PATH_UNCHANGED))
8973 vty_out(vty,
8974 " AS_PATH is propagated unchanged to this neighbor\n");
8975 if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_NEXTHOP_UNCHANGED))
8977 vty_out(vty,
8978 " NEXT_HOP is propagated unchanged to this neighbor\n");
8979 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8980 vty_out(vty,
8981 " MED is propagated unchanged to this neighbor\n");
8982 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8983 || CHECK_FLAG(p->af_flags[afi][safi],
8984 PEER_FLAG_SEND_EXT_COMMUNITY)
8985 || CHECK_FLAG(p->af_flags[afi][safi],
8986 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8987 vty_out(vty,
8988 " Community attribute sent to this neighbor");
8989 if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_COMMUNITY)
8991 && CHECK_FLAG(p->af_flags[afi][safi],
8992 PEER_FLAG_SEND_EXT_COMMUNITY)
8993 && CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_SEND_LARGE_COMMUNITY))
8995 vty_out(vty, "(all)\n");
8996 else if (CHECK_FLAG(p->af_flags[afi][safi],
8997 PEER_FLAG_SEND_LARGE_COMMUNITY))
8998 vty_out(vty, "(large)\n");
8999 else if (CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_SEND_EXT_COMMUNITY))
9001 vty_out(vty, "(extended)\n");
9002 else
9003 vty_out(vty, "(standard)\n");
9004 }
9005 if (CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_DEFAULT_ORIGINATE)) {
9007 vty_out(vty, " Default information originate,");
9008
9009 if (p->default_rmap[afi][safi].name)
9010 vty_out(vty, " default route-map %s%s,",
9011 p->default_rmap[afi][safi].map ? "*"
9012 : "",
9013 p->default_rmap[afi][safi].name);
9014 if (paf && PAF_SUBGRP(paf)
9015 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9016 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9017 vty_out(vty, " default sent\n");
9018 else
9019 vty_out(vty, " default not sent\n");
9020 }
9021
dff8f48d
MK
9022 /* advertise-vni-all */
9023 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9024 if (is_evpn_enabled())
dff8f48d
MK
9025 vty_out(vty, " advertise-all-vni\n");
9026 }
9027
d62a17ae 9028 if (filter->plist[FILTER_IN].name
9029 || filter->dlist[FILTER_IN].name
9030 || filter->aslist[FILTER_IN].name
9031 || filter->map[RMAP_IN].name)
9032 vty_out(vty, " Inbound path policy configured\n");
9033 if (filter->plist[FILTER_OUT].name
9034 || filter->dlist[FILTER_OUT].name
9035 || filter->aslist[FILTER_OUT].name
9036 || filter->map[RMAP_OUT].name || filter->usmap.name)
9037 vty_out(vty, " Outbound path policy configured\n");
9038
9039 /* prefix-list */
9040 if (filter->plist[FILTER_IN].name)
9041 vty_out(vty,
9042 " Incoming update prefix filter list is %s%s\n",
9043 filter->plist[FILTER_IN].plist ? "*" : "",
9044 filter->plist[FILTER_IN].name);
9045 if (filter->plist[FILTER_OUT].name)
9046 vty_out(vty,
9047 " Outgoing update prefix filter list is %s%s\n",
9048 filter->plist[FILTER_OUT].plist ? "*" : "",
9049 filter->plist[FILTER_OUT].name);
9050
9051 /* distribute-list */
9052 if (filter->dlist[FILTER_IN].name)
9053 vty_out(vty,
9054 " Incoming update network filter list is %s%s\n",
9055 filter->dlist[FILTER_IN].alist ? "*" : "",
9056 filter->dlist[FILTER_IN].name);
9057 if (filter->dlist[FILTER_OUT].name)
9058 vty_out(vty,
9059 " Outgoing update network filter list is %s%s\n",
9060 filter->dlist[FILTER_OUT].alist ? "*" : "",
9061 filter->dlist[FILTER_OUT].name);
9062
9063 /* filter-list. */
9064 if (filter->aslist[FILTER_IN].name)
9065 vty_out(vty,
9066 " Incoming update AS path filter list is %s%s\n",
9067 filter->aslist[FILTER_IN].aslist ? "*" : "",
9068 filter->aslist[FILTER_IN].name);
9069 if (filter->aslist[FILTER_OUT].name)
9070 vty_out(vty,
9071 " Outgoing update AS path filter list is %s%s\n",
9072 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9073 filter->aslist[FILTER_OUT].name);
9074
9075 /* route-map. */
9076 if (filter->map[RMAP_IN].name)
9077 vty_out(vty,
9078 " Route map for incoming advertisements is %s%s\n",
9079 filter->map[RMAP_IN].map ? "*" : "",
9080 filter->map[RMAP_IN].name);
9081 if (filter->map[RMAP_OUT].name)
9082 vty_out(vty,
9083 " Route map for outgoing advertisements is %s%s\n",
9084 filter->map[RMAP_OUT].map ? "*" : "",
9085 filter->map[RMAP_OUT].name);
9086
9087 /* unsuppress-map */
9088 if (filter->usmap.name)
9089 vty_out(vty,
9090 " Route map for selective unsuppress is %s%s\n",
9091 filter->usmap.map ? "*" : "",
9092 filter->usmap.name);
9093
9094 /* Receive prefix count */
9095 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9096
9097 /* Maximum prefix */
9098 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9099 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9100 p->pmax[afi][safi],
9101 CHECK_FLAG(p->af_flags[afi][safi],
9102 PEER_FLAG_MAX_PREFIX_WARNING)
9103 ? " (warning-only)"
9104 : "");
9105 vty_out(vty, " Threshold for warning message %d%%",
9106 p->pmax_threshold[afi][safi]);
9107 if (p->pmax_restart[afi][safi])
9108 vty_out(vty, ", restart interval %d min",
9109 p->pmax_restart[afi][safi]);
9110 vty_out(vty, "\n");
9111 }
9112
9113 vty_out(vty, "\n");
9114 }
9115}
9116
9f049418 9117static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9118 json_object *json)
718e3744 9119{
d62a17ae 9120 struct bgp *bgp;
9121 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9122 char timebuf[BGP_UPTIME_LEN];
9123 char dn_flag[2];
9124 const char *subcode_str;
9125 const char *code_str;
9126 afi_t afi;
9127 safi_t safi;
d7c0a89a
QY
9128 uint16_t i;
9129 uint8_t *msg;
d62a17ae 9130 json_object *json_neigh = NULL;
9131 time_t epoch_tbuf;
718e3744 9132
d62a17ae 9133 bgp = p->bgp;
9134
9135 if (use_json)
9136 json_neigh = json_object_new_object();
9137
9138 memset(dn_flag, '\0', sizeof(dn_flag));
9139 if (!p->conf_if && peer_dynamic_neighbor(p))
9140 dn_flag[0] = '*';
9141
9142 if (!use_json) {
9143 if (p->conf_if) /* Configured interface name. */
9144 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9145 BGP_PEER_SU_UNSPEC(p)
9146 ? "None"
9147 : sockunion2str(&p->su, buf,
9148 SU_ADDRSTRLEN));
9149 else /* Configured IP address. */
9150 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9151 p->host);
9152 }
9153
9154 if (use_json) {
9155 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9156 json_object_string_add(json_neigh, "bgpNeighborAddr",
9157 "none");
9158 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9159 json_object_string_add(
9160 json_neigh, "bgpNeighborAddr",
9161 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9162
9163 json_object_int_add(json_neigh, "remoteAs", p->as);
9164
9165 if (p->change_local_as)
9166 json_object_int_add(json_neigh, "localAs",
9167 p->change_local_as);
9168 else
9169 json_object_int_add(json_neigh, "localAs", p->local_as);
9170
9171 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9172 json_object_boolean_true_add(json_neigh,
9173 "localAsNoPrepend");
9174
9175 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9176 json_object_boolean_true_add(json_neigh,
9177 "localAsReplaceAs");
9178 } else {
9179 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9180 || (p->as_type == AS_INTERNAL))
9181 vty_out(vty, "remote AS %u, ", p->as);
9182 else
9183 vty_out(vty, "remote AS Unspecified, ");
9184 vty_out(vty, "local AS %u%s%s, ",
9185 p->change_local_as ? p->change_local_as : p->local_as,
9186 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9187 ? " no-prepend"
9188 : "",
9189 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9190 ? " replace-as"
9191 : "");
9192 }
9193 /* peer type internal, external, confed-internal or confed-external */
9194 if (p->as == p->local_as) {
9195 if (use_json) {
9196 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9197 json_object_boolean_true_add(
9198 json_neigh, "nbrConfedInternalLink");
9199 else
9200 json_object_boolean_true_add(json_neigh,
9201 "nbrInternalLink");
9202 } else {
9203 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9204 vty_out(vty, "confed-internal link\n");
9205 else
9206 vty_out(vty, "internal link\n");
9207 }
9208 } else {
9209 if (use_json) {
9210 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9211 json_object_boolean_true_add(
9212 json_neigh, "nbrConfedExternalLink");
9213 else
9214 json_object_boolean_true_add(json_neigh,
9215 "nbrExternalLink");
9216 } else {
9217 if (bgp_confederation_peers_check(bgp, p->as))
9218 vty_out(vty, "confed-external link\n");
9219 else
9220 vty_out(vty, "external link\n");
9221 }
9222 }
9223
9224 /* Description. */
9225 if (p->desc) {
9226 if (use_json)
9227 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9228 else
9229 vty_out(vty, " Description: %s\n", p->desc);
9230 }
9231
9232 if (p->hostname) {
9233 if (use_json) {
9234 if (p->hostname)
9235 json_object_string_add(json_neigh, "hostname",
9236 p->hostname);
9237
9238 if (p->domainname)
9239 json_object_string_add(json_neigh, "domainname",
9240 p->domainname);
9241 } else {
9242 if (p->domainname && (p->domainname[0] != '\0'))
9243 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9244 p->domainname);
9245 else
9246 vty_out(vty, "Hostname: %s\n", p->hostname);
9247 }
9248 }
9249
9250 /* Peer-group */
9251 if (p->group) {
9252 if (use_json) {
9253 json_object_string_add(json_neigh, "peerGroup",
9254 p->group->name);
9255
9256 if (dn_flag[0]) {
9257 struct prefix prefix, *range = NULL;
9258
9259 sockunion2hostprefix(&(p->su), &prefix);
9260 range = peer_group_lookup_dynamic_neighbor_range(
9261 p->group, &prefix);
9262
9263 if (range) {
9264 prefix2str(range, buf1, sizeof(buf1));
9265 json_object_string_add(
9266 json_neigh,
9267 "peerSubnetRangeGroup", buf1);
9268 }
9269 }
9270 } else {
9271 vty_out(vty,
9272 " Member of peer-group %s for session parameters\n",
9273 p->group->name);
9274
9275 if (dn_flag[0]) {
9276 struct prefix prefix, *range = NULL;
9277
9278 sockunion2hostprefix(&(p->su), &prefix);
9279 range = peer_group_lookup_dynamic_neighbor_range(
9280 p->group, &prefix);
9281
9282 if (range) {
9283 prefix2str(range, buf1, sizeof(buf1));
9284 vty_out(vty,
9285 " Belongs to the subnet range group: %s\n",
9286 buf1);
9287 }
9288 }
9289 }
9290 }
9291
9292 if (use_json) {
9293 /* Administrative shutdown. */
9294 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9295 json_object_boolean_true_add(json_neigh,
9296 "adminShutDown");
9297
9298 /* BGP Version. */
9299 json_object_int_add(json_neigh, "bgpVersion", 4);
9300 json_object_string_add(
9301 json_neigh, "remoteRouterId",
9302 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9303 json_object_string_add(
9304 json_neigh, "localRouterId",
9305 inet_ntop(AF_INET, &bgp->router_id, buf1,
9306 sizeof(buf1)));
d62a17ae 9307
9308 /* Confederation */
9309 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9310 && bgp_confederation_peers_check(bgp, p->as))
9311 json_object_boolean_true_add(json_neigh,
9312 "nbrCommonAdmin");
9313
9314 /* Status. */
9315 json_object_string_add(
9316 json_neigh, "bgpState",
9317 lookup_msg(bgp_status_msg, p->status, NULL));
9318
9319 if (p->status == Established) {
9320 time_t uptime;
d62a17ae 9321
9322 uptime = bgp_clock();
9323 uptime -= p->uptime;
d62a17ae 9324 epoch_tbuf = time(NULL) - uptime;
9325
bee57a7a 9326#if CONFDATE > 20200101
a4d82a8a
PZ
9327 CPP_NOTICE(
9328 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9329#endif
9330 /*
9331 * bgpTimerUp was miliseconds that was accurate
9332 * up to 1 day, then the value returned
9333 * became garbage. So in order to provide
9334 * some level of backwards compatability,
9335 * we still provde the data, but now
9336 * we are returning the correct value
9337 * and also adding a new bgpTimerUpMsec
9338 * which will allow us to deprecate
9339 * this eventually
9340 */
d62a17ae 9341 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9342 uptime * 1000);
d3c7efed
DS
9343 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9344 uptime * 1000);
d62a17ae 9345 json_object_string_add(json_neigh, "bgpTimerUpString",
9346 peer_uptime(p->uptime, timebuf,
9347 BGP_UPTIME_LEN, 0,
9348 NULL));
9349 json_object_int_add(json_neigh,
9350 "bgpTimerUpEstablishedEpoch",
9351 epoch_tbuf);
9352 }
9353
9354 else if (p->status == Active) {
9355 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9356 json_object_string_add(json_neigh, "bgpStateIs",
9357 "passive");
9358 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9359 json_object_string_add(json_neigh, "bgpStateIs",
9360 "passiveNSF");
9361 }
9362
9363 /* read timer */
9364 time_t uptime;
9365 struct tm *tm;
9366
9367 uptime = bgp_clock();
9368 uptime -= p->readtime;
9369 tm = gmtime(&uptime);
9370 json_object_int_add(json_neigh, "bgpTimerLastRead",
9371 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9372 + (tm->tm_hour * 3600000));
9373
9374 uptime = bgp_clock();
9375 uptime -= p->last_write;
9376 tm = gmtime(&uptime);
9377 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9378 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9379 + (tm->tm_hour * 3600000));
9380
9381 uptime = bgp_clock();
9382 uptime -= p->update_time;
9383 tm = gmtime(&uptime);
9384 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9385 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9386 + (tm->tm_hour * 3600000));
9387
9388 /* Configured timer values. */
9389 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9390 p->v_holdtime * 1000);
9391 json_object_int_add(json_neigh,
9392 "bgpTimerKeepAliveIntervalMsecs",
9393 p->v_keepalive * 1000);
b90a8e13 9394 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9395 json_object_int_add(json_neigh,
9396 "bgpTimerConfiguredHoldTimeMsecs",
9397 p->holdtime * 1000);
9398 json_object_int_add(
9399 json_neigh,
9400 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9401 p->keepalive * 1000);
d25e4efc 9402 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9403 || (bgp->default_keepalive
9404 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9405 json_object_int_add(json_neigh,
9406 "bgpTimerConfiguredHoldTimeMsecs",
9407 bgp->default_holdtime);
9408 json_object_int_add(
9409 json_neigh,
9410 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9411 bgp->default_keepalive);
d62a17ae 9412 }
9413 } else {
9414 /* Administrative shutdown. */
9415 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9416 vty_out(vty, " Administratively shut down\n");
9417
9418 /* BGP Version. */
9419 vty_out(vty, " BGP version 4");
0e38aeb4 9420 vty_out(vty, ", remote router ID %s",
d62a17ae 9421 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9422 vty_out(vty, ", local router ID %s\n",
9423 inet_ntop(AF_INET, &bgp->router_id, buf1,
9424 sizeof(buf1)));
d62a17ae 9425
9426 /* Confederation */
9427 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9428 && bgp_confederation_peers_check(bgp, p->as))
9429 vty_out(vty,
9430 " Neighbor under common administration\n");
9431
9432 /* Status. */
9433 vty_out(vty, " BGP state = %s",
9434 lookup_msg(bgp_status_msg, p->status, NULL));
9435
9436 if (p->status == Established)
9437 vty_out(vty, ", up for %8s",
9438 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9439 0, NULL));
9440
9441 else if (p->status == Active) {
9442 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9443 vty_out(vty, " (passive)");
9444 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9445 vty_out(vty, " (NSF passive)");
9446 }
9447 vty_out(vty, "\n");
9448
9449 /* read timer */
9450 vty_out(vty, " Last read %s",
9451 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9452 NULL));
9453 vty_out(vty, ", Last write %s\n",
9454 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9455 NULL));
9456
9457 /* Configured timer values. */
9458 vty_out(vty,
9459 " Hold time is %d, keepalive interval is %d seconds\n",
9460 p->v_holdtime, p->v_keepalive);
b90a8e13 9461 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9462 vty_out(vty, " Configured hold time is %d",
9463 p->holdtime);
9464 vty_out(vty, ", keepalive interval is %d seconds\n",
9465 p->keepalive);
d25e4efc 9466 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9467 || (bgp->default_keepalive
9468 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9469 vty_out(vty, " Configured hold time is %d",
9470 bgp->default_holdtime);
9471 vty_out(vty, ", keepalive interval is %d seconds\n",
9472 bgp->default_keepalive);
d62a17ae 9473 }
9474 }
9475 /* Capability. */
9476 if (p->status == Established) {
9477 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9478 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9479 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9480 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9481 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9482 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9483 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9484 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9485 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9486 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9487 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9488 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9489 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9490 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9491 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9492 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9493 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9494 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9495 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9496 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9497 if (use_json) {
9498 json_object *json_cap = NULL;
9499
9500 json_cap = json_object_new_object();
9501
9502 /* AS4 */
9503 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9504 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9505 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9506 && CHECK_FLAG(p->cap,
9507 PEER_CAP_AS4_RCV))
9508 json_object_string_add(
9509 json_cap, "4byteAs",
9510 "advertisedAndReceived");
9511 else if (CHECK_FLAG(p->cap,
9512 PEER_CAP_AS4_ADV))
9513 json_object_string_add(
9514 json_cap, "4byteAs",
9515 "advertised");
9516 else if (CHECK_FLAG(p->cap,
9517 PEER_CAP_AS4_RCV))
9518 json_object_string_add(
9519 json_cap, "4byteAs",
9520 "received");
9521 }
9522
9523 /* AddPath */
9524 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9525 || CHECK_FLAG(p->cap,
9526 PEER_CAP_ADDPATH_ADV)) {
9527 json_object *json_add = NULL;
9528 const char *print_store;
9529
9530 json_add = json_object_new_object();
9531
05c7a1cc
QY
9532 FOREACH_AFI_SAFI (afi, safi) {
9533 json_object *json_sub = NULL;
9534 json_sub =
9535 json_object_new_object();
9536 print_store = afi_safi_print(
9537 afi, safi);
d62a17ae 9538
05c7a1cc
QY
9539 if (CHECK_FLAG(
9540 p->af_cap[afi]
9541 [safi],
9542 PEER_CAP_ADDPATH_AF_TX_ADV)
9543 || CHECK_FLAG(
9544 p->af_cap[afi]
9545 [safi],
9546 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9547 if (CHECK_FLAG(
9548 p->af_cap
9549 [afi]
9550 [safi],
9551 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9552 && CHECK_FLAG(
d62a17ae 9553 p->af_cap
9554 [afi]
9555 [safi],
05c7a1cc
QY
9556 PEER_CAP_ADDPATH_AF_TX_RCV))
9557 json_object_boolean_true_add(
9558 json_sub,
9559 "txAdvertisedAndReceived");
9560 else if (
9561 CHECK_FLAG(
9562 p->af_cap
9563 [afi]
9564 [safi],
9565 PEER_CAP_ADDPATH_AF_TX_ADV))
9566 json_object_boolean_true_add(
9567 json_sub,
9568 "txAdvertised");
9569 else if (
9570 CHECK_FLAG(
9571 p->af_cap
9572 [afi]
9573 [safi],
9574 PEER_CAP_ADDPATH_AF_TX_RCV))
9575 json_object_boolean_true_add(
9576 json_sub,
9577 "txReceived");
9578 }
d62a17ae 9579
05c7a1cc
QY
9580 if (CHECK_FLAG(
9581 p->af_cap[afi]
9582 [safi],
9583 PEER_CAP_ADDPATH_AF_RX_ADV)
9584 || CHECK_FLAG(
9585 p->af_cap[afi]
9586 [safi],
9587 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9588 if (CHECK_FLAG(
9589 p->af_cap
9590 [afi]
9591 [safi],
9592 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9593 && CHECK_FLAG(
d62a17ae 9594 p->af_cap
9595 [afi]
9596 [safi],
9597 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9598 json_object_boolean_true_add(
9599 json_sub,
9600 "rxAdvertisedAndReceived");
9601 else if (
9602 CHECK_FLAG(
9603 p->af_cap
9604 [afi]
9605 [safi],
9606 PEER_CAP_ADDPATH_AF_RX_ADV))
9607 json_object_boolean_true_add(
9608 json_sub,
9609 "rxAdvertised");
9610 else if (
9611 CHECK_FLAG(
9612 p->af_cap
9613 [afi]
9614 [safi],
9615 PEER_CAP_ADDPATH_AF_RX_RCV))
9616 json_object_boolean_true_add(
9617 json_sub,
9618 "rxReceived");
d62a17ae 9619 }
9620
05c7a1cc
QY
9621 if (CHECK_FLAG(
9622 p->af_cap[afi]
9623 [safi],
9624 PEER_CAP_ADDPATH_AF_TX_ADV)
9625 || CHECK_FLAG(
9626 p->af_cap[afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_RCV)
9629 || CHECK_FLAG(
9630 p->af_cap[afi]
9631 [safi],
9632 PEER_CAP_ADDPATH_AF_RX_ADV)
9633 || CHECK_FLAG(
9634 p->af_cap[afi]
9635 [safi],
9636 PEER_CAP_ADDPATH_AF_RX_RCV))
9637 json_object_object_add(
9638 json_add,
9639 print_store,
9640 json_sub);
9641 else
9642 json_object_free(
9643 json_sub);
9644 }
9645
d62a17ae 9646 json_object_object_add(
9647 json_cap, "addPath", json_add);
9648 }
9649
9650 /* Dynamic */
9651 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9652 || CHECK_FLAG(p->cap,
9653 PEER_CAP_DYNAMIC_ADV)) {
9654 if (CHECK_FLAG(p->cap,
9655 PEER_CAP_DYNAMIC_ADV)
9656 && CHECK_FLAG(p->cap,
9657 PEER_CAP_DYNAMIC_RCV))
9658 json_object_string_add(
9659 json_cap, "dynamic",
9660 "advertisedAndReceived");
9661 else if (CHECK_FLAG(
9662 p->cap,
9663 PEER_CAP_DYNAMIC_ADV))
9664 json_object_string_add(
9665 json_cap, "dynamic",
9666 "advertised");
9667 else if (CHECK_FLAG(
9668 p->cap,
9669 PEER_CAP_DYNAMIC_RCV))
9670 json_object_string_add(
9671 json_cap, "dynamic",
9672 "received");
9673 }
9674
9675 /* Extended nexthop */
9676 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9677 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9678 json_object *json_nxt = NULL;
9679 const char *print_store;
9680
9681
9682 if (CHECK_FLAG(p->cap,
9683 PEER_CAP_ENHE_ADV)
9684 && CHECK_FLAG(p->cap,
9685 PEER_CAP_ENHE_RCV))
9686 json_object_string_add(
9687 json_cap,
9688 "extendedNexthop",
9689 "advertisedAndReceived");
9690 else if (CHECK_FLAG(p->cap,
9691 PEER_CAP_ENHE_ADV))
9692 json_object_string_add(
9693 json_cap,
9694 "extendedNexthop",
9695 "advertised");
9696 else if (CHECK_FLAG(p->cap,
9697 PEER_CAP_ENHE_RCV))
9698 json_object_string_add(
9699 json_cap,
9700 "extendedNexthop",
9701 "received");
9702
9703 if (CHECK_FLAG(p->cap,
9704 PEER_CAP_ENHE_RCV)) {
9705 json_nxt =
9706 json_object_new_object();
9707
9708 for (safi = SAFI_UNICAST;
9709 safi < SAFI_MAX; safi++) {
9710 if (CHECK_FLAG(
9711 p->af_cap
9712 [AFI_IP]
9713 [safi],
9714 PEER_CAP_ENHE_AF_RCV)) {
9715 print_store = afi_safi_print(
9716 AFI_IP,
9717 safi);
9718 json_object_string_add(
9719 json_nxt,
9720 print_store,
0437e105 9721 "received");
d62a17ae 9722 }
9723 }
9724 json_object_object_add(
9725 json_cap,
9726 "extendedNexthopFamililesByPeer",
9727 json_nxt);
9728 }
9729 }
9730
9731 /* Route Refresh */
9732 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9733 || CHECK_FLAG(p->cap,
9734 PEER_CAP_REFRESH_NEW_RCV)
9735 || CHECK_FLAG(p->cap,
9736 PEER_CAP_REFRESH_OLD_RCV)) {
9737 if (CHECK_FLAG(p->cap,
9738 PEER_CAP_REFRESH_ADV)
9739 && (CHECK_FLAG(
9740 p->cap,
9741 PEER_CAP_REFRESH_NEW_RCV)
9742 || CHECK_FLAG(
9743 p->cap,
9744 PEER_CAP_REFRESH_OLD_RCV))) {
9745 if (CHECK_FLAG(
9746 p->cap,
9747 PEER_CAP_REFRESH_OLD_RCV)
9748 && CHECK_FLAG(
9749 p->cap,
9750 PEER_CAP_REFRESH_NEW_RCV))
9751 json_object_string_add(
9752 json_cap,
9753 "routeRefresh",
9754 "advertisedAndReceivedOldNew");
9755 else {
9756 if (CHECK_FLAG(
9757 p->cap,
9758 PEER_CAP_REFRESH_OLD_RCV))
9759 json_object_string_add(
9760 json_cap,
9761 "routeRefresh",
9762 "advertisedAndReceivedOld");
9763 else
9764 json_object_string_add(
9765 json_cap,
9766 "routeRefresh",
9767 "advertisedAndReceivedNew");
9768 }
9769 } else if (
9770 CHECK_FLAG(
9771 p->cap,
9772 PEER_CAP_REFRESH_ADV))
9773 json_object_string_add(
9774 json_cap,
9775 "routeRefresh",
9776 "advertised");
9777 else if (
9778 CHECK_FLAG(
9779 p->cap,
9780 PEER_CAP_REFRESH_NEW_RCV)
9781 || CHECK_FLAG(
9782 p->cap,
9783 PEER_CAP_REFRESH_OLD_RCV))
9784 json_object_string_add(
9785 json_cap,
9786 "routeRefresh",
9787 "received");
9788 }
9789
9790 /* Multiprotocol Extensions */
9791 json_object *json_multi = NULL;
9792 json_multi = json_object_new_object();
9793
05c7a1cc
QY
9794 FOREACH_AFI_SAFI (afi, safi) {
9795 if (p->afc_adv[afi][safi]
9796 || p->afc_recv[afi][safi]) {
9797 json_object *json_exten = NULL;
9798 json_exten =
9799 json_object_new_object();
9800
d62a17ae 9801 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9802 && p->afc_recv[afi][safi])
9803 json_object_boolean_true_add(
9804 json_exten,
9805 "advertisedAndReceived");
9806 else if (p->afc_adv[afi][safi])
9807 json_object_boolean_true_add(
9808 json_exten,
9809 "advertised");
9810 else if (p->afc_recv[afi][safi])
9811 json_object_boolean_true_add(
9812 json_exten,
9813 "received");
d62a17ae 9814
05c7a1cc
QY
9815 json_object_object_add(
9816 json_multi,
9817 afi_safi_print(afi,
9818 safi),
9819 json_exten);
d62a17ae 9820 }
9821 }
9822 json_object_object_add(
9823 json_cap, "multiprotocolExtensions",
9824 json_multi);
9825
d77114b7 9826 /* Hostname capabilities */
60466a63 9827 json_object *json_hname = NULL;
d77114b7
MK
9828
9829 json_hname = json_object_new_object();
9830
9831 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9832 json_object_string_add(
60466a63
QY
9833 json_hname, "advHostName",
9834 bgp->peer_self->hostname
9835 ? bgp->peer_self
9836 ->hostname
d77114b7
MK
9837 : "n/a");
9838 json_object_string_add(
60466a63
QY
9839 json_hname, "advDomainName",
9840 bgp->peer_self->domainname
9841 ? bgp->peer_self
9842 ->domainname
d77114b7
MK
9843 : "n/a");
9844 }
9845
9846
9847 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9848 json_object_string_add(
60466a63
QY
9849 json_hname, "rcvHostName",
9850 p->hostname ? p->hostname
9851 : "n/a");
d77114b7 9852 json_object_string_add(
60466a63
QY
9853 json_hname, "rcvDomainName",
9854 p->domainname ? p->domainname
9855 : "n/a");
d77114b7
MK
9856 }
9857
60466a63 9858 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9859 json_hname);
9860
d62a17ae 9861 /* Gracefull Restart */
9862 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9863 || CHECK_FLAG(p->cap,
9864 PEER_CAP_RESTART_ADV)) {
9865 if (CHECK_FLAG(p->cap,
9866 PEER_CAP_RESTART_ADV)
9867 && CHECK_FLAG(p->cap,
9868 PEER_CAP_RESTART_RCV))
9869 json_object_string_add(
9870 json_cap,
9871 "gracefulRestart",
9872 "advertisedAndReceived");
9873 else if (CHECK_FLAG(
9874 p->cap,
9875 PEER_CAP_RESTART_ADV))
9876 json_object_string_add(
9877 json_cap,
9878 "gracefulRestartCapability",
9879 "advertised");
9880 else if (CHECK_FLAG(
9881 p->cap,
9882 PEER_CAP_RESTART_RCV))
9883 json_object_string_add(
9884 json_cap,
9885 "gracefulRestartCapability",
9886 "received");
9887
9888 if (CHECK_FLAG(p->cap,
9889 PEER_CAP_RESTART_RCV)) {
9890 int restart_af_count = 0;
9891 json_object *json_restart =
9892 NULL;
9893 json_restart =
9894 json_object_new_object();
9895
9896 json_object_int_add(
9897 json_cap,
9898 "gracefulRestartRemoteTimerMsecs",
9899 p->v_gr_restart * 1000);
9900
05c7a1cc
QY
9901 FOREACH_AFI_SAFI (afi, safi) {
9902 if (CHECK_FLAG(
9903 p->af_cap
9904 [afi]
9905 [safi],
9906 PEER_CAP_RESTART_AF_RCV)) {
9907 json_object *
9908 json_sub =
9909 NULL;
9910 json_sub =
9911 json_object_new_object();
9912
d62a17ae 9913 if (CHECK_FLAG(
9914 p->af_cap
9915 [afi]
9916 [safi],
05c7a1cc
QY
9917 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9918 json_object_boolean_true_add(
9919 json_sub,
9920 "preserved");
9921 restart_af_count++;
9922 json_object_object_add(
9923 json_restart,
9924 afi_safi_print(
9925 afi,
9926 safi),
9927 json_sub);
d62a17ae 9928 }
9929 }
9930 if (!restart_af_count) {
9931 json_object_string_add(
9932 json_cap,
9933 "addressFamiliesByPeer",
9934 "none");
9935 json_object_free(
9936 json_restart);
9937 } else
9938 json_object_object_add(
9939 json_cap,
9940 "addressFamiliesByPeer",
9941 json_restart);
9942 }
9943 }
9944 json_object_object_add(json_neigh,
9945 "neighborCapabilities",
9946 json_cap);
9947 } else {
9948 vty_out(vty, " Neighbor capabilities:\n");
9949
9950 /* AS4 */
9951 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9952 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9953 vty_out(vty, " 4 Byte AS:");
9954 if (CHECK_FLAG(p->cap,
9955 PEER_CAP_AS4_ADV))
9956 vty_out(vty, " advertised");
9957 if (CHECK_FLAG(p->cap,
9958 PEER_CAP_AS4_RCV))
9959 vty_out(vty, " %sreceived",
9960 CHECK_FLAG(
9961 p->cap,
9962 PEER_CAP_AS4_ADV)
9963 ? "and "
9964 : "");
9965 vty_out(vty, "\n");
9966 }
9967
9968 /* AddPath */
9969 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9970 || CHECK_FLAG(p->cap,
9971 PEER_CAP_ADDPATH_ADV)) {
9972 vty_out(vty, " AddPath:\n");
9973
05c7a1cc
QY
9974 FOREACH_AFI_SAFI (afi, safi) {
9975 if (CHECK_FLAG(
9976 p->af_cap[afi]
9977 [safi],
9978 PEER_CAP_ADDPATH_AF_TX_ADV)
9979 || CHECK_FLAG(
9980 p->af_cap[afi]
9981 [safi],
9982 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9983 vty_out(vty,
9984 " %s: TX ",
9985 afi_safi_print(
9986 afi,
9987 safi));
9988
d62a17ae 9989 if (CHECK_FLAG(
9990 p->af_cap
9991 [afi]
9992 [safi],
05c7a1cc 9993 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9994 vty_out(vty,
05c7a1cc 9995 "advertised %s",
d62a17ae 9996 afi_safi_print(
9997 afi,
9998 safi));
9999
05c7a1cc
QY
10000 if (CHECK_FLAG(
10001 p->af_cap
10002 [afi]
10003 [safi],
10004 PEER_CAP_ADDPATH_AF_TX_RCV))
10005 vty_out(vty,
10006 "%sreceived",
10007 CHECK_FLAG(
10008 p->af_cap
10009 [afi]
10010 [safi],
10011 PEER_CAP_ADDPATH_AF_TX_ADV)
10012 ? " and "
10013 : "");
d62a17ae 10014
05c7a1cc
QY
10015 vty_out(vty, "\n");
10016 }
d62a17ae 10017
05c7a1cc
QY
10018 if (CHECK_FLAG(
10019 p->af_cap[afi]
10020 [safi],
10021 PEER_CAP_ADDPATH_AF_RX_ADV)
10022 || CHECK_FLAG(
10023 p->af_cap[afi]
10024 [safi],
10025 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10026 vty_out(vty,
10027 " %s: RX ",
10028 afi_safi_print(
10029 afi,
10030 safi));
d62a17ae 10031
10032 if (CHECK_FLAG(
10033 p->af_cap
10034 [afi]
10035 [safi],
05c7a1cc 10036 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10037 vty_out(vty,
05c7a1cc 10038 "advertised %s",
d62a17ae 10039 afi_safi_print(
10040 afi,
10041 safi));
10042
05c7a1cc
QY
10043 if (CHECK_FLAG(
10044 p->af_cap
10045 [afi]
10046 [safi],
10047 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10048 vty_out(vty,
05c7a1cc
QY
10049 "%sreceived",
10050 CHECK_FLAG(
10051 p->af_cap
10052 [afi]
10053 [safi],
10054 PEER_CAP_ADDPATH_AF_RX_ADV)
10055 ? " and "
10056 : "");
10057
10058 vty_out(vty, "\n");
d62a17ae 10059 }
05c7a1cc 10060 }
d62a17ae 10061 }
10062
10063 /* Dynamic */
10064 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10065 || CHECK_FLAG(p->cap,
10066 PEER_CAP_DYNAMIC_ADV)) {
10067 vty_out(vty, " Dynamic:");
10068 if (CHECK_FLAG(p->cap,
10069 PEER_CAP_DYNAMIC_ADV))
10070 vty_out(vty, " advertised");
10071 if (CHECK_FLAG(p->cap,
10072 PEER_CAP_DYNAMIC_RCV))
10073 vty_out(vty, " %sreceived",
10074 CHECK_FLAG(
10075 p->cap,
10076 PEER_CAP_DYNAMIC_ADV)
10077 ? "and "
10078 : "");
10079 vty_out(vty, "\n");
10080 }
10081
10082 /* Extended nexthop */
10083 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10084 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10085 vty_out(vty, " Extended nexthop:");
10086 if (CHECK_FLAG(p->cap,
10087 PEER_CAP_ENHE_ADV))
10088 vty_out(vty, " advertised");
10089 if (CHECK_FLAG(p->cap,
10090 PEER_CAP_ENHE_RCV))
10091 vty_out(vty, " %sreceived",
10092 CHECK_FLAG(
10093 p->cap,
10094 PEER_CAP_ENHE_ADV)
10095 ? "and "
10096 : "");
10097 vty_out(vty, "\n");
10098
10099 if (CHECK_FLAG(p->cap,
10100 PEER_CAP_ENHE_RCV)) {
10101 vty_out(vty,
10102 " Address families by peer:\n ");
10103 for (safi = SAFI_UNICAST;
10104 safi < SAFI_MAX; safi++)
10105 if (CHECK_FLAG(
10106 p->af_cap
10107 [AFI_IP]
10108 [safi],
10109 PEER_CAP_ENHE_AF_RCV))
10110 vty_out(vty,
10111 " %s\n",
10112 afi_safi_print(
10113 AFI_IP,
10114 safi));
10115 }
10116 }
10117
10118 /* Route Refresh */
10119 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10120 || CHECK_FLAG(p->cap,
10121 PEER_CAP_REFRESH_NEW_RCV)
10122 || CHECK_FLAG(p->cap,
10123 PEER_CAP_REFRESH_OLD_RCV)) {
10124 vty_out(vty, " Route refresh:");
10125 if (CHECK_FLAG(p->cap,
10126 PEER_CAP_REFRESH_ADV))
10127 vty_out(vty, " advertised");
10128 if (CHECK_FLAG(p->cap,
10129 PEER_CAP_REFRESH_NEW_RCV)
10130 || CHECK_FLAG(
10131 p->cap,
10132 PEER_CAP_REFRESH_OLD_RCV))
10133 vty_out(vty, " %sreceived(%s)",
10134 CHECK_FLAG(
10135 p->cap,
10136 PEER_CAP_REFRESH_ADV)
10137 ? "and "
10138 : "",
10139 (CHECK_FLAG(
10140 p->cap,
10141 PEER_CAP_REFRESH_OLD_RCV)
10142 && CHECK_FLAG(
10143 p->cap,
10144 PEER_CAP_REFRESH_NEW_RCV))
10145 ? "old & new"
10146 : CHECK_FLAG(
10147 p->cap,
10148 PEER_CAP_REFRESH_OLD_RCV)
10149 ? "old"
10150 : "new");
10151
10152 vty_out(vty, "\n");
10153 }
10154
10155 /* Multiprotocol Extensions */
05c7a1cc
QY
10156 FOREACH_AFI_SAFI (afi, safi)
10157 if (p->afc_adv[afi][safi]
10158 || p->afc_recv[afi][safi]) {
10159 vty_out(vty,
10160 " Address Family %s:",
10161 afi_safi_print(afi,
10162 safi));
10163 if (p->afc_adv[afi][safi])
d62a17ae 10164 vty_out(vty,
05c7a1cc
QY
10165 " advertised");
10166 if (p->afc_recv[afi][safi])
10167 vty_out(vty,
10168 " %sreceived",
10169 p->afc_adv[afi]
10170 [safi]
10171 ? "and "
10172 : "");
10173 vty_out(vty, "\n");
10174 }
d62a17ae 10175
10176 /* Hostname capability */
60466a63 10177 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10178
10179 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10180 vty_out(vty,
10181 " advertised (name: %s,domain name: %s)",
60466a63
QY
10182 bgp->peer_self->hostname
10183 ? bgp->peer_self
10184 ->hostname
d77114b7 10185 : "n/a",
60466a63
QY
10186 bgp->peer_self->domainname
10187 ? bgp->peer_self
10188 ->domainname
d77114b7
MK
10189 : "n/a");
10190 } else {
10191 vty_out(vty, " not advertised");
d62a17ae 10192 }
10193
d77114b7 10194 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10195 vty_out(vty,
10196 " received (name: %s,domain name: %s)",
60466a63
QY
10197 p->hostname ? p->hostname
10198 : "n/a",
10199 p->domainname ? p->domainname
10200 : "n/a");
d77114b7
MK
10201 } else {
10202 vty_out(vty, " not received");
10203 }
10204
10205 vty_out(vty, "\n");
10206
d62a17ae 10207 /* Gracefull Restart */
10208 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10209 || CHECK_FLAG(p->cap,
10210 PEER_CAP_RESTART_ADV)) {
10211 vty_out(vty,
10212 " Graceful Restart Capabilty:");
10213 if (CHECK_FLAG(p->cap,
10214 PEER_CAP_RESTART_ADV))
10215 vty_out(vty, " advertised");
10216 if (CHECK_FLAG(p->cap,
10217 PEER_CAP_RESTART_RCV))
10218 vty_out(vty, " %sreceived",
10219 CHECK_FLAG(
10220 p->cap,
10221 PEER_CAP_RESTART_ADV)
10222 ? "and "
10223 : "");
10224 vty_out(vty, "\n");
10225
10226 if (CHECK_FLAG(p->cap,
10227 PEER_CAP_RESTART_RCV)) {
10228 int restart_af_count = 0;
10229
10230 vty_out(vty,
10231 " Remote Restart timer is %d seconds\n",
10232 p->v_gr_restart);
10233 vty_out(vty,
10234 " Address families by peer:\n ");
10235
05c7a1cc
QY
10236 FOREACH_AFI_SAFI (afi, safi)
10237 if (CHECK_FLAG(
10238 p->af_cap
10239 [afi]
10240 [safi],
10241 PEER_CAP_RESTART_AF_RCV)) {
10242 vty_out(vty,
10243 "%s%s(%s)",
10244 restart_af_count
10245 ? ", "
10246 : "",
10247 afi_safi_print(
10248 afi,
10249 safi),
10250 CHECK_FLAG(
10251 p->af_cap
10252 [afi]
10253 [safi],
10254 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10255 ? "preserved"
10256 : "not preserved");
10257 restart_af_count++;
10258 }
d62a17ae 10259 if (!restart_af_count)
10260 vty_out(vty, "none");
10261 vty_out(vty, "\n");
10262 }
10263 }
10264 }
10265 }
10266 }
10267
10268 /* graceful restart information */
10269 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10270 || p->t_gr_stale) {
10271 json_object *json_grace = NULL;
10272 json_object *json_grace_send = NULL;
10273 json_object *json_grace_recv = NULL;
10274 int eor_send_af_count = 0;
10275 int eor_receive_af_count = 0;
10276
10277 if (use_json) {
10278 json_grace = json_object_new_object();
10279 json_grace_send = json_object_new_object();
10280 json_grace_recv = json_object_new_object();
10281
10282 if (p->status == Established) {
05c7a1cc
QY
10283 FOREACH_AFI_SAFI (afi, safi) {
10284 if (CHECK_FLAG(p->af_sflags[afi][safi],
10285 PEER_STATUS_EOR_SEND)) {
10286 json_object_boolean_true_add(
10287 json_grace_send,
10288 afi_safi_print(afi,
10289 safi));
10290 eor_send_af_count++;
d62a17ae 10291 }
10292 }
05c7a1cc
QY
10293 FOREACH_AFI_SAFI (afi, safi) {
10294 if (CHECK_FLAG(
10295 p->af_sflags[afi][safi],
10296 PEER_STATUS_EOR_RECEIVED)) {
10297 json_object_boolean_true_add(
10298 json_grace_recv,
10299 afi_safi_print(afi,
10300 safi));
10301 eor_receive_af_count++;
d62a17ae 10302 }
10303 }
10304 }
10305
10306 json_object_object_add(json_grace, "endOfRibSend",
10307 json_grace_send);
10308 json_object_object_add(json_grace, "endOfRibRecv",
10309 json_grace_recv);
10310
10311 if (p->t_gr_restart)
10312 json_object_int_add(json_grace,
10313 "gracefulRestartTimerMsecs",
10314 thread_timer_remain_second(
10315 p->t_gr_restart)
10316 * 1000);
10317
10318 if (p->t_gr_stale)
10319 json_object_int_add(
10320 json_grace,
10321 "gracefulStalepathTimerMsecs",
10322 thread_timer_remain_second(
10323 p->t_gr_stale)
10324 * 1000);
10325
10326 json_object_object_add(
10327 json_neigh, "gracefulRestartInfo", json_grace);
10328 } else {
0437e105 10329 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10330 if (p->status == Established) {
10331 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10332 FOREACH_AFI_SAFI (afi, safi) {
10333 if (CHECK_FLAG(p->af_sflags[afi][safi],
10334 PEER_STATUS_EOR_SEND)) {
10335 vty_out(vty, "%s%s",
10336 eor_send_af_count ? ", "
10337 : "",
10338 afi_safi_print(afi,
10339 safi));
10340 eor_send_af_count++;
d62a17ae 10341 }
10342 }
10343 vty_out(vty, "\n");
10344 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10345 FOREACH_AFI_SAFI (afi, safi) {
10346 if (CHECK_FLAG(
10347 p->af_sflags[afi][safi],
10348 PEER_STATUS_EOR_RECEIVED)) {
10349 vty_out(vty, "%s%s",
10350 eor_receive_af_count
10351 ? ", "
10352 : "",
10353 afi_safi_print(afi,
10354 safi));
10355 eor_receive_af_count++;
d62a17ae 10356 }
10357 }
10358 vty_out(vty, "\n");
10359 }
10360
10361 if (p->t_gr_restart)
10362 vty_out(vty,
10363 " The remaining time of restart timer is %ld\n",
10364 thread_timer_remain_second(
10365 p->t_gr_restart));
10366
10367 if (p->t_gr_stale)
10368 vty_out(vty,
10369 " The remaining time of stalepath timer is %ld\n",
10370 thread_timer_remain_second(
10371 p->t_gr_stale));
10372 }
10373 }
10374 if (use_json) {
10375 json_object *json_stat = NULL;
10376 json_stat = json_object_new_object();
10377 /* Packet counts. */
10378 json_object_int_add(json_stat, "depthInq", 0);
10379 json_object_int_add(json_stat, "depthOutq",
10380 (unsigned long)p->obuf->count);
0112e9e0
QY
10381 json_object_int_add(json_stat, "opensSent",
10382 atomic_load_explicit(&p->open_out,
10383 memory_order_relaxed));
10384 json_object_int_add(json_stat, "opensRecv",
10385 atomic_load_explicit(&p->open_in,
10386 memory_order_relaxed));
d62a17ae 10387 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10388 atomic_load_explicit(&p->notify_out,
10389 memory_order_relaxed));
d62a17ae 10390 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10391 atomic_load_explicit(&p->notify_in,
10392 memory_order_relaxed));
10393 json_object_int_add(json_stat, "updatesSent",
10394 atomic_load_explicit(&p->update_out,
10395 memory_order_relaxed));
10396 json_object_int_add(json_stat, "updatesRecv",
10397 atomic_load_explicit(&p->update_in,
10398 memory_order_relaxed));
d62a17ae 10399 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10400 atomic_load_explicit(&p->keepalive_out,
10401 memory_order_relaxed));
d62a17ae 10402 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10403 atomic_load_explicit(&p->keepalive_in,
10404 memory_order_relaxed));
d62a17ae 10405 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10406 atomic_load_explicit(&p->refresh_out,
10407 memory_order_relaxed));
d62a17ae 10408 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10409 atomic_load_explicit(&p->refresh_in,
10410 memory_order_relaxed));
d62a17ae 10411 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10412 atomic_load_explicit(&p->dynamic_cap_out,
10413 memory_order_relaxed));
d62a17ae 10414 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10415 atomic_load_explicit(&p->dynamic_cap_in,
10416 memory_order_relaxed));
10417 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10418 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10419 json_object_object_add(json_neigh, "messageStats", json_stat);
10420 } else {
10421 /* Packet counts. */
10422 vty_out(vty, " Message statistics:\n");
10423 vty_out(vty, " Inq depth is 0\n");
10424 vty_out(vty, " Outq depth is %lu\n",
10425 (unsigned long)p->obuf->count);
10426 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10427 vty_out(vty, " Opens: %10d %10d\n",
10428 atomic_load_explicit(&p->open_out,
10429 memory_order_relaxed),
10430 atomic_load_explicit(&p->open_in,
10431 memory_order_relaxed));
10432 vty_out(vty, " Notifications: %10d %10d\n",
10433 atomic_load_explicit(&p->notify_out,
10434 memory_order_relaxed),
10435 atomic_load_explicit(&p->notify_in,
10436 memory_order_relaxed));
10437 vty_out(vty, " Updates: %10d %10d\n",
10438 atomic_load_explicit(&p->update_out,
10439 memory_order_relaxed),
10440 atomic_load_explicit(&p->update_in,
10441 memory_order_relaxed));
10442 vty_out(vty, " Keepalives: %10d %10d\n",
10443 atomic_load_explicit(&p->keepalive_out,
10444 memory_order_relaxed),
10445 atomic_load_explicit(&p->keepalive_in,
10446 memory_order_relaxed));
10447 vty_out(vty, " Route Refresh: %10d %10d\n",
10448 atomic_load_explicit(&p->refresh_out,
10449 memory_order_relaxed),
10450 atomic_load_explicit(&p->refresh_in,
10451 memory_order_relaxed));
d62a17ae 10452 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10453 atomic_load_explicit(&p->dynamic_cap_out,
10454 memory_order_relaxed),
10455 atomic_load_explicit(&p->dynamic_cap_in,
10456 memory_order_relaxed));
10457 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10458 PEER_TOTAL_RX(p));
d62a17ae 10459 }
10460
10461 if (use_json) {
10462 /* advertisement-interval */
10463 json_object_int_add(json_neigh,
10464 "minBtwnAdvertisementRunsTimerMsecs",
10465 p->v_routeadv * 1000);
10466
10467 /* Update-source. */
10468 if (p->update_if || p->update_source) {
10469 if (p->update_if)
10470 json_object_string_add(json_neigh,
10471 "updateSource",
10472 p->update_if);
10473 else if (p->update_source)
10474 json_object_string_add(
10475 json_neigh, "updateSource",
10476 sockunion2str(p->update_source, buf1,
10477 SU_ADDRSTRLEN));
10478 }
10479 } else {
10480 /* advertisement-interval */
10481 vty_out(vty,
10482 " Minimum time between advertisement runs is %d seconds\n",
10483 p->v_routeadv);
10484
10485 /* Update-source. */
10486 if (p->update_if || p->update_source) {
10487 vty_out(vty, " Update source is ");
10488 if (p->update_if)
10489 vty_out(vty, "%s", p->update_if);
10490 else if (p->update_source)
10491 vty_out(vty, "%s",
10492 sockunion2str(p->update_source, buf1,
10493 SU_ADDRSTRLEN));
10494 vty_out(vty, "\n");
10495 }
10496
10497 vty_out(vty, "\n");
10498 }
10499
10500 /* Address Family Information */
10501 json_object *json_hold = NULL;
10502
10503 if (use_json)
10504 json_hold = json_object_new_object();
10505
05c7a1cc
QY
10506 FOREACH_AFI_SAFI (afi, safi)
10507 if (p->afc[afi][safi])
10508 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10509 json_hold);
d62a17ae 10510
10511 if (use_json) {
10512 json_object_object_add(json_neigh, "addressFamilyInfo",
10513 json_hold);
10514 json_object_int_add(json_neigh, "connectionsEstablished",
10515 p->established);
10516 json_object_int_add(json_neigh, "connectionsDropped",
10517 p->dropped);
10518 } else
10519 vty_out(vty, " Connections established %d; dropped %d\n",
10520 p->established, p->dropped);
10521
10522 if (!p->last_reset) {
10523 if (use_json)
10524 json_object_string_add(json_neigh, "lastReset",
10525 "never");
10526 else
10527 vty_out(vty, " Last reset never\n");
10528 } else {
10529 if (use_json) {
10530 time_t uptime;
10531 struct tm *tm;
10532
10533 uptime = bgp_clock();
10534 uptime -= p->resettime;
10535 tm = gmtime(&uptime);
10536 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10537 (tm->tm_sec * 1000)
10538 + (tm->tm_min * 60000)
10539 + (tm->tm_hour * 3600000));
10540 json_object_string_add(
10541 json_neigh, "lastResetDueTo",
10542 peer_down_str[(int)p->last_reset]);
10543 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10544 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10545 char errorcodesubcode_hexstr[5];
10546 char errorcodesubcode_str[256];
10547
10548 code_str = bgp_notify_code_str(p->notify.code);
10549 subcode_str = bgp_notify_subcode_str(
10550 p->notify.code, p->notify.subcode);
10551
10552 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10553 p->notify.code, p->notify.subcode);
10554 json_object_string_add(json_neigh,
10555 "lastErrorCodeSubcode",
10556 errorcodesubcode_hexstr);
10557 snprintf(errorcodesubcode_str, 255, "%s%s",
10558 code_str, subcode_str);
10559 json_object_string_add(json_neigh,
10560 "lastNotificationReason",
10561 errorcodesubcode_str);
10562 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10563 && p->notify.code == BGP_NOTIFY_CEASE
10564 && (p->notify.subcode
10565 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10566 || p->notify.subcode
10567 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10568 && p->notify.length) {
10569 char msgbuf[1024];
10570 const char *msg_str;
10571
10572 msg_str = bgp_notify_admin_message(
10573 msgbuf, sizeof(msgbuf),
d7c0a89a 10574 (uint8_t *)p->notify.data,
d62a17ae 10575 p->notify.length);
10576 if (msg_str)
10577 json_object_string_add(
10578 json_neigh,
10579 "lastShutdownDescription",
10580 msg_str);
10581 }
10582 }
10583 } else {
10584 vty_out(vty, " Last reset %s, ",
10585 peer_uptime(p->resettime, timebuf,
10586 BGP_UPTIME_LEN, 0, NULL));
10587
10588 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10589 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10590 code_str = bgp_notify_code_str(p->notify.code);
10591 subcode_str = bgp_notify_subcode_str(
10592 p->notify.code, p->notify.subcode);
10593 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10594 p->last_reset == PEER_DOWN_NOTIFY_SEND
10595 ? "sent"
10596 : "received",
10597 code_str, subcode_str);
10598 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10599 && p->notify.code == BGP_NOTIFY_CEASE
10600 && (p->notify.subcode
10601 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10602 || p->notify.subcode
10603 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10604 && p->notify.length) {
10605 char msgbuf[1024];
10606 const char *msg_str;
10607
10608 msg_str = bgp_notify_admin_message(
10609 msgbuf, sizeof(msgbuf),
d7c0a89a 10610 (uint8_t *)p->notify.data,
d62a17ae 10611 p->notify.length);
10612 if (msg_str)
10613 vty_out(vty,
10614 " Message: \"%s\"\n",
10615 msg_str);
10616 }
10617 } else {
10618 vty_out(vty, "due to %s\n",
10619 peer_down_str[(int)p->last_reset]);
10620 }
10621
10622 if (p->last_reset_cause_size) {
10623 msg = p->last_reset_cause;
10624 vty_out(vty,
10625 " Message received that caused BGP to send a NOTIFICATION:\n ");
10626 for (i = 1; i <= p->last_reset_cause_size;
10627 i++) {
10628 vty_out(vty, "%02X", *msg++);
10629
10630 if (i != p->last_reset_cause_size) {
10631 if (i % 16 == 0) {
10632 vty_out(vty, "\n ");
10633 } else if (i % 4 == 0) {
10634 vty_out(vty, " ");
10635 }
10636 }
10637 }
10638 vty_out(vty, "\n");
10639 }
10640 }
10641 }
10642
10643 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10644 if (use_json)
10645 json_object_boolean_true_add(json_neigh,
10646 "prefixesConfigExceedMax");
10647 else
10648 vty_out(vty,
10649 " Peer had exceeded the max. no. of prefixes configured.\n");
10650
10651 if (p->t_pmax_restart) {
10652 if (use_json) {
10653 json_object_boolean_true_add(
10654 json_neigh, "reducePrefixNumFrom");
10655 json_object_int_add(json_neigh,
10656 "restartInTimerMsec",
10657 thread_timer_remain_second(
10658 p->t_pmax_restart)
10659 * 1000);
10660 } else
10661 vty_out(vty,
10662 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10663 p->host, thread_timer_remain_second(
10664 p->t_pmax_restart));
d62a17ae 10665 } else {
10666 if (use_json)
10667 json_object_boolean_true_add(
10668 json_neigh,
10669 "reducePrefixNumAndClearIpBgp");
10670 else
10671 vty_out(vty,
10672 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10673 p->host);
10674 }
10675 }
10676
10677 /* EBGP Multihop and GTSM */
10678 if (p->sort != BGP_PEER_IBGP) {
10679 if (use_json) {
10680 if (p->gtsm_hops > 0)
10681 json_object_int_add(json_neigh,
10682 "externalBgpNbrMaxHopsAway",
10683 p->gtsm_hops);
10684 else if (p->ttl > 1)
10685 json_object_int_add(json_neigh,
10686 "externalBgpNbrMaxHopsAway",
10687 p->ttl);
10688 } else {
10689 if (p->gtsm_hops > 0)
10690 vty_out(vty,
10691 " External BGP neighbor may be up to %d hops away.\n",
10692 p->gtsm_hops);
10693 else if (p->ttl > 1)
10694 vty_out(vty,
10695 " External BGP neighbor may be up to %d hops away.\n",
10696 p->ttl);
10697 }
10698 } else {
10699 if (p->gtsm_hops > 0) {
10700 if (use_json)
10701 json_object_int_add(json_neigh,
10702 "internalBgpNbrMaxHopsAway",
10703 p->gtsm_hops);
10704 else
10705 vty_out(vty,
10706 " Internal BGP neighbor may be up to %d hops away.\n",
10707 p->gtsm_hops);
10708 }
10709 }
10710
10711 /* Local address. */
10712 if (p->su_local) {
10713 if (use_json) {
10714 json_object_string_add(json_neigh, "hostLocal",
10715 sockunion2str(p->su_local, buf1,
10716 SU_ADDRSTRLEN));
10717 json_object_int_add(json_neigh, "portLocal",
10718 ntohs(p->su_local->sin.sin_port));
10719 } else
10720 vty_out(vty, "Local host: %s, Local port: %d\n",
10721 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10722 ntohs(p->su_local->sin.sin_port));
10723 }
10724
10725 /* Remote address. */
10726 if (p->su_remote) {
10727 if (use_json) {
10728 json_object_string_add(json_neigh, "hostForeign",
10729 sockunion2str(p->su_remote, buf1,
10730 SU_ADDRSTRLEN));
10731 json_object_int_add(json_neigh, "portForeign",
10732 ntohs(p->su_remote->sin.sin_port));
10733 } else
10734 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10735 sockunion2str(p->su_remote, buf1,
10736 SU_ADDRSTRLEN),
10737 ntohs(p->su_remote->sin.sin_port));
10738 }
10739
10740 /* Nexthop display. */
10741 if (p->su_local) {
10742 if (use_json) {
10743 json_object_string_add(json_neigh, "nexthop",
10744 inet_ntop(AF_INET,
10745 &p->nexthop.v4, buf1,
10746 sizeof(buf1)));
10747 json_object_string_add(json_neigh, "nexthopGlobal",
10748 inet_ntop(AF_INET6,
10749 &p->nexthop.v6_global,
10750 buf1, sizeof(buf1)));
10751 json_object_string_add(json_neigh, "nexthopLocal",
10752 inet_ntop(AF_INET6,
10753 &p->nexthop.v6_local,
10754 buf1, sizeof(buf1)));
10755 if (p->shared_network)
10756 json_object_string_add(json_neigh,
10757 "bgpConnection",
10758 "sharedNetwork");
10759 else
10760 json_object_string_add(json_neigh,
10761 "bgpConnection",
10762 "nonSharedNetwork");
10763 } else {
10764 vty_out(vty, "Nexthop: %s\n",
10765 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10766 sizeof(buf1)));
10767 vty_out(vty, "Nexthop global: %s\n",
10768 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10769 sizeof(buf1)));
10770 vty_out(vty, "Nexthop local: %s\n",
10771 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10772 sizeof(buf1)));
10773 vty_out(vty, "BGP connection: %s\n",
10774 p->shared_network ? "shared network"
10775 : "non shared network");
10776 }
10777 }
10778
10779 /* Timer information. */
10780 if (use_json) {
10781 json_object_int_add(json_neigh, "connectRetryTimer",
10782 p->v_connect);
10783 if (p->status == Established && p->rtt)
10784 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10785 p->rtt);
10786 if (p->t_start)
10787 json_object_int_add(
10788 json_neigh, "nextStartTimerDueInMsecs",
10789 thread_timer_remain_second(p->t_start) * 1000);
10790 if (p->t_connect)
10791 json_object_int_add(
10792 json_neigh, "nextConnectTimerDueInMsecs",
10793 thread_timer_remain_second(p->t_connect)
10794 * 1000);
10795 if (p->t_routeadv) {
10796 json_object_int_add(json_neigh, "mraiInterval",
10797 p->v_routeadv);
10798 json_object_int_add(
10799 json_neigh, "mraiTimerExpireInMsecs",
10800 thread_timer_remain_second(p->t_routeadv)
10801 * 1000);
10802 }
10803 if (p->password)
10804 json_object_int_add(json_neigh, "authenticationEnabled",
10805 1);
10806
10807 if (p->t_read)
10808 json_object_string_add(json_neigh, "readThread", "on");
10809 else
10810 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10811
10812 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10813 json_object_string_add(json_neigh, "writeThread", "on");
10814 else
10815 json_object_string_add(json_neigh, "writeThread",
10816 "off");
10817 } else {
10818 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10819 p->v_connect);
10820 if (p->status == Established && p->rtt)
10821 vty_out(vty, "Estimated round trip time: %d ms\n",
10822 p->rtt);
10823 if (p->t_start)
10824 vty_out(vty, "Next start timer due in %ld seconds\n",
10825 thread_timer_remain_second(p->t_start));
10826 if (p->t_connect)
10827 vty_out(vty, "Next connect timer due in %ld seconds\n",
10828 thread_timer_remain_second(p->t_connect));
10829 if (p->t_routeadv)
10830 vty_out(vty,
10831 "MRAI (interval %u) timer expires in %ld seconds\n",
10832 p->v_routeadv,
10833 thread_timer_remain_second(p->t_routeadv));
10834 if (p->password)
10835 vty_out(vty, "Peer Authentication Enabled\n");
10836
10837 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10838 p->t_read ? "on" : "off",
10839 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10840 ? "on"
10841 : "off");
d62a17ae 10842 }
10843
10844 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10845 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10846 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10847
10848 if (!use_json)
10849 vty_out(vty, "\n");
10850
10851 /* BFD information. */
10852 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10853
10854 if (use_json) {
10855 if (p->conf_if) /* Configured interface name. */
10856 json_object_object_add(json, p->conf_if, json_neigh);
10857 else /* Configured IP address. */
10858 json_object_object_add(json, p->host, json_neigh);
10859 }
10860}
10861
10862static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10863 enum show_type type, union sockunion *su,
9f049418 10864 const char *conf_if, bool use_json,
d62a17ae 10865 json_object *json)
10866{
10867 struct listnode *node, *nnode;
10868 struct peer *peer;
10869 int find = 0;
9f049418 10870 bool nbr_output = false;
d62a17ae 10871
10872 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10873 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10874 continue;
10875
10876 switch (type) {
10877 case show_all:
10878 bgp_show_peer(vty, peer, use_json, json);
9f049418 10879 nbr_output = true;
d62a17ae 10880 break;
10881 case show_peer:
10882 if (conf_if) {
10883 if ((peer->conf_if
10884 && !strcmp(peer->conf_if, conf_if))
10885 || (peer->hostname
10886 && !strcmp(peer->hostname, conf_if))) {
10887 find = 1;
10888 bgp_show_peer(vty, peer, use_json,
10889 json);
10890 }
10891 } else {
10892 if (sockunion_same(&peer->su, su)) {
10893 find = 1;
10894 bgp_show_peer(vty, peer, use_json,
10895 json);
10896 }
10897 }
10898 break;
10899 }
10900 }
10901
10902 if (type == show_peer && !find) {
10903 if (use_json)
10904 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10905 else
88b7d255 10906 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10907 }
10908
9f049418 10909 if (type != show_peer && !nbr_output && !use_json)
94d4c685 10910 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10911
d62a17ae 10912 if (use_json) {
996c9314
LB
10913 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10914 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10915 json_object_free(json);
10916 } else {
10917 vty_out(vty, "\n");
10918 }
10919
10920 return CMD_SUCCESS;
10921}
10922
10923static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10924 enum show_type type,
10925 const char *ip_str,
9f049418 10926 bool use_json)
d62a17ae 10927{
0291c246
MK
10928 struct listnode *node, *nnode;
10929 struct bgp *bgp;
71aedaa3 10930 union sockunion su;
0291c246 10931 json_object *json = NULL;
71aedaa3 10932 int ret, is_first = 1;
9f049418 10933 bool nbr_output = false;
d62a17ae 10934
10935 if (use_json)
10936 vty_out(vty, "{\n");
10937
10938 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10939 nbr_output = true;
d62a17ae 10940 if (use_json) {
10941 if (!(json = json_object_new_object())) {
af4c2728 10942 flog_err(
e50f7cfd 10943 EC_BGP_JSON_MEM_ERROR,
d62a17ae 10944 "Unable to allocate memory for JSON object");
10945 vty_out(vty,
10946 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10947 return;
10948 }
10949
10950 json_object_int_add(json, "vrfId",
10951 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10952 ? -1
10953 : (int64_t)bgp->vrf_id);
d62a17ae 10954 json_object_string_add(
10955 json, "vrfName",
10956 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10957 ? VRF_DEFAULT_NAME
d62a17ae 10958 : bgp->name);
10959
10960 if (!is_first)
10961 vty_out(vty, ",\n");
10962 else
10963 is_first = 0;
10964
10965 vty_out(vty, "\"%s\":",
10966 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10967 ? VRF_DEFAULT_NAME
d62a17ae 10968 : bgp->name);
10969 } else {
10970 vty_out(vty, "\nInstance %s:\n",
10971 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10972 ? VRF_DEFAULT_NAME
d62a17ae 10973 : bgp->name);
10974 }
71aedaa3
DS
10975
10976 if (type == show_peer) {
10977 ret = str2sockunion(ip_str, &su);
10978 if (ret < 0)
10979 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10980 use_json, json);
10981 else
10982 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10983 use_json, json);
10984 } else {
10985 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10986 use_json, json);
10987 }
d62a17ae 10988 }
10989
10990 if (use_json)
10991 vty_out(vty, "}\n");
9f049418
DS
10992 else if (!nbr_output)
10993 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10994}
10995
10996static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10997 enum show_type type, const char *ip_str,
9f049418 10998 bool use_json)
d62a17ae 10999{
11000 int ret;
11001 struct bgp *bgp;
11002 union sockunion su;
11003 json_object *json = NULL;
11004
11005 if (name) {
11006 if (strmatch(name, "all")) {
71aedaa3
DS
11007 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11008 use_json);
d62a17ae 11009 return CMD_SUCCESS;
11010 } else {
11011 bgp = bgp_lookup_by_name(name);
11012 if (!bgp) {
11013 if (use_json) {
11014 json = json_object_new_object();
d62a17ae 11015 vty_out(vty, "%s\n",
11016 json_object_to_json_string_ext(
11017 json,
11018 JSON_C_TO_STRING_PRETTY));
11019 json_object_free(json);
11020 } else
11021 vty_out(vty,
9f049418 11022 "%% BGP instance not found\n");
d62a17ae 11023
11024 return CMD_WARNING;
11025 }
11026 }
11027 } else {
11028 bgp = bgp_get_default();
11029 }
11030
11031 if (bgp) {
11032 json = json_object_new_object();
11033 if (ip_str) {
11034 ret = str2sockunion(ip_str, &su);
11035 if (ret < 0)
11036 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11037 use_json, json);
11038 else
11039 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11040 use_json, json);
11041 } else {
11042 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11043 json);
11044 }
11045 json_object_free(json);
ca61fd25
DS
11046 } else {
11047 if (use_json)
11048 vty_out(vty, "{}\n");
11049 else
11050 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11051 }
11052
11053 return CMD_SUCCESS;
4fb25c53
DW
11054}
11055
716b2d8a 11056/* "show [ip] bgp neighbors" commands. */
718e3744 11057DEFUN (show_ip_bgp_neighbors,
11058 show_ip_bgp_neighbors_cmd,
24345e82 11059 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11060 SHOW_STR
11061 IP_STR
11062 BGP_STR
f2a8972b 11063 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11064 "Address Family\n"
11065 "Address Family\n"
718e3744 11066 "Detailed information on TCP and BGP neighbor connections\n"
11067 "Neighbor to display information about\n"
a80beece 11068 "Neighbor to display information about\n"
91d37724 11069 "Neighbor on BGP configured interface\n"
9973d184 11070 JSON_STR)
718e3744 11071{
d62a17ae 11072 char *vrf = NULL;
11073 char *sh_arg = NULL;
11074 enum show_type sh_type;
718e3744 11075
9f049418 11076 bool uj = use_json(argc, argv);
718e3744 11077
d62a17ae 11078 int idx = 0;
718e3744 11079
9a8bdf1c
PG
11080 /* [<vrf> VIEWVRFNAME] */
11081 if (argv_find(argv, argc, "vrf", &idx)) {
11082 vrf = argv[idx + 1]->arg;
11083 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11084 vrf = NULL;
11085 } else if (argv_find(argv, argc, "view", &idx))
11086 /* [<view> VIEWVRFNAME] */
d62a17ae 11087 vrf = argv[idx + 1]->arg;
718e3744 11088
d62a17ae 11089 idx++;
11090 if (argv_find(argv, argc, "A.B.C.D", &idx)
11091 || argv_find(argv, argc, "X:X::X:X", &idx)
11092 || argv_find(argv, argc, "WORD", &idx)) {
11093 sh_type = show_peer;
11094 sh_arg = argv[idx]->arg;
11095 } else
11096 sh_type = show_all;
856ca177 11097
d62a17ae 11098 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11099}
11100
716b2d8a 11101/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11102 paths' and `show ip mbgp paths'. Those functions results are the
11103 same.*/
f412b39a 11104DEFUN (show_ip_bgp_paths,
718e3744 11105 show_ip_bgp_paths_cmd,
46f296b4 11106 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11107 SHOW_STR
11108 IP_STR
11109 BGP_STR
46f296b4 11110 BGP_SAFI_HELP_STR
718e3744 11111 "Path information\n")
11112{
d62a17ae 11113 vty_out(vty, "Address Refcnt Path\n");
11114 aspath_print_all_vty(vty);
11115 return CMD_SUCCESS;
718e3744 11116}
11117
718e3744 11118#include "hash.h"
11119
d62a17ae 11120static void community_show_all_iterator(struct hash_backet *backet,
11121 struct vty *vty)
718e3744 11122{
d62a17ae 11123 struct community *com;
718e3744 11124
d62a17ae 11125 com = (struct community *)backet->data;
3f65c5b1 11126 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11127 community_str(com, false));
718e3744 11128}
11129
11130/* Show BGP's community internal data. */
f412b39a 11131DEFUN (show_ip_bgp_community_info,
718e3744 11132 show_ip_bgp_community_info_cmd,
bec37ba5 11133 "show [ip] bgp community-info",
718e3744 11134 SHOW_STR
11135 IP_STR
11136 BGP_STR
11137 "List all bgp community information\n")
11138{
d62a17ae 11139 vty_out(vty, "Address Refcnt Community\n");
718e3744 11140
d62a17ae 11141 hash_iterate(community_hash(),
11142 (void (*)(struct hash_backet *,
11143 void *))community_show_all_iterator,
11144 vty);
718e3744 11145
d62a17ae 11146 return CMD_SUCCESS;
718e3744 11147}
11148
d62a17ae 11149static void lcommunity_show_all_iterator(struct hash_backet *backet,
11150 struct vty *vty)
57d187bc 11151{
d62a17ae 11152 struct lcommunity *lcom;
57d187bc 11153
d62a17ae 11154 lcom = (struct lcommunity *)backet->data;
3f65c5b1 11155 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11156 lcommunity_str(lcom, false));
57d187bc
JS
11157}
11158
11159/* Show BGP's community internal data. */
11160DEFUN (show_ip_bgp_lcommunity_info,
11161 show_ip_bgp_lcommunity_info_cmd,
11162 "show ip bgp large-community-info",
11163 SHOW_STR
11164 IP_STR
11165 BGP_STR
11166 "List all bgp large-community information\n")
11167{
d62a17ae 11168 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11169
d62a17ae 11170 hash_iterate(lcommunity_hash(),
11171 (void (*)(struct hash_backet *,
11172 void *))lcommunity_show_all_iterator,
11173 vty);
57d187bc 11174
d62a17ae 11175 return CMD_SUCCESS;
57d187bc
JS
11176}
11177
11178
f412b39a 11179DEFUN (show_ip_bgp_attr_info,
718e3744 11180 show_ip_bgp_attr_info_cmd,
bec37ba5 11181 "show [ip] bgp attribute-info",
718e3744 11182 SHOW_STR
11183 IP_STR
11184 BGP_STR
11185 "List all bgp attribute information\n")
11186{
d62a17ae 11187 attr_show_all(vty);
11188 return CMD_SUCCESS;
718e3744 11189}
6b0655a2 11190
9f049418
DS
11191static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11192 safi_t safi, bool use_json)
53089bec 11193{
11194 struct bgp *bgp;
11195 struct listnode *node;
11196 char *vname;
11197 char buf1[INET6_ADDRSTRLEN];
11198 char *ecom_str;
11199 vpn_policy_direction_t dir;
11200
b46dfd20
DS
11201 if (use_json) {
11202 json_object *json = NULL;
11203 json_object *json_import_vrfs = NULL;
11204 json_object *json_export_vrfs = NULL;
11205
11206 json = json_object_new_object();
b46dfd20 11207
b46dfd20
DS
11208 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11209
53089bec 11210 if (!bgp) {
b46dfd20
DS
11211 vty_out(vty, "%s\n",
11212 json_object_to_json_string_ext(
11213 json,
11214 JSON_C_TO_STRING_PRETTY));
11215 json_object_free(json);
11216
53089bec 11217 return CMD_WARNING;
11218 }
b46dfd20 11219
94d4c685
DS
11220 /* Provide context for the block */
11221 json_object_string_add(json, "vrf", name ? name : "default");
11222 json_object_string_add(json, "afiSafi",
11223 afi_safi_print(afi, safi));
11224
b46dfd20
DS
11225 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11226 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11227 json_object_string_add(json, "importFromVrfs", "none");
11228 json_object_string_add(json, "importRts", "none");
11229 } else {
6ce24e52
DS
11230 json_import_vrfs = json_object_new_array();
11231
b46dfd20
DS
11232 for (ALL_LIST_ELEMENTS_RO(
11233 bgp->vpn_policy[afi].import_vrf,
11234 node, vname))
11235 json_object_array_add(json_import_vrfs,
11236 json_object_new_string(vname));
11237
11238 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11239 ecom_str = ecommunity_ecom2str(
11240 bgp->vpn_policy[afi].rtlist[dir],
11241 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11242 json_object_object_add(json, "importFromVrfs",
11243 json_import_vrfs);
11244 json_object_string_add(json, "importRts", ecom_str);
11245
11246 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11247 }
11248
11249 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11250 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11251 json_object_string_add(json, "exportToVrfs", "none");
11252 json_object_string_add(json, "routeDistinguisher",
11253 "none");
11254 json_object_string_add(json, "exportRts", "none");
11255 } else {
6ce24e52
DS
11256 json_export_vrfs = json_object_new_array();
11257
b46dfd20
DS
11258 for (ALL_LIST_ELEMENTS_RO(
11259 bgp->vpn_policy[afi].export_vrf,
11260 node, vname))
11261 json_object_array_add(json_export_vrfs,
11262 json_object_new_string(vname));
11263 json_object_object_add(json, "exportToVrfs",
11264 json_export_vrfs);
11265 json_object_string_add(json, "routeDistinguisher",
11266 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11267 buf1, RD_ADDRSTRLEN));
11268
11269 dir = BGP_VPN_POLICY_DIR_TOVPN;
11270 ecom_str = ecommunity_ecom2str(
11271 bgp->vpn_policy[afi].rtlist[dir],
11272 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11273 json_object_string_add(json, "exportRts", ecom_str);
11274
11275 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11276 }
11277
11278 vty_out(vty, "%s\n",
11279 json_object_to_json_string_ext(json,
11280 JSON_C_TO_STRING_PRETTY));
11281 json_object_free(json);
11282
53089bec 11283 } else {
b46dfd20
DS
11284 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11285
53089bec 11286 if (!bgp) {
b46dfd20 11287 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11288 return CMD_WARNING;
11289 }
53089bec 11290
b46dfd20
DS
11291 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11292 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11293 vty_out(vty,
11294 "This VRF is not importing %s routes from any other VRF\n",
11295 afi_safi_print(afi, safi));
11296 else {
11297 vty_out(vty,
11298 "This VRF is importing %s routes from the following VRFs:\n",
11299 afi_safi_print(afi, safi));
11300
11301 for (ALL_LIST_ELEMENTS_RO(
11302 bgp->vpn_policy[afi].import_vrf,
11303 node, vname))
11304 vty_out(vty, " %s\n", vname);
11305
11306 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11307 ecom_str = ecommunity_ecom2str(
11308 bgp->vpn_policy[afi].rtlist[dir],
11309 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11310 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11311
11312 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11313 }
53089bec 11314
b46dfd20
DS
11315 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11316 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11317 vty_out(vty,
11318 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11319 afi_safi_print(afi, safi));
b46dfd20
DS
11320 else {
11321 vty_out(vty,
04c9077f 11322 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11323 afi_safi_print(afi, safi));
b46dfd20
DS
11324
11325 for (ALL_LIST_ELEMENTS_RO(
11326 bgp->vpn_policy[afi].export_vrf,
11327 node, vname))
11328 vty_out(vty, " %s\n", vname);
11329
11330 vty_out(vty, "RD: %s\n",
11331 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11332 buf1, RD_ADDRSTRLEN));
11333
11334 dir = BGP_VPN_POLICY_DIR_TOVPN;
11335 ecom_str = ecommunity_ecom2str(
11336 bgp->vpn_policy[afi].rtlist[dir],
11337 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11338 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11339 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11340 }
53089bec 11341 }
11342
11343 return CMD_SUCCESS;
11344}
11345
11346/* "show [ip] bgp route-leak" command. */
11347DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11348 show_ip_bgp_route_leak_cmd,
11349 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11350 SHOW_STR
11351 IP_STR
11352 BGP_STR
11353 BGP_INSTANCE_HELP_STR
11354 BGP_AFI_HELP_STR
11355 BGP_SAFI_HELP_STR
11356 "Route leaking information\n"
11357 JSON_STR)
53089bec 11358{
11359 char *vrf = NULL;
11360 afi_t afi = AFI_MAX;
11361 safi_t safi = SAFI_MAX;
11362
9f049418 11363 bool uj = use_json(argc, argv);
53089bec 11364 int idx = 0;
11365
11366 /* show [ip] bgp */
11367 if (argv_find(argv, argc, "ip", &idx)) {
11368 afi = AFI_IP;
11369 safi = SAFI_UNICAST;
11370 }
11371 /* [vrf VIEWVRFNAME] */
11372 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11373 vty_out(vty,
11374 "%% This command is not applicable to BGP views\n");
53089bec 11375 return CMD_WARNING;
11376 }
11377
9a8bdf1c
PG
11378 if (argv_find(argv, argc, "vrf", &idx)) {
11379 vrf = argv[idx + 1]->arg;
11380 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11381 vrf = NULL;
11382 }
53089bec 11383 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11384 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11385 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11386 }
11387
11388 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11389 vty_out(vty,
11390 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11391 return CMD_WARNING;
11392 }
11393
b46dfd20 11394 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
53089bec 11395}
11396
d62a17ae 11397static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11398 safi_t safi)
f186de26 11399{
d62a17ae 11400 struct listnode *node, *nnode;
11401 struct bgp *bgp;
f186de26 11402
d62a17ae 11403 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11404 vty_out(vty, "\nInstance %s:\n",
11405 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11406 ? VRF_DEFAULT_NAME
d62a17ae 11407 : bgp->name);
11408 update_group_show(bgp, afi, safi, vty, 0);
11409 }
f186de26 11410}
11411
d62a17ae 11412static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11413 int safi, uint64_t subgrp_id)
4fb25c53 11414{
d62a17ae 11415 struct bgp *bgp;
4fb25c53 11416
d62a17ae 11417 if (name) {
11418 if (strmatch(name, "all")) {
11419 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11420 return CMD_SUCCESS;
11421 } else {
11422 bgp = bgp_lookup_by_name(name);
11423 }
11424 } else {
11425 bgp = bgp_get_default();
11426 }
4fb25c53 11427
d62a17ae 11428 if (bgp)
11429 update_group_show(bgp, afi, safi, vty, subgrp_id);
11430 return CMD_SUCCESS;
4fb25c53
DW
11431}
11432
8fe8a7f6
DS
11433DEFUN (show_ip_bgp_updgrps,
11434 show_ip_bgp_updgrps_cmd,
c1a44e43 11435 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11436 SHOW_STR
11437 IP_STR
11438 BGP_STR
11439 BGP_INSTANCE_HELP_STR
c9e571b4 11440 BGP_AFI_HELP_STR
9bedbb1e 11441 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11442 "Detailed info about dynamic update groups\n"
11443 "Specific subgroup to display detailed info for\n")
8386ac43 11444{
d62a17ae 11445 char *vrf = NULL;
11446 afi_t afi = AFI_IP6;
11447 safi_t safi = SAFI_UNICAST;
11448 uint64_t subgrp_id = 0;
11449
11450 int idx = 0;
11451
11452 /* show [ip] bgp */
11453 if (argv_find(argv, argc, "ip", &idx))
11454 afi = AFI_IP;
9a8bdf1c
PG
11455 /* [<vrf> VIEWVRFNAME] */
11456 if (argv_find(argv, argc, "vrf", &idx)) {
11457 vrf = argv[idx + 1]->arg;
11458 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11459 vrf = NULL;
11460 } else if (argv_find(argv, argc, "view", &idx))
11461 /* [<view> VIEWVRFNAME] */
11462 vrf = argv[idx + 1]->arg;
d62a17ae 11463 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11464 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11465 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11466 }
5bf15956 11467
d62a17ae 11468 /* get subgroup id, if provided */
11469 idx = argc - 1;
11470 if (argv[idx]->type == VARIABLE_TKN)
11471 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11472
d62a17ae 11473 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11474}
11475
f186de26 11476DEFUN (show_bgp_instance_all_ipv6_updgrps,
11477 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11478 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11479 SHOW_STR
716b2d8a 11480 IP_STR
f186de26 11481 BGP_STR
11482 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11483 "Detailed info about dynamic update groups\n")
f186de26 11484{
d62a17ae 11485 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11486 return CMD_SUCCESS;
f186de26 11487}
11488
43d3f4fc
DS
11489DEFUN (show_bgp_l2vpn_evpn_updgrps,
11490 show_bgp_l2vpn_evpn_updgrps_cmd,
11491 "show [ip] bgp l2vpn evpn update-groups",
11492 SHOW_STR
11493 IP_STR
11494 BGP_STR
11495 "l2vpn address family\n"
11496 "evpn sub-address family\n"
11497 "Detailed info about dynamic update groups\n")
11498{
11499 char *vrf = NULL;
11500 uint64_t subgrp_id = 0;
11501
11502 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11503 return CMD_SUCCESS;
11504}
11505
5bf15956
DW
11506DEFUN (show_bgp_updgrps_stats,
11507 show_bgp_updgrps_stats_cmd,
716b2d8a 11508 "show [ip] bgp update-groups statistics",
3f9c7369 11509 SHOW_STR
716b2d8a 11510 IP_STR
3f9c7369 11511 BGP_STR
0c7b1b01 11512 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11513 "Statistics\n")
11514{
d62a17ae 11515 struct bgp *bgp;
3f9c7369 11516
d62a17ae 11517 bgp = bgp_get_default();
11518 if (bgp)
11519 update_group_show_stats(bgp, vty);
3f9c7369 11520
d62a17ae 11521 return CMD_SUCCESS;
3f9c7369
DS
11522}
11523
8386ac43 11524DEFUN (show_bgp_instance_updgrps_stats,
11525 show_bgp_instance_updgrps_stats_cmd,
18c57037 11526 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11527 SHOW_STR
716b2d8a 11528 IP_STR
8386ac43 11529 BGP_STR
11530 BGP_INSTANCE_HELP_STR
0c7b1b01 11531 "Detailed info about dynamic update groups\n"
8386ac43 11532 "Statistics\n")
11533{
d62a17ae 11534 int idx_word = 3;
11535 struct bgp *bgp;
8386ac43 11536
d62a17ae 11537 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11538 if (bgp)
11539 update_group_show_stats(bgp, vty);
8386ac43 11540
d62a17ae 11541 return CMD_SUCCESS;
8386ac43 11542}
11543
d62a17ae 11544static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11545 afi_t afi, safi_t safi,
11546 const char *what, uint64_t subgrp_id)
3f9c7369 11547{
d62a17ae 11548 struct bgp *bgp;
8386ac43 11549
d62a17ae 11550 if (name)
11551 bgp = bgp_lookup_by_name(name);
11552 else
11553 bgp = bgp_get_default();
8386ac43 11554
d62a17ae 11555 if (bgp) {
11556 if (!strcmp(what, "advertise-queue"))
11557 update_group_show_adj_queue(bgp, afi, safi, vty,
11558 subgrp_id);
11559 else if (!strcmp(what, "advertised-routes"))
11560 update_group_show_advertised(bgp, afi, safi, vty,
11561 subgrp_id);
11562 else if (!strcmp(what, "packet-queue"))
11563 update_group_show_packet_queue(bgp, afi, safi, vty,
11564 subgrp_id);
11565 }
3f9c7369
DS
11566}
11567
dc64bdec
QY
11568DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11569 show_ip_bgp_instance_updgrps_adj_s_cmd,
11570 "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",
11571 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11572 BGP_SAFI_HELP_STR
11573 "Detailed info about dynamic update groups\n"
11574 "Specific subgroup to display info for\n"
11575 "Advertisement queue\n"
11576 "Announced routes\n"
11577 "Packet queue\n")
3f9c7369 11578{
dc64bdec
QY
11579 uint64_t subgrp_id = 0;
11580 afi_t afiz;
11581 safi_t safiz;
11582 if (sgid)
11583 subgrp_id = strtoull(sgid, NULL, 10);
11584
11585 if (!ip && !afi)
11586 afiz = AFI_IP6;
11587 if (!ip && afi)
11588 afiz = bgp_vty_afi_from_str(afi);
11589 if (ip && !afi)
11590 afiz = AFI_IP;
11591 if (ip && afi) {
11592 afiz = bgp_vty_afi_from_str(afi);
11593 if (afiz != AFI_IP)
11594 vty_out(vty,
11595 "%% Cannot specify both 'ip' and 'ipv6'\n");
11596 return CMD_WARNING;
11597 }
d62a17ae 11598
dc64bdec 11599 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11600
dc64bdec 11601 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11602 return CMD_SUCCESS;
11603}
11604
d62a17ae 11605static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11606{
11607 struct listnode *node, *nnode;
11608 struct prefix *range;
11609 struct peer *conf;
11610 struct peer *peer;
11611 char buf[PREFIX2STR_BUFFER];
11612 afi_t afi;
11613 safi_t safi;
11614 const char *peer_status;
11615 const char *af_str;
11616 int lr_count;
11617 int dynamic;
11618 int af_cfgd;
11619
11620 conf = group->conf;
11621
11622 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11623 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11624 conf->as);
11625 } else if (conf->as_type == AS_INTERNAL) {
11626 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11627 group->bgp->as);
11628 } else {
11629 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11630 }
f14e6fdb 11631
d62a17ae 11632 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11633 vty_out(vty, " Peer-group type is internal\n");
11634 else
11635 vty_out(vty, " Peer-group type is external\n");
11636
11637 /* Display AFs configured. */
11638 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11639 FOREACH_AFI_SAFI (afi, safi) {
11640 if (conf->afc[afi][safi]) {
11641 af_cfgd = 1;
11642 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11643 }
05c7a1cc 11644 }
d62a17ae 11645 if (!af_cfgd)
11646 vty_out(vty, " none\n");
11647 else
11648 vty_out(vty, "\n");
11649
11650 /* Display listen ranges (for dynamic neighbors), if any */
11651 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11652 if (afi == AFI_IP)
11653 af_str = "IPv4";
11654 else if (afi == AFI_IP6)
11655 af_str = "IPv6";
11656 else
11657 af_str = "???";
11658 lr_count = listcount(group->listen_range[afi]);
11659 if (lr_count) {
11660 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11661 af_str);
11662
11663
11664 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11665 nnode, range)) {
11666 prefix2str(range, buf, sizeof(buf));
11667 vty_out(vty, " %s\n", buf);
11668 }
11669 }
11670 }
f14e6fdb 11671
d62a17ae 11672 /* Display group members and their status */
11673 if (listcount(group->peer)) {
11674 vty_out(vty, " Peer-group members:\n");
11675 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11676 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11677 peer_status = "Idle (Admin)";
11678 else if (CHECK_FLAG(peer->sflags,
11679 PEER_STATUS_PREFIX_OVERFLOW))
11680 peer_status = "Idle (PfxCt)";
11681 else
11682 peer_status = lookup_msg(bgp_status_msg,
11683 peer->status, NULL);
11684
11685 dynamic = peer_dynamic_neighbor(peer);
11686 vty_out(vty, " %s %s %s \n", peer->host,
11687 dynamic ? "(dynamic)" : "", peer_status);
11688 }
11689 }
f14e6fdb 11690
d62a17ae 11691 return CMD_SUCCESS;
11692}
11693
ff9959b0
QY
11694static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11695 const char *group_name)
d62a17ae 11696{
ff9959b0 11697 struct bgp *bgp;
d62a17ae 11698 struct listnode *node, *nnode;
11699 struct peer_group *group;
ff9959b0
QY
11700 bool found = false;
11701
11702 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11703
11704 if (!bgp) {
9f049418 11705 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11706 return CMD_WARNING;
11707 }
d62a17ae 11708
11709 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11710 if (group_name) {
11711 if (strmatch(group->name, group_name)) {
d62a17ae 11712 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11713 found = true;
11714 break;
d62a17ae 11715 }
ff9959b0
QY
11716 } else {
11717 bgp_show_one_peer_group(vty, group);
d62a17ae 11718 }
f14e6fdb 11719 }
f14e6fdb 11720
ff9959b0 11721 if (group_name && !found)
d62a17ae 11722 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11723
d62a17ae 11724 return CMD_SUCCESS;
f14e6fdb
DS
11725}
11726
f14e6fdb
DS
11727DEFUN (show_ip_bgp_peer_groups,
11728 show_ip_bgp_peer_groups_cmd,
18c57037 11729 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11730 SHOW_STR
11731 IP_STR
11732 BGP_STR
8386ac43 11733 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11734 "Detailed information on BGP peer groups\n"
11735 "Peer group name\n")
f14e6fdb 11736{
d62a17ae 11737 char *vrf, *pg;
d62a17ae 11738 int idx = 0;
f14e6fdb 11739
a4d82a8a
PZ
11740 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11741 : NULL;
d62a17ae 11742 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11743
ff9959b0 11744 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11745}
3f9c7369 11746
d6e3c605 11747
718e3744 11748/* Redistribute VTY commands. */
11749
718e3744 11750DEFUN (bgp_redistribute_ipv4,
11751 bgp_redistribute_ipv4_cmd,
40d1cbfb 11752 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11753 "Redistribute information from another routing protocol\n"
ab0181ee 11754 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11755{
d62a17ae 11756 VTY_DECLVAR_CONTEXT(bgp, bgp);
11757 int idx_protocol = 1;
11758 int type;
718e3744 11759
d62a17ae 11760 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11761 if (type < 0) {
11762 vty_out(vty, "%% Invalid route type\n");
11763 return CMD_WARNING_CONFIG_FAILED;
11764 }
7f323236 11765
d62a17ae 11766 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11767 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11768}
11769
d62a17ae 11770ALIAS_HIDDEN(
11771 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11772 "redistribute " FRR_IP_REDIST_STR_BGPD,
11773 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11774
718e3744 11775DEFUN (bgp_redistribute_ipv4_rmap,
11776 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11777 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11778 "Redistribute information from another routing protocol\n"
ab0181ee 11779 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11780 "Route map reference\n"
11781 "Pointer to route-map entries\n")
11782{
d62a17ae 11783 VTY_DECLVAR_CONTEXT(bgp, bgp);
11784 int idx_protocol = 1;
11785 int idx_word = 3;
11786 int type;
11787 struct bgp_redist *red;
e923dd62 11788 bool changed;
1de27621
DA
11789 struct route_map *route_map = route_map_lookup_warn_noexist(
11790 vty, argv[idx_word]->arg);
718e3744 11791
d62a17ae 11792 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11793 if (type < 0) {
11794 vty_out(vty, "%% Invalid route type\n");
11795 return CMD_WARNING_CONFIG_FAILED;
11796 }
718e3744 11797
d62a17ae 11798 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11799 changed =
11800 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11801 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11802}
11803
d62a17ae 11804ALIAS_HIDDEN(
11805 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11806 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11807 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11808 "Route map reference\n"
11809 "Pointer to route-map entries\n")
596c17ba 11810
718e3744 11811DEFUN (bgp_redistribute_ipv4_metric,
11812 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11813 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11814 "Redistribute information from another routing protocol\n"
ab0181ee 11815 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11816 "Metric for redistributed routes\n"
11817 "Default metric\n")
11818{
d62a17ae 11819 VTY_DECLVAR_CONTEXT(bgp, bgp);
11820 int idx_protocol = 1;
11821 int idx_number = 3;
11822 int type;
d7c0a89a 11823 uint32_t metric;
d62a17ae 11824 struct bgp_redist *red;
e923dd62 11825 bool changed;
d62a17ae 11826
11827 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11828 if (type < 0) {
11829 vty_out(vty, "%% Invalid route type\n");
11830 return CMD_WARNING_CONFIG_FAILED;
11831 }
11832 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11833
11834 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11835 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11836 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11837}
11838
11839ALIAS_HIDDEN(
11840 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11841 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11842 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11843 "Metric for redistributed routes\n"
11844 "Default metric\n")
596c17ba 11845
718e3744 11846DEFUN (bgp_redistribute_ipv4_rmap_metric,
11847 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11848 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11849 "Redistribute information from another routing protocol\n"
ab0181ee 11850 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11851 "Route map reference\n"
11852 "Pointer to route-map entries\n"
11853 "Metric for redistributed routes\n"
11854 "Default metric\n")
11855{
d62a17ae 11856 VTY_DECLVAR_CONTEXT(bgp, bgp);
11857 int idx_protocol = 1;
11858 int idx_word = 3;
11859 int idx_number = 5;
11860 int type;
d7c0a89a 11861 uint32_t metric;
d62a17ae 11862 struct bgp_redist *red;
e923dd62 11863 bool changed;
1de27621
DA
11864 struct route_map *route_map =
11865 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11866
11867 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11868 if (type < 0) {
11869 vty_out(vty, "%% Invalid route type\n");
11870 return CMD_WARNING_CONFIG_FAILED;
11871 }
11872 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11873
11874 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11875 changed =
11876 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11877 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11878 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11879}
11880
11881ALIAS_HIDDEN(
11882 bgp_redistribute_ipv4_rmap_metric,
11883 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11884 "redistribute " FRR_IP_REDIST_STR_BGPD
11885 " route-map WORD metric (0-4294967295)",
11886 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11887 "Route map reference\n"
11888 "Pointer to route-map entries\n"
11889 "Metric for redistributed routes\n"
11890 "Default metric\n")
596c17ba 11891
718e3744 11892DEFUN (bgp_redistribute_ipv4_metric_rmap,
11893 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11894 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11895 "Redistribute information from another routing protocol\n"
ab0181ee 11896 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11897 "Metric for redistributed routes\n"
11898 "Default metric\n"
11899 "Route map reference\n"
11900 "Pointer to route-map entries\n")
11901{
d62a17ae 11902 VTY_DECLVAR_CONTEXT(bgp, bgp);
11903 int idx_protocol = 1;
11904 int idx_number = 3;
11905 int idx_word = 5;
11906 int type;
d7c0a89a 11907 uint32_t metric;
d62a17ae 11908 struct bgp_redist *red;
e923dd62 11909 bool changed;
1de27621
DA
11910 struct route_map *route_map =
11911 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11912
11913 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11914 if (type < 0) {
11915 vty_out(vty, "%% Invalid route type\n");
11916 return CMD_WARNING_CONFIG_FAILED;
11917 }
11918 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11919
11920 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11921 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
11922 changed |=
11923 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11924 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11925}
11926
11927ALIAS_HIDDEN(
11928 bgp_redistribute_ipv4_metric_rmap,
11929 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11930 "redistribute " FRR_IP_REDIST_STR_BGPD
11931 " metric (0-4294967295) route-map WORD",
11932 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11933 "Metric for redistributed routes\n"
11934 "Default metric\n"
11935 "Route map reference\n"
11936 "Pointer to route-map entries\n")
596c17ba 11937
7c8ff89e
DS
11938DEFUN (bgp_redistribute_ipv4_ospf,
11939 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11940 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11941 "Redistribute information from another routing protocol\n"
11942 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11943 "Non-main Kernel Routing Table\n"
11944 "Instance ID/Table ID\n")
7c8ff89e 11945{
d62a17ae 11946 VTY_DECLVAR_CONTEXT(bgp, bgp);
11947 int idx_ospf_table = 1;
11948 int idx_number = 2;
d7c0a89a
QY
11949 unsigned short instance;
11950 unsigned short protocol;
7c8ff89e 11951
d62a17ae 11952 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11953
d62a17ae 11954 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11955 protocol = ZEBRA_ROUTE_OSPF;
11956 else
11957 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11958
d62a17ae 11959 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 11960 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
11961}
11962
d62a17ae 11963ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11964 "redistribute <ospf|table> (1-65535)",
11965 "Redistribute information from another routing protocol\n"
11966 "Open Shortest Path First (OSPFv2)\n"
11967 "Non-main Kernel Routing Table\n"
11968 "Instance ID/Table ID\n")
596c17ba 11969
7c8ff89e
DS
11970DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11971 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11972 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11973 "Redistribute information from another routing protocol\n"
11974 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11975 "Non-main Kernel Routing Table\n"
11976 "Instance ID/Table ID\n"
7c8ff89e
DS
11977 "Route map reference\n"
11978 "Pointer to route-map entries\n")
11979{
d62a17ae 11980 VTY_DECLVAR_CONTEXT(bgp, bgp);
11981 int idx_ospf_table = 1;
11982 int idx_number = 2;
11983 int idx_word = 4;
11984 struct bgp_redist *red;
d7c0a89a 11985 unsigned short instance;
d62a17ae 11986 int protocol;
e923dd62 11987 bool changed;
1de27621
DA
11988 struct route_map *route_map =
11989 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 11990
11991 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11992 protocol = ZEBRA_ROUTE_OSPF;
11993 else
11994 protocol = ZEBRA_ROUTE_TABLE;
11995
11996 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11997 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
11998 changed =
11999 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12000 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12001}
12002
12003ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12004 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12005 "redistribute <ospf|table> (1-65535) route-map WORD",
12006 "Redistribute information from another routing protocol\n"
12007 "Open Shortest Path First (OSPFv2)\n"
12008 "Non-main Kernel Routing Table\n"
12009 "Instance ID/Table ID\n"
12010 "Route map reference\n"
12011 "Pointer to route-map entries\n")
596c17ba 12012
7c8ff89e
DS
12013DEFUN (bgp_redistribute_ipv4_ospf_metric,
12014 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12015 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12016 "Redistribute information from another routing protocol\n"
12017 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12018 "Non-main Kernel Routing Table\n"
12019 "Instance ID/Table ID\n"
7c8ff89e
DS
12020 "Metric for redistributed routes\n"
12021 "Default metric\n")
12022{
d62a17ae 12023 VTY_DECLVAR_CONTEXT(bgp, bgp);
12024 int idx_ospf_table = 1;
12025 int idx_number = 2;
12026 int idx_number_2 = 4;
d7c0a89a 12027 uint32_t metric;
d62a17ae 12028 struct bgp_redist *red;
d7c0a89a 12029 unsigned short instance;
d62a17ae 12030 int protocol;
e923dd62 12031 bool changed;
d62a17ae 12032
12033 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12034 protocol = ZEBRA_ROUTE_OSPF;
12035 else
12036 protocol = ZEBRA_ROUTE_TABLE;
12037
12038 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12039 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12040
12041 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12042 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12043 metric);
12044 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12045}
12046
12047ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12048 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12049 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12050 "Redistribute information from another routing protocol\n"
12051 "Open Shortest Path First (OSPFv2)\n"
12052 "Non-main Kernel Routing Table\n"
12053 "Instance ID/Table ID\n"
12054 "Metric for redistributed routes\n"
12055 "Default metric\n")
596c17ba 12056
7c8ff89e
DS
12057DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12058 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12059 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12060 "Redistribute information from another routing protocol\n"
12061 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12062 "Non-main Kernel Routing Table\n"
12063 "Instance ID/Table ID\n"
7c8ff89e
DS
12064 "Route map reference\n"
12065 "Pointer to route-map entries\n"
12066 "Metric for redistributed routes\n"
12067 "Default metric\n")
12068{
d62a17ae 12069 VTY_DECLVAR_CONTEXT(bgp, bgp);
12070 int idx_ospf_table = 1;
12071 int idx_number = 2;
12072 int idx_word = 4;
12073 int idx_number_2 = 6;
d7c0a89a 12074 uint32_t metric;
d62a17ae 12075 struct bgp_redist *red;
d7c0a89a 12076 unsigned short instance;
d62a17ae 12077 int protocol;
e923dd62 12078 bool changed;
1de27621
DA
12079 struct route_map *route_map =
12080 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12081
12082 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12083 protocol = ZEBRA_ROUTE_OSPF;
12084 else
12085 protocol = ZEBRA_ROUTE_TABLE;
12086
12087 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12088 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12089
12090 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12091 changed =
12092 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12093 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12094 metric);
12095 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12096}
12097
12098ALIAS_HIDDEN(
12099 bgp_redistribute_ipv4_ospf_rmap_metric,
12100 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12101 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12102 "Redistribute information from another routing protocol\n"
12103 "Open Shortest Path First (OSPFv2)\n"
12104 "Non-main Kernel Routing Table\n"
12105 "Instance ID/Table ID\n"
12106 "Route map reference\n"
12107 "Pointer to route-map entries\n"
12108 "Metric for redistributed routes\n"
12109 "Default metric\n")
596c17ba 12110
7c8ff89e
DS
12111DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12112 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12113 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12114 "Redistribute information from another routing protocol\n"
12115 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12116 "Non-main Kernel Routing Table\n"
12117 "Instance ID/Table ID\n"
7c8ff89e
DS
12118 "Metric for redistributed routes\n"
12119 "Default metric\n"
12120 "Route map reference\n"
12121 "Pointer to route-map entries\n")
12122{
d62a17ae 12123 VTY_DECLVAR_CONTEXT(bgp, bgp);
12124 int idx_ospf_table = 1;
12125 int idx_number = 2;
12126 int idx_number_2 = 4;
12127 int idx_word = 6;
d7c0a89a 12128 uint32_t metric;
d62a17ae 12129 struct bgp_redist *red;
d7c0a89a 12130 unsigned short instance;
d62a17ae 12131 int protocol;
e923dd62 12132 bool changed;
1de27621
DA
12133 struct route_map *route_map =
12134 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12135
12136 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12137 protocol = ZEBRA_ROUTE_OSPF;
12138 else
12139 protocol = ZEBRA_ROUTE_TABLE;
12140
12141 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12142 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12143
12144 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12145 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12146 metric);
1de27621
DA
12147 changed |=
12148 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12149 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12150}
12151
12152ALIAS_HIDDEN(
12153 bgp_redistribute_ipv4_ospf_metric_rmap,
12154 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12155 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12156 "Redistribute information from another routing protocol\n"
12157 "Open Shortest Path First (OSPFv2)\n"
12158 "Non-main Kernel Routing Table\n"
12159 "Instance ID/Table ID\n"
12160 "Metric for redistributed routes\n"
12161 "Default metric\n"
12162 "Route map reference\n"
12163 "Pointer to route-map entries\n")
596c17ba 12164
7c8ff89e
DS
12165DEFUN (no_bgp_redistribute_ipv4_ospf,
12166 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12167 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12168 NO_STR
12169 "Redistribute information from another routing protocol\n"
12170 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12171 "Non-main Kernel Routing Table\n"
31500417
DW
12172 "Instance ID/Table ID\n"
12173 "Metric for redistributed routes\n"
12174 "Default metric\n"
12175 "Route map reference\n"
12176 "Pointer to route-map entries\n")
7c8ff89e 12177{
d62a17ae 12178 VTY_DECLVAR_CONTEXT(bgp, bgp);
12179 int idx_ospf_table = 2;
12180 int idx_number = 3;
d7c0a89a 12181 unsigned short instance;
d62a17ae 12182 int protocol;
12183
12184 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12185 protocol = ZEBRA_ROUTE_OSPF;
12186 else
12187 protocol = ZEBRA_ROUTE_TABLE;
12188
12189 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12190 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12191}
12192
12193ALIAS_HIDDEN(
12194 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12195 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12196 NO_STR
12197 "Redistribute information from another routing protocol\n"
12198 "Open Shortest Path First (OSPFv2)\n"
12199 "Non-main Kernel Routing Table\n"
12200 "Instance ID/Table ID\n"
12201 "Metric for redistributed routes\n"
12202 "Default metric\n"
12203 "Route map reference\n"
12204 "Pointer to route-map entries\n")
596c17ba 12205
718e3744 12206DEFUN (no_bgp_redistribute_ipv4,
12207 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12208 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12209 NO_STR
12210 "Redistribute information from another routing protocol\n"
3b14d86e 12211 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12212 "Metric for redistributed routes\n"
12213 "Default metric\n"
12214 "Route map reference\n"
12215 "Pointer to route-map entries\n")
718e3744 12216{
d62a17ae 12217 VTY_DECLVAR_CONTEXT(bgp, bgp);
12218 int idx_protocol = 2;
12219 int type;
12220
12221 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12222 if (type < 0) {
12223 vty_out(vty, "%% Invalid route type\n");
12224 return CMD_WARNING_CONFIG_FAILED;
12225 }
12226 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12227}
12228
12229ALIAS_HIDDEN(
12230 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12231 "no redistribute " FRR_IP_REDIST_STR_BGPD
12232 " [metric (0-4294967295)] [route-map WORD]",
12233 NO_STR
12234 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12235 "Metric for redistributed routes\n"
12236 "Default metric\n"
12237 "Route map reference\n"
12238 "Pointer to route-map entries\n")
596c17ba 12239
718e3744 12240DEFUN (bgp_redistribute_ipv6,
12241 bgp_redistribute_ipv6_cmd,
40d1cbfb 12242 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12243 "Redistribute information from another routing protocol\n"
ab0181ee 12244 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12245{
d62a17ae 12246 VTY_DECLVAR_CONTEXT(bgp, bgp);
12247 int idx_protocol = 1;
12248 int type;
718e3744 12249
d62a17ae 12250 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12251 if (type < 0) {
12252 vty_out(vty, "%% Invalid route type\n");
12253 return CMD_WARNING_CONFIG_FAILED;
12254 }
718e3744 12255
d62a17ae 12256 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12257 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12258}
12259
12260DEFUN (bgp_redistribute_ipv6_rmap,
12261 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12262 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12263 "Redistribute information from another routing protocol\n"
ab0181ee 12264 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12265 "Route map reference\n"
12266 "Pointer to route-map entries\n")
12267{
d62a17ae 12268 VTY_DECLVAR_CONTEXT(bgp, bgp);
12269 int idx_protocol = 1;
12270 int idx_word = 3;
12271 int type;
12272 struct bgp_redist *red;
e923dd62 12273 bool changed;
1de27621
DA
12274 struct route_map *route_map =
12275 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12276
d62a17ae 12277 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12278 if (type < 0) {
12279 vty_out(vty, "%% Invalid route type\n");
12280 return CMD_WARNING_CONFIG_FAILED;
12281 }
718e3744 12282
d62a17ae 12283 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12284 changed =
12285 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12286 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12287}
12288
12289DEFUN (bgp_redistribute_ipv6_metric,
12290 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12291 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12292 "Redistribute information from another routing protocol\n"
ab0181ee 12293 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12294 "Metric for redistributed routes\n"
12295 "Default metric\n")
12296{
d62a17ae 12297 VTY_DECLVAR_CONTEXT(bgp, bgp);
12298 int idx_protocol = 1;
12299 int idx_number = 3;
12300 int type;
d7c0a89a 12301 uint32_t metric;
d62a17ae 12302 struct bgp_redist *red;
e923dd62 12303 bool changed;
d62a17ae 12304
12305 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12306 if (type < 0) {
12307 vty_out(vty, "%% Invalid route type\n");
12308 return CMD_WARNING_CONFIG_FAILED;
12309 }
12310 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12311
d62a17ae 12312 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12313 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12314 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12315}
12316
12317DEFUN (bgp_redistribute_ipv6_rmap_metric,
12318 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12319 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12320 "Redistribute information from another routing protocol\n"
ab0181ee 12321 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12322 "Route map reference\n"
12323 "Pointer to route-map entries\n"
12324 "Metric for redistributed routes\n"
12325 "Default metric\n")
12326{
d62a17ae 12327 VTY_DECLVAR_CONTEXT(bgp, bgp);
12328 int idx_protocol = 1;
12329 int idx_word = 3;
12330 int idx_number = 5;
12331 int type;
d7c0a89a 12332 uint32_t metric;
d62a17ae 12333 struct bgp_redist *red;
e923dd62 12334 bool changed;
1de27621
DA
12335 struct route_map *route_map =
12336 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12337
12338 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12339 if (type < 0) {
12340 vty_out(vty, "%% Invalid route type\n");
12341 return CMD_WARNING_CONFIG_FAILED;
12342 }
12343 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12344
d62a17ae 12345 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12346 changed =
12347 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12348 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12349 metric);
12350 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12351}
12352
12353DEFUN (bgp_redistribute_ipv6_metric_rmap,
12354 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12355 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12356 "Redistribute information from another routing protocol\n"
ab0181ee 12357 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12358 "Metric for redistributed routes\n"
12359 "Default metric\n"
12360 "Route map reference\n"
12361 "Pointer to route-map entries\n")
12362{
d62a17ae 12363 VTY_DECLVAR_CONTEXT(bgp, bgp);
12364 int idx_protocol = 1;
12365 int idx_number = 3;
12366 int idx_word = 5;
12367 int type;
d7c0a89a 12368 uint32_t metric;
d62a17ae 12369 struct bgp_redist *red;
e923dd62 12370 bool changed;
1de27621
DA
12371 struct route_map *route_map =
12372 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12373
12374 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12375 if (type < 0) {
12376 vty_out(vty, "%% Invalid route type\n");
12377 return CMD_WARNING_CONFIG_FAILED;
12378 }
12379 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12380
d62a17ae 12381 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12382 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12383 metric);
1de27621
DA
12384 changed |=
12385 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12386 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12387}
12388
12389DEFUN (no_bgp_redistribute_ipv6,
12390 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12391 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12392 NO_STR
12393 "Redistribute information from another routing protocol\n"
3b14d86e 12394 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12395 "Metric for redistributed routes\n"
12396 "Default metric\n"
12397 "Route map reference\n"
12398 "Pointer to route-map entries\n")
718e3744 12399{
d62a17ae 12400 VTY_DECLVAR_CONTEXT(bgp, bgp);
12401 int idx_protocol = 2;
12402 int type;
718e3744 12403
d62a17ae 12404 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12405 if (type < 0) {
12406 vty_out(vty, "%% Invalid route type\n");
12407 return CMD_WARNING_CONFIG_FAILED;
12408 }
718e3744 12409
d62a17ae 12410 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12411}
12412
2b791107 12413void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12414 safi_t safi)
d62a17ae 12415{
12416 int i;
12417
12418 /* Unicast redistribution only. */
12419 if (safi != SAFI_UNICAST)
2b791107 12420 return;
d62a17ae 12421
12422 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12423 /* Redistribute BGP does not make sense. */
12424 if (i != ZEBRA_ROUTE_BGP) {
12425 struct list *red_list;
12426 struct listnode *node;
12427 struct bgp_redist *red;
12428
12429 red_list = bgp->redist[afi][i];
12430 if (!red_list)
12431 continue;
12432
12433 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12434 /* "redistribute" configuration. */
12435 vty_out(vty, " redistribute %s",
12436 zebra_route_string(i));
12437 if (red->instance)
12438 vty_out(vty, " %d", red->instance);
12439 if (red->redist_metric_flag)
12440 vty_out(vty, " metric %u",
12441 red->redist_metric);
12442 if (red->rmap.name)
12443 vty_out(vty, " route-map %s",
12444 red->rmap.name);
12445 vty_out(vty, "\n");
12446 }
12447 }
12448 }
718e3744 12449}
6b0655a2 12450
b9c7bc5a
PZ
12451/* This is part of the address-family block (unicast only) */
12452void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12453 afi_t afi)
12454{
b9c7bc5a 12455 int indent = 2;
ddb5b488 12456
8a066a70
PG
12457 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12458 if (listcount(bgp->vpn_policy[afi].import_vrf))
12459 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12460 bgp->vpn_policy[afi]
bb4f6190 12461 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12462 else
12463 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12464 bgp->vpn_policy[afi]
12465 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12466 }
12a844a5
DS
12467 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12468 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12469 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12470 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12471 return;
12472
e70e9f8e
PZ
12473 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12474 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12475
12476 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12477
12478 } else {
12479 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12480 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12481 bgp->vpn_policy[afi].tovpn_label);
12482 }
ddb5b488
PZ
12483 }
12484 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12485 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12486 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12487 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12488 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12489 sizeof(buf)));
12490 }
12491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12492 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12493
12494 char buf[PREFIX_STRLEN];
12495 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12496 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12497 sizeof(buf))) {
12498
b9c7bc5a
PZ
12499 vty_out(vty, "%*snexthop vpn export %s\n",
12500 indent, "", buf);
ddb5b488
PZ
12501 }
12502 }
12503 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12504 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12505 && ecommunity_cmp(
12506 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12507 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12508
12509 char *b = ecommunity_ecom2str(
12510 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12511 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12512 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12513 XFREE(MTYPE_ECOMMUNITY_STR, b);
12514 } else {
12515 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12516 char *b = ecommunity_ecom2str(
12517 bgp->vpn_policy[afi]
12518 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12519 ECOMMUNITY_FORMAT_ROUTE_MAP,
12520 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12521 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12522 XFREE(MTYPE_ECOMMUNITY_STR, b);
12523 }
12524 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12525 char *b = ecommunity_ecom2str(
12526 bgp->vpn_policy[afi]
12527 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12528 ECOMMUNITY_FORMAT_ROUTE_MAP,
12529 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12530 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12531 XFREE(MTYPE_ECOMMUNITY_STR, b);
12532 }
12533 }
bb4f6190
DS
12534
12535 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12536 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12537 bgp->vpn_policy[afi]
12538 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12539
301ad80a
PG
12540 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12541 char *b = ecommunity_ecom2str(
12542 bgp->vpn_policy[afi]
12543 .import_redirect_rtlist,
12544 ECOMMUNITY_FORMAT_ROUTE_MAP,
12545 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12546
301ad80a
PG
12547 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12548 XFREE(MTYPE_ECOMMUNITY_STR, b);
12549 }
ddb5b488
PZ
12550}
12551
12552
718e3744 12553/* BGP node structure. */
d62a17ae 12554static struct cmd_node bgp_node = {
9d303b37 12555 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12556};
12557
d62a17ae 12558static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12559 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12560};
12561
d62a17ae 12562static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12563 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12564};
12565
d62a17ae 12566static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12567 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12568};
12569
d62a17ae 12570static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12571 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12572};
12573
d62a17ae 12574static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12575 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12576};
12577
d62a17ae 12578static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12579 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12580};
12581
d62a17ae 12582static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12583 "%s(config-router-af)# ", 1};
6b0655a2 12584
d62a17ae 12585static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12586 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12587
d62a17ae 12588static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12589 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12590
d62a17ae 12591static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12592 "%s(config-router-af-vni)# ", 1};
90e60aa7 12593
7c40bf39 12594static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12595 "%s(config-router-af)# ", 1};
12596
12597static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12598 "%s(config-router-af-vpnv6)# ", 1};
12599
d62a17ae 12600static void community_list_vty(void);
1f8ae70b 12601
d62a17ae 12602static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12603{
d62a17ae 12604 struct bgp *bgp;
12605 struct peer *peer;
d62a17ae 12606 struct listnode *lnbgp, *lnpeer;
b8a815e5 12607
d62a17ae 12608 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12609 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12610 /* only provide suggestions on the appropriate input
12611 * token type,
12612 * they'll otherwise show up multiple times */
12613 enum cmd_token_type match_type;
12614 char *name = peer->host;
d48ed3e0 12615
d62a17ae 12616 if (peer->conf_if) {
12617 match_type = VARIABLE_TKN;
12618 name = peer->conf_if;
12619 } else if (strchr(peer->host, ':'))
12620 match_type = IPV6_TKN;
12621 else
12622 match_type = IPV4_TKN;
d48ed3e0 12623
d62a17ae 12624 if (token->type != match_type)
12625 continue;
d48ed3e0 12626
d62a17ae 12627 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12628 }
d62a17ae 12629 }
b8a815e5
DL
12630}
12631
12632static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12633 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12634 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12635 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12636 {.completions = NULL}};
12637
47a306a0
DS
12638static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12639{
12640 struct bgp *bgp;
12641 struct peer_group *group;
12642 struct listnode *lnbgp, *lnpeer;
12643
12644 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12645 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12646 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12647 group->name));
12648 }
12649}
12650
12651static const struct cmd_variable_handler bgp_var_peergroup[] = {
12652 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12653 {.completions = NULL} };
12654
d62a17ae 12655void bgp_vty_init(void)
12656{
12657 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12658 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12659
12660 /* Install bgp top node. */
12661 install_node(&bgp_node, bgp_config_write);
12662 install_node(&bgp_ipv4_unicast_node, NULL);
12663 install_node(&bgp_ipv4_multicast_node, NULL);
12664 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12665 install_node(&bgp_ipv6_unicast_node, NULL);
12666 install_node(&bgp_ipv6_multicast_node, NULL);
12667 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12668 install_node(&bgp_vpnv4_node, NULL);
12669 install_node(&bgp_vpnv6_node, NULL);
12670 install_node(&bgp_evpn_node, NULL);
12671 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12672 install_node(&bgp_flowspecv4_node, NULL);
12673 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12674
12675 /* Install default VTY commands to new nodes. */
12676 install_default(BGP_NODE);
12677 install_default(BGP_IPV4_NODE);
12678 install_default(BGP_IPV4M_NODE);
12679 install_default(BGP_IPV4L_NODE);
12680 install_default(BGP_IPV6_NODE);
12681 install_default(BGP_IPV6M_NODE);
12682 install_default(BGP_IPV6L_NODE);
12683 install_default(BGP_VPNV4_NODE);
12684 install_default(BGP_VPNV6_NODE);
7c40bf39 12685 install_default(BGP_FLOWSPECV4_NODE);
12686 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12687 install_default(BGP_EVPN_NODE);
12688 install_default(BGP_EVPN_VNI_NODE);
12689
12690 /* "bgp multiple-instance" commands. */
12691 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12692 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12693
12694 /* "bgp config-type" commands. */
12695 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12696 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12697
8029b216
AK
12698 /* "bgp local-mac" hidden commands. */
12699 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12700 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12701
d62a17ae 12702 /* bgp route-map delay-timer commands. */
12703 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12704 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12705
12706 /* Dummy commands (Currently not supported) */
12707 install_element(BGP_NODE, &no_synchronization_cmd);
12708 install_element(BGP_NODE, &no_auto_summary_cmd);
12709
12710 /* "router bgp" commands. */
12711 install_element(CONFIG_NODE, &router_bgp_cmd);
12712
12713 /* "no router bgp" commands. */
12714 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12715
12716 /* "bgp router-id" commands. */
12717 install_element(BGP_NODE, &bgp_router_id_cmd);
12718 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12719
12720 /* "bgp cluster-id" commands. */
12721 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12722 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12723
12724 /* "bgp confederation" commands. */
12725 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12726 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12727
12728 /* "bgp confederation peers" commands. */
12729 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12730 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12731
12732 /* bgp max-med command */
12733 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12734 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12735 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12736 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12737 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12738
12739 /* bgp disable-ebgp-connected-nh-check */
12740 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12741 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12742
12743 /* bgp update-delay command */
12744 install_element(BGP_NODE, &bgp_update_delay_cmd);
12745 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12746 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12747
12748 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12749 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12750 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12751 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12752
12753 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12754 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12755
12756 /* "maximum-paths" commands. */
12757 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12758 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12759 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12760 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12761 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12762 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12763 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12764 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12765 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12766 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12767 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12768 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12769 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12770 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12771 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12772
12773 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12774 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12775 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12776 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12777 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12778
12779 /* "timers bgp" commands. */
12780 install_element(BGP_NODE, &bgp_timers_cmd);
12781 install_element(BGP_NODE, &no_bgp_timers_cmd);
12782
12783 /* route-map delay-timer commands - per instance for backwards compat.
12784 */
12785 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12786 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12787
12788 /* "bgp client-to-client reflection" commands */
12789 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12790 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12791
12792 /* "bgp always-compare-med" commands */
12793 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12794 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12795
12796 /* "bgp deterministic-med" commands */
12797 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12798 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12799
12800 /* "bgp graceful-restart" commands */
12801 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12802 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12803 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12804 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12805 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12806 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12807
12808 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12809 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12810
7f323236
DW
12811 /* "bgp graceful-shutdown" commands */
12812 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12813 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12814
d62a17ae 12815 /* "bgp fast-external-failover" commands */
12816 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12817 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12818
12819 /* "bgp enforce-first-as" commands */
12820 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 12821
12822 /* "bgp bestpath compare-routerid" commands */
12823 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12824 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12825
12826 /* "bgp bestpath as-path ignore" commands */
12827 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12828 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12829
12830 /* "bgp bestpath as-path confed" commands */
12831 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12832 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12833
12834 /* "bgp bestpath as-path multipath-relax" commands */
12835 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12836 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12837
12838 /* "bgp log-neighbor-changes" commands */
12839 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12840 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12841
12842 /* "bgp bestpath med" commands */
12843 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12844 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12845
12846 /* "no bgp default ipv4-unicast" commands. */
12847 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12848 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12849
12850 /* "bgp network import-check" commands. */
12851 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12852 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12853 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12854
12855 /* "bgp default local-preference" commands. */
12856 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12857 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12858
12859 /* bgp default show-hostname */
12860 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12861 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12862
12863 /* "bgp default subgroup-pkt-queue-max" commands. */
12864 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12865 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12866
12867 /* bgp ibgp-allow-policy-mods command */
12868 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12869 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12870
12871 /* "bgp listen limit" commands. */
12872 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12873 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12874
12875 /* "bgp listen range" commands. */
12876 install_element(BGP_NODE, &bgp_listen_range_cmd);
12877 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12878
8175f54a 12879 /* "bgp default shutdown" command */
f26845f9
QY
12880 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12881
d62a17ae 12882 /* "neighbor remote-as" commands. */
12883 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12884 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12885 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12886 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12887 install_element(BGP_NODE,
12888 &neighbor_interface_v6only_config_remote_as_cmd);
12889 install_element(BGP_NODE, &no_neighbor_cmd);
12890 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12891
12892 /* "neighbor peer-group" commands. */
12893 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12894 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12895 install_element(BGP_NODE,
12896 &no_neighbor_interface_peer_group_remote_as_cmd);
12897
12898 /* "neighbor local-as" commands. */
12899 install_element(BGP_NODE, &neighbor_local_as_cmd);
12900 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12901 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12902 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12903
12904 /* "neighbor solo" commands. */
12905 install_element(BGP_NODE, &neighbor_solo_cmd);
12906 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12907
12908 /* "neighbor password" commands. */
12909 install_element(BGP_NODE, &neighbor_password_cmd);
12910 install_element(BGP_NODE, &no_neighbor_password_cmd);
12911
12912 /* "neighbor activate" commands. */
12913 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12914 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12915 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12916 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12917 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12918 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12919 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12920 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12921 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 12922 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12923 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 12924 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12925
12926 /* "no neighbor activate" commands. */
12927 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12928 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12929 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12930 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12931 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12933 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12934 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12935 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 12936 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12937 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 12938 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12939
12940 /* "neighbor peer-group" set commands. */
12941 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12942 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12943 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12944 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12945 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12946 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12947 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12948 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 12949 install_element(BGP_FLOWSPECV4_NODE,
12950 &neighbor_set_peer_group_hidden_cmd);
12951 install_element(BGP_FLOWSPECV6_NODE,
12952 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 12953
12954 /* "no neighbor peer-group unset" commands. */
12955 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12956 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12957 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12958 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12959 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12960 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12961 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12962 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 12963 install_element(BGP_FLOWSPECV4_NODE,
12964 &no_neighbor_set_peer_group_hidden_cmd);
12965 install_element(BGP_FLOWSPECV6_NODE,
12966 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 12967
12968 /* "neighbor softreconfiguration inbound" commands.*/
12969 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12970 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12971 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12972 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12973 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12974 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12975 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12976 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12977 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12978 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12979 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12980 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12981 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12982 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12983 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12984 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12985 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12986 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 12987 install_element(BGP_FLOWSPECV4_NODE,
12988 &neighbor_soft_reconfiguration_cmd);
12989 install_element(BGP_FLOWSPECV4_NODE,
12990 &no_neighbor_soft_reconfiguration_cmd);
12991 install_element(BGP_FLOWSPECV6_NODE,
12992 &neighbor_soft_reconfiguration_cmd);
12993 install_element(BGP_FLOWSPECV6_NODE,
12994 &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 12995
12996 /* "neighbor attribute-unchanged" commands. */
12997 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12998 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12999 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13000 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13001 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13002 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13003 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13004 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13006 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13007 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13008 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13009 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13010 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13011 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13012 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13013 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13014 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13015
13016 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13017 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13018
13019 /* "nexthop-local unchanged" commands */
13020 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13021 install_element(BGP_IPV6_NODE,
13022 &no_neighbor_nexthop_local_unchanged_cmd);
13023
13024 /* "neighbor next-hop-self" commands. */
13025 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13026 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13027 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13028 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13029 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13030 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13031 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13032 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13033 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13034 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13035 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13036 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13037 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13038 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13039 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13040 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13041 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13042 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13043 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13044 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13045
13046 /* "neighbor next-hop-self force" commands. */
13047 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13048 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13049 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13050 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13051 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13052 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13053 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13054 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13055 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13056 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13057 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13058 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13059 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13061 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13062 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13063 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13064 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13065
13066 /* "neighbor as-override" commands. */
13067 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13068 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13069 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13070 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13071 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13072 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13073 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13074 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13075 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13076 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13077 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13078 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13079 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13080 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13081 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13082 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13083 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13084 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13085
13086 /* "neighbor remove-private-AS" commands. */
13087 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13088 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13089 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13090 install_element(BGP_NODE,
13091 &no_neighbor_remove_private_as_all_hidden_cmd);
13092 install_element(BGP_NODE,
13093 &neighbor_remove_private_as_replace_as_hidden_cmd);
13094 install_element(BGP_NODE,
13095 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13096 install_element(BGP_NODE,
13097 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13098 install_element(
13099 BGP_NODE,
13100 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13101 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13102 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13103 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13104 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13105 install_element(BGP_IPV4_NODE,
13106 &neighbor_remove_private_as_replace_as_cmd);
13107 install_element(BGP_IPV4_NODE,
13108 &no_neighbor_remove_private_as_replace_as_cmd);
13109 install_element(BGP_IPV4_NODE,
13110 &neighbor_remove_private_as_all_replace_as_cmd);
13111 install_element(BGP_IPV4_NODE,
13112 &no_neighbor_remove_private_as_all_replace_as_cmd);
13113 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13114 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13115 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13116 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13117 install_element(BGP_IPV4M_NODE,
13118 &neighbor_remove_private_as_replace_as_cmd);
13119 install_element(BGP_IPV4M_NODE,
13120 &no_neighbor_remove_private_as_replace_as_cmd);
13121 install_element(BGP_IPV4M_NODE,
13122 &neighbor_remove_private_as_all_replace_as_cmd);
13123 install_element(BGP_IPV4M_NODE,
13124 &no_neighbor_remove_private_as_all_replace_as_cmd);
13125 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13126 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13127 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13128 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13129 install_element(BGP_IPV4L_NODE,
13130 &neighbor_remove_private_as_replace_as_cmd);
13131 install_element(BGP_IPV4L_NODE,
13132 &no_neighbor_remove_private_as_replace_as_cmd);
13133 install_element(BGP_IPV4L_NODE,
13134 &neighbor_remove_private_as_all_replace_as_cmd);
13135 install_element(BGP_IPV4L_NODE,
13136 &no_neighbor_remove_private_as_all_replace_as_cmd);
13137 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13138 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13139 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13140 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13141 install_element(BGP_IPV6_NODE,
13142 &neighbor_remove_private_as_replace_as_cmd);
13143 install_element(BGP_IPV6_NODE,
13144 &no_neighbor_remove_private_as_replace_as_cmd);
13145 install_element(BGP_IPV6_NODE,
13146 &neighbor_remove_private_as_all_replace_as_cmd);
13147 install_element(BGP_IPV6_NODE,
13148 &no_neighbor_remove_private_as_all_replace_as_cmd);
13149 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13150 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13151 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13152 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13153 install_element(BGP_IPV6M_NODE,
13154 &neighbor_remove_private_as_replace_as_cmd);
13155 install_element(BGP_IPV6M_NODE,
13156 &no_neighbor_remove_private_as_replace_as_cmd);
13157 install_element(BGP_IPV6M_NODE,
13158 &neighbor_remove_private_as_all_replace_as_cmd);
13159 install_element(BGP_IPV6M_NODE,
13160 &no_neighbor_remove_private_as_all_replace_as_cmd);
13161 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13162 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13163 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13164 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13165 install_element(BGP_IPV6L_NODE,
13166 &neighbor_remove_private_as_replace_as_cmd);
13167 install_element(BGP_IPV6L_NODE,
13168 &no_neighbor_remove_private_as_replace_as_cmd);
13169 install_element(BGP_IPV6L_NODE,
13170 &neighbor_remove_private_as_all_replace_as_cmd);
13171 install_element(BGP_IPV6L_NODE,
13172 &no_neighbor_remove_private_as_all_replace_as_cmd);
13173 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13174 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13175 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13176 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13177 install_element(BGP_VPNV4_NODE,
13178 &neighbor_remove_private_as_replace_as_cmd);
13179 install_element(BGP_VPNV4_NODE,
13180 &no_neighbor_remove_private_as_replace_as_cmd);
13181 install_element(BGP_VPNV4_NODE,
13182 &neighbor_remove_private_as_all_replace_as_cmd);
13183 install_element(BGP_VPNV4_NODE,
13184 &no_neighbor_remove_private_as_all_replace_as_cmd);
13185 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13186 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13187 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13188 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13189 install_element(BGP_VPNV6_NODE,
13190 &neighbor_remove_private_as_replace_as_cmd);
13191 install_element(BGP_VPNV6_NODE,
13192 &no_neighbor_remove_private_as_replace_as_cmd);
13193 install_element(BGP_VPNV6_NODE,
13194 &neighbor_remove_private_as_all_replace_as_cmd);
13195 install_element(BGP_VPNV6_NODE,
13196 &no_neighbor_remove_private_as_all_replace_as_cmd);
13197
13198 /* "neighbor send-community" commands.*/
13199 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13200 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13201 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13202 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13203 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13204 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13205 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13206 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13207 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13208 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13210 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13211 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13214 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13215 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13216 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13217 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13218 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13220 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13221 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13222 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13223 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13224 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13225 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13226 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13227 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13228 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13229 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13230 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13231 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13232 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13233 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13234 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13235
13236 /* "neighbor route-reflector" commands.*/
13237 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13238 install_element(BGP_NODE,
13239 &no_neighbor_route_reflector_client_hidden_cmd);
13240 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13241 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13242 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13243 install_element(BGP_IPV4M_NODE,
13244 &no_neighbor_route_reflector_client_cmd);
13245 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13246 install_element(BGP_IPV4L_NODE,
13247 &no_neighbor_route_reflector_client_cmd);
13248 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13249 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13250 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13251 install_element(BGP_IPV6M_NODE,
13252 &no_neighbor_route_reflector_client_cmd);
13253 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13254 install_element(BGP_IPV6L_NODE,
13255 &no_neighbor_route_reflector_client_cmd);
13256 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13257 install_element(BGP_VPNV4_NODE,
13258 &no_neighbor_route_reflector_client_cmd);
13259 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13260 install_element(BGP_VPNV6_NODE,
13261 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13262 install_element(BGP_FLOWSPECV4_NODE,
13263 &neighbor_route_reflector_client_cmd);
13264 install_element(BGP_FLOWSPECV4_NODE,
13265 &no_neighbor_route_reflector_client_cmd);
13266 install_element(BGP_FLOWSPECV6_NODE,
13267 &neighbor_route_reflector_client_cmd);
13268 install_element(BGP_FLOWSPECV6_NODE,
13269 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13270 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13271 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13272
13273 /* "neighbor route-server" commands.*/
13274 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13275 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13276 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13277 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13278 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13280 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13281 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13282 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13283 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13284 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13285 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13287 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13288 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13289 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13290 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13291 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13292 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13293 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13294 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13295 install_element(BGP_FLOWSPECV4_NODE,
13296 &no_neighbor_route_server_client_cmd);
13297 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13298 install_element(BGP_FLOWSPECV6_NODE,
13299 &no_neighbor_route_server_client_cmd);
d62a17ae 13300
13301 /* "neighbor addpath-tx-all-paths" commands.*/
13302 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13303 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13304 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13305 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13306 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13307 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13308 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13309 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13310 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13311 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13312 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13313 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13314 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13315 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13316 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13317 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13320
13321 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13322 install_element(BGP_NODE,
13323 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13324 install_element(BGP_NODE,
13325 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13326 install_element(BGP_IPV4_NODE,
13327 &neighbor_addpath_tx_bestpath_per_as_cmd);
13328 install_element(BGP_IPV4_NODE,
13329 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13330 install_element(BGP_IPV4M_NODE,
13331 &neighbor_addpath_tx_bestpath_per_as_cmd);
13332 install_element(BGP_IPV4M_NODE,
13333 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13334 install_element(BGP_IPV4L_NODE,
13335 &neighbor_addpath_tx_bestpath_per_as_cmd);
13336 install_element(BGP_IPV4L_NODE,
13337 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13338 install_element(BGP_IPV6_NODE,
13339 &neighbor_addpath_tx_bestpath_per_as_cmd);
13340 install_element(BGP_IPV6_NODE,
13341 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13342 install_element(BGP_IPV6M_NODE,
13343 &neighbor_addpath_tx_bestpath_per_as_cmd);
13344 install_element(BGP_IPV6M_NODE,
13345 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13346 install_element(BGP_IPV6L_NODE,
13347 &neighbor_addpath_tx_bestpath_per_as_cmd);
13348 install_element(BGP_IPV6L_NODE,
13349 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13350 install_element(BGP_VPNV4_NODE,
13351 &neighbor_addpath_tx_bestpath_per_as_cmd);
13352 install_element(BGP_VPNV4_NODE,
13353 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13354 install_element(BGP_VPNV6_NODE,
13355 &neighbor_addpath_tx_bestpath_per_as_cmd);
13356 install_element(BGP_VPNV6_NODE,
13357 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13358
13359 /* "neighbor passive" commands. */
13360 install_element(BGP_NODE, &neighbor_passive_cmd);
13361 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13362
13363
13364 /* "neighbor shutdown" commands. */
13365 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13366 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13367 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13368 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13369
13370 /* "neighbor capability extended-nexthop" commands.*/
13371 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13372 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13373
13374 /* "neighbor capability orf prefix-list" commands.*/
13375 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13376 install_element(BGP_NODE,
13377 &no_neighbor_capability_orf_prefix_hidden_cmd);
13378 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13379 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13380 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13381 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13382 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13383 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13384 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13385 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13386 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13387 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13388 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13389 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13390
13391 /* "neighbor capability dynamic" commands.*/
13392 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13393 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13394
13395 /* "neighbor dont-capability-negotiate" commands. */
13396 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13397 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13398
13399 /* "neighbor ebgp-multihop" commands. */
13400 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13401 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13402 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13403
13404 /* "neighbor disable-connected-check" commands. */
13405 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13406 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13407
47cbc09b
PM
13408 /* "neighbor enforce-first-as" commands. */
13409 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13410 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13411
d62a17ae 13412 /* "neighbor description" commands. */
13413 install_element(BGP_NODE, &neighbor_description_cmd);
13414 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13415 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13416
13417 /* "neighbor update-source" commands. "*/
13418 install_element(BGP_NODE, &neighbor_update_source_cmd);
13419 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13420
13421 /* "neighbor default-originate" commands. */
13422 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13423 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13424 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13425 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13426 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13427 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13428 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13429 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13430 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13431 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13432 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13433 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13434 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13435 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13436 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13437 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13438 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13439 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13440 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13441 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13442 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13443
13444 /* "neighbor port" commands. */
13445 install_element(BGP_NODE, &neighbor_port_cmd);
13446 install_element(BGP_NODE, &no_neighbor_port_cmd);
13447
13448 /* "neighbor weight" commands. */
13449 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13450 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13451
13452 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13453 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13454 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13455 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13456 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13457 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13458 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13459 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13460 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13461 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13462 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13463 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13464 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13465 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13466 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13467 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13468
13469 /* "neighbor override-capability" commands. */
13470 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13471 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13472
13473 /* "neighbor strict-capability-match" commands. */
13474 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13475 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13476
13477 /* "neighbor timers" commands. */
13478 install_element(BGP_NODE, &neighbor_timers_cmd);
13479 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13480
13481 /* "neighbor timers connect" commands. */
13482 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13483 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13484
13485 /* "neighbor advertisement-interval" commands. */
13486 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13487 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13488
13489 /* "neighbor interface" commands. */
13490 install_element(BGP_NODE, &neighbor_interface_cmd);
13491 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13492
13493 /* "neighbor distribute" commands. */
13494 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13495 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13496 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13497 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13498 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13499 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13500 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13501 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13502 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13503 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13504 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13505 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13506 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13507 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13508 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13509 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13510 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13511 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13512
13513 /* "neighbor prefix-list" commands. */
13514 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13515 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13516 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13517 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13518 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13519 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13520 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13521 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13522 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13523 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13524 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13525 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13526 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13527 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13528 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13529 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13530 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13531 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13532 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13533 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13534 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13535 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13536
13537 /* "neighbor filter-list" commands. */
13538 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13539 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13540 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13541 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13542 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13543 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13544 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13545 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13546 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13547 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13548 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13549 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13550 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13551 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13552 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13553 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13554 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13555 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13556 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13557 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13558 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13559 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13560
13561 /* "neighbor route-map" commands. */
13562 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13563 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13564 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13565 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13566 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13567 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13568 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13569 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13570 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13571 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13572 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13573 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13574 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13575 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13576 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13577 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13578 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13579 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13580 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13581 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13582 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13583 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13584 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13585 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13586
13587 /* "neighbor unsuppress-map" commands. */
13588 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13589 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13590 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13591 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13592 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13593 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13594 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13595 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13596 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13597 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13598 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13599 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13600 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13601 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13602 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13603 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13604 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13605 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13606
13607 /* "neighbor maximum-prefix" commands. */
13608 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13609 install_element(BGP_NODE,
13610 &neighbor_maximum_prefix_threshold_hidden_cmd);
13611 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13612 install_element(BGP_NODE,
13613 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13614 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13615 install_element(BGP_NODE,
13616 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13617 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13618 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13619 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13620 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13621 install_element(BGP_IPV4_NODE,
13622 &neighbor_maximum_prefix_threshold_warning_cmd);
13623 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13624 install_element(BGP_IPV4_NODE,
13625 &neighbor_maximum_prefix_threshold_restart_cmd);
13626 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13627 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13628 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13629 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13630 install_element(BGP_IPV4M_NODE,
13631 &neighbor_maximum_prefix_threshold_warning_cmd);
13632 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13633 install_element(BGP_IPV4M_NODE,
13634 &neighbor_maximum_prefix_threshold_restart_cmd);
13635 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13636 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13637 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13638 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13639 install_element(BGP_IPV4L_NODE,
13640 &neighbor_maximum_prefix_threshold_warning_cmd);
13641 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13642 install_element(BGP_IPV4L_NODE,
13643 &neighbor_maximum_prefix_threshold_restart_cmd);
13644 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13645 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13646 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13647 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13648 install_element(BGP_IPV6_NODE,
13649 &neighbor_maximum_prefix_threshold_warning_cmd);
13650 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13651 install_element(BGP_IPV6_NODE,
13652 &neighbor_maximum_prefix_threshold_restart_cmd);
13653 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13654 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13655 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13656 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13657 install_element(BGP_IPV6M_NODE,
13658 &neighbor_maximum_prefix_threshold_warning_cmd);
13659 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13660 install_element(BGP_IPV6M_NODE,
13661 &neighbor_maximum_prefix_threshold_restart_cmd);
13662 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13663 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13664 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13665 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13666 install_element(BGP_IPV6L_NODE,
13667 &neighbor_maximum_prefix_threshold_warning_cmd);
13668 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13669 install_element(BGP_IPV6L_NODE,
13670 &neighbor_maximum_prefix_threshold_restart_cmd);
13671 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13672 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13673 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13674 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13675 install_element(BGP_VPNV4_NODE,
13676 &neighbor_maximum_prefix_threshold_warning_cmd);
13677 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13678 install_element(BGP_VPNV4_NODE,
13679 &neighbor_maximum_prefix_threshold_restart_cmd);
13680 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13681 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13682 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13683 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13684 install_element(BGP_VPNV6_NODE,
13685 &neighbor_maximum_prefix_threshold_warning_cmd);
13686 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13687 install_element(BGP_VPNV6_NODE,
13688 &neighbor_maximum_prefix_threshold_restart_cmd);
13689 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13690
13691 /* "neighbor allowas-in" */
13692 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13693 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13694 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13695 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13696 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13697 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13698 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13699 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13700 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13701 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13702 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13703 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13704 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13705 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13706 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13707 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13708 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13709 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13710 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13711 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13712
13713 /* address-family commands. */
13714 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13715 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13716#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13717 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13718 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13719#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13720
d62a17ae 13721 install_element(BGP_NODE, &address_family_evpn_cmd);
13722
13723 /* "exit-address-family" command. */
13724 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13725 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13726 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13727 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13728 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13729 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13730 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13731 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13732 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13733 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13734 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13735
13736 /* "clear ip bgp commands" */
13737 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13738
13739 /* clear ip bgp prefix */
13740 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13741 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13742 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13743
13744 /* "show [ip] bgp summary" commands. */
13745 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13746 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13747 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13748 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13749 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13750 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13751 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13752
13753 /* "show [ip] bgp neighbors" commands. */
13754 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13755
13756 /* "show [ip] bgp peer-group" commands. */
13757 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13758
13759 /* "show [ip] bgp paths" commands. */
13760 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13761
13762 /* "show [ip] bgp community" commands. */
13763 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13764
13765 /* "show ip bgp large-community" commands. */
13766 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13767 /* "show [ip] bgp attribute-info" commands. */
13768 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13769 /* "show [ip] bgp route-leak" command */
13770 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13771
13772 /* "redistribute" commands. */
13773 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13774 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13775 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13776 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13777 install_element(BGP_NODE,
13778 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13779 install_element(BGP_NODE,
13780 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13781 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13782 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13783 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13784 install_element(BGP_NODE,
13785 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13786 install_element(BGP_NODE,
13787 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13788 install_element(BGP_NODE,
13789 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13790 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13791 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13792 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13793 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13794 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13795 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13796 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13797 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13798 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13800 install_element(BGP_IPV4_NODE,
13801 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13802 install_element(BGP_IPV4_NODE,
13803 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13804 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13805 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13806 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13807 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13808 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13809 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13810
b9c7bc5a
PZ
13811 /* import|export vpn [route-map WORD] */
13812 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13813 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13814
12a844a5
DS
13815 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13816 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13817
d62a17ae 13818 /* ttl_security commands */
13819 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13820 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13821
13822 /* "show [ip] bgp memory" commands. */
13823 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13824
acf71666
MK
13825 /* "show bgp martian next-hop" */
13826 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13827
d62a17ae 13828 /* "show [ip] bgp views" commands. */
13829 install_element(VIEW_NODE, &show_bgp_views_cmd);
13830
13831 /* "show [ip] bgp vrfs" commands. */
13832 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13833
13834 /* Community-list. */
13835 community_list_vty();
ddb5b488
PZ
13836
13837 /* vpn-policy commands */
b9c7bc5a
PZ
13838 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13839 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13840 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13841 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13842 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13843 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13844 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13845 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13846 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13847 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
13848 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13849 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 13850
301ad80a
PG
13851 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13852 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13853
b9c7bc5a
PZ
13854 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13855 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13856 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13857 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13858 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13859 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13860 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13861 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13862 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13863 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
13864 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13865 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 13866}
6b0655a2 13867
718e3744 13868#include "memory.h"
13869#include "bgp_regex.h"
13870#include "bgp_clist.h"
13871#include "bgp_ecommunity.h"
13872
13873/* VTY functions. */
13874
13875/* Direction value to string conversion. */
d62a17ae 13876static const char *community_direct_str(int direct)
13877{
13878 switch (direct) {
13879 case COMMUNITY_DENY:
13880 return "deny";
13881 case COMMUNITY_PERMIT:
13882 return "permit";
13883 default:
13884 return "unknown";
13885 }
718e3744 13886}
13887
13888/* Display error string. */
d62a17ae 13889static void community_list_perror(struct vty *vty, int ret)
13890{
13891 switch (ret) {
13892 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13893 vty_out(vty, "%% Can't find community-list\n");
13894 break;
13895 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13896 vty_out(vty, "%% Malformed community-list value\n");
13897 break;
13898 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13899 vty_out(vty,
13900 "%% Community name conflict, previously defined as standard community\n");
13901 break;
13902 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13903 vty_out(vty,
13904 "%% Community name conflict, previously defined as expanded community\n");
13905 break;
13906 }
718e3744 13907}
13908
5bf15956
DW
13909/* "community-list" keyword help string. */
13910#define COMMUNITY_LIST_STR "Add a community list entry\n"
13911
7336e101
SP
13912/*community-list standard */
13913DEFUN (community_list_standard,
13914 bgp_community_list_standard_cmd,
13915 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13916 BGP_STR
718e3744 13917 COMMUNITY_LIST_STR
13918 "Community list number (standard)\n"
5bf15956 13919 "Add an standard community-list entry\n"
718e3744 13920 "Community list name\n"
13921 "Specify community to reject\n"
13922 "Specify community to accept\n"
13923 COMMUNITY_VAL_STR)
13924{
d62a17ae 13925 char *cl_name_or_number = NULL;
13926 int direct = 0;
13927 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13928
d62a17ae 13929 int idx = 0;
7336e101
SP
13930
13931 if (argv_find(argv, argc, "ip", &idx)) {
13932 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13933 vty_out(vty, "if you are using this please migrate to the below command.\n");
13934 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13935 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13936 }
13937
d62a17ae 13938 argv_find(argv, argc, "(1-99)", &idx);
13939 argv_find(argv, argc, "WORD", &idx);
13940 cl_name_or_number = argv[idx]->arg;
13941 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13942 : COMMUNITY_DENY;
13943 argv_find(argv, argc, "AA:NN", &idx);
13944 char *str = argv_concat(argv, argc, idx);
42f914d4 13945
d62a17ae 13946 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13947 style);
42f914d4 13948
d62a17ae 13949 XFREE(MTYPE_TMP, str);
42f914d4 13950
d62a17ae 13951 if (ret < 0) {
13952 /* Display error string. */
13953 community_list_perror(vty, ret);
13954 return CMD_WARNING_CONFIG_FAILED;
13955 }
42f914d4 13956
d62a17ae 13957 return CMD_SUCCESS;
718e3744 13958}
13959
7336e101
SP
13960#if CONFDATE > 20191005
13961CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13962#endif
13963ALIAS (community_list_standard,
13964 ip_community_list_standard_cmd,
13965 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13966 IP_STR
13967 COMMUNITY_LIST_STR
13968 "Community list number (standard)\n"
5bf15956
DW
13969 "Add an standard community-list entry\n"
13970 "Community list name\n"
718e3744 13971 "Specify community to reject\n"
13972 "Specify community to accept\n"
13973 COMMUNITY_VAL_STR)
7336e101
SP
13974
13975DEFUN (no_community_list_standard_all,
13976 no_bgp_community_list_standard_all_cmd,
13977 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13978 NO_STR
13979 BGP_STR
13980 COMMUNITY_LIST_STR
13981 "Community list number (standard)\n"
13982 "Add an standard community-list entry\n"
13983 "Community list name\n"
13984 "Specify community to reject\n"
13985 "Specify community to accept\n"
13986 COMMUNITY_VAL_STR)
718e3744 13987{
d62a17ae 13988 char *cl_name_or_number = NULL;
174b5cb9 13989 char *str = NULL;
d62a17ae 13990 int direct = 0;
13991 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13992
d62a17ae 13993 int idx = 0;
7336e101
SP
13994
13995 if (argv_find(argv, argc, "ip", &idx)) {
13996 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
13997 vty_out(vty, "if you are using this please migrate to the below command.\n");
13998 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13999 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14000 }
14001
174b5cb9
DA
14002 argv_find(argv, argc, "permit", &idx);
14003 argv_find(argv, argc, "deny", &idx);
14004
14005 if (idx) {
14006 direct = argv_find(argv, argc, "permit", &idx)
14007 ? COMMUNITY_PERMIT
14008 : COMMUNITY_DENY;
14009
14010 idx = 0;
14011 argv_find(argv, argc, "AA:NN", &idx);
14012 str = argv_concat(argv, argc, idx);
14013 }
14014
14015 idx = 0;
d62a17ae 14016 argv_find(argv, argc, "(1-99)", &idx);
14017 argv_find(argv, argc, "WORD", &idx);
14018 cl_name_or_number = argv[idx]->arg;
42f914d4 14019
d62a17ae 14020 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14021 direct, style);
42f914d4 14022
d62a17ae 14023 XFREE(MTYPE_TMP, str);
daf9ddbb 14024
d62a17ae 14025 if (ret < 0) {
14026 community_list_perror(vty, ret);
14027 return CMD_WARNING_CONFIG_FAILED;
14028 }
42f914d4 14029
d62a17ae 14030 return CMD_SUCCESS;
718e3744 14031}
7336e101
SP
14032ALIAS (no_community_list_standard_all,
14033 no_ip_community_list_standard_all_cmd,
14034 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14035 NO_STR
718e3744 14036 IP_STR
14037 COMMUNITY_LIST_STR
7336e101
SP
14038 "Community list number (standard)\n"
14039 "Add an standard community-list entry\n"
14040 "Community list name\n"
14041 "Specify community to reject\n"
14042 "Specify community to accept\n"
14043 COMMUNITY_VAL_STR)
14044
174b5cb9
DA
14045ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14046 "no bgp community-list <(1-99)|standard WORD>",
14047 NO_STR BGP_STR COMMUNITY_LIST_STR
14048 "Community list number (standard)\n"
14049 "Add an standard community-list entry\n"
14050 "Community list name\n")
14051
14052ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14053 "no ip 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
7336e101
SP
14059/*community-list expanded */
14060DEFUN (community_list_expanded_all,
14061 bgp_community_list_expanded_all_cmd,
14062 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14063 BGP_STR
14064 COMMUNITY_LIST_STR
718e3744 14065 "Community list number (expanded)\n"
5bf15956 14066 "Add an expanded community-list entry\n"
718e3744 14067 "Community list name\n"
14068 "Specify community to reject\n"
14069 "Specify community to accept\n"
14070 COMMUNITY_VAL_STR)
14071{
d62a17ae 14072 char *cl_name_or_number = NULL;
14073 int direct = 0;
14074 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14075
d62a17ae 14076 int idx = 0;
7336e101
SP
14077 if (argv_find(argv, argc, "ip", &idx)) {
14078 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14079 vty_out(vty, "if you are using this please migrate to the below command.\n");
14080 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14081 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14082 }
d62a17ae 14083 argv_find(argv, argc, "(100-500)", &idx);
14084 argv_find(argv, argc, "WORD", &idx);
14085 cl_name_or_number = argv[idx]->arg;
14086 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14087 : COMMUNITY_DENY;
14088 argv_find(argv, argc, "AA:NN", &idx);
14089 char *str = argv_concat(argv, argc, idx);
42f914d4 14090
d62a17ae 14091 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14092 style);
42f914d4 14093
d62a17ae 14094 XFREE(MTYPE_TMP, str);
42f914d4 14095
d62a17ae 14096 if (ret < 0) {
14097 /* Display error string. */
14098 community_list_perror(vty, ret);
14099 return CMD_WARNING_CONFIG_FAILED;
14100 }
42f914d4 14101
d62a17ae 14102 return CMD_SUCCESS;
718e3744 14103}
14104
7336e101
SP
14105ALIAS (community_list_expanded_all,
14106 ip_community_list_expanded_all_cmd,
14107 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14108 IP_STR
14109 COMMUNITY_LIST_STR
5bf15956
DW
14110 "Community list number (expanded)\n"
14111 "Add an expanded community-list entry\n"
718e3744 14112 "Community list name\n"
14113 "Specify community to reject\n"
14114 "Specify community to accept\n"
5bf15956 14115 COMMUNITY_VAL_STR)
7336e101
SP
14116
14117DEFUN (no_community_list_expanded_all,
14118 no_bgp_community_list_expanded_all_cmd,
14119 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14120 NO_STR
14121 BGP_STR
14122 COMMUNITY_LIST_STR
14123 "Community list number (expanded)\n"
14124 "Add an expanded community-list entry\n"
14125 "Community list name\n"
14126 "Specify community to reject\n"
14127 "Specify community to accept\n"
14128 COMMUNITY_VAL_STR)
718e3744 14129{
d62a17ae 14130 char *cl_name_or_number = NULL;
174b5cb9 14131 char *str = NULL;
d62a17ae 14132 int direct = 0;
14133 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14134
d62a17ae 14135 int idx = 0;
7336e101
SP
14136 if (argv_find(argv, argc, "ip", &idx)) {
14137 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14138 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14139 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14140 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14141 }
14142
3c4b8fe2 14143 idx = 0;
174b5cb9
DA
14144 argv_find(argv, argc, "permit", &idx);
14145 argv_find(argv, argc, "deny", &idx);
14146
14147 if (idx) {
14148 direct = argv_find(argv, argc, "permit", &idx)
14149 ? COMMUNITY_PERMIT
14150 : COMMUNITY_DENY;
14151
14152 idx = 0;
14153 argv_find(argv, argc, "AA:NN", &idx);
14154 str = argv_concat(argv, argc, idx);
7336e101 14155 }
174b5cb9
DA
14156
14157 idx = 0;
d62a17ae 14158 argv_find(argv, argc, "(100-500)", &idx);
14159 argv_find(argv, argc, "WORD", &idx);
14160 cl_name_or_number = argv[idx]->arg;
42f914d4 14161
d62a17ae 14162 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14163 direct, style);
42f914d4 14164
d62a17ae 14165 XFREE(MTYPE_TMP, str);
daf9ddbb 14166
d62a17ae 14167 if (ret < 0) {
14168 community_list_perror(vty, ret);
14169 return CMD_WARNING_CONFIG_FAILED;
14170 }
42f914d4 14171
d62a17ae 14172 return CMD_SUCCESS;
718e3744 14173}
14174
7336e101
SP
14175ALIAS (no_community_list_expanded_all,
14176 no_ip_community_list_expanded_all_cmd,
14177 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14178 NO_STR
14179 IP_STR
14180 COMMUNITY_LIST_STR
14181 "Community list number (expanded)\n"
14182 "Add an expanded community-list entry\n"
14183 "Community list name\n"
14184 "Specify community to reject\n"
14185 "Specify community to accept\n"
14186 COMMUNITY_VAL_STR)
14187
174b5cb9
DA
14188ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14189 "no bgp community-list <(100-500)|expanded WORD>",
14190 NO_STR IP_STR COMMUNITY_LIST_STR
14191 "Community list number (expanded)\n"
14192 "Add an expanded community-list entry\n"
14193 "Community list name\n")
14194
14195ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14196 "no ip 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
8d9b8ed9
PM
14202/* Return configuration string of community-list entry. */
14203static const char *community_list_config_str(struct community_entry *entry)
14204{
14205 const char *str;
14206
14207 if (entry->any)
14208 str = "";
14209 else {
14210 if (entry->style == COMMUNITY_LIST_STANDARD)
14211 str = community_str(entry->u.com, false);
14212 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14213 str = lcommunity_str(entry->u.lcom, false);
14214 else
14215 str = entry->config;
14216 }
14217 return str;
14218}
14219
d62a17ae 14220static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14221{
d62a17ae 14222 struct community_entry *entry;
718e3744 14223
d62a17ae 14224 for (entry = list->head; entry; entry = entry->next) {
14225 if (entry == list->head) {
14226 if (all_digit(list->name))
14227 vty_out(vty, "Community %s list %s\n",
14228 entry->style == COMMUNITY_LIST_STANDARD
14229 ? "standard"
14230 : "(expanded) access",
14231 list->name);
14232 else
14233 vty_out(vty, "Named Community %s list %s\n",
14234 entry->style == COMMUNITY_LIST_STANDARD
14235 ? "standard"
14236 : "expanded",
14237 list->name);
14238 }
14239 if (entry->any)
14240 vty_out(vty, " %s\n",
14241 community_direct_str(entry->direct));
14242 else
14243 vty_out(vty, " %s %s\n",
14244 community_direct_str(entry->direct),
8d9b8ed9 14245 community_list_config_str(entry));
d62a17ae 14246 }
718e3744 14247}
14248
7336e101
SP
14249DEFUN (show_community_list,
14250 show_bgp_community_list_cmd,
14251 "show bgp community-list",
718e3744 14252 SHOW_STR
7336e101 14253 BGP_STR
718e3744 14254 "List community-list\n")
14255{
d62a17ae 14256 struct community_list *list;
14257 struct community_list_master *cm;
718e3744 14258
7336e101
SP
14259 int idx = 0;
14260 if (argv_find(argv, argc, "ip", &idx)) {
14261 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14262 vty_out(vty, "if you are using this please migrate to the below command.\n");
14263 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14264 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14265 }
d62a17ae 14266 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14267 if (!cm)
14268 return CMD_SUCCESS;
718e3744 14269
d62a17ae 14270 for (list = cm->num.head; list; list = list->next)
14271 community_list_show(vty, list);
718e3744 14272
d62a17ae 14273 for (list = cm->str.head; list; list = list->next)
14274 community_list_show(vty, list);
718e3744 14275
d62a17ae 14276 return CMD_SUCCESS;
718e3744 14277}
14278
7336e101
SP
14279ALIAS (show_community_list,
14280 show_ip_community_list_cmd,
14281 "show ip community-list",
718e3744 14282 SHOW_STR
14283 IP_STR
7336e101
SP
14284 "List community-list\n")
14285
14286DEFUN (show_community_list_arg,
14287 show_bgp_community_list_arg_cmd,
14288 "show bgp community-list <(1-500)|WORD>",
14289 SHOW_STR
14290 BGP_STR
718e3744 14291 "List community-list\n"
14292 "Community-list number\n"
14293 "Community-list name\n")
14294{
d62a17ae 14295 int idx_comm_list = 3;
14296 struct community_list *list;
718e3744 14297
7336e101
SP
14298 int idx = 0;
14299 if (argv_find(argv, argc, "ip", &idx)) {
14300 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14301 vty_out(vty, "if you are using this please migrate to the below command.\n");
14302 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14303 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14304 }
d62a17ae 14305 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14306 COMMUNITY_LIST_MASTER);
14307 if (!list) {
14308 vty_out(vty, "%% Can't find community-list\n");
14309 return CMD_WARNING;
14310 }
718e3744 14311
d62a17ae 14312 community_list_show(vty, list);
718e3744 14313
d62a17ae 14314 return CMD_SUCCESS;
718e3744 14315}
6b0655a2 14316
7336e101
SP
14317ALIAS (show_community_list_arg,
14318 show_ip_community_list_arg_cmd,
14319 "show ip community-list <(1-500)|WORD>",
14320 SHOW_STR
14321 IP_STR
14322 "List community-list\n"
14323 "Community-list number\n"
14324 "Community-list name\n")
14325
57d187bc
JS
14326/*
14327 * Large Community code.
14328 */
d62a17ae 14329static int lcommunity_list_set_vty(struct vty *vty, int argc,
14330 struct cmd_token **argv, int style,
14331 int reject_all_digit_name)
14332{
14333 int ret;
14334 int direct;
14335 char *str;
14336 int idx = 0;
14337 char *cl_name;
14338
7336e101
SP
14339 if (argv_find(argv, argc, "ip", &idx)) {
14340 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14341 vty_out(vty, "if you are using this please migrate to the below command.\n");
14342 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14343 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14344 }
d62a17ae 14345 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14346 : COMMUNITY_DENY;
14347
14348 /* All digit name check. */
14349 idx = 0;
14350 argv_find(argv, argc, "WORD", &idx);
14351 argv_find(argv, argc, "(1-99)", &idx);
14352 argv_find(argv, argc, "(100-500)", &idx);
14353 cl_name = argv[idx]->arg;
14354 if (reject_all_digit_name && all_digit(cl_name)) {
14355 vty_out(vty, "%% Community name cannot have all digits\n");
14356 return CMD_WARNING_CONFIG_FAILED;
14357 }
14358
14359 idx = 0;
14360 argv_find(argv, argc, "AA:BB:CC", &idx);
14361 argv_find(argv, argc, "LINE", &idx);
14362 /* Concat community string argument. */
14363 if (idx)
14364 str = argv_concat(argv, argc, idx);
14365 else
14366 str = NULL;
14367
14368 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14369
14370 /* Free temporary community list string allocated by
14371 argv_concat(). */
14372 if (str)
14373 XFREE(MTYPE_TMP, str);
14374
14375 if (ret < 0) {
14376 community_list_perror(vty, ret);
14377 return CMD_WARNING_CONFIG_FAILED;
14378 }
14379 return CMD_SUCCESS;
14380}
14381
14382static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14383 struct cmd_token **argv, int style)
14384{
14385 int ret;
14386 int direct = 0;
14387 char *str = NULL;
14388 int idx = 0;
14389
7336e101
SP
14390 if (argv_find(argv, argc, "ip", &idx)) {
14391 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14392 vty_out(vty, "if you are using this please migrate to the below command.\n");
14393 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14394 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14395 }
d62a17ae 14396 argv_find(argv, argc, "permit", &idx);
14397 argv_find(argv, argc, "deny", &idx);
14398
14399 if (idx) {
14400 /* Check the list direct. */
14401 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14402 direct = COMMUNITY_PERMIT;
14403 else
14404 direct = COMMUNITY_DENY;
14405
14406 idx = 0;
14407 argv_find(argv, argc, "LINE", &idx);
14408 argv_find(argv, argc, "AA:AA:NN", &idx);
14409 /* Concat community string argument. */
14410 str = argv_concat(argv, argc, idx);
14411 }
14412
14413 idx = 0;
14414 argv_find(argv, argc, "(1-99)", &idx);
14415 argv_find(argv, argc, "(100-500)", &idx);
14416 argv_find(argv, argc, "WORD", &idx);
14417
14418 /* Unset community list. */
14419 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14420 style);
14421
14422 /* Free temporary community list string allocated by
14423 argv_concat(). */
14424 if (str)
14425 XFREE(MTYPE_TMP, str);
14426
14427 if (ret < 0) {
14428 community_list_perror(vty, ret);
14429 return CMD_WARNING_CONFIG_FAILED;
14430 }
14431
14432 return CMD_SUCCESS;
57d187bc
JS
14433}
14434
14435/* "large-community-list" keyword help string. */
14436#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14437#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14438
7336e101
SP
14439#if CONFDATE > 20191005
14440CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14441#endif
14442DEFUN (lcommunity_list_standard,
14443 bgp_lcommunity_list_standard_cmd,
14444 "bgp large-community-list (1-99) <deny|permit>",
14445 BGP_STR
14446 LCOMMUNITY_LIST_STR
14447 "Large Community list number (standard)\n"
14448 "Specify large community to reject\n"
14449 "Specify large community to accept\n")
14450{
14451 return lcommunity_list_set_vty(vty, argc, argv,
14452 LARGE_COMMUNITY_LIST_STANDARD, 0);
14453}
14454
14455ALIAS (lcommunity_list_standard,
57d187bc 14456 ip_lcommunity_list_standard_cmd,
52951b63
DS
14457 "ip large-community-list (1-99) <deny|permit>",
14458 IP_STR
14459 LCOMMUNITY_LIST_STR
14460 "Large Community list number (standard)\n"
14461 "Specify large community to reject\n"
7111c1a0 14462 "Specify large community to accept\n")
7336e101
SP
14463
14464DEFUN (lcommunity_list_standard1,
14465 bgp_lcommunity_list_standard1_cmd,
14466 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14467 BGP_STR
14468 LCOMMUNITY_LIST_STR
14469 "Large Community list number (standard)\n"
14470 "Specify large community to reject\n"
14471 "Specify large community to accept\n"
14472 LCOMMUNITY_VAL_STR)
52951b63 14473{
d62a17ae 14474 return lcommunity_list_set_vty(vty, argc, argv,
14475 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14476}
14477
7336e101 14478ALIAS (lcommunity_list_standard1,
52951b63
DS
14479 ip_lcommunity_list_standard1_cmd,
14480 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14481 IP_STR
14482 LCOMMUNITY_LIST_STR
14483 "Large Community list number (standard)\n"
14484 "Specify large community to reject\n"
14485 "Specify large community to accept\n"
14486 LCOMMUNITY_VAL_STR)
7336e101
SP
14487
14488DEFUN (lcommunity_list_expanded,
14489 bgp_lcommunity_list_expanded_cmd,
14490 "bgp large-community-list (100-500) <deny|permit> LINE...",
14491 BGP_STR
14492 LCOMMUNITY_LIST_STR
14493 "Large Community list number (expanded)\n"
14494 "Specify large community to reject\n"
14495 "Specify large community to accept\n"
14496 "An ordered list as a regular-expression\n")
57d187bc 14497{
d62a17ae 14498 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14499 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14500}
14501
7336e101 14502ALIAS (lcommunity_list_expanded,
57d187bc
JS
14503 ip_lcommunity_list_expanded_cmd,
14504 "ip large-community-list (100-500) <deny|permit> LINE...",
14505 IP_STR
14506 LCOMMUNITY_LIST_STR
14507 "Large Community list number (expanded)\n"
14508 "Specify large community to reject\n"
14509 "Specify large community to accept\n"
14510 "An ordered list as a regular-expression\n")
7336e101
SP
14511
14512DEFUN (lcommunity_list_name_standard,
14513 bgp_lcommunity_list_name_standard_cmd,
14514 "bgp large-community-list standard WORD <deny|permit>",
14515 BGP_STR
14516 LCOMMUNITY_LIST_STR
14517 "Specify standard large-community-list\n"
14518 "Large Community list name\n"
14519 "Specify large community to reject\n"
14520 "Specify large community to accept\n")
57d187bc 14521{
d62a17ae 14522 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14523 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14524}
14525
7336e101 14526ALIAS (lcommunity_list_name_standard,
57d187bc 14527 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14528 "ip large-community-list standard WORD <deny|permit>",
14529 IP_STR
14530 LCOMMUNITY_LIST_STR
14531 "Specify standard large-community-list\n"
14532 "Large Community list name\n"
14533 "Specify large community to reject\n"
14534 "Specify large community to accept\n")
7336e101
SP
14535
14536DEFUN (lcommunity_list_name_standard1,
14537 bgp_lcommunity_list_name_standard1_cmd,
14538 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14539 BGP_STR
14540 LCOMMUNITY_LIST_STR
14541 "Specify standard large-community-list\n"
14542 "Large Community list name\n"
14543 "Specify large community to reject\n"
14544 "Specify large community to accept\n"
14545 LCOMMUNITY_VAL_STR)
52951b63 14546{
d62a17ae 14547 return lcommunity_list_set_vty(vty, argc, argv,
14548 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14549}
14550
7336e101 14551ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14552 ip_lcommunity_list_name_standard1_cmd,
14553 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14554 IP_STR
14555 LCOMMUNITY_LIST_STR
14556 "Specify standard large-community-list\n"
14557 "Large Community list name\n"
14558 "Specify large community to reject\n"
14559 "Specify large community to accept\n"
14560 LCOMMUNITY_VAL_STR)
7336e101
SP
14561
14562DEFUN (lcommunity_list_name_expanded,
14563 bgp_lcommunity_list_name_expanded_cmd,
14564 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14565 BGP_STR
14566 LCOMMUNITY_LIST_STR
14567 "Specify expanded large-community-list\n"
14568 "Large Community list name\n"
14569 "Specify large community to reject\n"
14570 "Specify large community to accept\n"
14571 "An ordered list as a regular-expression\n")
57d187bc 14572{
d62a17ae 14573 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14574 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14575}
14576
7336e101 14577ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14578 ip_lcommunity_list_name_expanded_cmd,
14579 "ip large-community-list expanded WORD <deny|permit> LINE...",
14580 IP_STR
14581 LCOMMUNITY_LIST_STR
14582 "Specify expanded large-community-list\n"
14583 "Large Community list name\n"
14584 "Specify large community to reject\n"
14585 "Specify large community to accept\n"
14586 "An ordered list as a regular-expression\n")
7336e101
SP
14587
14588DEFUN (no_lcommunity_list_standard_all,
14589 no_bgp_lcommunity_list_standard_all_cmd,
14590 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14591 NO_STR
14592 BGP_STR
14593 LCOMMUNITY_LIST_STR
14594 "Large Community list number (standard)\n"
14595 "Large Community list number (expanded)\n"
14596 "Large Community list name\n")
57d187bc 14597{
7336e101
SP
14598 return lcommunity_list_unset_vty(vty, argc, argv,
14599 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14600}
14601
7336e101 14602ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14603 no_ip_lcommunity_list_standard_all_cmd,
14604 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14605 NO_STR
14606 IP_STR
14607 LCOMMUNITY_LIST_STR
14608 "Large Community list number (standard)\n"
14609 "Large Community list number (expanded)\n"
14610 "Large Community list name\n")
7336e101
SP
14611
14612DEFUN (no_lcommunity_list_name_expanded_all,
14613 no_bgp_lcommunity_list_name_expanded_all_cmd,
14614 "no bgp large-community-list expanded WORD",
14615 NO_STR
14616 BGP_STR
14617 LCOMMUNITY_LIST_STR
14618 "Specify expanded large-community-list\n"
14619 "Large Community list name\n")
57d187bc 14620{
d62a17ae 14621 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14622 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14623}
14624
7336e101 14625ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14626 no_ip_lcommunity_list_name_expanded_all_cmd,
14627 "no ip large-community-list expanded WORD",
14628 NO_STR
14629 IP_STR
14630 LCOMMUNITY_LIST_STR
14631 "Specify expanded large-community-list\n"
14632 "Large Community list name\n")
7336e101
SP
14633
14634DEFUN (no_lcommunity_list_standard,
14635 no_bgp_lcommunity_list_standard_cmd,
14636 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14637 NO_STR
14638 BGP_STR
14639 LCOMMUNITY_LIST_STR
14640 "Large Community list number (standard)\n"
14641 "Specify large community to reject\n"
14642 "Specify large community to accept\n"
14643 LCOMMUNITY_VAL_STR)
57d187bc 14644{
d62a17ae 14645 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14646 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14647}
14648
7336e101 14649ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14650 no_ip_lcommunity_list_standard_cmd,
14651 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14652 NO_STR
14653 IP_STR
14654 LCOMMUNITY_LIST_STR
14655 "Large Community list number (standard)\n"
14656 "Specify large community to reject\n"
14657 "Specify large community to accept\n"
14658 LCOMMUNITY_VAL_STR)
7336e101
SP
14659
14660DEFUN (no_lcommunity_list_expanded,
14661 no_bgp_lcommunity_list_expanded_cmd,
14662 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14663 NO_STR
14664 BGP_STR
14665 LCOMMUNITY_LIST_STR
14666 "Large Community list number (expanded)\n"
14667 "Specify large community to reject\n"
14668 "Specify large community to accept\n"
14669 "An ordered list as a regular-expression\n")
57d187bc 14670{
d62a17ae 14671 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14672 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14673}
14674
7336e101 14675ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14676 no_ip_lcommunity_list_expanded_cmd,
14677 "no ip large-community-list (100-500) <deny|permit> LINE...",
14678 NO_STR
14679 IP_STR
14680 LCOMMUNITY_LIST_STR
14681 "Large Community list number (expanded)\n"
14682 "Specify large community to reject\n"
14683 "Specify large community to accept\n"
14684 "An ordered list as a regular-expression\n")
7336e101
SP
14685
14686DEFUN (no_lcommunity_list_name_standard,
14687 no_bgp_lcommunity_list_name_standard_cmd,
14688 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14689 NO_STR
14690 BGP_STR
14691 LCOMMUNITY_LIST_STR
14692 "Specify standard large-community-list\n"
14693 "Large Community list name\n"
14694 "Specify large community to reject\n"
14695 "Specify large community to accept\n"
14696 LCOMMUNITY_VAL_STR)
57d187bc 14697{
d62a17ae 14698 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14699 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14700}
14701
7336e101 14702ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14703 no_ip_lcommunity_list_name_standard_cmd,
14704 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14705 NO_STR
14706 IP_STR
14707 LCOMMUNITY_LIST_STR
14708 "Specify standard large-community-list\n"
14709 "Large Community list name\n"
14710 "Specify large community to reject\n"
14711 "Specify large community to accept\n"
14712 LCOMMUNITY_VAL_STR)
7336e101
SP
14713
14714DEFUN (no_lcommunity_list_name_expanded,
14715 no_bgp_lcommunity_list_name_expanded_cmd,
14716 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14717 NO_STR
14718 BGP_STR
14719 LCOMMUNITY_LIST_STR
14720 "Specify expanded large-community-list\n"
14721 "Large community list name\n"
14722 "Specify large community to reject\n"
14723 "Specify large community to accept\n"
14724 "An ordered list as a regular-expression\n")
57d187bc 14725{
d62a17ae 14726 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14727 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14728}
14729
7336e101 14730ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14731 no_ip_lcommunity_list_name_expanded_cmd,
14732 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14733 NO_STR
14734 IP_STR
14735 LCOMMUNITY_LIST_STR
14736 "Specify expanded large-community-list\n"
14737 "Large community list name\n"
14738 "Specify large community to reject\n"
14739 "Specify large community to accept\n"
14740 "An ordered list as a regular-expression\n")
d62a17ae 14741
14742static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14743{
14744 struct community_entry *entry;
14745
14746 for (entry = list->head; entry; entry = entry->next) {
14747 if (entry == list->head) {
14748 if (all_digit(list->name))
14749 vty_out(vty, "Large community %s list %s\n",
14750 entry->style == EXTCOMMUNITY_LIST_STANDARD
14751 ? "standard"
14752 : "(expanded) access",
14753 list->name);
14754 else
14755 vty_out(vty,
14756 "Named large community %s list %s\n",
14757 entry->style == EXTCOMMUNITY_LIST_STANDARD
14758 ? "standard"
14759 : "expanded",
14760 list->name);
14761 }
14762 if (entry->any)
14763 vty_out(vty, " %s\n",
14764 community_direct_str(entry->direct));
14765 else
14766 vty_out(vty, " %s %s\n",
14767 community_direct_str(entry->direct),
8d9b8ed9 14768 community_list_config_str(entry));
d62a17ae 14769 }
57d187bc
JS
14770}
14771
7336e101
SP
14772DEFUN (show_lcommunity_list,
14773 show_bgp_lcommunity_list_cmd,
14774 "show bgp large-community-list",
57d187bc 14775 SHOW_STR
7336e101 14776 BGP_STR
57d187bc
JS
14777 "List large-community list\n")
14778{
d62a17ae 14779 struct community_list *list;
14780 struct community_list_master *cm;
7336e101
SP
14781 int idx = 0;
14782
14783 if (argv_find(argv, argc, "ip", &idx)) {
14784 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14785 vty_out(vty, "if you are using this please migrate to the below command.\n");
14786 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14787 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14788 }
57d187bc 14789
d62a17ae 14790 cm = community_list_master_lookup(bgp_clist,
14791 LARGE_COMMUNITY_LIST_MASTER);
14792 if (!cm)
14793 return CMD_SUCCESS;
57d187bc 14794
d62a17ae 14795 for (list = cm->num.head; list; list = list->next)
14796 lcommunity_list_show(vty, list);
57d187bc 14797
d62a17ae 14798 for (list = cm->str.head; list; list = list->next)
14799 lcommunity_list_show(vty, list);
57d187bc 14800
d62a17ae 14801 return CMD_SUCCESS;
57d187bc
JS
14802}
14803
7336e101
SP
14804ALIAS (show_lcommunity_list,
14805 show_ip_lcommunity_list_cmd,
14806 "show ip large-community-list",
57d187bc
JS
14807 SHOW_STR
14808 IP_STR
7336e101
SP
14809 "List large-community list\n")
14810
14811DEFUN (show_lcommunity_list_arg,
14812 show_bgp_lcommunity_list_arg_cmd,
14813 "show bgp large-community-list <(1-500)|WORD>",
14814 SHOW_STR
14815 BGP_STR
57d187bc
JS
14816 "List large-community list\n"
14817 "large-community-list number\n"
14818 "large-community-list name\n")
14819{
d62a17ae 14820 struct community_list *list;
7336e101
SP
14821 int idx = 0;
14822
14823 if (argv_find(argv, argc, "ip", &idx)) {
14824 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14825 vty_out(vty, "if you are using this please migrate to the below command.\n");
14826 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14827 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14828 }
57d187bc 14829
d62a17ae 14830 list = community_list_lookup(bgp_clist, argv[3]->arg,
14831 LARGE_COMMUNITY_LIST_MASTER);
14832 if (!list) {
14833 vty_out(vty, "%% Can't find extcommunity-list\n");
14834 return CMD_WARNING;
14835 }
57d187bc 14836
d62a17ae 14837 lcommunity_list_show(vty, list);
57d187bc 14838
d62a17ae 14839 return CMD_SUCCESS;
57d187bc
JS
14840}
14841
7336e101
SP
14842ALIAS (show_lcommunity_list_arg,
14843 show_ip_lcommunity_list_arg_cmd,
14844 "show ip large-community-list <(1-500)|WORD>",
14845 SHOW_STR
14846 IP_STR
14847 "List large-community list\n"
14848 "large-community-list number\n"
14849 "large-community-list name\n")
14850
718e3744 14851/* "extcommunity-list" keyword help string. */
14852#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14853#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14854
7336e101
SP
14855DEFUN (extcommunity_list_standard,
14856 bgp_extcommunity_list_standard_cmd,
14857 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14858 BGP_STR
718e3744 14859 EXTCOMMUNITY_LIST_STR
14860 "Extended Community list number (standard)\n"
718e3744 14861 "Specify standard extcommunity-list\n"
5bf15956 14862 "Community list name\n"
718e3744 14863 "Specify community to reject\n"
14864 "Specify community to accept\n"
14865 EXTCOMMUNITY_VAL_STR)
14866{
d62a17ae 14867 int style = EXTCOMMUNITY_LIST_STANDARD;
14868 int direct = 0;
14869 char *cl_number_or_name = NULL;
42f914d4 14870
d62a17ae 14871 int idx = 0;
7336e101
SP
14872 if (argv_find(argv, argc, "ip", &idx)) {
14873 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14874 vty_out(vty, "if you are using this please migrate to the below command.\n");
14875 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14876 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14877 }
d62a17ae 14878 argv_find(argv, argc, "(1-99)", &idx);
14879 argv_find(argv, argc, "WORD", &idx);
14880 cl_number_or_name = argv[idx]->arg;
14881 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14882 : COMMUNITY_DENY;
14883 argv_find(argv, argc, "AA:NN", &idx);
14884 char *str = argv_concat(argv, argc, idx);
42f914d4 14885
d62a17ae 14886 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14887 direct, style);
42f914d4 14888
d62a17ae 14889 XFREE(MTYPE_TMP, str);
42f914d4 14890
d62a17ae 14891 if (ret < 0) {
14892 community_list_perror(vty, ret);
14893 return CMD_WARNING_CONFIG_FAILED;
14894 }
42f914d4 14895
d62a17ae 14896 return CMD_SUCCESS;
718e3744 14897}
14898
7336e101
SP
14899#if CONFDATE > 20191005
14900CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14901#endif
14902ALIAS (extcommunity_list_standard,
14903 ip_extcommunity_list_standard_cmd,
14904 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14905 IP_STR
14906 EXTCOMMUNITY_LIST_STR
7336e101
SP
14907 "Extended Community list number (standard)\n"
14908 "Specify standard extcommunity-list\n"
14909 "Community list name\n"
14910 "Specify community to reject\n"
14911 "Specify community to accept\n"
14912 EXTCOMMUNITY_VAL_STR)
14913
14914DEFUN (extcommunity_list_name_expanded,
14915 bgp_extcommunity_list_name_expanded_cmd,
14916 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14917 BGP_STR
14918 EXTCOMMUNITY_LIST_STR
5bf15956 14919 "Extended Community list number (expanded)\n"
718e3744 14920 "Specify expanded extcommunity-list\n"
14921 "Extended Community list name\n"
14922 "Specify community to reject\n"
14923 "Specify community to accept\n"
14924 "An ordered list as a regular-expression\n")
14925{
d62a17ae 14926 int style = EXTCOMMUNITY_LIST_EXPANDED;
14927 int direct = 0;
14928 char *cl_number_or_name = NULL;
42f914d4 14929
d62a17ae 14930 int idx = 0;
7336e101
SP
14931 if (argv_find(argv, argc, "ip", &idx)) {
14932 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14933 vty_out(vty, "if you are using this please migrate to the below command.\n");
14934 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14935 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14936 }
14937
d62a17ae 14938 argv_find(argv, argc, "(100-500)", &idx);
14939 argv_find(argv, argc, "WORD", &idx);
14940 cl_number_or_name = argv[idx]->arg;
14941 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14942 : COMMUNITY_DENY;
14943 argv_find(argv, argc, "LINE", &idx);
14944 char *str = argv_concat(argv, argc, idx);
42f914d4 14945
d62a17ae 14946 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14947 direct, style);
42f914d4 14948
d62a17ae 14949 XFREE(MTYPE_TMP, str);
42f914d4 14950
d62a17ae 14951 if (ret < 0) {
14952 community_list_perror(vty, ret);
14953 return CMD_WARNING_CONFIG_FAILED;
14954 }
42f914d4 14955
d62a17ae 14956 return CMD_SUCCESS;
718e3744 14957}
14958
7336e101
SP
14959ALIAS (extcommunity_list_name_expanded,
14960 ip_extcommunity_list_name_expanded_cmd,
14961 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
14962 IP_STR
14963 EXTCOMMUNITY_LIST_STR
7336e101
SP
14964 "Extended Community list number (expanded)\n"
14965 "Specify expanded extcommunity-list\n"
14966 "Extended Community list name\n"
14967 "Specify community to reject\n"
14968 "Specify community to accept\n"
14969 "An ordered list as a regular-expression\n")
14970
14971DEFUN (no_extcommunity_list_standard_all,
14972 no_bgp_extcommunity_list_standard_all_cmd,
14973 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14974 NO_STR
14975 BGP_STR
14976 EXTCOMMUNITY_LIST_STR
813d4307 14977 "Extended Community list number (standard)\n"
718e3744 14978 "Specify standard extcommunity-list\n"
5bf15956 14979 "Community list name\n"
718e3744 14980 "Specify community to reject\n"
14981 "Specify community to accept\n"
14982 EXTCOMMUNITY_VAL_STR)
14983{
d62a17ae 14984 int style = EXTCOMMUNITY_LIST_STANDARD;
14985 int direct = 0;
14986 char *cl_number_or_name = NULL;
42f914d4 14987
d62a17ae 14988 int idx = 0;
7336e101
SP
14989 if (argv_find(argv, argc, "ip", &idx)) {
14990 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14991 vty_out(vty, "if you are using this please migrate to the below command.\n");
14992 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14993 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14994 }
d62a17ae 14995 argv_find(argv, argc, "(1-99)", &idx);
14996 argv_find(argv, argc, "WORD", &idx);
14997 cl_number_or_name = argv[idx]->arg;
14998 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14999 : COMMUNITY_DENY;
15000 argv_find(argv, argc, "AA:NN", &idx);
15001 char *str = argv_concat(argv, argc, idx);
42f914d4 15002
d62a17ae 15003 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15004 direct, style);
42f914d4 15005
d62a17ae 15006 XFREE(MTYPE_TMP, str);
42f914d4 15007
d62a17ae 15008 if (ret < 0) {
15009 community_list_perror(vty, ret);
15010 return CMD_WARNING_CONFIG_FAILED;
15011 }
42f914d4 15012
d62a17ae 15013 return CMD_SUCCESS;
718e3744 15014}
15015
7336e101
SP
15016ALIAS (no_extcommunity_list_standard_all,
15017 no_ip_extcommunity_list_standard_all_cmd,
15018 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15019 NO_STR
15020 IP_STR
15021 EXTCOMMUNITY_LIST_STR
7336e101
SP
15022 "Extended Community list number (standard)\n"
15023 "Specify standard extcommunity-list\n"
15024 "Community list name\n"
15025 "Specify community to reject\n"
15026 "Specify community to accept\n"
15027 EXTCOMMUNITY_VAL_STR)
15028
15029DEFUN (no_extcommunity_list_expanded_all,
15030 no_bgp_extcommunity_list_expanded_all_cmd,
15031 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15032 NO_STR
15033 BGP_STR
15034 EXTCOMMUNITY_LIST_STR
718e3744 15035 "Extended Community list number (expanded)\n"
718e3744 15036 "Specify expanded extcommunity-list\n"
5bf15956 15037 "Extended Community list name\n"
718e3744 15038 "Specify community to reject\n"
15039 "Specify community to accept\n"
15040 "An ordered list as a regular-expression\n")
15041{
d62a17ae 15042 int style = EXTCOMMUNITY_LIST_EXPANDED;
15043 int direct = 0;
15044 char *cl_number_or_name = NULL;
42f914d4 15045
d62a17ae 15046 int idx = 0;
7336e101
SP
15047 if (argv_find(argv, argc, "ip", &idx)) {
15048 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15049 vty_out(vty, "if you are using this please migrate to the below command.\n");
15050 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15051 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15052 }
d62a17ae 15053 argv_find(argv, argc, "(100-500)", &idx);
15054 argv_find(argv, argc, "WORD", &idx);
15055 cl_number_or_name = argv[idx]->arg;
15056 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15057 : COMMUNITY_DENY;
15058 argv_find(argv, argc, "LINE", &idx);
15059 char *str = argv_concat(argv, argc, idx);
42f914d4 15060
d62a17ae 15061 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15062 direct, style);
42f914d4 15063
d62a17ae 15064 XFREE(MTYPE_TMP, str);
42f914d4 15065
d62a17ae 15066 if (ret < 0) {
15067 community_list_perror(vty, ret);
15068 return CMD_WARNING_CONFIG_FAILED;
15069 }
42f914d4 15070
d62a17ae 15071 return CMD_SUCCESS;
718e3744 15072}
15073
7336e101
SP
15074ALIAS (no_extcommunity_list_expanded_all,
15075 no_ip_extcommunity_list_expanded_all_cmd,
15076 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15077 NO_STR
15078 IP_STR
15079 EXTCOMMUNITY_LIST_STR
15080 "Extended Community list number (expanded)\n"
15081 "Specify expanded extcommunity-list\n"
15082 "Extended Community list name\n"
15083 "Specify community to reject\n"
15084 "Specify community to accept\n"
15085 "An ordered list as a regular-expression\n")
15086
d62a17ae 15087static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15088{
d62a17ae 15089 struct community_entry *entry;
718e3744 15090
d62a17ae 15091 for (entry = list->head; entry; entry = entry->next) {
15092 if (entry == list->head) {
15093 if (all_digit(list->name))
15094 vty_out(vty, "Extended community %s list %s\n",
15095 entry->style == EXTCOMMUNITY_LIST_STANDARD
15096 ? "standard"
15097 : "(expanded) access",
15098 list->name);
15099 else
15100 vty_out(vty,
15101 "Named extended community %s list %s\n",
15102 entry->style == EXTCOMMUNITY_LIST_STANDARD
15103 ? "standard"
15104 : "expanded",
15105 list->name);
15106 }
15107 if (entry->any)
15108 vty_out(vty, " %s\n",
15109 community_direct_str(entry->direct));
15110 else
15111 vty_out(vty, " %s %s\n",
15112 community_direct_str(entry->direct),
8d9b8ed9 15113 community_list_config_str(entry));
d62a17ae 15114 }
718e3744 15115}
15116
7336e101
SP
15117DEFUN (show_extcommunity_list,
15118 show_bgp_extcommunity_list_cmd,
15119 "show bgp extcommunity-list",
718e3744 15120 SHOW_STR
7336e101 15121 BGP_STR
718e3744 15122 "List extended-community list\n")
15123{
d62a17ae 15124 struct community_list *list;
15125 struct community_list_master *cm;
7336e101 15126 int idx = 0;
718e3744 15127
7336e101
SP
15128 if (argv_find(argv, argc, "ip", &idx)) {
15129 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15130 vty_out(vty, "if you are using this please migrate to the below command.\n");
15131 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15132 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15133 }
d62a17ae 15134 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15135 if (!cm)
15136 return CMD_SUCCESS;
718e3744 15137
d62a17ae 15138 for (list = cm->num.head; list; list = list->next)
15139 extcommunity_list_show(vty, list);
718e3744 15140
d62a17ae 15141 for (list = cm->str.head; list; list = list->next)
15142 extcommunity_list_show(vty, list);
718e3744 15143
d62a17ae 15144 return CMD_SUCCESS;
718e3744 15145}
15146
7336e101
SP
15147ALIAS (show_extcommunity_list,
15148 show_ip_extcommunity_list_cmd,
15149 "show ip extcommunity-list",
718e3744 15150 SHOW_STR
15151 IP_STR
7336e101
SP
15152 "List extended-community list\n")
15153
15154DEFUN (show_extcommunity_list_arg,
15155 show_bgp_extcommunity_list_arg_cmd,
15156 "show bgp extcommunity-list <(1-500)|WORD>",
15157 SHOW_STR
15158 BGP_STR
718e3744 15159 "List extended-community list\n"
15160 "Extcommunity-list number\n"
15161 "Extcommunity-list name\n")
15162{
d62a17ae 15163 int idx_comm_list = 3;
15164 struct community_list *list;
7336e101 15165 int idx = 0;
718e3744 15166
7336e101
SP
15167 if (argv_find(argv, argc, "ip", &idx)) {
15168 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15169 vty_out(vty, "if you are using this please migrate to the below command.\n");
15170 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15171 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15172 }
d62a17ae 15173 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15174 EXTCOMMUNITY_LIST_MASTER);
15175 if (!list) {
15176 vty_out(vty, "%% Can't find extcommunity-list\n");
15177 return CMD_WARNING;
15178 }
718e3744 15179
d62a17ae 15180 extcommunity_list_show(vty, list);
718e3744 15181
d62a17ae 15182 return CMD_SUCCESS;
718e3744 15183}
6b0655a2 15184
7336e101
SP
15185ALIAS (show_extcommunity_list_arg,
15186 show_ip_extcommunity_list_arg_cmd,
15187 "show ip extcommunity-list <(1-500)|WORD>",
15188 SHOW_STR
15189 IP_STR
15190 "List extended-community list\n"
15191 "Extcommunity-list number\n"
15192 "Extcommunity-list name\n")
15193
718e3744 15194/* Display community-list and extcommunity-list configuration. */
d62a17ae 15195static int community_list_config_write(struct vty *vty)
15196{
15197 struct community_list *list;
15198 struct community_entry *entry;
15199 struct community_list_master *cm;
15200 int write = 0;
15201
15202 /* Community-list. */
15203 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15204
15205 for (list = cm->num.head; list; list = list->next)
15206 for (entry = list->head; entry; entry = entry->next) {
7336e101 15207 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15208 community_direct_str(entry->direct),
15209 community_list_config_str(entry));
15210 write++;
15211 }
15212 for (list = cm->str.head; list; list = list->next)
15213 for (entry = list->head; entry; entry = entry->next) {
7336e101 15214 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15215 entry->style == COMMUNITY_LIST_STANDARD
15216 ? "standard"
15217 : "expanded",
15218 list->name, community_direct_str(entry->direct),
15219 community_list_config_str(entry));
15220 write++;
15221 }
15222
15223 /* Extcommunity-list. */
15224 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15225
15226 for (list = cm->num.head; list; list = list->next)
15227 for (entry = list->head; entry; entry = entry->next) {
7336e101 15228 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15229 list->name, community_direct_str(entry->direct),
15230 community_list_config_str(entry));
15231 write++;
15232 }
15233 for (list = cm->str.head; list; list = list->next)
15234 for (entry = list->head; entry; entry = entry->next) {
7336e101 15235 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15236 entry->style == EXTCOMMUNITY_LIST_STANDARD
15237 ? "standard"
15238 : "expanded",
15239 list->name, community_direct_str(entry->direct),
15240 community_list_config_str(entry));
15241 write++;
15242 }
15243
15244
15245 /* lcommunity-list. */
15246 cm = community_list_master_lookup(bgp_clist,
15247 LARGE_COMMUNITY_LIST_MASTER);
15248
15249 for (list = cm->num.head; list; list = list->next)
15250 for (entry = list->head; entry; entry = entry->next) {
7336e101 15251 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15252 list->name, community_direct_str(entry->direct),
15253 community_list_config_str(entry));
15254 write++;
15255 }
15256 for (list = cm->str.head; list; list = list->next)
15257 for (entry = list->head; entry; entry = entry->next) {
7336e101 15258 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15259 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15260 ? "standard"
15261 : "expanded",
15262 list->name, community_direct_str(entry->direct),
15263 community_list_config_str(entry));
15264 write++;
15265 }
15266
15267 return write;
15268}
15269
15270static struct cmd_node community_list_node = {
15271 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15272};
15273
d62a17ae 15274static void community_list_vty(void)
15275{
15276 install_node(&community_list_node, community_list_config_write);
15277
15278 /* Community-list. */
7336e101
SP
15279 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15280 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15281 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15282 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15283 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15284 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15285 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15286 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15287 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15288 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15289 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15290 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15291 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15292 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15293 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15294 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15295
15296 /* Extcommunity-list. */
7336e101
SP
15297 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15298 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15299 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15300 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15301 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15302 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15303 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15304 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15305 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15306 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15307 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15308 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15309
15310 /* Large Community List */
7336e101
SP
15311 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15312 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15313 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15314 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15315 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15316 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15317 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15318 install_element(CONFIG_NODE,
15319 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15320 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15321 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15322 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15323 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15324 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15325 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15326 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15327 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15328 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15329 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15330 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15331 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15332 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15333 install_element(CONFIG_NODE,
15334 &no_ip_lcommunity_list_name_expanded_all_cmd);
15335 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15336 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15337 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15338 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15339 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15340 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15341}