]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: resolve memleak on show bgp vrf all ipv6 unicast summary json
[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;
b26f891d 122 case AFI_UNSPEC:
d62a17ae 123 case AFI_MAX:
124 // We should never be here but to clarify the switch statement..
125 return BGP_IPV4_NODE;
126 break;
127 }
128
129 // Impossible to happen
130 return BGP_IPV4_NODE;
f51bae9c 131}
20eb8864 132
718e3744 133/* Utility function to get address family from current node. */
d62a17ae 134afi_t bgp_node_afi(struct vty *vty)
135{
136 afi_t afi;
137 switch (vty->node) {
138 case BGP_IPV6_NODE:
139 case BGP_IPV6M_NODE:
140 case BGP_IPV6L_NODE:
141 case BGP_VPNV6_NODE:
7c40bf39 142 case BGP_FLOWSPECV6_NODE:
d62a17ae 143 afi = AFI_IP6;
144 break;
145 case BGP_EVPN_NODE:
146 afi = AFI_L2VPN;
147 break;
148 default:
149 afi = AFI_IP;
150 break;
151 }
152 return afi;
718e3744 153}
154
155/* Utility function to get subsequent address family from current
156 node. */
d62a17ae 157safi_t bgp_node_safi(struct vty *vty)
158{
159 safi_t safi;
160 switch (vty->node) {
161 case BGP_VPNV4_NODE:
162 case BGP_VPNV6_NODE:
163 safi = SAFI_MPLS_VPN;
164 break;
165 case BGP_IPV4M_NODE:
166 case BGP_IPV6M_NODE:
167 safi = SAFI_MULTICAST;
168 break;
169 case BGP_EVPN_NODE:
170 safi = SAFI_EVPN;
171 break;
172 case BGP_IPV4L_NODE:
173 case BGP_IPV6L_NODE:
174 safi = SAFI_LABELED_UNICAST;
175 break;
7c40bf39 176 case BGP_FLOWSPECV4_NODE:
177 case BGP_FLOWSPECV6_NODE:
178 safi = SAFI_FLOWSPEC;
179 break;
d62a17ae 180 default:
181 safi = SAFI_UNICAST;
182 break;
183 }
184 return safi;
718e3744 185}
186
55f91488
QY
187/**
188 * Converts an AFI in string form to afi_t
189 *
190 * @param afi string, one of
191 * - "ipv4"
192 * - "ipv6"
81cf0de5 193 * - "l2vpn"
55f91488
QY
194 * @return the corresponding afi_t
195 */
d62a17ae 196afi_t bgp_vty_afi_from_str(const char *afi_str)
197{
198 afi_t afi = AFI_MAX; /* unknown */
199 if (strmatch(afi_str, "ipv4"))
200 afi = AFI_IP;
201 else if (strmatch(afi_str, "ipv6"))
202 afi = AFI_IP6;
81cf0de5
CS
203 else if (strmatch(afi_str, "l2vpn"))
204 afi = AFI_L2VPN;
d62a17ae 205 return afi;
206}
207
208int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
209 afi_t *afi)
210{
211 int ret = 0;
212 if (argv_find(argv, argc, "ipv4", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP;
216 } else if (argv_find(argv, argc, "ipv6", index)) {
217 ret = 1;
218 if (afi)
219 *afi = AFI_IP6;
8688b3e7
DS
220 } else if (argv_find(argv, argc, "l2vpn", index)) {
221 ret = 1;
222 if (afi)
223 *afi = AFI_L2VPN;
d62a17ae 224 }
225 return ret;
46f296b4
LB
226}
227
375a2e67 228/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 229safi_t bgp_vty_safi_from_str(const char *safi_str)
230{
231 safi_t safi = SAFI_MAX; /* unknown */
232 if (strmatch(safi_str, "multicast"))
233 safi = SAFI_MULTICAST;
234 else if (strmatch(safi_str, "unicast"))
235 safi = SAFI_UNICAST;
236 else if (strmatch(safi_str, "vpn"))
237 safi = SAFI_MPLS_VPN;
81cf0de5
CS
238 else if (strmatch(safi_str, "evpn"))
239 safi = SAFI_EVPN;
d62a17ae 240 else if (strmatch(safi_str, "labeled-unicast"))
241 safi = SAFI_LABELED_UNICAST;
7c40bf39 242 else if (strmatch(safi_str, "flowspec"))
243 safi = SAFI_FLOWSPEC;
d62a17ae 244 return safi;
245}
246
247int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
248 safi_t *safi)
249{
250 int ret = 0;
251 if (argv_find(argv, argc, "unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_UNICAST;
255 } else if (argv_find(argv, argc, "multicast", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MULTICAST;
259 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_LABELED_UNICAST;
263 } else if (argv_find(argv, argc, "vpn", index)) {
264 ret = 1;
265 if (safi)
266 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
267 } else if (argv_find(argv, argc, "evpn", index)) {
268 ret = 1;
269 if (safi)
270 *safi = SAFI_EVPN;
7c40bf39 271 } else if (argv_find(argv, argc, "flowspec", index)) {
272 ret = 1;
273 if (safi)
274 *safi = SAFI_FLOWSPEC;
d62a17ae 275 }
276 return ret;
46f296b4
LB
277}
278
7eeee51e 279/*
f212a857 280 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 281 *
f212a857
DS
282 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
283 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
284 * to appropriate values for the calling function. This is to allow the
285 * calling function to make decisions appropriate for the show command
286 * that is being parsed.
287 *
288 * The show commands are generally of the form:
d62a17ae 289 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
290 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
291 *
292 * Since we use argv_find if the show command in particular doesn't have:
293 * [ip]
18c57037 294 * [<view|vrf> VIEWVRFNAME]
375a2e67 295 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
296 * The command parsing should still be ok.
297 *
298 * vty -> The vty for the command so we can output some useful data in
299 * the event of a parse error in the vrf.
300 * argv -> The command tokens
301 * argc -> How many command tokens we have
d62a17ae 302 * idx -> The current place in the command, generally should be 0 for this
303 * function
7eeee51e
DS
304 * afi -> The parsed afi if it was included in the show command, returned here
305 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 306 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 307 * use_json -> json is configured or not
7eeee51e
DS
308 *
309 * The function returns the correct location in the parse tree for the
310 * last token found.
0e37c258
DS
311 *
312 * Returns 0 for failure to parse correctly, else the idx position of where
313 * it found the last token.
7eeee51e 314 */
d62a17ae 315int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
316 struct cmd_token **argv, int argc,
317 int *idx, afi_t *afi, safi_t *safi,
9f049418 318 struct bgp **bgp, bool use_json)
d62a17ae 319{
320 char *vrf_name = NULL;
321
322 assert(afi);
323 assert(safi);
324 assert(bgp);
325
326 if (argv_find(argv, argc, "ip", idx))
327 *afi = AFI_IP;
328
9a8bdf1c 329 if (argv_find(argv, argc, "view", idx))
d62a17ae 330 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
331 else if (argv_find(argv, argc, "vrf", idx)) {
332 vrf_name = argv[*idx + 1]->arg;
333 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
334 vrf_name = NULL;
335 }
336 if (vrf_name) {
d62a17ae 337 if (strmatch(vrf_name, "all"))
338 *bgp = NULL;
339 else {
340 *bgp = bgp_lookup_by_name(vrf_name);
341 if (!*bgp) {
52e5b8c4
SP
342 if (use_json) {
343 json_object *json = NULL;
344 json = json_object_new_object();
345 json_object_string_add(
346 json, "warning",
347 "View/Vrf is unknown");
348 vty_out(vty, "%s\n",
349 json_object_to_json_string_ext(json,
350 JSON_C_TO_STRING_PRETTY));
351 json_object_free(json);
352 }
ca61fd25
DS
353 else
354 vty_out(vty, "View/Vrf %s is unknown\n",
355 vrf_name);
d62a17ae 356 *idx = 0;
357 return 0;
358 }
359 }
360 } else {
361 *bgp = bgp_get_default();
362 if (!*bgp) {
52e5b8c4
SP
363 if (use_json) {
364 json_object *json = NULL;
365 json = json_object_new_object();
366 json_object_string_add(
367 json, "warning",
368 "Default BGP instance not found");
369 vty_out(vty, "%s\n",
370 json_object_to_json_string_ext(json,
371 JSON_C_TO_STRING_PRETTY));
372 json_object_free(json);
373 }
ca61fd25
DS
374 else
375 vty_out(vty,
376 "Default BGP instance not found\n");
d62a17ae 377 *idx = 0;
378 return 0;
379 }
380 }
381
382 if (argv_find_and_parse_afi(argv, argc, idx, afi))
383 argv_find_and_parse_safi(argv, argc, idx, safi);
384
385 *idx += 1;
386 return *idx;
387}
388
389static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
390{
391 struct interface *ifp = NULL;
392
393 if (su->sa.sa_family == AF_INET)
394 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
395 else if (su->sa.sa_family == AF_INET6)
396 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
397 su->sin6.sin6_scope_id,
398 bgp->vrf_id);
399
400 if (ifp)
401 return 1;
402
403 return 0;
718e3744 404}
405
406/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
407/* This is used only for configuration, so disallow if attempted on
408 * a dynamic neighbor.
409 */
d62a17ae 410static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
411{
412 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
413 int ret;
414 union sockunion su;
415 struct peer *peer;
416
417 if (!bgp) {
418 return NULL;
419 }
420
421 ret = str2sockunion(ip_str, &su);
422 if (ret < 0) {
423 peer = peer_lookup_by_conf_if(bgp, ip_str);
424 if (!peer) {
425 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
426 == NULL) {
427 vty_out(vty,
428 "%% Malformed address or name: %s\n",
429 ip_str);
430 return NULL;
431 }
432 }
433 } else {
434 peer = peer_lookup(bgp, &su);
435 if (!peer) {
436 vty_out(vty,
437 "%% Specify remote-as or peer-group commands first\n");
438 return NULL;
439 }
440 if (peer_dynamic_neighbor(peer)) {
441 vty_out(vty,
442 "%% Operation not allowed on a dynamic neighbor\n");
443 return NULL;
444 }
445 }
446 return peer;
718e3744 447}
448
449/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
450/* This is used only for configuration, so disallow if attempted on
451 * a dynamic neighbor.
452 */
d62a17ae 453struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
454{
455 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
456 int ret;
457 union sockunion su;
458 struct peer *peer = NULL;
459 struct peer_group *group = NULL;
460
461 if (!bgp) {
462 return NULL;
463 }
464
465 ret = str2sockunion(peer_str, &su);
466 if (ret == 0) {
467 /* IP address, locate peer. */
468 peer = peer_lookup(bgp, &su);
469 } else {
470 /* Not IP, could match either peer configured on interface or a
471 * group. */
472 peer = peer_lookup_by_conf_if(bgp, peer_str);
473 if (!peer)
474 group = peer_group_lookup(bgp, peer_str);
475 }
476
477 if (peer) {
478 if (peer_dynamic_neighbor(peer)) {
479 vty_out(vty,
480 "%% Operation not allowed on a dynamic neighbor\n");
481 return NULL;
482 }
483
484 return peer;
485 }
486
487 if (group)
488 return group->conf;
489
490 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
491
492 return NULL;
493}
494
495int bgp_vty_return(struct vty *vty, int ret)
496{
497 const char *str = NULL;
498
499 switch (ret) {
500 case BGP_ERR_INVALID_VALUE:
501 str = "Invalid value";
502 break;
503 case BGP_ERR_INVALID_FLAG:
504 str = "Invalid flag";
505 break;
506 case BGP_ERR_PEER_GROUP_SHUTDOWN:
507 str = "Peer-group has been shutdown. Activate the peer-group first";
508 break;
509 case BGP_ERR_PEER_FLAG_CONFLICT:
510 str = "Can't set override-capability and strict-capability-match at the same time";
511 break;
512 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
513 str = "Specify remote-as or peer-group remote AS first";
514 break;
515 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
516 str = "Cannot change the peer-group. Deconfigure first";
517 break;
518 case BGP_ERR_PEER_GROUP_MISMATCH:
519 str = "Peer is not a member of this peer-group";
520 break;
521 case BGP_ERR_PEER_FILTER_CONFLICT:
522 str = "Prefix/distribute list can not co-exist";
523 break;
524 case BGP_ERR_NOT_INTERNAL_PEER:
525 str = "Invalid command. Not an internal neighbor";
526 break;
527 case BGP_ERR_REMOVE_PRIVATE_AS:
528 str = "remove-private-AS cannot be configured for IBGP peers";
529 break;
530 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
531 str = "Local-AS allowed only for EBGP peers";
532 break;
533 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
534 str = "Cannot have local-as same as BGP AS number";
535 break;
536 case BGP_ERR_TCPSIG_FAILED:
537 str = "Error while applying TCP-Sig to session(s)";
538 break;
539 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
540 str = "ebgp-multihop and ttl-security cannot be configured together";
541 break;
542 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
543 str = "ttl-security only allowed for EBGP peers";
544 break;
545 case BGP_ERR_AS_OVERRIDE:
546 str = "as-override cannot be configured for IBGP peers";
547 break;
548 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
549 str = "Invalid limit for number of dynamic neighbors";
550 break;
551 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
552 str = "Dynamic neighbor listen range already exists";
553 break;
554 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
555 str = "Operation not allowed on a dynamic neighbor";
556 break;
557 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
558 str = "Operation not allowed on a directly connected neighbor";
559 break;
560 case BGP_ERR_PEER_SAFI_CONFLICT:
561 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
562 break;
563 }
564 if (str) {
565 vty_out(vty, "%% %s\n", str);
566 return CMD_WARNING_CONFIG_FAILED;
567 }
568 return CMD_SUCCESS;
718e3744 569}
570
7aafcaca 571/* BGP clear sort. */
d62a17ae 572enum clear_sort {
573 clear_all,
574 clear_peer,
575 clear_group,
576 clear_external,
577 clear_as
7aafcaca
DS
578};
579
d62a17ae 580static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
581 safi_t safi, int error)
582{
583 switch (error) {
584 case BGP_ERR_AF_UNCONFIGURED:
585 vty_out(vty,
586 "%%BGP: Enable %s address family for the neighbor %s\n",
587 afi_safi_print(afi, safi), peer->host);
588 break;
589 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
590 vty_out(vty,
591 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
592 peer->host);
593 break;
594 default:
595 break;
596 }
7aafcaca
DS
597}
598
599/* `clear ip bgp' functions. */
d62a17ae 600static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
601 enum clear_sort sort, enum bgp_clear_type stype,
602 const char *arg)
603{
604 int ret;
3ae8bfa5 605 bool found = false;
d62a17ae 606 struct peer *peer;
607 struct listnode *node, *nnode;
608
609 /* Clear all neighbors. */
610 /*
611 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
612 * nodes on the BGP instance as that may get freed if it is a
613 * doppelganger
d62a17ae 614 */
615 if (sort == clear_all) {
616 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
3ae8bfa5
PM
617 if (!peer->afc[afi][safi])
618 continue;
619
d62a17ae 620 if (stype == BGP_CLEAR_SOFT_NONE)
621 ret = peer_clear(peer, &nnode);
d62a17ae 622 else
3ae8bfa5 623 ret = peer_clear_soft(peer, afi, safi, stype);
d62a17ae 624
625 if (ret < 0)
626 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 627 }
d62a17ae 628
629 /* This is to apply read-only mode on this clear. */
630 if (stype == BGP_CLEAR_SOFT_NONE)
631 bgp->update_delay_over = 0;
632
633 return CMD_SUCCESS;
7aafcaca
DS
634 }
635
3ae8bfa5 636 /* Clear specified neighbor. */
d62a17ae 637 if (sort == clear_peer) {
638 union sockunion su;
d62a17ae 639
640 /* Make sockunion for lookup. */
641 ret = str2sockunion(arg, &su);
642 if (ret < 0) {
643 peer = peer_lookup_by_conf_if(bgp, arg);
644 if (!peer) {
645 peer = peer_lookup_by_hostname(bgp, arg);
646 if (!peer) {
647 vty_out(vty,
648 "Malformed address or name: %s\n",
649 arg);
650 return CMD_WARNING;
651 }
652 }
653 } else {
654 peer = peer_lookup(bgp, &su);
655 if (!peer) {
656 vty_out(vty,
657 "%%BGP: Unknown neighbor - \"%s\"\n",
658 arg);
659 return CMD_WARNING;
660 }
661 }
7aafcaca 662
3ae8bfa5
PM
663 if (!peer->afc[afi][safi])
664 ret = BGP_ERR_AF_UNCONFIGURED;
665 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 666 ret = peer_clear(peer, NULL);
667 else
668 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 669
d62a17ae 670 if (ret < 0)
671 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 672
d62a17ae 673 return CMD_SUCCESS;
7aafcaca 674 }
7aafcaca 675
3ae8bfa5 676 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 677 if (sort == clear_group) {
678 struct peer_group *group;
7aafcaca 679
d62a17ae 680 group = peer_group_lookup(bgp, arg);
681 if (!group) {
682 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
683 return CMD_WARNING;
684 }
685
686 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
d62a17ae 687 if (!peer->afc[afi][safi])
688 continue;
689
3ae8bfa5
PM
690 if (stype == BGP_CLEAR_SOFT_NONE)
691 ret = peer_clear(peer, NULL);
692 else
693 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 694
d62a17ae 695 if (ret < 0)
696 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
697 else
698 found = true;
d62a17ae 699 }
3ae8bfa5
PM
700
701 if (!found)
702 vty_out(vty,
703 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
704 afi_safi_print(afi, safi), arg);
705
d62a17ae 706 return CMD_SUCCESS;
7aafcaca 707 }
7aafcaca 708
3ae8bfa5 709 /* Clear all external (eBGP) neighbors. */
d62a17ae 710 if (sort == clear_external) {
711 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
712 if (peer->sort == BGP_PEER_IBGP)
713 continue;
7aafcaca 714
3ae8bfa5
PM
715 if (!peer->afc[afi][safi])
716 continue;
717
d62a17ae 718 if (stype == BGP_CLEAR_SOFT_NONE)
719 ret = peer_clear(peer, &nnode);
720 else
721 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 722
d62a17ae 723 if (ret < 0)
724 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
725 else
726 found = true;
d62a17ae 727 }
3ae8bfa5
PM
728
729 if (!found)
730 vty_out(vty,
731 "%%BGP: No external %s peer is configured\n",
732 afi_safi_print(afi, safi));
733
d62a17ae 734 return CMD_SUCCESS;
735 }
736
3ae8bfa5 737 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 738 if (sort == clear_as) {
3ae8bfa5 739 as_t as = strtoul(arg, NULL, 10);
d62a17ae 740
741 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
742 if (peer->as != as)
743 continue;
744
3ae8bfa5
PM
745 if (!peer->afc[afi][safi])
746 ret = BGP_ERR_AF_UNCONFIGURED;
747 else if (stype == BGP_CLEAR_SOFT_NONE)
d62a17ae 748 ret = peer_clear(peer, &nnode);
749 else
750 ret = peer_clear_soft(peer, afi, safi, stype);
751
752 if (ret < 0)
753 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
754 else
755 found = true;
d62a17ae 756 }
3ae8bfa5
PM
757
758 if (!found)
d62a17ae 759 vty_out(vty,
3ae8bfa5
PM
760 "%%BGP: No %s peer is configured with AS %s\n",
761 afi_safi_print(afi, safi), arg);
762
d62a17ae 763 return CMD_SUCCESS;
764 }
765
766 return CMD_SUCCESS;
767}
768
769static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
770 safi_t safi, enum clear_sort sort,
771 enum bgp_clear_type stype, const char *arg)
772{
773 struct bgp *bgp;
774
775 /* BGP structure lookup. */
776 if (name) {
777 bgp = bgp_lookup_by_name(name);
778 if (bgp == NULL) {
779 vty_out(vty, "Can't find BGP instance %s\n", name);
780 return CMD_WARNING;
781 }
782 } else {
783 bgp = bgp_get_default();
784 if (bgp == NULL) {
785 vty_out(vty, "No BGP process is configured\n");
786 return CMD_WARNING;
787 }
788 }
789
790 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
791}
792
793/* clear soft inbound */
d62a17ae 794static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 795{
99b3ebd3
NS
796 afi_t afi;
797 safi_t safi;
798
799 FOREACH_AFI_SAFI (afi, safi)
800 bgp_clear_vty(vty, name, afi, safi, clear_all,
801 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
802}
803
804/* clear soft outbound */
d62a17ae 805static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 806{
99b3ebd3
NS
807 afi_t afi;
808 safi_t safi;
809
810 FOREACH_AFI_SAFI (afi, safi)
811 bgp_clear_vty(vty, name, afi, safi, clear_all,
812 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
813}
814
815
f787d7a0 816#ifndef VTYSH_EXTRACT_PL
2e4c2296 817#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
818#endif
819
8029b216
AK
820DEFUN_HIDDEN (bgp_local_mac,
821 bgp_local_mac_cmd,
093e3f23 822 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
823 BGP_STR
824 "Local MAC config\n"
825 "VxLAN Network Identifier\n"
826 "VNI number\n"
827 "local mac\n"
828 "mac address\n"
829 "mac-mobility sequence\n"
830 "seq number\n")
831{
832 int rv;
833 vni_t vni;
834 struct ethaddr mac;
835 struct ipaddr ip;
836 uint32_t seq;
837 struct bgp *bgp;
838
839 vni = strtoul(argv[3]->arg, NULL, 10);
840 if (!prefix_str2mac(argv[5]->arg, &mac)) {
841 vty_out(vty, "%% Malformed MAC address\n");
842 return CMD_WARNING;
843 }
844 memset(&ip, 0, sizeof(ip));
845 seq = strtoul(argv[7]->arg, NULL, 10);
846
847 bgp = bgp_get_default();
848 if (!bgp) {
849 vty_out(vty, "Default BGP instance is not there\n");
850 return CMD_WARNING;
851 }
852
853 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
854 if (rv < 0) {
855 vty_out(vty, "Internal error\n");
856 return CMD_WARNING;
857 }
858
859 return CMD_SUCCESS;
860}
861
862DEFUN_HIDDEN (no_bgp_local_mac,
863 no_bgp_local_mac_cmd,
093e3f23 864 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
865 NO_STR
866 BGP_STR
867 "Local MAC config\n"
868 "VxLAN Network Identifier\n"
869 "VNI number\n"
870 "local mac\n"
871 "mac address\n")
872{
873 int rv;
874 vni_t vni;
875 struct ethaddr mac;
876 struct ipaddr ip;
877 struct bgp *bgp;
878
879 vni = strtoul(argv[4]->arg, NULL, 10);
880 if (!prefix_str2mac(argv[6]->arg, &mac)) {
881 vty_out(vty, "%% Malformed MAC address\n");
882 return CMD_WARNING;
883 }
884 memset(&ip, 0, sizeof(ip));
885
886 bgp = bgp_get_default();
887 if (!bgp) {
888 vty_out(vty, "Default BGP instance is not there\n");
889 return CMD_WARNING;
890 }
891
ec0ab544 892 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
893 if (rv < 0) {
894 vty_out(vty, "Internal error\n");
895 return CMD_WARNING;
896 }
897
898 return CMD_SUCCESS;
899}
900
718e3744 901DEFUN (no_synchronization,
902 no_synchronization_cmd,
903 "no synchronization",
904 NO_STR
905 "Perform IGP synchronization\n")
906{
d62a17ae 907 return CMD_SUCCESS;
718e3744 908}
909
910DEFUN (no_auto_summary,
911 no_auto_summary_cmd,
912 "no auto-summary",
913 NO_STR
914 "Enable automatic network number summarization\n")
915{
d62a17ae 916 return CMD_SUCCESS;
718e3744 917}
3d515fd9 918
718e3744 919/* "router bgp" commands. */
505e5056 920DEFUN_NOSH (router_bgp,
f412b39a 921 router_bgp_cmd,
2ed9fe4a 922 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 923 ROUTER_STR
924 BGP_STR
31500417
DW
925 AS_STR
926 BGP_INSTANCE_HELP_STR)
718e3744 927{
d62a17ae 928 int idx_asn = 2;
929 int idx_view_vrf = 3;
930 int idx_vrf = 4;
ecec9495 931 int is_new_bgp = 0;
d62a17ae 932 int ret;
933 as_t as;
934 struct bgp *bgp;
935 const char *name = NULL;
936 enum bgp_instance_type inst_type;
937
938 // "router bgp" without an ASN
939 if (argc == 2) {
940 // Pending: Make VRF option available for ASN less config
941 bgp = bgp_get_default();
942
943 if (bgp == NULL) {
944 vty_out(vty, "%% No BGP process is configured\n");
945 return CMD_WARNING_CONFIG_FAILED;
946 }
947
948 if (listcount(bm->bgp) > 1) {
996c9314 949 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 950 return CMD_WARNING_CONFIG_FAILED;
951 }
952 }
953
954 // "router bgp X"
955 else {
956 as = strtoul(argv[idx_asn]->arg, NULL, 10);
957
958 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
959 if (argc > 3) {
960 name = argv[idx_vrf]->arg;
961
9a8bdf1c
PG
962 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
963 if (strmatch(name, VRF_DEFAULT_NAME))
964 name = NULL;
965 else
966 inst_type = BGP_INSTANCE_TYPE_VRF;
967 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 968 inst_type = BGP_INSTANCE_TYPE_VIEW;
969 }
970
ecec9495
AD
971 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
972 is_new_bgp = (bgp_lookup(as, name) == NULL);
973
d62a17ae 974 ret = bgp_get(&bgp, &as, name, inst_type);
975 switch (ret) {
d62a17ae 976 case BGP_ERR_AS_MISMATCH:
977 vty_out(vty, "BGP is already running; AS is %u\n", as);
978 return CMD_WARNING_CONFIG_FAILED;
979 case BGP_ERR_INSTANCE_MISMATCH:
980 vty_out(vty,
981 "BGP instance name and AS number mismatch\n");
982 vty_out(vty,
983 "BGP instance is already running; AS is %u\n",
984 as);
985 return CMD_WARNING_CONFIG_FAILED;
986 }
987
3bd70bf8
PZ
988 /*
989 * If we just instantiated the default instance, complete
990 * any pending VRF-VPN leaking that was configured via
991 * earlier "router bgp X vrf FOO" blocks.
992 */
ecec9495 993 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
994 vpn_leak_postchange_all();
995
48381346
CS
996 if (inst_type == BGP_INSTANCE_TYPE_VRF)
997 bgp_vpn_leak_export(bgp);
d62a17ae 998 /* Pending: handle when user tries to change a view to vrf n vv.
999 */
1000 }
1001
0b5131c9
MK
1002 /* unset the auto created flag as the user config is now present */
1003 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1004 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1005
1006 return CMD_SUCCESS;
718e3744 1007}
1008
718e3744 1009/* "no router bgp" commands. */
1010DEFUN (no_router_bgp,
1011 no_router_bgp_cmd,
2ed9fe4a 1012 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1013 NO_STR
1014 ROUTER_STR
1015 BGP_STR
31500417
DW
1016 AS_STR
1017 BGP_INSTANCE_HELP_STR)
718e3744 1018{
d62a17ae 1019 int idx_asn = 3;
1020 int idx_vrf = 5;
1021 as_t as;
1022 struct bgp *bgp;
1023 const char *name = NULL;
718e3744 1024
d62a17ae 1025 // "no router bgp" without an ASN
1026 if (argc == 3) {
1027 // Pending: Make VRF option available for ASN less config
1028 bgp = bgp_get_default();
718e3744 1029
d62a17ae 1030 if (bgp == NULL) {
1031 vty_out(vty, "%% No BGP process is configured\n");
1032 return CMD_WARNING_CONFIG_FAILED;
1033 }
7fb21a9f 1034
d62a17ae 1035 if (listcount(bm->bgp) > 1) {
996c9314 1036 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1037 return CMD_WARNING_CONFIG_FAILED;
1038 }
0b5131c9
MK
1039
1040 if (bgp->l3vni) {
1041 vty_out(vty, "%% Please unconfigure l3vni %u",
1042 bgp->l3vni);
1043 return CMD_WARNING_CONFIG_FAILED;
1044 }
d62a17ae 1045 } else {
1046 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1047
d62a17ae 1048 if (argc > 4)
1049 name = argv[idx_vrf]->arg;
7fb21a9f 1050
d62a17ae 1051 /* Lookup bgp structure. */
1052 bgp = bgp_lookup(as, name);
1053 if (!bgp) {
1054 vty_out(vty, "%% Can't find BGP instance\n");
1055 return CMD_WARNING_CONFIG_FAILED;
1056 }
0b5131c9
MK
1057
1058 if (bgp->l3vni) {
dd5868c2 1059 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1060 bgp->l3vni);
1061 return CMD_WARNING_CONFIG_FAILED;
1062 }
dd5868c2
DS
1063
1064 /* Cannot delete default instance if vrf instances exist */
1065 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1066 struct listnode *node;
1067 struct bgp *tmp_bgp;
1068
1069 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1070 if (tmp_bgp->inst_type
1071 == BGP_INSTANCE_TYPE_VRF) {
1072 vty_out(vty,
1073 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1074 return CMD_WARNING_CONFIG_FAILED;
1075 }
1076 }
1077 }
d62a17ae 1078 }
718e3744 1079
9ecf931b
CS
1080 if (bgp_vpn_leak_unimport(bgp, vty))
1081 return CMD_WARNING_CONFIG_FAILED;
1082
d62a17ae 1083 bgp_delete(bgp);
718e3744 1084
d62a17ae 1085 return CMD_SUCCESS;
718e3744 1086}
1087
6b0655a2 1088
718e3744 1089/* BGP router-id. */
1090
f787d7a0 1091DEFPY (bgp_router_id,
718e3744 1092 bgp_router_id_cmd,
1093 "bgp router-id A.B.C.D",
1094 BGP_STR
1095 "Override configured router identifier\n"
1096 "Manually configured router identifier\n")
1097{
d62a17ae 1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_router_id_static_set(bgp, router_id);
1100 return CMD_SUCCESS;
718e3744 1101}
1102
f787d7a0 1103DEFPY (no_bgp_router_id,
718e3744 1104 no_bgp_router_id_cmd,
31500417 1105 "no bgp router-id [A.B.C.D]",
718e3744 1106 NO_STR
1107 BGP_STR
31500417
DW
1108 "Override configured router identifier\n"
1109 "Manually configured router identifier\n")
718e3744 1110{
d62a17ae 1111 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1112
d62a17ae 1113 if (router_id_str) {
1114 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1115 vty_out(vty, "%% BGP router-id doesn't match\n");
1116 return CMD_WARNING_CONFIG_FAILED;
1117 }
e018c7cc 1118 }
718e3744 1119
d62a17ae 1120 router_id.s_addr = 0;
1121 bgp_router_id_static_set(bgp, router_id);
718e3744 1122
d62a17ae 1123 return CMD_SUCCESS;
718e3744 1124}
1125
6b0655a2 1126
718e3744 1127/* BGP Cluster ID. */
718e3744 1128DEFUN (bgp_cluster_id,
1129 bgp_cluster_id_cmd,
838758ac 1130 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1131 BGP_STR
1132 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1133 "Route-Reflector Cluster-id in IP address format\n"
1134 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1135{
d62a17ae 1136 VTY_DECLVAR_CONTEXT(bgp, bgp);
1137 int idx_ipv4 = 2;
1138 int ret;
1139 struct in_addr cluster;
718e3744 1140
d62a17ae 1141 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1142 if (!ret) {
1143 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
718e3744 1146
d62a17ae 1147 bgp_cluster_id_set(bgp, &cluster);
1148 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1149
d62a17ae 1150 return CMD_SUCCESS;
718e3744 1151}
1152
718e3744 1153DEFUN (no_bgp_cluster_id,
1154 no_bgp_cluster_id_cmd,
c7178fe7 1155 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1156 NO_STR
1157 BGP_STR
838758ac
DW
1158 "Configure Route-Reflector Cluster-id\n"
1159 "Route-Reflector Cluster-id in IP address format\n"
1160 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1161{
d62a17ae 1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 bgp_cluster_id_unset(bgp);
1164 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1165
d62a17ae 1166 return CMD_SUCCESS;
718e3744 1167}
1168
718e3744 1169DEFUN (bgp_confederation_identifier,
1170 bgp_confederation_identifier_cmd,
9ccf14f7 1171 "bgp confederation identifier (1-4294967295)",
718e3744 1172 "BGP specific commands\n"
1173 "AS confederation parameters\n"
1174 "AS number\n"
1175 "Set routing domain confederation AS\n")
1176{
d62a17ae 1177 VTY_DECLVAR_CONTEXT(bgp, bgp);
1178 int idx_number = 3;
1179 as_t as;
718e3744 1180
d62a17ae 1181 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1182
d62a17ae 1183 bgp_confederation_id_set(bgp, as);
718e3744 1184
d62a17ae 1185 return CMD_SUCCESS;
718e3744 1186}
1187
1188DEFUN (no_bgp_confederation_identifier,
1189 no_bgp_confederation_identifier_cmd,
838758ac 1190 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1191 NO_STR
1192 "BGP specific commands\n"
1193 "AS confederation parameters\n"
3a2d747c
QY
1194 "AS number\n"
1195 "Set routing domain confederation AS\n")
718e3744 1196{
d62a17ae 1197 VTY_DECLVAR_CONTEXT(bgp, bgp);
1198 bgp_confederation_id_unset(bgp);
718e3744 1199
d62a17ae 1200 return CMD_SUCCESS;
718e3744 1201}
1202
718e3744 1203DEFUN (bgp_confederation_peers,
1204 bgp_confederation_peers_cmd,
12dcf78e 1205 "bgp confederation peers (1-4294967295)...",
718e3744 1206 "BGP specific commands\n"
1207 "AS confederation parameters\n"
1208 "Peer ASs in BGP confederation\n"
1209 AS_STR)
1210{
d62a17ae 1211 VTY_DECLVAR_CONTEXT(bgp, bgp);
1212 int idx_asn = 3;
1213 as_t as;
1214 int i;
718e3744 1215
d62a17ae 1216 for (i = idx_asn; i < argc; i++) {
1217 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1218
d62a17ae 1219 if (bgp->as == as) {
1220 vty_out(vty,
1221 "%% Local member-AS not allowed in confed peer list\n");
1222 continue;
1223 }
718e3744 1224
d62a17ae 1225 bgp_confederation_peers_add(bgp, as);
1226 }
1227 return CMD_SUCCESS;
718e3744 1228}
1229
1230DEFUN (no_bgp_confederation_peers,
1231 no_bgp_confederation_peers_cmd,
e83a9414 1232 "no bgp confederation peers (1-4294967295)...",
718e3744 1233 NO_STR
1234 "BGP specific commands\n"
1235 "AS confederation parameters\n"
1236 "Peer ASs in BGP confederation\n"
1237 AS_STR)
1238{
d62a17ae 1239 VTY_DECLVAR_CONTEXT(bgp, bgp);
1240 int idx_asn = 4;
1241 as_t as;
1242 int i;
718e3744 1243
d62a17ae 1244 for (i = idx_asn; i < argc; i++) {
1245 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1246
d62a17ae 1247 bgp_confederation_peers_remove(bgp, as);
1248 }
1249 return CMD_SUCCESS;
718e3744 1250}
6b0655a2 1251
5e242b0d
DS
1252/**
1253 * Central routine for maximum-paths configuration.
1254 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1255 * @set: 1 for setting values, 0 for removing the max-paths config.
1256 */
d62a17ae 1257static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1258 const char *mpaths, uint16_t options,
d62a17ae 1259 int set)
1260{
1261 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1262 uint16_t maxpaths = 0;
d62a17ae 1263 int ret;
1264 afi_t afi;
1265 safi_t safi;
1266
1267 afi = bgp_node_afi(vty);
1268 safi = bgp_node_safi(vty);
1269
1270 if (set) {
1271 maxpaths = strtol(mpaths, NULL, 10);
1272 if (maxpaths > multipath_num) {
1273 vty_out(vty,
1274 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1275 maxpaths, multipath_num);
1276 return CMD_WARNING_CONFIG_FAILED;
1277 }
1278 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1279 options);
1280 } else
1281 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1282
1283 if (ret < 0) {
1284 vty_out(vty,
1285 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1286 (set == 1) ? "" : "un",
1287 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1288 maxpaths, afi, safi);
1289 return CMD_WARNING_CONFIG_FAILED;
1290 }
1291
1292 bgp_recalculate_all_bestpaths(bgp);
1293
1294 return CMD_SUCCESS;
165b5fff
JB
1295}
1296
abc920f8
DS
1297DEFUN (bgp_maxmed_admin,
1298 bgp_maxmed_admin_cmd,
1299 "bgp max-med administrative ",
1300 BGP_STR
1301 "Advertise routes with max-med\n"
1302 "Administratively applied, for an indefinite period\n")
1303{
d62a17ae 1304 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1305
d62a17ae 1306 bgp->v_maxmed_admin = 1;
1307 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1308
d62a17ae 1309 bgp_maxmed_update(bgp);
abc920f8 1310
d62a17ae 1311 return CMD_SUCCESS;
abc920f8
DS
1312}
1313
1314DEFUN (bgp_maxmed_admin_medv,
1315 bgp_maxmed_admin_medv_cmd,
4668a151 1316 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1317 BGP_STR
1318 "Advertise routes with max-med\n"
1319 "Administratively applied, for an indefinite period\n"
1320 "Max MED value to be used\n")
1321{
d62a17ae 1322 VTY_DECLVAR_CONTEXT(bgp, bgp);
1323 int idx_number = 3;
abc920f8 1324
d62a17ae 1325 bgp->v_maxmed_admin = 1;
1326 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1327
d62a17ae 1328 bgp_maxmed_update(bgp);
abc920f8 1329
d62a17ae 1330 return CMD_SUCCESS;
abc920f8
DS
1331}
1332
1333DEFUN (no_bgp_maxmed_admin,
1334 no_bgp_maxmed_admin_cmd,
4668a151 1335 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1336 NO_STR
1337 BGP_STR
1338 "Advertise routes with max-med\n"
838758ac
DW
1339 "Administratively applied, for an indefinite period\n"
1340 "Max MED value to be used\n")
abc920f8 1341{
d62a17ae 1342 VTY_DECLVAR_CONTEXT(bgp, bgp);
1343 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1344 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1345 bgp_maxmed_update(bgp);
abc920f8 1346
d62a17ae 1347 return CMD_SUCCESS;
abc920f8
DS
1348}
1349
abc920f8
DS
1350DEFUN (bgp_maxmed_onstartup,
1351 bgp_maxmed_onstartup_cmd,
4668a151 1352 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1353 BGP_STR
1354 "Advertise routes with max-med\n"
1355 "Effective on a startup\n"
1356 "Time (seconds) period for max-med\n"
1357 "Max MED value to be used\n")
1358{
d62a17ae 1359 VTY_DECLVAR_CONTEXT(bgp, bgp);
1360 int idx = 0;
4668a151 1361
d62a17ae 1362 argv_find(argv, argc, "(5-86400)", &idx);
1363 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1364 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1365 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1366 else
1367 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1368
d62a17ae 1369 bgp_maxmed_update(bgp);
abc920f8 1370
d62a17ae 1371 return CMD_SUCCESS;
abc920f8
DS
1372}
1373
1374DEFUN (no_bgp_maxmed_onstartup,
1375 no_bgp_maxmed_onstartup_cmd,
4668a151 1376 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1377 NO_STR
1378 BGP_STR
1379 "Advertise routes with max-med\n"
838758ac
DW
1380 "Effective on a startup\n"
1381 "Time (seconds) period for max-med\n"
1382 "Max MED value to be used\n")
abc920f8 1383{
d62a17ae 1384 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1385
d62a17ae 1386 /* Cancel max-med onstartup if its on */
1387 if (bgp->t_maxmed_onstartup) {
1388 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1389 bgp->maxmed_onstartup_over = 1;
1390 }
abc920f8 1391
d62a17ae 1392 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1393 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1394
d62a17ae 1395 bgp_maxmed_update(bgp);
abc920f8 1396
d62a17ae 1397 return CMD_SUCCESS;
abc920f8
DS
1398}
1399
d62a17ae 1400static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1401 const char *wait)
f188f2c4 1402{
d62a17ae 1403 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1404 uint16_t update_delay;
1405 uint16_t establish_wait;
f188f2c4 1406
d62a17ae 1407 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1408
d62a17ae 1409 if (!wait) /* update-delay <delay> */
1410 {
1411 bgp->v_update_delay = update_delay;
1412 bgp->v_establish_wait = bgp->v_update_delay;
1413 return CMD_SUCCESS;
1414 }
f188f2c4 1415
d62a17ae 1416 /* update-delay <delay> <establish-wait> */
1417 establish_wait = atoi(wait);
1418 if (update_delay < establish_wait) {
1419 vty_out(vty,
1420 "%%Failed: update-delay less than the establish-wait!\n");
1421 return CMD_WARNING_CONFIG_FAILED;
1422 }
f188f2c4 1423
d62a17ae 1424 bgp->v_update_delay = update_delay;
1425 bgp->v_establish_wait = establish_wait;
f188f2c4 1426
d62a17ae 1427 return CMD_SUCCESS;
f188f2c4
DS
1428}
1429
d62a17ae 1430static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1431{
d62a17ae 1432 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1433
d62a17ae 1434 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1435 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1436
d62a17ae 1437 return CMD_SUCCESS;
f188f2c4
DS
1438}
1439
2b791107 1440void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1441{
d62a17ae 1442 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1443 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1444 if (bgp->v_update_delay != bgp->v_establish_wait)
1445 vty_out(vty, " %d", bgp->v_establish_wait);
1446 vty_out(vty, "\n");
1447 }
f188f2c4
DS
1448}
1449
1450
1451/* Update-delay configuration */
1452DEFUN (bgp_update_delay,
1453 bgp_update_delay_cmd,
6147e2c6 1454 "update-delay (0-3600)",
f188f2c4
DS
1455 "Force initial delay for best-path and updates\n"
1456 "Seconds\n")
1457{
d62a17ae 1458 int idx_number = 1;
1459 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1460}
1461
1462DEFUN (bgp_update_delay_establish_wait,
1463 bgp_update_delay_establish_wait_cmd,
6147e2c6 1464 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1465 "Force initial delay for best-path and updates\n"
1466 "Seconds\n"
f188f2c4
DS
1467 "Seconds\n")
1468{
d62a17ae 1469 int idx_number = 1;
1470 int idx_number_2 = 2;
1471 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1472 argv[idx_number_2]->arg);
f188f2c4
DS
1473}
1474
1475/* Update-delay deconfiguration */
1476DEFUN (no_bgp_update_delay,
1477 no_bgp_update_delay_cmd,
838758ac
DW
1478 "no update-delay [(0-3600) [(1-3600)]]",
1479 NO_STR
f188f2c4 1480 "Force initial delay for best-path and updates\n"
838758ac 1481 "Seconds\n"
7111c1a0 1482 "Seconds\n")
f188f2c4 1483{
d62a17ae 1484 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1485}
1486
5e242b0d 1487
d62a17ae 1488static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1489 char set)
cb1faec9 1490{
d62a17ae 1491 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1492
555e09d4
QY
1493 if (set) {
1494 uint32_t quanta = strtoul(num, NULL, 10);
1495 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1496 memory_order_relaxed);
1497 } else {
1498 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1499 memory_order_relaxed);
1500 }
1501
1502 return CMD_SUCCESS;
1503}
1504
1505static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1506 char set)
1507{
1508 VTY_DECLVAR_CONTEXT(bgp, bgp);
1509
1510 if (set) {
1511 uint32_t quanta = strtoul(num, NULL, 10);
1512 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1513 memory_order_relaxed);
1514 } else {
1515 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1516 memory_order_relaxed);
1517 }
cb1faec9 1518
d62a17ae 1519 return CMD_SUCCESS;
cb1faec9
DS
1520}
1521
2b791107 1522void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1523{
555e09d4
QY
1524 uint32_t quanta =
1525 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1526 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1527 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1528}
1529
555e09d4
QY
1530void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1531{
1532 uint32_t quanta =
1533 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1534 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1535 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1536}
cb1faec9 1537
555e09d4 1538/* Packet quanta configuration */
cb1faec9
DS
1539DEFUN (bgp_wpkt_quanta,
1540 bgp_wpkt_quanta_cmd,
555e09d4 1541 "write-quanta (1-10)",
cb1faec9
DS
1542 "How many packets to write to peer socket per run\n"
1543 "Number of packets\n")
1544{
d62a17ae 1545 int idx_number = 1;
1546 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1547}
1548
cb1faec9
DS
1549DEFUN (no_bgp_wpkt_quanta,
1550 no_bgp_wpkt_quanta_cmd,
555e09d4 1551 "no write-quanta (1-10)",
d7fa34c1 1552 NO_STR
555e09d4 1553 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1554 "Number of packets\n")
1555{
d62a17ae 1556 int idx_number = 2;
1557 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1558}
1559
555e09d4
QY
1560DEFUN (bgp_rpkt_quanta,
1561 bgp_rpkt_quanta_cmd,
1562 "read-quanta (1-10)",
1563 "How many packets to read from peer socket per I/O cycle\n"
1564 "Number of packets\n")
1565{
1566 int idx_number = 1;
1567 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1568}
1569
1570DEFUN (no_bgp_rpkt_quanta,
1571 no_bgp_rpkt_quanta_cmd,
1572 "no read-quanta (1-10)",
1573 NO_STR
1574 "How many packets to read from peer socket per I/O cycle\n"
1575 "Number of packets\n")
1576{
1577 int idx_number = 2;
1578 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1579}
1580
2b791107 1581void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1582{
37a333fe 1583 if (!bgp->heuristic_coalesce)
d62a17ae 1584 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1585}
1586
1587
1588DEFUN (bgp_coalesce_time,
1589 bgp_coalesce_time_cmd,
6147e2c6 1590 "coalesce-time (0-4294967295)",
3f9c7369
DS
1591 "Subgroup coalesce timer\n"
1592 "Subgroup coalesce timer value (in ms)\n")
1593{
d62a17ae 1594 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1595
d62a17ae 1596 int idx = 0;
1597 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1598 bgp->heuristic_coalesce = false;
d62a17ae 1599 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1600 return CMD_SUCCESS;
3f9c7369
DS
1601}
1602
1603DEFUN (no_bgp_coalesce_time,
1604 no_bgp_coalesce_time_cmd,
6147e2c6 1605 "no coalesce-time (0-4294967295)",
3a2d747c 1606 NO_STR
3f9c7369
DS
1607 "Subgroup coalesce timer\n"
1608 "Subgroup coalesce timer value (in ms)\n")
1609{
d62a17ae 1610 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1611
37a333fe 1612 bgp->heuristic_coalesce = true;
d62a17ae 1613 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1614 return CMD_SUCCESS;
3f9c7369
DS
1615}
1616
5e242b0d
DS
1617/* Maximum-paths configuration */
1618DEFUN (bgp_maxpaths,
1619 bgp_maxpaths_cmd,
6319fd63 1620 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1621 "Forward packets over multiple paths\n"
1622 "Number of paths\n")
1623{
d62a17ae 1624 int idx_number = 1;
1625 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1626 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1627}
1628
d62a17ae 1629ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1630 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1631 "Forward packets over multiple paths\n"
1632 "Number of paths\n")
596c17ba 1633
165b5fff
JB
1634DEFUN (bgp_maxpaths_ibgp,
1635 bgp_maxpaths_ibgp_cmd,
6319fd63 1636 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1637 "Forward packets over multiple paths\n"
1638 "iBGP-multipath\n"
1639 "Number of paths\n")
1640{
d62a17ae 1641 int idx_number = 2;
1642 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1643 argv[idx_number]->arg, 0, 1);
5e242b0d 1644}
165b5fff 1645
d62a17ae 1646ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1647 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1648 "Forward packets over multiple paths\n"
1649 "iBGP-multipath\n"
1650 "Number of paths\n")
596c17ba 1651
5e242b0d
DS
1652DEFUN (bgp_maxpaths_ibgp_cluster,
1653 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1654 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1655 "Forward packets over multiple paths\n"
1656 "iBGP-multipath\n"
1657 "Number of paths\n"
1658 "Match the cluster length\n")
1659{
d62a17ae 1660 int idx_number = 2;
1661 return bgp_maxpaths_config_vty(
1662 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1663 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1664}
1665
d62a17ae 1666ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1667 "maximum-paths ibgp " CMD_RANGE_STR(
1668 1, MULTIPATH_NUM) " equal-cluster-length",
1669 "Forward packets over multiple paths\n"
1670 "iBGP-multipath\n"
1671 "Number of paths\n"
1672 "Match the cluster length\n")
596c17ba 1673
165b5fff
JB
1674DEFUN (no_bgp_maxpaths,
1675 no_bgp_maxpaths_cmd,
6319fd63 1676 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1677 NO_STR
1678 "Forward packets over multiple paths\n"
1679 "Number of paths\n")
1680{
d62a17ae 1681 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1682}
1683
d62a17ae 1684ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1685 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1686 "Forward packets over multiple paths\n"
1687 "Number of paths\n")
596c17ba 1688
165b5fff
JB
1689DEFUN (no_bgp_maxpaths_ibgp,
1690 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1691 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1692 NO_STR
1693 "Forward packets over multiple paths\n"
1694 "iBGP-multipath\n"
838758ac
DW
1695 "Number of paths\n"
1696 "Match the cluster length\n")
165b5fff 1697{
d62a17ae 1698 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1699}
1700
d62a17ae 1701ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1702 "no maximum-paths ibgp [" CMD_RANGE_STR(
1703 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1704 NO_STR
1705 "Forward packets over multiple paths\n"
1706 "iBGP-multipath\n"
1707 "Number of paths\n"
1708 "Match the cluster length\n")
596c17ba 1709
2b791107 1710void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1711 safi_t safi)
165b5fff 1712{
d62a17ae 1713 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1714 vty_out(vty, " maximum-paths %d\n",
1715 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1716 }
165b5fff 1717
d62a17ae 1718 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1719 vty_out(vty, " maximum-paths ibgp %d",
1720 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1721 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1722 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1723 vty_out(vty, " equal-cluster-length");
1724 vty_out(vty, "\n");
1725 }
165b5fff 1726}
6b0655a2 1727
718e3744 1728/* BGP timers. */
1729
1730DEFUN (bgp_timers,
1731 bgp_timers_cmd,
6147e2c6 1732 "timers bgp (0-65535) (0-65535)",
718e3744 1733 "Adjust routing timers\n"
1734 "BGP timers\n"
1735 "Keepalive interval\n"
1736 "Holdtime\n")
1737{
d62a17ae 1738 VTY_DECLVAR_CONTEXT(bgp, bgp);
1739 int idx_number = 2;
1740 int idx_number_2 = 3;
1741 unsigned long keepalive = 0;
1742 unsigned long holdtime = 0;
718e3744 1743
d62a17ae 1744 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1745 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1746
d62a17ae 1747 /* Holdtime value check. */
1748 if (holdtime < 3 && holdtime != 0) {
1749 vty_out(vty,
1750 "%% hold time value must be either 0 or greater than 3\n");
1751 return CMD_WARNING_CONFIG_FAILED;
1752 }
718e3744 1753
d62a17ae 1754 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1755
d62a17ae 1756 return CMD_SUCCESS;
718e3744 1757}
1758
1759DEFUN (no_bgp_timers,
1760 no_bgp_timers_cmd,
838758ac 1761 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1762 NO_STR
1763 "Adjust routing timers\n"
838758ac
DW
1764 "BGP timers\n"
1765 "Keepalive interval\n"
1766 "Holdtime\n")
718e3744 1767{
d62a17ae 1768 VTY_DECLVAR_CONTEXT(bgp, bgp);
1769 bgp_timers_unset(bgp);
718e3744 1770
d62a17ae 1771 return CMD_SUCCESS;
718e3744 1772}
1773
6b0655a2 1774
718e3744 1775DEFUN (bgp_client_to_client_reflection,
1776 bgp_client_to_client_reflection_cmd,
1777 "bgp client-to-client reflection",
1778 "BGP specific commands\n"
1779 "Configure client to client route reflection\n"
1780 "reflection of routes allowed\n")
1781{
d62a17ae 1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1784 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1785
d62a17ae 1786 return CMD_SUCCESS;
718e3744 1787}
1788
1789DEFUN (no_bgp_client_to_client_reflection,
1790 no_bgp_client_to_client_reflection_cmd,
1791 "no bgp client-to-client reflection",
1792 NO_STR
1793 "BGP specific commands\n"
1794 "Configure client to client route reflection\n"
1795 "reflection of routes allowed\n")
1796{
d62a17ae 1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
1798 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1799 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1800
d62a17ae 1801 return CMD_SUCCESS;
718e3744 1802}
1803
1804/* "bgp always-compare-med" configuration. */
1805DEFUN (bgp_always_compare_med,
1806 bgp_always_compare_med_cmd,
1807 "bgp always-compare-med",
1808 "BGP specific commands\n"
1809 "Allow comparing MED from different neighbors\n")
1810{
d62a17ae 1811 VTY_DECLVAR_CONTEXT(bgp, bgp);
1812 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1813 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1814
d62a17ae 1815 return CMD_SUCCESS;
718e3744 1816}
1817
1818DEFUN (no_bgp_always_compare_med,
1819 no_bgp_always_compare_med_cmd,
1820 "no bgp always-compare-med",
1821 NO_STR
1822 "BGP specific commands\n"
1823 "Allow comparing MED from different neighbors\n")
1824{
d62a17ae 1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1827 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1828
d62a17ae 1829 return CMD_SUCCESS;
718e3744 1830}
6b0655a2 1831
9dac9fc8
DA
1832
1833DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1834 "bgp ebgp-requires-policy",
1835 "BGP specific commands\n"
1836 "Require in and out policy for eBGP peers (RFC8212)\n")
1837{
1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1840 return CMD_SUCCESS;
1841}
1842
1843DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1844 "no bgp ebgp-requires-policy",
1845 NO_STR
1846 "BGP specific commands\n"
1847 "Require in and out policy for eBGP peers (RFC8212)\n")
1848{
1849 VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1851 return CMD_SUCCESS;
1852}
1853
1854
718e3744 1855/* "bgp deterministic-med" configuration. */
1856DEFUN (bgp_deterministic_med,
1857 bgp_deterministic_med_cmd,
1858 "bgp deterministic-med",
1859 "BGP specific commands\n"
1860 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1861{
d62a17ae 1862 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1863
d62a17ae 1864 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1865 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1866 bgp_recalculate_all_bestpaths(bgp);
1867 }
7aafcaca 1868
d62a17ae 1869 return CMD_SUCCESS;
718e3744 1870}
1871
1872DEFUN (no_bgp_deterministic_med,
1873 no_bgp_deterministic_med_cmd,
1874 "no bgp deterministic-med",
1875 NO_STR
1876 "BGP specific commands\n"
1877 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1878{
d62a17ae 1879 VTY_DECLVAR_CONTEXT(bgp, bgp);
1880 int bestpath_per_as_used;
1881 afi_t afi;
1882 safi_t safi;
1883 struct peer *peer;
1884 struct listnode *node, *nnode;
1885
1886 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1887 bestpath_per_as_used = 0;
1888
1889 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1890 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1891 if (bgp_addpath_dmed_required(
1892 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1893 bestpath_per_as_used = 1;
1894 break;
1895 }
d62a17ae 1896
1897 if (bestpath_per_as_used)
1898 break;
1899 }
1900
1901 if (bestpath_per_as_used) {
1902 vty_out(vty,
1903 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1904 return CMD_WARNING_CONFIG_FAILED;
1905 } else {
1906 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1907 bgp_recalculate_all_bestpaths(bgp);
1908 }
1909 }
1910
1911 return CMD_SUCCESS;
718e3744 1912}
538621f2 1913
1914/* "bgp graceful-restart" configuration. */
1915DEFUN (bgp_graceful_restart,
1916 bgp_graceful_restart_cmd,
1917 "bgp graceful-restart",
1918 "BGP specific commands\n"
1919 "Graceful restart capability parameters\n")
1920{
d62a17ae 1921 VTY_DECLVAR_CONTEXT(bgp, bgp);
1922 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1923 return CMD_SUCCESS;
538621f2 1924}
1925
1926DEFUN (no_bgp_graceful_restart,
1927 no_bgp_graceful_restart_cmd,
1928 "no bgp graceful-restart",
1929 NO_STR
1930 "BGP specific commands\n"
1931 "Graceful restart capability parameters\n")
1932{
d62a17ae 1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1935 return CMD_SUCCESS;
538621f2 1936}
1937
93406d87 1938DEFUN (bgp_graceful_restart_stalepath_time,
1939 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 1940 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 1941 "BGP specific commands\n"
1942 "Graceful restart capability parameters\n"
1943 "Set the max time to hold onto restarting peer's stale paths\n"
1944 "Delay value (seconds)\n")
1945{
d62a17ae 1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 int idx_number = 3;
d7c0a89a 1948 uint32_t stalepath;
93406d87 1949
d62a17ae 1950 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1951 bgp->stalepath_time = stalepath;
1952 return CMD_SUCCESS;
93406d87 1953}
1954
eb6f1b41
PG
1955DEFUN (bgp_graceful_restart_restart_time,
1956 bgp_graceful_restart_restart_time_cmd,
c72d0314 1957 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
1958 "BGP specific commands\n"
1959 "Graceful restart capability parameters\n"
1960 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1961 "Delay value (seconds)\n")
1962{
d62a17ae 1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1964 int idx_number = 3;
d7c0a89a 1965 uint32_t restart;
eb6f1b41 1966
d62a17ae 1967 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1968 bgp->restart_time = restart;
1969 return CMD_SUCCESS;
eb6f1b41
PG
1970}
1971
93406d87 1972DEFUN (no_bgp_graceful_restart_stalepath_time,
1973 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 1974 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 1975 NO_STR
1976 "BGP specific commands\n"
1977 "Graceful restart capability parameters\n"
838758ac
DW
1978 "Set the max time to hold onto restarting peer's stale paths\n"
1979 "Delay value (seconds)\n")
93406d87 1980{
d62a17ae 1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1982
d62a17ae 1983 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1984 return CMD_SUCCESS;
93406d87 1985}
1986
eb6f1b41
PG
1987DEFUN (no_bgp_graceful_restart_restart_time,
1988 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 1989 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
1990 NO_STR
1991 "BGP specific commands\n"
1992 "Graceful restart capability parameters\n"
838758ac
DW
1993 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1994 "Delay value (seconds)\n")
eb6f1b41 1995{
d62a17ae 1996 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1997
d62a17ae 1998 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1999 return CMD_SUCCESS;
eb6f1b41
PG
2000}
2001
43fc21b3
JC
2002DEFUN (bgp_graceful_restart_preserve_fw,
2003 bgp_graceful_restart_preserve_fw_cmd,
2004 "bgp graceful-restart preserve-fw-state",
2005 "BGP specific commands\n"
2006 "Graceful restart capability parameters\n"
2007 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2008{
d62a17ae 2009 VTY_DECLVAR_CONTEXT(bgp, bgp);
2010 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2011 return CMD_SUCCESS;
43fc21b3
JC
2012}
2013
2014DEFUN (no_bgp_graceful_restart_preserve_fw,
2015 no_bgp_graceful_restart_preserve_fw_cmd,
2016 "no bgp graceful-restart preserve-fw-state",
2017 NO_STR
2018 "BGP specific commands\n"
2019 "Graceful restart capability parameters\n"
2020 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2021{
d62a17ae 2022 VTY_DECLVAR_CONTEXT(bgp, bgp);
2023 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2024 return CMD_SUCCESS;
43fc21b3
JC
2025}
2026
7f323236
DW
2027/* "bgp graceful-shutdown" configuration */
2028DEFUN (bgp_graceful_shutdown,
2029 bgp_graceful_shutdown_cmd,
2030 "bgp graceful-shutdown",
2031 BGP_STR
2032 "Graceful shutdown parameters\n")
2033{
2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035
2036 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2037 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2038 bgp_static_redo_import_check(bgp);
2039 bgp_redistribute_redo(bgp);
2040 bgp_clear_star_soft_out(vty, bgp->name);
2041 bgp_clear_star_soft_in(vty, bgp->name);
2042 }
2043
2044 return CMD_SUCCESS;
2045}
2046
2047DEFUN (no_bgp_graceful_shutdown,
2048 no_bgp_graceful_shutdown_cmd,
2049 "no bgp graceful-shutdown",
2050 NO_STR
2051 BGP_STR
2052 "Graceful shutdown parameters\n")
2053{
2054 VTY_DECLVAR_CONTEXT(bgp, bgp);
2055
2056 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2057 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2058 bgp_static_redo_import_check(bgp);
2059 bgp_redistribute_redo(bgp);
2060 bgp_clear_star_soft_out(vty, bgp->name);
2061 bgp_clear_star_soft_in(vty, bgp->name);
2062 }
2063
2064 return CMD_SUCCESS;
2065}
2066
718e3744 2067/* "bgp fast-external-failover" configuration. */
2068DEFUN (bgp_fast_external_failover,
2069 bgp_fast_external_failover_cmd,
2070 "bgp fast-external-failover",
2071 BGP_STR
2072 "Immediately reset session if a link to a directly connected external peer goes down\n")
2073{
d62a17ae 2074 VTY_DECLVAR_CONTEXT(bgp, bgp);
2075 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2076 return CMD_SUCCESS;
718e3744 2077}
2078
2079DEFUN (no_bgp_fast_external_failover,
2080 no_bgp_fast_external_failover_cmd,
2081 "no bgp fast-external-failover",
2082 NO_STR
2083 BGP_STR
2084 "Immediately reset session if a link to a directly connected external peer goes down\n")
2085{
d62a17ae 2086 VTY_DECLVAR_CONTEXT(bgp, bgp);
2087 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2088 return CMD_SUCCESS;
718e3744 2089}
6b0655a2 2090
718e3744 2091/* "bgp bestpath compare-routerid" configuration. */
2092DEFUN (bgp_bestpath_compare_router_id,
2093 bgp_bestpath_compare_router_id_cmd,
2094 "bgp bestpath compare-routerid",
2095 "BGP specific commands\n"
2096 "Change the default bestpath selection\n"
2097 "Compare router-id for identical EBGP paths\n")
2098{
d62a17ae 2099 VTY_DECLVAR_CONTEXT(bgp, bgp);
2100 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2101 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2102
d62a17ae 2103 return CMD_SUCCESS;
718e3744 2104}
2105
2106DEFUN (no_bgp_bestpath_compare_router_id,
2107 no_bgp_bestpath_compare_router_id_cmd,
2108 "no bgp bestpath compare-routerid",
2109 NO_STR
2110 "BGP specific commands\n"
2111 "Change the default bestpath selection\n"
2112 "Compare router-id for identical EBGP paths\n")
2113{
d62a17ae 2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2116 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2117
d62a17ae 2118 return CMD_SUCCESS;
718e3744 2119}
6b0655a2 2120
718e3744 2121/* "bgp bestpath as-path ignore" configuration. */
2122DEFUN (bgp_bestpath_aspath_ignore,
2123 bgp_bestpath_aspath_ignore_cmd,
2124 "bgp bestpath as-path ignore",
2125 "BGP specific commands\n"
2126 "Change the default bestpath selection\n"
2127 "AS-path attribute\n"
2128 "Ignore as-path length in selecting a route\n")
2129{
d62a17ae 2130 VTY_DECLVAR_CONTEXT(bgp, bgp);
2131 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2132 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2133
d62a17ae 2134 return CMD_SUCCESS;
718e3744 2135}
2136
2137DEFUN (no_bgp_bestpath_aspath_ignore,
2138 no_bgp_bestpath_aspath_ignore_cmd,
2139 "no bgp bestpath as-path ignore",
2140 NO_STR
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "AS-path attribute\n"
2144 "Ignore as-path length in selecting a route\n")
2145{
d62a17ae 2146 VTY_DECLVAR_CONTEXT(bgp, bgp);
2147 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2148 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2149
d62a17ae 2150 return CMD_SUCCESS;
718e3744 2151}
6b0655a2 2152
6811845b 2153/* "bgp bestpath as-path confed" configuration. */
2154DEFUN (bgp_bestpath_aspath_confed,
2155 bgp_bestpath_aspath_confed_cmd,
2156 "bgp bestpath as-path confed",
2157 "BGP specific commands\n"
2158 "Change the default bestpath selection\n"
2159 "AS-path attribute\n"
2160 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2161{
d62a17ae 2162 VTY_DECLVAR_CONTEXT(bgp, bgp);
2163 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2164 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2165
d62a17ae 2166 return CMD_SUCCESS;
6811845b 2167}
2168
2169DEFUN (no_bgp_bestpath_aspath_confed,
2170 no_bgp_bestpath_aspath_confed_cmd,
2171 "no bgp bestpath as-path confed",
2172 NO_STR
2173 "BGP specific commands\n"
2174 "Change the default bestpath selection\n"
2175 "AS-path attribute\n"
2176 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2177{
d62a17ae 2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
2179 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2180 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2181
d62a17ae 2182 return CMD_SUCCESS;
6811845b 2183}
6b0655a2 2184
2fdd455c
PM
2185/* "bgp bestpath as-path multipath-relax" configuration. */
2186DEFUN (bgp_bestpath_aspath_multipath_relax,
2187 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2188 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2189 "BGP specific commands\n"
2190 "Change the default bestpath selection\n"
2191 "AS-path attribute\n"
2192 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2193 "Generate an AS_SET\n"
16fc1eec
DS
2194 "Do not generate an AS_SET\n")
2195{
d62a17ae 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 int idx = 0;
2198 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2199
d62a17ae 2200 /* no-as-set is now the default behavior so we can silently
2201 * ignore it */
2202 if (argv_find(argv, argc, "as-set", &idx))
2203 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2204 else
2205 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2206
d62a17ae 2207 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2208
d62a17ae 2209 return CMD_SUCCESS;
16fc1eec
DS
2210}
2211
219178b6
DW
2212DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2213 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2214 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2215 NO_STR
2216 "BGP specific commands\n"
2217 "Change the default bestpath selection\n"
2218 "AS-path attribute\n"
2219 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2220 "Generate an AS_SET\n"
16fc1eec
DS
2221 "Do not generate an AS_SET\n")
2222{
d62a17ae 2223 VTY_DECLVAR_CONTEXT(bgp, bgp);
2224 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2225 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2226 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2227
d62a17ae 2228 return CMD_SUCCESS;
2fdd455c 2229}
6b0655a2 2230
848973c7 2231/* "bgp log-neighbor-changes" configuration. */
2232DEFUN (bgp_log_neighbor_changes,
2233 bgp_log_neighbor_changes_cmd,
2234 "bgp log-neighbor-changes",
2235 "BGP specific commands\n"
2236 "Log neighbor up/down and reset reason\n")
2237{
d62a17ae 2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2240 return CMD_SUCCESS;
848973c7 2241}
2242
2243DEFUN (no_bgp_log_neighbor_changes,
2244 no_bgp_log_neighbor_changes_cmd,
2245 "no bgp log-neighbor-changes",
2246 NO_STR
2247 "BGP specific commands\n"
2248 "Log neighbor up/down and reset reason\n")
2249{
d62a17ae 2250 VTY_DECLVAR_CONTEXT(bgp, bgp);
2251 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2252 return CMD_SUCCESS;
848973c7 2253}
6b0655a2 2254
718e3744 2255/* "bgp bestpath med" configuration. */
2256DEFUN (bgp_bestpath_med,
2257 bgp_bestpath_med_cmd,
2d8c1a4d 2258 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2259 "BGP specific commands\n"
2260 "Change the default bestpath selection\n"
2261 "MED attribute\n"
2262 "Compare MED among confederation paths\n"
838758ac
DW
2263 "Treat missing MED as the least preferred one\n"
2264 "Treat missing MED as the least preferred one\n"
2265 "Compare MED among confederation paths\n")
718e3744 2266{
d62a17ae 2267 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2268
d62a17ae 2269 int idx = 0;
2270 if (argv_find(argv, argc, "confed", &idx))
2271 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2272 idx = 0;
2273 if (argv_find(argv, argc, "missing-as-worst", &idx))
2274 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2275
d62a17ae 2276 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2277
d62a17ae 2278 return CMD_SUCCESS;
718e3744 2279}
2280
718e3744 2281DEFUN (no_bgp_bestpath_med,
2282 no_bgp_bestpath_med_cmd,
2d8c1a4d 2283 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2284 NO_STR
2285 "BGP specific commands\n"
2286 "Change the default bestpath selection\n"
2287 "MED attribute\n"
2288 "Compare MED among confederation paths\n"
3a2d747c
QY
2289 "Treat missing MED as the least preferred one\n"
2290 "Treat missing MED as the least preferred one\n"
2291 "Compare MED among confederation paths\n")
718e3744 2292{
d62a17ae 2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2294
d62a17ae 2295 int idx = 0;
2296 if (argv_find(argv, argc, "confed", &idx))
2297 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2298 idx = 0;
2299 if (argv_find(argv, argc, "missing-as-worst", &idx))
2300 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2301
d62a17ae 2302 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2303
d62a17ae 2304 return CMD_SUCCESS;
718e3744 2305}
2306
718e3744 2307/* "no bgp default ipv4-unicast". */
2308DEFUN (no_bgp_default_ipv4_unicast,
2309 no_bgp_default_ipv4_unicast_cmd,
2310 "no bgp default ipv4-unicast",
2311 NO_STR
2312 "BGP specific commands\n"
2313 "Configure BGP defaults\n"
2314 "Activate ipv4-unicast for a peer by default\n")
2315{
d62a17ae 2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2318 return CMD_SUCCESS;
718e3744 2319}
2320
2321DEFUN (bgp_default_ipv4_unicast,
2322 bgp_default_ipv4_unicast_cmd,
2323 "bgp default ipv4-unicast",
2324 "BGP specific commands\n"
2325 "Configure BGP defaults\n"
2326 "Activate ipv4-unicast for a peer by default\n")
2327{
d62a17ae 2328 VTY_DECLVAR_CONTEXT(bgp, bgp);
2329 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2330 return CMD_SUCCESS;
718e3744 2331}
6b0655a2 2332
04b6bdc0
DW
2333/* Display hostname in certain command outputs */
2334DEFUN (bgp_default_show_hostname,
2335 bgp_default_show_hostname_cmd,
2336 "bgp default show-hostname",
2337 "BGP specific commands\n"
2338 "Configure BGP defaults\n"
0437e105 2339 "Show hostname in certain command outputs\n")
04b6bdc0 2340{
d62a17ae 2341 VTY_DECLVAR_CONTEXT(bgp, bgp);
2342 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2343 return CMD_SUCCESS;
04b6bdc0
DW
2344}
2345
2346DEFUN (no_bgp_default_show_hostname,
2347 no_bgp_default_show_hostname_cmd,
2348 "no bgp default show-hostname",
2349 NO_STR
2350 "BGP specific commands\n"
2351 "Configure BGP defaults\n"
0437e105 2352 "Show hostname in certain command outputs\n")
04b6bdc0 2353{
d62a17ae 2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
2355 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2356 return CMD_SUCCESS;
04b6bdc0
DW
2357}
2358
8233ef81 2359/* "bgp network import-check" configuration. */
718e3744 2360DEFUN (bgp_network_import_check,
2361 bgp_network_import_check_cmd,
5623e905 2362 "bgp network import-check",
718e3744 2363 "BGP specific commands\n"
2364 "BGP network command\n"
5623e905 2365 "Check BGP network route exists in IGP\n")
718e3744 2366{
d62a17ae 2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2369 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2370 bgp_static_redo_import_check(bgp);
2371 }
078430f6 2372
d62a17ae 2373 return CMD_SUCCESS;
718e3744 2374}
2375
d62a17ae 2376ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2377 "bgp network import-check exact",
2378 "BGP specific commands\n"
2379 "BGP network command\n"
2380 "Check BGP network route exists in IGP\n"
2381 "Match route precisely\n")
8233ef81 2382
718e3744 2383DEFUN (no_bgp_network_import_check,
2384 no_bgp_network_import_check_cmd,
5623e905 2385 "no bgp network import-check",
718e3744 2386 NO_STR
2387 "BGP specific commands\n"
2388 "BGP network command\n"
2389 "Check BGP network route exists in IGP\n")
2390{
d62a17ae 2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2393 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2394 bgp_static_redo_import_check(bgp);
2395 }
5623e905 2396
d62a17ae 2397 return CMD_SUCCESS;
718e3744 2398}
6b0655a2 2399
718e3744 2400DEFUN (bgp_default_local_preference,
2401 bgp_default_local_preference_cmd,
6147e2c6 2402 "bgp default local-preference (0-4294967295)",
718e3744 2403 "BGP specific commands\n"
2404 "Configure BGP defaults\n"
2405 "local preference (higher=more preferred)\n"
2406 "Configure default local preference value\n")
2407{
d62a17ae 2408 VTY_DECLVAR_CONTEXT(bgp, bgp);
2409 int idx_number = 3;
d7c0a89a 2410 uint32_t local_pref;
718e3744 2411
d62a17ae 2412 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2413
d62a17ae 2414 bgp_default_local_preference_set(bgp, local_pref);
2415 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2416
d62a17ae 2417 return CMD_SUCCESS;
718e3744 2418}
2419
2420DEFUN (no_bgp_default_local_preference,
2421 no_bgp_default_local_preference_cmd,
838758ac 2422 "no bgp default local-preference [(0-4294967295)]",
718e3744 2423 NO_STR
2424 "BGP specific commands\n"
2425 "Configure BGP defaults\n"
838758ac
DW
2426 "local preference (higher=more preferred)\n"
2427 "Configure default local preference value\n")
718e3744 2428{
d62a17ae 2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430 bgp_default_local_preference_unset(bgp);
2431 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2432
d62a17ae 2433 return CMD_SUCCESS;
718e3744 2434}
2435
6b0655a2 2436
3f9c7369
DS
2437DEFUN (bgp_default_subgroup_pkt_queue_max,
2438 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2439 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2440 "BGP specific commands\n"
2441 "Configure BGP defaults\n"
2442 "subgroup-pkt-queue-max\n"
2443 "Configure subgroup packet queue max\n")
8bd9d948 2444{
d62a17ae 2445 VTY_DECLVAR_CONTEXT(bgp, bgp);
2446 int idx_number = 3;
d7c0a89a 2447 uint32_t max_size;
8bd9d948 2448
d62a17ae 2449 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2450
d62a17ae 2451 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2452
d62a17ae 2453 return CMD_SUCCESS;
3f9c7369
DS
2454}
2455
2456DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2457 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2458 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2459 NO_STR
2460 "BGP specific commands\n"
2461 "Configure BGP defaults\n"
838758ac
DW
2462 "subgroup-pkt-queue-max\n"
2463 "Configure subgroup packet queue max\n")
3f9c7369 2464{
d62a17ae 2465 VTY_DECLVAR_CONTEXT(bgp, bgp);
2466 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2467 return CMD_SUCCESS;
8bd9d948
DS
2468}
2469
813d4307 2470
8bd9d948
DS
2471DEFUN (bgp_rr_allow_outbound_policy,
2472 bgp_rr_allow_outbound_policy_cmd,
2473 "bgp route-reflector allow-outbound-policy",
2474 "BGP specific commands\n"
2475 "Allow modifications made by out route-map\n"
2476 "on ibgp neighbors\n")
2477{
d62a17ae 2478 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2479
d62a17ae 2480 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2481 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2482 update_group_announce_rrclients(bgp);
2483 bgp_clear_star_soft_out(vty, bgp->name);
2484 }
8bd9d948 2485
d62a17ae 2486 return CMD_SUCCESS;
8bd9d948
DS
2487}
2488
2489DEFUN (no_bgp_rr_allow_outbound_policy,
2490 no_bgp_rr_allow_outbound_policy_cmd,
2491 "no bgp route-reflector allow-outbound-policy",
2492 NO_STR
2493 "BGP specific commands\n"
2494 "Allow modifications made by out route-map\n"
2495 "on ibgp neighbors\n")
2496{
d62a17ae 2497 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2498
d62a17ae 2499 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2500 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2501 update_group_announce_rrclients(bgp);
2502 bgp_clear_star_soft_out(vty, bgp->name);
2503 }
8bd9d948 2504
d62a17ae 2505 return CMD_SUCCESS;
8bd9d948
DS
2506}
2507
f14e6fdb
DS
2508DEFUN (bgp_listen_limit,
2509 bgp_listen_limit_cmd,
9ccf14f7 2510 "bgp listen limit (1-5000)",
f14e6fdb
DS
2511 "BGP specific commands\n"
2512 "Configure BGP defaults\n"
2513 "maximum number of BGP Dynamic Neighbors that can be created\n"
2514 "Configure Dynamic Neighbors listen limit value\n")
2515{
d62a17ae 2516 VTY_DECLVAR_CONTEXT(bgp, bgp);
2517 int idx_number = 3;
2518 int listen_limit;
f14e6fdb 2519
d62a17ae 2520 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2521
d62a17ae 2522 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2523
d62a17ae 2524 return CMD_SUCCESS;
f14e6fdb
DS
2525}
2526
2527DEFUN (no_bgp_listen_limit,
2528 no_bgp_listen_limit_cmd,
838758ac 2529 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2530 "BGP specific commands\n"
2531 "Configure BGP defaults\n"
2532 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2533 "Configure Dynamic Neighbors listen limit value to default\n"
2534 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2535{
d62a17ae 2536 VTY_DECLVAR_CONTEXT(bgp, bgp);
2537 bgp_listen_limit_unset(bgp);
2538 return CMD_SUCCESS;
f14e6fdb
DS
2539}
2540
2541
20eb8864 2542/*
2543 * Check if this listen range is already configured. Check for exact
2544 * match or overlap based on input.
2545 */
d62a17ae 2546static struct peer_group *listen_range_exists(struct bgp *bgp,
2547 struct prefix *range, int exact)
2548{
2549 struct listnode *node, *nnode;
2550 struct listnode *node1, *nnode1;
2551 struct peer_group *group;
2552 struct prefix *lr;
2553 afi_t afi;
2554 int match;
2555
2556 afi = family2afi(range->family);
2557 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2558 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2559 lr)) {
2560 if (exact)
2561 match = prefix_same(range, lr);
2562 else
2563 match = (prefix_match(range, lr)
2564 || prefix_match(lr, range));
2565 if (match)
2566 return group;
2567 }
2568 }
2569
2570 return NULL;
20eb8864 2571}
2572
f14e6fdb
DS
2573DEFUN (bgp_listen_range,
2574 bgp_listen_range_cmd,
d7b9898c 2575 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 2576 "BGP specific commands\n"
d7fa34c1
QY
2577 "Configure BGP dynamic neighbors listen range\n"
2578 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2579 NEIGHBOR_ADDR_STR
2580 "Member of the peer-group\n"
2581 "Peer-group name\n")
f14e6fdb 2582{
d62a17ae 2583 VTY_DECLVAR_CONTEXT(bgp, bgp);
2584 struct prefix range;
2585 struct peer_group *group, *existing_group;
2586 afi_t afi;
2587 int ret;
2588 int idx = 0;
2589
2590 argv_find(argv, argc, "A.B.C.D/M", &idx);
2591 argv_find(argv, argc, "X:X::X:X/M", &idx);
2592 char *prefix = argv[idx]->arg;
d7b9898c 2593 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 2594 char *peergroup = argv[idx]->arg;
2595
2596 /* Convert IP prefix string to struct prefix. */
2597 ret = str2prefix(prefix, &range);
2598 if (!ret) {
2599 vty_out(vty, "%% Malformed listen range\n");
2600 return CMD_WARNING_CONFIG_FAILED;
2601 }
2602
2603 afi = family2afi(range.family);
2604
2605 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2606 vty_out(vty,
2607 "%% Malformed listen range (link-local address)\n");
2608 return CMD_WARNING_CONFIG_FAILED;
2609 }
2610
2611 apply_mask(&range);
2612
2613 /* Check if same listen range is already configured. */
2614 existing_group = listen_range_exists(bgp, &range, 1);
2615 if (existing_group) {
2616 if (strcmp(existing_group->name, peergroup) == 0)
2617 return CMD_SUCCESS;
2618 else {
2619 vty_out(vty,
2620 "%% Same listen range is attached to peer-group %s\n",
2621 existing_group->name);
2622 return CMD_WARNING_CONFIG_FAILED;
2623 }
2624 }
2625
2626 /* Check if an overlapping listen range exists. */
2627 if (listen_range_exists(bgp, &range, 0)) {
2628 vty_out(vty,
2629 "%% Listen range overlaps with existing listen range\n");
2630 return CMD_WARNING_CONFIG_FAILED;
2631 }
2632
2633 group = peer_group_lookup(bgp, peergroup);
2634 if (!group) {
2635 vty_out(vty, "%% Configure the peer-group first\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 ret = peer_group_listen_range_add(group, &range);
2640 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2641}
2642
2643DEFUN (no_bgp_listen_range,
2644 no_bgp_listen_range_cmd,
d7b9898c 2645 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 2646 NO_STR
f14e6fdb 2647 "BGP specific commands\n"
d7fa34c1
QY
2648 "Unconfigure BGP dynamic neighbors listen range\n"
2649 "Unconfigure BGP dynamic neighbors listen range\n"
2650 NEIGHBOR_ADDR_STR
2651 "Member of the peer-group\n"
2652 "Peer-group name\n")
f14e6fdb 2653{
d62a17ae 2654 VTY_DECLVAR_CONTEXT(bgp, bgp);
2655 struct prefix range;
2656 struct peer_group *group;
2657 afi_t afi;
2658 int ret;
2659 int idx = 0;
2660
2661 argv_find(argv, argc, "A.B.C.D/M", &idx);
2662 argv_find(argv, argc, "X:X::X:X/M", &idx);
2663 char *prefix = argv[idx]->arg;
2664 argv_find(argv, argc, "WORD", &idx);
2665 char *peergroup = argv[idx]->arg;
2666
2667 /* Convert IP prefix string to struct prefix. */
2668 ret = str2prefix(prefix, &range);
2669 if (!ret) {
2670 vty_out(vty, "%% Malformed listen range\n");
2671 return CMD_WARNING_CONFIG_FAILED;
2672 }
2673
2674 afi = family2afi(range.family);
2675
2676 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2677 vty_out(vty,
2678 "%% Malformed listen range (link-local address)\n");
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681
2682 apply_mask(&range);
2683
2684 group = peer_group_lookup(bgp, peergroup);
2685 if (!group) {
2686 vty_out(vty, "%% Peer-group does not exist\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689
2690 ret = peer_group_listen_range_del(group, &range);
2691 return bgp_vty_return(vty, ret);
2692}
2693
2b791107 2694void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2695{
2696 struct peer_group *group;
2697 struct listnode *node, *nnode, *rnode, *nrnode;
2698 struct prefix *range;
2699 afi_t afi;
2700 char buf[PREFIX2STR_BUFFER];
2701
2702 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2703 vty_out(vty, " bgp listen limit %d\n",
2704 bgp->dynamic_neighbors_limit);
2705
2706 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2707 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2708 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2709 nrnode, range)) {
2710 prefix2str(range, buf, sizeof(buf));
2711 vty_out(vty,
2712 " bgp listen range %s peer-group %s\n",
2713 buf, group->name);
2714 }
2715 }
2716 }
f14e6fdb
DS
2717}
2718
2719
907f92c8
DS
2720DEFUN (bgp_disable_connected_route_check,
2721 bgp_disable_connected_route_check_cmd,
2722 "bgp disable-ebgp-connected-route-check",
2723 "BGP specific commands\n"
2724 "Disable checking if nexthop is connected on ebgp sessions\n")
2725{
d62a17ae 2726 VTY_DECLVAR_CONTEXT(bgp, bgp);
2727 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2728 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2729
d62a17ae 2730 return CMD_SUCCESS;
907f92c8
DS
2731}
2732
2733DEFUN (no_bgp_disable_connected_route_check,
2734 no_bgp_disable_connected_route_check_cmd,
2735 "no bgp disable-ebgp-connected-route-check",
2736 NO_STR
2737 "BGP specific commands\n"
2738 "Disable checking if nexthop is connected on ebgp sessions\n")
2739{
d62a17ae 2740 VTY_DECLVAR_CONTEXT(bgp, bgp);
2741 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2742 bgp_clear_star_soft_in(vty, bgp->name);
2743
2744 return CMD_SUCCESS;
2745}
2746
2747
2748static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2749 const char *as_str, afi_t afi, safi_t safi)
2750{
2751 VTY_DECLVAR_CONTEXT(bgp, bgp);
2752 int ret;
2753 as_t as;
2754 int as_type = AS_SPECIFIED;
2755 union sockunion su;
2756
2757 if (as_str[0] == 'i') {
2758 as = 0;
2759 as_type = AS_INTERNAL;
2760 } else if (as_str[0] == 'e') {
2761 as = 0;
2762 as_type = AS_EXTERNAL;
2763 } else {
2764 /* Get AS number. */
2765 as = strtoul(as_str, NULL, 10);
2766 }
2767
390485fd 2768 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 2769 ret = str2sockunion(peer_str, &su);
2770 if (ret < 0) {
390485fd
DS
2771 struct peer *peer;
2772
2773 /* Check if existing interface peer */
2774 peer = peer_lookup_by_conf_if(bgp, peer_str);
2775
d62a17ae 2776 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2777 safi);
390485fd
DS
2778
2779 /* if not interface peer, check peer-group settings */
2780 if (ret < 0 && !peer) {
d62a17ae 2781 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2782 if (ret < 0) {
2783 vty_out(vty,
390485fd 2784 "%% Create the peer-group or interface first\n");
d62a17ae 2785 return CMD_WARNING_CONFIG_FAILED;
2786 }
2787 return CMD_SUCCESS;
2788 }
2789 } else {
2790 if (peer_address_self_check(bgp, &su)) {
2791 vty_out(vty,
2792 "%% Can not configure the local system as neighbor\n");
2793 return CMD_WARNING_CONFIG_FAILED;
2794 }
2795 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2796 }
2797
2798 /* This peer belongs to peer group. */
2799 switch (ret) {
2800 case BGP_ERR_PEER_GROUP_MEMBER:
2801 vty_out(vty,
faa16034 2802 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 2803 return CMD_WARNING_CONFIG_FAILED;
2804 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2805 vty_out(vty,
faa16034 2806 "%% Peer-group members must be all internal or all external\n");
d62a17ae 2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809 return bgp_vty_return(vty, ret);
718e3744 2810}
2811
f26845f9
QY
2812DEFUN (bgp_default_shutdown,
2813 bgp_default_shutdown_cmd,
2814 "[no] bgp default shutdown",
2815 NO_STR
2816 BGP_STR
2817 "Configure BGP defaults\n"
b012cbe2 2818 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2819{
2820 VTY_DECLVAR_CONTEXT(bgp, bgp);
2821 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2822 return CMD_SUCCESS;
2823}
2824
718e3744 2825DEFUN (neighbor_remote_as,
2826 neighbor_remote_as_cmd,
3a2d747c 2827 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2828 NEIGHBOR_STR
2829 NEIGHBOR_ADDR_STR2
2830 "Specify a BGP neighbor\n"
d7fa34c1 2831 AS_STR
3a2d747c
QY
2832 "Internal BGP peer\n"
2833 "External BGP peer\n")
718e3744 2834{
d62a17ae 2835 int idx_peer = 1;
2836 int idx_remote_as = 3;
2837 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2838 argv[idx_remote_as]->arg, AFI_IP,
2839 SAFI_UNICAST);
2840}
2841
2842static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2843 afi_t afi, safi_t safi, int v6only,
2844 const char *peer_group_name,
2845 const char *as_str)
2846{
2847 VTY_DECLVAR_CONTEXT(bgp, bgp);
2848 as_t as = 0;
2849 int as_type = AS_UNSPECIFIED;
2850 struct peer *peer;
2851 struct peer_group *group;
2852 int ret = 0;
2853 union sockunion su;
2854
2855 group = peer_group_lookup(bgp, conf_if);
2856
2857 if (group) {
2858 vty_out(vty, "%% Name conflict with peer-group \n");
2859 return CMD_WARNING_CONFIG_FAILED;
2860 }
2861
2862 if (as_str) {
2863 if (as_str[0] == 'i') {
2864 as_type = AS_INTERNAL;
2865 } else if (as_str[0] == 'e') {
2866 as_type = AS_EXTERNAL;
2867 } else {
2868 /* Get AS number. */
2869 as = strtoul(as_str, NULL, 10);
2870 as_type = AS_SPECIFIED;
2871 }
2872 }
2873
2874 peer = peer_lookup_by_conf_if(bgp, conf_if);
2875 if (peer) {
2876 if (as_str)
cc4d4ce8 2877 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2878 afi, safi);
2879 } else {
2880 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2881 && afi == AFI_IP && safi == SAFI_UNICAST)
2882 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2883 as_type, 0, 0, NULL);
2884 else
2885 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2886 as_type, afi, safi, NULL);
2887
2888 if (!peer) {
2889 vty_out(vty, "%% BGP failed to create peer\n");
2890 return CMD_WARNING_CONFIG_FAILED;
2891 }
2892
2893 if (v6only)
527de3dc 2894 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2895
2896 /* Request zebra to initiate IPv6 RAs on this interface. We do
2897 * this
2898 * any unnumbered peer in order to not worry about run-time
2899 * transitions
2900 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2901 * address
2902 * gets deleted later etc.)
2903 */
2904 if (peer->ifp)
2905 bgp_zebra_initiate_radv(bgp, peer);
2906 }
2907
2908 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2909 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2910 if (v6only)
527de3dc 2911 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2912 else
527de3dc 2913 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2914
2915 /* v6only flag changed. Reset bgp seesion */
2916 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2917 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2918 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2919 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2920 } else
2921 bgp_session_reset(peer);
2922 }
2923
9fb964de
PM
2924 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2925 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2926 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 2927 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 2928 }
d62a17ae 2929
2930 if (peer_group_name) {
2931 group = peer_group_lookup(bgp, peer_group_name);
2932 if (!group) {
2933 vty_out(vty, "%% Configure the peer-group first\n");
2934 return CMD_WARNING_CONFIG_FAILED;
2935 }
2936
2937 ret = peer_group_bind(bgp, &su, peer, group, &as);
2938 }
2939
2940 return bgp_vty_return(vty, ret);
a80beece
DS
2941}
2942
4c48cf63
DW
2943DEFUN (neighbor_interface_config,
2944 neighbor_interface_config_cmd,
d7b9898c 2945 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
2946 NEIGHBOR_STR
2947 "Interface name or neighbor tag\n"
31500417
DW
2948 "Enable BGP on interface\n"
2949 "Member of the peer-group\n"
16cedbb0 2950 "Peer-group name\n")
4c48cf63 2951{
d62a17ae 2952 int idx_word = 1;
2953 int idx_peer_group_word = 4;
31500417 2954
d62a17ae 2955 if (argc > idx_peer_group_word)
2956 return peer_conf_interface_get(
2957 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2958 argv[idx_peer_group_word]->arg, NULL);
2959 else
2960 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2961 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2962}
2963
4c48cf63
DW
2964DEFUN (neighbor_interface_config_v6only,
2965 neighbor_interface_config_v6only_cmd,
d7b9898c 2966 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
2967 NEIGHBOR_STR
2968 "Interface name or neighbor tag\n"
2969 "Enable BGP on interface\n"
31500417
DW
2970 "Enable BGP with v6 link-local only\n"
2971 "Member of the peer-group\n"
16cedbb0 2972 "Peer-group name\n")
4c48cf63 2973{
d62a17ae 2974 int idx_word = 1;
2975 int idx_peer_group_word = 5;
31500417 2976
d62a17ae 2977 if (argc > idx_peer_group_word)
2978 return peer_conf_interface_get(
2979 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2980 argv[idx_peer_group_word]->arg, NULL);
31500417 2981
d62a17ae 2982 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2983 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2984}
2985
a80beece 2986
b3a39dc5
DD
2987DEFUN (neighbor_interface_config_remote_as,
2988 neighbor_interface_config_remote_as_cmd,
3a2d747c 2989 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2990 NEIGHBOR_STR
2991 "Interface name or neighbor tag\n"
2992 "Enable BGP on interface\n"
3a2d747c 2993 "Specify a BGP neighbor\n"
d7fa34c1 2994 AS_STR
3a2d747c
QY
2995 "Internal BGP peer\n"
2996 "External BGP peer\n")
b3a39dc5 2997{
d62a17ae 2998 int idx_word = 1;
2999 int idx_remote_as = 4;
3000 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3001 SAFI_UNICAST, 0, NULL,
3002 argv[idx_remote_as]->arg);
b3a39dc5
DD
3003}
3004
3005DEFUN (neighbor_interface_v6only_config_remote_as,
3006 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3007 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3008 NEIGHBOR_STR
3009 "Interface name or neighbor tag\n"
3a2d747c 3010 "Enable BGP with v6 link-local only\n"
b3a39dc5 3011 "Enable BGP on interface\n"
3a2d747c 3012 "Specify a BGP neighbor\n"
d7fa34c1 3013 AS_STR
3a2d747c
QY
3014 "Internal BGP peer\n"
3015 "External BGP peer\n")
b3a39dc5 3016{
d62a17ae 3017 int idx_word = 1;
3018 int idx_remote_as = 5;
3019 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3020 SAFI_UNICAST, 1, NULL,
3021 argv[idx_remote_as]->arg);
b3a39dc5
DD
3022}
3023
718e3744 3024DEFUN (neighbor_peer_group,
3025 neighbor_peer_group_cmd,
3026 "neighbor WORD peer-group",
3027 NEIGHBOR_STR
a80beece 3028 "Interface name or neighbor tag\n"
718e3744 3029 "Configure peer-group\n")
3030{
d62a17ae 3031 VTY_DECLVAR_CONTEXT(bgp, bgp);
3032 int idx_word = 1;
3033 struct peer *peer;
3034 struct peer_group *group;
718e3744 3035
d62a17ae 3036 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3037 if (peer) {
3038 vty_out(vty, "%% Name conflict with interface: \n");
3039 return CMD_WARNING_CONFIG_FAILED;
3040 }
718e3744 3041
d62a17ae 3042 group = peer_group_get(bgp, argv[idx_word]->arg);
3043 if (!group) {
3044 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3045 return CMD_WARNING_CONFIG_FAILED;
3046 }
718e3744 3047
d62a17ae 3048 return CMD_SUCCESS;
718e3744 3049}
3050
3051DEFUN (no_neighbor,
3052 no_neighbor_cmd,
dab8cd00 3053 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3054 NO_STR
3055 NEIGHBOR_STR
3a2d747c
QY
3056 NEIGHBOR_ADDR_STR2
3057 "Specify a BGP neighbor\n"
3058 AS_STR
3059 "Internal BGP peer\n"
3060 "External BGP peer\n")
718e3744 3061{
d62a17ae 3062 VTY_DECLVAR_CONTEXT(bgp, bgp);
3063 int idx_peer = 2;
3064 int ret;
3065 union sockunion su;
3066 struct peer_group *group;
3067 struct peer *peer;
3068 struct peer *other;
3069
3070 ret = str2sockunion(argv[idx_peer]->arg, &su);
3071 if (ret < 0) {
3072 /* look up for neighbor by interface name config. */
3073 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3074 if (peer) {
3075 /* Request zebra to terminate IPv6 RAs on this
3076 * interface. */
3077 if (peer->ifp)
3078 bgp_zebra_terminate_radv(peer->bgp, peer);
3079 peer_delete(peer);
3080 return CMD_SUCCESS;
3081 }
f14e6fdb 3082
d62a17ae 3083 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3084 if (group)
3085 peer_group_delete(group);
3086 else {
3087 vty_out(vty, "%% Create the peer-group first\n");
3088 return CMD_WARNING_CONFIG_FAILED;
3089 }
3090 } else {
3091 peer = peer_lookup(bgp, &su);
3092 if (peer) {
3093 if (peer_dynamic_neighbor(peer)) {
3094 vty_out(vty,
3095 "%% Operation not allowed on a dynamic neighbor\n");
3096 return CMD_WARNING_CONFIG_FAILED;
3097 }
3098
3099 other = peer->doppelganger;
3100 peer_delete(peer);
3101 if (other && other->status != Deleted)
3102 peer_delete(other);
3103 }
1ff9a340 3104 }
718e3744 3105
d62a17ae 3106 return CMD_SUCCESS;
718e3744 3107}
3108
a80beece
DS
3109DEFUN (no_neighbor_interface_config,
3110 no_neighbor_interface_config_cmd,
d7b9898c 3111 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3112 NO_STR
3113 NEIGHBOR_STR
3114 "Interface name\n"
31500417
DW
3115 "Configure BGP on interface\n"
3116 "Enable BGP with v6 link-local only\n"
3117 "Member of the peer-group\n"
16cedbb0 3118 "Peer-group name\n"
3a2d747c
QY
3119 "Specify a BGP neighbor\n"
3120 AS_STR
3121 "Internal BGP peer\n"
3122 "External BGP peer\n")
a80beece 3123{
d62a17ae 3124 VTY_DECLVAR_CONTEXT(bgp, bgp);
3125 int idx_word = 2;
3126 struct peer *peer;
3127
3128 /* look up for neighbor by interface name config. */
3129 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3130 if (peer) {
3131 /* Request zebra to terminate IPv6 RAs on this interface. */
3132 if (peer->ifp)
3133 bgp_zebra_terminate_radv(peer->bgp, peer);
3134 peer_delete(peer);
3135 } else {
3136 vty_out(vty, "%% Create the bgp interface first\n");
3137 return CMD_WARNING_CONFIG_FAILED;
3138 }
3139 return CMD_SUCCESS;
a80beece
DS
3140}
3141
718e3744 3142DEFUN (no_neighbor_peer_group,
3143 no_neighbor_peer_group_cmd,
3144 "no neighbor WORD peer-group",
3145 NO_STR
3146 NEIGHBOR_STR
3147 "Neighbor tag\n"
3148 "Configure peer-group\n")
3149{
d62a17ae 3150 VTY_DECLVAR_CONTEXT(bgp, bgp);
3151 int idx_word = 2;
3152 struct peer_group *group;
718e3744 3153
d62a17ae 3154 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3155 if (group)
3156 peer_group_delete(group);
3157 else {
3158 vty_out(vty, "%% Create the peer-group first\n");
3159 return CMD_WARNING_CONFIG_FAILED;
3160 }
3161 return CMD_SUCCESS;
718e3744 3162}
3163
a80beece
DS
3164DEFUN (no_neighbor_interface_peer_group_remote_as,
3165 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3166 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3167 NO_STR
3168 NEIGHBOR_STR
a80beece 3169 "Interface name or neighbor tag\n"
718e3744 3170 "Specify a BGP neighbor\n"
3a2d747c
QY
3171 AS_STR
3172 "Internal BGP peer\n"
3173 "External BGP peer\n")
718e3744 3174{
d62a17ae 3175 VTY_DECLVAR_CONTEXT(bgp, bgp);
3176 int idx_word = 2;
3177 struct peer_group *group;
3178 struct peer *peer;
3179
3180 /* look up for neighbor by interface name config. */
3181 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3182 if (peer) {
390485fd 3183 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3184 return CMD_SUCCESS;
3185 }
3186
3187 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3188 if (group)
3189 peer_group_remote_as_delete(group);
3190 else {
3191 vty_out(vty, "%% Create the peer-group or interface first\n");
3192 return CMD_WARNING_CONFIG_FAILED;
3193 }
3194 return CMD_SUCCESS;
718e3744 3195}
6b0655a2 3196
718e3744 3197DEFUN (neighbor_local_as,
3198 neighbor_local_as_cmd,
9ccf14f7 3199 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3200 NEIGHBOR_STR
3201 NEIGHBOR_ADDR_STR2
3202 "Specify a local-as number\n"
3203 "AS number used as local AS\n")
3204{
d62a17ae 3205 int idx_peer = 1;
3206 int idx_number = 3;
3207 struct peer *peer;
3208 int ret;
3209 as_t as;
718e3744 3210
d62a17ae 3211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3212 if (!peer)
3213 return CMD_WARNING_CONFIG_FAILED;
718e3744 3214
d62a17ae 3215 as = strtoul(argv[idx_number]->arg, NULL, 10);
3216 ret = peer_local_as_set(peer, as, 0, 0);
3217 return bgp_vty_return(vty, ret);
718e3744 3218}
3219
3220DEFUN (neighbor_local_as_no_prepend,
3221 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3222 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3223 NEIGHBOR_STR
3224 NEIGHBOR_ADDR_STR2
3225 "Specify a local-as number\n"
3226 "AS number used as local AS\n"
3227 "Do not prepend local-as to updates from ebgp peers\n")
3228{
d62a17ae 3229 int idx_peer = 1;
3230 int idx_number = 3;
3231 struct peer *peer;
3232 int ret;
3233 as_t as;
718e3744 3234
d62a17ae 3235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3236 if (!peer)
3237 return CMD_WARNING_CONFIG_FAILED;
718e3744 3238
d62a17ae 3239 as = strtoul(argv[idx_number]->arg, NULL, 10);
3240 ret = peer_local_as_set(peer, as, 1, 0);
3241 return bgp_vty_return(vty, ret);
718e3744 3242}
3243
9d3f9705
AC
3244DEFUN (neighbor_local_as_no_prepend_replace_as,
3245 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3246 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 "Specify a local-as number\n"
3250 "AS number used as local AS\n"
3251 "Do not prepend local-as to updates from ebgp peers\n"
3252 "Do not prepend local-as to updates from ibgp peers\n")
3253{
d62a17ae 3254 int idx_peer = 1;
3255 int idx_number = 3;
3256 struct peer *peer;
3257 int ret;
3258 as_t as;
9d3f9705 3259
d62a17ae 3260 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3261 if (!peer)
3262 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3263
d62a17ae 3264 as = strtoul(argv[idx_number]->arg, NULL, 10);
3265 ret = peer_local_as_set(peer, as, 1, 1);
3266 return bgp_vty_return(vty, ret);
9d3f9705
AC
3267}
3268
718e3744 3269DEFUN (no_neighbor_local_as,
3270 no_neighbor_local_as_cmd,
a636c635 3271 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3272 NO_STR
3273 NEIGHBOR_STR
3274 NEIGHBOR_ADDR_STR2
a636c635
DW
3275 "Specify a local-as number\n"
3276 "AS number used as local AS\n"
3277 "Do not prepend local-as to updates from ebgp peers\n"
3278 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3279{
d62a17ae 3280 int idx_peer = 2;
3281 struct peer *peer;
3282 int ret;
718e3744 3283
d62a17ae 3284 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3285 if (!peer)
3286 return CMD_WARNING_CONFIG_FAILED;
718e3744 3287
d62a17ae 3288 ret = peer_local_as_unset(peer);
3289 return bgp_vty_return(vty, ret);
718e3744 3290}
3291
718e3744 3292
3f9c7369
DS
3293DEFUN (neighbor_solo,
3294 neighbor_solo_cmd,
9ccf14f7 3295 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 "Solo peer - part of its own update group\n")
3299{
d62a17ae 3300 int idx_peer = 1;
3301 struct peer *peer;
3302 int ret;
3f9c7369 3303
d62a17ae 3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3307
d62a17ae 3308 ret = update_group_adjust_soloness(peer, 1);
3309 return bgp_vty_return(vty, ret);
3f9c7369
DS
3310}
3311
3312DEFUN (no_neighbor_solo,
3313 no_neighbor_solo_cmd,
9ccf14f7 3314 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3315 NO_STR
3316 NEIGHBOR_STR
3317 NEIGHBOR_ADDR_STR2
3318 "Solo peer - part of its own update group\n")
3319{
d62a17ae 3320 int idx_peer = 2;
3321 struct peer *peer;
3322 int ret;
3f9c7369 3323
d62a17ae 3324 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3325 if (!peer)
3326 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3327
d62a17ae 3328 ret = update_group_adjust_soloness(peer, 0);
3329 return bgp_vty_return(vty, ret);
3f9c7369
DS
3330}
3331
0df7c91f
PJ
3332DEFUN (neighbor_password,
3333 neighbor_password_cmd,
9ccf14f7 3334 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3335 NEIGHBOR_STR
3336 NEIGHBOR_ADDR_STR2
3337 "Set a password\n"
3338 "The password\n")
3339{
d62a17ae 3340 int idx_peer = 1;
3341 int idx_line = 3;
3342 struct peer *peer;
3343 int ret;
0df7c91f 3344
d62a17ae 3345 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3346 if (!peer)
3347 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3348
d62a17ae 3349 ret = peer_password_set(peer, argv[idx_line]->arg);
3350 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3351}
3352
3353DEFUN (no_neighbor_password,
3354 no_neighbor_password_cmd,
a636c635 3355 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3356 NO_STR
3357 NEIGHBOR_STR
3358 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3359 "Set a password\n"
3360 "The password\n")
0df7c91f 3361{
d62a17ae 3362 int idx_peer = 2;
3363 struct peer *peer;
3364 int ret;
0df7c91f 3365
d62a17ae 3366 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3367 if (!peer)
3368 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3369
d62a17ae 3370 ret = peer_password_unset(peer);
3371 return bgp_vty_return(vty, ret);
0df7c91f 3372}
6b0655a2 3373
718e3744 3374DEFUN (neighbor_activate,
3375 neighbor_activate_cmd,
9ccf14f7 3376 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3377 NEIGHBOR_STR
3378 NEIGHBOR_ADDR_STR2
3379 "Enable the Address Family for this Neighbor\n")
3380{
d62a17ae 3381 int idx_peer = 1;
3382 int ret;
3383 struct peer *peer;
718e3744 3384
d62a17ae 3385 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
718e3744 3388
d62a17ae 3389 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3390 return bgp_vty_return(vty, ret);
718e3744 3391}
3392
d62a17ae 3393ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3394 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3396 "Enable the Address Family for this Neighbor\n")
596c17ba 3397
718e3744 3398DEFUN (no_neighbor_activate,
3399 no_neighbor_activate_cmd,
9ccf14f7 3400 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3401 NO_STR
3402 NEIGHBOR_STR
3403 NEIGHBOR_ADDR_STR2
3404 "Enable the Address Family for this Neighbor\n")
3405{
d62a17ae 3406 int idx_peer = 2;
3407 int ret;
3408 struct peer *peer;
718e3744 3409
d62a17ae 3410 /* Lookup peer. */
3411 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3412 if (!peer)
3413 return CMD_WARNING_CONFIG_FAILED;
718e3744 3414
d62a17ae 3415 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3416 return bgp_vty_return(vty, ret);
718e3744 3417}
6b0655a2 3418
d62a17ae 3419ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3420 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3421 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3422 "Enable the Address Family for this Neighbor\n")
596c17ba 3423
718e3744 3424DEFUN (neighbor_set_peer_group,
3425 neighbor_set_peer_group_cmd,
d7b9898c 3426 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3427 NEIGHBOR_STR
a80beece 3428 NEIGHBOR_ADDR_STR2
718e3744 3429 "Member of the peer-group\n"
16cedbb0 3430 "Peer-group name\n")
718e3744 3431{
d62a17ae 3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 int idx_peer = 1;
3434 int idx_word = 3;
3435 int ret;
3436 as_t as;
3437 union sockunion su;
3438 struct peer *peer;
3439 struct peer_group *group;
3440
d62a17ae 3441 ret = str2sockunion(argv[idx_peer]->arg, &su);
3442 if (ret < 0) {
3443 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3444 if (!peer) {
3445 vty_out(vty, "%% Malformed address or name: %s\n",
3446 argv[idx_peer]->arg);
3447 return CMD_WARNING_CONFIG_FAILED;
3448 }
3449 } else {
3450 if (peer_address_self_check(bgp, &su)) {
3451 vty_out(vty,
3452 "%% Can not configure the local system as neighbor\n");
3453 return CMD_WARNING_CONFIG_FAILED;
3454 }
3455
3456 /* Disallow for dynamic neighbor. */
3457 peer = peer_lookup(bgp, &su);
3458 if (peer && peer_dynamic_neighbor(peer)) {
3459 vty_out(vty,
3460 "%% Operation not allowed on a dynamic neighbor\n");
3461 return CMD_WARNING_CONFIG_FAILED;
3462 }
3463 }
3464
3465 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3466 if (!group) {
3467 vty_out(vty, "%% Configure the peer-group first\n");
3468 return CMD_WARNING_CONFIG_FAILED;
3469 }
3470
3471 ret = peer_group_bind(bgp, &su, peer, group, &as);
3472
3473 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3474 vty_out(vty,
3475 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3476 as);
3477 return CMD_WARNING_CONFIG_FAILED;
3478 }
3479
3480 return bgp_vty_return(vty, ret);
3481}
3482
3483ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 3484 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3485 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3486 "Member of the peer-group\n"
3487 "Peer-group name\n")
596c17ba 3488
718e3744 3489DEFUN (no_neighbor_set_peer_group,
3490 no_neighbor_set_peer_group_cmd,
d7b9898c 3491 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3492 NO_STR
3493 NEIGHBOR_STR
a80beece 3494 NEIGHBOR_ADDR_STR2
718e3744 3495 "Member of the peer-group\n"
16cedbb0 3496 "Peer-group name\n")
718e3744 3497{
d62a17ae 3498 VTY_DECLVAR_CONTEXT(bgp, bgp);
3499 int idx_peer = 2;
3500 int idx_word = 4;
3501 int ret;
3502 struct peer *peer;
3503 struct peer_group *group;
3504
3505 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3506 if (!peer)
3507 return CMD_WARNING_CONFIG_FAILED;
3508
3509 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3510 if (!group) {
3511 vty_out(vty, "%% Configure the peer-group first\n");
3512 return CMD_WARNING_CONFIG_FAILED;
3513 }
718e3744 3514
827ed707 3515 ret = peer_delete(peer);
718e3744 3516
d62a17ae 3517 return bgp_vty_return(vty, ret);
718e3744 3518}
6b0655a2 3519
d62a17ae 3520ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 3521 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3523 "Member of the peer-group\n"
3524 "Peer-group name\n")
596c17ba 3525
d62a17ae 3526static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3527 uint32_t flag, int set)
718e3744 3528{
d62a17ae 3529 int ret;
3530 struct peer *peer;
718e3744 3531
d62a17ae 3532 peer = peer_and_group_lookup_vty(vty, ip_str);
3533 if (!peer)
3534 return CMD_WARNING_CONFIG_FAILED;
718e3744 3535
7ebe625c
QY
3536 /*
3537 * If 'neighbor <interface>', then this is for directly connected peers,
3538 * we should not accept disable-connected-check.
3539 */
3540 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3541 vty_out(vty,
3542 "%s is directly connected peer, cannot accept disable-"
3543 "connected-check\n",
3544 ip_str);
3545 return CMD_WARNING_CONFIG_FAILED;
3546 }
3547
d62a17ae 3548 if (!set && flag == PEER_FLAG_SHUTDOWN)
3549 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3550
d62a17ae 3551 if (set)
3552 ret = peer_flag_set(peer, flag);
3553 else
3554 ret = peer_flag_unset(peer, flag);
718e3744 3555
d62a17ae 3556 return bgp_vty_return(vty, ret);
718e3744 3557}
3558
47cbc09b 3559static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3560{
d62a17ae 3561 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3562}
3563
d62a17ae 3564static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3565 uint32_t flag)
718e3744 3566{
d62a17ae 3567 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3568}
3569
3570/* neighbor passive. */
3571DEFUN (neighbor_passive,
3572 neighbor_passive_cmd,
9ccf14f7 3573 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3574 NEIGHBOR_STR
3575 NEIGHBOR_ADDR_STR2
3576 "Don't send open messages to this neighbor\n")
3577{
d62a17ae 3578 int idx_peer = 1;
3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3580}
3581
3582DEFUN (no_neighbor_passive,
3583 no_neighbor_passive_cmd,
9ccf14f7 3584 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3585 NO_STR
3586 NEIGHBOR_STR
3587 NEIGHBOR_ADDR_STR2
3588 "Don't send open messages to this neighbor\n")
3589{
d62a17ae 3590 int idx_peer = 2;
3591 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3592}
6b0655a2 3593
718e3744 3594/* neighbor shutdown. */
73d70fa6
DL
3595DEFUN (neighbor_shutdown_msg,
3596 neighbor_shutdown_msg_cmd,
3597 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3598 NEIGHBOR_STR
3599 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3600 "Administratively shut down this neighbor\n"
3601 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3602 "Shutdown message\n")
718e3744 3603{
d62a17ae 3604 int idx_peer = 1;
73d70fa6 3605
d62a17ae 3606 if (argc >= 5) {
3607 struct peer *peer =
3608 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3609 char *message;
73d70fa6 3610
d62a17ae 3611 if (!peer)
3612 return CMD_WARNING_CONFIG_FAILED;
3613 message = argv_concat(argv, argc, 4);
3614 peer_tx_shutdown_message_set(peer, message);
3615 XFREE(MTYPE_TMP, message);
3616 }
73d70fa6 3617
d62a17ae 3618 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3619}
3620
d62a17ae 3621ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3622 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3623 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3624 "Administratively shut down this neighbor\n")
73d70fa6
DL
3625
3626DEFUN (no_neighbor_shutdown_msg,
3627 no_neighbor_shutdown_msg_cmd,
3628 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3629 NO_STR
3630 NEIGHBOR_STR
3631 NEIGHBOR_ADDR_STR2
3632 "Administratively shut down this neighbor\n"
3633 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3634 "Shutdown message\n")
718e3744 3635{
d62a17ae 3636 int idx_peer = 2;
73d70fa6 3637
d62a17ae 3638 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3639 PEER_FLAG_SHUTDOWN);
718e3744 3640}
6b0655a2 3641
d62a17ae 3642ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3643 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3644 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3645 "Administratively shut down this neighbor\n")
73d70fa6 3646
718e3744 3647/* neighbor capability dynamic. */
3648DEFUN (neighbor_capability_dynamic,
3649 neighbor_capability_dynamic_cmd,
9ccf14f7 3650 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3651 NEIGHBOR_STR
3652 NEIGHBOR_ADDR_STR2
3653 "Advertise capability to the peer\n"
3654 "Advertise dynamic capability to this neighbor\n")
3655{
d62a17ae 3656 int idx_peer = 1;
3657 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3658 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3659}
3660
3661DEFUN (no_neighbor_capability_dynamic,
3662 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3663 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3664 NO_STR
3665 NEIGHBOR_STR
3666 NEIGHBOR_ADDR_STR2
3667 "Advertise capability to the peer\n"
3668 "Advertise dynamic capability to this neighbor\n")
3669{
d62a17ae 3670 int idx_peer = 2;
3671 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3672 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3673}
6b0655a2 3674
718e3744 3675/* neighbor dont-capability-negotiate */
3676DEFUN (neighbor_dont_capability_negotiate,
3677 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3678 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3679 NEIGHBOR_STR
3680 NEIGHBOR_ADDR_STR2
3681 "Do not perform capability negotiation\n")
3682{
d62a17ae 3683 int idx_peer = 1;
3684 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3685 PEER_FLAG_DONT_CAPABILITY);
718e3744 3686}
3687
3688DEFUN (no_neighbor_dont_capability_negotiate,
3689 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3691 NO_STR
3692 NEIGHBOR_STR
3693 NEIGHBOR_ADDR_STR2
3694 "Do not perform capability negotiation\n")
3695{
d62a17ae 3696 int idx_peer = 2;
3697 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3698 PEER_FLAG_DONT_CAPABILITY);
718e3744 3699}
6b0655a2 3700
8a92a8a0
DS
3701/* neighbor capability extended next hop encoding */
3702DEFUN (neighbor_capability_enhe,
3703 neighbor_capability_enhe_cmd,
9ccf14f7 3704 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3705 NEIGHBOR_STR
3706 NEIGHBOR_ADDR_STR2
3707 "Advertise capability to the peer\n"
3708 "Advertise extended next-hop capability to the peer\n")
3709{
d62a17ae 3710 int idx_peer = 1;
3711 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3712 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3713}
3714
3715DEFUN (no_neighbor_capability_enhe,
3716 no_neighbor_capability_enhe_cmd,
9ccf14f7 3717 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3718 NO_STR
3719 NEIGHBOR_STR
3720 NEIGHBOR_ADDR_STR2
3721 "Advertise capability to the peer\n"
3722 "Advertise extended next-hop capability to the peer\n")
3723{
d62a17ae 3724 int idx_peer = 2;
3725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3726 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3727}
3728
d62a17ae 3729static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3730 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3731 int set)
718e3744 3732{
d62a17ae 3733 int ret;
3734 struct peer *peer;
718e3744 3735
d62a17ae 3736 peer = peer_and_group_lookup_vty(vty, peer_str);
3737 if (!peer)
3738 return CMD_WARNING_CONFIG_FAILED;
718e3744 3739
d62a17ae 3740 if (set)
3741 ret = peer_af_flag_set(peer, afi, safi, flag);
3742 else
3743 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3744
d62a17ae 3745 return bgp_vty_return(vty, ret);
718e3744 3746}
3747
d62a17ae 3748static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3749 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3750{
d62a17ae 3751 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3752}
3753
d62a17ae 3754static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3755 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3756{
d62a17ae 3757 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3758}
6b0655a2 3759
718e3744 3760/* neighbor capability orf prefix-list. */
3761DEFUN (neighbor_capability_orf_prefix,
3762 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3763 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3764 NEIGHBOR_STR
3765 NEIGHBOR_ADDR_STR2
3766 "Advertise capability to the peer\n"
3767 "Advertise ORF capability to the peer\n"
3768 "Advertise prefixlist ORF capability to this neighbor\n"
3769 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3770 "Capability to RECEIVE the ORF from this neighbor\n"
3771 "Capability to SEND the ORF to this neighbor\n")
3772{
d62a17ae 3773 int idx_peer = 1;
3774 int idx_send_recv = 5;
d7c0a89a 3775 uint16_t flag = 0;
d62a17ae 3776
3777 if (strmatch(argv[idx_send_recv]->text, "send"))
3778 flag = PEER_FLAG_ORF_PREFIX_SM;
3779 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3780 flag = PEER_FLAG_ORF_PREFIX_RM;
3781 else if (strmatch(argv[idx_send_recv]->text, "both"))
3782 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3783 else {
3784 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3785 return CMD_WARNING_CONFIG_FAILED;
3786 }
3787
3788 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3789 bgp_node_safi(vty), flag);
3790}
3791
3792ALIAS_HIDDEN(
3793 neighbor_capability_orf_prefix,
3794 neighbor_capability_orf_prefix_hidden_cmd,
3795 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise ORF capability to the peer\n"
3799 "Advertise prefixlist ORF capability to this neighbor\n"
3800 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3801 "Capability to RECEIVE the ORF from this neighbor\n"
3802 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3803
718e3744 3804DEFUN (no_neighbor_capability_orf_prefix,
3805 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3806 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3807 NO_STR
3808 NEIGHBOR_STR
3809 NEIGHBOR_ADDR_STR2
3810 "Advertise capability to the peer\n"
3811 "Advertise ORF capability to the peer\n"
3812 "Advertise prefixlist ORF capability to this neighbor\n"
3813 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3814 "Capability to RECEIVE the ORF from this neighbor\n"
3815 "Capability to SEND the ORF to this neighbor\n")
3816{
d62a17ae 3817 int idx_peer = 2;
3818 int idx_send_recv = 6;
d7c0a89a 3819 uint16_t flag = 0;
d62a17ae 3820
3821 if (strmatch(argv[idx_send_recv]->text, "send"))
3822 flag = PEER_FLAG_ORF_PREFIX_SM;
3823 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3824 flag = PEER_FLAG_ORF_PREFIX_RM;
3825 else if (strmatch(argv[idx_send_recv]->text, "both"))
3826 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3827 else {
3828 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3829 return CMD_WARNING_CONFIG_FAILED;
3830 }
3831
3832 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3833 bgp_node_afi(vty), bgp_node_safi(vty),
3834 flag);
3835}
3836
3837ALIAS_HIDDEN(
3838 no_neighbor_capability_orf_prefix,
3839 no_neighbor_capability_orf_prefix_hidden_cmd,
3840 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3841 NO_STR NEIGHBOR_STR 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")
596c17ba 3848
718e3744 3849/* neighbor next-hop-self. */
3850DEFUN (neighbor_nexthop_self,
3851 neighbor_nexthop_self_cmd,
9ccf14f7 3852 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3853 NEIGHBOR_STR
3854 NEIGHBOR_ADDR_STR2
a538debe 3855 "Disable the next hop calculation for this neighbor\n")
718e3744 3856{
d62a17ae 3857 int idx_peer = 1;
3858 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3859 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3860}
9e7a53c1 3861
d62a17ae 3862ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3863 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3865 "Disable the next hop calculation for this neighbor\n")
596c17ba 3866
a538debe
DS
3867/* neighbor next-hop-self. */
3868DEFUN (neighbor_nexthop_self_force,
3869 neighbor_nexthop_self_force_cmd,
9ccf14f7 3870 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3871 NEIGHBOR_STR
3872 NEIGHBOR_ADDR_STR2
3873 "Disable the next hop calculation for this neighbor\n"
3874 "Set the next hop to self for reflected routes\n")
3875{
d62a17ae 3876 int idx_peer = 1;
3877 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3878 bgp_node_safi(vty),
3879 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3880}
3881
d62a17ae 3882ALIAS_HIDDEN(neighbor_nexthop_self_force,
3883 neighbor_nexthop_self_force_hidden_cmd,
3884 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3886 "Disable the next hop calculation for this neighbor\n"
3887 "Set the next hop to self for reflected routes\n")
596c17ba 3888
1bc4e531
DA
3889ALIAS_HIDDEN(neighbor_nexthop_self_force,
3890 neighbor_nexthop_self_all_hidden_cmd,
3891 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3893 "Disable the next hop calculation for this neighbor\n"
3894 "Set the next hop to self for reflected routes\n")
3895
718e3744 3896DEFUN (no_neighbor_nexthop_self,
3897 no_neighbor_nexthop_self_cmd,
9ccf14f7 3898 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3899 NO_STR
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
a538debe 3902 "Disable the next hop calculation for this neighbor\n")
718e3744 3903{
d62a17ae 3904 int idx_peer = 2;
3905 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3906 bgp_node_afi(vty), bgp_node_safi(vty),
3907 PEER_FLAG_NEXTHOP_SELF);
718e3744 3908}
6b0655a2 3909
d62a17ae 3910ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Disable the next hop calculation for this neighbor\n")
596c17ba 3914
88b8ed8d 3915DEFUN (no_neighbor_nexthop_self_force,
a538debe 3916 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3917 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3918 NO_STR
3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Disable the next hop calculation for this neighbor\n"
3922 "Set the next hop to self for reflected routes\n")
88b8ed8d 3923{
d62a17ae 3924 int idx_peer = 2;
3925 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3926 bgp_node_afi(vty), bgp_node_safi(vty),
3927 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3928}
a538debe 3929
d62a17ae 3930ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3931 no_neighbor_nexthop_self_force_hidden_cmd,
3932 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3933 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3934 "Disable the next hop calculation for this neighbor\n"
3935 "Set the next hop to self for reflected routes\n")
596c17ba 3936
1bc4e531
DA
3937ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3938 no_neighbor_nexthop_self_all_hidden_cmd,
3939 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3940 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n"
3942 "Set the next hop to self for reflected routes\n")
3943
c7122e14
DS
3944/* neighbor as-override */
3945DEFUN (neighbor_as_override,
3946 neighbor_as_override_cmd,
9ccf14f7 3947 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3948 NEIGHBOR_STR
3949 NEIGHBOR_ADDR_STR2
3950 "Override ASNs in outbound updates if aspath equals remote-as\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), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3955}
3956
d62a17ae 3957ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3958 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3959 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3960 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3961
c7122e14
DS
3962DEFUN (no_neighbor_as_override,
3963 no_neighbor_as_override_cmd,
9ccf14f7 3964 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3965 NO_STR
3966 NEIGHBOR_STR
3967 NEIGHBOR_ADDR_STR2
3968 "Override ASNs in outbound updates if aspath equals remote-as\n")
3969{
d62a17ae 3970 int idx_peer = 2;
3971 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3972 bgp_node_afi(vty), bgp_node_safi(vty),
3973 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3974}
3975
d62a17ae 3976ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3977 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3978 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3979 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3980
718e3744 3981/* neighbor remove-private-AS. */
3982DEFUN (neighbor_remove_private_as,
3983 neighbor_remove_private_as_cmd,
9ccf14f7 3984 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3985 NEIGHBOR_STR
3986 NEIGHBOR_ADDR_STR2
5000f21c 3987 "Remove private ASNs in outbound updates\n")
718e3744 3988{
d62a17ae 3989 int idx_peer = 1;
3990 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3991 bgp_node_safi(vty),
3992 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3993}
3994
d62a17ae 3995ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3998 "Remove private ASNs in outbound updates\n")
596c17ba 3999
5000f21c
DS
4000DEFUN (neighbor_remove_private_as_all,
4001 neighbor_remove_private_as_all_cmd,
9ccf14f7 4002 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4003 NEIGHBOR_STR
4004 NEIGHBOR_ADDR_STR2
4005 "Remove private ASNs in outbound updates\n"
efd7904e 4006 "Apply to all AS numbers\n")
5000f21c 4007{
d62a17ae 4008 int idx_peer = 1;
4009 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4010 bgp_node_safi(vty),
4011 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4012}
4013
d62a17ae 4014ALIAS_HIDDEN(neighbor_remove_private_as_all,
4015 neighbor_remove_private_as_all_hidden_cmd,
4016 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers")
596c17ba 4020
5000f21c
DS
4021DEFUN (neighbor_remove_private_as_replace_as,
4022 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4023 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Remove private ASNs in outbound updates\n"
4027 "Replace private ASNs with our ASN in outbound updates\n")
4028{
d62a17ae 4029 int idx_peer = 1;
4030 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4031 bgp_node_safi(vty),
4032 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4033}
4034
d62a17ae 4035ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4036 neighbor_remove_private_as_replace_as_hidden_cmd,
4037 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
4040 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4041
5000f21c
DS
4042DEFUN (neighbor_remove_private_as_all_replace_as,
4043 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4044 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
16cedbb0 4048 "Apply to all AS numbers\n"
5000f21c
DS
4049 "Replace private ASNs with our ASN in outbound updates\n")
4050{
d62a17ae 4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4055}
4056
d62a17ae 4057ALIAS_HIDDEN(
4058 neighbor_remove_private_as_all_replace_as,
4059 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4060 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n"
4064 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4065
718e3744 4066DEFUN (no_neighbor_remove_private_as,
4067 no_neighbor_remove_private_as_cmd,
9ccf14f7 4068 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4069 NO_STR
4070 NEIGHBOR_STR
4071 NEIGHBOR_ADDR_STR2
5000f21c 4072 "Remove private ASNs in outbound updates\n")
718e3744 4073{
d62a17ae 4074 int idx_peer = 2;
4075 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4076 bgp_node_afi(vty), bgp_node_safi(vty),
4077 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4078}
6b0655a2 4079
d62a17ae 4080ALIAS_HIDDEN(no_neighbor_remove_private_as,
4081 no_neighbor_remove_private_as_hidden_cmd,
4082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4083 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Remove private ASNs in outbound updates\n")
596c17ba 4085
88b8ed8d 4086DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4087 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Remove private ASNs in outbound updates\n"
16cedbb0 4093 "Apply to all AS numbers\n")
88b8ed8d 4094{
d62a17ae 4095 int idx_peer = 2;
4096 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4097 bgp_node_afi(vty), bgp_node_safi(vty),
4098 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4099}
5000f21c 4100
d62a17ae 4101ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4102 no_neighbor_remove_private_as_all_hidden_cmd,
4103 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4104 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Remove private ASNs in outbound updates\n"
4106 "Apply to all AS numbers\n")
596c17ba 4107
88b8ed8d 4108DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4109 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4110 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4111 NO_STR
4112 NEIGHBOR_STR
4113 NEIGHBOR_ADDR_STR2
4114 "Remove private ASNs in outbound updates\n"
4115 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4116{
d62a17ae 4117 int idx_peer = 2;
4118 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4119 bgp_node_afi(vty), bgp_node_safi(vty),
4120 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4121}
5000f21c 4122
d62a17ae 4123ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4124 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n"
4128 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4129
88b8ed8d 4130DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4131 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4132 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4133 NO_STR
4134 NEIGHBOR_STR
4135 NEIGHBOR_ADDR_STR2
4136 "Remove private ASNs in outbound updates\n"
16cedbb0 4137 "Apply to all AS numbers\n"
5000f21c 4138 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4139{
d62a17ae 4140 int idx_peer = 2;
4141 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4142 bgp_node_afi(vty), bgp_node_safi(vty),
4143 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4144}
5000f21c 4145
d62a17ae 4146ALIAS_HIDDEN(
4147 no_neighbor_remove_private_as_all_replace_as,
4148 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4149 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4150 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4151 "Remove private ASNs in outbound updates\n"
4152 "Apply to all AS numbers\n"
4153 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4154
5000f21c 4155
718e3744 4156/* neighbor send-community. */
4157DEFUN (neighbor_send_community,
4158 neighbor_send_community_cmd,
9ccf14f7 4159 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4160 NEIGHBOR_STR
4161 NEIGHBOR_ADDR_STR2
4162 "Send Community attribute to this neighbor\n")
4163{
d62a17ae 4164 int idx_peer = 1;
27c05d4d 4165
d62a17ae 4166 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4167 bgp_node_safi(vty),
4168 PEER_FLAG_SEND_COMMUNITY);
718e3744 4169}
4170
d62a17ae 4171ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4172 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4174 "Send Community attribute to this neighbor\n")
596c17ba 4175
718e3744 4176DEFUN (no_neighbor_send_community,
4177 no_neighbor_send_community_cmd,
9ccf14f7 4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4179 NO_STR
4180 NEIGHBOR_STR
4181 NEIGHBOR_ADDR_STR2
4182 "Send Community attribute to this neighbor\n")
4183{
d62a17ae 4184 int idx_peer = 2;
27c05d4d 4185
d62a17ae 4186 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4187 bgp_node_afi(vty), bgp_node_safi(vty),
4188 PEER_FLAG_SEND_COMMUNITY);
718e3744 4189}
6b0655a2 4190
d62a17ae 4191ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4192 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4193 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4194 "Send Community attribute to this neighbor\n")
596c17ba 4195
718e3744 4196/* neighbor send-community extended. */
4197DEFUN (neighbor_send_community_type,
4198 neighbor_send_community_type_cmd,
57d187bc 4199 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4200 NEIGHBOR_STR
4201 NEIGHBOR_ADDR_STR2
4202 "Send Community attribute to this neighbor\n"
4203 "Send Standard and Extended Community attributes\n"
57d187bc 4204 "Send Standard, Large and Extended Community attributes\n"
718e3744 4205 "Send Extended Community attributes\n"
57d187bc
JS
4206 "Send Standard Community attributes\n"
4207 "Send Large Community attributes\n")
718e3744 4208{
27c05d4d 4209 int idx_peer = 1;
d7c0a89a 4210 uint32_t flag = 0;
27c05d4d 4211 const char *type = argv[argc - 1]->text;
d62a17ae 4212
27c05d4d 4213 if (strmatch(type, "standard")) {
d62a17ae 4214 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4215 } else if (strmatch(type, "extended")) {
d62a17ae 4216 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4217 } else if (strmatch(type, "large")) {
d62a17ae 4218 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4219 } else if (strmatch(type, "both")) {
d62a17ae 4220 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4221 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4222 } else { /* if (strmatch(type, "all")) */
d62a17ae 4223 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4224 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4225 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4226 }
4227
27c05d4d 4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4229 bgp_node_safi(vty), flag);
4230}
4231
4232ALIAS_HIDDEN(
4233 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Send Community attribute to this neighbor\n"
4237 "Send Standard and Extended Community attributes\n"
4238 "Send Standard, Large and Extended Community attributes\n"
4239 "Send Extended Community attributes\n"
4240 "Send Standard Community attributes\n"
4241 "Send Large Community attributes\n")
596c17ba 4242
718e3744 4243DEFUN (no_neighbor_send_community_type,
4244 no_neighbor_send_community_type_cmd,
57d187bc 4245 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4246 NO_STR
4247 NEIGHBOR_STR
4248 NEIGHBOR_ADDR_STR2
4249 "Send Community attribute to this neighbor\n"
4250 "Send Standard and Extended Community attributes\n"
57d187bc 4251 "Send Standard, Large and Extended Community attributes\n"
718e3744 4252 "Send Extended Community attributes\n"
57d187bc
JS
4253 "Send Standard Community attributes\n"
4254 "Send Large Community attributes\n")
718e3744 4255{
d62a17ae 4256 int idx_peer = 2;
27c05d4d 4257 uint32_t flag = 0;
d62a17ae 4258 const char *type = argv[argc - 1]->text;
4259
27c05d4d
PM
4260 if (strmatch(type, "standard")) {
4261 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4262 } else if (strmatch(type, "extended")) {
4263 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4264 } else if (strmatch(type, "large")) {
4265 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4266 } else if (strmatch(type, "both")) {
4267 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4268 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4269 } else { /* if (strmatch(type, "all")) */
4270 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4271 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4272 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4273 }
4274
4275 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4276 bgp_node_afi(vty), bgp_node_safi(vty),
4277 flag);
d62a17ae 4278}
4279
4280ALIAS_HIDDEN(
4281 no_neighbor_send_community_type,
4282 no_neighbor_send_community_type_hidden_cmd,
4283 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4284 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4285 "Send Community attribute to this neighbor\n"
4286 "Send Standard and Extended Community attributes\n"
4287 "Send Standard, Large and Extended Community attributes\n"
4288 "Send Extended Community attributes\n"
4289 "Send Standard Community attributes\n"
4290 "Send Large Community attributes\n")
596c17ba 4291
718e3744 4292/* neighbor soft-reconfig. */
4293DEFUN (neighbor_soft_reconfiguration,
4294 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4295 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4296 NEIGHBOR_STR
4297 NEIGHBOR_ADDR_STR2
4298 "Per neighbor soft reconfiguration\n"
4299 "Allow inbound soft reconfiguration for this neighbor\n")
4300{
d62a17ae 4301 int idx_peer = 1;
4302 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4303 bgp_node_safi(vty),
4304 PEER_FLAG_SOFT_RECONFIG);
718e3744 4305}
4306
d62a17ae 4307ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4308 neighbor_soft_reconfiguration_hidden_cmd,
4309 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4310 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4311 "Per neighbor soft reconfiguration\n"
4312 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4313
718e3744 4314DEFUN (no_neighbor_soft_reconfiguration,
4315 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4316 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4317 NO_STR
4318 NEIGHBOR_STR
4319 NEIGHBOR_ADDR_STR2
4320 "Per neighbor soft reconfiguration\n"
4321 "Allow inbound soft reconfiguration for this neighbor\n")
4322{
d62a17ae 4323 int idx_peer = 2;
4324 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4325 bgp_node_afi(vty), bgp_node_safi(vty),
4326 PEER_FLAG_SOFT_RECONFIG);
718e3744 4327}
6b0655a2 4328
d62a17ae 4329ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4330 no_neighbor_soft_reconfiguration_hidden_cmd,
4331 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4332 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4333 "Per neighbor soft reconfiguration\n"
4334 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4335
718e3744 4336DEFUN (neighbor_route_reflector_client,
4337 neighbor_route_reflector_client_cmd,
9ccf14f7 4338 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4339 NEIGHBOR_STR
4340 NEIGHBOR_ADDR_STR2
4341 "Configure a neighbor as Route Reflector client\n")
4342{
d62a17ae 4343 int idx_peer = 1;
4344 struct peer *peer;
718e3744 4345
4346
d62a17ae 4347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4348 if (!peer)
4349 return CMD_WARNING_CONFIG_FAILED;
718e3744 4350
d62a17ae 4351 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4352 bgp_node_safi(vty),
4353 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4354}
4355
d62a17ae 4356ALIAS_HIDDEN(neighbor_route_reflector_client,
4357 neighbor_route_reflector_client_hidden_cmd,
4358 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4359 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4360 "Configure a neighbor as Route Reflector client\n")
596c17ba 4361
718e3744 4362DEFUN (no_neighbor_route_reflector_client,
4363 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4364 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4365 NO_STR
4366 NEIGHBOR_STR
4367 NEIGHBOR_ADDR_STR2
4368 "Configure a neighbor as Route Reflector client\n")
4369{
d62a17ae 4370 int idx_peer = 2;
4371 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4372 bgp_node_afi(vty), bgp_node_safi(vty),
4373 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4374}
6b0655a2 4375
d62a17ae 4376ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4377 no_neighbor_route_reflector_client_hidden_cmd,
4378 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4379 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4380 "Configure a neighbor as Route Reflector client\n")
596c17ba 4381
718e3744 4382/* neighbor route-server-client. */
4383DEFUN (neighbor_route_server_client,
4384 neighbor_route_server_client_cmd,
9ccf14f7 4385 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4386 NEIGHBOR_STR
4387 NEIGHBOR_ADDR_STR2
4388 "Configure a neighbor as Route Server client\n")
4389{
d62a17ae 4390 int idx_peer = 1;
4391 struct peer *peer;
2a3d5731 4392
d62a17ae 4393 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4394 if (!peer)
4395 return CMD_WARNING_CONFIG_FAILED;
4396 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4397 bgp_node_safi(vty),
4398 PEER_FLAG_RSERVER_CLIENT);
718e3744 4399}
4400
d62a17ae 4401ALIAS_HIDDEN(neighbor_route_server_client,
4402 neighbor_route_server_client_hidden_cmd,
4403 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4404 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4405 "Configure a neighbor as Route Server client\n")
596c17ba 4406
718e3744 4407DEFUN (no_neighbor_route_server_client,
4408 no_neighbor_route_server_client_cmd,
9ccf14f7 4409 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4410 NO_STR
4411 NEIGHBOR_STR
4412 NEIGHBOR_ADDR_STR2
4413 "Configure a neighbor as Route Server client\n")
fee0f4c6 4414{
d62a17ae 4415 int idx_peer = 2;
4416 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4417 bgp_node_afi(vty), bgp_node_safi(vty),
4418 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4419}
6b0655a2 4420
d62a17ae 4421ALIAS_HIDDEN(no_neighbor_route_server_client,
4422 no_neighbor_route_server_client_hidden_cmd,
4423 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4424 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4425 "Configure a neighbor as Route Server client\n")
596c17ba 4426
fee0f4c6 4427DEFUN (neighbor_nexthop_local_unchanged,
4428 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4429 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4430 NEIGHBOR_STR
4431 NEIGHBOR_ADDR_STR2
4432 "Configure treatment of outgoing link-local nexthop attribute\n"
4433 "Leave link-local nexthop unchanged for this peer\n")
4434{
d62a17ae 4435 int idx_peer = 1;
4436 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4437 bgp_node_safi(vty),
4438 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4439}
6b0655a2 4440
fee0f4c6 4441DEFUN (no_neighbor_nexthop_local_unchanged,
4442 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4443 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4444 NO_STR
4445 NEIGHBOR_STR
4446 NEIGHBOR_ADDR_STR2
4447 "Configure treatment of outgoing link-local-nexthop attribute\n"
4448 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4449{
d62a17ae 4450 int idx_peer = 2;
4451 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4452 bgp_node_afi(vty), bgp_node_safi(vty),
4453 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4454}
6b0655a2 4455
718e3744 4456DEFUN (neighbor_attr_unchanged,
4457 neighbor_attr_unchanged_cmd,
a8206004 4458 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "BGP attribute is propagated unchanged to this neighbor\n"
4462 "As-path attribute\n"
4463 "Nexthop attribute\n"
a8206004 4464 "Med attribute\n")
718e3744 4465{
d62a17ae 4466 int idx = 0;
8eeb0335
DW
4467 char *peer_str = argv[1]->arg;
4468 struct peer *peer;
d7c0a89a 4469 uint16_t flags = 0;
8eeb0335
DW
4470 afi_t afi = bgp_node_afi(vty);
4471 safi_t safi = bgp_node_safi(vty);
4472
4473 peer = peer_and_group_lookup_vty(vty, peer_str);
4474 if (!peer)
4475 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4476
4477 if (argv_find(argv, argc, "as-path", &idx))
4478 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4479 idx = 0;
4480 if (argv_find(argv, argc, "next-hop", &idx))
4481 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4482 idx = 0;
4483 if (argv_find(argv, argc, "med", &idx))
4484 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4485
8eeb0335
DW
4486 /* no flags means all of them! */
4487 if (!flags) {
d62a17ae 4488 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4489 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4490 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4491 } else {
a4d82a8a
PZ
4492 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4493 && peer_af_flag_check(peer, afi, safi,
4494 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4495 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4496 PEER_FLAG_AS_PATH_UNCHANGED);
4497 }
4498
a4d82a8a
PZ
4499 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4500 && peer_af_flag_check(peer, afi, safi,
4501 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4502 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4503 PEER_FLAG_NEXTHOP_UNCHANGED);
4504 }
4505
a4d82a8a
PZ
4506 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4507 && peer_af_flag_check(peer, afi, safi,
4508 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4509 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4510 PEER_FLAG_MED_UNCHANGED);
4511 }
d62a17ae 4512 }
4513
8eeb0335 4514 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4515}
4516
4517ALIAS_HIDDEN(
4518 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4519 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4520 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4521 "BGP attribute is propagated unchanged to this neighbor\n"
4522 "As-path attribute\n"
4523 "Nexthop attribute\n"
4524 "Med attribute\n")
596c17ba 4525
718e3744 4526DEFUN (no_neighbor_attr_unchanged,
4527 no_neighbor_attr_unchanged_cmd,
a8206004 4528 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4529 NO_STR
718e3744 4530 NEIGHBOR_STR
4531 NEIGHBOR_ADDR_STR2
31500417
DW
4532 "BGP attribute is propagated unchanged to this neighbor\n"
4533 "As-path attribute\n"
40e718b5 4534 "Nexthop attribute\n"
a8206004 4535 "Med attribute\n")
718e3744 4536{
d62a17ae 4537 int idx = 0;
4538 char *peer = argv[2]->arg;
d7c0a89a 4539 uint16_t flags = 0;
d62a17ae 4540
4541 if (argv_find(argv, argc, "as-path", &idx))
4542 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4543 idx = 0;
4544 if (argv_find(argv, argc, "next-hop", &idx))
4545 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4546 idx = 0;
4547 if (argv_find(argv, argc, "med", &idx))
4548 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4549
4550 if (!flags) // no flags means all of them!
4551 {
4552 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4553 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4554 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4555 }
4556
4557 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4558 bgp_node_safi(vty), flags);
4559}
4560
4561ALIAS_HIDDEN(
4562 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4563 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4564 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4565 "BGP attribute is propagated unchanged to this neighbor\n"
4566 "As-path attribute\n"
4567 "Nexthop attribute\n"
4568 "Med attribute\n")
718e3744 4569
718e3744 4570/* EBGP multihop configuration. */
d62a17ae 4571static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4572 const char *ttl_str)
718e3744 4573{
d62a17ae 4574 struct peer *peer;
4575 unsigned int ttl;
718e3744 4576
d62a17ae 4577 peer = peer_and_group_lookup_vty(vty, ip_str);
4578 if (!peer)
4579 return CMD_WARNING_CONFIG_FAILED;
718e3744 4580
d62a17ae 4581 if (peer->conf_if)
4582 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4583
d62a17ae 4584 if (!ttl_str)
4585 ttl = MAXTTL;
4586 else
4587 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4588
d62a17ae 4589 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4590}
4591
d62a17ae 4592static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4593{
d62a17ae 4594 struct peer *peer;
718e3744 4595
d62a17ae 4596 peer = peer_and_group_lookup_vty(vty, ip_str);
4597 if (!peer)
4598 return CMD_WARNING_CONFIG_FAILED;
718e3744 4599
d62a17ae 4600 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4601}
4602
4603/* neighbor ebgp-multihop. */
4604DEFUN (neighbor_ebgp_multihop,
4605 neighbor_ebgp_multihop_cmd,
9ccf14f7 4606 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4607 NEIGHBOR_STR
4608 NEIGHBOR_ADDR_STR2
4609 "Allow EBGP neighbors not on directly connected networks\n")
4610{
d62a17ae 4611 int idx_peer = 1;
4612 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4613}
4614
4615DEFUN (neighbor_ebgp_multihop_ttl,
4616 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4617 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4618 NEIGHBOR_STR
4619 NEIGHBOR_ADDR_STR2
4620 "Allow EBGP neighbors not on directly connected networks\n"
4621 "maximum hop count\n")
4622{
d62a17ae 4623 int idx_peer = 1;
4624 int idx_number = 3;
4625 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4626 argv[idx_number]->arg);
718e3744 4627}
4628
4629DEFUN (no_neighbor_ebgp_multihop,
4630 no_neighbor_ebgp_multihop_cmd,
a636c635 4631 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4632 NO_STR
4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
a636c635
DW
4635 "Allow EBGP neighbors not on directly connected networks\n"
4636 "maximum hop count\n")
718e3744 4637{
d62a17ae 4638 int idx_peer = 2;
4639 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4640}
4641
6b0655a2 4642
6ffd2079 4643/* disable-connected-check */
4644DEFUN (neighbor_disable_connected_check,
4645 neighbor_disable_connected_check_cmd,
7ebe625c 4646 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4647 NEIGHBOR_STR
7ebe625c 4648 NEIGHBOR_ADDR_STR2
a636c635
DW
4649 "one-hop away EBGP peer using loopback address\n"
4650 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4651{
d62a17ae 4652 int idx_peer = 1;
4653 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4654 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4655}
4656
4657DEFUN (no_neighbor_disable_connected_check,
4658 no_neighbor_disable_connected_check_cmd,
7ebe625c 4659 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4660 NO_STR
4661 NEIGHBOR_STR
7ebe625c 4662 NEIGHBOR_ADDR_STR2
a636c635
DW
4663 "one-hop away EBGP peer using loopback address\n"
4664 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4665{
d62a17ae 4666 int idx_peer = 2;
4667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4668 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4669}
4670
47cbc09b
PM
4671
4672/* enforce-first-as */
4673DEFUN (neighbor_enforce_first_as,
4674 neighbor_enforce_first_as_cmd,
4675 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "Enforce the first AS for EBGP routes\n")
4679{
4680 int idx_peer = 1;
4681
4682 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4683 PEER_FLAG_ENFORCE_FIRST_AS);
4684}
4685
4686DEFUN (no_neighbor_enforce_first_as,
4687 no_neighbor_enforce_first_as_cmd,
4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4689 NO_STR
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "Enforce the first AS for EBGP routes\n")
4693{
4694 int idx_peer = 2;
4695
4696 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4697 PEER_FLAG_ENFORCE_FIRST_AS);
4698}
4699
4700
718e3744 4701DEFUN (neighbor_description,
4702 neighbor_description_cmd,
e961923c 4703 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4704 NEIGHBOR_STR
4705 NEIGHBOR_ADDR_STR2
4706 "Neighbor specific description\n"
4707 "Up to 80 characters describing this neighbor\n")
4708{
d62a17ae 4709 int idx_peer = 1;
4710 int idx_line = 3;
4711 struct peer *peer;
4712 char *str;
718e3744 4713
d62a17ae 4714 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4715 if (!peer)
4716 return CMD_WARNING_CONFIG_FAILED;
718e3744 4717
d62a17ae 4718 str = argv_concat(argv, argc, idx_line);
718e3744 4719
d62a17ae 4720 peer_description_set(peer, str);
718e3744 4721
d62a17ae 4722 XFREE(MTYPE_TMP, str);
718e3744 4723
d62a17ae 4724 return CMD_SUCCESS;
718e3744 4725}
4726
4727DEFUN (no_neighbor_description,
4728 no_neighbor_description_cmd,
a14810f4 4729 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4730 NO_STR
4731 NEIGHBOR_STR
4732 NEIGHBOR_ADDR_STR2
a14810f4 4733 "Neighbor specific description\n")
718e3744 4734{
d62a17ae 4735 int idx_peer = 2;
4736 struct peer *peer;
718e3744 4737
d62a17ae 4738 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4739 if (!peer)
4740 return CMD_WARNING_CONFIG_FAILED;
718e3744 4741
d62a17ae 4742 peer_description_unset(peer);
718e3744 4743
d62a17ae 4744 return CMD_SUCCESS;
718e3744 4745}
4746
a14810f4
PM
4747ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4748 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4749 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4750 "Neighbor specific description\n"
4751 "Up to 80 characters describing this neighbor\n")
6b0655a2 4752
718e3744 4753/* Neighbor update-source. */
d62a17ae 4754static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4755 const char *source_str)
4756{
4757 struct peer *peer;
4758 struct prefix p;
a14810f4 4759 union sockunion su;
d62a17ae 4760
4761 peer = peer_and_group_lookup_vty(vty, peer_str);
4762 if (!peer)
4763 return CMD_WARNING_CONFIG_FAILED;
4764
4765 if (peer->conf_if)
4766 return CMD_WARNING;
4767
4768 if (source_str) {
a14810f4 4769 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4770 peer_update_source_addr_set(peer, &su);
4771 else {
4772 if (str2prefix(source_str, &p)) {
4773 vty_out(vty,
4774 "%% Invalid update-source, remove prefix length \n");
4775 return CMD_WARNING_CONFIG_FAILED;
4776 } else
4777 peer_update_source_if_set(peer, source_str);
4778 }
4779 } else
4780 peer_update_source_unset(peer);
4781
4782 return CMD_SUCCESS;
4783}
4784
4785#define BGP_UPDATE_SOURCE_HELP_STR \
4786 "IPv4 address\n" \
4787 "IPv6 address\n" \
4788 "Interface name (requires zebra to be running)\n"
369688c0 4789
718e3744 4790DEFUN (neighbor_update_source,
4791 neighbor_update_source_cmd,
9ccf14f7 4792 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4793 NEIGHBOR_STR
4794 NEIGHBOR_ADDR_STR2
4795 "Source of routing updates\n"
369688c0 4796 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4797{
d62a17ae 4798 int idx_peer = 1;
4799 int idx_peer_2 = 3;
4800 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4801 argv[idx_peer_2]->arg);
718e3744 4802}
4803
4804DEFUN (no_neighbor_update_source,
4805 no_neighbor_update_source_cmd,
c7178fe7 4806 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4807 NO_STR
4808 NEIGHBOR_STR
4809 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4810 "Source of routing updates\n"
4811 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4812{
d62a17ae 4813 int idx_peer = 2;
4814 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4815}
6b0655a2 4816
d62a17ae 4817static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4818 afi_t afi, safi_t safi,
4819 const char *rmap, int set)
718e3744 4820{
d62a17ae 4821 int ret;
4822 struct peer *peer;
80912664 4823 struct route_map *route_map = NULL;
718e3744 4824
d62a17ae 4825 peer = peer_and_group_lookup_vty(vty, peer_str);
4826 if (!peer)
4827 return CMD_WARNING_CONFIG_FAILED;
718e3744 4828
1de27621 4829 if (set) {
80912664
DS
4830 if (rmap)
4831 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
4832 ret = peer_default_originate_set(peer, afi, safi,
4833 rmap, route_map);
4834 } else
d62a17ae 4835 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4836
d62a17ae 4837 return bgp_vty_return(vty, ret);
718e3744 4838}
4839
4840/* neighbor default-originate. */
4841DEFUN (neighbor_default_originate,
4842 neighbor_default_originate_cmd,
9ccf14f7 4843 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4844 NEIGHBOR_STR
4845 NEIGHBOR_ADDR_STR2
4846 "Originate default route to this neighbor\n")
4847{
d62a17ae 4848 int idx_peer = 1;
4849 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4850 bgp_node_afi(vty),
4851 bgp_node_safi(vty), NULL, 1);
718e3744 4852}
4853
d62a17ae 4854ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4856 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Originate default route to this neighbor\n")
596c17ba 4858
718e3744 4859DEFUN (neighbor_default_originate_rmap,
4860 neighbor_default_originate_rmap_cmd,
9ccf14f7 4861 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4862 NEIGHBOR_STR
4863 NEIGHBOR_ADDR_STR2
4864 "Originate default route to this neighbor\n"
4865 "Route-map to specify criteria to originate default\n"
4866 "route-map name\n")
4867{
d62a17ae 4868 int idx_peer = 1;
4869 int idx_word = 4;
4870 return peer_default_originate_set_vty(
4871 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4872 argv[idx_word]->arg, 1);
718e3744 4873}
4874
d62a17ae 4875ALIAS_HIDDEN(
4876 neighbor_default_originate_rmap,
4877 neighbor_default_originate_rmap_hidden_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4880 "Originate default route to this neighbor\n"
4881 "Route-map to specify criteria to originate default\n"
4882 "route-map name\n")
596c17ba 4883
718e3744 4884DEFUN (no_neighbor_default_originate,
4885 no_neighbor_default_originate_cmd,
a636c635 4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
a636c635
DW
4890 "Originate default route to this neighbor\n"
4891 "Route-map to specify criteria to originate default\n"
4892 "route-map name\n")
718e3744 4893{
d62a17ae 4894 int idx_peer = 2;
4895 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4896 bgp_node_afi(vty),
4897 bgp_node_safi(vty), NULL, 0);
718e3744 4898}
4899
d62a17ae 4900ALIAS_HIDDEN(
4901 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4902 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4903 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4904 "Originate default route to this neighbor\n"
4905 "Route-map to specify criteria to originate default\n"
4906 "route-map name\n")
596c17ba 4907
6b0655a2 4908
718e3744 4909/* Set neighbor's BGP port. */
d62a17ae 4910static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4911 const char *port_str)
4912{
4913 struct peer *peer;
d7c0a89a 4914 uint16_t port;
d62a17ae 4915 struct servent *sp;
4916
4917 peer = peer_lookup_vty(vty, ip_str);
4918 if (!peer)
4919 return CMD_WARNING_CONFIG_FAILED;
4920
4921 if (!port_str) {
4922 sp = getservbyname("bgp", "tcp");
4923 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4924 } else {
4925 port = strtoul(port_str, NULL, 10);
4926 }
718e3744 4927
d62a17ae 4928 peer_port_set(peer, port);
718e3744 4929
d62a17ae 4930 return CMD_SUCCESS;
718e3744 4931}
4932
f418446b 4933/* Set specified peer's BGP port. */
718e3744 4934DEFUN (neighbor_port,
4935 neighbor_port_cmd,
9ccf14f7 4936 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4937 NEIGHBOR_STR
4938 NEIGHBOR_ADDR_STR
4939 "Neighbor's BGP port\n"
4940 "TCP port number\n")
4941{
d62a17ae 4942 int idx_ip = 1;
4943 int idx_number = 3;
4944 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4945 argv[idx_number]->arg);
718e3744 4946}
4947
4948DEFUN (no_neighbor_port,
4949 no_neighbor_port_cmd,
9ccf14f7 4950 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4951 NO_STR
4952 NEIGHBOR_STR
4953 NEIGHBOR_ADDR_STR
8334fd5a
DW
4954 "Neighbor's BGP port\n"
4955 "TCP port number\n")
718e3744 4956{
d62a17ae 4957 int idx_ip = 2;
4958 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4959}
4960
6b0655a2 4961
718e3744 4962/* neighbor weight. */
d62a17ae 4963static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4964 safi_t safi, const char *weight_str)
718e3744 4965{
d62a17ae 4966 int ret;
4967 struct peer *peer;
4968 unsigned long weight;
718e3744 4969
d62a17ae 4970 peer = peer_and_group_lookup_vty(vty, ip_str);
4971 if (!peer)
4972 return CMD_WARNING_CONFIG_FAILED;
718e3744 4973
d62a17ae 4974 weight = strtoul(weight_str, NULL, 10);
718e3744 4975
d62a17ae 4976 ret = peer_weight_set(peer, afi, safi, weight);
4977 return bgp_vty_return(vty, ret);
718e3744 4978}
4979
d62a17ae 4980static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4981 safi_t safi)
718e3744 4982{
d62a17ae 4983 int ret;
4984 struct peer *peer;
718e3744 4985
d62a17ae 4986 peer = peer_and_group_lookup_vty(vty, ip_str);
4987 if (!peer)
4988 return CMD_WARNING_CONFIG_FAILED;
718e3744 4989
d62a17ae 4990 ret = peer_weight_unset(peer, afi, safi);
4991 return bgp_vty_return(vty, ret);
718e3744 4992}
4993
4994DEFUN (neighbor_weight,
4995 neighbor_weight_cmd,
9ccf14f7 4996 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR2
4999 "Set default weight for routes from this neighbor\n"
5000 "default weight\n")
5001{
d62a17ae 5002 int idx_peer = 1;
5003 int idx_number = 3;
5004 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5005 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5006}
5007
d62a17ae 5008ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5009 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5011 "Set default weight for routes from this neighbor\n"
5012 "default weight\n")
596c17ba 5013
718e3744 5014DEFUN (no_neighbor_weight,
5015 no_neighbor_weight_cmd,
9ccf14f7 5016 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5017 NO_STR
5018 NEIGHBOR_STR
5019 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5020 "Set default weight for routes from this neighbor\n"
5021 "default weight\n")
718e3744 5022{
d62a17ae 5023 int idx_peer = 2;
5024 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5025 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5026}
5027
d62a17ae 5028ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Set default weight for routes from this neighbor\n"
5032 "default weight\n")
596c17ba 5033
6b0655a2 5034
718e3744 5035/* Override capability negotiation. */
5036DEFUN (neighbor_override_capability,
5037 neighbor_override_capability_cmd,
9ccf14f7 5038 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5039 NEIGHBOR_STR
5040 NEIGHBOR_ADDR_STR2
5041 "Override capability negotiation result\n")
5042{
d62a17ae 5043 int idx_peer = 1;
5044 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5045 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5046}
5047
5048DEFUN (no_neighbor_override_capability,
5049 no_neighbor_override_capability_cmd,
9ccf14f7 5050 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5051 NO_STR
5052 NEIGHBOR_STR
5053 NEIGHBOR_ADDR_STR2
5054 "Override capability negotiation result\n")
5055{
d62a17ae 5056 int idx_peer = 2;
5057 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5058 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5059}
6b0655a2 5060
718e3744 5061DEFUN (neighbor_strict_capability,
5062 neighbor_strict_capability_cmd,
9fb964de 5063 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5064 NEIGHBOR_STR
9fb964de 5065 NEIGHBOR_ADDR_STR2
718e3744 5066 "Strict capability negotiation match\n")
5067{
9fb964de
PM
5068 int idx_peer = 1;
5069
5070 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5071 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5072}
5073
5074DEFUN (no_neighbor_strict_capability,
5075 no_neighbor_strict_capability_cmd,
9fb964de 5076 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5077 NO_STR
5078 NEIGHBOR_STR
9fb964de 5079 NEIGHBOR_ADDR_STR2
718e3744 5080 "Strict capability negotiation match\n")
5081{
9fb964de
PM
5082 int idx_peer = 2;
5083
5084 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5085 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5086}
6b0655a2 5087
d62a17ae 5088static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5089 const char *keep_str, const char *hold_str)
718e3744 5090{
d62a17ae 5091 int ret;
5092 struct peer *peer;
d7c0a89a
QY
5093 uint32_t keepalive;
5094 uint32_t holdtime;
718e3744 5095
d62a17ae 5096 peer = peer_and_group_lookup_vty(vty, ip_str);
5097 if (!peer)
5098 return CMD_WARNING_CONFIG_FAILED;
718e3744 5099
d62a17ae 5100 keepalive = strtoul(keep_str, NULL, 10);
5101 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5102
d62a17ae 5103 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5104
d62a17ae 5105 return bgp_vty_return(vty, ret);
718e3744 5106}
6b0655a2 5107
d62a17ae 5108static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5109{
d62a17ae 5110 int ret;
5111 struct peer *peer;
718e3744 5112
d62a17ae 5113 peer = peer_and_group_lookup_vty(vty, ip_str);
5114 if (!peer)
5115 return CMD_WARNING_CONFIG_FAILED;
718e3744 5116
d62a17ae 5117 ret = peer_timers_unset(peer);
718e3744 5118
d62a17ae 5119 return bgp_vty_return(vty, ret);
718e3744 5120}
5121
5122DEFUN (neighbor_timers,
5123 neighbor_timers_cmd,
9ccf14f7 5124 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "BGP per neighbor timers\n"
5128 "Keepalive interval\n"
5129 "Holdtime\n")
5130{
d62a17ae 5131 int idx_peer = 1;
5132 int idx_number = 3;
5133 int idx_number_2 = 4;
5134 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5135 argv[idx_number]->arg,
5136 argv[idx_number_2]->arg);
718e3744 5137}
5138
5139DEFUN (no_neighbor_timers,
5140 no_neighbor_timers_cmd,
9ccf14f7 5141 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5142 NO_STR
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5145 "BGP per neighbor timers\n"
5146 "Keepalive interval\n"
5147 "Holdtime\n")
718e3744 5148{
d62a17ae 5149 int idx_peer = 2;
5150 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5151}
6b0655a2 5152
813d4307 5153
d62a17ae 5154static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5155 const char *time_str)
718e3744 5156{
d62a17ae 5157 int ret;
5158 struct peer *peer;
d7c0a89a 5159 uint32_t connect;
718e3744 5160
d62a17ae 5161 peer = peer_and_group_lookup_vty(vty, ip_str);
5162 if (!peer)
5163 return CMD_WARNING_CONFIG_FAILED;
718e3744 5164
d62a17ae 5165 connect = strtoul(time_str, NULL, 10);
718e3744 5166
d62a17ae 5167 ret = peer_timers_connect_set(peer, connect);
718e3744 5168
d62a17ae 5169 return bgp_vty_return(vty, ret);
718e3744 5170}
5171
d62a17ae 5172static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5173{
d62a17ae 5174 int ret;
5175 struct peer *peer;
718e3744 5176
d62a17ae 5177 peer = peer_and_group_lookup_vty(vty, ip_str);
5178 if (!peer)
5179 return CMD_WARNING_CONFIG_FAILED;
718e3744 5180
d62a17ae 5181 ret = peer_timers_connect_unset(peer);
718e3744 5182
d62a17ae 5183 return bgp_vty_return(vty, ret);
718e3744 5184}
5185
5186DEFUN (neighbor_timers_connect,
5187 neighbor_timers_connect_cmd,
9ccf14f7 5188 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5189 NEIGHBOR_STR
966f821c 5190 NEIGHBOR_ADDR_STR2
718e3744 5191 "BGP per neighbor timers\n"
5192 "BGP connect timer\n"
5193 "Connect timer\n")
5194{
d62a17ae 5195 int idx_peer = 1;
5196 int idx_number = 4;
5197 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5198 argv[idx_number]->arg);
718e3744 5199}
5200
5201DEFUN (no_neighbor_timers_connect,
5202 no_neighbor_timers_connect_cmd,
9ccf14f7 5203 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5204 NO_STR
5205 NEIGHBOR_STR
966f821c 5206 NEIGHBOR_ADDR_STR2
718e3744 5207 "BGP per neighbor timers\n"
8334fd5a
DW
5208 "BGP connect timer\n"
5209 "Connect timer\n")
718e3744 5210{
d62a17ae 5211 int idx_peer = 2;
5212 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5213}
5214
6b0655a2 5215
d62a17ae 5216static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5217 const char *time_str, int set)
718e3744 5218{
d62a17ae 5219 int ret;
5220 struct peer *peer;
d7c0a89a 5221 uint32_t routeadv = 0;
718e3744 5222
d62a17ae 5223 peer = peer_and_group_lookup_vty(vty, ip_str);
5224 if (!peer)
5225 return CMD_WARNING_CONFIG_FAILED;
718e3744 5226
d62a17ae 5227 if (time_str)
5228 routeadv = strtoul(time_str, NULL, 10);
718e3744 5229
d62a17ae 5230 if (set)
5231 ret = peer_advertise_interval_set(peer, routeadv);
5232 else
5233 ret = peer_advertise_interval_unset(peer);
718e3744 5234
d62a17ae 5235 return bgp_vty_return(vty, ret);
718e3744 5236}
5237
5238DEFUN (neighbor_advertise_interval,
5239 neighbor_advertise_interval_cmd,
9ccf14f7 5240 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5241 NEIGHBOR_STR
966f821c 5242 NEIGHBOR_ADDR_STR2
718e3744 5243 "Minimum interval between sending BGP routing updates\n"
5244 "time in seconds\n")
5245{
d62a17ae 5246 int idx_peer = 1;
5247 int idx_number = 3;
5248 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5249 argv[idx_number]->arg, 1);
718e3744 5250}
5251
5252DEFUN (no_neighbor_advertise_interval,
5253 no_neighbor_advertise_interval_cmd,
9ccf14f7 5254 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5255 NO_STR
5256 NEIGHBOR_STR
966f821c 5257 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5258 "Minimum interval between sending BGP routing updates\n"
5259 "time in seconds\n")
718e3744 5260{
d62a17ae 5261 int idx_peer = 2;
5262 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5263}
5264
6b0655a2 5265
518f0eb1
DS
5266/* Time to wait before processing route-map updates */
5267DEFUN (bgp_set_route_map_delay_timer,
5268 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5269 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5270 SET_STR
5271 "BGP route-map delay timer\n"
5272 "Time in secs to wait before processing route-map changes\n"
f414725f 5273 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5274{
d62a17ae 5275 int idx_number = 3;
d7c0a89a 5276 uint32_t rmap_delay_timer;
d62a17ae 5277
5278 if (argv[idx_number]->arg) {
5279 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5280 bm->rmap_update_timer = rmap_delay_timer;
5281
5282 /* if the dynamic update handling is being disabled, and a timer
5283 * is
5284 * running, stop the timer and act as if the timer has already
5285 * fired.
5286 */
5287 if (!rmap_delay_timer && bm->t_rmap_update) {
5288 BGP_TIMER_OFF(bm->t_rmap_update);
5289 thread_execute(bm->master, bgp_route_map_update_timer,
5290 NULL, 0);
5291 }
5292 return CMD_SUCCESS;
5293 } else {
5294 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5295 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5296 }
518f0eb1
DS
5297}
5298
5299DEFUN (no_bgp_set_route_map_delay_timer,
5300 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5301 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5302 NO_STR
3a2d747c 5303 BGP_STR
518f0eb1 5304 "Default BGP route-map delay timer\n"
8334fd5a
DW
5305 "Reset to default time to wait for processing route-map changes\n"
5306 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5307{
518f0eb1 5308
d62a17ae 5309 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5310
d62a17ae 5311 return CMD_SUCCESS;
518f0eb1
DS
5312}
5313
f414725f 5314
718e3744 5315/* neighbor interface */
d62a17ae 5316static int peer_interface_vty(struct vty *vty, const char *ip_str,
5317 const char *str)
718e3744 5318{
d62a17ae 5319 struct peer *peer;
718e3744 5320
d62a17ae 5321 peer = peer_lookup_vty(vty, ip_str);
5322 if (!peer || peer->conf_if) {
5323 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5324 return CMD_WARNING_CONFIG_FAILED;
5325 }
718e3744 5326
d62a17ae 5327 if (str)
5328 peer_interface_set(peer, str);
5329 else
5330 peer_interface_unset(peer);
718e3744 5331
d62a17ae 5332 return CMD_SUCCESS;
718e3744 5333}
5334
5335DEFUN (neighbor_interface,
5336 neighbor_interface_cmd,
9ccf14f7 5337 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR
5340 "Interface\n"
5341 "Interface name\n")
5342{
d62a17ae 5343 int idx_ip = 1;
5344 int idx_word = 3;
5345 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5346}
5347
5348DEFUN (no_neighbor_interface,
5349 no_neighbor_interface_cmd,
9ccf14f7 5350 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5351 NO_STR
5352 NEIGHBOR_STR
16cedbb0 5353 NEIGHBOR_ADDR_STR2
718e3744 5354 "Interface\n"
5355 "Interface name\n")
5356{
d62a17ae 5357 int idx_peer = 2;
5358 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5359}
6b0655a2 5360
718e3744 5361DEFUN (neighbor_distribute_list,
5362 neighbor_distribute_list_cmd,
9ccf14f7 5363 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5364 NEIGHBOR_STR
5365 NEIGHBOR_ADDR_STR2
5366 "Filter updates to/from this neighbor\n"
5367 "IP access-list number\n"
5368 "IP access-list number (expanded range)\n"
5369 "IP Access-list name\n"
5370 "Filter incoming updates\n"
5371 "Filter outgoing updates\n")
5372{
d62a17ae 5373 int idx_peer = 1;
5374 int idx_acl = 3;
5375 int direct, ret;
5376 struct peer *peer;
a8206004 5377
d62a17ae 5378 const char *pstr = argv[idx_peer]->arg;
5379 const char *acl = argv[idx_acl]->arg;
5380 const char *inout = argv[argc - 1]->text;
a8206004 5381
d62a17ae 5382 peer = peer_and_group_lookup_vty(vty, pstr);
5383 if (!peer)
5384 return CMD_WARNING_CONFIG_FAILED;
a8206004 5385
d62a17ae 5386 /* Check filter direction. */
5387 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5388 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5389 direct, acl);
a8206004 5390
d62a17ae 5391 return bgp_vty_return(vty, ret);
718e3744 5392}
5393
d62a17ae 5394ALIAS_HIDDEN(
5395 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5396 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5397 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5398 "Filter updates to/from this neighbor\n"
5399 "IP access-list number\n"
5400 "IP access-list number (expanded range)\n"
5401 "IP Access-list name\n"
5402 "Filter incoming updates\n"
5403 "Filter outgoing updates\n")
596c17ba 5404
718e3744 5405DEFUN (no_neighbor_distribute_list,
5406 no_neighbor_distribute_list_cmd,
9ccf14f7 5407 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5408 NO_STR
5409 NEIGHBOR_STR
5410 NEIGHBOR_ADDR_STR2
5411 "Filter updates to/from this neighbor\n"
5412 "IP access-list number\n"
5413 "IP access-list number (expanded range)\n"
5414 "IP Access-list name\n"
5415 "Filter incoming updates\n"
5416 "Filter outgoing updates\n")
5417{
d62a17ae 5418 int idx_peer = 2;
5419 int direct, ret;
5420 struct peer *peer;
a8206004 5421
d62a17ae 5422 const char *pstr = argv[idx_peer]->arg;
5423 const char *inout = argv[argc - 1]->text;
a8206004 5424
d62a17ae 5425 peer = peer_and_group_lookup_vty(vty, pstr);
5426 if (!peer)
5427 return CMD_WARNING_CONFIG_FAILED;
a8206004 5428
d62a17ae 5429 /* Check filter direction. */
5430 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5431 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5432 direct);
a8206004 5433
d62a17ae 5434 return bgp_vty_return(vty, ret);
718e3744 5435}
6b0655a2 5436
d62a17ae 5437ALIAS_HIDDEN(
5438 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5441 "Filter updates to/from this neighbor\n"
5442 "IP access-list number\n"
5443 "IP access-list number (expanded range)\n"
5444 "IP Access-list name\n"
5445 "Filter incoming updates\n"
5446 "Filter outgoing updates\n")
596c17ba 5447
718e3744 5448/* Set prefix list to the peer. */
d62a17ae 5449static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5450 afi_t afi, safi_t safi,
5451 const char *name_str,
5452 const char *direct_str)
718e3744 5453{
d62a17ae 5454 int ret;
d62a17ae 5455 int direct = FILTER_IN;
cf9ac8bf 5456 struct peer *peer;
718e3744 5457
d62a17ae 5458 peer = peer_and_group_lookup_vty(vty, ip_str);
5459 if (!peer)
5460 return CMD_WARNING_CONFIG_FAILED;
718e3744 5461
d62a17ae 5462 /* Check filter direction. */
5463 if (strncmp(direct_str, "i", 1) == 0)
5464 direct = FILTER_IN;
5465 else if (strncmp(direct_str, "o", 1) == 0)
5466 direct = FILTER_OUT;
718e3744 5467
d62a17ae 5468 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5469
d62a17ae 5470 return bgp_vty_return(vty, ret);
718e3744 5471}
5472
d62a17ae 5473static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5474 afi_t afi, safi_t safi,
5475 const char *direct_str)
718e3744 5476{
d62a17ae 5477 int ret;
5478 struct peer *peer;
5479 int direct = FILTER_IN;
718e3744 5480
d62a17ae 5481 peer = peer_and_group_lookup_vty(vty, ip_str);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5484
d62a17ae 5485 /* Check filter direction. */
5486 if (strncmp(direct_str, "i", 1) == 0)
5487 direct = FILTER_IN;
5488 else if (strncmp(direct_str, "o", 1) == 0)
5489 direct = FILTER_OUT;
718e3744 5490
d62a17ae 5491 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5492
d62a17ae 5493 return bgp_vty_return(vty, ret);
718e3744 5494}
5495
5496DEFUN (neighbor_prefix_list,
5497 neighbor_prefix_list_cmd,
9ccf14f7 5498 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5499 NEIGHBOR_STR
5500 NEIGHBOR_ADDR_STR2
5501 "Filter updates to/from this neighbor\n"
5502 "Name of a prefix list\n"
5503 "Filter incoming updates\n"
5504 "Filter outgoing updates\n")
5505{
d62a17ae 5506 int idx_peer = 1;
5507 int idx_word = 3;
5508 int idx_in_out = 4;
5509 return peer_prefix_list_set_vty(
5510 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5511 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5512}
5513
d62a17ae 5514ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5515 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5516 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5517 "Filter updates to/from this neighbor\n"
5518 "Name of a prefix list\n"
5519 "Filter incoming updates\n"
5520 "Filter outgoing updates\n")
596c17ba 5521
718e3744 5522DEFUN (no_neighbor_prefix_list,
5523 no_neighbor_prefix_list_cmd,
9ccf14f7 5524 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5525 NO_STR
5526 NEIGHBOR_STR
5527 NEIGHBOR_ADDR_STR2
5528 "Filter updates to/from this neighbor\n"
5529 "Name of a prefix list\n"
5530 "Filter incoming updates\n"
5531 "Filter outgoing updates\n")
5532{
d62a17ae 5533 int idx_peer = 2;
5534 int idx_in_out = 5;
5535 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5536 bgp_node_afi(vty), bgp_node_safi(vty),
5537 argv[idx_in_out]->arg);
718e3744 5538}
6b0655a2 5539
d62a17ae 5540ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5541 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5542 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5543 "Filter updates to/from this neighbor\n"
5544 "Name of a prefix list\n"
5545 "Filter incoming updates\n"
5546 "Filter outgoing updates\n")
596c17ba 5547
d62a17ae 5548static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5549 safi_t safi, const char *name_str,
5550 const char *direct_str)
718e3744 5551{
d62a17ae 5552 int ret;
5553 struct peer *peer;
5554 int direct = FILTER_IN;
718e3744 5555
d62a17ae 5556 peer = peer_and_group_lookup_vty(vty, ip_str);
5557 if (!peer)
5558 return CMD_WARNING_CONFIG_FAILED;
718e3744 5559
d62a17ae 5560 /* Check filter direction. */
5561 if (strncmp(direct_str, "i", 1) == 0)
5562 direct = FILTER_IN;
5563 else if (strncmp(direct_str, "o", 1) == 0)
5564 direct = FILTER_OUT;
718e3744 5565
d62a17ae 5566 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5567
d62a17ae 5568 return bgp_vty_return(vty, ret);
718e3744 5569}
5570
d62a17ae 5571static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5572 safi_t safi, const char *direct_str)
718e3744 5573{
d62a17ae 5574 int ret;
5575 struct peer *peer;
5576 int direct = FILTER_IN;
718e3744 5577
d62a17ae 5578 peer = peer_and_group_lookup_vty(vty, ip_str);
5579 if (!peer)
5580 return CMD_WARNING_CONFIG_FAILED;
718e3744 5581
d62a17ae 5582 /* Check filter direction. */
5583 if (strncmp(direct_str, "i", 1) == 0)
5584 direct = FILTER_IN;
5585 else if (strncmp(direct_str, "o", 1) == 0)
5586 direct = FILTER_OUT;
718e3744 5587
d62a17ae 5588 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5589
d62a17ae 5590 return bgp_vty_return(vty, ret);
718e3744 5591}
5592
5593DEFUN (neighbor_filter_list,
5594 neighbor_filter_list_cmd,
9ccf14f7 5595 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5596 NEIGHBOR_STR
5597 NEIGHBOR_ADDR_STR2
5598 "Establish BGP filters\n"
5599 "AS path access-list name\n"
5600 "Filter incoming routes\n"
5601 "Filter outgoing routes\n")
5602{
d62a17ae 5603 int idx_peer = 1;
5604 int idx_word = 3;
5605 int idx_in_out = 4;
5606 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5607 bgp_node_safi(vty), argv[idx_word]->arg,
5608 argv[idx_in_out]->arg);
718e3744 5609}
5610
d62a17ae 5611ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5613 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5614 "Establish BGP filters\n"
5615 "AS path access-list name\n"
5616 "Filter incoming routes\n"
5617 "Filter outgoing routes\n")
596c17ba 5618
718e3744 5619DEFUN (no_neighbor_filter_list,
5620 no_neighbor_filter_list_cmd,
9ccf14f7 5621 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5622 NO_STR
5623 NEIGHBOR_STR
5624 NEIGHBOR_ADDR_STR2
5625 "Establish BGP filters\n"
5626 "AS path access-list name\n"
5627 "Filter incoming routes\n"
5628 "Filter outgoing routes\n")
5629{
d62a17ae 5630 int idx_peer = 2;
5631 int idx_in_out = 5;
5632 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5633 bgp_node_afi(vty), bgp_node_safi(vty),
5634 argv[idx_in_out]->arg);
718e3744 5635}
6b0655a2 5636
d62a17ae 5637ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5640 "Establish BGP filters\n"
5641 "AS path access-list name\n"
5642 "Filter incoming routes\n"
5643 "Filter outgoing routes\n")
596c17ba 5644
718e3744 5645/* Set route-map to the peer. */
d62a17ae 5646static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5647 afi_t afi, safi_t safi, const char *name_str,
5648 const char *direct_str)
718e3744 5649{
d62a17ae 5650 int ret;
5651 struct peer *peer;
5652 int direct = RMAP_IN;
1de27621 5653 struct route_map *route_map;
718e3744 5654
d62a17ae 5655 peer = peer_and_group_lookup_vty(vty, ip_str);
5656 if (!peer)
5657 return CMD_WARNING_CONFIG_FAILED;
718e3744 5658
d62a17ae 5659 /* Check filter direction. */
5660 if (strncmp(direct_str, "in", 2) == 0)
5661 direct = RMAP_IN;
5662 else if (strncmp(direct_str, "o", 1) == 0)
5663 direct = RMAP_OUT;
718e3744 5664
1de27621
DA
5665 route_map = route_map_lookup_warn_noexist(vty, name_str);
5666 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5667
d62a17ae 5668 return bgp_vty_return(vty, ret);
718e3744 5669}
5670
d62a17ae 5671static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5672 afi_t afi, safi_t safi,
5673 const char *direct_str)
718e3744 5674{
d62a17ae 5675 int ret;
5676 struct peer *peer;
5677 int direct = RMAP_IN;
718e3744 5678
d62a17ae 5679 peer = peer_and_group_lookup_vty(vty, ip_str);
5680 if (!peer)
5681 return CMD_WARNING_CONFIG_FAILED;
718e3744 5682
d62a17ae 5683 /* Check filter direction. */
5684 if (strncmp(direct_str, "in", 2) == 0)
5685 direct = RMAP_IN;
5686 else if (strncmp(direct_str, "o", 1) == 0)
5687 direct = RMAP_OUT;
718e3744 5688
d62a17ae 5689 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5690
d62a17ae 5691 return bgp_vty_return(vty, ret);
718e3744 5692}
5693
5694DEFUN (neighbor_route_map,
5695 neighbor_route_map_cmd,
9ccf14f7 5696 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Apply route map to neighbor\n"
5700 "Name of route map\n"
5701 "Apply map to incoming routes\n"
2a3d5731 5702 "Apply map to outbound routes\n")
718e3744 5703{
d62a17ae 5704 int idx_peer = 1;
5705 int idx_word = 3;
5706 int idx_in_out = 4;
5707 return peer_route_map_set_vty(
5708 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5709 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5710}
5711
d62a17ae 5712ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Apply route map to neighbor\n"
5716 "Name of route map\n"
5717 "Apply map to incoming routes\n"
5718 "Apply map to outbound routes\n")
596c17ba 5719
718e3744 5720DEFUN (no_neighbor_route_map,
5721 no_neighbor_route_map_cmd,
9ccf14f7 5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Apply route map to neighbor\n"
5727 "Name of route map\n"
5728 "Apply map to incoming routes\n"
2a3d5731 5729 "Apply map to outbound routes\n")
718e3744 5730{
d62a17ae 5731 int idx_peer = 2;
5732 int idx_in_out = 5;
5733 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5734 bgp_node_afi(vty), bgp_node_safi(vty),
5735 argv[idx_in_out]->arg);
718e3744 5736}
6b0655a2 5737
d62a17ae 5738ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Apply route map to neighbor\n"
5742 "Name of route map\n"
5743 "Apply map to incoming routes\n"
5744 "Apply map to outbound routes\n")
596c17ba 5745
718e3744 5746/* Set unsuppress-map to the peer. */
d62a17ae 5747static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi,
5749 const char *name_str)
718e3744 5750{
d62a17ae 5751 int ret;
5752 struct peer *peer;
1de27621 5753 struct route_map *route_map;
718e3744 5754
d62a17ae 5755 peer = peer_and_group_lookup_vty(vty, ip_str);
5756 if (!peer)
5757 return CMD_WARNING_CONFIG_FAILED;
718e3744 5758
1de27621
DA
5759 route_map = route_map_lookup_warn_noexist(vty, name_str);
5760 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5761
d62a17ae 5762 return bgp_vty_return(vty, ret);
718e3744 5763}
5764
5765/* Unset route-map from the peer. */
d62a17ae 5766static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5767 afi_t afi, safi_t safi)
718e3744 5768{
d62a17ae 5769 int ret;
5770 struct peer *peer;
718e3744 5771
d62a17ae 5772 peer = peer_and_group_lookup_vty(vty, ip_str);
5773 if (!peer)
5774 return CMD_WARNING_CONFIG_FAILED;
718e3744 5775
d62a17ae 5776 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5777
d62a17ae 5778 return bgp_vty_return(vty, ret);
718e3744 5779}
5780
5781DEFUN (neighbor_unsuppress_map,
5782 neighbor_unsuppress_map_cmd,
9ccf14f7 5783 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5784 NEIGHBOR_STR
5785 NEIGHBOR_ADDR_STR2
5786 "Route-map to selectively unsuppress suppressed routes\n"
5787 "Name of route map\n")
5788{
d62a17ae 5789 int idx_peer = 1;
5790 int idx_word = 3;
5791 return peer_unsuppress_map_set_vty(
5792 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5793 argv[idx_word]->arg);
718e3744 5794}
5795
d62a17ae 5796ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5799 "Route-map to selectively unsuppress suppressed routes\n"
5800 "Name of route map\n")
596c17ba 5801
718e3744 5802DEFUN (no_neighbor_unsuppress_map,
5803 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5804 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5805 NO_STR
5806 NEIGHBOR_STR
5807 NEIGHBOR_ADDR_STR2
5808 "Route-map to selectively unsuppress suppressed routes\n"
5809 "Name of route map\n")
5810{
d62a17ae 5811 int idx_peer = 2;
5812 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5813 bgp_node_afi(vty),
5814 bgp_node_safi(vty));
718e3744 5815}
6b0655a2 5816
d62a17ae 5817ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5818 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5819 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5820 "Route-map to selectively unsuppress suppressed routes\n"
5821 "Name of route map\n")
596c17ba 5822
d62a17ae 5823static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5824 afi_t afi, safi_t safi,
5825 const char *num_str,
5826 const char *threshold_str, int warning,
5827 const char *restart_str)
718e3744 5828{
d62a17ae 5829 int ret;
5830 struct peer *peer;
d7c0a89a
QY
5831 uint32_t max;
5832 uint8_t threshold;
5833 uint16_t restart;
718e3744 5834
d62a17ae 5835 peer = peer_and_group_lookup_vty(vty, ip_str);
5836 if (!peer)
5837 return CMD_WARNING_CONFIG_FAILED;
718e3744 5838
d62a17ae 5839 max = strtoul(num_str, NULL, 10);
5840 if (threshold_str)
5841 threshold = atoi(threshold_str);
5842 else
5843 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5844
d62a17ae 5845 if (restart_str)
5846 restart = atoi(restart_str);
5847 else
5848 restart = 0;
0a486e5f 5849
d62a17ae 5850 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5851 restart);
718e3744 5852
d62a17ae 5853 return bgp_vty_return(vty, ret);
718e3744 5854}
5855
d62a17ae 5856static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5857 afi_t afi, safi_t safi)
718e3744 5858{
d62a17ae 5859 int ret;
5860 struct peer *peer;
718e3744 5861
d62a17ae 5862 peer = peer_and_group_lookup_vty(vty, ip_str);
5863 if (!peer)
5864 return CMD_WARNING_CONFIG_FAILED;
718e3744 5865
d62a17ae 5866 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5867
d62a17ae 5868 return bgp_vty_return(vty, ret);
718e3744 5869}
5870
5871/* Maximum number of prefix configuration. prefix count is different
5872 for each peer configuration. So this configuration can be set for
5873 each peer configuration. */
5874DEFUN (neighbor_maximum_prefix,
5875 neighbor_maximum_prefix_cmd,
9ccf14f7 5876 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5877 NEIGHBOR_STR
5878 NEIGHBOR_ADDR_STR2
5879 "Maximum number of prefix accept from this peer\n"
5880 "maximum no. of prefix limit\n")
5881{
d62a17ae 5882 int idx_peer = 1;
5883 int idx_number = 3;
5884 return peer_maximum_prefix_set_vty(
5885 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5886 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5887}
5888
d62a17ae 5889ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5891 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5892 "Maximum number of prefix accept from this peer\n"
5893 "maximum no. of prefix limit\n")
596c17ba 5894
e0701b79 5895DEFUN (neighbor_maximum_prefix_threshold,
5896 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5897 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5898 NEIGHBOR_STR
5899 NEIGHBOR_ADDR_STR2
5900 "Maximum number of prefix accept from this peer\n"
5901 "maximum no. of prefix limit\n"
5902 "Threshold value (%) at which to generate a warning msg\n")
5903{
d62a17ae 5904 int idx_peer = 1;
5905 int idx_number = 3;
5906 int idx_number_2 = 4;
5907 return peer_maximum_prefix_set_vty(
5908 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5909 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5910}
e0701b79 5911
d62a17ae 5912ALIAS_HIDDEN(
5913 neighbor_maximum_prefix_threshold,
5914 neighbor_maximum_prefix_threshold_hidden_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5916 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5917 "Maximum number of prefix accept from this peer\n"
5918 "maximum no. of prefix limit\n"
5919 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5920
718e3744 5921DEFUN (neighbor_maximum_prefix_warning,
5922 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5923 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
5926 "Maximum number of prefix accept from this peer\n"
5927 "maximum no. of prefix limit\n"
5928 "Only give warning message when limit is exceeded\n")
5929{
d62a17ae 5930 int idx_peer = 1;
5931 int idx_number = 3;
5932 return peer_maximum_prefix_set_vty(
5933 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5934 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5935}
5936
d62a17ae 5937ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_warning,
5939 neighbor_maximum_prefix_warning_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefix accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Only give warning message when limit is exceeded\n")
596c17ba 5945
e0701b79 5946DEFUN (neighbor_maximum_prefix_threshold_warning,
5947 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5948 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5949 NEIGHBOR_STR
5950 NEIGHBOR_ADDR_STR2
5951 "Maximum number of prefix accept from this peer\n"
5952 "maximum no. of prefix limit\n"
5953 "Threshold value (%) at which to generate a warning msg\n"
5954 "Only give warning message when limit is exceeded\n")
5955{
d62a17ae 5956 int idx_peer = 1;
5957 int idx_number = 3;
5958 int idx_number_2 = 4;
5959 return peer_maximum_prefix_set_vty(
5960 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5961 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5962}
5963
d62a17ae 5964ALIAS_HIDDEN(
5965 neighbor_maximum_prefix_threshold_warning,
5966 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5967 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5968 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "Maximum number of prefix accept from this peer\n"
5970 "maximum no. of prefix limit\n"
5971 "Threshold value (%) at which to generate a warning msg\n"
5972 "Only give warning message when limit is exceeded\n")
596c17ba 5973
0a486e5f 5974DEFUN (neighbor_maximum_prefix_restart,
5975 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefix accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Restart bgp connection after limit is exceeded\n"
efd7904e 5982 "Restart interval in minutes\n")
0a486e5f 5983{
d62a17ae 5984 int idx_peer = 1;
5985 int idx_number = 3;
5986 int idx_number_2 = 5;
5987 return peer_maximum_prefix_set_vty(
5988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5989 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5990}
5991
d62a17ae 5992ALIAS_HIDDEN(
5993 neighbor_maximum_prefix_restart,
5994 neighbor_maximum_prefix_restart_hidden_cmd,
5995 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5997 "Maximum number of prefix accept from this peer\n"
5998 "maximum no. of prefix limit\n"
5999 "Restart bgp connection after limit is exceeded\n"
efd7904e 6000 "Restart interval in minutes\n")
596c17ba 6001
0a486e5f 6002DEFUN (neighbor_maximum_prefix_threshold_restart,
6003 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
16cedbb0 6007 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6008 "maximum no. of prefix limit\n"
6009 "Threshold value (%) at which to generate a warning msg\n"
6010 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6011 "Restart interval in minutes\n")
0a486e5f 6012{
d62a17ae 6013 int idx_peer = 1;
6014 int idx_number = 3;
6015 int idx_number_2 = 4;
6016 int idx_number_3 = 6;
6017 return peer_maximum_prefix_set_vty(
6018 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6019 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6020 argv[idx_number_3]->arg);
6021}
6022
6023ALIAS_HIDDEN(
6024 neighbor_maximum_prefix_threshold_restart,
6025 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6026 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6027 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6028 "Maximum number of prefixes to accept from this peer\n"
6029 "maximum no. of prefix limit\n"
6030 "Threshold value (%) at which to generate a warning msg\n"
6031 "Restart bgp connection after limit is exceeded\n"
6032 "Restart interval in minutes\n")
596c17ba 6033
718e3744 6034DEFUN (no_neighbor_maximum_prefix,
6035 no_neighbor_maximum_prefix_cmd,
d04c479d 6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6037 NO_STR
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
16cedbb0 6040 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6041 "maximum no. of prefix limit\n"
6042 "Threshold value (%) at which to generate a warning msg\n"
6043 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6044 "Restart interval in minutes\n"
31500417 6045 "Only give warning message when limit is exceeded\n")
718e3744 6046{
d62a17ae 6047 int idx_peer = 2;
6048 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6049 bgp_node_afi(vty),
6050 bgp_node_safi(vty));
718e3744 6051}
e52702f2 6052
d62a17ae 6053ALIAS_HIDDEN(
6054 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6056 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6057 "Maximum number of prefixes to accept from this peer\n"
6058 "maximum no. of prefix limit\n"
6059 "Threshold value (%) at which to generate a warning msg\n"
6060 "Restart bgp connection after limit is exceeded\n"
6061 "Restart interval in minutes\n"
6062 "Only give warning message when limit is exceeded\n")
596c17ba 6063
718e3744 6064
718e3744 6065/* "neighbor allowas-in" */
6066DEFUN (neighbor_allowas_in,
6067 neighbor_allowas_in_cmd,
fd8503f5 6068 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6069 NEIGHBOR_STR
6070 NEIGHBOR_ADDR_STR2
31500417 6071 "Accept as-path with my AS present in it\n"
0437e105 6072 "Number of occurences of AS number\n"
fd8503f5 6073 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6074{
d62a17ae 6075 int idx_peer = 1;
6076 int idx_number_origin = 3;
6077 int ret;
6078 int origin = 0;
6079 struct peer *peer;
6080 int allow_num = 0;
6081
6082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6083 if (!peer)
6084 return CMD_WARNING_CONFIG_FAILED;
6085
6086 if (argc <= idx_number_origin)
6087 allow_num = 3;
6088 else {
6089 if (argv[idx_number_origin]->type == WORD_TKN)
6090 origin = 1;
6091 else
6092 allow_num = atoi(argv[idx_number_origin]->arg);
6093 }
6094
6095 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6096 allow_num, origin);
6097
6098 return bgp_vty_return(vty, ret);
6099}
6100
6101ALIAS_HIDDEN(
6102 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6103 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6105 "Accept as-path with my AS present in it\n"
0437e105 6106 "Number of occurences of AS number\n"
d62a17ae 6107 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6108
718e3744 6109DEFUN (no_neighbor_allowas_in,
6110 no_neighbor_allowas_in_cmd,
fd8503f5 6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6112 NO_STR
6113 NEIGHBOR_STR
6114 NEIGHBOR_ADDR_STR2
8334fd5a 6115 "allow local ASN appears in aspath attribute\n"
0437e105 6116 "Number of occurences of AS number\n"
fd8503f5 6117 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6118{
d62a17ae 6119 int idx_peer = 2;
6120 int ret;
6121 struct peer *peer;
718e3744 6122
d62a17ae 6123 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6124 if (!peer)
6125 return CMD_WARNING_CONFIG_FAILED;
718e3744 6126
d62a17ae 6127 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6128 bgp_node_safi(vty));
718e3744 6129
d62a17ae 6130 return bgp_vty_return(vty, ret);
718e3744 6131}
6b0655a2 6132
d62a17ae 6133ALIAS_HIDDEN(
6134 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6135 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6136 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "allow local ASN appears in aspath attribute\n"
0437e105 6138 "Number of occurences of AS number\n"
d62a17ae 6139 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6140
fa411a21
NH
6141DEFUN (neighbor_ttl_security,
6142 neighbor_ttl_security_cmd,
7ebe625c 6143 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6144 NEIGHBOR_STR
7ebe625c 6145 NEIGHBOR_ADDR_STR2
16cedbb0 6146 "BGP ttl-security parameters\n"
d7fa34c1
QY
6147 "Specify the maximum number of hops to the BGP peer\n"
6148 "Number of hops to BGP peer\n")
fa411a21 6149{
d62a17ae 6150 int idx_peer = 1;
6151 int idx_number = 4;
6152 struct peer *peer;
6153 int gtsm_hops;
6154
6155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6156 if (!peer)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6160
7ebe625c
QY
6161 /*
6162 * If 'neighbor swpX', then this is for directly connected peers,
6163 * we should not accept a ttl-security hops value greater than 1.
6164 */
6165 if (peer->conf_if && (gtsm_hops > 1)) {
6166 vty_out(vty,
6167 "%s is directly connected peer, hops cannot exceed 1\n",
6168 argv[idx_peer]->arg);
6169 return CMD_WARNING_CONFIG_FAILED;
6170 }
6171
d62a17ae 6172 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6173}
6174
6175DEFUN (no_neighbor_ttl_security,
6176 no_neighbor_ttl_security_cmd,
7ebe625c 6177 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6178 NO_STR
6179 NEIGHBOR_STR
7ebe625c 6180 NEIGHBOR_ADDR_STR2
16cedbb0 6181 "BGP ttl-security parameters\n"
3a2d747c
QY
6182 "Specify the maximum number of hops to the BGP peer\n"
6183 "Number of hops to BGP peer\n")
fa411a21 6184{
d62a17ae 6185 int idx_peer = 2;
6186 struct peer *peer;
fa411a21 6187
d62a17ae 6188 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6189 if (!peer)
6190 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6191
d62a17ae 6192 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6193}
6b0655a2 6194
adbac85e
DW
6195DEFUN (neighbor_addpath_tx_all_paths,
6196 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6197 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6198 NEIGHBOR_STR
6199 NEIGHBOR_ADDR_STR2
6200 "Use addpath to advertise all paths to a neighbor\n")
6201{
d62a17ae 6202 int idx_peer = 1;
6203 struct peer *peer;
adbac85e 6204
d62a17ae 6205 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6206 if (!peer)
6207 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6208
dcc68b5e
MS
6209 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6210 BGP_ADDPATH_ALL);
6211 return CMD_SUCCESS;
adbac85e
DW
6212}
6213
d62a17ae 6214ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6215 neighbor_addpath_tx_all_paths_hidden_cmd,
6216 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6217 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6218 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6219
adbac85e
DW
6220DEFUN (no_neighbor_addpath_tx_all_paths,
6221 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6223 NO_STR
6224 NEIGHBOR_STR
6225 NEIGHBOR_ADDR_STR2
6226 "Use addpath to advertise all paths to a neighbor\n")
6227{
d62a17ae 6228 int idx_peer = 2;
dcc68b5e
MS
6229 struct peer *peer;
6230
6231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6236 != BGP_ADDPATH_ALL) {
6237 vty_out(vty,
6238 "%% Peer not currently configured to transmit all paths.");
6239 return CMD_WARNING_CONFIG_FAILED;
6240 }
6241
6242 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6243 BGP_ADDPATH_NONE);
6244
6245 return CMD_SUCCESS;
adbac85e
DW
6246}
6247
d62a17ae 6248ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6249 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6252 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6253
06370dac
DW
6254DEFUN (neighbor_addpath_tx_bestpath_per_as,
6255 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6256 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6257 NEIGHBOR_STR
6258 NEIGHBOR_ADDR_STR2
6259 "Use addpath to advertise the bestpath per each neighboring AS\n")
6260{
d62a17ae 6261 int idx_peer = 1;
6262 struct peer *peer;
06370dac 6263
d62a17ae 6264 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6265 if (!peer)
6266 return CMD_WARNING_CONFIG_FAILED;
06370dac 6267
dcc68b5e
MS
6268 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6269 BGP_ADDPATH_BEST_PER_AS);
6270
6271 return CMD_SUCCESS;
06370dac
DW
6272}
6273
d62a17ae 6274ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6275 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6276 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6278 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6279
06370dac
DW
6280DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6281 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6283 NO_STR
6284 NEIGHBOR_STR
6285 NEIGHBOR_ADDR_STR2
6286 "Use addpath to advertise the bestpath per each neighboring AS\n")
6287{
d62a17ae 6288 int idx_peer = 2;
dcc68b5e
MS
6289 struct peer *peer;
6290
6291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6292 if (!peer)
6293 return CMD_WARNING_CONFIG_FAILED;
6294
6295 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6296 != BGP_ADDPATH_BEST_PER_AS) {
6297 vty_out(vty,
6298 "%% Peer not currently configured to transmit all best path per as.");
6299 return CMD_WARNING_CONFIG_FAILED;
6300 }
6301
6302 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6303 BGP_ADDPATH_NONE);
6304
6305 return CMD_SUCCESS;
06370dac
DW
6306}
6307
d62a17ae 6308ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6309 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6311 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6312 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6313
b9c7bc5a
PZ
6314static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6315 struct ecommunity **list)
ddb5b488 6316{
b9c7bc5a
PZ
6317 struct ecommunity *ecom = NULL;
6318 struct ecommunity *ecomadd;
ddb5b488 6319
b9c7bc5a 6320 for (; argc; --argc, ++argv) {
ddb5b488 6321
b9c7bc5a
PZ
6322 ecomadd = ecommunity_str2com(argv[0]->arg,
6323 ECOMMUNITY_ROUTE_TARGET, 0);
6324 if (!ecomadd) {
6325 vty_out(vty, "Malformed community-list value\n");
6326 if (ecom)
6327 ecommunity_free(&ecom);
6328 return CMD_WARNING_CONFIG_FAILED;
6329 }
ddb5b488 6330
b9c7bc5a
PZ
6331 if (ecom) {
6332 ecommunity_merge(ecom, ecomadd);
6333 ecommunity_free(&ecomadd);
6334 } else {
6335 ecom = ecomadd;
6336 }
6337 }
6338
6339 if (*list) {
6340 ecommunity_free(&*list);
ddb5b488 6341 }
b9c7bc5a
PZ
6342 *list = ecom;
6343
6344 return CMD_SUCCESS;
ddb5b488
PZ
6345}
6346
0ca70ba5
DS
6347/*
6348 * v2vimport is true if we are handling a `import vrf ...` command
6349 */
6350static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6351{
0ca70ba5
DS
6352 afi_t afi;
6353
ddb5b488 6354 switch (vty->node) {
b9c7bc5a 6355 case BGP_IPV4_NODE:
0ca70ba5
DS
6356 afi = AFI_IP;
6357 break;
b9c7bc5a 6358 case BGP_IPV6_NODE:
0ca70ba5
DS
6359 afi = AFI_IP6;
6360 break;
ddb5b488
PZ
6361 default:
6362 vty_out(vty,
b9c7bc5a 6363 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6364 return AFI_MAX;
ddb5b488 6365 }
69b07479 6366
0ca70ba5
DS
6367 if (!v2vimport) {
6368 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6369 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6370 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6371 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6372 vty_out(vty,
6373 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6374 return AFI_MAX;
6375 }
6376 } else {
6377 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6378 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6379 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6380 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6381 vty_out(vty,
6382 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6383 return AFI_MAX;
6384 }
6385 }
6386 return afi;
ddb5b488
PZ
6387}
6388
b9c7bc5a
PZ
6389DEFPY (af_rd_vpn_export,
6390 af_rd_vpn_export_cmd,
6391 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6392 NO_STR
ddb5b488 6393 "Specify route distinguisher\n"
b9c7bc5a
PZ
6394 "Between current address-family and vpn\n"
6395 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6396 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6397{
6398 VTY_DECLVAR_CONTEXT(bgp, bgp);
6399 struct prefix_rd prd;
6400 int ret;
ddb5b488 6401 afi_t afi;
b9c7bc5a
PZ
6402 int idx = 0;
6403 int yes = 1;
ddb5b488 6404
b9c7bc5a 6405 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6406 yes = 0;
b9c7bc5a
PZ
6407
6408 if (yes) {
6409 ret = str2prefix_rd(rd_str, &prd);
6410 if (!ret) {
6411 vty_out(vty, "%% Malformed rd\n");
6412 return CMD_WARNING_CONFIG_FAILED;
6413 }
ddb5b488
PZ
6414 }
6415
0ca70ba5 6416 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6417 if (afi == AFI_MAX)
6418 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6419
69b07479
DS
6420 /*
6421 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6422 */
6423 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6424 bgp_get_default(), bgp);
ddb5b488 6425
69b07479
DS
6426 if (yes) {
6427 bgp->vpn_policy[afi].tovpn_rd = prd;
6428 SET_FLAG(bgp->vpn_policy[afi].flags,
6429 BGP_VPN_POLICY_TOVPN_RD_SET);
6430 } else {
6431 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6432 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6433 }
6434
69b07479
DS
6435 /* post-change: re-export vpn routes */
6436 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6437 bgp_get_default(), bgp);
6438
ddb5b488
PZ
6439 return CMD_SUCCESS;
6440}
6441
b9c7bc5a
PZ
6442ALIAS (af_rd_vpn_export,
6443 af_no_rd_vpn_export_cmd,
6444 "no rd vpn export",
ddb5b488 6445 NO_STR
b9c7bc5a
PZ
6446 "Specify route distinguisher\n"
6447 "Between current address-family and vpn\n"
6448 "For routes leaked from current address-family to vpn\n")
ddb5b488 6449
b9c7bc5a
PZ
6450DEFPY (af_label_vpn_export,
6451 af_label_vpn_export_cmd,
e70e9f8e 6452 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6453 NO_STR
ddb5b488 6454 "label value for VRF\n"
b9c7bc5a
PZ
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6457 "Label Value <0-1048575>\n"
6458 "Automatically assign a label\n")
ddb5b488
PZ
6459{
6460 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6461 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6462 afi_t afi;
b9c7bc5a
PZ
6463 int idx = 0;
6464 int yes = 1;
6465
6466 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6467 yes = 0;
ddb5b488 6468
21a16cc2
PZ
6469 /* If "no ...", squash trailing parameter */
6470 if (!yes)
6471 label_auto = NULL;
6472
e70e9f8e
PZ
6473 if (yes) {
6474 if (!label_auto)
6475 label = label_val; /* parser should force unsigned */
6476 }
ddb5b488 6477
0ca70ba5 6478 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6479 if (afi == AFI_MAX)
6480 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6481
e70e9f8e 6482
69b07479
DS
6483 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6484 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6485 /* no change */
6486 return CMD_SUCCESS;
e70e9f8e 6487
69b07479
DS
6488 /*
6489 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6490 */
6491 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6492 bgp_get_default(), bgp);
6493
6494 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6495 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6496
6497 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6498
6499 /*
6500 * label has previously been automatically
6501 * assigned by labelpool: release it
6502 *
6503 * NB if tovpn_label == MPLS_LABEL_NONE it
6504 * means the automatic assignment is in flight
6505 * and therefore the labelpool callback must
6506 * detect that the auto label is not needed.
6507 */
6508
6509 bgp_lp_release(LP_TYPE_VRF,
6510 &bgp->vpn_policy[afi],
6511 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6512 }
69b07479
DS
6513 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6514 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6515 }
ddb5b488 6516
69b07479
DS
6517 bgp->vpn_policy[afi].tovpn_label = label;
6518 if (label_auto) {
6519 SET_FLAG(bgp->vpn_policy[afi].flags,
6520 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6521 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6522 vpn_leak_label_callback);
ddb5b488
PZ
6523 }
6524
69b07479
DS
6525 /* post-change: re-export vpn routes */
6526 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6527 bgp_get_default(), bgp);
6528
ddb5b488
PZ
6529 return CMD_SUCCESS;
6530}
6531
b9c7bc5a
PZ
6532ALIAS (af_label_vpn_export,
6533 af_no_label_vpn_export_cmd,
6534 "no label vpn export",
6535 NO_STR
6536 "label value for VRF\n"
6537 "Between current address-family and vpn\n"
6538 "For routes leaked from current address-family to vpn\n")
ddb5b488 6539
b9c7bc5a
PZ
6540DEFPY (af_nexthop_vpn_export,
6541 af_nexthop_vpn_export_cmd,
6542 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6543 NO_STR
ddb5b488 6544 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6545 "Between current address-family and vpn\n"
6546 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6547 "IPv4 prefix\n"
6548 "IPv6 prefix\n")
6549{
6550 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6551 afi_t afi;
ddb5b488 6552 struct prefix p;
b9c7bc5a
PZ
6553 int idx = 0;
6554 int yes = 1;
ddb5b488 6555
b9c7bc5a 6556 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6557 yes = 0;
b9c7bc5a
PZ
6558
6559 if (yes) {
6560 if (!sockunion2hostprefix(nexthop_str, &p))
6561 return CMD_WARNING_CONFIG_FAILED;
6562 }
ddb5b488 6563
0ca70ba5 6564 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6565 if (afi == AFI_MAX)
6566 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6567
69b07479
DS
6568 /*
6569 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6570 */
6571 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6572 bgp_get_default(), bgp);
ddb5b488 6573
69b07479
DS
6574 if (yes) {
6575 bgp->vpn_policy[afi].tovpn_nexthop = p;
6576 SET_FLAG(bgp->vpn_policy[afi].flags,
6577 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6578 } else {
6579 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6580 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6581 }
6582
69b07479
DS
6583 /* post-change: re-export vpn routes */
6584 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6585 bgp_get_default(), bgp);
6586
ddb5b488
PZ
6587 return CMD_SUCCESS;
6588}
6589
b9c7bc5a
PZ
6590ALIAS (af_nexthop_vpn_export,
6591 af_no_nexthop_vpn_export_cmd,
6592 "no nexthop vpn export",
ddb5b488 6593 NO_STR
b9c7bc5a
PZ
6594 "Specify next hop to use for VRF advertised prefixes\n"
6595 "Between current address-family and vpn\n"
6596 "For routes leaked from current address-family to vpn\n")
ddb5b488 6597
b9c7bc5a 6598static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6599{
b9c7bc5a
PZ
6600 if (!strcmp(dstr, "import")) {
6601 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6602 } else if (!strcmp(dstr, "export")) {
6603 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6604 } else if (!strcmp(dstr, "both")) {
6605 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6606 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6607 } else {
6608 vty_out(vty, "%% direction parse error\n");
6609 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6610 }
ddb5b488
PZ
6611 return CMD_SUCCESS;
6612}
6613
b9c7bc5a
PZ
6614DEFPY (af_rt_vpn_imexport,
6615 af_rt_vpn_imexport_cmd,
6616 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6617 NO_STR
6618 "Specify route target list\n"
ddb5b488 6619 "Specify route target list\n"
b9c7bc5a
PZ
6620 "Between current address-family and vpn\n"
6621 "For routes leaked from vpn to current address-family: match any\n"
6622 "For routes leaked from current address-family to vpn: set\n"
6623 "both import: match any and export: set\n"
ddb5b488
PZ
6624 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6625{
6626 VTY_DECLVAR_CONTEXT(bgp, bgp);
6627 int ret;
6628 struct ecommunity *ecom = NULL;
6629 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6630 vpn_policy_direction_t dir;
6631 afi_t afi;
6632 int idx = 0;
b9c7bc5a 6633 int yes = 1;
ddb5b488 6634
b9c7bc5a 6635 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6636 yes = 0;
b9c7bc5a 6637
0ca70ba5 6638 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6639 if (afi == AFI_MAX)
6640 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6641
b9c7bc5a 6642 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6643 if (ret != CMD_SUCCESS)
6644 return ret;
6645
b9c7bc5a
PZ
6646 if (yes) {
6647 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6648 vty_out(vty, "%% Missing RTLIST\n");
6649 return CMD_WARNING_CONFIG_FAILED;
6650 }
6651 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6652 if (ret != CMD_SUCCESS) {
6653 return ret;
6654 }
ddb5b488
PZ
6655 }
6656
69b07479
DS
6657 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6658 if (!dodir[dir])
ddb5b488 6659 continue;
ddb5b488 6660
69b07479 6661 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6662
69b07479
DS
6663 if (yes) {
6664 if (bgp->vpn_policy[afi].rtlist[dir])
6665 ecommunity_free(
6666 &bgp->vpn_policy[afi].rtlist[dir]);
6667 bgp->vpn_policy[afi].rtlist[dir] =
6668 ecommunity_dup(ecom);
6669 } else {
6670 if (bgp->vpn_policy[afi].rtlist[dir])
6671 ecommunity_free(
6672 &bgp->vpn_policy[afi].rtlist[dir]);
6673 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6674 }
69b07479
DS
6675
6676 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6677 }
69b07479 6678
d555f3e9
PZ
6679 if (ecom)
6680 ecommunity_free(&ecom);
ddb5b488
PZ
6681
6682 return CMD_SUCCESS;
6683}
6684
b9c7bc5a
PZ
6685ALIAS (af_rt_vpn_imexport,
6686 af_no_rt_vpn_imexport_cmd,
6687 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6688 NO_STR
6689 "Specify route target list\n"
b9c7bc5a
PZ
6690 "Specify route target list\n"
6691 "Between current address-family and vpn\n"
6692 "For routes leaked from vpn to current address-family\n"
6693 "For routes leaked from current address-family to vpn\n"
6694 "both import and export\n")
6695
6696DEFPY (af_route_map_vpn_imexport,
6697 af_route_map_vpn_imexport_cmd,
6698/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6699 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6700 NO_STR
ddb5b488 6701 "Specify route map\n"
b9c7bc5a
PZ
6702 "Between current address-family and vpn\n"
6703 "For routes leaked from vpn to current address-family\n"
6704 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6705 "name of route-map\n")
6706{
6707 VTY_DECLVAR_CONTEXT(bgp, bgp);
6708 int ret;
6709 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6710 vpn_policy_direction_t dir;
6711 afi_t afi;
ddb5b488 6712 int idx = 0;
b9c7bc5a 6713 int yes = 1;
ddb5b488 6714
b9c7bc5a 6715 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6716 yes = 0;
b9c7bc5a 6717
0ca70ba5 6718 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6719 if (afi == AFI_MAX)
6720 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6721
b9c7bc5a 6722 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6723 if (ret != CMD_SUCCESS)
6724 return ret;
6725
69b07479
DS
6726 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6727 if (!dodir[dir])
ddb5b488 6728 continue;
ddb5b488 6729
69b07479 6730 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6731
69b07479
DS
6732 if (yes) {
6733 if (bgp->vpn_policy[afi].rmap_name[dir])
6734 XFREE(MTYPE_ROUTE_MAP_NAME,
6735 bgp->vpn_policy[afi].rmap_name[dir]);
6736 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6737 MTYPE_ROUTE_MAP_NAME, rmap_str);
6738 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6739 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6740 if (!bgp->vpn_policy[afi].rmap[dir])
6741 return CMD_SUCCESS;
6742 } else {
6743 if (bgp->vpn_policy[afi].rmap_name[dir])
6744 XFREE(MTYPE_ROUTE_MAP_NAME,
6745 bgp->vpn_policy[afi].rmap_name[dir]);
6746 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6747 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6748 }
69b07479
DS
6749
6750 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6751 }
6752
6753 return CMD_SUCCESS;
6754}
6755
b9c7bc5a
PZ
6756ALIAS (af_route_map_vpn_imexport,
6757 af_no_route_map_vpn_imexport_cmd,
6758 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6759 NO_STR
6760 "Specify route map\n"
b9c7bc5a
PZ
6761 "Between current address-family and vpn\n"
6762 "For routes leaked from vpn to current address-family\n"
6763 "For routes leaked from current address-family to vpn\n")
6764
bb4f6190
DS
6765DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6766 "[no] import vrf route-map RMAP$rmap_str",
6767 NO_STR
6768 "Import routes from another VRF\n"
6769 "Vrf routes being filtered\n"
6770 "Specify route map\n"
6771 "name of route-map\n")
6772{
6773 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6774 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6775 afi_t afi;
6776 int idx = 0;
6777 int yes = 1;
6778 struct bgp *bgp_default;
6779
6780 if (argv_find(argv, argc, "no", &idx))
6781 yes = 0;
6782
0ca70ba5 6783 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6784 if (afi == AFI_MAX)
6785 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6786
6787 bgp_default = bgp_get_default();
6788 if (!bgp_default) {
6789 int32_t ret;
6790 as_t as = bgp->as;
6791
6792 /* Auto-create assuming the same AS */
6793 ret = bgp_get(&bgp_default, &as, NULL,
6794 BGP_INSTANCE_TYPE_DEFAULT);
6795
6796 if (ret) {
6797 vty_out(vty,
6798 "VRF default is not configured as a bgp instance\n");
6799 return CMD_WARNING;
6800 }
6801 }
6802
69b07479 6803 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6804
69b07479
DS
6805 if (yes) {
6806 if (bgp->vpn_policy[afi].rmap_name[dir])
6807 XFREE(MTYPE_ROUTE_MAP_NAME,
6808 bgp->vpn_policy[afi].rmap_name[dir]);
6809 bgp->vpn_policy[afi].rmap_name[dir] =
6810 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6811 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6812 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6813 if (!bgp->vpn_policy[afi].rmap[dir])
6814 return CMD_SUCCESS;
6815 } else {
6816 if (bgp->vpn_policy[afi].rmap_name[dir])
6817 XFREE(MTYPE_ROUTE_MAP_NAME,
6818 bgp->vpn_policy[afi].rmap_name[dir]);
6819 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6820 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6821 }
6822
69b07479
DS
6823 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6824
bb4f6190
DS
6825 return CMD_SUCCESS;
6826}
6827
6828ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6829 "no import vrf route-map",
6830 NO_STR
6831 "Import routes from another VRF\n"
6832 "Vrf routes being filtered\n"
6833 "Specify route map\n")
6834
4d1b335c
DA
6835DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6836 "[no] import vrf VIEWVRFNAME$import_name",
6837 NO_STR
6838 "Import routes from another VRF\n"
6839 "VRF to import from\n"
6840 "The name of the VRF\n")
12a844a5
DS
6841{
6842 VTY_DECLVAR_CONTEXT(bgp, bgp);
6843 struct listnode *node;
79ef8664
DS
6844 struct bgp *vrf_bgp, *bgp_default;
6845 int32_t ret = 0;
6846 as_t as = bgp->as;
12a844a5
DS
6847 bool remove = false;
6848 int32_t idx = 0;
6849 char *vname;
a8dadcf6 6850 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6851 safi_t safi;
6852 afi_t afi;
6853
867f0cca 6854 if (import_name == NULL) {
6855 vty_out(vty, "%% Missing import name\n");
6856 return CMD_WARNING;
6857 }
6858
12a844a5
DS
6859 if (argv_find(argv, argc, "no", &idx))
6860 remove = true;
6861
0ca70ba5
DS
6862 afi = vpn_policy_getafi(vty, bgp, true);
6863 if (afi == AFI_MAX)
6864 return CMD_WARNING_CONFIG_FAILED;
6865
12a844a5
DS
6866 safi = bgp_node_safi(vty);
6867
25679caa 6868 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6869 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6870 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6871 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6872 remove ? "unimport" : "import", import_name);
6873 return CMD_WARNING;
6874 }
6875
79ef8664
DS
6876 bgp_default = bgp_get_default();
6877 if (!bgp_default) {
6878 /* Auto-create assuming the same AS */
6879 ret = bgp_get(&bgp_default, &as, NULL,
6880 BGP_INSTANCE_TYPE_DEFAULT);
6881
6882 if (ret) {
6883 vty_out(vty,
6884 "VRF default is not configured as a bgp instance\n");
6885 return CMD_WARNING;
6886 }
6887 }
6888
12a844a5
DS
6889 vrf_bgp = bgp_lookup_by_name(import_name);
6890 if (!vrf_bgp) {
5742e42b 6891 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6892 vrf_bgp = bgp_default;
6893 else
0fb8d6e6
DS
6894 /* Auto-create assuming the same AS */
6895 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6896
6e2c7fe6 6897 if (ret) {
020a3f60
DS
6898 vty_out(vty,
6899 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
6900 import_name);
6901 return CMD_WARNING;
6902 }
12a844a5
DS
6903 }
6904
12a844a5 6905 if (remove) {
44338987 6906 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 6907 } else {
44338987 6908 /* Already importing from "import_vrf"? */
12a844a5
DS
6909 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6910 vname)) {
6911 if (strcmp(vname, import_name) == 0)
6912 return CMD_WARNING;
6913 }
6914
44338987 6915 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
6916 }
6917
6918 return CMD_SUCCESS;
6919}
6920
b9c7bc5a
PZ
6921/* This command is valid only in a bgp vrf instance or the default instance */
6922DEFPY (bgp_imexport_vpn,
6923 bgp_imexport_vpn_cmd,
6924 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
6925 NO_STR
6926 "Import routes to this address-family\n"
6927 "Export routes from this address-family\n"
6928 "to/from default instance VPN RIB\n")
ddb5b488
PZ
6929{
6930 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6931 int previous_state;
ddb5b488 6932 afi_t afi;
b9c7bc5a 6933 safi_t safi;
ddb5b488 6934 int idx = 0;
b9c7bc5a
PZ
6935 int yes = 1;
6936 int flag;
6937 vpn_policy_direction_t dir;
ddb5b488 6938
b9c7bc5a 6939 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6940 yes = 0;
ddb5b488 6941
b9c7bc5a
PZ
6942 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6943 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6944
b9c7bc5a
PZ
6945 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6946 return CMD_WARNING_CONFIG_FAILED;
6947 }
ddb5b488 6948
b9c7bc5a
PZ
6949 afi = bgp_node_afi(vty);
6950 safi = bgp_node_safi(vty);
6951 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6952 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6953 return CMD_WARNING_CONFIG_FAILED;
6954 }
ddb5b488 6955
b9c7bc5a
PZ
6956 if (!strcmp(direction_str, "import")) {
6957 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6958 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6959 } else if (!strcmp(direction_str, "export")) {
6960 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6961 dir = BGP_VPN_POLICY_DIR_TOVPN;
6962 } else {
6963 vty_out(vty, "%% unknown direction %s\n", direction_str);
6964 return CMD_WARNING_CONFIG_FAILED;
6965 }
6966
6967 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6968
b9c7bc5a
PZ
6969 if (yes) {
6970 SET_FLAG(bgp->af_flags[afi][safi], flag);
6971 if (!previous_state) {
6972 /* trigger export current vrf */
ddb5b488
PZ
6973 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6974 }
b9c7bc5a
PZ
6975 } else {
6976 if (previous_state) {
6977 /* trigger un-export current vrf */
6978 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6979 }
6980 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6981 }
6982
6983 return CMD_SUCCESS;
6984}
6985
301ad80a
PG
6986DEFPY (af_routetarget_import,
6987 af_routetarget_import_cmd,
6988 "[no] <rt|route-target> redirect import RTLIST...",
6989 NO_STR
6990 "Specify route target list\n"
6991 "Specify route target list\n"
6992 "Flow-spec redirect type route target\n"
6993 "Import routes to this address-family\n"
6994 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6995{
6996 VTY_DECLVAR_CONTEXT(bgp, bgp);
6997 int ret;
6998 struct ecommunity *ecom = NULL;
301ad80a
PG
6999 afi_t afi;
7000 int idx = 0;
7001 int yes = 1;
7002
7003 if (argv_find(argv, argc, "no", &idx))
7004 yes = 0;
7005
0ca70ba5 7006 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7007 if (afi == AFI_MAX)
7008 return CMD_WARNING_CONFIG_FAILED;
7009
301ad80a
PG
7010 if (yes) {
7011 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7012 vty_out(vty, "%% Missing RTLIST\n");
7013 return CMD_WARNING_CONFIG_FAILED;
7014 }
7015 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7016 if (ret != CMD_SUCCESS)
7017 return ret;
7018 }
69b07479
DS
7019
7020 if (yes) {
7021 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7022 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7023 .import_redirect_rtlist);
69b07479
DS
7024 bgp->vpn_policy[afi].import_redirect_rtlist =
7025 ecommunity_dup(ecom);
7026 } else {
7027 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7028 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7029 .import_redirect_rtlist);
69b07479 7030 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7031 }
69b07479 7032
301ad80a
PG
7033 if (ecom)
7034 ecommunity_free(&ecom);
7035
7036 return CMD_SUCCESS;
7037}
7038
505e5056 7039DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7040 address_family_ipv4_safi_cmd,
7041 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7042 "Enter Address Family command mode\n"
7043 "Address Family\n"
7044 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7045{
f51bae9c 7046
d62a17ae 7047 if (argc == 3) {
2131d5cf 7048 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7049 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7050 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7051 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7052 && safi != SAFI_EVPN) {
31947174
MK
7053 vty_out(vty,
7054 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7055 return CMD_WARNING_CONFIG_FAILED;
7056 }
d62a17ae 7057 vty->node = bgp_node_type(AFI_IP, safi);
7058 } else
7059 vty->node = BGP_IPV4_NODE;
718e3744 7060
d62a17ae 7061 return CMD_SUCCESS;
718e3744 7062}
7063
505e5056 7064DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7065 address_family_ipv6_safi_cmd,
7066 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7067 "Enter Address Family command mode\n"
7068 "Address Family\n"
7069 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7070{
d62a17ae 7071 if (argc == 3) {
2131d5cf 7072 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7073 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7074 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7075 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7076 && safi != SAFI_EVPN) {
31947174
MK
7077 vty_out(vty,
7078 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7079 return CMD_WARNING_CONFIG_FAILED;
7080 }
d62a17ae 7081 vty->node = bgp_node_type(AFI_IP6, safi);
7082 } else
7083 vty->node = BGP_IPV6_NODE;
25ffbdc1 7084
d62a17ae 7085 return CMD_SUCCESS;
25ffbdc1 7086}
718e3744 7087
d6902373 7088#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7089DEFUN_NOSH (address_family_vpnv4,
718e3744 7090 address_family_vpnv4_cmd,
8334fd5a 7091 "address-family vpnv4 [unicast]",
718e3744 7092 "Enter Address Family command mode\n"
8c3deaae 7093 "Address Family\n"
3a2d747c 7094 "Address Family modifier\n")
718e3744 7095{
d62a17ae 7096 vty->node = BGP_VPNV4_NODE;
7097 return CMD_SUCCESS;
718e3744 7098}
7099
505e5056 7100DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7101 address_family_vpnv6_cmd,
8334fd5a 7102 "address-family vpnv6 [unicast]",
8ecd3266 7103 "Enter Address Family command mode\n"
8c3deaae 7104 "Address Family\n"
3a2d747c 7105 "Address Family modifier\n")
8ecd3266 7106{
d62a17ae 7107 vty->node = BGP_VPNV6_NODE;
7108 return CMD_SUCCESS;
8ecd3266 7109}
64e4a6c5 7110#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7111
505e5056 7112DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7113 address_family_evpn_cmd,
7111c1a0 7114 "address-family l2vpn evpn",
4e0b7b6d 7115 "Enter Address Family command mode\n"
7111c1a0
QY
7116 "Address Family\n"
7117 "Address Family modifier\n")
4e0b7b6d 7118{
2131d5cf 7119 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7120 vty->node = BGP_EVPN_NODE;
7121 return CMD_SUCCESS;
4e0b7b6d
PG
7122}
7123
505e5056 7124DEFUN_NOSH (exit_address_family,
718e3744 7125 exit_address_family_cmd,
7126 "exit-address-family",
7127 "Exit from Address Family configuration mode\n")
7128{
d62a17ae 7129 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7130 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7131 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7132 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7133 || vty->node == BGP_EVPN_NODE
7134 || vty->node == BGP_FLOWSPECV4_NODE
7135 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7136 vty->node = BGP_NODE;
7137 return CMD_SUCCESS;
718e3744 7138}
6b0655a2 7139
8ad7271d 7140/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7141static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7142 const char *ip_str, afi_t afi, safi_t safi,
7143 struct prefix_rd *prd)
7144{
7145 int ret;
7146 struct prefix match;
7147 struct bgp_node *rn;
7148 struct bgp_node *rm;
7149 struct bgp *bgp;
7150 struct bgp_table *table;
7151 struct bgp_table *rib;
7152
7153 /* BGP structure lookup. */
7154 if (view_name) {
7155 bgp = bgp_lookup_by_name(view_name);
7156 if (bgp == NULL) {
7157 vty_out(vty, "%% Can't find BGP instance %s\n",
7158 view_name);
7159 return CMD_WARNING;
7160 }
7161 } else {
7162 bgp = bgp_get_default();
7163 if (bgp == NULL) {
7164 vty_out(vty, "%% No BGP process is configured\n");
7165 return CMD_WARNING;
7166 }
7167 }
7168
7169 /* Check IP address argument. */
7170 ret = str2prefix(ip_str, &match);
7171 if (!ret) {
7172 vty_out(vty, "%% address is malformed\n");
7173 return CMD_WARNING;
7174 }
7175
7176 match.family = afi2family(afi);
7177 rib = bgp->rib[afi][safi];
7178
7179 if (safi == SAFI_MPLS_VPN) {
7180 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7181 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7182 continue;
7183
67009e22
DS
7184 table = bgp_node_get_bgp_table_info(rn);
7185 if (table != NULL) {
7186
d62a17ae 7187 if ((rm = bgp_node_match(table, &match))
7188 != NULL) {
7189 if (rm->p.prefixlen
7190 == match.prefixlen) {
343cdb61 7191 SET_FLAG(rm->flags,
d62a17ae 7192 BGP_NODE_USER_CLEAR);
7193 bgp_process(bgp, rm, afi, safi);
7194 }
7195 bgp_unlock_node(rm);
7196 }
7197 }
7198 }
7199 } else {
7200 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7201 if (rn->p.prefixlen == match.prefixlen) {
7202 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7203 bgp_process(bgp, rn, afi, safi);
7204 }
7205 bgp_unlock_node(rn);
7206 }
7207 }
7208
7209 return CMD_SUCCESS;
8ad7271d
DS
7210}
7211
b09b5ae0 7212/* one clear bgp command to rule them all */
718e3744 7213DEFUN (clear_ip_bgp_all,
7214 clear_ip_bgp_all_cmd,
d7b9898c 7215 "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 7216 CLEAR_STR
7217 IP_STR
7218 BGP_STR
838758ac 7219 BGP_INSTANCE_HELP_STR
510afcd6 7220 BGP_AFI_HELP_STR
fd5e7b70 7221 "Address Family\n"
510afcd6 7222 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7223 "Address Family modifier\n"
b09b5ae0
DW
7224 "Clear all peers\n"
7225 "BGP neighbor address to clear\n"
a80beece 7226 "BGP IPv6 neighbor to clear\n"
838758ac 7227 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7228 "Clear peers with the AS number\n"
7229 "Clear all external peers\n"
718e3744 7230 "Clear all members of peer-group\n"
b09b5ae0 7231 "BGP peer-group name\n"
b09b5ae0
DW
7232 BGP_SOFT_STR
7233 BGP_SOFT_IN_STR
b09b5ae0
DW
7234 BGP_SOFT_OUT_STR
7235 BGP_SOFT_IN_STR
7236 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7237 BGP_SOFT_OUT_STR)
718e3744 7238{
d62a17ae 7239 char *vrf = NULL;
7240
7241 afi_t afi = AFI_IP6;
7242 safi_t safi = SAFI_UNICAST;
7243 enum clear_sort clr_sort = clear_peer;
7244 enum bgp_clear_type clr_type;
7245 char *clr_arg = NULL;
7246
7247 int idx = 0;
7248
7249 /* clear [ip] bgp */
7250 if (argv_find(argv, argc, "ip", &idx))
7251 afi = AFI_IP;
7252
9a8bdf1c
PG
7253 /* [<vrf> VIEWVRFNAME] */
7254 if (argv_find(argv, argc, "vrf", &idx)) {
7255 vrf = argv[idx + 1]->arg;
7256 idx += 2;
7257 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7258 vrf = NULL;
7259 } else if (argv_find(argv, argc, "view", &idx)) {
7260 /* [<view> VIEWVRFNAME] */
d62a17ae 7261 vrf = argv[idx + 1]->arg;
7262 idx += 2;
7263 }
d62a17ae 7264 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7265 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7266 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7267
d7b9898c 7268 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 7269 if (argv_find(argv, argc, "*", &idx)) {
7270 clr_sort = clear_all;
7271 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7272 clr_sort = clear_peer;
7273 clr_arg = argv[idx]->arg;
7274 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7275 clr_sort = clear_peer;
7276 clr_arg = argv[idx]->arg;
7277 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7278 clr_sort = clear_group;
7279 idx++;
7280 clr_arg = argv[idx]->arg;
d7b9898c 7281 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 7282 clr_sort = clear_peer;
7283 clr_arg = argv[idx]->arg;
8fa7d444
DS
7284 } else if (argv_find(argv, argc, "WORD", &idx)) {
7285 clr_sort = clear_peer;
7286 clr_arg = argv[idx]->arg;
d62a17ae 7287 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7288 clr_sort = clear_as;
7289 clr_arg = argv[idx]->arg;
7290 } else if (argv_find(argv, argc, "external", &idx)) {
7291 clr_sort = clear_external;
7292 }
7293
7294 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7295 if (argv_find(argv, argc, "soft", &idx)) {
7296 if (argv_find(argv, argc, "in", &idx)
7297 || argv_find(argv, argc, "out", &idx))
7298 clr_type = strmatch(argv[idx]->text, "in")
7299 ? BGP_CLEAR_SOFT_IN
7300 : BGP_CLEAR_SOFT_OUT;
7301 else
7302 clr_type = BGP_CLEAR_SOFT_BOTH;
7303 } else if (argv_find(argv, argc, "in", &idx)) {
7304 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7305 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7306 : BGP_CLEAR_SOFT_IN;
7307 } else if (argv_find(argv, argc, "out", &idx)) {
7308 clr_type = BGP_CLEAR_SOFT_OUT;
7309 } else
7310 clr_type = BGP_CLEAR_SOFT_NONE;
7311
7312 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7313}
01080f7c 7314
8ad7271d
DS
7315DEFUN (clear_ip_bgp_prefix,
7316 clear_ip_bgp_prefix_cmd,
18c57037 7317 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7318 CLEAR_STR
7319 IP_STR
7320 BGP_STR
838758ac 7321 BGP_INSTANCE_HELP_STR
8ad7271d 7322 "Clear bestpath and re-advertise\n"
0c7b1b01 7323 "IPv4 prefix\n")
8ad7271d 7324{
d62a17ae 7325 char *vrf = NULL;
7326 char *prefix = NULL;
8ad7271d 7327
d62a17ae 7328 int idx = 0;
01080f7c 7329
d62a17ae 7330 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7331 if (argv_find(argv, argc, "vrf", &idx)) {
7332 vrf = argv[idx + 1]->arg;
7333 idx += 2;
7334 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7335 vrf = NULL;
7336 } else if (argv_find(argv, argc, "view", &idx)) {
7337 /* [<view> VIEWVRFNAME] */
7338 vrf = argv[idx + 1]->arg;
7339 idx += 2;
7340 }
0c7b1b01 7341
d62a17ae 7342 prefix = argv[argc - 1]->arg;
8ad7271d 7343
d62a17ae 7344 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7345}
8ad7271d 7346
b09b5ae0
DW
7347DEFUN (clear_bgp_ipv6_safi_prefix,
7348 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7349 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7350 CLEAR_STR
3a2d747c 7351 IP_STR
718e3744 7352 BGP_STR
8c3deaae 7353 "Address Family\n"
46f296b4 7354 BGP_SAFI_HELP_STR
b09b5ae0 7355 "Clear bestpath and re-advertise\n"
0c7b1b01 7356 "IPv6 prefix\n")
718e3744 7357{
9b475e76
PG
7358 int idx_safi = 0;
7359 int idx_ipv6_prefix = 0;
7360 safi_t safi = SAFI_UNICAST;
7361 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7362 argv[idx_ipv6_prefix]->arg : NULL;
7363
7364 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7365 return bgp_clear_prefix(
9b475e76
PG
7366 vty, NULL, prefix, AFI_IP6,
7367 safi, NULL);
838758ac 7368}
01080f7c 7369
b09b5ae0
DW
7370DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7371 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7372 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7373 CLEAR_STR
3a2d747c 7374 IP_STR
718e3744 7375 BGP_STR
838758ac 7376 BGP_INSTANCE_HELP_STR
8c3deaae 7377 "Address Family\n"
46f296b4 7378 BGP_SAFI_HELP_STR
b09b5ae0 7379 "Clear bestpath and re-advertise\n"
0c7b1b01 7380 "IPv6 prefix\n")
718e3744 7381{
9b475e76 7382 int idx_safi = 0;
9a8bdf1c 7383 int idx_vrfview = 0;
9b475e76
PG
7384 int idx_ipv6_prefix = 0;
7385 safi_t safi = SAFI_UNICAST;
7386 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7387 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7388 char *vrfview = NULL;
9b475e76 7389
9a8bdf1c
PG
7390 /* [<view|vrf> VIEWVRFNAME] */
7391 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7392 vrfview = argv[idx_vrfview + 1]->arg;
7393 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7394 vrfview = NULL;
7395 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7396 /* [<view> VIEWVRFNAME] */
7397 vrfview = argv[idx_vrfview + 1]->arg;
7398 }
9b475e76
PG
7399 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7400
d62a17ae 7401 return bgp_clear_prefix(
9b475e76
PG
7402 vty, vrfview, prefix,
7403 AFI_IP6, safi, NULL);
718e3744 7404}
7405
b09b5ae0
DW
7406DEFUN (show_bgp_views,
7407 show_bgp_views_cmd,
d6e3c605 7408 "show [ip] bgp views",
b09b5ae0 7409 SHOW_STR
d6e3c605 7410 IP_STR
01080f7c 7411 BGP_STR
b09b5ae0 7412 "Show the defined BGP views\n")
01080f7c 7413{
d62a17ae 7414 struct list *inst = bm->bgp;
7415 struct listnode *node;
7416 struct bgp *bgp;
01080f7c 7417
d62a17ae 7418 vty_out(vty, "Defined BGP views:\n");
7419 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7420 /* Skip VRFs. */
7421 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7422 continue;
7423 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7424 bgp->as);
7425 }
e52702f2 7426
d62a17ae 7427 return CMD_SUCCESS;
e0081f70
ML
7428}
7429
8386ac43 7430DEFUN (show_bgp_vrfs,
7431 show_bgp_vrfs_cmd,
d6e3c605 7432 "show [ip] bgp vrfs [json]",
8386ac43 7433 SHOW_STR
d6e3c605 7434 IP_STR
8386ac43 7435 BGP_STR
7436 "Show BGP VRFs\n"
9973d184 7437 JSON_STR)
8386ac43 7438{
fe1dc5a3 7439 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7440 struct list *inst = bm->bgp;
7441 struct listnode *node;
7442 struct bgp *bgp;
9f049418 7443 bool uj = use_json(argc, argv);
d62a17ae 7444 json_object *json = NULL;
7445 json_object *json_vrfs = NULL;
7446 int count = 0;
d62a17ae 7447
d62a17ae 7448 if (uj) {
7449 json = json_object_new_object();
7450 json_vrfs = json_object_new_object();
7451 }
7452
7453 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7454 const char *name, *type;
7455 struct peer *peer;
7fe96307 7456 struct listnode *node2, *nnode2;
d62a17ae 7457 int peers_cfg, peers_estb;
7458 json_object *json_vrf = NULL;
d62a17ae 7459
7460 /* Skip Views. */
7461 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7462 continue;
7463
7464 count++;
efb4077a 7465 if (!uj && count == 1) {
fe1dc5a3 7466 vty_out(vty,
efb4077a 7467 "%4s %-5s %-16s %9s %10s %-37s\n",
a4d82a8a 7468 "Type", "Id", "routerId", "#PeersVfg",
efb4077a
CS
7469 "#PeersEstb", "Name");
7470 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7471 "L3-VNI", "RouterMAC", "Interface");
7472 }
d62a17ae 7473
7474 peers_cfg = peers_estb = 0;
7475 if (uj)
7476 json_vrf = json_object_new_object();
7477
7478
7fe96307 7479 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7480 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7481 continue;
7482 peers_cfg++;
7483 if (peer->status == Established)
7484 peers_estb++;
7485 }
7486
7487 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7488 name = VRF_DEFAULT_NAME;
d62a17ae 7489 type = "DFLT";
7490 } else {
7491 name = bgp->name;
7492 type = "VRF";
7493 }
7494
a8bf7d9c 7495
d62a17ae 7496 if (uj) {
a4d82a8a
PZ
7497 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7498 ? -1
7499 : (int64_t)bgp->vrf_id;
d62a17ae 7500 json_object_string_add(json_vrf, "type", type);
7501 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7502 json_object_string_add(json_vrf, "routerId",
7503 inet_ntoa(bgp->router_id));
7504 json_object_int_add(json_vrf, "numConfiguredPeers",
7505 peers_cfg);
7506 json_object_int_add(json_vrf, "numEstablishedPeers",
7507 peers_estb);
7508
fe1dc5a3 7509 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7510 json_object_string_add(
7511 json_vrf, "rmac",
7512 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
7513 json_object_string_add(json_vrf, "interface",
7514 ifindex2ifname(bgp->l3vni_svi_ifindex,
7515 bgp->vrf_id));
d62a17ae 7516 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 7517 } else {
fe1dc5a3 7518 vty_out(vty,
efb4077a 7519 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
7520 type,
7521 bgp->vrf_id == VRF_UNKNOWN ? -1
7522 : (int)bgp->vrf_id,
7523 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
7524 peers_estb, name);
7525 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7526 bgp->l3vni,
7527 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7528 ifindex2ifname(bgp->l3vni_svi_ifindex,
7529 bgp->vrf_id));
7530 }
d62a17ae 7531 }
7532
7533 if (uj) {
7534 json_object_object_add(json, "vrfs", json_vrfs);
7535
7536 json_object_int_add(json, "totalVrfs", count);
7537
996c9314
LB
7538 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7539 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7540 json_object_free(json);
7541 } else {
7542 if (count)
7543 vty_out(vty,
7544 "\nTotal number of VRFs (including default): %d\n",
7545 count);
7546 }
7547
7548 return CMD_SUCCESS;
8386ac43 7549}
7550
48ecf8f5
DS
7551DEFUN (show_bgp_mac_hash,
7552 show_bgp_mac_hash_cmd,
7553 "show bgp mac hash",
7554 SHOW_STR
7555 BGP_STR
7556 "Mac Address\n"
7557 "Mac Address database\n")
7558{
7559 bgp_mac_dump_table(vty);
7560
7561 return CMD_SUCCESS;
7562}
acf71666 7563
e3b78da8 7564static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7565{
0291c246 7566 struct vty *vty = (struct vty *)args;
e3b78da8 7567 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7568
60466a63 7569 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7570 tip->refcnt);
7571}
7572
7573static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7574{
7575 vty_out(vty, "self nexthop database:\n");
af97a18b 7576 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7577
7578 vty_out(vty, "Tunnel-ip database:\n");
7579 hash_iterate(bgp->tip_hash,
e3b78da8 7580 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7581 vty);
7582}
7583
15c81ca4
DS
7584DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7585 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7586 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7587 "martian next-hops\n"
7588 "martian next-hop database\n")
acf71666 7589{
0291c246 7590 struct bgp *bgp = NULL;
15c81ca4 7591 int idx = 0;
9a8bdf1c
PG
7592 char *name = NULL;
7593
7594 /* [<vrf> VIEWVRFNAME] */
7595 if (argv_find(argv, argc, "vrf", &idx)) {
7596 name = argv[idx + 1]->arg;
7597 if (name && strmatch(name, VRF_DEFAULT_NAME))
7598 name = NULL;
7599 } else if (argv_find(argv, argc, "view", &idx))
7600 /* [<view> VIEWVRFNAME] */
7601 name = argv[idx + 1]->arg;
7602 if (name)
7603 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7604 else
7605 bgp = bgp_get_default();
acf71666 7606
acf71666
MK
7607 if (!bgp) {
7608 vty_out(vty, "%% No BGP process is configured\n");
7609 return CMD_WARNING;
7610 }
7611 bgp_show_martian_nexthops(vty, bgp);
7612
7613 return CMD_SUCCESS;
7614}
7615
f412b39a 7616DEFUN (show_bgp_memory,
4bf6a362 7617 show_bgp_memory_cmd,
7fa12b13 7618 "show [ip] bgp memory",
4bf6a362 7619 SHOW_STR
3a2d747c 7620 IP_STR
4bf6a362
PJ
7621 BGP_STR
7622 "Global BGP memory statistics\n")
7623{
d62a17ae 7624 char memstrbuf[MTYPE_MEMSTR_LEN];
7625 unsigned long count;
7626
7627 /* RIB related usage stats */
7628 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7629 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7630 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7631 count * sizeof(struct bgp_node)));
7632
7633 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7634 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7635 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7636 count * sizeof(struct bgp_path_info)));
d62a17ae 7637 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7638 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7639 count,
4b7e6066
DS
7640 mtype_memstr(
7641 memstrbuf, sizeof(memstrbuf),
7642 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7643
7644 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7645 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7646 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7647 count * sizeof(struct bgp_static)));
7648
7649 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7650 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7651 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7652 count * sizeof(struct bpacket)));
7653
7654 /* Adj-In/Out */
7655 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7656 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7658 count * sizeof(struct bgp_adj_in)));
7659 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7660 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7661 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7662 count * sizeof(struct bgp_adj_out)));
7663
7664 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7665 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7666 count,
7667 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7668 count * sizeof(struct bgp_nexthop_cache)));
7669
7670 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7671 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7672 count,
7673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7674 count * sizeof(struct bgp_damp_info)));
7675
7676 /* Attributes */
7677 count = attr_count();
7678 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7680 count * sizeof(struct attr)));
7681
7682 if ((count = attr_unknown_count()))
7683 vty_out(vty, "%ld unknown attributes\n", count);
7684
7685 /* AS_PATH attributes */
7686 count = aspath_count();
7687 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7688 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7689 count * sizeof(struct aspath)));
7690
7691 count = mtype_stats_alloc(MTYPE_AS_SEG);
7692 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7693 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct assegment)));
7695
7696 /* Other attributes */
7697 if ((count = community_count()))
7698 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7699 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7700 count * sizeof(struct community)));
d62a17ae 7701 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7702 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7703 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct ecommunity)));
d62a17ae 7705 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7706 vty_out(vty,
7707 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7708 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7709 count * sizeof(struct lcommunity)));
d62a17ae 7710
7711 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7712 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct cluster_list)));
7715
7716 /* Peer related usage */
7717 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7718 vty_out(vty, "%ld peers, using %s of memory\n", count,
7719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7720 count * sizeof(struct peer)));
7721
7722 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7723 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct peer_group)));
7726
7727 /* Other */
d62a17ae 7728 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7729 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7730 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(regex_t)));
d62a17ae 7732 return CMD_SUCCESS;
4bf6a362 7733}
fee0f4c6 7734
57a9c8a8
DS
7735static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7736{
7737 json_object *bestpath = json_object_new_object();
7738
7739 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7740 json_object_string_add(bestpath, "asPath", "ignore");
7741
7742 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7743 json_object_string_add(bestpath, "asPath", "confed");
7744
7745 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7746 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7747 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7748 "as-set");
7749 else
a4d82a8a 7750 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7751 "true");
7752 } else
a4d82a8a 7753 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7754
7755 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7756 json_object_string_add(bestpath, "compareRouterId", "true");
7757 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7758 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7759 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7760 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7761 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7762 json_object_string_add(bestpath, "med",
7763 "missing-as-worst");
7764 else
7765 json_object_string_add(bestpath, "med", "true");
7766 }
7767
7768 json_object_object_add(json, "bestPath", bestpath);
7769}
7770
718e3744 7771/* Show BGP peer's summary information. */
d62a17ae 7772static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
9f049418 7773 bool use_json, json_object *json)
d62a17ae 7774{
7775 struct peer *peer;
7776 struct listnode *node, *nnode;
7777 unsigned int count = 0, dn_count = 0;
7778 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7779 char neighbor_buf[VTY_BUFSIZ];
7780 int neighbor_col_default_width = 16;
7781 int len;
7782 int max_neighbor_width = 0;
7783 int pfx_rcd_safi;
7784 json_object *json_peer = NULL;
7785 json_object *json_peers = NULL;
50e05855 7786 struct peer_af *paf;
d62a17ae 7787
7788 /* labeled-unicast routes are installed in the unicast table so in order
7789 * to
7790 * display the correct PfxRcd value we must look at SAFI_UNICAST
7791 */
7792 if (safi == SAFI_LABELED_UNICAST)
7793 pfx_rcd_safi = SAFI_UNICAST;
7794 else
7795 pfx_rcd_safi = safi;
7796
7797 if (use_json) {
7798 if (json == NULL)
7799 json = json_object_new_object();
7800
7801 json_peers = json_object_new_object();
7802 } else {
7803 /* Loop over all neighbors that will be displayed to determine
7804 * how many
7805 * characters are needed for the Neighbor column
7806 */
7807 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7808 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7809 continue;
7810
7811 if (peer->afc[afi][safi]) {
7812 memset(dn_flag, '\0', sizeof(dn_flag));
7813 if (peer_dynamic_neighbor(peer))
7814 dn_flag[0] = '*';
7815
7816 if (peer->hostname
7817 && bgp_flag_check(bgp,
7818 BGP_FLAG_SHOW_HOSTNAME))
7819 sprintf(neighbor_buf, "%s%s(%s) ",
7820 dn_flag, peer->hostname,
7821 peer->host);
7822 else
7823 sprintf(neighbor_buf, "%s%s ", dn_flag,
7824 peer->host);
7825
7826 len = strlen(neighbor_buf);
7827
7828 if (len > max_neighbor_width)
7829 max_neighbor_width = len;
7830 }
7831 }
f933309e 7832
d62a17ae 7833 /* Originally we displayed the Neighbor column as 16
7834 * characters wide so make that the default
7835 */
7836 if (max_neighbor_width < neighbor_col_default_width)
7837 max_neighbor_width = neighbor_col_default_width;
7838 }
f933309e 7839
d62a17ae 7840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7841 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7842 continue;
7843
ea47320b
DL
7844 if (!peer->afc[afi][safi])
7845 continue;
d62a17ae 7846
ea47320b
DL
7847 if (!count) {
7848 unsigned long ents;
7849 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7850 int64_t vrf_id_ui;
d62a17ae 7851
a4d82a8a
PZ
7852 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7853 ? -1
7854 : (int64_t)bgp->vrf_id;
ea47320b
DL
7855
7856 /* Usage summary and header */
7857 if (use_json) {
7858 json_object_string_add(
7859 json, "routerId",
7860 inet_ntoa(bgp->router_id));
60466a63
QY
7861 json_object_int_add(json, "as", bgp->as);
7862 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7863 json_object_string_add(
7864 json, "vrfName",
7865 (bgp->inst_type
7866 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 7867 ? VRF_DEFAULT_NAME
ea47320b
DL
7868 : bgp->name);
7869 } else {
7870 vty_out(vty,
7871 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7872 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7873 bgp->vrf_id == VRF_UNKNOWN
7874 ? -1
7875 : (int)bgp->vrf_id);
ea47320b
DL
7876 vty_out(vty, "\n");
7877 }
d62a17ae 7878
ea47320b 7879 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7880 if (use_json) {
ea47320b 7881 json_object_int_add(
60466a63 7882 json, "updateDelayLimit",
ea47320b 7883 bgp->v_update_delay);
d62a17ae 7884
ea47320b
DL
7885 if (bgp->v_update_delay
7886 != bgp->v_establish_wait)
d62a17ae 7887 json_object_int_add(
7888 json,
ea47320b
DL
7889 "updateDelayEstablishWait",
7890 bgp->v_establish_wait);
d62a17ae 7891
60466a63 7892 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7893 json_object_string_add(
7894 json,
7895 "updateDelayFirstNeighbor",
7896 bgp->update_delay_begin_time);
7897 json_object_boolean_true_add(
7898 json,
7899 "updateDelayInProgress");
7900 } else {
7901 if (bgp->update_delay_over) {
d62a17ae 7902 json_object_string_add(
7903 json,
7904 "updateDelayFirstNeighbor",
7905 bgp->update_delay_begin_time);
ea47320b 7906 json_object_string_add(
d62a17ae 7907 json,
ea47320b
DL
7908 "updateDelayBestpathResumed",
7909 bgp->update_delay_end_time);
7910 json_object_string_add(
d62a17ae 7911 json,
ea47320b
DL
7912 "updateDelayZebraUpdateResume",
7913 bgp->update_delay_zebra_resume_time);
7914 json_object_string_add(
7915 json,
7916 "updateDelayPeerUpdateResume",
7917 bgp->update_delay_peers_resume_time);
d62a17ae 7918 }
ea47320b
DL
7919 }
7920 } else {
7921 vty_out(vty,
7922 "Read-only mode update-delay limit: %d seconds\n",
7923 bgp->v_update_delay);
7924 if (bgp->v_update_delay
7925 != bgp->v_establish_wait)
d62a17ae 7926 vty_out(vty,
ea47320b
DL
7927 " Establish wait: %d seconds\n",
7928 bgp->v_establish_wait);
d62a17ae 7929
60466a63 7930 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7931 vty_out(vty,
7932 " First neighbor established: %s\n",
7933 bgp->update_delay_begin_time);
7934 vty_out(vty,
7935 " Delay in progress\n");
7936 } else {
7937 if (bgp->update_delay_over) {
d62a17ae 7938 vty_out(vty,
7939 " First neighbor established: %s\n",
7940 bgp->update_delay_begin_time);
7941 vty_out(vty,
ea47320b
DL
7942 " Best-paths resumed: %s\n",
7943 bgp->update_delay_end_time);
7944 vty_out(vty,
7945 " zebra update resumed: %s\n",
7946 bgp->update_delay_zebra_resume_time);
7947 vty_out(vty,
7948 " peers update resumed: %s\n",
7949 bgp->update_delay_peers_resume_time);
d62a17ae 7950 }
7951 }
7952 }
ea47320b 7953 }
d62a17ae 7954
ea47320b
DL
7955 if (use_json) {
7956 if (bgp_maxmed_onstartup_configured(bgp)
7957 && bgp->maxmed_active)
7958 json_object_boolean_true_add(
60466a63 7959 json, "maxMedOnStartup");
ea47320b
DL
7960 if (bgp->v_maxmed_admin)
7961 json_object_boolean_true_add(
60466a63 7962 json, "maxMedAdministrative");
d62a17ae 7963
ea47320b
DL
7964 json_object_int_add(
7965 json, "tableVersion",
60466a63 7966 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7967
60466a63
QY
7968 ents = bgp_table_count(bgp->rib[afi][safi]);
7969 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7970 json_object_int_add(
7971 json, "ribMemory",
7972 ents * sizeof(struct bgp_node));
d62a17ae 7973
210ec2a0 7974 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
7975 json_object_int_add(json, "peerCount", ents);
7976 json_object_int_add(json, "peerMemory",
7977 ents * sizeof(struct peer));
d62a17ae 7978
ea47320b
DL
7979 if ((ents = listcount(bgp->group))) {
7980 json_object_int_add(
60466a63 7981 json, "peerGroupCount", ents);
ea47320b
DL
7982 json_object_int_add(
7983 json, "peerGroupMemory",
996c9314
LB
7984 ents * sizeof(struct
7985 peer_group));
ea47320b 7986 }
d62a17ae 7987
ea47320b
DL
7988 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7989 BGP_CONFIG_DAMPENING))
7990 json_object_boolean_true_add(
60466a63 7991 json, "dampeningEnabled");
ea47320b
DL
7992 } else {
7993 if (bgp_maxmed_onstartup_configured(bgp)
7994 && bgp->maxmed_active)
d62a17ae 7995 vty_out(vty,
ea47320b
DL
7996 "Max-med on-startup active\n");
7997 if (bgp->v_maxmed_admin)
d62a17ae 7998 vty_out(vty,
ea47320b 7999 "Max-med administrative active\n");
d62a17ae 8000
60466a63
QY
8001 vty_out(vty, "BGP table version %" PRIu64 "\n",
8002 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8003
60466a63 8004 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8005 vty_out(vty,
8006 "RIB entries %ld, using %s of memory\n",
8007 ents,
996c9314
LB
8008 mtype_memstr(memstrbuf,
8009 sizeof(memstrbuf),
8010 ents * sizeof(struct
8011 bgp_node)));
ea47320b
DL
8012
8013 /* Peer related usage */
210ec2a0 8014 ents = bgp->af_peer_count[afi][safi];
60466a63 8015 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8016 ents,
8017 mtype_memstr(
60466a63
QY
8018 memstrbuf, sizeof(memstrbuf),
8019 ents * sizeof(struct peer)));
ea47320b
DL
8020
8021 if ((ents = listcount(bgp->group)))
d62a17ae 8022 vty_out(vty,
ea47320b 8023 "Peer groups %ld, using %s of memory\n",
d62a17ae 8024 ents,
8025 mtype_memstr(
8026 memstrbuf,
8027 sizeof(memstrbuf),
996c9314
LB
8028 ents * sizeof(struct
8029 peer_group)));
d62a17ae 8030
ea47320b
DL
8031 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8032 BGP_CONFIG_DAMPENING))
60466a63 8033 vty_out(vty, "Dampening enabled.\n");
ea47320b 8034 vty_out(vty, "\n");
d62a17ae 8035
ea47320b
DL
8036 /* Subtract 8 here because 'Neighbor' is
8037 * 8 characters */
8038 vty_out(vty, "Neighbor");
60466a63
QY
8039 vty_out(vty, "%*s", max_neighbor_width - 8,
8040 " ");
ea47320b
DL
8041 vty_out(vty,
8042 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8043 }
ea47320b 8044 }
d62a17ae 8045
ea47320b 8046 count++;
d62a17ae 8047
ea47320b
DL
8048 if (use_json) {
8049 json_peer = json_object_new_object();
d62a17ae 8050
b4e9dcba
DD
8051 if (peer_dynamic_neighbor(peer)) {
8052 dn_count++;
60466a63
QY
8053 json_object_boolean_true_add(json_peer,
8054 "dynamicPeer");
b4e9dcba 8055 }
d62a17ae 8056
ea47320b 8057 if (peer->hostname)
60466a63 8058 json_object_string_add(json_peer, "hostname",
ea47320b 8059 peer->hostname);
d62a17ae 8060
ea47320b 8061 if (peer->domainname)
60466a63
QY
8062 json_object_string_add(json_peer, "domainname",
8063 peer->domainname);
d62a17ae 8064
60466a63 8065 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 8066 json_object_int_add(json_peer, "version", 4);
60466a63 8067 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 8068 PEER_TOTAL_RX(peer));
60466a63 8069 json_object_int_add(json_peer, "msgSent",
0112e9e0 8070 PEER_TOTAL_TX(peer));
ea47320b
DL
8071
8072 json_object_int_add(json_peer, "tableVersion",
8073 peer->version[afi][safi]);
8074 json_object_int_add(json_peer, "outq",
8075 peer->obuf->count);
8076 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
8077 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8078 use_json, json_peer);
50e05855
AD
8079
8080 /*
8081 * Adding "pfxRcd" field to match with the corresponding
8082 * CLI. "prefixReceivedCount" will be deprecated in
8083 * future.
8084 */
60466a63
QY
8085 json_object_int_add(json_peer, "prefixReceivedCount",
8086 peer->pcount[afi][pfx_rcd_safi]);
50e05855
AD
8087 json_object_int_add(json_peer, "pfxRcd",
8088 peer->pcount[afi][pfx_rcd_safi]);
8089
8090 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8091 if (paf && PAF_SUBGRP(paf))
8092 json_object_int_add(json_peer,
8093 "pfxSnt",
8094 (PAF_SUBGRP(paf))->scount);
d62a17ae 8095
ea47320b 8096 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 8097 json_object_string_add(json_peer, "state",
ea47320b 8098 "Idle (Admin)");
9199a725
TM
8099 else if (peer->afc_recv[afi][safi])
8100 json_object_string_add(
8101 json_peer, "state",
8102 lookup_msg(bgp_status_msg, peer->status,
8103 NULL));
60466a63
QY
8104 else if (CHECK_FLAG(peer->sflags,
8105 PEER_STATUS_PREFIX_OVERFLOW))
8106 json_object_string_add(json_peer, "state",
ea47320b
DL
8107 "Idle (PfxCt)");
8108 else
8109 json_object_string_add(
8110 json_peer, "state",
60466a63
QY
8111 lookup_msg(bgp_status_msg, peer->status,
8112 NULL));
ea47320b
DL
8113
8114 if (peer->conf_if)
60466a63 8115 json_object_string_add(json_peer, "idType",
ea47320b
DL
8116 "interface");
8117 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8118 json_object_string_add(json_peer, "idType",
8119 "ipv4");
ea47320b 8120 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8121 json_object_string_add(json_peer, "idType",
8122 "ipv6");
d62a17ae 8123
ea47320b
DL
8124 json_object_object_add(json_peers, peer->host,
8125 json_peer);
8126 } else {
8127 memset(dn_flag, '\0', sizeof(dn_flag));
8128 if (peer_dynamic_neighbor(peer)) {
8129 dn_count++;
8130 dn_flag[0] = '*';
8131 }
d62a17ae 8132
ea47320b 8133 if (peer->hostname
60466a63 8134 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 8135 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 8136 peer->hostname, peer->host);
ea47320b 8137 else
60466a63 8138 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
8139
8140 /* pad the neighbor column with spaces */
8141 if (len < max_neighbor_width)
60466a63
QY
8142 vty_out(vty, "%*s", max_neighbor_width - len,
8143 " ");
ea47320b 8144
86a55b99 8145 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
8146 peer->as, PEER_TOTAL_RX(peer),
8147 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8148 0, peer->obuf->count,
d62a17ae 8149 peer_uptime(peer->uptime, timebuf,
ea47320b 8150 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 8151
ea47320b 8152 if (peer->status == Established)
2f8f4f10 8153 if (peer->afc_recv[afi][safi])
95077abf 8154 vty_out(vty, " %12ld",
a4d82a8a
PZ
8155 peer->pcount[afi]
8156 [pfx_rcd_safi]);
95077abf
DW
8157 else
8158 vty_out(vty, " NoNeg");
ea47320b 8159 else {
60466a63 8160 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 8161 vty_out(vty, " Idle (Admin)");
60466a63
QY
8162 else if (CHECK_FLAG(
8163 peer->sflags,
8164 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 8165 vty_out(vty, " Idle (PfxCt)");
d62a17ae 8166 else
ea47320b 8167 vty_out(vty, " %12s",
60466a63
QY
8168 lookup_msg(bgp_status_msg,
8169 peer->status, NULL));
d62a17ae 8170 }
ea47320b 8171 vty_out(vty, "\n");
d62a17ae 8172 }
8173 }
f933309e 8174
d62a17ae 8175 if (use_json) {
8176 json_object_object_add(json, "peers", json_peers);
8177
8178 json_object_int_add(json, "totalPeers", count);
8179 json_object_int_add(json, "dynamicPeers", dn_count);
8180
57a9c8a8
DS
8181 bgp_show_bestpath_json(bgp, json);
8182
996c9314
LB
8183 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8184 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8185 json_object_free(json);
8186 } else {
8187 if (count)
8188 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8189 else {
d6ceaca3 8190 vty_out(vty, "No %s neighbor is configured\n",
8191 afi_safi_print(afi, safi));
d62a17ae 8192 }
b05a1c8b 8193
d6ceaca3 8194 if (dn_count) {
d62a17ae 8195 vty_out(vty, "* - dynamic neighbor\n");
8196 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8197 dn_count, bgp->dynamic_neighbors_limit);
8198 }
8199 }
1ff9a340 8200
d62a17ae 8201 return CMD_SUCCESS;
718e3744 8202}
8203
d62a17ae 8204static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
f86897b9 8205 int safi, bool use_json)
d62a17ae 8206{
8207 int is_first = 1;
8208 int afi_wildcard = (afi == AFI_MAX);
8209 int safi_wildcard = (safi == SAFI_MAX);
8210 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8211 bool nbr_output = false;
f86897b9 8212 json_object *json = NULL;
d62a17ae 8213
8214 if (use_json && is_wildcard)
8215 vty_out(vty, "{\n");
8216 if (afi_wildcard)
8217 afi = 1; /* AFI_IP */
8218 while (afi < AFI_MAX) {
8219 if (safi_wildcard)
8220 safi = 1; /* SAFI_UNICAST */
8221 while (safi < SAFI_MAX) {
318cac96 8222 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8223 nbr_output = true;
f86897b9
DS
8224
8225 if (use_json)
8226 json = json_object_new_object();
8227
d62a17ae 8228 if (is_wildcard) {
8229 /*
8230 * So limit output to those afi/safi
8231 * pairs that
8232 * actualy have something interesting in
8233 * them
8234 */
8235 if (use_json) {
d62a17ae 8236 if (!is_first)
8237 vty_out(vty, ",\n");
8238 else
8239 is_first = 0;
8240
8241 vty_out(vty, "\"%s\":",
8242 afi_safi_json(afi,
8243 safi));
8244 } else {
8245 vty_out(vty, "\n%s Summary:\n",
8246 afi_safi_print(afi,
8247 safi));
8248 }
8249 }
8250 bgp_show_summary(vty, bgp, afi, safi, use_json,
8251 json);
8252 }
8253 safi++;
d62a17ae 8254 if (!safi_wildcard)
8255 safi = SAFI_MAX;
8256 }
8257 afi++;
ee851c8c 8258 if (!afi_wildcard)
d62a17ae 8259 afi = AFI_MAX;
8260 }
8261
8262 if (use_json && is_wildcard)
8263 vty_out(vty, "}\n");
ca61fd25
DS
8264 else if (!nbr_output) {
8265 if (use_json)
8266 vty_out(vty, "{}\n");
8267 else
8268 vty_out(vty, "%% No BGP neighbors found\n");
8269 }
d62a17ae 8270}
8271
8272static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
9f049418 8273 safi_t safi, bool use_json)
d62a17ae 8274{
8275 struct listnode *node, *nnode;
8276 struct bgp *bgp;
d62a17ae 8277 int is_first = 1;
9f049418 8278 bool nbr_output = false;
d62a17ae 8279
8280 if (use_json)
8281 vty_out(vty, "{\n");
8282
8283 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8284 nbr_output = true;
d62a17ae 8285 if (use_json) {
d62a17ae 8286 if (!is_first)
8287 vty_out(vty, ",\n");
8288 else
8289 is_first = 0;
8290
8291 vty_out(vty, "\"%s\":",
8292 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8293 ? VRF_DEFAULT_NAME
d62a17ae 8294 : bgp->name);
8295 } else {
8296 vty_out(vty, "\nInstance %s:\n",
8297 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8298 ? VRF_DEFAULT_NAME
d62a17ae 8299 : bgp->name);
8300 }
f86897b9 8301 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json);
d62a17ae 8302 }
8303
8304 if (use_json)
8305 vty_out(vty, "}\n");
9f049418
DS
8306 else if (!nbr_output)
8307 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8308}
8309
8310int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
9f049418 8311 safi_t safi, bool use_json)
d62a17ae 8312{
8313 struct bgp *bgp;
8314
8315 if (name) {
8316 if (strmatch(name, "all")) {
8317 bgp_show_all_instances_summary_vty(vty, afi, safi,
8318 use_json);
8319 return CMD_SUCCESS;
8320 } else {
8321 bgp = bgp_lookup_by_name(name);
8322
8323 if (!bgp) {
8324 if (use_json)
8325 vty_out(vty, "{}\n");
8326 else
8327 vty_out(vty,
ca61fd25 8328 "%% BGP instance not found\n");
d62a17ae 8329 return CMD_WARNING;
8330 }
8331
f86897b9
DS
8332 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
8333 use_json);
d62a17ae 8334 return CMD_SUCCESS;
8335 }
8336 }
8337
8338 bgp = bgp_get_default();
8339
8340 if (bgp)
f86897b9 8341 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json);
9f049418 8342 else {
ca61fd25
DS
8343 if (use_json)
8344 vty_out(vty, "{}\n");
8345 else
8346 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8347 return CMD_WARNING;
8348 }
d62a17ae 8349
8350 return CMD_SUCCESS;
4fb25c53
DW
8351}
8352
716b2d8a 8353/* `show [ip] bgp summary' commands. */
47fc97cc 8354DEFUN (show_ip_bgp_summary,
718e3744 8355 show_ip_bgp_summary_cmd,
dd6bd0f1 8356 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 8357 SHOW_STR
8358 IP_STR
8359 BGP_STR
8386ac43 8360 BGP_INSTANCE_HELP_STR
46f296b4 8361 BGP_AFI_HELP_STR
dd6bd0f1 8362 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8363 "Summary of BGP neighbor status\n"
9973d184 8364 JSON_STR)
718e3744 8365{
d62a17ae 8366 char *vrf = NULL;
8367 afi_t afi = AFI_MAX;
8368 safi_t safi = SAFI_MAX;
8369
8370 int idx = 0;
8371
8372 /* show [ip] bgp */
8373 if (argv_find(argv, argc, "ip", &idx))
8374 afi = AFI_IP;
9a8bdf1c
PG
8375 /* [<vrf> VIEWVRFNAME] */
8376 if (argv_find(argv, argc, "vrf", &idx)) {
8377 vrf = argv[idx + 1]->arg;
8378 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8379 vrf = NULL;
8380 } else if (argv_find(argv, argc, "view", &idx))
8381 /* [<view> VIEWVRFNAME] */
8382 vrf = argv[idx + 1]->arg;
d62a17ae 8383 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8384 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8385 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8386 }
8387
9f049418 8388 bool uj = use_json(argc, argv);
d62a17ae 8389
8390 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8391}
8392
8393const char *afi_safi_print(afi_t afi, safi_t safi)
8394{
8395 if (afi == AFI_IP && safi == SAFI_UNICAST)
8396 return "IPv4 Unicast";
8397 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8398 return "IPv4 Multicast";
8399 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8400 return "IPv4 Labeled Unicast";
8401 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8402 return "IPv4 VPN";
8403 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8404 return "IPv4 Encap";
7c40bf39 8405 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8406 return "IPv4 Flowspec";
d62a17ae 8407 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8408 return "IPv6 Unicast";
8409 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8410 return "IPv6 Multicast";
8411 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8412 return "IPv6 Labeled Unicast";
8413 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8414 return "IPv6 VPN";
8415 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8416 return "IPv6 Encap";
7c40bf39 8417 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8418 return "IPv6 Flowspec";
d62a17ae 8419 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8420 return "L2VPN EVPN";
8421 else
8422 return "Unknown";
538621f2 8423}
8424
b9f77ec8
DS
8425/*
8426 * Please note that we have intentionally camelCased
8427 * the return strings here. So if you want
8428 * to use this function, please ensure you
8429 * are doing this within json output
8430 */
d62a17ae 8431const char *afi_safi_json(afi_t afi, safi_t safi)
8432{
8433 if (afi == AFI_IP && safi == SAFI_UNICAST)
8434 return "ipv4Unicast";
8435 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8436 return "ipv4Multicast";
8437 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8438 return "ipv4LabeledUnicast";
8439 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8440 return "ipv4Vpn";
8441 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8442 return "ipv4Encap";
7c40bf39 8443 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8444 return "ipv4Flowspec";
d62a17ae 8445 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8446 return "ipv6Unicast";
8447 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8448 return "ipv6Multicast";
8449 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8450 return "ipv6LabeledUnicast";
8451 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8452 return "ipv6Vpn";
8453 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8454 return "ipv6Encap";
7c40bf39 8455 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8456 return "ipv6Flowspec";
d62a17ae 8457 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8458 return "l2VpnEvpn";
8459 else
8460 return "Unknown";
27162734
LB
8461}
8462
718e3744 8463/* Show BGP peer's information. */
d1927ebe 8464enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8465
8466static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8467 afi_t afi, safi_t safi,
d7c0a89a
QY
8468 uint16_t adv_smcap, uint16_t adv_rmcap,
8469 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8470 bool use_json, json_object *json_pref)
d62a17ae 8471{
8472 /* Send-Mode */
8473 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8474 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8475 if (use_json) {
8476 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8477 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8478 json_object_string_add(json_pref, "sendMode",
8479 "advertisedAndReceived");
8480 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8481 json_object_string_add(json_pref, "sendMode",
8482 "advertised");
8483 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8484 json_object_string_add(json_pref, "sendMode",
8485 "received");
8486 } else {
8487 vty_out(vty, " Send-mode: ");
8488 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8489 vty_out(vty, "advertised");
8490 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8491 vty_out(vty, "%sreceived",
8492 CHECK_FLAG(p->af_cap[afi][safi],
8493 adv_smcap)
8494 ? ", "
8495 : "");
8496 vty_out(vty, "\n");
8497 }
8498 }
8499
8500 /* Receive-Mode */
8501 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8502 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8503 if (use_json) {
8504 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8505 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8506 json_object_string_add(json_pref, "recvMode",
8507 "advertisedAndReceived");
8508 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8509 json_object_string_add(json_pref, "recvMode",
8510 "advertised");
8511 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8512 json_object_string_add(json_pref, "recvMode",
8513 "received");
8514 } else {
8515 vty_out(vty, " Receive-mode: ");
8516 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8517 vty_out(vty, "advertised");
8518 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8519 vty_out(vty, "%sreceived",
8520 CHECK_FLAG(p->af_cap[afi][safi],
8521 adv_rmcap)
8522 ? ", "
8523 : "");
8524 vty_out(vty, "\n");
8525 }
8526 }
8527}
8528
8529static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8530 safi_t safi, bool use_json,
d62a17ae 8531 json_object *json_neigh)
8532{
0291c246
MK
8533 struct bgp_filter *filter;
8534 struct peer_af *paf;
8535 char orf_pfx_name[BUFSIZ];
8536 int orf_pfx_count;
8537 json_object *json_af = NULL;
8538 json_object *json_prefA = NULL;
8539 json_object *json_prefB = NULL;
8540 json_object *json_addr = NULL;
d62a17ae 8541
8542 if (use_json) {
8543 json_addr = json_object_new_object();
8544 json_af = json_object_new_object();
8545 filter = &p->filter[afi][safi];
8546
8547 if (peer_group_active(p))
8548 json_object_string_add(json_addr, "peerGroupMember",
8549 p->group->name);
8550
8551 paf = peer_af_find(p, afi, safi);
8552 if (paf && PAF_SUBGRP(paf)) {
8553 json_object_int_add(json_addr, "updateGroupId",
8554 PAF_UPDGRP(paf)->id);
8555 json_object_int_add(json_addr, "subGroupId",
8556 PAF_SUBGRP(paf)->id);
8557 json_object_int_add(json_addr, "packetQueueLength",
8558 bpacket_queue_virtual_length(paf));
8559 }
8560
8561 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8562 || CHECK_FLAG(p->af_cap[afi][safi],
8563 PEER_CAP_ORF_PREFIX_SM_RCV)
8564 || CHECK_FLAG(p->af_cap[afi][safi],
8565 PEER_CAP_ORF_PREFIX_RM_ADV)
8566 || CHECK_FLAG(p->af_cap[afi][safi],
8567 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8568 json_object_int_add(json_af, "orfType",
8569 ORF_TYPE_PREFIX);
8570 json_prefA = json_object_new_object();
8571 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8572 PEER_CAP_ORF_PREFIX_SM_ADV,
8573 PEER_CAP_ORF_PREFIX_RM_ADV,
8574 PEER_CAP_ORF_PREFIX_SM_RCV,
8575 PEER_CAP_ORF_PREFIX_RM_RCV,
8576 use_json, json_prefA);
8577 json_object_object_add(json_af, "orfPrefixList",
8578 json_prefA);
8579 }
8580
8581 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8582 || CHECK_FLAG(p->af_cap[afi][safi],
8583 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8584 || CHECK_FLAG(p->af_cap[afi][safi],
8585 PEER_CAP_ORF_PREFIX_RM_ADV)
8586 || CHECK_FLAG(p->af_cap[afi][safi],
8587 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8588 json_object_int_add(json_af, "orfOldType",
8589 ORF_TYPE_PREFIX_OLD);
8590 json_prefB = json_object_new_object();
8591 bgp_show_peer_afi_orf_cap(
8592 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8593 PEER_CAP_ORF_PREFIX_RM_ADV,
8594 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8595 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8596 json_prefB);
8597 json_object_object_add(json_af, "orfOldPrefixList",
8598 json_prefB);
8599 }
8600
8601 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8602 || CHECK_FLAG(p->af_cap[afi][safi],
8603 PEER_CAP_ORF_PREFIX_SM_RCV)
8604 || CHECK_FLAG(p->af_cap[afi][safi],
8605 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8606 || CHECK_FLAG(p->af_cap[afi][safi],
8607 PEER_CAP_ORF_PREFIX_RM_ADV)
8608 || CHECK_FLAG(p->af_cap[afi][safi],
8609 PEER_CAP_ORF_PREFIX_RM_RCV)
8610 || CHECK_FLAG(p->af_cap[afi][safi],
8611 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8612 json_object_object_add(json_addr, "afDependentCap",
8613 json_af);
8614 else
8615 json_object_free(json_af);
8616
8617 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8618 orf_pfx_count = prefix_bgp_show_prefix_list(
8619 NULL, afi, orf_pfx_name, use_json);
8620
8621 if (CHECK_FLAG(p->af_sflags[afi][safi],
8622 PEER_STATUS_ORF_PREFIX_SEND)
8623 || orf_pfx_count) {
8624 if (CHECK_FLAG(p->af_sflags[afi][safi],
8625 PEER_STATUS_ORF_PREFIX_SEND))
8626 json_object_boolean_true_add(json_neigh,
8627 "orfSent");
8628 if (orf_pfx_count)
8629 json_object_int_add(json_addr, "orfRecvCounter",
8630 orf_pfx_count);
8631 }
8632 if (CHECK_FLAG(p->af_sflags[afi][safi],
8633 PEER_STATUS_ORF_WAIT_REFRESH))
8634 json_object_string_add(
8635 json_addr, "orfFirstUpdate",
8636 "deferredUntilORFOrRouteRefreshRecvd");
8637
8638 if (CHECK_FLAG(p->af_flags[afi][safi],
8639 PEER_FLAG_REFLECTOR_CLIENT))
8640 json_object_boolean_true_add(json_addr,
8641 "routeReflectorClient");
8642 if (CHECK_FLAG(p->af_flags[afi][safi],
8643 PEER_FLAG_RSERVER_CLIENT))
8644 json_object_boolean_true_add(json_addr,
8645 "routeServerClient");
8646 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8647 json_object_boolean_true_add(json_addr,
8648 "inboundSoftConfigPermit");
8649
8650 if (CHECK_FLAG(p->af_flags[afi][safi],
8651 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8652 json_object_boolean_true_add(
8653 json_addr,
8654 "privateAsNumsAllReplacedInUpdatesToNbr");
8655 else if (CHECK_FLAG(p->af_flags[afi][safi],
8656 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8657 json_object_boolean_true_add(
8658 json_addr,
8659 "privateAsNumsReplacedInUpdatesToNbr");
8660 else if (CHECK_FLAG(p->af_flags[afi][safi],
8661 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8662 json_object_boolean_true_add(
8663 json_addr,
8664 "privateAsNumsAllRemovedInUpdatesToNbr");
8665 else if (CHECK_FLAG(p->af_flags[afi][safi],
8666 PEER_FLAG_REMOVE_PRIVATE_AS))
8667 json_object_boolean_true_add(
8668 json_addr,
8669 "privateAsNumsRemovedInUpdatesToNbr");
8670
dcc68b5e
MS
8671 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8672 json_object_boolean_true_add(
8673 json_addr,
8674 bgp_addpath_names(p->addpath_type[afi][safi])
8675 ->type_json_name);
d62a17ae 8676
8677 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8678 json_object_string_add(json_addr,
8679 "overrideASNsInOutboundUpdates",
8680 "ifAspathEqualRemoteAs");
8681
8682 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8683 || CHECK_FLAG(p->af_flags[afi][safi],
8684 PEER_FLAG_FORCE_NEXTHOP_SELF))
8685 json_object_boolean_true_add(json_addr,
8686 "routerAlwaysNextHop");
8687 if (CHECK_FLAG(p->af_flags[afi][safi],
8688 PEER_FLAG_AS_PATH_UNCHANGED))
8689 json_object_boolean_true_add(
8690 json_addr, "unchangedAsPathPropogatedToNbr");
8691 if (CHECK_FLAG(p->af_flags[afi][safi],
8692 PEER_FLAG_NEXTHOP_UNCHANGED))
8693 json_object_boolean_true_add(
8694 json_addr, "unchangedNextHopPropogatedToNbr");
8695 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8696 json_object_boolean_true_add(
8697 json_addr, "unchangedMedPropogatedToNbr");
8698 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8699 || CHECK_FLAG(p->af_flags[afi][safi],
8700 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8701 if (CHECK_FLAG(p->af_flags[afi][safi],
8702 PEER_FLAG_SEND_COMMUNITY)
8703 && CHECK_FLAG(p->af_flags[afi][safi],
8704 PEER_FLAG_SEND_EXT_COMMUNITY))
8705 json_object_string_add(json_addr,
8706 "commAttriSentToNbr",
8707 "extendedAndStandard");
8708 else if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_SEND_EXT_COMMUNITY))
8710 json_object_string_add(json_addr,
8711 "commAttriSentToNbr",
8712 "extended");
8713 else
8714 json_object_string_add(json_addr,
8715 "commAttriSentToNbr",
8716 "standard");
8717 }
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_DEFAULT_ORIGINATE)) {
8720 if (p->default_rmap[afi][safi].name)
8721 json_object_string_add(
8722 json_addr, "defaultRouteMap",
8723 p->default_rmap[afi][safi].name);
8724
8725 if (paf && PAF_SUBGRP(paf)
8726 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8727 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8728 json_object_boolean_true_add(json_addr,
8729 "defaultSent");
8730 else
8731 json_object_boolean_true_add(json_addr,
8732 "defaultNotSent");
8733 }
8734
dff8f48d 8735 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8736 if (is_evpn_enabled())
60466a63
QY
8737 json_object_boolean_true_add(
8738 json_addr, "advertiseAllVnis");
dff8f48d
MK
8739 }
8740
d62a17ae 8741 if (filter->plist[FILTER_IN].name
8742 || filter->dlist[FILTER_IN].name
8743 || filter->aslist[FILTER_IN].name
8744 || filter->map[RMAP_IN].name)
8745 json_object_boolean_true_add(json_addr,
8746 "inboundPathPolicyConfig");
8747 if (filter->plist[FILTER_OUT].name
8748 || filter->dlist[FILTER_OUT].name
8749 || filter->aslist[FILTER_OUT].name
8750 || filter->map[RMAP_OUT].name || filter->usmap.name)
8751 json_object_boolean_true_add(
8752 json_addr, "outboundPathPolicyConfig");
8753
8754 /* prefix-list */
8755 if (filter->plist[FILTER_IN].name)
8756 json_object_string_add(json_addr,
8757 "incomingUpdatePrefixFilterList",
8758 filter->plist[FILTER_IN].name);
8759 if (filter->plist[FILTER_OUT].name)
8760 json_object_string_add(json_addr,
8761 "outgoingUpdatePrefixFilterList",
8762 filter->plist[FILTER_OUT].name);
8763
8764 /* distribute-list */
8765 if (filter->dlist[FILTER_IN].name)
8766 json_object_string_add(
8767 json_addr, "incomingUpdateNetworkFilterList",
8768 filter->dlist[FILTER_IN].name);
8769 if (filter->dlist[FILTER_OUT].name)
8770 json_object_string_add(
8771 json_addr, "outgoingUpdateNetworkFilterList",
8772 filter->dlist[FILTER_OUT].name);
8773
8774 /* filter-list. */
8775 if (filter->aslist[FILTER_IN].name)
8776 json_object_string_add(json_addr,
8777 "incomingUpdateAsPathFilterList",
8778 filter->aslist[FILTER_IN].name);
8779 if (filter->aslist[FILTER_OUT].name)
8780 json_object_string_add(json_addr,
8781 "outgoingUpdateAsPathFilterList",
8782 filter->aslist[FILTER_OUT].name);
8783
8784 /* route-map. */
8785 if (filter->map[RMAP_IN].name)
8786 json_object_string_add(
8787 json_addr, "routeMapForIncomingAdvertisements",
8788 filter->map[RMAP_IN].name);
8789 if (filter->map[RMAP_OUT].name)
8790 json_object_string_add(
8791 json_addr, "routeMapForOutgoingAdvertisements",
8792 filter->map[RMAP_OUT].name);
8793
9dac9fc8
DA
8794 /* ebgp-requires-policy (inbound) */
8795 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8796 && !bgp_inbound_policy_exists(p, filter))
8797 json_object_string_add(
8798 json_addr, "inboundEbgpRequiresPolicy",
8799 "Inbound updates discarded due to missing policy");
8800
8801 /* ebgp-requires-policy (outbound) */
8802 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8803 && (!bgp_outbound_policy_exists(p, filter)))
8804 json_object_string_add(
8805 json_addr, "outboundEbgpRequiresPolicy",
8806 "Outbound updates discarded due to missing policy");
8807
d62a17ae 8808 /* unsuppress-map */
8809 if (filter->usmap.name)
8810 json_object_string_add(json_addr,
8811 "selectiveUnsuppressRouteMap",
8812 filter->usmap.name);
8813
8814 /* Receive prefix count */
8815 json_object_int_add(json_addr, "acceptedPrefixCounter",
8816 p->pcount[afi][safi]);
50e05855
AD
8817 if (paf && PAF_SUBGRP(paf))
8818 json_object_int_add(json_addr, "sentPrefixCounter",
8819 (PAF_SUBGRP(paf))->scount);
d62a17ae 8820
8821 /* Maximum prefix */
8822 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8823 json_object_int_add(json_addr, "prefixAllowedMax",
8824 p->pmax[afi][safi]);
8825 if (CHECK_FLAG(p->af_flags[afi][safi],
8826 PEER_FLAG_MAX_PREFIX_WARNING))
8827 json_object_boolean_true_add(
8828 json_addr, "prefixAllowedMaxWarning");
8829 json_object_int_add(json_addr,
8830 "prefixAllowedWarningThresh",
8831 p->pmax_threshold[afi][safi]);
8832 if (p->pmax_restart[afi][safi])
8833 json_object_int_add(
8834 json_addr,
8835 "prefixAllowedRestartIntervalMsecs",
8836 p->pmax_restart[afi][safi] * 60000);
8837 }
8838 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8839 json_addr);
8840
8841 } else {
8842 filter = &p->filter[afi][safi];
8843
8844 vty_out(vty, " For address family: %s\n",
8845 afi_safi_print(afi, safi));
8846
8847 if (peer_group_active(p))
8848 vty_out(vty, " %s peer-group member\n",
8849 p->group->name);
8850
8851 paf = peer_af_find(p, afi, safi);
8852 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8853 vty_out(vty, " Update group %" PRIu64
8854 ", subgroup %" PRIu64 "\n",
d62a17ae 8855 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8856 vty_out(vty, " Packet Queue length %d\n",
8857 bpacket_queue_virtual_length(paf));
8858 } else {
8859 vty_out(vty, " Not part of any update group\n");
8860 }
8861 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8862 || CHECK_FLAG(p->af_cap[afi][safi],
8863 PEER_CAP_ORF_PREFIX_SM_RCV)
8864 || CHECK_FLAG(p->af_cap[afi][safi],
8865 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8866 || CHECK_FLAG(p->af_cap[afi][safi],
8867 PEER_CAP_ORF_PREFIX_RM_ADV)
8868 || CHECK_FLAG(p->af_cap[afi][safi],
8869 PEER_CAP_ORF_PREFIX_RM_RCV)
8870 || CHECK_FLAG(p->af_cap[afi][safi],
8871 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8872 vty_out(vty, " AF-dependant capabilities:\n");
8873
8874 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8875 || CHECK_FLAG(p->af_cap[afi][safi],
8876 PEER_CAP_ORF_PREFIX_SM_RCV)
8877 || CHECK_FLAG(p->af_cap[afi][safi],
8878 PEER_CAP_ORF_PREFIX_RM_ADV)
8879 || CHECK_FLAG(p->af_cap[afi][safi],
8880 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8881 vty_out(vty,
8882 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8883 ORF_TYPE_PREFIX);
8884 bgp_show_peer_afi_orf_cap(
8885 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8886 PEER_CAP_ORF_PREFIX_RM_ADV,
8887 PEER_CAP_ORF_PREFIX_SM_RCV,
8888 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8889 }
8890 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8891 || CHECK_FLAG(p->af_cap[afi][safi],
8892 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8893 || CHECK_FLAG(p->af_cap[afi][safi],
8894 PEER_CAP_ORF_PREFIX_RM_ADV)
8895 || CHECK_FLAG(p->af_cap[afi][safi],
8896 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8897 vty_out(vty,
8898 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8899 ORF_TYPE_PREFIX_OLD);
8900 bgp_show_peer_afi_orf_cap(
8901 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8902 PEER_CAP_ORF_PREFIX_RM_ADV,
8903 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8904 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8905 }
8906
8907 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8908 orf_pfx_count = prefix_bgp_show_prefix_list(
8909 NULL, afi, orf_pfx_name, use_json);
8910
8911 if (CHECK_FLAG(p->af_sflags[afi][safi],
8912 PEER_STATUS_ORF_PREFIX_SEND)
8913 || orf_pfx_count) {
8914 vty_out(vty, " Outbound Route Filter (ORF):");
8915 if (CHECK_FLAG(p->af_sflags[afi][safi],
8916 PEER_STATUS_ORF_PREFIX_SEND))
8917 vty_out(vty, " sent;");
8918 if (orf_pfx_count)
8919 vty_out(vty, " received (%d entries)",
8920 orf_pfx_count);
8921 vty_out(vty, "\n");
8922 }
8923 if (CHECK_FLAG(p->af_sflags[afi][safi],
8924 PEER_STATUS_ORF_WAIT_REFRESH))
8925 vty_out(vty,
8926 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8927
8928 if (CHECK_FLAG(p->af_flags[afi][safi],
8929 PEER_FLAG_REFLECTOR_CLIENT))
8930 vty_out(vty, " Route-Reflector Client\n");
8931 if (CHECK_FLAG(p->af_flags[afi][safi],
8932 PEER_FLAG_RSERVER_CLIENT))
8933 vty_out(vty, " Route-Server Client\n");
8934 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8935 vty_out(vty,
8936 " Inbound soft reconfiguration allowed\n");
8937
8938 if (CHECK_FLAG(p->af_flags[afi][safi],
8939 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8940 vty_out(vty,
8941 " Private AS numbers (all) replaced in updates to this neighbor\n");
8942 else if (CHECK_FLAG(p->af_flags[afi][safi],
8943 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8944 vty_out(vty,
8945 " Private AS numbers replaced in updates to this neighbor\n");
8946 else if (CHECK_FLAG(p->af_flags[afi][safi],
8947 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8948 vty_out(vty,
8949 " Private AS numbers (all) removed in updates to this neighbor\n");
8950 else if (CHECK_FLAG(p->af_flags[afi][safi],
8951 PEER_FLAG_REMOVE_PRIVATE_AS))
8952 vty_out(vty,
8953 " Private AS numbers removed in updates to this neighbor\n");
8954
dcc68b5e
MS
8955 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8956 vty_out(vty, " %s\n",
8957 bgp_addpath_names(p->addpath_type[afi][safi])
8958 ->human_description);
d62a17ae 8959
8960 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8961 vty_out(vty,
8962 " Override ASNs in outbound updates if aspath equals remote-as\n");
8963
8964 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8965 || CHECK_FLAG(p->af_flags[afi][safi],
8966 PEER_FLAG_FORCE_NEXTHOP_SELF))
8967 vty_out(vty, " NEXT_HOP is always this router\n");
8968 if (CHECK_FLAG(p->af_flags[afi][safi],
8969 PEER_FLAG_AS_PATH_UNCHANGED))
8970 vty_out(vty,
8971 " AS_PATH is propagated unchanged to this neighbor\n");
8972 if (CHECK_FLAG(p->af_flags[afi][safi],
8973 PEER_FLAG_NEXTHOP_UNCHANGED))
8974 vty_out(vty,
8975 " NEXT_HOP is propagated unchanged to this neighbor\n");
8976 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8977 vty_out(vty,
8978 " MED is propagated unchanged to this neighbor\n");
8979 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8980 || CHECK_FLAG(p->af_flags[afi][safi],
8981 PEER_FLAG_SEND_EXT_COMMUNITY)
8982 || CHECK_FLAG(p->af_flags[afi][safi],
8983 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8984 vty_out(vty,
8985 " Community attribute sent to this neighbor");
8986 if (CHECK_FLAG(p->af_flags[afi][safi],
8987 PEER_FLAG_SEND_COMMUNITY)
8988 && CHECK_FLAG(p->af_flags[afi][safi],
8989 PEER_FLAG_SEND_EXT_COMMUNITY)
8990 && CHECK_FLAG(p->af_flags[afi][safi],
8991 PEER_FLAG_SEND_LARGE_COMMUNITY))
8992 vty_out(vty, "(all)\n");
8993 else if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_SEND_LARGE_COMMUNITY))
8995 vty_out(vty, "(large)\n");
8996 else if (CHECK_FLAG(p->af_flags[afi][safi],
8997 PEER_FLAG_SEND_EXT_COMMUNITY))
8998 vty_out(vty, "(extended)\n");
8999 else
9000 vty_out(vty, "(standard)\n");
9001 }
9002 if (CHECK_FLAG(p->af_flags[afi][safi],
9003 PEER_FLAG_DEFAULT_ORIGINATE)) {
9004 vty_out(vty, " Default information originate,");
9005
9006 if (p->default_rmap[afi][safi].name)
9007 vty_out(vty, " default route-map %s%s,",
9008 p->default_rmap[afi][safi].map ? "*"
9009 : "",
9010 p->default_rmap[afi][safi].name);
9011 if (paf && PAF_SUBGRP(paf)
9012 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9013 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9014 vty_out(vty, " default sent\n");
9015 else
9016 vty_out(vty, " default not sent\n");
9017 }
9018
dff8f48d
MK
9019 /* advertise-vni-all */
9020 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9021 if (is_evpn_enabled())
dff8f48d
MK
9022 vty_out(vty, " advertise-all-vni\n");
9023 }
9024
d62a17ae 9025 if (filter->plist[FILTER_IN].name
9026 || filter->dlist[FILTER_IN].name
9027 || filter->aslist[FILTER_IN].name
9028 || filter->map[RMAP_IN].name)
9029 vty_out(vty, " Inbound path policy configured\n");
9030 if (filter->plist[FILTER_OUT].name
9031 || filter->dlist[FILTER_OUT].name
9032 || filter->aslist[FILTER_OUT].name
9033 || filter->map[RMAP_OUT].name || filter->usmap.name)
9034 vty_out(vty, " Outbound path policy configured\n");
9035
9036 /* prefix-list */
9037 if (filter->plist[FILTER_IN].name)
9038 vty_out(vty,
9039 " Incoming update prefix filter list is %s%s\n",
9040 filter->plist[FILTER_IN].plist ? "*" : "",
9041 filter->plist[FILTER_IN].name);
9042 if (filter->plist[FILTER_OUT].name)
9043 vty_out(vty,
9044 " Outgoing update prefix filter list is %s%s\n",
9045 filter->plist[FILTER_OUT].plist ? "*" : "",
9046 filter->plist[FILTER_OUT].name);
9047
9048 /* distribute-list */
9049 if (filter->dlist[FILTER_IN].name)
9050 vty_out(vty,
9051 " Incoming update network filter list is %s%s\n",
9052 filter->dlist[FILTER_IN].alist ? "*" : "",
9053 filter->dlist[FILTER_IN].name);
9054 if (filter->dlist[FILTER_OUT].name)
9055 vty_out(vty,
9056 " Outgoing update network filter list is %s%s\n",
9057 filter->dlist[FILTER_OUT].alist ? "*" : "",
9058 filter->dlist[FILTER_OUT].name);
9059
9060 /* filter-list. */
9061 if (filter->aslist[FILTER_IN].name)
9062 vty_out(vty,
9063 " Incoming update AS path filter list is %s%s\n",
9064 filter->aslist[FILTER_IN].aslist ? "*" : "",
9065 filter->aslist[FILTER_IN].name);
9066 if (filter->aslist[FILTER_OUT].name)
9067 vty_out(vty,
9068 " Outgoing update AS path filter list is %s%s\n",
9069 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9070 filter->aslist[FILTER_OUT].name);
9071
9072 /* route-map. */
9073 if (filter->map[RMAP_IN].name)
9074 vty_out(vty,
9075 " Route map for incoming advertisements is %s%s\n",
9076 filter->map[RMAP_IN].map ? "*" : "",
9077 filter->map[RMAP_IN].name);
9078 if (filter->map[RMAP_OUT].name)
9079 vty_out(vty,
9080 " Route map for outgoing advertisements is %s%s\n",
9081 filter->map[RMAP_OUT].map ? "*" : "",
9082 filter->map[RMAP_OUT].name);
9083
9dac9fc8
DA
9084 /* ebgp-requires-policy (inbound) */
9085 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9086 && !bgp_inbound_policy_exists(p, filter))
9087 vty_out(vty,
9088 " Inbound updates discarded due to missing policy\n");
9089
9090 /* ebgp-requires-policy (outbound) */
9091 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9092 && !bgp_outbound_policy_exists(p, filter))
9093 vty_out(vty,
9094 " Outbound updates discarded due to missing policy\n");
9095
d62a17ae 9096 /* unsuppress-map */
9097 if (filter->usmap.name)
9098 vty_out(vty,
9099 " Route map for selective unsuppress is %s%s\n",
9100 filter->usmap.map ? "*" : "",
9101 filter->usmap.name);
9102
9103 /* Receive prefix count */
9104 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9105
9106 /* Maximum prefix */
9107 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9108 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9109 p->pmax[afi][safi],
9110 CHECK_FLAG(p->af_flags[afi][safi],
9111 PEER_FLAG_MAX_PREFIX_WARNING)
9112 ? " (warning-only)"
9113 : "");
9114 vty_out(vty, " Threshold for warning message %d%%",
9115 p->pmax_threshold[afi][safi]);
9116 if (p->pmax_restart[afi][safi])
9117 vty_out(vty, ", restart interval %d min",
9118 p->pmax_restart[afi][safi]);
9119 vty_out(vty, "\n");
9120 }
9121
9122 vty_out(vty, "\n");
9123 }
9124}
9125
9f049418 9126static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9127 json_object *json)
718e3744 9128{
d62a17ae 9129 struct bgp *bgp;
9130 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9131 char timebuf[BGP_UPTIME_LEN];
9132 char dn_flag[2];
9133 const char *subcode_str;
9134 const char *code_str;
9135 afi_t afi;
9136 safi_t safi;
d7c0a89a
QY
9137 uint16_t i;
9138 uint8_t *msg;
d62a17ae 9139 json_object *json_neigh = NULL;
9140 time_t epoch_tbuf;
718e3744 9141
d62a17ae 9142 bgp = p->bgp;
9143
9144 if (use_json)
9145 json_neigh = json_object_new_object();
9146
9147 memset(dn_flag, '\0', sizeof(dn_flag));
9148 if (!p->conf_if && peer_dynamic_neighbor(p))
9149 dn_flag[0] = '*';
9150
9151 if (!use_json) {
9152 if (p->conf_if) /* Configured interface name. */
9153 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9154 BGP_PEER_SU_UNSPEC(p)
9155 ? "None"
9156 : sockunion2str(&p->su, buf,
9157 SU_ADDRSTRLEN));
9158 else /* Configured IP address. */
9159 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9160 p->host);
9161 }
9162
9163 if (use_json) {
9164 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9165 json_object_string_add(json_neigh, "bgpNeighborAddr",
9166 "none");
9167 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9168 json_object_string_add(
9169 json_neigh, "bgpNeighborAddr",
9170 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9171
9172 json_object_int_add(json_neigh, "remoteAs", p->as);
9173
9174 if (p->change_local_as)
9175 json_object_int_add(json_neigh, "localAs",
9176 p->change_local_as);
9177 else
9178 json_object_int_add(json_neigh, "localAs", p->local_as);
9179
9180 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9181 json_object_boolean_true_add(json_neigh,
9182 "localAsNoPrepend");
9183
9184 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9185 json_object_boolean_true_add(json_neigh,
9186 "localAsReplaceAs");
9187 } else {
9188 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9189 || (p->as_type == AS_INTERNAL))
9190 vty_out(vty, "remote AS %u, ", p->as);
9191 else
9192 vty_out(vty, "remote AS Unspecified, ");
9193 vty_out(vty, "local AS %u%s%s, ",
9194 p->change_local_as ? p->change_local_as : p->local_as,
9195 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9196 ? " no-prepend"
9197 : "",
9198 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9199 ? " replace-as"
9200 : "");
9201 }
faa16034
DS
9202 /* peer type internal or confed-internal */
9203 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9204 if (use_json) {
9205 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9206 json_object_boolean_true_add(
9207 json_neigh, "nbrConfedInternalLink");
9208 else
9209 json_object_boolean_true_add(json_neigh,
9210 "nbrInternalLink");
9211 } else {
9212 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9213 vty_out(vty, "confed-internal link\n");
9214 else
9215 vty_out(vty, "internal link\n");
9216 }
faa16034
DS
9217 /* peer type external or confed-external */
9218 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9219 if (use_json) {
9220 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9221 json_object_boolean_true_add(
9222 json_neigh, "nbrConfedExternalLink");
9223 else
9224 json_object_boolean_true_add(json_neigh,
9225 "nbrExternalLink");
9226 } else {
9227 if (bgp_confederation_peers_check(bgp, p->as))
9228 vty_out(vty, "confed-external link\n");
9229 else
9230 vty_out(vty, "external link\n");
9231 }
faa16034
DS
9232 } else {
9233 if (use_json)
9234 json_object_boolean_true_add(json_neigh,
9235 "nbrUnspecifiedLink");
9236 else
9237 vty_out(vty, "unspecified link\n");
d62a17ae 9238 }
9239
9240 /* Description. */
9241 if (p->desc) {
9242 if (use_json)
9243 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9244 else
9245 vty_out(vty, " Description: %s\n", p->desc);
9246 }
9247
9248 if (p->hostname) {
9249 if (use_json) {
9250 if (p->hostname)
9251 json_object_string_add(json_neigh, "hostname",
9252 p->hostname);
9253
9254 if (p->domainname)
9255 json_object_string_add(json_neigh, "domainname",
9256 p->domainname);
9257 } else {
9258 if (p->domainname && (p->domainname[0] != '\0'))
9259 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9260 p->domainname);
9261 else
9262 vty_out(vty, "Hostname: %s\n", p->hostname);
9263 }
9264 }
9265
9266 /* Peer-group */
9267 if (p->group) {
9268 if (use_json) {
9269 json_object_string_add(json_neigh, "peerGroup",
9270 p->group->name);
9271
9272 if (dn_flag[0]) {
9273 struct prefix prefix, *range = NULL;
9274
9275 sockunion2hostprefix(&(p->su), &prefix);
9276 range = peer_group_lookup_dynamic_neighbor_range(
9277 p->group, &prefix);
9278
9279 if (range) {
9280 prefix2str(range, buf1, sizeof(buf1));
9281 json_object_string_add(
9282 json_neigh,
9283 "peerSubnetRangeGroup", buf1);
9284 }
9285 }
9286 } else {
9287 vty_out(vty,
9288 " Member of peer-group %s for session parameters\n",
9289 p->group->name);
9290
9291 if (dn_flag[0]) {
9292 struct prefix prefix, *range = NULL;
9293
9294 sockunion2hostprefix(&(p->su), &prefix);
9295 range = peer_group_lookup_dynamic_neighbor_range(
9296 p->group, &prefix);
9297
9298 if (range) {
9299 prefix2str(range, buf1, sizeof(buf1));
9300 vty_out(vty,
9301 " Belongs to the subnet range group: %s\n",
9302 buf1);
9303 }
9304 }
9305 }
9306 }
9307
9308 if (use_json) {
9309 /* Administrative shutdown. */
9310 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9311 json_object_boolean_true_add(json_neigh,
9312 "adminShutDown");
9313
9314 /* BGP Version. */
9315 json_object_int_add(json_neigh, "bgpVersion", 4);
9316 json_object_string_add(
9317 json_neigh, "remoteRouterId",
9318 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9319 json_object_string_add(
9320 json_neigh, "localRouterId",
9321 inet_ntop(AF_INET, &bgp->router_id, buf1,
9322 sizeof(buf1)));
d62a17ae 9323
9324 /* Confederation */
9325 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9326 && bgp_confederation_peers_check(bgp, p->as))
9327 json_object_boolean_true_add(json_neigh,
9328 "nbrCommonAdmin");
9329
9330 /* Status. */
9331 json_object_string_add(
9332 json_neigh, "bgpState",
9333 lookup_msg(bgp_status_msg, p->status, NULL));
9334
9335 if (p->status == Established) {
9336 time_t uptime;
d62a17ae 9337
9338 uptime = bgp_clock();
9339 uptime -= p->uptime;
d62a17ae 9340 epoch_tbuf = time(NULL) - uptime;
9341
bee57a7a 9342#if CONFDATE > 20200101
a4d82a8a
PZ
9343 CPP_NOTICE(
9344 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9345#endif
9346 /*
9347 * bgpTimerUp was miliseconds that was accurate
9348 * up to 1 day, then the value returned
9349 * became garbage. So in order to provide
9350 * some level of backwards compatability,
9351 * we still provde the data, but now
9352 * we are returning the correct value
9353 * and also adding a new bgpTimerUpMsec
9354 * which will allow us to deprecate
9355 * this eventually
9356 */
d62a17ae 9357 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9358 uptime * 1000);
d3c7efed
DS
9359 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9360 uptime * 1000);
d62a17ae 9361 json_object_string_add(json_neigh, "bgpTimerUpString",
9362 peer_uptime(p->uptime, timebuf,
9363 BGP_UPTIME_LEN, 0,
9364 NULL));
9365 json_object_int_add(json_neigh,
9366 "bgpTimerUpEstablishedEpoch",
9367 epoch_tbuf);
9368 }
9369
9370 else if (p->status == Active) {
9371 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9372 json_object_string_add(json_neigh, "bgpStateIs",
9373 "passive");
9374 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9375 json_object_string_add(json_neigh, "bgpStateIs",
9376 "passiveNSF");
9377 }
9378
9379 /* read timer */
9380 time_t uptime;
9381 struct tm *tm;
9382
9383 uptime = bgp_clock();
9384 uptime -= p->readtime;
9385 tm = gmtime(&uptime);
9386 json_object_int_add(json_neigh, "bgpTimerLastRead",
9387 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9388 + (tm->tm_hour * 3600000));
9389
9390 uptime = bgp_clock();
9391 uptime -= p->last_write;
9392 tm = gmtime(&uptime);
9393 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9394 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9395 + (tm->tm_hour * 3600000));
9396
9397 uptime = bgp_clock();
9398 uptime -= p->update_time;
9399 tm = gmtime(&uptime);
9400 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9401 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9402 + (tm->tm_hour * 3600000));
9403
9404 /* Configured timer values. */
9405 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9406 p->v_holdtime * 1000);
9407 json_object_int_add(json_neigh,
9408 "bgpTimerKeepAliveIntervalMsecs",
9409 p->v_keepalive * 1000);
b90a8e13 9410 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9411 json_object_int_add(json_neigh,
9412 "bgpTimerConfiguredHoldTimeMsecs",
9413 p->holdtime * 1000);
9414 json_object_int_add(
9415 json_neigh,
9416 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9417 p->keepalive * 1000);
d25e4efc 9418 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9419 || (bgp->default_keepalive
9420 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9421 json_object_int_add(json_neigh,
9422 "bgpTimerConfiguredHoldTimeMsecs",
9423 bgp->default_holdtime);
9424 json_object_int_add(
9425 json_neigh,
9426 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9427 bgp->default_keepalive);
d62a17ae 9428 }
9429 } else {
9430 /* Administrative shutdown. */
9431 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9432 vty_out(vty, " Administratively shut down\n");
9433
9434 /* BGP Version. */
9435 vty_out(vty, " BGP version 4");
0e38aeb4 9436 vty_out(vty, ", remote router ID %s",
d62a17ae 9437 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9438 vty_out(vty, ", local router ID %s\n",
9439 inet_ntop(AF_INET, &bgp->router_id, buf1,
9440 sizeof(buf1)));
d62a17ae 9441
9442 /* Confederation */
9443 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9444 && bgp_confederation_peers_check(bgp, p->as))
9445 vty_out(vty,
9446 " Neighbor under common administration\n");
9447
9448 /* Status. */
9449 vty_out(vty, " BGP state = %s",
9450 lookup_msg(bgp_status_msg, p->status, NULL));
9451
9452 if (p->status == Established)
9453 vty_out(vty, ", up for %8s",
9454 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9455 0, NULL));
9456
9457 else if (p->status == Active) {
9458 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9459 vty_out(vty, " (passive)");
9460 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9461 vty_out(vty, " (NSF passive)");
9462 }
9463 vty_out(vty, "\n");
9464
9465 /* read timer */
9466 vty_out(vty, " Last read %s",
9467 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9468 NULL));
9469 vty_out(vty, ", Last write %s\n",
9470 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9471 NULL));
9472
9473 /* Configured timer values. */
9474 vty_out(vty,
9475 " Hold time is %d, keepalive interval is %d seconds\n",
9476 p->v_holdtime, p->v_keepalive);
b90a8e13 9477 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9478 vty_out(vty, " Configured hold time is %d",
9479 p->holdtime);
9480 vty_out(vty, ", keepalive interval is %d seconds\n",
9481 p->keepalive);
d25e4efc 9482 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9483 || (bgp->default_keepalive
9484 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9485 vty_out(vty, " Configured hold time is %d",
9486 bgp->default_holdtime);
9487 vty_out(vty, ", keepalive interval is %d seconds\n",
9488 bgp->default_keepalive);
d62a17ae 9489 }
9490 }
9491 /* Capability. */
9492 if (p->status == Established) {
9493 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9494 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9495 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9496 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9497 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9498 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9499 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9500 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9501 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9502 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9503 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9504 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9505 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9506 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9507 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9508 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9509 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9510 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9511 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9512 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9513 if (use_json) {
9514 json_object *json_cap = NULL;
9515
9516 json_cap = json_object_new_object();
9517
9518 /* AS4 */
9519 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9520 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9521 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9522 && CHECK_FLAG(p->cap,
9523 PEER_CAP_AS4_RCV))
9524 json_object_string_add(
9525 json_cap, "4byteAs",
9526 "advertisedAndReceived");
9527 else if (CHECK_FLAG(p->cap,
9528 PEER_CAP_AS4_ADV))
9529 json_object_string_add(
9530 json_cap, "4byteAs",
9531 "advertised");
9532 else if (CHECK_FLAG(p->cap,
9533 PEER_CAP_AS4_RCV))
9534 json_object_string_add(
9535 json_cap, "4byteAs",
9536 "received");
9537 }
9538
9539 /* AddPath */
9540 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9541 || CHECK_FLAG(p->cap,
9542 PEER_CAP_ADDPATH_ADV)) {
9543 json_object *json_add = NULL;
9544 const char *print_store;
9545
9546 json_add = json_object_new_object();
9547
05c7a1cc
QY
9548 FOREACH_AFI_SAFI (afi, safi) {
9549 json_object *json_sub = NULL;
9550 json_sub =
9551 json_object_new_object();
9552 print_store = afi_safi_print(
9553 afi, safi);
d62a17ae 9554
05c7a1cc
QY
9555 if (CHECK_FLAG(
9556 p->af_cap[afi]
9557 [safi],
9558 PEER_CAP_ADDPATH_AF_TX_ADV)
9559 || CHECK_FLAG(
9560 p->af_cap[afi]
9561 [safi],
9562 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9563 if (CHECK_FLAG(
9564 p->af_cap
9565 [afi]
9566 [safi],
9567 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9568 && CHECK_FLAG(
d62a17ae 9569 p->af_cap
9570 [afi]
9571 [safi],
05c7a1cc
QY
9572 PEER_CAP_ADDPATH_AF_TX_RCV))
9573 json_object_boolean_true_add(
9574 json_sub,
9575 "txAdvertisedAndReceived");
9576 else if (
9577 CHECK_FLAG(
9578 p->af_cap
9579 [afi]
9580 [safi],
9581 PEER_CAP_ADDPATH_AF_TX_ADV))
9582 json_object_boolean_true_add(
9583 json_sub,
9584 "txAdvertised");
9585 else if (
9586 CHECK_FLAG(
9587 p->af_cap
9588 [afi]
9589 [safi],
9590 PEER_CAP_ADDPATH_AF_TX_RCV))
9591 json_object_boolean_true_add(
9592 json_sub,
9593 "txReceived");
9594 }
d62a17ae 9595
05c7a1cc
QY
9596 if (CHECK_FLAG(
9597 p->af_cap[afi]
9598 [safi],
9599 PEER_CAP_ADDPATH_AF_RX_ADV)
9600 || CHECK_FLAG(
9601 p->af_cap[afi]
9602 [safi],
9603 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9604 if (CHECK_FLAG(
9605 p->af_cap
9606 [afi]
9607 [safi],
9608 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9609 && CHECK_FLAG(
d62a17ae 9610 p->af_cap
9611 [afi]
9612 [safi],
9613 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9614 json_object_boolean_true_add(
9615 json_sub,
9616 "rxAdvertisedAndReceived");
9617 else if (
9618 CHECK_FLAG(
9619 p->af_cap
9620 [afi]
9621 [safi],
9622 PEER_CAP_ADDPATH_AF_RX_ADV))
9623 json_object_boolean_true_add(
9624 json_sub,
9625 "rxAdvertised");
9626 else if (
9627 CHECK_FLAG(
9628 p->af_cap
9629 [afi]
9630 [safi],
9631 PEER_CAP_ADDPATH_AF_RX_RCV))
9632 json_object_boolean_true_add(
9633 json_sub,
9634 "rxReceived");
d62a17ae 9635 }
9636
05c7a1cc
QY
9637 if (CHECK_FLAG(
9638 p->af_cap[afi]
9639 [safi],
9640 PEER_CAP_ADDPATH_AF_TX_ADV)
9641 || CHECK_FLAG(
9642 p->af_cap[afi]
9643 [safi],
9644 PEER_CAP_ADDPATH_AF_TX_RCV)
9645 || CHECK_FLAG(
9646 p->af_cap[afi]
9647 [safi],
9648 PEER_CAP_ADDPATH_AF_RX_ADV)
9649 || CHECK_FLAG(
9650 p->af_cap[afi]
9651 [safi],
9652 PEER_CAP_ADDPATH_AF_RX_RCV))
9653 json_object_object_add(
9654 json_add,
9655 print_store,
9656 json_sub);
9657 else
9658 json_object_free(
9659 json_sub);
9660 }
9661
d62a17ae 9662 json_object_object_add(
9663 json_cap, "addPath", json_add);
9664 }
9665
9666 /* Dynamic */
9667 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9668 || CHECK_FLAG(p->cap,
9669 PEER_CAP_DYNAMIC_ADV)) {
9670 if (CHECK_FLAG(p->cap,
9671 PEER_CAP_DYNAMIC_ADV)
9672 && CHECK_FLAG(p->cap,
9673 PEER_CAP_DYNAMIC_RCV))
9674 json_object_string_add(
9675 json_cap, "dynamic",
9676 "advertisedAndReceived");
9677 else if (CHECK_FLAG(
9678 p->cap,
9679 PEER_CAP_DYNAMIC_ADV))
9680 json_object_string_add(
9681 json_cap, "dynamic",
9682 "advertised");
9683 else if (CHECK_FLAG(
9684 p->cap,
9685 PEER_CAP_DYNAMIC_RCV))
9686 json_object_string_add(
9687 json_cap, "dynamic",
9688 "received");
9689 }
9690
9691 /* Extended nexthop */
9692 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9693 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9694 json_object *json_nxt = NULL;
9695 const char *print_store;
9696
9697
9698 if (CHECK_FLAG(p->cap,
9699 PEER_CAP_ENHE_ADV)
9700 && CHECK_FLAG(p->cap,
9701 PEER_CAP_ENHE_RCV))
9702 json_object_string_add(
9703 json_cap,
9704 "extendedNexthop",
9705 "advertisedAndReceived");
9706 else if (CHECK_FLAG(p->cap,
9707 PEER_CAP_ENHE_ADV))
9708 json_object_string_add(
9709 json_cap,
9710 "extendedNexthop",
9711 "advertised");
9712 else if (CHECK_FLAG(p->cap,
9713 PEER_CAP_ENHE_RCV))
9714 json_object_string_add(
9715 json_cap,
9716 "extendedNexthop",
9717 "received");
9718
9719 if (CHECK_FLAG(p->cap,
9720 PEER_CAP_ENHE_RCV)) {
9721 json_nxt =
9722 json_object_new_object();
9723
9724 for (safi = SAFI_UNICAST;
9725 safi < SAFI_MAX; safi++) {
9726 if (CHECK_FLAG(
9727 p->af_cap
9728 [AFI_IP]
9729 [safi],
9730 PEER_CAP_ENHE_AF_RCV)) {
9731 print_store = afi_safi_print(
9732 AFI_IP,
9733 safi);
9734 json_object_string_add(
9735 json_nxt,
9736 print_store,
54f29523 9737 "recieved"); /* misspelled for compatibility */
d62a17ae 9738 }
9739 }
9740 json_object_object_add(
9741 json_cap,
9742 "extendedNexthopFamililesByPeer",
9743 json_nxt);
9744 }
9745 }
9746
9747 /* Route Refresh */
9748 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9749 || CHECK_FLAG(p->cap,
9750 PEER_CAP_REFRESH_NEW_RCV)
9751 || CHECK_FLAG(p->cap,
9752 PEER_CAP_REFRESH_OLD_RCV)) {
9753 if (CHECK_FLAG(p->cap,
9754 PEER_CAP_REFRESH_ADV)
9755 && (CHECK_FLAG(
9756 p->cap,
9757 PEER_CAP_REFRESH_NEW_RCV)
9758 || CHECK_FLAG(
9759 p->cap,
9760 PEER_CAP_REFRESH_OLD_RCV))) {
9761 if (CHECK_FLAG(
9762 p->cap,
9763 PEER_CAP_REFRESH_OLD_RCV)
9764 && CHECK_FLAG(
9765 p->cap,
9766 PEER_CAP_REFRESH_NEW_RCV))
9767 json_object_string_add(
9768 json_cap,
9769 "routeRefresh",
9770 "advertisedAndReceivedOldNew");
9771 else {
9772 if (CHECK_FLAG(
9773 p->cap,
9774 PEER_CAP_REFRESH_OLD_RCV))
9775 json_object_string_add(
9776 json_cap,
9777 "routeRefresh",
9778 "advertisedAndReceivedOld");
9779 else
9780 json_object_string_add(
9781 json_cap,
9782 "routeRefresh",
9783 "advertisedAndReceivedNew");
9784 }
9785 } else if (
9786 CHECK_FLAG(
9787 p->cap,
9788 PEER_CAP_REFRESH_ADV))
9789 json_object_string_add(
9790 json_cap,
9791 "routeRefresh",
9792 "advertised");
9793 else if (
9794 CHECK_FLAG(
9795 p->cap,
9796 PEER_CAP_REFRESH_NEW_RCV)
9797 || CHECK_FLAG(
9798 p->cap,
9799 PEER_CAP_REFRESH_OLD_RCV))
9800 json_object_string_add(
9801 json_cap,
9802 "routeRefresh",
9803 "received");
9804 }
9805
9806 /* Multiprotocol Extensions */
9807 json_object *json_multi = NULL;
9808 json_multi = json_object_new_object();
9809
05c7a1cc
QY
9810 FOREACH_AFI_SAFI (afi, safi) {
9811 if (p->afc_adv[afi][safi]
9812 || p->afc_recv[afi][safi]) {
9813 json_object *json_exten = NULL;
9814 json_exten =
9815 json_object_new_object();
9816
d62a17ae 9817 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9818 && p->afc_recv[afi][safi])
9819 json_object_boolean_true_add(
9820 json_exten,
9821 "advertisedAndReceived");
9822 else if (p->afc_adv[afi][safi])
9823 json_object_boolean_true_add(
9824 json_exten,
9825 "advertised");
9826 else if (p->afc_recv[afi][safi])
9827 json_object_boolean_true_add(
9828 json_exten,
9829 "received");
d62a17ae 9830
05c7a1cc
QY
9831 json_object_object_add(
9832 json_multi,
9833 afi_safi_print(afi,
9834 safi),
9835 json_exten);
d62a17ae 9836 }
9837 }
9838 json_object_object_add(
9839 json_cap, "multiprotocolExtensions",
9840 json_multi);
9841
d77114b7 9842 /* Hostname capabilities */
60466a63 9843 json_object *json_hname = NULL;
d77114b7
MK
9844
9845 json_hname = json_object_new_object();
9846
9847 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9848 json_object_string_add(
60466a63
QY
9849 json_hname, "advHostName",
9850 bgp->peer_self->hostname
9851 ? bgp->peer_self
9852 ->hostname
d77114b7
MK
9853 : "n/a");
9854 json_object_string_add(
60466a63
QY
9855 json_hname, "advDomainName",
9856 bgp->peer_self->domainname
9857 ? bgp->peer_self
9858 ->domainname
d77114b7
MK
9859 : "n/a");
9860 }
9861
9862
9863 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9864 json_object_string_add(
60466a63
QY
9865 json_hname, "rcvHostName",
9866 p->hostname ? p->hostname
9867 : "n/a");
d77114b7 9868 json_object_string_add(
60466a63
QY
9869 json_hname, "rcvDomainName",
9870 p->domainname ? p->domainname
9871 : "n/a");
d77114b7
MK
9872 }
9873
60466a63 9874 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9875 json_hname);
9876
d62a17ae 9877 /* Gracefull Restart */
9878 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9879 || CHECK_FLAG(p->cap,
9880 PEER_CAP_RESTART_ADV)) {
9881 if (CHECK_FLAG(p->cap,
9882 PEER_CAP_RESTART_ADV)
9883 && CHECK_FLAG(p->cap,
9884 PEER_CAP_RESTART_RCV))
9885 json_object_string_add(
9886 json_cap,
9887 "gracefulRestart",
9888 "advertisedAndReceived");
9889 else if (CHECK_FLAG(
9890 p->cap,
9891 PEER_CAP_RESTART_ADV))
9892 json_object_string_add(
9893 json_cap,
9894 "gracefulRestartCapability",
9895 "advertised");
9896 else if (CHECK_FLAG(
9897 p->cap,
9898 PEER_CAP_RESTART_RCV))
9899 json_object_string_add(
9900 json_cap,
9901 "gracefulRestartCapability",
9902 "received");
9903
9904 if (CHECK_FLAG(p->cap,
9905 PEER_CAP_RESTART_RCV)) {
9906 int restart_af_count = 0;
9907 json_object *json_restart =
9908 NULL;
9909 json_restart =
9910 json_object_new_object();
9911
9912 json_object_int_add(
9913 json_cap,
9914 "gracefulRestartRemoteTimerMsecs",
9915 p->v_gr_restart * 1000);
9916
05c7a1cc
QY
9917 FOREACH_AFI_SAFI (afi, safi) {
9918 if (CHECK_FLAG(
9919 p->af_cap
9920 [afi]
9921 [safi],
9922 PEER_CAP_RESTART_AF_RCV)) {
9923 json_object *
9924 json_sub =
9925 NULL;
9926 json_sub =
9927 json_object_new_object();
9928
d62a17ae 9929 if (CHECK_FLAG(
9930 p->af_cap
9931 [afi]
9932 [safi],
05c7a1cc
QY
9933 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9934 json_object_boolean_true_add(
9935 json_sub,
9936 "preserved");
9937 restart_af_count++;
9938 json_object_object_add(
9939 json_restart,
9940 afi_safi_print(
9941 afi,
9942 safi),
9943 json_sub);
d62a17ae 9944 }
9945 }
9946 if (!restart_af_count) {
9947 json_object_string_add(
9948 json_cap,
9949 "addressFamiliesByPeer",
9950 "none");
9951 json_object_free(
9952 json_restart);
9953 } else
9954 json_object_object_add(
9955 json_cap,
9956 "addressFamiliesByPeer",
9957 json_restart);
9958 }
9959 }
9960 json_object_object_add(json_neigh,
9961 "neighborCapabilities",
9962 json_cap);
9963 } else {
9964 vty_out(vty, " Neighbor capabilities:\n");
9965
9966 /* AS4 */
9967 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9968 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9969 vty_out(vty, " 4 Byte AS:");
9970 if (CHECK_FLAG(p->cap,
9971 PEER_CAP_AS4_ADV))
9972 vty_out(vty, " advertised");
9973 if (CHECK_FLAG(p->cap,
9974 PEER_CAP_AS4_RCV))
9975 vty_out(vty, " %sreceived",
9976 CHECK_FLAG(
9977 p->cap,
9978 PEER_CAP_AS4_ADV)
9979 ? "and "
9980 : "");
9981 vty_out(vty, "\n");
9982 }
9983
9984 /* AddPath */
9985 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9986 || CHECK_FLAG(p->cap,
9987 PEER_CAP_ADDPATH_ADV)) {
9988 vty_out(vty, " AddPath:\n");
9989
05c7a1cc
QY
9990 FOREACH_AFI_SAFI (afi, safi) {
9991 if (CHECK_FLAG(
9992 p->af_cap[afi]
9993 [safi],
9994 PEER_CAP_ADDPATH_AF_TX_ADV)
9995 || CHECK_FLAG(
9996 p->af_cap[afi]
9997 [safi],
9998 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9999 vty_out(vty,
10000 " %s: TX ",
10001 afi_safi_print(
10002 afi,
10003 safi));
10004
d62a17ae 10005 if (CHECK_FLAG(
10006 p->af_cap
10007 [afi]
10008 [safi],
05c7a1cc 10009 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10010 vty_out(vty,
05c7a1cc 10011 "advertised %s",
d62a17ae 10012 afi_safi_print(
10013 afi,
10014 safi));
10015
05c7a1cc
QY
10016 if (CHECK_FLAG(
10017 p->af_cap
10018 [afi]
10019 [safi],
10020 PEER_CAP_ADDPATH_AF_TX_RCV))
10021 vty_out(vty,
10022 "%sreceived",
10023 CHECK_FLAG(
10024 p->af_cap
10025 [afi]
10026 [safi],
10027 PEER_CAP_ADDPATH_AF_TX_ADV)
10028 ? " and "
10029 : "");
d62a17ae 10030
05c7a1cc
QY
10031 vty_out(vty, "\n");
10032 }
d62a17ae 10033
05c7a1cc
QY
10034 if (CHECK_FLAG(
10035 p->af_cap[afi]
10036 [safi],
10037 PEER_CAP_ADDPATH_AF_RX_ADV)
10038 || CHECK_FLAG(
10039 p->af_cap[afi]
10040 [safi],
10041 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10042 vty_out(vty,
10043 " %s: RX ",
10044 afi_safi_print(
10045 afi,
10046 safi));
d62a17ae 10047
10048 if (CHECK_FLAG(
10049 p->af_cap
10050 [afi]
10051 [safi],
05c7a1cc 10052 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10053 vty_out(vty,
05c7a1cc 10054 "advertised %s",
d62a17ae 10055 afi_safi_print(
10056 afi,
10057 safi));
10058
05c7a1cc
QY
10059 if (CHECK_FLAG(
10060 p->af_cap
10061 [afi]
10062 [safi],
10063 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10064 vty_out(vty,
05c7a1cc
QY
10065 "%sreceived",
10066 CHECK_FLAG(
10067 p->af_cap
10068 [afi]
10069 [safi],
10070 PEER_CAP_ADDPATH_AF_RX_ADV)
10071 ? " and "
10072 : "");
10073
10074 vty_out(vty, "\n");
d62a17ae 10075 }
05c7a1cc 10076 }
d62a17ae 10077 }
10078
10079 /* Dynamic */
10080 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10081 || CHECK_FLAG(p->cap,
10082 PEER_CAP_DYNAMIC_ADV)) {
10083 vty_out(vty, " Dynamic:");
10084 if (CHECK_FLAG(p->cap,
10085 PEER_CAP_DYNAMIC_ADV))
10086 vty_out(vty, " advertised");
10087 if (CHECK_FLAG(p->cap,
10088 PEER_CAP_DYNAMIC_RCV))
10089 vty_out(vty, " %sreceived",
10090 CHECK_FLAG(
10091 p->cap,
10092 PEER_CAP_DYNAMIC_ADV)
10093 ? "and "
10094 : "");
10095 vty_out(vty, "\n");
10096 }
10097
10098 /* Extended nexthop */
10099 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10100 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10101 vty_out(vty, " Extended nexthop:");
10102 if (CHECK_FLAG(p->cap,
10103 PEER_CAP_ENHE_ADV))
10104 vty_out(vty, " advertised");
10105 if (CHECK_FLAG(p->cap,
10106 PEER_CAP_ENHE_RCV))
10107 vty_out(vty, " %sreceived",
10108 CHECK_FLAG(
10109 p->cap,
10110 PEER_CAP_ENHE_ADV)
10111 ? "and "
10112 : "");
10113 vty_out(vty, "\n");
10114
10115 if (CHECK_FLAG(p->cap,
10116 PEER_CAP_ENHE_RCV)) {
10117 vty_out(vty,
10118 " Address families by peer:\n ");
10119 for (safi = SAFI_UNICAST;
10120 safi < SAFI_MAX; safi++)
10121 if (CHECK_FLAG(
10122 p->af_cap
10123 [AFI_IP]
10124 [safi],
10125 PEER_CAP_ENHE_AF_RCV))
10126 vty_out(vty,
10127 " %s\n",
10128 afi_safi_print(
10129 AFI_IP,
10130 safi));
10131 }
10132 }
10133
10134 /* Route Refresh */
10135 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10136 || CHECK_FLAG(p->cap,
10137 PEER_CAP_REFRESH_NEW_RCV)
10138 || CHECK_FLAG(p->cap,
10139 PEER_CAP_REFRESH_OLD_RCV)) {
10140 vty_out(vty, " Route refresh:");
10141 if (CHECK_FLAG(p->cap,
10142 PEER_CAP_REFRESH_ADV))
10143 vty_out(vty, " advertised");
10144 if (CHECK_FLAG(p->cap,
10145 PEER_CAP_REFRESH_NEW_RCV)
10146 || CHECK_FLAG(
10147 p->cap,
10148 PEER_CAP_REFRESH_OLD_RCV))
10149 vty_out(vty, " %sreceived(%s)",
10150 CHECK_FLAG(
10151 p->cap,
10152 PEER_CAP_REFRESH_ADV)
10153 ? "and "
10154 : "",
10155 (CHECK_FLAG(
10156 p->cap,
10157 PEER_CAP_REFRESH_OLD_RCV)
10158 && CHECK_FLAG(
10159 p->cap,
10160 PEER_CAP_REFRESH_NEW_RCV))
10161 ? "old & new"
10162 : CHECK_FLAG(
10163 p->cap,
10164 PEER_CAP_REFRESH_OLD_RCV)
10165 ? "old"
10166 : "new");
10167
10168 vty_out(vty, "\n");
10169 }
10170
10171 /* Multiprotocol Extensions */
05c7a1cc
QY
10172 FOREACH_AFI_SAFI (afi, safi)
10173 if (p->afc_adv[afi][safi]
10174 || p->afc_recv[afi][safi]) {
10175 vty_out(vty,
10176 " Address Family %s:",
10177 afi_safi_print(afi,
10178 safi));
10179 if (p->afc_adv[afi][safi])
d62a17ae 10180 vty_out(vty,
05c7a1cc
QY
10181 " advertised");
10182 if (p->afc_recv[afi][safi])
10183 vty_out(vty,
10184 " %sreceived",
10185 p->afc_adv[afi]
10186 [safi]
10187 ? "and "
10188 : "");
10189 vty_out(vty, "\n");
10190 }
d62a17ae 10191
10192 /* Hostname capability */
60466a63 10193 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10194
10195 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10196 vty_out(vty,
10197 " advertised (name: %s,domain name: %s)",
60466a63
QY
10198 bgp->peer_self->hostname
10199 ? bgp->peer_self
10200 ->hostname
d77114b7 10201 : "n/a",
60466a63
QY
10202 bgp->peer_self->domainname
10203 ? bgp->peer_self
10204 ->domainname
d77114b7
MK
10205 : "n/a");
10206 } else {
10207 vty_out(vty, " not advertised");
d62a17ae 10208 }
10209
d77114b7 10210 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10211 vty_out(vty,
10212 " received (name: %s,domain name: %s)",
60466a63
QY
10213 p->hostname ? p->hostname
10214 : "n/a",
10215 p->domainname ? p->domainname
10216 : "n/a");
d77114b7
MK
10217 } else {
10218 vty_out(vty, " not received");
10219 }
10220
10221 vty_out(vty, "\n");
10222
d62a17ae 10223 /* Gracefull Restart */
10224 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10225 || CHECK_FLAG(p->cap,
10226 PEER_CAP_RESTART_ADV)) {
10227 vty_out(vty,
10228 " Graceful Restart Capabilty:");
10229 if (CHECK_FLAG(p->cap,
10230 PEER_CAP_RESTART_ADV))
10231 vty_out(vty, " advertised");
10232 if (CHECK_FLAG(p->cap,
10233 PEER_CAP_RESTART_RCV))
10234 vty_out(vty, " %sreceived",
10235 CHECK_FLAG(
10236 p->cap,
10237 PEER_CAP_RESTART_ADV)
10238 ? "and "
10239 : "");
10240 vty_out(vty, "\n");
10241
10242 if (CHECK_FLAG(p->cap,
10243 PEER_CAP_RESTART_RCV)) {
10244 int restart_af_count = 0;
10245
10246 vty_out(vty,
10247 " Remote Restart timer is %d seconds\n",
10248 p->v_gr_restart);
10249 vty_out(vty,
10250 " Address families by peer:\n ");
10251
05c7a1cc
QY
10252 FOREACH_AFI_SAFI (afi, safi)
10253 if (CHECK_FLAG(
10254 p->af_cap
10255 [afi]
10256 [safi],
10257 PEER_CAP_RESTART_AF_RCV)) {
10258 vty_out(vty,
10259 "%s%s(%s)",
10260 restart_af_count
10261 ? ", "
10262 : "",
10263 afi_safi_print(
10264 afi,
10265 safi),
10266 CHECK_FLAG(
10267 p->af_cap
10268 [afi]
10269 [safi],
10270 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10271 ? "preserved"
10272 : "not preserved");
10273 restart_af_count++;
10274 }
d62a17ae 10275 if (!restart_af_count)
10276 vty_out(vty, "none");
10277 vty_out(vty, "\n");
10278 }
10279 }
10280 }
10281 }
10282 }
10283
10284 /* graceful restart information */
10285 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10286 || p->t_gr_stale) {
10287 json_object *json_grace = NULL;
10288 json_object *json_grace_send = NULL;
10289 json_object *json_grace_recv = NULL;
10290 int eor_send_af_count = 0;
10291 int eor_receive_af_count = 0;
10292
10293 if (use_json) {
10294 json_grace = json_object_new_object();
10295 json_grace_send = json_object_new_object();
10296 json_grace_recv = json_object_new_object();
10297
10298 if (p->status == Established) {
05c7a1cc
QY
10299 FOREACH_AFI_SAFI (afi, safi) {
10300 if (CHECK_FLAG(p->af_sflags[afi][safi],
10301 PEER_STATUS_EOR_SEND)) {
10302 json_object_boolean_true_add(
10303 json_grace_send,
10304 afi_safi_print(afi,
10305 safi));
10306 eor_send_af_count++;
d62a17ae 10307 }
10308 }
05c7a1cc
QY
10309 FOREACH_AFI_SAFI (afi, safi) {
10310 if (CHECK_FLAG(
10311 p->af_sflags[afi][safi],
10312 PEER_STATUS_EOR_RECEIVED)) {
10313 json_object_boolean_true_add(
10314 json_grace_recv,
10315 afi_safi_print(afi,
10316 safi));
10317 eor_receive_af_count++;
d62a17ae 10318 }
10319 }
10320 }
10321
10322 json_object_object_add(json_grace, "endOfRibSend",
10323 json_grace_send);
10324 json_object_object_add(json_grace, "endOfRibRecv",
10325 json_grace_recv);
10326
10327 if (p->t_gr_restart)
10328 json_object_int_add(json_grace,
10329 "gracefulRestartTimerMsecs",
10330 thread_timer_remain_second(
10331 p->t_gr_restart)
10332 * 1000);
10333
10334 if (p->t_gr_stale)
10335 json_object_int_add(
10336 json_grace,
10337 "gracefulStalepathTimerMsecs",
10338 thread_timer_remain_second(
10339 p->t_gr_stale)
10340 * 1000);
10341
10342 json_object_object_add(
10343 json_neigh, "gracefulRestartInfo", json_grace);
10344 } else {
0437e105 10345 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10346 if (p->status == Established) {
10347 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10348 FOREACH_AFI_SAFI (afi, safi) {
10349 if (CHECK_FLAG(p->af_sflags[afi][safi],
10350 PEER_STATUS_EOR_SEND)) {
10351 vty_out(vty, "%s%s",
10352 eor_send_af_count ? ", "
10353 : "",
10354 afi_safi_print(afi,
10355 safi));
10356 eor_send_af_count++;
d62a17ae 10357 }
10358 }
10359 vty_out(vty, "\n");
10360 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10361 FOREACH_AFI_SAFI (afi, safi) {
10362 if (CHECK_FLAG(
10363 p->af_sflags[afi][safi],
10364 PEER_STATUS_EOR_RECEIVED)) {
10365 vty_out(vty, "%s%s",
10366 eor_receive_af_count
10367 ? ", "
10368 : "",
10369 afi_safi_print(afi,
10370 safi));
10371 eor_receive_af_count++;
d62a17ae 10372 }
10373 }
10374 vty_out(vty, "\n");
10375 }
10376
10377 if (p->t_gr_restart)
10378 vty_out(vty,
10379 " The remaining time of restart timer is %ld\n",
10380 thread_timer_remain_second(
10381 p->t_gr_restart));
10382
10383 if (p->t_gr_stale)
10384 vty_out(vty,
10385 " The remaining time of stalepath timer is %ld\n",
10386 thread_timer_remain_second(
10387 p->t_gr_stale));
10388 }
10389 }
10390 if (use_json) {
10391 json_object *json_stat = NULL;
10392 json_stat = json_object_new_object();
10393 /* Packet counts. */
10394 json_object_int_add(json_stat, "depthInq", 0);
10395 json_object_int_add(json_stat, "depthOutq",
10396 (unsigned long)p->obuf->count);
0112e9e0
QY
10397 json_object_int_add(json_stat, "opensSent",
10398 atomic_load_explicit(&p->open_out,
10399 memory_order_relaxed));
10400 json_object_int_add(json_stat, "opensRecv",
10401 atomic_load_explicit(&p->open_in,
10402 memory_order_relaxed));
d62a17ae 10403 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10404 atomic_load_explicit(&p->notify_out,
10405 memory_order_relaxed));
d62a17ae 10406 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10407 atomic_load_explicit(&p->notify_in,
10408 memory_order_relaxed));
10409 json_object_int_add(json_stat, "updatesSent",
10410 atomic_load_explicit(&p->update_out,
10411 memory_order_relaxed));
10412 json_object_int_add(json_stat, "updatesRecv",
10413 atomic_load_explicit(&p->update_in,
10414 memory_order_relaxed));
d62a17ae 10415 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10416 atomic_load_explicit(&p->keepalive_out,
10417 memory_order_relaxed));
d62a17ae 10418 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10419 atomic_load_explicit(&p->keepalive_in,
10420 memory_order_relaxed));
d62a17ae 10421 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10422 atomic_load_explicit(&p->refresh_out,
10423 memory_order_relaxed));
d62a17ae 10424 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10425 atomic_load_explicit(&p->refresh_in,
10426 memory_order_relaxed));
d62a17ae 10427 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10428 atomic_load_explicit(&p->dynamic_cap_out,
10429 memory_order_relaxed));
d62a17ae 10430 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10431 atomic_load_explicit(&p->dynamic_cap_in,
10432 memory_order_relaxed));
10433 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10434 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10435 json_object_object_add(json_neigh, "messageStats", json_stat);
10436 } else {
10437 /* Packet counts. */
10438 vty_out(vty, " Message statistics:\n");
10439 vty_out(vty, " Inq depth is 0\n");
10440 vty_out(vty, " Outq depth is %lu\n",
10441 (unsigned long)p->obuf->count);
10442 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10443 vty_out(vty, " Opens: %10d %10d\n",
10444 atomic_load_explicit(&p->open_out,
10445 memory_order_relaxed),
10446 atomic_load_explicit(&p->open_in,
10447 memory_order_relaxed));
10448 vty_out(vty, " Notifications: %10d %10d\n",
10449 atomic_load_explicit(&p->notify_out,
10450 memory_order_relaxed),
10451 atomic_load_explicit(&p->notify_in,
10452 memory_order_relaxed));
10453 vty_out(vty, " Updates: %10d %10d\n",
10454 atomic_load_explicit(&p->update_out,
10455 memory_order_relaxed),
10456 atomic_load_explicit(&p->update_in,
10457 memory_order_relaxed));
10458 vty_out(vty, " Keepalives: %10d %10d\n",
10459 atomic_load_explicit(&p->keepalive_out,
10460 memory_order_relaxed),
10461 atomic_load_explicit(&p->keepalive_in,
10462 memory_order_relaxed));
10463 vty_out(vty, " Route Refresh: %10d %10d\n",
10464 atomic_load_explicit(&p->refresh_out,
10465 memory_order_relaxed),
10466 atomic_load_explicit(&p->refresh_in,
10467 memory_order_relaxed));
d62a17ae 10468 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10469 atomic_load_explicit(&p->dynamic_cap_out,
10470 memory_order_relaxed),
10471 atomic_load_explicit(&p->dynamic_cap_in,
10472 memory_order_relaxed));
10473 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10474 PEER_TOTAL_RX(p));
d62a17ae 10475 }
10476
10477 if (use_json) {
10478 /* advertisement-interval */
10479 json_object_int_add(json_neigh,
10480 "minBtwnAdvertisementRunsTimerMsecs",
10481 p->v_routeadv * 1000);
10482
10483 /* Update-source. */
10484 if (p->update_if || p->update_source) {
10485 if (p->update_if)
10486 json_object_string_add(json_neigh,
10487 "updateSource",
10488 p->update_if);
10489 else if (p->update_source)
10490 json_object_string_add(
10491 json_neigh, "updateSource",
10492 sockunion2str(p->update_source, buf1,
10493 SU_ADDRSTRLEN));
10494 }
10495 } else {
10496 /* advertisement-interval */
10497 vty_out(vty,
10498 " Minimum time between advertisement runs is %d seconds\n",
10499 p->v_routeadv);
10500
10501 /* Update-source. */
10502 if (p->update_if || p->update_source) {
10503 vty_out(vty, " Update source is ");
10504 if (p->update_if)
10505 vty_out(vty, "%s", p->update_if);
10506 else if (p->update_source)
10507 vty_out(vty, "%s",
10508 sockunion2str(p->update_source, buf1,
10509 SU_ADDRSTRLEN));
10510 vty_out(vty, "\n");
10511 }
10512
10513 vty_out(vty, "\n");
10514 }
10515
10516 /* Address Family Information */
10517 json_object *json_hold = NULL;
10518
10519 if (use_json)
10520 json_hold = json_object_new_object();
10521
05c7a1cc
QY
10522 FOREACH_AFI_SAFI (afi, safi)
10523 if (p->afc[afi][safi])
10524 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10525 json_hold);
d62a17ae 10526
10527 if (use_json) {
10528 json_object_object_add(json_neigh, "addressFamilyInfo",
10529 json_hold);
10530 json_object_int_add(json_neigh, "connectionsEstablished",
10531 p->established);
10532 json_object_int_add(json_neigh, "connectionsDropped",
10533 p->dropped);
10534 } else
10535 vty_out(vty, " Connections established %d; dropped %d\n",
10536 p->established, p->dropped);
10537
10538 if (!p->last_reset) {
10539 if (use_json)
10540 json_object_string_add(json_neigh, "lastReset",
10541 "never");
10542 else
10543 vty_out(vty, " Last reset never\n");
10544 } else {
10545 if (use_json) {
10546 time_t uptime;
10547 struct tm *tm;
10548
10549 uptime = bgp_clock();
10550 uptime -= p->resettime;
10551 tm = gmtime(&uptime);
10552 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10553 (tm->tm_sec * 1000)
10554 + (tm->tm_min * 60000)
10555 + (tm->tm_hour * 3600000));
10556 json_object_string_add(
10557 json_neigh, "lastResetDueTo",
10558 peer_down_str[(int)p->last_reset]);
10559 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10560 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10561 char errorcodesubcode_hexstr[5];
10562 char errorcodesubcode_str[256];
10563
10564 code_str = bgp_notify_code_str(p->notify.code);
10565 subcode_str = bgp_notify_subcode_str(
10566 p->notify.code, p->notify.subcode);
10567
10568 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10569 p->notify.code, p->notify.subcode);
10570 json_object_string_add(json_neigh,
10571 "lastErrorCodeSubcode",
10572 errorcodesubcode_hexstr);
10573 snprintf(errorcodesubcode_str, 255, "%s%s",
10574 code_str, subcode_str);
10575 json_object_string_add(json_neigh,
10576 "lastNotificationReason",
10577 errorcodesubcode_str);
10578 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10579 && p->notify.code == BGP_NOTIFY_CEASE
10580 && (p->notify.subcode
10581 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10582 || p->notify.subcode
10583 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10584 && p->notify.length) {
10585 char msgbuf[1024];
10586 const char *msg_str;
10587
10588 msg_str = bgp_notify_admin_message(
10589 msgbuf, sizeof(msgbuf),
d7c0a89a 10590 (uint8_t *)p->notify.data,
d62a17ae 10591 p->notify.length);
10592 if (msg_str)
10593 json_object_string_add(
10594 json_neigh,
10595 "lastShutdownDescription",
10596 msg_str);
10597 }
10598 }
10599 } else {
10600 vty_out(vty, " Last reset %s, ",
10601 peer_uptime(p->resettime, timebuf,
10602 BGP_UPTIME_LEN, 0, NULL));
10603
10604 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10605 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10606 code_str = bgp_notify_code_str(p->notify.code);
10607 subcode_str = bgp_notify_subcode_str(
10608 p->notify.code, p->notify.subcode);
10609 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10610 p->last_reset == PEER_DOWN_NOTIFY_SEND
10611 ? "sent"
10612 : "received",
10613 code_str, subcode_str);
10614 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10615 && p->notify.code == BGP_NOTIFY_CEASE
10616 && (p->notify.subcode
10617 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10618 || p->notify.subcode
10619 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10620 && p->notify.length) {
10621 char msgbuf[1024];
10622 const char *msg_str;
10623
10624 msg_str = bgp_notify_admin_message(
10625 msgbuf, sizeof(msgbuf),
d7c0a89a 10626 (uint8_t *)p->notify.data,
d62a17ae 10627 p->notify.length);
10628 if (msg_str)
10629 vty_out(vty,
10630 " Message: \"%s\"\n",
10631 msg_str);
10632 }
10633 } else {
10634 vty_out(vty, "due to %s\n",
10635 peer_down_str[(int)p->last_reset]);
10636 }
10637
10638 if (p->last_reset_cause_size) {
10639 msg = p->last_reset_cause;
10640 vty_out(vty,
10641 " Message received that caused BGP to send a NOTIFICATION:\n ");
10642 for (i = 1; i <= p->last_reset_cause_size;
10643 i++) {
10644 vty_out(vty, "%02X", *msg++);
10645
10646 if (i != p->last_reset_cause_size) {
10647 if (i % 16 == 0) {
10648 vty_out(vty, "\n ");
10649 } else if (i % 4 == 0) {
10650 vty_out(vty, " ");
10651 }
10652 }
10653 }
10654 vty_out(vty, "\n");
10655 }
10656 }
10657 }
10658
10659 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10660 if (use_json)
10661 json_object_boolean_true_add(json_neigh,
10662 "prefixesConfigExceedMax");
10663 else
10664 vty_out(vty,
10665 " Peer had exceeded the max. no. of prefixes configured.\n");
10666
10667 if (p->t_pmax_restart) {
10668 if (use_json) {
10669 json_object_boolean_true_add(
10670 json_neigh, "reducePrefixNumFrom");
10671 json_object_int_add(json_neigh,
10672 "restartInTimerMsec",
10673 thread_timer_remain_second(
10674 p->t_pmax_restart)
10675 * 1000);
10676 } else
10677 vty_out(vty,
10678 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10679 p->host, thread_timer_remain_second(
10680 p->t_pmax_restart));
d62a17ae 10681 } else {
10682 if (use_json)
10683 json_object_boolean_true_add(
10684 json_neigh,
10685 "reducePrefixNumAndClearIpBgp");
10686 else
10687 vty_out(vty,
10688 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10689 p->host);
10690 }
10691 }
10692
10693 /* EBGP Multihop and GTSM */
10694 if (p->sort != BGP_PEER_IBGP) {
10695 if (use_json) {
10696 if (p->gtsm_hops > 0)
10697 json_object_int_add(json_neigh,
10698 "externalBgpNbrMaxHopsAway",
10699 p->gtsm_hops);
10700 else if (p->ttl > 1)
10701 json_object_int_add(json_neigh,
10702 "externalBgpNbrMaxHopsAway",
10703 p->ttl);
10704 } else {
10705 if (p->gtsm_hops > 0)
10706 vty_out(vty,
10707 " External BGP neighbor may be up to %d hops away.\n",
10708 p->gtsm_hops);
10709 else if (p->ttl > 1)
10710 vty_out(vty,
10711 " External BGP neighbor may be up to %d hops away.\n",
10712 p->ttl);
10713 }
10714 } else {
10715 if (p->gtsm_hops > 0) {
10716 if (use_json)
10717 json_object_int_add(json_neigh,
10718 "internalBgpNbrMaxHopsAway",
10719 p->gtsm_hops);
10720 else
10721 vty_out(vty,
10722 " Internal BGP neighbor may be up to %d hops away.\n",
10723 p->gtsm_hops);
10724 }
10725 }
10726
10727 /* Local address. */
10728 if (p->su_local) {
10729 if (use_json) {
10730 json_object_string_add(json_neigh, "hostLocal",
10731 sockunion2str(p->su_local, buf1,
10732 SU_ADDRSTRLEN));
10733 json_object_int_add(json_neigh, "portLocal",
10734 ntohs(p->su_local->sin.sin_port));
10735 } else
10736 vty_out(vty, "Local host: %s, Local port: %d\n",
10737 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10738 ntohs(p->su_local->sin.sin_port));
10739 }
10740
10741 /* Remote address. */
10742 if (p->su_remote) {
10743 if (use_json) {
10744 json_object_string_add(json_neigh, "hostForeign",
10745 sockunion2str(p->su_remote, buf1,
10746 SU_ADDRSTRLEN));
10747 json_object_int_add(json_neigh, "portForeign",
10748 ntohs(p->su_remote->sin.sin_port));
10749 } else
10750 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10751 sockunion2str(p->su_remote, buf1,
10752 SU_ADDRSTRLEN),
10753 ntohs(p->su_remote->sin.sin_port));
10754 }
10755
10756 /* Nexthop display. */
10757 if (p->su_local) {
10758 if (use_json) {
10759 json_object_string_add(json_neigh, "nexthop",
10760 inet_ntop(AF_INET,
10761 &p->nexthop.v4, buf1,
10762 sizeof(buf1)));
10763 json_object_string_add(json_neigh, "nexthopGlobal",
10764 inet_ntop(AF_INET6,
10765 &p->nexthop.v6_global,
10766 buf1, sizeof(buf1)));
10767 json_object_string_add(json_neigh, "nexthopLocal",
10768 inet_ntop(AF_INET6,
10769 &p->nexthop.v6_local,
10770 buf1, sizeof(buf1)));
10771 if (p->shared_network)
10772 json_object_string_add(json_neigh,
10773 "bgpConnection",
10774 "sharedNetwork");
10775 else
10776 json_object_string_add(json_neigh,
10777 "bgpConnection",
10778 "nonSharedNetwork");
10779 } else {
10780 vty_out(vty, "Nexthop: %s\n",
10781 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10782 sizeof(buf1)));
10783 vty_out(vty, "Nexthop global: %s\n",
10784 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10785 sizeof(buf1)));
10786 vty_out(vty, "Nexthop local: %s\n",
10787 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10788 sizeof(buf1)));
10789 vty_out(vty, "BGP connection: %s\n",
10790 p->shared_network ? "shared network"
10791 : "non shared network");
10792 }
10793 }
10794
10795 /* Timer information. */
10796 if (use_json) {
10797 json_object_int_add(json_neigh, "connectRetryTimer",
10798 p->v_connect);
10799 if (p->status == Established && p->rtt)
10800 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10801 p->rtt);
10802 if (p->t_start)
10803 json_object_int_add(
10804 json_neigh, "nextStartTimerDueInMsecs",
10805 thread_timer_remain_second(p->t_start) * 1000);
10806 if (p->t_connect)
10807 json_object_int_add(
10808 json_neigh, "nextConnectTimerDueInMsecs",
10809 thread_timer_remain_second(p->t_connect)
10810 * 1000);
10811 if (p->t_routeadv) {
10812 json_object_int_add(json_neigh, "mraiInterval",
10813 p->v_routeadv);
10814 json_object_int_add(
10815 json_neigh, "mraiTimerExpireInMsecs",
10816 thread_timer_remain_second(p->t_routeadv)
10817 * 1000);
10818 }
10819 if (p->password)
10820 json_object_int_add(json_neigh, "authenticationEnabled",
10821 1);
10822
10823 if (p->t_read)
10824 json_object_string_add(json_neigh, "readThread", "on");
10825 else
10826 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10827
10828 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10829 json_object_string_add(json_neigh, "writeThread", "on");
10830 else
10831 json_object_string_add(json_neigh, "writeThread",
10832 "off");
10833 } else {
10834 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10835 p->v_connect);
10836 if (p->status == Established && p->rtt)
10837 vty_out(vty, "Estimated round trip time: %d ms\n",
10838 p->rtt);
10839 if (p->t_start)
10840 vty_out(vty, "Next start timer due in %ld seconds\n",
10841 thread_timer_remain_second(p->t_start));
10842 if (p->t_connect)
10843 vty_out(vty, "Next connect timer due in %ld seconds\n",
10844 thread_timer_remain_second(p->t_connect));
10845 if (p->t_routeadv)
10846 vty_out(vty,
10847 "MRAI (interval %u) timer expires in %ld seconds\n",
10848 p->v_routeadv,
10849 thread_timer_remain_second(p->t_routeadv));
10850 if (p->password)
10851 vty_out(vty, "Peer Authentication Enabled\n");
10852
cac9e917 10853 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
10854 p->t_read ? "on" : "off",
10855 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10856 ? "on"
cac9e917 10857 : "off", p->fd);
d62a17ae 10858 }
10859
10860 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10861 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10862 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10863
10864 if (!use_json)
10865 vty_out(vty, "\n");
10866
10867 /* BFD information. */
10868 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10869
10870 if (use_json) {
10871 if (p->conf_if) /* Configured interface name. */
10872 json_object_object_add(json, p->conf_if, json_neigh);
10873 else /* Configured IP address. */
10874 json_object_object_add(json, p->host, json_neigh);
10875 }
10876}
10877
10878static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10879 enum show_type type, union sockunion *su,
9f049418 10880 const char *conf_if, bool use_json,
d62a17ae 10881 json_object *json)
10882{
10883 struct listnode *node, *nnode;
10884 struct peer *peer;
10885 int find = 0;
9f049418 10886 bool nbr_output = false;
d1927ebe
AS
10887 afi_t afi = AFI_MAX;
10888 safi_t safi = SAFI_MAX;
10889
10890 if (type == show_ipv4_peer || type == show_ipv4_all) {
10891 afi = AFI_IP;
10892 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10893 afi = AFI_IP6;
10894 }
d62a17ae 10895
10896 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10897 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10898 continue;
10899
10900 switch (type) {
10901 case show_all:
10902 bgp_show_peer(vty, peer, use_json, json);
9f049418 10903 nbr_output = true;
d62a17ae 10904 break;
10905 case show_peer:
10906 if (conf_if) {
10907 if ((peer->conf_if
10908 && !strcmp(peer->conf_if, conf_if))
10909 || (peer->hostname
10910 && !strcmp(peer->hostname, conf_if))) {
10911 find = 1;
10912 bgp_show_peer(vty, peer, use_json,
10913 json);
10914 }
10915 } else {
10916 if (sockunion_same(&peer->su, su)) {
10917 find = 1;
10918 bgp_show_peer(vty, peer, use_json,
10919 json);
10920 }
10921 }
10922 break;
d1927ebe
AS
10923 case show_ipv4_peer:
10924 case show_ipv6_peer:
10925 FOREACH_SAFI (safi) {
10926 if (peer->afc[afi][safi]) {
10927 if (conf_if) {
10928 if ((peer->conf_if
10929 && !strcmp(peer->conf_if, conf_if))
10930 || (peer->hostname
10931 && !strcmp(peer->hostname, conf_if))) {
10932 find = 1;
10933 bgp_show_peer(vty, peer, use_json,
10934 json);
10935 break;
10936 }
10937 } else {
10938 if (sockunion_same(&peer->su, su)) {
10939 find = 1;
10940 bgp_show_peer(vty, peer, use_json,
10941 json);
10942 break;
10943 }
10944 }
10945 }
10946 }
10947 break;
10948 case show_ipv4_all:
10949 case show_ipv6_all:
10950 FOREACH_SAFI (safi) {
10951 if (peer->afc[afi][safi]) {
10952 bgp_show_peer(vty, peer, use_json, json);
10953 nbr_output = true;
10954 break;
10955 }
10956 }
10957 break;
d62a17ae 10958 }
10959 }
10960
d1927ebe
AS
10961 if ((type == show_peer || type == show_ipv4_peer ||
10962 type == show_ipv6_peer) && !find) {
d62a17ae 10963 if (use_json)
10964 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10965 else
88b7d255 10966 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 10967 }
10968
d1927ebe
AS
10969 if (type != show_peer && type != show_ipv4_peer &&
10970 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 10971 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 10972
d62a17ae 10973 if (use_json) {
996c9314
LB
10974 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10975 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10976 } else {
10977 vty_out(vty, "\n");
10978 }
10979
10980 return CMD_SUCCESS;
10981}
10982
10983static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10984 enum show_type type,
10985 const char *ip_str,
9f049418 10986 bool use_json)
d62a17ae 10987{
0291c246
MK
10988 struct listnode *node, *nnode;
10989 struct bgp *bgp;
71aedaa3 10990 union sockunion su;
0291c246 10991 json_object *json = NULL;
71aedaa3 10992 int ret, is_first = 1;
9f049418 10993 bool nbr_output = false;
d62a17ae 10994
10995 if (use_json)
10996 vty_out(vty, "{\n");
10997
10998 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10999 nbr_output = true;
d62a17ae 11000 if (use_json) {
11001 if (!(json = json_object_new_object())) {
af4c2728 11002 flog_err(
e50f7cfd 11003 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11004 "Unable to allocate memory for JSON object");
11005 vty_out(vty,
11006 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11007 return;
11008 }
11009
11010 json_object_int_add(json, "vrfId",
11011 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11012 ? -1
11013 : (int64_t)bgp->vrf_id);
d62a17ae 11014 json_object_string_add(
11015 json, "vrfName",
11016 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11017 ? VRF_DEFAULT_NAME
d62a17ae 11018 : bgp->name);
11019
11020 if (!is_first)
11021 vty_out(vty, ",\n");
11022 else
11023 is_first = 0;
11024
11025 vty_out(vty, "\"%s\":",
11026 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11027 ? VRF_DEFAULT_NAME
d62a17ae 11028 : bgp->name);
11029 } else {
11030 vty_out(vty, "\nInstance %s:\n",
11031 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11032 ? VRF_DEFAULT_NAME
d62a17ae 11033 : bgp->name);
11034 }
71aedaa3 11035
d1927ebe
AS
11036 if (type == show_peer || type == show_ipv4_peer ||
11037 type == show_ipv6_peer) {
71aedaa3
DS
11038 ret = str2sockunion(ip_str, &su);
11039 if (ret < 0)
11040 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11041 use_json, json);
11042 else
11043 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11044 use_json, json);
11045 } else {
d1927ebe 11046 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11047 use_json, json);
11048 }
b77004d6 11049 json_object_free(json);
d62a17ae 11050 }
11051
01cbfd04 11052 if (use_json) {
d62a17ae 11053 vty_out(vty, "}\n");
01cbfd04
QY
11054 json_object_free(json);
11055 }
9f049418
DS
11056 else if (!nbr_output)
11057 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11058}
11059
11060static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11061 enum show_type type, const char *ip_str,
9f049418 11062 bool use_json)
d62a17ae 11063{
11064 int ret;
11065 struct bgp *bgp;
11066 union sockunion su;
11067 json_object *json = NULL;
11068
11069 if (name) {
11070 if (strmatch(name, "all")) {
71aedaa3
DS
11071 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11072 use_json);
d62a17ae 11073 return CMD_SUCCESS;
11074 } else {
11075 bgp = bgp_lookup_by_name(name);
11076 if (!bgp) {
11077 if (use_json) {
11078 json = json_object_new_object();
d62a17ae 11079 vty_out(vty, "%s\n",
11080 json_object_to_json_string_ext(
11081 json,
11082 JSON_C_TO_STRING_PRETTY));
11083 json_object_free(json);
11084 } else
11085 vty_out(vty,
9f049418 11086 "%% BGP instance not found\n");
d62a17ae 11087
11088 return CMD_WARNING;
11089 }
11090 }
11091 } else {
11092 bgp = bgp_get_default();
11093 }
11094
11095 if (bgp) {
11096 json = json_object_new_object();
11097 if (ip_str) {
11098 ret = str2sockunion(ip_str, &su);
11099 if (ret < 0)
11100 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11101 use_json, json);
11102 else
11103 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11104 use_json, json);
11105 } else {
11106 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11107 json);
11108 }
11109 json_object_free(json);
ca61fd25
DS
11110 } else {
11111 if (use_json)
11112 vty_out(vty, "{}\n");
11113 else
11114 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11115 }
11116
11117 return CMD_SUCCESS;
4fb25c53
DW
11118}
11119
716b2d8a 11120/* "show [ip] bgp neighbors" commands. */
718e3744 11121DEFUN (show_ip_bgp_neighbors,
11122 show_ip_bgp_neighbors_cmd,
24345e82 11123 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11124 SHOW_STR
11125 IP_STR
11126 BGP_STR
f2a8972b 11127 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11128 "Address Family\n"
11129 "Address Family\n"
718e3744 11130 "Detailed information on TCP and BGP neighbor connections\n"
11131 "Neighbor to display information about\n"
a80beece 11132 "Neighbor to display information about\n"
91d37724 11133 "Neighbor on BGP configured interface\n"
9973d184 11134 JSON_STR)
718e3744 11135{
d62a17ae 11136 char *vrf = NULL;
11137 char *sh_arg = NULL;
11138 enum show_type sh_type;
d1927ebe 11139 afi_t afi = AFI_MAX;
718e3744 11140
9f049418 11141 bool uj = use_json(argc, argv);
718e3744 11142
d62a17ae 11143 int idx = 0;
718e3744 11144
9a8bdf1c
PG
11145 /* [<vrf> VIEWVRFNAME] */
11146 if (argv_find(argv, argc, "vrf", &idx)) {
11147 vrf = argv[idx + 1]->arg;
11148 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11149 vrf = NULL;
11150 } else if (argv_find(argv, argc, "view", &idx))
11151 /* [<view> VIEWVRFNAME] */
d62a17ae 11152 vrf = argv[idx + 1]->arg;
718e3744 11153
d62a17ae 11154 idx++;
d1927ebe
AS
11155
11156 if (argv_find(argv, argc, "ipv4", &idx)) {
11157 sh_type = show_ipv4_all;
11158 afi = AFI_IP;
11159 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11160 sh_type = show_ipv6_all;
11161 afi = AFI_IP6;
11162 } else {
11163 sh_type = show_all;
11164 }
11165
d62a17ae 11166 if (argv_find(argv, argc, "A.B.C.D", &idx)
11167 || argv_find(argv, argc, "X:X::X:X", &idx)
11168 || argv_find(argv, argc, "WORD", &idx)) {
11169 sh_type = show_peer;
11170 sh_arg = argv[idx]->arg;
d1927ebe
AS
11171 }
11172
11173 if (sh_type == show_peer && afi == AFI_IP) {
11174 sh_type = show_ipv4_peer;
11175 } else if (sh_type == show_peer && afi == AFI_IP6) {
11176 sh_type = show_ipv6_peer;
11177 }
856ca177 11178
d62a17ae 11179 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11180}
11181
716b2d8a 11182/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11183 paths' and `show ip mbgp paths'. Those functions results are the
11184 same.*/
f412b39a 11185DEFUN (show_ip_bgp_paths,
718e3744 11186 show_ip_bgp_paths_cmd,
46f296b4 11187 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11188 SHOW_STR
11189 IP_STR
11190 BGP_STR
46f296b4 11191 BGP_SAFI_HELP_STR
718e3744 11192 "Path information\n")
11193{
d62a17ae 11194 vty_out(vty, "Address Refcnt Path\n");
11195 aspath_print_all_vty(vty);
11196 return CMD_SUCCESS;
718e3744 11197}
11198
718e3744 11199#include "hash.h"
11200
e3b78da8 11201static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11202 struct vty *vty)
718e3744 11203{
d62a17ae 11204 struct community *com;
718e3744 11205
e3b78da8 11206 com = (struct community *)bucket->data;
3f65c5b1 11207 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11208 community_str(com, false));
718e3744 11209}
11210
11211/* Show BGP's community internal data. */
f412b39a 11212DEFUN (show_ip_bgp_community_info,
718e3744 11213 show_ip_bgp_community_info_cmd,
bec37ba5 11214 "show [ip] bgp community-info",
718e3744 11215 SHOW_STR
11216 IP_STR
11217 BGP_STR
11218 "List all bgp community information\n")
11219{
d62a17ae 11220 vty_out(vty, "Address Refcnt Community\n");
718e3744 11221
d62a17ae 11222 hash_iterate(community_hash(),
e3b78da8 11223 (void (*)(struct hash_bucket *,
d62a17ae 11224 void *))community_show_all_iterator,
11225 vty);
718e3744 11226
d62a17ae 11227 return CMD_SUCCESS;
718e3744 11228}
11229
e3b78da8 11230static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11231 struct vty *vty)
57d187bc 11232{
d62a17ae 11233 struct lcommunity *lcom;
57d187bc 11234
e3b78da8 11235 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11236 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11237 lcommunity_str(lcom, false));
57d187bc
JS
11238}
11239
11240/* Show BGP's community internal data. */
11241DEFUN (show_ip_bgp_lcommunity_info,
11242 show_ip_bgp_lcommunity_info_cmd,
11243 "show ip bgp large-community-info",
11244 SHOW_STR
11245 IP_STR
11246 BGP_STR
11247 "List all bgp large-community information\n")
11248{
d62a17ae 11249 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11250
d62a17ae 11251 hash_iterate(lcommunity_hash(),
e3b78da8 11252 (void (*)(struct hash_bucket *,
d62a17ae 11253 void *))lcommunity_show_all_iterator,
11254 vty);
57d187bc 11255
d62a17ae 11256 return CMD_SUCCESS;
57d187bc
JS
11257}
11258
11259
f412b39a 11260DEFUN (show_ip_bgp_attr_info,
718e3744 11261 show_ip_bgp_attr_info_cmd,
bec37ba5 11262 "show [ip] bgp attribute-info",
718e3744 11263 SHOW_STR
11264 IP_STR
11265 BGP_STR
11266 "List all bgp attribute information\n")
11267{
d62a17ae 11268 attr_show_all(vty);
11269 return CMD_SUCCESS;
718e3744 11270}
6b0655a2 11271
03915806
CS
11272static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11273 afi_t afi, safi_t safi,
11274 bool use_json, json_object *json)
53089bec 11275{
11276 struct bgp *bgp;
11277 struct listnode *node;
11278 char *vname;
11279 char buf1[INET6_ADDRSTRLEN];
11280 char *ecom_str;
11281 vpn_policy_direction_t dir;
11282
03915806 11283 if (json) {
b46dfd20
DS
11284 json_object *json_import_vrfs = NULL;
11285 json_object *json_export_vrfs = NULL;
11286
b46dfd20
DS
11287 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11288
53089bec 11289 if (!bgp) {
b46dfd20
DS
11290 vty_out(vty, "%s\n",
11291 json_object_to_json_string_ext(
11292 json,
11293 JSON_C_TO_STRING_PRETTY));
11294 json_object_free(json);
11295
53089bec 11296 return CMD_WARNING;
11297 }
b46dfd20 11298
94d4c685
DS
11299 /* Provide context for the block */
11300 json_object_string_add(json, "vrf", name ? name : "default");
11301 json_object_string_add(json, "afiSafi",
11302 afi_safi_print(afi, safi));
11303
b46dfd20
DS
11304 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11305 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11306 json_object_string_add(json, "importFromVrfs", "none");
11307 json_object_string_add(json, "importRts", "none");
11308 } else {
6ce24e52
DS
11309 json_import_vrfs = json_object_new_array();
11310
b46dfd20
DS
11311 for (ALL_LIST_ELEMENTS_RO(
11312 bgp->vpn_policy[afi].import_vrf,
11313 node, vname))
11314 json_object_array_add(json_import_vrfs,
11315 json_object_new_string(vname));
11316
b20875ea
CS
11317 json_object_object_add(json, "importFromVrfs",
11318 json_import_vrfs);
b46dfd20 11319 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11320 if (bgp->vpn_policy[afi].rtlist[dir]) {
11321 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11322 bgp->vpn_policy[afi].rtlist[dir],
11323 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11324 json_object_string_add(json, "importRts",
11325 ecom_str);
11326 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11327 } else
11328 json_object_string_add(json, "importRts",
11329 "none");
b46dfd20
DS
11330 }
11331
11332 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11333 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11334 json_object_string_add(json, "exportToVrfs", "none");
11335 json_object_string_add(json, "routeDistinguisher",
11336 "none");
11337 json_object_string_add(json, "exportRts", "none");
11338 } else {
6ce24e52
DS
11339 json_export_vrfs = json_object_new_array();
11340
b46dfd20
DS
11341 for (ALL_LIST_ELEMENTS_RO(
11342 bgp->vpn_policy[afi].export_vrf,
11343 node, vname))
11344 json_object_array_add(json_export_vrfs,
11345 json_object_new_string(vname));
11346 json_object_object_add(json, "exportToVrfs",
11347 json_export_vrfs);
11348 json_object_string_add(json, "routeDistinguisher",
11349 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11350 buf1, RD_ADDRSTRLEN));
11351
11352 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11353 if (bgp->vpn_policy[afi].rtlist[dir]) {
11354 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11355 bgp->vpn_policy[afi].rtlist[dir],
11356 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11357 json_object_string_add(json, "exportRts",
11358 ecom_str);
11359 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11360 } else
11361 json_object_string_add(json, "exportRts",
11362 "none");
b46dfd20
DS
11363 }
11364
03915806
CS
11365 if (use_json) {
11366 vty_out(vty, "%s\n",
11367 json_object_to_json_string_ext(json,
b46dfd20 11368 JSON_C_TO_STRING_PRETTY));
03915806
CS
11369 json_object_free(json);
11370 }
53089bec 11371 } else {
b46dfd20
DS
11372 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11373
53089bec 11374 if (!bgp) {
b46dfd20 11375 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11376 return CMD_WARNING;
11377 }
53089bec 11378
b46dfd20
DS
11379 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11380 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11381 vty_out(vty,
11382 "This VRF is not importing %s routes from any other VRF\n",
11383 afi_safi_print(afi, safi));
11384 else {
11385 vty_out(vty,
11386 "This VRF is importing %s routes from the following VRFs:\n",
11387 afi_safi_print(afi, safi));
11388
11389 for (ALL_LIST_ELEMENTS_RO(
11390 bgp->vpn_policy[afi].import_vrf,
11391 node, vname))
11392 vty_out(vty, " %s\n", vname);
11393
11394 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11395 ecom_str = NULL;
11396 if (bgp->vpn_policy[afi].rtlist[dir]) {
11397 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11398 bgp->vpn_policy[afi].rtlist[dir],
11399 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 11400 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 11401
b20875ea
CS
11402 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11403 } else
11404 vty_out(vty, "Import RT(s):\n");
53089bec 11405 }
53089bec 11406
b46dfd20
DS
11407 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11408 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11409 vty_out(vty,
11410 "This VRF is not exporting %s routes to any other VRF\n",
53089bec 11411 afi_safi_print(afi, safi));
b46dfd20
DS
11412 else {
11413 vty_out(vty,
04c9077f 11414 "This VRF is exporting %s routes to the following VRFs:\n",
53089bec 11415 afi_safi_print(afi, safi));
b46dfd20
DS
11416
11417 for (ALL_LIST_ELEMENTS_RO(
11418 bgp->vpn_policy[afi].export_vrf,
11419 node, vname))
11420 vty_out(vty, " %s\n", vname);
11421
11422 vty_out(vty, "RD: %s\n",
11423 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11424 buf1, RD_ADDRSTRLEN));
11425
11426 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11427 if (bgp->vpn_policy[afi].rtlist[dir]) {
11428 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11429 bgp->vpn_policy[afi].rtlist[dir],
11430 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11431 vty_out(vty, "Export RT: %s\n", ecom_str);
11432 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11433 } else
11434 vty_out(vty, "Import RT(s):\n");
53089bec 11435 }
53089bec 11436 }
11437
11438 return CMD_SUCCESS;
11439}
11440
03915806
CS
11441static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11442 safi_t safi, bool use_json)
11443{
11444 struct listnode *node, *nnode;
11445 struct bgp *bgp;
11446 char *vrf_name = NULL;
11447 json_object *json = NULL;
11448 json_object *json_vrf = NULL;
11449 json_object *json_vrfs = NULL;
11450
11451 if (use_json) {
11452 json = json_object_new_object();
11453 json_vrfs = json_object_new_object();
11454 }
11455
11456 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11457
11458 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11459 vrf_name = bgp->name;
11460
11461 if (use_json) {
11462 json_vrf = json_object_new_object();
11463 } else {
11464 vty_out(vty, "\nInstance %s:\n",
11465 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11466 ? VRF_DEFAULT_NAME : bgp->name);
11467 }
11468 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11469 if (use_json) {
11470 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11471 json_object_object_add(json_vrfs,
11472 VRF_DEFAULT_NAME, json_vrf);
11473 else
11474 json_object_object_add(json_vrfs, vrf_name,
11475 json_vrf);
11476 }
11477 }
11478
11479 if (use_json) {
11480 json_object_object_add(json, "vrfs", json_vrfs);
11481 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11482 JSON_C_TO_STRING_PRETTY));
11483 json_object_free(json);
11484 }
11485
11486 return CMD_SUCCESS;
11487}
11488
53089bec 11489/* "show [ip] bgp route-leak" command. */
11490DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11491 show_ip_bgp_route_leak_cmd,
11492 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11493 SHOW_STR
11494 IP_STR
11495 BGP_STR
11496 BGP_INSTANCE_HELP_STR
11497 BGP_AFI_HELP_STR
11498 BGP_SAFI_HELP_STR
11499 "Route leaking information\n"
11500 JSON_STR)
53089bec 11501{
11502 char *vrf = NULL;
11503 afi_t afi = AFI_MAX;
11504 safi_t safi = SAFI_MAX;
11505
9f049418 11506 bool uj = use_json(argc, argv);
53089bec 11507 int idx = 0;
03915806 11508 json_object *json = NULL;
53089bec 11509
11510 /* show [ip] bgp */
11511 if (argv_find(argv, argc, "ip", &idx)) {
11512 afi = AFI_IP;
11513 safi = SAFI_UNICAST;
11514 }
11515 /* [vrf VIEWVRFNAME] */
11516 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11517 vty_out(vty,
11518 "%% This command is not applicable to BGP views\n");
53089bec 11519 return CMD_WARNING;
11520 }
11521
9a8bdf1c
PG
11522 if (argv_find(argv, argc, "vrf", &idx)) {
11523 vrf = argv[idx + 1]->arg;
11524 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11525 vrf = NULL;
11526 }
53089bec 11527 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11528 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11529 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11530 }
11531
11532 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11533 vty_out(vty,
11534 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11535 return CMD_WARNING;
11536 }
11537
03915806
CS
11538 if (vrf && strmatch(vrf, "all"))
11539 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11540
11541 if (uj)
11542 json = json_object_new_object();
11543
11544 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11545}
11546
d62a17ae 11547static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11548 safi_t safi)
f186de26 11549{
d62a17ae 11550 struct listnode *node, *nnode;
11551 struct bgp *bgp;
f186de26 11552
d62a17ae 11553 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11554 vty_out(vty, "\nInstance %s:\n",
11555 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11556 ? VRF_DEFAULT_NAME
d62a17ae 11557 : bgp->name);
11558 update_group_show(bgp, afi, safi, vty, 0);
11559 }
f186de26 11560}
11561
d62a17ae 11562static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11563 int safi, uint64_t subgrp_id)
4fb25c53 11564{
d62a17ae 11565 struct bgp *bgp;
4fb25c53 11566
d62a17ae 11567 if (name) {
11568 if (strmatch(name, "all")) {
11569 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11570 return CMD_SUCCESS;
11571 } else {
11572 bgp = bgp_lookup_by_name(name);
11573 }
11574 } else {
11575 bgp = bgp_get_default();
11576 }
4fb25c53 11577
d62a17ae 11578 if (bgp)
11579 update_group_show(bgp, afi, safi, vty, subgrp_id);
11580 return CMD_SUCCESS;
4fb25c53
DW
11581}
11582
8fe8a7f6
DS
11583DEFUN (show_ip_bgp_updgrps,
11584 show_ip_bgp_updgrps_cmd,
c1a44e43 11585 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11586 SHOW_STR
11587 IP_STR
11588 BGP_STR
11589 BGP_INSTANCE_HELP_STR
c9e571b4 11590 BGP_AFI_HELP_STR
9bedbb1e 11591 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11592 "Detailed info about dynamic update groups\n"
11593 "Specific subgroup to display detailed info for\n")
8386ac43 11594{
d62a17ae 11595 char *vrf = NULL;
11596 afi_t afi = AFI_IP6;
11597 safi_t safi = SAFI_UNICAST;
11598 uint64_t subgrp_id = 0;
11599
11600 int idx = 0;
11601
11602 /* show [ip] bgp */
11603 if (argv_find(argv, argc, "ip", &idx))
11604 afi = AFI_IP;
9a8bdf1c
PG
11605 /* [<vrf> VIEWVRFNAME] */
11606 if (argv_find(argv, argc, "vrf", &idx)) {
11607 vrf = argv[idx + 1]->arg;
11608 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11609 vrf = NULL;
11610 } else if (argv_find(argv, argc, "view", &idx))
11611 /* [<view> VIEWVRFNAME] */
11612 vrf = argv[idx + 1]->arg;
d62a17ae 11613 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11614 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11615 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11616 }
5bf15956 11617
d62a17ae 11618 /* get subgroup id, if provided */
11619 idx = argc - 1;
11620 if (argv[idx]->type == VARIABLE_TKN)
11621 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11622
d62a17ae 11623 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11624}
11625
f186de26 11626DEFUN (show_bgp_instance_all_ipv6_updgrps,
11627 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11628 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11629 SHOW_STR
716b2d8a 11630 IP_STR
f186de26 11631 BGP_STR
11632 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11633 "Detailed info about dynamic update groups\n")
f186de26 11634{
d62a17ae 11635 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11636 return CMD_SUCCESS;
f186de26 11637}
11638
43d3f4fc
DS
11639DEFUN (show_bgp_l2vpn_evpn_updgrps,
11640 show_bgp_l2vpn_evpn_updgrps_cmd,
11641 "show [ip] bgp l2vpn evpn update-groups",
11642 SHOW_STR
11643 IP_STR
11644 BGP_STR
11645 "l2vpn address family\n"
11646 "evpn sub-address family\n"
11647 "Detailed info about dynamic update groups\n")
11648{
11649 char *vrf = NULL;
11650 uint64_t subgrp_id = 0;
11651
11652 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11653 return CMD_SUCCESS;
11654}
11655
5bf15956
DW
11656DEFUN (show_bgp_updgrps_stats,
11657 show_bgp_updgrps_stats_cmd,
716b2d8a 11658 "show [ip] bgp update-groups statistics",
3f9c7369 11659 SHOW_STR
716b2d8a 11660 IP_STR
3f9c7369 11661 BGP_STR
0c7b1b01 11662 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11663 "Statistics\n")
11664{
d62a17ae 11665 struct bgp *bgp;
3f9c7369 11666
d62a17ae 11667 bgp = bgp_get_default();
11668 if (bgp)
11669 update_group_show_stats(bgp, vty);
3f9c7369 11670
d62a17ae 11671 return CMD_SUCCESS;
3f9c7369
DS
11672}
11673
8386ac43 11674DEFUN (show_bgp_instance_updgrps_stats,
11675 show_bgp_instance_updgrps_stats_cmd,
18c57037 11676 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11677 SHOW_STR
716b2d8a 11678 IP_STR
8386ac43 11679 BGP_STR
11680 BGP_INSTANCE_HELP_STR
0c7b1b01 11681 "Detailed info about dynamic update groups\n"
8386ac43 11682 "Statistics\n")
11683{
d62a17ae 11684 int idx_word = 3;
11685 struct bgp *bgp;
8386ac43 11686
d62a17ae 11687 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11688 if (bgp)
11689 update_group_show_stats(bgp, vty);
8386ac43 11690
d62a17ae 11691 return CMD_SUCCESS;
8386ac43 11692}
11693
d62a17ae 11694static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11695 afi_t afi, safi_t safi,
11696 const char *what, uint64_t subgrp_id)
3f9c7369 11697{
d62a17ae 11698 struct bgp *bgp;
8386ac43 11699
d62a17ae 11700 if (name)
11701 bgp = bgp_lookup_by_name(name);
11702 else
11703 bgp = bgp_get_default();
8386ac43 11704
d62a17ae 11705 if (bgp) {
11706 if (!strcmp(what, "advertise-queue"))
11707 update_group_show_adj_queue(bgp, afi, safi, vty,
11708 subgrp_id);
11709 else if (!strcmp(what, "advertised-routes"))
11710 update_group_show_advertised(bgp, afi, safi, vty,
11711 subgrp_id);
11712 else if (!strcmp(what, "packet-queue"))
11713 update_group_show_packet_queue(bgp, afi, safi, vty,
11714 subgrp_id);
11715 }
3f9c7369
DS
11716}
11717
dc64bdec
QY
11718DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11719 show_ip_bgp_instance_updgrps_adj_s_cmd,
11720 "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",
11721 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11722 BGP_SAFI_HELP_STR
11723 "Detailed info about dynamic update groups\n"
11724 "Specific subgroup to display info for\n"
11725 "Advertisement queue\n"
11726 "Announced routes\n"
11727 "Packet queue\n")
3f9c7369 11728{
dc64bdec
QY
11729 uint64_t subgrp_id = 0;
11730 afi_t afiz;
11731 safi_t safiz;
11732 if (sgid)
11733 subgrp_id = strtoull(sgid, NULL, 10);
11734
11735 if (!ip && !afi)
11736 afiz = AFI_IP6;
11737 if (!ip && afi)
11738 afiz = bgp_vty_afi_from_str(afi);
11739 if (ip && !afi)
11740 afiz = AFI_IP;
11741 if (ip && afi) {
11742 afiz = bgp_vty_afi_from_str(afi);
11743 if (afiz != AFI_IP)
11744 vty_out(vty,
11745 "%% Cannot specify both 'ip' and 'ipv6'\n");
11746 return CMD_WARNING;
11747 }
d62a17ae 11748
dc64bdec 11749 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11750
dc64bdec 11751 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11752 return CMD_SUCCESS;
11753}
11754
d62a17ae 11755static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11756{
11757 struct listnode *node, *nnode;
11758 struct prefix *range;
11759 struct peer *conf;
11760 struct peer *peer;
11761 char buf[PREFIX2STR_BUFFER];
11762 afi_t afi;
11763 safi_t safi;
11764 const char *peer_status;
11765 const char *af_str;
11766 int lr_count;
11767 int dynamic;
11768 int af_cfgd;
11769
11770 conf = group->conf;
11771
11772 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
11773 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11774 group->name, conf->as);
d62a17ae 11775 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
11776 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11777 group->name, group->bgp->as);
d62a17ae 11778 } else {
11779 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11780 }
f14e6fdb 11781
d62a17ae 11782 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11783 vty_out(vty, " Peer-group type is internal\n");
11784 else
11785 vty_out(vty, " Peer-group type is external\n");
11786
11787 /* Display AFs configured. */
11788 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11789 FOREACH_AFI_SAFI (afi, safi) {
11790 if (conf->afc[afi][safi]) {
11791 af_cfgd = 1;
11792 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 11793 }
05c7a1cc 11794 }
d62a17ae 11795 if (!af_cfgd)
11796 vty_out(vty, " none\n");
11797 else
11798 vty_out(vty, "\n");
11799
11800 /* Display listen ranges (for dynamic neighbors), if any */
11801 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11802 if (afi == AFI_IP)
11803 af_str = "IPv4";
11804 else if (afi == AFI_IP6)
11805 af_str = "IPv6";
11806 else
11807 af_str = "???";
11808 lr_count = listcount(group->listen_range[afi]);
11809 if (lr_count) {
11810 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11811 af_str);
11812
11813
11814 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11815 nnode, range)) {
11816 prefix2str(range, buf, sizeof(buf));
11817 vty_out(vty, " %s\n", buf);
11818 }
11819 }
11820 }
f14e6fdb 11821
d62a17ae 11822 /* Display group members and their status */
11823 if (listcount(group->peer)) {
11824 vty_out(vty, " Peer-group members:\n");
11825 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11826 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11827 peer_status = "Idle (Admin)";
11828 else if (CHECK_FLAG(peer->sflags,
11829 PEER_STATUS_PREFIX_OVERFLOW))
11830 peer_status = "Idle (PfxCt)";
11831 else
11832 peer_status = lookup_msg(bgp_status_msg,
11833 peer->status, NULL);
11834
11835 dynamic = peer_dynamic_neighbor(peer);
11836 vty_out(vty, " %s %s %s \n", peer->host,
11837 dynamic ? "(dynamic)" : "", peer_status);
11838 }
11839 }
f14e6fdb 11840
d62a17ae 11841 return CMD_SUCCESS;
11842}
11843
ff9959b0
QY
11844static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11845 const char *group_name)
d62a17ae 11846{
ff9959b0 11847 struct bgp *bgp;
d62a17ae 11848 struct listnode *node, *nnode;
11849 struct peer_group *group;
ff9959b0
QY
11850 bool found = false;
11851
11852 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11853
11854 if (!bgp) {
9f049418 11855 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
11856 return CMD_WARNING;
11857 }
d62a17ae 11858
11859 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
11860 if (group_name) {
11861 if (strmatch(group->name, group_name)) {
d62a17ae 11862 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
11863 found = true;
11864 break;
d62a17ae 11865 }
ff9959b0
QY
11866 } else {
11867 bgp_show_one_peer_group(vty, group);
d62a17ae 11868 }
f14e6fdb 11869 }
f14e6fdb 11870
ff9959b0 11871 if (group_name && !found)
d62a17ae 11872 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 11873
d62a17ae 11874 return CMD_SUCCESS;
f14e6fdb
DS
11875}
11876
f14e6fdb
DS
11877DEFUN (show_ip_bgp_peer_groups,
11878 show_ip_bgp_peer_groups_cmd,
18c57037 11879 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
11880 SHOW_STR
11881 IP_STR
11882 BGP_STR
8386ac43 11883 BGP_INSTANCE_HELP_STR
d6e3c605
QY
11884 "Detailed information on BGP peer groups\n"
11885 "Peer group name\n")
f14e6fdb 11886{
d62a17ae 11887 char *vrf, *pg;
d62a17ae 11888 int idx = 0;
f14e6fdb 11889
a4d82a8a
PZ
11890 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11891 : NULL;
d62a17ae 11892 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 11893
ff9959b0 11894 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11895}
3f9c7369 11896
d6e3c605 11897
718e3744 11898/* Redistribute VTY commands. */
11899
718e3744 11900DEFUN (bgp_redistribute_ipv4,
11901 bgp_redistribute_ipv4_cmd,
40d1cbfb 11902 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11903 "Redistribute information from another routing protocol\n"
ab0181ee 11904 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11905{
d62a17ae 11906 VTY_DECLVAR_CONTEXT(bgp, bgp);
11907 int idx_protocol = 1;
11908 int type;
718e3744 11909
d62a17ae 11910 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11911 if (type < 0) {
11912 vty_out(vty, "%% Invalid route type\n");
11913 return CMD_WARNING_CONFIG_FAILED;
11914 }
7f323236 11915
d62a17ae 11916 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11917 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 11918}
11919
d62a17ae 11920ALIAS_HIDDEN(
11921 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11922 "redistribute " FRR_IP_REDIST_STR_BGPD,
11923 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11924
718e3744 11925DEFUN (bgp_redistribute_ipv4_rmap,
11926 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11927 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11928 "Redistribute information from another routing protocol\n"
ab0181ee 11929 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11930 "Route map reference\n"
11931 "Pointer to route-map entries\n")
11932{
d62a17ae 11933 VTY_DECLVAR_CONTEXT(bgp, bgp);
11934 int idx_protocol = 1;
11935 int idx_word = 3;
11936 int type;
11937 struct bgp_redist *red;
e923dd62 11938 bool changed;
1de27621
DA
11939 struct route_map *route_map = route_map_lookup_warn_noexist(
11940 vty, argv[idx_word]->arg);
718e3744 11941
d62a17ae 11942 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11943 if (type < 0) {
11944 vty_out(vty, "%% Invalid route type\n");
11945 return CMD_WARNING_CONFIG_FAILED;
11946 }
718e3744 11947
d62a17ae 11948 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
11949 changed =
11950 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 11951 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 11952}
11953
d62a17ae 11954ALIAS_HIDDEN(
11955 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11956 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11957 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11958 "Route map reference\n"
11959 "Pointer to route-map entries\n")
596c17ba 11960
718e3744 11961DEFUN (bgp_redistribute_ipv4_metric,
11962 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11963 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11964 "Redistribute information from another routing protocol\n"
ab0181ee 11965 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11966 "Metric for redistributed routes\n"
11967 "Default metric\n")
11968{
d62a17ae 11969 VTY_DECLVAR_CONTEXT(bgp, bgp);
11970 int idx_protocol = 1;
11971 int idx_number = 3;
11972 int type;
d7c0a89a 11973 uint32_t metric;
d62a17ae 11974 struct bgp_redist *red;
e923dd62 11975 bool changed;
d62a17ae 11976
11977 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11978 if (type < 0) {
11979 vty_out(vty, "%% Invalid route type\n");
11980 return CMD_WARNING_CONFIG_FAILED;
11981 }
11982 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11983
11984 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 11985 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11986 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 11987}
11988
11989ALIAS_HIDDEN(
11990 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11991 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11992 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11993 "Metric for redistributed routes\n"
11994 "Default metric\n")
596c17ba 11995
718e3744 11996DEFUN (bgp_redistribute_ipv4_rmap_metric,
11997 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11998 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11999 "Redistribute information from another routing protocol\n"
ab0181ee 12000 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12001 "Route map reference\n"
12002 "Pointer to route-map entries\n"
12003 "Metric for redistributed routes\n"
12004 "Default metric\n")
12005{
d62a17ae 12006 VTY_DECLVAR_CONTEXT(bgp, bgp);
12007 int idx_protocol = 1;
12008 int idx_word = 3;
12009 int idx_number = 5;
12010 int type;
d7c0a89a 12011 uint32_t metric;
d62a17ae 12012 struct bgp_redist *red;
e923dd62 12013 bool changed;
1de27621
DA
12014 struct route_map *route_map =
12015 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12016
12017 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12018 if (type < 0) {
12019 vty_out(vty, "%% Invalid route type\n");
12020 return CMD_WARNING_CONFIG_FAILED;
12021 }
12022 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12023
12024 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12025 changed =
12026 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12027 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12028 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12029}
12030
12031ALIAS_HIDDEN(
12032 bgp_redistribute_ipv4_rmap_metric,
12033 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12034 "redistribute " FRR_IP_REDIST_STR_BGPD
12035 " route-map WORD metric (0-4294967295)",
12036 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12037 "Route map reference\n"
12038 "Pointer to route-map entries\n"
12039 "Metric for redistributed routes\n"
12040 "Default metric\n")
596c17ba 12041
718e3744 12042DEFUN (bgp_redistribute_ipv4_metric_rmap,
12043 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12044 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12045 "Redistribute information from another routing protocol\n"
ab0181ee 12046 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12047 "Metric for redistributed routes\n"
12048 "Default metric\n"
12049 "Route map reference\n"
12050 "Pointer to route-map entries\n")
12051{
d62a17ae 12052 VTY_DECLVAR_CONTEXT(bgp, bgp);
12053 int idx_protocol = 1;
12054 int idx_number = 3;
12055 int idx_word = 5;
12056 int type;
d7c0a89a 12057 uint32_t metric;
d62a17ae 12058 struct bgp_redist *red;
e923dd62 12059 bool changed;
1de27621
DA
12060 struct route_map *route_map =
12061 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12062
12063 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12064 if (type < 0) {
12065 vty_out(vty, "%% Invalid route type\n");
12066 return CMD_WARNING_CONFIG_FAILED;
12067 }
12068 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12069
12070 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12071 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12072 changed |=
12073 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12074 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12075}
12076
12077ALIAS_HIDDEN(
12078 bgp_redistribute_ipv4_metric_rmap,
12079 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12080 "redistribute " FRR_IP_REDIST_STR_BGPD
12081 " metric (0-4294967295) route-map WORD",
12082 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12083 "Metric for redistributed routes\n"
12084 "Default metric\n"
12085 "Route map reference\n"
12086 "Pointer to route-map entries\n")
596c17ba 12087
7c8ff89e
DS
12088DEFUN (bgp_redistribute_ipv4_ospf,
12089 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12090 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12091 "Redistribute information from another routing protocol\n"
12092 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12093 "Non-main Kernel Routing Table\n"
12094 "Instance ID/Table ID\n")
7c8ff89e 12095{
d62a17ae 12096 VTY_DECLVAR_CONTEXT(bgp, bgp);
12097 int idx_ospf_table = 1;
12098 int idx_number = 2;
d7c0a89a
QY
12099 unsigned short instance;
12100 unsigned short protocol;
7c8ff89e 12101
d62a17ae 12102 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12103
d62a17ae 12104 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12105 protocol = ZEBRA_ROUTE_OSPF;
12106 else
12107 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12108
d62a17ae 12109 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12110 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12111}
12112
d62a17ae 12113ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12114 "redistribute <ospf|table> (1-65535)",
12115 "Redistribute information from another routing protocol\n"
12116 "Open Shortest Path First (OSPFv2)\n"
12117 "Non-main Kernel Routing Table\n"
12118 "Instance ID/Table ID\n")
596c17ba 12119
7c8ff89e
DS
12120DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12121 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12122 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12123 "Redistribute information from another routing protocol\n"
12124 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12125 "Non-main Kernel Routing Table\n"
12126 "Instance ID/Table ID\n"
7c8ff89e
DS
12127 "Route map reference\n"
12128 "Pointer to route-map entries\n")
12129{
d62a17ae 12130 VTY_DECLVAR_CONTEXT(bgp, bgp);
12131 int idx_ospf_table = 1;
12132 int idx_number = 2;
12133 int idx_word = 4;
12134 struct bgp_redist *red;
d7c0a89a 12135 unsigned short instance;
d62a17ae 12136 int protocol;
e923dd62 12137 bool changed;
1de27621
DA
12138 struct route_map *route_map =
12139 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12140
12141 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12142 protocol = ZEBRA_ROUTE_OSPF;
12143 else
12144 protocol = ZEBRA_ROUTE_TABLE;
12145
12146 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12147 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12148 changed =
12149 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12150 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12151}
12152
12153ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12154 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12155 "redistribute <ospf|table> (1-65535) route-map WORD",
12156 "Redistribute information from another routing protocol\n"
12157 "Open Shortest Path First (OSPFv2)\n"
12158 "Non-main Kernel Routing Table\n"
12159 "Instance ID/Table ID\n"
12160 "Route map reference\n"
12161 "Pointer to route-map entries\n")
596c17ba 12162
7c8ff89e
DS
12163DEFUN (bgp_redistribute_ipv4_ospf_metric,
12164 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12165 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12166 "Redistribute information from another routing protocol\n"
12167 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12168 "Non-main Kernel Routing Table\n"
12169 "Instance ID/Table ID\n"
7c8ff89e
DS
12170 "Metric for redistributed routes\n"
12171 "Default metric\n")
12172{
d62a17ae 12173 VTY_DECLVAR_CONTEXT(bgp, bgp);
12174 int idx_ospf_table = 1;
12175 int idx_number = 2;
12176 int idx_number_2 = 4;
d7c0a89a 12177 uint32_t metric;
d62a17ae 12178 struct bgp_redist *red;
d7c0a89a 12179 unsigned short instance;
d62a17ae 12180 int protocol;
e923dd62 12181 bool changed;
d62a17ae 12182
12183 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12184 protocol = ZEBRA_ROUTE_OSPF;
12185 else
12186 protocol = ZEBRA_ROUTE_TABLE;
12187
12188 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12189 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12190
12191 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12192 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12193 metric);
12194 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12195}
12196
12197ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12198 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12199 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12200 "Redistribute information from another routing protocol\n"
12201 "Open Shortest Path First (OSPFv2)\n"
12202 "Non-main Kernel Routing Table\n"
12203 "Instance ID/Table ID\n"
12204 "Metric for redistributed routes\n"
12205 "Default metric\n")
596c17ba 12206
7c8ff89e
DS
12207DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12208 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12209 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12210 "Redistribute information from another routing protocol\n"
12211 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12212 "Non-main Kernel Routing Table\n"
12213 "Instance ID/Table ID\n"
7c8ff89e
DS
12214 "Route map reference\n"
12215 "Pointer to route-map entries\n"
12216 "Metric for redistributed routes\n"
12217 "Default metric\n")
12218{
d62a17ae 12219 VTY_DECLVAR_CONTEXT(bgp, bgp);
12220 int idx_ospf_table = 1;
12221 int idx_number = 2;
12222 int idx_word = 4;
12223 int idx_number_2 = 6;
d7c0a89a 12224 uint32_t metric;
d62a17ae 12225 struct bgp_redist *red;
d7c0a89a 12226 unsigned short instance;
d62a17ae 12227 int protocol;
e923dd62 12228 bool changed;
1de27621
DA
12229 struct route_map *route_map =
12230 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12231
12232 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12233 protocol = ZEBRA_ROUTE_OSPF;
12234 else
12235 protocol = ZEBRA_ROUTE_TABLE;
12236
12237 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12238 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12239
12240 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12241 changed =
12242 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12243 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12244 metric);
12245 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12246}
12247
12248ALIAS_HIDDEN(
12249 bgp_redistribute_ipv4_ospf_rmap_metric,
12250 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12251 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12252 "Redistribute information from another routing protocol\n"
12253 "Open Shortest Path First (OSPFv2)\n"
12254 "Non-main Kernel Routing Table\n"
12255 "Instance ID/Table ID\n"
12256 "Route map reference\n"
12257 "Pointer to route-map entries\n"
12258 "Metric for redistributed routes\n"
12259 "Default metric\n")
596c17ba 12260
7c8ff89e
DS
12261DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12262 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12263 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12264 "Redistribute information from another routing protocol\n"
12265 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12266 "Non-main Kernel Routing Table\n"
12267 "Instance ID/Table ID\n"
7c8ff89e
DS
12268 "Metric for redistributed routes\n"
12269 "Default metric\n"
12270 "Route map reference\n"
12271 "Pointer to route-map entries\n")
12272{
d62a17ae 12273 VTY_DECLVAR_CONTEXT(bgp, bgp);
12274 int idx_ospf_table = 1;
12275 int idx_number = 2;
12276 int idx_number_2 = 4;
12277 int idx_word = 6;
d7c0a89a 12278 uint32_t metric;
d62a17ae 12279 struct bgp_redist *red;
d7c0a89a 12280 unsigned short instance;
d62a17ae 12281 int protocol;
e923dd62 12282 bool changed;
1de27621
DA
12283 struct route_map *route_map =
12284 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12285
12286 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12287 protocol = ZEBRA_ROUTE_OSPF;
12288 else
12289 protocol = ZEBRA_ROUTE_TABLE;
12290
12291 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12292 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12293
12294 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12295 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12296 metric);
1de27621
DA
12297 changed |=
12298 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12299 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12300}
12301
12302ALIAS_HIDDEN(
12303 bgp_redistribute_ipv4_ospf_metric_rmap,
12304 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12305 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12306 "Redistribute information from another routing protocol\n"
12307 "Open Shortest Path First (OSPFv2)\n"
12308 "Non-main Kernel Routing Table\n"
12309 "Instance ID/Table ID\n"
12310 "Metric for redistributed routes\n"
12311 "Default metric\n"
12312 "Route map reference\n"
12313 "Pointer to route-map entries\n")
596c17ba 12314
7c8ff89e
DS
12315DEFUN (no_bgp_redistribute_ipv4_ospf,
12316 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 12317 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
12318 NO_STR
12319 "Redistribute information from another routing protocol\n"
12320 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12321 "Non-main Kernel Routing Table\n"
31500417
DW
12322 "Instance ID/Table ID\n"
12323 "Metric for redistributed routes\n"
12324 "Default metric\n"
12325 "Route map reference\n"
12326 "Pointer to route-map entries\n")
7c8ff89e 12327{
d62a17ae 12328 VTY_DECLVAR_CONTEXT(bgp, bgp);
12329 int idx_ospf_table = 2;
12330 int idx_number = 3;
d7c0a89a 12331 unsigned short instance;
d62a17ae 12332 int protocol;
12333
12334 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12335 protocol = ZEBRA_ROUTE_OSPF;
12336 else
12337 protocol = ZEBRA_ROUTE_TABLE;
12338
12339 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12340 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12341}
12342
12343ALIAS_HIDDEN(
12344 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 12345 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12346 NO_STR
12347 "Redistribute information from another routing protocol\n"
12348 "Open Shortest Path First (OSPFv2)\n"
12349 "Non-main Kernel Routing Table\n"
12350 "Instance ID/Table ID\n"
12351 "Metric for redistributed routes\n"
12352 "Default metric\n"
12353 "Route map reference\n"
12354 "Pointer to route-map entries\n")
596c17ba 12355
718e3744 12356DEFUN (no_bgp_redistribute_ipv4,
12357 no_bgp_redistribute_ipv4_cmd,
e27957c0 12358 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12359 NO_STR
12360 "Redistribute information from another routing protocol\n"
3b14d86e 12361 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12362 "Metric for redistributed routes\n"
12363 "Default metric\n"
12364 "Route map reference\n"
12365 "Pointer to route-map entries\n")
718e3744 12366{
d62a17ae 12367 VTY_DECLVAR_CONTEXT(bgp, bgp);
12368 int idx_protocol = 2;
12369 int type;
12370
12371 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12372 if (type < 0) {
12373 vty_out(vty, "%% Invalid route type\n");
12374 return CMD_WARNING_CONFIG_FAILED;
12375 }
12376 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12377}
12378
12379ALIAS_HIDDEN(
12380 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12381 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 12382 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12383 NO_STR
12384 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12385 "Metric for redistributed routes\n"
12386 "Default metric\n"
12387 "Route map reference\n"
12388 "Pointer to route-map entries\n")
596c17ba 12389
718e3744 12390DEFUN (bgp_redistribute_ipv6,
12391 bgp_redistribute_ipv6_cmd,
40d1cbfb 12392 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12393 "Redistribute information from another routing protocol\n"
ab0181ee 12394 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12395{
d62a17ae 12396 VTY_DECLVAR_CONTEXT(bgp, bgp);
12397 int idx_protocol = 1;
12398 int type;
718e3744 12399
d62a17ae 12400 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12401 if (type < 0) {
12402 vty_out(vty, "%% Invalid route type\n");
12403 return CMD_WARNING_CONFIG_FAILED;
12404 }
718e3744 12405
d62a17ae 12406 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12407 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12408}
12409
12410DEFUN (bgp_redistribute_ipv6_rmap,
12411 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12412 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12413 "Redistribute information from another routing protocol\n"
ab0181ee 12414 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12415 "Route map reference\n"
12416 "Pointer to route-map entries\n")
12417{
d62a17ae 12418 VTY_DECLVAR_CONTEXT(bgp, bgp);
12419 int idx_protocol = 1;
12420 int idx_word = 3;
12421 int type;
12422 struct bgp_redist *red;
e923dd62 12423 bool changed;
1de27621
DA
12424 struct route_map *route_map =
12425 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12426
d62a17ae 12427 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12428 if (type < 0) {
12429 vty_out(vty, "%% Invalid route type\n");
12430 return CMD_WARNING_CONFIG_FAILED;
12431 }
718e3744 12432
d62a17ae 12433 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12434 changed =
12435 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12436 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12437}
12438
12439DEFUN (bgp_redistribute_ipv6_metric,
12440 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12441 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12442 "Redistribute information from another routing protocol\n"
ab0181ee 12443 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12444 "Metric for redistributed routes\n"
12445 "Default metric\n")
12446{
d62a17ae 12447 VTY_DECLVAR_CONTEXT(bgp, bgp);
12448 int idx_protocol = 1;
12449 int idx_number = 3;
12450 int type;
d7c0a89a 12451 uint32_t metric;
d62a17ae 12452 struct bgp_redist *red;
e923dd62 12453 bool changed;
d62a17ae 12454
12455 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12456 if (type < 0) {
12457 vty_out(vty, "%% Invalid route type\n");
12458 return CMD_WARNING_CONFIG_FAILED;
12459 }
12460 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12461
d62a17ae 12462 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12463 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12464 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12465}
12466
12467DEFUN (bgp_redistribute_ipv6_rmap_metric,
12468 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12469 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12470 "Redistribute information from another routing protocol\n"
ab0181ee 12471 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12472 "Route map reference\n"
12473 "Pointer to route-map entries\n"
12474 "Metric for redistributed routes\n"
12475 "Default metric\n")
12476{
d62a17ae 12477 VTY_DECLVAR_CONTEXT(bgp, bgp);
12478 int idx_protocol = 1;
12479 int idx_word = 3;
12480 int idx_number = 5;
12481 int type;
d7c0a89a 12482 uint32_t metric;
d62a17ae 12483 struct bgp_redist *red;
e923dd62 12484 bool changed;
1de27621
DA
12485 struct route_map *route_map =
12486 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12487
12488 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12489 if (type < 0) {
12490 vty_out(vty, "%% Invalid route type\n");
12491 return CMD_WARNING_CONFIG_FAILED;
12492 }
12493 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12494
d62a17ae 12495 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12496 changed =
12497 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12498 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12499 metric);
12500 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12501}
12502
12503DEFUN (bgp_redistribute_ipv6_metric_rmap,
12504 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12505 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12506 "Redistribute information from another routing protocol\n"
ab0181ee 12507 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12508 "Metric for redistributed routes\n"
12509 "Default metric\n"
12510 "Route map reference\n"
12511 "Pointer to route-map entries\n")
12512{
d62a17ae 12513 VTY_DECLVAR_CONTEXT(bgp, bgp);
12514 int idx_protocol = 1;
12515 int idx_number = 3;
12516 int idx_word = 5;
12517 int type;
d7c0a89a 12518 uint32_t metric;
d62a17ae 12519 struct bgp_redist *red;
e923dd62 12520 bool changed;
1de27621
DA
12521 struct route_map *route_map =
12522 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12523
12524 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12525 if (type < 0) {
12526 vty_out(vty, "%% Invalid route type\n");
12527 return CMD_WARNING_CONFIG_FAILED;
12528 }
12529 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12530
d62a17ae 12531 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12532 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12533 metric);
1de27621
DA
12534 changed |=
12535 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12536 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12537}
12538
12539DEFUN (no_bgp_redistribute_ipv6,
12540 no_bgp_redistribute_ipv6_cmd,
e27957c0 12541 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12542 NO_STR
12543 "Redistribute information from another routing protocol\n"
3b14d86e 12544 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12545 "Metric for redistributed routes\n"
12546 "Default metric\n"
12547 "Route map reference\n"
12548 "Pointer to route-map entries\n")
718e3744 12549{
d62a17ae 12550 VTY_DECLVAR_CONTEXT(bgp, bgp);
12551 int idx_protocol = 2;
12552 int type;
718e3744 12553
d62a17ae 12554 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12555 if (type < 0) {
12556 vty_out(vty, "%% Invalid route type\n");
12557 return CMD_WARNING_CONFIG_FAILED;
12558 }
718e3744 12559
d62a17ae 12560 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12561}
12562
2b791107 12563void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12564 safi_t safi)
d62a17ae 12565{
12566 int i;
12567
12568 /* Unicast redistribution only. */
12569 if (safi != SAFI_UNICAST)
2b791107 12570 return;
d62a17ae 12571
12572 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12573 /* Redistribute BGP does not make sense. */
12574 if (i != ZEBRA_ROUTE_BGP) {
12575 struct list *red_list;
12576 struct listnode *node;
12577 struct bgp_redist *red;
12578
12579 red_list = bgp->redist[afi][i];
12580 if (!red_list)
12581 continue;
12582
12583 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12584 /* "redistribute" configuration. */
12585 vty_out(vty, " redistribute %s",
12586 zebra_route_string(i));
12587 if (red->instance)
12588 vty_out(vty, " %d", red->instance);
12589 if (red->redist_metric_flag)
12590 vty_out(vty, " metric %u",
12591 red->redist_metric);
12592 if (red->rmap.name)
12593 vty_out(vty, " route-map %s",
12594 red->rmap.name);
12595 vty_out(vty, "\n");
12596 }
12597 }
12598 }
718e3744 12599}
6b0655a2 12600
b9c7bc5a
PZ
12601/* This is part of the address-family block (unicast only) */
12602void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12603 afi_t afi)
12604{
b9c7bc5a 12605 int indent = 2;
ddb5b488 12606
8a066a70
PG
12607 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12608 if (listcount(bgp->vpn_policy[afi].import_vrf))
12609 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12610 bgp->vpn_policy[afi]
bb4f6190 12611 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12612 else
12613 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12614 bgp->vpn_policy[afi]
12615 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12616 }
12a844a5
DS
12617 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12618 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12619 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12620 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12621 return;
12622
e70e9f8e
PZ
12623 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12624 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12625
12626 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12627
12628 } else {
12629 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12630 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12631 bgp->vpn_policy[afi].tovpn_label);
12632 }
ddb5b488
PZ
12633 }
12634 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12635 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12636 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12637 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12638 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12639 sizeof(buf)));
12640 }
12641 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12642 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12643
12644 char buf[PREFIX_STRLEN];
12645 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12646 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12647 sizeof(buf))) {
12648
b9c7bc5a
PZ
12649 vty_out(vty, "%*snexthop vpn export %s\n",
12650 indent, "", buf);
ddb5b488
PZ
12651 }
12652 }
12653 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12654 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12655 && ecommunity_cmp(
12656 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12657 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12658
12659 char *b = ecommunity_ecom2str(
12660 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12661 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12662 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12663 XFREE(MTYPE_ECOMMUNITY_STR, b);
12664 } else {
12665 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12666 char *b = ecommunity_ecom2str(
12667 bgp->vpn_policy[afi]
12668 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12669 ECOMMUNITY_FORMAT_ROUTE_MAP,
12670 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12671 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12672 XFREE(MTYPE_ECOMMUNITY_STR, b);
12673 }
12674 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12675 char *b = ecommunity_ecom2str(
12676 bgp->vpn_policy[afi]
12677 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12678 ECOMMUNITY_FORMAT_ROUTE_MAP,
12679 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12680 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12681 XFREE(MTYPE_ECOMMUNITY_STR, b);
12682 }
12683 }
bb4f6190
DS
12684
12685 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12686 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12687 bgp->vpn_policy[afi]
12688 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12689
301ad80a
PG
12690 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12691 char *b = ecommunity_ecom2str(
12692 bgp->vpn_policy[afi]
12693 .import_redirect_rtlist,
12694 ECOMMUNITY_FORMAT_ROUTE_MAP,
12695 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12696
301ad80a
PG
12697 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12698 XFREE(MTYPE_ECOMMUNITY_STR, b);
12699 }
ddb5b488
PZ
12700}
12701
12702
718e3744 12703/* BGP node structure. */
d62a17ae 12704static struct cmd_node bgp_node = {
9d303b37 12705 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12706};
12707
d62a17ae 12708static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12709 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12710};
12711
d62a17ae 12712static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12713 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12714};
12715
d62a17ae 12716static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12717 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12718};
12719
d62a17ae 12720static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12721 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12722};
12723
d62a17ae 12724static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12725 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12726};
12727
d62a17ae 12728static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12729 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12730};
12731
d62a17ae 12732static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12733 "%s(config-router-af)# ", 1};
6b0655a2 12734
d62a17ae 12735static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12736 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12737
d62a17ae 12738static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12739 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12740
d62a17ae 12741static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12742 "%s(config-router-af-vni)# ", 1};
90e60aa7 12743
7c40bf39 12744static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12745 "%s(config-router-af)# ", 1};
12746
12747static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12748 "%s(config-router-af-vpnv6)# ", 1};
12749
d62a17ae 12750static void community_list_vty(void);
1f8ae70b 12751
d62a17ae 12752static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12753{
d62a17ae 12754 struct bgp *bgp;
12755 struct peer *peer;
d62a17ae 12756 struct listnode *lnbgp, *lnpeer;
b8a815e5 12757
d62a17ae 12758 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12759 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12760 /* only provide suggestions on the appropriate input
12761 * token type,
12762 * they'll otherwise show up multiple times */
12763 enum cmd_token_type match_type;
12764 char *name = peer->host;
d48ed3e0 12765
d62a17ae 12766 if (peer->conf_if) {
12767 match_type = VARIABLE_TKN;
12768 name = peer->conf_if;
12769 } else if (strchr(peer->host, ':'))
12770 match_type = IPV6_TKN;
12771 else
12772 match_type = IPV4_TKN;
d48ed3e0 12773
d62a17ae 12774 if (token->type != match_type)
12775 continue;
d48ed3e0 12776
d62a17ae 12777 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12778 }
d62a17ae 12779 }
b8a815e5
DL
12780}
12781
12782static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12783 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12784 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12785 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12786 {.completions = NULL}};
12787
47a306a0
DS
12788static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12789{
12790 struct bgp *bgp;
12791 struct peer_group *group;
12792 struct listnode *lnbgp, *lnpeer;
12793
12794 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12795 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12796 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12797 group->name));
12798 }
12799}
12800
12801static const struct cmd_variable_handler bgp_var_peergroup[] = {
12802 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12803 {.completions = NULL} };
12804
d62a17ae 12805void bgp_vty_init(void)
12806{
12807 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12808 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12809
12810 /* Install bgp top node. */
12811 install_node(&bgp_node, bgp_config_write);
12812 install_node(&bgp_ipv4_unicast_node, NULL);
12813 install_node(&bgp_ipv4_multicast_node, NULL);
12814 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12815 install_node(&bgp_ipv6_unicast_node, NULL);
12816 install_node(&bgp_ipv6_multicast_node, NULL);
12817 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12818 install_node(&bgp_vpnv4_node, NULL);
12819 install_node(&bgp_vpnv6_node, NULL);
12820 install_node(&bgp_evpn_node, NULL);
12821 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 12822 install_node(&bgp_flowspecv4_node, NULL);
12823 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 12824
12825 /* Install default VTY commands to new nodes. */
12826 install_default(BGP_NODE);
12827 install_default(BGP_IPV4_NODE);
12828 install_default(BGP_IPV4M_NODE);
12829 install_default(BGP_IPV4L_NODE);
12830 install_default(BGP_IPV6_NODE);
12831 install_default(BGP_IPV6M_NODE);
12832 install_default(BGP_IPV6L_NODE);
12833 install_default(BGP_VPNV4_NODE);
12834 install_default(BGP_VPNV6_NODE);
7c40bf39 12835 install_default(BGP_FLOWSPECV4_NODE);
12836 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 12837 install_default(BGP_EVPN_NODE);
12838 install_default(BGP_EVPN_VNI_NODE);
12839
8029b216
AK
12840 /* "bgp local-mac" hidden commands. */
12841 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12842 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12843
d62a17ae 12844 /* bgp route-map delay-timer commands. */
12845 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12846 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12847
12848 /* Dummy commands (Currently not supported) */
12849 install_element(BGP_NODE, &no_synchronization_cmd);
12850 install_element(BGP_NODE, &no_auto_summary_cmd);
12851
12852 /* "router bgp" commands. */
12853 install_element(CONFIG_NODE, &router_bgp_cmd);
12854
12855 /* "no router bgp" commands. */
12856 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12857
12858 /* "bgp router-id" commands. */
12859 install_element(BGP_NODE, &bgp_router_id_cmd);
12860 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12861
12862 /* "bgp cluster-id" commands. */
12863 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12864 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12865
12866 /* "bgp confederation" commands. */
12867 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12868 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12869
12870 /* "bgp confederation peers" commands. */
12871 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12872 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12873
12874 /* bgp max-med command */
12875 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12876 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12877 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12878 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12879 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12880
12881 /* bgp disable-ebgp-connected-nh-check */
12882 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12883 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12884
12885 /* bgp update-delay command */
12886 install_element(BGP_NODE, &bgp_update_delay_cmd);
12887 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12888 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12889
12890 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12891 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12892 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12893 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12894
12895 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12896 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12897
12898 /* "maximum-paths" commands. */
12899 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12900 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12901 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12902 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12903 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12904 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12905 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12906 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12907 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12908 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12909 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12910 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12911 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12912 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12913 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12914
12915 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12916 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12917 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12918 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12919 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12920
12921 /* "timers bgp" commands. */
12922 install_element(BGP_NODE, &bgp_timers_cmd);
12923 install_element(BGP_NODE, &no_bgp_timers_cmd);
12924
12925 /* route-map delay-timer commands - per instance for backwards compat.
12926 */
12927 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12928 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12929
12930 /* "bgp client-to-client reflection" commands */
12931 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12932 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12933
12934 /* "bgp always-compare-med" commands */
12935 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12936 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12937
9dac9fc8
DA
12938 /* bgp ebgp-requires-policy */
12939 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12940 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12941
d62a17ae 12942 /* "bgp deterministic-med" commands */
12943 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12944 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12945
12946 /* "bgp graceful-restart" commands */
12947 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12948 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12949 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12950 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12951 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12952 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12953
12954 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12955 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12956
7f323236
DW
12957 /* "bgp graceful-shutdown" commands */
12958 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12959 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12960
d62a17ae 12961 /* "bgp fast-external-failover" commands */
12962 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12963 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12964
d62a17ae 12965 /* "bgp bestpath compare-routerid" commands */
12966 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12967 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12968
12969 /* "bgp bestpath as-path ignore" commands */
12970 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12971 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12972
12973 /* "bgp bestpath as-path confed" commands */
12974 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12975 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12976
12977 /* "bgp bestpath as-path multipath-relax" commands */
12978 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12979 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12980
12981 /* "bgp log-neighbor-changes" commands */
12982 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12983 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12984
12985 /* "bgp bestpath med" commands */
12986 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12987 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12988
12989 /* "no bgp default ipv4-unicast" commands. */
12990 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12991 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12992
12993 /* "bgp network import-check" commands. */
12994 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12995 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12996 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12997
12998 /* "bgp default local-preference" commands. */
12999 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13000 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13001
13002 /* bgp default show-hostname */
13003 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13004 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13005
13006 /* "bgp default subgroup-pkt-queue-max" commands. */
13007 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13008 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13009
13010 /* bgp ibgp-allow-policy-mods command */
13011 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13012 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13013
13014 /* "bgp listen limit" commands. */
13015 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13016 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13017
13018 /* "bgp listen range" commands. */
13019 install_element(BGP_NODE, &bgp_listen_range_cmd);
13020 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13021
8175f54a 13022 /* "bgp default shutdown" command */
f26845f9
QY
13023 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13024
d62a17ae 13025 /* "neighbor remote-as" commands. */
13026 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13027 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13028 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13029 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13030 install_element(BGP_NODE,
13031 &neighbor_interface_v6only_config_remote_as_cmd);
13032 install_element(BGP_NODE, &no_neighbor_cmd);
13033 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13034
13035 /* "neighbor peer-group" commands. */
13036 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13037 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13038 install_element(BGP_NODE,
13039 &no_neighbor_interface_peer_group_remote_as_cmd);
13040
13041 /* "neighbor local-as" commands. */
13042 install_element(BGP_NODE, &neighbor_local_as_cmd);
13043 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13044 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13045 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13046
13047 /* "neighbor solo" commands. */
13048 install_element(BGP_NODE, &neighbor_solo_cmd);
13049 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13050
13051 /* "neighbor password" commands. */
13052 install_element(BGP_NODE, &neighbor_password_cmd);
13053 install_element(BGP_NODE, &no_neighbor_password_cmd);
13054
13055 /* "neighbor activate" commands. */
13056 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13057 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13058 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13059 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13060 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13061 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13062 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13063 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13064 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13065 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13066 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13067 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13068
13069 /* "no neighbor activate" commands. */
13070 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13071 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13072 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13073 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13074 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13075 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13076 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13077 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13078 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13079 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13080 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13081 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13082
13083 /* "neighbor peer-group" set commands. */
13084 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13085 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13086 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13087 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13088 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13089 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13090 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13091 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13092 install_element(BGP_FLOWSPECV4_NODE,
13093 &neighbor_set_peer_group_hidden_cmd);
13094 install_element(BGP_FLOWSPECV6_NODE,
13095 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13096
13097 /* "no neighbor peer-group unset" commands. */
13098 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13099 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13100 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13101 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13102 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13103 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13104 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13105 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13106 install_element(BGP_FLOWSPECV4_NODE,
13107 &no_neighbor_set_peer_group_hidden_cmd);
13108 install_element(BGP_FLOWSPECV6_NODE,
13109 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13110
13111 /* "neighbor softreconfiguration inbound" commands.*/
13112 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13113 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13114 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13115 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13116 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13117 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13118 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13119 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13120 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13121 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13122 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13123 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13124 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13125 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13126 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13127 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13128 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13129 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13130 install_element(BGP_FLOWSPECV4_NODE,
13131 &neighbor_soft_reconfiguration_cmd);
13132 install_element(BGP_FLOWSPECV4_NODE,
13133 &no_neighbor_soft_reconfiguration_cmd);
13134 install_element(BGP_FLOWSPECV6_NODE,
13135 &neighbor_soft_reconfiguration_cmd);
13136 install_element(BGP_FLOWSPECV6_NODE,
13137 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13138 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13139 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13140
13141 /* "neighbor attribute-unchanged" commands. */
13142 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13143 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13144 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13145 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13146 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13147 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13148 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13149 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13150 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13151 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13152 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13153 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13154 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13155 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13156 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13157 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13158 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13159 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13160
13161 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13162 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13163
13164 /* "nexthop-local unchanged" commands */
13165 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13166 install_element(BGP_IPV6_NODE,
13167 &no_neighbor_nexthop_local_unchanged_cmd);
13168
13169 /* "neighbor next-hop-self" commands. */
13170 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13171 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13172 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13173 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13174 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13175 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13176 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13177 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13178 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13179 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13180 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13181 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13182 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13183 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13184 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13185 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13186 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13187 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13188 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13189 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13190
13191 /* "neighbor next-hop-self force" commands. */
13192 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13193 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
13194 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13195 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13196 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13197 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13198 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13199 install_element(BGP_IPV4_NODE,
13200 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13201 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13202 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13203 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13204 install_element(BGP_IPV4M_NODE,
13205 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13206 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13207 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13208 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13209 install_element(BGP_IPV4L_NODE,
13210 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13211 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13212 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13213 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13214 install_element(BGP_IPV6_NODE,
13215 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13216 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13217 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13218 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13219 install_element(BGP_IPV6M_NODE,
13220 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13221 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13222 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13223 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13224 install_element(BGP_IPV6L_NODE,
13225 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13226 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13227 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13228 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13229 install_element(BGP_VPNV4_NODE,
13230 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13231 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13232 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13233 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13234 install_element(BGP_VPNV6_NODE,
13235 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13236
13237 /* "neighbor as-override" commands. */
13238 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13239 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13240 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13241 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13242 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13243 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13244 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13245 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13246 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13247 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13248 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13249 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13250 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13251 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13252 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13253 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13254 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13255 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13256
13257 /* "neighbor remove-private-AS" commands. */
13258 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13259 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13260 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13261 install_element(BGP_NODE,
13262 &no_neighbor_remove_private_as_all_hidden_cmd);
13263 install_element(BGP_NODE,
13264 &neighbor_remove_private_as_replace_as_hidden_cmd);
13265 install_element(BGP_NODE,
13266 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13267 install_element(BGP_NODE,
13268 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13269 install_element(
13270 BGP_NODE,
13271 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13272 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13273 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13274 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13275 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13276 install_element(BGP_IPV4_NODE,
13277 &neighbor_remove_private_as_replace_as_cmd);
13278 install_element(BGP_IPV4_NODE,
13279 &no_neighbor_remove_private_as_replace_as_cmd);
13280 install_element(BGP_IPV4_NODE,
13281 &neighbor_remove_private_as_all_replace_as_cmd);
13282 install_element(BGP_IPV4_NODE,
13283 &no_neighbor_remove_private_as_all_replace_as_cmd);
13284 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13285 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13286 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13287 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13288 install_element(BGP_IPV4M_NODE,
13289 &neighbor_remove_private_as_replace_as_cmd);
13290 install_element(BGP_IPV4M_NODE,
13291 &no_neighbor_remove_private_as_replace_as_cmd);
13292 install_element(BGP_IPV4M_NODE,
13293 &neighbor_remove_private_as_all_replace_as_cmd);
13294 install_element(BGP_IPV4M_NODE,
13295 &no_neighbor_remove_private_as_all_replace_as_cmd);
13296 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13297 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13298 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13299 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13300 install_element(BGP_IPV4L_NODE,
13301 &neighbor_remove_private_as_replace_as_cmd);
13302 install_element(BGP_IPV4L_NODE,
13303 &no_neighbor_remove_private_as_replace_as_cmd);
13304 install_element(BGP_IPV4L_NODE,
13305 &neighbor_remove_private_as_all_replace_as_cmd);
13306 install_element(BGP_IPV4L_NODE,
13307 &no_neighbor_remove_private_as_all_replace_as_cmd);
13308 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13309 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13310 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13311 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13312 install_element(BGP_IPV6_NODE,
13313 &neighbor_remove_private_as_replace_as_cmd);
13314 install_element(BGP_IPV6_NODE,
13315 &no_neighbor_remove_private_as_replace_as_cmd);
13316 install_element(BGP_IPV6_NODE,
13317 &neighbor_remove_private_as_all_replace_as_cmd);
13318 install_element(BGP_IPV6_NODE,
13319 &no_neighbor_remove_private_as_all_replace_as_cmd);
13320 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13321 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13322 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13323 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13324 install_element(BGP_IPV6M_NODE,
13325 &neighbor_remove_private_as_replace_as_cmd);
13326 install_element(BGP_IPV6M_NODE,
13327 &no_neighbor_remove_private_as_replace_as_cmd);
13328 install_element(BGP_IPV6M_NODE,
13329 &neighbor_remove_private_as_all_replace_as_cmd);
13330 install_element(BGP_IPV6M_NODE,
13331 &no_neighbor_remove_private_as_all_replace_as_cmd);
13332 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13333 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13334 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13335 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13336 install_element(BGP_IPV6L_NODE,
13337 &neighbor_remove_private_as_replace_as_cmd);
13338 install_element(BGP_IPV6L_NODE,
13339 &no_neighbor_remove_private_as_replace_as_cmd);
13340 install_element(BGP_IPV6L_NODE,
13341 &neighbor_remove_private_as_all_replace_as_cmd);
13342 install_element(BGP_IPV6L_NODE,
13343 &no_neighbor_remove_private_as_all_replace_as_cmd);
13344 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13345 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13346 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13347 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13348 install_element(BGP_VPNV4_NODE,
13349 &neighbor_remove_private_as_replace_as_cmd);
13350 install_element(BGP_VPNV4_NODE,
13351 &no_neighbor_remove_private_as_replace_as_cmd);
13352 install_element(BGP_VPNV4_NODE,
13353 &neighbor_remove_private_as_all_replace_as_cmd);
13354 install_element(BGP_VPNV4_NODE,
13355 &no_neighbor_remove_private_as_all_replace_as_cmd);
13356 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13357 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13358 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13359 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13360 install_element(BGP_VPNV6_NODE,
13361 &neighbor_remove_private_as_replace_as_cmd);
13362 install_element(BGP_VPNV6_NODE,
13363 &no_neighbor_remove_private_as_replace_as_cmd);
13364 install_element(BGP_VPNV6_NODE,
13365 &neighbor_remove_private_as_all_replace_as_cmd);
13366 install_element(BGP_VPNV6_NODE,
13367 &no_neighbor_remove_private_as_all_replace_as_cmd);
13368
13369 /* "neighbor send-community" commands.*/
13370 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13371 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13372 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13373 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13374 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13375 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13376 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13377 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13378 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13379 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13380 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13381 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13382 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13383 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13384 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13385 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13386 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13388 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13389 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13390 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13391 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13392 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13393 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13394 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13395 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13396 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13397 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13398 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13399 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13400 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13401 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13402 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13403 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13404 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13405 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13406
13407 /* "neighbor route-reflector" commands.*/
13408 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13409 install_element(BGP_NODE,
13410 &no_neighbor_route_reflector_client_hidden_cmd);
13411 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13412 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13413 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13414 install_element(BGP_IPV4M_NODE,
13415 &no_neighbor_route_reflector_client_cmd);
13416 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13417 install_element(BGP_IPV4L_NODE,
13418 &no_neighbor_route_reflector_client_cmd);
13419 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13420 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13421 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13422 install_element(BGP_IPV6M_NODE,
13423 &no_neighbor_route_reflector_client_cmd);
13424 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13425 install_element(BGP_IPV6L_NODE,
13426 &no_neighbor_route_reflector_client_cmd);
13427 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13428 install_element(BGP_VPNV4_NODE,
13429 &no_neighbor_route_reflector_client_cmd);
13430 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13431 install_element(BGP_VPNV6_NODE,
13432 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13433 install_element(BGP_FLOWSPECV4_NODE,
13434 &neighbor_route_reflector_client_cmd);
13435 install_element(BGP_FLOWSPECV4_NODE,
13436 &no_neighbor_route_reflector_client_cmd);
13437 install_element(BGP_FLOWSPECV6_NODE,
13438 &neighbor_route_reflector_client_cmd);
13439 install_element(BGP_FLOWSPECV6_NODE,
13440 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13441 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13442 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13443
13444 /* "neighbor route-server" commands.*/
13445 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13446 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13447 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13448 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13449 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13450 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13451 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13452 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13453 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13454 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13455 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13456 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13457 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13458 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13459 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13460 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13461 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13462 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13463 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13464 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13465 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13466 install_element(BGP_FLOWSPECV4_NODE,
13467 &no_neighbor_route_server_client_cmd);
13468 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13469 install_element(BGP_FLOWSPECV6_NODE,
13470 &no_neighbor_route_server_client_cmd);
d62a17ae 13471
13472 /* "neighbor addpath-tx-all-paths" commands.*/
13473 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13474 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13475 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13476 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13477 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13478 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13479 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13480 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13481 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13482 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13483 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13484 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13485 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13486 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13487 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13488 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13489 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13490 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13491
13492 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13493 install_element(BGP_NODE,
13494 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13495 install_element(BGP_NODE,
13496 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13497 install_element(BGP_IPV4_NODE,
13498 &neighbor_addpath_tx_bestpath_per_as_cmd);
13499 install_element(BGP_IPV4_NODE,
13500 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13501 install_element(BGP_IPV4M_NODE,
13502 &neighbor_addpath_tx_bestpath_per_as_cmd);
13503 install_element(BGP_IPV4M_NODE,
13504 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13505 install_element(BGP_IPV4L_NODE,
13506 &neighbor_addpath_tx_bestpath_per_as_cmd);
13507 install_element(BGP_IPV4L_NODE,
13508 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13509 install_element(BGP_IPV6_NODE,
13510 &neighbor_addpath_tx_bestpath_per_as_cmd);
13511 install_element(BGP_IPV6_NODE,
13512 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13513 install_element(BGP_IPV6M_NODE,
13514 &neighbor_addpath_tx_bestpath_per_as_cmd);
13515 install_element(BGP_IPV6M_NODE,
13516 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13517 install_element(BGP_IPV6L_NODE,
13518 &neighbor_addpath_tx_bestpath_per_as_cmd);
13519 install_element(BGP_IPV6L_NODE,
13520 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13521 install_element(BGP_VPNV4_NODE,
13522 &neighbor_addpath_tx_bestpath_per_as_cmd);
13523 install_element(BGP_VPNV4_NODE,
13524 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13525 install_element(BGP_VPNV6_NODE,
13526 &neighbor_addpath_tx_bestpath_per_as_cmd);
13527 install_element(BGP_VPNV6_NODE,
13528 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13529
13530 /* "neighbor passive" commands. */
13531 install_element(BGP_NODE, &neighbor_passive_cmd);
13532 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13533
13534
13535 /* "neighbor shutdown" commands. */
13536 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13537 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13538 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13539 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13540
13541 /* "neighbor capability extended-nexthop" commands.*/
13542 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13543 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13544
13545 /* "neighbor capability orf prefix-list" commands.*/
13546 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13547 install_element(BGP_NODE,
13548 &no_neighbor_capability_orf_prefix_hidden_cmd);
13549 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13550 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13551 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13552 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13553 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13554 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13555 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13556 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13557 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13558 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13559 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13560 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13561
13562 /* "neighbor capability dynamic" commands.*/
13563 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13564 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13565
13566 /* "neighbor dont-capability-negotiate" commands. */
13567 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13568 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13569
13570 /* "neighbor ebgp-multihop" commands. */
13571 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13572 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13573 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13574
13575 /* "neighbor disable-connected-check" commands. */
13576 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13577 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13578
47cbc09b
PM
13579 /* "neighbor enforce-first-as" commands. */
13580 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13581 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13582
d62a17ae 13583 /* "neighbor description" commands. */
13584 install_element(BGP_NODE, &neighbor_description_cmd);
13585 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13586 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13587
13588 /* "neighbor update-source" commands. "*/
13589 install_element(BGP_NODE, &neighbor_update_source_cmd);
13590 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13591
13592 /* "neighbor default-originate" commands. */
13593 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13594 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13595 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13596 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13597 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13598 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13599 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13600 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13601 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13602 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13603 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13604 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13605 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13606 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13607 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13608 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13609 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13610 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13611 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13612 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13613 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13614
13615 /* "neighbor port" commands. */
13616 install_element(BGP_NODE, &neighbor_port_cmd);
13617 install_element(BGP_NODE, &no_neighbor_port_cmd);
13618
13619 /* "neighbor weight" commands. */
13620 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13621 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13622
13623 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13624 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13625 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13626 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13627 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13628 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13629 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13630 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13631 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13632 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13633 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13634 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13635 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13636 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13637 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13638 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13639
13640 /* "neighbor override-capability" commands. */
13641 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13642 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13643
13644 /* "neighbor strict-capability-match" commands. */
13645 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13646 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13647
13648 /* "neighbor timers" commands. */
13649 install_element(BGP_NODE, &neighbor_timers_cmd);
13650 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13651
13652 /* "neighbor timers connect" commands. */
13653 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13654 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13655
13656 /* "neighbor advertisement-interval" commands. */
13657 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13658 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13659
13660 /* "neighbor interface" commands. */
13661 install_element(BGP_NODE, &neighbor_interface_cmd);
13662 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13663
13664 /* "neighbor distribute" commands. */
13665 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13666 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13667 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13668 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13669 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13670 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13671 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13672 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13673 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13674 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13675 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13676 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13677 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13678 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13679 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13680 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13681 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13682 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13683
13684 /* "neighbor prefix-list" commands. */
13685 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13686 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13687 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13688 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13689 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13690 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13691 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13692 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13693 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13694 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13695 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13696 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13697 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13698 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13699 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13700 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13701 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13702 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13703 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13704 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13705 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13706 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13707
13708 /* "neighbor filter-list" commands. */
13709 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13710 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13711 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13712 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13713 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13714 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13715 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13716 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13717 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13718 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13719 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13720 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13721 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13722 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13723 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13724 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13725 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13726 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13727 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13728 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13729 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13730 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13731
13732 /* "neighbor route-map" commands. */
13733 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13734 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13735 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13736 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13737 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13738 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13739 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13740 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13741 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13742 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13743 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13744 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13745 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13746 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13747 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13748 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13749 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13750 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13751 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13752 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13753 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13754 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13755 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13756 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13757
13758 /* "neighbor unsuppress-map" commands. */
13759 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13760 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13761 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13762 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13763 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13764 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13765 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13766 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13767 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13768 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13769 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13770 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13771 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13772 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13773 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13774 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13775 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13776 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13777
13778 /* "neighbor maximum-prefix" commands. */
13779 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13780 install_element(BGP_NODE,
13781 &neighbor_maximum_prefix_threshold_hidden_cmd);
13782 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13783 install_element(BGP_NODE,
13784 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13785 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13786 install_element(BGP_NODE,
13787 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13788 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13789 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13790 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13791 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13792 install_element(BGP_IPV4_NODE,
13793 &neighbor_maximum_prefix_threshold_warning_cmd);
13794 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13795 install_element(BGP_IPV4_NODE,
13796 &neighbor_maximum_prefix_threshold_restart_cmd);
13797 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13798 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13799 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13800 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13801 install_element(BGP_IPV4M_NODE,
13802 &neighbor_maximum_prefix_threshold_warning_cmd);
13803 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13804 install_element(BGP_IPV4M_NODE,
13805 &neighbor_maximum_prefix_threshold_restart_cmd);
13806 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13807 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13808 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13809 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13810 install_element(BGP_IPV4L_NODE,
13811 &neighbor_maximum_prefix_threshold_warning_cmd);
13812 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13813 install_element(BGP_IPV4L_NODE,
13814 &neighbor_maximum_prefix_threshold_restart_cmd);
13815 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13816 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13817 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13818 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13819 install_element(BGP_IPV6_NODE,
13820 &neighbor_maximum_prefix_threshold_warning_cmd);
13821 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13822 install_element(BGP_IPV6_NODE,
13823 &neighbor_maximum_prefix_threshold_restart_cmd);
13824 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13825 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13826 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13827 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13828 install_element(BGP_IPV6M_NODE,
13829 &neighbor_maximum_prefix_threshold_warning_cmd);
13830 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13831 install_element(BGP_IPV6M_NODE,
13832 &neighbor_maximum_prefix_threshold_restart_cmd);
13833 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13834 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13835 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13836 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13837 install_element(BGP_IPV6L_NODE,
13838 &neighbor_maximum_prefix_threshold_warning_cmd);
13839 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13840 install_element(BGP_IPV6L_NODE,
13841 &neighbor_maximum_prefix_threshold_restart_cmd);
13842 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13843 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13844 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13845 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13846 install_element(BGP_VPNV4_NODE,
13847 &neighbor_maximum_prefix_threshold_warning_cmd);
13848 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13849 install_element(BGP_VPNV4_NODE,
13850 &neighbor_maximum_prefix_threshold_restart_cmd);
13851 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13852 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13853 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13854 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13855 install_element(BGP_VPNV6_NODE,
13856 &neighbor_maximum_prefix_threshold_warning_cmd);
13857 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13858 install_element(BGP_VPNV6_NODE,
13859 &neighbor_maximum_prefix_threshold_restart_cmd);
13860 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13861
13862 /* "neighbor allowas-in" */
13863 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13864 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13865 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13866 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13867 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13868 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13869 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13870 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13871 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13872 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13873 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13874 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13875 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13876 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13877 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13878 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13879 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13880 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13881 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13882 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13883
13884 /* address-family commands. */
13885 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13886 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 13887#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 13888 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13889 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 13890#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 13891
d62a17ae 13892 install_element(BGP_NODE, &address_family_evpn_cmd);
13893
13894 /* "exit-address-family" command. */
13895 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13896 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13897 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13898 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13899 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13900 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13901 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13902 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 13903 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13904 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 13905 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13906
13907 /* "clear ip bgp commands" */
13908 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13909
13910 /* clear ip bgp prefix */
13911 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13912 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13913 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13914
13915 /* "show [ip] bgp summary" commands. */
13916 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 13917 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 13918 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 13919 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 13920 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13921 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 13922 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13923
13924 /* "show [ip] bgp neighbors" commands. */
13925 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13926
13927 /* "show [ip] bgp peer-group" commands. */
13928 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13929
13930 /* "show [ip] bgp paths" commands. */
13931 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13932
13933 /* "show [ip] bgp community" commands. */
13934 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13935
13936 /* "show ip bgp large-community" commands. */
13937 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13938 /* "show [ip] bgp attribute-info" commands. */
13939 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 13940 /* "show [ip] bgp route-leak" command */
13941 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 13942
13943 /* "redistribute" commands. */
13944 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13945 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13946 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13947 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13948 install_element(BGP_NODE,
13949 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13950 install_element(BGP_NODE,
13951 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13952 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13953 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13954 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13955 install_element(BGP_NODE,
13956 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13957 install_element(BGP_NODE,
13958 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13959 install_element(BGP_NODE,
13960 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13961 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13962 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13963 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13964 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13965 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13966 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13967 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13968 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13969 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13970 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13971 install_element(BGP_IPV4_NODE,
13972 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13973 install_element(BGP_IPV4_NODE,
13974 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13975 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13976 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13977 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13978 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13979 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13980 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13981
b9c7bc5a
PZ
13982 /* import|export vpn [route-map WORD] */
13983 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13984 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 13985
12a844a5
DS
13986 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13987 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13988
d62a17ae 13989 /* ttl_security commands */
13990 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13991 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13992
13993 /* "show [ip] bgp memory" commands. */
13994 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13995
acf71666
MK
13996 /* "show bgp martian next-hop" */
13997 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13998
48ecf8f5
DS
13999 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14000
d62a17ae 14001 /* "show [ip] bgp views" commands. */
14002 install_element(VIEW_NODE, &show_bgp_views_cmd);
14003
14004 /* "show [ip] bgp vrfs" commands. */
14005 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14006
14007 /* Community-list. */
14008 community_list_vty();
ddb5b488
PZ
14009
14010 /* vpn-policy commands */
b9c7bc5a
PZ
14011 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14012 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14013 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14014 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14015 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14016 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14017 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14018 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14019 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14020 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14021 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14022 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14023
301ad80a
PG
14024 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14025 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14026
b9c7bc5a
PZ
14027 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14028 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14029 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14030 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14031 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14032 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14033 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14034 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14035 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14036 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14037 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14038 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14039}
6b0655a2 14040
718e3744 14041#include "memory.h"
14042#include "bgp_regex.h"
14043#include "bgp_clist.h"
14044#include "bgp_ecommunity.h"
14045
14046/* VTY functions. */
14047
14048/* Direction value to string conversion. */
d62a17ae 14049static const char *community_direct_str(int direct)
14050{
14051 switch (direct) {
14052 case COMMUNITY_DENY:
14053 return "deny";
14054 case COMMUNITY_PERMIT:
14055 return "permit";
14056 default:
14057 return "unknown";
14058 }
718e3744 14059}
14060
14061/* Display error string. */
d62a17ae 14062static void community_list_perror(struct vty *vty, int ret)
14063{
14064 switch (ret) {
14065 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14066 vty_out(vty, "%% Can't find community-list\n");
14067 break;
14068 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14069 vty_out(vty, "%% Malformed community-list value\n");
14070 break;
14071 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14072 vty_out(vty,
14073 "%% Community name conflict, previously defined as standard community\n");
14074 break;
14075 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14076 vty_out(vty,
14077 "%% Community name conflict, previously defined as expanded community\n");
14078 break;
14079 }
718e3744 14080}
14081
5bf15956
DW
14082/* "community-list" keyword help string. */
14083#define COMMUNITY_LIST_STR "Add a community list entry\n"
14084
7336e101
SP
14085/*community-list standard */
14086DEFUN (community_list_standard,
14087 bgp_community_list_standard_cmd,
14088 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14089 BGP_STR
718e3744 14090 COMMUNITY_LIST_STR
14091 "Community list number (standard)\n"
5bf15956 14092 "Add an standard community-list entry\n"
718e3744 14093 "Community list name\n"
14094 "Specify community to reject\n"
14095 "Specify community to accept\n"
14096 COMMUNITY_VAL_STR)
14097{
d62a17ae 14098 char *cl_name_or_number = NULL;
14099 int direct = 0;
14100 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14101
d62a17ae 14102 int idx = 0;
7336e101
SP
14103
14104 if (argv_find(argv, argc, "ip", &idx)) {
14105 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14106 vty_out(vty, "if you are using this please migrate to the below command.\n");
14107 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14108 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14109 }
14110
d62a17ae 14111 argv_find(argv, argc, "(1-99)", &idx);
14112 argv_find(argv, argc, "WORD", &idx);
14113 cl_name_or_number = argv[idx]->arg;
14114 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14115 : COMMUNITY_DENY;
14116 argv_find(argv, argc, "AA:NN", &idx);
14117 char *str = argv_concat(argv, argc, idx);
42f914d4 14118
d62a17ae 14119 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14120 style);
42f914d4 14121
d62a17ae 14122 XFREE(MTYPE_TMP, str);
42f914d4 14123
d62a17ae 14124 if (ret < 0) {
14125 /* Display error string. */
14126 community_list_perror(vty, ret);
14127 return CMD_WARNING_CONFIG_FAILED;
14128 }
42f914d4 14129
d62a17ae 14130 return CMD_SUCCESS;
718e3744 14131}
14132
7336e101
SP
14133#if CONFDATE > 20191005
14134CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14135#endif
14136ALIAS (community_list_standard,
14137 ip_community_list_standard_cmd,
14138 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14139 IP_STR
14140 COMMUNITY_LIST_STR
14141 "Community list number (standard)\n"
5bf15956
DW
14142 "Add an standard community-list entry\n"
14143 "Community list name\n"
718e3744 14144 "Specify community to reject\n"
14145 "Specify community to accept\n"
14146 COMMUNITY_VAL_STR)
7336e101
SP
14147
14148DEFUN (no_community_list_standard_all,
14149 no_bgp_community_list_standard_all_cmd,
14150 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14151 NO_STR
14152 BGP_STR
14153 COMMUNITY_LIST_STR
14154 "Community list number (standard)\n"
14155 "Add an standard community-list entry\n"
14156 "Community list name\n"
14157 "Specify community to reject\n"
14158 "Specify community to accept\n"
14159 COMMUNITY_VAL_STR)
718e3744 14160{
d62a17ae 14161 char *cl_name_or_number = NULL;
174b5cb9 14162 char *str = NULL;
d62a17ae 14163 int direct = 0;
14164 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14165
d62a17ae 14166 int idx = 0;
7336e101
SP
14167
14168 if (argv_find(argv, argc, "ip", &idx)) {
14169 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14170 vty_out(vty, "if you are using this please migrate to the below command.\n");
14171 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14172 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14173 }
14174
174b5cb9
DA
14175 argv_find(argv, argc, "permit", &idx);
14176 argv_find(argv, argc, "deny", &idx);
14177
14178 if (idx) {
14179 direct = argv_find(argv, argc, "permit", &idx)
14180 ? COMMUNITY_PERMIT
14181 : COMMUNITY_DENY;
14182
14183 idx = 0;
14184 argv_find(argv, argc, "AA:NN", &idx);
14185 str = argv_concat(argv, argc, idx);
14186 }
14187
14188 idx = 0;
d62a17ae 14189 argv_find(argv, argc, "(1-99)", &idx);
14190 argv_find(argv, argc, "WORD", &idx);
14191 cl_name_or_number = argv[idx]->arg;
42f914d4 14192
d62a17ae 14193 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14194 direct, style);
42f914d4 14195
d62a17ae 14196 XFREE(MTYPE_TMP, str);
daf9ddbb 14197
d62a17ae 14198 if (ret < 0) {
14199 community_list_perror(vty, ret);
14200 return CMD_WARNING_CONFIG_FAILED;
14201 }
42f914d4 14202
d62a17ae 14203 return CMD_SUCCESS;
718e3744 14204}
7336e101
SP
14205ALIAS (no_community_list_standard_all,
14206 no_ip_community_list_standard_all_cmd,
14207 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14208 NO_STR
718e3744 14209 IP_STR
14210 COMMUNITY_LIST_STR
7336e101
SP
14211 "Community list number (standard)\n"
14212 "Add an standard community-list entry\n"
14213 "Community list name\n"
14214 "Specify community to reject\n"
14215 "Specify community to accept\n"
14216 COMMUNITY_VAL_STR)
14217
174b5cb9
DA
14218ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14219 "no bgp community-list <(1-99)|standard WORD>",
14220 NO_STR BGP_STR COMMUNITY_LIST_STR
14221 "Community list number (standard)\n"
14222 "Add an standard community-list entry\n"
14223 "Community list name\n")
14224
14225ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14226 "no ip community-list <(1-99)|standard WORD>",
14227 NO_STR BGP_STR COMMUNITY_LIST_STR
14228 "Community list number (standard)\n"
14229 "Add an standard community-list entry\n"
14230 "Community list name\n")
14231
7336e101
SP
14232/*community-list expanded */
14233DEFUN (community_list_expanded_all,
14234 bgp_community_list_expanded_all_cmd,
14235 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14236 BGP_STR
14237 COMMUNITY_LIST_STR
718e3744 14238 "Community list number (expanded)\n"
5bf15956 14239 "Add an expanded community-list entry\n"
718e3744 14240 "Community list name\n"
14241 "Specify community to reject\n"
14242 "Specify community to accept\n"
14243 COMMUNITY_VAL_STR)
14244{
d62a17ae 14245 char *cl_name_or_number = NULL;
14246 int direct = 0;
14247 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14248
d62a17ae 14249 int idx = 0;
7336e101
SP
14250 if (argv_find(argv, argc, "ip", &idx)) {
14251 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14252 vty_out(vty, "if you are using this please migrate to the below command.\n");
14253 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14254 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14255 }
d62a17ae 14256 argv_find(argv, argc, "(100-500)", &idx);
14257 argv_find(argv, argc, "WORD", &idx);
14258 cl_name_or_number = argv[idx]->arg;
14259 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14260 : COMMUNITY_DENY;
14261 argv_find(argv, argc, "AA:NN", &idx);
14262 char *str = argv_concat(argv, argc, idx);
42f914d4 14263
d62a17ae 14264 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14265 style);
42f914d4 14266
d62a17ae 14267 XFREE(MTYPE_TMP, str);
42f914d4 14268
d62a17ae 14269 if (ret < 0) {
14270 /* Display error string. */
14271 community_list_perror(vty, ret);
14272 return CMD_WARNING_CONFIG_FAILED;
14273 }
42f914d4 14274
d62a17ae 14275 return CMD_SUCCESS;
718e3744 14276}
14277
7336e101
SP
14278ALIAS (community_list_expanded_all,
14279 ip_community_list_expanded_all_cmd,
14280 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14281 IP_STR
14282 COMMUNITY_LIST_STR
5bf15956
DW
14283 "Community list number (expanded)\n"
14284 "Add an expanded community-list entry\n"
718e3744 14285 "Community list name\n"
14286 "Specify community to reject\n"
14287 "Specify community to accept\n"
5bf15956 14288 COMMUNITY_VAL_STR)
7336e101
SP
14289
14290DEFUN (no_community_list_expanded_all,
14291 no_bgp_community_list_expanded_all_cmd,
14292 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14293 NO_STR
14294 BGP_STR
14295 COMMUNITY_LIST_STR
14296 "Community list number (expanded)\n"
14297 "Add an expanded community-list entry\n"
14298 "Community list name\n"
14299 "Specify community to reject\n"
14300 "Specify community to accept\n"
14301 COMMUNITY_VAL_STR)
718e3744 14302{
d62a17ae 14303 char *cl_name_or_number = NULL;
174b5cb9 14304 char *str = NULL;
d62a17ae 14305 int direct = 0;
14306 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14307
d62a17ae 14308 int idx = 0;
7336e101
SP
14309 if (argv_find(argv, argc, "ip", &idx)) {
14310 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14311 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14312 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14313 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14314 }
14315
3c4b8fe2 14316 idx = 0;
174b5cb9
DA
14317 argv_find(argv, argc, "permit", &idx);
14318 argv_find(argv, argc, "deny", &idx);
14319
14320 if (idx) {
14321 direct = argv_find(argv, argc, "permit", &idx)
14322 ? COMMUNITY_PERMIT
14323 : COMMUNITY_DENY;
14324
14325 idx = 0;
14326 argv_find(argv, argc, "AA:NN", &idx);
14327 str = argv_concat(argv, argc, idx);
7336e101 14328 }
174b5cb9
DA
14329
14330 idx = 0;
d62a17ae 14331 argv_find(argv, argc, "(100-500)", &idx);
14332 argv_find(argv, argc, "WORD", &idx);
14333 cl_name_or_number = argv[idx]->arg;
42f914d4 14334
d62a17ae 14335 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14336 direct, style);
42f914d4 14337
d62a17ae 14338 XFREE(MTYPE_TMP, str);
daf9ddbb 14339
d62a17ae 14340 if (ret < 0) {
14341 community_list_perror(vty, ret);
14342 return CMD_WARNING_CONFIG_FAILED;
14343 }
42f914d4 14344
d62a17ae 14345 return CMD_SUCCESS;
718e3744 14346}
14347
7336e101
SP
14348ALIAS (no_community_list_expanded_all,
14349 no_ip_community_list_expanded_all_cmd,
14350 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14351 NO_STR
14352 IP_STR
14353 COMMUNITY_LIST_STR
14354 "Community list number (expanded)\n"
14355 "Add an expanded community-list entry\n"
14356 "Community list name\n"
14357 "Specify community to reject\n"
14358 "Specify community to accept\n"
14359 COMMUNITY_VAL_STR)
14360
174b5cb9
DA
14361ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14362 "no bgp community-list <(100-500)|expanded WORD>",
14363 NO_STR IP_STR COMMUNITY_LIST_STR
14364 "Community list number (expanded)\n"
14365 "Add an expanded community-list entry\n"
14366 "Community list name\n")
14367
14368ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14369 "no ip community-list <(100-500)|expanded WORD>",
14370 NO_STR IP_STR COMMUNITY_LIST_STR
14371 "Community list number (expanded)\n"
14372 "Add an expanded community-list entry\n"
14373 "Community list name\n")
14374
8d9b8ed9
PM
14375/* Return configuration string of community-list entry. */
14376static const char *community_list_config_str(struct community_entry *entry)
14377{
14378 const char *str;
14379
14380 if (entry->any)
14381 str = "";
14382 else {
14383 if (entry->style == COMMUNITY_LIST_STANDARD)
14384 str = community_str(entry->u.com, false);
14385 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14386 str = lcommunity_str(entry->u.lcom, false);
14387 else
14388 str = entry->config;
14389 }
14390 return str;
14391}
14392
d62a17ae 14393static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14394{
d62a17ae 14395 struct community_entry *entry;
718e3744 14396
d62a17ae 14397 for (entry = list->head; entry; entry = entry->next) {
14398 if (entry == list->head) {
14399 if (all_digit(list->name))
14400 vty_out(vty, "Community %s list %s\n",
14401 entry->style == COMMUNITY_LIST_STANDARD
14402 ? "standard"
14403 : "(expanded) access",
14404 list->name);
14405 else
14406 vty_out(vty, "Named Community %s list %s\n",
14407 entry->style == COMMUNITY_LIST_STANDARD
14408 ? "standard"
14409 : "expanded",
14410 list->name);
14411 }
14412 if (entry->any)
14413 vty_out(vty, " %s\n",
14414 community_direct_str(entry->direct));
14415 else
14416 vty_out(vty, " %s %s\n",
14417 community_direct_str(entry->direct),
8d9b8ed9 14418 community_list_config_str(entry));
d62a17ae 14419 }
718e3744 14420}
14421
7336e101
SP
14422DEFUN (show_community_list,
14423 show_bgp_community_list_cmd,
14424 "show bgp community-list",
718e3744 14425 SHOW_STR
7336e101 14426 BGP_STR
718e3744 14427 "List community-list\n")
14428{
d62a17ae 14429 struct community_list *list;
14430 struct community_list_master *cm;
718e3744 14431
7336e101
SP
14432 int idx = 0;
14433 if (argv_find(argv, argc, "ip", &idx)) {
14434 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14435 vty_out(vty, "if you are using this please migrate to the below command.\n");
14436 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14437 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14438 }
d62a17ae 14439 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14440 if (!cm)
14441 return CMD_SUCCESS;
718e3744 14442
d62a17ae 14443 for (list = cm->num.head; list; list = list->next)
14444 community_list_show(vty, list);
718e3744 14445
d62a17ae 14446 for (list = cm->str.head; list; list = list->next)
14447 community_list_show(vty, list);
718e3744 14448
d62a17ae 14449 return CMD_SUCCESS;
718e3744 14450}
14451
7336e101
SP
14452ALIAS (show_community_list,
14453 show_ip_community_list_cmd,
14454 "show ip community-list",
718e3744 14455 SHOW_STR
14456 IP_STR
7336e101
SP
14457 "List community-list\n")
14458
14459DEFUN (show_community_list_arg,
14460 show_bgp_community_list_arg_cmd,
14461 "show bgp community-list <(1-500)|WORD>",
14462 SHOW_STR
14463 BGP_STR
718e3744 14464 "List community-list\n"
14465 "Community-list number\n"
14466 "Community-list name\n")
14467{
d62a17ae 14468 int idx_comm_list = 3;
14469 struct community_list *list;
718e3744 14470
7336e101
SP
14471 int idx = 0;
14472 if (argv_find(argv, argc, "ip", &idx)) {
14473 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14474 vty_out(vty, "if you are using this please migrate to the below command.\n");
14475 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14476 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14477 }
e237b0d2 14478 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14479 COMMUNITY_LIST_MASTER);
14480 if (!list) {
14481 vty_out(vty, "%% Can't find community-list\n");
14482 return CMD_WARNING;
14483 }
718e3744 14484
d62a17ae 14485 community_list_show(vty, list);
718e3744 14486
d62a17ae 14487 return CMD_SUCCESS;
718e3744 14488}
6b0655a2 14489
7336e101
SP
14490ALIAS (show_community_list_arg,
14491 show_ip_community_list_arg_cmd,
14492 "show ip community-list <(1-500)|WORD>",
14493 SHOW_STR
14494 IP_STR
14495 "List community-list\n"
14496 "Community-list number\n"
14497 "Community-list name\n")
14498
57d187bc
JS
14499/*
14500 * Large Community code.
14501 */
d62a17ae 14502static int lcommunity_list_set_vty(struct vty *vty, int argc,
14503 struct cmd_token **argv, int style,
14504 int reject_all_digit_name)
14505{
14506 int ret;
14507 int direct;
14508 char *str;
14509 int idx = 0;
14510 char *cl_name;
14511
7336e101
SP
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, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14516 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14517 }
d62a17ae 14518 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14519 : COMMUNITY_DENY;
14520
14521 /* All digit name check. */
14522 idx = 0;
14523 argv_find(argv, argc, "WORD", &idx);
14524 argv_find(argv, argc, "(1-99)", &idx);
14525 argv_find(argv, argc, "(100-500)", &idx);
14526 cl_name = argv[idx]->arg;
14527 if (reject_all_digit_name && all_digit(cl_name)) {
14528 vty_out(vty, "%% Community name cannot have all digits\n");
14529 return CMD_WARNING_CONFIG_FAILED;
14530 }
14531
14532 idx = 0;
14533 argv_find(argv, argc, "AA:BB:CC", &idx);
14534 argv_find(argv, argc, "LINE", &idx);
14535 /* Concat community string argument. */
14536 if (idx)
14537 str = argv_concat(argv, argc, idx);
14538 else
14539 str = NULL;
14540
14541 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14542
14543 /* Free temporary community list string allocated by
14544 argv_concat(). */
0a22ddfb 14545 XFREE(MTYPE_TMP, str);
d62a17ae 14546
14547 if (ret < 0) {
14548 community_list_perror(vty, ret);
14549 return CMD_WARNING_CONFIG_FAILED;
14550 }
14551 return CMD_SUCCESS;
14552}
14553
14554static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14555 struct cmd_token **argv, int style)
14556{
14557 int ret;
14558 int direct = 0;
14559 char *str = NULL;
14560 int idx = 0;
14561
7336e101
SP
14562 if (argv_find(argv, argc, "ip", &idx)) {
14563 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14564 vty_out(vty, "if you are using this please migrate to the below command.\n");
14565 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
16941c05 14566 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
7336e101 14567 }
d62a17ae 14568 argv_find(argv, argc, "permit", &idx);
14569 argv_find(argv, argc, "deny", &idx);
14570
14571 if (idx) {
14572 /* Check the list direct. */
14573 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14574 direct = COMMUNITY_PERMIT;
14575 else
14576 direct = COMMUNITY_DENY;
14577
14578 idx = 0;
14579 argv_find(argv, argc, "LINE", &idx);
14580 argv_find(argv, argc, "AA:AA:NN", &idx);
14581 /* Concat community string argument. */
14582 str = argv_concat(argv, argc, idx);
14583 }
14584
14585 idx = 0;
14586 argv_find(argv, argc, "(1-99)", &idx);
14587 argv_find(argv, argc, "(100-500)", &idx);
14588 argv_find(argv, argc, "WORD", &idx);
14589
14590 /* Unset community list. */
14591 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14592 style);
14593
14594 /* Free temporary community list string allocated by
14595 argv_concat(). */
0a22ddfb 14596 XFREE(MTYPE_TMP, str);
d62a17ae 14597
14598 if (ret < 0) {
14599 community_list_perror(vty, ret);
14600 return CMD_WARNING_CONFIG_FAILED;
14601 }
14602
14603 return CMD_SUCCESS;
57d187bc
JS
14604}
14605
14606/* "large-community-list" keyword help string. */
14607#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14608#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14609
7336e101
SP
14610#if CONFDATE > 20191005
14611CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14612#endif
14613DEFUN (lcommunity_list_standard,
14614 bgp_lcommunity_list_standard_cmd,
14615 "bgp large-community-list (1-99) <deny|permit>",
14616 BGP_STR
14617 LCOMMUNITY_LIST_STR
14618 "Large Community list number (standard)\n"
14619 "Specify large community to reject\n"
14620 "Specify large community to accept\n")
14621{
14622 return lcommunity_list_set_vty(vty, argc, argv,
14623 LARGE_COMMUNITY_LIST_STANDARD, 0);
14624}
14625
14626ALIAS (lcommunity_list_standard,
57d187bc 14627 ip_lcommunity_list_standard_cmd,
52951b63
DS
14628 "ip large-community-list (1-99) <deny|permit>",
14629 IP_STR
14630 LCOMMUNITY_LIST_STR
14631 "Large Community list number (standard)\n"
14632 "Specify large community to reject\n"
7111c1a0 14633 "Specify large community to accept\n")
7336e101
SP
14634
14635DEFUN (lcommunity_list_standard1,
14636 bgp_lcommunity_list_standard1_cmd,
14637 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14638 BGP_STR
14639 LCOMMUNITY_LIST_STR
14640 "Large Community list number (standard)\n"
14641 "Specify large community to reject\n"
14642 "Specify large community to accept\n"
14643 LCOMMUNITY_VAL_STR)
52951b63 14644{
d62a17ae 14645 return lcommunity_list_set_vty(vty, argc, argv,
14646 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14647}
14648
7336e101 14649ALIAS (lcommunity_list_standard1,
52951b63
DS
14650 ip_lcommunity_list_standard1_cmd,
14651 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14652 IP_STR
14653 LCOMMUNITY_LIST_STR
14654 "Large Community list number (standard)\n"
14655 "Specify large community to reject\n"
14656 "Specify large community to accept\n"
14657 LCOMMUNITY_VAL_STR)
7336e101
SP
14658
14659DEFUN (lcommunity_list_expanded,
14660 bgp_lcommunity_list_expanded_cmd,
14661 "bgp large-community-list (100-500) <deny|permit> LINE...",
14662 BGP_STR
14663 LCOMMUNITY_LIST_STR
14664 "Large Community list number (expanded)\n"
14665 "Specify large community to reject\n"
14666 "Specify large community to accept\n"
14667 "An ordered list as a regular-expression\n")
57d187bc 14668{
d62a17ae 14669 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14670 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14671}
14672
7336e101 14673ALIAS (lcommunity_list_expanded,
57d187bc
JS
14674 ip_lcommunity_list_expanded_cmd,
14675 "ip large-community-list (100-500) <deny|permit> LINE...",
14676 IP_STR
14677 LCOMMUNITY_LIST_STR
14678 "Large Community list number (expanded)\n"
14679 "Specify large community to reject\n"
14680 "Specify large community to accept\n"
14681 "An ordered list as a regular-expression\n")
7336e101
SP
14682
14683DEFUN (lcommunity_list_name_standard,
14684 bgp_lcommunity_list_name_standard_cmd,
14685 "bgp large-community-list standard WORD <deny|permit>",
14686 BGP_STR
14687 LCOMMUNITY_LIST_STR
14688 "Specify standard large-community-list\n"
14689 "Large Community list name\n"
14690 "Specify large community to reject\n"
14691 "Specify large community to accept\n")
57d187bc 14692{
d62a17ae 14693 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14694 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
14695}
14696
7336e101 14697ALIAS (lcommunity_list_name_standard,
57d187bc 14698 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
14699 "ip large-community-list standard WORD <deny|permit>",
14700 IP_STR
14701 LCOMMUNITY_LIST_STR
14702 "Specify standard large-community-list\n"
14703 "Large Community list name\n"
14704 "Specify large community to reject\n"
14705 "Specify large community to accept\n")
7336e101
SP
14706
14707DEFUN (lcommunity_list_name_standard1,
14708 bgp_lcommunity_list_name_standard1_cmd,
14709 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14710 BGP_STR
14711 LCOMMUNITY_LIST_STR
14712 "Specify standard large-community-list\n"
14713 "Large Community list name\n"
14714 "Specify large community to reject\n"
14715 "Specify large community to accept\n"
14716 LCOMMUNITY_VAL_STR)
52951b63 14717{
d62a17ae 14718 return lcommunity_list_set_vty(vty, argc, argv,
14719 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14720}
14721
7336e101 14722ALIAS (lcommunity_list_name_standard1,
52951b63
DS
14723 ip_lcommunity_list_name_standard1_cmd,
14724 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14725 IP_STR
14726 LCOMMUNITY_LIST_STR
14727 "Specify standard large-community-list\n"
14728 "Large Community list name\n"
14729 "Specify large community to reject\n"
14730 "Specify large community to accept\n"
14731 LCOMMUNITY_VAL_STR)
7336e101
SP
14732
14733DEFUN (lcommunity_list_name_expanded,
14734 bgp_lcommunity_list_name_expanded_cmd,
14735 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14736 BGP_STR
14737 LCOMMUNITY_LIST_STR
14738 "Specify expanded large-community-list\n"
14739 "Large Community list name\n"
14740 "Specify large community to reject\n"
14741 "Specify large community to accept\n"
14742 "An ordered list as a regular-expression\n")
57d187bc 14743{
d62a17ae 14744 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14745 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14746}
14747
7336e101 14748ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14749 ip_lcommunity_list_name_expanded_cmd,
14750 "ip large-community-list expanded WORD <deny|permit> LINE...",
14751 IP_STR
14752 LCOMMUNITY_LIST_STR
14753 "Specify expanded large-community-list\n"
14754 "Large Community list name\n"
14755 "Specify large community to reject\n"
14756 "Specify large community to accept\n"
14757 "An ordered list as a regular-expression\n")
7336e101
SP
14758
14759DEFUN (no_lcommunity_list_standard_all,
14760 no_bgp_lcommunity_list_standard_all_cmd,
14761 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14762 NO_STR
14763 BGP_STR
14764 LCOMMUNITY_LIST_STR
14765 "Large Community list number (standard)\n"
14766 "Large Community list number (expanded)\n"
14767 "Large Community list name\n")
57d187bc 14768{
7336e101
SP
14769 return lcommunity_list_unset_vty(vty, argc, argv,
14770 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14771}
14772
7336e101 14773ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14774 no_ip_lcommunity_list_standard_all_cmd,
14775 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14776 NO_STR
14777 IP_STR
14778 LCOMMUNITY_LIST_STR
14779 "Large Community list number (standard)\n"
14780 "Large Community list number (expanded)\n"
14781 "Large Community list name\n")
7336e101
SP
14782
14783DEFUN (no_lcommunity_list_name_expanded_all,
14784 no_bgp_lcommunity_list_name_expanded_all_cmd,
14785 "no bgp large-community-list expanded WORD",
14786 NO_STR
14787 BGP_STR
14788 LCOMMUNITY_LIST_STR
14789 "Specify expanded large-community-list\n"
14790 "Large Community list name\n")
57d187bc 14791{
d62a17ae 14792 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14793 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14794}
14795
7336e101 14796ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14797 no_ip_lcommunity_list_name_expanded_all_cmd,
14798 "no ip large-community-list expanded WORD",
14799 NO_STR
14800 IP_STR
14801 LCOMMUNITY_LIST_STR
14802 "Specify expanded large-community-list\n"
14803 "Large Community list name\n")
7336e101
SP
14804
14805DEFUN (no_lcommunity_list_standard,
14806 no_bgp_lcommunity_list_standard_cmd,
14807 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14808 NO_STR
14809 BGP_STR
14810 LCOMMUNITY_LIST_STR
14811 "Large Community list number (standard)\n"
14812 "Specify large community to reject\n"
14813 "Specify large community to accept\n"
14814 LCOMMUNITY_VAL_STR)
57d187bc 14815{
d62a17ae 14816 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14817 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14818}
14819
7336e101 14820ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14821 no_ip_lcommunity_list_standard_cmd,
14822 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14823 NO_STR
14824 IP_STR
14825 LCOMMUNITY_LIST_STR
14826 "Large Community list number (standard)\n"
14827 "Specify large community to reject\n"
14828 "Specify large community to accept\n"
14829 LCOMMUNITY_VAL_STR)
7336e101
SP
14830
14831DEFUN (no_lcommunity_list_expanded,
14832 no_bgp_lcommunity_list_expanded_cmd,
14833 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14834 NO_STR
14835 BGP_STR
14836 LCOMMUNITY_LIST_STR
14837 "Large Community list number (expanded)\n"
14838 "Specify large community to reject\n"
14839 "Specify large community to accept\n"
14840 "An ordered list as a regular-expression\n")
57d187bc 14841{
d62a17ae 14842 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14843 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14844}
14845
7336e101 14846ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14847 no_ip_lcommunity_list_expanded_cmd,
14848 "no ip large-community-list (100-500) <deny|permit> LINE...",
14849 NO_STR
14850 IP_STR
14851 LCOMMUNITY_LIST_STR
14852 "Large Community list number (expanded)\n"
14853 "Specify large community to reject\n"
14854 "Specify large community to accept\n"
14855 "An ordered list as a regular-expression\n")
7336e101
SP
14856
14857DEFUN (no_lcommunity_list_name_standard,
14858 no_bgp_lcommunity_list_name_standard_cmd,
14859 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14860 NO_STR
14861 BGP_STR
14862 LCOMMUNITY_LIST_STR
14863 "Specify standard large-community-list\n"
14864 "Large Community list name\n"
14865 "Specify large community to reject\n"
14866 "Specify large community to accept\n"
14867 LCOMMUNITY_VAL_STR)
57d187bc 14868{
d62a17ae 14869 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14870 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14871}
14872
7336e101 14873ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
14874 no_ip_lcommunity_list_name_standard_cmd,
14875 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14876 NO_STR
14877 IP_STR
14878 LCOMMUNITY_LIST_STR
14879 "Specify standard large-community-list\n"
14880 "Large Community list name\n"
14881 "Specify large community to reject\n"
14882 "Specify large community to accept\n"
14883 LCOMMUNITY_VAL_STR)
7336e101
SP
14884
14885DEFUN (no_lcommunity_list_name_expanded,
14886 no_bgp_lcommunity_list_name_expanded_cmd,
14887 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14888 NO_STR
14889 BGP_STR
14890 LCOMMUNITY_LIST_STR
14891 "Specify expanded large-community-list\n"
14892 "Large community list name\n"
14893 "Specify large community to reject\n"
14894 "Specify large community to accept\n"
14895 "An ordered list as a regular-expression\n")
57d187bc 14896{
d62a17ae 14897 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14898 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14899}
14900
7336e101 14901ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
14902 no_ip_lcommunity_list_name_expanded_cmd,
14903 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14904 NO_STR
14905 IP_STR
14906 LCOMMUNITY_LIST_STR
14907 "Specify expanded large-community-list\n"
14908 "Large community list name\n"
14909 "Specify large community to reject\n"
14910 "Specify large community to accept\n"
14911 "An ordered list as a regular-expression\n")
d62a17ae 14912
14913static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14914{
14915 struct community_entry *entry;
14916
14917 for (entry = list->head; entry; entry = entry->next) {
14918 if (entry == list->head) {
14919 if (all_digit(list->name))
14920 vty_out(vty, "Large community %s list %s\n",
169b72c8 14921 entry->style ==
14922 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14923 ? "standard"
14924 : "(expanded) access",
14925 list->name);
14926 else
14927 vty_out(vty,
14928 "Named large community %s list %s\n",
169b72c8 14929 entry->style ==
14930 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 14931 ? "standard"
14932 : "expanded",
14933 list->name);
14934 }
14935 if (entry->any)
14936 vty_out(vty, " %s\n",
14937 community_direct_str(entry->direct));
14938 else
14939 vty_out(vty, " %s %s\n",
14940 community_direct_str(entry->direct),
8d9b8ed9 14941 community_list_config_str(entry));
d62a17ae 14942 }
57d187bc
JS
14943}
14944
7336e101
SP
14945DEFUN (show_lcommunity_list,
14946 show_bgp_lcommunity_list_cmd,
14947 "show bgp large-community-list",
57d187bc 14948 SHOW_STR
7336e101 14949 BGP_STR
57d187bc
JS
14950 "List large-community list\n")
14951{
d62a17ae 14952 struct community_list *list;
14953 struct community_list_master *cm;
7336e101
SP
14954 int idx = 0;
14955
14956 if (argv_find(argv, argc, "ip", &idx)) {
14957 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14958 vty_out(vty, "if you are using this please migrate to the below command.\n");
14959 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14960 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14961 }
57d187bc 14962
d62a17ae 14963 cm = community_list_master_lookup(bgp_clist,
14964 LARGE_COMMUNITY_LIST_MASTER);
14965 if (!cm)
14966 return CMD_SUCCESS;
57d187bc 14967
d62a17ae 14968 for (list = cm->num.head; list; list = list->next)
14969 lcommunity_list_show(vty, list);
57d187bc 14970
d62a17ae 14971 for (list = cm->str.head; list; list = list->next)
14972 lcommunity_list_show(vty, list);
57d187bc 14973
d62a17ae 14974 return CMD_SUCCESS;
57d187bc
JS
14975}
14976
7336e101
SP
14977ALIAS (show_lcommunity_list,
14978 show_ip_lcommunity_list_cmd,
14979 "show ip large-community-list",
57d187bc
JS
14980 SHOW_STR
14981 IP_STR
7336e101
SP
14982 "List large-community list\n")
14983
14984DEFUN (show_lcommunity_list_arg,
14985 show_bgp_lcommunity_list_arg_cmd,
14986 "show bgp large-community-list <(1-500)|WORD>",
14987 SHOW_STR
14988 BGP_STR
57d187bc
JS
14989 "List large-community list\n"
14990 "large-community-list number\n"
14991 "large-community-list name\n")
14992{
d62a17ae 14993 struct community_list *list;
7336e101
SP
14994 int idx = 0;
14995
14996 if (argv_find(argv, argc, "ip", &idx)) {
14997 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14998 vty_out(vty, "if you are using this please migrate to the below command.\n");
14999 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15000 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15001 }
57d187bc 15002
e237b0d2 15003 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 15004 LARGE_COMMUNITY_LIST_MASTER);
15005 if (!list) {
15006 vty_out(vty, "%% Can't find extcommunity-list\n");
15007 return CMD_WARNING;
15008 }
57d187bc 15009
d62a17ae 15010 lcommunity_list_show(vty, list);
57d187bc 15011
d62a17ae 15012 return CMD_SUCCESS;
57d187bc
JS
15013}
15014
7336e101
SP
15015ALIAS (show_lcommunity_list_arg,
15016 show_ip_lcommunity_list_arg_cmd,
15017 "show ip large-community-list <(1-500)|WORD>",
15018 SHOW_STR
15019 IP_STR
15020 "List large-community list\n"
15021 "large-community-list number\n"
15022 "large-community-list name\n")
15023
718e3744 15024/* "extcommunity-list" keyword help string. */
15025#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15026#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15027
7336e101
SP
15028DEFUN (extcommunity_list_standard,
15029 bgp_extcommunity_list_standard_cmd,
15030 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15031 BGP_STR
718e3744 15032 EXTCOMMUNITY_LIST_STR
15033 "Extended Community list number (standard)\n"
718e3744 15034 "Specify standard extcommunity-list\n"
5bf15956 15035 "Community list name\n"
718e3744 15036 "Specify community to reject\n"
15037 "Specify community to accept\n"
15038 EXTCOMMUNITY_VAL_STR)
15039{
d62a17ae 15040 int style = EXTCOMMUNITY_LIST_STANDARD;
15041 int direct = 0;
15042 char *cl_number_or_name = NULL;
42f914d4 15043
d62a17ae 15044 int idx = 0;
7336e101
SP
15045 if (argv_find(argv, argc, "ip", &idx)) {
15046 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15047 vty_out(vty, "if you are using this please migrate to the below command.\n");
15048 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15049 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15050 }
d62a17ae 15051 argv_find(argv, argc, "(1-99)", &idx);
15052 argv_find(argv, argc, "WORD", &idx);
15053 cl_number_or_name = argv[idx]->arg;
15054 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15055 : COMMUNITY_DENY;
15056 argv_find(argv, argc, "AA:NN", &idx);
15057 char *str = argv_concat(argv, argc, idx);
42f914d4 15058
d62a17ae 15059 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15060 direct, style);
42f914d4 15061
d62a17ae 15062 XFREE(MTYPE_TMP, str);
42f914d4 15063
d62a17ae 15064 if (ret < 0) {
15065 community_list_perror(vty, ret);
15066 return CMD_WARNING_CONFIG_FAILED;
15067 }
42f914d4 15068
d62a17ae 15069 return CMD_SUCCESS;
718e3744 15070}
15071
7336e101
SP
15072#if CONFDATE > 20191005
15073CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15074#endif
15075ALIAS (extcommunity_list_standard,
15076 ip_extcommunity_list_standard_cmd,
15077 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15078 IP_STR
15079 EXTCOMMUNITY_LIST_STR
7336e101
SP
15080 "Extended Community list number (standard)\n"
15081 "Specify standard extcommunity-list\n"
15082 "Community list name\n"
15083 "Specify community to reject\n"
15084 "Specify community to accept\n"
15085 EXTCOMMUNITY_VAL_STR)
15086
15087DEFUN (extcommunity_list_name_expanded,
15088 bgp_extcommunity_list_name_expanded_cmd,
15089 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15090 BGP_STR
15091 EXTCOMMUNITY_LIST_STR
5bf15956 15092 "Extended Community list number (expanded)\n"
718e3744 15093 "Specify expanded extcommunity-list\n"
15094 "Extended Community list name\n"
15095 "Specify community to reject\n"
15096 "Specify community to accept\n"
15097 "An ordered list as a regular-expression\n")
15098{
d62a17ae 15099 int style = EXTCOMMUNITY_LIST_EXPANDED;
15100 int direct = 0;
15101 char *cl_number_or_name = NULL;
42f914d4 15102
d62a17ae 15103 int idx = 0;
7336e101
SP
15104 if (argv_find(argv, argc, "ip", &idx)) {
15105 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15106 vty_out(vty, "if you are using this please migrate to the below command.\n");
15107 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15108 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15109 }
15110
d62a17ae 15111 argv_find(argv, argc, "(100-500)", &idx);
15112 argv_find(argv, argc, "WORD", &idx);
15113 cl_number_or_name = argv[idx]->arg;
15114 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15115 : COMMUNITY_DENY;
15116 argv_find(argv, argc, "LINE", &idx);
15117 char *str = argv_concat(argv, argc, idx);
42f914d4 15118
d62a17ae 15119 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15120 direct, style);
42f914d4 15121
d62a17ae 15122 XFREE(MTYPE_TMP, str);
42f914d4 15123
d62a17ae 15124 if (ret < 0) {
15125 community_list_perror(vty, ret);
15126 return CMD_WARNING_CONFIG_FAILED;
15127 }
42f914d4 15128
d62a17ae 15129 return CMD_SUCCESS;
718e3744 15130}
15131
7336e101
SP
15132ALIAS (extcommunity_list_name_expanded,
15133 ip_extcommunity_list_name_expanded_cmd,
15134 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
15135 IP_STR
15136 EXTCOMMUNITY_LIST_STR
7336e101
SP
15137 "Extended Community list number (expanded)\n"
15138 "Specify expanded extcommunity-list\n"
15139 "Extended Community list name\n"
15140 "Specify community to reject\n"
15141 "Specify community to accept\n"
15142 "An ordered list as a regular-expression\n")
15143
15144DEFUN (no_extcommunity_list_standard_all,
15145 no_bgp_extcommunity_list_standard_all_cmd,
15146 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15147 NO_STR
15148 BGP_STR
15149 EXTCOMMUNITY_LIST_STR
813d4307 15150 "Extended Community list number (standard)\n"
718e3744 15151 "Specify standard extcommunity-list\n"
5bf15956 15152 "Community list name\n"
718e3744 15153 "Specify community to reject\n"
15154 "Specify community to accept\n"
15155 EXTCOMMUNITY_VAL_STR)
15156{
d62a17ae 15157 int style = EXTCOMMUNITY_LIST_STANDARD;
15158 int direct = 0;
15159 char *cl_number_or_name = NULL;
d4455c89 15160 char *str = NULL;
42f914d4 15161
d62a17ae 15162 int idx = 0;
7336e101
SP
15163 if (argv_find(argv, argc, "ip", &idx)) {
15164 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15165 vty_out(vty, "if you are using this please migrate to the below command.\n");
15166 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15167 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15168 }
d4455c89
DA
15169
15170 idx = 0;
15171 argv_find(argv, argc, "permit", &idx);
15172 argv_find(argv, argc, "deny", &idx);
15173
15174 if (idx) {
15175 direct = argv_find(argv, argc, "permit", &idx)
15176 ? COMMUNITY_PERMIT
15177 : COMMUNITY_DENY;
15178
15179 idx = 0;
15180 argv_find(argv, argc, "AA:NN", &idx);
15181 str = argv_concat(argv, argc, idx);
15182 }
15183
15184 idx = 0;
d62a17ae 15185 argv_find(argv, argc, "(1-99)", &idx);
15186 argv_find(argv, argc, "WORD", &idx);
15187 cl_number_or_name = argv[idx]->arg;
42f914d4 15188
d62a17ae 15189 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15190 direct, style);
42f914d4 15191
d62a17ae 15192 XFREE(MTYPE_TMP, str);
42f914d4 15193
d62a17ae 15194 if (ret < 0) {
15195 community_list_perror(vty, ret);
15196 return CMD_WARNING_CONFIG_FAILED;
15197 }
42f914d4 15198
d62a17ae 15199 return CMD_SUCCESS;
718e3744 15200}
15201
7336e101
SP
15202ALIAS (no_extcommunity_list_standard_all,
15203 no_ip_extcommunity_list_standard_all_cmd,
15204 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15205 NO_STR
15206 IP_STR
15207 EXTCOMMUNITY_LIST_STR
7336e101
SP
15208 "Extended Community list number (standard)\n"
15209 "Specify standard extcommunity-list\n"
15210 "Community list name\n"
15211 "Specify community to reject\n"
15212 "Specify community to accept\n"
15213 EXTCOMMUNITY_VAL_STR)
15214
d4455c89
DA
15215ALIAS(no_extcommunity_list_standard_all,
15216 no_bgp_extcommunity_list_standard_all_list_cmd,
15217 "no bgp extcommunity-list <(1-99)|standard WORD>",
15218 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15219 "Extended Community list number (standard)\n"
15220 "Specify standard extcommunity-list\n"
15221 "Community list name\n")
15222
15223ALIAS(no_extcommunity_list_standard_all,
15224 no_ip_extcommunity_list_standard_all_list_cmd,
15225 "no ip extcommunity-list <(1-99)|standard WORD>",
15226 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15227 "Extended Community list number (standard)\n"
15228 "Specify standard extcommunity-list\n"
15229 "Community list name\n")
15230
7336e101
SP
15231DEFUN (no_extcommunity_list_expanded_all,
15232 no_bgp_extcommunity_list_expanded_all_cmd,
15233 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15234 NO_STR
15235 BGP_STR
15236 EXTCOMMUNITY_LIST_STR
718e3744 15237 "Extended Community list number (expanded)\n"
718e3744 15238 "Specify expanded extcommunity-list\n"
5bf15956 15239 "Extended Community list name\n"
718e3744 15240 "Specify community to reject\n"
15241 "Specify community to accept\n"
15242 "An ordered list as a regular-expression\n")
15243{
d62a17ae 15244 int style = EXTCOMMUNITY_LIST_EXPANDED;
15245 int direct = 0;
15246 char *cl_number_or_name = NULL;
d4455c89 15247 char *str = NULL;
42f914d4 15248
d62a17ae 15249 int idx = 0;
7336e101
SP
15250 if (argv_find(argv, argc, "ip", &idx)) {
15251 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15252 vty_out(vty, "if you are using this please migrate to the below command.\n");
15253 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15254 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15255 }
d4455c89
DA
15256
15257 idx = 0;
15258 argv_find(argv, argc, "permit", &idx);
15259 argv_find(argv, argc, "deny", &idx);
15260
15261 if (idx) {
15262 direct = argv_find(argv, argc, "permit", &idx)
15263 ? COMMUNITY_PERMIT
15264 : COMMUNITY_DENY;
15265
15266 idx = 0;
15267 argv_find(argv, argc, "LINE", &idx);
15268 str = argv_concat(argv, argc, idx);
15269 }
15270
15271 idx = 0;
d62a17ae 15272 argv_find(argv, argc, "(100-500)", &idx);
15273 argv_find(argv, argc, "WORD", &idx);
15274 cl_number_or_name = argv[idx]->arg;
42f914d4 15275
d62a17ae 15276 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15277 direct, style);
42f914d4 15278
d62a17ae 15279 XFREE(MTYPE_TMP, str);
42f914d4 15280
d62a17ae 15281 if (ret < 0) {
15282 community_list_perror(vty, ret);
15283 return CMD_WARNING_CONFIG_FAILED;
15284 }
42f914d4 15285
d62a17ae 15286 return CMD_SUCCESS;
718e3744 15287}
15288
7336e101
SP
15289ALIAS (no_extcommunity_list_expanded_all,
15290 no_ip_extcommunity_list_expanded_all_cmd,
15291 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15292 NO_STR
15293 IP_STR
15294 EXTCOMMUNITY_LIST_STR
15295 "Extended Community list number (expanded)\n"
15296 "Specify expanded extcommunity-list\n"
15297 "Extended Community list name\n"
15298 "Specify community to reject\n"
15299 "Specify community to accept\n"
15300 "An ordered list as a regular-expression\n")
15301
d4455c89
DA
15302ALIAS(no_extcommunity_list_expanded_all,
15303 no_ip_extcommunity_list_expanded_all_list_cmd,
15304 "no ip extcommunity-list <(100-500)|expanded WORD>",
15305 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15306 "Extended Community list number (expanded)\n"
15307 "Specify expanded extcommunity-list\n"
15308 "Extended Community list name\n")
15309
15310ALIAS(no_extcommunity_list_expanded_all,
15311 no_bgp_extcommunity_list_expanded_all_list_cmd,
15312 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15313 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15314 "Extended Community list number (expanded)\n"
15315 "Specify expanded extcommunity-list\n"
15316 "Extended Community list name\n")
15317
d62a17ae 15318static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15319{
d62a17ae 15320 struct community_entry *entry;
718e3744 15321
d62a17ae 15322 for (entry = list->head; entry; entry = entry->next) {
15323 if (entry == list->head) {
15324 if (all_digit(list->name))
15325 vty_out(vty, "Extended community %s list %s\n",
15326 entry->style == EXTCOMMUNITY_LIST_STANDARD
15327 ? "standard"
15328 : "(expanded) access",
15329 list->name);
15330 else
15331 vty_out(vty,
15332 "Named extended community %s list %s\n",
15333 entry->style == EXTCOMMUNITY_LIST_STANDARD
15334 ? "standard"
15335 : "expanded",
15336 list->name);
15337 }
15338 if (entry->any)
15339 vty_out(vty, " %s\n",
15340 community_direct_str(entry->direct));
15341 else
15342 vty_out(vty, " %s %s\n",
15343 community_direct_str(entry->direct),
8d9b8ed9 15344 community_list_config_str(entry));
d62a17ae 15345 }
718e3744 15346}
15347
7336e101
SP
15348DEFUN (show_extcommunity_list,
15349 show_bgp_extcommunity_list_cmd,
15350 "show bgp extcommunity-list",
718e3744 15351 SHOW_STR
7336e101 15352 BGP_STR
718e3744 15353 "List extended-community list\n")
15354{
d62a17ae 15355 struct community_list *list;
15356 struct community_list_master *cm;
7336e101 15357 int idx = 0;
718e3744 15358
7336e101
SP
15359 if (argv_find(argv, argc, "ip", &idx)) {
15360 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15361 vty_out(vty, "if you are using this please migrate to the below command.\n");
15362 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15363 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15364 }
d62a17ae 15365 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15366 if (!cm)
15367 return CMD_SUCCESS;
718e3744 15368
d62a17ae 15369 for (list = cm->num.head; list; list = list->next)
15370 extcommunity_list_show(vty, list);
718e3744 15371
d62a17ae 15372 for (list = cm->str.head; list; list = list->next)
15373 extcommunity_list_show(vty, list);
718e3744 15374
d62a17ae 15375 return CMD_SUCCESS;
718e3744 15376}
15377
7336e101
SP
15378ALIAS (show_extcommunity_list,
15379 show_ip_extcommunity_list_cmd,
15380 "show ip extcommunity-list",
718e3744 15381 SHOW_STR
15382 IP_STR
7336e101
SP
15383 "List extended-community list\n")
15384
15385DEFUN (show_extcommunity_list_arg,
15386 show_bgp_extcommunity_list_arg_cmd,
15387 "show bgp extcommunity-list <(1-500)|WORD>",
15388 SHOW_STR
15389 BGP_STR
718e3744 15390 "List extended-community list\n"
15391 "Extcommunity-list number\n"
15392 "Extcommunity-list name\n")
15393{
d62a17ae 15394 int idx_comm_list = 3;
15395 struct community_list *list;
7336e101 15396 int idx = 0;
718e3744 15397
7336e101
SP
15398 if (argv_find(argv, argc, "ip", &idx)) {
15399 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15400 vty_out(vty, "if you are using this please migrate to the below command.\n");
15401 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15402 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15403 }
e237b0d2 15404 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15405 EXTCOMMUNITY_LIST_MASTER);
15406 if (!list) {
15407 vty_out(vty, "%% Can't find extcommunity-list\n");
15408 return CMD_WARNING;
15409 }
718e3744 15410
d62a17ae 15411 extcommunity_list_show(vty, list);
718e3744 15412
d62a17ae 15413 return CMD_SUCCESS;
718e3744 15414}
6b0655a2 15415
7336e101
SP
15416ALIAS (show_extcommunity_list_arg,
15417 show_ip_extcommunity_list_arg_cmd,
15418 "show ip extcommunity-list <(1-500)|WORD>",
15419 SHOW_STR
15420 IP_STR
15421 "List extended-community list\n"
15422 "Extcommunity-list number\n"
15423 "Extcommunity-list name\n")
15424
718e3744 15425/* Display community-list and extcommunity-list configuration. */
d62a17ae 15426static int community_list_config_write(struct vty *vty)
15427{
15428 struct community_list *list;
15429 struct community_entry *entry;
15430 struct community_list_master *cm;
15431 int write = 0;
15432
15433 /* Community-list. */
15434 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15435
15436 for (list = cm->num.head; list; list = list->next)
15437 for (entry = list->head; entry; entry = entry->next) {
7336e101 15438 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15439 community_direct_str(entry->direct),
15440 community_list_config_str(entry));
15441 write++;
15442 }
15443 for (list = cm->str.head; list; list = list->next)
15444 for (entry = list->head; entry; entry = entry->next) {
7336e101 15445 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15446 entry->style == COMMUNITY_LIST_STANDARD
15447 ? "standard"
15448 : "expanded",
15449 list->name, community_direct_str(entry->direct),
15450 community_list_config_str(entry));
15451 write++;
15452 }
15453
15454 /* Extcommunity-list. */
15455 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15456
15457 for (list = cm->num.head; list; list = list->next)
15458 for (entry = list->head; entry; entry = entry->next) {
7336e101 15459 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15460 list->name, community_direct_str(entry->direct),
15461 community_list_config_str(entry));
15462 write++;
15463 }
15464 for (list = cm->str.head; list; list = list->next)
15465 for (entry = list->head; entry; entry = entry->next) {
7336e101 15466 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15467 entry->style == EXTCOMMUNITY_LIST_STANDARD
15468 ? "standard"
15469 : "expanded",
15470 list->name, community_direct_str(entry->direct),
15471 community_list_config_str(entry));
15472 write++;
15473 }
15474
15475
15476 /* lcommunity-list. */
15477 cm = community_list_master_lookup(bgp_clist,
15478 LARGE_COMMUNITY_LIST_MASTER);
15479
15480 for (list = cm->num.head; list; list = list->next)
15481 for (entry = list->head; entry; entry = entry->next) {
7336e101 15482 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15483 list->name, community_direct_str(entry->direct),
15484 community_list_config_str(entry));
15485 write++;
15486 }
15487 for (list = cm->str.head; list; list = list->next)
15488 for (entry = list->head; entry; entry = entry->next) {
7336e101 15489 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15490 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15491 ? "standard"
15492 : "expanded",
15493 list->name, community_direct_str(entry->direct),
15494 community_list_config_str(entry));
15495 write++;
15496 }
15497
15498 return write;
15499}
15500
15501static struct cmd_node community_list_node = {
15502 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15503};
15504
d62a17ae 15505static void community_list_vty(void)
15506{
15507 install_node(&community_list_node, community_list_config_write);
15508
15509 /* Community-list. */
7336e101
SP
15510 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15511 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15512 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15513 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15514 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15515 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15516 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15517 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15518 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15519 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15520 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15521 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15522 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15523 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15524 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15525 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15526
15527 /* Extcommunity-list. */
7336e101
SP
15528 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15529 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15530 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15531 install_element(CONFIG_NODE,
15532 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15533 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15534 install_element(CONFIG_NODE,
15535 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15536 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15537 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15538 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15539 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15540 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15541 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15542 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15543 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15544 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15545 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15546
15547 /* Large Community List */
7336e101
SP
15548 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15549 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15550 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15551 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15552 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15553 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15554 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15555 install_element(CONFIG_NODE,
15556 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15557 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15558 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15559 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15560 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15561 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15562 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15563 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15564 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15565 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15566 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15567 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15568 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15569 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15570 install_element(CONFIG_NODE,
15571 &no_ip_lcommunity_list_name_expanded_all_cmd);
15572 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15573 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15574 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15575 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15576 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15577 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15578}