]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #5717 from pguibert6WIND/flowspec_issue_redistribute
[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 9595 vty_out(vty, " F bit : ");
698ba8d0 9596 }
2986cac2 9597
13909c4f
DS
9598 if (peer->nsf[afi][safi]
9599 && CHECK_FLAG(peer->af_cap[afi][safi],
9600 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9601
13909c4f
DS
9602 if (use_json) {
9603 json_object_boolean_true_add(
2986cac2 9604 json_afi_safi, "fBit");
13909c4f
DS
9605 } else
9606 vty_out(vty, "True\n");
9607 } else {
9608 if (use_json)
9609 json_object_boolean_false_add(
9610 json_afi_safi, "fBit");
9611 else
9612 vty_out(vty, "False\n");
9613 }
2986cac2 9614
13909c4f
DS
9615 if (!use_json)
9616 vty_out(vty, " End-of-RIB Received : ");
2986cac2 9617
13909c4f
DS
9618 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9619 PEER_STATUS_EOR_RECEIVED)) {
9620 if (use_json)
9621 json_object_boolean_true_add(
2986cac2 9622 json_endofrib_status,
13909c4f
DS
9623 "endOfRibRecv");
9624 else
9625 vty_out(vty, "Yes\n");
9626 } else {
9627 if (use_json)
9628 json_object_boolean_false_add(
2986cac2 9629 json_endofrib_status,
13909c4f
DS
9630 "endOfRibRecv");
9631 else
9632 vty_out(vty, "No\n");
9633 }
2986cac2 9634
13909c4f
DS
9635 if (!use_json)
9636 vty_out(vty, " End-of-RIB Send : ");
2986cac2 9637
13909c4f
DS
9638 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9639 PEER_STATUS_EOR_SEND)) {
9640 if (use_json) {
9641 json_object_boolean_true_add(
2986cac2 9642 json_endofrib_status,
13909c4f 9643 "endOfRibSend");
9e3b51a7 9644
13909c4f
DS
9645 PRINT_EOR_JSON(eor_flag);
9646 } else {
9647 vty_out(vty, "Yes\n");
9648 vty_out(vty,
9e3b51a7 9649 " EoRSentAfterUpdate : ");
2986cac2 9650
13909c4f
DS
9651 PRINT_EOR(eor_flag);
9652 }
9653 } else {
9654 if (use_json) {
9655 json_object_boolean_false_add(
2986cac2 9656 json_endofrib_status,
13909c4f
DS
9657 "endOfRibSend");
9658 json_object_boolean_false_add(
9e3b51a7 9659 json_endofrib_status,
13909c4f
DS
9660 "endOfRibSentAfterUpdate");
9661 } else {
9662 vty_out(vty, "No\n");
9663 vty_out(vty,
9e3b51a7 9664 " EoRSentAfterUpdate : ");
13909c4f 9665 vty_out(vty, "No\n");
2986cac2 9666 }
13909c4f 9667 }
2986cac2 9668
13909c4f
DS
9669 if (use_json) {
9670 json_object_int_add(json_timer,
9671 "stalePathTimer",
9672 peer->bgp->stalepath_time);
2986cac2 9673
13909c4f
DS
9674 if (peer->t_gr_stale != NULL) {
9675 json_object_int_add(
2986cac2 9676 json_timer,
9677 "stalePathTimerRemaining",
9678 thread_timer_remain_second(
13909c4f
DS
9679 peer->t_gr_stale));
9680 }
3a75afa4 9681
13909c4f
DS
9682 /* Display Configured Selection
9683 * Deferral only when when
9684 * Gr mode is enabled.
9685 */
9686 if (CHECK_FLAG(peer->flags,
9687 PEER_FLAG_GRACEFUL_RESTART)) {
9688 json_object_int_add(
3a75afa4 9689 json_timer,
2986cac2 9690 "selectionDeferralTimer",
9691 peer->bgp->stalepath_time);
13909c4f 9692 }
2986cac2 9693
13909c4f
DS
9694 if (peer->bgp->gr_info[afi][safi]
9695 .t_select_deferral
9696 != NULL) {
2986cac2 9697
13909c4f 9698 json_object_int_add(
2986cac2 9699 json_timer,
9700 "selectionDeferralTimerRemaining",
9701 thread_timer_remain_second(
13909c4f
DS
9702 peer->bgp
9703 ->gr_info[afi]
9704 [safi]
9705 .t_select_deferral));
9706 }
9707 } else {
9708 vty_out(vty, " Timers:\n");
2986cac2 9709
13909c4f
DS
9710 vty_out(vty, "%*s", 6, "");
9711 vty_out(vty,
9712 "Configured Stale Path Time(sec)%*s: %u\n",
9713 8, "", peer->bgp->stalepath_time);
2986cac2 9714
13909c4f 9715 if (peer->t_gr_stale != NULL) {
2986cac2 9716 vty_out(vty, "%*s", 6, "");
9717 vty_out(vty,
2986cac2 9718 "Stale Path Remaining(sec)%*s: %ld\n",
9719 14, "",
9720 thread_timer_remain_second(
13909c4f
DS
9721 peer->t_gr_stale));
9722 }
9723 /* Display Configured Selection
9724 * Deferral only when when
9725 * Gr mode is enabled.
9726 */
9727 if (CHECK_FLAG(peer->flags,
9728 PEER_FLAG_GRACEFUL_RESTART)) {
9729 vty_out(vty, "%*s", 6, "");
9730 vty_out(vty,
3a75afa4 9731 "Configured Selection Deferral Time(sec): %u\n",
9732 peer->bgp->select_defer_time);
13909c4f 9733 }
2986cac2 9734
13909c4f
DS
9735 if (peer->bgp->gr_info[afi][safi]
9736 .t_select_deferral
9737 != NULL) {
2986cac2 9738
13909c4f
DS
9739 vty_out(vty, "%*s", 6, "");
9740 vty_out(vty,
2986cac2 9741 "Selection Deferral Time Remaining(sec) : %ld\n",
9742 thread_timer_remain_second(
13909c4f
DS
9743 peer->bgp
9744 ->gr_info[afi]
9745 [safi]
9746 .t_select_deferral));
2986cac2 9747 }
9748 }
13909c4f
DS
9749 if (use_json) {
9750 json_object_object_add(json_afi_safi,
9751 "endOfRibStatus",
9752 json_endofrib_status);
9753 json_object_object_add(json_afi_safi, "timers",
9754 json_timer);
9755 json_object_object_add(
9756 json, get_afi_safi_str(afi, safi, true),
9757 json_afi_safi);
9758 }
2986cac2 9759 }
9760 }
9761}
9762
9763static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9764 struct peer *p,
9765 bool use_json,
9766 json_object *json)
9767{
9768 if (use_json) {
9769 json_object *json_timer = NULL;
9770
9771 json_timer = json_object_new_object();
9772
13909c4f
DS
9773 json_object_int_add(json_timer, "configuredRestartTimer",
9774 p->bgp->restart_time);
2986cac2 9775
13909c4f
DS
9776 json_object_int_add(json_timer, "receivedRestartTimer",
9777 p->v_gr_restart);
2986cac2 9778
13909c4f
DS
9779 if (p->t_gr_restart != NULL)
9780 json_object_int_add(
9781 json_timer, "restartTimerRemaining",
9782 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9783
9784 json_object_object_add(json, "timers", json_timer);
9785 } else {
9786
9787 vty_out(vty, " Timers :\n");
13909c4f
DS
9788 vty_out(vty, " Configured Restart Time(sec) : %u\n",
9789 p->bgp->restart_time);
2986cac2 9790
13909c4f
DS
9791 vty_out(vty, " Received Restart Time(sec) : %u\n",
9792 p->v_gr_restart);
9793 if (p->t_gr_restart != NULL)
2986cac2 9794 vty_out(vty,
13909c4f
DS
9795 " Restart Time Remaining(sec) : %ld\n",
9796 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9797 }
9798}
9799
9800static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
9801 bool use_json,
9802 json_object *json)
9803{
9804 char buf[SU_ADDRSTRLEN] = {0};
9805 char dn_flag[2] = {0};
9806 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9807
2986cac2 9808 if (!p->conf_if && peer_dynamic_neighbor(p))
9809 dn_flag[0] = '*';
9810
9811 if (p->conf_if) {
9812 if (use_json)
13909c4f
DS
9813 json_object_string_add(
9814 json, "neighborAddr",
2986cac2 9815 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
9816 ? "none"
9817 : sockunion2str(&p->su, buf,
9818 SU_ADDRSTRLEN));
2986cac2 9819 else
13909c4f 9820 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 9821 BGP_PEER_SU_UNSPEC(p)
9822 ? "none"
9823 : sockunion2str(&p->su, buf,
9824 SU_ADDRSTRLEN));
9825 } else {
9826 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9827
9828 if (use_json)
9829 json_object_string_add(
9830 json, "neighborAddr",
9831 neighborAddr);
9832 else
9833 vty_out(vty, "BGP neighbor is %s\n",
9834 neighborAddr);
9835 }
9836
9837 /* more gr info in new format */
9838 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9839}
9840
d62a17ae 9841static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 9842 safi_t safi, bool use_json,
d62a17ae 9843 json_object *json_neigh)
9844{
0291c246
MK
9845 struct bgp_filter *filter;
9846 struct peer_af *paf;
9847 char orf_pfx_name[BUFSIZ];
9848 int orf_pfx_count;
9849 json_object *json_af = NULL;
9850 json_object *json_prefA = NULL;
9851 json_object *json_prefB = NULL;
9852 json_object *json_addr = NULL;
d62a17ae 9853
9854 if (use_json) {
9855 json_addr = json_object_new_object();
9856 json_af = json_object_new_object();
9857 filter = &p->filter[afi][safi];
9858
9859 if (peer_group_active(p))
9860 json_object_string_add(json_addr, "peerGroupMember",
9861 p->group->name);
9862
9863 paf = peer_af_find(p, afi, safi);
9864 if (paf && PAF_SUBGRP(paf)) {
9865 json_object_int_add(json_addr, "updateGroupId",
9866 PAF_UPDGRP(paf)->id);
9867 json_object_int_add(json_addr, "subGroupId",
9868 PAF_SUBGRP(paf)->id);
9869 json_object_int_add(json_addr, "packetQueueLength",
9870 bpacket_queue_virtual_length(paf));
9871 }
9872
9873 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9874 || CHECK_FLAG(p->af_cap[afi][safi],
9875 PEER_CAP_ORF_PREFIX_SM_RCV)
9876 || CHECK_FLAG(p->af_cap[afi][safi],
9877 PEER_CAP_ORF_PREFIX_RM_ADV)
9878 || CHECK_FLAG(p->af_cap[afi][safi],
9879 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9880 json_object_int_add(json_af, "orfType",
9881 ORF_TYPE_PREFIX);
9882 json_prefA = json_object_new_object();
9883 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9884 PEER_CAP_ORF_PREFIX_SM_ADV,
9885 PEER_CAP_ORF_PREFIX_RM_ADV,
9886 PEER_CAP_ORF_PREFIX_SM_RCV,
9887 PEER_CAP_ORF_PREFIX_RM_RCV,
9888 use_json, json_prefA);
9889 json_object_object_add(json_af, "orfPrefixList",
9890 json_prefA);
9891 }
9892
9893 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9894 || CHECK_FLAG(p->af_cap[afi][safi],
9895 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9896 || CHECK_FLAG(p->af_cap[afi][safi],
9897 PEER_CAP_ORF_PREFIX_RM_ADV)
9898 || CHECK_FLAG(p->af_cap[afi][safi],
9899 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9900 json_object_int_add(json_af, "orfOldType",
9901 ORF_TYPE_PREFIX_OLD);
9902 json_prefB = json_object_new_object();
9903 bgp_show_peer_afi_orf_cap(
9904 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9905 PEER_CAP_ORF_PREFIX_RM_ADV,
9906 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9907 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9908 json_prefB);
9909 json_object_object_add(json_af, "orfOldPrefixList",
9910 json_prefB);
9911 }
9912
9913 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9914 || CHECK_FLAG(p->af_cap[afi][safi],
9915 PEER_CAP_ORF_PREFIX_SM_RCV)
9916 || CHECK_FLAG(p->af_cap[afi][safi],
9917 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9918 || CHECK_FLAG(p->af_cap[afi][safi],
9919 PEER_CAP_ORF_PREFIX_RM_ADV)
9920 || CHECK_FLAG(p->af_cap[afi][safi],
9921 PEER_CAP_ORF_PREFIX_RM_RCV)
9922 || CHECK_FLAG(p->af_cap[afi][safi],
9923 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9924 json_object_object_add(json_addr, "afDependentCap",
9925 json_af);
9926 else
9927 json_object_free(json_af);
9928
9929 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9930 orf_pfx_count = prefix_bgp_show_prefix_list(
9931 NULL, afi, orf_pfx_name, use_json);
9932
9933 if (CHECK_FLAG(p->af_sflags[afi][safi],
9934 PEER_STATUS_ORF_PREFIX_SEND)
9935 || orf_pfx_count) {
9936 if (CHECK_FLAG(p->af_sflags[afi][safi],
9937 PEER_STATUS_ORF_PREFIX_SEND))
9938 json_object_boolean_true_add(json_neigh,
9939 "orfSent");
9940 if (orf_pfx_count)
9941 json_object_int_add(json_addr, "orfRecvCounter",
9942 orf_pfx_count);
9943 }
9944 if (CHECK_FLAG(p->af_sflags[afi][safi],
9945 PEER_STATUS_ORF_WAIT_REFRESH))
9946 json_object_string_add(
9947 json_addr, "orfFirstUpdate",
9948 "deferredUntilORFOrRouteRefreshRecvd");
9949
9950 if (CHECK_FLAG(p->af_flags[afi][safi],
9951 PEER_FLAG_REFLECTOR_CLIENT))
9952 json_object_boolean_true_add(json_addr,
9953 "routeReflectorClient");
9954 if (CHECK_FLAG(p->af_flags[afi][safi],
9955 PEER_FLAG_RSERVER_CLIENT))
9956 json_object_boolean_true_add(json_addr,
9957 "routeServerClient");
9958 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9959 json_object_boolean_true_add(json_addr,
9960 "inboundSoftConfigPermit");
9961
9962 if (CHECK_FLAG(p->af_flags[afi][safi],
9963 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9964 json_object_boolean_true_add(
9965 json_addr,
9966 "privateAsNumsAllReplacedInUpdatesToNbr");
9967 else if (CHECK_FLAG(p->af_flags[afi][safi],
9968 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9969 json_object_boolean_true_add(
9970 json_addr,
9971 "privateAsNumsReplacedInUpdatesToNbr");
9972 else if (CHECK_FLAG(p->af_flags[afi][safi],
9973 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9974 json_object_boolean_true_add(
9975 json_addr,
9976 "privateAsNumsAllRemovedInUpdatesToNbr");
9977 else if (CHECK_FLAG(p->af_flags[afi][safi],
9978 PEER_FLAG_REMOVE_PRIVATE_AS))
9979 json_object_boolean_true_add(
9980 json_addr,
9981 "privateAsNumsRemovedInUpdatesToNbr");
9982
dcc68b5e
MS
9983 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9984 json_object_boolean_true_add(
9985 json_addr,
9986 bgp_addpath_names(p->addpath_type[afi][safi])
9987 ->type_json_name);
d62a17ae 9988
9989 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9990 json_object_string_add(json_addr,
9991 "overrideASNsInOutboundUpdates",
9992 "ifAspathEqualRemoteAs");
9993
9994 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9995 || CHECK_FLAG(p->af_flags[afi][safi],
9996 PEER_FLAG_FORCE_NEXTHOP_SELF))
9997 json_object_boolean_true_add(json_addr,
9998 "routerAlwaysNextHop");
9999 if (CHECK_FLAG(p->af_flags[afi][safi],
10000 PEER_FLAG_AS_PATH_UNCHANGED))
10001 json_object_boolean_true_add(
10002 json_addr, "unchangedAsPathPropogatedToNbr");
10003 if (CHECK_FLAG(p->af_flags[afi][safi],
10004 PEER_FLAG_NEXTHOP_UNCHANGED))
10005 json_object_boolean_true_add(
10006 json_addr, "unchangedNextHopPropogatedToNbr");
10007 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10008 json_object_boolean_true_add(
10009 json_addr, "unchangedMedPropogatedToNbr");
10010 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10011 || CHECK_FLAG(p->af_flags[afi][safi],
10012 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10013 if (CHECK_FLAG(p->af_flags[afi][safi],
10014 PEER_FLAG_SEND_COMMUNITY)
10015 && CHECK_FLAG(p->af_flags[afi][safi],
10016 PEER_FLAG_SEND_EXT_COMMUNITY))
10017 json_object_string_add(json_addr,
10018 "commAttriSentToNbr",
10019 "extendedAndStandard");
10020 else if (CHECK_FLAG(p->af_flags[afi][safi],
10021 PEER_FLAG_SEND_EXT_COMMUNITY))
10022 json_object_string_add(json_addr,
10023 "commAttriSentToNbr",
10024 "extended");
10025 else
10026 json_object_string_add(json_addr,
10027 "commAttriSentToNbr",
10028 "standard");
10029 }
10030 if (CHECK_FLAG(p->af_flags[afi][safi],
10031 PEER_FLAG_DEFAULT_ORIGINATE)) {
10032 if (p->default_rmap[afi][safi].name)
10033 json_object_string_add(
10034 json_addr, "defaultRouteMap",
10035 p->default_rmap[afi][safi].name);
10036
10037 if (paf && PAF_SUBGRP(paf)
10038 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10039 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10040 json_object_boolean_true_add(json_addr,
10041 "defaultSent");
10042 else
10043 json_object_boolean_true_add(json_addr,
10044 "defaultNotSent");
10045 }
10046
dff8f48d 10047 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10048 if (is_evpn_enabled())
60466a63
QY
10049 json_object_boolean_true_add(
10050 json_addr, "advertiseAllVnis");
dff8f48d
MK
10051 }
10052
d62a17ae 10053 if (filter->plist[FILTER_IN].name
10054 || filter->dlist[FILTER_IN].name
10055 || filter->aslist[FILTER_IN].name
10056 || filter->map[RMAP_IN].name)
10057 json_object_boolean_true_add(json_addr,
10058 "inboundPathPolicyConfig");
10059 if (filter->plist[FILTER_OUT].name
10060 || filter->dlist[FILTER_OUT].name
10061 || filter->aslist[FILTER_OUT].name
10062 || filter->map[RMAP_OUT].name || filter->usmap.name)
10063 json_object_boolean_true_add(
10064 json_addr, "outboundPathPolicyConfig");
10065
10066 /* prefix-list */
10067 if (filter->plist[FILTER_IN].name)
10068 json_object_string_add(json_addr,
10069 "incomingUpdatePrefixFilterList",
10070 filter->plist[FILTER_IN].name);
10071 if (filter->plist[FILTER_OUT].name)
10072 json_object_string_add(json_addr,
10073 "outgoingUpdatePrefixFilterList",
10074 filter->plist[FILTER_OUT].name);
10075
10076 /* distribute-list */
10077 if (filter->dlist[FILTER_IN].name)
10078 json_object_string_add(
10079 json_addr, "incomingUpdateNetworkFilterList",
10080 filter->dlist[FILTER_IN].name);
10081 if (filter->dlist[FILTER_OUT].name)
10082 json_object_string_add(
10083 json_addr, "outgoingUpdateNetworkFilterList",
10084 filter->dlist[FILTER_OUT].name);
10085
10086 /* filter-list. */
10087 if (filter->aslist[FILTER_IN].name)
10088 json_object_string_add(json_addr,
10089 "incomingUpdateAsPathFilterList",
10090 filter->aslist[FILTER_IN].name);
10091 if (filter->aslist[FILTER_OUT].name)
10092 json_object_string_add(json_addr,
10093 "outgoingUpdateAsPathFilterList",
10094 filter->aslist[FILTER_OUT].name);
10095
10096 /* route-map. */
10097 if (filter->map[RMAP_IN].name)
10098 json_object_string_add(
10099 json_addr, "routeMapForIncomingAdvertisements",
10100 filter->map[RMAP_IN].name);
10101 if (filter->map[RMAP_OUT].name)
10102 json_object_string_add(
10103 json_addr, "routeMapForOutgoingAdvertisements",
10104 filter->map[RMAP_OUT].name);
10105
9dac9fc8
DA
10106 /* ebgp-requires-policy (inbound) */
10107 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10108 && !bgp_inbound_policy_exists(p, filter))
10109 json_object_string_add(
10110 json_addr, "inboundEbgpRequiresPolicy",
10111 "Inbound updates discarded due to missing policy");
10112
10113 /* ebgp-requires-policy (outbound) */
10114 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10115 && (!bgp_outbound_policy_exists(p, filter)))
10116 json_object_string_add(
10117 json_addr, "outboundEbgpRequiresPolicy",
10118 "Outbound updates discarded due to missing policy");
10119
d62a17ae 10120 /* unsuppress-map */
10121 if (filter->usmap.name)
10122 json_object_string_add(json_addr,
10123 "selectiveUnsuppressRouteMap",
10124 filter->usmap.name);
10125
10126 /* Receive prefix count */
10127 json_object_int_add(json_addr, "acceptedPrefixCounter",
10128 p->pcount[afi][safi]);
50e05855
AD
10129 if (paf && PAF_SUBGRP(paf))
10130 json_object_int_add(json_addr, "sentPrefixCounter",
10131 (PAF_SUBGRP(paf))->scount);
d62a17ae 10132
fde246e8
DA
10133 /* Maximum prefix */
10134 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10135 json_object_int_add(json_addr, "prefixOutAllowedMax",
10136 p->pmax_out[afi][safi]);
10137
d62a17ae 10138 /* Maximum prefix */
10139 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10140 json_object_int_add(json_addr, "prefixAllowedMax",
10141 p->pmax[afi][safi]);
10142 if (CHECK_FLAG(p->af_flags[afi][safi],
10143 PEER_FLAG_MAX_PREFIX_WARNING))
10144 json_object_boolean_true_add(
10145 json_addr, "prefixAllowedMaxWarning");
10146 json_object_int_add(json_addr,
10147 "prefixAllowedWarningThresh",
10148 p->pmax_threshold[afi][safi]);
10149 if (p->pmax_restart[afi][safi])
10150 json_object_int_add(
10151 json_addr,
10152 "prefixAllowedRestartIntervalMsecs",
10153 p->pmax_restart[afi][safi] * 60000);
10154 }
2986cac2 10155 json_object_object_add(json_neigh,
10156 get_afi_safi_str(afi,
10157 safi, true),
d62a17ae 10158 json_addr);
10159
10160 } else {
10161 filter = &p->filter[afi][safi];
10162
10163 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10164 get_afi_safi_str(afi, safi, false));
d62a17ae 10165
10166 if (peer_group_active(p))
10167 vty_out(vty, " %s peer-group member\n",
10168 p->group->name);
10169
10170 paf = peer_af_find(p, afi, safi);
10171 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
10172 vty_out(vty, " Update group %" PRIu64
10173 ", subgroup %" PRIu64 "\n",
d62a17ae 10174 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10175 vty_out(vty, " Packet Queue length %d\n",
10176 bpacket_queue_virtual_length(paf));
10177 } else {
10178 vty_out(vty, " Not part of any update group\n");
10179 }
10180 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10181 || CHECK_FLAG(p->af_cap[afi][safi],
10182 PEER_CAP_ORF_PREFIX_SM_RCV)
10183 || CHECK_FLAG(p->af_cap[afi][safi],
10184 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10185 || CHECK_FLAG(p->af_cap[afi][safi],
10186 PEER_CAP_ORF_PREFIX_RM_ADV)
10187 || CHECK_FLAG(p->af_cap[afi][safi],
10188 PEER_CAP_ORF_PREFIX_RM_RCV)
10189 || CHECK_FLAG(p->af_cap[afi][safi],
10190 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10191 vty_out(vty, " AF-dependant capabilities:\n");
10192
10193 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10194 || CHECK_FLAG(p->af_cap[afi][safi],
10195 PEER_CAP_ORF_PREFIX_SM_RCV)
10196 || CHECK_FLAG(p->af_cap[afi][safi],
10197 PEER_CAP_ORF_PREFIX_RM_ADV)
10198 || CHECK_FLAG(p->af_cap[afi][safi],
10199 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10200 vty_out(vty,
10201 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10202 ORF_TYPE_PREFIX);
10203 bgp_show_peer_afi_orf_cap(
10204 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10205 PEER_CAP_ORF_PREFIX_RM_ADV,
10206 PEER_CAP_ORF_PREFIX_SM_RCV,
10207 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10208 }
10209 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10210 || CHECK_FLAG(p->af_cap[afi][safi],
10211 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10212 || CHECK_FLAG(p->af_cap[afi][safi],
10213 PEER_CAP_ORF_PREFIX_RM_ADV)
10214 || CHECK_FLAG(p->af_cap[afi][safi],
10215 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10216 vty_out(vty,
10217 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10218 ORF_TYPE_PREFIX_OLD);
10219 bgp_show_peer_afi_orf_cap(
10220 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10221 PEER_CAP_ORF_PREFIX_RM_ADV,
10222 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10223 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10224 }
10225
10226 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10227 orf_pfx_count = prefix_bgp_show_prefix_list(
10228 NULL, afi, orf_pfx_name, use_json);
10229
10230 if (CHECK_FLAG(p->af_sflags[afi][safi],
10231 PEER_STATUS_ORF_PREFIX_SEND)
10232 || orf_pfx_count) {
10233 vty_out(vty, " Outbound Route Filter (ORF):");
10234 if (CHECK_FLAG(p->af_sflags[afi][safi],
10235 PEER_STATUS_ORF_PREFIX_SEND))
10236 vty_out(vty, " sent;");
10237 if (orf_pfx_count)
10238 vty_out(vty, " received (%d entries)",
10239 orf_pfx_count);
10240 vty_out(vty, "\n");
10241 }
10242 if (CHECK_FLAG(p->af_sflags[afi][safi],
10243 PEER_STATUS_ORF_WAIT_REFRESH))
10244 vty_out(vty,
10245 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10246
10247 if (CHECK_FLAG(p->af_flags[afi][safi],
10248 PEER_FLAG_REFLECTOR_CLIENT))
10249 vty_out(vty, " Route-Reflector Client\n");
10250 if (CHECK_FLAG(p->af_flags[afi][safi],
10251 PEER_FLAG_RSERVER_CLIENT))
10252 vty_out(vty, " Route-Server Client\n");
10253 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10254 vty_out(vty,
10255 " Inbound soft reconfiguration allowed\n");
10256
10257 if (CHECK_FLAG(p->af_flags[afi][safi],
10258 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10259 vty_out(vty,
10260 " Private AS numbers (all) replaced in updates to this neighbor\n");
10261 else if (CHECK_FLAG(p->af_flags[afi][safi],
10262 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10263 vty_out(vty,
10264 " Private AS numbers replaced in updates to this neighbor\n");
10265 else if (CHECK_FLAG(p->af_flags[afi][safi],
10266 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10267 vty_out(vty,
10268 " Private AS numbers (all) removed in updates to this neighbor\n");
10269 else if (CHECK_FLAG(p->af_flags[afi][safi],
10270 PEER_FLAG_REMOVE_PRIVATE_AS))
10271 vty_out(vty,
10272 " Private AS numbers removed in updates to this neighbor\n");
10273
dcc68b5e
MS
10274 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10275 vty_out(vty, " %s\n",
10276 bgp_addpath_names(p->addpath_type[afi][safi])
10277 ->human_description);
d62a17ae 10278
10279 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10280 vty_out(vty,
10281 " Override ASNs in outbound updates if aspath equals remote-as\n");
10282
10283 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10284 || CHECK_FLAG(p->af_flags[afi][safi],
10285 PEER_FLAG_FORCE_NEXTHOP_SELF))
10286 vty_out(vty, " NEXT_HOP is always this router\n");
10287 if (CHECK_FLAG(p->af_flags[afi][safi],
10288 PEER_FLAG_AS_PATH_UNCHANGED))
10289 vty_out(vty,
10290 " AS_PATH is propagated unchanged to this neighbor\n");
10291 if (CHECK_FLAG(p->af_flags[afi][safi],
10292 PEER_FLAG_NEXTHOP_UNCHANGED))
10293 vty_out(vty,
10294 " NEXT_HOP is propagated unchanged to this neighbor\n");
10295 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10296 vty_out(vty,
10297 " MED is propagated unchanged to this neighbor\n");
10298 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10299 || CHECK_FLAG(p->af_flags[afi][safi],
10300 PEER_FLAG_SEND_EXT_COMMUNITY)
10301 || CHECK_FLAG(p->af_flags[afi][safi],
10302 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10303 vty_out(vty,
10304 " Community attribute sent to this neighbor");
10305 if (CHECK_FLAG(p->af_flags[afi][safi],
10306 PEER_FLAG_SEND_COMMUNITY)
10307 && CHECK_FLAG(p->af_flags[afi][safi],
10308 PEER_FLAG_SEND_EXT_COMMUNITY)
10309 && CHECK_FLAG(p->af_flags[afi][safi],
10310 PEER_FLAG_SEND_LARGE_COMMUNITY))
10311 vty_out(vty, "(all)\n");
10312 else if (CHECK_FLAG(p->af_flags[afi][safi],
10313 PEER_FLAG_SEND_LARGE_COMMUNITY))
10314 vty_out(vty, "(large)\n");
10315 else if (CHECK_FLAG(p->af_flags[afi][safi],
10316 PEER_FLAG_SEND_EXT_COMMUNITY))
10317 vty_out(vty, "(extended)\n");
10318 else
10319 vty_out(vty, "(standard)\n");
10320 }
10321 if (CHECK_FLAG(p->af_flags[afi][safi],
10322 PEER_FLAG_DEFAULT_ORIGINATE)) {
10323 vty_out(vty, " Default information originate,");
10324
10325 if (p->default_rmap[afi][safi].name)
10326 vty_out(vty, " default route-map %s%s,",
10327 p->default_rmap[afi][safi].map ? "*"
10328 : "",
10329 p->default_rmap[afi][safi].name);
10330 if (paf && PAF_SUBGRP(paf)
10331 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10332 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10333 vty_out(vty, " default sent\n");
10334 else
10335 vty_out(vty, " default not sent\n");
10336 }
10337
dff8f48d
MK
10338 /* advertise-vni-all */
10339 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10340 if (is_evpn_enabled())
dff8f48d
MK
10341 vty_out(vty, " advertise-all-vni\n");
10342 }
10343
d62a17ae 10344 if (filter->plist[FILTER_IN].name
10345 || filter->dlist[FILTER_IN].name
10346 || filter->aslist[FILTER_IN].name
10347 || filter->map[RMAP_IN].name)
10348 vty_out(vty, " Inbound path policy configured\n");
10349 if (filter->plist[FILTER_OUT].name
10350 || filter->dlist[FILTER_OUT].name
10351 || filter->aslist[FILTER_OUT].name
10352 || filter->map[RMAP_OUT].name || filter->usmap.name)
10353 vty_out(vty, " Outbound path policy configured\n");
10354
10355 /* prefix-list */
10356 if (filter->plist[FILTER_IN].name)
10357 vty_out(vty,
10358 " Incoming update prefix filter list is %s%s\n",
10359 filter->plist[FILTER_IN].plist ? "*" : "",
10360 filter->plist[FILTER_IN].name);
10361 if (filter->plist[FILTER_OUT].name)
10362 vty_out(vty,
10363 " Outgoing update prefix filter list is %s%s\n",
10364 filter->plist[FILTER_OUT].plist ? "*" : "",
10365 filter->plist[FILTER_OUT].name);
10366
10367 /* distribute-list */
10368 if (filter->dlist[FILTER_IN].name)
10369 vty_out(vty,
10370 " Incoming update network filter list is %s%s\n",
10371 filter->dlist[FILTER_IN].alist ? "*" : "",
10372 filter->dlist[FILTER_IN].name);
10373 if (filter->dlist[FILTER_OUT].name)
10374 vty_out(vty,
10375 " Outgoing update network filter list is %s%s\n",
10376 filter->dlist[FILTER_OUT].alist ? "*" : "",
10377 filter->dlist[FILTER_OUT].name);
10378
10379 /* filter-list. */
10380 if (filter->aslist[FILTER_IN].name)
10381 vty_out(vty,
10382 " Incoming update AS path filter list is %s%s\n",
10383 filter->aslist[FILTER_IN].aslist ? "*" : "",
10384 filter->aslist[FILTER_IN].name);
10385 if (filter->aslist[FILTER_OUT].name)
10386 vty_out(vty,
10387 " Outgoing update AS path filter list is %s%s\n",
10388 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10389 filter->aslist[FILTER_OUT].name);
10390
10391 /* route-map. */
10392 if (filter->map[RMAP_IN].name)
10393 vty_out(vty,
10394 " Route map for incoming advertisements is %s%s\n",
10395 filter->map[RMAP_IN].map ? "*" : "",
10396 filter->map[RMAP_IN].name);
10397 if (filter->map[RMAP_OUT].name)
10398 vty_out(vty,
10399 " Route map for outgoing advertisements is %s%s\n",
10400 filter->map[RMAP_OUT].map ? "*" : "",
10401 filter->map[RMAP_OUT].name);
10402
9dac9fc8
DA
10403 /* ebgp-requires-policy (inbound) */
10404 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10405 && !bgp_inbound_policy_exists(p, filter))
10406 vty_out(vty,
10407 " Inbound updates discarded due to missing policy\n");
10408
10409 /* ebgp-requires-policy (outbound) */
10410 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10411 && !bgp_outbound_policy_exists(p, filter))
10412 vty_out(vty,
10413 " Outbound updates discarded due to missing policy\n");
10414
d62a17ae 10415 /* unsuppress-map */
10416 if (filter->usmap.name)
10417 vty_out(vty,
10418 " Route map for selective unsuppress is %s%s\n",
10419 filter->usmap.map ? "*" : "",
10420 filter->usmap.name);
10421
10422 /* Receive prefix count */
a0a87037
DA
10423 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10424 p->pcount[afi][safi]);
d62a17ae 10425
fde246e8
DA
10426 /* maximum-prefix-out */
10427 if (CHECK_FLAG(p->af_flags[afi][safi],
10428 PEER_FLAG_MAX_PREFIX_OUT))
10429 vty_out(vty,
10430 " Maximum allowed prefixes sent %" PRIu32 "\n",
10431 p->pmax_out[afi][safi]);
10432
d62a17ae 10433 /* Maximum prefix */
10434 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
10435 vty_out(vty,
10436 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 10437 p->pmax[afi][safi],
10438 CHECK_FLAG(p->af_flags[afi][safi],
10439 PEER_FLAG_MAX_PREFIX_WARNING)
10440 ? " (warning-only)"
10441 : "");
10442 vty_out(vty, " Threshold for warning message %d%%",
10443 p->pmax_threshold[afi][safi]);
10444 if (p->pmax_restart[afi][safi])
10445 vty_out(vty, ", restart interval %d min",
10446 p->pmax_restart[afi][safi]);
10447 vty_out(vty, "\n");
10448 }
10449
10450 vty_out(vty, "\n");
10451 }
10452}
10453
9f049418 10454static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10455 json_object *json)
718e3744 10456{
d62a17ae 10457 struct bgp *bgp;
10458 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10459 char timebuf[BGP_UPTIME_LEN];
10460 char dn_flag[2];
d62a17ae 10461 afi_t afi;
10462 safi_t safi;
d7c0a89a
QY
10463 uint16_t i;
10464 uint8_t *msg;
d62a17ae 10465 json_object *json_neigh = NULL;
10466 time_t epoch_tbuf;
718e3744 10467
d62a17ae 10468 bgp = p->bgp;
10469
10470 if (use_json)
10471 json_neigh = json_object_new_object();
10472
10473 memset(dn_flag, '\0', sizeof(dn_flag));
10474 if (!p->conf_if && peer_dynamic_neighbor(p))
10475 dn_flag[0] = '*';
10476
10477 if (!use_json) {
10478 if (p->conf_if) /* Configured interface name. */
10479 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10480 BGP_PEER_SU_UNSPEC(p)
10481 ? "None"
10482 : sockunion2str(&p->su, buf,
10483 SU_ADDRSTRLEN));
10484 else /* Configured IP address. */
10485 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10486 p->host);
10487 }
10488
10489 if (use_json) {
10490 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10491 json_object_string_add(json_neigh, "bgpNeighborAddr",
10492 "none");
10493 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10494 json_object_string_add(
10495 json_neigh, "bgpNeighborAddr",
10496 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10497
10498 json_object_int_add(json_neigh, "remoteAs", p->as);
10499
10500 if (p->change_local_as)
10501 json_object_int_add(json_neigh, "localAs",
10502 p->change_local_as);
10503 else
10504 json_object_int_add(json_neigh, "localAs", p->local_as);
10505
10506 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10507 json_object_boolean_true_add(json_neigh,
10508 "localAsNoPrepend");
10509
10510 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10511 json_object_boolean_true_add(json_neigh,
10512 "localAsReplaceAs");
10513 } else {
10514 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10515 || (p->as_type == AS_INTERNAL))
10516 vty_out(vty, "remote AS %u, ", p->as);
10517 else
10518 vty_out(vty, "remote AS Unspecified, ");
10519 vty_out(vty, "local AS %u%s%s, ",
10520 p->change_local_as ? p->change_local_as : p->local_as,
10521 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10522 ? " no-prepend"
10523 : "",
10524 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10525 ? " replace-as"
10526 : "");
10527 }
faa16034
DS
10528 /* peer type internal or confed-internal */
10529 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10530 if (use_json) {
10531 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10532 json_object_boolean_true_add(
10533 json_neigh, "nbrConfedInternalLink");
10534 else
10535 json_object_boolean_true_add(json_neigh,
10536 "nbrInternalLink");
10537 } else {
10538 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10539 vty_out(vty, "confed-internal link\n");
10540 else
10541 vty_out(vty, "internal link\n");
10542 }
faa16034
DS
10543 /* peer type external or confed-external */
10544 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10545 if (use_json) {
10546 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10547 json_object_boolean_true_add(
10548 json_neigh, "nbrConfedExternalLink");
10549 else
10550 json_object_boolean_true_add(json_neigh,
10551 "nbrExternalLink");
10552 } else {
10553 if (bgp_confederation_peers_check(bgp, p->as))
10554 vty_out(vty, "confed-external link\n");
10555 else
10556 vty_out(vty, "external link\n");
10557 }
faa16034
DS
10558 } else {
10559 if (use_json)
10560 json_object_boolean_true_add(json_neigh,
10561 "nbrUnspecifiedLink");
10562 else
10563 vty_out(vty, "unspecified link\n");
d62a17ae 10564 }
10565
10566 /* Description. */
10567 if (p->desc) {
10568 if (use_json)
10569 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10570 else
10571 vty_out(vty, " Description: %s\n", p->desc);
10572 }
10573
10574 if (p->hostname) {
10575 if (use_json) {
10576 if (p->hostname)
10577 json_object_string_add(json_neigh, "hostname",
10578 p->hostname);
10579
10580 if (p->domainname)
10581 json_object_string_add(json_neigh, "domainname",
10582 p->domainname);
10583 } else {
10584 if (p->domainname && (p->domainname[0] != '\0'))
10585 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10586 p->domainname);
10587 else
10588 vty_out(vty, "Hostname: %s\n", p->hostname);
10589 }
10590 }
10591
10592 /* Peer-group */
10593 if (p->group) {
10594 if (use_json) {
10595 json_object_string_add(json_neigh, "peerGroup",
10596 p->group->name);
10597
10598 if (dn_flag[0]) {
10599 struct prefix prefix, *range = NULL;
10600
10601 sockunion2hostprefix(&(p->su), &prefix);
10602 range = peer_group_lookup_dynamic_neighbor_range(
10603 p->group, &prefix);
10604
10605 if (range) {
10606 prefix2str(range, buf1, sizeof(buf1));
10607 json_object_string_add(
10608 json_neigh,
10609 "peerSubnetRangeGroup", buf1);
10610 }
10611 }
10612 } else {
10613 vty_out(vty,
10614 " Member of peer-group %s for session parameters\n",
10615 p->group->name);
10616
10617 if (dn_flag[0]) {
10618 struct prefix prefix, *range = NULL;
10619
10620 sockunion2hostprefix(&(p->su), &prefix);
10621 range = peer_group_lookup_dynamic_neighbor_range(
10622 p->group, &prefix);
10623
10624 if (range) {
10625 prefix2str(range, buf1, sizeof(buf1));
10626 vty_out(vty,
10627 " Belongs to the subnet range group: %s\n",
10628 buf1);
10629 }
10630 }
10631 }
10632 }
10633
10634 if (use_json) {
10635 /* Administrative shutdown. */
10636 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10637 json_object_boolean_true_add(json_neigh,
10638 "adminShutDown");
10639
10640 /* BGP Version. */
10641 json_object_int_add(json_neigh, "bgpVersion", 4);
10642 json_object_string_add(
10643 json_neigh, "remoteRouterId",
10644 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10645 json_object_string_add(
10646 json_neigh, "localRouterId",
10647 inet_ntop(AF_INET, &bgp->router_id, buf1,
10648 sizeof(buf1)));
d62a17ae 10649
10650 /* Confederation */
10651 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10652 && bgp_confederation_peers_check(bgp, p->as))
10653 json_object_boolean_true_add(json_neigh,
10654 "nbrCommonAdmin");
10655
10656 /* Status. */
10657 json_object_string_add(
10658 json_neigh, "bgpState",
10659 lookup_msg(bgp_status_msg, p->status, NULL));
10660
10661 if (p->status == Established) {
10662 time_t uptime;
d62a17ae 10663
10664 uptime = bgp_clock();
10665 uptime -= p->uptime;
d62a17ae 10666 epoch_tbuf = time(NULL) - uptime;
10667
d3c7efed
DS
10668 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10669 uptime * 1000);
d62a17ae 10670 json_object_string_add(json_neigh, "bgpTimerUpString",
10671 peer_uptime(p->uptime, timebuf,
10672 BGP_UPTIME_LEN, 0,
10673 NULL));
10674 json_object_int_add(json_neigh,
10675 "bgpTimerUpEstablishedEpoch",
10676 epoch_tbuf);
10677 }
10678
10679 else if (p->status == Active) {
10680 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10681 json_object_string_add(json_neigh, "bgpStateIs",
10682 "passive");
10683 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10684 json_object_string_add(json_neigh, "bgpStateIs",
10685 "passiveNSF");
10686 }
10687
10688 /* read timer */
10689 time_t uptime;
10690 struct tm *tm;
10691
10692 uptime = bgp_clock();
10693 uptime -= p->readtime;
10694 tm = gmtime(&uptime);
10695 json_object_int_add(json_neigh, "bgpTimerLastRead",
10696 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10697 + (tm->tm_hour * 3600000));
10698
10699 uptime = bgp_clock();
10700 uptime -= p->last_write;
10701 tm = gmtime(&uptime);
10702 json_object_int_add(json_neigh, "bgpTimerLastWrite",
10703 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10704 + (tm->tm_hour * 3600000));
10705
10706 uptime = bgp_clock();
10707 uptime -= p->update_time;
10708 tm = gmtime(&uptime);
10709 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
10710 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10711 + (tm->tm_hour * 3600000));
10712
10713 /* Configured timer values. */
10714 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10715 p->v_holdtime * 1000);
10716 json_object_int_add(json_neigh,
10717 "bgpTimerKeepAliveIntervalMsecs",
10718 p->v_keepalive * 1000);
b90a8e13 10719 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10720 json_object_int_add(json_neigh,
10721 "bgpTimerConfiguredHoldTimeMsecs",
10722 p->holdtime * 1000);
10723 json_object_int_add(
10724 json_neigh,
10725 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10726 p->keepalive * 1000);
5d5393b9
DL
10727 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10728 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10729 json_object_int_add(json_neigh,
10730 "bgpTimerConfiguredHoldTimeMsecs",
10731 bgp->default_holdtime);
10732 json_object_int_add(
10733 json_neigh,
10734 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10735 bgp->default_keepalive);
d62a17ae 10736 }
10737 } else {
10738 /* Administrative shutdown. */
10739 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10740 vty_out(vty, " Administratively shut down\n");
10741
10742 /* BGP Version. */
10743 vty_out(vty, " BGP version 4");
0e38aeb4 10744 vty_out(vty, ", remote router ID %s",
d62a17ae 10745 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
10746 vty_out(vty, ", local router ID %s\n",
10747 inet_ntop(AF_INET, &bgp->router_id, buf1,
10748 sizeof(buf1)));
d62a17ae 10749
10750 /* Confederation */
10751 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10752 && bgp_confederation_peers_check(bgp, p->as))
10753 vty_out(vty,
10754 " Neighbor under common administration\n");
10755
10756 /* Status. */
10757 vty_out(vty, " BGP state = %s",
10758 lookup_msg(bgp_status_msg, p->status, NULL));
10759
10760 if (p->status == Established)
10761 vty_out(vty, ", up for %8s",
10762 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10763 0, NULL));
10764
10765 else if (p->status == Active) {
10766 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10767 vty_out(vty, " (passive)");
10768 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10769 vty_out(vty, " (NSF passive)");
10770 }
10771 vty_out(vty, "\n");
10772
10773 /* read timer */
10774 vty_out(vty, " Last read %s",
10775 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10776 NULL));
10777 vty_out(vty, ", Last write %s\n",
10778 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10779 NULL));
10780
10781 /* Configured timer values. */
10782 vty_out(vty,
10783 " Hold time is %d, keepalive interval is %d seconds\n",
10784 p->v_holdtime, p->v_keepalive);
b90a8e13 10785 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10786 vty_out(vty, " Configured hold time is %d",
10787 p->holdtime);
10788 vty_out(vty, ", keepalive interval is %d seconds\n",
10789 p->keepalive);
5d5393b9
DL
10790 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10791 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10792 vty_out(vty, " Configured hold time is %d",
10793 bgp->default_holdtime);
10794 vty_out(vty, ", keepalive interval is %d seconds\n",
10795 bgp->default_keepalive);
d62a17ae 10796 }
10797 }
10798 /* Capability. */
10799 if (p->status == Established) {
10800 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10801 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10802 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10803 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10804 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10805 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10806 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10807 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10808 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10809 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10810 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10811 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 10812 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10813 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 10814 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10815 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 10816 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10817 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 10818 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10819 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10820 if (use_json) {
10821 json_object *json_cap = NULL;
10822
10823 json_cap = json_object_new_object();
10824
10825 /* AS4 */
10826 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10827 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10828 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10829 && CHECK_FLAG(p->cap,
10830 PEER_CAP_AS4_RCV))
10831 json_object_string_add(
10832 json_cap, "4byteAs",
10833 "advertisedAndReceived");
10834 else if (CHECK_FLAG(p->cap,
10835 PEER_CAP_AS4_ADV))
10836 json_object_string_add(
10837 json_cap, "4byteAs",
10838 "advertised");
10839 else if (CHECK_FLAG(p->cap,
10840 PEER_CAP_AS4_RCV))
10841 json_object_string_add(
10842 json_cap, "4byteAs",
10843 "received");
10844 }
10845
10846 /* AddPath */
10847 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10848 || CHECK_FLAG(p->cap,
10849 PEER_CAP_ADDPATH_ADV)) {
10850 json_object *json_add = NULL;
10851 const char *print_store;
10852
10853 json_add = json_object_new_object();
10854
05c7a1cc
QY
10855 FOREACH_AFI_SAFI (afi, safi) {
10856 json_object *json_sub = NULL;
10857 json_sub =
10858 json_object_new_object();
5cb5f4d0
DD
10859 print_store = get_afi_safi_str(
10860 afi, safi, true);
d62a17ae 10861
05c7a1cc
QY
10862 if (CHECK_FLAG(
10863 p->af_cap[afi]
10864 [safi],
10865 PEER_CAP_ADDPATH_AF_TX_ADV)
10866 || CHECK_FLAG(
10867 p->af_cap[afi]
10868 [safi],
10869 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 10870 if (CHECK_FLAG(
10871 p->af_cap
10872 [afi]
10873 [safi],
10874 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 10875 && CHECK_FLAG(
d62a17ae 10876 p->af_cap
10877 [afi]
10878 [safi],
05c7a1cc
QY
10879 PEER_CAP_ADDPATH_AF_TX_RCV))
10880 json_object_boolean_true_add(
10881 json_sub,
10882 "txAdvertisedAndReceived");
10883 else if (
10884 CHECK_FLAG(
10885 p->af_cap
10886 [afi]
10887 [safi],
10888 PEER_CAP_ADDPATH_AF_TX_ADV))
10889 json_object_boolean_true_add(
10890 json_sub,
10891 "txAdvertised");
10892 else if (
10893 CHECK_FLAG(
10894 p->af_cap
10895 [afi]
10896 [safi],
10897 PEER_CAP_ADDPATH_AF_TX_RCV))
10898 json_object_boolean_true_add(
10899 json_sub,
10900 "txReceived");
10901 }
d62a17ae 10902
05c7a1cc
QY
10903 if (CHECK_FLAG(
10904 p->af_cap[afi]
10905 [safi],
10906 PEER_CAP_ADDPATH_AF_RX_ADV)
10907 || CHECK_FLAG(
10908 p->af_cap[afi]
10909 [safi],
10910 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 10911 if (CHECK_FLAG(
10912 p->af_cap
10913 [afi]
10914 [safi],
10915 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 10916 && CHECK_FLAG(
d62a17ae 10917 p->af_cap
10918 [afi]
10919 [safi],
10920 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
10921 json_object_boolean_true_add(
10922 json_sub,
10923 "rxAdvertisedAndReceived");
10924 else if (
10925 CHECK_FLAG(
10926 p->af_cap
10927 [afi]
10928 [safi],
10929 PEER_CAP_ADDPATH_AF_RX_ADV))
10930 json_object_boolean_true_add(
10931 json_sub,
10932 "rxAdvertised");
10933 else if (
10934 CHECK_FLAG(
10935 p->af_cap
10936 [afi]
10937 [safi],
10938 PEER_CAP_ADDPATH_AF_RX_RCV))
10939 json_object_boolean_true_add(
10940 json_sub,
10941 "rxReceived");
d62a17ae 10942 }
10943
05c7a1cc
QY
10944 if (CHECK_FLAG(
10945 p->af_cap[afi]
10946 [safi],
10947 PEER_CAP_ADDPATH_AF_TX_ADV)
10948 || CHECK_FLAG(
10949 p->af_cap[afi]
10950 [safi],
10951 PEER_CAP_ADDPATH_AF_TX_RCV)
10952 || CHECK_FLAG(
10953 p->af_cap[afi]
10954 [safi],
10955 PEER_CAP_ADDPATH_AF_RX_ADV)
10956 || CHECK_FLAG(
10957 p->af_cap[afi]
10958 [safi],
10959 PEER_CAP_ADDPATH_AF_RX_RCV))
10960 json_object_object_add(
10961 json_add,
10962 print_store,
10963 json_sub);
10964 else
10965 json_object_free(
10966 json_sub);
10967 }
10968
d62a17ae 10969 json_object_object_add(
10970 json_cap, "addPath", json_add);
10971 }
10972
10973 /* Dynamic */
10974 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10975 || CHECK_FLAG(p->cap,
10976 PEER_CAP_DYNAMIC_ADV)) {
10977 if (CHECK_FLAG(p->cap,
10978 PEER_CAP_DYNAMIC_ADV)
10979 && CHECK_FLAG(p->cap,
10980 PEER_CAP_DYNAMIC_RCV))
10981 json_object_string_add(
10982 json_cap, "dynamic",
10983 "advertisedAndReceived");
10984 else if (CHECK_FLAG(
10985 p->cap,
10986 PEER_CAP_DYNAMIC_ADV))
10987 json_object_string_add(
10988 json_cap, "dynamic",
10989 "advertised");
10990 else if (CHECK_FLAG(
10991 p->cap,
10992 PEER_CAP_DYNAMIC_RCV))
10993 json_object_string_add(
10994 json_cap, "dynamic",
10995 "received");
10996 }
10997
10998 /* Extended nexthop */
10999 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11000 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11001 json_object *json_nxt = NULL;
11002 const char *print_store;
11003
11004
11005 if (CHECK_FLAG(p->cap,
11006 PEER_CAP_ENHE_ADV)
11007 && CHECK_FLAG(p->cap,
11008 PEER_CAP_ENHE_RCV))
11009 json_object_string_add(
11010 json_cap,
11011 "extendedNexthop",
11012 "advertisedAndReceived");
11013 else if (CHECK_FLAG(p->cap,
11014 PEER_CAP_ENHE_ADV))
11015 json_object_string_add(
11016 json_cap,
11017 "extendedNexthop",
11018 "advertised");
11019 else if (CHECK_FLAG(p->cap,
11020 PEER_CAP_ENHE_RCV))
11021 json_object_string_add(
11022 json_cap,
11023 "extendedNexthop",
11024 "received");
11025
11026 if (CHECK_FLAG(p->cap,
11027 PEER_CAP_ENHE_RCV)) {
11028 json_nxt =
11029 json_object_new_object();
11030
11031 for (safi = SAFI_UNICAST;
11032 safi < SAFI_MAX; safi++) {
11033 if (CHECK_FLAG(
11034 p->af_cap
11035 [AFI_IP]
11036 [safi],
11037 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11038 print_store = get_afi_safi_str(
d62a17ae 11039 AFI_IP,
5cb5f4d0 11040 safi, true);
d62a17ae 11041 json_object_string_add(
11042 json_nxt,
11043 print_store,
54f29523 11044 "recieved"); /* misspelled for compatibility */
d62a17ae 11045 }
11046 }
11047 json_object_object_add(
11048 json_cap,
11049 "extendedNexthopFamililesByPeer",
11050 json_nxt);
11051 }
11052 }
11053
11054 /* Route Refresh */
11055 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11056 || CHECK_FLAG(p->cap,
11057 PEER_CAP_REFRESH_NEW_RCV)
11058 || CHECK_FLAG(p->cap,
11059 PEER_CAP_REFRESH_OLD_RCV)) {
11060 if (CHECK_FLAG(p->cap,
11061 PEER_CAP_REFRESH_ADV)
11062 && (CHECK_FLAG(
11063 p->cap,
11064 PEER_CAP_REFRESH_NEW_RCV)
11065 || CHECK_FLAG(
11066 p->cap,
11067 PEER_CAP_REFRESH_OLD_RCV))) {
11068 if (CHECK_FLAG(
11069 p->cap,
11070 PEER_CAP_REFRESH_OLD_RCV)
11071 && CHECK_FLAG(
11072 p->cap,
11073 PEER_CAP_REFRESH_NEW_RCV))
11074 json_object_string_add(
11075 json_cap,
11076 "routeRefresh",
11077 "advertisedAndReceivedOldNew");
11078 else {
11079 if (CHECK_FLAG(
11080 p->cap,
11081 PEER_CAP_REFRESH_OLD_RCV))
11082 json_object_string_add(
11083 json_cap,
11084 "routeRefresh",
11085 "advertisedAndReceivedOld");
11086 else
11087 json_object_string_add(
11088 json_cap,
11089 "routeRefresh",
11090 "advertisedAndReceivedNew");
11091 }
11092 } else if (
11093 CHECK_FLAG(
11094 p->cap,
11095 PEER_CAP_REFRESH_ADV))
11096 json_object_string_add(
11097 json_cap,
11098 "routeRefresh",
11099 "advertised");
11100 else if (
11101 CHECK_FLAG(
11102 p->cap,
11103 PEER_CAP_REFRESH_NEW_RCV)
11104 || CHECK_FLAG(
11105 p->cap,
11106 PEER_CAP_REFRESH_OLD_RCV))
11107 json_object_string_add(
11108 json_cap,
11109 "routeRefresh",
11110 "received");
11111 }
11112
11113 /* Multiprotocol Extensions */
11114 json_object *json_multi = NULL;
11115 json_multi = json_object_new_object();
11116
05c7a1cc
QY
11117 FOREACH_AFI_SAFI (afi, safi) {
11118 if (p->afc_adv[afi][safi]
11119 || p->afc_recv[afi][safi]) {
11120 json_object *json_exten = NULL;
11121 json_exten =
11122 json_object_new_object();
11123
d62a17ae 11124 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11125 && p->afc_recv[afi][safi])
11126 json_object_boolean_true_add(
11127 json_exten,
11128 "advertisedAndReceived");
11129 else if (p->afc_adv[afi][safi])
11130 json_object_boolean_true_add(
11131 json_exten,
11132 "advertised");
11133 else if (p->afc_recv[afi][safi])
11134 json_object_boolean_true_add(
11135 json_exten,
11136 "received");
d62a17ae 11137
05c7a1cc
QY
11138 json_object_object_add(
11139 json_multi,
5cb5f4d0
DD
11140 get_afi_safi_str(afi,
11141 safi,
11142 true),
05c7a1cc 11143 json_exten);
d62a17ae 11144 }
11145 }
11146 json_object_object_add(
11147 json_cap, "multiprotocolExtensions",
11148 json_multi);
11149
d77114b7 11150 /* Hostname capabilities */
60466a63 11151 json_object *json_hname = NULL;
d77114b7
MK
11152
11153 json_hname = json_object_new_object();
11154
11155 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11156 json_object_string_add(
60466a63
QY
11157 json_hname, "advHostName",
11158 bgp->peer_self->hostname
11159 ? bgp->peer_self
11160 ->hostname
d77114b7
MK
11161 : "n/a");
11162 json_object_string_add(
60466a63
QY
11163 json_hname, "advDomainName",
11164 bgp->peer_self->domainname
11165 ? bgp->peer_self
11166 ->domainname
d77114b7
MK
11167 : "n/a");
11168 }
11169
11170
11171 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11172 json_object_string_add(
60466a63
QY
11173 json_hname, "rcvHostName",
11174 p->hostname ? p->hostname
11175 : "n/a");
d77114b7 11176 json_object_string_add(
60466a63
QY
11177 json_hname, "rcvDomainName",
11178 p->domainname ? p->domainname
11179 : "n/a");
d77114b7
MK
11180 }
11181
60466a63 11182 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11183 json_hname);
11184
d62a17ae 11185 /* Gracefull Restart */
11186 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11187 || CHECK_FLAG(p->cap,
11188 PEER_CAP_RESTART_ADV)) {
11189 if (CHECK_FLAG(p->cap,
11190 PEER_CAP_RESTART_ADV)
11191 && CHECK_FLAG(p->cap,
11192 PEER_CAP_RESTART_RCV))
11193 json_object_string_add(
11194 json_cap,
11195 "gracefulRestart",
11196 "advertisedAndReceived");
11197 else if (CHECK_FLAG(
11198 p->cap,
11199 PEER_CAP_RESTART_ADV))
11200 json_object_string_add(
11201 json_cap,
11202 "gracefulRestartCapability",
11203 "advertised");
11204 else if (CHECK_FLAG(
11205 p->cap,
11206 PEER_CAP_RESTART_RCV))
11207 json_object_string_add(
11208 json_cap,
11209 "gracefulRestartCapability",
11210 "received");
11211
11212 if (CHECK_FLAG(p->cap,
11213 PEER_CAP_RESTART_RCV)) {
11214 int restart_af_count = 0;
11215 json_object *json_restart =
11216 NULL;
11217 json_restart =
11218 json_object_new_object();
11219
11220 json_object_int_add(
11221 json_cap,
11222 "gracefulRestartRemoteTimerMsecs",
11223 p->v_gr_restart * 1000);
11224
05c7a1cc
QY
11225 FOREACH_AFI_SAFI (afi, safi) {
11226 if (CHECK_FLAG(
11227 p->af_cap
11228 [afi]
11229 [safi],
11230 PEER_CAP_RESTART_AF_RCV)) {
11231 json_object *
11232 json_sub =
11233 NULL;
11234 json_sub =
11235 json_object_new_object();
11236
d62a17ae 11237 if (CHECK_FLAG(
11238 p->af_cap
11239 [afi]
11240 [safi],
05c7a1cc
QY
11241 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11242 json_object_boolean_true_add(
11243 json_sub,
11244 "preserved");
11245 restart_af_count++;
11246 json_object_object_add(
11247 json_restart,
5cb5f4d0 11248 get_afi_safi_str(
05c7a1cc 11249 afi,
5cb5f4d0
DD
11250 safi,
11251 true),
05c7a1cc 11252 json_sub);
d62a17ae 11253 }
11254 }
11255 if (!restart_af_count) {
11256 json_object_string_add(
11257 json_cap,
11258 "addressFamiliesByPeer",
11259 "none");
11260 json_object_free(
11261 json_restart);
11262 } else
11263 json_object_object_add(
11264 json_cap,
11265 "addressFamiliesByPeer",
11266 json_restart);
11267 }
11268 }
11269 json_object_object_add(json_neigh,
11270 "neighborCapabilities",
11271 json_cap);
11272 } else {
11273 vty_out(vty, " Neighbor capabilities:\n");
11274
11275 /* AS4 */
11276 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11277 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11278 vty_out(vty, " 4 Byte AS:");
11279 if (CHECK_FLAG(p->cap,
11280 PEER_CAP_AS4_ADV))
11281 vty_out(vty, " advertised");
11282 if (CHECK_FLAG(p->cap,
11283 PEER_CAP_AS4_RCV))
11284 vty_out(vty, " %sreceived",
11285 CHECK_FLAG(
11286 p->cap,
11287 PEER_CAP_AS4_ADV)
11288 ? "and "
11289 : "");
11290 vty_out(vty, "\n");
11291 }
11292
11293 /* AddPath */
11294 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11295 || CHECK_FLAG(p->cap,
11296 PEER_CAP_ADDPATH_ADV)) {
11297 vty_out(vty, " AddPath:\n");
11298
05c7a1cc
QY
11299 FOREACH_AFI_SAFI (afi, safi) {
11300 if (CHECK_FLAG(
11301 p->af_cap[afi]
11302 [safi],
11303 PEER_CAP_ADDPATH_AF_TX_ADV)
11304 || CHECK_FLAG(
11305 p->af_cap[afi]
11306 [safi],
11307 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11308 vty_out(vty,
11309 " %s: TX ",
5cb5f4d0 11310 get_afi_safi_str(
05c7a1cc 11311 afi,
5cb5f4d0
DD
11312 safi,
11313 false));
05c7a1cc 11314
d62a17ae 11315 if (CHECK_FLAG(
11316 p->af_cap
11317 [afi]
11318 [safi],
05c7a1cc 11319 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11320 vty_out(vty,
05c7a1cc 11321 "advertised %s",
5cb5f4d0 11322 get_afi_safi_str(
d62a17ae 11323 afi,
5cb5f4d0
DD
11324 safi,
11325 false));
d62a17ae 11326
05c7a1cc
QY
11327 if (CHECK_FLAG(
11328 p->af_cap
11329 [afi]
11330 [safi],
11331 PEER_CAP_ADDPATH_AF_TX_RCV))
11332 vty_out(vty,
11333 "%sreceived",
11334 CHECK_FLAG(
11335 p->af_cap
11336 [afi]
11337 [safi],
11338 PEER_CAP_ADDPATH_AF_TX_ADV)
11339 ? " and "
11340 : "");
d62a17ae 11341
05c7a1cc
QY
11342 vty_out(vty, "\n");
11343 }
d62a17ae 11344
05c7a1cc
QY
11345 if (CHECK_FLAG(
11346 p->af_cap[afi]
11347 [safi],
11348 PEER_CAP_ADDPATH_AF_RX_ADV)
11349 || CHECK_FLAG(
11350 p->af_cap[afi]
11351 [safi],
11352 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11353 vty_out(vty,
11354 " %s: RX ",
5cb5f4d0 11355 get_afi_safi_str(
05c7a1cc 11356 afi,
5cb5f4d0
DD
11357 safi,
11358 false));
d62a17ae 11359
11360 if (CHECK_FLAG(
11361 p->af_cap
11362 [afi]
11363 [safi],
05c7a1cc 11364 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11365 vty_out(vty,
05c7a1cc 11366 "advertised %s",
5cb5f4d0 11367 get_afi_safi_str(
d62a17ae 11368 afi,
5cb5f4d0
DD
11369 safi,
11370 false));
d62a17ae 11371
05c7a1cc
QY
11372 if (CHECK_FLAG(
11373 p->af_cap
11374 [afi]
11375 [safi],
11376 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11377 vty_out(vty,
05c7a1cc
QY
11378 "%sreceived",
11379 CHECK_FLAG(
11380 p->af_cap
11381 [afi]
11382 [safi],
11383 PEER_CAP_ADDPATH_AF_RX_ADV)
11384 ? " and "
11385 : "");
11386
11387 vty_out(vty, "\n");
d62a17ae 11388 }
05c7a1cc 11389 }
d62a17ae 11390 }
11391
11392 /* Dynamic */
11393 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11394 || CHECK_FLAG(p->cap,
11395 PEER_CAP_DYNAMIC_ADV)) {
11396 vty_out(vty, " Dynamic:");
11397 if (CHECK_FLAG(p->cap,
11398 PEER_CAP_DYNAMIC_ADV))
11399 vty_out(vty, " advertised");
11400 if (CHECK_FLAG(p->cap,
11401 PEER_CAP_DYNAMIC_RCV))
11402 vty_out(vty, " %sreceived",
11403 CHECK_FLAG(
11404 p->cap,
11405 PEER_CAP_DYNAMIC_ADV)
11406 ? "and "
11407 : "");
11408 vty_out(vty, "\n");
11409 }
11410
11411 /* Extended nexthop */
11412 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11413 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11414 vty_out(vty, " Extended nexthop:");
11415 if (CHECK_FLAG(p->cap,
11416 PEER_CAP_ENHE_ADV))
11417 vty_out(vty, " advertised");
11418 if (CHECK_FLAG(p->cap,
11419 PEER_CAP_ENHE_RCV))
11420 vty_out(vty, " %sreceived",
11421 CHECK_FLAG(
11422 p->cap,
11423 PEER_CAP_ENHE_ADV)
11424 ? "and "
11425 : "");
11426 vty_out(vty, "\n");
11427
11428 if (CHECK_FLAG(p->cap,
11429 PEER_CAP_ENHE_RCV)) {
11430 vty_out(vty,
11431 " Address families by peer:\n ");
11432 for (safi = SAFI_UNICAST;
11433 safi < SAFI_MAX; safi++)
11434 if (CHECK_FLAG(
11435 p->af_cap
11436 [AFI_IP]
11437 [safi],
11438 PEER_CAP_ENHE_AF_RCV))
11439 vty_out(vty,
11440 " %s\n",
5cb5f4d0 11441 get_afi_safi_str(
d62a17ae 11442 AFI_IP,
5cb5f4d0
DD
11443 safi,
11444 false));
d62a17ae 11445 }
11446 }
11447
11448 /* Route Refresh */
11449 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11450 || CHECK_FLAG(p->cap,
11451 PEER_CAP_REFRESH_NEW_RCV)
11452 || CHECK_FLAG(p->cap,
11453 PEER_CAP_REFRESH_OLD_RCV)) {
11454 vty_out(vty, " Route refresh:");
11455 if (CHECK_FLAG(p->cap,
11456 PEER_CAP_REFRESH_ADV))
11457 vty_out(vty, " advertised");
11458 if (CHECK_FLAG(p->cap,
11459 PEER_CAP_REFRESH_NEW_RCV)
11460 || CHECK_FLAG(
11461 p->cap,
11462 PEER_CAP_REFRESH_OLD_RCV))
11463 vty_out(vty, " %sreceived(%s)",
11464 CHECK_FLAG(
11465 p->cap,
11466 PEER_CAP_REFRESH_ADV)
11467 ? "and "
11468 : "",
11469 (CHECK_FLAG(
11470 p->cap,
11471 PEER_CAP_REFRESH_OLD_RCV)
11472 && CHECK_FLAG(
11473 p->cap,
11474 PEER_CAP_REFRESH_NEW_RCV))
11475 ? "old & new"
11476 : CHECK_FLAG(
11477 p->cap,
11478 PEER_CAP_REFRESH_OLD_RCV)
11479 ? "old"
11480 : "new");
11481
11482 vty_out(vty, "\n");
11483 }
11484
11485 /* Multiprotocol Extensions */
05c7a1cc
QY
11486 FOREACH_AFI_SAFI (afi, safi)
11487 if (p->afc_adv[afi][safi]
11488 || p->afc_recv[afi][safi]) {
11489 vty_out(vty,
11490 " Address Family %s:",
5cb5f4d0
DD
11491 get_afi_safi_str(
11492 afi,
11493 safi,
11494 false));
05c7a1cc 11495 if (p->afc_adv[afi][safi])
d62a17ae 11496 vty_out(vty,
05c7a1cc
QY
11497 " advertised");
11498 if (p->afc_recv[afi][safi])
11499 vty_out(vty,
11500 " %sreceived",
11501 p->afc_adv[afi]
11502 [safi]
11503 ? "and "
11504 : "");
11505 vty_out(vty, "\n");
11506 }
d62a17ae 11507
11508 /* Hostname capability */
60466a63 11509 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11510
11511 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11512 vty_out(vty,
11513 " advertised (name: %s,domain name: %s)",
60466a63
QY
11514 bgp->peer_self->hostname
11515 ? bgp->peer_self
11516 ->hostname
d77114b7 11517 : "n/a",
60466a63
QY
11518 bgp->peer_self->domainname
11519 ? bgp->peer_self
11520 ->domainname
d77114b7
MK
11521 : "n/a");
11522 } else {
11523 vty_out(vty, " not advertised");
d62a17ae 11524 }
11525
d77114b7 11526 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11527 vty_out(vty,
11528 " received (name: %s,domain name: %s)",
60466a63
QY
11529 p->hostname ? p->hostname
11530 : "n/a",
11531 p->domainname ? p->domainname
11532 : "n/a");
d77114b7
MK
11533 } else {
11534 vty_out(vty, " not received");
11535 }
11536
11537 vty_out(vty, "\n");
11538
d62a17ae 11539 /* Gracefull Restart */
11540 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11541 || CHECK_FLAG(p->cap,
11542 PEER_CAP_RESTART_ADV)) {
11543 vty_out(vty,
11544 " Graceful Restart Capabilty:");
11545 if (CHECK_FLAG(p->cap,
11546 PEER_CAP_RESTART_ADV))
11547 vty_out(vty, " advertised");
11548 if (CHECK_FLAG(p->cap,
11549 PEER_CAP_RESTART_RCV))
11550 vty_out(vty, " %sreceived",
11551 CHECK_FLAG(
11552 p->cap,
11553 PEER_CAP_RESTART_ADV)
11554 ? "and "
11555 : "");
11556 vty_out(vty, "\n");
11557
11558 if (CHECK_FLAG(p->cap,
11559 PEER_CAP_RESTART_RCV)) {
11560 int restart_af_count = 0;
11561
11562 vty_out(vty,
11563 " Remote Restart timer is %d seconds\n",
11564 p->v_gr_restart);
11565 vty_out(vty,
11566 " Address families by peer:\n ");
11567
05c7a1cc
QY
11568 FOREACH_AFI_SAFI (afi, safi)
11569 if (CHECK_FLAG(
11570 p->af_cap
11571 [afi]
11572 [safi],
11573 PEER_CAP_RESTART_AF_RCV)) {
11574 vty_out(vty,
11575 "%s%s(%s)",
11576 restart_af_count
11577 ? ", "
11578 : "",
5cb5f4d0 11579 get_afi_safi_str(
05c7a1cc 11580 afi,
5cb5f4d0
DD
11581 safi,
11582 false),
05c7a1cc
QY
11583 CHECK_FLAG(
11584 p->af_cap
11585 [afi]
11586 [safi],
11587 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11588 ? "preserved"
11589 : "not preserved");
11590 restart_af_count++;
11591 }
d62a17ae 11592 if (!restart_af_count)
11593 vty_out(vty, "none");
11594 vty_out(vty, "\n");
11595 }
2986cac2 11596 } /* Gracefull Restart */
d62a17ae 11597 }
11598 }
11599 }
11600
11601 /* graceful restart information */
d62a17ae 11602 json_object *json_grace = NULL;
11603 json_object *json_grace_send = NULL;
11604 json_object *json_grace_recv = NULL;
11605 int eor_send_af_count = 0;
11606 int eor_receive_af_count = 0;
11607
11608 if (use_json) {
11609 json_grace = json_object_new_object();
11610 json_grace_send = json_object_new_object();
11611 json_grace_recv = json_object_new_object();
11612
2986cac2 11613 if ((p->status == Established) &&
11614 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11615 FOREACH_AFI_SAFI (afi, safi) {
11616 if (CHECK_FLAG(p->af_sflags[afi][safi],
2986cac2 11617 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11618 json_object_boolean_true_add(
11619 json_grace_send,
5cb5f4d0
DD
11620 get_afi_safi_str(afi,
11621 safi,
11622 true));
05c7a1cc 11623 eor_send_af_count++;
d62a17ae 11624 }
11625 }
05c7a1cc
QY
11626 FOREACH_AFI_SAFI (afi, safi) {
11627 if (CHECK_FLAG(
2986cac2 11628 p->af_sflags[afi][safi],
11629 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11630 json_object_boolean_true_add(
11631 json_grace_recv,
5cb5f4d0
DD
11632 get_afi_safi_str(afi,
11633 safi,
11634 true));
05c7a1cc 11635 eor_receive_af_count++;
d62a17ae 11636 }
11637 }
11638 }
2986cac2 11639 json_object_object_add(json_grace,
11640 "endOfRibSend",
11641 json_grace_send);
11642 json_object_object_add(json_grace,
11643 "endOfRibRecv",
11644 json_grace_recv);
d62a17ae 11645
d62a17ae 11646
11647 if (p->t_gr_restart)
11648 json_object_int_add(json_grace,
11649 "gracefulRestartTimerMsecs",
11650 thread_timer_remain_second(
11651 p->t_gr_restart)
11652 * 1000);
11653
11654 if (p->t_gr_stale)
11655 json_object_int_add(
11656 json_grace,
11657 "gracefulStalepathTimerMsecs",
11658 thread_timer_remain_second(
11659 p->t_gr_stale)
11660 * 1000);
2986cac2 11661 /* more gr info in new format */
11662 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
11663 json_grace);
d62a17ae 11664 json_object_object_add(
11665 json_neigh, "gracefulRestartInfo", json_grace);
11666 } else {
2986cac2 11667 vty_out(vty, " Graceful restart informations:\n");
11668 if ((p->status == Established) &&
11669 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
11670
d62a17ae 11671 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11672 FOREACH_AFI_SAFI (afi, safi) {
11673 if (CHECK_FLAG(p->af_sflags[afi][safi],
11674 PEER_STATUS_EOR_SEND)) {
11675 vty_out(vty, "%s%s",
11676 eor_send_af_count ? ", "
11677 : "",
5cb5f4d0 11678 get_afi_safi_str(afi,
2986cac2 11679 safi,
11680 false));
05c7a1cc 11681 eor_send_af_count++;
d62a17ae 11682 }
11683 }
11684 vty_out(vty, "\n");
11685 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
11686 FOREACH_AFI_SAFI (afi, safi) {
11687 if (CHECK_FLAG(
11688 p->af_sflags[afi][safi],
11689 PEER_STATUS_EOR_RECEIVED)) {
11690 vty_out(vty, "%s%s",
11691 eor_receive_af_count
11692 ? ", "
11693 : "",
5cb5f4d0
DD
11694 get_afi_safi_str(afi,
11695 safi,
11696 false));
05c7a1cc 11697 eor_receive_af_count++;
d62a17ae 11698 }
11699 }
11700 vty_out(vty, "\n");
11701 }
11702
11703 if (p->t_gr_restart)
11704 vty_out(vty,
11705 " The remaining time of restart timer is %ld\n",
11706 thread_timer_remain_second(
11707 p->t_gr_restart));
11708
11709 if (p->t_gr_stale)
11710 vty_out(vty,
11711 " The remaining time of stalepath timer is %ld\n",
11712 thread_timer_remain_second(
11713 p->t_gr_stale));
2986cac2 11714
11715 /* more gr info in new format */
11716 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 11717 }
2986cac2 11718
d62a17ae 11719 if (use_json) {
11720 json_object *json_stat = NULL;
11721 json_stat = json_object_new_object();
11722 /* Packet counts. */
11723 json_object_int_add(json_stat, "depthInq", 0);
11724 json_object_int_add(json_stat, "depthOutq",
11725 (unsigned long)p->obuf->count);
0112e9e0
QY
11726 json_object_int_add(json_stat, "opensSent",
11727 atomic_load_explicit(&p->open_out,
11728 memory_order_relaxed));
11729 json_object_int_add(json_stat, "opensRecv",
11730 atomic_load_explicit(&p->open_in,
11731 memory_order_relaxed));
d62a17ae 11732 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
11733 atomic_load_explicit(&p->notify_out,
11734 memory_order_relaxed));
d62a17ae 11735 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
11736 atomic_load_explicit(&p->notify_in,
11737 memory_order_relaxed));
11738 json_object_int_add(json_stat, "updatesSent",
11739 atomic_load_explicit(&p->update_out,
11740 memory_order_relaxed));
11741 json_object_int_add(json_stat, "updatesRecv",
11742 atomic_load_explicit(&p->update_in,
11743 memory_order_relaxed));
d62a17ae 11744 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
11745 atomic_load_explicit(&p->keepalive_out,
11746 memory_order_relaxed));
d62a17ae 11747 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
11748 atomic_load_explicit(&p->keepalive_in,
11749 memory_order_relaxed));
d62a17ae 11750 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
11751 atomic_load_explicit(&p->refresh_out,
11752 memory_order_relaxed));
d62a17ae 11753 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
11754 atomic_load_explicit(&p->refresh_in,
11755 memory_order_relaxed));
d62a17ae 11756 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
11757 atomic_load_explicit(&p->dynamic_cap_out,
11758 memory_order_relaxed));
d62a17ae 11759 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
11760 atomic_load_explicit(&p->dynamic_cap_in,
11761 memory_order_relaxed));
11762 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11763 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 11764 json_object_object_add(json_neigh, "messageStats", json_stat);
11765 } else {
11766 /* Packet counts. */
11767 vty_out(vty, " Message statistics:\n");
11768 vty_out(vty, " Inq depth is 0\n");
11769 vty_out(vty, " Outq depth is %lu\n",
11770 (unsigned long)p->obuf->count);
11771 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
11772 vty_out(vty, " Opens: %10d %10d\n",
11773 atomic_load_explicit(&p->open_out,
11774 memory_order_relaxed),
11775 atomic_load_explicit(&p->open_in,
11776 memory_order_relaxed));
11777 vty_out(vty, " Notifications: %10d %10d\n",
11778 atomic_load_explicit(&p->notify_out,
11779 memory_order_relaxed),
11780 atomic_load_explicit(&p->notify_in,
11781 memory_order_relaxed));
11782 vty_out(vty, " Updates: %10d %10d\n",
11783 atomic_load_explicit(&p->update_out,
11784 memory_order_relaxed),
11785 atomic_load_explicit(&p->update_in,
11786 memory_order_relaxed));
11787 vty_out(vty, " Keepalives: %10d %10d\n",
11788 atomic_load_explicit(&p->keepalive_out,
11789 memory_order_relaxed),
11790 atomic_load_explicit(&p->keepalive_in,
11791 memory_order_relaxed));
11792 vty_out(vty, " Route Refresh: %10d %10d\n",
11793 atomic_load_explicit(&p->refresh_out,
11794 memory_order_relaxed),
11795 atomic_load_explicit(&p->refresh_in,
11796 memory_order_relaxed));
d62a17ae 11797 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
11798 atomic_load_explicit(&p->dynamic_cap_out,
11799 memory_order_relaxed),
11800 atomic_load_explicit(&p->dynamic_cap_in,
11801 memory_order_relaxed));
11802 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11803 PEER_TOTAL_RX(p));
d62a17ae 11804 }
11805
11806 if (use_json) {
11807 /* advertisement-interval */
11808 json_object_int_add(json_neigh,
11809 "minBtwnAdvertisementRunsTimerMsecs",
11810 p->v_routeadv * 1000);
11811
11812 /* Update-source. */
11813 if (p->update_if || p->update_source) {
11814 if (p->update_if)
11815 json_object_string_add(json_neigh,
11816 "updateSource",
11817 p->update_if);
11818 else if (p->update_source)
11819 json_object_string_add(
11820 json_neigh, "updateSource",
11821 sockunion2str(p->update_source, buf1,
11822 SU_ADDRSTRLEN));
11823 }
11824 } else {
11825 /* advertisement-interval */
11826 vty_out(vty,
11827 " Minimum time between advertisement runs is %d seconds\n",
11828 p->v_routeadv);
11829
11830 /* Update-source. */
11831 if (p->update_if || p->update_source) {
11832 vty_out(vty, " Update source is ");
11833 if (p->update_if)
11834 vty_out(vty, "%s", p->update_if);
11835 else if (p->update_source)
11836 vty_out(vty, "%s",
11837 sockunion2str(p->update_source, buf1,
11838 SU_ADDRSTRLEN));
11839 vty_out(vty, "\n");
11840 }
11841
11842 vty_out(vty, "\n");
11843 }
11844
11845 /* Address Family Information */
11846 json_object *json_hold = NULL;
11847
11848 if (use_json)
11849 json_hold = json_object_new_object();
11850
05c7a1cc
QY
11851 FOREACH_AFI_SAFI (afi, safi)
11852 if (p->afc[afi][safi])
11853 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11854 json_hold);
d62a17ae 11855
11856 if (use_json) {
11857 json_object_object_add(json_neigh, "addressFamilyInfo",
11858 json_hold);
11859 json_object_int_add(json_neigh, "connectionsEstablished",
11860 p->established);
11861 json_object_int_add(json_neigh, "connectionsDropped",
11862 p->dropped);
11863 } else
11864 vty_out(vty, " Connections established %d; dropped %d\n",
11865 p->established, p->dropped);
11866
11867 if (!p->last_reset) {
11868 if (use_json)
11869 json_object_string_add(json_neigh, "lastReset",
11870 "never");
11871 else
11872 vty_out(vty, " Last reset never\n");
11873 } else {
11874 if (use_json) {
11875 time_t uptime;
11876 struct tm *tm;
11877
11878 uptime = bgp_clock();
11879 uptime -= p->resettime;
11880 tm = gmtime(&uptime);
11881 json_object_int_add(json_neigh, "lastResetTimerMsecs",
11882 (tm->tm_sec * 1000)
11883 + (tm->tm_min * 60000)
11884 + (tm->tm_hour * 3600000));
3577f1c5 11885 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 11886 } else {
11887 vty_out(vty, " Last reset %s, ",
11888 peer_uptime(p->resettime, timebuf,
11889 BGP_UPTIME_LEN, 0, NULL));
11890
3577f1c5 11891 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 11892 if (p->last_reset_cause_size) {
11893 msg = p->last_reset_cause;
11894 vty_out(vty,
11895 " Message received that caused BGP to send a NOTIFICATION:\n ");
11896 for (i = 1; i <= p->last_reset_cause_size;
11897 i++) {
11898 vty_out(vty, "%02X", *msg++);
11899
11900 if (i != p->last_reset_cause_size) {
11901 if (i % 16 == 0) {
11902 vty_out(vty, "\n ");
11903 } else if (i % 4 == 0) {
11904 vty_out(vty, " ");
11905 }
11906 }
11907 }
11908 vty_out(vty, "\n");
11909 }
11910 }
11911 }
11912
11913 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11914 if (use_json)
11915 json_object_boolean_true_add(json_neigh,
11916 "prefixesConfigExceedMax");
11917 else
11918 vty_out(vty,
11919 " Peer had exceeded the max. no. of prefixes configured.\n");
11920
11921 if (p->t_pmax_restart) {
11922 if (use_json) {
11923 json_object_boolean_true_add(
11924 json_neigh, "reducePrefixNumFrom");
11925 json_object_int_add(json_neigh,
11926 "restartInTimerMsec",
11927 thread_timer_remain_second(
11928 p->t_pmax_restart)
11929 * 1000);
11930 } else
11931 vty_out(vty,
11932 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
11933 p->host, thread_timer_remain_second(
11934 p->t_pmax_restart));
d62a17ae 11935 } else {
11936 if (use_json)
11937 json_object_boolean_true_add(
11938 json_neigh,
11939 "reducePrefixNumAndClearIpBgp");
11940 else
11941 vty_out(vty,
11942 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
11943 p->host);
11944 }
11945 }
11946
11947 /* EBGP Multihop and GTSM */
11948 if (p->sort != BGP_PEER_IBGP) {
11949 if (use_json) {
11950 if (p->gtsm_hops > 0)
11951 json_object_int_add(json_neigh,
11952 "externalBgpNbrMaxHopsAway",
11953 p->gtsm_hops);
c8d6f0d6 11954 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11955 json_object_int_add(json_neigh,
11956 "externalBgpNbrMaxHopsAway",
11957 p->ttl);
11958 } else {
11959 if (p->gtsm_hops > 0)
11960 vty_out(vty,
11961 " External BGP neighbor may be up to %d hops away.\n",
11962 p->gtsm_hops);
c8d6f0d6 11963 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11964 vty_out(vty,
11965 " External BGP neighbor may be up to %d hops away.\n",
11966 p->ttl);
11967 }
11968 } else {
11969 if (p->gtsm_hops > 0) {
11970 if (use_json)
11971 json_object_int_add(json_neigh,
11972 "internalBgpNbrMaxHopsAway",
11973 p->gtsm_hops);
11974 else
11975 vty_out(vty,
11976 " Internal BGP neighbor may be up to %d hops away.\n",
11977 p->gtsm_hops);
11978 }
11979 }
11980
11981 /* Local address. */
11982 if (p->su_local) {
11983 if (use_json) {
11984 json_object_string_add(json_neigh, "hostLocal",
11985 sockunion2str(p->su_local, buf1,
11986 SU_ADDRSTRLEN));
11987 json_object_int_add(json_neigh, "portLocal",
11988 ntohs(p->su_local->sin.sin_port));
11989 } else
11990 vty_out(vty, "Local host: %s, Local port: %d\n",
11991 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
11992 ntohs(p->su_local->sin.sin_port));
11993 }
11994
11995 /* Remote address. */
11996 if (p->su_remote) {
11997 if (use_json) {
11998 json_object_string_add(json_neigh, "hostForeign",
11999 sockunion2str(p->su_remote, buf1,
12000 SU_ADDRSTRLEN));
12001 json_object_int_add(json_neigh, "portForeign",
12002 ntohs(p->su_remote->sin.sin_port));
12003 } else
12004 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12005 sockunion2str(p->su_remote, buf1,
12006 SU_ADDRSTRLEN),
12007 ntohs(p->su_remote->sin.sin_port));
12008 }
12009
12010 /* Nexthop display. */
12011 if (p->su_local) {
12012 if (use_json) {
12013 json_object_string_add(json_neigh, "nexthop",
12014 inet_ntop(AF_INET,
12015 &p->nexthop.v4, buf1,
12016 sizeof(buf1)));
12017 json_object_string_add(json_neigh, "nexthopGlobal",
12018 inet_ntop(AF_INET6,
12019 &p->nexthop.v6_global,
12020 buf1, sizeof(buf1)));
12021 json_object_string_add(json_neigh, "nexthopLocal",
12022 inet_ntop(AF_INET6,
12023 &p->nexthop.v6_local,
12024 buf1, sizeof(buf1)));
12025 if (p->shared_network)
12026 json_object_string_add(json_neigh,
12027 "bgpConnection",
12028 "sharedNetwork");
12029 else
12030 json_object_string_add(json_neigh,
12031 "bgpConnection",
12032 "nonSharedNetwork");
12033 } else {
12034 vty_out(vty, "Nexthop: %s\n",
12035 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12036 sizeof(buf1)));
12037 vty_out(vty, "Nexthop global: %s\n",
12038 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12039 sizeof(buf1)));
12040 vty_out(vty, "Nexthop local: %s\n",
12041 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12042 sizeof(buf1)));
12043 vty_out(vty, "BGP connection: %s\n",
12044 p->shared_network ? "shared network"
12045 : "non shared network");
12046 }
12047 }
12048
12049 /* Timer information. */
12050 if (use_json) {
12051 json_object_int_add(json_neigh, "connectRetryTimer",
12052 p->v_connect);
12053 if (p->status == Established && p->rtt)
12054 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12055 p->rtt);
12056 if (p->t_start)
12057 json_object_int_add(
12058 json_neigh, "nextStartTimerDueInMsecs",
12059 thread_timer_remain_second(p->t_start) * 1000);
12060 if (p->t_connect)
12061 json_object_int_add(
12062 json_neigh, "nextConnectTimerDueInMsecs",
12063 thread_timer_remain_second(p->t_connect)
12064 * 1000);
12065 if (p->t_routeadv) {
12066 json_object_int_add(json_neigh, "mraiInterval",
12067 p->v_routeadv);
12068 json_object_int_add(
12069 json_neigh, "mraiTimerExpireInMsecs",
12070 thread_timer_remain_second(p->t_routeadv)
12071 * 1000);
12072 }
12073 if (p->password)
12074 json_object_int_add(json_neigh, "authenticationEnabled",
12075 1);
12076
12077 if (p->t_read)
12078 json_object_string_add(json_neigh, "readThread", "on");
12079 else
12080 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12081
12082 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12083 json_object_string_add(json_neigh, "writeThread", "on");
12084 else
12085 json_object_string_add(json_neigh, "writeThread",
12086 "off");
12087 } else {
12088 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12089 p->v_connect);
12090 if (p->status == Established && p->rtt)
12091 vty_out(vty, "Estimated round trip time: %d ms\n",
12092 p->rtt);
12093 if (p->t_start)
12094 vty_out(vty, "Next start timer due in %ld seconds\n",
12095 thread_timer_remain_second(p->t_start));
12096 if (p->t_connect)
12097 vty_out(vty, "Next connect timer due in %ld seconds\n",
12098 thread_timer_remain_second(p->t_connect));
12099 if (p->t_routeadv)
12100 vty_out(vty,
12101 "MRAI (interval %u) timer expires in %ld seconds\n",
12102 p->v_routeadv,
12103 thread_timer_remain_second(p->t_routeadv));
12104 if (p->password)
12105 vty_out(vty, "Peer Authentication Enabled\n");
12106
cac9e917 12107 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12108 p->t_read ? "on" : "off",
12109 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12110 ? "on"
cac9e917 12111 : "off", p->fd);
d62a17ae 12112 }
12113
12114 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12115 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12116 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12117
12118 if (!use_json)
12119 vty_out(vty, "\n");
12120
12121 /* BFD information. */
12122 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12123
12124 if (use_json) {
12125 if (p->conf_if) /* Configured interface name. */
12126 json_object_object_add(json, p->conf_if, json_neigh);
12127 else /* Configured IP address. */
12128 json_object_object_add(json, p->host, json_neigh);
12129 }
12130}
12131
2986cac2 12132static int bgp_show_neighbor_graceful_restart(struct vty *vty,
12133 struct bgp *bgp,
12134 enum show_type type,
12135 union sockunion *su,
12136 const char *conf_if, afi_t afi,
12137 bool use_json, json_object *json)
12138{
12139 struct listnode *node, *nnode;
12140 struct peer *peer;
12141 int find = 0;
12142 safi_t safi = SAFI_UNICAST;
12143 json_object *json_neighbor = NULL;
12144
12145 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12146
12147 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12148 continue;
12149
12150 if ((peer->afc[afi][safi]) == 0)
12151 continue;
12152
12153 if (use_json)
12154 json_neighbor = json_object_new_object();
12155
2ba1fe69 12156 if (type == show_all) {
2986cac2 12157 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12158 json_neighbor);
2986cac2 12159
12160 if (use_json)
13909c4f
DS
12161 json_object_object_add(json, peer->host,
12162 json_neighbor);
2986cac2 12163
2ba1fe69 12164 } else if (type == show_peer) {
2986cac2 12165 if (conf_if) {
12166 if ((peer->conf_if
13909c4f
DS
12167 && !strcmp(peer->conf_if, conf_if))
12168 || (peer->hostname
2986cac2 12169 && !strcmp(peer->hostname, conf_if))) {
12170 find = 1;
13909c4f
DS
12171 bgp_show_peer_gr_status(vty, peer,
12172 use_json,
12173 json_neighbor);
2986cac2 12174 }
12175 } else {
12176 if (sockunion_same(&peer->su, su)) {
12177 find = 1;
13909c4f
DS
12178 bgp_show_peer_gr_status(vty, peer,
12179 use_json,
12180 json_neighbor);
2986cac2 12181 }
12182 }
13909c4f
DS
12183 if (use_json && find)
12184 json_object_object_add(json, peer->host,
12185 json_neighbor);
2986cac2 12186 }
12187
12188 if (find)
12189 break;
12190 }
12191
12192 if (type == show_peer && !find) {
12193 if (use_json)
13909c4f 12194 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12195 else
12196 vty_out(vty, "%% No such neighbor\n");
12197 }
12198 if (use_json) {
13909c4f
DS
12199 vty_out(vty, "%s\n",
12200 json_object_to_json_string_ext(
12201 json, JSON_C_TO_STRING_PRETTY));
2986cac2 12202 } else {
12203 vty_out(vty, "\n");
12204 }
12205
12206 return CMD_SUCCESS;
12207}
12208
d62a17ae 12209static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12210 enum show_type type, union sockunion *su,
9f049418 12211 const char *conf_if, bool use_json,
d62a17ae 12212 json_object *json)
12213{
12214 struct listnode *node, *nnode;
12215 struct peer *peer;
12216 int find = 0;
9f049418 12217 bool nbr_output = false;
d1927ebe
AS
12218 afi_t afi = AFI_MAX;
12219 safi_t safi = SAFI_MAX;
12220
12221 if (type == show_ipv4_peer || type == show_ipv4_all) {
12222 afi = AFI_IP;
12223 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12224 afi = AFI_IP6;
12225 }
d62a17ae 12226
12227 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12228 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12229 continue;
12230
12231 switch (type) {
12232 case show_all:
12233 bgp_show_peer(vty, peer, use_json, json);
9f049418 12234 nbr_output = true;
d62a17ae 12235 break;
12236 case show_peer:
12237 if (conf_if) {
12238 if ((peer->conf_if
12239 && !strcmp(peer->conf_if, conf_if))
12240 || (peer->hostname
12241 && !strcmp(peer->hostname, conf_if))) {
12242 find = 1;
12243 bgp_show_peer(vty, peer, use_json,
12244 json);
12245 }
12246 } else {
12247 if (sockunion_same(&peer->su, su)) {
12248 find = 1;
12249 bgp_show_peer(vty, peer, use_json,
12250 json);
12251 }
12252 }
12253 break;
d1927ebe
AS
12254 case show_ipv4_peer:
12255 case show_ipv6_peer:
12256 FOREACH_SAFI (safi) {
12257 if (peer->afc[afi][safi]) {
12258 if (conf_if) {
12259 if ((peer->conf_if
12260 && !strcmp(peer->conf_if, conf_if))
12261 || (peer->hostname
12262 && !strcmp(peer->hostname, conf_if))) {
12263 find = 1;
12264 bgp_show_peer(vty, peer, use_json,
12265 json);
12266 break;
12267 }
12268 } else {
12269 if (sockunion_same(&peer->su, su)) {
12270 find = 1;
12271 bgp_show_peer(vty, peer, use_json,
12272 json);
12273 break;
12274 }
12275 }
12276 }
12277 }
12278 break;
12279 case show_ipv4_all:
12280 case show_ipv6_all:
12281 FOREACH_SAFI (safi) {
12282 if (peer->afc[afi][safi]) {
12283 bgp_show_peer(vty, peer, use_json, json);
12284 nbr_output = true;
12285 break;
12286 }
12287 }
12288 break;
d62a17ae 12289 }
12290 }
12291
d1927ebe
AS
12292 if ((type == show_peer || type == show_ipv4_peer ||
12293 type == show_ipv6_peer) && !find) {
d62a17ae 12294 if (use_json)
12295 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12296 else
88b7d255 12297 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12298 }
12299
d1927ebe
AS
12300 if (type != show_peer && type != show_ipv4_peer &&
12301 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12302 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12303
d62a17ae 12304 if (use_json) {
996c9314
LB
12305 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12306 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12307 } else {
12308 vty_out(vty, "\n");
12309 }
12310
12311 return CMD_SUCCESS;
12312}
12313
2986cac2 12314static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12315 enum show_type type, const char *ip_str,
12316 afi_t afi, bool use_json)
12317{
12318
12319 int ret;
12320 struct bgp *bgp;
12321 union sockunion su;
12322 json_object *json = NULL;
12323
12324 bgp = bgp_get_default();
12325
13909c4f
DS
12326 if (!bgp)
12327 return;
2986cac2 12328
13909c4f
DS
12329 if (!use_json)
12330 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12331 NULL);
2986cac2 12332
13909c4f
DS
12333 json = json_object_new_object();
12334 if (ip_str) {
12335 ret = str2sockunion(ip_str, &su);
12336 if (ret < 0)
12337 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
12338 ip_str, afi,
12339 use_json, json);
12340 else
12341 bgp_show_neighbor_graceful_restart(
12342 vty, bgp, type, &su, NULL, afi, use_json, json);
12343 } else
12344 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12345 afi, use_json, json);
12346 json_object_free(json);
2986cac2 12347}
12348
d62a17ae 12349static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12350 enum show_type type,
12351 const char *ip_str,
9f049418 12352 bool use_json)
d62a17ae 12353{
0291c246
MK
12354 struct listnode *node, *nnode;
12355 struct bgp *bgp;
71aedaa3 12356 union sockunion su;
0291c246 12357 json_object *json = NULL;
71aedaa3 12358 int ret, is_first = 1;
9f049418 12359 bool nbr_output = false;
d62a17ae 12360
12361 if (use_json)
12362 vty_out(vty, "{\n");
12363
12364 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12365 nbr_output = true;
d62a17ae 12366 if (use_json) {
12367 if (!(json = json_object_new_object())) {
af4c2728 12368 flog_err(
e50f7cfd 12369 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12370 "Unable to allocate memory for JSON object");
12371 vty_out(vty,
12372 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12373 return;
12374 }
12375
12376 json_object_int_add(json, "vrfId",
12377 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12378 ? -1
12379 : (int64_t)bgp->vrf_id);
d62a17ae 12380 json_object_string_add(
12381 json, "vrfName",
12382 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12383 ? VRF_DEFAULT_NAME
d62a17ae 12384 : bgp->name);
12385
12386 if (!is_first)
12387 vty_out(vty, ",\n");
12388 else
12389 is_first = 0;
12390
12391 vty_out(vty, "\"%s\":",
12392 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12393 ? VRF_DEFAULT_NAME
d62a17ae 12394 : bgp->name);
12395 } else {
12396 vty_out(vty, "\nInstance %s:\n",
12397 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12398 ? VRF_DEFAULT_NAME
d62a17ae 12399 : bgp->name);
12400 }
71aedaa3 12401
d1927ebe
AS
12402 if (type == show_peer || type == show_ipv4_peer ||
12403 type == show_ipv6_peer) {
71aedaa3
DS
12404 ret = str2sockunion(ip_str, &su);
12405 if (ret < 0)
12406 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12407 use_json, json);
12408 else
12409 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12410 use_json, json);
12411 } else {
d1927ebe 12412 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12413 use_json, json);
12414 }
b77004d6 12415 json_object_free(json);
d62a17ae 12416 }
12417
01cbfd04 12418 if (use_json) {
d62a17ae 12419 vty_out(vty, "}\n");
01cbfd04
QY
12420 json_object_free(json);
12421 }
9f049418
DS
12422 else if (!nbr_output)
12423 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12424}
12425
12426static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12427 enum show_type type, const char *ip_str,
9f049418 12428 bool use_json)
d62a17ae 12429{
12430 int ret;
12431 struct bgp *bgp;
12432 union sockunion su;
12433 json_object *json = NULL;
12434
12435 if (name) {
12436 if (strmatch(name, "all")) {
71aedaa3
DS
12437 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12438 use_json);
d62a17ae 12439 return CMD_SUCCESS;
12440 } else {
12441 bgp = bgp_lookup_by_name(name);
12442 if (!bgp) {
12443 if (use_json) {
12444 json = json_object_new_object();
d62a17ae 12445 vty_out(vty, "%s\n",
12446 json_object_to_json_string_ext(
12447 json,
12448 JSON_C_TO_STRING_PRETTY));
12449 json_object_free(json);
12450 } else
12451 vty_out(vty,
9f049418 12452 "%% BGP instance not found\n");
d62a17ae 12453
12454 return CMD_WARNING;
12455 }
12456 }
12457 } else {
12458 bgp = bgp_get_default();
12459 }
12460
12461 if (bgp) {
12462 json = json_object_new_object();
12463 if (ip_str) {
12464 ret = str2sockunion(ip_str, &su);
12465 if (ret < 0)
12466 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12467 use_json, json);
12468 else
12469 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12470 use_json, json);
12471 } else {
12472 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12473 json);
12474 }
12475 json_object_free(json);
ca61fd25
DS
12476 } else {
12477 if (use_json)
12478 vty_out(vty, "{}\n");
12479 else
12480 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12481 }
12482
12483 return CMD_SUCCESS;
4fb25c53
DW
12484}
12485
2986cac2 12486
12487
12488/* "show [ip] bgp neighbors graceful-restart" commands. */
12489DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12490 show_ip_bgp_neighbors_graceful_restart_cmd,
12491 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12492 SHOW_STR
12493 BGP_STR
12494 IP_STR
12495 IPV6_STR
12496 NEIGHBOR_STR
12497 "Neighbor to display information about\n"
12498 "Neighbor to display information about\n"
12499 "Neighbor on BGP configured interface\n"
12500 GR_SHOW
12501 JSON_STR)
12502{
12503 char *sh_arg = NULL;
12504 enum show_type sh_type;
12505 int idx = 0;
12506 afi_t afi = AFI_MAX;
2986cac2 12507 bool uj = use_json(argc, argv);
12508
12509 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
12510 afi = AFI_MAX;
12511
12512 idx++;
12513
12514 if (argv_find(argv, argc, "A.B.C.D", &idx)
12515 || argv_find(argv, argc, "X:X::X:X", &idx)
12516 || argv_find(argv, argc, "WORD", &idx)) {
12517 sh_type = show_peer;
12518 sh_arg = argv[idx]->arg;
12519 } else
12520 sh_type = show_all;
12521
12522 if (!argv_find(argv, argc, "graceful-restart", &idx))
12523 return CMD_SUCCESS;
12524
12525
12526 return bgp_show_neighbor_graceful_restart_afi_all(vty,
12527 sh_type, sh_arg,
12528 afi, uj);
12529}
12530
716b2d8a 12531/* "show [ip] bgp neighbors" commands. */
718e3744 12532DEFUN (show_ip_bgp_neighbors,
12533 show_ip_bgp_neighbors_cmd,
24345e82 12534 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12535 SHOW_STR
12536 IP_STR
12537 BGP_STR
f2a8972b 12538 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12539 "Address Family\n"
12540 "Address Family\n"
718e3744 12541 "Detailed information on TCP and BGP neighbor connections\n"
12542 "Neighbor to display information about\n"
a80beece 12543 "Neighbor to display information about\n"
91d37724 12544 "Neighbor on BGP configured interface\n"
9973d184 12545 JSON_STR)
718e3744 12546{
d62a17ae 12547 char *vrf = NULL;
12548 char *sh_arg = NULL;
12549 enum show_type sh_type;
d1927ebe 12550 afi_t afi = AFI_MAX;
718e3744 12551
9f049418 12552 bool uj = use_json(argc, argv);
718e3744 12553
d62a17ae 12554 int idx = 0;
718e3744 12555
9a8bdf1c
PG
12556 /* [<vrf> VIEWVRFNAME] */
12557 if (argv_find(argv, argc, "vrf", &idx)) {
12558 vrf = argv[idx + 1]->arg;
12559 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12560 vrf = NULL;
12561 } else if (argv_find(argv, argc, "view", &idx))
12562 /* [<view> VIEWVRFNAME] */
d62a17ae 12563 vrf = argv[idx + 1]->arg;
718e3744 12564
d62a17ae 12565 idx++;
d1927ebe
AS
12566
12567 if (argv_find(argv, argc, "ipv4", &idx)) {
12568 sh_type = show_ipv4_all;
12569 afi = AFI_IP;
12570 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12571 sh_type = show_ipv6_all;
12572 afi = AFI_IP6;
12573 } else {
12574 sh_type = show_all;
12575 }
12576
d62a17ae 12577 if (argv_find(argv, argc, "A.B.C.D", &idx)
12578 || argv_find(argv, argc, "X:X::X:X", &idx)
12579 || argv_find(argv, argc, "WORD", &idx)) {
12580 sh_type = show_peer;
12581 sh_arg = argv[idx]->arg;
d1927ebe
AS
12582 }
12583
12584 if (sh_type == show_peer && afi == AFI_IP) {
12585 sh_type = show_ipv4_peer;
12586 } else if (sh_type == show_peer && afi == AFI_IP6) {
12587 sh_type = show_ipv6_peer;
12588 }
856ca177 12589
d62a17ae 12590 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12591}
12592
716b2d8a 12593/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12594 paths' and `show ip mbgp paths'. Those functions results are the
12595 same.*/
f412b39a 12596DEFUN (show_ip_bgp_paths,
718e3744 12597 show_ip_bgp_paths_cmd,
46f296b4 12598 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12599 SHOW_STR
12600 IP_STR
12601 BGP_STR
46f296b4 12602 BGP_SAFI_HELP_STR
718e3744 12603 "Path information\n")
12604{
d62a17ae 12605 vty_out(vty, "Address Refcnt Path\n");
12606 aspath_print_all_vty(vty);
12607 return CMD_SUCCESS;
718e3744 12608}
12609
718e3744 12610#include "hash.h"
12611
e3b78da8 12612static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12613 struct vty *vty)
718e3744 12614{
d62a17ae 12615 struct community *com;
718e3744 12616
e3b78da8 12617 com = (struct community *)bucket->data;
3f65c5b1 12618 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12619 community_str(com, false));
718e3744 12620}
12621
12622/* Show BGP's community internal data. */
f412b39a 12623DEFUN (show_ip_bgp_community_info,
718e3744 12624 show_ip_bgp_community_info_cmd,
bec37ba5 12625 "show [ip] bgp community-info",
718e3744 12626 SHOW_STR
12627 IP_STR
12628 BGP_STR
12629 "List all bgp community information\n")
12630{
d62a17ae 12631 vty_out(vty, "Address Refcnt Community\n");
718e3744 12632
d62a17ae 12633 hash_iterate(community_hash(),
e3b78da8 12634 (void (*)(struct hash_bucket *,
d62a17ae 12635 void *))community_show_all_iterator,
12636 vty);
718e3744 12637
d62a17ae 12638 return CMD_SUCCESS;
718e3744 12639}
12640
e3b78da8 12641static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12642 struct vty *vty)
57d187bc 12643{
d62a17ae 12644 struct lcommunity *lcom;
57d187bc 12645
e3b78da8 12646 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12647 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12648 lcommunity_str(lcom, false));
57d187bc
JS
12649}
12650
12651/* Show BGP's community internal data. */
12652DEFUN (show_ip_bgp_lcommunity_info,
12653 show_ip_bgp_lcommunity_info_cmd,
12654 "show ip bgp large-community-info",
12655 SHOW_STR
12656 IP_STR
12657 BGP_STR
12658 "List all bgp large-community information\n")
12659{
d62a17ae 12660 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 12661
d62a17ae 12662 hash_iterate(lcommunity_hash(),
e3b78da8 12663 (void (*)(struct hash_bucket *,
d62a17ae 12664 void *))lcommunity_show_all_iterator,
12665 vty);
57d187bc 12666
d62a17ae 12667 return CMD_SUCCESS;
57d187bc 12668}
2986cac2 12669/* Graceful Restart */
12670
12671static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
12672 struct bgp *bgp,
12673 bool use_json,
12674 json_object *json)
12675{
57d187bc
JS
12676
12677
2986cac2 12678 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12679
7318ae88 12680 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 12681
12682 switch (bgp_global_gr_mode) {
12683
12684 case GLOBAL_HELPER:
13909c4f 12685 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 12686 break;
12687
12688 case GLOBAL_GR:
13909c4f 12689 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 12690 break;
12691
12692 case GLOBAL_DISABLE:
13909c4f 12693 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 12694 break;
12695
12696 case GLOBAL_INVALID:
2986cac2 12697 vty_out(vty,
2ba1fe69 12698 "Global BGP GR Mode Invalid\n");
2986cac2 12699 break;
12700 }
12701 vty_out(vty, "\n");
12702}
12703
12704static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12705 enum show_type type,
12706 const char *ip_str,
12707 afi_t afi,
12708 bool use_json)
12709{
12710 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12711 afi = AFI_IP;
12712
12713 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12714
12715 bgp_show_neighbor_graceful_restart_vty(vty,
12716 type, ip_str,
12717 afi, use_json);
12718 afi++;
12719 }
12720 } else if (afi != AFI_MAX) {
12721 bgp_show_neighbor_graceful_restart_vty(vty,
12722 type, ip_str,
12723 afi, use_json);
12724 } else {
12725 return CMD_ERR_INCOMPLETE;
12726 }
12727
12728 return CMD_SUCCESS;
12729}
12730/* Graceful Restart */
12731
f412b39a 12732DEFUN (show_ip_bgp_attr_info,
718e3744 12733 show_ip_bgp_attr_info_cmd,
bec37ba5 12734 "show [ip] bgp attribute-info",
718e3744 12735 SHOW_STR
12736 IP_STR
12737 BGP_STR
12738 "List all bgp attribute information\n")
12739{
d62a17ae 12740 attr_show_all(vty);
12741 return CMD_SUCCESS;
718e3744 12742}
6b0655a2 12743
03915806
CS
12744static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12745 afi_t afi, safi_t safi,
12746 bool use_json, json_object *json)
53089bec 12747{
12748 struct bgp *bgp;
12749 struct listnode *node;
12750 char *vname;
12751 char buf1[INET6_ADDRSTRLEN];
12752 char *ecom_str;
12753 vpn_policy_direction_t dir;
12754
03915806 12755 if (json) {
b46dfd20
DS
12756 json_object *json_import_vrfs = NULL;
12757 json_object *json_export_vrfs = NULL;
12758
b46dfd20
DS
12759 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12760
53089bec 12761 if (!bgp) {
b46dfd20
DS
12762 vty_out(vty, "%s\n",
12763 json_object_to_json_string_ext(
12764 json,
12765 JSON_C_TO_STRING_PRETTY));
12766 json_object_free(json);
12767
53089bec 12768 return CMD_WARNING;
12769 }
b46dfd20 12770
94d4c685
DS
12771 /* Provide context for the block */
12772 json_object_string_add(json, "vrf", name ? name : "default");
12773 json_object_string_add(json, "afiSafi",
5cb5f4d0 12774 get_afi_safi_str(afi, safi, true));
94d4c685 12775
b46dfd20
DS
12776 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12777 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12778 json_object_string_add(json, "importFromVrfs", "none");
12779 json_object_string_add(json, "importRts", "none");
12780 } else {
6ce24e52
DS
12781 json_import_vrfs = json_object_new_array();
12782
b46dfd20
DS
12783 for (ALL_LIST_ELEMENTS_RO(
12784 bgp->vpn_policy[afi].import_vrf,
12785 node, vname))
12786 json_object_array_add(json_import_vrfs,
12787 json_object_new_string(vname));
12788
b20875ea
CS
12789 json_object_object_add(json, "importFromVrfs",
12790 json_import_vrfs);
b46dfd20 12791 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12792 if (bgp->vpn_policy[afi].rtlist[dir]) {
12793 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12794 bgp->vpn_policy[afi].rtlist[dir],
12795 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12796 json_object_string_add(json, "importRts",
12797 ecom_str);
12798 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12799 } else
12800 json_object_string_add(json, "importRts",
12801 "none");
b46dfd20
DS
12802 }
12803
12804 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12805 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12806 json_object_string_add(json, "exportToVrfs", "none");
12807 json_object_string_add(json, "routeDistinguisher",
12808 "none");
12809 json_object_string_add(json, "exportRts", "none");
12810 } else {
6ce24e52
DS
12811 json_export_vrfs = json_object_new_array();
12812
b46dfd20
DS
12813 for (ALL_LIST_ELEMENTS_RO(
12814 bgp->vpn_policy[afi].export_vrf,
12815 node, vname))
12816 json_object_array_add(json_export_vrfs,
12817 json_object_new_string(vname));
12818 json_object_object_add(json, "exportToVrfs",
12819 json_export_vrfs);
12820 json_object_string_add(json, "routeDistinguisher",
12821 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12822 buf1, RD_ADDRSTRLEN));
12823
12824 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12825 if (bgp->vpn_policy[afi].rtlist[dir]) {
12826 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12827 bgp->vpn_policy[afi].rtlist[dir],
12828 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12829 json_object_string_add(json, "exportRts",
12830 ecom_str);
12831 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12832 } else
12833 json_object_string_add(json, "exportRts",
12834 "none");
b46dfd20
DS
12835 }
12836
03915806
CS
12837 if (use_json) {
12838 vty_out(vty, "%s\n",
12839 json_object_to_json_string_ext(json,
b46dfd20 12840 JSON_C_TO_STRING_PRETTY));
03915806
CS
12841 json_object_free(json);
12842 }
53089bec 12843 } else {
b46dfd20
DS
12844 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12845
53089bec 12846 if (!bgp) {
b46dfd20 12847 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 12848 return CMD_WARNING;
12849 }
53089bec 12850
b46dfd20
DS
12851 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12852 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12853 vty_out(vty,
12854 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 12855 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12856 else {
12857 vty_out(vty,
12858 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 12859 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12860
12861 for (ALL_LIST_ELEMENTS_RO(
12862 bgp->vpn_policy[afi].import_vrf,
12863 node, vname))
12864 vty_out(vty, " %s\n", vname);
12865
12866 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12867 ecom_str = NULL;
12868 if (bgp->vpn_policy[afi].rtlist[dir]) {
12869 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12870 bgp->vpn_policy[afi].rtlist[dir],
12871 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 12872 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 12873
b20875ea
CS
12874 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12875 } else
12876 vty_out(vty, "Import RT(s):\n");
53089bec 12877 }
53089bec 12878
b46dfd20
DS
12879 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12880 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12881 vty_out(vty,
12882 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 12883 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12884 else {
12885 vty_out(vty,
04c9077f 12886 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 12887 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12888
12889 for (ALL_LIST_ELEMENTS_RO(
12890 bgp->vpn_policy[afi].export_vrf,
12891 node, vname))
12892 vty_out(vty, " %s\n", vname);
12893
12894 vty_out(vty, "RD: %s\n",
12895 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12896 buf1, RD_ADDRSTRLEN));
12897
12898 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12899 if (bgp->vpn_policy[afi].rtlist[dir]) {
12900 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12901 bgp->vpn_policy[afi].rtlist[dir],
12902 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12903 vty_out(vty, "Export RT: %s\n", ecom_str);
12904 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12905 } else
12906 vty_out(vty, "Import RT(s):\n");
53089bec 12907 }
53089bec 12908 }
12909
12910 return CMD_SUCCESS;
12911}
12912
03915806
CS
12913static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12914 safi_t safi, bool use_json)
12915{
12916 struct listnode *node, *nnode;
12917 struct bgp *bgp;
12918 char *vrf_name = NULL;
12919 json_object *json = NULL;
12920 json_object *json_vrf = NULL;
12921 json_object *json_vrfs = NULL;
12922
12923 if (use_json) {
12924 json = json_object_new_object();
12925 json_vrfs = json_object_new_object();
12926 }
12927
12928 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12929
12930 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12931 vrf_name = bgp->name;
12932
12933 if (use_json) {
12934 json_vrf = json_object_new_object();
12935 } else {
12936 vty_out(vty, "\nInstance %s:\n",
12937 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12938 ? VRF_DEFAULT_NAME : bgp->name);
12939 }
12940 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
12941 if (use_json) {
12942 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12943 json_object_object_add(json_vrfs,
12944 VRF_DEFAULT_NAME, json_vrf);
12945 else
12946 json_object_object_add(json_vrfs, vrf_name,
12947 json_vrf);
12948 }
12949 }
12950
12951 if (use_json) {
12952 json_object_object_add(json, "vrfs", json_vrfs);
12953 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
12954 JSON_C_TO_STRING_PRETTY));
12955 json_object_free(json);
12956 }
12957
12958 return CMD_SUCCESS;
12959}
12960
53089bec 12961/* "show [ip] bgp route-leak" command. */
12962DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
12963 show_ip_bgp_route_leak_cmd,
12964 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
12965 SHOW_STR
12966 IP_STR
12967 BGP_STR
12968 BGP_INSTANCE_HELP_STR
12969 BGP_AFI_HELP_STR
12970 BGP_SAFI_HELP_STR
12971 "Route leaking information\n"
12972 JSON_STR)
53089bec 12973{
12974 char *vrf = NULL;
12975 afi_t afi = AFI_MAX;
12976 safi_t safi = SAFI_MAX;
12977
9f049418 12978 bool uj = use_json(argc, argv);
53089bec 12979 int idx = 0;
03915806 12980 json_object *json = NULL;
53089bec 12981
12982 /* show [ip] bgp */
12983 if (argv_find(argv, argc, "ip", &idx)) {
12984 afi = AFI_IP;
12985 safi = SAFI_UNICAST;
12986 }
12987 /* [vrf VIEWVRFNAME] */
12988 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
12989 vty_out(vty,
12990 "%% This command is not applicable to BGP views\n");
53089bec 12991 return CMD_WARNING;
12992 }
12993
9a8bdf1c
PG
12994 if (argv_find(argv, argc, "vrf", &idx)) {
12995 vrf = argv[idx + 1]->arg;
12996 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12997 vrf = NULL;
12998 }
53089bec 12999 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13000 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13001 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13002 }
13003
13004 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13005 vty_out(vty,
13006 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13007 return CMD_WARNING;
13008 }
13009
03915806
CS
13010 if (vrf && strmatch(vrf, "all"))
13011 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13012
13013 if (uj)
13014 json = json_object_new_object();
13015
13016 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13017}
13018
d62a17ae 13019static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13020 safi_t safi)
f186de26 13021{
d62a17ae 13022 struct listnode *node, *nnode;
13023 struct bgp *bgp;
f186de26 13024
d62a17ae 13025 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13026 vty_out(vty, "\nInstance %s:\n",
13027 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13028 ? VRF_DEFAULT_NAME
d62a17ae 13029 : bgp->name);
13030 update_group_show(bgp, afi, safi, vty, 0);
13031 }
f186de26 13032}
13033
d62a17ae 13034static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13035 int safi, uint64_t subgrp_id)
4fb25c53 13036{
d62a17ae 13037 struct bgp *bgp;
4fb25c53 13038
d62a17ae 13039 if (name) {
13040 if (strmatch(name, "all")) {
13041 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13042 return CMD_SUCCESS;
13043 } else {
13044 bgp = bgp_lookup_by_name(name);
13045 }
13046 } else {
13047 bgp = bgp_get_default();
13048 }
4fb25c53 13049
d62a17ae 13050 if (bgp)
13051 update_group_show(bgp, afi, safi, vty, subgrp_id);
13052 return CMD_SUCCESS;
4fb25c53
DW
13053}
13054
8fe8a7f6
DS
13055DEFUN (show_ip_bgp_updgrps,
13056 show_ip_bgp_updgrps_cmd,
c1a44e43 13057 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13058 SHOW_STR
13059 IP_STR
13060 BGP_STR
13061 BGP_INSTANCE_HELP_STR
c9e571b4 13062 BGP_AFI_HELP_STR
9bedbb1e 13063 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13064 "Detailed info about dynamic update groups\n"
13065 "Specific subgroup to display detailed info for\n")
8386ac43 13066{
d62a17ae 13067 char *vrf = NULL;
13068 afi_t afi = AFI_IP6;
13069 safi_t safi = SAFI_UNICAST;
13070 uint64_t subgrp_id = 0;
13071
13072 int idx = 0;
13073
13074 /* show [ip] bgp */
13075 if (argv_find(argv, argc, "ip", &idx))
13076 afi = AFI_IP;
9a8bdf1c
PG
13077 /* [<vrf> VIEWVRFNAME] */
13078 if (argv_find(argv, argc, "vrf", &idx)) {
13079 vrf = argv[idx + 1]->arg;
13080 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13081 vrf = NULL;
13082 } else if (argv_find(argv, argc, "view", &idx))
13083 /* [<view> VIEWVRFNAME] */
13084 vrf = argv[idx + 1]->arg;
d62a17ae 13085 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13086 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13087 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13088 }
5bf15956 13089
d62a17ae 13090 /* get subgroup id, if provided */
13091 idx = argc - 1;
13092 if (argv[idx]->type == VARIABLE_TKN)
13093 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13094
d62a17ae 13095 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13096}
13097
f186de26 13098DEFUN (show_bgp_instance_all_ipv6_updgrps,
13099 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13100 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13101 SHOW_STR
716b2d8a 13102 IP_STR
f186de26 13103 BGP_STR
13104 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13105 "Detailed info about dynamic update groups\n")
f186de26 13106{
d62a17ae 13107 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13108 return CMD_SUCCESS;
f186de26 13109}
13110
43d3f4fc
DS
13111DEFUN (show_bgp_l2vpn_evpn_updgrps,
13112 show_bgp_l2vpn_evpn_updgrps_cmd,
13113 "show [ip] bgp l2vpn evpn update-groups",
13114 SHOW_STR
13115 IP_STR
13116 BGP_STR
13117 "l2vpn address family\n"
13118 "evpn sub-address family\n"
13119 "Detailed info about dynamic update groups\n")
13120{
13121 char *vrf = NULL;
13122 uint64_t subgrp_id = 0;
13123
13124 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13125 return CMD_SUCCESS;
13126}
13127
5bf15956
DW
13128DEFUN (show_bgp_updgrps_stats,
13129 show_bgp_updgrps_stats_cmd,
716b2d8a 13130 "show [ip] bgp update-groups statistics",
3f9c7369 13131 SHOW_STR
716b2d8a 13132 IP_STR
3f9c7369 13133 BGP_STR
0c7b1b01 13134 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13135 "Statistics\n")
13136{
d62a17ae 13137 struct bgp *bgp;
3f9c7369 13138
d62a17ae 13139 bgp = bgp_get_default();
13140 if (bgp)
13141 update_group_show_stats(bgp, vty);
3f9c7369 13142
d62a17ae 13143 return CMD_SUCCESS;
3f9c7369
DS
13144}
13145
8386ac43 13146DEFUN (show_bgp_instance_updgrps_stats,
13147 show_bgp_instance_updgrps_stats_cmd,
18c57037 13148 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13149 SHOW_STR
716b2d8a 13150 IP_STR
8386ac43 13151 BGP_STR
13152 BGP_INSTANCE_HELP_STR
0c7b1b01 13153 "Detailed info about dynamic update groups\n"
8386ac43 13154 "Statistics\n")
13155{
d62a17ae 13156 int idx_word = 3;
13157 struct bgp *bgp;
8386ac43 13158
d62a17ae 13159 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13160 if (bgp)
13161 update_group_show_stats(bgp, vty);
8386ac43 13162
d62a17ae 13163 return CMD_SUCCESS;
8386ac43 13164}
13165
d62a17ae 13166static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13167 afi_t afi, safi_t safi,
13168 const char *what, uint64_t subgrp_id)
3f9c7369 13169{
d62a17ae 13170 struct bgp *bgp;
8386ac43 13171
d62a17ae 13172 if (name)
13173 bgp = bgp_lookup_by_name(name);
13174 else
13175 bgp = bgp_get_default();
8386ac43 13176
d62a17ae 13177 if (bgp) {
13178 if (!strcmp(what, "advertise-queue"))
13179 update_group_show_adj_queue(bgp, afi, safi, vty,
13180 subgrp_id);
13181 else if (!strcmp(what, "advertised-routes"))
13182 update_group_show_advertised(bgp, afi, safi, vty,
13183 subgrp_id);
13184 else if (!strcmp(what, "packet-queue"))
13185 update_group_show_packet_queue(bgp, afi, safi, vty,
13186 subgrp_id);
13187 }
3f9c7369
DS
13188}
13189
dc64bdec
QY
13190DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13191 show_ip_bgp_instance_updgrps_adj_s_cmd,
13192 "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",
13193 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13194 BGP_SAFI_HELP_STR
13195 "Detailed info about dynamic update groups\n"
13196 "Specific subgroup to display info for\n"
13197 "Advertisement queue\n"
13198 "Announced routes\n"
13199 "Packet queue\n")
3f9c7369 13200{
dc64bdec
QY
13201 uint64_t subgrp_id = 0;
13202 afi_t afiz;
13203 safi_t safiz;
13204 if (sgid)
13205 subgrp_id = strtoull(sgid, NULL, 10);
13206
13207 if (!ip && !afi)
13208 afiz = AFI_IP6;
13209 if (!ip && afi)
13210 afiz = bgp_vty_afi_from_str(afi);
13211 if (ip && !afi)
13212 afiz = AFI_IP;
13213 if (ip && afi) {
13214 afiz = bgp_vty_afi_from_str(afi);
13215 if (afiz != AFI_IP)
13216 vty_out(vty,
13217 "%% Cannot specify both 'ip' and 'ipv6'\n");
13218 return CMD_WARNING;
13219 }
d62a17ae 13220
dc64bdec 13221 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13222
dc64bdec 13223 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13224 return CMD_SUCCESS;
13225}
13226
d62a17ae 13227static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13228{
13229 struct listnode *node, *nnode;
13230 struct prefix *range;
13231 struct peer *conf;
13232 struct peer *peer;
13233 char buf[PREFIX2STR_BUFFER];
13234 afi_t afi;
13235 safi_t safi;
13236 const char *peer_status;
13237 const char *af_str;
13238 int lr_count;
13239 int dynamic;
13240 int af_cfgd;
13241
13242 conf = group->conf;
13243
13244 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
13245 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13246 group->name, conf->as);
d62a17ae 13247 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
13248 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13249 group->name, group->bgp->as);
d62a17ae 13250 } else {
13251 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13252 }
f14e6fdb 13253
d62a17ae 13254 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13255 vty_out(vty, " Peer-group type is internal\n");
13256 else
13257 vty_out(vty, " Peer-group type is external\n");
13258
13259 /* Display AFs configured. */
13260 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13261 FOREACH_AFI_SAFI (afi, safi) {
13262 if (conf->afc[afi][safi]) {
13263 af_cfgd = 1;
5cb5f4d0 13264 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13265 }
05c7a1cc 13266 }
d62a17ae 13267 if (!af_cfgd)
13268 vty_out(vty, " none\n");
13269 else
13270 vty_out(vty, "\n");
13271
13272 /* Display listen ranges (for dynamic neighbors), if any */
13273 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13274 if (afi == AFI_IP)
13275 af_str = "IPv4";
13276 else if (afi == AFI_IP6)
13277 af_str = "IPv6";
13278 else
13279 af_str = "???";
13280 lr_count = listcount(group->listen_range[afi]);
13281 if (lr_count) {
13282 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13283 af_str);
13284
13285
13286 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13287 nnode, range)) {
13288 prefix2str(range, buf, sizeof(buf));
13289 vty_out(vty, " %s\n", buf);
13290 }
13291 }
13292 }
f14e6fdb 13293
d62a17ae 13294 /* Display group members and their status */
13295 if (listcount(group->peer)) {
13296 vty_out(vty, " Peer-group members:\n");
13297 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13298 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13299 peer_status = "Idle (Admin)";
13300 else if (CHECK_FLAG(peer->sflags,
13301 PEER_STATUS_PREFIX_OVERFLOW))
13302 peer_status = "Idle (PfxCt)";
13303 else
13304 peer_status = lookup_msg(bgp_status_msg,
13305 peer->status, NULL);
13306
13307 dynamic = peer_dynamic_neighbor(peer);
13308 vty_out(vty, " %s %s %s \n", peer->host,
13309 dynamic ? "(dynamic)" : "", peer_status);
13310 }
13311 }
f14e6fdb 13312
d62a17ae 13313 return CMD_SUCCESS;
13314}
13315
ff9959b0
QY
13316static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13317 const char *group_name)
d62a17ae 13318{
ff9959b0 13319 struct bgp *bgp;
d62a17ae 13320 struct listnode *node, *nnode;
13321 struct peer_group *group;
ff9959b0
QY
13322 bool found = false;
13323
13324 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13325
13326 if (!bgp) {
9f049418 13327 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13328 return CMD_WARNING;
13329 }
d62a17ae 13330
13331 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13332 if (group_name) {
13333 if (strmatch(group->name, group_name)) {
d62a17ae 13334 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13335 found = true;
13336 break;
d62a17ae 13337 }
ff9959b0
QY
13338 } else {
13339 bgp_show_one_peer_group(vty, group);
d62a17ae 13340 }
f14e6fdb 13341 }
f14e6fdb 13342
ff9959b0 13343 if (group_name && !found)
d62a17ae 13344 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13345
d62a17ae 13346 return CMD_SUCCESS;
f14e6fdb
DS
13347}
13348
f14e6fdb
DS
13349DEFUN (show_ip_bgp_peer_groups,
13350 show_ip_bgp_peer_groups_cmd,
18c57037 13351 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13352 SHOW_STR
13353 IP_STR
13354 BGP_STR
8386ac43 13355 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13356 "Detailed information on BGP peer groups\n"
13357 "Peer group name\n")
f14e6fdb 13358{
d62a17ae 13359 char *vrf, *pg;
d62a17ae 13360 int idx = 0;
f14e6fdb 13361
a4d82a8a
PZ
13362 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13363 : NULL;
d62a17ae 13364 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13365
ff9959b0 13366 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13367}
3f9c7369 13368
d6e3c605 13369
718e3744 13370/* Redistribute VTY commands. */
13371
718e3744 13372DEFUN (bgp_redistribute_ipv4,
13373 bgp_redistribute_ipv4_cmd,
40d1cbfb 13374 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13375 "Redistribute information from another routing protocol\n"
ab0181ee 13376 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13377{
d62a17ae 13378 VTY_DECLVAR_CONTEXT(bgp, bgp);
13379 int idx_protocol = 1;
13380 int type;
718e3744 13381
d62a17ae 13382 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13383 if (type < 0) {
13384 vty_out(vty, "%% Invalid route type\n");
13385 return CMD_WARNING_CONFIG_FAILED;
13386 }
7f323236 13387
d62a17ae 13388 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13389 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13390}
13391
d62a17ae 13392ALIAS_HIDDEN(
13393 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13394 "redistribute " FRR_IP_REDIST_STR_BGPD,
13395 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13396
718e3744 13397DEFUN (bgp_redistribute_ipv4_rmap,
13398 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13399 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13400 "Redistribute information from another routing protocol\n"
ab0181ee 13401 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13402 "Route map reference\n"
13403 "Pointer to route-map entries\n")
13404{
d62a17ae 13405 VTY_DECLVAR_CONTEXT(bgp, bgp);
13406 int idx_protocol = 1;
13407 int idx_word = 3;
13408 int type;
13409 struct bgp_redist *red;
e923dd62 13410 bool changed;
1de27621
DA
13411 struct route_map *route_map = route_map_lookup_warn_noexist(
13412 vty, argv[idx_word]->arg);
718e3744 13413
d62a17ae 13414 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13415 if (type < 0) {
13416 vty_out(vty, "%% Invalid route type\n");
13417 return CMD_WARNING_CONFIG_FAILED;
13418 }
718e3744 13419
d62a17ae 13420 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13421 changed =
13422 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13423 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13424}
13425
d62a17ae 13426ALIAS_HIDDEN(
13427 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13428 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13429 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13430 "Route map reference\n"
13431 "Pointer to route-map entries\n")
596c17ba 13432
718e3744 13433DEFUN (bgp_redistribute_ipv4_metric,
13434 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13435 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13436 "Redistribute information from another routing protocol\n"
ab0181ee 13437 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13438 "Metric for redistributed routes\n"
13439 "Default metric\n")
13440{
d62a17ae 13441 VTY_DECLVAR_CONTEXT(bgp, bgp);
13442 int idx_protocol = 1;
13443 int idx_number = 3;
13444 int type;
d7c0a89a 13445 uint32_t metric;
d62a17ae 13446 struct bgp_redist *red;
e923dd62 13447 bool changed;
d62a17ae 13448
13449 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13450 if (type < 0) {
13451 vty_out(vty, "%% Invalid route type\n");
13452 return CMD_WARNING_CONFIG_FAILED;
13453 }
13454 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13455
13456 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13457 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13458 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13459}
13460
13461ALIAS_HIDDEN(
13462 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13463 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13464 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13465 "Metric for redistributed routes\n"
13466 "Default metric\n")
596c17ba 13467
718e3744 13468DEFUN (bgp_redistribute_ipv4_rmap_metric,
13469 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13470 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13471 "Redistribute information from another routing protocol\n"
ab0181ee 13472 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13473 "Route map reference\n"
13474 "Pointer to route-map entries\n"
13475 "Metric for redistributed routes\n"
13476 "Default metric\n")
13477{
d62a17ae 13478 VTY_DECLVAR_CONTEXT(bgp, bgp);
13479 int idx_protocol = 1;
13480 int idx_word = 3;
13481 int idx_number = 5;
13482 int type;
d7c0a89a 13483 uint32_t metric;
d62a17ae 13484 struct bgp_redist *red;
e923dd62 13485 bool changed;
1de27621
DA
13486 struct route_map *route_map =
13487 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13488
13489 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13490 if (type < 0) {
13491 vty_out(vty, "%% Invalid route type\n");
13492 return CMD_WARNING_CONFIG_FAILED;
13493 }
13494 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13495
13496 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13497 changed =
13498 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13499 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13500 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13501}
13502
13503ALIAS_HIDDEN(
13504 bgp_redistribute_ipv4_rmap_metric,
13505 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13506 "redistribute " FRR_IP_REDIST_STR_BGPD
13507 " route-map WORD metric (0-4294967295)",
13508 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13509 "Route map reference\n"
13510 "Pointer to route-map entries\n"
13511 "Metric for redistributed routes\n"
13512 "Default metric\n")
596c17ba 13513
718e3744 13514DEFUN (bgp_redistribute_ipv4_metric_rmap,
13515 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13516 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13517 "Redistribute information from another routing protocol\n"
ab0181ee 13518 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13519 "Metric for redistributed routes\n"
13520 "Default metric\n"
13521 "Route map reference\n"
13522 "Pointer to route-map entries\n")
13523{
d62a17ae 13524 VTY_DECLVAR_CONTEXT(bgp, bgp);
13525 int idx_protocol = 1;
13526 int idx_number = 3;
13527 int idx_word = 5;
13528 int type;
d7c0a89a 13529 uint32_t metric;
d62a17ae 13530 struct bgp_redist *red;
e923dd62 13531 bool changed;
1de27621
DA
13532 struct route_map *route_map =
13533 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13534
13535 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13536 if (type < 0) {
13537 vty_out(vty, "%% Invalid route type\n");
13538 return CMD_WARNING_CONFIG_FAILED;
13539 }
13540 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13541
13542 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13543 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13544 changed |=
13545 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13546 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13547}
13548
13549ALIAS_HIDDEN(
13550 bgp_redistribute_ipv4_metric_rmap,
13551 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13552 "redistribute " FRR_IP_REDIST_STR_BGPD
13553 " metric (0-4294967295) route-map WORD",
13554 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13555 "Metric for redistributed routes\n"
13556 "Default metric\n"
13557 "Route map reference\n"
13558 "Pointer to route-map entries\n")
596c17ba 13559
7c8ff89e
DS
13560DEFUN (bgp_redistribute_ipv4_ospf,
13561 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13562 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13563 "Redistribute information from another routing protocol\n"
13564 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13565 "Non-main Kernel Routing Table\n"
13566 "Instance ID/Table ID\n")
7c8ff89e 13567{
d62a17ae 13568 VTY_DECLVAR_CONTEXT(bgp, bgp);
13569 int idx_ospf_table = 1;
13570 int idx_number = 2;
d7c0a89a
QY
13571 unsigned short instance;
13572 unsigned short protocol;
7c8ff89e 13573
d62a17ae 13574 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13575
d62a17ae 13576 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13577 protocol = ZEBRA_ROUTE_OSPF;
13578 else
13579 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13580
d62a17ae 13581 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13582 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13583}
13584
d62a17ae 13585ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13586 "redistribute <ospf|table> (1-65535)",
13587 "Redistribute information from another routing protocol\n"
13588 "Open Shortest Path First (OSPFv2)\n"
13589 "Non-main Kernel Routing Table\n"
13590 "Instance ID/Table ID\n")
596c17ba 13591
7c8ff89e
DS
13592DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13593 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13594 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13595 "Redistribute information from another routing protocol\n"
13596 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13597 "Non-main Kernel Routing Table\n"
13598 "Instance ID/Table ID\n"
7c8ff89e
DS
13599 "Route map reference\n"
13600 "Pointer to route-map entries\n")
13601{
d62a17ae 13602 VTY_DECLVAR_CONTEXT(bgp, bgp);
13603 int idx_ospf_table = 1;
13604 int idx_number = 2;
13605 int idx_word = 4;
13606 struct bgp_redist *red;
d7c0a89a 13607 unsigned short instance;
d62a17ae 13608 int protocol;
e923dd62 13609 bool changed;
1de27621
DA
13610 struct route_map *route_map =
13611 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13612
13613 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13614 protocol = ZEBRA_ROUTE_OSPF;
13615 else
13616 protocol = ZEBRA_ROUTE_TABLE;
13617
13618 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13619 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13620 changed =
13621 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13622 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13623}
13624
13625ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13626 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13627 "redistribute <ospf|table> (1-65535) route-map WORD",
13628 "Redistribute information from another routing protocol\n"
13629 "Open Shortest Path First (OSPFv2)\n"
13630 "Non-main Kernel Routing Table\n"
13631 "Instance ID/Table ID\n"
13632 "Route map reference\n"
13633 "Pointer to route-map entries\n")
596c17ba 13634
7c8ff89e
DS
13635DEFUN (bgp_redistribute_ipv4_ospf_metric,
13636 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13637 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13638 "Redistribute information from another routing protocol\n"
13639 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13640 "Non-main Kernel Routing Table\n"
13641 "Instance ID/Table ID\n"
7c8ff89e
DS
13642 "Metric for redistributed routes\n"
13643 "Default metric\n")
13644{
d62a17ae 13645 VTY_DECLVAR_CONTEXT(bgp, bgp);
13646 int idx_ospf_table = 1;
13647 int idx_number = 2;
13648 int idx_number_2 = 4;
d7c0a89a 13649 uint32_t metric;
d62a17ae 13650 struct bgp_redist *red;
d7c0a89a 13651 unsigned short instance;
d62a17ae 13652 int protocol;
e923dd62 13653 bool changed;
d62a17ae 13654
13655 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13656 protocol = ZEBRA_ROUTE_OSPF;
13657 else
13658 protocol = ZEBRA_ROUTE_TABLE;
13659
13660 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13661 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13662
13663 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13664 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13665 metric);
13666 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13667}
13668
13669ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13670 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13671 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13672 "Redistribute information from another routing protocol\n"
13673 "Open Shortest Path First (OSPFv2)\n"
13674 "Non-main Kernel Routing Table\n"
13675 "Instance ID/Table ID\n"
13676 "Metric for redistributed routes\n"
13677 "Default metric\n")
596c17ba 13678
7c8ff89e
DS
13679DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13680 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 13681 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
13682 "Redistribute information from another routing protocol\n"
13683 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13684 "Non-main Kernel Routing Table\n"
13685 "Instance ID/Table ID\n"
7c8ff89e
DS
13686 "Route map reference\n"
13687 "Pointer to route-map entries\n"
13688 "Metric for redistributed routes\n"
13689 "Default metric\n")
13690{
d62a17ae 13691 VTY_DECLVAR_CONTEXT(bgp, bgp);
13692 int idx_ospf_table = 1;
13693 int idx_number = 2;
13694 int idx_word = 4;
13695 int idx_number_2 = 6;
d7c0a89a 13696 uint32_t metric;
d62a17ae 13697 struct bgp_redist *red;
d7c0a89a 13698 unsigned short instance;
d62a17ae 13699 int protocol;
e923dd62 13700 bool changed;
1de27621
DA
13701 struct route_map *route_map =
13702 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13703
13704 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13705 protocol = ZEBRA_ROUTE_OSPF;
13706 else
13707 protocol = ZEBRA_ROUTE_TABLE;
13708
13709 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13710 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13711
13712 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13713 changed =
13714 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13715 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13716 metric);
13717 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13718}
13719
13720ALIAS_HIDDEN(
13721 bgp_redistribute_ipv4_ospf_rmap_metric,
13722 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13723 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13724 "Redistribute information from another routing protocol\n"
13725 "Open Shortest Path First (OSPFv2)\n"
13726 "Non-main Kernel Routing Table\n"
13727 "Instance ID/Table ID\n"
13728 "Route map reference\n"
13729 "Pointer to route-map entries\n"
13730 "Metric for redistributed routes\n"
13731 "Default metric\n")
596c17ba 13732
7c8ff89e
DS
13733DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13734 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 13735 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
13736 "Redistribute information from another routing protocol\n"
13737 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13738 "Non-main Kernel Routing Table\n"
13739 "Instance ID/Table ID\n"
7c8ff89e
DS
13740 "Metric for redistributed routes\n"
13741 "Default metric\n"
13742 "Route map reference\n"
13743 "Pointer to route-map entries\n")
13744{
d62a17ae 13745 VTY_DECLVAR_CONTEXT(bgp, bgp);
13746 int idx_ospf_table = 1;
13747 int idx_number = 2;
13748 int idx_number_2 = 4;
13749 int idx_word = 6;
d7c0a89a 13750 uint32_t metric;
d62a17ae 13751 struct bgp_redist *red;
d7c0a89a 13752 unsigned short instance;
d62a17ae 13753 int protocol;
e923dd62 13754 bool changed;
1de27621
DA
13755 struct route_map *route_map =
13756 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13757
13758 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13759 protocol = ZEBRA_ROUTE_OSPF;
13760 else
13761 protocol = ZEBRA_ROUTE_TABLE;
13762
13763 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13764 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13765
13766 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13767 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13768 metric);
1de27621
DA
13769 changed |=
13770 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13771 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13772}
13773
13774ALIAS_HIDDEN(
13775 bgp_redistribute_ipv4_ospf_metric_rmap,
13776 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13777 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13778 "Redistribute information from another routing protocol\n"
13779 "Open Shortest Path First (OSPFv2)\n"
13780 "Non-main Kernel Routing Table\n"
13781 "Instance ID/Table ID\n"
13782 "Metric for redistributed routes\n"
13783 "Default metric\n"
13784 "Route map reference\n"
13785 "Pointer to route-map entries\n")
596c17ba 13786
7c8ff89e
DS
13787DEFUN (no_bgp_redistribute_ipv4_ospf,
13788 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 13789 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
13790 NO_STR
13791 "Redistribute information from another routing protocol\n"
13792 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 13793 "Non-main Kernel Routing Table\n"
31500417
DW
13794 "Instance ID/Table ID\n"
13795 "Metric for redistributed routes\n"
13796 "Default metric\n"
13797 "Route map reference\n"
13798 "Pointer to route-map entries\n")
7c8ff89e 13799{
d62a17ae 13800 VTY_DECLVAR_CONTEXT(bgp, bgp);
13801 int idx_ospf_table = 2;
13802 int idx_number = 3;
d7c0a89a 13803 unsigned short instance;
d62a17ae 13804 int protocol;
13805
13806 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13807 protocol = ZEBRA_ROUTE_OSPF;
13808 else
13809 protocol = ZEBRA_ROUTE_TABLE;
13810
13811 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13812 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13813}
13814
13815ALIAS_HIDDEN(
13816 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 13817 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13818 NO_STR
13819 "Redistribute information from another routing protocol\n"
13820 "Open Shortest Path First (OSPFv2)\n"
13821 "Non-main Kernel Routing Table\n"
13822 "Instance ID/Table ID\n"
13823 "Metric for redistributed routes\n"
13824 "Default metric\n"
13825 "Route map reference\n"
13826 "Pointer to route-map entries\n")
596c17ba 13827
718e3744 13828DEFUN (no_bgp_redistribute_ipv4,
13829 no_bgp_redistribute_ipv4_cmd,
e27957c0 13830 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 13831 NO_STR
13832 "Redistribute information from another routing protocol\n"
3b14d86e 13833 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
13834 "Metric for redistributed routes\n"
13835 "Default metric\n"
13836 "Route map reference\n"
13837 "Pointer to route-map entries\n")
718e3744 13838{
d62a17ae 13839 VTY_DECLVAR_CONTEXT(bgp, bgp);
13840 int idx_protocol = 2;
13841 int type;
13842
13843 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13844 if (type < 0) {
13845 vty_out(vty, "%% Invalid route type\n");
13846 return CMD_WARNING_CONFIG_FAILED;
13847 }
13848 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13849}
13850
13851ALIAS_HIDDEN(
13852 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13853 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 13854 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13855 NO_STR
13856 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13857 "Metric for redistributed routes\n"
13858 "Default metric\n"
13859 "Route map reference\n"
13860 "Pointer to route-map entries\n")
596c17ba 13861
718e3744 13862DEFUN (bgp_redistribute_ipv6,
13863 bgp_redistribute_ipv6_cmd,
40d1cbfb 13864 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 13865 "Redistribute information from another routing protocol\n"
ab0181ee 13866 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 13867{
d62a17ae 13868 VTY_DECLVAR_CONTEXT(bgp, bgp);
13869 int idx_protocol = 1;
13870 int type;
718e3744 13871
d62a17ae 13872 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13873 if (type < 0) {
13874 vty_out(vty, "%% Invalid route type\n");
13875 return CMD_WARNING_CONFIG_FAILED;
13876 }
718e3744 13877
d62a17ae 13878 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13879 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 13880}
13881
13882DEFUN (bgp_redistribute_ipv6_rmap,
13883 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 13884 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 13885 "Redistribute information from another routing protocol\n"
ab0181ee 13886 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13887 "Route map reference\n"
13888 "Pointer to route-map entries\n")
13889{
d62a17ae 13890 VTY_DECLVAR_CONTEXT(bgp, bgp);
13891 int idx_protocol = 1;
13892 int idx_word = 3;
13893 int type;
13894 struct bgp_redist *red;
e923dd62 13895 bool changed;
1de27621
DA
13896 struct route_map *route_map =
13897 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 13898
d62a17ae 13899 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13900 if (type < 0) {
13901 vty_out(vty, "%% Invalid route type\n");
13902 return CMD_WARNING_CONFIG_FAILED;
13903 }
718e3744 13904
d62a17ae 13905 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13906 changed =
13907 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13908 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13909}
13910
13911DEFUN (bgp_redistribute_ipv6_metric,
13912 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 13913 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13914 "Redistribute information from another routing protocol\n"
ab0181ee 13915 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13916 "Metric for redistributed routes\n"
13917 "Default metric\n")
13918{
d62a17ae 13919 VTY_DECLVAR_CONTEXT(bgp, bgp);
13920 int idx_protocol = 1;
13921 int idx_number = 3;
13922 int type;
d7c0a89a 13923 uint32_t metric;
d62a17ae 13924 struct bgp_redist *red;
e923dd62 13925 bool changed;
d62a17ae 13926
13927 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13928 if (type < 0) {
13929 vty_out(vty, "%% Invalid route type\n");
13930 return CMD_WARNING_CONFIG_FAILED;
13931 }
13932 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13933
d62a17ae 13934 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13935 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13936 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13937}
13938
13939DEFUN (bgp_redistribute_ipv6_rmap_metric,
13940 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 13941 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13942 "Redistribute information from another routing protocol\n"
ab0181ee 13943 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13944 "Route map reference\n"
13945 "Pointer to route-map entries\n"
13946 "Metric for redistributed routes\n"
13947 "Default metric\n")
13948{
d62a17ae 13949 VTY_DECLVAR_CONTEXT(bgp, bgp);
13950 int idx_protocol = 1;
13951 int idx_word = 3;
13952 int idx_number = 5;
13953 int type;
d7c0a89a 13954 uint32_t metric;
d62a17ae 13955 struct bgp_redist *red;
e923dd62 13956 bool changed;
1de27621
DA
13957 struct route_map *route_map =
13958 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13959
13960 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13961 if (type < 0) {
13962 vty_out(vty, "%% Invalid route type\n");
13963 return CMD_WARNING_CONFIG_FAILED;
13964 }
13965 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13966
d62a17ae 13967 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13968 changed =
13969 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13970 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
13971 metric);
13972 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13973}
13974
13975DEFUN (bgp_redistribute_ipv6_metric_rmap,
13976 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 13977 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13978 "Redistribute information from another routing protocol\n"
ab0181ee 13979 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13980 "Metric for redistributed routes\n"
13981 "Default metric\n"
13982 "Route map reference\n"
13983 "Pointer to route-map entries\n")
13984{
d62a17ae 13985 VTY_DECLVAR_CONTEXT(bgp, bgp);
13986 int idx_protocol = 1;
13987 int idx_number = 3;
13988 int idx_word = 5;
13989 int type;
d7c0a89a 13990 uint32_t metric;
d62a17ae 13991 struct bgp_redist *red;
e923dd62 13992 bool changed;
1de27621
DA
13993 struct route_map *route_map =
13994 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13995
13996 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13997 if (type < 0) {
13998 vty_out(vty, "%% Invalid route type\n");
13999 return CMD_WARNING_CONFIG_FAILED;
14000 }
14001 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14002
d62a17ae 14003 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14004 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14005 metric);
1de27621
DA
14006 changed |=
14007 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14008 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14009}
14010
14011DEFUN (no_bgp_redistribute_ipv6,
14012 no_bgp_redistribute_ipv6_cmd,
e27957c0 14013 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14014 NO_STR
14015 "Redistribute information from another routing protocol\n"
3b14d86e 14016 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14017 "Metric for redistributed routes\n"
14018 "Default metric\n"
14019 "Route map reference\n"
14020 "Pointer to route-map entries\n")
718e3744 14021{
d62a17ae 14022 VTY_DECLVAR_CONTEXT(bgp, bgp);
14023 int idx_protocol = 2;
14024 int type;
718e3744 14025
d62a17ae 14026 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14027 if (type < 0) {
14028 vty_out(vty, "%% Invalid route type\n");
14029 return CMD_WARNING_CONFIG_FAILED;
14030 }
718e3744 14031
d62a17ae 14032 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14033}
14034
dd65f45e
DL
14035static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14036 afi_t afi, safi_t safi)
d62a17ae 14037{
14038 int i;
14039
14040 /* Unicast redistribution only. */
14041 if (safi != SAFI_UNICAST)
2b791107 14042 return;
d62a17ae 14043
14044 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14045 /* Redistribute BGP does not make sense. */
14046 if (i != ZEBRA_ROUTE_BGP) {
14047 struct list *red_list;
14048 struct listnode *node;
14049 struct bgp_redist *red;
14050
14051 red_list = bgp->redist[afi][i];
14052 if (!red_list)
14053 continue;
14054
14055 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14056 /* "redistribute" configuration. */
14057 vty_out(vty, " redistribute %s",
14058 zebra_route_string(i));
14059 if (red->instance)
14060 vty_out(vty, " %d", red->instance);
14061 if (red->redist_metric_flag)
14062 vty_out(vty, " metric %u",
14063 red->redist_metric);
14064 if (red->rmap.name)
14065 vty_out(vty, " route-map %s",
14066 red->rmap.name);
14067 vty_out(vty, "\n");
14068 }
14069 }
14070 }
718e3744 14071}
6b0655a2 14072
dd65f45e
DL
14073/* peer-group helpers for config-write */
14074
14075static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14076{
14077 if (!peer_group_active(peer)) {
14078 if (CHECK_FLAG(peer->flags_invert, flag))
14079 return !CHECK_FLAG(peer->flags, flag);
14080 else
14081 return !!CHECK_FLAG(peer->flags, flag);
14082 }
14083
14084 return !!CHECK_FLAG(peer->flags_override, flag);
14085}
14086
14087static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14088 uint32_t flag)
14089{
14090 if (!peer_group_active(peer)) {
14091 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14092 return !peer_af_flag_check(peer, afi, safi, flag);
14093 else
14094 return !!peer_af_flag_check(peer, afi, safi, flag);
14095 }
14096
14097 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14098}
14099
14100static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14101 uint8_t type, int direct)
14102{
14103 struct bgp_filter *filter;
14104
14105 if (peer_group_active(peer))
14106 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14107 type);
14108
14109 filter = &peer->filter[afi][safi];
14110 switch (type) {
14111 case PEER_FT_DISTRIBUTE_LIST:
14112 return !!(filter->dlist[direct].name);
14113 case PEER_FT_FILTER_LIST:
14114 return !!(filter->aslist[direct].name);
14115 case PEER_FT_PREFIX_LIST:
14116 return !!(filter->plist[direct].name);
14117 case PEER_FT_ROUTE_MAP:
14118 return !!(filter->map[direct].name);
14119 case PEER_FT_UNSUPPRESS_MAP:
14120 return !!(filter->usmap.name);
14121 default:
14122 return false;
14123 }
14124}
14125
14126/* Return true if the addpath type is set for peer and different from
14127 * peer-group.
14128 */
14129static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
14130{
14131 enum bgp_addpath_strat type, g_type;
14132
14133 type = peer->addpath_type[afi][safi];
14134
14135 if (type != BGP_ADDPATH_NONE) {
14136 if (peer_group_active(peer)) {
14137 g_type = peer->group->conf->addpath_type[afi][safi];
14138
14139 if (type != g_type)
14140 return 1;
14141 else
14142 return 0;
14143 }
14144
14145 return 1;
14146 }
14147
14148 return 0;
14149}
14150
b9c7bc5a 14151/* This is part of the address-family block (unicast only) */
dd65f45e 14152static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14153 afi_t afi)
14154{
b9c7bc5a 14155 int indent = 2;
ddb5b488 14156
8a066a70
PG
14157 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14158 if (listcount(bgp->vpn_policy[afi].import_vrf))
14159 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14160 bgp->vpn_policy[afi]
bb4f6190 14161 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14162 else
14163 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14164 bgp->vpn_policy[afi]
14165 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14166 }
12a844a5
DS
14167 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14168 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14169 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14170 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14171 return;
14172
e70e9f8e
PZ
14173 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14174 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14175
14176 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14177
14178 } else {
14179 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14180 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14181 bgp->vpn_policy[afi].tovpn_label);
14182 }
ddb5b488
PZ
14183 }
14184 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14185 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14186 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14187 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14188 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14189 sizeof(buf)));
14190 }
14191 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14192 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14193
14194 char buf[PREFIX_STRLEN];
14195 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14196 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14197 sizeof(buf))) {
14198
b9c7bc5a
PZ
14199 vty_out(vty, "%*snexthop vpn export %s\n",
14200 indent, "", buf);
ddb5b488
PZ
14201 }
14202 }
14203 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14204 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14205 && ecommunity_cmp(
14206 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14207 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14208
14209 char *b = ecommunity_ecom2str(
14210 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14211 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14212 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14213 XFREE(MTYPE_ECOMMUNITY_STR, b);
14214 } else {
14215 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14216 char *b = ecommunity_ecom2str(
14217 bgp->vpn_policy[afi]
14218 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14219 ECOMMUNITY_FORMAT_ROUTE_MAP,
14220 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14221 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14222 XFREE(MTYPE_ECOMMUNITY_STR, b);
14223 }
14224 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14225 char *b = ecommunity_ecom2str(
14226 bgp->vpn_policy[afi]
14227 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14228 ECOMMUNITY_FORMAT_ROUTE_MAP,
14229 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14230 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14231 XFREE(MTYPE_ECOMMUNITY_STR, b);
14232 }
14233 }
bb4f6190
DS
14234
14235 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14236 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14237 bgp->vpn_policy[afi]
14238 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14239
301ad80a
PG
14240 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14241 char *b = ecommunity_ecom2str(
14242 bgp->vpn_policy[afi]
14243 .import_redirect_rtlist,
14244 ECOMMUNITY_FORMAT_ROUTE_MAP,
14245 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14246
301ad80a
PG
14247 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14248 XFREE(MTYPE_ECOMMUNITY_STR, b);
14249 }
ddb5b488
PZ
14250}
14251
dd65f45e
DL
14252static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14253 afi_t afi, safi_t safi)
14254{
14255 struct bgp_filter *filter;
14256 char *addr;
14257
14258 addr = peer->host;
14259 filter = &peer->filter[afi][safi];
14260
14261 /* distribute-list. */
14262 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14263 FILTER_IN))
14264 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14265 filter->dlist[FILTER_IN].name);
14266
14267 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14268 FILTER_OUT))
14269 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14270 filter->dlist[FILTER_OUT].name);
14271
14272 /* prefix-list. */
14273 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14274 FILTER_IN))
14275 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14276 filter->plist[FILTER_IN].name);
14277
14278 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14279 FILTER_OUT))
14280 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14281 filter->plist[FILTER_OUT].name);
14282
14283 /* route-map. */
14284 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14285 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14286 filter->map[RMAP_IN].name);
14287
14288 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14289 RMAP_OUT))
14290 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14291 filter->map[RMAP_OUT].name);
14292
14293 /* unsuppress-map */
14294 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14295 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14296 filter->usmap.name);
14297
14298 /* filter-list. */
14299 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14300 FILTER_IN))
14301 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14302 filter->aslist[FILTER_IN].name);
14303
14304 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14305 FILTER_OUT))
14306 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14307 filter->aslist[FILTER_OUT].name);
14308}
14309
14310/* BGP peer configuration display function. */
14311static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14312 struct peer *peer)
14313{
14314 struct peer *g_peer = NULL;
14315 char buf[SU_ADDRSTRLEN];
14316 char *addr;
14317 int if_pg_printed = false;
14318 int if_ras_printed = false;
14319
14320 /* Skip dynamic neighbors. */
14321 if (peer_dynamic_neighbor(peer))
14322 return;
14323
14324 if (peer->conf_if)
14325 addr = peer->conf_if;
14326 else
14327 addr = peer->host;
14328
14329 /************************************
14330 ****** Global to the neighbor ******
14331 ************************************/
14332 if (peer->conf_if) {
14333 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14334 vty_out(vty, " neighbor %s interface v6only", addr);
14335 else
14336 vty_out(vty, " neighbor %s interface", addr);
14337
14338 if (peer_group_active(peer)) {
14339 vty_out(vty, " peer-group %s", peer->group->name);
14340 if_pg_printed = true;
14341 } else if (peer->as_type == AS_SPECIFIED) {
14342 vty_out(vty, " remote-as %u", peer->as);
14343 if_ras_printed = true;
14344 } else if (peer->as_type == AS_INTERNAL) {
14345 vty_out(vty, " remote-as internal");
14346 if_ras_printed = true;
14347 } else if (peer->as_type == AS_EXTERNAL) {
14348 vty_out(vty, " remote-as external");
14349 if_ras_printed = true;
14350 }
14351
14352 vty_out(vty, "\n");
14353 }
14354
14355 /* remote-as and peer-group */
14356 /* peer is a member of a peer-group */
14357 if (peer_group_active(peer)) {
14358 g_peer = peer->group->conf;
14359
14360 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14361 if (peer->as_type == AS_SPECIFIED) {
14362 vty_out(vty, " neighbor %s remote-as %u\n",
14363 addr, peer->as);
14364 } else if (peer->as_type == AS_INTERNAL) {
14365 vty_out(vty,
14366 " neighbor %s remote-as internal\n",
14367 addr);
14368 } else if (peer->as_type == AS_EXTERNAL) {
14369 vty_out(vty,
14370 " neighbor %s remote-as external\n",
14371 addr);
14372 }
14373 }
14374
14375 /* For swpX peers we displayed the peer-group
14376 * via 'neighbor swpX interface peer-group PGNAME' */
14377 if (!if_pg_printed)
14378 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14379 peer->group->name);
14380 }
14381
14382 /* peer is NOT a member of a peer-group */
14383 else {
14384 /* peer is a peer-group, declare the peer-group */
14385 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14386 vty_out(vty, " neighbor %s peer-group\n", addr);
14387 }
14388
14389 if (!if_ras_printed) {
14390 if (peer->as_type == AS_SPECIFIED) {
14391 vty_out(vty, " neighbor %s remote-as %u\n",
14392 addr, peer->as);
14393 } else if (peer->as_type == AS_INTERNAL) {
14394 vty_out(vty,
14395 " neighbor %s remote-as internal\n",
14396 addr);
14397 } else if (peer->as_type == AS_EXTERNAL) {
14398 vty_out(vty,
14399 " neighbor %s remote-as external\n",
14400 addr);
14401 }
14402 }
14403 }
14404
14405 /* local-as */
14406 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14407 vty_out(vty, " neighbor %s local-as %u", addr,
14408 peer->change_local_as);
14409 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14410 vty_out(vty, " no-prepend");
14411 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14412 vty_out(vty, " replace-as");
14413 vty_out(vty, "\n");
14414 }
14415
14416 /* description */
14417 if (peer->desc) {
14418 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14419 }
14420
14421 /* shutdown */
14422 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14423 if (peer->tx_shutdown_message)
14424 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14425 peer->tx_shutdown_message);
14426 else
14427 vty_out(vty, " neighbor %s shutdown\n", addr);
14428 }
14429
14430 /* bfd */
14431 if (peer->bfd_info) {
14432 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14433 bgp_bfd_peer_config_write(vty, peer, addr);
14434 }
14435 }
14436
14437 /* password */
14438 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14439 vty_out(vty, " neighbor %s password %s\n", addr,
14440 peer->password);
14441
14442 /* neighbor solo */
14443 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14444 if (!peer_group_active(peer)) {
14445 vty_out(vty, " neighbor %s solo\n", addr);
14446 }
14447 }
14448
14449 /* BGP port */
14450 if (peer->port != BGP_PORT_DEFAULT) {
14451 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14452 }
14453
14454 /* Local interface name */
14455 if (peer->ifname) {
14456 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14457 }
14458
14459 /* passive */
14460 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14461 vty_out(vty, " neighbor %s passive\n", addr);
14462
14463 /* ebgp-multihop */
14464 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14465 && !(peer->gtsm_hops != 0 && peer->ttl == MAXTTL)) {
14466 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14467 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14468 peer->ttl);
14469 }
14470 }
14471
14472 /* ttl-security hops */
14473 if (peer->gtsm_hops != 0) {
14474 if (!peer_group_active(peer)
14475 || g_peer->gtsm_hops != peer->gtsm_hops) {
14476 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14477 addr, peer->gtsm_hops);
14478 }
14479 }
14480
14481 /* disable-connected-check */
14482 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14483 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14484
14485 /* enforce-first-as */
14486 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14487 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14488
14489 /* update-source */
14490 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14491 if (peer->update_source)
14492 vty_out(vty, " neighbor %s update-source %s\n", addr,
14493 sockunion2str(peer->update_source, buf,
14494 SU_ADDRSTRLEN));
14495 else if (peer->update_if)
14496 vty_out(vty, " neighbor %s update-source %s\n", addr,
14497 peer->update_if);
14498 }
14499
14500 /* advertisement-interval */
14501 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14502 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14503 peer->routeadv);
14504
14505 /* timers */
14506 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14507 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14508 peer->keepalive, peer->holdtime);
14509
14510 /* timers connect */
14511 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14512 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14513 peer->connect);
5d5393b9
DL
14514 /* need special-case handling for changed default values due to
14515 * config profile / version (because there is no "timers bgp connect"
14516 * command, we need to save this per-peer :/)
14517 */
14518 else if (!peer_group_active(peer) && !peer->connect &&
14519 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14520 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14521 peer->bgp->default_connect_retry);
dd65f45e
DL
14522
14523 /* capability dynamic */
14524 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14525 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14526
14527 /* capability extended-nexthop */
14528 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14529 if (!peer->conf_if) {
14530 if (CHECK_FLAG(peer->flags_invert,
14531 PEER_FLAG_CAPABILITY_ENHE))
14532 vty_out(vty,
14533 " no neighbor %s capability extended-nexthop\n",
14534 addr);
14535 else
14536 vty_out(vty,
14537 " neighbor %s capability extended-nexthop\n",
14538 addr);
14539 }
14540 }
14541
14542 /* dont-capability-negotiation */
14543 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14544 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14545
14546 /* override-capability */
14547 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14548 vty_out(vty, " neighbor %s override-capability\n", addr);
14549
14550 /* strict-capability-match */
14551 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14552 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14553
14554 /* Sender side AS path loop detection. */
14555 if (peer->as_path_loop_detection)
14556 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14557 addr);
cfd47646 14558
14559 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14560 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14561
14562 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14563 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14564 vty_out(vty,
14565 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14566 } else if (CHECK_FLAG(
14567 peer->peer_gr_new_status_flag,
14568 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14569 vty_out(vty,
14570 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14571 } else if (
14572 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14573 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14574 && !(CHECK_FLAG(
14575 peer->peer_gr_new_status_flag,
14576 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14577 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14578 addr);
cfd47646 14579 }
14580 }
dd65f45e
DL
14581}
14582
14583/* BGP peer configuration display function. */
14584static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14585 struct peer *peer, afi_t afi, safi_t safi)
14586{
14587 struct peer *g_peer = NULL;
14588 char *addr;
14589 bool flag_scomm, flag_secomm, flag_slcomm;
14590
14591 /* Skip dynamic neighbors. */
14592 if (peer_dynamic_neighbor(peer))
14593 return;
14594
14595 if (peer->conf_if)
14596 addr = peer->conf_if;
14597 else
14598 addr = peer->host;
14599
14600 /************************************
14601 ****** Per AF to the neighbor ******
14602 ************************************/
14603 if (peer_group_active(peer)) {
14604 g_peer = peer->group->conf;
14605
14606 /* If the peer-group is active but peer is not, print a 'no
14607 * activate' */
14608 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14609 vty_out(vty, " no neighbor %s activate\n", addr);
14610 }
14611
14612 /* If the peer-group is not active but peer is, print an
14613 'activate' */
14614 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14615 vty_out(vty, " neighbor %s activate\n", addr);
14616 }
14617 } else {
14618 if (peer->afc[afi][safi]) {
14619 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14620 if (bgp_flag_check(bgp,
14621 BGP_FLAG_NO_DEFAULT_IPV4)) {
14622 vty_out(vty, " neighbor %s activate\n",
14623 addr);
14624 }
14625 } else
14626 vty_out(vty, " neighbor %s activate\n", addr);
14627 } else {
14628 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
14629 if (!bgp_flag_check(bgp,
14630 BGP_FLAG_NO_DEFAULT_IPV4)) {
14631 vty_out(vty,
14632 " no neighbor %s activate\n",
14633 addr);
14634 }
14635 }
14636 }
14637 }
14638
14639 /* addpath TX knobs */
14640 if (peergroup_af_addpath_check(peer, afi, safi)) {
14641 switch (peer->addpath_type[afi][safi]) {
14642 case BGP_ADDPATH_ALL:
14643 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14644 addr);
14645 break;
14646 case BGP_ADDPATH_BEST_PER_AS:
14647 vty_out(vty,
14648 " neighbor %s addpath-tx-bestpath-per-AS\n",
14649 addr);
14650 break;
14651 case BGP_ADDPATH_MAX:
14652 case BGP_ADDPATH_NONE:
14653 break;
14654 }
14655 }
14656
14657 /* ORF capability. */
14658 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14659 || peergroup_af_flag_check(peer, afi, safi,
14660 PEER_FLAG_ORF_PREFIX_RM)) {
14661 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14662
14663 if (peergroup_af_flag_check(peer, afi, safi,
14664 PEER_FLAG_ORF_PREFIX_SM)
14665 && peergroup_af_flag_check(peer, afi, safi,
14666 PEER_FLAG_ORF_PREFIX_RM))
14667 vty_out(vty, " both");
14668 else if (peergroup_af_flag_check(peer, afi, safi,
14669 PEER_FLAG_ORF_PREFIX_SM))
14670 vty_out(vty, " send");
14671 else
14672 vty_out(vty, " receive");
14673 vty_out(vty, "\n");
14674 }
14675
14676 /* BGP flag dampening. */
14677 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14678 BGP_CONFIG_DAMPENING))
14679 bgp_config_write_damp(vty, afi, safi);
14680
14681 /* Route reflector client. */
14682 if (peergroup_af_flag_check(peer, afi, safi,
14683 PEER_FLAG_REFLECTOR_CLIENT)) {
14684 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14685 }
14686
14687 /* next-hop-self force */
14688 if (peergroup_af_flag_check(peer, afi, safi,
14689 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14690 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14691 }
14692
14693 /* next-hop-self */
14694 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14695 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14696 }
14697
14698 /* remove-private-AS */
14699 if (peergroup_af_flag_check(peer, afi, safi,
14700 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14701 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14702 addr);
14703 }
14704
14705 else if (peergroup_af_flag_check(peer, afi, safi,
14706 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14707 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14708 addr);
14709 }
14710
14711 else if (peergroup_af_flag_check(peer, afi, safi,
14712 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14713 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14714 }
14715
14716 else if (peergroup_af_flag_check(peer, afi, safi,
14717 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14718 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14719 }
14720
14721 /* as-override */
14722 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14723 vty_out(vty, " neighbor %s as-override\n", addr);
14724 }
14725
14726 /* send-community print. */
14727 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14728 PEER_FLAG_SEND_COMMUNITY);
14729 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14730 PEER_FLAG_SEND_EXT_COMMUNITY);
14731 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14732 PEER_FLAG_SEND_LARGE_COMMUNITY);
14733
14734 if (flag_scomm && flag_secomm && flag_slcomm) {
14735 vty_out(vty, " no neighbor %s send-community all\n", addr);
14736 } else {
14737 if (flag_scomm)
14738 vty_out(vty, " no neighbor %s send-community\n", addr);
14739 if (flag_secomm)
14740 vty_out(vty,
14741 " no neighbor %s send-community extended\n",
14742 addr);
14743
14744 if (flag_slcomm)
14745 vty_out(vty, " no neighbor %s send-community large\n",
14746 addr);
14747 }
14748
14749 /* Default information */
14750 if (peergroup_af_flag_check(peer, afi, safi,
14751 PEER_FLAG_DEFAULT_ORIGINATE)) {
14752 vty_out(vty, " neighbor %s default-originate", addr);
14753
14754 if (peer->default_rmap[afi][safi].name)
14755 vty_out(vty, " route-map %s",
14756 peer->default_rmap[afi][safi].name);
14757
14758 vty_out(vty, "\n");
14759 }
14760
14761 /* Soft reconfiguration inbound. */
14762 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14763 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14764 addr);
14765 }
14766
14767 /* maximum-prefix. */
14768 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14769 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14770 peer->pmax[afi][safi]);
14771
14772 if (peer->pmax_threshold[afi][safi]
14773 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14774 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14775 if (peer_af_flag_check(peer, afi, safi,
14776 PEER_FLAG_MAX_PREFIX_WARNING))
14777 vty_out(vty, " warning-only");
14778 if (peer->pmax_restart[afi][safi])
14779 vty_out(vty, " restart %u",
14780 peer->pmax_restart[afi][safi]);
14781
14782 vty_out(vty, "\n");
14783 }
14784
fde246e8
DA
14785 /* maximum-prefix-out */
14786 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14787 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14788 addr, peer->pmax_out[afi][safi]);
14789
dd65f45e
DL
14790 /* Route server client. */
14791 if (peergroup_af_flag_check(peer, afi, safi,
14792 PEER_FLAG_RSERVER_CLIENT)) {
14793 vty_out(vty, " neighbor %s route-server-client\n", addr);
14794 }
14795
14796 /* Nexthop-local unchanged. */
14797 if (peergroup_af_flag_check(peer, afi, safi,
14798 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14799 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14800 }
14801
14802 /* allowas-in <1-10> */
14803 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14804 if (peer_af_flag_check(peer, afi, safi,
14805 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14806 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14807 } else if (peer->allowas_in[afi][safi] == 3) {
14808 vty_out(vty, " neighbor %s allowas-in\n", addr);
14809 } else {
14810 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14811 peer->allowas_in[afi][safi]);
14812 }
14813 }
14814
14815 /* weight */
14816 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14817 vty_out(vty, " neighbor %s weight %lu\n", addr,
14818 peer->weight[afi][safi]);
14819
14820 /* Filter. */
14821 bgp_config_write_filter(vty, peer, afi, safi);
14822
14823 /* atribute-unchanged. */
14824 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14825 || (safi != SAFI_EVPN
14826 && peer_af_flag_check(peer, afi, safi,
14827 PEER_FLAG_NEXTHOP_UNCHANGED))
14828 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14829
14830 if (!peer_group_active(peer)
14831 || peergroup_af_flag_check(peer, afi, safi,
14832 PEER_FLAG_AS_PATH_UNCHANGED)
14833 || peergroup_af_flag_check(peer, afi, safi,
14834 PEER_FLAG_NEXTHOP_UNCHANGED)
14835 || peergroup_af_flag_check(peer, afi, safi,
14836 PEER_FLAG_MED_UNCHANGED)) {
14837
14838 vty_out(vty,
14839 " neighbor %s attribute-unchanged%s%s%s\n",
14840 addr,
14841 peer_af_flag_check(peer, afi, safi,
14842 PEER_FLAG_AS_PATH_UNCHANGED)
14843 ? " as-path"
14844 : "",
14845 peer_af_flag_check(peer, afi, safi,
14846 PEER_FLAG_NEXTHOP_UNCHANGED)
14847 ? " next-hop"
14848 : "",
14849 peer_af_flag_check(peer, afi, safi,
14850 PEER_FLAG_MED_UNCHANGED)
14851 ? " med"
14852 : "");
14853 }
14854 }
14855}
14856
14857/* Address family based peer configuration display. */
14858static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14859 safi_t safi)
14860{
14861 struct peer *peer;
14862 struct peer_group *group;
14863 struct listnode *node, *nnode;
14864
14865
14866 vty_frame(vty, " !\n address-family ");
14867 if (afi == AFI_IP) {
14868 if (safi == SAFI_UNICAST)
14869 vty_frame(vty, "ipv4 unicast");
14870 else if (safi == SAFI_LABELED_UNICAST)
14871 vty_frame(vty, "ipv4 labeled-unicast");
14872 else if (safi == SAFI_MULTICAST)
14873 vty_frame(vty, "ipv4 multicast");
14874 else if (safi == SAFI_MPLS_VPN)
14875 vty_frame(vty, "ipv4 vpn");
14876 else if (safi == SAFI_ENCAP)
14877 vty_frame(vty, "ipv4 encap");
14878 else if (safi == SAFI_FLOWSPEC)
14879 vty_frame(vty, "ipv4 flowspec");
14880 } else if (afi == AFI_IP6) {
14881 if (safi == SAFI_UNICAST)
14882 vty_frame(vty, "ipv6 unicast");
14883 else if (safi == SAFI_LABELED_UNICAST)
14884 vty_frame(vty, "ipv6 labeled-unicast");
14885 else if (safi == SAFI_MULTICAST)
14886 vty_frame(vty, "ipv6 multicast");
14887 else if (safi == SAFI_MPLS_VPN)
14888 vty_frame(vty, "ipv6 vpn");
14889 else if (safi == SAFI_ENCAP)
14890 vty_frame(vty, "ipv6 encap");
14891 else if (safi == SAFI_FLOWSPEC)
14892 vty_frame(vty, "ipv6 flowspec");
14893 } else if (afi == AFI_L2VPN) {
14894 if (safi == SAFI_EVPN)
14895 vty_frame(vty, "l2vpn evpn");
14896 }
14897 vty_frame(vty, "\n");
14898
14899 bgp_config_write_distance(vty, bgp, afi, safi);
14900
14901 bgp_config_write_network(vty, bgp, afi, safi);
14902
14903 bgp_config_write_redistribute(vty, bgp, afi, safi);
14904
14905 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14906 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14907
14908 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14909 /* Skip dynamic neighbors. */
14910 if (peer_dynamic_neighbor(peer))
14911 continue;
14912
14913 /* Do not display doppelganger peers */
14914 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14915 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14916 }
14917
14918 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14919 bgp_config_write_table_map(vty, bgp, afi, safi);
14920
14921 if (safi == SAFI_EVPN)
14922 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14923
14924 if (safi == SAFI_FLOWSPEC)
14925 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14926
14927 if (safi == SAFI_UNICAST) {
14928 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14929 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14930 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14931
14932 vty_out(vty, " export vpn\n");
14933 }
14934 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14935 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
14936
14937 vty_out(vty, " import vpn\n");
14938 }
14939 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14940 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14941 char *name;
14942
14943 for (ALL_LIST_ELEMENTS_RO(
14944 bgp->vpn_policy[afi].import_vrf, node,
14945 name))
14946 vty_out(vty, " import vrf %s\n", name);
14947 }
14948 }
14949
14950 vty_endframe(vty, " exit-address-family\n");
14951}
14952
14953int bgp_config_write(struct vty *vty)
14954{
14955 struct bgp *bgp;
14956 struct peer_group *group;
14957 struct peer *peer;
14958 struct listnode *node, *nnode;
14959 struct listnode *mnode, *mnnode;
14960
14961 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
14962 vty_out(vty, "bgp route-map delay-timer %u\n",
14963 bm->rmap_update_timer);
14964
14965 /* BGP configuration. */
14966 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
14967
14968 /* skip all auto created vrf as they dont have user config */
14969 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
14970 continue;
14971
14972 /* Router bgp ASN */
14973 vty_out(vty, "router bgp %u", bgp->as);
14974
14975 if (bgp->name)
14976 vty_out(vty, " %s %s",
14977 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
14978 ? "view" : "vrf", bgp->name);
14979 vty_out(vty, "\n");
14980
14981 /* BGP fast-external-failover. */
14982 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
14983 vty_out(vty, " no bgp fast-external-failover\n");
14984
14985 /* BGP router ID. */
14986 if (bgp->router_id_static.s_addr != 0)
14987 vty_out(vty, " bgp router-id %s\n",
14988 inet_ntoa(bgp->router_id_static));
14989
14990 /* BGP log-neighbor-changes. */
14991 if (!!bgp_flag_check(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 14992 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
14993 vty_out(vty, " %sbgp log-neighbor-changes\n",
14994 bgp_flag_check(bgp,
14995 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
14996 ? ""
14997 : "no ");
14998
14999 /* BGP configuration. */
15000 if (bgp_flag_check(bgp, BGP_FLAG_ALWAYS_COMPARE_MED))
15001 vty_out(vty, " bgp always-compare-med\n");
15002
15003 /* RFC8212 default eBGP policy. */
15004 if (bgp->ebgp_requires_policy
15005 == DEFAULT_EBGP_POLICY_ENABLED)
15006 vty_out(vty, " bgp ebgp-requires-policy\n");
15007
15008 /* draft-ietf-idr-deprecate-as-set-confed-set */
15009 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
15010 vty_out(vty, " bgp reject-as-sets\n");
15011
15012 /* BGP default ipv4-unicast. */
15013 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4))
15014 vty_out(vty, " no bgp default ipv4-unicast\n");
15015
15016 /* BGP default local-preference. */
15017 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15018 vty_out(vty, " bgp default local-preference %u\n",
15019 bgp->default_local_pref);
15020
15021 /* BGP default show-hostname */
15022 if (!!bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15023 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e
DL
15024 vty_out(vty, " %sbgp default show-hostname\n",
15025 bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
15026 ? ""
15027 : "no ");
15028
15029 /* BGP default subgroup-pkt-queue-max. */
15030 if (bgp->default_subgroup_pkt_queue_max
15031 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15032 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15033 bgp->default_subgroup_pkt_queue_max);
15034
15035 /* BGP client-to-client reflection. */
15036 if (bgp_flag_check(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
15037 vty_out(vty, " no bgp client-to-client reflection\n");
15038
15039 /* BGP cluster ID. */
15040 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15041 vty_out(vty, " bgp cluster-id %s\n",
15042 inet_ntoa(bgp->cluster_id));
15043
15044 /* Disable ebgp connected nexthop check */
15045 if (bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
15046 vty_out(vty,
15047 " bgp disable-ebgp-connected-route-check\n");
15048
15049 /* Confederation identifier*/
15050 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15051 vty_out(vty, " bgp confederation identifier %u\n",
15052 bgp->confed_id);
15053
15054 /* Confederation peer */
15055 if (bgp->confed_peers_cnt > 0) {
15056 int i;
15057
15058 vty_out(vty, " bgp confederation peers");
15059
15060 for (i = 0; i < bgp->confed_peers_cnt; i++)
15061 vty_out(vty, " %u", bgp->confed_peers[i]);
15062
15063 vty_out(vty, "\n");
15064 }
15065
15066 /* BGP deterministic-med. */
15067 if (!!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15068 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e
DL
15069 vty_out(vty, " %sbgp deterministic-med\n",
15070 bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)
15071 ? ""
15072 : "no ");
15073
15074 /* BGP update-delay. */
15075 bgp_config_write_update_delay(vty, bgp);
15076
15077 if (bgp->v_maxmed_onstartup
15078 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15079 vty_out(vty, " bgp max-med on-startup %u",
15080 bgp->v_maxmed_onstartup);
15081 if (bgp->maxmed_onstartup_value
15082 != BGP_MAXMED_VALUE_DEFAULT)
15083 vty_out(vty, " %u",
15084 bgp->maxmed_onstartup_value);
15085 vty_out(vty, "\n");
15086 }
15087 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15088 vty_out(vty, " bgp max-med administrative");
15089 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15090 vty_out(vty, " %u", bgp->maxmed_admin_value);
15091 vty_out(vty, "\n");
15092 }
15093
15094 /* write quanta */
15095 bgp_config_write_wpkt_quanta(vty, bgp);
15096 /* read quanta */
15097 bgp_config_write_rpkt_quanta(vty, bgp);
15098
15099 /* coalesce time */
15100 bgp_config_write_coalesce_time(vty, bgp);
15101
15102 /* BGP graceful-restart. */
15103 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15104 vty_out(vty,
15105 " bgp graceful-restart stalepath-time %u\n",
15106 bgp->stalepath_time);
cfd47646 15107
dd65f45e
DL
15108 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15109 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15110 bgp->restart_time);
cfd47646 15111
15112 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15113 vty_out(vty,
15114 " bgp graceful-restart select-defer-time %u\n",
15115 bgp->select_defer_time);
15116
15117 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15118 vty_out(vty, " bgp graceful-restart\n");
15119
cfd47646 15120 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15121 vty_out(vty, " bgp graceful-restart-disable\n");
15122
dd65f45e
DL
15123 /* BGP graceful-shutdown */
15124 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN))
15125 vty_out(vty, " bgp graceful-shutdown\n");
15126
15127 /* BGP graceful-restart Preserve State F bit. */
15128 if (bgp_flag_check(bgp, BGP_FLAG_GR_PRESERVE_FWD))
15129 vty_out(vty,
15130 " bgp graceful-restart preserve-fw-state\n");
15131
dc95985f 15132 /* Stale timer for RIB */
15133 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15134 vty_out(vty,
15135 " bgp graceful-restart rib-stale-time %u\n",
15136 bgp->rib_stale_time);
15137
dd65f45e
DL
15138 /* BGP bestpath method. */
15139 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
15140 vty_out(vty, " bgp bestpath as-path ignore\n");
15141 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
15142 vty_out(vty, " bgp bestpath as-path confed\n");
15143
15144 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15145 if (bgp_flag_check(bgp,
15146 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
15147 vty_out(vty,
15148 " bgp bestpath as-path multipath-relax as-set\n");
15149 } else {
15150 vty_out(vty,
15151 " bgp bestpath as-path multipath-relax\n");
15152 }
15153 }
15154
15155 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
15156 vty_out(vty,
15157 " bgp route-reflector allow-outbound-policy\n");
15158 }
15159 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
15160 vty_out(vty, " bgp bestpath compare-routerid\n");
15161 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
15162 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
15163 vty_out(vty, " bgp bestpath med");
15164 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
15165 vty_out(vty, " confed");
15166 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
15167 vty_out(vty, " missing-as-worst");
15168 vty_out(vty, "\n");
15169 }
15170
15171 /* BGP network import check. */
15172 if (!!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15173 != SAVE_BGP_IMPORT_CHECK)
dd65f45e
DL
15174 vty_out(vty, " %sbgp network import-check\n",
15175 bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)
15176 ? ""
15177 : "no ");
15178
15179 /* BGP timers configuration. */
5d5393b9
DL
15180 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15181 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15182 vty_out(vty, " timers bgp %u %u\n",
15183 bgp->default_keepalive, bgp->default_holdtime);
15184
15185 /* peer-group */
15186 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15187 bgp_config_write_peer_global(vty, bgp, group->conf);
15188 }
15189
15190 /* Normal neighbor configuration. */
15191 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15192 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15193 bgp_config_write_peer_global(vty, bgp, peer);
15194 }
15195
15196 /* listen range and limit for dynamic BGP neighbors */
15197 bgp_config_write_listen(vty, bgp);
15198
15199 /*
15200 * BGP default autoshutdown neighbors
15201 *
15202 * This must be placed after any peer and peer-group
15203 * configuration, to avoid setting all peers to shutdown after
15204 * a daemon restart, which is undesired behavior. (see #2286)
15205 */
15206 if (bgp->autoshutdown)
15207 vty_out(vty, " bgp default shutdown\n");
15208
15209 /* IPv4 unicast configuration. */
15210 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15211
15212 /* IPv4 multicast configuration. */
15213 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15214
15215 /* IPv4 labeled-unicast configuration. */
15216 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15217
15218 /* IPv4 VPN configuration. */
15219 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15220
15221 /* ENCAPv4 configuration. */
15222 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15223
15224 /* FLOWSPEC v4 configuration. */
15225 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15226
15227 /* IPv6 unicast configuration. */
15228 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15229
15230 /* IPv6 multicast configuration. */
15231 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15232
15233 /* IPv6 labeled-unicast configuration. */
15234 bgp_config_write_family(vty, bgp, AFI_IP6,
15235 SAFI_LABELED_UNICAST);
15236
15237 /* IPv6 VPN configuration. */
15238 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15239
15240 /* ENCAPv6 configuration. */
15241 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15242
15243 /* FLOWSPEC v6 configuration. */
15244 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15245
15246 /* EVPN configuration. */
15247 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15248
15249 hook_call(bgp_inst_config_write, bgp, vty);
15250
15251#if ENABLE_BGP_VNC
15252 bgp_rfapi_cfg_write(vty, bgp);
15253#endif
15254
15255 vty_out(vty, "!\n");
15256 }
15257 return 0;
15258}
15259
ddb5b488 15260
718e3744 15261/* BGP node structure. */
d62a17ae 15262static struct cmd_node bgp_node = {
9d303b37 15263 BGP_NODE, "%s(config-router)# ", 1,
718e3744 15264};
15265
d62a17ae 15266static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 15267 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 15268};
15269
d62a17ae 15270static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 15271 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 15272};
15273
d62a17ae 15274static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 15275 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15276};
15277
d62a17ae 15278static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 15279 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 15280};
15281
d62a17ae 15282static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 15283 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 15284};
15285
d62a17ae 15286static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 15287 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15288};
15289
d62a17ae 15290static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15291 "%s(config-router-af)# ", 1};
6b0655a2 15292
d62a17ae 15293static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15294 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 15295
d62a17ae 15296static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15297 "%s(config-router-evpn)# ", 1};
4e0b7b6d 15298
d62a17ae 15299static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15300 "%s(config-router-af-vni)# ", 1};
90e60aa7 15301
7c40bf39 15302static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15303 "%s(config-router-af)# ", 1};
15304
15305static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15306 "%s(config-router-af-vpnv6)# ", 1};
15307
d62a17ae 15308static void community_list_vty(void);
1f8ae70b 15309
d62a17ae 15310static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15311{
d62a17ae 15312 struct bgp *bgp;
15313 struct peer *peer;
d62a17ae 15314 struct listnode *lnbgp, *lnpeer;
b8a815e5 15315
d62a17ae 15316 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15317 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15318 /* only provide suggestions on the appropriate input
15319 * token type,
15320 * they'll otherwise show up multiple times */
15321 enum cmd_token_type match_type;
15322 char *name = peer->host;
d48ed3e0 15323
d62a17ae 15324 if (peer->conf_if) {
15325 match_type = VARIABLE_TKN;
15326 name = peer->conf_if;
15327 } else if (strchr(peer->host, ':'))
15328 match_type = IPV6_TKN;
15329 else
15330 match_type = IPV4_TKN;
d48ed3e0 15331
d62a17ae 15332 if (token->type != match_type)
15333 continue;
d48ed3e0 15334
d62a17ae 15335 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15336 }
d62a17ae 15337 }
b8a815e5
DL
15338}
15339
15340static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15341 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15342 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15343 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15344 {.completions = NULL}};
15345
47a306a0
DS
15346static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15347{
15348 struct bgp *bgp;
15349 struct peer_group *group;
15350 struct listnode *lnbgp, *lnpeer;
15351
15352 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15353 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15354 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15355 group->name));
15356 }
15357}
15358
15359static const struct cmd_variable_handler bgp_var_peergroup[] = {
15360 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15361 {.completions = NULL} };
15362
d62a17ae 15363void bgp_vty_init(void)
15364{
15365 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15366 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15367
15368 /* Install bgp top node. */
15369 install_node(&bgp_node, bgp_config_write);
15370 install_node(&bgp_ipv4_unicast_node, NULL);
15371 install_node(&bgp_ipv4_multicast_node, NULL);
15372 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15373 install_node(&bgp_ipv6_unicast_node, NULL);
15374 install_node(&bgp_ipv6_multicast_node, NULL);
15375 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15376 install_node(&bgp_vpnv4_node, NULL);
15377 install_node(&bgp_vpnv6_node, NULL);
15378 install_node(&bgp_evpn_node, NULL);
15379 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 15380 install_node(&bgp_flowspecv4_node, NULL);
15381 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 15382
15383 /* Install default VTY commands to new nodes. */
15384 install_default(BGP_NODE);
15385 install_default(BGP_IPV4_NODE);
15386 install_default(BGP_IPV4M_NODE);
15387 install_default(BGP_IPV4L_NODE);
15388 install_default(BGP_IPV6_NODE);
15389 install_default(BGP_IPV6M_NODE);
15390 install_default(BGP_IPV6L_NODE);
15391 install_default(BGP_VPNV4_NODE);
15392 install_default(BGP_VPNV6_NODE);
7c40bf39 15393 install_default(BGP_FLOWSPECV4_NODE);
15394 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15395 install_default(BGP_EVPN_NODE);
15396 install_default(BGP_EVPN_VNI_NODE);
15397
8029b216
AK
15398 /* "bgp local-mac" hidden commands. */
15399 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15400 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15401
d62a17ae 15402 /* bgp route-map delay-timer commands. */
15403 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15404 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15405
15406 /* Dummy commands (Currently not supported) */
15407 install_element(BGP_NODE, &no_synchronization_cmd);
15408 install_element(BGP_NODE, &no_auto_summary_cmd);
15409
15410 /* "router bgp" commands. */
15411 install_element(CONFIG_NODE, &router_bgp_cmd);
15412
15413 /* "no router bgp" commands. */
15414 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15415
15416 /* "bgp router-id" commands. */
15417 install_element(BGP_NODE, &bgp_router_id_cmd);
15418 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15419
15420 /* "bgp cluster-id" commands. */
15421 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15422 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15423
15424 /* "bgp confederation" commands. */
15425 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15426 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15427
15428 /* "bgp confederation peers" commands. */
15429 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15430 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15431
15432 /* bgp max-med command */
15433 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15434 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15435 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15436 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15437 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15438
15439 /* bgp disable-ebgp-connected-nh-check */
15440 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15441 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15442
15443 /* bgp update-delay command */
15444 install_element(BGP_NODE, &bgp_update_delay_cmd);
15445 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15446 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15447
15448 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15449 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15450
15451 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15452 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15453
15454 /* "maximum-paths" commands. */
15455 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15456 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15457 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15458 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15459 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15460 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15461 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15462 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15463 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15464 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15465 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15466 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15467 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15468 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15469 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15470
15471 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15472 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15473 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15474 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15475 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15476
15477 /* "timers bgp" commands. */
15478 install_element(BGP_NODE, &bgp_timers_cmd);
15479 install_element(BGP_NODE, &no_bgp_timers_cmd);
15480
15481 /* route-map delay-timer commands - per instance for backwards compat.
15482 */
15483 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15484 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15485
15486 /* "bgp client-to-client reflection" commands */
15487 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15488 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15489
15490 /* "bgp always-compare-med" commands */
15491 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15492 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15493
9dac9fc8
DA
15494 /* bgp ebgp-requires-policy */
15495 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15496 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15497
fb29348a
DA
15498 /* bgp reject-as-sets */
15499 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15500 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15501
d62a17ae 15502 /* "bgp deterministic-med" commands */
15503 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15504 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15505
055679e9 15506 /* "bgp graceful-restart" command */
15507 install_element(BGP_NODE,
15508 &bgp_graceful_restart_cmd);
15509 install_element(BGP_NODE,
15510 &no_bgp_graceful_restart_cmd);
15511
15512 /* "bgp graceful-restart-disable" command */
15513 install_element(BGP_NODE,
15514 &bgp_graceful_restart_disable_cmd);
15515 install_element(BGP_NODE,
15516 &no_bgp_graceful_restart_disable_cmd);
15517
15518 /* "neighbor a:b:c:d graceful-restart" command */
15519 install_element(BGP_NODE,
15520 &bgp_neighbor_graceful_restart_set_cmd);
15521 install_element(BGP_NODE,
15522 &no_bgp_neighbor_graceful_restart_set_cmd);
15523
15524 /* "neighbor a:b:c:d graceful-restart-disable" command */
15525 install_element(BGP_NODE,
15526 &bgp_neighbor_graceful_restart_disable_set_cmd);
15527 install_element(BGP_NODE,
15528 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15529
15530 /* "neighbor a:b:c:d graceful-restart-helper" command */
15531 install_element(BGP_NODE,
15532 &bgp_neighbor_graceful_restart_helper_set_cmd);
15533 install_element(BGP_NODE,
15534 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15535
d62a17ae 15536 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15537 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15538 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15539 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15540 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15541 install_element(BGP_NODE,
15542 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15543 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15544 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15545
d6e3c15b 15546 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15547 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15548 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15549 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15550
7f323236
DW
15551 /* "bgp graceful-shutdown" commands */
15552 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15553 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15554
d62a17ae 15555 /* "bgp fast-external-failover" commands */
15556 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15557 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15558
d62a17ae 15559 /* "bgp bestpath compare-routerid" commands */
15560 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15561 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15562
15563 /* "bgp bestpath as-path ignore" commands */
15564 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15565 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15566
15567 /* "bgp bestpath as-path confed" commands */
15568 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15569 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15570
15571 /* "bgp bestpath as-path multipath-relax" commands */
15572 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15573 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15574
15575 /* "bgp log-neighbor-changes" commands */
15576 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15577 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15578
15579 /* "bgp bestpath med" commands */
15580 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15581 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15582
15583 /* "no bgp default ipv4-unicast" commands. */
15584 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15585 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15586
15587 /* "bgp network import-check" commands. */
15588 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15589 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15590 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15591
15592 /* "bgp default local-preference" commands. */
15593 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15594 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15595
15596 /* bgp default show-hostname */
15597 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15598 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15599
15600 /* "bgp default subgroup-pkt-queue-max" commands. */
15601 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15602 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15603
15604 /* bgp ibgp-allow-policy-mods command */
15605 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15606 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15607
15608 /* "bgp listen limit" commands. */
15609 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15610 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15611
15612 /* "bgp listen range" commands. */
15613 install_element(BGP_NODE, &bgp_listen_range_cmd);
15614 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15615
8175f54a 15616 /* "bgp default shutdown" command */
f26845f9
QY
15617 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15618
d62a17ae 15619 /* "neighbor remote-as" commands. */
15620 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15621 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15622 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15623 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15624 install_element(BGP_NODE,
15625 &neighbor_interface_v6only_config_remote_as_cmd);
15626 install_element(BGP_NODE, &no_neighbor_cmd);
15627 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15628
15629 /* "neighbor peer-group" commands. */
15630 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15631 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15632 install_element(BGP_NODE,
15633 &no_neighbor_interface_peer_group_remote_as_cmd);
15634
15635 /* "neighbor local-as" commands. */
15636 install_element(BGP_NODE, &neighbor_local_as_cmd);
15637 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15638 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15639 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15640
15641 /* "neighbor solo" commands. */
15642 install_element(BGP_NODE, &neighbor_solo_cmd);
15643 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15644
15645 /* "neighbor password" commands. */
15646 install_element(BGP_NODE, &neighbor_password_cmd);
15647 install_element(BGP_NODE, &no_neighbor_password_cmd);
15648
15649 /* "neighbor activate" commands. */
15650 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15651 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15652 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15653 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15654 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15655 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15656 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15657 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15658 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 15659 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15660 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 15661 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15662
15663 /* "no neighbor activate" commands. */
15664 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15665 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15666 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15667 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15668 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15669 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15670 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15671 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15672 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 15673 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15674 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 15675 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15676
15677 /* "neighbor peer-group" set commands. */
15678 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15679 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15680 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15681 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15682 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15683 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15684 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15685 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 15686 install_element(BGP_FLOWSPECV4_NODE,
15687 &neighbor_set_peer_group_hidden_cmd);
15688 install_element(BGP_FLOWSPECV6_NODE,
15689 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 15690
15691 /* "no neighbor peer-group unset" commands. */
15692 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15693 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15694 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15695 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15696 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15697 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15698 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15699 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 15700 install_element(BGP_FLOWSPECV4_NODE,
15701 &no_neighbor_set_peer_group_hidden_cmd);
15702 install_element(BGP_FLOWSPECV6_NODE,
15703 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 15704
15705 /* "neighbor softreconfiguration inbound" commands.*/
15706 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15707 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15708 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15709 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15710 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15711 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15712 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15713 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15714 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15715 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15716 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15717 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15718 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15719 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15720 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15721 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15722 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15723 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 15724 install_element(BGP_FLOWSPECV4_NODE,
15725 &neighbor_soft_reconfiguration_cmd);
15726 install_element(BGP_FLOWSPECV4_NODE,
15727 &no_neighbor_soft_reconfiguration_cmd);
15728 install_element(BGP_FLOWSPECV6_NODE,
15729 &neighbor_soft_reconfiguration_cmd);
15730 install_element(BGP_FLOWSPECV6_NODE,
15731 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
15732 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15733 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 15734
15735 /* "neighbor attribute-unchanged" commands. */
15736 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15737 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15738 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15739 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15740 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15741 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15742 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15743 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15744 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15745 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15746 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15747 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15748 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15749 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15750 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15751 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15752 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15753 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15754
15755 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15756 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15757
15758 /* "nexthop-local unchanged" commands */
15759 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15760 install_element(BGP_IPV6_NODE,
15761 &no_neighbor_nexthop_local_unchanged_cmd);
15762
15763 /* "neighbor next-hop-self" commands. */
15764 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15765 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15766 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15767 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15768 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15769 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15770 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15771 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15772 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15773 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15774 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15775 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15776 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15777 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15778 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15779 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15780 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15781 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
15782 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15783 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 15784
15785 /* "neighbor next-hop-self force" commands. */
15786 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15787 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
15788 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15789 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15790 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15791 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15792 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15793 install_element(BGP_IPV4_NODE,
15794 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15795 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15796 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15797 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15798 install_element(BGP_IPV4M_NODE,
15799 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15800 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15801 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15802 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15803 install_element(BGP_IPV4L_NODE,
15804 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15805 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15806 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15807 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15808 install_element(BGP_IPV6_NODE,
15809 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15810 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15811 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15812 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15813 install_element(BGP_IPV6M_NODE,
15814 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15815 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15816 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15817 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15818 install_element(BGP_IPV6L_NODE,
15819 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15820 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15821 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15822 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15823 install_element(BGP_VPNV4_NODE,
15824 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15825 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15826 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15827 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15828 install_element(BGP_VPNV6_NODE,
15829 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15830
15831 /* "neighbor as-override" commands. */
15832 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15833 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15834 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15835 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15836 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15837 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15838 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15839 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15840 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15841 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15842 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15843 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15844 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15845 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15846 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15847 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15848 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15849 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15850
15851 /* "neighbor remove-private-AS" commands. */
15852 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15853 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15854 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15855 install_element(BGP_NODE,
15856 &no_neighbor_remove_private_as_all_hidden_cmd);
15857 install_element(BGP_NODE,
15858 &neighbor_remove_private_as_replace_as_hidden_cmd);
15859 install_element(BGP_NODE,
15860 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15861 install_element(BGP_NODE,
15862 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15863 install_element(
15864 BGP_NODE,
15865 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15866 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15867 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15868 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15869 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15870 install_element(BGP_IPV4_NODE,
15871 &neighbor_remove_private_as_replace_as_cmd);
15872 install_element(BGP_IPV4_NODE,
15873 &no_neighbor_remove_private_as_replace_as_cmd);
15874 install_element(BGP_IPV4_NODE,
15875 &neighbor_remove_private_as_all_replace_as_cmd);
15876 install_element(BGP_IPV4_NODE,
15877 &no_neighbor_remove_private_as_all_replace_as_cmd);
15878 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15879 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15880 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15881 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15882 install_element(BGP_IPV4M_NODE,
15883 &neighbor_remove_private_as_replace_as_cmd);
15884 install_element(BGP_IPV4M_NODE,
15885 &no_neighbor_remove_private_as_replace_as_cmd);
15886 install_element(BGP_IPV4M_NODE,
15887 &neighbor_remove_private_as_all_replace_as_cmd);
15888 install_element(BGP_IPV4M_NODE,
15889 &no_neighbor_remove_private_as_all_replace_as_cmd);
15890 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15891 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15892 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15893 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15894 install_element(BGP_IPV4L_NODE,
15895 &neighbor_remove_private_as_replace_as_cmd);
15896 install_element(BGP_IPV4L_NODE,
15897 &no_neighbor_remove_private_as_replace_as_cmd);
15898 install_element(BGP_IPV4L_NODE,
15899 &neighbor_remove_private_as_all_replace_as_cmd);
15900 install_element(BGP_IPV4L_NODE,
15901 &no_neighbor_remove_private_as_all_replace_as_cmd);
15902 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15903 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15904 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15905 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15906 install_element(BGP_IPV6_NODE,
15907 &neighbor_remove_private_as_replace_as_cmd);
15908 install_element(BGP_IPV6_NODE,
15909 &no_neighbor_remove_private_as_replace_as_cmd);
15910 install_element(BGP_IPV6_NODE,
15911 &neighbor_remove_private_as_all_replace_as_cmd);
15912 install_element(BGP_IPV6_NODE,
15913 &no_neighbor_remove_private_as_all_replace_as_cmd);
15914 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15915 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15916 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15917 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15918 install_element(BGP_IPV6M_NODE,
15919 &neighbor_remove_private_as_replace_as_cmd);
15920 install_element(BGP_IPV6M_NODE,
15921 &no_neighbor_remove_private_as_replace_as_cmd);
15922 install_element(BGP_IPV6M_NODE,
15923 &neighbor_remove_private_as_all_replace_as_cmd);
15924 install_element(BGP_IPV6M_NODE,
15925 &no_neighbor_remove_private_as_all_replace_as_cmd);
15926 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15927 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
15928 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
15929 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
15930 install_element(BGP_IPV6L_NODE,
15931 &neighbor_remove_private_as_replace_as_cmd);
15932 install_element(BGP_IPV6L_NODE,
15933 &no_neighbor_remove_private_as_replace_as_cmd);
15934 install_element(BGP_IPV6L_NODE,
15935 &neighbor_remove_private_as_all_replace_as_cmd);
15936 install_element(BGP_IPV6L_NODE,
15937 &no_neighbor_remove_private_as_all_replace_as_cmd);
15938 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
15939 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
15940 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
15941 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15942 install_element(BGP_VPNV4_NODE,
15943 &neighbor_remove_private_as_replace_as_cmd);
15944 install_element(BGP_VPNV4_NODE,
15945 &no_neighbor_remove_private_as_replace_as_cmd);
15946 install_element(BGP_VPNV4_NODE,
15947 &neighbor_remove_private_as_all_replace_as_cmd);
15948 install_element(BGP_VPNV4_NODE,
15949 &no_neighbor_remove_private_as_all_replace_as_cmd);
15950 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
15951 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
15952 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
15953 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15954 install_element(BGP_VPNV6_NODE,
15955 &neighbor_remove_private_as_replace_as_cmd);
15956 install_element(BGP_VPNV6_NODE,
15957 &no_neighbor_remove_private_as_replace_as_cmd);
15958 install_element(BGP_VPNV6_NODE,
15959 &neighbor_remove_private_as_all_replace_as_cmd);
15960 install_element(BGP_VPNV6_NODE,
15961 &no_neighbor_remove_private_as_all_replace_as_cmd);
15962
15963 /* "neighbor send-community" commands.*/
15964 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
15965 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
15966 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
15967 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
15968 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
15969 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
15970 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
15971 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
15972 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
15973 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
15974 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
15975 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
15976 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
15977 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
15978 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
15979 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
15980 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
15981 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
15982 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
15983 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
15984 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
15985 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
15986 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
15987 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
15988 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
15989 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
15990 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
15991 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
15992 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
15993 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
15994 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
15995 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
15996 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
15997 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
15998 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
15999 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
16000
16001 /* "neighbor route-reflector" commands.*/
16002 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
16003 install_element(BGP_NODE,
16004 &no_neighbor_route_reflector_client_hidden_cmd);
16005 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
16006 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
16007 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
16008 install_element(BGP_IPV4M_NODE,
16009 &no_neighbor_route_reflector_client_cmd);
16010 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
16011 install_element(BGP_IPV4L_NODE,
16012 &no_neighbor_route_reflector_client_cmd);
16013 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
16014 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
16015 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16016 install_element(BGP_IPV6M_NODE,
16017 &no_neighbor_route_reflector_client_cmd);
16018 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16019 install_element(BGP_IPV6L_NODE,
16020 &no_neighbor_route_reflector_client_cmd);
16021 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16022 install_element(BGP_VPNV4_NODE,
16023 &no_neighbor_route_reflector_client_cmd);
16024 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16025 install_element(BGP_VPNV6_NODE,
16026 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16027 install_element(BGP_FLOWSPECV4_NODE,
16028 &neighbor_route_reflector_client_cmd);
16029 install_element(BGP_FLOWSPECV4_NODE,
16030 &no_neighbor_route_reflector_client_cmd);
16031 install_element(BGP_FLOWSPECV6_NODE,
16032 &neighbor_route_reflector_client_cmd);
16033 install_element(BGP_FLOWSPECV6_NODE,
16034 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16035 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16036 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16037
16038 /* "neighbor route-server" commands.*/
16039 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16040 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16041 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16042 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16043 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16044 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16045 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16046 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16047 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16048 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16049 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16050 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16051 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16052 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16053 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16054 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16055 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16056 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16057 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16058 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16059 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16060 install_element(BGP_FLOWSPECV4_NODE,
16061 &no_neighbor_route_server_client_cmd);
16062 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16063 install_element(BGP_FLOWSPECV6_NODE,
16064 &no_neighbor_route_server_client_cmd);
d62a17ae 16065
16066 /* "neighbor addpath-tx-all-paths" commands.*/
16067 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16068 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16069 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16070 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16071 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16072 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16073 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16074 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16075 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16076 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16077 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16078 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16079 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16080 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16081 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16082 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16083 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16084 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16085
16086 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16087 install_element(BGP_NODE,
16088 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16089 install_element(BGP_NODE,
16090 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16091 install_element(BGP_IPV4_NODE,
16092 &neighbor_addpath_tx_bestpath_per_as_cmd);
16093 install_element(BGP_IPV4_NODE,
16094 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16095 install_element(BGP_IPV4M_NODE,
16096 &neighbor_addpath_tx_bestpath_per_as_cmd);
16097 install_element(BGP_IPV4M_NODE,
16098 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16099 install_element(BGP_IPV4L_NODE,
16100 &neighbor_addpath_tx_bestpath_per_as_cmd);
16101 install_element(BGP_IPV4L_NODE,
16102 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16103 install_element(BGP_IPV6_NODE,
16104 &neighbor_addpath_tx_bestpath_per_as_cmd);
16105 install_element(BGP_IPV6_NODE,
16106 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16107 install_element(BGP_IPV6M_NODE,
16108 &neighbor_addpath_tx_bestpath_per_as_cmd);
16109 install_element(BGP_IPV6M_NODE,
16110 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16111 install_element(BGP_IPV6L_NODE,
16112 &neighbor_addpath_tx_bestpath_per_as_cmd);
16113 install_element(BGP_IPV6L_NODE,
16114 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16115 install_element(BGP_VPNV4_NODE,
16116 &neighbor_addpath_tx_bestpath_per_as_cmd);
16117 install_element(BGP_VPNV4_NODE,
16118 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16119 install_element(BGP_VPNV6_NODE,
16120 &neighbor_addpath_tx_bestpath_per_as_cmd);
16121 install_element(BGP_VPNV6_NODE,
16122 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16123
2b31007c
RZ
16124 /* "neighbor sender-as-path-loop-detection" commands. */
16125 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16126 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16127
d62a17ae 16128 /* "neighbor passive" commands. */
16129 install_element(BGP_NODE, &neighbor_passive_cmd);
16130 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16131
16132
16133 /* "neighbor shutdown" commands. */
16134 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16135 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16136 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16137 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16138
16139 /* "neighbor capability extended-nexthop" commands.*/
16140 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16141 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16142
16143 /* "neighbor capability orf prefix-list" commands.*/
16144 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16145 install_element(BGP_NODE,
16146 &no_neighbor_capability_orf_prefix_hidden_cmd);
16147 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16148 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16149 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16150 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16151 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16152 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16153 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16154 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16155 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16156 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16157 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16158 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16159
16160 /* "neighbor capability dynamic" commands.*/
16161 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16162 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16163
16164 /* "neighbor dont-capability-negotiate" commands. */
16165 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16166 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16167
16168 /* "neighbor ebgp-multihop" commands. */
16169 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16170 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16171 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16172
16173 /* "neighbor disable-connected-check" commands. */
16174 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16175 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16176
47cbc09b
PM
16177 /* "neighbor enforce-first-as" commands. */
16178 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16179 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16180
d62a17ae 16181 /* "neighbor description" commands. */
16182 install_element(BGP_NODE, &neighbor_description_cmd);
16183 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16184 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16185
16186 /* "neighbor update-source" commands. "*/
16187 install_element(BGP_NODE, &neighbor_update_source_cmd);
16188 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16189
16190 /* "neighbor default-originate" commands. */
16191 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16192 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16193 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16194 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16195 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16196 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16197 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16198 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16199 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16200 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16201 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16202 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16203 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16204 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16205 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16206 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16207 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16208 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16209 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16210 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16211 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16212
16213 /* "neighbor port" commands. */
16214 install_element(BGP_NODE, &neighbor_port_cmd);
16215 install_element(BGP_NODE, &no_neighbor_port_cmd);
16216
16217 /* "neighbor weight" commands. */
16218 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16219 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16220
16221 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16222 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16223 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16224 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16225 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16226 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16227 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16228 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16229 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16230 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16231 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16232 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16233 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16234 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16235 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16236 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16237
16238 /* "neighbor override-capability" commands. */
16239 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16240 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16241
16242 /* "neighbor strict-capability-match" commands. */
16243 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16244 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16245
16246 /* "neighbor timers" commands. */
16247 install_element(BGP_NODE, &neighbor_timers_cmd);
16248 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16249
16250 /* "neighbor timers connect" commands. */
16251 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16252 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16253
16254 /* "neighbor advertisement-interval" commands. */
16255 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16256 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16257
16258 /* "neighbor interface" commands. */
16259 install_element(BGP_NODE, &neighbor_interface_cmd);
16260 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16261
16262 /* "neighbor distribute" commands. */
16263 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16264 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16265 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16266 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16267 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16268 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16269 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16270 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16271 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16272 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16273 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16274 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16275 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16276 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16277 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16278 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16279 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16280 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16281
16282 /* "neighbor prefix-list" commands. */
16283 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16284 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16285 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16286 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16287 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16288 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16289 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16290 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16291 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16292 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16293 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16294 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16295 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16296 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16297 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16298 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16299 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16300 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16301 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16302 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16303 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16304 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16305
16306 /* "neighbor filter-list" commands. */
16307 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16308 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16309 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16310 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16311 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16312 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16313 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16314 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16315 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16316 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16317 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16318 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16319 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16320 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16321 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16322 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16323 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16324 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16325 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16326 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16327 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16328 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16329
16330 /* "neighbor route-map" commands. */
16331 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16332 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16333 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16334 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16335 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16336 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16337 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16338 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16339 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16340 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16341 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16342 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16343 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16344 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16345 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16346 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16347 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16348 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16349 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16350 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16351 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16352 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16353 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16354 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16355
16356 /* "neighbor unsuppress-map" commands. */
16357 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16358 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16359 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16360 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16361 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16362 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16363 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16364 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16365 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16366 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16367 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16368 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16369 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16370 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16371 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16372 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16373 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16374 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16375
fde246e8
DA
16376 /* neighbor maximum-prefix-out commands. */
16377 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16378 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16379 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16380 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16381 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16382 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16383 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16384 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16385 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16386 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16387 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16388 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16389 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16390 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16391 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16392 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16393 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16394 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16395
d62a17ae 16396 /* "neighbor maximum-prefix" commands. */
16397 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16398 install_element(BGP_NODE,
16399 &neighbor_maximum_prefix_threshold_hidden_cmd);
16400 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16401 install_element(BGP_NODE,
16402 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16403 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16404 install_element(BGP_NODE,
16405 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16406 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16407 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16408 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16409 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16410 install_element(BGP_IPV4_NODE,
16411 &neighbor_maximum_prefix_threshold_warning_cmd);
16412 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16413 install_element(BGP_IPV4_NODE,
16414 &neighbor_maximum_prefix_threshold_restart_cmd);
16415 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16416 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16417 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16418 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16419 install_element(BGP_IPV4M_NODE,
16420 &neighbor_maximum_prefix_threshold_warning_cmd);
16421 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16422 install_element(BGP_IPV4M_NODE,
16423 &neighbor_maximum_prefix_threshold_restart_cmd);
16424 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16425 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16426 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16427 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16428 install_element(BGP_IPV4L_NODE,
16429 &neighbor_maximum_prefix_threshold_warning_cmd);
16430 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16431 install_element(BGP_IPV4L_NODE,
16432 &neighbor_maximum_prefix_threshold_restart_cmd);
16433 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16434 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16435 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16436 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16437 install_element(BGP_IPV6_NODE,
16438 &neighbor_maximum_prefix_threshold_warning_cmd);
16439 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16440 install_element(BGP_IPV6_NODE,
16441 &neighbor_maximum_prefix_threshold_restart_cmd);
16442 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16443 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16444 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16445 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16446 install_element(BGP_IPV6M_NODE,
16447 &neighbor_maximum_prefix_threshold_warning_cmd);
16448 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16449 install_element(BGP_IPV6M_NODE,
16450 &neighbor_maximum_prefix_threshold_restart_cmd);
16451 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16452 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16453 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16454 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16455 install_element(BGP_IPV6L_NODE,
16456 &neighbor_maximum_prefix_threshold_warning_cmd);
16457 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16458 install_element(BGP_IPV6L_NODE,
16459 &neighbor_maximum_prefix_threshold_restart_cmd);
16460 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16461 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16462 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16463 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16464 install_element(BGP_VPNV4_NODE,
16465 &neighbor_maximum_prefix_threshold_warning_cmd);
16466 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16467 install_element(BGP_VPNV4_NODE,
16468 &neighbor_maximum_prefix_threshold_restart_cmd);
16469 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16470 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16471 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16472 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16473 install_element(BGP_VPNV6_NODE,
16474 &neighbor_maximum_prefix_threshold_warning_cmd);
16475 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16476 install_element(BGP_VPNV6_NODE,
16477 &neighbor_maximum_prefix_threshold_restart_cmd);
16478 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16479
16480 /* "neighbor allowas-in" */
16481 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16482 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16483 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16484 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16485 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16486 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16487 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16488 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16489 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16490 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16491 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16492 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16493 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16494 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16495 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16496 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16497 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16498 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16499 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16500 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16501
16502 /* address-family commands. */
16503 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16504 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16505#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16506 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16507 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16508#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16509
d62a17ae 16510 install_element(BGP_NODE, &address_family_evpn_cmd);
16511
16512 /* "exit-address-family" command. */
16513 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16514 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16515 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16516 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16517 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16518 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16519 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16520 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16521 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16522 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16523 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16524
16525 /* "clear ip bgp commands" */
16526 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16527
16528 /* clear ip bgp prefix */
16529 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16530 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16531 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16532
16533 /* "show [ip] bgp summary" commands. */
16534 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16535 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16536 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16537 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16538 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16539 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16540 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16541
16542 /* "show [ip] bgp neighbors" commands. */
16543 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16544
2986cac2 16545 install_element(VIEW_NODE,
16546 &show_ip_bgp_neighbors_graceful_restart_cmd);
16547
d62a17ae 16548 /* "show [ip] bgp peer-group" commands. */
16549 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16550
16551 /* "show [ip] bgp paths" commands. */
16552 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16553
16554 /* "show [ip] bgp community" commands. */
16555 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16556
16557 /* "show ip bgp large-community" commands. */
16558 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16559 /* "show [ip] bgp attribute-info" commands. */
16560 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16561 /* "show [ip] bgp route-leak" command */
16562 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16563
16564 /* "redistribute" commands. */
16565 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16566 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16567 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16568 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16569 install_element(BGP_NODE,
16570 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16571 install_element(BGP_NODE,
16572 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16573 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16574 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16575 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16576 install_element(BGP_NODE,
16577 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16578 install_element(BGP_NODE,
16579 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16580 install_element(BGP_NODE,
16581 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16582 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16583 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16584 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16585 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16586 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16587 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16588 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16589 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16590 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16591 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16592 install_element(BGP_IPV4_NODE,
16593 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16594 install_element(BGP_IPV4_NODE,
16595 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16596 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16597 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16598 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16599 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16600 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16601 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16602
b9c7bc5a
PZ
16603 /* import|export vpn [route-map WORD] */
16604 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16605 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 16606
12a844a5
DS
16607 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16608 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16609
d62a17ae 16610 /* ttl_security commands */
16611 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16612 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16613
16614 /* "show [ip] bgp memory" commands. */
16615 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16616
acf71666
MK
16617 /* "show bgp martian next-hop" */
16618 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16619
48ecf8f5
DS
16620 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16621
d62a17ae 16622 /* "show [ip] bgp views" commands. */
16623 install_element(VIEW_NODE, &show_bgp_views_cmd);
16624
16625 /* "show [ip] bgp vrfs" commands. */
16626 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16627
16628 /* Community-list. */
16629 community_list_vty();
ddb5b488
PZ
16630
16631 /* vpn-policy commands */
b9c7bc5a
PZ
16632 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16633 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16634 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16635 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16636 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16637 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16638 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16639 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16640 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16641 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
16642 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16643 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 16644
301ad80a
PG
16645 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16646 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16647
b9c7bc5a
PZ
16648 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16649 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16650 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16651 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
16652 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
16653 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
16654 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16655 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16656 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16657 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
16658 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16659 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 16660}
6b0655a2 16661
718e3744 16662#include "memory.h"
16663#include "bgp_regex.h"
16664#include "bgp_clist.h"
16665#include "bgp_ecommunity.h"
16666
16667/* VTY functions. */
16668
16669/* Direction value to string conversion. */
d62a17ae 16670static const char *community_direct_str(int direct)
16671{
16672 switch (direct) {
16673 case COMMUNITY_DENY:
16674 return "deny";
16675 case COMMUNITY_PERMIT:
16676 return "permit";
16677 default:
16678 return "unknown";
16679 }
718e3744 16680}
16681
16682/* Display error string. */
d62a17ae 16683static void community_list_perror(struct vty *vty, int ret)
16684{
16685 switch (ret) {
16686 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16687 vty_out(vty, "%% Can't find community-list\n");
16688 break;
16689 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16690 vty_out(vty, "%% Malformed community-list value\n");
16691 break;
16692 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16693 vty_out(vty,
16694 "%% Community name conflict, previously defined as standard community\n");
16695 break;
16696 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16697 vty_out(vty,
16698 "%% Community name conflict, previously defined as expanded community\n");
16699 break;
16700 }
718e3744 16701}
16702
5bf15956
DW
16703/* "community-list" keyword help string. */
16704#define COMMUNITY_LIST_STR "Add a community list entry\n"
16705
7336e101
SP
16706/*community-list standard */
16707DEFUN (community_list_standard,
16708 bgp_community_list_standard_cmd,
2f8cc0e5 16709 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 16710 BGP_STR
718e3744 16711 COMMUNITY_LIST_STR
16712 "Community list number (standard)\n"
5bf15956 16713 "Add an standard community-list entry\n"
718e3744 16714 "Community list name\n"
2f8cc0e5
DA
16715 "Sequence number of an entry\n"
16716 "Sequence number\n"
718e3744 16717 "Specify community to reject\n"
16718 "Specify community to accept\n"
16719 COMMUNITY_VAL_STR)
16720{
d62a17ae 16721 char *cl_name_or_number = NULL;
2f8cc0e5 16722 char *seq = NULL;
d62a17ae 16723 int direct = 0;
16724 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 16725 int idx = 0;
7336e101 16726
2f8cc0e5
DA
16727 argv_find(argv, argc, "(1-4294967295)", &idx);
16728 if (idx)
16729 seq = argv[idx]->arg;
16730
16731 idx = 0;
d62a17ae 16732 argv_find(argv, argc, "(1-99)", &idx);
16733 argv_find(argv, argc, "WORD", &idx);
16734 cl_name_or_number = argv[idx]->arg;
16735 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16736 : COMMUNITY_DENY;
16737 argv_find(argv, argc, "AA:NN", &idx);
16738 char *str = argv_concat(argv, argc, idx);
42f914d4 16739
2f8cc0e5
DA
16740 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16741 direct, style);
42f914d4 16742
d62a17ae 16743 XFREE(MTYPE_TMP, str);
42f914d4 16744
d62a17ae 16745 if (ret < 0) {
16746 /* Display error string. */
16747 community_list_perror(vty, ret);
16748 return CMD_WARNING_CONFIG_FAILED;
16749 }
42f914d4 16750
d62a17ae 16751 return CMD_SUCCESS;
718e3744 16752}
16753
7336e101
SP
16754DEFUN (no_community_list_standard_all,
16755 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 16756 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16757 NO_STR
16758 BGP_STR
16759 COMMUNITY_LIST_STR
16760 "Community list number (standard)\n"
16761 "Add an standard community-list entry\n"
16762 "Community list name\n"
2f8cc0e5
DA
16763 "Sequence number of an entry\n"
16764 "Sequence number\n"
7336e101
SP
16765 "Specify community to reject\n"
16766 "Specify community to accept\n"
16767 COMMUNITY_VAL_STR)
718e3744 16768{
d62a17ae 16769 char *cl_name_or_number = NULL;
174b5cb9 16770 char *str = NULL;
d62a17ae 16771 int direct = 0;
16772 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 16773 char *seq = NULL;
d62a17ae 16774 int idx = 0;
7336e101 16775
2f8cc0e5
DA
16776 argv_find(argv, argc, "(1-4294967295)", &idx);
16777 if (idx)
16778 seq = argv[idx]->arg;
16779
16780 idx = 0;
174b5cb9
DA
16781 argv_find(argv, argc, "permit", &idx);
16782 argv_find(argv, argc, "deny", &idx);
16783
16784 if (idx) {
16785 direct = argv_find(argv, argc, "permit", &idx)
16786 ? COMMUNITY_PERMIT
16787 : COMMUNITY_DENY;
16788
16789 idx = 0;
16790 argv_find(argv, argc, "AA:NN", &idx);
16791 str = argv_concat(argv, argc, idx);
16792 }
16793
16794 idx = 0;
d62a17ae 16795 argv_find(argv, argc, "(1-99)", &idx);
16796 argv_find(argv, argc, "WORD", &idx);
16797 cl_name_or_number = argv[idx]->arg;
42f914d4 16798
2f8cc0e5 16799 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16800 direct, style);
42f914d4 16801
d62a17ae 16802 XFREE(MTYPE_TMP, str);
daf9ddbb 16803
d62a17ae 16804 if (ret < 0) {
16805 community_list_perror(vty, ret);
16806 return CMD_WARNING_CONFIG_FAILED;
16807 }
42f914d4 16808
d62a17ae 16809 return CMD_SUCCESS;
718e3744 16810}
7336e101 16811
174b5cb9
DA
16812ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16813 "no bgp community-list <(1-99)|standard WORD>",
16814 NO_STR BGP_STR COMMUNITY_LIST_STR
16815 "Community list number (standard)\n"
16816 "Add an standard community-list entry\n"
16817 "Community list name\n")
16818
7336e101
SP
16819/*community-list expanded */
16820DEFUN (community_list_expanded_all,
16821 bgp_community_list_expanded_all_cmd,
2f8cc0e5 16822 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16823 BGP_STR
16824 COMMUNITY_LIST_STR
718e3744 16825 "Community list number (expanded)\n"
5bf15956 16826 "Add an expanded community-list entry\n"
718e3744 16827 "Community list name\n"
2f8cc0e5
DA
16828 "Sequence number of an entry\n"
16829 "Sequence number\n"
718e3744 16830 "Specify community to reject\n"
16831 "Specify community to accept\n"
16832 COMMUNITY_VAL_STR)
16833{
d62a17ae 16834 char *cl_name_or_number = NULL;
2f8cc0e5 16835 char *seq = NULL;
d62a17ae 16836 int direct = 0;
16837 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16838 int idx = 0;
7b9a4750 16839
2f8cc0e5
DA
16840 argv_find(argv, argc, "(1-4294967295)", &idx);
16841 if (idx)
16842 seq = argv[idx]->arg;
16843
16844 idx = 0;
16845
d62a17ae 16846 argv_find(argv, argc, "(100-500)", &idx);
16847 argv_find(argv, argc, "WORD", &idx);
16848 cl_name_or_number = argv[idx]->arg;
16849 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16850 : COMMUNITY_DENY;
16851 argv_find(argv, argc, "AA:NN", &idx);
16852 char *str = argv_concat(argv, argc, idx);
42f914d4 16853
2f8cc0e5
DA
16854 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16855 direct, style);
42f914d4 16856
d62a17ae 16857 XFREE(MTYPE_TMP, str);
42f914d4 16858
d62a17ae 16859 if (ret < 0) {
16860 /* Display error string. */
16861 community_list_perror(vty, ret);
16862 return CMD_WARNING_CONFIG_FAILED;
16863 }
42f914d4 16864
d62a17ae 16865 return CMD_SUCCESS;
718e3744 16866}
16867
7336e101
SP
16868DEFUN (no_community_list_expanded_all,
16869 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 16870 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16871 NO_STR
16872 BGP_STR
16873 COMMUNITY_LIST_STR
16874 "Community list number (expanded)\n"
16875 "Add an expanded community-list entry\n"
16876 "Community list name\n"
2f8cc0e5
DA
16877 "Sequence number of an entry\n"
16878 "Sequence number\n"
7336e101
SP
16879 "Specify community to reject\n"
16880 "Specify community to accept\n"
16881 COMMUNITY_VAL_STR)
718e3744 16882{
d62a17ae 16883 char *cl_name_or_number = NULL;
2f8cc0e5 16884 char *seq = NULL;
174b5cb9 16885 char *str = NULL;
d62a17ae 16886 int direct = 0;
16887 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16888 int idx = 0;
174b5cb9 16889
2f8cc0e5
DA
16890 argv_find(argv, argc, "(1-4294967295)", &idx);
16891 if (idx)
16892 seq = argv[idx]->arg;
16893
16894 idx = 0;
174b5cb9
DA
16895 argv_find(argv, argc, "permit", &idx);
16896 argv_find(argv, argc, "deny", &idx);
16897
16898 if (idx) {
16899 direct = argv_find(argv, argc, "permit", &idx)
16900 ? COMMUNITY_PERMIT
16901 : COMMUNITY_DENY;
16902
16903 idx = 0;
16904 argv_find(argv, argc, "AA:NN", &idx);
16905 str = argv_concat(argv, argc, idx);
7336e101 16906 }
174b5cb9
DA
16907
16908 idx = 0;
d62a17ae 16909 argv_find(argv, argc, "(100-500)", &idx);
16910 argv_find(argv, argc, "WORD", &idx);
16911 cl_name_or_number = argv[idx]->arg;
42f914d4 16912
2f8cc0e5 16913 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16914 direct, style);
42f914d4 16915
d62a17ae 16916 XFREE(MTYPE_TMP, str);
daf9ddbb 16917
d62a17ae 16918 if (ret < 0) {
16919 community_list_perror(vty, ret);
16920 return CMD_WARNING_CONFIG_FAILED;
16921 }
42f914d4 16922
d62a17ae 16923 return CMD_SUCCESS;
718e3744 16924}
16925
174b5cb9
DA
16926ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16927 "no bgp community-list <(100-500)|expanded WORD>",
16928 NO_STR IP_STR COMMUNITY_LIST_STR
16929 "Community list number (expanded)\n"
16930 "Add an expanded community-list entry\n"
16931 "Community list name\n")
16932
8d9b8ed9
PM
16933/* Return configuration string of community-list entry. */
16934static const char *community_list_config_str(struct community_entry *entry)
16935{
16936 const char *str;
16937
16938 if (entry->any)
16939 str = "";
16940 else {
16941 if (entry->style == COMMUNITY_LIST_STANDARD)
16942 str = community_str(entry->u.com, false);
16943 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
16944 str = lcommunity_str(entry->u.lcom, false);
16945 else
16946 str = entry->config;
16947 }
16948 return str;
16949}
16950
d62a17ae 16951static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 16952{
d62a17ae 16953 struct community_entry *entry;
718e3744 16954
d62a17ae 16955 for (entry = list->head; entry; entry = entry->next) {
16956 if (entry == list->head) {
16957 if (all_digit(list->name))
16958 vty_out(vty, "Community %s list %s\n",
16959 entry->style == COMMUNITY_LIST_STANDARD
16960 ? "standard"
16961 : "(expanded) access",
16962 list->name);
16963 else
16964 vty_out(vty, "Named Community %s list %s\n",
16965 entry->style == COMMUNITY_LIST_STANDARD
16966 ? "standard"
16967 : "expanded",
16968 list->name);
16969 }
16970 if (entry->any)
16971 vty_out(vty, " %s\n",
16972 community_direct_str(entry->direct));
16973 else
16974 vty_out(vty, " %s %s\n",
16975 community_direct_str(entry->direct),
8d9b8ed9 16976 community_list_config_str(entry));
d62a17ae 16977 }
718e3744 16978}
16979
7336e101
SP
16980DEFUN (show_community_list,
16981 show_bgp_community_list_cmd,
16982 "show bgp community-list",
718e3744 16983 SHOW_STR
7336e101 16984 BGP_STR
718e3744 16985 "List community-list\n")
16986{
d62a17ae 16987 struct community_list *list;
16988 struct community_list_master *cm;
718e3744 16989
d62a17ae 16990 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16991 if (!cm)
16992 return CMD_SUCCESS;
718e3744 16993
d62a17ae 16994 for (list = cm->num.head; list; list = list->next)
16995 community_list_show(vty, list);
718e3744 16996
d62a17ae 16997 for (list = cm->str.head; list; list = list->next)
16998 community_list_show(vty, list);
718e3744 16999
d62a17ae 17000 return CMD_SUCCESS;
718e3744 17001}
17002
7336e101
SP
17003DEFUN (show_community_list_arg,
17004 show_bgp_community_list_arg_cmd,
960b69b9 17005 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
17006 SHOW_STR
17007 BGP_STR
718e3744 17008 "List community-list\n"
17009 "Community-list number\n"
960b69b9 17010 "Community-list name\n"
17011 "Detailed information on community-list\n")
718e3744 17012{
d62a17ae 17013 int idx_comm_list = 3;
17014 struct community_list *list;
718e3744 17015
e237b0d2 17016 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17017 COMMUNITY_LIST_MASTER);
17018 if (!list) {
17019 vty_out(vty, "%% Can't find community-list\n");
17020 return CMD_WARNING;
17021 }
718e3744 17022
d62a17ae 17023 community_list_show(vty, list);
718e3744 17024
d62a17ae 17025 return CMD_SUCCESS;
718e3744 17026}
6b0655a2 17027
57d187bc
JS
17028/*
17029 * Large Community code.
17030 */
d62a17ae 17031static int lcommunity_list_set_vty(struct vty *vty, int argc,
17032 struct cmd_token **argv, int style,
17033 int reject_all_digit_name)
17034{
17035 int ret;
17036 int direct;
17037 char *str;
17038 int idx = 0;
17039 char *cl_name;
2f8cc0e5
DA
17040 char *seq = NULL;
17041
17042 argv_find(argv, argc, "(1-4294967295)", &idx);
17043 if (idx)
17044 seq = argv[idx]->arg;
d62a17ae 17045
2f8cc0e5 17046 idx = 0;
d62a17ae 17047 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17048 : COMMUNITY_DENY;
17049
17050 /* All digit name check. */
17051 idx = 0;
17052 argv_find(argv, argc, "WORD", &idx);
17053 argv_find(argv, argc, "(1-99)", &idx);
17054 argv_find(argv, argc, "(100-500)", &idx);
17055 cl_name = argv[idx]->arg;
17056 if (reject_all_digit_name && all_digit(cl_name)) {
17057 vty_out(vty, "%% Community name cannot have all digits\n");
17058 return CMD_WARNING_CONFIG_FAILED;
17059 }
17060
17061 idx = 0;
17062 argv_find(argv, argc, "AA:BB:CC", &idx);
17063 argv_find(argv, argc, "LINE", &idx);
17064 /* Concat community string argument. */
17065 if (idx)
17066 str = argv_concat(argv, argc, idx);
17067 else
17068 str = NULL;
17069
2f8cc0e5 17070 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17071
17072 /* Free temporary community list string allocated by
17073 argv_concat(). */
0a22ddfb 17074 XFREE(MTYPE_TMP, str);
d62a17ae 17075
17076 if (ret < 0) {
17077 community_list_perror(vty, ret);
17078 return CMD_WARNING_CONFIG_FAILED;
17079 }
17080 return CMD_SUCCESS;
17081}
17082
17083static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17084 struct cmd_token **argv, int style)
17085{
17086 int ret;
17087 int direct = 0;
17088 char *str = NULL;
17089 int idx = 0;
2f8cc0e5 17090 char *seq = NULL;
d62a17ae 17091
2f8cc0e5
DA
17092 argv_find(argv, argc, "(1-4294967295)", &idx);
17093 if (idx)
17094 seq = argv[idx]->arg;
d62a17ae 17095
2f8cc0e5 17096 idx = 0;
d62a17ae 17097 argv_find(argv, argc, "permit", &idx);
17098 argv_find(argv, argc, "deny", &idx);
17099
17100 if (idx) {
17101 /* Check the list direct. */
17102 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17103 direct = COMMUNITY_PERMIT;
17104 else
17105 direct = COMMUNITY_DENY;
17106
17107 idx = 0;
17108 argv_find(argv, argc, "LINE", &idx);
17109 argv_find(argv, argc, "AA:AA:NN", &idx);
17110 /* Concat community string argument. */
17111 str = argv_concat(argv, argc, idx);
17112 }
17113
17114 idx = 0;
17115 argv_find(argv, argc, "(1-99)", &idx);
17116 argv_find(argv, argc, "(100-500)", &idx);
17117 argv_find(argv, argc, "WORD", &idx);
17118
17119 /* Unset community list. */
2f8cc0e5 17120 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17121 style);
17122
17123 /* Free temporary community list string allocated by
17124 argv_concat(). */
0a22ddfb 17125 XFREE(MTYPE_TMP, str);
d62a17ae 17126
17127 if (ret < 0) {
17128 community_list_perror(vty, ret);
17129 return CMD_WARNING_CONFIG_FAILED;
17130 }
17131
17132 return CMD_SUCCESS;
57d187bc
JS
17133}
17134
17135/* "large-community-list" keyword help string. */
17136#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17137#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17138
7336e101
SP
17139DEFUN (lcommunity_list_standard,
17140 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17141 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17142 BGP_STR
17143 LCOMMUNITY_LIST_STR
17144 "Large Community list number (standard)\n"
2f8cc0e5
DA
17145 "Sequence number of an entry\n"
17146 "Sequence number\n"
7336e101
SP
17147 "Specify large community to reject\n"
17148 "Specify large community to accept\n"
17149 LCOMMUNITY_VAL_STR)
52951b63 17150{
d62a17ae 17151 return lcommunity_list_set_vty(vty, argc, argv,
17152 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17153}
17154
7336e101
SP
17155DEFUN (lcommunity_list_expanded,
17156 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17157 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17158 BGP_STR
17159 LCOMMUNITY_LIST_STR
17160 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17161 "Sequence number of an entry\n"
17162 "Sequence number\n"
7336e101
SP
17163 "Specify large community to reject\n"
17164 "Specify large community to accept\n"
17165 "An ordered list as a regular-expression\n")
57d187bc 17166{
d62a17ae 17167 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17168 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17169}
17170
7336e101
SP
17171DEFUN (lcommunity_list_name_standard,
17172 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17173 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17174 BGP_STR
17175 LCOMMUNITY_LIST_STR
17176 "Specify standard large-community-list\n"
17177 "Large Community list name\n"
2f8cc0e5
DA
17178 "Sequence number of an entry\n"
17179 "Sequence number\n"
7336e101
SP
17180 "Specify large community to reject\n"
17181 "Specify large community to accept\n"
17182 LCOMMUNITY_VAL_STR)
52951b63 17183{
d62a17ae 17184 return lcommunity_list_set_vty(vty, argc, argv,
17185 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17186}
17187
7336e101
SP
17188DEFUN (lcommunity_list_name_expanded,
17189 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17190 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17191 BGP_STR
17192 LCOMMUNITY_LIST_STR
17193 "Specify expanded large-community-list\n"
17194 "Large Community list name\n"
2f8cc0e5
DA
17195 "Sequence number of an entry\n"
17196 "Sequence number\n"
7336e101
SP
17197 "Specify large community to reject\n"
17198 "Specify large community to accept\n"
17199 "An ordered list as a regular-expression\n")
57d187bc 17200{
d62a17ae 17201 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17202 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17203}
17204
4378f57c
DA
17205DEFUN (no_lcommunity_list_all,
17206 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17207 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17208 NO_STR
17209 BGP_STR
17210 LCOMMUNITY_LIST_STR
17211 "Large Community list number (standard)\n"
17212 "Large Community list number (expanded)\n"
17213 "Large Community list name\n")
57d187bc 17214{
7336e101
SP
17215 return lcommunity_list_unset_vty(vty, argc, argv,
17216 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17217}
17218
4378f57c
DA
17219DEFUN (no_lcommunity_list_name_standard_all,
17220 no_bgp_lcommunity_list_name_standard_all_cmd,
17221 "no bgp large-community-list standard WORD",
17222 NO_STR
17223 BGP_STR
17224 LCOMMUNITY_LIST_STR
17225 "Specify standard large-community-list\n"
17226 "Large Community list name\n")
17227{
17228 return lcommunity_list_unset_vty(vty, argc, argv,
17229 LARGE_COMMUNITY_LIST_STANDARD);
17230}
17231
7336e101
SP
17232DEFUN (no_lcommunity_list_name_expanded_all,
17233 no_bgp_lcommunity_list_name_expanded_all_cmd,
17234 "no bgp large-community-list expanded WORD",
17235 NO_STR
17236 BGP_STR
17237 LCOMMUNITY_LIST_STR
17238 "Specify expanded large-community-list\n"
17239 "Large Community list name\n")
57d187bc 17240{
d62a17ae 17241 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17242 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17243}
17244
7336e101
SP
17245DEFUN (no_lcommunity_list_standard,
17246 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17247 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17248 NO_STR
17249 BGP_STR
17250 LCOMMUNITY_LIST_STR
17251 "Large Community list number (standard)\n"
2f8cc0e5
DA
17252 "Sequence number of an entry\n"
17253 "Sequence number\n"
7336e101
SP
17254 "Specify large community to reject\n"
17255 "Specify large community to accept\n"
17256 LCOMMUNITY_VAL_STR)
57d187bc 17257{
d62a17ae 17258 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17259 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17260}
17261
7336e101
SP
17262DEFUN (no_lcommunity_list_expanded,
17263 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17264 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17265 NO_STR
17266 BGP_STR
17267 LCOMMUNITY_LIST_STR
17268 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17269 "Sequence number of an entry\n"
17270 "Sequence number\n"
7336e101
SP
17271 "Specify large community to reject\n"
17272 "Specify large community to accept\n"
17273 "An ordered list as a regular-expression\n")
57d187bc 17274{
d62a17ae 17275 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17276 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17277}
17278
7336e101
SP
17279DEFUN (no_lcommunity_list_name_standard,
17280 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17281 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17282 NO_STR
17283 BGP_STR
17284 LCOMMUNITY_LIST_STR
17285 "Specify standard large-community-list\n"
17286 "Large Community list name\n"
2f8cc0e5
DA
17287 "Sequence number of an entry\n"
17288 "Sequence number\n"
7336e101
SP
17289 "Specify large community to reject\n"
17290 "Specify large community to accept\n"
17291 LCOMMUNITY_VAL_STR)
57d187bc 17292{
d62a17ae 17293 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17294 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17295}
17296
7336e101
SP
17297DEFUN (no_lcommunity_list_name_expanded,
17298 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17299 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17300 NO_STR
17301 BGP_STR
17302 LCOMMUNITY_LIST_STR
17303 "Specify expanded large-community-list\n"
17304 "Large community list name\n"
2f8cc0e5
DA
17305 "Sequence number of an entry\n"
17306 "Sequence number\n"
7336e101
SP
17307 "Specify large community to reject\n"
17308 "Specify large community to accept\n"
17309 "An ordered list as a regular-expression\n")
57d187bc 17310{
d62a17ae 17311 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17312 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17313}
17314
d62a17ae 17315static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17316{
17317 struct community_entry *entry;
17318
17319 for (entry = list->head; entry; entry = entry->next) {
17320 if (entry == list->head) {
17321 if (all_digit(list->name))
17322 vty_out(vty, "Large community %s list %s\n",
169b72c8 17323 entry->style ==
17324 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17325 ? "standard"
17326 : "(expanded) access",
17327 list->name);
17328 else
17329 vty_out(vty,
17330 "Named large community %s list %s\n",
169b72c8 17331 entry->style ==
17332 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17333 ? "standard"
17334 : "expanded",
17335 list->name);
17336 }
17337 if (entry->any)
17338 vty_out(vty, " %s\n",
17339 community_direct_str(entry->direct));
17340 else
17341 vty_out(vty, " %s %s\n",
17342 community_direct_str(entry->direct),
8d9b8ed9 17343 community_list_config_str(entry));
d62a17ae 17344 }
57d187bc
JS
17345}
17346
7336e101
SP
17347DEFUN (show_lcommunity_list,
17348 show_bgp_lcommunity_list_cmd,
17349 "show bgp large-community-list",
57d187bc 17350 SHOW_STR
7336e101 17351 BGP_STR
57d187bc
JS
17352 "List large-community list\n")
17353{
d62a17ae 17354 struct community_list *list;
17355 struct community_list_master *cm;
57d187bc 17356
d62a17ae 17357 cm = community_list_master_lookup(bgp_clist,
17358 LARGE_COMMUNITY_LIST_MASTER);
17359 if (!cm)
17360 return CMD_SUCCESS;
57d187bc 17361
d62a17ae 17362 for (list = cm->num.head; list; list = list->next)
17363 lcommunity_list_show(vty, list);
57d187bc 17364
d62a17ae 17365 for (list = cm->str.head; list; list = list->next)
17366 lcommunity_list_show(vty, list);
57d187bc 17367
d62a17ae 17368 return CMD_SUCCESS;
57d187bc
JS
17369}
17370
7336e101
SP
17371DEFUN (show_lcommunity_list_arg,
17372 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17373 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17374 SHOW_STR
17375 BGP_STR
57d187bc 17376 "List large-community list\n"
960b69b9 17377 "Large-community-list number\n"
17378 "Large-community-list name\n"
17379 "Detailed information on large-community-list\n")
57d187bc 17380{
d62a17ae 17381 struct community_list *list;
57d187bc 17382
e237b0d2 17383 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17384 LARGE_COMMUNITY_LIST_MASTER);
17385 if (!list) {
960b69b9 17386 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17387 return CMD_WARNING;
17388 }
57d187bc 17389
d62a17ae 17390 lcommunity_list_show(vty, list);
57d187bc 17391
d62a17ae 17392 return CMD_SUCCESS;
57d187bc
JS
17393}
17394
718e3744 17395/* "extcommunity-list" keyword help string. */
17396#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17397#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17398
7336e101
SP
17399DEFUN (extcommunity_list_standard,
17400 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 17401 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17402 BGP_STR
718e3744 17403 EXTCOMMUNITY_LIST_STR
17404 "Extended Community list number (standard)\n"
718e3744 17405 "Specify standard extcommunity-list\n"
5bf15956 17406 "Community list name\n"
2f8cc0e5
DA
17407 "Sequence number of an entry\n"
17408 "Sequence number\n"
718e3744 17409 "Specify community to reject\n"
17410 "Specify community to accept\n"
17411 EXTCOMMUNITY_VAL_STR)
17412{
d62a17ae 17413 int style = EXTCOMMUNITY_LIST_STANDARD;
17414 int direct = 0;
17415 char *cl_number_or_name = NULL;
2f8cc0e5 17416 char *seq = NULL;
42f914d4 17417
d62a17ae 17418 int idx = 0;
7b9a4750 17419
d62a17ae 17420 argv_find(argv, argc, "(1-99)", &idx);
17421 argv_find(argv, argc, "WORD", &idx);
17422 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17423
17424 argv_find(argv, argc, "(1-4294967295)", &idx);
17425 if (idx)
17426 seq = argv[idx]->arg;
17427
d62a17ae 17428 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17429 : COMMUNITY_DENY;
17430 argv_find(argv, argc, "AA:NN", &idx);
17431 char *str = argv_concat(argv, argc, idx);
42f914d4 17432
2f8cc0e5 17433 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17434 direct, style);
42f914d4 17435
d62a17ae 17436 XFREE(MTYPE_TMP, str);
42f914d4 17437
d62a17ae 17438 if (ret < 0) {
17439 community_list_perror(vty, ret);
17440 return CMD_WARNING_CONFIG_FAILED;
17441 }
42f914d4 17442
d62a17ae 17443 return CMD_SUCCESS;
718e3744 17444}
17445
7336e101
SP
17446DEFUN (extcommunity_list_name_expanded,
17447 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 17448 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17449 BGP_STR
17450 EXTCOMMUNITY_LIST_STR
5bf15956 17451 "Extended Community list number (expanded)\n"
718e3744 17452 "Specify expanded extcommunity-list\n"
17453 "Extended Community list name\n"
2f8cc0e5
DA
17454 "Sequence number of an entry\n"
17455 "Sequence number\n"
718e3744 17456 "Specify community to reject\n"
17457 "Specify community to accept\n"
17458 "An ordered list as a regular-expression\n")
17459{
d62a17ae 17460 int style = EXTCOMMUNITY_LIST_EXPANDED;
17461 int direct = 0;
17462 char *cl_number_or_name = NULL;
2f8cc0e5 17463 char *seq = NULL;
d62a17ae 17464 int idx = 0;
7336e101 17465
d62a17ae 17466 argv_find(argv, argc, "(100-500)", &idx);
17467 argv_find(argv, argc, "WORD", &idx);
17468 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17469
17470 argv_find(argv, argc, "(1-4294967295)", &idx);
17471 if (idx)
17472 seq = argv[idx]->arg;
17473
d62a17ae 17474 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17475 : COMMUNITY_DENY;
17476 argv_find(argv, argc, "LINE", &idx);
17477 char *str = argv_concat(argv, argc, idx);
42f914d4 17478
2f8cc0e5 17479 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17480 direct, style);
42f914d4 17481
d62a17ae 17482 XFREE(MTYPE_TMP, str);
42f914d4 17483
d62a17ae 17484 if (ret < 0) {
17485 community_list_perror(vty, ret);
17486 return CMD_WARNING_CONFIG_FAILED;
17487 }
42f914d4 17488
d62a17ae 17489 return CMD_SUCCESS;
718e3744 17490}
17491
7336e101
SP
17492DEFUN (no_extcommunity_list_standard_all,
17493 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 17494 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17495 NO_STR
17496 BGP_STR
17497 EXTCOMMUNITY_LIST_STR
813d4307 17498 "Extended Community list number (standard)\n"
718e3744 17499 "Specify standard extcommunity-list\n"
5bf15956 17500 "Community list name\n"
2f8cc0e5
DA
17501 "Sequence number of an entry\n"
17502 "Sequence number\n"
718e3744 17503 "Specify community to reject\n"
17504 "Specify community to accept\n"
17505 EXTCOMMUNITY_VAL_STR)
17506{
d62a17ae 17507 int style = EXTCOMMUNITY_LIST_STANDARD;
17508 int direct = 0;
17509 char *cl_number_or_name = NULL;
d4455c89 17510 char *str = NULL;
2f8cc0e5 17511 char *seq = NULL;
d62a17ae 17512 int idx = 0;
d4455c89 17513
2f8cc0e5
DA
17514 argv_find(argv, argc, "(1-4294967295)", &idx);
17515 if (idx)
17516 seq = argv[idx]->arg;
17517
17518 idx = 0;
d4455c89
DA
17519 argv_find(argv, argc, "permit", &idx);
17520 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
17521 if (idx) {
17522 direct = argv_find(argv, argc, "permit", &idx)
17523 ? COMMUNITY_PERMIT
17524 : COMMUNITY_DENY;
17525
17526 idx = 0;
17527 argv_find(argv, argc, "AA:NN", &idx);
17528 str = argv_concat(argv, argc, idx);
17529 }
17530
17531 idx = 0;
d62a17ae 17532 argv_find(argv, argc, "(1-99)", &idx);
17533 argv_find(argv, argc, "WORD", &idx);
17534 cl_number_or_name = argv[idx]->arg;
42f914d4 17535
d62a17ae 17536 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17537 seq, direct, style);
42f914d4 17538
d62a17ae 17539 XFREE(MTYPE_TMP, str);
42f914d4 17540
d62a17ae 17541 if (ret < 0) {
17542 community_list_perror(vty, ret);
17543 return CMD_WARNING_CONFIG_FAILED;
17544 }
42f914d4 17545
d62a17ae 17546 return CMD_SUCCESS;
718e3744 17547}
17548
d4455c89
DA
17549ALIAS(no_extcommunity_list_standard_all,
17550 no_bgp_extcommunity_list_standard_all_list_cmd,
17551 "no bgp extcommunity-list <(1-99)|standard WORD>",
17552 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17553 "Extended Community list number (standard)\n"
17554 "Specify standard extcommunity-list\n"
17555 "Community list name\n")
17556
7336e101
SP
17557DEFUN (no_extcommunity_list_expanded_all,
17558 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 17559 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17560 NO_STR
17561 BGP_STR
17562 EXTCOMMUNITY_LIST_STR
718e3744 17563 "Extended Community list number (expanded)\n"
718e3744 17564 "Specify expanded extcommunity-list\n"
5bf15956 17565 "Extended Community list name\n"
2f8cc0e5
DA
17566 "Sequence number of an entry\n"
17567 "Sequence number\n"
718e3744 17568 "Specify community to reject\n"
17569 "Specify community to accept\n"
17570 "An ordered list as a regular-expression\n")
17571{
d62a17ae 17572 int style = EXTCOMMUNITY_LIST_EXPANDED;
17573 int direct = 0;
17574 char *cl_number_or_name = NULL;
d4455c89 17575 char *str = NULL;
2f8cc0e5 17576 char *seq = NULL;
d62a17ae 17577 int idx = 0;
d4455c89 17578
2f8cc0e5
DA
17579 argv_find(argv, argc, "(1-4294967295)", &idx);
17580 if (idx)
17581 seq = argv[idx]->arg;
17582
17583 idx = 0;
d4455c89
DA
17584 argv_find(argv, argc, "permit", &idx);
17585 argv_find(argv, argc, "deny", &idx);
17586
17587 if (idx) {
17588 direct = argv_find(argv, argc, "permit", &idx)
17589 ? COMMUNITY_PERMIT
17590 : COMMUNITY_DENY;
17591
17592 idx = 0;
17593 argv_find(argv, argc, "LINE", &idx);
17594 str = argv_concat(argv, argc, idx);
17595 }
17596
17597 idx = 0;
d62a17ae 17598 argv_find(argv, argc, "(100-500)", &idx);
17599 argv_find(argv, argc, "WORD", &idx);
17600 cl_number_or_name = argv[idx]->arg;
42f914d4 17601
d62a17ae 17602 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17603 seq, direct, style);
42f914d4 17604
d62a17ae 17605 XFREE(MTYPE_TMP, str);
42f914d4 17606
d62a17ae 17607 if (ret < 0) {
17608 community_list_perror(vty, ret);
17609 return CMD_WARNING_CONFIG_FAILED;
17610 }
42f914d4 17611
d62a17ae 17612 return CMD_SUCCESS;
718e3744 17613}
17614
d4455c89
DA
17615ALIAS(no_extcommunity_list_expanded_all,
17616 no_bgp_extcommunity_list_expanded_all_list_cmd,
17617 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17618 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17619 "Extended Community list number (expanded)\n"
17620 "Specify expanded extcommunity-list\n"
17621 "Extended Community list name\n")
17622
d62a17ae 17623static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 17624{
d62a17ae 17625 struct community_entry *entry;
718e3744 17626
d62a17ae 17627 for (entry = list->head; entry; entry = entry->next) {
17628 if (entry == list->head) {
17629 if (all_digit(list->name))
17630 vty_out(vty, "Extended community %s list %s\n",
17631 entry->style == EXTCOMMUNITY_LIST_STANDARD
17632 ? "standard"
17633 : "(expanded) access",
17634 list->name);
17635 else
17636 vty_out(vty,
17637 "Named extended community %s list %s\n",
17638 entry->style == EXTCOMMUNITY_LIST_STANDARD
17639 ? "standard"
17640 : "expanded",
17641 list->name);
17642 }
17643 if (entry->any)
17644 vty_out(vty, " %s\n",
17645 community_direct_str(entry->direct));
17646 else
17647 vty_out(vty, " %s %s\n",
17648 community_direct_str(entry->direct),
8d9b8ed9 17649 community_list_config_str(entry));
d62a17ae 17650 }
718e3744 17651}
17652
7336e101
SP
17653DEFUN (show_extcommunity_list,
17654 show_bgp_extcommunity_list_cmd,
17655 "show bgp extcommunity-list",
718e3744 17656 SHOW_STR
7336e101 17657 BGP_STR
718e3744 17658 "List extended-community list\n")
17659{
d62a17ae 17660 struct community_list *list;
17661 struct community_list_master *cm;
718e3744 17662
d62a17ae 17663 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17664 if (!cm)
17665 return CMD_SUCCESS;
718e3744 17666
d62a17ae 17667 for (list = cm->num.head; list; list = list->next)
17668 extcommunity_list_show(vty, list);
718e3744 17669
d62a17ae 17670 for (list = cm->str.head; list; list = list->next)
17671 extcommunity_list_show(vty, list);
718e3744 17672
d62a17ae 17673 return CMD_SUCCESS;
718e3744 17674}
17675
7336e101
SP
17676DEFUN (show_extcommunity_list_arg,
17677 show_bgp_extcommunity_list_arg_cmd,
960b69b9 17678 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
17679 SHOW_STR
17680 BGP_STR
718e3744 17681 "List extended-community list\n"
17682 "Extcommunity-list number\n"
960b69b9 17683 "Extcommunity-list name\n"
17684 "Detailed information on extcommunity-list\n")
718e3744 17685{
d62a17ae 17686 int idx_comm_list = 3;
17687 struct community_list *list;
718e3744 17688
e237b0d2 17689 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17690 EXTCOMMUNITY_LIST_MASTER);
17691 if (!list) {
17692 vty_out(vty, "%% Can't find extcommunity-list\n");
17693 return CMD_WARNING;
17694 }
718e3744 17695
d62a17ae 17696 extcommunity_list_show(vty, list);
718e3744 17697
d62a17ae 17698 return CMD_SUCCESS;
718e3744 17699}
6b0655a2 17700
718e3744 17701/* Display community-list and extcommunity-list configuration. */
d62a17ae 17702static int community_list_config_write(struct vty *vty)
17703{
17704 struct community_list *list;
17705 struct community_entry *entry;
17706 struct community_list_master *cm;
17707 int write = 0;
17708
17709 /* Community-list. */
17710 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17711
17712 for (list = cm->num.head; list; list = list->next)
17713 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17714 vty_out(vty,
17715 "bgp community-list %s seq %" PRId64 " %s %s\n",
17716 list->name, entry->seq,
d62a17ae 17717 community_direct_str(entry->direct),
17718 community_list_config_str(entry));
17719 write++;
17720 }
17721 for (list = cm->str.head; list; list = list->next)
17722 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17723 vty_out(vty,
17724 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 17725 entry->style == COMMUNITY_LIST_STANDARD
17726 ? "standard"
17727 : "expanded",
2f8cc0e5
DA
17728 list->name, entry->seq,
17729 community_direct_str(entry->direct),
d62a17ae 17730 community_list_config_str(entry));
17731 write++;
17732 }
17733
17734 /* Extcommunity-list. */
17735 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17736
17737 for (list = cm->num.head; list; list = list->next)
17738 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17739 vty_out(vty,
17740 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
17741 list->name, entry->seq,
17742 community_direct_str(entry->direct),
d62a17ae 17743 community_list_config_str(entry));
17744 write++;
17745 }
17746 for (list = cm->str.head; list; list = list->next)
17747 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17748 vty_out(vty,
17749 "bgp extcommunity-list %s %s seq %" PRId64
17750 " %s %s\n",
d62a17ae 17751 entry->style == EXTCOMMUNITY_LIST_STANDARD
17752 ? "standard"
17753 : "expanded",
2f8cc0e5
DA
17754 list->name, entry->seq,
17755 community_direct_str(entry->direct),
d62a17ae 17756 community_list_config_str(entry));
17757 write++;
17758 }
17759
17760
17761 /* lcommunity-list. */
17762 cm = community_list_master_lookup(bgp_clist,
17763 LARGE_COMMUNITY_LIST_MASTER);
17764
17765 for (list = cm->num.head; list; list = list->next)
17766 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17767 vty_out(vty,
17768 "bgp large-community-list %s seq %" PRId64
17769 " %s %s\n",
17770 list->name, entry->seq,
17771 community_direct_str(entry->direct),
d62a17ae 17772 community_list_config_str(entry));
17773 write++;
17774 }
17775 for (list = cm->str.head; list; list = list->next)
17776 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17777 vty_out(vty,
17778 "bgp large-community-list %s %s seq %" PRId64
17779 " %s %s\n",
17780
d62a17ae 17781 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17782 ? "standard"
17783 : "expanded",
2f8cc0e5 17784 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 17785 community_list_config_str(entry));
17786 write++;
17787 }
17788
17789 return write;
17790}
17791
17792static struct cmd_node community_list_node = {
17793 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 17794};
17795
d62a17ae 17796static void community_list_vty(void)
17797{
17798 install_node(&community_list_node, community_list_config_write);
17799
17800 /* Community-list. */
7336e101
SP
17801 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17802 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17803 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 17804 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 17805 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 17806 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
17807 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17808 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 17809
17810 /* Extcommunity-list. */
7336e101
SP
17811 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17812 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17813 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
17814 install_element(CONFIG_NODE,
17815 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 17816 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
17817 install_element(CONFIG_NODE,
17818 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
17819 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17820 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 17821
17822 /* Large Community List */
7336e101 17823 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
17824 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17825 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 17826 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
17827 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
17828 install_element(CONFIG_NODE,
17829 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
17830 install_element(CONFIG_NODE,
17831 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17832 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17833 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17834 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17835 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17836 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17837 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 17838}