]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Fix per afi/safi addpath peer counting
[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.
87338296 298 * use_json -> json is configured or not
7eeee51e
DS
299 *
300 * The function returns the correct location in the parse tree for the
301 * last token found.
0e37c258
DS
302 *
303 * Returns 0 for failure to parse correctly, else the idx position of where
304 * it found the last token.
7eeee51e 305 */
d62a17ae 306int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
307 struct cmd_token **argv, int argc,
308 int *idx, afi_t *afi, safi_t *safi,
9f049418 309 struct bgp **bgp, bool use_json)
d62a17ae 310{
311 char *vrf_name = NULL;
312
313 assert(afi);
314 assert(safi);
315 assert(bgp);
316
317 if (argv_find(argv, argc, "ip", idx))
318 *afi = AFI_IP;
319
9a8bdf1c 320 if (argv_find(argv, argc, "view", idx))
d62a17ae 321 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
322 else if (argv_find(argv, argc, "vrf", idx)) {
323 vrf_name = argv[*idx + 1]->arg;
324 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
325 vrf_name = NULL;
326 }
327 if (vrf_name) {
d62a17ae 328 if (strmatch(vrf_name, "all"))
329 *bgp = NULL;
330 else {
331 *bgp = bgp_lookup_by_name(vrf_name);
332 if (!*bgp) {
87338296
SP
333 if (use_json) {
334 json_object *json = NULL;
335 json = json_object_new_object();
336 json_object_string_add(
337 json, "warning",
338 "View/Vrf is unknown");
339 vty_out(vty, "%s\n",
340 json_object_to_json_string_ext(json,
341 JSON_C_TO_STRING_PRETTY));
342 json_object_free(json);
343 }
ca61fd25
DS
344 else
345 vty_out(vty, "View/Vrf %s is unknown\n",
346 vrf_name);
d62a17ae 347 *idx = 0;
348 return 0;
349 }
350 }
351 } else {
352 *bgp = bgp_get_default();
353 if (!*bgp) {
87338296
SP
354 if (use_json) {
355 json_object *json = NULL;
356 json = json_object_new_object();
357 json_object_string_add(
358 json, "warning",
359 "Default BGP instance not found");
360 vty_out(vty, "%s\n",
361 json_object_to_json_string_ext(json,
362 JSON_C_TO_STRING_PRETTY));
363 json_object_free(json);
364 }
ca61fd25
DS
365 else
366 vty_out(vty,
367 "Default BGP instance not found\n");
d62a17ae 368 *idx = 0;
369 return 0;
370 }
371 }
372
373 if (argv_find_and_parse_afi(argv, argc, idx, afi))
374 argv_find_and_parse_safi(argv, argc, idx, safi);
375
376 *idx += 1;
377 return *idx;
378}
379
380static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
381{
382 struct interface *ifp = NULL;
383
384 if (su->sa.sa_family == AF_INET)
385 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
386 else if (su->sa.sa_family == AF_INET6)
387 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
388 su->sin6.sin6_scope_id,
389 bgp->vrf_id);
390
391 if (ifp)
392 return 1;
393
394 return 0;
718e3744 395}
396
397/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
398/* This is used only for configuration, so disallow if attempted on
399 * a dynamic neighbor.
400 */
d62a17ae 401static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
402{
403 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
404 int ret;
405 union sockunion su;
406 struct peer *peer;
407
408 if (!bgp) {
409 return NULL;
410 }
411
412 ret = str2sockunion(ip_str, &su);
413 if (ret < 0) {
414 peer = peer_lookup_by_conf_if(bgp, ip_str);
415 if (!peer) {
416 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
417 == NULL) {
418 vty_out(vty,
419 "%% Malformed address or name: %s\n",
420 ip_str);
421 return NULL;
422 }
423 }
424 } else {
425 peer = peer_lookup(bgp, &su);
426 if (!peer) {
427 vty_out(vty,
428 "%% Specify remote-as or peer-group commands first\n");
429 return NULL;
430 }
431 if (peer_dynamic_neighbor(peer)) {
432 vty_out(vty,
433 "%% Operation not allowed on a dynamic neighbor\n");
434 return NULL;
435 }
436 }
437 return peer;
718e3744 438}
439
440/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
441/* This is used only for configuration, so disallow if attempted on
442 * a dynamic neighbor.
443 */
d62a17ae 444struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
445{
446 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
447 int ret;
448 union sockunion su;
449 struct peer *peer = NULL;
450 struct peer_group *group = NULL;
451
452 if (!bgp) {
453 return NULL;
454 }
455
456 ret = str2sockunion(peer_str, &su);
457 if (ret == 0) {
458 /* IP address, locate peer. */
459 peer = peer_lookup(bgp, &su);
460 } else {
461 /* Not IP, could match either peer configured on interface or a
462 * group. */
463 peer = peer_lookup_by_conf_if(bgp, peer_str);
464 if (!peer)
465 group = peer_group_lookup(bgp, peer_str);
466 }
467
468 if (peer) {
469 if (peer_dynamic_neighbor(peer)) {
470 vty_out(vty,
471 "%% Operation not allowed on a dynamic neighbor\n");
472 return NULL;
473 }
474
475 return peer;
476 }
477
478 if (group)
479 return group->conf;
480
481 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
482
483 return NULL;
484}
485
486int bgp_vty_return(struct vty *vty, int ret)
487{
488 const char *str = NULL;
489
490 switch (ret) {
491 case BGP_ERR_INVALID_VALUE:
492 str = "Invalid value";
493 break;
494 case BGP_ERR_INVALID_FLAG:
495 str = "Invalid flag";
496 break;
497 case BGP_ERR_PEER_GROUP_SHUTDOWN:
498 str = "Peer-group has been shutdown. Activate the peer-group first";
499 break;
500 case BGP_ERR_PEER_FLAG_CONFLICT:
501 str = "Can't set override-capability and strict-capability-match at the same time";
502 break;
503 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
504 str = "Specify remote-as or peer-group remote AS first";
505 break;
506 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
507 str = "Cannot change the peer-group. Deconfigure first";
508 break;
509 case BGP_ERR_PEER_GROUP_MISMATCH:
510 str = "Peer is not a member of this peer-group";
511 break;
512 case BGP_ERR_PEER_FILTER_CONFLICT:
513 str = "Prefix/distribute list can not co-exist";
514 break;
515 case BGP_ERR_NOT_INTERNAL_PEER:
516 str = "Invalid command. Not an internal neighbor";
517 break;
518 case BGP_ERR_REMOVE_PRIVATE_AS:
519 str = "remove-private-AS cannot be configured for IBGP peers";
520 break;
521 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
522 str = "Local-AS allowed only for EBGP peers";
523 break;
524 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
525 str = "Cannot have local-as same as BGP AS number";
526 break;
527 case BGP_ERR_TCPSIG_FAILED:
528 str = "Error while applying TCP-Sig to session(s)";
529 break;
530 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
531 str = "ebgp-multihop and ttl-security cannot be configured together";
532 break;
533 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
534 str = "ttl-security only allowed for EBGP peers";
535 break;
536 case BGP_ERR_AS_OVERRIDE:
537 str = "as-override cannot be configured for IBGP peers";
538 break;
539 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
540 str = "Invalid limit for number of dynamic neighbors";
541 break;
542 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
543 str = "Dynamic neighbor listen range already exists";
544 break;
545 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
546 str = "Operation not allowed on a dynamic neighbor";
547 break;
548 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
549 str = "Operation not allowed on a directly connected neighbor";
550 break;
551 case BGP_ERR_PEER_SAFI_CONFLICT:
552 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
553 break;
554 }
555 if (str) {
556 vty_out(vty, "%% %s\n", str);
557 return CMD_WARNING_CONFIG_FAILED;
558 }
559 return CMD_SUCCESS;
718e3744 560}
561
7aafcaca 562/* BGP clear sort. */
d62a17ae 563enum clear_sort {
564 clear_all,
565 clear_peer,
566 clear_group,
567 clear_external,
568 clear_as
7aafcaca
DS
569};
570
d62a17ae 571static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
572 safi_t safi, int error)
573{
574 switch (error) {
575 case BGP_ERR_AF_UNCONFIGURED:
576 vty_out(vty,
577 "%%BGP: Enable %s address family for the neighbor %s\n",
578 afi_safi_print(afi, safi), peer->host);
579 break;
580 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
581 vty_out(vty,
582 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
583 peer->host);
584 break;
585 default:
586 break;
587 }
7aafcaca
DS
588}
589
590/* `clear ip bgp' functions. */
d62a17ae 591static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
592 enum clear_sort sort, enum bgp_clear_type stype,
593 const char *arg)
594{
595 int ret;
3ae8bfa5 596 bool found = false;
d62a17ae 597 struct peer *peer;
598 struct listnode *node, *nnode;
599
600 /* Clear all neighbors. */
601 /*
602 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
603 * nodes on the BGP instance as that may get freed if it is a
604 * doppelganger
d62a17ae 605 */
606 if (sort == clear_all) {
607 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
608 if (!peer->afc[afi][safi])
609 continue;
610
d62a17ae 611 if (stype == BGP_CLEAR_SOFT_NONE)
612 ret = peer_clear(peer, &nnode);
d62a17ae 613 else
3ae8bfa5 614 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 615
616 if (ret < 0)
617 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
618 else
619 found = true;
04b6bdc0 620 }
d62a17ae 621
622 /* This is to apply read-only mode on this clear. */
623 if (stype == BGP_CLEAR_SOFT_NONE)
624 bgp->update_delay_over = 0;
625
3ae8bfa5 626 if (!found)
3702f84d 627 vty_out(vty, "%%BGP: No %s peer configured\n",
3ae8bfa5
PM
628 afi_safi_print(afi, safi));
629
d62a17ae 630 return CMD_SUCCESS;
7aafcaca
DS
631 }
632
3ae8bfa5 633 /* Clear specified neighbor. */
d62a17ae 634 if (sort == clear_peer) {
635 union sockunion su;
d62a17ae 636
637 /* Make sockunion for lookup. */
638 ret = str2sockunion(arg, &su);
639 if (ret < 0) {
640 peer = peer_lookup_by_conf_if(bgp, arg);
641 if (!peer) {
642 peer = peer_lookup_by_hostname(bgp, arg);
643 if (!peer) {
644 vty_out(vty,
645 "Malformed address or name: %s\n",
646 arg);
647 return CMD_WARNING;
648 }
649 }
650 } else {
651 peer = peer_lookup(bgp, &su);
652 if (!peer) {
653 vty_out(vty,
654 "%%BGP: Unknown neighbor - \"%s\"\n",
655 arg);
656 return CMD_WARNING;
657 }
658 }
7aafcaca 659
3ae8bfa5
PM
660 if (!peer->afc[afi][safi])
661 ret = BGP_ERR_AF_UNCONFIGURED;
662 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 663 ret = peer_clear(peer, NULL);
664 else
665 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 666
d62a17ae 667 if (ret < 0)
668 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 669
d62a17ae 670 return CMD_SUCCESS;
7aafcaca 671 }
7aafcaca 672
3ae8bfa5 673 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 674 if (sort == clear_group) {
675 struct peer_group *group;
7aafcaca 676
d62a17ae 677 group = peer_group_lookup(bgp, arg);
678 if (!group) {
679 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
680 return CMD_WARNING;
681 }
682
683 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 684 if (!peer->afc[afi][safi])
685 continue;
686
3ae8bfa5
PM
687 if (stype == BGP_CLEAR_SOFT_NONE)
688 ret = peer_clear(peer, NULL);
689 else
690 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 691
d62a17ae 692 if (ret < 0)
693 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
694 else
695 found = true;
d62a17ae 696 }
3ae8bfa5
PM
697
698 if (!found)
699 vty_out(vty,
700 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
701 afi_safi_print(afi, safi), arg);
702
d62a17ae 703 return CMD_SUCCESS;
7aafcaca 704 }
7aafcaca 705
3ae8bfa5 706 /* Clear all external (eBGP) neighbors. */
d62a17ae 707 if (sort == clear_external) {
708 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
709 if (peer->sort == BGP_PEER_IBGP)
710 continue;
7aafcaca 711
3ae8bfa5
PM
712 if (!peer->afc[afi][safi])
713 continue;
714
d62a17ae 715 if (stype == BGP_CLEAR_SOFT_NONE)
716 ret = peer_clear(peer, &nnode);
717 else
718 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 719
d62a17ae 720 if (ret < 0)
721 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
722 else
723 found = true;
d62a17ae 724 }
3ae8bfa5
PM
725
726 if (!found)
727 vty_out(vty,
728 "%%BGP: No external %s peer is configured\n",
729 afi_safi_print(afi, safi));
730
d62a17ae 731 return CMD_SUCCESS;
732 }
733
3ae8bfa5 734 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 735 if (sort == clear_as) {
3ae8bfa5 736 as_t as = strtoul(arg, NULL, 10);
d62a17ae 737
738 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
739 if (peer->as != as)
740 continue;
741
3ae8bfa5
PM
742 if (!peer->afc[afi][safi])
743 ret = BGP_ERR_AF_UNCONFIGURED;
744 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 745 ret = peer_clear(peer, &nnode);
746 else
747 ret = peer_clear_soft(peer, afi, safi, stype);
748
749 if (ret < 0)
750 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
751 else
752 found = true;
d62a17ae 753 }
3ae8bfa5
PM
754
755 if (!found)
d62a17ae 756 vty_out(vty,
3ae8bfa5
PM
757 "%%BGP: No %s peer is configured with AS %s\n",
758 afi_safi_print(afi, safi), arg);
759
d62a17ae 760 return CMD_SUCCESS;
761 }
762
763 return CMD_SUCCESS;
764}
765
766static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
767 safi_t safi, enum clear_sort sort,
768 enum bgp_clear_type stype, const char *arg)
769{
770 struct bgp *bgp;
771
772 /* BGP structure lookup. */
773 if (name) {
774 bgp = bgp_lookup_by_name(name);
775 if (bgp == NULL) {
776 vty_out(vty, "Can't find BGP instance %s\n", name);
777 return CMD_WARNING;
778 }
779 } else {
780 bgp = bgp_get_default();
781 if (bgp == NULL) {
782 vty_out(vty, "No BGP process is configured\n");
783 return CMD_WARNING;
784 }
785 }
786
787 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
788}
789
790/* clear soft inbound */
d62a17ae 791static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 792{
99b3ebd3
NS
793 afi_t afi;
794 safi_t safi;
795
796 FOREACH_AFI_SAFI (afi, safi)
797 bgp_clear_vty(vty, name, afi, safi, clear_all,
798 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
799}
800
801/* clear soft outbound */
d62a17ae 802static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 803{
99b3ebd3
NS
804 afi_t afi;
805 safi_t safi;
806
807 FOREACH_AFI_SAFI (afi, safi)
808 bgp_clear_vty(vty, name, afi, safi, clear_all,
809 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
810}
811
812
f787d7a0 813#ifndef VTYSH_EXTRACT_PL
2e4c2296 814#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
815#endif
816
718e3744 817/* BGP global configuration. */
bee57a7a 818#if (CONFDATE > 20190601)
1cc40660
DS
819CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
820CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
821#endif
822DEFUN_HIDDEN (bgp_multiple_instance_func,
823 bgp_multiple_instance_cmd,
824 "bgp multiple-instance",
825 BGP_STR
826 "Enable bgp multiple instance\n")
718e3744 827{
d62a17ae 828 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
829 return CMD_SUCCESS;
718e3744 830}
831
1cc40660 832DEFUN_HIDDEN (no_bgp_multiple_instance,
718e3744 833 no_bgp_multiple_instance_cmd,
834 "no bgp multiple-instance",
835 NO_STR
836 BGP_STR
837 "BGP multiple instance\n")
838{
d62a17ae 839 int ret;
718e3744 840
1cc40660
DS
841 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
842 vty_out(vty, "if you are using this please let the developers know\n");
b7cd3069 843 zlog_info("Deprecated option: `bgp multiple-instance` being used");
d62a17ae 844 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
845 if (ret < 0) {
846 vty_out(vty, "%% There are more than two BGP instances\n");
847 return CMD_WARNING_CONFIG_FAILED;
848 }
849 return CMD_SUCCESS;
718e3744 850}
851
8029b216
AK
852DEFUN_HIDDEN (bgp_local_mac,
853 bgp_local_mac_cmd,
093e3f23 854 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
855 BGP_STR
856 "Local MAC config\n"
857 "VxLAN Network Identifier\n"
858 "VNI number\n"
859 "local mac\n"
860 "mac address\n"
861 "mac-mobility sequence\n"
862 "seq number\n")
863{
864 int rv;
865 vni_t vni;
866 struct ethaddr mac;
867 struct ipaddr ip;
868 uint32_t seq;
869 struct bgp *bgp;
870
871 vni = strtoul(argv[3]->arg, NULL, 10);
872 if (!prefix_str2mac(argv[5]->arg, &mac)) {
873 vty_out(vty, "%% Malformed MAC address\n");
874 return CMD_WARNING;
875 }
876 memset(&ip, 0, sizeof(ip));
877 seq = strtoul(argv[7]->arg, NULL, 10);
878
879 bgp = bgp_get_default();
880 if (!bgp) {
881 vty_out(vty, "Default BGP instance is not there\n");
882 return CMD_WARNING;
883 }
884
885 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
886 if (rv < 0) {
887 vty_out(vty, "Internal error\n");
888 return CMD_WARNING;
889 }
890
891 return CMD_SUCCESS;
892}
893
894DEFUN_HIDDEN (no_bgp_local_mac,
895 no_bgp_local_mac_cmd,
093e3f23 896 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
897 NO_STR
898 BGP_STR
899 "Local MAC config\n"
900 "VxLAN Network Identifier\n"
901 "VNI number\n"
902 "local mac\n"
903 "mac address\n")
904{
905 int rv;
906 vni_t vni;
907 struct ethaddr mac;
908 struct ipaddr ip;
909 struct bgp *bgp;
910
911 vni = strtoul(argv[4]->arg, NULL, 10);
912 if (!prefix_str2mac(argv[6]->arg, &mac)) {
913 vty_out(vty, "%% Malformed MAC address\n");
914 return CMD_WARNING;
915 }
916 memset(&ip, 0, sizeof(ip));
917
918 bgp = bgp_get_default();
919 if (!bgp) {
920 vty_out(vty, "Default BGP instance is not there\n");
921 return CMD_WARNING;
922 }
923
ec0ab544 924 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
925 if (rv < 0) {
926 vty_out(vty, "Internal error\n");
927 return CMD_WARNING;
928 }
929
930 return CMD_SUCCESS;
931}
932
bee57a7a 933#if (CONFDATE > 20190601)
798467a2
DS
934CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
935CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
936#endif
937DEFUN_HIDDEN (bgp_config_type,
938 bgp_config_type_cmd,
939 "bgp config-type <cisco|zebra>",
940 BGP_STR
941 "Configuration type\n"
942 "cisco\n"
943 "zebra\n")
718e3744 944{
d62a17ae 945 int idx = 0;
798467a2
DS
946 if (argv_find(argv, argc, "cisco", &idx)) {
947 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
948 vty_out(vty, "if you are using this please let the developers know!\n");
b7cd3069 949 zlog_info("Deprecated option: `bgp config-type cisco` being used");
d62a17ae 950 bgp_option_set(BGP_OPT_CONFIG_CISCO);
798467a2 951 } else
d62a17ae 952 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 953
d62a17ae 954 return CMD_SUCCESS;
718e3744 955}
956
798467a2
DS
957DEFUN_HIDDEN (no_bgp_config_type,
958 no_bgp_config_type_cmd,
959 "no bgp config-type [<cisco|zebra>]",
960 NO_STR
961 BGP_STR
962 "Display configuration type\n"
963 "cisco\n"
964 "zebra\n")
718e3744 965{
d62a17ae 966 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
967 return CMD_SUCCESS;
718e3744 968}
969
813d4307 970
718e3744 971DEFUN (no_synchronization,
972 no_synchronization_cmd,
973 "no synchronization",
974 NO_STR
975 "Perform IGP synchronization\n")
976{
d62a17ae 977 return CMD_SUCCESS;
718e3744 978}
979
980DEFUN (no_auto_summary,
981 no_auto_summary_cmd,
982 "no auto-summary",
983 NO_STR
984 "Enable automatic network number summarization\n")
985{
d62a17ae 986 return CMD_SUCCESS;
718e3744 987}
3d515fd9 988
718e3744 989/* "router bgp" commands. */
505e5056 990DEFUN_NOSH (router_bgp,
f412b39a 991 router_bgp_cmd,
18c57037 992 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 993 ROUTER_STR
994 BGP_STR
31500417
DW
995 AS_STR
996 BGP_INSTANCE_HELP_STR)
718e3744 997{
d62a17ae 998 int idx_asn = 2;
999 int idx_view_vrf = 3;
1000 int idx_vrf = 4;
ecec9495 1001 int is_new_bgp = 0;
d62a17ae 1002 int ret;
1003 as_t as;
1004 struct bgp *bgp;
1005 const char *name = NULL;
1006 enum bgp_instance_type inst_type;
1007
1008 // "router bgp" without an ASN
1009 if (argc == 2) {
1010 // Pending: Make VRF option available for ASN less config
1011 bgp = bgp_get_default();
1012
1013 if (bgp == NULL) {
1014 vty_out(vty, "%% No BGP process is configured\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 if (listcount(bm->bgp) > 1) {
996c9314 1019 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1020 return CMD_WARNING_CONFIG_FAILED;
1021 }
1022 }
1023
1024 // "router bgp X"
1025 else {
1026 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1027
1028 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1029 if (argc > 3) {
1030 name = argv[idx_vrf]->arg;
1031
9a8bdf1c
PG
1032 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1033 if (strmatch(name, VRF_DEFAULT_NAME))
1034 name = NULL;
1035 else
1036 inst_type = BGP_INSTANCE_TYPE_VRF;
1037 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1038 inst_type = BGP_INSTANCE_TYPE_VIEW;
1039 }
1040
ecec9495
AD
1041 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1042 is_new_bgp = (bgp_lookup(as, name) == NULL);
1043
d62a17ae 1044 ret = bgp_get(&bgp, &as, name, inst_type);
1045 switch (ret) {
1046 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1047 vty_out(vty,
1048 "Please specify 'bgp multiple-instance' first\n");
1049 return CMD_WARNING_CONFIG_FAILED;
1050 case BGP_ERR_AS_MISMATCH:
1051 vty_out(vty, "BGP is already running; AS is %u\n", as);
1052 return CMD_WARNING_CONFIG_FAILED;
1053 case BGP_ERR_INSTANCE_MISMATCH:
1054 vty_out(vty,
1055 "BGP instance name and AS number mismatch\n");
1056 vty_out(vty,
1057 "BGP instance is already running; AS is %u\n",
1058 as);
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
3bd70bf8
PZ
1062 /*
1063 * If we just instantiated the default instance, complete
1064 * any pending VRF-VPN leaking that was configured via
1065 * earlier "router bgp X vrf FOO" blocks.
1066 */
ecec9495 1067 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1068 vpn_leak_postchange_all();
1069
d62a17ae 1070 /* Pending: handle when user tries to change a view to vrf n vv.
1071 */
1072 }
1073
0b5131c9
MK
1074 /* unset the auto created flag as the user config is now present */
1075 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1076 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1077
1078 return CMD_SUCCESS;
718e3744 1079}
1080
718e3744 1081/* "no router bgp" commands. */
1082DEFUN (no_router_bgp,
1083 no_router_bgp_cmd,
18c57037 1084 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 1085 NO_STR
1086 ROUTER_STR
1087 BGP_STR
31500417
DW
1088 AS_STR
1089 BGP_INSTANCE_HELP_STR)
718e3744 1090{
d62a17ae 1091 int idx_asn = 3;
1092 int idx_vrf = 5;
1093 as_t as;
1094 struct bgp *bgp;
1095 const char *name = NULL;
718e3744 1096
d62a17ae 1097 // "no router bgp" without an ASN
1098 if (argc == 3) {
1099 // Pending: Make VRF option available for ASN less config
1100 bgp = bgp_get_default();
718e3744 1101
d62a17ae 1102 if (bgp == NULL) {
1103 vty_out(vty, "%% No BGP process is configured\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
7fb21a9f 1106
d62a17ae 1107 if (listcount(bm->bgp) > 1) {
996c9314 1108 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1109 return CMD_WARNING_CONFIG_FAILED;
1110 }
0b5131c9
MK
1111
1112 if (bgp->l3vni) {
1113 vty_out(vty, "%% Please unconfigure l3vni %u",
1114 bgp->l3vni);
1115 return CMD_WARNING_CONFIG_FAILED;
1116 }
d62a17ae 1117 } else {
1118 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1119
d62a17ae 1120 if (argc > 4)
1121 name = argv[idx_vrf]->arg;
7fb21a9f 1122
d62a17ae 1123 /* Lookup bgp structure. */
1124 bgp = bgp_lookup(as, name);
1125 if (!bgp) {
1126 vty_out(vty, "%% Can't find BGP instance\n");
1127 return CMD_WARNING_CONFIG_FAILED;
1128 }
0b5131c9
MK
1129
1130 if (bgp->l3vni) {
1131 vty_out(vty, "%% Please unconfigure l3vni %u",
1132 bgp->l3vni);
1133 return CMD_WARNING_CONFIG_FAILED;
1134 }
d62a17ae 1135 }
718e3744 1136
d62a17ae 1137 bgp_delete(bgp);
718e3744 1138
d62a17ae 1139 return CMD_SUCCESS;
718e3744 1140}
1141
6b0655a2 1142
718e3744 1143/* BGP router-id. */
1144
f787d7a0 1145DEFPY (bgp_router_id,
718e3744 1146 bgp_router_id_cmd,
1147 "bgp router-id A.B.C.D",
1148 BGP_STR
1149 "Override configured router identifier\n"
1150 "Manually configured router identifier\n")
1151{
d62a17ae 1152 VTY_DECLVAR_CONTEXT(bgp, bgp);
1153 bgp_router_id_static_set(bgp, router_id);
1154 return CMD_SUCCESS;
718e3744 1155}
1156
f787d7a0 1157DEFPY (no_bgp_router_id,
718e3744 1158 no_bgp_router_id_cmd,
31500417 1159 "no bgp router-id [A.B.C.D]",
718e3744 1160 NO_STR
1161 BGP_STR
31500417
DW
1162 "Override configured router identifier\n"
1163 "Manually configured router identifier\n")
718e3744 1164{
d62a17ae 1165 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1166
d62a17ae 1167 if (router_id_str) {
1168 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1169 vty_out(vty, "%% BGP router-id doesn't match\n");
1170 return CMD_WARNING_CONFIG_FAILED;
1171 }
e018c7cc 1172 }
718e3744 1173
d62a17ae 1174 router_id.s_addr = 0;
1175 bgp_router_id_static_set(bgp, router_id);
718e3744 1176
d62a17ae 1177 return CMD_SUCCESS;
718e3744 1178}
1179
6b0655a2 1180
718e3744 1181/* BGP Cluster ID. */
718e3744 1182DEFUN (bgp_cluster_id,
1183 bgp_cluster_id_cmd,
838758ac 1184 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1185 BGP_STR
1186 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1189{
d62a17ae 1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 int idx_ipv4 = 2;
1192 int ret;
1193 struct in_addr cluster;
718e3744 1194
d62a17ae 1195 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1196 if (!ret) {
1197 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1198 return CMD_WARNING_CONFIG_FAILED;
1199 }
718e3744 1200
d62a17ae 1201 bgp_cluster_id_set(bgp, &cluster);
1202 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1203
d62a17ae 1204 return CMD_SUCCESS;
718e3744 1205}
1206
718e3744 1207DEFUN (no_bgp_cluster_id,
1208 no_bgp_cluster_id_cmd,
c7178fe7 1209 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1210 NO_STR
1211 BGP_STR
838758ac
DW
1212 "Configure Route-Reflector Cluster-id\n"
1213 "Route-Reflector Cluster-id in IP address format\n"
1214 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1215{
d62a17ae 1216 VTY_DECLVAR_CONTEXT(bgp, bgp);
1217 bgp_cluster_id_unset(bgp);
1218 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1219
d62a17ae 1220 return CMD_SUCCESS;
718e3744 1221}
1222
718e3744 1223DEFUN (bgp_confederation_identifier,
1224 bgp_confederation_identifier_cmd,
9ccf14f7 1225 "bgp confederation identifier (1-4294967295)",
718e3744 1226 "BGP specific commands\n"
1227 "AS confederation parameters\n"
1228 "AS number\n"
1229 "Set routing domain confederation AS\n")
1230{
d62a17ae 1231 VTY_DECLVAR_CONTEXT(bgp, bgp);
1232 int idx_number = 3;
1233 as_t as;
718e3744 1234
d62a17ae 1235 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1236
d62a17ae 1237 bgp_confederation_id_set(bgp, as);
718e3744 1238
d62a17ae 1239 return CMD_SUCCESS;
718e3744 1240}
1241
1242DEFUN (no_bgp_confederation_identifier,
1243 no_bgp_confederation_identifier_cmd,
838758ac 1244 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1245 NO_STR
1246 "BGP specific commands\n"
1247 "AS confederation parameters\n"
3a2d747c
QY
1248 "AS number\n"
1249 "Set routing domain confederation AS\n")
718e3744 1250{
d62a17ae 1251 VTY_DECLVAR_CONTEXT(bgp, bgp);
1252 bgp_confederation_id_unset(bgp);
718e3744 1253
d62a17ae 1254 return CMD_SUCCESS;
718e3744 1255}
1256
718e3744 1257DEFUN (bgp_confederation_peers,
1258 bgp_confederation_peers_cmd,
12dcf78e 1259 "bgp confederation peers (1-4294967295)...",
718e3744 1260 "BGP specific commands\n"
1261 "AS confederation parameters\n"
1262 "Peer ASs in BGP confederation\n"
1263 AS_STR)
1264{
d62a17ae 1265 VTY_DECLVAR_CONTEXT(bgp, bgp);
1266 int idx_asn = 3;
1267 as_t as;
1268 int i;
718e3744 1269
d62a17ae 1270 for (i = idx_asn; i < argc; i++) {
1271 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1272
d62a17ae 1273 if (bgp->as == as) {
1274 vty_out(vty,
1275 "%% Local member-AS not allowed in confed peer list\n");
1276 continue;
1277 }
718e3744 1278
d62a17ae 1279 bgp_confederation_peers_add(bgp, as);
1280 }
1281 return CMD_SUCCESS;
718e3744 1282}
1283
1284DEFUN (no_bgp_confederation_peers,
1285 no_bgp_confederation_peers_cmd,
e83a9414 1286 "no bgp confederation peers (1-4294967295)...",
718e3744 1287 NO_STR
1288 "BGP specific commands\n"
1289 "AS confederation parameters\n"
1290 "Peer ASs in BGP confederation\n"
1291 AS_STR)
1292{
d62a17ae 1293 VTY_DECLVAR_CONTEXT(bgp, bgp);
1294 int idx_asn = 4;
1295 as_t as;
1296 int i;
718e3744 1297
d62a17ae 1298 for (i = idx_asn; i < argc; i++) {
1299 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1300
d62a17ae 1301 bgp_confederation_peers_remove(bgp, as);
1302 }
1303 return CMD_SUCCESS;
718e3744 1304}
6b0655a2 1305
5e242b0d
DS
1306/**
1307 * Central routine for maximum-paths configuration.
1308 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1309 * @set: 1 for setting values, 0 for removing the max-paths config.
1310 */
d62a17ae 1311static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1312 const char *mpaths, uint16_t options,
d62a17ae 1313 int set)
1314{
1315 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1316 uint16_t maxpaths = 0;
d62a17ae 1317 int ret;
1318 afi_t afi;
1319 safi_t safi;
1320
1321 afi = bgp_node_afi(vty);
1322 safi = bgp_node_safi(vty);
1323
1324 if (set) {
1325 maxpaths = strtol(mpaths, NULL, 10);
1326 if (maxpaths > multipath_num) {
1327 vty_out(vty,
1328 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1329 maxpaths, multipath_num);
1330 return CMD_WARNING_CONFIG_FAILED;
1331 }
1332 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1333 options);
1334 } else
1335 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1336
1337 if (ret < 0) {
1338 vty_out(vty,
1339 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1340 (set == 1) ? "" : "un",
1341 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1342 maxpaths, afi, safi);
1343 return CMD_WARNING_CONFIG_FAILED;
1344 }
1345
1346 bgp_recalculate_all_bestpaths(bgp);
1347
1348 return CMD_SUCCESS;
165b5fff
JB
1349}
1350
abc920f8
DS
1351DEFUN (bgp_maxmed_admin,
1352 bgp_maxmed_admin_cmd,
1353 "bgp max-med administrative ",
1354 BGP_STR
1355 "Advertise routes with max-med\n"
1356 "Administratively applied, for an indefinite period\n")
1357{
d62a17ae 1358 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1359
d62a17ae 1360 bgp->v_maxmed_admin = 1;
1361 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1362
d62a17ae 1363 bgp_maxmed_update(bgp);
abc920f8 1364
d62a17ae 1365 return CMD_SUCCESS;
abc920f8
DS
1366}
1367
1368DEFUN (bgp_maxmed_admin_medv,
1369 bgp_maxmed_admin_medv_cmd,
4668a151 1370 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1371 BGP_STR
1372 "Advertise routes with max-med\n"
1373 "Administratively applied, for an indefinite period\n"
1374 "Max MED value to be used\n")
1375{
d62a17ae 1376 VTY_DECLVAR_CONTEXT(bgp, bgp);
1377 int idx_number = 3;
abc920f8 1378
d62a17ae 1379 bgp->v_maxmed_admin = 1;
1380 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1381
d62a17ae 1382 bgp_maxmed_update(bgp);
abc920f8 1383
d62a17ae 1384 return CMD_SUCCESS;
abc920f8
DS
1385}
1386
1387DEFUN (no_bgp_maxmed_admin,
1388 no_bgp_maxmed_admin_cmd,
4668a151 1389 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1390 NO_STR
1391 BGP_STR
1392 "Advertise routes with max-med\n"
838758ac
DW
1393 "Administratively applied, for an indefinite period\n"
1394 "Max MED value to be used\n")
abc920f8 1395{
d62a17ae 1396 VTY_DECLVAR_CONTEXT(bgp, bgp);
1397 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1398 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1399 bgp_maxmed_update(bgp);
abc920f8 1400
d62a17ae 1401 return CMD_SUCCESS;
abc920f8
DS
1402}
1403
abc920f8
DS
1404DEFUN (bgp_maxmed_onstartup,
1405 bgp_maxmed_onstartup_cmd,
4668a151 1406 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1407 BGP_STR
1408 "Advertise routes with max-med\n"
1409 "Effective on a startup\n"
1410 "Time (seconds) period for max-med\n"
1411 "Max MED value to be used\n")
1412{
d62a17ae 1413 VTY_DECLVAR_CONTEXT(bgp, bgp);
1414 int idx = 0;
4668a151 1415
d62a17ae 1416 argv_find(argv, argc, "(5-86400)", &idx);
1417 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1418 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1419 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1420 else
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1422
d62a17ae 1423 bgp_maxmed_update(bgp);
abc920f8 1424
d62a17ae 1425 return CMD_SUCCESS;
abc920f8
DS
1426}
1427
1428DEFUN (no_bgp_maxmed_onstartup,
1429 no_bgp_maxmed_onstartup_cmd,
4668a151 1430 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1431 NO_STR
1432 BGP_STR
1433 "Advertise routes with max-med\n"
838758ac
DW
1434 "Effective on a startup\n"
1435 "Time (seconds) period for max-med\n"
1436 "Max MED value to be used\n")
abc920f8 1437{
d62a17ae 1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1439
d62a17ae 1440 /* Cancel max-med onstartup if its on */
1441 if (bgp->t_maxmed_onstartup) {
1442 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1443 bgp->maxmed_onstartup_over = 1;
1444 }
abc920f8 1445
d62a17ae 1446 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1447 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1448
d62a17ae 1449 bgp_maxmed_update(bgp);
abc920f8 1450
d62a17ae 1451 return CMD_SUCCESS;
abc920f8
DS
1452}
1453
d62a17ae 1454static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1455 const char *wait)
f188f2c4 1456{
d62a17ae 1457 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1458 uint16_t update_delay;
1459 uint16_t establish_wait;
f188f2c4 1460
d62a17ae 1461 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1462
d62a17ae 1463 if (!wait) /* update-delay <delay> */
1464 {
1465 bgp->v_update_delay = update_delay;
1466 bgp->v_establish_wait = bgp->v_update_delay;
1467 return CMD_SUCCESS;
1468 }
f188f2c4 1469
d62a17ae 1470 /* update-delay <delay> <establish-wait> */
1471 establish_wait = atoi(wait);
1472 if (update_delay < establish_wait) {
1473 vty_out(vty,
1474 "%%Failed: update-delay less than the establish-wait!\n");
1475 return CMD_WARNING_CONFIG_FAILED;
1476 }
f188f2c4 1477
d62a17ae 1478 bgp->v_update_delay = update_delay;
1479 bgp->v_establish_wait = establish_wait;
f188f2c4 1480
d62a17ae 1481 return CMD_SUCCESS;
f188f2c4
DS
1482}
1483
d62a17ae 1484static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1485{
d62a17ae 1486 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1487
d62a17ae 1488 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1489 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1490
d62a17ae 1491 return CMD_SUCCESS;
f188f2c4
DS
1492}
1493
2b791107 1494void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1495{
d62a17ae 1496 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1497 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1498 if (bgp->v_update_delay != bgp->v_establish_wait)
1499 vty_out(vty, " %d", bgp->v_establish_wait);
1500 vty_out(vty, "\n");
1501 }
f188f2c4
DS
1502}
1503
1504
1505/* Update-delay configuration */
1506DEFUN (bgp_update_delay,
1507 bgp_update_delay_cmd,
6147e2c6 1508 "update-delay (0-3600)",
f188f2c4
DS
1509 "Force initial delay for best-path and updates\n"
1510 "Seconds\n")
1511{
d62a17ae 1512 int idx_number = 1;
1513 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1514}
1515
1516DEFUN (bgp_update_delay_establish_wait,
1517 bgp_update_delay_establish_wait_cmd,
6147e2c6 1518 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1519 "Force initial delay for best-path and updates\n"
1520 "Seconds\n"
f188f2c4
DS
1521 "Seconds\n")
1522{
d62a17ae 1523 int idx_number = 1;
1524 int idx_number_2 = 2;
1525 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1526 argv[idx_number_2]->arg);
f188f2c4
DS
1527}
1528
1529/* Update-delay deconfiguration */
1530DEFUN (no_bgp_update_delay,
1531 no_bgp_update_delay_cmd,
838758ac
DW
1532 "no update-delay [(0-3600) [(1-3600)]]",
1533 NO_STR
f188f2c4 1534 "Force initial delay for best-path and updates\n"
838758ac 1535 "Seconds\n"
7111c1a0 1536 "Seconds\n")
f188f2c4 1537{
d62a17ae 1538 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1539}
1540
5e242b0d 1541
d62a17ae 1542static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1543 char set)
cb1faec9 1544{
d62a17ae 1545 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1546
555e09d4
QY
1547 if (set) {
1548 uint32_t quanta = strtoul(num, NULL, 10);
1549 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1550 memory_order_relaxed);
1551 } else {
1552 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1553 memory_order_relaxed);
1554 }
1555
1556 return CMD_SUCCESS;
1557}
1558
1559static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1560 char set)
1561{
1562 VTY_DECLVAR_CONTEXT(bgp, bgp);
1563
1564 if (set) {
1565 uint32_t quanta = strtoul(num, NULL, 10);
1566 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1567 memory_order_relaxed);
1568 } else {
1569 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1570 memory_order_relaxed);
1571 }
cb1faec9 1572
d62a17ae 1573 return CMD_SUCCESS;
cb1faec9
DS
1574}
1575
2b791107 1576void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1577{
555e09d4
QY
1578 uint32_t quanta =
1579 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1580 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1581 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1582}
1583
555e09d4
QY
1584void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1585{
1586 uint32_t quanta =
1587 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1588 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1589 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1590}
cb1faec9 1591
555e09d4 1592/* Packet quanta configuration */
cb1faec9
DS
1593DEFUN (bgp_wpkt_quanta,
1594 bgp_wpkt_quanta_cmd,
555e09d4 1595 "write-quanta (1-10)",
cb1faec9
DS
1596 "How many packets to write to peer socket per run\n"
1597 "Number of packets\n")
1598{
d62a17ae 1599 int idx_number = 1;
1600 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1601}
1602
cb1faec9
DS
1603DEFUN (no_bgp_wpkt_quanta,
1604 no_bgp_wpkt_quanta_cmd,
555e09d4 1605 "no write-quanta (1-10)",
d7fa34c1 1606 NO_STR
555e09d4 1607 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1608 "Number of packets\n")
1609{
d62a17ae 1610 int idx_number = 2;
1611 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1612}
1613
555e09d4
QY
1614DEFUN (bgp_rpkt_quanta,
1615 bgp_rpkt_quanta_cmd,
1616 "read-quanta (1-10)",
1617 "How many packets to read from peer socket per I/O cycle\n"
1618 "Number of packets\n")
1619{
1620 int idx_number = 1;
1621 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1622}
1623
1624DEFUN (no_bgp_rpkt_quanta,
1625 no_bgp_rpkt_quanta_cmd,
1626 "no read-quanta (1-10)",
1627 NO_STR
1628 "How many packets to read from peer socket per I/O cycle\n"
1629 "Number of packets\n")
1630{
1631 int idx_number = 2;
1632 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1633}
1634
2b791107 1635void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1636{
37a333fe 1637 if (!bgp->heuristic_coalesce)
d62a17ae 1638 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1639}
1640
1641
1642DEFUN (bgp_coalesce_time,
1643 bgp_coalesce_time_cmd,
6147e2c6 1644 "coalesce-time (0-4294967295)",
3f9c7369
DS
1645 "Subgroup coalesce timer\n"
1646 "Subgroup coalesce timer value (in ms)\n")
1647{
d62a17ae 1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1649
d62a17ae 1650 int idx = 0;
1651 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1652 bgp->heuristic_coalesce = false;
d62a17ae 1653 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1654 return CMD_SUCCESS;
3f9c7369
DS
1655}
1656
1657DEFUN (no_bgp_coalesce_time,
1658 no_bgp_coalesce_time_cmd,
6147e2c6 1659 "no coalesce-time (0-4294967295)",
3a2d747c 1660 NO_STR
3f9c7369
DS
1661 "Subgroup coalesce timer\n"
1662 "Subgroup coalesce timer value (in ms)\n")
1663{
d62a17ae 1664 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1665
37a333fe 1666 bgp->heuristic_coalesce = true;
d62a17ae 1667 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1668 return CMD_SUCCESS;
3f9c7369
DS
1669}
1670
5e242b0d
DS
1671/* Maximum-paths configuration */
1672DEFUN (bgp_maxpaths,
1673 bgp_maxpaths_cmd,
6319fd63 1674 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1675 "Forward packets over multiple paths\n"
1676 "Number of paths\n")
1677{
d62a17ae 1678 int idx_number = 1;
1679 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1680 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1681}
1682
d62a17ae 1683ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1684 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1685 "Forward packets over multiple paths\n"
1686 "Number of paths\n")
596c17ba 1687
165b5fff
JB
1688DEFUN (bgp_maxpaths_ibgp,
1689 bgp_maxpaths_ibgp_cmd,
6319fd63 1690 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1691 "Forward packets over multiple paths\n"
1692 "iBGP-multipath\n"
1693 "Number of paths\n")
1694{
d62a17ae 1695 int idx_number = 2;
1696 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1697 argv[idx_number]->arg, 0, 1);
5e242b0d 1698}
165b5fff 1699
d62a17ae 1700ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1701 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1702 "Forward packets over multiple paths\n"
1703 "iBGP-multipath\n"
1704 "Number of paths\n")
596c17ba 1705
5e242b0d
DS
1706DEFUN (bgp_maxpaths_ibgp_cluster,
1707 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1708 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1709 "Forward packets over multiple paths\n"
1710 "iBGP-multipath\n"
1711 "Number of paths\n"
1712 "Match the cluster length\n")
1713{
d62a17ae 1714 int idx_number = 2;
1715 return bgp_maxpaths_config_vty(
1716 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1717 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1718}
1719
d62a17ae 1720ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1721 "maximum-paths ibgp " CMD_RANGE_STR(
1722 1, MULTIPATH_NUM) " equal-cluster-length",
1723 "Forward packets over multiple paths\n"
1724 "iBGP-multipath\n"
1725 "Number of paths\n"
1726 "Match the cluster length\n")
596c17ba 1727
165b5fff
JB
1728DEFUN (no_bgp_maxpaths,
1729 no_bgp_maxpaths_cmd,
6319fd63 1730 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1731 NO_STR
1732 "Forward packets over multiple paths\n"
1733 "Number of paths\n")
1734{
d62a17ae 1735 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1736}
1737
d62a17ae 1738ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1739 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1740 "Forward packets over multiple paths\n"
1741 "Number of paths\n")
596c17ba 1742
165b5fff
JB
1743DEFUN (no_bgp_maxpaths_ibgp,
1744 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1745 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1746 NO_STR
1747 "Forward packets over multiple paths\n"
1748 "iBGP-multipath\n"
838758ac
DW
1749 "Number of paths\n"
1750 "Match the cluster length\n")
165b5fff 1751{
d62a17ae 1752 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1753}
1754
d62a17ae 1755ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1756 "no maximum-paths ibgp [" CMD_RANGE_STR(
1757 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1758 NO_STR
1759 "Forward packets over multiple paths\n"
1760 "iBGP-multipath\n"
1761 "Number of paths\n"
1762 "Match the cluster length\n")
596c17ba 1763
2b791107 1764void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1765 safi_t safi)
165b5fff 1766{
d62a17ae 1767 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1768 vty_out(vty, " maximum-paths %d\n",
1769 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1770 }
165b5fff 1771
d62a17ae 1772 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1773 vty_out(vty, " maximum-paths ibgp %d",
1774 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1775 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1776 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1777 vty_out(vty, " equal-cluster-length");
1778 vty_out(vty, "\n");
1779 }
165b5fff 1780}
6b0655a2 1781
718e3744 1782/* BGP timers. */
1783
1784DEFUN (bgp_timers,
1785 bgp_timers_cmd,
6147e2c6 1786 "timers bgp (0-65535) (0-65535)",
718e3744 1787 "Adjust routing timers\n"
1788 "BGP timers\n"
1789 "Keepalive interval\n"
1790 "Holdtime\n")
1791{
d62a17ae 1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 int idx_number = 2;
1794 int idx_number_2 = 3;
1795 unsigned long keepalive = 0;
1796 unsigned long holdtime = 0;
718e3744 1797
d62a17ae 1798 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1799 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1800
d62a17ae 1801 /* Holdtime value check. */
1802 if (holdtime < 3 && holdtime != 0) {
1803 vty_out(vty,
1804 "%% hold time value must be either 0 or greater than 3\n");
1805 return CMD_WARNING_CONFIG_FAILED;
1806 }
718e3744 1807
d62a17ae 1808 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1809
d62a17ae 1810 return CMD_SUCCESS;
718e3744 1811}
1812
1813DEFUN (no_bgp_timers,
1814 no_bgp_timers_cmd,
838758ac 1815 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1816 NO_STR
1817 "Adjust routing timers\n"
838758ac
DW
1818 "BGP timers\n"
1819 "Keepalive interval\n"
1820 "Holdtime\n")
718e3744 1821{
d62a17ae 1822 VTY_DECLVAR_CONTEXT(bgp, bgp);
1823 bgp_timers_unset(bgp);
718e3744 1824
d62a17ae 1825 return CMD_SUCCESS;
718e3744 1826}
1827
6b0655a2 1828
718e3744 1829DEFUN (bgp_client_to_client_reflection,
1830 bgp_client_to_client_reflection_cmd,
1831 "bgp client-to-client reflection",
1832 "BGP specific commands\n"
1833 "Configure client to client route reflection\n"
1834 "reflection of routes allowed\n")
1835{
d62a17ae 1836 VTY_DECLVAR_CONTEXT(bgp, bgp);
1837 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1838 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1839
d62a17ae 1840 return CMD_SUCCESS;
718e3744 1841}
1842
1843DEFUN (no_bgp_client_to_client_reflection,
1844 no_bgp_client_to_client_reflection_cmd,
1845 "no bgp client-to-client reflection",
1846 NO_STR
1847 "BGP specific commands\n"
1848 "Configure client to client route reflection\n"
1849 "reflection of routes allowed\n")
1850{
d62a17ae 1851 VTY_DECLVAR_CONTEXT(bgp, bgp);
1852 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1853 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1854
d62a17ae 1855 return CMD_SUCCESS;
718e3744 1856}
1857
1858/* "bgp always-compare-med" configuration. */
1859DEFUN (bgp_always_compare_med,
1860 bgp_always_compare_med_cmd,
1861 "bgp always-compare-med",
1862 "BGP specific commands\n"
1863 "Allow comparing MED from different neighbors\n")
1864{
d62a17ae 1865 VTY_DECLVAR_CONTEXT(bgp, bgp);
1866 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1868
d62a17ae 1869 return CMD_SUCCESS;
718e3744 1870}
1871
1872DEFUN (no_bgp_always_compare_med,
1873 no_bgp_always_compare_med_cmd,
1874 "no bgp always-compare-med",
1875 NO_STR
1876 "BGP specific commands\n"
1877 "Allow comparing MED from different neighbors\n")
1878{
d62a17ae 1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1881 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1882
d62a17ae 1883 return CMD_SUCCESS;
718e3744 1884}
6b0655a2 1885
9dac9fc8
DA
1886
1887DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1888 "bgp ebgp-requires-policy",
1889 "BGP specific commands\n"
1890 "Require in and out policy for eBGP peers (RFC8212)\n")
1891{
1892 VTY_DECLVAR_CONTEXT(bgp, bgp);
1893 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1894 return CMD_SUCCESS;
1895}
1896
1897DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1898 "no bgp ebgp-requires-policy",
1899 NO_STR
1900 "BGP specific commands\n"
1901 "Require in and out policy for eBGP peers (RFC8212)\n")
1902{
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1905 return CMD_SUCCESS;
1906}
1907
1908
718e3744 1909/* "bgp deterministic-med" configuration. */
1910DEFUN (bgp_deterministic_med,
1911 bgp_deterministic_med_cmd,
1912 "bgp deterministic-med",
1913 "BGP specific commands\n"
1914 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1915{
d62a17ae 1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1917
d62a17ae 1918 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1919 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1920 bgp_recalculate_all_bestpaths(bgp);
1921 }
7aafcaca 1922
d62a17ae 1923 return CMD_SUCCESS;
718e3744 1924}
1925
1926DEFUN (no_bgp_deterministic_med,
1927 no_bgp_deterministic_med_cmd,
1928 "no bgp deterministic-med",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1932{
d62a17ae 1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 int bestpath_per_as_used;
1935 afi_t afi;
1936 safi_t safi;
1937 struct peer *peer;
1938 struct listnode *node, *nnode;
1939
1940 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1941 bestpath_per_as_used = 0;
1942
1943 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1944 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1945 if (bgp_addpath_dmed_required(
1946 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1947 bestpath_per_as_used = 1;
1948 break;
1949 }
d62a17ae 1950
1951 if (bestpath_per_as_used)
1952 break;
1953 }
1954
1955 if (bestpath_per_as_used) {
1956 vty_out(vty,
1957 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1958 return CMD_WARNING_CONFIG_FAILED;
1959 } else {
1960 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1961 bgp_recalculate_all_bestpaths(bgp);
1962 }
1963 }
1964
1965 return CMD_SUCCESS;
718e3744 1966}
538621f2 1967
1968/* "bgp graceful-restart" configuration. */
1969DEFUN (bgp_graceful_restart,
1970 bgp_graceful_restart_cmd,
1971 "bgp graceful-restart",
1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n")
1974{
d62a17ae 1975 VTY_DECLVAR_CONTEXT(bgp, bgp);
1976 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1977 return CMD_SUCCESS;
538621f2 1978}
1979
1980DEFUN (no_bgp_graceful_restart,
1981 no_bgp_graceful_restart_cmd,
1982 "no bgp graceful-restart",
1983 NO_STR
1984 "BGP specific commands\n"
1985 "Graceful restart capability parameters\n")
1986{
d62a17ae 1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1989 return CMD_SUCCESS;
538621f2 1990}
1991
93406d87 1992DEFUN (bgp_graceful_restart_stalepath_time,
1993 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 1994 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 1995 "BGP specific commands\n"
1996 "Graceful restart capability parameters\n"
1997 "Set the max time to hold onto restarting peer's stale paths\n"
1998 "Delay value (seconds)\n")
1999{
d62a17ae 2000 VTY_DECLVAR_CONTEXT(bgp, bgp);
2001 int idx_number = 3;
d7c0a89a 2002 uint32_t stalepath;
93406d87 2003
d62a17ae 2004 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2005 bgp->stalepath_time = stalepath;
2006 return CMD_SUCCESS;
93406d87 2007}
2008
eb6f1b41
PG
2009DEFUN (bgp_graceful_restart_restart_time,
2010 bgp_graceful_restart_restart_time_cmd,
c72d0314 2011 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
2012 "BGP specific commands\n"
2013 "Graceful restart capability parameters\n"
2014 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2015 "Delay value (seconds)\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 int idx_number = 3;
d7c0a89a 2019 uint32_t restart;
eb6f1b41 2020
d62a17ae 2021 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2022 bgp->restart_time = restart;
2023 return CMD_SUCCESS;
eb6f1b41
PG
2024}
2025
93406d87 2026DEFUN (no_bgp_graceful_restart_stalepath_time,
2027 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2028 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 2029 NO_STR
2030 "BGP specific commands\n"
2031 "Graceful restart capability parameters\n"
838758ac
DW
2032 "Set the max time to hold onto restarting peer's stale paths\n"
2033 "Delay value (seconds)\n")
93406d87 2034{
d62a17ae 2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2036
d62a17ae 2037 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2038 return CMD_SUCCESS;
93406d87 2039}
2040
eb6f1b41
PG
2041DEFUN (no_bgp_graceful_restart_restart_time,
2042 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 2043 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
2044 NO_STR
2045 "BGP specific commands\n"
2046 "Graceful restart capability parameters\n"
838758ac
DW
2047 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2048 "Delay value (seconds)\n")
eb6f1b41 2049{
d62a17ae 2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2051
d62a17ae 2052 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2053 return CMD_SUCCESS;
eb6f1b41
PG
2054}
2055
43fc21b3
JC
2056DEFUN (bgp_graceful_restart_preserve_fw,
2057 bgp_graceful_restart_preserve_fw_cmd,
2058 "bgp graceful-restart preserve-fw-state",
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n"
2061 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2062{
d62a17ae 2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2065 return CMD_SUCCESS;
43fc21b3
JC
2066}
2067
2068DEFUN (no_bgp_graceful_restart_preserve_fw,
2069 no_bgp_graceful_restart_preserve_fw_cmd,
2070 "no bgp graceful-restart preserve-fw-state",
2071 NO_STR
2072 "BGP specific commands\n"
2073 "Graceful restart capability parameters\n"
2074 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2075{
d62a17ae 2076 VTY_DECLVAR_CONTEXT(bgp, bgp);
2077 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2078 return CMD_SUCCESS;
43fc21b3
JC
2079}
2080
7f323236
DW
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,
f3c3ee0d 2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
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;
f3c3ee0d 2669 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 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,
f3c3ee0d 2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 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,
f3c3ee0d 3021 "neighbor WORD interface [peer-group PGNAME]",
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,
f3c3ee0d 3042 "neighbor WORD interface v6only [peer-group PGNAME]",
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,
f3c3ee0d 3187 "no neighbor WORD interface [v6only] [peer-group PGNAME] [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,
f3c3ee0d 3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
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,
f3c3ee0d 3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 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,
f3c3ee0d 3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
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,
f3c3ee0d 3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 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
1bc4e531
DA
3965ALIAS_HIDDEN(neighbor_nexthop_self_force,
3966 neighbor_nexthop_self_all_hidden_cmd,
3967 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3969 "Disable the next hop calculation for this neighbor\n"
3970 "Set the next hop to self for reflected routes\n")
3971
718e3744 3972DEFUN (no_neighbor_nexthop_self,
3973 no_neighbor_nexthop_self_cmd,
9ccf14f7 3974 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3975 NO_STR
3976 NEIGHBOR_STR
3977 NEIGHBOR_ADDR_STR2
a538debe 3978 "Disable the next hop calculation for this neighbor\n")
718e3744 3979{
d62a17ae 3980 int idx_peer = 2;
3981 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3982 bgp_node_afi(vty), bgp_node_safi(vty),
3983 PEER_FLAG_NEXTHOP_SELF);
718e3744 3984}
6b0655a2 3985
d62a17ae 3986ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3987 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3988 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3989 "Disable the next hop calculation for this neighbor\n")
596c17ba 3990
88b8ed8d 3991DEFUN (no_neighbor_nexthop_self_force,
a538debe 3992 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3994 NO_STR
3995 NEIGHBOR_STR
3996 NEIGHBOR_ADDR_STR2
3997 "Disable the next hop calculation for this neighbor\n"
3998 "Set the next hop to self for reflected routes\n")
88b8ed8d 3999{
d62a17ae 4000 int idx_peer = 2;
4001 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4002 bgp_node_afi(vty), bgp_node_safi(vty),
4003 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4004}
a538debe 4005
d62a17ae 4006ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4007 no_neighbor_nexthop_self_force_hidden_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4009 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Disable the next hop calculation for this neighbor\n"
4011 "Set the next hop to self for reflected routes\n")
596c17ba 4012
1bc4e531
DA
4013ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4014 no_neighbor_nexthop_self_all_hidden_cmd,
4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4016 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Disable the next hop calculation for this neighbor\n"
4018 "Set the next hop to self for reflected routes\n")
4019
c7122e14
DS
4020/* neighbor as-override */
4021DEFUN (neighbor_as_override,
4022 neighbor_as_override_cmd,
9ccf14f7 4023 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Override ASNs in outbound updates if aspath equals remote-as\n")
4027{
d62a17ae 4028 int idx_peer = 1;
4029 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4030 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4031}
4032
d62a17ae 4033ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4034 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4035 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4036 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4037
c7122e14
DS
4038DEFUN (no_neighbor_as_override,
4039 no_neighbor_as_override_cmd,
9ccf14f7 4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4041 NO_STR
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Override ASNs in outbound updates if aspath equals remote-as\n")
4045{
d62a17ae 4046 int idx_peer = 2;
4047 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4048 bgp_node_afi(vty), bgp_node_safi(vty),
4049 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4050}
4051
d62a17ae 4052ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4053 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4054 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4056
718e3744 4057/* neighbor remove-private-AS. */
4058DEFUN (neighbor_remove_private_as,
4059 neighbor_remove_private_as_cmd,
9ccf14f7 4060 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4061 NEIGHBOR_STR
4062 NEIGHBOR_ADDR_STR2
5000f21c 4063 "Remove private ASNs in outbound updates\n")
718e3744 4064{
d62a17ae 4065 int idx_peer = 1;
4066 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4067 bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4069}
4070
d62a17ae 4071ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4072 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4073 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4074 "Remove private ASNs in outbound updates\n")
596c17ba 4075
5000f21c
DS
4076DEFUN (neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_cmd,
9ccf14f7 4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4079 NEIGHBOR_STR
4080 NEIGHBOR_ADDR_STR2
4081 "Remove private ASNs in outbound updates\n"
efd7904e 4082 "Apply to all AS numbers\n")
5000f21c 4083{
d62a17ae 4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4088}
4089
d62a17ae 4090ALIAS_HIDDEN(neighbor_remove_private_as_all,
4091 neighbor_remove_private_as_all_hidden_cmd,
4092 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4094 "Remove private ASNs in outbound updates\n"
4095 "Apply to all AS numbers")
596c17ba 4096
5000f21c
DS
4097DEFUN (neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4100 NEIGHBOR_STR
4101 NEIGHBOR_ADDR_STR2
4102 "Remove private ASNs in outbound updates\n"
4103 "Replace private ASNs with our ASN in outbound updates\n")
4104{
d62a17ae 4105 int idx_peer = 1;
4106 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4107 bgp_node_safi(vty),
4108 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4109}
4110
d62a17ae 4111ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4112 neighbor_remove_private_as_replace_as_hidden_cmd,
4113 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4114 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4115 "Remove private ASNs in outbound updates\n"
4116 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4117
5000f21c
DS
4118DEFUN (neighbor_remove_private_as_all_replace_as,
4119 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4120 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4121 NEIGHBOR_STR
4122 NEIGHBOR_ADDR_STR2
4123 "Remove private ASNs in outbound updates\n"
16cedbb0 4124 "Apply to all AS numbers\n"
5000f21c
DS
4125 "Replace private ASNs with our ASN in outbound updates\n")
4126{
d62a17ae 4127 int idx_peer = 1;
4128 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4129 bgp_node_safi(vty),
4130 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4131}
4132
d62a17ae 4133ALIAS_HIDDEN(
4134 neighbor_remove_private_as_all_replace_as,
4135 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4136 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4137 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n"
4140 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4141
718e3744 4142DEFUN (no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_cmd,
9ccf14f7 4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4145 NO_STR
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
5000f21c 4148 "Remove private ASNs in outbound updates\n")
718e3744 4149{
d62a17ae 4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4154}
6b0655a2 4155
d62a17ae 4156ALIAS_HIDDEN(no_neighbor_remove_private_as,
4157 no_neighbor_remove_private_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n")
596c17ba 4161
88b8ed8d 4162DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4163 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4164 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4165 NO_STR
4166 NEIGHBOR_STR
4167 NEIGHBOR_ADDR_STR2
4168 "Remove private ASNs in outbound updates\n"
16cedbb0 4169 "Apply to all AS numbers\n")
88b8ed8d 4170{
d62a17ae 4171 int idx_peer = 2;
4172 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4173 bgp_node_afi(vty), bgp_node_safi(vty),
4174 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4175}
5000f21c 4176
d62a17ae 4177ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4178 no_neighbor_remove_private_as_all_hidden_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4180 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4181 "Remove private ASNs in outbound updates\n"
4182 "Apply to all AS numbers\n")
596c17ba 4183
88b8ed8d 4184DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4185 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4186 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4187 NO_STR
4188 NEIGHBOR_STR
4189 NEIGHBOR_ADDR_STR2
4190 "Remove private ASNs in outbound updates\n"
4191 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4192{
d62a17ae 4193 int idx_peer = 2;
4194 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4195 bgp_node_afi(vty), bgp_node_safi(vty),
4196 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4197}
5000f21c 4198
d62a17ae 4199ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4200 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4201 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Remove private ASNs in outbound updates\n"
4204 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4205
88b8ed8d 4206DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4207 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4208 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4209 NO_STR
4210 NEIGHBOR_STR
4211 NEIGHBOR_ADDR_STR2
4212 "Remove private ASNs in outbound updates\n"
16cedbb0 4213 "Apply to all AS numbers\n"
5000f21c 4214 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4215{
d62a17ae 4216 int idx_peer = 2;
4217 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4218 bgp_node_afi(vty), bgp_node_safi(vty),
4219 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4220}
5000f21c 4221
d62a17ae 4222ALIAS_HIDDEN(
4223 no_neighbor_remove_private_as_all_replace_as,
4224 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Remove private ASNs in outbound updates\n"
4228 "Apply to all AS numbers\n"
4229 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4230
5000f21c 4231
718e3744 4232/* neighbor send-community. */
4233DEFUN (neighbor_send_community,
4234 neighbor_send_community_cmd,
9ccf14f7 4235 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4236 NEIGHBOR_STR
4237 NEIGHBOR_ADDR_STR2
4238 "Send Community attribute to this neighbor\n")
4239{
d62a17ae 4240 int idx_peer = 1;
27c05d4d 4241
d62a17ae 4242 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4243 bgp_node_safi(vty),
4244 PEER_FLAG_SEND_COMMUNITY);
718e3744 4245}
4246
d62a17ae 4247ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4248 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4250 "Send Community attribute to this neighbor\n")
596c17ba 4251
718e3744 4252DEFUN (no_neighbor_send_community,
4253 no_neighbor_send_community_cmd,
9ccf14f7 4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4255 NO_STR
4256 NEIGHBOR_STR
4257 NEIGHBOR_ADDR_STR2
4258 "Send Community attribute to this neighbor\n")
4259{
d62a17ae 4260 int idx_peer = 2;
27c05d4d 4261
d62a17ae 4262 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4263 bgp_node_afi(vty), bgp_node_safi(vty),
4264 PEER_FLAG_SEND_COMMUNITY);
718e3744 4265}
6b0655a2 4266
d62a17ae 4267ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4268 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4269 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4270 "Send Community attribute to this neighbor\n")
596c17ba 4271
718e3744 4272/* neighbor send-community extended. */
4273DEFUN (neighbor_send_community_type,
4274 neighbor_send_community_type_cmd,
57d187bc 4275 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
4278 "Send Community attribute to this neighbor\n"
4279 "Send Standard and Extended Community attributes\n"
57d187bc 4280 "Send Standard, Large and Extended Community attributes\n"
718e3744 4281 "Send Extended Community attributes\n"
57d187bc
JS
4282 "Send Standard Community attributes\n"
4283 "Send Large Community attributes\n")
718e3744 4284{
27c05d4d 4285 int idx_peer = 1;
d7c0a89a 4286 uint32_t flag = 0;
27c05d4d 4287 const char *type = argv[argc - 1]->text;
d62a17ae 4288
27c05d4d 4289 if (strmatch(type, "standard")) {
d62a17ae 4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4291 } else if (strmatch(type, "extended")) {
d62a17ae 4292 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4293 } else if (strmatch(type, "large")) {
d62a17ae 4294 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4295 } else if (strmatch(type, "both")) {
d62a17ae 4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4298 } else { /* if (strmatch(type, "all")) */
d62a17ae 4299 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4300 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4302 }
4303
27c05d4d 4304 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4305 bgp_node_safi(vty), flag);
4306}
4307
4308ALIAS_HIDDEN(
4309 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4310 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4312 "Send Community attribute to this neighbor\n"
4313 "Send Standard and Extended Community attributes\n"
4314 "Send Standard, Large and Extended Community attributes\n"
4315 "Send Extended Community attributes\n"
4316 "Send Standard Community attributes\n"
4317 "Send Large Community attributes\n")
596c17ba 4318
718e3744 4319DEFUN (no_neighbor_send_community_type,
4320 no_neighbor_send_community_type_cmd,
57d187bc 4321 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4322 NO_STR
4323 NEIGHBOR_STR
4324 NEIGHBOR_ADDR_STR2
4325 "Send Community attribute to this neighbor\n"
4326 "Send Standard and Extended Community attributes\n"
57d187bc 4327 "Send Standard, Large and Extended Community attributes\n"
718e3744 4328 "Send Extended Community attributes\n"
57d187bc
JS
4329 "Send Standard Community attributes\n"
4330 "Send Large Community attributes\n")
718e3744 4331{
d62a17ae 4332 int idx_peer = 2;
27c05d4d 4333 uint32_t flag = 0;
d62a17ae 4334 const char *type = argv[argc - 1]->text;
4335
27c05d4d
PM
4336 if (strmatch(type, "standard")) {
4337 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4338 } else if (strmatch(type, "extended")) {
4339 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4340 } else if (strmatch(type, "large")) {
4341 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4342 } else if (strmatch(type, "both")) {
4343 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4344 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4345 } else { /* if (strmatch(type, "all")) */
4346 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4347 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4348 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4349 }
4350
4351 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4352 bgp_node_afi(vty), bgp_node_safi(vty),
4353 flag);
d62a17ae 4354}
4355
4356ALIAS_HIDDEN(
4357 no_neighbor_send_community_type,
4358 no_neighbor_send_community_type_hidden_cmd,
4359 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4360 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4361 "Send Community attribute to this neighbor\n"
4362 "Send Standard and Extended Community attributes\n"
4363 "Send Standard, Large and Extended Community attributes\n"
4364 "Send Extended Community attributes\n"
4365 "Send Standard Community attributes\n"
4366 "Send Large Community attributes\n")
596c17ba 4367
718e3744 4368/* neighbor soft-reconfig. */
4369DEFUN (neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Per neighbor soft reconfiguration\n"
4375 "Allow inbound soft reconfiguration for this neighbor\n")
4376{
d62a17ae 4377 int idx_peer = 1;
4378 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4379 bgp_node_safi(vty),
4380 PEER_FLAG_SOFT_RECONFIG);
718e3744 4381}
4382
d62a17ae 4383ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4384 neighbor_soft_reconfiguration_hidden_cmd,
4385 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4387 "Per neighbor soft reconfiguration\n"
4388 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4389
718e3744 4390DEFUN (no_neighbor_soft_reconfiguration,
4391 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4392 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4393 NO_STR
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Per neighbor soft reconfiguration\n"
4397 "Allow inbound soft reconfiguration for this neighbor\n")
4398{
d62a17ae 4399 int idx_peer = 2;
4400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4401 bgp_node_afi(vty), bgp_node_safi(vty),
4402 PEER_FLAG_SOFT_RECONFIG);
718e3744 4403}
6b0655a2 4404
d62a17ae 4405ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4406 no_neighbor_soft_reconfiguration_hidden_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4409 "Per neighbor soft reconfiguration\n"
4410 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4411
718e3744 4412DEFUN (neighbor_route_reflector_client,
4413 neighbor_route_reflector_client_cmd,
9ccf14f7 4414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4415 NEIGHBOR_STR
4416 NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Reflector client\n")
4418{
d62a17ae 4419 int idx_peer = 1;
4420 struct peer *peer;
718e3744 4421
4422
d62a17ae 4423 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4424 if (!peer)
4425 return CMD_WARNING_CONFIG_FAILED;
718e3744 4426
d62a17ae 4427 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4428 bgp_node_safi(vty),
4429 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4430}
4431
d62a17ae 4432ALIAS_HIDDEN(neighbor_route_reflector_client,
4433 neighbor_route_reflector_client_hidden_cmd,
4434 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4436 "Configure a neighbor as Route Reflector client\n")
596c17ba 4437
718e3744 4438DEFUN (no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4441 NO_STR
4442 NEIGHBOR_STR
4443 NEIGHBOR_ADDR_STR2
4444 "Configure a neighbor as Route Reflector client\n")
4445{
d62a17ae 4446 int idx_peer = 2;
4447 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4448 bgp_node_afi(vty), bgp_node_safi(vty),
4449 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4450}
6b0655a2 4451
d62a17ae 4452ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4453 no_neighbor_route_reflector_client_hidden_cmd,
4454 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4456 "Configure a neighbor as Route Reflector client\n")
596c17ba 4457
718e3744 4458/* neighbor route-server-client. */
4459DEFUN (neighbor_route_server_client,
4460 neighbor_route_server_client_cmd,
9ccf14f7 4461 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4462 NEIGHBOR_STR
4463 NEIGHBOR_ADDR_STR2
4464 "Configure a neighbor as Route Server client\n")
4465{
d62a17ae 4466 int idx_peer = 1;
4467 struct peer *peer;
2a3d5731 4468
d62a17ae 4469 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4470 if (!peer)
4471 return CMD_WARNING_CONFIG_FAILED;
4472 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4473 bgp_node_safi(vty),
4474 PEER_FLAG_RSERVER_CLIENT);
718e3744 4475}
4476
d62a17ae 4477ALIAS_HIDDEN(neighbor_route_server_client,
4478 neighbor_route_server_client_hidden_cmd,
4479 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "Configure a neighbor as Route Server client\n")
596c17ba 4482
718e3744 4483DEFUN (no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_cmd,
9ccf14f7 4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4486 NO_STR
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure a neighbor as Route Server client\n")
fee0f4c6 4490{
d62a17ae 4491 int idx_peer = 2;
4492 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4493 bgp_node_afi(vty), bgp_node_safi(vty),
4494 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4495}
6b0655a2 4496
d62a17ae 4497ALIAS_HIDDEN(no_neighbor_route_server_client,
4498 no_neighbor_route_server_client_hidden_cmd,
4499 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4500 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4501 "Configure a neighbor as Route Server client\n")
596c17ba 4502
fee0f4c6 4503DEFUN (neighbor_nexthop_local_unchanged,
4504 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4505 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Configure treatment of outgoing link-local nexthop attribute\n"
4509 "Leave link-local nexthop unchanged for this peer\n")
4510{
d62a17ae 4511 int idx_peer = 1;
4512 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4513 bgp_node_safi(vty),
4514 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4515}
6b0655a2 4516
fee0f4c6 4517DEFUN (no_neighbor_nexthop_local_unchanged,
4518 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4519 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4520 NO_STR
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "Configure treatment of outgoing link-local-nexthop attribute\n"
4524 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4525{
d62a17ae 4526 int idx_peer = 2;
4527 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4528 bgp_node_afi(vty), bgp_node_safi(vty),
4529 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4530}
6b0655a2 4531
718e3744 4532DEFUN (neighbor_attr_unchanged,
4533 neighbor_attr_unchanged_cmd,
a8206004 4534 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "BGP attribute is propagated unchanged to this neighbor\n"
4538 "As-path attribute\n"
4539 "Nexthop attribute\n"
a8206004 4540 "Med attribute\n")
718e3744 4541{
d62a17ae 4542 int idx = 0;
8eeb0335
DW
4543 char *peer_str = argv[1]->arg;
4544 struct peer *peer;
d7c0a89a 4545 uint16_t flags = 0;
8eeb0335
DW
4546 afi_t afi = bgp_node_afi(vty);
4547 safi_t safi = bgp_node_safi(vty);
4548
4549 peer = peer_and_group_lookup_vty(vty, peer_str);
4550 if (!peer)
4551 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4552
4553 if (argv_find(argv, argc, "as-path", &idx))
4554 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4555 idx = 0;
4556 if (argv_find(argv, argc, "next-hop", &idx))
4557 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4558 idx = 0;
4559 if (argv_find(argv, argc, "med", &idx))
4560 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4561
8eeb0335
DW
4562 /* no flags means all of them! */
4563 if (!flags) {
d62a17ae 4564 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4565 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4566 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4567 } else {
a4d82a8a
PZ
4568 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_AS_PATH_UNCHANGED);
4573 }
4574
a4d82a8a
PZ
4575 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4576 && peer_af_flag_check(peer, afi, safi,
4577 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4578 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4579 PEER_FLAG_NEXTHOP_UNCHANGED);
4580 }
4581
a4d82a8a
PZ
4582 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4583 && peer_af_flag_check(peer, afi, safi,
4584 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4585 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4586 PEER_FLAG_MED_UNCHANGED);
4587 }
d62a17ae 4588 }
4589
8eeb0335 4590 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4591}
4592
4593ALIAS_HIDDEN(
4594 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4595 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4596 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4597 "BGP attribute is propagated unchanged to this neighbor\n"
4598 "As-path attribute\n"
4599 "Nexthop attribute\n"
4600 "Med attribute\n")
596c17ba 4601
718e3744 4602DEFUN (no_neighbor_attr_unchanged,
4603 no_neighbor_attr_unchanged_cmd,
a8206004 4604 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4605 NO_STR
718e3744 4606 NEIGHBOR_STR
4607 NEIGHBOR_ADDR_STR2
31500417
DW
4608 "BGP attribute is propagated unchanged to this neighbor\n"
4609 "As-path attribute\n"
40e718b5 4610 "Nexthop attribute\n"
a8206004 4611 "Med attribute\n")
718e3744 4612{
d62a17ae 4613 int idx = 0;
4614 char *peer = argv[2]->arg;
d7c0a89a 4615 uint16_t flags = 0;
d62a17ae 4616
4617 if (argv_find(argv, argc, "as-path", &idx))
4618 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4619 idx = 0;
4620 if (argv_find(argv, argc, "next-hop", &idx))
4621 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4622 idx = 0;
4623 if (argv_find(argv, argc, "med", &idx))
4624 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4625
4626 if (!flags) // no flags means all of them!
4627 {
4628 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4629 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4630 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4631 }
4632
4633 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4634 bgp_node_safi(vty), flags);
4635}
4636
4637ALIAS_HIDDEN(
4638 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4639 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4641 "BGP attribute is propagated unchanged to this neighbor\n"
4642 "As-path attribute\n"
4643 "Nexthop attribute\n"
4644 "Med attribute\n")
718e3744 4645
718e3744 4646/* EBGP multihop configuration. */
d62a17ae 4647static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4648 const char *ttl_str)
718e3744 4649{
d62a17ae 4650 struct peer *peer;
4651 unsigned int ttl;
718e3744 4652
d62a17ae 4653 peer = peer_and_group_lookup_vty(vty, ip_str);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
718e3744 4656
d62a17ae 4657 if (peer->conf_if)
4658 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4659
d62a17ae 4660 if (!ttl_str)
4661 ttl = MAXTTL;
4662 else
4663 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4664
d62a17ae 4665 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4666}
4667
d62a17ae 4668static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4669{
d62a17ae 4670 struct peer *peer;
718e3744 4671
d62a17ae 4672 peer = peer_and_group_lookup_vty(vty, ip_str);
4673 if (!peer)
4674 return CMD_WARNING_CONFIG_FAILED;
718e3744 4675
d62a17ae 4676 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4677}
4678
4679/* neighbor ebgp-multihop. */
4680DEFUN (neighbor_ebgp_multihop,
4681 neighbor_ebgp_multihop_cmd,
9ccf14f7 4682 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
4685 "Allow EBGP neighbors not on directly connected networks\n")
4686{
d62a17ae 4687 int idx_peer = 1;
4688 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4689}
4690
4691DEFUN (neighbor_ebgp_multihop_ttl,
4692 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4693 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Allow EBGP neighbors not on directly connected networks\n"
4697 "maximum hop count\n")
4698{
d62a17ae 4699 int idx_peer = 1;
4700 int idx_number = 3;
4701 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4702 argv[idx_number]->arg);
718e3744 4703}
4704
4705DEFUN (no_neighbor_ebgp_multihop,
4706 no_neighbor_ebgp_multihop_cmd,
a636c635 4707 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4708 NO_STR
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
a636c635
DW
4711 "Allow EBGP neighbors not on directly connected networks\n"
4712 "maximum hop count\n")
718e3744 4713{
d62a17ae 4714 int idx_peer = 2;
4715 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4716}
4717
6b0655a2 4718
6ffd2079 4719/* disable-connected-check */
4720DEFUN (neighbor_disable_connected_check,
4721 neighbor_disable_connected_check_cmd,
7ebe625c 4722 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 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 = 1;
4729 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4731}
4732
4733DEFUN (no_neighbor_disable_connected_check,
4734 no_neighbor_disable_connected_check_cmd,
7ebe625c 4735 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4736 NO_STR
4737 NEIGHBOR_STR
7ebe625c 4738 NEIGHBOR_ADDR_STR2
a636c635
DW
4739 "one-hop away EBGP peer using loopback address\n"
4740 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4741{
d62a17ae 4742 int idx_peer = 2;
4743 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4744 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4745}
4746
47cbc09b
PM
4747
4748/* enforce-first-as */
4749DEFUN (neighbor_enforce_first_as,
4750 neighbor_enforce_first_as_cmd,
4751 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755{
4756 int idx_peer = 1;
4757
4758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760}
4761
4762DEFUN (no_neighbor_enforce_first_as,
4763 no_neighbor_enforce_first_as_cmd,
4764 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4765 NO_STR
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Enforce the first AS for EBGP routes\n")
4769{
4770 int idx_peer = 2;
4771
4772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4773 PEER_FLAG_ENFORCE_FIRST_AS);
4774}
4775
4776
718e3744 4777DEFUN (neighbor_description,
4778 neighbor_description_cmd,
e961923c 4779 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Neighbor specific description\n"
4783 "Up to 80 characters describing this neighbor\n")
4784{
d62a17ae 4785 int idx_peer = 1;
4786 int idx_line = 3;
4787 struct peer *peer;
4788 char *str;
718e3744 4789
d62a17ae 4790 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4791 if (!peer)
4792 return CMD_WARNING_CONFIG_FAILED;
718e3744 4793
d62a17ae 4794 str = argv_concat(argv, argc, idx_line);
718e3744 4795
d62a17ae 4796 peer_description_set(peer, str);
718e3744 4797
d62a17ae 4798 XFREE(MTYPE_TMP, str);
718e3744 4799
d62a17ae 4800 return CMD_SUCCESS;
718e3744 4801}
4802
4803DEFUN (no_neighbor_description,
4804 no_neighbor_description_cmd,
a14810f4 4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4806 NO_STR
4807 NEIGHBOR_STR
4808 NEIGHBOR_ADDR_STR2
a14810f4 4809 "Neighbor specific description\n")
718e3744 4810{
d62a17ae 4811 int idx_peer = 2;
4812 struct peer *peer;
718e3744 4813
d62a17ae 4814 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4815 if (!peer)
4816 return CMD_WARNING_CONFIG_FAILED;
718e3744 4817
d62a17ae 4818 peer_description_unset(peer);
718e3744 4819
d62a17ae 4820 return CMD_SUCCESS;
718e3744 4821}
4822
a14810f4
PM
4823ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4824 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4826 "Neighbor specific description\n"
4827 "Up to 80 characters describing this neighbor\n")
6b0655a2 4828
718e3744 4829/* Neighbor update-source. */
d62a17ae 4830static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4831 const char *source_str)
4832{
4833 struct peer *peer;
4834 struct prefix p;
a14810f4 4835 union sockunion su;
d62a17ae 4836
4837 peer = peer_and_group_lookup_vty(vty, peer_str);
4838 if (!peer)
4839 return CMD_WARNING_CONFIG_FAILED;
4840
4841 if (peer->conf_if)
4842 return CMD_WARNING;
4843
4844 if (source_str) {
a14810f4 4845 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4846 peer_update_source_addr_set(peer, &su);
4847 else {
4848 if (str2prefix(source_str, &p)) {
4849 vty_out(vty,
4850 "%% Invalid update-source, remove prefix length \n");
4851 return CMD_WARNING_CONFIG_FAILED;
4852 } else
4853 peer_update_source_if_set(peer, source_str);
4854 }
4855 } else
4856 peer_update_source_unset(peer);
4857
4858 return CMD_SUCCESS;
4859}
4860
4861#define BGP_UPDATE_SOURCE_HELP_STR \
4862 "IPv4 address\n" \
4863 "IPv6 address\n" \
4864 "Interface name (requires zebra to be running)\n"
369688c0 4865
718e3744 4866DEFUN (neighbor_update_source,
4867 neighbor_update_source_cmd,
9ccf14f7 4868 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4869 NEIGHBOR_STR
4870 NEIGHBOR_ADDR_STR2
4871 "Source of routing updates\n"
369688c0 4872 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4873{
d62a17ae 4874 int idx_peer = 1;
4875 int idx_peer_2 = 3;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4877 argv[idx_peer_2]->arg);
718e3744 4878}
4879
4880DEFUN (no_neighbor_update_source,
4881 no_neighbor_update_source_cmd,
c7178fe7 4882 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4883 NO_STR
4884 NEIGHBOR_STR
4885 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4886 "Source of routing updates\n"
4887 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4888{
d62a17ae 4889 int idx_peer = 2;
4890 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4891}
6b0655a2 4892
d62a17ae 4893static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4894 afi_t afi, safi_t safi,
4895 const char *rmap, int set)
718e3744 4896{
d62a17ae 4897 int ret;
4898 struct peer *peer;
08793e99 4899 struct route_map *route_map = NULL;
718e3744 4900
d62a17ae 4901 peer = peer_and_group_lookup_vty(vty, peer_str);
4902 if (!peer)
4903 return CMD_WARNING_CONFIG_FAILED;
718e3744 4904
1de27621 4905 if (set) {
08793e99
DS
4906 if (rmap)
4907 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
4908 ret = peer_default_originate_set(peer, afi, safi,
4909 rmap, route_map);
4910 } else
d62a17ae 4911 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4912
d62a17ae 4913 return bgp_vty_return(vty, ret);
718e3744 4914}
4915
4916/* neighbor default-originate. */
4917DEFUN (neighbor_default_originate,
4918 neighbor_default_originate_cmd,
9ccf14f7 4919 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n")
4923{
d62a17ae 4924 int idx_peer = 1;
4925 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4926 bgp_node_afi(vty),
4927 bgp_node_safi(vty), NULL, 1);
718e3744 4928}
4929
d62a17ae 4930ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4931 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4933 "Originate default route to this neighbor\n")
596c17ba 4934
718e3744 4935DEFUN (neighbor_default_originate_rmap,
4936 neighbor_default_originate_rmap_cmd,
9ccf14f7 4937 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Originate default route to this neighbor\n"
4941 "Route-map to specify criteria to originate default\n"
4942 "route-map name\n")
4943{
d62a17ae 4944 int idx_peer = 1;
4945 int idx_word = 4;
4946 return peer_default_originate_set_vty(
4947 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4948 argv[idx_word]->arg, 1);
718e3744 4949}
4950
d62a17ae 4951ALIAS_HIDDEN(
4952 neighbor_default_originate_rmap,
4953 neighbor_default_originate_rmap_hidden_cmd,
4954 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4955 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4956 "Originate default route to this neighbor\n"
4957 "Route-map to specify criteria to originate default\n"
4958 "route-map name\n")
596c17ba 4959
718e3744 4960DEFUN (no_neighbor_default_originate,
4961 no_neighbor_default_originate_cmd,
a636c635 4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
a636c635
DW
4966 "Originate default route to this neighbor\n"
4967 "Route-map to specify criteria to originate default\n"
4968 "route-map name\n")
718e3744 4969{
d62a17ae 4970 int idx_peer = 2;
4971 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4972 bgp_node_afi(vty),
4973 bgp_node_safi(vty), NULL, 0);
718e3744 4974}
4975
d62a17ae 4976ALIAS_HIDDEN(
4977 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4979 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4980 "Originate default route to this neighbor\n"
4981 "Route-map to specify criteria to originate default\n"
4982 "route-map name\n")
596c17ba 4983
6b0655a2 4984
718e3744 4985/* Set neighbor's BGP port. */
d62a17ae 4986static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4987 const char *port_str)
4988{
4989 struct peer *peer;
d7c0a89a 4990 uint16_t port;
d62a17ae 4991 struct servent *sp;
4992
4993 peer = peer_lookup_vty(vty, ip_str);
4994 if (!peer)
4995 return CMD_WARNING_CONFIG_FAILED;
4996
4997 if (!port_str) {
4998 sp = getservbyname("bgp", "tcp");
4999 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5000 } else {
5001 port = strtoul(port_str, NULL, 10);
5002 }
718e3744 5003
d62a17ae 5004 peer_port_set(peer, port);
718e3744 5005
d62a17ae 5006 return CMD_SUCCESS;
718e3744 5007}
5008
f418446b 5009/* Set specified peer's BGP port. */
718e3744 5010DEFUN (neighbor_port,
5011 neighbor_port_cmd,
9ccf14f7 5012 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
5017{
d62a17ae 5018 int idx_ip = 1;
5019 int idx_number = 3;
5020 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5021 argv[idx_number]->arg);
718e3744 5022}
5023
5024DEFUN (no_neighbor_port,
5025 no_neighbor_port_cmd,
9ccf14f7 5026 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5027 NO_STR
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR
8334fd5a
DW
5030 "Neighbor's BGP port\n"
5031 "TCP port number\n")
718e3744 5032{
d62a17ae 5033 int idx_ip = 2;
5034 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5035}
5036
6b0655a2 5037
718e3744 5038/* neighbor weight. */
d62a17ae 5039static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5040 safi_t safi, const char *weight_str)
718e3744 5041{
d62a17ae 5042 int ret;
5043 struct peer *peer;
5044 unsigned long weight;
718e3744 5045
d62a17ae 5046 peer = peer_and_group_lookup_vty(vty, ip_str);
5047 if (!peer)
5048 return CMD_WARNING_CONFIG_FAILED;
718e3744 5049
d62a17ae 5050 weight = strtoul(weight_str, NULL, 10);
718e3744 5051
d62a17ae 5052 ret = peer_weight_set(peer, afi, safi, weight);
5053 return bgp_vty_return(vty, ret);
718e3744 5054}
5055
d62a17ae 5056static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5057 safi_t safi)
718e3744 5058{
d62a17ae 5059 int ret;
5060 struct peer *peer;
718e3744 5061
d62a17ae 5062 peer = peer_and_group_lookup_vty(vty, ip_str);
5063 if (!peer)
5064 return CMD_WARNING_CONFIG_FAILED;
718e3744 5065
d62a17ae 5066 ret = peer_weight_unset(peer, afi, safi);
5067 return bgp_vty_return(vty, ret);
718e3744 5068}
5069
5070DEFUN (neighbor_weight,
5071 neighbor_weight_cmd,
9ccf14f7 5072 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "Set default weight for routes from this neighbor\n"
5076 "default weight\n")
5077{
d62a17ae 5078 int idx_peer = 1;
5079 int idx_number = 3;
5080 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5081 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5082}
5083
d62a17ae 5084ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5085 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Set default weight for routes from this neighbor\n"
5088 "default weight\n")
596c17ba 5089
718e3744 5090DEFUN (no_neighbor_weight,
5091 no_neighbor_weight_cmd,
9ccf14f7 5092 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5093 NO_STR
5094 NEIGHBOR_STR
5095 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5096 "Set default weight for routes from this neighbor\n"
5097 "default weight\n")
718e3744 5098{
d62a17ae 5099 int idx_peer = 2;
5100 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5101 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5102}
5103
d62a17ae 5104ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5105 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5106 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5107 "Set default weight for routes from this neighbor\n"
5108 "default weight\n")
596c17ba 5109
6b0655a2 5110
718e3744 5111/* Override capability negotiation. */
5112DEFUN (neighbor_override_capability,
5113 neighbor_override_capability_cmd,
9ccf14f7 5114 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "Override capability negotiation result\n")
5118{
d62a17ae 5119 int idx_peer = 1;
5120 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5121 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5122}
5123
5124DEFUN (no_neighbor_override_capability,
5125 no_neighbor_override_capability_cmd,
9ccf14f7 5126 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5127 NO_STR
5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Override capability negotiation result\n")
5131{
d62a17ae 5132 int idx_peer = 2;
5133 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5134 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5135}
6b0655a2 5136
718e3744 5137DEFUN (neighbor_strict_capability,
5138 neighbor_strict_capability_cmd,
9fb964de 5139 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5140 NEIGHBOR_STR
9fb964de 5141 NEIGHBOR_ADDR_STR2
718e3744 5142 "Strict capability negotiation match\n")
5143{
9fb964de
PM
5144 int idx_peer = 1;
5145
5146 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5147 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5148}
5149
5150DEFUN (no_neighbor_strict_capability,
5151 no_neighbor_strict_capability_cmd,
9fb964de 5152 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5153 NO_STR
5154 NEIGHBOR_STR
9fb964de 5155 NEIGHBOR_ADDR_STR2
718e3744 5156 "Strict capability negotiation match\n")
5157{
9fb964de
PM
5158 int idx_peer = 2;
5159
5160 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5161 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5162}
6b0655a2 5163
d62a17ae 5164static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5165 const char *keep_str, const char *hold_str)
718e3744 5166{
d62a17ae 5167 int ret;
5168 struct peer *peer;
d7c0a89a
QY
5169 uint32_t keepalive;
5170 uint32_t holdtime;
718e3744 5171
d62a17ae 5172 peer = peer_and_group_lookup_vty(vty, ip_str);
5173 if (!peer)
5174 return CMD_WARNING_CONFIG_FAILED;
718e3744 5175
d62a17ae 5176 keepalive = strtoul(keep_str, NULL, 10);
5177 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5178
d62a17ae 5179 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5180
d62a17ae 5181 return bgp_vty_return(vty, ret);
718e3744 5182}
6b0655a2 5183
d62a17ae 5184static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5185{
d62a17ae 5186 int ret;
5187 struct peer *peer;
718e3744 5188
d62a17ae 5189 peer = peer_and_group_lookup_vty(vty, ip_str);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
718e3744 5192
d62a17ae 5193 ret = peer_timers_unset(peer);
718e3744 5194
d62a17ae 5195 return bgp_vty_return(vty, ret);
718e3744 5196}
5197
5198DEFUN (neighbor_timers,
5199 neighbor_timers_cmd,
9ccf14f7 5200 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "BGP per neighbor timers\n"
5204 "Keepalive interval\n"
5205 "Holdtime\n")
5206{
d62a17ae 5207 int idx_peer = 1;
5208 int idx_number = 3;
5209 int idx_number_2 = 4;
5210 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5211 argv[idx_number]->arg,
5212 argv[idx_number_2]->arg);
718e3744 5213}
5214
5215DEFUN (no_neighbor_timers,
5216 no_neighbor_timers_cmd,
9ccf14f7 5217 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5218 NO_STR
5219 NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5221 "BGP per neighbor timers\n"
5222 "Keepalive interval\n"
5223 "Holdtime\n")
718e3744 5224{
d62a17ae 5225 int idx_peer = 2;
5226 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5227}
6b0655a2 5228
813d4307 5229
d62a17ae 5230static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5231 const char *time_str)
718e3744 5232{
d62a17ae 5233 int ret;
5234 struct peer *peer;
d7c0a89a 5235 uint32_t connect;
718e3744 5236
d62a17ae 5237 peer = peer_and_group_lookup_vty(vty, ip_str);
5238 if (!peer)
5239 return CMD_WARNING_CONFIG_FAILED;
718e3744 5240
d62a17ae 5241 connect = strtoul(time_str, NULL, 10);
718e3744 5242
d62a17ae 5243 ret = peer_timers_connect_set(peer, connect);
718e3744 5244
d62a17ae 5245 return bgp_vty_return(vty, ret);
718e3744 5246}
5247
d62a17ae 5248static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5249{
d62a17ae 5250 int ret;
5251 struct peer *peer;
718e3744 5252
d62a17ae 5253 peer = peer_and_group_lookup_vty(vty, ip_str);
5254 if (!peer)
5255 return CMD_WARNING_CONFIG_FAILED;
718e3744 5256
d62a17ae 5257 ret = peer_timers_connect_unset(peer);
718e3744 5258
d62a17ae 5259 return bgp_vty_return(vty, ret);
718e3744 5260}
5261
5262DEFUN (neighbor_timers_connect,
5263 neighbor_timers_connect_cmd,
9ccf14f7 5264 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5265 NEIGHBOR_STR
966f821c 5266 NEIGHBOR_ADDR_STR2
718e3744 5267 "BGP per neighbor timers\n"
5268 "BGP connect timer\n"
5269 "Connect timer\n")
5270{
d62a17ae 5271 int idx_peer = 1;
5272 int idx_number = 4;
5273 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5274 argv[idx_number]->arg);
718e3744 5275}
5276
5277DEFUN (no_neighbor_timers_connect,
5278 no_neighbor_timers_connect_cmd,
9ccf14f7 5279 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5280 NO_STR
5281 NEIGHBOR_STR
966f821c 5282 NEIGHBOR_ADDR_STR2
718e3744 5283 "BGP per neighbor timers\n"
8334fd5a
DW
5284 "BGP connect timer\n"
5285 "Connect timer\n")
718e3744 5286{
d62a17ae 5287 int idx_peer = 2;
5288 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5289}
5290
6b0655a2 5291
d62a17ae 5292static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5293 const char *time_str, int set)
718e3744 5294{
d62a17ae 5295 int ret;
5296 struct peer *peer;
d7c0a89a 5297 uint32_t routeadv = 0;
718e3744 5298
d62a17ae 5299 peer = peer_and_group_lookup_vty(vty, ip_str);
5300 if (!peer)
5301 return CMD_WARNING_CONFIG_FAILED;
718e3744 5302
d62a17ae 5303 if (time_str)
5304 routeadv = strtoul(time_str, NULL, 10);
718e3744 5305
d62a17ae 5306 if (set)
5307 ret = peer_advertise_interval_set(peer, routeadv);
5308 else
5309 ret = peer_advertise_interval_unset(peer);
718e3744 5310
d62a17ae 5311 return bgp_vty_return(vty, ret);
718e3744 5312}
5313
5314DEFUN (neighbor_advertise_interval,
5315 neighbor_advertise_interval_cmd,
9ccf14f7 5316 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5317 NEIGHBOR_STR
966f821c 5318 NEIGHBOR_ADDR_STR2
718e3744 5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
5321{
d62a17ae 5322 int idx_peer = 1;
5323 int idx_number = 3;
5324 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5325 argv[idx_number]->arg, 1);
718e3744 5326}
5327
5328DEFUN (no_neighbor_advertise_interval,
5329 no_neighbor_advertise_interval_cmd,
9ccf14f7 5330 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5331 NO_STR
5332 NEIGHBOR_STR
966f821c 5333 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5334 "Minimum interval between sending BGP routing updates\n"
5335 "time in seconds\n")
718e3744 5336{
d62a17ae 5337 int idx_peer = 2;
5338 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5339}
5340
6b0655a2 5341
518f0eb1
DS
5342/* Time to wait before processing route-map updates */
5343DEFUN (bgp_set_route_map_delay_timer,
5344 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5345 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5346 SET_STR
5347 "BGP route-map delay timer\n"
5348 "Time in secs to wait before processing route-map changes\n"
f414725f 5349 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5350{
d62a17ae 5351 int idx_number = 3;
d7c0a89a 5352 uint32_t rmap_delay_timer;
d62a17ae 5353
5354 if (argv[idx_number]->arg) {
5355 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5356 bm->rmap_update_timer = rmap_delay_timer;
5357
5358 /* if the dynamic update handling is being disabled, and a timer
5359 * is
5360 * running, stop the timer and act as if the timer has already
5361 * fired.
5362 */
5363 if (!rmap_delay_timer && bm->t_rmap_update) {
5364 BGP_TIMER_OFF(bm->t_rmap_update);
5365 thread_execute(bm->master, bgp_route_map_update_timer,
5366 NULL, 0);
5367 }
5368 return CMD_SUCCESS;
5369 } else {
5370 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5371 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5372 }
518f0eb1
DS
5373}
5374
5375DEFUN (no_bgp_set_route_map_delay_timer,
5376 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5377 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5378 NO_STR
3a2d747c 5379 BGP_STR
518f0eb1 5380 "Default BGP route-map delay timer\n"
8334fd5a
DW
5381 "Reset to default time to wait for processing route-map changes\n"
5382 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5383{
518f0eb1 5384
d62a17ae 5385 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5386
d62a17ae 5387 return CMD_SUCCESS;
518f0eb1
DS
5388}
5389
f414725f 5390
718e3744 5391/* neighbor interface */
d62a17ae 5392static int peer_interface_vty(struct vty *vty, const char *ip_str,
5393 const char *str)
718e3744 5394{
d62a17ae 5395 struct peer *peer;
718e3744 5396
d62a17ae 5397 peer = peer_lookup_vty(vty, ip_str);
5398 if (!peer || peer->conf_if) {
5399 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5400 return CMD_WARNING_CONFIG_FAILED;
5401 }
718e3744 5402
d62a17ae 5403 if (str)
5404 peer_interface_set(peer, str);
5405 else
5406 peer_interface_unset(peer);
718e3744 5407
d62a17ae 5408 return CMD_SUCCESS;
718e3744 5409}
5410
5411DEFUN (neighbor_interface,
5412 neighbor_interface_cmd,
9ccf14f7 5413 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5414 NEIGHBOR_STR
5415 NEIGHBOR_ADDR_STR
5416 "Interface\n"
5417 "Interface name\n")
5418{
d62a17ae 5419 int idx_ip = 1;
5420 int idx_word = 3;
5421 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5422}
5423
5424DEFUN (no_neighbor_interface,
5425 no_neighbor_interface_cmd,
9ccf14f7 5426 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5427 NO_STR
5428 NEIGHBOR_STR
16cedbb0 5429 NEIGHBOR_ADDR_STR2
718e3744 5430 "Interface\n"
5431 "Interface name\n")
5432{
d62a17ae 5433 int idx_peer = 2;
5434 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5435}
6b0655a2 5436
718e3744 5437DEFUN (neighbor_distribute_list,
5438 neighbor_distribute_list_cmd,
9ccf14f7 5439 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5440 NEIGHBOR_STR
5441 NEIGHBOR_ADDR_STR2
5442 "Filter updates to/from this neighbor\n"
5443 "IP access-list number\n"
5444 "IP access-list number (expanded range)\n"
5445 "IP Access-list name\n"
5446 "Filter incoming updates\n"
5447 "Filter outgoing updates\n")
5448{
d62a17ae 5449 int idx_peer = 1;
5450 int idx_acl = 3;
5451 int direct, ret;
5452 struct peer *peer;
a8206004 5453
d62a17ae 5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *acl = argv[idx_acl]->arg;
5456 const char *inout = argv[argc - 1]->text;
a8206004 5457
d62a17ae 5458 peer = peer_and_group_lookup_vty(vty, pstr);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
a8206004 5461
d62a17ae 5462 /* Check filter direction. */
5463 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5464 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5465 direct, acl);
a8206004 5466
d62a17ae 5467 return bgp_vty_return(vty, ret);
718e3744 5468}
5469
d62a17ae 5470ALIAS_HIDDEN(
5471 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5472 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5473 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5474 "Filter updates to/from this neighbor\n"
5475 "IP access-list number\n"
5476 "IP access-list number (expanded range)\n"
5477 "IP Access-list name\n"
5478 "Filter incoming updates\n"
5479 "Filter outgoing updates\n")
596c17ba 5480
718e3744 5481DEFUN (no_neighbor_distribute_list,
5482 no_neighbor_distribute_list_cmd,
9ccf14f7 5483 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5484 NO_STR
5485 NEIGHBOR_STR
5486 NEIGHBOR_ADDR_STR2
5487 "Filter updates to/from this neighbor\n"
5488 "IP access-list number\n"
5489 "IP access-list number (expanded range)\n"
5490 "IP Access-list name\n"
5491 "Filter incoming updates\n"
5492 "Filter outgoing updates\n")
5493{
d62a17ae 5494 int idx_peer = 2;
5495 int direct, ret;
5496 struct peer *peer;
a8206004 5497
d62a17ae 5498 const char *pstr = argv[idx_peer]->arg;
5499 const char *inout = argv[argc - 1]->text;
a8206004 5500
d62a17ae 5501 peer = peer_and_group_lookup_vty(vty, pstr);
5502 if (!peer)
5503 return CMD_WARNING_CONFIG_FAILED;
a8206004 5504
d62a17ae 5505 /* Check filter direction. */
5506 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5507 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5508 direct);
a8206004 5509
d62a17ae 5510 return bgp_vty_return(vty, ret);
718e3744 5511}
6b0655a2 5512
d62a17ae 5513ALIAS_HIDDEN(
5514 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5515 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5516 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5517 "Filter updates to/from this neighbor\n"
5518 "IP access-list number\n"
5519 "IP access-list number (expanded range)\n"
5520 "IP Access-list name\n"
5521 "Filter incoming updates\n"
5522 "Filter outgoing updates\n")
596c17ba 5523
718e3744 5524/* Set prefix list to the peer. */
d62a17ae 5525static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5526 afi_t afi, safi_t safi,
5527 const char *name_str,
5528 const char *direct_str)
718e3744 5529{
d62a17ae 5530 int ret;
d62a17ae 5531 int direct = FILTER_IN;
cf9ac8bf 5532 struct peer *peer;
718e3744 5533
d62a17ae 5534 peer = peer_and_group_lookup_vty(vty, ip_str);
5535 if (!peer)
5536 return CMD_WARNING_CONFIG_FAILED;
718e3744 5537
d62a17ae 5538 /* Check filter direction. */
5539 if (strncmp(direct_str, "i", 1) == 0)
5540 direct = FILTER_IN;
5541 else if (strncmp(direct_str, "o", 1) == 0)
5542 direct = FILTER_OUT;
718e3744 5543
d62a17ae 5544 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5545
d62a17ae 5546 return bgp_vty_return(vty, ret);
718e3744 5547}
5548
d62a17ae 5549static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5550 afi_t afi, safi_t safi,
5551 const char *direct_str)
718e3744 5552{
d62a17ae 5553 int ret;
5554 struct peer *peer;
5555 int direct = FILTER_IN;
718e3744 5556
d62a17ae 5557 peer = peer_and_group_lookup_vty(vty, ip_str);
5558 if (!peer)
5559 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5560
d62a17ae 5561 /* Check filter direction. */
5562 if (strncmp(direct_str, "i", 1) == 0)
5563 direct = FILTER_IN;
5564 else if (strncmp(direct_str, "o", 1) == 0)
5565 direct = FILTER_OUT;
718e3744 5566
d62a17ae 5567 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5568
d62a17ae 5569 return bgp_vty_return(vty, ret);
718e3744 5570}
5571
5572DEFUN (neighbor_prefix_list,
5573 neighbor_prefix_list_cmd,
9ccf14f7 5574 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5575 NEIGHBOR_STR
5576 NEIGHBOR_ADDR_STR2
5577 "Filter updates to/from this neighbor\n"
5578 "Name of a prefix list\n"
5579 "Filter incoming updates\n"
5580 "Filter outgoing updates\n")
5581{
d62a17ae 5582 int idx_peer = 1;
5583 int idx_word = 3;
5584 int idx_in_out = 4;
5585 return peer_prefix_list_set_vty(
5586 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5587 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5588}
5589
d62a17ae 5590ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5592 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Filter updates to/from this neighbor\n"
5594 "Name of a prefix list\n"
5595 "Filter incoming updates\n"
5596 "Filter outgoing updates\n")
596c17ba 5597
718e3744 5598DEFUN (no_neighbor_prefix_list,
5599 no_neighbor_prefix_list_cmd,
9ccf14f7 5600 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5601 NO_STR
5602 NEIGHBOR_STR
5603 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")
5608{
d62a17ae 5609 int idx_peer = 2;
5610 int idx_in_out = 5;
5611 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5612 bgp_node_afi(vty), bgp_node_safi(vty),
5613 argv[idx_in_out]->arg);
718e3744 5614}
6b0655a2 5615
d62a17ae 5616ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5617 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5618 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Filter updates to/from this neighbor\n"
5620 "Name of a prefix list\n"
5621 "Filter incoming updates\n"
5622 "Filter outgoing updates\n")
596c17ba 5623
d62a17ae 5624static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5625 safi_t safi, const char *name_str,
5626 const char *direct_str)
718e3744 5627{
d62a17ae 5628 int ret;
5629 struct peer *peer;
5630 int direct = FILTER_IN;
718e3744 5631
d62a17ae 5632 peer = peer_and_group_lookup_vty(vty, ip_str);
5633 if (!peer)
5634 return CMD_WARNING_CONFIG_FAILED;
718e3744 5635
d62a17ae 5636 /* Check filter direction. */
5637 if (strncmp(direct_str, "i", 1) == 0)
5638 direct = FILTER_IN;
5639 else if (strncmp(direct_str, "o", 1) == 0)
5640 direct = FILTER_OUT;
718e3744 5641
d62a17ae 5642 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5643
d62a17ae 5644 return bgp_vty_return(vty, ret);
718e3744 5645}
5646
d62a17ae 5647static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5648 safi_t safi, const char *direct_str)
718e3744 5649{
d62a17ae 5650 int ret;
5651 struct peer *peer;
5652 int direct = FILTER_IN;
718e3744 5653
d62a17ae 5654 peer = peer_and_group_lookup_vty(vty, ip_str);
5655 if (!peer)
5656 return CMD_WARNING_CONFIG_FAILED;
718e3744 5657
d62a17ae 5658 /* Check filter direction. */
5659 if (strncmp(direct_str, "i", 1) == 0)
5660 direct = FILTER_IN;
5661 else if (strncmp(direct_str, "o", 1) == 0)
5662 direct = FILTER_OUT;
718e3744 5663
d62a17ae 5664 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5665
d62a17ae 5666 return bgp_vty_return(vty, ret);
718e3744 5667}
5668
5669DEFUN (neighbor_filter_list,
5670 neighbor_filter_list_cmd,
9ccf14f7 5671 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5672 NEIGHBOR_STR
5673 NEIGHBOR_ADDR_STR2
5674 "Establish BGP filters\n"
5675 "AS path access-list name\n"
5676 "Filter incoming routes\n"
5677 "Filter outgoing routes\n")
5678{
d62a17ae 5679 int idx_peer = 1;
5680 int idx_word = 3;
5681 int idx_in_out = 4;
5682 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5683 bgp_node_safi(vty), argv[idx_word]->arg,
5684 argv[idx_in_out]->arg);
718e3744 5685}
5686
d62a17ae 5687ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5688 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5689 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Establish BGP filters\n"
5691 "AS path access-list name\n"
5692 "Filter incoming routes\n"
5693 "Filter outgoing routes\n")
596c17ba 5694
718e3744 5695DEFUN (no_neighbor_filter_list,
5696 no_neighbor_filter_list_cmd,
9ccf14f7 5697 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5698 NO_STR
5699 NEIGHBOR_STR
5700 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")
5705{
d62a17ae 5706 int idx_peer = 2;
5707 int idx_in_out = 5;
5708 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5709 bgp_node_afi(vty), bgp_node_safi(vty),
5710 argv[idx_in_out]->arg);
718e3744 5711}
6b0655a2 5712
d62a17ae 5713ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5714 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Establish BGP filters\n"
5717 "AS path access-list name\n"
5718 "Filter incoming routes\n"
5719 "Filter outgoing routes\n")
596c17ba 5720
718e3744 5721/* Set route-map to the peer. */
d62a17ae 5722static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5723 afi_t afi, safi_t safi, const char *name_str,
5724 const char *direct_str)
718e3744 5725{
d62a17ae 5726 int ret;
5727 struct peer *peer;
5728 int direct = RMAP_IN;
1de27621 5729 struct route_map *route_map;
718e3744 5730
d62a17ae 5731 peer = peer_and_group_lookup_vty(vty, ip_str);
5732 if (!peer)
5733 return CMD_WARNING_CONFIG_FAILED;
718e3744 5734
d62a17ae 5735 /* Check filter direction. */
5736 if (strncmp(direct_str, "in", 2) == 0)
5737 direct = RMAP_IN;
5738 else if (strncmp(direct_str, "o", 1) == 0)
5739 direct = RMAP_OUT;
718e3744 5740
1de27621
DA
5741 route_map = route_map_lookup_warn_noexist(vty, name_str);
5742 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5743
d62a17ae 5744 return bgp_vty_return(vty, ret);
718e3744 5745}
5746
d62a17ae 5747static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi,
5749 const char *direct_str)
718e3744 5750{
d62a17ae 5751 int ret;
5752 struct peer *peer;
5753 int direct = RMAP_IN;
718e3744 5754
d62a17ae 5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
718e3744 5758
d62a17ae 5759 /* Check filter direction. */
5760 if (strncmp(direct_str, "in", 2) == 0)
5761 direct = RMAP_IN;
5762 else if (strncmp(direct_str, "o", 1) == 0)
5763 direct = RMAP_OUT;
718e3744 5764
d62a17ae 5765 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5766
d62a17ae 5767 return bgp_vty_return(vty, ret);
718e3744 5768}
5769
5770DEFUN (neighbor_route_map,
5771 neighbor_route_map_cmd,
9ccf14f7 5772 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5773 NEIGHBOR_STR
5774 NEIGHBOR_ADDR_STR2
5775 "Apply route map to neighbor\n"
5776 "Name of route map\n"
5777 "Apply map to incoming routes\n"
2a3d5731 5778 "Apply map to outbound routes\n")
718e3744 5779{
d62a17ae 5780 int idx_peer = 1;
5781 int idx_word = 3;
5782 int idx_in_out = 4;
5783 return peer_route_map_set_vty(
5784 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5785 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5786}
5787
d62a17ae 5788ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5790 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5791 "Apply route map to neighbor\n"
5792 "Name of route map\n"
5793 "Apply map to incoming routes\n"
5794 "Apply map to outbound routes\n")
596c17ba 5795
718e3744 5796DEFUN (no_neighbor_route_map,
5797 no_neighbor_route_map_cmd,
9ccf14f7 5798 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5799 NO_STR
5800 NEIGHBOR_STR
5801 NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
2a3d5731 5805 "Apply map to outbound routes\n")
718e3744 5806{
d62a17ae 5807 int idx_peer = 2;
5808 int idx_in_out = 5;
5809 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5810 bgp_node_afi(vty), bgp_node_safi(vty),
5811 argv[idx_in_out]->arg);
718e3744 5812}
6b0655a2 5813
d62a17ae 5814ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5815 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Apply route map to neighbor\n"
5818 "Name of route map\n"
5819 "Apply map to incoming routes\n"
5820 "Apply map to outbound routes\n")
596c17ba 5821
718e3744 5822/* Set unsuppress-map to the peer. */
d62a17ae 5823static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5824 afi_t afi, safi_t safi,
5825 const char *name_str)
718e3744 5826{
d62a17ae 5827 int ret;
5828 struct peer *peer;
1de27621 5829 struct route_map *route_map;
718e3744 5830
d62a17ae 5831 peer = peer_and_group_lookup_vty(vty, ip_str);
5832 if (!peer)
5833 return CMD_WARNING_CONFIG_FAILED;
718e3744 5834
1de27621
DA
5835 route_map = route_map_lookup_warn_noexist(vty, name_str);
5836 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5837
d62a17ae 5838 return bgp_vty_return(vty, ret);
718e3744 5839}
5840
5841/* Unset route-map from the peer. */
d62a17ae 5842static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5843 afi_t afi, safi_t safi)
718e3744 5844{
d62a17ae 5845 int ret;
5846 struct peer *peer;
718e3744 5847
d62a17ae 5848 peer = peer_and_group_lookup_vty(vty, ip_str);
5849 if (!peer)
5850 return CMD_WARNING_CONFIG_FAILED;
718e3744 5851
d62a17ae 5852 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5853
d62a17ae 5854 return bgp_vty_return(vty, ret);
718e3744 5855}
5856
5857DEFUN (neighbor_unsuppress_map,
5858 neighbor_unsuppress_map_cmd,
9ccf14f7 5859 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5860 NEIGHBOR_STR
5861 NEIGHBOR_ADDR_STR2
5862 "Route-map to selectively unsuppress suppressed routes\n"
5863 "Name of route map\n")
5864{
d62a17ae 5865 int idx_peer = 1;
5866 int idx_word = 3;
5867 return peer_unsuppress_map_set_vty(
5868 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5869 argv[idx_word]->arg);
718e3744 5870}
5871
d62a17ae 5872ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5875 "Route-map to selectively unsuppress suppressed routes\n"
5876 "Name of route map\n")
596c17ba 5877
718e3744 5878DEFUN (no_neighbor_unsuppress_map,
5879 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Route-map to selectively unsuppress suppressed routes\n"
5885 "Name of route map\n")
5886{
d62a17ae 5887 int idx_peer = 2;
5888 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5889 bgp_node_afi(vty),
5890 bgp_node_safi(vty));
718e3744 5891}
6b0655a2 5892
d62a17ae 5893ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5894 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5895 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5896 "Route-map to selectively unsuppress suppressed routes\n"
5897 "Name of route map\n")
596c17ba 5898
d62a17ae 5899static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5900 afi_t afi, safi_t safi,
5901 const char *num_str,
5902 const char *threshold_str, int warning,
5903 const char *restart_str)
718e3744 5904{
d62a17ae 5905 int ret;
5906 struct peer *peer;
d7c0a89a
QY
5907 uint32_t max;
5908 uint8_t threshold;
5909 uint16_t restart;
718e3744 5910
d62a17ae 5911 peer = peer_and_group_lookup_vty(vty, ip_str);
5912 if (!peer)
5913 return CMD_WARNING_CONFIG_FAILED;
718e3744 5914
d62a17ae 5915 max = strtoul(num_str, NULL, 10);
5916 if (threshold_str)
5917 threshold = atoi(threshold_str);
5918 else
5919 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5920
d62a17ae 5921 if (restart_str)
5922 restart = atoi(restart_str);
5923 else
5924 restart = 0;
0a486e5f 5925
d62a17ae 5926 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5927 restart);
718e3744 5928
d62a17ae 5929 return bgp_vty_return(vty, ret);
718e3744 5930}
5931
d62a17ae 5932static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5933 afi_t afi, safi_t safi)
718e3744 5934{
d62a17ae 5935 int ret;
5936 struct peer *peer;
718e3744 5937
d62a17ae 5938 peer = peer_and_group_lookup_vty(vty, ip_str);
5939 if (!peer)
5940 return CMD_WARNING_CONFIG_FAILED;
718e3744 5941
d62a17ae 5942 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5943
d62a17ae 5944 return bgp_vty_return(vty, ret);
718e3744 5945}
5946
5947/* Maximum number of prefix configuration. prefix count is different
5948 for each peer configuration. So this configuration can be set for
5949 each peer configuration. */
5950DEFUN (neighbor_maximum_prefix,
5951 neighbor_maximum_prefix_cmd,
9ccf14f7 5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Maximum number of prefix accept from this peer\n"
5956 "maximum no. of prefix limit\n")
5957{
d62a17ae 5958 int idx_peer = 1;
5959 int idx_number = 3;
5960 return peer_maximum_prefix_set_vty(
5961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5962 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5963}
5964
d62a17ae 5965ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5966 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5967 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5968 "Maximum number of prefix accept from this peer\n"
5969 "maximum no. of prefix limit\n")
596c17ba 5970
e0701b79 5971DEFUN (neighbor_maximum_prefix_threshold,
5972 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5973 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "Maximum number of prefix accept from this peer\n"
5977 "maximum no. of prefix limit\n"
5978 "Threshold value (%) at which to generate a warning msg\n")
5979{
d62a17ae 5980 int idx_peer = 1;
5981 int idx_number = 3;
5982 int idx_number_2 = 4;
5983 return peer_maximum_prefix_set_vty(
5984 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5985 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5986}
e0701b79 5987
d62a17ae 5988ALIAS_HIDDEN(
5989 neighbor_maximum_prefix_threshold,
5990 neighbor_maximum_prefix_threshold_hidden_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n"
5995 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5996
718e3744 5997DEFUN (neighbor_maximum_prefix_warning,
5998 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6000 NEIGHBOR_STR
6001 NEIGHBOR_ADDR_STR2
6002 "Maximum number of prefix accept from this peer\n"
6003 "maximum no. of prefix limit\n"
6004 "Only give warning message when limit is exceeded\n")
6005{
d62a17ae 6006 int idx_peer = 1;
6007 int idx_number = 3;
6008 return peer_maximum_prefix_set_vty(
6009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6010 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6011}
6012
d62a17ae 6013ALIAS_HIDDEN(
6014 neighbor_maximum_prefix_warning,
6015 neighbor_maximum_prefix_warning_hidden_cmd,
6016 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6018 "Maximum number of prefix accept from this peer\n"
6019 "maximum no. of prefix limit\n"
6020 "Only give warning message when limit is exceeded\n")
596c17ba 6021
e0701b79 6022DEFUN (neighbor_maximum_prefix_threshold_warning,
6023 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6024 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Maximum number of prefix accept from this peer\n"
6028 "maximum no. of prefix limit\n"
6029 "Threshold value (%) at which to generate a warning msg\n"
6030 "Only give warning message when limit is exceeded\n")
6031{
d62a17ae 6032 int idx_peer = 1;
6033 int idx_number = 3;
6034 int idx_number_2 = 4;
6035 return peer_maximum_prefix_set_vty(
6036 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6037 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6038}
6039
d62a17ae 6040ALIAS_HIDDEN(
6041 neighbor_maximum_prefix_threshold_warning,
6042 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6043 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6045 "Maximum number of prefix accept from this peer\n"
6046 "maximum no. of prefix limit\n"
6047 "Threshold value (%) at which to generate a warning msg\n"
6048 "Only give warning message when limit is exceeded\n")
596c17ba 6049
0a486e5f 6050DEFUN (neighbor_maximum_prefix_restart,
6051 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6052 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Maximum number of prefix accept from this peer\n"
6056 "maximum no. of prefix limit\n"
6057 "Restart bgp connection after limit is exceeded\n"
efd7904e 6058 "Restart interval in minutes\n")
0a486e5f 6059{
d62a17ae 6060 int idx_peer = 1;
6061 int idx_number = 3;
6062 int idx_number_2 = 5;
6063 return peer_maximum_prefix_set_vty(
6064 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6065 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6066}
6067
d62a17ae 6068ALIAS_HIDDEN(
6069 neighbor_maximum_prefix_restart,
6070 neighbor_maximum_prefix_restart_hidden_cmd,
6071 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6072 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6073 "Maximum number of prefix accept from this peer\n"
6074 "maximum no. of prefix limit\n"
6075 "Restart bgp connection after limit is exceeded\n"
efd7904e 6076 "Restart interval in minutes\n")
596c17ba 6077
0a486e5f 6078DEFUN (neighbor_maximum_prefix_threshold_restart,
6079 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6080 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6081 NEIGHBOR_STR
6082 NEIGHBOR_ADDR_STR2
16cedbb0 6083 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6084 "maximum no. of prefix limit\n"
6085 "Threshold value (%) at which to generate a warning msg\n"
6086 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6087 "Restart interval in minutes\n")
0a486e5f 6088{
d62a17ae 6089 int idx_peer = 1;
6090 int idx_number = 3;
6091 int idx_number_2 = 4;
6092 int idx_number_3 = 6;
6093 return peer_maximum_prefix_set_vty(
6094 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6095 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6096 argv[idx_number_3]->arg);
6097}
6098
6099ALIAS_HIDDEN(
6100 neighbor_maximum_prefix_threshold_restart,
6101 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6102 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6104 "Maximum number of prefixes to accept from this peer\n"
6105 "maximum no. of prefix limit\n"
6106 "Threshold value (%) at which to generate a warning msg\n"
6107 "Restart bgp connection after limit is exceeded\n"
6108 "Restart interval in minutes\n")
596c17ba 6109
718e3744 6110DEFUN (no_neighbor_maximum_prefix,
6111 no_neighbor_maximum_prefix_cmd,
d04c479d 6112 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6113 NO_STR
6114 NEIGHBOR_STR
6115 NEIGHBOR_ADDR_STR2
16cedbb0 6116 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6117 "maximum no. of prefix limit\n"
6118 "Threshold value (%) at which to generate a warning msg\n"
6119 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6120 "Restart interval in minutes\n"
31500417 6121 "Only give warning message when limit is exceeded\n")
718e3744 6122{
d62a17ae 6123 int idx_peer = 2;
6124 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6125 bgp_node_afi(vty),
6126 bgp_node_safi(vty));
718e3744 6127}
e52702f2 6128
d62a17ae 6129ALIAS_HIDDEN(
6130 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Maximum number of prefixes to accept from this peer\n"
6134 "maximum no. of prefix limit\n"
6135 "Threshold value (%) at which to generate a warning msg\n"
6136 "Restart bgp connection after limit is exceeded\n"
6137 "Restart interval in minutes\n"
6138 "Only give warning message when limit is exceeded\n")
596c17ba 6139
718e3744 6140
718e3744 6141/* "neighbor allowas-in" */
6142DEFUN (neighbor_allowas_in,
6143 neighbor_allowas_in_cmd,
fd8503f5 6144 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
31500417 6147 "Accept as-path with my AS present in it\n"
0437e105 6148 "Number of occurences of AS number\n"
fd8503f5 6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6150{
d62a17ae 6151 int idx_peer = 1;
6152 int idx_number_origin = 3;
6153 int ret;
6154 int origin = 0;
6155 struct peer *peer;
6156 int allow_num = 0;
6157
6158 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6159 if (!peer)
6160 return CMD_WARNING_CONFIG_FAILED;
6161
6162 if (argc <= idx_number_origin)
6163 allow_num = 3;
6164 else {
6165 if (argv[idx_number_origin]->type == WORD_TKN)
6166 origin = 1;
6167 else
6168 allow_num = atoi(argv[idx_number_origin]->arg);
6169 }
6170
6171 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6172 allow_num, origin);
6173
6174 return bgp_vty_return(vty, ret);
6175}
6176
6177ALIAS_HIDDEN(
6178 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6179 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6180 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6181 "Accept as-path with my AS present in it\n"
0437e105 6182 "Number of occurences of AS number\n"
d62a17ae 6183 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6184
718e3744 6185DEFUN (no_neighbor_allowas_in,
6186 no_neighbor_allowas_in_cmd,
fd8503f5 6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6188 NO_STR
6189 NEIGHBOR_STR
6190 NEIGHBOR_ADDR_STR2
8334fd5a 6191 "allow local ASN appears in aspath attribute\n"
0437e105 6192 "Number of occurences of AS number\n"
fd8503f5 6193 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6194{
d62a17ae 6195 int idx_peer = 2;
6196 int ret;
6197 struct peer *peer;
718e3744 6198
d62a17ae 6199 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6200 if (!peer)
6201 return CMD_WARNING_CONFIG_FAILED;
718e3744 6202
d62a17ae 6203 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6204 bgp_node_safi(vty));
718e3744 6205
d62a17ae 6206 return bgp_vty_return(vty, ret);
718e3744 6207}
6b0655a2 6208
d62a17ae 6209ALIAS_HIDDEN(
6210 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6211 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6213 "allow local ASN appears in aspath attribute\n"
0437e105 6214 "Number of occurences of AS number\n"
d62a17ae 6215 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6216
fa411a21
NH
6217DEFUN (neighbor_ttl_security,
6218 neighbor_ttl_security_cmd,
7ebe625c 6219 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6220 NEIGHBOR_STR
7ebe625c 6221 NEIGHBOR_ADDR_STR2
16cedbb0 6222 "BGP ttl-security parameters\n"
d7fa34c1
QY
6223 "Specify the maximum number of hops to the BGP peer\n"
6224 "Number of hops to BGP peer\n")
fa411a21 6225{
d62a17ae 6226 int idx_peer = 1;
6227 int idx_number = 4;
6228 struct peer *peer;
6229 int gtsm_hops;
6230
6231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6236
7ebe625c
QY
6237 /*
6238 * If 'neighbor swpX', then this is for directly connected peers,
6239 * we should not accept a ttl-security hops value greater than 1.
6240 */
6241 if (peer->conf_if && (gtsm_hops > 1)) {
6242 vty_out(vty,
6243 "%s is directly connected peer, hops cannot exceed 1\n",
6244 argv[idx_peer]->arg);
6245 return CMD_WARNING_CONFIG_FAILED;
6246 }
6247
d62a17ae 6248 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6249}
6250
6251DEFUN (no_neighbor_ttl_security,
6252 no_neighbor_ttl_security_cmd,
7ebe625c 6253 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6254 NO_STR
6255 NEIGHBOR_STR
7ebe625c 6256 NEIGHBOR_ADDR_STR2
16cedbb0 6257 "BGP ttl-security parameters\n"
3a2d747c
QY
6258 "Specify the maximum number of hops to the BGP peer\n"
6259 "Number of hops to BGP peer\n")
fa411a21 6260{
d62a17ae 6261 int idx_peer = 2;
6262 struct peer *peer;
fa411a21 6263
d62a17ae 6264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6265 if (!peer)
6266 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6267
d62a17ae 6268 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6269}
6b0655a2 6270
adbac85e
DW
6271DEFUN (neighbor_addpath_tx_all_paths,
6272 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6273 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6274 NEIGHBOR_STR
6275 NEIGHBOR_ADDR_STR2
6276 "Use addpath to advertise all paths to a neighbor\n")
6277{
d62a17ae 6278 int idx_peer = 1;
6279 struct peer *peer;
adbac85e 6280
d62a17ae 6281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6282 if (!peer)
6283 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6284
dcc68b5e
MS
6285 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6286 BGP_ADDPATH_ALL);
6287 return CMD_SUCCESS;
adbac85e
DW
6288}
6289
d62a17ae 6290ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6291 neighbor_addpath_tx_all_paths_hidden_cmd,
6292 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6294 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6295
adbac85e
DW
6296DEFUN (no_neighbor_addpath_tx_all_paths,
6297 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6298 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6299 NO_STR
6300 NEIGHBOR_STR
6301 NEIGHBOR_ADDR_STR2
6302 "Use addpath to advertise all paths to a neighbor\n")
6303{
d62a17ae 6304 int idx_peer = 2;
dcc68b5e
MS
6305 struct peer *peer;
6306
6307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6308 if (!peer)
6309 return CMD_WARNING_CONFIG_FAILED;
6310
6311 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6312 != BGP_ADDPATH_ALL) {
6313 vty_out(vty,
6314 "%% Peer not currently configured to transmit all paths.");
6315 return CMD_WARNING_CONFIG_FAILED;
6316 }
6317
6318 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6319 BGP_ADDPATH_NONE);
6320
6321 return CMD_SUCCESS;
adbac85e
DW
6322}
6323
d62a17ae 6324ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6325 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6326 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6328 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6329
06370dac
DW
6330DEFUN (neighbor_addpath_tx_bestpath_per_as,
6331 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6333 NEIGHBOR_STR
6334 NEIGHBOR_ADDR_STR2
6335 "Use addpath to advertise the bestpath per each neighboring AS\n")
6336{
d62a17ae 6337 int idx_peer = 1;
6338 struct peer *peer;
06370dac 6339
d62a17ae 6340 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6341 if (!peer)
6342 return CMD_WARNING_CONFIG_FAILED;
06370dac 6343
dcc68b5e
MS
6344 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6345 BGP_ADDPATH_BEST_PER_AS);
6346
6347 return CMD_SUCCESS;
06370dac
DW
6348}
6349
d62a17ae 6350ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6351 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6352 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6355
06370dac
DW
6356DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6357 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6358 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6359 NO_STR
6360 NEIGHBOR_STR
6361 NEIGHBOR_ADDR_STR2
6362 "Use addpath to advertise the bestpath per each neighboring AS\n")
6363{
d62a17ae 6364 int idx_peer = 2;
dcc68b5e
MS
6365 struct peer *peer;
6366
6367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6368 if (!peer)
6369 return CMD_WARNING_CONFIG_FAILED;
6370
6371 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6372 != BGP_ADDPATH_BEST_PER_AS) {
6373 vty_out(vty,
6374 "%% Peer not currently configured to transmit all best path per as.");
6375 return CMD_WARNING_CONFIG_FAILED;
6376 }
6377
6378 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6379 BGP_ADDPATH_NONE);
6380
6381 return CMD_SUCCESS;
06370dac
DW
6382}
6383
d62a17ae 6384ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6385 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6386 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6387 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6388 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6389
b9c7bc5a
PZ
6390static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6391 struct ecommunity **list)
ddb5b488 6392{
b9c7bc5a
PZ
6393 struct ecommunity *ecom = NULL;
6394 struct ecommunity *ecomadd;
ddb5b488 6395
b9c7bc5a 6396 for (; argc; --argc, ++argv) {
ddb5b488 6397
b9c7bc5a
PZ
6398 ecomadd = ecommunity_str2com(argv[0]->arg,
6399 ECOMMUNITY_ROUTE_TARGET, 0);
6400 if (!ecomadd) {
6401 vty_out(vty, "Malformed community-list value\n");
6402 if (ecom)
6403 ecommunity_free(&ecom);
6404 return CMD_WARNING_CONFIG_FAILED;
6405 }
ddb5b488 6406
b9c7bc5a
PZ
6407 if (ecom) {
6408 ecommunity_merge(ecom, ecomadd);
6409 ecommunity_free(&ecomadd);
6410 } else {
6411 ecom = ecomadd;
6412 }
6413 }
6414
6415 if (*list) {
6416 ecommunity_free(&*list);
ddb5b488 6417 }
b9c7bc5a
PZ
6418 *list = ecom;
6419
6420 return CMD_SUCCESS;
ddb5b488
PZ
6421}
6422
0ca70ba5
DS
6423/*
6424 * v2vimport is true if we are handling a `import vrf ...` command
6425 */
6426static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6427{
0ca70ba5
DS
6428 afi_t afi;
6429
ddb5b488 6430 switch (vty->node) {
b9c7bc5a 6431 case BGP_IPV4_NODE:
0ca70ba5
DS
6432 afi = AFI_IP;
6433 break;
b9c7bc5a 6434 case BGP_IPV6_NODE:
0ca70ba5
DS
6435 afi = AFI_IP6;
6436 break;
ddb5b488
PZ
6437 default:
6438 vty_out(vty,
b9c7bc5a 6439 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6440 return AFI_MAX;
ddb5b488 6441 }
69b07479 6442
0ca70ba5
DS
6443 if (!v2vimport) {
6444 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6445 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6446 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6447 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6448 vty_out(vty,
6449 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6450 return AFI_MAX;
6451 }
6452 } else {
6453 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6454 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6455 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6456 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6457 vty_out(vty,
6458 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6459 return AFI_MAX;
6460 }
6461 }
6462 return afi;
ddb5b488
PZ
6463}
6464
b9c7bc5a
PZ
6465DEFPY (af_rd_vpn_export,
6466 af_rd_vpn_export_cmd,
6467 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6468 NO_STR
ddb5b488 6469 "Specify route distinguisher\n"
b9c7bc5a
PZ
6470 "Between current address-family and vpn\n"
6471 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6472 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6473{
6474 VTY_DECLVAR_CONTEXT(bgp, bgp);
6475 struct prefix_rd prd;
6476 int ret;
ddb5b488 6477 afi_t afi;
b9c7bc5a
PZ
6478 int idx = 0;
6479 int yes = 1;
ddb5b488 6480
b9c7bc5a 6481 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6482 yes = 0;
b9c7bc5a
PZ
6483
6484 if (yes) {
6485 ret = str2prefix_rd(rd_str, &prd);
6486 if (!ret) {
6487 vty_out(vty, "%% Malformed rd\n");
6488 return CMD_WARNING_CONFIG_FAILED;
6489 }
ddb5b488
PZ
6490 }
6491
0ca70ba5 6492 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6493 if (afi == AFI_MAX)
6494 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6495
69b07479
DS
6496 /*
6497 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6498 */
6499 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6500 bgp_get_default(), bgp);
ddb5b488 6501
69b07479
DS
6502 if (yes) {
6503 bgp->vpn_policy[afi].tovpn_rd = prd;
6504 SET_FLAG(bgp->vpn_policy[afi].flags,
6505 BGP_VPN_POLICY_TOVPN_RD_SET);
6506 } else {
6507 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6508 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6509 }
6510
69b07479
DS
6511 /* post-change: re-export vpn routes */
6512 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6513 bgp_get_default(), bgp);
6514
ddb5b488
PZ
6515 return CMD_SUCCESS;
6516}
6517
b9c7bc5a
PZ
6518ALIAS (af_rd_vpn_export,
6519 af_no_rd_vpn_export_cmd,
6520 "no rd vpn export",
ddb5b488 6521 NO_STR
b9c7bc5a
PZ
6522 "Specify route distinguisher\n"
6523 "Between current address-family and vpn\n"
6524 "For routes leaked from current address-family to vpn\n")
ddb5b488 6525
b9c7bc5a
PZ
6526DEFPY (af_label_vpn_export,
6527 af_label_vpn_export_cmd,
e70e9f8e 6528 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6529 NO_STR
ddb5b488 6530 "label value for VRF\n"
b9c7bc5a
PZ
6531 "Between current address-family and vpn\n"
6532 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6533 "Label Value <0-1048575>\n"
6534 "Automatically assign a label\n")
ddb5b488
PZ
6535{
6536 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6537 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6538 afi_t afi;
b9c7bc5a
PZ
6539 int idx = 0;
6540 int yes = 1;
6541
6542 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6543 yes = 0;
ddb5b488 6544
21a16cc2
PZ
6545 /* If "no ...", squash trailing parameter */
6546 if (!yes)
6547 label_auto = NULL;
6548
e70e9f8e
PZ
6549 if (yes) {
6550 if (!label_auto)
6551 label = label_val; /* parser should force unsigned */
6552 }
ddb5b488 6553
0ca70ba5 6554 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6555 if (afi == AFI_MAX)
6556 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6557
e70e9f8e 6558
69b07479
DS
6559 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6560 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6561 /* no change */
6562 return CMD_SUCCESS;
e70e9f8e 6563
69b07479
DS
6564 /*
6565 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6566 */
6567 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6568 bgp_get_default(), bgp);
6569
6570 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6571 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6572
6573 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6574
6575 /*
6576 * label has previously been automatically
6577 * assigned by labelpool: release it
6578 *
6579 * NB if tovpn_label == MPLS_LABEL_NONE it
6580 * means the automatic assignment is in flight
6581 * and therefore the labelpool callback must
6582 * detect that the auto label is not needed.
6583 */
6584
6585 bgp_lp_release(LP_TYPE_VRF,
6586 &bgp->vpn_policy[afi],
6587 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6588 }
69b07479
DS
6589 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6590 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6591 }
ddb5b488 6592
69b07479
DS
6593 bgp->vpn_policy[afi].tovpn_label = label;
6594 if (label_auto) {
6595 SET_FLAG(bgp->vpn_policy[afi].flags,
6596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6597 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6598 vpn_leak_label_callback);
ddb5b488
PZ
6599 }
6600
69b07479
DS
6601 /* post-change: re-export vpn routes */
6602 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6603 bgp_get_default(), bgp);
6604
ddb5b488
PZ
6605 return CMD_SUCCESS;
6606}
6607
b9c7bc5a
PZ
6608ALIAS (af_label_vpn_export,
6609 af_no_label_vpn_export_cmd,
6610 "no label vpn export",
6611 NO_STR
6612 "label value for VRF\n"
6613 "Between current address-family and vpn\n"
6614 "For routes leaked from current address-family to vpn\n")
ddb5b488 6615
b9c7bc5a
PZ
6616DEFPY (af_nexthop_vpn_export,
6617 af_nexthop_vpn_export_cmd,
6618 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6619 NO_STR
ddb5b488 6620 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6621 "Between current address-family and vpn\n"
6622 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6623 "IPv4 prefix\n"
6624 "IPv6 prefix\n")
6625{
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6627 afi_t afi;
ddb5b488 6628 struct prefix p;
b9c7bc5a
PZ
6629 int idx = 0;
6630 int yes = 1;
ddb5b488 6631
b9c7bc5a 6632 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6633 yes = 0;
b9c7bc5a
PZ
6634
6635 if (yes) {
6636 if (!sockunion2hostprefix(nexthop_str, &p))
6637 return CMD_WARNING_CONFIG_FAILED;
6638 }
ddb5b488 6639
0ca70ba5 6640 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6641 if (afi == AFI_MAX)
6642 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6643
69b07479
DS
6644 /*
6645 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6646 */
6647 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6648 bgp_get_default(), bgp);
ddb5b488 6649
69b07479
DS
6650 if (yes) {
6651 bgp->vpn_policy[afi].tovpn_nexthop = p;
6652 SET_FLAG(bgp->vpn_policy[afi].flags,
6653 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6654 } else {
6655 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6656 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6657 }
6658
69b07479
DS
6659 /* post-change: re-export vpn routes */
6660 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6661 bgp_get_default(), bgp);
6662
ddb5b488
PZ
6663 return CMD_SUCCESS;
6664}
6665
b9c7bc5a
PZ
6666ALIAS (af_nexthop_vpn_export,
6667 af_no_nexthop_vpn_export_cmd,
6668 "no nexthop vpn export",
ddb5b488 6669 NO_STR
b9c7bc5a
PZ
6670 "Specify next hop to use for VRF advertised prefixes\n"
6671 "Between current address-family and vpn\n"
6672 "For routes leaked from current address-family to vpn\n")
ddb5b488 6673
b9c7bc5a 6674static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6675{
b9c7bc5a
PZ
6676 if (!strcmp(dstr, "import")) {
6677 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6678 } else if (!strcmp(dstr, "export")) {
6679 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6680 } else if (!strcmp(dstr, "both")) {
6681 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6682 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6683 } else {
6684 vty_out(vty, "%% direction parse error\n");
6685 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6686 }
ddb5b488
PZ
6687 return CMD_SUCCESS;
6688}
6689
b9c7bc5a
PZ
6690DEFPY (af_rt_vpn_imexport,
6691 af_rt_vpn_imexport_cmd,
6692 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6693 NO_STR
6694 "Specify route target list\n"
ddb5b488 6695 "Specify route target list\n"
b9c7bc5a
PZ
6696 "Between current address-family and vpn\n"
6697 "For routes leaked from vpn to current address-family: match any\n"
6698 "For routes leaked from current address-family to vpn: set\n"
6699 "both import: match any and export: set\n"
ddb5b488
PZ
6700 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6701{
6702 VTY_DECLVAR_CONTEXT(bgp, bgp);
6703 int ret;
6704 struct ecommunity *ecom = NULL;
6705 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6706 vpn_policy_direction_t dir;
6707 afi_t afi;
6708 int idx = 0;
b9c7bc5a 6709 int yes = 1;
ddb5b488 6710
b9c7bc5a 6711 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6712 yes = 0;
b9c7bc5a 6713
0ca70ba5 6714 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6715 if (afi == AFI_MAX)
6716 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6717
b9c7bc5a 6718 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6719 if (ret != CMD_SUCCESS)
6720 return ret;
6721
b9c7bc5a
PZ
6722 if (yes) {
6723 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6724 vty_out(vty, "%% Missing RTLIST\n");
6725 return CMD_WARNING_CONFIG_FAILED;
6726 }
6727 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6728 if (ret != CMD_SUCCESS) {
6729 return ret;
6730 }
ddb5b488
PZ
6731 }
6732
69b07479
DS
6733 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6734 if (!dodir[dir])
ddb5b488 6735 continue;
ddb5b488 6736
69b07479 6737 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6738
69b07479
DS
6739 if (yes) {
6740 if (bgp->vpn_policy[afi].rtlist[dir])
6741 ecommunity_free(
6742 &bgp->vpn_policy[afi].rtlist[dir]);
6743 bgp->vpn_policy[afi].rtlist[dir] =
6744 ecommunity_dup(ecom);
6745 } else {
6746 if (bgp->vpn_policy[afi].rtlist[dir])
6747 ecommunity_free(
6748 &bgp->vpn_policy[afi].rtlist[dir]);
6749 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6750 }
69b07479
DS
6751
6752 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6753 }
69b07479 6754
d555f3e9
PZ
6755 if (ecom)
6756 ecommunity_free(&ecom);
ddb5b488
PZ
6757
6758 return CMD_SUCCESS;
6759}
6760
b9c7bc5a
PZ
6761ALIAS (af_rt_vpn_imexport,
6762 af_no_rt_vpn_imexport_cmd,
6763 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6764 NO_STR
6765 "Specify route target list\n"
b9c7bc5a
PZ
6766 "Specify route target list\n"
6767 "Between current address-family and vpn\n"
6768 "For routes leaked from vpn to current address-family\n"
6769 "For routes leaked from current address-family to vpn\n"
6770 "both import and export\n")
6771
6772DEFPY (af_route_map_vpn_imexport,
6773 af_route_map_vpn_imexport_cmd,
6774/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6775 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6776 NO_STR
ddb5b488 6777 "Specify route map\n"
b9c7bc5a
PZ
6778 "Between current address-family and vpn\n"
6779 "For routes leaked from vpn to current address-family\n"
6780 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6781 "name of route-map\n")
6782{
6783 VTY_DECLVAR_CONTEXT(bgp, bgp);
6784 int ret;
6785 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6786 vpn_policy_direction_t dir;
6787 afi_t afi;
ddb5b488 6788 int idx = 0;
b9c7bc5a 6789 int yes = 1;
ddb5b488 6790
b9c7bc5a 6791 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6792 yes = 0;
b9c7bc5a 6793
0ca70ba5 6794 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6795 if (afi == AFI_MAX)
6796 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6797
b9c7bc5a 6798 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6799 if (ret != CMD_SUCCESS)
6800 return ret;
6801
69b07479
DS
6802 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6803 if (!dodir[dir])
ddb5b488 6804 continue;
ddb5b488 6805
69b07479 6806 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6807
69b07479
DS
6808 if (yes) {
6809 if (bgp->vpn_policy[afi].rmap_name[dir])
6810 XFREE(MTYPE_ROUTE_MAP_NAME,
6811 bgp->vpn_policy[afi].rmap_name[dir]);
6812 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6813 MTYPE_ROUTE_MAP_NAME, rmap_str);
6814 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6815 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6816 if (!bgp->vpn_policy[afi].rmap[dir])
6817 return CMD_SUCCESS;
6818 } else {
6819 if (bgp->vpn_policy[afi].rmap_name[dir])
6820 XFREE(MTYPE_ROUTE_MAP_NAME,
6821 bgp->vpn_policy[afi].rmap_name[dir]);
6822 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6823 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6824 }
69b07479
DS
6825
6826 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6827 }
6828
6829 return CMD_SUCCESS;
6830}
6831
b9c7bc5a
PZ
6832ALIAS (af_route_map_vpn_imexport,
6833 af_no_route_map_vpn_imexport_cmd,
6834 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6835 NO_STR
6836 "Specify route map\n"
b9c7bc5a
PZ
6837 "Between current address-family and vpn\n"
6838 "For routes leaked from vpn to current address-family\n"
6839 "For routes leaked from current address-family to vpn\n")
6840
bb4f6190
DS
6841DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6842 "[no] import vrf route-map RMAP$rmap_str",
6843 NO_STR
6844 "Import routes from another VRF\n"
6845 "Vrf routes being filtered\n"
6846 "Specify route map\n"
6847 "name of route-map\n")
6848{
6849 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6850 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6851 afi_t afi;
6852 int idx = 0;
6853 int yes = 1;
6854 struct bgp *bgp_default;
6855
6856 if (argv_find(argv, argc, "no", &idx))
6857 yes = 0;
6858
0ca70ba5 6859 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6860 if (afi == AFI_MAX)
6861 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6862
6863 bgp_default = bgp_get_default();
6864 if (!bgp_default) {
6865 int32_t ret;
6866 as_t as = bgp->as;
6867
6868 /* Auto-create assuming the same AS */
6869 ret = bgp_get(&bgp_default, &as, NULL,
6870 BGP_INSTANCE_TYPE_DEFAULT);
6871
6872 if (ret) {
6873 vty_out(vty,
6874 "VRF default is not configured as a bgp instance\n");
6875 return CMD_WARNING;
6876 }
6877 }
6878
69b07479 6879 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6880
69b07479
DS
6881 if (yes) {
6882 if (bgp->vpn_policy[afi].rmap_name[dir])
6883 XFREE(MTYPE_ROUTE_MAP_NAME,
6884 bgp->vpn_policy[afi].rmap_name[dir]);
6885 bgp->vpn_policy[afi].rmap_name[dir] =
6886 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6887 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6888 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6889 if (!bgp->vpn_policy[afi].rmap[dir])
6890 return CMD_SUCCESS;
6891 } else {
6892 if (bgp->vpn_policy[afi].rmap_name[dir])
6893 XFREE(MTYPE_ROUTE_MAP_NAME,
6894 bgp->vpn_policy[afi].rmap_name[dir]);
6895 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6896 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6897 }
6898
69b07479
DS
6899 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6900
bb4f6190
DS
6901 return CMD_SUCCESS;
6902}
6903
6904ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6905 "no import vrf route-map",
6906 NO_STR
6907 "Import routes from another VRF\n"
6908 "Vrf routes being filtered\n"
6909 "Specify route map\n")
6910
4d1b335c
DA
6911DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6912 "[no] import vrf VIEWVRFNAME$import_name",
6913 NO_STR
6914 "Import routes from another VRF\n"
6915 "VRF to import from\n"
6916 "The name of the VRF\n")
12a844a5
DS
6917{
6918 VTY_DECLVAR_CONTEXT(bgp, bgp);
6919 struct listnode *node;
79ef8664
DS
6920 struct bgp *vrf_bgp, *bgp_default;
6921 int32_t ret = 0;
6922 as_t as = bgp->as;
12a844a5
DS
6923 bool remove = false;
6924 int32_t idx = 0;
6925 char *vname;
a8dadcf6 6926 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6927 safi_t safi;
6928 afi_t afi;
6929
867f0cca 6930 if (import_name == NULL) {
6931 vty_out(vty, "%% Missing import name\n");
6932 return CMD_WARNING;
6933 }
6934
12a844a5
DS
6935 if (argv_find(argv, argc, "no", &idx))
6936 remove = true;
6937
0ca70ba5
DS
6938 afi = vpn_policy_getafi(vty, bgp, true);
6939 if (afi == AFI_MAX)
6940 return CMD_WARNING_CONFIG_FAILED;
6941
12a844a5
DS
6942 safi = bgp_node_safi(vty);
6943
25679caa 6944 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6945 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6946 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6947 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6948 remove ? "unimport" : "import", import_name);
6949 return CMD_WARNING;
6950 }
6951
79ef8664
DS
6952 bgp_default = bgp_get_default();
6953 if (!bgp_default) {
6954 /* Auto-create assuming the same AS */
6955 ret = bgp_get(&bgp_default, &as, NULL,
6956 BGP_INSTANCE_TYPE_DEFAULT);
6957
6958 if (ret) {
6959 vty_out(vty,
6960 "VRF default is not configured as a bgp instance\n");
6961 return CMD_WARNING;
6962 }
6963 }
6964
12a844a5
DS
6965 vrf_bgp = bgp_lookup_by_name(import_name);
6966 if (!vrf_bgp) {
5742e42b 6967 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6968 vrf_bgp = bgp_default;
6969 else
0fb8d6e6
DS
6970 /* Auto-create assuming the same AS */
6971 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6972
6e2c7fe6 6973 if (ret) {
020a3f60
DS
6974 vty_out(vty,
6975 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6976 import_name);
6977 return CMD_WARNING;
6978 }
12a844a5
DS
6979 }
6980
12a844a5 6981 if (remove) {
44338987 6982 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6983 } else {
44338987 6984 /* Already importing from "import_vrf"? */
12a844a5
DS
6985 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6986 vname)) {
6987 if (strcmp(vname, import_name) == 0)
6988 return CMD_WARNING;
6989 }
6990
44338987 6991 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6992 }
6993
6994 return CMD_SUCCESS;
6995}
6996
b9c7bc5a
PZ
6997/* This command is valid only in a bgp vrf instance or the default instance */
6998DEFPY (bgp_imexport_vpn,
6999 bgp_imexport_vpn_cmd,
7000 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7001 NO_STR
7002 "Import routes to this address-family\n"
7003 "Export routes from this address-family\n"
7004 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7005{
7006 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7007 int previous_state;
ddb5b488 7008 afi_t afi;
b9c7bc5a 7009 safi_t safi;
ddb5b488 7010 int idx = 0;
b9c7bc5a
PZ
7011 int yes = 1;
7012 int flag;
7013 vpn_policy_direction_t dir;
ddb5b488 7014
b9c7bc5a 7015 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7016 yes = 0;
ddb5b488 7017
b9c7bc5a
PZ
7018 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7019 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7020
b9c7bc5a
PZ
7021 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7022 return CMD_WARNING_CONFIG_FAILED;
7023 }
ddb5b488 7024
b9c7bc5a
PZ
7025 afi = bgp_node_afi(vty);
7026 safi = bgp_node_safi(vty);
7027 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7028 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7029 return CMD_WARNING_CONFIG_FAILED;
7030 }
ddb5b488 7031
b9c7bc5a
PZ
7032 if (!strcmp(direction_str, "import")) {
7033 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7034 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7035 } else if (!strcmp(direction_str, "export")) {
7036 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7037 dir = BGP_VPN_POLICY_DIR_TOVPN;
7038 } else {
7039 vty_out(vty, "%% unknown direction %s\n", direction_str);
7040 return CMD_WARNING_CONFIG_FAILED;
7041 }
7042
7043 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7044
b9c7bc5a
PZ
7045 if (yes) {
7046 SET_FLAG(bgp->af_flags[afi][safi], flag);
7047 if (!previous_state) {
7048 /* trigger export current vrf */
ddb5b488
PZ
7049 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7050 }
b9c7bc5a
PZ
7051 } else {
7052 if (previous_state) {
7053 /* trigger un-export current vrf */
7054 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7055 }
7056 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7057 }
7058
7059 return CMD_SUCCESS;
7060}
7061
301ad80a
PG
7062DEFPY (af_routetarget_import,
7063 af_routetarget_import_cmd,
7064 "[no] <rt|route-target> redirect import RTLIST...",
7065 NO_STR
7066 "Specify route target list\n"
7067 "Specify route target list\n"
7068 "Flow-spec redirect type route target\n"
7069 "Import routes to this address-family\n"
7070 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7071{
7072 VTY_DECLVAR_CONTEXT(bgp, bgp);
7073 int ret;
7074 struct ecommunity *ecom = NULL;
301ad80a
PG
7075 afi_t afi;
7076 int idx = 0;
7077 int yes = 1;
7078
7079 if (argv_find(argv, argc, "no", &idx))
7080 yes = 0;
7081
0ca70ba5 7082 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7083 if (afi == AFI_MAX)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
301ad80a
PG
7086 if (yes) {
7087 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7088 vty_out(vty, "%% Missing RTLIST\n");
7089 return CMD_WARNING_CONFIG_FAILED;
7090 }
7091 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7092 if (ret != CMD_SUCCESS)
7093 return ret;
7094 }
69b07479
DS
7095
7096 if (yes) {
7097 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7098 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7099 .import_redirect_rtlist);
69b07479
DS
7100 bgp->vpn_policy[afi].import_redirect_rtlist =
7101 ecommunity_dup(ecom);
7102 } else {
7103 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7104 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7105 .import_redirect_rtlist);
69b07479 7106 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7107 }
69b07479 7108
301ad80a
PG
7109 if (ecom)
7110 ecommunity_free(&ecom);
7111
7112 return CMD_SUCCESS;
7113}
7114
505e5056 7115DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7116 address_family_ipv4_safi_cmd,
7117 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7118 "Enter Address Family command mode\n"
7119 "Address Family\n"
7120 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7121{
f51bae9c 7122
d62a17ae 7123 if (argc == 3) {
2131d5cf 7124 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7125 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7126 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7127 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7128 && safi != SAFI_EVPN) {
31947174
MK
7129 vty_out(vty,
7130 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7131 return CMD_WARNING_CONFIG_FAILED;
7132 }
d62a17ae 7133 vty->node = bgp_node_type(AFI_IP, safi);
7134 } else
7135 vty->node = BGP_IPV4_NODE;
718e3744 7136
d62a17ae 7137 return CMD_SUCCESS;
718e3744 7138}
7139
505e5056 7140DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7141 address_family_ipv6_safi_cmd,
7142 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7146{
d62a17ae 7147 if (argc == 3) {
2131d5cf 7148 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7149 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7150 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7151 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7152 && safi != SAFI_EVPN) {
31947174
MK
7153 vty_out(vty,
7154 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7155 return CMD_WARNING_CONFIG_FAILED;
7156 }
d62a17ae 7157 vty->node = bgp_node_type(AFI_IP6, safi);
7158 } else
7159 vty->node = BGP_IPV6_NODE;
25ffbdc1 7160
d62a17ae 7161 return CMD_SUCCESS;
25ffbdc1 7162}
718e3744 7163
d6902373 7164#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7165DEFUN_NOSH (address_family_vpnv4,
718e3744 7166 address_family_vpnv4_cmd,
8334fd5a 7167 "address-family vpnv4 [unicast]",
718e3744 7168 "Enter Address Family command mode\n"
8c3deaae 7169 "Address Family\n"
3a2d747c 7170 "Address Family modifier\n")
718e3744 7171{
d62a17ae 7172 vty->node = BGP_VPNV4_NODE;
7173 return CMD_SUCCESS;
718e3744 7174}
7175
505e5056 7176DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7177 address_family_vpnv6_cmd,
8334fd5a 7178 "address-family vpnv6 [unicast]",
8ecd3266 7179 "Enter Address Family command mode\n"
8c3deaae 7180 "Address Family\n"
3a2d747c 7181 "Address Family modifier\n")
8ecd3266 7182{
d62a17ae 7183 vty->node = BGP_VPNV6_NODE;
7184 return CMD_SUCCESS;
8ecd3266 7185}
64e4a6c5 7186#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7187
505e5056 7188DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7189 address_family_evpn_cmd,
7111c1a0 7190 "address-family l2vpn evpn",
4e0b7b6d 7191 "Enter Address Family command mode\n"
7111c1a0
QY
7192 "Address Family\n"
7193 "Address Family modifier\n")
4e0b7b6d 7194{
2131d5cf 7195 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7196 vty->node = BGP_EVPN_NODE;
7197 return CMD_SUCCESS;
4e0b7b6d
PG
7198}
7199
505e5056 7200DEFUN_NOSH (exit_address_family,
718e3744 7201 exit_address_family_cmd,
7202 "exit-address-family",
7203 "Exit from Address Family configuration mode\n")
7204{
d62a17ae 7205 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7206 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7207 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7208 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7209 || vty->node == BGP_EVPN_NODE
7210 || vty->node == BGP_FLOWSPECV4_NODE
7211 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7212 vty->node = BGP_NODE;
7213 return CMD_SUCCESS;
718e3744 7214}
6b0655a2 7215
8ad7271d 7216/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7217static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7218 const char *ip_str, afi_t afi, safi_t safi,
7219 struct prefix_rd *prd)
7220{
7221 int ret;
7222 struct prefix match;
7223 struct bgp_node *rn;
7224 struct bgp_node *rm;
7225 struct bgp *bgp;
7226 struct bgp_table *table;
7227 struct bgp_table *rib;
7228
7229 /* BGP structure lookup. */
7230 if (view_name) {
7231 bgp = bgp_lookup_by_name(view_name);
7232 if (bgp == NULL) {
7233 vty_out(vty, "%% Can't find BGP instance %s\n",
7234 view_name);
7235 return CMD_WARNING;
7236 }
7237 } else {
7238 bgp = bgp_get_default();
7239 if (bgp == NULL) {
7240 vty_out(vty, "%% No BGP process is configured\n");
7241 return CMD_WARNING;
7242 }
7243 }
7244
7245 /* Check IP address argument. */
7246 ret = str2prefix(ip_str, &match);
7247 if (!ret) {
7248 vty_out(vty, "%% address is malformed\n");
7249 return CMD_WARNING;
7250 }
7251
7252 match.family = afi2family(afi);
7253 rib = bgp->rib[afi][safi];
7254
7255 if (safi == SAFI_MPLS_VPN) {
7256 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7257 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7258 continue;
7259
67009e22
DS
7260 table = bgp_node_get_bgp_table_info(rn);
7261 if (table != NULL) {
7262
d62a17ae 7263 if ((rm = bgp_node_match(table, &match))
7264 != NULL) {
7265 if (rm->p.prefixlen
7266 == match.prefixlen) {
343cdb61 7267 SET_FLAG(rm->flags,
d62a17ae 7268 BGP_NODE_USER_CLEAR);
7269 bgp_process(bgp, rm, afi, safi);
7270 }
7271 bgp_unlock_node(rm);
7272 }
7273 }
7274 }
7275 } else {
7276 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7277 if (rn->p.prefixlen == match.prefixlen) {
7278 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7279 bgp_process(bgp, rn, afi, safi);
7280 }
7281 bgp_unlock_node(rn);
7282 }
7283 }
7284
7285 return CMD_SUCCESS;
8ad7271d
DS
7286}
7287
b09b5ae0 7288/* one clear bgp command to rule them all */
718e3744 7289DEFUN (clear_ip_bgp_all,
7290 clear_ip_bgp_all_cmd,
f3c3ee0d 7291 "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 PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 7292 CLEAR_STR
7293 IP_STR
7294 BGP_STR
838758ac 7295 BGP_INSTANCE_HELP_STR
510afcd6 7296 BGP_AFI_HELP_STR
fd5e7b70 7297 "Address Family\n"
510afcd6 7298 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7299 "Address Family modifier\n"
b09b5ae0
DW
7300 "Clear all peers\n"
7301 "BGP neighbor address to clear\n"
a80beece 7302 "BGP IPv6 neighbor to clear\n"
838758ac 7303 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7304 "Clear peers with the AS number\n"
7305 "Clear all external peers\n"
718e3744 7306 "Clear all members of peer-group\n"
b09b5ae0 7307 "BGP peer-group name\n"
b09b5ae0
DW
7308 BGP_SOFT_STR
7309 BGP_SOFT_IN_STR
b09b5ae0
DW
7310 BGP_SOFT_OUT_STR
7311 BGP_SOFT_IN_STR
7312 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7313 BGP_SOFT_OUT_STR)
718e3744 7314{
d62a17ae 7315 char *vrf = NULL;
7316
7317 afi_t afi = AFI_IP6;
7318 safi_t safi = SAFI_UNICAST;
7319 enum clear_sort clr_sort = clear_peer;
7320 enum bgp_clear_type clr_type;
7321 char *clr_arg = NULL;
7322
7323 int idx = 0;
7324
7325 /* clear [ip] bgp */
7326 if (argv_find(argv, argc, "ip", &idx))
7327 afi = AFI_IP;
7328
9a8bdf1c
PG
7329 /* [<vrf> VIEWVRFNAME] */
7330 if (argv_find(argv, argc, "vrf", &idx)) {
7331 vrf = argv[idx + 1]->arg;
7332 idx += 2;
7333 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7334 vrf = NULL;
7335 } else if (argv_find(argv, argc, "view", &idx)) {
7336 /* [<view> VIEWVRFNAME] */
d62a17ae 7337 vrf = argv[idx + 1]->arg;
7338 idx += 2;
7339 }
d62a17ae 7340 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7341 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7342 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7343
f3c3ee0d 7344 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 7345 if (argv_find(argv, argc, "*", &idx)) {
7346 clr_sort = clear_all;
7347 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7348 clr_sort = clear_peer;
7349 clr_arg = argv[idx]->arg;
7350 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7351 clr_sort = clear_peer;
7352 clr_arg = argv[idx]->arg;
7353 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7354 clr_sort = clear_group;
7355 idx++;
7356 clr_arg = argv[idx]->arg;
f3c3ee0d 7357 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 7358 clr_sort = clear_peer;
7359 clr_arg = argv[idx]->arg;
7360 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7361 clr_sort = clear_as;
7362 clr_arg = argv[idx]->arg;
7363 } else if (argv_find(argv, argc, "external", &idx)) {
7364 clr_sort = clear_external;
7365 }
7366
7367 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7368 if (argv_find(argv, argc, "soft", &idx)) {
7369 if (argv_find(argv, argc, "in", &idx)
7370 || argv_find(argv, argc, "out", &idx))
7371 clr_type = strmatch(argv[idx]->text, "in")
7372 ? BGP_CLEAR_SOFT_IN
7373 : BGP_CLEAR_SOFT_OUT;
7374 else
7375 clr_type = BGP_CLEAR_SOFT_BOTH;
7376 } else if (argv_find(argv, argc, "in", &idx)) {
7377 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7378 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7379 : BGP_CLEAR_SOFT_IN;
7380 } else if (argv_find(argv, argc, "out", &idx)) {
7381 clr_type = BGP_CLEAR_SOFT_OUT;
7382 } else
7383 clr_type = BGP_CLEAR_SOFT_NONE;
7384
7385 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7386}
01080f7c 7387
8ad7271d
DS
7388DEFUN (clear_ip_bgp_prefix,
7389 clear_ip_bgp_prefix_cmd,
18c57037 7390 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7391 CLEAR_STR
7392 IP_STR
7393 BGP_STR
838758ac 7394 BGP_INSTANCE_HELP_STR
8ad7271d 7395 "Clear bestpath and re-advertise\n"
0c7b1b01 7396 "IPv4 prefix\n")
8ad7271d 7397{
d62a17ae 7398 char *vrf = NULL;
7399 char *prefix = NULL;
8ad7271d 7400
d62a17ae 7401 int idx = 0;
01080f7c 7402
d62a17ae 7403 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7404 if (argv_find(argv, argc, "vrf", &idx)) {
7405 vrf = argv[idx + 1]->arg;
7406 idx += 2;
7407 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7408 vrf = NULL;
7409 } else if (argv_find(argv, argc, "view", &idx)) {
7410 /* [<view> VIEWVRFNAME] */
7411 vrf = argv[idx + 1]->arg;
7412 idx += 2;
7413 }
0c7b1b01 7414
d62a17ae 7415 prefix = argv[argc - 1]->arg;
8ad7271d 7416
d62a17ae 7417 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7418}
8ad7271d 7419
b09b5ae0
DW
7420DEFUN (clear_bgp_ipv6_safi_prefix,
7421 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7422 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7423 CLEAR_STR
3a2d747c 7424 IP_STR
718e3744 7425 BGP_STR
8c3deaae 7426 "Address Family\n"
46f296b4 7427 BGP_SAFI_HELP_STR
b09b5ae0 7428 "Clear bestpath and re-advertise\n"
0c7b1b01 7429 "IPv6 prefix\n")
718e3744 7430{
9b475e76
PG
7431 int idx_safi = 0;
7432 int idx_ipv6_prefix = 0;
7433 safi_t safi = SAFI_UNICAST;
7434 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7435 argv[idx_ipv6_prefix]->arg : NULL;
7436
7437 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7438 return bgp_clear_prefix(
9b475e76
PG
7439 vty, NULL, prefix, AFI_IP6,
7440 safi, NULL);
838758ac 7441}
01080f7c 7442
b09b5ae0
DW
7443DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7444 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7445 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7446 CLEAR_STR
3a2d747c 7447 IP_STR
718e3744 7448 BGP_STR
838758ac 7449 BGP_INSTANCE_HELP_STR
8c3deaae 7450 "Address Family\n"
46f296b4 7451 BGP_SAFI_HELP_STR
b09b5ae0 7452 "Clear bestpath and re-advertise\n"
0c7b1b01 7453 "IPv6 prefix\n")
718e3744 7454{
9b475e76 7455 int idx_safi = 0;
9a8bdf1c 7456 int idx_vrfview = 0;
9b475e76
PG
7457 int idx_ipv6_prefix = 0;
7458 safi_t safi = SAFI_UNICAST;
7459 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7460 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7461 char *vrfview = NULL;
9b475e76 7462
9a8bdf1c
PG
7463 /* [<view|vrf> VIEWVRFNAME] */
7464 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7465 vrfview = argv[idx_vrfview + 1]->arg;
7466 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7467 vrfview = NULL;
7468 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7469 /* [<view> VIEWVRFNAME] */
7470 vrfview = argv[idx_vrfview + 1]->arg;
7471 }
9b475e76
PG
7472 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7473
d62a17ae 7474 return bgp_clear_prefix(
9b475e76
PG
7475 vty, vrfview, prefix,
7476 AFI_IP6, safi, NULL);
718e3744 7477}
7478
b09b5ae0
DW
7479DEFUN (show_bgp_views,
7480 show_bgp_views_cmd,
d6e3c605 7481 "show [ip] bgp views",
b09b5ae0 7482 SHOW_STR
d6e3c605 7483 IP_STR
01080f7c 7484 BGP_STR
b09b5ae0 7485 "Show the defined BGP views\n")
01080f7c 7486{
d62a17ae 7487 struct list *inst = bm->bgp;
7488 struct listnode *node;
7489 struct bgp *bgp;
01080f7c 7490
d62a17ae 7491 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7492 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7493 return CMD_WARNING;
7494 }
e52702f2 7495
d62a17ae 7496 vty_out(vty, "Defined BGP views:\n");
7497 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7498 /* Skip VRFs. */
7499 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7500 continue;
7501 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7502 bgp->as);
7503 }
e52702f2 7504
d62a17ae 7505 return CMD_SUCCESS;
e0081f70
ML
7506}
7507
8386ac43 7508DEFUN (show_bgp_vrfs,
7509 show_bgp_vrfs_cmd,
d6e3c605 7510 "show [ip] bgp vrfs [json]",
8386ac43 7511 SHOW_STR
d6e3c605 7512 IP_STR
8386ac43 7513 BGP_STR
7514 "Show BGP VRFs\n"
9973d184 7515 JSON_STR)
8386ac43 7516{
fe1dc5a3 7517 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7518 struct list *inst = bm->bgp;
7519 struct listnode *node;
7520 struct bgp *bgp;
9f049418 7521 bool uj = use_json(argc, argv);
d62a17ae 7522 json_object *json = NULL;
7523 json_object *json_vrfs = NULL;
7524 int count = 0;
d62a17ae 7525
7526 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7527 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7528 return CMD_WARNING;
7529 }
7530
7531 if (uj) {
7532 json = json_object_new_object();
7533 json_vrfs = json_object_new_object();
7534 }
7535
7536 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7537 const char *name, *type;
7538 struct peer *peer;
7fe96307 7539 struct listnode *node2, *nnode2;
d62a17ae 7540 int peers_cfg, peers_estb;
7541 json_object *json_vrf = NULL;
d62a17ae 7542
7543 /* Skip Views. */
7544 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7545 continue;
7546
7547 count++;
7548 if (!uj && count == 1)
fe1dc5a3
MK
7549 vty_out(vty,
7550 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7551 "Type", "Id", "routerId", "#PeersVfg",
7552 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7553
7554 peers_cfg = peers_estb = 0;
7555 if (uj)
7556 json_vrf = json_object_new_object();
7557
7558
7fe96307 7559 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7560 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7561 continue;
7562 peers_cfg++;
7563 if (peer->status == Established)
7564 peers_estb++;
7565 }
7566
7567 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7568 name = VRF_DEFAULT_NAME;
d62a17ae 7569 type = "DFLT";
7570 } else {
7571 name = bgp->name;
7572 type = "VRF";
7573 }
7574
a8bf7d9c 7575
d62a17ae 7576 if (uj) {
a4d82a8a
PZ
7577 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7578 ? -1
7579 : (int64_t)bgp->vrf_id;
d62a17ae 7580 json_object_string_add(json_vrf, "type", type);
7581 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7582 json_object_string_add(json_vrf, "routerId",
7583 inet_ntoa(bgp->router_id));
7584 json_object_int_add(json_vrf, "numConfiguredPeers",
7585 peers_cfg);
7586 json_object_int_add(json_vrf, "numEstablishedPeers",
7587 peers_estb);
7588
fe1dc5a3 7589 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7590 json_object_string_add(
7591 json_vrf, "rmac",
7592 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7593 json_object_object_add(json_vrfs, name, json_vrf);
7594 } else
fe1dc5a3
MK
7595 vty_out(vty,
7596 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7597 type,
7598 bgp->vrf_id == VRF_UNKNOWN ? -1
7599 : (int)bgp->vrf_id,
7600 inet_ntoa(bgp->router_id), peers_cfg,
7601 peers_estb, name, bgp->l3vni,
fe1dc5a3 7602 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7603 }
7604
7605 if (uj) {
7606 json_object_object_add(json, "vrfs", json_vrfs);
7607
7608 json_object_int_add(json, "totalVrfs", count);
7609
996c9314
LB
7610 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7611 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7612 json_object_free(json);
7613 } else {
7614 if (count)
7615 vty_out(vty,
7616 "\nTotal number of VRFs (including default): %d\n",
7617 count);
7618 }
7619
7620 return CMD_SUCCESS;
8386ac43 7621}
7622
48ecf8f5
DS
7623DEFUN (show_bgp_mac_hash,
7624 show_bgp_mac_hash_cmd,
7625 "show bgp mac hash",
7626 SHOW_STR
7627 BGP_STR
7628 "Mac Address\n"
7629 "Mac Address database\n")
7630{
7631 bgp_mac_dump_table(vty);
7632
7633 return CMD_SUCCESS;
7634}
acf71666 7635
e3b78da8 7636static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7637{
0291c246 7638 struct vty *vty = (struct vty *)args;
e3b78da8 7639 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7640
60466a63 7641 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7642 tip->refcnt);
7643}
7644
7645static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7646{
7647 vty_out(vty, "self nexthop database:\n");
af97a18b 7648 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7649
7650 vty_out(vty, "Tunnel-ip database:\n");
7651 hash_iterate(bgp->tip_hash,
e3b78da8 7652 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7653 vty);
7654}
7655
15c81ca4
DS
7656DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7657 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7658 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7659 "martian next-hops\n"
7660 "martian next-hop database\n")
acf71666 7661{
0291c246 7662 struct bgp *bgp = NULL;
15c81ca4 7663 int idx = 0;
9a8bdf1c
PG
7664 char *name = NULL;
7665
7666 /* [<vrf> VIEWVRFNAME] */
7667 if (argv_find(argv, argc, "vrf", &idx)) {
7668 name = argv[idx + 1]->arg;
7669 if (name && strmatch(name, VRF_DEFAULT_NAME))
7670 name = NULL;
7671 } else if (argv_find(argv, argc, "view", &idx))
7672 /* [<view> VIEWVRFNAME] */
7673 name = argv[idx + 1]->arg;
7674 if (name)
7675 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7676 else
7677 bgp = bgp_get_default();
acf71666 7678
acf71666
MK
7679 if (!bgp) {
7680 vty_out(vty, "%% No BGP process is configured\n");
7681 return CMD_WARNING;
7682 }
7683 bgp_show_martian_nexthops(vty, bgp);
7684
7685 return CMD_SUCCESS;
7686}
7687
f412b39a 7688DEFUN (show_bgp_memory,
4bf6a362 7689 show_bgp_memory_cmd,
7fa12b13 7690 "show [ip] bgp memory",
4bf6a362 7691 SHOW_STR
3a2d747c 7692 IP_STR
4bf6a362
PJ
7693 BGP_STR
7694 "Global BGP memory statistics\n")
7695{
d62a17ae 7696 char memstrbuf[MTYPE_MEMSTR_LEN];
7697 unsigned long count;
7698
7699 /* RIB related usage stats */
7700 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7701 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7703 count * sizeof(struct bgp_node)));
7704
7705 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7706 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7708 count * sizeof(struct bgp_path_info)));
d62a17ae 7709 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7710 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7711 count,
4b7e6066
DS
7712 mtype_memstr(
7713 memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7715
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7717 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_static)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7722 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7723 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7724 count * sizeof(struct bpacket)));
7725
7726 /* Adj-In/Out */
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7728 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7729 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7730 count * sizeof(struct bgp_adj_in)));
7731 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7732 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7733 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct bgp_adj_out)));
7735
7736 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7737 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7738 count,
7739 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7740 count * sizeof(struct bgp_nexthop_cache)));
7741
7742 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7743 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7744 count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct bgp_damp_info)));
7747
7748 /* Attributes */
7749 count = attr_count();
7750 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7751 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct attr)));
7753
7754 if ((count = attr_unknown_count()))
7755 vty_out(vty, "%ld unknown attributes\n", count);
7756
7757 /* AS_PATH attributes */
7758 count = aspath_count();
7759 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7760 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct aspath)));
7762
7763 count = mtype_stats_alloc(MTYPE_AS_SEG);
7764 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7765 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct assegment)));
7767
7768 /* Other attributes */
7769 if ((count = community_count()))
7770 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7771 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7772 count * sizeof(struct community)));
d62a17ae 7773 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7774 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7775 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7776 count * sizeof(struct ecommunity)));
d62a17ae 7777 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7778 vty_out(vty,
7779 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7780 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7781 count * sizeof(struct lcommunity)));
d62a17ae 7782
7783 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7784 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7785 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7786 count * sizeof(struct cluster_list)));
7787
7788 /* Peer related usage */
7789 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7790 vty_out(vty, "%ld peers, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7792 count * sizeof(struct peer)));
7793
7794 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7795 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7796 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7797 count * sizeof(struct peer_group)));
7798
7799 /* Other */
7800 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7801 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7802 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7803 count * sizeof(struct hash)));
7804 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7805 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7806 mtype_memstr(memstrbuf, sizeof(memstrbuf),
e3b78da8 7807 count * sizeof(struct hash_bucket)));
d62a17ae 7808 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7809 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7810 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7811 count * sizeof(regex_t)));
d62a17ae 7812 return CMD_SUCCESS;
4bf6a362 7813}
fee0f4c6 7814
57a9c8a8
DS
7815static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7816{
7817 json_object *bestpath = json_object_new_object();
7818
7819 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7820 json_object_string_add(bestpath, "asPath", "ignore");
7821
7822 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7823 json_object_string_add(bestpath, "asPath", "confed");
7824
7825 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7826 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7827 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7828 "as-set");
7829 else
a4d82a8a 7830 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7831 "true");
7832 } else
a4d82a8a 7833 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7834
7835 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7836 json_object_string_add(bestpath, "compareRouterId", "true");
7837 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7838 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7839 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7840 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7841 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7842 json_object_string_add(bestpath, "med",
7843 "missing-as-worst");
7844 else
7845 json_object_string_add(bestpath, "med", "true");
7846 }
7847
7848 json_object_object_add(json, "bestPath", bestpath);
7849}
7850
718e3744 7851/* Show BGP peer's summary information. */
d62a17ae 7852static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7853 bool use_json, json_object *json)
d62a17ae 7854{
7855 struct peer *peer;
7856 struct listnode *node, *nnode;
7857 unsigned int count = 0, dn_count = 0;
7858 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7859 char neighbor_buf[VTY_BUFSIZ];
7860 int neighbor_col_default_width = 16;
7861 int len;
7862 int max_neighbor_width = 0;
7863 int pfx_rcd_safi;
7864 json_object *json_peer = NULL;
7865 json_object *json_peers = NULL;
50e05855 7866 struct peer_af *paf;
d62a17ae 7867
7868 /* labeled-unicast routes are installed in the unicast table so in order
7869 * to
7870 * display the correct PfxRcd value we must look at SAFI_UNICAST
7871 */
7872 if (safi == SAFI_LABELED_UNICAST)
7873 pfx_rcd_safi = SAFI_UNICAST;
7874 else
7875 pfx_rcd_safi = safi;
7876
7877 if (use_json) {
7878 if (json == NULL)
7879 json = json_object_new_object();
7880
7881 json_peers = json_object_new_object();
7882 } else {
7883 /* Loop over all neighbors that will be displayed to determine
7884 * how many
7885 * characters are needed for the Neighbor column
7886 */
7887 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7888 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7889 continue;
7890
7891 if (peer->afc[afi][safi]) {
7892 memset(dn_flag, '\0', sizeof(dn_flag));
7893 if (peer_dynamic_neighbor(peer))
7894 dn_flag[0] = '*';
7895
7896 if (peer->hostname
7897 && bgp_flag_check(bgp,
7898 BGP_FLAG_SHOW_HOSTNAME))
7899 sprintf(neighbor_buf, "%s%s(%s) ",
7900 dn_flag, peer->hostname,
7901 peer->host);
7902 else
7903 sprintf(neighbor_buf, "%s%s ", dn_flag,
7904 peer->host);
7905
7906 len = strlen(neighbor_buf);
7907
7908 if (len > max_neighbor_width)
7909 max_neighbor_width = len;
7910 }
7911 }
f933309e 7912
d62a17ae 7913 /* Originally we displayed the Neighbor column as 16
7914 * characters wide so make that the default
7915 */
7916 if (max_neighbor_width < neighbor_col_default_width)
7917 max_neighbor_width = neighbor_col_default_width;
7918 }
f933309e 7919
d62a17ae 7920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7921 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7922 continue;
7923
ea47320b
DL
7924 if (!peer->afc[afi][safi])
7925 continue;
d62a17ae 7926
ea47320b
DL
7927 if (!count) {
7928 unsigned long ents;
7929 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7930 int64_t vrf_id_ui;
d62a17ae 7931
a4d82a8a
PZ
7932 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7933 ? -1
7934 : (int64_t)bgp->vrf_id;
ea47320b
DL
7935
7936 /* Usage summary and header */
7937 if (use_json) {
7938 json_object_string_add(
7939 json, "routerId",
7940 inet_ntoa(bgp->router_id));
60466a63
QY
7941 json_object_int_add(json, "as", bgp->as);
7942 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7943 json_object_string_add(
7944 json, "vrfName",
7945 (bgp->inst_type
7946 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7947 ? VRF_DEFAULT_NAME
ea47320b
DL
7948 : bgp->name);
7949 } else {
7950 vty_out(vty,
7951 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7952 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7953 bgp->vrf_id == VRF_UNKNOWN
7954 ? -1
7955 : (int)bgp->vrf_id);
ea47320b
DL
7956 vty_out(vty, "\n");
7957 }
d62a17ae 7958
ea47320b 7959 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7960 if (use_json) {
ea47320b 7961 json_object_int_add(
60466a63 7962 json, "updateDelayLimit",
ea47320b 7963 bgp->v_update_delay);
d62a17ae 7964
ea47320b
DL
7965 if (bgp->v_update_delay
7966 != bgp->v_establish_wait)
d62a17ae 7967 json_object_int_add(
7968 json,
ea47320b
DL
7969 "updateDelayEstablishWait",
7970 bgp->v_establish_wait);
d62a17ae 7971
60466a63 7972 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7973 json_object_string_add(
7974 json,
7975 "updateDelayFirstNeighbor",
7976 bgp->update_delay_begin_time);
7977 json_object_boolean_true_add(
7978 json,
7979 "updateDelayInProgress");
7980 } else {
7981 if (bgp->update_delay_over) {
d62a17ae 7982 json_object_string_add(
7983 json,
7984 "updateDelayFirstNeighbor",
7985 bgp->update_delay_begin_time);
ea47320b 7986 json_object_string_add(
d62a17ae 7987 json,
ea47320b
DL
7988 "updateDelayBestpathResumed",
7989 bgp->update_delay_end_time);
7990 json_object_string_add(
d62a17ae 7991 json,
ea47320b
DL
7992 "updateDelayZebraUpdateResume",
7993 bgp->update_delay_zebra_resume_time);
7994 json_object_string_add(
7995 json,
7996 "updateDelayPeerUpdateResume",
7997 bgp->update_delay_peers_resume_time);
d62a17ae 7998 }
ea47320b
DL
7999 }
8000 } else {
8001 vty_out(vty,
8002 "Read-only mode update-delay limit: %d seconds\n",
8003 bgp->v_update_delay);
8004 if (bgp->v_update_delay
8005 != bgp->v_establish_wait)
d62a17ae 8006 vty_out(vty,
ea47320b
DL
8007 " Establish wait: %d seconds\n",
8008 bgp->v_establish_wait);
d62a17ae 8009
60466a63 8010 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8011 vty_out(vty,
8012 " First neighbor established: %s\n",
8013 bgp->update_delay_begin_time);
8014 vty_out(vty,
8015 " Delay in progress\n");
8016 } else {
8017 if (bgp->update_delay_over) {
d62a17ae 8018 vty_out(vty,
8019 " First neighbor established: %s\n",
8020 bgp->update_delay_begin_time);
8021 vty_out(vty,
ea47320b
DL
8022 " Best-paths resumed: %s\n",
8023 bgp->update_delay_end_time);
8024 vty_out(vty,
8025 " zebra update resumed: %s\n",
8026 bgp->update_delay_zebra_resume_time);
8027 vty_out(vty,
8028 " peers update resumed: %s\n",
8029 bgp->update_delay_peers_resume_time);
d62a17ae 8030 }
8031 }
8032 }
ea47320b 8033 }
d62a17ae 8034
ea47320b
DL
8035 if (use_json) {
8036 if (bgp_maxmed_onstartup_configured(bgp)
8037 && bgp->maxmed_active)
8038 json_object_boolean_true_add(
60466a63 8039 json, "maxMedOnStartup");
ea47320b
DL
8040 if (bgp->v_maxmed_admin)
8041 json_object_boolean_true_add(
60466a63 8042 json, "maxMedAdministrative");
d62a17ae 8043
ea47320b
DL
8044 json_object_int_add(
8045 json, "tableVersion",
60466a63 8046 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8047
60466a63
QY
8048 ents = bgp_table_count(bgp->rib[afi][safi]);
8049 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8050 json_object_int_add(
8051 json, "ribMemory",
8052 ents * sizeof(struct bgp_node));
d62a17ae 8053
210ec2a0 8054 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8055 json_object_int_add(json, "peerCount", ents);
8056 json_object_int_add(json, "peerMemory",
8057 ents * sizeof(struct peer));
d62a17ae 8058
ea47320b
DL
8059 if ((ents = listcount(bgp->group))) {
8060 json_object_int_add(
60466a63 8061 json, "peerGroupCount", ents);
ea47320b
DL
8062 json_object_int_add(
8063 json, "peerGroupMemory",
996c9314
LB
8064 ents * sizeof(struct
8065 peer_group));
ea47320b 8066 }
d62a17ae 8067
ea47320b
DL
8068 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8069 BGP_CONFIG_DAMPENING))
8070 json_object_boolean_true_add(
60466a63 8071 json, "dampeningEnabled");
ea47320b
DL
8072 } else {
8073 if (bgp_maxmed_onstartup_configured(bgp)
8074 && bgp->maxmed_active)
d62a17ae 8075 vty_out(vty,
ea47320b
DL
8076 "Max-med on-startup active\n");
8077 if (bgp->v_maxmed_admin)
d62a17ae 8078 vty_out(vty,
ea47320b 8079 "Max-med administrative active\n");
d62a17ae 8080
60466a63
QY
8081 vty_out(vty, "BGP table version %" PRIu64 "\n",
8082 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8083
60466a63 8084 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8085 vty_out(vty,
8086 "RIB entries %ld, using %s of memory\n",
8087 ents,
996c9314
LB
8088 mtype_memstr(memstrbuf,
8089 sizeof(memstrbuf),
8090 ents * sizeof(struct
8091 bgp_node)));
ea47320b
DL
8092
8093 /* Peer related usage */
210ec2a0 8094 ents = bgp->af_peer_count[afi][safi];
60466a63 8095 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8096 ents,
8097 mtype_memstr(
60466a63
QY
8098 memstrbuf, sizeof(memstrbuf),
8099 ents * sizeof(struct peer)));
ea47320b
DL
8100
8101 if ((ents = listcount(bgp->group)))
d62a17ae 8102 vty_out(vty,
ea47320b 8103 "Peer groups %ld, using %s of memory\n",
d62a17ae 8104 ents,
8105 mtype_memstr(
8106 memstrbuf,
8107 sizeof(memstrbuf),
996c9314
LB
8108 ents * sizeof(struct
8109 peer_group)));
d62a17ae 8110
ea47320b
DL
8111 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8112 BGP_CONFIG_DAMPENING))
60466a63 8113 vty_out(vty, "Dampening enabled.\n");
ea47320b 8114 vty_out(vty, "\n");
d62a17ae 8115
ea47320b
DL
8116 /* Subtract 8 here because 'Neighbor' is
8117 * 8 characters */
8118 vty_out(vty, "Neighbor");
60466a63
QY
8119 vty_out(vty, "%*s", max_neighbor_width - 8,
8120 " ");
ea47320b
DL
8121 vty_out(vty,
8122 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8123 }
ea47320b 8124 }
d62a17ae 8125
ea47320b 8126 count++;
d62a17ae 8127
ea47320b
DL
8128 if (use_json) {
8129 json_peer = json_object_new_object();
d62a17ae 8130
b4e9dcba
DD
8131 if (peer_dynamic_neighbor(peer)) {
8132 dn_count++;
60466a63
QY
8133 json_object_boolean_true_add(json_peer,
8134 "dynamicPeer");
b4e9dcba 8135 }
d62a17ae 8136
ea47320b 8137 if (peer->hostname)
60466a63 8138 json_object_string_add(json_peer, "hostname",
ea47320b 8139 peer->hostname);
d62a17ae 8140
ea47320b 8141 if (peer->domainname)
60466a63
QY
8142 json_object_string_add(json_peer, "domainname",
8143 peer->domainname);
d62a17ae 8144
60466a63 8145 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8146 json_object_int_add(json_peer, "version", 4);
60466a63 8147 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8148 PEER_TOTAL_RX(peer));
60466a63 8149 json_object_int_add(json_peer, "msgSent",
0112e9e0 8150 PEER_TOTAL_TX(peer));
ea47320b
DL
8151
8152 json_object_int_add(json_peer, "tableVersion",
8153 peer->version[afi][safi]);
8154 json_object_int_add(json_peer, "outq",
8155 peer->obuf->count);
8156 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8157 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8158 use_json, json_peer);
50e05855
AD
8159
8160 /*
8161 * Adding "pfxRcd" field to match with the corresponding
8162 * CLI. "prefixReceivedCount" will be deprecated in
8163 * future.
8164 */
60466a63
QY
8165 json_object_int_add(json_peer, "prefixReceivedCount",
8166 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8167 json_object_int_add(json_peer, "pfxRcd",
8168 peer->pcount[afi][pfx_rcd_safi]);
8169
8170 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8171 if (paf && PAF_SUBGRP(paf))
8172 json_object_int_add(json_peer,
8173 "pfxSnt",
8174 (PAF_SUBGRP(paf))->scount);
d62a17ae 8175
ea47320b 8176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8177 json_object_string_add(json_peer, "state",
ea47320b 8178 "Idle (Admin)");
9199a725
TM
8179 else if (peer->afc_recv[afi][safi])
8180 json_object_string_add(
8181 json_peer, "state",
8182 lookup_msg(bgp_status_msg, peer->status,
8183 NULL));
60466a63
QY
8184 else if (CHECK_FLAG(peer->sflags,
8185 PEER_STATUS_PREFIX_OVERFLOW))
8186 json_object_string_add(json_peer, "state",
ea47320b
DL
8187 "Idle (PfxCt)");
8188 else
8189 json_object_string_add(
8190 json_peer, "state",
60466a63
QY
8191 lookup_msg(bgp_status_msg, peer->status,
8192 NULL));
ea47320b
DL
8193
8194 if (peer->conf_if)
60466a63 8195 json_object_string_add(json_peer, "idType",
ea47320b
DL
8196 "interface");
8197 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8198 json_object_string_add(json_peer, "idType",
8199 "ipv4");
ea47320b 8200 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8201 json_object_string_add(json_peer, "idType",
8202 "ipv6");
d62a17ae 8203
ea47320b
DL
8204 json_object_object_add(json_peers, peer->host,
8205 json_peer);
8206 } else {
8207 memset(dn_flag, '\0', sizeof(dn_flag));
8208 if (peer_dynamic_neighbor(peer)) {
8209 dn_count++;
8210 dn_flag[0] = '*';
8211 }
d62a17ae 8212
ea47320b 8213 if (peer->hostname
60466a63 8214 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8215 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8216 peer->hostname, peer->host);
ea47320b 8217 else
60466a63 8218 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8219
8220 /* pad the neighbor column with spaces */
8221 if (len < max_neighbor_width)
60466a63
QY
8222 vty_out(vty, "%*s", max_neighbor_width - len,
8223 " ");
ea47320b 8224
86a55b99 8225 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8226 peer->as, PEER_TOTAL_RX(peer),
8227 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8228 0, peer->obuf->count,
d62a17ae 8229 peer_uptime(peer->uptime, timebuf,
ea47320b 8230 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8231
ea47320b 8232 if (peer->status == Established)
2f8f4f10 8233 if (peer->afc_recv[afi][safi])
3b59184d 8234 vty_out(vty, " %12" PRIu32,
a4d82a8a
PZ
8235 peer->pcount[afi]
8236 [pfx_rcd_safi]);
95077abf
DW
8237 else
8238 vty_out(vty, " NoNeg");
ea47320b 8239 else {
60466a63 8240 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8241 vty_out(vty, " Idle (Admin)");
60466a63
QY
8242 else if (CHECK_FLAG(
8243 peer->sflags,
8244 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8245 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8246 else
ea47320b 8247 vty_out(vty, " %12s",
60466a63
QY
8248 lookup_msg(bgp_status_msg,
8249 peer->status, NULL));
d62a17ae 8250 }
ea47320b 8251 vty_out(vty, "\n");
d62a17ae 8252 }
8253 }
f933309e 8254
d62a17ae 8255 if (use_json) {
8256 json_object_object_add(json, "peers", json_peers);
8257
8258 json_object_int_add(json, "totalPeers", count);
8259 json_object_int_add(json, "dynamicPeers", dn_count);
8260
57a9c8a8
DS
8261 bgp_show_bestpath_json(bgp, json);
8262
996c9314
LB
8263 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8264 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8265 json_object_free(json);
8266 } else {
8267 if (count)
8268 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8269 else {
d6ceaca3 8270 vty_out(vty, "No %s neighbor is configured\n",
8271 afi_safi_print(afi, safi));
d62a17ae 8272 }
b05a1c8b 8273
d6ceaca3 8274 if (dn_count) {
d62a17ae 8275 vty_out(vty, "* - dynamic neighbor\n");
8276 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8277 dn_count, bgp->dynamic_neighbors_limit);
8278 }
8279 }
1ff9a340 8280
d62a17ae 8281 return CMD_SUCCESS;
718e3744 8282}
8283
d62a17ae 8284static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
9f049418 8285 int safi, bool use_json,
d62a17ae 8286 json_object *json)
8287{
8288 int is_first = 1;
8289 int afi_wildcard = (afi == AFI_MAX);
8290 int safi_wildcard = (safi == SAFI_MAX);
8291 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8292 bool nbr_output = false;
d62a17ae 8293
8294 if (use_json && is_wildcard)
8295 vty_out(vty, "{\n");
8296 if (afi_wildcard)
8297 afi = 1; /* AFI_IP */
8298 while (afi < AFI_MAX) {
8299 if (safi_wildcard)
8300 safi = 1; /* SAFI_UNICAST */
8301 while (safi < SAFI_MAX) {
318cac96 8302 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8303 nbr_output = true;
d62a17ae 8304 if (is_wildcard) {
8305 /*
8306 * So limit output to those afi/safi
8307 * pairs that
8308 * actualy have something interesting in
8309 * them
8310 */
8311 if (use_json) {
8312 json = json_object_new_object();
8313
8314 if (!is_first)
8315 vty_out(vty, ",\n");
8316 else
8317 is_first = 0;
8318
8319 vty_out(vty, "\"%s\":",
8320 afi_safi_json(afi,
8321 safi));
8322 } else {
8323 vty_out(vty, "\n%s Summary:\n",
8324 afi_safi_print(afi,
8325 safi));
8326 }
8327 }
8328 bgp_show_summary(vty, bgp, afi, safi, use_json,
8329 json);
8330 }
8331 safi++;
d62a17ae 8332 if (!safi_wildcard)
8333 safi = SAFI_MAX;
8334 }
8335 afi++;
ee851c8c 8336 if (!afi_wildcard)
d62a17ae 8337 afi = AFI_MAX;
8338 }
8339
8340 if (use_json && is_wildcard)
8341 vty_out(vty, "}\n");
ca61fd25
DS
8342 else if (!nbr_output) {
8343 if (use_json)
8344 vty_out(vty, "{}\n");
8345 else
8346 vty_out(vty, "%% No BGP neighbors found\n");
8347 }
d62a17ae 8348}
8349
8350static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8351 safi_t safi, bool use_json)
d62a17ae 8352{
8353 struct listnode *node, *nnode;
8354 struct bgp *bgp;
8355 json_object *json = NULL;
8356 int is_first = 1;
9f049418 8357 bool nbr_output = false;
d62a17ae 8358
8359 if (use_json)
8360 vty_out(vty, "{\n");
8361
8362 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8363 nbr_output = true;
d62a17ae 8364 if (use_json) {
8365 json = json_object_new_object();
8366
8367 if (!is_first)
8368 vty_out(vty, ",\n");
8369 else
8370 is_first = 0;
8371
8372 vty_out(vty, "\"%s\":",
8373 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8374 ? VRF_DEFAULT_NAME
d62a17ae 8375 : bgp->name);
8376 } else {
8377 vty_out(vty, "\nInstance %s:\n",
8378 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8379 ? VRF_DEFAULT_NAME
d62a17ae 8380 : bgp->name);
8381 }
8382 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8383 }
8384
8385 if (use_json)
8386 vty_out(vty, "}\n");
9f049418
DS
8387 else if (!nbr_output)
8388 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8389}
8390
8391int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8392 safi_t safi, bool use_json)
d62a17ae 8393{
8394 struct bgp *bgp;
8395
8396 if (name) {
8397 if (strmatch(name, "all")) {
8398 bgp_show_all_instances_summary_vty(vty, afi, safi,
8399 use_json);
8400 return CMD_SUCCESS;
8401 } else {
8402 bgp = bgp_lookup_by_name(name);
8403
8404 if (!bgp) {
8405 if (use_json)
8406 vty_out(vty, "{}\n");
8407 else
8408 vty_out(vty,
ca61fd25 8409 "%% BGP instance not found\n");
d62a17ae 8410 return CMD_WARNING;
8411 }
8412
8413 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8414 NULL);
8415 return CMD_SUCCESS;
8416 }
8417 }
8418
8419 bgp = bgp_get_default();
8420
8421 if (bgp)
8422 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
9f049418 8423 else {
ca61fd25
DS
8424 if (use_json)
8425 vty_out(vty, "{}\n");
8426 else
8427 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8428 return CMD_WARNING;
8429 }
d62a17ae 8430
8431 return CMD_SUCCESS;
4fb25c53
DW
8432}
8433
716b2d8a 8434/* `show [ip] bgp summary' commands. */
47fc97cc 8435DEFUN (show_ip_bgp_summary,
718e3744 8436 show_ip_bgp_summary_cmd,
dd6bd0f1 8437 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8438 SHOW_STR
8439 IP_STR
8440 BGP_STR
8386ac43 8441 BGP_INSTANCE_HELP_STR
46f296b4 8442 BGP_AFI_HELP_STR
dd6bd0f1 8443 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8444 "Summary of BGP neighbor status\n"
9973d184 8445 JSON_STR)
718e3744 8446{
d62a17ae 8447 char *vrf = NULL;
8448 afi_t afi = AFI_MAX;
8449 safi_t safi = SAFI_MAX;
8450
8451 int idx = 0;
8452
8453 /* show [ip] bgp */
8454 if (argv_find(argv, argc, "ip", &idx))
8455 afi = AFI_IP;
9a8bdf1c
PG
8456 /* [<vrf> VIEWVRFNAME] */
8457 if (argv_find(argv, argc, "vrf", &idx)) {
8458 vrf = argv[idx + 1]->arg;
8459 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8460 vrf = NULL;
8461 } else if (argv_find(argv, argc, "view", &idx))
8462 /* [<view> VIEWVRFNAME] */
8463 vrf = argv[idx + 1]->arg;
d62a17ae 8464 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8465 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8466 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8467 }
8468
9f049418 8469 bool uj = use_json(argc, argv);
d62a17ae 8470
8471 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8472}
8473
8474const char *afi_safi_print(afi_t afi, safi_t safi)
8475{
8476 if (afi == AFI_IP && safi == SAFI_UNICAST)
8477 return "IPv4 Unicast";
8478 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8479 return "IPv4 Multicast";
8480 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8481 return "IPv4 Labeled Unicast";
8482 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8483 return "IPv4 VPN";
8484 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8485 return "IPv4 Encap";
7c40bf39 8486 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8487 return "IPv4 Flowspec";
d62a17ae 8488 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8489 return "IPv6 Unicast";
8490 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8491 return "IPv6 Multicast";
8492 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8493 return "IPv6 Labeled Unicast";
8494 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8495 return "IPv6 VPN";
8496 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8497 return "IPv6 Encap";
7c40bf39 8498 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8499 return "IPv6 Flowspec";
d62a17ae 8500 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8501 return "L2VPN EVPN";
8502 else
8503 return "Unknown";
538621f2 8504}
8505
b9f77ec8
DS
8506/*
8507 * Please note that we have intentionally camelCased
8508 * the return strings here. So if you want
8509 * to use this function, please ensure you
8510 * are doing this within json output
8511 */
d62a17ae 8512const char *afi_safi_json(afi_t afi, safi_t safi)
8513{
8514 if (afi == AFI_IP && safi == SAFI_UNICAST)
8515 return "ipv4Unicast";
8516 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8517 return "ipv4Multicast";
8518 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8519 return "ipv4LabeledUnicast";
8520 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8521 return "ipv4Vpn";
8522 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8523 return "ipv4Encap";
7c40bf39 8524 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8525 return "ipv4Flowspec";
d62a17ae 8526 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8527 return "ipv6Unicast";
8528 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8529 return "ipv6Multicast";
8530 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8531 return "ipv6LabeledUnicast";
8532 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8533 return "ipv6Vpn";
8534 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8535 return "ipv6Encap";
7c40bf39 8536 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8537 return "ipv6Flowspec";
d62a17ae 8538 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8539 return "l2VpnEvpn";
8540 else
8541 return "Unknown";
27162734
LB
8542}
8543
718e3744 8544/* Show BGP peer's information. */
d1927ebe 8545enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8546
8547static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8548 afi_t afi, safi_t safi,
d7c0a89a
QY
8549 uint16_t adv_smcap, uint16_t adv_rmcap,
8550 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8551 bool use_json, json_object *json_pref)
d62a17ae 8552{
8553 /* Send-Mode */
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8555 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8556 if (use_json) {
8557 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8558 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8559 json_object_string_add(json_pref, "sendMode",
8560 "advertisedAndReceived");
8561 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8562 json_object_string_add(json_pref, "sendMode",
8563 "advertised");
8564 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8565 json_object_string_add(json_pref, "sendMode",
8566 "received");
8567 } else {
8568 vty_out(vty, " Send-mode: ");
8569 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8570 vty_out(vty, "advertised");
8571 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8572 vty_out(vty, "%sreceived",
8573 CHECK_FLAG(p->af_cap[afi][safi],
8574 adv_smcap)
8575 ? ", "
8576 : "");
8577 vty_out(vty, "\n");
8578 }
8579 }
8580
8581 /* Receive-Mode */
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8583 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8584 if (use_json) {
8585 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8586 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8587 json_object_string_add(json_pref, "recvMode",
8588 "advertisedAndReceived");
8589 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8590 json_object_string_add(json_pref, "recvMode",
8591 "advertised");
8592 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8593 json_object_string_add(json_pref, "recvMode",
8594 "received");
8595 } else {
8596 vty_out(vty, " Receive-mode: ");
8597 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8598 vty_out(vty, "advertised");
8599 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8600 vty_out(vty, "%sreceived",
8601 CHECK_FLAG(p->af_cap[afi][safi],
8602 adv_rmcap)
8603 ? ", "
8604 : "");
8605 vty_out(vty, "\n");
8606 }
8607 }
8608}
8609
8610static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8611 safi_t safi, bool use_json,
d62a17ae 8612 json_object *json_neigh)
8613{
0291c246
MK
8614 struct bgp_filter *filter;
8615 struct peer_af *paf;
8616 char orf_pfx_name[BUFSIZ];
8617 int orf_pfx_count;
8618 json_object *json_af = NULL;
8619 json_object *json_prefA = NULL;
8620 json_object *json_prefB = NULL;
8621 json_object *json_addr = NULL;
d62a17ae 8622
8623 if (use_json) {
8624 json_addr = json_object_new_object();
8625 json_af = json_object_new_object();
8626 filter = &p->filter[afi][safi];
8627
8628 if (peer_group_active(p))
8629 json_object_string_add(json_addr, "peerGroupMember",
8630 p->group->name);
8631
8632 paf = peer_af_find(p, afi, safi);
8633 if (paf && PAF_SUBGRP(paf)) {
8634 json_object_int_add(json_addr, "updateGroupId",
8635 PAF_UPDGRP(paf)->id);
8636 json_object_int_add(json_addr, "subGroupId",
8637 PAF_SUBGRP(paf)->id);
8638 json_object_int_add(json_addr, "packetQueueLength",
8639 bpacket_queue_virtual_length(paf));
8640 }
8641
8642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8649 json_object_int_add(json_af, "orfType",
8650 ORF_TYPE_PREFIX);
8651 json_prefA = json_object_new_object();
8652 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8653 PEER_CAP_ORF_PREFIX_SM_ADV,
8654 PEER_CAP_ORF_PREFIX_RM_ADV,
8655 PEER_CAP_ORF_PREFIX_SM_RCV,
8656 PEER_CAP_ORF_PREFIX_RM_RCV,
8657 use_json, json_prefA);
8658 json_object_object_add(json_af, "orfPrefixList",
8659 json_prefA);
8660 }
8661
8662 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_RM_ADV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8669 json_object_int_add(json_af, "orfOldType",
8670 ORF_TYPE_PREFIX_OLD);
8671 json_prefB = json_object_new_object();
8672 bgp_show_peer_afi_orf_cap(
8673 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8674 PEER_CAP_ORF_PREFIX_RM_ADV,
8675 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8676 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8677 json_prefB);
8678 json_object_object_add(json_af, "orfOldPrefixList",
8679 json_prefB);
8680 }
8681
8682 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_ADV)
8689 || CHECK_FLAG(p->af_cap[afi][safi],
8690 PEER_CAP_ORF_PREFIX_RM_RCV)
8691 || CHECK_FLAG(p->af_cap[afi][safi],
8692 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8693 json_object_object_add(json_addr, "afDependentCap",
8694 json_af);
8695 else
8696 json_object_free(json_af);
8697
8698 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8699 orf_pfx_count = prefix_bgp_show_prefix_list(
8700 NULL, afi, orf_pfx_name, use_json);
8701
8702 if (CHECK_FLAG(p->af_sflags[afi][safi],
8703 PEER_STATUS_ORF_PREFIX_SEND)
8704 || orf_pfx_count) {
8705 if (CHECK_FLAG(p->af_sflags[afi][safi],
8706 PEER_STATUS_ORF_PREFIX_SEND))
8707 json_object_boolean_true_add(json_neigh,
8708 "orfSent");
8709 if (orf_pfx_count)
8710 json_object_int_add(json_addr, "orfRecvCounter",
8711 orf_pfx_count);
8712 }
8713 if (CHECK_FLAG(p->af_sflags[afi][safi],
8714 PEER_STATUS_ORF_WAIT_REFRESH))
8715 json_object_string_add(
8716 json_addr, "orfFirstUpdate",
8717 "deferredUntilORFOrRouteRefreshRecvd");
8718
8719 if (CHECK_FLAG(p->af_flags[afi][safi],
8720 PEER_FLAG_REFLECTOR_CLIENT))
8721 json_object_boolean_true_add(json_addr,
8722 "routeReflectorClient");
8723 if (CHECK_FLAG(p->af_flags[afi][safi],
8724 PEER_FLAG_RSERVER_CLIENT))
8725 json_object_boolean_true_add(json_addr,
8726 "routeServerClient");
8727 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8728 json_object_boolean_true_add(json_addr,
8729 "inboundSoftConfigPermit");
8730
8731 if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsAllReplacedInUpdatesToNbr");
8736 else if (CHECK_FLAG(p->af_flags[afi][safi],
8737 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8738 json_object_boolean_true_add(
8739 json_addr,
8740 "privateAsNumsReplacedInUpdatesToNbr");
8741 else if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8743 json_object_boolean_true_add(
8744 json_addr,
8745 "privateAsNumsAllRemovedInUpdatesToNbr");
8746 else if (CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_REMOVE_PRIVATE_AS))
8748 json_object_boolean_true_add(
8749 json_addr,
8750 "privateAsNumsRemovedInUpdatesToNbr");
8751
dcc68b5e
MS
8752 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8753 json_object_boolean_true_add(
8754 json_addr,
8755 bgp_addpath_names(p->addpath_type[afi][safi])
8756 ->type_json_name);
d62a17ae 8757
8758 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8759 json_object_string_add(json_addr,
8760 "overrideASNsInOutboundUpdates",
8761 "ifAspathEqualRemoteAs");
8762
8763 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8764 || CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_FORCE_NEXTHOP_SELF))
8766 json_object_boolean_true_add(json_addr,
8767 "routerAlwaysNextHop");
8768 if (CHECK_FLAG(p->af_flags[afi][safi],
8769 PEER_FLAG_AS_PATH_UNCHANGED))
8770 json_object_boolean_true_add(
8771 json_addr, "unchangedAsPathPropogatedToNbr");
8772 if (CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_NEXTHOP_UNCHANGED))
8774 json_object_boolean_true_add(
8775 json_addr, "unchangedNextHopPropogatedToNbr");
8776 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8777 json_object_boolean_true_add(
8778 json_addr, "unchangedMedPropogatedToNbr");
8779 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8780 || CHECK_FLAG(p->af_flags[afi][safi],
8781 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8782 if (CHECK_FLAG(p->af_flags[afi][safi],
8783 PEER_FLAG_SEND_COMMUNITY)
8784 && CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_SEND_EXT_COMMUNITY))
8786 json_object_string_add(json_addr,
8787 "commAttriSentToNbr",
8788 "extendedAndStandard");
8789 else if (CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_EXT_COMMUNITY))
8791 json_object_string_add(json_addr,
8792 "commAttriSentToNbr",
8793 "extended");
8794 else
8795 json_object_string_add(json_addr,
8796 "commAttriSentToNbr",
8797 "standard");
8798 }
8799 if (CHECK_FLAG(p->af_flags[afi][safi],
8800 PEER_FLAG_DEFAULT_ORIGINATE)) {
8801 if (p->default_rmap[afi][safi].name)
8802 json_object_string_add(
8803 json_addr, "defaultRouteMap",
8804 p->default_rmap[afi][safi].name);
8805
8806 if (paf && PAF_SUBGRP(paf)
8807 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8808 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8809 json_object_boolean_true_add(json_addr,
8810 "defaultSent");
8811 else
8812 json_object_boolean_true_add(json_addr,
8813 "defaultNotSent");
8814 }
8815
dff8f48d 8816 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8817 if (is_evpn_enabled())
60466a63
QY
8818 json_object_boolean_true_add(
8819 json_addr, "advertiseAllVnis");
dff8f48d
MK
8820 }
8821
d62a17ae 8822 if (filter->plist[FILTER_IN].name
8823 || filter->dlist[FILTER_IN].name
8824 || filter->aslist[FILTER_IN].name
8825 || filter->map[RMAP_IN].name)
8826 json_object_boolean_true_add(json_addr,
8827 "inboundPathPolicyConfig");
8828 if (filter->plist[FILTER_OUT].name
8829 || filter->dlist[FILTER_OUT].name
8830 || filter->aslist[FILTER_OUT].name
8831 || filter->map[RMAP_OUT].name || filter->usmap.name)
8832 json_object_boolean_true_add(
8833 json_addr, "outboundPathPolicyConfig");
8834
8835 /* prefix-list */
8836 if (filter->plist[FILTER_IN].name)
8837 json_object_string_add(json_addr,
8838 "incomingUpdatePrefixFilterList",
8839 filter->plist[FILTER_IN].name);
8840 if (filter->plist[FILTER_OUT].name)
8841 json_object_string_add(json_addr,
8842 "outgoingUpdatePrefixFilterList",
8843 filter->plist[FILTER_OUT].name);
8844
8845 /* distribute-list */
8846 if (filter->dlist[FILTER_IN].name)
8847 json_object_string_add(
8848 json_addr, "incomingUpdateNetworkFilterList",
8849 filter->dlist[FILTER_IN].name);
8850 if (filter->dlist[FILTER_OUT].name)
8851 json_object_string_add(
8852 json_addr, "outgoingUpdateNetworkFilterList",
8853 filter->dlist[FILTER_OUT].name);
8854
8855 /* filter-list. */
8856 if (filter->aslist[FILTER_IN].name)
8857 json_object_string_add(json_addr,
8858 "incomingUpdateAsPathFilterList",
8859 filter->aslist[FILTER_IN].name);
8860 if (filter->aslist[FILTER_OUT].name)
8861 json_object_string_add(json_addr,
8862 "outgoingUpdateAsPathFilterList",
8863 filter->aslist[FILTER_OUT].name);
8864
8865 /* route-map. */
8866 if (filter->map[RMAP_IN].name)
8867 json_object_string_add(
8868 json_addr, "routeMapForIncomingAdvertisements",
8869 filter->map[RMAP_IN].name);
8870 if (filter->map[RMAP_OUT].name)
8871 json_object_string_add(
8872 json_addr, "routeMapForOutgoingAdvertisements",
8873 filter->map[RMAP_OUT].name);
8874
9dac9fc8
DA
8875 /* ebgp-requires-policy (inbound) */
8876 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8877 && !bgp_inbound_policy_exists(p, filter))
8878 json_object_string_add(
8879 json_addr, "inboundEbgpRequiresPolicy",
8880 "Inbound updates discarded due to missing policy");
8881
8882 /* ebgp-requires-policy (outbound) */
8883 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8884 && (!bgp_outbound_policy_exists(p, filter)))
8885 json_object_string_add(
8886 json_addr, "outboundEbgpRequiresPolicy",
8887 "Outbound updates discarded due to missing policy");
8888
d62a17ae 8889 /* unsuppress-map */
8890 if (filter->usmap.name)
8891 json_object_string_add(json_addr,
8892 "selectiveUnsuppressRouteMap",
8893 filter->usmap.name);
8894
8895 /* Receive prefix count */
8896 json_object_int_add(json_addr, "acceptedPrefixCounter",
8897 p->pcount[afi][safi]);
50e05855
AD
8898 if (paf && PAF_SUBGRP(paf))
8899 json_object_int_add(json_addr, "sentPrefixCounter",
8900 (PAF_SUBGRP(paf))->scount);
d62a17ae 8901
8902 /* Maximum prefix */
8903 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8904 json_object_int_add(json_addr, "prefixAllowedMax",
8905 p->pmax[afi][safi]);
8906 if (CHECK_FLAG(p->af_flags[afi][safi],
8907 PEER_FLAG_MAX_PREFIX_WARNING))
8908 json_object_boolean_true_add(
8909 json_addr, "prefixAllowedMaxWarning");
8910 json_object_int_add(json_addr,
8911 "prefixAllowedWarningThresh",
8912 p->pmax_threshold[afi][safi]);
8913 if (p->pmax_restart[afi][safi])
8914 json_object_int_add(
8915 json_addr,
8916 "prefixAllowedRestartIntervalMsecs",
8917 p->pmax_restart[afi][safi] * 60000);
8918 }
8919 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8920 json_addr);
8921
8922 } else {
8923 filter = &p->filter[afi][safi];
8924
8925 vty_out(vty, " For address family: %s\n",
8926 afi_safi_print(afi, safi));
8927
8928 if (peer_group_active(p))
8929 vty_out(vty, " %s peer-group member\n",
8930 p->group->name);
8931
8932 paf = peer_af_find(p, afi, safi);
8933 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8934 vty_out(vty, " Update group %" PRIu64
8935 ", subgroup %" PRIu64 "\n",
d62a17ae 8936 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8937 vty_out(vty, " Packet Queue length %d\n",
8938 bpacket_queue_virtual_length(paf));
8939 } else {
8940 vty_out(vty, " Not part of any update group\n");
8941 }
8942 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_SM_RCV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8947 || CHECK_FLAG(p->af_cap[afi][safi],
8948 PEER_CAP_ORF_PREFIX_RM_ADV)
8949 || CHECK_FLAG(p->af_cap[afi][safi],
8950 PEER_CAP_ORF_PREFIX_RM_RCV)
8951 || CHECK_FLAG(p->af_cap[afi][safi],
8952 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8953 vty_out(vty, " AF-dependant capabilities:\n");
8954
8955 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8956 || CHECK_FLAG(p->af_cap[afi][safi],
8957 PEER_CAP_ORF_PREFIX_SM_RCV)
8958 || CHECK_FLAG(p->af_cap[afi][safi],
8959 PEER_CAP_ORF_PREFIX_RM_ADV)
8960 || CHECK_FLAG(p->af_cap[afi][safi],
8961 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8962 vty_out(vty,
8963 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8964 ORF_TYPE_PREFIX);
8965 bgp_show_peer_afi_orf_cap(
8966 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8967 PEER_CAP_ORF_PREFIX_RM_ADV,
8968 PEER_CAP_ORF_PREFIX_SM_RCV,
8969 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8970 }
8971 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8972 || CHECK_FLAG(p->af_cap[afi][safi],
8973 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8974 || CHECK_FLAG(p->af_cap[afi][safi],
8975 PEER_CAP_ORF_PREFIX_RM_ADV)
8976 || CHECK_FLAG(p->af_cap[afi][safi],
8977 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8978 vty_out(vty,
8979 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8980 ORF_TYPE_PREFIX_OLD);
8981 bgp_show_peer_afi_orf_cap(
8982 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8983 PEER_CAP_ORF_PREFIX_RM_ADV,
8984 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8986 }
8987
8988 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8989 orf_pfx_count = prefix_bgp_show_prefix_list(
8990 NULL, afi, orf_pfx_name, use_json);
8991
8992 if (CHECK_FLAG(p->af_sflags[afi][safi],
8993 PEER_STATUS_ORF_PREFIX_SEND)
8994 || orf_pfx_count) {
8995 vty_out(vty, " Outbound Route Filter (ORF):");
8996 if (CHECK_FLAG(p->af_sflags[afi][safi],
8997 PEER_STATUS_ORF_PREFIX_SEND))
8998 vty_out(vty, " sent;");
8999 if (orf_pfx_count)
9000 vty_out(vty, " received (%d entries)",
9001 orf_pfx_count);
9002 vty_out(vty, "\n");
9003 }
9004 if (CHECK_FLAG(p->af_sflags[afi][safi],
9005 PEER_STATUS_ORF_WAIT_REFRESH))
9006 vty_out(vty,
9007 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9008
9009 if (CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_REFLECTOR_CLIENT))
9011 vty_out(vty, " Route-Reflector Client\n");
9012 if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_RSERVER_CLIENT))
9014 vty_out(vty, " Route-Server Client\n");
9015 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9016 vty_out(vty,
9017 " Inbound soft reconfiguration allowed\n");
9018
9019 if (CHECK_FLAG(p->af_flags[afi][safi],
9020 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9021 vty_out(vty,
9022 " Private AS numbers (all) replaced in updates to this neighbor\n");
9023 else if (CHECK_FLAG(p->af_flags[afi][safi],
9024 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9025 vty_out(vty,
9026 " Private AS numbers replaced in updates to this neighbor\n");
9027 else if (CHECK_FLAG(p->af_flags[afi][safi],
9028 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9029 vty_out(vty,
9030 " Private AS numbers (all) removed in updates to this neighbor\n");
9031 else if (CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_REMOVE_PRIVATE_AS))
9033 vty_out(vty,
9034 " Private AS numbers removed in updates to this neighbor\n");
9035
dcc68b5e
MS
9036 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9037 vty_out(vty, " %s\n",
9038 bgp_addpath_names(p->addpath_type[afi][safi])
9039 ->human_description);
d62a17ae 9040
9041 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9042 vty_out(vty,
9043 " Override ASNs in outbound updates if aspath equals remote-as\n");
9044
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_FORCE_NEXTHOP_SELF))
9048 vty_out(vty, " NEXT_HOP is always this router\n");
9049 if (CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_AS_PATH_UNCHANGED))
9051 vty_out(vty,
9052 " AS_PATH is propagated unchanged to this neighbor\n");
9053 if (CHECK_FLAG(p->af_flags[afi][safi],
9054 PEER_FLAG_NEXTHOP_UNCHANGED))
9055 vty_out(vty,
9056 " NEXT_HOP is propagated unchanged to this neighbor\n");
9057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9058 vty_out(vty,
9059 " MED is propagated unchanged to this neighbor\n");
9060 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9061 || CHECK_FLAG(p->af_flags[afi][safi],
9062 PEER_FLAG_SEND_EXT_COMMUNITY)
9063 || CHECK_FLAG(p->af_flags[afi][safi],
9064 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9065 vty_out(vty,
9066 " Community attribute sent to this neighbor");
9067 if (CHECK_FLAG(p->af_flags[afi][safi],
9068 PEER_FLAG_SEND_COMMUNITY)
9069 && CHECK_FLAG(p->af_flags[afi][safi],
9070 PEER_FLAG_SEND_EXT_COMMUNITY)
9071 && CHECK_FLAG(p->af_flags[afi][safi],
9072 PEER_FLAG_SEND_LARGE_COMMUNITY))
9073 vty_out(vty, "(all)\n");
9074 else if (CHECK_FLAG(p->af_flags[afi][safi],
9075 PEER_FLAG_SEND_LARGE_COMMUNITY))
9076 vty_out(vty, "(large)\n");
9077 else if (CHECK_FLAG(p->af_flags[afi][safi],
9078 PEER_FLAG_SEND_EXT_COMMUNITY))
9079 vty_out(vty, "(extended)\n");
9080 else
9081 vty_out(vty, "(standard)\n");
9082 }
9083 if (CHECK_FLAG(p->af_flags[afi][safi],
9084 PEER_FLAG_DEFAULT_ORIGINATE)) {
9085 vty_out(vty, " Default information originate,");
9086
9087 if (p->default_rmap[afi][safi].name)
9088 vty_out(vty, " default route-map %s%s,",
9089 p->default_rmap[afi][safi].map ? "*"
9090 : "",
9091 p->default_rmap[afi][safi].name);
9092 if (paf && PAF_SUBGRP(paf)
9093 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9094 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9095 vty_out(vty, " default sent\n");
9096 else
9097 vty_out(vty, " default not sent\n");
9098 }
9099
dff8f48d
MK
9100 /* advertise-vni-all */
9101 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9102 if (is_evpn_enabled())
dff8f48d
MK
9103 vty_out(vty, " advertise-all-vni\n");
9104 }
9105
d62a17ae 9106 if (filter->plist[FILTER_IN].name
9107 || filter->dlist[FILTER_IN].name
9108 || filter->aslist[FILTER_IN].name
9109 || filter->map[RMAP_IN].name)
9110 vty_out(vty, " Inbound path policy configured\n");
9111 if (filter->plist[FILTER_OUT].name
9112 || filter->dlist[FILTER_OUT].name
9113 || filter->aslist[FILTER_OUT].name
9114 || filter->map[RMAP_OUT].name || filter->usmap.name)
9115 vty_out(vty, " Outbound path policy configured\n");
9116
9117 /* prefix-list */
9118 if (filter->plist[FILTER_IN].name)
9119 vty_out(vty,
9120 " Incoming update prefix filter list is %s%s\n",
9121 filter->plist[FILTER_IN].plist ? "*" : "",
9122 filter->plist[FILTER_IN].name);
9123 if (filter->plist[FILTER_OUT].name)
9124 vty_out(vty,
9125 " Outgoing update prefix filter list is %s%s\n",
9126 filter->plist[FILTER_OUT].plist ? "*" : "",
9127 filter->plist[FILTER_OUT].name);
9128
9129 /* distribute-list */
9130 if (filter->dlist[FILTER_IN].name)
9131 vty_out(vty,
9132 " Incoming update network filter list is %s%s\n",
9133 filter->dlist[FILTER_IN].alist ? "*" : "",
9134 filter->dlist[FILTER_IN].name);
9135 if (filter->dlist[FILTER_OUT].name)
9136 vty_out(vty,
9137 " Outgoing update network filter list is %s%s\n",
9138 filter->dlist[FILTER_OUT].alist ? "*" : "",
9139 filter->dlist[FILTER_OUT].name);
9140
9141 /* filter-list. */
9142 if (filter->aslist[FILTER_IN].name)
9143 vty_out(vty,
9144 " Incoming update AS path filter list is %s%s\n",
9145 filter->aslist[FILTER_IN].aslist ? "*" : "",
9146 filter->aslist[FILTER_IN].name);
9147 if (filter->aslist[FILTER_OUT].name)
9148 vty_out(vty,
9149 " Outgoing update AS path filter list is %s%s\n",
9150 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9151 filter->aslist[FILTER_OUT].name);
9152
9153 /* route-map. */
9154 if (filter->map[RMAP_IN].name)
9155 vty_out(vty,
9156 " Route map for incoming advertisements is %s%s\n",
9157 filter->map[RMAP_IN].map ? "*" : "",
9158 filter->map[RMAP_IN].name);
9159 if (filter->map[RMAP_OUT].name)
9160 vty_out(vty,
9161 " Route map for outgoing advertisements is %s%s\n",
9162 filter->map[RMAP_OUT].map ? "*" : "",
9163 filter->map[RMAP_OUT].name);
9164
9dac9fc8
DA
9165 /* ebgp-requires-policy (inbound) */
9166 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9167 && !bgp_inbound_policy_exists(p, filter))
9168 vty_out(vty,
9169 " Inbound updates discarded due to missing policy\n");
9170
9171 /* ebgp-requires-policy (outbound) */
9172 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9173 && !bgp_outbound_policy_exists(p, filter))
9174 vty_out(vty,
9175 " Outbound updates discarded due to missing policy\n");
9176
d62a17ae 9177 /* unsuppress-map */
9178 if (filter->usmap.name)
9179 vty_out(vty,
9180 " Route map for selective unsuppress is %s%s\n",
9181 filter->usmap.map ? "*" : "",
9182 filter->usmap.name);
9183
9184 /* Receive prefix count */
3b59184d
DA
9185 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
9186 p->pcount[afi][safi]);
d62a17ae 9187
9188 /* Maximum prefix */
9189 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
3b59184d
DA
9190 vty_out(vty,
9191 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 9192 p->pmax[afi][safi],
9193 CHECK_FLAG(p->af_flags[afi][safi],
9194 PEER_FLAG_MAX_PREFIX_WARNING)
9195 ? " (warning-only)"
9196 : "");
9197 vty_out(vty, " Threshold for warning message %d%%",
9198 p->pmax_threshold[afi][safi]);
9199 if (p->pmax_restart[afi][safi])
9200 vty_out(vty, ", restart interval %d min",
9201 p->pmax_restart[afi][safi]);
9202 vty_out(vty, "\n");
9203 }
9204
9205 vty_out(vty, "\n");
9206 }
9207}
9208
9f049418 9209static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9210 json_object *json)
718e3744 9211{
d62a17ae 9212 struct bgp *bgp;
9213 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9214 char timebuf[BGP_UPTIME_LEN];
9215 char dn_flag[2];
9216 const char *subcode_str;
9217 const char *code_str;
9218 afi_t afi;
9219 safi_t safi;
d7c0a89a
QY
9220 uint16_t i;
9221 uint8_t *msg;
d62a17ae 9222 json_object *json_neigh = NULL;
9223 time_t epoch_tbuf;
718e3744 9224
d62a17ae 9225 bgp = p->bgp;
9226
9227 if (use_json)
9228 json_neigh = json_object_new_object();
9229
9230 memset(dn_flag, '\0', sizeof(dn_flag));
9231 if (!p->conf_if && peer_dynamic_neighbor(p))
9232 dn_flag[0] = '*';
9233
9234 if (!use_json) {
9235 if (p->conf_if) /* Configured interface name. */
9236 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9237 BGP_PEER_SU_UNSPEC(p)
9238 ? "None"
9239 : sockunion2str(&p->su, buf,
9240 SU_ADDRSTRLEN));
9241 else /* Configured IP address. */
9242 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9243 p->host);
9244 }
9245
9246 if (use_json) {
9247 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9248 json_object_string_add(json_neigh, "bgpNeighborAddr",
9249 "none");
9250 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9251 json_object_string_add(
9252 json_neigh, "bgpNeighborAddr",
9253 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9254
9255 json_object_int_add(json_neigh, "remoteAs", p->as);
9256
9257 if (p->change_local_as)
9258 json_object_int_add(json_neigh, "localAs",
9259 p->change_local_as);
9260 else
9261 json_object_int_add(json_neigh, "localAs", p->local_as);
9262
9263 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9264 json_object_boolean_true_add(json_neigh,
9265 "localAsNoPrepend");
9266
9267 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9268 json_object_boolean_true_add(json_neigh,
9269 "localAsReplaceAs");
9270 } else {
9271 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9272 || (p->as_type == AS_INTERNAL))
9273 vty_out(vty, "remote AS %u, ", p->as);
9274 else
9275 vty_out(vty, "remote AS Unspecified, ");
9276 vty_out(vty, "local AS %u%s%s, ",
9277 p->change_local_as ? p->change_local_as : p->local_as,
9278 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9279 ? " no-prepend"
9280 : "",
9281 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9282 ? " replace-as"
9283 : "");
9284 }
faa16034
DS
9285 /* peer type internal or confed-internal */
9286 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9287 if (use_json) {
9288 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9289 json_object_boolean_true_add(
9290 json_neigh, "nbrConfedInternalLink");
9291 else
9292 json_object_boolean_true_add(json_neigh,
9293 "nbrInternalLink");
9294 } else {
9295 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9296 vty_out(vty, "confed-internal link\n");
9297 else
9298 vty_out(vty, "internal link\n");
9299 }
faa16034
DS
9300 /* peer type external or confed-external */
9301 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9302 if (use_json) {
9303 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9304 json_object_boolean_true_add(
9305 json_neigh, "nbrConfedExternalLink");
9306 else
9307 json_object_boolean_true_add(json_neigh,
9308 "nbrExternalLink");
9309 } else {
9310 if (bgp_confederation_peers_check(bgp, p->as))
9311 vty_out(vty, "confed-external link\n");
9312 else
9313 vty_out(vty, "external link\n");
9314 }
faa16034
DS
9315 } else {
9316 if (use_json)
9317 json_object_boolean_true_add(json_neigh,
9318 "nbrUnspecifiedLink");
9319 else
9320 vty_out(vty, "unspecified link\n");
d62a17ae 9321 }
9322
9323 /* Description. */
9324 if (p->desc) {
9325 if (use_json)
9326 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9327 else
9328 vty_out(vty, " Description: %s\n", p->desc);
9329 }
9330
9331 if (p->hostname) {
9332 if (use_json) {
9333 if (p->hostname)
9334 json_object_string_add(json_neigh, "hostname",
9335 p->hostname);
9336
9337 if (p->domainname)
9338 json_object_string_add(json_neigh, "domainname",
9339 p->domainname);
9340 } else {
9341 if (p->domainname && (p->domainname[0] != '\0'))
9342 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9343 p->domainname);
9344 else
9345 vty_out(vty, "Hostname: %s\n", p->hostname);
9346 }
9347 }
9348
9349 /* Peer-group */
9350 if (p->group) {
9351 if (use_json) {
9352 json_object_string_add(json_neigh, "peerGroup",
9353 p->group->name);
9354
9355 if (dn_flag[0]) {
9356 struct prefix prefix, *range = NULL;
9357
9358 sockunion2hostprefix(&(p->su), &prefix);
9359 range = peer_group_lookup_dynamic_neighbor_range(
9360 p->group, &prefix);
9361
9362 if (range) {
9363 prefix2str(range, buf1, sizeof(buf1));
9364 json_object_string_add(
9365 json_neigh,
9366 "peerSubnetRangeGroup", buf1);
9367 }
9368 }
9369 } else {
9370 vty_out(vty,
9371 " Member of peer-group %s for session parameters\n",
9372 p->group->name);
9373
9374 if (dn_flag[0]) {
9375 struct prefix prefix, *range = NULL;
9376
9377 sockunion2hostprefix(&(p->su), &prefix);
9378 range = peer_group_lookup_dynamic_neighbor_range(
9379 p->group, &prefix);
9380
9381 if (range) {
9382 prefix2str(range, buf1, sizeof(buf1));
9383 vty_out(vty,
9384 " Belongs to the subnet range group: %s\n",
9385 buf1);
9386 }
9387 }
9388 }
9389 }
9390
9391 if (use_json) {
9392 /* Administrative shutdown. */
9393 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9394 json_object_boolean_true_add(json_neigh,
9395 "adminShutDown");
9396
9397 /* BGP Version. */
9398 json_object_int_add(json_neigh, "bgpVersion", 4);
9399 json_object_string_add(
9400 json_neigh, "remoteRouterId",
9401 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9402 json_object_string_add(
9403 json_neigh, "localRouterId",
9404 inet_ntop(AF_INET, &bgp->router_id, buf1,
9405 sizeof(buf1)));
d62a17ae 9406
9407 /* Confederation */
9408 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9409 && bgp_confederation_peers_check(bgp, p->as))
9410 json_object_boolean_true_add(json_neigh,
9411 "nbrCommonAdmin");
9412
9413 /* Status. */
9414 json_object_string_add(
9415 json_neigh, "bgpState",
9416 lookup_msg(bgp_status_msg, p->status, NULL));
9417
9418 if (p->status == Established) {
9419 time_t uptime;
d62a17ae 9420
9421 uptime = bgp_clock();
9422 uptime -= p->uptime;
d62a17ae 9423 epoch_tbuf = time(NULL) - uptime;
9424
bee57a7a 9425#if CONFDATE > 20200101
a4d82a8a
PZ
9426 CPP_NOTICE(
9427 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9428#endif
9429 /*
9430 * bgpTimerUp was miliseconds that was accurate
9431 * up to 1 day, then the value returned
9432 * became garbage. So in order to provide
9433 * some level of backwards compatability,
9434 * we still provde the data, but now
9435 * we are returning the correct value
9436 * and also adding a new bgpTimerUpMsec
9437 * which will allow us to deprecate
9438 * this eventually
9439 */
d62a17ae 9440 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9441 uptime * 1000);
d3c7efed
DS
9442 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9443 uptime * 1000);
d62a17ae 9444 json_object_string_add(json_neigh, "bgpTimerUpString",
9445 peer_uptime(p->uptime, timebuf,
9446 BGP_UPTIME_LEN, 0,
9447 NULL));
9448 json_object_int_add(json_neigh,
9449 "bgpTimerUpEstablishedEpoch",
9450 epoch_tbuf);
9451 }
9452
9453 else if (p->status == Active) {
9454 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9455 json_object_string_add(json_neigh, "bgpStateIs",
9456 "passive");
9457 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9458 json_object_string_add(json_neigh, "bgpStateIs",
9459 "passiveNSF");
9460 }
9461
9462 /* read timer */
9463 time_t uptime;
9464 struct tm *tm;
9465
9466 uptime = bgp_clock();
9467 uptime -= p->readtime;
9468 tm = gmtime(&uptime);
9469 json_object_int_add(json_neigh, "bgpTimerLastRead",
9470 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9471 + (tm->tm_hour * 3600000));
9472
9473 uptime = bgp_clock();
9474 uptime -= p->last_write;
9475 tm = gmtime(&uptime);
9476 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9477 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9478 + (tm->tm_hour * 3600000));
9479
9480 uptime = bgp_clock();
9481 uptime -= p->update_time;
9482 tm = gmtime(&uptime);
9483 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9484 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9485 + (tm->tm_hour * 3600000));
9486
9487 /* Configured timer values. */
9488 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9489 p->v_holdtime * 1000);
9490 json_object_int_add(json_neigh,
9491 "bgpTimerKeepAliveIntervalMsecs",
9492 p->v_keepalive * 1000);
b90a8e13 9493 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9494 json_object_int_add(json_neigh,
9495 "bgpTimerConfiguredHoldTimeMsecs",
9496 p->holdtime * 1000);
9497 json_object_int_add(
9498 json_neigh,
9499 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9500 p->keepalive * 1000);
d25e4efc 9501 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9502 || (bgp->default_keepalive
9503 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9504 json_object_int_add(json_neigh,
9505 "bgpTimerConfiguredHoldTimeMsecs",
9506 bgp->default_holdtime);
9507 json_object_int_add(
9508 json_neigh,
9509 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9510 bgp->default_keepalive);
d62a17ae 9511 }
9512 } else {
9513 /* Administrative shutdown. */
9514 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9515 vty_out(vty, " Administratively shut down\n");
9516
9517 /* BGP Version. */
9518 vty_out(vty, " BGP version 4");
0e38aeb4 9519 vty_out(vty, ", remote router ID %s",
d62a17ae 9520 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9521 vty_out(vty, ", local router ID %s\n",
9522 inet_ntop(AF_INET, &bgp->router_id, buf1,
9523 sizeof(buf1)));
d62a17ae 9524
9525 /* Confederation */
9526 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9527 && bgp_confederation_peers_check(bgp, p->as))
9528 vty_out(vty,
9529 " Neighbor under common administration\n");
9530
9531 /* Status. */
9532 vty_out(vty, " BGP state = %s",
9533 lookup_msg(bgp_status_msg, p->status, NULL));
9534
9535 if (p->status == Established)
9536 vty_out(vty, ", up for %8s",
9537 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9538 0, NULL));
9539
9540 else if (p->status == Active) {
9541 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9542 vty_out(vty, " (passive)");
9543 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9544 vty_out(vty, " (NSF passive)");
9545 }
9546 vty_out(vty, "\n");
9547
9548 /* read timer */
9549 vty_out(vty, " Last read %s",
9550 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9551 NULL));
9552 vty_out(vty, ", Last write %s\n",
9553 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9554 NULL));
9555
9556 /* Configured timer values. */
9557 vty_out(vty,
9558 " Hold time is %d, keepalive interval is %d seconds\n",
9559 p->v_holdtime, p->v_keepalive);
b90a8e13 9560 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9561 vty_out(vty, " Configured hold time is %d",
9562 p->holdtime);
9563 vty_out(vty, ", keepalive interval is %d seconds\n",
9564 p->keepalive);
d25e4efc 9565 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9566 || (bgp->default_keepalive
9567 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9568 vty_out(vty, " Configured hold time is %d",
9569 bgp->default_holdtime);
9570 vty_out(vty, ", keepalive interval is %d seconds\n",
9571 bgp->default_keepalive);
d62a17ae 9572 }
9573 }
9574 /* Capability. */
9575 if (p->status == Established) {
9576 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9577 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9578 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9579 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9580 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9581 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9582 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9583 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9584 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9585 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9586 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9587 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9588 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9589 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9590 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9591 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9592 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9593 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9594 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9595 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9596 if (use_json) {
9597 json_object *json_cap = NULL;
9598
9599 json_cap = json_object_new_object();
9600
9601 /* AS4 */
9602 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9603 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9604 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9605 && CHECK_FLAG(p->cap,
9606 PEER_CAP_AS4_RCV))
9607 json_object_string_add(
9608 json_cap, "4byteAs",
9609 "advertisedAndReceived");
9610 else if (CHECK_FLAG(p->cap,
9611 PEER_CAP_AS4_ADV))
9612 json_object_string_add(
9613 json_cap, "4byteAs",
9614 "advertised");
9615 else if (CHECK_FLAG(p->cap,
9616 PEER_CAP_AS4_RCV))
9617 json_object_string_add(
9618 json_cap, "4byteAs",
9619 "received");
9620 }
9621
9622 /* AddPath */
9623 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9624 || CHECK_FLAG(p->cap,
9625 PEER_CAP_ADDPATH_ADV)) {
9626 json_object *json_add = NULL;
9627 const char *print_store;
9628
9629 json_add = json_object_new_object();
9630
05c7a1cc
QY
9631 FOREACH_AFI_SAFI (afi, safi) {
9632 json_object *json_sub = NULL;
9633 json_sub =
9634 json_object_new_object();
9635 print_store = afi_safi_print(
9636 afi, safi);
d62a17ae 9637
05c7a1cc
QY
9638 if (CHECK_FLAG(
9639 p->af_cap[afi]
9640 [safi],
9641 PEER_CAP_ADDPATH_AF_TX_ADV)
9642 || CHECK_FLAG(
9643 p->af_cap[afi]
9644 [safi],
9645 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9646 if (CHECK_FLAG(
9647 p->af_cap
9648 [afi]
9649 [safi],
9650 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9651 && CHECK_FLAG(
d62a17ae 9652 p->af_cap
9653 [afi]
9654 [safi],
05c7a1cc
QY
9655 PEER_CAP_ADDPATH_AF_TX_RCV))
9656 json_object_boolean_true_add(
9657 json_sub,
9658 "txAdvertisedAndReceived");
9659 else if (
9660 CHECK_FLAG(
9661 p->af_cap
9662 [afi]
9663 [safi],
9664 PEER_CAP_ADDPATH_AF_TX_ADV))
9665 json_object_boolean_true_add(
9666 json_sub,
9667 "txAdvertised");
9668 else if (
9669 CHECK_FLAG(
9670 p->af_cap
9671 [afi]
9672 [safi],
9673 PEER_CAP_ADDPATH_AF_TX_RCV))
9674 json_object_boolean_true_add(
9675 json_sub,
9676 "txReceived");
9677 }
d62a17ae 9678
05c7a1cc
QY
9679 if (CHECK_FLAG(
9680 p->af_cap[afi]
9681 [safi],
9682 PEER_CAP_ADDPATH_AF_RX_ADV)
9683 || CHECK_FLAG(
9684 p->af_cap[afi]
9685 [safi],
9686 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9687 if (CHECK_FLAG(
9688 p->af_cap
9689 [afi]
9690 [safi],
9691 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9692 && CHECK_FLAG(
d62a17ae 9693 p->af_cap
9694 [afi]
9695 [safi],
9696 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9697 json_object_boolean_true_add(
9698 json_sub,
9699 "rxAdvertisedAndReceived");
9700 else if (
9701 CHECK_FLAG(
9702 p->af_cap
9703 [afi]
9704 [safi],
9705 PEER_CAP_ADDPATH_AF_RX_ADV))
9706 json_object_boolean_true_add(
9707 json_sub,
9708 "rxAdvertised");
9709 else if (
9710 CHECK_FLAG(
9711 p->af_cap
9712 [afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_RX_RCV))
9715 json_object_boolean_true_add(
9716 json_sub,
9717 "rxReceived");
d62a17ae 9718 }
9719
05c7a1cc
QY
9720 if (CHECK_FLAG(
9721 p->af_cap[afi]
9722 [safi],
9723 PEER_CAP_ADDPATH_AF_TX_ADV)
9724 || CHECK_FLAG(
9725 p->af_cap[afi]
9726 [safi],
9727 PEER_CAP_ADDPATH_AF_TX_RCV)
9728 || CHECK_FLAG(
9729 p->af_cap[afi]
9730 [safi],
9731 PEER_CAP_ADDPATH_AF_RX_ADV)
9732 || CHECK_FLAG(
9733 p->af_cap[afi]
9734 [safi],
9735 PEER_CAP_ADDPATH_AF_RX_RCV))
9736 json_object_object_add(
9737 json_add,
9738 print_store,
9739 json_sub);
9740 else
9741 json_object_free(
9742 json_sub);
9743 }
9744
d62a17ae 9745 json_object_object_add(
9746 json_cap, "addPath", json_add);
9747 }
9748
9749 /* Dynamic */
9750 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9751 || CHECK_FLAG(p->cap,
9752 PEER_CAP_DYNAMIC_ADV)) {
9753 if (CHECK_FLAG(p->cap,
9754 PEER_CAP_DYNAMIC_ADV)
9755 && CHECK_FLAG(p->cap,
9756 PEER_CAP_DYNAMIC_RCV))
9757 json_object_string_add(
9758 json_cap, "dynamic",
9759 "advertisedAndReceived");
9760 else if (CHECK_FLAG(
9761 p->cap,
9762 PEER_CAP_DYNAMIC_ADV))
9763 json_object_string_add(
9764 json_cap, "dynamic",
9765 "advertised");
9766 else if (CHECK_FLAG(
9767 p->cap,
9768 PEER_CAP_DYNAMIC_RCV))
9769 json_object_string_add(
9770 json_cap, "dynamic",
9771 "received");
9772 }
9773
9774 /* Extended nexthop */
9775 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9776 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9777 json_object *json_nxt = NULL;
9778 const char *print_store;
9779
9780
9781 if (CHECK_FLAG(p->cap,
9782 PEER_CAP_ENHE_ADV)
9783 && CHECK_FLAG(p->cap,
9784 PEER_CAP_ENHE_RCV))
9785 json_object_string_add(
9786 json_cap,
9787 "extendedNexthop",
9788 "advertisedAndReceived");
9789 else if (CHECK_FLAG(p->cap,
9790 PEER_CAP_ENHE_ADV))
9791 json_object_string_add(
9792 json_cap,
9793 "extendedNexthop",
9794 "advertised");
9795 else if (CHECK_FLAG(p->cap,
9796 PEER_CAP_ENHE_RCV))
9797 json_object_string_add(
9798 json_cap,
9799 "extendedNexthop",
9800 "received");
9801
9802 if (CHECK_FLAG(p->cap,
9803 PEER_CAP_ENHE_RCV)) {
9804 json_nxt =
9805 json_object_new_object();
9806
9807 for (safi = SAFI_UNICAST;
9808 safi < SAFI_MAX; safi++) {
9809 if (CHECK_FLAG(
9810 p->af_cap
9811 [AFI_IP]
9812 [safi],
9813 PEER_CAP_ENHE_AF_RCV)) {
9814 print_store = afi_safi_print(
9815 AFI_IP,
9816 safi);
9817 json_object_string_add(
9818 json_nxt,
9819 print_store,
54f29523 9820 "recieved"); /* misspelled for compatibility */
d62a17ae 9821 }
9822 }
9823 json_object_object_add(
9824 json_cap,
9825 "extendedNexthopFamililesByPeer",
9826 json_nxt);
9827 }
9828 }
9829
9830 /* Route Refresh */
9831 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9832 || CHECK_FLAG(p->cap,
9833 PEER_CAP_REFRESH_NEW_RCV)
9834 || CHECK_FLAG(p->cap,
9835 PEER_CAP_REFRESH_OLD_RCV)) {
9836 if (CHECK_FLAG(p->cap,
9837 PEER_CAP_REFRESH_ADV)
9838 && (CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_NEW_RCV)
9841 || CHECK_FLAG(
9842 p->cap,
9843 PEER_CAP_REFRESH_OLD_RCV))) {
9844 if (CHECK_FLAG(
9845 p->cap,
9846 PEER_CAP_REFRESH_OLD_RCV)
9847 && CHECK_FLAG(
9848 p->cap,
9849 PEER_CAP_REFRESH_NEW_RCV))
9850 json_object_string_add(
9851 json_cap,
9852 "routeRefresh",
9853 "advertisedAndReceivedOldNew");
9854 else {
9855 if (CHECK_FLAG(
9856 p->cap,
9857 PEER_CAP_REFRESH_OLD_RCV))
9858 json_object_string_add(
9859 json_cap,
9860 "routeRefresh",
9861 "advertisedAndReceivedOld");
9862 else
9863 json_object_string_add(
9864 json_cap,
9865 "routeRefresh",
9866 "advertisedAndReceivedNew");
9867 }
9868 } else if (
9869 CHECK_FLAG(
9870 p->cap,
9871 PEER_CAP_REFRESH_ADV))
9872 json_object_string_add(
9873 json_cap,
9874 "routeRefresh",
9875 "advertised");
9876 else if (
9877 CHECK_FLAG(
9878 p->cap,
9879 PEER_CAP_REFRESH_NEW_RCV)
9880 || CHECK_FLAG(
9881 p->cap,
9882 PEER_CAP_REFRESH_OLD_RCV))
9883 json_object_string_add(
9884 json_cap,
9885 "routeRefresh",
9886 "received");
9887 }
9888
9889 /* Multiprotocol Extensions */
9890 json_object *json_multi = NULL;
9891 json_multi = json_object_new_object();
9892
05c7a1cc
QY
9893 FOREACH_AFI_SAFI (afi, safi) {
9894 if (p->afc_adv[afi][safi]
9895 || p->afc_recv[afi][safi]) {
9896 json_object *json_exten = NULL;
9897 json_exten =
9898 json_object_new_object();
9899
d62a17ae 9900 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9901 && p->afc_recv[afi][safi])
9902 json_object_boolean_true_add(
9903 json_exten,
9904 "advertisedAndReceived");
9905 else if (p->afc_adv[afi][safi])
9906 json_object_boolean_true_add(
9907 json_exten,
9908 "advertised");
9909 else if (p->afc_recv[afi][safi])
9910 json_object_boolean_true_add(
9911 json_exten,
9912 "received");
d62a17ae 9913
05c7a1cc
QY
9914 json_object_object_add(
9915 json_multi,
9916 afi_safi_print(afi,
9917 safi),
9918 json_exten);
d62a17ae 9919 }
9920 }
9921 json_object_object_add(
9922 json_cap, "multiprotocolExtensions",
9923 json_multi);
9924
d77114b7 9925 /* Hostname capabilities */
60466a63 9926 json_object *json_hname = NULL;
d77114b7
MK
9927
9928 json_hname = json_object_new_object();
9929
9930 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9931 json_object_string_add(
60466a63
QY
9932 json_hname, "advHostName",
9933 bgp->peer_self->hostname
9934 ? bgp->peer_self
9935 ->hostname
d77114b7
MK
9936 : "n/a");
9937 json_object_string_add(
60466a63
QY
9938 json_hname, "advDomainName",
9939 bgp->peer_self->domainname
9940 ? bgp->peer_self
9941 ->domainname
d77114b7
MK
9942 : "n/a");
9943 }
9944
9945
9946 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9947 json_object_string_add(
60466a63
QY
9948 json_hname, "rcvHostName",
9949 p->hostname ? p->hostname
9950 : "n/a");
d77114b7 9951 json_object_string_add(
60466a63
QY
9952 json_hname, "rcvDomainName",
9953 p->domainname ? p->domainname
9954 : "n/a");
d77114b7
MK
9955 }
9956
60466a63 9957 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9958 json_hname);
9959
d62a17ae 9960 /* Gracefull Restart */
9961 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9962 || CHECK_FLAG(p->cap,
9963 PEER_CAP_RESTART_ADV)) {
9964 if (CHECK_FLAG(p->cap,
9965 PEER_CAP_RESTART_ADV)
9966 && CHECK_FLAG(p->cap,
9967 PEER_CAP_RESTART_RCV))
9968 json_object_string_add(
9969 json_cap,
9970 "gracefulRestart",
9971 "advertisedAndReceived");
9972 else if (CHECK_FLAG(
9973 p->cap,
9974 PEER_CAP_RESTART_ADV))
9975 json_object_string_add(
9976 json_cap,
9977 "gracefulRestartCapability",
9978 "advertised");
9979 else if (CHECK_FLAG(
9980 p->cap,
9981 PEER_CAP_RESTART_RCV))
9982 json_object_string_add(
9983 json_cap,
9984 "gracefulRestartCapability",
9985 "received");
9986
9987 if (CHECK_FLAG(p->cap,
9988 PEER_CAP_RESTART_RCV)) {
9989 int restart_af_count = 0;
9990 json_object *json_restart =
9991 NULL;
9992 json_restart =
9993 json_object_new_object();
9994
9995 json_object_int_add(
9996 json_cap,
9997 "gracefulRestartRemoteTimerMsecs",
9998 p->v_gr_restart * 1000);
9999
05c7a1cc
QY
10000 FOREACH_AFI_SAFI (afi, safi) {
10001 if (CHECK_FLAG(
10002 p->af_cap
10003 [afi]
10004 [safi],
10005 PEER_CAP_RESTART_AF_RCV)) {
10006 json_object *
10007 json_sub =
10008 NULL;
10009 json_sub =
10010 json_object_new_object();
10011
d62a17ae 10012 if (CHECK_FLAG(
10013 p->af_cap
10014 [afi]
10015 [safi],
05c7a1cc
QY
10016 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10017 json_object_boolean_true_add(
10018 json_sub,
10019 "preserved");
10020 restart_af_count++;
10021 json_object_object_add(
10022 json_restart,
10023 afi_safi_print(
10024 afi,
10025 safi),
10026 json_sub);
d62a17ae 10027 }
10028 }
10029 if (!restart_af_count) {
10030 json_object_string_add(
10031 json_cap,
10032 "addressFamiliesByPeer",
10033 "none");
10034 json_object_free(
10035 json_restart);
10036 } else
10037 json_object_object_add(
10038 json_cap,
10039 "addressFamiliesByPeer",
10040 json_restart);
10041 }
10042 }
10043 json_object_object_add(json_neigh,
10044 "neighborCapabilities",
10045 json_cap);
10046 } else {
10047 vty_out(vty, " Neighbor capabilities:\n");
10048
10049 /* AS4 */
10050 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10051 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10052 vty_out(vty, " 4 Byte AS:");
10053 if (CHECK_FLAG(p->cap,
10054 PEER_CAP_AS4_ADV))
10055 vty_out(vty, " advertised");
10056 if (CHECK_FLAG(p->cap,
10057 PEER_CAP_AS4_RCV))
10058 vty_out(vty, " %sreceived",
10059 CHECK_FLAG(
10060 p->cap,
10061 PEER_CAP_AS4_ADV)
10062 ? "and "
10063 : "");
10064 vty_out(vty, "\n");
10065 }
10066
10067 /* AddPath */
10068 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10069 || CHECK_FLAG(p->cap,
10070 PEER_CAP_ADDPATH_ADV)) {
10071 vty_out(vty, " AddPath:\n");
10072
05c7a1cc
QY
10073 FOREACH_AFI_SAFI (afi, safi) {
10074 if (CHECK_FLAG(
10075 p->af_cap[afi]
10076 [safi],
10077 PEER_CAP_ADDPATH_AF_TX_ADV)
10078 || CHECK_FLAG(
10079 p->af_cap[afi]
10080 [safi],
10081 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10082 vty_out(vty,
10083 " %s: TX ",
10084 afi_safi_print(
10085 afi,
10086 safi));
10087
d62a17ae 10088 if (CHECK_FLAG(
10089 p->af_cap
10090 [afi]
10091 [safi],
05c7a1cc 10092 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10093 vty_out(vty,
05c7a1cc 10094 "advertised %s",
d62a17ae 10095 afi_safi_print(
10096 afi,
10097 safi));
10098
05c7a1cc
QY
10099 if (CHECK_FLAG(
10100 p->af_cap
10101 [afi]
10102 [safi],
10103 PEER_CAP_ADDPATH_AF_TX_RCV))
10104 vty_out(vty,
10105 "%sreceived",
10106 CHECK_FLAG(
10107 p->af_cap
10108 [afi]
10109 [safi],
10110 PEER_CAP_ADDPATH_AF_TX_ADV)
10111 ? " and "
10112 : "");
d62a17ae 10113
05c7a1cc
QY
10114 vty_out(vty, "\n");
10115 }
d62a17ae 10116
05c7a1cc
QY
10117 if (CHECK_FLAG(
10118 p->af_cap[afi]
10119 [safi],
10120 PEER_CAP_ADDPATH_AF_RX_ADV)
10121 || CHECK_FLAG(
10122 p->af_cap[afi]
10123 [safi],
10124 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10125 vty_out(vty,
10126 " %s: RX ",
10127 afi_safi_print(
10128 afi,
10129 safi));
d62a17ae 10130
10131 if (CHECK_FLAG(
10132 p->af_cap
10133 [afi]
10134 [safi],
05c7a1cc 10135 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10136 vty_out(vty,
05c7a1cc 10137 "advertised %s",
d62a17ae 10138 afi_safi_print(
10139 afi,
10140 safi));
10141
05c7a1cc
QY
10142 if (CHECK_FLAG(
10143 p->af_cap
10144 [afi]
10145 [safi],
10146 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10147 vty_out(vty,
05c7a1cc
QY
10148 "%sreceived",
10149 CHECK_FLAG(
10150 p->af_cap
10151 [afi]
10152 [safi],
10153 PEER_CAP_ADDPATH_AF_RX_ADV)
10154 ? " and "
10155 : "");
10156
10157 vty_out(vty, "\n");
d62a17ae 10158 }
05c7a1cc 10159 }
d62a17ae 10160 }
10161
10162 /* Dynamic */
10163 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10164 || CHECK_FLAG(p->cap,
10165 PEER_CAP_DYNAMIC_ADV)) {
10166 vty_out(vty, " Dynamic:");
10167 if (CHECK_FLAG(p->cap,
10168 PEER_CAP_DYNAMIC_ADV))
10169 vty_out(vty, " advertised");
10170 if (CHECK_FLAG(p->cap,
10171 PEER_CAP_DYNAMIC_RCV))
10172 vty_out(vty, " %sreceived",
10173 CHECK_FLAG(
10174 p->cap,
10175 PEER_CAP_DYNAMIC_ADV)
10176 ? "and "
10177 : "");
10178 vty_out(vty, "\n");
10179 }
10180
10181 /* Extended nexthop */
10182 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10183 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10184 vty_out(vty, " Extended nexthop:");
10185 if (CHECK_FLAG(p->cap,
10186 PEER_CAP_ENHE_ADV))
10187 vty_out(vty, " advertised");
10188 if (CHECK_FLAG(p->cap,
10189 PEER_CAP_ENHE_RCV))
10190 vty_out(vty, " %sreceived",
10191 CHECK_FLAG(
10192 p->cap,
10193 PEER_CAP_ENHE_ADV)
10194 ? "and "
10195 : "");
10196 vty_out(vty, "\n");
10197
10198 if (CHECK_FLAG(p->cap,
10199 PEER_CAP_ENHE_RCV)) {
10200 vty_out(vty,
10201 " Address families by peer:\n ");
10202 for (safi = SAFI_UNICAST;
10203 safi < SAFI_MAX; safi++)
10204 if (CHECK_FLAG(
10205 p->af_cap
10206 [AFI_IP]
10207 [safi],
10208 PEER_CAP_ENHE_AF_RCV))
10209 vty_out(vty,
10210 " %s\n",
10211 afi_safi_print(
10212 AFI_IP,
10213 safi));
10214 }
10215 }
10216
10217 /* Route Refresh */
10218 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10219 || CHECK_FLAG(p->cap,
10220 PEER_CAP_REFRESH_NEW_RCV)
10221 || CHECK_FLAG(p->cap,
10222 PEER_CAP_REFRESH_OLD_RCV)) {
10223 vty_out(vty, " Route refresh:");
10224 if (CHECK_FLAG(p->cap,
10225 PEER_CAP_REFRESH_ADV))
10226 vty_out(vty, " advertised");
10227 if (CHECK_FLAG(p->cap,
10228 PEER_CAP_REFRESH_NEW_RCV)
10229 || CHECK_FLAG(
10230 p->cap,
10231 PEER_CAP_REFRESH_OLD_RCV))
10232 vty_out(vty, " %sreceived(%s)",
10233 CHECK_FLAG(
10234 p->cap,
10235 PEER_CAP_REFRESH_ADV)
10236 ? "and "
10237 : "",
10238 (CHECK_FLAG(
10239 p->cap,
10240 PEER_CAP_REFRESH_OLD_RCV)
10241 && CHECK_FLAG(
10242 p->cap,
10243 PEER_CAP_REFRESH_NEW_RCV))
10244 ? "old & new"
10245 : CHECK_FLAG(
10246 p->cap,
10247 PEER_CAP_REFRESH_OLD_RCV)
10248 ? "old"
10249 : "new");
10250
10251 vty_out(vty, "\n");
10252 }
10253
10254 /* Multiprotocol Extensions */
05c7a1cc
QY
10255 FOREACH_AFI_SAFI (afi, safi)
10256 if (p->afc_adv[afi][safi]
10257 || p->afc_recv[afi][safi]) {
10258 vty_out(vty,
10259 " Address Family %s:",
10260 afi_safi_print(afi,
10261 safi));
10262 if (p->afc_adv[afi][safi])
d62a17ae 10263 vty_out(vty,
05c7a1cc
QY
10264 " advertised");
10265 if (p->afc_recv[afi][safi])
10266 vty_out(vty,
10267 " %sreceived",
10268 p->afc_adv[afi]
10269 [safi]
10270 ? "and "
10271 : "");
10272 vty_out(vty, "\n");
10273 }
d62a17ae 10274
10275 /* Hostname capability */
60466a63 10276 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10277
10278 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10279 vty_out(vty,
10280 " advertised (name: %s,domain name: %s)",
60466a63
QY
10281 bgp->peer_self->hostname
10282 ? bgp->peer_self
10283 ->hostname
d77114b7 10284 : "n/a",
60466a63
QY
10285 bgp->peer_self->domainname
10286 ? bgp->peer_self
10287 ->domainname
d77114b7
MK
10288 : "n/a");
10289 } else {
10290 vty_out(vty, " not advertised");
d62a17ae 10291 }
10292
d77114b7 10293 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10294 vty_out(vty,
10295 " received (name: %s,domain name: %s)",
60466a63
QY
10296 p->hostname ? p->hostname
10297 : "n/a",
10298 p->domainname ? p->domainname
10299 : "n/a");
d77114b7
MK
10300 } else {
10301 vty_out(vty, " not received");
10302 }
10303
10304 vty_out(vty, "\n");
10305
d62a17ae 10306 /* Gracefull Restart */
10307 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10308 || CHECK_FLAG(p->cap,
10309 PEER_CAP_RESTART_ADV)) {
10310 vty_out(vty,
10311 " Graceful Restart Capabilty:");
10312 if (CHECK_FLAG(p->cap,
10313 PEER_CAP_RESTART_ADV))
10314 vty_out(vty, " advertised");
10315 if (CHECK_FLAG(p->cap,
10316 PEER_CAP_RESTART_RCV))
10317 vty_out(vty, " %sreceived",
10318 CHECK_FLAG(
10319 p->cap,
10320 PEER_CAP_RESTART_ADV)
10321 ? "and "
10322 : "");
10323 vty_out(vty, "\n");
10324
10325 if (CHECK_FLAG(p->cap,
10326 PEER_CAP_RESTART_RCV)) {
10327 int restart_af_count = 0;
10328
10329 vty_out(vty,
10330 " Remote Restart timer is %d seconds\n",
10331 p->v_gr_restart);
10332 vty_out(vty,
10333 " Address families by peer:\n ");
10334
05c7a1cc
QY
10335 FOREACH_AFI_SAFI (afi, safi)
10336 if (CHECK_FLAG(
10337 p->af_cap
10338 [afi]
10339 [safi],
10340 PEER_CAP_RESTART_AF_RCV)) {
10341 vty_out(vty,
10342 "%s%s(%s)",
10343 restart_af_count
10344 ? ", "
10345 : "",
10346 afi_safi_print(
10347 afi,
10348 safi),
10349 CHECK_FLAG(
10350 p->af_cap
10351 [afi]
10352 [safi],
10353 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10354 ? "preserved"
10355 : "not preserved");
10356 restart_af_count++;
10357 }
d62a17ae 10358 if (!restart_af_count)
10359 vty_out(vty, "none");
10360 vty_out(vty, "\n");
10361 }
10362 }
10363 }
10364 }
10365 }
10366
10367 /* graceful restart information */
10368 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10369 || p->t_gr_stale) {
10370 json_object *json_grace = NULL;
10371 json_object *json_grace_send = NULL;
10372 json_object *json_grace_recv = NULL;
10373 int eor_send_af_count = 0;
10374 int eor_receive_af_count = 0;
10375
10376 if (use_json) {
10377 json_grace = json_object_new_object();
10378 json_grace_send = json_object_new_object();
10379 json_grace_recv = json_object_new_object();
10380
10381 if (p->status == Established) {
05c7a1cc
QY
10382 FOREACH_AFI_SAFI (afi, safi) {
10383 if (CHECK_FLAG(p->af_sflags[afi][safi],
10384 PEER_STATUS_EOR_SEND)) {
10385 json_object_boolean_true_add(
10386 json_grace_send,
10387 afi_safi_print(afi,
10388 safi));
10389 eor_send_af_count++;
d62a17ae 10390 }
10391 }
05c7a1cc
QY
10392 FOREACH_AFI_SAFI (afi, safi) {
10393 if (CHECK_FLAG(
10394 p->af_sflags[afi][safi],
10395 PEER_STATUS_EOR_RECEIVED)) {
10396 json_object_boolean_true_add(
10397 json_grace_recv,
10398 afi_safi_print(afi,
10399 safi));
10400 eor_receive_af_count++;
d62a17ae 10401 }
10402 }
10403 }
10404
10405 json_object_object_add(json_grace, "endOfRibSend",
10406 json_grace_send);
10407 json_object_object_add(json_grace, "endOfRibRecv",
10408 json_grace_recv);
10409
10410 if (p->t_gr_restart)
10411 json_object_int_add(json_grace,
10412 "gracefulRestartTimerMsecs",
10413 thread_timer_remain_second(
10414 p->t_gr_restart)
10415 * 1000);
10416
10417 if (p->t_gr_stale)
10418 json_object_int_add(
10419 json_grace,
10420 "gracefulStalepathTimerMsecs",
10421 thread_timer_remain_second(
10422 p->t_gr_stale)
10423 * 1000);
10424
10425 json_object_object_add(
10426 json_neigh, "gracefulRestartInfo", json_grace);
10427 } else {
0437e105 10428 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10429 if (p->status == Established) {
10430 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10431 FOREACH_AFI_SAFI (afi, safi) {
10432 if (CHECK_FLAG(p->af_sflags[afi][safi],
10433 PEER_STATUS_EOR_SEND)) {
10434 vty_out(vty, "%s%s",
10435 eor_send_af_count ? ", "
10436 : "",
10437 afi_safi_print(afi,
10438 safi));
10439 eor_send_af_count++;
d62a17ae 10440 }
10441 }
10442 vty_out(vty, "\n");
10443 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10444 FOREACH_AFI_SAFI (afi, safi) {
10445 if (CHECK_FLAG(
10446 p->af_sflags[afi][safi],
10447 PEER_STATUS_EOR_RECEIVED)) {
10448 vty_out(vty, "%s%s",
10449 eor_receive_af_count
10450 ? ", "
10451 : "",
10452 afi_safi_print(afi,
10453 safi));
10454 eor_receive_af_count++;
d62a17ae 10455 }
10456 }
10457 vty_out(vty, "\n");
10458 }
10459
10460 if (p->t_gr_restart)
10461 vty_out(vty,
10462 " The remaining time of restart timer is %ld\n",
10463 thread_timer_remain_second(
10464 p->t_gr_restart));
10465
10466 if (p->t_gr_stale)
10467 vty_out(vty,
10468 " The remaining time of stalepath timer is %ld\n",
10469 thread_timer_remain_second(
10470 p->t_gr_stale));
10471 }
10472 }
10473 if (use_json) {
10474 json_object *json_stat = NULL;
10475 json_stat = json_object_new_object();
10476 /* Packet counts. */
10477 json_object_int_add(json_stat, "depthInq", 0);
10478 json_object_int_add(json_stat, "depthOutq",
10479 (unsigned long)p->obuf->count);
0112e9e0
QY
10480 json_object_int_add(json_stat, "opensSent",
10481 atomic_load_explicit(&p->open_out,
10482 memory_order_relaxed));
10483 json_object_int_add(json_stat, "opensRecv",
10484 atomic_load_explicit(&p->open_in,
10485 memory_order_relaxed));
d62a17ae 10486 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10487 atomic_load_explicit(&p->notify_out,
10488 memory_order_relaxed));
d62a17ae 10489 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10490 atomic_load_explicit(&p->notify_in,
10491 memory_order_relaxed));
10492 json_object_int_add(json_stat, "updatesSent",
10493 atomic_load_explicit(&p->update_out,
10494 memory_order_relaxed));
10495 json_object_int_add(json_stat, "updatesRecv",
10496 atomic_load_explicit(&p->update_in,
10497 memory_order_relaxed));
d62a17ae 10498 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10499 atomic_load_explicit(&p->keepalive_out,
10500 memory_order_relaxed));
d62a17ae 10501 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10502 atomic_load_explicit(&p->keepalive_in,
10503 memory_order_relaxed));
d62a17ae 10504 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10505 atomic_load_explicit(&p->refresh_out,
10506 memory_order_relaxed));
d62a17ae 10507 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10508 atomic_load_explicit(&p->refresh_in,
10509 memory_order_relaxed));
d62a17ae 10510 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10511 atomic_load_explicit(&p->dynamic_cap_out,
10512 memory_order_relaxed));
d62a17ae 10513 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10514 atomic_load_explicit(&p->dynamic_cap_in,
10515 memory_order_relaxed));
10516 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10517 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10518 json_object_object_add(json_neigh, "messageStats", json_stat);
10519 } else {
10520 /* Packet counts. */
10521 vty_out(vty, " Message statistics:\n");
10522 vty_out(vty, " Inq depth is 0\n");
10523 vty_out(vty, " Outq depth is %lu\n",
10524 (unsigned long)p->obuf->count);
10525 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10526 vty_out(vty, " Opens: %10d %10d\n",
10527 atomic_load_explicit(&p->open_out,
10528 memory_order_relaxed),
10529 atomic_load_explicit(&p->open_in,
10530 memory_order_relaxed));
10531 vty_out(vty, " Notifications: %10d %10d\n",
10532 atomic_load_explicit(&p->notify_out,
10533 memory_order_relaxed),
10534 atomic_load_explicit(&p->notify_in,
10535 memory_order_relaxed));
10536 vty_out(vty, " Updates: %10d %10d\n",
10537 atomic_load_explicit(&p->update_out,
10538 memory_order_relaxed),
10539 atomic_load_explicit(&p->update_in,
10540 memory_order_relaxed));
10541 vty_out(vty, " Keepalives: %10d %10d\n",
10542 atomic_load_explicit(&p->keepalive_out,
10543 memory_order_relaxed),
10544 atomic_load_explicit(&p->keepalive_in,
10545 memory_order_relaxed));
10546 vty_out(vty, " Route Refresh: %10d %10d\n",
10547 atomic_load_explicit(&p->refresh_out,
10548 memory_order_relaxed),
10549 atomic_load_explicit(&p->refresh_in,
10550 memory_order_relaxed));
d62a17ae 10551 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10552 atomic_load_explicit(&p->dynamic_cap_out,
10553 memory_order_relaxed),
10554 atomic_load_explicit(&p->dynamic_cap_in,
10555 memory_order_relaxed));
10556 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10557 PEER_TOTAL_RX(p));
d62a17ae 10558 }
10559
10560 if (use_json) {
10561 /* advertisement-interval */
10562 json_object_int_add(json_neigh,
10563 "minBtwnAdvertisementRunsTimerMsecs",
10564 p->v_routeadv * 1000);
10565
10566 /* Update-source. */
10567 if (p->update_if || p->update_source) {
10568 if (p->update_if)
10569 json_object_string_add(json_neigh,
10570 "updateSource",
10571 p->update_if);
10572 else if (p->update_source)
10573 json_object_string_add(
10574 json_neigh, "updateSource",
10575 sockunion2str(p->update_source, buf1,
10576 SU_ADDRSTRLEN));
10577 }
10578 } else {
10579 /* advertisement-interval */
10580 vty_out(vty,
10581 " Minimum time between advertisement runs is %d seconds\n",
10582 p->v_routeadv);
10583
10584 /* Update-source. */
10585 if (p->update_if || p->update_source) {
10586 vty_out(vty, " Update source is ");
10587 if (p->update_if)
10588 vty_out(vty, "%s", p->update_if);
10589 else if (p->update_source)
10590 vty_out(vty, "%s",
10591 sockunion2str(p->update_source, buf1,
10592 SU_ADDRSTRLEN));
10593 vty_out(vty, "\n");
10594 }
10595
10596 vty_out(vty, "\n");
10597 }
10598
10599 /* Address Family Information */
10600 json_object *json_hold = NULL;
10601
10602 if (use_json)
10603 json_hold = json_object_new_object();
10604
05c7a1cc
QY
10605 FOREACH_AFI_SAFI (afi, safi)
10606 if (p->afc[afi][safi])
10607 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10608 json_hold);
d62a17ae 10609
10610 if (use_json) {
10611 json_object_object_add(json_neigh, "addressFamilyInfo",
10612 json_hold);
10613 json_object_int_add(json_neigh, "connectionsEstablished",
10614 p->established);
10615 json_object_int_add(json_neigh, "connectionsDropped",
10616 p->dropped);
10617 } else
10618 vty_out(vty, " Connections established %d; dropped %d\n",
10619 p->established, p->dropped);
10620
10621 if (!p->last_reset) {
10622 if (use_json)
10623 json_object_string_add(json_neigh, "lastReset",
10624 "never");
10625 else
10626 vty_out(vty, " Last reset never\n");
10627 } else {
10628 if (use_json) {
10629 time_t uptime;
10630 struct tm *tm;
10631
10632 uptime = bgp_clock();
10633 uptime -= p->resettime;
10634 tm = gmtime(&uptime);
10635 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10636 (tm->tm_sec * 1000)
10637 + (tm->tm_min * 60000)
10638 + (tm->tm_hour * 3600000));
10639 json_object_string_add(
10640 json_neigh, "lastResetDueTo",
10641 peer_down_str[(int)p->last_reset]);
10642 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10643 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10644 char errorcodesubcode_hexstr[5];
10645 char errorcodesubcode_str[256];
10646
10647 code_str = bgp_notify_code_str(p->notify.code);
10648 subcode_str = bgp_notify_subcode_str(
10649 p->notify.code, p->notify.subcode);
10650
10651 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10652 p->notify.code, p->notify.subcode);
10653 json_object_string_add(json_neigh,
10654 "lastErrorCodeSubcode",
10655 errorcodesubcode_hexstr);
10656 snprintf(errorcodesubcode_str, 255, "%s%s",
10657 code_str, subcode_str);
10658 json_object_string_add(json_neigh,
10659 "lastNotificationReason",
10660 errorcodesubcode_str);
10661 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10662 && p->notify.code == BGP_NOTIFY_CEASE
10663 && (p->notify.subcode
10664 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10665 || p->notify.subcode
10666 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10667 && p->notify.length) {
10668 char msgbuf[1024];
10669 const char *msg_str;
10670
10671 msg_str = bgp_notify_admin_message(
10672 msgbuf, sizeof(msgbuf),
d7c0a89a 10673 (uint8_t *)p->notify.data,
d62a17ae 10674 p->notify.length);
10675 if (msg_str)
10676 json_object_string_add(
10677 json_neigh,
10678 "lastShutdownDescription",
10679 msg_str);
10680 }
10681 }
10682 } else {
10683 vty_out(vty, " Last reset %s, ",
10684 peer_uptime(p->resettime, timebuf,
10685 BGP_UPTIME_LEN, 0, NULL));
10686
10687 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10688 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10689 code_str = bgp_notify_code_str(p->notify.code);
10690 subcode_str = bgp_notify_subcode_str(
10691 p->notify.code, p->notify.subcode);
10692 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10693 p->last_reset == PEER_DOWN_NOTIFY_SEND
10694 ? "sent"
10695 : "received",
10696 code_str, subcode_str);
10697 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10698 && p->notify.code == BGP_NOTIFY_CEASE
10699 && (p->notify.subcode
10700 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10701 || p->notify.subcode
10702 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10703 && p->notify.length) {
10704 char msgbuf[1024];
10705 const char *msg_str;
10706
10707 msg_str = bgp_notify_admin_message(
10708 msgbuf, sizeof(msgbuf),
d7c0a89a 10709 (uint8_t *)p->notify.data,
d62a17ae 10710 p->notify.length);
10711 if (msg_str)
10712 vty_out(vty,
10713 " Message: \"%s\"\n",
10714 msg_str);
10715 }
10716 } else {
10717 vty_out(vty, "due to %s\n",
10718 peer_down_str[(int)p->last_reset]);
10719 }
10720
10721 if (p->last_reset_cause_size) {
10722 msg = p->last_reset_cause;
10723 vty_out(vty,
10724 " Message received that caused BGP to send a NOTIFICATION:\n ");
10725 for (i = 1; i <= p->last_reset_cause_size;
10726 i++) {
10727 vty_out(vty, "%02X", *msg++);
10728
10729 if (i != p->last_reset_cause_size) {
10730 if (i % 16 == 0) {
10731 vty_out(vty, "\n ");
10732 } else if (i % 4 == 0) {
10733 vty_out(vty, " ");
10734 }
10735 }
10736 }
10737 vty_out(vty, "\n");
10738 }
10739 }
10740 }
10741
10742 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10743 if (use_json)
10744 json_object_boolean_true_add(json_neigh,
10745 "prefixesConfigExceedMax");
10746 else
10747 vty_out(vty,
10748 " Peer had exceeded the max. no. of prefixes configured.\n");
10749
10750 if (p->t_pmax_restart) {
10751 if (use_json) {
10752 json_object_boolean_true_add(
10753 json_neigh, "reducePrefixNumFrom");
10754 json_object_int_add(json_neigh,
10755 "restartInTimerMsec",
10756 thread_timer_remain_second(
10757 p->t_pmax_restart)
10758 * 1000);
10759 } else
10760 vty_out(vty,
10761 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10762 p->host, thread_timer_remain_second(
10763 p->t_pmax_restart));
d62a17ae 10764 } else {
10765 if (use_json)
10766 json_object_boolean_true_add(
10767 json_neigh,
10768 "reducePrefixNumAndClearIpBgp");
10769 else
10770 vty_out(vty,
10771 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10772 p->host);
10773 }
10774 }
10775
10776 /* EBGP Multihop and GTSM */
10777 if (p->sort != BGP_PEER_IBGP) {
10778 if (use_json) {
10779 if (p->gtsm_hops > 0)
10780 json_object_int_add(json_neigh,
10781 "externalBgpNbrMaxHopsAway",
10782 p->gtsm_hops);
10783 else if (p->ttl > 1)
10784 json_object_int_add(json_neigh,
10785 "externalBgpNbrMaxHopsAway",
10786 p->ttl);
10787 } else {
10788 if (p->gtsm_hops > 0)
10789 vty_out(vty,
10790 " External BGP neighbor may be up to %d hops away.\n",
10791 p->gtsm_hops);
10792 else if (p->ttl > 1)
10793 vty_out(vty,
10794 " External BGP neighbor may be up to %d hops away.\n",
10795 p->ttl);
10796 }
10797 } else {
10798 if (p->gtsm_hops > 0) {
10799 if (use_json)
10800 json_object_int_add(json_neigh,
10801 "internalBgpNbrMaxHopsAway",
10802 p->gtsm_hops);
10803 else
10804 vty_out(vty,
10805 " Internal BGP neighbor may be up to %d hops away.\n",
10806 p->gtsm_hops);
10807 }
10808 }
10809
10810 /* Local address. */
10811 if (p->su_local) {
10812 if (use_json) {
10813 json_object_string_add(json_neigh, "hostLocal",
10814 sockunion2str(p->su_local, buf1,
10815 SU_ADDRSTRLEN));
10816 json_object_int_add(json_neigh, "portLocal",
10817 ntohs(p->su_local->sin.sin_port));
10818 } else
10819 vty_out(vty, "Local host: %s, Local port: %d\n",
10820 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10821 ntohs(p->su_local->sin.sin_port));
10822 }
10823
10824 /* Remote address. */
10825 if (p->su_remote) {
10826 if (use_json) {
10827 json_object_string_add(json_neigh, "hostForeign",
10828 sockunion2str(p->su_remote, buf1,
10829 SU_ADDRSTRLEN));
10830 json_object_int_add(json_neigh, "portForeign",
10831 ntohs(p->su_remote->sin.sin_port));
10832 } else
10833 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10834 sockunion2str(p->su_remote, buf1,
10835 SU_ADDRSTRLEN),
10836 ntohs(p->su_remote->sin.sin_port));
10837 }
10838
10839 /* Nexthop display. */
10840 if (p->su_local) {
10841 if (use_json) {
10842 json_object_string_add(json_neigh, "nexthop",
10843 inet_ntop(AF_INET,
10844 &p->nexthop.v4, buf1,
10845 sizeof(buf1)));
10846 json_object_string_add(json_neigh, "nexthopGlobal",
10847 inet_ntop(AF_INET6,
10848 &p->nexthop.v6_global,
10849 buf1, sizeof(buf1)));
10850 json_object_string_add(json_neigh, "nexthopLocal",
10851 inet_ntop(AF_INET6,
10852 &p->nexthop.v6_local,
10853 buf1, sizeof(buf1)));
10854 if (p->shared_network)
10855 json_object_string_add(json_neigh,
10856 "bgpConnection",
10857 "sharedNetwork");
10858 else
10859 json_object_string_add(json_neigh,
10860 "bgpConnection",
10861 "nonSharedNetwork");
10862 } else {
10863 vty_out(vty, "Nexthop: %s\n",
10864 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10865 sizeof(buf1)));
10866 vty_out(vty, "Nexthop global: %s\n",
10867 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10868 sizeof(buf1)));
10869 vty_out(vty, "Nexthop local: %s\n",
10870 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10871 sizeof(buf1)));
10872 vty_out(vty, "BGP connection: %s\n",
10873 p->shared_network ? "shared network"
10874 : "non shared network");
10875 }
10876 }
10877
10878 /* Timer information. */
10879 if (use_json) {
10880 json_object_int_add(json_neigh, "connectRetryTimer",
10881 p->v_connect);
10882 if (p->status == Established && p->rtt)
10883 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10884 p->rtt);
10885 if (p->t_start)
10886 json_object_int_add(
10887 json_neigh, "nextStartTimerDueInMsecs",
10888 thread_timer_remain_second(p->t_start) * 1000);
10889 if (p->t_connect)
10890 json_object_int_add(
10891 json_neigh, "nextConnectTimerDueInMsecs",
10892 thread_timer_remain_second(p->t_connect)
10893 * 1000);
10894 if (p->t_routeadv) {
10895 json_object_int_add(json_neigh, "mraiInterval",
10896 p->v_routeadv);
10897 json_object_int_add(
10898 json_neigh, "mraiTimerExpireInMsecs",
10899 thread_timer_remain_second(p->t_routeadv)
10900 * 1000);
10901 }
10902 if (p->password)
10903 json_object_int_add(json_neigh, "authenticationEnabled",
10904 1);
10905
10906 if (p->t_read)
10907 json_object_string_add(json_neigh, "readThread", "on");
10908 else
10909 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10910
10911 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10912 json_object_string_add(json_neigh, "writeThread", "on");
10913 else
10914 json_object_string_add(json_neigh, "writeThread",
10915 "off");
10916 } else {
10917 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10918 p->v_connect);
10919 if (p->status == Established && p->rtt)
10920 vty_out(vty, "Estimated round trip time: %d ms\n",
10921 p->rtt);
10922 if (p->t_start)
10923 vty_out(vty, "Next start timer due in %ld seconds\n",
10924 thread_timer_remain_second(p->t_start));
10925 if (p->t_connect)
10926 vty_out(vty, "Next connect timer due in %ld seconds\n",
10927 thread_timer_remain_second(p->t_connect));
10928 if (p->t_routeadv)
10929 vty_out(vty,
10930 "MRAI (interval %u) timer expires in %ld seconds\n",
10931 p->v_routeadv,
10932 thread_timer_remain_second(p->t_routeadv));
10933 if (p->password)
10934 vty_out(vty, "Peer Authentication Enabled\n");
10935
10936 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10937 p->t_read ? "on" : "off",
10938 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10939 ? "on"
10940 : "off");
d62a17ae 10941 }
10942
10943 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10944 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10945 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10946
10947 if (!use_json)
10948 vty_out(vty, "\n");
10949
10950 /* BFD information. */
10951 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10952
10953 if (use_json) {
10954 if (p->conf_if) /* Configured interface name. */
10955 json_object_object_add(json, p->conf_if, json_neigh);
10956 else /* Configured IP address. */
10957 json_object_object_add(json, p->host, json_neigh);
10958 }
10959}
10960
10961static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10962 enum show_type type, union sockunion *su,
9f049418 10963 const char *conf_if, bool use_json,
d62a17ae 10964 json_object *json)
10965{
10966 struct listnode *node, *nnode;
10967 struct peer *peer;
10968 int find = 0;
9f049418 10969 bool nbr_output = false;
d1927ebe
AS
10970 afi_t afi = AFI_MAX;
10971 safi_t safi = SAFI_MAX;
10972
10973 if (type == show_ipv4_peer || type == show_ipv4_all) {
10974 afi = AFI_IP;
10975 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10976 afi = AFI_IP6;
10977 }
d62a17ae 10978
10979 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10980 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10981 continue;
10982
10983 switch (type) {
10984 case show_all:
10985 bgp_show_peer(vty, peer, use_json, json);
9f049418 10986 nbr_output = true;
d62a17ae 10987 break;
10988 case show_peer:
10989 if (conf_if) {
10990 if ((peer->conf_if
10991 && !strcmp(peer->conf_if, conf_if))
10992 || (peer->hostname
10993 && !strcmp(peer->hostname, conf_if))) {
10994 find = 1;
10995 bgp_show_peer(vty, peer, use_json,
10996 json);
10997 }
10998 } else {
10999 if (sockunion_same(&peer->su, su)) {
11000 find = 1;
11001 bgp_show_peer(vty, peer, use_json,
11002 json);
11003 }
11004 }
11005 break;
d1927ebe
AS
11006 case show_ipv4_peer:
11007 case show_ipv6_peer:
11008 FOREACH_SAFI (safi) {
11009 if (peer->afc[afi][safi]) {
11010 if (conf_if) {
11011 if ((peer->conf_if
11012 && !strcmp(peer->conf_if, conf_if))
11013 || (peer->hostname
11014 && !strcmp(peer->hostname, conf_if))) {
11015 find = 1;
11016 bgp_show_peer(vty, peer, use_json,
11017 json);
11018 break;
11019 }
11020 } else {
11021 if (sockunion_same(&peer->su, su)) {
11022 find = 1;
11023 bgp_show_peer(vty, peer, use_json,
11024 json);
11025 break;
11026 }
11027 }
11028 }
11029 }
11030 break;
11031 case show_ipv4_all:
11032 case show_ipv6_all:
11033 FOREACH_SAFI (safi) {
11034 if (peer->afc[afi][safi]) {
11035 bgp_show_peer(vty, peer, use_json, json);
11036 nbr_output = true;
11037 break;
11038 }
11039 }
11040 break;
d62a17ae 11041 }
11042 }
11043
d1927ebe
AS
11044 if ((type == show_peer || type == show_ipv4_peer ||
11045 type == show_ipv6_peer) && !find) {
d62a17ae 11046 if (use_json)
11047 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11048 else
88b7d255 11049 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 11050 }
11051
d1927ebe
AS
11052 if (type != show_peer && type != show_ipv4_peer &&
11053 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 11054 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 11055
d62a17ae 11056 if (use_json) {
996c9314
LB
11057 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11058 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11059 } else {
11060 vty_out(vty, "\n");
11061 }
11062
11063 return CMD_SUCCESS;
11064}
11065
11066static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
11067 enum show_type type,
11068 const char *ip_str,
9f049418 11069 bool use_json)
d62a17ae 11070{
0291c246
MK
11071 struct listnode *node, *nnode;
11072 struct bgp *bgp;
71aedaa3 11073 union sockunion su;
0291c246 11074 json_object *json = NULL;
71aedaa3 11075 int ret, is_first = 1;
9f049418 11076 bool nbr_output = false;
d62a17ae 11077
11078 if (use_json)
11079 vty_out(vty, "{\n");
11080
11081 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11082 nbr_output = true;
d62a17ae 11083 if (use_json) {
11084 if (!(json = json_object_new_object())) {
af4c2728 11085 flog_err(
e50f7cfd 11086 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11087 "Unable to allocate memory for JSON object");
11088 vty_out(vty,
11089 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11090 return;
11091 }
11092
11093 json_object_int_add(json, "vrfId",
11094 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11095 ? -1
11096 : (int64_t)bgp->vrf_id);
d62a17ae 11097 json_object_string_add(
11098 json, "vrfName",
11099 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11100 ? VRF_DEFAULT_NAME
d62a17ae 11101 : bgp->name);
11102
11103 if (!is_first)
11104 vty_out(vty, ",\n");
11105 else
11106 is_first = 0;
11107
11108 vty_out(vty, "\"%s\":",
11109 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11110 ? VRF_DEFAULT_NAME
d62a17ae 11111 : bgp->name);
11112 } else {
11113 vty_out(vty, "\nInstance %s:\n",
11114 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11115 ? VRF_DEFAULT_NAME
d62a17ae 11116 : bgp->name);
11117 }
71aedaa3 11118
d1927ebe
AS
11119 if (type == show_peer || type == show_ipv4_peer ||
11120 type == show_ipv6_peer) {
71aedaa3
DS
11121 ret = str2sockunion(ip_str, &su);
11122 if (ret < 0)
11123 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11124 use_json, json);
11125 else
11126 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11127 use_json, json);
11128 } else {
d1927ebe 11129 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11130 use_json, json);
11131 }
b77004d6 11132 json_object_free(json);
d62a17ae 11133 }
11134
01cbfd04 11135 if (use_json) {
d62a17ae 11136 vty_out(vty, "}\n");
01cbfd04
QY
11137 json_object_free(json);
11138 }
9f049418
DS
11139 else if (!nbr_output)
11140 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11141}
11142
11143static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11144 enum show_type type, const char *ip_str,
9f049418 11145 bool use_json)
d62a17ae 11146{
11147 int ret;
11148 struct bgp *bgp;
11149 union sockunion su;
11150 json_object *json = NULL;
11151
11152 if (name) {
11153 if (strmatch(name, "all")) {
71aedaa3
DS
11154 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11155 use_json);
d62a17ae 11156 return CMD_SUCCESS;
11157 } else {
11158 bgp = bgp_lookup_by_name(name);
11159 if (!bgp) {
11160 if (use_json) {
11161 json = json_object_new_object();
d62a17ae 11162 vty_out(vty, "%s\n",
11163 json_object_to_json_string_ext(
11164 json,
11165 JSON_C_TO_STRING_PRETTY));
11166 json_object_free(json);
11167 } else
11168 vty_out(vty,
9f049418 11169 "%% BGP instance not found\n");
d62a17ae 11170
11171 return CMD_WARNING;
11172 }
11173 }
11174 } else {
11175 bgp = bgp_get_default();
11176 }
11177
11178 if (bgp) {
11179 json = json_object_new_object();
11180 if (ip_str) {
11181 ret = str2sockunion(ip_str, &su);
11182 if (ret < 0)
11183 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11184 use_json, json);
11185 else
11186 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11187 use_json, json);
11188 } else {
11189 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11190 json);
11191 }
11192 json_object_free(json);
ca61fd25
DS
11193 } else {
11194 if (use_json)
11195 vty_out(vty, "{}\n");
11196 else
11197 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11198 }
11199
11200 return CMD_SUCCESS;
4fb25c53
DW
11201}
11202
716b2d8a 11203/* "show [ip] bgp neighbors" commands. */
718e3744 11204DEFUN (show_ip_bgp_neighbors,
11205 show_ip_bgp_neighbors_cmd,
24345e82 11206 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11207 SHOW_STR
11208 IP_STR
11209 BGP_STR
f2a8972b 11210 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11211 "Address Family\n"
11212 "Address Family\n"
718e3744 11213 "Detailed information on TCP and BGP neighbor connections\n"
11214 "Neighbor to display information about\n"
a80beece 11215 "Neighbor to display information about\n"
91d37724 11216 "Neighbor on BGP configured interface\n"
9973d184 11217 JSON_STR)
718e3744 11218{
d62a17ae 11219 char *vrf = NULL;
11220 char *sh_arg = NULL;
11221 enum show_type sh_type;
d1927ebe 11222 afi_t afi = AFI_MAX;
718e3744 11223
9f049418 11224 bool uj = use_json(argc, argv);
718e3744 11225
d62a17ae 11226 int idx = 0;
718e3744 11227
9a8bdf1c
PG
11228 /* [<vrf> VIEWVRFNAME] */
11229 if (argv_find(argv, argc, "vrf", &idx)) {
11230 vrf = argv[idx + 1]->arg;
11231 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11232 vrf = NULL;
11233 } else if (argv_find(argv, argc, "view", &idx))
11234 /* [<view> VIEWVRFNAME] */
d62a17ae 11235 vrf = argv[idx + 1]->arg;
718e3744 11236
d62a17ae 11237 idx++;
d1927ebe
AS
11238
11239 if (argv_find(argv, argc, "ipv4", &idx)) {
11240 sh_type = show_ipv4_all;
11241 afi = AFI_IP;
11242 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11243 sh_type = show_ipv6_all;
11244 afi = AFI_IP6;
11245 } else {
11246 sh_type = show_all;
11247 }
11248
d62a17ae 11249 if (argv_find(argv, argc, "A.B.C.D", &idx)
11250 || argv_find(argv, argc, "X:X::X:X", &idx)
11251 || argv_find(argv, argc, "WORD", &idx)) {
11252 sh_type = show_peer;
11253 sh_arg = argv[idx]->arg;
d1927ebe
AS
11254 }
11255
11256 if (sh_type == show_peer && afi == AFI_IP) {
11257 sh_type = show_ipv4_peer;
11258 } else if (sh_type == show_peer && afi == AFI_IP6) {
11259 sh_type = show_ipv6_peer;
11260 }
856ca177 11261
d62a17ae 11262 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11263}
11264
716b2d8a 11265/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11266 paths' and `show ip mbgp paths'. Those functions results are the
11267 same.*/
f412b39a 11268DEFUN (show_ip_bgp_paths,
718e3744 11269 show_ip_bgp_paths_cmd,
46f296b4 11270 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11271 SHOW_STR
11272 IP_STR
11273 BGP_STR
46f296b4 11274 BGP_SAFI_HELP_STR
718e3744 11275 "Path information\n")
11276{
d62a17ae 11277 vty_out(vty, "Address Refcnt Path\n");
11278 aspath_print_all_vty(vty);
11279 return CMD_SUCCESS;
718e3744 11280}
11281
718e3744 11282#include "hash.h"
11283
e3b78da8 11284static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11285 struct vty *vty)
718e3744 11286{
d62a17ae 11287 struct community *com;
718e3744 11288
e3b78da8 11289 com = (struct community *)bucket->data;
3f65c5b1 11290 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11291 community_str(com, false));
718e3744 11292}
11293
11294/* Show BGP's community internal data. */
f412b39a 11295DEFUN (show_ip_bgp_community_info,
718e3744 11296 show_ip_bgp_community_info_cmd,
bec37ba5 11297 "show [ip] bgp community-info",
718e3744 11298 SHOW_STR
11299 IP_STR
11300 BGP_STR
11301 "List all bgp community information\n")
11302{
d62a17ae 11303 vty_out(vty, "Address Refcnt Community\n");
718e3744 11304
d62a17ae 11305 hash_iterate(community_hash(),
e3b78da8 11306 (void (*)(struct hash_bucket *,
d62a17ae 11307 void *))community_show_all_iterator,
11308 vty);
718e3744 11309
d62a17ae 11310 return CMD_SUCCESS;
718e3744 11311}
11312
e3b78da8 11313static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11314 struct vty *vty)
57d187bc 11315{
d62a17ae 11316 struct lcommunity *lcom;
57d187bc 11317
e3b78da8 11318 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11319 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11320 lcommunity_str(lcom, false));
57d187bc
JS
11321}
11322
11323/* Show BGP's community internal data. */
11324DEFUN (show_ip_bgp_lcommunity_info,
11325 show_ip_bgp_lcommunity_info_cmd,
11326 "show ip bgp large-community-info",
11327 SHOW_STR
11328 IP_STR
11329 BGP_STR
11330 "List all bgp large-community information\n")
11331{
d62a17ae 11332 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11333
d62a17ae 11334 hash_iterate(lcommunity_hash(),
e3b78da8 11335 (void (*)(struct hash_bucket *,
d62a17ae 11336 void *))lcommunity_show_all_iterator,
11337 vty);
57d187bc 11338
d62a17ae 11339 return CMD_SUCCESS;
57d187bc
JS
11340}
11341
11342
f412b39a 11343DEFUN (show_ip_bgp_attr_info,
718e3744 11344 show_ip_bgp_attr_info_cmd,
bec37ba5 11345 "show [ip] bgp attribute-info",
718e3744 11346 SHOW_STR
11347 IP_STR
11348 BGP_STR
11349 "List all bgp attribute information\n")
11350{
d62a17ae 11351 attr_show_all(vty);
11352 return CMD_SUCCESS;
718e3744 11353}
6b0655a2 11354
03915806
CS
11355static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11356 afi_t afi, safi_t safi,
11357 bool use_json, json_object *json)
53089bec 11358{
11359 struct bgp *bgp;
11360 struct listnode *node;
11361 char *vname;
11362 char buf1[INET6_ADDRSTRLEN];
11363 char *ecom_str;
11364 vpn_policy_direction_t dir;
11365
03915806 11366 if (json) {
b46dfd20
DS
11367 json_object *json_import_vrfs = NULL;
11368 json_object *json_export_vrfs = NULL;
11369
b46dfd20
DS
11370 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11371
53089bec 11372 if (!bgp) {
b46dfd20
DS
11373 vty_out(vty, "%s\n",
11374 json_object_to_json_string_ext(
11375 json,
11376 JSON_C_TO_STRING_PRETTY));
11377 json_object_free(json);
11378
53089bec 11379 return CMD_WARNING;
11380 }
b46dfd20 11381
94d4c685
DS
11382 /* Provide context for the block */
11383 json_object_string_add(json, "vrf", name ? name : "default");
11384 json_object_string_add(json, "afiSafi",
11385 afi_safi_print(afi, safi));
11386
b46dfd20
DS
11387 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11388 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11389 json_object_string_add(json, "importFromVrfs", "none");
11390 json_object_string_add(json, "importRts", "none");
11391 } else {
6ce24e52
DS
11392 json_import_vrfs = json_object_new_array();
11393
b46dfd20
DS
11394 for (ALL_LIST_ELEMENTS_RO(
11395 bgp->vpn_policy[afi].import_vrf,
11396 node, vname))
11397 json_object_array_add(json_import_vrfs,
11398 json_object_new_string(vname));
11399
11400 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11401 ecom_str = ecommunity_ecom2str(
11402 bgp->vpn_policy[afi].rtlist[dir],
11403 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11404 json_object_object_add(json, "importFromVrfs",
11405 json_import_vrfs);
11406 json_object_string_add(json, "importRts", ecom_str);
11407
11408 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11409 }
11410
11411 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11412 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11413 json_object_string_add(json, "exportToVrfs", "none");
11414 json_object_string_add(json, "routeDistinguisher",
11415 "none");
11416 json_object_string_add(json, "exportRts", "none");
11417 } else {
6ce24e52
DS
11418 json_export_vrfs = json_object_new_array();
11419
b46dfd20
DS
11420 for (ALL_LIST_ELEMENTS_RO(
11421 bgp->vpn_policy[afi].export_vrf,
11422 node, vname))
11423 json_object_array_add(json_export_vrfs,
11424 json_object_new_string(vname));
11425 json_object_object_add(json, "exportToVrfs",
11426 json_export_vrfs);
11427 json_object_string_add(json, "routeDistinguisher",
11428 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11429 buf1, RD_ADDRSTRLEN));
11430
11431 dir = BGP_VPN_POLICY_DIR_TOVPN;
11432 ecom_str = ecommunity_ecom2str(
11433 bgp->vpn_policy[afi].rtlist[dir],
11434 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11435 json_object_string_add(json, "exportRts", ecom_str);
11436
11437 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11438 }
11439
03915806
CS
11440 if (use_json) {
11441 vty_out(vty, "%s\n",
11442 json_object_to_json_string_ext(json,
b46dfd20 11443 JSON_C_TO_STRING_PRETTY));
03915806
CS
11444 json_object_free(json);
11445 }
53089bec 11446 } else {
b46dfd20
DS
11447 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11448
53089bec 11449 if (!bgp) {
b46dfd20 11450 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11451 return CMD_WARNING;
11452 }
53089bec 11453
b46dfd20
DS
11454 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11455 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11456 vty_out(vty,
11457 "This VRF is not importing %s routes from any other VRF\n",
11458 afi_safi_print(afi, safi));
11459 else {
11460 vty_out(vty,
11461 "This VRF is importing %s routes from the following VRFs:\n",
11462 afi_safi_print(afi, safi));
11463
11464 for (ALL_LIST_ELEMENTS_RO(
11465 bgp->vpn_policy[afi].import_vrf,
11466 node, vname))
11467 vty_out(vty, " %s\n", vname);
11468
11469 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11470 ecom_str = ecommunity_ecom2str(
11471 bgp->vpn_policy[afi].rtlist[dir],
11472 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11473 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11474
11475 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11476 }
53089bec 11477
b46dfd20
DS
11478 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11479 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11480 vty_out(vty,
11481 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11482 afi_safi_print(afi, safi));
b46dfd20
DS
11483 else {
11484 vty_out(vty,
04c9077f 11485 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11486 afi_safi_print(afi, safi));
b46dfd20
DS
11487
11488 for (ALL_LIST_ELEMENTS_RO(
11489 bgp->vpn_policy[afi].export_vrf,
11490 node, vname))
11491 vty_out(vty, " %s\n", vname);
11492
11493 vty_out(vty, "RD: %s\n",
11494 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11495 buf1, RD_ADDRSTRLEN));
11496
11497 dir = BGP_VPN_POLICY_DIR_TOVPN;
11498 ecom_str = ecommunity_ecom2str(
11499 bgp->vpn_policy[afi].rtlist[dir],
11500 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11501 vty_out(vty, "Export RT: %s\n", ecom_str);
04c9077f 11502 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
53089bec 11503 }
53089bec 11504 }
11505
11506 return CMD_SUCCESS;
11507}
11508
03915806
CS
11509static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11510 safi_t safi, bool use_json)
11511{
11512 struct listnode *node, *nnode;
11513 struct bgp *bgp;
11514 char *vrf_name = NULL;
11515 json_object *json = NULL;
11516 json_object *json_vrf = NULL;
11517 json_object *json_vrfs = NULL;
11518
11519 if (use_json) {
11520 json = json_object_new_object();
11521 json_vrfs = json_object_new_object();
11522 }
11523
11524 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11525
11526 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11527 vrf_name = bgp->name;
11528
11529 if (use_json) {
11530 json_vrf = json_object_new_object();
11531 } else {
11532 vty_out(vty, "\nInstance %s:\n",
11533 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11534 ? VRF_DEFAULT_NAME : bgp->name);
11535 }
11536 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11537 if (use_json) {
11538 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11539 json_object_object_add(json_vrfs,
11540 VRF_DEFAULT_NAME, json_vrf);
11541 else
11542 json_object_object_add(json_vrfs, vrf_name,
11543 json_vrf);
11544 }
11545 }
11546
11547 if (use_json) {
11548 json_object_object_add(json, "vrfs", json_vrfs);
11549 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11550 JSON_C_TO_STRING_PRETTY));
11551 json_object_free(json);
11552 }
11553
11554 return CMD_SUCCESS;
11555}
11556
53089bec 11557/* "show [ip] bgp route-leak" command. */
11558DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11559 show_ip_bgp_route_leak_cmd,
11560 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11561 SHOW_STR
11562 IP_STR
11563 BGP_STR
11564 BGP_INSTANCE_HELP_STR
11565 BGP_AFI_HELP_STR
11566 BGP_SAFI_HELP_STR
11567 "Route leaking information\n"
11568 JSON_STR)
53089bec 11569{
11570 char *vrf = NULL;
11571 afi_t afi = AFI_MAX;
11572 safi_t safi = SAFI_MAX;
11573
9f049418 11574 bool uj = use_json(argc, argv);
53089bec 11575 int idx = 0;
03915806 11576 json_object *json = NULL;
53089bec 11577
11578 /* show [ip] bgp */
11579 if (argv_find(argv, argc, "ip", &idx)) {
11580 afi = AFI_IP;
11581 safi = SAFI_UNICAST;
11582 }
11583 /* [vrf VIEWVRFNAME] */
11584 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11585 vty_out(vty,
11586 "%% This command is not applicable to BGP views\n");
53089bec 11587 return CMD_WARNING;
11588 }
11589
9a8bdf1c
PG
11590 if (argv_find(argv, argc, "vrf", &idx)) {
11591 vrf = argv[idx + 1]->arg;
11592 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11593 vrf = NULL;
11594 }
53089bec 11595 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11596 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11597 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11598 }
11599
11600 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11601 vty_out(vty,
11602 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11603 return CMD_WARNING;
11604 }
11605
03915806
CS
11606 if (vrf && strmatch(vrf, "all"))
11607 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11608
11609 if (uj)
11610 json = json_object_new_object();
11611
11612 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11613}
11614
d62a17ae 11615static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11616 safi_t safi)
f186de26 11617{
d62a17ae 11618 struct listnode *node, *nnode;
11619 struct bgp *bgp;
f186de26 11620
d62a17ae 11621 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11622 vty_out(vty, "\nInstance %s:\n",
11623 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11624 ? VRF_DEFAULT_NAME
d62a17ae 11625 : bgp->name);
11626 update_group_show(bgp, afi, safi, vty, 0);
11627 }
f186de26 11628}
11629
d62a17ae 11630static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11631 int safi, uint64_t subgrp_id)
4fb25c53 11632{
d62a17ae 11633 struct bgp *bgp;
4fb25c53 11634
d62a17ae 11635 if (name) {
11636 if (strmatch(name, "all")) {
11637 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11638 return CMD_SUCCESS;
11639 } else {
11640 bgp = bgp_lookup_by_name(name);
11641 }
11642 } else {
11643 bgp = bgp_get_default();
11644 }
4fb25c53 11645
d62a17ae 11646 if (bgp)
11647 update_group_show(bgp, afi, safi, vty, subgrp_id);
11648 return CMD_SUCCESS;
4fb25c53
DW
11649}
11650
8fe8a7f6
DS
11651DEFUN (show_ip_bgp_updgrps,
11652 show_ip_bgp_updgrps_cmd,
c1a44e43 11653 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11654 SHOW_STR
11655 IP_STR
11656 BGP_STR
11657 BGP_INSTANCE_HELP_STR
c9e571b4 11658 BGP_AFI_HELP_STR
9bedbb1e 11659 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11660 "Detailed info about dynamic update groups\n"
11661 "Specific subgroup to display detailed info for\n")
8386ac43 11662{
d62a17ae 11663 char *vrf = NULL;
11664 afi_t afi = AFI_IP6;
11665 safi_t safi = SAFI_UNICAST;
11666 uint64_t subgrp_id = 0;
11667
11668 int idx = 0;
11669
11670 /* show [ip] bgp */
11671 if (argv_find(argv, argc, "ip", &idx))
11672 afi = AFI_IP;
9a8bdf1c
PG
11673 /* [<vrf> VIEWVRFNAME] */
11674 if (argv_find(argv, argc, "vrf", &idx)) {
11675 vrf = argv[idx + 1]->arg;
11676 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11677 vrf = NULL;
11678 } else if (argv_find(argv, argc, "view", &idx))
11679 /* [<view> VIEWVRFNAME] */
11680 vrf = argv[idx + 1]->arg;
d62a17ae 11681 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11682 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11683 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11684 }
5bf15956 11685
d62a17ae 11686 /* get subgroup id, if provided */
11687 idx = argc - 1;
11688 if (argv[idx]->type == VARIABLE_TKN)
11689 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11690
d62a17ae 11691 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11692}
11693
f186de26 11694DEFUN (show_bgp_instance_all_ipv6_updgrps,
11695 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11696 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11697 SHOW_STR
716b2d8a 11698 IP_STR
f186de26 11699 BGP_STR
11700 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11701 "Detailed info about dynamic update groups\n")
f186de26 11702{
d62a17ae 11703 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11704 return CMD_SUCCESS;
f186de26 11705}
11706
43d3f4fc
DS
11707DEFUN (show_bgp_l2vpn_evpn_updgrps,
11708 show_bgp_l2vpn_evpn_updgrps_cmd,
11709 "show [ip] bgp l2vpn evpn update-groups",
11710 SHOW_STR
11711 IP_STR
11712 BGP_STR
11713 "l2vpn address family\n"
11714 "evpn sub-address family\n"
11715 "Detailed info about dynamic update groups\n")
11716{
11717 char *vrf = NULL;
11718 uint64_t subgrp_id = 0;
11719
11720 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11721 return CMD_SUCCESS;
11722}
11723
5bf15956
DW
11724DEFUN (show_bgp_updgrps_stats,
11725 show_bgp_updgrps_stats_cmd,
716b2d8a 11726 "show [ip] bgp update-groups statistics",
3f9c7369 11727 SHOW_STR
716b2d8a 11728 IP_STR
3f9c7369 11729 BGP_STR
0c7b1b01 11730 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11731 "Statistics\n")
11732{
d62a17ae 11733 struct bgp *bgp;
3f9c7369 11734
d62a17ae 11735 bgp = bgp_get_default();
11736 if (bgp)
11737 update_group_show_stats(bgp, vty);
3f9c7369 11738
d62a17ae 11739 return CMD_SUCCESS;
3f9c7369
DS
11740}
11741
8386ac43 11742DEFUN (show_bgp_instance_updgrps_stats,
11743 show_bgp_instance_updgrps_stats_cmd,
18c57037 11744 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11745 SHOW_STR
716b2d8a 11746 IP_STR
8386ac43 11747 BGP_STR
11748 BGP_INSTANCE_HELP_STR
0c7b1b01 11749 "Detailed info about dynamic update groups\n"
8386ac43 11750 "Statistics\n")
11751{
d62a17ae 11752 int idx_word = 3;
11753 struct bgp *bgp;
8386ac43 11754
d62a17ae 11755 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11756 if (bgp)
11757 update_group_show_stats(bgp, vty);
8386ac43 11758
d62a17ae 11759 return CMD_SUCCESS;
8386ac43 11760}
11761
d62a17ae 11762static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11763 afi_t afi, safi_t safi,
11764 const char *what, uint64_t subgrp_id)
3f9c7369 11765{
d62a17ae 11766 struct bgp *bgp;
8386ac43 11767
d62a17ae 11768 if (name)
11769 bgp = bgp_lookup_by_name(name);
11770 else
11771 bgp = bgp_get_default();
8386ac43 11772
d62a17ae 11773 if (bgp) {
11774 if (!strcmp(what, "advertise-queue"))
11775 update_group_show_adj_queue(bgp, afi, safi, vty,
11776 subgrp_id);
11777 else if (!strcmp(what, "advertised-routes"))
11778 update_group_show_advertised(bgp, afi, safi, vty,
11779 subgrp_id);
11780 else if (!strcmp(what, "packet-queue"))
11781 update_group_show_packet_queue(bgp, afi, safi, vty,
11782 subgrp_id);
11783 }
3f9c7369
DS
11784}
11785
dc64bdec
QY
11786DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11787 show_ip_bgp_instance_updgrps_adj_s_cmd,
11788 "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",
11789 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11790 BGP_SAFI_HELP_STR
11791 "Detailed info about dynamic update groups\n"
11792 "Specific subgroup to display info for\n"
11793 "Advertisement queue\n"
11794 "Announced routes\n"
11795 "Packet queue\n")
3f9c7369 11796{
dc64bdec
QY
11797 uint64_t subgrp_id = 0;
11798 afi_t afiz;
11799 safi_t safiz;
11800 if (sgid)
11801 subgrp_id = strtoull(sgid, NULL, 10);
11802
11803 if (!ip && !afi)
11804 afiz = AFI_IP6;
11805 if (!ip && afi)
11806 afiz = bgp_vty_afi_from_str(afi);
11807 if (ip && !afi)
11808 afiz = AFI_IP;
11809 if (ip && afi) {
11810 afiz = bgp_vty_afi_from_str(afi);
11811 if (afiz != AFI_IP)
11812 vty_out(vty,
11813 "%% Cannot specify both 'ip' and 'ipv6'\n");
11814 return CMD_WARNING;
11815 }
d62a17ae 11816
dc64bdec 11817 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11818
dc64bdec 11819 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11820 return CMD_SUCCESS;
11821}
11822
d62a17ae 11823static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11824{
11825 struct listnode *node, *nnode;
11826 struct prefix *range;
11827 struct peer *conf;
11828 struct peer *peer;
11829 char buf[PREFIX2STR_BUFFER];
11830 afi_t afi;
11831 safi_t safi;
11832 const char *peer_status;
11833 const char *af_str;
11834 int lr_count;
11835 int dynamic;
11836 int af_cfgd;
11837
11838 conf = group->conf;
11839
11840 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
11841 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11842 group->name, conf->as);
d62a17ae 11843 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
11844 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11845 group->name, group->bgp->as);
d62a17ae 11846 } else {
11847 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11848 }
f14e6fdb 11849
d62a17ae 11850 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11851 vty_out(vty, " Peer-group type is internal\n");
11852 else
11853 vty_out(vty, " Peer-group type is external\n");
11854
11855 /* Display AFs configured. */
11856 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11857 FOREACH_AFI_SAFI (afi, safi) {
11858 if (conf->afc[afi][safi]) {
11859 af_cfgd = 1;
11860 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11861 }
05c7a1cc 11862 }
d62a17ae 11863 if (!af_cfgd)
11864 vty_out(vty, " none\n");
11865 else
11866 vty_out(vty, "\n");
11867
11868 /* Display listen ranges (for dynamic neighbors), if any */
11869 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11870 if (afi == AFI_IP)
11871 af_str = "IPv4";
11872 else if (afi == AFI_IP6)
11873 af_str = "IPv6";
11874 else
11875 af_str = "???";
11876 lr_count = listcount(group->listen_range[afi]);
11877 if (lr_count) {
11878 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11879 af_str);
11880
11881
11882 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11883 nnode, range)) {
11884 prefix2str(range, buf, sizeof(buf));
11885 vty_out(vty, " %s\n", buf);
11886 }
11887 }
11888 }
f14e6fdb 11889
d62a17ae 11890 /* Display group members and their status */
11891 if (listcount(group->peer)) {
11892 vty_out(vty, " Peer-group members:\n");
11893 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11894 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11895 peer_status = "Idle (Admin)";
11896 else if (CHECK_FLAG(peer->sflags,
11897 PEER_STATUS_PREFIX_OVERFLOW))
11898 peer_status = "Idle (PfxCt)";
11899 else
11900 peer_status = lookup_msg(bgp_status_msg,
11901 peer->status, NULL);
11902
11903 dynamic = peer_dynamic_neighbor(peer);
11904 vty_out(vty, " %s %s %s \n", peer->host,
11905 dynamic ? "(dynamic)" : "", peer_status);
11906 }
11907 }
f14e6fdb 11908
d62a17ae 11909 return CMD_SUCCESS;
11910}
11911
ff9959b0
QY
11912static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11913 const char *group_name)
d62a17ae 11914{
ff9959b0 11915 struct bgp *bgp;
d62a17ae 11916 struct listnode *node, *nnode;
11917 struct peer_group *group;
ff9959b0
QY
11918 bool found = false;
11919
11920 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11921
11922 if (!bgp) {
9f049418 11923 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11924 return CMD_WARNING;
11925 }
d62a17ae 11926
11927 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11928 if (group_name) {
11929 if (strmatch(group->name, group_name)) {
d62a17ae 11930 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11931 found = true;
11932 break;
d62a17ae 11933 }
ff9959b0
QY
11934 } else {
11935 bgp_show_one_peer_group(vty, group);
d62a17ae 11936 }
f14e6fdb 11937 }
f14e6fdb 11938
ff9959b0 11939 if (group_name && !found)
d62a17ae 11940 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11941
d62a17ae 11942 return CMD_SUCCESS;
f14e6fdb
DS
11943}
11944
f14e6fdb
DS
11945DEFUN (show_ip_bgp_peer_groups,
11946 show_ip_bgp_peer_groups_cmd,
18c57037 11947 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11948 SHOW_STR
11949 IP_STR
11950 BGP_STR
8386ac43 11951 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11952 "Detailed information on BGP peer groups\n"
11953 "Peer group name\n")
f14e6fdb 11954{
d62a17ae 11955 char *vrf, *pg;
d62a17ae 11956 int idx = 0;
f14e6fdb 11957
a4d82a8a
PZ
11958 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11959 : NULL;
d62a17ae 11960 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11961
ff9959b0 11962 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11963}
3f9c7369 11964
d6e3c605 11965
718e3744 11966/* Redistribute VTY commands. */
11967
718e3744 11968DEFUN (bgp_redistribute_ipv4,
11969 bgp_redistribute_ipv4_cmd,
40d1cbfb 11970 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11971 "Redistribute information from another routing protocol\n"
ab0181ee 11972 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11973{
d62a17ae 11974 VTY_DECLVAR_CONTEXT(bgp, bgp);
11975 int idx_protocol = 1;
11976 int type;
718e3744 11977
d62a17ae 11978 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11979 if (type < 0) {
11980 vty_out(vty, "%% Invalid route type\n");
11981 return CMD_WARNING_CONFIG_FAILED;
11982 }
7f323236 11983
d62a17ae 11984 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11985 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11986}
11987
d62a17ae 11988ALIAS_HIDDEN(
11989 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11990 "redistribute " FRR_IP_REDIST_STR_BGPD,
11991 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11992
718e3744 11993DEFUN (bgp_redistribute_ipv4_rmap,
11994 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11995 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11996 "Redistribute information from another routing protocol\n"
ab0181ee 11997 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11998 "Route map reference\n"
11999 "Pointer to route-map entries\n")
12000{
d62a17ae 12001 VTY_DECLVAR_CONTEXT(bgp, bgp);
12002 int idx_protocol = 1;
12003 int idx_word = 3;
12004 int type;
12005 struct bgp_redist *red;
e923dd62 12006 bool changed;
1de27621
DA
12007 struct route_map *route_map = route_map_lookup_warn_noexist(
12008 vty, argv[idx_word]->arg);
718e3744 12009
d62a17ae 12010 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12011 if (type < 0) {
12012 vty_out(vty, "%% Invalid route type\n");
12013 return CMD_WARNING_CONFIG_FAILED;
12014 }
718e3744 12015
d62a17ae 12016 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12017 changed =
12018 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12019 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 12020}
12021
d62a17ae 12022ALIAS_HIDDEN(
12023 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12024 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12025 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12026 "Route map reference\n"
12027 "Pointer to route-map entries\n")
596c17ba 12028
718e3744 12029DEFUN (bgp_redistribute_ipv4_metric,
12030 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 12031 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12032 "Redistribute information from another routing protocol\n"
ab0181ee 12033 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12034 "Metric for redistributed routes\n"
12035 "Default metric\n")
12036{
d62a17ae 12037 VTY_DECLVAR_CONTEXT(bgp, bgp);
12038 int idx_protocol = 1;
12039 int idx_number = 3;
12040 int type;
d7c0a89a 12041 uint32_t metric;
d62a17ae 12042 struct bgp_redist *red;
e923dd62 12043 bool changed;
d62a17ae 12044
12045 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12046 if (type < 0) {
12047 vty_out(vty, "%% Invalid route type\n");
12048 return CMD_WARNING_CONFIG_FAILED;
12049 }
12050 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12051
12052 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12053 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12054 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12055}
12056
12057ALIAS_HIDDEN(
12058 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12059 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12060 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12061 "Metric for redistributed routes\n"
12062 "Default metric\n")
596c17ba 12063
718e3744 12064DEFUN (bgp_redistribute_ipv4_rmap_metric,
12065 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 12066 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12067 "Redistribute information from another routing protocol\n"
ab0181ee 12068 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12069 "Route map reference\n"
12070 "Pointer to route-map entries\n"
12071 "Metric for redistributed routes\n"
12072 "Default metric\n")
12073{
d62a17ae 12074 VTY_DECLVAR_CONTEXT(bgp, bgp);
12075 int idx_protocol = 1;
12076 int idx_word = 3;
12077 int idx_number = 5;
12078 int type;
d7c0a89a 12079 uint32_t metric;
d62a17ae 12080 struct bgp_redist *red;
e923dd62 12081 bool changed;
1de27621
DA
12082 struct route_map *route_map =
12083 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12084
12085 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12086 if (type < 0) {
12087 vty_out(vty, "%% Invalid route type\n");
12088 return CMD_WARNING_CONFIG_FAILED;
12089 }
12090 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12091
12092 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12093 changed =
12094 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12095 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12096 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12097}
12098
12099ALIAS_HIDDEN(
12100 bgp_redistribute_ipv4_rmap_metric,
12101 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12102 "redistribute " FRR_IP_REDIST_STR_BGPD
12103 " route-map WORD metric (0-4294967295)",
12104 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12105 "Route map reference\n"
12106 "Pointer to route-map entries\n"
12107 "Metric for redistributed routes\n"
12108 "Default metric\n")
596c17ba 12109
718e3744 12110DEFUN (bgp_redistribute_ipv4_metric_rmap,
12111 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12112 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12113 "Redistribute information from another routing protocol\n"
ab0181ee 12114 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12115 "Metric for redistributed routes\n"
12116 "Default metric\n"
12117 "Route map reference\n"
12118 "Pointer to route-map entries\n")
12119{
d62a17ae 12120 VTY_DECLVAR_CONTEXT(bgp, bgp);
12121 int idx_protocol = 1;
12122 int idx_number = 3;
12123 int idx_word = 5;
12124 int type;
d7c0a89a 12125 uint32_t metric;
d62a17ae 12126 struct bgp_redist *red;
e923dd62 12127 bool changed;
1de27621
DA
12128 struct route_map *route_map =
12129 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12130
12131 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12132 if (type < 0) {
12133 vty_out(vty, "%% Invalid route type\n");
12134 return CMD_WARNING_CONFIG_FAILED;
12135 }
12136 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12137
12138 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12139 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12140 changed |=
12141 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12142 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12143}
12144
12145ALIAS_HIDDEN(
12146 bgp_redistribute_ipv4_metric_rmap,
12147 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12148 "redistribute " FRR_IP_REDIST_STR_BGPD
12149 " metric (0-4294967295) route-map WORD",
12150 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12151 "Metric for redistributed routes\n"
12152 "Default metric\n"
12153 "Route map reference\n"
12154 "Pointer to route-map entries\n")
596c17ba 12155
7c8ff89e
DS
12156DEFUN (bgp_redistribute_ipv4_ospf,
12157 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12158 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12159 "Redistribute information from another routing protocol\n"
12160 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12161 "Non-main Kernel Routing Table\n"
12162 "Instance ID/Table ID\n")
7c8ff89e 12163{
d62a17ae 12164 VTY_DECLVAR_CONTEXT(bgp, bgp);
12165 int idx_ospf_table = 1;
12166 int idx_number = 2;
d7c0a89a
QY
12167 unsigned short instance;
12168 unsigned short protocol;
7c8ff89e 12169
d62a17ae 12170 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12171
d62a17ae 12172 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12173 protocol = ZEBRA_ROUTE_OSPF;
12174 else
12175 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12176
d62a17ae 12177 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12178 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12179}
12180
d62a17ae 12181ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12182 "redistribute <ospf|table> (1-65535)",
12183 "Redistribute information from another routing protocol\n"
12184 "Open Shortest Path First (OSPFv2)\n"
12185 "Non-main Kernel Routing Table\n"
12186 "Instance ID/Table ID\n")
596c17ba 12187
7c8ff89e
DS
12188DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12189 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12190 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12191 "Redistribute information from another routing protocol\n"
12192 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12193 "Non-main Kernel Routing Table\n"
12194 "Instance ID/Table ID\n"
7c8ff89e
DS
12195 "Route map reference\n"
12196 "Pointer to route-map entries\n")
12197{
d62a17ae 12198 VTY_DECLVAR_CONTEXT(bgp, bgp);
12199 int idx_ospf_table = 1;
12200 int idx_number = 2;
12201 int idx_word = 4;
12202 struct bgp_redist *red;
d7c0a89a 12203 unsigned short instance;
d62a17ae 12204 int protocol;
e923dd62 12205 bool changed;
1de27621
DA
12206 struct route_map *route_map =
12207 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12208
12209 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12210 protocol = ZEBRA_ROUTE_OSPF;
12211 else
12212 protocol = ZEBRA_ROUTE_TABLE;
12213
12214 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12215 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12216 changed =
12217 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12218 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12219}
12220
12221ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12222 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12223 "redistribute <ospf|table> (1-65535) route-map WORD",
12224 "Redistribute information from another routing protocol\n"
12225 "Open Shortest Path First (OSPFv2)\n"
12226 "Non-main Kernel Routing Table\n"
12227 "Instance ID/Table ID\n"
12228 "Route map reference\n"
12229 "Pointer to route-map entries\n")
596c17ba 12230
7c8ff89e
DS
12231DEFUN (bgp_redistribute_ipv4_ospf_metric,
12232 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12233 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12234 "Redistribute information from another routing protocol\n"
12235 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12236 "Non-main Kernel Routing Table\n"
12237 "Instance ID/Table ID\n"
7c8ff89e
DS
12238 "Metric for redistributed routes\n"
12239 "Default metric\n")
12240{
d62a17ae 12241 VTY_DECLVAR_CONTEXT(bgp, bgp);
12242 int idx_ospf_table = 1;
12243 int idx_number = 2;
12244 int idx_number_2 = 4;
d7c0a89a 12245 uint32_t metric;
d62a17ae 12246 struct bgp_redist *red;
d7c0a89a 12247 unsigned short instance;
d62a17ae 12248 int protocol;
e923dd62 12249 bool changed;
d62a17ae 12250
12251 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12252 protocol = ZEBRA_ROUTE_OSPF;
12253 else
12254 protocol = ZEBRA_ROUTE_TABLE;
12255
12256 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12257 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12258
12259 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12260 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12261 metric);
12262 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12263}
12264
12265ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12266 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12267 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12268 "Redistribute information from another routing protocol\n"
12269 "Open Shortest Path First (OSPFv2)\n"
12270 "Non-main Kernel Routing Table\n"
12271 "Instance ID/Table ID\n"
12272 "Metric for redistributed routes\n"
12273 "Default metric\n")
596c17ba 12274
7c8ff89e
DS
12275DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12276 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12277 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12278 "Redistribute information from another routing protocol\n"
12279 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12280 "Non-main Kernel Routing Table\n"
12281 "Instance ID/Table ID\n"
7c8ff89e
DS
12282 "Route map reference\n"
12283 "Pointer to route-map entries\n"
12284 "Metric for redistributed routes\n"
12285 "Default metric\n")
12286{
d62a17ae 12287 VTY_DECLVAR_CONTEXT(bgp, bgp);
12288 int idx_ospf_table = 1;
12289 int idx_number = 2;
12290 int idx_word = 4;
12291 int idx_number_2 = 6;
d7c0a89a 12292 uint32_t metric;
d62a17ae 12293 struct bgp_redist *red;
d7c0a89a 12294 unsigned short instance;
d62a17ae 12295 int protocol;
e923dd62 12296 bool changed;
1de27621
DA
12297 struct route_map *route_map =
12298 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12299
12300 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12301 protocol = ZEBRA_ROUTE_OSPF;
12302 else
12303 protocol = ZEBRA_ROUTE_TABLE;
12304
12305 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12306 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12307
12308 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12309 changed =
12310 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12311 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12312 metric);
12313 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12314}
12315
12316ALIAS_HIDDEN(
12317 bgp_redistribute_ipv4_ospf_rmap_metric,
12318 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12319 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12320 "Redistribute information from another routing protocol\n"
12321 "Open Shortest Path First (OSPFv2)\n"
12322 "Non-main Kernel Routing Table\n"
12323 "Instance ID/Table ID\n"
12324 "Route map reference\n"
12325 "Pointer to route-map entries\n"
12326 "Metric for redistributed routes\n"
12327 "Default metric\n")
596c17ba 12328
7c8ff89e
DS
12329DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12330 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12331 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12332 "Redistribute information from another routing protocol\n"
12333 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12334 "Non-main Kernel Routing Table\n"
12335 "Instance ID/Table ID\n"
7c8ff89e
DS
12336 "Metric for redistributed routes\n"
12337 "Default metric\n"
12338 "Route map reference\n"
12339 "Pointer to route-map entries\n")
12340{
d62a17ae 12341 VTY_DECLVAR_CONTEXT(bgp, bgp);
12342 int idx_ospf_table = 1;
12343 int idx_number = 2;
12344 int idx_number_2 = 4;
12345 int idx_word = 6;
d7c0a89a 12346 uint32_t metric;
d62a17ae 12347 struct bgp_redist *red;
d7c0a89a 12348 unsigned short instance;
d62a17ae 12349 int protocol;
e923dd62 12350 bool changed;
1de27621
DA
12351 struct route_map *route_map =
12352 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12353
12354 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12355 protocol = ZEBRA_ROUTE_OSPF;
12356 else
12357 protocol = ZEBRA_ROUTE_TABLE;
12358
12359 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12360 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12361
12362 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12363 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12364 metric);
1de27621
DA
12365 changed |=
12366 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12367 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12368}
12369
12370ALIAS_HIDDEN(
12371 bgp_redistribute_ipv4_ospf_metric_rmap,
12372 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12373 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12374 "Redistribute information from another routing protocol\n"
12375 "Open Shortest Path First (OSPFv2)\n"
12376 "Non-main Kernel Routing Table\n"
12377 "Instance ID/Table ID\n"
12378 "Metric for redistributed routes\n"
12379 "Default metric\n"
12380 "Route map reference\n"
12381 "Pointer to route-map entries\n")
596c17ba 12382
7c8ff89e
DS
12383DEFUN (no_bgp_redistribute_ipv4_ospf,
12384 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 12385 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
12386 NO_STR
12387 "Redistribute information from another routing protocol\n"
12388 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12389 "Non-main Kernel Routing Table\n"
31500417
DW
12390 "Instance ID/Table ID\n"
12391 "Metric for redistributed routes\n"
12392 "Default metric\n"
12393 "Route map reference\n"
12394 "Pointer to route-map entries\n")
7c8ff89e 12395{
d62a17ae 12396 VTY_DECLVAR_CONTEXT(bgp, bgp);
12397 int idx_ospf_table = 2;
12398 int idx_number = 3;
d7c0a89a 12399 unsigned short instance;
d62a17ae 12400 int protocol;
12401
12402 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12403 protocol = ZEBRA_ROUTE_OSPF;
12404 else
12405 protocol = ZEBRA_ROUTE_TABLE;
12406
12407 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12408 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12409}
12410
12411ALIAS_HIDDEN(
12412 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12413 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12414 NO_STR
12415 "Redistribute information from another routing protocol\n"
12416 "Open Shortest Path First (OSPFv2)\n"
12417 "Non-main Kernel Routing Table\n"
12418 "Instance ID/Table ID\n"
12419 "Metric for redistributed routes\n"
12420 "Default metric\n"
12421 "Route map reference\n"
12422 "Pointer to route-map entries\n")
596c17ba 12423
718e3744 12424DEFUN (no_bgp_redistribute_ipv4,
12425 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 12426 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12427 NO_STR
12428 "Redistribute information from another routing protocol\n"
3b14d86e 12429 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12430 "Metric for redistributed routes\n"
12431 "Default metric\n"
12432 "Route map reference\n"
12433 "Pointer to route-map entries\n")
718e3744 12434{
d62a17ae 12435 VTY_DECLVAR_CONTEXT(bgp, bgp);
12436 int idx_protocol = 2;
12437 int type;
12438
12439 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12440 if (type < 0) {
12441 vty_out(vty, "%% Invalid route type\n");
12442 return CMD_WARNING_CONFIG_FAILED;
12443 }
12444 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12445}
12446
12447ALIAS_HIDDEN(
12448 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12449 "no redistribute " FRR_IP_REDIST_STR_BGPD
12450 " [metric (0-4294967295)] [route-map WORD]",
12451 NO_STR
12452 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12453 "Metric for redistributed routes\n"
12454 "Default metric\n"
12455 "Route map reference\n"
12456 "Pointer to route-map entries\n")
596c17ba 12457
718e3744 12458DEFUN (bgp_redistribute_ipv6,
12459 bgp_redistribute_ipv6_cmd,
40d1cbfb 12460 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12461 "Redistribute information from another routing protocol\n"
ab0181ee 12462 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12463{
d62a17ae 12464 VTY_DECLVAR_CONTEXT(bgp, bgp);
12465 int idx_protocol = 1;
12466 int type;
718e3744 12467
d62a17ae 12468 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12469 if (type < 0) {
12470 vty_out(vty, "%% Invalid route type\n");
12471 return CMD_WARNING_CONFIG_FAILED;
12472 }
718e3744 12473
d62a17ae 12474 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12475 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12476}
12477
12478DEFUN (bgp_redistribute_ipv6_rmap,
12479 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12480 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12481 "Redistribute information from another routing protocol\n"
ab0181ee 12482 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12483 "Route map reference\n"
12484 "Pointer to route-map entries\n")
12485{
d62a17ae 12486 VTY_DECLVAR_CONTEXT(bgp, bgp);
12487 int idx_protocol = 1;
12488 int idx_word = 3;
12489 int type;
12490 struct bgp_redist *red;
e923dd62 12491 bool changed;
1de27621
DA
12492 struct route_map *route_map =
12493 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12494
d62a17ae 12495 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12496 if (type < 0) {
12497 vty_out(vty, "%% Invalid route type\n");
12498 return CMD_WARNING_CONFIG_FAILED;
12499 }
718e3744 12500
d62a17ae 12501 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12502 changed =
12503 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12504 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12505}
12506
12507DEFUN (bgp_redistribute_ipv6_metric,
12508 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12509 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12510 "Redistribute information from another routing protocol\n"
ab0181ee 12511 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12512 "Metric for redistributed routes\n"
12513 "Default metric\n")
12514{
d62a17ae 12515 VTY_DECLVAR_CONTEXT(bgp, bgp);
12516 int idx_protocol = 1;
12517 int idx_number = 3;
12518 int type;
d7c0a89a 12519 uint32_t metric;
d62a17ae 12520 struct bgp_redist *red;
e923dd62 12521 bool changed;
d62a17ae 12522
12523 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12524 if (type < 0) {
12525 vty_out(vty, "%% Invalid route type\n");
12526 return CMD_WARNING_CONFIG_FAILED;
12527 }
12528 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12529
d62a17ae 12530 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12531 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12532 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12533}
12534
12535DEFUN (bgp_redistribute_ipv6_rmap_metric,
12536 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12537 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12538 "Redistribute information from another routing protocol\n"
ab0181ee 12539 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12540 "Route map reference\n"
12541 "Pointer to route-map entries\n"
12542 "Metric for redistributed routes\n"
12543 "Default metric\n")
12544{
d62a17ae 12545 VTY_DECLVAR_CONTEXT(bgp, bgp);
12546 int idx_protocol = 1;
12547 int idx_word = 3;
12548 int idx_number = 5;
12549 int type;
d7c0a89a 12550 uint32_t metric;
d62a17ae 12551 struct bgp_redist *red;
e923dd62 12552 bool changed;
1de27621
DA
12553 struct route_map *route_map =
12554 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12555
12556 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12557 if (type < 0) {
12558 vty_out(vty, "%% Invalid route type\n");
12559 return CMD_WARNING_CONFIG_FAILED;
12560 }
12561 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12562
d62a17ae 12563 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12564 changed =
12565 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12566 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12567 metric);
12568 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12569}
12570
12571DEFUN (bgp_redistribute_ipv6_metric_rmap,
12572 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12573 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12574 "Redistribute information from another routing protocol\n"
ab0181ee 12575 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12576 "Metric for redistributed routes\n"
12577 "Default metric\n"
12578 "Route map reference\n"
12579 "Pointer to route-map entries\n")
12580{
d62a17ae 12581 VTY_DECLVAR_CONTEXT(bgp, bgp);
12582 int idx_protocol = 1;
12583 int idx_number = 3;
12584 int idx_word = 5;
12585 int type;
d7c0a89a 12586 uint32_t metric;
d62a17ae 12587 struct bgp_redist *red;
e923dd62 12588 bool changed;
1de27621
DA
12589 struct route_map *route_map =
12590 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12591
12592 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12593 if (type < 0) {
12594 vty_out(vty, "%% Invalid route type\n");
12595 return CMD_WARNING_CONFIG_FAILED;
12596 }
12597 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12598
d62a17ae 12599 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12600 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12601 metric);
1de27621
DA
12602 changed |=
12603 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12604 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12605}
12606
12607DEFUN (no_bgp_redistribute_ipv6,
12608 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 12609 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 12610 NO_STR
12611 "Redistribute information from another routing protocol\n"
3b14d86e 12612 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12613 "Metric for redistributed routes\n"
12614 "Default metric\n"
12615 "Route map reference\n"
12616 "Pointer to route-map entries\n")
718e3744 12617{
d62a17ae 12618 VTY_DECLVAR_CONTEXT(bgp, bgp);
12619 int idx_protocol = 2;
12620 int type;
718e3744 12621
d62a17ae 12622 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12623 if (type < 0) {
12624 vty_out(vty, "%% Invalid route type\n");
12625 return CMD_WARNING_CONFIG_FAILED;
12626 }
718e3744 12627
d62a17ae 12628 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12629}
12630
2b791107 12631void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12632 safi_t safi)
d62a17ae 12633{
12634 int i;
12635
12636 /* Unicast redistribution only. */
12637 if (safi != SAFI_UNICAST)
2b791107 12638 return;
d62a17ae 12639
12640 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12641 /* Redistribute BGP does not make sense. */
12642 if (i != ZEBRA_ROUTE_BGP) {
12643 struct list *red_list;
12644 struct listnode *node;
12645 struct bgp_redist *red;
12646
12647 red_list = bgp->redist[afi][i];
12648 if (!red_list)
12649 continue;
12650
12651 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12652 /* "redistribute" configuration. */
12653 vty_out(vty, " redistribute %s",
12654 zebra_route_string(i));
12655 if (red->instance)
12656 vty_out(vty, " %d", red->instance);
12657 if (red->redist_metric_flag)
12658 vty_out(vty, " metric %u",
12659 red->redist_metric);
12660 if (red->rmap.name)
12661 vty_out(vty, " route-map %s",
12662 red->rmap.name);
12663 vty_out(vty, "\n");
12664 }
12665 }
12666 }
718e3744 12667}
6b0655a2 12668
b9c7bc5a
PZ
12669/* This is part of the address-family block (unicast only) */
12670void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12671 afi_t afi)
12672{
b9c7bc5a 12673 int indent = 2;
ddb5b488 12674
8a066a70
PG
12675 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12676 if (listcount(bgp->vpn_policy[afi].import_vrf))
12677 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12678 bgp->vpn_policy[afi]
bb4f6190 12679 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12680 else
12681 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12682 bgp->vpn_policy[afi]
12683 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12684 }
12a844a5
DS
12685 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12686 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12687 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12688 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12689 return;
12690
e70e9f8e
PZ
12691 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12692 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12693
12694 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12695
12696 } else {
12697 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12698 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12699 bgp->vpn_policy[afi].tovpn_label);
12700 }
ddb5b488
PZ
12701 }
12702 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12703 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12704 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12705 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12706 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12707 sizeof(buf)));
12708 }
12709 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12710 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12711
12712 char buf[PREFIX_STRLEN];
12713 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12714 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12715 sizeof(buf))) {
12716
b9c7bc5a
PZ
12717 vty_out(vty, "%*snexthop vpn export %s\n",
12718 indent, "", buf);
ddb5b488
PZ
12719 }
12720 }
12721 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12722 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12723 && ecommunity_cmp(
12724 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12725 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12726
12727 char *b = ecommunity_ecom2str(
12728 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12729 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12730 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12731 XFREE(MTYPE_ECOMMUNITY_STR, b);
12732 } else {
12733 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12734 char *b = ecommunity_ecom2str(
12735 bgp->vpn_policy[afi]
12736 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12737 ECOMMUNITY_FORMAT_ROUTE_MAP,
12738 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12739 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12740 XFREE(MTYPE_ECOMMUNITY_STR, b);
12741 }
12742 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12743 char *b = ecommunity_ecom2str(
12744 bgp->vpn_policy[afi]
12745 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12746 ECOMMUNITY_FORMAT_ROUTE_MAP,
12747 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12748 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12749 XFREE(MTYPE_ECOMMUNITY_STR, b);
12750 }
12751 }
bb4f6190
DS
12752
12753 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12754 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12755 bgp->vpn_policy[afi]
12756 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12757
301ad80a
PG
12758 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12759 char *b = ecommunity_ecom2str(
12760 bgp->vpn_policy[afi]
12761 .import_redirect_rtlist,
12762 ECOMMUNITY_FORMAT_ROUTE_MAP,
12763 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12764
301ad80a
PG
12765 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12766 XFREE(MTYPE_ECOMMUNITY_STR, b);
12767 }
ddb5b488
PZ
12768}
12769
12770
718e3744 12771/* BGP node structure. */
d62a17ae 12772static struct cmd_node bgp_node = {
9d303b37 12773 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12774};
12775
d62a17ae 12776static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12777 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12778};
12779
d62a17ae 12780static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12781 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12782};
12783
d62a17ae 12784static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12785 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12786};
12787
d62a17ae 12788static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12789 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12790};
12791
d62a17ae 12792static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12793 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12794};
12795
d62a17ae 12796static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12797 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12798};
12799
d62a17ae 12800static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12801 "%s(config-router-af)# ", 1};
6b0655a2 12802
d62a17ae 12803static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12804 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12805
d62a17ae 12806static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12807 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12808
d62a17ae 12809static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12810 "%s(config-router-af-vni)# ", 1};
90e60aa7 12811
7c40bf39 12812static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12813 "%s(config-router-af)# ", 1};
12814
12815static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12816 "%s(config-router-af-vpnv6)# ", 1};
12817
d62a17ae 12818static void community_list_vty(void);
1f8ae70b 12819
d62a17ae 12820static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12821{
d62a17ae 12822 struct bgp *bgp;
12823 struct peer *peer;
d62a17ae 12824 struct listnode *lnbgp, *lnpeer;
b8a815e5 12825
d62a17ae 12826 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12827 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12828 /* only provide suggestions on the appropriate input
12829 * token type,
12830 * they'll otherwise show up multiple times */
12831 enum cmd_token_type match_type;
12832 char *name = peer->host;
d48ed3e0 12833
d62a17ae 12834 if (peer->conf_if) {
12835 match_type = VARIABLE_TKN;
12836 name = peer->conf_if;
12837 } else if (strchr(peer->host, ':'))
12838 match_type = IPV6_TKN;
12839 else
12840 match_type = IPV4_TKN;
d48ed3e0 12841
d62a17ae 12842 if (token->type != match_type)
12843 continue;
d48ed3e0 12844
d62a17ae 12845 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12846 }
d62a17ae 12847 }
b8a815e5
DL
12848}
12849
12850static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12851 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12852 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12853 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12854 {.completions = NULL}};
12855
47a306a0
DS
12856static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12857{
12858 struct bgp *bgp;
12859 struct peer_group *group;
12860 struct listnode *lnbgp, *lnpeer;
12861
12862 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12863 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12864 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12865 group->name));
12866 }
12867}
12868
12869static const struct cmd_variable_handler bgp_var_peergroup[] = {
12870 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12871 {.completions = NULL} };
12872
d62a17ae 12873void bgp_vty_init(void)
12874{
12875 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12876 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12877
12878 /* Install bgp top node. */
12879 install_node(&bgp_node, bgp_config_write);
12880 install_node(&bgp_ipv4_unicast_node, NULL);
12881 install_node(&bgp_ipv4_multicast_node, NULL);
12882 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12883 install_node(&bgp_ipv6_unicast_node, NULL);
12884 install_node(&bgp_ipv6_multicast_node, NULL);
12885 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12886 install_node(&bgp_vpnv4_node, NULL);
12887 install_node(&bgp_vpnv6_node, NULL);
12888 install_node(&bgp_evpn_node, NULL);
12889 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12890 install_node(&bgp_flowspecv4_node, NULL);
12891 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12892
12893 /* Install default VTY commands to new nodes. */
12894 install_default(BGP_NODE);
12895 install_default(BGP_IPV4_NODE);
12896 install_default(BGP_IPV4M_NODE);
12897 install_default(BGP_IPV4L_NODE);
12898 install_default(BGP_IPV6_NODE);
12899 install_default(BGP_IPV6M_NODE);
12900 install_default(BGP_IPV6L_NODE);
12901 install_default(BGP_VPNV4_NODE);
12902 install_default(BGP_VPNV6_NODE);
7c40bf39 12903 install_default(BGP_FLOWSPECV4_NODE);
12904 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12905 install_default(BGP_EVPN_NODE);
12906 install_default(BGP_EVPN_VNI_NODE);
12907
12908 /* "bgp multiple-instance" commands. */
12909 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12910 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12911
12912 /* "bgp config-type" commands. */
12913 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12914 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12915
8029b216
AK
12916 /* "bgp local-mac" hidden commands. */
12917 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12918 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12919
d62a17ae 12920 /* bgp route-map delay-timer commands. */
12921 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12922 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12923
12924 /* Dummy commands (Currently not supported) */
12925 install_element(BGP_NODE, &no_synchronization_cmd);
12926 install_element(BGP_NODE, &no_auto_summary_cmd);
12927
12928 /* "router bgp" commands. */
12929 install_element(CONFIG_NODE, &router_bgp_cmd);
12930
12931 /* "no router bgp" commands. */
12932 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12933
12934 /* "bgp router-id" commands. */
12935 install_element(BGP_NODE, &bgp_router_id_cmd);
12936 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12937
12938 /* "bgp cluster-id" commands. */
12939 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12940 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12941
12942 /* "bgp confederation" commands. */
12943 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12944 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12945
12946 /* "bgp confederation peers" commands. */
12947 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12948 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12949
12950 /* bgp max-med command */
12951 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12952 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12953 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12954 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12955 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12956
12957 /* bgp disable-ebgp-connected-nh-check */
12958 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12959 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12960
12961 /* bgp update-delay command */
12962 install_element(BGP_NODE, &bgp_update_delay_cmd);
12963 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12964 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12965
12966 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12967 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12968 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12969 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12970
12971 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12972 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12973
12974 /* "maximum-paths" commands. */
12975 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12976 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12977 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12978 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12979 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12980 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12981 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12982 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12983 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12984 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12985 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12986 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12987 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12988 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12989 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12990
12991 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12992 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12993 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12994 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12995 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12996
12997 /* "timers bgp" commands. */
12998 install_element(BGP_NODE, &bgp_timers_cmd);
12999 install_element(BGP_NODE, &no_bgp_timers_cmd);
13000
13001 /* route-map delay-timer commands - per instance for backwards compat.
13002 */
13003 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13004 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13005
13006 /* "bgp client-to-client reflection" commands */
13007 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13008 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13009
13010 /* "bgp always-compare-med" commands */
13011 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13012 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13013
9dac9fc8
DA
13014 /* bgp ebgp-requires-policy */
13015 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13016 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13017
d62a17ae 13018 /* "bgp deterministic-med" commands */
13019 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13020 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13021
13022 /* "bgp graceful-restart" commands */
13023 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13024 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13025 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13026 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13027 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13028 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13029
13030 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13031 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13032
7f323236
DW
13033 /* "bgp graceful-shutdown" commands */
13034 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13035 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13036
d62a17ae 13037 /* "bgp fast-external-failover" commands */
13038 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13039 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13040
13041 /* "bgp enforce-first-as" commands */
13042 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
d62a17ae 13043
13044 /* "bgp bestpath compare-routerid" commands */
13045 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13046 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13047
13048 /* "bgp bestpath as-path ignore" commands */
13049 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13050 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13051
13052 /* "bgp bestpath as-path confed" commands */
13053 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13054 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13055
13056 /* "bgp bestpath as-path multipath-relax" commands */
13057 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13058 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13059
13060 /* "bgp log-neighbor-changes" commands */
13061 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13062 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13063
13064 /* "bgp bestpath med" commands */
13065 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13066 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13067
13068 /* "no bgp default ipv4-unicast" commands. */
13069 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13070 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13071
13072 /* "bgp network import-check" commands. */
13073 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13074 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13075 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13076
13077 /* "bgp default local-preference" commands. */
13078 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13079 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13080
13081 /* bgp default show-hostname */
13082 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13083 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13084
13085 /* "bgp default subgroup-pkt-queue-max" commands. */
13086 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13087 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13088
13089 /* bgp ibgp-allow-policy-mods command */
13090 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13091 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13092
13093 /* "bgp listen limit" commands. */
13094 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13095 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13096
13097 /* "bgp listen range" commands. */
13098 install_element(BGP_NODE, &bgp_listen_range_cmd);
13099 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13100
8175f54a 13101 /* "bgp default shutdown" command */
f26845f9
QY
13102 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13103
d62a17ae 13104 /* "neighbor remote-as" commands. */
13105 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13106 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13107 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13108 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13109 install_element(BGP_NODE,
13110 &neighbor_interface_v6only_config_remote_as_cmd);
13111 install_element(BGP_NODE, &no_neighbor_cmd);
13112 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13113
13114 /* "neighbor peer-group" commands. */
13115 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13116 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13117 install_element(BGP_NODE,
13118 &no_neighbor_interface_peer_group_remote_as_cmd);
13119
13120 /* "neighbor local-as" commands. */
13121 install_element(BGP_NODE, &neighbor_local_as_cmd);
13122 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13123 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13124 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13125
13126 /* "neighbor solo" commands. */
13127 install_element(BGP_NODE, &neighbor_solo_cmd);
13128 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13129
13130 /* "neighbor password" commands. */
13131 install_element(BGP_NODE, &neighbor_password_cmd);
13132 install_element(BGP_NODE, &no_neighbor_password_cmd);
13133
13134 /* "neighbor activate" commands. */
13135 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13136 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13137 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13139 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13140 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13141 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13142 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13143 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13144 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13145 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13146 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13147
13148 /* "no neighbor activate" commands. */
13149 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13150 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13151 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13152 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13153 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13154 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13155 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13156 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13157 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13158 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13159 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13160 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13161
13162 /* "neighbor peer-group" set commands. */
13163 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13164 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13165 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13166 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13167 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13169 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13170 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13171 install_element(BGP_FLOWSPECV4_NODE,
13172 &neighbor_set_peer_group_hidden_cmd);
13173 install_element(BGP_FLOWSPECV6_NODE,
13174 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13175
13176 /* "no neighbor peer-group unset" commands. */
13177 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13178 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13179 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13180 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13181 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13182 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13183 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13184 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13185 install_element(BGP_FLOWSPECV4_NODE,
13186 &no_neighbor_set_peer_group_hidden_cmd);
13187 install_element(BGP_FLOWSPECV6_NODE,
13188 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13189
13190 /* "neighbor softreconfiguration inbound" commands.*/
13191 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13192 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13194 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13195 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13196 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13197 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13198 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13199 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13200 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13201 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13202 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13203 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13204 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13205 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13206 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13207 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13208 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13209 install_element(BGP_FLOWSPECV4_NODE,
13210 &neighbor_soft_reconfiguration_cmd);
13211 install_element(BGP_FLOWSPECV4_NODE,
13212 &no_neighbor_soft_reconfiguration_cmd);
13213 install_element(BGP_FLOWSPECV6_NODE,
13214 &neighbor_soft_reconfiguration_cmd);
13215 install_element(BGP_FLOWSPECV6_NODE,
13216 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13217 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13218 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13219
13220 /* "neighbor attribute-unchanged" commands. */
13221 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13222 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13223 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13224 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13225 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13226 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13227 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13228 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13229 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13230 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13231 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13232 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13233 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13234 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13235 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13236 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13237 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13238 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13239
13240 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13241 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13242
13243 /* "nexthop-local unchanged" commands */
13244 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13245 install_element(BGP_IPV6_NODE,
13246 &no_neighbor_nexthop_local_unchanged_cmd);
13247
13248 /* "neighbor next-hop-self" commands. */
13249 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13250 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13251 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13252 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13253 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13254 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13255 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13256 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13257 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13258 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13259 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13260 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13261 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13262 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13263 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13264 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13265 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13266 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13267 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13268 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13269
13270 /* "neighbor next-hop-self force" commands. */
13271 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13272 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
13273 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13274 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13275 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13276 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13277 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13278 install_element(BGP_IPV4_NODE,
13279 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13280 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13281 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13282 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13283 install_element(BGP_IPV4M_NODE,
13284 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13285 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13286 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13287 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13288 install_element(BGP_IPV4L_NODE,
13289 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13290 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13291 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13292 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13293 install_element(BGP_IPV6_NODE,
13294 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13295 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13296 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13297 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13298 install_element(BGP_IPV6M_NODE,
13299 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13300 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13301 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13302 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13303 install_element(BGP_IPV6L_NODE,
13304 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13305 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13306 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13307 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13308 install_element(BGP_VPNV4_NODE,
13309 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13310 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13311 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
ef298c61
DA
13312 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13313 install_element(BGP_VPNV6_NODE,
13314 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13315
13316 /* "neighbor as-override" commands. */
13317 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13318 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13319 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13320 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13321 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13322 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13323 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13324 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13325 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13326 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13327 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13328 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13329 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13330 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13331 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13332 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13333 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13334 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13335
13336 /* "neighbor remove-private-AS" commands. */
13337 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13338 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13339 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13340 install_element(BGP_NODE,
13341 &no_neighbor_remove_private_as_all_hidden_cmd);
13342 install_element(BGP_NODE,
13343 &neighbor_remove_private_as_replace_as_hidden_cmd);
13344 install_element(BGP_NODE,
13345 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13346 install_element(BGP_NODE,
13347 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13348 install_element(
13349 BGP_NODE,
13350 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13351 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13352 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13353 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13354 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13355 install_element(BGP_IPV4_NODE,
13356 &neighbor_remove_private_as_replace_as_cmd);
13357 install_element(BGP_IPV4_NODE,
13358 &no_neighbor_remove_private_as_replace_as_cmd);
13359 install_element(BGP_IPV4_NODE,
13360 &neighbor_remove_private_as_all_replace_as_cmd);
13361 install_element(BGP_IPV4_NODE,
13362 &no_neighbor_remove_private_as_all_replace_as_cmd);
13363 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13364 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13365 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13366 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13367 install_element(BGP_IPV4M_NODE,
13368 &neighbor_remove_private_as_replace_as_cmd);
13369 install_element(BGP_IPV4M_NODE,
13370 &no_neighbor_remove_private_as_replace_as_cmd);
13371 install_element(BGP_IPV4M_NODE,
13372 &neighbor_remove_private_as_all_replace_as_cmd);
13373 install_element(BGP_IPV4M_NODE,
13374 &no_neighbor_remove_private_as_all_replace_as_cmd);
13375 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13376 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13377 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13378 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13379 install_element(BGP_IPV4L_NODE,
13380 &neighbor_remove_private_as_replace_as_cmd);
13381 install_element(BGP_IPV4L_NODE,
13382 &no_neighbor_remove_private_as_replace_as_cmd);
13383 install_element(BGP_IPV4L_NODE,
13384 &neighbor_remove_private_as_all_replace_as_cmd);
13385 install_element(BGP_IPV4L_NODE,
13386 &no_neighbor_remove_private_as_all_replace_as_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13388 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13389 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13390 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13391 install_element(BGP_IPV6_NODE,
13392 &neighbor_remove_private_as_replace_as_cmd);
13393 install_element(BGP_IPV6_NODE,
13394 &no_neighbor_remove_private_as_replace_as_cmd);
13395 install_element(BGP_IPV6_NODE,
13396 &neighbor_remove_private_as_all_replace_as_cmd);
13397 install_element(BGP_IPV6_NODE,
13398 &no_neighbor_remove_private_as_all_replace_as_cmd);
13399 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13400 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13401 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13402 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13403 install_element(BGP_IPV6M_NODE,
13404 &neighbor_remove_private_as_replace_as_cmd);
13405 install_element(BGP_IPV6M_NODE,
13406 &no_neighbor_remove_private_as_replace_as_cmd);
13407 install_element(BGP_IPV6M_NODE,
13408 &neighbor_remove_private_as_all_replace_as_cmd);
13409 install_element(BGP_IPV6M_NODE,
13410 &no_neighbor_remove_private_as_all_replace_as_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13412 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13413 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13414 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13415 install_element(BGP_IPV6L_NODE,
13416 &neighbor_remove_private_as_replace_as_cmd);
13417 install_element(BGP_IPV6L_NODE,
13418 &no_neighbor_remove_private_as_replace_as_cmd);
13419 install_element(BGP_IPV6L_NODE,
13420 &neighbor_remove_private_as_all_replace_as_cmd);
13421 install_element(BGP_IPV6L_NODE,
13422 &no_neighbor_remove_private_as_all_replace_as_cmd);
13423 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13424 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13425 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13426 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13427 install_element(BGP_VPNV4_NODE,
13428 &neighbor_remove_private_as_replace_as_cmd);
13429 install_element(BGP_VPNV4_NODE,
13430 &no_neighbor_remove_private_as_replace_as_cmd);
13431 install_element(BGP_VPNV4_NODE,
13432 &neighbor_remove_private_as_all_replace_as_cmd);
13433 install_element(BGP_VPNV4_NODE,
13434 &no_neighbor_remove_private_as_all_replace_as_cmd);
13435 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13436 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13437 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13438 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13439 install_element(BGP_VPNV6_NODE,
13440 &neighbor_remove_private_as_replace_as_cmd);
13441 install_element(BGP_VPNV6_NODE,
13442 &no_neighbor_remove_private_as_replace_as_cmd);
13443 install_element(BGP_VPNV6_NODE,
13444 &neighbor_remove_private_as_all_replace_as_cmd);
13445 install_element(BGP_VPNV6_NODE,
13446 &no_neighbor_remove_private_as_all_replace_as_cmd);
13447
13448 /* "neighbor send-community" commands.*/
13449 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13450 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13451 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13452 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13453 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13454 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13455 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13456 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13457 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13458 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13459 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13460 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13461 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13462 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13463 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13464 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13465 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13466 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13467 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13468 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13469 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13470 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13471 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13472 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13473 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13474 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13475 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13476 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13477 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13478 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13479 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13480 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13481 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13482 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13483 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13484 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13485
13486 /* "neighbor route-reflector" commands.*/
13487 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13488 install_element(BGP_NODE,
13489 &no_neighbor_route_reflector_client_hidden_cmd);
13490 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13491 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13492 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13493 install_element(BGP_IPV4M_NODE,
13494 &no_neighbor_route_reflector_client_cmd);
13495 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13496 install_element(BGP_IPV4L_NODE,
13497 &no_neighbor_route_reflector_client_cmd);
13498 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13499 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13500 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13501 install_element(BGP_IPV6M_NODE,
13502 &no_neighbor_route_reflector_client_cmd);
13503 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13504 install_element(BGP_IPV6L_NODE,
13505 &no_neighbor_route_reflector_client_cmd);
13506 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13507 install_element(BGP_VPNV4_NODE,
13508 &no_neighbor_route_reflector_client_cmd);
13509 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13510 install_element(BGP_VPNV6_NODE,
13511 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13512 install_element(BGP_FLOWSPECV4_NODE,
13513 &neighbor_route_reflector_client_cmd);
13514 install_element(BGP_FLOWSPECV4_NODE,
13515 &no_neighbor_route_reflector_client_cmd);
13516 install_element(BGP_FLOWSPECV6_NODE,
13517 &neighbor_route_reflector_client_cmd);
13518 install_element(BGP_FLOWSPECV6_NODE,
13519 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13520 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13521 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13522
13523 /* "neighbor route-server" commands.*/
13524 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13525 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13526 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13527 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13528 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13529 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13530 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13531 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13532 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13533 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13534 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13535 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13536 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13537 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13538 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13539 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13540 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13541 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13542 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13543 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13544 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13545 install_element(BGP_FLOWSPECV4_NODE,
13546 &no_neighbor_route_server_client_cmd);
13547 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13548 install_element(BGP_FLOWSPECV6_NODE,
13549 &no_neighbor_route_server_client_cmd);
d62a17ae 13550
13551 /* "neighbor addpath-tx-all-paths" commands.*/
13552 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13553 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13554 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13555 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13556 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13557 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13558 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13559 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13560 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13561 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13562 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13563 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13564 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13565 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13566 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13567 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13568 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13569 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13570
13571 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13572 install_element(BGP_NODE,
13573 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13574 install_element(BGP_NODE,
13575 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13576 install_element(BGP_IPV4_NODE,
13577 &neighbor_addpath_tx_bestpath_per_as_cmd);
13578 install_element(BGP_IPV4_NODE,
13579 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13580 install_element(BGP_IPV4M_NODE,
13581 &neighbor_addpath_tx_bestpath_per_as_cmd);
13582 install_element(BGP_IPV4M_NODE,
13583 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13584 install_element(BGP_IPV4L_NODE,
13585 &neighbor_addpath_tx_bestpath_per_as_cmd);
13586 install_element(BGP_IPV4L_NODE,
13587 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13588 install_element(BGP_IPV6_NODE,
13589 &neighbor_addpath_tx_bestpath_per_as_cmd);
13590 install_element(BGP_IPV6_NODE,
13591 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13592 install_element(BGP_IPV6M_NODE,
13593 &neighbor_addpath_tx_bestpath_per_as_cmd);
13594 install_element(BGP_IPV6M_NODE,
13595 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13596 install_element(BGP_IPV6L_NODE,
13597 &neighbor_addpath_tx_bestpath_per_as_cmd);
13598 install_element(BGP_IPV6L_NODE,
13599 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13600 install_element(BGP_VPNV4_NODE,
13601 &neighbor_addpath_tx_bestpath_per_as_cmd);
13602 install_element(BGP_VPNV4_NODE,
13603 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13604 install_element(BGP_VPNV6_NODE,
13605 &neighbor_addpath_tx_bestpath_per_as_cmd);
13606 install_element(BGP_VPNV6_NODE,
13607 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13608
13609 /* "neighbor passive" commands. */
13610 install_element(BGP_NODE, &neighbor_passive_cmd);
13611 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13612
13613
13614 /* "neighbor shutdown" commands. */
13615 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13616 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13617 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13618 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13619
13620 /* "neighbor capability extended-nexthop" commands.*/
13621 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13622 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13623
13624 /* "neighbor capability orf prefix-list" commands.*/
13625 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13626 install_element(BGP_NODE,
13627 &no_neighbor_capability_orf_prefix_hidden_cmd);
13628 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13629 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13630 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13631 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13632 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13633 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13634 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13635 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13636 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13637 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13638 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13639 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13640
13641 /* "neighbor capability dynamic" commands.*/
13642 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13643 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13644
13645 /* "neighbor dont-capability-negotiate" commands. */
13646 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13647 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13648
13649 /* "neighbor ebgp-multihop" commands. */
13650 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13651 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13652 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13653
13654 /* "neighbor disable-connected-check" commands. */
13655 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13656 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13657
47cbc09b
PM
13658 /* "neighbor enforce-first-as" commands. */
13659 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13660 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13661
d62a17ae 13662 /* "neighbor description" commands. */
13663 install_element(BGP_NODE, &neighbor_description_cmd);
13664 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13665 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13666
13667 /* "neighbor update-source" commands. "*/
13668 install_element(BGP_NODE, &neighbor_update_source_cmd);
13669 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13670
13671 /* "neighbor default-originate" commands. */
13672 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13673 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13674 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13675 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13676 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13677 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13678 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13679 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13680 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13681 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13682 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13683 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13684 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13685 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13686 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13687 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13688 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13689 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13690 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13691 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13692 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13693
13694 /* "neighbor port" commands. */
13695 install_element(BGP_NODE, &neighbor_port_cmd);
13696 install_element(BGP_NODE, &no_neighbor_port_cmd);
13697
13698 /* "neighbor weight" commands. */
13699 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13700 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13701
13702 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13703 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13704 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13705 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13706 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13707 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13708 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13709 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13710 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13711 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13712 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13713 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13714 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13715 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13716 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13717 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13718
13719 /* "neighbor override-capability" commands. */
13720 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13721 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13722
13723 /* "neighbor strict-capability-match" commands. */
13724 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13725 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13726
13727 /* "neighbor timers" commands. */
13728 install_element(BGP_NODE, &neighbor_timers_cmd);
13729 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13730
13731 /* "neighbor timers connect" commands. */
13732 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13733 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13734
13735 /* "neighbor advertisement-interval" commands. */
13736 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13737 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13738
13739 /* "neighbor interface" commands. */
13740 install_element(BGP_NODE, &neighbor_interface_cmd);
13741 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13742
13743 /* "neighbor distribute" commands. */
13744 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13745 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13746 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13747 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13748 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13749 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13750 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13751 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13752 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13753 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13754 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13755 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13756 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13757 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13758 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13759 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13760 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13761 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13762
13763 /* "neighbor prefix-list" commands. */
13764 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13765 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13766 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13767 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13768 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13769 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13770 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13771 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13772 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13773 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13774 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13775 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13776 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13777 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13778 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13779 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13780 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13781 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13782 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13783 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13784 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13785 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13786
13787 /* "neighbor filter-list" commands. */
13788 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13789 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13790 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13791 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13792 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13793 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13794 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13795 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13796 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13797 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13798 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13799 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13800 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13801 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13802 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13803 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13804 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13805 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13806 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13807 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13808 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13809 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13810
13811 /* "neighbor route-map" commands. */
13812 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13813 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13814 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13815 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13816 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13817 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13818 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13819 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13820 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13821 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13822 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13823 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13824 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13825 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13826 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13827 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13828 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13829 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13830 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13831 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13832 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13833 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13834 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13835 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13836
13837 /* "neighbor unsuppress-map" commands. */
13838 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13839 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13840 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13841 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13842 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13843 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13844 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13845 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13846 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13847 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13848 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13849 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13850 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13851 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13852 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13853 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13854 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13855 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13856
13857 /* "neighbor maximum-prefix" commands. */
13858 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13859 install_element(BGP_NODE,
13860 &neighbor_maximum_prefix_threshold_hidden_cmd);
13861 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13862 install_element(BGP_NODE,
13863 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13864 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13865 install_element(BGP_NODE,
13866 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13867 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13868 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13869 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13870 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13871 install_element(BGP_IPV4_NODE,
13872 &neighbor_maximum_prefix_threshold_warning_cmd);
13873 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13874 install_element(BGP_IPV4_NODE,
13875 &neighbor_maximum_prefix_threshold_restart_cmd);
13876 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13877 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13878 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13879 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13880 install_element(BGP_IPV4M_NODE,
13881 &neighbor_maximum_prefix_threshold_warning_cmd);
13882 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13883 install_element(BGP_IPV4M_NODE,
13884 &neighbor_maximum_prefix_threshold_restart_cmd);
13885 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13886 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13887 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13888 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13889 install_element(BGP_IPV4L_NODE,
13890 &neighbor_maximum_prefix_threshold_warning_cmd);
13891 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13892 install_element(BGP_IPV4L_NODE,
13893 &neighbor_maximum_prefix_threshold_restart_cmd);
13894 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13895 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13896 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13897 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13898 install_element(BGP_IPV6_NODE,
13899 &neighbor_maximum_prefix_threshold_warning_cmd);
13900 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13901 install_element(BGP_IPV6_NODE,
13902 &neighbor_maximum_prefix_threshold_restart_cmd);
13903 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13904 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13905 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13906 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13907 install_element(BGP_IPV6M_NODE,
13908 &neighbor_maximum_prefix_threshold_warning_cmd);
13909 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13910 install_element(BGP_IPV6M_NODE,
13911 &neighbor_maximum_prefix_threshold_restart_cmd);
13912 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13913 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13914 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13915 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13916 install_element(BGP_IPV6L_NODE,
13917 &neighbor_maximum_prefix_threshold_warning_cmd);
13918 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13919 install_element(BGP_IPV6L_NODE,
13920 &neighbor_maximum_prefix_threshold_restart_cmd);
13921 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13922 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13923 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13924 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13925 install_element(BGP_VPNV4_NODE,
13926 &neighbor_maximum_prefix_threshold_warning_cmd);
13927 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13928 install_element(BGP_VPNV4_NODE,
13929 &neighbor_maximum_prefix_threshold_restart_cmd);
13930 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13931 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13932 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13933 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13934 install_element(BGP_VPNV6_NODE,
13935 &neighbor_maximum_prefix_threshold_warning_cmd);
13936 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13937 install_element(BGP_VPNV6_NODE,
13938 &neighbor_maximum_prefix_threshold_restart_cmd);
13939 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13940
13941 /* "neighbor allowas-in" */
13942 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13943 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13944 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13945 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13946 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13947 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13948 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13949 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13950 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13951 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13952 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13953 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13954 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13955 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13956 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13957 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13958 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13959 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13960 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13961 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13962
13963 /* address-family commands. */
13964 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13965 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13966#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13967 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13968 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13969#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13970
d62a17ae 13971 install_element(BGP_NODE, &address_family_evpn_cmd);
13972
13973 /* "exit-address-family" command. */
13974 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13975 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13976 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13977 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13978 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13979 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13980 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13981 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13982 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13983 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13984 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13985
13986 /* "clear ip bgp commands" */
13987 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13988
13989 /* clear ip bgp prefix */
13990 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13991 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13992 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13993
13994 /* "show [ip] bgp summary" commands. */
13995 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13996 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13997 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13998 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13999 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14000 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 14001 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14002
14003 /* "show [ip] bgp neighbors" commands. */
14004 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14005
14006 /* "show [ip] bgp peer-group" commands. */
14007 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14008
14009 /* "show [ip] bgp paths" commands. */
14010 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14011
14012 /* "show [ip] bgp community" commands. */
14013 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14014
14015 /* "show ip bgp large-community" commands. */
14016 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14017 /* "show [ip] bgp attribute-info" commands. */
14018 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 14019 /* "show [ip] bgp route-leak" command */
14020 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 14021
14022 /* "redistribute" commands. */
14023 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14024 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14025 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14026 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14027 install_element(BGP_NODE,
14028 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14029 install_element(BGP_NODE,
14030 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14031 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14032 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14033 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14034 install_element(BGP_NODE,
14035 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14036 install_element(BGP_NODE,
14037 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14038 install_element(BGP_NODE,
14039 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14040 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14041 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14042 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14043 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14044 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14045 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14046 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14047 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14048 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14049 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14050 install_element(BGP_IPV4_NODE,
14051 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14052 install_element(BGP_IPV4_NODE,
14053 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14054 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14055 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14056 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14057 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14058 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14059 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14060
b9c7bc5a
PZ
14061 /* import|export vpn [route-map WORD] */
14062 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14063 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 14064
12a844a5
DS
14065 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14066 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14067
d62a17ae 14068 /* ttl_security commands */
14069 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14070 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14071
14072 /* "show [ip] bgp memory" commands. */
14073 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14074
acf71666
MK
14075 /* "show bgp martian next-hop" */
14076 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14077
48ecf8f5
DS
14078 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14079
d62a17ae 14080 /* "show [ip] bgp views" commands. */
14081 install_element(VIEW_NODE, &show_bgp_views_cmd);
14082
14083 /* "show [ip] bgp vrfs" commands. */
14084 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14085
14086 /* Community-list. */
14087 community_list_vty();
ddb5b488
PZ
14088
14089 /* vpn-policy commands */
b9c7bc5a
PZ
14090 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14091 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14092 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14093 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14094 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14095 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14096 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14097 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14098 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14099 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14100 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14101 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14102
301ad80a
PG
14103 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14104 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14105
b9c7bc5a
PZ
14106 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14107 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14108 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14109 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14110 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14111 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14112 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14113 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14114 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14115 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14116 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14117 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14118}
6b0655a2 14119
718e3744 14120#include "memory.h"
14121#include "bgp_regex.h"
14122#include "bgp_clist.h"
14123#include "bgp_ecommunity.h"
14124
14125/* VTY functions. */
14126
14127/* Direction value to string conversion. */
d62a17ae 14128static const char *community_direct_str(int direct)
14129{
14130 switch (direct) {
14131 case COMMUNITY_DENY:
14132 return "deny";
14133 case COMMUNITY_PERMIT:
14134 return "permit";
14135 default:
14136 return "unknown";
14137 }
718e3744 14138}
14139
14140/* Display error string. */
d62a17ae 14141static void community_list_perror(struct vty *vty, int ret)
14142{
14143 switch (ret) {
14144 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14145 vty_out(vty, "%% Can't find community-list\n");
14146 break;
14147 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14148 vty_out(vty, "%% Malformed community-list value\n");
14149 break;
14150 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14151 vty_out(vty,
14152 "%% Community name conflict, previously defined as standard community\n");
14153 break;
14154 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14155 vty_out(vty,
14156 "%% Community name conflict, previously defined as expanded community\n");
14157 break;
14158 }
718e3744 14159}
14160
5bf15956
DW
14161/* "community-list" keyword help string. */
14162#define COMMUNITY_LIST_STR "Add a community list entry\n"
14163
7336e101
SP
14164/*community-list standard */
14165DEFUN (community_list_standard,
14166 bgp_community_list_standard_cmd,
14167 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14168 BGP_STR
718e3744 14169 COMMUNITY_LIST_STR
14170 "Community list number (standard)\n"
5bf15956 14171 "Add an standard community-list entry\n"
718e3744 14172 "Community list name\n"
14173 "Specify community to reject\n"
14174 "Specify community to accept\n"
14175 COMMUNITY_VAL_STR)
14176{
d62a17ae 14177 char *cl_name_or_number = NULL;
14178 int direct = 0;
14179 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14180
d62a17ae 14181 int idx = 0;
7336e101
SP
14182
14183 if (argv_find(argv, argc, "ip", &idx)) {
14184 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14185 vty_out(vty, "if you are using this please migrate to the below command.\n");
14186 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14187 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14188 }
14189
d62a17ae 14190 argv_find(argv, argc, "(1-99)", &idx);
14191 argv_find(argv, argc, "WORD", &idx);
14192 cl_name_or_number = argv[idx]->arg;
14193 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14194 : COMMUNITY_DENY;
14195 argv_find(argv, argc, "AA:NN", &idx);
14196 char *str = argv_concat(argv, argc, idx);
42f914d4 14197
d62a17ae 14198 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14199 style);
42f914d4 14200
d62a17ae 14201 XFREE(MTYPE_TMP, str);
42f914d4 14202
d62a17ae 14203 if (ret < 0) {
14204 /* Display error string. */
14205 community_list_perror(vty, ret);
14206 return CMD_WARNING_CONFIG_FAILED;
14207 }
42f914d4 14208
d62a17ae 14209 return CMD_SUCCESS;
718e3744 14210}
14211
7336e101
SP
14212#if CONFDATE > 20191005
14213CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14214#endif
14215ALIAS (community_list_standard,
14216 ip_community_list_standard_cmd,
14217 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14218 IP_STR
14219 COMMUNITY_LIST_STR
14220 "Community list number (standard)\n"
5bf15956
DW
14221 "Add an standard community-list entry\n"
14222 "Community list name\n"
718e3744 14223 "Specify community to reject\n"
14224 "Specify community to accept\n"
14225 COMMUNITY_VAL_STR)
7336e101
SP
14226
14227DEFUN (no_community_list_standard_all,
14228 no_bgp_community_list_standard_all_cmd,
14229 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14230 NO_STR
14231 BGP_STR
14232 COMMUNITY_LIST_STR
14233 "Community list number (standard)\n"
14234 "Add an standard community-list entry\n"
14235 "Community list name\n"
14236 "Specify community to reject\n"
14237 "Specify community to accept\n"
14238 COMMUNITY_VAL_STR)
718e3744 14239{
d62a17ae 14240 char *cl_name_or_number = NULL;
174b5cb9 14241 char *str = NULL;
d62a17ae 14242 int direct = 0;
14243 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14244
d62a17ae 14245 int idx = 0;
7336e101
SP
14246
14247 if (argv_find(argv, argc, "ip", &idx)) {
14248 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14249 vty_out(vty, "if you are using this please migrate to the below command.\n");
14250 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14251 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14252 }
14253
174b5cb9
DA
14254 argv_find(argv, argc, "permit", &idx);
14255 argv_find(argv, argc, "deny", &idx);
14256
14257 if (idx) {
14258 direct = argv_find(argv, argc, "permit", &idx)
14259 ? COMMUNITY_PERMIT
14260 : COMMUNITY_DENY;
14261
14262 idx = 0;
14263 argv_find(argv, argc, "AA:NN", &idx);
14264 str = argv_concat(argv, argc, idx);
14265 }
14266
14267 idx = 0;
d62a17ae 14268 argv_find(argv, argc, "(1-99)", &idx);
14269 argv_find(argv, argc, "WORD", &idx);
14270 cl_name_or_number = argv[idx]->arg;
42f914d4 14271
d62a17ae 14272 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14273 direct, style);
42f914d4 14274
d62a17ae 14275 XFREE(MTYPE_TMP, str);
daf9ddbb 14276
d62a17ae 14277 if (ret < 0) {
14278 community_list_perror(vty, ret);
14279 return CMD_WARNING_CONFIG_FAILED;
14280 }
42f914d4 14281
d62a17ae 14282 return CMD_SUCCESS;
718e3744 14283}
7336e101
SP
14284ALIAS (no_community_list_standard_all,
14285 no_ip_community_list_standard_all_cmd,
14286 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14287 NO_STR
718e3744 14288 IP_STR
14289 COMMUNITY_LIST_STR
7336e101
SP
14290 "Community list number (standard)\n"
14291 "Add an standard community-list entry\n"
14292 "Community list name\n"
14293 "Specify community to reject\n"
14294 "Specify community to accept\n"
14295 COMMUNITY_VAL_STR)
14296
174b5cb9
DA
14297ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14298 "no bgp community-list <(1-99)|standard WORD>",
14299 NO_STR BGP_STR COMMUNITY_LIST_STR
14300 "Community list number (standard)\n"
14301 "Add an standard community-list entry\n"
14302 "Community list name\n")
14303
14304ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14305 "no ip community-list <(1-99)|standard WORD>",
14306 NO_STR BGP_STR COMMUNITY_LIST_STR
14307 "Community list number (standard)\n"
14308 "Add an standard community-list entry\n"
14309 "Community list name\n")
14310
7336e101
SP
14311/*community-list expanded */
14312DEFUN (community_list_expanded_all,
14313 bgp_community_list_expanded_all_cmd,
14314 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14315 BGP_STR
14316 COMMUNITY_LIST_STR
718e3744 14317 "Community list number (expanded)\n"
5bf15956 14318 "Add an expanded community-list entry\n"
718e3744 14319 "Community list name\n"
14320 "Specify community to reject\n"
14321 "Specify community to accept\n"
14322 COMMUNITY_VAL_STR)
14323{
d62a17ae 14324 char *cl_name_or_number = NULL;
14325 int direct = 0;
14326 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14327
d62a17ae 14328 int idx = 0;
7336e101
SP
14329 if (argv_find(argv, argc, "ip", &idx)) {
14330 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14331 vty_out(vty, "if you are using this please migrate to the below command.\n");
14332 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14333 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14334 }
d62a17ae 14335 argv_find(argv, argc, "(100-500)", &idx);
14336 argv_find(argv, argc, "WORD", &idx);
14337 cl_name_or_number = argv[idx]->arg;
14338 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14339 : COMMUNITY_DENY;
14340 argv_find(argv, argc, "AA:NN", &idx);
14341 char *str = argv_concat(argv, argc, idx);
42f914d4 14342
d62a17ae 14343 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14344 style);
42f914d4 14345
d62a17ae 14346 XFREE(MTYPE_TMP, str);
42f914d4 14347
d62a17ae 14348 if (ret < 0) {
14349 /* Display error string. */
14350 community_list_perror(vty, ret);
14351 return CMD_WARNING_CONFIG_FAILED;
14352 }
42f914d4 14353
d62a17ae 14354 return CMD_SUCCESS;
718e3744 14355}
14356
7336e101
SP
14357ALIAS (community_list_expanded_all,
14358 ip_community_list_expanded_all_cmd,
14359 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14360 IP_STR
14361 COMMUNITY_LIST_STR
5bf15956
DW
14362 "Community list number (expanded)\n"
14363 "Add an expanded community-list entry\n"
718e3744 14364 "Community list name\n"
14365 "Specify community to reject\n"
14366 "Specify community to accept\n"
5bf15956 14367 COMMUNITY_VAL_STR)
7336e101
SP
14368
14369DEFUN (no_community_list_expanded_all,
14370 no_bgp_community_list_expanded_all_cmd,
14371 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14372 NO_STR
14373 BGP_STR
14374 COMMUNITY_LIST_STR
14375 "Community list number (expanded)\n"
14376 "Add an expanded community-list entry\n"
14377 "Community list name\n"
14378 "Specify community to reject\n"
14379 "Specify community to accept\n"
14380 COMMUNITY_VAL_STR)
718e3744 14381{
d62a17ae 14382 char *cl_name_or_number = NULL;
174b5cb9 14383 char *str = NULL;
d62a17ae 14384 int direct = 0;
14385 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14386
d62a17ae 14387 int idx = 0;
7336e101
SP
14388 if (argv_find(argv, argc, "ip", &idx)) {
14389 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14390 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14391 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14392 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14393 }
14394
3c4b8fe2 14395 idx = 0;
174b5cb9
DA
14396 argv_find(argv, argc, "permit", &idx);
14397 argv_find(argv, argc, "deny", &idx);
14398
14399 if (idx) {
14400 direct = argv_find(argv, argc, "permit", &idx)
14401 ? COMMUNITY_PERMIT
14402 : COMMUNITY_DENY;
14403
14404 idx = 0;
14405 argv_find(argv, argc, "AA:NN", &idx);
14406 str = argv_concat(argv, argc, idx);
7336e101 14407 }
174b5cb9
DA
14408
14409 idx = 0;
d62a17ae 14410 argv_find(argv, argc, "(100-500)", &idx);
14411 argv_find(argv, argc, "WORD", &idx);
14412 cl_name_or_number = argv[idx]->arg;
42f914d4 14413
d62a17ae 14414 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14415 direct, style);
42f914d4 14416
d62a17ae 14417 XFREE(MTYPE_TMP, str);
daf9ddbb 14418
d62a17ae 14419 if (ret < 0) {
14420 community_list_perror(vty, ret);
14421 return CMD_WARNING_CONFIG_FAILED;
14422 }
42f914d4 14423
d62a17ae 14424 return CMD_SUCCESS;
718e3744 14425}
14426
7336e101
SP
14427ALIAS (no_community_list_expanded_all,
14428 no_ip_community_list_expanded_all_cmd,
14429 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14430 NO_STR
14431 IP_STR
14432 COMMUNITY_LIST_STR
14433 "Community list number (expanded)\n"
14434 "Add an expanded community-list entry\n"
14435 "Community list name\n"
14436 "Specify community to reject\n"
14437 "Specify community to accept\n"
14438 COMMUNITY_VAL_STR)
14439
174b5cb9
DA
14440ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14441 "no bgp community-list <(100-500)|expanded WORD>",
14442 NO_STR IP_STR COMMUNITY_LIST_STR
14443 "Community list number (expanded)\n"
14444 "Add an expanded community-list entry\n"
14445 "Community list name\n")
14446
14447ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14448 "no ip community-list <(100-500)|expanded WORD>",
14449 NO_STR IP_STR COMMUNITY_LIST_STR
14450 "Community list number (expanded)\n"
14451 "Add an expanded community-list entry\n"
14452 "Community list name\n")
14453
8d9b8ed9
PM
14454/* Return configuration string of community-list entry. */
14455static const char *community_list_config_str(struct community_entry *entry)
14456{
14457 const char *str;
14458
14459 if (entry->any)
14460 str = "";
14461 else {
14462 if (entry->style == COMMUNITY_LIST_STANDARD)
14463 str = community_str(entry->u.com, false);
14464 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14465 str = lcommunity_str(entry->u.lcom, false);
14466 else
14467 str = entry->config;
14468 }
14469 return str;
14470}
14471
d62a17ae 14472static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14473{
d62a17ae 14474 struct community_entry *entry;
718e3744 14475
d62a17ae 14476 for (entry = list->head; entry; entry = entry->next) {
14477 if (entry == list->head) {
14478 if (all_digit(list->name))
14479 vty_out(vty, "Community %s list %s\n",
14480 entry->style == COMMUNITY_LIST_STANDARD
14481 ? "standard"
14482 : "(expanded) access",
14483 list->name);
14484 else
14485 vty_out(vty, "Named Community %s list %s\n",
14486 entry->style == COMMUNITY_LIST_STANDARD
14487 ? "standard"
14488 : "expanded",
14489 list->name);
14490 }
14491 if (entry->any)
14492 vty_out(vty, " %s\n",
14493 community_direct_str(entry->direct));
14494 else
14495 vty_out(vty, " %s %s\n",
14496 community_direct_str(entry->direct),
8d9b8ed9 14497 community_list_config_str(entry));
d62a17ae 14498 }
718e3744 14499}
14500
7336e101
SP
14501DEFUN (show_community_list,
14502 show_bgp_community_list_cmd,
14503 "show bgp community-list",
718e3744 14504 SHOW_STR
7336e101 14505 BGP_STR
718e3744 14506 "List community-list\n")
14507{
d62a17ae 14508 struct community_list *list;
14509 struct community_list_master *cm;
718e3744 14510
7336e101
SP
14511 int idx = 0;
14512 if (argv_find(argv, argc, "ip", &idx)) {
14513 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14514 vty_out(vty, "if you are using this please migrate to the below command.\n");
14515 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14516 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14517 }
d62a17ae 14518 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14519 if (!cm)
14520 return CMD_SUCCESS;
718e3744 14521
d62a17ae 14522 for (list = cm->num.head; list; list = list->next)
14523 community_list_show(vty, list);
718e3744 14524
d62a17ae 14525 for (list = cm->str.head; list; list = list->next)
14526 community_list_show(vty, list);
718e3744 14527
d62a17ae 14528 return CMD_SUCCESS;
718e3744 14529}
14530
7336e101
SP
14531ALIAS (show_community_list,
14532 show_ip_community_list_cmd,
14533 "show ip community-list",
718e3744 14534 SHOW_STR
14535 IP_STR
7336e101
SP
14536 "List community-list\n")
14537
14538DEFUN (show_community_list_arg,
14539 show_bgp_community_list_arg_cmd,
14540 "show bgp community-list <(1-500)|WORD>",
14541 SHOW_STR
14542 BGP_STR
718e3744 14543 "List community-list\n"
14544 "Community-list number\n"
14545 "Community-list name\n")
14546{
d62a17ae 14547 int idx_comm_list = 3;
14548 struct community_list *list;
718e3744 14549
7336e101
SP
14550 int idx = 0;
14551 if (argv_find(argv, argc, "ip", &idx)) {
14552 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14553 vty_out(vty, "if you are using this please migrate to the below command.\n");
14554 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14555 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14556 }
e237b0d2 14557 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14558 COMMUNITY_LIST_MASTER);
14559 if (!list) {
14560 vty_out(vty, "%% Can't find community-list\n");
14561 return CMD_WARNING;
14562 }
718e3744 14563
d62a17ae 14564 community_list_show(vty, list);
718e3744 14565
d62a17ae 14566 return CMD_SUCCESS;
718e3744 14567}
6b0655a2 14568
7336e101
SP
14569ALIAS (show_community_list_arg,
14570 show_ip_community_list_arg_cmd,
14571 "show ip community-list <(1-500)|WORD>",
14572 SHOW_STR
14573 IP_STR
14574 "List community-list\n"
14575 "Community-list number\n"
14576 "Community-list name\n")
14577
57d187bc
JS
14578/*
14579 * Large Community code.
14580 */
d62a17ae 14581static int lcommunity_list_set_vty(struct vty *vty, int argc,
14582 struct cmd_token **argv, int style,
14583 int reject_all_digit_name)
14584{
14585 int ret;
14586 int direct;
14587 char *str;
14588 int idx = 0;
14589 char *cl_name;
14590
7336e101
SP
14591 if (argv_find(argv, argc, "ip", &idx)) {
14592 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14593 vty_out(vty, "if you are using this please migrate to the below command.\n");
14594 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14595 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14596 }
d62a17ae 14597 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14598 : COMMUNITY_DENY;
14599
14600 /* All digit name check. */
14601 idx = 0;
14602 argv_find(argv, argc, "WORD", &idx);
14603 argv_find(argv, argc, "(1-99)", &idx);
14604 argv_find(argv, argc, "(100-500)", &idx);
14605 cl_name = argv[idx]->arg;
14606 if (reject_all_digit_name && all_digit(cl_name)) {
14607 vty_out(vty, "%% Community name cannot have all digits\n");
14608 return CMD_WARNING_CONFIG_FAILED;
14609 }
14610
14611 idx = 0;
14612 argv_find(argv, argc, "AA:BB:CC", &idx);
14613 argv_find(argv, argc, "LINE", &idx);
14614 /* Concat community string argument. */
14615 if (idx)
14616 str = argv_concat(argv, argc, idx);
14617 else
14618 str = NULL;
14619
14620 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14621
14622 /* Free temporary community list string allocated by
14623 argv_concat(). */
0a22ddfb 14624 XFREE(MTYPE_TMP, str);
d62a17ae 14625
14626 if (ret < 0) {
14627 community_list_perror(vty, ret);
14628 return CMD_WARNING_CONFIG_FAILED;
14629 }
14630 return CMD_SUCCESS;
14631}
14632
14633static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14634 struct cmd_token **argv, int style)
14635{
14636 int ret;
14637 int direct = 0;
14638 char *str = NULL;
14639 int idx = 0;
14640
7336e101
SP
14641 if (argv_find(argv, argc, "ip", &idx)) {
14642 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14643 vty_out(vty, "if you are using this please migrate to the below command.\n");
14644 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14645 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14646 }
d62a17ae 14647 argv_find(argv, argc, "permit", &idx);
14648 argv_find(argv, argc, "deny", &idx);
14649
14650 if (idx) {
14651 /* Check the list direct. */
14652 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14653 direct = COMMUNITY_PERMIT;
14654 else
14655 direct = COMMUNITY_DENY;
14656
14657 idx = 0;
14658 argv_find(argv, argc, "LINE", &idx);
14659 argv_find(argv, argc, "AA:AA:NN", &idx);
14660 /* Concat community string argument. */
14661 str = argv_concat(argv, argc, idx);
14662 }
14663
14664 idx = 0;
14665 argv_find(argv, argc, "(1-99)", &idx);
14666 argv_find(argv, argc, "(100-500)", &idx);
14667 argv_find(argv, argc, "WORD", &idx);
14668
14669 /* Unset community list. */
14670 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14671 style);
14672
14673 /* Free temporary community list string allocated by
14674 argv_concat(). */
0a22ddfb 14675 XFREE(MTYPE_TMP, str);
d62a17ae 14676
14677 if (ret < 0) {
14678 community_list_perror(vty, ret);
14679 return CMD_WARNING_CONFIG_FAILED;
14680 }
14681
14682 return CMD_SUCCESS;
57d187bc
JS
14683}
14684
14685/* "large-community-list" keyword help string. */
14686#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14687#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14688
7336e101
SP
14689#if CONFDATE > 20191005
14690CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14691#endif
14692DEFUN (lcommunity_list_standard,
14693 bgp_lcommunity_list_standard_cmd,
14694 "bgp large-community-list (1-99) <deny|permit>",
14695 BGP_STR
14696 LCOMMUNITY_LIST_STR
14697 "Large Community list number (standard)\n"
14698 "Specify large community to reject\n"
14699 "Specify large community to accept\n")
14700{
14701 return lcommunity_list_set_vty(vty, argc, argv,
14702 LARGE_COMMUNITY_LIST_STANDARD, 0);
14703}
14704
14705ALIAS (lcommunity_list_standard,
57d187bc 14706 ip_lcommunity_list_standard_cmd,
52951b63
DS
14707 "ip large-community-list (1-99) <deny|permit>",
14708 IP_STR
14709 LCOMMUNITY_LIST_STR
14710 "Large Community list number (standard)\n"
14711 "Specify large community to reject\n"
7111c1a0 14712 "Specify large community to accept\n")
7336e101
SP
14713
14714DEFUN (lcommunity_list_standard1,
14715 bgp_lcommunity_list_standard1_cmd,
14716 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14717 BGP_STR
14718 LCOMMUNITY_LIST_STR
14719 "Large Community list number (standard)\n"
14720 "Specify large community to reject\n"
14721 "Specify large community to accept\n"
14722 LCOMMUNITY_VAL_STR)
52951b63 14723{
d62a17ae 14724 return lcommunity_list_set_vty(vty, argc, argv,
14725 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14726}
14727
7336e101 14728ALIAS (lcommunity_list_standard1,
52951b63
DS
14729 ip_lcommunity_list_standard1_cmd,
14730 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14731 IP_STR
14732 LCOMMUNITY_LIST_STR
14733 "Large Community list number (standard)\n"
14734 "Specify large community to reject\n"
14735 "Specify large community to accept\n"
14736 LCOMMUNITY_VAL_STR)
7336e101
SP
14737
14738DEFUN (lcommunity_list_expanded,
14739 bgp_lcommunity_list_expanded_cmd,
14740 "bgp large-community-list (100-500) <deny|permit> LINE...",
14741 BGP_STR
14742 LCOMMUNITY_LIST_STR
14743 "Large Community list number (expanded)\n"
14744 "Specify large community to reject\n"
14745 "Specify large community to accept\n"
14746 "An ordered list as a regular-expression\n")
57d187bc 14747{
d62a17ae 14748 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14749 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14750}
14751
7336e101 14752ALIAS (lcommunity_list_expanded,
57d187bc
JS
14753 ip_lcommunity_list_expanded_cmd,
14754 "ip large-community-list (100-500) <deny|permit> LINE...",
14755 IP_STR
14756 LCOMMUNITY_LIST_STR
14757 "Large Community list number (expanded)\n"
14758 "Specify large community to reject\n"
14759 "Specify large community to accept\n"
14760 "An ordered list as a regular-expression\n")
7336e101
SP
14761
14762DEFUN (lcommunity_list_name_standard,
14763 bgp_lcommunity_list_name_standard_cmd,
14764 "bgp large-community-list standard WORD <deny|permit>",
14765 BGP_STR
14766 LCOMMUNITY_LIST_STR
14767 "Specify standard large-community-list\n"
14768 "Large Community list name\n"
14769 "Specify large community to reject\n"
14770 "Specify large community to accept\n")
57d187bc 14771{
d62a17ae 14772 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14773 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14774}
14775
7336e101 14776ALIAS (lcommunity_list_name_standard,
57d187bc 14777 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14778 "ip large-community-list standard WORD <deny|permit>",
14779 IP_STR
14780 LCOMMUNITY_LIST_STR
14781 "Specify standard large-community-list\n"
14782 "Large Community list name\n"
14783 "Specify large community to reject\n"
14784 "Specify large community to accept\n")
7336e101
SP
14785
14786DEFUN (lcommunity_list_name_standard1,
14787 bgp_lcommunity_list_name_standard1_cmd,
14788 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14789 BGP_STR
14790 LCOMMUNITY_LIST_STR
14791 "Specify standard large-community-list\n"
14792 "Large Community list name\n"
14793 "Specify large community to reject\n"
14794 "Specify large community to accept\n"
14795 LCOMMUNITY_VAL_STR)
52951b63 14796{
d62a17ae 14797 return lcommunity_list_set_vty(vty, argc, argv,
14798 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14799}
14800
7336e101 14801ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14802 ip_lcommunity_list_name_standard1_cmd,
14803 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14804 IP_STR
14805 LCOMMUNITY_LIST_STR
14806 "Specify standard large-community-list\n"
14807 "Large Community list name\n"
14808 "Specify large community to reject\n"
14809 "Specify large community to accept\n"
14810 LCOMMUNITY_VAL_STR)
7336e101
SP
14811
14812DEFUN (lcommunity_list_name_expanded,
14813 bgp_lcommunity_list_name_expanded_cmd,
14814 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14815 BGP_STR
14816 LCOMMUNITY_LIST_STR
14817 "Specify expanded large-community-list\n"
14818 "Large Community list name\n"
14819 "Specify large community to reject\n"
14820 "Specify large community to accept\n"
14821 "An ordered list as a regular-expression\n")
57d187bc 14822{
d62a17ae 14823 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14824 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14825}
14826
7336e101 14827ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14828 ip_lcommunity_list_name_expanded_cmd,
14829 "ip large-community-list expanded WORD <deny|permit> LINE...",
14830 IP_STR
14831 LCOMMUNITY_LIST_STR
14832 "Specify expanded large-community-list\n"
14833 "Large Community list name\n"
14834 "Specify large community to reject\n"
14835 "Specify large community to accept\n"
14836 "An ordered list as a regular-expression\n")
7336e101
SP
14837
14838DEFUN (no_lcommunity_list_standard_all,
14839 no_bgp_lcommunity_list_standard_all_cmd,
14840 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14841 NO_STR
14842 BGP_STR
14843 LCOMMUNITY_LIST_STR
14844 "Large Community list number (standard)\n"
14845 "Large Community list number (expanded)\n"
14846 "Large Community list name\n")
57d187bc 14847{
7336e101
SP
14848 return lcommunity_list_unset_vty(vty, argc, argv,
14849 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14850}
14851
7336e101 14852ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14853 no_ip_lcommunity_list_standard_all_cmd,
14854 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14855 NO_STR
14856 IP_STR
14857 LCOMMUNITY_LIST_STR
14858 "Large Community list number (standard)\n"
14859 "Large Community list number (expanded)\n"
14860 "Large Community list name\n")
7336e101
SP
14861
14862DEFUN (no_lcommunity_list_name_expanded_all,
14863 no_bgp_lcommunity_list_name_expanded_all_cmd,
14864 "no bgp large-community-list expanded WORD",
14865 NO_STR
14866 BGP_STR
14867 LCOMMUNITY_LIST_STR
14868 "Specify expanded large-community-list\n"
14869 "Large Community list name\n")
57d187bc 14870{
d62a17ae 14871 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14872 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14873}
14874
7336e101 14875ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14876 no_ip_lcommunity_list_name_expanded_all_cmd,
14877 "no ip large-community-list expanded WORD",
14878 NO_STR
14879 IP_STR
14880 LCOMMUNITY_LIST_STR
14881 "Specify expanded large-community-list\n"
14882 "Large Community list name\n")
7336e101
SP
14883
14884DEFUN (no_lcommunity_list_standard,
14885 no_bgp_lcommunity_list_standard_cmd,
14886 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14887 NO_STR
14888 BGP_STR
14889 LCOMMUNITY_LIST_STR
14890 "Large Community list number (standard)\n"
14891 "Specify large community to reject\n"
14892 "Specify large community to accept\n"
14893 LCOMMUNITY_VAL_STR)
57d187bc 14894{
d62a17ae 14895 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14896 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14897}
14898
7336e101 14899ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14900 no_ip_lcommunity_list_standard_cmd,
14901 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14902 NO_STR
14903 IP_STR
14904 LCOMMUNITY_LIST_STR
14905 "Large Community list number (standard)\n"
14906 "Specify large community to reject\n"
14907 "Specify large community to accept\n"
14908 LCOMMUNITY_VAL_STR)
7336e101
SP
14909
14910DEFUN (no_lcommunity_list_expanded,
14911 no_bgp_lcommunity_list_expanded_cmd,
14912 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14913 NO_STR
14914 BGP_STR
14915 LCOMMUNITY_LIST_STR
14916 "Large Community list number (expanded)\n"
14917 "Specify large community to reject\n"
14918 "Specify large community to accept\n"
14919 "An ordered list as a regular-expression\n")
57d187bc 14920{
d62a17ae 14921 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14922 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14923}
14924
7336e101 14925ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14926 no_ip_lcommunity_list_expanded_cmd,
14927 "no ip large-community-list (100-500) <deny|permit> LINE...",
14928 NO_STR
14929 IP_STR
14930 LCOMMUNITY_LIST_STR
14931 "Large Community list number (expanded)\n"
14932 "Specify large community to reject\n"
14933 "Specify large community to accept\n"
14934 "An ordered list as a regular-expression\n")
7336e101
SP
14935
14936DEFUN (no_lcommunity_list_name_standard,
14937 no_bgp_lcommunity_list_name_standard_cmd,
14938 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14939 NO_STR
14940 BGP_STR
14941 LCOMMUNITY_LIST_STR
14942 "Specify standard large-community-list\n"
14943 "Large Community list name\n"
14944 "Specify large community to reject\n"
14945 "Specify large community to accept\n"
14946 LCOMMUNITY_VAL_STR)
57d187bc 14947{
d62a17ae 14948 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14949 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14950}
14951
7336e101 14952ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14953 no_ip_lcommunity_list_name_standard_cmd,
14954 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14955 NO_STR
14956 IP_STR
14957 LCOMMUNITY_LIST_STR
14958 "Specify standard large-community-list\n"
14959 "Large Community list name\n"
14960 "Specify large community to reject\n"
14961 "Specify large community to accept\n"
14962 LCOMMUNITY_VAL_STR)
7336e101
SP
14963
14964DEFUN (no_lcommunity_list_name_expanded,
14965 no_bgp_lcommunity_list_name_expanded_cmd,
14966 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14967 NO_STR
14968 BGP_STR
14969 LCOMMUNITY_LIST_STR
14970 "Specify expanded large-community-list\n"
14971 "Large community list name\n"
14972 "Specify large community to reject\n"
14973 "Specify large community to accept\n"
14974 "An ordered list as a regular-expression\n")
57d187bc 14975{
d62a17ae 14976 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14977 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14978}
14979
7336e101 14980ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14981 no_ip_lcommunity_list_name_expanded_cmd,
14982 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14983 NO_STR
14984 IP_STR
14985 LCOMMUNITY_LIST_STR
14986 "Specify expanded large-community-list\n"
14987 "Large community list name\n"
14988 "Specify large community to reject\n"
14989 "Specify large community to accept\n"
14990 "An ordered list as a regular-expression\n")
d62a17ae 14991
14992static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14993{
14994 struct community_entry *entry;
14995
14996 for (entry = list->head; entry; entry = entry->next) {
14997 if (entry == list->head) {
14998 if (all_digit(list->name))
14999 vty_out(vty, "Large community %s list %s\n",
169b72c8 15000 entry->style ==
15001 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 15002 ? "standard"
15003 : "(expanded) access",
15004 list->name);
15005 else
15006 vty_out(vty,
15007 "Named large community %s list %s\n",
169b72c8 15008 entry->style ==
15009 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 15010 ? "standard"
15011 : "expanded",
15012 list->name);
15013 }
15014 if (entry->any)
15015 vty_out(vty, " %s\n",
15016 community_direct_str(entry->direct));
15017 else
15018 vty_out(vty, " %s %s\n",
15019 community_direct_str(entry->direct),
8d9b8ed9 15020 community_list_config_str(entry));
d62a17ae 15021 }
57d187bc
JS
15022}
15023
7336e101
SP
15024DEFUN (show_lcommunity_list,
15025 show_bgp_lcommunity_list_cmd,
15026 "show bgp large-community-list",
57d187bc 15027 SHOW_STR
7336e101 15028 BGP_STR
57d187bc
JS
15029 "List large-community list\n")
15030{
d62a17ae 15031 struct community_list *list;
15032 struct community_list_master *cm;
7336e101
SP
15033 int idx = 0;
15034
15035 if (argv_find(argv, argc, "ip", &idx)) {
15036 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15037 vty_out(vty, "if you are using this please migrate to the below command.\n");
15038 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15039 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15040 }
57d187bc 15041
d62a17ae 15042 cm = community_list_master_lookup(bgp_clist,
15043 LARGE_COMMUNITY_LIST_MASTER);
15044 if (!cm)
15045 return CMD_SUCCESS;
57d187bc 15046
d62a17ae 15047 for (list = cm->num.head; list; list = list->next)
15048 lcommunity_list_show(vty, list);
57d187bc 15049
d62a17ae 15050 for (list = cm->str.head; list; list = list->next)
15051 lcommunity_list_show(vty, list);
57d187bc 15052
d62a17ae 15053 return CMD_SUCCESS;
57d187bc
JS
15054}
15055
7336e101
SP
15056ALIAS (show_lcommunity_list,
15057 show_ip_lcommunity_list_cmd,
15058 "show ip large-community-list",
57d187bc
JS
15059 SHOW_STR
15060 IP_STR
7336e101
SP
15061 "List large-community list\n")
15062
15063DEFUN (show_lcommunity_list_arg,
15064 show_bgp_lcommunity_list_arg_cmd,
15065 "show bgp large-community-list <(1-500)|WORD>",
15066 SHOW_STR
15067 BGP_STR
57d187bc
JS
15068 "List large-community list\n"
15069 "large-community-list number\n"
15070 "large-community-list name\n")
15071{
d62a17ae 15072 struct community_list *list;
7336e101
SP
15073 int idx = 0;
15074
15075 if (argv_find(argv, argc, "ip", &idx)) {
15076 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15077 vty_out(vty, "if you are using this please migrate to the below command.\n");
15078 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15079 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15080 }
57d187bc 15081
e237b0d2 15082 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 15083 LARGE_COMMUNITY_LIST_MASTER);
15084 if (!list) {
15085 vty_out(vty, "%% Can't find extcommunity-list\n");
15086 return CMD_WARNING;
15087 }
57d187bc 15088
d62a17ae 15089 lcommunity_list_show(vty, list);
57d187bc 15090
d62a17ae 15091 return CMD_SUCCESS;
57d187bc
JS
15092}
15093
7336e101
SP
15094ALIAS (show_lcommunity_list_arg,
15095 show_ip_lcommunity_list_arg_cmd,
15096 "show ip large-community-list <(1-500)|WORD>",
15097 SHOW_STR
15098 IP_STR
15099 "List large-community list\n"
15100 "large-community-list number\n"
15101 "large-community-list name\n")
15102
718e3744 15103/* "extcommunity-list" keyword help string. */
15104#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15105#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15106
7336e101
SP
15107DEFUN (extcommunity_list_standard,
15108 bgp_extcommunity_list_standard_cmd,
15109 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15110 BGP_STR
718e3744 15111 EXTCOMMUNITY_LIST_STR
15112 "Extended Community list number (standard)\n"
718e3744 15113 "Specify standard extcommunity-list\n"
5bf15956 15114 "Community list name\n"
718e3744 15115 "Specify community to reject\n"
15116 "Specify community to accept\n"
15117 EXTCOMMUNITY_VAL_STR)
15118{
d62a17ae 15119 int style = EXTCOMMUNITY_LIST_STANDARD;
15120 int direct = 0;
15121 char *cl_number_or_name = NULL;
42f914d4 15122
d62a17ae 15123 int idx = 0;
7336e101
SP
15124 if (argv_find(argv, argc, "ip", &idx)) {
15125 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15126 vty_out(vty, "if you are using this please migrate to the below command.\n");
15127 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15128 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15129 }
d62a17ae 15130 argv_find(argv, argc, "(1-99)", &idx);
15131 argv_find(argv, argc, "WORD", &idx);
15132 cl_number_or_name = argv[idx]->arg;
15133 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15134 : COMMUNITY_DENY;
15135 argv_find(argv, argc, "AA:NN", &idx);
15136 char *str = argv_concat(argv, argc, idx);
42f914d4 15137
d62a17ae 15138 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15139 direct, style);
42f914d4 15140
d62a17ae 15141 XFREE(MTYPE_TMP, str);
42f914d4 15142
d62a17ae 15143 if (ret < 0) {
15144 community_list_perror(vty, ret);
15145 return CMD_WARNING_CONFIG_FAILED;
15146 }
42f914d4 15147
d62a17ae 15148 return CMD_SUCCESS;
718e3744 15149}
15150
7336e101
SP
15151#if CONFDATE > 20191005
15152CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15153#endif
15154ALIAS (extcommunity_list_standard,
15155 ip_extcommunity_list_standard_cmd,
15156 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15157 IP_STR
15158 EXTCOMMUNITY_LIST_STR
7336e101
SP
15159 "Extended Community list number (standard)\n"
15160 "Specify standard extcommunity-list\n"
15161 "Community list name\n"
15162 "Specify community to reject\n"
15163 "Specify community to accept\n"
15164 EXTCOMMUNITY_VAL_STR)
15165
15166DEFUN (extcommunity_list_name_expanded,
15167 bgp_extcommunity_list_name_expanded_cmd,
15168 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15169 BGP_STR
15170 EXTCOMMUNITY_LIST_STR
5bf15956 15171 "Extended Community list number (expanded)\n"
718e3744 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{
d62a17ae 15178 int style = EXTCOMMUNITY_LIST_EXPANDED;
15179 int direct = 0;
15180 char *cl_number_or_name = NULL;
42f914d4 15181
d62a17ae 15182 int idx = 0;
7336e101
SP
15183 if (argv_find(argv, argc, "ip", &idx)) {
15184 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15185 vty_out(vty, "if you are using this please migrate to the below command.\n");
15186 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15187 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15188 }
15189
d62a17ae 15190 argv_find(argv, argc, "(100-500)", &idx);
15191 argv_find(argv, argc, "WORD", &idx);
15192 cl_number_or_name = argv[idx]->arg;
15193 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15194 : COMMUNITY_DENY;
15195 argv_find(argv, argc, "LINE", &idx);
15196 char *str = argv_concat(argv, argc, idx);
42f914d4 15197
d62a17ae 15198 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15199 direct, style);
42f914d4 15200
d62a17ae 15201 XFREE(MTYPE_TMP, str);
42f914d4 15202
d62a17ae 15203 if (ret < 0) {
15204 community_list_perror(vty, ret);
15205 return CMD_WARNING_CONFIG_FAILED;
15206 }
42f914d4 15207
d62a17ae 15208 return CMD_SUCCESS;
718e3744 15209}
15210
7336e101
SP
15211ALIAS (extcommunity_list_name_expanded,
15212 ip_extcommunity_list_name_expanded_cmd,
15213 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
15214 IP_STR
15215 EXTCOMMUNITY_LIST_STR
7336e101
SP
15216 "Extended Community list number (expanded)\n"
15217 "Specify expanded extcommunity-list\n"
15218 "Extended Community list name\n"
15219 "Specify community to reject\n"
15220 "Specify community to accept\n"
15221 "An ordered list as a regular-expression\n")
15222
15223DEFUN (no_extcommunity_list_standard_all,
15224 no_bgp_extcommunity_list_standard_all_cmd,
15225 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15226 NO_STR
15227 BGP_STR
15228 EXTCOMMUNITY_LIST_STR
813d4307 15229 "Extended Community list number (standard)\n"
718e3744 15230 "Specify standard extcommunity-list\n"
5bf15956 15231 "Community list name\n"
718e3744 15232 "Specify community to reject\n"
15233 "Specify community to accept\n"
15234 EXTCOMMUNITY_VAL_STR)
15235{
d62a17ae 15236 int style = EXTCOMMUNITY_LIST_STANDARD;
15237 int direct = 0;
15238 char *cl_number_or_name = NULL;
d4455c89 15239 char *str = NULL;
42f914d4 15240
d62a17ae 15241 int idx = 0;
7336e101
SP
15242 if (argv_find(argv, argc, "ip", &idx)) {
15243 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15244 vty_out(vty, "if you are using this please migrate to the below command.\n");
15245 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15246 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15247 }
d4455c89
DA
15248
15249 idx = 0;
15250 argv_find(argv, argc, "permit", &idx);
15251 argv_find(argv, argc, "deny", &idx);
15252
15253 if (idx) {
15254 direct = argv_find(argv, argc, "permit", &idx)
15255 ? COMMUNITY_PERMIT
15256 : COMMUNITY_DENY;
15257
15258 idx = 0;
15259 argv_find(argv, argc, "AA:NN", &idx);
15260 str = argv_concat(argv, argc, idx);
15261 }
15262
15263 idx = 0;
d62a17ae 15264 argv_find(argv, argc, "(1-99)", &idx);
15265 argv_find(argv, argc, "WORD", &idx);
15266 cl_number_or_name = argv[idx]->arg;
42f914d4 15267
d62a17ae 15268 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15269 direct, style);
42f914d4 15270
d62a17ae 15271 XFREE(MTYPE_TMP, str);
42f914d4 15272
d62a17ae 15273 if (ret < 0) {
15274 community_list_perror(vty, ret);
15275 return CMD_WARNING_CONFIG_FAILED;
15276 }
42f914d4 15277
d62a17ae 15278 return CMD_SUCCESS;
718e3744 15279}
15280
7336e101
SP
15281ALIAS (no_extcommunity_list_standard_all,
15282 no_ip_extcommunity_list_standard_all_cmd,
15283 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15284 NO_STR
15285 IP_STR
15286 EXTCOMMUNITY_LIST_STR
7336e101
SP
15287 "Extended Community list number (standard)\n"
15288 "Specify standard extcommunity-list\n"
15289 "Community list name\n"
15290 "Specify community to reject\n"
15291 "Specify community to accept\n"
15292 EXTCOMMUNITY_VAL_STR)
15293
d4455c89
DA
15294ALIAS(no_extcommunity_list_standard_all,
15295 no_bgp_extcommunity_list_standard_all_list_cmd,
15296 "no bgp extcommunity-list <(1-99)|standard WORD>",
15297 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15298 "Extended Community list number (standard)\n"
15299 "Specify standard extcommunity-list\n"
15300 "Community list name\n")
15301
15302ALIAS(no_extcommunity_list_standard_all,
15303 no_ip_extcommunity_list_standard_all_list_cmd,
15304 "no ip extcommunity-list <(1-99)|standard WORD>",
15305 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15306 "Extended Community list number (standard)\n"
15307 "Specify standard extcommunity-list\n"
15308 "Community list name\n")
15309
7336e101
SP
15310DEFUN (no_extcommunity_list_expanded_all,
15311 no_bgp_extcommunity_list_expanded_all_cmd,
15312 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15313 NO_STR
15314 BGP_STR
15315 EXTCOMMUNITY_LIST_STR
718e3744 15316 "Extended Community list number (expanded)\n"
718e3744 15317 "Specify expanded extcommunity-list\n"
5bf15956 15318 "Extended Community list name\n"
718e3744 15319 "Specify community to reject\n"
15320 "Specify community to accept\n"
15321 "An ordered list as a regular-expression\n")
15322{
d62a17ae 15323 int style = EXTCOMMUNITY_LIST_EXPANDED;
15324 int direct = 0;
15325 char *cl_number_or_name = NULL;
d4455c89 15326 char *str = NULL;
42f914d4 15327
d62a17ae 15328 int idx = 0;
7336e101
SP
15329 if (argv_find(argv, argc, "ip", &idx)) {
15330 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15331 vty_out(vty, "if you are using this please migrate to the below command.\n");
15332 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15333 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15334 }
d4455c89
DA
15335
15336 idx = 0;
15337 argv_find(argv, argc, "permit", &idx);
15338 argv_find(argv, argc, "deny", &idx);
15339
15340 if (idx) {
15341 direct = argv_find(argv, argc, "permit", &idx)
15342 ? COMMUNITY_PERMIT
15343 : COMMUNITY_DENY;
15344
15345 idx = 0;
15346 argv_find(argv, argc, "LINE", &idx);
15347 str = argv_concat(argv, argc, idx);
15348 }
15349
15350 idx = 0;
d62a17ae 15351 argv_find(argv, argc, "(100-500)", &idx);
15352 argv_find(argv, argc, "WORD", &idx);
15353 cl_number_or_name = argv[idx]->arg;
42f914d4 15354
d62a17ae 15355 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15356 direct, style);
42f914d4 15357
d62a17ae 15358 XFREE(MTYPE_TMP, str);
42f914d4 15359
d62a17ae 15360 if (ret < 0) {
15361 community_list_perror(vty, ret);
15362 return CMD_WARNING_CONFIG_FAILED;
15363 }
42f914d4 15364
d62a17ae 15365 return CMD_SUCCESS;
718e3744 15366}
15367
7336e101
SP
15368ALIAS (no_extcommunity_list_expanded_all,
15369 no_ip_extcommunity_list_expanded_all_cmd,
15370 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15371 NO_STR
15372 IP_STR
15373 EXTCOMMUNITY_LIST_STR
15374 "Extended Community list number (expanded)\n"
15375 "Specify expanded extcommunity-list\n"
15376 "Extended Community list name\n"
15377 "Specify community to reject\n"
15378 "Specify community to accept\n"
15379 "An ordered list as a regular-expression\n")
15380
d4455c89
DA
15381ALIAS(no_extcommunity_list_expanded_all,
15382 no_ip_extcommunity_list_expanded_all_list_cmd,
15383 "no ip extcommunity-list <(100-500)|expanded WORD>",
15384 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15385 "Extended Community list number (expanded)\n"
15386 "Specify expanded extcommunity-list\n"
15387 "Extended Community list name\n")
15388
15389ALIAS(no_extcommunity_list_expanded_all,
15390 no_bgp_extcommunity_list_expanded_all_list_cmd,
15391 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15392 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15393 "Extended Community list number (expanded)\n"
15394 "Specify expanded extcommunity-list\n"
15395 "Extended Community list name\n")
15396
d62a17ae 15397static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15398{
d62a17ae 15399 struct community_entry *entry;
718e3744 15400
d62a17ae 15401 for (entry = list->head; entry; entry = entry->next) {
15402 if (entry == list->head) {
15403 if (all_digit(list->name))
15404 vty_out(vty, "Extended community %s list %s\n",
15405 entry->style == EXTCOMMUNITY_LIST_STANDARD
15406 ? "standard"
15407 : "(expanded) access",
15408 list->name);
15409 else
15410 vty_out(vty,
15411 "Named extended community %s list %s\n",
15412 entry->style == EXTCOMMUNITY_LIST_STANDARD
15413 ? "standard"
15414 : "expanded",
15415 list->name);
15416 }
15417 if (entry->any)
15418 vty_out(vty, " %s\n",
15419 community_direct_str(entry->direct));
15420 else
15421 vty_out(vty, " %s %s\n",
15422 community_direct_str(entry->direct),
8d9b8ed9 15423 community_list_config_str(entry));
d62a17ae 15424 }
718e3744 15425}
15426
7336e101
SP
15427DEFUN (show_extcommunity_list,
15428 show_bgp_extcommunity_list_cmd,
15429 "show bgp extcommunity-list",
718e3744 15430 SHOW_STR
7336e101 15431 BGP_STR
718e3744 15432 "List extended-community list\n")
15433{
d62a17ae 15434 struct community_list *list;
15435 struct community_list_master *cm;
7336e101 15436 int idx = 0;
718e3744 15437
7336e101
SP
15438 if (argv_find(argv, argc, "ip", &idx)) {
15439 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15440 vty_out(vty, "if you are using this please migrate to the below command.\n");
15441 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15442 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15443 }
d62a17ae 15444 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15445 if (!cm)
15446 return CMD_SUCCESS;
718e3744 15447
d62a17ae 15448 for (list = cm->num.head; list; list = list->next)
15449 extcommunity_list_show(vty, list);
718e3744 15450
d62a17ae 15451 for (list = cm->str.head; list; list = list->next)
15452 extcommunity_list_show(vty, list);
718e3744 15453
d62a17ae 15454 return CMD_SUCCESS;
718e3744 15455}
15456
7336e101
SP
15457ALIAS (show_extcommunity_list,
15458 show_ip_extcommunity_list_cmd,
15459 "show ip extcommunity-list",
718e3744 15460 SHOW_STR
15461 IP_STR
7336e101
SP
15462 "List extended-community list\n")
15463
15464DEFUN (show_extcommunity_list_arg,
15465 show_bgp_extcommunity_list_arg_cmd,
15466 "show bgp extcommunity-list <(1-500)|WORD>",
15467 SHOW_STR
15468 BGP_STR
718e3744 15469 "List extended-community list\n"
15470 "Extcommunity-list number\n"
15471 "Extcommunity-list name\n")
15472{
d62a17ae 15473 int idx_comm_list = 3;
15474 struct community_list *list;
7336e101 15475 int idx = 0;
718e3744 15476
7336e101
SP
15477 if (argv_find(argv, argc, "ip", &idx)) {
15478 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15479 vty_out(vty, "if you are using this please migrate to the below command.\n");
15480 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15481 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15482 }
e237b0d2 15483 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15484 EXTCOMMUNITY_LIST_MASTER);
15485 if (!list) {
15486 vty_out(vty, "%% Can't find extcommunity-list\n");
15487 return CMD_WARNING;
15488 }
718e3744 15489
d62a17ae 15490 extcommunity_list_show(vty, list);
718e3744 15491
d62a17ae 15492 return CMD_SUCCESS;
718e3744 15493}
6b0655a2 15494
7336e101
SP
15495ALIAS (show_extcommunity_list_arg,
15496 show_ip_extcommunity_list_arg_cmd,
15497 "show ip extcommunity-list <(1-500)|WORD>",
15498 SHOW_STR
15499 IP_STR
15500 "List extended-community list\n"
15501 "Extcommunity-list number\n"
15502 "Extcommunity-list name\n")
15503
718e3744 15504/* Display community-list and extcommunity-list configuration. */
d62a17ae 15505static int community_list_config_write(struct vty *vty)
15506{
15507 struct community_list *list;
15508 struct community_entry *entry;
15509 struct community_list_master *cm;
15510 int write = 0;
15511
15512 /* Community-list. */
15513 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15514
15515 for (list = cm->num.head; list; list = list->next)
15516 for (entry = list->head; entry; entry = entry->next) {
7336e101 15517 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15518 community_direct_str(entry->direct),
15519 community_list_config_str(entry));
15520 write++;
15521 }
15522 for (list = cm->str.head; list; list = list->next)
15523 for (entry = list->head; entry; entry = entry->next) {
7336e101 15524 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15525 entry->style == COMMUNITY_LIST_STANDARD
15526 ? "standard"
15527 : "expanded",
15528 list->name, community_direct_str(entry->direct),
15529 community_list_config_str(entry));
15530 write++;
15531 }
15532
15533 /* Extcommunity-list. */
15534 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15535
15536 for (list = cm->num.head; list; list = list->next)
15537 for (entry = list->head; entry; entry = entry->next) {
7336e101 15538 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15539 list->name, community_direct_str(entry->direct),
15540 community_list_config_str(entry));
15541 write++;
15542 }
15543 for (list = cm->str.head; list; list = list->next)
15544 for (entry = list->head; entry; entry = entry->next) {
7336e101 15545 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15546 entry->style == EXTCOMMUNITY_LIST_STANDARD
15547 ? "standard"
15548 : "expanded",
15549 list->name, community_direct_str(entry->direct),
15550 community_list_config_str(entry));
15551 write++;
15552 }
15553
15554
15555 /* lcommunity-list. */
15556 cm = community_list_master_lookup(bgp_clist,
15557 LARGE_COMMUNITY_LIST_MASTER);
15558
15559 for (list = cm->num.head; list; list = list->next)
15560 for (entry = list->head; entry; entry = entry->next) {
7336e101 15561 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15562 list->name, community_direct_str(entry->direct),
15563 community_list_config_str(entry));
15564 write++;
15565 }
15566 for (list = cm->str.head; list; list = list->next)
15567 for (entry = list->head; entry; entry = entry->next) {
7336e101 15568 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15569 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15570 ? "standard"
15571 : "expanded",
15572 list->name, community_direct_str(entry->direct),
15573 community_list_config_str(entry));
15574 write++;
15575 }
15576
15577 return write;
15578}
15579
15580static struct cmd_node community_list_node = {
15581 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15582};
15583
d62a17ae 15584static void community_list_vty(void)
15585{
15586 install_node(&community_list_node, community_list_config_write);
15587
15588 /* Community-list. */
7336e101
SP
15589 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15590 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15591 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15592 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15593 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15594 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15595 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15596 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15597 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15598 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15599 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15600 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15601 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15602 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15603 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15604 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15605
15606 /* Extcommunity-list. */
7336e101
SP
15607 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15608 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15609 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15610 install_element(CONFIG_NODE,
15611 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15612 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15613 install_element(CONFIG_NODE,
15614 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15615 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15616 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15617 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15618 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15619 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15620 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15621 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15622 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15623 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15624 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15625
15626 /* Large Community List */
7336e101
SP
15627 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15628 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15629 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15630 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15631 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15632 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15633 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15634 install_element(CONFIG_NODE,
15635 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15636 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15637 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15638 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15639 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15640 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15641 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15642 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15643 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15644 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15645 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15646 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15647 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15648 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15649 install_element(CONFIG_NODE,
15650 &no_ip_lcommunity_list_name_expanded_all_cmd);
15651 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15652 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15653 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15654 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15655 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15656 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15657}