]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #3909 from AnuradhaKaruppiah/l3-vni-0
[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"
ec0ab544 25#include "lib/zclient.h"
718e3744 26#include "prefix.h"
27#include "plist.h"
28#include "buffer.h"
29#include "linklist.h"
30#include "stream.h"
31#include "thread.h"
32#include "log.h"
3b8b1855 33#include "memory.h"
fc7948fa 34#include "memory_vty.h"
4bf6a362 35#include "hash.h"
3f9c7369 36#include "queue.h"
039f3a34 37#include "filter.h"
5d5ba018 38#include "frrstr.h"
718e3744 39
40#include "bgpd/bgpd.h"
48ecf8f5 41#include "bgpd/bgp_attr_evpn.h"
4bf6a362 42#include "bgpd/bgp_advertise.h"
718e3744 43#include "bgpd/bgp_attr.h"
44#include "bgpd/bgp_aspath.h"
45#include "bgpd/bgp_community.h"
4bf6a362 46#include "bgpd/bgp_ecommunity.h"
57d187bc 47#include "bgpd/bgp_lcommunity.h"
4bf6a362 48#include "bgpd/bgp_damp.h"
718e3744 49#include "bgpd/bgp_debug.h"
14454c9f 50#include "bgpd/bgp_errors.h"
e0701b79 51#include "bgpd/bgp_fsm.h"
4bf6a362 52#include "bgpd/bgp_nexthop.h"
718e3744 53#include "bgpd/bgp_open.h"
4bf6a362 54#include "bgpd/bgp_regex.h"
718e3744 55#include "bgpd/bgp_route.h"
c016b6c7 56#include "bgpd/bgp_mplsvpn.h"
718e3744 57#include "bgpd/bgp_zebra.h"
fee0f4c6 58#include "bgpd/bgp_table.h"
94f2b392 59#include "bgpd/bgp_vty.h"
165b5fff 60#include "bgpd/bgp_mpath.h"
cb1faec9 61#include "bgpd/bgp_packet.h"
3f9c7369 62#include "bgpd/bgp_updgrp.h"
c43ed2e4 63#include "bgpd/bgp_bfd.h"
555e09d4 64#include "bgpd/bgp_io.h"
94c2f693 65#include "bgpd/bgp_evpn.h"
dcc68b5e 66#include "bgpd/bgp_addpath.h"
48ecf8f5 67#include "bgpd/bgp_mac.h"
718e3744 68
d62a17ae 69static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73{
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
7c40bf39 89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
5c525538
RW
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
d62a17ae 95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
7c40bf39 111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
5c525538
RW
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
d62a17ae 117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_MAX:
123 // We should never be here but to clarify the switch statement..
124 return BGP_IPV4_NODE;
125 break;
126 }
127
128 // Impossible to happen
129 return BGP_IPV4_NODE;
f51bae9c 130}
20eb8864 131
718e3744 132/* Utility function to get address family from current node. */
d62a17ae 133afi_t bgp_node_afi(struct vty *vty)
134{
135 afi_t afi;
136 switch (vty->node) {
137 case BGP_IPV6_NODE:
138 case BGP_IPV6M_NODE:
139 case BGP_IPV6L_NODE:
140 case BGP_VPNV6_NODE:
7c40bf39 141 case BGP_FLOWSPECV6_NODE:
d62a17ae 142 afi = AFI_IP6;
143 break;
144 case BGP_EVPN_NODE:
145 afi = AFI_L2VPN;
146 break;
147 default:
148 afi = AFI_IP;
149 break;
150 }
151 return afi;
718e3744 152}
153
154/* Utility function to get subsequent address family from current
155 node. */
d62a17ae 156safi_t bgp_node_safi(struct vty *vty)
157{
158 safi_t safi;
159 switch (vty->node) {
160 case BGP_VPNV4_NODE:
161 case BGP_VPNV6_NODE:
162 safi = SAFI_MPLS_VPN;
163 break;
164 case BGP_IPV4M_NODE:
165 case BGP_IPV6M_NODE:
166 safi = SAFI_MULTICAST;
167 break;
168 case BGP_EVPN_NODE:
169 safi = SAFI_EVPN;
170 break;
171 case BGP_IPV4L_NODE:
172 case BGP_IPV6L_NODE:
173 safi = SAFI_LABELED_UNICAST;
174 break;
7c40bf39 175 case BGP_FLOWSPECV4_NODE:
176 case BGP_FLOWSPECV6_NODE:
177 safi = SAFI_FLOWSPEC;
178 break;
d62a17ae 179 default:
180 safi = SAFI_UNICAST;
181 break;
182 }
183 return safi;
718e3744 184}
185
55f91488
QY
186/**
187 * Converts an AFI in string form to afi_t
188 *
189 * @param afi string, one of
190 * - "ipv4"
191 * - "ipv6"
81cf0de5 192 * - "l2vpn"
55f91488
QY
193 * @return the corresponding afi_t
194 */
d62a17ae 195afi_t bgp_vty_afi_from_str(const char *afi_str)
196{
197 afi_t afi = AFI_MAX; /* unknown */
198 if (strmatch(afi_str, "ipv4"))
199 afi = AFI_IP;
200 else if (strmatch(afi_str, "ipv6"))
201 afi = AFI_IP6;
81cf0de5
CS
202 else if (strmatch(afi_str, "l2vpn"))
203 afi = AFI_L2VPN;
d62a17ae 204 return afi;
205}
206
207int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
208 afi_t *afi)
209{
210 int ret = 0;
211 if (argv_find(argv, argc, "ipv4", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP;
215 } else if (argv_find(argv, argc, "ipv6", index)) {
216 ret = 1;
217 if (afi)
218 *afi = AFI_IP6;
219 }
220 return ret;
46f296b4
LB
221}
222
375a2e67 223/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 224safi_t bgp_vty_safi_from_str(const char *safi_str)
225{
226 safi_t safi = SAFI_MAX; /* unknown */
227 if (strmatch(safi_str, "multicast"))
228 safi = SAFI_MULTICAST;
229 else if (strmatch(safi_str, "unicast"))
230 safi = SAFI_UNICAST;
231 else if (strmatch(safi_str, "vpn"))
232 safi = SAFI_MPLS_VPN;
81cf0de5
CS
233 else if (strmatch(safi_str, "evpn"))
234 safi = SAFI_EVPN;
d62a17ae 235 else if (strmatch(safi_str, "labeled-unicast"))
236 safi = SAFI_LABELED_UNICAST;
7c40bf39 237 else if (strmatch(safi_str, "flowspec"))
238 safi = SAFI_FLOWSPEC;
d62a17ae 239 return safi;
240}
241
242int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
243 safi_t *safi)
244{
245 int ret = 0;
246 if (argv_find(argv, argc, "unicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_UNICAST;
250 } else if (argv_find(argv, argc, "multicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_MULTICAST;
254 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_LABELED_UNICAST;
258 } else if (argv_find(argv, argc, "vpn", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_MPLS_VPN;
7c40bf39 262 } else if (argv_find(argv, argc, "flowspec", index)) {
263 ret = 1;
264 if (safi)
265 *safi = SAFI_FLOWSPEC;
d62a17ae 266 }
267 return ret;
46f296b4
LB
268}
269
7eeee51e 270/*
f212a857 271 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 272 *
f212a857
DS
273 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
274 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
275 * to appropriate values for the calling function. This is to allow the
276 * calling function to make decisions appropriate for the show command
277 * that is being parsed.
278 *
279 * The show commands are generally of the form:
d62a17ae 280 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
281 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
282 *
283 * Since we use argv_find if the show command in particular doesn't have:
284 * [ip]
18c57037 285 * [<view|vrf> VIEWVRFNAME]
375a2e67 286 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
287 * The command parsing should still be ok.
288 *
289 * vty -> The vty for the command so we can output some useful data in
290 * the event of a parse error in the vrf.
291 * argv -> The command tokens
292 * argc -> How many command tokens we have
d62a17ae 293 * idx -> The current place in the command, generally should be 0 for this
294 * function
7eeee51e
DS
295 * afi -> The parsed afi if it was included in the show command, returned here
296 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 297 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
298 *
299 * The function returns the correct location in the parse tree for the
300 * last token found.
0e37c258
DS
301 *
302 * Returns 0 for failure to parse correctly, else the idx position of where
303 * it found the last token.
7eeee51e 304 */
d62a17ae 305int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
306 struct cmd_token **argv, int argc,
307 int *idx, afi_t *afi, safi_t *safi,
9f049418 308 struct bgp **bgp, bool use_json)
d62a17ae 309{
310 char *vrf_name = NULL;
311
312 assert(afi);
313 assert(safi);
314 assert(bgp);
315
316 if (argv_find(argv, argc, "ip", idx))
317 *afi = AFI_IP;
318
9a8bdf1c 319 if (argv_find(argv, argc, "view", idx))
d62a17ae 320 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
321 else if (argv_find(argv, argc, "vrf", idx)) {
322 vrf_name = argv[*idx + 1]->arg;
323 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
324 vrf_name = NULL;
325 }
326 if (vrf_name) {
d62a17ae 327 if (strmatch(vrf_name, "all"))
328 *bgp = NULL;
329 else {
330 *bgp = bgp_lookup_by_name(vrf_name);
331 if (!*bgp) {
ca61fd25
DS
332 if (use_json)
333 vty_out(vty, "{}\n");
334 else
335 vty_out(vty, "View/Vrf %s is unknown\n",
336 vrf_name);
d62a17ae 337 *idx = 0;
338 return 0;
339 }
340 }
341 } else {
342 *bgp = bgp_get_default();
343 if (!*bgp) {
ca61fd25
DS
344 if (use_json)
345 vty_out(vty, "{}\n");
346 else
347 vty_out(vty,
348 "Default BGP instance not found\n");
d62a17ae 349 *idx = 0;
350 return 0;
351 }
352 }
353
354 if (argv_find_and_parse_afi(argv, argc, idx, afi))
355 argv_find_and_parse_safi(argv, argc, idx, safi);
356
357 *idx += 1;
358 return *idx;
359}
360
361static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
362{
363 struct interface *ifp = NULL;
364
365 if (su->sa.sa_family == AF_INET)
366 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
367 else if (su->sa.sa_family == AF_INET6)
368 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
369 su->sin6.sin6_scope_id,
370 bgp->vrf_id);
371
372 if (ifp)
373 return 1;
374
375 return 0;
718e3744 376}
377
378/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
379/* This is used only for configuration, so disallow if attempted on
380 * a dynamic neighbor.
381 */
d62a17ae 382static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
383{
384 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
385 int ret;
386 union sockunion su;
387 struct peer *peer;
388
389 if (!bgp) {
390 return NULL;
391 }
392
393 ret = str2sockunion(ip_str, &su);
394 if (ret < 0) {
395 peer = peer_lookup_by_conf_if(bgp, ip_str);
396 if (!peer) {
397 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
398 == NULL) {
399 vty_out(vty,
400 "%% Malformed address or name: %s\n",
401 ip_str);
402 return NULL;
403 }
404 }
405 } else {
406 peer = peer_lookup(bgp, &su);
407 if (!peer) {
408 vty_out(vty,
409 "%% Specify remote-as or peer-group commands first\n");
410 return NULL;
411 }
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417 }
418 return peer;
718e3744 419}
420
421/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
422/* This is used only for configuration, so disallow if attempted on
423 * a dynamic neighbor.
424 */
d62a17ae 425struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
426{
427 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
428 int ret;
429 union sockunion su;
430 struct peer *peer = NULL;
431 struct peer_group *group = NULL;
432
433 if (!bgp) {
434 return NULL;
435 }
436
437 ret = str2sockunion(peer_str, &su);
438 if (ret == 0) {
439 /* IP address, locate peer. */
440 peer = peer_lookup(bgp, &su);
441 } else {
442 /* Not IP, could match either peer configured on interface or a
443 * group. */
444 peer = peer_lookup_by_conf_if(bgp, peer_str);
445 if (!peer)
446 group = peer_group_lookup(bgp, peer_str);
447 }
448
449 if (peer) {
450 if (peer_dynamic_neighbor(peer)) {
451 vty_out(vty,
452 "%% Operation not allowed on a dynamic neighbor\n");
453 return NULL;
454 }
455
456 return peer;
457 }
458
459 if (group)
460 return group->conf;
461
462 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
463
464 return NULL;
465}
466
467int bgp_vty_return(struct vty *vty, int ret)
468{
469 const char *str = NULL;
470
471 switch (ret) {
472 case BGP_ERR_INVALID_VALUE:
473 str = "Invalid value";
474 break;
475 case BGP_ERR_INVALID_FLAG:
476 str = "Invalid flag";
477 break;
478 case BGP_ERR_PEER_GROUP_SHUTDOWN:
479 str = "Peer-group has been shutdown. Activate the peer-group first";
480 break;
481 case BGP_ERR_PEER_FLAG_CONFLICT:
482 str = "Can't set override-capability and strict-capability-match at the same time";
483 break;
484 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
485 str = "Specify remote-as or peer-group remote AS first";
486 break;
487 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
488 str = "Cannot change the peer-group. Deconfigure first";
489 break;
490 case BGP_ERR_PEER_GROUP_MISMATCH:
491 str = "Peer is not a member of this peer-group";
492 break;
493 case BGP_ERR_PEER_FILTER_CONFLICT:
494 str = "Prefix/distribute list can not co-exist";
495 break;
496 case BGP_ERR_NOT_INTERNAL_PEER:
497 str = "Invalid command. Not an internal neighbor";
498 break;
499 case BGP_ERR_REMOVE_PRIVATE_AS:
500 str = "remove-private-AS cannot be configured for IBGP peers";
501 break;
502 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
503 str = "Local-AS allowed only for EBGP peers";
504 break;
505 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
506 str = "Cannot have local-as same as BGP AS number";
507 break;
508 case BGP_ERR_TCPSIG_FAILED:
509 str = "Error while applying TCP-Sig to session(s)";
510 break;
511 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
512 str = "ebgp-multihop and ttl-security cannot be configured together";
513 break;
514 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
515 str = "ttl-security only allowed for EBGP peers";
516 break;
517 case BGP_ERR_AS_OVERRIDE:
518 str = "as-override cannot be configured for IBGP peers";
519 break;
520 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
521 str = "Invalid limit for number of dynamic neighbors";
522 break;
523 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
524 str = "Dynamic neighbor listen range already exists";
525 break;
526 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
527 str = "Operation not allowed on a dynamic neighbor";
528 break;
529 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
530 str = "Operation not allowed on a directly connected neighbor";
531 break;
532 case BGP_ERR_PEER_SAFI_CONFLICT:
533 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
534 break;
535 }
536 if (str) {
537 vty_out(vty, "%% %s\n", str);
538 return CMD_WARNING_CONFIG_FAILED;
539 }
540 return CMD_SUCCESS;
718e3744 541}
542
7aafcaca 543/* BGP clear sort. */
d62a17ae 544enum clear_sort {
545 clear_all,
546 clear_peer,
547 clear_group,
548 clear_external,
549 clear_as
7aafcaca
DS
550};
551
d62a17ae 552static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
553 safi_t safi, int error)
554{
555 switch (error) {
556 case BGP_ERR_AF_UNCONFIGURED:
557 vty_out(vty,
558 "%%BGP: Enable %s address family for the neighbor %s\n",
559 afi_safi_print(afi, safi), peer->host);
560 break;
561 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
562 vty_out(vty,
563 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
564 peer->host);
565 break;
566 default:
567 break;
568 }
7aafcaca
DS
569}
570
571/* `clear ip bgp' functions. */
d62a17ae 572static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
573 enum clear_sort sort, enum bgp_clear_type stype,
574 const char *arg)
575{
576 int ret;
3ae8bfa5 577 bool found = false;
d62a17ae 578 struct peer *peer;
579 struct listnode *node, *nnode;
580
581 /* Clear all neighbors. */
582 /*
583 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
584 * nodes on the BGP instance as that may get freed if it is a
585 * doppelganger
d62a17ae 586 */
587 if (sort == clear_all) {
588 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
589 if (!peer->afc[afi][safi])
590 continue;
591
d62a17ae 592 if (stype == BGP_CLEAR_SOFT_NONE)
593 ret = peer_clear(peer, &nnode);
d62a17ae 594 else
3ae8bfa5 595 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 596
597 if (ret < 0)
598 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
599 else
600 found = true;
04b6bdc0 601 }
d62a17ae 602
603 /* This is to apply read-only mode on this clear. */
604 if (stype == BGP_CLEAR_SOFT_NONE)
605 bgp->update_delay_over = 0;
606
3ae8bfa5 607 if (!found)
3702f84d 608 vty_out(vty, "%%BGP: No %s peer configured\n",
3ae8bfa5
PM
609 afi_safi_print(afi, safi));
610
d62a17ae 611 return CMD_SUCCESS;
7aafcaca
DS
612 }
613
3ae8bfa5 614 /* Clear specified neighbor. */
d62a17ae 615 if (sort == clear_peer) {
616 union sockunion su;
d62a17ae 617
618 /* Make sockunion for lookup. */
619 ret = str2sockunion(arg, &su);
620 if (ret < 0) {
621 peer = peer_lookup_by_conf_if(bgp, arg);
622 if (!peer) {
623 peer = peer_lookup_by_hostname(bgp, arg);
624 if (!peer) {
625 vty_out(vty,
626 "Malformed address or name: %s\n",
627 arg);
628 return CMD_WARNING;
629 }
630 }
631 } else {
632 peer = peer_lookup(bgp, &su);
633 if (!peer) {
634 vty_out(vty,
635 "%%BGP: Unknown neighbor - \"%s\"\n",
636 arg);
637 return CMD_WARNING;
638 }
639 }
7aafcaca 640
3ae8bfa5
PM
641 if (!peer->afc[afi][safi])
642 ret = BGP_ERR_AF_UNCONFIGURED;
643 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 644 ret = peer_clear(peer, NULL);
645 else
646 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 647
d62a17ae 648 if (ret < 0)
649 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 650
d62a17ae 651 return CMD_SUCCESS;
7aafcaca 652 }
7aafcaca 653
3ae8bfa5 654 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 655 if (sort == clear_group) {
656 struct peer_group *group;
7aafcaca 657
d62a17ae 658 group = peer_group_lookup(bgp, arg);
659 if (!group) {
660 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
661 return CMD_WARNING;
662 }
663
664 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 665 if (!peer->afc[afi][safi])
666 continue;
667
3ae8bfa5
PM
668 if (stype == BGP_CLEAR_SOFT_NONE)
669 ret = peer_clear(peer, NULL);
670 else
671 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 672
d62a17ae 673 if (ret < 0)
674 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
675 else
676 found = true;
d62a17ae 677 }
3ae8bfa5
PM
678
679 if (!found)
680 vty_out(vty,
681 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
682 afi_safi_print(afi, safi), arg);
683
d62a17ae 684 return CMD_SUCCESS;
7aafcaca 685 }
7aafcaca 686
3ae8bfa5 687 /* Clear all external (eBGP) neighbors. */
d62a17ae 688 if (sort == clear_external) {
689 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
690 if (peer->sort == BGP_PEER_IBGP)
691 continue;
7aafcaca 692
3ae8bfa5
PM
693 if (!peer->afc[afi][safi])
694 continue;
695
d62a17ae 696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, &nnode);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 700
d62a17ae 701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
703 else
704 found = true;
d62a17ae 705 }
3ae8bfa5
PM
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No external %s peer is configured\n",
710 afi_safi_print(afi, safi));
711
d62a17ae 712 return CMD_SUCCESS;
713 }
714
3ae8bfa5 715 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 716 if (sort == clear_as) {
3ae8bfa5 717 as_t as = strtoul(arg, NULL, 10);
d62a17ae 718
719 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
720 if (peer->as != as)
721 continue;
722
3ae8bfa5
PM
723 if (!peer->afc[afi][safi])
724 ret = BGP_ERR_AF_UNCONFIGURED;
725 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 726 ret = peer_clear(peer, &nnode);
727 else
728 ret = peer_clear_soft(peer, afi, safi, stype);
729
730 if (ret < 0)
731 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
732 else
733 found = true;
d62a17ae 734 }
3ae8bfa5
PM
735
736 if (!found)
d62a17ae 737 vty_out(vty,
3ae8bfa5
PM
738 "%%BGP: No %s peer is configured with AS %s\n",
739 afi_safi_print(afi, safi), arg);
740
d62a17ae 741 return CMD_SUCCESS;
742 }
743
744 return CMD_SUCCESS;
745}
746
747static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
748 safi_t safi, enum clear_sort sort,
749 enum bgp_clear_type stype, const char *arg)
750{
751 struct bgp *bgp;
752
753 /* BGP structure lookup. */
754 if (name) {
755 bgp = bgp_lookup_by_name(name);
756 if (bgp == NULL) {
757 vty_out(vty, "Can't find BGP instance %s\n", name);
758 return CMD_WARNING;
759 }
760 } else {
761 bgp = bgp_get_default();
762 if (bgp == NULL) {
763 vty_out(vty, "No BGP process is configured\n");
764 return CMD_WARNING;
765 }
766 }
767
768 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
769}
770
771/* clear soft inbound */
d62a17ae 772static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 773{
d62a17ae 774 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
775 BGP_CLEAR_SOFT_IN, NULL);
776 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
777 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
778}
779
780/* clear soft outbound */
d62a17ae 781static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 782{
d62a17ae 783 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
784 BGP_CLEAR_SOFT_OUT, NULL);
785 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
786 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
787}
788
789
f787d7a0 790#ifndef VTYSH_EXTRACT_PL
2e4c2296 791#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
792#endif
793
718e3744 794/* BGP global configuration. */
bee57a7a 795#if (CONFDATE > 20190601)
1cc40660
DS
796CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
797CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
798#endif
799DEFUN_HIDDEN (bgp_multiple_instance_func,
800 bgp_multiple_instance_cmd,
801 "bgp multiple-instance",
802 BGP_STR
803 "Enable bgp multiple instance\n")
718e3744 804{
d62a17ae 805 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
806 return CMD_SUCCESS;
718e3744 807}
808
1cc40660 809DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 810 no_bgp_multiple_instance_cmd,
811 "no bgp multiple-instance",
812 NO_STR
813 BGP_STR
814 "BGP multiple instance\n")
815{
d62a17ae 816 int ret;
718e3744 817
1cc40660
DS
818 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
819 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 820 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 821 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
822 if (ret < 0) {
823 vty_out(vty, "%% There are more than two BGP instances\n");
824 return CMD_WARNING_CONFIG_FAILED;
825 }
826 return CMD_SUCCESS;
718e3744 827}
828
8029b216
AK
829DEFUN_HIDDEN (bgp_local_mac,
830 bgp_local_mac_cmd,
093e3f23 831 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
832 BGP_STR
833 "Local MAC config\n"
834 "VxLAN Network Identifier\n"
835 "VNI number\n"
836 "local mac\n"
837 "mac address\n"
838 "mac-mobility sequence\n"
839 "seq number\n")
840{
841 int rv;
842 vni_t vni;
843 struct ethaddr mac;
844 struct ipaddr ip;
845 uint32_t seq;
846 struct bgp *bgp;
847
848 vni = strtoul(argv[3]->arg, NULL, 10);
849 if (!prefix_str2mac(argv[5]->arg, &mac)) {
850 vty_out(vty, "%% Malformed MAC address\n");
851 return CMD_WARNING;
852 }
853 memset(&ip, 0, sizeof(ip));
854 seq = strtoul(argv[7]->arg, NULL, 10);
855
856 bgp = bgp_get_default();
857 if (!bgp) {
858 vty_out(vty, "Default BGP instance is not there\n");
859 return CMD_WARNING;
860 }
861
862 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
863 if (rv < 0) {
864 vty_out(vty, "Internal error\n");
865 return CMD_WARNING;
866 }
867
868 return CMD_SUCCESS;
869}
870
871DEFUN_HIDDEN (no_bgp_local_mac,
872 no_bgp_local_mac_cmd,
093e3f23 873 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
874 NO_STR
875 BGP_STR
876 "Local MAC config\n"
877 "VxLAN Network Identifier\n"
878 "VNI number\n"
879 "local mac\n"
880 "mac address\n")
881{
882 int rv;
883 vni_t vni;
884 struct ethaddr mac;
885 struct ipaddr ip;
886 struct bgp *bgp;
887
888 vni = strtoul(argv[4]->arg, NULL, 10);
889 if (!prefix_str2mac(argv[6]->arg, &mac)) {
890 vty_out(vty, "%% Malformed MAC address\n");
891 return CMD_WARNING;
892 }
893 memset(&ip, 0, sizeof(ip));
894
895 bgp = bgp_get_default();
896 if (!bgp) {
897 vty_out(vty, "Default BGP instance is not there\n");
898 return CMD_WARNING;
899 }
900
ec0ab544 901 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
902 if (rv < 0) {
903 vty_out(vty, "Internal error\n");
904 return CMD_WARNING;
905 }
906
907 return CMD_SUCCESS;
908}
909
bee57a7a 910#if (CONFDATE > 20190601)
798467a2
DS
911CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
912CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
913#endif
914DEFUN_HIDDEN (bgp_config_type,
915 bgp_config_type_cmd,
916 "bgp config-type <cisco|zebra>",
917 BGP_STR
918 "Configuration type\n"
919 "cisco\n"
920 "zebra\n")
718e3744 921{
d62a17ae 922 int idx = 0;
798467a2
DS
923 if (argv_find(argv, argc, "cisco", &idx)) {
924 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
925 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 926 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 927 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 928 } else
d62a17ae 929 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 930
d62a17ae 931 return CMD_SUCCESS;
718e3744 932}
933
798467a2
DS
934DEFUN_HIDDEN (no_bgp_config_type,
935 no_bgp_config_type_cmd,
936 "no bgp config-type [<cisco|zebra>]",
937 NO_STR
938 BGP_STR
939 "Display configuration type\n"
940 "cisco\n"
941 "zebra\n")
718e3744 942{
d62a17ae 943 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
944 return CMD_SUCCESS;
718e3744 945}
946
813d4307 947
718e3744 948DEFUN (no_synchronization,
949 no_synchronization_cmd,
950 "no synchronization",
951 NO_STR
952 "Perform IGP synchronization\n")
953{
d62a17ae 954 return CMD_SUCCESS;
718e3744 955}
956
957DEFUN (no_auto_summary,
958 no_auto_summary_cmd,
959 "no auto-summary",
960 NO_STR
961 "Enable automatic network number summarization\n")
962{
d62a17ae 963 return CMD_SUCCESS;
718e3744 964}
3d515fd9 965
718e3744 966/* "router bgp" commands. */
505e5056 967DEFUN_NOSH (router_bgp,
f412b39a 968 router_bgp_cmd,
18c57037 969 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 970 ROUTER_STR
971 BGP_STR
31500417
DW
972 AS_STR
973 BGP_INSTANCE_HELP_STR)
718e3744 974{
d62a17ae 975 int idx_asn = 2;
976 int idx_view_vrf = 3;
977 int idx_vrf = 4;
ecec9495 978 int is_new_bgp = 0;
d62a17ae 979 int ret;
980 as_t as;
981 struct bgp *bgp;
982 const char *name = NULL;
983 enum bgp_instance_type inst_type;
984
985 // "router bgp" without an ASN
986 if (argc == 2) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
989
990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
994
995 if (listcount(bm->bgp) > 1) {
996c9314 996 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 997 return CMD_WARNING_CONFIG_FAILED;
998 }
999 }
1000
1001 // "router bgp X"
1002 else {
1003 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1004
1005 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1006 if (argc > 3) {
1007 name = argv[idx_vrf]->arg;
1008
9a8bdf1c
PG
1009 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1010 if (strmatch(name, VRF_DEFAULT_NAME))
1011 name = NULL;
1012 else
1013 inst_type = BGP_INSTANCE_TYPE_VRF;
1014 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1015 inst_type = BGP_INSTANCE_TYPE_VIEW;
1016 }
1017
ecec9495
AD
1018 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1019 is_new_bgp = (bgp_lookup(as, name) == NULL);
1020
d62a17ae 1021 ret = bgp_get(&bgp, &as, name, inst_type);
1022 switch (ret) {
1023 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1024 vty_out(vty,
1025 "Please specify 'bgp multiple-instance' first\n");
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_AS_MISMATCH:
1028 vty_out(vty, "BGP is already running; AS is %u\n", as);
1029 return CMD_WARNING_CONFIG_FAILED;
1030 case BGP_ERR_INSTANCE_MISMATCH:
1031 vty_out(vty,
1032 "BGP instance name and AS number mismatch\n");
1033 vty_out(vty,
1034 "BGP instance is already running; AS is %u\n",
1035 as);
1036 return CMD_WARNING_CONFIG_FAILED;
1037 }
1038
3bd70bf8
PZ
1039 /*
1040 * If we just instantiated the default instance, complete
1041 * any pending VRF-VPN leaking that was configured via
1042 * earlier "router bgp X vrf FOO" blocks.
1043 */
ecec9495 1044 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1045 vpn_leak_postchange_all();
1046
d62a17ae 1047 /* Pending: handle when user tries to change a view to vrf n vv.
1048 */
1049 }
1050
0b5131c9
MK
1051 /* unset the auto created flag as the user config is now present */
1052 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1053 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1054
1055 return CMD_SUCCESS;
718e3744 1056}
1057
718e3744 1058/* "no router bgp" commands. */
1059DEFUN (no_router_bgp,
1060 no_router_bgp_cmd,
18c57037 1061 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 1062 NO_STR
1063 ROUTER_STR
1064 BGP_STR
31500417
DW
1065 AS_STR
1066 BGP_INSTANCE_HELP_STR)
718e3744 1067{
d62a17ae 1068 int idx_asn = 3;
1069 int idx_vrf = 5;
1070 as_t as;
1071 struct bgp *bgp;
1072 const char *name = NULL;
718e3744 1073
d62a17ae 1074 // "no router bgp" without an ASN
1075 if (argc == 3) {
1076 // Pending: Make VRF option available for ASN less config
1077 bgp = bgp_get_default();
718e3744 1078
d62a17ae 1079 if (bgp == NULL) {
1080 vty_out(vty, "%% No BGP process is configured\n");
1081 return CMD_WARNING_CONFIG_FAILED;
1082 }
7fb21a9f 1083
d62a17ae 1084 if (listcount(bm->bgp) > 1) {
996c9314 1085 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
0b5131c9
MK
1088
1089 if (bgp->l3vni) {
1090 vty_out(vty, "%% Please unconfigure l3vni %u",
1091 bgp->l3vni);
1092 return CMD_WARNING_CONFIG_FAILED;
1093 }
d62a17ae 1094 } else {
1095 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1096
d62a17ae 1097 if (argc > 4)
1098 name = argv[idx_vrf]->arg;
7fb21a9f 1099
d62a17ae 1100 /* Lookup bgp structure. */
1101 bgp = bgp_lookup(as, name);
1102 if (!bgp) {
1103 vty_out(vty, "%% Can't find BGP instance\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
0b5131c9
MK
1106
1107 if (bgp->l3vni) {
1108 vty_out(vty, "%% Please unconfigure l3vni %u",
1109 bgp->l3vni);
1110 return CMD_WARNING_CONFIG_FAILED;
1111 }
d62a17ae 1112 }
718e3744 1113
d62a17ae 1114 bgp_delete(bgp);
718e3744 1115
d62a17ae 1116 return CMD_SUCCESS;
718e3744 1117}
1118
6b0655a2 1119
718e3744 1120/* BGP router-id. */
1121
f787d7a0 1122DEFPY (bgp_router_id,
718e3744 1123 bgp_router_id_cmd,
1124 "bgp router-id A.B.C.D",
1125 BGP_STR
1126 "Override configured router identifier\n"
1127 "Manually configured router identifier\n")
1128{
d62a17ae 1129 VTY_DECLVAR_CONTEXT(bgp, bgp);
1130 bgp_router_id_static_set(bgp, router_id);
1131 return CMD_SUCCESS;
718e3744 1132}
1133
f787d7a0 1134DEFPY (no_bgp_router_id,
718e3744 1135 no_bgp_router_id_cmd,
31500417 1136 "no bgp router-id [A.B.C.D]",
718e3744 1137 NO_STR
1138 BGP_STR
31500417
DW
1139 "Override configured router identifier\n"
1140 "Manually configured router identifier\n")
718e3744 1141{
d62a17ae 1142 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1143
d62a17ae 1144 if (router_id_str) {
1145 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1146 vty_out(vty, "%% BGP router-id doesn't match\n");
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
e018c7cc 1149 }
718e3744 1150
d62a17ae 1151 router_id.s_addr = 0;
1152 bgp_router_id_static_set(bgp, router_id);
718e3744 1153
d62a17ae 1154 return CMD_SUCCESS;
718e3744 1155}
1156
6b0655a2 1157
718e3744 1158/* BGP Cluster ID. */
718e3744 1159DEFUN (bgp_cluster_id,
1160 bgp_cluster_id_cmd,
838758ac 1161 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1162 BGP_STR
1163 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1164 "Route-Reflector Cluster-id in IP address format\n"
1165 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1166{
d62a17ae 1167 VTY_DECLVAR_CONTEXT(bgp, bgp);
1168 int idx_ipv4 = 2;
1169 int ret;
1170 struct in_addr cluster;
718e3744 1171
d62a17ae 1172 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1173 if (!ret) {
1174 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1175 return CMD_WARNING_CONFIG_FAILED;
1176 }
718e3744 1177
d62a17ae 1178 bgp_cluster_id_set(bgp, &cluster);
1179 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1180
d62a17ae 1181 return CMD_SUCCESS;
718e3744 1182}
1183
718e3744 1184DEFUN (no_bgp_cluster_id,
1185 no_bgp_cluster_id_cmd,
c7178fe7 1186 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1187 NO_STR
1188 BGP_STR
838758ac
DW
1189 "Configure Route-Reflector Cluster-id\n"
1190 "Route-Reflector Cluster-id in IP address format\n"
1191 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1192{
d62a17ae 1193 VTY_DECLVAR_CONTEXT(bgp, bgp);
1194 bgp_cluster_id_unset(bgp);
1195 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1196
d62a17ae 1197 return CMD_SUCCESS;
718e3744 1198}
1199
718e3744 1200DEFUN (bgp_confederation_identifier,
1201 bgp_confederation_identifier_cmd,
9ccf14f7 1202 "bgp confederation identifier (1-4294967295)",
718e3744 1203 "BGP specific commands\n"
1204 "AS confederation parameters\n"
1205 "AS number\n"
1206 "Set routing domain confederation AS\n")
1207{
d62a17ae 1208 VTY_DECLVAR_CONTEXT(bgp, bgp);
1209 int idx_number = 3;
1210 as_t as;
718e3744 1211
d62a17ae 1212 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1213
d62a17ae 1214 bgp_confederation_id_set(bgp, as);
718e3744 1215
d62a17ae 1216 return CMD_SUCCESS;
718e3744 1217}
1218
1219DEFUN (no_bgp_confederation_identifier,
1220 no_bgp_confederation_identifier_cmd,
838758ac 1221 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1222 NO_STR
1223 "BGP specific commands\n"
1224 "AS confederation parameters\n"
3a2d747c
QY
1225 "AS number\n"
1226 "Set routing domain confederation AS\n")
718e3744 1227{
d62a17ae 1228 VTY_DECLVAR_CONTEXT(bgp, bgp);
1229 bgp_confederation_id_unset(bgp);
718e3744 1230
d62a17ae 1231 return CMD_SUCCESS;
718e3744 1232}
1233
718e3744 1234DEFUN (bgp_confederation_peers,
1235 bgp_confederation_peers_cmd,
12dcf78e 1236 "bgp confederation peers (1-4294967295)...",
718e3744 1237 "BGP specific commands\n"
1238 "AS confederation parameters\n"
1239 "Peer ASs in BGP confederation\n"
1240 AS_STR)
1241{
d62a17ae 1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
1243 int idx_asn = 3;
1244 as_t as;
1245 int i;
718e3744 1246
d62a17ae 1247 for (i = idx_asn; i < argc; i++) {
1248 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1249
d62a17ae 1250 if (bgp->as == as) {
1251 vty_out(vty,
1252 "%% Local member-AS not allowed in confed peer list\n");
1253 continue;
1254 }
718e3744 1255
d62a17ae 1256 bgp_confederation_peers_add(bgp, as);
1257 }
1258 return CMD_SUCCESS;
718e3744 1259}
1260
1261DEFUN (no_bgp_confederation_peers,
1262 no_bgp_confederation_peers_cmd,
e83a9414 1263 "no bgp confederation peers (1-4294967295)...",
718e3744 1264 NO_STR
1265 "BGP specific commands\n"
1266 "AS confederation parameters\n"
1267 "Peer ASs in BGP confederation\n"
1268 AS_STR)
1269{
d62a17ae 1270 VTY_DECLVAR_CONTEXT(bgp, bgp);
1271 int idx_asn = 4;
1272 as_t as;
1273 int i;
718e3744 1274
d62a17ae 1275 for (i = idx_asn; i < argc; i++) {
1276 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1277
d62a17ae 1278 bgp_confederation_peers_remove(bgp, as);
1279 }
1280 return CMD_SUCCESS;
718e3744 1281}
6b0655a2 1282
5e242b0d
DS
1283/**
1284 * Central routine for maximum-paths configuration.
1285 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1286 * @set: 1 for setting values, 0 for removing the max-paths config.
1287 */
d62a17ae 1288static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1289 const char *mpaths, uint16_t options,
d62a17ae 1290 int set)
1291{
1292 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1293 uint16_t maxpaths = 0;
d62a17ae 1294 int ret;
1295 afi_t afi;
1296 safi_t safi;
1297
1298 afi = bgp_node_afi(vty);
1299 safi = bgp_node_safi(vty);
1300
1301 if (set) {
1302 maxpaths = strtol(mpaths, NULL, 10);
1303 if (maxpaths > multipath_num) {
1304 vty_out(vty,
1305 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1306 maxpaths, multipath_num);
1307 return CMD_WARNING_CONFIG_FAILED;
1308 }
1309 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1310 options);
1311 } else
1312 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1313
1314 if (ret < 0) {
1315 vty_out(vty,
1316 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1317 (set == 1) ? "" : "un",
1318 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1319 maxpaths, afi, safi);
1320 return CMD_WARNING_CONFIG_FAILED;
1321 }
1322
1323 bgp_recalculate_all_bestpaths(bgp);
1324
1325 return CMD_SUCCESS;
165b5fff
JB
1326}
1327
abc920f8
DS
1328DEFUN (bgp_maxmed_admin,
1329 bgp_maxmed_admin_cmd,
1330 "bgp max-med administrative ",
1331 BGP_STR
1332 "Advertise routes with max-med\n"
1333 "Administratively applied, for an indefinite period\n")
1334{
d62a17ae 1335 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1336
d62a17ae 1337 bgp->v_maxmed_admin = 1;
1338 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1339
d62a17ae 1340 bgp_maxmed_update(bgp);
abc920f8 1341
d62a17ae 1342 return CMD_SUCCESS;
abc920f8
DS
1343}
1344
1345DEFUN (bgp_maxmed_admin_medv,
1346 bgp_maxmed_admin_medv_cmd,
4668a151 1347 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1348 BGP_STR
1349 "Advertise routes with max-med\n"
1350 "Administratively applied, for an indefinite period\n"
1351 "Max MED value to be used\n")
1352{
d62a17ae 1353 VTY_DECLVAR_CONTEXT(bgp, bgp);
1354 int idx_number = 3;
abc920f8 1355
d62a17ae 1356 bgp->v_maxmed_admin = 1;
1357 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1358
d62a17ae 1359 bgp_maxmed_update(bgp);
abc920f8 1360
d62a17ae 1361 return CMD_SUCCESS;
abc920f8
DS
1362}
1363
1364DEFUN (no_bgp_maxmed_admin,
1365 no_bgp_maxmed_admin_cmd,
4668a151 1366 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1367 NO_STR
1368 BGP_STR
1369 "Advertise routes with max-med\n"
838758ac
DW
1370 "Administratively applied, for an indefinite period\n"
1371 "Max MED value to be used\n")
abc920f8 1372{
d62a17ae 1373 VTY_DECLVAR_CONTEXT(bgp, bgp);
1374 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1375 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1376 bgp_maxmed_update(bgp);
abc920f8 1377
d62a17ae 1378 return CMD_SUCCESS;
abc920f8
DS
1379}
1380
abc920f8
DS
1381DEFUN (bgp_maxmed_onstartup,
1382 bgp_maxmed_onstartup_cmd,
4668a151 1383 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1384 BGP_STR
1385 "Advertise routes with max-med\n"
1386 "Effective on a startup\n"
1387 "Time (seconds) period for max-med\n"
1388 "Max MED value to be used\n")
1389{
d62a17ae 1390 VTY_DECLVAR_CONTEXT(bgp, bgp);
1391 int idx = 0;
4668a151 1392
d62a17ae 1393 argv_find(argv, argc, "(5-86400)", &idx);
1394 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1395 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1396 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1397 else
1398 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1399
d62a17ae 1400 bgp_maxmed_update(bgp);
abc920f8 1401
d62a17ae 1402 return CMD_SUCCESS;
abc920f8
DS
1403}
1404
1405DEFUN (no_bgp_maxmed_onstartup,
1406 no_bgp_maxmed_onstartup_cmd,
4668a151 1407 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1408 NO_STR
1409 BGP_STR
1410 "Advertise routes with max-med\n"
838758ac
DW
1411 "Effective on a startup\n"
1412 "Time (seconds) period for max-med\n"
1413 "Max MED value to be used\n")
abc920f8 1414{
d62a17ae 1415 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1416
d62a17ae 1417 /* Cancel max-med onstartup if its on */
1418 if (bgp->t_maxmed_onstartup) {
1419 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1420 bgp->maxmed_onstartup_over = 1;
1421 }
abc920f8 1422
d62a17ae 1423 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1424 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1425
d62a17ae 1426 bgp_maxmed_update(bgp);
abc920f8 1427
d62a17ae 1428 return CMD_SUCCESS;
abc920f8
DS
1429}
1430
d62a17ae 1431static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1432 const char *wait)
f188f2c4 1433{
d62a17ae 1434 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1435 uint16_t update_delay;
1436 uint16_t establish_wait;
f188f2c4 1437
d62a17ae 1438 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1439
d62a17ae 1440 if (!wait) /* update-delay <delay> */
1441 {
1442 bgp->v_update_delay = update_delay;
1443 bgp->v_establish_wait = bgp->v_update_delay;
1444 return CMD_SUCCESS;
1445 }
f188f2c4 1446
d62a17ae 1447 /* update-delay <delay> <establish-wait> */
1448 establish_wait = atoi(wait);
1449 if (update_delay < establish_wait) {
1450 vty_out(vty,
1451 "%%Failed: update-delay less than the establish-wait!\n");
1452 return CMD_WARNING_CONFIG_FAILED;
1453 }
f188f2c4 1454
d62a17ae 1455 bgp->v_update_delay = update_delay;
1456 bgp->v_establish_wait = establish_wait;
f188f2c4 1457
d62a17ae 1458 return CMD_SUCCESS;
f188f2c4
DS
1459}
1460
d62a17ae 1461static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1462{
d62a17ae 1463 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1464
d62a17ae 1465 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1466 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1467
d62a17ae 1468 return CMD_SUCCESS;
f188f2c4
DS
1469}
1470
2b791107 1471void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1472{
d62a17ae 1473 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1474 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1475 if (bgp->v_update_delay != bgp->v_establish_wait)
1476 vty_out(vty, " %d", bgp->v_establish_wait);
1477 vty_out(vty, "\n");
1478 }
f188f2c4
DS
1479}
1480
1481
1482/* Update-delay configuration */
1483DEFUN (bgp_update_delay,
1484 bgp_update_delay_cmd,
6147e2c6 1485 "update-delay (0-3600)",
f188f2c4
DS
1486 "Force initial delay for best-path and updates\n"
1487 "Seconds\n")
1488{
d62a17ae 1489 int idx_number = 1;
1490 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1491}
1492
1493DEFUN (bgp_update_delay_establish_wait,
1494 bgp_update_delay_establish_wait_cmd,
6147e2c6 1495 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1496 "Force initial delay for best-path and updates\n"
1497 "Seconds\n"
f188f2c4
DS
1498 "Seconds\n")
1499{
d62a17ae 1500 int idx_number = 1;
1501 int idx_number_2 = 2;
1502 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1503 argv[idx_number_2]->arg);
f188f2c4
DS
1504}
1505
1506/* Update-delay deconfiguration */
1507DEFUN (no_bgp_update_delay,
1508 no_bgp_update_delay_cmd,
838758ac
DW
1509 "no update-delay [(0-3600) [(1-3600)]]",
1510 NO_STR
f188f2c4 1511 "Force initial delay for best-path and updates\n"
838758ac 1512 "Seconds\n"
7111c1a0 1513 "Seconds\n")
f188f2c4 1514{
d62a17ae 1515 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1516}
1517
5e242b0d 1518
d62a17ae 1519static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1520 char set)
cb1faec9 1521{
d62a17ae 1522 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1523
555e09d4
QY
1524 if (set) {
1525 uint32_t quanta = strtoul(num, NULL, 10);
1526 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1527 memory_order_relaxed);
1528 } else {
1529 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1530 memory_order_relaxed);
1531 }
1532
1533 return CMD_SUCCESS;
1534}
1535
1536static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1537 char set)
1538{
1539 VTY_DECLVAR_CONTEXT(bgp, bgp);
1540
1541 if (set) {
1542 uint32_t quanta = strtoul(num, NULL, 10);
1543 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1544 memory_order_relaxed);
1545 } else {
1546 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1547 memory_order_relaxed);
1548 }
cb1faec9 1549
d62a17ae 1550 return CMD_SUCCESS;
cb1faec9
DS
1551}
1552
2b791107 1553void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1554{
555e09d4
QY
1555 uint32_t quanta =
1556 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1557 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1558 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1559}
1560
555e09d4
QY
1561void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1562{
1563 uint32_t quanta =
1564 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1565 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1566 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1567}
cb1faec9 1568
555e09d4 1569/* Packet quanta configuration */
cb1faec9
DS
1570DEFUN (bgp_wpkt_quanta,
1571 bgp_wpkt_quanta_cmd,
555e09d4 1572 "write-quanta (1-10)",
cb1faec9
DS
1573 "How many packets to write to peer socket per run\n"
1574 "Number of packets\n")
1575{
d62a17ae 1576 int idx_number = 1;
1577 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1578}
1579
cb1faec9
DS
1580DEFUN (no_bgp_wpkt_quanta,
1581 no_bgp_wpkt_quanta_cmd,
555e09d4 1582 "no write-quanta (1-10)",
d7fa34c1 1583 NO_STR
555e09d4 1584 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1585 "Number of packets\n")
1586{
d62a17ae 1587 int idx_number = 2;
1588 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1589}
1590
555e09d4
QY
1591DEFUN (bgp_rpkt_quanta,
1592 bgp_rpkt_quanta_cmd,
1593 "read-quanta (1-10)",
1594 "How many packets to read from peer socket per I/O cycle\n"
1595 "Number of packets\n")
1596{
1597 int idx_number = 1;
1598 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1599}
1600
1601DEFUN (no_bgp_rpkt_quanta,
1602 no_bgp_rpkt_quanta_cmd,
1603 "no read-quanta (1-10)",
1604 NO_STR
1605 "How many packets to read from peer socket per I/O cycle\n"
1606 "Number of packets\n")
1607{
1608 int idx_number = 2;
1609 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1610}
1611
2b791107 1612void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1613{
37a333fe 1614 if (!bgp->heuristic_coalesce)
d62a17ae 1615 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1616}
1617
1618
1619DEFUN (bgp_coalesce_time,
1620 bgp_coalesce_time_cmd,
6147e2c6 1621 "coalesce-time (0-4294967295)",
3f9c7369
DS
1622 "Subgroup coalesce timer\n"
1623 "Subgroup coalesce timer value (in ms)\n")
1624{
d62a17ae 1625 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1626
d62a17ae 1627 int idx = 0;
1628 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1629 bgp->heuristic_coalesce = false;
d62a17ae 1630 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1631 return CMD_SUCCESS;
3f9c7369
DS
1632}
1633
1634DEFUN (no_bgp_coalesce_time,
1635 no_bgp_coalesce_time_cmd,
6147e2c6 1636 "no coalesce-time (0-4294967295)",
3a2d747c 1637 NO_STR
3f9c7369
DS
1638 "Subgroup coalesce timer\n"
1639 "Subgroup coalesce timer value (in ms)\n")
1640{
d62a17ae 1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1642
37a333fe 1643 bgp->heuristic_coalesce = true;
d62a17ae 1644 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1645 return CMD_SUCCESS;
3f9c7369
DS
1646}
1647
5e242b0d
DS
1648/* Maximum-paths configuration */
1649DEFUN (bgp_maxpaths,
1650 bgp_maxpaths_cmd,
6319fd63 1651 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1652 "Forward packets over multiple paths\n"
1653 "Number of paths\n")
1654{
d62a17ae 1655 int idx_number = 1;
1656 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1657 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1658}
1659
d62a17ae 1660ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1661 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1662 "Forward packets over multiple paths\n"
1663 "Number of paths\n")
596c17ba 1664
165b5fff
JB
1665DEFUN (bgp_maxpaths_ibgp,
1666 bgp_maxpaths_ibgp_cmd,
6319fd63 1667 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1668 "Forward packets over multiple paths\n"
1669 "iBGP-multipath\n"
1670 "Number of paths\n")
1671{
d62a17ae 1672 int idx_number = 2;
1673 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1674 argv[idx_number]->arg, 0, 1);
5e242b0d 1675}
165b5fff 1676
d62a17ae 1677ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1678 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1679 "Forward packets over multiple paths\n"
1680 "iBGP-multipath\n"
1681 "Number of paths\n")
596c17ba 1682
5e242b0d
DS
1683DEFUN (bgp_maxpaths_ibgp_cluster,
1684 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1685 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1686 "Forward packets over multiple paths\n"
1687 "iBGP-multipath\n"
1688 "Number of paths\n"
1689 "Match the cluster length\n")
1690{
d62a17ae 1691 int idx_number = 2;
1692 return bgp_maxpaths_config_vty(
1693 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1694 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1695}
1696
d62a17ae 1697ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1698 "maximum-paths ibgp " CMD_RANGE_STR(
1699 1, MULTIPATH_NUM) " equal-cluster-length",
1700 "Forward packets over multiple paths\n"
1701 "iBGP-multipath\n"
1702 "Number of paths\n"
1703 "Match the cluster length\n")
596c17ba 1704
165b5fff
JB
1705DEFUN (no_bgp_maxpaths,
1706 no_bgp_maxpaths_cmd,
6319fd63 1707 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1708 NO_STR
1709 "Forward packets over multiple paths\n"
1710 "Number of paths\n")
1711{
d62a17ae 1712 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1713}
1714
d62a17ae 1715ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1716 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1717 "Forward packets over multiple paths\n"
1718 "Number of paths\n")
596c17ba 1719
165b5fff
JB
1720DEFUN (no_bgp_maxpaths_ibgp,
1721 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1722 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1723 NO_STR
1724 "Forward packets over multiple paths\n"
1725 "iBGP-multipath\n"
838758ac
DW
1726 "Number of paths\n"
1727 "Match the cluster length\n")
165b5fff 1728{
d62a17ae 1729 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1730}
1731
d62a17ae 1732ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1733 "no maximum-paths ibgp [" CMD_RANGE_STR(
1734 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1735 NO_STR
1736 "Forward packets over multiple paths\n"
1737 "iBGP-multipath\n"
1738 "Number of paths\n"
1739 "Match the cluster length\n")
596c17ba 1740
2b791107 1741void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1742 safi_t safi)
165b5fff 1743{
d62a17ae 1744 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1745 vty_out(vty, " maximum-paths %d\n",
1746 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1747 }
165b5fff 1748
d62a17ae 1749 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1750 vty_out(vty, " maximum-paths ibgp %d",
1751 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1752 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1753 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1754 vty_out(vty, " equal-cluster-length");
1755 vty_out(vty, "\n");
1756 }
165b5fff 1757}
6b0655a2 1758
718e3744 1759/* BGP timers. */
1760
1761DEFUN (bgp_timers,
1762 bgp_timers_cmd,
6147e2c6 1763 "timers bgp (0-65535) (0-65535)",
718e3744 1764 "Adjust routing timers\n"
1765 "BGP timers\n"
1766 "Keepalive interval\n"
1767 "Holdtime\n")
1768{
d62a17ae 1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 int idx_number = 2;
1771 int idx_number_2 = 3;
1772 unsigned long keepalive = 0;
1773 unsigned long holdtime = 0;
718e3744 1774
d62a17ae 1775 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1776 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1777
d62a17ae 1778 /* Holdtime value check. */
1779 if (holdtime < 3 && holdtime != 0) {
1780 vty_out(vty,
1781 "%% hold time value must be either 0 or greater than 3\n");
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
718e3744 1784
d62a17ae 1785 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1786
d62a17ae 1787 return CMD_SUCCESS;
718e3744 1788}
1789
1790DEFUN (no_bgp_timers,
1791 no_bgp_timers_cmd,
838758ac 1792 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1793 NO_STR
1794 "Adjust routing timers\n"
838758ac
DW
1795 "BGP timers\n"
1796 "Keepalive interval\n"
1797 "Holdtime\n")
718e3744 1798{
d62a17ae 1799 VTY_DECLVAR_CONTEXT(bgp, bgp);
1800 bgp_timers_unset(bgp);
718e3744 1801
d62a17ae 1802 return CMD_SUCCESS;
718e3744 1803}
1804
6b0655a2 1805
718e3744 1806DEFUN (bgp_client_to_client_reflection,
1807 bgp_client_to_client_reflection_cmd,
1808 "bgp client-to-client reflection",
1809 "BGP specific commands\n"
1810 "Configure client to client route reflection\n"
1811 "reflection of routes allowed\n")
1812{
d62a17ae 1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1815 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1816
d62a17ae 1817 return CMD_SUCCESS;
718e3744 1818}
1819
1820DEFUN (no_bgp_client_to_client_reflection,
1821 no_bgp_client_to_client_reflection_cmd,
1822 "no bgp client-to-client reflection",
1823 NO_STR
1824 "BGP specific commands\n"
1825 "Configure client to client route reflection\n"
1826 "reflection of routes allowed\n")
1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1830 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1831
d62a17ae 1832 return CMD_SUCCESS;
718e3744 1833}
1834
1835/* "bgp always-compare-med" configuration. */
1836DEFUN (bgp_always_compare_med,
1837 bgp_always_compare_med_cmd,
1838 "bgp always-compare-med",
1839 "BGP specific commands\n"
1840 "Allow comparing MED from different neighbors\n")
1841{
d62a17ae 1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1844 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1845
d62a17ae 1846 return CMD_SUCCESS;
718e3744 1847}
1848
1849DEFUN (no_bgp_always_compare_med,
1850 no_bgp_always_compare_med_cmd,
1851 "no bgp always-compare-med",
1852 NO_STR
1853 "BGP specific commands\n"
1854 "Allow comparing MED from different neighbors\n")
1855{
d62a17ae 1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1858 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1859
d62a17ae 1860 return CMD_SUCCESS;
718e3744 1861}
6b0655a2 1862
9dac9fc8
DA
1863
1864DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1865 "bgp ebgp-requires-policy",
1866 "BGP specific commands\n"
1867 "Require in and out policy for eBGP peers (RFC8212)\n")
1868{
1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1871 return CMD_SUCCESS;
1872}
1873
1874DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1875 "no bgp ebgp-requires-policy",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Require in and out policy for eBGP peers (RFC8212)\n")
1879{
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1882 return CMD_SUCCESS;
1883}
1884
1885
718e3744 1886/* "bgp deterministic-med" configuration. */
1887DEFUN (bgp_deterministic_med,
1888 bgp_deterministic_med_cmd,
1889 "bgp deterministic-med",
1890 "BGP specific commands\n"
1891 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1892{
d62a17ae 1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1894
d62a17ae 1895 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1896 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1897 bgp_recalculate_all_bestpaths(bgp);
1898 }
7aafcaca 1899
d62a17ae 1900 return CMD_SUCCESS;
718e3744 1901}
1902
1903DEFUN (no_bgp_deterministic_med,
1904 no_bgp_deterministic_med_cmd,
1905 "no bgp deterministic-med",
1906 NO_STR
1907 "BGP specific commands\n"
1908 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1909{
d62a17ae 1910 VTY_DECLVAR_CONTEXT(bgp, bgp);
1911 int bestpath_per_as_used;
1912 afi_t afi;
1913 safi_t safi;
1914 struct peer *peer;
1915 struct listnode *node, *nnode;
1916
1917 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1918 bestpath_per_as_used = 0;
1919
1920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1921 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1922 if (bgp_addpath_dmed_required(
1923 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1924 bestpath_per_as_used = 1;
1925 break;
1926 }
d62a17ae 1927
1928 if (bestpath_per_as_used)
1929 break;
1930 }
1931
1932 if (bestpath_per_as_used) {
1933 vty_out(vty,
1934 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1935 return CMD_WARNING_CONFIG_FAILED;
1936 } else {
1937 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1938 bgp_recalculate_all_bestpaths(bgp);
1939 }
1940 }
1941
1942 return CMD_SUCCESS;
718e3744 1943}
538621f2 1944
1945/* "bgp graceful-restart" configuration. */
1946DEFUN (bgp_graceful_restart,
1947 bgp_graceful_restart_cmd,
1948 "bgp graceful-restart",
1949 "BGP specific commands\n"
1950 "Graceful restart capability parameters\n")
1951{
d62a17ae 1952 VTY_DECLVAR_CONTEXT(bgp, bgp);
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1954 return CMD_SUCCESS;
538621f2 1955}
1956
1957DEFUN (no_bgp_graceful_restart,
1958 no_bgp_graceful_restart_cmd,
1959 "no bgp graceful-restart",
1960 NO_STR
1961 "BGP specific commands\n"
1962 "Graceful restart capability parameters\n")
1963{
d62a17ae 1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1966 return CMD_SUCCESS;
538621f2 1967}
1968
93406d87 1969DEFUN (bgp_graceful_restart_stalepath_time,
1970 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 1971 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n"
1974 "Set the max time to hold onto restarting peer's stale paths\n"
1975 "Delay value (seconds)\n")
1976{
d62a17ae 1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978 int idx_number = 3;
d7c0a89a 1979 uint32_t stalepath;
93406d87 1980
d62a17ae 1981 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1982 bgp->stalepath_time = stalepath;
1983 return CMD_SUCCESS;
93406d87 1984}
1985
eb6f1b41
PG
1986DEFUN (bgp_graceful_restart_restart_time,
1987 bgp_graceful_restart_restart_time_cmd,
c72d0314 1988 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
1989 "BGP specific commands\n"
1990 "Graceful restart capability parameters\n"
1991 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1992 "Delay value (seconds)\n")
1993{
d62a17ae 1994 VTY_DECLVAR_CONTEXT(bgp, bgp);
1995 int idx_number = 3;
d7c0a89a 1996 uint32_t restart;
eb6f1b41 1997
d62a17ae 1998 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1999 bgp->restart_time = restart;
2000 return CMD_SUCCESS;
eb6f1b41
PG
2001}
2002
93406d87 2003DEFUN (no_bgp_graceful_restart_stalepath_time,
2004 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2005 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 2006 NO_STR
2007 "BGP specific commands\n"
2008 "Graceful restart capability parameters\n"
838758ac
DW
2009 "Set the max time to hold onto restarting peer's stale paths\n"
2010 "Delay value (seconds)\n")
93406d87 2011{
d62a17ae 2012 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2013
d62a17ae 2014 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2015 return CMD_SUCCESS;
93406d87 2016}
2017
eb6f1b41
PG
2018DEFUN (no_bgp_graceful_restart_restart_time,
2019 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 2020 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
2021 NO_STR
2022 "BGP specific commands\n"
2023 "Graceful restart capability parameters\n"
838758ac
DW
2024 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2025 "Delay value (seconds)\n")
eb6f1b41 2026{
d62a17ae 2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2028
d62a17ae 2029 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2030 return CMD_SUCCESS;
eb6f1b41
PG
2031}
2032
43fc21b3
JC
2033DEFUN (bgp_graceful_restart_preserve_fw,
2034 bgp_graceful_restart_preserve_fw_cmd,
2035 "bgp graceful-restart preserve-fw-state",
2036 "BGP specific commands\n"
2037 "Graceful restart capability parameters\n"
2038 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2039{
d62a17ae 2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2042 return CMD_SUCCESS;
43fc21b3
JC
2043}
2044
2045DEFUN (no_bgp_graceful_restart_preserve_fw,
2046 no_bgp_graceful_restart_preserve_fw_cmd,
2047 "no bgp graceful-restart preserve-fw-state",
2048 NO_STR
2049 "BGP specific commands\n"
2050 "Graceful restart capability parameters\n"
2051 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2052{
d62a17ae 2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2055 return CMD_SUCCESS;
43fc21b3
JC
2056}
2057
7f323236
DW
2058static void bgp_redistribute_redo(struct bgp *bgp)
2059{
2060 afi_t afi;
2061 int i;
2062 struct list *red_list;
2063 struct listnode *node;
2064 struct bgp_redist *red;
2065
a4d82a8a
PZ
2066 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2067 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 2068
a4d82a8a
PZ
2069 red_list = bgp->redist[afi][i];
2070 if (!red_list)
2071 continue;
7f323236 2072
a4d82a8a 2073 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
2074 bgp_redistribute_resend(bgp, afi, i,
2075 red->instance);
2076 }
2077 }
2078 }
2079}
2080
2081/* "bgp graceful-shutdown" configuration */
2082DEFUN (bgp_graceful_shutdown,
2083 bgp_graceful_shutdown_cmd,
2084 "bgp graceful-shutdown",
2085 BGP_STR
2086 "Graceful shutdown parameters\n")
2087{
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2091 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2092 bgp_static_redo_import_check(bgp);
2093 bgp_redistribute_redo(bgp);
2094 bgp_clear_star_soft_out(vty, bgp->name);
2095 bgp_clear_star_soft_in(vty, bgp->name);
2096 }
2097
2098 return CMD_SUCCESS;
2099}
2100
2101DEFUN (no_bgp_graceful_shutdown,
2102 no_bgp_graceful_shutdown_cmd,
2103 "no bgp graceful-shutdown",
2104 NO_STR
2105 BGP_STR
2106 "Graceful shutdown parameters\n")
2107{
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109
2110 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2111 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2112 bgp_static_redo_import_check(bgp);
2113 bgp_redistribute_redo(bgp);
2114 bgp_clear_star_soft_out(vty, bgp->name);
2115 bgp_clear_star_soft_in(vty, bgp->name);
2116 }
2117
2118 return CMD_SUCCESS;
2119}
2120
718e3744 2121/* "bgp fast-external-failover" configuration. */
2122DEFUN (bgp_fast_external_failover,
2123 bgp_fast_external_failover_cmd,
2124 "bgp fast-external-failover",
2125 BGP_STR
2126 "Immediately reset session if a link to a directly connected external peer goes down\n")
2127{
d62a17ae 2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2130 return CMD_SUCCESS;
718e3744 2131}
2132
2133DEFUN (no_bgp_fast_external_failover,
2134 no_bgp_fast_external_failover_cmd,
2135 "no bgp fast-external-failover",
2136 NO_STR
2137 BGP_STR
2138 "Immediately reset session if a link to a directly connected external peer goes down\n")
2139{
d62a17ae 2140 VTY_DECLVAR_CONTEXT(bgp, bgp);
2141 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2142 return CMD_SUCCESS;
718e3744 2143}
6b0655a2 2144
718e3744 2145/* "bgp enforce-first-as" configuration. */
ec4f0750 2146#if CONFDATE > 20190517
47cbc09b
PM
2147CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2148#endif
2149
f07e1c4f
QY
2150DEFUN_HIDDEN (bgp_enforce_first_as,
2151 bgp_enforce_first_as_cmd,
2152 "[no] bgp enforce-first-as",
2153 NO_STR
2154 BGP_STR
2155 "Enforce the first AS for EBGP routes\n")
718e3744 2156{
d62a17ae 2157 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2158
f07e1c4f
QY
2159 if (strmatch(argv[0]->text, "no"))
2160 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2161 else
2162 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
7aafcaca 2163
d62a17ae 2164 return CMD_SUCCESS;
718e3744 2165}
6b0655a2 2166
718e3744 2167/* "bgp bestpath compare-routerid" configuration. */
2168DEFUN (bgp_bestpath_compare_router_id,
2169 bgp_bestpath_compare_router_id_cmd,
2170 "bgp bestpath compare-routerid",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "Compare router-id for identical EBGP paths\n")
2174{
d62a17ae 2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2177 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2178
d62a17ae 2179 return CMD_SUCCESS;
718e3744 2180}
2181
2182DEFUN (no_bgp_bestpath_compare_router_id,
2183 no_bgp_bestpath_compare_router_id_cmd,
2184 "no bgp bestpath compare-routerid",
2185 NO_STR
2186 "BGP specific commands\n"
2187 "Change the default bestpath selection\n"
2188 "Compare router-id for identical EBGP paths\n")
2189{
d62a17ae 2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2192 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2193
d62a17ae 2194 return CMD_SUCCESS;
718e3744 2195}
6b0655a2 2196
718e3744 2197/* "bgp bestpath as-path ignore" configuration. */
2198DEFUN (bgp_bestpath_aspath_ignore,
2199 bgp_bestpath_aspath_ignore_cmd,
2200 "bgp bestpath as-path ignore",
2201 "BGP specific commands\n"
2202 "Change the default bestpath selection\n"
2203 "AS-path attribute\n"
2204 "Ignore as-path length in selecting a route\n")
2205{
d62a17ae 2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2208 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2209
d62a17ae 2210 return CMD_SUCCESS;
718e3744 2211}
2212
2213DEFUN (no_bgp_bestpath_aspath_ignore,
2214 no_bgp_bestpath_aspath_ignore_cmd,
2215 "no bgp bestpath as-path ignore",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Ignore as-path length in selecting a route\n")
2221{
d62a17ae 2222 VTY_DECLVAR_CONTEXT(bgp, bgp);
2223 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2224 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2225
d62a17ae 2226 return CMD_SUCCESS;
718e3744 2227}
6b0655a2 2228
6811845b 2229/* "bgp bestpath as-path confed" configuration. */
2230DEFUN (bgp_bestpath_aspath_confed,
2231 bgp_bestpath_aspath_confed_cmd,
2232 "bgp bestpath as-path confed",
2233 "BGP specific commands\n"
2234 "Change the default bestpath selection\n"
2235 "AS-path attribute\n"
2236 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2237{
d62a17ae 2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2240 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2241
d62a17ae 2242 return CMD_SUCCESS;
6811845b 2243}
2244
2245DEFUN (no_bgp_bestpath_aspath_confed,
2246 no_bgp_bestpath_aspath_confed_cmd,
2247 "no bgp bestpath as-path confed",
2248 NO_STR
2249 "BGP specific commands\n"
2250 "Change the default bestpath selection\n"
2251 "AS-path attribute\n"
2252 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2253{
d62a17ae 2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2256 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2257
d62a17ae 2258 return CMD_SUCCESS;
6811845b 2259}
6b0655a2 2260
2fdd455c
PM
2261/* "bgp bestpath as-path multipath-relax" configuration. */
2262DEFUN (bgp_bestpath_aspath_multipath_relax,
2263 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2264 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "AS-path attribute\n"
2268 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2269 "Generate an AS_SET\n"
16fc1eec
DS
2270 "Do not generate an AS_SET\n")
2271{
d62a17ae 2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273 int idx = 0;
2274 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2275
d62a17ae 2276 /* no-as-set is now the default behavior so we can silently
2277 * ignore it */
2278 if (argv_find(argv, argc, "as-set", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2280 else
2281 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2282
d62a17ae 2283 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2284
d62a17ae 2285 return CMD_SUCCESS;
16fc1eec
DS
2286}
2287
219178b6
DW
2288DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2289 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2290 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2291 NO_STR
2292 "BGP specific commands\n"
2293 "Change the default bestpath selection\n"
2294 "AS-path attribute\n"
2295 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2296 "Generate an AS_SET\n"
16fc1eec
DS
2297 "Do not generate an AS_SET\n")
2298{
d62a17ae 2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2301 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2302 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2303
d62a17ae 2304 return CMD_SUCCESS;
2fdd455c 2305}
6b0655a2 2306
848973c7 2307/* "bgp log-neighbor-changes" configuration. */
2308DEFUN (bgp_log_neighbor_changes,
2309 bgp_log_neighbor_changes_cmd,
2310 "bgp log-neighbor-changes",
2311 "BGP specific commands\n"
2312 "Log neighbor up/down and reset reason\n")
2313{
d62a17ae 2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2316 return CMD_SUCCESS;
848973c7 2317}
2318
2319DEFUN (no_bgp_log_neighbor_changes,
2320 no_bgp_log_neighbor_changes_cmd,
2321 "no bgp log-neighbor-changes",
2322 NO_STR
2323 "BGP specific commands\n"
2324 "Log neighbor up/down and reset reason\n")
2325{
d62a17ae 2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2328 return CMD_SUCCESS;
848973c7 2329}
6b0655a2 2330
718e3744 2331/* "bgp bestpath med" configuration. */
2332DEFUN (bgp_bestpath_med,
2333 bgp_bestpath_med_cmd,
2d8c1a4d 2334 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
838758ac
DW
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
718e3744 2342{
d62a17ae 2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2344
d62a17ae 2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2351
d62a17ae 2352 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2353
d62a17ae 2354 return CMD_SUCCESS;
718e3744 2355}
2356
718e3744 2357DEFUN (no_bgp_bestpath_med,
2358 no_bgp_bestpath_med_cmd,
2d8c1a4d 2359 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2360 NO_STR
2361 "BGP specific commands\n"
2362 "Change the default bestpath selection\n"
2363 "MED attribute\n"
2364 "Compare MED among confederation paths\n"
3a2d747c
QY
2365 "Treat missing MED as the least preferred one\n"
2366 "Treat missing MED as the least preferred one\n"
2367 "Compare MED among confederation paths\n")
718e3744 2368{
d62a17ae 2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2370
d62a17ae 2371 int idx = 0;
2372 if (argv_find(argv, argc, "confed", &idx))
2373 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2374 idx = 0;
2375 if (argv_find(argv, argc, "missing-as-worst", &idx))
2376 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2377
d62a17ae 2378 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2379
d62a17ae 2380 return CMD_SUCCESS;
718e3744 2381}
2382
718e3744 2383/* "no bgp default ipv4-unicast". */
2384DEFUN (no_bgp_default_ipv4_unicast,
2385 no_bgp_default_ipv4_unicast_cmd,
2386 "no bgp default ipv4-unicast",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "Configure BGP defaults\n"
2390 "Activate ipv4-unicast for a peer by default\n")
2391{
d62a17ae 2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2394 return CMD_SUCCESS;
718e3744 2395}
2396
2397DEFUN (bgp_default_ipv4_unicast,
2398 bgp_default_ipv4_unicast_cmd,
2399 "bgp default ipv4-unicast",
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Activate ipv4-unicast for a peer by default\n")
2403{
d62a17ae 2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2406 return CMD_SUCCESS;
718e3744 2407}
6b0655a2 2408
04b6bdc0
DW
2409/* Display hostname in certain command outputs */
2410DEFUN (bgp_default_show_hostname,
2411 bgp_default_show_hostname_cmd,
2412 "bgp default show-hostname",
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
0437e105 2415 "Show hostname in certain command outputs\n")
04b6bdc0 2416{
d62a17ae 2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2419 return CMD_SUCCESS;
04b6bdc0
DW
2420}
2421
2422DEFUN (no_bgp_default_show_hostname,
2423 no_bgp_default_show_hostname_cmd,
2424 "no bgp default show-hostname",
2425 NO_STR
2426 "BGP specific commands\n"
2427 "Configure BGP defaults\n"
0437e105 2428 "Show hostname in certain command outputs\n")
04b6bdc0 2429{
d62a17ae 2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2432 return CMD_SUCCESS;
04b6bdc0
DW
2433}
2434
8233ef81 2435/* "bgp network import-check" configuration. */
718e3744 2436DEFUN (bgp_network_import_check,
2437 bgp_network_import_check_cmd,
5623e905 2438 "bgp network import-check",
718e3744 2439 "BGP specific commands\n"
2440 "BGP network command\n"
5623e905 2441 "Check BGP network route exists in IGP\n")
718e3744 2442{
d62a17ae 2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
078430f6 2448
d62a17ae 2449 return CMD_SUCCESS;
718e3744 2450}
2451
d62a17ae 2452ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2453 "bgp network import-check exact",
2454 "BGP specific commands\n"
2455 "BGP network command\n"
2456 "Check BGP network route exists in IGP\n"
2457 "Match route precisely\n")
8233ef81 2458
718e3744 2459DEFUN (no_bgp_network_import_check,
2460 no_bgp_network_import_check_cmd,
5623e905 2461 "no bgp network import-check",
718e3744 2462 NO_STR
2463 "BGP specific commands\n"
2464 "BGP network command\n"
2465 "Check BGP network route exists in IGP\n")
2466{
d62a17ae 2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2469 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2470 bgp_static_redo_import_check(bgp);
2471 }
5623e905 2472
d62a17ae 2473 return CMD_SUCCESS;
718e3744 2474}
6b0655a2 2475
718e3744 2476DEFUN (bgp_default_local_preference,
2477 bgp_default_local_preference_cmd,
6147e2c6 2478 "bgp default local-preference (0-4294967295)",
718e3744 2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "local preference (higher=more preferred)\n"
2482 "Configure default local preference value\n")
2483{
d62a17ae 2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485 int idx_number = 3;
d7c0a89a 2486 uint32_t local_pref;
718e3744 2487
d62a17ae 2488 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2489
d62a17ae 2490 bgp_default_local_preference_set(bgp, local_pref);
2491 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2492
d62a17ae 2493 return CMD_SUCCESS;
718e3744 2494}
2495
2496DEFUN (no_bgp_default_local_preference,
2497 no_bgp_default_local_preference_cmd,
838758ac 2498 "no bgp default local-preference [(0-4294967295)]",
718e3744 2499 NO_STR
2500 "BGP specific commands\n"
2501 "Configure BGP defaults\n"
838758ac
DW
2502 "local preference (higher=more preferred)\n"
2503 "Configure default local preference value\n")
718e3744 2504{
d62a17ae 2505 VTY_DECLVAR_CONTEXT(bgp, bgp);
2506 bgp_default_local_preference_unset(bgp);
2507 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2508
d62a17ae 2509 return CMD_SUCCESS;
718e3744 2510}
2511
6b0655a2 2512
3f9c7369
DS
2513DEFUN (bgp_default_subgroup_pkt_queue_max,
2514 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2515 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "subgroup-pkt-queue-max\n"
2519 "Configure subgroup packet queue max\n")
8bd9d948 2520{
d62a17ae 2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
d7c0a89a 2523 uint32_t max_size;
8bd9d948 2524
d62a17ae 2525 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2526
d62a17ae 2527 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2528
d62a17ae 2529 return CMD_SUCCESS;
3f9c7369
DS
2530}
2531
2532DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2533 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2534 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2535 NO_STR
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
838758ac
DW
2538 "subgroup-pkt-queue-max\n"
2539 "Configure subgroup packet queue max\n")
3f9c7369 2540{
d62a17ae 2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2543 return CMD_SUCCESS;
8bd9d948
DS
2544}
2545
813d4307 2546
8bd9d948
DS
2547DEFUN (bgp_rr_allow_outbound_policy,
2548 bgp_rr_allow_outbound_policy_cmd,
2549 "bgp route-reflector allow-outbound-policy",
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553{
d62a17ae 2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2555
d62a17ae 2556 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
8bd9d948 2561
d62a17ae 2562 return CMD_SUCCESS;
8bd9d948
DS
2563}
2564
2565DEFUN (no_bgp_rr_allow_outbound_policy,
2566 no_bgp_rr_allow_outbound_policy_cmd,
2567 "no bgp route-reflector allow-outbound-policy",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "Allow modifications made by out route-map\n"
2571 "on ibgp neighbors\n")
2572{
d62a17ae 2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2574
d62a17ae 2575 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2576 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2577 update_group_announce_rrclients(bgp);
2578 bgp_clear_star_soft_out(vty, bgp->name);
2579 }
8bd9d948 2580
d62a17ae 2581 return CMD_SUCCESS;
8bd9d948
DS
2582}
2583
f14e6fdb
DS
2584DEFUN (bgp_listen_limit,
2585 bgp_listen_limit_cmd,
9ccf14f7 2586 "bgp listen limit (1-5000)",
f14e6fdb
DS
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value\n")
2591{
d62a17ae 2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 int idx_number = 3;
2594 int listen_limit;
f14e6fdb 2595
d62a17ae 2596 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2597
d62a17ae 2598 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2599
d62a17ae 2600 return CMD_SUCCESS;
f14e6fdb
DS
2601}
2602
2603DEFUN (no_bgp_listen_limit,
2604 no_bgp_listen_limit_cmd,
838758ac 2605 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2606 "BGP specific commands\n"
2607 "Configure BGP defaults\n"
2608 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2609 "Configure Dynamic Neighbors listen limit value to default\n"
2610 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2611{
d62a17ae 2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 bgp_listen_limit_unset(bgp);
2614 return CMD_SUCCESS;
f14e6fdb
DS
2615}
2616
2617
20eb8864 2618/*
2619 * Check if this listen range is already configured. Check for exact
2620 * match or overlap based on input.
2621 */
d62a17ae 2622static struct peer_group *listen_range_exists(struct bgp *bgp,
2623 struct prefix *range, int exact)
2624{
2625 struct listnode *node, *nnode;
2626 struct listnode *node1, *nnode1;
2627 struct peer_group *group;
2628 struct prefix *lr;
2629 afi_t afi;
2630 int match;
2631
2632 afi = family2afi(range->family);
2633 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2634 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2635 lr)) {
2636 if (exact)
2637 match = prefix_same(range, lr);
2638 else
2639 match = (prefix_match(range, lr)
2640 || prefix_match(lr, range));
2641 if (match)
2642 return group;
2643 }
2644 }
2645
2646 return NULL;
20eb8864 2647}
2648
f14e6fdb
DS
2649DEFUN (bgp_listen_range,
2650 bgp_listen_range_cmd,
9ccf14f7 2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2652 "BGP specific commands\n"
d7fa34c1
QY
2653 "Configure BGP dynamic neighbors listen range\n"
2654 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
f14e6fdb 2658{
d62a17ae 2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group, *existing_group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "WORD", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 /* Check if same listen range is already configured. */
2690 existing_group = listen_range_exists(bgp, &range, 1);
2691 if (existing_group) {
2692 if (strcmp(existing_group->name, peergroup) == 0)
2693 return CMD_SUCCESS;
2694 else {
2695 vty_out(vty,
2696 "%% Same listen range is attached to peer-group %s\n",
2697 existing_group->name);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 }
2700 }
2701
2702 /* Check if an overlapping listen range exists. */
2703 if (listen_range_exists(bgp, &range, 0)) {
2704 vty_out(vty,
2705 "%% Listen range overlaps with existing listen range\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 group = peer_group_lookup(bgp, peergroup);
2710 if (!group) {
2711 vty_out(vty, "%% Configure the peer-group first\n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 ret = peer_group_listen_range_add(group, &range);
2716 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2717}
2718
2719DEFUN (no_bgp_listen_range,
2720 no_bgp_listen_range_cmd,
d7fa34c1
QY
2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2722 NO_STR
f14e6fdb 2723 "BGP specific commands\n"
d7fa34c1
QY
2724 "Unconfigure BGP dynamic neighbors listen range\n"
2725 "Unconfigure BGP dynamic neighbors listen range\n"
2726 NEIGHBOR_ADDR_STR
2727 "Member of the peer-group\n"
2728 "Peer-group name\n")
f14e6fdb 2729{
d62a17ae 2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 struct prefix range;
2732 struct peer_group *group;
2733 afi_t afi;
2734 int ret;
2735 int idx = 0;
2736
2737 argv_find(argv, argc, "A.B.C.D/M", &idx);
2738 argv_find(argv, argc, "X:X::X:X/M", &idx);
2739 char *prefix = argv[idx]->arg;
2740 argv_find(argv, argc, "WORD", &idx);
2741 char *peergroup = argv[idx]->arg;
2742
2743 /* Convert IP prefix string to struct prefix. */
2744 ret = str2prefix(prefix, &range);
2745 if (!ret) {
2746 vty_out(vty, "%% Malformed listen range\n");
2747 return CMD_WARNING_CONFIG_FAILED;
2748 }
2749
2750 afi = family2afi(range.family);
2751
2752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2753 vty_out(vty,
2754 "%% Malformed listen range (link-local address)\n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 apply_mask(&range);
2759
2760 group = peer_group_lookup(bgp, peergroup);
2761 if (!group) {
2762 vty_out(vty, "%% Peer-group does not exist\n");
2763 return CMD_WARNING_CONFIG_FAILED;
2764 }
2765
2766 ret = peer_group_listen_range_del(group, &range);
2767 return bgp_vty_return(vty, ret);
2768}
2769
2b791107 2770void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2771{
2772 struct peer_group *group;
2773 struct listnode *node, *nnode, *rnode, *nrnode;
2774 struct prefix *range;
2775 afi_t afi;
2776 char buf[PREFIX2STR_BUFFER];
2777
2778 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2779 vty_out(vty, " bgp listen limit %d\n",
2780 bgp->dynamic_neighbors_limit);
2781
2782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2783 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2784 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2785 nrnode, range)) {
2786 prefix2str(range, buf, sizeof(buf));
2787 vty_out(vty,
2788 " bgp listen range %s peer-group %s\n",
2789 buf, group->name);
2790 }
2791 }
2792 }
f14e6fdb
DS
2793}
2794
2795
907f92c8
DS
2796DEFUN (bgp_disable_connected_route_check,
2797 bgp_disable_connected_route_check_cmd,
2798 "bgp disable-ebgp-connected-route-check",
2799 "BGP specific commands\n"
2800 "Disable checking if nexthop is connected on ebgp sessions\n")
2801{
d62a17ae 2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2804 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2805
d62a17ae 2806 return CMD_SUCCESS;
907f92c8
DS
2807}
2808
2809DEFUN (no_bgp_disable_connected_route_check,
2810 no_bgp_disable_connected_route_check_cmd,
2811 "no bgp disable-ebgp-connected-route-check",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Disable checking if nexthop is connected on ebgp sessions\n")
2815{
d62a17ae 2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2818 bgp_clear_star_soft_in(vty, bgp->name);
2819
2820 return CMD_SUCCESS;
2821}
2822
2823
2824static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2825 const char *as_str, afi_t afi, safi_t safi)
2826{
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 int ret;
2829 as_t as;
2830 int as_type = AS_SPECIFIED;
2831 union sockunion su;
2832
2833 if (as_str[0] == 'i') {
2834 as = 0;
2835 as_type = AS_INTERNAL;
2836 } else if (as_str[0] == 'e') {
2837 as = 0;
2838 as_type = AS_EXTERNAL;
2839 } else {
2840 /* Get AS number. */
2841 as = strtoul(as_str, NULL, 10);
2842 }
2843
390485fd 2844 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
390485fd
DS
2847 struct peer *peer;
2848
2849 /* Check if existing interface peer */
2850 peer = peer_lookup_by_conf_if(bgp, peer_str);
2851
d62a17ae 2852 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2853 safi);
390485fd
DS
2854
2855 /* if not interface peer, check peer-group settings */
2856 if (ret < 0 && !peer) {
d62a17ae 2857 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2858 if (ret < 0) {
2859 vty_out(vty,
390485fd 2860 "%% Create the peer-group or interface first\n");
d62a17ae 2861 return CMD_WARNING_CONFIG_FAILED;
2862 }
2863 return CMD_SUCCESS;
2864 }
2865 } else {
2866 if (peer_address_self_check(bgp, &su)) {
2867 vty_out(vty,
2868 "%% Can not configure the local system as neighbor\n");
2869 return CMD_WARNING_CONFIG_FAILED;
2870 }
2871 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2872 }
2873
2874 /* This peer belongs to peer group. */
2875 switch (ret) {
2876 case BGP_ERR_PEER_GROUP_MEMBER:
2877 vty_out(vty,
faa16034 2878 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 2879 return CMD_WARNING_CONFIG_FAILED;
2880 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2881 vty_out(vty,
faa16034 2882 "%% Peer-group members must be all internal or all external\n");
d62a17ae 2883 return CMD_WARNING_CONFIG_FAILED;
2884 }
2885 return bgp_vty_return(vty, ret);
718e3744 2886}
2887
f26845f9
QY
2888DEFUN (bgp_default_shutdown,
2889 bgp_default_shutdown_cmd,
2890 "[no] bgp default shutdown",
2891 NO_STR
2892 BGP_STR
2893 "Configure BGP defaults\n"
b012cbe2 2894 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2895{
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2898 return CMD_SUCCESS;
2899}
2900
718e3744 2901DEFUN (neighbor_remote_as,
2902 neighbor_remote_as_cmd,
3a2d747c 2903 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 "Specify a BGP neighbor\n"
d7fa34c1 2907 AS_STR
3a2d747c
QY
2908 "Internal BGP peer\n"
2909 "External BGP peer\n")
718e3744 2910{
d62a17ae 2911 int idx_peer = 1;
2912 int idx_remote_as = 3;
2913 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2914 argv[idx_remote_as]->arg, AFI_IP,
2915 SAFI_UNICAST);
2916}
2917
2918static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2919 afi_t afi, safi_t safi, int v6only,
2920 const char *peer_group_name,
2921 const char *as_str)
2922{
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924 as_t as = 0;
2925 int as_type = AS_UNSPECIFIED;
2926 struct peer *peer;
2927 struct peer_group *group;
2928 int ret = 0;
2929 union sockunion su;
2930
2931 group = peer_group_lookup(bgp, conf_if);
2932
2933 if (group) {
2934 vty_out(vty, "%% Name conflict with peer-group \n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 if (as_str) {
2939 if (as_str[0] == 'i') {
2940 as_type = AS_INTERNAL;
2941 } else if (as_str[0] == 'e') {
2942 as_type = AS_EXTERNAL;
2943 } else {
2944 /* Get AS number. */
2945 as = strtoul(as_str, NULL, 10);
2946 as_type = AS_SPECIFIED;
2947 }
2948 }
2949
2950 peer = peer_lookup_by_conf_if(bgp, conf_if);
2951 if (peer) {
2952 if (as_str)
cc4d4ce8 2953 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2954 afi, safi);
2955 } else {
2956 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2957 && afi == AFI_IP && safi == SAFI_UNICAST)
2958 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2959 as_type, 0, 0, NULL);
2960 else
2961 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2962 as_type, afi, safi, NULL);
2963
2964 if (!peer) {
2965 vty_out(vty, "%% BGP failed to create peer\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968
2969 if (v6only)
527de3dc 2970 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2971
2972 /* Request zebra to initiate IPv6 RAs on this interface. We do
2973 * this
2974 * any unnumbered peer in order to not worry about run-time
2975 * transitions
2976 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2977 * address
2978 * gets deleted later etc.)
2979 */
2980 if (peer->ifp)
2981 bgp_zebra_initiate_radv(bgp, peer);
2982 }
2983
2984 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2985 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2986 if (v6only)
527de3dc 2987 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2988 else
527de3dc 2989 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2990
2991 /* v6only flag changed. Reset bgp seesion */
2992 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2993 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2994 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2995 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2996 } else
2997 bgp_session_reset(peer);
2998 }
2999
9fb964de
PM
3000 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3001 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3002 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3003 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3004 }
d62a17ae 3005
3006 if (peer_group_name) {
3007 group = peer_group_lookup(bgp, peer_group_name);
3008 if (!group) {
3009 vty_out(vty, "%% Configure the peer-group first\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 ret = peer_group_bind(bgp, &su, peer, group, &as);
3014 }
3015
3016 return bgp_vty_return(vty, ret);
a80beece
DS
3017}
3018
4c48cf63
DW
3019DEFUN (neighbor_interface_config,
3020 neighbor_interface_config_cmd,
31500417 3021 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
3022 NEIGHBOR_STR
3023 "Interface name or neighbor tag\n"
31500417
DW
3024 "Enable BGP on interface\n"
3025 "Member of the peer-group\n"
16cedbb0 3026 "Peer-group name\n")
4c48cf63 3027{
d62a17ae 3028 int idx_word = 1;
3029 int idx_peer_group_word = 4;
31500417 3030
d62a17ae 3031 if (argc > idx_peer_group_word)
3032 return peer_conf_interface_get(
3033 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3034 argv[idx_peer_group_word]->arg, NULL);
3035 else
3036 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3037 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3038}
3039
4c48cf63
DW
3040DEFUN (neighbor_interface_config_v6only,
3041 neighbor_interface_config_v6only_cmd,
31500417 3042 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
31500417
DW
3046 "Enable BGP with v6 link-local only\n"
3047 "Member of the peer-group\n"
16cedbb0 3048 "Peer-group name\n")
4c48cf63 3049{
d62a17ae 3050 int idx_word = 1;
3051 int idx_peer_group_word = 5;
31500417 3052
d62a17ae 3053 if (argc > idx_peer_group_word)
3054 return peer_conf_interface_get(
3055 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3056 argv[idx_peer_group_word]->arg, NULL);
31500417 3057
d62a17ae 3058 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3059 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3060}
3061
a80beece 3062
b3a39dc5
DD
3063DEFUN (neighbor_interface_config_remote_as,
3064 neighbor_interface_config_remote_as_cmd,
3a2d747c 3065 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
3068 "Enable BGP on interface\n"
3a2d747c 3069 "Specify a BGP neighbor\n"
d7fa34c1 3070 AS_STR
3a2d747c
QY
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
b3a39dc5 3073{
d62a17ae 3074 int idx_word = 1;
3075 int idx_remote_as = 4;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 0, NULL,
3078 argv[idx_remote_as]->arg);
b3a39dc5
DD
3079}
3080
3081DEFUN (neighbor_interface_v6only_config_remote_as,
3082 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3083 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3a2d747c 3086 "Enable BGP with v6 link-local only\n"
b3a39dc5 3087 "Enable BGP on interface\n"
3a2d747c 3088 "Specify a BGP neighbor\n"
d7fa34c1 3089 AS_STR
3a2d747c
QY
3090 "Internal BGP peer\n"
3091 "External BGP peer\n")
b3a39dc5 3092{
d62a17ae 3093 int idx_word = 1;
3094 int idx_remote_as = 5;
3095 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3096 SAFI_UNICAST, 1, NULL,
3097 argv[idx_remote_as]->arg);
b3a39dc5
DD
3098}
3099
718e3744 3100DEFUN (neighbor_peer_group,
3101 neighbor_peer_group_cmd,
3102 "neighbor WORD peer-group",
3103 NEIGHBOR_STR
a80beece 3104 "Interface name or neighbor tag\n"
718e3744 3105 "Configure peer-group\n")
3106{
d62a17ae 3107 VTY_DECLVAR_CONTEXT(bgp, bgp);
3108 int idx_word = 1;
3109 struct peer *peer;
3110 struct peer_group *group;
718e3744 3111
d62a17ae 3112 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3113 if (peer) {
3114 vty_out(vty, "%% Name conflict with interface: \n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
718e3744 3117
d62a17ae 3118 group = peer_group_get(bgp, argv[idx_word]->arg);
3119 if (!group) {
3120 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
718e3744 3123
d62a17ae 3124 return CMD_SUCCESS;
718e3744 3125}
3126
3127DEFUN (no_neighbor,
3128 no_neighbor_cmd,
dab8cd00 3129 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3130 NO_STR
3131 NEIGHBOR_STR
3a2d747c
QY
3132 NEIGHBOR_ADDR_STR2
3133 "Specify a BGP neighbor\n"
3134 AS_STR
3135 "Internal BGP peer\n"
3136 "External BGP peer\n")
718e3744 3137{
d62a17ae 3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 int idx_peer = 2;
3140 int ret;
3141 union sockunion su;
3142 struct peer_group *group;
3143 struct peer *peer;
3144 struct peer *other;
3145
3146 ret = str2sockunion(argv[idx_peer]->arg, &su);
3147 if (ret < 0) {
3148 /* look up for neighbor by interface name config. */
3149 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3150 if (peer) {
3151 /* Request zebra to terminate IPv6 RAs on this
3152 * interface. */
3153 if (peer->ifp)
3154 bgp_zebra_terminate_radv(peer->bgp, peer);
3155 peer_delete(peer);
3156 return CMD_SUCCESS;
3157 }
f14e6fdb 3158
d62a17ae 3159 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 } else {
3167 peer = peer_lookup(bgp, &su);
3168 if (peer) {
3169 if (peer_dynamic_neighbor(peer)) {
3170 vty_out(vty,
3171 "%% Operation not allowed on a dynamic neighbor\n");
3172 return CMD_WARNING_CONFIG_FAILED;
3173 }
3174
3175 other = peer->doppelganger;
3176 peer_delete(peer);
3177 if (other && other->status != Deleted)
3178 peer_delete(other);
3179 }
1ff9a340 3180 }
718e3744 3181
d62a17ae 3182 return CMD_SUCCESS;
718e3744 3183}
3184
a80beece
DS
3185DEFUN (no_neighbor_interface_config,
3186 no_neighbor_interface_config_cmd,
31500417 3187 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Interface name\n"
31500417
DW
3191 "Configure BGP on interface\n"
3192 "Enable BGP with v6 link-local only\n"
3193 "Member of the peer-group\n"
16cedbb0 3194 "Peer-group name\n"
3a2d747c
QY
3195 "Specify a BGP neighbor\n"
3196 AS_STR
3197 "Internal BGP peer\n"
3198 "External BGP peer\n")
a80beece 3199{
d62a17ae 3200 VTY_DECLVAR_CONTEXT(bgp, bgp);
3201 int idx_word = 2;
3202 struct peer *peer;
3203
3204 /* look up for neighbor by interface name config. */
3205 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3206 if (peer) {
3207 /* Request zebra to terminate IPv6 RAs on this interface. */
3208 if (peer->ifp)
3209 bgp_zebra_terminate_radv(peer->bgp, peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
a80beece
DS
3216}
3217
718e3744 3218DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225{
d62a17ae 3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
718e3744 3229
d62a17ae 3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
718e3744 3238}
3239
a80beece
DS
3240DEFUN (no_neighbor_interface_peer_group_remote_as,
3241 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3242 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3243 NO_STR
3244 NEIGHBOR_STR
a80beece 3245 "Interface name or neighbor tag\n"
718e3744 3246 "Specify a BGP neighbor\n"
3a2d747c
QY
3247 AS_STR
3248 "Internal BGP peer\n"
3249 "External BGP peer\n")
718e3744 3250{
d62a17ae 3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254 struct peer *peer;
3255
3256 /* look up for neighbor by interface name config. */
3257 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3258 if (peer) {
390485fd 3259 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3260 return CMD_SUCCESS;
3261 }
3262
3263 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3264 if (group)
3265 peer_group_remote_as_delete(group);
3266 else {
3267 vty_out(vty, "%% Create the peer-group or interface first\n");
3268 return CMD_WARNING_CONFIG_FAILED;
3269 }
3270 return CMD_SUCCESS;
718e3744 3271}
6b0655a2 3272
718e3744 3273DEFUN (neighbor_local_as,
3274 neighbor_local_as_cmd,
9ccf14f7 3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n")
3280{
d62a17ae 3281 int idx_peer = 1;
3282 int idx_number = 3;
3283 struct peer *peer;
3284 int ret;
3285 as_t as;
718e3744 3286
d62a17ae 3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
718e3744 3290
d62a17ae 3291 as = strtoul(argv[idx_number]->arg, NULL, 10);
3292 ret = peer_local_as_set(peer, as, 0, 0);
3293 return bgp_vty_return(vty, ret);
718e3744 3294}
3295
3296DEFUN (neighbor_local_as_no_prepend,
3297 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3298 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Specify a local-as number\n"
3302 "AS number used as local AS\n"
3303 "Do not prepend local-as to updates from ebgp peers\n")
3304{
d62a17ae 3305 int idx_peer = 1;
3306 int idx_number = 3;
3307 struct peer *peer;
3308 int ret;
3309 as_t as;
718e3744 3310
d62a17ae 3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
718e3744 3314
d62a17ae 3315 as = strtoul(argv[idx_number]->arg, NULL, 10);
3316 ret = peer_local_as_set(peer, as, 1, 0);
3317 return bgp_vty_return(vty, ret);
718e3744 3318}
3319
9d3f9705
AC
3320DEFUN (neighbor_local_as_no_prepend_replace_as,
3321 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3322 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3323 NEIGHBOR_STR
3324 NEIGHBOR_ADDR_STR2
3325 "Specify a local-as number\n"
3326 "AS number used as local AS\n"
3327 "Do not prepend local-as to updates from ebgp peers\n"
3328 "Do not prepend local-as to updates from ibgp peers\n")
3329{
d62a17ae 3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
9d3f9705 3335
d62a17ae 3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3339
d62a17ae 3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 1);
3342 return bgp_vty_return(vty, ret);
9d3f9705
AC
3343}
3344
718e3744 3345DEFUN (no_neighbor_local_as,
3346 no_neighbor_local_as_cmd,
a636c635 3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
a636c635
DW
3351 "Specify a local-as number\n"
3352 "AS number used as local AS\n"
3353 "Do not prepend local-as to updates from ebgp peers\n"
3354 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3355{
d62a17ae 3356 int idx_peer = 2;
3357 struct peer *peer;
3358 int ret;
718e3744 3359
d62a17ae 3360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3361 if (!peer)
3362 return CMD_WARNING_CONFIG_FAILED;
718e3744 3363
d62a17ae 3364 ret = peer_local_as_unset(peer);
3365 return bgp_vty_return(vty, ret);
718e3744 3366}
3367
718e3744 3368
3f9c7369
DS
3369DEFUN (neighbor_solo,
3370 neighbor_solo_cmd,
9ccf14f7 3371 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Solo peer - part of its own update group\n")
3375{
d62a17ae 3376 int idx_peer = 1;
3377 struct peer *peer;
3378 int ret;
3f9c7369 3379
d62a17ae 3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3383
d62a17ae 3384 ret = update_group_adjust_soloness(peer, 1);
3385 return bgp_vty_return(vty, ret);
3f9c7369
DS
3386}
3387
3388DEFUN (no_neighbor_solo,
3389 no_neighbor_solo_cmd,
9ccf14f7 3390 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3391 NO_STR
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Solo peer - part of its own update group\n")
3395{
d62a17ae 3396 int idx_peer = 2;
3397 struct peer *peer;
3398 int ret;
3f9c7369 3399
d62a17ae 3400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3403
d62a17ae 3404 ret = update_group_adjust_soloness(peer, 0);
3405 return bgp_vty_return(vty, ret);
3f9c7369
DS
3406}
3407
0df7c91f
PJ
3408DEFUN (neighbor_password,
3409 neighbor_password_cmd,
9ccf14f7 3410 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Set a password\n"
3414 "The password\n")
3415{
d62a17ae 3416 int idx_peer = 1;
3417 int idx_line = 3;
3418 struct peer *peer;
3419 int ret;
0df7c91f 3420
d62a17ae 3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3424
d62a17ae 3425 ret = peer_password_set(peer, argv[idx_line]->arg);
3426 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3427}
3428
3429DEFUN (no_neighbor_password,
3430 no_neighbor_password_cmd,
a636c635 3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3435 "Set a password\n"
3436 "The password\n")
0df7c91f 3437{
d62a17ae 3438 int idx_peer = 2;
3439 struct peer *peer;
3440 int ret;
0df7c91f 3441
d62a17ae 3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3445
d62a17ae 3446 ret = peer_password_unset(peer);
3447 return bgp_vty_return(vty, ret);
0df7c91f 3448}
6b0655a2 3449
718e3744 3450DEFUN (neighbor_activate,
3451 neighbor_activate_cmd,
9ccf14f7 3452 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3453 NEIGHBOR_STR
3454 NEIGHBOR_ADDR_STR2
3455 "Enable the Address Family for this Neighbor\n")
3456{
d62a17ae 3457 int idx_peer = 1;
3458 int ret;
3459 struct peer *peer;
718e3744 3460
d62a17ae 3461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3462 if (!peer)
3463 return CMD_WARNING_CONFIG_FAILED;
718e3744 3464
d62a17ae 3465 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3466 return bgp_vty_return(vty, ret);
718e3744 3467}
3468
d62a17ae 3469ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3472 "Enable the Address Family for this Neighbor\n")
596c17ba 3473
718e3744 3474DEFUN (no_neighbor_activate,
3475 no_neighbor_activate_cmd,
9ccf14f7 3476 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3477 NO_STR
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481{
d62a17ae 3482 int idx_peer = 2;
3483 int ret;
3484 struct peer *peer;
718e3744 3485
d62a17ae 3486 /* Lookup peer. */
3487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3488 if (!peer)
3489 return CMD_WARNING_CONFIG_FAILED;
718e3744 3490
d62a17ae 3491 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3492 return bgp_vty_return(vty, ret);
718e3744 3493}
6b0655a2 3494
d62a17ae 3495ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3498 "Enable the Address Family for this Neighbor\n")
596c17ba 3499
718e3744 3500DEFUN (neighbor_set_peer_group,
3501 neighbor_set_peer_group_cmd,
9ccf14f7 3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3503 NEIGHBOR_STR
a80beece 3504 NEIGHBOR_ADDR_STR2
718e3744 3505 "Member of the peer-group\n"
16cedbb0 3506 "Peer-group name\n")
718e3744 3507{
d62a17ae 3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
3509 int idx_peer = 1;
3510 int idx_word = 3;
3511 int ret;
3512 as_t as;
3513 union sockunion su;
3514 struct peer *peer;
3515 struct peer_group *group;
3516
d62a17ae 3517 ret = str2sockunion(argv[idx_peer]->arg, &su);
3518 if (ret < 0) {
3519 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3520 if (!peer) {
3521 vty_out(vty, "%% Malformed address or name: %s\n",
3522 argv[idx_peer]->arg);
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525 } else {
3526 if (peer_address_self_check(bgp, &su)) {
3527 vty_out(vty,
3528 "%% Can not configure the local system as neighbor\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 /* Disallow for dynamic neighbor. */
3533 peer = peer_lookup(bgp, &su);
3534 if (peer && peer_dynamic_neighbor(peer)) {
3535 vty_out(vty,
3536 "%% Operation not allowed on a dynamic neighbor\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539 }
3540
3541 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3542 if (!group) {
3543 vty_out(vty, "%% Configure the peer-group first\n");
3544 return CMD_WARNING_CONFIG_FAILED;
3545 }
3546
3547 ret = peer_group_bind(bgp, &su, peer, group, &as);
3548
3549 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3550 vty_out(vty,
3551 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3552 as);
3553 return CMD_WARNING_CONFIG_FAILED;
3554 }
3555
3556 return bgp_vty_return(vty, ret);
3557}
3558
3559ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3562 "Member of the peer-group\n"
3563 "Peer-group name\n")
596c17ba 3564
718e3744 3565DEFUN (no_neighbor_set_peer_group,
3566 no_neighbor_set_peer_group_cmd,
9ccf14f7 3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3568 NO_STR
3569 NEIGHBOR_STR
a80beece 3570 NEIGHBOR_ADDR_STR2
718e3744 3571 "Member of the peer-group\n"
16cedbb0 3572 "Peer-group name\n")
718e3744 3573{
d62a17ae 3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575 int idx_peer = 2;
3576 int idx_word = 4;
3577 int ret;
3578 struct peer *peer;
3579 struct peer_group *group;
3580
3581 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
718e3744 3590
827ed707 3591 ret = peer_delete(peer);
718e3744 3592
d62a17ae 3593 return bgp_vty_return(vty, ret);
718e3744 3594}
6b0655a2 3595
d62a17ae 3596ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
596c17ba 3601
d62a17ae 3602static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3603 uint32_t flag, int set)
718e3744 3604{
d62a17ae 3605 int ret;
3606 struct peer *peer;
718e3744 3607
d62a17ae 3608 peer = peer_and_group_lookup_vty(vty, ip_str);
3609 if (!peer)
3610 return CMD_WARNING_CONFIG_FAILED;
718e3744 3611
7ebe625c
QY
3612 /*
3613 * If 'neighbor <interface>', then this is for directly connected peers,
3614 * we should not accept disable-connected-check.
3615 */
3616 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3617 vty_out(vty,
3618 "%s is directly connected peer, cannot accept disable-"
3619 "connected-check\n",
3620 ip_str);
3621 return CMD_WARNING_CONFIG_FAILED;
3622 }
3623
d62a17ae 3624 if (!set && flag == PEER_FLAG_SHUTDOWN)
3625 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3626
d62a17ae 3627 if (set)
3628 ret = peer_flag_set(peer, flag);
3629 else
3630 ret = peer_flag_unset(peer, flag);
718e3744 3631
d62a17ae 3632 return bgp_vty_return(vty, ret);
718e3744 3633}
3634
47cbc09b 3635static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3636{
d62a17ae 3637 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3638}
3639
d62a17ae 3640static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3641 uint32_t flag)
718e3744 3642{
d62a17ae 3643 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3644}
3645
3646/* neighbor passive. */
3647DEFUN (neighbor_passive,
3648 neighbor_passive_cmd,
9ccf14f7 3649 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Don't send open messages to this neighbor\n")
3653{
d62a17ae 3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3656}
3657
3658DEFUN (no_neighbor_passive,
3659 no_neighbor_passive_cmd,
9ccf14f7 3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Don't send open messages to this neighbor\n")
3665{
d62a17ae 3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3668}
6b0655a2 3669
718e3744 3670/* neighbor shutdown. */
73d70fa6
DL
3671DEFUN (neighbor_shutdown_msg,
3672 neighbor_shutdown_msg_cmd,
3673 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3674 NEIGHBOR_STR
3675 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3676 "Administratively shut down this neighbor\n"
3677 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3678 "Shutdown message\n")
718e3744 3679{
d62a17ae 3680 int idx_peer = 1;
73d70fa6 3681
d62a17ae 3682 if (argc >= 5) {
3683 struct peer *peer =
3684 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3685 char *message;
73d70fa6 3686
d62a17ae 3687 if (!peer)
3688 return CMD_WARNING_CONFIG_FAILED;
3689 message = argv_concat(argv, argc, 4);
3690 peer_tx_shutdown_message_set(peer, message);
3691 XFREE(MTYPE_TMP, message);
3692 }
73d70fa6 3693
d62a17ae 3694 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3695}
3696
d62a17ae 3697ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Administratively shut down this neighbor\n")
73d70fa6
DL
3701
3702DEFUN (no_neighbor_shutdown_msg,
3703 no_neighbor_shutdown_msg_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Administratively shut down this neighbor\n"
3709 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3710 "Shutdown message\n")
718e3744 3711{
d62a17ae 3712 int idx_peer = 2;
73d70fa6 3713
d62a17ae 3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_SHUTDOWN);
718e3744 3716}
6b0655a2 3717
d62a17ae 3718ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3721 "Administratively shut down this neighbor\n")
73d70fa6 3722
718e3744 3723/* neighbor capability dynamic. */
3724DEFUN (neighbor_capability_dynamic,
3725 neighbor_capability_dynamic_cmd,
9ccf14f7 3726 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3727 NEIGHBOR_STR
3728 NEIGHBOR_ADDR_STR2
3729 "Advertise capability to the peer\n"
3730 "Advertise dynamic capability to this neighbor\n")
3731{
d62a17ae 3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3735}
3736
3737DEFUN (no_neighbor_capability_dynamic,
3738 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Advertise capability to the peer\n"
3744 "Advertise dynamic capability to this neighbor\n")
3745{
d62a17ae 3746 int idx_peer = 2;
3747 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3748 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3749}
6b0655a2 3750
718e3744 3751/* neighbor dont-capability-negotiate */
3752DEFUN (neighbor_dont_capability_negotiate,
3753 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3754 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Do not perform capability negotiation\n")
3758{
d62a17ae 3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_DONT_CAPABILITY);
718e3744 3762}
3763
3764DEFUN (no_neighbor_dont_capability_negotiate,
3765 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Do not perform capability negotiation\n")
3771{
d62a17ae 3772 int idx_peer = 2;
3773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3774 PEER_FLAG_DONT_CAPABILITY);
718e3744 3775}
6b0655a2 3776
8a92a8a0
DS
3777/* neighbor capability extended next hop encoding */
3778DEFUN (neighbor_capability_enhe,
3779 neighbor_capability_enhe_cmd,
9ccf14f7 3780 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3781 NEIGHBOR_STR
3782 NEIGHBOR_ADDR_STR2
3783 "Advertise capability to the peer\n"
3784 "Advertise extended next-hop capability to the peer\n")
3785{
d62a17ae 3786 int idx_peer = 1;
3787 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3788 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3789}
3790
3791DEFUN (no_neighbor_capability_enhe,
3792 no_neighbor_capability_enhe_cmd,
9ccf14f7 3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise extended next-hop capability to the peer\n")
3799{
d62a17ae 3800 int idx_peer = 2;
3801 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3803}
3804
d62a17ae 3805static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3806 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3807 int set)
718e3744 3808{
d62a17ae 3809 int ret;
3810 struct peer *peer;
718e3744 3811
d62a17ae 3812 peer = peer_and_group_lookup_vty(vty, peer_str);
3813 if (!peer)
3814 return CMD_WARNING_CONFIG_FAILED;
718e3744 3815
d62a17ae 3816 if (set)
3817 ret = peer_af_flag_set(peer, afi, safi, flag);
3818 else
3819 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3820
d62a17ae 3821 return bgp_vty_return(vty, ret);
718e3744 3822}
3823
d62a17ae 3824static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3825 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3826{
d62a17ae 3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3828}
3829
d62a17ae 3830static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3831 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3832{
d62a17ae 3833 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3834}
6b0655a2 3835
718e3744 3836/* neighbor capability orf prefix-list. */
3837DEFUN (neighbor_capability_orf_prefix,
3838 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3839 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Advertise capability to the peer\n"
3843 "Advertise ORF capability to the peer\n"
3844 "Advertise prefixlist ORF capability to this neighbor\n"
3845 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3846 "Capability to RECEIVE the ORF from this neighbor\n"
3847 "Capability to SEND the ORF to this neighbor\n")
3848{
d62a17ae 3849 int idx_peer = 1;
3850 int idx_send_recv = 5;
d7c0a89a 3851 uint16_t flag = 0;
d62a17ae 3852
3853 if (strmatch(argv[idx_send_recv]->text, "send"))
3854 flag = PEER_FLAG_ORF_PREFIX_SM;
3855 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3856 flag = PEER_FLAG_ORF_PREFIX_RM;
3857 else if (strmatch(argv[idx_send_recv]->text, "both"))
3858 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3859 else {
3860 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3861 return CMD_WARNING_CONFIG_FAILED;
3862 }
3863
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), flag);
3866}
3867
3868ALIAS_HIDDEN(
3869 neighbor_capability_orf_prefix,
3870 neighbor_capability_orf_prefix_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Advertise capability to the peer\n"
3874 "Advertise ORF capability to the peer\n"
3875 "Advertise prefixlist ORF capability to this neighbor\n"
3876 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3877 "Capability to RECEIVE the ORF from this neighbor\n"
3878 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3879
718e3744 3880DEFUN (no_neighbor_capability_orf_prefix,
3881 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3882 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892{
d62a17ae 3893 int idx_peer = 2;
3894 int idx_send_recv = 6;
d7c0a89a 3895 uint16_t flag = 0;
d62a17ae 3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3909 bgp_node_afi(vty), bgp_node_safi(vty),
3910 flag);
3911}
3912
3913ALIAS_HIDDEN(
3914 no_neighbor_capability_orf_prefix,
3915 no_neighbor_capability_orf_prefix_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Advertise capability to the peer\n"
3919 "Advertise ORF capability to the peer\n"
3920 "Advertise prefixlist ORF capability to this neighbor\n"
3921 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3922 "Capability to RECEIVE the ORF from this neighbor\n"
3923 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3924
718e3744 3925/* neighbor next-hop-self. */
3926DEFUN (neighbor_nexthop_self,
3927 neighbor_nexthop_self_cmd,
9ccf14f7 3928 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
a538debe 3931 "Disable the next hop calculation for this neighbor\n")
718e3744 3932{
d62a17ae 3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3936}
9e7a53c1 3937
d62a17ae 3938ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3939 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n")
596c17ba 3942
a538debe
DS
3943/* neighbor next-hop-self. */
3944DEFUN (neighbor_nexthop_self_force,
3945 neighbor_nexthop_self_force_cmd,
9ccf14f7 3946 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n"
3950 "Set the next hop to self for reflected routes\n")
3951{
d62a17ae 3952 int idx_peer = 1;
3953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3954 bgp_node_safi(vty),
3955 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3956}
3957
d62a17ae 3958ALIAS_HIDDEN(neighbor_nexthop_self_force,
3959 neighbor_nexthop_self_force_hidden_cmd,
3960 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Disable the next hop calculation for this neighbor\n"
3963 "Set the next hop to self for reflected routes\n")
596c17ba 3964
718e3744 3965DEFUN (no_neighbor_nexthop_self,
3966 no_neighbor_nexthop_self_cmd,
9ccf14f7 3967 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3968 NO_STR
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
a538debe 3971 "Disable the next hop calculation for this neighbor\n")
718e3744 3972{
d62a17ae 3973 int idx_peer = 2;
3974 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3975 bgp_node_afi(vty), bgp_node_safi(vty),
3976 PEER_FLAG_NEXTHOP_SELF);
718e3744 3977}
6b0655a2 3978
d62a17ae 3979ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3980 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3982 "Disable the next hop calculation for this neighbor\n")
596c17ba 3983
88b8ed8d 3984DEFUN (no_neighbor_nexthop_self_force,
a538debe 3985 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3986 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3987 NO_STR
3988 NEIGHBOR_STR
3989 NEIGHBOR_ADDR_STR2
3990 "Disable the next hop calculation for this neighbor\n"
3991 "Set the next hop to self for reflected routes\n")
88b8ed8d 3992{
d62a17ae 3993 int idx_peer = 2;
3994 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3995 bgp_node_afi(vty), bgp_node_safi(vty),
3996 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3997}
a538debe 3998
d62a17ae 3999ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4000 no_neighbor_nexthop_self_force_hidden_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4002 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4003 "Disable the next hop calculation for this neighbor\n"
4004 "Set the next hop to self for reflected routes\n")
596c17ba 4005
c7122e14
DS
4006/* neighbor as-override */
4007DEFUN (neighbor_as_override,
4008 neighbor_as_override_cmd,
9ccf14f7 4009 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4010 NEIGHBOR_STR
4011 NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
4013{
d62a17ae 4014 int idx_peer = 1;
4015 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4016 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4017}
4018
d62a17ae 4019ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4020 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4021 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4022 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4023
c7122e14
DS
4024DEFUN (no_neighbor_as_override,
4025 no_neighbor_as_override_cmd,
9ccf14f7 4026 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4027 NO_STR
4028 NEIGHBOR_STR
4029 NEIGHBOR_ADDR_STR2
4030 "Override ASNs in outbound updates if aspath equals remote-as\n")
4031{
d62a17ae 4032 int idx_peer = 2;
4033 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4034 bgp_node_afi(vty), bgp_node_safi(vty),
4035 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4036}
4037
d62a17ae 4038ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4039 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4041 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4042
718e3744 4043/* neighbor remove-private-AS. */
4044DEFUN (neighbor_remove_private_as,
4045 neighbor_remove_private_as_cmd,
9ccf14f7 4046 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4047 NEIGHBOR_STR
4048 NEIGHBOR_ADDR_STR2
5000f21c 4049 "Remove private ASNs in outbound updates\n")
718e3744 4050{
d62a17ae 4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4055}
4056
d62a17ae 4057ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4058 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4060 "Remove private ASNs in outbound updates\n")
596c17ba 4061
5000f21c
DS
4062DEFUN (neighbor_remove_private_as_all,
4063 neighbor_remove_private_as_all_cmd,
9ccf14f7 4064 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Remove private ASNs in outbound updates\n"
efd7904e 4068 "Apply to all AS numbers\n")
5000f21c 4069{
d62a17ae 4070 int idx_peer = 1;
4071 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4072 bgp_node_safi(vty),
4073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4074}
4075
d62a17ae 4076ALIAS_HIDDEN(neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_hidden_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers")
596c17ba 4082
5000f21c
DS
4083DEFUN (neighbor_remove_private_as_replace_as,
4084 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4085 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Remove private ASNs in outbound updates\n"
4089 "Replace private ASNs with our ASN in outbound updates\n")
4090{
d62a17ae 4091 int idx_peer = 1;
4092 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4093 bgp_node_safi(vty),
4094 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4095}
4096
d62a17ae 4097ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_hidden_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4100 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4101 "Remove private ASNs in outbound updates\n"
4102 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4103
5000f21c
DS
4104DEFUN (neighbor_remove_private_as_all_replace_as,
4105 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4106 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4107 NEIGHBOR_STR
4108 NEIGHBOR_ADDR_STR2
4109 "Remove private ASNs in outbound updates\n"
16cedbb0 4110 "Apply to all AS numbers\n"
5000f21c
DS
4111 "Replace private ASNs with our ASN in outbound updates\n")
4112{
d62a17ae 4113 int idx_peer = 1;
4114 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4115 bgp_node_safi(vty),
4116 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4117}
4118
d62a17ae 4119ALIAS_HIDDEN(
4120 neighbor_remove_private_as_all_replace_as,
4121 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4122 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4123 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4124 "Remove private ASNs in outbound updates\n"
4125 "Apply to all AS numbers\n"
4126 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4127
718e3744 4128DEFUN (no_neighbor_remove_private_as,
4129 no_neighbor_remove_private_as_cmd,
9ccf14f7 4130 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4131 NO_STR
4132 NEIGHBOR_STR
4133 NEIGHBOR_ADDR_STR2
5000f21c 4134 "Remove private ASNs in outbound updates\n")
718e3744 4135{
d62a17ae 4136 int idx_peer = 2;
4137 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4138 bgp_node_afi(vty), bgp_node_safi(vty),
4139 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4140}
6b0655a2 4141
d62a17ae 4142ALIAS_HIDDEN(no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_hidden_cmd,
4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4145 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Remove private ASNs in outbound updates\n")
596c17ba 4147
88b8ed8d 4148DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4149 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4150 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4151 NO_STR
4152 NEIGHBOR_STR
4153 NEIGHBOR_ADDR_STR2
4154 "Remove private ASNs in outbound updates\n"
16cedbb0 4155 "Apply to all AS numbers\n")
88b8ed8d 4156{
d62a17ae 4157 int idx_peer = 2;
4158 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4159 bgp_node_afi(vty), bgp_node_safi(vty),
4160 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4161}
5000f21c 4162
d62a17ae 4163ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4164 no_neighbor_remove_private_as_all_hidden_cmd,
4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4166 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4167 "Remove private ASNs in outbound updates\n"
4168 "Apply to all AS numbers\n")
596c17ba 4169
88b8ed8d 4170DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4171 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4172 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4173 NO_STR
4174 NEIGHBOR_STR
4175 NEIGHBOR_ADDR_STR2
4176 "Remove private ASNs in outbound updates\n"
4177 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4178{
d62a17ae 4179 int idx_peer = 2;
4180 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4181 bgp_node_afi(vty), bgp_node_safi(vty),
4182 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4183}
5000f21c 4184
d62a17ae 4185ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4186 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4187 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4188 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4189 "Remove private ASNs in outbound updates\n"
4190 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4191
88b8ed8d 4192DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4193 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4194 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4195 NO_STR
4196 NEIGHBOR_STR
4197 NEIGHBOR_ADDR_STR2
4198 "Remove private ASNs in outbound updates\n"
16cedbb0 4199 "Apply to all AS numbers\n"
5000f21c 4200 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4201{
d62a17ae 4202 int idx_peer = 2;
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4206}
5000f21c 4207
d62a17ae 4208ALIAS_HIDDEN(
4209 no_neighbor_remove_private_as_all_replace_as,
4210 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Remove private ASNs in outbound updates\n"
4214 "Apply to all AS numbers\n"
4215 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4216
5000f21c 4217
718e3744 4218/* neighbor send-community. */
4219DEFUN (neighbor_send_community,
4220 neighbor_send_community_cmd,
9ccf14f7 4221 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4222 NEIGHBOR_STR
4223 NEIGHBOR_ADDR_STR2
4224 "Send Community attribute to this neighbor\n")
4225{
d62a17ae 4226 int idx_peer = 1;
27c05d4d 4227
d62a17ae 4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty),
4230 PEER_FLAG_SEND_COMMUNITY);
718e3744 4231}
4232
d62a17ae 4233ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Send Community attribute to this neighbor\n")
596c17ba 4237
718e3744 4238DEFUN (no_neighbor_send_community,
4239 no_neighbor_send_community_cmd,
9ccf14f7 4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4241 NO_STR
4242 NEIGHBOR_STR
4243 NEIGHBOR_ADDR_STR2
4244 "Send Community attribute to this neighbor\n")
4245{
d62a17ae 4246 int idx_peer = 2;
27c05d4d 4247
d62a17ae 4248 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4249 bgp_node_afi(vty), bgp_node_safi(vty),
4250 PEER_FLAG_SEND_COMMUNITY);
718e3744 4251}
6b0655a2 4252
d62a17ae 4253ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4255 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4256 "Send Community attribute to this neighbor\n")
596c17ba 4257
718e3744 4258/* neighbor send-community extended. */
4259DEFUN (neighbor_send_community_type,
4260 neighbor_send_community_type_cmd,
57d187bc 4261 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4262 NEIGHBOR_STR
4263 NEIGHBOR_ADDR_STR2
4264 "Send Community attribute to this neighbor\n"
4265 "Send Standard and Extended Community attributes\n"
57d187bc 4266 "Send Standard, Large and Extended Community attributes\n"
718e3744 4267 "Send Extended Community attributes\n"
57d187bc
JS
4268 "Send Standard Community attributes\n"
4269 "Send Large Community attributes\n")
718e3744 4270{
27c05d4d 4271 int idx_peer = 1;
d7c0a89a 4272 uint32_t flag = 0;
27c05d4d 4273 const char *type = argv[argc - 1]->text;
d62a17ae 4274
27c05d4d 4275 if (strmatch(type, "standard")) {
d62a17ae 4276 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4277 } else if (strmatch(type, "extended")) {
d62a17ae 4278 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4279 } else if (strmatch(type, "large")) {
d62a17ae 4280 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4281 } else if (strmatch(type, "both")) {
d62a17ae 4282 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4283 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4284 } else { /* if (strmatch(type, "all")) */
d62a17ae 4285 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4286 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4287 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4288 }
4289
27c05d4d 4290 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4291 bgp_node_safi(vty), flag);
4292}
4293
4294ALIAS_HIDDEN(
4295 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4296 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4297 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4298 "Send Community attribute to this neighbor\n"
4299 "Send Standard and Extended Community attributes\n"
4300 "Send Standard, Large and Extended Community attributes\n"
4301 "Send Extended Community attributes\n"
4302 "Send Standard Community attributes\n"
4303 "Send Large Community attributes\n")
596c17ba 4304
718e3744 4305DEFUN (no_neighbor_send_community_type,
4306 no_neighbor_send_community_type_cmd,
57d187bc 4307 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4308 NO_STR
4309 NEIGHBOR_STR
4310 NEIGHBOR_ADDR_STR2
4311 "Send Community attribute to this neighbor\n"
4312 "Send Standard and Extended Community attributes\n"
57d187bc 4313 "Send Standard, Large and Extended Community attributes\n"
718e3744 4314 "Send Extended Community attributes\n"
57d187bc
JS
4315 "Send Standard Community attributes\n"
4316 "Send Large Community attributes\n")
718e3744 4317{
d62a17ae 4318 int idx_peer = 2;
27c05d4d 4319 uint32_t flag = 0;
d62a17ae 4320 const char *type = argv[argc - 1]->text;
4321
27c05d4d
PM
4322 if (strmatch(type, "standard")) {
4323 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4324 } else if (strmatch(type, "extended")) {
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 } else if (strmatch(type, "large")) {
4327 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4328 } else if (strmatch(type, "both")) {
4329 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4330 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4331 } else { /* if (strmatch(type, "all")) */
4332 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4333 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4334 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4335 }
4336
4337 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4338 bgp_node_afi(vty), bgp_node_safi(vty),
4339 flag);
d62a17ae 4340}
4341
4342ALIAS_HIDDEN(
4343 no_neighbor_send_community_type,
4344 no_neighbor_send_community_type_hidden_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4347 "Send Community attribute to this neighbor\n"
4348 "Send Standard and Extended Community attributes\n"
4349 "Send Standard, Large and Extended Community attributes\n"
4350 "Send Extended Community attributes\n"
4351 "Send Standard Community attributes\n"
4352 "Send Large Community attributes\n")
596c17ba 4353
718e3744 4354/* neighbor soft-reconfig. */
4355DEFUN (neighbor_soft_reconfiguration,
4356 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4357 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Per neighbor soft reconfiguration\n"
4361 "Allow inbound soft reconfiguration for this neighbor\n")
4362{
d62a17ae 4363 int idx_peer = 1;
4364 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4365 bgp_node_safi(vty),
4366 PEER_FLAG_SOFT_RECONFIG);
718e3744 4367}
4368
d62a17ae 4369ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_hidden_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4372 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4373 "Per neighbor soft reconfiguration\n"
4374 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4375
718e3744 4376DEFUN (no_neighbor_soft_reconfiguration,
4377 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4378 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4379 NO_STR
4380 NEIGHBOR_STR
4381 NEIGHBOR_ADDR_STR2
4382 "Per neighbor soft reconfiguration\n"
4383 "Allow inbound soft reconfiguration for this neighbor\n")
4384{
d62a17ae 4385 int idx_peer = 2;
4386 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4387 bgp_node_afi(vty), bgp_node_safi(vty),
4388 PEER_FLAG_SOFT_RECONFIG);
718e3744 4389}
6b0655a2 4390
d62a17ae 4391ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4392 no_neighbor_soft_reconfiguration_hidden_cmd,
4393 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4394 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4395 "Per neighbor soft reconfiguration\n"
4396 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4397
718e3744 4398DEFUN (neighbor_route_reflector_client,
4399 neighbor_route_reflector_client_cmd,
9ccf14f7 4400 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4401 NEIGHBOR_STR
4402 NEIGHBOR_ADDR_STR2
4403 "Configure a neighbor as Route Reflector client\n")
4404{
d62a17ae 4405 int idx_peer = 1;
4406 struct peer *peer;
718e3744 4407
4408
d62a17ae 4409 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4410 if (!peer)
4411 return CMD_WARNING_CONFIG_FAILED;
718e3744 4412
d62a17ae 4413 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4414 bgp_node_safi(vty),
4415 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4416}
4417
d62a17ae 4418ALIAS_HIDDEN(neighbor_route_reflector_client,
4419 neighbor_route_reflector_client_hidden_cmd,
4420 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4421 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4422 "Configure a neighbor as Route Reflector client\n")
596c17ba 4423
718e3744 4424DEFUN (no_neighbor_route_reflector_client,
4425 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4426 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4427 NO_STR
4428 NEIGHBOR_STR
4429 NEIGHBOR_ADDR_STR2
4430 "Configure a neighbor as Route Reflector client\n")
4431{
d62a17ae 4432 int idx_peer = 2;
4433 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4434 bgp_node_afi(vty), bgp_node_safi(vty),
4435 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4436}
6b0655a2 4437
d62a17ae 4438ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_hidden_cmd,
4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4441 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Reflector client\n")
596c17ba 4443
718e3744 4444/* neighbor route-server-client. */
4445DEFUN (neighbor_route_server_client,
4446 neighbor_route_server_client_cmd,
9ccf14f7 4447 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4448 NEIGHBOR_STR
4449 NEIGHBOR_ADDR_STR2
4450 "Configure a neighbor as Route Server client\n")
4451{
d62a17ae 4452 int idx_peer = 1;
4453 struct peer *peer;
2a3d5731 4454
d62a17ae 4455 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4456 if (!peer)
4457 return CMD_WARNING_CONFIG_FAILED;
4458 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4459 bgp_node_safi(vty),
4460 PEER_FLAG_RSERVER_CLIENT);
718e3744 4461}
4462
d62a17ae 4463ALIAS_HIDDEN(neighbor_route_server_client,
4464 neighbor_route_server_client_hidden_cmd,
4465 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4467 "Configure a neighbor as Route Server client\n")
596c17ba 4468
718e3744 4469DEFUN (no_neighbor_route_server_client,
4470 no_neighbor_route_server_client_cmd,
9ccf14f7 4471 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4472 NO_STR
4473 NEIGHBOR_STR
4474 NEIGHBOR_ADDR_STR2
4475 "Configure a neighbor as Route Server client\n")
fee0f4c6 4476{
d62a17ae 4477 int idx_peer = 2;
4478 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4479 bgp_node_afi(vty), bgp_node_safi(vty),
4480 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4481}
6b0655a2 4482
d62a17ae 4483ALIAS_HIDDEN(no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_hidden_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4487 "Configure a neighbor as Route Server client\n")
596c17ba 4488
fee0f4c6 4489DEFUN (neighbor_nexthop_local_unchanged,
4490 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4491 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "Configure treatment of outgoing link-local nexthop attribute\n"
4495 "Leave link-local nexthop unchanged for this peer\n")
4496{
d62a17ae 4497 int idx_peer = 1;
4498 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4499 bgp_node_safi(vty),
4500 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4501}
6b0655a2 4502
fee0f4c6 4503DEFUN (no_neighbor_nexthop_local_unchanged,
4504 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4505 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4506 NO_STR
4507 NEIGHBOR_STR
4508 NEIGHBOR_ADDR_STR2
4509 "Configure treatment of outgoing link-local-nexthop attribute\n"
4510 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4511{
d62a17ae 4512 int idx_peer = 2;
4513 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4514 bgp_node_afi(vty), bgp_node_safi(vty),
4515 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4516}
6b0655a2 4517
718e3744 4518DEFUN (neighbor_attr_unchanged,
4519 neighbor_attr_unchanged_cmd,
a8206004 4520 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "BGP attribute is propagated unchanged to this neighbor\n"
4524 "As-path attribute\n"
4525 "Nexthop attribute\n"
a8206004 4526 "Med attribute\n")
718e3744 4527{
d62a17ae 4528 int idx = 0;
8eeb0335
DW
4529 char *peer_str = argv[1]->arg;
4530 struct peer *peer;
d7c0a89a 4531 uint16_t flags = 0;
8eeb0335
DW
4532 afi_t afi = bgp_node_afi(vty);
4533 safi_t safi = bgp_node_safi(vty);
4534
4535 peer = peer_and_group_lookup_vty(vty, peer_str);
4536 if (!peer)
4537 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4538
4539 if (argv_find(argv, argc, "as-path", &idx))
4540 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4541 idx = 0;
4542 if (argv_find(argv, argc, "next-hop", &idx))
4543 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4544 idx = 0;
4545 if (argv_find(argv, argc, "med", &idx))
4546 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4547
8eeb0335
DW
4548 /* no flags means all of them! */
4549 if (!flags) {
d62a17ae 4550 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4551 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4552 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4553 } else {
a4d82a8a
PZ
4554 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4555 && peer_af_flag_check(peer, afi, safi,
4556 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4557 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4558 PEER_FLAG_AS_PATH_UNCHANGED);
4559 }
4560
a4d82a8a
PZ
4561 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4562 && peer_af_flag_check(peer, afi, safi,
4563 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4564 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4565 PEER_FLAG_NEXTHOP_UNCHANGED);
4566 }
4567
a4d82a8a
PZ
4568 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_MED_UNCHANGED);
4573 }
d62a17ae 4574 }
4575
8eeb0335 4576 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4577}
4578
4579ALIAS_HIDDEN(
4580 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4581 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4582 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4583 "BGP attribute is propagated unchanged to this neighbor\n"
4584 "As-path attribute\n"
4585 "Nexthop attribute\n"
4586 "Med attribute\n")
596c17ba 4587
718e3744 4588DEFUN (no_neighbor_attr_unchanged,
4589 no_neighbor_attr_unchanged_cmd,
a8206004 4590 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4591 NO_STR
718e3744 4592 NEIGHBOR_STR
4593 NEIGHBOR_ADDR_STR2
31500417
DW
4594 "BGP attribute is propagated unchanged to this neighbor\n"
4595 "As-path attribute\n"
40e718b5 4596 "Nexthop attribute\n"
a8206004 4597 "Med attribute\n")
718e3744 4598{
d62a17ae 4599 int idx = 0;
4600 char *peer = argv[2]->arg;
d7c0a89a 4601 uint16_t flags = 0;
d62a17ae 4602
4603 if (argv_find(argv, argc, "as-path", &idx))
4604 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4605 idx = 0;
4606 if (argv_find(argv, argc, "next-hop", &idx))
4607 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4608 idx = 0;
4609 if (argv_find(argv, argc, "med", &idx))
4610 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4611
4612 if (!flags) // no flags means all of them!
4613 {
4614 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4615 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4616 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4617 }
4618
4619 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4620 bgp_node_safi(vty), flags);
4621}
4622
4623ALIAS_HIDDEN(
4624 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4625 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4627 "BGP attribute is propagated unchanged to this neighbor\n"
4628 "As-path attribute\n"
4629 "Nexthop attribute\n"
4630 "Med attribute\n")
718e3744 4631
718e3744 4632/* EBGP multihop configuration. */
d62a17ae 4633static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4634 const char *ttl_str)
718e3744 4635{
d62a17ae 4636 struct peer *peer;
4637 unsigned int ttl;
718e3744 4638
d62a17ae 4639 peer = peer_and_group_lookup_vty(vty, ip_str);
4640 if (!peer)
4641 return CMD_WARNING_CONFIG_FAILED;
718e3744 4642
d62a17ae 4643 if (peer->conf_if)
4644 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4645
d62a17ae 4646 if (!ttl_str)
4647 ttl = MAXTTL;
4648 else
4649 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4650
d62a17ae 4651 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4652}
4653
d62a17ae 4654static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4655{
d62a17ae 4656 struct peer *peer;
718e3744 4657
d62a17ae 4658 peer = peer_and_group_lookup_vty(vty, ip_str);
4659 if (!peer)
4660 return CMD_WARNING_CONFIG_FAILED;
718e3744 4661
d62a17ae 4662 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4663}
4664
4665/* neighbor ebgp-multihop. */
4666DEFUN (neighbor_ebgp_multihop,
4667 neighbor_ebgp_multihop_cmd,
9ccf14f7 4668 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4669 NEIGHBOR_STR
4670 NEIGHBOR_ADDR_STR2
4671 "Allow EBGP neighbors not on directly connected networks\n")
4672{
d62a17ae 4673 int idx_peer = 1;
4674 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4675}
4676
4677DEFUN (neighbor_ebgp_multihop_ttl,
4678 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4679 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Allow EBGP neighbors not on directly connected networks\n"
4683 "maximum hop count\n")
4684{
d62a17ae 4685 int idx_peer = 1;
4686 int idx_number = 3;
4687 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4688 argv[idx_number]->arg);
718e3744 4689}
4690
4691DEFUN (no_neighbor_ebgp_multihop,
4692 no_neighbor_ebgp_multihop_cmd,
a636c635 4693 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4694 NO_STR
4695 NEIGHBOR_STR
4696 NEIGHBOR_ADDR_STR2
a636c635
DW
4697 "Allow EBGP neighbors not on directly connected networks\n"
4698 "maximum hop count\n")
718e3744 4699{
d62a17ae 4700 int idx_peer = 2;
4701 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4702}
4703
6b0655a2 4704
6ffd2079 4705/* disable-connected-check */
4706DEFUN (neighbor_disable_connected_check,
4707 neighbor_disable_connected_check_cmd,
7ebe625c 4708 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4709 NEIGHBOR_STR
7ebe625c 4710 NEIGHBOR_ADDR_STR2
a636c635
DW
4711 "one-hop away EBGP peer using loopback address\n"
4712 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4713{
d62a17ae 4714 int idx_peer = 1;
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4717}
4718
4719DEFUN (no_neighbor_disable_connected_check,
4720 no_neighbor_disable_connected_check_cmd,
7ebe625c 4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4722 NO_STR
4723 NEIGHBOR_STR
7ebe625c 4724 NEIGHBOR_ADDR_STR2
a636c635
DW
4725 "one-hop away EBGP peer using loopback address\n"
4726 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4727{
d62a17ae 4728 int idx_peer = 2;
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4731}
4732
47cbc09b
PM
4733
4734/* enforce-first-as */
4735DEFUN (neighbor_enforce_first_as,
4736 neighbor_enforce_first_as_cmd,
4737 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Enforce the first AS for EBGP routes\n")
4741{
4742 int idx_peer = 1;
4743
4744 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4745 PEER_FLAG_ENFORCE_FIRST_AS);
4746}
4747
4748DEFUN (no_neighbor_enforce_first_as,
4749 no_neighbor_enforce_first_as_cmd,
4750 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4751 NO_STR
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755{
4756 int idx_peer = 2;
4757
4758 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760}
4761
4762
718e3744 4763DEFUN (neighbor_description,
4764 neighbor_description_cmd,
e961923c 4765 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Neighbor specific description\n"
4769 "Up to 80 characters describing this neighbor\n")
4770{
d62a17ae 4771 int idx_peer = 1;
4772 int idx_line = 3;
4773 struct peer *peer;
4774 char *str;
718e3744 4775
d62a17ae 4776 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4777 if (!peer)
4778 return CMD_WARNING_CONFIG_FAILED;
718e3744 4779
d62a17ae 4780 str = argv_concat(argv, argc, idx_line);
718e3744 4781
d62a17ae 4782 peer_description_set(peer, str);
718e3744 4783
d62a17ae 4784 XFREE(MTYPE_TMP, str);
718e3744 4785
d62a17ae 4786 return CMD_SUCCESS;
718e3744 4787}
4788
4789DEFUN (no_neighbor_description,
4790 no_neighbor_description_cmd,
a14810f4 4791 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4792 NO_STR
4793 NEIGHBOR_STR
4794 NEIGHBOR_ADDR_STR2
a14810f4 4795 "Neighbor specific description\n")
718e3744 4796{
d62a17ae 4797 int idx_peer = 2;
4798 struct peer *peer;
718e3744 4799
d62a17ae 4800 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4801 if (!peer)
4802 return CMD_WARNING_CONFIG_FAILED;
718e3744 4803
d62a17ae 4804 peer_description_unset(peer);
718e3744 4805
d62a17ae 4806 return CMD_SUCCESS;
718e3744 4807}
4808
a14810f4
PM
4809ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4811 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4812 "Neighbor specific description\n"
4813 "Up to 80 characters describing this neighbor\n")
6b0655a2 4814
718e3744 4815/* Neighbor update-source. */
d62a17ae 4816static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4817 const char *source_str)
4818{
4819 struct peer *peer;
4820 struct prefix p;
a14810f4 4821 union sockunion su;
d62a17ae 4822
4823 peer = peer_and_group_lookup_vty(vty, peer_str);
4824 if (!peer)
4825 return CMD_WARNING_CONFIG_FAILED;
4826
4827 if (peer->conf_if)
4828 return CMD_WARNING;
4829
4830 if (source_str) {
a14810f4 4831 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4832 peer_update_source_addr_set(peer, &su);
4833 else {
4834 if (str2prefix(source_str, &p)) {
4835 vty_out(vty,
4836 "%% Invalid update-source, remove prefix length \n");
4837 return CMD_WARNING_CONFIG_FAILED;
4838 } else
4839 peer_update_source_if_set(peer, source_str);
4840 }
4841 } else
4842 peer_update_source_unset(peer);
4843
4844 return CMD_SUCCESS;
4845}
4846
4847#define BGP_UPDATE_SOURCE_HELP_STR \
4848 "IPv4 address\n" \
4849 "IPv6 address\n" \
4850 "Interface name (requires zebra to be running)\n"
369688c0 4851
718e3744 4852DEFUN (neighbor_update_source,
4853 neighbor_update_source_cmd,
9ccf14f7 4854 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Source of routing updates\n"
369688c0 4858 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4859{
d62a17ae 4860 int idx_peer = 1;
4861 int idx_peer_2 = 3;
4862 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4863 argv[idx_peer_2]->arg);
718e3744 4864}
4865
4866DEFUN (no_neighbor_update_source,
4867 no_neighbor_update_source_cmd,
c7178fe7 4868 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4869 NO_STR
4870 NEIGHBOR_STR
4871 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4872 "Source of routing updates\n"
4873 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4874{
d62a17ae 4875 int idx_peer = 2;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4877}
6b0655a2 4878
d62a17ae 4879static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4880 afi_t afi, safi_t safi,
4881 const char *rmap, int set)
718e3744 4882{
d62a17ae 4883 int ret;
4884 struct peer *peer;
1de27621 4885 struct route_map *route_map;
718e3744 4886
d62a17ae 4887 peer = peer_and_group_lookup_vty(vty, peer_str);
4888 if (!peer)
4889 return CMD_WARNING_CONFIG_FAILED;
718e3744 4890
1de27621
DA
4891 if (set) {
4892 route_map = route_map_lookup_warn_noexist(vty, rmap);
4893 ret = peer_default_originate_set(peer, afi, safi,
4894 rmap, route_map);
4895 } else
d62a17ae 4896 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4897
d62a17ae 4898 return bgp_vty_return(vty, ret);
718e3744 4899}
4900
4901/* neighbor default-originate. */
4902DEFUN (neighbor_default_originate,
4903 neighbor_default_originate_cmd,
9ccf14f7 4904 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Originate default route to this neighbor\n")
4908{
d62a17ae 4909 int idx_peer = 1;
4910 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4911 bgp_node_afi(vty),
4912 bgp_node_safi(vty), NULL, 1);
718e3744 4913}
4914
d62a17ae 4915ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Originate default route to this neighbor\n")
596c17ba 4919
718e3744 4920DEFUN (neighbor_default_originate_rmap,
4921 neighbor_default_originate_rmap_cmd,
9ccf14f7 4922 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4923 NEIGHBOR_STR
4924 NEIGHBOR_ADDR_STR2
4925 "Originate default route to this neighbor\n"
4926 "Route-map to specify criteria to originate default\n"
4927 "route-map name\n")
4928{
d62a17ae 4929 int idx_peer = 1;
4930 int idx_word = 4;
4931 return peer_default_originate_set_vty(
4932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4933 argv[idx_word]->arg, 1);
718e3744 4934}
4935
d62a17ae 4936ALIAS_HIDDEN(
4937 neighbor_default_originate_rmap,
4938 neighbor_default_originate_rmap_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Originate default route to this neighbor\n"
4942 "Route-map to specify criteria to originate default\n"
4943 "route-map name\n")
596c17ba 4944
718e3744 4945DEFUN (no_neighbor_default_originate,
4946 no_neighbor_default_originate_cmd,
a636c635 4947 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4948 NO_STR
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
a636c635
DW
4951 "Originate default route to this neighbor\n"
4952 "Route-map to specify criteria to originate default\n"
4953 "route-map name\n")
718e3744 4954{
d62a17ae 4955 int idx_peer = 2;
4956 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4957 bgp_node_afi(vty),
4958 bgp_node_safi(vty), NULL, 0);
718e3744 4959}
4960
d62a17ae 4961ALIAS_HIDDEN(
4962 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
596c17ba 4968
6b0655a2 4969
718e3744 4970/* Set neighbor's BGP port. */
d62a17ae 4971static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4972 const char *port_str)
4973{
4974 struct peer *peer;
d7c0a89a 4975 uint16_t port;
d62a17ae 4976 struct servent *sp;
4977
4978 peer = peer_lookup_vty(vty, ip_str);
4979 if (!peer)
4980 return CMD_WARNING_CONFIG_FAILED;
4981
4982 if (!port_str) {
4983 sp = getservbyname("bgp", "tcp");
4984 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4985 } else {
4986 port = strtoul(port_str, NULL, 10);
4987 }
718e3744 4988
d62a17ae 4989 peer_port_set(peer, port);
718e3744 4990
d62a17ae 4991 return CMD_SUCCESS;
718e3744 4992}
4993
f418446b 4994/* Set specified peer's BGP port. */
718e3744 4995DEFUN (neighbor_port,
4996 neighbor_port_cmd,
9ccf14f7 4997 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR
5000 "Neighbor's BGP port\n"
5001 "TCP port number\n")
5002{
d62a17ae 5003 int idx_ip = 1;
5004 int idx_number = 3;
5005 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5006 argv[idx_number]->arg);
718e3744 5007}
5008
5009DEFUN (no_neighbor_port,
5010 no_neighbor_port_cmd,
9ccf14f7 5011 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5012 NO_STR
5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
8334fd5a
DW
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
718e3744 5017{
d62a17ae 5018 int idx_ip = 2;
5019 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5020}
5021
6b0655a2 5022
718e3744 5023/* neighbor weight. */
d62a17ae 5024static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5025 safi_t safi, const char *weight_str)
718e3744 5026{
d62a17ae 5027 int ret;
5028 struct peer *peer;
5029 unsigned long weight;
718e3744 5030
d62a17ae 5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
718e3744 5034
d62a17ae 5035 weight = strtoul(weight_str, NULL, 10);
718e3744 5036
d62a17ae 5037 ret = peer_weight_set(peer, afi, safi, weight);
5038 return bgp_vty_return(vty, ret);
718e3744 5039}
5040
d62a17ae 5041static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5042 safi_t safi)
718e3744 5043{
d62a17ae 5044 int ret;
5045 struct peer *peer;
718e3744 5046
d62a17ae 5047 peer = peer_and_group_lookup_vty(vty, ip_str);
5048 if (!peer)
5049 return CMD_WARNING_CONFIG_FAILED;
718e3744 5050
d62a17ae 5051 ret = peer_weight_unset(peer, afi, safi);
5052 return bgp_vty_return(vty, ret);
718e3744 5053}
5054
5055DEFUN (neighbor_weight,
5056 neighbor_weight_cmd,
9ccf14f7 5057 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Set default weight for routes from this neighbor\n"
5061 "default weight\n")
5062{
d62a17ae 5063 int idx_peer = 1;
5064 int idx_number = 3;
5065 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5066 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5067}
5068
d62a17ae 5069ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5070 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5072 "Set default weight for routes from this neighbor\n"
5073 "default weight\n")
596c17ba 5074
718e3744 5075DEFUN (no_neighbor_weight,
5076 no_neighbor_weight_cmd,
9ccf14f7 5077 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5078 NO_STR
5079 NEIGHBOR_STR
5080 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5081 "Set default weight for routes from this neighbor\n"
5082 "default weight\n")
718e3744 5083{
d62a17ae 5084 int idx_peer = 2;
5085 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5086 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5087}
5088
d62a17ae 5089ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5090 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5091 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5092 "Set default weight for routes from this neighbor\n"
5093 "default weight\n")
596c17ba 5094
6b0655a2 5095
718e3744 5096/* Override capability negotiation. */
5097DEFUN (neighbor_override_capability,
5098 neighbor_override_capability_cmd,
9ccf14f7 5099 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Override capability negotiation result\n")
5103{
d62a17ae 5104 int idx_peer = 1;
5105 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5106 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5107}
5108
5109DEFUN (no_neighbor_override_capability,
5110 no_neighbor_override_capability_cmd,
9ccf14f7 5111 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5112 NO_STR
5113 NEIGHBOR_STR
5114 NEIGHBOR_ADDR_STR2
5115 "Override capability negotiation result\n")
5116{
d62a17ae 5117 int idx_peer = 2;
5118 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5119 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5120}
6b0655a2 5121
718e3744 5122DEFUN (neighbor_strict_capability,
5123 neighbor_strict_capability_cmd,
9fb964de 5124 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5125 NEIGHBOR_STR
9fb964de 5126 NEIGHBOR_ADDR_STR2
718e3744 5127 "Strict capability negotiation match\n")
5128{
9fb964de
PM
5129 int idx_peer = 1;
5130
5131 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5132 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5133}
5134
5135DEFUN (no_neighbor_strict_capability,
5136 no_neighbor_strict_capability_cmd,
9fb964de 5137 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5138 NO_STR
5139 NEIGHBOR_STR
9fb964de 5140 NEIGHBOR_ADDR_STR2
718e3744 5141 "Strict capability negotiation match\n")
5142{
9fb964de
PM
5143 int idx_peer = 2;
5144
5145 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5146 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5147}
6b0655a2 5148
d62a17ae 5149static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5150 const char *keep_str, const char *hold_str)
718e3744 5151{
d62a17ae 5152 int ret;
5153 struct peer *peer;
d7c0a89a
QY
5154 uint32_t keepalive;
5155 uint32_t holdtime;
718e3744 5156
d62a17ae 5157 peer = peer_and_group_lookup_vty(vty, ip_str);
5158 if (!peer)
5159 return CMD_WARNING_CONFIG_FAILED;
718e3744 5160
d62a17ae 5161 keepalive = strtoul(keep_str, NULL, 10);
5162 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5163
d62a17ae 5164 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5165
d62a17ae 5166 return bgp_vty_return(vty, ret);
718e3744 5167}
6b0655a2 5168
d62a17ae 5169static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5170{
d62a17ae 5171 int ret;
5172 struct peer *peer;
718e3744 5173
d62a17ae 5174 peer = peer_and_group_lookup_vty(vty, ip_str);
5175 if (!peer)
5176 return CMD_WARNING_CONFIG_FAILED;
718e3744 5177
d62a17ae 5178 ret = peer_timers_unset(peer);
718e3744 5179
d62a17ae 5180 return bgp_vty_return(vty, ret);
718e3744 5181}
5182
5183DEFUN (neighbor_timers,
5184 neighbor_timers_cmd,
9ccf14f7 5185 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR2
5188 "BGP per neighbor timers\n"
5189 "Keepalive interval\n"
5190 "Holdtime\n")
5191{
d62a17ae 5192 int idx_peer = 1;
5193 int idx_number = 3;
5194 int idx_number_2 = 4;
5195 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5196 argv[idx_number]->arg,
5197 argv[idx_number_2]->arg);
718e3744 5198}
5199
5200DEFUN (no_neighbor_timers,
5201 no_neighbor_timers_cmd,
9ccf14f7 5202 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5203 NO_STR
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5206 "BGP per neighbor timers\n"
5207 "Keepalive interval\n"
5208 "Holdtime\n")
718e3744 5209{
d62a17ae 5210 int idx_peer = 2;
5211 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5212}
6b0655a2 5213
813d4307 5214
d62a17ae 5215static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5216 const char *time_str)
718e3744 5217{
d62a17ae 5218 int ret;
5219 struct peer *peer;
d7c0a89a 5220 uint32_t connect;
718e3744 5221
d62a17ae 5222 peer = peer_and_group_lookup_vty(vty, ip_str);
5223 if (!peer)
5224 return CMD_WARNING_CONFIG_FAILED;
718e3744 5225
d62a17ae 5226 connect = strtoul(time_str, NULL, 10);
718e3744 5227
d62a17ae 5228 ret = peer_timers_connect_set(peer, connect);
718e3744 5229
d62a17ae 5230 return bgp_vty_return(vty, ret);
718e3744 5231}
5232
d62a17ae 5233static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5234{
d62a17ae 5235 int ret;
5236 struct peer *peer;
718e3744 5237
d62a17ae 5238 peer = peer_and_group_lookup_vty(vty, ip_str);
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
718e3744 5241
d62a17ae 5242 ret = peer_timers_connect_unset(peer);
718e3744 5243
d62a17ae 5244 return bgp_vty_return(vty, ret);
718e3744 5245}
5246
5247DEFUN (neighbor_timers_connect,
5248 neighbor_timers_connect_cmd,
9ccf14f7 5249 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5250 NEIGHBOR_STR
966f821c 5251 NEIGHBOR_ADDR_STR2
718e3744 5252 "BGP per neighbor timers\n"
5253 "BGP connect timer\n"
5254 "Connect timer\n")
5255{
d62a17ae 5256 int idx_peer = 1;
5257 int idx_number = 4;
5258 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5259 argv[idx_number]->arg);
718e3744 5260}
5261
5262DEFUN (no_neighbor_timers_connect,
5263 no_neighbor_timers_connect_cmd,
9ccf14f7 5264 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5265 NO_STR
5266 NEIGHBOR_STR
966f821c 5267 NEIGHBOR_ADDR_STR2
718e3744 5268 "BGP per neighbor timers\n"
8334fd5a
DW
5269 "BGP connect timer\n"
5270 "Connect timer\n")
718e3744 5271{
d62a17ae 5272 int idx_peer = 2;
5273 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5274}
5275
6b0655a2 5276
d62a17ae 5277static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5278 const char *time_str, int set)
718e3744 5279{
d62a17ae 5280 int ret;
5281 struct peer *peer;
d7c0a89a 5282 uint32_t routeadv = 0;
718e3744 5283
d62a17ae 5284 peer = peer_and_group_lookup_vty(vty, ip_str);
5285 if (!peer)
5286 return CMD_WARNING_CONFIG_FAILED;
718e3744 5287
d62a17ae 5288 if (time_str)
5289 routeadv = strtoul(time_str, NULL, 10);
718e3744 5290
d62a17ae 5291 if (set)
5292 ret = peer_advertise_interval_set(peer, routeadv);
5293 else
5294 ret = peer_advertise_interval_unset(peer);
718e3744 5295
d62a17ae 5296 return bgp_vty_return(vty, ret);
718e3744 5297}
5298
5299DEFUN (neighbor_advertise_interval,
5300 neighbor_advertise_interval_cmd,
9ccf14f7 5301 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5302 NEIGHBOR_STR
966f821c 5303 NEIGHBOR_ADDR_STR2
718e3744 5304 "Minimum interval between sending BGP routing updates\n"
5305 "time in seconds\n")
5306{
d62a17ae 5307 int idx_peer = 1;
5308 int idx_number = 3;
5309 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5310 argv[idx_number]->arg, 1);
718e3744 5311}
5312
5313DEFUN (no_neighbor_advertise_interval,
5314 no_neighbor_advertise_interval_cmd,
9ccf14f7 5315 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5316 NO_STR
5317 NEIGHBOR_STR
966f821c 5318 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
718e3744 5321{
d62a17ae 5322 int idx_peer = 2;
5323 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5324}
5325
6b0655a2 5326
518f0eb1
DS
5327/* Time to wait before processing route-map updates */
5328DEFUN (bgp_set_route_map_delay_timer,
5329 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5330 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5331 SET_STR
5332 "BGP route-map delay timer\n"
5333 "Time in secs to wait before processing route-map changes\n"
f414725f 5334 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5335{
d62a17ae 5336 int idx_number = 3;
d7c0a89a 5337 uint32_t rmap_delay_timer;
d62a17ae 5338
5339 if (argv[idx_number]->arg) {
5340 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5341 bm->rmap_update_timer = rmap_delay_timer;
5342
5343 /* if the dynamic update handling is being disabled, and a timer
5344 * is
5345 * running, stop the timer and act as if the timer has already
5346 * fired.
5347 */
5348 if (!rmap_delay_timer && bm->t_rmap_update) {
5349 BGP_TIMER_OFF(bm->t_rmap_update);
5350 thread_execute(bm->master, bgp_route_map_update_timer,
5351 NULL, 0);
5352 }
5353 return CMD_SUCCESS;
5354 } else {
5355 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5356 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5357 }
518f0eb1
DS
5358}
5359
5360DEFUN (no_bgp_set_route_map_delay_timer,
5361 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5362 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5363 NO_STR
3a2d747c 5364 BGP_STR
518f0eb1 5365 "Default BGP route-map delay timer\n"
8334fd5a
DW
5366 "Reset to default time to wait for processing route-map changes\n"
5367 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5368{
518f0eb1 5369
d62a17ae 5370 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5371
d62a17ae 5372 return CMD_SUCCESS;
518f0eb1
DS
5373}
5374
f414725f 5375
718e3744 5376/* neighbor interface */
d62a17ae 5377static int peer_interface_vty(struct vty *vty, const char *ip_str,
5378 const char *str)
718e3744 5379{
d62a17ae 5380 struct peer *peer;
718e3744 5381
d62a17ae 5382 peer = peer_lookup_vty(vty, ip_str);
5383 if (!peer || peer->conf_if) {
5384 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5385 return CMD_WARNING_CONFIG_FAILED;
5386 }
718e3744 5387
d62a17ae 5388 if (str)
5389 peer_interface_set(peer, str);
5390 else
5391 peer_interface_unset(peer);
718e3744 5392
d62a17ae 5393 return CMD_SUCCESS;
718e3744 5394}
5395
5396DEFUN (neighbor_interface,
5397 neighbor_interface_cmd,
9ccf14f7 5398 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR
5401 "Interface\n"
5402 "Interface name\n")
5403{
d62a17ae 5404 int idx_ip = 1;
5405 int idx_word = 3;
5406 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5407}
5408
5409DEFUN (no_neighbor_interface,
5410 no_neighbor_interface_cmd,
9ccf14f7 5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5412 NO_STR
5413 NEIGHBOR_STR
16cedbb0 5414 NEIGHBOR_ADDR_STR2
718e3744 5415 "Interface\n"
5416 "Interface name\n")
5417{
d62a17ae 5418 int idx_peer = 2;
5419 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5420}
6b0655a2 5421
718e3744 5422DEFUN (neighbor_distribute_list,
5423 neighbor_distribute_list_cmd,
9ccf14f7 5424 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Filter updates to/from this neighbor\n"
5428 "IP access-list number\n"
5429 "IP access-list number (expanded range)\n"
5430 "IP Access-list name\n"
5431 "Filter incoming updates\n"
5432 "Filter outgoing updates\n")
5433{
d62a17ae 5434 int idx_peer = 1;
5435 int idx_acl = 3;
5436 int direct, ret;
5437 struct peer *peer;
a8206004 5438
d62a17ae 5439 const char *pstr = argv[idx_peer]->arg;
5440 const char *acl = argv[idx_acl]->arg;
5441 const char *inout = argv[argc - 1]->text;
a8206004 5442
d62a17ae 5443 peer = peer_and_group_lookup_vty(vty, pstr);
5444 if (!peer)
5445 return CMD_WARNING_CONFIG_FAILED;
a8206004 5446
d62a17ae 5447 /* Check filter direction. */
5448 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5449 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5450 direct, acl);
a8206004 5451
d62a17ae 5452 return bgp_vty_return(vty, ret);
718e3744 5453}
5454
d62a17ae 5455ALIAS_HIDDEN(
5456 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Filter updates to/from this neighbor\n"
5460 "IP access-list number\n"
5461 "IP access-list number (expanded range)\n"
5462 "IP Access-list name\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
596c17ba 5465
718e3744 5466DEFUN (no_neighbor_distribute_list,
5467 no_neighbor_distribute_list_cmd,
9ccf14f7 5468 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5469 NO_STR
5470 NEIGHBOR_STR
5471 NEIGHBOR_ADDR_STR2
5472 "Filter updates to/from this neighbor\n"
5473 "IP access-list number\n"
5474 "IP access-list number (expanded range)\n"
5475 "IP Access-list name\n"
5476 "Filter incoming updates\n"
5477 "Filter outgoing updates\n")
5478{
d62a17ae 5479 int idx_peer = 2;
5480 int direct, ret;
5481 struct peer *peer;
a8206004 5482
d62a17ae 5483 const char *pstr = argv[idx_peer]->arg;
5484 const char *inout = argv[argc - 1]->text;
a8206004 5485
d62a17ae 5486 peer = peer_and_group_lookup_vty(vty, pstr);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
a8206004 5489
d62a17ae 5490 /* Check filter direction. */
5491 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5492 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5493 direct);
a8206004 5494
d62a17ae 5495 return bgp_vty_return(vty, ret);
718e3744 5496}
6b0655a2 5497
d62a17ae 5498ALIAS_HIDDEN(
5499 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5500 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Filter updates to/from this neighbor\n"
5503 "IP access-list number\n"
5504 "IP access-list number (expanded range)\n"
5505 "IP Access-list name\n"
5506 "Filter incoming updates\n"
5507 "Filter outgoing updates\n")
596c17ba 5508
718e3744 5509/* Set prefix list to the peer. */
d62a17ae 5510static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5511 afi_t afi, safi_t safi,
5512 const char *name_str,
5513 const char *direct_str)
718e3744 5514{
d62a17ae 5515 int ret;
d62a17ae 5516 int direct = FILTER_IN;
cf9ac8bf 5517 struct peer *peer;
718e3744 5518
d62a17ae 5519 peer = peer_and_group_lookup_vty(vty, ip_str);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
718e3744 5522
d62a17ae 5523 /* Check filter direction. */
5524 if (strncmp(direct_str, "i", 1) == 0)
5525 direct = FILTER_IN;
5526 else if (strncmp(direct_str, "o", 1) == 0)
5527 direct = FILTER_OUT;
718e3744 5528
d62a17ae 5529 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5530
d62a17ae 5531 return bgp_vty_return(vty, ret);
718e3744 5532}
5533
d62a17ae 5534static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5535 afi_t afi, safi_t safi,
5536 const char *direct_str)
718e3744 5537{
d62a17ae 5538 int ret;
5539 struct peer *peer;
5540 int direct = FILTER_IN;
718e3744 5541
d62a17ae 5542 peer = peer_and_group_lookup_vty(vty, ip_str);
5543 if (!peer)
5544 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5545
d62a17ae 5546 /* Check filter direction. */
5547 if (strncmp(direct_str, "i", 1) == 0)
5548 direct = FILTER_IN;
5549 else if (strncmp(direct_str, "o", 1) == 0)
5550 direct = FILTER_OUT;
718e3744 5551
d62a17ae 5552 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5553
d62a17ae 5554 return bgp_vty_return(vty, ret);
718e3744 5555}
5556
5557DEFUN (neighbor_prefix_list,
5558 neighbor_prefix_list_cmd,
9ccf14f7 5559 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Filter updates to/from this neighbor\n"
5563 "Name of a prefix list\n"
5564 "Filter incoming updates\n"
5565 "Filter outgoing updates\n")
5566{
d62a17ae 5567 int idx_peer = 1;
5568 int idx_word = 3;
5569 int idx_in_out = 4;
5570 return peer_prefix_list_set_vty(
5571 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5572 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5573}
5574
d62a17ae 5575ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Filter updates to/from this neighbor\n"
5579 "Name of a prefix list\n"
5580 "Filter incoming updates\n"
5581 "Filter outgoing updates\n")
596c17ba 5582
718e3744 5583DEFUN (no_neighbor_prefix_list,
5584 no_neighbor_prefix_list_cmd,
9ccf14f7 5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5586 NO_STR
5587 NEIGHBOR_STR
5588 NEIGHBOR_ADDR_STR2
5589 "Filter updates to/from this neighbor\n"
5590 "Name of a prefix list\n"
5591 "Filter incoming updates\n"
5592 "Filter outgoing updates\n")
5593{
d62a17ae 5594 int idx_peer = 2;
5595 int idx_in_out = 5;
5596 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5597 bgp_node_afi(vty), bgp_node_safi(vty),
5598 argv[idx_in_out]->arg);
718e3744 5599}
6b0655a2 5600
d62a17ae 5601ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Filter updates to/from this neighbor\n"
5605 "Name of a prefix list\n"
5606 "Filter incoming updates\n"
5607 "Filter outgoing updates\n")
596c17ba 5608
d62a17ae 5609static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5610 safi_t safi, const char *name_str,
5611 const char *direct_str)
718e3744 5612{
d62a17ae 5613 int ret;
5614 struct peer *peer;
5615 int direct = FILTER_IN;
718e3744 5616
d62a17ae 5617 peer = peer_and_group_lookup_vty(vty, ip_str);
5618 if (!peer)
5619 return CMD_WARNING_CONFIG_FAILED;
718e3744 5620
d62a17ae 5621 /* Check filter direction. */
5622 if (strncmp(direct_str, "i", 1) == 0)
5623 direct = FILTER_IN;
5624 else if (strncmp(direct_str, "o", 1) == 0)
5625 direct = FILTER_OUT;
718e3744 5626
d62a17ae 5627 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5628
d62a17ae 5629 return bgp_vty_return(vty, ret);
718e3744 5630}
5631
d62a17ae 5632static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5633 safi_t safi, const char *direct_str)
718e3744 5634{
d62a17ae 5635 int ret;
5636 struct peer *peer;
5637 int direct = FILTER_IN;
718e3744 5638
d62a17ae 5639 peer = peer_and_group_lookup_vty(vty, ip_str);
5640 if (!peer)
5641 return CMD_WARNING_CONFIG_FAILED;
718e3744 5642
d62a17ae 5643 /* Check filter direction. */
5644 if (strncmp(direct_str, "i", 1) == 0)
5645 direct = FILTER_IN;
5646 else if (strncmp(direct_str, "o", 1) == 0)
5647 direct = FILTER_OUT;
718e3744 5648
d62a17ae 5649 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5650
d62a17ae 5651 return bgp_vty_return(vty, ret);
718e3744 5652}
5653
5654DEFUN (neighbor_filter_list,
5655 neighbor_filter_list_cmd,
9ccf14f7 5656 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Establish BGP filters\n"
5660 "AS path access-list name\n"
5661 "Filter incoming routes\n"
5662 "Filter outgoing routes\n")
5663{
d62a17ae 5664 int idx_peer = 1;
5665 int idx_word = 3;
5666 int idx_in_out = 4;
5667 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5668 bgp_node_safi(vty), argv[idx_word]->arg,
5669 argv[idx_in_out]->arg);
718e3744 5670}
5671
d62a17ae 5672ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5673 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5675 "Establish BGP filters\n"
5676 "AS path access-list name\n"
5677 "Filter incoming routes\n"
5678 "Filter outgoing routes\n")
596c17ba 5679
718e3744 5680DEFUN (no_neighbor_filter_list,
5681 no_neighbor_filter_list_cmd,
9ccf14f7 5682 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5683 NO_STR
5684 NEIGHBOR_STR
5685 NEIGHBOR_ADDR_STR2
5686 "Establish BGP filters\n"
5687 "AS path access-list name\n"
5688 "Filter incoming routes\n"
5689 "Filter outgoing routes\n")
5690{
d62a17ae 5691 int idx_peer = 2;
5692 int idx_in_out = 5;
5693 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5694 bgp_node_afi(vty), bgp_node_safi(vty),
5695 argv[idx_in_out]->arg);
718e3744 5696}
6b0655a2 5697
d62a17ae 5698ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5699 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5700 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5701 "Establish BGP filters\n"
5702 "AS path access-list name\n"
5703 "Filter incoming routes\n"
5704 "Filter outgoing routes\n")
596c17ba 5705
718e3744 5706/* Set route-map to the peer. */
d62a17ae 5707static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5708 afi_t afi, safi_t safi, const char *name_str,
5709 const char *direct_str)
718e3744 5710{
d62a17ae 5711 int ret;
5712 struct peer *peer;
5713 int direct = RMAP_IN;
1de27621 5714 struct route_map *route_map;
718e3744 5715
d62a17ae 5716 peer = peer_and_group_lookup_vty(vty, ip_str);
5717 if (!peer)
5718 return CMD_WARNING_CONFIG_FAILED;
718e3744 5719
d62a17ae 5720 /* Check filter direction. */
5721 if (strncmp(direct_str, "in", 2) == 0)
5722 direct = RMAP_IN;
5723 else if (strncmp(direct_str, "o", 1) == 0)
5724 direct = RMAP_OUT;
718e3744 5725
1de27621
DA
5726 route_map = route_map_lookup_warn_noexist(vty, name_str);
5727 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5728
d62a17ae 5729 return bgp_vty_return(vty, ret);
718e3744 5730}
5731
d62a17ae 5732static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5733 afi_t afi, safi_t safi,
5734 const char *direct_str)
718e3744 5735{
d62a17ae 5736 int ret;
5737 struct peer *peer;
5738 int direct = RMAP_IN;
718e3744 5739
d62a17ae 5740 peer = peer_and_group_lookup_vty(vty, ip_str);
5741 if (!peer)
5742 return CMD_WARNING_CONFIG_FAILED;
718e3744 5743
d62a17ae 5744 /* Check filter direction. */
5745 if (strncmp(direct_str, "in", 2) == 0)
5746 direct = RMAP_IN;
5747 else if (strncmp(direct_str, "o", 1) == 0)
5748 direct = RMAP_OUT;
718e3744 5749
d62a17ae 5750 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5751
d62a17ae 5752 return bgp_vty_return(vty, ret);
718e3744 5753}
5754
5755DEFUN (neighbor_route_map,
5756 neighbor_route_map_cmd,
9ccf14f7 5757 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Apply route map to neighbor\n"
5761 "Name of route map\n"
5762 "Apply map to incoming routes\n"
2a3d5731 5763 "Apply map to outbound routes\n")
718e3744 5764{
d62a17ae 5765 int idx_peer = 1;
5766 int idx_word = 3;
5767 int idx_in_out = 4;
5768 return peer_route_map_set_vty(
5769 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5770 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5771}
5772
d62a17ae 5773ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5775 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5776 "Apply route map to neighbor\n"
5777 "Name of route map\n"
5778 "Apply map to incoming routes\n"
5779 "Apply map to outbound routes\n")
596c17ba 5780
718e3744 5781DEFUN (no_neighbor_route_map,
5782 no_neighbor_route_map_cmd,
9ccf14f7 5783 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5784 NO_STR
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
5787 "Apply route map to neighbor\n"
5788 "Name of route map\n"
5789 "Apply map to incoming routes\n"
2a3d5731 5790 "Apply map to outbound routes\n")
718e3744 5791{
d62a17ae 5792 int idx_peer = 2;
5793 int idx_in_out = 5;
5794 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5795 bgp_node_afi(vty), bgp_node_safi(vty),
5796 argv[idx_in_out]->arg);
718e3744 5797}
6b0655a2 5798
d62a17ae 5799ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5800 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
5805 "Apply map to outbound routes\n")
596c17ba 5806
718e3744 5807/* Set unsuppress-map to the peer. */
d62a17ae 5808static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5809 afi_t afi, safi_t safi,
5810 const char *name_str)
718e3744 5811{
d62a17ae 5812 int ret;
5813 struct peer *peer;
1de27621 5814 struct route_map *route_map;
718e3744 5815
d62a17ae 5816 peer = peer_and_group_lookup_vty(vty, ip_str);
5817 if (!peer)
5818 return CMD_WARNING_CONFIG_FAILED;
718e3744 5819
1de27621
DA
5820 route_map = route_map_lookup_warn_noexist(vty, name_str);
5821 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5822
d62a17ae 5823 return bgp_vty_return(vty, ret);
718e3744 5824}
5825
5826/* Unset route-map from the peer. */
d62a17ae 5827static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5828 afi_t afi, safi_t safi)
718e3744 5829{
d62a17ae 5830 int ret;
5831 struct peer *peer;
718e3744 5832
d62a17ae 5833 peer = peer_and_group_lookup_vty(vty, ip_str);
5834 if (!peer)
5835 return CMD_WARNING_CONFIG_FAILED;
718e3744 5836
d62a17ae 5837 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5838
d62a17ae 5839 return bgp_vty_return(vty, ret);
718e3744 5840}
5841
5842DEFUN (neighbor_unsuppress_map,
5843 neighbor_unsuppress_map_cmd,
9ccf14f7 5844 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Route-map to selectively unsuppress suppressed routes\n"
5848 "Name of route map\n")
5849{
d62a17ae 5850 int idx_peer = 1;
5851 int idx_word = 3;
5852 return peer_unsuppress_map_set_vty(
5853 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5854 argv[idx_word]->arg);
718e3744 5855}
5856
d62a17ae 5857ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5859 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Route-map to selectively unsuppress suppressed routes\n"
5861 "Name of route map\n")
596c17ba 5862
718e3744 5863DEFUN (no_neighbor_unsuppress_map,
5864 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5865 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5866 NO_STR
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Route-map to selectively unsuppress suppressed routes\n"
5870 "Name of route map\n")
5871{
d62a17ae 5872 int idx_peer = 2;
5873 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5874 bgp_node_afi(vty),
5875 bgp_node_safi(vty));
718e3744 5876}
6b0655a2 5877
d62a17ae 5878ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5879 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5880 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5881 "Route-map to selectively unsuppress suppressed routes\n"
5882 "Name of route map\n")
596c17ba 5883
d62a17ae 5884static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi,
5886 const char *num_str,
5887 const char *threshold_str, int warning,
5888 const char *restart_str)
718e3744 5889{
d62a17ae 5890 int ret;
5891 struct peer *peer;
d7c0a89a
QY
5892 uint32_t max;
5893 uint8_t threshold;
5894 uint16_t restart;
718e3744 5895
d62a17ae 5896 peer = peer_and_group_lookup_vty(vty, ip_str);
5897 if (!peer)
5898 return CMD_WARNING_CONFIG_FAILED;
718e3744 5899
d62a17ae 5900 max = strtoul(num_str, NULL, 10);
5901 if (threshold_str)
5902 threshold = atoi(threshold_str);
5903 else
5904 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5905
d62a17ae 5906 if (restart_str)
5907 restart = atoi(restart_str);
5908 else
5909 restart = 0;
0a486e5f 5910
d62a17ae 5911 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5912 restart);
718e3744 5913
d62a17ae 5914 return bgp_vty_return(vty, ret);
718e3744 5915}
5916
d62a17ae 5917static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5918 afi_t afi, safi_t safi)
718e3744 5919{
d62a17ae 5920 int ret;
5921 struct peer *peer;
718e3744 5922
d62a17ae 5923 peer = peer_and_group_lookup_vty(vty, ip_str);
5924 if (!peer)
5925 return CMD_WARNING_CONFIG_FAILED;
718e3744 5926
d62a17ae 5927 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5928
d62a17ae 5929 return bgp_vty_return(vty, ret);
718e3744 5930}
5931
5932/* Maximum number of prefix configuration. prefix count is different
5933 for each peer configuration. So this configuration can be set for
5934 each peer configuration. */
5935DEFUN (neighbor_maximum_prefix,
5936 neighbor_maximum_prefix_cmd,
9ccf14f7 5937 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Maximum number of prefix accept from this peer\n"
5941 "maximum no. of prefix limit\n")
5942{
d62a17ae 5943 int idx_peer = 1;
5944 int idx_number = 3;
5945 return peer_maximum_prefix_set_vty(
5946 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5947 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5948}
5949
d62a17ae 5950ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5952 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Maximum number of prefix accept from this peer\n"
5954 "maximum no. of prefix limit\n")
596c17ba 5955
e0701b79 5956DEFUN (neighbor_maximum_prefix_threshold,
5957 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5958 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5959 NEIGHBOR_STR
5960 NEIGHBOR_ADDR_STR2
5961 "Maximum number of prefix accept from this peer\n"
5962 "maximum no. of prefix limit\n"
5963 "Threshold value (%) at which to generate a warning msg\n")
5964{
d62a17ae 5965 int idx_peer = 1;
5966 int idx_number = 3;
5967 int idx_number_2 = 4;
5968 return peer_maximum_prefix_set_vty(
5969 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5970 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5971}
e0701b79 5972
d62a17ae 5973ALIAS_HIDDEN(
5974 neighbor_maximum_prefix_threshold,
5975 neighbor_maximum_prefix_threshold_hidden_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5977 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5978 "Maximum number of prefix accept from this peer\n"
5979 "maximum no. of prefix limit\n"
5980 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5981
718e3744 5982DEFUN (neighbor_maximum_prefix_warning,
5983 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5984 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Maximum number of prefix accept from this peer\n"
5988 "maximum no. of prefix limit\n"
5989 "Only give warning message when limit is exceeded\n")
5990{
d62a17ae 5991 int idx_peer = 1;
5992 int idx_number = 3;
5993 return peer_maximum_prefix_set_vty(
5994 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5995 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5996}
5997
d62a17ae 5998ALIAS_HIDDEN(
5999 neighbor_maximum_prefix_warning,
6000 neighbor_maximum_prefix_warning_hidden_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefix accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Only give warning message when limit is exceeded\n")
596c17ba 6006
e0701b79 6007DEFUN (neighbor_maximum_prefix_threshold_warning,
6008 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6009 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6010 NEIGHBOR_STR
6011 NEIGHBOR_ADDR_STR2
6012 "Maximum number of prefix accept from this peer\n"
6013 "maximum no. of prefix limit\n"
6014 "Threshold value (%) at which to generate a warning msg\n"
6015 "Only give warning message when limit is exceeded\n")
6016{
d62a17ae 6017 int idx_peer = 1;
6018 int idx_number = 3;
6019 int idx_number_2 = 4;
6020 return peer_maximum_prefix_set_vty(
6021 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6022 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6023}
6024
d62a17ae 6025ALIAS_HIDDEN(
6026 neighbor_maximum_prefix_threshold_warning,
6027 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6028 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6030 "Maximum number of prefix accept from this peer\n"
6031 "maximum no. of prefix limit\n"
6032 "Threshold value (%) at which to generate a warning msg\n"
6033 "Only give warning message when limit is exceeded\n")
596c17ba 6034
0a486e5f 6035DEFUN (neighbor_maximum_prefix_restart,
6036 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "Maximum number of prefix accept from this peer\n"
6041 "maximum no. of prefix limit\n"
6042 "Restart bgp connection after limit is exceeded\n"
efd7904e 6043 "Restart interval in minutes\n")
0a486e5f 6044{
d62a17ae 6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 5;
6048 return peer_maximum_prefix_set_vty(
6049 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6050 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6051}
6052
d62a17ae 6053ALIAS_HIDDEN(
6054 neighbor_maximum_prefix_restart,
6055 neighbor_maximum_prefix_restart_hidden_cmd,
6056 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 "Maximum number of prefix accept from this peer\n"
6059 "maximum no. of prefix limit\n"
6060 "Restart bgp connection after limit is exceeded\n"
efd7904e 6061 "Restart interval in minutes\n")
596c17ba 6062
0a486e5f 6063DEFUN (neighbor_maximum_prefix_threshold_restart,
6064 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6065 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
16cedbb0 6068 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 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")
0a486e5f 6073{
d62a17ae 6074 int idx_peer = 1;
6075 int idx_number = 3;
6076 int idx_number_2 = 4;
6077 int idx_number_3 = 6;
6078 return peer_maximum_prefix_set_vty(
6079 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6080 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6081 argv[idx_number_3]->arg);
6082}
6083
6084ALIAS_HIDDEN(
6085 neighbor_maximum_prefix_threshold_restart,
6086 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n")
596c17ba 6094
718e3744 6095DEFUN (no_neighbor_maximum_prefix,
6096 no_neighbor_maximum_prefix_cmd,
d04c479d 6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
16cedbb0 6101 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6102 "maximum no. of prefix limit\n"
6103 "Threshold value (%) at which to generate a warning msg\n"
6104 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6105 "Restart interval in minutes\n"
31500417 6106 "Only give warning message when limit is exceeded\n")
718e3744 6107{
d62a17ae 6108 int idx_peer = 2;
6109 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6110 bgp_node_afi(vty),
6111 bgp_node_safi(vty));
718e3744 6112}
e52702f2 6113
d62a17ae 6114ALIAS_HIDDEN(
6115 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6117 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Maximum number of prefixes to accept from this peer\n"
6119 "maximum no. of prefix limit\n"
6120 "Threshold value (%) at which to generate a warning msg\n"
6121 "Restart bgp connection after limit is exceeded\n"
6122 "Restart interval in minutes\n"
6123 "Only give warning message when limit is exceeded\n")
596c17ba 6124
718e3744 6125
718e3744 6126/* "neighbor allowas-in" */
6127DEFUN (neighbor_allowas_in,
6128 neighbor_allowas_in_cmd,
fd8503f5 6129 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
31500417 6132 "Accept as-path with my AS present in it\n"
0437e105 6133 "Number of occurences of AS number\n"
fd8503f5 6134 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6135{
d62a17ae 6136 int idx_peer = 1;
6137 int idx_number_origin = 3;
6138 int ret;
6139 int origin = 0;
6140 struct peer *peer;
6141 int allow_num = 0;
6142
6143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6144 if (!peer)
6145 return CMD_WARNING_CONFIG_FAILED;
6146
6147 if (argc <= idx_number_origin)
6148 allow_num = 3;
6149 else {
6150 if (argv[idx_number_origin]->type == WORD_TKN)
6151 origin = 1;
6152 else
6153 allow_num = atoi(argv[idx_number_origin]->arg);
6154 }
6155
6156 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6157 allow_num, origin);
6158
6159 return bgp_vty_return(vty, ret);
6160}
6161
6162ALIAS_HIDDEN(
6163 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6164 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6166 "Accept as-path with my AS present in it\n"
0437e105 6167 "Number of occurences of AS number\n"
d62a17ae 6168 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6169
718e3744 6170DEFUN (no_neighbor_allowas_in,
6171 no_neighbor_allowas_in_cmd,
fd8503f5 6172 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6173 NO_STR
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
8334fd5a 6176 "allow local ASN appears in aspath attribute\n"
0437e105 6177 "Number of occurences of AS number\n"
fd8503f5 6178 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6179{
d62a17ae 6180 int idx_peer = 2;
6181 int ret;
6182 struct peer *peer;
718e3744 6183
d62a17ae 6184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6185 if (!peer)
6186 return CMD_WARNING_CONFIG_FAILED;
718e3744 6187
d62a17ae 6188 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6189 bgp_node_safi(vty));
718e3744 6190
d62a17ae 6191 return bgp_vty_return(vty, ret);
718e3744 6192}
6b0655a2 6193
d62a17ae 6194ALIAS_HIDDEN(
6195 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6196 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6197 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6198 "allow local ASN appears in aspath attribute\n"
0437e105 6199 "Number of occurences of AS number\n"
d62a17ae 6200 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6201
fa411a21
NH
6202DEFUN (neighbor_ttl_security,
6203 neighbor_ttl_security_cmd,
7ebe625c 6204 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6205 NEIGHBOR_STR
7ebe625c 6206 NEIGHBOR_ADDR_STR2
16cedbb0 6207 "BGP ttl-security parameters\n"
d7fa34c1
QY
6208 "Specify the maximum number of hops to the BGP peer\n"
6209 "Number of hops to BGP peer\n")
fa411a21 6210{
d62a17ae 6211 int idx_peer = 1;
6212 int idx_number = 4;
6213 struct peer *peer;
6214 int gtsm_hops;
6215
6216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
6219
6220 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6221
7ebe625c
QY
6222 /*
6223 * If 'neighbor swpX', then this is for directly connected peers,
6224 * we should not accept a ttl-security hops value greater than 1.
6225 */
6226 if (peer->conf_if && (gtsm_hops > 1)) {
6227 vty_out(vty,
6228 "%s is directly connected peer, hops cannot exceed 1\n",
6229 argv[idx_peer]->arg);
6230 return CMD_WARNING_CONFIG_FAILED;
6231 }
6232
d62a17ae 6233 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6234}
6235
6236DEFUN (no_neighbor_ttl_security,
6237 no_neighbor_ttl_security_cmd,
7ebe625c 6238 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6239 NO_STR
6240 NEIGHBOR_STR
7ebe625c 6241 NEIGHBOR_ADDR_STR2
16cedbb0 6242 "BGP ttl-security parameters\n"
3a2d747c
QY
6243 "Specify the maximum number of hops to the BGP peer\n"
6244 "Number of hops to BGP peer\n")
fa411a21 6245{
d62a17ae 6246 int idx_peer = 2;
6247 struct peer *peer;
fa411a21 6248
d62a17ae 6249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6250 if (!peer)
6251 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6252
d62a17ae 6253 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6254}
6b0655a2 6255
adbac85e
DW
6256DEFUN (neighbor_addpath_tx_all_paths,
6257 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6258 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6259 NEIGHBOR_STR
6260 NEIGHBOR_ADDR_STR2
6261 "Use addpath to advertise all paths to a neighbor\n")
6262{
d62a17ae 6263 int idx_peer = 1;
6264 struct peer *peer;
adbac85e 6265
d62a17ae 6266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6267 if (!peer)
6268 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6269
dcc68b5e
MS
6270 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6271 BGP_ADDPATH_ALL);
6272 return CMD_SUCCESS;
adbac85e
DW
6273}
6274
d62a17ae 6275ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6276 neighbor_addpath_tx_all_paths_hidden_cmd,
6277 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6279 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6280
adbac85e
DW
6281DEFUN (no_neighbor_addpath_tx_all_paths,
6282 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6283 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6284 NO_STR
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Use addpath to advertise all paths to a neighbor\n")
6288{
d62a17ae 6289 int idx_peer = 2;
dcc68b5e
MS
6290 struct peer *peer;
6291
6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6297 != BGP_ADDPATH_ALL) {
6298 vty_out(vty,
6299 "%% Peer not currently configured to transmit all paths.");
6300 return CMD_WARNING_CONFIG_FAILED;
6301 }
6302
6303 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6304 BGP_ADDPATH_NONE);
6305
6306 return CMD_SUCCESS;
adbac85e
DW
6307}
6308
d62a17ae 6309ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6310 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6313 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6314
06370dac
DW
6315DEFUN (neighbor_addpath_tx_bestpath_per_as,
6316 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise the bestpath per each neighboring AS\n")
6321{
d62a17ae 6322 int idx_peer = 1;
6323 struct peer *peer;
06370dac 6324
d62a17ae 6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
06370dac 6328
dcc68b5e
MS
6329 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6330 BGP_ADDPATH_BEST_PER_AS);
6331
6332 return CMD_SUCCESS;
06370dac
DW
6333}
6334
d62a17ae 6335ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6336 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6337 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6339 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6340
06370dac
DW
6341DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6342 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6343 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6344 NO_STR
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Use addpath to advertise the bestpath per each neighboring AS\n")
6348{
d62a17ae 6349 int idx_peer = 2;
dcc68b5e
MS
6350 struct peer *peer;
6351
6352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6353 if (!peer)
6354 return CMD_WARNING_CONFIG_FAILED;
6355
6356 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6357 != BGP_ADDPATH_BEST_PER_AS) {
6358 vty_out(vty,
6359 "%% Peer not currently configured to transmit all best path per as.");
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
6362
6363 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6364 BGP_ADDPATH_NONE);
6365
6366 return CMD_SUCCESS;
06370dac
DW
6367}
6368
d62a17ae 6369ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6370 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6371 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6372 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6373 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6374
b9c7bc5a
PZ
6375static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6376 struct ecommunity **list)
ddb5b488 6377{
b9c7bc5a
PZ
6378 struct ecommunity *ecom = NULL;
6379 struct ecommunity *ecomadd;
ddb5b488 6380
b9c7bc5a 6381 for (; argc; --argc, ++argv) {
ddb5b488 6382
b9c7bc5a
PZ
6383 ecomadd = ecommunity_str2com(argv[0]->arg,
6384 ECOMMUNITY_ROUTE_TARGET, 0);
6385 if (!ecomadd) {
6386 vty_out(vty, "Malformed community-list value\n");
6387 if (ecom)
6388 ecommunity_free(&ecom);
6389 return CMD_WARNING_CONFIG_FAILED;
6390 }
ddb5b488 6391
b9c7bc5a
PZ
6392 if (ecom) {
6393 ecommunity_merge(ecom, ecomadd);
6394 ecommunity_free(&ecomadd);
6395 } else {
6396 ecom = ecomadd;
6397 }
6398 }
6399
6400 if (*list) {
6401 ecommunity_free(&*list);
ddb5b488 6402 }
b9c7bc5a
PZ
6403 *list = ecom;
6404
6405 return CMD_SUCCESS;
ddb5b488
PZ
6406}
6407
0ca70ba5
DS
6408/*
6409 * v2vimport is true if we are handling a `import vrf ...` command
6410 */
6411static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6412{
0ca70ba5
DS
6413 afi_t afi;
6414
ddb5b488 6415 switch (vty->node) {
b9c7bc5a 6416 case BGP_IPV4_NODE:
0ca70ba5
DS
6417 afi = AFI_IP;
6418 break;
b9c7bc5a 6419 case BGP_IPV6_NODE:
0ca70ba5
DS
6420 afi = AFI_IP6;
6421 break;
ddb5b488
PZ
6422 default:
6423 vty_out(vty,
b9c7bc5a 6424 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6425 return AFI_MAX;
ddb5b488 6426 }
69b07479 6427
0ca70ba5
DS
6428 if (!v2vimport) {
6429 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6430 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6431 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6432 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6433 vty_out(vty,
6434 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6435 return AFI_MAX;
6436 }
6437 } else {
6438 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6439 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6440 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6441 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6442 vty_out(vty,
6443 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6444 return AFI_MAX;
6445 }
6446 }
6447 return afi;
ddb5b488
PZ
6448}
6449
b9c7bc5a
PZ
6450DEFPY (af_rd_vpn_export,
6451 af_rd_vpn_export_cmd,
6452 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6453 NO_STR
ddb5b488 6454 "Specify route distinguisher\n"
b9c7bc5a
PZ
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6457 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6458{
6459 VTY_DECLVAR_CONTEXT(bgp, bgp);
6460 struct prefix_rd prd;
6461 int ret;
ddb5b488 6462 afi_t afi;
b9c7bc5a
PZ
6463 int idx = 0;
6464 int yes = 1;
ddb5b488 6465
b9c7bc5a 6466 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6467 yes = 0;
b9c7bc5a
PZ
6468
6469 if (yes) {
6470 ret = str2prefix_rd(rd_str, &prd);
6471 if (!ret) {
6472 vty_out(vty, "%% Malformed rd\n");
6473 return CMD_WARNING_CONFIG_FAILED;
6474 }
ddb5b488
PZ
6475 }
6476
0ca70ba5 6477 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6478 if (afi == AFI_MAX)
6479 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6480
69b07479
DS
6481 /*
6482 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6483 */
6484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6485 bgp_get_default(), bgp);
ddb5b488 6486
69b07479
DS
6487 if (yes) {
6488 bgp->vpn_policy[afi].tovpn_rd = prd;
6489 SET_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_RD_SET);
6491 } else {
6492 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6493 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6494 }
6495
69b07479
DS
6496 /* post-change: re-export vpn routes */
6497 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6498 bgp_get_default(), bgp);
6499
ddb5b488
PZ
6500 return CMD_SUCCESS;
6501}
6502
b9c7bc5a
PZ
6503ALIAS (af_rd_vpn_export,
6504 af_no_rd_vpn_export_cmd,
6505 "no rd vpn export",
ddb5b488 6506 NO_STR
b9c7bc5a
PZ
6507 "Specify route distinguisher\n"
6508 "Between current address-family and vpn\n"
6509 "For routes leaked from current address-family to vpn\n")
ddb5b488 6510
b9c7bc5a
PZ
6511DEFPY (af_label_vpn_export,
6512 af_label_vpn_export_cmd,
e70e9f8e 6513 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6514 NO_STR
ddb5b488 6515 "label value for VRF\n"
b9c7bc5a
PZ
6516 "Between current address-family and vpn\n"
6517 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6518 "Label Value <0-1048575>\n"
6519 "Automatically assign a label\n")
ddb5b488
PZ
6520{
6521 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6522 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6523 afi_t afi;
b9c7bc5a
PZ
6524 int idx = 0;
6525 int yes = 1;
6526
6527 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6528 yes = 0;
ddb5b488 6529
21a16cc2
PZ
6530 /* If "no ...", squash trailing parameter */
6531 if (!yes)
6532 label_auto = NULL;
6533
e70e9f8e
PZ
6534 if (yes) {
6535 if (!label_auto)
6536 label = label_val; /* parser should force unsigned */
6537 }
ddb5b488 6538
0ca70ba5 6539 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6540 if (afi == AFI_MAX)
6541 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6542
e70e9f8e 6543
69b07479
DS
6544 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6545 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6546 /* no change */
6547 return CMD_SUCCESS;
e70e9f8e 6548
69b07479
DS
6549 /*
6550 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6551 */
6552 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6553 bgp_get_default(), bgp);
6554
6555 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6556 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6557
6558 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6559
6560 /*
6561 * label has previously been automatically
6562 * assigned by labelpool: release it
6563 *
6564 * NB if tovpn_label == MPLS_LABEL_NONE it
6565 * means the automatic assignment is in flight
6566 * and therefore the labelpool callback must
6567 * detect that the auto label is not needed.
6568 */
6569
6570 bgp_lp_release(LP_TYPE_VRF,
6571 &bgp->vpn_policy[afi],
6572 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6573 }
69b07479
DS
6574 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6575 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6576 }
ddb5b488 6577
69b07479
DS
6578 bgp->vpn_policy[afi].tovpn_label = label;
6579 if (label_auto) {
6580 SET_FLAG(bgp->vpn_policy[afi].flags,
6581 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6582 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6583 vpn_leak_label_callback);
ddb5b488
PZ
6584 }
6585
69b07479
DS
6586 /* post-change: re-export vpn routes */
6587 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6588 bgp_get_default(), bgp);
6589
ddb5b488
PZ
6590 return CMD_SUCCESS;
6591}
6592
b9c7bc5a
PZ
6593ALIAS (af_label_vpn_export,
6594 af_no_label_vpn_export_cmd,
6595 "no label vpn export",
6596 NO_STR
6597 "label value for VRF\n"
6598 "Between current address-family and vpn\n"
6599 "For routes leaked from current address-family to vpn\n")
ddb5b488 6600
b9c7bc5a
PZ
6601DEFPY (af_nexthop_vpn_export,
6602 af_nexthop_vpn_export_cmd,
6603 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6604 NO_STR
ddb5b488 6605 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6606 "Between current address-family and vpn\n"
6607 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6608 "IPv4 prefix\n"
6609 "IPv6 prefix\n")
6610{
6611 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6612 afi_t afi;
ddb5b488 6613 struct prefix p;
b9c7bc5a
PZ
6614 int idx = 0;
6615 int yes = 1;
ddb5b488 6616
b9c7bc5a 6617 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6618 yes = 0;
b9c7bc5a
PZ
6619
6620 if (yes) {
6621 if (!sockunion2hostprefix(nexthop_str, &p))
6622 return CMD_WARNING_CONFIG_FAILED;
6623 }
ddb5b488 6624
0ca70ba5 6625 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6626 if (afi == AFI_MAX)
6627 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6628
69b07479
DS
6629 /*
6630 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6631 */
6632 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6633 bgp_get_default(), bgp);
ddb5b488 6634
69b07479
DS
6635 if (yes) {
6636 bgp->vpn_policy[afi].tovpn_nexthop = p;
6637 SET_FLAG(bgp->vpn_policy[afi].flags,
6638 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6639 } else {
6640 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6641 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6642 }
6643
69b07479
DS
6644 /* post-change: re-export vpn routes */
6645 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6646 bgp_get_default(), bgp);
6647
ddb5b488
PZ
6648 return CMD_SUCCESS;
6649}
6650
b9c7bc5a
PZ
6651ALIAS (af_nexthop_vpn_export,
6652 af_no_nexthop_vpn_export_cmd,
6653 "no nexthop vpn export",
ddb5b488 6654 NO_STR
b9c7bc5a
PZ
6655 "Specify next hop to use for VRF advertised prefixes\n"
6656 "Between current address-family and vpn\n"
6657 "For routes leaked from current address-family to vpn\n")
ddb5b488 6658
b9c7bc5a 6659static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6660{
b9c7bc5a
PZ
6661 if (!strcmp(dstr, "import")) {
6662 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6663 } else if (!strcmp(dstr, "export")) {
6664 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6665 } else if (!strcmp(dstr, "both")) {
6666 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6667 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6668 } else {
6669 vty_out(vty, "%% direction parse error\n");
6670 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6671 }
ddb5b488
PZ
6672 return CMD_SUCCESS;
6673}
6674
b9c7bc5a
PZ
6675DEFPY (af_rt_vpn_imexport,
6676 af_rt_vpn_imexport_cmd,
6677 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6678 NO_STR
6679 "Specify route target list\n"
ddb5b488 6680 "Specify route target list\n"
b9c7bc5a
PZ
6681 "Between current address-family and vpn\n"
6682 "For routes leaked from vpn to current address-family: match any\n"
6683 "For routes leaked from current address-family to vpn: set\n"
6684 "both import: match any and export: set\n"
ddb5b488
PZ
6685 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6686{
6687 VTY_DECLVAR_CONTEXT(bgp, bgp);
6688 int ret;
6689 struct ecommunity *ecom = NULL;
6690 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6691 vpn_policy_direction_t dir;
6692 afi_t afi;
6693 int idx = 0;
b9c7bc5a 6694 int yes = 1;
ddb5b488 6695
b9c7bc5a 6696 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6697 yes = 0;
b9c7bc5a 6698
0ca70ba5 6699 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6700 if (afi == AFI_MAX)
6701 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6702
b9c7bc5a 6703 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6704 if (ret != CMD_SUCCESS)
6705 return ret;
6706
b9c7bc5a
PZ
6707 if (yes) {
6708 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6709 vty_out(vty, "%% Missing RTLIST\n");
6710 return CMD_WARNING_CONFIG_FAILED;
6711 }
6712 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6713 if (ret != CMD_SUCCESS) {
6714 return ret;
6715 }
ddb5b488
PZ
6716 }
6717
69b07479
DS
6718 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6719 if (!dodir[dir])
ddb5b488 6720 continue;
ddb5b488 6721
69b07479 6722 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6723
69b07479
DS
6724 if (yes) {
6725 if (bgp->vpn_policy[afi].rtlist[dir])
6726 ecommunity_free(
6727 &bgp->vpn_policy[afi].rtlist[dir]);
6728 bgp->vpn_policy[afi].rtlist[dir] =
6729 ecommunity_dup(ecom);
6730 } else {
6731 if (bgp->vpn_policy[afi].rtlist[dir])
6732 ecommunity_free(
6733 &bgp->vpn_policy[afi].rtlist[dir]);
6734 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6735 }
69b07479
DS
6736
6737 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6738 }
69b07479 6739
d555f3e9
PZ
6740 if (ecom)
6741 ecommunity_free(&ecom);
ddb5b488
PZ
6742
6743 return CMD_SUCCESS;
6744}
6745
b9c7bc5a
PZ
6746ALIAS (af_rt_vpn_imexport,
6747 af_no_rt_vpn_imexport_cmd,
6748 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6749 NO_STR
6750 "Specify route target list\n"
b9c7bc5a
PZ
6751 "Specify route target list\n"
6752 "Between current address-family and vpn\n"
6753 "For routes leaked from vpn to current address-family\n"
6754 "For routes leaked from current address-family to vpn\n"
6755 "both import and export\n")
6756
6757DEFPY (af_route_map_vpn_imexport,
6758 af_route_map_vpn_imexport_cmd,
6759/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6760 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6761 NO_STR
ddb5b488 6762 "Specify route map\n"
b9c7bc5a
PZ
6763 "Between current address-family and vpn\n"
6764 "For routes leaked from vpn to current address-family\n"
6765 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6766 "name of route-map\n")
6767{
6768 VTY_DECLVAR_CONTEXT(bgp, bgp);
6769 int ret;
6770 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6771 vpn_policy_direction_t dir;
6772 afi_t afi;
ddb5b488 6773 int idx = 0;
b9c7bc5a 6774 int yes = 1;
ddb5b488 6775
b9c7bc5a 6776 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6777 yes = 0;
b9c7bc5a 6778
0ca70ba5 6779 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6780 if (afi == AFI_MAX)
6781 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6782
b9c7bc5a 6783 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6784 if (ret != CMD_SUCCESS)
6785 return ret;
6786
69b07479
DS
6787 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6788 if (!dodir[dir])
ddb5b488 6789 continue;
ddb5b488 6790
69b07479 6791 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6792
69b07479
DS
6793 if (yes) {
6794 if (bgp->vpn_policy[afi].rmap_name[dir])
6795 XFREE(MTYPE_ROUTE_MAP_NAME,
6796 bgp->vpn_policy[afi].rmap_name[dir]);
6797 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6798 MTYPE_ROUTE_MAP_NAME, rmap_str);
6799 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6800 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6801 if (!bgp->vpn_policy[afi].rmap[dir])
6802 return CMD_SUCCESS;
6803 } else {
6804 if (bgp->vpn_policy[afi].rmap_name[dir])
6805 XFREE(MTYPE_ROUTE_MAP_NAME,
6806 bgp->vpn_policy[afi].rmap_name[dir]);
6807 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6808 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6809 }
69b07479
DS
6810
6811 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6812 }
6813
6814 return CMD_SUCCESS;
6815}
6816
b9c7bc5a
PZ
6817ALIAS (af_route_map_vpn_imexport,
6818 af_no_route_map_vpn_imexport_cmd,
6819 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6820 NO_STR
6821 "Specify route map\n"
b9c7bc5a
PZ
6822 "Between current address-family and vpn\n"
6823 "For routes leaked from vpn to current address-family\n"
6824 "For routes leaked from current address-family to vpn\n")
6825
bb4f6190
DS
6826DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6827 "[no] import vrf route-map RMAP$rmap_str",
6828 NO_STR
6829 "Import routes from another VRF\n"
6830 "Vrf routes being filtered\n"
6831 "Specify route map\n"
6832 "name of route-map\n")
6833{
6834 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6835 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6836 afi_t afi;
6837 int idx = 0;
6838 int yes = 1;
6839 struct bgp *bgp_default;
6840
6841 if (argv_find(argv, argc, "no", &idx))
6842 yes = 0;
6843
0ca70ba5 6844 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6845 if (afi == AFI_MAX)
6846 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6847
6848 bgp_default = bgp_get_default();
6849 if (!bgp_default) {
6850 int32_t ret;
6851 as_t as = bgp->as;
6852
6853 /* Auto-create assuming the same AS */
6854 ret = bgp_get(&bgp_default, &as, NULL,
6855 BGP_INSTANCE_TYPE_DEFAULT);
6856
6857 if (ret) {
6858 vty_out(vty,
6859 "VRF default is not configured as a bgp instance\n");
6860 return CMD_WARNING;
6861 }
6862 }
6863
69b07479 6864 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6865
69b07479
DS
6866 if (yes) {
6867 if (bgp->vpn_policy[afi].rmap_name[dir])
6868 XFREE(MTYPE_ROUTE_MAP_NAME,
6869 bgp->vpn_policy[afi].rmap_name[dir]);
6870 bgp->vpn_policy[afi].rmap_name[dir] =
6871 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6872 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6873 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6874 if (!bgp->vpn_policy[afi].rmap[dir])
6875 return CMD_SUCCESS;
6876 } else {
6877 if (bgp->vpn_policy[afi].rmap_name[dir])
6878 XFREE(MTYPE_ROUTE_MAP_NAME,
6879 bgp->vpn_policy[afi].rmap_name[dir]);
6880 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6881 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6882 }
6883
69b07479
DS
6884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6885
bb4f6190
DS
6886 return CMD_SUCCESS;
6887}
6888
6889ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6890 "no import vrf route-map",
6891 NO_STR
6892 "Import routes from another VRF\n"
6893 "Vrf routes being filtered\n"
6894 "Specify route map\n")
6895
4d1b335c
DA
6896DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6897 "[no] import vrf VIEWVRFNAME$import_name",
6898 NO_STR
6899 "Import routes from another VRF\n"
6900 "VRF to import from\n"
6901 "The name of the VRF\n")
12a844a5
DS
6902{
6903 VTY_DECLVAR_CONTEXT(bgp, bgp);
6904 struct listnode *node;
79ef8664
DS
6905 struct bgp *vrf_bgp, *bgp_default;
6906 int32_t ret = 0;
6907 as_t as = bgp->as;
12a844a5
DS
6908 bool remove = false;
6909 int32_t idx = 0;
6910 char *vname;
a8dadcf6 6911 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6912 safi_t safi;
6913 afi_t afi;
6914
867f0cca 6915 if (import_name == NULL) {
6916 vty_out(vty, "%% Missing import name\n");
6917 return CMD_WARNING;
6918 }
6919
12a844a5
DS
6920 if (argv_find(argv, argc, "no", &idx))
6921 remove = true;
6922
0ca70ba5
DS
6923 afi = vpn_policy_getafi(vty, bgp, true);
6924 if (afi == AFI_MAX)
6925 return CMD_WARNING_CONFIG_FAILED;
6926
12a844a5
DS
6927 safi = bgp_node_safi(vty);
6928
25679caa 6929 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6930 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6931 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6932 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6933 remove ? "unimport" : "import", import_name);
6934 return CMD_WARNING;
6935 }
6936
79ef8664
DS
6937 bgp_default = bgp_get_default();
6938 if (!bgp_default) {
6939 /* Auto-create assuming the same AS */
6940 ret = bgp_get(&bgp_default, &as, NULL,
6941 BGP_INSTANCE_TYPE_DEFAULT);
6942
6943 if (ret) {
6944 vty_out(vty,
6945 "VRF default is not configured as a bgp instance\n");
6946 return CMD_WARNING;
6947 }
6948 }
6949
12a844a5
DS
6950 vrf_bgp = bgp_lookup_by_name(import_name);
6951 if (!vrf_bgp) {
5742e42b 6952 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6953 vrf_bgp = bgp_default;
6954 else
0fb8d6e6
DS
6955 /* Auto-create assuming the same AS */
6956 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6957
6e2c7fe6 6958 if (ret) {
020a3f60
DS
6959 vty_out(vty,
6960 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6961 import_name);
6962 return CMD_WARNING;
6963 }
12a844a5
DS
6964 }
6965
12a844a5 6966 if (remove) {
44338987 6967 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6968 } else {
44338987 6969 /* Already importing from "import_vrf"? */
12a844a5
DS
6970 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6971 vname)) {
6972 if (strcmp(vname, import_name) == 0)
6973 return CMD_WARNING;
6974 }
6975
44338987 6976 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6977 }
6978
6979 return CMD_SUCCESS;
6980}
6981
b9c7bc5a
PZ
6982/* This command is valid only in a bgp vrf instance or the default instance */
6983DEFPY (bgp_imexport_vpn,
6984 bgp_imexport_vpn_cmd,
6985 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6986 NO_STR
6987 "Import routes to this address-family\n"
6988 "Export routes from this address-family\n"
6989 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6990{
6991 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6992 int previous_state;
ddb5b488 6993 afi_t afi;
b9c7bc5a 6994 safi_t safi;
ddb5b488 6995 int idx = 0;
b9c7bc5a
PZ
6996 int yes = 1;
6997 int flag;
6998 vpn_policy_direction_t dir;
ddb5b488 6999
b9c7bc5a 7000 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7001 yes = 0;
ddb5b488 7002
b9c7bc5a
PZ
7003 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7004 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7005
b9c7bc5a
PZ
7006 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7007 return CMD_WARNING_CONFIG_FAILED;
7008 }
ddb5b488 7009
b9c7bc5a
PZ
7010 afi = bgp_node_afi(vty);
7011 safi = bgp_node_safi(vty);
7012 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7013 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7014 return CMD_WARNING_CONFIG_FAILED;
7015 }
ddb5b488 7016
b9c7bc5a
PZ
7017 if (!strcmp(direction_str, "import")) {
7018 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7019 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7020 } else if (!strcmp(direction_str, "export")) {
7021 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7022 dir = BGP_VPN_POLICY_DIR_TOVPN;
7023 } else {
7024 vty_out(vty, "%% unknown direction %s\n", direction_str);
7025 return CMD_WARNING_CONFIG_FAILED;
7026 }
7027
7028 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7029
b9c7bc5a
PZ
7030 if (yes) {
7031 SET_FLAG(bgp->af_flags[afi][safi], flag);
7032 if (!previous_state) {
7033 /* trigger export current vrf */
ddb5b488
PZ
7034 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7035 }
b9c7bc5a
PZ
7036 } else {
7037 if (previous_state) {
7038 /* trigger un-export current vrf */
7039 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7040 }
7041 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7042 }
7043
7044 return CMD_SUCCESS;
7045}
7046
301ad80a
PG
7047DEFPY (af_routetarget_import,
7048 af_routetarget_import_cmd,
7049 "[no] <rt|route-target> redirect import RTLIST...",
7050 NO_STR
7051 "Specify route target list\n"
7052 "Specify route target list\n"
7053 "Flow-spec redirect type route target\n"
7054 "Import routes to this address-family\n"
7055 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7056{
7057 VTY_DECLVAR_CONTEXT(bgp, bgp);
7058 int ret;
7059 struct ecommunity *ecom = NULL;
301ad80a
PG
7060 afi_t afi;
7061 int idx = 0;
7062 int yes = 1;
7063
7064 if (argv_find(argv, argc, "no", &idx))
7065 yes = 0;
7066
0ca70ba5 7067 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7068 if (afi == AFI_MAX)
7069 return CMD_WARNING_CONFIG_FAILED;
7070
301ad80a
PG
7071 if (yes) {
7072 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7073 vty_out(vty, "%% Missing RTLIST\n");
7074 return CMD_WARNING_CONFIG_FAILED;
7075 }
7076 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7077 if (ret != CMD_SUCCESS)
7078 return ret;
7079 }
69b07479
DS
7080
7081 if (yes) {
7082 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7083 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7084 .import_redirect_rtlist);
69b07479
DS
7085 bgp->vpn_policy[afi].import_redirect_rtlist =
7086 ecommunity_dup(ecom);
7087 } else {
7088 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7089 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7090 .import_redirect_rtlist);
69b07479 7091 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7092 }
69b07479 7093
301ad80a
PG
7094 if (ecom)
7095 ecommunity_free(&ecom);
7096
7097 return CMD_SUCCESS;
7098}
7099
505e5056 7100DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7101 address_family_ipv4_safi_cmd,
7102 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7103 "Enter Address Family command mode\n"
7104 "Address Family\n"
7105 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7106{
f51bae9c 7107
d62a17ae 7108 if (argc == 3) {
2131d5cf 7109 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7110 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7111 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7112 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7113 && safi != SAFI_EVPN) {
31947174
MK
7114 vty_out(vty,
7115 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7116 return CMD_WARNING_CONFIG_FAILED;
7117 }
d62a17ae 7118 vty->node = bgp_node_type(AFI_IP, safi);
7119 } else
7120 vty->node = BGP_IPV4_NODE;
718e3744 7121
d62a17ae 7122 return CMD_SUCCESS;
718e3744 7123}
7124
505e5056 7125DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7126 address_family_ipv6_safi_cmd,
7127 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7128 "Enter Address Family command mode\n"
7129 "Address Family\n"
7130 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7131{
d62a17ae 7132 if (argc == 3) {
2131d5cf 7133 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7134 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7135 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7136 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7137 && safi != SAFI_EVPN) {
31947174
MK
7138 vty_out(vty,
7139 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7140 return CMD_WARNING_CONFIG_FAILED;
7141 }
d62a17ae 7142 vty->node = bgp_node_type(AFI_IP6, safi);
7143 } else
7144 vty->node = BGP_IPV6_NODE;
25ffbdc1 7145
d62a17ae 7146 return CMD_SUCCESS;
25ffbdc1 7147}
718e3744 7148
d6902373 7149#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7150DEFUN_NOSH (address_family_vpnv4,
718e3744 7151 address_family_vpnv4_cmd,
8334fd5a 7152 "address-family vpnv4 [unicast]",
718e3744 7153 "Enter Address Family command mode\n"
8c3deaae 7154 "Address Family\n"
3a2d747c 7155 "Address Family modifier\n")
718e3744 7156{
d62a17ae 7157 vty->node = BGP_VPNV4_NODE;
7158 return CMD_SUCCESS;
718e3744 7159}
7160
505e5056 7161DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7162 address_family_vpnv6_cmd,
8334fd5a 7163 "address-family vpnv6 [unicast]",
8ecd3266 7164 "Enter Address Family command mode\n"
8c3deaae 7165 "Address Family\n"
3a2d747c 7166 "Address Family modifier\n")
8ecd3266 7167{
d62a17ae 7168 vty->node = BGP_VPNV6_NODE;
7169 return CMD_SUCCESS;
8ecd3266 7170}
64e4a6c5 7171#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7172
505e5056 7173DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7174 address_family_evpn_cmd,
7111c1a0 7175 "address-family l2vpn evpn",
4e0b7b6d 7176 "Enter Address Family command mode\n"
7111c1a0
QY
7177 "Address Family\n"
7178 "Address Family modifier\n")
4e0b7b6d 7179{
2131d5cf 7180 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7181 vty->node = BGP_EVPN_NODE;
7182 return CMD_SUCCESS;
4e0b7b6d
PG
7183}
7184
505e5056 7185DEFUN_NOSH (exit_address_family,
718e3744 7186 exit_address_family_cmd,
7187 "exit-address-family",
7188 "Exit from Address Family configuration mode\n")
7189{
d62a17ae 7190 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7191 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7192 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7193 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7194 || vty->node == BGP_EVPN_NODE
7195 || vty->node == BGP_FLOWSPECV4_NODE
7196 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7197 vty->node = BGP_NODE;
7198 return CMD_SUCCESS;
718e3744 7199}
6b0655a2 7200
8ad7271d 7201/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7202static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7203 const char *ip_str, afi_t afi, safi_t safi,
7204 struct prefix_rd *prd)
7205{
7206 int ret;
7207 struct prefix match;
7208 struct bgp_node *rn;
7209 struct bgp_node *rm;
7210 struct bgp *bgp;
7211 struct bgp_table *table;
7212 struct bgp_table *rib;
7213
7214 /* BGP structure lookup. */
7215 if (view_name) {
7216 bgp = bgp_lookup_by_name(view_name);
7217 if (bgp == NULL) {
7218 vty_out(vty, "%% Can't find BGP instance %s\n",
7219 view_name);
7220 return CMD_WARNING;
7221 }
7222 } else {
7223 bgp = bgp_get_default();
7224 if (bgp == NULL) {
7225 vty_out(vty, "%% No BGP process is configured\n");
7226 return CMD_WARNING;
7227 }
7228 }
7229
7230 /* Check IP address argument. */
7231 ret = str2prefix(ip_str, &match);
7232 if (!ret) {
7233 vty_out(vty, "%% address is malformed\n");
7234 return CMD_WARNING;
7235 }
7236
7237 match.family = afi2family(afi);
7238 rib = bgp->rib[afi][safi];
7239
7240 if (safi == SAFI_MPLS_VPN) {
7241 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7242 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7243 continue;
7244
67009e22
DS
7245 table = bgp_node_get_bgp_table_info(rn);
7246 if (table != NULL) {
7247
d62a17ae 7248 if ((rm = bgp_node_match(table, &match))
7249 != NULL) {
7250 if (rm->p.prefixlen
7251 == match.prefixlen) {
343cdb61 7252 SET_FLAG(rm->flags,
d62a17ae 7253 BGP_NODE_USER_CLEAR);
7254 bgp_process(bgp, rm, afi, safi);
7255 }
7256 bgp_unlock_node(rm);
7257 }
7258 }
7259 }
7260 } else {
7261 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7262 if (rn->p.prefixlen == match.prefixlen) {
7263 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7264 bgp_process(bgp, rn, afi, safi);
7265 }
7266 bgp_unlock_node(rn);
7267 }
7268 }
7269
7270 return CMD_SUCCESS;
8ad7271d
DS
7271}
7272
b09b5ae0 7273/* one clear bgp command to rule them all */
718e3744 7274DEFUN (clear_ip_bgp_all,
7275 clear_ip_bgp_all_cmd,
fd5e7b70 7276 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7277 CLEAR_STR
7278 IP_STR
7279 BGP_STR
838758ac 7280 BGP_INSTANCE_HELP_STR
510afcd6 7281 BGP_AFI_HELP_STR
fd5e7b70 7282 "Address Family\n"
510afcd6 7283 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7284 "Address Family modifier\n"
b09b5ae0
DW
7285 "Clear all peers\n"
7286 "BGP neighbor address to clear\n"
a80beece 7287 "BGP IPv6 neighbor to clear\n"
838758ac 7288 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7289 "Clear peers with the AS number\n"
7290 "Clear all external peers\n"
718e3744 7291 "Clear all members of peer-group\n"
b09b5ae0 7292 "BGP peer-group name\n"
b09b5ae0
DW
7293 BGP_SOFT_STR
7294 BGP_SOFT_IN_STR
b09b5ae0
DW
7295 BGP_SOFT_OUT_STR
7296 BGP_SOFT_IN_STR
7297 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7298 BGP_SOFT_OUT_STR)
718e3744 7299{
d62a17ae 7300 char *vrf = NULL;
7301
7302 afi_t afi = AFI_IP6;
7303 safi_t safi = SAFI_UNICAST;
7304 enum clear_sort clr_sort = clear_peer;
7305 enum bgp_clear_type clr_type;
7306 char *clr_arg = NULL;
7307
7308 int idx = 0;
7309
7310 /* clear [ip] bgp */
7311 if (argv_find(argv, argc, "ip", &idx))
7312 afi = AFI_IP;
7313
9a8bdf1c
PG
7314 /* [<vrf> VIEWVRFNAME] */
7315 if (argv_find(argv, argc, "vrf", &idx)) {
7316 vrf = argv[idx + 1]->arg;
7317 idx += 2;
7318 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7319 vrf = NULL;
7320 } else if (argv_find(argv, argc, "view", &idx)) {
7321 /* [<view> VIEWVRFNAME] */
d62a17ae 7322 vrf = argv[idx + 1]->arg;
7323 idx += 2;
7324 }
d62a17ae 7325 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7326 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7327 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7328
7329 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7330 if (argv_find(argv, argc, "*", &idx)) {
7331 clr_sort = clear_all;
7332 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7333 clr_sort = clear_peer;
7334 clr_arg = argv[idx]->arg;
7335 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7336 clr_sort = clear_peer;
7337 clr_arg = argv[idx]->arg;
7338 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7339 clr_sort = clear_group;
7340 idx++;
7341 clr_arg = argv[idx]->arg;
7342 } else if (argv_find(argv, argc, "WORD", &idx)) {
7343 clr_sort = clear_peer;
7344 clr_arg = argv[idx]->arg;
7345 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7346 clr_sort = clear_as;
7347 clr_arg = argv[idx]->arg;
7348 } else if (argv_find(argv, argc, "external", &idx)) {
7349 clr_sort = clear_external;
7350 }
7351
7352 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7353 if (argv_find(argv, argc, "soft", &idx)) {
7354 if (argv_find(argv, argc, "in", &idx)
7355 || argv_find(argv, argc, "out", &idx))
7356 clr_type = strmatch(argv[idx]->text, "in")
7357 ? BGP_CLEAR_SOFT_IN
7358 : BGP_CLEAR_SOFT_OUT;
7359 else
7360 clr_type = BGP_CLEAR_SOFT_BOTH;
7361 } else if (argv_find(argv, argc, "in", &idx)) {
7362 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7363 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7364 : BGP_CLEAR_SOFT_IN;
7365 } else if (argv_find(argv, argc, "out", &idx)) {
7366 clr_type = BGP_CLEAR_SOFT_OUT;
7367 } else
7368 clr_type = BGP_CLEAR_SOFT_NONE;
7369
7370 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7371}
01080f7c 7372
8ad7271d
DS
7373DEFUN (clear_ip_bgp_prefix,
7374 clear_ip_bgp_prefix_cmd,
18c57037 7375 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7376 CLEAR_STR
7377 IP_STR
7378 BGP_STR
838758ac 7379 BGP_INSTANCE_HELP_STR
8ad7271d 7380 "Clear bestpath and re-advertise\n"
0c7b1b01 7381 "IPv4 prefix\n")
8ad7271d 7382{
d62a17ae 7383 char *vrf = NULL;
7384 char *prefix = NULL;
8ad7271d 7385
d62a17ae 7386 int idx = 0;
01080f7c 7387
d62a17ae 7388 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7389 if (argv_find(argv, argc, "vrf", &idx)) {
7390 vrf = argv[idx + 1]->arg;
7391 idx += 2;
7392 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7393 vrf = NULL;
7394 } else if (argv_find(argv, argc, "view", &idx)) {
7395 /* [<view> VIEWVRFNAME] */
7396 vrf = argv[idx + 1]->arg;
7397 idx += 2;
7398 }
0c7b1b01 7399
d62a17ae 7400 prefix = argv[argc - 1]->arg;
8ad7271d 7401
d62a17ae 7402 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7403}
8ad7271d 7404
b09b5ae0
DW
7405DEFUN (clear_bgp_ipv6_safi_prefix,
7406 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7407 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7408 CLEAR_STR
3a2d747c 7409 IP_STR
718e3744 7410 BGP_STR
8c3deaae 7411 "Address Family\n"
46f296b4 7412 BGP_SAFI_HELP_STR
b09b5ae0 7413 "Clear bestpath and re-advertise\n"
0c7b1b01 7414 "IPv6 prefix\n")
718e3744 7415{
9b475e76
PG
7416 int idx_safi = 0;
7417 int idx_ipv6_prefix = 0;
7418 safi_t safi = SAFI_UNICAST;
7419 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7420 argv[idx_ipv6_prefix]->arg : NULL;
7421
7422 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7423 return bgp_clear_prefix(
9b475e76
PG
7424 vty, NULL, prefix, AFI_IP6,
7425 safi, NULL);
838758ac 7426}
01080f7c 7427
b09b5ae0
DW
7428DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7429 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7430 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7431 CLEAR_STR
3a2d747c 7432 IP_STR
718e3744 7433 BGP_STR
838758ac 7434 BGP_INSTANCE_HELP_STR
8c3deaae 7435 "Address Family\n"
46f296b4 7436 BGP_SAFI_HELP_STR
b09b5ae0 7437 "Clear bestpath and re-advertise\n"
0c7b1b01 7438 "IPv6 prefix\n")
718e3744 7439{
9b475e76 7440 int idx_safi = 0;
9a8bdf1c 7441 int idx_vrfview = 0;
9b475e76
PG
7442 int idx_ipv6_prefix = 0;
7443 safi_t safi = SAFI_UNICAST;
7444 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7445 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7446 char *vrfview = NULL;
9b475e76 7447
9a8bdf1c
PG
7448 /* [<view|vrf> VIEWVRFNAME] */
7449 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7450 vrfview = argv[idx_vrfview + 1]->arg;
7451 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7452 vrfview = NULL;
7453 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7454 /* [<view> VIEWVRFNAME] */
7455 vrfview = argv[idx_vrfview + 1]->arg;
7456 }
9b475e76
PG
7457 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7458
d62a17ae 7459 return bgp_clear_prefix(
9b475e76
PG
7460 vty, vrfview, prefix,
7461 AFI_IP6, safi, NULL);
718e3744 7462}
7463
b09b5ae0
DW
7464DEFUN (show_bgp_views,
7465 show_bgp_views_cmd,
d6e3c605 7466 "show [ip] bgp views",
b09b5ae0 7467 SHOW_STR
d6e3c605 7468 IP_STR
01080f7c 7469 BGP_STR
b09b5ae0 7470 "Show the defined BGP views\n")
01080f7c 7471{
d62a17ae 7472 struct list *inst = bm->bgp;
7473 struct listnode *node;
7474 struct bgp *bgp;
01080f7c 7475
d62a17ae 7476 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7477 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7478 return CMD_WARNING;
7479 }
e52702f2 7480
d62a17ae 7481 vty_out(vty, "Defined BGP views:\n");
7482 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7483 /* Skip VRFs. */
7484 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7485 continue;
7486 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7487 bgp->as);
7488 }
e52702f2 7489
d62a17ae 7490 return CMD_SUCCESS;
e0081f70
ML
7491}
7492
8386ac43 7493DEFUN (show_bgp_vrfs,
7494 show_bgp_vrfs_cmd,
d6e3c605 7495 "show [ip] bgp vrfs [json]",
8386ac43 7496 SHOW_STR
d6e3c605 7497 IP_STR
8386ac43 7498 BGP_STR
7499 "Show BGP VRFs\n"
9973d184 7500 JSON_STR)
8386ac43 7501{
fe1dc5a3 7502 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7503 struct list *inst = bm->bgp;
7504 struct listnode *node;
7505 struct bgp *bgp;
9f049418 7506 bool uj = use_json(argc, argv);
d62a17ae 7507 json_object *json = NULL;
7508 json_object *json_vrfs = NULL;
7509 int count = 0;
d62a17ae 7510
7511 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7512 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7513 return CMD_WARNING;
7514 }
7515
7516 if (uj) {
7517 json = json_object_new_object();
7518 json_vrfs = json_object_new_object();
7519 }
7520
7521 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7522 const char *name, *type;
7523 struct peer *peer;
7fe96307 7524 struct listnode *node2, *nnode2;
d62a17ae 7525 int peers_cfg, peers_estb;
7526 json_object *json_vrf = NULL;
d62a17ae 7527
7528 /* Skip Views. */
7529 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7530 continue;
7531
7532 count++;
7533 if (!uj && count == 1)
fe1dc5a3
MK
7534 vty_out(vty,
7535 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7536 "Type", "Id", "routerId", "#PeersVfg",
7537 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7538
7539 peers_cfg = peers_estb = 0;
7540 if (uj)
7541 json_vrf = json_object_new_object();
7542
7543
7fe96307 7544 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7545 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7546 continue;
7547 peers_cfg++;
7548 if (peer->status == Established)
7549 peers_estb++;
7550 }
7551
7552 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7553 name = VRF_DEFAULT_NAME;
d62a17ae 7554 type = "DFLT";
7555 } else {
7556 name = bgp->name;
7557 type = "VRF";
7558 }
7559
a8bf7d9c 7560
d62a17ae 7561 if (uj) {
a4d82a8a
PZ
7562 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7563 ? -1
7564 : (int64_t)bgp->vrf_id;
d62a17ae 7565 json_object_string_add(json_vrf, "type", type);
7566 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7567 json_object_string_add(json_vrf, "routerId",
7568 inet_ntoa(bgp->router_id));
7569 json_object_int_add(json_vrf, "numConfiguredPeers",
7570 peers_cfg);
7571 json_object_int_add(json_vrf, "numEstablishedPeers",
7572 peers_estb);
7573
fe1dc5a3 7574 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7575 json_object_string_add(
7576 json_vrf, "rmac",
7577 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7578 json_object_object_add(json_vrfs, name, json_vrf);
7579 } else
fe1dc5a3
MK
7580 vty_out(vty,
7581 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7582 type,
7583 bgp->vrf_id == VRF_UNKNOWN ? -1
7584 : (int)bgp->vrf_id,
7585 inet_ntoa(bgp->router_id), peers_cfg,
7586 peers_estb, name, bgp->l3vni,
fe1dc5a3 7587 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7588 }
7589
7590 if (uj) {
7591 json_object_object_add(json, "vrfs", json_vrfs);
7592
7593 json_object_int_add(json, "totalVrfs", count);
7594
996c9314
LB
7595 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7596 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7597 json_object_free(json);
7598 } else {
7599 if (count)
7600 vty_out(vty,
7601 "\nTotal number of VRFs (including default): %d\n",
7602 count);
7603 }
7604
7605 return CMD_SUCCESS;
8386ac43 7606}
7607
48ecf8f5
DS
7608DEFUN (show_bgp_mac_hash,
7609 show_bgp_mac_hash_cmd,
7610 "show bgp mac hash",
7611 SHOW_STR
7612 BGP_STR
7613 "Mac Address\n"
7614 "Mac Address database\n")
7615{
7616 bgp_mac_dump_table(vty);
7617
7618 return CMD_SUCCESS;
7619}
acf71666 7620
e3b78da8 7621static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7622{
0291c246 7623 struct vty *vty = (struct vty *)args;
e3b78da8 7624 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7625
60466a63 7626 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7627 tip->refcnt);
7628}
7629
7630static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7631{
7632 vty_out(vty, "self nexthop database:\n");
af97a18b 7633 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7634
7635 vty_out(vty, "Tunnel-ip database:\n");
7636 hash_iterate(bgp->tip_hash,
e3b78da8 7637 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7638 vty);
7639}
7640
15c81ca4
DS
7641DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7642 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7643 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7644 "martian next-hops\n"
7645 "martian next-hop database\n")
acf71666 7646{
0291c246 7647 struct bgp *bgp = NULL;
15c81ca4 7648 int idx = 0;
9a8bdf1c
PG
7649 char *name = NULL;
7650
7651 /* [<vrf> VIEWVRFNAME] */
7652 if (argv_find(argv, argc, "vrf", &idx)) {
7653 name = argv[idx + 1]->arg;
7654 if (name && strmatch(name, VRF_DEFAULT_NAME))
7655 name = NULL;
7656 } else if (argv_find(argv, argc, "view", &idx))
7657 /* [<view> VIEWVRFNAME] */
7658 name = argv[idx + 1]->arg;
7659 if (name)
7660 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7661 else
7662 bgp = bgp_get_default();
acf71666 7663
acf71666
MK
7664 if (!bgp) {
7665 vty_out(vty, "%% No BGP process is configured\n");
7666 return CMD_WARNING;
7667 }
7668 bgp_show_martian_nexthops(vty, bgp);
7669
7670 return CMD_SUCCESS;
7671}
7672
f412b39a 7673DEFUN (show_bgp_memory,
4bf6a362 7674 show_bgp_memory_cmd,
7fa12b13 7675 "show [ip] bgp memory",
4bf6a362 7676 SHOW_STR
3a2d747c 7677 IP_STR
4bf6a362
PJ
7678 BGP_STR
7679 "Global BGP memory statistics\n")
7680{
d62a17ae 7681 char memstrbuf[MTYPE_MEMSTR_LEN];
7682 unsigned long count;
7683
7684 /* RIB related usage stats */
7685 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7686 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_node)));
7689
7690 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7691 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7692 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7693 count * sizeof(struct bgp_path_info)));
d62a17ae 7694 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7695 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7696 count,
4b7e6066
DS
7697 mtype_memstr(
7698 memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7700
7701 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7702 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bgp_static)));
7705
7706 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7707 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7708 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7709 count * sizeof(struct bpacket)));
7710
7711 /* Adj-In/Out */
7712 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7713 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7715 count * sizeof(struct bgp_adj_in)));
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7717 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_adj_out)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7722 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7723 count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct bgp_nexthop_cache)));
7726
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7728 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7729 count,
7730 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(struct bgp_damp_info)));
7732
7733 /* Attributes */
7734 count = attr_count();
7735 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(struct attr)));
7738
7739 if ((count = attr_unknown_count()))
7740 vty_out(vty, "%ld unknown attributes\n", count);
7741
7742 /* AS_PATH attributes */
7743 count = aspath_count();
7744 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct aspath)));
7747
7748 count = mtype_stats_alloc(MTYPE_AS_SEG);
7749 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7750 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7751 count * sizeof(struct assegment)));
7752
7753 /* Other attributes */
7754 if ((count = community_count()))
7755 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7756 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7757 count * sizeof(struct community)));
d62a17ae 7758 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7759 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct ecommunity)));
d62a17ae 7762 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7763 vty_out(vty,
7764 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7765 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct lcommunity)));
d62a17ae 7767
7768 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7769 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7770 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7771 count * sizeof(struct cluster_list)));
7772
7773 /* Peer related usage */
7774 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7775 vty_out(vty, "%ld peers, using %s of memory\n", count,
7776 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(struct peer)));
7778
7779 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7780 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7781 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7782 count * sizeof(struct peer_group)));
7783
7784 /* Other */
7785 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7786 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7787 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7788 count * sizeof(struct hash)));
7789 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7790 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
e3b78da8 7792 count * sizeof(struct hash_bucket)));
d62a17ae 7793 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7794 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7795 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7796 count * sizeof(regex_t)));
d62a17ae 7797 return CMD_SUCCESS;
4bf6a362 7798}
fee0f4c6 7799
57a9c8a8
DS
7800static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7801{
7802 json_object *bestpath = json_object_new_object();
7803
7804 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7805 json_object_string_add(bestpath, "asPath", "ignore");
7806
7807 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7808 json_object_string_add(bestpath, "asPath", "confed");
7809
7810 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7811 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7812 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7813 "as-set");
7814 else
a4d82a8a 7815 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7816 "true");
7817 } else
a4d82a8a 7818 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7819
7820 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7821 json_object_string_add(bestpath, "compareRouterId", "true");
7822 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7823 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7824 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7825 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7826 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7827 json_object_string_add(bestpath, "med",
7828 "missing-as-worst");
7829 else
7830 json_object_string_add(bestpath, "med", "true");
7831 }
7832
7833 json_object_object_add(json, "bestPath", bestpath);
7834}
7835
718e3744 7836/* Show BGP peer's summary information. */
d62a17ae 7837static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7838 bool use_json, json_object *json)
d62a17ae 7839{
7840 struct peer *peer;
7841 struct listnode *node, *nnode;
7842 unsigned int count = 0, dn_count = 0;
7843 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7844 char neighbor_buf[VTY_BUFSIZ];
7845 int neighbor_col_default_width = 16;
7846 int len;
7847 int max_neighbor_width = 0;
7848 int pfx_rcd_safi;
7849 json_object *json_peer = NULL;
7850 json_object *json_peers = NULL;
50e05855 7851 struct peer_af *paf;
d62a17ae 7852
7853 /* labeled-unicast routes are installed in the unicast table so in order
7854 * to
7855 * display the correct PfxRcd value we must look at SAFI_UNICAST
7856 */
7857 if (safi == SAFI_LABELED_UNICAST)
7858 pfx_rcd_safi = SAFI_UNICAST;
7859 else
7860 pfx_rcd_safi = safi;
7861
7862 if (use_json) {
7863 if (json == NULL)
7864 json = json_object_new_object();
7865
7866 json_peers = json_object_new_object();
7867 } else {
7868 /* Loop over all neighbors that will be displayed to determine
7869 * how many
7870 * characters are needed for the Neighbor column
7871 */
7872 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7873 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7874 continue;
7875
7876 if (peer->afc[afi][safi]) {
7877 memset(dn_flag, '\0', sizeof(dn_flag));
7878 if (peer_dynamic_neighbor(peer))
7879 dn_flag[0] = '*';
7880
7881 if (peer->hostname
7882 && bgp_flag_check(bgp,
7883 BGP_FLAG_SHOW_HOSTNAME))
7884 sprintf(neighbor_buf, "%s%s(%s) ",
7885 dn_flag, peer->hostname,
7886 peer->host);
7887 else
7888 sprintf(neighbor_buf, "%s%s ", dn_flag,
7889 peer->host);
7890
7891 len = strlen(neighbor_buf);
7892
7893 if (len > max_neighbor_width)
7894 max_neighbor_width = len;
7895 }
7896 }
f933309e 7897
d62a17ae 7898 /* Originally we displayed the Neighbor column as 16
7899 * characters wide so make that the default
7900 */
7901 if (max_neighbor_width < neighbor_col_default_width)
7902 max_neighbor_width = neighbor_col_default_width;
7903 }
f933309e 7904
d62a17ae 7905 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7906 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7907 continue;
7908
ea47320b
DL
7909 if (!peer->afc[afi][safi])
7910 continue;
d62a17ae 7911
ea47320b
DL
7912 if (!count) {
7913 unsigned long ents;
7914 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7915 int64_t vrf_id_ui;
d62a17ae 7916
a4d82a8a
PZ
7917 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7918 ? -1
7919 : (int64_t)bgp->vrf_id;
ea47320b
DL
7920
7921 /* Usage summary and header */
7922 if (use_json) {
7923 json_object_string_add(
7924 json, "routerId",
7925 inet_ntoa(bgp->router_id));
60466a63
QY
7926 json_object_int_add(json, "as", bgp->as);
7927 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7928 json_object_string_add(
7929 json, "vrfName",
7930 (bgp->inst_type
7931 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7932 ? VRF_DEFAULT_NAME
ea47320b
DL
7933 : bgp->name);
7934 } else {
7935 vty_out(vty,
7936 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7937 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7938 bgp->vrf_id == VRF_UNKNOWN
7939 ? -1
7940 : (int)bgp->vrf_id);
ea47320b
DL
7941 vty_out(vty, "\n");
7942 }
d62a17ae 7943
ea47320b 7944 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7945 if (use_json) {
ea47320b 7946 json_object_int_add(
60466a63 7947 json, "updateDelayLimit",
ea47320b 7948 bgp->v_update_delay);
d62a17ae 7949
ea47320b
DL
7950 if (bgp->v_update_delay
7951 != bgp->v_establish_wait)
d62a17ae 7952 json_object_int_add(
7953 json,
ea47320b
DL
7954 "updateDelayEstablishWait",
7955 bgp->v_establish_wait);
d62a17ae 7956
60466a63 7957 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7958 json_object_string_add(
7959 json,
7960 "updateDelayFirstNeighbor",
7961 bgp->update_delay_begin_time);
7962 json_object_boolean_true_add(
7963 json,
7964 "updateDelayInProgress");
7965 } else {
7966 if (bgp->update_delay_over) {
d62a17ae 7967 json_object_string_add(
7968 json,
7969 "updateDelayFirstNeighbor",
7970 bgp->update_delay_begin_time);
ea47320b 7971 json_object_string_add(
d62a17ae 7972 json,
ea47320b
DL
7973 "updateDelayBestpathResumed",
7974 bgp->update_delay_end_time);
7975 json_object_string_add(
d62a17ae 7976 json,
ea47320b
DL
7977 "updateDelayZebraUpdateResume",
7978 bgp->update_delay_zebra_resume_time);
7979 json_object_string_add(
7980 json,
7981 "updateDelayPeerUpdateResume",
7982 bgp->update_delay_peers_resume_time);
d62a17ae 7983 }
ea47320b
DL
7984 }
7985 } else {
7986 vty_out(vty,
7987 "Read-only mode update-delay limit: %d seconds\n",
7988 bgp->v_update_delay);
7989 if (bgp->v_update_delay
7990 != bgp->v_establish_wait)
d62a17ae 7991 vty_out(vty,
ea47320b
DL
7992 " Establish wait: %d seconds\n",
7993 bgp->v_establish_wait);
d62a17ae 7994
60466a63 7995 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7996 vty_out(vty,
7997 " First neighbor established: %s\n",
7998 bgp->update_delay_begin_time);
7999 vty_out(vty,
8000 " Delay in progress\n");
8001 } else {
8002 if (bgp->update_delay_over) {
d62a17ae 8003 vty_out(vty,
8004 " First neighbor established: %s\n",
8005 bgp->update_delay_begin_time);
8006 vty_out(vty,
ea47320b
DL
8007 " Best-paths resumed: %s\n",
8008 bgp->update_delay_end_time);
8009 vty_out(vty,
8010 " zebra update resumed: %s\n",
8011 bgp->update_delay_zebra_resume_time);
8012 vty_out(vty,
8013 " peers update resumed: %s\n",
8014 bgp->update_delay_peers_resume_time);
d62a17ae 8015 }
8016 }
8017 }
ea47320b 8018 }
d62a17ae 8019
ea47320b
DL
8020 if (use_json) {
8021 if (bgp_maxmed_onstartup_configured(bgp)
8022 && bgp->maxmed_active)
8023 json_object_boolean_true_add(
60466a63 8024 json, "maxMedOnStartup");
ea47320b
DL
8025 if (bgp->v_maxmed_admin)
8026 json_object_boolean_true_add(
60466a63 8027 json, "maxMedAdministrative");
d62a17ae 8028
ea47320b
DL
8029 json_object_int_add(
8030 json, "tableVersion",
60466a63 8031 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8032
60466a63
QY
8033 ents = bgp_table_count(bgp->rib[afi][safi]);
8034 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8035 json_object_int_add(
8036 json, "ribMemory",
8037 ents * sizeof(struct bgp_node));
d62a17ae 8038
ea47320b 8039 ents = listcount(bgp->peer);
60466a63
QY
8040 json_object_int_add(json, "peerCount", ents);
8041 json_object_int_add(json, "peerMemory",
8042 ents * sizeof(struct peer));
d62a17ae 8043
ea47320b
DL
8044 if ((ents = listcount(bgp->group))) {
8045 json_object_int_add(
60466a63 8046 json, "peerGroupCount", ents);
ea47320b
DL
8047 json_object_int_add(
8048 json, "peerGroupMemory",
996c9314
LB
8049 ents * sizeof(struct
8050 peer_group));
ea47320b 8051 }
d62a17ae 8052
ea47320b
DL
8053 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8054 BGP_CONFIG_DAMPENING))
8055 json_object_boolean_true_add(
60466a63 8056 json, "dampeningEnabled");
ea47320b
DL
8057 } else {
8058 if (bgp_maxmed_onstartup_configured(bgp)
8059 && bgp->maxmed_active)
d62a17ae 8060 vty_out(vty,
ea47320b
DL
8061 "Max-med on-startup active\n");
8062 if (bgp->v_maxmed_admin)
d62a17ae 8063 vty_out(vty,
ea47320b 8064 "Max-med administrative active\n");
d62a17ae 8065
60466a63
QY
8066 vty_out(vty, "BGP table version %" PRIu64 "\n",
8067 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8068
60466a63 8069 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8070 vty_out(vty,
8071 "RIB entries %ld, using %s of memory\n",
8072 ents,
996c9314
LB
8073 mtype_memstr(memstrbuf,
8074 sizeof(memstrbuf),
8075 ents * sizeof(struct
8076 bgp_node)));
ea47320b
DL
8077
8078 /* Peer related usage */
8079 ents = listcount(bgp->peer);
60466a63 8080 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8081 ents,
8082 mtype_memstr(
60466a63
QY
8083 memstrbuf, sizeof(memstrbuf),
8084 ents * sizeof(struct peer)));
ea47320b
DL
8085
8086 if ((ents = listcount(bgp->group)))
d62a17ae 8087 vty_out(vty,
ea47320b 8088 "Peer groups %ld, using %s of memory\n",
d62a17ae 8089 ents,
8090 mtype_memstr(
8091 memstrbuf,
8092 sizeof(memstrbuf),
996c9314
LB
8093 ents * sizeof(struct
8094 peer_group)));
d62a17ae 8095
ea47320b
DL
8096 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8097 BGP_CONFIG_DAMPENING))
60466a63 8098 vty_out(vty, "Dampening enabled.\n");
ea47320b 8099 vty_out(vty, "\n");
d62a17ae 8100
ea47320b
DL
8101 /* Subtract 8 here because 'Neighbor' is
8102 * 8 characters */
8103 vty_out(vty, "Neighbor");
60466a63
QY
8104 vty_out(vty, "%*s", max_neighbor_width - 8,
8105 " ");
ea47320b
DL
8106 vty_out(vty,
8107 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8108 }
ea47320b 8109 }
d62a17ae 8110
ea47320b 8111 count++;
d62a17ae 8112
ea47320b
DL
8113 if (use_json) {
8114 json_peer = json_object_new_object();
d62a17ae 8115
b4e9dcba
DD
8116 if (peer_dynamic_neighbor(peer)) {
8117 dn_count++;
60466a63
QY
8118 json_object_boolean_true_add(json_peer,
8119 "dynamicPeer");
b4e9dcba 8120 }
d62a17ae 8121
ea47320b 8122 if (peer->hostname)
60466a63 8123 json_object_string_add(json_peer, "hostname",
ea47320b 8124 peer->hostname);
d62a17ae 8125
ea47320b 8126 if (peer->domainname)
60466a63
QY
8127 json_object_string_add(json_peer, "domainname",
8128 peer->domainname);
d62a17ae 8129
60466a63 8130 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8131 json_object_int_add(json_peer, "version", 4);
60466a63 8132 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8133 PEER_TOTAL_RX(peer));
60466a63 8134 json_object_int_add(json_peer, "msgSent",
0112e9e0 8135 PEER_TOTAL_TX(peer));
ea47320b
DL
8136
8137 json_object_int_add(json_peer, "tableVersion",
8138 peer->version[afi][safi]);
8139 json_object_int_add(json_peer, "outq",
8140 peer->obuf->count);
8141 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8142 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8143 use_json, json_peer);
50e05855
AD
8144
8145 /*
8146 * Adding "pfxRcd" field to match with the corresponding
8147 * CLI. "prefixReceivedCount" will be deprecated in
8148 * future.
8149 */
60466a63
QY
8150 json_object_int_add(json_peer, "prefixReceivedCount",
8151 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8152 json_object_int_add(json_peer, "pfxRcd",
8153 peer->pcount[afi][pfx_rcd_safi]);
8154
8155 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8156 if (paf && PAF_SUBGRP(paf))
8157 json_object_int_add(json_peer,
8158 "pfxSnt",
8159 (PAF_SUBGRP(paf))->scount);
d62a17ae 8160
ea47320b 8161 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8162 json_object_string_add(json_peer, "state",
ea47320b 8163 "Idle (Admin)");
9199a725
TM
8164 else if (peer->afc_recv[afi][safi])
8165 json_object_string_add(
8166 json_peer, "state",
8167 lookup_msg(bgp_status_msg, peer->status,
8168 NULL));
60466a63
QY
8169 else if (CHECK_FLAG(peer->sflags,
8170 PEER_STATUS_PREFIX_OVERFLOW))
8171 json_object_string_add(json_peer, "state",
ea47320b
DL
8172 "Idle (PfxCt)");
8173 else
8174 json_object_string_add(
8175 json_peer, "state",
60466a63
QY
8176 lookup_msg(bgp_status_msg, peer->status,
8177 NULL));
ea47320b
DL
8178
8179 if (peer->conf_if)
60466a63 8180 json_object_string_add(json_peer, "idType",
ea47320b
DL
8181 "interface");
8182 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8183 json_object_string_add(json_peer, "idType",
8184 "ipv4");
ea47320b 8185 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8186 json_object_string_add(json_peer, "idType",
8187 "ipv6");
d62a17ae 8188
ea47320b
DL
8189 json_object_object_add(json_peers, peer->host,
8190 json_peer);
8191 } else {
8192 memset(dn_flag, '\0', sizeof(dn_flag));
8193 if (peer_dynamic_neighbor(peer)) {
8194 dn_count++;
8195 dn_flag[0] = '*';
8196 }
d62a17ae 8197
ea47320b 8198 if (peer->hostname
60466a63 8199 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8200 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8201 peer->hostname, peer->host);
ea47320b 8202 else
60466a63 8203 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8204
8205 /* pad the neighbor column with spaces */
8206 if (len < max_neighbor_width)
60466a63
QY
8207 vty_out(vty, "%*s", max_neighbor_width - len,
8208 " ");
ea47320b 8209
86a55b99 8210 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8211 peer->as, PEER_TOTAL_RX(peer),
8212 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8213 0, peer->obuf->count,
d62a17ae 8214 peer_uptime(peer->uptime, timebuf,
ea47320b 8215 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8216
ea47320b 8217 if (peer->status == Established)
2f8f4f10 8218 if (peer->afc_recv[afi][safi])
95077abf 8219 vty_out(vty, " %12ld",
a4d82a8a
PZ
8220 peer->pcount[afi]
8221 [pfx_rcd_safi]);
95077abf
DW
8222 else
8223 vty_out(vty, " NoNeg");
ea47320b 8224 else {
60466a63 8225 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8226 vty_out(vty, " Idle (Admin)");
60466a63
QY
8227 else if (CHECK_FLAG(
8228 peer->sflags,
8229 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8230 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8231 else
ea47320b 8232 vty_out(vty, " %12s",
60466a63
QY
8233 lookup_msg(bgp_status_msg,
8234 peer->status, NULL));
d62a17ae 8235 }
ea47320b 8236 vty_out(vty, "\n");
d62a17ae 8237 }
8238 }
f933309e 8239
d62a17ae 8240 if (use_json) {
8241 json_object_object_add(json, "peers", json_peers);
8242
8243 json_object_int_add(json, "totalPeers", count);
8244 json_object_int_add(json, "dynamicPeers", dn_count);
8245
57a9c8a8
DS
8246 bgp_show_bestpath_json(bgp, json);
8247
996c9314
LB
8248 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8249 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8250 json_object_free(json);
8251 } else {
8252 if (count)
8253 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8254 else {
d6ceaca3 8255 vty_out(vty, "No %s neighbor is configured\n",
8256 afi_safi_print(afi, safi));
d62a17ae 8257 }
b05a1c8b 8258
d6ceaca3 8259 if (dn_count) {
d62a17ae 8260 vty_out(vty, "* - dynamic neighbor\n");
8261 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8262 dn_count, bgp->dynamic_neighbors_limit);
8263 }
8264 }
1ff9a340 8265
d62a17ae 8266 return CMD_SUCCESS;
718e3744 8267}
8268
d62a17ae 8269static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8270 int safi, bool use_json,
d62a17ae 8271 json_object *json)
8272{
8273 int is_first = 1;
8274 int afi_wildcard = (afi == AFI_MAX);
8275 int safi_wildcard = (safi == SAFI_MAX);
8276 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8277 bool nbr_output = false;
d62a17ae 8278
8279 if (use_json && is_wildcard)
8280 vty_out(vty, "{\n");
8281 if (afi_wildcard)
8282 afi = 1; /* AFI_IP */
8283 while (afi < AFI_MAX) {
8284 if (safi_wildcard)
8285 safi = 1; /* SAFI_UNICAST */
8286 while (safi < SAFI_MAX) {
318cac96 8287 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8288 nbr_output = true;
d62a17ae 8289 if (is_wildcard) {
8290 /*
8291 * So limit output to those afi/safi
8292 * pairs that
8293 * actualy have something interesting in
8294 * them
8295 */
8296 if (use_json) {
8297 json = json_object_new_object();
8298
8299 if (!is_first)
8300 vty_out(vty, ",\n");
8301 else
8302 is_first = 0;
8303
8304 vty_out(vty, "\"%s\":",
8305 afi_safi_json(afi,
8306 safi));
8307 } else {
8308 vty_out(vty, "\n%s Summary:\n",
8309 afi_safi_print(afi,
8310 safi));
8311 }
8312 }
8313 bgp_show_summary(vty, bgp, afi, safi, use_json,
8314 json);
8315 }
8316 safi++;
d62a17ae 8317 if (!safi_wildcard)
8318 safi = SAFI_MAX;
8319 }
8320 afi++;
ee851c8c 8321 if (!afi_wildcard)
d62a17ae 8322 afi = AFI_MAX;
8323 }
8324
8325 if (use_json && is_wildcard)
8326 vty_out(vty, "}\n");
ca61fd25
DS
8327 else if (!nbr_output) {
8328 if (use_json)
8329 vty_out(vty, "{}\n");
8330 else
8331 vty_out(vty, "%% No BGP neighbors found\n");
8332 }
d62a17ae 8333}
8334
8335static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8336 safi_t safi, bool use_json)
d62a17ae 8337{
8338 struct listnode *node, *nnode;
8339 struct bgp *bgp;
8340 json_object *json = NULL;
8341 int is_first = 1;
9f049418 8342 bool nbr_output = false;
d62a17ae 8343
8344 if (use_json)
8345 vty_out(vty, "{\n");
8346
8347 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8348 nbr_output = true;
d62a17ae 8349 if (use_json) {
8350 json = json_object_new_object();
8351
8352 if (!is_first)
8353 vty_out(vty, ",\n");
8354 else
8355 is_first = 0;
8356
8357 vty_out(vty, "\"%s\":",
8358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8359 ? VRF_DEFAULT_NAME
d62a17ae 8360 : bgp->name);
8361 } else {
8362 vty_out(vty, "\nInstance %s:\n",
8363 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8364 ? VRF_DEFAULT_NAME
d62a17ae 8365 : bgp->name);
8366 }
8367 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8368 }
8369
8370 if (use_json)
8371 vty_out(vty, "}\n");
9f049418
DS
8372 else if (!nbr_output)
8373 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8374}
8375
8376int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8377 safi_t safi, bool use_json)
d62a17ae 8378{
8379 struct bgp *bgp;
8380
8381 if (name) {
8382 if (strmatch(name, "all")) {
8383 bgp_show_all_instances_summary_vty(vty, afi, safi,
8384 use_json);
8385 return CMD_SUCCESS;
8386 } else {
8387 bgp = bgp_lookup_by_name(name);
8388
8389 if (!bgp) {
8390 if (use_json)
8391 vty_out(vty, "{}\n");
8392 else
8393 vty_out(vty,
ca61fd25 8394 "%% BGP instance not found\n");
d62a17ae 8395 return CMD_WARNING;
8396 }
8397
8398 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8399 NULL);
8400 return CMD_SUCCESS;
8401 }
8402 }
8403
8404 bgp = bgp_get_default();
8405
8406 if (bgp)
8407 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8408 else {
ca61fd25
DS
8409 if (use_json)
8410 vty_out(vty, "{}\n");
8411 else
8412 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8413 return CMD_WARNING;
8414 }
d62a17ae 8415
8416 return CMD_SUCCESS;
4fb25c53
DW
8417}
8418
716b2d8a 8419/* `show [ip] bgp summary' commands. */
47fc97cc 8420DEFUN (show_ip_bgp_summary,
718e3744 8421 show_ip_bgp_summary_cmd,
dd6bd0f1 8422 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8423 SHOW_STR
8424 IP_STR
8425 BGP_STR
8386ac43 8426 BGP_INSTANCE_HELP_STR
46f296b4 8427 BGP_AFI_HELP_STR
dd6bd0f1 8428 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8429 "Summary of BGP neighbor status\n"
9973d184 8430 JSON_STR)
718e3744 8431{
d62a17ae 8432 char *vrf = NULL;
8433 afi_t afi = AFI_MAX;
8434 safi_t safi = SAFI_MAX;
8435
8436 int idx = 0;
8437
8438 /* show [ip] bgp */
8439 if (argv_find(argv, argc, "ip", &idx))
8440 afi = AFI_IP;
9a8bdf1c
PG
8441 /* [<vrf> VIEWVRFNAME] */
8442 if (argv_find(argv, argc, "vrf", &idx)) {
8443 vrf = argv[idx + 1]->arg;
8444 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8445 vrf = NULL;
8446 } else if (argv_find(argv, argc, "view", &idx))
8447 /* [<view> VIEWVRFNAME] */
8448 vrf = argv[idx + 1]->arg;
d62a17ae 8449 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8450 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8451 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8452 }
8453
9f049418 8454 bool uj = use_json(argc, argv);
d62a17ae 8455
8456 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8457}
8458
8459const char *afi_safi_print(afi_t afi, safi_t safi)
8460{
8461 if (afi == AFI_IP && safi == SAFI_UNICAST)
8462 return "IPv4 Unicast";
8463 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8464 return "IPv4 Multicast";
8465 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8466 return "IPv4 Labeled Unicast";
8467 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8468 return "IPv4 VPN";
8469 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8470 return "IPv4 Encap";
7c40bf39 8471 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8472 return "IPv4 Flowspec";
d62a17ae 8473 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8474 return "IPv6 Unicast";
8475 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8476 return "IPv6 Multicast";
8477 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8478 return "IPv6 Labeled Unicast";
8479 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8480 return "IPv6 VPN";
8481 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8482 return "IPv6 Encap";
7c40bf39 8483 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8484 return "IPv6 Flowspec";
d62a17ae 8485 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8486 return "L2VPN EVPN";
8487 else
8488 return "Unknown";
538621f2 8489}
8490
b9f77ec8
DS
8491/*
8492 * Please note that we have intentionally camelCased
8493 * the return strings here. So if you want
8494 * to use this function, please ensure you
8495 * are doing this within json output
8496 */
d62a17ae 8497const char *afi_safi_json(afi_t afi, safi_t safi)
8498{
8499 if (afi == AFI_IP && safi == SAFI_UNICAST)
8500 return "ipv4Unicast";
8501 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8502 return "ipv4Multicast";
8503 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8504 return "ipv4LabeledUnicast";
8505 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8506 return "ipv4Vpn";
8507 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8508 return "ipv4Encap";
7c40bf39 8509 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8510 return "ipv4Flowspec";
d62a17ae 8511 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8512 return "ipv6Unicast";
8513 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8514 return "ipv6Multicast";
8515 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8516 return "ipv6LabeledUnicast";
8517 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8518 return "ipv6Vpn";
8519 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8520 return "ipv6Encap";
7c40bf39 8521 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8522 return "ipv6Flowspec";
d62a17ae 8523 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8524 return "l2VpnEvpn";
8525 else
8526 return "Unknown";
27162734
LB
8527}
8528
718e3744 8529/* Show BGP peer's information. */
d1927ebe 8530enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8531
8532static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8533 afi_t afi, safi_t safi,
d7c0a89a
QY
8534 uint16_t adv_smcap, uint16_t adv_rmcap,
8535 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8536 bool use_json, json_object *json_pref)
d62a17ae 8537{
8538 /* Send-Mode */
8539 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8540 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8541 if (use_json) {
8542 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8543 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8544 json_object_string_add(json_pref, "sendMode",
8545 "advertisedAndReceived");
8546 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8547 json_object_string_add(json_pref, "sendMode",
8548 "advertised");
8549 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8550 json_object_string_add(json_pref, "sendMode",
8551 "received");
8552 } else {
8553 vty_out(vty, " Send-mode: ");
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8555 vty_out(vty, "advertised");
8556 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8557 vty_out(vty, "%sreceived",
8558 CHECK_FLAG(p->af_cap[afi][safi],
8559 adv_smcap)
8560 ? ", "
8561 : "");
8562 vty_out(vty, "\n");
8563 }
8564 }
8565
8566 /* Receive-Mode */
8567 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8568 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8569 if (use_json) {
8570 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8571 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8572 json_object_string_add(json_pref, "recvMode",
8573 "advertisedAndReceived");
8574 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8575 json_object_string_add(json_pref, "recvMode",
8576 "advertised");
8577 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8578 json_object_string_add(json_pref, "recvMode",
8579 "received");
8580 } else {
8581 vty_out(vty, " Receive-mode: ");
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8583 vty_out(vty, "advertised");
8584 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8585 vty_out(vty, "%sreceived",
8586 CHECK_FLAG(p->af_cap[afi][safi],
8587 adv_rmcap)
8588 ? ", "
8589 : "");
8590 vty_out(vty, "\n");
8591 }
8592 }
8593}
8594
8595static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8596 safi_t safi, bool use_json,
d62a17ae 8597 json_object *json_neigh)
8598{
0291c246
MK
8599 struct bgp_filter *filter;
8600 struct peer_af *paf;
8601 char orf_pfx_name[BUFSIZ];
8602 int orf_pfx_count;
8603 json_object *json_af = NULL;
8604 json_object *json_prefA = NULL;
8605 json_object *json_prefB = NULL;
8606 json_object *json_addr = NULL;
d62a17ae 8607
8608 if (use_json) {
8609 json_addr = json_object_new_object();
8610 json_af = json_object_new_object();
8611 filter = &p->filter[afi][safi];
8612
8613 if (peer_group_active(p))
8614 json_object_string_add(json_addr, "peerGroupMember",
8615 p->group->name);
8616
8617 paf = peer_af_find(p, afi, safi);
8618 if (paf && PAF_SUBGRP(paf)) {
8619 json_object_int_add(json_addr, "updateGroupId",
8620 PAF_UPDGRP(paf)->id);
8621 json_object_int_add(json_addr, "subGroupId",
8622 PAF_SUBGRP(paf)->id);
8623 json_object_int_add(json_addr, "packetQueueLength",
8624 bpacket_queue_virtual_length(paf));
8625 }
8626
8627 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8628 || CHECK_FLAG(p->af_cap[afi][safi],
8629 PEER_CAP_ORF_PREFIX_SM_RCV)
8630 || CHECK_FLAG(p->af_cap[afi][safi],
8631 PEER_CAP_ORF_PREFIX_RM_ADV)
8632 || CHECK_FLAG(p->af_cap[afi][safi],
8633 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8634 json_object_int_add(json_af, "orfType",
8635 ORF_TYPE_PREFIX);
8636 json_prefA = json_object_new_object();
8637 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8638 PEER_CAP_ORF_PREFIX_SM_ADV,
8639 PEER_CAP_ORF_PREFIX_RM_ADV,
8640 PEER_CAP_ORF_PREFIX_SM_RCV,
8641 PEER_CAP_ORF_PREFIX_RM_RCV,
8642 use_json, json_prefA);
8643 json_object_object_add(json_af, "orfPrefixList",
8644 json_prefA);
8645 }
8646
8647 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8648 || CHECK_FLAG(p->af_cap[afi][safi],
8649 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8650 || CHECK_FLAG(p->af_cap[afi][safi],
8651 PEER_CAP_ORF_PREFIX_RM_ADV)
8652 || CHECK_FLAG(p->af_cap[afi][safi],
8653 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8654 json_object_int_add(json_af, "orfOldType",
8655 ORF_TYPE_PREFIX_OLD);
8656 json_prefB = json_object_new_object();
8657 bgp_show_peer_afi_orf_cap(
8658 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8659 PEER_CAP_ORF_PREFIX_RM_ADV,
8660 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8661 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8662 json_prefB);
8663 json_object_object_add(json_af, "orfOldPrefixList",
8664 json_prefB);
8665 }
8666
8667 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8668 || CHECK_FLAG(p->af_cap[afi][safi],
8669 PEER_CAP_ORF_PREFIX_SM_RCV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_RM_ADV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_RCV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8678 json_object_object_add(json_addr, "afDependentCap",
8679 json_af);
8680 else
8681 json_object_free(json_af);
8682
8683 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8684 orf_pfx_count = prefix_bgp_show_prefix_list(
8685 NULL, afi, orf_pfx_name, use_json);
8686
8687 if (CHECK_FLAG(p->af_sflags[afi][safi],
8688 PEER_STATUS_ORF_PREFIX_SEND)
8689 || orf_pfx_count) {
8690 if (CHECK_FLAG(p->af_sflags[afi][safi],
8691 PEER_STATUS_ORF_PREFIX_SEND))
8692 json_object_boolean_true_add(json_neigh,
8693 "orfSent");
8694 if (orf_pfx_count)
8695 json_object_int_add(json_addr, "orfRecvCounter",
8696 orf_pfx_count);
8697 }
8698 if (CHECK_FLAG(p->af_sflags[afi][safi],
8699 PEER_STATUS_ORF_WAIT_REFRESH))
8700 json_object_string_add(
8701 json_addr, "orfFirstUpdate",
8702 "deferredUntilORFOrRouteRefreshRecvd");
8703
8704 if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_REFLECTOR_CLIENT))
8706 json_object_boolean_true_add(json_addr,
8707 "routeReflectorClient");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_RSERVER_CLIENT))
8710 json_object_boolean_true_add(json_addr,
8711 "routeServerClient");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8713 json_object_boolean_true_add(json_addr,
8714 "inboundSoftConfigPermit");
8715
8716 if (CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8718 json_object_boolean_true_add(
8719 json_addr,
8720 "privateAsNumsAllReplacedInUpdatesToNbr");
8721 else if (CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8723 json_object_boolean_true_add(
8724 json_addr,
8725 "privateAsNumsReplacedInUpdatesToNbr");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8728 json_object_boolean_true_add(
8729 json_addr,
8730 "privateAsNumsAllRemovedInUpdatesToNbr");
8731 else if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsRemovedInUpdatesToNbr");
8736
dcc68b5e
MS
8737 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8738 json_object_boolean_true_add(
8739 json_addr,
8740 bgp_addpath_names(p->addpath_type[afi][safi])
8741 ->type_json_name);
d62a17ae 8742
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8744 json_object_string_add(json_addr,
8745 "overrideASNsInOutboundUpdates",
8746 "ifAspathEqualRemoteAs");
8747
8748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8749 || CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_FORCE_NEXTHOP_SELF))
8751 json_object_boolean_true_add(json_addr,
8752 "routerAlwaysNextHop");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_AS_PATH_UNCHANGED))
8755 json_object_boolean_true_add(
8756 json_addr, "unchangedAsPathPropogatedToNbr");
8757 if (CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_NEXTHOP_UNCHANGED))
8759 json_object_boolean_true_add(
8760 json_addr, "unchangedNextHopPropogatedToNbr");
8761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8762 json_object_boolean_true_add(
8763 json_addr, "unchangedMedPropogatedToNbr");
8764 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8765 || CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_SEND_COMMUNITY)
8769 && CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_SEND_EXT_COMMUNITY))
8771 json_object_string_add(json_addr,
8772 "commAttriSentToNbr",
8773 "extendedAndStandard");
8774 else if (CHECK_FLAG(p->af_flags[afi][safi],
8775 PEER_FLAG_SEND_EXT_COMMUNITY))
8776 json_object_string_add(json_addr,
8777 "commAttriSentToNbr",
8778 "extended");
8779 else
8780 json_object_string_add(json_addr,
8781 "commAttriSentToNbr",
8782 "standard");
8783 }
8784 if (CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_DEFAULT_ORIGINATE)) {
8786 if (p->default_rmap[afi][safi].name)
8787 json_object_string_add(
8788 json_addr, "defaultRouteMap",
8789 p->default_rmap[afi][safi].name);
8790
8791 if (paf && PAF_SUBGRP(paf)
8792 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8793 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8794 json_object_boolean_true_add(json_addr,
8795 "defaultSent");
8796 else
8797 json_object_boolean_true_add(json_addr,
8798 "defaultNotSent");
8799 }
8800
dff8f48d 8801 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8802 if (is_evpn_enabled())
60466a63
QY
8803 json_object_boolean_true_add(
8804 json_addr, "advertiseAllVnis");
dff8f48d
MK
8805 }
8806
d62a17ae 8807 if (filter->plist[FILTER_IN].name
8808 || filter->dlist[FILTER_IN].name
8809 || filter->aslist[FILTER_IN].name
8810 || filter->map[RMAP_IN].name)
8811 json_object_boolean_true_add(json_addr,
8812 "inboundPathPolicyConfig");
8813 if (filter->plist[FILTER_OUT].name
8814 || filter->dlist[FILTER_OUT].name
8815 || filter->aslist[FILTER_OUT].name
8816 || filter->map[RMAP_OUT].name || filter->usmap.name)
8817 json_object_boolean_true_add(
8818 json_addr, "outboundPathPolicyConfig");
8819
8820 /* prefix-list */
8821 if (filter->plist[FILTER_IN].name)
8822 json_object_string_add(json_addr,
8823 "incomingUpdatePrefixFilterList",
8824 filter->plist[FILTER_IN].name);
8825 if (filter->plist[FILTER_OUT].name)
8826 json_object_string_add(json_addr,
8827 "outgoingUpdatePrefixFilterList",
8828 filter->plist[FILTER_OUT].name);
8829
8830 /* distribute-list */
8831 if (filter->dlist[FILTER_IN].name)
8832 json_object_string_add(
8833 json_addr, "incomingUpdateNetworkFilterList",
8834 filter->dlist[FILTER_IN].name);
8835 if (filter->dlist[FILTER_OUT].name)
8836 json_object_string_add(
8837 json_addr, "outgoingUpdateNetworkFilterList",
8838 filter->dlist[FILTER_OUT].name);
8839
8840 /* filter-list. */
8841 if (filter->aslist[FILTER_IN].name)
8842 json_object_string_add(json_addr,
8843 "incomingUpdateAsPathFilterList",
8844 filter->aslist[FILTER_IN].name);
8845 if (filter->aslist[FILTER_OUT].name)
8846 json_object_string_add(json_addr,
8847 "outgoingUpdateAsPathFilterList",
8848 filter->aslist[FILTER_OUT].name);
8849
8850 /* route-map. */
8851 if (filter->map[RMAP_IN].name)
8852 json_object_string_add(
8853 json_addr, "routeMapForIncomingAdvertisements",
8854 filter->map[RMAP_IN].name);
8855 if (filter->map[RMAP_OUT].name)
8856 json_object_string_add(
8857 json_addr, "routeMapForOutgoingAdvertisements",
8858 filter->map[RMAP_OUT].name);
8859
9dac9fc8
DA
8860 /* ebgp-requires-policy (inbound) */
8861 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8862 && !bgp_inbound_policy_exists(p, filter))
8863 json_object_string_add(
8864 json_addr, "inboundEbgpRequiresPolicy",
8865 "Inbound updates discarded due to missing policy");
8866
8867 /* ebgp-requires-policy (outbound) */
8868 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8869 && (!bgp_outbound_policy_exists(p, filter)))
8870 json_object_string_add(
8871 json_addr, "outboundEbgpRequiresPolicy",
8872 "Outbound updates discarded due to missing policy");
8873
d62a17ae 8874 /* unsuppress-map */
8875 if (filter->usmap.name)
8876 json_object_string_add(json_addr,
8877 "selectiveUnsuppressRouteMap",
8878 filter->usmap.name);
8879
8880 /* Receive prefix count */
8881 json_object_int_add(json_addr, "acceptedPrefixCounter",
8882 p->pcount[afi][safi]);
50e05855
AD
8883 if (paf && PAF_SUBGRP(paf))
8884 json_object_int_add(json_addr, "sentPrefixCounter",
8885 (PAF_SUBGRP(paf))->scount);
d62a17ae 8886
8887 /* Maximum prefix */
8888 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8889 json_object_int_add(json_addr, "prefixAllowedMax",
8890 p->pmax[afi][safi]);
8891 if (CHECK_FLAG(p->af_flags[afi][safi],
8892 PEER_FLAG_MAX_PREFIX_WARNING))
8893 json_object_boolean_true_add(
8894 json_addr, "prefixAllowedMaxWarning");
8895 json_object_int_add(json_addr,
8896 "prefixAllowedWarningThresh",
8897 p->pmax_threshold[afi][safi]);
8898 if (p->pmax_restart[afi][safi])
8899 json_object_int_add(
8900 json_addr,
8901 "prefixAllowedRestartIntervalMsecs",
8902 p->pmax_restart[afi][safi] * 60000);
8903 }
8904 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8905 json_addr);
8906
8907 } else {
8908 filter = &p->filter[afi][safi];
8909
8910 vty_out(vty, " For address family: %s\n",
8911 afi_safi_print(afi, safi));
8912
8913 if (peer_group_active(p))
8914 vty_out(vty, " %s peer-group member\n",
8915 p->group->name);
8916
8917 paf = peer_af_find(p, afi, safi);
8918 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8919 vty_out(vty, " Update group %" PRIu64
8920 ", subgroup %" PRIu64 "\n",
d62a17ae 8921 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8922 vty_out(vty, " Packet Queue length %d\n",
8923 bpacket_queue_virtual_length(paf));
8924 } else {
8925 vty_out(vty, " Not part of any update group\n");
8926 }
8927 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8928 || CHECK_FLAG(p->af_cap[afi][safi],
8929 PEER_CAP_ORF_PREFIX_SM_RCV)
8930 || CHECK_FLAG(p->af_cap[afi][safi],
8931 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8932 || CHECK_FLAG(p->af_cap[afi][safi],
8933 PEER_CAP_ORF_PREFIX_RM_ADV)
8934 || CHECK_FLAG(p->af_cap[afi][safi],
8935 PEER_CAP_ORF_PREFIX_RM_RCV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8938 vty_out(vty, " AF-dependant capabilities:\n");
8939
8940 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8941 || CHECK_FLAG(p->af_cap[afi][safi],
8942 PEER_CAP_ORF_PREFIX_SM_RCV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_RM_ADV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8947 vty_out(vty,
8948 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8949 ORF_TYPE_PREFIX);
8950 bgp_show_peer_afi_orf_cap(
8951 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8952 PEER_CAP_ORF_PREFIX_RM_ADV,
8953 PEER_CAP_ORF_PREFIX_SM_RCV,
8954 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8955 }
8956 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8957 || CHECK_FLAG(p->af_cap[afi][safi],
8958 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8959 || CHECK_FLAG(p->af_cap[afi][safi],
8960 PEER_CAP_ORF_PREFIX_RM_ADV)
8961 || CHECK_FLAG(p->af_cap[afi][safi],
8962 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8963 vty_out(vty,
8964 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8965 ORF_TYPE_PREFIX_OLD);
8966 bgp_show_peer_afi_orf_cap(
8967 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8968 PEER_CAP_ORF_PREFIX_RM_ADV,
8969 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8970 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8971 }
8972
8973 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8974 orf_pfx_count = prefix_bgp_show_prefix_list(
8975 NULL, afi, orf_pfx_name, use_json);
8976
8977 if (CHECK_FLAG(p->af_sflags[afi][safi],
8978 PEER_STATUS_ORF_PREFIX_SEND)
8979 || orf_pfx_count) {
8980 vty_out(vty, " Outbound Route Filter (ORF):");
8981 if (CHECK_FLAG(p->af_sflags[afi][safi],
8982 PEER_STATUS_ORF_PREFIX_SEND))
8983 vty_out(vty, " sent;");
8984 if (orf_pfx_count)
8985 vty_out(vty, " received (%d entries)",
8986 orf_pfx_count);
8987 vty_out(vty, "\n");
8988 }
8989 if (CHECK_FLAG(p->af_sflags[afi][safi],
8990 PEER_STATUS_ORF_WAIT_REFRESH))
8991 vty_out(vty,
8992 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8993
8994 if (CHECK_FLAG(p->af_flags[afi][safi],
8995 PEER_FLAG_REFLECTOR_CLIENT))
8996 vty_out(vty, " Route-Reflector Client\n");
8997 if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_RSERVER_CLIENT))
8999 vty_out(vty, " Route-Server Client\n");
9000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9001 vty_out(vty,
9002 " Inbound soft reconfiguration allowed\n");
9003
9004 if (CHECK_FLAG(p->af_flags[afi][safi],
9005 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9006 vty_out(vty,
9007 " Private AS numbers (all) replaced in updates to this neighbor\n");
9008 else if (CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9010 vty_out(vty,
9011 " Private AS numbers replaced in updates to this neighbor\n");
9012 else if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9014 vty_out(vty,
9015 " Private AS numbers (all) removed in updates to this neighbor\n");
9016 else if (CHECK_FLAG(p->af_flags[afi][safi],
9017 PEER_FLAG_REMOVE_PRIVATE_AS))
9018 vty_out(vty,
9019 " Private AS numbers removed in updates to this neighbor\n");
9020
dcc68b5e
MS
9021 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9022 vty_out(vty, " %s\n",
9023 bgp_addpath_names(p->addpath_type[afi][safi])
9024 ->human_description);
d62a17ae 9025
9026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9027 vty_out(vty,
9028 " Override ASNs in outbound updates if aspath equals remote-as\n");
9029
9030 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9031 || CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_FORCE_NEXTHOP_SELF))
9033 vty_out(vty, " NEXT_HOP is always this router\n");
9034 if (CHECK_FLAG(p->af_flags[afi][safi],
9035 PEER_FLAG_AS_PATH_UNCHANGED))
9036 vty_out(vty,
9037 " AS_PATH is propagated unchanged to this neighbor\n");
9038 if (CHECK_FLAG(p->af_flags[afi][safi],
9039 PEER_FLAG_NEXTHOP_UNCHANGED))
9040 vty_out(vty,
9041 " NEXT_HOP is propagated unchanged to this neighbor\n");
9042 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9043 vty_out(vty,
9044 " MED is propagated unchanged to this neighbor\n");
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_SEND_EXT_COMMUNITY)
9048 || CHECK_FLAG(p->af_flags[afi][safi],
9049 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9050 vty_out(vty,
9051 " Community attribute sent to this neighbor");
9052 if (CHECK_FLAG(p->af_flags[afi][safi],
9053 PEER_FLAG_SEND_COMMUNITY)
9054 && CHECK_FLAG(p->af_flags[afi][safi],
9055 PEER_FLAG_SEND_EXT_COMMUNITY)
9056 && CHECK_FLAG(p->af_flags[afi][safi],
9057 PEER_FLAG_SEND_LARGE_COMMUNITY))
9058 vty_out(vty, "(all)\n");
9059 else if (CHECK_FLAG(p->af_flags[afi][safi],
9060 PEER_FLAG_SEND_LARGE_COMMUNITY))
9061 vty_out(vty, "(large)\n");
9062 else if (CHECK_FLAG(p->af_flags[afi][safi],
9063 PEER_FLAG_SEND_EXT_COMMUNITY))
9064 vty_out(vty, "(extended)\n");
9065 else
9066 vty_out(vty, "(standard)\n");
9067 }
9068 if (CHECK_FLAG(p->af_flags[afi][safi],
9069 PEER_FLAG_DEFAULT_ORIGINATE)) {
9070 vty_out(vty, " Default information originate,");
9071
9072 if (p->default_rmap[afi][safi].name)
9073 vty_out(vty, " default route-map %s%s,",
9074 p->default_rmap[afi][safi].map ? "*"
9075 : "",
9076 p->default_rmap[afi][safi].name);
9077 if (paf && PAF_SUBGRP(paf)
9078 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9079 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9080 vty_out(vty, " default sent\n");
9081 else
9082 vty_out(vty, " default not sent\n");
9083 }
9084
dff8f48d
MK
9085 /* advertise-vni-all */
9086 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9087 if (is_evpn_enabled())
dff8f48d
MK
9088 vty_out(vty, " advertise-all-vni\n");
9089 }
9090
d62a17ae 9091 if (filter->plist[FILTER_IN].name
9092 || filter->dlist[FILTER_IN].name
9093 || filter->aslist[FILTER_IN].name
9094 || filter->map[RMAP_IN].name)
9095 vty_out(vty, " Inbound path policy configured\n");
9096 if (filter->plist[FILTER_OUT].name
9097 || filter->dlist[FILTER_OUT].name
9098 || filter->aslist[FILTER_OUT].name
9099 || filter->map[RMAP_OUT].name || filter->usmap.name)
9100 vty_out(vty, " Outbound path policy configured\n");
9101
9102 /* prefix-list */
9103 if (filter->plist[FILTER_IN].name)
9104 vty_out(vty,
9105 " Incoming update prefix filter list is %s%s\n",
9106 filter->plist[FILTER_IN].plist ? "*" : "",
9107 filter->plist[FILTER_IN].name);
9108 if (filter->plist[FILTER_OUT].name)
9109 vty_out(vty,
9110 " Outgoing update prefix filter list is %s%s\n",
9111 filter->plist[FILTER_OUT].plist ? "*" : "",
9112 filter->plist[FILTER_OUT].name);
9113
9114 /* distribute-list */
9115 if (filter->dlist[FILTER_IN].name)
9116 vty_out(vty,
9117 " Incoming update network filter list is %s%s\n",
9118 filter->dlist[FILTER_IN].alist ? "*" : "",
9119 filter->dlist[FILTER_IN].name);
9120 if (filter->dlist[FILTER_OUT].name)
9121 vty_out(vty,
9122 " Outgoing update network filter list is %s%s\n",
9123 filter->dlist[FILTER_OUT].alist ? "*" : "",
9124 filter->dlist[FILTER_OUT].name);
9125
9126 /* filter-list. */
9127 if (filter->aslist[FILTER_IN].name)
9128 vty_out(vty,
9129 " Incoming update AS path filter list is %s%s\n",
9130 filter->aslist[FILTER_IN].aslist ? "*" : "",
9131 filter->aslist[FILTER_IN].name);
9132 if (filter->aslist[FILTER_OUT].name)
9133 vty_out(vty,
9134 " Outgoing update AS path filter list is %s%s\n",
9135 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9136 filter->aslist[FILTER_OUT].name);
9137
9138 /* route-map. */
9139 if (filter->map[RMAP_IN].name)
9140 vty_out(vty,
9141 " Route map for incoming advertisements is %s%s\n",
9142 filter->map[RMAP_IN].map ? "*" : "",
9143 filter->map[RMAP_IN].name);
9144 if (filter->map[RMAP_OUT].name)
9145 vty_out(vty,
9146 " Route map for outgoing advertisements is %s%s\n",
9147 filter->map[RMAP_OUT].map ? "*" : "",
9148 filter->map[RMAP_OUT].name);
9149
9dac9fc8
DA
9150 /* ebgp-requires-policy (inbound) */
9151 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9152 && !bgp_inbound_policy_exists(p, filter))
9153 vty_out(vty,
9154 " Inbound updates discarded due to missing policy\n");
9155
9156 /* ebgp-requires-policy (outbound) */
9157 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9158 && !bgp_outbound_policy_exists(p, filter))
9159 vty_out(vty,
9160 " Outbound updates discarded due to missing policy\n");
9161
d62a17ae 9162 /* unsuppress-map */
9163 if (filter->usmap.name)
9164 vty_out(vty,
9165 " Route map for selective unsuppress is %s%s\n",
9166 filter->usmap.map ? "*" : "",
9167 filter->usmap.name);
9168
9169 /* Receive prefix count */
9170 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9171
9172 /* Maximum prefix */
9173 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9174 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9175 p->pmax[afi][safi],
9176 CHECK_FLAG(p->af_flags[afi][safi],
9177 PEER_FLAG_MAX_PREFIX_WARNING)
9178 ? " (warning-only)"
9179 : "");
9180 vty_out(vty, " Threshold for warning message %d%%",
9181 p->pmax_threshold[afi][safi]);
9182 if (p->pmax_restart[afi][safi])
9183 vty_out(vty, ", restart interval %d min",
9184 p->pmax_restart[afi][safi]);
9185 vty_out(vty, "\n");
9186 }
9187
9188 vty_out(vty, "\n");
9189 }
9190}
9191
9f049418 9192static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9193 json_object *json)
718e3744 9194{
d62a17ae 9195 struct bgp *bgp;
9196 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9197 char timebuf[BGP_UPTIME_LEN];
9198 char dn_flag[2];
9199 const char *subcode_str;
9200 const char *code_str;
9201 afi_t afi;
9202 safi_t safi;
d7c0a89a
QY
9203 uint16_t i;
9204 uint8_t *msg;
d62a17ae 9205 json_object *json_neigh = NULL;
9206 time_t epoch_tbuf;
718e3744 9207
d62a17ae 9208 bgp = p->bgp;
9209
9210 if (use_json)
9211 json_neigh = json_object_new_object();
9212
9213 memset(dn_flag, '\0', sizeof(dn_flag));
9214 if (!p->conf_if && peer_dynamic_neighbor(p))
9215 dn_flag[0] = '*';
9216
9217 if (!use_json) {
9218 if (p->conf_if) /* Configured interface name. */
9219 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9220 BGP_PEER_SU_UNSPEC(p)
9221 ? "None"
9222 : sockunion2str(&p->su, buf,
9223 SU_ADDRSTRLEN));
9224 else /* Configured IP address. */
9225 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9226 p->host);
9227 }
9228
9229 if (use_json) {
9230 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9231 json_object_string_add(json_neigh, "bgpNeighborAddr",
9232 "none");
9233 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9234 json_object_string_add(
9235 json_neigh, "bgpNeighborAddr",
9236 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9237
9238 json_object_int_add(json_neigh, "remoteAs", p->as);
9239
9240 if (p->change_local_as)
9241 json_object_int_add(json_neigh, "localAs",
9242 p->change_local_as);
9243 else
9244 json_object_int_add(json_neigh, "localAs", p->local_as);
9245
9246 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9247 json_object_boolean_true_add(json_neigh,
9248 "localAsNoPrepend");
9249
9250 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9251 json_object_boolean_true_add(json_neigh,
9252 "localAsReplaceAs");
9253 } else {
9254 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9255 || (p->as_type == AS_INTERNAL))
9256 vty_out(vty, "remote AS %u, ", p->as);
9257 else
9258 vty_out(vty, "remote AS Unspecified, ");
9259 vty_out(vty, "local AS %u%s%s, ",
9260 p->change_local_as ? p->change_local_as : p->local_as,
9261 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9262 ? " no-prepend"
9263 : "",
9264 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9265 ? " replace-as"
9266 : "");
9267 }
faa16034
DS
9268 /* peer type internal or confed-internal */
9269 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9270 if (use_json) {
9271 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9272 json_object_boolean_true_add(
9273 json_neigh, "nbrConfedInternalLink");
9274 else
9275 json_object_boolean_true_add(json_neigh,
9276 "nbrInternalLink");
9277 } else {
9278 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9279 vty_out(vty, "confed-internal link\n");
9280 else
9281 vty_out(vty, "internal link\n");
9282 }
faa16034
DS
9283 /* peer type external or confed-external */
9284 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9285 if (use_json) {
9286 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9287 json_object_boolean_true_add(
9288 json_neigh, "nbrConfedExternalLink");
9289 else
9290 json_object_boolean_true_add(json_neigh,
9291 "nbrExternalLink");
9292 } else {
9293 if (bgp_confederation_peers_check(bgp, p->as))
9294 vty_out(vty, "confed-external link\n");
9295 else
9296 vty_out(vty, "external link\n");
9297 }
faa16034
DS
9298 } else {
9299 if (use_json)
9300 json_object_boolean_true_add(json_neigh,
9301 "nbrUnspecifiedLink");
9302 else
9303 vty_out(vty, "unspecified link\n");
d62a17ae 9304 }
9305
9306 /* Description. */
9307 if (p->desc) {
9308 if (use_json)
9309 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9310 else
9311 vty_out(vty, " Description: %s\n", p->desc);
9312 }
9313
9314 if (p->hostname) {
9315 if (use_json) {
9316 if (p->hostname)
9317 json_object_string_add(json_neigh, "hostname",
9318 p->hostname);
9319
9320 if (p->domainname)
9321 json_object_string_add(json_neigh, "domainname",
9322 p->domainname);
9323 } else {
9324 if (p->domainname && (p->domainname[0] != '\0'))
9325 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9326 p->domainname);
9327 else
9328 vty_out(vty, "Hostname: %s\n", p->hostname);
9329 }
9330 }
9331
9332 /* Peer-group */
9333 if (p->group) {
9334 if (use_json) {
9335 json_object_string_add(json_neigh, "peerGroup",
9336 p->group->name);
9337
9338 if (dn_flag[0]) {
9339 struct prefix prefix, *range = NULL;
9340
9341 sockunion2hostprefix(&(p->su), &prefix);
9342 range = peer_group_lookup_dynamic_neighbor_range(
9343 p->group, &prefix);
9344
9345 if (range) {
9346 prefix2str(range, buf1, sizeof(buf1));
9347 json_object_string_add(
9348 json_neigh,
9349 "peerSubnetRangeGroup", buf1);
9350 }
9351 }
9352 } else {
9353 vty_out(vty,
9354 " Member of peer-group %s for session parameters\n",
9355 p->group->name);
9356
9357 if (dn_flag[0]) {
9358 struct prefix prefix, *range = NULL;
9359
9360 sockunion2hostprefix(&(p->su), &prefix);
9361 range = peer_group_lookup_dynamic_neighbor_range(
9362 p->group, &prefix);
9363
9364 if (range) {
9365 prefix2str(range, buf1, sizeof(buf1));
9366 vty_out(vty,
9367 " Belongs to the subnet range group: %s\n",
9368 buf1);
9369 }
9370 }
9371 }
9372 }
9373
9374 if (use_json) {
9375 /* Administrative shutdown. */
9376 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9377 json_object_boolean_true_add(json_neigh,
9378 "adminShutDown");
9379
9380 /* BGP Version. */
9381 json_object_int_add(json_neigh, "bgpVersion", 4);
9382 json_object_string_add(
9383 json_neigh, "remoteRouterId",
9384 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9385 json_object_string_add(
9386 json_neigh, "localRouterId",
9387 inet_ntop(AF_INET, &bgp->router_id, buf1,
9388 sizeof(buf1)));
d62a17ae 9389
9390 /* Confederation */
9391 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9392 && bgp_confederation_peers_check(bgp, p->as))
9393 json_object_boolean_true_add(json_neigh,
9394 "nbrCommonAdmin");
9395
9396 /* Status. */
9397 json_object_string_add(
9398 json_neigh, "bgpState",
9399 lookup_msg(bgp_status_msg, p->status, NULL));
9400
9401 if (p->status == Established) {
9402 time_t uptime;
d62a17ae 9403
9404 uptime = bgp_clock();
9405 uptime -= p->uptime;
d62a17ae 9406 epoch_tbuf = time(NULL) - uptime;
9407
bee57a7a 9408#if CONFDATE > 20200101
a4d82a8a
PZ
9409 CPP_NOTICE(
9410 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9411#endif
9412 /*
9413 * bgpTimerUp was miliseconds that was accurate
9414 * up to 1 day, then the value returned
9415 * became garbage. So in order to provide
9416 * some level of backwards compatability,
9417 * we still provde the data, but now
9418 * we are returning the correct value
9419 * and also adding a new bgpTimerUpMsec
9420 * which will allow us to deprecate
9421 * this eventually
9422 */
d62a17ae 9423 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9424 uptime * 1000);
d3c7efed
DS
9425 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9426 uptime * 1000);
d62a17ae 9427 json_object_string_add(json_neigh, "bgpTimerUpString",
9428 peer_uptime(p->uptime, timebuf,
9429 BGP_UPTIME_LEN, 0,
9430 NULL));
9431 json_object_int_add(json_neigh,
9432 "bgpTimerUpEstablishedEpoch",
9433 epoch_tbuf);
9434 }
9435
9436 else if (p->status == Active) {
9437 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9438 json_object_string_add(json_neigh, "bgpStateIs",
9439 "passive");
9440 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9441 json_object_string_add(json_neigh, "bgpStateIs",
9442 "passiveNSF");
9443 }
9444
9445 /* read timer */
9446 time_t uptime;
9447 struct tm *tm;
9448
9449 uptime = bgp_clock();
9450 uptime -= p->readtime;
9451 tm = gmtime(&uptime);
9452 json_object_int_add(json_neigh, "bgpTimerLastRead",
9453 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9454 + (tm->tm_hour * 3600000));
9455
9456 uptime = bgp_clock();
9457 uptime -= p->last_write;
9458 tm = gmtime(&uptime);
9459 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9460 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9461 + (tm->tm_hour * 3600000));
9462
9463 uptime = bgp_clock();
9464 uptime -= p->update_time;
9465 tm = gmtime(&uptime);
9466 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9467 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9468 + (tm->tm_hour * 3600000));
9469
9470 /* Configured timer values. */
9471 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9472 p->v_holdtime * 1000);
9473 json_object_int_add(json_neigh,
9474 "bgpTimerKeepAliveIntervalMsecs",
9475 p->v_keepalive * 1000);
b90a8e13 9476 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9477 json_object_int_add(json_neigh,
9478 "bgpTimerConfiguredHoldTimeMsecs",
9479 p->holdtime * 1000);
9480 json_object_int_add(
9481 json_neigh,
9482 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9483 p->keepalive * 1000);
d25e4efc 9484 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9485 || (bgp->default_keepalive
9486 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9487 json_object_int_add(json_neigh,
9488 "bgpTimerConfiguredHoldTimeMsecs",
9489 bgp->default_holdtime);
9490 json_object_int_add(
9491 json_neigh,
9492 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9493 bgp->default_keepalive);
d62a17ae 9494 }
9495 } else {
9496 /* Administrative shutdown. */
9497 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9498 vty_out(vty, " Administratively shut down\n");
9499
9500 /* BGP Version. */
9501 vty_out(vty, " BGP version 4");
0e38aeb4 9502 vty_out(vty, ", remote router ID %s",
d62a17ae 9503 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9504 vty_out(vty, ", local router ID %s\n",
9505 inet_ntop(AF_INET, &bgp->router_id, buf1,
9506 sizeof(buf1)));
d62a17ae 9507
9508 /* Confederation */
9509 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9510 && bgp_confederation_peers_check(bgp, p->as))
9511 vty_out(vty,
9512 " Neighbor under common administration\n");
9513
9514 /* Status. */
9515 vty_out(vty, " BGP state = %s",
9516 lookup_msg(bgp_status_msg, p->status, NULL));
9517
9518 if (p->status == Established)
9519 vty_out(vty, ", up for %8s",
9520 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9521 0, NULL));
9522
9523 else if (p->status == Active) {
9524 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9525 vty_out(vty, " (passive)");
9526 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9527 vty_out(vty, " (NSF passive)");
9528 }
9529 vty_out(vty, "\n");
9530
9531 /* read timer */
9532 vty_out(vty, " Last read %s",
9533 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9534 NULL));
9535 vty_out(vty, ", Last write %s\n",
9536 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9537 NULL));
9538
9539 /* Configured timer values. */
9540 vty_out(vty,
9541 " Hold time is %d, keepalive interval is %d seconds\n",
9542 p->v_holdtime, p->v_keepalive);
b90a8e13 9543 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9544 vty_out(vty, " Configured hold time is %d",
9545 p->holdtime);
9546 vty_out(vty, ", keepalive interval is %d seconds\n",
9547 p->keepalive);
d25e4efc 9548 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9549 || (bgp->default_keepalive
9550 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9551 vty_out(vty, " Configured hold time is %d",
9552 bgp->default_holdtime);
9553 vty_out(vty, ", keepalive interval is %d seconds\n",
9554 bgp->default_keepalive);
d62a17ae 9555 }
9556 }
9557 /* Capability. */
9558 if (p->status == Established) {
9559 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9560 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9561 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9562 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9563 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9564 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9565 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9566 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9567 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9568 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9569 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9570 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9571 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9572 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9573 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9574 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9575 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9576 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9577 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9578 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9579 if (use_json) {
9580 json_object *json_cap = NULL;
9581
9582 json_cap = json_object_new_object();
9583
9584 /* AS4 */
9585 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9586 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9587 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9588 && CHECK_FLAG(p->cap,
9589 PEER_CAP_AS4_RCV))
9590 json_object_string_add(
9591 json_cap, "4byteAs",
9592 "advertisedAndReceived");
9593 else if (CHECK_FLAG(p->cap,
9594 PEER_CAP_AS4_ADV))
9595 json_object_string_add(
9596 json_cap, "4byteAs",
9597 "advertised");
9598 else if (CHECK_FLAG(p->cap,
9599 PEER_CAP_AS4_RCV))
9600 json_object_string_add(
9601 json_cap, "4byteAs",
9602 "received");
9603 }
9604
9605 /* AddPath */
9606 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9607 || CHECK_FLAG(p->cap,
9608 PEER_CAP_ADDPATH_ADV)) {
9609 json_object *json_add = NULL;
9610 const char *print_store;
9611
9612 json_add = json_object_new_object();
9613
05c7a1cc
QY
9614 FOREACH_AFI_SAFI (afi, safi) {
9615 json_object *json_sub = NULL;
9616 json_sub =
9617 json_object_new_object();
9618 print_store = afi_safi_print(
9619 afi, safi);
d62a17ae 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)) {
d62a17ae 9629 if (CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9634 && CHECK_FLAG(
d62a17ae 9635 p->af_cap
9636 [afi]
9637 [safi],
05c7a1cc
QY
9638 PEER_CAP_ADDPATH_AF_TX_RCV))
9639 json_object_boolean_true_add(
9640 json_sub,
9641 "txAdvertisedAndReceived");
9642 else if (
9643 CHECK_FLAG(
9644 p->af_cap
9645 [afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_TX_ADV))
9648 json_object_boolean_true_add(
9649 json_sub,
9650 "txAdvertised");
9651 else if (
9652 CHECK_FLAG(
9653 p->af_cap
9654 [afi]
9655 [safi],
9656 PEER_CAP_ADDPATH_AF_TX_RCV))
9657 json_object_boolean_true_add(
9658 json_sub,
9659 "txReceived");
9660 }
d62a17ae 9661
05c7a1cc
QY
9662 if (CHECK_FLAG(
9663 p->af_cap[afi]
9664 [safi],
9665 PEER_CAP_ADDPATH_AF_RX_ADV)
9666 || CHECK_FLAG(
9667 p->af_cap[afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9670 if (CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9675 && CHECK_FLAG(
d62a17ae 9676 p->af_cap
9677 [afi]
9678 [safi],
9679 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9680 json_object_boolean_true_add(
9681 json_sub,
9682 "rxAdvertisedAndReceived");
9683 else if (
9684 CHECK_FLAG(
9685 p->af_cap
9686 [afi]
9687 [safi],
9688 PEER_CAP_ADDPATH_AF_RX_ADV))
9689 json_object_boolean_true_add(
9690 json_sub,
9691 "rxAdvertised");
9692 else if (
9693 CHECK_FLAG(
9694 p->af_cap
9695 [afi]
9696 [safi],
9697 PEER_CAP_ADDPATH_AF_RX_RCV))
9698 json_object_boolean_true_add(
9699 json_sub,
9700 "rxReceived");
d62a17ae 9701 }
9702
05c7a1cc
QY
9703 if (CHECK_FLAG(
9704 p->af_cap[afi]
9705 [safi],
9706 PEER_CAP_ADDPATH_AF_TX_ADV)
9707 || CHECK_FLAG(
9708 p->af_cap[afi]
9709 [safi],
9710 PEER_CAP_ADDPATH_AF_TX_RCV)
9711 || CHECK_FLAG(
9712 p->af_cap[afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_RX_ADV)
9715 || CHECK_FLAG(
9716 p->af_cap[afi]
9717 [safi],
9718 PEER_CAP_ADDPATH_AF_RX_RCV))
9719 json_object_object_add(
9720 json_add,
9721 print_store,
9722 json_sub);
9723 else
9724 json_object_free(
9725 json_sub);
9726 }
9727
d62a17ae 9728 json_object_object_add(
9729 json_cap, "addPath", json_add);
9730 }
9731
9732 /* Dynamic */
9733 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9734 || CHECK_FLAG(p->cap,
9735 PEER_CAP_DYNAMIC_ADV)) {
9736 if (CHECK_FLAG(p->cap,
9737 PEER_CAP_DYNAMIC_ADV)
9738 && CHECK_FLAG(p->cap,
9739 PEER_CAP_DYNAMIC_RCV))
9740 json_object_string_add(
9741 json_cap, "dynamic",
9742 "advertisedAndReceived");
9743 else if (CHECK_FLAG(
9744 p->cap,
9745 PEER_CAP_DYNAMIC_ADV))
9746 json_object_string_add(
9747 json_cap, "dynamic",
9748 "advertised");
9749 else if (CHECK_FLAG(
9750 p->cap,
9751 PEER_CAP_DYNAMIC_RCV))
9752 json_object_string_add(
9753 json_cap, "dynamic",
9754 "received");
9755 }
9756
9757 /* Extended nexthop */
9758 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9759 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9760 json_object *json_nxt = NULL;
9761 const char *print_store;
9762
9763
9764 if (CHECK_FLAG(p->cap,
9765 PEER_CAP_ENHE_ADV)
9766 && CHECK_FLAG(p->cap,
9767 PEER_CAP_ENHE_RCV))
9768 json_object_string_add(
9769 json_cap,
9770 "extendedNexthop",
9771 "advertisedAndReceived");
9772 else if (CHECK_FLAG(p->cap,
9773 PEER_CAP_ENHE_ADV))
9774 json_object_string_add(
9775 json_cap,
9776 "extendedNexthop",
9777 "advertised");
9778 else if (CHECK_FLAG(p->cap,
9779 PEER_CAP_ENHE_RCV))
9780 json_object_string_add(
9781 json_cap,
9782 "extendedNexthop",
9783 "received");
9784
9785 if (CHECK_FLAG(p->cap,
9786 PEER_CAP_ENHE_RCV)) {
9787 json_nxt =
9788 json_object_new_object();
9789
9790 for (safi = SAFI_UNICAST;
9791 safi < SAFI_MAX; safi++) {
9792 if (CHECK_FLAG(
9793 p->af_cap
9794 [AFI_IP]
9795 [safi],
9796 PEER_CAP_ENHE_AF_RCV)) {
9797 print_store = afi_safi_print(
9798 AFI_IP,
9799 safi);
9800 json_object_string_add(
9801 json_nxt,
9802 print_store,
54f29523 9803 "recieved"); /* misspelled for compatibility */
d62a17ae 9804 }
9805 }
9806 json_object_object_add(
9807 json_cap,
9808 "extendedNexthopFamililesByPeer",
9809 json_nxt);
9810 }
9811 }
9812
9813 /* Route Refresh */
9814 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9815 || CHECK_FLAG(p->cap,
9816 PEER_CAP_REFRESH_NEW_RCV)
9817 || CHECK_FLAG(p->cap,
9818 PEER_CAP_REFRESH_OLD_RCV)) {
9819 if (CHECK_FLAG(p->cap,
9820 PEER_CAP_REFRESH_ADV)
9821 && (CHECK_FLAG(
9822 p->cap,
9823 PEER_CAP_REFRESH_NEW_RCV)
9824 || CHECK_FLAG(
9825 p->cap,
9826 PEER_CAP_REFRESH_OLD_RCV))) {
9827 if (CHECK_FLAG(
9828 p->cap,
9829 PEER_CAP_REFRESH_OLD_RCV)
9830 && CHECK_FLAG(
9831 p->cap,
9832 PEER_CAP_REFRESH_NEW_RCV))
9833 json_object_string_add(
9834 json_cap,
9835 "routeRefresh",
9836 "advertisedAndReceivedOldNew");
9837 else {
9838 if (CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_OLD_RCV))
9841 json_object_string_add(
9842 json_cap,
9843 "routeRefresh",
9844 "advertisedAndReceivedOld");
9845 else
9846 json_object_string_add(
9847 json_cap,
9848 "routeRefresh",
9849 "advertisedAndReceivedNew");
9850 }
9851 } else if (
9852 CHECK_FLAG(
9853 p->cap,
9854 PEER_CAP_REFRESH_ADV))
9855 json_object_string_add(
9856 json_cap,
9857 "routeRefresh",
9858 "advertised");
9859 else if (
9860 CHECK_FLAG(
9861 p->cap,
9862 PEER_CAP_REFRESH_NEW_RCV)
9863 || CHECK_FLAG(
9864 p->cap,
9865 PEER_CAP_REFRESH_OLD_RCV))
9866 json_object_string_add(
9867 json_cap,
9868 "routeRefresh",
9869 "received");
9870 }
9871
9872 /* Multiprotocol Extensions */
9873 json_object *json_multi = NULL;
9874 json_multi = json_object_new_object();
9875
05c7a1cc
QY
9876 FOREACH_AFI_SAFI (afi, safi) {
9877 if (p->afc_adv[afi][safi]
9878 || p->afc_recv[afi][safi]) {
9879 json_object *json_exten = NULL;
9880 json_exten =
9881 json_object_new_object();
9882
d62a17ae 9883 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9884 && p->afc_recv[afi][safi])
9885 json_object_boolean_true_add(
9886 json_exten,
9887 "advertisedAndReceived");
9888 else if (p->afc_adv[afi][safi])
9889 json_object_boolean_true_add(
9890 json_exten,
9891 "advertised");
9892 else if (p->afc_recv[afi][safi])
9893 json_object_boolean_true_add(
9894 json_exten,
9895 "received");
d62a17ae 9896
05c7a1cc
QY
9897 json_object_object_add(
9898 json_multi,
9899 afi_safi_print(afi,
9900 safi),
9901 json_exten);
d62a17ae 9902 }
9903 }
9904 json_object_object_add(
9905 json_cap, "multiprotocolExtensions",
9906 json_multi);
9907
d77114b7 9908 /* Hostname capabilities */
60466a63 9909 json_object *json_hname = NULL;
d77114b7
MK
9910
9911 json_hname = json_object_new_object();
9912
9913 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9914 json_object_string_add(
60466a63
QY
9915 json_hname, "advHostName",
9916 bgp->peer_self->hostname
9917 ? bgp->peer_self
9918 ->hostname
d77114b7
MK
9919 : "n/a");
9920 json_object_string_add(
60466a63
QY
9921 json_hname, "advDomainName",
9922 bgp->peer_self->domainname
9923 ? bgp->peer_self
9924 ->domainname
d77114b7
MK
9925 : "n/a");
9926 }
9927
9928
9929 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9930 json_object_string_add(
60466a63
QY
9931 json_hname, "rcvHostName",
9932 p->hostname ? p->hostname
9933 : "n/a");
d77114b7 9934 json_object_string_add(
60466a63
QY
9935 json_hname, "rcvDomainName",
9936 p->domainname ? p->domainname
9937 : "n/a");
d77114b7
MK
9938 }
9939
60466a63 9940 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9941 json_hname);
9942
d62a17ae 9943 /* Gracefull Restart */
9944 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_RESTART_ADV)) {
9947 if (CHECK_FLAG(p->cap,
9948 PEER_CAP_RESTART_ADV)
9949 && CHECK_FLAG(p->cap,
9950 PEER_CAP_RESTART_RCV))
9951 json_object_string_add(
9952 json_cap,
9953 "gracefulRestart",
9954 "advertisedAndReceived");
9955 else if (CHECK_FLAG(
9956 p->cap,
9957 PEER_CAP_RESTART_ADV))
9958 json_object_string_add(
9959 json_cap,
9960 "gracefulRestartCapability",
9961 "advertised");
9962 else if (CHECK_FLAG(
9963 p->cap,
9964 PEER_CAP_RESTART_RCV))
9965 json_object_string_add(
9966 json_cap,
9967 "gracefulRestartCapability",
9968 "received");
9969
9970 if (CHECK_FLAG(p->cap,
9971 PEER_CAP_RESTART_RCV)) {
9972 int restart_af_count = 0;
9973 json_object *json_restart =
9974 NULL;
9975 json_restart =
9976 json_object_new_object();
9977
9978 json_object_int_add(
9979 json_cap,
9980 "gracefulRestartRemoteTimerMsecs",
9981 p->v_gr_restart * 1000);
9982
05c7a1cc
QY
9983 FOREACH_AFI_SAFI (afi, safi) {
9984 if (CHECK_FLAG(
9985 p->af_cap
9986 [afi]
9987 [safi],
9988 PEER_CAP_RESTART_AF_RCV)) {
9989 json_object *
9990 json_sub =
9991 NULL;
9992 json_sub =
9993 json_object_new_object();
9994
d62a17ae 9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
05c7a1cc
QY
9999 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10000 json_object_boolean_true_add(
10001 json_sub,
10002 "preserved");
10003 restart_af_count++;
10004 json_object_object_add(
10005 json_restart,
10006 afi_safi_print(
10007 afi,
10008 safi),
10009 json_sub);
d62a17ae 10010 }
10011 }
10012 if (!restart_af_count) {
10013 json_object_string_add(
10014 json_cap,
10015 "addressFamiliesByPeer",
10016 "none");
10017 json_object_free(
10018 json_restart);
10019 } else
10020 json_object_object_add(
10021 json_cap,
10022 "addressFamiliesByPeer",
10023 json_restart);
10024 }
10025 }
10026 json_object_object_add(json_neigh,
10027 "neighborCapabilities",
10028 json_cap);
10029 } else {
10030 vty_out(vty, " Neighbor capabilities:\n");
10031
10032 /* AS4 */
10033 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10034 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10035 vty_out(vty, " 4 Byte AS:");
10036 if (CHECK_FLAG(p->cap,
10037 PEER_CAP_AS4_ADV))
10038 vty_out(vty, " advertised");
10039 if (CHECK_FLAG(p->cap,
10040 PEER_CAP_AS4_RCV))
10041 vty_out(vty, " %sreceived",
10042 CHECK_FLAG(
10043 p->cap,
10044 PEER_CAP_AS4_ADV)
10045 ? "and "
10046 : "");
10047 vty_out(vty, "\n");
10048 }
10049
10050 /* AddPath */
10051 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10052 || CHECK_FLAG(p->cap,
10053 PEER_CAP_ADDPATH_ADV)) {
10054 vty_out(vty, " AddPath:\n");
10055
05c7a1cc
QY
10056 FOREACH_AFI_SAFI (afi, safi) {
10057 if (CHECK_FLAG(
10058 p->af_cap[afi]
10059 [safi],
10060 PEER_CAP_ADDPATH_AF_TX_ADV)
10061 || CHECK_FLAG(
10062 p->af_cap[afi]
10063 [safi],
10064 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10065 vty_out(vty,
10066 " %s: TX ",
10067 afi_safi_print(
10068 afi,
10069 safi));
10070
d62a17ae 10071 if (CHECK_FLAG(
10072 p->af_cap
10073 [afi]
10074 [safi],
05c7a1cc 10075 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10076 vty_out(vty,
05c7a1cc 10077 "advertised %s",
d62a17ae 10078 afi_safi_print(
10079 afi,
10080 safi));
10081
05c7a1cc
QY
10082 if (CHECK_FLAG(
10083 p->af_cap
10084 [afi]
10085 [safi],
10086 PEER_CAP_ADDPATH_AF_TX_RCV))
10087 vty_out(vty,
10088 "%sreceived",
10089 CHECK_FLAG(
10090 p->af_cap
10091 [afi]
10092 [safi],
10093 PEER_CAP_ADDPATH_AF_TX_ADV)
10094 ? " and "
10095 : "");
d62a17ae 10096
05c7a1cc
QY
10097 vty_out(vty, "\n");
10098 }
d62a17ae 10099
05c7a1cc
QY
10100 if (CHECK_FLAG(
10101 p->af_cap[afi]
10102 [safi],
10103 PEER_CAP_ADDPATH_AF_RX_ADV)
10104 || CHECK_FLAG(
10105 p->af_cap[afi]
10106 [safi],
10107 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10108 vty_out(vty,
10109 " %s: RX ",
10110 afi_safi_print(
10111 afi,
10112 safi));
d62a17ae 10113
10114 if (CHECK_FLAG(
10115 p->af_cap
10116 [afi]
10117 [safi],
05c7a1cc 10118 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10119 vty_out(vty,
05c7a1cc 10120 "advertised %s",
d62a17ae 10121 afi_safi_print(
10122 afi,
10123 safi));
10124
05c7a1cc
QY
10125 if (CHECK_FLAG(
10126 p->af_cap
10127 [afi]
10128 [safi],
10129 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10130 vty_out(vty,
05c7a1cc
QY
10131 "%sreceived",
10132 CHECK_FLAG(
10133 p->af_cap
10134 [afi]
10135 [safi],
10136 PEER_CAP_ADDPATH_AF_RX_ADV)
10137 ? " and "
10138 : "");
10139
10140 vty_out(vty, "\n");
d62a17ae 10141 }
05c7a1cc 10142 }
d62a17ae 10143 }
10144
10145 /* Dynamic */
10146 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10147 || CHECK_FLAG(p->cap,
10148 PEER_CAP_DYNAMIC_ADV)) {
10149 vty_out(vty, " Dynamic:");
10150 if (CHECK_FLAG(p->cap,
10151 PEER_CAP_DYNAMIC_ADV))
10152 vty_out(vty, " advertised");
10153 if (CHECK_FLAG(p->cap,
10154 PEER_CAP_DYNAMIC_RCV))
10155 vty_out(vty, " %sreceived",
10156 CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_DYNAMIC_ADV)
10159 ? "and "
10160 : "");
10161 vty_out(vty, "\n");
10162 }
10163
10164 /* Extended nexthop */
10165 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10166 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10167 vty_out(vty, " Extended nexthop:");
10168 if (CHECK_FLAG(p->cap,
10169 PEER_CAP_ENHE_ADV))
10170 vty_out(vty, " advertised");
10171 if (CHECK_FLAG(p->cap,
10172 PEER_CAP_ENHE_RCV))
10173 vty_out(vty, " %sreceived",
10174 CHECK_FLAG(
10175 p->cap,
10176 PEER_CAP_ENHE_ADV)
10177 ? "and "
10178 : "");
10179 vty_out(vty, "\n");
10180
10181 if (CHECK_FLAG(p->cap,
10182 PEER_CAP_ENHE_RCV)) {
10183 vty_out(vty,
10184 " Address families by peer:\n ");
10185 for (safi = SAFI_UNICAST;
10186 safi < SAFI_MAX; safi++)
10187 if (CHECK_FLAG(
10188 p->af_cap
10189 [AFI_IP]
10190 [safi],
10191 PEER_CAP_ENHE_AF_RCV))
10192 vty_out(vty,
10193 " %s\n",
10194 afi_safi_print(
10195 AFI_IP,
10196 safi));
10197 }
10198 }
10199
10200 /* Route Refresh */
10201 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10202 || CHECK_FLAG(p->cap,
10203 PEER_CAP_REFRESH_NEW_RCV)
10204 || CHECK_FLAG(p->cap,
10205 PEER_CAP_REFRESH_OLD_RCV)) {
10206 vty_out(vty, " Route refresh:");
10207 if (CHECK_FLAG(p->cap,
10208 PEER_CAP_REFRESH_ADV))
10209 vty_out(vty, " advertised");
10210 if (CHECK_FLAG(p->cap,
10211 PEER_CAP_REFRESH_NEW_RCV)
10212 || CHECK_FLAG(
10213 p->cap,
10214 PEER_CAP_REFRESH_OLD_RCV))
10215 vty_out(vty, " %sreceived(%s)",
10216 CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_REFRESH_ADV)
10219 ? "and "
10220 : "",
10221 (CHECK_FLAG(
10222 p->cap,
10223 PEER_CAP_REFRESH_OLD_RCV)
10224 && CHECK_FLAG(
10225 p->cap,
10226 PEER_CAP_REFRESH_NEW_RCV))
10227 ? "old & new"
10228 : CHECK_FLAG(
10229 p->cap,
10230 PEER_CAP_REFRESH_OLD_RCV)
10231 ? "old"
10232 : "new");
10233
10234 vty_out(vty, "\n");
10235 }
10236
10237 /* Multiprotocol Extensions */
05c7a1cc
QY
10238 FOREACH_AFI_SAFI (afi, safi)
10239 if (p->afc_adv[afi][safi]
10240 || p->afc_recv[afi][safi]) {
10241 vty_out(vty,
10242 " Address Family %s:",
10243 afi_safi_print(afi,
10244 safi));
10245 if (p->afc_adv[afi][safi])
d62a17ae 10246 vty_out(vty,
05c7a1cc
QY
10247 " advertised");
10248 if (p->afc_recv[afi][safi])
10249 vty_out(vty,
10250 " %sreceived",
10251 p->afc_adv[afi]
10252 [safi]
10253 ? "and "
10254 : "");
10255 vty_out(vty, "\n");
10256 }
d62a17ae 10257
10258 /* Hostname capability */
60466a63 10259 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10260
10261 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10262 vty_out(vty,
10263 " advertised (name: %s,domain name: %s)",
60466a63
QY
10264 bgp->peer_self->hostname
10265 ? bgp->peer_self
10266 ->hostname
d77114b7 10267 : "n/a",
60466a63
QY
10268 bgp->peer_self->domainname
10269 ? bgp->peer_self
10270 ->domainname
d77114b7
MK
10271 : "n/a");
10272 } else {
10273 vty_out(vty, " not advertised");
d62a17ae 10274 }
10275
d77114b7 10276 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10277 vty_out(vty,
10278 " received (name: %s,domain name: %s)",
60466a63
QY
10279 p->hostname ? p->hostname
10280 : "n/a",
10281 p->domainname ? p->domainname
10282 : "n/a");
d77114b7
MK
10283 } else {
10284 vty_out(vty, " not received");
10285 }
10286
10287 vty_out(vty, "\n");
10288
d62a17ae 10289 /* Gracefull Restart */
10290 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10291 || CHECK_FLAG(p->cap,
10292 PEER_CAP_RESTART_ADV)) {
10293 vty_out(vty,
10294 " Graceful Restart Capabilty:");
10295 if (CHECK_FLAG(p->cap,
10296 PEER_CAP_RESTART_ADV))
10297 vty_out(vty, " advertised");
10298 if (CHECK_FLAG(p->cap,
10299 PEER_CAP_RESTART_RCV))
10300 vty_out(vty, " %sreceived",
10301 CHECK_FLAG(
10302 p->cap,
10303 PEER_CAP_RESTART_ADV)
10304 ? "and "
10305 : "");
10306 vty_out(vty, "\n");
10307
10308 if (CHECK_FLAG(p->cap,
10309 PEER_CAP_RESTART_RCV)) {
10310 int restart_af_count = 0;
10311
10312 vty_out(vty,
10313 " Remote Restart timer is %d seconds\n",
10314 p->v_gr_restart);
10315 vty_out(vty,
10316 " Address families by peer:\n ");
10317
05c7a1cc
QY
10318 FOREACH_AFI_SAFI (afi, safi)
10319 if (CHECK_FLAG(
10320 p->af_cap
10321 [afi]
10322 [safi],
10323 PEER_CAP_RESTART_AF_RCV)) {
10324 vty_out(vty,
10325 "%s%s(%s)",
10326 restart_af_count
10327 ? ", "
10328 : "",
10329 afi_safi_print(
10330 afi,
10331 safi),
10332 CHECK_FLAG(
10333 p->af_cap
10334 [afi]
10335 [safi],
10336 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10337 ? "preserved"
10338 : "not preserved");
10339 restart_af_count++;
10340 }
d62a17ae 10341 if (!restart_af_count)
10342 vty_out(vty, "none");
10343 vty_out(vty, "\n");
10344 }
10345 }
10346 }
10347 }
10348 }
10349
10350 /* graceful restart information */
10351 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10352 || p->t_gr_stale) {
10353 json_object *json_grace = NULL;
10354 json_object *json_grace_send = NULL;
10355 json_object *json_grace_recv = NULL;
10356 int eor_send_af_count = 0;
10357 int eor_receive_af_count = 0;
10358
10359 if (use_json) {
10360 json_grace = json_object_new_object();
10361 json_grace_send = json_object_new_object();
10362 json_grace_recv = json_object_new_object();
10363
10364 if (p->status == Established) {
05c7a1cc
QY
10365 FOREACH_AFI_SAFI (afi, safi) {
10366 if (CHECK_FLAG(p->af_sflags[afi][safi],
10367 PEER_STATUS_EOR_SEND)) {
10368 json_object_boolean_true_add(
10369 json_grace_send,
10370 afi_safi_print(afi,
10371 safi));
10372 eor_send_af_count++;
d62a17ae 10373 }
10374 }
05c7a1cc
QY
10375 FOREACH_AFI_SAFI (afi, safi) {
10376 if (CHECK_FLAG(
10377 p->af_sflags[afi][safi],
10378 PEER_STATUS_EOR_RECEIVED)) {
10379 json_object_boolean_true_add(
10380 json_grace_recv,
10381 afi_safi_print(afi,
10382 safi));
10383 eor_receive_af_count++;
d62a17ae 10384 }
10385 }
10386 }
10387
10388 json_object_object_add(json_grace, "endOfRibSend",
10389 json_grace_send);
10390 json_object_object_add(json_grace, "endOfRibRecv",
10391 json_grace_recv);
10392
10393 if (p->t_gr_restart)
10394 json_object_int_add(json_grace,
10395 "gracefulRestartTimerMsecs",
10396 thread_timer_remain_second(
10397 p->t_gr_restart)
10398 * 1000);
10399
10400 if (p->t_gr_stale)
10401 json_object_int_add(
10402 json_grace,
10403 "gracefulStalepathTimerMsecs",
10404 thread_timer_remain_second(
10405 p->t_gr_stale)
10406 * 1000);
10407
10408 json_object_object_add(
10409 json_neigh, "gracefulRestartInfo", json_grace);
10410 } else {
0437e105 10411 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10412 if (p->status == Established) {
10413 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10414 FOREACH_AFI_SAFI (afi, safi) {
10415 if (CHECK_FLAG(p->af_sflags[afi][safi],
10416 PEER_STATUS_EOR_SEND)) {
10417 vty_out(vty, "%s%s",
10418 eor_send_af_count ? ", "
10419 : "",
10420 afi_safi_print(afi,
10421 safi));
10422 eor_send_af_count++;
d62a17ae 10423 }
10424 }
10425 vty_out(vty, "\n");
10426 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10427 FOREACH_AFI_SAFI (afi, safi) {
10428 if (CHECK_FLAG(
10429 p->af_sflags[afi][safi],
10430 PEER_STATUS_EOR_RECEIVED)) {
10431 vty_out(vty, "%s%s",
10432 eor_receive_af_count
10433 ? ", "
10434 : "",
10435 afi_safi_print(afi,
10436 safi));
10437 eor_receive_af_count++;
d62a17ae 10438 }
10439 }
10440 vty_out(vty, "\n");
10441 }
10442
10443 if (p->t_gr_restart)
10444 vty_out(vty,
10445 " The remaining time of restart timer is %ld\n",
10446 thread_timer_remain_second(
10447 p->t_gr_restart));
10448
10449 if (p->t_gr_stale)
10450 vty_out(vty,
10451 " The remaining time of stalepath timer is %ld\n",
10452 thread_timer_remain_second(
10453 p->t_gr_stale));
10454 }
10455 }
10456 if (use_json) {
10457 json_object *json_stat = NULL;
10458 json_stat = json_object_new_object();
10459 /* Packet counts. */
10460 json_object_int_add(json_stat, "depthInq", 0);
10461 json_object_int_add(json_stat, "depthOutq",
10462 (unsigned long)p->obuf->count);
0112e9e0
QY
10463 json_object_int_add(json_stat, "opensSent",
10464 atomic_load_explicit(&p->open_out,
10465 memory_order_relaxed));
10466 json_object_int_add(json_stat, "opensRecv",
10467 atomic_load_explicit(&p->open_in,
10468 memory_order_relaxed));
d62a17ae 10469 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10470 atomic_load_explicit(&p->notify_out,
10471 memory_order_relaxed));
d62a17ae 10472 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10473 atomic_load_explicit(&p->notify_in,
10474 memory_order_relaxed));
10475 json_object_int_add(json_stat, "updatesSent",
10476 atomic_load_explicit(&p->update_out,
10477 memory_order_relaxed));
10478 json_object_int_add(json_stat, "updatesRecv",
10479 atomic_load_explicit(&p->update_in,
10480 memory_order_relaxed));
d62a17ae 10481 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10482 atomic_load_explicit(&p->keepalive_out,
10483 memory_order_relaxed));
d62a17ae 10484 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10485 atomic_load_explicit(&p->keepalive_in,
10486 memory_order_relaxed));
d62a17ae 10487 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10488 atomic_load_explicit(&p->refresh_out,
10489 memory_order_relaxed));
d62a17ae 10490 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10491 atomic_load_explicit(&p->refresh_in,
10492 memory_order_relaxed));
d62a17ae 10493 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10494 atomic_load_explicit(&p->dynamic_cap_out,
10495 memory_order_relaxed));
d62a17ae 10496 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10497 atomic_load_explicit(&p->dynamic_cap_in,
10498 memory_order_relaxed));
10499 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10500 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10501 json_object_object_add(json_neigh, "messageStats", json_stat);
10502 } else {
10503 /* Packet counts. */
10504 vty_out(vty, " Message statistics:\n");
10505 vty_out(vty, " Inq depth is 0\n");
10506 vty_out(vty, " Outq depth is %lu\n",
10507 (unsigned long)p->obuf->count);
10508 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10509 vty_out(vty, " Opens: %10d %10d\n",
10510 atomic_load_explicit(&p->open_out,
10511 memory_order_relaxed),
10512 atomic_load_explicit(&p->open_in,
10513 memory_order_relaxed));
10514 vty_out(vty, " Notifications: %10d %10d\n",
10515 atomic_load_explicit(&p->notify_out,
10516 memory_order_relaxed),
10517 atomic_load_explicit(&p->notify_in,
10518 memory_order_relaxed));
10519 vty_out(vty, " Updates: %10d %10d\n",
10520 atomic_load_explicit(&p->update_out,
10521 memory_order_relaxed),
10522 atomic_load_explicit(&p->update_in,
10523 memory_order_relaxed));
10524 vty_out(vty, " Keepalives: %10d %10d\n",
10525 atomic_load_explicit(&p->keepalive_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->keepalive_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Route Refresh: %10d %10d\n",
10530 atomic_load_explicit(&p->refresh_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->refresh_in,
10533 memory_order_relaxed));
d62a17ae 10534 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10535 atomic_load_explicit(&p->dynamic_cap_out,
10536 memory_order_relaxed),
10537 atomic_load_explicit(&p->dynamic_cap_in,
10538 memory_order_relaxed));
10539 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10540 PEER_TOTAL_RX(p));
d62a17ae 10541 }
10542
10543 if (use_json) {
10544 /* advertisement-interval */
10545 json_object_int_add(json_neigh,
10546 "minBtwnAdvertisementRunsTimerMsecs",
10547 p->v_routeadv * 1000);
10548
10549 /* Update-source. */
10550 if (p->update_if || p->update_source) {
10551 if (p->update_if)
10552 json_object_string_add(json_neigh,
10553 "updateSource",
10554 p->update_if);
10555 else if (p->update_source)
10556 json_object_string_add(
10557 json_neigh, "updateSource",
10558 sockunion2str(p->update_source, buf1,
10559 SU_ADDRSTRLEN));
10560 }
10561 } else {
10562 /* advertisement-interval */
10563 vty_out(vty,
10564 " Minimum time between advertisement runs is %d seconds\n",
10565 p->v_routeadv);
10566
10567 /* Update-source. */
10568 if (p->update_if || p->update_source) {
10569 vty_out(vty, " Update source is ");
10570 if (p->update_if)
10571 vty_out(vty, "%s", p->update_if);
10572 else if (p->update_source)
10573 vty_out(vty, "%s",
10574 sockunion2str(p->update_source, buf1,
10575 SU_ADDRSTRLEN));
10576 vty_out(vty, "\n");
10577 }
10578
10579 vty_out(vty, "\n");
10580 }
10581
10582 /* Address Family Information */
10583 json_object *json_hold = NULL;
10584
10585 if (use_json)
10586 json_hold = json_object_new_object();
10587
05c7a1cc
QY
10588 FOREACH_AFI_SAFI (afi, safi)
10589 if (p->afc[afi][safi])
10590 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10591 json_hold);
d62a17ae 10592
10593 if (use_json) {
10594 json_object_object_add(json_neigh, "addressFamilyInfo",
10595 json_hold);
10596 json_object_int_add(json_neigh, "connectionsEstablished",
10597 p->established);
10598 json_object_int_add(json_neigh, "connectionsDropped",
10599 p->dropped);
10600 } else
10601 vty_out(vty, " Connections established %d; dropped %d\n",
10602 p->established, p->dropped);
10603
10604 if (!p->last_reset) {
10605 if (use_json)
10606 json_object_string_add(json_neigh, "lastReset",
10607 "never");
10608 else
10609 vty_out(vty, " Last reset never\n");
10610 } else {
10611 if (use_json) {
10612 time_t uptime;
10613 struct tm *tm;
10614
10615 uptime = bgp_clock();
10616 uptime -= p->resettime;
10617 tm = gmtime(&uptime);
10618 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10619 (tm->tm_sec * 1000)
10620 + (tm->tm_min * 60000)
10621 + (tm->tm_hour * 3600000));
10622 json_object_string_add(
10623 json_neigh, "lastResetDueTo",
10624 peer_down_str[(int)p->last_reset]);
10625 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10626 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10627 char errorcodesubcode_hexstr[5];
10628 char errorcodesubcode_str[256];
10629
10630 code_str = bgp_notify_code_str(p->notify.code);
10631 subcode_str = bgp_notify_subcode_str(
10632 p->notify.code, p->notify.subcode);
10633
10634 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10635 p->notify.code, p->notify.subcode);
10636 json_object_string_add(json_neigh,
10637 "lastErrorCodeSubcode",
10638 errorcodesubcode_hexstr);
10639 snprintf(errorcodesubcode_str, 255, "%s%s",
10640 code_str, subcode_str);
10641 json_object_string_add(json_neigh,
10642 "lastNotificationReason",
10643 errorcodesubcode_str);
10644 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10645 && p->notify.code == BGP_NOTIFY_CEASE
10646 && (p->notify.subcode
10647 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10648 || p->notify.subcode
10649 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10650 && p->notify.length) {
10651 char msgbuf[1024];
10652 const char *msg_str;
10653
10654 msg_str = bgp_notify_admin_message(
10655 msgbuf, sizeof(msgbuf),
d7c0a89a 10656 (uint8_t *)p->notify.data,
d62a17ae 10657 p->notify.length);
10658 if (msg_str)
10659 json_object_string_add(
10660 json_neigh,
10661 "lastShutdownDescription",
10662 msg_str);
10663 }
10664 }
10665 } else {
10666 vty_out(vty, " Last reset %s, ",
10667 peer_uptime(p->resettime, timebuf,
10668 BGP_UPTIME_LEN, 0, NULL));
10669
10670 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10671 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10672 code_str = bgp_notify_code_str(p->notify.code);
10673 subcode_str = bgp_notify_subcode_str(
10674 p->notify.code, p->notify.subcode);
10675 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10676 p->last_reset == PEER_DOWN_NOTIFY_SEND
10677 ? "sent"
10678 : "received",
10679 code_str, subcode_str);
10680 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10681 && p->notify.code == BGP_NOTIFY_CEASE
10682 && (p->notify.subcode
10683 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10684 || p->notify.subcode
10685 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10686 && p->notify.length) {
10687 char msgbuf[1024];
10688 const char *msg_str;
10689
10690 msg_str = bgp_notify_admin_message(
10691 msgbuf, sizeof(msgbuf),
d7c0a89a 10692 (uint8_t *)p->notify.data,
d62a17ae 10693 p->notify.length);
10694 if (msg_str)
10695 vty_out(vty,
10696 " Message: \"%s\"\n",
10697 msg_str);
10698 }
10699 } else {
10700 vty_out(vty, "due to %s\n",
10701 peer_down_str[(int)p->last_reset]);
10702 }
10703
10704 if (p->last_reset_cause_size) {
10705 msg = p->last_reset_cause;
10706 vty_out(vty,
10707 " Message received that caused BGP to send a NOTIFICATION:\n ");
10708 for (i = 1; i <= p->last_reset_cause_size;
10709 i++) {
10710 vty_out(vty, "%02X", *msg++);
10711
10712 if (i != p->last_reset_cause_size) {
10713 if (i % 16 == 0) {
10714 vty_out(vty, "\n ");
10715 } else if (i % 4 == 0) {
10716 vty_out(vty, " ");
10717 }
10718 }
10719 }
10720 vty_out(vty, "\n");
10721 }
10722 }
10723 }
10724
10725 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10726 if (use_json)
10727 json_object_boolean_true_add(json_neigh,
10728 "prefixesConfigExceedMax");
10729 else
10730 vty_out(vty,
10731 " Peer had exceeded the max. no. of prefixes configured.\n");
10732
10733 if (p->t_pmax_restart) {
10734 if (use_json) {
10735 json_object_boolean_true_add(
10736 json_neigh, "reducePrefixNumFrom");
10737 json_object_int_add(json_neigh,
10738 "restartInTimerMsec",
10739 thread_timer_remain_second(
10740 p->t_pmax_restart)
10741 * 1000);
10742 } else
10743 vty_out(vty,
10744 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10745 p->host, thread_timer_remain_second(
10746 p->t_pmax_restart));
d62a17ae 10747 } else {
10748 if (use_json)
10749 json_object_boolean_true_add(
10750 json_neigh,
10751 "reducePrefixNumAndClearIpBgp");
10752 else
10753 vty_out(vty,
10754 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10755 p->host);
10756 }
10757 }
10758
10759 /* EBGP Multihop and GTSM */
10760 if (p->sort != BGP_PEER_IBGP) {
10761 if (use_json) {
10762 if (p->gtsm_hops > 0)
10763 json_object_int_add(json_neigh,
10764 "externalBgpNbrMaxHopsAway",
10765 p->gtsm_hops);
10766 else if (p->ttl > 1)
10767 json_object_int_add(json_neigh,
10768 "externalBgpNbrMaxHopsAway",
10769 p->ttl);
10770 } else {
10771 if (p->gtsm_hops > 0)
10772 vty_out(vty,
10773 " External BGP neighbor may be up to %d hops away.\n",
10774 p->gtsm_hops);
10775 else if (p->ttl > 1)
10776 vty_out(vty,
10777 " External BGP neighbor may be up to %d hops away.\n",
10778 p->ttl);
10779 }
10780 } else {
10781 if (p->gtsm_hops > 0) {
10782 if (use_json)
10783 json_object_int_add(json_neigh,
10784 "internalBgpNbrMaxHopsAway",
10785 p->gtsm_hops);
10786 else
10787 vty_out(vty,
10788 " Internal BGP neighbor may be up to %d hops away.\n",
10789 p->gtsm_hops);
10790 }
10791 }
10792
10793 /* Local address. */
10794 if (p->su_local) {
10795 if (use_json) {
10796 json_object_string_add(json_neigh, "hostLocal",
10797 sockunion2str(p->su_local, buf1,
10798 SU_ADDRSTRLEN));
10799 json_object_int_add(json_neigh, "portLocal",
10800 ntohs(p->su_local->sin.sin_port));
10801 } else
10802 vty_out(vty, "Local host: %s, Local port: %d\n",
10803 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10804 ntohs(p->su_local->sin.sin_port));
10805 }
10806
10807 /* Remote address. */
10808 if (p->su_remote) {
10809 if (use_json) {
10810 json_object_string_add(json_neigh, "hostForeign",
10811 sockunion2str(p->su_remote, buf1,
10812 SU_ADDRSTRLEN));
10813 json_object_int_add(json_neigh, "portForeign",
10814 ntohs(p->su_remote->sin.sin_port));
10815 } else
10816 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10817 sockunion2str(p->su_remote, buf1,
10818 SU_ADDRSTRLEN),
10819 ntohs(p->su_remote->sin.sin_port));
10820 }
10821
10822 /* Nexthop display. */
10823 if (p->su_local) {
10824 if (use_json) {
10825 json_object_string_add(json_neigh, "nexthop",
10826 inet_ntop(AF_INET,
10827 &p->nexthop.v4, buf1,
10828 sizeof(buf1)));
10829 json_object_string_add(json_neigh, "nexthopGlobal",
10830 inet_ntop(AF_INET6,
10831 &p->nexthop.v6_global,
10832 buf1, sizeof(buf1)));
10833 json_object_string_add(json_neigh, "nexthopLocal",
10834 inet_ntop(AF_INET6,
10835 &p->nexthop.v6_local,
10836 buf1, sizeof(buf1)));
10837 if (p->shared_network)
10838 json_object_string_add(json_neigh,
10839 "bgpConnection",
10840 "sharedNetwork");
10841 else
10842 json_object_string_add(json_neigh,
10843 "bgpConnection",
10844 "nonSharedNetwork");
10845 } else {
10846 vty_out(vty, "Nexthop: %s\n",
10847 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10848 sizeof(buf1)));
10849 vty_out(vty, "Nexthop global: %s\n",
10850 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10851 sizeof(buf1)));
10852 vty_out(vty, "Nexthop local: %s\n",
10853 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10854 sizeof(buf1)));
10855 vty_out(vty, "BGP connection: %s\n",
10856 p->shared_network ? "shared network"
10857 : "non shared network");
10858 }
10859 }
10860
10861 /* Timer information. */
10862 if (use_json) {
10863 json_object_int_add(json_neigh, "connectRetryTimer",
10864 p->v_connect);
10865 if (p->status == Established && p->rtt)
10866 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10867 p->rtt);
10868 if (p->t_start)
10869 json_object_int_add(
10870 json_neigh, "nextStartTimerDueInMsecs",
10871 thread_timer_remain_second(p->t_start) * 1000);
10872 if (p->t_connect)
10873 json_object_int_add(
10874 json_neigh, "nextConnectTimerDueInMsecs",
10875 thread_timer_remain_second(p->t_connect)
10876 * 1000);
10877 if (p->t_routeadv) {
10878 json_object_int_add(json_neigh, "mraiInterval",
10879 p->v_routeadv);
10880 json_object_int_add(
10881 json_neigh, "mraiTimerExpireInMsecs",
10882 thread_timer_remain_second(p->t_routeadv)
10883 * 1000);
10884 }
10885 if (p->password)
10886 json_object_int_add(json_neigh, "authenticationEnabled",
10887 1);
10888
10889 if (p->t_read)
10890 json_object_string_add(json_neigh, "readThread", "on");
10891 else
10892 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10893
10894 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10895 json_object_string_add(json_neigh, "writeThread", "on");
10896 else
10897 json_object_string_add(json_neigh, "writeThread",
10898 "off");
10899 } else {
10900 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10901 p->v_connect);
10902 if (p->status == Established && p->rtt)
10903 vty_out(vty, "Estimated round trip time: %d ms\n",
10904 p->rtt);
10905 if (p->t_start)
10906 vty_out(vty, "Next start timer due in %ld seconds\n",
10907 thread_timer_remain_second(p->t_start));
10908 if (p->t_connect)
10909 vty_out(vty, "Next connect timer due in %ld seconds\n",
10910 thread_timer_remain_second(p->t_connect));
10911 if (p->t_routeadv)
10912 vty_out(vty,
10913 "MRAI (interval %u) timer expires in %ld seconds\n",
10914 p->v_routeadv,
10915 thread_timer_remain_second(p->t_routeadv));
10916 if (p->password)
10917 vty_out(vty, "Peer Authentication Enabled\n");
10918
10919 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10920 p->t_read ? "on" : "off",
10921 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10922 ? "on"
10923 : "off");
d62a17ae 10924 }
10925
10926 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10927 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10928 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10929
10930 if (!use_json)
10931 vty_out(vty, "\n");
10932
10933 /* BFD information. */
10934 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10935
10936 if (use_json) {
10937 if (p->conf_if) /* Configured interface name. */
10938 json_object_object_add(json, p->conf_if, json_neigh);
10939 else /* Configured IP address. */
10940 json_object_object_add(json, p->host, json_neigh);
10941 }
10942}
10943
10944static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10945 enum show_type type, union sockunion *su,
9f049418 10946 const char *conf_if, bool use_json,
d62a17ae 10947 json_object *json)
10948{
10949 struct listnode *node, *nnode;
10950 struct peer *peer;
10951 int find = 0;
9f049418 10952 bool nbr_output = false;
d1927ebe
AS
10953 afi_t afi = AFI_MAX;
10954 safi_t safi = SAFI_MAX;
10955
10956 if (type == show_ipv4_peer || type == show_ipv4_all) {
10957 afi = AFI_IP;
10958 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10959 afi = AFI_IP6;
10960 }
d62a17ae 10961
10962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10963 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10964 continue;
10965
10966 switch (type) {
10967 case show_all:
10968 bgp_show_peer(vty, peer, use_json, json);
9f049418 10969 nbr_output = true;
d62a17ae 10970 break;
10971 case show_peer:
10972 if (conf_if) {
10973 if ((peer->conf_if
10974 && !strcmp(peer->conf_if, conf_if))
10975 || (peer->hostname
10976 && !strcmp(peer->hostname, conf_if))) {
10977 find = 1;
10978 bgp_show_peer(vty, peer, use_json,
10979 json);
10980 }
10981 } else {
10982 if (sockunion_same(&peer->su, su)) {
10983 find = 1;
10984 bgp_show_peer(vty, peer, use_json,
10985 json);
10986 }
10987 }
10988 break;
d1927ebe
AS
10989 case show_ipv4_peer:
10990 case show_ipv6_peer:
10991 FOREACH_SAFI (safi) {
10992 if (peer->afc[afi][safi]) {
10993 if (conf_if) {
10994 if ((peer->conf_if
10995 && !strcmp(peer->conf_if, conf_if))
10996 || (peer->hostname
10997 && !strcmp(peer->hostname, conf_if))) {
10998 find = 1;
10999 bgp_show_peer(vty, peer, use_json,
11000 json);
11001 break;
11002 }
11003 } else {
11004 if (sockunion_same(&peer->su, su)) {
11005 find = 1;
11006 bgp_show_peer(vty, peer, use_json,
11007 json);
11008 break;
11009 }
11010 }
11011 }
11012 }
11013 break;
11014 case show_ipv4_all:
11015 case show_ipv6_all:
11016 FOREACH_SAFI (safi) {
11017 if (peer->afc[afi][safi]) {
11018 bgp_show_peer(vty, peer, use_json, json);
11019 nbr_output = true;
11020 break;
11021 }
11022 }
11023 break;
d62a17ae 11024 }
11025 }
11026
d1927ebe
AS
11027 if ((type == show_peer || type == show_ipv4_peer ||
11028 type == show_ipv6_peer) && !find) {
d62a17ae 11029 if (use_json)
11030 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11031 else
88b7d255 11032 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 11033 }
11034
d1927ebe
AS
11035 if (type != show_peer && type != show_ipv4_peer &&
11036 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 11037 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 11038
d62a17ae 11039 if (use_json) {
996c9314
LB
11040 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11041 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11042 } else {
11043 vty_out(vty, "\n");
11044 }
11045
11046 return CMD_SUCCESS;
11047}
11048
11049static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
11050 enum show_type type,
11051 const char *ip_str,
9f049418 11052 bool use_json)
d62a17ae 11053{
0291c246
MK
11054 struct listnode *node, *nnode;
11055 struct bgp *bgp;
71aedaa3 11056 union sockunion su;
0291c246 11057 json_object *json = NULL;
71aedaa3 11058 int ret, is_first = 1;
9f049418 11059 bool nbr_output = false;
d62a17ae 11060
11061 if (use_json)
11062 vty_out(vty, "{\n");
11063
11064 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11065 nbr_output = true;
d62a17ae 11066 if (use_json) {
11067 if (!(json = json_object_new_object())) {
af4c2728 11068 flog_err(
e50f7cfd 11069 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11070 "Unable to allocate memory for JSON object");
11071 vty_out(vty,
11072 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11073 return;
11074 }
11075
11076 json_object_int_add(json, "vrfId",
11077 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11078 ? -1
11079 : (int64_t)bgp->vrf_id);
d62a17ae 11080 json_object_string_add(
11081 json, "vrfName",
11082 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11083 ? VRF_DEFAULT_NAME
d62a17ae 11084 : bgp->name);
11085
11086 if (!is_first)
11087 vty_out(vty, ",\n");
11088 else
11089 is_first = 0;
11090
11091 vty_out(vty, "\"%s\":",
11092 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11093 ? VRF_DEFAULT_NAME
d62a17ae 11094 : bgp->name);
11095 } else {
11096 vty_out(vty, "\nInstance %s:\n",
11097 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11098 ? VRF_DEFAULT_NAME
d62a17ae 11099 : bgp->name);
11100 }
71aedaa3 11101
d1927ebe
AS
11102 if (type == show_peer || type == show_ipv4_peer ||
11103 type == show_ipv6_peer) {
71aedaa3
DS
11104 ret = str2sockunion(ip_str, &su);
11105 if (ret < 0)
11106 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11107 use_json, json);
11108 else
11109 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11110 use_json, json);
11111 } else {
d1927ebe 11112 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11113 use_json, json);
11114 }
b77004d6 11115 json_object_free(json);
d62a17ae 11116 }
11117
01cbfd04 11118 if (use_json) {
d62a17ae 11119 vty_out(vty, "}\n");
01cbfd04
QY
11120 json_object_free(json);
11121 }
9f049418
DS
11122 else if (!nbr_output)
11123 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11124}
11125
11126static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11127 enum show_type type, const char *ip_str,
9f049418 11128 bool use_json)
d62a17ae 11129{
11130 int ret;
11131 struct bgp *bgp;
11132 union sockunion su;
11133 json_object *json = NULL;
11134
11135 if (name) {
11136 if (strmatch(name, "all")) {
71aedaa3
DS
11137 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11138 use_json);
d62a17ae 11139 return CMD_SUCCESS;
11140 } else {
11141 bgp = bgp_lookup_by_name(name);
11142 if (!bgp) {
11143 if (use_json) {
11144 json = json_object_new_object();
d62a17ae 11145 vty_out(vty, "%s\n",
11146 json_object_to_json_string_ext(
11147 json,
11148 JSON_C_TO_STRING_PRETTY));
11149 json_object_free(json);
11150 } else
11151 vty_out(vty,
9f049418 11152 "%% BGP instance not found\n");
d62a17ae 11153
11154 return CMD_WARNING;
11155 }
11156 }
11157 } else {
11158 bgp = bgp_get_default();
11159 }
11160
11161 if (bgp) {
11162 json = json_object_new_object();
11163 if (ip_str) {
11164 ret = str2sockunion(ip_str, &su);
11165 if (ret < 0)
11166 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11167 use_json, json);
11168 else
11169 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11170 use_json, json);
11171 } else {
11172 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11173 json);
11174 }
11175 json_object_free(json);
ca61fd25
DS
11176 } else {
11177 if (use_json)
11178 vty_out(vty, "{}\n");
11179 else
11180 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11181 }
11182
11183 return CMD_SUCCESS;
4fb25c53
DW
11184}
11185
716b2d8a 11186/* "show [ip] bgp neighbors" commands. */
718e3744 11187DEFUN (show_ip_bgp_neighbors,
11188 show_ip_bgp_neighbors_cmd,
24345e82 11189 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11190 SHOW_STR
11191 IP_STR
11192 BGP_STR
f2a8972b 11193 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11194 "Address Family\n"
11195 "Address Family\n"
718e3744 11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
a80beece 11198 "Neighbor to display information about\n"
91d37724 11199 "Neighbor on BGP configured interface\n"
9973d184 11200 JSON_STR)
718e3744 11201{
d62a17ae 11202 char *vrf = NULL;
11203 char *sh_arg = NULL;
11204 enum show_type sh_type;
d1927ebe 11205 afi_t afi = AFI_MAX;
718e3744 11206
9f049418 11207 bool uj = use_json(argc, argv);
718e3744 11208
d62a17ae 11209 int idx = 0;
718e3744 11210
9a8bdf1c
PG
11211 /* [<vrf> VIEWVRFNAME] */
11212 if (argv_find(argv, argc, "vrf", &idx)) {
11213 vrf = argv[idx + 1]->arg;
11214 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11215 vrf = NULL;
11216 } else if (argv_find(argv, argc, "view", &idx))
11217 /* [<view> VIEWVRFNAME] */
d62a17ae 11218 vrf = argv[idx + 1]->arg;
718e3744 11219
d62a17ae 11220 idx++;
d1927ebe
AS
11221
11222 if (argv_find(argv, argc, "ipv4", &idx)) {
11223 sh_type = show_ipv4_all;
11224 afi = AFI_IP;
11225 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11226 sh_type = show_ipv6_all;
11227 afi = AFI_IP6;
11228 } else {
11229 sh_type = show_all;
11230 }
11231
d62a17ae 11232 if (argv_find(argv, argc, "A.B.C.D", &idx)
11233 || argv_find(argv, argc, "X:X::X:X", &idx)
11234 || argv_find(argv, argc, "WORD", &idx)) {
11235 sh_type = show_peer;
11236 sh_arg = argv[idx]->arg;
d1927ebe
AS
11237 }
11238
11239 if (sh_type == show_peer && afi == AFI_IP) {
11240 sh_type = show_ipv4_peer;
11241 } else if (sh_type == show_peer && afi == AFI_IP6) {
11242 sh_type = show_ipv6_peer;
11243 }
856ca177 11244
d62a17ae 11245 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11246}
11247
716b2d8a 11248/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11249 paths' and `show ip mbgp paths'. Those functions results are the
11250 same.*/
f412b39a 11251DEFUN (show_ip_bgp_paths,
718e3744 11252 show_ip_bgp_paths_cmd,
46f296b4 11253 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11254 SHOW_STR
11255 IP_STR
11256 BGP_STR
46f296b4 11257 BGP_SAFI_HELP_STR
718e3744 11258 "Path information\n")
11259{
d62a17ae 11260 vty_out(vty, "Address Refcnt Path\n");
11261 aspath_print_all_vty(vty);
11262 return CMD_SUCCESS;
718e3744 11263}
11264
718e3744 11265#include "hash.h"
11266
e3b78da8 11267static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11268 struct vty *vty)
718e3744 11269{
d62a17ae 11270 struct community *com;
718e3744 11271
e3b78da8 11272 com = (struct community *)bucket->data;
3f65c5b1 11273 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11274 community_str(com, false));
718e3744 11275}
11276
11277/* Show BGP's community internal data. */
f412b39a 11278DEFUN (show_ip_bgp_community_info,
718e3744 11279 show_ip_bgp_community_info_cmd,
bec37ba5 11280 "show [ip] bgp community-info",
718e3744 11281 SHOW_STR
11282 IP_STR
11283 BGP_STR
11284 "List all bgp community information\n")
11285{
d62a17ae 11286 vty_out(vty, "Address Refcnt Community\n");
718e3744 11287
d62a17ae 11288 hash_iterate(community_hash(),
e3b78da8 11289 (void (*)(struct hash_bucket *,
d62a17ae 11290 void *))community_show_all_iterator,
11291 vty);
718e3744 11292
d62a17ae 11293 return CMD_SUCCESS;
718e3744 11294}
11295
e3b78da8 11296static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11297 struct vty *vty)
57d187bc 11298{
d62a17ae 11299 struct lcommunity *lcom;
57d187bc 11300
e3b78da8 11301 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11302 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11303 lcommunity_str(lcom, false));
57d187bc
JS
11304}
11305
11306/* Show BGP's community internal data. */
11307DEFUN (show_ip_bgp_lcommunity_info,
11308 show_ip_bgp_lcommunity_info_cmd,
11309 "show ip bgp large-community-info",
11310 SHOW_STR
11311 IP_STR
11312 BGP_STR
11313 "List all bgp large-community information\n")
11314{
d62a17ae 11315 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11316
d62a17ae 11317 hash_iterate(lcommunity_hash(),
e3b78da8 11318 (void (*)(struct hash_bucket *,
d62a17ae 11319 void *))lcommunity_show_all_iterator,
11320 vty);
57d187bc 11321
d62a17ae 11322 return CMD_SUCCESS;
57d187bc
JS
11323}
11324
11325
f412b39a 11326DEFUN (show_ip_bgp_attr_info,
718e3744 11327 show_ip_bgp_attr_info_cmd,
bec37ba5 11328 "show [ip] bgp attribute-info",
718e3744 11329 SHOW_STR
11330 IP_STR
11331 BGP_STR
11332 "List all bgp attribute information\n")
11333{
d62a17ae 11334 attr_show_all(vty);
11335 return CMD_SUCCESS;
718e3744 11336}
6b0655a2 11337
03915806
CS
11338static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11339 afi_t afi, safi_t safi,
11340 bool use_json, json_object *json)
53089bec 11341{
11342 struct bgp *bgp;
11343 struct listnode *node;
11344 char *vname;
11345 char buf1[INET6_ADDRSTRLEN];
11346 char *ecom_str;
11347 vpn_policy_direction_t dir;
11348
03915806 11349 if (json) {
b46dfd20
DS
11350 json_object *json_import_vrfs = NULL;
11351 json_object *json_export_vrfs = NULL;
11352
b46dfd20
DS
11353 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11354
53089bec 11355 if (!bgp) {
b46dfd20
DS
11356 vty_out(vty, "%s\n",
11357 json_object_to_json_string_ext(
11358 json,
11359 JSON_C_TO_STRING_PRETTY));
11360 json_object_free(json);
11361
53089bec 11362 return CMD_WARNING;
11363 }
b46dfd20 11364
94d4c685
DS
11365 /* Provide context for the block */
11366 json_object_string_add(json, "vrf", name ? name : "default");
11367 json_object_string_add(json, "afiSafi",
11368 afi_safi_print(afi, safi));
11369
b46dfd20
DS
11370 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11371 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11372 json_object_string_add(json, "importFromVrfs", "none");
11373 json_object_string_add(json, "importRts", "none");
11374 } else {
6ce24e52
DS
11375 json_import_vrfs = json_object_new_array();
11376
b46dfd20
DS
11377 for (ALL_LIST_ELEMENTS_RO(
11378 bgp->vpn_policy[afi].import_vrf,
11379 node, vname))
11380 json_object_array_add(json_import_vrfs,
11381 json_object_new_string(vname));
11382
11383 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11384 ecom_str = ecommunity_ecom2str(
11385 bgp->vpn_policy[afi].rtlist[dir],
11386 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11387 json_object_object_add(json, "importFromVrfs",
11388 json_import_vrfs);
11389 json_object_string_add(json, "importRts", ecom_str);
11390
11391 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11392 }
11393
11394 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11395 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11396 json_object_string_add(json, "exportToVrfs", "none");
11397 json_object_string_add(json, "routeDistinguisher",
11398 "none");
11399 json_object_string_add(json, "exportRts", "none");
11400 } else {
6ce24e52
DS
11401 json_export_vrfs = json_object_new_array();
11402
b46dfd20
DS
11403 for (ALL_LIST_ELEMENTS_RO(
11404 bgp->vpn_policy[afi].export_vrf,
11405 node, vname))
11406 json_object_array_add(json_export_vrfs,
11407 json_object_new_string(vname));
11408 json_object_object_add(json, "exportToVrfs",
11409 json_export_vrfs);
11410 json_object_string_add(json, "routeDistinguisher",
11411 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11412 buf1, RD_ADDRSTRLEN));
11413
11414 dir = BGP_VPN_POLICY_DIR_TOVPN;
11415 ecom_str = ecommunity_ecom2str(
11416 bgp->vpn_policy[afi].rtlist[dir],
11417 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11418 json_object_string_add(json, "exportRts", ecom_str);
11419
11420 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11421 }
11422
03915806
CS
11423 if (use_json) {
11424 vty_out(vty, "%s\n",
11425 json_object_to_json_string_ext(json,
b46dfd20 11426 JSON_C_TO_STRING_PRETTY));
03915806
CS
11427 json_object_free(json);
11428 }
53089bec 11429 } else {
b46dfd20
DS
11430 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11431
53089bec 11432 if (!bgp) {
b46dfd20 11433 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11434 return CMD_WARNING;
11435 }
53089bec 11436
b46dfd20
DS
11437 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11438 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11439 vty_out(vty,
11440 "This VRF is not importing %s routes from any other VRF\n",
11441 afi_safi_print(afi, safi));
11442 else {
11443 vty_out(vty,
11444 "This VRF is importing %s routes from the following VRFs:\n",
11445 afi_safi_print(afi, safi));
11446
11447 for (ALL_LIST_ELEMENTS_RO(
11448 bgp->vpn_policy[afi].import_vrf,
11449 node, vname))
11450 vty_out(vty, " %s\n", vname);
11451
11452 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11453 ecom_str = ecommunity_ecom2str(
11454 bgp->vpn_policy[afi].rtlist[dir],
11455 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11456 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11457
11458 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11459 }
53089bec 11460
b46dfd20
DS
11461 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11462 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11463 vty_out(vty,
11464 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11465 afi_safi_print(afi, safi));
b46dfd20
DS
11466 else {
11467 vty_out(vty,
04c9077f 11468 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11469 afi_safi_print(afi, safi));
b46dfd20
DS
11470
11471 for (ALL_LIST_ELEMENTS_RO(
11472 bgp->vpn_policy[afi].export_vrf,
11473 node, vname))
11474 vty_out(vty, " %s\n", vname);
11475
11476 vty_out(vty, "RD: %s\n",
11477 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11478 buf1, RD_ADDRSTRLEN));
11479
11480 dir = BGP_VPN_POLICY_DIR_TOVPN;
11481 ecom_str = ecommunity_ecom2str(
11482 bgp->vpn_policy[afi].rtlist[dir],
11483 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11484 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11485 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11486 }
53089bec 11487 }
11488
11489 return CMD_SUCCESS;
11490}
11491
03915806
CS
11492static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11493 safi_t safi, bool use_json)
11494{
11495 struct listnode *node, *nnode;
11496 struct bgp *bgp;
11497 char *vrf_name = NULL;
11498 json_object *json = NULL;
11499 json_object *json_vrf = NULL;
11500 json_object *json_vrfs = NULL;
11501
11502 if (use_json) {
11503 json = json_object_new_object();
11504 json_vrfs = json_object_new_object();
11505 }
11506
11507 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11508
11509 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11510 vrf_name = bgp->name;
11511
11512 if (use_json) {
11513 json_vrf = json_object_new_object();
11514 } else {
11515 vty_out(vty, "\nInstance %s:\n",
11516 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11517 ? VRF_DEFAULT_NAME : bgp->name);
11518 }
11519 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11520 if (use_json) {
11521 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11522 json_object_object_add(json_vrfs,
11523 VRF_DEFAULT_NAME, json_vrf);
11524 else
11525 json_object_object_add(json_vrfs, vrf_name,
11526 json_vrf);
11527 }
11528 }
11529
11530 if (use_json) {
11531 json_object_object_add(json, "vrfs", json_vrfs);
11532 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11533 JSON_C_TO_STRING_PRETTY));
11534 json_object_free(json);
11535 }
11536
11537 return CMD_SUCCESS;
11538}
11539
53089bec 11540/* "show [ip] bgp route-leak" command. */
11541DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11542 show_ip_bgp_route_leak_cmd,
11543 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11544 SHOW_STR
11545 IP_STR
11546 BGP_STR
11547 BGP_INSTANCE_HELP_STR
11548 BGP_AFI_HELP_STR
11549 BGP_SAFI_HELP_STR
11550 "Route leaking information\n"
11551 JSON_STR)
53089bec 11552{
11553 char *vrf = NULL;
11554 afi_t afi = AFI_MAX;
11555 safi_t safi = SAFI_MAX;
11556
9f049418 11557 bool uj = use_json(argc, argv);
53089bec 11558 int idx = 0;
03915806 11559 json_object *json = NULL;
53089bec 11560
11561 /* show [ip] bgp */
11562 if (argv_find(argv, argc, "ip", &idx)) {
11563 afi = AFI_IP;
11564 safi = SAFI_UNICAST;
11565 }
11566 /* [vrf VIEWVRFNAME] */
11567 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11568 vty_out(vty,
11569 "%% This command is not applicable to BGP views\n");
53089bec 11570 return CMD_WARNING;
11571 }
11572
9a8bdf1c
PG
11573 if (argv_find(argv, argc, "vrf", &idx)) {
11574 vrf = argv[idx + 1]->arg;
11575 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11576 vrf = NULL;
11577 }
53089bec 11578 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11579 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11580 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11581 }
11582
11583 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11584 vty_out(vty,
11585 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11586 return CMD_WARNING;
11587 }
11588
03915806
CS
11589 if (vrf && strmatch(vrf, "all"))
11590 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11591
11592 if (uj)
11593 json = json_object_new_object();
11594
11595 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11596}
11597
d62a17ae 11598static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11599 safi_t safi)
f186de26 11600{
d62a17ae 11601 struct listnode *node, *nnode;
11602 struct bgp *bgp;
f186de26 11603
d62a17ae 11604 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11605 vty_out(vty, "\nInstance %s:\n",
11606 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11607 ? VRF_DEFAULT_NAME
d62a17ae 11608 : bgp->name);
11609 update_group_show(bgp, afi, safi, vty, 0);
11610 }
f186de26 11611}
11612
d62a17ae 11613static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11614 int safi, uint64_t subgrp_id)
4fb25c53 11615{
d62a17ae 11616 struct bgp *bgp;
4fb25c53 11617
d62a17ae 11618 if (name) {
11619 if (strmatch(name, "all")) {
11620 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11621 return CMD_SUCCESS;
11622 } else {
11623 bgp = bgp_lookup_by_name(name);
11624 }
11625 } else {
11626 bgp = bgp_get_default();
11627 }
4fb25c53 11628
d62a17ae 11629 if (bgp)
11630 update_group_show(bgp, afi, safi, vty, subgrp_id);
11631 return CMD_SUCCESS;
4fb25c53
DW
11632}
11633
8fe8a7f6
DS
11634DEFUN (show_ip_bgp_updgrps,
11635 show_ip_bgp_updgrps_cmd,
c1a44e43 11636 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11637 SHOW_STR
11638 IP_STR
11639 BGP_STR
11640 BGP_INSTANCE_HELP_STR
c9e571b4 11641 BGP_AFI_HELP_STR
9bedbb1e 11642 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11643 "Detailed info about dynamic update groups\n"
11644 "Specific subgroup to display detailed info for\n")
8386ac43 11645{
d62a17ae 11646 char *vrf = NULL;
11647 afi_t afi = AFI_IP6;
11648 safi_t safi = SAFI_UNICAST;
11649 uint64_t subgrp_id = 0;
11650
11651 int idx = 0;
11652
11653 /* show [ip] bgp */
11654 if (argv_find(argv, argc, "ip", &idx))
11655 afi = AFI_IP;
9a8bdf1c
PG
11656 /* [<vrf> VIEWVRFNAME] */
11657 if (argv_find(argv, argc, "vrf", &idx)) {
11658 vrf = argv[idx + 1]->arg;
11659 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11660 vrf = NULL;
11661 } else if (argv_find(argv, argc, "view", &idx))
11662 /* [<view> VIEWVRFNAME] */
11663 vrf = argv[idx + 1]->arg;
d62a17ae 11664 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11665 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11666 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11667 }
5bf15956 11668
d62a17ae 11669 /* get subgroup id, if provided */
11670 idx = argc - 1;
11671 if (argv[idx]->type == VARIABLE_TKN)
11672 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11673
d62a17ae 11674 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11675}
11676
f186de26 11677DEFUN (show_bgp_instance_all_ipv6_updgrps,
11678 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11679 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11680 SHOW_STR
716b2d8a 11681 IP_STR
f186de26 11682 BGP_STR
11683 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11684 "Detailed info about dynamic update groups\n")
f186de26 11685{
d62a17ae 11686 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11687 return CMD_SUCCESS;
f186de26 11688}
11689
43d3f4fc
DS
11690DEFUN (show_bgp_l2vpn_evpn_updgrps,
11691 show_bgp_l2vpn_evpn_updgrps_cmd,
11692 "show [ip] bgp l2vpn evpn update-groups",
11693 SHOW_STR
11694 IP_STR
11695 BGP_STR
11696 "l2vpn address family\n"
11697 "evpn sub-address family\n"
11698 "Detailed info about dynamic update groups\n")
11699{
11700 char *vrf = NULL;
11701 uint64_t subgrp_id = 0;
11702
11703 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11704 return CMD_SUCCESS;
11705}
11706
5bf15956
DW
11707DEFUN (show_bgp_updgrps_stats,
11708 show_bgp_updgrps_stats_cmd,
716b2d8a 11709 "show [ip] bgp update-groups statistics",
3f9c7369 11710 SHOW_STR
716b2d8a 11711 IP_STR
3f9c7369 11712 BGP_STR
0c7b1b01 11713 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11714 "Statistics\n")
11715{
d62a17ae 11716 struct bgp *bgp;
3f9c7369 11717
d62a17ae 11718 bgp = bgp_get_default();
11719 if (bgp)
11720 update_group_show_stats(bgp, vty);
3f9c7369 11721
d62a17ae 11722 return CMD_SUCCESS;
3f9c7369
DS
11723}
11724
8386ac43 11725DEFUN (show_bgp_instance_updgrps_stats,
11726 show_bgp_instance_updgrps_stats_cmd,
18c57037 11727 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11728 SHOW_STR
716b2d8a 11729 IP_STR
8386ac43 11730 BGP_STR
11731 BGP_INSTANCE_HELP_STR
0c7b1b01 11732 "Detailed info about dynamic update groups\n"
8386ac43 11733 "Statistics\n")
11734{
d62a17ae 11735 int idx_word = 3;
11736 struct bgp *bgp;
8386ac43 11737
d62a17ae 11738 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11739 if (bgp)
11740 update_group_show_stats(bgp, vty);
8386ac43 11741
d62a17ae 11742 return CMD_SUCCESS;
8386ac43 11743}
11744
d62a17ae 11745static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11746 afi_t afi, safi_t safi,
11747 const char *what, uint64_t subgrp_id)
3f9c7369 11748{
d62a17ae 11749 struct bgp *bgp;
8386ac43 11750
d62a17ae 11751 if (name)
11752 bgp = bgp_lookup_by_name(name);
11753 else
11754 bgp = bgp_get_default();
8386ac43 11755
d62a17ae 11756 if (bgp) {
11757 if (!strcmp(what, "advertise-queue"))
11758 update_group_show_adj_queue(bgp, afi, safi, vty,
11759 subgrp_id);
11760 else if (!strcmp(what, "advertised-routes"))
11761 update_group_show_advertised(bgp, afi, safi, vty,
11762 subgrp_id);
11763 else if (!strcmp(what, "packet-queue"))
11764 update_group_show_packet_queue(bgp, afi, safi, vty,
11765 subgrp_id);
11766 }
3f9c7369
DS
11767}
11768
dc64bdec
QY
11769DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11770 show_ip_bgp_instance_updgrps_adj_s_cmd,
11771 "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",
11772 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11773 BGP_SAFI_HELP_STR
11774 "Detailed info about dynamic update groups\n"
11775 "Specific subgroup to display info for\n"
11776 "Advertisement queue\n"
11777 "Announced routes\n"
11778 "Packet queue\n")
3f9c7369 11779{
dc64bdec
QY
11780 uint64_t subgrp_id = 0;
11781 afi_t afiz;
11782 safi_t safiz;
11783 if (sgid)
11784 subgrp_id = strtoull(sgid, NULL, 10);
11785
11786 if (!ip && !afi)
11787 afiz = AFI_IP6;
11788 if (!ip && afi)
11789 afiz = bgp_vty_afi_from_str(afi);
11790 if (ip && !afi)
11791 afiz = AFI_IP;
11792 if (ip && afi) {
11793 afiz = bgp_vty_afi_from_str(afi);
11794 if (afiz != AFI_IP)
11795 vty_out(vty,
11796 "%% Cannot specify both 'ip' and 'ipv6'\n");
11797 return CMD_WARNING;
11798 }
d62a17ae 11799
dc64bdec 11800 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11801
dc64bdec 11802 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11803 return CMD_SUCCESS;
11804}
11805
d62a17ae 11806static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11807{
11808 struct listnode *node, *nnode;
11809 struct prefix *range;
11810 struct peer *conf;
11811 struct peer *peer;
11812 char buf[PREFIX2STR_BUFFER];
11813 afi_t afi;
11814 safi_t safi;
11815 const char *peer_status;
11816 const char *af_str;
11817 int lr_count;
11818 int dynamic;
11819 int af_cfgd;
11820
11821 conf = group->conf;
11822
11823 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
11824 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11825 group->name, conf->as);
d62a17ae 11826 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
11827 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11828 group->name, group->bgp->as);
d62a17ae 11829 } else {
11830 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11831 }
f14e6fdb 11832
d62a17ae 11833 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11834 vty_out(vty, " Peer-group type is internal\n");
11835 else
11836 vty_out(vty, " Peer-group type is external\n");
11837
11838 /* Display AFs configured. */
11839 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11840 FOREACH_AFI_SAFI (afi, safi) {
11841 if (conf->afc[afi][safi]) {
11842 af_cfgd = 1;
11843 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11844 }
05c7a1cc 11845 }
d62a17ae 11846 if (!af_cfgd)
11847 vty_out(vty, " none\n");
11848 else
11849 vty_out(vty, "\n");
11850
11851 /* Display listen ranges (for dynamic neighbors), if any */
11852 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11853 if (afi == AFI_IP)
11854 af_str = "IPv4";
11855 else if (afi == AFI_IP6)
11856 af_str = "IPv6";
11857 else
11858 af_str = "???";
11859 lr_count = listcount(group->listen_range[afi]);
11860 if (lr_count) {
11861 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11862 af_str);
11863
11864
11865 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11866 nnode, range)) {
11867 prefix2str(range, buf, sizeof(buf));
11868 vty_out(vty, " %s\n", buf);
11869 }
11870 }
11871 }
f14e6fdb 11872
d62a17ae 11873 /* Display group members and their status */
11874 if (listcount(group->peer)) {
11875 vty_out(vty, " Peer-group members:\n");
11876 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11877 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11878 peer_status = "Idle (Admin)";
11879 else if (CHECK_FLAG(peer->sflags,
11880 PEER_STATUS_PREFIX_OVERFLOW))
11881 peer_status = "Idle (PfxCt)";
11882 else
11883 peer_status = lookup_msg(bgp_status_msg,
11884 peer->status, NULL);
11885
11886 dynamic = peer_dynamic_neighbor(peer);
11887 vty_out(vty, " %s %s %s \n", peer->host,
11888 dynamic ? "(dynamic)" : "", peer_status);
11889 }
11890 }
f14e6fdb 11891
d62a17ae 11892 return CMD_SUCCESS;
11893}
11894
ff9959b0
QY
11895static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11896 const char *group_name)
d62a17ae 11897{
ff9959b0 11898 struct bgp *bgp;
d62a17ae 11899 struct listnode *node, *nnode;
11900 struct peer_group *group;
ff9959b0
QY
11901 bool found = false;
11902
11903 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11904
11905 if (!bgp) {
9f049418 11906 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11907 return CMD_WARNING;
11908 }
d62a17ae 11909
11910 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11911 if (group_name) {
11912 if (strmatch(group->name, group_name)) {
d62a17ae 11913 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11914 found = true;
11915 break;
d62a17ae 11916 }
ff9959b0
QY
11917 } else {
11918 bgp_show_one_peer_group(vty, group);
d62a17ae 11919 }
f14e6fdb 11920 }
f14e6fdb 11921
ff9959b0 11922 if (group_name && !found)
d62a17ae 11923 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11924
d62a17ae 11925 return CMD_SUCCESS;
f14e6fdb
DS
11926}
11927
f14e6fdb
DS
11928DEFUN (show_ip_bgp_peer_groups,
11929 show_ip_bgp_peer_groups_cmd,
18c57037 11930 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11931 SHOW_STR
11932 IP_STR
11933 BGP_STR
8386ac43 11934 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11935 "Detailed information on BGP peer groups\n"
11936 "Peer group name\n")
f14e6fdb 11937{
d62a17ae 11938 char *vrf, *pg;
d62a17ae 11939 int idx = 0;
f14e6fdb 11940
a4d82a8a
PZ
11941 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11942 : NULL;
d62a17ae 11943 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11944
ff9959b0 11945 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11946}
3f9c7369 11947
d6e3c605 11948
718e3744 11949/* Redistribute VTY commands. */
11950
718e3744 11951DEFUN (bgp_redistribute_ipv4,
11952 bgp_redistribute_ipv4_cmd,
40d1cbfb 11953 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11954 "Redistribute information from another routing protocol\n"
ab0181ee 11955 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11956{
d62a17ae 11957 VTY_DECLVAR_CONTEXT(bgp, bgp);
11958 int idx_protocol = 1;
11959 int type;
718e3744 11960
d62a17ae 11961 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11962 if (type < 0) {
11963 vty_out(vty, "%% Invalid route type\n");
11964 return CMD_WARNING_CONFIG_FAILED;
11965 }
7f323236 11966
d62a17ae 11967 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11968 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11969}
11970
d62a17ae 11971ALIAS_HIDDEN(
11972 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11973 "redistribute " FRR_IP_REDIST_STR_BGPD,
11974 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11975
718e3744 11976DEFUN (bgp_redistribute_ipv4_rmap,
11977 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11978 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11979 "Redistribute information from another routing protocol\n"
ab0181ee 11980 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11981 "Route map reference\n"
11982 "Pointer to route-map entries\n")
11983{
d62a17ae 11984 VTY_DECLVAR_CONTEXT(bgp, bgp);
11985 int idx_protocol = 1;
11986 int idx_word = 3;
11987 int type;
11988 struct bgp_redist *red;
e923dd62 11989 bool changed;
1de27621
DA
11990 struct route_map *route_map = route_map_lookup_warn_noexist(
11991 vty, argv[idx_word]->arg);
718e3744 11992
d62a17ae 11993 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11994 if (type < 0) {
11995 vty_out(vty, "%% Invalid route type\n");
11996 return CMD_WARNING_CONFIG_FAILED;
11997 }
718e3744 11998
d62a17ae 11999 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12000 changed =
12001 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12002 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 12003}
12004
d62a17ae 12005ALIAS_HIDDEN(
12006 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12007 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12008 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12009 "Route map reference\n"
12010 "Pointer to route-map entries\n")
596c17ba 12011
718e3744 12012DEFUN (bgp_redistribute_ipv4_metric,
12013 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 12014 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12015 "Redistribute information from another routing protocol\n"
ab0181ee 12016 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12017 "Metric for redistributed routes\n"
12018 "Default metric\n")
12019{
d62a17ae 12020 VTY_DECLVAR_CONTEXT(bgp, bgp);
12021 int idx_protocol = 1;
12022 int idx_number = 3;
12023 int type;
d7c0a89a 12024 uint32_t metric;
d62a17ae 12025 struct bgp_redist *red;
e923dd62 12026 bool changed;
d62a17ae 12027
12028 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12029 if (type < 0) {
12030 vty_out(vty, "%% Invalid route type\n");
12031 return CMD_WARNING_CONFIG_FAILED;
12032 }
12033 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12034
12035 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12036 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12037 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12038}
12039
12040ALIAS_HIDDEN(
12041 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12042 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12043 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12044 "Metric for redistributed routes\n"
12045 "Default metric\n")
596c17ba 12046
718e3744 12047DEFUN (bgp_redistribute_ipv4_rmap_metric,
12048 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 12049 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12050 "Redistribute information from another routing protocol\n"
ab0181ee 12051 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12052 "Route map reference\n"
12053 "Pointer to route-map entries\n"
12054 "Metric for redistributed routes\n"
12055 "Default metric\n")
12056{
d62a17ae 12057 VTY_DECLVAR_CONTEXT(bgp, bgp);
12058 int idx_protocol = 1;
12059 int idx_word = 3;
12060 int idx_number = 5;
12061 int type;
d7c0a89a 12062 uint32_t metric;
d62a17ae 12063 struct bgp_redist *red;
e923dd62 12064 bool changed;
1de27621
DA
12065 struct route_map *route_map =
12066 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12067
12068 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12069 if (type < 0) {
12070 vty_out(vty, "%% Invalid route type\n");
12071 return CMD_WARNING_CONFIG_FAILED;
12072 }
12073 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12074
12075 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12076 changed =
12077 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12078 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12079 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12080}
12081
12082ALIAS_HIDDEN(
12083 bgp_redistribute_ipv4_rmap_metric,
12084 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12085 "redistribute " FRR_IP_REDIST_STR_BGPD
12086 " route-map WORD metric (0-4294967295)",
12087 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12088 "Route map reference\n"
12089 "Pointer to route-map entries\n"
12090 "Metric for redistributed routes\n"
12091 "Default metric\n")
596c17ba 12092
718e3744 12093DEFUN (bgp_redistribute_ipv4_metric_rmap,
12094 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12095 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12096 "Redistribute information from another routing protocol\n"
ab0181ee 12097 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12098 "Metric for redistributed routes\n"
12099 "Default metric\n"
12100 "Route map reference\n"
12101 "Pointer to route-map entries\n")
12102{
d62a17ae 12103 VTY_DECLVAR_CONTEXT(bgp, bgp);
12104 int idx_protocol = 1;
12105 int idx_number = 3;
12106 int idx_word = 5;
12107 int type;
d7c0a89a 12108 uint32_t metric;
d62a17ae 12109 struct bgp_redist *red;
e923dd62 12110 bool changed;
1de27621
DA
12111 struct route_map *route_map =
12112 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12113
12114 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12115 if (type < 0) {
12116 vty_out(vty, "%% Invalid route type\n");
12117 return CMD_WARNING_CONFIG_FAILED;
12118 }
12119 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12120
12121 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12122 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12123 changed |=
12124 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12125 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12126}
12127
12128ALIAS_HIDDEN(
12129 bgp_redistribute_ipv4_metric_rmap,
12130 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12131 "redistribute " FRR_IP_REDIST_STR_BGPD
12132 " metric (0-4294967295) route-map WORD",
12133 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12134 "Metric for redistributed routes\n"
12135 "Default metric\n"
12136 "Route map reference\n"
12137 "Pointer to route-map entries\n")
596c17ba 12138
7c8ff89e
DS
12139DEFUN (bgp_redistribute_ipv4_ospf,
12140 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12141 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12142 "Redistribute information from another routing protocol\n"
12143 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12144 "Non-main Kernel Routing Table\n"
12145 "Instance ID/Table ID\n")
7c8ff89e 12146{
d62a17ae 12147 VTY_DECLVAR_CONTEXT(bgp, bgp);
12148 int idx_ospf_table = 1;
12149 int idx_number = 2;
d7c0a89a
QY
12150 unsigned short instance;
12151 unsigned short protocol;
7c8ff89e 12152
d62a17ae 12153 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12154
d62a17ae 12155 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12156 protocol = ZEBRA_ROUTE_OSPF;
12157 else
12158 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12159
d62a17ae 12160 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12161 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12162}
12163
d62a17ae 12164ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12165 "redistribute <ospf|table> (1-65535)",
12166 "Redistribute information from another routing protocol\n"
12167 "Open Shortest Path First (OSPFv2)\n"
12168 "Non-main Kernel Routing Table\n"
12169 "Instance ID/Table ID\n")
596c17ba 12170
7c8ff89e
DS
12171DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12172 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12173 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12174 "Redistribute information from another routing protocol\n"
12175 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12176 "Non-main Kernel Routing Table\n"
12177 "Instance ID/Table ID\n"
7c8ff89e
DS
12178 "Route map reference\n"
12179 "Pointer to route-map entries\n")
12180{
d62a17ae 12181 VTY_DECLVAR_CONTEXT(bgp, bgp);
12182 int idx_ospf_table = 1;
12183 int idx_number = 2;
12184 int idx_word = 4;
12185 struct bgp_redist *red;
d7c0a89a 12186 unsigned short instance;
d62a17ae 12187 int protocol;
e923dd62 12188 bool changed;
1de27621
DA
12189 struct route_map *route_map =
12190 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12191
12192 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12193 protocol = ZEBRA_ROUTE_OSPF;
12194 else
12195 protocol = ZEBRA_ROUTE_TABLE;
12196
12197 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12198 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12199 changed =
12200 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12201 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12202}
12203
12204ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12205 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12206 "redistribute <ospf|table> (1-65535) route-map WORD",
12207 "Redistribute information from another routing protocol\n"
12208 "Open Shortest Path First (OSPFv2)\n"
12209 "Non-main Kernel Routing Table\n"
12210 "Instance ID/Table ID\n"
12211 "Route map reference\n"
12212 "Pointer to route-map entries\n")
596c17ba 12213
7c8ff89e
DS
12214DEFUN (bgp_redistribute_ipv4_ospf_metric,
12215 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12216 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12217 "Redistribute information from another routing protocol\n"
12218 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12219 "Non-main Kernel Routing Table\n"
12220 "Instance ID/Table ID\n"
7c8ff89e
DS
12221 "Metric for redistributed routes\n"
12222 "Default metric\n")
12223{
d62a17ae 12224 VTY_DECLVAR_CONTEXT(bgp, bgp);
12225 int idx_ospf_table = 1;
12226 int idx_number = 2;
12227 int idx_number_2 = 4;
d7c0a89a 12228 uint32_t metric;
d62a17ae 12229 struct bgp_redist *red;
d7c0a89a 12230 unsigned short instance;
d62a17ae 12231 int protocol;
e923dd62 12232 bool changed;
d62a17ae 12233
12234 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12235 protocol = ZEBRA_ROUTE_OSPF;
12236 else
12237 protocol = ZEBRA_ROUTE_TABLE;
12238
12239 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12240 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12241
12242 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12243 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12244 metric);
12245 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12246}
12247
12248ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12249 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12250 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12251 "Redistribute information from another routing protocol\n"
12252 "Open Shortest Path First (OSPFv2)\n"
12253 "Non-main Kernel Routing Table\n"
12254 "Instance ID/Table ID\n"
12255 "Metric for redistributed routes\n"
12256 "Default metric\n")
596c17ba 12257
7c8ff89e
DS
12258DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12259 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12260 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12261 "Redistribute information from another routing protocol\n"
12262 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12263 "Non-main Kernel Routing Table\n"
12264 "Instance ID/Table ID\n"
7c8ff89e
DS
12265 "Route map reference\n"
12266 "Pointer to route-map entries\n"
12267 "Metric for redistributed routes\n"
12268 "Default metric\n")
12269{
d62a17ae 12270 VTY_DECLVAR_CONTEXT(bgp, bgp);
12271 int idx_ospf_table = 1;
12272 int idx_number = 2;
12273 int idx_word = 4;
12274 int idx_number_2 = 6;
d7c0a89a 12275 uint32_t metric;
d62a17ae 12276 struct bgp_redist *red;
d7c0a89a 12277 unsigned short instance;
d62a17ae 12278 int protocol;
e923dd62 12279 bool changed;
1de27621
DA
12280 struct route_map *route_map =
12281 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12282
12283 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12284 protocol = ZEBRA_ROUTE_OSPF;
12285 else
12286 protocol = ZEBRA_ROUTE_TABLE;
12287
12288 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12289 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12290
12291 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12292 changed =
12293 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12294 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12295 metric);
12296 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12297}
12298
12299ALIAS_HIDDEN(
12300 bgp_redistribute_ipv4_ospf_rmap_metric,
12301 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12302 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12303 "Redistribute information from another routing protocol\n"
12304 "Open Shortest Path First (OSPFv2)\n"
12305 "Non-main Kernel Routing Table\n"
12306 "Instance ID/Table ID\n"
12307 "Route map reference\n"
12308 "Pointer to route-map entries\n"
12309 "Metric for redistributed routes\n"
12310 "Default metric\n")
596c17ba 12311
7c8ff89e
DS
12312DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12313 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12314 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12315 "Redistribute information from another routing protocol\n"
12316 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12317 "Non-main Kernel Routing Table\n"
12318 "Instance ID/Table ID\n"
7c8ff89e
DS
12319 "Metric for redistributed routes\n"
12320 "Default metric\n"
12321 "Route map reference\n"
12322 "Pointer to route-map entries\n")
12323{
d62a17ae 12324 VTY_DECLVAR_CONTEXT(bgp, bgp);
12325 int idx_ospf_table = 1;
12326 int idx_number = 2;
12327 int idx_number_2 = 4;
12328 int idx_word = 6;
d7c0a89a 12329 uint32_t metric;
d62a17ae 12330 struct bgp_redist *red;
d7c0a89a 12331 unsigned short instance;
d62a17ae 12332 int protocol;
e923dd62 12333 bool changed;
1de27621
DA
12334 struct route_map *route_map =
12335 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12336
12337 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12338 protocol = ZEBRA_ROUTE_OSPF;
12339 else
12340 protocol = ZEBRA_ROUTE_TABLE;
12341
12342 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12343 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12344
12345 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12346 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12347 metric);
1de27621
DA
12348 changed |=
12349 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12350 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12351}
12352
12353ALIAS_HIDDEN(
12354 bgp_redistribute_ipv4_ospf_metric_rmap,
12355 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12356 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12357 "Redistribute information from another routing protocol\n"
12358 "Open Shortest Path First (OSPFv2)\n"
12359 "Non-main Kernel Routing Table\n"
12360 "Instance ID/Table ID\n"
12361 "Metric for redistributed routes\n"
12362 "Default metric\n"
12363 "Route map reference\n"
12364 "Pointer to route-map entries\n")
596c17ba 12365
7c8ff89e
DS
12366DEFUN (no_bgp_redistribute_ipv4_ospf,
12367 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12368 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12369 NO_STR
12370 "Redistribute information from another routing protocol\n"
12371 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12372 "Non-main Kernel Routing Table\n"
31500417
DW
12373 "Instance ID/Table ID\n"
12374 "Metric for redistributed routes\n"
12375 "Default metric\n"
12376 "Route map reference\n"
12377 "Pointer to route-map entries\n")
7c8ff89e 12378{
d62a17ae 12379 VTY_DECLVAR_CONTEXT(bgp, bgp);
12380 int idx_ospf_table = 2;
12381 int idx_number = 3;
d7c0a89a 12382 unsigned short instance;
d62a17ae 12383 int protocol;
12384
12385 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12386 protocol = ZEBRA_ROUTE_OSPF;
12387 else
12388 protocol = ZEBRA_ROUTE_TABLE;
12389
12390 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12391 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12392}
12393
12394ALIAS_HIDDEN(
12395 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12396 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12397 NO_STR
12398 "Redistribute information from another routing protocol\n"
12399 "Open Shortest Path First (OSPFv2)\n"
12400 "Non-main Kernel Routing Table\n"
12401 "Instance ID/Table ID\n"
12402 "Metric for redistributed routes\n"
12403 "Default metric\n"
12404 "Route map reference\n"
12405 "Pointer to route-map entries\n")
596c17ba 12406
718e3744 12407DEFUN (no_bgp_redistribute_ipv4,
12408 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12409 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12410 NO_STR
12411 "Redistribute information from another routing protocol\n"
3b14d86e 12412 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12413 "Metric for redistributed routes\n"
12414 "Default metric\n"
12415 "Route map reference\n"
12416 "Pointer to route-map entries\n")
718e3744 12417{
d62a17ae 12418 VTY_DECLVAR_CONTEXT(bgp, bgp);
12419 int idx_protocol = 2;
12420 int type;
12421
12422 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12423 if (type < 0) {
12424 vty_out(vty, "%% Invalid route type\n");
12425 return CMD_WARNING_CONFIG_FAILED;
12426 }
12427 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12428}
12429
12430ALIAS_HIDDEN(
12431 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12432 "no redistribute " FRR_IP_REDIST_STR_BGPD
12433 " [metric (0-4294967295)] [route-map WORD]",
12434 NO_STR
12435 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12436 "Metric for redistributed routes\n"
12437 "Default metric\n"
12438 "Route map reference\n"
12439 "Pointer to route-map entries\n")
596c17ba 12440
718e3744 12441DEFUN (bgp_redistribute_ipv6,
12442 bgp_redistribute_ipv6_cmd,
40d1cbfb 12443 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12444 "Redistribute information from another routing protocol\n"
ab0181ee 12445 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12446{
d62a17ae 12447 VTY_DECLVAR_CONTEXT(bgp, bgp);
12448 int idx_protocol = 1;
12449 int type;
718e3744 12450
d62a17ae 12451 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12452 if (type < 0) {
12453 vty_out(vty, "%% Invalid route type\n");
12454 return CMD_WARNING_CONFIG_FAILED;
12455 }
718e3744 12456
d62a17ae 12457 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12458 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12459}
12460
12461DEFUN (bgp_redistribute_ipv6_rmap,
12462 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12463 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12464 "Redistribute information from another routing protocol\n"
ab0181ee 12465 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12466 "Route map reference\n"
12467 "Pointer to route-map entries\n")
12468{
d62a17ae 12469 VTY_DECLVAR_CONTEXT(bgp, bgp);
12470 int idx_protocol = 1;
12471 int idx_word = 3;
12472 int type;
12473 struct bgp_redist *red;
e923dd62 12474 bool changed;
1de27621
DA
12475 struct route_map *route_map =
12476 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12477
d62a17ae 12478 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12479 if (type < 0) {
12480 vty_out(vty, "%% Invalid route type\n");
12481 return CMD_WARNING_CONFIG_FAILED;
12482 }
718e3744 12483
d62a17ae 12484 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12485 changed =
12486 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12487 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12488}
12489
12490DEFUN (bgp_redistribute_ipv6_metric,
12491 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12492 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12493 "Redistribute information from another routing protocol\n"
ab0181ee 12494 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12495 "Metric for redistributed routes\n"
12496 "Default metric\n")
12497{
d62a17ae 12498 VTY_DECLVAR_CONTEXT(bgp, bgp);
12499 int idx_protocol = 1;
12500 int idx_number = 3;
12501 int type;
d7c0a89a 12502 uint32_t metric;
d62a17ae 12503 struct bgp_redist *red;
e923dd62 12504 bool changed;
d62a17ae 12505
12506 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12507 if (type < 0) {
12508 vty_out(vty, "%% Invalid route type\n");
12509 return CMD_WARNING_CONFIG_FAILED;
12510 }
12511 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12512
d62a17ae 12513 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12514 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12515 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12516}
12517
12518DEFUN (bgp_redistribute_ipv6_rmap_metric,
12519 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12520 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12521 "Redistribute information from another routing protocol\n"
ab0181ee 12522 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12523 "Route map reference\n"
12524 "Pointer to route-map entries\n"
12525 "Metric for redistributed routes\n"
12526 "Default metric\n")
12527{
d62a17ae 12528 VTY_DECLVAR_CONTEXT(bgp, bgp);
12529 int idx_protocol = 1;
12530 int idx_word = 3;
12531 int idx_number = 5;
12532 int type;
d7c0a89a 12533 uint32_t metric;
d62a17ae 12534 struct bgp_redist *red;
e923dd62 12535 bool changed;
1de27621
DA
12536 struct route_map *route_map =
12537 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12538
12539 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12540 if (type < 0) {
12541 vty_out(vty, "%% Invalid route type\n");
12542 return CMD_WARNING_CONFIG_FAILED;
12543 }
12544 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12545
d62a17ae 12546 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12547 changed =
12548 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12549 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12550 metric);
12551 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12552}
12553
12554DEFUN (bgp_redistribute_ipv6_metric_rmap,
12555 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12556 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12557 "Redistribute information from another routing protocol\n"
ab0181ee 12558 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12559 "Metric for redistributed routes\n"
12560 "Default metric\n"
12561 "Route map reference\n"
12562 "Pointer to route-map entries\n")
12563{
d62a17ae 12564 VTY_DECLVAR_CONTEXT(bgp, bgp);
12565 int idx_protocol = 1;
12566 int idx_number = 3;
12567 int idx_word = 5;
12568 int type;
d7c0a89a 12569 uint32_t metric;
d62a17ae 12570 struct bgp_redist *red;
e923dd62 12571 bool changed;
1de27621
DA
12572 struct route_map *route_map =
12573 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12574
12575 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12576 if (type < 0) {
12577 vty_out(vty, "%% Invalid route type\n");
12578 return CMD_WARNING_CONFIG_FAILED;
12579 }
12580 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12581
d62a17ae 12582 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12583 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12584 metric);
1de27621
DA
12585 changed |=
12586 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12587 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12588}
12589
12590DEFUN (no_bgp_redistribute_ipv6,
12591 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12592 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12593 NO_STR
12594 "Redistribute information from another routing protocol\n"
3b14d86e 12595 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12596 "Metric for redistributed routes\n"
12597 "Default metric\n"
12598 "Route map reference\n"
12599 "Pointer to route-map entries\n")
718e3744 12600{
d62a17ae 12601 VTY_DECLVAR_CONTEXT(bgp, bgp);
12602 int idx_protocol = 2;
12603 int type;
718e3744 12604
d62a17ae 12605 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12606 if (type < 0) {
12607 vty_out(vty, "%% Invalid route type\n");
12608 return CMD_WARNING_CONFIG_FAILED;
12609 }
718e3744 12610
d62a17ae 12611 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12612}
12613
2b791107 12614void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12615 safi_t safi)
d62a17ae 12616{
12617 int i;
12618
12619 /* Unicast redistribution only. */
12620 if (safi != SAFI_UNICAST)
2b791107 12621 return;
d62a17ae 12622
12623 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12624 /* Redistribute BGP does not make sense. */
12625 if (i != ZEBRA_ROUTE_BGP) {
12626 struct list *red_list;
12627 struct listnode *node;
12628 struct bgp_redist *red;
12629
12630 red_list = bgp->redist[afi][i];
12631 if (!red_list)
12632 continue;
12633
12634 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12635 /* "redistribute" configuration. */
12636 vty_out(vty, " redistribute %s",
12637 zebra_route_string(i));
12638 if (red->instance)
12639 vty_out(vty, " %d", red->instance);
12640 if (red->redist_metric_flag)
12641 vty_out(vty, " metric %u",
12642 red->redist_metric);
12643 if (red->rmap.name)
12644 vty_out(vty, " route-map %s",
12645 red->rmap.name);
12646 vty_out(vty, "\n");
12647 }
12648 }
12649 }
718e3744 12650}
6b0655a2 12651
b9c7bc5a
PZ
12652/* This is part of the address-family block (unicast only) */
12653void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12654 afi_t afi)
12655{
b9c7bc5a 12656 int indent = 2;
ddb5b488 12657
8a066a70
PG
12658 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12659 if (listcount(bgp->vpn_policy[afi].import_vrf))
12660 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12661 bgp->vpn_policy[afi]
bb4f6190 12662 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12663 else
12664 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12665 bgp->vpn_policy[afi]
12666 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12667 }
12a844a5
DS
12668 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12669 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12670 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12671 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12672 return;
12673
e70e9f8e
PZ
12674 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12675 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12676
12677 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12678
12679 } else {
12680 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12681 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12682 bgp->vpn_policy[afi].tovpn_label);
12683 }
ddb5b488
PZ
12684 }
12685 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12686 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12687 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12688 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12689 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12690 sizeof(buf)));
12691 }
12692 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12693 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12694
12695 char buf[PREFIX_STRLEN];
12696 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12697 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12698 sizeof(buf))) {
12699
b9c7bc5a
PZ
12700 vty_out(vty, "%*snexthop vpn export %s\n",
12701 indent, "", buf);
ddb5b488
PZ
12702 }
12703 }
12704 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12705 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12706 && ecommunity_cmp(
12707 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12708 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12709
12710 char *b = ecommunity_ecom2str(
12711 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12712 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12713 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12714 XFREE(MTYPE_ECOMMUNITY_STR, b);
12715 } else {
12716 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12717 char *b = ecommunity_ecom2str(
12718 bgp->vpn_policy[afi]
12719 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12720 ECOMMUNITY_FORMAT_ROUTE_MAP,
12721 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12722 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12723 XFREE(MTYPE_ECOMMUNITY_STR, b);
12724 }
12725 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12726 char *b = ecommunity_ecom2str(
12727 bgp->vpn_policy[afi]
12728 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12729 ECOMMUNITY_FORMAT_ROUTE_MAP,
12730 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12731 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12732 XFREE(MTYPE_ECOMMUNITY_STR, b);
12733 }
12734 }
bb4f6190
DS
12735
12736 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12737 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12738 bgp->vpn_policy[afi]
12739 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12740
301ad80a
PG
12741 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12742 char *b = ecommunity_ecom2str(
12743 bgp->vpn_policy[afi]
12744 .import_redirect_rtlist,
12745 ECOMMUNITY_FORMAT_ROUTE_MAP,
12746 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12747
301ad80a
PG
12748 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12749 XFREE(MTYPE_ECOMMUNITY_STR, b);
12750 }
ddb5b488
PZ
12751}
12752
12753
718e3744 12754/* BGP node structure. */
d62a17ae 12755static struct cmd_node bgp_node = {
9d303b37 12756 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12757};
12758
d62a17ae 12759static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12760 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12761};
12762
d62a17ae 12763static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12764 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12765};
12766
d62a17ae 12767static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12768 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12769};
12770
d62a17ae 12771static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12772 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12773};
12774
d62a17ae 12775static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12776 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12777};
12778
d62a17ae 12779static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12780 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12781};
12782
d62a17ae 12783static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12784 "%s(config-router-af)# ", 1};
6b0655a2 12785
d62a17ae 12786static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12787 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12788
d62a17ae 12789static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12790 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12791
d62a17ae 12792static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12793 "%s(config-router-af-vni)# ", 1};
90e60aa7 12794
7c40bf39 12795static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12796 "%s(config-router-af)# ", 1};
12797
12798static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12799 "%s(config-router-af-vpnv6)# ", 1};
12800
d62a17ae 12801static void community_list_vty(void);
1f8ae70b 12802
d62a17ae 12803static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12804{
d62a17ae 12805 struct bgp *bgp;
12806 struct peer *peer;
d62a17ae 12807 struct listnode *lnbgp, *lnpeer;
b8a815e5 12808
d62a17ae 12809 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12810 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12811 /* only provide suggestions on the appropriate input
12812 * token type,
12813 * they'll otherwise show up multiple times */
12814 enum cmd_token_type match_type;
12815 char *name = peer->host;
d48ed3e0 12816
d62a17ae 12817 if (peer->conf_if) {
12818 match_type = VARIABLE_TKN;
12819 name = peer->conf_if;
12820 } else if (strchr(peer->host, ':'))
12821 match_type = IPV6_TKN;
12822 else
12823 match_type = IPV4_TKN;
d48ed3e0 12824
d62a17ae 12825 if (token->type != match_type)
12826 continue;
d48ed3e0 12827
d62a17ae 12828 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12829 }
d62a17ae 12830 }
b8a815e5
DL
12831}
12832
12833static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12834 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12835 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12836 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12837 {.completions = NULL}};
12838
47a306a0
DS
12839static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12840{
12841 struct bgp *bgp;
12842 struct peer_group *group;
12843 struct listnode *lnbgp, *lnpeer;
12844
12845 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12846 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12847 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12848 group->name));
12849 }
12850}
12851
12852static const struct cmd_variable_handler bgp_var_peergroup[] = {
12853 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12854 {.completions = NULL} };
12855
d62a17ae 12856void bgp_vty_init(void)
12857{
12858 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12859 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12860
12861 /* Install bgp top node. */
12862 install_node(&bgp_node, bgp_config_write);
12863 install_node(&bgp_ipv4_unicast_node, NULL);
12864 install_node(&bgp_ipv4_multicast_node, NULL);
12865 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12866 install_node(&bgp_ipv6_unicast_node, NULL);
12867 install_node(&bgp_ipv6_multicast_node, NULL);
12868 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12869 install_node(&bgp_vpnv4_node, NULL);
12870 install_node(&bgp_vpnv6_node, NULL);
12871 install_node(&bgp_evpn_node, NULL);
12872 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12873 install_node(&bgp_flowspecv4_node, NULL);
12874 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12875
12876 /* Install default VTY commands to new nodes. */
12877 install_default(BGP_NODE);
12878 install_default(BGP_IPV4_NODE);
12879 install_default(BGP_IPV4M_NODE);
12880 install_default(BGP_IPV4L_NODE);
12881 install_default(BGP_IPV6_NODE);
12882 install_default(BGP_IPV6M_NODE);
12883 install_default(BGP_IPV6L_NODE);
12884 install_default(BGP_VPNV4_NODE);
12885 install_default(BGP_VPNV6_NODE);
7c40bf39 12886 install_default(BGP_FLOWSPECV4_NODE);
12887 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12888 install_default(BGP_EVPN_NODE);
12889 install_default(BGP_EVPN_VNI_NODE);
12890
12891 /* "bgp multiple-instance" commands. */
12892 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12893 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12894
12895 /* "bgp config-type" commands. */
12896 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12897 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12898
8029b216
AK
12899 /* "bgp local-mac" hidden commands. */
12900 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12901 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12902
d62a17ae 12903 /* bgp route-map delay-timer commands. */
12904 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12905 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12906
12907 /* Dummy commands (Currently not supported) */
12908 install_element(BGP_NODE, &no_synchronization_cmd);
12909 install_element(BGP_NODE, &no_auto_summary_cmd);
12910
12911 /* "router bgp" commands. */
12912 install_element(CONFIG_NODE, &router_bgp_cmd);
12913
12914 /* "no router bgp" commands. */
12915 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12916
12917 /* "bgp router-id" commands. */
12918 install_element(BGP_NODE, &bgp_router_id_cmd);
12919 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12920
12921 /* "bgp cluster-id" commands. */
12922 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12923 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12924
12925 /* "bgp confederation" commands. */
12926 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12927 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12928
12929 /* "bgp confederation peers" commands. */
12930 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12931 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12932
12933 /* bgp max-med command */
12934 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12935 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12936 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12937 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12938 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12939
12940 /* bgp disable-ebgp-connected-nh-check */
12941 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12942 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12943
12944 /* bgp update-delay command */
12945 install_element(BGP_NODE, &bgp_update_delay_cmd);
12946 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12947 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12948
12949 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12950 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12951 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12952 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12953
12954 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12955 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12956
12957 /* "maximum-paths" commands. */
12958 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12959 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12960 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12961 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12962 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12963 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12964 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12965 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12966 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12967 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12968 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12969 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12970 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12971 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12972 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12973
12974 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12975 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12976 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12977 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12978 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12979
12980 /* "timers bgp" commands. */
12981 install_element(BGP_NODE, &bgp_timers_cmd);
12982 install_element(BGP_NODE, &no_bgp_timers_cmd);
12983
12984 /* route-map delay-timer commands - per instance for backwards compat.
12985 */
12986 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12987 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12988
12989 /* "bgp client-to-client reflection" commands */
12990 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12991 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12992
12993 /* "bgp always-compare-med" commands */
12994 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12995 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12996
9dac9fc8
DA
12997 /* bgp ebgp-requires-policy */
12998 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12999 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13000
d62a17ae 13001 /* "bgp deterministic-med" commands */
13002 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13003 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13004
13005 /* "bgp graceful-restart" commands */
13006 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13007 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13008 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13009 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13010 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13011 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13012
13013 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13014 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13015
7f323236
DW
13016 /* "bgp graceful-shutdown" commands */
13017 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13018 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13019
d62a17ae 13020 /* "bgp fast-external-failover" commands */
13021 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13022 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13023
13024 /* "bgp enforce-first-as" commands */
13025 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 13026
13027 /* "bgp bestpath compare-routerid" commands */
13028 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13029 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13030
13031 /* "bgp bestpath as-path ignore" commands */
13032 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13033 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13034
13035 /* "bgp bestpath as-path confed" commands */
13036 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13037 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13038
13039 /* "bgp bestpath as-path multipath-relax" commands */
13040 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13041 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13042
13043 /* "bgp log-neighbor-changes" commands */
13044 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13045 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13046
13047 /* "bgp bestpath med" commands */
13048 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13049 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13050
13051 /* "no bgp default ipv4-unicast" commands. */
13052 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13053 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13054
13055 /* "bgp network import-check" commands. */
13056 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13057 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13058 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13059
13060 /* "bgp default local-preference" commands. */
13061 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13062 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13063
13064 /* bgp default show-hostname */
13065 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13066 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13067
13068 /* "bgp default subgroup-pkt-queue-max" commands. */
13069 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13070 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13071
13072 /* bgp ibgp-allow-policy-mods command */
13073 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13074 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13075
13076 /* "bgp listen limit" commands. */
13077 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13078 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13079
13080 /* "bgp listen range" commands. */
13081 install_element(BGP_NODE, &bgp_listen_range_cmd);
13082 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13083
8175f54a 13084 /* "bgp default shutdown" command */
f26845f9
QY
13085 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13086
d62a17ae 13087 /* "neighbor remote-as" commands. */
13088 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13089 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13090 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13091 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13092 install_element(BGP_NODE,
13093 &neighbor_interface_v6only_config_remote_as_cmd);
13094 install_element(BGP_NODE, &no_neighbor_cmd);
13095 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13096
13097 /* "neighbor peer-group" commands. */
13098 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13099 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13100 install_element(BGP_NODE,
13101 &no_neighbor_interface_peer_group_remote_as_cmd);
13102
13103 /* "neighbor local-as" commands. */
13104 install_element(BGP_NODE, &neighbor_local_as_cmd);
13105 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13106 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13107 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13108
13109 /* "neighbor solo" commands. */
13110 install_element(BGP_NODE, &neighbor_solo_cmd);
13111 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13112
13113 /* "neighbor password" commands. */
13114 install_element(BGP_NODE, &neighbor_password_cmd);
13115 install_element(BGP_NODE, &no_neighbor_password_cmd);
13116
13117 /* "neighbor activate" commands. */
13118 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13119 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13120 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13121 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13122 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13123 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13125 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13127 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13128 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13129 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13130
13131 /* "no neighbor activate" commands. */
13132 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13133 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13134 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13136 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13137 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13138 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13139 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13140 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13141 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13142 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13143 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13144
13145 /* "neighbor peer-group" set commands. */
13146 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13147 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13148 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13149 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13150 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13151 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13152 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13153 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13154 install_element(BGP_FLOWSPECV4_NODE,
13155 &neighbor_set_peer_group_hidden_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE,
13157 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13158
13159 /* "no neighbor peer-group unset" commands. */
13160 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13161 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13162 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13163 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13164 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13168 install_element(BGP_FLOWSPECV4_NODE,
13169 &no_neighbor_set_peer_group_hidden_cmd);
13170 install_element(BGP_FLOWSPECV6_NODE,
13171 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13172
13173 /* "neighbor softreconfiguration inbound" commands.*/
13174 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13175 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13176 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13177 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13179 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13180 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13181 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13182 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13183 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13184 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13185 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13186 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13187 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13188 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13189 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13190 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13191 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13192 install_element(BGP_FLOWSPECV4_NODE,
13193 &neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_FLOWSPECV4_NODE,
13195 &no_neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_FLOWSPECV6_NODE,
13197 &neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_FLOWSPECV6_NODE,
13199 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13200 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13202
13203 /* "neighbor attribute-unchanged" commands. */
13204 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13205 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13206 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13207 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13208 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13211 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13212 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13213 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13214 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13215 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13216 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13217 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13218 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13219 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13220 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13221 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13222
13223 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13224 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13225
13226 /* "nexthop-local unchanged" commands */
13227 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13228 install_element(BGP_IPV6_NODE,
13229 &no_neighbor_nexthop_local_unchanged_cmd);
13230
13231 /* "neighbor next-hop-self" commands. */
13232 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13233 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13235 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13236 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13237 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13238 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13239 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13240 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13241 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13242 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13243 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13244 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13245 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13246 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13247 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13248 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13249 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13250 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13251 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13252
13253 /* "neighbor next-hop-self force" commands. */
13254 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13255 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13256 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13257 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13258 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13259 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13260 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13261 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13262 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13263 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13264 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13265 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13266 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13267 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13268 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13269 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13270 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13271 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13272
13273 /* "neighbor as-override" commands. */
13274 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13275 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13276 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13277 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13278 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13280 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13281 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13282 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13283 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13284 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13285 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13287 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13288 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13289 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13290 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13291 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13292
13293 /* "neighbor remove-private-AS" commands. */
13294 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13295 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13296 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13297 install_element(BGP_NODE,
13298 &no_neighbor_remove_private_as_all_hidden_cmd);
13299 install_element(BGP_NODE,
13300 &neighbor_remove_private_as_replace_as_hidden_cmd);
13301 install_element(BGP_NODE,
13302 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13303 install_element(BGP_NODE,
13304 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13305 install_element(
13306 BGP_NODE,
13307 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13308 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13309 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13310 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13311 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13312 install_element(BGP_IPV4_NODE,
13313 &neighbor_remove_private_as_replace_as_cmd);
13314 install_element(BGP_IPV4_NODE,
13315 &no_neighbor_remove_private_as_replace_as_cmd);
13316 install_element(BGP_IPV4_NODE,
13317 &neighbor_remove_private_as_all_replace_as_cmd);
13318 install_element(BGP_IPV4_NODE,
13319 &no_neighbor_remove_private_as_all_replace_as_cmd);
13320 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13321 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13322 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13323 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13324 install_element(BGP_IPV4M_NODE,
13325 &neighbor_remove_private_as_replace_as_cmd);
13326 install_element(BGP_IPV4M_NODE,
13327 &no_neighbor_remove_private_as_replace_as_cmd);
13328 install_element(BGP_IPV4M_NODE,
13329 &neighbor_remove_private_as_all_replace_as_cmd);
13330 install_element(BGP_IPV4M_NODE,
13331 &no_neighbor_remove_private_as_all_replace_as_cmd);
13332 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13333 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13334 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13335 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13336 install_element(BGP_IPV4L_NODE,
13337 &neighbor_remove_private_as_replace_as_cmd);
13338 install_element(BGP_IPV4L_NODE,
13339 &no_neighbor_remove_private_as_replace_as_cmd);
13340 install_element(BGP_IPV4L_NODE,
13341 &neighbor_remove_private_as_all_replace_as_cmd);
13342 install_element(BGP_IPV4L_NODE,
13343 &no_neighbor_remove_private_as_all_replace_as_cmd);
13344 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13345 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13346 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13347 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13348 install_element(BGP_IPV6_NODE,
13349 &neighbor_remove_private_as_replace_as_cmd);
13350 install_element(BGP_IPV6_NODE,
13351 &no_neighbor_remove_private_as_replace_as_cmd);
13352 install_element(BGP_IPV6_NODE,
13353 &neighbor_remove_private_as_all_replace_as_cmd);
13354 install_element(BGP_IPV6_NODE,
13355 &no_neighbor_remove_private_as_all_replace_as_cmd);
13356 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13357 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13358 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13359 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13360 install_element(BGP_IPV6M_NODE,
13361 &neighbor_remove_private_as_replace_as_cmd);
13362 install_element(BGP_IPV6M_NODE,
13363 &no_neighbor_remove_private_as_replace_as_cmd);
13364 install_element(BGP_IPV6M_NODE,
13365 &neighbor_remove_private_as_all_replace_as_cmd);
13366 install_element(BGP_IPV6M_NODE,
13367 &no_neighbor_remove_private_as_all_replace_as_cmd);
13368 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13369 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13370 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13371 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13372 install_element(BGP_IPV6L_NODE,
13373 &neighbor_remove_private_as_replace_as_cmd);
13374 install_element(BGP_IPV6L_NODE,
13375 &no_neighbor_remove_private_as_replace_as_cmd);
13376 install_element(BGP_IPV6L_NODE,
13377 &neighbor_remove_private_as_all_replace_as_cmd);
13378 install_element(BGP_IPV6L_NODE,
13379 &no_neighbor_remove_private_as_all_replace_as_cmd);
13380 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13381 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13382 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13383 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13384 install_element(BGP_VPNV4_NODE,
13385 &neighbor_remove_private_as_replace_as_cmd);
13386 install_element(BGP_VPNV4_NODE,
13387 &no_neighbor_remove_private_as_replace_as_cmd);
13388 install_element(BGP_VPNV4_NODE,
13389 &neighbor_remove_private_as_all_replace_as_cmd);
13390 install_element(BGP_VPNV4_NODE,
13391 &no_neighbor_remove_private_as_all_replace_as_cmd);
13392 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13393 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13394 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13395 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13396 install_element(BGP_VPNV6_NODE,
13397 &neighbor_remove_private_as_replace_as_cmd);
13398 install_element(BGP_VPNV6_NODE,
13399 &no_neighbor_remove_private_as_replace_as_cmd);
13400 install_element(BGP_VPNV6_NODE,
13401 &neighbor_remove_private_as_all_replace_as_cmd);
13402 install_element(BGP_VPNV6_NODE,
13403 &no_neighbor_remove_private_as_all_replace_as_cmd);
13404
13405 /* "neighbor send-community" commands.*/
13406 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13407 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13408 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13409 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13410 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13411 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13412 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13413 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13414 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13415 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13416 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13417 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13418 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13419 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13420 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13421 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13422 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13423 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13424 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13425 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13426 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13427 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13428 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13429 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13430 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13431 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13432 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13433 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13434 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13435 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13436 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13437 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13438 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13439 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13440 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13441 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13442
13443 /* "neighbor route-reflector" commands.*/
13444 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13445 install_element(BGP_NODE,
13446 &no_neighbor_route_reflector_client_hidden_cmd);
13447 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13448 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13449 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13450 install_element(BGP_IPV4M_NODE,
13451 &no_neighbor_route_reflector_client_cmd);
13452 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13453 install_element(BGP_IPV4L_NODE,
13454 &no_neighbor_route_reflector_client_cmd);
13455 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13456 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13457 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13458 install_element(BGP_IPV6M_NODE,
13459 &no_neighbor_route_reflector_client_cmd);
13460 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13461 install_element(BGP_IPV6L_NODE,
13462 &no_neighbor_route_reflector_client_cmd);
13463 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13464 install_element(BGP_VPNV4_NODE,
13465 &no_neighbor_route_reflector_client_cmd);
13466 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13467 install_element(BGP_VPNV6_NODE,
13468 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13469 install_element(BGP_FLOWSPECV4_NODE,
13470 &neighbor_route_reflector_client_cmd);
13471 install_element(BGP_FLOWSPECV4_NODE,
13472 &no_neighbor_route_reflector_client_cmd);
13473 install_element(BGP_FLOWSPECV6_NODE,
13474 &neighbor_route_reflector_client_cmd);
13475 install_element(BGP_FLOWSPECV6_NODE,
13476 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13477 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13478 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13479
13480 /* "neighbor route-server" commands.*/
13481 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13482 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13483 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13484 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13485 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13486 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13487 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13488 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13489 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13490 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13491 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13492 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13493 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13494 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13495 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13496 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13497 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13498 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13499 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13500 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13501 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13502 install_element(BGP_FLOWSPECV4_NODE,
13503 &no_neighbor_route_server_client_cmd);
13504 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13505 install_element(BGP_FLOWSPECV6_NODE,
13506 &no_neighbor_route_server_client_cmd);
d62a17ae 13507
13508 /* "neighbor addpath-tx-all-paths" commands.*/
13509 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13510 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13511 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13512 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13513 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13514 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13515 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13516 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13517 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13518 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13519 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13520 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13521 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13522 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13523 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13524 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13525 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13526 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13527
13528 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13529 install_element(BGP_NODE,
13530 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13531 install_element(BGP_NODE,
13532 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13533 install_element(BGP_IPV4_NODE,
13534 &neighbor_addpath_tx_bestpath_per_as_cmd);
13535 install_element(BGP_IPV4_NODE,
13536 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13537 install_element(BGP_IPV4M_NODE,
13538 &neighbor_addpath_tx_bestpath_per_as_cmd);
13539 install_element(BGP_IPV4M_NODE,
13540 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13541 install_element(BGP_IPV4L_NODE,
13542 &neighbor_addpath_tx_bestpath_per_as_cmd);
13543 install_element(BGP_IPV4L_NODE,
13544 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13545 install_element(BGP_IPV6_NODE,
13546 &neighbor_addpath_tx_bestpath_per_as_cmd);
13547 install_element(BGP_IPV6_NODE,
13548 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13549 install_element(BGP_IPV6M_NODE,
13550 &neighbor_addpath_tx_bestpath_per_as_cmd);
13551 install_element(BGP_IPV6M_NODE,
13552 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13553 install_element(BGP_IPV6L_NODE,
13554 &neighbor_addpath_tx_bestpath_per_as_cmd);
13555 install_element(BGP_IPV6L_NODE,
13556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13557 install_element(BGP_VPNV4_NODE,
13558 &neighbor_addpath_tx_bestpath_per_as_cmd);
13559 install_element(BGP_VPNV4_NODE,
13560 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13561 install_element(BGP_VPNV6_NODE,
13562 &neighbor_addpath_tx_bestpath_per_as_cmd);
13563 install_element(BGP_VPNV6_NODE,
13564 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13565
13566 /* "neighbor passive" commands. */
13567 install_element(BGP_NODE, &neighbor_passive_cmd);
13568 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13569
13570
13571 /* "neighbor shutdown" commands. */
13572 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13573 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13574 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13575 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13576
13577 /* "neighbor capability extended-nexthop" commands.*/
13578 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13579 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13580
13581 /* "neighbor capability orf prefix-list" commands.*/
13582 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13583 install_element(BGP_NODE,
13584 &no_neighbor_capability_orf_prefix_hidden_cmd);
13585 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13586 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13587 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13588 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13589 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13590 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13591 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13592 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13593 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13594 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13595 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13596 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13597
13598 /* "neighbor capability dynamic" commands.*/
13599 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13600 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13601
13602 /* "neighbor dont-capability-negotiate" commands. */
13603 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13604 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13605
13606 /* "neighbor ebgp-multihop" commands. */
13607 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13608 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13609 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13610
13611 /* "neighbor disable-connected-check" commands. */
13612 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13613 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13614
47cbc09b
PM
13615 /* "neighbor enforce-first-as" commands. */
13616 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13617 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13618
d62a17ae 13619 /* "neighbor description" commands. */
13620 install_element(BGP_NODE, &neighbor_description_cmd);
13621 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13622 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13623
13624 /* "neighbor update-source" commands. "*/
13625 install_element(BGP_NODE, &neighbor_update_source_cmd);
13626 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13627
13628 /* "neighbor default-originate" commands. */
13629 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13630 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13631 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13632 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13633 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13634 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13635 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13637 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13638 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13639 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13640 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13641 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13642 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13643 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13644 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13645 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13646 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13647 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13648 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13649 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13650
13651 /* "neighbor port" commands. */
13652 install_element(BGP_NODE, &neighbor_port_cmd);
13653 install_element(BGP_NODE, &no_neighbor_port_cmd);
13654
13655 /* "neighbor weight" commands. */
13656 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13657 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13658
13659 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13660 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13661 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13662 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13663 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13664 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13665 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13666 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13667 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13668 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13669 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13670 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13671 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13672 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13673 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13674 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13675
13676 /* "neighbor override-capability" commands. */
13677 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13678 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13679
13680 /* "neighbor strict-capability-match" commands. */
13681 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13682 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13683
13684 /* "neighbor timers" commands. */
13685 install_element(BGP_NODE, &neighbor_timers_cmd);
13686 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13687
13688 /* "neighbor timers connect" commands. */
13689 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13690 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13691
13692 /* "neighbor advertisement-interval" commands. */
13693 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13694 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13695
13696 /* "neighbor interface" commands. */
13697 install_element(BGP_NODE, &neighbor_interface_cmd);
13698 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13699
13700 /* "neighbor distribute" commands. */
13701 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13702 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13703 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13704 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13705 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13706 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13707 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13708 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13709 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13710 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13711 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13712 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13713 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13714 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13715 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13716 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13717 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13718 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13719
13720 /* "neighbor prefix-list" commands. */
13721 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13722 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13723 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13724 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13725 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13726 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13727 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13728 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13729 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13730 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13731 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13732 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13733 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13734 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13735 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13736 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13737 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13738 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13739 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13740 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13741 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13742 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13743
13744 /* "neighbor filter-list" commands. */
13745 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13746 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13747 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13748 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13749 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13750 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13751 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13752 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13753 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13754 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13755 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13756 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13757 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13758 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13759 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13760 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13761 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13762 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13763 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13764 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13765 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13766 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13767
13768 /* "neighbor route-map" commands. */
13769 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13770 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13771 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13772 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13773 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13774 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13775 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13776 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13777 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13778 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13779 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13780 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13781 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13782 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13783 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13784 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13785 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13786 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13787 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13788 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13789 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13790 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13791 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13792 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13793
13794 /* "neighbor unsuppress-map" commands. */
13795 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13796 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13797 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13798 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13799 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13800 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13801 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13802 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13803 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13804 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13805 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13806 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13807 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13808 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13809 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13810 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13811 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13812 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13813
13814 /* "neighbor maximum-prefix" commands. */
13815 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13816 install_element(BGP_NODE,
13817 &neighbor_maximum_prefix_threshold_hidden_cmd);
13818 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13819 install_element(BGP_NODE,
13820 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13821 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13822 install_element(BGP_NODE,
13823 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13824 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13825 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13826 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13827 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13828 install_element(BGP_IPV4_NODE,
13829 &neighbor_maximum_prefix_threshold_warning_cmd);
13830 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13831 install_element(BGP_IPV4_NODE,
13832 &neighbor_maximum_prefix_threshold_restart_cmd);
13833 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13834 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13835 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13836 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13837 install_element(BGP_IPV4M_NODE,
13838 &neighbor_maximum_prefix_threshold_warning_cmd);
13839 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13840 install_element(BGP_IPV4M_NODE,
13841 &neighbor_maximum_prefix_threshold_restart_cmd);
13842 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13843 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13844 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13845 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13846 install_element(BGP_IPV4L_NODE,
13847 &neighbor_maximum_prefix_threshold_warning_cmd);
13848 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13849 install_element(BGP_IPV4L_NODE,
13850 &neighbor_maximum_prefix_threshold_restart_cmd);
13851 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13852 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13853 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13854 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13855 install_element(BGP_IPV6_NODE,
13856 &neighbor_maximum_prefix_threshold_warning_cmd);
13857 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13858 install_element(BGP_IPV6_NODE,
13859 &neighbor_maximum_prefix_threshold_restart_cmd);
13860 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13861 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13862 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13863 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13864 install_element(BGP_IPV6M_NODE,
13865 &neighbor_maximum_prefix_threshold_warning_cmd);
13866 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13867 install_element(BGP_IPV6M_NODE,
13868 &neighbor_maximum_prefix_threshold_restart_cmd);
13869 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13870 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13871 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13872 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13873 install_element(BGP_IPV6L_NODE,
13874 &neighbor_maximum_prefix_threshold_warning_cmd);
13875 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13876 install_element(BGP_IPV6L_NODE,
13877 &neighbor_maximum_prefix_threshold_restart_cmd);
13878 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13879 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13880 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13881 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13882 install_element(BGP_VPNV4_NODE,
13883 &neighbor_maximum_prefix_threshold_warning_cmd);
13884 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13885 install_element(BGP_VPNV4_NODE,
13886 &neighbor_maximum_prefix_threshold_restart_cmd);
13887 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13888 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13889 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13890 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13891 install_element(BGP_VPNV6_NODE,
13892 &neighbor_maximum_prefix_threshold_warning_cmd);
13893 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13894 install_element(BGP_VPNV6_NODE,
13895 &neighbor_maximum_prefix_threshold_restart_cmd);
13896 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13897
13898 /* "neighbor allowas-in" */
13899 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13900 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13901 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13902 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13903 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13904 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13905 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13906 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13907 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13908 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13909 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13910 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13911 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13912 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13913 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13914 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13915 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13916 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13917 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13918 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13919
13920 /* address-family commands. */
13921 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13922 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13923#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13924 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13925 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13926#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13927
d62a17ae 13928 install_element(BGP_NODE, &address_family_evpn_cmd);
13929
13930 /* "exit-address-family" command. */
13931 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13932 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13933 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13934 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13935 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13936 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13937 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13938 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13939 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13940 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13941 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13942
13943 /* "clear ip bgp commands" */
13944 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13945
13946 /* clear ip bgp prefix */
13947 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13948 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13949 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13950
13951 /* "show [ip] bgp summary" commands. */
13952 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13953 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13954 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13955 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13956 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13957 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13958 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13959
13960 /* "show [ip] bgp neighbors" commands. */
13961 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13962
13963 /* "show [ip] bgp peer-group" commands. */
13964 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13965
13966 /* "show [ip] bgp paths" commands. */
13967 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13968
13969 /* "show [ip] bgp community" commands. */
13970 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13971
13972 /* "show ip bgp large-community" commands. */
13973 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13974 /* "show [ip] bgp attribute-info" commands. */
13975 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13976 /* "show [ip] bgp route-leak" command */
13977 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13978
13979 /* "redistribute" commands. */
13980 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13981 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13982 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13983 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13984 install_element(BGP_NODE,
13985 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13986 install_element(BGP_NODE,
13987 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13988 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13989 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13990 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13991 install_element(BGP_NODE,
13992 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13993 install_element(BGP_NODE,
13994 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13995 install_element(BGP_NODE,
13996 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13997 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13998 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13999 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14000 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14001 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14002 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14003 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14004 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14005 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14006 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14007 install_element(BGP_IPV4_NODE,
14008 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14009 install_element(BGP_IPV4_NODE,
14010 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14011 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14012 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14013 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14014 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14015 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14016 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14017
b9c7bc5a
PZ
14018 /* import|export vpn [route-map WORD] */
14019 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14020 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 14021
12a844a5
DS
14022 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14023 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14024
d62a17ae 14025 /* ttl_security commands */
14026 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14027 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14028
14029 /* "show [ip] bgp memory" commands. */
14030 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14031
acf71666
MK
14032 /* "show bgp martian next-hop" */
14033 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14034
48ecf8f5
DS
14035 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14036
d62a17ae 14037 /* "show [ip] bgp views" commands. */
14038 install_element(VIEW_NODE, &show_bgp_views_cmd);
14039
14040 /* "show [ip] bgp vrfs" commands. */
14041 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14042
14043 /* Community-list. */
14044 community_list_vty();
ddb5b488
PZ
14045
14046 /* vpn-policy commands */
b9c7bc5a
PZ
14047 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14048 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14049 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14050 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14051 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14052 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14053 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14054 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14055 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14056 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14057 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14058 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14059
301ad80a
PG
14060 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14061 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14062
b9c7bc5a
PZ
14063 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14064 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14065 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14066 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14067 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14068 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14069 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14070 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14071 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14072 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14073 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14074 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14075}
6b0655a2 14076
718e3744 14077#include "memory.h"
14078#include "bgp_regex.h"
14079#include "bgp_clist.h"
14080#include "bgp_ecommunity.h"
14081
14082/* VTY functions. */
14083
14084/* Direction value to string conversion. */
d62a17ae 14085static const char *community_direct_str(int direct)
14086{
14087 switch (direct) {
14088 case COMMUNITY_DENY:
14089 return "deny";
14090 case COMMUNITY_PERMIT:
14091 return "permit";
14092 default:
14093 return "unknown";
14094 }
718e3744 14095}
14096
14097/* Display error string. */
d62a17ae 14098static void community_list_perror(struct vty *vty, int ret)
14099{
14100 switch (ret) {
14101 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14102 vty_out(vty, "%% Can't find community-list\n");
14103 break;
14104 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14105 vty_out(vty, "%% Malformed community-list value\n");
14106 break;
14107 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14108 vty_out(vty,
14109 "%% Community name conflict, previously defined as standard community\n");
14110 break;
14111 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14112 vty_out(vty,
14113 "%% Community name conflict, previously defined as expanded community\n");
14114 break;
14115 }
718e3744 14116}
14117
5bf15956
DW
14118/* "community-list" keyword help string. */
14119#define COMMUNITY_LIST_STR "Add a community list entry\n"
14120
7336e101
SP
14121/*community-list standard */
14122DEFUN (community_list_standard,
14123 bgp_community_list_standard_cmd,
14124 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14125 BGP_STR
718e3744 14126 COMMUNITY_LIST_STR
14127 "Community list number (standard)\n"
5bf15956 14128 "Add an standard community-list entry\n"
718e3744 14129 "Community list name\n"
14130 "Specify community to reject\n"
14131 "Specify community to accept\n"
14132 COMMUNITY_VAL_STR)
14133{
d62a17ae 14134 char *cl_name_or_number = NULL;
14135 int direct = 0;
14136 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14137
d62a17ae 14138 int idx = 0;
7336e101
SP
14139
14140 if (argv_find(argv, argc, "ip", &idx)) {
14141 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14142 vty_out(vty, "if you are using this please migrate to the below command.\n");
14143 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14144 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14145 }
14146
d62a17ae 14147 argv_find(argv, argc, "(1-99)", &idx);
14148 argv_find(argv, argc, "WORD", &idx);
14149 cl_name_or_number = argv[idx]->arg;
14150 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14151 : COMMUNITY_DENY;
14152 argv_find(argv, argc, "AA:NN", &idx);
14153 char *str = argv_concat(argv, argc, idx);
42f914d4 14154
d62a17ae 14155 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14156 style);
42f914d4 14157
d62a17ae 14158 XFREE(MTYPE_TMP, str);
42f914d4 14159
d62a17ae 14160 if (ret < 0) {
14161 /* Display error string. */
14162 community_list_perror(vty, ret);
14163 return CMD_WARNING_CONFIG_FAILED;
14164 }
42f914d4 14165
d62a17ae 14166 return CMD_SUCCESS;
718e3744 14167}
14168
7336e101
SP
14169#if CONFDATE > 20191005
14170CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14171#endif
14172ALIAS (community_list_standard,
14173 ip_community_list_standard_cmd,
14174 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14175 IP_STR
14176 COMMUNITY_LIST_STR
14177 "Community list number (standard)\n"
5bf15956
DW
14178 "Add an standard community-list entry\n"
14179 "Community list name\n"
718e3744 14180 "Specify community to reject\n"
14181 "Specify community to accept\n"
14182 COMMUNITY_VAL_STR)
7336e101
SP
14183
14184DEFUN (no_community_list_standard_all,
14185 no_bgp_community_list_standard_all_cmd,
14186 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14187 NO_STR
14188 BGP_STR
14189 COMMUNITY_LIST_STR
14190 "Community list number (standard)\n"
14191 "Add an standard community-list entry\n"
14192 "Community list name\n"
14193 "Specify community to reject\n"
14194 "Specify community to accept\n"
14195 COMMUNITY_VAL_STR)
718e3744 14196{
d62a17ae 14197 char *cl_name_or_number = NULL;
174b5cb9 14198 char *str = NULL;
d62a17ae 14199 int direct = 0;
14200 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14201
d62a17ae 14202 int idx = 0;
7336e101
SP
14203
14204 if (argv_find(argv, argc, "ip", &idx)) {
14205 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14206 vty_out(vty, "if you are using this please migrate to the below command.\n");
14207 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14208 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14209 }
14210
174b5cb9
DA
14211 argv_find(argv, argc, "permit", &idx);
14212 argv_find(argv, argc, "deny", &idx);
14213
14214 if (idx) {
14215 direct = argv_find(argv, argc, "permit", &idx)
14216 ? COMMUNITY_PERMIT
14217 : COMMUNITY_DENY;
14218
14219 idx = 0;
14220 argv_find(argv, argc, "AA:NN", &idx);
14221 str = argv_concat(argv, argc, idx);
14222 }
14223
14224 idx = 0;
d62a17ae 14225 argv_find(argv, argc, "(1-99)", &idx);
14226 argv_find(argv, argc, "WORD", &idx);
14227 cl_name_or_number = argv[idx]->arg;
42f914d4 14228
d62a17ae 14229 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14230 direct, style);
42f914d4 14231
d62a17ae 14232 XFREE(MTYPE_TMP, str);
daf9ddbb 14233
d62a17ae 14234 if (ret < 0) {
14235 community_list_perror(vty, ret);
14236 return CMD_WARNING_CONFIG_FAILED;
14237 }
42f914d4 14238
d62a17ae 14239 return CMD_SUCCESS;
718e3744 14240}
7336e101
SP
14241ALIAS (no_community_list_standard_all,
14242 no_ip_community_list_standard_all_cmd,
14243 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14244 NO_STR
718e3744 14245 IP_STR
14246 COMMUNITY_LIST_STR
7336e101
SP
14247 "Community list number (standard)\n"
14248 "Add an standard community-list entry\n"
14249 "Community list name\n"
14250 "Specify community to reject\n"
14251 "Specify community to accept\n"
14252 COMMUNITY_VAL_STR)
14253
174b5cb9
DA
14254ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14255 "no bgp community-list <(1-99)|standard WORD>",
14256 NO_STR BGP_STR COMMUNITY_LIST_STR
14257 "Community list number (standard)\n"
14258 "Add an standard community-list entry\n"
14259 "Community list name\n")
14260
14261ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14262 "no ip community-list <(1-99)|standard WORD>",
14263 NO_STR BGP_STR COMMUNITY_LIST_STR
14264 "Community list number (standard)\n"
14265 "Add an standard community-list entry\n"
14266 "Community list name\n")
14267
7336e101
SP
14268/*community-list expanded */
14269DEFUN (community_list_expanded_all,
14270 bgp_community_list_expanded_all_cmd,
14271 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14272 BGP_STR
14273 COMMUNITY_LIST_STR
718e3744 14274 "Community list number (expanded)\n"
5bf15956 14275 "Add an expanded community-list entry\n"
718e3744 14276 "Community list name\n"
14277 "Specify community to reject\n"
14278 "Specify community to accept\n"
14279 COMMUNITY_VAL_STR)
14280{
d62a17ae 14281 char *cl_name_or_number = NULL;
14282 int direct = 0;
14283 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14284
d62a17ae 14285 int idx = 0;
7336e101
SP
14286 if (argv_find(argv, argc, "ip", &idx)) {
14287 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14288 vty_out(vty, "if you are using this please migrate to the below command.\n");
14289 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14290 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14291 }
d62a17ae 14292 argv_find(argv, argc, "(100-500)", &idx);
14293 argv_find(argv, argc, "WORD", &idx);
14294 cl_name_or_number = argv[idx]->arg;
14295 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14296 : COMMUNITY_DENY;
14297 argv_find(argv, argc, "AA:NN", &idx);
14298 char *str = argv_concat(argv, argc, idx);
42f914d4 14299
d62a17ae 14300 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14301 style);
42f914d4 14302
d62a17ae 14303 XFREE(MTYPE_TMP, str);
42f914d4 14304
d62a17ae 14305 if (ret < 0) {
14306 /* Display error string. */
14307 community_list_perror(vty, ret);
14308 return CMD_WARNING_CONFIG_FAILED;
14309 }
42f914d4 14310
d62a17ae 14311 return CMD_SUCCESS;
718e3744 14312}
14313
7336e101
SP
14314ALIAS (community_list_expanded_all,
14315 ip_community_list_expanded_all_cmd,
14316 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14317 IP_STR
14318 COMMUNITY_LIST_STR
5bf15956
DW
14319 "Community list number (expanded)\n"
14320 "Add an expanded community-list entry\n"
718e3744 14321 "Community list name\n"
14322 "Specify community to reject\n"
14323 "Specify community to accept\n"
5bf15956 14324 COMMUNITY_VAL_STR)
7336e101
SP
14325
14326DEFUN (no_community_list_expanded_all,
14327 no_bgp_community_list_expanded_all_cmd,
14328 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14329 NO_STR
14330 BGP_STR
14331 COMMUNITY_LIST_STR
14332 "Community list number (expanded)\n"
14333 "Add an expanded community-list entry\n"
14334 "Community list name\n"
14335 "Specify community to reject\n"
14336 "Specify community to accept\n"
14337 COMMUNITY_VAL_STR)
718e3744 14338{
d62a17ae 14339 char *cl_name_or_number = NULL;
174b5cb9 14340 char *str = NULL;
d62a17ae 14341 int direct = 0;
14342 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14343
d62a17ae 14344 int idx = 0;
7336e101
SP
14345 if (argv_find(argv, argc, "ip", &idx)) {
14346 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14347 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14348 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14349 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14350 }
14351
3c4b8fe2 14352 idx = 0;
174b5cb9
DA
14353 argv_find(argv, argc, "permit", &idx);
14354 argv_find(argv, argc, "deny", &idx);
14355
14356 if (idx) {
14357 direct = argv_find(argv, argc, "permit", &idx)
14358 ? COMMUNITY_PERMIT
14359 : COMMUNITY_DENY;
14360
14361 idx = 0;
14362 argv_find(argv, argc, "AA:NN", &idx);
14363 str = argv_concat(argv, argc, idx);
7336e101 14364 }
174b5cb9
DA
14365
14366 idx = 0;
d62a17ae 14367 argv_find(argv, argc, "(100-500)", &idx);
14368 argv_find(argv, argc, "WORD", &idx);
14369 cl_name_or_number = argv[idx]->arg;
42f914d4 14370
d62a17ae 14371 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14372 direct, style);
42f914d4 14373
d62a17ae 14374 XFREE(MTYPE_TMP, str);
daf9ddbb 14375
d62a17ae 14376 if (ret < 0) {
14377 community_list_perror(vty, ret);
14378 return CMD_WARNING_CONFIG_FAILED;
14379 }
42f914d4 14380
d62a17ae 14381 return CMD_SUCCESS;
718e3744 14382}
14383
7336e101
SP
14384ALIAS (no_community_list_expanded_all,
14385 no_ip_community_list_expanded_all_cmd,
14386 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14387 NO_STR
14388 IP_STR
14389 COMMUNITY_LIST_STR
14390 "Community list number (expanded)\n"
14391 "Add an expanded community-list entry\n"
14392 "Community list name\n"
14393 "Specify community to reject\n"
14394 "Specify community to accept\n"
14395 COMMUNITY_VAL_STR)
14396
174b5cb9
DA
14397ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14398 "no bgp community-list <(100-500)|expanded WORD>",
14399 NO_STR IP_STR COMMUNITY_LIST_STR
14400 "Community list number (expanded)\n"
14401 "Add an expanded community-list entry\n"
14402 "Community list name\n")
14403
14404ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14405 "no ip community-list <(100-500)|expanded WORD>",
14406 NO_STR IP_STR COMMUNITY_LIST_STR
14407 "Community list number (expanded)\n"
14408 "Add an expanded community-list entry\n"
14409 "Community list name\n")
14410
8d9b8ed9
PM
14411/* Return configuration string of community-list entry. */
14412static const char *community_list_config_str(struct community_entry *entry)
14413{
14414 const char *str;
14415
14416 if (entry->any)
14417 str = "";
14418 else {
14419 if (entry->style == COMMUNITY_LIST_STANDARD)
14420 str = community_str(entry->u.com, false);
14421 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14422 str = lcommunity_str(entry->u.lcom, false);
14423 else
14424 str = entry->config;
14425 }
14426 return str;
14427}
14428
d62a17ae 14429static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14430{
d62a17ae 14431 struct community_entry *entry;
718e3744 14432
d62a17ae 14433 for (entry = list->head; entry; entry = entry->next) {
14434 if (entry == list->head) {
14435 if (all_digit(list->name))
14436 vty_out(vty, "Community %s list %s\n",
14437 entry->style == COMMUNITY_LIST_STANDARD
14438 ? "standard"
14439 : "(expanded) access",
14440 list->name);
14441 else
14442 vty_out(vty, "Named Community %s list %s\n",
14443 entry->style == COMMUNITY_LIST_STANDARD
14444 ? "standard"
14445 : "expanded",
14446 list->name);
14447 }
14448 if (entry->any)
14449 vty_out(vty, " %s\n",
14450 community_direct_str(entry->direct));
14451 else
14452 vty_out(vty, " %s %s\n",
14453 community_direct_str(entry->direct),
8d9b8ed9 14454 community_list_config_str(entry));
d62a17ae 14455 }
718e3744 14456}
14457
7336e101
SP
14458DEFUN (show_community_list,
14459 show_bgp_community_list_cmd,
14460 "show bgp community-list",
718e3744 14461 SHOW_STR
7336e101 14462 BGP_STR
718e3744 14463 "List community-list\n")
14464{
d62a17ae 14465 struct community_list *list;
14466 struct community_list_master *cm;
718e3744 14467
7336e101
SP
14468 int idx = 0;
14469 if (argv_find(argv, argc, "ip", &idx)) {
14470 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14471 vty_out(vty, "if you are using this please migrate to the below command.\n");
14472 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14473 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14474 }
d62a17ae 14475 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14476 if (!cm)
14477 return CMD_SUCCESS;
718e3744 14478
d62a17ae 14479 for (list = cm->num.head; list; list = list->next)
14480 community_list_show(vty, list);
718e3744 14481
d62a17ae 14482 for (list = cm->str.head; list; list = list->next)
14483 community_list_show(vty, list);
718e3744 14484
d62a17ae 14485 return CMD_SUCCESS;
718e3744 14486}
14487
7336e101
SP
14488ALIAS (show_community_list,
14489 show_ip_community_list_cmd,
14490 "show ip community-list",
718e3744 14491 SHOW_STR
14492 IP_STR
7336e101
SP
14493 "List community-list\n")
14494
14495DEFUN (show_community_list_arg,
14496 show_bgp_community_list_arg_cmd,
14497 "show bgp community-list <(1-500)|WORD>",
14498 SHOW_STR
14499 BGP_STR
718e3744 14500 "List community-list\n"
14501 "Community-list number\n"
14502 "Community-list name\n")
14503{
d62a17ae 14504 int idx_comm_list = 3;
14505 struct community_list *list;
718e3744 14506
7336e101
SP
14507 int idx = 0;
14508 if (argv_find(argv, argc, "ip", &idx)) {
14509 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14510 vty_out(vty, "if you are using this please migrate to the below command.\n");
14511 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14512 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14513 }
e237b0d2 14514 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14515 COMMUNITY_LIST_MASTER);
14516 if (!list) {
14517 vty_out(vty, "%% Can't find community-list\n");
14518 return CMD_WARNING;
14519 }
718e3744 14520
d62a17ae 14521 community_list_show(vty, list);
718e3744 14522
d62a17ae 14523 return CMD_SUCCESS;
718e3744 14524}
6b0655a2 14525
7336e101
SP
14526ALIAS (show_community_list_arg,
14527 show_ip_community_list_arg_cmd,
14528 "show ip community-list <(1-500)|WORD>",
14529 SHOW_STR
14530 IP_STR
14531 "List community-list\n"
14532 "Community-list number\n"
14533 "Community-list name\n")
14534
57d187bc
JS
14535/*
14536 * Large Community code.
14537 */
d62a17ae 14538static int lcommunity_list_set_vty(struct vty *vty, int argc,
14539 struct cmd_token **argv, int style,
14540 int reject_all_digit_name)
14541{
14542 int ret;
14543 int direct;
14544 char *str;
14545 int idx = 0;
14546 char *cl_name;
14547
7336e101
SP
14548 if (argv_find(argv, argc, "ip", &idx)) {
14549 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14550 vty_out(vty, "if you are using this please migrate to the below command.\n");
14551 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14552 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14553 }
d62a17ae 14554 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14555 : COMMUNITY_DENY;
14556
14557 /* All digit name check. */
14558 idx = 0;
14559 argv_find(argv, argc, "WORD", &idx);
14560 argv_find(argv, argc, "(1-99)", &idx);
14561 argv_find(argv, argc, "(100-500)", &idx);
14562 cl_name = argv[idx]->arg;
14563 if (reject_all_digit_name && all_digit(cl_name)) {
14564 vty_out(vty, "%% Community name cannot have all digits\n");
14565 return CMD_WARNING_CONFIG_FAILED;
14566 }
14567
14568 idx = 0;
14569 argv_find(argv, argc, "AA:BB:CC", &idx);
14570 argv_find(argv, argc, "LINE", &idx);
14571 /* Concat community string argument. */
14572 if (idx)
14573 str = argv_concat(argv, argc, idx);
14574 else
14575 str = NULL;
14576
14577 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14578
14579 /* Free temporary community list string allocated by
14580 argv_concat(). */
0a22ddfb 14581 XFREE(MTYPE_TMP, str);
d62a17ae 14582
14583 if (ret < 0) {
14584 community_list_perror(vty, ret);
14585 return CMD_WARNING_CONFIG_FAILED;
14586 }
14587 return CMD_SUCCESS;
14588}
14589
14590static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14591 struct cmd_token **argv, int style)
14592{
14593 int ret;
14594 int direct = 0;
14595 char *str = NULL;
14596 int idx = 0;
14597
7336e101
SP
14598 if (argv_find(argv, argc, "ip", &idx)) {
14599 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14600 vty_out(vty, "if you are using this please migrate to the below command.\n");
14601 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14602 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14603 }
d62a17ae 14604 argv_find(argv, argc, "permit", &idx);
14605 argv_find(argv, argc, "deny", &idx);
14606
14607 if (idx) {
14608 /* Check the list direct. */
14609 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14610 direct = COMMUNITY_PERMIT;
14611 else
14612 direct = COMMUNITY_DENY;
14613
14614 idx = 0;
14615 argv_find(argv, argc, "LINE", &idx);
14616 argv_find(argv, argc, "AA:AA:NN", &idx);
14617 /* Concat community string argument. */
14618 str = argv_concat(argv, argc, idx);
14619 }
14620
14621 idx = 0;
14622 argv_find(argv, argc, "(1-99)", &idx);
14623 argv_find(argv, argc, "(100-500)", &idx);
14624 argv_find(argv, argc, "WORD", &idx);
14625
14626 /* Unset community list. */
14627 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14628 style);
14629
14630 /* Free temporary community list string allocated by
14631 argv_concat(). */
0a22ddfb 14632 XFREE(MTYPE_TMP, str);
d62a17ae 14633
14634 if (ret < 0) {
14635 community_list_perror(vty, ret);
14636 return CMD_WARNING_CONFIG_FAILED;
14637 }
14638
14639 return CMD_SUCCESS;
57d187bc
JS
14640}
14641
14642/* "large-community-list" keyword help string. */
14643#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14644#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14645
7336e101
SP
14646#if CONFDATE > 20191005
14647CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14648#endif
14649DEFUN (lcommunity_list_standard,
14650 bgp_lcommunity_list_standard_cmd,
14651 "bgp large-community-list (1-99) <deny|permit>",
14652 BGP_STR
14653 LCOMMUNITY_LIST_STR
14654 "Large Community list number (standard)\n"
14655 "Specify large community to reject\n"
14656 "Specify large community to accept\n")
14657{
14658 return lcommunity_list_set_vty(vty, argc, argv,
14659 LARGE_COMMUNITY_LIST_STANDARD, 0);
14660}
14661
14662ALIAS (lcommunity_list_standard,
57d187bc 14663 ip_lcommunity_list_standard_cmd,
52951b63
DS
14664 "ip large-community-list (1-99) <deny|permit>",
14665 IP_STR
14666 LCOMMUNITY_LIST_STR
14667 "Large Community list number (standard)\n"
14668 "Specify large community to reject\n"
7111c1a0 14669 "Specify large community to accept\n")
7336e101
SP
14670
14671DEFUN (lcommunity_list_standard1,
14672 bgp_lcommunity_list_standard1_cmd,
14673 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14674 BGP_STR
14675 LCOMMUNITY_LIST_STR
14676 "Large Community list number (standard)\n"
14677 "Specify large community to reject\n"
14678 "Specify large community to accept\n"
14679 LCOMMUNITY_VAL_STR)
52951b63 14680{
d62a17ae 14681 return lcommunity_list_set_vty(vty, argc, argv,
14682 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14683}
14684
7336e101 14685ALIAS (lcommunity_list_standard1,
52951b63
DS
14686 ip_lcommunity_list_standard1_cmd,
14687 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14688 IP_STR
14689 LCOMMUNITY_LIST_STR
14690 "Large Community list number (standard)\n"
14691 "Specify large community to reject\n"
14692 "Specify large community to accept\n"
14693 LCOMMUNITY_VAL_STR)
7336e101
SP
14694
14695DEFUN (lcommunity_list_expanded,
14696 bgp_lcommunity_list_expanded_cmd,
14697 "bgp large-community-list (100-500) <deny|permit> LINE...",
14698 BGP_STR
14699 LCOMMUNITY_LIST_STR
14700 "Large Community list number (expanded)\n"
14701 "Specify large community to reject\n"
14702 "Specify large community to accept\n"
14703 "An ordered list as a regular-expression\n")
57d187bc 14704{
d62a17ae 14705 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14706 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14707}
14708
7336e101 14709ALIAS (lcommunity_list_expanded,
57d187bc
JS
14710 ip_lcommunity_list_expanded_cmd,
14711 "ip large-community-list (100-500) <deny|permit> LINE...",
14712 IP_STR
14713 LCOMMUNITY_LIST_STR
14714 "Large Community list number (expanded)\n"
14715 "Specify large community to reject\n"
14716 "Specify large community to accept\n"
14717 "An ordered list as a regular-expression\n")
7336e101
SP
14718
14719DEFUN (lcommunity_list_name_standard,
14720 bgp_lcommunity_list_name_standard_cmd,
14721 "bgp large-community-list standard WORD <deny|permit>",
14722 BGP_STR
14723 LCOMMUNITY_LIST_STR
14724 "Specify standard large-community-list\n"
14725 "Large Community list name\n"
14726 "Specify large community to reject\n"
14727 "Specify large community to accept\n")
57d187bc 14728{
d62a17ae 14729 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14730 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14731}
14732
7336e101 14733ALIAS (lcommunity_list_name_standard,
57d187bc 14734 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14735 "ip large-community-list standard WORD <deny|permit>",
14736 IP_STR
14737 LCOMMUNITY_LIST_STR
14738 "Specify standard large-community-list\n"
14739 "Large Community list name\n"
14740 "Specify large community to reject\n"
14741 "Specify large community to accept\n")
7336e101
SP
14742
14743DEFUN (lcommunity_list_name_standard1,
14744 bgp_lcommunity_list_name_standard1_cmd,
14745 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14746 BGP_STR
14747 LCOMMUNITY_LIST_STR
14748 "Specify standard large-community-list\n"
14749 "Large Community list name\n"
14750 "Specify large community to reject\n"
14751 "Specify large community to accept\n"
14752 LCOMMUNITY_VAL_STR)
52951b63 14753{
d62a17ae 14754 return lcommunity_list_set_vty(vty, argc, argv,
14755 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14756}
14757
7336e101 14758ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14759 ip_lcommunity_list_name_standard1_cmd,
14760 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14761 IP_STR
14762 LCOMMUNITY_LIST_STR
14763 "Specify standard large-community-list\n"
14764 "Large Community list name\n"
14765 "Specify large community to reject\n"
14766 "Specify large community to accept\n"
14767 LCOMMUNITY_VAL_STR)
7336e101
SP
14768
14769DEFUN (lcommunity_list_name_expanded,
14770 bgp_lcommunity_list_name_expanded_cmd,
14771 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14772 BGP_STR
14773 LCOMMUNITY_LIST_STR
14774 "Specify expanded large-community-list\n"
14775 "Large Community list name\n"
14776 "Specify large community to reject\n"
14777 "Specify large community to accept\n"
14778 "An ordered list as a regular-expression\n")
57d187bc 14779{
d62a17ae 14780 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14781 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14782}
14783
7336e101 14784ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14785 ip_lcommunity_list_name_expanded_cmd,
14786 "ip large-community-list expanded WORD <deny|permit> LINE...",
14787 IP_STR
14788 LCOMMUNITY_LIST_STR
14789 "Specify expanded large-community-list\n"
14790 "Large Community list name\n"
14791 "Specify large community to reject\n"
14792 "Specify large community to accept\n"
14793 "An ordered list as a regular-expression\n")
7336e101
SP
14794
14795DEFUN (no_lcommunity_list_standard_all,
14796 no_bgp_lcommunity_list_standard_all_cmd,
14797 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14798 NO_STR
14799 BGP_STR
14800 LCOMMUNITY_LIST_STR
14801 "Large Community list number (standard)\n"
14802 "Large Community list number (expanded)\n"
14803 "Large Community list name\n")
57d187bc 14804{
7336e101
SP
14805 return lcommunity_list_unset_vty(vty, argc, argv,
14806 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14807}
14808
7336e101 14809ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14810 no_ip_lcommunity_list_standard_all_cmd,
14811 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14812 NO_STR
14813 IP_STR
14814 LCOMMUNITY_LIST_STR
14815 "Large Community list number (standard)\n"
14816 "Large Community list number (expanded)\n"
14817 "Large Community list name\n")
7336e101
SP
14818
14819DEFUN (no_lcommunity_list_name_expanded_all,
14820 no_bgp_lcommunity_list_name_expanded_all_cmd,
14821 "no bgp large-community-list expanded WORD",
14822 NO_STR
14823 BGP_STR
14824 LCOMMUNITY_LIST_STR
14825 "Specify expanded large-community-list\n"
14826 "Large Community list name\n")
57d187bc 14827{
d62a17ae 14828 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14829 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14830}
14831
7336e101 14832ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14833 no_ip_lcommunity_list_name_expanded_all_cmd,
14834 "no ip large-community-list expanded WORD",
14835 NO_STR
14836 IP_STR
14837 LCOMMUNITY_LIST_STR
14838 "Specify expanded large-community-list\n"
14839 "Large Community list name\n")
7336e101
SP
14840
14841DEFUN (no_lcommunity_list_standard,
14842 no_bgp_lcommunity_list_standard_cmd,
14843 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14844 NO_STR
14845 BGP_STR
14846 LCOMMUNITY_LIST_STR
14847 "Large Community list number (standard)\n"
14848 "Specify large community to reject\n"
14849 "Specify large community to accept\n"
14850 LCOMMUNITY_VAL_STR)
57d187bc 14851{
d62a17ae 14852 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14853 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14854}
14855
7336e101 14856ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14857 no_ip_lcommunity_list_standard_cmd,
14858 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14859 NO_STR
14860 IP_STR
14861 LCOMMUNITY_LIST_STR
14862 "Large Community list number (standard)\n"
14863 "Specify large community to reject\n"
14864 "Specify large community to accept\n"
14865 LCOMMUNITY_VAL_STR)
7336e101
SP
14866
14867DEFUN (no_lcommunity_list_expanded,
14868 no_bgp_lcommunity_list_expanded_cmd,
14869 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14870 NO_STR
14871 BGP_STR
14872 LCOMMUNITY_LIST_STR
14873 "Large Community list number (expanded)\n"
14874 "Specify large community to reject\n"
14875 "Specify large community to accept\n"
14876 "An ordered list as a regular-expression\n")
57d187bc 14877{
d62a17ae 14878 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14879 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14880}
14881
7336e101 14882ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14883 no_ip_lcommunity_list_expanded_cmd,
14884 "no ip large-community-list (100-500) <deny|permit> LINE...",
14885 NO_STR
14886 IP_STR
14887 LCOMMUNITY_LIST_STR
14888 "Large Community list number (expanded)\n"
14889 "Specify large community to reject\n"
14890 "Specify large community to accept\n"
14891 "An ordered list as a regular-expression\n")
7336e101
SP
14892
14893DEFUN (no_lcommunity_list_name_standard,
14894 no_bgp_lcommunity_list_name_standard_cmd,
14895 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14896 NO_STR
14897 BGP_STR
14898 LCOMMUNITY_LIST_STR
14899 "Specify standard large-community-list\n"
14900 "Large Community list name\n"
14901 "Specify large community to reject\n"
14902 "Specify large community to accept\n"
14903 LCOMMUNITY_VAL_STR)
57d187bc 14904{
d62a17ae 14905 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14906 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14907}
14908
7336e101 14909ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14910 no_ip_lcommunity_list_name_standard_cmd,
14911 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14912 NO_STR
14913 IP_STR
14914 LCOMMUNITY_LIST_STR
14915 "Specify standard large-community-list\n"
14916 "Large Community list name\n"
14917 "Specify large community to reject\n"
14918 "Specify large community to accept\n"
14919 LCOMMUNITY_VAL_STR)
7336e101
SP
14920
14921DEFUN (no_lcommunity_list_name_expanded,
14922 no_bgp_lcommunity_list_name_expanded_cmd,
14923 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14924 NO_STR
14925 BGP_STR
14926 LCOMMUNITY_LIST_STR
14927 "Specify expanded large-community-list\n"
14928 "Large community list name\n"
14929 "Specify large community to reject\n"
14930 "Specify large community to accept\n"
14931 "An ordered list as a regular-expression\n")
57d187bc 14932{
d62a17ae 14933 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14934 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14935}
14936
7336e101 14937ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14938 no_ip_lcommunity_list_name_expanded_cmd,
14939 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14940 NO_STR
14941 IP_STR
14942 LCOMMUNITY_LIST_STR
14943 "Specify expanded large-community-list\n"
14944 "Large community list name\n"
14945 "Specify large community to reject\n"
14946 "Specify large community to accept\n"
14947 "An ordered list as a regular-expression\n")
d62a17ae 14948
14949static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14950{
14951 struct community_entry *entry;
14952
14953 for (entry = list->head; entry; entry = entry->next) {
14954 if (entry == list->head) {
14955 if (all_digit(list->name))
14956 vty_out(vty, "Large community %s list %s\n",
14957 entry->style == EXTCOMMUNITY_LIST_STANDARD
14958 ? "standard"
14959 : "(expanded) access",
14960 list->name);
14961 else
14962 vty_out(vty,
14963 "Named large community %s list %s\n",
14964 entry->style == EXTCOMMUNITY_LIST_STANDARD
14965 ? "standard"
14966 : "expanded",
14967 list->name);
14968 }
14969 if (entry->any)
14970 vty_out(vty, " %s\n",
14971 community_direct_str(entry->direct));
14972 else
14973 vty_out(vty, " %s %s\n",
14974 community_direct_str(entry->direct),
8d9b8ed9 14975 community_list_config_str(entry));
d62a17ae 14976 }
57d187bc
JS
14977}
14978
7336e101
SP
14979DEFUN (show_lcommunity_list,
14980 show_bgp_lcommunity_list_cmd,
14981 "show bgp large-community-list",
57d187bc 14982 SHOW_STR
7336e101 14983 BGP_STR
57d187bc
JS
14984 "List large-community list\n")
14985{
d62a17ae 14986 struct community_list *list;
14987 struct community_list_master *cm;
7336e101
SP
14988 int idx = 0;
14989
14990 if (argv_find(argv, argc, "ip", &idx)) {
14991 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14992 vty_out(vty, "if you are using this please migrate to the below command.\n");
14993 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14994 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14995 }
57d187bc 14996
d62a17ae 14997 cm = community_list_master_lookup(bgp_clist,
14998 LARGE_COMMUNITY_LIST_MASTER);
14999 if (!cm)
15000 return CMD_SUCCESS;
57d187bc 15001
d62a17ae 15002 for (list = cm->num.head; list; list = list->next)
15003 lcommunity_list_show(vty, list);
57d187bc 15004
d62a17ae 15005 for (list = cm->str.head; list; list = list->next)
15006 lcommunity_list_show(vty, list);
57d187bc 15007
d62a17ae 15008 return CMD_SUCCESS;
57d187bc
JS
15009}
15010
7336e101
SP
15011ALIAS (show_lcommunity_list,
15012 show_ip_lcommunity_list_cmd,
15013 "show ip large-community-list",
57d187bc
JS
15014 SHOW_STR
15015 IP_STR
7336e101
SP
15016 "List large-community list\n")
15017
15018DEFUN (show_lcommunity_list_arg,
15019 show_bgp_lcommunity_list_arg_cmd,
15020 "show bgp large-community-list <(1-500)|WORD>",
15021 SHOW_STR
15022 BGP_STR
57d187bc
JS
15023 "List large-community list\n"
15024 "large-community-list number\n"
15025 "large-community-list name\n")
15026{
d62a17ae 15027 struct community_list *list;
7336e101
SP
15028 int idx = 0;
15029
15030 if (argv_find(argv, argc, "ip", &idx)) {
15031 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15032 vty_out(vty, "if you are using this please migrate to the below command.\n");
15033 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15034 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15035 }
57d187bc 15036
e237b0d2 15037 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 15038 LARGE_COMMUNITY_LIST_MASTER);
15039 if (!list) {
15040 vty_out(vty, "%% Can't find extcommunity-list\n");
15041 return CMD_WARNING;
15042 }
57d187bc 15043
d62a17ae 15044 lcommunity_list_show(vty, list);
57d187bc 15045
d62a17ae 15046 return CMD_SUCCESS;
57d187bc
JS
15047}
15048
7336e101
SP
15049ALIAS (show_lcommunity_list_arg,
15050 show_ip_lcommunity_list_arg_cmd,
15051 "show ip large-community-list <(1-500)|WORD>",
15052 SHOW_STR
15053 IP_STR
15054 "List large-community list\n"
15055 "large-community-list number\n"
15056 "large-community-list name\n")
15057
718e3744 15058/* "extcommunity-list" keyword help string. */
15059#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15060#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15061
7336e101
SP
15062DEFUN (extcommunity_list_standard,
15063 bgp_extcommunity_list_standard_cmd,
15064 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15065 BGP_STR
718e3744 15066 EXTCOMMUNITY_LIST_STR
15067 "Extended Community list number (standard)\n"
718e3744 15068 "Specify standard extcommunity-list\n"
5bf15956 15069 "Community list name\n"
718e3744 15070 "Specify community to reject\n"
15071 "Specify community to accept\n"
15072 EXTCOMMUNITY_VAL_STR)
15073{
d62a17ae 15074 int style = EXTCOMMUNITY_LIST_STANDARD;
15075 int direct = 0;
15076 char *cl_number_or_name = NULL;
42f914d4 15077
d62a17ae 15078 int idx = 0;
7336e101
SP
15079 if (argv_find(argv, argc, "ip", &idx)) {
15080 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15081 vty_out(vty, "if you are using this please migrate to the below command.\n");
15082 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15083 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15084 }
d62a17ae 15085 argv_find(argv, argc, "(1-99)", &idx);
15086 argv_find(argv, argc, "WORD", &idx);
15087 cl_number_or_name = argv[idx]->arg;
15088 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15089 : COMMUNITY_DENY;
15090 argv_find(argv, argc, "AA:NN", &idx);
15091 char *str = argv_concat(argv, argc, idx);
42f914d4 15092
d62a17ae 15093 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15094 direct, style);
42f914d4 15095
d62a17ae 15096 XFREE(MTYPE_TMP, str);
42f914d4 15097
d62a17ae 15098 if (ret < 0) {
15099 community_list_perror(vty, ret);
15100 return CMD_WARNING_CONFIG_FAILED;
15101 }
42f914d4 15102
d62a17ae 15103 return CMD_SUCCESS;
718e3744 15104}
15105
7336e101
SP
15106#if CONFDATE > 20191005
15107CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15108#endif
15109ALIAS (extcommunity_list_standard,
15110 ip_extcommunity_list_standard_cmd,
15111 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15112 IP_STR
15113 EXTCOMMUNITY_LIST_STR
7336e101
SP
15114 "Extended Community list number (standard)\n"
15115 "Specify standard extcommunity-list\n"
15116 "Community list name\n"
15117 "Specify community to reject\n"
15118 "Specify community to accept\n"
15119 EXTCOMMUNITY_VAL_STR)
15120
15121DEFUN (extcommunity_list_name_expanded,
15122 bgp_extcommunity_list_name_expanded_cmd,
15123 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15124 BGP_STR
15125 EXTCOMMUNITY_LIST_STR
5bf15956 15126 "Extended Community list number (expanded)\n"
718e3744 15127 "Specify expanded extcommunity-list\n"
15128 "Extended Community list name\n"
15129 "Specify community to reject\n"
15130 "Specify community to accept\n"
15131 "An ordered list as a regular-expression\n")
15132{
d62a17ae 15133 int style = EXTCOMMUNITY_LIST_EXPANDED;
15134 int direct = 0;
15135 char *cl_number_or_name = NULL;
42f914d4 15136
d62a17ae 15137 int idx = 0;
7336e101
SP
15138 if (argv_find(argv, argc, "ip", &idx)) {
15139 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15140 vty_out(vty, "if you are using this please migrate to the below command.\n");
15141 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15142 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15143 }
15144
d62a17ae 15145 argv_find(argv, argc, "(100-500)", &idx);
15146 argv_find(argv, argc, "WORD", &idx);
15147 cl_number_or_name = argv[idx]->arg;
15148 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15149 : COMMUNITY_DENY;
15150 argv_find(argv, argc, "LINE", &idx);
15151 char *str = argv_concat(argv, argc, idx);
42f914d4 15152
d62a17ae 15153 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15154 direct, style);
42f914d4 15155
d62a17ae 15156 XFREE(MTYPE_TMP, str);
42f914d4 15157
d62a17ae 15158 if (ret < 0) {
15159 community_list_perror(vty, ret);
15160 return CMD_WARNING_CONFIG_FAILED;
15161 }
42f914d4 15162
d62a17ae 15163 return CMD_SUCCESS;
718e3744 15164}
15165
7336e101
SP
15166ALIAS (extcommunity_list_name_expanded,
15167 ip_extcommunity_list_name_expanded_cmd,
15168 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
15169 IP_STR
15170 EXTCOMMUNITY_LIST_STR
7336e101
SP
15171 "Extended Community list number (expanded)\n"
15172 "Specify expanded extcommunity-list\n"
15173 "Extended Community list name\n"
15174 "Specify community to reject\n"
15175 "Specify community to accept\n"
15176 "An ordered list as a regular-expression\n")
15177
15178DEFUN (no_extcommunity_list_standard_all,
15179 no_bgp_extcommunity_list_standard_all_cmd,
15180 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15181 NO_STR
15182 BGP_STR
15183 EXTCOMMUNITY_LIST_STR
813d4307 15184 "Extended Community list number (standard)\n"
718e3744 15185 "Specify standard extcommunity-list\n"
5bf15956 15186 "Community list name\n"
718e3744 15187 "Specify community to reject\n"
15188 "Specify community to accept\n"
15189 EXTCOMMUNITY_VAL_STR)
15190{
d62a17ae 15191 int style = EXTCOMMUNITY_LIST_STANDARD;
15192 int direct = 0;
15193 char *cl_number_or_name = NULL;
d4455c89 15194 char *str = NULL;
42f914d4 15195
d62a17ae 15196 int idx = 0;
7336e101
SP
15197 if (argv_find(argv, argc, "ip", &idx)) {
15198 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15199 vty_out(vty, "if you are using this please migrate to the below command.\n");
15200 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15201 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15202 }
d4455c89
DA
15203
15204 idx = 0;
15205 argv_find(argv, argc, "permit", &idx);
15206 argv_find(argv, argc, "deny", &idx);
15207
15208 if (idx) {
15209 direct = argv_find(argv, argc, "permit", &idx)
15210 ? COMMUNITY_PERMIT
15211 : COMMUNITY_DENY;
15212
15213 idx = 0;
15214 argv_find(argv, argc, "AA:NN", &idx);
15215 str = argv_concat(argv, argc, idx);
15216 }
15217
15218 idx = 0;
d62a17ae 15219 argv_find(argv, argc, "(1-99)", &idx);
15220 argv_find(argv, argc, "WORD", &idx);
15221 cl_number_or_name = argv[idx]->arg;
42f914d4 15222
d62a17ae 15223 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15224 direct, style);
42f914d4 15225
d62a17ae 15226 XFREE(MTYPE_TMP, str);
42f914d4 15227
d62a17ae 15228 if (ret < 0) {
15229 community_list_perror(vty, ret);
15230 return CMD_WARNING_CONFIG_FAILED;
15231 }
42f914d4 15232
d62a17ae 15233 return CMD_SUCCESS;
718e3744 15234}
15235
7336e101
SP
15236ALIAS (no_extcommunity_list_standard_all,
15237 no_ip_extcommunity_list_standard_all_cmd,
15238 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15239 NO_STR
15240 IP_STR
15241 EXTCOMMUNITY_LIST_STR
7336e101
SP
15242 "Extended Community list number (standard)\n"
15243 "Specify standard extcommunity-list\n"
15244 "Community list name\n"
15245 "Specify community to reject\n"
15246 "Specify community to accept\n"
15247 EXTCOMMUNITY_VAL_STR)
15248
d4455c89
DA
15249ALIAS(no_extcommunity_list_standard_all,
15250 no_bgp_extcommunity_list_standard_all_list_cmd,
15251 "no bgp extcommunity-list <(1-99)|standard WORD>",
15252 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15253 "Extended Community list number (standard)\n"
15254 "Specify standard extcommunity-list\n"
15255 "Community list name\n")
15256
15257ALIAS(no_extcommunity_list_standard_all,
15258 no_ip_extcommunity_list_standard_all_list_cmd,
15259 "no ip extcommunity-list <(1-99)|standard WORD>",
15260 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15261 "Extended Community list number (standard)\n"
15262 "Specify standard extcommunity-list\n"
15263 "Community list name\n")
15264
7336e101
SP
15265DEFUN (no_extcommunity_list_expanded_all,
15266 no_bgp_extcommunity_list_expanded_all_cmd,
15267 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15268 NO_STR
15269 BGP_STR
15270 EXTCOMMUNITY_LIST_STR
718e3744 15271 "Extended Community list number (expanded)\n"
718e3744 15272 "Specify expanded extcommunity-list\n"
5bf15956 15273 "Extended Community list name\n"
718e3744 15274 "Specify community to reject\n"
15275 "Specify community to accept\n"
15276 "An ordered list as a regular-expression\n")
15277{
d62a17ae 15278 int style = EXTCOMMUNITY_LIST_EXPANDED;
15279 int direct = 0;
15280 char *cl_number_or_name = NULL;
d4455c89 15281 char *str = NULL;
42f914d4 15282
d62a17ae 15283 int idx = 0;
7336e101
SP
15284 if (argv_find(argv, argc, "ip", &idx)) {
15285 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15286 vty_out(vty, "if you are using this please migrate to the below command.\n");
15287 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15288 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15289 }
d4455c89
DA
15290
15291 idx = 0;
15292 argv_find(argv, argc, "permit", &idx);
15293 argv_find(argv, argc, "deny", &idx);
15294
15295 if (idx) {
15296 direct = argv_find(argv, argc, "permit", &idx)
15297 ? COMMUNITY_PERMIT
15298 : COMMUNITY_DENY;
15299
15300 idx = 0;
15301 argv_find(argv, argc, "LINE", &idx);
15302 str = argv_concat(argv, argc, idx);
15303 }
15304
15305 idx = 0;
d62a17ae 15306 argv_find(argv, argc, "(100-500)", &idx);
15307 argv_find(argv, argc, "WORD", &idx);
15308 cl_number_or_name = argv[idx]->arg;
42f914d4 15309
d62a17ae 15310 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15311 direct, style);
42f914d4 15312
d62a17ae 15313 XFREE(MTYPE_TMP, str);
42f914d4 15314
d62a17ae 15315 if (ret < 0) {
15316 community_list_perror(vty, ret);
15317 return CMD_WARNING_CONFIG_FAILED;
15318 }
42f914d4 15319
d62a17ae 15320 return CMD_SUCCESS;
718e3744 15321}
15322
7336e101
SP
15323ALIAS (no_extcommunity_list_expanded_all,
15324 no_ip_extcommunity_list_expanded_all_cmd,
15325 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15326 NO_STR
15327 IP_STR
15328 EXTCOMMUNITY_LIST_STR
15329 "Extended Community list number (expanded)\n"
15330 "Specify expanded extcommunity-list\n"
15331 "Extended Community list name\n"
15332 "Specify community to reject\n"
15333 "Specify community to accept\n"
15334 "An ordered list as a regular-expression\n")
15335
d4455c89
DA
15336ALIAS(no_extcommunity_list_expanded_all,
15337 no_ip_extcommunity_list_expanded_all_list_cmd,
15338 "no ip extcommunity-list <(100-500)|expanded WORD>",
15339 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15340 "Extended Community list number (expanded)\n"
15341 "Specify expanded extcommunity-list\n"
15342 "Extended Community list name\n")
15343
15344ALIAS(no_extcommunity_list_expanded_all,
15345 no_bgp_extcommunity_list_expanded_all_list_cmd,
15346 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15347 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15348 "Extended Community list number (expanded)\n"
15349 "Specify expanded extcommunity-list\n"
15350 "Extended Community list name\n")
15351
d62a17ae 15352static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15353{
d62a17ae 15354 struct community_entry *entry;
718e3744 15355
d62a17ae 15356 for (entry = list->head; entry; entry = entry->next) {
15357 if (entry == list->head) {
15358 if (all_digit(list->name))
15359 vty_out(vty, "Extended community %s list %s\n",
15360 entry->style == EXTCOMMUNITY_LIST_STANDARD
15361 ? "standard"
15362 : "(expanded) access",
15363 list->name);
15364 else
15365 vty_out(vty,
15366 "Named extended community %s list %s\n",
15367 entry->style == EXTCOMMUNITY_LIST_STANDARD
15368 ? "standard"
15369 : "expanded",
15370 list->name);
15371 }
15372 if (entry->any)
15373 vty_out(vty, " %s\n",
15374 community_direct_str(entry->direct));
15375 else
15376 vty_out(vty, " %s %s\n",
15377 community_direct_str(entry->direct),
8d9b8ed9 15378 community_list_config_str(entry));
d62a17ae 15379 }
718e3744 15380}
15381
7336e101
SP
15382DEFUN (show_extcommunity_list,
15383 show_bgp_extcommunity_list_cmd,
15384 "show bgp extcommunity-list",
718e3744 15385 SHOW_STR
7336e101 15386 BGP_STR
718e3744 15387 "List extended-community list\n")
15388{
d62a17ae 15389 struct community_list *list;
15390 struct community_list_master *cm;
7336e101 15391 int idx = 0;
718e3744 15392
7336e101
SP
15393 if (argv_find(argv, argc, "ip", &idx)) {
15394 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15395 vty_out(vty, "if you are using this please migrate to the below command.\n");
15396 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15397 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15398 }
d62a17ae 15399 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15400 if (!cm)
15401 return CMD_SUCCESS;
718e3744 15402
d62a17ae 15403 for (list = cm->num.head; list; list = list->next)
15404 extcommunity_list_show(vty, list);
718e3744 15405
d62a17ae 15406 for (list = cm->str.head; list; list = list->next)
15407 extcommunity_list_show(vty, list);
718e3744 15408
d62a17ae 15409 return CMD_SUCCESS;
718e3744 15410}
15411
7336e101
SP
15412ALIAS (show_extcommunity_list,
15413 show_ip_extcommunity_list_cmd,
15414 "show ip extcommunity-list",
718e3744 15415 SHOW_STR
15416 IP_STR
7336e101
SP
15417 "List extended-community list\n")
15418
15419DEFUN (show_extcommunity_list_arg,
15420 show_bgp_extcommunity_list_arg_cmd,
15421 "show bgp extcommunity-list <(1-500)|WORD>",
15422 SHOW_STR
15423 BGP_STR
718e3744 15424 "List extended-community list\n"
15425 "Extcommunity-list number\n"
15426 "Extcommunity-list name\n")
15427{
d62a17ae 15428 int idx_comm_list = 3;
15429 struct community_list *list;
7336e101 15430 int idx = 0;
718e3744 15431
7336e101
SP
15432 if (argv_find(argv, argc, "ip", &idx)) {
15433 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15434 vty_out(vty, "if you are using this please migrate to the below command.\n");
15435 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15436 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15437 }
e237b0d2 15438 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15439 EXTCOMMUNITY_LIST_MASTER);
15440 if (!list) {
15441 vty_out(vty, "%% Can't find extcommunity-list\n");
15442 return CMD_WARNING;
15443 }
718e3744 15444
d62a17ae 15445 extcommunity_list_show(vty, list);
718e3744 15446
d62a17ae 15447 return CMD_SUCCESS;
718e3744 15448}
6b0655a2 15449
7336e101
SP
15450ALIAS (show_extcommunity_list_arg,
15451 show_ip_extcommunity_list_arg_cmd,
15452 "show ip extcommunity-list <(1-500)|WORD>",
15453 SHOW_STR
15454 IP_STR
15455 "List extended-community list\n"
15456 "Extcommunity-list number\n"
15457 "Extcommunity-list name\n")
15458
718e3744 15459/* Display community-list and extcommunity-list configuration. */
d62a17ae 15460static int community_list_config_write(struct vty *vty)
15461{
15462 struct community_list *list;
15463 struct community_entry *entry;
15464 struct community_list_master *cm;
15465 int write = 0;
15466
15467 /* Community-list. */
15468 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15469
15470 for (list = cm->num.head; list; list = list->next)
15471 for (entry = list->head; entry; entry = entry->next) {
7336e101 15472 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15473 community_direct_str(entry->direct),
15474 community_list_config_str(entry));
15475 write++;
15476 }
15477 for (list = cm->str.head; list; list = list->next)
15478 for (entry = list->head; entry; entry = entry->next) {
7336e101 15479 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15480 entry->style == COMMUNITY_LIST_STANDARD
15481 ? "standard"
15482 : "expanded",
15483 list->name, community_direct_str(entry->direct),
15484 community_list_config_str(entry));
15485 write++;
15486 }
15487
15488 /* Extcommunity-list. */
15489 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15490
15491 for (list = cm->num.head; list; list = list->next)
15492 for (entry = list->head; entry; entry = entry->next) {
7336e101 15493 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15494 list->name, community_direct_str(entry->direct),
15495 community_list_config_str(entry));
15496 write++;
15497 }
15498 for (list = cm->str.head; list; list = list->next)
15499 for (entry = list->head; entry; entry = entry->next) {
7336e101 15500 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15501 entry->style == EXTCOMMUNITY_LIST_STANDARD
15502 ? "standard"
15503 : "expanded",
15504 list->name, community_direct_str(entry->direct),
15505 community_list_config_str(entry));
15506 write++;
15507 }
15508
15509
15510 /* lcommunity-list. */
15511 cm = community_list_master_lookup(bgp_clist,
15512 LARGE_COMMUNITY_LIST_MASTER);
15513
15514 for (list = cm->num.head; list; list = list->next)
15515 for (entry = list->head; entry; entry = entry->next) {
7336e101 15516 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15517 list->name, community_direct_str(entry->direct),
15518 community_list_config_str(entry));
15519 write++;
15520 }
15521 for (list = cm->str.head; list; list = list->next)
15522 for (entry = list->head; entry; entry = entry->next) {
7336e101 15523 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15524 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15525 ? "standard"
15526 : "expanded",
15527 list->name, community_direct_str(entry->direct),
15528 community_list_config_str(entry));
15529 write++;
15530 }
15531
15532 return write;
15533}
15534
15535static struct cmd_node community_list_node = {
15536 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15537};
15538
d62a17ae 15539static void community_list_vty(void)
15540{
15541 install_node(&community_list_node, community_list_config_write);
15542
15543 /* Community-list. */
7336e101
SP
15544 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15545 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15546 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15547 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15548 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15549 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15550 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15551 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15552 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15553 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15554 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15555 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15556 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15557 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15558 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15559 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15560
15561 /* Extcommunity-list. */
7336e101
SP
15562 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15563 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15564 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15565 install_element(CONFIG_NODE,
15566 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15567 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15568 install_element(CONFIG_NODE,
15569 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15570 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15571 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15572 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15573 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15574 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15575 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15576 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15577 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15578 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15579 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15580
15581 /* Large Community List */
7336e101
SP
15582 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15583 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15584 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15585 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15586 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15587 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15588 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15589 install_element(CONFIG_NODE,
15590 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15592 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15593 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15594 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15595 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15596 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15597 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15598 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15599 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15600 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15601 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15602 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15603 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15604 install_element(CONFIG_NODE,
15605 &no_ip_lcommunity_list_name_expanded_all_cmd);
15606 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15607 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15608 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15609 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15610 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15611 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15612}