]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Tell Coverity SA that regex cannot be NULL here
[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"
1c0d8808 35#include "lib_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"
dd65f45e 67#include "bgpd/bgp_evpn_vty.h"
dcc68b5e 68#include "bgpd/bgp_addpath.h"
48ecf8f5 69#include "bgpd/bgp_mac.h"
dd65f45e
DL
70#include "bgpd/bgp_flowspec.h"
71#if ENABLE_BGP_VNC
72#include "bgpd/rfapi/bgp_rfapi_cfg.h"
73#endif
74
5d5393b9
DL
75FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
76 { .val_long = true, .match_profile = "datacenter", },
77 { .val_long = false },
78)
79FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
80 { .val_long = true, .match_profile = "datacenter", },
81 { .val_long = false },
82)
83FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
84 { .val_long = true, .match_profile = "datacenter", },
85 { .val_long = false },
86)
87FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
88 { .val_long = true, .match_profile = "datacenter", },
89 { .val_long = false },
90)
91FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
92 { .val_ulong = 10, .match_profile = "datacenter", },
93 { .val_ulong = 120 },
94)
95FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
96 { .val_ulong = 9, .match_profile = "datacenter", },
97 { .val_ulong = 180 },
98)
99FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
100 { .val_ulong = 3, .match_profile = "datacenter", },
101 { .val_ulong = 60 },
102)
103
dd65f45e
DL
104DEFINE_HOOK(bgp_inst_config_write,
105 (struct bgp *bgp, struct vty *vty),
106 (bgp, vty))
718e3744 107
2ba1fe69 108#define GR_NO_OPER "The Graceful Restart No Operation was executed as cmd same as previous one."
055679e9 109#define GR_INVALID "The Graceful Restart command used is not valid at this moment."
d62a17ae 110static struct peer_group *listen_range_exists(struct bgp *bgp,
111 struct prefix *range, int exact);
112
055679e9 113/* Show BGP peer's information. */
114enum show_type {
115 show_all,
116 show_peer,
117 show_ipv4_all,
118 show_ipv6_all,
119 show_ipv4_peer,
120 show_ipv6_peer
121};
122
2986cac2 123static struct peer_group *listen_range_exists(
124 struct bgp *bgp,
125 struct prefix *range,
126 int exact);
127
128static void bgp_show_global_graceful_restart_mode_vty(
129 struct vty *vty,
130 struct bgp *bgp,
131 bool use_json,
132 json_object *json);
133
134static int bgp_show_neighbor_graceful_restart_afi_all(
135 struct vty *vty,
136 enum show_type type,
137 const char *ip_str,
138 afi_t afi,
139 bool use_json);
140
d62a17ae 141static enum node_type bgp_node_type(afi_t afi, safi_t safi)
142{
143 switch (afi) {
144 case AFI_IP:
145 switch (safi) {
146 case SAFI_UNICAST:
147 return BGP_IPV4_NODE;
148 break;
149 case SAFI_MULTICAST:
150 return BGP_IPV4M_NODE;
151 break;
152 case SAFI_LABELED_UNICAST:
153 return BGP_IPV4L_NODE;
154 break;
155 case SAFI_MPLS_VPN:
156 return BGP_VPNV4_NODE;
157 break;
7c40bf39 158 case SAFI_FLOWSPEC:
159 return BGP_FLOWSPECV4_NODE;
5c525538
RW
160 default:
161 /* not expected */
162 return BGP_IPV4_NODE;
163 break;
d62a17ae 164 }
165 break;
166 case AFI_IP6:
167 switch (safi) {
168 case SAFI_UNICAST:
169 return BGP_IPV6_NODE;
170 break;
171 case SAFI_MULTICAST:
172 return BGP_IPV6M_NODE;
173 break;
174 case SAFI_LABELED_UNICAST:
175 return BGP_IPV6L_NODE;
176 break;
177 case SAFI_MPLS_VPN:
178 return BGP_VPNV6_NODE;
179 break;
7c40bf39 180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV6_NODE;
5c525538
RW
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
185 break;
d62a17ae 186 }
187 break;
188 case AFI_L2VPN:
189 return BGP_EVPN_NODE;
190 break;
b26f891d 191 case AFI_UNSPEC:
d62a17ae 192 case AFI_MAX:
193 // We should never be here but to clarify the switch statement..
194 return BGP_IPV4_NODE;
195 break;
196 }
197
198 // Impossible to happen
199 return BGP_IPV4_NODE;
f51bae9c 200}
20eb8864 201
5cb5f4d0
DD
202static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
203{
204 if (afi == AFI_IP && safi == SAFI_UNICAST)
205 return "IPv4 Unicast";
206 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
207 return "IPv4 Multicast";
208 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
209 return "IPv4 Labeled Unicast";
210 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
211 return "IPv4 VPN";
212 else if (afi == AFI_IP && safi == SAFI_ENCAP)
213 return "IPv4 Encap";
214 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
215 return "IPv4 Flowspec";
216 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
217 return "IPv6 Unicast";
218 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
219 return "IPv6 Multicast";
220 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
221 return "IPv6 Labeled Unicast";
222 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
223 return "IPv6 VPN";
224 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
225 return "IPv6 Encap";
226 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
227 return "IPv6 Flowspec";
228 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
229 return "L2VPN EVPN";
8e5509b0 230 else
5cb5f4d0 231 return "Unknown";
5cb5f4d0
DD
232}
233
234/*
235 * Please note that we have intentionally camelCased
236 * the return strings here. So if you want
237 * to use this function, please ensure you
238 * are doing this within json output
239 */
240static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
241{
242 if (afi == AFI_IP && safi == SAFI_UNICAST)
243 return "ipv4Unicast";
244 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
245 return "ipv4Multicast";
246 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
247 return "ipv4LabeledUnicast";
248 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
249 return "ipv4Vpn";
250 else if (afi == AFI_IP && safi == SAFI_ENCAP)
251 return "ipv4Encap";
252 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
253 return "ipv4Flowspec";
254 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
255 return "ipv6Unicast";
256 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
257 return "ipv6Multicast";
258 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
259 return "ipv6LabeledUnicast";
260 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
261 return "ipv6Vpn";
262 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
263 return "ipv6Encap";
264 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
265 return "ipv6Flowspec";
266 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
267 return "l2VpnEvpn";
8e5509b0 268 else
5cb5f4d0 269 return "Unknown";
5cb5f4d0
DD
270}
271
718e3744 272/* Utility function to get address family from current node. */
d62a17ae 273afi_t bgp_node_afi(struct vty *vty)
274{
275 afi_t afi;
276 switch (vty->node) {
277 case BGP_IPV6_NODE:
278 case BGP_IPV6M_NODE:
279 case BGP_IPV6L_NODE:
280 case BGP_VPNV6_NODE:
7c40bf39 281 case BGP_FLOWSPECV6_NODE:
d62a17ae 282 afi = AFI_IP6;
283 break;
284 case BGP_EVPN_NODE:
285 afi = AFI_L2VPN;
286 break;
287 default:
288 afi = AFI_IP;
289 break;
290 }
291 return afi;
718e3744 292}
293
294/* Utility function to get subsequent address family from current
295 node. */
d62a17ae 296safi_t bgp_node_safi(struct vty *vty)
297{
298 safi_t safi;
299 switch (vty->node) {
300 case BGP_VPNV4_NODE:
301 case BGP_VPNV6_NODE:
302 safi = SAFI_MPLS_VPN;
303 break;
304 case BGP_IPV4M_NODE:
305 case BGP_IPV6M_NODE:
306 safi = SAFI_MULTICAST;
307 break;
308 case BGP_EVPN_NODE:
309 safi = SAFI_EVPN;
310 break;
311 case BGP_IPV4L_NODE:
312 case BGP_IPV6L_NODE:
313 safi = SAFI_LABELED_UNICAST;
314 break;
7c40bf39 315 case BGP_FLOWSPECV4_NODE:
316 case BGP_FLOWSPECV6_NODE:
317 safi = SAFI_FLOWSPEC;
318 break;
d62a17ae 319 default:
320 safi = SAFI_UNICAST;
321 break;
322 }
323 return safi;
718e3744 324}
325
55f91488
QY
326/**
327 * Converts an AFI in string form to afi_t
328 *
329 * @param afi string, one of
330 * - "ipv4"
331 * - "ipv6"
81cf0de5 332 * - "l2vpn"
55f91488
QY
333 * @return the corresponding afi_t
334 */
d62a17ae 335afi_t bgp_vty_afi_from_str(const char *afi_str)
336{
337 afi_t afi = AFI_MAX; /* unknown */
338 if (strmatch(afi_str, "ipv4"))
339 afi = AFI_IP;
340 else if (strmatch(afi_str, "ipv6"))
341 afi = AFI_IP6;
81cf0de5
CS
342 else if (strmatch(afi_str, "l2vpn"))
343 afi = AFI_L2VPN;
d62a17ae 344 return afi;
345}
346
347int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
348 afi_t *afi)
349{
350 int ret = 0;
351 if (argv_find(argv, argc, "ipv4", index)) {
352 ret = 1;
353 if (afi)
354 *afi = AFI_IP;
355 } else if (argv_find(argv, argc, "ipv6", index)) {
356 ret = 1;
357 if (afi)
358 *afi = AFI_IP6;
8688b3e7
DS
359 } else if (argv_find(argv, argc, "l2vpn", index)) {
360 ret = 1;
361 if (afi)
362 *afi = AFI_L2VPN;
d62a17ae 363 }
364 return ret;
46f296b4
LB
365}
366
375a2e67 367/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 368safi_t bgp_vty_safi_from_str(const char *safi_str)
369{
370 safi_t safi = SAFI_MAX; /* unknown */
371 if (strmatch(safi_str, "multicast"))
372 safi = SAFI_MULTICAST;
373 else if (strmatch(safi_str, "unicast"))
374 safi = SAFI_UNICAST;
375 else if (strmatch(safi_str, "vpn"))
376 safi = SAFI_MPLS_VPN;
81cf0de5
CS
377 else if (strmatch(safi_str, "evpn"))
378 safi = SAFI_EVPN;
d62a17ae 379 else if (strmatch(safi_str, "labeled-unicast"))
380 safi = SAFI_LABELED_UNICAST;
7c40bf39 381 else if (strmatch(safi_str, "flowspec"))
382 safi = SAFI_FLOWSPEC;
d62a17ae 383 return safi;
384}
385
386int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
387 safi_t *safi)
388{
389 int ret = 0;
390 if (argv_find(argv, argc, "unicast", index)) {
391 ret = 1;
392 if (safi)
393 *safi = SAFI_UNICAST;
394 } else if (argv_find(argv, argc, "multicast", index)) {
395 ret = 1;
396 if (safi)
397 *safi = SAFI_MULTICAST;
398 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
399 ret = 1;
400 if (safi)
401 *safi = SAFI_LABELED_UNICAST;
402 } else if (argv_find(argv, argc, "vpn", index)) {
403 ret = 1;
404 if (safi)
405 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
406 } else if (argv_find(argv, argc, "evpn", index)) {
407 ret = 1;
408 if (safi)
409 *safi = SAFI_EVPN;
7c40bf39 410 } else if (argv_find(argv, argc, "flowspec", index)) {
411 ret = 1;
412 if (safi)
413 *safi = SAFI_FLOWSPEC;
d62a17ae 414 }
415 return ret;
46f296b4
LB
416}
417
5d5393b9
DL
418int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
419 enum bgp_instance_type inst_type)
420{
421 int ret = bgp_get(bgp, as, name, inst_type);
422
423 if (ret == BGP_CREATED) {
424 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
425 DFLT_BGP_CONNECT_RETRY);
426
427 if (DFLT_BGP_IMPORT_CHECK)
428 bgp_flag_set(*bgp, BGP_FLAG_IMPORT_CHECK);
429 if (DFLT_BGP_SHOW_HOSTNAME)
430 bgp_flag_set(*bgp, BGP_FLAG_SHOW_HOSTNAME);
431 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
432 bgp_flag_set(*bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
433 if (DFLT_BGP_DETERMINISTIC_MED)
434 bgp_flag_set(*bgp, BGP_FLAG_DETERMINISTIC_MED);
435
436 ret = BGP_SUCCESS;
437 }
438 return ret;
439}
440
7eeee51e 441/*
f212a857 442 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 443 *
f212a857
DS
444 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
445 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
446 * to appropriate values for the calling function. This is to allow the
447 * calling function to make decisions appropriate for the show command
448 * that is being parsed.
449 *
450 * The show commands are generally of the form:
d62a17ae 451 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
452 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
453 *
454 * Since we use argv_find if the show command in particular doesn't have:
455 * [ip]
18c57037 456 * [<view|vrf> VIEWVRFNAME]
375a2e67 457 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
458 * The command parsing should still be ok.
459 *
460 * vty -> The vty for the command so we can output some useful data in
461 * the event of a parse error in the vrf.
462 * argv -> The command tokens
463 * argc -> How many command tokens we have
d62a17ae 464 * idx -> The current place in the command, generally should be 0 for this
465 * function
7eeee51e
DS
466 * afi -> The parsed afi if it was included in the show command, returned here
467 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 468 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 469 * use_json -> json is configured or not
7eeee51e
DS
470 *
471 * The function returns the correct location in the parse tree for the
472 * last token found.
0e37c258
DS
473 *
474 * Returns 0 for failure to parse correctly, else the idx position of where
475 * it found the last token.
7eeee51e 476 */
d62a17ae 477int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
478 struct cmd_token **argv, int argc,
479 int *idx, afi_t *afi, safi_t *safi,
9f049418 480 struct bgp **bgp, bool use_json)
d62a17ae 481{
482 char *vrf_name = NULL;
483
484 assert(afi);
485 assert(safi);
486 assert(bgp);
487
488 if (argv_find(argv, argc, "ip", idx))
489 *afi = AFI_IP;
490
9a8bdf1c 491 if (argv_find(argv, argc, "view", idx))
d62a17ae 492 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
493 else if (argv_find(argv, argc, "vrf", idx)) {
494 vrf_name = argv[*idx + 1]->arg;
495 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
496 vrf_name = NULL;
497 }
498 if (vrf_name) {
d62a17ae 499 if (strmatch(vrf_name, "all"))
500 *bgp = NULL;
501 else {
502 *bgp = bgp_lookup_by_name(vrf_name);
503 if (!*bgp) {
52e5b8c4
SP
504 if (use_json) {
505 json_object *json = NULL;
506 json = json_object_new_object();
507 json_object_string_add(
508 json, "warning",
509 "View/Vrf is unknown");
510 vty_out(vty, "%s\n",
511 json_object_to_json_string_ext(json,
512 JSON_C_TO_STRING_PRETTY));
513 json_object_free(json);
514 }
ca61fd25
DS
515 else
516 vty_out(vty, "View/Vrf %s is unknown\n",
517 vrf_name);
d62a17ae 518 *idx = 0;
519 return 0;
520 }
521 }
522 } else {
523 *bgp = bgp_get_default();
524 if (!*bgp) {
52e5b8c4
SP
525 if (use_json) {
526 json_object *json = NULL;
527 json = json_object_new_object();
528 json_object_string_add(
529 json, "warning",
530 "Default BGP instance not found");
531 vty_out(vty, "%s\n",
532 json_object_to_json_string_ext(json,
533 JSON_C_TO_STRING_PRETTY));
534 json_object_free(json);
535 }
ca61fd25
DS
536 else
537 vty_out(vty,
538 "Default BGP instance not found\n");
d62a17ae 539 *idx = 0;
540 return 0;
541 }
542 }
543
544 if (argv_find_and_parse_afi(argv, argc, idx, afi))
545 argv_find_and_parse_safi(argv, argc, idx, safi);
546
547 *idx += 1;
548 return *idx;
549}
550
551static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
552{
553 struct interface *ifp = NULL;
554
555 if (su->sa.sa_family == AF_INET)
556 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
557 else if (su->sa.sa_family == AF_INET6)
558 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
559 su->sin6.sin6_scope_id,
560 bgp->vrf_id);
561
562 if (ifp)
563 return 1;
564
565 return 0;
718e3744 566}
567
568/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
569/* This is used only for configuration, so disallow if attempted on
570 * a dynamic neighbor.
571 */
d62a17ae 572static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
573{
574 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
575 int ret;
576 union sockunion su;
577 struct peer *peer;
578
579 if (!bgp) {
580 return NULL;
581 }
582
583 ret = str2sockunion(ip_str, &su);
584 if (ret < 0) {
585 peer = peer_lookup_by_conf_if(bgp, ip_str);
586 if (!peer) {
587 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
588 == NULL) {
589 vty_out(vty,
590 "%% Malformed address or name: %s\n",
591 ip_str);
592 return NULL;
593 }
594 }
595 } else {
596 peer = peer_lookup(bgp, &su);
597 if (!peer) {
598 vty_out(vty,
599 "%% Specify remote-as or peer-group commands first\n");
600 return NULL;
601 }
602 if (peer_dynamic_neighbor(peer)) {
603 vty_out(vty,
604 "%% Operation not allowed on a dynamic neighbor\n");
605 return NULL;
606 }
607 }
608 return peer;
718e3744 609}
610
611/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
612/* This is used only for configuration, so disallow if attempted on
613 * a dynamic neighbor.
614 */
d62a17ae 615struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
616{
617 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
618 int ret;
619 union sockunion su;
620 struct peer *peer = NULL;
621 struct peer_group *group = NULL;
622
623 if (!bgp) {
624 return NULL;
625 }
626
627 ret = str2sockunion(peer_str, &su);
628 if (ret == 0) {
629 /* IP address, locate peer. */
630 peer = peer_lookup(bgp, &su);
631 } else {
632 /* Not IP, could match either peer configured on interface or a
633 * group. */
634 peer = peer_lookup_by_conf_if(bgp, peer_str);
635 if (!peer)
636 group = peer_group_lookup(bgp, peer_str);
637 }
638
639 if (peer) {
640 if (peer_dynamic_neighbor(peer)) {
641 vty_out(vty,
642 "%% Operation not allowed on a dynamic neighbor\n");
643 return NULL;
644 }
645
646 return peer;
647 }
648
649 if (group)
650 return group->conf;
651
652 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
653
654 return NULL;
655}
656
657int bgp_vty_return(struct vty *vty, int ret)
658{
659 const char *str = NULL;
660
661 switch (ret) {
662 case BGP_ERR_INVALID_VALUE:
663 str = "Invalid value";
664 break;
665 case BGP_ERR_INVALID_FLAG:
666 str = "Invalid flag";
667 break;
668 case BGP_ERR_PEER_GROUP_SHUTDOWN:
669 str = "Peer-group has been shutdown. Activate the peer-group first";
670 break;
671 case BGP_ERR_PEER_FLAG_CONFLICT:
672 str = "Can't set override-capability and strict-capability-match at the same time";
673 break;
674 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
675 str = "Specify remote-as or peer-group remote AS first";
676 break;
677 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
678 str = "Cannot change the peer-group. Deconfigure first";
679 break;
680 case BGP_ERR_PEER_GROUP_MISMATCH:
681 str = "Peer is not a member of this peer-group";
682 break;
683 case BGP_ERR_PEER_FILTER_CONFLICT:
684 str = "Prefix/distribute list can not co-exist";
685 break;
686 case BGP_ERR_NOT_INTERNAL_PEER:
687 str = "Invalid command. Not an internal neighbor";
688 break;
689 case BGP_ERR_REMOVE_PRIVATE_AS:
690 str = "remove-private-AS cannot be configured for IBGP peers";
691 break;
692 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
693 str = "Local-AS allowed only for EBGP peers";
694 break;
695 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
696 str = "Cannot have local-as same as BGP AS number";
697 break;
698 case BGP_ERR_TCPSIG_FAILED:
699 str = "Error while applying TCP-Sig to session(s)";
700 break;
701 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
702 str = "ebgp-multihop and ttl-security cannot be configured together";
703 break;
704 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
705 str = "ttl-security only allowed for EBGP peers";
706 break;
707 case BGP_ERR_AS_OVERRIDE:
708 str = "as-override cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
711 str = "Invalid limit for number of dynamic neighbors";
712 break;
713 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
714 str = "Dynamic neighbor listen range already exists";
715 break;
716 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
717 str = "Operation not allowed on a dynamic neighbor";
718 break;
719 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
720 str = "Operation not allowed on a directly connected neighbor";
721 break;
722 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 723 str = GR_INVALID;
724 break;
725 case BGP_ERR_GR_INVALID_CMD:
726 str = "The Graceful Restart command used is not valid at this moment.";
727 break;
728 case BGP_ERR_GR_OPERATION_FAILED:
729 str = "The Graceful Restart Operation failed due to an err.";
730 break;
731 case BGP_GR_NO_OPERATION:
732 str = GR_NO_OPER;
d62a17ae 733 break;
734 }
735 if (str) {
736 vty_out(vty, "%% %s\n", str);
737 return CMD_WARNING_CONFIG_FAILED;
738 }
739 return CMD_SUCCESS;
718e3744 740}
741
7aafcaca 742/* BGP clear sort. */
d62a17ae 743enum clear_sort {
744 clear_all,
745 clear_peer,
746 clear_group,
747 clear_external,
748 clear_as
7aafcaca
DS
749};
750
d62a17ae 751static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
752 safi_t safi, int error)
753{
754 switch (error) {
755 case BGP_ERR_AF_UNCONFIGURED:
756 vty_out(vty,
757 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 758 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 759 break;
760 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
761 vty_out(vty,
762 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
763 peer->host);
764 break;
765 default:
766 break;
767 }
7aafcaca
DS
768}
769
dc912615
DS
770static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
771 struct listnode *nnode, enum bgp_clear_type stype)
772{
773 int ret = 0;
774
775 /* if afi/.safi not specified, spin thru all of them */
776 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
777 afi_t tmp_afi;
778 safi_t tmp_safi;
779
780 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
781 if (!peer->afc[tmp_afi][tmp_safi])
782 continue;
783
784 if (stype == BGP_CLEAR_SOFT_NONE)
785 ret = peer_clear(peer, &nnode);
786 else
787 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
788 stype);
789 }
790 /* if afi specified and safi not, spin thru safis on this afi */
791 } else if (safi == SAFI_UNSPEC) {
792 safi_t tmp_safi;
793
794 for (tmp_safi = SAFI_UNICAST;
795 tmp_safi < SAFI_MAX; tmp_safi++) {
796 if (!peer->afc[afi][tmp_safi])
797 continue;
798
799 if (stype == BGP_CLEAR_SOFT_NONE)
800 ret = peer_clear(peer, &nnode);
801 else
802 ret = peer_clear_soft(peer, afi,
803 tmp_safi, stype);
804 }
805 /* both afi/safi specified, let the caller know if not defined */
806 } else {
807 if (!peer->afc[afi][safi])
808 return 1;
809
810 if (stype == BGP_CLEAR_SOFT_NONE)
811 ret = peer_clear(peer, &nnode);
812 else
813 ret = peer_clear_soft(peer, afi, safi, stype);
814 }
815
816 return ret;
817}
818
7aafcaca 819/* `clear ip bgp' functions. */
d62a17ae 820static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
821 enum clear_sort sort, enum bgp_clear_type stype,
822 const char *arg)
823{
dc912615 824 int ret = 0;
3ae8bfa5 825 bool found = false;
d62a17ae 826 struct peer *peer;
dc95985f 827
828 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 829
830 /* Clear all neighbors. */
831 /*
832 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
833 * nodes on the BGP instance as that may get freed if it is a
834 * doppelganger
d62a17ae 835 */
836 if (sort == clear_all) {
837 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 838
839 bgp_peer_gr_flags_update(peer);
840
841 if (CHECK_FLAG(peer->flags,
842 PEER_FLAG_GRACEFUL_RESTART))
843 gr_router_detected = true;
844
dc912615
DS
845 ret = bgp_peer_clear(peer, afi, safi, nnode,
846 stype);
d62a17ae 847
848 if (ret < 0)
849 bgp_clear_vty_error(vty, peer, afi, safi, ret);
5cce3f05 850
dc95985f 851 }
852
853 if (gr_router_detected &&
854 bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
855 bgp_zebra_send_capabilities(bgp, false);
856 } else if (!gr_router_detected &&
857 bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
858 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 859 }
d62a17ae 860
861 /* This is to apply read-only mode on this clear. */
862 if (stype == BGP_CLEAR_SOFT_NONE)
863 bgp->update_delay_over = 0;
864
865 return CMD_SUCCESS;
7aafcaca
DS
866 }
867
3ae8bfa5 868 /* Clear specified neighbor. */
d62a17ae 869 if (sort == clear_peer) {
870 union sockunion su;
d62a17ae 871
872 /* Make sockunion for lookup. */
873 ret = str2sockunion(arg, &su);
874 if (ret < 0) {
875 peer = peer_lookup_by_conf_if(bgp, arg);
876 if (!peer) {
877 peer = peer_lookup_by_hostname(bgp, arg);
878 if (!peer) {
879 vty_out(vty,
880 "Malformed address or name: %s\n",
881 arg);
882 return CMD_WARNING;
883 }
884 }
885 } else {
886 peer = peer_lookup(bgp, &su);
887 if (!peer) {
888 vty_out(vty,
889 "%%BGP: Unknown neighbor - \"%s\"\n",
890 arg);
891 return CMD_WARNING;
892 }
893 }
7aafcaca 894
dc95985f 895 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
896 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
897
dc912615
DS
898 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
899
900 /* if afi/safi not defined for this peer, let caller know */
901 if (ret == 1)
3ae8bfa5 902 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 903
d62a17ae 904 if (ret < 0)
905 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 906
d62a17ae 907 return CMD_SUCCESS;
7aafcaca 908 }
7aafcaca 909
3ae8bfa5 910 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 911 if (sort == clear_group) {
912 struct peer_group *group;
7aafcaca 913
d62a17ae 914 group = peer_group_lookup(bgp, arg);
915 if (!group) {
916 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
917 return CMD_WARNING;
918 }
919
920 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
dc912615 921 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 922
d62a17ae 923 if (ret < 0)
924 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
925 else
926 found = true;
d62a17ae 927 }
3ae8bfa5
PM
928
929 if (!found)
930 vty_out(vty,
931 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 932 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 933
d62a17ae 934 return CMD_SUCCESS;
7aafcaca 935 }
7aafcaca 936
3ae8bfa5 937 /* Clear all external (eBGP) neighbors. */
d62a17ae 938 if (sort == clear_external) {
939 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
940 if (peer->sort == BGP_PEER_IBGP)
941 continue;
7aafcaca 942
dc95985f 943 bgp_peer_gr_flags_update(peer);
944
945 if (CHECK_FLAG(peer->flags,
946 PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 947 gr_router_detected = true;
dc95985f 948
dc912615 949 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 950
d62a17ae 951 if (ret < 0)
952 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
953 else
954 found = true;
d62a17ae 955 }
3ae8bfa5 956
dc95985f 957 if (gr_router_detected &&
958 bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
959 bgp_zebra_send_capabilities(bgp, false);
960 } else if (!gr_router_detected &&
961 bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
962 bgp_zebra_send_capabilities(bgp, true);
963 }
964
3ae8bfa5
PM
965 if (!found)
966 vty_out(vty,
967 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 968 get_afi_safi_str(afi, safi, false));
3ae8bfa5 969
d62a17ae 970 return CMD_SUCCESS;
971 }
972
3ae8bfa5 973 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 974 if (sort == clear_as) {
3ae8bfa5 975 as_t as = strtoul(arg, NULL, 10);
d62a17ae 976
977 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
978 if (peer->as != as)
979 continue;
980
dc95985f 981 bgp_peer_gr_flags_update(peer);
982
983 if (CHECK_FLAG(peer->flags,
984 PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 985 gr_router_detected = true;
dc95985f 986
dc912615 987 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
d62a17ae 988
989 if (ret < 0)
990 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
991 else
992 found = true;
d62a17ae 993 }
3ae8bfa5 994
dc95985f 995 if (gr_router_detected &&
996 bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
997 bgp_zebra_send_capabilities(bgp, false);
998 } else if (!gr_router_detected &&
999 bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1000 bgp_zebra_send_capabilities(bgp, true);
1001 }
1002
3ae8bfa5 1003 if (!found)
d62a17ae 1004 vty_out(vty,
3ae8bfa5 1005 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 1006 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1007
d62a17ae 1008 return CMD_SUCCESS;
1009 }
1010
1011 return CMD_SUCCESS;
1012}
1013
1014static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1015 safi_t safi, enum clear_sort sort,
1016 enum bgp_clear_type stype, const char *arg)
1017{
1018 struct bgp *bgp;
1019
1020 /* BGP structure lookup. */
1021 if (name) {
1022 bgp = bgp_lookup_by_name(name);
1023 if (bgp == NULL) {
1024 vty_out(vty, "Can't find BGP instance %s\n", name);
1025 return CMD_WARNING;
1026 }
1027 } else {
1028 bgp = bgp_get_default();
1029 if (bgp == NULL) {
1030 vty_out(vty, "No BGP process is configured\n");
1031 return CMD_WARNING;
1032 }
1033 }
1034
1035 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1036}
1037
1038/* clear soft inbound */
d62a17ae 1039static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1040{
99b3ebd3
NS
1041 afi_t afi;
1042 safi_t safi;
1043
1044 FOREACH_AFI_SAFI (afi, safi)
1045 bgp_clear_vty(vty, name, afi, safi, clear_all,
1046 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1047}
1048
1049/* clear soft outbound */
d62a17ae 1050static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1051{
99b3ebd3
NS
1052 afi_t afi;
1053 safi_t safi;
1054
1055 FOREACH_AFI_SAFI (afi, safi)
1056 bgp_clear_vty(vty, name, afi, safi, clear_all,
1057 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1058}
1059
1060
f787d7a0 1061#ifndef VTYSH_EXTRACT_PL
2e4c2296 1062#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1063#endif
1064
8029b216
AK
1065DEFUN_HIDDEN (bgp_local_mac,
1066 bgp_local_mac_cmd,
093e3f23 1067 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1068 BGP_STR
1069 "Local MAC config\n"
1070 "VxLAN Network Identifier\n"
1071 "VNI number\n"
1072 "local mac\n"
1073 "mac address\n"
1074 "mac-mobility sequence\n"
1075 "seq number\n")
1076{
1077 int rv;
1078 vni_t vni;
1079 struct ethaddr mac;
1080 struct ipaddr ip;
1081 uint32_t seq;
1082 struct bgp *bgp;
1083
1084 vni = strtoul(argv[3]->arg, NULL, 10);
1085 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1086 vty_out(vty, "%% Malformed MAC address\n");
1087 return CMD_WARNING;
1088 }
1089 memset(&ip, 0, sizeof(ip));
1090 seq = strtoul(argv[7]->arg, NULL, 10);
1091
1092 bgp = bgp_get_default();
1093 if (!bgp) {
1094 vty_out(vty, "Default BGP instance is not there\n");
1095 return CMD_WARNING;
1096 }
1097
1098 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
1099 if (rv < 0) {
1100 vty_out(vty, "Internal error\n");
1101 return CMD_WARNING;
1102 }
1103
1104 return CMD_SUCCESS;
1105}
1106
1107DEFUN_HIDDEN (no_bgp_local_mac,
1108 no_bgp_local_mac_cmd,
093e3f23 1109 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1110 NO_STR
1111 BGP_STR
1112 "Local MAC config\n"
1113 "VxLAN Network Identifier\n"
1114 "VNI number\n"
1115 "local mac\n"
1116 "mac address\n")
1117{
1118 int rv;
1119 vni_t vni;
1120 struct ethaddr mac;
1121 struct ipaddr ip;
1122 struct bgp *bgp;
1123
1124 vni = strtoul(argv[4]->arg, NULL, 10);
1125 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1126 vty_out(vty, "%% Malformed MAC address\n");
1127 return CMD_WARNING;
1128 }
1129 memset(&ip, 0, sizeof(ip));
1130
1131 bgp = bgp_get_default();
1132 if (!bgp) {
1133 vty_out(vty, "Default BGP instance is not there\n");
1134 return CMD_WARNING;
1135 }
1136
ec0ab544 1137 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1138 if (rv < 0) {
1139 vty_out(vty, "Internal error\n");
1140 return CMD_WARNING;
1141 }
1142
1143 return CMD_SUCCESS;
1144}
1145
718e3744 1146DEFUN (no_synchronization,
1147 no_synchronization_cmd,
1148 "no synchronization",
1149 NO_STR
1150 "Perform IGP synchronization\n")
1151{
d62a17ae 1152 return CMD_SUCCESS;
718e3744 1153}
1154
1155DEFUN (no_auto_summary,
1156 no_auto_summary_cmd,
1157 "no auto-summary",
1158 NO_STR
1159 "Enable automatic network number summarization\n")
1160{
d62a17ae 1161 return CMD_SUCCESS;
718e3744 1162}
3d515fd9 1163
718e3744 1164/* "router bgp" commands. */
505e5056 1165DEFUN_NOSH (router_bgp,
f412b39a 1166 router_bgp_cmd,
2ed9fe4a 1167 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1168 ROUTER_STR
1169 BGP_STR
31500417
DW
1170 AS_STR
1171 BGP_INSTANCE_HELP_STR)
718e3744 1172{
d62a17ae 1173 int idx_asn = 2;
1174 int idx_view_vrf = 3;
1175 int idx_vrf = 4;
ecec9495 1176 int is_new_bgp = 0;
d62a17ae 1177 int ret;
1178 as_t as;
1179 struct bgp *bgp;
1180 const char *name = NULL;
1181 enum bgp_instance_type inst_type;
1182
1183 // "router bgp" without an ASN
1184 if (argc == 2) {
1185 // Pending: Make VRF option available for ASN less config
1186 bgp = bgp_get_default();
1187
1188 if (bgp == NULL) {
1189 vty_out(vty, "%% No BGP process is configured\n");
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 if (listcount(bm->bgp) > 1) {
996c9314 1194 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1195 return CMD_WARNING_CONFIG_FAILED;
1196 }
1197 }
1198
1199 // "router bgp X"
1200 else {
1201 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1202
1203 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1204 if (argc > 3) {
1205 name = argv[idx_vrf]->arg;
1206
9a8bdf1c
PG
1207 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1208 if (strmatch(name, VRF_DEFAULT_NAME))
1209 name = NULL;
1210 else
1211 inst_type = BGP_INSTANCE_TYPE_VRF;
1212 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1213 inst_type = BGP_INSTANCE_TYPE_VIEW;
1214 }
1215
ecec9495
AD
1216 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1217 is_new_bgp = (bgp_lookup(as, name) == NULL);
1218
5d5393b9 1219 ret = bgp_get_vty(&bgp, &as, name, inst_type);
d62a17ae 1220 switch (ret) {
d62a17ae 1221 case BGP_ERR_AS_MISMATCH:
1222 vty_out(vty, "BGP is already running; AS is %u\n", as);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 case BGP_ERR_INSTANCE_MISMATCH:
1225 vty_out(vty,
1226 "BGP instance name and AS number mismatch\n");
1227 vty_out(vty,
1228 "BGP instance is already running; AS is %u\n",
1229 as);
1230 return CMD_WARNING_CONFIG_FAILED;
1231 }
1232
3bd70bf8
PZ
1233 /*
1234 * If we just instantiated the default instance, complete
1235 * any pending VRF-VPN leaking that was configured via
1236 * earlier "router bgp X vrf FOO" blocks.
1237 */
ecec9495 1238 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1239 vpn_leak_postchange_all();
1240
48381346
CS
1241 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1242 bgp_vpn_leak_export(bgp);
d62a17ae 1243 /* Pending: handle when user tries to change a view to vrf n vv.
1244 */
1245 }
1246
0b5131c9
MK
1247 /* unset the auto created flag as the user config is now present */
1248 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1249 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1250
1251 return CMD_SUCCESS;
718e3744 1252}
1253
718e3744 1254/* "no router bgp" commands. */
1255DEFUN (no_router_bgp,
1256 no_router_bgp_cmd,
2ed9fe4a 1257 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1258 NO_STR
1259 ROUTER_STR
1260 BGP_STR
31500417
DW
1261 AS_STR
1262 BGP_INSTANCE_HELP_STR)
718e3744 1263{
d62a17ae 1264 int idx_asn = 3;
1265 int idx_vrf = 5;
1266 as_t as;
1267 struct bgp *bgp;
1268 const char *name = NULL;
718e3744 1269
d62a17ae 1270 // "no router bgp" without an ASN
1271 if (argc == 3) {
1272 // Pending: Make VRF option available for ASN less config
1273 bgp = bgp_get_default();
718e3744 1274
d62a17ae 1275 if (bgp == NULL) {
1276 vty_out(vty, "%% No BGP process is configured\n");
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
7fb21a9f 1279
d62a17ae 1280 if (listcount(bm->bgp) > 1) {
996c9314 1281 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1282 return CMD_WARNING_CONFIG_FAILED;
1283 }
0b5131c9
MK
1284
1285 if (bgp->l3vni) {
1286 vty_out(vty, "%% Please unconfigure l3vni %u",
1287 bgp->l3vni);
1288 return CMD_WARNING_CONFIG_FAILED;
1289 }
d62a17ae 1290 } else {
1291 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1292
d62a17ae 1293 if (argc > 4)
1294 name = argv[idx_vrf]->arg;
7fb21a9f 1295
d62a17ae 1296 /* Lookup bgp structure. */
1297 bgp = bgp_lookup(as, name);
1298 if (!bgp) {
1299 vty_out(vty, "%% Can't find BGP instance\n");
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
0b5131c9
MK
1302
1303 if (bgp->l3vni) {
dd5868c2 1304 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1305 bgp->l3vni);
1306 return CMD_WARNING_CONFIG_FAILED;
1307 }
dd5868c2
DS
1308
1309 /* Cannot delete default instance if vrf instances exist */
1310 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1311 struct listnode *node;
1312 struct bgp *tmp_bgp;
1313
1314 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1315 if (tmp_bgp->inst_type
1316 == BGP_INSTANCE_TYPE_VRF) {
1317 vty_out(vty,
1318 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1319 return CMD_WARNING_CONFIG_FAILED;
1320 }
1321 }
1322 }
d62a17ae 1323 }
718e3744 1324
9ecf931b
CS
1325 if (bgp_vpn_leak_unimport(bgp, vty))
1326 return CMD_WARNING_CONFIG_FAILED;
1327
d62a17ae 1328 bgp_delete(bgp);
718e3744 1329
d62a17ae 1330 return CMD_SUCCESS;
718e3744 1331}
1332
6b0655a2 1333
718e3744 1334/* BGP router-id. */
1335
f787d7a0 1336DEFPY (bgp_router_id,
718e3744 1337 bgp_router_id_cmd,
1338 "bgp router-id A.B.C.D",
1339 BGP_STR
1340 "Override configured router identifier\n"
1341 "Manually configured router identifier\n")
1342{
d62a17ae 1343 VTY_DECLVAR_CONTEXT(bgp, bgp);
1344 bgp_router_id_static_set(bgp, router_id);
1345 return CMD_SUCCESS;
718e3744 1346}
1347
f787d7a0 1348DEFPY (no_bgp_router_id,
718e3744 1349 no_bgp_router_id_cmd,
31500417 1350 "no bgp router-id [A.B.C.D]",
718e3744 1351 NO_STR
1352 BGP_STR
31500417
DW
1353 "Override configured router identifier\n"
1354 "Manually configured router identifier\n")
718e3744 1355{
d62a17ae 1356 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1357
d62a17ae 1358 if (router_id_str) {
1359 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1360 vty_out(vty, "%% BGP router-id doesn't match\n");
1361 return CMD_WARNING_CONFIG_FAILED;
1362 }
e018c7cc 1363 }
718e3744 1364
d62a17ae 1365 router_id.s_addr = 0;
1366 bgp_router_id_static_set(bgp, router_id);
718e3744 1367
d62a17ae 1368 return CMD_SUCCESS;
718e3744 1369}
1370
6b0655a2 1371
718e3744 1372/* BGP Cluster ID. */
718e3744 1373DEFUN (bgp_cluster_id,
1374 bgp_cluster_id_cmd,
838758ac 1375 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1376 BGP_STR
1377 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1378 "Route-Reflector Cluster-id in IP address format\n"
1379 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1380{
d62a17ae 1381 VTY_DECLVAR_CONTEXT(bgp, bgp);
1382 int idx_ipv4 = 2;
1383 int ret;
1384 struct in_addr cluster;
718e3744 1385
d62a17ae 1386 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1387 if (!ret) {
1388 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1389 return CMD_WARNING_CONFIG_FAILED;
1390 }
718e3744 1391
d62a17ae 1392 bgp_cluster_id_set(bgp, &cluster);
1393 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1394
d62a17ae 1395 return CMD_SUCCESS;
718e3744 1396}
1397
718e3744 1398DEFUN (no_bgp_cluster_id,
1399 no_bgp_cluster_id_cmd,
c7178fe7 1400 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1401 NO_STR
1402 BGP_STR
838758ac
DW
1403 "Configure Route-Reflector Cluster-id\n"
1404 "Route-Reflector Cluster-id in IP address format\n"
1405 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1406{
d62a17ae 1407 VTY_DECLVAR_CONTEXT(bgp, bgp);
1408 bgp_cluster_id_unset(bgp);
1409 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1410
d62a17ae 1411 return CMD_SUCCESS;
718e3744 1412}
1413
718e3744 1414DEFUN (bgp_confederation_identifier,
1415 bgp_confederation_identifier_cmd,
9ccf14f7 1416 "bgp confederation identifier (1-4294967295)",
718e3744 1417 "BGP specific commands\n"
1418 "AS confederation parameters\n"
1419 "AS number\n"
1420 "Set routing domain confederation AS\n")
1421{
d62a17ae 1422 VTY_DECLVAR_CONTEXT(bgp, bgp);
1423 int idx_number = 3;
1424 as_t as;
718e3744 1425
d62a17ae 1426 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1427
d62a17ae 1428 bgp_confederation_id_set(bgp, as);
718e3744 1429
d62a17ae 1430 return CMD_SUCCESS;
718e3744 1431}
1432
1433DEFUN (no_bgp_confederation_identifier,
1434 no_bgp_confederation_identifier_cmd,
838758ac 1435 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1436 NO_STR
1437 "BGP specific commands\n"
1438 "AS confederation parameters\n"
3a2d747c
QY
1439 "AS number\n"
1440 "Set routing domain confederation AS\n")
718e3744 1441{
d62a17ae 1442 VTY_DECLVAR_CONTEXT(bgp, bgp);
1443 bgp_confederation_id_unset(bgp);
718e3744 1444
d62a17ae 1445 return CMD_SUCCESS;
718e3744 1446}
1447
718e3744 1448DEFUN (bgp_confederation_peers,
1449 bgp_confederation_peers_cmd,
12dcf78e 1450 "bgp confederation peers (1-4294967295)...",
718e3744 1451 "BGP specific commands\n"
1452 "AS confederation parameters\n"
1453 "Peer ASs in BGP confederation\n"
1454 AS_STR)
1455{
d62a17ae 1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457 int idx_asn = 3;
1458 as_t as;
1459 int i;
718e3744 1460
d62a17ae 1461 for (i = idx_asn; i < argc; i++) {
1462 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1463
d62a17ae 1464 if (bgp->as == as) {
1465 vty_out(vty,
1466 "%% Local member-AS not allowed in confed peer list\n");
1467 continue;
1468 }
718e3744 1469
d62a17ae 1470 bgp_confederation_peers_add(bgp, as);
1471 }
1472 return CMD_SUCCESS;
718e3744 1473}
1474
1475DEFUN (no_bgp_confederation_peers,
1476 no_bgp_confederation_peers_cmd,
e83a9414 1477 "no bgp confederation peers (1-4294967295)...",
718e3744 1478 NO_STR
1479 "BGP specific commands\n"
1480 "AS confederation parameters\n"
1481 "Peer ASs in BGP confederation\n"
1482 AS_STR)
1483{
d62a17ae 1484 VTY_DECLVAR_CONTEXT(bgp, bgp);
1485 int idx_asn = 4;
1486 as_t as;
1487 int i;
718e3744 1488
d62a17ae 1489 for (i = idx_asn; i < argc; i++) {
1490 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1491
d62a17ae 1492 bgp_confederation_peers_remove(bgp, as);
1493 }
1494 return CMD_SUCCESS;
718e3744 1495}
6b0655a2 1496
5e242b0d
DS
1497/**
1498 * Central routine for maximum-paths configuration.
1499 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1500 * @set: 1 for setting values, 0 for removing the max-paths config.
1501 */
d62a17ae 1502static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1503 const char *mpaths, uint16_t options,
d62a17ae 1504 int set)
1505{
1506 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1507 uint16_t maxpaths = 0;
d62a17ae 1508 int ret;
1509 afi_t afi;
1510 safi_t safi;
1511
1512 afi = bgp_node_afi(vty);
1513 safi = bgp_node_safi(vty);
1514
1515 if (set) {
1516 maxpaths = strtol(mpaths, NULL, 10);
1517 if (maxpaths > multipath_num) {
1518 vty_out(vty,
1519 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1520 maxpaths, multipath_num);
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1524 options);
1525 } else
1526 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1527
1528 if (ret < 0) {
1529 vty_out(vty,
1530 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1531 (set == 1) ? "" : "un",
1532 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1533 maxpaths, afi, safi);
1534 return CMD_WARNING_CONFIG_FAILED;
1535 }
1536
1537 bgp_recalculate_all_bestpaths(bgp);
1538
1539 return CMD_SUCCESS;
165b5fff
JB
1540}
1541
abc920f8
DS
1542DEFUN (bgp_maxmed_admin,
1543 bgp_maxmed_admin_cmd,
1544 "bgp max-med administrative ",
1545 BGP_STR
1546 "Advertise routes with max-med\n"
1547 "Administratively applied, for an indefinite period\n")
1548{
d62a17ae 1549 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1550
d62a17ae 1551 bgp->v_maxmed_admin = 1;
1552 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1553
d62a17ae 1554 bgp_maxmed_update(bgp);
abc920f8 1555
d62a17ae 1556 return CMD_SUCCESS;
abc920f8
DS
1557}
1558
1559DEFUN (bgp_maxmed_admin_medv,
1560 bgp_maxmed_admin_medv_cmd,
4668a151 1561 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1562 BGP_STR
1563 "Advertise routes with max-med\n"
1564 "Administratively applied, for an indefinite period\n"
1565 "Max MED value to be used\n")
1566{
d62a17ae 1567 VTY_DECLVAR_CONTEXT(bgp, bgp);
1568 int idx_number = 3;
abc920f8 1569
d62a17ae 1570 bgp->v_maxmed_admin = 1;
1571 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1572
d62a17ae 1573 bgp_maxmed_update(bgp);
abc920f8 1574
d62a17ae 1575 return CMD_SUCCESS;
abc920f8
DS
1576}
1577
1578DEFUN (no_bgp_maxmed_admin,
1579 no_bgp_maxmed_admin_cmd,
4668a151 1580 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1581 NO_STR
1582 BGP_STR
1583 "Advertise routes with max-med\n"
838758ac
DW
1584 "Administratively applied, for an indefinite period\n"
1585 "Max MED value to be used\n")
abc920f8 1586{
d62a17ae 1587 VTY_DECLVAR_CONTEXT(bgp, bgp);
1588 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1589 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1590 bgp_maxmed_update(bgp);
abc920f8 1591
d62a17ae 1592 return CMD_SUCCESS;
abc920f8
DS
1593}
1594
abc920f8
DS
1595DEFUN (bgp_maxmed_onstartup,
1596 bgp_maxmed_onstartup_cmd,
4668a151 1597 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1598 BGP_STR
1599 "Advertise routes with max-med\n"
1600 "Effective on a startup\n"
1601 "Time (seconds) period for max-med\n"
1602 "Max MED value to be used\n")
1603{
d62a17ae 1604 VTY_DECLVAR_CONTEXT(bgp, bgp);
1605 int idx = 0;
4668a151 1606
d62a17ae 1607 argv_find(argv, argc, "(5-86400)", &idx);
1608 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1609 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1610 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1611 else
1612 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1613
d62a17ae 1614 bgp_maxmed_update(bgp);
abc920f8 1615
d62a17ae 1616 return CMD_SUCCESS;
abc920f8
DS
1617}
1618
1619DEFUN (no_bgp_maxmed_onstartup,
1620 no_bgp_maxmed_onstartup_cmd,
4668a151 1621 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1622 NO_STR
1623 BGP_STR
1624 "Advertise routes with max-med\n"
838758ac
DW
1625 "Effective on a startup\n"
1626 "Time (seconds) period for max-med\n"
1627 "Max MED value to be used\n")
abc920f8 1628{
d62a17ae 1629 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1630
d62a17ae 1631 /* Cancel max-med onstartup if its on */
1632 if (bgp->t_maxmed_onstartup) {
1633 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1634 bgp->maxmed_onstartup_over = 1;
1635 }
abc920f8 1636
d62a17ae 1637 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1638 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1639
d62a17ae 1640 bgp_maxmed_update(bgp);
abc920f8 1641
d62a17ae 1642 return CMD_SUCCESS;
abc920f8
DS
1643}
1644
d62a17ae 1645static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1646 const char *wait)
f188f2c4 1647{
d62a17ae 1648 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1649 uint16_t update_delay;
1650 uint16_t establish_wait;
f188f2c4 1651
d62a17ae 1652 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1653
d62a17ae 1654 if (!wait) /* update-delay <delay> */
1655 {
1656 bgp->v_update_delay = update_delay;
1657 bgp->v_establish_wait = bgp->v_update_delay;
1658 return CMD_SUCCESS;
1659 }
f188f2c4 1660
d62a17ae 1661 /* update-delay <delay> <establish-wait> */
1662 establish_wait = atoi(wait);
1663 if (update_delay < establish_wait) {
1664 vty_out(vty,
1665 "%%Failed: update-delay less than the establish-wait!\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
f188f2c4 1668
d62a17ae 1669 bgp->v_update_delay = update_delay;
1670 bgp->v_establish_wait = establish_wait;
f188f2c4 1671
d62a17ae 1672 return CMD_SUCCESS;
f188f2c4
DS
1673}
1674
d62a17ae 1675static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1676{
d62a17ae 1677 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1678
d62a17ae 1679 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1680 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1681
d62a17ae 1682 return CMD_SUCCESS;
f188f2c4
DS
1683}
1684
2b791107 1685void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1686{
d62a17ae 1687 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1688 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1689 if (bgp->v_update_delay != bgp->v_establish_wait)
1690 vty_out(vty, " %d", bgp->v_establish_wait);
1691 vty_out(vty, "\n");
1692 }
f188f2c4
DS
1693}
1694
1695
1696/* Update-delay configuration */
1697DEFUN (bgp_update_delay,
1698 bgp_update_delay_cmd,
6147e2c6 1699 "update-delay (0-3600)",
f188f2c4
DS
1700 "Force initial delay for best-path and updates\n"
1701 "Seconds\n")
1702{
d62a17ae 1703 int idx_number = 1;
1704 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1705}
1706
1707DEFUN (bgp_update_delay_establish_wait,
1708 bgp_update_delay_establish_wait_cmd,
6147e2c6 1709 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1710 "Force initial delay for best-path and updates\n"
1711 "Seconds\n"
f188f2c4
DS
1712 "Seconds\n")
1713{
d62a17ae 1714 int idx_number = 1;
1715 int idx_number_2 = 2;
1716 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1717 argv[idx_number_2]->arg);
f188f2c4
DS
1718}
1719
1720/* Update-delay deconfiguration */
1721DEFUN (no_bgp_update_delay,
1722 no_bgp_update_delay_cmd,
838758ac
DW
1723 "no update-delay [(0-3600) [(1-3600)]]",
1724 NO_STR
f188f2c4 1725 "Force initial delay for best-path and updates\n"
838758ac 1726 "Seconds\n"
7111c1a0 1727 "Seconds\n")
f188f2c4 1728{
d62a17ae 1729 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1730}
1731
5e242b0d 1732
8fa7732f
QY
1733static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1734 bool set)
cb1faec9 1735{
d62a17ae 1736 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1737
8fa7732f
QY
1738 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1739 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1740
1741 return CMD_SUCCESS;
1742}
1743
8fa7732f
QY
1744static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1745 bool set)
555e09d4
QY
1746{
1747 VTY_DECLVAR_CONTEXT(bgp, bgp);
1748
8fa7732f
QY
1749 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1750 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1751
d62a17ae 1752 return CMD_SUCCESS;
cb1faec9
DS
1753}
1754
2b791107 1755void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1756{
555e09d4
QY
1757 uint32_t quanta =
1758 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1759 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1760 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1761}
1762
555e09d4
QY
1763void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1764{
1765 uint32_t quanta =
1766 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1767 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1768 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1769}
cb1faec9 1770
8fa7732f
QY
1771/* Packet quanta configuration
1772 *
1773 * XXX: The value set here controls the size of a stack buffer in the IO
1774 * thread. When changing these limits be careful to prevent stack overflow.
1775 *
1776 * Furthermore, the maximums used here should correspond to
1777 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1778 */
1779DEFPY (bgp_wpkt_quanta,
cb1faec9 1780 bgp_wpkt_quanta_cmd,
8fa7732f 1781 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1782 NO_STR
8fa7732f 1783 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1784 "Number of packets\n")
1785{
8fa7732f 1786 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1787}
1788
8fa7732f 1789DEFPY (bgp_rpkt_quanta,
555e09d4 1790 bgp_rpkt_quanta_cmd,
8fa7732f 1791 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1792 NO_STR
1793 "How many packets to read from peer socket per I/O cycle\n"
1794 "Number of packets\n")
1795{
8fa7732f 1796 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1797}
1798
2b791107 1799void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1800{
37a333fe 1801 if (!bgp->heuristic_coalesce)
d62a17ae 1802 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1803}
1804
1805
1806DEFUN (bgp_coalesce_time,
1807 bgp_coalesce_time_cmd,
6147e2c6 1808 "coalesce-time (0-4294967295)",
3f9c7369
DS
1809 "Subgroup coalesce timer\n"
1810 "Subgroup coalesce timer value (in ms)\n")
1811{
d62a17ae 1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1813
d62a17ae 1814 int idx = 0;
1815 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1816 bgp->heuristic_coalesce = false;
d62a17ae 1817 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1818 return CMD_SUCCESS;
3f9c7369
DS
1819}
1820
1821DEFUN (no_bgp_coalesce_time,
1822 no_bgp_coalesce_time_cmd,
6147e2c6 1823 "no coalesce-time (0-4294967295)",
3a2d747c 1824 NO_STR
3f9c7369
DS
1825 "Subgroup coalesce timer\n"
1826 "Subgroup coalesce timer value (in ms)\n")
1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1829
37a333fe 1830 bgp->heuristic_coalesce = true;
d62a17ae 1831 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1832 return CMD_SUCCESS;
3f9c7369
DS
1833}
1834
5e242b0d
DS
1835/* Maximum-paths configuration */
1836DEFUN (bgp_maxpaths,
1837 bgp_maxpaths_cmd,
6319fd63 1838 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1839 "Forward packets over multiple paths\n"
1840 "Number of paths\n")
1841{
d62a17ae 1842 int idx_number = 1;
1843 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1844 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1845}
1846
d62a17ae 1847ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1848 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1849 "Forward packets over multiple paths\n"
1850 "Number of paths\n")
596c17ba 1851
165b5fff
JB
1852DEFUN (bgp_maxpaths_ibgp,
1853 bgp_maxpaths_ibgp_cmd,
6319fd63 1854 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1855 "Forward packets over multiple paths\n"
1856 "iBGP-multipath\n"
1857 "Number of paths\n")
1858{
d62a17ae 1859 int idx_number = 2;
1860 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1861 argv[idx_number]->arg, 0, 1);
5e242b0d 1862}
165b5fff 1863
d62a17ae 1864ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1865 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1866 "Forward packets over multiple paths\n"
1867 "iBGP-multipath\n"
1868 "Number of paths\n")
596c17ba 1869
5e242b0d
DS
1870DEFUN (bgp_maxpaths_ibgp_cluster,
1871 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1872 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1873 "Forward packets over multiple paths\n"
1874 "iBGP-multipath\n"
1875 "Number of paths\n"
1876 "Match the cluster length\n")
1877{
d62a17ae 1878 int idx_number = 2;
1879 return bgp_maxpaths_config_vty(
1880 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1881 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1882}
1883
d62a17ae 1884ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1885 "maximum-paths ibgp " CMD_RANGE_STR(
1886 1, MULTIPATH_NUM) " equal-cluster-length",
1887 "Forward packets over multiple paths\n"
1888 "iBGP-multipath\n"
1889 "Number of paths\n"
1890 "Match the cluster length\n")
596c17ba 1891
165b5fff
JB
1892DEFUN (no_bgp_maxpaths,
1893 no_bgp_maxpaths_cmd,
6319fd63 1894 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1895 NO_STR
1896 "Forward packets over multiple paths\n"
1897 "Number of paths\n")
1898{
d62a17ae 1899 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1900}
1901
d62a17ae 1902ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1903 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1904 "Forward packets over multiple paths\n"
1905 "Number of paths\n")
596c17ba 1906
165b5fff
JB
1907DEFUN (no_bgp_maxpaths_ibgp,
1908 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1909 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1910 NO_STR
1911 "Forward packets over multiple paths\n"
1912 "iBGP-multipath\n"
838758ac
DW
1913 "Number of paths\n"
1914 "Match the cluster length\n")
165b5fff 1915{
d62a17ae 1916 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1917}
1918
d62a17ae 1919ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1920 "no maximum-paths ibgp [" CMD_RANGE_STR(
1921 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1922 NO_STR
1923 "Forward packets over multiple paths\n"
1924 "iBGP-multipath\n"
1925 "Number of paths\n"
1926 "Match the cluster length\n")
596c17ba 1927
dd65f45e
DL
1928static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1929 afi_t afi, safi_t safi)
165b5fff 1930{
d62a17ae 1931 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1932 vty_out(vty, " maximum-paths %d\n",
1933 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1934 }
165b5fff 1935
d62a17ae 1936 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1937 vty_out(vty, " maximum-paths ibgp %d",
1938 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1939 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1940 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1941 vty_out(vty, " equal-cluster-length");
1942 vty_out(vty, "\n");
1943 }
165b5fff 1944}
6b0655a2 1945
718e3744 1946/* BGP timers. */
1947
1948DEFUN (bgp_timers,
1949 bgp_timers_cmd,
6147e2c6 1950 "timers bgp (0-65535) (0-65535)",
718e3744 1951 "Adjust routing timers\n"
1952 "BGP timers\n"
1953 "Keepalive interval\n"
1954 "Holdtime\n")
1955{
d62a17ae 1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957 int idx_number = 2;
1958 int idx_number_2 = 3;
1959 unsigned long keepalive = 0;
1960 unsigned long holdtime = 0;
718e3744 1961
d62a17ae 1962 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1963 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1964
d62a17ae 1965 /* Holdtime value check. */
1966 if (holdtime < 3 && holdtime != 0) {
1967 vty_out(vty,
1968 "%% hold time value must be either 0 or greater than 3\n");
1969 return CMD_WARNING_CONFIG_FAILED;
1970 }
718e3744 1971
5d5393b9 1972 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
718e3744 1973
d62a17ae 1974 return CMD_SUCCESS;
718e3744 1975}
1976
1977DEFUN (no_bgp_timers,
1978 no_bgp_timers_cmd,
838758ac 1979 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1980 NO_STR
1981 "Adjust routing timers\n"
838758ac
DW
1982 "BGP timers\n"
1983 "Keepalive interval\n"
1984 "Holdtime\n")
718e3744 1985{
d62a17ae 1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
5d5393b9
DL
1987 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1988 DFLT_BGP_CONNECT_RETRY);
718e3744 1989
d62a17ae 1990 return CMD_SUCCESS;
718e3744 1991}
1992
6b0655a2 1993
718e3744 1994DEFUN (bgp_client_to_client_reflection,
1995 bgp_client_to_client_reflection_cmd,
1996 "bgp client-to-client reflection",
1997 "BGP specific commands\n"
1998 "Configure client to client route reflection\n"
1999 "reflection of routes allowed\n")
2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2003 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2004
d62a17ae 2005 return CMD_SUCCESS;
718e3744 2006}
2007
2008DEFUN (no_bgp_client_to_client_reflection,
2009 no_bgp_client_to_client_reflection_cmd,
2010 "no bgp client-to-client reflection",
2011 NO_STR
2012 "BGP specific commands\n"
2013 "Configure client to client route reflection\n"
2014 "reflection of routes allowed\n")
2015{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2018 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2019
d62a17ae 2020 return CMD_SUCCESS;
718e3744 2021}
2022
2023/* "bgp always-compare-med" configuration. */
2024DEFUN (bgp_always_compare_med,
2025 bgp_always_compare_med_cmd,
2026 "bgp always-compare-med",
2027 "BGP specific commands\n"
2028 "Allow comparing MED from different neighbors\n")
2029{
d62a17ae 2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
2032 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2033
d62a17ae 2034 return CMD_SUCCESS;
718e3744 2035}
2036
2037DEFUN (no_bgp_always_compare_med,
2038 no_bgp_always_compare_med_cmd,
2039 "no bgp always-compare-med",
2040 NO_STR
2041 "BGP specific commands\n"
2042 "Allow comparing MED from different neighbors\n")
2043{
d62a17ae 2044 VTY_DECLVAR_CONTEXT(bgp, bgp);
2045 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
2046 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2047
d62a17ae 2048 return CMD_SUCCESS;
718e3744 2049}
6b0655a2 2050
9dac9fc8
DA
2051
2052DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2053 "bgp ebgp-requires-policy",
2054 "BGP specific commands\n"
2055 "Require in and out policy for eBGP peers (RFC8212)\n")
2056{
2057 VTY_DECLVAR_CONTEXT(bgp, bgp);
2058 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
2059 return CMD_SUCCESS;
2060}
2061
2062DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2063 "no bgp ebgp-requires-policy",
2064 NO_STR
2065 "BGP specific commands\n"
2066 "Require in and out policy for eBGP peers (RFC8212)\n")
2067{
2068 VTY_DECLVAR_CONTEXT(bgp, bgp);
2069 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
2070 return CMD_SUCCESS;
2071}
2072
fb29348a
DA
2073DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2074 "bgp reject-as-sets",
2075 "BGP specific commands\n"
2076 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2077{
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 struct listnode *node, *nnode;
2080 struct peer *peer;
2081
2082 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
2083
2084 /* Reset existing BGP sessions to reject routes
2085 * with aspath containing AS_SET or AS_CONFED_SET.
2086 */
2087 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2088 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2089 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2090 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2091 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2092 }
2093 }
2094
2095 return CMD_SUCCESS;
2096}
2097
2098DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2099 "no bgp reject-as-sets",
2100 NO_STR
2101 "BGP specific commands\n"
2102 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2103{
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105 struct listnode *node, *nnode;
2106 struct peer *peer;
2107
2108 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
2109
2110 /* Reset existing BGP sessions to reject routes
2111 * with aspath containing AS_SET or AS_CONFED_SET.
2112 */
2113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2114 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2115 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2116 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2117 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2118 }
2119 }
2120
2121 return CMD_SUCCESS;
2122}
9dac9fc8 2123
718e3744 2124/* "bgp deterministic-med" configuration. */
2125DEFUN (bgp_deterministic_med,
2126 bgp_deterministic_med_cmd,
2127 "bgp deterministic-med",
2128 "BGP specific commands\n"
2129 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2130{
d62a17ae 2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 2132
d62a17ae 2133 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
2134 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
2135 bgp_recalculate_all_bestpaths(bgp);
2136 }
7aafcaca 2137
d62a17ae 2138 return CMD_SUCCESS;
718e3744 2139}
2140
2141DEFUN (no_bgp_deterministic_med,
2142 no_bgp_deterministic_med_cmd,
2143 "no bgp deterministic-med",
2144 NO_STR
2145 "BGP specific commands\n"
2146 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2147{
d62a17ae 2148 VTY_DECLVAR_CONTEXT(bgp, bgp);
2149 int bestpath_per_as_used;
2150 afi_t afi;
2151 safi_t safi;
2152 struct peer *peer;
2153 struct listnode *node, *nnode;
2154
2155 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
2156 bestpath_per_as_used = 0;
2157
2158 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2159 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2160 if (bgp_addpath_dmed_required(
2161 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2162 bestpath_per_as_used = 1;
2163 break;
2164 }
d62a17ae 2165
2166 if (bestpath_per_as_used)
2167 break;
2168 }
2169
2170 if (bestpath_per_as_used) {
2171 vty_out(vty,
2172 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2173 return CMD_WARNING_CONFIG_FAILED;
2174 } else {
2175 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
2176 bgp_recalculate_all_bestpaths(bgp);
2177 }
2178 }
2179
2180 return CMD_SUCCESS;
718e3744 2181}
538621f2 2182
055679e9 2183/* "bgp graceful-restart mode" configuration. */
538621f2 2184DEFUN (bgp_graceful_restart,
2ba1fe69 2185 bgp_graceful_restart_cmd,
2186 "bgp graceful-restart",
2187 "BGP specific commands\n"
2188 GR_CMD
055679e9 2189 )
538621f2 2190{
055679e9 2191 int ret = BGP_GR_FAILURE;
2192
2193 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2194 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2195
d62a17ae 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2197
2198 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2199
dc95985f 2200 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2201 bgp->peer, ret);
5cce3f05 2202
055679e9 2203 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2204 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2205 vty_out(vty,
2206 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2207 return bgp_vty_return(vty, ret);
538621f2 2208}
2209
2210DEFUN (no_bgp_graceful_restart,
2ba1fe69 2211 no_bgp_graceful_restart_cmd,
2212 "no bgp graceful-restart",
2213 NO_STR
2214 "BGP specific commands\n"
2215 NO_GR_CMD
055679e9 2216 )
538621f2 2217{
d62a17ae 2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2219
2220 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2221 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2222
2223 int ret = BGP_GR_FAILURE;
2224
2225 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2226
dc95985f 2227 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2228 bgp->peer, ret);
5cce3f05 2229
055679e9 2230 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2231 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2232 vty_out(vty,
2233 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2234
2235 return bgp_vty_return(vty, ret);
538621f2 2236}
2237
93406d87 2238DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2239 bgp_graceful_restart_stalepath_time_cmd,
2240 "bgp graceful-restart stalepath-time (1-4095)",
2241 "BGP specific commands\n"
2242 "Graceful restart capability parameters\n"
2243 "Set the max time to hold onto restarting peer's stale paths\n"
2244 "Delay value (seconds)\n")
93406d87 2245{
d62a17ae 2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx_number = 3;
d7c0a89a 2248 uint32_t stalepath;
93406d87 2249
d62a17ae 2250 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2251 bgp->stalepath_time = stalepath;
2252 return CMD_SUCCESS;
93406d87 2253}
2254
eb6f1b41 2255DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2256 bgp_graceful_restart_restart_time_cmd,
2257 "bgp graceful-restart restart-time (1-4095)",
2258 "BGP specific commands\n"
2259 "Graceful restart capability parameters\n"
2260 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2261 "Delay value (seconds)\n")
eb6f1b41 2262{
d62a17ae 2263 VTY_DECLVAR_CONTEXT(bgp, bgp);
2264 int idx_number = 3;
d7c0a89a 2265 uint32_t restart;
eb6f1b41 2266
d62a17ae 2267 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2268 bgp->restart_time = restart;
2269 return CMD_SUCCESS;
eb6f1b41
PG
2270}
2271
cfd47646 2272DEFUN (bgp_graceful_restart_select_defer_time,
2273 bgp_graceful_restart_select_defer_time_cmd,
2274 "bgp graceful-restart select-defer-time (0-3600)",
2275 "BGP specific commands\n"
2276 "Graceful restart capability parameters\n"
2277 "Set the time to defer the BGP route selection after restart\n"
2278 "Delay value (seconds, 0 - disable)\n")
2279{
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 int idx_number = 3;
2282 uint32_t defer_time;
2283
2284 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2285 bgp->select_defer_time = defer_time;
2286 if (defer_time == 0)
2287 bgp_flag_set(bgp, BGP_FLAG_SELECT_DEFER_DISABLE);
2288 else
2289 bgp_flag_unset(bgp, BGP_FLAG_SELECT_DEFER_DISABLE);
2290
2291 return CMD_SUCCESS;
2292}
2293
93406d87 2294DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2295 no_bgp_graceful_restart_stalepath_time_cmd,
2296 "no bgp graceful-restart stalepath-time [(1-4095)]",
2297 NO_STR
2298 "BGP specific commands\n"
2299 "Graceful restart capability parameters\n"
2300 "Set the max time to hold onto restarting peer's stale paths\n"
2301 "Delay value (seconds)\n")
93406d87 2302{
d62a17ae 2303 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2304
d62a17ae 2305 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2306 return CMD_SUCCESS;
93406d87 2307}
2308
eb6f1b41 2309DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2310 no_bgp_graceful_restart_restart_time_cmd,
2311 "no bgp graceful-restart restart-time [(1-4095)]",
2312 NO_STR
2313 "BGP specific commands\n"
2314 "Graceful restart capability parameters\n"
2315 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2316 "Delay value (seconds)\n")
eb6f1b41 2317{
d62a17ae 2318 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2319
d62a17ae 2320 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2321 return CMD_SUCCESS;
eb6f1b41
PG
2322}
2323
cfd47646 2324DEFUN (no_bgp_graceful_restart_select_defer_time,
2325 no_bgp_graceful_restart_select_defer_time_cmd,
2326 "no bgp graceful-restart select-defer-time [(0-3600)]",
2327 NO_STR
2328 "BGP specific commands\n"
2329 "Graceful restart capability parameters\n"
2330 "Set the time to defer the BGP route selection after restart\n"
2331 "Delay value (seconds)\n")
2332{
2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334
2335 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2336 bgp_flag_unset(bgp, BGP_FLAG_SELECT_DEFER_DISABLE);
2337
2338 return CMD_SUCCESS;
2339}
2340
43fc21b3 2341DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2342 bgp_graceful_restart_preserve_fw_cmd,
2343 "bgp graceful-restart preserve-fw-state",
2344 "BGP specific commands\n"
2345 "Graceful restart capability parameters\n"
2346 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2347{
d62a17ae 2348 VTY_DECLVAR_CONTEXT(bgp, bgp);
2349 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2350 return CMD_SUCCESS;
43fc21b3
JC
2351}
2352
2353DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2354 no_bgp_graceful_restart_preserve_fw_cmd,
2355 "no bgp graceful-restart preserve-fw-state",
2356 NO_STR
2357 "BGP specific commands\n"
2358 "Graceful restart capability parameters\n"
2359 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2360{
d62a17ae 2361 VTY_DECLVAR_CONTEXT(bgp, bgp);
2362 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2363 return CMD_SUCCESS;
43fc21b3
JC
2364}
2365
055679e9 2366DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2367 bgp_graceful_restart_disable_cmd,
2368 "bgp graceful-restart-disable",
2369 "BGP specific commands\n"
2370 GR_DISABLE)
055679e9 2371{
2372 int ret = BGP_GR_FAILURE;
2373
2374 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2375 zlog_debug(
2ba1fe69 2376 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2377
055679e9 2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379
2380 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2381
dc95985f 2382 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2383 bgp->peer, ret);
5cce3f05 2384
055679e9 2385 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2386 zlog_debug(
2ba1fe69 2387 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2388 vty_out(vty,
2389 "Graceful restart configuration changed, reset all peers to take effect\n");
2390
055679e9 2391 return bgp_vty_return(vty, ret);
2392}
2393
2394DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2395 no_bgp_graceful_restart_disable_cmd,
2396 "no bgp graceful-restart-disable",
2397 NO_STR
2398 "BGP specific commands\n"
2399 NO_GR_DISABLE
055679e9 2400 )
2401{
2402 VTY_DECLVAR_CONTEXT(bgp, bgp);
2403
2404 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2405 zlog_debug(
2ba1fe69 2406 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2407
2408 int ret = BGP_GR_FAILURE;
2409
2410 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2411
dc95985f 2412 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2413 bgp->peer, ret);
5cce3f05 2414
055679e9 2415 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2416 zlog_debug(
2ba1fe69 2417 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2418 vty_out(vty,
2419 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2420
2421 return bgp_vty_return(vty, ret);
2422}
2423
2424DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2425 bgp_neighbor_graceful_restart_set_cmd,
2426 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2427 NEIGHBOR_STR
2428 NEIGHBOR_ADDR_STR2
2429 GR_NEIGHBOR_CMD
055679e9 2430 )
2431{
2432 int idx_peer = 1;
2433 struct peer *peer;
2434 int ret = BGP_GR_FAILURE;
2435
dc95985f 2436 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2437
055679e9 2438 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2439 zlog_debug(
2ba1fe69 2440 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2441
055679e9 2442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2443 if (!peer)
2444 return CMD_WARNING_CONFIG_FAILED;
2445
2446 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2447
dc95985f 2448 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2449 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2450
2451 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2452 zlog_debug(
2ba1fe69 2453 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2454 vty_out(vty,
2455 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2456
2457 return bgp_vty_return(vty, ret);
2458}
2459
2460DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2461 no_bgp_neighbor_graceful_restart_set_cmd,
2462 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2463 NO_STR
2464 NEIGHBOR_STR
2465 NEIGHBOR_ADDR_STR2
2466 NO_GR_NEIGHBOR_CMD
055679e9 2467 )
2468{
2469 int idx_peer = 2;
2470 int ret = BGP_GR_FAILURE;
2471 struct peer *peer;
2472
dc95985f 2473 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2474
055679e9 2475 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2476 if (!peer)
2477 return CMD_WARNING_CONFIG_FAILED;
2478
2479 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2480 zlog_debug(
2ba1fe69 2481 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2482
2483 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2484
dc95985f 2485 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2486 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2487
2488 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2489 zlog_debug(
2ba1fe69 2490 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2491 vty_out(vty,
2492 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2493
2494 return bgp_vty_return(vty, ret);
2495}
2496
2497DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2498 bgp_neighbor_graceful_restart_helper_set_cmd,
2499 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2500 NEIGHBOR_STR
2501 NEIGHBOR_ADDR_STR2
2502 GR_NEIGHBOR_HELPER_CMD
055679e9 2503 )
2504{
2505 int idx_peer = 1;
2506 struct peer *peer;
2507 int ret = BGP_GR_FAILURE;
2508
dc95985f 2509 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2510
055679e9 2511 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2512 zlog_debug(
2ba1fe69 2513 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2514
055679e9 2515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2516
055679e9 2517 if (!peer)
2518 return CMD_WARNING_CONFIG_FAILED;
2519
2520
2521 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2522
dc95985f 2523 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2524 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2525
055679e9 2526 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2527 zlog_debug(
2ba1fe69 2528 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2529 vty_out(vty,
2530 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2531
2532 return bgp_vty_return(vty, ret);
2533}
2534
2535DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2536 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2537 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2538 NO_STR
2539 NEIGHBOR_STR
2540 NEIGHBOR_ADDR_STR2
2541 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2542 )
2543{
2544 int idx_peer = 2;
2545 int ret = BGP_GR_FAILURE;
2546 struct peer *peer;
2547
dc95985f 2548 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2549
055679e9 2550 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2551 if (!peer)
2552 return CMD_WARNING_CONFIG_FAILED;
2553
2554 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2555 zlog_debug(
2ba1fe69 2556 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2557
2558 ret = bgp_neighbor_graceful_restart(peer,
2559 NO_PEER_HELPER_CMD);
2560
dc95985f 2561 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2562 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2563
2564 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2565 zlog_debug(
2ba1fe69 2566 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2567 vty_out(vty,
2568 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2569
2570 return bgp_vty_return(vty, ret);
2571}
2572
2573DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2574 bgp_neighbor_graceful_restart_disable_set_cmd,
2575 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2576 NEIGHBOR_STR
2577 NEIGHBOR_ADDR_STR2
2578 GR_NEIGHBOR_DISABLE_CMD
055679e9 2579 )
2580{
2581 int idx_peer = 1;
2582 struct peer *peer;
2583 int ret = BGP_GR_FAILURE;
2584
dc95985f 2585 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2586
055679e9 2587 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2588 zlog_debug(
2ba1fe69 2589 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2590
2591 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2592 if (!peer)
2593 return CMD_WARNING_CONFIG_FAILED;
2594
055679e9 2595 ret = bgp_neighbor_graceful_restart(peer,
2ba1fe69 2596 PEER_DISABLE_CMD);
055679e9 2597
2598 if (peer->bgp->t_startup)
2599 bgp_peer_gr_flags_update(peer);
2600
dc95985f 2601 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2602 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2603
055679e9 2604 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2605 zlog_debug(
2ba1fe69 2606 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2607 vty_out(vty,
2608 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2609
2610 return bgp_vty_return(vty, ret);
2611}
2612
2613DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2614 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2615 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2616 NO_STR
2617 NEIGHBOR_STR
2618 NEIGHBOR_ADDR_STR2
2619 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2620 )
2621{
2622 int idx_peer = 2;
2623 int ret = BGP_GR_FAILURE;
2624 struct peer *peer;
2625
dc95985f 2626 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2627
055679e9 2628 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2629 if (!peer)
2630 return CMD_WARNING_CONFIG_FAILED;
2631
2632 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2633 zlog_debug(
2ba1fe69 2634 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2635
2636 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2637
dc95985f 2638 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2639 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2640
2641 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2642 zlog_debug(
2ba1fe69 2643 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2644 vty_out(vty,
2645 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2646
2647 return bgp_vty_return(vty, ret);
2648}
2649
d6e3c15b 2650DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2651 bgp_graceful_restart_disable_eor_cmd,
2652 "bgp graceful-restart disable-eor",
2653 "BGP specific commands\n"
2654 "Graceful restart configuration parameters\n"
2655 "Disable EOR Check\n")
2656{
2657 VTY_DECLVAR_CONTEXT(bgp, bgp);
2658 bgp_flag_set(bgp, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2659
d6e3c15b 2660 return CMD_SUCCESS;
2661}
2662
2663DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2664 no_bgp_graceful_restart_disable_eor_cmd,
2665 "no bgp graceful-restart disable-eor",
2666 NO_STR
2667 "BGP specific commands\n"
2668 "Graceful restart configuration parameters\n"
2669 "Disable EOR Check\n")
2670{
2671 VTY_DECLVAR_CONTEXT(bgp, bgp);
2672 bgp_flag_unset(bgp, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2673
2674 return CMD_SUCCESS;
2675}
2676
2677DEFUN (bgp_graceful_restart_rib_stale_time,
2678 bgp_graceful_restart_rib_stale_time_cmd,
2679 "bgp graceful-restart rib-stale-time (1-3600)",
2680 "BGP specific commands\n"
2681 "Graceful restart configuration parameters\n"
2682 "Specify the stale route removal timer in rib\n"
2683 "Delay value (seconds)\n")
2684{
2685 VTY_DECLVAR_CONTEXT(bgp, bgp);
2686 int idx_number = 3;
2687 uint32_t stale_time;
2688
2689 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2690 bgp->rib_stale_time = stale_time;
2691 /* Send the stale timer update message to RIB */
2692 if (bgp_zebra_stale_timer_update(bgp))
2693 return CMD_WARNING;
2694
2695 return CMD_SUCCESS;
2696}
2697
2698DEFUN (no_bgp_graceful_restart_rib_stale_time,
2699 no_bgp_graceful_restart_rib_stale_time_cmd,
2700 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2701 NO_STR
2702 "BGP specific commands\n"
2703 "Graceful restart configuration parameters\n"
2704 "Specify the stale route removal timer in rib\n"
2705 "Delay value (seconds)\n")
2706{
2707 VTY_DECLVAR_CONTEXT(bgp, bgp);
2708
2709 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2710 /* Send the stale timer update message to RIB */
2711 if (bgp_zebra_stale_timer_update(bgp))
2712 return CMD_WARNING;
2713
d6e3c15b 2714 return CMD_SUCCESS;
2715}
2716
7f323236
DW
2717/* "bgp graceful-shutdown" configuration */
2718DEFUN (bgp_graceful_shutdown,
2719 bgp_graceful_shutdown_cmd,
2720 "bgp graceful-shutdown",
2721 BGP_STR
2722 "Graceful shutdown parameters\n")
2723{
2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
2725
2726 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2727 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2728 bgp_static_redo_import_check(bgp);
2729 bgp_redistribute_redo(bgp);
2730 bgp_clear_star_soft_out(vty, bgp->name);
2731 bgp_clear_star_soft_in(vty, bgp->name);
2732 }
2733
2734 return CMD_SUCCESS;
2735}
2736
2737DEFUN (no_bgp_graceful_shutdown,
2738 no_bgp_graceful_shutdown_cmd,
2739 "no bgp graceful-shutdown",
2740 NO_STR
2741 BGP_STR
2742 "Graceful shutdown parameters\n")
2743{
2744 VTY_DECLVAR_CONTEXT(bgp, bgp);
2745
2746 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2747 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2748 bgp_static_redo_import_check(bgp);
2749 bgp_redistribute_redo(bgp);
2750 bgp_clear_star_soft_out(vty, bgp->name);
2751 bgp_clear_star_soft_in(vty, bgp->name);
2752 }
2753
2754 return CMD_SUCCESS;
2755}
2756
718e3744 2757/* "bgp fast-external-failover" configuration. */
2758DEFUN (bgp_fast_external_failover,
2759 bgp_fast_external_failover_cmd,
2760 "bgp fast-external-failover",
2761 BGP_STR
2762 "Immediately reset session if a link to a directly connected external peer goes down\n")
2763{
d62a17ae 2764 VTY_DECLVAR_CONTEXT(bgp, bgp);
2765 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2766 return CMD_SUCCESS;
718e3744 2767}
2768
2769DEFUN (no_bgp_fast_external_failover,
2770 no_bgp_fast_external_failover_cmd,
2771 "no bgp fast-external-failover",
2772 NO_STR
2773 BGP_STR
2774 "Immediately reset session if a link to a directly connected external peer goes down\n")
2775{
d62a17ae 2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2778 return CMD_SUCCESS;
718e3744 2779}
6b0655a2 2780
718e3744 2781/* "bgp bestpath compare-routerid" configuration. */
2782DEFUN (bgp_bestpath_compare_router_id,
2783 bgp_bestpath_compare_router_id_cmd,
2784 "bgp bestpath compare-routerid",
2785 "BGP specific commands\n"
2786 "Change the default bestpath selection\n"
2787 "Compare router-id for identical EBGP paths\n")
2788{
d62a17ae 2789 VTY_DECLVAR_CONTEXT(bgp, bgp);
2790 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2791 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2792
d62a17ae 2793 return CMD_SUCCESS;
718e3744 2794}
2795
2796DEFUN (no_bgp_bestpath_compare_router_id,
2797 no_bgp_bestpath_compare_router_id_cmd,
2798 "no bgp bestpath compare-routerid",
2799 NO_STR
2800 "BGP specific commands\n"
2801 "Change the default bestpath selection\n"
2802 "Compare router-id for identical EBGP paths\n")
2803{
d62a17ae 2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2806 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2807
d62a17ae 2808 return CMD_SUCCESS;
718e3744 2809}
6b0655a2 2810
718e3744 2811/* "bgp bestpath as-path ignore" configuration. */
2812DEFUN (bgp_bestpath_aspath_ignore,
2813 bgp_bestpath_aspath_ignore_cmd,
2814 "bgp bestpath as-path ignore",
2815 "BGP specific commands\n"
2816 "Change the default bestpath selection\n"
2817 "AS-path attribute\n"
2818 "Ignore as-path length in selecting a route\n")
2819{
d62a17ae 2820 VTY_DECLVAR_CONTEXT(bgp, bgp);
2821 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2822 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2823
d62a17ae 2824 return CMD_SUCCESS;
718e3744 2825}
2826
2827DEFUN (no_bgp_bestpath_aspath_ignore,
2828 no_bgp_bestpath_aspath_ignore_cmd,
2829 "no bgp bestpath as-path ignore",
2830 NO_STR
2831 "BGP specific commands\n"
2832 "Change the default bestpath selection\n"
2833 "AS-path attribute\n"
2834 "Ignore as-path length in selecting a route\n")
2835{
d62a17ae 2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
2837 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2838 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2839
d62a17ae 2840 return CMD_SUCCESS;
718e3744 2841}
6b0655a2 2842
6811845b 2843/* "bgp bestpath as-path confed" configuration. */
2844DEFUN (bgp_bestpath_aspath_confed,
2845 bgp_bestpath_aspath_confed_cmd,
2846 "bgp bestpath as-path confed",
2847 "BGP specific commands\n"
2848 "Change the default bestpath selection\n"
2849 "AS-path attribute\n"
2850 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2851{
d62a17ae 2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
2853 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2854 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2855
d62a17ae 2856 return CMD_SUCCESS;
6811845b 2857}
2858
2859DEFUN (no_bgp_bestpath_aspath_confed,
2860 no_bgp_bestpath_aspath_confed_cmd,
2861 "no bgp bestpath as-path confed",
2862 NO_STR
2863 "BGP specific commands\n"
2864 "Change the default bestpath selection\n"
2865 "AS-path attribute\n"
2866 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2867{
d62a17ae 2868 VTY_DECLVAR_CONTEXT(bgp, bgp);
2869 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2870 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2871
d62a17ae 2872 return CMD_SUCCESS;
6811845b 2873}
6b0655a2 2874
2fdd455c
PM
2875/* "bgp bestpath as-path multipath-relax" configuration. */
2876DEFUN (bgp_bestpath_aspath_multipath_relax,
2877 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2878 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2879 "BGP specific commands\n"
2880 "Change the default bestpath selection\n"
2881 "AS-path attribute\n"
2882 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2883 "Generate an AS_SET\n"
16fc1eec
DS
2884 "Do not generate an AS_SET\n")
2885{
d62a17ae 2886 VTY_DECLVAR_CONTEXT(bgp, bgp);
2887 int idx = 0;
2888 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2889
d62a17ae 2890 /* no-as-set is now the default behavior so we can silently
2891 * ignore it */
2892 if (argv_find(argv, argc, "as-set", &idx))
2893 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2894 else
2895 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2896
d62a17ae 2897 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2898
d62a17ae 2899 return CMD_SUCCESS;
16fc1eec
DS
2900}
2901
219178b6
DW
2902DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2903 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2904 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2905 NO_STR
2906 "BGP specific commands\n"
2907 "Change the default bestpath selection\n"
2908 "AS-path attribute\n"
2909 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2910 "Generate an AS_SET\n"
16fc1eec
DS
2911 "Do not generate an AS_SET\n")
2912{
d62a17ae 2913 VTY_DECLVAR_CONTEXT(bgp, bgp);
2914 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2915 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2916 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2917
d62a17ae 2918 return CMD_SUCCESS;
2fdd455c 2919}
6b0655a2 2920
848973c7 2921/* "bgp log-neighbor-changes" configuration. */
2922DEFUN (bgp_log_neighbor_changes,
2923 bgp_log_neighbor_changes_cmd,
2924 "bgp log-neighbor-changes",
2925 "BGP specific commands\n"
2926 "Log neighbor up/down and reset reason\n")
2927{
d62a17ae 2928 VTY_DECLVAR_CONTEXT(bgp, bgp);
2929 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2930 return CMD_SUCCESS;
848973c7 2931}
2932
2933DEFUN (no_bgp_log_neighbor_changes,
2934 no_bgp_log_neighbor_changes_cmd,
2935 "no bgp log-neighbor-changes",
2936 NO_STR
2937 "BGP specific commands\n"
2938 "Log neighbor up/down and reset reason\n")
2939{
d62a17ae 2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2942 return CMD_SUCCESS;
848973c7 2943}
6b0655a2 2944
718e3744 2945/* "bgp bestpath med" configuration. */
2946DEFUN (bgp_bestpath_med,
2947 bgp_bestpath_med_cmd,
2d8c1a4d 2948 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2949 "BGP specific commands\n"
2950 "Change the default bestpath selection\n"
2951 "MED attribute\n"
2952 "Compare MED among confederation paths\n"
838758ac
DW
2953 "Treat missing MED as the least preferred one\n"
2954 "Treat missing MED as the least preferred one\n"
2955 "Compare MED among confederation paths\n")
718e3744 2956{
d62a17ae 2957 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2958
d62a17ae 2959 int idx = 0;
2960 if (argv_find(argv, argc, "confed", &idx))
2961 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2962 idx = 0;
2963 if (argv_find(argv, argc, "missing-as-worst", &idx))
2964 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2965
d62a17ae 2966 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2967
d62a17ae 2968 return CMD_SUCCESS;
718e3744 2969}
2970
718e3744 2971DEFUN (no_bgp_bestpath_med,
2972 no_bgp_bestpath_med_cmd,
2d8c1a4d 2973 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2974 NO_STR
2975 "BGP specific commands\n"
2976 "Change the default bestpath selection\n"
2977 "MED attribute\n"
2978 "Compare MED among confederation paths\n"
3a2d747c
QY
2979 "Treat missing MED as the least preferred one\n"
2980 "Treat missing MED as the least preferred one\n"
2981 "Compare MED among confederation paths\n")
718e3744 2982{
d62a17ae 2983 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2984
d62a17ae 2985 int idx = 0;
2986 if (argv_find(argv, argc, "confed", &idx))
2987 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2988 idx = 0;
2989 if (argv_find(argv, argc, "missing-as-worst", &idx))
2990 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2991
d62a17ae 2992 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2993
d62a17ae 2994 return CMD_SUCCESS;
718e3744 2995}
2996
718e3744 2997/* "no bgp default ipv4-unicast". */
2998DEFUN (no_bgp_default_ipv4_unicast,
2999 no_bgp_default_ipv4_unicast_cmd,
3000 "no bgp default ipv4-unicast",
3001 NO_STR
3002 "BGP specific commands\n"
3003 "Configure BGP defaults\n"
3004 "Activate ipv4-unicast for a peer by default\n")
3005{
d62a17ae 3006 VTY_DECLVAR_CONTEXT(bgp, bgp);
3007 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
3008 return CMD_SUCCESS;
718e3744 3009}
3010
3011DEFUN (bgp_default_ipv4_unicast,
3012 bgp_default_ipv4_unicast_cmd,
3013 "bgp default ipv4-unicast",
3014 "BGP specific commands\n"
3015 "Configure BGP defaults\n"
3016 "Activate ipv4-unicast for a peer by default\n")
3017{
d62a17ae 3018 VTY_DECLVAR_CONTEXT(bgp, bgp);
3019 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
3020 return CMD_SUCCESS;
718e3744 3021}
6b0655a2 3022
04b6bdc0
DW
3023/* Display hostname in certain command outputs */
3024DEFUN (bgp_default_show_hostname,
3025 bgp_default_show_hostname_cmd,
3026 "bgp default show-hostname",
3027 "BGP specific commands\n"
3028 "Configure BGP defaults\n"
0437e105 3029 "Show hostname in certain command outputs\n")
04b6bdc0 3030{
d62a17ae 3031 VTY_DECLVAR_CONTEXT(bgp, bgp);
3032 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
3033 return CMD_SUCCESS;
04b6bdc0
DW
3034}
3035
3036DEFUN (no_bgp_default_show_hostname,
3037 no_bgp_default_show_hostname_cmd,
3038 "no bgp default show-hostname",
3039 NO_STR
3040 "BGP specific commands\n"
3041 "Configure BGP defaults\n"
0437e105 3042 "Show hostname in certain command outputs\n")
04b6bdc0 3043{
d62a17ae 3044 VTY_DECLVAR_CONTEXT(bgp, bgp);
3045 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
3046 return CMD_SUCCESS;
04b6bdc0
DW
3047}
3048
8233ef81 3049/* "bgp network import-check" configuration. */
718e3744 3050DEFUN (bgp_network_import_check,
3051 bgp_network_import_check_cmd,
5623e905 3052 "bgp network import-check",
718e3744 3053 "BGP specific commands\n"
3054 "BGP network command\n"
5623e905 3055 "Check BGP network route exists in IGP\n")
718e3744 3056{
d62a17ae 3057 VTY_DECLVAR_CONTEXT(bgp, bgp);
3058 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
3059 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
3060 bgp_static_redo_import_check(bgp);
3061 }
078430f6 3062
d62a17ae 3063 return CMD_SUCCESS;
718e3744 3064}
3065
d62a17ae 3066ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3067 "bgp network import-check exact",
3068 "BGP specific commands\n"
3069 "BGP network command\n"
3070 "Check BGP network route exists in IGP\n"
3071 "Match route precisely\n")
8233ef81 3072
718e3744 3073DEFUN (no_bgp_network_import_check,
3074 no_bgp_network_import_check_cmd,
5623e905 3075 "no bgp network import-check",
718e3744 3076 NO_STR
3077 "BGP specific commands\n"
3078 "BGP network command\n"
3079 "Check BGP network route exists in IGP\n")
3080{
d62a17ae 3081 VTY_DECLVAR_CONTEXT(bgp, bgp);
3082 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
3083 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
3084 bgp_static_redo_import_check(bgp);
3085 }
5623e905 3086
d62a17ae 3087 return CMD_SUCCESS;
718e3744 3088}
6b0655a2 3089
718e3744 3090DEFUN (bgp_default_local_preference,
3091 bgp_default_local_preference_cmd,
6147e2c6 3092 "bgp default local-preference (0-4294967295)",
718e3744 3093 "BGP specific commands\n"
3094 "Configure BGP defaults\n"
3095 "local preference (higher=more preferred)\n"
3096 "Configure default local preference value\n")
3097{
d62a17ae 3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 int idx_number = 3;
d7c0a89a 3100 uint32_t local_pref;
718e3744 3101
d62a17ae 3102 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3103
d62a17ae 3104 bgp_default_local_preference_set(bgp, local_pref);
3105 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3106
d62a17ae 3107 return CMD_SUCCESS;
718e3744 3108}
3109
3110DEFUN (no_bgp_default_local_preference,
3111 no_bgp_default_local_preference_cmd,
838758ac 3112 "no bgp default local-preference [(0-4294967295)]",
718e3744 3113 NO_STR
3114 "BGP specific commands\n"
3115 "Configure BGP defaults\n"
838758ac
DW
3116 "local preference (higher=more preferred)\n"
3117 "Configure default local preference value\n")
718e3744 3118{
d62a17ae 3119 VTY_DECLVAR_CONTEXT(bgp, bgp);
3120 bgp_default_local_preference_unset(bgp);
3121 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3122
d62a17ae 3123 return CMD_SUCCESS;
718e3744 3124}
3125
6b0655a2 3126
3f9c7369
DS
3127DEFUN (bgp_default_subgroup_pkt_queue_max,
3128 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 3129 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
3130 "BGP specific commands\n"
3131 "Configure BGP defaults\n"
3132 "subgroup-pkt-queue-max\n"
3133 "Configure subgroup packet queue max\n")
8bd9d948 3134{
d62a17ae 3135 VTY_DECLVAR_CONTEXT(bgp, bgp);
3136 int idx_number = 3;
d7c0a89a 3137 uint32_t max_size;
8bd9d948 3138
d62a17ae 3139 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3140
d62a17ae 3141 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 3142
d62a17ae 3143 return CMD_SUCCESS;
3f9c7369
DS
3144}
3145
3146DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3147 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 3148 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
3149 NO_STR
3150 "BGP specific commands\n"
3151 "Configure BGP defaults\n"
838758ac
DW
3152 "subgroup-pkt-queue-max\n"
3153 "Configure subgroup packet queue max\n")
3f9c7369 3154{
d62a17ae 3155 VTY_DECLVAR_CONTEXT(bgp, bgp);
3156 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3157 return CMD_SUCCESS;
8bd9d948
DS
3158}
3159
813d4307 3160
8bd9d948
DS
3161DEFUN (bgp_rr_allow_outbound_policy,
3162 bgp_rr_allow_outbound_policy_cmd,
3163 "bgp route-reflector allow-outbound-policy",
3164 "BGP specific commands\n"
3165 "Allow modifications made by out route-map\n"
3166 "on ibgp neighbors\n")
3167{
d62a17ae 3168 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3169
d62a17ae 3170 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3171 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3172 update_group_announce_rrclients(bgp);
3173 bgp_clear_star_soft_out(vty, bgp->name);
3174 }
8bd9d948 3175
d62a17ae 3176 return CMD_SUCCESS;
8bd9d948
DS
3177}
3178
3179DEFUN (no_bgp_rr_allow_outbound_policy,
3180 no_bgp_rr_allow_outbound_policy_cmd,
3181 "no bgp route-reflector allow-outbound-policy",
3182 NO_STR
3183 "BGP specific commands\n"
3184 "Allow modifications made by out route-map\n"
3185 "on ibgp neighbors\n")
3186{
d62a17ae 3187 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3188
d62a17ae 3189 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3190 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3191 update_group_announce_rrclients(bgp);
3192 bgp_clear_star_soft_out(vty, bgp->name);
3193 }
8bd9d948 3194
d62a17ae 3195 return CMD_SUCCESS;
8bd9d948
DS
3196}
3197
f14e6fdb
DS
3198DEFUN (bgp_listen_limit,
3199 bgp_listen_limit_cmd,
9ccf14f7 3200 "bgp listen limit (1-5000)",
f14e6fdb 3201 "BGP specific commands\n"
1601a46f 3202 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3203 "Maximum number of BGP Dynamic Neighbors that can be created\n"
f14e6fdb
DS
3204 "Configure Dynamic Neighbors listen limit value\n")
3205{
d62a17ae 3206 VTY_DECLVAR_CONTEXT(bgp, bgp);
3207 int idx_number = 3;
3208 int listen_limit;
f14e6fdb 3209
d62a17ae 3210 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3211
d62a17ae 3212 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3213
d62a17ae 3214 return CMD_SUCCESS;
f14e6fdb
DS
3215}
3216
3217DEFUN (no_bgp_listen_limit,
3218 no_bgp_listen_limit_cmd,
838758ac 3219 "no bgp listen limit [(1-5000)]",
1601a46f 3220 NO_STR
f14e6fdb 3221 "BGP specific commands\n"
1601a46f 3222 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3223 "Maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac 3224 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3225{
d62a17ae 3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 bgp_listen_limit_unset(bgp);
3228 return CMD_SUCCESS;
f14e6fdb
DS
3229}
3230
3231
20eb8864 3232/*
3233 * Check if this listen range is already configured. Check for exact
3234 * match or overlap based on input.
3235 */
d62a17ae 3236static struct peer_group *listen_range_exists(struct bgp *bgp,
3237 struct prefix *range, int exact)
3238{
3239 struct listnode *node, *nnode;
3240 struct listnode *node1, *nnode1;
3241 struct peer_group *group;
3242 struct prefix *lr;
3243 afi_t afi;
3244 int match;
3245
3246 afi = family2afi(range->family);
3247 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3248 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3249 lr)) {
3250 if (exact)
3251 match = prefix_same(range, lr);
3252 else
3253 match = (prefix_match(range, lr)
3254 || prefix_match(lr, range));
3255 if (match)
3256 return group;
3257 }
3258 }
3259
3260 return NULL;
20eb8864 3261}
3262
f14e6fdb
DS
3263DEFUN (bgp_listen_range,
3264 bgp_listen_range_cmd,
d7b9898c 3265 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3266 "BGP specific commands\n"
d7fa34c1
QY
3267 "Configure BGP dynamic neighbors listen range\n"
3268 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3269 NEIGHBOR_ADDR_STR
3270 "Member of the peer-group\n"
3271 "Peer-group name\n")
f14e6fdb 3272{
d62a17ae 3273 VTY_DECLVAR_CONTEXT(bgp, bgp);
3274 struct prefix range;
3275 struct peer_group *group, *existing_group;
3276 afi_t afi;
3277 int ret;
3278 int idx = 0;
3279
3280 argv_find(argv, argc, "A.B.C.D/M", &idx);
3281 argv_find(argv, argc, "X:X::X:X/M", &idx);
3282 char *prefix = argv[idx]->arg;
d7b9898c 3283 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3284 char *peergroup = argv[idx]->arg;
3285
3286 /* Convert IP prefix string to struct prefix. */
3287 ret = str2prefix(prefix, &range);
3288 if (!ret) {
3289 vty_out(vty, "%% Malformed listen range\n");
3290 return CMD_WARNING_CONFIG_FAILED;
3291 }
3292
3293 afi = family2afi(range.family);
3294
3295 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3296 vty_out(vty,
3297 "%% Malformed listen range (link-local address)\n");
3298 return CMD_WARNING_CONFIG_FAILED;
3299 }
3300
3301 apply_mask(&range);
3302
3303 /* Check if same listen range is already configured. */
3304 existing_group = listen_range_exists(bgp, &range, 1);
3305 if (existing_group) {
3306 if (strcmp(existing_group->name, peergroup) == 0)
3307 return CMD_SUCCESS;
3308 else {
3309 vty_out(vty,
3310 "%% Same listen range is attached to peer-group %s\n",
3311 existing_group->name);
3312 return CMD_WARNING_CONFIG_FAILED;
3313 }
3314 }
3315
3316 /* Check if an overlapping listen range exists. */
3317 if (listen_range_exists(bgp, &range, 0)) {
3318 vty_out(vty,
3319 "%% Listen range overlaps with existing listen range\n");
3320 return CMD_WARNING_CONFIG_FAILED;
3321 }
3322
3323 group = peer_group_lookup(bgp, peergroup);
3324 if (!group) {
3325 vty_out(vty, "%% Configure the peer-group first\n");
3326 return CMD_WARNING_CONFIG_FAILED;
3327 }
3328
3329 ret = peer_group_listen_range_add(group, &range);
3330 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3331}
3332
3333DEFUN (no_bgp_listen_range,
3334 no_bgp_listen_range_cmd,
d7b9898c 3335 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3336 NO_STR
f14e6fdb 3337 "BGP specific commands\n"
d7fa34c1
QY
3338 "Unconfigure BGP dynamic neighbors listen range\n"
3339 "Unconfigure BGP dynamic neighbors listen range\n"
3340 NEIGHBOR_ADDR_STR
3341 "Member of the peer-group\n"
3342 "Peer-group name\n")
f14e6fdb 3343{
d62a17ae 3344 VTY_DECLVAR_CONTEXT(bgp, bgp);
3345 struct prefix range;
3346 struct peer_group *group;
3347 afi_t afi;
3348 int ret;
3349 int idx = 0;
3350
3351 argv_find(argv, argc, "A.B.C.D/M", &idx);
3352 argv_find(argv, argc, "X:X::X:X/M", &idx);
3353 char *prefix = argv[idx]->arg;
21d88a71 3354 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3355 char *peergroup = argv[idx]->arg;
3356
3357 /* Convert IP prefix string to struct prefix. */
3358 ret = str2prefix(prefix, &range);
3359 if (!ret) {
3360 vty_out(vty, "%% Malformed listen range\n");
3361 return CMD_WARNING_CONFIG_FAILED;
3362 }
3363
3364 afi = family2afi(range.family);
3365
3366 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3367 vty_out(vty,
3368 "%% Malformed listen range (link-local address)\n");
3369 return CMD_WARNING_CONFIG_FAILED;
3370 }
3371
3372 apply_mask(&range);
3373
3374 group = peer_group_lookup(bgp, peergroup);
3375 if (!group) {
3376 vty_out(vty, "%% Peer-group does not exist\n");
3377 return CMD_WARNING_CONFIG_FAILED;
3378 }
3379
3380 ret = peer_group_listen_range_del(group, &range);
3381 return bgp_vty_return(vty, ret);
3382}
3383
2b791107 3384void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3385{
3386 struct peer_group *group;
3387 struct listnode *node, *nnode, *rnode, *nrnode;
3388 struct prefix *range;
3389 afi_t afi;
3390 char buf[PREFIX2STR_BUFFER];
3391
3392 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3393 vty_out(vty, " bgp listen limit %d\n",
3394 bgp->dynamic_neighbors_limit);
3395
3396 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3397 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3398 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3399 nrnode, range)) {
3400 prefix2str(range, buf, sizeof(buf));
3401 vty_out(vty,
3402 " bgp listen range %s peer-group %s\n",
3403 buf, group->name);
3404 }
3405 }
3406 }
f14e6fdb
DS
3407}
3408
3409
907f92c8
DS
3410DEFUN (bgp_disable_connected_route_check,
3411 bgp_disable_connected_route_check_cmd,
3412 "bgp disable-ebgp-connected-route-check",
3413 "BGP specific commands\n"
3414 "Disable checking if nexthop is connected on ebgp sessions\n")
3415{
d62a17ae 3416 VTY_DECLVAR_CONTEXT(bgp, bgp);
3417 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3418 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3419
d62a17ae 3420 return CMD_SUCCESS;
907f92c8
DS
3421}
3422
3423DEFUN (no_bgp_disable_connected_route_check,
3424 no_bgp_disable_connected_route_check_cmd,
3425 "no bgp disable-ebgp-connected-route-check",
3426 NO_STR
3427 "BGP specific commands\n"
3428 "Disable checking if nexthop is connected on ebgp sessions\n")
3429{
d62a17ae 3430 VTY_DECLVAR_CONTEXT(bgp, bgp);
3431 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
3432 bgp_clear_star_soft_in(vty, bgp->name);
3433
3434 return CMD_SUCCESS;
3435}
3436
3437
3438static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3439 const char *as_str, afi_t afi, safi_t safi)
3440{
3441 VTY_DECLVAR_CONTEXT(bgp, bgp);
3442 int ret;
3443 as_t as;
3444 int as_type = AS_SPECIFIED;
3445 union sockunion su;
3446
3447 if (as_str[0] == 'i') {
3448 as = 0;
3449 as_type = AS_INTERNAL;
3450 } else if (as_str[0] == 'e') {
3451 as = 0;
3452 as_type = AS_EXTERNAL;
3453 } else {
3454 /* Get AS number. */
3455 as = strtoul(as_str, NULL, 10);
3456 }
3457
390485fd 3458 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3459 ret = str2sockunion(peer_str, &su);
3460 if (ret < 0) {
390485fd
DS
3461 struct peer *peer;
3462
3463 /* Check if existing interface peer */
3464 peer = peer_lookup_by_conf_if(bgp, peer_str);
3465
d62a17ae 3466 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3467 safi);
390485fd
DS
3468
3469 /* if not interface peer, check peer-group settings */
3470 if (ret < 0 && !peer) {
d62a17ae 3471 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3472 if (ret < 0) {
3473 vty_out(vty,
390485fd 3474 "%% Create the peer-group or interface first\n");
d62a17ae 3475 return CMD_WARNING_CONFIG_FAILED;
3476 }
3477 return CMD_SUCCESS;
3478 }
3479 } else {
3480 if (peer_address_self_check(bgp, &su)) {
3481 vty_out(vty,
3482 "%% Can not configure the local system as neighbor\n");
3483 return CMD_WARNING_CONFIG_FAILED;
3484 }
3485 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3486 }
3487
3488 /* This peer belongs to peer group. */
3489 switch (ret) {
3490 case BGP_ERR_PEER_GROUP_MEMBER:
3491 vty_out(vty,
faa16034 3492 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3493 return CMD_WARNING_CONFIG_FAILED;
3494 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3495 vty_out(vty,
faa16034 3496 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3497 return CMD_WARNING_CONFIG_FAILED;
3498 }
3499 return bgp_vty_return(vty, ret);
718e3744 3500}
3501
f26845f9
QY
3502DEFUN (bgp_default_shutdown,
3503 bgp_default_shutdown_cmd,
3504 "[no] bgp default shutdown",
3505 NO_STR
3506 BGP_STR
3507 "Configure BGP defaults\n"
b012cbe2 3508 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
3509{
3510 VTY_DECLVAR_CONTEXT(bgp, bgp);
3511 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3512 return CMD_SUCCESS;
3513}
3514
718e3744 3515DEFUN (neighbor_remote_as,
3516 neighbor_remote_as_cmd,
3a2d747c 3517 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 3518 NEIGHBOR_STR
3519 NEIGHBOR_ADDR_STR2
3520 "Specify a BGP neighbor\n"
d7fa34c1 3521 AS_STR
3a2d747c
QY
3522 "Internal BGP peer\n"
3523 "External BGP peer\n")
718e3744 3524{
d62a17ae 3525 int idx_peer = 1;
3526 int idx_remote_as = 3;
3527 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3528 argv[idx_remote_as]->arg, AFI_IP,
3529 SAFI_UNICAST);
3530}
3531
3532static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3533 afi_t afi, safi_t safi, int v6only,
3534 const char *peer_group_name,
3535 const char *as_str)
3536{
3537 VTY_DECLVAR_CONTEXT(bgp, bgp);
3538 as_t as = 0;
3539 int as_type = AS_UNSPECIFIED;
3540 struct peer *peer;
3541 struct peer_group *group;
3542 int ret = 0;
3543 union sockunion su;
3544
3545 group = peer_group_lookup(bgp, conf_if);
3546
3547 if (group) {
3548 vty_out(vty, "%% Name conflict with peer-group \n");
3549 return CMD_WARNING_CONFIG_FAILED;
3550 }
3551
3552 if (as_str) {
3553 if (as_str[0] == 'i') {
3554 as_type = AS_INTERNAL;
3555 } else if (as_str[0] == 'e') {
3556 as_type = AS_EXTERNAL;
3557 } else {
3558 /* Get AS number. */
3559 as = strtoul(as_str, NULL, 10);
3560 as_type = AS_SPECIFIED;
3561 }
3562 }
3563
3564 peer = peer_lookup_by_conf_if(bgp, conf_if);
3565 if (peer) {
3566 if (as_str)
cc4d4ce8 3567 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 3568 afi, safi);
3569 } else {
3570 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
3571 && afi == AFI_IP && safi == SAFI_UNICAST)
3572 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3573 as_type, 0, 0, NULL);
3574 else
3575 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3576 as_type, afi, safi, NULL);
3577
3578 if (!peer) {
3579 vty_out(vty, "%% BGP failed to create peer\n");
3580 return CMD_WARNING_CONFIG_FAILED;
3581 }
3582
3583 if (v6only)
527de3dc 3584 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3585
3586 /* Request zebra to initiate IPv6 RAs on this interface. We do
3587 * this
3588 * any unnumbered peer in order to not worry about run-time
3589 * transitions
3590 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3591 * address
3592 * gets deleted later etc.)
3593 */
3594 if (peer->ifp)
3595 bgp_zebra_initiate_radv(bgp, peer);
3596 }
3597
3598 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3599 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3600 if (v6only)
527de3dc 3601 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3602 else
527de3dc 3603 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3604
3605 /* v6only flag changed. Reset bgp seesion */
3606 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3607 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3608 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3609 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3610 } else
3611 bgp_session_reset(peer);
3612 }
3613
9fb964de
PM
3614 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3615 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3616 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3617 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3618 }
d62a17ae 3619
3620 if (peer_group_name) {
3621 group = peer_group_lookup(bgp, peer_group_name);
3622 if (!group) {
3623 vty_out(vty, "%% Configure the peer-group first\n");
3624 return CMD_WARNING_CONFIG_FAILED;
3625 }
3626
3627 ret = peer_group_bind(bgp, &su, peer, group, &as);
3628 }
3629
3630 return bgp_vty_return(vty, ret);
a80beece
DS
3631}
3632
4c48cf63
DW
3633DEFUN (neighbor_interface_config,
3634 neighbor_interface_config_cmd,
d7b9898c 3635 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3636 NEIGHBOR_STR
3637 "Interface name or neighbor tag\n"
31500417
DW
3638 "Enable BGP on interface\n"
3639 "Member of the peer-group\n"
16cedbb0 3640 "Peer-group name\n")
4c48cf63 3641{
d62a17ae 3642 int idx_word = 1;
3643 int idx_peer_group_word = 4;
31500417 3644
d62a17ae 3645 if (argc > idx_peer_group_word)
3646 return peer_conf_interface_get(
3647 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3648 argv[idx_peer_group_word]->arg, NULL);
3649 else
3650 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3651 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3652}
3653
4c48cf63
DW
3654DEFUN (neighbor_interface_config_v6only,
3655 neighbor_interface_config_v6only_cmd,
d7b9898c 3656 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3657 NEIGHBOR_STR
3658 "Interface name or neighbor tag\n"
3659 "Enable BGP on interface\n"
31500417
DW
3660 "Enable BGP with v6 link-local only\n"
3661 "Member of the peer-group\n"
16cedbb0 3662 "Peer-group name\n")
4c48cf63 3663{
d62a17ae 3664 int idx_word = 1;
3665 int idx_peer_group_word = 5;
31500417 3666
d62a17ae 3667 if (argc > idx_peer_group_word)
3668 return peer_conf_interface_get(
3669 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3670 argv[idx_peer_group_word]->arg, NULL);
31500417 3671
d62a17ae 3672 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3673 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3674}
3675
a80beece 3676
b3a39dc5
DD
3677DEFUN (neighbor_interface_config_remote_as,
3678 neighbor_interface_config_remote_as_cmd,
3a2d747c 3679 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3680 NEIGHBOR_STR
3681 "Interface name or neighbor tag\n"
3682 "Enable BGP on interface\n"
3a2d747c 3683 "Specify a BGP neighbor\n"
d7fa34c1 3684 AS_STR
3a2d747c
QY
3685 "Internal BGP peer\n"
3686 "External BGP peer\n")
b3a39dc5 3687{
d62a17ae 3688 int idx_word = 1;
3689 int idx_remote_as = 4;
3690 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3691 SAFI_UNICAST, 0, NULL,
3692 argv[idx_remote_as]->arg);
b3a39dc5
DD
3693}
3694
3695DEFUN (neighbor_interface_v6only_config_remote_as,
3696 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3697 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3698 NEIGHBOR_STR
3699 "Interface name or neighbor tag\n"
3a2d747c 3700 "Enable BGP with v6 link-local only\n"
b3a39dc5 3701 "Enable BGP on interface\n"
3a2d747c 3702 "Specify a BGP neighbor\n"
d7fa34c1 3703 AS_STR
3a2d747c
QY
3704 "Internal BGP peer\n"
3705 "External BGP peer\n")
b3a39dc5 3706{
d62a17ae 3707 int idx_word = 1;
3708 int idx_remote_as = 5;
3709 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3710 SAFI_UNICAST, 1, NULL,
3711 argv[idx_remote_as]->arg);
b3a39dc5
DD
3712}
3713
718e3744 3714DEFUN (neighbor_peer_group,
3715 neighbor_peer_group_cmd,
3716 "neighbor WORD peer-group",
3717 NEIGHBOR_STR
a80beece 3718 "Interface name or neighbor tag\n"
718e3744 3719 "Configure peer-group\n")
3720{
d62a17ae 3721 VTY_DECLVAR_CONTEXT(bgp, bgp);
3722 int idx_word = 1;
3723 struct peer *peer;
3724 struct peer_group *group;
718e3744 3725
d62a17ae 3726 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3727 if (peer) {
3728 vty_out(vty, "%% Name conflict with interface: \n");
3729 return CMD_WARNING_CONFIG_FAILED;
3730 }
718e3744 3731
d62a17ae 3732 group = peer_group_get(bgp, argv[idx_word]->arg);
3733 if (!group) {
3734 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3735 return CMD_WARNING_CONFIG_FAILED;
3736 }
718e3744 3737
d62a17ae 3738 return CMD_SUCCESS;
718e3744 3739}
3740
3741DEFUN (no_neighbor,
3742 no_neighbor_cmd,
dab8cd00 3743 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3744 NO_STR
3745 NEIGHBOR_STR
3a2d747c
QY
3746 NEIGHBOR_ADDR_STR2
3747 "Specify a BGP neighbor\n"
3748 AS_STR
3749 "Internal BGP peer\n"
3750 "External BGP peer\n")
718e3744 3751{
d62a17ae 3752 VTY_DECLVAR_CONTEXT(bgp, bgp);
3753 int idx_peer = 2;
3754 int ret;
3755 union sockunion su;
3756 struct peer_group *group;
3757 struct peer *peer;
3758 struct peer *other;
3759
3760 ret = str2sockunion(argv[idx_peer]->arg, &su);
3761 if (ret < 0) {
3762 /* look up for neighbor by interface name config. */
3763 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3764 if (peer) {
3765 /* Request zebra to terminate IPv6 RAs on this
3766 * interface. */
3767 if (peer->ifp)
3768 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3769 peer_notify_unconfig(peer);
d62a17ae 3770 peer_delete(peer);
3771 return CMD_SUCCESS;
3772 }
f14e6fdb 3773
d62a17ae 3774 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
3775 if (group) {
3776 peer_group_notify_unconfig(group);
d62a17ae 3777 peer_group_delete(group);
4e2786df 3778 } else {
d62a17ae 3779 vty_out(vty, "%% Create the peer-group first\n");
3780 return CMD_WARNING_CONFIG_FAILED;
3781 }
3782 } else {
3783 peer = peer_lookup(bgp, &su);
3784 if (peer) {
3785 if (peer_dynamic_neighbor(peer)) {
3786 vty_out(vty,
3787 "%% Operation not allowed on a dynamic neighbor\n");
3788 return CMD_WARNING_CONFIG_FAILED;
3789 }
3790
3791 other = peer->doppelganger;
4e2786df 3792 peer_notify_unconfig(peer);
d62a17ae 3793 peer_delete(peer);
4e2786df
DA
3794 if (other && other->status != Deleted) {
3795 peer_notify_unconfig(other);
d62a17ae 3796 peer_delete(other);
4e2786df 3797 }
d62a17ae 3798 }
1ff9a340 3799 }
718e3744 3800
d62a17ae 3801 return CMD_SUCCESS;
718e3744 3802}
3803
a80beece
DS
3804DEFUN (no_neighbor_interface_config,
3805 no_neighbor_interface_config_cmd,
d7b9898c 3806 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3807 NO_STR
3808 NEIGHBOR_STR
3809 "Interface name\n"
31500417
DW
3810 "Configure BGP on interface\n"
3811 "Enable BGP with v6 link-local only\n"
3812 "Member of the peer-group\n"
16cedbb0 3813 "Peer-group name\n"
3a2d747c
QY
3814 "Specify a BGP neighbor\n"
3815 AS_STR
3816 "Internal BGP peer\n"
3817 "External BGP peer\n")
a80beece 3818{
d62a17ae 3819 VTY_DECLVAR_CONTEXT(bgp, bgp);
3820 int idx_word = 2;
3821 struct peer *peer;
3822
3823 /* look up for neighbor by interface name config. */
3824 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3825 if (peer) {
3826 /* Request zebra to terminate IPv6 RAs on this interface. */
3827 if (peer->ifp)
3828 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3829 peer_notify_unconfig(peer);
d62a17ae 3830 peer_delete(peer);
3831 } else {
3832 vty_out(vty, "%% Create the bgp interface first\n");
3833 return CMD_WARNING_CONFIG_FAILED;
3834 }
3835 return CMD_SUCCESS;
a80beece
DS
3836}
3837
718e3744 3838DEFUN (no_neighbor_peer_group,
3839 no_neighbor_peer_group_cmd,
3840 "no neighbor WORD peer-group",
3841 NO_STR
3842 NEIGHBOR_STR
3843 "Neighbor tag\n"
3844 "Configure peer-group\n")
3845{
d62a17ae 3846 VTY_DECLVAR_CONTEXT(bgp, bgp);
3847 int idx_word = 2;
3848 struct peer_group *group;
718e3744 3849
d62a17ae 3850 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
3851 if (group) {
3852 peer_group_notify_unconfig(group);
d62a17ae 3853 peer_group_delete(group);
4e2786df 3854 } else {
d62a17ae 3855 vty_out(vty, "%% Create the peer-group first\n");
3856 return CMD_WARNING_CONFIG_FAILED;
3857 }
3858 return CMD_SUCCESS;
718e3744 3859}
3860
a80beece
DS
3861DEFUN (no_neighbor_interface_peer_group_remote_as,
3862 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3863 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3864 NO_STR
3865 NEIGHBOR_STR
a80beece 3866 "Interface name or neighbor tag\n"
718e3744 3867 "Specify a BGP neighbor\n"
3a2d747c
QY
3868 AS_STR
3869 "Internal BGP peer\n"
3870 "External BGP peer\n")
718e3744 3871{
d62a17ae 3872 VTY_DECLVAR_CONTEXT(bgp, bgp);
3873 int idx_word = 2;
3874 struct peer_group *group;
3875 struct peer *peer;
3876
3877 /* look up for neighbor by interface name config. */
3878 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3879 if (peer) {
390485fd 3880 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3881 return CMD_SUCCESS;
3882 }
3883
3884 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3885 if (group)
3886 peer_group_remote_as_delete(group);
3887 else {
3888 vty_out(vty, "%% Create the peer-group or interface first\n");
3889 return CMD_WARNING_CONFIG_FAILED;
3890 }
3891 return CMD_SUCCESS;
718e3744 3892}
6b0655a2 3893
718e3744 3894DEFUN (neighbor_local_as,
3895 neighbor_local_as_cmd,
9ccf14f7 3896 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3897 NEIGHBOR_STR
3898 NEIGHBOR_ADDR_STR2
3899 "Specify a local-as number\n"
3900 "AS number used as local AS\n")
3901{
d62a17ae 3902 int idx_peer = 1;
3903 int idx_number = 3;
3904 struct peer *peer;
3905 int ret;
3906 as_t as;
718e3744 3907
d62a17ae 3908 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3909 if (!peer)
3910 return CMD_WARNING_CONFIG_FAILED;
718e3744 3911
d62a17ae 3912 as = strtoul(argv[idx_number]->arg, NULL, 10);
3913 ret = peer_local_as_set(peer, as, 0, 0);
3914 return bgp_vty_return(vty, ret);
718e3744 3915}
3916
3917DEFUN (neighbor_local_as_no_prepend,
3918 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3919 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3920 NEIGHBOR_STR
3921 NEIGHBOR_ADDR_STR2
3922 "Specify a local-as number\n"
3923 "AS number used as local AS\n"
3924 "Do not prepend local-as to updates from ebgp peers\n")
3925{
d62a17ae 3926 int idx_peer = 1;
3927 int idx_number = 3;
3928 struct peer *peer;
3929 int ret;
3930 as_t as;
718e3744 3931
d62a17ae 3932 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3933 if (!peer)
3934 return CMD_WARNING_CONFIG_FAILED;
718e3744 3935
d62a17ae 3936 as = strtoul(argv[idx_number]->arg, NULL, 10);
3937 ret = peer_local_as_set(peer, as, 1, 0);
3938 return bgp_vty_return(vty, ret);
718e3744 3939}
3940
9d3f9705
AC
3941DEFUN (neighbor_local_as_no_prepend_replace_as,
3942 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3943 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3944 NEIGHBOR_STR
3945 NEIGHBOR_ADDR_STR2
3946 "Specify a local-as number\n"
3947 "AS number used as local AS\n"
3948 "Do not prepend local-as to updates from ebgp peers\n"
3949 "Do not prepend local-as to updates from ibgp peers\n")
3950{
d62a17ae 3951 int idx_peer = 1;
3952 int idx_number = 3;
3953 struct peer *peer;
3954 int ret;
3955 as_t as;
9d3f9705 3956
d62a17ae 3957 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3958 if (!peer)
3959 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3960
d62a17ae 3961 as = strtoul(argv[idx_number]->arg, NULL, 10);
3962 ret = peer_local_as_set(peer, as, 1, 1);
3963 return bgp_vty_return(vty, ret);
9d3f9705
AC
3964}
3965
718e3744 3966DEFUN (no_neighbor_local_as,
3967 no_neighbor_local_as_cmd,
a636c635 3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3969 NO_STR
3970 NEIGHBOR_STR
3971 NEIGHBOR_ADDR_STR2
a636c635
DW
3972 "Specify a local-as number\n"
3973 "AS number used as local AS\n"
3974 "Do not prepend local-as to updates from ebgp peers\n"
3975 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3976{
d62a17ae 3977 int idx_peer = 2;
3978 struct peer *peer;
3979 int ret;
718e3744 3980
d62a17ae 3981 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3982 if (!peer)
3983 return CMD_WARNING_CONFIG_FAILED;
718e3744 3984
d62a17ae 3985 ret = peer_local_as_unset(peer);
3986 return bgp_vty_return(vty, ret);
718e3744 3987}
3988
718e3744 3989
3f9c7369
DS
3990DEFUN (neighbor_solo,
3991 neighbor_solo_cmd,
9ccf14f7 3992 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3993 NEIGHBOR_STR
3994 NEIGHBOR_ADDR_STR2
3995 "Solo peer - part of its own update group\n")
3996{
d62a17ae 3997 int idx_peer = 1;
3998 struct peer *peer;
3999 int ret;
3f9c7369 4000
d62a17ae 4001 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4002 if (!peer)
4003 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4004
d62a17ae 4005 ret = update_group_adjust_soloness(peer, 1);
4006 return bgp_vty_return(vty, ret);
3f9c7369
DS
4007}
4008
4009DEFUN (no_neighbor_solo,
4010 no_neighbor_solo_cmd,
9ccf14f7 4011 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4012 NO_STR
4013 NEIGHBOR_STR
4014 NEIGHBOR_ADDR_STR2
4015 "Solo peer - part of its own update group\n")
4016{
d62a17ae 4017 int idx_peer = 2;
4018 struct peer *peer;
4019 int ret;
3f9c7369 4020
d62a17ae 4021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4022 if (!peer)
4023 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4024
d62a17ae 4025 ret = update_group_adjust_soloness(peer, 0);
4026 return bgp_vty_return(vty, ret);
3f9c7369
DS
4027}
4028
0df7c91f
PJ
4029DEFUN (neighbor_password,
4030 neighbor_password_cmd,
9ccf14f7 4031 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4032 NEIGHBOR_STR
4033 NEIGHBOR_ADDR_STR2
4034 "Set a password\n"
4035 "The password\n")
4036{
d62a17ae 4037 int idx_peer = 1;
4038 int idx_line = 3;
4039 struct peer *peer;
4040 int ret;
0df7c91f 4041
d62a17ae 4042 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4043 if (!peer)
4044 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4045
d62a17ae 4046 ret = peer_password_set(peer, argv[idx_line]->arg);
4047 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4048}
4049
4050DEFUN (no_neighbor_password,
4051 no_neighbor_password_cmd,
a636c635 4052 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4053 NO_STR
4054 NEIGHBOR_STR
4055 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4056 "Set a password\n"
4057 "The password\n")
0df7c91f 4058{
d62a17ae 4059 int idx_peer = 2;
4060 struct peer *peer;
4061 int ret;
0df7c91f 4062
d62a17ae 4063 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4064 if (!peer)
4065 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4066
d62a17ae 4067 ret = peer_password_unset(peer);
4068 return bgp_vty_return(vty, ret);
0df7c91f 4069}
6b0655a2 4070
718e3744 4071DEFUN (neighbor_activate,
4072 neighbor_activate_cmd,
9ccf14f7 4073 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4074 NEIGHBOR_STR
4075 NEIGHBOR_ADDR_STR2
4076 "Enable the Address Family for this Neighbor\n")
4077{
d62a17ae 4078 int idx_peer = 1;
4079 int ret;
4080 struct peer *peer;
718e3744 4081
d62a17ae 4082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4083 if (!peer)
4084 return CMD_WARNING_CONFIG_FAILED;
718e3744 4085
d62a17ae 4086 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4087 return bgp_vty_return(vty, ret);
718e3744 4088}
4089
d62a17ae 4090ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4091 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4093 "Enable the Address Family for this Neighbor\n")
596c17ba 4094
718e3744 4095DEFUN (no_neighbor_activate,
4096 no_neighbor_activate_cmd,
9ccf14f7 4097 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4098 NO_STR
4099 NEIGHBOR_STR
4100 NEIGHBOR_ADDR_STR2
4101 "Enable the Address Family for this Neighbor\n")
4102{
d62a17ae 4103 int idx_peer = 2;
4104 int ret;
4105 struct peer *peer;
718e3744 4106
d62a17ae 4107 /* Lookup peer. */
4108 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4109 if (!peer)
4110 return CMD_WARNING_CONFIG_FAILED;
718e3744 4111
d62a17ae 4112 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4113 return bgp_vty_return(vty, ret);
718e3744 4114}
6b0655a2 4115
d62a17ae 4116ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4117 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4118 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Enable the Address Family for this Neighbor\n")
596c17ba 4120
718e3744 4121DEFUN (neighbor_set_peer_group,
4122 neighbor_set_peer_group_cmd,
d7b9898c 4123 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4124 NEIGHBOR_STR
a80beece 4125 NEIGHBOR_ADDR_STR2
718e3744 4126 "Member of the peer-group\n"
16cedbb0 4127 "Peer-group name\n")
718e3744 4128{
d62a17ae 4129 VTY_DECLVAR_CONTEXT(bgp, bgp);
4130 int idx_peer = 1;
4131 int idx_word = 3;
4132 int ret;
4133 as_t as;
4134 union sockunion su;
4135 struct peer *peer;
4136 struct peer_group *group;
4137
d62a17ae 4138 ret = str2sockunion(argv[idx_peer]->arg, &su);
4139 if (ret < 0) {
4140 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4141 if (!peer) {
4142 vty_out(vty, "%% Malformed address or name: %s\n",
4143 argv[idx_peer]->arg);
4144 return CMD_WARNING_CONFIG_FAILED;
4145 }
4146 } else {
4147 if (peer_address_self_check(bgp, &su)) {
4148 vty_out(vty,
4149 "%% Can not configure the local system as neighbor\n");
4150 return CMD_WARNING_CONFIG_FAILED;
4151 }
4152
4153 /* Disallow for dynamic neighbor. */
4154 peer = peer_lookup(bgp, &su);
4155 if (peer && peer_dynamic_neighbor(peer)) {
4156 vty_out(vty,
4157 "%% Operation not allowed on a dynamic neighbor\n");
4158 return CMD_WARNING_CONFIG_FAILED;
4159 }
4160 }
4161
4162 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4163 if (!group) {
4164 vty_out(vty, "%% Configure the peer-group first\n");
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 ret = peer_group_bind(bgp, &su, peer, group, &as);
4169
4170 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4171 vty_out(vty,
4172 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4173 as);
4174 return CMD_WARNING_CONFIG_FAILED;
4175 }
4176
4177 return bgp_vty_return(vty, ret);
4178}
4179
4180ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4181 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4183 "Member of the peer-group\n"
4184 "Peer-group name\n")
596c17ba 4185
718e3744 4186DEFUN (no_neighbor_set_peer_group,
4187 no_neighbor_set_peer_group_cmd,
d7b9898c 4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4189 NO_STR
4190 NEIGHBOR_STR
a80beece 4191 NEIGHBOR_ADDR_STR2
718e3744 4192 "Member of the peer-group\n"
16cedbb0 4193 "Peer-group name\n")
718e3744 4194{
d62a17ae 4195 VTY_DECLVAR_CONTEXT(bgp, bgp);
4196 int idx_peer = 2;
4197 int idx_word = 4;
4198 int ret;
4199 struct peer *peer;
4200 struct peer_group *group;
4201
4202 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4203 if (!peer)
4204 return CMD_WARNING_CONFIG_FAILED;
4205
4206 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4207 if (!group) {
4208 vty_out(vty, "%% Configure the peer-group first\n");
4209 return CMD_WARNING_CONFIG_FAILED;
4210 }
718e3744 4211
4e2786df 4212 peer_notify_unconfig(peer);
827ed707 4213 ret = peer_delete(peer);
718e3744 4214
d62a17ae 4215 return bgp_vty_return(vty, ret);
718e3744 4216}
6b0655a2 4217
d62a17ae 4218ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4219 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4221 "Member of the peer-group\n"
4222 "Peer-group name\n")
596c17ba 4223
d62a17ae 4224static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4225 uint32_t flag, int set)
718e3744 4226{
d62a17ae 4227 int ret;
4228 struct peer *peer;
718e3744 4229
d62a17ae 4230 peer = peer_and_group_lookup_vty(vty, ip_str);
4231 if (!peer)
4232 return CMD_WARNING_CONFIG_FAILED;
718e3744 4233
7ebe625c
QY
4234 /*
4235 * If 'neighbor <interface>', then this is for directly connected peers,
4236 * we should not accept disable-connected-check.
4237 */
4238 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4239 vty_out(vty,
4240 "%s is directly connected peer, cannot accept disable-"
4241 "connected-check\n",
4242 ip_str);
4243 return CMD_WARNING_CONFIG_FAILED;
4244 }
4245
d62a17ae 4246 if (!set && flag == PEER_FLAG_SHUTDOWN)
4247 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4248
d62a17ae 4249 if (set)
4250 ret = peer_flag_set(peer, flag);
4251 else
4252 ret = peer_flag_unset(peer, flag);
718e3744 4253
d62a17ae 4254 return bgp_vty_return(vty, ret);
718e3744 4255}
4256
47cbc09b 4257static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4258{
d62a17ae 4259 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4260}
4261
d62a17ae 4262static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4263 uint32_t flag)
718e3744 4264{
d62a17ae 4265 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4266}
4267
4268/* neighbor passive. */
4269DEFUN (neighbor_passive,
4270 neighbor_passive_cmd,
9ccf14f7 4271 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4272 NEIGHBOR_STR
4273 NEIGHBOR_ADDR_STR2
4274 "Don't send open messages to this neighbor\n")
4275{
d62a17ae 4276 int idx_peer = 1;
4277 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4278}
4279
4280DEFUN (no_neighbor_passive,
4281 no_neighbor_passive_cmd,
9ccf14f7 4282 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4283 NO_STR
4284 NEIGHBOR_STR
4285 NEIGHBOR_ADDR_STR2
4286 "Don't send open messages to this neighbor\n")
4287{
d62a17ae 4288 int idx_peer = 2;
4289 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4290}
6b0655a2 4291
718e3744 4292/* neighbor shutdown. */
73d70fa6
DL
4293DEFUN (neighbor_shutdown_msg,
4294 neighbor_shutdown_msg_cmd,
4295 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4296 NEIGHBOR_STR
4297 NEIGHBOR_ADDR_STR2
73d70fa6
DL
4298 "Administratively shut down this neighbor\n"
4299 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
4300 "Shutdown message\n")
718e3744 4301{
d62a17ae 4302 int idx_peer = 1;
73d70fa6 4303
d62a17ae 4304 if (argc >= 5) {
4305 struct peer *peer =
4306 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4307 char *message;
73d70fa6 4308
d62a17ae 4309 if (!peer)
4310 return CMD_WARNING_CONFIG_FAILED;
4311 message = argv_concat(argv, argc, 4);
4312 peer_tx_shutdown_message_set(peer, message);
4313 XFREE(MTYPE_TMP, message);
4314 }
73d70fa6 4315
d62a17ae 4316 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4317}
4318
d62a17ae 4319ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4320 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4321 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4322 "Administratively shut down this neighbor\n")
73d70fa6
DL
4323
4324DEFUN (no_neighbor_shutdown_msg,
4325 no_neighbor_shutdown_msg_cmd,
4326 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4327 NO_STR
4328 NEIGHBOR_STR
4329 NEIGHBOR_ADDR_STR2
4330 "Administratively shut down this neighbor\n"
4331 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
4332 "Shutdown message\n")
718e3744 4333{
d62a17ae 4334 int idx_peer = 2;
73d70fa6 4335
d62a17ae 4336 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4337 PEER_FLAG_SHUTDOWN);
718e3744 4338}
6b0655a2 4339
d62a17ae 4340ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4341 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4342 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4343 "Administratively shut down this neighbor\n")
73d70fa6 4344
718e3744 4345/* neighbor capability dynamic. */
4346DEFUN (neighbor_capability_dynamic,
4347 neighbor_capability_dynamic_cmd,
9ccf14f7 4348 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4349 NEIGHBOR_STR
4350 NEIGHBOR_ADDR_STR2
4351 "Advertise capability to the peer\n"
4352 "Advertise dynamic capability to this neighbor\n")
4353{
d62a17ae 4354 int idx_peer = 1;
4355 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4356 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4357}
4358
4359DEFUN (no_neighbor_capability_dynamic,
4360 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4361 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4362 NO_STR
4363 NEIGHBOR_STR
4364 NEIGHBOR_ADDR_STR2
4365 "Advertise capability to the peer\n"
4366 "Advertise dynamic capability to this neighbor\n")
4367{
d62a17ae 4368 int idx_peer = 2;
4369 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4370 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4371}
6b0655a2 4372
718e3744 4373/* neighbor dont-capability-negotiate */
4374DEFUN (neighbor_dont_capability_negotiate,
4375 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4376 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4377 NEIGHBOR_STR
4378 NEIGHBOR_ADDR_STR2
4379 "Do not perform capability negotiation\n")
4380{
d62a17ae 4381 int idx_peer = 1;
4382 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4383 PEER_FLAG_DONT_CAPABILITY);
718e3744 4384}
4385
4386DEFUN (no_neighbor_dont_capability_negotiate,
4387 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4388 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4389 NO_STR
4390 NEIGHBOR_STR
4391 NEIGHBOR_ADDR_STR2
4392 "Do not perform capability negotiation\n")
4393{
d62a17ae 4394 int idx_peer = 2;
4395 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4396 PEER_FLAG_DONT_CAPABILITY);
718e3744 4397}
6b0655a2 4398
8a92a8a0
DS
4399/* neighbor capability extended next hop encoding */
4400DEFUN (neighbor_capability_enhe,
4401 neighbor_capability_enhe_cmd,
9ccf14f7 4402 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4403 NEIGHBOR_STR
4404 NEIGHBOR_ADDR_STR2
4405 "Advertise capability to the peer\n"
4406 "Advertise extended next-hop capability to the peer\n")
4407{
d62a17ae 4408 int idx_peer = 1;
4409 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4410 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4411}
4412
4413DEFUN (no_neighbor_capability_enhe,
4414 no_neighbor_capability_enhe_cmd,
9ccf14f7 4415 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4416 NO_STR
4417 NEIGHBOR_STR
4418 NEIGHBOR_ADDR_STR2
4419 "Advertise capability to the peer\n"
4420 "Advertise extended next-hop capability to the peer\n")
4421{
d62a17ae 4422 int idx_peer = 2;
4423 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4424 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4425}
4426
d62a17ae 4427static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4428 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 4429 int set)
718e3744 4430{
d62a17ae 4431 int ret;
4432 struct peer *peer;
718e3744 4433
d62a17ae 4434 peer = peer_and_group_lookup_vty(vty, peer_str);
4435 if (!peer)
4436 return CMD_WARNING_CONFIG_FAILED;
718e3744 4437
d62a17ae 4438 if (set)
4439 ret = peer_af_flag_set(peer, afi, safi, flag);
4440 else
4441 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 4442
d62a17ae 4443 return bgp_vty_return(vty, ret);
718e3744 4444}
4445
d62a17ae 4446static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4447 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4448{
d62a17ae 4449 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 4450}
4451
d62a17ae 4452static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4453 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4454{
d62a17ae 4455 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 4456}
6b0655a2 4457
718e3744 4458/* neighbor capability orf prefix-list. */
4459DEFUN (neighbor_capability_orf_prefix,
4460 neighbor_capability_orf_prefix_cmd,
9ccf14f7 4461 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4462 NEIGHBOR_STR
4463 NEIGHBOR_ADDR_STR2
4464 "Advertise capability to the peer\n"
4465 "Advertise ORF capability to the peer\n"
4466 "Advertise prefixlist ORF capability to this neighbor\n"
4467 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4468 "Capability to RECEIVE the ORF from this neighbor\n"
4469 "Capability to SEND the ORF to this neighbor\n")
4470{
d62a17ae 4471 int idx_peer = 1;
4472 int idx_send_recv = 5;
d7c0a89a 4473 uint16_t flag = 0;
d62a17ae 4474
4475 if (strmatch(argv[idx_send_recv]->text, "send"))
4476 flag = PEER_FLAG_ORF_PREFIX_SM;
4477 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4478 flag = PEER_FLAG_ORF_PREFIX_RM;
4479 else if (strmatch(argv[idx_send_recv]->text, "both"))
4480 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4481 else {
4482 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4483 return CMD_WARNING_CONFIG_FAILED;
4484 }
4485
4486 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4487 bgp_node_safi(vty), flag);
4488}
4489
4490ALIAS_HIDDEN(
4491 neighbor_capability_orf_prefix,
4492 neighbor_capability_orf_prefix_hidden_cmd,
4493 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4494 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4495 "Advertise capability to the peer\n"
4496 "Advertise ORF capability to the peer\n"
4497 "Advertise prefixlist ORF capability to this neighbor\n"
4498 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4499 "Capability to RECEIVE the ORF from this neighbor\n"
4500 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4501
718e3744 4502DEFUN (no_neighbor_capability_orf_prefix,
4503 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 4504 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4505 NO_STR
4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Advertise capability to the peer\n"
4509 "Advertise ORF capability to the peer\n"
4510 "Advertise prefixlist ORF capability to this neighbor\n"
4511 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4512 "Capability to RECEIVE the ORF from this neighbor\n"
4513 "Capability to SEND the ORF to this neighbor\n")
4514{
d62a17ae 4515 int idx_peer = 2;
4516 int idx_send_recv = 6;
d7c0a89a 4517 uint16_t flag = 0;
d62a17ae 4518
4519 if (strmatch(argv[idx_send_recv]->text, "send"))
4520 flag = PEER_FLAG_ORF_PREFIX_SM;
4521 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4522 flag = PEER_FLAG_ORF_PREFIX_RM;
4523 else if (strmatch(argv[idx_send_recv]->text, "both"))
4524 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4525 else {
4526 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4527 return CMD_WARNING_CONFIG_FAILED;
4528 }
4529
4530 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4531 bgp_node_afi(vty), bgp_node_safi(vty),
4532 flag);
4533}
4534
4535ALIAS_HIDDEN(
4536 no_neighbor_capability_orf_prefix,
4537 no_neighbor_capability_orf_prefix_hidden_cmd,
4538 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4539 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4540 "Advertise capability to the peer\n"
4541 "Advertise ORF capability to the peer\n"
4542 "Advertise prefixlist ORF capability to this neighbor\n"
4543 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4544 "Capability to RECEIVE the ORF from this neighbor\n"
4545 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4546
718e3744 4547/* neighbor next-hop-self. */
4548DEFUN (neighbor_nexthop_self,
4549 neighbor_nexthop_self_cmd,
9ccf14f7 4550 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4551 NEIGHBOR_STR
4552 NEIGHBOR_ADDR_STR2
a538debe 4553 "Disable the next hop calculation for this neighbor\n")
718e3744 4554{
d62a17ae 4555 int idx_peer = 1;
4556 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4557 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 4558}
9e7a53c1 4559
d62a17ae 4560ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4561 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4562 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4563 "Disable the next hop calculation for this neighbor\n")
596c17ba 4564
a538debe
DS
4565/* neighbor next-hop-self. */
4566DEFUN (neighbor_nexthop_self_force,
4567 neighbor_nexthop_self_force_cmd,
9ccf14f7 4568 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4569 NEIGHBOR_STR
4570 NEIGHBOR_ADDR_STR2
4571 "Disable the next hop calculation for this neighbor\n"
4572 "Set the next hop to self for reflected routes\n")
4573{
d62a17ae 4574 int idx_peer = 1;
4575 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4576 bgp_node_safi(vty),
4577 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4578}
4579
d62a17ae 4580ALIAS_HIDDEN(neighbor_nexthop_self_force,
4581 neighbor_nexthop_self_force_hidden_cmd,
4582 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4583 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4584 "Disable the next hop calculation for this neighbor\n"
4585 "Set the next hop to self for reflected routes\n")
596c17ba 4586
1bc4e531
DA
4587ALIAS_HIDDEN(neighbor_nexthop_self_force,
4588 neighbor_nexthop_self_all_hidden_cmd,
4589 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4590 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4591 "Disable the next hop calculation for this neighbor\n"
4592 "Set the next hop to self for reflected routes\n")
4593
718e3744 4594DEFUN (no_neighbor_nexthop_self,
4595 no_neighbor_nexthop_self_cmd,
9ccf14f7 4596 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4597 NO_STR
4598 NEIGHBOR_STR
4599 NEIGHBOR_ADDR_STR2
a538debe 4600 "Disable the next hop calculation for this neighbor\n")
718e3744 4601{
d62a17ae 4602 int idx_peer = 2;
4603 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4604 bgp_node_afi(vty), bgp_node_safi(vty),
4605 PEER_FLAG_NEXTHOP_SELF);
718e3744 4606}
6b0655a2 4607
d62a17ae 4608ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4609 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4610 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4611 "Disable the next hop calculation for this neighbor\n")
596c17ba 4612
88b8ed8d 4613DEFUN (no_neighbor_nexthop_self_force,
a538debe 4614 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4615 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4616 NO_STR
4617 NEIGHBOR_STR
4618 NEIGHBOR_ADDR_STR2
4619 "Disable the next hop calculation for this neighbor\n"
4620 "Set the next hop to self for reflected routes\n")
88b8ed8d 4621{
d62a17ae 4622 int idx_peer = 2;
4623 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4624 bgp_node_afi(vty), bgp_node_safi(vty),
4625 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4626}
a538debe 4627
d62a17ae 4628ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4629 no_neighbor_nexthop_self_force_hidden_cmd,
4630 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4631 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4632 "Disable the next hop calculation for this neighbor\n"
4633 "Set the next hop to self for reflected routes\n")
596c17ba 4634
1bc4e531
DA
4635ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4636 no_neighbor_nexthop_self_all_hidden_cmd,
4637 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4638 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4639 "Disable the next hop calculation for this neighbor\n"
4640 "Set the next hop to self for reflected routes\n")
4641
c7122e14
DS
4642/* neighbor as-override */
4643DEFUN (neighbor_as_override,
4644 neighbor_as_override_cmd,
9ccf14f7 4645 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4646 NEIGHBOR_STR
4647 NEIGHBOR_ADDR_STR2
4648 "Override ASNs in outbound updates if aspath equals remote-as\n")
4649{
d62a17ae 4650 int idx_peer = 1;
4651 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4652 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4653}
4654
d62a17ae 4655ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4656 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4657 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4658 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4659
c7122e14
DS
4660DEFUN (no_neighbor_as_override,
4661 no_neighbor_as_override_cmd,
9ccf14f7 4662 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4663 NO_STR
4664 NEIGHBOR_STR
4665 NEIGHBOR_ADDR_STR2
4666 "Override ASNs in outbound updates if aspath equals remote-as\n")
4667{
d62a17ae 4668 int idx_peer = 2;
4669 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4670 bgp_node_afi(vty), bgp_node_safi(vty),
4671 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4672}
4673
d62a17ae 4674ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4675 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4677 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4678
718e3744 4679/* neighbor remove-private-AS. */
4680DEFUN (neighbor_remove_private_as,
4681 neighbor_remove_private_as_cmd,
9ccf14f7 4682 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
5000f21c 4685 "Remove private ASNs in outbound updates\n")
718e3744 4686{
d62a17ae 4687 int idx_peer = 1;
4688 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4689 bgp_node_safi(vty),
4690 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4691}
4692
d62a17ae 4693ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4694 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4696 "Remove private ASNs in outbound updates\n")
596c17ba 4697
5000f21c
DS
4698DEFUN (neighbor_remove_private_as_all,
4699 neighbor_remove_private_as_all_cmd,
9ccf14f7 4700 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4701 NEIGHBOR_STR
4702 NEIGHBOR_ADDR_STR2
4703 "Remove private ASNs in outbound updates\n"
efd7904e 4704 "Apply to all AS numbers\n")
5000f21c 4705{
d62a17ae 4706 int idx_peer = 1;
4707 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4708 bgp_node_safi(vty),
4709 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4710}
4711
d62a17ae 4712ALIAS_HIDDEN(neighbor_remove_private_as_all,
4713 neighbor_remove_private_as_all_hidden_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4716 "Remove private ASNs in outbound updates\n"
4717 "Apply to all AS numbers")
596c17ba 4718
5000f21c
DS
4719DEFUN (neighbor_remove_private_as_replace_as,
4720 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4721 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4722 NEIGHBOR_STR
4723 NEIGHBOR_ADDR_STR2
4724 "Remove private ASNs in outbound updates\n"
4725 "Replace private ASNs with our ASN in outbound updates\n")
4726{
d62a17ae 4727 int idx_peer = 1;
4728 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4729 bgp_node_safi(vty),
4730 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4731}
4732
d62a17ae 4733ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4734 neighbor_remove_private_as_replace_as_hidden_cmd,
4735 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4737 "Remove private ASNs in outbound updates\n"
4738 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4739
5000f21c
DS
4740DEFUN (neighbor_remove_private_as_all_replace_as,
4741 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4742 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4743 NEIGHBOR_STR
4744 NEIGHBOR_ADDR_STR2
4745 "Remove private ASNs in outbound updates\n"
16cedbb0 4746 "Apply to all AS numbers\n"
5000f21c
DS
4747 "Replace private ASNs with our ASN in outbound updates\n")
4748{
d62a17ae 4749 int idx_peer = 1;
4750 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4751 bgp_node_safi(vty),
4752 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4753}
4754
d62a17ae 4755ALIAS_HIDDEN(
4756 neighbor_remove_private_as_all_replace_as,
4757 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4758 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4760 "Remove private ASNs in outbound updates\n"
4761 "Apply to all AS numbers\n"
4762 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4763
718e3744 4764DEFUN (no_neighbor_remove_private_as,
4765 no_neighbor_remove_private_as_cmd,
9ccf14f7 4766 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4767 NO_STR
4768 NEIGHBOR_STR
4769 NEIGHBOR_ADDR_STR2
5000f21c 4770 "Remove private ASNs in outbound updates\n")
718e3744 4771{
d62a17ae 4772 int idx_peer = 2;
4773 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4774 bgp_node_afi(vty), bgp_node_safi(vty),
4775 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4776}
6b0655a2 4777
d62a17ae 4778ALIAS_HIDDEN(no_neighbor_remove_private_as,
4779 no_neighbor_remove_private_as_hidden_cmd,
4780 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Remove private ASNs in outbound updates\n")
596c17ba 4783
88b8ed8d 4784DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4785 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4786 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4787 NO_STR
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR2
4790 "Remove private ASNs in outbound updates\n"
16cedbb0 4791 "Apply to all AS numbers\n")
88b8ed8d 4792{
d62a17ae 4793 int idx_peer = 2;
4794 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4795 bgp_node_afi(vty), bgp_node_safi(vty),
4796 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4797}
5000f21c 4798
d62a17ae 4799ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4800 no_neighbor_remove_private_as_all_hidden_cmd,
4801 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4802 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4803 "Remove private ASNs in outbound updates\n"
4804 "Apply to all AS numbers\n")
596c17ba 4805
88b8ed8d 4806DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4807 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4808 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4809 NO_STR
4810 NEIGHBOR_STR
4811 NEIGHBOR_ADDR_STR2
4812 "Remove private ASNs in outbound updates\n"
4813 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4814{
d62a17ae 4815 int idx_peer = 2;
4816 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4817 bgp_node_afi(vty), bgp_node_safi(vty),
4818 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4819}
5000f21c 4820
d62a17ae 4821ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4822 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4823 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4824 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4825 "Remove private ASNs in outbound updates\n"
4826 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4827
88b8ed8d 4828DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4829 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Remove private ASNs in outbound updates\n"
16cedbb0 4835 "Apply to all AS numbers\n"
5000f21c 4836 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4837{
d62a17ae 4838 int idx_peer = 2;
4839 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4840 bgp_node_afi(vty), bgp_node_safi(vty),
4841 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4842}
5000f21c 4843
d62a17ae 4844ALIAS_HIDDEN(
4845 no_neighbor_remove_private_as_all_replace_as,
4846 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4847 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4849 "Remove private ASNs in outbound updates\n"
4850 "Apply to all AS numbers\n"
4851 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4852
5000f21c 4853
718e3744 4854/* neighbor send-community. */
4855DEFUN (neighbor_send_community,
4856 neighbor_send_community_cmd,
9ccf14f7 4857 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4858 NEIGHBOR_STR
4859 NEIGHBOR_ADDR_STR2
4860 "Send Community attribute to this neighbor\n")
4861{
d62a17ae 4862 int idx_peer = 1;
27c05d4d 4863
d62a17ae 4864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4865 bgp_node_safi(vty),
4866 PEER_FLAG_SEND_COMMUNITY);
718e3744 4867}
4868
d62a17ae 4869ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4870 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4871 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4872 "Send Community attribute to this neighbor\n")
596c17ba 4873
718e3744 4874DEFUN (no_neighbor_send_community,
4875 no_neighbor_send_community_cmd,
9ccf14f7 4876 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4877 NO_STR
4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
4880 "Send Community attribute to this neighbor\n")
4881{
d62a17ae 4882 int idx_peer = 2;
27c05d4d 4883
d62a17ae 4884 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4885 bgp_node_afi(vty), bgp_node_safi(vty),
4886 PEER_FLAG_SEND_COMMUNITY);
718e3744 4887}
6b0655a2 4888
d62a17ae 4889ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4890 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4892 "Send Community attribute to this neighbor\n")
596c17ba 4893
718e3744 4894/* neighbor send-community extended. */
4895DEFUN (neighbor_send_community_type,
4896 neighbor_send_community_type_cmd,
57d187bc 4897 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Send Community attribute to this neighbor\n"
4901 "Send Standard and Extended Community attributes\n"
57d187bc 4902 "Send Standard, Large and Extended Community attributes\n"
718e3744 4903 "Send Extended Community attributes\n"
57d187bc
JS
4904 "Send Standard Community attributes\n"
4905 "Send Large Community attributes\n")
718e3744 4906{
27c05d4d 4907 int idx_peer = 1;
d7c0a89a 4908 uint32_t flag = 0;
27c05d4d 4909 const char *type = argv[argc - 1]->text;
d62a17ae 4910
27c05d4d 4911 if (strmatch(type, "standard")) {
d62a17ae 4912 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4913 } else if (strmatch(type, "extended")) {
d62a17ae 4914 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4915 } else if (strmatch(type, "large")) {
d62a17ae 4916 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4917 } else if (strmatch(type, "both")) {
d62a17ae 4918 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4919 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4920 } else { /* if (strmatch(type, "all")) */
d62a17ae 4921 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4922 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4923 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4924 }
4925
27c05d4d 4926 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4927 bgp_node_safi(vty), flag);
4928}
4929
4930ALIAS_HIDDEN(
4931 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4932 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4934 "Send Community attribute to this neighbor\n"
4935 "Send Standard and Extended Community attributes\n"
4936 "Send Standard, Large and Extended Community attributes\n"
4937 "Send Extended Community attributes\n"
4938 "Send Standard Community attributes\n"
4939 "Send Large Community attributes\n")
596c17ba 4940
718e3744 4941DEFUN (no_neighbor_send_community_type,
4942 no_neighbor_send_community_type_cmd,
57d187bc 4943 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4944 NO_STR
4945 NEIGHBOR_STR
4946 NEIGHBOR_ADDR_STR2
4947 "Send Community attribute to this neighbor\n"
4948 "Send Standard and Extended Community attributes\n"
57d187bc 4949 "Send Standard, Large and Extended Community attributes\n"
718e3744 4950 "Send Extended Community attributes\n"
57d187bc
JS
4951 "Send Standard Community attributes\n"
4952 "Send Large Community attributes\n")
718e3744 4953{
d62a17ae 4954 int idx_peer = 2;
27c05d4d 4955 uint32_t flag = 0;
d62a17ae 4956 const char *type = argv[argc - 1]->text;
4957
27c05d4d
PM
4958 if (strmatch(type, "standard")) {
4959 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4960 } else if (strmatch(type, "extended")) {
4961 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4962 } else if (strmatch(type, "large")) {
4963 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4964 } else if (strmatch(type, "both")) {
4965 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4966 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4967 } else { /* if (strmatch(type, "all")) */
4968 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4969 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4970 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4971 }
4972
4973 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4974 bgp_node_afi(vty), bgp_node_safi(vty),
4975 flag);
d62a17ae 4976}
4977
4978ALIAS_HIDDEN(
4979 no_neighbor_send_community_type,
4980 no_neighbor_send_community_type_hidden_cmd,
4981 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4983 "Send Community attribute to this neighbor\n"
4984 "Send Standard and Extended Community attributes\n"
4985 "Send Standard, Large and Extended Community attributes\n"
4986 "Send Extended Community attributes\n"
4987 "Send Standard Community attributes\n"
4988 "Send Large Community attributes\n")
596c17ba 4989
718e3744 4990/* neighbor soft-reconfig. */
4991DEFUN (neighbor_soft_reconfiguration,
4992 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4993 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4994 NEIGHBOR_STR
4995 NEIGHBOR_ADDR_STR2
4996 "Per neighbor soft reconfiguration\n"
4997 "Allow inbound soft reconfiguration for this neighbor\n")
4998{
d62a17ae 4999 int idx_peer = 1;
5000 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5001 bgp_node_safi(vty),
5002 PEER_FLAG_SOFT_RECONFIG);
718e3744 5003}
5004
d62a17ae 5005ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5006 neighbor_soft_reconfiguration_hidden_cmd,
5007 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5008 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5009 "Per neighbor soft reconfiguration\n"
5010 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5011
718e3744 5012DEFUN (no_neighbor_soft_reconfiguration,
5013 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5014 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5015 NO_STR
5016 NEIGHBOR_STR
5017 NEIGHBOR_ADDR_STR2
5018 "Per neighbor soft reconfiguration\n"
5019 "Allow inbound soft reconfiguration for this neighbor\n")
5020{
d62a17ae 5021 int idx_peer = 2;
5022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5023 bgp_node_afi(vty), bgp_node_safi(vty),
5024 PEER_FLAG_SOFT_RECONFIG);
718e3744 5025}
6b0655a2 5026
d62a17ae 5027ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5028 no_neighbor_soft_reconfiguration_hidden_cmd,
5029 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5031 "Per neighbor soft reconfiguration\n"
5032 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5033
718e3744 5034DEFUN (neighbor_route_reflector_client,
5035 neighbor_route_reflector_client_cmd,
9ccf14f7 5036 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5037 NEIGHBOR_STR
5038 NEIGHBOR_ADDR_STR2
5039 "Configure a neighbor as Route Reflector client\n")
5040{
d62a17ae 5041 int idx_peer = 1;
5042 struct peer *peer;
718e3744 5043
5044
d62a17ae 5045 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5046 if (!peer)
5047 return CMD_WARNING_CONFIG_FAILED;
718e3744 5048
d62a17ae 5049 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5050 bgp_node_safi(vty),
5051 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5052}
5053
d62a17ae 5054ALIAS_HIDDEN(neighbor_route_reflector_client,
5055 neighbor_route_reflector_client_hidden_cmd,
5056 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5058 "Configure a neighbor as Route Reflector client\n")
596c17ba 5059
718e3744 5060DEFUN (no_neighbor_route_reflector_client,
5061 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5062 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5063 NO_STR
5064 NEIGHBOR_STR
5065 NEIGHBOR_ADDR_STR2
5066 "Configure a neighbor as Route Reflector client\n")
5067{
d62a17ae 5068 int idx_peer = 2;
5069 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5070 bgp_node_afi(vty), bgp_node_safi(vty),
5071 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5072}
6b0655a2 5073
d62a17ae 5074ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5075 no_neighbor_route_reflector_client_hidden_cmd,
5076 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5077 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5078 "Configure a neighbor as Route Reflector client\n")
596c17ba 5079
718e3744 5080/* neighbor route-server-client. */
5081DEFUN (neighbor_route_server_client,
5082 neighbor_route_server_client_cmd,
9ccf14f7 5083 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Configure a neighbor as Route Server client\n")
5087{
d62a17ae 5088 int idx_peer = 1;
5089 struct peer *peer;
2a3d5731 5090
d62a17ae 5091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5092 if (!peer)
5093 return CMD_WARNING_CONFIG_FAILED;
5094 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5095 bgp_node_safi(vty),
5096 PEER_FLAG_RSERVER_CLIENT);
718e3744 5097}
5098
d62a17ae 5099ALIAS_HIDDEN(neighbor_route_server_client,
5100 neighbor_route_server_client_hidden_cmd,
5101 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5102 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5103 "Configure a neighbor as Route Server client\n")
596c17ba 5104
718e3744 5105DEFUN (no_neighbor_route_server_client,
5106 no_neighbor_route_server_client_cmd,
9ccf14f7 5107 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5108 NO_STR
5109 NEIGHBOR_STR
5110 NEIGHBOR_ADDR_STR2
5111 "Configure a neighbor as Route Server client\n")
fee0f4c6 5112{
d62a17ae 5113 int idx_peer = 2;
5114 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5115 bgp_node_afi(vty), bgp_node_safi(vty),
5116 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5117}
6b0655a2 5118
d62a17ae 5119ALIAS_HIDDEN(no_neighbor_route_server_client,
5120 no_neighbor_route_server_client_hidden_cmd,
5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5122 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5123 "Configure a neighbor as Route Server client\n")
596c17ba 5124
fee0f4c6 5125DEFUN (neighbor_nexthop_local_unchanged,
5126 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5127 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Configure treatment of outgoing link-local nexthop attribute\n"
5131 "Leave link-local nexthop unchanged for this peer\n")
5132{
d62a17ae 5133 int idx_peer = 1;
5134 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5135 bgp_node_safi(vty),
5136 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5137}
6b0655a2 5138
fee0f4c6 5139DEFUN (no_neighbor_nexthop_local_unchanged,
5140 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5141 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5142 NO_STR
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
5145 "Configure treatment of outgoing link-local-nexthop attribute\n"
5146 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5147{
d62a17ae 5148 int idx_peer = 2;
5149 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5150 bgp_node_afi(vty), bgp_node_safi(vty),
5151 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5152}
6b0655a2 5153
718e3744 5154DEFUN (neighbor_attr_unchanged,
5155 neighbor_attr_unchanged_cmd,
a8206004 5156 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "BGP attribute is propagated unchanged to this neighbor\n"
5160 "As-path attribute\n"
5161 "Nexthop attribute\n"
a8206004 5162 "Med attribute\n")
718e3744 5163{
d62a17ae 5164 int idx = 0;
8eeb0335
DW
5165 char *peer_str = argv[1]->arg;
5166 struct peer *peer;
d7c0a89a 5167 uint16_t flags = 0;
8eeb0335
DW
5168 afi_t afi = bgp_node_afi(vty);
5169 safi_t safi = bgp_node_safi(vty);
5170
5171 peer = peer_and_group_lookup_vty(vty, peer_str);
5172 if (!peer)
5173 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5174
5175 if (argv_find(argv, argc, "as-path", &idx))
5176 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5177 idx = 0;
5178 if (argv_find(argv, argc, "next-hop", &idx))
5179 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5180 idx = 0;
5181 if (argv_find(argv, argc, "med", &idx))
5182 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5183
8eeb0335
DW
5184 /* no flags means all of them! */
5185 if (!flags) {
d62a17ae 5186 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5187 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5188 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 5189 } else {
a4d82a8a
PZ
5190 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
5191 && peer_af_flag_check(peer, afi, safi,
5192 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
5193 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5194 PEER_FLAG_AS_PATH_UNCHANGED);
5195 }
5196
a4d82a8a
PZ
5197 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
5198 && peer_af_flag_check(peer, afi, safi,
5199 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
5200 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5201 PEER_FLAG_NEXTHOP_UNCHANGED);
5202 }
5203
a4d82a8a
PZ
5204 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
5205 && peer_af_flag_check(peer, afi, safi,
5206 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
5207 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5208 PEER_FLAG_MED_UNCHANGED);
5209 }
d62a17ae 5210 }
5211
8eeb0335 5212 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 5213}
5214
5215ALIAS_HIDDEN(
5216 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5217 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5218 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5219 "BGP attribute is propagated unchanged to this neighbor\n"
5220 "As-path attribute\n"
5221 "Nexthop attribute\n"
5222 "Med attribute\n")
596c17ba 5223
718e3744 5224DEFUN (no_neighbor_attr_unchanged,
5225 no_neighbor_attr_unchanged_cmd,
a8206004 5226 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5227 NO_STR
718e3744 5228 NEIGHBOR_STR
5229 NEIGHBOR_ADDR_STR2
31500417
DW
5230 "BGP attribute is propagated unchanged to this neighbor\n"
5231 "As-path attribute\n"
40e718b5 5232 "Nexthop attribute\n"
a8206004 5233 "Med attribute\n")
718e3744 5234{
d62a17ae 5235 int idx = 0;
5236 char *peer = argv[2]->arg;
d7c0a89a 5237 uint16_t flags = 0;
d62a17ae 5238
5239 if (argv_find(argv, argc, "as-path", &idx))
5240 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5241 idx = 0;
5242 if (argv_find(argv, argc, "next-hop", &idx))
5243 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5244 idx = 0;
5245 if (argv_find(argv, argc, "med", &idx))
5246 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5247
5248 if (!flags) // no flags means all of them!
5249 {
5250 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5251 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5252 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5253 }
5254
5255 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
5256 bgp_node_safi(vty), flags);
5257}
5258
5259ALIAS_HIDDEN(
5260 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5261 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5262 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5263 "BGP attribute is propagated unchanged to this neighbor\n"
5264 "As-path attribute\n"
5265 "Nexthop attribute\n"
5266 "Med attribute\n")
718e3744 5267
718e3744 5268/* EBGP multihop configuration. */
d62a17ae 5269static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5270 const char *ttl_str)
718e3744 5271{
d62a17ae 5272 struct peer *peer;
5273 unsigned int ttl;
718e3744 5274
d62a17ae 5275 peer = peer_and_group_lookup_vty(vty, ip_str);
5276 if (!peer)
5277 return CMD_WARNING_CONFIG_FAILED;
718e3744 5278
d62a17ae 5279 if (peer->conf_if)
5280 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5281
d62a17ae 5282 if (!ttl_str)
5283 ttl = MAXTTL;
5284 else
5285 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5286
d62a17ae 5287 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5288}
5289
d62a17ae 5290static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5291{
d62a17ae 5292 struct peer *peer;
718e3744 5293
d62a17ae 5294 peer = peer_and_group_lookup_vty(vty, ip_str);
5295 if (!peer)
5296 return CMD_WARNING_CONFIG_FAILED;
718e3744 5297
d62a17ae 5298 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 5299}
5300
5301/* neighbor ebgp-multihop. */
5302DEFUN (neighbor_ebgp_multihop,
5303 neighbor_ebgp_multihop_cmd,
9ccf14f7 5304 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 5305 NEIGHBOR_STR
5306 NEIGHBOR_ADDR_STR2
5307 "Allow EBGP neighbors not on directly connected networks\n")
5308{
d62a17ae 5309 int idx_peer = 1;
5310 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5311}
5312
5313DEFUN (neighbor_ebgp_multihop_ttl,
5314 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 5315 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5318 "Allow EBGP neighbors not on directly connected networks\n"
5319 "maximum hop count\n")
5320{
d62a17ae 5321 int idx_peer = 1;
5322 int idx_number = 3;
5323 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5324 argv[idx_number]->arg);
718e3744 5325}
5326
5327DEFUN (no_neighbor_ebgp_multihop,
5328 no_neighbor_ebgp_multihop_cmd,
a636c635 5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 5330 NO_STR
5331 NEIGHBOR_STR
5332 NEIGHBOR_ADDR_STR2
a636c635
DW
5333 "Allow EBGP neighbors not on directly connected networks\n"
5334 "maximum hop count\n")
718e3744 5335{
d62a17ae 5336 int idx_peer = 2;
5337 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5338}
5339
6b0655a2 5340
6ffd2079 5341/* disable-connected-check */
5342DEFUN (neighbor_disable_connected_check,
5343 neighbor_disable_connected_check_cmd,
7ebe625c 5344 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5345 NEIGHBOR_STR
7ebe625c 5346 NEIGHBOR_ADDR_STR2
a636c635
DW
5347 "one-hop away EBGP peer using loopback address\n"
5348 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5349{
d62a17ae 5350 int idx_peer = 1;
5351 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5352 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5353}
5354
5355DEFUN (no_neighbor_disable_connected_check,
5356 no_neighbor_disable_connected_check_cmd,
7ebe625c 5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5358 NO_STR
5359 NEIGHBOR_STR
7ebe625c 5360 NEIGHBOR_ADDR_STR2
a636c635
DW
5361 "one-hop away EBGP peer using loopback address\n"
5362 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5363{
d62a17ae 5364 int idx_peer = 2;
5365 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5366 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5367}
5368
47cbc09b
PM
5369
5370/* enforce-first-as */
5371DEFUN (neighbor_enforce_first_as,
5372 neighbor_enforce_first_as_cmd,
5373 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Enforce the first AS for EBGP routes\n")
5377{
5378 int idx_peer = 1;
5379
5380 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5381 PEER_FLAG_ENFORCE_FIRST_AS);
5382}
5383
5384DEFUN (no_neighbor_enforce_first_as,
5385 no_neighbor_enforce_first_as_cmd,
5386 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5387 NO_STR
5388 NEIGHBOR_STR
5389 NEIGHBOR_ADDR_STR2
5390 "Enforce the first AS for EBGP routes\n")
5391{
5392 int idx_peer = 2;
5393
5394 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5395 PEER_FLAG_ENFORCE_FIRST_AS);
5396}
5397
5398
718e3744 5399DEFUN (neighbor_description,
5400 neighbor_description_cmd,
e961923c 5401 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Neighbor specific description\n"
5405 "Up to 80 characters describing this neighbor\n")
5406{
d62a17ae 5407 int idx_peer = 1;
5408 int idx_line = 3;
5409 struct peer *peer;
5410 char *str;
718e3744 5411
d62a17ae 5412 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5413 if (!peer)
5414 return CMD_WARNING_CONFIG_FAILED;
718e3744 5415
d62a17ae 5416 str = argv_concat(argv, argc, idx_line);
718e3744 5417
d62a17ae 5418 peer_description_set(peer, str);
718e3744 5419
d62a17ae 5420 XFREE(MTYPE_TMP, str);
718e3744 5421
d62a17ae 5422 return CMD_SUCCESS;
718e3744 5423}
5424
5425DEFUN (no_neighbor_description,
5426 no_neighbor_description_cmd,
a14810f4 5427 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 5428 NO_STR
5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
a14810f4 5431 "Neighbor specific description\n")
718e3744 5432{
d62a17ae 5433 int idx_peer = 2;
5434 struct peer *peer;
718e3744 5435
d62a17ae 5436 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5437 if (!peer)
5438 return CMD_WARNING_CONFIG_FAILED;
718e3744 5439
d62a17ae 5440 peer_description_unset(peer);
718e3744 5441
d62a17ae 5442 return CMD_SUCCESS;
718e3744 5443}
5444
a14810f4
PM
5445ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5446 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5447 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5448 "Neighbor specific description\n"
5449 "Up to 80 characters describing this neighbor\n")
6b0655a2 5450
718e3744 5451/* Neighbor update-source. */
d62a17ae 5452static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5453 const char *source_str)
5454{
5455 struct peer *peer;
5456 struct prefix p;
a14810f4 5457 union sockunion su;
d62a17ae 5458
5459 peer = peer_and_group_lookup_vty(vty, peer_str);
5460 if (!peer)
5461 return CMD_WARNING_CONFIG_FAILED;
5462
5463 if (peer->conf_if)
5464 return CMD_WARNING;
5465
5466 if (source_str) {
a14810f4 5467 if (str2sockunion(source_str, &su) == 0)
d62a17ae 5468 peer_update_source_addr_set(peer, &su);
5469 else {
5470 if (str2prefix(source_str, &p)) {
5471 vty_out(vty,
5472 "%% Invalid update-source, remove prefix length \n");
5473 return CMD_WARNING_CONFIG_FAILED;
5474 } else
5475 peer_update_source_if_set(peer, source_str);
5476 }
5477 } else
5478 peer_update_source_unset(peer);
5479
5480 return CMD_SUCCESS;
5481}
5482
5483#define BGP_UPDATE_SOURCE_HELP_STR \
5484 "IPv4 address\n" \
5485 "IPv6 address\n" \
5486 "Interface name (requires zebra to be running)\n"
369688c0 5487
718e3744 5488DEFUN (neighbor_update_source,
5489 neighbor_update_source_cmd,
9ccf14f7 5490 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Source of routing updates\n"
369688c0 5494 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5495{
d62a17ae 5496 int idx_peer = 1;
5497 int idx_peer_2 = 3;
5498 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5499 argv[idx_peer_2]->arg);
718e3744 5500}
5501
5502DEFUN (no_neighbor_update_source,
5503 no_neighbor_update_source_cmd,
c7178fe7 5504 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 5505 NO_STR
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
5508 "Source of routing updates\n"
5509 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5510{
d62a17ae 5511 int idx_peer = 2;
5512 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5513}
6b0655a2 5514
d62a17ae 5515static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5516 afi_t afi, safi_t safi,
5517 const char *rmap, int set)
718e3744 5518{
d62a17ae 5519 int ret;
5520 struct peer *peer;
80912664 5521 struct route_map *route_map = NULL;
718e3744 5522
d62a17ae 5523 peer = peer_and_group_lookup_vty(vty, peer_str);
5524 if (!peer)
5525 return CMD_WARNING_CONFIG_FAILED;
718e3744 5526
1de27621 5527 if (set) {
80912664
DS
5528 if (rmap)
5529 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
5530 ret = peer_default_originate_set(peer, afi, safi,
5531 rmap, route_map);
5532 } else
d62a17ae 5533 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 5534
d62a17ae 5535 return bgp_vty_return(vty, ret);
718e3744 5536}
5537
5538/* neighbor default-originate. */
5539DEFUN (neighbor_default_originate,
5540 neighbor_default_originate_cmd,
9ccf14f7 5541 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 5542 NEIGHBOR_STR
5543 NEIGHBOR_ADDR_STR2
5544 "Originate default route to this neighbor\n")
5545{
d62a17ae 5546 int idx_peer = 1;
5547 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5548 bgp_node_afi(vty),
5549 bgp_node_safi(vty), NULL, 1);
718e3744 5550}
5551
d62a17ae 5552ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5553 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5554 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5555 "Originate default route to this neighbor\n")
596c17ba 5556
718e3744 5557DEFUN (neighbor_default_originate_rmap,
5558 neighbor_default_originate_rmap_cmd,
9ccf14f7 5559 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Originate default route to this neighbor\n"
5563 "Route-map to specify criteria to originate default\n"
5564 "route-map name\n")
5565{
d62a17ae 5566 int idx_peer = 1;
5567 int idx_word = 4;
5568 return peer_default_originate_set_vty(
5569 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5570 argv[idx_word]->arg, 1);
718e3744 5571}
5572
d62a17ae 5573ALIAS_HIDDEN(
5574 neighbor_default_originate_rmap,
5575 neighbor_default_originate_rmap_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Originate default route to this neighbor\n"
5579 "Route-map to specify criteria to originate default\n"
5580 "route-map name\n")
596c17ba 5581
718e3744 5582DEFUN (no_neighbor_default_originate,
5583 no_neighbor_default_originate_cmd,
a636c635 5584 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 5585 NO_STR
5586 NEIGHBOR_STR
5587 NEIGHBOR_ADDR_STR2
a636c635
DW
5588 "Originate default route to this neighbor\n"
5589 "Route-map to specify criteria to originate default\n"
5590 "route-map name\n")
718e3744 5591{
d62a17ae 5592 int idx_peer = 2;
5593 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5594 bgp_node_afi(vty),
5595 bgp_node_safi(vty), NULL, 0);
718e3744 5596}
5597
d62a17ae 5598ALIAS_HIDDEN(
5599 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5600 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5601 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5602 "Originate default route to this neighbor\n"
5603 "Route-map to specify criteria to originate default\n"
5604 "route-map name\n")
596c17ba 5605
6b0655a2 5606
718e3744 5607/* Set neighbor's BGP port. */
d62a17ae 5608static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5609 const char *port_str)
5610{
5611 struct peer *peer;
d7c0a89a 5612 uint16_t port;
d62a17ae 5613 struct servent *sp;
5614
5615 peer = peer_lookup_vty(vty, ip_str);
5616 if (!peer)
5617 return CMD_WARNING_CONFIG_FAILED;
5618
5619 if (!port_str) {
5620 sp = getservbyname("bgp", "tcp");
5621 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5622 } else {
5623 port = strtoul(port_str, NULL, 10);
5624 }
718e3744 5625
d62a17ae 5626 peer_port_set(peer, port);
718e3744 5627
d62a17ae 5628 return CMD_SUCCESS;
718e3744 5629}
5630
f418446b 5631/* Set specified peer's BGP port. */
718e3744 5632DEFUN (neighbor_port,
5633 neighbor_port_cmd,
9ccf14f7 5634 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5635 NEIGHBOR_STR
5636 NEIGHBOR_ADDR_STR
5637 "Neighbor's BGP port\n"
5638 "TCP port number\n")
5639{
d62a17ae 5640 int idx_ip = 1;
5641 int idx_number = 3;
5642 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5643 argv[idx_number]->arg);
718e3744 5644}
5645
5646DEFUN (no_neighbor_port,
5647 no_neighbor_port_cmd,
9ccf14f7 5648 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR
8334fd5a
DW
5652 "Neighbor's BGP port\n"
5653 "TCP port number\n")
718e3744 5654{
d62a17ae 5655 int idx_ip = 2;
5656 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5657}
5658
6b0655a2 5659
718e3744 5660/* neighbor weight. */
d62a17ae 5661static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5662 safi_t safi, const char *weight_str)
718e3744 5663{
d62a17ae 5664 int ret;
5665 struct peer *peer;
5666 unsigned long weight;
718e3744 5667
d62a17ae 5668 peer = peer_and_group_lookup_vty(vty, ip_str);
5669 if (!peer)
5670 return CMD_WARNING_CONFIG_FAILED;
718e3744 5671
d62a17ae 5672 weight = strtoul(weight_str, NULL, 10);
718e3744 5673
d62a17ae 5674 ret = peer_weight_set(peer, afi, safi, weight);
5675 return bgp_vty_return(vty, ret);
718e3744 5676}
5677
d62a17ae 5678static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5679 safi_t safi)
718e3744 5680{
d62a17ae 5681 int ret;
5682 struct peer *peer;
718e3744 5683
d62a17ae 5684 peer = peer_and_group_lookup_vty(vty, ip_str);
5685 if (!peer)
5686 return CMD_WARNING_CONFIG_FAILED;
718e3744 5687
d62a17ae 5688 ret = peer_weight_unset(peer, afi, safi);
5689 return bgp_vty_return(vty, ret);
718e3744 5690}
5691
5692DEFUN (neighbor_weight,
5693 neighbor_weight_cmd,
9ccf14f7 5694 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5695 NEIGHBOR_STR
5696 NEIGHBOR_ADDR_STR2
5697 "Set default weight for routes from this neighbor\n"
5698 "default weight\n")
5699{
d62a17ae 5700 int idx_peer = 1;
5701 int idx_number = 3;
5702 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5703 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5704}
5705
d62a17ae 5706ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5707 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5708 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5709 "Set default weight for routes from this neighbor\n"
5710 "default weight\n")
596c17ba 5711
718e3744 5712DEFUN (no_neighbor_weight,
5713 no_neighbor_weight_cmd,
9ccf14f7 5714 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5715 NO_STR
5716 NEIGHBOR_STR
5717 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5718 "Set default weight for routes from this neighbor\n"
5719 "default weight\n")
718e3744 5720{
d62a17ae 5721 int idx_peer = 2;
5722 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5723 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5724}
5725
d62a17ae 5726ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5727 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5728 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5729 "Set default weight for routes from this neighbor\n"
5730 "default weight\n")
596c17ba 5731
6b0655a2 5732
718e3744 5733/* Override capability negotiation. */
5734DEFUN (neighbor_override_capability,
5735 neighbor_override_capability_cmd,
9ccf14f7 5736 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5737 NEIGHBOR_STR
5738 NEIGHBOR_ADDR_STR2
5739 "Override capability negotiation result\n")
5740{
d62a17ae 5741 int idx_peer = 1;
5742 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5743 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5744}
5745
5746DEFUN (no_neighbor_override_capability,
5747 no_neighbor_override_capability_cmd,
9ccf14f7 5748 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5749 NO_STR
5750 NEIGHBOR_STR
5751 NEIGHBOR_ADDR_STR2
5752 "Override capability negotiation result\n")
5753{
d62a17ae 5754 int idx_peer = 2;
5755 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5756 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5757}
6b0655a2 5758
718e3744 5759DEFUN (neighbor_strict_capability,
5760 neighbor_strict_capability_cmd,
9fb964de 5761 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5762 NEIGHBOR_STR
9fb964de 5763 NEIGHBOR_ADDR_STR2
718e3744 5764 "Strict capability negotiation match\n")
5765{
9fb964de
PM
5766 int idx_peer = 1;
5767
5768 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5769 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5770}
5771
5772DEFUN (no_neighbor_strict_capability,
5773 no_neighbor_strict_capability_cmd,
9fb964de 5774 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5775 NO_STR
5776 NEIGHBOR_STR
9fb964de 5777 NEIGHBOR_ADDR_STR2
718e3744 5778 "Strict capability negotiation match\n")
5779{
9fb964de
PM
5780 int idx_peer = 2;
5781
5782 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5783 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5784}
6b0655a2 5785
d62a17ae 5786static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5787 const char *keep_str, const char *hold_str)
718e3744 5788{
d62a17ae 5789 int ret;
5790 struct peer *peer;
d7c0a89a
QY
5791 uint32_t keepalive;
5792 uint32_t holdtime;
718e3744 5793
d62a17ae 5794 peer = peer_and_group_lookup_vty(vty, ip_str);
5795 if (!peer)
5796 return CMD_WARNING_CONFIG_FAILED;
718e3744 5797
d62a17ae 5798 keepalive = strtoul(keep_str, NULL, 10);
5799 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5800
d62a17ae 5801 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5802
d62a17ae 5803 return bgp_vty_return(vty, ret);
718e3744 5804}
6b0655a2 5805
d62a17ae 5806static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5807{
d62a17ae 5808 int ret;
5809 struct peer *peer;
718e3744 5810
d62a17ae 5811 peer = peer_and_group_lookup_vty(vty, ip_str);
5812 if (!peer)
5813 return CMD_WARNING_CONFIG_FAILED;
718e3744 5814
d62a17ae 5815 ret = peer_timers_unset(peer);
718e3744 5816
d62a17ae 5817 return bgp_vty_return(vty, ret);
718e3744 5818}
5819
5820DEFUN (neighbor_timers,
5821 neighbor_timers_cmd,
9ccf14f7 5822 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5823 NEIGHBOR_STR
5824 NEIGHBOR_ADDR_STR2
5825 "BGP per neighbor timers\n"
5826 "Keepalive interval\n"
5827 "Holdtime\n")
5828{
d62a17ae 5829 int idx_peer = 1;
5830 int idx_number = 3;
5831 int idx_number_2 = 4;
5832 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5833 argv[idx_number]->arg,
5834 argv[idx_number_2]->arg);
718e3744 5835}
5836
5837DEFUN (no_neighbor_timers,
5838 no_neighbor_timers_cmd,
9ccf14f7 5839 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5840 NO_STR
5841 NEIGHBOR_STR
5842 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5843 "BGP per neighbor timers\n"
5844 "Keepalive interval\n"
5845 "Holdtime\n")
718e3744 5846{
d62a17ae 5847 int idx_peer = 2;
5848 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5849}
6b0655a2 5850
813d4307 5851
d62a17ae 5852static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5853 const char *time_str)
718e3744 5854{
d62a17ae 5855 int ret;
5856 struct peer *peer;
d7c0a89a 5857 uint32_t connect;
718e3744 5858
d62a17ae 5859 peer = peer_and_group_lookup_vty(vty, ip_str);
5860 if (!peer)
5861 return CMD_WARNING_CONFIG_FAILED;
718e3744 5862
d62a17ae 5863 connect = strtoul(time_str, NULL, 10);
718e3744 5864
d62a17ae 5865 ret = peer_timers_connect_set(peer, connect);
718e3744 5866
d62a17ae 5867 return bgp_vty_return(vty, ret);
718e3744 5868}
5869
d62a17ae 5870static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5871{
d62a17ae 5872 int ret;
5873 struct peer *peer;
718e3744 5874
d62a17ae 5875 peer = peer_and_group_lookup_vty(vty, ip_str);
5876 if (!peer)
5877 return CMD_WARNING_CONFIG_FAILED;
718e3744 5878
d62a17ae 5879 ret = peer_timers_connect_unset(peer);
718e3744 5880
d62a17ae 5881 return bgp_vty_return(vty, ret);
718e3744 5882}
5883
5884DEFUN (neighbor_timers_connect,
5885 neighbor_timers_connect_cmd,
9ccf14f7 5886 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5887 NEIGHBOR_STR
966f821c 5888 NEIGHBOR_ADDR_STR2
718e3744 5889 "BGP per neighbor timers\n"
5890 "BGP connect timer\n"
5891 "Connect timer\n")
5892{
d62a17ae 5893 int idx_peer = 1;
5894 int idx_number = 4;
5895 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5896 argv[idx_number]->arg);
718e3744 5897}
5898
5899DEFUN (no_neighbor_timers_connect,
5900 no_neighbor_timers_connect_cmd,
9ccf14f7 5901 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5902 NO_STR
5903 NEIGHBOR_STR
966f821c 5904 NEIGHBOR_ADDR_STR2
718e3744 5905 "BGP per neighbor timers\n"
8334fd5a
DW
5906 "BGP connect timer\n"
5907 "Connect timer\n")
718e3744 5908{
d62a17ae 5909 int idx_peer = 2;
5910 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5911}
5912
6b0655a2 5913
d62a17ae 5914static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5915 const char *time_str, int set)
718e3744 5916{
d62a17ae 5917 int ret;
5918 struct peer *peer;
d7c0a89a 5919 uint32_t routeadv = 0;
718e3744 5920
d62a17ae 5921 peer = peer_and_group_lookup_vty(vty, ip_str);
5922 if (!peer)
5923 return CMD_WARNING_CONFIG_FAILED;
718e3744 5924
d62a17ae 5925 if (time_str)
5926 routeadv = strtoul(time_str, NULL, 10);
718e3744 5927
d62a17ae 5928 if (set)
5929 ret = peer_advertise_interval_set(peer, routeadv);
5930 else
5931 ret = peer_advertise_interval_unset(peer);
718e3744 5932
d62a17ae 5933 return bgp_vty_return(vty, ret);
718e3744 5934}
5935
5936DEFUN (neighbor_advertise_interval,
5937 neighbor_advertise_interval_cmd,
9ccf14f7 5938 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5939 NEIGHBOR_STR
966f821c 5940 NEIGHBOR_ADDR_STR2
718e3744 5941 "Minimum interval between sending BGP routing updates\n"
5942 "time in seconds\n")
5943{
d62a17ae 5944 int idx_peer = 1;
5945 int idx_number = 3;
5946 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5947 argv[idx_number]->arg, 1);
718e3744 5948}
5949
5950DEFUN (no_neighbor_advertise_interval,
5951 no_neighbor_advertise_interval_cmd,
9ccf14f7 5952 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5953 NO_STR
5954 NEIGHBOR_STR
966f821c 5955 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5956 "Minimum interval between sending BGP routing updates\n"
5957 "time in seconds\n")
718e3744 5958{
d62a17ae 5959 int idx_peer = 2;
5960 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5961}
5962
6b0655a2 5963
518f0eb1
DS
5964/* Time to wait before processing route-map updates */
5965DEFUN (bgp_set_route_map_delay_timer,
5966 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5967 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5968 SET_STR
5969 "BGP route-map delay timer\n"
5970 "Time in secs to wait before processing route-map changes\n"
f414725f 5971 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5972{
d62a17ae 5973 int idx_number = 3;
d7c0a89a 5974 uint32_t rmap_delay_timer;
d62a17ae 5975
5976 if (argv[idx_number]->arg) {
5977 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5978 bm->rmap_update_timer = rmap_delay_timer;
5979
5980 /* if the dynamic update handling is being disabled, and a timer
5981 * is
5982 * running, stop the timer and act as if the timer has already
5983 * fired.
5984 */
5985 if (!rmap_delay_timer && bm->t_rmap_update) {
5986 BGP_TIMER_OFF(bm->t_rmap_update);
5987 thread_execute(bm->master, bgp_route_map_update_timer,
5988 NULL, 0);
5989 }
5990 return CMD_SUCCESS;
5991 } else {
5992 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5993 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5994 }
518f0eb1
DS
5995}
5996
5997DEFUN (no_bgp_set_route_map_delay_timer,
5998 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5999 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6000 NO_STR
3a2d747c 6001 BGP_STR
518f0eb1 6002 "Default BGP route-map delay timer\n"
8334fd5a
DW
6003 "Reset to default time to wait for processing route-map changes\n"
6004 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6005{
518f0eb1 6006
d62a17ae 6007 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6008
d62a17ae 6009 return CMD_SUCCESS;
518f0eb1
DS
6010}
6011
f414725f 6012
718e3744 6013/* neighbor interface */
d62a17ae 6014static int peer_interface_vty(struct vty *vty, const char *ip_str,
6015 const char *str)
718e3744 6016{
d62a17ae 6017 struct peer *peer;
718e3744 6018
d62a17ae 6019 peer = peer_lookup_vty(vty, ip_str);
6020 if (!peer || peer->conf_if) {
6021 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6022 return CMD_WARNING_CONFIG_FAILED;
6023 }
718e3744 6024
d62a17ae 6025 if (str)
6026 peer_interface_set(peer, str);
6027 else
6028 peer_interface_unset(peer);
718e3744 6029
d62a17ae 6030 return CMD_SUCCESS;
718e3744 6031}
6032
6033DEFUN (neighbor_interface,
6034 neighbor_interface_cmd,
9ccf14f7 6035 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6036 NEIGHBOR_STR
6037 NEIGHBOR_ADDR_STR
6038 "Interface\n"
6039 "Interface name\n")
6040{
d62a17ae 6041 int idx_ip = 1;
6042 int idx_word = 3;
6043 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6044}
6045
6046DEFUN (no_neighbor_interface,
6047 no_neighbor_interface_cmd,
9ccf14f7 6048 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6049 NO_STR
6050 NEIGHBOR_STR
16cedbb0 6051 NEIGHBOR_ADDR_STR2
718e3744 6052 "Interface\n"
6053 "Interface name\n")
6054{
d62a17ae 6055 int idx_peer = 2;
6056 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6057}
6b0655a2 6058
718e3744 6059DEFUN (neighbor_distribute_list,
6060 neighbor_distribute_list_cmd,
9ccf14f7 6061 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6062 NEIGHBOR_STR
6063 NEIGHBOR_ADDR_STR2
6064 "Filter updates to/from this neighbor\n"
6065 "IP access-list number\n"
6066 "IP access-list number (expanded range)\n"
6067 "IP Access-list name\n"
6068 "Filter incoming updates\n"
6069 "Filter outgoing updates\n")
6070{
d62a17ae 6071 int idx_peer = 1;
6072 int idx_acl = 3;
6073 int direct, ret;
6074 struct peer *peer;
a8206004 6075
d62a17ae 6076 const char *pstr = argv[idx_peer]->arg;
6077 const char *acl = argv[idx_acl]->arg;
6078 const char *inout = argv[argc - 1]->text;
a8206004 6079
d62a17ae 6080 peer = peer_and_group_lookup_vty(vty, pstr);
6081 if (!peer)
6082 return CMD_WARNING_CONFIG_FAILED;
a8206004 6083
d62a17ae 6084 /* Check filter direction. */
6085 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6086 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6087 direct, acl);
a8206004 6088
d62a17ae 6089 return bgp_vty_return(vty, ret);
718e3744 6090}
6091
d62a17ae 6092ALIAS_HIDDEN(
6093 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6094 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6096 "Filter updates to/from this neighbor\n"
6097 "IP access-list number\n"
6098 "IP access-list number (expanded range)\n"
6099 "IP Access-list name\n"
6100 "Filter incoming updates\n"
6101 "Filter outgoing updates\n")
596c17ba 6102
718e3744 6103DEFUN (no_neighbor_distribute_list,
6104 no_neighbor_distribute_list_cmd,
9ccf14f7 6105 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6106 NO_STR
6107 NEIGHBOR_STR
6108 NEIGHBOR_ADDR_STR2
6109 "Filter updates to/from this neighbor\n"
6110 "IP access-list number\n"
6111 "IP access-list number (expanded range)\n"
6112 "IP Access-list name\n"
6113 "Filter incoming updates\n"
6114 "Filter outgoing updates\n")
6115{
d62a17ae 6116 int idx_peer = 2;
6117 int direct, ret;
6118 struct peer *peer;
a8206004 6119
d62a17ae 6120 const char *pstr = argv[idx_peer]->arg;
6121 const char *inout = argv[argc - 1]->text;
a8206004 6122
d62a17ae 6123 peer = peer_and_group_lookup_vty(vty, pstr);
6124 if (!peer)
6125 return CMD_WARNING_CONFIG_FAILED;
a8206004 6126
d62a17ae 6127 /* Check filter direction. */
6128 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6129 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6130 direct);
a8206004 6131
d62a17ae 6132 return bgp_vty_return(vty, ret);
718e3744 6133}
6b0655a2 6134
d62a17ae 6135ALIAS_HIDDEN(
6136 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6137 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6138 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6139 "Filter updates to/from this neighbor\n"
6140 "IP access-list number\n"
6141 "IP access-list number (expanded range)\n"
6142 "IP Access-list name\n"
6143 "Filter incoming updates\n"
6144 "Filter outgoing updates\n")
596c17ba 6145
718e3744 6146/* Set prefix list to the peer. */
d62a17ae 6147static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6148 afi_t afi, safi_t safi,
6149 const char *name_str,
6150 const char *direct_str)
718e3744 6151{
d62a17ae 6152 int ret;
d62a17ae 6153 int direct = FILTER_IN;
cf9ac8bf 6154 struct peer *peer;
718e3744 6155
d62a17ae 6156 peer = peer_and_group_lookup_vty(vty, ip_str);
6157 if (!peer)
6158 return CMD_WARNING_CONFIG_FAILED;
718e3744 6159
d62a17ae 6160 /* Check filter direction. */
6161 if (strncmp(direct_str, "i", 1) == 0)
6162 direct = FILTER_IN;
6163 else if (strncmp(direct_str, "o", 1) == 0)
6164 direct = FILTER_OUT;
718e3744 6165
d62a17ae 6166 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6167
d62a17ae 6168 return bgp_vty_return(vty, ret);
718e3744 6169}
6170
d62a17ae 6171static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6172 afi_t afi, safi_t safi,
6173 const char *direct_str)
718e3744 6174{
d62a17ae 6175 int ret;
6176 struct peer *peer;
6177 int direct = FILTER_IN;
718e3744 6178
d62a17ae 6179 peer = peer_and_group_lookup_vty(vty, ip_str);
6180 if (!peer)
6181 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6182
d62a17ae 6183 /* Check filter direction. */
6184 if (strncmp(direct_str, "i", 1) == 0)
6185 direct = FILTER_IN;
6186 else if (strncmp(direct_str, "o", 1) == 0)
6187 direct = FILTER_OUT;
718e3744 6188
d62a17ae 6189 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6190
d62a17ae 6191 return bgp_vty_return(vty, ret);
718e3744 6192}
6193
6194DEFUN (neighbor_prefix_list,
6195 neighbor_prefix_list_cmd,
9ccf14f7 6196 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6197 NEIGHBOR_STR
6198 NEIGHBOR_ADDR_STR2
6199 "Filter updates to/from this neighbor\n"
6200 "Name of a prefix list\n"
6201 "Filter incoming updates\n"
6202 "Filter outgoing updates\n")
6203{
d62a17ae 6204 int idx_peer = 1;
6205 int idx_word = 3;
6206 int idx_in_out = 4;
6207 return peer_prefix_list_set_vty(
6208 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6209 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6210}
6211
d62a17ae 6212ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6213 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6214 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6215 "Filter updates to/from this neighbor\n"
6216 "Name of a prefix list\n"
6217 "Filter incoming updates\n"
6218 "Filter outgoing updates\n")
596c17ba 6219
718e3744 6220DEFUN (no_neighbor_prefix_list,
6221 no_neighbor_prefix_list_cmd,
9ccf14f7 6222 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6223 NO_STR
6224 NEIGHBOR_STR
6225 NEIGHBOR_ADDR_STR2
6226 "Filter updates to/from this neighbor\n"
6227 "Name of a prefix list\n"
6228 "Filter incoming updates\n"
6229 "Filter outgoing updates\n")
6230{
d62a17ae 6231 int idx_peer = 2;
6232 int idx_in_out = 5;
6233 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6234 bgp_node_afi(vty), bgp_node_safi(vty),
6235 argv[idx_in_out]->arg);
718e3744 6236}
6b0655a2 6237
d62a17ae 6238ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6239 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6240 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6241 "Filter updates to/from this neighbor\n"
6242 "Name of a prefix list\n"
6243 "Filter incoming updates\n"
6244 "Filter outgoing updates\n")
596c17ba 6245
d62a17ae 6246static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6247 safi_t safi, const char *name_str,
6248 const char *direct_str)
718e3744 6249{
d62a17ae 6250 int ret;
6251 struct peer *peer;
6252 int direct = FILTER_IN;
718e3744 6253
d62a17ae 6254 peer = peer_and_group_lookup_vty(vty, ip_str);
6255 if (!peer)
6256 return CMD_WARNING_CONFIG_FAILED;
718e3744 6257
d62a17ae 6258 /* Check filter direction. */
6259 if (strncmp(direct_str, "i", 1) == 0)
6260 direct = FILTER_IN;
6261 else if (strncmp(direct_str, "o", 1) == 0)
6262 direct = FILTER_OUT;
718e3744 6263
d62a17ae 6264 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6265
d62a17ae 6266 return bgp_vty_return(vty, ret);
718e3744 6267}
6268
d62a17ae 6269static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6270 safi_t safi, const char *direct_str)
718e3744 6271{
d62a17ae 6272 int ret;
6273 struct peer *peer;
6274 int direct = FILTER_IN;
718e3744 6275
d62a17ae 6276 peer = peer_and_group_lookup_vty(vty, ip_str);
6277 if (!peer)
6278 return CMD_WARNING_CONFIG_FAILED;
718e3744 6279
d62a17ae 6280 /* Check filter direction. */
6281 if (strncmp(direct_str, "i", 1) == 0)
6282 direct = FILTER_IN;
6283 else if (strncmp(direct_str, "o", 1) == 0)
6284 direct = FILTER_OUT;
718e3744 6285
d62a17ae 6286 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6287
d62a17ae 6288 return bgp_vty_return(vty, ret);
718e3744 6289}
6290
6291DEFUN (neighbor_filter_list,
6292 neighbor_filter_list_cmd,
9ccf14f7 6293 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6294 NEIGHBOR_STR
6295 NEIGHBOR_ADDR_STR2
6296 "Establish BGP filters\n"
6297 "AS path access-list name\n"
6298 "Filter incoming routes\n"
6299 "Filter outgoing routes\n")
6300{
d62a17ae 6301 int idx_peer = 1;
6302 int idx_word = 3;
6303 int idx_in_out = 4;
6304 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6305 bgp_node_safi(vty), argv[idx_word]->arg,
6306 argv[idx_in_out]->arg);
718e3744 6307}
6308
d62a17ae 6309ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6310 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6311 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6312 "Establish BGP filters\n"
6313 "AS path access-list name\n"
6314 "Filter incoming routes\n"
6315 "Filter outgoing routes\n")
596c17ba 6316
718e3744 6317DEFUN (no_neighbor_filter_list,
6318 no_neighbor_filter_list_cmd,
9ccf14f7 6319 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6320 NO_STR
6321 NEIGHBOR_STR
6322 NEIGHBOR_ADDR_STR2
6323 "Establish BGP filters\n"
6324 "AS path access-list name\n"
6325 "Filter incoming routes\n"
6326 "Filter outgoing routes\n")
6327{
d62a17ae 6328 int idx_peer = 2;
6329 int idx_in_out = 5;
6330 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6331 bgp_node_afi(vty), bgp_node_safi(vty),
6332 argv[idx_in_out]->arg);
718e3744 6333}
6b0655a2 6334
d62a17ae 6335ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6336 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6337 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6338 "Establish BGP filters\n"
6339 "AS path access-list name\n"
6340 "Filter incoming routes\n"
6341 "Filter outgoing routes\n")
596c17ba 6342
718e3744 6343/* Set route-map to the peer. */
d62a17ae 6344static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6345 afi_t afi, safi_t safi, const char *name_str,
6346 const char *direct_str)
718e3744 6347{
d62a17ae 6348 int ret;
6349 struct peer *peer;
6350 int direct = RMAP_IN;
1de27621 6351 struct route_map *route_map;
718e3744 6352
d62a17ae 6353 peer = peer_and_group_lookup_vty(vty, ip_str);
6354 if (!peer)
6355 return CMD_WARNING_CONFIG_FAILED;
718e3744 6356
d62a17ae 6357 /* Check filter direction. */
6358 if (strncmp(direct_str, "in", 2) == 0)
6359 direct = RMAP_IN;
6360 else if (strncmp(direct_str, "o", 1) == 0)
6361 direct = RMAP_OUT;
718e3744 6362
1de27621
DA
6363 route_map = route_map_lookup_warn_noexist(vty, name_str);
6364 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 6365
d62a17ae 6366 return bgp_vty_return(vty, ret);
718e3744 6367}
6368
d62a17ae 6369static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6370 afi_t afi, safi_t safi,
6371 const char *direct_str)
718e3744 6372{
d62a17ae 6373 int ret;
6374 struct peer *peer;
6375 int direct = RMAP_IN;
718e3744 6376
d62a17ae 6377 peer = peer_and_group_lookup_vty(vty, ip_str);
6378 if (!peer)
6379 return CMD_WARNING_CONFIG_FAILED;
718e3744 6380
d62a17ae 6381 /* Check filter direction. */
6382 if (strncmp(direct_str, "in", 2) == 0)
6383 direct = RMAP_IN;
6384 else if (strncmp(direct_str, "o", 1) == 0)
6385 direct = RMAP_OUT;
718e3744 6386
d62a17ae 6387 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 6388
d62a17ae 6389 return bgp_vty_return(vty, ret);
718e3744 6390}
6391
6392DEFUN (neighbor_route_map,
6393 neighbor_route_map_cmd,
9ccf14f7 6394 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6395 NEIGHBOR_STR
6396 NEIGHBOR_ADDR_STR2
6397 "Apply route map to neighbor\n"
6398 "Name of route map\n"
6399 "Apply map to incoming routes\n"
2a3d5731 6400 "Apply map to outbound routes\n")
718e3744 6401{
d62a17ae 6402 int idx_peer = 1;
6403 int idx_word = 3;
6404 int idx_in_out = 4;
6405 return peer_route_map_set_vty(
6406 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6407 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6408}
6409
d62a17ae 6410ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6411 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6412 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "Apply route map to neighbor\n"
6414 "Name of route map\n"
6415 "Apply map to incoming routes\n"
6416 "Apply map to outbound routes\n")
596c17ba 6417
718e3744 6418DEFUN (no_neighbor_route_map,
6419 no_neighbor_route_map_cmd,
9ccf14f7 6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
6424 "Apply route map to neighbor\n"
6425 "Name of route map\n"
6426 "Apply map to incoming routes\n"
2a3d5731 6427 "Apply map to outbound routes\n")
718e3744 6428{
d62a17ae 6429 int idx_peer = 2;
6430 int idx_in_out = 5;
6431 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6432 bgp_node_afi(vty), bgp_node_safi(vty),
6433 argv[idx_in_out]->arg);
718e3744 6434}
6b0655a2 6435
d62a17ae 6436ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6437 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6438 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6439 "Apply route map to neighbor\n"
6440 "Name of route map\n"
6441 "Apply map to incoming routes\n"
6442 "Apply map to outbound routes\n")
596c17ba 6443
718e3744 6444/* Set unsuppress-map to the peer. */
d62a17ae 6445static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6446 afi_t afi, safi_t safi,
6447 const char *name_str)
718e3744 6448{
d62a17ae 6449 int ret;
6450 struct peer *peer;
1de27621 6451 struct route_map *route_map;
718e3744 6452
d62a17ae 6453 peer = peer_and_group_lookup_vty(vty, ip_str);
6454 if (!peer)
6455 return CMD_WARNING_CONFIG_FAILED;
718e3744 6456
1de27621
DA
6457 route_map = route_map_lookup_warn_noexist(vty, name_str);
6458 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 6459
d62a17ae 6460 return bgp_vty_return(vty, ret);
718e3744 6461}
6462
6463/* Unset route-map from the peer. */
d62a17ae 6464static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6465 afi_t afi, safi_t safi)
718e3744 6466{
d62a17ae 6467 int ret;
6468 struct peer *peer;
718e3744 6469
d62a17ae 6470 peer = peer_and_group_lookup_vty(vty, ip_str);
6471 if (!peer)
6472 return CMD_WARNING_CONFIG_FAILED;
718e3744 6473
d62a17ae 6474 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 6475
d62a17ae 6476 return bgp_vty_return(vty, ret);
718e3744 6477}
6478
6479DEFUN (neighbor_unsuppress_map,
6480 neighbor_unsuppress_map_cmd,
9ccf14f7 6481 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6482 NEIGHBOR_STR
6483 NEIGHBOR_ADDR_STR2
6484 "Route-map to selectively unsuppress suppressed routes\n"
6485 "Name of route map\n")
6486{
d62a17ae 6487 int idx_peer = 1;
6488 int idx_word = 3;
6489 return peer_unsuppress_map_set_vty(
6490 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6491 argv[idx_word]->arg);
718e3744 6492}
6493
d62a17ae 6494ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6495 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6496 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6497 "Route-map to selectively unsuppress suppressed routes\n"
6498 "Name of route map\n")
596c17ba 6499
718e3744 6500DEFUN (no_neighbor_unsuppress_map,
6501 no_neighbor_unsuppress_map_cmd,
9ccf14f7 6502 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6503 NO_STR
6504 NEIGHBOR_STR
6505 NEIGHBOR_ADDR_STR2
6506 "Route-map to selectively unsuppress suppressed routes\n"
6507 "Name of route map\n")
6508{
d62a17ae 6509 int idx_peer = 2;
6510 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6511 bgp_node_afi(vty),
6512 bgp_node_safi(vty));
718e3744 6513}
6b0655a2 6514
d62a17ae 6515ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6516 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6518 "Route-map to selectively unsuppress suppressed routes\n"
6519 "Name of route map\n")
596c17ba 6520
d62a17ae 6521static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6522 afi_t afi, safi_t safi,
6523 const char *num_str,
6524 const char *threshold_str, int warning,
6525 const char *restart_str)
718e3744 6526{
d62a17ae 6527 int ret;
6528 struct peer *peer;
d7c0a89a
QY
6529 uint32_t max;
6530 uint8_t threshold;
6531 uint16_t restart;
718e3744 6532
d62a17ae 6533 peer = peer_and_group_lookup_vty(vty, ip_str);
6534 if (!peer)
6535 return CMD_WARNING_CONFIG_FAILED;
718e3744 6536
d62a17ae 6537 max = strtoul(num_str, NULL, 10);
6538 if (threshold_str)
6539 threshold = atoi(threshold_str);
6540 else
6541 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 6542
d62a17ae 6543 if (restart_str)
6544 restart = atoi(restart_str);
6545 else
6546 restart = 0;
0a486e5f 6547
d62a17ae 6548 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6549 restart);
718e3744 6550
d62a17ae 6551 return bgp_vty_return(vty, ret);
718e3744 6552}
6553
d62a17ae 6554static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6555 afi_t afi, safi_t safi)
718e3744 6556{
d62a17ae 6557 int ret;
6558 struct peer *peer;
718e3744 6559
d62a17ae 6560 peer = peer_and_group_lookup_vty(vty, ip_str);
6561 if (!peer)
6562 return CMD_WARNING_CONFIG_FAILED;
718e3744 6563
d62a17ae 6564 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 6565
d62a17ae 6566 return bgp_vty_return(vty, ret);
718e3744 6567}
6568
fde246e8
DA
6569/* Maximum number of prefix to be sent to the neighbor. */
6570DEFUN(neighbor_maximum_prefix_out,
6571 neighbor_maximum_prefix_out_cmd,
6572 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6573 NEIGHBOR_STR
6574 NEIGHBOR_ADDR_STR2
6575 "Maximum number of prefixes to be sent to this peer\n"
6576 "Maximum no. of prefix limit\n")
6577{
6578 int idx_peer = 1;
6579 int idx_number = 3;
6580 struct peer *peer;
6581 uint32_t max;
6582 afi_t afi = bgp_node_afi(vty);
6583 safi_t safi = bgp_node_safi(vty);
6584
6585 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6586 if (!peer)
6587 return CMD_WARNING_CONFIG_FAILED;
6588
6589 max = strtoul(argv[idx_number]->arg, NULL, 10);
6590
6591 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6592 peer->pmax_out[afi][safi] = max;
6593
6594 return CMD_SUCCESS;
6595}
6596
6597DEFUN(no_neighbor_maximum_prefix_out,
6598 no_neighbor_maximum_prefix_out_cmd,
6599 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6600 NO_STR
6601 NEIGHBOR_STR
6602 NEIGHBOR_ADDR_STR2
6603 "Maximum number of prefixes to be sent to this peer\n")
6604{
6605 int idx_peer = 2;
6606 struct peer *peer;
6607 afi_t afi = bgp_node_afi(vty);
6608 safi_t safi = bgp_node_safi(vty);
6609
6610 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6611 if (!peer)
6612 return CMD_WARNING_CONFIG_FAILED;
6613
6614 peer->pmax_out[afi][safi] = 0;
6615
6616 return CMD_SUCCESS;
6617}
6618
718e3744 6619/* Maximum number of prefix configuration. prefix count is different
6620 for each peer configuration. So this configuration can be set for
6621 each peer configuration. */
6622DEFUN (neighbor_maximum_prefix,
6623 neighbor_maximum_prefix_cmd,
9ccf14f7 6624 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 6625 NEIGHBOR_STR
6626 NEIGHBOR_ADDR_STR2
6627 "Maximum number of prefix accept from this peer\n"
6628 "maximum no. of prefix limit\n")
6629{
d62a17ae 6630 int idx_peer = 1;
6631 int idx_number = 3;
6632 return peer_maximum_prefix_set_vty(
6633 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6634 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 6635}
6636
d62a17ae 6637ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6639 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6640 "Maximum number of prefix accept from this peer\n"
6641 "maximum no. of prefix limit\n")
596c17ba 6642
e0701b79 6643DEFUN (neighbor_maximum_prefix_threshold,
6644 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 6645 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 6646 NEIGHBOR_STR
6647 NEIGHBOR_ADDR_STR2
6648 "Maximum number of prefix accept from this peer\n"
6649 "maximum no. of prefix limit\n"
6650 "Threshold value (%) at which to generate a warning msg\n")
6651{
d62a17ae 6652 int idx_peer = 1;
6653 int idx_number = 3;
6654 int idx_number_2 = 4;
6655 return peer_maximum_prefix_set_vty(
6656 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6657 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 6658}
e0701b79 6659
d62a17ae 6660ALIAS_HIDDEN(
6661 neighbor_maximum_prefix_threshold,
6662 neighbor_maximum_prefix_threshold_hidden_cmd,
6663 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6664 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6665 "Maximum number of prefix accept from this peer\n"
6666 "maximum no. of prefix limit\n"
6667 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 6668
718e3744 6669DEFUN (neighbor_maximum_prefix_warning,
6670 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 6671 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6672 NEIGHBOR_STR
6673 NEIGHBOR_ADDR_STR2
6674 "Maximum number of prefix accept from this peer\n"
6675 "maximum no. of prefix limit\n"
6676 "Only give warning message when limit is exceeded\n")
6677{
d62a17ae 6678 int idx_peer = 1;
6679 int idx_number = 3;
6680 return peer_maximum_prefix_set_vty(
6681 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6682 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6683}
6684
d62a17ae 6685ALIAS_HIDDEN(
6686 neighbor_maximum_prefix_warning,
6687 neighbor_maximum_prefix_warning_hidden_cmd,
6688 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6689 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6690 "Maximum number of prefix accept from this peer\n"
6691 "maximum no. of prefix limit\n"
6692 "Only give warning message when limit is exceeded\n")
596c17ba 6693
e0701b79 6694DEFUN (neighbor_maximum_prefix_threshold_warning,
6695 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6696 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6697 NEIGHBOR_STR
6698 NEIGHBOR_ADDR_STR2
6699 "Maximum number of prefix accept from this peer\n"
6700 "maximum no. of prefix limit\n"
6701 "Threshold value (%) at which to generate a warning msg\n"
6702 "Only give warning message when limit is exceeded\n")
6703{
d62a17ae 6704 int idx_peer = 1;
6705 int idx_number = 3;
6706 int idx_number_2 = 4;
6707 return peer_maximum_prefix_set_vty(
6708 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6709 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6710}
6711
d62a17ae 6712ALIAS_HIDDEN(
6713 neighbor_maximum_prefix_threshold_warning,
6714 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6715 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6716 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6717 "Maximum number of prefix accept from this peer\n"
6718 "maximum no. of prefix limit\n"
6719 "Threshold value (%) at which to generate a warning msg\n"
6720 "Only give warning message when limit is exceeded\n")
596c17ba 6721
0a486e5f 6722DEFUN (neighbor_maximum_prefix_restart,
6723 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6724 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6725 NEIGHBOR_STR
6726 NEIGHBOR_ADDR_STR2
6727 "Maximum number of prefix accept from this peer\n"
6728 "maximum no. of prefix limit\n"
6729 "Restart bgp connection after limit is exceeded\n"
efd7904e 6730 "Restart interval in minutes\n")
0a486e5f 6731{
d62a17ae 6732 int idx_peer = 1;
6733 int idx_number = 3;
6734 int idx_number_2 = 5;
6735 return peer_maximum_prefix_set_vty(
6736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6737 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6738}
6739
d62a17ae 6740ALIAS_HIDDEN(
6741 neighbor_maximum_prefix_restart,
6742 neighbor_maximum_prefix_restart_hidden_cmd,
6743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6745 "Maximum number of prefix accept from this peer\n"
6746 "maximum no. of prefix limit\n"
6747 "Restart bgp connection after limit is exceeded\n"
efd7904e 6748 "Restart interval in minutes\n")
596c17ba 6749
0a486e5f 6750DEFUN (neighbor_maximum_prefix_threshold_restart,
6751 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6752 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6753 NEIGHBOR_STR
6754 NEIGHBOR_ADDR_STR2
16cedbb0 6755 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6756 "maximum no. of prefix limit\n"
6757 "Threshold value (%) at which to generate a warning msg\n"
6758 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6759 "Restart interval in minutes\n")
0a486e5f 6760{
d62a17ae 6761 int idx_peer = 1;
6762 int idx_number = 3;
6763 int idx_number_2 = 4;
6764 int idx_number_3 = 6;
6765 return peer_maximum_prefix_set_vty(
6766 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6767 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6768 argv[idx_number_3]->arg);
6769}
6770
6771ALIAS_HIDDEN(
6772 neighbor_maximum_prefix_threshold_restart,
6773 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6774 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6775 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6776 "Maximum number of prefixes to accept from this peer\n"
6777 "maximum no. of prefix limit\n"
6778 "Threshold value (%) at which to generate a warning msg\n"
6779 "Restart bgp connection after limit is exceeded\n"
6780 "Restart interval in minutes\n")
596c17ba 6781
718e3744 6782DEFUN (no_neighbor_maximum_prefix,
6783 no_neighbor_maximum_prefix_cmd,
d04c479d 6784 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6785 NO_STR
6786 NEIGHBOR_STR
6787 NEIGHBOR_ADDR_STR2
16cedbb0 6788 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6789 "maximum no. of prefix limit\n"
6790 "Threshold value (%) at which to generate a warning msg\n"
6791 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6792 "Restart interval in minutes\n"
31500417 6793 "Only give warning message when limit is exceeded\n")
718e3744 6794{
d62a17ae 6795 int idx_peer = 2;
6796 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6797 bgp_node_afi(vty),
6798 bgp_node_safi(vty));
718e3744 6799}
e52702f2 6800
d62a17ae 6801ALIAS_HIDDEN(
6802 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6803 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6804 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6805 "Maximum number of prefixes to accept from this peer\n"
6806 "maximum no. of prefix limit\n"
6807 "Threshold value (%) at which to generate a warning msg\n"
6808 "Restart bgp connection after limit is exceeded\n"
6809 "Restart interval in minutes\n"
6810 "Only give warning message when limit is exceeded\n")
596c17ba 6811
718e3744 6812
718e3744 6813/* "neighbor allowas-in" */
6814DEFUN (neighbor_allowas_in,
6815 neighbor_allowas_in_cmd,
fd8503f5 6816 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6817 NEIGHBOR_STR
6818 NEIGHBOR_ADDR_STR2
31500417 6819 "Accept as-path with my AS present in it\n"
f79f7a7b 6820 "Number of occurrences of AS number\n"
fd8503f5 6821 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6822{
d62a17ae 6823 int idx_peer = 1;
6824 int idx_number_origin = 3;
6825 int ret;
6826 int origin = 0;
6827 struct peer *peer;
6828 int allow_num = 0;
6829
6830 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6831 if (!peer)
6832 return CMD_WARNING_CONFIG_FAILED;
6833
6834 if (argc <= idx_number_origin)
6835 allow_num = 3;
6836 else {
6837 if (argv[idx_number_origin]->type == WORD_TKN)
6838 origin = 1;
6839 else
6840 allow_num = atoi(argv[idx_number_origin]->arg);
6841 }
6842
6843 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6844 allow_num, origin);
6845
6846 return bgp_vty_return(vty, ret);
6847}
6848
6849ALIAS_HIDDEN(
6850 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6851 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6852 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6853 "Accept as-path with my AS present in it\n"
f79f7a7b 6854 "Number of occurrences of AS number\n"
d62a17ae 6855 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6856
718e3744 6857DEFUN (no_neighbor_allowas_in,
6858 no_neighbor_allowas_in_cmd,
fd8503f5 6859 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6860 NO_STR
6861 NEIGHBOR_STR
6862 NEIGHBOR_ADDR_STR2
8334fd5a 6863 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6864 "Number of occurrences of AS number\n"
fd8503f5 6865 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6866{
d62a17ae 6867 int idx_peer = 2;
6868 int ret;
6869 struct peer *peer;
718e3744 6870
d62a17ae 6871 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6872 if (!peer)
6873 return CMD_WARNING_CONFIG_FAILED;
718e3744 6874
d62a17ae 6875 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6876 bgp_node_safi(vty));
718e3744 6877
d62a17ae 6878 return bgp_vty_return(vty, ret);
718e3744 6879}
6b0655a2 6880
d62a17ae 6881ALIAS_HIDDEN(
6882 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6883 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6884 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6885 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6886 "Number of occurrences of AS number\n"
d62a17ae 6887 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6888
fa411a21
NH
6889DEFUN (neighbor_ttl_security,
6890 neighbor_ttl_security_cmd,
7ebe625c 6891 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6892 NEIGHBOR_STR
7ebe625c 6893 NEIGHBOR_ADDR_STR2
16cedbb0 6894 "BGP ttl-security parameters\n"
d7fa34c1
QY
6895 "Specify the maximum number of hops to the BGP peer\n"
6896 "Number of hops to BGP peer\n")
fa411a21 6897{
d62a17ae 6898 int idx_peer = 1;
6899 int idx_number = 4;
6900 struct peer *peer;
6901 int gtsm_hops;
6902
6903 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6904 if (!peer)
6905 return CMD_WARNING_CONFIG_FAILED;
6906
6907 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6908
7ebe625c
QY
6909 /*
6910 * If 'neighbor swpX', then this is for directly connected peers,
6911 * we should not accept a ttl-security hops value greater than 1.
6912 */
6913 if (peer->conf_if && (gtsm_hops > 1)) {
6914 vty_out(vty,
6915 "%s is directly connected peer, hops cannot exceed 1\n",
6916 argv[idx_peer]->arg);
6917 return CMD_WARNING_CONFIG_FAILED;
6918 }
6919
d62a17ae 6920 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6921}
6922
6923DEFUN (no_neighbor_ttl_security,
6924 no_neighbor_ttl_security_cmd,
7ebe625c 6925 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6926 NO_STR
6927 NEIGHBOR_STR
7ebe625c 6928 NEIGHBOR_ADDR_STR2
16cedbb0 6929 "BGP ttl-security parameters\n"
3a2d747c
QY
6930 "Specify the maximum number of hops to the BGP peer\n"
6931 "Number of hops to BGP peer\n")
fa411a21 6932{
d62a17ae 6933 int idx_peer = 2;
6934 struct peer *peer;
fa411a21 6935
d62a17ae 6936 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6937 if (!peer)
6938 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6939
d62a17ae 6940 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6941}
6b0655a2 6942
adbac85e
DW
6943DEFUN (neighbor_addpath_tx_all_paths,
6944 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6945 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6946 NEIGHBOR_STR
6947 NEIGHBOR_ADDR_STR2
6948 "Use addpath to advertise all paths to a neighbor\n")
6949{
d62a17ae 6950 int idx_peer = 1;
6951 struct peer *peer;
adbac85e 6952
d62a17ae 6953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6954 if (!peer)
6955 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6956
dcc68b5e
MS
6957 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6958 BGP_ADDPATH_ALL);
6959 return CMD_SUCCESS;
adbac85e
DW
6960}
6961
d62a17ae 6962ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6963 neighbor_addpath_tx_all_paths_hidden_cmd,
6964 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6966 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6967
adbac85e
DW
6968DEFUN (no_neighbor_addpath_tx_all_paths,
6969 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6970 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6971 NO_STR
6972 NEIGHBOR_STR
6973 NEIGHBOR_ADDR_STR2
6974 "Use addpath to advertise all paths to a neighbor\n")
6975{
d62a17ae 6976 int idx_peer = 2;
dcc68b5e
MS
6977 struct peer *peer;
6978
6979 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6980 if (!peer)
6981 return CMD_WARNING_CONFIG_FAILED;
6982
6983 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6984 != BGP_ADDPATH_ALL) {
6985 vty_out(vty,
6986 "%% Peer not currently configured to transmit all paths.");
6987 return CMD_WARNING_CONFIG_FAILED;
6988 }
6989
6990 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6991 BGP_ADDPATH_NONE);
6992
6993 return CMD_SUCCESS;
adbac85e
DW
6994}
6995
d62a17ae 6996ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6997 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6998 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6999 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7000 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7001
06370dac
DW
7002DEFUN (neighbor_addpath_tx_bestpath_per_as,
7003 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7004 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7005 NEIGHBOR_STR
7006 NEIGHBOR_ADDR_STR2
7007 "Use addpath to advertise the bestpath per each neighboring AS\n")
7008{
d62a17ae 7009 int idx_peer = 1;
7010 struct peer *peer;
06370dac 7011
d62a17ae 7012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7013 if (!peer)
7014 return CMD_WARNING_CONFIG_FAILED;
06370dac 7015
dcc68b5e
MS
7016 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7017 BGP_ADDPATH_BEST_PER_AS);
7018
7019 return CMD_SUCCESS;
06370dac
DW
7020}
7021
d62a17ae 7022ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7023 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7024 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7025 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7026 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7027
06370dac
DW
7028DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7029 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7030 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7031 NO_STR
7032 NEIGHBOR_STR
7033 NEIGHBOR_ADDR_STR2
7034 "Use addpath to advertise the bestpath per each neighboring AS\n")
7035{
d62a17ae 7036 int idx_peer = 2;
dcc68b5e
MS
7037 struct peer *peer;
7038
7039 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7040 if (!peer)
7041 return CMD_WARNING_CONFIG_FAILED;
7042
7043 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7044 != BGP_ADDPATH_BEST_PER_AS) {
7045 vty_out(vty,
7046 "%% Peer not currently configured to transmit all best path per as.");
7047 return CMD_WARNING_CONFIG_FAILED;
7048 }
7049
7050 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7051 BGP_ADDPATH_NONE);
7052
7053 return CMD_SUCCESS;
06370dac
DW
7054}
7055
d62a17ae 7056ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7057 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7058 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7059 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7060 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7061
2b31007c
RZ
7062DEFPY(
7063 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7064 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7065 NEIGHBOR_STR
7066 NEIGHBOR_ADDR_STR2
7067 "Detect AS loops before sending to neighbor\n")
7068{
7069 struct peer *peer;
7070
7071 peer = peer_and_group_lookup_vty(vty, neighbor);
7072 if (!peer)
7073 return CMD_WARNING_CONFIG_FAILED;
7074
7075 peer->as_path_loop_detection = true;
7076
7077 return CMD_SUCCESS;
7078}
7079
7080DEFPY(
7081 no_neighbor_aspath_loop_detection,
7082 no_neighbor_aspath_loop_detection_cmd,
7083 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7084 NO_STR
7085 NEIGHBOR_STR
7086 NEIGHBOR_ADDR_STR2
7087 "Detect AS loops before sending to neighbor\n")
7088{
7089 struct peer *peer;
7090
7091 peer = peer_and_group_lookup_vty(vty, neighbor);
7092 if (!peer)
7093 return CMD_WARNING_CONFIG_FAILED;
7094
7095 peer->as_path_loop_detection = false;
7096
7097 return CMD_SUCCESS;
7098}
7099
b9c7bc5a
PZ
7100static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7101 struct ecommunity **list)
ddb5b488 7102{
b9c7bc5a
PZ
7103 struct ecommunity *ecom = NULL;
7104 struct ecommunity *ecomadd;
ddb5b488 7105
b9c7bc5a 7106 for (; argc; --argc, ++argv) {
ddb5b488 7107
b9c7bc5a
PZ
7108 ecomadd = ecommunity_str2com(argv[0]->arg,
7109 ECOMMUNITY_ROUTE_TARGET, 0);
7110 if (!ecomadd) {
7111 vty_out(vty, "Malformed community-list value\n");
7112 if (ecom)
7113 ecommunity_free(&ecom);
7114 return CMD_WARNING_CONFIG_FAILED;
7115 }
ddb5b488 7116
b9c7bc5a
PZ
7117 if (ecom) {
7118 ecommunity_merge(ecom, ecomadd);
7119 ecommunity_free(&ecomadd);
7120 } else {
7121 ecom = ecomadd;
7122 }
7123 }
7124
7125 if (*list) {
7126 ecommunity_free(&*list);
ddb5b488 7127 }
b9c7bc5a
PZ
7128 *list = ecom;
7129
7130 return CMD_SUCCESS;
ddb5b488
PZ
7131}
7132
0ca70ba5
DS
7133/*
7134 * v2vimport is true if we are handling a `import vrf ...` command
7135 */
7136static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7137{
0ca70ba5
DS
7138 afi_t afi;
7139
ddb5b488 7140 switch (vty->node) {
b9c7bc5a 7141 case BGP_IPV4_NODE:
0ca70ba5
DS
7142 afi = AFI_IP;
7143 break;
b9c7bc5a 7144 case BGP_IPV6_NODE:
0ca70ba5
DS
7145 afi = AFI_IP6;
7146 break;
ddb5b488
PZ
7147 default:
7148 vty_out(vty,
b9c7bc5a 7149 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7150 return AFI_MAX;
ddb5b488 7151 }
69b07479 7152
0ca70ba5
DS
7153 if (!v2vimport) {
7154 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7155 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7156 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7157 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7158 vty_out(vty,
7159 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7160 return AFI_MAX;
7161 }
7162 } else {
7163 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7164 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7165 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7166 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7167 vty_out(vty,
7168 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7169 return AFI_MAX;
7170 }
7171 }
7172 return afi;
ddb5b488
PZ
7173}
7174
b9c7bc5a
PZ
7175DEFPY (af_rd_vpn_export,
7176 af_rd_vpn_export_cmd,
7177 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7178 NO_STR
ddb5b488 7179 "Specify route distinguisher\n"
b9c7bc5a
PZ
7180 "Between current address-family and vpn\n"
7181 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7182 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7183{
7184 VTY_DECLVAR_CONTEXT(bgp, bgp);
7185 struct prefix_rd prd;
7186 int ret;
ddb5b488 7187 afi_t afi;
b9c7bc5a
PZ
7188 int idx = 0;
7189 int yes = 1;
ddb5b488 7190
b9c7bc5a 7191 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7192 yes = 0;
b9c7bc5a
PZ
7193
7194 if (yes) {
7195 ret = str2prefix_rd(rd_str, &prd);
7196 if (!ret) {
7197 vty_out(vty, "%% Malformed rd\n");
7198 return CMD_WARNING_CONFIG_FAILED;
7199 }
ddb5b488
PZ
7200 }
7201
0ca70ba5 7202 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7203 if (afi == AFI_MAX)
7204 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7205
69b07479
DS
7206 /*
7207 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7208 */
7209 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7210 bgp_get_default(), bgp);
ddb5b488 7211
69b07479
DS
7212 if (yes) {
7213 bgp->vpn_policy[afi].tovpn_rd = prd;
7214 SET_FLAG(bgp->vpn_policy[afi].flags,
7215 BGP_VPN_POLICY_TOVPN_RD_SET);
7216 } else {
7217 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7218 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7219 }
7220
69b07479
DS
7221 /* post-change: re-export vpn routes */
7222 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7223 bgp_get_default(), bgp);
7224
ddb5b488
PZ
7225 return CMD_SUCCESS;
7226}
7227
b9c7bc5a
PZ
7228ALIAS (af_rd_vpn_export,
7229 af_no_rd_vpn_export_cmd,
7230 "no rd vpn export",
ddb5b488 7231 NO_STR
b9c7bc5a
PZ
7232 "Specify route distinguisher\n"
7233 "Between current address-family and vpn\n"
7234 "For routes leaked from current address-family to vpn\n")
ddb5b488 7235
b9c7bc5a
PZ
7236DEFPY (af_label_vpn_export,
7237 af_label_vpn_export_cmd,
e70e9f8e 7238 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7239 NO_STR
ddb5b488 7240 "label value for VRF\n"
b9c7bc5a
PZ
7241 "Between current address-family and vpn\n"
7242 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7243 "Label Value <0-1048575>\n"
7244 "Automatically assign a label\n")
ddb5b488
PZ
7245{
7246 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7247 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7248 afi_t afi;
b9c7bc5a
PZ
7249 int idx = 0;
7250 int yes = 1;
7251
7252 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7253 yes = 0;
ddb5b488 7254
21a16cc2
PZ
7255 /* If "no ...", squash trailing parameter */
7256 if (!yes)
7257 label_auto = NULL;
7258
e70e9f8e
PZ
7259 if (yes) {
7260 if (!label_auto)
7261 label = label_val; /* parser should force unsigned */
7262 }
ddb5b488 7263
0ca70ba5 7264 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7265 if (afi == AFI_MAX)
7266 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7267
e70e9f8e 7268
69b07479
DS
7269 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7270 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7271 /* no change */
7272 return CMD_SUCCESS;
e70e9f8e 7273
69b07479
DS
7274 /*
7275 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7276 */
7277 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7278 bgp_get_default(), bgp);
7279
7280 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7281 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7282
7283 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7284
7285 /*
7286 * label has previously been automatically
7287 * assigned by labelpool: release it
7288 *
7289 * NB if tovpn_label == MPLS_LABEL_NONE it
7290 * means the automatic assignment is in flight
7291 * and therefore the labelpool callback must
7292 * detect that the auto label is not needed.
7293 */
7294
7295 bgp_lp_release(LP_TYPE_VRF,
7296 &bgp->vpn_policy[afi],
7297 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7298 }
69b07479
DS
7299 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7300 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7301 }
ddb5b488 7302
69b07479
DS
7303 bgp->vpn_policy[afi].tovpn_label = label;
7304 if (label_auto) {
7305 SET_FLAG(bgp->vpn_policy[afi].flags,
7306 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7307 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7308 vpn_leak_label_callback);
ddb5b488
PZ
7309 }
7310
69b07479
DS
7311 /* post-change: re-export vpn routes */
7312 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7313 bgp_get_default(), bgp);
7314
ddb5b488
PZ
7315 return CMD_SUCCESS;
7316}
7317
b9c7bc5a
PZ
7318ALIAS (af_label_vpn_export,
7319 af_no_label_vpn_export_cmd,
7320 "no label vpn export",
7321 NO_STR
7322 "label value for VRF\n"
7323 "Between current address-family and vpn\n"
7324 "For routes leaked from current address-family to vpn\n")
ddb5b488 7325
b9c7bc5a
PZ
7326DEFPY (af_nexthop_vpn_export,
7327 af_nexthop_vpn_export_cmd,
7328 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
7329 NO_STR
ddb5b488 7330 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7331 "Between current address-family and vpn\n"
7332 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7333 "IPv4 prefix\n"
7334 "IPv6 prefix\n")
7335{
7336 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7337 afi_t afi;
ddb5b488 7338 struct prefix p;
b9c7bc5a
PZ
7339 int idx = 0;
7340 int yes = 1;
ddb5b488 7341
b9c7bc5a 7342 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7343 yes = 0;
b9c7bc5a
PZ
7344
7345 if (yes) {
7346 if (!sockunion2hostprefix(nexthop_str, &p))
7347 return CMD_WARNING_CONFIG_FAILED;
7348 }
ddb5b488 7349
0ca70ba5 7350 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7351 if (afi == AFI_MAX)
7352 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7353
69b07479
DS
7354 /*
7355 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7356 */
7357 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7358 bgp_get_default(), bgp);
ddb5b488 7359
69b07479
DS
7360 if (yes) {
7361 bgp->vpn_policy[afi].tovpn_nexthop = p;
7362 SET_FLAG(bgp->vpn_policy[afi].flags,
7363 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7364 } else {
7365 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7366 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7367 }
7368
69b07479
DS
7369 /* post-change: re-export vpn routes */
7370 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7371 bgp_get_default(), bgp);
7372
ddb5b488
PZ
7373 return CMD_SUCCESS;
7374}
7375
b9c7bc5a
PZ
7376ALIAS (af_nexthop_vpn_export,
7377 af_no_nexthop_vpn_export_cmd,
7378 "no nexthop vpn export",
ddb5b488 7379 NO_STR
b9c7bc5a
PZ
7380 "Specify next hop to use for VRF advertised prefixes\n"
7381 "Between current address-family and vpn\n"
7382 "For routes leaked from current address-family to vpn\n")
ddb5b488 7383
b9c7bc5a 7384static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7385{
b9c7bc5a
PZ
7386 if (!strcmp(dstr, "import")) {
7387 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7388 } else if (!strcmp(dstr, "export")) {
7389 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7390 } else if (!strcmp(dstr, "both")) {
7391 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7392 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7393 } else {
7394 vty_out(vty, "%% direction parse error\n");
7395 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7396 }
ddb5b488
PZ
7397 return CMD_SUCCESS;
7398}
7399
b9c7bc5a
PZ
7400DEFPY (af_rt_vpn_imexport,
7401 af_rt_vpn_imexport_cmd,
7402 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7403 NO_STR
7404 "Specify route target list\n"
ddb5b488 7405 "Specify route target list\n"
b9c7bc5a
PZ
7406 "Between current address-family and vpn\n"
7407 "For routes leaked from vpn to current address-family: match any\n"
7408 "For routes leaked from current address-family to vpn: set\n"
7409 "both import: match any and export: set\n"
ddb5b488
PZ
7410 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7411{
7412 VTY_DECLVAR_CONTEXT(bgp, bgp);
7413 int ret;
7414 struct ecommunity *ecom = NULL;
7415 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7416 vpn_policy_direction_t dir;
7417 afi_t afi;
7418 int idx = 0;
b9c7bc5a 7419 int yes = 1;
ddb5b488 7420
b9c7bc5a 7421 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7422 yes = 0;
b9c7bc5a 7423
0ca70ba5 7424 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7425 if (afi == AFI_MAX)
7426 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7427
b9c7bc5a 7428 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7429 if (ret != CMD_SUCCESS)
7430 return ret;
7431
b9c7bc5a
PZ
7432 if (yes) {
7433 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7434 vty_out(vty, "%% Missing RTLIST\n");
7435 return CMD_WARNING_CONFIG_FAILED;
7436 }
7437 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7438 if (ret != CMD_SUCCESS) {
7439 return ret;
7440 }
ddb5b488
PZ
7441 }
7442
69b07479
DS
7443 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7444 if (!dodir[dir])
ddb5b488 7445 continue;
ddb5b488 7446
69b07479 7447 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7448
69b07479
DS
7449 if (yes) {
7450 if (bgp->vpn_policy[afi].rtlist[dir])
7451 ecommunity_free(
7452 &bgp->vpn_policy[afi].rtlist[dir]);
7453 bgp->vpn_policy[afi].rtlist[dir] =
7454 ecommunity_dup(ecom);
7455 } else {
7456 if (bgp->vpn_policy[afi].rtlist[dir])
7457 ecommunity_free(
7458 &bgp->vpn_policy[afi].rtlist[dir]);
7459 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7460 }
69b07479
DS
7461
7462 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7463 }
69b07479 7464
d555f3e9
PZ
7465 if (ecom)
7466 ecommunity_free(&ecom);
ddb5b488
PZ
7467
7468 return CMD_SUCCESS;
7469}
7470
b9c7bc5a
PZ
7471ALIAS (af_rt_vpn_imexport,
7472 af_no_rt_vpn_imexport_cmd,
7473 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7474 NO_STR
7475 "Specify route target list\n"
b9c7bc5a
PZ
7476 "Specify route target list\n"
7477 "Between current address-family and vpn\n"
7478 "For routes leaked from vpn to current address-family\n"
7479 "For routes leaked from current address-family to vpn\n"
7480 "both import and export\n")
7481
7482DEFPY (af_route_map_vpn_imexport,
7483 af_route_map_vpn_imexport_cmd,
7484/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7485 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7486 NO_STR
ddb5b488 7487 "Specify route map\n"
b9c7bc5a
PZ
7488 "Between current address-family and vpn\n"
7489 "For routes leaked from vpn to current address-family\n"
7490 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7491 "name of route-map\n")
7492{
7493 VTY_DECLVAR_CONTEXT(bgp, bgp);
7494 int ret;
7495 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7496 vpn_policy_direction_t dir;
7497 afi_t afi;
ddb5b488 7498 int idx = 0;
b9c7bc5a 7499 int yes = 1;
ddb5b488 7500
b9c7bc5a 7501 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7502 yes = 0;
b9c7bc5a 7503
0ca70ba5 7504 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7505 if (afi == AFI_MAX)
7506 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7507
b9c7bc5a 7508 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7509 if (ret != CMD_SUCCESS)
7510 return ret;
7511
69b07479
DS
7512 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7513 if (!dodir[dir])
ddb5b488 7514 continue;
ddb5b488 7515
69b07479 7516 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7517
69b07479
DS
7518 if (yes) {
7519 if (bgp->vpn_policy[afi].rmap_name[dir])
7520 XFREE(MTYPE_ROUTE_MAP_NAME,
7521 bgp->vpn_policy[afi].rmap_name[dir]);
7522 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7523 MTYPE_ROUTE_MAP_NAME, rmap_str);
7524 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7525 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7526 if (!bgp->vpn_policy[afi].rmap[dir])
7527 return CMD_SUCCESS;
7528 } else {
7529 if (bgp->vpn_policy[afi].rmap_name[dir])
7530 XFREE(MTYPE_ROUTE_MAP_NAME,
7531 bgp->vpn_policy[afi].rmap_name[dir]);
7532 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7533 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 7534 }
69b07479
DS
7535
7536 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
7537 }
7538
7539 return CMD_SUCCESS;
7540}
7541
b9c7bc5a
PZ
7542ALIAS (af_route_map_vpn_imexport,
7543 af_no_route_map_vpn_imexport_cmd,
7544 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
7545 NO_STR
7546 "Specify route map\n"
b9c7bc5a
PZ
7547 "Between current address-family and vpn\n"
7548 "For routes leaked from vpn to current address-family\n"
7549 "For routes leaked from current address-family to vpn\n")
7550
bb4f6190
DS
7551DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
7552 "[no] import vrf route-map RMAP$rmap_str",
7553 NO_STR
7554 "Import routes from another VRF\n"
7555 "Vrf routes being filtered\n"
7556 "Specify route map\n"
7557 "name of route-map\n")
7558{
7559 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
7560 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7561 afi_t afi;
7562 int idx = 0;
7563 int yes = 1;
7564 struct bgp *bgp_default;
7565
7566 if (argv_find(argv, argc, "no", &idx))
7567 yes = 0;
7568
0ca70ba5 7569 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
7570 if (afi == AFI_MAX)
7571 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
7572
7573 bgp_default = bgp_get_default();
7574 if (!bgp_default) {
7575 int32_t ret;
7576 as_t as = bgp->as;
7577
7578 /* Auto-create assuming the same AS */
5d5393b9
DL
7579 ret = bgp_get_vty(&bgp_default, &as, NULL,
7580 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
7581
7582 if (ret) {
7583 vty_out(vty,
7584 "VRF default is not configured as a bgp instance\n");
7585 return CMD_WARNING;
7586 }
7587 }
7588
69b07479 7589 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 7590
69b07479
DS
7591 if (yes) {
7592 if (bgp->vpn_policy[afi].rmap_name[dir])
7593 XFREE(MTYPE_ROUTE_MAP_NAME,
7594 bgp->vpn_policy[afi].rmap_name[dir]);
7595 bgp->vpn_policy[afi].rmap_name[dir] =
7596 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7597 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7598 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7599 if (!bgp->vpn_policy[afi].rmap[dir])
7600 return CMD_SUCCESS;
7601 } else {
7602 if (bgp->vpn_policy[afi].rmap_name[dir])
7603 XFREE(MTYPE_ROUTE_MAP_NAME,
7604 bgp->vpn_policy[afi].rmap_name[dir]);
7605 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7606 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
7607 }
7608
69b07479
DS
7609 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7610
bb4f6190
DS
7611 return CMD_SUCCESS;
7612}
7613
7614ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7615 "no import vrf route-map",
7616 NO_STR
7617 "Import routes from another VRF\n"
7618 "Vrf routes being filtered\n"
7619 "Specify route map\n")
7620
4d1b335c
DA
7621DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7622 "[no] import vrf VIEWVRFNAME$import_name",
7623 NO_STR
7624 "Import routes from another VRF\n"
7625 "VRF to import from\n"
7626 "The name of the VRF\n")
12a844a5
DS
7627{
7628 VTY_DECLVAR_CONTEXT(bgp, bgp);
7629 struct listnode *node;
79ef8664
DS
7630 struct bgp *vrf_bgp, *bgp_default;
7631 int32_t ret = 0;
7632 as_t as = bgp->as;
12a844a5
DS
7633 bool remove = false;
7634 int32_t idx = 0;
7635 char *vname;
a8dadcf6 7636 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7637 safi_t safi;
7638 afi_t afi;
7639
867f0cca 7640 if (import_name == NULL) {
7641 vty_out(vty, "%% Missing import name\n");
7642 return CMD_WARNING;
7643 }
7644
12a844a5
DS
7645 if (argv_find(argv, argc, "no", &idx))
7646 remove = true;
7647
0ca70ba5
DS
7648 afi = vpn_policy_getafi(vty, bgp, true);
7649 if (afi == AFI_MAX)
7650 return CMD_WARNING_CONFIG_FAILED;
7651
12a844a5
DS
7652 safi = bgp_node_safi(vty);
7653
25679caa 7654 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7655 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7656 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7657 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7658 remove ? "unimport" : "import", import_name);
7659 return CMD_WARNING;
7660 }
7661
79ef8664
DS
7662 bgp_default = bgp_get_default();
7663 if (!bgp_default) {
7664 /* Auto-create assuming the same AS */
5d5393b9
DL
7665 ret = bgp_get_vty(&bgp_default, &as, NULL,
7666 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
7667
7668 if (ret) {
7669 vty_out(vty,
7670 "VRF default is not configured as a bgp instance\n");
7671 return CMD_WARNING;
7672 }
7673 }
7674
12a844a5
DS
7675 vrf_bgp = bgp_lookup_by_name(import_name);
7676 if (!vrf_bgp) {
5742e42b 7677 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7678 vrf_bgp = bgp_default;
7679 else
0fb8d6e6 7680 /* Auto-create assuming the same AS */
5d5393b9 7681 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7682
6e2c7fe6 7683 if (ret) {
020a3f60
DS
7684 vty_out(vty,
7685 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7686 import_name);
7687 return CMD_WARNING;
7688 }
12a844a5
DS
7689 }
7690
12a844a5 7691 if (remove) {
44338987 7692 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7693 } else {
44338987 7694 /* Already importing from "import_vrf"? */
12a844a5
DS
7695 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7696 vname)) {
7697 if (strcmp(vname, import_name) == 0)
7698 return CMD_WARNING;
7699 }
7700
44338987 7701 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7702 }
7703
7704 return CMD_SUCCESS;
7705}
7706
b9c7bc5a
PZ
7707/* This command is valid only in a bgp vrf instance or the default instance */
7708DEFPY (bgp_imexport_vpn,
7709 bgp_imexport_vpn_cmd,
7710 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7711 NO_STR
7712 "Import routes to this address-family\n"
7713 "Export routes from this address-family\n"
7714 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7715{
7716 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7717 int previous_state;
ddb5b488 7718 afi_t afi;
b9c7bc5a 7719 safi_t safi;
ddb5b488 7720 int idx = 0;
b9c7bc5a
PZ
7721 int yes = 1;
7722 int flag;
7723 vpn_policy_direction_t dir;
ddb5b488 7724
b9c7bc5a 7725 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7726 yes = 0;
ddb5b488 7727
b9c7bc5a
PZ
7728 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7729 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7730
b9c7bc5a
PZ
7731 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7732 return CMD_WARNING_CONFIG_FAILED;
7733 }
ddb5b488 7734
b9c7bc5a
PZ
7735 afi = bgp_node_afi(vty);
7736 safi = bgp_node_safi(vty);
7737 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7738 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7739 return CMD_WARNING_CONFIG_FAILED;
7740 }
ddb5b488 7741
b9c7bc5a
PZ
7742 if (!strcmp(direction_str, "import")) {
7743 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7744 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7745 } else if (!strcmp(direction_str, "export")) {
7746 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7747 dir = BGP_VPN_POLICY_DIR_TOVPN;
7748 } else {
7749 vty_out(vty, "%% unknown direction %s\n", direction_str);
7750 return CMD_WARNING_CONFIG_FAILED;
7751 }
7752
7753 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7754
b9c7bc5a
PZ
7755 if (yes) {
7756 SET_FLAG(bgp->af_flags[afi][safi], flag);
7757 if (!previous_state) {
7758 /* trigger export current vrf */
ddb5b488
PZ
7759 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7760 }
b9c7bc5a
PZ
7761 } else {
7762 if (previous_state) {
7763 /* trigger un-export current vrf */
7764 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7765 }
7766 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7767 }
7768
7769 return CMD_SUCCESS;
7770}
7771
301ad80a
PG
7772DEFPY (af_routetarget_import,
7773 af_routetarget_import_cmd,
7774 "[no] <rt|route-target> redirect import RTLIST...",
7775 NO_STR
7776 "Specify route target list\n"
7777 "Specify route target list\n"
7778 "Flow-spec redirect type route target\n"
7779 "Import routes to this address-family\n"
7780 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7781{
7782 VTY_DECLVAR_CONTEXT(bgp, bgp);
7783 int ret;
7784 struct ecommunity *ecom = NULL;
301ad80a
PG
7785 afi_t afi;
7786 int idx = 0;
7787 int yes = 1;
7788
7789 if (argv_find(argv, argc, "no", &idx))
7790 yes = 0;
7791
0ca70ba5 7792 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7793 if (afi == AFI_MAX)
7794 return CMD_WARNING_CONFIG_FAILED;
7795
301ad80a
PG
7796 if (yes) {
7797 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7798 vty_out(vty, "%% Missing RTLIST\n");
7799 return CMD_WARNING_CONFIG_FAILED;
7800 }
7801 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7802 if (ret != CMD_SUCCESS)
7803 return ret;
7804 }
69b07479
DS
7805
7806 if (yes) {
7807 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7808 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7809 .import_redirect_rtlist);
69b07479
DS
7810 bgp->vpn_policy[afi].import_redirect_rtlist =
7811 ecommunity_dup(ecom);
7812 } else {
7813 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7814 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7815 .import_redirect_rtlist);
69b07479 7816 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7817 }
69b07479 7818
301ad80a
PG
7819 if (ecom)
7820 ecommunity_free(&ecom);
7821
7822 return CMD_SUCCESS;
7823}
7824
505e5056 7825DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7826 address_family_ipv4_safi_cmd,
7827 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7828 "Enter Address Family command mode\n"
7829 "Address Family\n"
7830 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7831{
f51bae9c 7832
d62a17ae 7833 if (argc == 3) {
2131d5cf 7834 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7835 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7836 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7837 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7838 && safi != SAFI_EVPN) {
31947174
MK
7839 vty_out(vty,
7840 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7841 return CMD_WARNING_CONFIG_FAILED;
7842 }
d62a17ae 7843 vty->node = bgp_node_type(AFI_IP, safi);
7844 } else
7845 vty->node = BGP_IPV4_NODE;
718e3744 7846
d62a17ae 7847 return CMD_SUCCESS;
718e3744 7848}
7849
505e5056 7850DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7851 address_family_ipv6_safi_cmd,
7852 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7853 "Enter Address Family command mode\n"
7854 "Address Family\n"
7855 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7856{
d62a17ae 7857 if (argc == 3) {
2131d5cf 7858 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7859 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7860 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7861 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7862 && safi != SAFI_EVPN) {
31947174
MK
7863 vty_out(vty,
7864 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7865 return CMD_WARNING_CONFIG_FAILED;
7866 }
d62a17ae 7867 vty->node = bgp_node_type(AFI_IP6, safi);
7868 } else
7869 vty->node = BGP_IPV6_NODE;
25ffbdc1 7870
d62a17ae 7871 return CMD_SUCCESS;
25ffbdc1 7872}
718e3744 7873
d6902373 7874#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7875DEFUN_NOSH (address_family_vpnv4,
718e3744 7876 address_family_vpnv4_cmd,
8334fd5a 7877 "address-family vpnv4 [unicast]",
718e3744 7878 "Enter Address Family command mode\n"
8c3deaae 7879 "Address Family\n"
3a2d747c 7880 "Address Family modifier\n")
718e3744 7881{
d62a17ae 7882 vty->node = BGP_VPNV4_NODE;
7883 return CMD_SUCCESS;
718e3744 7884}
7885
505e5056 7886DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7887 address_family_vpnv6_cmd,
8334fd5a 7888 "address-family vpnv6 [unicast]",
8ecd3266 7889 "Enter Address Family command mode\n"
8c3deaae 7890 "Address Family\n"
3a2d747c 7891 "Address Family modifier\n")
8ecd3266 7892{
d62a17ae 7893 vty->node = BGP_VPNV6_NODE;
7894 return CMD_SUCCESS;
8ecd3266 7895}
64e4a6c5 7896#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7897
505e5056 7898DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7899 address_family_evpn_cmd,
7111c1a0 7900 "address-family l2vpn evpn",
4e0b7b6d 7901 "Enter Address Family command mode\n"
7111c1a0
QY
7902 "Address Family\n"
7903 "Address Family modifier\n")
4e0b7b6d 7904{
2131d5cf 7905 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7906 vty->node = BGP_EVPN_NODE;
7907 return CMD_SUCCESS;
4e0b7b6d
PG
7908}
7909
505e5056 7910DEFUN_NOSH (exit_address_family,
718e3744 7911 exit_address_family_cmd,
7912 "exit-address-family",
7913 "Exit from Address Family configuration mode\n")
7914{
d62a17ae 7915 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7916 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7917 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7918 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7919 || vty->node == BGP_EVPN_NODE
7920 || vty->node == BGP_FLOWSPECV4_NODE
7921 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7922 vty->node = BGP_NODE;
7923 return CMD_SUCCESS;
718e3744 7924}
6b0655a2 7925
8ad7271d 7926/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7927static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7928 const char *ip_str, afi_t afi, safi_t safi,
7929 struct prefix_rd *prd)
7930{
7931 int ret;
7932 struct prefix match;
7933 struct bgp_node *rn;
7934 struct bgp_node *rm;
7935 struct bgp *bgp;
7936 struct bgp_table *table;
7937 struct bgp_table *rib;
7938
7939 /* BGP structure lookup. */
7940 if (view_name) {
7941 bgp = bgp_lookup_by_name(view_name);
7942 if (bgp == NULL) {
7943 vty_out(vty, "%% Can't find BGP instance %s\n",
7944 view_name);
7945 return CMD_WARNING;
7946 }
7947 } else {
7948 bgp = bgp_get_default();
7949 if (bgp == NULL) {
7950 vty_out(vty, "%% No BGP process is configured\n");
7951 return CMD_WARNING;
7952 }
7953 }
7954
7955 /* Check IP address argument. */
7956 ret = str2prefix(ip_str, &match);
7957 if (!ret) {
7958 vty_out(vty, "%% address is malformed\n");
7959 return CMD_WARNING;
7960 }
7961
7962 match.family = afi2family(afi);
7963 rib = bgp->rib[afi][safi];
7964
7965 if (safi == SAFI_MPLS_VPN) {
7966 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7967 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7968 continue;
7969
67009e22
DS
7970 table = bgp_node_get_bgp_table_info(rn);
7971 if (table != NULL) {
7972
d62a17ae 7973 if ((rm = bgp_node_match(table, &match))
7974 != NULL) {
7975 if (rm->p.prefixlen
7976 == match.prefixlen) {
343cdb61 7977 SET_FLAG(rm->flags,
d62a17ae 7978 BGP_NODE_USER_CLEAR);
7979 bgp_process(bgp, rm, afi, safi);
7980 }
7981 bgp_unlock_node(rm);
7982 }
7983 }
7984 }
7985 } else {
7986 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7987 if (rn->p.prefixlen == match.prefixlen) {
7988 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7989 bgp_process(bgp, rn, afi, safi);
7990 }
7991 bgp_unlock_node(rn);
7992 }
7993 }
7994
7995 return CMD_SUCCESS;
8ad7271d
DS
7996}
7997
b09b5ae0 7998/* one clear bgp command to rule them all */
718e3744 7999DEFUN (clear_ip_bgp_all,
8000 clear_ip_bgp_all_cmd,
453c92f6 8001 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 8002 CLEAR_STR
8003 IP_STR
8004 BGP_STR
838758ac 8005 BGP_INSTANCE_HELP_STR
510afcd6 8006 BGP_AFI_HELP_STR
fd5e7b70 8007 "Address Family\n"
510afcd6 8008 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8009 "Address Family modifier\n"
b09b5ae0 8010 "Clear all peers\n"
453c92f6 8011 "BGP IPv4 neighbor to clear\n"
a80beece 8012 "BGP IPv6 neighbor to clear\n"
838758ac 8013 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8014 "Clear peers with the AS number\n"
8015 "Clear all external peers\n"
718e3744 8016 "Clear all members of peer-group\n"
b09b5ae0 8017 "BGP peer-group name\n"
b09b5ae0
DW
8018 BGP_SOFT_STR
8019 BGP_SOFT_IN_STR
b09b5ae0
DW
8020 BGP_SOFT_OUT_STR
8021 BGP_SOFT_IN_STR
8022 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8023 BGP_SOFT_OUT_STR)
718e3744 8024{
d62a17ae 8025 char *vrf = NULL;
8026
dc912615
DS
8027 afi_t afi = AFI_UNSPEC;
8028 safi_t safi = SAFI_UNSPEC;
d62a17ae 8029 enum clear_sort clr_sort = clear_peer;
8030 enum bgp_clear_type clr_type;
8031 char *clr_arg = NULL;
8032
8033 int idx = 0;
8034
8035 /* clear [ip] bgp */
8036 if (argv_find(argv, argc, "ip", &idx))
8037 afi = AFI_IP;
8038
9a8bdf1c
PG
8039 /* [<vrf> VIEWVRFNAME] */
8040 if (argv_find(argv, argc, "vrf", &idx)) {
8041 vrf = argv[idx + 1]->arg;
8042 idx += 2;
8043 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8044 vrf = NULL;
8045 } else if (argv_find(argv, argc, "view", &idx)) {
8046 /* [<view> VIEWVRFNAME] */
d62a17ae 8047 vrf = argv[idx + 1]->arg;
8048 idx += 2;
8049 }
d62a17ae 8050 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8051 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8052 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8053
d7b9898c 8054 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8055 if (argv_find(argv, argc, "*", &idx)) {
8056 clr_sort = clear_all;
8057 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8058 clr_sort = clear_peer;
8059 clr_arg = argv[idx]->arg;
8060 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8061 clr_sort = clear_peer;
8062 clr_arg = argv[idx]->arg;
8063 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8064 clr_sort = clear_group;
8065 idx++;
8066 clr_arg = argv[idx]->arg;
d7b9898c 8067 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8068 clr_sort = clear_peer;
8069 clr_arg = argv[idx]->arg;
8fa7d444
DS
8070 } else if (argv_find(argv, argc, "WORD", &idx)) {
8071 clr_sort = clear_peer;
8072 clr_arg = argv[idx]->arg;
d62a17ae 8073 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8074 clr_sort = clear_as;
8075 clr_arg = argv[idx]->arg;
8076 } else if (argv_find(argv, argc, "external", &idx)) {
8077 clr_sort = clear_external;
8078 }
8079
8080 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8081 if (argv_find(argv, argc, "soft", &idx)) {
8082 if (argv_find(argv, argc, "in", &idx)
8083 || argv_find(argv, argc, "out", &idx))
8084 clr_type = strmatch(argv[idx]->text, "in")
8085 ? BGP_CLEAR_SOFT_IN
8086 : BGP_CLEAR_SOFT_OUT;
8087 else
8088 clr_type = BGP_CLEAR_SOFT_BOTH;
8089 } else if (argv_find(argv, argc, "in", &idx)) {
8090 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8091 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8092 : BGP_CLEAR_SOFT_IN;
8093 } else if (argv_find(argv, argc, "out", &idx)) {
8094 clr_type = BGP_CLEAR_SOFT_OUT;
8095 } else
8096 clr_type = BGP_CLEAR_SOFT_NONE;
8097
8098 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8099}
01080f7c 8100
8ad7271d
DS
8101DEFUN (clear_ip_bgp_prefix,
8102 clear_ip_bgp_prefix_cmd,
18c57037 8103 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8104 CLEAR_STR
8105 IP_STR
8106 BGP_STR
838758ac 8107 BGP_INSTANCE_HELP_STR
8ad7271d 8108 "Clear bestpath and re-advertise\n"
0c7b1b01 8109 "IPv4 prefix\n")
8ad7271d 8110{
d62a17ae 8111 char *vrf = NULL;
8112 char *prefix = NULL;
8ad7271d 8113
d62a17ae 8114 int idx = 0;
01080f7c 8115
d62a17ae 8116 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8117 if (argv_find(argv, argc, "vrf", &idx)) {
8118 vrf = argv[idx + 1]->arg;
8119 idx += 2;
8120 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8121 vrf = NULL;
8122 } else if (argv_find(argv, argc, "view", &idx)) {
8123 /* [<view> VIEWVRFNAME] */
8124 vrf = argv[idx + 1]->arg;
8125 idx += 2;
8126 }
0c7b1b01 8127
d62a17ae 8128 prefix = argv[argc - 1]->arg;
8ad7271d 8129
d62a17ae 8130 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8131}
8ad7271d 8132
b09b5ae0
DW
8133DEFUN (clear_bgp_ipv6_safi_prefix,
8134 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8135 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8136 CLEAR_STR
3a2d747c 8137 IP_STR
718e3744 8138 BGP_STR
8c3deaae 8139 "Address Family\n"
46f296b4 8140 BGP_SAFI_HELP_STR
b09b5ae0 8141 "Clear bestpath and re-advertise\n"
0c7b1b01 8142 "IPv6 prefix\n")
718e3744 8143{
9b475e76
PG
8144 int idx_safi = 0;
8145 int idx_ipv6_prefix = 0;
8146 safi_t safi = SAFI_UNICAST;
8147 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8148 argv[idx_ipv6_prefix]->arg : NULL;
8149
8150 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8151 return bgp_clear_prefix(
9b475e76
PG
8152 vty, NULL, prefix, AFI_IP6,
8153 safi, NULL);
838758ac 8154}
01080f7c 8155
b09b5ae0
DW
8156DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8157 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8158 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8159 CLEAR_STR
3a2d747c 8160 IP_STR
718e3744 8161 BGP_STR
838758ac 8162 BGP_INSTANCE_HELP_STR
8c3deaae 8163 "Address Family\n"
46f296b4 8164 BGP_SAFI_HELP_STR
b09b5ae0 8165 "Clear bestpath and re-advertise\n"
0c7b1b01 8166 "IPv6 prefix\n")
718e3744 8167{
9b475e76 8168 int idx_safi = 0;
9a8bdf1c 8169 int idx_vrfview = 0;
9b475e76
PG
8170 int idx_ipv6_prefix = 0;
8171 safi_t safi = SAFI_UNICAST;
8172 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8173 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8174 char *vrfview = NULL;
9b475e76 8175
9a8bdf1c
PG
8176 /* [<view|vrf> VIEWVRFNAME] */
8177 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8178 vrfview = argv[idx_vrfview + 1]->arg;
8179 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8180 vrfview = NULL;
8181 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8182 /* [<view> VIEWVRFNAME] */
8183 vrfview = argv[idx_vrfview + 1]->arg;
8184 }
9b475e76
PG
8185 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8186
d62a17ae 8187 return bgp_clear_prefix(
9b475e76
PG
8188 vty, vrfview, prefix,
8189 AFI_IP6, safi, NULL);
718e3744 8190}
8191
b09b5ae0
DW
8192DEFUN (show_bgp_views,
8193 show_bgp_views_cmd,
d6e3c605 8194 "show [ip] bgp views",
b09b5ae0 8195 SHOW_STR
d6e3c605 8196 IP_STR
01080f7c 8197 BGP_STR
b09b5ae0 8198 "Show the defined BGP views\n")
01080f7c 8199{
d62a17ae 8200 struct list *inst = bm->bgp;
8201 struct listnode *node;
8202 struct bgp *bgp;
01080f7c 8203
d62a17ae 8204 vty_out(vty, "Defined BGP views:\n");
8205 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8206 /* Skip VRFs. */
8207 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8208 continue;
8209 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8210 bgp->as);
8211 }
e52702f2 8212
d62a17ae 8213 return CMD_SUCCESS;
e0081f70
ML
8214}
8215
8386ac43 8216DEFUN (show_bgp_vrfs,
8217 show_bgp_vrfs_cmd,
d6e3c605 8218 "show [ip] bgp vrfs [json]",
8386ac43 8219 SHOW_STR
d6e3c605 8220 IP_STR
8386ac43 8221 BGP_STR
8222 "Show BGP VRFs\n"
9973d184 8223 JSON_STR)
8386ac43 8224{
fe1dc5a3 8225 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8226 struct list *inst = bm->bgp;
8227 struct listnode *node;
8228 struct bgp *bgp;
9f049418 8229 bool uj = use_json(argc, argv);
d62a17ae 8230 json_object *json = NULL;
8231 json_object *json_vrfs = NULL;
8232 int count = 0;
d62a17ae 8233
d62a17ae 8234 if (uj) {
8235 json = json_object_new_object();
8236 json_vrfs = json_object_new_object();
8237 }
8238
8239 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8240 const char *name, *type;
8241 struct peer *peer;
7fe96307 8242 struct listnode *node2, *nnode2;
d62a17ae 8243 int peers_cfg, peers_estb;
8244 json_object *json_vrf = NULL;
d62a17ae 8245
8246 /* Skip Views. */
8247 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8248 continue;
8249
8250 count++;
efb4077a 8251 if (!uj && count == 1) {
fe1dc5a3 8252 vty_out(vty,
efb4077a 8253 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8254 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8255 "#PeersEstb", "Name");
8256 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8257 "L3-VNI", "RouterMAC", "Interface");
8258 }
d62a17ae 8259
8260 peers_cfg = peers_estb = 0;
8261 if (uj)
8262 json_vrf = json_object_new_object();
8263
8264
7fe96307 8265 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8266 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8267 continue;
8268 peers_cfg++;
8269 if (peer->status == Established)
8270 peers_estb++;
8271 }
8272
8273 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8274 name = VRF_DEFAULT_NAME;
d62a17ae 8275 type = "DFLT";
8276 } else {
8277 name = bgp->name;
8278 type = "VRF";
8279 }
8280
a8bf7d9c 8281
d62a17ae 8282 if (uj) {
a4d82a8a
PZ
8283 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8284 ? -1
8285 : (int64_t)bgp->vrf_id;
d62a17ae 8286 json_object_string_add(json_vrf, "type", type);
8287 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8288 json_object_string_add(json_vrf, "routerId",
8289 inet_ntoa(bgp->router_id));
8290 json_object_int_add(json_vrf, "numConfiguredPeers",
8291 peers_cfg);
8292 json_object_int_add(json_vrf, "numEstablishedPeers",
8293 peers_estb);
8294
fe1dc5a3 8295 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8296 json_object_string_add(
8297 json_vrf, "rmac",
8298 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8299 json_object_string_add(json_vrf, "interface",
8300 ifindex2ifname(bgp->l3vni_svi_ifindex,
8301 bgp->vrf_id));
d62a17ae 8302 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8303 } else {
fe1dc5a3 8304 vty_out(vty,
efb4077a 8305 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8306 type,
8307 bgp->vrf_id == VRF_UNKNOWN ? -1
8308 : (int)bgp->vrf_id,
8309 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8310 peers_estb, name);
8311 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8312 bgp->l3vni,
8313 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8314 ifindex2ifname(bgp->l3vni_svi_ifindex,
8315 bgp->vrf_id));
8316 }
d62a17ae 8317 }
8318
8319 if (uj) {
8320 json_object_object_add(json, "vrfs", json_vrfs);
8321
8322 json_object_int_add(json, "totalVrfs", count);
8323
996c9314
LB
8324 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8325 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8326 json_object_free(json);
8327 } else {
8328 if (count)
8329 vty_out(vty,
8330 "\nTotal number of VRFs (including default): %d\n",
8331 count);
8332 }
8333
8334 return CMD_SUCCESS;
8386ac43 8335}
8336
48ecf8f5
DS
8337DEFUN (show_bgp_mac_hash,
8338 show_bgp_mac_hash_cmd,
8339 "show bgp mac hash",
8340 SHOW_STR
8341 BGP_STR
8342 "Mac Address\n"
8343 "Mac Address database\n")
8344{
8345 bgp_mac_dump_table(vty);
8346
8347 return CMD_SUCCESS;
8348}
acf71666 8349
e3b78da8 8350static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8351{
0291c246 8352 struct vty *vty = (struct vty *)args;
e3b78da8 8353 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8354
60466a63 8355 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8356 tip->refcnt);
8357}
8358
8359static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8360{
8361 vty_out(vty, "self nexthop database:\n");
af97a18b 8362 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8363
8364 vty_out(vty, "Tunnel-ip database:\n");
8365 hash_iterate(bgp->tip_hash,
e3b78da8 8366 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8367 vty);
8368}
8369
15c81ca4
DS
8370DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8371 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8372 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8373 "martian next-hops\n"
8374 "martian next-hop database\n")
acf71666 8375{
0291c246 8376 struct bgp *bgp = NULL;
15c81ca4 8377 int idx = 0;
9a8bdf1c
PG
8378 char *name = NULL;
8379
8380 /* [<vrf> VIEWVRFNAME] */
8381 if (argv_find(argv, argc, "vrf", &idx)) {
8382 name = argv[idx + 1]->arg;
8383 if (name && strmatch(name, VRF_DEFAULT_NAME))
8384 name = NULL;
8385 } else if (argv_find(argv, argc, "view", &idx))
8386 /* [<view> VIEWVRFNAME] */
8387 name = argv[idx + 1]->arg;
8388 if (name)
8389 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8390 else
8391 bgp = bgp_get_default();
acf71666 8392
acf71666
MK
8393 if (!bgp) {
8394 vty_out(vty, "%% No BGP process is configured\n");
8395 return CMD_WARNING;
8396 }
8397 bgp_show_martian_nexthops(vty, bgp);
8398
8399 return CMD_SUCCESS;
8400}
8401
f412b39a 8402DEFUN (show_bgp_memory,
4bf6a362 8403 show_bgp_memory_cmd,
7fa12b13 8404 "show [ip] bgp memory",
4bf6a362 8405 SHOW_STR
3a2d747c 8406 IP_STR
4bf6a362
PJ
8407 BGP_STR
8408 "Global BGP memory statistics\n")
8409{
d62a17ae 8410 char memstrbuf[MTYPE_MEMSTR_LEN];
8411 unsigned long count;
8412
8413 /* RIB related usage stats */
8414 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8415 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8416 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8417 count * sizeof(struct bgp_node)));
8418
8419 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8420 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8421 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8422 count * sizeof(struct bgp_path_info)));
d62a17ae 8423 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8424 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8425 count,
4b7e6066
DS
8426 mtype_memstr(
8427 memstrbuf, sizeof(memstrbuf),
8428 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8429
8430 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8431 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8432 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8433 count * sizeof(struct bgp_static)));
8434
8435 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8436 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8437 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8438 count * sizeof(struct bpacket)));
8439
8440 /* Adj-In/Out */
8441 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8442 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8443 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8444 count * sizeof(struct bgp_adj_in)));
8445 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8446 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8447 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8448 count * sizeof(struct bgp_adj_out)));
8449
8450 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8451 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8452 count,
8453 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8454 count * sizeof(struct bgp_nexthop_cache)));
8455
8456 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8457 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8458 count,
8459 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8460 count * sizeof(struct bgp_damp_info)));
8461
8462 /* Attributes */
8463 count = attr_count();
8464 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8465 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8466 count * sizeof(struct attr)));
8467
8468 if ((count = attr_unknown_count()))
8469 vty_out(vty, "%ld unknown attributes\n", count);
8470
8471 /* AS_PATH attributes */
8472 count = aspath_count();
8473 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8474 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8475 count * sizeof(struct aspath)));
8476
8477 count = mtype_stats_alloc(MTYPE_AS_SEG);
8478 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8480 count * sizeof(struct assegment)));
8481
8482 /* Other attributes */
8483 if ((count = community_count()))
8484 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8485 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8486 count * sizeof(struct community)));
d62a17ae 8487 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8488 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8489 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8490 count * sizeof(struct ecommunity)));
d62a17ae 8491 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8492 vty_out(vty,
8493 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
8494 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8495 count * sizeof(struct lcommunity)));
d62a17ae 8496
8497 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8498 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8500 count * sizeof(struct cluster_list)));
8501
8502 /* Peer related usage */
8503 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8504 vty_out(vty, "%ld peers, using %s of memory\n", count,
8505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8506 count * sizeof(struct peer)));
8507
8508 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8509 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8510 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8511 count * sizeof(struct peer_group)));
8512
8513 /* Other */
d62a17ae 8514 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8515 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
8516 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8517 count * sizeof(regex_t)));
d62a17ae 8518 return CMD_SUCCESS;
4bf6a362 8519}
fee0f4c6 8520
57a9c8a8
DS
8521static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8522{
8523 json_object *bestpath = json_object_new_object();
8524
8525 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
8526 json_object_string_add(bestpath, "asPath", "ignore");
8527
8528 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
8529 json_object_string_add(bestpath, "asPath", "confed");
8530
8531 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
8532 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
8533 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8534 "as-set");
8535 else
a4d82a8a 8536 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8537 "true");
8538 } else
a4d82a8a 8539 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
8540
8541 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
8542 json_object_string_add(bestpath, "compareRouterId", "true");
8543 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
8544 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
8545 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 8546 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
8547 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
8548 json_object_string_add(bestpath, "med",
8549 "missing-as-worst");
8550 else
8551 json_object_string_add(bestpath, "med", "true");
8552 }
8553
8554 json_object_object_add(json, "bestPath", bestpath);
8555}
8556
3577f1c5
DD
8557/* Print the error code/subcode for why the peer is down */
8558static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8559 json_object *json_peer, bool use_json)
8560{
8561 const char *code_str;
8562 const char *subcode_str;
8563
8564 if (use_json) {
8565 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8566 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8567 char errorcodesubcode_hexstr[5];
8568 char errorcodesubcode_str[256];
8569
8570 code_str = bgp_notify_code_str(peer->notify.code);
8571 subcode_str = bgp_notify_subcode_str(
8572 peer->notify.code,
8573 peer->notify.subcode);
8574
8575 sprintf(errorcodesubcode_hexstr, "%02X%02X",
8576 peer->notify.code, peer->notify.subcode);
8577 json_object_string_add(json_peer,
8578 "lastErrorCodeSubcode",
8579 errorcodesubcode_hexstr);
8580 snprintf(errorcodesubcode_str, 255, "%s%s",
8581 code_str, subcode_str);
8582 json_object_string_add(json_peer,
8583 "lastNotificationReason",
8584 errorcodesubcode_str);
8585 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8586 && peer->notify.code == BGP_NOTIFY_CEASE
8587 && (peer->notify.subcode
8588 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8589 || peer->notify.subcode
8590 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8591 && peer->notify.length) {
8592 char msgbuf[1024];
8593 const char *msg_str;
8594
8595 msg_str = bgp_notify_admin_message(
8596 msgbuf, sizeof(msgbuf),
8597 (uint8_t *)peer->notify.data,
8598 peer->notify.length);
8599 if (msg_str)
8600 json_object_string_add(
8601 json_peer,
8602 "lastShutdownDescription",
8603 msg_str);
8604 }
8605
c258527b 8606 }
3577f1c5
DD
8607 json_object_string_add(json_peer, "lastResetDueTo",
8608 peer_down_str[(int)peer->last_reset]);
05912a17
DD
8609 json_object_int_add(json_peer, "lastResetCode",
8610 peer->last_reset);
3577f1c5
DD
8611 } else {
8612 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8613 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8614 code_str = bgp_notify_code_str(peer->notify.code);
8615 subcode_str =
8616 bgp_notify_subcode_str(peer->notify.code,
8617 peer->notify.subcode);
8618 vty_out(vty, " Notification %s (%s%s)\n",
8619 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8620 ? "sent"
8621 : "received",
8622 code_str, subcode_str);
8623 } else {
8624 vty_out(vty, " %s\n",
8625 peer_down_str[(int)peer->last_reset]);
8626 }
8627 }
8628}
8629
8630static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8631 safi_t safi)
8632{
8633 return ((peer->status != Established) ||
8634 !peer->afc_recv[afi][safi]);
8635}
8636
8637static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8638 struct peer *peer, json_object *json_peer,
8639 int max_neighbor_width, bool use_json)
8640{
8641 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8642 int len;
8643
8644 if (use_json) {
8645 if (peer_dynamic_neighbor(peer))
8646 json_object_boolean_true_add(json_peer,
8647 "dynamicPeer");
8648 if (peer->hostname)
8649 json_object_string_add(json_peer, "hostname",
8650 peer->hostname);
8651
8652 if (peer->domainname)
8653 json_object_string_add(json_peer, "domainname",
8654 peer->domainname);
8655 json_object_int_add(json_peer, "connectionsEstablished",
8656 peer->established);
8657 json_object_int_add(json_peer, "connectionsDropped",
8658 peer->dropped);
8659 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8660 use_json, json_peer);
8661 if (peer->status == Established)
8662 json_object_string_add(json_peer, "lastResetDueTo",
8663 "AFI/SAFI Not Negotiated");
8664 else
8665 bgp_show_peer_reset(NULL, peer, json_peer, true);
8666 } else {
8667 dn_flag[1] = '\0';
8668 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8669 if (peer->hostname
8670 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8671 len = vty_out(vty, "%s%s(%s)", dn_flag,
8672 peer->hostname, peer->host);
8673 else
8674 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8675
8676 /* pad the neighbor column with spaces */
8677 if (len < max_neighbor_width)
8678 vty_out(vty, "%*s", max_neighbor_width - len,
8679 " ");
8680 vty_out(vty, "%7d %7d %8s", peer->established,
8681 peer->dropped,
8682 peer_uptime(peer->uptime, timebuf,
8683 BGP_UPTIME_LEN, 0, NULL));
8684 if (peer->status == Established)
8685 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8686 else
8687 bgp_show_peer_reset(vty, peer, NULL,
8688 false);
8689 }
8690}
c258527b 8691
3577f1c5 8692
718e3744 8693/* Show BGP peer's summary information. */
d62a17ae 8694static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 8695 bool show_failed, bool use_json)
d62a17ae 8696{
8697 struct peer *peer;
8698 struct listnode *node, *nnode;
8699 unsigned int count = 0, dn_count = 0;
8700 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8701 char neighbor_buf[VTY_BUFSIZ];
8702 int neighbor_col_default_width = 16;
3577f1c5 8703 int len, failed_count = 0;
d62a17ae 8704 int max_neighbor_width = 0;
8705 int pfx_rcd_safi;
3c13337d 8706 json_object *json = NULL;
d62a17ae 8707 json_object *json_peer = NULL;
8708 json_object *json_peers = NULL;
50e05855 8709 struct peer_af *paf;
d62a17ae 8710
8711 /* labeled-unicast routes are installed in the unicast table so in order
8712 * to
8713 * display the correct PfxRcd value we must look at SAFI_UNICAST
8714 */
3577f1c5 8715
d62a17ae 8716 if (safi == SAFI_LABELED_UNICAST)
8717 pfx_rcd_safi = SAFI_UNICAST;
8718 else
8719 pfx_rcd_safi = safi;
8720
8721 if (use_json) {
3c13337d 8722 json = json_object_new_object();
d62a17ae 8723 json_peers = json_object_new_object();
3577f1c5
DD
8724 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8725 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8726 continue;
8727
8728 if (peer->afc[afi][safi]) {
8729 /* See if we have at least a single failed peer */
8730 if (bgp_has_peer_failed(peer, afi, safi))
8731 failed_count++;
8732 count++;
8733 }
8734 if (peer_dynamic_neighbor(peer))
8735 dn_count++;
8736 }
c258527b 8737
d62a17ae 8738 } else {
8739 /* Loop over all neighbors that will be displayed to determine
8740 * how many
8741 * characters are needed for the Neighbor column
8742 */
8743 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8744 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8745 continue;
8746
8747 if (peer->afc[afi][safi]) {
8748 memset(dn_flag, '\0', sizeof(dn_flag));
8749 if (peer_dynamic_neighbor(peer))
8750 dn_flag[0] = '*';
8751
8752 if (peer->hostname
8753 && bgp_flag_check(bgp,
8754 BGP_FLAG_SHOW_HOSTNAME))
8755 sprintf(neighbor_buf, "%s%s(%s) ",
8756 dn_flag, peer->hostname,
8757 peer->host);
8758 else
8759 sprintf(neighbor_buf, "%s%s ", dn_flag,
8760 peer->host);
8761
8762 len = strlen(neighbor_buf);
8763
8764 if (len > max_neighbor_width)
8765 max_neighbor_width = len;
c258527b 8766
3577f1c5
DD
8767 /* See if we have at least a single failed peer */
8768 if (bgp_has_peer_failed(peer, afi, safi))
8769 failed_count++;
8770 count++;
d62a17ae 8771 }
8772 }
f933309e 8773
d62a17ae 8774 /* Originally we displayed the Neighbor column as 16
8775 * characters wide so make that the default
8776 */
8777 if (max_neighbor_width < neighbor_col_default_width)
8778 max_neighbor_width = neighbor_col_default_width;
8779 }
f933309e 8780
3577f1c5
DD
8781 if (show_failed && !failed_count) {
8782 if (use_json) {
8783 json_object_int_add(json, "failedPeersCount", 0);
8784 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 8785 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
8786
8787 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8788 json, JSON_C_TO_STRING_PRETTY));
8789 json_object_free(json);
8790 } else {
8791 vty_out(vty, "%% No failed BGP neighbors found\n");
8792 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8793 }
8794 return CMD_SUCCESS;
8795 }
c258527b 8796
3577f1c5 8797 count = 0; /* Reset the value as its used again */
d62a17ae 8798 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8799 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8800 continue;
8801
ea47320b
DL
8802 if (!peer->afc[afi][safi])
8803 continue;
d62a17ae 8804
ea47320b
DL
8805 if (!count) {
8806 unsigned long ents;
8807 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8808 int64_t vrf_id_ui;
d62a17ae 8809
a4d82a8a
PZ
8810 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8811 ? -1
8812 : (int64_t)bgp->vrf_id;
ea47320b
DL
8813
8814 /* Usage summary and header */
8815 if (use_json) {
8816 json_object_string_add(
8817 json, "routerId",
8818 inet_ntoa(bgp->router_id));
60466a63
QY
8819 json_object_int_add(json, "as", bgp->as);
8820 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8821 json_object_string_add(
8822 json, "vrfName",
8823 (bgp->inst_type
8824 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8825 ? VRF_DEFAULT_NAME
ea47320b
DL
8826 : bgp->name);
8827 } else {
8828 vty_out(vty,
8829 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8830 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8831 bgp->vrf_id == VRF_UNKNOWN
8832 ? -1
8833 : (int)bgp->vrf_id);
ea47320b
DL
8834 vty_out(vty, "\n");
8835 }
d62a17ae 8836
ea47320b 8837 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8838 if (use_json) {
ea47320b 8839 json_object_int_add(
60466a63 8840 json, "updateDelayLimit",
ea47320b 8841 bgp->v_update_delay);
d62a17ae 8842
ea47320b
DL
8843 if (bgp->v_update_delay
8844 != bgp->v_establish_wait)
d62a17ae 8845 json_object_int_add(
8846 json,
ea47320b
DL
8847 "updateDelayEstablishWait",
8848 bgp->v_establish_wait);
d62a17ae 8849
60466a63 8850 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8851 json_object_string_add(
8852 json,
8853 "updateDelayFirstNeighbor",
8854 bgp->update_delay_begin_time);
8855 json_object_boolean_true_add(
8856 json,
8857 "updateDelayInProgress");
8858 } else {
8859 if (bgp->update_delay_over) {
d62a17ae 8860 json_object_string_add(
8861 json,
8862 "updateDelayFirstNeighbor",
8863 bgp->update_delay_begin_time);
ea47320b 8864 json_object_string_add(
d62a17ae 8865 json,
ea47320b
DL
8866 "updateDelayBestpathResumed",
8867 bgp->update_delay_end_time);
8868 json_object_string_add(
d62a17ae 8869 json,
ea47320b
DL
8870 "updateDelayZebraUpdateResume",
8871 bgp->update_delay_zebra_resume_time);
8872 json_object_string_add(
8873 json,
8874 "updateDelayPeerUpdateResume",
8875 bgp->update_delay_peers_resume_time);
d62a17ae 8876 }
ea47320b
DL
8877 }
8878 } else {
8879 vty_out(vty,
8880 "Read-only mode update-delay limit: %d seconds\n",
8881 bgp->v_update_delay);
8882 if (bgp->v_update_delay
8883 != bgp->v_establish_wait)
d62a17ae 8884 vty_out(vty,
ea47320b
DL
8885 " Establish wait: %d seconds\n",
8886 bgp->v_establish_wait);
d62a17ae 8887
60466a63 8888 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8889 vty_out(vty,
8890 " First neighbor established: %s\n",
8891 bgp->update_delay_begin_time);
8892 vty_out(vty,
8893 " Delay in progress\n");
8894 } else {
8895 if (bgp->update_delay_over) {
d62a17ae 8896 vty_out(vty,
8897 " First neighbor established: %s\n",
8898 bgp->update_delay_begin_time);
8899 vty_out(vty,
ea47320b
DL
8900 " Best-paths resumed: %s\n",
8901 bgp->update_delay_end_time);
8902 vty_out(vty,
8903 " zebra update resumed: %s\n",
8904 bgp->update_delay_zebra_resume_time);
8905 vty_out(vty,
8906 " peers update resumed: %s\n",
8907 bgp->update_delay_peers_resume_time);
d62a17ae 8908 }
8909 }
8910 }
ea47320b 8911 }
d62a17ae 8912
ea47320b
DL
8913 if (use_json) {
8914 if (bgp_maxmed_onstartup_configured(bgp)
8915 && bgp->maxmed_active)
8916 json_object_boolean_true_add(
60466a63 8917 json, "maxMedOnStartup");
ea47320b
DL
8918 if (bgp->v_maxmed_admin)
8919 json_object_boolean_true_add(
60466a63 8920 json, "maxMedAdministrative");
d62a17ae 8921
ea47320b
DL
8922 json_object_int_add(
8923 json, "tableVersion",
60466a63 8924 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8925
60466a63
QY
8926 ents = bgp_table_count(bgp->rib[afi][safi]);
8927 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8928 json_object_int_add(
8929 json, "ribMemory",
8930 ents * sizeof(struct bgp_node));
d62a17ae 8931
210ec2a0 8932 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8933 json_object_int_add(json, "peerCount", ents);
8934 json_object_int_add(json, "peerMemory",
8935 ents * sizeof(struct peer));
d62a17ae 8936
ea47320b
DL
8937 if ((ents = listcount(bgp->group))) {
8938 json_object_int_add(
60466a63 8939 json, "peerGroupCount", ents);
ea47320b
DL
8940 json_object_int_add(
8941 json, "peerGroupMemory",
996c9314
LB
8942 ents * sizeof(struct
8943 peer_group));
ea47320b 8944 }
d62a17ae 8945
ea47320b
DL
8946 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8947 BGP_CONFIG_DAMPENING))
8948 json_object_boolean_true_add(
60466a63 8949 json, "dampeningEnabled");
ea47320b
DL
8950 } else {
8951 if (bgp_maxmed_onstartup_configured(bgp)
8952 && bgp->maxmed_active)
d62a17ae 8953 vty_out(vty,
ea47320b
DL
8954 "Max-med on-startup active\n");
8955 if (bgp->v_maxmed_admin)
d62a17ae 8956 vty_out(vty,
ea47320b 8957 "Max-med administrative active\n");
d62a17ae 8958
60466a63
QY
8959 vty_out(vty, "BGP table version %" PRIu64 "\n",
8960 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8961
60466a63 8962 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8963 vty_out(vty,
8964 "RIB entries %ld, using %s of memory\n",
8965 ents,
996c9314
LB
8966 mtype_memstr(memstrbuf,
8967 sizeof(memstrbuf),
8968 ents * sizeof(struct
8969 bgp_node)));
ea47320b
DL
8970
8971 /* Peer related usage */
210ec2a0 8972 ents = bgp->af_peer_count[afi][safi];
60466a63 8973 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8974 ents,
8975 mtype_memstr(
60466a63
QY
8976 memstrbuf, sizeof(memstrbuf),
8977 ents * sizeof(struct peer)));
ea47320b
DL
8978
8979 if ((ents = listcount(bgp->group)))
d62a17ae 8980 vty_out(vty,
ea47320b 8981 "Peer groups %ld, using %s of memory\n",
d62a17ae 8982 ents,
8983 mtype_memstr(
8984 memstrbuf,
8985 sizeof(memstrbuf),
996c9314
LB
8986 ents * sizeof(struct
8987 peer_group)));
d62a17ae 8988
ea47320b
DL
8989 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8990 BGP_CONFIG_DAMPENING))
60466a63 8991 vty_out(vty, "Dampening enabled.\n");
ea47320b 8992 vty_out(vty, "\n");
d62a17ae 8993
ea47320b
DL
8994 /* Subtract 8 here because 'Neighbor' is
8995 * 8 characters */
8996 vty_out(vty, "Neighbor");
60466a63
QY
8997 vty_out(vty, "%*s", max_neighbor_width - 8,
8998 " ");
3577f1c5
DD
8999 if (show_failed)
9000 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9001 else
9002 vty_out(vty,
ea47320b 9003 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 9004 }
ea47320b 9005 }
d62a17ae 9006
ea47320b 9007 count++;
3577f1c5
DD
9008 /* Works for both failed & successful cases */
9009 if (peer_dynamic_neighbor(peer))
9010 dn_count++;
d62a17ae 9011
ea47320b 9012 if (use_json) {
3577f1c5
DD
9013 json_peer = NULL;
9014
9015 if (show_failed &&
9016 bgp_has_peer_failed(peer, afi, safi)) {
9017 json_peer = json_object_new_object();
9018 bgp_show_failed_summary(vty, bgp, peer,
9019 json_peer, 0, use_json);
9020 } else if (!show_failed) {
9021 json_peer = json_object_new_object();
9022 if (peer_dynamic_neighbor(peer)) {
9023 json_object_boolean_true_add(json_peer,
9024 "dynamicPeer");
9025 }
d62a17ae 9026
3577f1c5
DD
9027 if (peer->hostname)
9028 json_object_string_add(json_peer, "hostname",
9029 peer->hostname);
9030
9031 if (peer->domainname)
9032 json_object_string_add(json_peer, "domainname",
9033 peer->domainname);
9034
9035 json_object_int_add(json_peer, "remoteAs", peer->as);
9036 json_object_int_add(json_peer, "version", 4);
9037 json_object_int_add(json_peer, "msgRcvd",
9038 PEER_TOTAL_RX(peer));
9039 json_object_int_add(json_peer, "msgSent",
9040 PEER_TOTAL_TX(peer));
9041
9042 json_object_int_add(json_peer, "tableVersion",
9043 peer->version[afi][safi]);
9044 json_object_int_add(json_peer, "outq",
9045 peer->obuf->count);
9046 json_object_int_add(json_peer, "inq", 0);
9047 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9048 use_json, json_peer);
9049
9050 /*
9051 * Adding "pfxRcd" field to match with the corresponding
9052 * CLI. "prefixReceivedCount" will be deprecated in
9053 * future.
9054 */
9055 json_object_int_add(json_peer, "prefixReceivedCount",
9056 peer->pcount[afi][pfx_rcd_safi]);
9057 json_object_int_add(json_peer, "pfxRcd",
9058 peer->pcount[afi][pfx_rcd_safi]);
9059
9060 paf = peer_af_find(peer, afi, pfx_rcd_safi);
9061 if (paf && PAF_SUBGRP(paf))
9062 json_object_int_add(json_peer,
9063 "pfxSnt",
9064 (PAF_SUBGRP(paf))->scount);
9065 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9066 json_object_string_add(json_peer, "state",
9067 "Idle (Admin)");
9068 else if (peer->afc_recv[afi][safi])
9069 json_object_string_add(
9070 json_peer, "state",
9071 lookup_msg(bgp_status_msg, peer->status,
9072 NULL));
9073 else if (CHECK_FLAG(peer->sflags,
9074 PEER_STATUS_PREFIX_OVERFLOW))
9075 json_object_string_add(json_peer, "state",
9076 "Idle (PfxCt)");
9077 else
9078 json_object_string_add(
9079 json_peer, "state",
9080 lookup_msg(bgp_status_msg, peer->status,
9081 NULL));
200116db
DD
9082 json_object_int_add(json_peer, "connectionsEstablished",
9083 peer->established);
9084 json_object_int_add(json_peer, "connectionsDropped",
9085 peer->dropped);
b4e9dcba 9086 }
3577f1c5
DD
9087 /* Avoid creating empty peer dicts in JSON */
9088 if (json_peer == NULL)
9089 continue;
ea47320b
DL
9090
9091 if (peer->conf_if)
60466a63 9092 json_object_string_add(json_peer, "idType",
ea47320b
DL
9093 "interface");
9094 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9095 json_object_string_add(json_peer, "idType",
9096 "ipv4");
ea47320b 9097 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9098 json_object_string_add(json_peer, "idType",
9099 "ipv6");
ea47320b
DL
9100 json_object_object_add(json_peers, peer->host,
9101 json_peer);
9102 } else {
3577f1c5
DD
9103 if (show_failed &&
9104 bgp_has_peer_failed(peer, afi, safi)) {
9105 bgp_show_failed_summary(vty, bgp, peer, NULL,
9106 max_neighbor_width,
9107 use_json);
9108 } else if (!show_failed) {
9109 memset(dn_flag, '\0', sizeof(dn_flag));
9110 if (peer_dynamic_neighbor(peer)) {
9111 dn_flag[0] = '*';
9112 }
d62a17ae 9113
3577f1c5
DD
9114 if (peer->hostname
9115 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
9116 len = vty_out(vty, "%s%s(%s)", dn_flag,
9117 peer->hostname, peer->host);
d62a17ae 9118 else
3577f1c5
DD
9119 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9120
9121 /* pad the neighbor column with spaces */
9122 if (len < max_neighbor_width)
9123 vty_out(vty, "%*s", max_neighbor_width - len,
9124 " ");
9125
9126 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
9127 peer->as, PEER_TOTAL_RX(peer),
9128 PEER_TOTAL_TX(peer), peer->version[afi][safi],
9129 0, peer->obuf->count,
9130 peer_uptime(peer->uptime, timebuf,
9131 BGP_UPTIME_LEN, 0, NULL));
9132
9133 if (peer->status == Established)
9134 if (peer->afc_recv[afi][safi])
a0a87037
DA
9135 vty_out(vty, " %12" PRIu32,
9136 peer->pcount
9137 [afi]
9138 [pfx_rcd_safi]);
3577f1c5
DD
9139 else
9140 vty_out(vty, " NoNeg");
9141 else {
9142 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9143 vty_out(vty, " Idle (Admin)");
9144 else if (CHECK_FLAG(
9145 peer->sflags,
9146 PEER_STATUS_PREFIX_OVERFLOW))
9147 vty_out(vty, " Idle (PfxCt)");
9148 else
9149 vty_out(vty, " %12s",
9150 lookup_msg(bgp_status_msg,
9151 peer->status, NULL));
9152 }
9153 vty_out(vty, "\n");
d62a17ae 9154 }
3577f1c5 9155
d62a17ae 9156 }
9157 }
f933309e 9158
d62a17ae 9159 if (use_json) {
9160 json_object_object_add(json, "peers", json_peers);
3577f1c5 9161 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9162 json_object_int_add(json, "totalPeers", count);
9163 json_object_int_add(json, "dynamicPeers", dn_count);
9164
3577f1c5
DD
9165 if (!show_failed)
9166 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9167
996c9314
LB
9168 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9169 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9170 json_object_free(json);
9171 } else {
9172 if (count)
9173 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9174 else {
d6ceaca3 9175 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9176 get_afi_safi_str(afi, safi, false));
d62a17ae 9177 }
b05a1c8b 9178
d6ceaca3 9179 if (dn_count) {
d62a17ae 9180 vty_out(vty, "* - dynamic neighbor\n");
9181 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9182 dn_count, bgp->dynamic_neighbors_limit);
9183 }
9184 }
1ff9a340 9185
d62a17ae 9186 return CMD_SUCCESS;
718e3744 9187}
9188
d62a17ae 9189static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 9190 int safi, bool show_failed, bool use_json)
d62a17ae 9191{
9192 int is_first = 1;
9193 int afi_wildcard = (afi == AFI_MAX);
9194 int safi_wildcard = (safi == SAFI_MAX);
9195 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9196 bool nbr_output = false;
d62a17ae 9197
9198 if (use_json && is_wildcard)
9199 vty_out(vty, "{\n");
9200 if (afi_wildcard)
9201 afi = 1; /* AFI_IP */
9202 while (afi < AFI_MAX) {
9203 if (safi_wildcard)
9204 safi = 1; /* SAFI_UNICAST */
9205 while (safi < SAFI_MAX) {
318cac96 9206 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9207 nbr_output = true;
f86897b9 9208
d62a17ae 9209 if (is_wildcard) {
9210 /*
9211 * So limit output to those afi/safi
9212 * pairs that
9213 * actualy have something interesting in
9214 * them
9215 */
9216 if (use_json) {
d62a17ae 9217 if (!is_first)
9218 vty_out(vty, ",\n");
9219 else
9220 is_first = 0;
9221
9222 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9223 get_afi_safi_str(afi,
9224 safi,
9225 true));
d62a17ae 9226 } else {
9227 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9228 get_afi_safi_str(afi,
9229 safi,
9230 false));
d62a17ae 9231 }
9232 }
3577f1c5
DD
9233 bgp_show_summary(vty, bgp, afi, safi, show_failed,
9234 use_json);
d62a17ae 9235 }
9236 safi++;
d62a17ae 9237 if (!safi_wildcard)
9238 safi = SAFI_MAX;
9239 }
9240 afi++;
ee851c8c 9241 if (!afi_wildcard)
d62a17ae 9242 afi = AFI_MAX;
9243 }
9244
9245 if (use_json && is_wildcard)
9246 vty_out(vty, "}\n");
ca61fd25
DS
9247 else if (!nbr_output) {
9248 if (use_json)
9249 vty_out(vty, "{}\n");
9250 else
9251 vty_out(vty, "%% No BGP neighbors found\n");
9252 }
d62a17ae 9253}
9254
9255static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
9256 safi_t safi, bool show_failed,
9257 bool use_json)
d62a17ae 9258{
9259 struct listnode *node, *nnode;
9260 struct bgp *bgp;
d62a17ae 9261 int is_first = 1;
9f049418 9262 bool nbr_output = false;
d62a17ae 9263
9264 if (use_json)
9265 vty_out(vty, "{\n");
9266
9267 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9268 nbr_output = true;
d62a17ae 9269 if (use_json) {
d62a17ae 9270 if (!is_first)
9271 vty_out(vty, ",\n");
9272 else
9273 is_first = 0;
9274
9275 vty_out(vty, "\"%s\":",
9276 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9277 ? VRF_DEFAULT_NAME
d62a17ae 9278 : bgp->name);
9279 } else {
9280 vty_out(vty, "\nInstance %s:\n",
9281 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9282 ? VRF_DEFAULT_NAME
d62a17ae 9283 : bgp->name);
9284 }
3577f1c5
DD
9285 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9286 use_json);
d62a17ae 9287 }
9288
9289 if (use_json)
9290 vty_out(vty, "}\n");
9f049418
DS
9291 else if (!nbr_output)
9292 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9293}
9294
9295int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 9296 safi_t safi, bool show_failed, bool use_json)
d62a17ae 9297{
9298 struct bgp *bgp;
9299
9300 if (name) {
9301 if (strmatch(name, "all")) {
9302 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 9303 show_failed,
d62a17ae 9304 use_json);
9305 return CMD_SUCCESS;
9306 } else {
9307 bgp = bgp_lookup_by_name(name);
9308
9309 if (!bgp) {
9310 if (use_json)
9311 vty_out(vty, "{}\n");
9312 else
9313 vty_out(vty,
ca61fd25 9314 "%% BGP instance not found\n");
d62a17ae 9315 return CMD_WARNING;
9316 }
9317
f86897b9 9318 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 9319 show_failed, use_json);
d62a17ae 9320 return CMD_SUCCESS;
9321 }
9322 }
9323
9324 bgp = bgp_get_default();
9325
9326 if (bgp)
3577f1c5
DD
9327 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9328 use_json);
9f049418 9329 else {
ca61fd25
DS
9330 if (use_json)
9331 vty_out(vty, "{}\n");
9332 else
9333 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9334 return CMD_WARNING;
9335 }
d62a17ae 9336
9337 return CMD_SUCCESS;
4fb25c53
DW
9338}
9339
716b2d8a 9340/* `show [ip] bgp summary' commands. */
47fc97cc 9341DEFUN (show_ip_bgp_summary,
718e3744 9342 show_ip_bgp_summary_cmd,
3577f1c5 9343 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
8386ac43 9347 BGP_INSTANCE_HELP_STR
46f296b4 9348 BGP_AFI_HELP_STR
dd6bd0f1 9349 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 9350 "Summary of BGP neighbor status\n"
3577f1c5 9351 "Show only sessions not in Established state\n"
9973d184 9352 JSON_STR)
718e3744 9353{
d62a17ae 9354 char *vrf = NULL;
9355 afi_t afi = AFI_MAX;
9356 safi_t safi = SAFI_MAX;
3577f1c5 9357 bool show_failed = false;
d62a17ae 9358
9359 int idx = 0;
9360
9361 /* show [ip] bgp */
9362 if (argv_find(argv, argc, "ip", &idx))
9363 afi = AFI_IP;
9a8bdf1c
PG
9364 /* [<vrf> VIEWVRFNAME] */
9365 if (argv_find(argv, argc, "vrf", &idx)) {
9366 vrf = argv[idx + 1]->arg;
9367 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9368 vrf = NULL;
9369 } else if (argv_find(argv, argc, "view", &idx))
9370 /* [<view> VIEWVRFNAME] */
9371 vrf = argv[idx + 1]->arg;
d62a17ae 9372 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9373 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9374 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9375 }
9376
3577f1c5
DD
9377 if (argv_find(argv, argc, "failed", &idx))
9378 show_failed = true;
9379
9f049418 9380 bool uj = use_json(argc, argv);
d62a17ae 9381
3577f1c5 9382 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 9383}
9384
5cb5f4d0 9385const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9386{
5cb5f4d0
DD
9387 if (for_json)
9388 return get_afi_safi_json_str(afi, safi);
d62a17ae 9389 else
5cb5f4d0 9390 return get_afi_safi_vty_str(afi, safi);
27162734
LB
9391}
9392
d62a17ae 9393
9394static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9395 afi_t afi, safi_t safi,
d7c0a89a
QY
9396 uint16_t adv_smcap, uint16_t adv_rmcap,
9397 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 9398 bool use_json, json_object *json_pref)
d62a17ae 9399{
9400 /* Send-Mode */
9401 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9402 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9403 if (use_json) {
9404 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9405 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9406 json_object_string_add(json_pref, "sendMode",
9407 "advertisedAndReceived");
9408 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9409 json_object_string_add(json_pref, "sendMode",
9410 "advertised");
9411 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9412 json_object_string_add(json_pref, "sendMode",
9413 "received");
9414 } else {
9415 vty_out(vty, " Send-mode: ");
9416 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9417 vty_out(vty, "advertised");
9418 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9419 vty_out(vty, "%sreceived",
9420 CHECK_FLAG(p->af_cap[afi][safi],
9421 adv_smcap)
9422 ? ", "
9423 : "");
9424 vty_out(vty, "\n");
9425 }
9426 }
9427
9428 /* Receive-Mode */
9429 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9430 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9431 if (use_json) {
9432 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9433 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9434 json_object_string_add(json_pref, "recvMode",
9435 "advertisedAndReceived");
9436 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9437 json_object_string_add(json_pref, "recvMode",
9438 "advertised");
9439 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9440 json_object_string_add(json_pref, "recvMode",
9441 "received");
9442 } else {
9443 vty_out(vty, " Receive-mode: ");
9444 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9445 vty_out(vty, "advertised");
9446 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9447 vty_out(vty, "%sreceived",
9448 CHECK_FLAG(p->af_cap[afi][safi],
9449 adv_rmcap)
9450 ? ", "
9451 : "");
9452 vty_out(vty, "\n");
9453 }
9454 }
9455}
9456
13909c4f
DS
9457static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9458 struct peer *p,
9459 bool use_json,
9460 json_object *json)
2986cac2 9461{
9462 bool rbit_status = 0;
9463
9464 if (!use_json)
9465 vty_out(vty, "\n R bit : ");
9466
13909c4f
DS
9467 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9468 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9469 && (p->status == Established)) {
2986cac2 9470
9471 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
9472 rbit_status = 1;
9473 else
9474 rbit_status = 0;
9475 }
9476
9477 if (rbit_status) {
9478 if (use_json)
13909c4f 9479 json_object_boolean_true_add(json, "rBit");
2986cac2 9480 else
9481 vty_out(vty, "True\n");
9482 } else {
9483 if (use_json)
13909c4f 9484 json_object_boolean_false_add(json, "rBit");
2986cac2 9485 else
9486 vty_out(vty, "False\n");
9487 }
9488}
9489
13909c4f
DS
9490static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9491 struct peer *peer,
9492 bool use_json,
9493 json_object *json)
2986cac2 9494{
2bb5d39b 9495 const char *mode = "NotApplicable";
2986cac2 9496
9497 if (!use_json)
9498 vty_out(vty, "\n Remote GR Mode : ");
9499
13909c4f
DS
9500 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9501 && (peer->status == Established)) {
2986cac2 9502
13909c4f
DS
9503 if ((peer->nsf_af_count == 0)
9504 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9505
2986cac2 9506 mode = "Disable";
9507
13909c4f
DS
9508 } else if (peer->nsf_af_count == 0
9509 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9510
2986cac2 9511 mode = "Helper";
9512
13909c4f
DS
9513 } else if (peer->nsf_af_count != 0
9514 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9515
2986cac2 9516 mode = "Restart";
2986cac2 9517 }
9518 }
9519
9520 if (use_json) {
13909c4f 9521 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 9522 } else
9523 vty_out(vty, mode, "\n");
9524}
9525
13909c4f
DS
9526static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9527 struct peer *p,
9528 bool use_json,
9529 json_object *json)
2986cac2 9530{
9531 const char *mode = "Invalid";
9532
9533 if (!use_json)
9534 vty_out(vty, " Local GR Mode : ");
9535
9536 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9537 mode = "Helper";
9538 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9539 mode = "Restart";
9540 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9541 mode = "Disable";
2ba1fe69 9542 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 9543 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9544 mode = "Helper*";
9545 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9546 mode = "Restart*";
9547 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9548 mode = "Disable*";
9549 else
9550 mode = "Invalid*";
2ba1fe69 9551 }
2986cac2 9552
9553 if (use_json) {
13909c4f 9554 json_object_string_add(json, "localGrMode", mode);
2986cac2 9555 } else {
9556 vty_out(vty, mode, "\n");
9557 }
9558}
9559
13909c4f
DS
9560static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9561 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 9562{
2ba1fe69 9563 afi_t afi;
9564 safi_t safi;
2986cac2 9565 json_object *json_afi_safi = NULL;
9566 json_object *json_timer = NULL;
9567 json_object *json_endofrib_status = NULL;
9e3b51a7 9568 bool eor_flag = false;
2986cac2 9569
9570 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9571 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
9572 if (!peer->afc[afi][safi])
9573 continue;
2986cac2 9574
13909c4f
DS
9575 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9576 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9577 continue;
9e3b51a7 9578
13909c4f
DS
9579 if (use_json) {
9580 json_afi_safi = json_object_new_object();
9581 json_endofrib_status = json_object_new_object();
9582 json_timer = json_object_new_object();
9583 }
2986cac2 9584
13909c4f
DS
9585 if (peer->eor_stime[afi][safi]
9586 >= peer->pkt_stime[afi][safi])
9587 eor_flag = true;
9588 else
9589 eor_flag = false;
2986cac2 9590
13909c4f
DS
9591 if (!use_json) {
9592 vty_out(vty, " %s :\n",
9593 get_afi_safi_str(afi, safi, false));
2986cac2 9594
13909c4f
DS
9595 vty_out(vty, " F bit : ");
9596 } else
9597 get_afi_safi_str(afi, safi, true);
2986cac2 9598
13909c4f
DS
9599 if (peer->nsf[afi][safi]
9600 && CHECK_FLAG(peer->af_cap[afi][safi],
9601 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9602
13909c4f
DS
9603 if (use_json) {
9604 json_object_boolean_true_add(
2986cac2 9605 json_afi_safi, "fBit");
13909c4f
DS
9606 } else
9607 vty_out(vty, "True\n");
9608 } else {
9609 if (use_json)
9610 json_object_boolean_false_add(
9611 json_afi_safi, "fBit");
9612 else
9613 vty_out(vty, "False\n");
9614 }
2986cac2 9615
13909c4f
DS
9616 if (!use_json)
9617 vty_out(vty, " End-of-RIB Received : ");
2986cac2 9618
13909c4f
DS
9619 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9620 PEER_STATUS_EOR_RECEIVED)) {
9621 if (use_json)
9622 json_object_boolean_true_add(
2986cac2 9623 json_endofrib_status,
13909c4f
DS
9624 "endOfRibRecv");
9625 else
9626 vty_out(vty, "Yes\n");
9627 } else {
9628 if (use_json)
9629 json_object_boolean_false_add(
2986cac2 9630 json_endofrib_status,
13909c4f
DS
9631 "endOfRibRecv");
9632 else
9633 vty_out(vty, "No\n");
9634 }
2986cac2 9635
13909c4f
DS
9636 if (!use_json)
9637 vty_out(vty, " End-of-RIB Send : ");
2986cac2 9638
13909c4f
DS
9639 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9640 PEER_STATUS_EOR_SEND)) {
9641 if (use_json) {
9642 json_object_boolean_true_add(
2986cac2 9643 json_endofrib_status,
13909c4f 9644 "endOfRibSend");
9e3b51a7 9645
13909c4f
DS
9646 PRINT_EOR_JSON(eor_flag);
9647 } else {
9648 vty_out(vty, "Yes\n");
9649 vty_out(vty,
9e3b51a7 9650 " EoRSentAfterUpdate : ");
2986cac2 9651
13909c4f
DS
9652 PRINT_EOR(eor_flag);
9653 }
9654 } else {
9655 if (use_json) {
9656 json_object_boolean_false_add(
2986cac2 9657 json_endofrib_status,
13909c4f
DS
9658 "endOfRibSend");
9659 json_object_boolean_false_add(
9e3b51a7 9660 json_endofrib_status,
13909c4f
DS
9661 "endOfRibSentAfterUpdate");
9662 } else {
9663 vty_out(vty, "No\n");
9664 vty_out(vty,
9e3b51a7 9665 " EoRSentAfterUpdate : ");
13909c4f 9666 vty_out(vty, "No\n");
2986cac2 9667 }
13909c4f 9668 }
2986cac2 9669
13909c4f
DS
9670 if (use_json) {
9671 json_object_int_add(json_timer,
9672 "stalePathTimer",
9673 peer->bgp->stalepath_time);
2986cac2 9674
13909c4f
DS
9675 if (peer->t_gr_stale != NULL) {
9676 json_object_int_add(
2986cac2 9677 json_timer,
9678 "stalePathTimerRemaining",
9679 thread_timer_remain_second(
13909c4f
DS
9680 peer->t_gr_stale));
9681 }
3a75afa4 9682
13909c4f
DS
9683 /* Display Configured Selection
9684 * Deferral only when when
9685 * Gr mode is enabled.
9686 */
9687 if (CHECK_FLAG(peer->flags,
9688 PEER_FLAG_GRACEFUL_RESTART)) {
9689 json_object_int_add(
3a75afa4 9690 json_timer,
2986cac2 9691 "selectionDeferralTimer",
9692 peer->bgp->stalepath_time);
13909c4f 9693 }
2986cac2 9694
13909c4f
DS
9695 if (peer->bgp->gr_info[afi][safi]
9696 .t_select_deferral
9697 != NULL) {
2986cac2 9698
13909c4f 9699 json_object_int_add(
2986cac2 9700 json_timer,
9701 "selectionDeferralTimerRemaining",
9702 thread_timer_remain_second(
13909c4f
DS
9703 peer->bgp
9704 ->gr_info[afi]
9705 [safi]
9706 .t_select_deferral));
9707 }
9708 } else {
9709 vty_out(vty, " Timers:\n");
2986cac2 9710
13909c4f
DS
9711 vty_out(vty, "%*s", 6, "");
9712 vty_out(vty,
9713 "Configured Stale Path Time(sec)%*s: %u\n",
9714 8, "", peer->bgp->stalepath_time);
2986cac2 9715
13909c4f 9716 if (peer->t_gr_stale != NULL) {
2986cac2 9717 vty_out(vty, "%*s", 6, "");
9718 vty_out(vty,
2986cac2 9719 "Stale Path Remaining(sec)%*s: %ld\n",
9720 14, "",
9721 thread_timer_remain_second(
13909c4f
DS
9722 peer->t_gr_stale));
9723 }
9724 /* Display Configured Selection
9725 * Deferral only when when
9726 * Gr mode is enabled.
9727 */
9728 if (CHECK_FLAG(peer->flags,
9729 PEER_FLAG_GRACEFUL_RESTART)) {
9730 vty_out(vty, "%*s", 6, "");
9731 vty_out(vty,
3a75afa4 9732 "Configured Selection Deferral Time(sec): %u\n",
9733 peer->bgp->select_defer_time);
13909c4f 9734 }
2986cac2 9735
13909c4f
DS
9736 if (peer->bgp->gr_info[afi][safi]
9737 .t_select_deferral
9738 != NULL) {
2986cac2 9739
13909c4f
DS
9740 vty_out(vty, "%*s", 6, "");
9741 vty_out(vty,
2986cac2 9742 "Selection Deferral Time Remaining(sec) : %ld\n",
9743 thread_timer_remain_second(
13909c4f
DS
9744 peer->bgp
9745 ->gr_info[afi]
9746 [safi]
9747 .t_select_deferral));
2986cac2 9748 }
9749 }
13909c4f
DS
9750 if (use_json) {
9751 json_object_object_add(json_afi_safi,
9752 "endOfRibStatus",
9753 json_endofrib_status);
9754 json_object_object_add(json_afi_safi, "timers",
9755 json_timer);
9756 json_object_object_add(
9757 json, get_afi_safi_str(afi, safi, true),
9758 json_afi_safi);
9759 }
2986cac2 9760 }
9761 }
9762}
9763
9764static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9765 struct peer *p,
9766 bool use_json,
9767 json_object *json)
9768{
9769 if (use_json) {
9770 json_object *json_timer = NULL;
9771
9772 json_timer = json_object_new_object();
9773
13909c4f
DS
9774 json_object_int_add(json_timer, "configuredRestartTimer",
9775 p->bgp->restart_time);
2986cac2 9776
13909c4f
DS
9777 json_object_int_add(json_timer, "receivedRestartTimer",
9778 p->v_gr_restart);
2986cac2 9779
13909c4f
DS
9780 if (p->t_gr_restart != NULL)
9781 json_object_int_add(
9782 json_timer, "restartTimerRemaining",
9783 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9784
9785 json_object_object_add(json, "timers", json_timer);
9786 } else {
9787
9788 vty_out(vty, " Timers :\n");
13909c4f
DS
9789 vty_out(vty, " Configured Restart Time(sec) : %u\n",
9790 p->bgp->restart_time);
2986cac2 9791
13909c4f
DS
9792 vty_out(vty, " Received Restart Time(sec) : %u\n",
9793 p->v_gr_restart);
9794 if (p->t_gr_restart != NULL)
2986cac2 9795 vty_out(vty,
13909c4f
DS
9796 " Restart Time Remaining(sec) : %ld\n",
9797 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9798 }
9799}
9800
9801static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
9802 bool use_json,
9803 json_object *json)
9804{
9805 char buf[SU_ADDRSTRLEN] = {0};
9806 char dn_flag[2] = {0};
9807 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9808
2986cac2 9809 if (!p->conf_if && peer_dynamic_neighbor(p))
9810 dn_flag[0] = '*';
9811
9812 if (p->conf_if) {
9813 if (use_json)
13909c4f
DS
9814 json_object_string_add(
9815 json, "neighborAddr",
2986cac2 9816 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
9817 ? "none"
9818 : sockunion2str(&p->su, buf,
9819 SU_ADDRSTRLEN));
2986cac2 9820 else
13909c4f 9821 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 9822 BGP_PEER_SU_UNSPEC(p)
9823 ? "none"
9824 : sockunion2str(&p->su, buf,
9825 SU_ADDRSTRLEN));
9826 } else {
9827 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9828
9829 if (use_json)
9830 json_object_string_add(
9831 json, "neighborAddr",
9832 neighborAddr);
9833 else
9834 vty_out(vty, "BGP neighbor is %s\n",
9835 neighborAddr);
9836 }
9837
9838 /* more gr info in new format */
9839 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9840}
9841
d62a17ae 9842static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 9843 safi_t safi, bool use_json,
d62a17ae 9844 json_object *json_neigh)
9845{
0291c246
MK
9846 struct bgp_filter *filter;
9847 struct peer_af *paf;
9848 char orf_pfx_name[BUFSIZ];
9849 int orf_pfx_count;
9850 json_object *json_af = NULL;
9851 json_object *json_prefA = NULL;
9852 json_object *json_prefB = NULL;
9853 json_object *json_addr = NULL;
d62a17ae 9854
9855 if (use_json) {
9856 json_addr = json_object_new_object();
9857 json_af = json_object_new_object();
9858 filter = &p->filter[afi][safi];
9859
9860 if (peer_group_active(p))
9861 json_object_string_add(json_addr, "peerGroupMember",
9862 p->group->name);
9863
9864 paf = peer_af_find(p, afi, safi);
9865 if (paf && PAF_SUBGRP(paf)) {
9866 json_object_int_add(json_addr, "updateGroupId",
9867 PAF_UPDGRP(paf)->id);
9868 json_object_int_add(json_addr, "subGroupId",
9869 PAF_SUBGRP(paf)->id);
9870 json_object_int_add(json_addr, "packetQueueLength",
9871 bpacket_queue_virtual_length(paf));
9872 }
9873
9874 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9875 || CHECK_FLAG(p->af_cap[afi][safi],
9876 PEER_CAP_ORF_PREFIX_SM_RCV)
9877 || CHECK_FLAG(p->af_cap[afi][safi],
9878 PEER_CAP_ORF_PREFIX_RM_ADV)
9879 || CHECK_FLAG(p->af_cap[afi][safi],
9880 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9881 json_object_int_add(json_af, "orfType",
9882 ORF_TYPE_PREFIX);
9883 json_prefA = json_object_new_object();
9884 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9885 PEER_CAP_ORF_PREFIX_SM_ADV,
9886 PEER_CAP_ORF_PREFIX_RM_ADV,
9887 PEER_CAP_ORF_PREFIX_SM_RCV,
9888 PEER_CAP_ORF_PREFIX_RM_RCV,
9889 use_json, json_prefA);
9890 json_object_object_add(json_af, "orfPrefixList",
9891 json_prefA);
9892 }
9893
9894 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9895 || CHECK_FLAG(p->af_cap[afi][safi],
9896 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9897 || CHECK_FLAG(p->af_cap[afi][safi],
9898 PEER_CAP_ORF_PREFIX_RM_ADV)
9899 || CHECK_FLAG(p->af_cap[afi][safi],
9900 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9901 json_object_int_add(json_af, "orfOldType",
9902 ORF_TYPE_PREFIX_OLD);
9903 json_prefB = json_object_new_object();
9904 bgp_show_peer_afi_orf_cap(
9905 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9906 PEER_CAP_ORF_PREFIX_RM_ADV,
9907 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9908 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9909 json_prefB);
9910 json_object_object_add(json_af, "orfOldPrefixList",
9911 json_prefB);
9912 }
9913
9914 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9915 || CHECK_FLAG(p->af_cap[afi][safi],
9916 PEER_CAP_ORF_PREFIX_SM_RCV)
9917 || CHECK_FLAG(p->af_cap[afi][safi],
9918 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9919 || CHECK_FLAG(p->af_cap[afi][safi],
9920 PEER_CAP_ORF_PREFIX_RM_ADV)
9921 || CHECK_FLAG(p->af_cap[afi][safi],
9922 PEER_CAP_ORF_PREFIX_RM_RCV)
9923 || CHECK_FLAG(p->af_cap[afi][safi],
9924 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9925 json_object_object_add(json_addr, "afDependentCap",
9926 json_af);
9927 else
9928 json_object_free(json_af);
9929
9930 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9931 orf_pfx_count = prefix_bgp_show_prefix_list(
9932 NULL, afi, orf_pfx_name, use_json);
9933
9934 if (CHECK_FLAG(p->af_sflags[afi][safi],
9935 PEER_STATUS_ORF_PREFIX_SEND)
9936 || orf_pfx_count) {
9937 if (CHECK_FLAG(p->af_sflags[afi][safi],
9938 PEER_STATUS_ORF_PREFIX_SEND))
9939 json_object_boolean_true_add(json_neigh,
9940 "orfSent");
9941 if (orf_pfx_count)
9942 json_object_int_add(json_addr, "orfRecvCounter",
9943 orf_pfx_count);
9944 }
9945 if (CHECK_FLAG(p->af_sflags[afi][safi],
9946 PEER_STATUS_ORF_WAIT_REFRESH))
9947 json_object_string_add(
9948 json_addr, "orfFirstUpdate",
9949 "deferredUntilORFOrRouteRefreshRecvd");
9950
9951 if (CHECK_FLAG(p->af_flags[afi][safi],
9952 PEER_FLAG_REFLECTOR_CLIENT))
9953 json_object_boolean_true_add(json_addr,
9954 "routeReflectorClient");
9955 if (CHECK_FLAG(p->af_flags[afi][safi],
9956 PEER_FLAG_RSERVER_CLIENT))
9957 json_object_boolean_true_add(json_addr,
9958 "routeServerClient");
9959 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9960 json_object_boolean_true_add(json_addr,
9961 "inboundSoftConfigPermit");
9962
9963 if (CHECK_FLAG(p->af_flags[afi][safi],
9964 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9965 json_object_boolean_true_add(
9966 json_addr,
9967 "privateAsNumsAllReplacedInUpdatesToNbr");
9968 else if (CHECK_FLAG(p->af_flags[afi][safi],
9969 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9970 json_object_boolean_true_add(
9971 json_addr,
9972 "privateAsNumsReplacedInUpdatesToNbr");
9973 else if (CHECK_FLAG(p->af_flags[afi][safi],
9974 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9975 json_object_boolean_true_add(
9976 json_addr,
9977 "privateAsNumsAllRemovedInUpdatesToNbr");
9978 else if (CHECK_FLAG(p->af_flags[afi][safi],
9979 PEER_FLAG_REMOVE_PRIVATE_AS))
9980 json_object_boolean_true_add(
9981 json_addr,
9982 "privateAsNumsRemovedInUpdatesToNbr");
9983
dcc68b5e
MS
9984 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9985 json_object_boolean_true_add(
9986 json_addr,
9987 bgp_addpath_names(p->addpath_type[afi][safi])
9988 ->type_json_name);
d62a17ae 9989
9990 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9991 json_object_string_add(json_addr,
9992 "overrideASNsInOutboundUpdates",
9993 "ifAspathEqualRemoteAs");
9994
9995 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9996 || CHECK_FLAG(p->af_flags[afi][safi],
9997 PEER_FLAG_FORCE_NEXTHOP_SELF))
9998 json_object_boolean_true_add(json_addr,
9999 "routerAlwaysNextHop");
10000 if (CHECK_FLAG(p->af_flags[afi][safi],
10001 PEER_FLAG_AS_PATH_UNCHANGED))
10002 json_object_boolean_true_add(
10003 json_addr, "unchangedAsPathPropogatedToNbr");
10004 if (CHECK_FLAG(p->af_flags[afi][safi],
10005 PEER_FLAG_NEXTHOP_UNCHANGED))
10006 json_object_boolean_true_add(
10007 json_addr, "unchangedNextHopPropogatedToNbr");
10008 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10009 json_object_boolean_true_add(
10010 json_addr, "unchangedMedPropogatedToNbr");
10011 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10012 || CHECK_FLAG(p->af_flags[afi][safi],
10013 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10014 if (CHECK_FLAG(p->af_flags[afi][safi],
10015 PEER_FLAG_SEND_COMMUNITY)
10016 && CHECK_FLAG(p->af_flags[afi][safi],
10017 PEER_FLAG_SEND_EXT_COMMUNITY))
10018 json_object_string_add(json_addr,
10019 "commAttriSentToNbr",
10020 "extendedAndStandard");
10021 else if (CHECK_FLAG(p->af_flags[afi][safi],
10022 PEER_FLAG_SEND_EXT_COMMUNITY))
10023 json_object_string_add(json_addr,
10024 "commAttriSentToNbr",
10025 "extended");
10026 else
10027 json_object_string_add(json_addr,
10028 "commAttriSentToNbr",
10029 "standard");
10030 }
10031 if (CHECK_FLAG(p->af_flags[afi][safi],
10032 PEER_FLAG_DEFAULT_ORIGINATE)) {
10033 if (p->default_rmap[afi][safi].name)
10034 json_object_string_add(
10035 json_addr, "defaultRouteMap",
10036 p->default_rmap[afi][safi].name);
10037
10038 if (paf && PAF_SUBGRP(paf)
10039 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10040 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10041 json_object_boolean_true_add(json_addr,
10042 "defaultSent");
10043 else
10044 json_object_boolean_true_add(json_addr,
10045 "defaultNotSent");
10046 }
10047
dff8f48d 10048 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10049 if (is_evpn_enabled())
60466a63
QY
10050 json_object_boolean_true_add(
10051 json_addr, "advertiseAllVnis");
dff8f48d
MK
10052 }
10053
d62a17ae 10054 if (filter->plist[FILTER_IN].name
10055 || filter->dlist[FILTER_IN].name
10056 || filter->aslist[FILTER_IN].name
10057 || filter->map[RMAP_IN].name)
10058 json_object_boolean_true_add(json_addr,
10059 "inboundPathPolicyConfig");
10060 if (filter->plist[FILTER_OUT].name
10061 || filter->dlist[FILTER_OUT].name
10062 || filter->aslist[FILTER_OUT].name
10063 || filter->map[RMAP_OUT].name || filter->usmap.name)
10064 json_object_boolean_true_add(
10065 json_addr, "outboundPathPolicyConfig");
10066
10067 /* prefix-list */
10068 if (filter->plist[FILTER_IN].name)
10069 json_object_string_add(json_addr,
10070 "incomingUpdatePrefixFilterList",
10071 filter->plist[FILTER_IN].name);
10072 if (filter->plist[FILTER_OUT].name)
10073 json_object_string_add(json_addr,
10074 "outgoingUpdatePrefixFilterList",
10075 filter->plist[FILTER_OUT].name);
10076
10077 /* distribute-list */
10078 if (filter->dlist[FILTER_IN].name)
10079 json_object_string_add(
10080 json_addr, "incomingUpdateNetworkFilterList",
10081 filter->dlist[FILTER_IN].name);
10082 if (filter->dlist[FILTER_OUT].name)
10083 json_object_string_add(
10084 json_addr, "outgoingUpdateNetworkFilterList",
10085 filter->dlist[FILTER_OUT].name);
10086
10087 /* filter-list. */
10088 if (filter->aslist[FILTER_IN].name)
10089 json_object_string_add(json_addr,
10090 "incomingUpdateAsPathFilterList",
10091 filter->aslist[FILTER_IN].name);
10092 if (filter->aslist[FILTER_OUT].name)
10093 json_object_string_add(json_addr,
10094 "outgoingUpdateAsPathFilterList",
10095 filter->aslist[FILTER_OUT].name);
10096
10097 /* route-map. */
10098 if (filter->map[RMAP_IN].name)
10099 json_object_string_add(
10100 json_addr, "routeMapForIncomingAdvertisements",
10101 filter->map[RMAP_IN].name);
10102 if (filter->map[RMAP_OUT].name)
10103 json_object_string_add(
10104 json_addr, "routeMapForOutgoingAdvertisements",
10105 filter->map[RMAP_OUT].name);
10106
9dac9fc8
DA
10107 /* ebgp-requires-policy (inbound) */
10108 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10109 && !bgp_inbound_policy_exists(p, filter))
10110 json_object_string_add(
10111 json_addr, "inboundEbgpRequiresPolicy",
10112 "Inbound updates discarded due to missing policy");
10113
10114 /* ebgp-requires-policy (outbound) */
10115 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10116 && (!bgp_outbound_policy_exists(p, filter)))
10117 json_object_string_add(
10118 json_addr, "outboundEbgpRequiresPolicy",
10119 "Outbound updates discarded due to missing policy");
10120
d62a17ae 10121 /* unsuppress-map */
10122 if (filter->usmap.name)
10123 json_object_string_add(json_addr,
10124 "selectiveUnsuppressRouteMap",
10125 filter->usmap.name);
10126
10127 /* Receive prefix count */
10128 json_object_int_add(json_addr, "acceptedPrefixCounter",
10129 p->pcount[afi][safi]);
50e05855
AD
10130 if (paf && PAF_SUBGRP(paf))
10131 json_object_int_add(json_addr, "sentPrefixCounter",
10132 (PAF_SUBGRP(paf))->scount);
d62a17ae 10133
fde246e8
DA
10134 /* Maximum prefix */
10135 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10136 json_object_int_add(json_addr, "prefixOutAllowedMax",
10137 p->pmax_out[afi][safi]);
10138
d62a17ae 10139 /* Maximum prefix */
10140 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10141 json_object_int_add(json_addr, "prefixAllowedMax",
10142 p->pmax[afi][safi]);
10143 if (CHECK_FLAG(p->af_flags[afi][safi],
10144 PEER_FLAG_MAX_PREFIX_WARNING))
10145 json_object_boolean_true_add(
10146 json_addr, "prefixAllowedMaxWarning");
10147 json_object_int_add(json_addr,
10148 "prefixAllowedWarningThresh",
10149 p->pmax_threshold[afi][safi]);
10150 if (p->pmax_restart[afi][safi])
10151 json_object_int_add(
10152 json_addr,
10153 "prefixAllowedRestartIntervalMsecs",
10154 p->pmax_restart[afi][safi] * 60000);
10155 }
2986cac2 10156 json_object_object_add(json_neigh,
10157 get_afi_safi_str(afi,
10158 safi, true),
d62a17ae 10159 json_addr);
10160
10161 } else {
10162 filter = &p->filter[afi][safi];
10163
10164 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10165 get_afi_safi_str(afi, safi, false));
d62a17ae 10166
10167 if (peer_group_active(p))
10168 vty_out(vty, " %s peer-group member\n",
10169 p->group->name);
10170
10171 paf = peer_af_find(p, afi, safi);
10172 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
10173 vty_out(vty, " Update group %" PRIu64
10174 ", subgroup %" PRIu64 "\n",
d62a17ae 10175 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10176 vty_out(vty, " Packet Queue length %d\n",
10177 bpacket_queue_virtual_length(paf));
10178 } else {
10179 vty_out(vty, " Not part of any update group\n");
10180 }
10181 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10182 || CHECK_FLAG(p->af_cap[afi][safi],
10183 PEER_CAP_ORF_PREFIX_SM_RCV)
10184 || CHECK_FLAG(p->af_cap[afi][safi],
10185 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10186 || CHECK_FLAG(p->af_cap[afi][safi],
10187 PEER_CAP_ORF_PREFIX_RM_ADV)
10188 || CHECK_FLAG(p->af_cap[afi][safi],
10189 PEER_CAP_ORF_PREFIX_RM_RCV)
10190 || CHECK_FLAG(p->af_cap[afi][safi],
10191 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10192 vty_out(vty, " AF-dependant capabilities:\n");
10193
10194 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10195 || CHECK_FLAG(p->af_cap[afi][safi],
10196 PEER_CAP_ORF_PREFIX_SM_RCV)
10197 || CHECK_FLAG(p->af_cap[afi][safi],
10198 PEER_CAP_ORF_PREFIX_RM_ADV)
10199 || CHECK_FLAG(p->af_cap[afi][safi],
10200 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10201 vty_out(vty,
10202 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10203 ORF_TYPE_PREFIX);
10204 bgp_show_peer_afi_orf_cap(
10205 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10206 PEER_CAP_ORF_PREFIX_RM_ADV,
10207 PEER_CAP_ORF_PREFIX_SM_RCV,
10208 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10209 }
10210 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10211 || CHECK_FLAG(p->af_cap[afi][safi],
10212 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10213 || CHECK_FLAG(p->af_cap[afi][safi],
10214 PEER_CAP_ORF_PREFIX_RM_ADV)
10215 || CHECK_FLAG(p->af_cap[afi][safi],
10216 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10217 vty_out(vty,
10218 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10219 ORF_TYPE_PREFIX_OLD);
10220 bgp_show_peer_afi_orf_cap(
10221 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10222 PEER_CAP_ORF_PREFIX_RM_ADV,
10223 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10224 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10225 }
10226
10227 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10228 orf_pfx_count = prefix_bgp_show_prefix_list(
10229 NULL, afi, orf_pfx_name, use_json);
10230
10231 if (CHECK_FLAG(p->af_sflags[afi][safi],
10232 PEER_STATUS_ORF_PREFIX_SEND)
10233 || orf_pfx_count) {
10234 vty_out(vty, " Outbound Route Filter (ORF):");
10235 if (CHECK_FLAG(p->af_sflags[afi][safi],
10236 PEER_STATUS_ORF_PREFIX_SEND))
10237 vty_out(vty, " sent;");
10238 if (orf_pfx_count)
10239 vty_out(vty, " received (%d entries)",
10240 orf_pfx_count);
10241 vty_out(vty, "\n");
10242 }
10243 if (CHECK_FLAG(p->af_sflags[afi][safi],
10244 PEER_STATUS_ORF_WAIT_REFRESH))
10245 vty_out(vty,
10246 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10247
10248 if (CHECK_FLAG(p->af_flags[afi][safi],
10249 PEER_FLAG_REFLECTOR_CLIENT))
10250 vty_out(vty, " Route-Reflector Client\n");
10251 if (CHECK_FLAG(p->af_flags[afi][safi],
10252 PEER_FLAG_RSERVER_CLIENT))
10253 vty_out(vty, " Route-Server Client\n");
10254 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10255 vty_out(vty,
10256 " Inbound soft reconfiguration allowed\n");
10257
10258 if (CHECK_FLAG(p->af_flags[afi][safi],
10259 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10260 vty_out(vty,
10261 " Private AS numbers (all) replaced in updates to this neighbor\n");
10262 else if (CHECK_FLAG(p->af_flags[afi][safi],
10263 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10264 vty_out(vty,
10265 " Private AS numbers replaced in updates to this neighbor\n");
10266 else if (CHECK_FLAG(p->af_flags[afi][safi],
10267 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10268 vty_out(vty,
10269 " Private AS numbers (all) removed in updates to this neighbor\n");
10270 else if (CHECK_FLAG(p->af_flags[afi][safi],
10271 PEER_FLAG_REMOVE_PRIVATE_AS))
10272 vty_out(vty,
10273 " Private AS numbers removed in updates to this neighbor\n");
10274
dcc68b5e
MS
10275 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10276 vty_out(vty, " %s\n",
10277 bgp_addpath_names(p->addpath_type[afi][safi])
10278 ->human_description);
d62a17ae 10279
10280 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10281 vty_out(vty,
10282 " Override ASNs in outbound updates if aspath equals remote-as\n");
10283
10284 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10285 || CHECK_FLAG(p->af_flags[afi][safi],
10286 PEER_FLAG_FORCE_NEXTHOP_SELF))
10287 vty_out(vty, " NEXT_HOP is always this router\n");
10288 if (CHECK_FLAG(p->af_flags[afi][safi],
10289 PEER_FLAG_AS_PATH_UNCHANGED))
10290 vty_out(vty,
10291 " AS_PATH is propagated unchanged to this neighbor\n");
10292 if (CHECK_FLAG(p->af_flags[afi][safi],
10293 PEER_FLAG_NEXTHOP_UNCHANGED))
10294 vty_out(vty,
10295 " NEXT_HOP is propagated unchanged to this neighbor\n");
10296 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10297 vty_out(vty,
10298 " MED is propagated unchanged to this neighbor\n");
10299 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10300 || CHECK_FLAG(p->af_flags[afi][safi],
10301 PEER_FLAG_SEND_EXT_COMMUNITY)
10302 || CHECK_FLAG(p->af_flags[afi][safi],
10303 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10304 vty_out(vty,
10305 " Community attribute sent to this neighbor");
10306 if (CHECK_FLAG(p->af_flags[afi][safi],
10307 PEER_FLAG_SEND_COMMUNITY)
10308 && CHECK_FLAG(p->af_flags[afi][safi],
10309 PEER_FLAG_SEND_EXT_COMMUNITY)
10310 && CHECK_FLAG(p->af_flags[afi][safi],
10311 PEER_FLAG_SEND_LARGE_COMMUNITY))
10312 vty_out(vty, "(all)\n");
10313 else if (CHECK_FLAG(p->af_flags[afi][safi],
10314 PEER_FLAG_SEND_LARGE_COMMUNITY))
10315 vty_out(vty, "(large)\n");
10316 else if (CHECK_FLAG(p->af_flags[afi][safi],
10317 PEER_FLAG_SEND_EXT_COMMUNITY))
10318 vty_out(vty, "(extended)\n");
10319 else
10320 vty_out(vty, "(standard)\n");
10321 }
10322 if (CHECK_FLAG(p->af_flags[afi][safi],
10323 PEER_FLAG_DEFAULT_ORIGINATE)) {
10324 vty_out(vty, " Default information originate,");
10325
10326 if (p->default_rmap[afi][safi].name)
10327 vty_out(vty, " default route-map %s%s,",
10328 p->default_rmap[afi][safi].map ? "*"
10329 : "",
10330 p->default_rmap[afi][safi].name);
10331 if (paf && PAF_SUBGRP(paf)
10332 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10333 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10334 vty_out(vty, " default sent\n");
10335 else
10336 vty_out(vty, " default not sent\n");
10337 }
10338
dff8f48d
MK
10339 /* advertise-vni-all */
10340 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10341 if (is_evpn_enabled())
dff8f48d
MK
10342 vty_out(vty, " advertise-all-vni\n");
10343 }
10344
d62a17ae 10345 if (filter->plist[FILTER_IN].name
10346 || filter->dlist[FILTER_IN].name
10347 || filter->aslist[FILTER_IN].name
10348 || filter->map[RMAP_IN].name)
10349 vty_out(vty, " Inbound path policy configured\n");
10350 if (filter->plist[FILTER_OUT].name
10351 || filter->dlist[FILTER_OUT].name
10352 || filter->aslist[FILTER_OUT].name
10353 || filter->map[RMAP_OUT].name || filter->usmap.name)
10354 vty_out(vty, " Outbound path policy configured\n");
10355
10356 /* prefix-list */
10357 if (filter->plist[FILTER_IN].name)
10358 vty_out(vty,
10359 " Incoming update prefix filter list is %s%s\n",
10360 filter->plist[FILTER_IN].plist ? "*" : "",
10361 filter->plist[FILTER_IN].name);
10362 if (filter->plist[FILTER_OUT].name)
10363 vty_out(vty,
10364 " Outgoing update prefix filter list is %s%s\n",
10365 filter->plist[FILTER_OUT].plist ? "*" : "",
10366 filter->plist[FILTER_OUT].name);
10367
10368 /* distribute-list */
10369 if (filter->dlist[FILTER_IN].name)
10370 vty_out(vty,
10371 " Incoming update network filter list is %s%s\n",
10372 filter->dlist[FILTER_IN].alist ? "*" : "",
10373 filter->dlist[FILTER_IN].name);
10374 if (filter->dlist[FILTER_OUT].name)
10375 vty_out(vty,
10376 " Outgoing update network filter list is %s%s\n",
10377 filter->dlist[FILTER_OUT].alist ? "*" : "",
10378 filter->dlist[FILTER_OUT].name);
10379
10380 /* filter-list. */
10381 if (filter->aslist[FILTER_IN].name)
10382 vty_out(vty,
10383 " Incoming update AS path filter list is %s%s\n",
10384 filter->aslist[FILTER_IN].aslist ? "*" : "",
10385 filter->aslist[FILTER_IN].name);
10386 if (filter->aslist[FILTER_OUT].name)
10387 vty_out(vty,
10388 " Outgoing update AS path filter list is %s%s\n",
10389 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10390 filter->aslist[FILTER_OUT].name);
10391
10392 /* route-map. */
10393 if (filter->map[RMAP_IN].name)
10394 vty_out(vty,
10395 " Route map for incoming advertisements is %s%s\n",
10396 filter->map[RMAP_IN].map ? "*" : "",
10397 filter->map[RMAP_IN].name);
10398 if (filter->map[RMAP_OUT].name)
10399 vty_out(vty,
10400 " Route map for outgoing advertisements is %s%s\n",
10401 filter->map[RMAP_OUT].map ? "*" : "",
10402 filter->map[RMAP_OUT].name);
10403
9dac9fc8
DA
10404 /* ebgp-requires-policy (inbound) */
10405 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10406 && !bgp_inbound_policy_exists(p, filter))
10407 vty_out(vty,
10408 " Inbound updates discarded due to missing policy\n");
10409
10410 /* ebgp-requires-policy (outbound) */
10411 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10412 && !bgp_outbound_policy_exists(p, filter))
10413 vty_out(vty,
10414 " Outbound updates discarded due to missing policy\n");
10415
d62a17ae 10416 /* unsuppress-map */
10417 if (filter->usmap.name)
10418 vty_out(vty,
10419 " Route map for selective unsuppress is %s%s\n",
10420 filter->usmap.map ? "*" : "",
10421 filter->usmap.name);
10422
10423 /* Receive prefix count */
a0a87037
DA
10424 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10425 p->pcount[afi][safi]);
d62a17ae 10426
fde246e8
DA
10427 /* maximum-prefix-out */
10428 if (CHECK_FLAG(p->af_flags[afi][safi],
10429 PEER_FLAG_MAX_PREFIX_OUT))
10430 vty_out(vty,
10431 " Maximum allowed prefixes sent %" PRIu32 "\n",
10432 p->pmax_out[afi][safi]);
10433
d62a17ae 10434 /* Maximum prefix */
10435 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
10436 vty_out(vty,
10437 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 10438 p->pmax[afi][safi],
10439 CHECK_FLAG(p->af_flags[afi][safi],
10440 PEER_FLAG_MAX_PREFIX_WARNING)
10441 ? " (warning-only)"
10442 : "");
10443 vty_out(vty, " Threshold for warning message %d%%",
10444 p->pmax_threshold[afi][safi]);
10445 if (p->pmax_restart[afi][safi])
10446 vty_out(vty, ", restart interval %d min",
10447 p->pmax_restart[afi][safi]);
10448 vty_out(vty, "\n");
10449 }
10450
10451 vty_out(vty, "\n");
10452 }
10453}
10454
9f049418 10455static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10456 json_object *json)
718e3744 10457{
d62a17ae 10458 struct bgp *bgp;
10459 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10460 char timebuf[BGP_UPTIME_LEN];
10461 char dn_flag[2];
d62a17ae 10462 afi_t afi;
10463 safi_t safi;
d7c0a89a
QY
10464 uint16_t i;
10465 uint8_t *msg;
d62a17ae 10466 json_object *json_neigh = NULL;
10467 time_t epoch_tbuf;
718e3744 10468
d62a17ae 10469 bgp = p->bgp;
10470
10471 if (use_json)
10472 json_neigh = json_object_new_object();
10473
10474 memset(dn_flag, '\0', sizeof(dn_flag));
10475 if (!p->conf_if && peer_dynamic_neighbor(p))
10476 dn_flag[0] = '*';
10477
10478 if (!use_json) {
10479 if (p->conf_if) /* Configured interface name. */
10480 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10481 BGP_PEER_SU_UNSPEC(p)
10482 ? "None"
10483 : sockunion2str(&p->su, buf,
10484 SU_ADDRSTRLEN));
10485 else /* Configured IP address. */
10486 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10487 p->host);
10488 }
10489
10490 if (use_json) {
10491 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10492 json_object_string_add(json_neigh, "bgpNeighborAddr",
10493 "none");
10494 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10495 json_object_string_add(
10496 json_neigh, "bgpNeighborAddr",
10497 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10498
10499 json_object_int_add(json_neigh, "remoteAs", p->as);
10500
10501 if (p->change_local_as)
10502 json_object_int_add(json_neigh, "localAs",
10503 p->change_local_as);
10504 else
10505 json_object_int_add(json_neigh, "localAs", p->local_as);
10506
10507 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10508 json_object_boolean_true_add(json_neigh,
10509 "localAsNoPrepend");
10510
10511 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10512 json_object_boolean_true_add(json_neigh,
10513 "localAsReplaceAs");
10514 } else {
10515 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10516 || (p->as_type == AS_INTERNAL))
10517 vty_out(vty, "remote AS %u, ", p->as);
10518 else
10519 vty_out(vty, "remote AS Unspecified, ");
10520 vty_out(vty, "local AS %u%s%s, ",
10521 p->change_local_as ? p->change_local_as : p->local_as,
10522 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10523 ? " no-prepend"
10524 : "",
10525 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10526 ? " replace-as"
10527 : "");
10528 }
faa16034
DS
10529 /* peer type internal or confed-internal */
10530 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10531 if (use_json) {
10532 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10533 json_object_boolean_true_add(
10534 json_neigh, "nbrConfedInternalLink");
10535 else
10536 json_object_boolean_true_add(json_neigh,
10537 "nbrInternalLink");
10538 } else {
10539 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10540 vty_out(vty, "confed-internal link\n");
10541 else
10542 vty_out(vty, "internal link\n");
10543 }
faa16034
DS
10544 /* peer type external or confed-external */
10545 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10546 if (use_json) {
10547 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10548 json_object_boolean_true_add(
10549 json_neigh, "nbrConfedExternalLink");
10550 else
10551 json_object_boolean_true_add(json_neigh,
10552 "nbrExternalLink");
10553 } else {
10554 if (bgp_confederation_peers_check(bgp, p->as))
10555 vty_out(vty, "confed-external link\n");
10556 else
10557 vty_out(vty, "external link\n");
10558 }
faa16034
DS
10559 } else {
10560 if (use_json)
10561 json_object_boolean_true_add(json_neigh,
10562 "nbrUnspecifiedLink");
10563 else
10564 vty_out(vty, "unspecified link\n");
d62a17ae 10565 }
10566
10567 /* Description. */
10568 if (p->desc) {
10569 if (use_json)
10570 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10571 else
10572 vty_out(vty, " Description: %s\n", p->desc);
10573 }
10574
10575 if (p->hostname) {
10576 if (use_json) {
10577 if (p->hostname)
10578 json_object_string_add(json_neigh, "hostname",
10579 p->hostname);
10580
10581 if (p->domainname)
10582 json_object_string_add(json_neigh, "domainname",
10583 p->domainname);
10584 } else {
10585 if (p->domainname && (p->domainname[0] != '\0'))
10586 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10587 p->domainname);
10588 else
10589 vty_out(vty, "Hostname: %s\n", p->hostname);
10590 }
10591 }
10592
10593 /* Peer-group */
10594 if (p->group) {
10595 if (use_json) {
10596 json_object_string_add(json_neigh, "peerGroup",
10597 p->group->name);
10598
10599 if (dn_flag[0]) {
10600 struct prefix prefix, *range = NULL;
10601
10602 sockunion2hostprefix(&(p->su), &prefix);
10603 range = peer_group_lookup_dynamic_neighbor_range(
10604 p->group, &prefix);
10605
10606 if (range) {
10607 prefix2str(range, buf1, sizeof(buf1));
10608 json_object_string_add(
10609 json_neigh,
10610 "peerSubnetRangeGroup", buf1);
10611 }
10612 }
10613 } else {
10614 vty_out(vty,
10615 " Member of peer-group %s for session parameters\n",
10616 p->group->name);
10617
10618 if (dn_flag[0]) {
10619 struct prefix prefix, *range = NULL;
10620
10621 sockunion2hostprefix(&(p->su), &prefix);
10622 range = peer_group_lookup_dynamic_neighbor_range(
10623 p->group, &prefix);
10624
10625 if (range) {
10626 prefix2str(range, buf1, sizeof(buf1));
10627 vty_out(vty,
10628 " Belongs to the subnet range group: %s\n",
10629 buf1);
10630 }
10631 }
10632 }
10633 }
10634
10635 if (use_json) {
10636 /* Administrative shutdown. */
10637 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10638 json_object_boolean_true_add(json_neigh,
10639 "adminShutDown");
10640
10641 /* BGP Version. */
10642 json_object_int_add(json_neigh, "bgpVersion", 4);
10643 json_object_string_add(
10644 json_neigh, "remoteRouterId",
10645 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10646 json_object_string_add(
10647 json_neigh, "localRouterId",
10648 inet_ntop(AF_INET, &bgp->router_id, buf1,
10649 sizeof(buf1)));
d62a17ae 10650
10651 /* Confederation */
10652 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10653 && bgp_confederation_peers_check(bgp, p->as))
10654 json_object_boolean_true_add(json_neigh,
10655 "nbrCommonAdmin");
10656
10657 /* Status. */
10658 json_object_string_add(
10659 json_neigh, "bgpState",
10660 lookup_msg(bgp_status_msg, p->status, NULL));
10661
10662 if (p->status == Established) {
10663 time_t uptime;
d62a17ae 10664
10665 uptime = bgp_clock();
10666 uptime -= p->uptime;
d62a17ae 10667 epoch_tbuf = time(NULL) - uptime;
10668
d3c7efed
DS
10669 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10670 uptime * 1000);
d62a17ae 10671 json_object_string_add(json_neigh, "bgpTimerUpString",
10672 peer_uptime(p->uptime, timebuf,
10673 BGP_UPTIME_LEN, 0,
10674 NULL));
10675 json_object_int_add(json_neigh,
10676 "bgpTimerUpEstablishedEpoch",
10677 epoch_tbuf);
10678 }
10679
10680 else if (p->status == Active) {
10681 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10682 json_object_string_add(json_neigh, "bgpStateIs",
10683 "passive");
10684 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10685 json_object_string_add(json_neigh, "bgpStateIs",
10686 "passiveNSF");
10687 }
10688
10689 /* read timer */
10690 time_t uptime;
10691 struct tm *tm;
10692
10693 uptime = bgp_clock();
10694 uptime -= p->readtime;
10695 tm = gmtime(&uptime);
10696 json_object_int_add(json_neigh, "bgpTimerLastRead",
10697 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10698 + (tm->tm_hour * 3600000));
10699
10700 uptime = bgp_clock();
10701 uptime -= p->last_write;
10702 tm = gmtime(&uptime);
10703 json_object_int_add(json_neigh, "bgpTimerLastWrite",
10704 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10705 + (tm->tm_hour * 3600000));
10706
10707 uptime = bgp_clock();
10708 uptime -= p->update_time;
10709 tm = gmtime(&uptime);
10710 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
10711 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10712 + (tm->tm_hour * 3600000));
10713
10714 /* Configured timer values. */
10715 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10716 p->v_holdtime * 1000);
10717 json_object_int_add(json_neigh,
10718 "bgpTimerKeepAliveIntervalMsecs",
10719 p->v_keepalive * 1000);
b90a8e13 10720 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10721 json_object_int_add(json_neigh,
10722 "bgpTimerConfiguredHoldTimeMsecs",
10723 p->holdtime * 1000);
10724 json_object_int_add(
10725 json_neigh,
10726 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10727 p->keepalive * 1000);
5d5393b9
DL
10728 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10729 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10730 json_object_int_add(json_neigh,
10731 "bgpTimerConfiguredHoldTimeMsecs",
10732 bgp->default_holdtime);
10733 json_object_int_add(
10734 json_neigh,
10735 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10736 bgp->default_keepalive);
d62a17ae 10737 }
10738 } else {
10739 /* Administrative shutdown. */
10740 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10741 vty_out(vty, " Administratively shut down\n");
10742
10743 /* BGP Version. */
10744 vty_out(vty, " BGP version 4");
0e38aeb4 10745 vty_out(vty, ", remote router ID %s",
d62a17ae 10746 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
10747 vty_out(vty, ", local router ID %s\n",
10748 inet_ntop(AF_INET, &bgp->router_id, buf1,
10749 sizeof(buf1)));
d62a17ae 10750
10751 /* Confederation */
10752 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10753 && bgp_confederation_peers_check(bgp, p->as))
10754 vty_out(vty,
10755 " Neighbor under common administration\n");
10756
10757 /* Status. */
10758 vty_out(vty, " BGP state = %s",
10759 lookup_msg(bgp_status_msg, p->status, NULL));
10760
10761 if (p->status == Established)
10762 vty_out(vty, ", up for %8s",
10763 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10764 0, NULL));
10765
10766 else if (p->status == Active) {
10767 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10768 vty_out(vty, " (passive)");
10769 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10770 vty_out(vty, " (NSF passive)");
10771 }
10772 vty_out(vty, "\n");
10773
10774 /* read timer */
10775 vty_out(vty, " Last read %s",
10776 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10777 NULL));
10778 vty_out(vty, ", Last write %s\n",
10779 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10780 NULL));
10781
10782 /* Configured timer values. */
10783 vty_out(vty,
10784 " Hold time is %d, keepalive interval is %d seconds\n",
10785 p->v_holdtime, p->v_keepalive);
b90a8e13 10786 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10787 vty_out(vty, " Configured hold time is %d",
10788 p->holdtime);
10789 vty_out(vty, ", keepalive interval is %d seconds\n",
10790 p->keepalive);
5d5393b9
DL
10791 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10792 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10793 vty_out(vty, " Configured hold time is %d",
10794 bgp->default_holdtime);
10795 vty_out(vty, ", keepalive interval is %d seconds\n",
10796 bgp->default_keepalive);
d62a17ae 10797 }
10798 }
10799 /* Capability. */
10800 if (p->status == Established) {
10801 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10802 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10803 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10804 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10805 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10806 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10807 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10808 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10809 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10810 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10811 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10812 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 10813 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10814 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 10815 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10816 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 10817 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10818 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 10819 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10820 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10821 if (use_json) {
10822 json_object *json_cap = NULL;
10823
10824 json_cap = json_object_new_object();
10825
10826 /* AS4 */
10827 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10828 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10829 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10830 && CHECK_FLAG(p->cap,
10831 PEER_CAP_AS4_RCV))
10832 json_object_string_add(
10833 json_cap, "4byteAs",
10834 "advertisedAndReceived");
10835 else if (CHECK_FLAG(p->cap,
10836 PEER_CAP_AS4_ADV))
10837 json_object_string_add(
10838 json_cap, "4byteAs",
10839 "advertised");
10840 else if (CHECK_FLAG(p->cap,
10841 PEER_CAP_AS4_RCV))
10842 json_object_string_add(
10843 json_cap, "4byteAs",
10844 "received");
10845 }
10846
10847 /* AddPath */
10848 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10849 || CHECK_FLAG(p->cap,
10850 PEER_CAP_ADDPATH_ADV)) {
10851 json_object *json_add = NULL;
10852 const char *print_store;
10853
10854 json_add = json_object_new_object();
10855
05c7a1cc
QY
10856 FOREACH_AFI_SAFI (afi, safi) {
10857 json_object *json_sub = NULL;
10858 json_sub =
10859 json_object_new_object();
5cb5f4d0
DD
10860 print_store = get_afi_safi_str(
10861 afi, safi, true);
d62a17ae 10862
05c7a1cc
QY
10863 if (CHECK_FLAG(
10864 p->af_cap[afi]
10865 [safi],
10866 PEER_CAP_ADDPATH_AF_TX_ADV)
10867 || CHECK_FLAG(
10868 p->af_cap[afi]
10869 [safi],
10870 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 10871 if (CHECK_FLAG(
10872 p->af_cap
10873 [afi]
10874 [safi],
10875 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 10876 && CHECK_FLAG(
d62a17ae 10877 p->af_cap
10878 [afi]
10879 [safi],
05c7a1cc
QY
10880 PEER_CAP_ADDPATH_AF_TX_RCV))
10881 json_object_boolean_true_add(
10882 json_sub,
10883 "txAdvertisedAndReceived");
10884 else if (
10885 CHECK_FLAG(
10886 p->af_cap
10887 [afi]
10888 [safi],
10889 PEER_CAP_ADDPATH_AF_TX_ADV))
10890 json_object_boolean_true_add(
10891 json_sub,
10892 "txAdvertised");
10893 else if (
10894 CHECK_FLAG(
10895 p->af_cap
10896 [afi]
10897 [safi],
10898 PEER_CAP_ADDPATH_AF_TX_RCV))
10899 json_object_boolean_true_add(
10900 json_sub,
10901 "txReceived");
10902 }
d62a17ae 10903
05c7a1cc
QY
10904 if (CHECK_FLAG(
10905 p->af_cap[afi]
10906 [safi],
10907 PEER_CAP_ADDPATH_AF_RX_ADV)
10908 || CHECK_FLAG(
10909 p->af_cap[afi]
10910 [safi],
10911 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 10912 if (CHECK_FLAG(
10913 p->af_cap
10914 [afi]
10915 [safi],
10916 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 10917 && CHECK_FLAG(
d62a17ae 10918 p->af_cap
10919 [afi]
10920 [safi],
10921 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
10922 json_object_boolean_true_add(
10923 json_sub,
10924 "rxAdvertisedAndReceived");
10925 else if (
10926 CHECK_FLAG(
10927 p->af_cap
10928 [afi]
10929 [safi],
10930 PEER_CAP_ADDPATH_AF_RX_ADV))
10931 json_object_boolean_true_add(
10932 json_sub,
10933 "rxAdvertised");
10934 else if (
10935 CHECK_FLAG(
10936 p->af_cap
10937 [afi]
10938 [safi],
10939 PEER_CAP_ADDPATH_AF_RX_RCV))
10940 json_object_boolean_true_add(
10941 json_sub,
10942 "rxReceived");
d62a17ae 10943 }
10944
05c7a1cc
QY
10945 if (CHECK_FLAG(
10946 p->af_cap[afi]
10947 [safi],
10948 PEER_CAP_ADDPATH_AF_TX_ADV)
10949 || CHECK_FLAG(
10950 p->af_cap[afi]
10951 [safi],
10952 PEER_CAP_ADDPATH_AF_TX_RCV)
10953 || CHECK_FLAG(
10954 p->af_cap[afi]
10955 [safi],
10956 PEER_CAP_ADDPATH_AF_RX_ADV)
10957 || CHECK_FLAG(
10958 p->af_cap[afi]
10959 [safi],
10960 PEER_CAP_ADDPATH_AF_RX_RCV))
10961 json_object_object_add(
10962 json_add,
10963 print_store,
10964 json_sub);
10965 else
10966 json_object_free(
10967 json_sub);
10968 }
10969
d62a17ae 10970 json_object_object_add(
10971 json_cap, "addPath", json_add);
10972 }
10973
10974 /* Dynamic */
10975 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10976 || CHECK_FLAG(p->cap,
10977 PEER_CAP_DYNAMIC_ADV)) {
10978 if (CHECK_FLAG(p->cap,
10979 PEER_CAP_DYNAMIC_ADV)
10980 && CHECK_FLAG(p->cap,
10981 PEER_CAP_DYNAMIC_RCV))
10982 json_object_string_add(
10983 json_cap, "dynamic",
10984 "advertisedAndReceived");
10985 else if (CHECK_FLAG(
10986 p->cap,
10987 PEER_CAP_DYNAMIC_ADV))
10988 json_object_string_add(
10989 json_cap, "dynamic",
10990 "advertised");
10991 else if (CHECK_FLAG(
10992 p->cap,
10993 PEER_CAP_DYNAMIC_RCV))
10994 json_object_string_add(
10995 json_cap, "dynamic",
10996 "received");
10997 }
10998
10999 /* Extended nexthop */
11000 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11001 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11002 json_object *json_nxt = NULL;
11003 const char *print_store;
11004
11005
11006 if (CHECK_FLAG(p->cap,
11007 PEER_CAP_ENHE_ADV)
11008 && CHECK_FLAG(p->cap,
11009 PEER_CAP_ENHE_RCV))
11010 json_object_string_add(
11011 json_cap,
11012 "extendedNexthop",
11013 "advertisedAndReceived");
11014 else if (CHECK_FLAG(p->cap,
11015 PEER_CAP_ENHE_ADV))
11016 json_object_string_add(
11017 json_cap,
11018 "extendedNexthop",
11019 "advertised");
11020 else if (CHECK_FLAG(p->cap,
11021 PEER_CAP_ENHE_RCV))
11022 json_object_string_add(
11023 json_cap,
11024 "extendedNexthop",
11025 "received");
11026
11027 if (CHECK_FLAG(p->cap,
11028 PEER_CAP_ENHE_RCV)) {
11029 json_nxt =
11030 json_object_new_object();
11031
11032 for (safi = SAFI_UNICAST;
11033 safi < SAFI_MAX; safi++) {
11034 if (CHECK_FLAG(
11035 p->af_cap
11036 [AFI_IP]
11037 [safi],
11038 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11039 print_store = get_afi_safi_str(
d62a17ae 11040 AFI_IP,
5cb5f4d0 11041 safi, true);
d62a17ae 11042 json_object_string_add(
11043 json_nxt,
11044 print_store,
54f29523 11045 "recieved"); /* misspelled for compatibility */
d62a17ae 11046 }
11047 }
11048 json_object_object_add(
11049 json_cap,
11050 "extendedNexthopFamililesByPeer",
11051 json_nxt);
11052 }
11053 }
11054
11055 /* Route Refresh */
11056 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11057 || CHECK_FLAG(p->cap,
11058 PEER_CAP_REFRESH_NEW_RCV)
11059 || CHECK_FLAG(p->cap,
11060 PEER_CAP_REFRESH_OLD_RCV)) {
11061 if (CHECK_FLAG(p->cap,
11062 PEER_CAP_REFRESH_ADV)
11063 && (CHECK_FLAG(
11064 p->cap,
11065 PEER_CAP_REFRESH_NEW_RCV)
11066 || CHECK_FLAG(
11067 p->cap,
11068 PEER_CAP_REFRESH_OLD_RCV))) {
11069 if (CHECK_FLAG(
11070 p->cap,
11071 PEER_CAP_REFRESH_OLD_RCV)
11072 && CHECK_FLAG(
11073 p->cap,
11074 PEER_CAP_REFRESH_NEW_RCV))
11075 json_object_string_add(
11076 json_cap,
11077 "routeRefresh",
11078 "advertisedAndReceivedOldNew");
11079 else {
11080 if (CHECK_FLAG(
11081 p->cap,
11082 PEER_CAP_REFRESH_OLD_RCV))
11083 json_object_string_add(
11084 json_cap,
11085 "routeRefresh",
11086 "advertisedAndReceivedOld");
11087 else
11088 json_object_string_add(
11089 json_cap,
11090 "routeRefresh",
11091 "advertisedAndReceivedNew");
11092 }
11093 } else if (
11094 CHECK_FLAG(
11095 p->cap,
11096 PEER_CAP_REFRESH_ADV))
11097 json_object_string_add(
11098 json_cap,
11099 "routeRefresh",
11100 "advertised");
11101 else if (
11102 CHECK_FLAG(
11103 p->cap,
11104 PEER_CAP_REFRESH_NEW_RCV)
11105 || CHECK_FLAG(
11106 p->cap,
11107 PEER_CAP_REFRESH_OLD_RCV))
11108 json_object_string_add(
11109 json_cap,
11110 "routeRefresh",
11111 "received");
11112 }
11113
11114 /* Multiprotocol Extensions */
11115 json_object *json_multi = NULL;
11116 json_multi = json_object_new_object();
11117
05c7a1cc
QY
11118 FOREACH_AFI_SAFI (afi, safi) {
11119 if (p->afc_adv[afi][safi]
11120 || p->afc_recv[afi][safi]) {
11121 json_object *json_exten = NULL;
11122 json_exten =
11123 json_object_new_object();
11124
d62a17ae 11125 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11126 && p->afc_recv[afi][safi])
11127 json_object_boolean_true_add(
11128 json_exten,
11129 "advertisedAndReceived");
11130 else if (p->afc_adv[afi][safi])
11131 json_object_boolean_true_add(
11132 json_exten,
11133 "advertised");
11134 else if (p->afc_recv[afi][safi])
11135 json_object_boolean_true_add(
11136 json_exten,
11137 "received");
d62a17ae 11138
05c7a1cc
QY
11139 json_object_object_add(
11140 json_multi,
5cb5f4d0
DD
11141 get_afi_safi_str(afi,
11142 safi,
11143 true),
05c7a1cc 11144 json_exten);
d62a17ae 11145 }
11146 }
11147 json_object_object_add(
11148 json_cap, "multiprotocolExtensions",
11149 json_multi);
11150
d77114b7 11151 /* Hostname capabilities */
60466a63 11152 json_object *json_hname = NULL;
d77114b7
MK
11153
11154 json_hname = json_object_new_object();
11155
11156 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11157 json_object_string_add(
60466a63
QY
11158 json_hname, "advHostName",
11159 bgp->peer_self->hostname
11160 ? bgp->peer_self
11161 ->hostname
d77114b7
MK
11162 : "n/a");
11163 json_object_string_add(
60466a63
QY
11164 json_hname, "advDomainName",
11165 bgp->peer_self->domainname
11166 ? bgp->peer_self
11167 ->domainname
d77114b7
MK
11168 : "n/a");
11169 }
11170
11171
11172 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11173 json_object_string_add(
60466a63
QY
11174 json_hname, "rcvHostName",
11175 p->hostname ? p->hostname
11176 : "n/a");
d77114b7 11177 json_object_string_add(
60466a63
QY
11178 json_hname, "rcvDomainName",
11179 p->domainname ? p->domainname
11180 : "n/a");
d77114b7
MK
11181 }
11182
60466a63 11183 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11184 json_hname);
11185
d62a17ae 11186 /* Gracefull Restart */
11187 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11188 || CHECK_FLAG(p->cap,
11189 PEER_CAP_RESTART_ADV)) {
11190 if (CHECK_FLAG(p->cap,
11191 PEER_CAP_RESTART_ADV)
11192 && CHECK_FLAG(p->cap,
11193 PEER_CAP_RESTART_RCV))
11194 json_object_string_add(
11195 json_cap,
11196 "gracefulRestart",
11197 "advertisedAndReceived");
11198 else if (CHECK_FLAG(
11199 p->cap,
11200 PEER_CAP_RESTART_ADV))
11201 json_object_string_add(
11202 json_cap,
11203 "gracefulRestartCapability",
11204 "advertised");
11205 else if (CHECK_FLAG(
11206 p->cap,
11207 PEER_CAP_RESTART_RCV))
11208 json_object_string_add(
11209 json_cap,
11210 "gracefulRestartCapability",
11211 "received");
11212
11213 if (CHECK_FLAG(p->cap,
11214 PEER_CAP_RESTART_RCV)) {
11215 int restart_af_count = 0;
11216 json_object *json_restart =
11217 NULL;
11218 json_restart =
11219 json_object_new_object();
11220
11221 json_object_int_add(
11222 json_cap,
11223 "gracefulRestartRemoteTimerMsecs",
11224 p->v_gr_restart * 1000);
11225
05c7a1cc
QY
11226 FOREACH_AFI_SAFI (afi, safi) {
11227 if (CHECK_FLAG(
11228 p->af_cap
11229 [afi]
11230 [safi],
11231 PEER_CAP_RESTART_AF_RCV)) {
11232 json_object *
11233 json_sub =
11234 NULL;
11235 json_sub =
11236 json_object_new_object();
11237
d62a17ae 11238 if (CHECK_FLAG(
11239 p->af_cap
11240 [afi]
11241 [safi],
05c7a1cc
QY
11242 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11243 json_object_boolean_true_add(
11244 json_sub,
11245 "preserved");
11246 restart_af_count++;
11247 json_object_object_add(
11248 json_restart,
5cb5f4d0 11249 get_afi_safi_str(
05c7a1cc 11250 afi,
5cb5f4d0
DD
11251 safi,
11252 true),
05c7a1cc 11253 json_sub);
d62a17ae 11254 }
11255 }
11256 if (!restart_af_count) {
11257 json_object_string_add(
11258 json_cap,
11259 "addressFamiliesByPeer",
11260 "none");
11261 json_object_free(
11262 json_restart);
11263 } else
11264 json_object_object_add(
11265 json_cap,
11266 "addressFamiliesByPeer",
11267 json_restart);
11268 }
11269 }
11270 json_object_object_add(json_neigh,
11271 "neighborCapabilities",
11272 json_cap);
11273 } else {
11274 vty_out(vty, " Neighbor capabilities:\n");
11275
11276 /* AS4 */
11277 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11278 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11279 vty_out(vty, " 4 Byte AS:");
11280 if (CHECK_FLAG(p->cap,
11281 PEER_CAP_AS4_ADV))
11282 vty_out(vty, " advertised");
11283 if (CHECK_FLAG(p->cap,
11284 PEER_CAP_AS4_RCV))
11285 vty_out(vty, " %sreceived",
11286 CHECK_FLAG(
11287 p->cap,
11288 PEER_CAP_AS4_ADV)
11289 ? "and "
11290 : "");
11291 vty_out(vty, "\n");
11292 }
11293
11294 /* AddPath */
11295 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11296 || CHECK_FLAG(p->cap,
11297 PEER_CAP_ADDPATH_ADV)) {
11298 vty_out(vty, " AddPath:\n");
11299
05c7a1cc
QY
11300 FOREACH_AFI_SAFI (afi, safi) {
11301 if (CHECK_FLAG(
11302 p->af_cap[afi]
11303 [safi],
11304 PEER_CAP_ADDPATH_AF_TX_ADV)
11305 || CHECK_FLAG(
11306 p->af_cap[afi]
11307 [safi],
11308 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11309 vty_out(vty,
11310 " %s: TX ",
5cb5f4d0 11311 get_afi_safi_str(
05c7a1cc 11312 afi,
5cb5f4d0
DD
11313 safi,
11314 false));
05c7a1cc 11315
d62a17ae 11316 if (CHECK_FLAG(
11317 p->af_cap
11318 [afi]
11319 [safi],
05c7a1cc 11320 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11321 vty_out(vty,
05c7a1cc 11322 "advertised %s",
5cb5f4d0 11323 get_afi_safi_str(
d62a17ae 11324 afi,
5cb5f4d0
DD
11325 safi,
11326 false));
d62a17ae 11327
05c7a1cc
QY
11328 if (CHECK_FLAG(
11329 p->af_cap
11330 [afi]
11331 [safi],
11332 PEER_CAP_ADDPATH_AF_TX_RCV))
11333 vty_out(vty,
11334 "%sreceived",
11335 CHECK_FLAG(
11336 p->af_cap
11337 [afi]
11338 [safi],
11339 PEER_CAP_ADDPATH_AF_TX_ADV)
11340 ? " and "
11341 : "");
d62a17ae 11342
05c7a1cc
QY
11343 vty_out(vty, "\n");
11344 }
d62a17ae 11345
05c7a1cc
QY
11346 if (CHECK_FLAG(
11347 p->af_cap[afi]
11348 [safi],
11349 PEER_CAP_ADDPATH_AF_RX_ADV)
11350 || CHECK_FLAG(
11351 p->af_cap[afi]
11352 [safi],
11353 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11354 vty_out(vty,
11355 " %s: RX ",
5cb5f4d0 11356 get_afi_safi_str(
05c7a1cc 11357 afi,
5cb5f4d0
DD
11358 safi,
11359 false));
d62a17ae 11360
11361 if (CHECK_FLAG(
11362 p->af_cap
11363 [afi]
11364 [safi],
05c7a1cc 11365 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11366 vty_out(vty,
05c7a1cc 11367 "advertised %s",
5cb5f4d0 11368 get_afi_safi_str(
d62a17ae 11369 afi,
5cb5f4d0
DD
11370 safi,
11371 false));
d62a17ae 11372
05c7a1cc
QY
11373 if (CHECK_FLAG(
11374 p->af_cap
11375 [afi]
11376 [safi],
11377 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11378 vty_out(vty,
05c7a1cc
QY
11379 "%sreceived",
11380 CHECK_FLAG(
11381 p->af_cap
11382 [afi]
11383 [safi],
11384 PEER_CAP_ADDPATH_AF_RX_ADV)
11385 ? " and "
11386 : "");
11387
11388 vty_out(vty, "\n");
d62a17ae 11389 }
05c7a1cc 11390 }
d62a17ae 11391 }
11392
11393 /* Dynamic */
11394 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11395 || CHECK_FLAG(p->cap,
11396 PEER_CAP_DYNAMIC_ADV)) {
11397 vty_out(vty, " Dynamic:");
11398 if (CHECK_FLAG(p->cap,
11399 PEER_CAP_DYNAMIC_ADV))
11400 vty_out(vty, " advertised");
11401 if (CHECK_FLAG(p->cap,
11402 PEER_CAP_DYNAMIC_RCV))
11403 vty_out(vty, " %sreceived",
11404 CHECK_FLAG(
11405 p->cap,
11406 PEER_CAP_DYNAMIC_ADV)
11407 ? "and "
11408 : "");
11409 vty_out(vty, "\n");
11410 }
11411
11412 /* Extended nexthop */
11413 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11414 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11415 vty_out(vty, " Extended nexthop:");
11416 if (CHECK_FLAG(p->cap,
11417 PEER_CAP_ENHE_ADV))
11418 vty_out(vty, " advertised");
11419 if (CHECK_FLAG(p->cap,
11420 PEER_CAP_ENHE_RCV))
11421 vty_out(vty, " %sreceived",
11422 CHECK_FLAG(
11423 p->cap,
11424 PEER_CAP_ENHE_ADV)
11425 ? "and "
11426 : "");
11427 vty_out(vty, "\n");
11428
11429 if (CHECK_FLAG(p->cap,
11430 PEER_CAP_ENHE_RCV)) {
11431 vty_out(vty,
11432 " Address families by peer:\n ");
11433 for (safi = SAFI_UNICAST;
11434 safi < SAFI_MAX; safi++)
11435 if (CHECK_FLAG(
11436 p->af_cap
11437 [AFI_IP]
11438 [safi],
11439 PEER_CAP_ENHE_AF_RCV))
11440 vty_out(vty,
11441 " %s\n",
5cb5f4d0 11442 get_afi_safi_str(
d62a17ae 11443 AFI_IP,
5cb5f4d0
DD
11444 safi,
11445 false));
d62a17ae 11446 }
11447 }
11448
11449 /* Route Refresh */
11450 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11451 || CHECK_FLAG(p->cap,
11452 PEER_CAP_REFRESH_NEW_RCV)
11453 || CHECK_FLAG(p->cap,
11454 PEER_CAP_REFRESH_OLD_RCV)) {
11455 vty_out(vty, " Route refresh:");
11456 if (CHECK_FLAG(p->cap,
11457 PEER_CAP_REFRESH_ADV))
11458 vty_out(vty, " advertised");
11459 if (CHECK_FLAG(p->cap,
11460 PEER_CAP_REFRESH_NEW_RCV)
11461 || CHECK_FLAG(
11462 p->cap,
11463 PEER_CAP_REFRESH_OLD_RCV))
11464 vty_out(vty, " %sreceived(%s)",
11465 CHECK_FLAG(
11466 p->cap,
11467 PEER_CAP_REFRESH_ADV)
11468 ? "and "
11469 : "",
11470 (CHECK_FLAG(
11471 p->cap,
11472 PEER_CAP_REFRESH_OLD_RCV)
11473 && CHECK_FLAG(
11474 p->cap,
11475 PEER_CAP_REFRESH_NEW_RCV))
11476 ? "old & new"
11477 : CHECK_FLAG(
11478 p->cap,
11479 PEER_CAP_REFRESH_OLD_RCV)
11480 ? "old"
11481 : "new");
11482
11483 vty_out(vty, "\n");
11484 }
11485
11486 /* Multiprotocol Extensions */
05c7a1cc
QY
11487 FOREACH_AFI_SAFI (afi, safi)
11488 if (p->afc_adv[afi][safi]
11489 || p->afc_recv[afi][safi]) {
11490 vty_out(vty,
11491 " Address Family %s:",
5cb5f4d0
DD
11492 get_afi_safi_str(
11493 afi,
11494 safi,
11495 false));
05c7a1cc 11496 if (p->afc_adv[afi][safi])
d62a17ae 11497 vty_out(vty,
05c7a1cc
QY
11498 " advertised");
11499 if (p->afc_recv[afi][safi])
11500 vty_out(vty,
11501 " %sreceived",
11502 p->afc_adv[afi]
11503 [safi]
11504 ? "and "
11505 : "");
11506 vty_out(vty, "\n");
11507 }
d62a17ae 11508
11509 /* Hostname capability */
60466a63 11510 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11511
11512 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11513 vty_out(vty,
11514 " advertised (name: %s,domain name: %s)",
60466a63
QY
11515 bgp->peer_self->hostname
11516 ? bgp->peer_self
11517 ->hostname
d77114b7 11518 : "n/a",
60466a63
QY
11519 bgp->peer_self->domainname
11520 ? bgp->peer_self
11521 ->domainname
d77114b7
MK
11522 : "n/a");
11523 } else {
11524 vty_out(vty, " not advertised");
d62a17ae 11525 }
11526
d77114b7 11527 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11528 vty_out(vty,
11529 " received (name: %s,domain name: %s)",
60466a63
QY
11530 p->hostname ? p->hostname
11531 : "n/a",
11532 p->domainname ? p->domainname
11533 : "n/a");
d77114b7
MK
11534 } else {
11535 vty_out(vty, " not received");
11536 }
11537
11538 vty_out(vty, "\n");
11539
d62a17ae 11540 /* Gracefull Restart */
11541 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11542 || CHECK_FLAG(p->cap,
11543 PEER_CAP_RESTART_ADV)) {
11544 vty_out(vty,
11545 " Graceful Restart Capabilty:");
11546 if (CHECK_FLAG(p->cap,
11547 PEER_CAP_RESTART_ADV))
11548 vty_out(vty, " advertised");
11549 if (CHECK_FLAG(p->cap,
11550 PEER_CAP_RESTART_RCV))
11551 vty_out(vty, " %sreceived",
11552 CHECK_FLAG(
11553 p->cap,
11554 PEER_CAP_RESTART_ADV)
11555 ? "and "
11556 : "");
11557 vty_out(vty, "\n");
11558
11559 if (CHECK_FLAG(p->cap,
11560 PEER_CAP_RESTART_RCV)) {
11561 int restart_af_count = 0;
11562
11563 vty_out(vty,
11564 " Remote Restart timer is %d seconds\n",
11565 p->v_gr_restart);
11566 vty_out(vty,
11567 " Address families by peer:\n ");
11568
05c7a1cc
QY
11569 FOREACH_AFI_SAFI (afi, safi)
11570 if (CHECK_FLAG(
11571 p->af_cap
11572 [afi]
11573 [safi],
11574 PEER_CAP_RESTART_AF_RCV)) {
11575 vty_out(vty,
11576 "%s%s(%s)",
11577 restart_af_count
11578 ? ", "
11579 : "",
5cb5f4d0 11580 get_afi_safi_str(
05c7a1cc 11581 afi,
5cb5f4d0
DD
11582 safi,
11583 false),
05c7a1cc
QY
11584 CHECK_FLAG(
11585 p->af_cap
11586 [afi]
11587 [safi],
11588 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11589 ? "preserved"
11590 : "not preserved");
11591 restart_af_count++;
11592 }
d62a17ae 11593 if (!restart_af_count)
11594 vty_out(vty, "none");
11595 vty_out(vty, "\n");
11596 }
2986cac2 11597 } /* Gracefull Restart */
d62a17ae 11598 }
11599 }
11600 }
11601
11602 /* graceful restart information */
d62a17ae 11603 json_object *json_grace = NULL;
11604 json_object *json_grace_send = NULL;
11605 json_object *json_grace_recv = NULL;
11606 int eor_send_af_count = 0;
11607 int eor_receive_af_count = 0;
11608
11609 if (use_json) {
11610 json_grace = json_object_new_object();
11611 json_grace_send = json_object_new_object();
11612 json_grace_recv = json_object_new_object();
11613
2986cac2 11614 if ((p->status == Established) &&
11615 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11616 FOREACH_AFI_SAFI (afi, safi) {
11617 if (CHECK_FLAG(p->af_sflags[afi][safi],
2986cac2 11618 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11619 json_object_boolean_true_add(
11620 json_grace_send,
5cb5f4d0
DD
11621 get_afi_safi_str(afi,
11622 safi,
11623 true));
05c7a1cc 11624 eor_send_af_count++;
d62a17ae 11625 }
11626 }
05c7a1cc
QY
11627 FOREACH_AFI_SAFI (afi, safi) {
11628 if (CHECK_FLAG(
2986cac2 11629 p->af_sflags[afi][safi],
11630 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11631 json_object_boolean_true_add(
11632 json_grace_recv,
5cb5f4d0
DD
11633 get_afi_safi_str(afi,
11634 safi,
11635 true));
05c7a1cc 11636 eor_receive_af_count++;
d62a17ae 11637 }
11638 }
11639 }
2986cac2 11640 json_object_object_add(json_grace,
11641 "endOfRibSend",
11642 json_grace_send);
11643 json_object_object_add(json_grace,
11644 "endOfRibRecv",
11645 json_grace_recv);
d62a17ae 11646
d62a17ae 11647
11648 if (p->t_gr_restart)
11649 json_object_int_add(json_grace,
11650 "gracefulRestartTimerMsecs",
11651 thread_timer_remain_second(
11652 p->t_gr_restart)
11653 * 1000);
11654
11655 if (p->t_gr_stale)
11656 json_object_int_add(
11657 json_grace,
11658 "gracefulStalepathTimerMsecs",
11659 thread_timer_remain_second(
11660 p->t_gr_stale)
11661 * 1000);
2986cac2 11662 /* more gr info in new format */
11663 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
11664 json_grace);
d62a17ae 11665 json_object_object_add(
11666 json_neigh, "gracefulRestartInfo", json_grace);
11667 } else {
2986cac2 11668 vty_out(vty, " Graceful restart informations:\n");
11669 if ((p->status == Established) &&
11670 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11671
d62a17ae 11672 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11673 FOREACH_AFI_SAFI (afi, safi) {
11674 if (CHECK_FLAG(p->af_sflags[afi][safi],
11675 PEER_STATUS_EOR_SEND)) {
11676 vty_out(vty, "%s%s",
11677 eor_send_af_count ? ", "
11678 : "",
5cb5f4d0 11679 get_afi_safi_str(afi,
2986cac2 11680 safi,
11681 false));
05c7a1cc 11682 eor_send_af_count++;
d62a17ae 11683 }
11684 }
11685 vty_out(vty, "\n");
11686 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
11687 FOREACH_AFI_SAFI (afi, safi) {
11688 if (CHECK_FLAG(
11689 p->af_sflags[afi][safi],
11690 PEER_STATUS_EOR_RECEIVED)) {
11691 vty_out(vty, "%s%s",
11692 eor_receive_af_count
11693 ? ", "
11694 : "",
5cb5f4d0
DD
11695 get_afi_safi_str(afi,
11696 safi,
11697 false));
05c7a1cc 11698 eor_receive_af_count++;
d62a17ae 11699 }
11700 }
11701 vty_out(vty, "\n");
11702 }
11703
11704 if (p->t_gr_restart)
11705 vty_out(vty,
11706 " The remaining time of restart timer is %ld\n",
11707 thread_timer_remain_second(
11708 p->t_gr_restart));
11709
11710 if (p->t_gr_stale)
11711 vty_out(vty,
11712 " The remaining time of stalepath timer is %ld\n",
11713 thread_timer_remain_second(
11714 p->t_gr_stale));
2986cac2 11715
11716 /* more gr info in new format */
11717 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 11718 }
2986cac2 11719
d62a17ae 11720 if (use_json) {
11721 json_object *json_stat = NULL;
11722 json_stat = json_object_new_object();
11723 /* Packet counts. */
11724 json_object_int_add(json_stat, "depthInq", 0);
11725 json_object_int_add(json_stat, "depthOutq",
11726 (unsigned long)p->obuf->count);
0112e9e0
QY
11727 json_object_int_add(json_stat, "opensSent",
11728 atomic_load_explicit(&p->open_out,
11729 memory_order_relaxed));
11730 json_object_int_add(json_stat, "opensRecv",
11731 atomic_load_explicit(&p->open_in,
11732 memory_order_relaxed));
d62a17ae 11733 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
11734 atomic_load_explicit(&p->notify_out,
11735 memory_order_relaxed));
d62a17ae 11736 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
11737 atomic_load_explicit(&p->notify_in,
11738 memory_order_relaxed));
11739 json_object_int_add(json_stat, "updatesSent",
11740 atomic_load_explicit(&p->update_out,
11741 memory_order_relaxed));
11742 json_object_int_add(json_stat, "updatesRecv",
11743 atomic_load_explicit(&p->update_in,
11744 memory_order_relaxed));
d62a17ae 11745 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
11746 atomic_load_explicit(&p->keepalive_out,
11747 memory_order_relaxed));
d62a17ae 11748 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
11749 atomic_load_explicit(&p->keepalive_in,
11750 memory_order_relaxed));
d62a17ae 11751 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
11752 atomic_load_explicit(&p->refresh_out,
11753 memory_order_relaxed));
d62a17ae 11754 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
11755 atomic_load_explicit(&p->refresh_in,
11756 memory_order_relaxed));
d62a17ae 11757 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
11758 atomic_load_explicit(&p->dynamic_cap_out,
11759 memory_order_relaxed));
d62a17ae 11760 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
11761 atomic_load_explicit(&p->dynamic_cap_in,
11762 memory_order_relaxed));
11763 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11764 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 11765 json_object_object_add(json_neigh, "messageStats", json_stat);
11766 } else {
11767 /* Packet counts. */
11768 vty_out(vty, " Message statistics:\n");
11769 vty_out(vty, " Inq depth is 0\n");
11770 vty_out(vty, " Outq depth is %lu\n",
11771 (unsigned long)p->obuf->count);
11772 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
11773 vty_out(vty, " Opens: %10d %10d\n",
11774 atomic_load_explicit(&p->open_out,
11775 memory_order_relaxed),
11776 atomic_load_explicit(&p->open_in,
11777 memory_order_relaxed));
11778 vty_out(vty, " Notifications: %10d %10d\n",
11779 atomic_load_explicit(&p->notify_out,
11780 memory_order_relaxed),
11781 atomic_load_explicit(&p->notify_in,
11782 memory_order_relaxed));
11783 vty_out(vty, " Updates: %10d %10d\n",
11784 atomic_load_explicit(&p->update_out,
11785 memory_order_relaxed),
11786 atomic_load_explicit(&p->update_in,
11787 memory_order_relaxed));
11788 vty_out(vty, " Keepalives: %10d %10d\n",
11789 atomic_load_explicit(&p->keepalive_out,
11790 memory_order_relaxed),
11791 atomic_load_explicit(&p->keepalive_in,
11792 memory_order_relaxed));
11793 vty_out(vty, " Route Refresh: %10d %10d\n",
11794 atomic_load_explicit(&p->refresh_out,
11795 memory_order_relaxed),
11796 atomic_load_explicit(&p->refresh_in,
11797 memory_order_relaxed));
d62a17ae 11798 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
11799 atomic_load_explicit(&p->dynamic_cap_out,
11800 memory_order_relaxed),
11801 atomic_load_explicit(&p->dynamic_cap_in,
11802 memory_order_relaxed));
11803 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11804 PEER_TOTAL_RX(p));
d62a17ae 11805 }
11806
11807 if (use_json) {
11808 /* advertisement-interval */
11809 json_object_int_add(json_neigh,
11810 "minBtwnAdvertisementRunsTimerMsecs",
11811 p->v_routeadv * 1000);
11812
11813 /* Update-source. */
11814 if (p->update_if || p->update_source) {
11815 if (p->update_if)
11816 json_object_string_add(json_neigh,
11817 "updateSource",
11818 p->update_if);
11819 else if (p->update_source)
11820 json_object_string_add(
11821 json_neigh, "updateSource",
11822 sockunion2str(p->update_source, buf1,
11823 SU_ADDRSTRLEN));
11824 }
11825 } else {
11826 /* advertisement-interval */
11827 vty_out(vty,
11828 " Minimum time between advertisement runs is %d seconds\n",
11829 p->v_routeadv);
11830
11831 /* Update-source. */
11832 if (p->update_if || p->update_source) {
11833 vty_out(vty, " Update source is ");
11834 if (p->update_if)
11835 vty_out(vty, "%s", p->update_if);
11836 else if (p->update_source)
11837 vty_out(vty, "%s",
11838 sockunion2str(p->update_source, buf1,
11839 SU_ADDRSTRLEN));
11840 vty_out(vty, "\n");
11841 }
11842
11843 vty_out(vty, "\n");
11844 }
11845
11846 /* Address Family Information */
11847 json_object *json_hold = NULL;
11848
11849 if (use_json)
11850 json_hold = json_object_new_object();
11851
05c7a1cc
QY
11852 FOREACH_AFI_SAFI (afi, safi)
11853 if (p->afc[afi][safi])
11854 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11855 json_hold);
d62a17ae 11856
11857 if (use_json) {
11858 json_object_object_add(json_neigh, "addressFamilyInfo",
11859 json_hold);
11860 json_object_int_add(json_neigh, "connectionsEstablished",
11861 p->established);
11862 json_object_int_add(json_neigh, "connectionsDropped",
11863 p->dropped);
11864 } else
11865 vty_out(vty, " Connections established %d; dropped %d\n",
11866 p->established, p->dropped);
11867
11868 if (!p->last_reset) {
11869 if (use_json)
11870 json_object_string_add(json_neigh, "lastReset",
11871 "never");
11872 else
11873 vty_out(vty, " Last reset never\n");
11874 } else {
11875 if (use_json) {
11876 time_t uptime;
11877 struct tm *tm;
11878
11879 uptime = bgp_clock();
11880 uptime -= p->resettime;
11881 tm = gmtime(&uptime);
11882 json_object_int_add(json_neigh, "lastResetTimerMsecs",
11883 (tm->tm_sec * 1000)
11884 + (tm->tm_min * 60000)
11885 + (tm->tm_hour * 3600000));
3577f1c5 11886 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 11887 } else {
11888 vty_out(vty, " Last reset %s, ",
11889 peer_uptime(p->resettime, timebuf,
11890 BGP_UPTIME_LEN, 0, NULL));
11891
3577f1c5 11892 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 11893 if (p->last_reset_cause_size) {
11894 msg = p->last_reset_cause;
11895 vty_out(vty,
11896 " Message received that caused BGP to send a NOTIFICATION:\n ");
11897 for (i = 1; i <= p->last_reset_cause_size;
11898 i++) {
11899 vty_out(vty, "%02X", *msg++);
11900
11901 if (i != p->last_reset_cause_size) {
11902 if (i % 16 == 0) {
11903 vty_out(vty, "\n ");
11904 } else if (i % 4 == 0) {
11905 vty_out(vty, " ");
11906 }
11907 }
11908 }
11909 vty_out(vty, "\n");
11910 }
11911 }
11912 }
11913
11914 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11915 if (use_json)
11916 json_object_boolean_true_add(json_neigh,
11917 "prefixesConfigExceedMax");
11918 else
11919 vty_out(vty,
11920 " Peer had exceeded the max. no. of prefixes configured.\n");
11921
11922 if (p->t_pmax_restart) {
11923 if (use_json) {
11924 json_object_boolean_true_add(
11925 json_neigh, "reducePrefixNumFrom");
11926 json_object_int_add(json_neigh,
11927 "restartInTimerMsec",
11928 thread_timer_remain_second(
11929 p->t_pmax_restart)
11930 * 1000);
11931 } else
11932 vty_out(vty,
11933 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
11934 p->host, thread_timer_remain_second(
11935 p->t_pmax_restart));
d62a17ae 11936 } else {
11937 if (use_json)
11938 json_object_boolean_true_add(
11939 json_neigh,
11940 "reducePrefixNumAndClearIpBgp");
11941 else
11942 vty_out(vty,
11943 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
11944 p->host);
11945 }
11946 }
11947
11948 /* EBGP Multihop and GTSM */
11949 if (p->sort != BGP_PEER_IBGP) {
11950 if (use_json) {
11951 if (p->gtsm_hops > 0)
11952 json_object_int_add(json_neigh,
11953 "externalBgpNbrMaxHopsAway",
11954 p->gtsm_hops);
c8d6f0d6 11955 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11956 json_object_int_add(json_neigh,
11957 "externalBgpNbrMaxHopsAway",
11958 p->ttl);
11959 } else {
11960 if (p->gtsm_hops > 0)
11961 vty_out(vty,
11962 " External BGP neighbor may be up to %d hops away.\n",
11963 p->gtsm_hops);
c8d6f0d6 11964 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11965 vty_out(vty,
11966 " External BGP neighbor may be up to %d hops away.\n",
11967 p->ttl);
11968 }
11969 } else {
11970 if (p->gtsm_hops > 0) {
11971 if (use_json)
11972 json_object_int_add(json_neigh,
11973 "internalBgpNbrMaxHopsAway",
11974 p->gtsm_hops);
11975 else
11976 vty_out(vty,
11977 " Internal BGP neighbor may be up to %d hops away.\n",
11978 p->gtsm_hops);
11979 }
11980 }
11981
11982 /* Local address. */
11983 if (p->su_local) {
11984 if (use_json) {
11985 json_object_string_add(json_neigh, "hostLocal",
11986 sockunion2str(p->su_local, buf1,
11987 SU_ADDRSTRLEN));
11988 json_object_int_add(json_neigh, "portLocal",
11989 ntohs(p->su_local->sin.sin_port));
11990 } else
11991 vty_out(vty, "Local host: %s, Local port: %d\n",
11992 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
11993 ntohs(p->su_local->sin.sin_port));
11994 }
11995
11996 /* Remote address. */
11997 if (p->su_remote) {
11998 if (use_json) {
11999 json_object_string_add(json_neigh, "hostForeign",
12000 sockunion2str(p->su_remote, buf1,
12001 SU_ADDRSTRLEN));
12002 json_object_int_add(json_neigh, "portForeign",
12003 ntohs(p->su_remote->sin.sin_port));
12004 } else
12005 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12006 sockunion2str(p->su_remote, buf1,
12007 SU_ADDRSTRLEN),
12008 ntohs(p->su_remote->sin.sin_port));
12009 }
12010
12011 /* Nexthop display. */
12012 if (p->su_local) {
12013 if (use_json) {
12014 json_object_string_add(json_neigh, "nexthop",
12015 inet_ntop(AF_INET,
12016 &p->nexthop.v4, buf1,
12017 sizeof(buf1)));
12018 json_object_string_add(json_neigh, "nexthopGlobal",
12019 inet_ntop(AF_INET6,
12020 &p->nexthop.v6_global,
12021 buf1, sizeof(buf1)));
12022 json_object_string_add(json_neigh, "nexthopLocal",
12023 inet_ntop(AF_INET6,
12024 &p->nexthop.v6_local,
12025 buf1, sizeof(buf1)));
12026 if (p->shared_network)
12027 json_object_string_add(json_neigh,
12028 "bgpConnection",
12029 "sharedNetwork");
12030 else
12031 json_object_string_add(json_neigh,
12032 "bgpConnection",
12033 "nonSharedNetwork");
12034 } else {
12035 vty_out(vty, "Nexthop: %s\n",
12036 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12037 sizeof(buf1)));
12038 vty_out(vty, "Nexthop global: %s\n",
12039 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12040 sizeof(buf1)));
12041 vty_out(vty, "Nexthop local: %s\n",
12042 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12043 sizeof(buf1)));
12044 vty_out(vty, "BGP connection: %s\n",
12045 p->shared_network ? "shared network"
12046 : "non shared network");
12047 }
12048 }
12049
12050 /* Timer information. */
12051 if (use_json) {
12052 json_object_int_add(json_neigh, "connectRetryTimer",
12053 p->v_connect);
12054 if (p->status == Established && p->rtt)
12055 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12056 p->rtt);
12057 if (p->t_start)
12058 json_object_int_add(
12059 json_neigh, "nextStartTimerDueInMsecs",
12060 thread_timer_remain_second(p->t_start) * 1000);
12061 if (p->t_connect)
12062 json_object_int_add(
12063 json_neigh, "nextConnectTimerDueInMsecs",
12064 thread_timer_remain_second(p->t_connect)
12065 * 1000);
12066 if (p->t_routeadv) {
12067 json_object_int_add(json_neigh, "mraiInterval",
12068 p->v_routeadv);
12069 json_object_int_add(
12070 json_neigh, "mraiTimerExpireInMsecs",
12071 thread_timer_remain_second(p->t_routeadv)
12072 * 1000);
12073 }
12074 if (p->password)
12075 json_object_int_add(json_neigh, "authenticationEnabled",
12076 1);
12077
12078 if (p->t_read)
12079 json_object_string_add(json_neigh, "readThread", "on");
12080 else
12081 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12082
12083 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12084 json_object_string_add(json_neigh, "writeThread", "on");
12085 else
12086 json_object_string_add(json_neigh, "writeThread",
12087 "off");
12088 } else {
12089 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12090 p->v_connect);
12091 if (p->status == Established && p->rtt)
12092 vty_out(vty, "Estimated round trip time: %d ms\n",
12093 p->rtt);
12094 if (p->t_start)
12095 vty_out(vty, "Next start timer due in %ld seconds\n",
12096 thread_timer_remain_second(p->t_start));
12097 if (p->t_connect)
12098 vty_out(vty, "Next connect timer due in %ld seconds\n",
12099 thread_timer_remain_second(p->t_connect));
12100 if (p->t_routeadv)
12101 vty_out(vty,
12102 "MRAI (interval %u) timer expires in %ld seconds\n",
12103 p->v_routeadv,
12104 thread_timer_remain_second(p->t_routeadv));
12105 if (p->password)
12106 vty_out(vty, "Peer Authentication Enabled\n");
12107
cac9e917 12108 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12109 p->t_read ? "on" : "off",
12110 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12111 ? "on"
cac9e917 12112 : "off", p->fd);
d62a17ae 12113 }
12114
12115 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12116 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12117 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12118
12119 if (!use_json)
12120 vty_out(vty, "\n");
12121
12122 /* BFD information. */
12123 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12124
12125 if (use_json) {
12126 if (p->conf_if) /* Configured interface name. */
12127 json_object_object_add(json, p->conf_if, json_neigh);
12128 else /* Configured IP address. */
12129 json_object_object_add(json, p->host, json_neigh);
12130 }
12131}
12132
2986cac2 12133static int bgp_show_neighbor_graceful_restart(struct vty *vty,
12134 struct bgp *bgp,
12135 enum show_type type,
12136 union sockunion *su,
12137 const char *conf_if, afi_t afi,
12138 bool use_json, json_object *json)
12139{
12140 struct listnode *node, *nnode;
12141 struct peer *peer;
12142 int find = 0;
12143 safi_t safi = SAFI_UNICAST;
12144 json_object *json_neighbor = NULL;
12145
12146 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12147
12148 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12149 continue;
12150
12151 if ((peer->afc[afi][safi]) == 0)
12152 continue;
12153
12154 if (use_json)
12155 json_neighbor = json_object_new_object();
12156
2ba1fe69 12157 if (type == show_all) {
2986cac2 12158 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12159 json_neighbor);
2986cac2 12160
12161 if (use_json)
13909c4f
DS
12162 json_object_object_add(json, peer->host,
12163 json_neighbor);
2986cac2 12164
2ba1fe69 12165 } else if (type == show_peer) {
2986cac2 12166 if (conf_if) {
12167 if ((peer->conf_if
13909c4f
DS
12168 && !strcmp(peer->conf_if, conf_if))
12169 || (peer->hostname
2986cac2 12170 && !strcmp(peer->hostname, conf_if))) {
12171 find = 1;
13909c4f
DS
12172 bgp_show_peer_gr_status(vty, peer,
12173 use_json,
12174 json_neighbor);
2986cac2 12175 }
12176 } else {
12177 if (sockunion_same(&peer->su, su)) {
12178 find = 1;
13909c4f
DS
12179 bgp_show_peer_gr_status(vty, peer,
12180 use_json,
12181 json_neighbor);
2986cac2 12182 }
12183 }
13909c4f
DS
12184 if (use_json && find)
12185 json_object_object_add(json, peer->host,
12186 json_neighbor);
2986cac2 12187 }
12188
12189 if (find)
12190 break;
12191 }
12192
12193 if (type == show_peer && !find) {
12194 if (use_json)
13909c4f 12195 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12196 else
12197 vty_out(vty, "%% No such neighbor\n");
12198 }
12199 if (use_json) {
13909c4f
DS
12200 vty_out(vty, "%s\n",
12201 json_object_to_json_string_ext(
12202 json, JSON_C_TO_STRING_PRETTY));
2986cac2 12203 } else {
12204 vty_out(vty, "\n");
12205 }
12206
12207 return CMD_SUCCESS;
12208}
12209
d62a17ae 12210static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12211 enum show_type type, union sockunion *su,
9f049418 12212 const char *conf_if, bool use_json,
d62a17ae 12213 json_object *json)
12214{
12215 struct listnode *node, *nnode;
12216 struct peer *peer;
12217 int find = 0;
9f049418 12218 bool nbr_output = false;
d1927ebe
AS
12219 afi_t afi = AFI_MAX;
12220 safi_t safi = SAFI_MAX;
12221
12222 if (type == show_ipv4_peer || type == show_ipv4_all) {
12223 afi = AFI_IP;
12224 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12225 afi = AFI_IP6;
12226 }
d62a17ae 12227
12228 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12229 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12230 continue;
12231
12232 switch (type) {
12233 case show_all:
12234 bgp_show_peer(vty, peer, use_json, json);
9f049418 12235 nbr_output = true;
d62a17ae 12236 break;
12237 case show_peer:
12238 if (conf_if) {
12239 if ((peer->conf_if
12240 && !strcmp(peer->conf_if, conf_if))
12241 || (peer->hostname
12242 && !strcmp(peer->hostname, conf_if))) {
12243 find = 1;
12244 bgp_show_peer(vty, peer, use_json,
12245 json);
12246 }
12247 } else {
12248 if (sockunion_same(&peer->su, su)) {
12249 find = 1;
12250 bgp_show_peer(vty, peer, use_json,
12251 json);
12252 }
12253 }
12254 break;
d1927ebe
AS
12255 case show_ipv4_peer:
12256 case show_ipv6_peer:
12257 FOREACH_SAFI (safi) {
12258 if (peer->afc[afi][safi]) {
12259 if (conf_if) {
12260 if ((peer->conf_if
12261 && !strcmp(peer->conf_if, conf_if))
12262 || (peer->hostname
12263 && !strcmp(peer->hostname, conf_if))) {
12264 find = 1;
12265 bgp_show_peer(vty, peer, use_json,
12266 json);
12267 break;
12268 }
12269 } else {
12270 if (sockunion_same(&peer->su, su)) {
12271 find = 1;
12272 bgp_show_peer(vty, peer, use_json,
12273 json);
12274 break;
12275 }
12276 }
12277 }
12278 }
12279 break;
12280 case show_ipv4_all:
12281 case show_ipv6_all:
12282 FOREACH_SAFI (safi) {
12283 if (peer->afc[afi][safi]) {
12284 bgp_show_peer(vty, peer, use_json, json);
12285 nbr_output = true;
12286 break;
12287 }
12288 }
12289 break;
d62a17ae 12290 }
12291 }
12292
d1927ebe
AS
12293 if ((type == show_peer || type == show_ipv4_peer ||
12294 type == show_ipv6_peer) && !find) {
d62a17ae 12295 if (use_json)
12296 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12297 else
88b7d255 12298 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12299 }
12300
d1927ebe
AS
12301 if (type != show_peer && type != show_ipv4_peer &&
12302 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12303 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12304
d62a17ae 12305 if (use_json) {
996c9314
LB
12306 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12307 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12308 } else {
12309 vty_out(vty, "\n");
12310 }
12311
12312 return CMD_SUCCESS;
12313}
12314
2986cac2 12315static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12316 enum show_type type, const char *ip_str,
12317 afi_t afi, bool use_json)
12318{
12319
12320 int ret;
12321 struct bgp *bgp;
12322 union sockunion su;
12323 json_object *json = NULL;
12324
12325 bgp = bgp_get_default();
12326
13909c4f
DS
12327 if (!bgp)
12328 return;
2986cac2 12329
13909c4f
DS
12330 if (!use_json)
12331 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12332 NULL);
2986cac2 12333
13909c4f
DS
12334 json = json_object_new_object();
12335 if (ip_str) {
12336 ret = str2sockunion(ip_str, &su);
12337 if (ret < 0)
12338 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
12339 ip_str, afi,
12340 use_json, json);
12341 else
12342 bgp_show_neighbor_graceful_restart(
12343 vty, bgp, type, &su, NULL, afi, use_json, json);
12344 } else
12345 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12346 afi, use_json, json);
12347 json_object_free(json);
2986cac2 12348}
12349
d62a17ae 12350static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12351 enum show_type type,
12352 const char *ip_str,
9f049418 12353 bool use_json)
d62a17ae 12354{
0291c246
MK
12355 struct listnode *node, *nnode;
12356 struct bgp *bgp;
71aedaa3 12357 union sockunion su;
0291c246 12358 json_object *json = NULL;
71aedaa3 12359 int ret, is_first = 1;
9f049418 12360 bool nbr_output = false;
d62a17ae 12361
12362 if (use_json)
12363 vty_out(vty, "{\n");
12364
12365 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12366 nbr_output = true;
d62a17ae 12367 if (use_json) {
12368 if (!(json = json_object_new_object())) {
af4c2728 12369 flog_err(
e50f7cfd 12370 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12371 "Unable to allocate memory for JSON object");
12372 vty_out(vty,
12373 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12374 return;
12375 }
12376
12377 json_object_int_add(json, "vrfId",
12378 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12379 ? -1
12380 : (int64_t)bgp->vrf_id);
d62a17ae 12381 json_object_string_add(
12382 json, "vrfName",
12383 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12384 ? VRF_DEFAULT_NAME
d62a17ae 12385 : bgp->name);
12386
12387 if (!is_first)
12388 vty_out(vty, ",\n");
12389 else
12390 is_first = 0;
12391
12392 vty_out(vty, "\"%s\":",
12393 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12394 ? VRF_DEFAULT_NAME
d62a17ae 12395 : bgp->name);
12396 } else {
12397 vty_out(vty, "\nInstance %s:\n",
12398 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12399 ? VRF_DEFAULT_NAME
d62a17ae 12400 : bgp->name);
12401 }
71aedaa3 12402
d1927ebe
AS
12403 if (type == show_peer || type == show_ipv4_peer ||
12404 type == show_ipv6_peer) {
71aedaa3
DS
12405 ret = str2sockunion(ip_str, &su);
12406 if (ret < 0)
12407 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12408 use_json, json);
12409 else
12410 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12411 use_json, json);
12412 } else {
d1927ebe 12413 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12414 use_json, json);
12415 }
b77004d6 12416 json_object_free(json);
d62a17ae 12417 }
12418
01cbfd04 12419 if (use_json) {
d62a17ae 12420 vty_out(vty, "}\n");
01cbfd04
QY
12421 json_object_free(json);
12422 }
9f049418
DS
12423 else if (!nbr_output)
12424 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12425}
12426
12427static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12428 enum show_type type, const char *ip_str,
9f049418 12429 bool use_json)
d62a17ae 12430{
12431 int ret;
12432 struct bgp *bgp;
12433 union sockunion su;
12434 json_object *json = NULL;
12435
12436 if (name) {
12437 if (strmatch(name, "all")) {
71aedaa3
DS
12438 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12439 use_json);
d62a17ae 12440 return CMD_SUCCESS;
12441 } else {
12442 bgp = bgp_lookup_by_name(name);
12443 if (!bgp) {
12444 if (use_json) {
12445 json = json_object_new_object();
d62a17ae 12446 vty_out(vty, "%s\n",
12447 json_object_to_json_string_ext(
12448 json,
12449 JSON_C_TO_STRING_PRETTY));
12450 json_object_free(json);
12451 } else
12452 vty_out(vty,
9f049418 12453 "%% BGP instance not found\n");
d62a17ae 12454
12455 return CMD_WARNING;
12456 }
12457 }
12458 } else {
12459 bgp = bgp_get_default();
12460 }
12461
12462 if (bgp) {
12463 json = json_object_new_object();
12464 if (ip_str) {
12465 ret = str2sockunion(ip_str, &su);
12466 if (ret < 0)
12467 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12468 use_json, json);
12469 else
12470 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12471 use_json, json);
12472 } else {
12473 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12474 json);
12475 }
12476 json_object_free(json);
ca61fd25
DS
12477 } else {
12478 if (use_json)
12479 vty_out(vty, "{}\n");
12480 else
12481 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12482 }
12483
12484 return CMD_SUCCESS;
4fb25c53
DW
12485}
12486
2986cac2 12487
12488
12489/* "show [ip] bgp neighbors graceful-restart" commands. */
12490DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12491 show_ip_bgp_neighbors_graceful_restart_cmd,
12492 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12493 SHOW_STR
12494 BGP_STR
12495 IP_STR
12496 IPV6_STR
12497 NEIGHBOR_STR
12498 "Neighbor to display information about\n"
12499 "Neighbor to display information about\n"
12500 "Neighbor on BGP configured interface\n"
12501 GR_SHOW
12502 JSON_STR)
12503{
12504 char *sh_arg = NULL;
12505 enum show_type sh_type;
12506 int idx = 0;
12507 afi_t afi = AFI_MAX;
2986cac2 12508 bool uj = use_json(argc, argv);
12509
12510 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
12511 afi = AFI_MAX;
12512
12513 idx++;
12514
12515 if (argv_find(argv, argc, "A.B.C.D", &idx)
12516 || argv_find(argv, argc, "X:X::X:X", &idx)
12517 || argv_find(argv, argc, "WORD", &idx)) {
12518 sh_type = show_peer;
12519 sh_arg = argv[idx]->arg;
12520 } else
12521 sh_type = show_all;
12522
12523 if (!argv_find(argv, argc, "graceful-restart", &idx))
12524 return CMD_SUCCESS;
12525
12526
12527 return bgp_show_neighbor_graceful_restart_afi_all(vty,
12528 sh_type, sh_arg,
12529 afi, uj);
12530}
12531
716b2d8a 12532/* "show [ip] bgp neighbors" commands. */
718e3744 12533DEFUN (show_ip_bgp_neighbors,
12534 show_ip_bgp_neighbors_cmd,
24345e82 12535 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12536 SHOW_STR
12537 IP_STR
12538 BGP_STR
f2a8972b 12539 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12540 "Address Family\n"
12541 "Address Family\n"
718e3744 12542 "Detailed information on TCP and BGP neighbor connections\n"
12543 "Neighbor to display information about\n"
a80beece 12544 "Neighbor to display information about\n"
91d37724 12545 "Neighbor on BGP configured interface\n"
9973d184 12546 JSON_STR)
718e3744 12547{
d62a17ae 12548 char *vrf = NULL;
12549 char *sh_arg = NULL;
12550 enum show_type sh_type;
d1927ebe 12551 afi_t afi = AFI_MAX;
718e3744 12552
9f049418 12553 bool uj = use_json(argc, argv);
718e3744 12554
d62a17ae 12555 int idx = 0;
718e3744 12556
9a8bdf1c
PG
12557 /* [<vrf> VIEWVRFNAME] */
12558 if (argv_find(argv, argc, "vrf", &idx)) {
12559 vrf = argv[idx + 1]->arg;
12560 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12561 vrf = NULL;
12562 } else if (argv_find(argv, argc, "view", &idx))
12563 /* [<view> VIEWVRFNAME] */
d62a17ae 12564 vrf = argv[idx + 1]->arg;
718e3744 12565
d62a17ae 12566 idx++;
d1927ebe
AS
12567
12568 if (argv_find(argv, argc, "ipv4", &idx)) {
12569 sh_type = show_ipv4_all;
12570 afi = AFI_IP;
12571 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12572 sh_type = show_ipv6_all;
12573 afi = AFI_IP6;
12574 } else {
12575 sh_type = show_all;
12576 }
12577
d62a17ae 12578 if (argv_find(argv, argc, "A.B.C.D", &idx)
12579 || argv_find(argv, argc, "X:X::X:X", &idx)
12580 || argv_find(argv, argc, "WORD", &idx)) {
12581 sh_type = show_peer;
12582 sh_arg = argv[idx]->arg;
d1927ebe
AS
12583 }
12584
12585 if (sh_type == show_peer && afi == AFI_IP) {
12586 sh_type = show_ipv4_peer;
12587 } else if (sh_type == show_peer && afi == AFI_IP6) {
12588 sh_type = show_ipv6_peer;
12589 }
856ca177 12590
d62a17ae 12591 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12592}
12593
716b2d8a 12594/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12595 paths' and `show ip mbgp paths'. Those functions results are the
12596 same.*/
f412b39a 12597DEFUN (show_ip_bgp_paths,
718e3744 12598 show_ip_bgp_paths_cmd,
46f296b4 12599 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12600 SHOW_STR
12601 IP_STR
12602 BGP_STR
46f296b4 12603 BGP_SAFI_HELP_STR
718e3744 12604 "Path information\n")
12605{
d62a17ae 12606 vty_out(vty, "Address Refcnt Path\n");
12607 aspath_print_all_vty(vty);
12608 return CMD_SUCCESS;
718e3744 12609}
12610
718e3744 12611#include "hash.h"
12612
e3b78da8 12613static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12614 struct vty *vty)
718e3744 12615{
d62a17ae 12616 struct community *com;
718e3744 12617
e3b78da8 12618 com = (struct community *)bucket->data;
3f65c5b1 12619 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12620 community_str(com, false));
718e3744 12621}
12622
12623/* Show BGP's community internal data. */
f412b39a 12624DEFUN (show_ip_bgp_community_info,
718e3744 12625 show_ip_bgp_community_info_cmd,
bec37ba5 12626 "show [ip] bgp community-info",
718e3744 12627 SHOW_STR
12628 IP_STR
12629 BGP_STR
12630 "List all bgp community information\n")
12631{
d62a17ae 12632 vty_out(vty, "Address Refcnt Community\n");
718e3744 12633
d62a17ae 12634 hash_iterate(community_hash(),
e3b78da8 12635 (void (*)(struct hash_bucket *,
d62a17ae 12636 void *))community_show_all_iterator,
12637 vty);
718e3744 12638
d62a17ae 12639 return CMD_SUCCESS;
718e3744 12640}
12641
e3b78da8 12642static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12643 struct vty *vty)
57d187bc 12644{
d62a17ae 12645 struct lcommunity *lcom;
57d187bc 12646
e3b78da8 12647 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12648 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12649 lcommunity_str(lcom, false));
57d187bc
JS
12650}
12651
12652/* Show BGP's community internal data. */
12653DEFUN (show_ip_bgp_lcommunity_info,
12654 show_ip_bgp_lcommunity_info_cmd,
12655 "show ip bgp large-community-info",
12656 SHOW_STR
12657 IP_STR
12658 BGP_STR
12659 "List all bgp large-community information\n")
12660{
d62a17ae 12661 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 12662
d62a17ae 12663 hash_iterate(lcommunity_hash(),
e3b78da8 12664 (void (*)(struct hash_bucket *,
d62a17ae 12665 void *))lcommunity_show_all_iterator,
12666 vty);
57d187bc 12667
d62a17ae 12668 return CMD_SUCCESS;
57d187bc 12669}
2986cac2 12670/* Graceful Restart */
12671
12672static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
12673 struct bgp *bgp,
12674 bool use_json,
12675 json_object *json)
12676{
57d187bc
JS
12677
12678
2986cac2 12679 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12680
7318ae88 12681 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 12682
12683 switch (bgp_global_gr_mode) {
12684
12685 case GLOBAL_HELPER:
13909c4f 12686 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 12687 break;
12688
12689 case GLOBAL_GR:
13909c4f 12690 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 12691 break;
12692
12693 case GLOBAL_DISABLE:
13909c4f 12694 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 12695 break;
12696
12697 case GLOBAL_INVALID:
2986cac2 12698 vty_out(vty,
2ba1fe69 12699 "Global BGP GR Mode Invalid\n");
2986cac2 12700 break;
12701 }
12702 vty_out(vty, "\n");
12703}
12704
12705static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12706 enum show_type type,
12707 const char *ip_str,
12708 afi_t afi,
12709 bool use_json)
12710{
12711 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12712 afi = AFI_IP;
12713
12714 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12715
12716 bgp_show_neighbor_graceful_restart_vty(vty,
12717 type, ip_str,
12718 afi, use_json);
12719 afi++;
12720 }
12721 } else if (afi != AFI_MAX) {
12722 bgp_show_neighbor_graceful_restart_vty(vty,
12723 type, ip_str,
12724 afi, use_json);
12725 } else {
12726 return CMD_ERR_INCOMPLETE;
12727 }
12728
12729 return CMD_SUCCESS;
12730}
12731/* Graceful Restart */
12732
f412b39a 12733DEFUN (show_ip_bgp_attr_info,
718e3744 12734 show_ip_bgp_attr_info_cmd,
bec37ba5 12735 "show [ip] bgp attribute-info",
718e3744 12736 SHOW_STR
12737 IP_STR
12738 BGP_STR
12739 "List all bgp attribute information\n")
12740{
d62a17ae 12741 attr_show_all(vty);
12742 return CMD_SUCCESS;
718e3744 12743}
6b0655a2 12744
03915806
CS
12745static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12746 afi_t afi, safi_t safi,
12747 bool use_json, json_object *json)
53089bec 12748{
12749 struct bgp *bgp;
12750 struct listnode *node;
12751 char *vname;
12752 char buf1[INET6_ADDRSTRLEN];
12753 char *ecom_str;
12754 vpn_policy_direction_t dir;
12755
03915806 12756 if (json) {
b46dfd20
DS
12757 json_object *json_import_vrfs = NULL;
12758 json_object *json_export_vrfs = NULL;
12759
b46dfd20
DS
12760 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12761
53089bec 12762 if (!bgp) {
b46dfd20
DS
12763 vty_out(vty, "%s\n",
12764 json_object_to_json_string_ext(
12765 json,
12766 JSON_C_TO_STRING_PRETTY));
12767 json_object_free(json);
12768
53089bec 12769 return CMD_WARNING;
12770 }
b46dfd20 12771
94d4c685
DS
12772 /* Provide context for the block */
12773 json_object_string_add(json, "vrf", name ? name : "default");
12774 json_object_string_add(json, "afiSafi",
5cb5f4d0 12775 get_afi_safi_str(afi, safi, true));
94d4c685 12776
b46dfd20
DS
12777 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12778 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12779 json_object_string_add(json, "importFromVrfs", "none");
12780 json_object_string_add(json, "importRts", "none");
12781 } else {
6ce24e52
DS
12782 json_import_vrfs = json_object_new_array();
12783
b46dfd20
DS
12784 for (ALL_LIST_ELEMENTS_RO(
12785 bgp->vpn_policy[afi].import_vrf,
12786 node, vname))
12787 json_object_array_add(json_import_vrfs,
12788 json_object_new_string(vname));
12789
b20875ea
CS
12790 json_object_object_add(json, "importFromVrfs",
12791 json_import_vrfs);
b46dfd20 12792 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12793 if (bgp->vpn_policy[afi].rtlist[dir]) {
12794 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12795 bgp->vpn_policy[afi].rtlist[dir],
12796 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12797 json_object_string_add(json, "importRts",
12798 ecom_str);
12799 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12800 } else
12801 json_object_string_add(json, "importRts",
12802 "none");
b46dfd20
DS
12803 }
12804
12805 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12806 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12807 json_object_string_add(json, "exportToVrfs", "none");
12808 json_object_string_add(json, "routeDistinguisher",
12809 "none");
12810 json_object_string_add(json, "exportRts", "none");
12811 } else {
6ce24e52
DS
12812 json_export_vrfs = json_object_new_array();
12813
b46dfd20
DS
12814 for (ALL_LIST_ELEMENTS_RO(
12815 bgp->vpn_policy[afi].export_vrf,
12816 node, vname))
12817 json_object_array_add(json_export_vrfs,
12818 json_object_new_string(vname));
12819 json_object_object_add(json, "exportToVrfs",
12820 json_export_vrfs);
12821 json_object_string_add(json, "routeDistinguisher",
12822 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12823 buf1, RD_ADDRSTRLEN));
12824
12825 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12826 if (bgp->vpn_policy[afi].rtlist[dir]) {
12827 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12828 bgp->vpn_policy[afi].rtlist[dir],
12829 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12830 json_object_string_add(json, "exportRts",
12831 ecom_str);
12832 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12833 } else
12834 json_object_string_add(json, "exportRts",
12835 "none");
b46dfd20
DS
12836 }
12837
03915806
CS
12838 if (use_json) {
12839 vty_out(vty, "%s\n",
12840 json_object_to_json_string_ext(json,
b46dfd20 12841 JSON_C_TO_STRING_PRETTY));
03915806
CS
12842 json_object_free(json);
12843 }
53089bec 12844 } else {
b46dfd20
DS
12845 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12846
53089bec 12847 if (!bgp) {
b46dfd20 12848 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 12849 return CMD_WARNING;
12850 }
53089bec 12851
b46dfd20
DS
12852 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12853 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12854 vty_out(vty,
12855 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 12856 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12857 else {
12858 vty_out(vty,
12859 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 12860 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12861
12862 for (ALL_LIST_ELEMENTS_RO(
12863 bgp->vpn_policy[afi].import_vrf,
12864 node, vname))
12865 vty_out(vty, " %s\n", vname);
12866
12867 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12868 ecom_str = NULL;
12869 if (bgp->vpn_policy[afi].rtlist[dir]) {
12870 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12871 bgp->vpn_policy[afi].rtlist[dir],
12872 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 12873 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 12874
b20875ea
CS
12875 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12876 } else
12877 vty_out(vty, "Import RT(s):\n");
53089bec 12878 }
53089bec 12879
b46dfd20
DS
12880 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12881 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12882 vty_out(vty,
12883 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 12884 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12885 else {
12886 vty_out(vty,
04c9077f 12887 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 12888 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12889
12890 for (ALL_LIST_ELEMENTS_RO(
12891 bgp->vpn_policy[afi].export_vrf,
12892 node, vname))
12893 vty_out(vty, " %s\n", vname);
12894
12895 vty_out(vty, "RD: %s\n",
12896 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12897 buf1, RD_ADDRSTRLEN));
12898
12899 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12900 if (bgp->vpn_policy[afi].rtlist[dir]) {
12901 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12902 bgp->vpn_policy[afi].rtlist[dir],
12903 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12904 vty_out(vty, "Export RT: %s\n", ecom_str);
12905 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12906 } else
12907 vty_out(vty, "Import RT(s):\n");
53089bec 12908 }
53089bec 12909 }
12910
12911 return CMD_SUCCESS;
12912}
12913
03915806
CS
12914static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12915 safi_t safi, bool use_json)
12916{
12917 struct listnode *node, *nnode;
12918 struct bgp *bgp;
12919 char *vrf_name = NULL;
12920 json_object *json = NULL;
12921 json_object *json_vrf = NULL;
12922 json_object *json_vrfs = NULL;
12923
12924 if (use_json) {
12925 json = json_object_new_object();
12926 json_vrfs = json_object_new_object();
12927 }
12928
12929 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12930
12931 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12932 vrf_name = bgp->name;
12933
12934 if (use_json) {
12935 json_vrf = json_object_new_object();
12936 } else {
12937 vty_out(vty, "\nInstance %s:\n",
12938 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12939 ? VRF_DEFAULT_NAME : bgp->name);
12940 }
12941 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
12942 if (use_json) {
12943 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12944 json_object_object_add(json_vrfs,
12945 VRF_DEFAULT_NAME, json_vrf);
12946 else
12947 json_object_object_add(json_vrfs, vrf_name,
12948 json_vrf);
12949 }
12950 }
12951
12952 if (use_json) {
12953 json_object_object_add(json, "vrfs", json_vrfs);
12954 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
12955 JSON_C_TO_STRING_PRETTY));
12956 json_object_free(json);
12957 }
12958
12959 return CMD_SUCCESS;
12960}
12961
53089bec 12962/* "show [ip] bgp route-leak" command. */
12963DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
12964 show_ip_bgp_route_leak_cmd,
12965 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
12966 SHOW_STR
12967 IP_STR
12968 BGP_STR
12969 BGP_INSTANCE_HELP_STR
12970 BGP_AFI_HELP_STR
12971 BGP_SAFI_HELP_STR
12972 "Route leaking information\n"
12973 JSON_STR)
53089bec 12974{
12975 char *vrf = NULL;
12976 afi_t afi = AFI_MAX;
12977 safi_t safi = SAFI_MAX;
12978
9f049418 12979 bool uj = use_json(argc, argv);
53089bec 12980 int idx = 0;
03915806 12981 json_object *json = NULL;
53089bec 12982
12983 /* show [ip] bgp */
12984 if (argv_find(argv, argc, "ip", &idx)) {
12985 afi = AFI_IP;
12986 safi = SAFI_UNICAST;
12987 }
12988 /* [vrf VIEWVRFNAME] */
12989 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
12990 vty_out(vty,
12991 "%% This command is not applicable to BGP views\n");
53089bec 12992 return CMD_WARNING;
12993 }
12994
9a8bdf1c
PG
12995 if (argv_find(argv, argc, "vrf", &idx)) {
12996 vrf = argv[idx + 1]->arg;
12997 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12998 vrf = NULL;
12999 }
53089bec 13000 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13001 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13002 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13003 }
13004
13005 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13006 vty_out(vty,
13007 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13008 return CMD_WARNING;
13009 }
13010
03915806
CS
13011 if (vrf && strmatch(vrf, "all"))
13012 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13013
13014 if (uj)
13015 json = json_object_new_object();
13016
13017 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13018}
13019
d62a17ae 13020static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13021 safi_t safi)
f186de26 13022{
d62a17ae 13023 struct listnode *node, *nnode;
13024 struct bgp *bgp;
f186de26 13025
d62a17ae 13026 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13027 vty_out(vty, "\nInstance %s:\n",
13028 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13029 ? VRF_DEFAULT_NAME
d62a17ae 13030 : bgp->name);
13031 update_group_show(bgp, afi, safi, vty, 0);
13032 }
f186de26 13033}
13034
d62a17ae 13035static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13036 int safi, uint64_t subgrp_id)
4fb25c53 13037{
d62a17ae 13038 struct bgp *bgp;
4fb25c53 13039
d62a17ae 13040 if (name) {
13041 if (strmatch(name, "all")) {
13042 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13043 return CMD_SUCCESS;
13044 } else {
13045 bgp = bgp_lookup_by_name(name);
13046 }
13047 } else {
13048 bgp = bgp_get_default();
13049 }
4fb25c53 13050
d62a17ae 13051 if (bgp)
13052 update_group_show(bgp, afi, safi, vty, subgrp_id);
13053 return CMD_SUCCESS;
4fb25c53
DW
13054}
13055
8fe8a7f6
DS
13056DEFUN (show_ip_bgp_updgrps,
13057 show_ip_bgp_updgrps_cmd,
c1a44e43 13058 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13059 SHOW_STR
13060 IP_STR
13061 BGP_STR
13062 BGP_INSTANCE_HELP_STR
c9e571b4 13063 BGP_AFI_HELP_STR
9bedbb1e 13064 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13065 "Detailed info about dynamic update groups\n"
13066 "Specific subgroup to display detailed info for\n")
8386ac43 13067{
d62a17ae 13068 char *vrf = NULL;
13069 afi_t afi = AFI_IP6;
13070 safi_t safi = SAFI_UNICAST;
13071 uint64_t subgrp_id = 0;
13072
13073 int idx = 0;
13074
13075 /* show [ip] bgp */
13076 if (argv_find(argv, argc, "ip", &idx))
13077 afi = AFI_IP;
9a8bdf1c
PG
13078 /* [<vrf> VIEWVRFNAME] */
13079 if (argv_find(argv, argc, "vrf", &idx)) {
13080 vrf = argv[idx + 1]->arg;
13081 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13082 vrf = NULL;
13083 } else if (argv_find(argv, argc, "view", &idx))
13084 /* [<view> VIEWVRFNAME] */
13085 vrf = argv[idx + 1]->arg;
d62a17ae 13086 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13087 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13088 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13089 }
5bf15956 13090
d62a17ae 13091 /* get subgroup id, if provided */
13092 idx = argc - 1;
13093 if (argv[idx]->type == VARIABLE_TKN)
13094 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13095
d62a17ae 13096 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13097}
13098
f186de26 13099DEFUN (show_bgp_instance_all_ipv6_updgrps,
13100 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13101 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13102 SHOW_STR
716b2d8a 13103 IP_STR
f186de26 13104 BGP_STR
13105 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13106 "Detailed info about dynamic update groups\n")
f186de26 13107{
d62a17ae 13108 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13109 return CMD_SUCCESS;
f186de26 13110}
13111
43d3f4fc
DS
13112DEFUN (show_bgp_l2vpn_evpn_updgrps,
13113 show_bgp_l2vpn_evpn_updgrps_cmd,
13114 "show [ip] bgp l2vpn evpn update-groups",
13115 SHOW_STR
13116 IP_STR
13117 BGP_STR
13118 "l2vpn address family\n"
13119 "evpn sub-address family\n"
13120 "Detailed info about dynamic update groups\n")
13121{
13122 char *vrf = NULL;
13123 uint64_t subgrp_id = 0;
13124
13125 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13126 return CMD_SUCCESS;
13127}
13128
5bf15956
DW
13129DEFUN (show_bgp_updgrps_stats,
13130 show_bgp_updgrps_stats_cmd,
716b2d8a 13131 "show [ip] bgp update-groups statistics",
3f9c7369 13132 SHOW_STR
716b2d8a 13133 IP_STR
3f9c7369 13134 BGP_STR
0c7b1b01 13135 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13136 "Statistics\n")
13137{
d62a17ae 13138 struct bgp *bgp;
3f9c7369 13139
d62a17ae 13140 bgp = bgp_get_default();
13141 if (bgp)
13142 update_group_show_stats(bgp, vty);
3f9c7369 13143
d62a17ae 13144 return CMD_SUCCESS;
3f9c7369
DS
13145}
13146
8386ac43 13147DEFUN (show_bgp_instance_updgrps_stats,
13148 show_bgp_instance_updgrps_stats_cmd,
18c57037 13149 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13150 SHOW_STR
716b2d8a 13151 IP_STR
8386ac43 13152 BGP_STR
13153 BGP_INSTANCE_HELP_STR
0c7b1b01 13154 "Detailed info about dynamic update groups\n"
8386ac43 13155 "Statistics\n")
13156{
d62a17ae 13157 int idx_word = 3;
13158 struct bgp *bgp;
8386ac43 13159
d62a17ae 13160 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13161 if (bgp)
13162 update_group_show_stats(bgp, vty);
8386ac43 13163
d62a17ae 13164 return CMD_SUCCESS;
8386ac43 13165}
13166
d62a17ae 13167static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13168 afi_t afi, safi_t safi,
13169 const char *what, uint64_t subgrp_id)
3f9c7369 13170{
d62a17ae 13171 struct bgp *bgp;
8386ac43 13172
d62a17ae 13173 if (name)
13174 bgp = bgp_lookup_by_name(name);
13175 else
13176 bgp = bgp_get_default();
8386ac43 13177
d62a17ae 13178 if (bgp) {
13179 if (!strcmp(what, "advertise-queue"))
13180 update_group_show_adj_queue(bgp, afi, safi, vty,
13181 subgrp_id);
13182 else if (!strcmp(what, "advertised-routes"))
13183 update_group_show_advertised(bgp, afi, safi, vty,
13184 subgrp_id);
13185 else if (!strcmp(what, "packet-queue"))
13186 update_group_show_packet_queue(bgp, afi, safi, vty,
13187 subgrp_id);
13188 }
3f9c7369
DS
13189}
13190
dc64bdec
QY
13191DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13192 show_ip_bgp_instance_updgrps_adj_s_cmd,
13193 "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",
13194 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13195 BGP_SAFI_HELP_STR
13196 "Detailed info about dynamic update groups\n"
13197 "Specific subgroup to display info for\n"
13198 "Advertisement queue\n"
13199 "Announced routes\n"
13200 "Packet queue\n")
3f9c7369 13201{
dc64bdec
QY
13202 uint64_t subgrp_id = 0;
13203 afi_t afiz;
13204 safi_t safiz;
13205 if (sgid)
13206 subgrp_id = strtoull(sgid, NULL, 10);
13207
13208 if (!ip && !afi)
13209 afiz = AFI_IP6;
13210 if (!ip && afi)
13211 afiz = bgp_vty_afi_from_str(afi);
13212 if (ip && !afi)
13213 afiz = AFI_IP;
13214 if (ip && afi) {
13215 afiz = bgp_vty_afi_from_str(afi);
13216 if (afiz != AFI_IP)
13217 vty_out(vty,
13218 "%% Cannot specify both 'ip' and 'ipv6'\n");
13219 return CMD_WARNING;
13220 }
d62a17ae 13221
dc64bdec 13222 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13223
dc64bdec 13224 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13225 return CMD_SUCCESS;
13226}
13227
d62a17ae 13228static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13229{
13230 struct listnode *node, *nnode;
13231 struct prefix *range;
13232 struct peer *conf;
13233 struct peer *peer;
13234 char buf[PREFIX2STR_BUFFER];
13235 afi_t afi;
13236 safi_t safi;
13237 const char *peer_status;
13238 const char *af_str;
13239 int lr_count;
13240 int dynamic;
13241 int af_cfgd;
13242
13243 conf = group->conf;
13244
13245 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
13246 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13247 group->name, conf->as);
d62a17ae 13248 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
13249 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13250 group->name, group->bgp->as);
d62a17ae 13251 } else {
13252 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13253 }
f14e6fdb 13254
d62a17ae 13255 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13256 vty_out(vty, " Peer-group type is internal\n");
13257 else
13258 vty_out(vty, " Peer-group type is external\n");
13259
13260 /* Display AFs configured. */
13261 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13262 FOREACH_AFI_SAFI (afi, safi) {
13263 if (conf->afc[afi][safi]) {
13264 af_cfgd = 1;
5cb5f4d0 13265 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13266 }
05c7a1cc 13267 }
d62a17ae 13268 if (!af_cfgd)
13269 vty_out(vty, " none\n");
13270 else
13271 vty_out(vty, "\n");
13272
13273 /* Display listen ranges (for dynamic neighbors), if any */
13274 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13275 if (afi == AFI_IP)
13276 af_str = "IPv4";
13277 else if (afi == AFI_IP6)
13278 af_str = "IPv6";
13279 else
13280 af_str = "???";
13281 lr_count = listcount(group->listen_range[afi]);
13282 if (lr_count) {
13283 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13284 af_str);
13285
13286
13287 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13288 nnode, range)) {
13289 prefix2str(range, buf, sizeof(buf));
13290 vty_out(vty, " %s\n", buf);
13291 }
13292 }
13293 }
f14e6fdb 13294
d62a17ae 13295 /* Display group members and their status */
13296 if (listcount(group->peer)) {
13297 vty_out(vty, " Peer-group members:\n");
13298 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13299 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13300 peer_status = "Idle (Admin)";
13301 else if (CHECK_FLAG(peer->sflags,
13302 PEER_STATUS_PREFIX_OVERFLOW))
13303 peer_status = "Idle (PfxCt)";
13304 else
13305 peer_status = lookup_msg(bgp_status_msg,
13306 peer->status, NULL);
13307
13308 dynamic = peer_dynamic_neighbor(peer);
13309 vty_out(vty, " %s %s %s \n", peer->host,
13310 dynamic ? "(dynamic)" : "", peer_status);
13311 }
13312 }
f14e6fdb 13313
d62a17ae 13314 return CMD_SUCCESS;
13315}
13316
ff9959b0
QY
13317static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13318 const char *group_name)
d62a17ae 13319{
ff9959b0 13320 struct bgp *bgp;
d62a17ae 13321 struct listnode *node, *nnode;
13322 struct peer_group *group;
ff9959b0
QY
13323 bool found = false;
13324
13325 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13326
13327 if (!bgp) {
9f049418 13328 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13329 return CMD_WARNING;
13330 }
d62a17ae 13331
13332 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13333 if (group_name) {
13334 if (strmatch(group->name, group_name)) {
d62a17ae 13335 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13336 found = true;
13337 break;
d62a17ae 13338 }
ff9959b0
QY
13339 } else {
13340 bgp_show_one_peer_group(vty, group);
d62a17ae 13341 }
f14e6fdb 13342 }
f14e6fdb 13343
ff9959b0 13344 if (group_name && !found)
d62a17ae 13345 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13346
d62a17ae 13347 return CMD_SUCCESS;
f14e6fdb
DS
13348}
13349
f14e6fdb
DS
13350DEFUN (show_ip_bgp_peer_groups,
13351 show_ip_bgp_peer_groups_cmd,
18c57037 13352 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13353 SHOW_STR
13354 IP_STR
13355 BGP_STR
8386ac43 13356 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13357 "Detailed information on BGP peer groups\n"
13358 "Peer group name\n")
f14e6fdb 13359{
d62a17ae 13360 char *vrf, *pg;
d62a17ae 13361 int idx = 0;
f14e6fdb 13362
a4d82a8a
PZ
13363 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13364 : NULL;
d62a17ae 13365 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13366
ff9959b0 13367 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13368}
3f9c7369 13369
d6e3c605 13370
718e3744 13371/* Redistribute VTY commands. */
13372
718e3744 13373DEFUN (bgp_redistribute_ipv4,
13374 bgp_redistribute_ipv4_cmd,
40d1cbfb 13375 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13376 "Redistribute information from another routing protocol\n"
ab0181ee 13377 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13378{
d62a17ae 13379 VTY_DECLVAR_CONTEXT(bgp, bgp);
13380 int idx_protocol = 1;
13381 int type;
718e3744 13382
d62a17ae 13383 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13384 if (type < 0) {
13385 vty_out(vty, "%% Invalid route type\n");
13386 return CMD_WARNING_CONFIG_FAILED;
13387 }
7f323236 13388
d62a17ae 13389 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13390 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13391}
13392
d62a17ae 13393ALIAS_HIDDEN(
13394 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13395 "redistribute " FRR_IP_REDIST_STR_BGPD,
13396 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13397
718e3744 13398DEFUN (bgp_redistribute_ipv4_rmap,
13399 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13400 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13401 "Redistribute information from another routing protocol\n"
ab0181ee 13402 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13403 "Route map reference\n"
13404 "Pointer to route-map entries\n")
13405{
d62a17ae 13406 VTY_DECLVAR_CONTEXT(bgp, bgp);
13407 int idx_protocol = 1;
13408 int idx_word = 3;
13409 int type;
13410 struct bgp_redist *red;
e923dd62 13411 bool changed;
1de27621
DA
13412 struct route_map *route_map = route_map_lookup_warn_noexist(
13413 vty, argv[idx_word]->arg);
718e3744 13414
d62a17ae 13415 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13416 if (type < 0) {
13417 vty_out(vty, "%% Invalid route type\n");
13418 return CMD_WARNING_CONFIG_FAILED;
13419 }
718e3744 13420
d62a17ae 13421 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13422 changed =
13423 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13424 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13425}
13426
d62a17ae 13427ALIAS_HIDDEN(
13428 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13429 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13430 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13431 "Route map reference\n"
13432 "Pointer to route-map entries\n")
596c17ba 13433
718e3744 13434DEFUN (bgp_redistribute_ipv4_metric,
13435 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13436 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13437 "Redistribute information from another routing protocol\n"
ab0181ee 13438 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13439 "Metric for redistributed routes\n"
13440 "Default metric\n")
13441{
d62a17ae 13442 VTY_DECLVAR_CONTEXT(bgp, bgp);
13443 int idx_protocol = 1;
13444 int idx_number = 3;
13445 int type;
d7c0a89a 13446 uint32_t metric;
d62a17ae 13447 struct bgp_redist *red;
e923dd62 13448 bool changed;
d62a17ae 13449
13450 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13451 if (type < 0) {
13452 vty_out(vty, "%% Invalid route type\n");
13453 return CMD_WARNING_CONFIG_FAILED;
13454 }
13455 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13456
13457 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13458 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13459 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13460}
13461
13462ALIAS_HIDDEN(
13463 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13464 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13465 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13466 "Metric for redistributed routes\n"
13467 "Default metric\n")
596c17ba 13468
718e3744 13469DEFUN (bgp_redistribute_ipv4_rmap_metric,
13470 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13471 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13472 "Redistribute information from another routing protocol\n"
ab0181ee 13473 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13474 "Route map reference\n"
13475 "Pointer to route-map entries\n"
13476 "Metric for redistributed routes\n"
13477 "Default metric\n")
13478{
d62a17ae 13479 VTY_DECLVAR_CONTEXT(bgp, bgp);
13480 int idx_protocol = 1;
13481 int idx_word = 3;
13482 int idx_number = 5;
13483 int type;
d7c0a89a 13484 uint32_t metric;
d62a17ae 13485 struct bgp_redist *red;
e923dd62 13486 bool changed;
1de27621
DA
13487 struct route_map *route_map =
13488 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13489
13490 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13491 if (type < 0) {
13492 vty_out(vty, "%% Invalid route type\n");
13493 return CMD_WARNING_CONFIG_FAILED;
13494 }
13495 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13496
13497 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13498 changed =
13499 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13500 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13501 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13502}
13503
13504ALIAS_HIDDEN(
13505 bgp_redistribute_ipv4_rmap_metric,
13506 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13507 "redistribute " FRR_IP_REDIST_STR_BGPD
13508 " route-map WORD metric (0-4294967295)",
13509 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13510 "Route map reference\n"
13511 "Pointer to route-map entries\n"
13512 "Metric for redistributed routes\n"
13513 "Default metric\n")
596c17ba 13514
718e3744 13515DEFUN (bgp_redistribute_ipv4_metric_rmap,
13516 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13517 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13518 "Redistribute information from another routing protocol\n"
ab0181ee 13519 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13520 "Metric for redistributed routes\n"
13521 "Default metric\n"
13522 "Route map reference\n"
13523 "Pointer to route-map entries\n")
13524{
d62a17ae 13525 VTY_DECLVAR_CONTEXT(bgp, bgp);
13526 int idx_protocol = 1;
13527 int idx_number = 3;
13528 int idx_word = 5;
13529 int type;
d7c0a89a 13530 uint32_t metric;
d62a17ae 13531 struct bgp_redist *red;
e923dd62 13532 bool changed;
1de27621
DA
13533 struct route_map *route_map =
13534 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13535
13536 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13537 if (type < 0) {
13538 vty_out(vty, "%% Invalid route type\n");
13539 return CMD_WARNING_CONFIG_FAILED;
13540 }
13541 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13542
13543 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13544 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13545 changed |=
13546 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13547 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13548}
13549
13550ALIAS_HIDDEN(
13551 bgp_redistribute_ipv4_metric_rmap,
13552 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13553 "redistribute " FRR_IP_REDIST_STR_BGPD
13554 " metric (0-4294967295) route-map WORD",
13555 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13556 "Metric for redistributed routes\n"
13557 "Default metric\n"
13558 "Route map reference\n"
13559 "Pointer to route-map entries\n")
596c17ba 13560
7c8ff89e
DS
13561DEFUN (bgp_redistribute_ipv4_ospf,
13562 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13563 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13564 "Redistribute information from another routing protocol\n"
13565 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13566 "Non-main Kernel Routing Table\n"
13567 "Instance ID/Table ID\n")
7c8ff89e 13568{
d62a17ae 13569 VTY_DECLVAR_CONTEXT(bgp, bgp);
13570 int idx_ospf_table = 1;
13571 int idx_number = 2;
d7c0a89a
QY
13572 unsigned short instance;
13573 unsigned short protocol;
7c8ff89e 13574
d62a17ae 13575 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13576
d62a17ae 13577 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13578 protocol = ZEBRA_ROUTE_OSPF;
13579 else
13580 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13581
d62a17ae 13582 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13583 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13584}
13585
d62a17ae 13586ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13587 "redistribute <ospf|table> (1-65535)",
13588 "Redistribute information from another routing protocol\n"
13589 "Open Shortest Path First (OSPFv2)\n"
13590 "Non-main Kernel Routing Table\n"
13591 "Instance ID/Table ID\n")
596c17ba 13592
7c8ff89e
DS
13593DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13594 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13595 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13596 "Redistribute information from another routing protocol\n"
13597 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13598 "Non-main Kernel Routing Table\n"
13599 "Instance ID/Table ID\n"
7c8ff89e
DS
13600 "Route map reference\n"
13601 "Pointer to route-map entries\n")
13602{
d62a17ae 13603 VTY_DECLVAR_CONTEXT(bgp, bgp);
13604 int idx_ospf_table = 1;
13605 int idx_number = 2;
13606 int idx_word = 4;
13607 struct bgp_redist *red;
d7c0a89a 13608 unsigned short instance;
d62a17ae 13609 int protocol;
e923dd62 13610 bool changed;
1de27621
DA
13611 struct route_map *route_map =
13612 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13613
13614 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13615 protocol = ZEBRA_ROUTE_OSPF;
13616 else
13617 protocol = ZEBRA_ROUTE_TABLE;
13618
13619 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13620 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13621 changed =
13622 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13623 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13624}
13625
13626ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13627 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13628 "redistribute <ospf|table> (1-65535) route-map WORD",
13629 "Redistribute information from another routing protocol\n"
13630 "Open Shortest Path First (OSPFv2)\n"
13631 "Non-main Kernel Routing Table\n"
13632 "Instance ID/Table ID\n"
13633 "Route map reference\n"
13634 "Pointer to route-map entries\n")
596c17ba 13635
7c8ff89e
DS
13636DEFUN (bgp_redistribute_ipv4_ospf_metric,
13637 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13638 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13639 "Redistribute information from another routing protocol\n"
13640 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13641 "Non-main Kernel Routing Table\n"
13642 "Instance ID/Table ID\n"
7c8ff89e
DS
13643 "Metric for redistributed routes\n"
13644 "Default metric\n")
13645{
d62a17ae 13646 VTY_DECLVAR_CONTEXT(bgp, bgp);
13647 int idx_ospf_table = 1;
13648 int idx_number = 2;
13649 int idx_number_2 = 4;
d7c0a89a 13650 uint32_t metric;
d62a17ae 13651 struct bgp_redist *red;
d7c0a89a 13652 unsigned short instance;
d62a17ae 13653 int protocol;
e923dd62 13654 bool changed;
d62a17ae 13655
13656 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13657 protocol = ZEBRA_ROUTE_OSPF;
13658 else
13659 protocol = ZEBRA_ROUTE_TABLE;
13660
13661 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13662 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13663
13664 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13665 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13666 metric);
13667 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13668}
13669
13670ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13671 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13672 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13673 "Redistribute information from another routing protocol\n"
13674 "Open Shortest Path First (OSPFv2)\n"
13675 "Non-main Kernel Routing Table\n"
13676 "Instance ID/Table ID\n"
13677 "Metric for redistributed routes\n"
13678 "Default metric\n")
596c17ba 13679
7c8ff89e
DS
13680DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13681 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 13682 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
13683 "Redistribute information from another routing protocol\n"
13684 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13685 "Non-main Kernel Routing Table\n"
13686 "Instance ID/Table ID\n"
7c8ff89e
DS
13687 "Route map reference\n"
13688 "Pointer to route-map entries\n"
13689 "Metric for redistributed routes\n"
13690 "Default metric\n")
13691{
d62a17ae 13692 VTY_DECLVAR_CONTEXT(bgp, bgp);
13693 int idx_ospf_table = 1;
13694 int idx_number = 2;
13695 int idx_word = 4;
13696 int idx_number_2 = 6;
d7c0a89a 13697 uint32_t metric;
d62a17ae 13698 struct bgp_redist *red;
d7c0a89a 13699 unsigned short instance;
d62a17ae 13700 int protocol;
e923dd62 13701 bool changed;
1de27621
DA
13702 struct route_map *route_map =
13703 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13704
13705 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13706 protocol = ZEBRA_ROUTE_OSPF;
13707 else
13708 protocol = ZEBRA_ROUTE_TABLE;
13709
13710 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13711 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13712
13713 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13714 changed =
13715 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13716 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13717 metric);
13718 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13719}
13720
13721ALIAS_HIDDEN(
13722 bgp_redistribute_ipv4_ospf_rmap_metric,
13723 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13724 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13725 "Redistribute information from another routing protocol\n"
13726 "Open Shortest Path First (OSPFv2)\n"
13727 "Non-main Kernel Routing Table\n"
13728 "Instance ID/Table ID\n"
13729 "Route map reference\n"
13730 "Pointer to route-map entries\n"
13731 "Metric for redistributed routes\n"
13732 "Default metric\n")
596c17ba 13733
7c8ff89e
DS
13734DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13735 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 13736 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
13737 "Redistribute information from another routing protocol\n"
13738 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13739 "Non-main Kernel Routing Table\n"
13740 "Instance ID/Table ID\n"
7c8ff89e
DS
13741 "Metric for redistributed routes\n"
13742 "Default metric\n"
13743 "Route map reference\n"
13744 "Pointer to route-map entries\n")
13745{
d62a17ae 13746 VTY_DECLVAR_CONTEXT(bgp, bgp);
13747 int idx_ospf_table = 1;
13748 int idx_number = 2;
13749 int idx_number_2 = 4;
13750 int idx_word = 6;
d7c0a89a 13751 uint32_t metric;
d62a17ae 13752 struct bgp_redist *red;
d7c0a89a 13753 unsigned short instance;
d62a17ae 13754 int protocol;
e923dd62 13755 bool changed;
1de27621
DA
13756 struct route_map *route_map =
13757 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13758
13759 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13760 protocol = ZEBRA_ROUTE_OSPF;
13761 else
13762 protocol = ZEBRA_ROUTE_TABLE;
13763
13764 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13765 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13766
13767 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13768 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13769 metric);
1de27621
DA
13770 changed |=
13771 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13772 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13773}
13774
13775ALIAS_HIDDEN(
13776 bgp_redistribute_ipv4_ospf_metric_rmap,
13777 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13778 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13779 "Redistribute information from another routing protocol\n"
13780 "Open Shortest Path First (OSPFv2)\n"
13781 "Non-main Kernel Routing Table\n"
13782 "Instance ID/Table ID\n"
13783 "Metric for redistributed routes\n"
13784 "Default metric\n"
13785 "Route map reference\n"
13786 "Pointer to route-map entries\n")
596c17ba 13787
7c8ff89e
DS
13788DEFUN (no_bgp_redistribute_ipv4_ospf,
13789 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 13790 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
13791 NO_STR
13792 "Redistribute information from another routing protocol\n"
13793 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 13794 "Non-main Kernel Routing Table\n"
31500417
DW
13795 "Instance ID/Table ID\n"
13796 "Metric for redistributed routes\n"
13797 "Default metric\n"
13798 "Route map reference\n"
13799 "Pointer to route-map entries\n")
7c8ff89e 13800{
d62a17ae 13801 VTY_DECLVAR_CONTEXT(bgp, bgp);
13802 int idx_ospf_table = 2;
13803 int idx_number = 3;
d7c0a89a 13804 unsigned short instance;
d62a17ae 13805 int protocol;
13806
13807 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13808 protocol = ZEBRA_ROUTE_OSPF;
13809 else
13810 protocol = ZEBRA_ROUTE_TABLE;
13811
13812 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13813 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13814}
13815
13816ALIAS_HIDDEN(
13817 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 13818 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13819 NO_STR
13820 "Redistribute information from another routing protocol\n"
13821 "Open Shortest Path First (OSPFv2)\n"
13822 "Non-main Kernel Routing Table\n"
13823 "Instance ID/Table ID\n"
13824 "Metric for redistributed routes\n"
13825 "Default metric\n"
13826 "Route map reference\n"
13827 "Pointer to route-map entries\n")
596c17ba 13828
718e3744 13829DEFUN (no_bgp_redistribute_ipv4,
13830 no_bgp_redistribute_ipv4_cmd,
e27957c0 13831 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 13832 NO_STR
13833 "Redistribute information from another routing protocol\n"
3b14d86e 13834 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
13835 "Metric for redistributed routes\n"
13836 "Default metric\n"
13837 "Route map reference\n"
13838 "Pointer to route-map entries\n")
718e3744 13839{
d62a17ae 13840 VTY_DECLVAR_CONTEXT(bgp, bgp);
13841 int idx_protocol = 2;
13842 int type;
13843
13844 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13845 if (type < 0) {
13846 vty_out(vty, "%% Invalid route type\n");
13847 return CMD_WARNING_CONFIG_FAILED;
13848 }
13849 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13850}
13851
13852ALIAS_HIDDEN(
13853 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13854 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 13855 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13856 NO_STR
13857 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13858 "Metric for redistributed routes\n"
13859 "Default metric\n"
13860 "Route map reference\n"
13861 "Pointer to route-map entries\n")
596c17ba 13862
718e3744 13863DEFUN (bgp_redistribute_ipv6,
13864 bgp_redistribute_ipv6_cmd,
40d1cbfb 13865 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 13866 "Redistribute information from another routing protocol\n"
ab0181ee 13867 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 13868{
d62a17ae 13869 VTY_DECLVAR_CONTEXT(bgp, bgp);
13870 int idx_protocol = 1;
13871 int type;
718e3744 13872
d62a17ae 13873 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13874 if (type < 0) {
13875 vty_out(vty, "%% Invalid route type\n");
13876 return CMD_WARNING_CONFIG_FAILED;
13877 }
718e3744 13878
d62a17ae 13879 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13880 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 13881}
13882
13883DEFUN (bgp_redistribute_ipv6_rmap,
13884 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 13885 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 13886 "Redistribute information from another routing protocol\n"
ab0181ee 13887 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13888 "Route map reference\n"
13889 "Pointer to route-map entries\n")
13890{
d62a17ae 13891 VTY_DECLVAR_CONTEXT(bgp, bgp);
13892 int idx_protocol = 1;
13893 int idx_word = 3;
13894 int type;
13895 struct bgp_redist *red;
e923dd62 13896 bool changed;
1de27621
DA
13897 struct route_map *route_map =
13898 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 13899
d62a17ae 13900 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13901 if (type < 0) {
13902 vty_out(vty, "%% Invalid route type\n");
13903 return CMD_WARNING_CONFIG_FAILED;
13904 }
718e3744 13905
d62a17ae 13906 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13907 changed =
13908 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13909 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13910}
13911
13912DEFUN (bgp_redistribute_ipv6_metric,
13913 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 13914 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13915 "Redistribute information from another routing protocol\n"
ab0181ee 13916 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13917 "Metric for redistributed routes\n"
13918 "Default metric\n")
13919{
d62a17ae 13920 VTY_DECLVAR_CONTEXT(bgp, bgp);
13921 int idx_protocol = 1;
13922 int idx_number = 3;
13923 int type;
d7c0a89a 13924 uint32_t metric;
d62a17ae 13925 struct bgp_redist *red;
e923dd62 13926 bool changed;
d62a17ae 13927
13928 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13929 if (type < 0) {
13930 vty_out(vty, "%% Invalid route type\n");
13931 return CMD_WARNING_CONFIG_FAILED;
13932 }
13933 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13934
d62a17ae 13935 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13936 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13937 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13938}
13939
13940DEFUN (bgp_redistribute_ipv6_rmap_metric,
13941 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 13942 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13943 "Redistribute information from another routing protocol\n"
ab0181ee 13944 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13945 "Route map reference\n"
13946 "Pointer to route-map entries\n"
13947 "Metric for redistributed routes\n"
13948 "Default metric\n")
13949{
d62a17ae 13950 VTY_DECLVAR_CONTEXT(bgp, bgp);
13951 int idx_protocol = 1;
13952 int idx_word = 3;
13953 int idx_number = 5;
13954 int type;
d7c0a89a 13955 uint32_t metric;
d62a17ae 13956 struct bgp_redist *red;
e923dd62 13957 bool changed;
1de27621
DA
13958 struct route_map *route_map =
13959 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13960
13961 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13962 if (type < 0) {
13963 vty_out(vty, "%% Invalid route type\n");
13964 return CMD_WARNING_CONFIG_FAILED;
13965 }
13966 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13967
d62a17ae 13968 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13969 changed =
13970 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13971 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
13972 metric);
13973 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13974}
13975
13976DEFUN (bgp_redistribute_ipv6_metric_rmap,
13977 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 13978 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13979 "Redistribute information from another routing protocol\n"
ab0181ee 13980 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13981 "Metric for redistributed routes\n"
13982 "Default metric\n"
13983 "Route map reference\n"
13984 "Pointer to route-map entries\n")
13985{
d62a17ae 13986 VTY_DECLVAR_CONTEXT(bgp, bgp);
13987 int idx_protocol = 1;
13988 int idx_number = 3;
13989 int idx_word = 5;
13990 int type;
d7c0a89a 13991 uint32_t metric;
d62a17ae 13992 struct bgp_redist *red;
e923dd62 13993 bool changed;
1de27621
DA
13994 struct route_map *route_map =
13995 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13996
13997 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13998 if (type < 0) {
13999 vty_out(vty, "%% Invalid route type\n");
14000 return CMD_WARNING_CONFIG_FAILED;
14001 }
14002 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14003
d62a17ae 14004 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14005 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14006 metric);
1de27621
DA
14007 changed |=
14008 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14009 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14010}
14011
14012DEFUN (no_bgp_redistribute_ipv6,
14013 no_bgp_redistribute_ipv6_cmd,
e27957c0 14014 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14015 NO_STR
14016 "Redistribute information from another routing protocol\n"
3b14d86e 14017 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14018 "Metric for redistributed routes\n"
14019 "Default metric\n"
14020 "Route map reference\n"
14021 "Pointer to route-map entries\n")
718e3744 14022{
d62a17ae 14023 VTY_DECLVAR_CONTEXT(bgp, bgp);
14024 int idx_protocol = 2;
14025 int type;
718e3744 14026
d62a17ae 14027 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14028 if (type < 0) {
14029 vty_out(vty, "%% Invalid route type\n");
14030 return CMD_WARNING_CONFIG_FAILED;
14031 }
718e3744 14032
d62a17ae 14033 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14034}
14035
dd65f45e
DL
14036static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14037 afi_t afi, safi_t safi)
d62a17ae 14038{
14039 int i;
14040
14041 /* Unicast redistribution only. */
14042 if (safi != SAFI_UNICAST)
2b791107 14043 return;
d62a17ae 14044
14045 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14046 /* Redistribute BGP does not make sense. */
14047 if (i != ZEBRA_ROUTE_BGP) {
14048 struct list *red_list;
14049 struct listnode *node;
14050 struct bgp_redist *red;
14051
14052 red_list = bgp->redist[afi][i];
14053 if (!red_list)
14054 continue;
14055
14056 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14057 /* "redistribute" configuration. */
14058 vty_out(vty, " redistribute %s",
14059 zebra_route_string(i));
14060 if (red->instance)
14061 vty_out(vty, " %d", red->instance);
14062 if (red->redist_metric_flag)
14063 vty_out(vty, " metric %u",
14064 red->redist_metric);
14065 if (red->rmap.name)
14066 vty_out(vty, " route-map %s",
14067 red->rmap.name);
14068 vty_out(vty, "\n");
14069 }
14070 }
14071 }
718e3744 14072}
6b0655a2 14073
dd65f45e
DL
14074/* peer-group helpers for config-write */
14075
14076static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14077{
14078 if (!peer_group_active(peer)) {
14079 if (CHECK_FLAG(peer->flags_invert, flag))
14080 return !CHECK_FLAG(peer->flags, flag);
14081 else
14082 return !!CHECK_FLAG(peer->flags, flag);
14083 }
14084
14085 return !!CHECK_FLAG(peer->flags_override, flag);
14086}
14087
14088static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14089 uint32_t flag)
14090{
14091 if (!peer_group_active(peer)) {
14092 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14093 return !peer_af_flag_check(peer, afi, safi, flag);
14094 else
14095 return !!peer_af_flag_check(peer, afi, safi, flag);
14096 }
14097
14098 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14099}
14100
14101static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14102 uint8_t type, int direct)
14103{
14104 struct bgp_filter *filter;
14105
14106 if (peer_group_active(peer))
14107 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14108 type);
14109
14110 filter = &peer->filter[afi][safi];
14111 switch (type) {
14112 case PEER_FT_DISTRIBUTE_LIST:
14113 return !!(filter->dlist[direct].name);
14114 case PEER_FT_FILTER_LIST:
14115 return !!(filter->aslist[direct].name);
14116 case PEER_FT_PREFIX_LIST:
14117 return !!(filter->plist[direct].name);
14118 case PEER_FT_ROUTE_MAP:
14119 return !!(filter->map[direct].name);
14120 case PEER_FT_UNSUPPRESS_MAP:
14121 return !!(filter->usmap.name);
14122 default:
14123 return false;
14124 }
14125}
14126
14127/* Return true if the addpath type is set for peer and different from
14128 * peer-group.
14129 */
14130static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
14131{
14132 enum bgp_addpath_strat type, g_type;
14133
14134 type = peer->addpath_type[afi][safi];
14135
14136 if (type != BGP_ADDPATH_NONE) {
14137 if (peer_group_active(peer)) {
14138 g_type = peer->group->conf->addpath_type[afi][safi];
14139
14140 if (type != g_type)
14141 return 1;
14142 else
14143 return 0;
14144 }
14145
14146 return 1;
14147 }
14148
14149 return 0;
14150}
14151
b9c7bc5a 14152/* This is part of the address-family block (unicast only) */
dd65f45e 14153static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14154 afi_t afi)
14155{
b9c7bc5a 14156 int indent = 2;
ddb5b488 14157
8a066a70
PG
14158 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14159 if (listcount(bgp->vpn_policy[afi].import_vrf))
14160 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14161 bgp->vpn_policy[afi]
bb4f6190 14162 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14163 else
14164 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14165 bgp->vpn_policy[afi]
14166 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14167 }
12a844a5
DS
14168 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14169 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14170 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14171 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14172 return;
14173
e70e9f8e
PZ
14174 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14175 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14176
14177 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14178
14179 } else {
14180 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14181 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14182 bgp->vpn_policy[afi].tovpn_label);
14183 }
ddb5b488
PZ
14184 }
14185 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14186 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14187 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14188 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14189 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14190 sizeof(buf)));
14191 }
14192 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14193 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14194
14195 char buf[PREFIX_STRLEN];
14196 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14197 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14198 sizeof(buf))) {
14199
b9c7bc5a
PZ
14200 vty_out(vty, "%*snexthop vpn export %s\n",
14201 indent, "", buf);
ddb5b488
PZ
14202 }
14203 }
14204 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14205 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14206 && ecommunity_cmp(
14207 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14208 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14209
14210 char *b = ecommunity_ecom2str(
14211 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14212 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14213 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14214 XFREE(MTYPE_ECOMMUNITY_STR, b);
14215 } else {
14216 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14217 char *b = ecommunity_ecom2str(
14218 bgp->vpn_policy[afi]
14219 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14220 ECOMMUNITY_FORMAT_ROUTE_MAP,
14221 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14222 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14223 XFREE(MTYPE_ECOMMUNITY_STR, b);
14224 }
14225 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14226 char *b = ecommunity_ecom2str(
14227 bgp->vpn_policy[afi]
14228 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14229 ECOMMUNITY_FORMAT_ROUTE_MAP,
14230 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14231 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14232 XFREE(MTYPE_ECOMMUNITY_STR, b);
14233 }
14234 }
bb4f6190
DS
14235
14236 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14237 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14238 bgp->vpn_policy[afi]
14239 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14240
301ad80a
PG
14241 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14242 char *b = ecommunity_ecom2str(
14243 bgp->vpn_policy[afi]
14244 .import_redirect_rtlist,
14245 ECOMMUNITY_FORMAT_ROUTE_MAP,
14246 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14247
301ad80a
PG
14248 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14249 XFREE(MTYPE_ECOMMUNITY_STR, b);
14250 }
ddb5b488
PZ
14251}
14252
dd65f45e
DL
14253static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14254 afi_t afi, safi_t safi)
14255{
14256 struct bgp_filter *filter;
14257 char *addr;
14258
14259 addr = peer->host;
14260 filter = &peer->filter[afi][safi];
14261
14262 /* distribute-list. */
14263 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14264 FILTER_IN))
14265 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14266 filter->dlist[FILTER_IN].name);
14267
14268 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14269 FILTER_OUT))
14270 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14271 filter->dlist[FILTER_OUT].name);
14272
14273 /* prefix-list. */
14274 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14275 FILTER_IN))
14276 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14277 filter->plist[FILTER_IN].name);
14278
14279 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14280 FILTER_OUT))
14281 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14282 filter->plist[FILTER_OUT].name);
14283
14284 /* route-map. */
14285 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14286 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14287 filter->map[RMAP_IN].name);
14288
14289 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14290 RMAP_OUT))
14291 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14292 filter->map[RMAP_OUT].name);
14293
14294 /* unsuppress-map */
14295 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14296 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14297 filter->usmap.name);
14298
14299 /* filter-list. */
14300 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14301 FILTER_IN))
14302 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14303 filter->aslist[FILTER_IN].name);
14304
14305 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14306 FILTER_OUT))
14307 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14308 filter->aslist[FILTER_OUT].name);
14309}
14310
14311/* BGP peer configuration display function. */
14312static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14313 struct peer *peer)
14314{
14315 struct peer *g_peer = NULL;
14316 char buf[SU_ADDRSTRLEN];
14317 char *addr;
14318 int if_pg_printed = false;
14319 int if_ras_printed = false;
14320
14321 /* Skip dynamic neighbors. */
14322 if (peer_dynamic_neighbor(peer))
14323 return;
14324
14325 if (peer->conf_if)
14326 addr = peer->conf_if;
14327 else
14328 addr = peer->host;
14329
14330 /************************************
14331 ****** Global to the neighbor ******
14332 ************************************/
14333 if (peer->conf_if) {
14334 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14335 vty_out(vty, " neighbor %s interface v6only", addr);
14336 else
14337 vty_out(vty, " neighbor %s interface", addr);
14338
14339 if (peer_group_active(peer)) {
14340 vty_out(vty, " peer-group %s", peer->group->name);
14341 if_pg_printed = true;
14342 } else if (peer->as_type == AS_SPECIFIED) {
14343 vty_out(vty, " remote-as %u", peer->as);
14344 if_ras_printed = true;
14345 } else if (peer->as_type == AS_INTERNAL) {
14346 vty_out(vty, " remote-as internal");
14347 if_ras_printed = true;
14348 } else if (peer->as_type == AS_EXTERNAL) {
14349 vty_out(vty, " remote-as external");
14350 if_ras_printed = true;
14351 }
14352
14353 vty_out(vty, "\n");
14354 }
14355
14356 /* remote-as and peer-group */
14357 /* peer is a member of a peer-group */
14358 if (peer_group_active(peer)) {
14359 g_peer = peer->group->conf;
14360
14361 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14362 if (peer->as_type == AS_SPECIFIED) {
14363 vty_out(vty, " neighbor %s remote-as %u\n",
14364 addr, peer->as);
14365 } else if (peer->as_type == AS_INTERNAL) {
14366 vty_out(vty,
14367 " neighbor %s remote-as internal\n",
14368 addr);
14369 } else if (peer->as_type == AS_EXTERNAL) {
14370 vty_out(vty,
14371 " neighbor %s remote-as external\n",
14372 addr);
14373 }
14374 }
14375
14376 /* For swpX peers we displayed the peer-group
14377 * via 'neighbor swpX interface peer-group PGNAME' */
14378 if (!if_pg_printed)
14379 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14380 peer->group->name);
14381 }
14382
14383 /* peer is NOT a member of a peer-group */
14384 else {
14385 /* peer is a peer-group, declare the peer-group */
14386 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14387 vty_out(vty, " neighbor %s peer-group\n", addr);
14388 }
14389
14390 if (!if_ras_printed) {
14391 if (peer->as_type == AS_SPECIFIED) {
14392 vty_out(vty, " neighbor %s remote-as %u\n",
14393 addr, peer->as);
14394 } else if (peer->as_type == AS_INTERNAL) {
14395 vty_out(vty,
14396 " neighbor %s remote-as internal\n",
14397 addr);
14398 } else if (peer->as_type == AS_EXTERNAL) {
14399 vty_out(vty,
14400 " neighbor %s remote-as external\n",
14401 addr);
14402 }
14403 }
14404 }
14405
14406 /* local-as */
14407 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14408 vty_out(vty, " neighbor %s local-as %u", addr,
14409 peer->change_local_as);
14410 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14411 vty_out(vty, " no-prepend");
14412 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14413 vty_out(vty, " replace-as");
14414 vty_out(vty, "\n");
14415 }
14416
14417 /* description */
14418 if (peer->desc) {
14419 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14420 }
14421
14422 /* shutdown */
14423 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14424 if (peer->tx_shutdown_message)
14425 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14426 peer->tx_shutdown_message);
14427 else
14428 vty_out(vty, " neighbor %s shutdown\n", addr);
14429 }
14430
14431 /* bfd */
14432 if (peer->bfd_info) {
14433 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14434 bgp_bfd_peer_config_write(vty, peer, addr);
14435 }
14436 }
14437
14438 /* password */
14439 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14440 vty_out(vty, " neighbor %s password %s\n", addr,
14441 peer->password);
14442
14443 /* neighbor solo */
14444 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14445 if (!peer_group_active(peer)) {
14446 vty_out(vty, " neighbor %s solo\n", addr);
14447 }
14448 }
14449
14450 /* BGP port */
14451 if (peer->port != BGP_PORT_DEFAULT) {
14452 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14453 }
14454
14455 /* Local interface name */
14456 if (peer->ifname) {
14457 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14458 }
14459
14460 /* passive */
14461 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14462 vty_out(vty, " neighbor %s passive\n", addr);
14463
14464 /* ebgp-multihop */
14465 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14466 && !(peer->gtsm_hops != 0 && peer->ttl == MAXTTL)) {
14467 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14468 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14469 peer->ttl);
14470 }
14471 }
14472
14473 /* ttl-security hops */
14474 if (peer->gtsm_hops != 0) {
14475 if (!peer_group_active(peer)
14476 || g_peer->gtsm_hops != peer->gtsm_hops) {
14477 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14478 addr, peer->gtsm_hops);
14479 }
14480 }
14481
14482 /* disable-connected-check */
14483 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14484 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14485
14486 /* enforce-first-as */
14487 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14488 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14489
14490 /* update-source */
14491 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14492 if (peer->update_source)
14493 vty_out(vty, " neighbor %s update-source %s\n", addr,
14494 sockunion2str(peer->update_source, buf,
14495 SU_ADDRSTRLEN));
14496 else if (peer->update_if)
14497 vty_out(vty, " neighbor %s update-source %s\n", addr,
14498 peer->update_if);
14499 }
14500
14501 /* advertisement-interval */
14502 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14503 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14504 peer->routeadv);
14505
14506 /* timers */
14507 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14508 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14509 peer->keepalive, peer->holdtime);
14510
14511 /* timers connect */
14512 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14513 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14514 peer->connect);
5d5393b9
DL
14515 /* need special-case handling for changed default values due to
14516 * config profile / version (because there is no "timers bgp connect"
14517 * command, we need to save this per-peer :/)
14518 */
14519 else if (!peer_group_active(peer) && !peer->connect &&
14520 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14521 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14522 peer->bgp->default_connect_retry);
dd65f45e
DL
14523
14524 /* capability dynamic */
14525 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14526 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14527
14528 /* capability extended-nexthop */
14529 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14530 if (!peer->conf_if) {
14531 if (CHECK_FLAG(peer->flags_invert,
14532 PEER_FLAG_CAPABILITY_ENHE))
14533 vty_out(vty,
14534 " no neighbor %s capability extended-nexthop\n",
14535 addr);
14536 else
14537 vty_out(vty,
14538 " neighbor %s capability extended-nexthop\n",
14539 addr);
14540 }
14541 }
14542
14543 /* dont-capability-negotiation */
14544 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14545 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14546
14547 /* override-capability */
14548 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14549 vty_out(vty, " neighbor %s override-capability\n", addr);
14550
14551 /* strict-capability-match */
14552 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14553 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14554
14555 /* Sender side AS path loop detection. */
14556 if (peer->as_path_loop_detection)
14557 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14558 addr);
cfd47646 14559
14560 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14561 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14562
14563 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14564 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14565 vty_out(vty,
14566 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14567 } else if (CHECK_FLAG(
14568 peer->peer_gr_new_status_flag,
14569 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14570 vty_out(vty,
14571 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14572 } else if (
14573 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14574 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14575 && !(CHECK_FLAG(
14576 peer->peer_gr_new_status_flag,
14577 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14578 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14579 addr);
cfd47646 14580 }
14581 }
dd65f45e
DL
14582}
14583
14584/* BGP peer configuration display function. */
14585static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14586 struct peer *peer, afi_t afi, safi_t safi)
14587{
14588 struct peer *g_peer = NULL;
14589 char *addr;
14590 bool flag_scomm, flag_secomm, flag_slcomm;
14591
14592 /* Skip dynamic neighbors. */
14593 if (peer_dynamic_neighbor(peer))
14594 return;
14595
14596 if (peer->conf_if)
14597 addr = peer->conf_if;
14598 else
14599 addr = peer->host;
14600
14601 /************************************
14602 ****** Per AF to the neighbor ******
14603 ************************************/
14604 if (peer_group_active(peer)) {
14605 g_peer = peer->group->conf;
14606
14607 /* If the peer-group is active but peer is not, print a 'no
14608 * activate' */
14609 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14610 vty_out(vty, " no neighbor %s activate\n", addr);
14611 }
14612
14613 /* If the peer-group is not active but peer is, print an
14614 'activate' */
14615 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14616 vty_out(vty, " neighbor %s activate\n", addr);
14617 }
14618 } else {
14619 if (peer->afc[afi][safi]) {
14620 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14621 if (bgp_flag_check(bgp,
14622 BGP_FLAG_NO_DEFAULT_IPV4)) {
14623 vty_out(vty, " neighbor %s activate\n",
14624 addr);
14625 }
14626 } else
14627 vty_out(vty, " neighbor %s activate\n", addr);
14628 } else {
14629 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14630 if (!bgp_flag_check(bgp,
14631 BGP_FLAG_NO_DEFAULT_IPV4)) {
14632 vty_out(vty,
14633 " no neighbor %s activate\n",
14634 addr);
14635 }
14636 }
14637 }
14638 }
14639
14640 /* addpath TX knobs */
14641 if (peergroup_af_addpath_check(peer, afi, safi)) {
14642 switch (peer->addpath_type[afi][safi]) {
14643 case BGP_ADDPATH_ALL:
14644 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14645 addr);
14646 break;
14647 case BGP_ADDPATH_BEST_PER_AS:
14648 vty_out(vty,
14649 " neighbor %s addpath-tx-bestpath-per-AS\n",
14650 addr);
14651 break;
14652 case BGP_ADDPATH_MAX:
14653 case BGP_ADDPATH_NONE:
14654 break;
14655 }
14656 }
14657
14658 /* ORF capability. */
14659 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14660 || peergroup_af_flag_check(peer, afi, safi,
14661 PEER_FLAG_ORF_PREFIX_RM)) {
14662 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14663
14664 if (peergroup_af_flag_check(peer, afi, safi,
14665 PEER_FLAG_ORF_PREFIX_SM)
14666 && peergroup_af_flag_check(peer, afi, safi,
14667 PEER_FLAG_ORF_PREFIX_RM))
14668 vty_out(vty, " both");
14669 else if (peergroup_af_flag_check(peer, afi, safi,
14670 PEER_FLAG_ORF_PREFIX_SM))
14671 vty_out(vty, " send");
14672 else
14673 vty_out(vty, " receive");
14674 vty_out(vty, "\n");
14675 }
14676
14677 /* BGP flag dampening. */
14678 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14679 BGP_CONFIG_DAMPENING))
14680 bgp_config_write_damp(vty, afi, safi);
14681
14682 /* Route reflector client. */
14683 if (peergroup_af_flag_check(peer, afi, safi,
14684 PEER_FLAG_REFLECTOR_CLIENT)) {
14685 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14686 }
14687
14688 /* next-hop-self force */
14689 if (peergroup_af_flag_check(peer, afi, safi,
14690 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14691 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14692 }
14693
14694 /* next-hop-self */
14695 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14696 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14697 }
14698
14699 /* remove-private-AS */
14700 if (peergroup_af_flag_check(peer, afi, safi,
14701 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14702 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14703 addr);
14704 }
14705
14706 else if (peergroup_af_flag_check(peer, afi, safi,
14707 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14708 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14709 addr);
14710 }
14711
14712 else if (peergroup_af_flag_check(peer, afi, safi,
14713 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14714 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14715 }
14716
14717 else if (peergroup_af_flag_check(peer, afi, safi,
14718 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14719 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14720 }
14721
14722 /* as-override */
14723 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14724 vty_out(vty, " neighbor %s as-override\n", addr);
14725 }
14726
14727 /* send-community print. */
14728 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14729 PEER_FLAG_SEND_COMMUNITY);
14730 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14731 PEER_FLAG_SEND_EXT_COMMUNITY);
14732 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14733 PEER_FLAG_SEND_LARGE_COMMUNITY);
14734
14735 if (flag_scomm && flag_secomm && flag_slcomm) {
14736 vty_out(vty, " no neighbor %s send-community all\n", addr);
14737 } else {
14738 if (flag_scomm)
14739 vty_out(vty, " no neighbor %s send-community\n", addr);
14740 if (flag_secomm)
14741 vty_out(vty,
14742 " no neighbor %s send-community extended\n",
14743 addr);
14744
14745 if (flag_slcomm)
14746 vty_out(vty, " no neighbor %s send-community large\n",
14747 addr);
14748 }
14749
14750 /* Default information */
14751 if (peergroup_af_flag_check(peer, afi, safi,
14752 PEER_FLAG_DEFAULT_ORIGINATE)) {
14753 vty_out(vty, " neighbor %s default-originate", addr);
14754
14755 if (peer->default_rmap[afi][safi].name)
14756 vty_out(vty, " route-map %s",
14757 peer->default_rmap[afi][safi].name);
14758
14759 vty_out(vty, "\n");
14760 }
14761
14762 /* Soft reconfiguration inbound. */
14763 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14764 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14765 addr);
14766 }
14767
14768 /* maximum-prefix. */
14769 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14770 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14771 peer->pmax[afi][safi]);
14772
14773 if (peer->pmax_threshold[afi][safi]
14774 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14775 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14776 if (peer_af_flag_check(peer, afi, safi,
14777 PEER_FLAG_MAX_PREFIX_WARNING))
14778 vty_out(vty, " warning-only");
14779 if (peer->pmax_restart[afi][safi])
14780 vty_out(vty, " restart %u",
14781 peer->pmax_restart[afi][safi]);
14782
14783 vty_out(vty, "\n");
14784 }
14785
fde246e8
DA
14786 /* maximum-prefix-out */
14787 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14788 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14789 addr, peer->pmax_out[afi][safi]);
14790
dd65f45e
DL
14791 /* Route server client. */
14792 if (peergroup_af_flag_check(peer, afi, safi,
14793 PEER_FLAG_RSERVER_CLIENT)) {
14794 vty_out(vty, " neighbor %s route-server-client\n", addr);
14795 }
14796
14797 /* Nexthop-local unchanged. */
14798 if (peergroup_af_flag_check(peer, afi, safi,
14799 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14800 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14801 }
14802
14803 /* allowas-in <1-10> */
14804 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14805 if (peer_af_flag_check(peer, afi, safi,
14806 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14807 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14808 } else if (peer->allowas_in[afi][safi] == 3) {
14809 vty_out(vty, " neighbor %s allowas-in\n", addr);
14810 } else {
14811 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14812 peer->allowas_in[afi][safi]);
14813 }
14814 }
14815
14816 /* weight */
14817 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14818 vty_out(vty, " neighbor %s weight %lu\n", addr,
14819 peer->weight[afi][safi]);
14820
14821 /* Filter. */
14822 bgp_config_write_filter(vty, peer, afi, safi);
14823
14824 /* atribute-unchanged. */
14825 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14826 || (safi != SAFI_EVPN
14827 && peer_af_flag_check(peer, afi, safi,
14828 PEER_FLAG_NEXTHOP_UNCHANGED))
14829 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14830
14831 if (!peer_group_active(peer)
14832 || peergroup_af_flag_check(peer, afi, safi,
14833 PEER_FLAG_AS_PATH_UNCHANGED)
14834 || peergroup_af_flag_check(peer, afi, safi,
14835 PEER_FLAG_NEXTHOP_UNCHANGED)
14836 || peergroup_af_flag_check(peer, afi, safi,
14837 PEER_FLAG_MED_UNCHANGED)) {
14838
14839 vty_out(vty,
14840 " neighbor %s attribute-unchanged%s%s%s\n",
14841 addr,
14842 peer_af_flag_check(peer, afi, safi,
14843 PEER_FLAG_AS_PATH_UNCHANGED)
14844 ? " as-path"
14845 : "",
14846 peer_af_flag_check(peer, afi, safi,
14847 PEER_FLAG_NEXTHOP_UNCHANGED)
14848 ? " next-hop"
14849 : "",
14850 peer_af_flag_check(peer, afi, safi,
14851 PEER_FLAG_MED_UNCHANGED)
14852 ? " med"
14853 : "");
14854 }
14855 }
14856}
14857
14858/* Address family based peer configuration display. */
14859static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14860 safi_t safi)
14861{
14862 struct peer *peer;
14863 struct peer_group *group;
14864 struct listnode *node, *nnode;
14865
14866
14867 vty_frame(vty, " !\n address-family ");
14868 if (afi == AFI_IP) {
14869 if (safi == SAFI_UNICAST)
14870 vty_frame(vty, "ipv4 unicast");
14871 else if (safi == SAFI_LABELED_UNICAST)
14872 vty_frame(vty, "ipv4 labeled-unicast");
14873 else if (safi == SAFI_MULTICAST)
14874 vty_frame(vty, "ipv4 multicast");
14875 else if (safi == SAFI_MPLS_VPN)
14876 vty_frame(vty, "ipv4 vpn");
14877 else if (safi == SAFI_ENCAP)
14878 vty_frame(vty, "ipv4 encap");
14879 else if (safi == SAFI_FLOWSPEC)
14880 vty_frame(vty, "ipv4 flowspec");
14881 } else if (afi == AFI_IP6) {
14882 if (safi == SAFI_UNICAST)
14883 vty_frame(vty, "ipv6 unicast");
14884 else if (safi == SAFI_LABELED_UNICAST)
14885 vty_frame(vty, "ipv6 labeled-unicast");
14886 else if (safi == SAFI_MULTICAST)
14887 vty_frame(vty, "ipv6 multicast");
14888 else if (safi == SAFI_MPLS_VPN)
14889 vty_frame(vty, "ipv6 vpn");
14890 else if (safi == SAFI_ENCAP)
14891 vty_frame(vty, "ipv6 encap");
14892 else if (safi == SAFI_FLOWSPEC)
14893 vty_frame(vty, "ipv6 flowspec");
14894 } else if (afi == AFI_L2VPN) {
14895 if (safi == SAFI_EVPN)
14896 vty_frame(vty, "l2vpn evpn");
14897 }
14898 vty_frame(vty, "\n");
14899
14900 bgp_config_write_distance(vty, bgp, afi, safi);
14901
14902 bgp_config_write_network(vty, bgp, afi, safi);
14903
14904 bgp_config_write_redistribute(vty, bgp, afi, safi);
14905
14906 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14907 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14908
14909 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14910 /* Skip dynamic neighbors. */
14911 if (peer_dynamic_neighbor(peer))
14912 continue;
14913
14914 /* Do not display doppelganger peers */
14915 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14916 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14917 }
14918
14919 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14920 bgp_config_write_table_map(vty, bgp, afi, safi);
14921
14922 if (safi == SAFI_EVPN)
14923 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14924
14925 if (safi == SAFI_FLOWSPEC)
14926 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14927
14928 if (safi == SAFI_UNICAST) {
14929 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14930 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14931 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14932
14933 vty_out(vty, " export vpn\n");
14934 }
14935 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14936 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
14937
14938 vty_out(vty, " import vpn\n");
14939 }
14940 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14941 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14942 char *name;
14943
14944 for (ALL_LIST_ELEMENTS_RO(
14945 bgp->vpn_policy[afi].import_vrf, node,
14946 name))
14947 vty_out(vty, " import vrf %s\n", name);
14948 }
14949 }
14950
14951 vty_endframe(vty, " exit-address-family\n");
14952}
14953
14954int bgp_config_write(struct vty *vty)
14955{
14956 struct bgp *bgp;
14957 struct peer_group *group;
14958 struct peer *peer;
14959 struct listnode *node, *nnode;
14960 struct listnode *mnode, *mnnode;
14961
14962 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
14963 vty_out(vty, "bgp route-map delay-timer %u\n",
14964 bm->rmap_update_timer);
14965
14966 /* BGP configuration. */
14967 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
14968
14969 /* skip all auto created vrf as they dont have user config */
14970 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
14971 continue;
14972
14973 /* Router bgp ASN */
14974 vty_out(vty, "router bgp %u", bgp->as);
14975
14976 if (bgp->name)
14977 vty_out(vty, " %s %s",
14978 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
14979 ? "view" : "vrf", bgp->name);
14980 vty_out(vty, "\n");
14981
14982 /* BGP fast-external-failover. */
14983 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
14984 vty_out(vty, " no bgp fast-external-failover\n");
14985
14986 /* BGP router ID. */
14987 if (bgp->router_id_static.s_addr != 0)
14988 vty_out(vty, " bgp router-id %s\n",
14989 inet_ntoa(bgp->router_id_static));
14990
14991 /* BGP log-neighbor-changes. */
14992 if (!!bgp_flag_check(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 14993 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
14994 vty_out(vty, " %sbgp log-neighbor-changes\n",
14995 bgp_flag_check(bgp,
14996 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14997 ? ""
14998 : "no ");
14999
15000 /* BGP configuration. */
15001 if (bgp_flag_check(bgp, BGP_FLAG_ALWAYS_COMPARE_MED))
15002 vty_out(vty, " bgp always-compare-med\n");
15003
15004 /* RFC8212 default eBGP policy. */
15005 if (bgp->ebgp_requires_policy
15006 == DEFAULT_EBGP_POLICY_ENABLED)
15007 vty_out(vty, " bgp ebgp-requires-policy\n");
15008
15009 /* draft-ietf-idr-deprecate-as-set-confed-set */
15010 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
15011 vty_out(vty, " bgp reject-as-sets\n");
15012
15013 /* BGP default ipv4-unicast. */
15014 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4))
15015 vty_out(vty, " no bgp default ipv4-unicast\n");
15016
15017 /* BGP default local-preference. */
15018 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15019 vty_out(vty, " bgp default local-preference %u\n",
15020 bgp->default_local_pref);
15021
15022 /* BGP default show-hostname */
15023 if (!!bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15024 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e
DL
15025 vty_out(vty, " %sbgp default show-hostname\n",
15026 bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
15027 ? ""
15028 : "no ");
15029
15030 /* BGP default subgroup-pkt-queue-max. */
15031 if (bgp->default_subgroup_pkt_queue_max
15032 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15033 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15034 bgp->default_subgroup_pkt_queue_max);
15035
15036 /* BGP client-to-client reflection. */
15037 if (bgp_flag_check(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15038 vty_out(vty, " no bgp client-to-client reflection\n");
15039
15040 /* BGP cluster ID. */
15041 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15042 vty_out(vty, " bgp cluster-id %s\n",
15043 inet_ntoa(bgp->cluster_id));
15044
15045 /* Disable ebgp connected nexthop check */
15046 if (bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15047 vty_out(vty,
15048 " bgp disable-ebgp-connected-route-check\n");
15049
15050 /* Confederation identifier*/
15051 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15052 vty_out(vty, " bgp confederation identifier %u\n",
15053 bgp->confed_id);
15054
15055 /* Confederation peer */
15056 if (bgp->confed_peers_cnt > 0) {
15057 int i;
15058
15059 vty_out(vty, " bgp confederation peers");
15060
15061 for (i = 0; i < bgp->confed_peers_cnt; i++)
15062 vty_out(vty, " %u", bgp->confed_peers[i]);
15063
15064 vty_out(vty, "\n");
15065 }
15066
15067 /* BGP deterministic-med. */
15068 if (!!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15069 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e
DL
15070 vty_out(vty, " %sbgp deterministic-med\n",
15071 bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
15072 ? ""
15073 : "no ");
15074
15075 /* BGP update-delay. */
15076 bgp_config_write_update_delay(vty, bgp);
15077
15078 if (bgp->v_maxmed_onstartup
15079 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15080 vty_out(vty, " bgp max-med on-startup %u",
15081 bgp->v_maxmed_onstartup);
15082 if (bgp->maxmed_onstartup_value
15083 != BGP_MAXMED_VALUE_DEFAULT)
15084 vty_out(vty, " %u",
15085 bgp->maxmed_onstartup_value);
15086 vty_out(vty, "\n");
15087 }
15088 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15089 vty_out(vty, " bgp max-med administrative");
15090 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15091 vty_out(vty, " %u", bgp->maxmed_admin_value);
15092 vty_out(vty, "\n");
15093 }
15094
15095 /* write quanta */
15096 bgp_config_write_wpkt_quanta(vty, bgp);
15097 /* read quanta */
15098 bgp_config_write_rpkt_quanta(vty, bgp);
15099
15100 /* coalesce time */
15101 bgp_config_write_coalesce_time(vty, bgp);
15102
15103 /* BGP graceful-restart. */
15104 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15105 vty_out(vty,
15106 " bgp graceful-restart stalepath-time %u\n",
15107 bgp->stalepath_time);
cfd47646 15108
dd65f45e
DL
15109 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15110 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15111 bgp->restart_time);
cfd47646 15112
15113 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15114 vty_out(vty,
15115 " bgp graceful-restart select-defer-time %u\n",
15116 bgp->select_defer_time);
15117
15118 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15119 vty_out(vty, " bgp graceful-restart\n");
15120
cfd47646 15121 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15122 vty_out(vty, " bgp graceful-restart-disable\n");
15123
dd65f45e
DL
15124 /* BGP graceful-shutdown */
15125 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN))
15126 vty_out(vty, " bgp graceful-shutdown\n");
15127
15128 /* BGP graceful-restart Preserve State F bit. */
15129 if (bgp_flag_check(bgp, BGP_FLAG_GR_PRESERVE_FWD))
15130 vty_out(vty,
15131 " bgp graceful-restart preserve-fw-state\n");
15132
dc95985f 15133 /* Stale timer for RIB */
15134 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15135 vty_out(vty,
15136 " bgp graceful-restart rib-stale-time %u\n",
15137 bgp->rib_stale_time);
15138
dd65f45e
DL
15139 /* BGP bestpath method. */
15140 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
15141 vty_out(vty, " bgp bestpath as-path ignore\n");
15142 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
15143 vty_out(vty, " bgp bestpath as-path confed\n");
15144
15145 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15146 if (bgp_flag_check(bgp,
15147 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
15148 vty_out(vty,
15149 " bgp bestpath as-path multipath-relax as-set\n");
15150 } else {
15151 vty_out(vty,
15152 " bgp bestpath as-path multipath-relax\n");
15153 }
15154 }
15155
15156 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
15157 vty_out(vty,
15158 " bgp route-reflector allow-outbound-policy\n");
15159 }
15160 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
15161 vty_out(vty, " bgp bestpath compare-routerid\n");
15162 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
15163 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
15164 vty_out(vty, " bgp bestpath med");
15165 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
15166 vty_out(vty, " confed");
15167 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
15168 vty_out(vty, " missing-as-worst");
15169 vty_out(vty, "\n");
15170 }
15171
15172 /* BGP network import check. */
15173 if (!!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15174 != SAVE_BGP_IMPORT_CHECK)
dd65f45e
DL
15175 vty_out(vty, " %sbgp network import-check\n",
15176 bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
15177 ? ""
15178 : "no ");
15179
15180 /* BGP timers configuration. */
5d5393b9
DL
15181 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15182 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15183 vty_out(vty, " timers bgp %u %u\n",
15184 bgp->default_keepalive, bgp->default_holdtime);
15185
15186 /* peer-group */
15187 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15188 bgp_config_write_peer_global(vty, bgp, group->conf);
15189 }
15190
15191 /* Normal neighbor configuration. */
15192 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15193 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15194 bgp_config_write_peer_global(vty, bgp, peer);
15195 }
15196
15197 /* listen range and limit for dynamic BGP neighbors */
15198 bgp_config_write_listen(vty, bgp);
15199
15200 /*
15201 * BGP default autoshutdown neighbors
15202 *
15203 * This must be placed after any peer and peer-group
15204 * configuration, to avoid setting all peers to shutdown after
15205 * a daemon restart, which is undesired behavior. (see #2286)
15206 */
15207 if (bgp->autoshutdown)
15208 vty_out(vty, " bgp default shutdown\n");
15209
15210 /* IPv4 unicast configuration. */
15211 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15212
15213 /* IPv4 multicast configuration. */
15214 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15215
15216 /* IPv4 labeled-unicast configuration. */
15217 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15218
15219 /* IPv4 VPN configuration. */
15220 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15221
15222 /* ENCAPv4 configuration. */
15223 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15224
15225 /* FLOWSPEC v4 configuration. */
15226 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15227
15228 /* IPv6 unicast configuration. */
15229 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15230
15231 /* IPv6 multicast configuration. */
15232 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15233
15234 /* IPv6 labeled-unicast configuration. */
15235 bgp_config_write_family(vty, bgp, AFI_IP6,
15236 SAFI_LABELED_UNICAST);
15237
15238 /* IPv6 VPN configuration. */
15239 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15240
15241 /* ENCAPv6 configuration. */
15242 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15243
15244 /* FLOWSPEC v6 configuration. */
15245 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15246
15247 /* EVPN configuration. */
15248 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15249
15250 hook_call(bgp_inst_config_write, bgp, vty);
15251
15252#if ENABLE_BGP_VNC
15253 bgp_rfapi_cfg_write(vty, bgp);
15254#endif
15255
15256 vty_out(vty, "!\n");
15257 }
15258 return 0;
15259}
15260
ddb5b488 15261
718e3744 15262/* BGP node structure. */
d62a17ae 15263static struct cmd_node bgp_node = {
9d303b37 15264 BGP_NODE, "%s(config-router)# ", 1,
718e3744 15265};
15266
d62a17ae 15267static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 15268 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 15269};
15270
d62a17ae 15271static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 15272 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 15273};
15274
d62a17ae 15275static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 15276 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15277};
15278
d62a17ae 15279static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 15280 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 15281};
15282
d62a17ae 15283static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 15284 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 15285};
15286
d62a17ae 15287static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 15288 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15289};
15290
d62a17ae 15291static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15292 "%s(config-router-af)# ", 1};
6b0655a2 15293
d62a17ae 15294static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15295 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 15296
d62a17ae 15297static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15298 "%s(config-router-evpn)# ", 1};
4e0b7b6d 15299
d62a17ae 15300static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15301 "%s(config-router-af-vni)# ", 1};
90e60aa7 15302
7c40bf39 15303static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15304 "%s(config-router-af)# ", 1};
15305
15306static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15307 "%s(config-router-af-vpnv6)# ", 1};
15308
d62a17ae 15309static void community_list_vty(void);
1f8ae70b 15310
d62a17ae 15311static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15312{
d62a17ae 15313 struct bgp *bgp;
15314 struct peer *peer;
d62a17ae 15315 struct listnode *lnbgp, *lnpeer;
b8a815e5 15316
d62a17ae 15317 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15318 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15319 /* only provide suggestions on the appropriate input
15320 * token type,
15321 * they'll otherwise show up multiple times */
15322 enum cmd_token_type match_type;
15323 char *name = peer->host;
d48ed3e0 15324
d62a17ae 15325 if (peer->conf_if) {
15326 match_type = VARIABLE_TKN;
15327 name = peer->conf_if;
15328 } else if (strchr(peer->host, ':'))
15329 match_type = IPV6_TKN;
15330 else
15331 match_type = IPV4_TKN;
d48ed3e0 15332
d62a17ae 15333 if (token->type != match_type)
15334 continue;
d48ed3e0 15335
d62a17ae 15336 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15337 }
d62a17ae 15338 }
b8a815e5
DL
15339}
15340
15341static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15342 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15343 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15344 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15345 {.completions = NULL}};
15346
47a306a0
DS
15347static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15348{
15349 struct bgp *bgp;
15350 struct peer_group *group;
15351 struct listnode *lnbgp, *lnpeer;
15352
15353 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15354 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15355 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15356 group->name));
15357 }
15358}
15359
15360static const struct cmd_variable_handler bgp_var_peergroup[] = {
15361 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15362 {.completions = NULL} };
15363
d62a17ae 15364void bgp_vty_init(void)
15365{
15366 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15367 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15368
15369 /* Install bgp top node. */
15370 install_node(&bgp_node, bgp_config_write);
15371 install_node(&bgp_ipv4_unicast_node, NULL);
15372 install_node(&bgp_ipv4_multicast_node, NULL);
15373 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15374 install_node(&bgp_ipv6_unicast_node, NULL);
15375 install_node(&bgp_ipv6_multicast_node, NULL);
15376 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15377 install_node(&bgp_vpnv4_node, NULL);
15378 install_node(&bgp_vpnv6_node, NULL);
15379 install_node(&bgp_evpn_node, NULL);
15380 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 15381 install_node(&bgp_flowspecv4_node, NULL);
15382 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 15383
15384 /* Install default VTY commands to new nodes. */
15385 install_default(BGP_NODE);
15386 install_default(BGP_IPV4_NODE);
15387 install_default(BGP_IPV4M_NODE);
15388 install_default(BGP_IPV4L_NODE);
15389 install_default(BGP_IPV6_NODE);
15390 install_default(BGP_IPV6M_NODE);
15391 install_default(BGP_IPV6L_NODE);
15392 install_default(BGP_VPNV4_NODE);
15393 install_default(BGP_VPNV6_NODE);
7c40bf39 15394 install_default(BGP_FLOWSPECV4_NODE);
15395 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15396 install_default(BGP_EVPN_NODE);
15397 install_default(BGP_EVPN_VNI_NODE);
15398
8029b216
AK
15399 /* "bgp local-mac" hidden commands. */
15400 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15401 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15402
d62a17ae 15403 /* bgp route-map delay-timer commands. */
15404 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15405 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15406
15407 /* Dummy commands (Currently not supported) */
15408 install_element(BGP_NODE, &no_synchronization_cmd);
15409 install_element(BGP_NODE, &no_auto_summary_cmd);
15410
15411 /* "router bgp" commands. */
15412 install_element(CONFIG_NODE, &router_bgp_cmd);
15413
15414 /* "no router bgp" commands. */
15415 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15416
15417 /* "bgp router-id" commands. */
15418 install_element(BGP_NODE, &bgp_router_id_cmd);
15419 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15420
15421 /* "bgp cluster-id" commands. */
15422 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15423 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15424
15425 /* "bgp confederation" commands. */
15426 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15427 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15428
15429 /* "bgp confederation peers" commands. */
15430 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15431 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15432
15433 /* bgp max-med command */
15434 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15435 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15436 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15437 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15438 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15439
15440 /* bgp disable-ebgp-connected-nh-check */
15441 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15442 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15443
15444 /* bgp update-delay command */
15445 install_element(BGP_NODE, &bgp_update_delay_cmd);
15446 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15447 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15448
15449 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15450 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15451
15452 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15453 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15454
15455 /* "maximum-paths" commands. */
15456 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15457 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15458 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15459 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15460 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15461 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15462 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15463 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15464 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15465 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15466 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15467 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15468 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15469 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15470 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15471
15472 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15473 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15474 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15475 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15476 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15477
15478 /* "timers bgp" commands. */
15479 install_element(BGP_NODE, &bgp_timers_cmd);
15480 install_element(BGP_NODE, &no_bgp_timers_cmd);
15481
15482 /* route-map delay-timer commands - per instance for backwards compat.
15483 */
15484 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15485 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15486
15487 /* "bgp client-to-client reflection" commands */
15488 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15489 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15490
15491 /* "bgp always-compare-med" commands */
15492 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15493 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15494
9dac9fc8
DA
15495 /* bgp ebgp-requires-policy */
15496 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15497 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15498
fb29348a
DA
15499 /* bgp reject-as-sets */
15500 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15501 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15502
d62a17ae 15503 /* "bgp deterministic-med" commands */
15504 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15505 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15506
055679e9 15507 /* "bgp graceful-restart" command */
15508 install_element(BGP_NODE,
15509 &bgp_graceful_restart_cmd);
15510 install_element(BGP_NODE,
15511 &no_bgp_graceful_restart_cmd);
15512
15513 /* "bgp graceful-restart-disable" command */
15514 install_element(BGP_NODE,
15515 &bgp_graceful_restart_disable_cmd);
15516 install_element(BGP_NODE,
15517 &no_bgp_graceful_restart_disable_cmd);
15518
15519 /* "neighbor a:b:c:d graceful-restart" command */
15520 install_element(BGP_NODE,
15521 &bgp_neighbor_graceful_restart_set_cmd);
15522 install_element(BGP_NODE,
15523 &no_bgp_neighbor_graceful_restart_set_cmd);
15524
15525 /* "neighbor a:b:c:d graceful-restart-disable" command */
15526 install_element(BGP_NODE,
15527 &bgp_neighbor_graceful_restart_disable_set_cmd);
15528 install_element(BGP_NODE,
15529 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15530
15531 /* "neighbor a:b:c:d graceful-restart-helper" command */
15532 install_element(BGP_NODE,
15533 &bgp_neighbor_graceful_restart_helper_set_cmd);
15534 install_element(BGP_NODE,
15535 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15536
d62a17ae 15537 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15538 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15539 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15540 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15541 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15542 install_element(BGP_NODE,
15543 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15544 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15545 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15546
d6e3c15b 15547 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15548 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15549 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15550 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15551
7f323236
DW
15552 /* "bgp graceful-shutdown" commands */
15553 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15554 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15555
d62a17ae 15556 /* "bgp fast-external-failover" commands */
15557 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15558 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15559
d62a17ae 15560 /* "bgp bestpath compare-routerid" commands */
15561 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15562 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15563
15564 /* "bgp bestpath as-path ignore" commands */
15565 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15566 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15567
15568 /* "bgp bestpath as-path confed" commands */
15569 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15570 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15571
15572 /* "bgp bestpath as-path multipath-relax" commands */
15573 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15574 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15575
15576 /* "bgp log-neighbor-changes" commands */
15577 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15578 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15579
15580 /* "bgp bestpath med" commands */
15581 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15582 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15583
15584 /* "no bgp default ipv4-unicast" commands. */
15585 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15586 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15587
15588 /* "bgp network import-check" commands. */
15589 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15590 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15591 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15592
15593 /* "bgp default local-preference" commands. */
15594 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15595 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15596
15597 /* bgp default show-hostname */
15598 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15599 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15600
15601 /* "bgp default subgroup-pkt-queue-max" commands. */
15602 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15603 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15604
15605 /* bgp ibgp-allow-policy-mods command */
15606 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15607 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15608
15609 /* "bgp listen limit" commands. */
15610 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15611 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15612
15613 /* "bgp listen range" commands. */
15614 install_element(BGP_NODE, &bgp_listen_range_cmd);
15615 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15616
8175f54a 15617 /* "bgp default shutdown" command */
f26845f9
QY
15618 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15619
d62a17ae 15620 /* "neighbor remote-as" commands. */
15621 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15622 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15623 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15624 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15625 install_element(BGP_NODE,
15626 &neighbor_interface_v6only_config_remote_as_cmd);
15627 install_element(BGP_NODE, &no_neighbor_cmd);
15628 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15629
15630 /* "neighbor peer-group" commands. */
15631 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15632 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15633 install_element(BGP_NODE,
15634 &no_neighbor_interface_peer_group_remote_as_cmd);
15635
15636 /* "neighbor local-as" commands. */
15637 install_element(BGP_NODE, &neighbor_local_as_cmd);
15638 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15639 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15640 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15641
15642 /* "neighbor solo" commands. */
15643 install_element(BGP_NODE, &neighbor_solo_cmd);
15644 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15645
15646 /* "neighbor password" commands. */
15647 install_element(BGP_NODE, &neighbor_password_cmd);
15648 install_element(BGP_NODE, &no_neighbor_password_cmd);
15649
15650 /* "neighbor activate" commands. */
15651 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15652 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15653 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15654 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15655 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15656 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15657 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15658 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15659 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 15660 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15661 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 15662 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15663
15664 /* "no neighbor activate" commands. */
15665 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15666 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15667 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15668 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15669 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15670 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15671 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15672 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15673 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 15674 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15675 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 15676 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15677
15678 /* "neighbor peer-group" set commands. */
15679 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15680 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15681 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15682 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15683 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15684 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15685 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15686 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 15687 install_element(BGP_FLOWSPECV4_NODE,
15688 &neighbor_set_peer_group_hidden_cmd);
15689 install_element(BGP_FLOWSPECV6_NODE,
15690 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 15691
15692 /* "no neighbor peer-group unset" commands. */
15693 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15694 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15695 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15696 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15697 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15698 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15699 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15700 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 15701 install_element(BGP_FLOWSPECV4_NODE,
15702 &no_neighbor_set_peer_group_hidden_cmd);
15703 install_element(BGP_FLOWSPECV6_NODE,
15704 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 15705
15706 /* "neighbor softreconfiguration inbound" commands.*/
15707 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15708 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15709 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15710 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15711 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15712 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15713 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15714 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15715 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15716 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15717 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15718 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15719 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15720 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15721 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15722 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15723 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15724 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 15725 install_element(BGP_FLOWSPECV4_NODE,
15726 &neighbor_soft_reconfiguration_cmd);
15727 install_element(BGP_FLOWSPECV4_NODE,
15728 &no_neighbor_soft_reconfiguration_cmd);
15729 install_element(BGP_FLOWSPECV6_NODE,
15730 &neighbor_soft_reconfiguration_cmd);
15731 install_element(BGP_FLOWSPECV6_NODE,
15732 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
15733 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15734 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 15735
15736 /* "neighbor attribute-unchanged" commands. */
15737 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15738 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15739 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15740 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15741 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15742 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15743 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15744 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15745 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15746 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15747 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15748 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15749 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15750 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15751 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15752 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15753 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15754 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15755
15756 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15757 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15758
15759 /* "nexthop-local unchanged" commands */
15760 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15761 install_element(BGP_IPV6_NODE,
15762 &no_neighbor_nexthop_local_unchanged_cmd);
15763
15764 /* "neighbor next-hop-self" commands. */
15765 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15766 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15767 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15768 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15769 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15770 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15771 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15772 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15773 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15774 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15775 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15776 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15777 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15778 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15779 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15780 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15781 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15782 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
15783 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15784 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 15785
15786 /* "neighbor next-hop-self force" commands. */
15787 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15788 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
15789 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15790 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15791 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15792 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15793 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15794 install_element(BGP_IPV4_NODE,
15795 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15796 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15797 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15798 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15799 install_element(BGP_IPV4M_NODE,
15800 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15801 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15802 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15803 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15804 install_element(BGP_IPV4L_NODE,
15805 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15806 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15807 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15808 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15809 install_element(BGP_IPV6_NODE,
15810 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15811 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15812 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15813 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15814 install_element(BGP_IPV6M_NODE,
15815 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15816 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15817 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15818 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15819 install_element(BGP_IPV6L_NODE,
15820 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15821 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15822 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15823 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15824 install_element(BGP_VPNV4_NODE,
15825 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15826 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15827 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15828 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15829 install_element(BGP_VPNV6_NODE,
15830 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15831
15832 /* "neighbor as-override" commands. */
15833 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15834 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15835 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15836 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15837 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15838 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15839 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15840 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15841 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15842 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15843 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15844 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15845 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15846 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15847 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15848 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15849 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15850 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15851
15852 /* "neighbor remove-private-AS" commands. */
15853 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15854 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15855 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15856 install_element(BGP_NODE,
15857 &no_neighbor_remove_private_as_all_hidden_cmd);
15858 install_element(BGP_NODE,
15859 &neighbor_remove_private_as_replace_as_hidden_cmd);
15860 install_element(BGP_NODE,
15861 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15862 install_element(BGP_NODE,
15863 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15864 install_element(
15865 BGP_NODE,
15866 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15867 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15868 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15869 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15870 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15871 install_element(BGP_IPV4_NODE,
15872 &neighbor_remove_private_as_replace_as_cmd);
15873 install_element(BGP_IPV4_NODE,
15874 &no_neighbor_remove_private_as_replace_as_cmd);
15875 install_element(BGP_IPV4_NODE,
15876 &neighbor_remove_private_as_all_replace_as_cmd);
15877 install_element(BGP_IPV4_NODE,
15878 &no_neighbor_remove_private_as_all_replace_as_cmd);
15879 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15880 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15881 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15882 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15883 install_element(BGP_IPV4M_NODE,
15884 &neighbor_remove_private_as_replace_as_cmd);
15885 install_element(BGP_IPV4M_NODE,
15886 &no_neighbor_remove_private_as_replace_as_cmd);
15887 install_element(BGP_IPV4M_NODE,
15888 &neighbor_remove_private_as_all_replace_as_cmd);
15889 install_element(BGP_IPV4M_NODE,
15890 &no_neighbor_remove_private_as_all_replace_as_cmd);
15891 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15892 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15893 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15894 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15895 install_element(BGP_IPV4L_NODE,
15896 &neighbor_remove_private_as_replace_as_cmd);
15897 install_element(BGP_IPV4L_NODE,
15898 &no_neighbor_remove_private_as_replace_as_cmd);
15899 install_element(BGP_IPV4L_NODE,
15900 &neighbor_remove_private_as_all_replace_as_cmd);
15901 install_element(BGP_IPV4L_NODE,
15902 &no_neighbor_remove_private_as_all_replace_as_cmd);
15903 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15904 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15905 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15906 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15907 install_element(BGP_IPV6_NODE,
15908 &neighbor_remove_private_as_replace_as_cmd);
15909 install_element(BGP_IPV6_NODE,
15910 &no_neighbor_remove_private_as_replace_as_cmd);
15911 install_element(BGP_IPV6_NODE,
15912 &neighbor_remove_private_as_all_replace_as_cmd);
15913 install_element(BGP_IPV6_NODE,
15914 &no_neighbor_remove_private_as_all_replace_as_cmd);
15915 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15916 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15917 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15918 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15919 install_element(BGP_IPV6M_NODE,
15920 &neighbor_remove_private_as_replace_as_cmd);
15921 install_element(BGP_IPV6M_NODE,
15922 &no_neighbor_remove_private_as_replace_as_cmd);
15923 install_element(BGP_IPV6M_NODE,
15924 &neighbor_remove_private_as_all_replace_as_cmd);
15925 install_element(BGP_IPV6M_NODE,
15926 &no_neighbor_remove_private_as_all_replace_as_cmd);
15927 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15928 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
15929 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
15930 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
15931 install_element(BGP_IPV6L_NODE,
15932 &neighbor_remove_private_as_replace_as_cmd);
15933 install_element(BGP_IPV6L_NODE,
15934 &no_neighbor_remove_private_as_replace_as_cmd);
15935 install_element(BGP_IPV6L_NODE,
15936 &neighbor_remove_private_as_all_replace_as_cmd);
15937 install_element(BGP_IPV6L_NODE,
15938 &no_neighbor_remove_private_as_all_replace_as_cmd);
15939 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
15940 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
15941 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
15942 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15943 install_element(BGP_VPNV4_NODE,
15944 &neighbor_remove_private_as_replace_as_cmd);
15945 install_element(BGP_VPNV4_NODE,
15946 &no_neighbor_remove_private_as_replace_as_cmd);
15947 install_element(BGP_VPNV4_NODE,
15948 &neighbor_remove_private_as_all_replace_as_cmd);
15949 install_element(BGP_VPNV4_NODE,
15950 &no_neighbor_remove_private_as_all_replace_as_cmd);
15951 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
15952 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
15953 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
15954 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15955 install_element(BGP_VPNV6_NODE,
15956 &neighbor_remove_private_as_replace_as_cmd);
15957 install_element(BGP_VPNV6_NODE,
15958 &no_neighbor_remove_private_as_replace_as_cmd);
15959 install_element(BGP_VPNV6_NODE,
15960 &neighbor_remove_private_as_all_replace_as_cmd);
15961 install_element(BGP_VPNV6_NODE,
15962 &no_neighbor_remove_private_as_all_replace_as_cmd);
15963
15964 /* "neighbor send-community" commands.*/
15965 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
15966 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
15967 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
15968 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
15969 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
15970 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
15971 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
15972 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
15973 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
15974 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
15975 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
15976 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
15977 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
15978 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
15979 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
15980 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
15981 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
15982 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
15983 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
15984 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
15985 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
15986 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
15987 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
15988 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
15989 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
15990 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
15991 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
15992 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
15993 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
15994 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
15995 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
15996 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
15997 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
15998 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
15999 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
16000 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16001
16002 /* "neighbor route-reflector" commands.*/
16003 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16004 install_element(BGP_NODE,
16005 &no_neighbor_route_reflector_client_hidden_cmd);
16006 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16007 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16008 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16009 install_element(BGP_IPV4M_NODE,
16010 &no_neighbor_route_reflector_client_cmd);
16011 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16012 install_element(BGP_IPV4L_NODE,
16013 &no_neighbor_route_reflector_client_cmd);
16014 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16015 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16016 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16017 install_element(BGP_IPV6M_NODE,
16018 &no_neighbor_route_reflector_client_cmd);
16019 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16020 install_element(BGP_IPV6L_NODE,
16021 &no_neighbor_route_reflector_client_cmd);
16022 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16023 install_element(BGP_VPNV4_NODE,
16024 &no_neighbor_route_reflector_client_cmd);
16025 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16026 install_element(BGP_VPNV6_NODE,
16027 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16028 install_element(BGP_FLOWSPECV4_NODE,
16029 &neighbor_route_reflector_client_cmd);
16030 install_element(BGP_FLOWSPECV4_NODE,
16031 &no_neighbor_route_reflector_client_cmd);
16032 install_element(BGP_FLOWSPECV6_NODE,
16033 &neighbor_route_reflector_client_cmd);
16034 install_element(BGP_FLOWSPECV6_NODE,
16035 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16036 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16037 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16038
16039 /* "neighbor route-server" commands.*/
16040 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16041 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16042 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16043 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16044 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16045 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16046 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16047 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16048 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16049 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16050 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16051 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16052 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16053 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16054 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16055 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16056 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16057 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16058 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16059 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16060 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16061 install_element(BGP_FLOWSPECV4_NODE,
16062 &no_neighbor_route_server_client_cmd);
16063 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16064 install_element(BGP_FLOWSPECV6_NODE,
16065 &no_neighbor_route_server_client_cmd);
d62a17ae 16066
16067 /* "neighbor addpath-tx-all-paths" commands.*/
16068 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16069 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16070 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16071 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16072 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16073 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16074 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16075 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16076 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16077 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16078 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16079 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16080 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16081 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16082 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16083 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16084 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16085 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16086
16087 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16088 install_element(BGP_NODE,
16089 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16090 install_element(BGP_NODE,
16091 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16092 install_element(BGP_IPV4_NODE,
16093 &neighbor_addpath_tx_bestpath_per_as_cmd);
16094 install_element(BGP_IPV4_NODE,
16095 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16096 install_element(BGP_IPV4M_NODE,
16097 &neighbor_addpath_tx_bestpath_per_as_cmd);
16098 install_element(BGP_IPV4M_NODE,
16099 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16100 install_element(BGP_IPV4L_NODE,
16101 &neighbor_addpath_tx_bestpath_per_as_cmd);
16102 install_element(BGP_IPV4L_NODE,
16103 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16104 install_element(BGP_IPV6_NODE,
16105 &neighbor_addpath_tx_bestpath_per_as_cmd);
16106 install_element(BGP_IPV6_NODE,
16107 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16108 install_element(BGP_IPV6M_NODE,
16109 &neighbor_addpath_tx_bestpath_per_as_cmd);
16110 install_element(BGP_IPV6M_NODE,
16111 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16112 install_element(BGP_IPV6L_NODE,
16113 &neighbor_addpath_tx_bestpath_per_as_cmd);
16114 install_element(BGP_IPV6L_NODE,
16115 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16116 install_element(BGP_VPNV4_NODE,
16117 &neighbor_addpath_tx_bestpath_per_as_cmd);
16118 install_element(BGP_VPNV4_NODE,
16119 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16120 install_element(BGP_VPNV6_NODE,
16121 &neighbor_addpath_tx_bestpath_per_as_cmd);
16122 install_element(BGP_VPNV6_NODE,
16123 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16124
2b31007c
RZ
16125 /* "neighbor sender-as-path-loop-detection" commands. */
16126 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16127 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16128
d62a17ae 16129 /* "neighbor passive" commands. */
16130 install_element(BGP_NODE, &neighbor_passive_cmd);
16131 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16132
16133
16134 /* "neighbor shutdown" commands. */
16135 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16136 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16137 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16138 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16139
16140 /* "neighbor capability extended-nexthop" commands.*/
16141 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16142 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16143
16144 /* "neighbor capability orf prefix-list" commands.*/
16145 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16146 install_element(BGP_NODE,
16147 &no_neighbor_capability_orf_prefix_hidden_cmd);
16148 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16149 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16150 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16151 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16152 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16153 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16154 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16155 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16156 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16157 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16158 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16159 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16160
16161 /* "neighbor capability dynamic" commands.*/
16162 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16163 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16164
16165 /* "neighbor dont-capability-negotiate" commands. */
16166 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16167 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16168
16169 /* "neighbor ebgp-multihop" commands. */
16170 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16171 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16172 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16173
16174 /* "neighbor disable-connected-check" commands. */
16175 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16176 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16177
47cbc09b
PM
16178 /* "neighbor enforce-first-as" commands. */
16179 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16180 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16181
d62a17ae 16182 /* "neighbor description" commands. */
16183 install_element(BGP_NODE, &neighbor_description_cmd);
16184 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16185 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16186
16187 /* "neighbor update-source" commands. "*/
16188 install_element(BGP_NODE, &neighbor_update_source_cmd);
16189 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16190
16191 /* "neighbor default-originate" commands. */
16192 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16193 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16194 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16195 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16196 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16197 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16198 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16199 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16200 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16201 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16202 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16203 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16204 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16205 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16206 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16207 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16208 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16209 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16210 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16211 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16212 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16213
16214 /* "neighbor port" commands. */
16215 install_element(BGP_NODE, &neighbor_port_cmd);
16216 install_element(BGP_NODE, &no_neighbor_port_cmd);
16217
16218 /* "neighbor weight" commands. */
16219 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16220 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16221
16222 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16223 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16224 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16225 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16226 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16227 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16228 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16229 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16230 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16231 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16232 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16233 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16234 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16235 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16236 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16237 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16238
16239 /* "neighbor override-capability" commands. */
16240 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16241 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16242
16243 /* "neighbor strict-capability-match" commands. */
16244 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16245 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16246
16247 /* "neighbor timers" commands. */
16248 install_element(BGP_NODE, &neighbor_timers_cmd);
16249 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16250
16251 /* "neighbor timers connect" commands. */
16252 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16253 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16254
16255 /* "neighbor advertisement-interval" commands. */
16256 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16257 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16258
16259 /* "neighbor interface" commands. */
16260 install_element(BGP_NODE, &neighbor_interface_cmd);
16261 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16262
16263 /* "neighbor distribute" commands. */
16264 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16265 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16266 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16267 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16268 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16269 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16270 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16271 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16272 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16273 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16274 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16275 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16276 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16277 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16278 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16279 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16280 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16281 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16282
16283 /* "neighbor prefix-list" commands. */
16284 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16285 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16286 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16287 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16288 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16289 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16290 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16291 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16292 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16293 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16294 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16295 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16296 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16297 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16298 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16299 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16300 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16301 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16302 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16303 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16304 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16305 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16306
16307 /* "neighbor filter-list" commands. */
16308 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16309 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16310 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16311 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16312 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16313 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16314 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16315 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16316 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16317 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16318 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16319 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16320 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16321 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16322 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16323 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16324 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16325 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16326 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16327 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16328 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16329 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16330
16331 /* "neighbor route-map" commands. */
16332 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16333 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16334 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16335 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16336 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16337 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16338 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16339 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16340 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16341 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16342 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16343 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16344 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16345 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16346 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16347 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16348 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16349 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16350 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16351 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16352 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16353 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16354 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16355 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16356
16357 /* "neighbor unsuppress-map" commands. */
16358 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16359 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16360 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16361 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16362 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16363 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16364 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16365 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16366 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16367 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16368 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16369 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16370 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16371 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16372 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16373 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16374 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16375 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16376
fde246e8
DA
16377 /* neighbor maximum-prefix-out commands. */
16378 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16379 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16380 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16381 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16382 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16383 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16384 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16385 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16386 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16387 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16388 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16389 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16390 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16391 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16392 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16393 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16394 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16395 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16396
d62a17ae 16397 /* "neighbor maximum-prefix" commands. */
16398 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16399 install_element(BGP_NODE,
16400 &neighbor_maximum_prefix_threshold_hidden_cmd);
16401 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16402 install_element(BGP_NODE,
16403 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16404 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16405 install_element(BGP_NODE,
16406 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16407 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16408 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16409 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16410 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16411 install_element(BGP_IPV4_NODE,
16412 &neighbor_maximum_prefix_threshold_warning_cmd);
16413 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16414 install_element(BGP_IPV4_NODE,
16415 &neighbor_maximum_prefix_threshold_restart_cmd);
16416 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16417 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16418 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16419 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16420 install_element(BGP_IPV4M_NODE,
16421 &neighbor_maximum_prefix_threshold_warning_cmd);
16422 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16423 install_element(BGP_IPV4M_NODE,
16424 &neighbor_maximum_prefix_threshold_restart_cmd);
16425 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16426 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16427 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16428 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16429 install_element(BGP_IPV4L_NODE,
16430 &neighbor_maximum_prefix_threshold_warning_cmd);
16431 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16432 install_element(BGP_IPV4L_NODE,
16433 &neighbor_maximum_prefix_threshold_restart_cmd);
16434 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16435 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16436 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16437 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16438 install_element(BGP_IPV6_NODE,
16439 &neighbor_maximum_prefix_threshold_warning_cmd);
16440 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16441 install_element(BGP_IPV6_NODE,
16442 &neighbor_maximum_prefix_threshold_restart_cmd);
16443 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16444 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16445 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16446 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16447 install_element(BGP_IPV6M_NODE,
16448 &neighbor_maximum_prefix_threshold_warning_cmd);
16449 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16450 install_element(BGP_IPV6M_NODE,
16451 &neighbor_maximum_prefix_threshold_restart_cmd);
16452 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16453 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16454 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16455 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16456 install_element(BGP_IPV6L_NODE,
16457 &neighbor_maximum_prefix_threshold_warning_cmd);
16458 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16459 install_element(BGP_IPV6L_NODE,
16460 &neighbor_maximum_prefix_threshold_restart_cmd);
16461 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16462 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16463 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16464 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16465 install_element(BGP_VPNV4_NODE,
16466 &neighbor_maximum_prefix_threshold_warning_cmd);
16467 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16468 install_element(BGP_VPNV4_NODE,
16469 &neighbor_maximum_prefix_threshold_restart_cmd);
16470 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16471 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16472 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16473 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16474 install_element(BGP_VPNV6_NODE,
16475 &neighbor_maximum_prefix_threshold_warning_cmd);
16476 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16477 install_element(BGP_VPNV6_NODE,
16478 &neighbor_maximum_prefix_threshold_restart_cmd);
16479 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16480
16481 /* "neighbor allowas-in" */
16482 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16483 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16484 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16485 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16486 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16487 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16488 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16489 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16490 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16491 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16492 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16493 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16494 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16495 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16496 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16497 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16498 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16499 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16500 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16501 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16502
16503 /* address-family commands. */
16504 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16505 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16506#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16507 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16508 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16509#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16510
d62a17ae 16511 install_element(BGP_NODE, &address_family_evpn_cmd);
16512
16513 /* "exit-address-family" command. */
16514 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16515 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16516 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16517 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16518 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16519 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16520 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16521 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16522 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16523 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16524 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16525
16526 /* "clear ip bgp commands" */
16527 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16528
16529 /* clear ip bgp prefix */
16530 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16531 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16532 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16533
16534 /* "show [ip] bgp summary" commands. */
16535 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16536 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16537 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16538 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16539 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16540 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16541 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16542
16543 /* "show [ip] bgp neighbors" commands. */
16544 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16545
2986cac2 16546 install_element(VIEW_NODE,
16547 &show_ip_bgp_neighbors_graceful_restart_cmd);
16548
d62a17ae 16549 /* "show [ip] bgp peer-group" commands. */
16550 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16551
16552 /* "show [ip] bgp paths" commands. */
16553 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16554
16555 /* "show [ip] bgp community" commands. */
16556 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16557
16558 /* "show ip bgp large-community" commands. */
16559 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16560 /* "show [ip] bgp attribute-info" commands. */
16561 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16562 /* "show [ip] bgp route-leak" command */
16563 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16564
16565 /* "redistribute" commands. */
16566 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16567 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16568 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16569 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16570 install_element(BGP_NODE,
16571 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16572 install_element(BGP_NODE,
16573 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16574 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16575 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16576 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16577 install_element(BGP_NODE,
16578 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16579 install_element(BGP_NODE,
16580 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16581 install_element(BGP_NODE,
16582 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16583 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16584 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16585 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16586 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16587 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16588 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16589 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16590 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16591 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16592 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16593 install_element(BGP_IPV4_NODE,
16594 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16595 install_element(BGP_IPV4_NODE,
16596 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16597 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16598 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16599 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16600 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16601 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16602 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16603
b9c7bc5a
PZ
16604 /* import|export vpn [route-map WORD] */
16605 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16606 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 16607
12a844a5
DS
16608 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16609 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16610
d62a17ae 16611 /* ttl_security commands */
16612 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16613 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16614
16615 /* "show [ip] bgp memory" commands. */
16616 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16617
acf71666
MK
16618 /* "show bgp martian next-hop" */
16619 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16620
48ecf8f5
DS
16621 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16622
d62a17ae 16623 /* "show [ip] bgp views" commands. */
16624 install_element(VIEW_NODE, &show_bgp_views_cmd);
16625
16626 /* "show [ip] bgp vrfs" commands. */
16627 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16628
16629 /* Community-list. */
16630 community_list_vty();
ddb5b488
PZ
16631
16632 /* vpn-policy commands */
b9c7bc5a
PZ
16633 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16634 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16635 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16636 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16637 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16638 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16639 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16640 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16641 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16642 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
16643 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16644 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 16645
301ad80a
PG
16646 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16647 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16648
b9c7bc5a
PZ
16649 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16650 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16651 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16652 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
16653 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
16654 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
16655 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16656 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16657 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16658 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
16659 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16660 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 16661}
6b0655a2 16662
718e3744 16663#include "memory.h"
16664#include "bgp_regex.h"
16665#include "bgp_clist.h"
16666#include "bgp_ecommunity.h"
16667
16668/* VTY functions. */
16669
16670/* Direction value to string conversion. */
d62a17ae 16671static const char *community_direct_str(int direct)
16672{
16673 switch (direct) {
16674 case COMMUNITY_DENY:
16675 return "deny";
16676 case COMMUNITY_PERMIT:
16677 return "permit";
16678 default:
16679 return "unknown";
16680 }
718e3744 16681}
16682
16683/* Display error string. */
d62a17ae 16684static void community_list_perror(struct vty *vty, int ret)
16685{
16686 switch (ret) {
16687 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16688 vty_out(vty, "%% Can't find community-list\n");
16689 break;
16690 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16691 vty_out(vty, "%% Malformed community-list value\n");
16692 break;
16693 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16694 vty_out(vty,
16695 "%% Community name conflict, previously defined as standard community\n");
16696 break;
16697 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16698 vty_out(vty,
16699 "%% Community name conflict, previously defined as expanded community\n");
16700 break;
16701 }
718e3744 16702}
16703
5bf15956
DW
16704/* "community-list" keyword help string. */
16705#define COMMUNITY_LIST_STR "Add a community list entry\n"
16706
7336e101
SP
16707/*community-list standard */
16708DEFUN (community_list_standard,
16709 bgp_community_list_standard_cmd,
16710 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
16711 BGP_STR
718e3744 16712 COMMUNITY_LIST_STR
16713 "Community list number (standard)\n"
5bf15956 16714 "Add an standard community-list entry\n"
718e3744 16715 "Community list name\n"
16716 "Specify community to reject\n"
16717 "Specify community to accept\n"
16718 COMMUNITY_VAL_STR)
16719{
d62a17ae 16720 char *cl_name_or_number = NULL;
16721 int direct = 0;
16722 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 16723 int idx = 0;
7336e101 16724
d62a17ae 16725 argv_find(argv, argc, "(1-99)", &idx);
16726 argv_find(argv, argc, "WORD", &idx);
16727 cl_name_or_number = argv[idx]->arg;
16728 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16729 : COMMUNITY_DENY;
16730 argv_find(argv, argc, "AA:NN", &idx);
16731 char *str = argv_concat(argv, argc, idx);
42f914d4 16732
d62a17ae 16733 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
16734 style);
42f914d4 16735
d62a17ae 16736 XFREE(MTYPE_TMP, str);
42f914d4 16737
d62a17ae 16738 if (ret < 0) {
16739 /* Display error string. */
16740 community_list_perror(vty, ret);
16741 return CMD_WARNING_CONFIG_FAILED;
16742 }
42f914d4 16743
d62a17ae 16744 return CMD_SUCCESS;
718e3744 16745}
16746
7336e101
SP
16747DEFUN (no_community_list_standard_all,
16748 no_bgp_community_list_standard_all_cmd,
16749 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
16750 NO_STR
16751 BGP_STR
16752 COMMUNITY_LIST_STR
16753 "Community list number (standard)\n"
16754 "Add an standard community-list entry\n"
16755 "Community list name\n"
16756 "Specify community to reject\n"
16757 "Specify community to accept\n"
16758 COMMUNITY_VAL_STR)
718e3744 16759{
d62a17ae 16760 char *cl_name_or_number = NULL;
174b5cb9 16761 char *str = NULL;
d62a17ae 16762 int direct = 0;
16763 int style = COMMUNITY_LIST_STANDARD;
42f914d4 16764
d62a17ae 16765 int idx = 0;
7336e101 16766
174b5cb9
DA
16767 argv_find(argv, argc, "permit", &idx);
16768 argv_find(argv, argc, "deny", &idx);
16769
16770 if (idx) {
16771 direct = argv_find(argv, argc, "permit", &idx)
16772 ? COMMUNITY_PERMIT
16773 : COMMUNITY_DENY;
16774
16775 idx = 0;
16776 argv_find(argv, argc, "AA:NN", &idx);
16777 str = argv_concat(argv, argc, idx);
16778 }
16779
16780 idx = 0;
d62a17ae 16781 argv_find(argv, argc, "(1-99)", &idx);
16782 argv_find(argv, argc, "WORD", &idx);
16783 cl_name_or_number = argv[idx]->arg;
42f914d4 16784
d62a17ae 16785 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 16786 direct, style);
42f914d4 16787
d62a17ae 16788 XFREE(MTYPE_TMP, str);
daf9ddbb 16789
d62a17ae 16790 if (ret < 0) {
16791 community_list_perror(vty, ret);
16792 return CMD_WARNING_CONFIG_FAILED;
16793 }
42f914d4 16794
d62a17ae 16795 return CMD_SUCCESS;
718e3744 16796}
7336e101 16797
174b5cb9
DA
16798ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16799 "no bgp community-list <(1-99)|standard WORD>",
16800 NO_STR BGP_STR COMMUNITY_LIST_STR
16801 "Community list number (standard)\n"
16802 "Add an standard community-list entry\n"
16803 "Community list name\n")
16804
7336e101
SP
16805/*community-list expanded */
16806DEFUN (community_list_expanded_all,
16807 bgp_community_list_expanded_all_cmd,
16808 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
16809 BGP_STR
16810 COMMUNITY_LIST_STR
718e3744 16811 "Community list number (expanded)\n"
5bf15956 16812 "Add an expanded community-list entry\n"
718e3744 16813 "Community list name\n"
16814 "Specify community to reject\n"
16815 "Specify community to accept\n"
16816 COMMUNITY_VAL_STR)
16817{
d62a17ae 16818 char *cl_name_or_number = NULL;
16819 int direct = 0;
16820 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 16821
d62a17ae 16822 int idx = 0;
7b9a4750 16823
d62a17ae 16824 argv_find(argv, argc, "(100-500)", &idx);
16825 argv_find(argv, argc, "WORD", &idx);
16826 cl_name_or_number = argv[idx]->arg;
16827 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16828 : COMMUNITY_DENY;
16829 argv_find(argv, argc, "AA:NN", &idx);
16830 char *str = argv_concat(argv, argc, idx);
42f914d4 16831
d62a17ae 16832 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
16833 style);
42f914d4 16834
d62a17ae 16835 XFREE(MTYPE_TMP, str);
42f914d4 16836
d62a17ae 16837 if (ret < 0) {
16838 /* Display error string. */
16839 community_list_perror(vty, ret);
16840 return CMD_WARNING_CONFIG_FAILED;
16841 }
42f914d4 16842
d62a17ae 16843 return CMD_SUCCESS;
718e3744 16844}
16845
7336e101
SP
16846DEFUN (no_community_list_expanded_all,
16847 no_bgp_community_list_expanded_all_cmd,
16848 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
16849 NO_STR
16850 BGP_STR
16851 COMMUNITY_LIST_STR
16852 "Community list number (expanded)\n"
16853 "Add an expanded community-list entry\n"
16854 "Community list name\n"
16855 "Specify community to reject\n"
16856 "Specify community to accept\n"
16857 COMMUNITY_VAL_STR)
718e3744 16858{
d62a17ae 16859 char *cl_name_or_number = NULL;
174b5cb9 16860 char *str = NULL;
d62a17ae 16861 int direct = 0;
16862 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 16863
d62a17ae 16864 int idx = 0;
174b5cb9
DA
16865
16866 argv_find(argv, argc, "permit", &idx);
16867 argv_find(argv, argc, "deny", &idx);
16868
16869 if (idx) {
16870 direct = argv_find(argv, argc, "permit", &idx)
16871 ? COMMUNITY_PERMIT
16872 : COMMUNITY_DENY;
16873
16874 idx = 0;
16875 argv_find(argv, argc, "AA:NN", &idx);
16876 str = argv_concat(argv, argc, idx);
7336e101 16877 }
174b5cb9
DA
16878
16879 idx = 0;
d62a17ae 16880 argv_find(argv, argc, "(100-500)", &idx);
16881 argv_find(argv, argc, "WORD", &idx);
16882 cl_name_or_number = argv[idx]->arg;
42f914d4 16883
d62a17ae 16884 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
7298a8e1 16885 direct, style);
42f914d4 16886
d62a17ae 16887 XFREE(MTYPE_TMP, str);
daf9ddbb 16888
d62a17ae 16889 if (ret < 0) {
16890 community_list_perror(vty, ret);
16891 return CMD_WARNING_CONFIG_FAILED;
16892 }
42f914d4 16893
d62a17ae 16894 return CMD_SUCCESS;
718e3744 16895}
16896
174b5cb9
DA
16897ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16898 "no bgp community-list <(100-500)|expanded WORD>",
16899 NO_STR IP_STR COMMUNITY_LIST_STR
16900 "Community list number (expanded)\n"
16901 "Add an expanded community-list entry\n"
16902 "Community list name\n")
16903
8d9b8ed9
PM
16904/* Return configuration string of community-list entry. */
16905static const char *community_list_config_str(struct community_entry *entry)
16906{
16907 const char *str;
16908
16909 if (entry->any)
16910 str = "";
16911 else {
16912 if (entry->style == COMMUNITY_LIST_STANDARD)
16913 str = community_str(entry->u.com, false);
16914 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
16915 str = lcommunity_str(entry->u.lcom, false);
16916 else
16917 str = entry->config;
16918 }
16919 return str;
16920}
16921
d62a17ae 16922static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 16923{
d62a17ae 16924 struct community_entry *entry;
718e3744 16925
d62a17ae 16926 for (entry = list->head; entry; entry = entry->next) {
16927 if (entry == list->head) {
16928 if (all_digit(list->name))
16929 vty_out(vty, "Community %s list %s\n",
16930 entry->style == COMMUNITY_LIST_STANDARD
16931 ? "standard"
16932 : "(expanded) access",
16933 list->name);
16934 else
16935 vty_out(vty, "Named Community %s list %s\n",
16936 entry->style == COMMUNITY_LIST_STANDARD
16937 ? "standard"
16938 : "expanded",
16939 list->name);
16940 }
16941 if (entry->any)
16942 vty_out(vty, " %s\n",
16943 community_direct_str(entry->direct));
16944 else
16945 vty_out(vty, " %s %s\n",
16946 community_direct_str(entry->direct),
8d9b8ed9 16947 community_list_config_str(entry));
d62a17ae 16948 }
718e3744 16949}
16950
7336e101
SP
16951DEFUN (show_community_list,
16952 show_bgp_community_list_cmd,
16953 "show bgp community-list",
718e3744 16954 SHOW_STR
7336e101 16955 BGP_STR
718e3744 16956 "List community-list\n")
16957{
d62a17ae 16958 struct community_list *list;
16959 struct community_list_master *cm;
718e3744 16960
d62a17ae 16961 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16962 if (!cm)
16963 return CMD_SUCCESS;
718e3744 16964
d62a17ae 16965 for (list = cm->num.head; list; list = list->next)
16966 community_list_show(vty, list);
718e3744 16967
d62a17ae 16968 for (list = cm->str.head; list; list = list->next)
16969 community_list_show(vty, list);
718e3744 16970
d62a17ae 16971 return CMD_SUCCESS;
718e3744 16972}
16973
7336e101
SP
16974DEFUN (show_community_list_arg,
16975 show_bgp_community_list_arg_cmd,
960b69b9 16976 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
16977 SHOW_STR
16978 BGP_STR
718e3744 16979 "List community-list\n"
16980 "Community-list number\n"
960b69b9 16981 "Community-list name\n"
16982 "Detailed information on community-list\n")
718e3744 16983{
d62a17ae 16984 int idx_comm_list = 3;
16985 struct community_list *list;
718e3744 16986
e237b0d2 16987 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 16988 COMMUNITY_LIST_MASTER);
16989 if (!list) {
16990 vty_out(vty, "%% Can't find community-list\n");
16991 return CMD_WARNING;
16992 }
718e3744 16993
d62a17ae 16994 community_list_show(vty, list);
718e3744 16995
d62a17ae 16996 return CMD_SUCCESS;
718e3744 16997}
6b0655a2 16998
57d187bc
JS
16999/*
17000 * Large Community code.
17001 */
d62a17ae 17002static int lcommunity_list_set_vty(struct vty *vty, int argc,
17003 struct cmd_token **argv, int style,
17004 int reject_all_digit_name)
17005{
17006 int ret;
17007 int direct;
17008 char *str;
17009 int idx = 0;
17010 char *cl_name;
17011
17012 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17013 : COMMUNITY_DENY;
17014
17015 /* All digit name check. */
17016 idx = 0;
17017 argv_find(argv, argc, "WORD", &idx);
17018 argv_find(argv, argc, "(1-99)", &idx);
17019 argv_find(argv, argc, "(100-500)", &idx);
17020 cl_name = argv[idx]->arg;
17021 if (reject_all_digit_name && all_digit(cl_name)) {
17022 vty_out(vty, "%% Community name cannot have all digits\n");
17023 return CMD_WARNING_CONFIG_FAILED;
17024 }
17025
17026 idx = 0;
17027 argv_find(argv, argc, "AA:BB:CC", &idx);
17028 argv_find(argv, argc, "LINE", &idx);
17029 /* Concat community string argument. */
17030 if (idx)
17031 str = argv_concat(argv, argc, idx);
17032 else
17033 str = NULL;
17034
17035 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
17036
17037 /* Free temporary community list string allocated by
17038 argv_concat(). */
0a22ddfb 17039 XFREE(MTYPE_TMP, str);
d62a17ae 17040
17041 if (ret < 0) {
17042 community_list_perror(vty, ret);
17043 return CMD_WARNING_CONFIG_FAILED;
17044 }
17045 return CMD_SUCCESS;
17046}
17047
17048static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17049 struct cmd_token **argv, int style)
17050{
17051 int ret;
17052 int direct = 0;
17053 char *str = NULL;
17054 int idx = 0;
17055
17056 argv_find(argv, argc, "permit", &idx);
17057 argv_find(argv, argc, "deny", &idx);
17058
17059 if (idx) {
17060 /* Check the list direct. */
17061 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17062 direct = COMMUNITY_PERMIT;
17063 else
17064 direct = COMMUNITY_DENY;
17065
17066 idx = 0;
17067 argv_find(argv, argc, "LINE", &idx);
17068 argv_find(argv, argc, "AA:AA:NN", &idx);
17069 /* Concat community string argument. */
17070 str = argv_concat(argv, argc, idx);
17071 }
17072
17073 idx = 0;
17074 argv_find(argv, argc, "(1-99)", &idx);
17075 argv_find(argv, argc, "(100-500)", &idx);
17076 argv_find(argv, argc, "WORD", &idx);
17077
17078 /* Unset community list. */
17079 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
17080 style);
17081
17082 /* Free temporary community list string allocated by
17083 argv_concat(). */
0a22ddfb 17084 XFREE(MTYPE_TMP, str);
d62a17ae 17085
17086 if (ret < 0) {
17087 community_list_perror(vty, ret);
17088 return CMD_WARNING_CONFIG_FAILED;
17089 }
17090
17091 return CMD_SUCCESS;
57d187bc
JS
17092}
17093
17094/* "large-community-list" keyword help string. */
17095#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17096#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17097
7336e101
SP
17098DEFUN (lcommunity_list_standard,
17099 bgp_lcommunity_list_standard_cmd,
7336e101
SP
17100 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
17101 BGP_STR
17102 LCOMMUNITY_LIST_STR
17103 "Large Community list number (standard)\n"
17104 "Specify large community to reject\n"
17105 "Specify large community to accept\n"
17106 LCOMMUNITY_VAL_STR)
52951b63 17107{
d62a17ae 17108 return lcommunity_list_set_vty(vty, argc, argv,
17109 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17110}
17111
7336e101
SP
17112DEFUN (lcommunity_list_expanded,
17113 bgp_lcommunity_list_expanded_cmd,
17114 "bgp large-community-list (100-500) <deny|permit> LINE...",
17115 BGP_STR
17116 LCOMMUNITY_LIST_STR
17117 "Large Community list number (expanded)\n"
17118 "Specify large community to reject\n"
17119 "Specify large community to accept\n"
17120 "An ordered list as a regular-expression\n")
57d187bc 17121{
d62a17ae 17122 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17123 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17124}
17125
7336e101
SP
17126DEFUN (lcommunity_list_name_standard,
17127 bgp_lcommunity_list_name_standard_cmd,
7336e101
SP
17128 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
17129 BGP_STR
17130 LCOMMUNITY_LIST_STR
17131 "Specify standard large-community-list\n"
17132 "Large Community list name\n"
17133 "Specify large community to reject\n"
17134 "Specify large community to accept\n"
17135 LCOMMUNITY_VAL_STR)
52951b63 17136{
d62a17ae 17137 return lcommunity_list_set_vty(vty, argc, argv,
17138 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17139}
17140
7336e101
SP
17141DEFUN (lcommunity_list_name_expanded,
17142 bgp_lcommunity_list_name_expanded_cmd,
17143 "bgp large-community-list expanded WORD <deny|permit> LINE...",
17144 BGP_STR
17145 LCOMMUNITY_LIST_STR
17146 "Specify expanded large-community-list\n"
17147 "Large Community list name\n"
17148 "Specify large community to reject\n"
17149 "Specify large community to accept\n"
17150 "An ordered list as a regular-expression\n")
57d187bc 17151{
d62a17ae 17152 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17153 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17154}
17155
7336e101
SP
17156DEFUN (no_lcommunity_list_standard_all,
17157 no_bgp_lcommunity_list_standard_all_cmd,
17158 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17159 NO_STR
17160 BGP_STR
17161 LCOMMUNITY_LIST_STR
17162 "Large Community list number (standard)\n"
17163 "Large Community list number (expanded)\n"
17164 "Large Community list name\n")
57d187bc 17165{
7336e101
SP
17166 return lcommunity_list_unset_vty(vty, argc, argv,
17167 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17168}
17169
7336e101
SP
17170DEFUN (no_lcommunity_list_name_expanded_all,
17171 no_bgp_lcommunity_list_name_expanded_all_cmd,
17172 "no bgp large-community-list expanded WORD",
17173 NO_STR
17174 BGP_STR
17175 LCOMMUNITY_LIST_STR
17176 "Specify expanded large-community-list\n"
17177 "Large Community list name\n")
57d187bc 17178{
d62a17ae 17179 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17180 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17181}
17182
7336e101
SP
17183DEFUN (no_lcommunity_list_standard,
17184 no_bgp_lcommunity_list_standard_cmd,
17185 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
17186 NO_STR
17187 BGP_STR
17188 LCOMMUNITY_LIST_STR
17189 "Large Community list number (standard)\n"
17190 "Specify large community to reject\n"
17191 "Specify large community to accept\n"
17192 LCOMMUNITY_VAL_STR)
57d187bc 17193{
d62a17ae 17194 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17195 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17196}
17197
7336e101
SP
17198DEFUN (no_lcommunity_list_expanded,
17199 no_bgp_lcommunity_list_expanded_cmd,
17200 "no bgp large-community-list (100-500) <deny|permit> LINE...",
17201 NO_STR
17202 BGP_STR
17203 LCOMMUNITY_LIST_STR
17204 "Large Community list number (expanded)\n"
17205 "Specify large community to reject\n"
17206 "Specify large community to accept\n"
17207 "An ordered list as a regular-expression\n")
57d187bc 17208{
d62a17ae 17209 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17210 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17211}
17212
7336e101
SP
17213DEFUN (no_lcommunity_list_name_standard,
17214 no_bgp_lcommunity_list_name_standard_cmd,
17215 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
17216 NO_STR
17217 BGP_STR
17218 LCOMMUNITY_LIST_STR
17219 "Specify standard large-community-list\n"
17220 "Large Community list name\n"
17221 "Specify large community to reject\n"
17222 "Specify large community to accept\n"
17223 LCOMMUNITY_VAL_STR)
57d187bc 17224{
d62a17ae 17225 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17226 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17227}
17228
7336e101
SP
17229DEFUN (no_lcommunity_list_name_expanded,
17230 no_bgp_lcommunity_list_name_expanded_cmd,
17231 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
17232 NO_STR
17233 BGP_STR
17234 LCOMMUNITY_LIST_STR
17235 "Specify expanded large-community-list\n"
17236 "Large community list name\n"
17237 "Specify large community to reject\n"
17238 "Specify large community to accept\n"
17239 "An ordered list as a regular-expression\n")
57d187bc 17240{
d62a17ae 17241 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17242 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17243}
17244
d62a17ae 17245static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17246{
17247 struct community_entry *entry;
17248
17249 for (entry = list->head; entry; entry = entry->next) {
17250 if (entry == list->head) {
17251 if (all_digit(list->name))
17252 vty_out(vty, "Large community %s list %s\n",
169b72c8 17253 entry->style ==
17254 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17255 ? "standard"
17256 : "(expanded) access",
17257 list->name);
17258 else
17259 vty_out(vty,
17260 "Named large community %s list %s\n",
169b72c8 17261 entry->style ==
17262 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17263 ? "standard"
17264 : "expanded",
17265 list->name);
17266 }
17267 if (entry->any)
17268 vty_out(vty, " %s\n",
17269 community_direct_str(entry->direct));
17270 else
17271 vty_out(vty, " %s %s\n",
17272 community_direct_str(entry->direct),
8d9b8ed9 17273 community_list_config_str(entry));
d62a17ae 17274 }
57d187bc
JS
17275}
17276
7336e101
SP
17277DEFUN (show_lcommunity_list,
17278 show_bgp_lcommunity_list_cmd,
17279 "show bgp large-community-list",
57d187bc 17280 SHOW_STR
7336e101 17281 BGP_STR
57d187bc
JS
17282 "List large-community list\n")
17283{
d62a17ae 17284 struct community_list *list;
17285 struct community_list_master *cm;
57d187bc 17286
d62a17ae 17287 cm = community_list_master_lookup(bgp_clist,
17288 LARGE_COMMUNITY_LIST_MASTER);
17289 if (!cm)
17290 return CMD_SUCCESS;
57d187bc 17291
d62a17ae 17292 for (list = cm->num.head; list; list = list->next)
17293 lcommunity_list_show(vty, list);
57d187bc 17294
d62a17ae 17295 for (list = cm->str.head; list; list = list->next)
17296 lcommunity_list_show(vty, list);
57d187bc 17297
d62a17ae 17298 return CMD_SUCCESS;
57d187bc
JS
17299}
17300
7336e101
SP
17301DEFUN (show_lcommunity_list_arg,
17302 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17303 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17304 SHOW_STR
17305 BGP_STR
57d187bc 17306 "List large-community list\n"
960b69b9 17307 "Large-community-list number\n"
17308 "Large-community-list name\n"
17309 "Detailed information on large-community-list\n")
57d187bc 17310{
d62a17ae 17311 struct community_list *list;
57d187bc 17312
e237b0d2 17313 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17314 LARGE_COMMUNITY_LIST_MASTER);
17315 if (!list) {
960b69b9 17316 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17317 return CMD_WARNING;
17318 }
57d187bc 17319
d62a17ae 17320 lcommunity_list_show(vty, list);
57d187bc 17321
d62a17ae 17322 return CMD_SUCCESS;
57d187bc
JS
17323}
17324
718e3744 17325/* "extcommunity-list" keyword help string. */
17326#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17327#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17328
7336e101
SP
17329DEFUN (extcommunity_list_standard,
17330 bgp_extcommunity_list_standard_cmd,
17331 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
17332 BGP_STR
718e3744 17333 EXTCOMMUNITY_LIST_STR
17334 "Extended Community list number (standard)\n"
718e3744 17335 "Specify standard extcommunity-list\n"
5bf15956 17336 "Community list name\n"
718e3744 17337 "Specify community to reject\n"
17338 "Specify community to accept\n"
17339 EXTCOMMUNITY_VAL_STR)
17340{
d62a17ae 17341 int style = EXTCOMMUNITY_LIST_STANDARD;
17342 int direct = 0;
17343 char *cl_number_or_name = NULL;
42f914d4 17344
d62a17ae 17345 int idx = 0;
7b9a4750 17346
d62a17ae 17347 argv_find(argv, argc, "(1-99)", &idx);
17348 argv_find(argv, argc, "WORD", &idx);
17349 cl_number_or_name = argv[idx]->arg;
17350 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17351 : COMMUNITY_DENY;
17352 argv_find(argv, argc, "AA:NN", &idx);
17353 char *str = argv_concat(argv, argc, idx);
42f914d4 17354
d62a17ae 17355 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
17356 direct, style);
42f914d4 17357
d62a17ae 17358 XFREE(MTYPE_TMP, str);
42f914d4 17359
d62a17ae 17360 if (ret < 0) {
17361 community_list_perror(vty, ret);
17362 return CMD_WARNING_CONFIG_FAILED;
17363 }
42f914d4 17364
d62a17ae 17365 return CMD_SUCCESS;
718e3744 17366}
17367
7336e101
SP
17368DEFUN (extcommunity_list_name_expanded,
17369 bgp_extcommunity_list_name_expanded_cmd,
17370 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
17371 BGP_STR
17372 EXTCOMMUNITY_LIST_STR
5bf15956 17373 "Extended Community list number (expanded)\n"
718e3744 17374 "Specify expanded extcommunity-list\n"
17375 "Extended Community list name\n"
17376 "Specify community to reject\n"
17377 "Specify community to accept\n"
17378 "An ordered list as a regular-expression\n")
17379{
d62a17ae 17380 int style = EXTCOMMUNITY_LIST_EXPANDED;
17381 int direct = 0;
17382 char *cl_number_or_name = NULL;
d62a17ae 17383 int idx = 0;
7336e101 17384
d62a17ae 17385 argv_find(argv, argc, "(100-500)", &idx);
17386 argv_find(argv, argc, "WORD", &idx);
17387 cl_number_or_name = argv[idx]->arg;
17388 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17389 : COMMUNITY_DENY;
17390 argv_find(argv, argc, "LINE", &idx);
17391 char *str = argv_concat(argv, argc, idx);
42f914d4 17392
d62a17ae 17393 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
17394 direct, style);
42f914d4 17395
d62a17ae 17396 XFREE(MTYPE_TMP, str);
42f914d4 17397
d62a17ae 17398 if (ret < 0) {
17399 community_list_perror(vty, ret);
17400 return CMD_WARNING_CONFIG_FAILED;
17401 }
42f914d4 17402
d62a17ae 17403 return CMD_SUCCESS;
718e3744 17404}
17405
7336e101
SP
17406DEFUN (no_extcommunity_list_standard_all,
17407 no_bgp_extcommunity_list_standard_all_cmd,
17408 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
17409 NO_STR
17410 BGP_STR
17411 EXTCOMMUNITY_LIST_STR
813d4307 17412 "Extended Community list number (standard)\n"
718e3744 17413 "Specify standard extcommunity-list\n"
5bf15956 17414 "Community list name\n"
718e3744 17415 "Specify community to reject\n"
17416 "Specify community to accept\n"
17417 EXTCOMMUNITY_VAL_STR)
17418{
d62a17ae 17419 int style = EXTCOMMUNITY_LIST_STANDARD;
17420 int direct = 0;
17421 char *cl_number_or_name = NULL;
d4455c89 17422 char *str = NULL;
d62a17ae 17423 int idx = 0;
d4455c89 17424
d4455c89
DA
17425 argv_find(argv, argc, "permit", &idx);
17426 argv_find(argv, argc, "deny", &idx);
17427
17428 if (idx) {
17429 direct = argv_find(argv, argc, "permit", &idx)
17430 ? COMMUNITY_PERMIT
17431 : COMMUNITY_DENY;
17432
17433 idx = 0;
17434 argv_find(argv, argc, "AA:NN", &idx);
17435 str = argv_concat(argv, argc, idx);
17436 }
17437
17438 idx = 0;
d62a17ae 17439 argv_find(argv, argc, "(1-99)", &idx);
17440 argv_find(argv, argc, "WORD", &idx);
17441 cl_number_or_name = argv[idx]->arg;
42f914d4 17442
d62a17ae 17443 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 17444 direct, style);
42f914d4 17445
d62a17ae 17446 XFREE(MTYPE_TMP, str);
42f914d4 17447
d62a17ae 17448 if (ret < 0) {
17449 community_list_perror(vty, ret);
17450 return CMD_WARNING_CONFIG_FAILED;
17451 }
42f914d4 17452
d62a17ae 17453 return CMD_SUCCESS;
718e3744 17454}
17455
d4455c89
DA
17456ALIAS(no_extcommunity_list_standard_all,
17457 no_bgp_extcommunity_list_standard_all_list_cmd,
17458 "no bgp extcommunity-list <(1-99)|standard WORD>",
17459 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17460 "Extended Community list number (standard)\n"
17461 "Specify standard extcommunity-list\n"
17462 "Community list name\n")
17463
7336e101
SP
17464DEFUN (no_extcommunity_list_expanded_all,
17465 no_bgp_extcommunity_list_expanded_all_cmd,
17466 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
17467 NO_STR
17468 BGP_STR
17469 EXTCOMMUNITY_LIST_STR
718e3744 17470 "Extended Community list number (expanded)\n"
718e3744 17471 "Specify expanded extcommunity-list\n"
5bf15956 17472 "Extended Community list name\n"
718e3744 17473 "Specify community to reject\n"
17474 "Specify community to accept\n"
17475 "An ordered list as a regular-expression\n")
17476{
d62a17ae 17477 int style = EXTCOMMUNITY_LIST_EXPANDED;
17478 int direct = 0;
17479 char *cl_number_or_name = NULL;
d4455c89 17480 char *str = NULL;
d62a17ae 17481 int idx = 0;
d4455c89 17482
d4455c89
DA
17483 argv_find(argv, argc, "permit", &idx);
17484 argv_find(argv, argc, "deny", &idx);
17485
17486 if (idx) {
17487 direct = argv_find(argv, argc, "permit", &idx)
17488 ? COMMUNITY_PERMIT
17489 : COMMUNITY_DENY;
17490
17491 idx = 0;
17492 argv_find(argv, argc, "LINE", &idx);
17493 str = argv_concat(argv, argc, idx);
17494 }
17495
17496 idx = 0;
d62a17ae 17497 argv_find(argv, argc, "(100-500)", &idx);
17498 argv_find(argv, argc, "WORD", &idx);
17499 cl_number_or_name = argv[idx]->arg;
42f914d4 17500
d62a17ae 17501 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
7298a8e1 17502 direct, style);
42f914d4 17503
d62a17ae 17504 XFREE(MTYPE_TMP, str);
42f914d4 17505
d62a17ae 17506 if (ret < 0) {
17507 community_list_perror(vty, ret);
17508 return CMD_WARNING_CONFIG_FAILED;
17509 }
42f914d4 17510
d62a17ae 17511 return CMD_SUCCESS;
718e3744 17512}
17513
d4455c89
DA
17514ALIAS(no_extcommunity_list_expanded_all,
17515 no_bgp_extcommunity_list_expanded_all_list_cmd,
17516 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17517 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17518 "Extended Community list number (expanded)\n"
17519 "Specify expanded extcommunity-list\n"
17520 "Extended Community list name\n")
17521
d62a17ae 17522static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 17523{
d62a17ae 17524 struct community_entry *entry;
718e3744 17525
d62a17ae 17526 for (entry = list->head; entry; entry = entry->next) {
17527 if (entry == list->head) {
17528 if (all_digit(list->name))
17529 vty_out(vty, "Extended community %s list %s\n",
17530 entry->style == EXTCOMMUNITY_LIST_STANDARD
17531 ? "standard"
17532 : "(expanded) access",
17533 list->name);
17534 else
17535 vty_out(vty,
17536 "Named extended community %s list %s\n",
17537 entry->style == EXTCOMMUNITY_LIST_STANDARD
17538 ? "standard"
17539 : "expanded",
17540 list->name);
17541 }
17542 if (entry->any)
17543 vty_out(vty, " %s\n",
17544 community_direct_str(entry->direct));
17545 else
17546 vty_out(vty, " %s %s\n",
17547 community_direct_str(entry->direct),
8d9b8ed9 17548 community_list_config_str(entry));
d62a17ae 17549 }
718e3744 17550}
17551
7336e101
SP
17552DEFUN (show_extcommunity_list,
17553 show_bgp_extcommunity_list_cmd,
17554 "show bgp extcommunity-list",
718e3744 17555 SHOW_STR
7336e101 17556 BGP_STR
718e3744 17557 "List extended-community list\n")
17558{
d62a17ae 17559 struct community_list *list;
17560 struct community_list_master *cm;
718e3744 17561
d62a17ae 17562 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17563 if (!cm)
17564 return CMD_SUCCESS;
718e3744 17565
d62a17ae 17566 for (list = cm->num.head; list; list = list->next)
17567 extcommunity_list_show(vty, list);
718e3744 17568
d62a17ae 17569 for (list = cm->str.head; list; list = list->next)
17570 extcommunity_list_show(vty, list);
718e3744 17571
d62a17ae 17572 return CMD_SUCCESS;
718e3744 17573}
17574
7336e101
SP
17575DEFUN (show_extcommunity_list_arg,
17576 show_bgp_extcommunity_list_arg_cmd,
960b69b9 17577 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
17578 SHOW_STR
17579 BGP_STR
718e3744 17580 "List extended-community list\n"
17581 "Extcommunity-list number\n"
960b69b9 17582 "Extcommunity-list name\n"
17583 "Detailed information on extcommunity-list\n")
718e3744 17584{
d62a17ae 17585 int idx_comm_list = 3;
17586 struct community_list *list;
718e3744 17587
e237b0d2 17588 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17589 EXTCOMMUNITY_LIST_MASTER);
17590 if (!list) {
17591 vty_out(vty, "%% Can't find extcommunity-list\n");
17592 return CMD_WARNING;
17593 }
718e3744 17594
d62a17ae 17595 extcommunity_list_show(vty, list);
718e3744 17596
d62a17ae 17597 return CMD_SUCCESS;
718e3744 17598}
6b0655a2 17599
718e3744 17600/* Display community-list and extcommunity-list configuration. */
d62a17ae 17601static int community_list_config_write(struct vty *vty)
17602{
17603 struct community_list *list;
17604 struct community_entry *entry;
17605 struct community_list_master *cm;
17606 int write = 0;
17607
17608 /* Community-list. */
17609 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17610
17611 for (list = cm->num.head; list; list = list->next)
17612 for (entry = list->head; entry; entry = entry->next) {
7336e101 17613 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
d62a17ae 17614 community_direct_str(entry->direct),
17615 community_list_config_str(entry));
17616 write++;
17617 }
17618 for (list = cm->str.head; list; list = list->next)
17619 for (entry = list->head; entry; entry = entry->next) {
7336e101 17620 vty_out(vty, "bgp community-list %s %s %s %s\n",
d62a17ae 17621 entry->style == COMMUNITY_LIST_STANDARD
17622 ? "standard"
17623 : "expanded",
17624 list->name, community_direct_str(entry->direct),
17625 community_list_config_str(entry));
17626 write++;
17627 }
17628
17629 /* Extcommunity-list. */
17630 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17631
17632 for (list = cm->num.head; list; list = list->next)
17633 for (entry = list->head; entry; entry = entry->next) {
7336e101 17634 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
d62a17ae 17635 list->name, community_direct_str(entry->direct),
17636 community_list_config_str(entry));
17637 write++;
17638 }
17639 for (list = cm->str.head; list; list = list->next)
17640 for (entry = list->head; entry; entry = entry->next) {
7336e101 17641 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
d62a17ae 17642 entry->style == EXTCOMMUNITY_LIST_STANDARD
17643 ? "standard"
17644 : "expanded",
17645 list->name, community_direct_str(entry->direct),
17646 community_list_config_str(entry));
17647 write++;
17648 }
17649
17650
17651 /* lcommunity-list. */
17652 cm = community_list_master_lookup(bgp_clist,
17653 LARGE_COMMUNITY_LIST_MASTER);
17654
17655 for (list = cm->num.head; list; list = list->next)
17656 for (entry = list->head; entry; entry = entry->next) {
7336e101 17657 vty_out(vty, "bgp large-community-list %s %s %s\n",
d62a17ae 17658 list->name, community_direct_str(entry->direct),
17659 community_list_config_str(entry));
17660 write++;
17661 }
17662 for (list = cm->str.head; list; list = list->next)
17663 for (entry = list->head; entry; entry = entry->next) {
7336e101 17664 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
d62a17ae 17665 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17666 ? "standard"
17667 : "expanded",
17668 list->name, community_direct_str(entry->direct),
17669 community_list_config_str(entry));
17670 write++;
17671 }
17672
17673 return write;
17674}
17675
17676static struct cmd_node community_list_node = {
17677 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 17678};
17679
d62a17ae 17680static void community_list_vty(void)
17681{
17682 install_node(&community_list_node, community_list_config_write);
17683
17684 /* Community-list. */
7336e101
SP
17685 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17686 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17687 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 17688 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 17689 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 17690 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
17691 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17692 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 17693
17694 /* Extcommunity-list. */
7336e101
SP
17695 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17696 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17697 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
17698 install_element(CONFIG_NODE,
17699 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 17700 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
17701 install_element(CONFIG_NODE,
17702 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
17703 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17704 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 17705
17706 /* Large Community List */
7336e101 17707 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
17708 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17709 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101
SP
17710 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
17711 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
17712 install_element(CONFIG_NODE,
17713 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17714 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17715 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17716 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17717 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17718 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17719 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 17720}