]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Accept no aggregate-address <IP> route-map <RMAP> commands
[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"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
fc7948fa 35#include "memory_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dcc68b5e 67#include "bgpd/bgp_addpath.h"
48ecf8f5 68#include "bgpd/bgp_mac.h"
718e3744 69
d62a17ae 70static struct peer_group *listen_range_exists(struct bgp *bgp,
71 struct prefix *range, int exact);
72
73static enum node_type bgp_node_type(afi_t afi, safi_t safi)
74{
75 switch (afi) {
76 case AFI_IP:
77 switch (safi) {
78 case SAFI_UNICAST:
79 return BGP_IPV4_NODE;
80 break;
81 case SAFI_MULTICAST:
82 return BGP_IPV4M_NODE;
83 break;
84 case SAFI_LABELED_UNICAST:
85 return BGP_IPV4L_NODE;
86 break;
87 case SAFI_MPLS_VPN:
88 return BGP_VPNV4_NODE;
89 break;
7c40bf39 90 case SAFI_FLOWSPEC:
91 return BGP_FLOWSPECV4_NODE;
5c525538
RW
92 default:
93 /* not expected */
94 return BGP_IPV4_NODE;
95 break;
d62a17ae 96 }
97 break;
98 case AFI_IP6:
99 switch (safi) {
100 case SAFI_UNICAST:
101 return BGP_IPV6_NODE;
102 break;
103 case SAFI_MULTICAST:
104 return BGP_IPV6M_NODE;
105 break;
106 case SAFI_LABELED_UNICAST:
107 return BGP_IPV6L_NODE;
108 break;
109 case SAFI_MPLS_VPN:
110 return BGP_VPNV6_NODE;
111 break;
7c40bf39 112 case SAFI_FLOWSPEC:
113 return BGP_FLOWSPECV6_NODE;
5c525538
RW
114 default:
115 /* not expected */
116 return BGP_IPV4_NODE;
117 break;
d62a17ae 118 }
119 break;
120 case AFI_L2VPN:
121 return BGP_EVPN_NODE;
122 break;
b26f891d 123 case AFI_UNSPEC:
d62a17ae 124 case AFI_MAX:
125 // We should never be here but to clarify the switch statement..
126 return BGP_IPV4_NODE;
127 break;
128 }
129
130 // Impossible to happen
131 return BGP_IPV4_NODE;
f51bae9c 132}
20eb8864 133
5cb5f4d0
DD
134static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
135{
136 if (afi == AFI_IP && safi == SAFI_UNICAST)
137 return "IPv4 Unicast";
138 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
139 return "IPv4 Multicast";
140 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
141 return "IPv4 Labeled Unicast";
142 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
143 return "IPv4 VPN";
144 else if (afi == AFI_IP && safi == SAFI_ENCAP)
145 return "IPv4 Encap";
146 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
147 return "IPv4 Flowspec";
148 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
149 return "IPv6 Unicast";
150 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
151 return "IPv6 Multicast";
152 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
153 return "IPv6 Labeled Unicast";
154 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
155 return "IPv6 VPN";
156 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
157 return "IPv6 Encap";
158 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
159 return "IPv6 Flowspec";
160 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
161 return "L2VPN EVPN";
162 else {
163 flog_err(EC_LIB_DEVELOPMENT, "New afi/safi that needs to be taken care of?");
164 return "Unknown";
165 }
166}
167
168/*
169 * Please note that we have intentionally camelCased
170 * the return strings here. So if you want
171 * to use this function, please ensure you
172 * are doing this within json output
173 */
174static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
175{
176 if (afi == AFI_IP && safi == SAFI_UNICAST)
177 return "ipv4Unicast";
178 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
179 return "ipv4Multicast";
180 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
181 return "ipv4LabeledUnicast";
182 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
183 return "ipv4Vpn";
184 else if (afi == AFI_IP && safi == SAFI_ENCAP)
185 return "ipv4Encap";
186 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
187 return "ipv4Flowspec";
188 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
189 return "ipv6Unicast";
190 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
191 return "ipv6Multicast";
192 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
193 return "ipv6LabeledUnicast";
194 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
195 return "ipv6Vpn";
196 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
197 return "ipv6Encap";
198 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
199 return "ipv6Flowspec";
200 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
201 return "l2VpnEvpn";
202 else {
203 flog_err(EC_LIB_DEVELOPMENT, "New afi/safi that needs to be taken care of?");
204 return "Unknown";
205 }
206}
207
718e3744 208/* Utility function to get address family from current node. */
d62a17ae 209afi_t bgp_node_afi(struct vty *vty)
210{
211 afi_t afi;
212 switch (vty->node) {
213 case BGP_IPV6_NODE:
214 case BGP_IPV6M_NODE:
215 case BGP_IPV6L_NODE:
216 case BGP_VPNV6_NODE:
7c40bf39 217 case BGP_FLOWSPECV6_NODE:
d62a17ae 218 afi = AFI_IP6;
219 break;
220 case BGP_EVPN_NODE:
221 afi = AFI_L2VPN;
222 break;
223 default:
224 afi = AFI_IP;
225 break;
226 }
227 return afi;
718e3744 228}
229
230/* Utility function to get subsequent address family from current
231 node. */
d62a17ae 232safi_t bgp_node_safi(struct vty *vty)
233{
234 safi_t safi;
235 switch (vty->node) {
236 case BGP_VPNV4_NODE:
237 case BGP_VPNV6_NODE:
238 safi = SAFI_MPLS_VPN;
239 break;
240 case BGP_IPV4M_NODE:
241 case BGP_IPV6M_NODE:
242 safi = SAFI_MULTICAST;
243 break;
244 case BGP_EVPN_NODE:
245 safi = SAFI_EVPN;
246 break;
247 case BGP_IPV4L_NODE:
248 case BGP_IPV6L_NODE:
249 safi = SAFI_LABELED_UNICAST;
250 break;
7c40bf39 251 case BGP_FLOWSPECV4_NODE:
252 case BGP_FLOWSPECV6_NODE:
253 safi = SAFI_FLOWSPEC;
254 break;
d62a17ae 255 default:
256 safi = SAFI_UNICAST;
257 break;
258 }
259 return safi;
718e3744 260}
261
55f91488
QY
262/**
263 * Converts an AFI in string form to afi_t
264 *
265 * @param afi string, one of
266 * - "ipv4"
267 * - "ipv6"
81cf0de5 268 * - "l2vpn"
55f91488
QY
269 * @return the corresponding afi_t
270 */
d62a17ae 271afi_t bgp_vty_afi_from_str(const char *afi_str)
272{
273 afi_t afi = AFI_MAX; /* unknown */
274 if (strmatch(afi_str, "ipv4"))
275 afi = AFI_IP;
276 else if (strmatch(afi_str, "ipv6"))
277 afi = AFI_IP6;
81cf0de5
CS
278 else if (strmatch(afi_str, "l2vpn"))
279 afi = AFI_L2VPN;
d62a17ae 280 return afi;
281}
282
283int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
284 afi_t *afi)
285{
286 int ret = 0;
287 if (argv_find(argv, argc, "ipv4", index)) {
288 ret = 1;
289 if (afi)
290 *afi = AFI_IP;
291 } else if (argv_find(argv, argc, "ipv6", index)) {
292 ret = 1;
293 if (afi)
294 *afi = AFI_IP6;
8688b3e7
DS
295 } else if (argv_find(argv, argc, "l2vpn", index)) {
296 ret = 1;
297 if (afi)
298 *afi = AFI_L2VPN;
d62a17ae 299 }
300 return ret;
46f296b4
LB
301}
302
375a2e67 303/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 304safi_t bgp_vty_safi_from_str(const char *safi_str)
305{
306 safi_t safi = SAFI_MAX; /* unknown */
307 if (strmatch(safi_str, "multicast"))
308 safi = SAFI_MULTICAST;
309 else if (strmatch(safi_str, "unicast"))
310 safi = SAFI_UNICAST;
311 else if (strmatch(safi_str, "vpn"))
312 safi = SAFI_MPLS_VPN;
81cf0de5
CS
313 else if (strmatch(safi_str, "evpn"))
314 safi = SAFI_EVPN;
d62a17ae 315 else if (strmatch(safi_str, "labeled-unicast"))
316 safi = SAFI_LABELED_UNICAST;
7c40bf39 317 else if (strmatch(safi_str, "flowspec"))
318 safi = SAFI_FLOWSPEC;
d62a17ae 319 return safi;
320}
321
322int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
323 safi_t *safi)
324{
325 int ret = 0;
326 if (argv_find(argv, argc, "unicast", index)) {
327 ret = 1;
328 if (safi)
329 *safi = SAFI_UNICAST;
330 } else if (argv_find(argv, argc, "multicast", index)) {
331 ret = 1;
332 if (safi)
333 *safi = SAFI_MULTICAST;
334 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
335 ret = 1;
336 if (safi)
337 *safi = SAFI_LABELED_UNICAST;
338 } else if (argv_find(argv, argc, "vpn", index)) {
339 ret = 1;
340 if (safi)
341 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
342 } else if (argv_find(argv, argc, "evpn", index)) {
343 ret = 1;
344 if (safi)
345 *safi = SAFI_EVPN;
7c40bf39 346 } else if (argv_find(argv, argc, "flowspec", index)) {
347 ret = 1;
348 if (safi)
349 *safi = SAFI_FLOWSPEC;
d62a17ae 350 }
351 return ret;
46f296b4
LB
352}
353
7eeee51e 354/*
f212a857 355 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 356 *
f212a857
DS
357 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
358 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
359 * to appropriate values for the calling function. This is to allow the
360 * calling function to make decisions appropriate for the show command
361 * that is being parsed.
362 *
363 * The show commands are generally of the form:
d62a17ae 364 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
365 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
366 *
367 * Since we use argv_find if the show command in particular doesn't have:
368 * [ip]
18c57037 369 * [<view|vrf> VIEWVRFNAME]
375a2e67 370 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
371 * The command parsing should still be ok.
372 *
373 * vty -> The vty for the command so we can output some useful data in
374 * the event of a parse error in the vrf.
375 * argv -> The command tokens
376 * argc -> How many command tokens we have
d62a17ae 377 * idx -> The current place in the command, generally should be 0 for this
378 * function
7eeee51e
DS
379 * afi -> The parsed afi if it was included in the show command, returned here
380 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 381 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 382 * use_json -> json is configured or not
7eeee51e
DS
383 *
384 * The function returns the correct location in the parse tree for the
385 * last token found.
0e37c258
DS
386 *
387 * Returns 0 for failure to parse correctly, else the idx position of where
388 * it found the last token.
7eeee51e 389 */
d62a17ae 390int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
391 struct cmd_token **argv, int argc,
392 int *idx, afi_t *afi, safi_t *safi,
9f049418 393 struct bgp **bgp, bool use_json)
d62a17ae 394{
395 char *vrf_name = NULL;
396
397 assert(afi);
398 assert(safi);
399 assert(bgp);
400
401 if (argv_find(argv, argc, "ip", idx))
402 *afi = AFI_IP;
403
9a8bdf1c 404 if (argv_find(argv, argc, "view", idx))
d62a17ae 405 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
406 else if (argv_find(argv, argc, "vrf", idx)) {
407 vrf_name = argv[*idx + 1]->arg;
408 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
409 vrf_name = NULL;
410 }
411 if (vrf_name) {
d62a17ae 412 if (strmatch(vrf_name, "all"))
413 *bgp = NULL;
414 else {
415 *bgp = bgp_lookup_by_name(vrf_name);
416 if (!*bgp) {
52e5b8c4
SP
417 if (use_json) {
418 json_object *json = NULL;
419 json = json_object_new_object();
420 json_object_string_add(
421 json, "warning",
422 "View/Vrf is unknown");
423 vty_out(vty, "%s\n",
424 json_object_to_json_string_ext(json,
425 JSON_C_TO_STRING_PRETTY));
426 json_object_free(json);
427 }
ca61fd25
DS
428 else
429 vty_out(vty, "View/Vrf %s is unknown\n",
430 vrf_name);
d62a17ae 431 *idx = 0;
432 return 0;
433 }
434 }
435 } else {
436 *bgp = bgp_get_default();
437 if (!*bgp) {
52e5b8c4
SP
438 if (use_json) {
439 json_object *json = NULL;
440 json = json_object_new_object();
441 json_object_string_add(
442 json, "warning",
443 "Default BGP instance not found");
444 vty_out(vty, "%s\n",
445 json_object_to_json_string_ext(json,
446 JSON_C_TO_STRING_PRETTY));
447 json_object_free(json);
448 }
ca61fd25
DS
449 else
450 vty_out(vty,
451 "Default BGP instance not found\n");
d62a17ae 452 *idx = 0;
453 return 0;
454 }
455 }
456
457 if (argv_find_and_parse_afi(argv, argc, idx, afi))
458 argv_find_and_parse_safi(argv, argc, idx, safi);
459
460 *idx += 1;
461 return *idx;
462}
463
464static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
465{
466 struct interface *ifp = NULL;
467
468 if (su->sa.sa_family == AF_INET)
469 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
470 else if (su->sa.sa_family == AF_INET6)
471 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
472 su->sin6.sin6_scope_id,
473 bgp->vrf_id);
474
475 if (ifp)
476 return 1;
477
478 return 0;
718e3744 479}
480
481/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
482/* This is used only for configuration, so disallow if attempted on
483 * a dynamic neighbor.
484 */
d62a17ae 485static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
486{
487 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
488 int ret;
489 union sockunion su;
490 struct peer *peer;
491
492 if (!bgp) {
493 return NULL;
494 }
495
496 ret = str2sockunion(ip_str, &su);
497 if (ret < 0) {
498 peer = peer_lookup_by_conf_if(bgp, ip_str);
499 if (!peer) {
500 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
501 == NULL) {
502 vty_out(vty,
503 "%% Malformed address or name: %s\n",
504 ip_str);
505 return NULL;
506 }
507 }
508 } else {
509 peer = peer_lookup(bgp, &su);
510 if (!peer) {
511 vty_out(vty,
512 "%% Specify remote-as or peer-group commands first\n");
513 return NULL;
514 }
515 if (peer_dynamic_neighbor(peer)) {
516 vty_out(vty,
517 "%% Operation not allowed on a dynamic neighbor\n");
518 return NULL;
519 }
520 }
521 return peer;
718e3744 522}
523
524/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
525/* This is used only for configuration, so disallow if attempted on
526 * a dynamic neighbor.
527 */
d62a17ae 528struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
529{
530 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
531 int ret;
532 union sockunion su;
533 struct peer *peer = NULL;
534 struct peer_group *group = NULL;
535
536 if (!bgp) {
537 return NULL;
538 }
539
540 ret = str2sockunion(peer_str, &su);
541 if (ret == 0) {
542 /* IP address, locate peer. */
543 peer = peer_lookup(bgp, &su);
544 } else {
545 /* Not IP, could match either peer configured on interface or a
546 * group. */
547 peer = peer_lookup_by_conf_if(bgp, peer_str);
548 if (!peer)
549 group = peer_group_lookup(bgp, peer_str);
550 }
551
552 if (peer) {
553 if (peer_dynamic_neighbor(peer)) {
554 vty_out(vty,
555 "%% Operation not allowed on a dynamic neighbor\n");
556 return NULL;
557 }
558
559 return peer;
560 }
561
562 if (group)
563 return group->conf;
564
565 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
566
567 return NULL;
568}
569
570int bgp_vty_return(struct vty *vty, int ret)
571{
572 const char *str = NULL;
573
574 switch (ret) {
575 case BGP_ERR_INVALID_VALUE:
576 str = "Invalid value";
577 break;
578 case BGP_ERR_INVALID_FLAG:
579 str = "Invalid flag";
580 break;
581 case BGP_ERR_PEER_GROUP_SHUTDOWN:
582 str = "Peer-group has been shutdown. Activate the peer-group first";
583 break;
584 case BGP_ERR_PEER_FLAG_CONFLICT:
585 str = "Can't set override-capability and strict-capability-match at the same time";
586 break;
587 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
588 str = "Specify remote-as or peer-group remote AS first";
589 break;
590 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
591 str = "Cannot change the peer-group. Deconfigure first";
592 break;
593 case BGP_ERR_PEER_GROUP_MISMATCH:
594 str = "Peer is not a member of this peer-group";
595 break;
596 case BGP_ERR_PEER_FILTER_CONFLICT:
597 str = "Prefix/distribute list can not co-exist";
598 break;
599 case BGP_ERR_NOT_INTERNAL_PEER:
600 str = "Invalid command. Not an internal neighbor";
601 break;
602 case BGP_ERR_REMOVE_PRIVATE_AS:
603 str = "remove-private-AS cannot be configured for IBGP peers";
604 break;
605 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
606 str = "Local-AS allowed only for EBGP peers";
607 break;
608 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
609 str = "Cannot have local-as same as BGP AS number";
610 break;
611 case BGP_ERR_TCPSIG_FAILED:
612 str = "Error while applying TCP-Sig to session(s)";
613 break;
614 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
615 str = "ebgp-multihop and ttl-security cannot be configured together";
616 break;
617 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
618 str = "ttl-security only allowed for EBGP peers";
619 break;
620 case BGP_ERR_AS_OVERRIDE:
621 str = "as-override cannot be configured for IBGP peers";
622 break;
623 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
624 str = "Invalid limit for number of dynamic neighbors";
625 break;
626 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
627 str = "Dynamic neighbor listen range already exists";
628 break;
629 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
630 str = "Operation not allowed on a dynamic neighbor";
631 break;
632 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
633 str = "Operation not allowed on a directly connected neighbor";
634 break;
635 case BGP_ERR_PEER_SAFI_CONFLICT:
636 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
637 break;
638 }
639 if (str) {
640 vty_out(vty, "%% %s\n", str);
641 return CMD_WARNING_CONFIG_FAILED;
642 }
643 return CMD_SUCCESS;
718e3744 644}
645
7aafcaca 646/* BGP clear sort. */
d62a17ae 647enum clear_sort {
648 clear_all,
649 clear_peer,
650 clear_group,
651 clear_external,
652 clear_as
7aafcaca
DS
653};
654
d62a17ae 655static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
656 safi_t safi, int error)
657{
658 switch (error) {
659 case BGP_ERR_AF_UNCONFIGURED:
660 vty_out(vty,
661 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 662 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 663 break;
664 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
665 vty_out(vty,
666 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
667 peer->host);
668 break;
669 default:
670 break;
671 }
7aafcaca
DS
672}
673
dc912615
DS
674static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
675 struct listnode *nnode, enum bgp_clear_type stype)
676{
677 int ret = 0;
678
679 /* if afi/.safi not specified, spin thru all of them */
680 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
681 afi_t tmp_afi;
682 safi_t tmp_safi;
683
684 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
685 if (!peer->afc[tmp_afi][tmp_safi])
686 continue;
687
688 if (stype == BGP_CLEAR_SOFT_NONE)
689 ret = peer_clear(peer, &nnode);
690 else
691 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
692 stype);
693 }
694 /* if afi specified and safi not, spin thru safis on this afi */
695 } else if (safi == SAFI_UNSPEC) {
696 safi_t tmp_safi;
697
698 for (tmp_safi = SAFI_UNICAST;
699 tmp_safi < SAFI_MAX; tmp_safi++) {
700 if (!peer->afc[afi][tmp_safi])
701 continue;
702
703 if (stype == BGP_CLEAR_SOFT_NONE)
704 ret = peer_clear(peer, &nnode);
705 else
706 ret = peer_clear_soft(peer, afi,
707 tmp_safi, stype);
708 }
709 /* both afi/safi specified, let the caller know if not defined */
710 } else {
711 if (!peer->afc[afi][safi])
712 return 1;
713
714 if (stype == BGP_CLEAR_SOFT_NONE)
715 ret = peer_clear(peer, &nnode);
716 else
717 ret = peer_clear_soft(peer, afi, safi, stype);
718 }
719
720 return ret;
721}
722
7aafcaca 723/* `clear ip bgp' functions. */
d62a17ae 724static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
725 enum clear_sort sort, enum bgp_clear_type stype,
726 const char *arg)
727{
dc912615 728 int ret = 0;
3ae8bfa5 729 bool found = false;
d62a17ae 730 struct peer *peer;
731 struct listnode *node, *nnode;
732
733 /* Clear all neighbors. */
734 /*
735 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
736 * nodes on the BGP instance as that may get freed if it is a
737 * doppelganger
d62a17ae 738 */
739 if (sort == clear_all) {
740 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc912615
DS
741 ret = bgp_peer_clear(peer, afi, safi, nnode,
742 stype);
d62a17ae 743
744 if (ret < 0)
745 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 746 }
d62a17ae 747
748 /* This is to apply read-only mode on this clear. */
749 if (stype == BGP_CLEAR_SOFT_NONE)
750 bgp->update_delay_over = 0;
751
752 return CMD_SUCCESS;
7aafcaca
DS
753 }
754
3ae8bfa5 755 /* Clear specified neighbor. */
d62a17ae 756 if (sort == clear_peer) {
757 union sockunion su;
d62a17ae 758
759 /* Make sockunion for lookup. */
760 ret = str2sockunion(arg, &su);
761 if (ret < 0) {
762 peer = peer_lookup_by_conf_if(bgp, arg);
763 if (!peer) {
764 peer = peer_lookup_by_hostname(bgp, arg);
765 if (!peer) {
766 vty_out(vty,
767 "Malformed address or name: %s\n",
768 arg);
769 return CMD_WARNING;
770 }
771 }
772 } else {
773 peer = peer_lookup(bgp, &su);
774 if (!peer) {
775 vty_out(vty,
776 "%%BGP: Unknown neighbor - \"%s\"\n",
777 arg);
778 return CMD_WARNING;
779 }
780 }
7aafcaca 781
dc912615
DS
782 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
783
784 /* if afi/safi not defined for this peer, let caller know */
785 if (ret == 1)
3ae8bfa5 786 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 787
d62a17ae 788 if (ret < 0)
789 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 790
d62a17ae 791 return CMD_SUCCESS;
7aafcaca 792 }
7aafcaca 793
3ae8bfa5 794 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 795 if (sort == clear_group) {
796 struct peer_group *group;
7aafcaca 797
d62a17ae 798 group = peer_group_lookup(bgp, arg);
799 if (!group) {
800 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
801 return CMD_WARNING;
802 }
803
804 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
dc912615 805 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 806
d62a17ae 807 if (ret < 0)
808 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
809 else
810 found = true;
d62a17ae 811 }
3ae8bfa5
PM
812
813 if (!found)
814 vty_out(vty,
815 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 816 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 817
d62a17ae 818 return CMD_SUCCESS;
7aafcaca 819 }
7aafcaca 820
3ae8bfa5 821 /* Clear all external (eBGP) neighbors. */
d62a17ae 822 if (sort == clear_external) {
823 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
824 if (peer->sort == BGP_PEER_IBGP)
825 continue;
7aafcaca 826
dc912615 827 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 828
d62a17ae 829 if (ret < 0)
830 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
831 else
832 found = true;
d62a17ae 833 }
3ae8bfa5
PM
834
835 if (!found)
836 vty_out(vty,
837 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 838 get_afi_safi_str(afi, safi, false));
3ae8bfa5 839
d62a17ae 840 return CMD_SUCCESS;
841 }
842
3ae8bfa5 843 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 844 if (sort == clear_as) {
3ae8bfa5 845 as_t as = strtoul(arg, NULL, 10);
d62a17ae 846
847 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
848 if (peer->as != as)
849 continue;
850
dc912615 851 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
d62a17ae 852
853 if (ret < 0)
854 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
855 else
856 found = true;
d62a17ae 857 }
3ae8bfa5
PM
858
859 if (!found)
d62a17ae 860 vty_out(vty,
3ae8bfa5 861 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 862 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 863
d62a17ae 864 return CMD_SUCCESS;
865 }
866
867 return CMD_SUCCESS;
868}
869
870static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
871 safi_t safi, enum clear_sort sort,
872 enum bgp_clear_type stype, const char *arg)
873{
874 struct bgp *bgp;
875
876 /* BGP structure lookup. */
877 if (name) {
878 bgp = bgp_lookup_by_name(name);
879 if (bgp == NULL) {
880 vty_out(vty, "Can't find BGP instance %s\n", name);
881 return CMD_WARNING;
882 }
883 } else {
884 bgp = bgp_get_default();
885 if (bgp == NULL) {
886 vty_out(vty, "No BGP process is configured\n");
887 return CMD_WARNING;
888 }
889 }
890
891 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
892}
893
894/* clear soft inbound */
d62a17ae 895static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 896{
99b3ebd3
NS
897 afi_t afi;
898 safi_t safi;
899
900 FOREACH_AFI_SAFI (afi, safi)
901 bgp_clear_vty(vty, name, afi, safi, clear_all,
902 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
903}
904
905/* clear soft outbound */
d62a17ae 906static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 907{
99b3ebd3
NS
908 afi_t afi;
909 safi_t safi;
910
911 FOREACH_AFI_SAFI (afi, safi)
912 bgp_clear_vty(vty, name, afi, safi, clear_all,
913 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
914}
915
916
f787d7a0 917#ifndef VTYSH_EXTRACT_PL
2e4c2296 918#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
919#endif
920
8029b216
AK
921DEFUN_HIDDEN (bgp_local_mac,
922 bgp_local_mac_cmd,
093e3f23 923 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
924 BGP_STR
925 "Local MAC config\n"
926 "VxLAN Network Identifier\n"
927 "VNI number\n"
928 "local mac\n"
929 "mac address\n"
930 "mac-mobility sequence\n"
931 "seq number\n")
932{
933 int rv;
934 vni_t vni;
935 struct ethaddr mac;
936 struct ipaddr ip;
937 uint32_t seq;
938 struct bgp *bgp;
939
940 vni = strtoul(argv[3]->arg, NULL, 10);
941 if (!prefix_str2mac(argv[5]->arg, &mac)) {
942 vty_out(vty, "%% Malformed MAC address\n");
943 return CMD_WARNING;
944 }
945 memset(&ip, 0, sizeof(ip));
946 seq = strtoul(argv[7]->arg, NULL, 10);
947
948 bgp = bgp_get_default();
949 if (!bgp) {
950 vty_out(vty, "Default BGP instance is not there\n");
951 return CMD_WARNING;
952 }
953
954 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
955 if (rv < 0) {
956 vty_out(vty, "Internal error\n");
957 return CMD_WARNING;
958 }
959
960 return CMD_SUCCESS;
961}
962
963DEFUN_HIDDEN (no_bgp_local_mac,
964 no_bgp_local_mac_cmd,
093e3f23 965 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
966 NO_STR
967 BGP_STR
968 "Local MAC config\n"
969 "VxLAN Network Identifier\n"
970 "VNI number\n"
971 "local mac\n"
972 "mac address\n")
973{
974 int rv;
975 vni_t vni;
976 struct ethaddr mac;
977 struct ipaddr ip;
978 struct bgp *bgp;
979
980 vni = strtoul(argv[4]->arg, NULL, 10);
981 if (!prefix_str2mac(argv[6]->arg, &mac)) {
982 vty_out(vty, "%% Malformed MAC address\n");
983 return CMD_WARNING;
984 }
985 memset(&ip, 0, sizeof(ip));
986
987 bgp = bgp_get_default();
988 if (!bgp) {
989 vty_out(vty, "Default BGP instance is not there\n");
990 return CMD_WARNING;
991 }
992
ec0ab544 993 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
994 if (rv < 0) {
995 vty_out(vty, "Internal error\n");
996 return CMD_WARNING;
997 }
998
999 return CMD_SUCCESS;
1000}
1001
718e3744 1002DEFUN (no_synchronization,
1003 no_synchronization_cmd,
1004 "no synchronization",
1005 NO_STR
1006 "Perform IGP synchronization\n")
1007{
d62a17ae 1008 return CMD_SUCCESS;
718e3744 1009}
1010
1011DEFUN (no_auto_summary,
1012 no_auto_summary_cmd,
1013 "no auto-summary",
1014 NO_STR
1015 "Enable automatic network number summarization\n")
1016{
d62a17ae 1017 return CMD_SUCCESS;
718e3744 1018}
3d515fd9 1019
718e3744 1020/* "router bgp" commands. */
505e5056 1021DEFUN_NOSH (router_bgp,
f412b39a 1022 router_bgp_cmd,
2ed9fe4a 1023 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1024 ROUTER_STR
1025 BGP_STR
31500417
DW
1026 AS_STR
1027 BGP_INSTANCE_HELP_STR)
718e3744 1028{
d62a17ae 1029 int idx_asn = 2;
1030 int idx_view_vrf = 3;
1031 int idx_vrf = 4;
ecec9495 1032 int is_new_bgp = 0;
d62a17ae 1033 int ret;
1034 as_t as;
1035 struct bgp *bgp;
1036 const char *name = NULL;
1037 enum bgp_instance_type inst_type;
1038
1039 // "router bgp" without an ASN
1040 if (argc == 2) {
1041 // Pending: Make VRF option available for ASN less config
1042 bgp = bgp_get_default();
1043
1044 if (bgp == NULL) {
1045 vty_out(vty, "%% No BGP process is configured\n");
1046 return CMD_WARNING_CONFIG_FAILED;
1047 }
1048
1049 if (listcount(bm->bgp) > 1) {
996c9314 1050 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1051 return CMD_WARNING_CONFIG_FAILED;
1052 }
1053 }
1054
1055 // "router bgp X"
1056 else {
1057 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1058
1059 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1060 if (argc > 3) {
1061 name = argv[idx_vrf]->arg;
1062
9a8bdf1c
PG
1063 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1064 if (strmatch(name, VRF_DEFAULT_NAME))
1065 name = NULL;
1066 else
1067 inst_type = BGP_INSTANCE_TYPE_VRF;
1068 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1069 inst_type = BGP_INSTANCE_TYPE_VIEW;
1070 }
1071
ecec9495
AD
1072 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1073 is_new_bgp = (bgp_lookup(as, name) == NULL);
1074
d62a17ae 1075 ret = bgp_get(&bgp, &as, name, inst_type);
1076 switch (ret) {
d62a17ae 1077 case BGP_ERR_AS_MISMATCH:
1078 vty_out(vty, "BGP is already running; AS is %u\n", as);
1079 return CMD_WARNING_CONFIG_FAILED;
1080 case BGP_ERR_INSTANCE_MISMATCH:
1081 vty_out(vty,
1082 "BGP instance name and AS number mismatch\n");
1083 vty_out(vty,
1084 "BGP instance is already running; AS is %u\n",
1085 as);
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
3bd70bf8
PZ
1089 /*
1090 * If we just instantiated the default instance, complete
1091 * any pending VRF-VPN leaking that was configured via
1092 * earlier "router bgp X vrf FOO" blocks.
1093 */
ecec9495 1094 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1095 vpn_leak_postchange_all();
1096
48381346
CS
1097 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1098 bgp_vpn_leak_export(bgp);
d62a17ae 1099 /* Pending: handle when user tries to change a view to vrf n vv.
1100 */
1101 }
1102
0b5131c9
MK
1103 /* unset the auto created flag as the user config is now present */
1104 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1105 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1106
1107 return CMD_SUCCESS;
718e3744 1108}
1109
718e3744 1110/* "no router bgp" commands. */
1111DEFUN (no_router_bgp,
1112 no_router_bgp_cmd,
2ed9fe4a 1113 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1114 NO_STR
1115 ROUTER_STR
1116 BGP_STR
31500417
DW
1117 AS_STR
1118 BGP_INSTANCE_HELP_STR)
718e3744 1119{
d62a17ae 1120 int idx_asn = 3;
1121 int idx_vrf = 5;
1122 as_t as;
1123 struct bgp *bgp;
1124 const char *name = NULL;
718e3744 1125
d62a17ae 1126 // "no router bgp" without an ASN
1127 if (argc == 3) {
1128 // Pending: Make VRF option available for ASN less config
1129 bgp = bgp_get_default();
718e3744 1130
d62a17ae 1131 if (bgp == NULL) {
1132 vty_out(vty, "%% No BGP process is configured\n");
1133 return CMD_WARNING_CONFIG_FAILED;
1134 }
7fb21a9f 1135
d62a17ae 1136 if (listcount(bm->bgp) > 1) {
996c9314 1137 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1138 return CMD_WARNING_CONFIG_FAILED;
1139 }
0b5131c9
MK
1140
1141 if (bgp->l3vni) {
1142 vty_out(vty, "%% Please unconfigure l3vni %u",
1143 bgp->l3vni);
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
d62a17ae 1146 } else {
1147 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1148
d62a17ae 1149 if (argc > 4)
1150 name = argv[idx_vrf]->arg;
7fb21a9f 1151
d62a17ae 1152 /* Lookup bgp structure. */
1153 bgp = bgp_lookup(as, name);
1154 if (!bgp) {
1155 vty_out(vty, "%% Can't find BGP instance\n");
1156 return CMD_WARNING_CONFIG_FAILED;
1157 }
0b5131c9
MK
1158
1159 if (bgp->l3vni) {
dd5868c2 1160 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1161 bgp->l3vni);
1162 return CMD_WARNING_CONFIG_FAILED;
1163 }
dd5868c2
DS
1164
1165 /* Cannot delete default instance if vrf instances exist */
1166 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1167 struct listnode *node;
1168 struct bgp *tmp_bgp;
1169
1170 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1171 if (tmp_bgp->inst_type
1172 == BGP_INSTANCE_TYPE_VRF) {
1173 vty_out(vty,
1174 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1175 return CMD_WARNING_CONFIG_FAILED;
1176 }
1177 }
1178 }
d62a17ae 1179 }
718e3744 1180
9ecf931b
CS
1181 if (bgp_vpn_leak_unimport(bgp, vty))
1182 return CMD_WARNING_CONFIG_FAILED;
1183
d62a17ae 1184 bgp_delete(bgp);
718e3744 1185
d62a17ae 1186 return CMD_SUCCESS;
718e3744 1187}
1188
6b0655a2 1189
718e3744 1190/* BGP router-id. */
1191
f787d7a0 1192DEFPY (bgp_router_id,
718e3744 1193 bgp_router_id_cmd,
1194 "bgp router-id A.B.C.D",
1195 BGP_STR
1196 "Override configured router identifier\n"
1197 "Manually configured router identifier\n")
1198{
d62a17ae 1199 VTY_DECLVAR_CONTEXT(bgp, bgp);
1200 bgp_router_id_static_set(bgp, router_id);
1201 return CMD_SUCCESS;
718e3744 1202}
1203
f787d7a0 1204DEFPY (no_bgp_router_id,
718e3744 1205 no_bgp_router_id_cmd,
31500417 1206 "no bgp router-id [A.B.C.D]",
718e3744 1207 NO_STR
1208 BGP_STR
31500417
DW
1209 "Override configured router identifier\n"
1210 "Manually configured router identifier\n")
718e3744 1211{
d62a17ae 1212 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1213
d62a17ae 1214 if (router_id_str) {
1215 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1216 vty_out(vty, "%% BGP router-id doesn't match\n");
1217 return CMD_WARNING_CONFIG_FAILED;
1218 }
e018c7cc 1219 }
718e3744 1220
d62a17ae 1221 router_id.s_addr = 0;
1222 bgp_router_id_static_set(bgp, router_id);
718e3744 1223
d62a17ae 1224 return CMD_SUCCESS;
718e3744 1225}
1226
6b0655a2 1227
718e3744 1228/* BGP Cluster ID. */
718e3744 1229DEFUN (bgp_cluster_id,
1230 bgp_cluster_id_cmd,
838758ac 1231 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1232 BGP_STR
1233 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1234 "Route-Reflector Cluster-id in IP address format\n"
1235 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1236{
d62a17ae 1237 VTY_DECLVAR_CONTEXT(bgp, bgp);
1238 int idx_ipv4 = 2;
1239 int ret;
1240 struct in_addr cluster;
718e3744 1241
d62a17ae 1242 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1243 if (!ret) {
1244 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1245 return CMD_WARNING_CONFIG_FAILED;
1246 }
718e3744 1247
d62a17ae 1248 bgp_cluster_id_set(bgp, &cluster);
1249 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1250
d62a17ae 1251 return CMD_SUCCESS;
718e3744 1252}
1253
718e3744 1254DEFUN (no_bgp_cluster_id,
1255 no_bgp_cluster_id_cmd,
c7178fe7 1256 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1257 NO_STR
1258 BGP_STR
838758ac
DW
1259 "Configure Route-Reflector Cluster-id\n"
1260 "Route-Reflector Cluster-id in IP address format\n"
1261 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1262{
d62a17ae 1263 VTY_DECLVAR_CONTEXT(bgp, bgp);
1264 bgp_cluster_id_unset(bgp);
1265 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1266
d62a17ae 1267 return CMD_SUCCESS;
718e3744 1268}
1269
718e3744 1270DEFUN (bgp_confederation_identifier,
1271 bgp_confederation_identifier_cmd,
9ccf14f7 1272 "bgp confederation identifier (1-4294967295)",
718e3744 1273 "BGP specific commands\n"
1274 "AS confederation parameters\n"
1275 "AS number\n"
1276 "Set routing domain confederation AS\n")
1277{
d62a17ae 1278 VTY_DECLVAR_CONTEXT(bgp, bgp);
1279 int idx_number = 3;
1280 as_t as;
718e3744 1281
d62a17ae 1282 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1283
d62a17ae 1284 bgp_confederation_id_set(bgp, as);
718e3744 1285
d62a17ae 1286 return CMD_SUCCESS;
718e3744 1287}
1288
1289DEFUN (no_bgp_confederation_identifier,
1290 no_bgp_confederation_identifier_cmd,
838758ac 1291 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1292 NO_STR
1293 "BGP specific commands\n"
1294 "AS confederation parameters\n"
3a2d747c
QY
1295 "AS number\n"
1296 "Set routing domain confederation AS\n")
718e3744 1297{
d62a17ae 1298 VTY_DECLVAR_CONTEXT(bgp, bgp);
1299 bgp_confederation_id_unset(bgp);
718e3744 1300
d62a17ae 1301 return CMD_SUCCESS;
718e3744 1302}
1303
718e3744 1304DEFUN (bgp_confederation_peers,
1305 bgp_confederation_peers_cmd,
12dcf78e 1306 "bgp confederation peers (1-4294967295)...",
718e3744 1307 "BGP specific commands\n"
1308 "AS confederation parameters\n"
1309 "Peer ASs in BGP confederation\n"
1310 AS_STR)
1311{
d62a17ae 1312 VTY_DECLVAR_CONTEXT(bgp, bgp);
1313 int idx_asn = 3;
1314 as_t as;
1315 int i;
718e3744 1316
d62a17ae 1317 for (i = idx_asn; i < argc; i++) {
1318 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1319
d62a17ae 1320 if (bgp->as == as) {
1321 vty_out(vty,
1322 "%% Local member-AS not allowed in confed peer list\n");
1323 continue;
1324 }
718e3744 1325
d62a17ae 1326 bgp_confederation_peers_add(bgp, as);
1327 }
1328 return CMD_SUCCESS;
718e3744 1329}
1330
1331DEFUN (no_bgp_confederation_peers,
1332 no_bgp_confederation_peers_cmd,
e83a9414 1333 "no bgp confederation peers (1-4294967295)...",
718e3744 1334 NO_STR
1335 "BGP specific commands\n"
1336 "AS confederation parameters\n"
1337 "Peer ASs in BGP confederation\n"
1338 AS_STR)
1339{
d62a17ae 1340 VTY_DECLVAR_CONTEXT(bgp, bgp);
1341 int idx_asn = 4;
1342 as_t as;
1343 int i;
718e3744 1344
d62a17ae 1345 for (i = idx_asn; i < argc; i++) {
1346 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1347
d62a17ae 1348 bgp_confederation_peers_remove(bgp, as);
1349 }
1350 return CMD_SUCCESS;
718e3744 1351}
6b0655a2 1352
5e242b0d
DS
1353/**
1354 * Central routine for maximum-paths configuration.
1355 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1356 * @set: 1 for setting values, 0 for removing the max-paths config.
1357 */
d62a17ae 1358static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1359 const char *mpaths, uint16_t options,
d62a17ae 1360 int set)
1361{
1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1363 uint16_t maxpaths = 0;
d62a17ae 1364 int ret;
1365 afi_t afi;
1366 safi_t safi;
1367
1368 afi = bgp_node_afi(vty);
1369 safi = bgp_node_safi(vty);
1370
1371 if (set) {
1372 maxpaths = strtol(mpaths, NULL, 10);
1373 if (maxpaths > multipath_num) {
1374 vty_out(vty,
1375 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1376 maxpaths, multipath_num);
1377 return CMD_WARNING_CONFIG_FAILED;
1378 }
1379 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1380 options);
1381 } else
1382 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1383
1384 if (ret < 0) {
1385 vty_out(vty,
1386 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1387 (set == 1) ? "" : "un",
1388 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1389 maxpaths, afi, safi);
1390 return CMD_WARNING_CONFIG_FAILED;
1391 }
1392
1393 bgp_recalculate_all_bestpaths(bgp);
1394
1395 return CMD_SUCCESS;
165b5fff
JB
1396}
1397
abc920f8
DS
1398DEFUN (bgp_maxmed_admin,
1399 bgp_maxmed_admin_cmd,
1400 "bgp max-med administrative ",
1401 BGP_STR
1402 "Advertise routes with max-med\n"
1403 "Administratively applied, for an indefinite period\n")
1404{
d62a17ae 1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1406
d62a17ae 1407 bgp->v_maxmed_admin = 1;
1408 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1409
d62a17ae 1410 bgp_maxmed_update(bgp);
abc920f8 1411
d62a17ae 1412 return CMD_SUCCESS;
abc920f8
DS
1413}
1414
1415DEFUN (bgp_maxmed_admin_medv,
1416 bgp_maxmed_admin_medv_cmd,
4668a151 1417 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1418 BGP_STR
1419 "Advertise routes with max-med\n"
1420 "Administratively applied, for an indefinite period\n"
1421 "Max MED value to be used\n")
1422{
d62a17ae 1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424 int idx_number = 3;
abc920f8 1425
d62a17ae 1426 bgp->v_maxmed_admin = 1;
1427 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1428
d62a17ae 1429 bgp_maxmed_update(bgp);
abc920f8 1430
d62a17ae 1431 return CMD_SUCCESS;
abc920f8
DS
1432}
1433
1434DEFUN (no_bgp_maxmed_admin,
1435 no_bgp_maxmed_admin_cmd,
4668a151 1436 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1437 NO_STR
1438 BGP_STR
1439 "Advertise routes with max-med\n"
838758ac
DW
1440 "Administratively applied, for an indefinite period\n"
1441 "Max MED value to be used\n")
abc920f8 1442{
d62a17ae 1443 VTY_DECLVAR_CONTEXT(bgp, bgp);
1444 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1445 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1446 bgp_maxmed_update(bgp);
abc920f8 1447
d62a17ae 1448 return CMD_SUCCESS;
abc920f8
DS
1449}
1450
abc920f8
DS
1451DEFUN (bgp_maxmed_onstartup,
1452 bgp_maxmed_onstartup_cmd,
4668a151 1453 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1454 BGP_STR
1455 "Advertise routes with max-med\n"
1456 "Effective on a startup\n"
1457 "Time (seconds) period for max-med\n"
1458 "Max MED value to be used\n")
1459{
d62a17ae 1460 VTY_DECLVAR_CONTEXT(bgp, bgp);
1461 int idx = 0;
4668a151 1462
d62a17ae 1463 argv_find(argv, argc, "(5-86400)", &idx);
1464 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1465 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1466 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1467 else
1468 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1469
d62a17ae 1470 bgp_maxmed_update(bgp);
abc920f8 1471
d62a17ae 1472 return CMD_SUCCESS;
abc920f8
DS
1473}
1474
1475DEFUN (no_bgp_maxmed_onstartup,
1476 no_bgp_maxmed_onstartup_cmd,
4668a151 1477 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1478 NO_STR
1479 BGP_STR
1480 "Advertise routes with max-med\n"
838758ac
DW
1481 "Effective on a startup\n"
1482 "Time (seconds) period for max-med\n"
1483 "Max MED value to be used\n")
abc920f8 1484{
d62a17ae 1485 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1486
d62a17ae 1487 /* Cancel max-med onstartup if its on */
1488 if (bgp->t_maxmed_onstartup) {
1489 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1490 bgp->maxmed_onstartup_over = 1;
1491 }
abc920f8 1492
d62a17ae 1493 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1494 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1495
d62a17ae 1496 bgp_maxmed_update(bgp);
abc920f8 1497
d62a17ae 1498 return CMD_SUCCESS;
abc920f8
DS
1499}
1500
d62a17ae 1501static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1502 const char *wait)
f188f2c4 1503{
d62a17ae 1504 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1505 uint16_t update_delay;
1506 uint16_t establish_wait;
f188f2c4 1507
d62a17ae 1508 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1509
d62a17ae 1510 if (!wait) /* update-delay <delay> */
1511 {
1512 bgp->v_update_delay = update_delay;
1513 bgp->v_establish_wait = bgp->v_update_delay;
1514 return CMD_SUCCESS;
1515 }
f188f2c4 1516
d62a17ae 1517 /* update-delay <delay> <establish-wait> */
1518 establish_wait = atoi(wait);
1519 if (update_delay < establish_wait) {
1520 vty_out(vty,
1521 "%%Failed: update-delay less than the establish-wait!\n");
1522 return CMD_WARNING_CONFIG_FAILED;
1523 }
f188f2c4 1524
d62a17ae 1525 bgp->v_update_delay = update_delay;
1526 bgp->v_establish_wait = establish_wait;
f188f2c4 1527
d62a17ae 1528 return CMD_SUCCESS;
f188f2c4
DS
1529}
1530
d62a17ae 1531static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1532{
d62a17ae 1533 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1534
d62a17ae 1535 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1536 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1537
d62a17ae 1538 return CMD_SUCCESS;
f188f2c4
DS
1539}
1540
2b791107 1541void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1542{
d62a17ae 1543 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1544 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1545 if (bgp->v_update_delay != bgp->v_establish_wait)
1546 vty_out(vty, " %d", bgp->v_establish_wait);
1547 vty_out(vty, "\n");
1548 }
f188f2c4
DS
1549}
1550
1551
1552/* Update-delay configuration */
1553DEFUN (bgp_update_delay,
1554 bgp_update_delay_cmd,
6147e2c6 1555 "update-delay (0-3600)",
f188f2c4
DS
1556 "Force initial delay for best-path and updates\n"
1557 "Seconds\n")
1558{
d62a17ae 1559 int idx_number = 1;
1560 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1561}
1562
1563DEFUN (bgp_update_delay_establish_wait,
1564 bgp_update_delay_establish_wait_cmd,
6147e2c6 1565 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1566 "Force initial delay for best-path and updates\n"
1567 "Seconds\n"
f188f2c4
DS
1568 "Seconds\n")
1569{
d62a17ae 1570 int idx_number = 1;
1571 int idx_number_2 = 2;
1572 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1573 argv[idx_number_2]->arg);
f188f2c4
DS
1574}
1575
1576/* Update-delay deconfiguration */
1577DEFUN (no_bgp_update_delay,
1578 no_bgp_update_delay_cmd,
838758ac
DW
1579 "no update-delay [(0-3600) [(1-3600)]]",
1580 NO_STR
f188f2c4 1581 "Force initial delay for best-path and updates\n"
838758ac 1582 "Seconds\n"
7111c1a0 1583 "Seconds\n")
f188f2c4 1584{
d62a17ae 1585 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1586}
1587
5e242b0d 1588
d62a17ae 1589static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1590 char set)
cb1faec9 1591{
d62a17ae 1592 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1593
555e09d4
QY
1594 if (set) {
1595 uint32_t quanta = strtoul(num, NULL, 10);
1596 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1597 memory_order_relaxed);
1598 } else {
1599 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1600 memory_order_relaxed);
1601 }
1602
1603 return CMD_SUCCESS;
1604}
1605
1606static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1607 char set)
1608{
1609 VTY_DECLVAR_CONTEXT(bgp, bgp);
1610
1611 if (set) {
1612 uint32_t quanta = strtoul(num, NULL, 10);
1613 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1614 memory_order_relaxed);
1615 } else {
1616 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1617 memory_order_relaxed);
1618 }
cb1faec9 1619
d62a17ae 1620 return CMD_SUCCESS;
cb1faec9
DS
1621}
1622
2b791107 1623void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1624{
555e09d4
QY
1625 uint32_t quanta =
1626 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1627 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1628 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1629}
1630
555e09d4
QY
1631void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1632{
1633 uint32_t quanta =
1634 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1635 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1636 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1637}
cb1faec9 1638
555e09d4 1639/* Packet quanta configuration */
cb1faec9
DS
1640DEFUN (bgp_wpkt_quanta,
1641 bgp_wpkt_quanta_cmd,
555e09d4 1642 "write-quanta (1-10)",
cb1faec9
DS
1643 "How many packets to write to peer socket per run\n"
1644 "Number of packets\n")
1645{
d62a17ae 1646 int idx_number = 1;
1647 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1648}
1649
cb1faec9
DS
1650DEFUN (no_bgp_wpkt_quanta,
1651 no_bgp_wpkt_quanta_cmd,
555e09d4 1652 "no write-quanta (1-10)",
d7fa34c1 1653 NO_STR
555e09d4 1654 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1655 "Number of packets\n")
1656{
d62a17ae 1657 int idx_number = 2;
1658 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1659}
1660
555e09d4
QY
1661DEFUN (bgp_rpkt_quanta,
1662 bgp_rpkt_quanta_cmd,
1663 "read-quanta (1-10)",
1664 "How many packets to read from peer socket per I/O cycle\n"
1665 "Number of packets\n")
1666{
1667 int idx_number = 1;
1668 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1669}
1670
1671DEFUN (no_bgp_rpkt_quanta,
1672 no_bgp_rpkt_quanta_cmd,
1673 "no read-quanta (1-10)",
1674 NO_STR
1675 "How many packets to read from peer socket per I/O cycle\n"
1676 "Number of packets\n")
1677{
1678 int idx_number = 2;
1679 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1680}
1681
2b791107 1682void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1683{
37a333fe 1684 if (!bgp->heuristic_coalesce)
d62a17ae 1685 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1686}
1687
1688
1689DEFUN (bgp_coalesce_time,
1690 bgp_coalesce_time_cmd,
6147e2c6 1691 "coalesce-time (0-4294967295)",
3f9c7369
DS
1692 "Subgroup coalesce timer\n"
1693 "Subgroup coalesce timer value (in ms)\n")
1694{
d62a17ae 1695 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1696
d62a17ae 1697 int idx = 0;
1698 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1699 bgp->heuristic_coalesce = false;
d62a17ae 1700 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1701 return CMD_SUCCESS;
3f9c7369
DS
1702}
1703
1704DEFUN (no_bgp_coalesce_time,
1705 no_bgp_coalesce_time_cmd,
6147e2c6 1706 "no coalesce-time (0-4294967295)",
3a2d747c 1707 NO_STR
3f9c7369
DS
1708 "Subgroup coalesce timer\n"
1709 "Subgroup coalesce timer value (in ms)\n")
1710{
d62a17ae 1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1712
37a333fe 1713 bgp->heuristic_coalesce = true;
d62a17ae 1714 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1715 return CMD_SUCCESS;
3f9c7369
DS
1716}
1717
5e242b0d
DS
1718/* Maximum-paths configuration */
1719DEFUN (bgp_maxpaths,
1720 bgp_maxpaths_cmd,
6319fd63 1721 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1722 "Forward packets over multiple paths\n"
1723 "Number of paths\n")
1724{
d62a17ae 1725 int idx_number = 1;
1726 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1727 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1728}
1729
d62a17ae 1730ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1731 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1732 "Forward packets over multiple paths\n"
1733 "Number of paths\n")
596c17ba 1734
165b5fff
JB
1735DEFUN (bgp_maxpaths_ibgp,
1736 bgp_maxpaths_ibgp_cmd,
6319fd63 1737 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1738 "Forward packets over multiple paths\n"
1739 "iBGP-multipath\n"
1740 "Number of paths\n")
1741{
d62a17ae 1742 int idx_number = 2;
1743 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1744 argv[idx_number]->arg, 0, 1);
5e242b0d 1745}
165b5fff 1746
d62a17ae 1747ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1748 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1749 "Forward packets over multiple paths\n"
1750 "iBGP-multipath\n"
1751 "Number of paths\n")
596c17ba 1752
5e242b0d
DS
1753DEFUN (bgp_maxpaths_ibgp_cluster,
1754 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1755 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1756 "Forward packets over multiple paths\n"
1757 "iBGP-multipath\n"
1758 "Number of paths\n"
1759 "Match the cluster length\n")
1760{
d62a17ae 1761 int idx_number = 2;
1762 return bgp_maxpaths_config_vty(
1763 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1764 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1765}
1766
d62a17ae 1767ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1768 "maximum-paths ibgp " CMD_RANGE_STR(
1769 1, MULTIPATH_NUM) " equal-cluster-length",
1770 "Forward packets over multiple paths\n"
1771 "iBGP-multipath\n"
1772 "Number of paths\n"
1773 "Match the cluster length\n")
596c17ba 1774
165b5fff
JB
1775DEFUN (no_bgp_maxpaths,
1776 no_bgp_maxpaths_cmd,
6319fd63 1777 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1778 NO_STR
1779 "Forward packets over multiple paths\n"
1780 "Number of paths\n")
1781{
d62a17ae 1782 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1783}
1784
d62a17ae 1785ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1786 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1787 "Forward packets over multiple paths\n"
1788 "Number of paths\n")
596c17ba 1789
165b5fff
JB
1790DEFUN (no_bgp_maxpaths_ibgp,
1791 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1792 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1793 NO_STR
1794 "Forward packets over multiple paths\n"
1795 "iBGP-multipath\n"
838758ac
DW
1796 "Number of paths\n"
1797 "Match the cluster length\n")
165b5fff 1798{
d62a17ae 1799 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1800}
1801
d62a17ae 1802ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1803 "no maximum-paths ibgp [" CMD_RANGE_STR(
1804 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1805 NO_STR
1806 "Forward packets over multiple paths\n"
1807 "iBGP-multipath\n"
1808 "Number of paths\n"
1809 "Match the cluster length\n")
596c17ba 1810
2b791107 1811void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1812 safi_t safi)
165b5fff 1813{
d62a17ae 1814 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1815 vty_out(vty, " maximum-paths %d\n",
1816 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1817 }
165b5fff 1818
d62a17ae 1819 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1820 vty_out(vty, " maximum-paths ibgp %d",
1821 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1822 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1823 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1824 vty_out(vty, " equal-cluster-length");
1825 vty_out(vty, "\n");
1826 }
165b5fff 1827}
6b0655a2 1828
718e3744 1829/* BGP timers. */
1830
1831DEFUN (bgp_timers,
1832 bgp_timers_cmd,
6147e2c6 1833 "timers bgp (0-65535) (0-65535)",
718e3744 1834 "Adjust routing timers\n"
1835 "BGP timers\n"
1836 "Keepalive interval\n"
1837 "Holdtime\n")
1838{
d62a17ae 1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 int idx_number = 2;
1841 int idx_number_2 = 3;
1842 unsigned long keepalive = 0;
1843 unsigned long holdtime = 0;
718e3744 1844
d62a17ae 1845 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1846 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1847
d62a17ae 1848 /* Holdtime value check. */
1849 if (holdtime < 3 && holdtime != 0) {
1850 vty_out(vty,
1851 "%% hold time value must be either 0 or greater than 3\n");
1852 return CMD_WARNING_CONFIG_FAILED;
1853 }
718e3744 1854
d62a17ae 1855 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1856
d62a17ae 1857 return CMD_SUCCESS;
718e3744 1858}
1859
1860DEFUN (no_bgp_timers,
1861 no_bgp_timers_cmd,
838758ac 1862 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1863 NO_STR
1864 "Adjust routing timers\n"
838758ac
DW
1865 "BGP timers\n"
1866 "Keepalive interval\n"
1867 "Holdtime\n")
718e3744 1868{
d62a17ae 1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 bgp_timers_unset(bgp);
718e3744 1871
d62a17ae 1872 return CMD_SUCCESS;
718e3744 1873}
1874
6b0655a2 1875
718e3744 1876DEFUN (bgp_client_to_client_reflection,
1877 bgp_client_to_client_reflection_cmd,
1878 "bgp client-to-client reflection",
1879 "BGP specific commands\n"
1880 "Configure client to client route reflection\n"
1881 "reflection of routes allowed\n")
1882{
d62a17ae 1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1885 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1886
d62a17ae 1887 return CMD_SUCCESS;
718e3744 1888}
1889
1890DEFUN (no_bgp_client_to_client_reflection,
1891 no_bgp_client_to_client_reflection_cmd,
1892 "no bgp client-to-client reflection",
1893 NO_STR
1894 "BGP specific commands\n"
1895 "Configure client to client route reflection\n"
1896 "reflection of routes allowed\n")
1897{
d62a17ae 1898 VTY_DECLVAR_CONTEXT(bgp, bgp);
1899 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1900 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1901
d62a17ae 1902 return CMD_SUCCESS;
718e3744 1903}
1904
1905/* "bgp always-compare-med" configuration. */
1906DEFUN (bgp_always_compare_med,
1907 bgp_always_compare_med_cmd,
1908 "bgp always-compare-med",
1909 "BGP specific commands\n"
1910 "Allow comparing MED from different neighbors\n")
1911{
d62a17ae 1912 VTY_DECLVAR_CONTEXT(bgp, bgp);
1913 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1914 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1915
d62a17ae 1916 return CMD_SUCCESS;
718e3744 1917}
1918
1919DEFUN (no_bgp_always_compare_med,
1920 no_bgp_always_compare_med_cmd,
1921 "no bgp always-compare-med",
1922 NO_STR
1923 "BGP specific commands\n"
1924 "Allow comparing MED from different neighbors\n")
1925{
d62a17ae 1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1928 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1929
d62a17ae 1930 return CMD_SUCCESS;
718e3744 1931}
6b0655a2 1932
9dac9fc8
DA
1933
1934DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1935 "bgp ebgp-requires-policy",
1936 "BGP specific commands\n"
1937 "Require in and out policy for eBGP peers (RFC8212)\n")
1938{
1939 VTY_DECLVAR_CONTEXT(bgp, bgp);
1940 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1941 return CMD_SUCCESS;
1942}
1943
1944DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1945 "no bgp ebgp-requires-policy",
1946 NO_STR
1947 "BGP specific commands\n"
1948 "Require in and out policy for eBGP peers (RFC8212)\n")
1949{
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1952 return CMD_SUCCESS;
1953}
1954
1955
718e3744 1956/* "bgp deterministic-med" configuration. */
1957DEFUN (bgp_deterministic_med,
1958 bgp_deterministic_med_cmd,
1959 "bgp deterministic-med",
1960 "BGP specific commands\n"
1961 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1962{
d62a17ae 1963 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1964
d62a17ae 1965 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1966 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1967 bgp_recalculate_all_bestpaths(bgp);
1968 }
7aafcaca 1969
d62a17ae 1970 return CMD_SUCCESS;
718e3744 1971}
1972
1973DEFUN (no_bgp_deterministic_med,
1974 no_bgp_deterministic_med_cmd,
1975 "no bgp deterministic-med",
1976 NO_STR
1977 "BGP specific commands\n"
1978 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1979{
d62a17ae 1980 VTY_DECLVAR_CONTEXT(bgp, bgp);
1981 int bestpath_per_as_used;
1982 afi_t afi;
1983 safi_t safi;
1984 struct peer *peer;
1985 struct listnode *node, *nnode;
1986
1987 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1988 bestpath_per_as_used = 0;
1989
1990 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 1991 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
1992 if (bgp_addpath_dmed_required(
1993 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
1994 bestpath_per_as_used = 1;
1995 break;
1996 }
d62a17ae 1997
1998 if (bestpath_per_as_used)
1999 break;
2000 }
2001
2002 if (bestpath_per_as_used) {
2003 vty_out(vty,
2004 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2005 return CMD_WARNING_CONFIG_FAILED;
2006 } else {
2007 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2008 bgp_recalculate_all_bestpaths(bgp);
2009 }
2010 }
2011
2012 return CMD_SUCCESS;
718e3744 2013}
538621f2 2014
2015/* "bgp graceful-restart" configuration. */
2016DEFUN (bgp_graceful_restart,
2017 bgp_graceful_restart_cmd,
2018 "bgp graceful-restart",
2019 "BGP specific commands\n"
2020 "Graceful restart capability parameters\n")
2021{
d62a17ae 2022 VTY_DECLVAR_CONTEXT(bgp, bgp);
2023 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
2024 return CMD_SUCCESS;
538621f2 2025}
2026
2027DEFUN (no_bgp_graceful_restart,
2028 no_bgp_graceful_restart_cmd,
2029 "no bgp graceful-restart",
2030 NO_STR
2031 "BGP specific commands\n"
2032 "Graceful restart capability parameters\n")
2033{
d62a17ae 2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
2036 return CMD_SUCCESS;
538621f2 2037}
2038
93406d87 2039DEFUN (bgp_graceful_restart_stalepath_time,
2040 bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2041 "bgp graceful-restart stalepath-time (1-4095)",
93406d87 2042 "BGP specific commands\n"
2043 "Graceful restart capability parameters\n"
2044 "Set the max time to hold onto restarting peer's stale paths\n"
2045 "Delay value (seconds)\n")
2046{
d62a17ae 2047 VTY_DECLVAR_CONTEXT(bgp, bgp);
2048 int idx_number = 3;
d7c0a89a 2049 uint32_t stalepath;
93406d87 2050
d62a17ae 2051 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2052 bgp->stalepath_time = stalepath;
2053 return CMD_SUCCESS;
93406d87 2054}
2055
eb6f1b41
PG
2056DEFUN (bgp_graceful_restart_restart_time,
2057 bgp_graceful_restart_restart_time_cmd,
c72d0314 2058 "bgp graceful-restart restart-time (1-4095)",
eb6f1b41
PG
2059 "BGP specific commands\n"
2060 "Graceful restart capability parameters\n"
2061 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2062 "Delay value (seconds)\n")
2063{
d62a17ae 2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 int idx_number = 3;
d7c0a89a 2066 uint32_t restart;
eb6f1b41 2067
d62a17ae 2068 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2069 bgp->restart_time = restart;
2070 return CMD_SUCCESS;
eb6f1b41
PG
2071}
2072
93406d87 2073DEFUN (no_bgp_graceful_restart_stalepath_time,
2074 no_bgp_graceful_restart_stalepath_time_cmd,
c1779b7d 2075 "no bgp graceful-restart stalepath-time [(1-4095)]",
93406d87 2076 NO_STR
2077 "BGP specific commands\n"
2078 "Graceful restart capability parameters\n"
838758ac
DW
2079 "Set the max time to hold onto restarting peer's stale paths\n"
2080 "Delay value (seconds)\n")
93406d87 2081{
d62a17ae 2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2083
d62a17ae 2084 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2085 return CMD_SUCCESS;
93406d87 2086}
2087
eb6f1b41
PG
2088DEFUN (no_bgp_graceful_restart_restart_time,
2089 no_bgp_graceful_restart_restart_time_cmd,
c72d0314 2090 "no bgp graceful-restart restart-time [(1-4095)]",
eb6f1b41
PG
2091 NO_STR
2092 "BGP specific commands\n"
2093 "Graceful restart capability parameters\n"
838758ac
DW
2094 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2095 "Delay value (seconds)\n")
eb6f1b41 2096{
d62a17ae 2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2098
d62a17ae 2099 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2100 return CMD_SUCCESS;
eb6f1b41
PG
2101}
2102
43fc21b3
JC
2103DEFUN (bgp_graceful_restart_preserve_fw,
2104 bgp_graceful_restart_preserve_fw_cmd,
2105 "bgp graceful-restart preserve-fw-state",
2106 "BGP specific commands\n"
2107 "Graceful restart capability parameters\n"
2108 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2109{
d62a17ae 2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2112 return CMD_SUCCESS;
43fc21b3
JC
2113}
2114
2115DEFUN (no_bgp_graceful_restart_preserve_fw,
2116 no_bgp_graceful_restart_preserve_fw_cmd,
2117 "no bgp graceful-restart preserve-fw-state",
2118 NO_STR
2119 "BGP specific commands\n"
2120 "Graceful restart capability parameters\n"
2121 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2125 return CMD_SUCCESS;
43fc21b3
JC
2126}
2127
7f323236
DW
2128/* "bgp graceful-shutdown" configuration */
2129DEFUN (bgp_graceful_shutdown,
2130 bgp_graceful_shutdown_cmd,
2131 "bgp graceful-shutdown",
2132 BGP_STR
2133 "Graceful shutdown parameters\n")
2134{
2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136
2137 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2138 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2139 bgp_static_redo_import_check(bgp);
2140 bgp_redistribute_redo(bgp);
2141 bgp_clear_star_soft_out(vty, bgp->name);
2142 bgp_clear_star_soft_in(vty, bgp->name);
2143 }
2144
2145 return CMD_SUCCESS;
2146}
2147
2148DEFUN (no_bgp_graceful_shutdown,
2149 no_bgp_graceful_shutdown_cmd,
2150 "no bgp graceful-shutdown",
2151 NO_STR
2152 BGP_STR
2153 "Graceful shutdown parameters\n")
2154{
2155 VTY_DECLVAR_CONTEXT(bgp, bgp);
2156
2157 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2158 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2159 bgp_static_redo_import_check(bgp);
2160 bgp_redistribute_redo(bgp);
2161 bgp_clear_star_soft_out(vty, bgp->name);
2162 bgp_clear_star_soft_in(vty, bgp->name);
2163 }
2164
2165 return CMD_SUCCESS;
2166}
2167
718e3744 2168/* "bgp fast-external-failover" configuration. */
2169DEFUN (bgp_fast_external_failover,
2170 bgp_fast_external_failover_cmd,
2171 "bgp fast-external-failover",
2172 BGP_STR
2173 "Immediately reset session if a link to a directly connected external peer goes down\n")
2174{
d62a17ae 2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2177 return CMD_SUCCESS;
718e3744 2178}
2179
2180DEFUN (no_bgp_fast_external_failover,
2181 no_bgp_fast_external_failover_cmd,
2182 "no bgp fast-external-failover",
2183 NO_STR
2184 BGP_STR
2185 "Immediately reset session if a link to a directly connected external peer goes down\n")
2186{
d62a17ae 2187 VTY_DECLVAR_CONTEXT(bgp, bgp);
2188 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2189 return CMD_SUCCESS;
718e3744 2190}
6b0655a2 2191
718e3744 2192/* "bgp bestpath compare-routerid" configuration. */
2193DEFUN (bgp_bestpath_compare_router_id,
2194 bgp_bestpath_compare_router_id_cmd,
2195 "bgp bestpath compare-routerid",
2196 "BGP specific commands\n"
2197 "Change the default bestpath selection\n"
2198 "Compare router-id for identical EBGP paths\n")
2199{
d62a17ae 2200 VTY_DECLVAR_CONTEXT(bgp, bgp);
2201 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2202 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2203
d62a17ae 2204 return CMD_SUCCESS;
718e3744 2205}
2206
2207DEFUN (no_bgp_bestpath_compare_router_id,
2208 no_bgp_bestpath_compare_router_id_cmd,
2209 "no bgp bestpath compare-routerid",
2210 NO_STR
2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "Compare router-id for identical EBGP paths\n")
2214{
d62a17ae 2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2217 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2218
d62a17ae 2219 return CMD_SUCCESS;
718e3744 2220}
6b0655a2 2221
718e3744 2222/* "bgp bestpath as-path ignore" configuration. */
2223DEFUN (bgp_bestpath_aspath_ignore,
2224 bgp_bestpath_aspath_ignore_cmd,
2225 "bgp bestpath as-path ignore",
2226 "BGP specific commands\n"
2227 "Change the default bestpath selection\n"
2228 "AS-path attribute\n"
2229 "Ignore as-path length in selecting a route\n")
2230{
d62a17ae 2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
2232 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2233 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2234
d62a17ae 2235 return CMD_SUCCESS;
718e3744 2236}
2237
2238DEFUN (no_bgp_bestpath_aspath_ignore,
2239 no_bgp_bestpath_aspath_ignore_cmd,
2240 "no bgp bestpath as-path ignore",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Change the default bestpath selection\n"
2244 "AS-path attribute\n"
2245 "Ignore as-path length in selecting a route\n")
2246{
d62a17ae 2247 VTY_DECLVAR_CONTEXT(bgp, bgp);
2248 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2249 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2250
d62a17ae 2251 return CMD_SUCCESS;
718e3744 2252}
6b0655a2 2253
6811845b 2254/* "bgp bestpath as-path confed" configuration. */
2255DEFUN (bgp_bestpath_aspath_confed,
2256 bgp_bestpath_aspath_confed_cmd,
2257 "bgp bestpath as-path confed",
2258 "BGP specific commands\n"
2259 "Change the default bestpath selection\n"
2260 "AS-path attribute\n"
2261 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2262{
d62a17ae 2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2265 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2266
d62a17ae 2267 return CMD_SUCCESS;
6811845b 2268}
2269
2270DEFUN (no_bgp_bestpath_aspath_confed,
2271 no_bgp_bestpath_aspath_confed_cmd,
2272 "no bgp bestpath as-path confed",
2273 NO_STR
2274 "BGP specific commands\n"
2275 "Change the default bestpath selection\n"
2276 "AS-path attribute\n"
2277 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2278{
d62a17ae 2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2281 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2282
d62a17ae 2283 return CMD_SUCCESS;
6811845b 2284}
6b0655a2 2285
2fdd455c
PM
2286/* "bgp bestpath as-path multipath-relax" configuration. */
2287DEFUN (bgp_bestpath_aspath_multipath_relax,
2288 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2289 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2290 "BGP specific commands\n"
2291 "Change the default bestpath selection\n"
2292 "AS-path attribute\n"
2293 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2294 "Generate an AS_SET\n"
16fc1eec
DS
2295 "Do not generate an AS_SET\n")
2296{
d62a17ae 2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
2298 int idx = 0;
2299 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2300
d62a17ae 2301 /* no-as-set is now the default behavior so we can silently
2302 * ignore it */
2303 if (argv_find(argv, argc, "as-set", &idx))
2304 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2305 else
2306 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2307
d62a17ae 2308 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2309
d62a17ae 2310 return CMD_SUCCESS;
16fc1eec
DS
2311}
2312
219178b6
DW
2313DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2314 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2315 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2316 NO_STR
2317 "BGP specific commands\n"
2318 "Change the default bestpath selection\n"
2319 "AS-path attribute\n"
2320 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2321 "Generate an AS_SET\n"
16fc1eec
DS
2322 "Do not generate an AS_SET\n")
2323{
d62a17ae 2324 VTY_DECLVAR_CONTEXT(bgp, bgp);
2325 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2326 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2327 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2328
d62a17ae 2329 return CMD_SUCCESS;
2fdd455c 2330}
6b0655a2 2331
848973c7 2332/* "bgp log-neighbor-changes" configuration. */
2333DEFUN (bgp_log_neighbor_changes,
2334 bgp_log_neighbor_changes_cmd,
2335 "bgp log-neighbor-changes",
2336 "BGP specific commands\n"
2337 "Log neighbor up/down and reset reason\n")
2338{
d62a17ae 2339 VTY_DECLVAR_CONTEXT(bgp, bgp);
2340 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2341 return CMD_SUCCESS;
848973c7 2342}
2343
2344DEFUN (no_bgp_log_neighbor_changes,
2345 no_bgp_log_neighbor_changes_cmd,
2346 "no bgp log-neighbor-changes",
2347 NO_STR
2348 "BGP specific commands\n"
2349 "Log neighbor up/down and reset reason\n")
2350{
d62a17ae 2351 VTY_DECLVAR_CONTEXT(bgp, bgp);
2352 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2353 return CMD_SUCCESS;
848973c7 2354}
6b0655a2 2355
718e3744 2356/* "bgp bestpath med" configuration. */
2357DEFUN (bgp_bestpath_med,
2358 bgp_bestpath_med_cmd,
2d8c1a4d 2359 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2360 "BGP specific commands\n"
2361 "Change the default bestpath selection\n"
2362 "MED attribute\n"
2363 "Compare MED among confederation paths\n"
838758ac
DW
2364 "Treat missing MED as the least preferred one\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Compare MED among confederation paths\n")
718e3744 2367{
d62a17ae 2368 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2369
d62a17ae 2370 int idx = 0;
2371 if (argv_find(argv, argc, "confed", &idx))
2372 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2373 idx = 0;
2374 if (argv_find(argv, argc, "missing-as-worst", &idx))
2375 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2376
d62a17ae 2377 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2378
d62a17ae 2379 return CMD_SUCCESS;
718e3744 2380}
2381
718e3744 2382DEFUN (no_bgp_bestpath_med,
2383 no_bgp_bestpath_med_cmd,
2d8c1a4d 2384 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2385 NO_STR
2386 "BGP specific commands\n"
2387 "Change the default bestpath selection\n"
2388 "MED attribute\n"
2389 "Compare MED among confederation paths\n"
3a2d747c
QY
2390 "Treat missing MED as the least preferred one\n"
2391 "Treat missing MED as the least preferred one\n"
2392 "Compare MED among confederation paths\n")
718e3744 2393{
d62a17ae 2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2395
d62a17ae 2396 int idx = 0;
2397 if (argv_find(argv, argc, "confed", &idx))
2398 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2399 idx = 0;
2400 if (argv_find(argv, argc, "missing-as-worst", &idx))
2401 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2402
d62a17ae 2403 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2404
d62a17ae 2405 return CMD_SUCCESS;
718e3744 2406}
2407
718e3744 2408/* "no bgp default ipv4-unicast". */
2409DEFUN (no_bgp_default_ipv4_unicast,
2410 no_bgp_default_ipv4_unicast_cmd,
2411 "no bgp default ipv4-unicast",
2412 NO_STR
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Activate ipv4-unicast for a peer by default\n")
2416{
d62a17ae 2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2419 return CMD_SUCCESS;
718e3744 2420}
2421
2422DEFUN (bgp_default_ipv4_unicast,
2423 bgp_default_ipv4_unicast_cmd,
2424 "bgp default ipv4-unicast",
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
2427 "Activate ipv4-unicast for a peer by default\n")
2428{
d62a17ae 2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2431 return CMD_SUCCESS;
718e3744 2432}
6b0655a2 2433
04b6bdc0
DW
2434/* Display hostname in certain command outputs */
2435DEFUN (bgp_default_show_hostname,
2436 bgp_default_show_hostname_cmd,
2437 "bgp default show-hostname",
2438 "BGP specific commands\n"
2439 "Configure BGP defaults\n"
0437e105 2440 "Show hostname in certain command outputs\n")
04b6bdc0 2441{
d62a17ae 2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
2443 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2444 return CMD_SUCCESS;
04b6bdc0
DW
2445}
2446
2447DEFUN (no_bgp_default_show_hostname,
2448 no_bgp_default_show_hostname_cmd,
2449 "no bgp default show-hostname",
2450 NO_STR
2451 "BGP specific commands\n"
2452 "Configure BGP defaults\n"
0437e105 2453 "Show hostname in certain command outputs\n")
04b6bdc0 2454{
d62a17ae 2455 VTY_DECLVAR_CONTEXT(bgp, bgp);
2456 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2457 return CMD_SUCCESS;
04b6bdc0
DW
2458}
2459
8233ef81 2460/* "bgp network import-check" configuration. */
718e3744 2461DEFUN (bgp_network_import_check,
2462 bgp_network_import_check_cmd,
5623e905 2463 "bgp network import-check",
718e3744 2464 "BGP specific commands\n"
2465 "BGP network command\n"
5623e905 2466 "Check BGP network route exists in IGP\n")
718e3744 2467{
d62a17ae 2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2470 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2471 bgp_static_redo_import_check(bgp);
2472 }
078430f6 2473
d62a17ae 2474 return CMD_SUCCESS;
718e3744 2475}
2476
d62a17ae 2477ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2478 "bgp network import-check exact",
2479 "BGP specific commands\n"
2480 "BGP network command\n"
2481 "Check BGP network route exists in IGP\n"
2482 "Match route precisely\n")
8233ef81 2483
718e3744 2484DEFUN (no_bgp_network_import_check,
2485 no_bgp_network_import_check_cmd,
5623e905 2486 "no bgp network import-check",
718e3744 2487 NO_STR
2488 "BGP specific commands\n"
2489 "BGP network command\n"
2490 "Check BGP network route exists in IGP\n")
2491{
d62a17ae 2492 VTY_DECLVAR_CONTEXT(bgp, bgp);
2493 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2494 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2495 bgp_static_redo_import_check(bgp);
2496 }
5623e905 2497
d62a17ae 2498 return CMD_SUCCESS;
718e3744 2499}
6b0655a2 2500
718e3744 2501DEFUN (bgp_default_local_preference,
2502 bgp_default_local_preference_cmd,
6147e2c6 2503 "bgp default local-preference (0-4294967295)",
718e3744 2504 "BGP specific commands\n"
2505 "Configure BGP defaults\n"
2506 "local preference (higher=more preferred)\n"
2507 "Configure default local preference value\n")
2508{
d62a17ae 2509 VTY_DECLVAR_CONTEXT(bgp, bgp);
2510 int idx_number = 3;
d7c0a89a 2511 uint32_t local_pref;
718e3744 2512
d62a17ae 2513 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2514
d62a17ae 2515 bgp_default_local_preference_set(bgp, local_pref);
2516 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2517
d62a17ae 2518 return CMD_SUCCESS;
718e3744 2519}
2520
2521DEFUN (no_bgp_default_local_preference,
2522 no_bgp_default_local_preference_cmd,
838758ac 2523 "no bgp default local-preference [(0-4294967295)]",
718e3744 2524 NO_STR
2525 "BGP specific commands\n"
2526 "Configure BGP defaults\n"
838758ac
DW
2527 "local preference (higher=more preferred)\n"
2528 "Configure default local preference value\n")
718e3744 2529{
d62a17ae 2530 VTY_DECLVAR_CONTEXT(bgp, bgp);
2531 bgp_default_local_preference_unset(bgp);
2532 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2533
d62a17ae 2534 return CMD_SUCCESS;
718e3744 2535}
2536
6b0655a2 2537
3f9c7369
DS
2538DEFUN (bgp_default_subgroup_pkt_queue_max,
2539 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2540 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2541 "BGP specific commands\n"
2542 "Configure BGP defaults\n"
2543 "subgroup-pkt-queue-max\n"
2544 "Configure subgroup packet queue max\n")
8bd9d948 2545{
d62a17ae 2546 VTY_DECLVAR_CONTEXT(bgp, bgp);
2547 int idx_number = 3;
d7c0a89a 2548 uint32_t max_size;
8bd9d948 2549
d62a17ae 2550 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2551
d62a17ae 2552 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2553
d62a17ae 2554 return CMD_SUCCESS;
3f9c7369
DS
2555}
2556
2557DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2558 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2559 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2560 NO_STR
2561 "BGP specific commands\n"
2562 "Configure BGP defaults\n"
838758ac
DW
2563 "subgroup-pkt-queue-max\n"
2564 "Configure subgroup packet queue max\n")
3f9c7369 2565{
d62a17ae 2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2568 return CMD_SUCCESS;
8bd9d948
DS
2569}
2570
813d4307 2571
8bd9d948
DS
2572DEFUN (bgp_rr_allow_outbound_policy,
2573 bgp_rr_allow_outbound_policy_cmd,
2574 "bgp route-reflector allow-outbound-policy",
2575 "BGP specific commands\n"
2576 "Allow modifications made by out route-map\n"
2577 "on ibgp neighbors\n")
2578{
d62a17ae 2579 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2580
d62a17ae 2581 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2582 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2583 update_group_announce_rrclients(bgp);
2584 bgp_clear_star_soft_out(vty, bgp->name);
2585 }
8bd9d948 2586
d62a17ae 2587 return CMD_SUCCESS;
8bd9d948
DS
2588}
2589
2590DEFUN (no_bgp_rr_allow_outbound_policy,
2591 no_bgp_rr_allow_outbound_policy_cmd,
2592 "no bgp route-reflector allow-outbound-policy",
2593 NO_STR
2594 "BGP specific commands\n"
2595 "Allow modifications made by out route-map\n"
2596 "on ibgp neighbors\n")
2597{
d62a17ae 2598 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2599
d62a17ae 2600 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2601 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2602 update_group_announce_rrclients(bgp);
2603 bgp_clear_star_soft_out(vty, bgp->name);
2604 }
8bd9d948 2605
d62a17ae 2606 return CMD_SUCCESS;
8bd9d948
DS
2607}
2608
f14e6fdb
DS
2609DEFUN (bgp_listen_limit,
2610 bgp_listen_limit_cmd,
9ccf14f7 2611 "bgp listen limit (1-5000)",
f14e6fdb
DS
2612 "BGP specific commands\n"
2613 "Configure BGP defaults\n"
2614 "maximum number of BGP Dynamic Neighbors that can be created\n"
2615 "Configure Dynamic Neighbors listen limit value\n")
2616{
d62a17ae 2617 VTY_DECLVAR_CONTEXT(bgp, bgp);
2618 int idx_number = 3;
2619 int listen_limit;
f14e6fdb 2620
d62a17ae 2621 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2622
d62a17ae 2623 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2624
d62a17ae 2625 return CMD_SUCCESS;
f14e6fdb
DS
2626}
2627
2628DEFUN (no_bgp_listen_limit,
2629 no_bgp_listen_limit_cmd,
838758ac 2630 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2631 "BGP specific commands\n"
2632 "Configure BGP defaults\n"
2633 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2634 "Configure Dynamic Neighbors listen limit value to default\n"
2635 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2636{
d62a17ae 2637 VTY_DECLVAR_CONTEXT(bgp, bgp);
2638 bgp_listen_limit_unset(bgp);
2639 return CMD_SUCCESS;
f14e6fdb
DS
2640}
2641
2642
20eb8864 2643/*
2644 * Check if this listen range is already configured. Check for exact
2645 * match or overlap based on input.
2646 */
d62a17ae 2647static struct peer_group *listen_range_exists(struct bgp *bgp,
2648 struct prefix *range, int exact)
2649{
2650 struct listnode *node, *nnode;
2651 struct listnode *node1, *nnode1;
2652 struct peer_group *group;
2653 struct prefix *lr;
2654 afi_t afi;
2655 int match;
2656
2657 afi = family2afi(range->family);
2658 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2659 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2660 lr)) {
2661 if (exact)
2662 match = prefix_same(range, lr);
2663 else
2664 match = (prefix_match(range, lr)
2665 || prefix_match(lr, range));
2666 if (match)
2667 return group;
2668 }
2669 }
2670
2671 return NULL;
20eb8864 2672}
2673
f14e6fdb
DS
2674DEFUN (bgp_listen_range,
2675 bgp_listen_range_cmd,
d7b9898c 2676 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 2677 "BGP specific commands\n"
d7fa34c1
QY
2678 "Configure BGP dynamic neighbors listen range\n"
2679 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2680 NEIGHBOR_ADDR_STR
2681 "Member of the peer-group\n"
2682 "Peer-group name\n")
f14e6fdb 2683{
d62a17ae 2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 struct prefix range;
2686 struct peer_group *group, *existing_group;
2687 afi_t afi;
2688 int ret;
2689 int idx = 0;
2690
2691 argv_find(argv, argc, "A.B.C.D/M", &idx);
2692 argv_find(argv, argc, "X:X::X:X/M", &idx);
2693 char *prefix = argv[idx]->arg;
d7b9898c 2694 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 2695 char *peergroup = argv[idx]->arg;
2696
2697 /* Convert IP prefix string to struct prefix. */
2698 ret = str2prefix(prefix, &range);
2699 if (!ret) {
2700 vty_out(vty, "%% Malformed listen range\n");
2701 return CMD_WARNING_CONFIG_FAILED;
2702 }
2703
2704 afi = family2afi(range.family);
2705
2706 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2707 vty_out(vty,
2708 "%% Malformed listen range (link-local address)\n");
2709 return CMD_WARNING_CONFIG_FAILED;
2710 }
2711
2712 apply_mask(&range);
2713
2714 /* Check if same listen range is already configured. */
2715 existing_group = listen_range_exists(bgp, &range, 1);
2716 if (existing_group) {
2717 if (strcmp(existing_group->name, peergroup) == 0)
2718 return CMD_SUCCESS;
2719 else {
2720 vty_out(vty,
2721 "%% Same listen range is attached to peer-group %s\n",
2722 existing_group->name);
2723 return CMD_WARNING_CONFIG_FAILED;
2724 }
2725 }
2726
2727 /* Check if an overlapping listen range exists. */
2728 if (listen_range_exists(bgp, &range, 0)) {
2729 vty_out(vty,
2730 "%% Listen range overlaps with existing listen range\n");
2731 return CMD_WARNING_CONFIG_FAILED;
2732 }
2733
2734 group = peer_group_lookup(bgp, peergroup);
2735 if (!group) {
2736 vty_out(vty, "%% Configure the peer-group first\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 ret = peer_group_listen_range_add(group, &range);
2741 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2742}
2743
2744DEFUN (no_bgp_listen_range,
2745 no_bgp_listen_range_cmd,
d7b9898c 2746 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 2747 NO_STR
f14e6fdb 2748 "BGP specific commands\n"
d7fa34c1
QY
2749 "Unconfigure BGP dynamic neighbors listen range\n"
2750 "Unconfigure BGP dynamic neighbors listen range\n"
2751 NEIGHBOR_ADDR_STR
2752 "Member of the peer-group\n"
2753 "Peer-group name\n")
f14e6fdb 2754{
d62a17ae 2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
2756 struct prefix range;
2757 struct peer_group *group;
2758 afi_t afi;
2759 int ret;
2760 int idx = 0;
2761
2762 argv_find(argv, argc, "A.B.C.D/M", &idx);
2763 argv_find(argv, argc, "X:X::X:X/M", &idx);
2764 char *prefix = argv[idx]->arg;
2765 argv_find(argv, argc, "WORD", &idx);
2766 char *peergroup = argv[idx]->arg;
2767
2768 /* Convert IP prefix string to struct prefix. */
2769 ret = str2prefix(prefix, &range);
2770 if (!ret) {
2771 vty_out(vty, "%% Malformed listen range\n");
2772 return CMD_WARNING_CONFIG_FAILED;
2773 }
2774
2775 afi = family2afi(range.family);
2776
2777 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2778 vty_out(vty,
2779 "%% Malformed listen range (link-local address)\n");
2780 return CMD_WARNING_CONFIG_FAILED;
2781 }
2782
2783 apply_mask(&range);
2784
2785 group = peer_group_lookup(bgp, peergroup);
2786 if (!group) {
2787 vty_out(vty, "%% Peer-group does not exist\n");
2788 return CMD_WARNING_CONFIG_FAILED;
2789 }
2790
2791 ret = peer_group_listen_range_del(group, &range);
2792 return bgp_vty_return(vty, ret);
2793}
2794
2b791107 2795void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2796{
2797 struct peer_group *group;
2798 struct listnode *node, *nnode, *rnode, *nrnode;
2799 struct prefix *range;
2800 afi_t afi;
2801 char buf[PREFIX2STR_BUFFER];
2802
2803 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2804 vty_out(vty, " bgp listen limit %d\n",
2805 bgp->dynamic_neighbors_limit);
2806
2807 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2808 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2809 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2810 nrnode, range)) {
2811 prefix2str(range, buf, sizeof(buf));
2812 vty_out(vty,
2813 " bgp listen range %s peer-group %s\n",
2814 buf, group->name);
2815 }
2816 }
2817 }
f14e6fdb
DS
2818}
2819
2820
907f92c8
DS
2821DEFUN (bgp_disable_connected_route_check,
2822 bgp_disable_connected_route_check_cmd,
2823 "bgp disable-ebgp-connected-route-check",
2824 "BGP specific commands\n"
2825 "Disable checking if nexthop is connected on ebgp sessions\n")
2826{
d62a17ae 2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2829 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2830
d62a17ae 2831 return CMD_SUCCESS;
907f92c8
DS
2832}
2833
2834DEFUN (no_bgp_disable_connected_route_check,
2835 no_bgp_disable_connected_route_check_cmd,
2836 "no bgp disable-ebgp-connected-route-check",
2837 NO_STR
2838 "BGP specific commands\n"
2839 "Disable checking if nexthop is connected on ebgp sessions\n")
2840{
d62a17ae 2841 VTY_DECLVAR_CONTEXT(bgp, bgp);
2842 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2843 bgp_clear_star_soft_in(vty, bgp->name);
2844
2845 return CMD_SUCCESS;
2846}
2847
2848
2849static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2850 const char *as_str, afi_t afi, safi_t safi)
2851{
2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
2853 int ret;
2854 as_t as;
2855 int as_type = AS_SPECIFIED;
2856 union sockunion su;
2857
2858 if (as_str[0] == 'i') {
2859 as = 0;
2860 as_type = AS_INTERNAL;
2861 } else if (as_str[0] == 'e') {
2862 as = 0;
2863 as_type = AS_EXTERNAL;
2864 } else {
2865 /* Get AS number. */
2866 as = strtoul(as_str, NULL, 10);
2867 }
2868
390485fd 2869 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 2870 ret = str2sockunion(peer_str, &su);
2871 if (ret < 0) {
390485fd
DS
2872 struct peer *peer;
2873
2874 /* Check if existing interface peer */
2875 peer = peer_lookup_by_conf_if(bgp, peer_str);
2876
d62a17ae 2877 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2878 safi);
390485fd
DS
2879
2880 /* if not interface peer, check peer-group settings */
2881 if (ret < 0 && !peer) {
d62a17ae 2882 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2883 if (ret < 0) {
2884 vty_out(vty,
390485fd 2885 "%% Create the peer-group or interface first\n");
d62a17ae 2886 return CMD_WARNING_CONFIG_FAILED;
2887 }
2888 return CMD_SUCCESS;
2889 }
2890 } else {
2891 if (peer_address_self_check(bgp, &su)) {
2892 vty_out(vty,
2893 "%% Can not configure the local system as neighbor\n");
2894 return CMD_WARNING_CONFIG_FAILED;
2895 }
2896 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2897 }
2898
2899 /* This peer belongs to peer group. */
2900 switch (ret) {
2901 case BGP_ERR_PEER_GROUP_MEMBER:
2902 vty_out(vty,
faa16034 2903 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 2904 return CMD_WARNING_CONFIG_FAILED;
2905 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2906 vty_out(vty,
faa16034 2907 "%% Peer-group members must be all internal or all external\n");
d62a17ae 2908 return CMD_WARNING_CONFIG_FAILED;
2909 }
2910 return bgp_vty_return(vty, ret);
718e3744 2911}
2912
f26845f9
QY
2913DEFUN (bgp_default_shutdown,
2914 bgp_default_shutdown_cmd,
2915 "[no] bgp default shutdown",
2916 NO_STR
2917 BGP_STR
2918 "Configure BGP defaults\n"
b012cbe2 2919 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2920{
2921 VTY_DECLVAR_CONTEXT(bgp, bgp);
2922 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2923 return CMD_SUCCESS;
2924}
2925
718e3744 2926DEFUN (neighbor_remote_as,
2927 neighbor_remote_as_cmd,
3a2d747c 2928 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2929 NEIGHBOR_STR
2930 NEIGHBOR_ADDR_STR2
2931 "Specify a BGP neighbor\n"
d7fa34c1 2932 AS_STR
3a2d747c
QY
2933 "Internal BGP peer\n"
2934 "External BGP peer\n")
718e3744 2935{
d62a17ae 2936 int idx_peer = 1;
2937 int idx_remote_as = 3;
2938 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2939 argv[idx_remote_as]->arg, AFI_IP,
2940 SAFI_UNICAST);
2941}
2942
2943static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2944 afi_t afi, safi_t safi, int v6only,
2945 const char *peer_group_name,
2946 const char *as_str)
2947{
2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
2949 as_t as = 0;
2950 int as_type = AS_UNSPECIFIED;
2951 struct peer *peer;
2952 struct peer_group *group;
2953 int ret = 0;
2954 union sockunion su;
2955
2956 group = peer_group_lookup(bgp, conf_if);
2957
2958 if (group) {
2959 vty_out(vty, "%% Name conflict with peer-group \n");
2960 return CMD_WARNING_CONFIG_FAILED;
2961 }
2962
2963 if (as_str) {
2964 if (as_str[0] == 'i') {
2965 as_type = AS_INTERNAL;
2966 } else if (as_str[0] == 'e') {
2967 as_type = AS_EXTERNAL;
2968 } else {
2969 /* Get AS number. */
2970 as = strtoul(as_str, NULL, 10);
2971 as_type = AS_SPECIFIED;
2972 }
2973 }
2974
2975 peer = peer_lookup_by_conf_if(bgp, conf_if);
2976 if (peer) {
2977 if (as_str)
cc4d4ce8 2978 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 2979 afi, safi);
2980 } else {
2981 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2982 && afi == AFI_IP && safi == SAFI_UNICAST)
2983 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2984 as_type, 0, 0, NULL);
2985 else
2986 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2987 as_type, afi, safi, NULL);
2988
2989 if (!peer) {
2990 vty_out(vty, "%% BGP failed to create peer\n");
2991 return CMD_WARNING_CONFIG_FAILED;
2992 }
2993
2994 if (v6only)
527de3dc 2995 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 2996
2997 /* Request zebra to initiate IPv6 RAs on this interface. We do
2998 * this
2999 * any unnumbered peer in order to not worry about run-time
3000 * transitions
3001 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3002 * address
3003 * gets deleted later etc.)
3004 */
3005 if (peer->ifp)
3006 bgp_zebra_initiate_radv(bgp, peer);
3007 }
3008
3009 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3010 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3011 if (v6only)
527de3dc 3012 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3013 else
527de3dc 3014 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3015
3016 /* v6only flag changed. Reset bgp seesion */
3017 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3018 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3019 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3020 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3021 } else
3022 bgp_session_reset(peer);
3023 }
3024
9fb964de
PM
3025 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3026 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3027 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3028 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3029 }
d62a17ae 3030
3031 if (peer_group_name) {
3032 group = peer_group_lookup(bgp, peer_group_name);
3033 if (!group) {
3034 vty_out(vty, "%% Configure the peer-group first\n");
3035 return CMD_WARNING_CONFIG_FAILED;
3036 }
3037
3038 ret = peer_group_bind(bgp, &su, peer, group, &as);
3039 }
3040
3041 return bgp_vty_return(vty, ret);
a80beece
DS
3042}
3043
4c48cf63
DW
3044DEFUN (neighbor_interface_config,
3045 neighbor_interface_config_cmd,
d7b9898c 3046 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3047 NEIGHBOR_STR
3048 "Interface name or neighbor tag\n"
31500417
DW
3049 "Enable BGP on interface\n"
3050 "Member of the peer-group\n"
16cedbb0 3051 "Peer-group name\n")
4c48cf63 3052{
d62a17ae 3053 int idx_word = 1;
3054 int idx_peer_group_word = 4;
31500417 3055
d62a17ae 3056 if (argc > idx_peer_group_word)
3057 return peer_conf_interface_get(
3058 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3059 argv[idx_peer_group_word]->arg, NULL);
3060 else
3061 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3062 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3063}
3064
4c48cf63
DW
3065DEFUN (neighbor_interface_config_v6only,
3066 neighbor_interface_config_v6only_cmd,
d7b9898c 3067 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3068 NEIGHBOR_STR
3069 "Interface name or neighbor tag\n"
3070 "Enable BGP on interface\n"
31500417
DW
3071 "Enable BGP with v6 link-local only\n"
3072 "Member of the peer-group\n"
16cedbb0 3073 "Peer-group name\n")
4c48cf63 3074{
d62a17ae 3075 int idx_word = 1;
3076 int idx_peer_group_word = 5;
31500417 3077
d62a17ae 3078 if (argc > idx_peer_group_word)
3079 return peer_conf_interface_get(
3080 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3081 argv[idx_peer_group_word]->arg, NULL);
31500417 3082
d62a17ae 3083 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3084 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3085}
3086
a80beece 3087
b3a39dc5
DD
3088DEFUN (neighbor_interface_config_remote_as,
3089 neighbor_interface_config_remote_as_cmd,
3a2d747c 3090 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3091 NEIGHBOR_STR
3092 "Interface name or neighbor tag\n"
3093 "Enable BGP on interface\n"
3a2d747c 3094 "Specify a BGP neighbor\n"
d7fa34c1 3095 AS_STR
3a2d747c
QY
3096 "Internal BGP peer\n"
3097 "External BGP peer\n")
b3a39dc5 3098{
d62a17ae 3099 int idx_word = 1;
3100 int idx_remote_as = 4;
3101 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3102 SAFI_UNICAST, 0, NULL,
3103 argv[idx_remote_as]->arg);
b3a39dc5
DD
3104}
3105
3106DEFUN (neighbor_interface_v6only_config_remote_as,
3107 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3108 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3109 NEIGHBOR_STR
3110 "Interface name or neighbor tag\n"
3a2d747c 3111 "Enable BGP with v6 link-local only\n"
b3a39dc5 3112 "Enable BGP on interface\n"
3a2d747c 3113 "Specify a BGP neighbor\n"
d7fa34c1 3114 AS_STR
3a2d747c
QY
3115 "Internal BGP peer\n"
3116 "External BGP peer\n")
b3a39dc5 3117{
d62a17ae 3118 int idx_word = 1;
3119 int idx_remote_as = 5;
3120 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3121 SAFI_UNICAST, 1, NULL,
3122 argv[idx_remote_as]->arg);
b3a39dc5
DD
3123}
3124
718e3744 3125DEFUN (neighbor_peer_group,
3126 neighbor_peer_group_cmd,
3127 "neighbor WORD peer-group",
3128 NEIGHBOR_STR
a80beece 3129 "Interface name or neighbor tag\n"
718e3744 3130 "Configure peer-group\n")
3131{
d62a17ae 3132 VTY_DECLVAR_CONTEXT(bgp, bgp);
3133 int idx_word = 1;
3134 struct peer *peer;
3135 struct peer_group *group;
718e3744 3136
d62a17ae 3137 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3138 if (peer) {
3139 vty_out(vty, "%% Name conflict with interface: \n");
3140 return CMD_WARNING_CONFIG_FAILED;
3141 }
718e3744 3142
d62a17ae 3143 group = peer_group_get(bgp, argv[idx_word]->arg);
3144 if (!group) {
3145 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3146 return CMD_WARNING_CONFIG_FAILED;
3147 }
718e3744 3148
d62a17ae 3149 return CMD_SUCCESS;
718e3744 3150}
3151
3152DEFUN (no_neighbor,
3153 no_neighbor_cmd,
dab8cd00 3154 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3155 NO_STR
3156 NEIGHBOR_STR
3a2d747c
QY
3157 NEIGHBOR_ADDR_STR2
3158 "Specify a BGP neighbor\n"
3159 AS_STR
3160 "Internal BGP peer\n"
3161 "External BGP peer\n")
718e3744 3162{
d62a17ae 3163 VTY_DECLVAR_CONTEXT(bgp, bgp);
3164 int idx_peer = 2;
3165 int ret;
3166 union sockunion su;
3167 struct peer_group *group;
3168 struct peer *peer;
3169 struct peer *other;
3170
3171 ret = str2sockunion(argv[idx_peer]->arg, &su);
3172 if (ret < 0) {
3173 /* look up for neighbor by interface name config. */
3174 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3175 if (peer) {
3176 /* Request zebra to terminate IPv6 RAs on this
3177 * interface. */
3178 if (peer->ifp)
3179 bgp_zebra_terminate_radv(peer->bgp, peer);
3180 peer_delete(peer);
3181 return CMD_SUCCESS;
3182 }
f14e6fdb 3183
d62a17ae 3184 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3185 if (group)
3186 peer_group_delete(group);
3187 else {
3188 vty_out(vty, "%% Create the peer-group first\n");
3189 return CMD_WARNING_CONFIG_FAILED;
3190 }
3191 } else {
3192 peer = peer_lookup(bgp, &su);
3193 if (peer) {
3194 if (peer_dynamic_neighbor(peer)) {
3195 vty_out(vty,
3196 "%% Operation not allowed on a dynamic neighbor\n");
3197 return CMD_WARNING_CONFIG_FAILED;
3198 }
3199
3200 other = peer->doppelganger;
3201 peer_delete(peer);
3202 if (other && other->status != Deleted)
3203 peer_delete(other);
3204 }
1ff9a340 3205 }
718e3744 3206
d62a17ae 3207 return CMD_SUCCESS;
718e3744 3208}
3209
a80beece
DS
3210DEFUN (no_neighbor_interface_config,
3211 no_neighbor_interface_config_cmd,
d7b9898c 3212 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3213 NO_STR
3214 NEIGHBOR_STR
3215 "Interface name\n"
31500417
DW
3216 "Configure BGP on interface\n"
3217 "Enable BGP with v6 link-local only\n"
3218 "Member of the peer-group\n"
16cedbb0 3219 "Peer-group name\n"
3a2d747c
QY
3220 "Specify a BGP neighbor\n"
3221 AS_STR
3222 "Internal BGP peer\n"
3223 "External BGP peer\n")
a80beece 3224{
d62a17ae 3225 VTY_DECLVAR_CONTEXT(bgp, bgp);
3226 int idx_word = 2;
3227 struct peer *peer;
3228
3229 /* look up for neighbor by interface name config. */
3230 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3231 if (peer) {
3232 /* Request zebra to terminate IPv6 RAs on this interface. */
3233 if (peer->ifp)
3234 bgp_zebra_terminate_radv(peer->bgp, peer);
3235 peer_delete(peer);
3236 } else {
3237 vty_out(vty, "%% Create the bgp interface first\n");
3238 return CMD_WARNING_CONFIG_FAILED;
3239 }
3240 return CMD_SUCCESS;
a80beece
DS
3241}
3242
718e3744 3243DEFUN (no_neighbor_peer_group,
3244 no_neighbor_peer_group_cmd,
3245 "no neighbor WORD peer-group",
3246 NO_STR
3247 NEIGHBOR_STR
3248 "Neighbor tag\n"
3249 "Configure peer-group\n")
3250{
d62a17ae 3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
718e3744 3254
d62a17ae 3255 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3256 if (group)
3257 peer_group_delete(group);
3258 else {
3259 vty_out(vty, "%% Create the peer-group first\n");
3260 return CMD_WARNING_CONFIG_FAILED;
3261 }
3262 return CMD_SUCCESS;
718e3744 3263}
3264
a80beece
DS
3265DEFUN (no_neighbor_interface_peer_group_remote_as,
3266 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3267 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3268 NO_STR
3269 NEIGHBOR_STR
a80beece 3270 "Interface name or neighbor tag\n"
718e3744 3271 "Specify a BGP neighbor\n"
3a2d747c
QY
3272 AS_STR
3273 "Internal BGP peer\n"
3274 "External BGP peer\n")
718e3744 3275{
d62a17ae 3276 VTY_DECLVAR_CONTEXT(bgp, bgp);
3277 int idx_word = 2;
3278 struct peer_group *group;
3279 struct peer *peer;
3280
3281 /* look up for neighbor by interface name config. */
3282 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3283 if (peer) {
390485fd 3284 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3285 return CMD_SUCCESS;
3286 }
3287
3288 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3289 if (group)
3290 peer_group_remote_as_delete(group);
3291 else {
3292 vty_out(vty, "%% Create the peer-group or interface first\n");
3293 return CMD_WARNING_CONFIG_FAILED;
3294 }
3295 return CMD_SUCCESS;
718e3744 3296}
6b0655a2 3297
718e3744 3298DEFUN (neighbor_local_as,
3299 neighbor_local_as_cmd,
9ccf14f7 3300 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3301 NEIGHBOR_STR
3302 NEIGHBOR_ADDR_STR2
3303 "Specify a local-as number\n"
3304 "AS number used as local AS\n")
3305{
d62a17ae 3306 int idx_peer = 1;
3307 int idx_number = 3;
3308 struct peer *peer;
3309 int ret;
3310 as_t as;
718e3744 3311
d62a17ae 3312 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3313 if (!peer)
3314 return CMD_WARNING_CONFIG_FAILED;
718e3744 3315
d62a17ae 3316 as = strtoul(argv[idx_number]->arg, NULL, 10);
3317 ret = peer_local_as_set(peer, as, 0, 0);
3318 return bgp_vty_return(vty, ret);
718e3744 3319}
3320
3321DEFUN (neighbor_local_as_no_prepend,
3322 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3323 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3324 NEIGHBOR_STR
3325 NEIGHBOR_ADDR_STR2
3326 "Specify a local-as number\n"
3327 "AS number used as local AS\n"
3328 "Do not prepend local-as to updates from ebgp peers\n")
3329{
d62a17ae 3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
718e3744 3335
d62a17ae 3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
718e3744 3339
d62a17ae 3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 0);
3342 return bgp_vty_return(vty, ret);
718e3744 3343}
3344
9d3f9705
AC
3345DEFUN (neighbor_local_as_no_prepend_replace_as,
3346 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3347 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3348 NEIGHBOR_STR
3349 NEIGHBOR_ADDR_STR2
3350 "Specify a local-as number\n"
3351 "AS number used as local AS\n"
3352 "Do not prepend local-as to updates from ebgp peers\n"
3353 "Do not prepend local-as to updates from ibgp peers\n")
3354{
d62a17ae 3355 int idx_peer = 1;
3356 int idx_number = 3;
3357 struct peer *peer;
3358 int ret;
3359 as_t as;
9d3f9705 3360
d62a17ae 3361 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3362 if (!peer)
3363 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3364
d62a17ae 3365 as = strtoul(argv[idx_number]->arg, NULL, 10);
3366 ret = peer_local_as_set(peer, as, 1, 1);
3367 return bgp_vty_return(vty, ret);
9d3f9705
AC
3368}
3369
718e3744 3370DEFUN (no_neighbor_local_as,
3371 no_neighbor_local_as_cmd,
a636c635 3372 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3373 NO_STR
3374 NEIGHBOR_STR
3375 NEIGHBOR_ADDR_STR2
a636c635
DW
3376 "Specify a local-as number\n"
3377 "AS number used as local AS\n"
3378 "Do not prepend local-as to updates from ebgp peers\n"
3379 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3380{
d62a17ae 3381 int idx_peer = 2;
3382 struct peer *peer;
3383 int ret;
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_local_as_unset(peer);
3390 return bgp_vty_return(vty, ret);
718e3744 3391}
3392
718e3744 3393
3f9c7369
DS
3394DEFUN (neighbor_solo,
3395 neighbor_solo_cmd,
9ccf14f7 3396 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3397 NEIGHBOR_STR
3398 NEIGHBOR_ADDR_STR2
3399 "Solo peer - part of its own update group\n")
3400{
d62a17ae 3401 int idx_peer = 1;
3402 struct peer *peer;
3403 int ret;
3f9c7369 3404
d62a17ae 3405 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3406 if (!peer)
3407 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3408
d62a17ae 3409 ret = update_group_adjust_soloness(peer, 1);
3410 return bgp_vty_return(vty, ret);
3f9c7369
DS
3411}
3412
3413DEFUN (no_neighbor_solo,
3414 no_neighbor_solo_cmd,
9ccf14f7 3415 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3416 NO_STR
3417 NEIGHBOR_STR
3418 NEIGHBOR_ADDR_STR2
3419 "Solo peer - part of its own update group\n")
3420{
d62a17ae 3421 int idx_peer = 2;
3422 struct peer *peer;
3423 int ret;
3f9c7369 3424
d62a17ae 3425 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3426 if (!peer)
3427 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3428
d62a17ae 3429 ret = update_group_adjust_soloness(peer, 0);
3430 return bgp_vty_return(vty, ret);
3f9c7369
DS
3431}
3432
0df7c91f
PJ
3433DEFUN (neighbor_password,
3434 neighbor_password_cmd,
9ccf14f7 3435 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3436 NEIGHBOR_STR
3437 NEIGHBOR_ADDR_STR2
3438 "Set a password\n"
3439 "The password\n")
3440{
d62a17ae 3441 int idx_peer = 1;
3442 int idx_line = 3;
3443 struct peer *peer;
3444 int ret;
0df7c91f 3445
d62a17ae 3446 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3447 if (!peer)
3448 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3449
d62a17ae 3450 ret = peer_password_set(peer, argv[idx_line]->arg);
3451 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3452}
3453
3454DEFUN (no_neighbor_password,
3455 no_neighbor_password_cmd,
a636c635 3456 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3457 NO_STR
3458 NEIGHBOR_STR
3459 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3460 "Set a password\n"
3461 "The password\n")
0df7c91f 3462{
d62a17ae 3463 int idx_peer = 2;
3464 struct peer *peer;
3465 int ret;
0df7c91f 3466
d62a17ae 3467 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3468 if (!peer)
3469 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3470
d62a17ae 3471 ret = peer_password_unset(peer);
3472 return bgp_vty_return(vty, ret);
0df7c91f 3473}
6b0655a2 3474
718e3744 3475DEFUN (neighbor_activate,
3476 neighbor_activate_cmd,
9ccf14f7 3477 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481{
d62a17ae 3482 int idx_peer = 1;
3483 int ret;
3484 struct peer *peer;
718e3744 3485
d62a17ae 3486 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3487 if (!peer)
3488 return CMD_WARNING_CONFIG_FAILED;
718e3744 3489
d62a17ae 3490 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3491 return bgp_vty_return(vty, ret);
718e3744 3492}
3493
d62a17ae 3494ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3495 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3497 "Enable the Address Family for this Neighbor\n")
596c17ba 3498
718e3744 3499DEFUN (no_neighbor_activate,
3500 no_neighbor_activate_cmd,
9ccf14f7 3501 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3502 NO_STR
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Enable the Address Family for this Neighbor\n")
3506{
d62a17ae 3507 int idx_peer = 2;
3508 int ret;
3509 struct peer *peer;
718e3744 3510
d62a17ae 3511 /* Lookup peer. */
3512 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3513 if (!peer)
3514 return CMD_WARNING_CONFIG_FAILED;
718e3744 3515
d62a17ae 3516 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3517 return bgp_vty_return(vty, ret);
718e3744 3518}
6b0655a2 3519
d62a17ae 3520ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3521 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3523 "Enable the Address Family for this Neighbor\n")
596c17ba 3524
718e3744 3525DEFUN (neighbor_set_peer_group,
3526 neighbor_set_peer_group_cmd,
d7b9898c 3527 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3528 NEIGHBOR_STR
a80beece 3529 NEIGHBOR_ADDR_STR2
718e3744 3530 "Member of the peer-group\n"
16cedbb0 3531 "Peer-group name\n")
718e3744 3532{
d62a17ae 3533 VTY_DECLVAR_CONTEXT(bgp, bgp);
3534 int idx_peer = 1;
3535 int idx_word = 3;
3536 int ret;
3537 as_t as;
3538 union sockunion su;
3539 struct peer *peer;
3540 struct peer_group *group;
3541
d62a17ae 3542 ret = str2sockunion(argv[idx_peer]->arg, &su);
3543 if (ret < 0) {
3544 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3545 if (!peer) {
3546 vty_out(vty, "%% Malformed address or name: %s\n",
3547 argv[idx_peer]->arg);
3548 return CMD_WARNING_CONFIG_FAILED;
3549 }
3550 } else {
3551 if (peer_address_self_check(bgp, &su)) {
3552 vty_out(vty,
3553 "%% Can not configure the local system as neighbor\n");
3554 return CMD_WARNING_CONFIG_FAILED;
3555 }
3556
3557 /* Disallow for dynamic neighbor. */
3558 peer = peer_lookup(bgp, &su);
3559 if (peer && peer_dynamic_neighbor(peer)) {
3560 vty_out(vty,
3561 "%% Operation not allowed on a dynamic neighbor\n");
3562 return CMD_WARNING_CONFIG_FAILED;
3563 }
3564 }
3565
3566 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3567 if (!group) {
3568 vty_out(vty, "%% Configure the peer-group first\n");
3569 return CMD_WARNING_CONFIG_FAILED;
3570 }
3571
3572 ret = peer_group_bind(bgp, &su, peer, group, &as);
3573
3574 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3575 vty_out(vty,
3576 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3577 as);
3578 return CMD_WARNING_CONFIG_FAILED;
3579 }
3580
3581 return bgp_vty_return(vty, ret);
3582}
3583
3584ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 3585 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3586 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3587 "Member of the peer-group\n"
3588 "Peer-group name\n")
596c17ba 3589
718e3744 3590DEFUN (no_neighbor_set_peer_group,
3591 no_neighbor_set_peer_group_cmd,
d7b9898c 3592 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 3593 NO_STR
3594 NEIGHBOR_STR
a80beece 3595 NEIGHBOR_ADDR_STR2
718e3744 3596 "Member of the peer-group\n"
16cedbb0 3597 "Peer-group name\n")
718e3744 3598{
d62a17ae 3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600 int idx_peer = 2;
3601 int idx_word = 4;
3602 int ret;
3603 struct peer *peer;
3604 struct peer_group *group;
3605
3606 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3607 if (!peer)
3608 return CMD_WARNING_CONFIG_FAILED;
3609
3610 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3611 if (!group) {
3612 vty_out(vty, "%% Configure the peer-group first\n");
3613 return CMD_WARNING_CONFIG_FAILED;
3614 }
718e3744 3615
827ed707 3616 ret = peer_delete(peer);
718e3744 3617
d62a17ae 3618 return bgp_vty_return(vty, ret);
718e3744 3619}
6b0655a2 3620
d62a17ae 3621ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 3622 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 3623 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3624 "Member of the peer-group\n"
3625 "Peer-group name\n")
596c17ba 3626
d62a17ae 3627static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 3628 uint32_t flag, int set)
718e3744 3629{
d62a17ae 3630 int ret;
3631 struct peer *peer;
718e3744 3632
d62a17ae 3633 peer = peer_and_group_lookup_vty(vty, ip_str);
3634 if (!peer)
3635 return CMD_WARNING_CONFIG_FAILED;
718e3744 3636
7ebe625c
QY
3637 /*
3638 * If 'neighbor <interface>', then this is for directly connected peers,
3639 * we should not accept disable-connected-check.
3640 */
3641 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3642 vty_out(vty,
3643 "%s is directly connected peer, cannot accept disable-"
3644 "connected-check\n",
3645 ip_str);
3646 return CMD_WARNING_CONFIG_FAILED;
3647 }
3648
d62a17ae 3649 if (!set && flag == PEER_FLAG_SHUTDOWN)
3650 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3651
d62a17ae 3652 if (set)
3653 ret = peer_flag_set(peer, flag);
3654 else
3655 ret = peer_flag_unset(peer, flag);
718e3744 3656
d62a17ae 3657 return bgp_vty_return(vty, ret);
718e3744 3658}
3659
47cbc09b 3660static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 3661{
d62a17ae 3662 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3663}
3664
d62a17ae 3665static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 3666 uint32_t flag)
718e3744 3667{
d62a17ae 3668 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3669}
3670
3671/* neighbor passive. */
3672DEFUN (neighbor_passive,
3673 neighbor_passive_cmd,
9ccf14f7 3674 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3675 NEIGHBOR_STR
3676 NEIGHBOR_ADDR_STR2
3677 "Don't send open messages to this neighbor\n")
3678{
d62a17ae 3679 int idx_peer = 1;
3680 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3681}
3682
3683DEFUN (no_neighbor_passive,
3684 no_neighbor_passive_cmd,
9ccf14f7 3685 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3686 NO_STR
3687 NEIGHBOR_STR
3688 NEIGHBOR_ADDR_STR2
3689 "Don't send open messages to this neighbor\n")
3690{
d62a17ae 3691 int idx_peer = 2;
3692 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3693}
6b0655a2 3694
718e3744 3695/* neighbor shutdown. */
73d70fa6
DL
3696DEFUN (neighbor_shutdown_msg,
3697 neighbor_shutdown_msg_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3699 NEIGHBOR_STR
3700 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3701 "Administratively shut down this neighbor\n"
3702 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3703 "Shutdown message\n")
718e3744 3704{
d62a17ae 3705 int idx_peer = 1;
73d70fa6 3706
d62a17ae 3707 if (argc >= 5) {
3708 struct peer *peer =
3709 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3710 char *message;
73d70fa6 3711
d62a17ae 3712 if (!peer)
3713 return CMD_WARNING_CONFIG_FAILED;
3714 message = argv_concat(argv, argc, 4);
3715 peer_tx_shutdown_message_set(peer, message);
3716 XFREE(MTYPE_TMP, message);
3717 }
73d70fa6 3718
d62a17ae 3719 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3720}
3721
d62a17ae 3722ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3723 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3725 "Administratively shut down this neighbor\n")
73d70fa6
DL
3726
3727DEFUN (no_neighbor_shutdown_msg,
3728 no_neighbor_shutdown_msg_cmd,
3729 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3730 NO_STR
3731 NEIGHBOR_STR
3732 NEIGHBOR_ADDR_STR2
3733 "Administratively shut down this neighbor\n"
3734 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3735 "Shutdown message\n")
718e3744 3736{
d62a17ae 3737 int idx_peer = 2;
73d70fa6 3738
d62a17ae 3739 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3740 PEER_FLAG_SHUTDOWN);
718e3744 3741}
6b0655a2 3742
d62a17ae 3743ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3744 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3746 "Administratively shut down this neighbor\n")
73d70fa6 3747
718e3744 3748/* neighbor capability dynamic. */
3749DEFUN (neighbor_capability_dynamic,
3750 neighbor_capability_dynamic_cmd,
9ccf14f7 3751 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise dynamic capability to this neighbor\n")
3756{
d62a17ae 3757 int idx_peer = 1;
3758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3760}
3761
3762DEFUN (no_neighbor_capability_dynamic,
3763 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Advertise capability to the peer\n"
3769 "Advertise dynamic capability to this neighbor\n")
3770{
d62a17ae 3771 int idx_peer = 2;
3772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3774}
6b0655a2 3775
718e3744 3776/* neighbor dont-capability-negotiate */
3777DEFUN (neighbor_dont_capability_negotiate,
3778 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3779 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3780 NEIGHBOR_STR
3781 NEIGHBOR_ADDR_STR2
3782 "Do not perform capability negotiation\n")
3783{
d62a17ae 3784 int idx_peer = 1;
3785 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3786 PEER_FLAG_DONT_CAPABILITY);
718e3744 3787}
3788
3789DEFUN (no_neighbor_dont_capability_negotiate,
3790 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3791 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3792 NO_STR
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Do not perform capability negotiation\n")
3796{
d62a17ae 3797 int idx_peer = 2;
3798 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3799 PEER_FLAG_DONT_CAPABILITY);
718e3744 3800}
6b0655a2 3801
8a92a8a0
DS
3802/* neighbor capability extended next hop encoding */
3803DEFUN (neighbor_capability_enhe,
3804 neighbor_capability_enhe_cmd,
9ccf14f7 3805 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3806 NEIGHBOR_STR
3807 NEIGHBOR_ADDR_STR2
3808 "Advertise capability to the peer\n"
3809 "Advertise extended next-hop capability to the peer\n")
3810{
d62a17ae 3811 int idx_peer = 1;
3812 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3813 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3814}
3815
3816DEFUN (no_neighbor_capability_enhe,
3817 no_neighbor_capability_enhe_cmd,
9ccf14f7 3818 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3819 NO_STR
3820 NEIGHBOR_STR
3821 NEIGHBOR_ADDR_STR2
3822 "Advertise capability to the peer\n"
3823 "Advertise extended next-hop capability to the peer\n")
3824{
d62a17ae 3825 int idx_peer = 2;
3826 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3827 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3828}
3829
d62a17ae 3830static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3831 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 3832 int set)
718e3744 3833{
d62a17ae 3834 int ret;
3835 struct peer *peer;
718e3744 3836
d62a17ae 3837 peer = peer_and_group_lookup_vty(vty, peer_str);
3838 if (!peer)
3839 return CMD_WARNING_CONFIG_FAILED;
718e3744 3840
d62a17ae 3841 if (set)
3842 ret = peer_af_flag_set(peer, afi, safi, flag);
3843 else
3844 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3845
d62a17ae 3846 return bgp_vty_return(vty, ret);
718e3744 3847}
3848
d62a17ae 3849static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3850 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3851{
d62a17ae 3852 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3853}
3854
d62a17ae 3855static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 3856 afi_t afi, safi_t safi, uint32_t flag)
718e3744 3857{
d62a17ae 3858 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3859}
6b0655a2 3860
718e3744 3861/* neighbor capability orf prefix-list. */
3862DEFUN (neighbor_capability_orf_prefix,
3863 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3864 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3865 NEIGHBOR_STR
3866 NEIGHBOR_ADDR_STR2
3867 "Advertise capability to the peer\n"
3868 "Advertise ORF capability to the peer\n"
3869 "Advertise prefixlist ORF capability to this neighbor\n"
3870 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3871 "Capability to RECEIVE the ORF from this neighbor\n"
3872 "Capability to SEND the ORF to this neighbor\n")
3873{
d62a17ae 3874 int idx_peer = 1;
3875 int idx_send_recv = 5;
d7c0a89a 3876 uint16_t flag = 0;
d62a17ae 3877
3878 if (strmatch(argv[idx_send_recv]->text, "send"))
3879 flag = PEER_FLAG_ORF_PREFIX_SM;
3880 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3881 flag = PEER_FLAG_ORF_PREFIX_RM;
3882 else if (strmatch(argv[idx_send_recv]->text, "both"))
3883 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3884 else {
3885 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3886 return CMD_WARNING_CONFIG_FAILED;
3887 }
3888
3889 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3890 bgp_node_safi(vty), flag);
3891}
3892
3893ALIAS_HIDDEN(
3894 neighbor_capability_orf_prefix,
3895 neighbor_capability_orf_prefix_hidden_cmd,
3896 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3897 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3898 "Advertise capability to the peer\n"
3899 "Advertise ORF capability to the peer\n"
3900 "Advertise prefixlist ORF capability to this neighbor\n"
3901 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3902 "Capability to RECEIVE the ORF from this neighbor\n"
3903 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3904
718e3744 3905DEFUN (no_neighbor_capability_orf_prefix,
3906 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3907 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3908 NO_STR
3909 NEIGHBOR_STR
3910 NEIGHBOR_ADDR_STR2
3911 "Advertise capability to the peer\n"
3912 "Advertise ORF capability to the peer\n"
3913 "Advertise prefixlist ORF capability to this neighbor\n"
3914 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3915 "Capability to RECEIVE the ORF from this neighbor\n"
3916 "Capability to SEND the ORF to this neighbor\n")
3917{
d62a17ae 3918 int idx_peer = 2;
3919 int idx_send_recv = 6;
d7c0a89a 3920 uint16_t flag = 0;
d62a17ae 3921
3922 if (strmatch(argv[idx_send_recv]->text, "send"))
3923 flag = PEER_FLAG_ORF_PREFIX_SM;
3924 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3925 flag = PEER_FLAG_ORF_PREFIX_RM;
3926 else if (strmatch(argv[idx_send_recv]->text, "both"))
3927 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3928 else {
3929 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3930 return CMD_WARNING_CONFIG_FAILED;
3931 }
3932
3933 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3934 bgp_node_afi(vty), bgp_node_safi(vty),
3935 flag);
3936}
3937
3938ALIAS_HIDDEN(
3939 no_neighbor_capability_orf_prefix,
3940 no_neighbor_capability_orf_prefix_hidden_cmd,
3941 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Advertise capability to the peer\n"
3944 "Advertise ORF capability to the peer\n"
3945 "Advertise prefixlist ORF capability to this neighbor\n"
3946 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3947 "Capability to RECEIVE the ORF from this neighbor\n"
3948 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3949
718e3744 3950/* neighbor next-hop-self. */
3951DEFUN (neighbor_nexthop_self,
3952 neighbor_nexthop_self_cmd,
9ccf14f7 3953 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3954 NEIGHBOR_STR
3955 NEIGHBOR_ADDR_STR2
a538debe 3956 "Disable the next hop calculation for this neighbor\n")
718e3744 3957{
d62a17ae 3958 int idx_peer = 1;
3959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3960 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3961}
9e7a53c1 3962
d62a17ae 3963ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3964 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3966 "Disable the next hop calculation for this neighbor\n")
596c17ba 3967
a538debe
DS
3968/* neighbor next-hop-self. */
3969DEFUN (neighbor_nexthop_self_force,
3970 neighbor_nexthop_self_force_cmd,
9ccf14f7 3971 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3972 NEIGHBOR_STR
3973 NEIGHBOR_ADDR_STR2
3974 "Disable the next hop calculation for this neighbor\n"
3975 "Set the next hop to self for reflected routes\n")
3976{
d62a17ae 3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty),
3980 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3981}
3982
d62a17ae 3983ALIAS_HIDDEN(neighbor_nexthop_self_force,
3984 neighbor_nexthop_self_force_hidden_cmd,
3985 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3987 "Disable the next hop calculation for this neighbor\n"
3988 "Set the next hop to self for reflected routes\n")
596c17ba 3989
1bc4e531
DA
3990ALIAS_HIDDEN(neighbor_nexthop_self_force,
3991 neighbor_nexthop_self_all_hidden_cmd,
3992 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3993 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3994 "Disable the next hop calculation for this neighbor\n"
3995 "Set the next hop to self for reflected routes\n")
3996
718e3744 3997DEFUN (no_neighbor_nexthop_self,
3998 no_neighbor_nexthop_self_cmd,
9ccf14f7 3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
a538debe 4003 "Disable the next hop calculation for this neighbor\n")
718e3744 4004{
d62a17ae 4005 int idx_peer = 2;
4006 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4007 bgp_node_afi(vty), bgp_node_safi(vty),
4008 PEER_FLAG_NEXTHOP_SELF);
718e3744 4009}
6b0655a2 4010
d62a17ae 4011ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4012 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4013 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4014 "Disable the next hop calculation for this neighbor\n")
596c17ba 4015
88b8ed8d 4016DEFUN (no_neighbor_nexthop_self_force,
a538debe 4017 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4019 NO_STR
4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
4022 "Disable the next hop calculation for this neighbor\n"
4023 "Set the next hop to self for reflected routes\n")
88b8ed8d 4024{
d62a17ae 4025 int idx_peer = 2;
4026 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4027 bgp_node_afi(vty), bgp_node_safi(vty),
4028 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4029}
a538debe 4030
d62a17ae 4031ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4032 no_neighbor_nexthop_self_force_hidden_cmd,
4033 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4035 "Disable the next hop calculation for this neighbor\n"
4036 "Set the next hop to self for reflected routes\n")
596c17ba 4037
1bc4e531
DA
4038ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4039 no_neighbor_nexthop_self_all_hidden_cmd,
4040 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4041 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4042 "Disable the next hop calculation for this neighbor\n"
4043 "Set the next hop to self for reflected routes\n")
4044
c7122e14
DS
4045/* neighbor as-override */
4046DEFUN (neighbor_as_override,
4047 neighbor_as_override_cmd,
9ccf14f7 4048 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4049 NEIGHBOR_STR
4050 NEIGHBOR_ADDR_STR2
4051 "Override ASNs in outbound updates if aspath equals remote-as\n")
4052{
d62a17ae 4053 int idx_peer = 1;
4054 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4055 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4056}
4057
d62a17ae 4058ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4059 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4060 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4062
c7122e14
DS
4063DEFUN (no_neighbor_as_override,
4064 no_neighbor_as_override_cmd,
9ccf14f7 4065 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4066 NO_STR
4067 NEIGHBOR_STR
4068 NEIGHBOR_ADDR_STR2
4069 "Override ASNs in outbound updates if aspath equals remote-as\n")
4070{
d62a17ae 4071 int idx_peer = 2;
4072 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4073 bgp_node_afi(vty), bgp_node_safi(vty),
4074 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4075}
4076
d62a17ae 4077ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4078 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4079 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4081
718e3744 4082/* neighbor remove-private-AS. */
4083DEFUN (neighbor_remove_private_as,
4084 neighbor_remove_private_as_cmd,
9ccf14f7 4085 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
5000f21c 4088 "Remove private ASNs in outbound updates\n")
718e3744 4089{
d62a17ae 4090 int idx_peer = 1;
4091 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4092 bgp_node_safi(vty),
4093 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4094}
4095
d62a17ae 4096ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4097 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4098 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4099 "Remove private ASNs in outbound updates\n")
596c17ba 4100
5000f21c
DS
4101DEFUN (neighbor_remove_private_as_all,
4102 neighbor_remove_private_as_all_cmd,
9ccf14f7 4103 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4104 NEIGHBOR_STR
4105 NEIGHBOR_ADDR_STR2
4106 "Remove private ASNs in outbound updates\n"
efd7904e 4107 "Apply to all AS numbers\n")
5000f21c 4108{
d62a17ae 4109 int idx_peer = 1;
4110 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4111 bgp_node_safi(vty),
4112 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4113}
4114
d62a17ae 4115ALIAS_HIDDEN(neighbor_remove_private_as_all,
4116 neighbor_remove_private_as_all_hidden_cmd,
4117 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n"
4120 "Apply to all AS numbers")
596c17ba 4121
5000f21c
DS
4122DEFUN (neighbor_remove_private_as_replace_as,
4123 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4124 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4125 NEIGHBOR_STR
4126 NEIGHBOR_ADDR_STR2
4127 "Remove private ASNs in outbound updates\n"
4128 "Replace private ASNs with our ASN in outbound updates\n")
4129{
d62a17ae 4130 int idx_peer = 1;
4131 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4132 bgp_node_safi(vty),
4133 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4134}
4135
d62a17ae 4136ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4137 neighbor_remove_private_as_replace_as_hidden_cmd,
4138 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4139 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4140 "Remove private ASNs in outbound updates\n"
4141 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4142
5000f21c
DS
4143DEFUN (neighbor_remove_private_as_all_replace_as,
4144 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4145 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4146 NEIGHBOR_STR
4147 NEIGHBOR_ADDR_STR2
4148 "Remove private ASNs in outbound updates\n"
16cedbb0 4149 "Apply to all AS numbers\n"
5000f21c
DS
4150 "Replace private ASNs with our ASN in outbound updates\n")
4151{
d62a17ae 4152 int idx_peer = 1;
4153 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4154 bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4156}
4157
d62a17ae 4158ALIAS_HIDDEN(
4159 neighbor_remove_private_as_all_replace_as,
4160 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4161 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4162 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4163 "Remove private ASNs in outbound updates\n"
4164 "Apply to all AS numbers\n"
4165 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4166
718e3744 4167DEFUN (no_neighbor_remove_private_as,
4168 no_neighbor_remove_private_as_cmd,
9ccf14f7 4169 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4170 NO_STR
4171 NEIGHBOR_STR
4172 NEIGHBOR_ADDR_STR2
5000f21c 4173 "Remove private ASNs in outbound updates\n")
718e3744 4174{
d62a17ae 4175 int idx_peer = 2;
4176 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4177 bgp_node_afi(vty), bgp_node_safi(vty),
4178 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4179}
6b0655a2 4180
d62a17ae 4181ALIAS_HIDDEN(no_neighbor_remove_private_as,
4182 no_neighbor_remove_private_as_hidden_cmd,
4183 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4185 "Remove private ASNs in outbound updates\n")
596c17ba 4186
88b8ed8d 4187DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4188 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4189 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR2
4193 "Remove private ASNs in outbound updates\n"
16cedbb0 4194 "Apply to all AS numbers\n")
88b8ed8d 4195{
d62a17ae 4196 int idx_peer = 2;
4197 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4198 bgp_node_afi(vty), bgp_node_safi(vty),
4199 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4200}
5000f21c 4201
d62a17ae 4202ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4203 no_neighbor_remove_private_as_all_hidden_cmd,
4204 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4205 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4206 "Remove private ASNs in outbound updates\n"
4207 "Apply to all AS numbers\n")
596c17ba 4208
88b8ed8d 4209DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4210 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4212 NO_STR
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Remove private ASNs in outbound updates\n"
4216 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4217{
d62a17ae 4218 int idx_peer = 2;
4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4222}
5000f21c 4223
d62a17ae 4224ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4225 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4226 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4227 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4228 "Remove private ASNs in outbound updates\n"
4229 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4230
88b8ed8d 4231DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4232 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4233 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4234 NO_STR
4235 NEIGHBOR_STR
4236 NEIGHBOR_ADDR_STR2
4237 "Remove private ASNs in outbound updates\n"
16cedbb0 4238 "Apply to all AS numbers\n"
5000f21c 4239 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4240{
d62a17ae 4241 int idx_peer = 2;
4242 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4243 bgp_node_afi(vty), bgp_node_safi(vty),
4244 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4245}
5000f21c 4246
d62a17ae 4247ALIAS_HIDDEN(
4248 no_neighbor_remove_private_as_all_replace_as,
4249 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4252 "Remove private ASNs in outbound updates\n"
4253 "Apply to all AS numbers\n"
4254 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4255
5000f21c 4256
718e3744 4257/* neighbor send-community. */
4258DEFUN (neighbor_send_community,
4259 neighbor_send_community_cmd,
9ccf14f7 4260 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4261 NEIGHBOR_STR
4262 NEIGHBOR_ADDR_STR2
4263 "Send Community attribute to this neighbor\n")
4264{
d62a17ae 4265 int idx_peer = 1;
27c05d4d 4266
d62a17ae 4267 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4268 bgp_node_safi(vty),
4269 PEER_FLAG_SEND_COMMUNITY);
718e3744 4270}
4271
d62a17ae 4272ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4273 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4274 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4275 "Send Community attribute to this neighbor\n")
596c17ba 4276
718e3744 4277DEFUN (no_neighbor_send_community,
4278 no_neighbor_send_community_cmd,
9ccf14f7 4279 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4280 NO_STR
4281 NEIGHBOR_STR
4282 NEIGHBOR_ADDR_STR2
4283 "Send Community attribute to this neighbor\n")
4284{
d62a17ae 4285 int idx_peer = 2;
27c05d4d 4286
d62a17ae 4287 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4288 bgp_node_afi(vty), bgp_node_safi(vty),
4289 PEER_FLAG_SEND_COMMUNITY);
718e3744 4290}
6b0655a2 4291
d62a17ae 4292ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4293 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4294 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4295 "Send Community attribute to this neighbor\n")
596c17ba 4296
718e3744 4297/* neighbor send-community extended. */
4298DEFUN (neighbor_send_community_type,
4299 neighbor_send_community_type_cmd,
57d187bc 4300 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4301 NEIGHBOR_STR
4302 NEIGHBOR_ADDR_STR2
4303 "Send Community attribute to this neighbor\n"
4304 "Send Standard and Extended Community attributes\n"
57d187bc 4305 "Send Standard, Large and Extended Community attributes\n"
718e3744 4306 "Send Extended Community attributes\n"
57d187bc
JS
4307 "Send Standard Community attributes\n"
4308 "Send Large Community attributes\n")
718e3744 4309{
27c05d4d 4310 int idx_peer = 1;
d7c0a89a 4311 uint32_t flag = 0;
27c05d4d 4312 const char *type = argv[argc - 1]->text;
d62a17ae 4313
27c05d4d 4314 if (strmatch(type, "standard")) {
d62a17ae 4315 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4316 } else if (strmatch(type, "extended")) {
d62a17ae 4317 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4318 } else if (strmatch(type, "large")) {
d62a17ae 4319 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4320 } else if (strmatch(type, "both")) {
d62a17ae 4321 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4322 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4323 } else { /* if (strmatch(type, "all")) */
d62a17ae 4324 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4327 }
4328
27c05d4d 4329 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4330 bgp_node_safi(vty), flag);
4331}
4332
4333ALIAS_HIDDEN(
4334 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4335 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4336 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4337 "Send Community attribute to this neighbor\n"
4338 "Send Standard and Extended Community attributes\n"
4339 "Send Standard, Large and Extended Community attributes\n"
4340 "Send Extended Community attributes\n"
4341 "Send Standard Community attributes\n"
4342 "Send Large Community attributes\n")
596c17ba 4343
718e3744 4344DEFUN (no_neighbor_send_community_type,
4345 no_neighbor_send_community_type_cmd,
57d187bc 4346 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4347 NO_STR
4348 NEIGHBOR_STR
4349 NEIGHBOR_ADDR_STR2
4350 "Send Community attribute to this neighbor\n"
4351 "Send Standard and Extended Community attributes\n"
57d187bc 4352 "Send Standard, Large and Extended Community attributes\n"
718e3744 4353 "Send Extended Community attributes\n"
57d187bc
JS
4354 "Send Standard Community attributes\n"
4355 "Send Large Community attributes\n")
718e3744 4356{
d62a17ae 4357 int idx_peer = 2;
27c05d4d 4358 uint32_t flag = 0;
d62a17ae 4359 const char *type = argv[argc - 1]->text;
4360
27c05d4d
PM
4361 if (strmatch(type, "standard")) {
4362 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4363 } else if (strmatch(type, "extended")) {
4364 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4365 } else if (strmatch(type, "large")) {
4366 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4367 } else if (strmatch(type, "both")) {
4368 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4369 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4370 } else { /* if (strmatch(type, "all")) */
4371 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4372 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4373 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4374 }
4375
4376 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4377 bgp_node_afi(vty), bgp_node_safi(vty),
4378 flag);
d62a17ae 4379}
4380
4381ALIAS_HIDDEN(
4382 no_neighbor_send_community_type,
4383 no_neighbor_send_community_type_hidden_cmd,
4384 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4385 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4386 "Send Community attribute to this neighbor\n"
4387 "Send Standard and Extended Community attributes\n"
4388 "Send Standard, Large and Extended Community attributes\n"
4389 "Send Extended Community attributes\n"
4390 "Send Standard Community attributes\n"
4391 "Send Large Community attributes\n")
596c17ba 4392
718e3744 4393/* neighbor soft-reconfig. */
4394DEFUN (neighbor_soft_reconfiguration,
4395 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4396 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4397 NEIGHBOR_STR
4398 NEIGHBOR_ADDR_STR2
4399 "Per neighbor soft reconfiguration\n"
4400 "Allow inbound soft reconfiguration for this neighbor\n")
4401{
d62a17ae 4402 int idx_peer = 1;
4403 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4404 bgp_node_safi(vty),
4405 PEER_FLAG_SOFT_RECONFIG);
718e3744 4406}
4407
d62a17ae 4408ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4409 neighbor_soft_reconfiguration_hidden_cmd,
4410 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4411 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4412 "Per neighbor soft reconfiguration\n"
4413 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4414
718e3744 4415DEFUN (no_neighbor_soft_reconfiguration,
4416 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4417 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4418 NO_STR
4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Per neighbor soft reconfiguration\n"
4422 "Allow inbound soft reconfiguration for this neighbor\n")
4423{
d62a17ae 4424 int idx_peer = 2;
4425 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4426 bgp_node_afi(vty), bgp_node_safi(vty),
4427 PEER_FLAG_SOFT_RECONFIG);
718e3744 4428}
6b0655a2 4429
d62a17ae 4430ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4431 no_neighbor_soft_reconfiguration_hidden_cmd,
4432 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4433 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4434 "Per neighbor soft reconfiguration\n"
4435 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4436
718e3744 4437DEFUN (neighbor_route_reflector_client,
4438 neighbor_route_reflector_client_cmd,
9ccf14f7 4439 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4440 NEIGHBOR_STR
4441 NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Reflector client\n")
4443{
d62a17ae 4444 int idx_peer = 1;
4445 struct peer *peer;
718e3744 4446
4447
d62a17ae 4448 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4449 if (!peer)
4450 return CMD_WARNING_CONFIG_FAILED;
718e3744 4451
d62a17ae 4452 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4453 bgp_node_safi(vty),
4454 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4455}
4456
d62a17ae 4457ALIAS_HIDDEN(neighbor_route_reflector_client,
4458 neighbor_route_reflector_client_hidden_cmd,
4459 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4460 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4461 "Configure a neighbor as Route Reflector client\n")
596c17ba 4462
718e3744 4463DEFUN (no_neighbor_route_reflector_client,
4464 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4465 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4466 NO_STR
4467 NEIGHBOR_STR
4468 NEIGHBOR_ADDR_STR2
4469 "Configure a neighbor as Route Reflector client\n")
4470{
d62a17ae 4471 int idx_peer = 2;
4472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4473 bgp_node_afi(vty), bgp_node_safi(vty),
4474 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4475}
6b0655a2 4476
d62a17ae 4477ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4478 no_neighbor_route_reflector_client_hidden_cmd,
4479 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4481 "Configure a neighbor as Route Reflector client\n")
596c17ba 4482
718e3744 4483/* neighbor route-server-client. */
4484DEFUN (neighbor_route_server_client,
4485 neighbor_route_server_client_cmd,
9ccf14f7 4486 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure a neighbor as Route Server client\n")
4490{
d62a17ae 4491 int idx_peer = 1;
4492 struct peer *peer;
2a3d5731 4493
d62a17ae 4494 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4495 if (!peer)
4496 return CMD_WARNING_CONFIG_FAILED;
4497 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4498 bgp_node_safi(vty),
4499 PEER_FLAG_RSERVER_CLIENT);
718e3744 4500}
4501
d62a17ae 4502ALIAS_HIDDEN(neighbor_route_server_client,
4503 neighbor_route_server_client_hidden_cmd,
4504 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4505 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4506 "Configure a neighbor as Route Server client\n")
596c17ba 4507
718e3744 4508DEFUN (no_neighbor_route_server_client,
4509 no_neighbor_route_server_client_cmd,
9ccf14f7 4510 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4511 NO_STR
4512 NEIGHBOR_STR
4513 NEIGHBOR_ADDR_STR2
4514 "Configure a neighbor as Route Server client\n")
fee0f4c6 4515{
d62a17ae 4516 int idx_peer = 2;
4517 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4518 bgp_node_afi(vty), bgp_node_safi(vty),
4519 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4520}
6b0655a2 4521
d62a17ae 4522ALIAS_HIDDEN(no_neighbor_route_server_client,
4523 no_neighbor_route_server_client_hidden_cmd,
4524 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4526 "Configure a neighbor as Route Server client\n")
596c17ba 4527
fee0f4c6 4528DEFUN (neighbor_nexthop_local_unchanged,
4529 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4530 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4531 NEIGHBOR_STR
4532 NEIGHBOR_ADDR_STR2
4533 "Configure treatment of outgoing link-local nexthop attribute\n"
4534 "Leave link-local nexthop unchanged for this peer\n")
4535{
d62a17ae 4536 int idx_peer = 1;
4537 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4538 bgp_node_safi(vty),
4539 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4540}
6b0655a2 4541
fee0f4c6 4542DEFUN (no_neighbor_nexthop_local_unchanged,
4543 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4544 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4545 NO_STR
4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Configure treatment of outgoing link-local-nexthop attribute\n"
4549 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4550{
d62a17ae 4551 int idx_peer = 2;
4552 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4553 bgp_node_afi(vty), bgp_node_safi(vty),
4554 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4555}
6b0655a2 4556
718e3744 4557DEFUN (neighbor_attr_unchanged,
4558 neighbor_attr_unchanged_cmd,
a8206004 4559 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "BGP attribute is propagated unchanged to this neighbor\n"
4563 "As-path attribute\n"
4564 "Nexthop attribute\n"
a8206004 4565 "Med attribute\n")
718e3744 4566{
d62a17ae 4567 int idx = 0;
8eeb0335
DW
4568 char *peer_str = argv[1]->arg;
4569 struct peer *peer;
d7c0a89a 4570 uint16_t flags = 0;
8eeb0335
DW
4571 afi_t afi = bgp_node_afi(vty);
4572 safi_t safi = bgp_node_safi(vty);
4573
4574 peer = peer_and_group_lookup_vty(vty, peer_str);
4575 if (!peer)
4576 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4577
4578 if (argv_find(argv, argc, "as-path", &idx))
4579 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4580 idx = 0;
4581 if (argv_find(argv, argc, "next-hop", &idx))
4582 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4583 idx = 0;
4584 if (argv_find(argv, argc, "med", &idx))
4585 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4586
8eeb0335
DW
4587 /* no flags means all of them! */
4588 if (!flags) {
d62a17ae 4589 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4590 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4591 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4592 } else {
a4d82a8a
PZ
4593 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4594 && peer_af_flag_check(peer, afi, safi,
4595 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4596 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4597 PEER_FLAG_AS_PATH_UNCHANGED);
4598 }
4599
a4d82a8a
PZ
4600 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4601 && peer_af_flag_check(peer, afi, safi,
4602 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4603 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4604 PEER_FLAG_NEXTHOP_UNCHANGED);
4605 }
4606
a4d82a8a
PZ
4607 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4608 && peer_af_flag_check(peer, afi, safi,
4609 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4610 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4611 PEER_FLAG_MED_UNCHANGED);
4612 }
d62a17ae 4613 }
4614
8eeb0335 4615 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4616}
4617
4618ALIAS_HIDDEN(
4619 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4620 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4621 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4622 "BGP attribute is propagated unchanged to this neighbor\n"
4623 "As-path attribute\n"
4624 "Nexthop attribute\n"
4625 "Med attribute\n")
596c17ba 4626
718e3744 4627DEFUN (no_neighbor_attr_unchanged,
4628 no_neighbor_attr_unchanged_cmd,
a8206004 4629 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4630 NO_STR
718e3744 4631 NEIGHBOR_STR
4632 NEIGHBOR_ADDR_STR2
31500417
DW
4633 "BGP attribute is propagated unchanged to this neighbor\n"
4634 "As-path attribute\n"
40e718b5 4635 "Nexthop attribute\n"
a8206004 4636 "Med attribute\n")
718e3744 4637{
d62a17ae 4638 int idx = 0;
4639 char *peer = argv[2]->arg;
d7c0a89a 4640 uint16_t flags = 0;
d62a17ae 4641
4642 if (argv_find(argv, argc, "as-path", &idx))
4643 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4644 idx = 0;
4645 if (argv_find(argv, argc, "next-hop", &idx))
4646 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4647 idx = 0;
4648 if (argv_find(argv, argc, "med", &idx))
4649 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4650
4651 if (!flags) // no flags means all of them!
4652 {
4653 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4654 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4655 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4656 }
4657
4658 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4659 bgp_node_safi(vty), flags);
4660}
4661
4662ALIAS_HIDDEN(
4663 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4665 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4666 "BGP attribute is propagated unchanged to this neighbor\n"
4667 "As-path attribute\n"
4668 "Nexthop attribute\n"
4669 "Med attribute\n")
718e3744 4670
718e3744 4671/* EBGP multihop configuration. */
d62a17ae 4672static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4673 const char *ttl_str)
718e3744 4674{
d62a17ae 4675 struct peer *peer;
4676 unsigned int ttl;
718e3744 4677
d62a17ae 4678 peer = peer_and_group_lookup_vty(vty, ip_str);
4679 if (!peer)
4680 return CMD_WARNING_CONFIG_FAILED;
718e3744 4681
d62a17ae 4682 if (peer->conf_if)
4683 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4684
d62a17ae 4685 if (!ttl_str)
4686 ttl = MAXTTL;
4687 else
4688 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4689
d62a17ae 4690 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4691}
4692
d62a17ae 4693static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4694{
d62a17ae 4695 struct peer *peer;
718e3744 4696
d62a17ae 4697 peer = peer_and_group_lookup_vty(vty, ip_str);
4698 if (!peer)
4699 return CMD_WARNING_CONFIG_FAILED;
718e3744 4700
d62a17ae 4701 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4702}
4703
4704/* neighbor ebgp-multihop. */
4705DEFUN (neighbor_ebgp_multihop,
4706 neighbor_ebgp_multihop_cmd,
9ccf14f7 4707 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4708 NEIGHBOR_STR
4709 NEIGHBOR_ADDR_STR2
4710 "Allow EBGP neighbors not on directly connected networks\n")
4711{
d62a17ae 4712 int idx_peer = 1;
4713 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4714}
4715
4716DEFUN (neighbor_ebgp_multihop_ttl,
4717 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4718 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4719 NEIGHBOR_STR
4720 NEIGHBOR_ADDR_STR2
4721 "Allow EBGP neighbors not on directly connected networks\n"
4722 "maximum hop count\n")
4723{
d62a17ae 4724 int idx_peer = 1;
4725 int idx_number = 3;
4726 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4727 argv[idx_number]->arg);
718e3744 4728}
4729
4730DEFUN (no_neighbor_ebgp_multihop,
4731 no_neighbor_ebgp_multihop_cmd,
a636c635 4732 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4733 NO_STR
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
a636c635
DW
4736 "Allow EBGP neighbors not on directly connected networks\n"
4737 "maximum hop count\n")
718e3744 4738{
d62a17ae 4739 int idx_peer = 2;
4740 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4741}
4742
6b0655a2 4743
6ffd2079 4744/* disable-connected-check */
4745DEFUN (neighbor_disable_connected_check,
4746 neighbor_disable_connected_check_cmd,
7ebe625c 4747 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4748 NEIGHBOR_STR
7ebe625c 4749 NEIGHBOR_ADDR_STR2
a636c635
DW
4750 "one-hop away EBGP peer using loopback address\n"
4751 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4752{
d62a17ae 4753 int idx_peer = 1;
4754 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4755 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4756}
4757
4758DEFUN (no_neighbor_disable_connected_check,
4759 no_neighbor_disable_connected_check_cmd,
7ebe625c 4760 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4761 NO_STR
4762 NEIGHBOR_STR
7ebe625c 4763 NEIGHBOR_ADDR_STR2
a636c635
DW
4764 "one-hop away EBGP peer using loopback address\n"
4765 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4766{
d62a17ae 4767 int idx_peer = 2;
4768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4769 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4770}
4771
47cbc09b
PM
4772
4773/* enforce-first-as */
4774DEFUN (neighbor_enforce_first_as,
4775 neighbor_enforce_first_as_cmd,
4776 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4777 NEIGHBOR_STR
4778 NEIGHBOR_ADDR_STR2
4779 "Enforce the first AS for EBGP routes\n")
4780{
4781 int idx_peer = 1;
4782
4783 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4784 PEER_FLAG_ENFORCE_FIRST_AS);
4785}
4786
4787DEFUN (no_neighbor_enforce_first_as,
4788 no_neighbor_enforce_first_as_cmd,
4789 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4790 NO_STR
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR2
4793 "Enforce the first AS for EBGP routes\n")
4794{
4795 int idx_peer = 2;
4796
4797 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4798 PEER_FLAG_ENFORCE_FIRST_AS);
4799}
4800
4801
718e3744 4802DEFUN (neighbor_description,
4803 neighbor_description_cmd,
e961923c 4804 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4805 NEIGHBOR_STR
4806 NEIGHBOR_ADDR_STR2
4807 "Neighbor specific description\n"
4808 "Up to 80 characters describing this neighbor\n")
4809{
d62a17ae 4810 int idx_peer = 1;
4811 int idx_line = 3;
4812 struct peer *peer;
4813 char *str;
718e3744 4814
d62a17ae 4815 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4816 if (!peer)
4817 return CMD_WARNING_CONFIG_FAILED;
718e3744 4818
d62a17ae 4819 str = argv_concat(argv, argc, idx_line);
718e3744 4820
d62a17ae 4821 peer_description_set(peer, str);
718e3744 4822
d62a17ae 4823 XFREE(MTYPE_TMP, str);
718e3744 4824
d62a17ae 4825 return CMD_SUCCESS;
718e3744 4826}
4827
4828DEFUN (no_neighbor_description,
4829 no_neighbor_description_cmd,
a14810f4 4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
a14810f4 4834 "Neighbor specific description\n")
718e3744 4835{
d62a17ae 4836 int idx_peer = 2;
4837 struct peer *peer;
718e3744 4838
d62a17ae 4839 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4840 if (!peer)
4841 return CMD_WARNING_CONFIG_FAILED;
718e3744 4842
d62a17ae 4843 peer_description_unset(peer);
718e3744 4844
d62a17ae 4845 return CMD_SUCCESS;
718e3744 4846}
4847
a14810f4
PM
4848ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4849 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4850 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4851 "Neighbor specific description\n"
4852 "Up to 80 characters describing this neighbor\n")
6b0655a2 4853
718e3744 4854/* Neighbor update-source. */
d62a17ae 4855static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4856 const char *source_str)
4857{
4858 struct peer *peer;
4859 struct prefix p;
a14810f4 4860 union sockunion su;
d62a17ae 4861
4862 peer = peer_and_group_lookup_vty(vty, peer_str);
4863 if (!peer)
4864 return CMD_WARNING_CONFIG_FAILED;
4865
4866 if (peer->conf_if)
4867 return CMD_WARNING;
4868
4869 if (source_str) {
a14810f4 4870 if (str2sockunion(source_str, &su) == 0)
d62a17ae 4871 peer_update_source_addr_set(peer, &su);
4872 else {
4873 if (str2prefix(source_str, &p)) {
4874 vty_out(vty,
4875 "%% Invalid update-source, remove prefix length \n");
4876 return CMD_WARNING_CONFIG_FAILED;
4877 } else
4878 peer_update_source_if_set(peer, source_str);
4879 }
4880 } else
4881 peer_update_source_unset(peer);
4882
4883 return CMD_SUCCESS;
4884}
4885
4886#define BGP_UPDATE_SOURCE_HELP_STR \
4887 "IPv4 address\n" \
4888 "IPv6 address\n" \
4889 "Interface name (requires zebra to be running)\n"
369688c0 4890
718e3744 4891DEFUN (neighbor_update_source,
4892 neighbor_update_source_cmd,
9ccf14f7 4893 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Source of routing updates\n"
369688c0 4897 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4898{
d62a17ae 4899 int idx_peer = 1;
4900 int idx_peer_2 = 3;
4901 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4902 argv[idx_peer_2]->arg);
718e3744 4903}
4904
4905DEFUN (no_neighbor_update_source,
4906 no_neighbor_update_source_cmd,
c7178fe7 4907 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4908 NO_STR
4909 NEIGHBOR_STR
4910 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4911 "Source of routing updates\n"
4912 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4913{
d62a17ae 4914 int idx_peer = 2;
4915 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4916}
6b0655a2 4917
d62a17ae 4918static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4919 afi_t afi, safi_t safi,
4920 const char *rmap, int set)
718e3744 4921{
d62a17ae 4922 int ret;
4923 struct peer *peer;
80912664 4924 struct route_map *route_map = NULL;
718e3744 4925
d62a17ae 4926 peer = peer_and_group_lookup_vty(vty, peer_str);
4927 if (!peer)
4928 return CMD_WARNING_CONFIG_FAILED;
718e3744 4929
1de27621 4930 if (set) {
80912664
DS
4931 if (rmap)
4932 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
4933 ret = peer_default_originate_set(peer, afi, safi,
4934 rmap, route_map);
4935 } else
d62a17ae 4936 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4937
d62a17ae 4938 return bgp_vty_return(vty, ret);
718e3744 4939}
4940
4941/* neighbor default-originate. */
4942DEFUN (neighbor_default_originate,
4943 neighbor_default_originate_cmd,
9ccf14f7 4944 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4945 NEIGHBOR_STR
4946 NEIGHBOR_ADDR_STR2
4947 "Originate default route to this neighbor\n")
4948{
d62a17ae 4949 int idx_peer = 1;
4950 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4951 bgp_node_afi(vty),
4952 bgp_node_safi(vty), NULL, 1);
718e3744 4953}
4954
d62a17ae 4955ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4957 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4958 "Originate default route to this neighbor\n")
596c17ba 4959
718e3744 4960DEFUN (neighbor_default_originate_rmap,
4961 neighbor_default_originate_rmap_cmd,
9ccf14f7 4962 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4963 NEIGHBOR_STR
4964 NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
4968{
d62a17ae 4969 int idx_peer = 1;
4970 int idx_word = 4;
4971 return peer_default_originate_set_vty(
4972 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4973 argv[idx_word]->arg, 1);
718e3744 4974}
4975
d62a17ae 4976ALIAS_HIDDEN(
4977 neighbor_default_originate_rmap,
4978 neighbor_default_originate_rmap_hidden_cmd,
4979 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4980 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Originate default route to this neighbor\n"
4982 "Route-map to specify criteria to originate default\n"
4983 "route-map name\n")
596c17ba 4984
718e3744 4985DEFUN (no_neighbor_default_originate,
4986 no_neighbor_default_originate_cmd,
a636c635 4987 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4988 NO_STR
4989 NEIGHBOR_STR
4990 NEIGHBOR_ADDR_STR2
a636c635
DW
4991 "Originate default route to this neighbor\n"
4992 "Route-map to specify criteria to originate default\n"
4993 "route-map name\n")
718e3744 4994{
d62a17ae 4995 int idx_peer = 2;
4996 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4997 bgp_node_afi(vty),
4998 bgp_node_safi(vty), NULL, 0);
718e3744 4999}
5000
d62a17ae 5001ALIAS_HIDDEN(
5002 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5003 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5004 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5005 "Originate default route to this neighbor\n"
5006 "Route-map to specify criteria to originate default\n"
5007 "route-map name\n")
596c17ba 5008
6b0655a2 5009
718e3744 5010/* Set neighbor's BGP port. */
d62a17ae 5011static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5012 const char *port_str)
5013{
5014 struct peer *peer;
d7c0a89a 5015 uint16_t port;
d62a17ae 5016 struct servent *sp;
5017
5018 peer = peer_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 if (!port_str) {
5023 sp = getservbyname("bgp", "tcp");
5024 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5025 } else {
5026 port = strtoul(port_str, NULL, 10);
5027 }
718e3744 5028
d62a17ae 5029 peer_port_set(peer, port);
718e3744 5030
d62a17ae 5031 return CMD_SUCCESS;
718e3744 5032}
5033
f418446b 5034/* Set specified peer's BGP port. */
718e3744 5035DEFUN (neighbor_port,
5036 neighbor_port_cmd,
9ccf14f7 5037 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5038 NEIGHBOR_STR
5039 NEIGHBOR_ADDR_STR
5040 "Neighbor's BGP port\n"
5041 "TCP port number\n")
5042{
d62a17ae 5043 int idx_ip = 1;
5044 int idx_number = 3;
5045 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5046 argv[idx_number]->arg);
718e3744 5047}
5048
5049DEFUN (no_neighbor_port,
5050 no_neighbor_port_cmd,
9ccf14f7 5051 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5052 NO_STR
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR
8334fd5a
DW
5055 "Neighbor's BGP port\n"
5056 "TCP port number\n")
718e3744 5057{
d62a17ae 5058 int idx_ip = 2;
5059 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5060}
5061
6b0655a2 5062
718e3744 5063/* neighbor weight. */
d62a17ae 5064static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5065 safi_t safi, const char *weight_str)
718e3744 5066{
d62a17ae 5067 int ret;
5068 struct peer *peer;
5069 unsigned long weight;
718e3744 5070
d62a17ae 5071 peer = peer_and_group_lookup_vty(vty, ip_str);
5072 if (!peer)
5073 return CMD_WARNING_CONFIG_FAILED;
718e3744 5074
d62a17ae 5075 weight = strtoul(weight_str, NULL, 10);
718e3744 5076
d62a17ae 5077 ret = peer_weight_set(peer, afi, safi, weight);
5078 return bgp_vty_return(vty, ret);
718e3744 5079}
5080
d62a17ae 5081static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5082 safi_t safi)
718e3744 5083{
d62a17ae 5084 int ret;
5085 struct peer *peer;
718e3744 5086
d62a17ae 5087 peer = peer_and_group_lookup_vty(vty, ip_str);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
718e3744 5090
d62a17ae 5091 ret = peer_weight_unset(peer, afi, safi);
5092 return bgp_vty_return(vty, ret);
718e3744 5093}
5094
5095DEFUN (neighbor_weight,
5096 neighbor_weight_cmd,
9ccf14f7 5097 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5098 NEIGHBOR_STR
5099 NEIGHBOR_ADDR_STR2
5100 "Set default weight for routes from this neighbor\n"
5101 "default weight\n")
5102{
d62a17ae 5103 int idx_peer = 1;
5104 int idx_number = 3;
5105 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5106 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5107}
5108
d62a17ae 5109ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5110 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5111 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5112 "Set default weight for routes from this neighbor\n"
5113 "default weight\n")
596c17ba 5114
718e3744 5115DEFUN (no_neighbor_weight,
5116 no_neighbor_weight_cmd,
9ccf14f7 5117 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5118 NO_STR
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5121 "Set default weight for routes from this neighbor\n"
5122 "default weight\n")
718e3744 5123{
d62a17ae 5124 int idx_peer = 2;
5125 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5126 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5127}
5128
d62a17ae 5129ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5130 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5131 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5132 "Set default weight for routes from this neighbor\n"
5133 "default weight\n")
596c17ba 5134
6b0655a2 5135
718e3744 5136/* Override capability negotiation. */
5137DEFUN (neighbor_override_capability,
5138 neighbor_override_capability_cmd,
9ccf14f7 5139 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5140 NEIGHBOR_STR
5141 NEIGHBOR_ADDR_STR2
5142 "Override capability negotiation result\n")
5143{
d62a17ae 5144 int idx_peer = 1;
5145 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5147}
5148
5149DEFUN (no_neighbor_override_capability,
5150 no_neighbor_override_capability_cmd,
9ccf14f7 5151 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5152 NO_STR
5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "Override capability negotiation result\n")
5156{
d62a17ae 5157 int idx_peer = 2;
5158 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5159 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5160}
6b0655a2 5161
718e3744 5162DEFUN (neighbor_strict_capability,
5163 neighbor_strict_capability_cmd,
9fb964de 5164 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5165 NEIGHBOR_STR
9fb964de 5166 NEIGHBOR_ADDR_STR2
718e3744 5167 "Strict capability negotiation match\n")
5168{
9fb964de
PM
5169 int idx_peer = 1;
5170
5171 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5172 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5173}
5174
5175DEFUN (no_neighbor_strict_capability,
5176 no_neighbor_strict_capability_cmd,
9fb964de 5177 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5178 NO_STR
5179 NEIGHBOR_STR
9fb964de 5180 NEIGHBOR_ADDR_STR2
718e3744 5181 "Strict capability negotiation match\n")
5182{
9fb964de
PM
5183 int idx_peer = 2;
5184
5185 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5186 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5187}
6b0655a2 5188
d62a17ae 5189static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5190 const char *keep_str, const char *hold_str)
718e3744 5191{
d62a17ae 5192 int ret;
5193 struct peer *peer;
d7c0a89a
QY
5194 uint32_t keepalive;
5195 uint32_t holdtime;
718e3744 5196
d62a17ae 5197 peer = peer_and_group_lookup_vty(vty, ip_str);
5198 if (!peer)
5199 return CMD_WARNING_CONFIG_FAILED;
718e3744 5200
d62a17ae 5201 keepalive = strtoul(keep_str, NULL, 10);
5202 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5203
d62a17ae 5204 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5205
d62a17ae 5206 return bgp_vty_return(vty, ret);
718e3744 5207}
6b0655a2 5208
d62a17ae 5209static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5210{
d62a17ae 5211 int ret;
5212 struct peer *peer;
718e3744 5213
d62a17ae 5214 peer = peer_and_group_lookup_vty(vty, ip_str);
5215 if (!peer)
5216 return CMD_WARNING_CONFIG_FAILED;
718e3744 5217
d62a17ae 5218 ret = peer_timers_unset(peer);
718e3744 5219
d62a17ae 5220 return bgp_vty_return(vty, ret);
718e3744 5221}
5222
5223DEFUN (neighbor_timers,
5224 neighbor_timers_cmd,
9ccf14f7 5225 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5226 NEIGHBOR_STR
5227 NEIGHBOR_ADDR_STR2
5228 "BGP per neighbor timers\n"
5229 "Keepalive interval\n"
5230 "Holdtime\n")
5231{
d62a17ae 5232 int idx_peer = 1;
5233 int idx_number = 3;
5234 int idx_number_2 = 4;
5235 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5236 argv[idx_number]->arg,
5237 argv[idx_number_2]->arg);
718e3744 5238}
5239
5240DEFUN (no_neighbor_timers,
5241 no_neighbor_timers_cmd,
9ccf14f7 5242 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5243 NO_STR
5244 NEIGHBOR_STR
5245 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5246 "BGP per neighbor timers\n"
5247 "Keepalive interval\n"
5248 "Holdtime\n")
718e3744 5249{
d62a17ae 5250 int idx_peer = 2;
5251 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5252}
6b0655a2 5253
813d4307 5254
d62a17ae 5255static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5256 const char *time_str)
718e3744 5257{
d62a17ae 5258 int ret;
5259 struct peer *peer;
d7c0a89a 5260 uint32_t connect;
718e3744 5261
d62a17ae 5262 peer = peer_and_group_lookup_vty(vty, ip_str);
5263 if (!peer)
5264 return CMD_WARNING_CONFIG_FAILED;
718e3744 5265
d62a17ae 5266 connect = strtoul(time_str, NULL, 10);
718e3744 5267
d62a17ae 5268 ret = peer_timers_connect_set(peer, connect);
718e3744 5269
d62a17ae 5270 return bgp_vty_return(vty, ret);
718e3744 5271}
5272
d62a17ae 5273static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5274{
d62a17ae 5275 int ret;
5276 struct peer *peer;
718e3744 5277
d62a17ae 5278 peer = peer_and_group_lookup_vty(vty, ip_str);
5279 if (!peer)
5280 return CMD_WARNING_CONFIG_FAILED;
718e3744 5281
d62a17ae 5282 ret = peer_timers_connect_unset(peer);
718e3744 5283
d62a17ae 5284 return bgp_vty_return(vty, ret);
718e3744 5285}
5286
5287DEFUN (neighbor_timers_connect,
5288 neighbor_timers_connect_cmd,
9ccf14f7 5289 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5290 NEIGHBOR_STR
966f821c 5291 NEIGHBOR_ADDR_STR2
718e3744 5292 "BGP per neighbor timers\n"
5293 "BGP connect timer\n"
5294 "Connect timer\n")
5295{
d62a17ae 5296 int idx_peer = 1;
5297 int idx_number = 4;
5298 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5299 argv[idx_number]->arg);
718e3744 5300}
5301
5302DEFUN (no_neighbor_timers_connect,
5303 no_neighbor_timers_connect_cmd,
9ccf14f7 5304 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5305 NO_STR
5306 NEIGHBOR_STR
966f821c 5307 NEIGHBOR_ADDR_STR2
718e3744 5308 "BGP per neighbor timers\n"
8334fd5a
DW
5309 "BGP connect timer\n"
5310 "Connect timer\n")
718e3744 5311{
d62a17ae 5312 int idx_peer = 2;
5313 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5314}
5315
6b0655a2 5316
d62a17ae 5317static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5318 const char *time_str, int set)
718e3744 5319{
d62a17ae 5320 int ret;
5321 struct peer *peer;
d7c0a89a 5322 uint32_t routeadv = 0;
718e3744 5323
d62a17ae 5324 peer = peer_and_group_lookup_vty(vty, ip_str);
5325 if (!peer)
5326 return CMD_WARNING_CONFIG_FAILED;
718e3744 5327
d62a17ae 5328 if (time_str)
5329 routeadv = strtoul(time_str, NULL, 10);
718e3744 5330
d62a17ae 5331 if (set)
5332 ret = peer_advertise_interval_set(peer, routeadv);
5333 else
5334 ret = peer_advertise_interval_unset(peer);
718e3744 5335
d62a17ae 5336 return bgp_vty_return(vty, ret);
718e3744 5337}
5338
5339DEFUN (neighbor_advertise_interval,
5340 neighbor_advertise_interval_cmd,
9ccf14f7 5341 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5342 NEIGHBOR_STR
966f821c 5343 NEIGHBOR_ADDR_STR2
718e3744 5344 "Minimum interval between sending BGP routing updates\n"
5345 "time in seconds\n")
5346{
d62a17ae 5347 int idx_peer = 1;
5348 int idx_number = 3;
5349 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5350 argv[idx_number]->arg, 1);
718e3744 5351}
5352
5353DEFUN (no_neighbor_advertise_interval,
5354 no_neighbor_advertise_interval_cmd,
9ccf14f7 5355 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5356 NO_STR
5357 NEIGHBOR_STR
966f821c 5358 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5359 "Minimum interval between sending BGP routing updates\n"
5360 "time in seconds\n")
718e3744 5361{
d62a17ae 5362 int idx_peer = 2;
5363 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5364}
5365
6b0655a2 5366
518f0eb1
DS
5367/* Time to wait before processing route-map updates */
5368DEFUN (bgp_set_route_map_delay_timer,
5369 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5370 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5371 SET_STR
5372 "BGP route-map delay timer\n"
5373 "Time in secs to wait before processing route-map changes\n"
f414725f 5374 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5375{
d62a17ae 5376 int idx_number = 3;
d7c0a89a 5377 uint32_t rmap_delay_timer;
d62a17ae 5378
5379 if (argv[idx_number]->arg) {
5380 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5381 bm->rmap_update_timer = rmap_delay_timer;
5382
5383 /* if the dynamic update handling is being disabled, and a timer
5384 * is
5385 * running, stop the timer and act as if the timer has already
5386 * fired.
5387 */
5388 if (!rmap_delay_timer && bm->t_rmap_update) {
5389 BGP_TIMER_OFF(bm->t_rmap_update);
5390 thread_execute(bm->master, bgp_route_map_update_timer,
5391 NULL, 0);
5392 }
5393 return CMD_SUCCESS;
5394 } else {
5395 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5396 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5397 }
518f0eb1
DS
5398}
5399
5400DEFUN (no_bgp_set_route_map_delay_timer,
5401 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5402 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5403 NO_STR
3a2d747c 5404 BGP_STR
518f0eb1 5405 "Default BGP route-map delay timer\n"
8334fd5a
DW
5406 "Reset to default time to wait for processing route-map changes\n"
5407 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5408{
518f0eb1 5409
d62a17ae 5410 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5411
d62a17ae 5412 return CMD_SUCCESS;
518f0eb1
DS
5413}
5414
f414725f 5415
718e3744 5416/* neighbor interface */
d62a17ae 5417static int peer_interface_vty(struct vty *vty, const char *ip_str,
5418 const char *str)
718e3744 5419{
d62a17ae 5420 struct peer *peer;
718e3744 5421
d62a17ae 5422 peer = peer_lookup_vty(vty, ip_str);
5423 if (!peer || peer->conf_if) {
5424 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5425 return CMD_WARNING_CONFIG_FAILED;
5426 }
718e3744 5427
d62a17ae 5428 if (str)
5429 peer_interface_set(peer, str);
5430 else
5431 peer_interface_unset(peer);
718e3744 5432
d62a17ae 5433 return CMD_SUCCESS;
718e3744 5434}
5435
5436DEFUN (neighbor_interface,
5437 neighbor_interface_cmd,
9ccf14f7 5438 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5439 NEIGHBOR_STR
5440 NEIGHBOR_ADDR_STR
5441 "Interface\n"
5442 "Interface name\n")
5443{
d62a17ae 5444 int idx_ip = 1;
5445 int idx_word = 3;
5446 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5447}
5448
5449DEFUN (no_neighbor_interface,
5450 no_neighbor_interface_cmd,
9ccf14f7 5451 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5452 NO_STR
5453 NEIGHBOR_STR
16cedbb0 5454 NEIGHBOR_ADDR_STR2
718e3744 5455 "Interface\n"
5456 "Interface name\n")
5457{
d62a17ae 5458 int idx_peer = 2;
5459 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5460}
6b0655a2 5461
718e3744 5462DEFUN (neighbor_distribute_list,
5463 neighbor_distribute_list_cmd,
9ccf14f7 5464 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "IP access-list number\n"
5469 "IP access-list number (expanded range)\n"
5470 "IP Access-list name\n"
5471 "Filter incoming updates\n"
5472 "Filter outgoing updates\n")
5473{
d62a17ae 5474 int idx_peer = 1;
5475 int idx_acl = 3;
5476 int direct, ret;
5477 struct peer *peer;
a8206004 5478
d62a17ae 5479 const char *pstr = argv[idx_peer]->arg;
5480 const char *acl = argv[idx_acl]->arg;
5481 const char *inout = argv[argc - 1]->text;
a8206004 5482
d62a17ae 5483 peer = peer_and_group_lookup_vty(vty, pstr);
5484 if (!peer)
5485 return CMD_WARNING_CONFIG_FAILED;
a8206004 5486
d62a17ae 5487 /* Check filter direction. */
5488 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5489 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5490 direct, acl);
a8206004 5491
d62a17ae 5492 return bgp_vty_return(vty, ret);
718e3744 5493}
5494
d62a17ae 5495ALIAS_HIDDEN(
5496 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5497 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5498 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5499 "Filter updates to/from this neighbor\n"
5500 "IP access-list number\n"
5501 "IP access-list number (expanded range)\n"
5502 "IP Access-list name\n"
5503 "Filter incoming updates\n"
5504 "Filter outgoing updates\n")
596c17ba 5505
718e3744 5506DEFUN (no_neighbor_distribute_list,
5507 no_neighbor_distribute_list_cmd,
9ccf14f7 5508 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5509 NO_STR
5510 NEIGHBOR_STR
5511 NEIGHBOR_ADDR_STR2
5512 "Filter updates to/from this neighbor\n"
5513 "IP access-list number\n"
5514 "IP access-list number (expanded range)\n"
5515 "IP Access-list name\n"
5516 "Filter incoming updates\n"
5517 "Filter outgoing updates\n")
5518{
d62a17ae 5519 int idx_peer = 2;
5520 int direct, ret;
5521 struct peer *peer;
a8206004 5522
d62a17ae 5523 const char *pstr = argv[idx_peer]->arg;
5524 const char *inout = argv[argc - 1]->text;
a8206004 5525
d62a17ae 5526 peer = peer_and_group_lookup_vty(vty, pstr);
5527 if (!peer)
5528 return CMD_WARNING_CONFIG_FAILED;
a8206004 5529
d62a17ae 5530 /* Check filter direction. */
5531 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5532 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5533 direct);
a8206004 5534
d62a17ae 5535 return bgp_vty_return(vty, ret);
718e3744 5536}
6b0655a2 5537
d62a17ae 5538ALIAS_HIDDEN(
5539 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5540 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5541 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5542 "Filter updates to/from this neighbor\n"
5543 "IP access-list number\n"
5544 "IP access-list number (expanded range)\n"
5545 "IP Access-list name\n"
5546 "Filter incoming updates\n"
5547 "Filter outgoing updates\n")
596c17ba 5548
718e3744 5549/* Set prefix list to the peer. */
d62a17ae 5550static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5551 afi_t afi, safi_t safi,
5552 const char *name_str,
5553 const char *direct_str)
718e3744 5554{
d62a17ae 5555 int ret;
d62a17ae 5556 int direct = FILTER_IN;
cf9ac8bf 5557 struct peer *peer;
718e3744 5558
d62a17ae 5559 peer = peer_and_group_lookup_vty(vty, ip_str);
5560 if (!peer)
5561 return CMD_WARNING_CONFIG_FAILED;
718e3744 5562
d62a17ae 5563 /* Check filter direction. */
5564 if (strncmp(direct_str, "i", 1) == 0)
5565 direct = FILTER_IN;
5566 else if (strncmp(direct_str, "o", 1) == 0)
5567 direct = FILTER_OUT;
718e3744 5568
d62a17ae 5569 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5570
d62a17ae 5571 return bgp_vty_return(vty, ret);
718e3744 5572}
5573
d62a17ae 5574static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5575 afi_t afi, safi_t safi,
5576 const char *direct_str)
718e3744 5577{
d62a17ae 5578 int ret;
5579 struct peer *peer;
5580 int direct = FILTER_IN;
718e3744 5581
d62a17ae 5582 peer = peer_and_group_lookup_vty(vty, ip_str);
5583 if (!peer)
5584 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5585
d62a17ae 5586 /* Check filter direction. */
5587 if (strncmp(direct_str, "i", 1) == 0)
5588 direct = FILTER_IN;
5589 else if (strncmp(direct_str, "o", 1) == 0)
5590 direct = FILTER_OUT;
718e3744 5591
d62a17ae 5592 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5593
d62a17ae 5594 return bgp_vty_return(vty, ret);
718e3744 5595}
5596
5597DEFUN (neighbor_prefix_list,
5598 neighbor_prefix_list_cmd,
9ccf14f7 5599 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Filter updates to/from this neighbor\n"
5603 "Name of a prefix list\n"
5604 "Filter incoming updates\n"
5605 "Filter outgoing updates\n")
5606{
d62a17ae 5607 int idx_peer = 1;
5608 int idx_word = 3;
5609 int idx_in_out = 4;
5610 return peer_prefix_list_set_vty(
5611 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5612 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5613}
5614
d62a17ae 5615ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5616 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5617 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5618 "Filter updates to/from this neighbor\n"
5619 "Name of a prefix list\n"
5620 "Filter incoming updates\n"
5621 "Filter outgoing updates\n")
596c17ba 5622
718e3744 5623DEFUN (no_neighbor_prefix_list,
5624 no_neighbor_prefix_list_cmd,
9ccf14f7 5625 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5626 NO_STR
5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Filter updates to/from this neighbor\n"
5630 "Name of a prefix list\n"
5631 "Filter incoming updates\n"
5632 "Filter outgoing updates\n")
5633{
d62a17ae 5634 int idx_peer = 2;
5635 int idx_in_out = 5;
5636 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5637 bgp_node_afi(vty), bgp_node_safi(vty),
5638 argv[idx_in_out]->arg);
718e3744 5639}
6b0655a2 5640
d62a17ae 5641ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5643 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5644 "Filter updates to/from this neighbor\n"
5645 "Name of a prefix list\n"
5646 "Filter incoming updates\n"
5647 "Filter outgoing updates\n")
596c17ba 5648
d62a17ae 5649static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5650 safi_t safi, const char *name_str,
5651 const char *direct_str)
718e3744 5652{
d62a17ae 5653 int ret;
5654 struct peer *peer;
5655 int direct = FILTER_IN;
718e3744 5656
d62a17ae 5657 peer = peer_and_group_lookup_vty(vty, ip_str);
5658 if (!peer)
5659 return CMD_WARNING_CONFIG_FAILED;
718e3744 5660
d62a17ae 5661 /* Check filter direction. */
5662 if (strncmp(direct_str, "i", 1) == 0)
5663 direct = FILTER_IN;
5664 else if (strncmp(direct_str, "o", 1) == 0)
5665 direct = FILTER_OUT;
718e3744 5666
d62a17ae 5667 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5668
d62a17ae 5669 return bgp_vty_return(vty, ret);
718e3744 5670}
5671
d62a17ae 5672static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5673 safi_t safi, const char *direct_str)
718e3744 5674{
d62a17ae 5675 int ret;
5676 struct peer *peer;
5677 int direct = FILTER_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, "i", 1) == 0)
5685 direct = FILTER_IN;
5686 else if (strncmp(direct_str, "o", 1) == 0)
5687 direct = FILTER_OUT;
718e3744 5688
d62a17ae 5689 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5690
d62a17ae 5691 return bgp_vty_return(vty, ret);
718e3744 5692}
5693
5694DEFUN (neighbor_filter_list,
5695 neighbor_filter_list_cmd,
9ccf14f7 5696 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Establish BGP filters\n"
5700 "AS path access-list name\n"
5701 "Filter incoming routes\n"
5702 "Filter outgoing routes\n")
5703{
d62a17ae 5704 int idx_peer = 1;
5705 int idx_word = 3;
5706 int idx_in_out = 4;
5707 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5708 bgp_node_safi(vty), argv[idx_word]->arg,
5709 argv[idx_in_out]->arg);
718e3744 5710}
5711
d62a17ae 5712ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5713 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5714 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5715 "Establish BGP filters\n"
5716 "AS path access-list name\n"
5717 "Filter incoming routes\n"
5718 "Filter outgoing routes\n")
596c17ba 5719
718e3744 5720DEFUN (no_neighbor_filter_list,
5721 no_neighbor_filter_list_cmd,
9ccf14f7 5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Establish BGP filters\n"
5727 "AS path access-list name\n"
5728 "Filter incoming routes\n"
5729 "Filter outgoing routes\n")
5730{
d62a17ae 5731 int idx_peer = 2;
5732 int idx_in_out = 5;
5733 return peer_aslist_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_filter_list, no_neighbor_filter_list_hidden_cmd,
5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5740 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5741 "Establish BGP filters\n"
5742 "AS path access-list name\n"
5743 "Filter incoming routes\n"
5744 "Filter outgoing routes\n")
596c17ba 5745
718e3744 5746/* Set route-map to the peer. */
d62a17ae 5747static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5748 afi_t afi, safi_t safi, const char *name_str,
5749 const char *direct_str)
718e3744 5750{
d62a17ae 5751 int ret;
5752 struct peer *peer;
5753 int direct = RMAP_IN;
1de27621 5754 struct route_map *route_map;
718e3744 5755
d62a17ae 5756 peer = peer_and_group_lookup_vty(vty, ip_str);
5757 if (!peer)
5758 return CMD_WARNING_CONFIG_FAILED;
718e3744 5759
d62a17ae 5760 /* Check filter direction. */
5761 if (strncmp(direct_str, "in", 2) == 0)
5762 direct = RMAP_IN;
5763 else if (strncmp(direct_str, "o", 1) == 0)
5764 direct = RMAP_OUT;
718e3744 5765
1de27621
DA
5766 route_map = route_map_lookup_warn_noexist(vty, name_str);
5767 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 5768
d62a17ae 5769 return bgp_vty_return(vty, ret);
718e3744 5770}
5771
d62a17ae 5772static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5773 afi_t afi, safi_t safi,
5774 const char *direct_str)
718e3744 5775{
d62a17ae 5776 int ret;
5777 struct peer *peer;
5778 int direct = RMAP_IN;
718e3744 5779
d62a17ae 5780 peer = peer_and_group_lookup_vty(vty, ip_str);
5781 if (!peer)
5782 return CMD_WARNING_CONFIG_FAILED;
718e3744 5783
d62a17ae 5784 /* Check filter direction. */
5785 if (strncmp(direct_str, "in", 2) == 0)
5786 direct = RMAP_IN;
5787 else if (strncmp(direct_str, "o", 1) == 0)
5788 direct = RMAP_OUT;
718e3744 5789
d62a17ae 5790 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5791
d62a17ae 5792 return bgp_vty_return(vty, ret);
718e3744 5793}
5794
5795DEFUN (neighbor_route_map,
5796 neighbor_route_map_cmd,
9ccf14f7 5797 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5798 NEIGHBOR_STR
5799 NEIGHBOR_ADDR_STR2
5800 "Apply route map to neighbor\n"
5801 "Name of route map\n"
5802 "Apply map to incoming routes\n"
2a3d5731 5803 "Apply map to outbound routes\n")
718e3744 5804{
d62a17ae 5805 int idx_peer = 1;
5806 int idx_word = 3;
5807 int idx_in_out = 4;
5808 return peer_route_map_set_vty(
5809 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5810 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5811}
5812
d62a17ae 5813ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5814 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5815 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5816 "Apply route map to neighbor\n"
5817 "Name of route map\n"
5818 "Apply map to incoming routes\n"
5819 "Apply map to outbound routes\n")
596c17ba 5820
718e3744 5821DEFUN (no_neighbor_route_map,
5822 no_neighbor_route_map_cmd,
9ccf14f7 5823 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5824 NO_STR
5825 NEIGHBOR_STR
5826 NEIGHBOR_ADDR_STR2
5827 "Apply route map to neighbor\n"
5828 "Name of route map\n"
5829 "Apply map to incoming routes\n"
2a3d5731 5830 "Apply map to outbound routes\n")
718e3744 5831{
d62a17ae 5832 int idx_peer = 2;
5833 int idx_in_out = 5;
5834 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5835 bgp_node_afi(vty), bgp_node_safi(vty),
5836 argv[idx_in_out]->arg);
718e3744 5837}
6b0655a2 5838
d62a17ae 5839ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5840 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5842 "Apply route map to neighbor\n"
5843 "Name of route map\n"
5844 "Apply map to incoming routes\n"
5845 "Apply map to outbound routes\n")
596c17ba 5846
718e3744 5847/* Set unsuppress-map to the peer. */
d62a17ae 5848static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5849 afi_t afi, safi_t safi,
5850 const char *name_str)
718e3744 5851{
d62a17ae 5852 int ret;
5853 struct peer *peer;
1de27621 5854 struct route_map *route_map;
718e3744 5855
d62a17ae 5856 peer = peer_and_group_lookup_vty(vty, ip_str);
5857 if (!peer)
5858 return CMD_WARNING_CONFIG_FAILED;
718e3744 5859
1de27621
DA
5860 route_map = route_map_lookup_warn_noexist(vty, name_str);
5861 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 5862
d62a17ae 5863 return bgp_vty_return(vty, ret);
718e3744 5864}
5865
5866/* Unset route-map from the peer. */
d62a17ae 5867static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5868 afi_t afi, safi_t safi)
718e3744 5869{
d62a17ae 5870 int ret;
5871 struct peer *peer;
718e3744 5872
d62a17ae 5873 peer = peer_and_group_lookup_vty(vty, ip_str);
5874 if (!peer)
5875 return CMD_WARNING_CONFIG_FAILED;
718e3744 5876
d62a17ae 5877 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5878
d62a17ae 5879 return bgp_vty_return(vty, ret);
718e3744 5880}
5881
5882DEFUN (neighbor_unsuppress_map,
5883 neighbor_unsuppress_map_cmd,
9ccf14f7 5884 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Route-map to selectively unsuppress suppressed routes\n"
5888 "Name of route map\n")
5889{
d62a17ae 5890 int idx_peer = 1;
5891 int idx_word = 3;
5892 return peer_unsuppress_map_set_vty(
5893 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5894 argv[idx_word]->arg);
718e3744 5895}
5896
d62a17ae 5897ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5898 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5900 "Route-map to selectively unsuppress suppressed routes\n"
5901 "Name of route map\n")
596c17ba 5902
718e3744 5903DEFUN (no_neighbor_unsuppress_map,
5904 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5906 NO_STR
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Route-map to selectively unsuppress suppressed routes\n"
5910 "Name of route map\n")
5911{
d62a17ae 5912 int idx_peer = 2;
5913 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5914 bgp_node_afi(vty),
5915 bgp_node_safi(vty));
718e3744 5916}
6b0655a2 5917
d62a17ae 5918ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5919 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5920 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5921 "Route-map to selectively unsuppress suppressed routes\n"
5922 "Name of route map\n")
596c17ba 5923
d62a17ae 5924static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5925 afi_t afi, safi_t safi,
5926 const char *num_str,
5927 const char *threshold_str, int warning,
5928 const char *restart_str)
718e3744 5929{
d62a17ae 5930 int ret;
5931 struct peer *peer;
d7c0a89a
QY
5932 uint32_t max;
5933 uint8_t threshold;
5934 uint16_t restart;
718e3744 5935
d62a17ae 5936 peer = peer_and_group_lookup_vty(vty, ip_str);
5937 if (!peer)
5938 return CMD_WARNING_CONFIG_FAILED;
718e3744 5939
d62a17ae 5940 max = strtoul(num_str, NULL, 10);
5941 if (threshold_str)
5942 threshold = atoi(threshold_str);
5943 else
5944 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5945
d62a17ae 5946 if (restart_str)
5947 restart = atoi(restart_str);
5948 else
5949 restart = 0;
0a486e5f 5950
d62a17ae 5951 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5952 restart);
718e3744 5953
d62a17ae 5954 return bgp_vty_return(vty, ret);
718e3744 5955}
5956
d62a17ae 5957static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5958 afi_t afi, safi_t safi)
718e3744 5959{
d62a17ae 5960 int ret;
5961 struct peer *peer;
718e3744 5962
d62a17ae 5963 peer = peer_and_group_lookup_vty(vty, ip_str);
5964 if (!peer)
5965 return CMD_WARNING_CONFIG_FAILED;
718e3744 5966
d62a17ae 5967 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5968
d62a17ae 5969 return bgp_vty_return(vty, ret);
718e3744 5970}
5971
5972/* Maximum number of prefix configuration. prefix count is different
5973 for each peer configuration. So this configuration can be set for
5974 each peer configuration. */
5975DEFUN (neighbor_maximum_prefix,
5976 neighbor_maximum_prefix_cmd,
9ccf14f7 5977 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5978 NEIGHBOR_STR
5979 NEIGHBOR_ADDR_STR2
5980 "Maximum number of prefix accept from this peer\n"
5981 "maximum no. of prefix limit\n")
5982{
d62a17ae 5983 int idx_peer = 1;
5984 int idx_number = 3;
5985 return peer_maximum_prefix_set_vty(
5986 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5987 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5988}
5989
d62a17ae 5990ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5991 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5993 "Maximum number of prefix accept from this peer\n"
5994 "maximum no. of prefix limit\n")
596c17ba 5995
e0701b79 5996DEFUN (neighbor_maximum_prefix_threshold,
5997 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5998 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5999 NEIGHBOR_STR
6000 NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Threshold value (%) at which to generate a warning msg\n")
6004{
d62a17ae 6005 int idx_peer = 1;
6006 int idx_number = 3;
6007 int idx_number_2 = 4;
6008 return peer_maximum_prefix_set_vty(
6009 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6010 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 6011}
e0701b79 6012
d62a17ae 6013ALIAS_HIDDEN(
6014 neighbor_maximum_prefix_threshold,
6015 neighbor_maximum_prefix_threshold_hidden_cmd,
6016 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6018 "Maximum number of prefix accept from this peer\n"
6019 "maximum no. of prefix limit\n"
6020 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 6021
718e3744 6022DEFUN (neighbor_maximum_prefix_warning,
6023 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 6024 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6025 NEIGHBOR_STR
6026 NEIGHBOR_ADDR_STR2
6027 "Maximum number of prefix accept from this peer\n"
6028 "maximum no. of prefix limit\n"
6029 "Only give warning message when limit is exceeded\n")
6030{
d62a17ae 6031 int idx_peer = 1;
6032 int idx_number = 3;
6033 return peer_maximum_prefix_set_vty(
6034 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6035 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6036}
6037
d62a17ae 6038ALIAS_HIDDEN(
6039 neighbor_maximum_prefix_warning,
6040 neighbor_maximum_prefix_warning_hidden_cmd,
6041 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6043 "Maximum number of prefix accept from this peer\n"
6044 "maximum no. of prefix limit\n"
6045 "Only give warning message when limit is exceeded\n")
596c17ba 6046
e0701b79 6047DEFUN (neighbor_maximum_prefix_threshold_warning,
6048 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6049 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "Maximum number of prefix accept from this peer\n"
6053 "maximum no. of prefix limit\n"
6054 "Threshold value (%) at which to generate a warning msg\n"
6055 "Only give warning message when limit is exceeded\n")
6056{
d62a17ae 6057 int idx_peer = 1;
6058 int idx_number = 3;
6059 int idx_number_2 = 4;
6060 return peer_maximum_prefix_set_vty(
6061 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6062 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6063}
6064
d62a17ae 6065ALIAS_HIDDEN(
6066 neighbor_maximum_prefix_threshold_warning,
6067 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6068 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6069 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6070 "Maximum number of prefix accept from this peer\n"
6071 "maximum no. of prefix limit\n"
6072 "Threshold value (%) at which to generate a warning msg\n"
6073 "Only give warning message when limit is exceeded\n")
596c17ba 6074
0a486e5f 6075DEFUN (neighbor_maximum_prefix_restart,
6076 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6077 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6078 NEIGHBOR_STR
6079 NEIGHBOR_ADDR_STR2
6080 "Maximum number of prefix accept from this peer\n"
6081 "maximum no. of prefix limit\n"
6082 "Restart bgp connection after limit is exceeded\n"
efd7904e 6083 "Restart interval in minutes\n")
0a486e5f 6084{
d62a17ae 6085 int idx_peer = 1;
6086 int idx_number = 3;
6087 int idx_number_2 = 5;
6088 return peer_maximum_prefix_set_vty(
6089 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6090 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6091}
6092
d62a17ae 6093ALIAS_HIDDEN(
6094 neighbor_maximum_prefix_restart,
6095 neighbor_maximum_prefix_restart_hidden_cmd,
6096 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6097 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6098 "Maximum number of prefix accept from this peer\n"
6099 "maximum no. of prefix limit\n"
6100 "Restart bgp connection after limit is exceeded\n"
efd7904e 6101 "Restart interval in minutes\n")
596c17ba 6102
0a486e5f 6103DEFUN (neighbor_maximum_prefix_threshold_restart,
6104 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6105 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6106 NEIGHBOR_STR
6107 NEIGHBOR_ADDR_STR2
16cedbb0 6108 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6109 "maximum no. of prefix limit\n"
6110 "Threshold value (%) at which to generate a warning msg\n"
6111 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6112 "Restart interval in minutes\n")
0a486e5f 6113{
d62a17ae 6114 int idx_peer = 1;
6115 int idx_number = 3;
6116 int idx_number_2 = 4;
6117 int idx_number_3 = 6;
6118 return peer_maximum_prefix_set_vty(
6119 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6120 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6121 argv[idx_number_3]->arg);
6122}
6123
6124ALIAS_HIDDEN(
6125 neighbor_maximum_prefix_threshold_restart,
6126 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6127 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6128 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6129 "Maximum number of prefixes to accept from this peer\n"
6130 "maximum no. of prefix limit\n"
6131 "Threshold value (%) at which to generate a warning msg\n"
6132 "Restart bgp connection after limit is exceeded\n"
6133 "Restart interval in minutes\n")
596c17ba 6134
718e3744 6135DEFUN (no_neighbor_maximum_prefix,
6136 no_neighbor_maximum_prefix_cmd,
d04c479d 6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6138 NO_STR
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
16cedbb0 6141 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6142 "maximum no. of prefix limit\n"
6143 "Threshold value (%) at which to generate a warning msg\n"
6144 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6145 "Restart interval in minutes\n"
31500417 6146 "Only give warning message when limit is exceeded\n")
718e3744 6147{
d62a17ae 6148 int idx_peer = 2;
6149 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6150 bgp_node_afi(vty),
6151 bgp_node_safi(vty));
718e3744 6152}
e52702f2 6153
d62a17ae 6154ALIAS_HIDDEN(
6155 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6156 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6157 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6158 "Maximum number of prefixes to accept from this peer\n"
6159 "maximum no. of prefix limit\n"
6160 "Threshold value (%) at which to generate a warning msg\n"
6161 "Restart bgp connection after limit is exceeded\n"
6162 "Restart interval in minutes\n"
6163 "Only give warning message when limit is exceeded\n")
596c17ba 6164
718e3744 6165
718e3744 6166/* "neighbor allowas-in" */
6167DEFUN (neighbor_allowas_in,
6168 neighbor_allowas_in_cmd,
fd8503f5 6169 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6170 NEIGHBOR_STR
6171 NEIGHBOR_ADDR_STR2
31500417 6172 "Accept as-path with my AS present in it\n"
f79f7a7b 6173 "Number of occurrences of AS number\n"
fd8503f5 6174 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6175{
d62a17ae 6176 int idx_peer = 1;
6177 int idx_number_origin = 3;
6178 int ret;
6179 int origin = 0;
6180 struct peer *peer;
6181 int allow_num = 0;
6182
6183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6184 if (!peer)
6185 return CMD_WARNING_CONFIG_FAILED;
6186
6187 if (argc <= idx_number_origin)
6188 allow_num = 3;
6189 else {
6190 if (argv[idx_number_origin]->type == WORD_TKN)
6191 origin = 1;
6192 else
6193 allow_num = atoi(argv[idx_number_origin]->arg);
6194 }
6195
6196 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6197 allow_num, origin);
6198
6199 return bgp_vty_return(vty, ret);
6200}
6201
6202ALIAS_HIDDEN(
6203 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6206 "Accept as-path with my AS present in it\n"
f79f7a7b 6207 "Number of occurrences of AS number\n"
d62a17ae 6208 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6209
718e3744 6210DEFUN (no_neighbor_allowas_in,
6211 no_neighbor_allowas_in_cmd,
fd8503f5 6212 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6213 NO_STR
6214 NEIGHBOR_STR
6215 NEIGHBOR_ADDR_STR2
8334fd5a 6216 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6217 "Number of occurrences of AS number\n"
fd8503f5 6218 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6219{
d62a17ae 6220 int idx_peer = 2;
6221 int ret;
6222 struct peer *peer;
718e3744 6223
d62a17ae 6224 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6225 if (!peer)
6226 return CMD_WARNING_CONFIG_FAILED;
718e3744 6227
d62a17ae 6228 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6229 bgp_node_safi(vty));
718e3744 6230
d62a17ae 6231 return bgp_vty_return(vty, ret);
718e3744 6232}
6b0655a2 6233
d62a17ae 6234ALIAS_HIDDEN(
6235 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6236 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6237 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6238 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6239 "Number of occurrences of AS number\n"
d62a17ae 6240 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6241
fa411a21
NH
6242DEFUN (neighbor_ttl_security,
6243 neighbor_ttl_security_cmd,
7ebe625c 6244 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6245 NEIGHBOR_STR
7ebe625c 6246 NEIGHBOR_ADDR_STR2
16cedbb0 6247 "BGP ttl-security parameters\n"
d7fa34c1
QY
6248 "Specify the maximum number of hops to the BGP peer\n"
6249 "Number of hops to BGP peer\n")
fa411a21 6250{
d62a17ae 6251 int idx_peer = 1;
6252 int idx_number = 4;
6253 struct peer *peer;
6254 int gtsm_hops;
6255
6256 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6257 if (!peer)
6258 return CMD_WARNING_CONFIG_FAILED;
6259
6260 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6261
7ebe625c
QY
6262 /*
6263 * If 'neighbor swpX', then this is for directly connected peers,
6264 * we should not accept a ttl-security hops value greater than 1.
6265 */
6266 if (peer->conf_if && (gtsm_hops > 1)) {
6267 vty_out(vty,
6268 "%s is directly connected peer, hops cannot exceed 1\n",
6269 argv[idx_peer]->arg);
6270 return CMD_WARNING_CONFIG_FAILED;
6271 }
6272
d62a17ae 6273 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6274}
6275
6276DEFUN (no_neighbor_ttl_security,
6277 no_neighbor_ttl_security_cmd,
7ebe625c 6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6279 NO_STR
6280 NEIGHBOR_STR
7ebe625c 6281 NEIGHBOR_ADDR_STR2
16cedbb0 6282 "BGP ttl-security parameters\n"
3a2d747c
QY
6283 "Specify the maximum number of hops to the BGP peer\n"
6284 "Number of hops to BGP peer\n")
fa411a21 6285{
d62a17ae 6286 int idx_peer = 2;
6287 struct peer *peer;
fa411a21 6288
d62a17ae 6289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6290 if (!peer)
6291 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6292
d62a17ae 6293 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6294}
6b0655a2 6295
adbac85e
DW
6296DEFUN (neighbor_addpath_tx_all_paths,
6297 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6298 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6299 NEIGHBOR_STR
6300 NEIGHBOR_ADDR_STR2
6301 "Use addpath to advertise all paths to a neighbor\n")
6302{
d62a17ae 6303 int idx_peer = 1;
6304 struct peer *peer;
adbac85e 6305
d62a17ae 6306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6307 if (!peer)
6308 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6309
dcc68b5e
MS
6310 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6311 BGP_ADDPATH_ALL);
6312 return CMD_SUCCESS;
adbac85e
DW
6313}
6314
d62a17ae 6315ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6316 neighbor_addpath_tx_all_paths_hidden_cmd,
6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6318 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6319 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6320
adbac85e
DW
6321DEFUN (no_neighbor_addpath_tx_all_paths,
6322 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6323 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6324 NO_STR
6325 NEIGHBOR_STR
6326 NEIGHBOR_ADDR_STR2
6327 "Use addpath to advertise all paths to a neighbor\n")
6328{
d62a17ae 6329 int idx_peer = 2;
dcc68b5e
MS
6330 struct peer *peer;
6331
6332 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6333 if (!peer)
6334 return CMD_WARNING_CONFIG_FAILED;
6335
6336 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6337 != BGP_ADDPATH_ALL) {
6338 vty_out(vty,
6339 "%% Peer not currently configured to transmit all paths.");
6340 return CMD_WARNING_CONFIG_FAILED;
6341 }
6342
6343 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6344 BGP_ADDPATH_NONE);
6345
6346 return CMD_SUCCESS;
adbac85e
DW
6347}
6348
d62a17ae 6349ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6350 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6351 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6352 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6353 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6354
06370dac
DW
6355DEFUN (neighbor_addpath_tx_bestpath_per_as,
6356 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6357 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6358 NEIGHBOR_STR
6359 NEIGHBOR_ADDR_STR2
6360 "Use addpath to advertise the bestpath per each neighboring AS\n")
6361{
d62a17ae 6362 int idx_peer = 1;
6363 struct peer *peer;
06370dac 6364
d62a17ae 6365 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6366 if (!peer)
6367 return CMD_WARNING_CONFIG_FAILED;
06370dac 6368
dcc68b5e
MS
6369 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6370 BGP_ADDPATH_BEST_PER_AS);
6371
6372 return CMD_SUCCESS;
06370dac
DW
6373}
6374
d62a17ae 6375ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6376 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6377 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6378 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6379 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6380
06370dac
DW
6381DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6382 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6383 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6384 NO_STR
6385 NEIGHBOR_STR
6386 NEIGHBOR_ADDR_STR2
6387 "Use addpath to advertise the bestpath per each neighboring AS\n")
6388{
d62a17ae 6389 int idx_peer = 2;
dcc68b5e
MS
6390 struct peer *peer;
6391
6392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6393 if (!peer)
6394 return CMD_WARNING_CONFIG_FAILED;
6395
6396 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6397 != BGP_ADDPATH_BEST_PER_AS) {
6398 vty_out(vty,
6399 "%% Peer not currently configured to transmit all best path per as.");
6400 return CMD_WARNING_CONFIG_FAILED;
6401 }
6402
6403 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6404 BGP_ADDPATH_NONE);
6405
6406 return CMD_SUCCESS;
06370dac
DW
6407}
6408
d62a17ae 6409ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6410 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6411 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6414
b9c7bc5a
PZ
6415static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6416 struct ecommunity **list)
ddb5b488 6417{
b9c7bc5a
PZ
6418 struct ecommunity *ecom = NULL;
6419 struct ecommunity *ecomadd;
ddb5b488 6420
b9c7bc5a 6421 for (; argc; --argc, ++argv) {
ddb5b488 6422
b9c7bc5a
PZ
6423 ecomadd = ecommunity_str2com(argv[0]->arg,
6424 ECOMMUNITY_ROUTE_TARGET, 0);
6425 if (!ecomadd) {
6426 vty_out(vty, "Malformed community-list value\n");
6427 if (ecom)
6428 ecommunity_free(&ecom);
6429 return CMD_WARNING_CONFIG_FAILED;
6430 }
ddb5b488 6431
b9c7bc5a
PZ
6432 if (ecom) {
6433 ecommunity_merge(ecom, ecomadd);
6434 ecommunity_free(&ecomadd);
6435 } else {
6436 ecom = ecomadd;
6437 }
6438 }
6439
6440 if (*list) {
6441 ecommunity_free(&*list);
ddb5b488 6442 }
b9c7bc5a
PZ
6443 *list = ecom;
6444
6445 return CMD_SUCCESS;
ddb5b488
PZ
6446}
6447
0ca70ba5
DS
6448/*
6449 * v2vimport is true if we are handling a `import vrf ...` command
6450 */
6451static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 6452{
0ca70ba5
DS
6453 afi_t afi;
6454
ddb5b488 6455 switch (vty->node) {
b9c7bc5a 6456 case BGP_IPV4_NODE:
0ca70ba5
DS
6457 afi = AFI_IP;
6458 break;
b9c7bc5a 6459 case BGP_IPV6_NODE:
0ca70ba5
DS
6460 afi = AFI_IP6;
6461 break;
ddb5b488
PZ
6462 default:
6463 vty_out(vty,
b9c7bc5a 6464 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 6465 return AFI_MAX;
ddb5b488 6466 }
69b07479 6467
0ca70ba5
DS
6468 if (!v2vimport) {
6469 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6470 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6471 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6472 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6473 vty_out(vty,
6474 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6475 return AFI_MAX;
6476 }
6477 } else {
6478 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6479 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6480 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6481 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6482 vty_out(vty,
6483 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6484 return AFI_MAX;
6485 }
6486 }
6487 return afi;
ddb5b488
PZ
6488}
6489
b9c7bc5a
PZ
6490DEFPY (af_rd_vpn_export,
6491 af_rd_vpn_export_cmd,
6492 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6493 NO_STR
ddb5b488 6494 "Specify route distinguisher\n"
b9c7bc5a
PZ
6495 "Between current address-family and vpn\n"
6496 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6497 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6498{
6499 VTY_DECLVAR_CONTEXT(bgp, bgp);
6500 struct prefix_rd prd;
6501 int ret;
ddb5b488 6502 afi_t afi;
b9c7bc5a
PZ
6503 int idx = 0;
6504 int yes = 1;
ddb5b488 6505
b9c7bc5a 6506 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6507 yes = 0;
b9c7bc5a
PZ
6508
6509 if (yes) {
6510 ret = str2prefix_rd(rd_str, &prd);
6511 if (!ret) {
6512 vty_out(vty, "%% Malformed rd\n");
6513 return CMD_WARNING_CONFIG_FAILED;
6514 }
ddb5b488
PZ
6515 }
6516
0ca70ba5 6517 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6518 if (afi == AFI_MAX)
6519 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6520
69b07479
DS
6521 /*
6522 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6523 */
6524 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6525 bgp_get_default(), bgp);
ddb5b488 6526
69b07479
DS
6527 if (yes) {
6528 bgp->vpn_policy[afi].tovpn_rd = prd;
6529 SET_FLAG(bgp->vpn_policy[afi].flags,
6530 BGP_VPN_POLICY_TOVPN_RD_SET);
6531 } else {
6532 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6533 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
6534 }
6535
69b07479
DS
6536 /* post-change: re-export vpn routes */
6537 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6538 bgp_get_default(), bgp);
6539
ddb5b488
PZ
6540 return CMD_SUCCESS;
6541}
6542
b9c7bc5a
PZ
6543ALIAS (af_rd_vpn_export,
6544 af_no_rd_vpn_export_cmd,
6545 "no rd vpn export",
ddb5b488 6546 NO_STR
b9c7bc5a
PZ
6547 "Specify route distinguisher\n"
6548 "Between current address-family and vpn\n"
6549 "For routes leaked from current address-family to vpn\n")
ddb5b488 6550
b9c7bc5a
PZ
6551DEFPY (af_label_vpn_export,
6552 af_label_vpn_export_cmd,
e70e9f8e 6553 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 6554 NO_STR
ddb5b488 6555 "label value for VRF\n"
b9c7bc5a
PZ
6556 "Between current address-family and vpn\n"
6557 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
6558 "Label Value <0-1048575>\n"
6559 "Automatically assign a label\n")
ddb5b488
PZ
6560{
6561 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6562 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 6563 afi_t afi;
b9c7bc5a
PZ
6564 int idx = 0;
6565 int yes = 1;
6566
6567 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6568 yes = 0;
ddb5b488 6569
21a16cc2
PZ
6570 /* If "no ...", squash trailing parameter */
6571 if (!yes)
6572 label_auto = NULL;
6573
e70e9f8e
PZ
6574 if (yes) {
6575 if (!label_auto)
6576 label = label_val; /* parser should force unsigned */
6577 }
ddb5b488 6578
0ca70ba5 6579 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6580 if (afi == AFI_MAX)
6581 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 6582
e70e9f8e 6583
69b07479
DS
6584 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6585 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6586 /* no change */
6587 return CMD_SUCCESS;
e70e9f8e 6588
69b07479
DS
6589 /*
6590 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6591 */
6592 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6593 bgp_get_default(), bgp);
6594
6595 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6596 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6597
6598 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6599
6600 /*
6601 * label has previously been automatically
6602 * assigned by labelpool: release it
6603 *
6604 * NB if tovpn_label == MPLS_LABEL_NONE it
6605 * means the automatic assignment is in flight
6606 * and therefore the labelpool callback must
6607 * detect that the auto label is not needed.
6608 */
6609
6610 bgp_lp_release(LP_TYPE_VRF,
6611 &bgp->vpn_policy[afi],
6612 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 6613 }
69b07479
DS
6614 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6615 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6616 }
ddb5b488 6617
69b07479
DS
6618 bgp->vpn_policy[afi].tovpn_label = label;
6619 if (label_auto) {
6620 SET_FLAG(bgp->vpn_policy[afi].flags,
6621 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6622 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6623 vpn_leak_label_callback);
ddb5b488
PZ
6624 }
6625
69b07479
DS
6626 /* post-change: re-export vpn routes */
6627 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6628 bgp_get_default(), bgp);
6629
ddb5b488
PZ
6630 return CMD_SUCCESS;
6631}
6632
b9c7bc5a
PZ
6633ALIAS (af_label_vpn_export,
6634 af_no_label_vpn_export_cmd,
6635 "no label vpn export",
6636 NO_STR
6637 "label value for VRF\n"
6638 "Between current address-family and vpn\n"
6639 "For routes leaked from current address-family to vpn\n")
ddb5b488 6640
b9c7bc5a
PZ
6641DEFPY (af_nexthop_vpn_export,
6642 af_nexthop_vpn_export_cmd,
6643 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6644 NO_STR
ddb5b488 6645 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6648 "IPv4 prefix\n"
6649 "IPv6 prefix\n")
6650{
6651 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 6652 afi_t afi;
ddb5b488 6653 struct prefix p;
b9c7bc5a
PZ
6654 int idx = 0;
6655 int yes = 1;
ddb5b488 6656
b9c7bc5a 6657 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6658 yes = 0;
b9c7bc5a
PZ
6659
6660 if (yes) {
6661 if (!sockunion2hostprefix(nexthop_str, &p))
6662 return CMD_WARNING_CONFIG_FAILED;
6663 }
ddb5b488 6664
0ca70ba5 6665 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6666 if (afi == AFI_MAX)
6667 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6668
69b07479
DS
6669 /*
6670 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6671 */
6672 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6673 bgp_get_default(), bgp);
ddb5b488 6674
69b07479
DS
6675 if (yes) {
6676 bgp->vpn_policy[afi].tovpn_nexthop = p;
6677 SET_FLAG(bgp->vpn_policy[afi].flags,
6678 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6679 } else {
6680 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6681 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
6682 }
6683
69b07479
DS
6684 /* post-change: re-export vpn routes */
6685 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6686 bgp_get_default(), bgp);
6687
ddb5b488
PZ
6688 return CMD_SUCCESS;
6689}
6690
b9c7bc5a
PZ
6691ALIAS (af_nexthop_vpn_export,
6692 af_no_nexthop_vpn_export_cmd,
6693 "no nexthop vpn export",
ddb5b488 6694 NO_STR
b9c7bc5a
PZ
6695 "Specify next hop to use for VRF advertised prefixes\n"
6696 "Between current address-family and vpn\n"
6697 "For routes leaked from current address-family to vpn\n")
ddb5b488 6698
b9c7bc5a 6699static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6700{
b9c7bc5a
PZ
6701 if (!strcmp(dstr, "import")) {
6702 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6703 } else if (!strcmp(dstr, "export")) {
6704 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6705 } else if (!strcmp(dstr, "both")) {
6706 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6707 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6708 } else {
6709 vty_out(vty, "%% direction parse error\n");
6710 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6711 }
ddb5b488
PZ
6712 return CMD_SUCCESS;
6713}
6714
b9c7bc5a
PZ
6715DEFPY (af_rt_vpn_imexport,
6716 af_rt_vpn_imexport_cmd,
6717 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6718 NO_STR
6719 "Specify route target list\n"
ddb5b488 6720 "Specify route target list\n"
b9c7bc5a
PZ
6721 "Between current address-family and vpn\n"
6722 "For routes leaked from vpn to current address-family: match any\n"
6723 "For routes leaked from current address-family to vpn: set\n"
6724 "both import: match any and export: set\n"
ddb5b488
PZ
6725 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6726{
6727 VTY_DECLVAR_CONTEXT(bgp, bgp);
6728 int ret;
6729 struct ecommunity *ecom = NULL;
6730 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6731 vpn_policy_direction_t dir;
6732 afi_t afi;
6733 int idx = 0;
b9c7bc5a 6734 int yes = 1;
ddb5b488 6735
b9c7bc5a 6736 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6737 yes = 0;
b9c7bc5a 6738
0ca70ba5 6739 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6740 if (afi == AFI_MAX)
6741 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6742
b9c7bc5a 6743 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6744 if (ret != CMD_SUCCESS)
6745 return ret;
6746
b9c7bc5a
PZ
6747 if (yes) {
6748 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6749 vty_out(vty, "%% Missing RTLIST\n");
6750 return CMD_WARNING_CONFIG_FAILED;
6751 }
6752 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6753 if (ret != CMD_SUCCESS) {
6754 return ret;
6755 }
ddb5b488
PZ
6756 }
6757
69b07479
DS
6758 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6759 if (!dodir[dir])
ddb5b488 6760 continue;
ddb5b488 6761
69b07479 6762 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6763
69b07479
DS
6764 if (yes) {
6765 if (bgp->vpn_policy[afi].rtlist[dir])
6766 ecommunity_free(
6767 &bgp->vpn_policy[afi].rtlist[dir]);
6768 bgp->vpn_policy[afi].rtlist[dir] =
6769 ecommunity_dup(ecom);
6770 } else {
6771 if (bgp->vpn_policy[afi].rtlist[dir])
6772 ecommunity_free(
6773 &bgp->vpn_policy[afi].rtlist[dir]);
6774 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 6775 }
69b07479
DS
6776
6777 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6778 }
69b07479 6779
d555f3e9
PZ
6780 if (ecom)
6781 ecommunity_free(&ecom);
ddb5b488
PZ
6782
6783 return CMD_SUCCESS;
6784}
6785
b9c7bc5a
PZ
6786ALIAS (af_rt_vpn_imexport,
6787 af_no_rt_vpn_imexport_cmd,
6788 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6789 NO_STR
6790 "Specify route target list\n"
b9c7bc5a
PZ
6791 "Specify route target list\n"
6792 "Between current address-family and vpn\n"
6793 "For routes leaked from vpn to current address-family\n"
6794 "For routes leaked from current address-family to vpn\n"
6795 "both import and export\n")
6796
6797DEFPY (af_route_map_vpn_imexport,
6798 af_route_map_vpn_imexport_cmd,
6799/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6800 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6801 NO_STR
ddb5b488 6802 "Specify route map\n"
b9c7bc5a
PZ
6803 "Between current address-family and vpn\n"
6804 "For routes leaked from vpn to current address-family\n"
6805 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6806 "name of route-map\n")
6807{
6808 VTY_DECLVAR_CONTEXT(bgp, bgp);
6809 int ret;
6810 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
6811 vpn_policy_direction_t dir;
6812 afi_t afi;
ddb5b488 6813 int idx = 0;
b9c7bc5a 6814 int yes = 1;
ddb5b488 6815
b9c7bc5a 6816 if (argv_find(argv, argc, "no", &idx))
d555f3e9 6817 yes = 0;
b9c7bc5a 6818
0ca70ba5 6819 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
6820 if (afi == AFI_MAX)
6821 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6822
b9c7bc5a 6823 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6824 if (ret != CMD_SUCCESS)
6825 return ret;
6826
69b07479
DS
6827 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6828 if (!dodir[dir])
ddb5b488 6829 continue;
ddb5b488 6830
69b07479 6831 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 6832
69b07479
DS
6833 if (yes) {
6834 if (bgp->vpn_policy[afi].rmap_name[dir])
6835 XFREE(MTYPE_ROUTE_MAP_NAME,
6836 bgp->vpn_policy[afi].rmap_name[dir]);
6837 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6838 MTYPE_ROUTE_MAP_NAME, rmap_str);
6839 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6840 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6841 if (!bgp->vpn_policy[afi].rmap[dir])
6842 return CMD_SUCCESS;
6843 } else {
6844 if (bgp->vpn_policy[afi].rmap_name[dir])
6845 XFREE(MTYPE_ROUTE_MAP_NAME,
6846 bgp->vpn_policy[afi].rmap_name[dir]);
6847 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6848 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 6849 }
69b07479
DS
6850
6851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
6852 }
6853
6854 return CMD_SUCCESS;
6855}
6856
b9c7bc5a
PZ
6857ALIAS (af_route_map_vpn_imexport,
6858 af_no_route_map_vpn_imexport_cmd,
6859 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6860 NO_STR
6861 "Specify route map\n"
b9c7bc5a
PZ
6862 "Between current address-family and vpn\n"
6863 "For routes leaked from vpn to current address-family\n"
6864 "For routes leaked from current address-family to vpn\n")
6865
bb4f6190
DS
6866DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6867 "[no] import vrf route-map RMAP$rmap_str",
6868 NO_STR
6869 "Import routes from another VRF\n"
6870 "Vrf routes being filtered\n"
6871 "Specify route map\n"
6872 "name of route-map\n")
6873{
6874 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
6875 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6876 afi_t afi;
6877 int idx = 0;
6878 int yes = 1;
6879 struct bgp *bgp_default;
6880
6881 if (argv_find(argv, argc, "no", &idx))
6882 yes = 0;
6883
0ca70ba5 6884 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
6885 if (afi == AFI_MAX)
6886 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
6887
6888 bgp_default = bgp_get_default();
6889 if (!bgp_default) {
6890 int32_t ret;
6891 as_t as = bgp->as;
6892
6893 /* Auto-create assuming the same AS */
6894 ret = bgp_get(&bgp_default, &as, NULL,
6895 BGP_INSTANCE_TYPE_DEFAULT);
6896
6897 if (ret) {
6898 vty_out(vty,
6899 "VRF default is not configured as a bgp instance\n");
6900 return CMD_WARNING;
6901 }
6902 }
6903
69b07479 6904 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 6905
69b07479
DS
6906 if (yes) {
6907 if (bgp->vpn_policy[afi].rmap_name[dir])
6908 XFREE(MTYPE_ROUTE_MAP_NAME,
6909 bgp->vpn_policy[afi].rmap_name[dir]);
6910 bgp->vpn_policy[afi].rmap_name[dir] =
6911 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6912 bgp->vpn_policy[afi].rmap[dir] =
1de27621 6913 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
6914 if (!bgp->vpn_policy[afi].rmap[dir])
6915 return CMD_SUCCESS;
6916 } else {
6917 if (bgp->vpn_policy[afi].rmap_name[dir])
6918 XFREE(MTYPE_ROUTE_MAP_NAME,
6919 bgp->vpn_policy[afi].rmap_name[dir]);
6920 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6921 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
6922 }
6923
69b07479
DS
6924 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6925
bb4f6190
DS
6926 return CMD_SUCCESS;
6927}
6928
6929ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6930 "no import vrf route-map",
6931 NO_STR
6932 "Import routes from another VRF\n"
6933 "Vrf routes being filtered\n"
6934 "Specify route map\n")
6935
4d1b335c
DA
6936DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6937 "[no] import vrf VIEWVRFNAME$import_name",
6938 NO_STR
6939 "Import routes from another VRF\n"
6940 "VRF to import from\n"
6941 "The name of the VRF\n")
12a844a5
DS
6942{
6943 VTY_DECLVAR_CONTEXT(bgp, bgp);
6944 struct listnode *node;
79ef8664
DS
6945 struct bgp *vrf_bgp, *bgp_default;
6946 int32_t ret = 0;
6947 as_t as = bgp->as;
12a844a5
DS
6948 bool remove = false;
6949 int32_t idx = 0;
6950 char *vname;
a8dadcf6 6951 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
6952 safi_t safi;
6953 afi_t afi;
6954
867f0cca 6955 if (import_name == NULL) {
6956 vty_out(vty, "%% Missing import name\n");
6957 return CMD_WARNING;
6958 }
6959
12a844a5
DS
6960 if (argv_find(argv, argc, "no", &idx))
6961 remove = true;
6962
0ca70ba5
DS
6963 afi = vpn_policy_getafi(vty, bgp, true);
6964 if (afi == AFI_MAX)
6965 return CMD_WARNING_CONFIG_FAILED;
6966
12a844a5
DS
6967 safi = bgp_node_safi(vty);
6968
25679caa 6969 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 6970 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
6971 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6972 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6973 remove ? "unimport" : "import", import_name);
6974 return CMD_WARNING;
6975 }
6976
79ef8664
DS
6977 bgp_default = bgp_get_default();
6978 if (!bgp_default) {
6979 /* Auto-create assuming the same AS */
6980 ret = bgp_get(&bgp_default, &as, NULL,
6981 BGP_INSTANCE_TYPE_DEFAULT);
6982
6983 if (ret) {
6984 vty_out(vty,
6985 "VRF default is not configured as a bgp instance\n");
6986 return CMD_WARNING;
6987 }
6988 }
6989
12a844a5
DS
6990 vrf_bgp = bgp_lookup_by_name(import_name);
6991 if (!vrf_bgp) {
5742e42b 6992 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
6993 vrf_bgp = bgp_default;
6994 else
0fb8d6e6
DS
6995 /* Auto-create assuming the same AS */
6996 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 6997
6e2c7fe6 6998 if (ret) {
020a3f60
DS
6999 vty_out(vty,
7000 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7001 import_name);
7002 return CMD_WARNING;
7003 }
12a844a5
DS
7004 }
7005
12a844a5 7006 if (remove) {
44338987 7007 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7008 } else {
44338987 7009 /* Already importing from "import_vrf"? */
12a844a5
DS
7010 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7011 vname)) {
7012 if (strcmp(vname, import_name) == 0)
7013 return CMD_WARNING;
7014 }
7015
44338987 7016 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7017 }
7018
7019 return CMD_SUCCESS;
7020}
7021
b9c7bc5a
PZ
7022/* This command is valid only in a bgp vrf instance or the default instance */
7023DEFPY (bgp_imexport_vpn,
7024 bgp_imexport_vpn_cmd,
7025 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7026 NO_STR
7027 "Import routes to this address-family\n"
7028 "Export routes from this address-family\n"
7029 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7030{
7031 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7032 int previous_state;
ddb5b488 7033 afi_t afi;
b9c7bc5a 7034 safi_t safi;
ddb5b488 7035 int idx = 0;
b9c7bc5a
PZ
7036 int yes = 1;
7037 int flag;
7038 vpn_policy_direction_t dir;
ddb5b488 7039
b9c7bc5a 7040 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7041 yes = 0;
ddb5b488 7042
b9c7bc5a
PZ
7043 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7044 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7045
b9c7bc5a
PZ
7046 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7047 return CMD_WARNING_CONFIG_FAILED;
7048 }
ddb5b488 7049
b9c7bc5a
PZ
7050 afi = bgp_node_afi(vty);
7051 safi = bgp_node_safi(vty);
7052 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7053 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7054 return CMD_WARNING_CONFIG_FAILED;
7055 }
ddb5b488 7056
b9c7bc5a
PZ
7057 if (!strcmp(direction_str, "import")) {
7058 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7059 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7060 } else if (!strcmp(direction_str, "export")) {
7061 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7062 dir = BGP_VPN_POLICY_DIR_TOVPN;
7063 } else {
7064 vty_out(vty, "%% unknown direction %s\n", direction_str);
7065 return CMD_WARNING_CONFIG_FAILED;
7066 }
7067
7068 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7069
b9c7bc5a
PZ
7070 if (yes) {
7071 SET_FLAG(bgp->af_flags[afi][safi], flag);
7072 if (!previous_state) {
7073 /* trigger export current vrf */
ddb5b488
PZ
7074 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7075 }
b9c7bc5a
PZ
7076 } else {
7077 if (previous_state) {
7078 /* trigger un-export current vrf */
7079 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7080 }
7081 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7082 }
7083
7084 return CMD_SUCCESS;
7085}
7086
301ad80a
PG
7087DEFPY (af_routetarget_import,
7088 af_routetarget_import_cmd,
7089 "[no] <rt|route-target> redirect import RTLIST...",
7090 NO_STR
7091 "Specify route target list\n"
7092 "Specify route target list\n"
7093 "Flow-spec redirect type route target\n"
7094 "Import routes to this address-family\n"
7095 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7096{
7097 VTY_DECLVAR_CONTEXT(bgp, bgp);
7098 int ret;
7099 struct ecommunity *ecom = NULL;
301ad80a
PG
7100 afi_t afi;
7101 int idx = 0;
7102 int yes = 1;
7103
7104 if (argv_find(argv, argc, "no", &idx))
7105 yes = 0;
7106
0ca70ba5 7107 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7108 if (afi == AFI_MAX)
7109 return CMD_WARNING_CONFIG_FAILED;
7110
301ad80a
PG
7111 if (yes) {
7112 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7113 vty_out(vty, "%% Missing RTLIST\n");
7114 return CMD_WARNING_CONFIG_FAILED;
7115 }
7116 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7117 if (ret != CMD_SUCCESS)
7118 return ret;
7119 }
69b07479
DS
7120
7121 if (yes) {
7122 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7123 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7124 .import_redirect_rtlist);
69b07479
DS
7125 bgp->vpn_policy[afi].import_redirect_rtlist =
7126 ecommunity_dup(ecom);
7127 } else {
7128 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7129 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7130 .import_redirect_rtlist);
69b07479 7131 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7132 }
69b07479 7133
301ad80a
PG
7134 if (ecom)
7135 ecommunity_free(&ecom);
7136
7137 return CMD_SUCCESS;
7138}
7139
505e5056 7140DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7141 address_family_ipv4_safi_cmd,
7142 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7146{
f51bae9c 7147
d62a17ae 7148 if (argc == 3) {
2131d5cf 7149 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7150 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7151 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7152 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7153 && safi != SAFI_EVPN) {
31947174
MK
7154 vty_out(vty,
7155 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7156 return CMD_WARNING_CONFIG_FAILED;
7157 }
d62a17ae 7158 vty->node = bgp_node_type(AFI_IP, safi);
7159 } else
7160 vty->node = BGP_IPV4_NODE;
718e3744 7161
d62a17ae 7162 return CMD_SUCCESS;
718e3744 7163}
7164
505e5056 7165DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7166 address_family_ipv6_safi_cmd,
7167 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7168 "Enter Address Family command mode\n"
7169 "Address Family\n"
7170 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7171{
d62a17ae 7172 if (argc == 3) {
2131d5cf 7173 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7174 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7175 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7176 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7177 && safi != SAFI_EVPN) {
31947174
MK
7178 vty_out(vty,
7179 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7180 return CMD_WARNING_CONFIG_FAILED;
7181 }
d62a17ae 7182 vty->node = bgp_node_type(AFI_IP6, safi);
7183 } else
7184 vty->node = BGP_IPV6_NODE;
25ffbdc1 7185
d62a17ae 7186 return CMD_SUCCESS;
25ffbdc1 7187}
718e3744 7188
d6902373 7189#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7190DEFUN_NOSH (address_family_vpnv4,
718e3744 7191 address_family_vpnv4_cmd,
8334fd5a 7192 "address-family vpnv4 [unicast]",
718e3744 7193 "Enter Address Family command mode\n"
8c3deaae 7194 "Address Family\n"
3a2d747c 7195 "Address Family modifier\n")
718e3744 7196{
d62a17ae 7197 vty->node = BGP_VPNV4_NODE;
7198 return CMD_SUCCESS;
718e3744 7199}
7200
505e5056 7201DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7202 address_family_vpnv6_cmd,
8334fd5a 7203 "address-family vpnv6 [unicast]",
8ecd3266 7204 "Enter Address Family command mode\n"
8c3deaae 7205 "Address Family\n"
3a2d747c 7206 "Address Family modifier\n")
8ecd3266 7207{
d62a17ae 7208 vty->node = BGP_VPNV6_NODE;
7209 return CMD_SUCCESS;
8ecd3266 7210}
64e4a6c5 7211#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7212
505e5056 7213DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7214 address_family_evpn_cmd,
7111c1a0 7215 "address-family l2vpn evpn",
4e0b7b6d 7216 "Enter Address Family command mode\n"
7111c1a0
QY
7217 "Address Family\n"
7218 "Address Family modifier\n")
4e0b7b6d 7219{
2131d5cf 7220 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7221 vty->node = BGP_EVPN_NODE;
7222 return CMD_SUCCESS;
4e0b7b6d
PG
7223}
7224
505e5056 7225DEFUN_NOSH (exit_address_family,
718e3744 7226 exit_address_family_cmd,
7227 "exit-address-family",
7228 "Exit from Address Family configuration mode\n")
7229{
d62a17ae 7230 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7231 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7232 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7233 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7234 || vty->node == BGP_EVPN_NODE
7235 || vty->node == BGP_FLOWSPECV4_NODE
7236 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7237 vty->node = BGP_NODE;
7238 return CMD_SUCCESS;
718e3744 7239}
6b0655a2 7240
8ad7271d 7241/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7242static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7243 const char *ip_str, afi_t afi, safi_t safi,
7244 struct prefix_rd *prd)
7245{
7246 int ret;
7247 struct prefix match;
7248 struct bgp_node *rn;
7249 struct bgp_node *rm;
7250 struct bgp *bgp;
7251 struct bgp_table *table;
7252 struct bgp_table *rib;
7253
7254 /* BGP structure lookup. */
7255 if (view_name) {
7256 bgp = bgp_lookup_by_name(view_name);
7257 if (bgp == NULL) {
7258 vty_out(vty, "%% Can't find BGP instance %s\n",
7259 view_name);
7260 return CMD_WARNING;
7261 }
7262 } else {
7263 bgp = bgp_get_default();
7264 if (bgp == NULL) {
7265 vty_out(vty, "%% No BGP process is configured\n");
7266 return CMD_WARNING;
7267 }
7268 }
7269
7270 /* Check IP address argument. */
7271 ret = str2prefix(ip_str, &match);
7272 if (!ret) {
7273 vty_out(vty, "%% address is malformed\n");
7274 return CMD_WARNING;
7275 }
7276
7277 match.family = afi2family(afi);
7278 rib = bgp->rib[afi][safi];
7279
7280 if (safi == SAFI_MPLS_VPN) {
7281 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7282 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7283 continue;
7284
67009e22
DS
7285 table = bgp_node_get_bgp_table_info(rn);
7286 if (table != NULL) {
7287
d62a17ae 7288 if ((rm = bgp_node_match(table, &match))
7289 != NULL) {
7290 if (rm->p.prefixlen
7291 == match.prefixlen) {
343cdb61 7292 SET_FLAG(rm->flags,
d62a17ae 7293 BGP_NODE_USER_CLEAR);
7294 bgp_process(bgp, rm, afi, safi);
7295 }
7296 bgp_unlock_node(rm);
7297 }
7298 }
7299 }
7300 } else {
7301 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7302 if (rn->p.prefixlen == match.prefixlen) {
7303 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7304 bgp_process(bgp, rn, afi, safi);
7305 }
7306 bgp_unlock_node(rn);
7307 }
7308 }
7309
7310 return CMD_SUCCESS;
8ad7271d
DS
7311}
7312
b09b5ae0 7313/* one clear bgp command to rule them all */
718e3744 7314DEFUN (clear_ip_bgp_all,
7315 clear_ip_bgp_all_cmd,
d7b9898c 7316 "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 7317 CLEAR_STR
7318 IP_STR
7319 BGP_STR
838758ac 7320 BGP_INSTANCE_HELP_STR
510afcd6 7321 BGP_AFI_HELP_STR
fd5e7b70 7322 "Address Family\n"
510afcd6 7323 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 7324 "Address Family modifier\n"
b09b5ae0
DW
7325 "Clear all peers\n"
7326 "BGP neighbor address to clear\n"
a80beece 7327 "BGP IPv6 neighbor to clear\n"
838758ac 7328 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
7329 "Clear peers with the AS number\n"
7330 "Clear all external peers\n"
718e3744 7331 "Clear all members of peer-group\n"
b09b5ae0 7332 "BGP peer-group name\n"
b09b5ae0
DW
7333 BGP_SOFT_STR
7334 BGP_SOFT_IN_STR
b09b5ae0
DW
7335 BGP_SOFT_OUT_STR
7336 BGP_SOFT_IN_STR
7337 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 7338 BGP_SOFT_OUT_STR)
718e3744 7339{
d62a17ae 7340 char *vrf = NULL;
7341
dc912615
DS
7342 afi_t afi = AFI_UNSPEC;
7343 safi_t safi = SAFI_UNSPEC;
d62a17ae 7344 enum clear_sort clr_sort = clear_peer;
7345 enum bgp_clear_type clr_type;
7346 char *clr_arg = NULL;
7347
7348 int idx = 0;
7349
7350 /* clear [ip] bgp */
7351 if (argv_find(argv, argc, "ip", &idx))
7352 afi = AFI_IP;
7353
9a8bdf1c
PG
7354 /* [<vrf> VIEWVRFNAME] */
7355 if (argv_find(argv, argc, "vrf", &idx)) {
7356 vrf = argv[idx + 1]->arg;
7357 idx += 2;
7358 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7359 vrf = NULL;
7360 } else if (argv_find(argv, argc, "view", &idx)) {
7361 /* [<view> VIEWVRFNAME] */
d62a17ae 7362 vrf = argv[idx + 1]->arg;
7363 idx += 2;
7364 }
d62a17ae 7365 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7366 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7367 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7368
d7b9898c 7369 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 7370 if (argv_find(argv, argc, "*", &idx)) {
7371 clr_sort = clear_all;
7372 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7373 clr_sort = clear_peer;
7374 clr_arg = argv[idx]->arg;
7375 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7376 clr_sort = clear_peer;
7377 clr_arg = argv[idx]->arg;
7378 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7379 clr_sort = clear_group;
7380 idx++;
7381 clr_arg = argv[idx]->arg;
d7b9898c 7382 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 7383 clr_sort = clear_peer;
7384 clr_arg = argv[idx]->arg;
8fa7d444
DS
7385 } else if (argv_find(argv, argc, "WORD", &idx)) {
7386 clr_sort = clear_peer;
7387 clr_arg = argv[idx]->arg;
d62a17ae 7388 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7389 clr_sort = clear_as;
7390 clr_arg = argv[idx]->arg;
7391 } else if (argv_find(argv, argc, "external", &idx)) {
7392 clr_sort = clear_external;
7393 }
7394
7395 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7396 if (argv_find(argv, argc, "soft", &idx)) {
7397 if (argv_find(argv, argc, "in", &idx)
7398 || argv_find(argv, argc, "out", &idx))
7399 clr_type = strmatch(argv[idx]->text, "in")
7400 ? BGP_CLEAR_SOFT_IN
7401 : BGP_CLEAR_SOFT_OUT;
7402 else
7403 clr_type = BGP_CLEAR_SOFT_BOTH;
7404 } else if (argv_find(argv, argc, "in", &idx)) {
7405 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7406 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7407 : BGP_CLEAR_SOFT_IN;
7408 } else if (argv_find(argv, argc, "out", &idx)) {
7409 clr_type = BGP_CLEAR_SOFT_OUT;
7410 } else
7411 clr_type = BGP_CLEAR_SOFT_NONE;
7412
7413 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 7414}
01080f7c 7415
8ad7271d
DS
7416DEFUN (clear_ip_bgp_prefix,
7417 clear_ip_bgp_prefix_cmd,
18c57037 7418 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
7419 CLEAR_STR
7420 IP_STR
7421 BGP_STR
838758ac 7422 BGP_INSTANCE_HELP_STR
8ad7271d 7423 "Clear bestpath and re-advertise\n"
0c7b1b01 7424 "IPv4 prefix\n")
8ad7271d 7425{
d62a17ae 7426 char *vrf = NULL;
7427 char *prefix = NULL;
8ad7271d 7428
d62a17ae 7429 int idx = 0;
01080f7c 7430
d62a17ae 7431 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
7432 if (argv_find(argv, argc, "vrf", &idx)) {
7433 vrf = argv[idx + 1]->arg;
7434 idx += 2;
7435 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7436 vrf = NULL;
7437 } else if (argv_find(argv, argc, "view", &idx)) {
7438 /* [<view> VIEWVRFNAME] */
7439 vrf = argv[idx + 1]->arg;
7440 idx += 2;
7441 }
0c7b1b01 7442
d62a17ae 7443 prefix = argv[argc - 1]->arg;
8ad7271d 7444
d62a17ae 7445 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 7446}
8ad7271d 7447
b09b5ae0
DW
7448DEFUN (clear_bgp_ipv6_safi_prefix,
7449 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 7450 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7451 CLEAR_STR
3a2d747c 7452 IP_STR
718e3744 7453 BGP_STR
8c3deaae 7454 "Address Family\n"
46f296b4 7455 BGP_SAFI_HELP_STR
b09b5ae0 7456 "Clear bestpath and re-advertise\n"
0c7b1b01 7457 "IPv6 prefix\n")
718e3744 7458{
9b475e76
PG
7459 int idx_safi = 0;
7460 int idx_ipv6_prefix = 0;
7461 safi_t safi = SAFI_UNICAST;
7462 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7463 argv[idx_ipv6_prefix]->arg : NULL;
7464
7465 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 7466 return bgp_clear_prefix(
9b475e76
PG
7467 vty, NULL, prefix, AFI_IP6,
7468 safi, NULL);
838758ac 7469}
01080f7c 7470
b09b5ae0
DW
7471DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7472 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 7473 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 7474 CLEAR_STR
3a2d747c 7475 IP_STR
718e3744 7476 BGP_STR
838758ac 7477 BGP_INSTANCE_HELP_STR
8c3deaae 7478 "Address Family\n"
46f296b4 7479 BGP_SAFI_HELP_STR
b09b5ae0 7480 "Clear bestpath and re-advertise\n"
0c7b1b01 7481 "IPv6 prefix\n")
718e3744 7482{
9b475e76 7483 int idx_safi = 0;
9a8bdf1c 7484 int idx_vrfview = 0;
9b475e76
PG
7485 int idx_ipv6_prefix = 0;
7486 safi_t safi = SAFI_UNICAST;
7487 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7488 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 7489 char *vrfview = NULL;
9b475e76 7490
9a8bdf1c
PG
7491 /* [<view|vrf> VIEWVRFNAME] */
7492 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7493 vrfview = argv[idx_vrfview + 1]->arg;
7494 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7495 vrfview = NULL;
7496 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7497 /* [<view> VIEWVRFNAME] */
7498 vrfview = argv[idx_vrfview + 1]->arg;
7499 }
9b475e76
PG
7500 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7501
d62a17ae 7502 return bgp_clear_prefix(
9b475e76
PG
7503 vty, vrfview, prefix,
7504 AFI_IP6, safi, NULL);
718e3744 7505}
7506
b09b5ae0
DW
7507DEFUN (show_bgp_views,
7508 show_bgp_views_cmd,
d6e3c605 7509 "show [ip] bgp views",
b09b5ae0 7510 SHOW_STR
d6e3c605 7511 IP_STR
01080f7c 7512 BGP_STR
b09b5ae0 7513 "Show the defined BGP views\n")
01080f7c 7514{
d62a17ae 7515 struct list *inst = bm->bgp;
7516 struct listnode *node;
7517 struct bgp *bgp;
01080f7c 7518
d62a17ae 7519 vty_out(vty, "Defined BGP views:\n");
7520 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7521 /* Skip VRFs. */
7522 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7523 continue;
7524 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7525 bgp->as);
7526 }
e52702f2 7527
d62a17ae 7528 return CMD_SUCCESS;
e0081f70
ML
7529}
7530
8386ac43 7531DEFUN (show_bgp_vrfs,
7532 show_bgp_vrfs_cmd,
d6e3c605 7533 "show [ip] bgp vrfs [json]",
8386ac43 7534 SHOW_STR
d6e3c605 7535 IP_STR
8386ac43 7536 BGP_STR
7537 "Show BGP VRFs\n"
9973d184 7538 JSON_STR)
8386ac43 7539{
fe1dc5a3 7540 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7541 struct list *inst = bm->bgp;
7542 struct listnode *node;
7543 struct bgp *bgp;
9f049418 7544 bool uj = use_json(argc, argv);
d62a17ae 7545 json_object *json = NULL;
7546 json_object *json_vrfs = NULL;
7547 int count = 0;
d62a17ae 7548
d62a17ae 7549 if (uj) {
7550 json = json_object_new_object();
7551 json_vrfs = json_object_new_object();
7552 }
7553
7554 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7555 const char *name, *type;
7556 struct peer *peer;
7fe96307 7557 struct listnode *node2, *nnode2;
d62a17ae 7558 int peers_cfg, peers_estb;
7559 json_object *json_vrf = NULL;
d62a17ae 7560
7561 /* Skip Views. */
7562 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7563 continue;
7564
7565 count++;
efb4077a 7566 if (!uj && count == 1) {
fe1dc5a3 7567 vty_out(vty,
efb4077a 7568 "%4s %-5s %-16s %9s %10s %-37s\n",
a4d82a8a 7569 "Type", "Id", "routerId", "#PeersVfg",
efb4077a
CS
7570 "#PeersEstb", "Name");
7571 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7572 "L3-VNI", "RouterMAC", "Interface");
7573 }
d62a17ae 7574
7575 peers_cfg = peers_estb = 0;
7576 if (uj)
7577 json_vrf = json_object_new_object();
7578
7579
7fe96307 7580 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 7581 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7582 continue;
7583 peers_cfg++;
7584 if (peer->status == Established)
7585 peers_estb++;
7586 }
7587
7588 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 7589 name = VRF_DEFAULT_NAME;
d62a17ae 7590 type = "DFLT";
7591 } else {
7592 name = bgp->name;
7593 type = "VRF";
7594 }
7595
a8bf7d9c 7596
d62a17ae 7597 if (uj) {
a4d82a8a
PZ
7598 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7599 ? -1
7600 : (int64_t)bgp->vrf_id;
d62a17ae 7601 json_object_string_add(json_vrf, "type", type);
7602 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7603 json_object_string_add(json_vrf, "routerId",
7604 inet_ntoa(bgp->router_id));
7605 json_object_int_add(json_vrf, "numConfiguredPeers",
7606 peers_cfg);
7607 json_object_int_add(json_vrf, "numEstablishedPeers",
7608 peers_estb);
7609
fe1dc5a3 7610 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7611 json_object_string_add(
7612 json_vrf, "rmac",
7613 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
7614 json_object_string_add(json_vrf, "interface",
7615 ifindex2ifname(bgp->l3vni_svi_ifindex,
7616 bgp->vrf_id));
d62a17ae 7617 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 7618 } else {
fe1dc5a3 7619 vty_out(vty,
efb4077a 7620 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
7621 type,
7622 bgp->vrf_id == VRF_UNKNOWN ? -1
7623 : (int)bgp->vrf_id,
7624 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
7625 peers_estb, name);
7626 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7627 bgp->l3vni,
7628 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7629 ifindex2ifname(bgp->l3vni_svi_ifindex,
7630 bgp->vrf_id));
7631 }
d62a17ae 7632 }
7633
7634 if (uj) {
7635 json_object_object_add(json, "vrfs", json_vrfs);
7636
7637 json_object_int_add(json, "totalVrfs", count);
7638
996c9314
LB
7639 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7640 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7641 json_object_free(json);
7642 } else {
7643 if (count)
7644 vty_out(vty,
7645 "\nTotal number of VRFs (including default): %d\n",
7646 count);
7647 }
7648
7649 return CMD_SUCCESS;
8386ac43 7650}
7651
48ecf8f5
DS
7652DEFUN (show_bgp_mac_hash,
7653 show_bgp_mac_hash_cmd,
7654 "show bgp mac hash",
7655 SHOW_STR
7656 BGP_STR
7657 "Mac Address\n"
7658 "Mac Address database\n")
7659{
7660 bgp_mac_dump_table(vty);
7661
7662 return CMD_SUCCESS;
7663}
acf71666 7664
e3b78da8 7665static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 7666{
0291c246 7667 struct vty *vty = (struct vty *)args;
e3b78da8 7668 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 7669
60466a63 7670 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7671 tip->refcnt);
7672}
7673
7674static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7675{
7676 vty_out(vty, "self nexthop database:\n");
af97a18b 7677 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
7678
7679 vty_out(vty, "Tunnel-ip database:\n");
7680 hash_iterate(bgp->tip_hash,
e3b78da8 7681 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
7682 vty);
7683}
7684
15c81ca4
DS
7685DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7686 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7687 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7688 "martian next-hops\n"
7689 "martian next-hop database\n")
acf71666 7690{
0291c246 7691 struct bgp *bgp = NULL;
15c81ca4 7692 int idx = 0;
9a8bdf1c
PG
7693 char *name = NULL;
7694
7695 /* [<vrf> VIEWVRFNAME] */
7696 if (argv_find(argv, argc, "vrf", &idx)) {
7697 name = argv[idx + 1]->arg;
7698 if (name && strmatch(name, VRF_DEFAULT_NAME))
7699 name = NULL;
7700 } else if (argv_find(argv, argc, "view", &idx))
7701 /* [<view> VIEWVRFNAME] */
7702 name = argv[idx + 1]->arg;
7703 if (name)
7704 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
7705 else
7706 bgp = bgp_get_default();
acf71666 7707
acf71666
MK
7708 if (!bgp) {
7709 vty_out(vty, "%% No BGP process is configured\n");
7710 return CMD_WARNING;
7711 }
7712 bgp_show_martian_nexthops(vty, bgp);
7713
7714 return CMD_SUCCESS;
7715}
7716
f412b39a 7717DEFUN (show_bgp_memory,
4bf6a362 7718 show_bgp_memory_cmd,
7fa12b13 7719 "show [ip] bgp memory",
4bf6a362 7720 SHOW_STR
3a2d747c 7721 IP_STR
4bf6a362
PJ
7722 BGP_STR
7723 "Global BGP memory statistics\n")
7724{
d62a17ae 7725 char memstrbuf[MTYPE_MEMSTR_LEN];
7726 unsigned long count;
7727
7728 /* RIB related usage stats */
7729 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7730 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct bgp_node)));
7733
7734 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7735 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 7737 count * sizeof(struct bgp_path_info)));
d62a17ae 7738 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7739 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7740 count,
4b7e6066
DS
7741 mtype_memstr(
7742 memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 7744
7745 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7746 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7747 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7748 count * sizeof(struct bgp_static)));
7749
7750 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7751 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7752 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7753 count * sizeof(struct bpacket)));
7754
7755 /* Adj-In/Out */
7756 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7757 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7758 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7759 count * sizeof(struct bgp_adj_in)));
7760 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7761 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7762 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7763 count * sizeof(struct bgp_adj_out)));
7764
7765 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7766 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7767 count,
7768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7769 count * sizeof(struct bgp_nexthop_cache)));
7770
7771 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7772 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7773 count,
7774 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7775 count * sizeof(struct bgp_damp_info)));
7776
7777 /* Attributes */
7778 count = attr_count();
7779 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7780 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7781 count * sizeof(struct attr)));
7782
7783 if ((count = attr_unknown_count()))
7784 vty_out(vty, "%ld unknown attributes\n", count);
7785
7786 /* AS_PATH attributes */
7787 count = aspath_count();
7788 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7789 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7790 count * sizeof(struct aspath)));
7791
7792 count = mtype_stats_alloc(MTYPE_AS_SEG);
7793 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7794 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7795 count * sizeof(struct assegment)));
7796
7797 /* Other attributes */
7798 if ((count = community_count()))
7799 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7800 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7801 count * sizeof(struct community)));
d62a17ae 7802 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7803 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7804 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7805 count * sizeof(struct ecommunity)));
d62a17ae 7806 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7807 vty_out(vty,
7808 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7809 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7810 count * sizeof(struct lcommunity)));
d62a17ae 7811
7812 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7813 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7814 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7815 count * sizeof(struct cluster_list)));
7816
7817 /* Peer related usage */
7818 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7819 vty_out(vty, "%ld peers, using %s of memory\n", count,
7820 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7821 count * sizeof(struct peer)));
7822
7823 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7824 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7825 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7826 count * sizeof(struct peer_group)));
7827
7828 /* Other */
d62a17ae 7829 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7830 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7831 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7832 count * sizeof(regex_t)));
d62a17ae 7833 return CMD_SUCCESS;
4bf6a362 7834}
fee0f4c6 7835
57a9c8a8
DS
7836static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7837{
7838 json_object *bestpath = json_object_new_object();
7839
7840 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7841 json_object_string_add(bestpath, "asPath", "ignore");
7842
7843 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7844 json_object_string_add(bestpath, "asPath", "confed");
7845
7846 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7847 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7848 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7849 "as-set");
7850 else
a4d82a8a 7851 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7852 "true");
7853 } else
a4d82a8a 7854 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7855
7856 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7857 json_object_string_add(bestpath, "compareRouterId", "true");
7858 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7859 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7860 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7861 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7862 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7863 json_object_string_add(bestpath, "med",
7864 "missing-as-worst");
7865 else
7866 json_object_string_add(bestpath, "med", "true");
7867 }
7868
7869 json_object_object_add(json, "bestPath", bestpath);
7870}
7871
3577f1c5
DD
7872/* Print the error code/subcode for why the peer is down */
7873static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
7874 json_object *json_peer, bool use_json)
7875{
7876 const char *code_str;
7877 const char *subcode_str;
7878
7879 if (use_json) {
7880 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7881 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7882 char errorcodesubcode_hexstr[5];
7883 char errorcodesubcode_str[256];
7884
7885 code_str = bgp_notify_code_str(peer->notify.code);
7886 subcode_str = bgp_notify_subcode_str(
7887 peer->notify.code,
7888 peer->notify.subcode);
7889
7890 sprintf(errorcodesubcode_hexstr, "%02X%02X",
7891 peer->notify.code, peer->notify.subcode);
7892 json_object_string_add(json_peer,
7893 "lastErrorCodeSubcode",
7894 errorcodesubcode_hexstr);
7895 snprintf(errorcodesubcode_str, 255, "%s%s",
7896 code_str, subcode_str);
7897 json_object_string_add(json_peer,
7898 "lastNotificationReason",
7899 errorcodesubcode_str);
7900 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
7901 && peer->notify.code == BGP_NOTIFY_CEASE
7902 && (peer->notify.subcode
7903 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
7904 || peer->notify.subcode
7905 == BGP_NOTIFY_CEASE_ADMIN_RESET)
7906 && peer->notify.length) {
7907 char msgbuf[1024];
7908 const char *msg_str;
7909
7910 msg_str = bgp_notify_admin_message(
7911 msgbuf, sizeof(msgbuf),
7912 (uint8_t *)peer->notify.data,
7913 peer->notify.length);
7914 if (msg_str)
7915 json_object_string_add(
7916 json_peer,
7917 "lastShutdownDescription",
7918 msg_str);
7919 }
7920
7921 }
7922 json_object_string_add(json_peer, "lastResetDueTo",
7923 peer_down_str[(int)peer->last_reset]);
05912a17
DD
7924 json_object_int_add(json_peer, "lastResetCode",
7925 peer->last_reset);
3577f1c5
DD
7926 } else {
7927 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
7928 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
7929 code_str = bgp_notify_code_str(peer->notify.code);
7930 subcode_str =
7931 bgp_notify_subcode_str(peer->notify.code,
7932 peer->notify.subcode);
7933 vty_out(vty, " Notification %s (%s%s)\n",
7934 peer->last_reset == PEER_DOWN_NOTIFY_SEND
7935 ? "sent"
7936 : "received",
7937 code_str, subcode_str);
7938 } else {
7939 vty_out(vty, " %s\n",
7940 peer_down_str[(int)peer->last_reset]);
7941 }
7942 }
7943}
7944
7945static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
7946 safi_t safi)
7947{
7948 return ((peer->status != Established) ||
7949 !peer->afc_recv[afi][safi]);
7950}
7951
7952static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
7953 struct peer *peer, json_object *json_peer,
7954 int max_neighbor_width, bool use_json)
7955{
7956 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7957 int len;
7958
7959 if (use_json) {
7960 if (peer_dynamic_neighbor(peer))
7961 json_object_boolean_true_add(json_peer,
7962 "dynamicPeer");
7963 if (peer->hostname)
7964 json_object_string_add(json_peer, "hostname",
7965 peer->hostname);
7966
7967 if (peer->domainname)
7968 json_object_string_add(json_peer, "domainname",
7969 peer->domainname);
7970 json_object_int_add(json_peer, "connectionsEstablished",
7971 peer->established);
7972 json_object_int_add(json_peer, "connectionsDropped",
7973 peer->dropped);
7974 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7975 use_json, json_peer);
7976 if (peer->status == Established)
7977 json_object_string_add(json_peer, "lastResetDueTo",
7978 "AFI/SAFI Not Negotiated");
7979 else
7980 bgp_show_peer_reset(NULL, peer, json_peer, true);
7981 } else {
7982 dn_flag[1] = '\0';
7983 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
7984 if (peer->hostname
7985 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7986 len = vty_out(vty, "%s%s(%s)", dn_flag,
7987 peer->hostname, peer->host);
7988 else
7989 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7990
7991 /* pad the neighbor column with spaces */
7992 if (len < max_neighbor_width)
7993 vty_out(vty, "%*s", max_neighbor_width - len,
7994 " ");
7995 vty_out(vty, "%7d %7d %8s", peer->established,
7996 peer->dropped,
7997 peer_uptime(peer->uptime, timebuf,
7998 BGP_UPTIME_LEN, 0, NULL));
7999 if (peer->status == Established)
8000 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8001 else
8002 bgp_show_peer_reset(vty, peer, NULL,
8003 false);
8004 }
8005}
8006
8007
718e3744 8008/* Show BGP peer's summary information. */
d62a17ae 8009static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 8010 bool show_failed, bool use_json)
d62a17ae 8011{
8012 struct peer *peer;
8013 struct listnode *node, *nnode;
8014 unsigned int count = 0, dn_count = 0;
8015 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8016 char neighbor_buf[VTY_BUFSIZ];
8017 int neighbor_col_default_width = 16;
3577f1c5 8018 int len, failed_count = 0;
d62a17ae 8019 int max_neighbor_width = 0;
8020 int pfx_rcd_safi;
3c13337d 8021 json_object *json = NULL;
d62a17ae 8022 json_object *json_peer = NULL;
8023 json_object *json_peers = NULL;
50e05855 8024 struct peer_af *paf;
d62a17ae 8025
8026 /* labeled-unicast routes are installed in the unicast table so in order
8027 * to
8028 * display the correct PfxRcd value we must look at SAFI_UNICAST
8029 */
3577f1c5 8030
d62a17ae 8031 if (safi == SAFI_LABELED_UNICAST)
8032 pfx_rcd_safi = SAFI_UNICAST;
8033 else
8034 pfx_rcd_safi = safi;
8035
8036 if (use_json) {
3c13337d 8037 json = json_object_new_object();
d62a17ae 8038 json_peers = json_object_new_object();
3577f1c5
DD
8039 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8040 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8041 continue;
8042
8043 if (peer->afc[afi][safi]) {
8044 /* See if we have at least a single failed peer */
8045 if (bgp_has_peer_failed(peer, afi, safi))
8046 failed_count++;
8047 count++;
8048 }
8049 if (peer_dynamic_neighbor(peer))
8050 dn_count++;
8051 }
8052
d62a17ae 8053 } else {
8054 /* Loop over all neighbors that will be displayed to determine
8055 * how many
8056 * characters are needed for the Neighbor column
8057 */
8058 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8059 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8060 continue;
8061
8062 if (peer->afc[afi][safi]) {
8063 memset(dn_flag, '\0', sizeof(dn_flag));
8064 if (peer_dynamic_neighbor(peer))
8065 dn_flag[0] = '*';
8066
8067 if (peer->hostname
8068 && bgp_flag_check(bgp,
8069 BGP_FLAG_SHOW_HOSTNAME))
8070 sprintf(neighbor_buf, "%s%s(%s) ",
8071 dn_flag, peer->hostname,
8072 peer->host);
8073 else
8074 sprintf(neighbor_buf, "%s%s ", dn_flag,
8075 peer->host);
8076
8077 len = strlen(neighbor_buf);
8078
8079 if (len > max_neighbor_width)
8080 max_neighbor_width = len;
3577f1c5
DD
8081
8082 /* See if we have at least a single failed peer */
8083 if (bgp_has_peer_failed(peer, afi, safi))
8084 failed_count++;
8085 count++;
d62a17ae 8086 }
8087 }
f933309e 8088
d62a17ae 8089 /* Originally we displayed the Neighbor column as 16
8090 * characters wide so make that the default
8091 */
8092 if (max_neighbor_width < neighbor_col_default_width)
8093 max_neighbor_width = neighbor_col_default_width;
8094 }
f933309e 8095
3577f1c5
DD
8096 if (show_failed && !failed_count) {
8097 if (use_json) {
8098 json_object_int_add(json, "failedPeersCount", 0);
8099 json_object_int_add(json, "dynamicPeers", dn_count);
8100 json_object_int_add(json, "totalPeers", count);
8101
8102 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8103 json, JSON_C_TO_STRING_PRETTY));
8104 json_object_free(json);
8105 } else {
8106 vty_out(vty, "%% No failed BGP neighbors found\n");
8107 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8108 }
8109 return CMD_SUCCESS;
8110 }
8111
8112 count = 0; /* Reset the value as its used again */
d62a17ae 8113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8114 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8115 continue;
8116
ea47320b
DL
8117 if (!peer->afc[afi][safi])
8118 continue;
d62a17ae 8119
ea47320b
DL
8120 if (!count) {
8121 unsigned long ents;
8122 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8123 int64_t vrf_id_ui;
d62a17ae 8124
a4d82a8a
PZ
8125 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8126 ? -1
8127 : (int64_t)bgp->vrf_id;
ea47320b
DL
8128
8129 /* Usage summary and header */
8130 if (use_json) {
8131 json_object_string_add(
8132 json, "routerId",
8133 inet_ntoa(bgp->router_id));
60466a63
QY
8134 json_object_int_add(json, "as", bgp->as);
8135 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8136 json_object_string_add(
8137 json, "vrfName",
8138 (bgp->inst_type
8139 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8140 ? VRF_DEFAULT_NAME
ea47320b
DL
8141 : bgp->name);
8142 } else {
8143 vty_out(vty,
8144 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8145 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8146 bgp->vrf_id == VRF_UNKNOWN
8147 ? -1
8148 : (int)bgp->vrf_id);
ea47320b
DL
8149 vty_out(vty, "\n");
8150 }
d62a17ae 8151
ea47320b 8152 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8153 if (use_json) {
ea47320b 8154 json_object_int_add(
60466a63 8155 json, "updateDelayLimit",
ea47320b 8156 bgp->v_update_delay);
d62a17ae 8157
ea47320b
DL
8158 if (bgp->v_update_delay
8159 != bgp->v_establish_wait)
d62a17ae 8160 json_object_int_add(
8161 json,
ea47320b
DL
8162 "updateDelayEstablishWait",
8163 bgp->v_establish_wait);
d62a17ae 8164
60466a63 8165 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8166 json_object_string_add(
8167 json,
8168 "updateDelayFirstNeighbor",
8169 bgp->update_delay_begin_time);
8170 json_object_boolean_true_add(
8171 json,
8172 "updateDelayInProgress");
8173 } else {
8174 if (bgp->update_delay_over) {
d62a17ae 8175 json_object_string_add(
8176 json,
8177 "updateDelayFirstNeighbor",
8178 bgp->update_delay_begin_time);
ea47320b 8179 json_object_string_add(
d62a17ae 8180 json,
ea47320b
DL
8181 "updateDelayBestpathResumed",
8182 bgp->update_delay_end_time);
8183 json_object_string_add(
d62a17ae 8184 json,
ea47320b
DL
8185 "updateDelayZebraUpdateResume",
8186 bgp->update_delay_zebra_resume_time);
8187 json_object_string_add(
8188 json,
8189 "updateDelayPeerUpdateResume",
8190 bgp->update_delay_peers_resume_time);
d62a17ae 8191 }
ea47320b
DL
8192 }
8193 } else {
8194 vty_out(vty,
8195 "Read-only mode update-delay limit: %d seconds\n",
8196 bgp->v_update_delay);
8197 if (bgp->v_update_delay
8198 != bgp->v_establish_wait)
d62a17ae 8199 vty_out(vty,
ea47320b
DL
8200 " Establish wait: %d seconds\n",
8201 bgp->v_establish_wait);
d62a17ae 8202
60466a63 8203 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8204 vty_out(vty,
8205 " First neighbor established: %s\n",
8206 bgp->update_delay_begin_time);
8207 vty_out(vty,
8208 " Delay in progress\n");
8209 } else {
8210 if (bgp->update_delay_over) {
d62a17ae 8211 vty_out(vty,
8212 " First neighbor established: %s\n",
8213 bgp->update_delay_begin_time);
8214 vty_out(vty,
ea47320b
DL
8215 " Best-paths resumed: %s\n",
8216 bgp->update_delay_end_time);
8217 vty_out(vty,
8218 " zebra update resumed: %s\n",
8219 bgp->update_delay_zebra_resume_time);
8220 vty_out(vty,
8221 " peers update resumed: %s\n",
8222 bgp->update_delay_peers_resume_time);
d62a17ae 8223 }
8224 }
8225 }
ea47320b 8226 }
d62a17ae 8227
ea47320b
DL
8228 if (use_json) {
8229 if (bgp_maxmed_onstartup_configured(bgp)
8230 && bgp->maxmed_active)
8231 json_object_boolean_true_add(
60466a63 8232 json, "maxMedOnStartup");
ea47320b
DL
8233 if (bgp->v_maxmed_admin)
8234 json_object_boolean_true_add(
60466a63 8235 json, "maxMedAdministrative");
d62a17ae 8236
ea47320b
DL
8237 json_object_int_add(
8238 json, "tableVersion",
60466a63 8239 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8240
60466a63
QY
8241 ents = bgp_table_count(bgp->rib[afi][safi]);
8242 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8243 json_object_int_add(
8244 json, "ribMemory",
8245 ents * sizeof(struct bgp_node));
d62a17ae 8246
210ec2a0 8247 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8248 json_object_int_add(json, "peerCount", ents);
8249 json_object_int_add(json, "peerMemory",
8250 ents * sizeof(struct peer));
d62a17ae 8251
ea47320b
DL
8252 if ((ents = listcount(bgp->group))) {
8253 json_object_int_add(
60466a63 8254 json, "peerGroupCount", ents);
ea47320b
DL
8255 json_object_int_add(
8256 json, "peerGroupMemory",
996c9314
LB
8257 ents * sizeof(struct
8258 peer_group));
ea47320b 8259 }
d62a17ae 8260
ea47320b
DL
8261 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8262 BGP_CONFIG_DAMPENING))
8263 json_object_boolean_true_add(
60466a63 8264 json, "dampeningEnabled");
ea47320b
DL
8265 } else {
8266 if (bgp_maxmed_onstartup_configured(bgp)
8267 && bgp->maxmed_active)
d62a17ae 8268 vty_out(vty,
ea47320b
DL
8269 "Max-med on-startup active\n");
8270 if (bgp->v_maxmed_admin)
d62a17ae 8271 vty_out(vty,
ea47320b 8272 "Max-med administrative active\n");
d62a17ae 8273
60466a63
QY
8274 vty_out(vty, "BGP table version %" PRIu64 "\n",
8275 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8276
60466a63 8277 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8278 vty_out(vty,
8279 "RIB entries %ld, using %s of memory\n",
8280 ents,
996c9314
LB
8281 mtype_memstr(memstrbuf,
8282 sizeof(memstrbuf),
8283 ents * sizeof(struct
8284 bgp_node)));
ea47320b
DL
8285
8286 /* Peer related usage */
210ec2a0 8287 ents = bgp->af_peer_count[afi][safi];
60466a63 8288 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8289 ents,
8290 mtype_memstr(
60466a63
QY
8291 memstrbuf, sizeof(memstrbuf),
8292 ents * sizeof(struct peer)));
ea47320b
DL
8293
8294 if ((ents = listcount(bgp->group)))
d62a17ae 8295 vty_out(vty,
ea47320b 8296 "Peer groups %ld, using %s of memory\n",
d62a17ae 8297 ents,
8298 mtype_memstr(
8299 memstrbuf,
8300 sizeof(memstrbuf),
996c9314
LB
8301 ents * sizeof(struct
8302 peer_group)));
d62a17ae 8303
ea47320b
DL
8304 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8305 BGP_CONFIG_DAMPENING))
60466a63 8306 vty_out(vty, "Dampening enabled.\n");
ea47320b 8307 vty_out(vty, "\n");
d62a17ae 8308
ea47320b
DL
8309 /* Subtract 8 here because 'Neighbor' is
8310 * 8 characters */
8311 vty_out(vty, "Neighbor");
60466a63
QY
8312 vty_out(vty, "%*s", max_neighbor_width - 8,
8313 " ");
3577f1c5
DD
8314 if (show_failed)
8315 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8316 else
8317 vty_out(vty,
ea47320b 8318 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8319 }
ea47320b 8320 }
d62a17ae 8321
ea47320b 8322 count++;
3577f1c5
DD
8323 /* Works for both failed & successful cases */
8324 if (peer_dynamic_neighbor(peer))
8325 dn_count++;
d62a17ae 8326
ea47320b 8327 if (use_json) {
3577f1c5
DD
8328 json_peer = NULL;
8329
8330 if (show_failed &&
8331 bgp_has_peer_failed(peer, afi, safi)) {
8332 json_peer = json_object_new_object();
8333 bgp_show_failed_summary(vty, bgp, peer,
8334 json_peer, 0, use_json);
8335 } else if (!show_failed) {
8336 json_peer = json_object_new_object();
8337 if (peer_dynamic_neighbor(peer)) {
8338 json_object_boolean_true_add(json_peer,
8339 "dynamicPeer");
8340 }
d62a17ae 8341
3577f1c5
DD
8342 if (peer->hostname)
8343 json_object_string_add(json_peer, "hostname",
8344 peer->hostname);
8345
8346 if (peer->domainname)
8347 json_object_string_add(json_peer, "domainname",
8348 peer->domainname);
8349
8350 json_object_int_add(json_peer, "remoteAs", peer->as);
8351 json_object_int_add(json_peer, "version", 4);
8352 json_object_int_add(json_peer, "msgRcvd",
8353 PEER_TOTAL_RX(peer));
8354 json_object_int_add(json_peer, "msgSent",
8355 PEER_TOTAL_TX(peer));
8356
8357 json_object_int_add(json_peer, "tableVersion",
8358 peer->version[afi][safi]);
8359 json_object_int_add(json_peer, "outq",
8360 peer->obuf->count);
8361 json_object_int_add(json_peer, "inq", 0);
8362 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8363 use_json, json_peer);
8364
8365 /*
8366 * Adding "pfxRcd" field to match with the corresponding
8367 * CLI. "prefixReceivedCount" will be deprecated in
8368 * future.
8369 */
8370 json_object_int_add(json_peer, "prefixReceivedCount",
8371 peer->pcount[afi][pfx_rcd_safi]);
8372 json_object_int_add(json_peer, "pfxRcd",
8373 peer->pcount[afi][pfx_rcd_safi]);
8374
8375 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8376 if (paf && PAF_SUBGRP(paf))
8377 json_object_int_add(json_peer,
8378 "pfxSnt",
8379 (PAF_SUBGRP(paf))->scount);
8380 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8381 json_object_string_add(json_peer, "state",
8382 "Idle (Admin)");
8383 else if (peer->afc_recv[afi][safi])
8384 json_object_string_add(
8385 json_peer, "state",
8386 lookup_msg(bgp_status_msg, peer->status,
8387 NULL));
8388 else if (CHECK_FLAG(peer->sflags,
8389 PEER_STATUS_PREFIX_OVERFLOW))
8390 json_object_string_add(json_peer, "state",
8391 "Idle (PfxCt)");
8392 else
8393 json_object_string_add(
8394 json_peer, "state",
8395 lookup_msg(bgp_status_msg, peer->status,
8396 NULL));
200116db
DD
8397 json_object_int_add(json_peer, "connectionsEstablished",
8398 peer->established);
8399 json_object_int_add(json_peer, "connectionsDropped",
8400 peer->dropped);
b4e9dcba 8401 }
3577f1c5
DD
8402 /* Avoid creating empty peer dicts in JSON */
8403 if (json_peer == NULL)
8404 continue;
ea47320b
DL
8405
8406 if (peer->conf_if)
60466a63 8407 json_object_string_add(json_peer, "idType",
ea47320b
DL
8408 "interface");
8409 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
8410 json_object_string_add(json_peer, "idType",
8411 "ipv4");
ea47320b 8412 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
8413 json_object_string_add(json_peer, "idType",
8414 "ipv6");
ea47320b
DL
8415 json_object_object_add(json_peers, peer->host,
8416 json_peer);
8417 } else {
3577f1c5
DD
8418 if (show_failed &&
8419 bgp_has_peer_failed(peer, afi, safi)) {
8420 bgp_show_failed_summary(vty, bgp, peer, NULL,
8421 max_neighbor_width,
8422 use_json);
8423 } else if (!show_failed) {
8424 memset(dn_flag, '\0', sizeof(dn_flag));
8425 if (peer_dynamic_neighbor(peer)) {
8426 dn_flag[0] = '*';
8427 }
d62a17ae 8428
3577f1c5
DD
8429 if (peer->hostname
8430 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8431 len = vty_out(vty, "%s%s(%s)", dn_flag,
8432 peer->hostname, peer->host);
d62a17ae 8433 else
3577f1c5
DD
8434 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8435
8436 /* pad the neighbor column with spaces */
8437 if (len < max_neighbor_width)
8438 vty_out(vty, "%*s", max_neighbor_width - len,
8439 " ");
8440
8441 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8442 peer->as, PEER_TOTAL_RX(peer),
8443 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8444 0, peer->obuf->count,
8445 peer_uptime(peer->uptime, timebuf,
8446 BGP_UPTIME_LEN, 0, NULL));
8447
8448 if (peer->status == Established)
8449 if (peer->afc_recv[afi][safi])
8450 vty_out(vty, " %12ld",
8451 peer->pcount[afi]
8452 [pfx_rcd_safi]);
8453 else
8454 vty_out(vty, " NoNeg");
8455 else {
8456 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8457 vty_out(vty, " Idle (Admin)");
8458 else if (CHECK_FLAG(
8459 peer->sflags,
8460 PEER_STATUS_PREFIX_OVERFLOW))
8461 vty_out(vty, " Idle (PfxCt)");
8462 else
8463 vty_out(vty, " %12s",
8464 lookup_msg(bgp_status_msg,
8465 peer->status, NULL));
8466 }
8467 vty_out(vty, "\n");
d62a17ae 8468 }
3577f1c5 8469
d62a17ae 8470 }
8471 }
f933309e 8472
d62a17ae 8473 if (use_json) {
8474 json_object_object_add(json, "peers", json_peers);
3577f1c5 8475 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 8476 json_object_int_add(json, "totalPeers", count);
8477 json_object_int_add(json, "dynamicPeers", dn_count);
8478
3577f1c5
DD
8479 if (!show_failed)
8480 bgp_show_bestpath_json(bgp, json);
57a9c8a8 8481
996c9314
LB
8482 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8483 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8484 json_object_free(json);
8485 } else {
8486 if (count)
8487 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8488 else {
d6ceaca3 8489 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 8490 get_afi_safi_str(afi, safi, false));
d62a17ae 8491 }
b05a1c8b 8492
d6ceaca3 8493 if (dn_count) {
d62a17ae 8494 vty_out(vty, "* - dynamic neighbor\n");
8495 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8496 dn_count, bgp->dynamic_neighbors_limit);
8497 }
8498 }
1ff9a340 8499
d62a17ae 8500 return CMD_SUCCESS;
718e3744 8501}
8502
d62a17ae 8503static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 8504 int safi, bool show_failed, bool use_json)
d62a17ae 8505{
8506 int is_first = 1;
8507 int afi_wildcard = (afi == AFI_MAX);
8508 int safi_wildcard = (safi == SAFI_MAX);
8509 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 8510 bool nbr_output = false;
d62a17ae 8511
8512 if (use_json && is_wildcard)
8513 vty_out(vty, "{\n");
8514 if (afi_wildcard)
8515 afi = 1; /* AFI_IP */
8516 while (afi < AFI_MAX) {
8517 if (safi_wildcard)
8518 safi = 1; /* SAFI_UNICAST */
8519 while (safi < SAFI_MAX) {
318cac96 8520 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 8521 nbr_output = true;
f86897b9 8522
d62a17ae 8523 if (is_wildcard) {
8524 /*
8525 * So limit output to those afi/safi
8526 * pairs that
8527 * actualy have something interesting in
8528 * them
8529 */
8530 if (use_json) {
d62a17ae 8531 if (!is_first)
8532 vty_out(vty, ",\n");
8533 else
8534 is_first = 0;
8535
8536 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
8537 get_afi_safi_str(afi,
8538 safi,
8539 true));
d62a17ae 8540 } else {
8541 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
8542 get_afi_safi_str(afi,
8543 safi,
8544 false));
d62a17ae 8545 }
8546 }
3577f1c5
DD
8547 bgp_show_summary(vty, bgp, afi, safi, show_failed,
8548 use_json);
d62a17ae 8549 }
8550 safi++;
d62a17ae 8551 if (!safi_wildcard)
8552 safi = SAFI_MAX;
8553 }
8554 afi++;
ee851c8c 8555 if (!afi_wildcard)
d62a17ae 8556 afi = AFI_MAX;
8557 }
8558
8559 if (use_json && is_wildcard)
8560 vty_out(vty, "}\n");
ca61fd25
DS
8561 else if (!nbr_output) {
8562 if (use_json)
8563 vty_out(vty, "{}\n");
8564 else
8565 vty_out(vty, "%% No BGP neighbors found\n");
8566 }
d62a17ae 8567}
8568
8569static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
8570 safi_t safi, bool show_failed,
8571 bool use_json)
d62a17ae 8572{
8573 struct listnode *node, *nnode;
8574 struct bgp *bgp;
d62a17ae 8575 int is_first = 1;
9f049418 8576 bool nbr_output = false;
d62a17ae 8577
8578 if (use_json)
8579 vty_out(vty, "{\n");
8580
8581 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 8582 nbr_output = true;
d62a17ae 8583 if (use_json) {
d62a17ae 8584 if (!is_first)
8585 vty_out(vty, ",\n");
8586 else
8587 is_first = 0;
8588
8589 vty_out(vty, "\"%s\":",
8590 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8591 ? VRF_DEFAULT_NAME
d62a17ae 8592 : bgp->name);
8593 } else {
8594 vty_out(vty, "\nInstance %s:\n",
8595 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8596 ? VRF_DEFAULT_NAME
d62a17ae 8597 : bgp->name);
8598 }
3577f1c5
DD
8599 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8600 use_json);
d62a17ae 8601 }
8602
8603 if (use_json)
8604 vty_out(vty, "}\n");
9f049418
DS
8605 else if (!nbr_output)
8606 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 8607}
8608
8609int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 8610 safi_t safi, bool show_failed, bool use_json)
d62a17ae 8611{
8612 struct bgp *bgp;
8613
8614 if (name) {
8615 if (strmatch(name, "all")) {
8616 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 8617 show_failed,
d62a17ae 8618 use_json);
8619 return CMD_SUCCESS;
8620 } else {
8621 bgp = bgp_lookup_by_name(name);
8622
8623 if (!bgp) {
8624 if (use_json)
8625 vty_out(vty, "{}\n");
8626 else
8627 vty_out(vty,
ca61fd25 8628 "%% BGP instance not found\n");
d62a17ae 8629 return CMD_WARNING;
8630 }
8631
f86897b9 8632 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 8633 show_failed, use_json);
d62a17ae 8634 return CMD_SUCCESS;
8635 }
8636 }
8637
8638 bgp = bgp_get_default();
8639
8640 if (bgp)
3577f1c5
DD
8641 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
8642 use_json);
9f049418 8643 else {
ca61fd25
DS
8644 if (use_json)
8645 vty_out(vty, "{}\n");
8646 else
8647 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
8648 return CMD_WARNING;
8649 }
d62a17ae 8650
8651 return CMD_SUCCESS;
4fb25c53
DW
8652}
8653
716b2d8a 8654/* `show [ip] bgp summary' commands. */
47fc97cc 8655DEFUN (show_ip_bgp_summary,
718e3744 8656 show_ip_bgp_summary_cmd,
3577f1c5 8657 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 8658 SHOW_STR
8659 IP_STR
8660 BGP_STR
8386ac43 8661 BGP_INSTANCE_HELP_STR
46f296b4 8662 BGP_AFI_HELP_STR
dd6bd0f1 8663 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 8664 "Summary of BGP neighbor status\n"
3577f1c5 8665 "Show only sessions not in Established state\n"
9973d184 8666 JSON_STR)
718e3744 8667{
d62a17ae 8668 char *vrf = NULL;
8669 afi_t afi = AFI_MAX;
8670 safi_t safi = SAFI_MAX;
3577f1c5 8671 bool show_failed = false;
d62a17ae 8672
8673 int idx = 0;
8674
8675 /* show [ip] bgp */
8676 if (argv_find(argv, argc, "ip", &idx))
8677 afi = AFI_IP;
9a8bdf1c
PG
8678 /* [<vrf> VIEWVRFNAME] */
8679 if (argv_find(argv, argc, "vrf", &idx)) {
8680 vrf = argv[idx + 1]->arg;
8681 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8682 vrf = NULL;
8683 } else if (argv_find(argv, argc, "view", &idx))
8684 /* [<view> VIEWVRFNAME] */
8685 vrf = argv[idx + 1]->arg;
d62a17ae 8686 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8687 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8688 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8689 }
8690
3577f1c5
DD
8691 if (argv_find(argv, argc, "failed", &idx))
8692 show_failed = true;
8693
9f049418 8694 bool uj = use_json(argc, argv);
d62a17ae 8695
3577f1c5 8696 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 8697}
8698
5cb5f4d0 8699const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 8700{
5cb5f4d0
DD
8701 if (for_json)
8702 return get_afi_safi_json_str(afi, safi);
d62a17ae 8703 else
5cb5f4d0 8704 return get_afi_safi_vty_str(afi, safi);
27162734
LB
8705}
8706
718e3744 8707/* Show BGP peer's information. */
d1927ebe 8708enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
d62a17ae 8709
8710static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8711 afi_t afi, safi_t safi,
d7c0a89a
QY
8712 uint16_t adv_smcap, uint16_t adv_rmcap,
8713 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 8714 bool use_json, json_object *json_pref)
d62a17ae 8715{
8716 /* Send-Mode */
8717 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8718 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8719 if (use_json) {
8720 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8721 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8722 json_object_string_add(json_pref, "sendMode",
8723 "advertisedAndReceived");
8724 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8725 json_object_string_add(json_pref, "sendMode",
8726 "advertised");
8727 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8728 json_object_string_add(json_pref, "sendMode",
8729 "received");
8730 } else {
8731 vty_out(vty, " Send-mode: ");
8732 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8733 vty_out(vty, "advertised");
8734 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8735 vty_out(vty, "%sreceived",
8736 CHECK_FLAG(p->af_cap[afi][safi],
8737 adv_smcap)
8738 ? ", "
8739 : "");
8740 vty_out(vty, "\n");
8741 }
8742 }
8743
8744 /* Receive-Mode */
8745 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8746 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8747 if (use_json) {
8748 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8749 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8750 json_object_string_add(json_pref, "recvMode",
8751 "advertisedAndReceived");
8752 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8753 json_object_string_add(json_pref, "recvMode",
8754 "advertised");
8755 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8756 json_object_string_add(json_pref, "recvMode",
8757 "received");
8758 } else {
8759 vty_out(vty, " Receive-mode: ");
8760 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8761 vty_out(vty, "advertised");
8762 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8763 vty_out(vty, "%sreceived",
8764 CHECK_FLAG(p->af_cap[afi][safi],
8765 adv_rmcap)
8766 ? ", "
8767 : "");
8768 vty_out(vty, "\n");
8769 }
8770 }
8771}
8772
8773static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 8774 safi_t safi, bool use_json,
d62a17ae 8775 json_object *json_neigh)
8776{
0291c246
MK
8777 struct bgp_filter *filter;
8778 struct peer_af *paf;
8779 char orf_pfx_name[BUFSIZ];
8780 int orf_pfx_count;
8781 json_object *json_af = NULL;
8782 json_object *json_prefA = NULL;
8783 json_object *json_prefB = NULL;
8784 json_object *json_addr = NULL;
d62a17ae 8785
8786 if (use_json) {
8787 json_addr = json_object_new_object();
8788 json_af = json_object_new_object();
8789 filter = &p->filter[afi][safi];
8790
8791 if (peer_group_active(p))
8792 json_object_string_add(json_addr, "peerGroupMember",
8793 p->group->name);
8794
8795 paf = peer_af_find(p, afi, safi);
8796 if (paf && PAF_SUBGRP(paf)) {
8797 json_object_int_add(json_addr, "updateGroupId",
8798 PAF_UPDGRP(paf)->id);
8799 json_object_int_add(json_addr, "subGroupId",
8800 PAF_SUBGRP(paf)->id);
8801 json_object_int_add(json_addr, "packetQueueLength",
8802 bpacket_queue_virtual_length(paf));
8803 }
8804
8805 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8806 || CHECK_FLAG(p->af_cap[afi][safi],
8807 PEER_CAP_ORF_PREFIX_SM_RCV)
8808 || CHECK_FLAG(p->af_cap[afi][safi],
8809 PEER_CAP_ORF_PREFIX_RM_ADV)
8810 || CHECK_FLAG(p->af_cap[afi][safi],
8811 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8812 json_object_int_add(json_af, "orfType",
8813 ORF_TYPE_PREFIX);
8814 json_prefA = json_object_new_object();
8815 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8816 PEER_CAP_ORF_PREFIX_SM_ADV,
8817 PEER_CAP_ORF_PREFIX_RM_ADV,
8818 PEER_CAP_ORF_PREFIX_SM_RCV,
8819 PEER_CAP_ORF_PREFIX_RM_RCV,
8820 use_json, json_prefA);
8821 json_object_object_add(json_af, "orfPrefixList",
8822 json_prefA);
8823 }
8824
8825 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8826 || CHECK_FLAG(p->af_cap[afi][safi],
8827 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8828 || CHECK_FLAG(p->af_cap[afi][safi],
8829 PEER_CAP_ORF_PREFIX_RM_ADV)
8830 || CHECK_FLAG(p->af_cap[afi][safi],
8831 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8832 json_object_int_add(json_af, "orfOldType",
8833 ORF_TYPE_PREFIX_OLD);
8834 json_prefB = json_object_new_object();
8835 bgp_show_peer_afi_orf_cap(
8836 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8837 PEER_CAP_ORF_PREFIX_RM_ADV,
8838 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8839 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8840 json_prefB);
8841 json_object_object_add(json_af, "orfOldPrefixList",
8842 json_prefB);
8843 }
8844
8845 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8846 || CHECK_FLAG(p->af_cap[afi][safi],
8847 PEER_CAP_ORF_PREFIX_SM_RCV)
8848 || CHECK_FLAG(p->af_cap[afi][safi],
8849 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8850 || CHECK_FLAG(p->af_cap[afi][safi],
8851 PEER_CAP_ORF_PREFIX_RM_ADV)
8852 || CHECK_FLAG(p->af_cap[afi][safi],
8853 PEER_CAP_ORF_PREFIX_RM_RCV)
8854 || CHECK_FLAG(p->af_cap[afi][safi],
8855 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8856 json_object_object_add(json_addr, "afDependentCap",
8857 json_af);
8858 else
8859 json_object_free(json_af);
8860
8861 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8862 orf_pfx_count = prefix_bgp_show_prefix_list(
8863 NULL, afi, orf_pfx_name, use_json);
8864
8865 if (CHECK_FLAG(p->af_sflags[afi][safi],
8866 PEER_STATUS_ORF_PREFIX_SEND)
8867 || orf_pfx_count) {
8868 if (CHECK_FLAG(p->af_sflags[afi][safi],
8869 PEER_STATUS_ORF_PREFIX_SEND))
8870 json_object_boolean_true_add(json_neigh,
8871 "orfSent");
8872 if (orf_pfx_count)
8873 json_object_int_add(json_addr, "orfRecvCounter",
8874 orf_pfx_count);
8875 }
8876 if (CHECK_FLAG(p->af_sflags[afi][safi],
8877 PEER_STATUS_ORF_WAIT_REFRESH))
8878 json_object_string_add(
8879 json_addr, "orfFirstUpdate",
8880 "deferredUntilORFOrRouteRefreshRecvd");
8881
8882 if (CHECK_FLAG(p->af_flags[afi][safi],
8883 PEER_FLAG_REFLECTOR_CLIENT))
8884 json_object_boolean_true_add(json_addr,
8885 "routeReflectorClient");
8886 if (CHECK_FLAG(p->af_flags[afi][safi],
8887 PEER_FLAG_RSERVER_CLIENT))
8888 json_object_boolean_true_add(json_addr,
8889 "routeServerClient");
8890 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8891 json_object_boolean_true_add(json_addr,
8892 "inboundSoftConfigPermit");
8893
8894 if (CHECK_FLAG(p->af_flags[afi][safi],
8895 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8896 json_object_boolean_true_add(
8897 json_addr,
8898 "privateAsNumsAllReplacedInUpdatesToNbr");
8899 else if (CHECK_FLAG(p->af_flags[afi][safi],
8900 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8901 json_object_boolean_true_add(
8902 json_addr,
8903 "privateAsNumsReplacedInUpdatesToNbr");
8904 else if (CHECK_FLAG(p->af_flags[afi][safi],
8905 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8906 json_object_boolean_true_add(
8907 json_addr,
8908 "privateAsNumsAllRemovedInUpdatesToNbr");
8909 else if (CHECK_FLAG(p->af_flags[afi][safi],
8910 PEER_FLAG_REMOVE_PRIVATE_AS))
8911 json_object_boolean_true_add(
8912 json_addr,
8913 "privateAsNumsRemovedInUpdatesToNbr");
8914
dcc68b5e
MS
8915 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8916 json_object_boolean_true_add(
8917 json_addr,
8918 bgp_addpath_names(p->addpath_type[afi][safi])
8919 ->type_json_name);
d62a17ae 8920
8921 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8922 json_object_string_add(json_addr,
8923 "overrideASNsInOutboundUpdates",
8924 "ifAspathEqualRemoteAs");
8925
8926 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8927 || CHECK_FLAG(p->af_flags[afi][safi],
8928 PEER_FLAG_FORCE_NEXTHOP_SELF))
8929 json_object_boolean_true_add(json_addr,
8930 "routerAlwaysNextHop");
8931 if (CHECK_FLAG(p->af_flags[afi][safi],
8932 PEER_FLAG_AS_PATH_UNCHANGED))
8933 json_object_boolean_true_add(
8934 json_addr, "unchangedAsPathPropogatedToNbr");
8935 if (CHECK_FLAG(p->af_flags[afi][safi],
8936 PEER_FLAG_NEXTHOP_UNCHANGED))
8937 json_object_boolean_true_add(
8938 json_addr, "unchangedNextHopPropogatedToNbr");
8939 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8940 json_object_boolean_true_add(
8941 json_addr, "unchangedMedPropogatedToNbr");
8942 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8943 || CHECK_FLAG(p->af_flags[afi][safi],
8944 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8945 if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_SEND_COMMUNITY)
8947 && CHECK_FLAG(p->af_flags[afi][safi],
8948 PEER_FLAG_SEND_EXT_COMMUNITY))
8949 json_object_string_add(json_addr,
8950 "commAttriSentToNbr",
8951 "extendedAndStandard");
8952 else if (CHECK_FLAG(p->af_flags[afi][safi],
8953 PEER_FLAG_SEND_EXT_COMMUNITY))
8954 json_object_string_add(json_addr,
8955 "commAttriSentToNbr",
8956 "extended");
8957 else
8958 json_object_string_add(json_addr,
8959 "commAttriSentToNbr",
8960 "standard");
8961 }
8962 if (CHECK_FLAG(p->af_flags[afi][safi],
8963 PEER_FLAG_DEFAULT_ORIGINATE)) {
8964 if (p->default_rmap[afi][safi].name)
8965 json_object_string_add(
8966 json_addr, "defaultRouteMap",
8967 p->default_rmap[afi][safi].name);
8968
8969 if (paf && PAF_SUBGRP(paf)
8970 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8971 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8972 json_object_boolean_true_add(json_addr,
8973 "defaultSent");
8974 else
8975 json_object_boolean_true_add(json_addr,
8976 "defaultNotSent");
8977 }
8978
dff8f48d 8979 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8980 if (is_evpn_enabled())
60466a63
QY
8981 json_object_boolean_true_add(
8982 json_addr, "advertiseAllVnis");
dff8f48d
MK
8983 }
8984
d62a17ae 8985 if (filter->plist[FILTER_IN].name
8986 || filter->dlist[FILTER_IN].name
8987 || filter->aslist[FILTER_IN].name
8988 || filter->map[RMAP_IN].name)
8989 json_object_boolean_true_add(json_addr,
8990 "inboundPathPolicyConfig");
8991 if (filter->plist[FILTER_OUT].name
8992 || filter->dlist[FILTER_OUT].name
8993 || filter->aslist[FILTER_OUT].name
8994 || filter->map[RMAP_OUT].name || filter->usmap.name)
8995 json_object_boolean_true_add(
8996 json_addr, "outboundPathPolicyConfig");
8997
8998 /* prefix-list */
8999 if (filter->plist[FILTER_IN].name)
9000 json_object_string_add(json_addr,
9001 "incomingUpdatePrefixFilterList",
9002 filter->plist[FILTER_IN].name);
9003 if (filter->plist[FILTER_OUT].name)
9004 json_object_string_add(json_addr,
9005 "outgoingUpdatePrefixFilterList",
9006 filter->plist[FILTER_OUT].name);
9007
9008 /* distribute-list */
9009 if (filter->dlist[FILTER_IN].name)
9010 json_object_string_add(
9011 json_addr, "incomingUpdateNetworkFilterList",
9012 filter->dlist[FILTER_IN].name);
9013 if (filter->dlist[FILTER_OUT].name)
9014 json_object_string_add(
9015 json_addr, "outgoingUpdateNetworkFilterList",
9016 filter->dlist[FILTER_OUT].name);
9017
9018 /* filter-list. */
9019 if (filter->aslist[FILTER_IN].name)
9020 json_object_string_add(json_addr,
9021 "incomingUpdateAsPathFilterList",
9022 filter->aslist[FILTER_IN].name);
9023 if (filter->aslist[FILTER_OUT].name)
9024 json_object_string_add(json_addr,
9025 "outgoingUpdateAsPathFilterList",
9026 filter->aslist[FILTER_OUT].name);
9027
9028 /* route-map. */
9029 if (filter->map[RMAP_IN].name)
9030 json_object_string_add(
9031 json_addr, "routeMapForIncomingAdvertisements",
9032 filter->map[RMAP_IN].name);
9033 if (filter->map[RMAP_OUT].name)
9034 json_object_string_add(
9035 json_addr, "routeMapForOutgoingAdvertisements",
9036 filter->map[RMAP_OUT].name);
9037
9dac9fc8
DA
9038 /* ebgp-requires-policy (inbound) */
9039 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9040 && !bgp_inbound_policy_exists(p, filter))
9041 json_object_string_add(
9042 json_addr, "inboundEbgpRequiresPolicy",
9043 "Inbound updates discarded due to missing policy");
9044
9045 /* ebgp-requires-policy (outbound) */
9046 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9047 && (!bgp_outbound_policy_exists(p, filter)))
9048 json_object_string_add(
9049 json_addr, "outboundEbgpRequiresPolicy",
9050 "Outbound updates discarded due to missing policy");
9051
d62a17ae 9052 /* unsuppress-map */
9053 if (filter->usmap.name)
9054 json_object_string_add(json_addr,
9055 "selectiveUnsuppressRouteMap",
9056 filter->usmap.name);
9057
9058 /* Receive prefix count */
9059 json_object_int_add(json_addr, "acceptedPrefixCounter",
9060 p->pcount[afi][safi]);
50e05855
AD
9061 if (paf && PAF_SUBGRP(paf))
9062 json_object_int_add(json_addr, "sentPrefixCounter",
9063 (PAF_SUBGRP(paf))->scount);
d62a17ae 9064
9065 /* Maximum prefix */
9066 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9067 json_object_int_add(json_addr, "prefixAllowedMax",
9068 p->pmax[afi][safi]);
9069 if (CHECK_FLAG(p->af_flags[afi][safi],
9070 PEER_FLAG_MAX_PREFIX_WARNING))
9071 json_object_boolean_true_add(
9072 json_addr, "prefixAllowedMaxWarning");
9073 json_object_int_add(json_addr,
9074 "prefixAllowedWarningThresh",
9075 p->pmax_threshold[afi][safi]);
9076 if (p->pmax_restart[afi][safi])
9077 json_object_int_add(
9078 json_addr,
9079 "prefixAllowedRestartIntervalMsecs",
9080 p->pmax_restart[afi][safi] * 60000);
9081 }
5cb5f4d0 9082 json_object_object_add(json_neigh, get_afi_safi_str(afi, safi, true),
d62a17ae 9083 json_addr);
9084
9085 } else {
9086 filter = &p->filter[afi][safi];
9087
9088 vty_out(vty, " For address family: %s\n",
5cb5f4d0 9089 get_afi_safi_str(afi, safi, false));
d62a17ae 9090
9091 if (peer_group_active(p))
9092 vty_out(vty, " %s peer-group member\n",
9093 p->group->name);
9094
9095 paf = peer_af_find(p, afi, safi);
9096 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
9097 vty_out(vty, " Update group %" PRIu64
9098 ", subgroup %" PRIu64 "\n",
d62a17ae 9099 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
9100 vty_out(vty, " Packet Queue length %d\n",
9101 bpacket_queue_virtual_length(paf));
9102 } else {
9103 vty_out(vty, " Not part of any update group\n");
9104 }
9105 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9106 || CHECK_FLAG(p->af_cap[afi][safi],
9107 PEER_CAP_ORF_PREFIX_SM_RCV)
9108 || CHECK_FLAG(p->af_cap[afi][safi],
9109 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9110 || CHECK_FLAG(p->af_cap[afi][safi],
9111 PEER_CAP_ORF_PREFIX_RM_ADV)
9112 || CHECK_FLAG(p->af_cap[afi][safi],
9113 PEER_CAP_ORF_PREFIX_RM_RCV)
9114 || CHECK_FLAG(p->af_cap[afi][safi],
9115 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9116 vty_out(vty, " AF-dependant capabilities:\n");
9117
9118 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9119 || CHECK_FLAG(p->af_cap[afi][safi],
9120 PEER_CAP_ORF_PREFIX_SM_RCV)
9121 || CHECK_FLAG(p->af_cap[afi][safi],
9122 PEER_CAP_ORF_PREFIX_RM_ADV)
9123 || CHECK_FLAG(p->af_cap[afi][safi],
9124 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9125 vty_out(vty,
9126 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9127 ORF_TYPE_PREFIX);
9128 bgp_show_peer_afi_orf_cap(
9129 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9130 PEER_CAP_ORF_PREFIX_RM_ADV,
9131 PEER_CAP_ORF_PREFIX_SM_RCV,
9132 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
9133 }
9134 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9135 || CHECK_FLAG(p->af_cap[afi][safi],
9136 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9137 || CHECK_FLAG(p->af_cap[afi][safi],
9138 PEER_CAP_ORF_PREFIX_RM_ADV)
9139 || CHECK_FLAG(p->af_cap[afi][safi],
9140 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9141 vty_out(vty,
9142 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
9143 ORF_TYPE_PREFIX_OLD);
9144 bgp_show_peer_afi_orf_cap(
9145 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9146 PEER_CAP_ORF_PREFIX_RM_ADV,
9147 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9148 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
9149 }
9150
9151 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9152 orf_pfx_count = prefix_bgp_show_prefix_list(
9153 NULL, afi, orf_pfx_name, use_json);
9154
9155 if (CHECK_FLAG(p->af_sflags[afi][safi],
9156 PEER_STATUS_ORF_PREFIX_SEND)
9157 || orf_pfx_count) {
9158 vty_out(vty, " Outbound Route Filter (ORF):");
9159 if (CHECK_FLAG(p->af_sflags[afi][safi],
9160 PEER_STATUS_ORF_PREFIX_SEND))
9161 vty_out(vty, " sent;");
9162 if (orf_pfx_count)
9163 vty_out(vty, " received (%d entries)",
9164 orf_pfx_count);
9165 vty_out(vty, "\n");
9166 }
9167 if (CHECK_FLAG(p->af_sflags[afi][safi],
9168 PEER_STATUS_ORF_WAIT_REFRESH))
9169 vty_out(vty,
9170 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
9171
9172 if (CHECK_FLAG(p->af_flags[afi][safi],
9173 PEER_FLAG_REFLECTOR_CLIENT))
9174 vty_out(vty, " Route-Reflector Client\n");
9175 if (CHECK_FLAG(p->af_flags[afi][safi],
9176 PEER_FLAG_RSERVER_CLIENT))
9177 vty_out(vty, " Route-Server Client\n");
9178 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9179 vty_out(vty,
9180 " Inbound soft reconfiguration allowed\n");
9181
9182 if (CHECK_FLAG(p->af_flags[afi][safi],
9183 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9184 vty_out(vty,
9185 " Private AS numbers (all) replaced in updates to this neighbor\n");
9186 else if (CHECK_FLAG(p->af_flags[afi][safi],
9187 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9188 vty_out(vty,
9189 " Private AS numbers replaced in updates to this neighbor\n");
9190 else if (CHECK_FLAG(p->af_flags[afi][safi],
9191 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9192 vty_out(vty,
9193 " Private AS numbers (all) removed in updates to this neighbor\n");
9194 else if (CHECK_FLAG(p->af_flags[afi][safi],
9195 PEER_FLAG_REMOVE_PRIVATE_AS))
9196 vty_out(vty,
9197 " Private AS numbers removed in updates to this neighbor\n");
9198
dcc68b5e
MS
9199 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9200 vty_out(vty, " %s\n",
9201 bgp_addpath_names(p->addpath_type[afi][safi])
9202 ->human_description);
d62a17ae 9203
9204 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9205 vty_out(vty,
9206 " Override ASNs in outbound updates if aspath equals remote-as\n");
9207
9208 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9209 || CHECK_FLAG(p->af_flags[afi][safi],
9210 PEER_FLAG_FORCE_NEXTHOP_SELF))
9211 vty_out(vty, " NEXT_HOP is always this router\n");
9212 if (CHECK_FLAG(p->af_flags[afi][safi],
9213 PEER_FLAG_AS_PATH_UNCHANGED))
9214 vty_out(vty,
9215 " AS_PATH is propagated unchanged to this neighbor\n");
9216 if (CHECK_FLAG(p->af_flags[afi][safi],
9217 PEER_FLAG_NEXTHOP_UNCHANGED))
9218 vty_out(vty,
9219 " NEXT_HOP is propagated unchanged to this neighbor\n");
9220 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9221 vty_out(vty,
9222 " MED is propagated unchanged to this neighbor\n");
9223 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9224 || CHECK_FLAG(p->af_flags[afi][safi],
9225 PEER_FLAG_SEND_EXT_COMMUNITY)
9226 || CHECK_FLAG(p->af_flags[afi][safi],
9227 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9228 vty_out(vty,
9229 " Community attribute sent to this neighbor");
9230 if (CHECK_FLAG(p->af_flags[afi][safi],
9231 PEER_FLAG_SEND_COMMUNITY)
9232 && CHECK_FLAG(p->af_flags[afi][safi],
9233 PEER_FLAG_SEND_EXT_COMMUNITY)
9234 && CHECK_FLAG(p->af_flags[afi][safi],
9235 PEER_FLAG_SEND_LARGE_COMMUNITY))
9236 vty_out(vty, "(all)\n");
9237 else if (CHECK_FLAG(p->af_flags[afi][safi],
9238 PEER_FLAG_SEND_LARGE_COMMUNITY))
9239 vty_out(vty, "(large)\n");
9240 else if (CHECK_FLAG(p->af_flags[afi][safi],
9241 PEER_FLAG_SEND_EXT_COMMUNITY))
9242 vty_out(vty, "(extended)\n");
9243 else
9244 vty_out(vty, "(standard)\n");
9245 }
9246 if (CHECK_FLAG(p->af_flags[afi][safi],
9247 PEER_FLAG_DEFAULT_ORIGINATE)) {
9248 vty_out(vty, " Default information originate,");
9249
9250 if (p->default_rmap[afi][safi].name)
9251 vty_out(vty, " default route-map %s%s,",
9252 p->default_rmap[afi][safi].map ? "*"
9253 : "",
9254 p->default_rmap[afi][safi].name);
9255 if (paf && PAF_SUBGRP(paf)
9256 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9257 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9258 vty_out(vty, " default sent\n");
9259 else
9260 vty_out(vty, " default not sent\n");
9261 }
9262
dff8f48d
MK
9263 /* advertise-vni-all */
9264 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 9265 if (is_evpn_enabled())
dff8f48d
MK
9266 vty_out(vty, " advertise-all-vni\n");
9267 }
9268
d62a17ae 9269 if (filter->plist[FILTER_IN].name
9270 || filter->dlist[FILTER_IN].name
9271 || filter->aslist[FILTER_IN].name
9272 || filter->map[RMAP_IN].name)
9273 vty_out(vty, " Inbound path policy configured\n");
9274 if (filter->plist[FILTER_OUT].name
9275 || filter->dlist[FILTER_OUT].name
9276 || filter->aslist[FILTER_OUT].name
9277 || filter->map[RMAP_OUT].name || filter->usmap.name)
9278 vty_out(vty, " Outbound path policy configured\n");
9279
9280 /* prefix-list */
9281 if (filter->plist[FILTER_IN].name)
9282 vty_out(vty,
9283 " Incoming update prefix filter list is %s%s\n",
9284 filter->plist[FILTER_IN].plist ? "*" : "",
9285 filter->plist[FILTER_IN].name);
9286 if (filter->plist[FILTER_OUT].name)
9287 vty_out(vty,
9288 " Outgoing update prefix filter list is %s%s\n",
9289 filter->plist[FILTER_OUT].plist ? "*" : "",
9290 filter->plist[FILTER_OUT].name);
9291
9292 /* distribute-list */
9293 if (filter->dlist[FILTER_IN].name)
9294 vty_out(vty,
9295 " Incoming update network filter list is %s%s\n",
9296 filter->dlist[FILTER_IN].alist ? "*" : "",
9297 filter->dlist[FILTER_IN].name);
9298 if (filter->dlist[FILTER_OUT].name)
9299 vty_out(vty,
9300 " Outgoing update network filter list is %s%s\n",
9301 filter->dlist[FILTER_OUT].alist ? "*" : "",
9302 filter->dlist[FILTER_OUT].name);
9303
9304 /* filter-list. */
9305 if (filter->aslist[FILTER_IN].name)
9306 vty_out(vty,
9307 " Incoming update AS path filter list is %s%s\n",
9308 filter->aslist[FILTER_IN].aslist ? "*" : "",
9309 filter->aslist[FILTER_IN].name);
9310 if (filter->aslist[FILTER_OUT].name)
9311 vty_out(vty,
9312 " Outgoing update AS path filter list is %s%s\n",
9313 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9314 filter->aslist[FILTER_OUT].name);
9315
9316 /* route-map. */
9317 if (filter->map[RMAP_IN].name)
9318 vty_out(vty,
9319 " Route map for incoming advertisements is %s%s\n",
9320 filter->map[RMAP_IN].map ? "*" : "",
9321 filter->map[RMAP_IN].name);
9322 if (filter->map[RMAP_OUT].name)
9323 vty_out(vty,
9324 " Route map for outgoing advertisements is %s%s\n",
9325 filter->map[RMAP_OUT].map ? "*" : "",
9326 filter->map[RMAP_OUT].name);
9327
9dac9fc8
DA
9328 /* ebgp-requires-policy (inbound) */
9329 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9330 && !bgp_inbound_policy_exists(p, filter))
9331 vty_out(vty,
9332 " Inbound updates discarded due to missing policy\n");
9333
9334 /* ebgp-requires-policy (outbound) */
9335 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9336 && !bgp_outbound_policy_exists(p, filter))
9337 vty_out(vty,
9338 " Outbound updates discarded due to missing policy\n");
9339
d62a17ae 9340 /* unsuppress-map */
9341 if (filter->usmap.name)
9342 vty_out(vty,
9343 " Route map for selective unsuppress is %s%s\n",
9344 filter->usmap.map ? "*" : "",
9345 filter->usmap.name);
9346
9347 /* Receive prefix count */
9348 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9349
9350 /* Maximum prefix */
9351 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9352 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9353 p->pmax[afi][safi],
9354 CHECK_FLAG(p->af_flags[afi][safi],
9355 PEER_FLAG_MAX_PREFIX_WARNING)
9356 ? " (warning-only)"
9357 : "");
9358 vty_out(vty, " Threshold for warning message %d%%",
9359 p->pmax_threshold[afi][safi]);
9360 if (p->pmax_restart[afi][safi])
9361 vty_out(vty, ", restart interval %d min",
9362 p->pmax_restart[afi][safi]);
9363 vty_out(vty, "\n");
9364 }
9365
9366 vty_out(vty, "\n");
9367 }
9368}
9369
9f049418 9370static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 9371 json_object *json)
718e3744 9372{
d62a17ae 9373 struct bgp *bgp;
9374 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9375 char timebuf[BGP_UPTIME_LEN];
9376 char dn_flag[2];
d62a17ae 9377 afi_t afi;
9378 safi_t safi;
d7c0a89a
QY
9379 uint16_t i;
9380 uint8_t *msg;
d62a17ae 9381 json_object *json_neigh = NULL;
9382 time_t epoch_tbuf;
718e3744 9383
d62a17ae 9384 bgp = p->bgp;
9385
9386 if (use_json)
9387 json_neigh = json_object_new_object();
9388
9389 memset(dn_flag, '\0', sizeof(dn_flag));
9390 if (!p->conf_if && peer_dynamic_neighbor(p))
9391 dn_flag[0] = '*';
9392
9393 if (!use_json) {
9394 if (p->conf_if) /* Configured interface name. */
9395 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9396 BGP_PEER_SU_UNSPEC(p)
9397 ? "None"
9398 : sockunion2str(&p->su, buf,
9399 SU_ADDRSTRLEN));
9400 else /* Configured IP address. */
9401 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9402 p->host);
9403 }
9404
9405 if (use_json) {
9406 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9407 json_object_string_add(json_neigh, "bgpNeighborAddr",
9408 "none");
9409 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9410 json_object_string_add(
9411 json_neigh, "bgpNeighborAddr",
9412 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9413
9414 json_object_int_add(json_neigh, "remoteAs", p->as);
9415
9416 if (p->change_local_as)
9417 json_object_int_add(json_neigh, "localAs",
9418 p->change_local_as);
9419 else
9420 json_object_int_add(json_neigh, "localAs", p->local_as);
9421
9422 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9423 json_object_boolean_true_add(json_neigh,
9424 "localAsNoPrepend");
9425
9426 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9427 json_object_boolean_true_add(json_neigh,
9428 "localAsReplaceAs");
9429 } else {
9430 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9431 || (p->as_type == AS_INTERNAL))
9432 vty_out(vty, "remote AS %u, ", p->as);
9433 else
9434 vty_out(vty, "remote AS Unspecified, ");
9435 vty_out(vty, "local AS %u%s%s, ",
9436 p->change_local_as ? p->change_local_as : p->local_as,
9437 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9438 ? " no-prepend"
9439 : "",
9440 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9441 ? " replace-as"
9442 : "");
9443 }
faa16034
DS
9444 /* peer type internal or confed-internal */
9445 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 9446 if (use_json) {
9447 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9448 json_object_boolean_true_add(
9449 json_neigh, "nbrConfedInternalLink");
9450 else
9451 json_object_boolean_true_add(json_neigh,
9452 "nbrInternalLink");
9453 } else {
9454 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9455 vty_out(vty, "confed-internal link\n");
9456 else
9457 vty_out(vty, "internal link\n");
9458 }
faa16034
DS
9459 /* peer type external or confed-external */
9460 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 9461 if (use_json) {
9462 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9463 json_object_boolean_true_add(
9464 json_neigh, "nbrConfedExternalLink");
9465 else
9466 json_object_boolean_true_add(json_neigh,
9467 "nbrExternalLink");
9468 } else {
9469 if (bgp_confederation_peers_check(bgp, p->as))
9470 vty_out(vty, "confed-external link\n");
9471 else
9472 vty_out(vty, "external link\n");
9473 }
faa16034
DS
9474 } else {
9475 if (use_json)
9476 json_object_boolean_true_add(json_neigh,
9477 "nbrUnspecifiedLink");
9478 else
9479 vty_out(vty, "unspecified link\n");
d62a17ae 9480 }
9481
9482 /* Description. */
9483 if (p->desc) {
9484 if (use_json)
9485 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9486 else
9487 vty_out(vty, " Description: %s\n", p->desc);
9488 }
9489
9490 if (p->hostname) {
9491 if (use_json) {
9492 if (p->hostname)
9493 json_object_string_add(json_neigh, "hostname",
9494 p->hostname);
9495
9496 if (p->domainname)
9497 json_object_string_add(json_neigh, "domainname",
9498 p->domainname);
9499 } else {
9500 if (p->domainname && (p->domainname[0] != '\0'))
9501 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9502 p->domainname);
9503 else
9504 vty_out(vty, "Hostname: %s\n", p->hostname);
9505 }
9506 }
9507
9508 /* Peer-group */
9509 if (p->group) {
9510 if (use_json) {
9511 json_object_string_add(json_neigh, "peerGroup",
9512 p->group->name);
9513
9514 if (dn_flag[0]) {
9515 struct prefix prefix, *range = NULL;
9516
9517 sockunion2hostprefix(&(p->su), &prefix);
9518 range = peer_group_lookup_dynamic_neighbor_range(
9519 p->group, &prefix);
9520
9521 if (range) {
9522 prefix2str(range, buf1, sizeof(buf1));
9523 json_object_string_add(
9524 json_neigh,
9525 "peerSubnetRangeGroup", buf1);
9526 }
9527 }
9528 } else {
9529 vty_out(vty,
9530 " Member of peer-group %s for session parameters\n",
9531 p->group->name);
9532
9533 if (dn_flag[0]) {
9534 struct prefix prefix, *range = NULL;
9535
9536 sockunion2hostprefix(&(p->su), &prefix);
9537 range = peer_group_lookup_dynamic_neighbor_range(
9538 p->group, &prefix);
9539
9540 if (range) {
9541 prefix2str(range, buf1, sizeof(buf1));
9542 vty_out(vty,
9543 " Belongs to the subnet range group: %s\n",
9544 buf1);
9545 }
9546 }
9547 }
9548 }
9549
9550 if (use_json) {
9551 /* Administrative shutdown. */
9552 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9553 json_object_boolean_true_add(json_neigh,
9554 "adminShutDown");
9555
9556 /* BGP Version. */
9557 json_object_int_add(json_neigh, "bgpVersion", 4);
9558 json_object_string_add(
9559 json_neigh, "remoteRouterId",
9560 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
9561 json_object_string_add(
9562 json_neigh, "localRouterId",
9563 inet_ntop(AF_INET, &bgp->router_id, buf1,
9564 sizeof(buf1)));
d62a17ae 9565
9566 /* Confederation */
9567 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9568 && bgp_confederation_peers_check(bgp, p->as))
9569 json_object_boolean_true_add(json_neigh,
9570 "nbrCommonAdmin");
9571
9572 /* Status. */
9573 json_object_string_add(
9574 json_neigh, "bgpState",
9575 lookup_msg(bgp_status_msg, p->status, NULL));
9576
9577 if (p->status == Established) {
9578 time_t uptime;
d62a17ae 9579
9580 uptime = bgp_clock();
9581 uptime -= p->uptime;
d62a17ae 9582 epoch_tbuf = time(NULL) - uptime;
9583
bee57a7a 9584#if CONFDATE > 20200101
a4d82a8a
PZ
9585 CPP_NOTICE(
9586 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
9587#endif
9588 /*
9589 * bgpTimerUp was miliseconds that was accurate
9590 * up to 1 day, then the value returned
9591 * became garbage. So in order to provide
9592 * some level of backwards compatability,
9593 * we still provde the data, but now
9594 * we are returning the correct value
9595 * and also adding a new bgpTimerUpMsec
9596 * which will allow us to deprecate
9597 * this eventually
9598 */
d62a17ae 9599 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 9600 uptime * 1000);
d3c7efed
DS
9601 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9602 uptime * 1000);
d62a17ae 9603 json_object_string_add(json_neigh, "bgpTimerUpString",
9604 peer_uptime(p->uptime, timebuf,
9605 BGP_UPTIME_LEN, 0,
9606 NULL));
9607 json_object_int_add(json_neigh,
9608 "bgpTimerUpEstablishedEpoch",
9609 epoch_tbuf);
9610 }
9611
9612 else if (p->status == Active) {
9613 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9614 json_object_string_add(json_neigh, "bgpStateIs",
9615 "passive");
9616 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9617 json_object_string_add(json_neigh, "bgpStateIs",
9618 "passiveNSF");
9619 }
9620
9621 /* read timer */
9622 time_t uptime;
9623 struct tm *tm;
9624
9625 uptime = bgp_clock();
9626 uptime -= p->readtime;
9627 tm = gmtime(&uptime);
9628 json_object_int_add(json_neigh, "bgpTimerLastRead",
9629 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9630 + (tm->tm_hour * 3600000));
9631
9632 uptime = bgp_clock();
9633 uptime -= p->last_write;
9634 tm = gmtime(&uptime);
9635 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9636 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9637 + (tm->tm_hour * 3600000));
9638
9639 uptime = bgp_clock();
9640 uptime -= p->update_time;
9641 tm = gmtime(&uptime);
9642 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9643 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9644 + (tm->tm_hour * 3600000));
9645
9646 /* Configured timer values. */
9647 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9648 p->v_holdtime * 1000);
9649 json_object_int_add(json_neigh,
9650 "bgpTimerKeepAliveIntervalMsecs",
9651 p->v_keepalive * 1000);
b90a8e13 9652 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9653 json_object_int_add(json_neigh,
9654 "bgpTimerConfiguredHoldTimeMsecs",
9655 p->holdtime * 1000);
9656 json_object_int_add(
9657 json_neigh,
9658 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9659 p->keepalive * 1000);
d25e4efc 9660 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9661 || (bgp->default_keepalive
9662 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9663 json_object_int_add(json_neigh,
9664 "bgpTimerConfiguredHoldTimeMsecs",
9665 bgp->default_holdtime);
9666 json_object_int_add(
9667 json_neigh,
9668 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9669 bgp->default_keepalive);
d62a17ae 9670 }
9671 } else {
9672 /* Administrative shutdown. */
9673 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9674 vty_out(vty, " Administratively shut down\n");
9675
9676 /* BGP Version. */
9677 vty_out(vty, " BGP version 4");
0e38aeb4 9678 vty_out(vty, ", remote router ID %s",
d62a17ae 9679 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
9680 vty_out(vty, ", local router ID %s\n",
9681 inet_ntop(AF_INET, &bgp->router_id, buf1,
9682 sizeof(buf1)));
d62a17ae 9683
9684 /* Confederation */
9685 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9686 && bgp_confederation_peers_check(bgp, p->as))
9687 vty_out(vty,
9688 " Neighbor under common administration\n");
9689
9690 /* Status. */
9691 vty_out(vty, " BGP state = %s",
9692 lookup_msg(bgp_status_msg, p->status, NULL));
9693
9694 if (p->status == Established)
9695 vty_out(vty, ", up for %8s",
9696 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9697 0, NULL));
9698
9699 else if (p->status == Active) {
9700 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9701 vty_out(vty, " (passive)");
9702 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9703 vty_out(vty, " (NSF passive)");
9704 }
9705 vty_out(vty, "\n");
9706
9707 /* read timer */
9708 vty_out(vty, " Last read %s",
9709 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9710 NULL));
9711 vty_out(vty, ", Last write %s\n",
9712 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9713 NULL));
9714
9715 /* Configured timer values. */
9716 vty_out(vty,
9717 " Hold time is %d, keepalive interval is %d seconds\n",
9718 p->v_holdtime, p->v_keepalive);
b90a8e13 9719 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 9720 vty_out(vty, " Configured hold time is %d",
9721 p->holdtime);
9722 vty_out(vty, ", keepalive interval is %d seconds\n",
9723 p->keepalive);
d25e4efc 9724 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
9725 || (bgp->default_keepalive
9726 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
9727 vty_out(vty, " Configured hold time is %d",
9728 bgp->default_holdtime);
9729 vty_out(vty, ", keepalive interval is %d seconds\n",
9730 bgp->default_keepalive);
d62a17ae 9731 }
9732 }
9733 /* Capability. */
9734 if (p->status == Established) {
9735 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9736 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9737 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9738 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9739 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9740 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9741 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9742 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9743 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9744 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9745 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9746 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 9747 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9748 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 9749 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9750 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 9751 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9752 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 9753 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9754 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9755 if (use_json) {
9756 json_object *json_cap = NULL;
9757
9758 json_cap = json_object_new_object();
9759
9760 /* AS4 */
9761 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9762 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9763 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9764 && CHECK_FLAG(p->cap,
9765 PEER_CAP_AS4_RCV))
9766 json_object_string_add(
9767 json_cap, "4byteAs",
9768 "advertisedAndReceived");
9769 else if (CHECK_FLAG(p->cap,
9770 PEER_CAP_AS4_ADV))
9771 json_object_string_add(
9772 json_cap, "4byteAs",
9773 "advertised");
9774 else if (CHECK_FLAG(p->cap,
9775 PEER_CAP_AS4_RCV))
9776 json_object_string_add(
9777 json_cap, "4byteAs",
9778 "received");
9779 }
9780
9781 /* AddPath */
9782 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9783 || CHECK_FLAG(p->cap,
9784 PEER_CAP_ADDPATH_ADV)) {
9785 json_object *json_add = NULL;
9786 const char *print_store;
9787
9788 json_add = json_object_new_object();
9789
05c7a1cc
QY
9790 FOREACH_AFI_SAFI (afi, safi) {
9791 json_object *json_sub = NULL;
9792 json_sub =
9793 json_object_new_object();
5cb5f4d0
DD
9794 print_store = get_afi_safi_str(
9795 afi, safi, true);
d62a17ae 9796
05c7a1cc
QY
9797 if (CHECK_FLAG(
9798 p->af_cap[afi]
9799 [safi],
9800 PEER_CAP_ADDPATH_AF_TX_ADV)
9801 || CHECK_FLAG(
9802 p->af_cap[afi]
9803 [safi],
9804 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9805 if (CHECK_FLAG(
9806 p->af_cap
9807 [afi]
9808 [safi],
9809 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9810 && CHECK_FLAG(
d62a17ae 9811 p->af_cap
9812 [afi]
9813 [safi],
05c7a1cc
QY
9814 PEER_CAP_ADDPATH_AF_TX_RCV))
9815 json_object_boolean_true_add(
9816 json_sub,
9817 "txAdvertisedAndReceived");
9818 else if (
9819 CHECK_FLAG(
9820 p->af_cap
9821 [afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_TX_ADV))
9824 json_object_boolean_true_add(
9825 json_sub,
9826 "txAdvertised");
9827 else if (
9828 CHECK_FLAG(
9829 p->af_cap
9830 [afi]
9831 [safi],
9832 PEER_CAP_ADDPATH_AF_TX_RCV))
9833 json_object_boolean_true_add(
9834 json_sub,
9835 "txReceived");
9836 }
d62a17ae 9837
05c7a1cc
QY
9838 if (CHECK_FLAG(
9839 p->af_cap[afi]
9840 [safi],
9841 PEER_CAP_ADDPATH_AF_RX_ADV)
9842 || CHECK_FLAG(
9843 p->af_cap[afi]
9844 [safi],
9845 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9846 if (CHECK_FLAG(
9847 p->af_cap
9848 [afi]
9849 [safi],
9850 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9851 && CHECK_FLAG(
d62a17ae 9852 p->af_cap
9853 [afi]
9854 [safi],
9855 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9856 json_object_boolean_true_add(
9857 json_sub,
9858 "rxAdvertisedAndReceived");
9859 else if (
9860 CHECK_FLAG(
9861 p->af_cap
9862 [afi]
9863 [safi],
9864 PEER_CAP_ADDPATH_AF_RX_ADV))
9865 json_object_boolean_true_add(
9866 json_sub,
9867 "rxAdvertised");
9868 else if (
9869 CHECK_FLAG(
9870 p->af_cap
9871 [afi]
9872 [safi],
9873 PEER_CAP_ADDPATH_AF_RX_RCV))
9874 json_object_boolean_true_add(
9875 json_sub,
9876 "rxReceived");
d62a17ae 9877 }
9878
05c7a1cc
QY
9879 if (CHECK_FLAG(
9880 p->af_cap[afi]
9881 [safi],
9882 PEER_CAP_ADDPATH_AF_TX_ADV)
9883 || CHECK_FLAG(
9884 p->af_cap[afi]
9885 [safi],
9886 PEER_CAP_ADDPATH_AF_TX_RCV)
9887 || CHECK_FLAG(
9888 p->af_cap[afi]
9889 [safi],
9890 PEER_CAP_ADDPATH_AF_RX_ADV)
9891 || CHECK_FLAG(
9892 p->af_cap[afi]
9893 [safi],
9894 PEER_CAP_ADDPATH_AF_RX_RCV))
9895 json_object_object_add(
9896 json_add,
9897 print_store,
9898 json_sub);
9899 else
9900 json_object_free(
9901 json_sub);
9902 }
9903
d62a17ae 9904 json_object_object_add(
9905 json_cap, "addPath", json_add);
9906 }
9907
9908 /* Dynamic */
9909 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9910 || CHECK_FLAG(p->cap,
9911 PEER_CAP_DYNAMIC_ADV)) {
9912 if (CHECK_FLAG(p->cap,
9913 PEER_CAP_DYNAMIC_ADV)
9914 && CHECK_FLAG(p->cap,
9915 PEER_CAP_DYNAMIC_RCV))
9916 json_object_string_add(
9917 json_cap, "dynamic",
9918 "advertisedAndReceived");
9919 else if (CHECK_FLAG(
9920 p->cap,
9921 PEER_CAP_DYNAMIC_ADV))
9922 json_object_string_add(
9923 json_cap, "dynamic",
9924 "advertised");
9925 else if (CHECK_FLAG(
9926 p->cap,
9927 PEER_CAP_DYNAMIC_RCV))
9928 json_object_string_add(
9929 json_cap, "dynamic",
9930 "received");
9931 }
9932
9933 /* Extended nexthop */
9934 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9935 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9936 json_object *json_nxt = NULL;
9937 const char *print_store;
9938
9939
9940 if (CHECK_FLAG(p->cap,
9941 PEER_CAP_ENHE_ADV)
9942 && CHECK_FLAG(p->cap,
9943 PEER_CAP_ENHE_RCV))
9944 json_object_string_add(
9945 json_cap,
9946 "extendedNexthop",
9947 "advertisedAndReceived");
9948 else if (CHECK_FLAG(p->cap,
9949 PEER_CAP_ENHE_ADV))
9950 json_object_string_add(
9951 json_cap,
9952 "extendedNexthop",
9953 "advertised");
9954 else if (CHECK_FLAG(p->cap,
9955 PEER_CAP_ENHE_RCV))
9956 json_object_string_add(
9957 json_cap,
9958 "extendedNexthop",
9959 "received");
9960
9961 if (CHECK_FLAG(p->cap,
9962 PEER_CAP_ENHE_RCV)) {
9963 json_nxt =
9964 json_object_new_object();
9965
9966 for (safi = SAFI_UNICAST;
9967 safi < SAFI_MAX; safi++) {
9968 if (CHECK_FLAG(
9969 p->af_cap
9970 [AFI_IP]
9971 [safi],
9972 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 9973 print_store = get_afi_safi_str(
d62a17ae 9974 AFI_IP,
5cb5f4d0 9975 safi, true);
d62a17ae 9976 json_object_string_add(
9977 json_nxt,
9978 print_store,
54f29523 9979 "recieved"); /* misspelled for compatibility */
d62a17ae 9980 }
9981 }
9982 json_object_object_add(
9983 json_cap,
9984 "extendedNexthopFamililesByPeer",
9985 json_nxt);
9986 }
9987 }
9988
9989 /* Route Refresh */
9990 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9991 || CHECK_FLAG(p->cap,
9992 PEER_CAP_REFRESH_NEW_RCV)
9993 || CHECK_FLAG(p->cap,
9994 PEER_CAP_REFRESH_OLD_RCV)) {
9995 if (CHECK_FLAG(p->cap,
9996 PEER_CAP_REFRESH_ADV)
9997 && (CHECK_FLAG(
9998 p->cap,
9999 PEER_CAP_REFRESH_NEW_RCV)
10000 || CHECK_FLAG(
10001 p->cap,
10002 PEER_CAP_REFRESH_OLD_RCV))) {
10003 if (CHECK_FLAG(
10004 p->cap,
10005 PEER_CAP_REFRESH_OLD_RCV)
10006 && CHECK_FLAG(
10007 p->cap,
10008 PEER_CAP_REFRESH_NEW_RCV))
10009 json_object_string_add(
10010 json_cap,
10011 "routeRefresh",
10012 "advertisedAndReceivedOldNew");
10013 else {
10014 if (CHECK_FLAG(
10015 p->cap,
10016 PEER_CAP_REFRESH_OLD_RCV))
10017 json_object_string_add(
10018 json_cap,
10019 "routeRefresh",
10020 "advertisedAndReceivedOld");
10021 else
10022 json_object_string_add(
10023 json_cap,
10024 "routeRefresh",
10025 "advertisedAndReceivedNew");
10026 }
10027 } else if (
10028 CHECK_FLAG(
10029 p->cap,
10030 PEER_CAP_REFRESH_ADV))
10031 json_object_string_add(
10032 json_cap,
10033 "routeRefresh",
10034 "advertised");
10035 else if (
10036 CHECK_FLAG(
10037 p->cap,
10038 PEER_CAP_REFRESH_NEW_RCV)
10039 || CHECK_FLAG(
10040 p->cap,
10041 PEER_CAP_REFRESH_OLD_RCV))
10042 json_object_string_add(
10043 json_cap,
10044 "routeRefresh",
10045 "received");
10046 }
10047
10048 /* Multiprotocol Extensions */
10049 json_object *json_multi = NULL;
10050 json_multi = json_object_new_object();
10051
05c7a1cc
QY
10052 FOREACH_AFI_SAFI (afi, safi) {
10053 if (p->afc_adv[afi][safi]
10054 || p->afc_recv[afi][safi]) {
10055 json_object *json_exten = NULL;
10056 json_exten =
10057 json_object_new_object();
10058
d62a17ae 10059 if (p->afc_adv[afi][safi]
05c7a1cc
QY
10060 && p->afc_recv[afi][safi])
10061 json_object_boolean_true_add(
10062 json_exten,
10063 "advertisedAndReceived");
10064 else if (p->afc_adv[afi][safi])
10065 json_object_boolean_true_add(
10066 json_exten,
10067 "advertised");
10068 else if (p->afc_recv[afi][safi])
10069 json_object_boolean_true_add(
10070 json_exten,
10071 "received");
d62a17ae 10072
05c7a1cc
QY
10073 json_object_object_add(
10074 json_multi,
5cb5f4d0
DD
10075 get_afi_safi_str(afi,
10076 safi,
10077 true),
05c7a1cc 10078 json_exten);
d62a17ae 10079 }
10080 }
10081 json_object_object_add(
10082 json_cap, "multiprotocolExtensions",
10083 json_multi);
10084
d77114b7 10085 /* Hostname capabilities */
60466a63 10086 json_object *json_hname = NULL;
d77114b7
MK
10087
10088 json_hname = json_object_new_object();
10089
10090 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10091 json_object_string_add(
60466a63
QY
10092 json_hname, "advHostName",
10093 bgp->peer_self->hostname
10094 ? bgp->peer_self
10095 ->hostname
d77114b7
MK
10096 : "n/a");
10097 json_object_string_add(
60466a63
QY
10098 json_hname, "advDomainName",
10099 bgp->peer_self->domainname
10100 ? bgp->peer_self
10101 ->domainname
d77114b7
MK
10102 : "n/a");
10103 }
10104
10105
10106 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10107 json_object_string_add(
60466a63
QY
10108 json_hname, "rcvHostName",
10109 p->hostname ? p->hostname
10110 : "n/a");
d77114b7 10111 json_object_string_add(
60466a63
QY
10112 json_hname, "rcvDomainName",
10113 p->domainname ? p->domainname
10114 : "n/a");
d77114b7
MK
10115 }
10116
60466a63 10117 json_object_object_add(json_cap, "hostName",
d77114b7
MK
10118 json_hname);
10119
d62a17ae 10120 /* Gracefull Restart */
10121 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10122 || CHECK_FLAG(p->cap,
10123 PEER_CAP_RESTART_ADV)) {
10124 if (CHECK_FLAG(p->cap,
10125 PEER_CAP_RESTART_ADV)
10126 && CHECK_FLAG(p->cap,
10127 PEER_CAP_RESTART_RCV))
10128 json_object_string_add(
10129 json_cap,
10130 "gracefulRestart",
10131 "advertisedAndReceived");
10132 else if (CHECK_FLAG(
10133 p->cap,
10134 PEER_CAP_RESTART_ADV))
10135 json_object_string_add(
10136 json_cap,
10137 "gracefulRestartCapability",
10138 "advertised");
10139 else if (CHECK_FLAG(
10140 p->cap,
10141 PEER_CAP_RESTART_RCV))
10142 json_object_string_add(
10143 json_cap,
10144 "gracefulRestartCapability",
10145 "received");
10146
10147 if (CHECK_FLAG(p->cap,
10148 PEER_CAP_RESTART_RCV)) {
10149 int restart_af_count = 0;
10150 json_object *json_restart =
10151 NULL;
10152 json_restart =
10153 json_object_new_object();
10154
10155 json_object_int_add(
10156 json_cap,
10157 "gracefulRestartRemoteTimerMsecs",
10158 p->v_gr_restart * 1000);
10159
05c7a1cc
QY
10160 FOREACH_AFI_SAFI (afi, safi) {
10161 if (CHECK_FLAG(
10162 p->af_cap
10163 [afi]
10164 [safi],
10165 PEER_CAP_RESTART_AF_RCV)) {
10166 json_object *
10167 json_sub =
10168 NULL;
10169 json_sub =
10170 json_object_new_object();
10171
d62a17ae 10172 if (CHECK_FLAG(
10173 p->af_cap
10174 [afi]
10175 [safi],
05c7a1cc
QY
10176 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10177 json_object_boolean_true_add(
10178 json_sub,
10179 "preserved");
10180 restart_af_count++;
10181 json_object_object_add(
10182 json_restart,
5cb5f4d0 10183 get_afi_safi_str(
05c7a1cc 10184 afi,
5cb5f4d0
DD
10185 safi,
10186 true),
05c7a1cc 10187 json_sub);
d62a17ae 10188 }
10189 }
10190 if (!restart_af_count) {
10191 json_object_string_add(
10192 json_cap,
10193 "addressFamiliesByPeer",
10194 "none");
10195 json_object_free(
10196 json_restart);
10197 } else
10198 json_object_object_add(
10199 json_cap,
10200 "addressFamiliesByPeer",
10201 json_restart);
10202 }
10203 }
10204 json_object_object_add(json_neigh,
10205 "neighborCapabilities",
10206 json_cap);
10207 } else {
10208 vty_out(vty, " Neighbor capabilities:\n");
10209
10210 /* AS4 */
10211 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10212 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10213 vty_out(vty, " 4 Byte AS:");
10214 if (CHECK_FLAG(p->cap,
10215 PEER_CAP_AS4_ADV))
10216 vty_out(vty, " advertised");
10217 if (CHECK_FLAG(p->cap,
10218 PEER_CAP_AS4_RCV))
10219 vty_out(vty, " %sreceived",
10220 CHECK_FLAG(
10221 p->cap,
10222 PEER_CAP_AS4_ADV)
10223 ? "and "
10224 : "");
10225 vty_out(vty, "\n");
10226 }
10227
10228 /* AddPath */
10229 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10230 || CHECK_FLAG(p->cap,
10231 PEER_CAP_ADDPATH_ADV)) {
10232 vty_out(vty, " AddPath:\n");
10233
05c7a1cc
QY
10234 FOREACH_AFI_SAFI (afi, safi) {
10235 if (CHECK_FLAG(
10236 p->af_cap[afi]
10237 [safi],
10238 PEER_CAP_ADDPATH_AF_TX_ADV)
10239 || CHECK_FLAG(
10240 p->af_cap[afi]
10241 [safi],
10242 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10243 vty_out(vty,
10244 " %s: TX ",
5cb5f4d0 10245 get_afi_safi_str(
05c7a1cc 10246 afi,
5cb5f4d0
DD
10247 safi,
10248 false));
05c7a1cc 10249
d62a17ae 10250 if (CHECK_FLAG(
10251 p->af_cap
10252 [afi]
10253 [safi],
05c7a1cc 10254 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 10255 vty_out(vty,
05c7a1cc 10256 "advertised %s",
5cb5f4d0 10257 get_afi_safi_str(
d62a17ae 10258 afi,
5cb5f4d0
DD
10259 safi,
10260 false));
d62a17ae 10261
05c7a1cc
QY
10262 if (CHECK_FLAG(
10263 p->af_cap
10264 [afi]
10265 [safi],
10266 PEER_CAP_ADDPATH_AF_TX_RCV))
10267 vty_out(vty,
10268 "%sreceived",
10269 CHECK_FLAG(
10270 p->af_cap
10271 [afi]
10272 [safi],
10273 PEER_CAP_ADDPATH_AF_TX_ADV)
10274 ? " and "
10275 : "");
d62a17ae 10276
05c7a1cc
QY
10277 vty_out(vty, "\n");
10278 }
d62a17ae 10279
05c7a1cc
QY
10280 if (CHECK_FLAG(
10281 p->af_cap[afi]
10282 [safi],
10283 PEER_CAP_ADDPATH_AF_RX_ADV)
10284 || CHECK_FLAG(
10285 p->af_cap[afi]
10286 [safi],
10287 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10288 vty_out(vty,
10289 " %s: RX ",
5cb5f4d0 10290 get_afi_safi_str(
05c7a1cc 10291 afi,
5cb5f4d0
DD
10292 safi,
10293 false));
d62a17ae 10294
10295 if (CHECK_FLAG(
10296 p->af_cap
10297 [afi]
10298 [safi],
05c7a1cc 10299 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 10300 vty_out(vty,
05c7a1cc 10301 "advertised %s",
5cb5f4d0 10302 get_afi_safi_str(
d62a17ae 10303 afi,
5cb5f4d0
DD
10304 safi,
10305 false));
d62a17ae 10306
05c7a1cc
QY
10307 if (CHECK_FLAG(
10308 p->af_cap
10309 [afi]
10310 [safi],
10311 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 10312 vty_out(vty,
05c7a1cc
QY
10313 "%sreceived",
10314 CHECK_FLAG(
10315 p->af_cap
10316 [afi]
10317 [safi],
10318 PEER_CAP_ADDPATH_AF_RX_ADV)
10319 ? " and "
10320 : "");
10321
10322 vty_out(vty, "\n");
d62a17ae 10323 }
05c7a1cc 10324 }
d62a17ae 10325 }
10326
10327 /* Dynamic */
10328 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10329 || CHECK_FLAG(p->cap,
10330 PEER_CAP_DYNAMIC_ADV)) {
10331 vty_out(vty, " Dynamic:");
10332 if (CHECK_FLAG(p->cap,
10333 PEER_CAP_DYNAMIC_ADV))
10334 vty_out(vty, " advertised");
10335 if (CHECK_FLAG(p->cap,
10336 PEER_CAP_DYNAMIC_RCV))
10337 vty_out(vty, " %sreceived",
10338 CHECK_FLAG(
10339 p->cap,
10340 PEER_CAP_DYNAMIC_ADV)
10341 ? "and "
10342 : "");
10343 vty_out(vty, "\n");
10344 }
10345
10346 /* Extended nexthop */
10347 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10348 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10349 vty_out(vty, " Extended nexthop:");
10350 if (CHECK_FLAG(p->cap,
10351 PEER_CAP_ENHE_ADV))
10352 vty_out(vty, " advertised");
10353 if (CHECK_FLAG(p->cap,
10354 PEER_CAP_ENHE_RCV))
10355 vty_out(vty, " %sreceived",
10356 CHECK_FLAG(
10357 p->cap,
10358 PEER_CAP_ENHE_ADV)
10359 ? "and "
10360 : "");
10361 vty_out(vty, "\n");
10362
10363 if (CHECK_FLAG(p->cap,
10364 PEER_CAP_ENHE_RCV)) {
10365 vty_out(vty,
10366 " Address families by peer:\n ");
10367 for (safi = SAFI_UNICAST;
10368 safi < SAFI_MAX; safi++)
10369 if (CHECK_FLAG(
10370 p->af_cap
10371 [AFI_IP]
10372 [safi],
10373 PEER_CAP_ENHE_AF_RCV))
10374 vty_out(vty,
10375 " %s\n",
5cb5f4d0 10376 get_afi_safi_str(
d62a17ae 10377 AFI_IP,
5cb5f4d0
DD
10378 safi,
10379 false));
d62a17ae 10380 }
10381 }
10382
10383 /* Route Refresh */
10384 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10385 || CHECK_FLAG(p->cap,
10386 PEER_CAP_REFRESH_NEW_RCV)
10387 || CHECK_FLAG(p->cap,
10388 PEER_CAP_REFRESH_OLD_RCV)) {
10389 vty_out(vty, " Route refresh:");
10390 if (CHECK_FLAG(p->cap,
10391 PEER_CAP_REFRESH_ADV))
10392 vty_out(vty, " advertised");
10393 if (CHECK_FLAG(p->cap,
10394 PEER_CAP_REFRESH_NEW_RCV)
10395 || CHECK_FLAG(
10396 p->cap,
10397 PEER_CAP_REFRESH_OLD_RCV))
10398 vty_out(vty, " %sreceived(%s)",
10399 CHECK_FLAG(
10400 p->cap,
10401 PEER_CAP_REFRESH_ADV)
10402 ? "and "
10403 : "",
10404 (CHECK_FLAG(
10405 p->cap,
10406 PEER_CAP_REFRESH_OLD_RCV)
10407 && CHECK_FLAG(
10408 p->cap,
10409 PEER_CAP_REFRESH_NEW_RCV))
10410 ? "old & new"
10411 : CHECK_FLAG(
10412 p->cap,
10413 PEER_CAP_REFRESH_OLD_RCV)
10414 ? "old"
10415 : "new");
10416
10417 vty_out(vty, "\n");
10418 }
10419
10420 /* Multiprotocol Extensions */
05c7a1cc
QY
10421 FOREACH_AFI_SAFI (afi, safi)
10422 if (p->afc_adv[afi][safi]
10423 || p->afc_recv[afi][safi]) {
10424 vty_out(vty,
10425 " Address Family %s:",
5cb5f4d0
DD
10426 get_afi_safi_str(
10427 afi,
10428 safi,
10429 false));
05c7a1cc 10430 if (p->afc_adv[afi][safi])
d62a17ae 10431 vty_out(vty,
05c7a1cc
QY
10432 " advertised");
10433 if (p->afc_recv[afi][safi])
10434 vty_out(vty,
10435 " %sreceived",
10436 p->afc_adv[afi]
10437 [safi]
10438 ? "and "
10439 : "");
10440 vty_out(vty, "\n");
10441 }
d62a17ae 10442
10443 /* Hostname capability */
60466a63 10444 vty_out(vty, " Hostname Capability:");
d77114b7
MK
10445
10446 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
10447 vty_out(vty,
10448 " advertised (name: %s,domain name: %s)",
60466a63
QY
10449 bgp->peer_self->hostname
10450 ? bgp->peer_self
10451 ->hostname
d77114b7 10452 : "n/a",
60466a63
QY
10453 bgp->peer_self->domainname
10454 ? bgp->peer_self
10455 ->domainname
d77114b7
MK
10456 : "n/a");
10457 } else {
10458 vty_out(vty, " not advertised");
d62a17ae 10459 }
10460
d77114b7 10461 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
10462 vty_out(vty,
10463 " received (name: %s,domain name: %s)",
60466a63
QY
10464 p->hostname ? p->hostname
10465 : "n/a",
10466 p->domainname ? p->domainname
10467 : "n/a");
d77114b7
MK
10468 } else {
10469 vty_out(vty, " not received");
10470 }
10471
10472 vty_out(vty, "\n");
10473
d62a17ae 10474 /* Gracefull Restart */
10475 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10476 || CHECK_FLAG(p->cap,
10477 PEER_CAP_RESTART_ADV)) {
10478 vty_out(vty,
10479 " Graceful Restart Capabilty:");
10480 if (CHECK_FLAG(p->cap,
10481 PEER_CAP_RESTART_ADV))
10482 vty_out(vty, " advertised");
10483 if (CHECK_FLAG(p->cap,
10484 PEER_CAP_RESTART_RCV))
10485 vty_out(vty, " %sreceived",
10486 CHECK_FLAG(
10487 p->cap,
10488 PEER_CAP_RESTART_ADV)
10489 ? "and "
10490 : "");
10491 vty_out(vty, "\n");
10492
10493 if (CHECK_FLAG(p->cap,
10494 PEER_CAP_RESTART_RCV)) {
10495 int restart_af_count = 0;
10496
10497 vty_out(vty,
10498 " Remote Restart timer is %d seconds\n",
10499 p->v_gr_restart);
10500 vty_out(vty,
10501 " Address families by peer:\n ");
10502
05c7a1cc
QY
10503 FOREACH_AFI_SAFI (afi, safi)
10504 if (CHECK_FLAG(
10505 p->af_cap
10506 [afi]
10507 [safi],
10508 PEER_CAP_RESTART_AF_RCV)) {
10509 vty_out(vty,
10510 "%s%s(%s)",
10511 restart_af_count
10512 ? ", "
10513 : "",
5cb5f4d0 10514 get_afi_safi_str(
05c7a1cc 10515 afi,
5cb5f4d0
DD
10516 safi,
10517 false),
05c7a1cc
QY
10518 CHECK_FLAG(
10519 p->af_cap
10520 [afi]
10521 [safi],
10522 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10523 ? "preserved"
10524 : "not preserved");
10525 restart_af_count++;
10526 }
d62a17ae 10527 if (!restart_af_count)
10528 vty_out(vty, "none");
10529 vty_out(vty, "\n");
10530 }
10531 }
10532 }
10533 }
10534 }
10535
10536 /* graceful restart information */
10537 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10538 || p->t_gr_stale) {
10539 json_object *json_grace = NULL;
10540 json_object *json_grace_send = NULL;
10541 json_object *json_grace_recv = NULL;
10542 int eor_send_af_count = 0;
10543 int eor_receive_af_count = 0;
10544
10545 if (use_json) {
10546 json_grace = json_object_new_object();
10547 json_grace_send = json_object_new_object();
10548 json_grace_recv = json_object_new_object();
10549
10550 if (p->status == Established) {
05c7a1cc
QY
10551 FOREACH_AFI_SAFI (afi, safi) {
10552 if (CHECK_FLAG(p->af_sflags[afi][safi],
10553 PEER_STATUS_EOR_SEND)) {
10554 json_object_boolean_true_add(
10555 json_grace_send,
5cb5f4d0
DD
10556 get_afi_safi_str(afi,
10557 safi,
10558 true));
05c7a1cc 10559 eor_send_af_count++;
d62a17ae 10560 }
10561 }
05c7a1cc
QY
10562 FOREACH_AFI_SAFI (afi, safi) {
10563 if (CHECK_FLAG(
10564 p->af_sflags[afi][safi],
10565 PEER_STATUS_EOR_RECEIVED)) {
10566 json_object_boolean_true_add(
10567 json_grace_recv,
5cb5f4d0
DD
10568 get_afi_safi_str(afi,
10569 safi,
10570 true));
05c7a1cc 10571 eor_receive_af_count++;
d62a17ae 10572 }
10573 }
10574 }
10575
10576 json_object_object_add(json_grace, "endOfRibSend",
10577 json_grace_send);
10578 json_object_object_add(json_grace, "endOfRibRecv",
10579 json_grace_recv);
10580
10581 if (p->t_gr_restart)
10582 json_object_int_add(json_grace,
10583 "gracefulRestartTimerMsecs",
10584 thread_timer_remain_second(
10585 p->t_gr_restart)
10586 * 1000);
10587
10588 if (p->t_gr_stale)
10589 json_object_int_add(
10590 json_grace,
10591 "gracefulStalepathTimerMsecs",
10592 thread_timer_remain_second(
10593 p->t_gr_stale)
10594 * 1000);
10595
10596 json_object_object_add(
10597 json_neigh, "gracefulRestartInfo", json_grace);
10598 } else {
0437e105 10599 vty_out(vty, " Graceful restart information:\n");
d62a17ae 10600 if (p->status == Established) {
10601 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
10602 FOREACH_AFI_SAFI (afi, safi) {
10603 if (CHECK_FLAG(p->af_sflags[afi][safi],
10604 PEER_STATUS_EOR_SEND)) {
10605 vty_out(vty, "%s%s",
10606 eor_send_af_count ? ", "
10607 : "",
5cb5f4d0
DD
10608 get_afi_safi_str(afi,
10609 safi,
10610 false));
05c7a1cc 10611 eor_send_af_count++;
d62a17ae 10612 }
10613 }
10614 vty_out(vty, "\n");
10615 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
10616 FOREACH_AFI_SAFI (afi, safi) {
10617 if (CHECK_FLAG(
10618 p->af_sflags[afi][safi],
10619 PEER_STATUS_EOR_RECEIVED)) {
10620 vty_out(vty, "%s%s",
10621 eor_receive_af_count
10622 ? ", "
10623 : "",
5cb5f4d0
DD
10624 get_afi_safi_str(afi,
10625 safi,
10626 false));
05c7a1cc 10627 eor_receive_af_count++;
d62a17ae 10628 }
10629 }
10630 vty_out(vty, "\n");
10631 }
10632
10633 if (p->t_gr_restart)
10634 vty_out(vty,
10635 " The remaining time of restart timer is %ld\n",
10636 thread_timer_remain_second(
10637 p->t_gr_restart));
10638
10639 if (p->t_gr_stale)
10640 vty_out(vty,
10641 " The remaining time of stalepath timer is %ld\n",
10642 thread_timer_remain_second(
10643 p->t_gr_stale));
10644 }
10645 }
10646 if (use_json) {
10647 json_object *json_stat = NULL;
10648 json_stat = json_object_new_object();
10649 /* Packet counts. */
10650 json_object_int_add(json_stat, "depthInq", 0);
10651 json_object_int_add(json_stat, "depthOutq",
10652 (unsigned long)p->obuf->count);
0112e9e0
QY
10653 json_object_int_add(json_stat, "opensSent",
10654 atomic_load_explicit(&p->open_out,
10655 memory_order_relaxed));
10656 json_object_int_add(json_stat, "opensRecv",
10657 atomic_load_explicit(&p->open_in,
10658 memory_order_relaxed));
d62a17ae 10659 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
10660 atomic_load_explicit(&p->notify_out,
10661 memory_order_relaxed));
d62a17ae 10662 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
10663 atomic_load_explicit(&p->notify_in,
10664 memory_order_relaxed));
10665 json_object_int_add(json_stat, "updatesSent",
10666 atomic_load_explicit(&p->update_out,
10667 memory_order_relaxed));
10668 json_object_int_add(json_stat, "updatesRecv",
10669 atomic_load_explicit(&p->update_in,
10670 memory_order_relaxed));
d62a17ae 10671 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
10672 atomic_load_explicit(&p->keepalive_out,
10673 memory_order_relaxed));
d62a17ae 10674 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
10675 atomic_load_explicit(&p->keepalive_in,
10676 memory_order_relaxed));
d62a17ae 10677 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
10678 atomic_load_explicit(&p->refresh_out,
10679 memory_order_relaxed));
d62a17ae 10680 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
10681 atomic_load_explicit(&p->refresh_in,
10682 memory_order_relaxed));
d62a17ae 10683 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
10684 atomic_load_explicit(&p->dynamic_cap_out,
10685 memory_order_relaxed));
d62a17ae 10686 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
10687 atomic_load_explicit(&p->dynamic_cap_in,
10688 memory_order_relaxed));
10689 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10690 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 10691 json_object_object_add(json_neigh, "messageStats", json_stat);
10692 } else {
10693 /* Packet counts. */
10694 vty_out(vty, " Message statistics:\n");
10695 vty_out(vty, " Inq depth is 0\n");
10696 vty_out(vty, " Outq depth is %lu\n",
10697 (unsigned long)p->obuf->count);
10698 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
10699 vty_out(vty, " Opens: %10d %10d\n",
10700 atomic_load_explicit(&p->open_out,
10701 memory_order_relaxed),
10702 atomic_load_explicit(&p->open_in,
10703 memory_order_relaxed));
10704 vty_out(vty, " Notifications: %10d %10d\n",
10705 atomic_load_explicit(&p->notify_out,
10706 memory_order_relaxed),
10707 atomic_load_explicit(&p->notify_in,
10708 memory_order_relaxed));
10709 vty_out(vty, " Updates: %10d %10d\n",
10710 atomic_load_explicit(&p->update_out,
10711 memory_order_relaxed),
10712 atomic_load_explicit(&p->update_in,
10713 memory_order_relaxed));
10714 vty_out(vty, " Keepalives: %10d %10d\n",
10715 atomic_load_explicit(&p->keepalive_out,
10716 memory_order_relaxed),
10717 atomic_load_explicit(&p->keepalive_in,
10718 memory_order_relaxed));
10719 vty_out(vty, " Route Refresh: %10d %10d\n",
10720 atomic_load_explicit(&p->refresh_out,
10721 memory_order_relaxed),
10722 atomic_load_explicit(&p->refresh_in,
10723 memory_order_relaxed));
d62a17ae 10724 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
10725 atomic_load_explicit(&p->dynamic_cap_out,
10726 memory_order_relaxed),
10727 atomic_load_explicit(&p->dynamic_cap_in,
10728 memory_order_relaxed));
10729 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10730 PEER_TOTAL_RX(p));
d62a17ae 10731 }
10732
10733 if (use_json) {
10734 /* advertisement-interval */
10735 json_object_int_add(json_neigh,
10736 "minBtwnAdvertisementRunsTimerMsecs",
10737 p->v_routeadv * 1000);
10738
10739 /* Update-source. */
10740 if (p->update_if || p->update_source) {
10741 if (p->update_if)
10742 json_object_string_add(json_neigh,
10743 "updateSource",
10744 p->update_if);
10745 else if (p->update_source)
10746 json_object_string_add(
10747 json_neigh, "updateSource",
10748 sockunion2str(p->update_source, buf1,
10749 SU_ADDRSTRLEN));
10750 }
10751 } else {
10752 /* advertisement-interval */
10753 vty_out(vty,
10754 " Minimum time between advertisement runs is %d seconds\n",
10755 p->v_routeadv);
10756
10757 /* Update-source. */
10758 if (p->update_if || p->update_source) {
10759 vty_out(vty, " Update source is ");
10760 if (p->update_if)
10761 vty_out(vty, "%s", p->update_if);
10762 else if (p->update_source)
10763 vty_out(vty, "%s",
10764 sockunion2str(p->update_source, buf1,
10765 SU_ADDRSTRLEN));
10766 vty_out(vty, "\n");
10767 }
10768
10769 vty_out(vty, "\n");
10770 }
10771
10772 /* Address Family Information */
10773 json_object *json_hold = NULL;
10774
10775 if (use_json)
10776 json_hold = json_object_new_object();
10777
05c7a1cc
QY
10778 FOREACH_AFI_SAFI (afi, safi)
10779 if (p->afc[afi][safi])
10780 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10781 json_hold);
d62a17ae 10782
10783 if (use_json) {
10784 json_object_object_add(json_neigh, "addressFamilyInfo",
10785 json_hold);
10786 json_object_int_add(json_neigh, "connectionsEstablished",
10787 p->established);
10788 json_object_int_add(json_neigh, "connectionsDropped",
10789 p->dropped);
10790 } else
10791 vty_out(vty, " Connections established %d; dropped %d\n",
10792 p->established, p->dropped);
10793
10794 if (!p->last_reset) {
10795 if (use_json)
10796 json_object_string_add(json_neigh, "lastReset",
10797 "never");
10798 else
10799 vty_out(vty, " Last reset never\n");
10800 } else {
10801 if (use_json) {
10802 time_t uptime;
10803 struct tm *tm;
10804
10805 uptime = bgp_clock();
10806 uptime -= p->resettime;
10807 tm = gmtime(&uptime);
10808 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10809 (tm->tm_sec * 1000)
10810 + (tm->tm_min * 60000)
10811 + (tm->tm_hour * 3600000));
3577f1c5 10812 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 10813 } else {
10814 vty_out(vty, " Last reset %s, ",
10815 peer_uptime(p->resettime, timebuf,
10816 BGP_UPTIME_LEN, 0, NULL));
10817
3577f1c5 10818 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 10819 if (p->last_reset_cause_size) {
10820 msg = p->last_reset_cause;
10821 vty_out(vty,
10822 " Message received that caused BGP to send a NOTIFICATION:\n ");
10823 for (i = 1; i <= p->last_reset_cause_size;
10824 i++) {
10825 vty_out(vty, "%02X", *msg++);
10826
10827 if (i != p->last_reset_cause_size) {
10828 if (i % 16 == 0) {
10829 vty_out(vty, "\n ");
10830 } else if (i % 4 == 0) {
10831 vty_out(vty, " ");
10832 }
10833 }
10834 }
10835 vty_out(vty, "\n");
10836 }
10837 }
10838 }
10839
10840 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10841 if (use_json)
10842 json_object_boolean_true_add(json_neigh,
10843 "prefixesConfigExceedMax");
10844 else
10845 vty_out(vty,
10846 " Peer had exceeded the max. no. of prefixes configured.\n");
10847
10848 if (p->t_pmax_restart) {
10849 if (use_json) {
10850 json_object_boolean_true_add(
10851 json_neigh, "reducePrefixNumFrom");
10852 json_object_int_add(json_neigh,
10853 "restartInTimerMsec",
10854 thread_timer_remain_second(
10855 p->t_pmax_restart)
10856 * 1000);
10857 } else
10858 vty_out(vty,
10859 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10860 p->host, thread_timer_remain_second(
10861 p->t_pmax_restart));
d62a17ae 10862 } else {
10863 if (use_json)
10864 json_object_boolean_true_add(
10865 json_neigh,
10866 "reducePrefixNumAndClearIpBgp");
10867 else
10868 vty_out(vty,
10869 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10870 p->host);
10871 }
10872 }
10873
10874 /* EBGP Multihop and GTSM */
10875 if (p->sort != BGP_PEER_IBGP) {
10876 if (use_json) {
10877 if (p->gtsm_hops > 0)
10878 json_object_int_add(json_neigh,
10879 "externalBgpNbrMaxHopsAway",
10880 p->gtsm_hops);
10881 else if (p->ttl > 1)
10882 json_object_int_add(json_neigh,
10883 "externalBgpNbrMaxHopsAway",
10884 p->ttl);
10885 } else {
10886 if (p->gtsm_hops > 0)
10887 vty_out(vty,
10888 " External BGP neighbor may be up to %d hops away.\n",
10889 p->gtsm_hops);
10890 else if (p->ttl > 1)
10891 vty_out(vty,
10892 " External BGP neighbor may be up to %d hops away.\n",
10893 p->ttl);
10894 }
10895 } else {
10896 if (p->gtsm_hops > 0) {
10897 if (use_json)
10898 json_object_int_add(json_neigh,
10899 "internalBgpNbrMaxHopsAway",
10900 p->gtsm_hops);
10901 else
10902 vty_out(vty,
10903 " Internal BGP neighbor may be up to %d hops away.\n",
10904 p->gtsm_hops);
10905 }
10906 }
10907
10908 /* Local address. */
10909 if (p->su_local) {
10910 if (use_json) {
10911 json_object_string_add(json_neigh, "hostLocal",
10912 sockunion2str(p->su_local, buf1,
10913 SU_ADDRSTRLEN));
10914 json_object_int_add(json_neigh, "portLocal",
10915 ntohs(p->su_local->sin.sin_port));
10916 } else
10917 vty_out(vty, "Local host: %s, Local port: %d\n",
10918 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10919 ntohs(p->su_local->sin.sin_port));
10920 }
10921
10922 /* Remote address. */
10923 if (p->su_remote) {
10924 if (use_json) {
10925 json_object_string_add(json_neigh, "hostForeign",
10926 sockunion2str(p->su_remote, buf1,
10927 SU_ADDRSTRLEN));
10928 json_object_int_add(json_neigh, "portForeign",
10929 ntohs(p->su_remote->sin.sin_port));
10930 } else
10931 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10932 sockunion2str(p->su_remote, buf1,
10933 SU_ADDRSTRLEN),
10934 ntohs(p->su_remote->sin.sin_port));
10935 }
10936
10937 /* Nexthop display. */
10938 if (p->su_local) {
10939 if (use_json) {
10940 json_object_string_add(json_neigh, "nexthop",
10941 inet_ntop(AF_INET,
10942 &p->nexthop.v4, buf1,
10943 sizeof(buf1)));
10944 json_object_string_add(json_neigh, "nexthopGlobal",
10945 inet_ntop(AF_INET6,
10946 &p->nexthop.v6_global,
10947 buf1, sizeof(buf1)));
10948 json_object_string_add(json_neigh, "nexthopLocal",
10949 inet_ntop(AF_INET6,
10950 &p->nexthop.v6_local,
10951 buf1, sizeof(buf1)));
10952 if (p->shared_network)
10953 json_object_string_add(json_neigh,
10954 "bgpConnection",
10955 "sharedNetwork");
10956 else
10957 json_object_string_add(json_neigh,
10958 "bgpConnection",
10959 "nonSharedNetwork");
10960 } else {
10961 vty_out(vty, "Nexthop: %s\n",
10962 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10963 sizeof(buf1)));
10964 vty_out(vty, "Nexthop global: %s\n",
10965 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10966 sizeof(buf1)));
10967 vty_out(vty, "Nexthop local: %s\n",
10968 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10969 sizeof(buf1)));
10970 vty_out(vty, "BGP connection: %s\n",
10971 p->shared_network ? "shared network"
10972 : "non shared network");
10973 }
10974 }
10975
10976 /* Timer information. */
10977 if (use_json) {
10978 json_object_int_add(json_neigh, "connectRetryTimer",
10979 p->v_connect);
10980 if (p->status == Established && p->rtt)
10981 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10982 p->rtt);
10983 if (p->t_start)
10984 json_object_int_add(
10985 json_neigh, "nextStartTimerDueInMsecs",
10986 thread_timer_remain_second(p->t_start) * 1000);
10987 if (p->t_connect)
10988 json_object_int_add(
10989 json_neigh, "nextConnectTimerDueInMsecs",
10990 thread_timer_remain_second(p->t_connect)
10991 * 1000);
10992 if (p->t_routeadv) {
10993 json_object_int_add(json_neigh, "mraiInterval",
10994 p->v_routeadv);
10995 json_object_int_add(
10996 json_neigh, "mraiTimerExpireInMsecs",
10997 thread_timer_remain_second(p->t_routeadv)
10998 * 1000);
10999 }
11000 if (p->password)
11001 json_object_int_add(json_neigh, "authenticationEnabled",
11002 1);
11003
11004 if (p->t_read)
11005 json_object_string_add(json_neigh, "readThread", "on");
11006 else
11007 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
11008
11009 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 11010 json_object_string_add(json_neigh, "writeThread", "on");
11011 else
11012 json_object_string_add(json_neigh, "writeThread",
11013 "off");
11014 } else {
11015 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
11016 p->v_connect);
11017 if (p->status == Established && p->rtt)
11018 vty_out(vty, "Estimated round trip time: %d ms\n",
11019 p->rtt);
11020 if (p->t_start)
11021 vty_out(vty, "Next start timer due in %ld seconds\n",
11022 thread_timer_remain_second(p->t_start));
11023 if (p->t_connect)
11024 vty_out(vty, "Next connect timer due in %ld seconds\n",
11025 thread_timer_remain_second(p->t_connect));
11026 if (p->t_routeadv)
11027 vty_out(vty,
11028 "MRAI (interval %u) timer expires in %ld seconds\n",
11029 p->v_routeadv,
11030 thread_timer_remain_second(p->t_routeadv));
11031 if (p->password)
11032 vty_out(vty, "Peer Authentication Enabled\n");
11033
cac9e917 11034 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
11035 p->t_read ? "on" : "off",
11036 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
11037 ? "on"
cac9e917 11038 : "off", p->fd);
d62a17ae 11039 }
11040
11041 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
11042 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
11043 bgp_capability_vty_out(vty, p, use_json, json_neigh);
11044
11045 if (!use_json)
11046 vty_out(vty, "\n");
11047
11048 /* BFD information. */
11049 bgp_bfd_show_info(vty, p, use_json, json_neigh);
11050
11051 if (use_json) {
11052 if (p->conf_if) /* Configured interface name. */
11053 json_object_object_add(json, p->conf_if, json_neigh);
11054 else /* Configured IP address. */
11055 json_object_object_add(json, p->host, json_neigh);
11056 }
11057}
11058
11059static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
11060 enum show_type type, union sockunion *su,
9f049418 11061 const char *conf_if, bool use_json,
d62a17ae 11062 json_object *json)
11063{
11064 struct listnode *node, *nnode;
11065 struct peer *peer;
11066 int find = 0;
9f049418 11067 bool nbr_output = false;
d1927ebe
AS
11068 afi_t afi = AFI_MAX;
11069 safi_t safi = SAFI_MAX;
11070
11071 if (type == show_ipv4_peer || type == show_ipv4_all) {
11072 afi = AFI_IP;
11073 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
11074 afi = AFI_IP6;
11075 }
d62a17ae 11076
11077 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
11078 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
11079 continue;
11080
11081 switch (type) {
11082 case show_all:
11083 bgp_show_peer(vty, peer, use_json, json);
9f049418 11084 nbr_output = true;
d62a17ae 11085 break;
11086 case show_peer:
11087 if (conf_if) {
11088 if ((peer->conf_if
11089 && !strcmp(peer->conf_if, conf_if))
11090 || (peer->hostname
11091 && !strcmp(peer->hostname, conf_if))) {
11092 find = 1;
11093 bgp_show_peer(vty, peer, use_json,
11094 json);
11095 }
11096 } else {
11097 if (sockunion_same(&peer->su, su)) {
11098 find = 1;
11099 bgp_show_peer(vty, peer, use_json,
11100 json);
11101 }
11102 }
11103 break;
d1927ebe
AS
11104 case show_ipv4_peer:
11105 case show_ipv6_peer:
11106 FOREACH_SAFI (safi) {
11107 if (peer->afc[afi][safi]) {
11108 if (conf_if) {
11109 if ((peer->conf_if
11110 && !strcmp(peer->conf_if, conf_if))
11111 || (peer->hostname
11112 && !strcmp(peer->hostname, conf_if))) {
11113 find = 1;
11114 bgp_show_peer(vty, peer, use_json,
11115 json);
11116 break;
11117 }
11118 } else {
11119 if (sockunion_same(&peer->su, su)) {
11120 find = 1;
11121 bgp_show_peer(vty, peer, use_json,
11122 json);
11123 break;
11124 }
11125 }
11126 }
11127 }
11128 break;
11129 case show_ipv4_all:
11130 case show_ipv6_all:
11131 FOREACH_SAFI (safi) {
11132 if (peer->afc[afi][safi]) {
11133 bgp_show_peer(vty, peer, use_json, json);
11134 nbr_output = true;
11135 break;
11136 }
11137 }
11138 break;
d62a17ae 11139 }
11140 }
11141
d1927ebe
AS
11142 if ((type == show_peer || type == show_ipv4_peer ||
11143 type == show_ipv6_peer) && !find) {
d62a17ae 11144 if (use_json)
11145 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
11146 else
88b7d255 11147 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 11148 }
11149
d1927ebe
AS
11150 if (type != show_peer && type != show_ipv4_peer &&
11151 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 11152 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 11153
d62a17ae 11154 if (use_json) {
996c9314
LB
11155 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11156 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11157 } else {
11158 vty_out(vty, "\n");
11159 }
11160
11161 return CMD_SUCCESS;
11162}
11163
11164static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
11165 enum show_type type,
11166 const char *ip_str,
9f049418 11167 bool use_json)
d62a17ae 11168{
0291c246
MK
11169 struct listnode *node, *nnode;
11170 struct bgp *bgp;
71aedaa3 11171 union sockunion su;
0291c246 11172 json_object *json = NULL;
71aedaa3 11173 int ret, is_first = 1;
9f049418 11174 bool nbr_output = false;
d62a17ae 11175
11176 if (use_json)
11177 vty_out(vty, "{\n");
11178
11179 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11180 nbr_output = true;
d62a17ae 11181 if (use_json) {
11182 if (!(json = json_object_new_object())) {
af4c2728 11183 flog_err(
e50f7cfd 11184 EC_BGP_JSON_MEM_ERROR,
d62a17ae 11185 "Unable to allocate memory for JSON object");
11186 vty_out(vty,
11187 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11188 return;
11189 }
11190
11191 json_object_int_add(json, "vrfId",
11192 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
11193 ? -1
11194 : (int64_t)bgp->vrf_id);
d62a17ae 11195 json_object_string_add(
11196 json, "vrfName",
11197 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11198 ? VRF_DEFAULT_NAME
d62a17ae 11199 : bgp->name);
11200
11201 if (!is_first)
11202 vty_out(vty, ",\n");
11203 else
11204 is_first = 0;
11205
11206 vty_out(vty, "\"%s\":",
11207 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11208 ? VRF_DEFAULT_NAME
d62a17ae 11209 : bgp->name);
11210 } else {
11211 vty_out(vty, "\nInstance %s:\n",
11212 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11213 ? VRF_DEFAULT_NAME
d62a17ae 11214 : bgp->name);
11215 }
71aedaa3 11216
d1927ebe
AS
11217 if (type == show_peer || type == show_ipv4_peer ||
11218 type == show_ipv6_peer) {
71aedaa3
DS
11219 ret = str2sockunion(ip_str, &su);
11220 if (ret < 0)
11221 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11222 use_json, json);
11223 else
11224 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11225 use_json, json);
11226 } else {
d1927ebe 11227 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
11228 use_json, json);
11229 }
b77004d6 11230 json_object_free(json);
d62a17ae 11231 }
11232
01cbfd04 11233 if (use_json) {
d62a17ae 11234 vty_out(vty, "}\n");
01cbfd04
QY
11235 json_object_free(json);
11236 }
9f049418
DS
11237 else if (!nbr_output)
11238 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11239}
11240
11241static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11242 enum show_type type, const char *ip_str,
9f049418 11243 bool use_json)
d62a17ae 11244{
11245 int ret;
11246 struct bgp *bgp;
11247 union sockunion su;
11248 json_object *json = NULL;
11249
11250 if (name) {
11251 if (strmatch(name, "all")) {
71aedaa3
DS
11252 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11253 use_json);
d62a17ae 11254 return CMD_SUCCESS;
11255 } else {
11256 bgp = bgp_lookup_by_name(name);
11257 if (!bgp) {
11258 if (use_json) {
11259 json = json_object_new_object();
d62a17ae 11260 vty_out(vty, "%s\n",
11261 json_object_to_json_string_ext(
11262 json,
11263 JSON_C_TO_STRING_PRETTY));
11264 json_object_free(json);
11265 } else
11266 vty_out(vty,
9f049418 11267 "%% BGP instance not found\n");
d62a17ae 11268
11269 return CMD_WARNING;
11270 }
11271 }
11272 } else {
11273 bgp = bgp_get_default();
11274 }
11275
11276 if (bgp) {
11277 json = json_object_new_object();
11278 if (ip_str) {
11279 ret = str2sockunion(ip_str, &su);
11280 if (ret < 0)
11281 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11282 use_json, json);
11283 else
11284 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11285 use_json, json);
11286 } else {
11287 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11288 json);
11289 }
11290 json_object_free(json);
ca61fd25
DS
11291 } else {
11292 if (use_json)
11293 vty_out(vty, "{}\n");
11294 else
11295 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11296 }
11297
11298 return CMD_SUCCESS;
4fb25c53
DW
11299}
11300
716b2d8a 11301/* "show [ip] bgp neighbors" commands. */
718e3744 11302DEFUN (show_ip_bgp_neighbors,
11303 show_ip_bgp_neighbors_cmd,
24345e82 11304 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 11305 SHOW_STR
11306 IP_STR
11307 BGP_STR
f2a8972b 11308 BGP_INSTANCE_HELP_STR
8c3deaae
QY
11309 "Address Family\n"
11310 "Address Family\n"
718e3744 11311 "Detailed information on TCP and BGP neighbor connections\n"
11312 "Neighbor to display information about\n"
a80beece 11313 "Neighbor to display information about\n"
91d37724 11314 "Neighbor on BGP configured interface\n"
9973d184 11315 JSON_STR)
718e3744 11316{
d62a17ae 11317 char *vrf = NULL;
11318 char *sh_arg = NULL;
11319 enum show_type sh_type;
d1927ebe 11320 afi_t afi = AFI_MAX;
718e3744 11321
9f049418 11322 bool uj = use_json(argc, argv);
718e3744 11323
d62a17ae 11324 int idx = 0;
718e3744 11325
9a8bdf1c
PG
11326 /* [<vrf> VIEWVRFNAME] */
11327 if (argv_find(argv, argc, "vrf", &idx)) {
11328 vrf = argv[idx + 1]->arg;
11329 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11330 vrf = NULL;
11331 } else if (argv_find(argv, argc, "view", &idx))
11332 /* [<view> VIEWVRFNAME] */
d62a17ae 11333 vrf = argv[idx + 1]->arg;
718e3744 11334
d62a17ae 11335 idx++;
d1927ebe
AS
11336
11337 if (argv_find(argv, argc, "ipv4", &idx)) {
11338 sh_type = show_ipv4_all;
11339 afi = AFI_IP;
11340 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11341 sh_type = show_ipv6_all;
11342 afi = AFI_IP6;
11343 } else {
11344 sh_type = show_all;
11345 }
11346
d62a17ae 11347 if (argv_find(argv, argc, "A.B.C.D", &idx)
11348 || argv_find(argv, argc, "X:X::X:X", &idx)
11349 || argv_find(argv, argc, "WORD", &idx)) {
11350 sh_type = show_peer;
11351 sh_arg = argv[idx]->arg;
d1927ebe
AS
11352 }
11353
11354 if (sh_type == show_peer && afi == AFI_IP) {
11355 sh_type = show_ipv4_peer;
11356 } else if (sh_type == show_peer && afi == AFI_IP6) {
11357 sh_type = show_ipv6_peer;
11358 }
856ca177 11359
d62a17ae 11360 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 11361}
11362
716b2d8a 11363/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 11364 paths' and `show ip mbgp paths'. Those functions results are the
11365 same.*/
f412b39a 11366DEFUN (show_ip_bgp_paths,
718e3744 11367 show_ip_bgp_paths_cmd,
46f296b4 11368 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 11369 SHOW_STR
11370 IP_STR
11371 BGP_STR
46f296b4 11372 BGP_SAFI_HELP_STR
718e3744 11373 "Path information\n")
11374{
d62a17ae 11375 vty_out(vty, "Address Refcnt Path\n");
11376 aspath_print_all_vty(vty);
11377 return CMD_SUCCESS;
718e3744 11378}
11379
718e3744 11380#include "hash.h"
11381
e3b78da8 11382static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11383 struct vty *vty)
718e3744 11384{
d62a17ae 11385 struct community *com;
718e3744 11386
e3b78da8 11387 com = (struct community *)bucket->data;
3f65c5b1 11388 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 11389 community_str(com, false));
718e3744 11390}
11391
11392/* Show BGP's community internal data. */
f412b39a 11393DEFUN (show_ip_bgp_community_info,
718e3744 11394 show_ip_bgp_community_info_cmd,
bec37ba5 11395 "show [ip] bgp community-info",
718e3744 11396 SHOW_STR
11397 IP_STR
11398 BGP_STR
11399 "List all bgp community information\n")
11400{
d62a17ae 11401 vty_out(vty, "Address Refcnt Community\n");
718e3744 11402
d62a17ae 11403 hash_iterate(community_hash(),
e3b78da8 11404 (void (*)(struct hash_bucket *,
d62a17ae 11405 void *))community_show_all_iterator,
11406 vty);
718e3744 11407
d62a17ae 11408 return CMD_SUCCESS;
718e3744 11409}
11410
e3b78da8 11411static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 11412 struct vty *vty)
57d187bc 11413{
d62a17ae 11414 struct lcommunity *lcom;
57d187bc 11415
e3b78da8 11416 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 11417 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 11418 lcommunity_str(lcom, false));
57d187bc
JS
11419}
11420
11421/* Show BGP's community internal data. */
11422DEFUN (show_ip_bgp_lcommunity_info,
11423 show_ip_bgp_lcommunity_info_cmd,
11424 "show ip bgp large-community-info",
11425 SHOW_STR
11426 IP_STR
11427 BGP_STR
11428 "List all bgp large-community information\n")
11429{
d62a17ae 11430 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 11431
d62a17ae 11432 hash_iterate(lcommunity_hash(),
e3b78da8 11433 (void (*)(struct hash_bucket *,
d62a17ae 11434 void *))lcommunity_show_all_iterator,
11435 vty);
57d187bc 11436
d62a17ae 11437 return CMD_SUCCESS;
57d187bc
JS
11438}
11439
11440
f412b39a 11441DEFUN (show_ip_bgp_attr_info,
718e3744 11442 show_ip_bgp_attr_info_cmd,
bec37ba5 11443 "show [ip] bgp attribute-info",
718e3744 11444 SHOW_STR
11445 IP_STR
11446 BGP_STR
11447 "List all bgp attribute information\n")
11448{
d62a17ae 11449 attr_show_all(vty);
11450 return CMD_SUCCESS;
718e3744 11451}
6b0655a2 11452
03915806
CS
11453static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11454 afi_t afi, safi_t safi,
11455 bool use_json, json_object *json)
53089bec 11456{
11457 struct bgp *bgp;
11458 struct listnode *node;
11459 char *vname;
11460 char buf1[INET6_ADDRSTRLEN];
11461 char *ecom_str;
11462 vpn_policy_direction_t dir;
11463
03915806 11464 if (json) {
b46dfd20
DS
11465 json_object *json_import_vrfs = NULL;
11466 json_object *json_export_vrfs = NULL;
11467
b46dfd20
DS
11468 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11469
53089bec 11470 if (!bgp) {
b46dfd20
DS
11471 vty_out(vty, "%s\n",
11472 json_object_to_json_string_ext(
11473 json,
11474 JSON_C_TO_STRING_PRETTY));
11475 json_object_free(json);
11476
53089bec 11477 return CMD_WARNING;
11478 }
b46dfd20 11479
94d4c685
DS
11480 /* Provide context for the block */
11481 json_object_string_add(json, "vrf", name ? name : "default");
11482 json_object_string_add(json, "afiSafi",
5cb5f4d0 11483 get_afi_safi_str(afi, safi, true));
94d4c685 11484
b46dfd20
DS
11485 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11486 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11487 json_object_string_add(json, "importFromVrfs", "none");
11488 json_object_string_add(json, "importRts", "none");
11489 } else {
6ce24e52
DS
11490 json_import_vrfs = json_object_new_array();
11491
b46dfd20
DS
11492 for (ALL_LIST_ELEMENTS_RO(
11493 bgp->vpn_policy[afi].import_vrf,
11494 node, vname))
11495 json_object_array_add(json_import_vrfs,
11496 json_object_new_string(vname));
11497
b20875ea
CS
11498 json_object_object_add(json, "importFromVrfs",
11499 json_import_vrfs);
b46dfd20 11500 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11501 if (bgp->vpn_policy[afi].rtlist[dir]) {
11502 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11503 bgp->vpn_policy[afi].rtlist[dir],
11504 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11505 json_object_string_add(json, "importRts",
11506 ecom_str);
11507 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11508 } else
11509 json_object_string_add(json, "importRts",
11510 "none");
b46dfd20
DS
11511 }
11512
11513 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11514 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11515 json_object_string_add(json, "exportToVrfs", "none");
11516 json_object_string_add(json, "routeDistinguisher",
11517 "none");
11518 json_object_string_add(json, "exportRts", "none");
11519 } else {
6ce24e52
DS
11520 json_export_vrfs = json_object_new_array();
11521
b46dfd20
DS
11522 for (ALL_LIST_ELEMENTS_RO(
11523 bgp->vpn_policy[afi].export_vrf,
11524 node, vname))
11525 json_object_array_add(json_export_vrfs,
11526 json_object_new_string(vname));
11527 json_object_object_add(json, "exportToVrfs",
11528 json_export_vrfs);
11529 json_object_string_add(json, "routeDistinguisher",
11530 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11531 buf1, RD_ADDRSTRLEN));
11532
11533 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11534 if (bgp->vpn_policy[afi].rtlist[dir]) {
11535 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11536 bgp->vpn_policy[afi].rtlist[dir],
11537 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11538 json_object_string_add(json, "exportRts",
11539 ecom_str);
11540 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11541 } else
11542 json_object_string_add(json, "exportRts",
11543 "none");
b46dfd20
DS
11544 }
11545
03915806
CS
11546 if (use_json) {
11547 vty_out(vty, "%s\n",
11548 json_object_to_json_string_ext(json,
b46dfd20 11549 JSON_C_TO_STRING_PRETTY));
03915806
CS
11550 json_object_free(json);
11551 }
53089bec 11552 } else {
b46dfd20
DS
11553 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11554
53089bec 11555 if (!bgp) {
b46dfd20 11556 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 11557 return CMD_WARNING;
11558 }
53089bec 11559
b46dfd20
DS
11560 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11561 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11562 vty_out(vty,
11563 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 11564 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11565 else {
11566 vty_out(vty,
11567 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 11568 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11569
11570 for (ALL_LIST_ELEMENTS_RO(
11571 bgp->vpn_policy[afi].import_vrf,
11572 node, vname))
11573 vty_out(vty, " %s\n", vname);
11574
11575 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
11576 ecom_str = NULL;
11577 if (bgp->vpn_policy[afi].rtlist[dir]) {
11578 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11579 bgp->vpn_policy[afi].rtlist[dir],
11580 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 11581 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 11582
b20875ea
CS
11583 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11584 } else
11585 vty_out(vty, "Import RT(s):\n");
53089bec 11586 }
53089bec 11587
b46dfd20
DS
11588 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11589 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11590 vty_out(vty,
11591 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 11592 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11593 else {
11594 vty_out(vty,
04c9077f 11595 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 11596 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
11597
11598 for (ALL_LIST_ELEMENTS_RO(
11599 bgp->vpn_policy[afi].export_vrf,
11600 node, vname))
11601 vty_out(vty, " %s\n", vname);
11602
11603 vty_out(vty, "RD: %s\n",
11604 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11605 buf1, RD_ADDRSTRLEN));
11606
11607 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
11608 if (bgp->vpn_policy[afi].rtlist[dir]) {
11609 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
11610 bgp->vpn_policy[afi].rtlist[dir],
11611 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
11612 vty_out(vty, "Export RT: %s\n", ecom_str);
11613 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11614 } else
11615 vty_out(vty, "Import RT(s):\n");
53089bec 11616 }
53089bec 11617 }
11618
11619 return CMD_SUCCESS;
11620}
11621
03915806
CS
11622static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11623 safi_t safi, bool use_json)
11624{
11625 struct listnode *node, *nnode;
11626 struct bgp *bgp;
11627 char *vrf_name = NULL;
11628 json_object *json = NULL;
11629 json_object *json_vrf = NULL;
11630 json_object *json_vrfs = NULL;
11631
11632 if (use_json) {
11633 json = json_object_new_object();
11634 json_vrfs = json_object_new_object();
11635 }
11636
11637 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11638
11639 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11640 vrf_name = bgp->name;
11641
11642 if (use_json) {
11643 json_vrf = json_object_new_object();
11644 } else {
11645 vty_out(vty, "\nInstance %s:\n",
11646 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11647 ? VRF_DEFAULT_NAME : bgp->name);
11648 }
11649 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11650 if (use_json) {
11651 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11652 json_object_object_add(json_vrfs,
11653 VRF_DEFAULT_NAME, json_vrf);
11654 else
11655 json_object_object_add(json_vrfs, vrf_name,
11656 json_vrf);
11657 }
11658 }
11659
11660 if (use_json) {
11661 json_object_object_add(json, "vrfs", json_vrfs);
11662 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11663 JSON_C_TO_STRING_PRETTY));
11664 json_object_free(json);
11665 }
11666
11667 return CMD_SUCCESS;
11668}
11669
53089bec 11670/* "show [ip] bgp route-leak" command. */
11671DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
11672 show_ip_bgp_route_leak_cmd,
11673 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
11674 SHOW_STR
11675 IP_STR
11676 BGP_STR
11677 BGP_INSTANCE_HELP_STR
11678 BGP_AFI_HELP_STR
11679 BGP_SAFI_HELP_STR
11680 "Route leaking information\n"
11681 JSON_STR)
53089bec 11682{
11683 char *vrf = NULL;
11684 afi_t afi = AFI_MAX;
11685 safi_t safi = SAFI_MAX;
11686
9f049418 11687 bool uj = use_json(argc, argv);
53089bec 11688 int idx = 0;
03915806 11689 json_object *json = NULL;
53089bec 11690
11691 /* show [ip] bgp */
11692 if (argv_find(argv, argc, "ip", &idx)) {
11693 afi = AFI_IP;
11694 safi = SAFI_UNICAST;
11695 }
11696 /* [vrf VIEWVRFNAME] */
11697 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
11698 vty_out(vty,
11699 "%% This command is not applicable to BGP views\n");
53089bec 11700 return CMD_WARNING;
11701 }
11702
9a8bdf1c
PG
11703 if (argv_find(argv, argc, "vrf", &idx)) {
11704 vrf = argv[idx + 1]->arg;
11705 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11706 vrf = NULL;
11707 }
53089bec 11708 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11709 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11710 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11711 }
11712
11713 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
11714 vty_out(vty,
11715 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 11716 return CMD_WARNING;
11717 }
11718
03915806
CS
11719 if (vrf && strmatch(vrf, "all"))
11720 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11721
11722 if (uj)
11723 json = json_object_new_object();
11724
11725 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 11726}
11727
d62a17ae 11728static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11729 safi_t safi)
f186de26 11730{
d62a17ae 11731 struct listnode *node, *nnode;
11732 struct bgp *bgp;
f186de26 11733
d62a17ae 11734 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11735 vty_out(vty, "\nInstance %s:\n",
11736 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11737 ? VRF_DEFAULT_NAME
d62a17ae 11738 : bgp->name);
11739 update_group_show(bgp, afi, safi, vty, 0);
11740 }
f186de26 11741}
11742
d62a17ae 11743static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11744 int safi, uint64_t subgrp_id)
4fb25c53 11745{
d62a17ae 11746 struct bgp *bgp;
4fb25c53 11747
d62a17ae 11748 if (name) {
11749 if (strmatch(name, "all")) {
11750 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11751 return CMD_SUCCESS;
11752 } else {
11753 bgp = bgp_lookup_by_name(name);
11754 }
11755 } else {
11756 bgp = bgp_get_default();
11757 }
4fb25c53 11758
d62a17ae 11759 if (bgp)
11760 update_group_show(bgp, afi, safi, vty, subgrp_id);
11761 return CMD_SUCCESS;
4fb25c53
DW
11762}
11763
8fe8a7f6
DS
11764DEFUN (show_ip_bgp_updgrps,
11765 show_ip_bgp_updgrps_cmd,
c1a44e43 11766 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 11767 SHOW_STR
11768 IP_STR
11769 BGP_STR
11770 BGP_INSTANCE_HELP_STR
c9e571b4 11771 BGP_AFI_HELP_STR
9bedbb1e 11772 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
11773 "Detailed info about dynamic update groups\n"
11774 "Specific subgroup to display detailed info for\n")
8386ac43 11775{
d62a17ae 11776 char *vrf = NULL;
11777 afi_t afi = AFI_IP6;
11778 safi_t safi = SAFI_UNICAST;
11779 uint64_t subgrp_id = 0;
11780
11781 int idx = 0;
11782
11783 /* show [ip] bgp */
11784 if (argv_find(argv, argc, "ip", &idx))
11785 afi = AFI_IP;
9a8bdf1c
PG
11786 /* [<vrf> VIEWVRFNAME] */
11787 if (argv_find(argv, argc, "vrf", &idx)) {
11788 vrf = argv[idx + 1]->arg;
11789 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11790 vrf = NULL;
11791 } else if (argv_find(argv, argc, "view", &idx))
11792 /* [<view> VIEWVRFNAME] */
11793 vrf = argv[idx + 1]->arg;
d62a17ae 11794 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11795 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11796 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11797 }
5bf15956 11798
d62a17ae 11799 /* get subgroup id, if provided */
11800 idx = argc - 1;
11801 if (argv[idx]->type == VARIABLE_TKN)
11802 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 11803
d62a17ae 11804 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
11805}
11806
f186de26 11807DEFUN (show_bgp_instance_all_ipv6_updgrps,
11808 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 11809 "show [ip] bgp <view|vrf> all update-groups",
f186de26 11810 SHOW_STR
716b2d8a 11811 IP_STR
f186de26 11812 BGP_STR
11813 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 11814 "Detailed info about dynamic update groups\n")
f186de26 11815{
d62a17ae 11816 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11817 return CMD_SUCCESS;
f186de26 11818}
11819
43d3f4fc
DS
11820DEFUN (show_bgp_l2vpn_evpn_updgrps,
11821 show_bgp_l2vpn_evpn_updgrps_cmd,
11822 "show [ip] bgp l2vpn evpn update-groups",
11823 SHOW_STR
11824 IP_STR
11825 BGP_STR
11826 "l2vpn address family\n"
11827 "evpn sub-address family\n"
11828 "Detailed info about dynamic update groups\n")
11829{
11830 char *vrf = NULL;
11831 uint64_t subgrp_id = 0;
11832
11833 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11834 return CMD_SUCCESS;
11835}
11836
5bf15956
DW
11837DEFUN (show_bgp_updgrps_stats,
11838 show_bgp_updgrps_stats_cmd,
716b2d8a 11839 "show [ip] bgp update-groups statistics",
3f9c7369 11840 SHOW_STR
716b2d8a 11841 IP_STR
3f9c7369 11842 BGP_STR
0c7b1b01 11843 "Detailed info about dynamic update groups\n"
3f9c7369
DS
11844 "Statistics\n")
11845{
d62a17ae 11846 struct bgp *bgp;
3f9c7369 11847
d62a17ae 11848 bgp = bgp_get_default();
11849 if (bgp)
11850 update_group_show_stats(bgp, vty);
3f9c7369 11851
d62a17ae 11852 return CMD_SUCCESS;
3f9c7369
DS
11853}
11854
8386ac43 11855DEFUN (show_bgp_instance_updgrps_stats,
11856 show_bgp_instance_updgrps_stats_cmd,
18c57037 11857 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 11858 SHOW_STR
716b2d8a 11859 IP_STR
8386ac43 11860 BGP_STR
11861 BGP_INSTANCE_HELP_STR
0c7b1b01 11862 "Detailed info about dynamic update groups\n"
8386ac43 11863 "Statistics\n")
11864{
d62a17ae 11865 int idx_word = 3;
11866 struct bgp *bgp;
8386ac43 11867
d62a17ae 11868 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11869 if (bgp)
11870 update_group_show_stats(bgp, vty);
8386ac43 11871
d62a17ae 11872 return CMD_SUCCESS;
8386ac43 11873}
11874
d62a17ae 11875static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11876 afi_t afi, safi_t safi,
11877 const char *what, uint64_t subgrp_id)
3f9c7369 11878{
d62a17ae 11879 struct bgp *bgp;
8386ac43 11880
d62a17ae 11881 if (name)
11882 bgp = bgp_lookup_by_name(name);
11883 else
11884 bgp = bgp_get_default();
8386ac43 11885
d62a17ae 11886 if (bgp) {
11887 if (!strcmp(what, "advertise-queue"))
11888 update_group_show_adj_queue(bgp, afi, safi, vty,
11889 subgrp_id);
11890 else if (!strcmp(what, "advertised-routes"))
11891 update_group_show_advertised(bgp, afi, safi, vty,
11892 subgrp_id);
11893 else if (!strcmp(what, "packet-queue"))
11894 update_group_show_packet_queue(bgp, afi, safi, vty,
11895 subgrp_id);
11896 }
3f9c7369
DS
11897}
11898
dc64bdec
QY
11899DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11900 show_ip_bgp_instance_updgrps_adj_s_cmd,
11901 "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",
11902 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11903 BGP_SAFI_HELP_STR
11904 "Detailed info about dynamic update groups\n"
11905 "Specific subgroup to display info for\n"
11906 "Advertisement queue\n"
11907 "Announced routes\n"
11908 "Packet queue\n")
3f9c7369 11909{
dc64bdec
QY
11910 uint64_t subgrp_id = 0;
11911 afi_t afiz;
11912 safi_t safiz;
11913 if (sgid)
11914 subgrp_id = strtoull(sgid, NULL, 10);
11915
11916 if (!ip && !afi)
11917 afiz = AFI_IP6;
11918 if (!ip && afi)
11919 afiz = bgp_vty_afi_from_str(afi);
11920 if (ip && !afi)
11921 afiz = AFI_IP;
11922 if (ip && afi) {
11923 afiz = bgp_vty_afi_from_str(afi);
11924 if (afiz != AFI_IP)
11925 vty_out(vty,
11926 "%% Cannot specify both 'ip' and 'ipv6'\n");
11927 return CMD_WARNING;
11928 }
d62a17ae 11929
dc64bdec 11930 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 11931
dc64bdec 11932 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 11933 return CMD_SUCCESS;
11934}
11935
d62a17ae 11936static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11937{
11938 struct listnode *node, *nnode;
11939 struct prefix *range;
11940 struct peer *conf;
11941 struct peer *peer;
11942 char buf[PREFIX2STR_BUFFER];
11943 afi_t afi;
11944 safi_t safi;
11945 const char *peer_status;
11946 const char *af_str;
11947 int lr_count;
11948 int dynamic;
11949 int af_cfgd;
11950
11951 conf = group->conf;
11952
11953 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
11954 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11955 group->name, conf->as);
d62a17ae 11956 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
11957 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11958 group->name, group->bgp->as);
d62a17ae 11959 } else {
11960 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11961 }
f14e6fdb 11962
d62a17ae 11963 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11964 vty_out(vty, " Peer-group type is internal\n");
11965 else
11966 vty_out(vty, " Peer-group type is external\n");
11967
11968 /* Display AFs configured. */
11969 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
11970 FOREACH_AFI_SAFI (afi, safi) {
11971 if (conf->afc[afi][safi]) {
11972 af_cfgd = 1;
5cb5f4d0 11973 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 11974 }
05c7a1cc 11975 }
d62a17ae 11976 if (!af_cfgd)
11977 vty_out(vty, " none\n");
11978 else
11979 vty_out(vty, "\n");
11980
11981 /* Display listen ranges (for dynamic neighbors), if any */
11982 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11983 if (afi == AFI_IP)
11984 af_str = "IPv4";
11985 else if (afi == AFI_IP6)
11986 af_str = "IPv6";
11987 else
11988 af_str = "???";
11989 lr_count = listcount(group->listen_range[afi]);
11990 if (lr_count) {
11991 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11992 af_str);
11993
11994
11995 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11996 nnode, range)) {
11997 prefix2str(range, buf, sizeof(buf));
11998 vty_out(vty, " %s\n", buf);
11999 }
12000 }
12001 }
f14e6fdb 12002
d62a17ae 12003 /* Display group members and their status */
12004 if (listcount(group->peer)) {
12005 vty_out(vty, " Peer-group members:\n");
12006 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
12007 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
12008 peer_status = "Idle (Admin)";
12009 else if (CHECK_FLAG(peer->sflags,
12010 PEER_STATUS_PREFIX_OVERFLOW))
12011 peer_status = "Idle (PfxCt)";
12012 else
12013 peer_status = lookup_msg(bgp_status_msg,
12014 peer->status, NULL);
12015
12016 dynamic = peer_dynamic_neighbor(peer);
12017 vty_out(vty, " %s %s %s \n", peer->host,
12018 dynamic ? "(dynamic)" : "", peer_status);
12019 }
12020 }
f14e6fdb 12021
d62a17ae 12022 return CMD_SUCCESS;
12023}
12024
ff9959b0
QY
12025static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
12026 const char *group_name)
d62a17ae 12027{
ff9959b0 12028 struct bgp *bgp;
d62a17ae 12029 struct listnode *node, *nnode;
12030 struct peer_group *group;
ff9959b0
QY
12031 bool found = false;
12032
12033 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12034
12035 if (!bgp) {
9f049418 12036 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
12037 return CMD_WARNING;
12038 }
d62a17ae 12039
12040 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
12041 if (group_name) {
12042 if (strmatch(group->name, group_name)) {
d62a17ae 12043 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
12044 found = true;
12045 break;
d62a17ae 12046 }
ff9959b0
QY
12047 } else {
12048 bgp_show_one_peer_group(vty, group);
d62a17ae 12049 }
f14e6fdb 12050 }
f14e6fdb 12051
ff9959b0 12052 if (group_name && !found)
d62a17ae 12053 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 12054
d62a17ae 12055 return CMD_SUCCESS;
f14e6fdb
DS
12056}
12057
f14e6fdb
DS
12058DEFUN (show_ip_bgp_peer_groups,
12059 show_ip_bgp_peer_groups_cmd,
18c57037 12060 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
12061 SHOW_STR
12062 IP_STR
12063 BGP_STR
8386ac43 12064 BGP_INSTANCE_HELP_STR
d6e3c605
QY
12065 "Detailed information on BGP peer groups\n"
12066 "Peer group name\n")
f14e6fdb 12067{
d62a17ae 12068 char *vrf, *pg;
d62a17ae 12069 int idx = 0;
f14e6fdb 12070
a4d82a8a
PZ
12071 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
12072 : NULL;
d62a17ae 12073 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 12074
ff9959b0 12075 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 12076}
3f9c7369 12077
d6e3c605 12078
718e3744 12079/* Redistribute VTY commands. */
12080
718e3744 12081DEFUN (bgp_redistribute_ipv4,
12082 bgp_redistribute_ipv4_cmd,
40d1cbfb 12083 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 12084 "Redistribute information from another routing protocol\n"
ab0181ee 12085 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 12086{
d62a17ae 12087 VTY_DECLVAR_CONTEXT(bgp, bgp);
12088 int idx_protocol = 1;
12089 int type;
718e3744 12090
d62a17ae 12091 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12092 if (type < 0) {
12093 vty_out(vty, "%% Invalid route type\n");
12094 return CMD_WARNING_CONFIG_FAILED;
12095 }
7f323236 12096
d62a17ae 12097 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12098 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 12099}
12100
d62a17ae 12101ALIAS_HIDDEN(
12102 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
12103 "redistribute " FRR_IP_REDIST_STR_BGPD,
12104 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 12105
718e3744 12106DEFUN (bgp_redistribute_ipv4_rmap,
12107 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 12108 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 12109 "Redistribute information from another routing protocol\n"
ab0181ee 12110 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12111 "Route map reference\n"
12112 "Pointer to route-map entries\n")
12113{
d62a17ae 12114 VTY_DECLVAR_CONTEXT(bgp, bgp);
12115 int idx_protocol = 1;
12116 int idx_word = 3;
12117 int type;
12118 struct bgp_redist *red;
e923dd62 12119 bool changed;
1de27621
DA
12120 struct route_map *route_map = route_map_lookup_warn_noexist(
12121 vty, argv[idx_word]->arg);
718e3744 12122
d62a17ae 12123 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12124 if (type < 0) {
12125 vty_out(vty, "%% Invalid route type\n");
12126 return CMD_WARNING_CONFIG_FAILED;
12127 }
718e3744 12128
d62a17ae 12129 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12130 changed =
12131 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12132 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 12133}
12134
d62a17ae 12135ALIAS_HIDDEN(
12136 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
12137 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
12138 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12139 "Route map reference\n"
12140 "Pointer to route-map entries\n")
596c17ba 12141
718e3744 12142DEFUN (bgp_redistribute_ipv4_metric,
12143 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 12144 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12145 "Redistribute information from another routing protocol\n"
ab0181ee 12146 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12147 "Metric for redistributed routes\n"
12148 "Default metric\n")
12149{
d62a17ae 12150 VTY_DECLVAR_CONTEXT(bgp, bgp);
12151 int idx_protocol = 1;
12152 int idx_number = 3;
12153 int type;
d7c0a89a 12154 uint32_t metric;
d62a17ae 12155 struct bgp_redist *red;
e923dd62 12156 bool changed;
d62a17ae 12157
12158 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12159 if (type < 0) {
12160 vty_out(vty, "%% Invalid route type\n");
12161 return CMD_WARNING_CONFIG_FAILED;
12162 }
12163 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12164
12165 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12166 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12167 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12168}
12169
12170ALIAS_HIDDEN(
12171 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
12172 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
12173 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12174 "Metric for redistributed routes\n"
12175 "Default metric\n")
596c17ba 12176
718e3744 12177DEFUN (bgp_redistribute_ipv4_rmap_metric,
12178 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 12179 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12180 "Redistribute information from another routing protocol\n"
ab0181ee 12181 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12182 "Route map reference\n"
12183 "Pointer to route-map entries\n"
12184 "Metric for redistributed routes\n"
12185 "Default metric\n")
12186{
d62a17ae 12187 VTY_DECLVAR_CONTEXT(bgp, bgp);
12188 int idx_protocol = 1;
12189 int idx_word = 3;
12190 int idx_number = 5;
12191 int type;
d7c0a89a 12192 uint32_t metric;
d62a17ae 12193 struct bgp_redist *red;
e923dd62 12194 bool changed;
1de27621
DA
12195 struct route_map *route_map =
12196 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12197
12198 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12199 if (type < 0) {
12200 vty_out(vty, "%% Invalid route type\n");
12201 return CMD_WARNING_CONFIG_FAILED;
12202 }
12203 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12204
12205 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
12206 changed =
12207 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12208 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12209 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12210}
12211
12212ALIAS_HIDDEN(
12213 bgp_redistribute_ipv4_rmap_metric,
12214 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12215 "redistribute " FRR_IP_REDIST_STR_BGPD
12216 " route-map WORD metric (0-4294967295)",
12217 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12218 "Route map reference\n"
12219 "Pointer to route-map entries\n"
12220 "Metric for redistributed routes\n"
12221 "Default metric\n")
596c17ba 12222
718e3744 12223DEFUN (bgp_redistribute_ipv4_metric_rmap,
12224 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 12225 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12226 "Redistribute information from another routing protocol\n"
ab0181ee 12227 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 12228 "Metric for redistributed routes\n"
12229 "Default metric\n"
12230 "Route map reference\n"
12231 "Pointer to route-map entries\n")
12232{
d62a17ae 12233 VTY_DECLVAR_CONTEXT(bgp, bgp);
12234 int idx_protocol = 1;
12235 int idx_number = 3;
12236 int idx_word = 5;
12237 int type;
d7c0a89a 12238 uint32_t metric;
d62a17ae 12239 struct bgp_redist *red;
e923dd62 12240 bool changed;
1de27621
DA
12241 struct route_map *route_map =
12242 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12243
12244 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12245 if (type < 0) {
12246 vty_out(vty, "%% Invalid route type\n");
12247 return CMD_WARNING_CONFIG_FAILED;
12248 }
12249 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12250
12251 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 12252 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
12253 changed |=
12254 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12255 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 12256}
12257
12258ALIAS_HIDDEN(
12259 bgp_redistribute_ipv4_metric_rmap,
12260 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12261 "redistribute " FRR_IP_REDIST_STR_BGPD
12262 " metric (0-4294967295) route-map WORD",
12263 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12264 "Metric for redistributed routes\n"
12265 "Default metric\n"
12266 "Route map reference\n"
12267 "Pointer to route-map entries\n")
596c17ba 12268
7c8ff89e
DS
12269DEFUN (bgp_redistribute_ipv4_ospf,
12270 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 12271 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
12272 "Redistribute information from another routing protocol\n"
12273 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12274 "Non-main Kernel Routing Table\n"
12275 "Instance ID/Table ID\n")
7c8ff89e 12276{
d62a17ae 12277 VTY_DECLVAR_CONTEXT(bgp, bgp);
12278 int idx_ospf_table = 1;
12279 int idx_number = 2;
d7c0a89a
QY
12280 unsigned short instance;
12281 unsigned short protocol;
7c8ff89e 12282
d62a17ae 12283 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 12284
d62a17ae 12285 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12286 protocol = ZEBRA_ROUTE_OSPF;
12287 else
12288 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 12289
d62a17ae 12290 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12291 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
12292}
12293
d62a17ae 12294ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12295 "redistribute <ospf|table> (1-65535)",
12296 "Redistribute information from another routing protocol\n"
12297 "Open Shortest Path First (OSPFv2)\n"
12298 "Non-main Kernel Routing Table\n"
12299 "Instance ID/Table ID\n")
596c17ba 12300
7c8ff89e
DS
12301DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12302 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 12303 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
12304 "Redistribute information from another routing protocol\n"
12305 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12306 "Non-main Kernel Routing Table\n"
12307 "Instance ID/Table ID\n"
7c8ff89e
DS
12308 "Route map reference\n"
12309 "Pointer to route-map entries\n")
12310{
d62a17ae 12311 VTY_DECLVAR_CONTEXT(bgp, bgp);
12312 int idx_ospf_table = 1;
12313 int idx_number = 2;
12314 int idx_word = 4;
12315 struct bgp_redist *red;
d7c0a89a 12316 unsigned short instance;
d62a17ae 12317 int protocol;
e923dd62 12318 bool changed;
1de27621
DA
12319 struct route_map *route_map =
12320 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12321
12322 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12323 protocol = ZEBRA_ROUTE_OSPF;
12324 else
12325 protocol = ZEBRA_ROUTE_TABLE;
12326
12327 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12328 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12329 changed =
12330 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12331 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12332}
12333
12334ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12335 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12336 "redistribute <ospf|table> (1-65535) route-map WORD",
12337 "Redistribute information from another routing protocol\n"
12338 "Open Shortest Path First (OSPFv2)\n"
12339 "Non-main Kernel Routing Table\n"
12340 "Instance ID/Table ID\n"
12341 "Route map reference\n"
12342 "Pointer to route-map entries\n")
596c17ba 12343
7c8ff89e
DS
12344DEFUN (bgp_redistribute_ipv4_ospf_metric,
12345 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 12346 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
12347 "Redistribute information from another routing protocol\n"
12348 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12349 "Non-main Kernel Routing Table\n"
12350 "Instance ID/Table ID\n"
7c8ff89e
DS
12351 "Metric for redistributed routes\n"
12352 "Default metric\n")
12353{
d62a17ae 12354 VTY_DECLVAR_CONTEXT(bgp, bgp);
12355 int idx_ospf_table = 1;
12356 int idx_number = 2;
12357 int idx_number_2 = 4;
d7c0a89a 12358 uint32_t metric;
d62a17ae 12359 struct bgp_redist *red;
d7c0a89a 12360 unsigned short instance;
d62a17ae 12361 int protocol;
e923dd62 12362 bool changed;
d62a17ae 12363
12364 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12365 protocol = ZEBRA_ROUTE_OSPF;
12366 else
12367 protocol = ZEBRA_ROUTE_TABLE;
12368
12369 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12370 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12371
12372 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12373 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12374 metric);
12375 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12376}
12377
12378ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12379 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12380 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12381 "Redistribute information from another routing protocol\n"
12382 "Open Shortest Path First (OSPFv2)\n"
12383 "Non-main Kernel Routing Table\n"
12384 "Instance ID/Table ID\n"
12385 "Metric for redistributed routes\n"
12386 "Default metric\n")
596c17ba 12387
7c8ff89e
DS
12388DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12389 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 12390 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
12391 "Redistribute information from another routing protocol\n"
12392 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12393 "Non-main Kernel Routing Table\n"
12394 "Instance ID/Table ID\n"
7c8ff89e
DS
12395 "Route map reference\n"
12396 "Pointer to route-map entries\n"
12397 "Metric for redistributed routes\n"
12398 "Default metric\n")
12399{
d62a17ae 12400 VTY_DECLVAR_CONTEXT(bgp, bgp);
12401 int idx_ospf_table = 1;
12402 int idx_number = 2;
12403 int idx_word = 4;
12404 int idx_number_2 = 6;
d7c0a89a 12405 uint32_t metric;
d62a17ae 12406 struct bgp_redist *red;
d7c0a89a 12407 unsigned short instance;
d62a17ae 12408 int protocol;
e923dd62 12409 bool changed;
1de27621
DA
12410 struct route_map *route_map =
12411 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12412
12413 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12414 protocol = ZEBRA_ROUTE_OSPF;
12415 else
12416 protocol = ZEBRA_ROUTE_TABLE;
12417
12418 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12419 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12420
12421 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
12422 changed =
12423 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12424 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12425 metric);
12426 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12427}
12428
12429ALIAS_HIDDEN(
12430 bgp_redistribute_ipv4_ospf_rmap_metric,
12431 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12432 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12433 "Redistribute information from another routing protocol\n"
12434 "Open Shortest Path First (OSPFv2)\n"
12435 "Non-main Kernel Routing Table\n"
12436 "Instance ID/Table ID\n"
12437 "Route map reference\n"
12438 "Pointer to route-map entries\n"
12439 "Metric for redistributed routes\n"
12440 "Default metric\n")
596c17ba 12441
7c8ff89e
DS
12442DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12443 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 12444 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
12445 "Redistribute information from another routing protocol\n"
12446 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
12447 "Non-main Kernel Routing Table\n"
12448 "Instance ID/Table ID\n"
7c8ff89e
DS
12449 "Metric for redistributed routes\n"
12450 "Default metric\n"
12451 "Route map reference\n"
12452 "Pointer to route-map entries\n")
12453{
d62a17ae 12454 VTY_DECLVAR_CONTEXT(bgp, bgp);
12455 int idx_ospf_table = 1;
12456 int idx_number = 2;
12457 int idx_number_2 = 4;
12458 int idx_word = 6;
d7c0a89a 12459 uint32_t metric;
d62a17ae 12460 struct bgp_redist *red;
d7c0a89a 12461 unsigned short instance;
d62a17ae 12462 int protocol;
e923dd62 12463 bool changed;
1de27621
DA
12464 struct route_map *route_map =
12465 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12466
12467 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12468 protocol = ZEBRA_ROUTE_OSPF;
12469 else
12470 protocol = ZEBRA_ROUTE_TABLE;
12471
12472 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12473 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12474
12475 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 12476 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12477 metric);
1de27621
DA
12478 changed |=
12479 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12480 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 12481}
12482
12483ALIAS_HIDDEN(
12484 bgp_redistribute_ipv4_ospf_metric_rmap,
12485 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12486 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12487 "Redistribute information from another routing protocol\n"
12488 "Open Shortest Path First (OSPFv2)\n"
12489 "Non-main Kernel Routing Table\n"
12490 "Instance ID/Table ID\n"
12491 "Metric for redistributed routes\n"
12492 "Default metric\n"
12493 "Route map reference\n"
12494 "Pointer to route-map entries\n")
596c17ba 12495
7c8ff89e
DS
12496DEFUN (no_bgp_redistribute_ipv4_ospf,
12497 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 12498 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
12499 NO_STR
12500 "Redistribute information from another routing protocol\n"
12501 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 12502 "Non-main Kernel Routing Table\n"
31500417
DW
12503 "Instance ID/Table ID\n"
12504 "Metric for redistributed routes\n"
12505 "Default metric\n"
12506 "Route map reference\n"
12507 "Pointer to route-map entries\n")
7c8ff89e 12508{
d62a17ae 12509 VTY_DECLVAR_CONTEXT(bgp, bgp);
12510 int idx_ospf_table = 2;
12511 int idx_number = 3;
d7c0a89a 12512 unsigned short instance;
d62a17ae 12513 int protocol;
12514
12515 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12516 protocol = ZEBRA_ROUTE_OSPF;
12517 else
12518 protocol = ZEBRA_ROUTE_TABLE;
12519
12520 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12521 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12522}
12523
12524ALIAS_HIDDEN(
12525 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 12526 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12527 NO_STR
12528 "Redistribute information from another routing protocol\n"
12529 "Open Shortest Path First (OSPFv2)\n"
12530 "Non-main Kernel Routing Table\n"
12531 "Instance ID/Table ID\n"
12532 "Metric for redistributed routes\n"
12533 "Default metric\n"
12534 "Route map reference\n"
12535 "Pointer to route-map entries\n")
596c17ba 12536
718e3744 12537DEFUN (no_bgp_redistribute_ipv4,
12538 no_bgp_redistribute_ipv4_cmd,
e27957c0 12539 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12540 NO_STR
12541 "Redistribute information from another routing protocol\n"
3b14d86e 12542 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
12543 "Metric for redistributed routes\n"
12544 "Default metric\n"
12545 "Route map reference\n"
12546 "Pointer to route-map entries\n")
718e3744 12547{
d62a17ae 12548 VTY_DECLVAR_CONTEXT(bgp, bgp);
12549 int idx_protocol = 2;
12550 int type;
12551
12552 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12553 if (type < 0) {
12554 vty_out(vty, "%% Invalid route type\n");
12555 return CMD_WARNING_CONFIG_FAILED;
12556 }
12557 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12558}
12559
12560ALIAS_HIDDEN(
12561 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12562 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 12563 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 12564 NO_STR
12565 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12566 "Metric for redistributed routes\n"
12567 "Default metric\n"
12568 "Route map reference\n"
12569 "Pointer to route-map entries\n")
596c17ba 12570
718e3744 12571DEFUN (bgp_redistribute_ipv6,
12572 bgp_redistribute_ipv6_cmd,
40d1cbfb 12573 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 12574 "Redistribute information from another routing protocol\n"
ab0181ee 12575 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 12576{
d62a17ae 12577 VTY_DECLVAR_CONTEXT(bgp, bgp);
12578 int idx_protocol = 1;
12579 int type;
718e3744 12580
d62a17ae 12581 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12582 if (type < 0) {
12583 vty_out(vty, "%% Invalid route type\n");
12584 return CMD_WARNING_CONFIG_FAILED;
12585 }
718e3744 12586
d62a17ae 12587 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12588 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 12589}
12590
12591DEFUN (bgp_redistribute_ipv6_rmap,
12592 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 12593 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 12594 "Redistribute information from another routing protocol\n"
ab0181ee 12595 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12596 "Route map reference\n"
12597 "Pointer to route-map entries\n")
12598{
d62a17ae 12599 VTY_DECLVAR_CONTEXT(bgp, bgp);
12600 int idx_protocol = 1;
12601 int idx_word = 3;
12602 int type;
12603 struct bgp_redist *red;
e923dd62 12604 bool changed;
1de27621
DA
12605 struct route_map *route_map =
12606 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 12607
d62a17ae 12608 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12609 if (type < 0) {
12610 vty_out(vty, "%% Invalid route type\n");
12611 return CMD_WARNING_CONFIG_FAILED;
12612 }
718e3744 12613
d62a17ae 12614 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12615 changed =
12616 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12617 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12618}
12619
12620DEFUN (bgp_redistribute_ipv6_metric,
12621 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 12622 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 12623 "Redistribute information from another routing protocol\n"
ab0181ee 12624 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12625 "Metric for redistributed routes\n"
12626 "Default metric\n")
12627{
d62a17ae 12628 VTY_DECLVAR_CONTEXT(bgp, bgp);
12629 int idx_protocol = 1;
12630 int idx_number = 3;
12631 int type;
d7c0a89a 12632 uint32_t metric;
d62a17ae 12633 struct bgp_redist *red;
e923dd62 12634 bool changed;
d62a17ae 12635
12636 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12637 if (type < 0) {
12638 vty_out(vty, "%% Invalid route type\n");
12639 return CMD_WARNING_CONFIG_FAILED;
12640 }
12641 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12642
d62a17ae 12643 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12644 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12645 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12646}
12647
12648DEFUN (bgp_redistribute_ipv6_rmap_metric,
12649 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 12650 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 12651 "Redistribute information from another routing protocol\n"
ab0181ee 12652 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12653 "Route map reference\n"
12654 "Pointer to route-map entries\n"
12655 "Metric for redistributed routes\n"
12656 "Default metric\n")
12657{
d62a17ae 12658 VTY_DECLVAR_CONTEXT(bgp, bgp);
12659 int idx_protocol = 1;
12660 int idx_word = 3;
12661 int idx_number = 5;
12662 int type;
d7c0a89a 12663 uint32_t metric;
d62a17ae 12664 struct bgp_redist *red;
e923dd62 12665 bool changed;
1de27621
DA
12666 struct route_map *route_map =
12667 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12668
12669 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12670 if (type < 0) {
12671 vty_out(vty, "%% Invalid route type\n");
12672 return CMD_WARNING_CONFIG_FAILED;
12673 }
12674 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12675
d62a17ae 12676 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
12677 changed =
12678 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12679 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12680 metric);
12681 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12682}
12683
12684DEFUN (bgp_redistribute_ipv6_metric_rmap,
12685 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 12686 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 12687 "Redistribute information from another routing protocol\n"
ab0181ee 12688 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 12689 "Metric for redistributed routes\n"
12690 "Default metric\n"
12691 "Route map reference\n"
12692 "Pointer to route-map entries\n")
12693{
d62a17ae 12694 VTY_DECLVAR_CONTEXT(bgp, bgp);
12695 int idx_protocol = 1;
12696 int idx_number = 3;
12697 int idx_word = 5;
12698 int type;
d7c0a89a 12699 uint32_t metric;
d62a17ae 12700 struct bgp_redist *red;
e923dd62 12701 bool changed;
1de27621
DA
12702 struct route_map *route_map =
12703 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 12704
12705 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12706 if (type < 0) {
12707 vty_out(vty, "%% Invalid route type\n");
12708 return CMD_WARNING_CONFIG_FAILED;
12709 }
12710 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 12711
d62a17ae 12712 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 12713 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12714 metric);
1de27621
DA
12715 changed |=
12716 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 12717 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 12718}
12719
12720DEFUN (no_bgp_redistribute_ipv6,
12721 no_bgp_redistribute_ipv6_cmd,
e27957c0 12722 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 12723 NO_STR
12724 "Redistribute information from another routing protocol\n"
3b14d86e 12725 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
12726 "Metric for redistributed routes\n"
12727 "Default metric\n"
12728 "Route map reference\n"
12729 "Pointer to route-map entries\n")
718e3744 12730{
d62a17ae 12731 VTY_DECLVAR_CONTEXT(bgp, bgp);
12732 int idx_protocol = 2;
12733 int type;
718e3744 12734
d62a17ae 12735 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12736 if (type < 0) {
12737 vty_out(vty, "%% Invalid route type\n");
12738 return CMD_WARNING_CONFIG_FAILED;
12739 }
718e3744 12740
d62a17ae 12741 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12742}
12743
2b791107 12744void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 12745 safi_t safi)
d62a17ae 12746{
12747 int i;
12748
12749 /* Unicast redistribution only. */
12750 if (safi != SAFI_UNICAST)
2b791107 12751 return;
d62a17ae 12752
12753 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12754 /* Redistribute BGP does not make sense. */
12755 if (i != ZEBRA_ROUTE_BGP) {
12756 struct list *red_list;
12757 struct listnode *node;
12758 struct bgp_redist *red;
12759
12760 red_list = bgp->redist[afi][i];
12761 if (!red_list)
12762 continue;
12763
12764 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 12765 /* "redistribute" configuration. */
12766 vty_out(vty, " redistribute %s",
12767 zebra_route_string(i));
12768 if (red->instance)
12769 vty_out(vty, " %d", red->instance);
12770 if (red->redist_metric_flag)
12771 vty_out(vty, " metric %u",
12772 red->redist_metric);
12773 if (red->rmap.name)
12774 vty_out(vty, " route-map %s",
12775 red->rmap.name);
12776 vty_out(vty, "\n");
12777 }
12778 }
12779 }
718e3744 12780}
6b0655a2 12781
b9c7bc5a
PZ
12782/* This is part of the address-family block (unicast only) */
12783void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
12784 afi_t afi)
12785{
b9c7bc5a 12786 int indent = 2;
ddb5b488 12787
8a066a70
PG
12788 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12789 if (listcount(bgp->vpn_policy[afi].import_vrf))
12790 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12791 bgp->vpn_policy[afi]
bb4f6190 12792 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
12793 else
12794 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12795 bgp->vpn_policy[afi]
12796 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12797 }
12a844a5
DS
12798 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12799 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12800 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12801 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12802 return;
12803
e70e9f8e
PZ
12804 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12805 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12806
12807 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12808
12809 } else {
12810 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12811 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12812 bgp->vpn_policy[afi].tovpn_label);
12813 }
ddb5b488
PZ
12814 }
12815 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12816 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12817 char buf[RD_ADDRSTRLEN];
b9c7bc5a 12818 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
12819 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12820 sizeof(buf)));
12821 }
12822 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12823 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12824
12825 char buf[PREFIX_STRLEN];
12826 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12827 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12828 sizeof(buf))) {
12829
b9c7bc5a
PZ
12830 vty_out(vty, "%*snexthop vpn export %s\n",
12831 indent, "", buf);
ddb5b488
PZ
12832 }
12833 }
12834 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12835 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12836 && ecommunity_cmp(
12837 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12838 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12839
12840 char *b = ecommunity_ecom2str(
12841 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12842 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12843 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
12844 XFREE(MTYPE_ECOMMUNITY_STR, b);
12845 } else {
12846 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12847 char *b = ecommunity_ecom2str(
12848 bgp->vpn_policy[afi]
12849 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12850 ECOMMUNITY_FORMAT_ROUTE_MAP,
12851 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12852 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
12853 XFREE(MTYPE_ECOMMUNITY_STR, b);
12854 }
12855 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12856 char *b = ecommunity_ecom2str(
12857 bgp->vpn_policy[afi]
12858 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12859 ECOMMUNITY_FORMAT_ROUTE_MAP,
12860 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 12861 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
12862 XFREE(MTYPE_ECOMMUNITY_STR, b);
12863 }
12864 }
bb4f6190
DS
12865
12866 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 12867 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
12868 bgp->vpn_policy[afi]
12869 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 12870
301ad80a
PG
12871 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12872 char *b = ecommunity_ecom2str(
12873 bgp->vpn_policy[afi]
12874 .import_redirect_rtlist,
12875 ECOMMUNITY_FORMAT_ROUTE_MAP,
12876 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 12877
301ad80a
PG
12878 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12879 XFREE(MTYPE_ECOMMUNITY_STR, b);
12880 }
ddb5b488
PZ
12881}
12882
12883
718e3744 12884/* BGP node structure. */
d62a17ae 12885static struct cmd_node bgp_node = {
9d303b37 12886 BGP_NODE, "%s(config-router)# ", 1,
718e3744 12887};
12888
d62a17ae 12889static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 12890 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 12891};
12892
d62a17ae 12893static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 12894 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 12895};
12896
d62a17ae 12897static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 12898 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12899};
12900
d62a17ae 12901static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 12902 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 12903};
12904
d62a17ae 12905static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 12906 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 12907};
12908
d62a17ae 12909static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 12910 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
12911};
12912
d62a17ae 12913static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12914 "%s(config-router-af)# ", 1};
6b0655a2 12915
d62a17ae 12916static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12917 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 12918
d62a17ae 12919static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12920 "%s(config-router-evpn)# ", 1};
4e0b7b6d 12921
d62a17ae 12922static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12923 "%s(config-router-af-vni)# ", 1};
90e60aa7 12924
7c40bf39 12925static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12926 "%s(config-router-af)# ", 1};
12927
12928static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12929 "%s(config-router-af-vpnv6)# ", 1};
12930
d62a17ae 12931static void community_list_vty(void);
1f8ae70b 12932
d62a17ae 12933static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 12934{
d62a17ae 12935 struct bgp *bgp;
12936 struct peer *peer;
d62a17ae 12937 struct listnode *lnbgp, *lnpeer;
b8a815e5 12938
d62a17ae 12939 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12940 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12941 /* only provide suggestions on the appropriate input
12942 * token type,
12943 * they'll otherwise show up multiple times */
12944 enum cmd_token_type match_type;
12945 char *name = peer->host;
d48ed3e0 12946
d62a17ae 12947 if (peer->conf_if) {
12948 match_type = VARIABLE_TKN;
12949 name = peer->conf_if;
12950 } else if (strchr(peer->host, ':'))
12951 match_type = IPV6_TKN;
12952 else
12953 match_type = IPV4_TKN;
d48ed3e0 12954
d62a17ae 12955 if (token->type != match_type)
12956 continue;
d48ed3e0 12957
d62a17ae 12958 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12959 }
d62a17ae 12960 }
b8a815e5
DL
12961}
12962
12963static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 12964 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12965 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 12966 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 12967 {.completions = NULL}};
12968
47a306a0
DS
12969static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12970{
12971 struct bgp *bgp;
12972 struct peer_group *group;
12973 struct listnode *lnbgp, *lnpeer;
12974
12975 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12976 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12977 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12978 group->name));
12979 }
12980}
12981
12982static const struct cmd_variable_handler bgp_var_peergroup[] = {
12983 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12984 {.completions = NULL} };
12985
d62a17ae 12986void bgp_vty_init(void)
12987{
12988 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 12989 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 12990
12991 /* Install bgp top node. */
12992 install_node(&bgp_node, bgp_config_write);
12993 install_node(&bgp_ipv4_unicast_node, NULL);
12994 install_node(&bgp_ipv4_multicast_node, NULL);
12995 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12996 install_node(&bgp_ipv6_unicast_node, NULL);
12997 install_node(&bgp_ipv6_multicast_node, NULL);
12998 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12999 install_node(&bgp_vpnv4_node, NULL);
13000 install_node(&bgp_vpnv6_node, NULL);
13001 install_node(&bgp_evpn_node, NULL);
13002 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 13003 install_node(&bgp_flowspecv4_node, NULL);
13004 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 13005
13006 /* Install default VTY commands to new nodes. */
13007 install_default(BGP_NODE);
13008 install_default(BGP_IPV4_NODE);
13009 install_default(BGP_IPV4M_NODE);
13010 install_default(BGP_IPV4L_NODE);
13011 install_default(BGP_IPV6_NODE);
13012 install_default(BGP_IPV6M_NODE);
13013 install_default(BGP_IPV6L_NODE);
13014 install_default(BGP_VPNV4_NODE);
13015 install_default(BGP_VPNV6_NODE);
7c40bf39 13016 install_default(BGP_FLOWSPECV4_NODE);
13017 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 13018 install_default(BGP_EVPN_NODE);
13019 install_default(BGP_EVPN_VNI_NODE);
13020
8029b216
AK
13021 /* "bgp local-mac" hidden commands. */
13022 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
13023 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
13024
d62a17ae 13025 /* bgp route-map delay-timer commands. */
13026 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
13027 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13028
13029 /* Dummy commands (Currently not supported) */
13030 install_element(BGP_NODE, &no_synchronization_cmd);
13031 install_element(BGP_NODE, &no_auto_summary_cmd);
13032
13033 /* "router bgp" commands. */
13034 install_element(CONFIG_NODE, &router_bgp_cmd);
13035
13036 /* "no router bgp" commands. */
13037 install_element(CONFIG_NODE, &no_router_bgp_cmd);
13038
13039 /* "bgp router-id" commands. */
13040 install_element(BGP_NODE, &bgp_router_id_cmd);
13041 install_element(BGP_NODE, &no_bgp_router_id_cmd);
13042
13043 /* "bgp cluster-id" commands. */
13044 install_element(BGP_NODE, &bgp_cluster_id_cmd);
13045 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
13046
13047 /* "bgp confederation" commands. */
13048 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
13049 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
13050
13051 /* "bgp confederation peers" commands. */
13052 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
13053 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
13054
13055 /* bgp max-med command */
13056 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
13057 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
13058 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
13059 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
13060 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
13061
13062 /* bgp disable-ebgp-connected-nh-check */
13063 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
13064 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
13065
13066 /* bgp update-delay command */
13067 install_element(BGP_NODE, &bgp_update_delay_cmd);
13068 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
13069 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
13070
13071 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
13072 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
13073 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
13074 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 13075
13076 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
13077 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
13078
13079 /* "maximum-paths" commands. */
13080 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
13081 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
13082 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
13083 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
13084 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
13085 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
13086 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
13087 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
13088 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
13089 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
13090 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13091 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
13092 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
13093 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13094 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
13095
13096 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
13097 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
13098 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
13099 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
13100 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
13101
13102 /* "timers bgp" commands. */
13103 install_element(BGP_NODE, &bgp_timers_cmd);
13104 install_element(BGP_NODE, &no_bgp_timers_cmd);
13105
13106 /* route-map delay-timer commands - per instance for backwards compat.
13107 */
13108 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
13109 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
13110
13111 /* "bgp client-to-client reflection" commands */
13112 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
13113 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
13114
13115 /* "bgp always-compare-med" commands */
13116 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
13117 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
13118
9dac9fc8
DA
13119 /* bgp ebgp-requires-policy */
13120 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
13121 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
13122
d62a17ae 13123 /* "bgp deterministic-med" commands */
13124 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
13125 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
13126
13127 /* "bgp graceful-restart" commands */
13128 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
13129 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
13130 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
13131 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
13132 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
13133 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
13134
13135 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
13136 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
13137
7f323236
DW
13138 /* "bgp graceful-shutdown" commands */
13139 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
13140 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
13141
d62a17ae 13142 /* "bgp fast-external-failover" commands */
13143 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
13144 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
13145
d62a17ae 13146 /* "bgp bestpath compare-routerid" commands */
13147 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
13148 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
13149
13150 /* "bgp bestpath as-path ignore" commands */
13151 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
13152 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
13153
13154 /* "bgp bestpath as-path confed" commands */
13155 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
13156 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
13157
13158 /* "bgp bestpath as-path multipath-relax" commands */
13159 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
13160 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
13161
13162 /* "bgp log-neighbor-changes" commands */
13163 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
13164 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
13165
13166 /* "bgp bestpath med" commands */
13167 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
13168 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
13169
13170 /* "no bgp default ipv4-unicast" commands. */
13171 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
13172 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
13173
13174 /* "bgp network import-check" commands. */
13175 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13176 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13177 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13178
13179 /* "bgp default local-preference" commands. */
13180 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13181 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13182
13183 /* bgp default show-hostname */
13184 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13185 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13186
13187 /* "bgp default subgroup-pkt-queue-max" commands. */
13188 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13189 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13190
13191 /* bgp ibgp-allow-policy-mods command */
13192 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13193 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13194
13195 /* "bgp listen limit" commands. */
13196 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13197 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13198
13199 /* "bgp listen range" commands. */
13200 install_element(BGP_NODE, &bgp_listen_range_cmd);
13201 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13202
8175f54a 13203 /* "bgp default shutdown" command */
f26845f9
QY
13204 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13205
d62a17ae 13206 /* "neighbor remote-as" commands. */
13207 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13208 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13209 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13210 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13211 install_element(BGP_NODE,
13212 &neighbor_interface_v6only_config_remote_as_cmd);
13213 install_element(BGP_NODE, &no_neighbor_cmd);
13214 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13215
13216 /* "neighbor peer-group" commands. */
13217 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13218 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13219 install_element(BGP_NODE,
13220 &no_neighbor_interface_peer_group_remote_as_cmd);
13221
13222 /* "neighbor local-as" commands. */
13223 install_element(BGP_NODE, &neighbor_local_as_cmd);
13224 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13225 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13226 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13227
13228 /* "neighbor solo" commands. */
13229 install_element(BGP_NODE, &neighbor_solo_cmd);
13230 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13231
13232 /* "neighbor password" commands. */
13233 install_element(BGP_NODE, &neighbor_password_cmd);
13234 install_element(BGP_NODE, &no_neighbor_password_cmd);
13235
13236 /* "neighbor activate" commands. */
13237 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13238 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13239 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13240 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13241 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13242 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13243 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13244 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13245 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 13246 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13247 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 13248 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13249
13250 /* "no neighbor activate" commands. */
13251 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13252 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13253 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13254 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13255 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13256 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13257 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13258 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13259 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 13260 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13261 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 13262 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13263
13264 /* "neighbor peer-group" set commands. */
13265 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13266 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13267 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13269 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13270 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13271 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13272 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 13273 install_element(BGP_FLOWSPECV4_NODE,
13274 &neighbor_set_peer_group_hidden_cmd);
13275 install_element(BGP_FLOWSPECV6_NODE,
13276 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 13277
13278 /* "no neighbor peer-group unset" commands. */
13279 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13280 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13281 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13282 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13283 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13284 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13285 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13286 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 13287 install_element(BGP_FLOWSPECV4_NODE,
13288 &no_neighbor_set_peer_group_hidden_cmd);
13289 install_element(BGP_FLOWSPECV6_NODE,
13290 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 13291
13292 /* "neighbor softreconfiguration inbound" commands.*/
13293 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13294 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13295 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13296 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13297 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13298 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13299 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13300 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13301 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13302 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13303 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13304 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13305 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13306 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13307 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13308 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13309 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13310 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 13311 install_element(BGP_FLOWSPECV4_NODE,
13312 &neighbor_soft_reconfiguration_cmd);
13313 install_element(BGP_FLOWSPECV4_NODE,
13314 &no_neighbor_soft_reconfiguration_cmd);
13315 install_element(BGP_FLOWSPECV6_NODE,
13316 &neighbor_soft_reconfiguration_cmd);
13317 install_element(BGP_FLOWSPECV6_NODE,
13318 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
13319 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13320 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 13321
13322 /* "neighbor attribute-unchanged" commands. */
13323 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13324 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13325 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13326 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13327 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13328 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13329 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13330 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13331 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13332 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13333 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13334 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13335 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13336 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13337 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13338 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13339 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13340 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13341
13342 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13343 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13344
13345 /* "nexthop-local unchanged" commands */
13346 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13347 install_element(BGP_IPV6_NODE,
13348 &no_neighbor_nexthop_local_unchanged_cmd);
13349
13350 /* "neighbor next-hop-self" commands. */
13351 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13352 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13353 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13354 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13355 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13356 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13357 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13358 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13359 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13360 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13361 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13362 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13363 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13364 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13365 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13366 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13367 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13368 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
13369 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13370 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 13371
13372 /* "neighbor next-hop-self force" commands. */
13373 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13374 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
13375 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13376 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13377 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13378 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13379 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13380 install_element(BGP_IPV4_NODE,
13381 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13382 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13383 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13384 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13385 install_element(BGP_IPV4M_NODE,
13386 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13387 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13388 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13389 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13390 install_element(BGP_IPV4L_NODE,
13391 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13392 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13393 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13394 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13395 install_element(BGP_IPV6_NODE,
13396 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13397 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13398 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13399 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13400 install_element(BGP_IPV6M_NODE,
13401 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13402 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13403 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13404 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13405 install_element(BGP_IPV6L_NODE,
13406 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13407 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13408 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13409 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13410 install_element(BGP_VPNV4_NODE,
13411 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13412 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13413 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
13414 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13415 install_element(BGP_VPNV6_NODE,
13416 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 13417
13418 /* "neighbor as-override" commands. */
13419 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13420 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13421 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13422 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13423 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13424 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13425 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13426 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13427 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13428 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13429 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13430 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13431 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13432 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13433 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13434 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13435 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13436 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13437
13438 /* "neighbor remove-private-AS" commands. */
13439 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13440 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13441 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13442 install_element(BGP_NODE,
13443 &no_neighbor_remove_private_as_all_hidden_cmd);
13444 install_element(BGP_NODE,
13445 &neighbor_remove_private_as_replace_as_hidden_cmd);
13446 install_element(BGP_NODE,
13447 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13448 install_element(BGP_NODE,
13449 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13450 install_element(
13451 BGP_NODE,
13452 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13453 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13454 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13455 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13456 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13457 install_element(BGP_IPV4_NODE,
13458 &neighbor_remove_private_as_replace_as_cmd);
13459 install_element(BGP_IPV4_NODE,
13460 &no_neighbor_remove_private_as_replace_as_cmd);
13461 install_element(BGP_IPV4_NODE,
13462 &neighbor_remove_private_as_all_replace_as_cmd);
13463 install_element(BGP_IPV4_NODE,
13464 &no_neighbor_remove_private_as_all_replace_as_cmd);
13465 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13466 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13467 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13468 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13469 install_element(BGP_IPV4M_NODE,
13470 &neighbor_remove_private_as_replace_as_cmd);
13471 install_element(BGP_IPV4M_NODE,
13472 &no_neighbor_remove_private_as_replace_as_cmd);
13473 install_element(BGP_IPV4M_NODE,
13474 &neighbor_remove_private_as_all_replace_as_cmd);
13475 install_element(BGP_IPV4M_NODE,
13476 &no_neighbor_remove_private_as_all_replace_as_cmd);
13477 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13478 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13479 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13480 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13481 install_element(BGP_IPV4L_NODE,
13482 &neighbor_remove_private_as_replace_as_cmd);
13483 install_element(BGP_IPV4L_NODE,
13484 &no_neighbor_remove_private_as_replace_as_cmd);
13485 install_element(BGP_IPV4L_NODE,
13486 &neighbor_remove_private_as_all_replace_as_cmd);
13487 install_element(BGP_IPV4L_NODE,
13488 &no_neighbor_remove_private_as_all_replace_as_cmd);
13489 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13490 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13491 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13492 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13493 install_element(BGP_IPV6_NODE,
13494 &neighbor_remove_private_as_replace_as_cmd);
13495 install_element(BGP_IPV6_NODE,
13496 &no_neighbor_remove_private_as_replace_as_cmd);
13497 install_element(BGP_IPV6_NODE,
13498 &neighbor_remove_private_as_all_replace_as_cmd);
13499 install_element(BGP_IPV6_NODE,
13500 &no_neighbor_remove_private_as_all_replace_as_cmd);
13501 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13502 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13503 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13504 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13505 install_element(BGP_IPV6M_NODE,
13506 &neighbor_remove_private_as_replace_as_cmd);
13507 install_element(BGP_IPV6M_NODE,
13508 &no_neighbor_remove_private_as_replace_as_cmd);
13509 install_element(BGP_IPV6M_NODE,
13510 &neighbor_remove_private_as_all_replace_as_cmd);
13511 install_element(BGP_IPV6M_NODE,
13512 &no_neighbor_remove_private_as_all_replace_as_cmd);
13513 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13514 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13515 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13516 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13517 install_element(BGP_IPV6L_NODE,
13518 &neighbor_remove_private_as_replace_as_cmd);
13519 install_element(BGP_IPV6L_NODE,
13520 &no_neighbor_remove_private_as_replace_as_cmd);
13521 install_element(BGP_IPV6L_NODE,
13522 &neighbor_remove_private_as_all_replace_as_cmd);
13523 install_element(BGP_IPV6L_NODE,
13524 &no_neighbor_remove_private_as_all_replace_as_cmd);
13525 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13526 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13527 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13528 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13529 install_element(BGP_VPNV4_NODE,
13530 &neighbor_remove_private_as_replace_as_cmd);
13531 install_element(BGP_VPNV4_NODE,
13532 &no_neighbor_remove_private_as_replace_as_cmd);
13533 install_element(BGP_VPNV4_NODE,
13534 &neighbor_remove_private_as_all_replace_as_cmd);
13535 install_element(BGP_VPNV4_NODE,
13536 &no_neighbor_remove_private_as_all_replace_as_cmd);
13537 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13538 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13539 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13540 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13541 install_element(BGP_VPNV6_NODE,
13542 &neighbor_remove_private_as_replace_as_cmd);
13543 install_element(BGP_VPNV6_NODE,
13544 &no_neighbor_remove_private_as_replace_as_cmd);
13545 install_element(BGP_VPNV6_NODE,
13546 &neighbor_remove_private_as_all_replace_as_cmd);
13547 install_element(BGP_VPNV6_NODE,
13548 &no_neighbor_remove_private_as_all_replace_as_cmd);
13549
13550 /* "neighbor send-community" commands.*/
13551 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13552 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13553 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13554 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13555 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13556 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13557 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13558 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13559 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13560 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13561 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13562 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13563 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13564 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13565 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13566 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13567 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13568 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13569 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13570 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13571 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13572 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13573 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13574 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13575 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13576 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13577 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13578 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13579 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13580 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13581 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13582 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13583 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13584 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13585 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13586 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13587
13588 /* "neighbor route-reflector" commands.*/
13589 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13590 install_element(BGP_NODE,
13591 &no_neighbor_route_reflector_client_hidden_cmd);
13592 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13593 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13594 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13595 install_element(BGP_IPV4M_NODE,
13596 &no_neighbor_route_reflector_client_cmd);
13597 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13598 install_element(BGP_IPV4L_NODE,
13599 &no_neighbor_route_reflector_client_cmd);
13600 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13601 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13602 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13603 install_element(BGP_IPV6M_NODE,
13604 &no_neighbor_route_reflector_client_cmd);
13605 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13606 install_element(BGP_IPV6L_NODE,
13607 &no_neighbor_route_reflector_client_cmd);
13608 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13609 install_element(BGP_VPNV4_NODE,
13610 &no_neighbor_route_reflector_client_cmd);
13611 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13612 install_element(BGP_VPNV6_NODE,
13613 &no_neighbor_route_reflector_client_cmd);
7c40bf39 13614 install_element(BGP_FLOWSPECV4_NODE,
13615 &neighbor_route_reflector_client_cmd);
13616 install_element(BGP_FLOWSPECV4_NODE,
13617 &no_neighbor_route_reflector_client_cmd);
13618 install_element(BGP_FLOWSPECV6_NODE,
13619 &neighbor_route_reflector_client_cmd);
13620 install_element(BGP_FLOWSPECV6_NODE,
13621 &no_neighbor_route_reflector_client_cmd);
d62a17ae 13622 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13623 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13624
13625 /* "neighbor route-server" commands.*/
13626 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13627 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13628 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13629 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13630 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13631 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13632 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13633 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13634 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13635 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13636 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13637 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13638 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13639 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13640 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13641 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13642 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13643 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
13644 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13645 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 13646 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13647 install_element(BGP_FLOWSPECV4_NODE,
13648 &no_neighbor_route_server_client_cmd);
13649 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13650 install_element(BGP_FLOWSPECV6_NODE,
13651 &no_neighbor_route_server_client_cmd);
d62a17ae 13652
13653 /* "neighbor addpath-tx-all-paths" commands.*/
13654 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13655 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13656 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13657 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13658 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13659 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13660 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13661 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13662 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13663 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13664 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13665 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13666 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13667 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13668 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13669 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13670 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13671 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13672
13673 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13674 install_element(BGP_NODE,
13675 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13676 install_element(BGP_NODE,
13677 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13678 install_element(BGP_IPV4_NODE,
13679 &neighbor_addpath_tx_bestpath_per_as_cmd);
13680 install_element(BGP_IPV4_NODE,
13681 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13682 install_element(BGP_IPV4M_NODE,
13683 &neighbor_addpath_tx_bestpath_per_as_cmd);
13684 install_element(BGP_IPV4M_NODE,
13685 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13686 install_element(BGP_IPV4L_NODE,
13687 &neighbor_addpath_tx_bestpath_per_as_cmd);
13688 install_element(BGP_IPV4L_NODE,
13689 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13690 install_element(BGP_IPV6_NODE,
13691 &neighbor_addpath_tx_bestpath_per_as_cmd);
13692 install_element(BGP_IPV6_NODE,
13693 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13694 install_element(BGP_IPV6M_NODE,
13695 &neighbor_addpath_tx_bestpath_per_as_cmd);
13696 install_element(BGP_IPV6M_NODE,
13697 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13698 install_element(BGP_IPV6L_NODE,
13699 &neighbor_addpath_tx_bestpath_per_as_cmd);
13700 install_element(BGP_IPV6L_NODE,
13701 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13702 install_element(BGP_VPNV4_NODE,
13703 &neighbor_addpath_tx_bestpath_per_as_cmd);
13704 install_element(BGP_VPNV4_NODE,
13705 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13706 install_element(BGP_VPNV6_NODE,
13707 &neighbor_addpath_tx_bestpath_per_as_cmd);
13708 install_element(BGP_VPNV6_NODE,
13709 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13710
13711 /* "neighbor passive" commands. */
13712 install_element(BGP_NODE, &neighbor_passive_cmd);
13713 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13714
13715
13716 /* "neighbor shutdown" commands. */
13717 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13718 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13719 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13720 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13721
13722 /* "neighbor capability extended-nexthop" commands.*/
13723 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13724 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13725
13726 /* "neighbor capability orf prefix-list" commands.*/
13727 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13728 install_element(BGP_NODE,
13729 &no_neighbor_capability_orf_prefix_hidden_cmd);
13730 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13731 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13732 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13733 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13734 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13735 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13736 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13737 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13738 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13739 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13740 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13741 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13742
13743 /* "neighbor capability dynamic" commands.*/
13744 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13745 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13746
13747 /* "neighbor dont-capability-negotiate" commands. */
13748 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13749 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13750
13751 /* "neighbor ebgp-multihop" commands. */
13752 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13753 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13754 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13755
13756 /* "neighbor disable-connected-check" commands. */
13757 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13758 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13759
47cbc09b
PM
13760 /* "neighbor enforce-first-as" commands. */
13761 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13762 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13763
d62a17ae 13764 /* "neighbor description" commands. */
13765 install_element(BGP_NODE, &neighbor_description_cmd);
13766 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 13767 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 13768
13769 /* "neighbor update-source" commands. "*/
13770 install_element(BGP_NODE, &neighbor_update_source_cmd);
13771 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13772
13773 /* "neighbor default-originate" commands. */
13774 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13775 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13776 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13777 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13778 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13779 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13780 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13781 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13782 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13783 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13784 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13785 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13786 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13787 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13788 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13789 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13790 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13791 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13792 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13793 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13794 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13795
13796 /* "neighbor port" commands. */
13797 install_element(BGP_NODE, &neighbor_port_cmd);
13798 install_element(BGP_NODE, &no_neighbor_port_cmd);
13799
13800 /* "neighbor weight" commands. */
13801 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13802 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13803
13804 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13805 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13806 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13807 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13808 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13809 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13810 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13811 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13812 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13813 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13814 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13815 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13816 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13817 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13818 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13819 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13820
13821 /* "neighbor override-capability" commands. */
13822 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13823 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13824
13825 /* "neighbor strict-capability-match" commands. */
13826 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13827 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13828
13829 /* "neighbor timers" commands. */
13830 install_element(BGP_NODE, &neighbor_timers_cmd);
13831 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13832
13833 /* "neighbor timers connect" commands. */
13834 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13835 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13836
13837 /* "neighbor advertisement-interval" commands. */
13838 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13839 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13840
13841 /* "neighbor interface" commands. */
13842 install_element(BGP_NODE, &neighbor_interface_cmd);
13843 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13844
13845 /* "neighbor distribute" commands. */
13846 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13847 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13848 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13849 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13850 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13851 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13852 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13853 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13854 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13855 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13856 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13857 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13858 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13859 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13860 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13861 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13862 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13863 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13864
13865 /* "neighbor prefix-list" commands. */
13866 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13867 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13868 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13869 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13870 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13871 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13872 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13873 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13874 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13875 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13876 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13877 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13878 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13879 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13880 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13881 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13882 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13883 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 13884 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13885 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13886 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13887 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 13888
13889 /* "neighbor filter-list" commands. */
13890 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13891 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13892 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13893 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13894 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13895 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13896 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13897 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13898 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13899 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13900 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13901 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13902 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13903 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13904 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13905 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13906 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13907 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 13908 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13909 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13910 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13911 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 13912
13913 /* "neighbor route-map" commands. */
13914 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13915 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13916 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13917 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13918 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13919 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13920 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13921 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13922 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13923 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13924 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13925 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13926 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13927 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13928 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13929 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13930 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13931 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 13932 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13933 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13934 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13935 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
13936 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13937 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 13938
13939 /* "neighbor unsuppress-map" commands. */
13940 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13941 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13942 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13943 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13944 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13945 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13946 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13947 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13948 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13949 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13950 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13951 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13952 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13953 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13954 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13955 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13956 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13957 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13958
13959 /* "neighbor maximum-prefix" commands. */
13960 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13961 install_element(BGP_NODE,
13962 &neighbor_maximum_prefix_threshold_hidden_cmd);
13963 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13964 install_element(BGP_NODE,
13965 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13966 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13967 install_element(BGP_NODE,
13968 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13969 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13970 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13971 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13972 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13973 install_element(BGP_IPV4_NODE,
13974 &neighbor_maximum_prefix_threshold_warning_cmd);
13975 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13976 install_element(BGP_IPV4_NODE,
13977 &neighbor_maximum_prefix_threshold_restart_cmd);
13978 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13979 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13980 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13981 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13982 install_element(BGP_IPV4M_NODE,
13983 &neighbor_maximum_prefix_threshold_warning_cmd);
13984 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13985 install_element(BGP_IPV4M_NODE,
13986 &neighbor_maximum_prefix_threshold_restart_cmd);
13987 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13988 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13989 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13990 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13991 install_element(BGP_IPV4L_NODE,
13992 &neighbor_maximum_prefix_threshold_warning_cmd);
13993 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13994 install_element(BGP_IPV4L_NODE,
13995 &neighbor_maximum_prefix_threshold_restart_cmd);
13996 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13997 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13998 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13999 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14000 install_element(BGP_IPV6_NODE,
14001 &neighbor_maximum_prefix_threshold_warning_cmd);
14002 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14003 install_element(BGP_IPV6_NODE,
14004 &neighbor_maximum_prefix_threshold_restart_cmd);
14005 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
14006 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
14007 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
14008 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
14009 install_element(BGP_IPV6M_NODE,
14010 &neighbor_maximum_prefix_threshold_warning_cmd);
14011 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
14012 install_element(BGP_IPV6M_NODE,
14013 &neighbor_maximum_prefix_threshold_restart_cmd);
14014 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
14015 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
14016 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
14017 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
14018 install_element(BGP_IPV6L_NODE,
14019 &neighbor_maximum_prefix_threshold_warning_cmd);
14020 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
14021 install_element(BGP_IPV6L_NODE,
14022 &neighbor_maximum_prefix_threshold_restart_cmd);
14023 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
14024 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
14025 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
14026 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
14027 install_element(BGP_VPNV4_NODE,
14028 &neighbor_maximum_prefix_threshold_warning_cmd);
14029 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
14030 install_element(BGP_VPNV4_NODE,
14031 &neighbor_maximum_prefix_threshold_restart_cmd);
14032 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
14033 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
14034 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
14035 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
14036 install_element(BGP_VPNV6_NODE,
14037 &neighbor_maximum_prefix_threshold_warning_cmd);
14038 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
14039 install_element(BGP_VPNV6_NODE,
14040 &neighbor_maximum_prefix_threshold_restart_cmd);
14041 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
14042
14043 /* "neighbor allowas-in" */
14044 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
14045 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
14046 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
14047 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
14048 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
14049 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
14050 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
14051 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
14052 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
14053 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
14054 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
14055 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
14056 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
14057 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
14058 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
14059 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
14060 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
14061 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
14062 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
14063 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
14064
14065 /* address-family commands. */
14066 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
14067 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 14068#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 14069 install_element(BGP_NODE, &address_family_vpnv4_cmd);
14070 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 14071#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 14072
d62a17ae 14073 install_element(BGP_NODE, &address_family_evpn_cmd);
14074
14075 /* "exit-address-family" command. */
14076 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
14077 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
14078 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
14079 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
14080 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
14081 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
14082 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
14083 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 14084 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
14085 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 14086 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
14087
14088 /* "clear ip bgp commands" */
14089 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
14090
14091 /* clear ip bgp prefix */
14092 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
14093 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
14094 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
14095
14096 /* "show [ip] bgp summary" commands. */
14097 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 14098 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 14099 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 14100 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 14101 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
14102 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 14103 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
14104
14105 /* "show [ip] bgp neighbors" commands. */
14106 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
14107
14108 /* "show [ip] bgp peer-group" commands. */
14109 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
14110
14111 /* "show [ip] bgp paths" commands. */
14112 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
14113
14114 /* "show [ip] bgp community" commands. */
14115 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
14116
14117 /* "show ip bgp large-community" commands. */
14118 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
14119 /* "show [ip] bgp attribute-info" commands. */
14120 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 14121 /* "show [ip] bgp route-leak" command */
14122 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 14123
14124 /* "redistribute" commands. */
14125 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
14126 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
14127 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
14128 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
14129 install_element(BGP_NODE,
14130 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
14131 install_element(BGP_NODE,
14132 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
14133 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
14134 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
14135 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
14136 install_element(BGP_NODE,
14137 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
14138 install_element(BGP_NODE,
14139 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
14140 install_element(BGP_NODE,
14141 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
14142 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
14143 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
14144 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
14145 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
14146 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
14147 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
14148 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
14149 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
14150 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
14151 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
14152 install_element(BGP_IPV4_NODE,
14153 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
14154 install_element(BGP_IPV4_NODE,
14155 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
14156 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
14157 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
14158 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
14159 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
14160 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
14161 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
14162
b9c7bc5a
PZ
14163 /* import|export vpn [route-map WORD] */
14164 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
14165 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 14166
12a844a5
DS
14167 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
14168 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
14169
d62a17ae 14170 /* ttl_security commands */
14171 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
14172 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
14173
14174 /* "show [ip] bgp memory" commands. */
14175 install_element(VIEW_NODE, &show_bgp_memory_cmd);
14176
acf71666
MK
14177 /* "show bgp martian next-hop" */
14178 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
14179
48ecf8f5
DS
14180 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
14181
d62a17ae 14182 /* "show [ip] bgp views" commands. */
14183 install_element(VIEW_NODE, &show_bgp_views_cmd);
14184
14185 /* "show [ip] bgp vrfs" commands. */
14186 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
14187
14188 /* Community-list. */
14189 community_list_vty();
ddb5b488
PZ
14190
14191 /* vpn-policy commands */
b9c7bc5a
PZ
14192 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
14193 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
14194 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
14195 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
14196 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
14197 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14198 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14199 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14200 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14201 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
14202 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14203 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 14204
301ad80a
PG
14205 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14206 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14207
b9c7bc5a
PZ
14208 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14209 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14210 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14211 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14212 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14213 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14214 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14215 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14216 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14217 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
14218 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14219 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 14220}
6b0655a2 14221
718e3744 14222#include "memory.h"
14223#include "bgp_regex.h"
14224#include "bgp_clist.h"
14225#include "bgp_ecommunity.h"
14226
14227/* VTY functions. */
14228
14229/* Direction value to string conversion. */
d62a17ae 14230static const char *community_direct_str(int direct)
14231{
14232 switch (direct) {
14233 case COMMUNITY_DENY:
14234 return "deny";
14235 case COMMUNITY_PERMIT:
14236 return "permit";
14237 default:
14238 return "unknown";
14239 }
718e3744 14240}
14241
14242/* Display error string. */
d62a17ae 14243static void community_list_perror(struct vty *vty, int ret)
14244{
14245 switch (ret) {
14246 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14247 vty_out(vty, "%% Can't find community-list\n");
14248 break;
14249 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14250 vty_out(vty, "%% Malformed community-list value\n");
14251 break;
14252 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14253 vty_out(vty,
14254 "%% Community name conflict, previously defined as standard community\n");
14255 break;
14256 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14257 vty_out(vty,
14258 "%% Community name conflict, previously defined as expanded community\n");
14259 break;
14260 }
718e3744 14261}
14262
5bf15956
DW
14263/* "community-list" keyword help string. */
14264#define COMMUNITY_LIST_STR "Add a community list entry\n"
14265
7336e101
SP
14266/*community-list standard */
14267DEFUN (community_list_standard,
14268 bgp_community_list_standard_cmd,
14269 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14270 BGP_STR
718e3744 14271 COMMUNITY_LIST_STR
14272 "Community list number (standard)\n"
5bf15956 14273 "Add an standard community-list entry\n"
718e3744 14274 "Community list name\n"
14275 "Specify community to reject\n"
14276 "Specify community to accept\n"
14277 COMMUNITY_VAL_STR)
14278{
d62a17ae 14279 char *cl_name_or_number = NULL;
14280 int direct = 0;
14281 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14282
d62a17ae 14283 int idx = 0;
7336e101
SP
14284
14285 if (argv_find(argv, argc, "ip", &idx)) {
14286 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14287 vty_out(vty, "if you are using this please migrate to the below command.\n");
14288 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14289 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14290 }
14291
d62a17ae 14292 argv_find(argv, argc, "(1-99)", &idx);
14293 argv_find(argv, argc, "WORD", &idx);
14294 cl_name_or_number = argv[idx]->arg;
14295 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14296 : COMMUNITY_DENY;
14297 argv_find(argv, argc, "AA:NN", &idx);
14298 char *str = argv_concat(argv, argc, idx);
42f914d4 14299
d62a17ae 14300 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14301 style);
42f914d4 14302
d62a17ae 14303 XFREE(MTYPE_TMP, str);
42f914d4 14304
d62a17ae 14305 if (ret < 0) {
14306 /* Display error string. */
14307 community_list_perror(vty, ret);
14308 return CMD_WARNING_CONFIG_FAILED;
14309 }
42f914d4 14310
d62a17ae 14311 return CMD_SUCCESS;
718e3744 14312}
14313
7336e101
SP
14314#if CONFDATE > 20191005
14315CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14316#endif
14317ALIAS (community_list_standard,
14318 ip_community_list_standard_cmd,
14319 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 14320 IP_STR
14321 COMMUNITY_LIST_STR
14322 "Community list number (standard)\n"
5bf15956
DW
14323 "Add an standard community-list entry\n"
14324 "Community list name\n"
718e3744 14325 "Specify community to reject\n"
14326 "Specify community to accept\n"
14327 COMMUNITY_VAL_STR)
7336e101
SP
14328
14329DEFUN (no_community_list_standard_all,
14330 no_bgp_community_list_standard_all_cmd,
14331 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14332 NO_STR
14333 BGP_STR
14334 COMMUNITY_LIST_STR
14335 "Community list number (standard)\n"
14336 "Add an standard community-list entry\n"
14337 "Community list name\n"
14338 "Specify community to reject\n"
14339 "Specify community to accept\n"
14340 COMMUNITY_VAL_STR)
718e3744 14341{
d62a17ae 14342 char *cl_name_or_number = NULL;
174b5cb9 14343 char *str = NULL;
d62a17ae 14344 int direct = 0;
14345 int style = COMMUNITY_LIST_STANDARD;
42f914d4 14346
d62a17ae 14347 int idx = 0;
7336e101
SP
14348
14349 if (argv_find(argv, argc, "ip", &idx)) {
14350 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14351 vty_out(vty, "if you are using this please migrate to the below command.\n");
14352 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14353 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14354 }
14355
174b5cb9
DA
14356 argv_find(argv, argc, "permit", &idx);
14357 argv_find(argv, argc, "deny", &idx);
14358
14359 if (idx) {
14360 direct = argv_find(argv, argc, "permit", &idx)
14361 ? COMMUNITY_PERMIT
14362 : COMMUNITY_DENY;
14363
14364 idx = 0;
14365 argv_find(argv, argc, "AA:NN", &idx);
14366 str = argv_concat(argv, argc, idx);
14367 }
14368
14369 idx = 0;
d62a17ae 14370 argv_find(argv, argc, "(1-99)", &idx);
14371 argv_find(argv, argc, "WORD", &idx);
14372 cl_name_or_number = argv[idx]->arg;
42f914d4 14373
d62a17ae 14374 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14375 direct, style);
42f914d4 14376
d62a17ae 14377 XFREE(MTYPE_TMP, str);
daf9ddbb 14378
d62a17ae 14379 if (ret < 0) {
14380 community_list_perror(vty, ret);
14381 return CMD_WARNING_CONFIG_FAILED;
14382 }
42f914d4 14383
d62a17ae 14384 return CMD_SUCCESS;
718e3744 14385}
7336e101
SP
14386ALIAS (no_community_list_standard_all,
14387 no_ip_community_list_standard_all_cmd,
14388 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14389 NO_STR
718e3744 14390 IP_STR
14391 COMMUNITY_LIST_STR
7336e101
SP
14392 "Community list number (standard)\n"
14393 "Add an standard community-list entry\n"
14394 "Community list name\n"
14395 "Specify community to reject\n"
14396 "Specify community to accept\n"
14397 COMMUNITY_VAL_STR)
14398
174b5cb9
DA
14399ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14400 "no bgp community-list <(1-99)|standard WORD>",
14401 NO_STR BGP_STR COMMUNITY_LIST_STR
14402 "Community list number (standard)\n"
14403 "Add an standard community-list entry\n"
14404 "Community list name\n")
14405
14406ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14407 "no ip community-list <(1-99)|standard WORD>",
14408 NO_STR BGP_STR COMMUNITY_LIST_STR
14409 "Community list number (standard)\n"
14410 "Add an standard community-list entry\n"
14411 "Community list name\n")
14412
7336e101
SP
14413/*community-list expanded */
14414DEFUN (community_list_expanded_all,
14415 bgp_community_list_expanded_all_cmd,
14416 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14417 BGP_STR
14418 COMMUNITY_LIST_STR
718e3744 14419 "Community list number (expanded)\n"
5bf15956 14420 "Add an expanded community-list entry\n"
718e3744 14421 "Community list name\n"
14422 "Specify community to reject\n"
14423 "Specify community to accept\n"
14424 COMMUNITY_VAL_STR)
14425{
d62a17ae 14426 char *cl_name_or_number = NULL;
14427 int direct = 0;
14428 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14429
d62a17ae 14430 int idx = 0;
7336e101
SP
14431 if (argv_find(argv, argc, "ip", &idx)) {
14432 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14433 vty_out(vty, "if you are using this please migrate to the below command.\n");
14434 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14435 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14436 }
d62a17ae 14437 argv_find(argv, argc, "(100-500)", &idx);
14438 argv_find(argv, argc, "WORD", &idx);
14439 cl_name_or_number = argv[idx]->arg;
14440 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14441 : COMMUNITY_DENY;
14442 argv_find(argv, argc, "AA:NN", &idx);
14443 char *str = argv_concat(argv, argc, idx);
42f914d4 14444
d62a17ae 14445 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14446 style);
42f914d4 14447
d62a17ae 14448 XFREE(MTYPE_TMP, str);
42f914d4 14449
d62a17ae 14450 if (ret < 0) {
14451 /* Display error string. */
14452 community_list_perror(vty, ret);
14453 return CMD_WARNING_CONFIG_FAILED;
14454 }
42f914d4 14455
d62a17ae 14456 return CMD_SUCCESS;
718e3744 14457}
14458
7336e101
SP
14459ALIAS (community_list_expanded_all,
14460 ip_community_list_expanded_all_cmd,
14461 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 14462 IP_STR
14463 COMMUNITY_LIST_STR
5bf15956
DW
14464 "Community list number (expanded)\n"
14465 "Add an expanded community-list entry\n"
718e3744 14466 "Community list name\n"
14467 "Specify community to reject\n"
14468 "Specify community to accept\n"
5bf15956 14469 COMMUNITY_VAL_STR)
7336e101
SP
14470
14471DEFUN (no_community_list_expanded_all,
14472 no_bgp_community_list_expanded_all_cmd,
14473 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14474 NO_STR
14475 BGP_STR
14476 COMMUNITY_LIST_STR
14477 "Community list number (expanded)\n"
14478 "Add an expanded community-list entry\n"
14479 "Community list name\n"
14480 "Specify community to reject\n"
14481 "Specify community to accept\n"
14482 COMMUNITY_VAL_STR)
718e3744 14483{
d62a17ae 14484 char *cl_name_or_number = NULL;
174b5cb9 14485 char *str = NULL;
d62a17ae 14486 int direct = 0;
14487 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 14488
d62a17ae 14489 int idx = 0;
7336e101
SP
14490 if (argv_find(argv, argc, "ip", &idx)) {
14491 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14492 vty_out(vty, "if you are using this please migrate to the below command.\n");
174b5cb9
DA
14493 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14494 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14495 }
14496
3c4b8fe2 14497 idx = 0;
174b5cb9
DA
14498 argv_find(argv, argc, "permit", &idx);
14499 argv_find(argv, argc, "deny", &idx);
14500
14501 if (idx) {
14502 direct = argv_find(argv, argc, "permit", &idx)
14503 ? COMMUNITY_PERMIT
14504 : COMMUNITY_DENY;
14505
14506 idx = 0;
14507 argv_find(argv, argc, "AA:NN", &idx);
14508 str = argv_concat(argv, argc, idx);
7336e101 14509 }
174b5cb9
DA
14510
14511 idx = 0;
d62a17ae 14512 argv_find(argv, argc, "(100-500)", &idx);
14513 argv_find(argv, argc, "WORD", &idx);
14514 cl_name_or_number = argv[idx]->arg;
42f914d4 14515
d62a17ae 14516 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 14517 direct, style);
42f914d4 14518
d62a17ae 14519 XFREE(MTYPE_TMP, str);
daf9ddbb 14520
d62a17ae 14521 if (ret < 0) {
14522 community_list_perror(vty, ret);
14523 return CMD_WARNING_CONFIG_FAILED;
14524 }
42f914d4 14525
d62a17ae 14526 return CMD_SUCCESS;
718e3744 14527}
14528
7336e101
SP
14529ALIAS (no_community_list_expanded_all,
14530 no_ip_community_list_expanded_all_cmd,
14531 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14532 NO_STR
14533 IP_STR
14534 COMMUNITY_LIST_STR
14535 "Community list number (expanded)\n"
14536 "Add an expanded community-list entry\n"
14537 "Community list name\n"
14538 "Specify community to reject\n"
14539 "Specify community to accept\n"
14540 COMMUNITY_VAL_STR)
14541
174b5cb9
DA
14542ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14543 "no bgp community-list <(100-500)|expanded WORD>",
14544 NO_STR IP_STR COMMUNITY_LIST_STR
14545 "Community list number (expanded)\n"
14546 "Add an expanded community-list entry\n"
14547 "Community list name\n")
14548
14549ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14550 "no ip community-list <(100-500)|expanded WORD>",
14551 NO_STR IP_STR COMMUNITY_LIST_STR
14552 "Community list number (expanded)\n"
14553 "Add an expanded community-list entry\n"
14554 "Community list name\n")
14555
8d9b8ed9
PM
14556/* Return configuration string of community-list entry. */
14557static const char *community_list_config_str(struct community_entry *entry)
14558{
14559 const char *str;
14560
14561 if (entry->any)
14562 str = "";
14563 else {
14564 if (entry->style == COMMUNITY_LIST_STANDARD)
14565 str = community_str(entry->u.com, false);
14566 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14567 str = lcommunity_str(entry->u.lcom, false);
14568 else
14569 str = entry->config;
14570 }
14571 return str;
14572}
14573
d62a17ae 14574static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 14575{
d62a17ae 14576 struct community_entry *entry;
718e3744 14577
d62a17ae 14578 for (entry = list->head; entry; entry = entry->next) {
14579 if (entry == list->head) {
14580 if (all_digit(list->name))
14581 vty_out(vty, "Community %s list %s\n",
14582 entry->style == COMMUNITY_LIST_STANDARD
14583 ? "standard"
14584 : "(expanded) access",
14585 list->name);
14586 else
14587 vty_out(vty, "Named Community %s list %s\n",
14588 entry->style == COMMUNITY_LIST_STANDARD
14589 ? "standard"
14590 : "expanded",
14591 list->name);
14592 }
14593 if (entry->any)
14594 vty_out(vty, " %s\n",
14595 community_direct_str(entry->direct));
14596 else
14597 vty_out(vty, " %s %s\n",
14598 community_direct_str(entry->direct),
8d9b8ed9 14599 community_list_config_str(entry));
d62a17ae 14600 }
718e3744 14601}
14602
7336e101
SP
14603DEFUN (show_community_list,
14604 show_bgp_community_list_cmd,
14605 "show bgp community-list",
718e3744 14606 SHOW_STR
7336e101 14607 BGP_STR
718e3744 14608 "List community-list\n")
14609{
d62a17ae 14610 struct community_list *list;
14611 struct community_list_master *cm;
718e3744 14612
7336e101
SP
14613 int idx = 0;
14614 if (argv_find(argv, argc, "ip", &idx)) {
14615 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14616 vty_out(vty, "if you are using this please migrate to the below command.\n");
14617 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14618 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14619 }
d62a17ae 14620 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14621 if (!cm)
14622 return CMD_SUCCESS;
718e3744 14623
d62a17ae 14624 for (list = cm->num.head; list; list = list->next)
14625 community_list_show(vty, list);
718e3744 14626
d62a17ae 14627 for (list = cm->str.head; list; list = list->next)
14628 community_list_show(vty, list);
718e3744 14629
d62a17ae 14630 return CMD_SUCCESS;
718e3744 14631}
14632
7336e101
SP
14633ALIAS (show_community_list,
14634 show_ip_community_list_cmd,
14635 "show ip community-list",
718e3744 14636 SHOW_STR
14637 IP_STR
7336e101
SP
14638 "List community-list\n")
14639
14640DEFUN (show_community_list_arg,
14641 show_bgp_community_list_arg_cmd,
960b69b9 14642 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
14643 SHOW_STR
14644 BGP_STR
718e3744 14645 "List community-list\n"
14646 "Community-list number\n"
960b69b9 14647 "Community-list name\n"
14648 "Detailed information on community-list\n")
718e3744 14649{
d62a17ae 14650 int idx_comm_list = 3;
14651 struct community_list *list;
718e3744 14652
7336e101
SP
14653 int idx = 0;
14654 if (argv_find(argv, argc, "ip", &idx)) {
14655 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14656 vty_out(vty, "if you are using this please migrate to the below command.\n");
960b69b9 14657 vty_out(vty, "'show bgp community-list <(1-500)|WORD> detail'\n");
14658 zlog_warn("Deprecated option: 'show ip community-list <(1-500)|WORD>' being used");
7336e101 14659 }
e237b0d2 14660 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 14661 COMMUNITY_LIST_MASTER);
14662 if (!list) {
14663 vty_out(vty, "%% Can't find community-list\n");
14664 return CMD_WARNING;
14665 }
718e3744 14666
d62a17ae 14667 community_list_show(vty, list);
718e3744 14668
d62a17ae 14669 return CMD_SUCCESS;
718e3744 14670}
6b0655a2 14671
7336e101
SP
14672ALIAS (show_community_list_arg,
14673 show_ip_community_list_arg_cmd,
14674 "show ip community-list <(1-500)|WORD>",
14675 SHOW_STR
14676 IP_STR
14677 "List community-list\n"
14678 "Community-list number\n"
14679 "Community-list name\n")
14680
57d187bc
JS
14681/*
14682 * Large Community code.
14683 */
d62a17ae 14684static int lcommunity_list_set_vty(struct vty *vty, int argc,
14685 struct cmd_token **argv, int style,
14686 int reject_all_digit_name)
14687{
14688 int ret;
14689 int direct;
14690 char *str;
14691 int idx = 0;
14692 char *cl_name;
14693
7336e101
SP
14694 if (argv_find(argv, argc, "ip", &idx)) {
14695 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14696 vty_out(vty, "if you are using this please migrate to the below command.\n");
14697 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14698 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14699 }
d62a17ae 14700 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14701 : COMMUNITY_DENY;
14702
14703 /* All digit name check. */
14704 idx = 0;
14705 argv_find(argv, argc, "WORD", &idx);
14706 argv_find(argv, argc, "(1-99)", &idx);
14707 argv_find(argv, argc, "(100-500)", &idx);
14708 cl_name = argv[idx]->arg;
14709 if (reject_all_digit_name && all_digit(cl_name)) {
14710 vty_out(vty, "%% Community name cannot have all digits\n");
14711 return CMD_WARNING_CONFIG_FAILED;
14712 }
14713
14714 idx = 0;
14715 argv_find(argv, argc, "AA:BB:CC", &idx);
14716 argv_find(argv, argc, "LINE", &idx);
14717 /* Concat community string argument. */
14718 if (idx)
14719 str = argv_concat(argv, argc, idx);
14720 else
14721 str = NULL;
14722
14723 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14724
14725 /* Free temporary community list string allocated by
14726 argv_concat(). */
0a22ddfb 14727 XFREE(MTYPE_TMP, str);
d62a17ae 14728
14729 if (ret < 0) {
14730 community_list_perror(vty, ret);
14731 return CMD_WARNING_CONFIG_FAILED;
14732 }
14733 return CMD_SUCCESS;
14734}
14735
14736static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14737 struct cmd_token **argv, int style)
14738{
14739 int ret;
14740 int direct = 0;
14741 char *str = NULL;
14742 int idx = 0;
14743
7336e101
SP
14744 if (argv_find(argv, argc, "ip", &idx)) {
14745 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14746 vty_out(vty, "if you are using this please migrate to the below command.\n");
14747 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
16941c05 14748 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
7336e101 14749 }
d62a17ae 14750 argv_find(argv, argc, "permit", &idx);
14751 argv_find(argv, argc, "deny", &idx);
14752
14753 if (idx) {
14754 /* Check the list direct. */
14755 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14756 direct = COMMUNITY_PERMIT;
14757 else
14758 direct = COMMUNITY_DENY;
14759
14760 idx = 0;
14761 argv_find(argv, argc, "LINE", &idx);
14762 argv_find(argv, argc, "AA:AA:NN", &idx);
14763 /* Concat community string argument. */
14764 str = argv_concat(argv, argc, idx);
14765 }
14766
14767 idx = 0;
14768 argv_find(argv, argc, "(1-99)", &idx);
14769 argv_find(argv, argc, "(100-500)", &idx);
14770 argv_find(argv, argc, "WORD", &idx);
14771
14772 /* Unset community list. */
14773 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14774 style);
14775
14776 /* Free temporary community list string allocated by
14777 argv_concat(). */
0a22ddfb 14778 XFREE(MTYPE_TMP, str);
d62a17ae 14779
14780 if (ret < 0) {
14781 community_list_perror(vty, ret);
14782 return CMD_WARNING_CONFIG_FAILED;
14783 }
14784
14785 return CMD_SUCCESS;
57d187bc
JS
14786}
14787
14788/* "large-community-list" keyword help string. */
14789#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14790#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14791
7336e101
SP
14792#if CONFDATE > 20191005
14793CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14794#endif
14795DEFUN (lcommunity_list_standard,
14796 bgp_lcommunity_list_standard_cmd,
7336e101
SP
14797 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14798 BGP_STR
14799 LCOMMUNITY_LIST_STR
14800 "Large Community list number (standard)\n"
14801 "Specify large community to reject\n"
14802 "Specify large community to accept\n"
14803 LCOMMUNITY_VAL_STR)
52951b63 14804{
d62a17ae 14805 return lcommunity_list_set_vty(vty, argc, argv,
14806 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
14807}
14808
82cdf28d
NT
14809ALIAS (lcommunity_list_standard,
14810 ip_lcommunity_list_standard_cmd,
52951b63 14811 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
14812 IP_STR
14813 LCOMMUNITY_LIST_STR
14814 "Large Community list number (standard)\n"
14815 "Specify large community to reject\n"
14816 "Specify large community to accept\n"
14817 LCOMMUNITY_VAL_STR)
7336e101
SP
14818
14819DEFUN (lcommunity_list_expanded,
14820 bgp_lcommunity_list_expanded_cmd,
14821 "bgp large-community-list (100-500) <deny|permit> LINE...",
14822 BGP_STR
14823 LCOMMUNITY_LIST_STR
14824 "Large Community list number (expanded)\n"
14825 "Specify large community to reject\n"
14826 "Specify large community to accept\n"
14827 "An ordered list as a regular-expression\n")
57d187bc 14828{
d62a17ae 14829 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14830 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
14831}
14832
7336e101 14833ALIAS (lcommunity_list_expanded,
57d187bc
JS
14834 ip_lcommunity_list_expanded_cmd,
14835 "ip large-community-list (100-500) <deny|permit> LINE...",
14836 IP_STR
14837 LCOMMUNITY_LIST_STR
14838 "Large Community list number (expanded)\n"
14839 "Specify large community to reject\n"
14840 "Specify large community to accept\n"
14841 "An ordered list as a regular-expression\n")
7336e101
SP
14842
14843DEFUN (lcommunity_list_name_standard,
14844 bgp_lcommunity_list_name_standard_cmd,
7336e101
SP
14845 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14846 BGP_STR
14847 LCOMMUNITY_LIST_STR
14848 "Specify standard large-community-list\n"
14849 "Large Community list name\n"
14850 "Specify large community to reject\n"
14851 "Specify large community to accept\n"
14852 LCOMMUNITY_VAL_STR)
52951b63 14853{
d62a17ae 14854 return lcommunity_list_set_vty(vty, argc, argv,
14855 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
14856}
14857
82cdf28d
NT
14858ALIAS (lcommunity_list_name_standard,
14859 ip_lcommunity_list_name_standard_cmd,
52951b63 14860 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
14861 IP_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)
7336e101
SP
14868
14869DEFUN (lcommunity_list_name_expanded,
14870 bgp_lcommunity_list_name_expanded_cmd,
14871 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14872 BGP_STR
14873 LCOMMUNITY_LIST_STR
14874 "Specify expanded large-community-list\n"
14875 "Large Community list name\n"
14876 "Specify large community to reject\n"
14877 "Specify large community to accept\n"
14878 "An ordered list as a regular-expression\n")
57d187bc 14879{
d62a17ae 14880 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 14881 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
14882}
14883
7336e101 14884ALIAS (lcommunity_list_name_expanded,
57d187bc
JS
14885 ip_lcommunity_list_name_expanded_cmd,
14886 "ip large-community-list expanded WORD <deny|permit> LINE...",
14887 IP_STR
14888 LCOMMUNITY_LIST_STR
14889 "Specify expanded large-community-list\n"
14890 "Large Community list name\n"
14891 "Specify large community to reject\n"
14892 "Specify large community to accept\n"
14893 "An ordered list as a regular-expression\n")
7336e101
SP
14894
14895DEFUN (no_lcommunity_list_standard_all,
14896 no_bgp_lcommunity_list_standard_all_cmd,
14897 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14898 NO_STR
14899 BGP_STR
14900 LCOMMUNITY_LIST_STR
14901 "Large Community list number (standard)\n"
14902 "Large Community list number (expanded)\n"
14903 "Large Community list name\n")
57d187bc 14904{
7336e101
SP
14905 return lcommunity_list_unset_vty(vty, argc, argv,
14906 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14907}
14908
7336e101 14909ALIAS (no_lcommunity_list_standard_all,
57d187bc
JS
14910 no_ip_lcommunity_list_standard_all_cmd,
14911 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14912 NO_STR
14913 IP_STR
14914 LCOMMUNITY_LIST_STR
14915 "Large Community list number (standard)\n"
14916 "Large Community list number (expanded)\n"
14917 "Large Community list name\n")
7336e101
SP
14918
14919DEFUN (no_lcommunity_list_name_expanded_all,
14920 no_bgp_lcommunity_list_name_expanded_all_cmd,
14921 "no bgp large-community-list expanded WORD",
14922 NO_STR
14923 BGP_STR
14924 LCOMMUNITY_LIST_STR
14925 "Specify expanded large-community-list\n"
14926 "Large Community list name\n")
57d187bc 14927{
d62a17ae 14928 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14929 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14930}
14931
7336e101 14932ALIAS (no_lcommunity_list_name_expanded_all,
57d187bc
JS
14933 no_ip_lcommunity_list_name_expanded_all_cmd,
14934 "no ip large-community-list expanded WORD",
14935 NO_STR
14936 IP_STR
14937 LCOMMUNITY_LIST_STR
14938 "Specify expanded large-community-list\n"
14939 "Large Community list name\n")
7336e101
SP
14940
14941DEFUN (no_lcommunity_list_standard,
14942 no_bgp_lcommunity_list_standard_cmd,
14943 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14944 NO_STR
14945 BGP_STR
14946 LCOMMUNITY_LIST_STR
14947 "Large Community list number (standard)\n"
14948 "Specify large community to reject\n"
14949 "Specify large community to accept\n"
14950 LCOMMUNITY_VAL_STR)
57d187bc 14951{
d62a17ae 14952 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14953 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
14954}
14955
7336e101 14956ALIAS (no_lcommunity_list_standard,
57d187bc
JS
14957 no_ip_lcommunity_list_standard_cmd,
14958 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14959 NO_STR
14960 IP_STR
14961 LCOMMUNITY_LIST_STR
14962 "Large Community list number (standard)\n"
14963 "Specify large community to reject\n"
14964 "Specify large community to accept\n"
14965 LCOMMUNITY_VAL_STR)
7336e101
SP
14966
14967DEFUN (no_lcommunity_list_expanded,
14968 no_bgp_lcommunity_list_expanded_cmd,
14969 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14970 NO_STR
14971 BGP_STR
14972 LCOMMUNITY_LIST_STR
14973 "Large Community list number (expanded)\n"
14974 "Specify large community to reject\n"
14975 "Specify large community to accept\n"
14976 "An ordered list as a regular-expression\n")
57d187bc 14977{
d62a17ae 14978 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 14979 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
14980}
14981
7336e101 14982ALIAS (no_lcommunity_list_expanded,
57d187bc
JS
14983 no_ip_lcommunity_list_expanded_cmd,
14984 "no ip large-community-list (100-500) <deny|permit> LINE...",
14985 NO_STR
14986 IP_STR
14987 LCOMMUNITY_LIST_STR
14988 "Large Community list number (expanded)\n"
14989 "Specify large community to reject\n"
14990 "Specify large community to accept\n"
14991 "An ordered list as a regular-expression\n")
7336e101
SP
14992
14993DEFUN (no_lcommunity_list_name_standard,
14994 no_bgp_lcommunity_list_name_standard_cmd,
14995 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14996 NO_STR
14997 BGP_STR
14998 LCOMMUNITY_LIST_STR
14999 "Specify standard large-community-list\n"
15000 "Large Community list name\n"
15001 "Specify large community to reject\n"
15002 "Specify large community to accept\n"
15003 LCOMMUNITY_VAL_STR)
57d187bc 15004{
d62a17ae 15005 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 15006 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
15007}
15008
7336e101 15009ALIAS (no_lcommunity_list_name_standard,
57d187bc
JS
15010 no_ip_lcommunity_list_name_standard_cmd,
15011 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
15012 NO_STR
15013 IP_STR
15014 LCOMMUNITY_LIST_STR
15015 "Specify standard large-community-list\n"
15016 "Large Community list name\n"
15017 "Specify large community to reject\n"
15018 "Specify large community to accept\n"
15019 LCOMMUNITY_VAL_STR)
7336e101
SP
15020
15021DEFUN (no_lcommunity_list_name_expanded,
15022 no_bgp_lcommunity_list_name_expanded_cmd,
15023 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
15024 NO_STR
15025 BGP_STR
15026 LCOMMUNITY_LIST_STR
15027 "Specify expanded large-community-list\n"
15028 "Large community list name\n"
15029 "Specify large community to reject\n"
15030 "Specify large community to accept\n"
15031 "An ordered list as a regular-expression\n")
57d187bc 15032{
d62a17ae 15033 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 15034 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
15035}
15036
7336e101 15037ALIAS (no_lcommunity_list_name_expanded,
57d187bc
JS
15038 no_ip_lcommunity_list_name_expanded_cmd,
15039 "no ip large-community-list expanded WORD <deny|permit> LINE...",
15040 NO_STR
15041 IP_STR
15042 LCOMMUNITY_LIST_STR
15043 "Specify expanded large-community-list\n"
15044 "Large community list name\n"
15045 "Specify large community to reject\n"
15046 "Specify large community to accept\n"
15047 "An ordered list as a regular-expression\n")
d62a17ae 15048
15049static void lcommunity_list_show(struct vty *vty, struct community_list *list)
15050{
15051 struct community_entry *entry;
15052
15053 for (entry = list->head; entry; entry = entry->next) {
15054 if (entry == list->head) {
15055 if (all_digit(list->name))
15056 vty_out(vty, "Large community %s list %s\n",
169b72c8 15057 entry->style ==
15058 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 15059 ? "standard"
15060 : "(expanded) access",
15061 list->name);
15062 else
15063 vty_out(vty,
15064 "Named large community %s list %s\n",
169b72c8 15065 entry->style ==
15066 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 15067 ? "standard"
15068 : "expanded",
15069 list->name);
15070 }
15071 if (entry->any)
15072 vty_out(vty, " %s\n",
15073 community_direct_str(entry->direct));
15074 else
15075 vty_out(vty, " %s %s\n",
15076 community_direct_str(entry->direct),
8d9b8ed9 15077 community_list_config_str(entry));
d62a17ae 15078 }
57d187bc
JS
15079}
15080
7336e101
SP
15081DEFUN (show_lcommunity_list,
15082 show_bgp_lcommunity_list_cmd,
15083 "show bgp large-community-list",
57d187bc 15084 SHOW_STR
7336e101 15085 BGP_STR
57d187bc
JS
15086 "List large-community list\n")
15087{
d62a17ae 15088 struct community_list *list;
15089 struct community_list_master *cm;
7336e101
SP
15090 int idx = 0;
15091
15092 if (argv_find(argv, argc, "ip", &idx)) {
15093 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15094 vty_out(vty, "if you are using this please migrate to the below command.\n");
15095 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
15096 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
15097 }
57d187bc 15098
d62a17ae 15099 cm = community_list_master_lookup(bgp_clist,
15100 LARGE_COMMUNITY_LIST_MASTER);
15101 if (!cm)
15102 return CMD_SUCCESS;
57d187bc 15103
d62a17ae 15104 for (list = cm->num.head; list; list = list->next)
15105 lcommunity_list_show(vty, list);
57d187bc 15106
d62a17ae 15107 for (list = cm->str.head; list; list = list->next)
15108 lcommunity_list_show(vty, list);
57d187bc 15109
d62a17ae 15110 return CMD_SUCCESS;
57d187bc
JS
15111}
15112
7336e101
SP
15113ALIAS (show_lcommunity_list,
15114 show_ip_lcommunity_list_cmd,
15115 "show ip large-community-list",
57d187bc
JS
15116 SHOW_STR
15117 IP_STR
7336e101
SP
15118 "List large-community list\n")
15119
15120DEFUN (show_lcommunity_list_arg,
15121 show_bgp_lcommunity_list_arg_cmd,
960b69b9 15122 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
15123 SHOW_STR
15124 BGP_STR
57d187bc 15125 "List large-community list\n"
960b69b9 15126 "Large-community-list number\n"
15127 "Large-community-list name\n"
15128 "Detailed information on large-community-list\n")
57d187bc 15129{
d62a17ae 15130 struct community_list *list;
7336e101
SP
15131 int idx = 0;
15132
15133 if (argv_find(argv, argc, "ip", &idx)) {
15134 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15135 vty_out(vty, "if you are using this please migrate to the below command.\n");
960b69b9 15136 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD> detail'\n");
15137 zlog_warn("Deprecated option: 'show ip large-community-list <(1-500)|WORD>' being used");
7336e101 15138 }
57d187bc 15139
e237b0d2 15140 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 15141 LARGE_COMMUNITY_LIST_MASTER);
15142 if (!list) {
960b69b9 15143 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 15144 return CMD_WARNING;
15145 }
57d187bc 15146
d62a17ae 15147 lcommunity_list_show(vty, list);
57d187bc 15148
d62a17ae 15149 return CMD_SUCCESS;
57d187bc
JS
15150}
15151
7336e101
SP
15152ALIAS (show_lcommunity_list_arg,
15153 show_ip_lcommunity_list_arg_cmd,
15154 "show ip large-community-list <(1-500)|WORD>",
15155 SHOW_STR
15156 IP_STR
15157 "List large-community list\n"
15158 "large-community-list number\n"
15159 "large-community-list name\n")
15160
718e3744 15161/* "extcommunity-list" keyword help string. */
15162#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15163#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15164
7336e101
SP
15165DEFUN (extcommunity_list_standard,
15166 bgp_extcommunity_list_standard_cmd,
15167 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15168 BGP_STR
718e3744 15169 EXTCOMMUNITY_LIST_STR
15170 "Extended Community list number (standard)\n"
718e3744 15171 "Specify standard extcommunity-list\n"
5bf15956 15172 "Community list name\n"
718e3744 15173 "Specify community to reject\n"
15174 "Specify community to accept\n"
15175 EXTCOMMUNITY_VAL_STR)
15176{
d62a17ae 15177 int style = EXTCOMMUNITY_LIST_STANDARD;
15178 int direct = 0;
15179 char *cl_number_or_name = NULL;
42f914d4 15180
d62a17ae 15181 int idx = 0;
7336e101
SP
15182 if (argv_find(argv, argc, "ip", &idx)) {
15183 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15184 vty_out(vty, "if you are using this please migrate to the below command.\n");
15185 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15186 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15187 }
d62a17ae 15188 argv_find(argv, argc, "(1-99)", &idx);
15189 argv_find(argv, argc, "WORD", &idx);
15190 cl_number_or_name = argv[idx]->arg;
15191 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15192 : COMMUNITY_DENY;
15193 argv_find(argv, argc, "AA:NN", &idx);
15194 char *str = argv_concat(argv, argc, idx);
42f914d4 15195
d62a17ae 15196 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15197 direct, style);
42f914d4 15198
d62a17ae 15199 XFREE(MTYPE_TMP, str);
42f914d4 15200
d62a17ae 15201 if (ret < 0) {
15202 community_list_perror(vty, ret);
15203 return CMD_WARNING_CONFIG_FAILED;
15204 }
42f914d4 15205
d62a17ae 15206 return CMD_SUCCESS;
718e3744 15207}
15208
7336e101
SP
15209#if CONFDATE > 20191005
15210CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15211#endif
15212ALIAS (extcommunity_list_standard,
15213 ip_extcommunity_list_standard_cmd,
15214 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15215 IP_STR
15216 EXTCOMMUNITY_LIST_STR
7336e101
SP
15217 "Extended Community list number (standard)\n"
15218 "Specify standard extcommunity-list\n"
15219 "Community list name\n"
15220 "Specify community to reject\n"
15221 "Specify community to accept\n"
15222 EXTCOMMUNITY_VAL_STR)
15223
15224DEFUN (extcommunity_list_name_expanded,
15225 bgp_extcommunity_list_name_expanded_cmd,
15226 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15227 BGP_STR
15228 EXTCOMMUNITY_LIST_STR
5bf15956 15229 "Extended Community list number (expanded)\n"
718e3744 15230 "Specify expanded extcommunity-list\n"
15231 "Extended Community list name\n"
15232 "Specify community to reject\n"
15233 "Specify community to accept\n"
15234 "An ordered list as a regular-expression\n")
15235{
d62a17ae 15236 int style = EXTCOMMUNITY_LIST_EXPANDED;
15237 int direct = 0;
15238 char *cl_number_or_name = NULL;
42f914d4 15239
d62a17ae 15240 int idx = 0;
7336e101
SP
15241 if (argv_find(argv, argc, "ip", &idx)) {
15242 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15243 vty_out(vty, "if you are using this please migrate to the below command.\n");
15244 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15245 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15246 }
15247
d62a17ae 15248 argv_find(argv, argc, "(100-500)", &idx);
15249 argv_find(argv, argc, "WORD", &idx);
15250 cl_number_or_name = argv[idx]->arg;
15251 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15252 : COMMUNITY_DENY;
15253 argv_find(argv, argc, "LINE", &idx);
15254 char *str = argv_concat(argv, argc, idx);
42f914d4 15255
d62a17ae 15256 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15257 direct, style);
42f914d4 15258
d62a17ae 15259 XFREE(MTYPE_TMP, str);
42f914d4 15260
d62a17ae 15261 if (ret < 0) {
15262 community_list_perror(vty, ret);
15263 return CMD_WARNING_CONFIG_FAILED;
15264 }
42f914d4 15265
d62a17ae 15266 return CMD_SUCCESS;
718e3744 15267}
15268
7336e101
SP
15269ALIAS (extcommunity_list_name_expanded,
15270 ip_extcommunity_list_name_expanded_cmd,
15271 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
813d4307
DW
15272 IP_STR
15273 EXTCOMMUNITY_LIST_STR
7336e101
SP
15274 "Extended Community list number (expanded)\n"
15275 "Specify expanded extcommunity-list\n"
15276 "Extended Community list name\n"
15277 "Specify community to reject\n"
15278 "Specify community to accept\n"
15279 "An ordered list as a regular-expression\n")
15280
15281DEFUN (no_extcommunity_list_standard_all,
15282 no_bgp_extcommunity_list_standard_all_cmd,
15283 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15284 NO_STR
15285 BGP_STR
15286 EXTCOMMUNITY_LIST_STR
813d4307 15287 "Extended Community list number (standard)\n"
718e3744 15288 "Specify standard extcommunity-list\n"
5bf15956 15289 "Community list name\n"
718e3744 15290 "Specify community to reject\n"
15291 "Specify community to accept\n"
15292 EXTCOMMUNITY_VAL_STR)
15293{
d62a17ae 15294 int style = EXTCOMMUNITY_LIST_STANDARD;
15295 int direct = 0;
15296 char *cl_number_or_name = NULL;
d4455c89 15297 char *str = NULL;
42f914d4 15298
d62a17ae 15299 int idx = 0;
7336e101
SP
15300 if (argv_find(argv, argc, "ip", &idx)) {
15301 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15302 vty_out(vty, "if you are using this please migrate to the below command.\n");
15303 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15304 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15305 }
d4455c89
DA
15306
15307 idx = 0;
15308 argv_find(argv, argc, "permit", &idx);
15309 argv_find(argv, argc, "deny", &idx);
15310
15311 if (idx) {
15312 direct = argv_find(argv, argc, "permit", &idx)
15313 ? COMMUNITY_PERMIT
15314 : COMMUNITY_DENY;
15315
15316 idx = 0;
15317 argv_find(argv, argc, "AA:NN", &idx);
15318 str = argv_concat(argv, argc, idx);
15319 }
15320
15321 idx = 0;
d62a17ae 15322 argv_find(argv, argc, "(1-99)", &idx);
15323 argv_find(argv, argc, "WORD", &idx);
15324 cl_number_or_name = argv[idx]->arg;
42f914d4 15325
d62a17ae 15326 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15327 direct, style);
42f914d4 15328
d62a17ae 15329 XFREE(MTYPE_TMP, str);
42f914d4 15330
d62a17ae 15331 if (ret < 0) {
15332 community_list_perror(vty, ret);
15333 return CMD_WARNING_CONFIG_FAILED;
15334 }
42f914d4 15335
d62a17ae 15336 return CMD_SUCCESS;
718e3744 15337}
15338
7336e101
SP
15339ALIAS (no_extcommunity_list_standard_all,
15340 no_ip_extcommunity_list_standard_all_cmd,
15341 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 15342 NO_STR
15343 IP_STR
15344 EXTCOMMUNITY_LIST_STR
7336e101
SP
15345 "Extended Community list number (standard)\n"
15346 "Specify standard extcommunity-list\n"
15347 "Community list name\n"
15348 "Specify community to reject\n"
15349 "Specify community to accept\n"
15350 EXTCOMMUNITY_VAL_STR)
15351
d4455c89
DA
15352ALIAS(no_extcommunity_list_standard_all,
15353 no_bgp_extcommunity_list_standard_all_list_cmd,
15354 "no bgp extcommunity-list <(1-99)|standard WORD>",
15355 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15356 "Extended Community list number (standard)\n"
15357 "Specify standard extcommunity-list\n"
15358 "Community list name\n")
15359
15360ALIAS(no_extcommunity_list_standard_all,
15361 no_ip_extcommunity_list_standard_all_list_cmd,
15362 "no ip extcommunity-list <(1-99)|standard WORD>",
15363 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15364 "Extended Community list number (standard)\n"
15365 "Specify standard extcommunity-list\n"
15366 "Community list name\n")
15367
7336e101
SP
15368DEFUN (no_extcommunity_list_expanded_all,
15369 no_bgp_extcommunity_list_expanded_all_cmd,
15370 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15371 NO_STR
15372 BGP_STR
15373 EXTCOMMUNITY_LIST_STR
718e3744 15374 "Extended Community list number (expanded)\n"
718e3744 15375 "Specify expanded extcommunity-list\n"
5bf15956 15376 "Extended Community list name\n"
718e3744 15377 "Specify community to reject\n"
15378 "Specify community to accept\n"
15379 "An ordered list as a regular-expression\n")
15380{
d62a17ae 15381 int style = EXTCOMMUNITY_LIST_EXPANDED;
15382 int direct = 0;
15383 char *cl_number_or_name = NULL;
d4455c89 15384 char *str = NULL;
42f914d4 15385
d62a17ae 15386 int idx = 0;
7336e101
SP
15387 if (argv_find(argv, argc, "ip", &idx)) {
15388 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15389 vty_out(vty, "if you are using this please migrate to the below command.\n");
15390 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15391 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15392 }
d4455c89
DA
15393
15394 idx = 0;
15395 argv_find(argv, argc, "permit", &idx);
15396 argv_find(argv, argc, "deny", &idx);
15397
15398 if (idx) {
15399 direct = argv_find(argv, argc, "permit", &idx)
15400 ? COMMUNITY_PERMIT
15401 : COMMUNITY_DENY;
15402
15403 idx = 0;
15404 argv_find(argv, argc, "LINE", &idx);
15405 str = argv_concat(argv, argc, idx);
15406 }
15407
15408 idx = 0;
d62a17ae 15409 argv_find(argv, argc, "(100-500)", &idx);
15410 argv_find(argv, argc, "WORD", &idx);
15411 cl_number_or_name = argv[idx]->arg;
42f914d4 15412
d62a17ae 15413 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 15414 direct, style);
42f914d4 15415
d62a17ae 15416 XFREE(MTYPE_TMP, str);
42f914d4 15417
d62a17ae 15418 if (ret < 0) {
15419 community_list_perror(vty, ret);
15420 return CMD_WARNING_CONFIG_FAILED;
15421 }
42f914d4 15422
d62a17ae 15423 return CMD_SUCCESS;
718e3744 15424}
15425
7336e101
SP
15426ALIAS (no_extcommunity_list_expanded_all,
15427 no_ip_extcommunity_list_expanded_all_cmd,
15428 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15429 NO_STR
15430 IP_STR
15431 EXTCOMMUNITY_LIST_STR
15432 "Extended Community list number (expanded)\n"
15433 "Specify expanded extcommunity-list\n"
15434 "Extended Community list name\n"
15435 "Specify community to reject\n"
15436 "Specify community to accept\n"
15437 "An ordered list as a regular-expression\n")
15438
d4455c89
DA
15439ALIAS(no_extcommunity_list_expanded_all,
15440 no_ip_extcommunity_list_expanded_all_list_cmd,
15441 "no ip extcommunity-list <(100-500)|expanded WORD>",
15442 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15443 "Extended Community list number (expanded)\n"
15444 "Specify expanded extcommunity-list\n"
15445 "Extended Community list name\n")
15446
15447ALIAS(no_extcommunity_list_expanded_all,
15448 no_bgp_extcommunity_list_expanded_all_list_cmd,
15449 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15450 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15451 "Extended Community list number (expanded)\n"
15452 "Specify expanded extcommunity-list\n"
15453 "Extended Community list name\n")
15454
d62a17ae 15455static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 15456{
d62a17ae 15457 struct community_entry *entry;
718e3744 15458
d62a17ae 15459 for (entry = list->head; entry; entry = entry->next) {
15460 if (entry == list->head) {
15461 if (all_digit(list->name))
15462 vty_out(vty, "Extended community %s list %s\n",
15463 entry->style == EXTCOMMUNITY_LIST_STANDARD
15464 ? "standard"
15465 : "(expanded) access",
15466 list->name);
15467 else
15468 vty_out(vty,
15469 "Named extended community %s list %s\n",
15470 entry->style == EXTCOMMUNITY_LIST_STANDARD
15471 ? "standard"
15472 : "expanded",
15473 list->name);
15474 }
15475 if (entry->any)
15476 vty_out(vty, " %s\n",
15477 community_direct_str(entry->direct));
15478 else
15479 vty_out(vty, " %s %s\n",
15480 community_direct_str(entry->direct),
8d9b8ed9 15481 community_list_config_str(entry));
d62a17ae 15482 }
718e3744 15483}
15484
7336e101
SP
15485DEFUN (show_extcommunity_list,
15486 show_bgp_extcommunity_list_cmd,
15487 "show bgp extcommunity-list",
718e3744 15488 SHOW_STR
7336e101 15489 BGP_STR
718e3744 15490 "List extended-community list\n")
15491{
d62a17ae 15492 struct community_list *list;
15493 struct community_list_master *cm;
7336e101 15494 int idx = 0;
718e3744 15495
7336e101
SP
15496 if (argv_find(argv, argc, "ip", &idx)) {
15497 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15498 vty_out(vty, "if you are using this please migrate to the below command.\n");
15499 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15500 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15501 }
d62a17ae 15502 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15503 if (!cm)
15504 return CMD_SUCCESS;
718e3744 15505
d62a17ae 15506 for (list = cm->num.head; list; list = list->next)
15507 extcommunity_list_show(vty, list);
718e3744 15508
d62a17ae 15509 for (list = cm->str.head; list; list = list->next)
15510 extcommunity_list_show(vty, list);
718e3744 15511
d62a17ae 15512 return CMD_SUCCESS;
718e3744 15513}
15514
7336e101
SP
15515ALIAS (show_extcommunity_list,
15516 show_ip_extcommunity_list_cmd,
15517 "show ip extcommunity-list",
718e3744 15518 SHOW_STR
15519 IP_STR
7336e101
SP
15520 "List extended-community list\n")
15521
15522DEFUN (show_extcommunity_list_arg,
15523 show_bgp_extcommunity_list_arg_cmd,
960b69b9 15524 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
15525 SHOW_STR
15526 BGP_STR
718e3744 15527 "List extended-community list\n"
15528 "Extcommunity-list number\n"
960b69b9 15529 "Extcommunity-list name\n"
15530 "Detailed information on extcommunity-list\n")
718e3744 15531{
d62a17ae 15532 int idx_comm_list = 3;
15533 struct community_list *list;
7336e101 15534 int idx = 0;
718e3744 15535
7336e101
SP
15536 if (argv_find(argv, argc, "ip", &idx)) {
15537 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15538 vty_out(vty, "if you are using this please migrate to the below command.\n");
960b69b9 15539 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD> detail'\n");
15540 zlog_warn("Deprecated option: 'show ip extcommunity-list <(1-500)|WORD>' being used");
7336e101 15541 }
e237b0d2 15542 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 15543 EXTCOMMUNITY_LIST_MASTER);
15544 if (!list) {
15545 vty_out(vty, "%% Can't find extcommunity-list\n");
15546 return CMD_WARNING;
15547 }
718e3744 15548
d62a17ae 15549 extcommunity_list_show(vty, list);
718e3744 15550
d62a17ae 15551 return CMD_SUCCESS;
718e3744 15552}
6b0655a2 15553
7336e101
SP
15554ALIAS (show_extcommunity_list_arg,
15555 show_ip_extcommunity_list_arg_cmd,
15556 "show ip extcommunity-list <(1-500)|WORD>",
15557 SHOW_STR
15558 IP_STR
15559 "List extended-community list\n"
15560 "Extcommunity-list number\n"
15561 "Extcommunity-list name\n")
15562
718e3744 15563/* Display community-list and extcommunity-list configuration. */
d62a17ae 15564static int community_list_config_write(struct vty *vty)
15565{
15566 struct community_list *list;
15567 struct community_entry *entry;
15568 struct community_list_master *cm;
15569 int write = 0;
15570
15571 /* Community-list. */
15572 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15573
15574 for (list = cm->num.head; list; list = list->next)
15575 for (entry = list->head; entry; entry = entry->next) {
7336e101 15576 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 15577 community_direct_str(entry->direct),
15578 community_list_config_str(entry));
15579 write++;
15580 }
15581 for (list = cm->str.head; list; list = list->next)
15582 for (entry = list->head; entry; entry = entry->next) {
7336e101 15583 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 15584 entry->style == COMMUNITY_LIST_STANDARD
15585 ? "standard"
15586 : "expanded",
15587 list->name, community_direct_str(entry->direct),
15588 community_list_config_str(entry));
15589 write++;
15590 }
15591
15592 /* Extcommunity-list. */
15593 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15594
15595 for (list = cm->num.head; list; list = list->next)
15596 for (entry = list->head; entry; entry = entry->next) {
7336e101 15597 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 15598 list->name, community_direct_str(entry->direct),
15599 community_list_config_str(entry));
15600 write++;
15601 }
15602 for (list = cm->str.head; list; list = list->next)
15603 for (entry = list->head; entry; entry = entry->next) {
7336e101 15604 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 15605 entry->style == EXTCOMMUNITY_LIST_STANDARD
15606 ? "standard"
15607 : "expanded",
15608 list->name, community_direct_str(entry->direct),
15609 community_list_config_str(entry));
15610 write++;
15611 }
15612
15613
15614 /* lcommunity-list. */
15615 cm = community_list_master_lookup(bgp_clist,
15616 LARGE_COMMUNITY_LIST_MASTER);
15617
15618 for (list = cm->num.head; list; list = list->next)
15619 for (entry = list->head; entry; entry = entry->next) {
7336e101 15620 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 15621 list->name, community_direct_str(entry->direct),
15622 community_list_config_str(entry));
15623 write++;
15624 }
15625 for (list = cm->str.head; list; list = list->next)
15626 for (entry = list->head; entry; entry = entry->next) {
7336e101 15627 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 15628 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15629 ? "standard"
15630 : "expanded",
15631 list->name, community_direct_str(entry->direct),
15632 community_list_config_str(entry));
15633 write++;
15634 }
15635
15636 return write;
15637}
15638
15639static struct cmd_node community_list_node = {
15640 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 15641};
15642
d62a17ae 15643static void community_list_vty(void)
15644{
15645 install_node(&community_list_node, community_list_config_write);
15646
15647 /* Community-list. */
7336e101
SP
15648 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15649 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15650 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 15651 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 15652 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 15653 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
15654 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15655 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 15656 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15657 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15658 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
174b5cb9 15659 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
d62a17ae 15660 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
174b5cb9 15661 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
d62a17ae 15662 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15663 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15664
15665 /* Extcommunity-list. */
7336e101
SP
15666 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15667 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15668 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
15669 install_element(CONFIG_NODE,
15670 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 15671 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
15672 install_element(CONFIG_NODE,
15673 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
15674 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15675 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 15676 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15677 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15678 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
d4455c89 15679 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
d62a17ae 15680 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
d4455c89 15681 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
d62a17ae 15682 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15683 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15684
15685 /* Large Community List */
7336e101 15686 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
15687 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15688 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101
SP
15689 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15690 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15691 install_element(CONFIG_NODE,
15692 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15693 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15694 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15695 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15696 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15697 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15698 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
d62a17ae 15699 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
d62a17ae 15700 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15701 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
d62a17ae 15702 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15703 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15704 install_element(CONFIG_NODE,
15705 &no_ip_lcommunity_list_name_expanded_all_cmd);
15706 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15707 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15708 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15709 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15710 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15711 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 15712}