]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #5744 from ton31337/fix/thread-as-withdraw_attributes
[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
36235319
QY
108#define GR_NO_OPER \
109 "The Graceful Restart No Operation was executed as cmd same as previous one."
110#define GR_INVALID \
111 "The Graceful Restart command used is not valid at this moment."
d62a17ae 112static struct peer_group *listen_range_exists(struct bgp *bgp,
113 struct prefix *range, int exact);
114
055679e9 115/* Show BGP peer's information. */
116enum show_type {
117 show_all,
118 show_peer,
119 show_ipv4_all,
120 show_ipv6_all,
121 show_ipv4_peer,
122 show_ipv6_peer
123};
124
36235319
QY
125static struct peer_group *listen_range_exists(struct bgp *bgp,
126 struct prefix *range, int exact);
2986cac2 127
36235319
QY
128static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
129 struct bgp *bgp,
130 bool use_json,
131 json_object *json);
2986cac2 132
36235319
QY
133static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
134 enum show_type type,
135 const char *ip_str,
136 afi_t afi, bool use_json);
2986cac2 137
d62a17ae 138static enum node_type bgp_node_type(afi_t afi, safi_t safi)
139{
140 switch (afi) {
141 case AFI_IP:
142 switch (safi) {
143 case SAFI_UNICAST:
144 return BGP_IPV4_NODE;
145 break;
146 case SAFI_MULTICAST:
147 return BGP_IPV4M_NODE;
148 break;
149 case SAFI_LABELED_UNICAST:
150 return BGP_IPV4L_NODE;
151 break;
152 case SAFI_MPLS_VPN:
153 return BGP_VPNV4_NODE;
154 break;
7c40bf39 155 case SAFI_FLOWSPEC:
156 return BGP_FLOWSPECV4_NODE;
5c525538
RW
157 default:
158 /* not expected */
159 return BGP_IPV4_NODE;
160 break;
d62a17ae 161 }
162 break;
163 case AFI_IP6:
164 switch (safi) {
165 case SAFI_UNICAST:
166 return BGP_IPV6_NODE;
167 break;
168 case SAFI_MULTICAST:
169 return BGP_IPV6M_NODE;
170 break;
171 case SAFI_LABELED_UNICAST:
172 return BGP_IPV6L_NODE;
173 break;
174 case SAFI_MPLS_VPN:
175 return BGP_VPNV6_NODE;
176 break;
7c40bf39 177 case SAFI_FLOWSPEC:
178 return BGP_FLOWSPECV6_NODE;
5c525538
RW
179 default:
180 /* not expected */
181 return BGP_IPV4_NODE;
182 break;
d62a17ae 183 }
184 break;
185 case AFI_L2VPN:
186 return BGP_EVPN_NODE;
187 break;
b26f891d 188 case AFI_UNSPEC:
d62a17ae 189 case AFI_MAX:
190 // We should never be here but to clarify the switch statement..
191 return BGP_IPV4_NODE;
192 break;
193 }
194
195 // Impossible to happen
196 return BGP_IPV4_NODE;
f51bae9c 197}
20eb8864 198
5cb5f4d0
DD
199static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
200{
201 if (afi == AFI_IP && safi == SAFI_UNICAST)
202 return "IPv4 Unicast";
203 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
204 return "IPv4 Multicast";
205 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
206 return "IPv4 Labeled Unicast";
207 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
208 return "IPv4 VPN";
209 else if (afi == AFI_IP && safi == SAFI_ENCAP)
210 return "IPv4 Encap";
211 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
212 return "IPv4 Flowspec";
213 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
214 return "IPv6 Unicast";
215 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
216 return "IPv6 Multicast";
217 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
218 return "IPv6 Labeled Unicast";
219 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
220 return "IPv6 VPN";
221 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
222 return "IPv6 Encap";
223 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
224 return "IPv6 Flowspec";
225 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
226 return "L2VPN EVPN";
8e5509b0 227 else
5cb5f4d0 228 return "Unknown";
5cb5f4d0
DD
229}
230
231/*
232 * Please note that we have intentionally camelCased
233 * the return strings here. So if you want
234 * to use this function, please ensure you
235 * are doing this within json output
236 */
237static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
238{
239 if (afi == AFI_IP && safi == SAFI_UNICAST)
240 return "ipv4Unicast";
241 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
242 return "ipv4Multicast";
243 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
244 return "ipv4LabeledUnicast";
245 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
246 return "ipv4Vpn";
247 else if (afi == AFI_IP && safi == SAFI_ENCAP)
248 return "ipv4Encap";
249 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
250 return "ipv4Flowspec";
251 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
252 return "ipv6Unicast";
253 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
254 return "ipv6Multicast";
255 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
256 return "ipv6LabeledUnicast";
257 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
258 return "ipv6Vpn";
259 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
260 return "ipv6Encap";
261 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
262 return "ipv6Flowspec";
263 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
264 return "l2VpnEvpn";
8e5509b0 265 else
5cb5f4d0 266 return "Unknown";
5cb5f4d0
DD
267}
268
718e3744 269/* Utility function to get address family from current node. */
d62a17ae 270afi_t bgp_node_afi(struct vty *vty)
271{
272 afi_t afi;
273 switch (vty->node) {
274 case BGP_IPV6_NODE:
275 case BGP_IPV6M_NODE:
276 case BGP_IPV6L_NODE:
277 case BGP_VPNV6_NODE:
7c40bf39 278 case BGP_FLOWSPECV6_NODE:
d62a17ae 279 afi = AFI_IP6;
280 break;
281 case BGP_EVPN_NODE:
282 afi = AFI_L2VPN;
283 break;
284 default:
285 afi = AFI_IP;
286 break;
287 }
288 return afi;
718e3744 289}
290
291/* Utility function to get subsequent address family from current
292 node. */
d62a17ae 293safi_t bgp_node_safi(struct vty *vty)
294{
295 safi_t safi;
296 switch (vty->node) {
297 case BGP_VPNV4_NODE:
298 case BGP_VPNV6_NODE:
299 safi = SAFI_MPLS_VPN;
300 break;
301 case BGP_IPV4M_NODE:
302 case BGP_IPV6M_NODE:
303 safi = SAFI_MULTICAST;
304 break;
305 case BGP_EVPN_NODE:
306 safi = SAFI_EVPN;
307 break;
308 case BGP_IPV4L_NODE:
309 case BGP_IPV6L_NODE:
310 safi = SAFI_LABELED_UNICAST;
311 break;
7c40bf39 312 case BGP_FLOWSPECV4_NODE:
313 case BGP_FLOWSPECV6_NODE:
314 safi = SAFI_FLOWSPEC;
315 break;
d62a17ae 316 default:
317 safi = SAFI_UNICAST;
318 break;
319 }
320 return safi;
718e3744 321}
322
55f91488
QY
323/**
324 * Converts an AFI in string form to afi_t
325 *
326 * @param afi string, one of
327 * - "ipv4"
328 * - "ipv6"
81cf0de5 329 * - "l2vpn"
55f91488
QY
330 * @return the corresponding afi_t
331 */
d62a17ae 332afi_t bgp_vty_afi_from_str(const char *afi_str)
333{
334 afi_t afi = AFI_MAX; /* unknown */
335 if (strmatch(afi_str, "ipv4"))
336 afi = AFI_IP;
337 else if (strmatch(afi_str, "ipv6"))
338 afi = AFI_IP6;
81cf0de5
CS
339 else if (strmatch(afi_str, "l2vpn"))
340 afi = AFI_L2VPN;
d62a17ae 341 return afi;
342}
343
344int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
345 afi_t *afi)
346{
347 int ret = 0;
348 if (argv_find(argv, argc, "ipv4", index)) {
349 ret = 1;
350 if (afi)
351 *afi = AFI_IP;
352 } else if (argv_find(argv, argc, "ipv6", index)) {
353 ret = 1;
354 if (afi)
355 *afi = AFI_IP6;
8688b3e7
DS
356 } else if (argv_find(argv, argc, "l2vpn", index)) {
357 ret = 1;
358 if (afi)
359 *afi = AFI_L2VPN;
d62a17ae 360 }
361 return ret;
46f296b4
LB
362}
363
375a2e67 364/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 365safi_t bgp_vty_safi_from_str(const char *safi_str)
366{
367 safi_t safi = SAFI_MAX; /* unknown */
368 if (strmatch(safi_str, "multicast"))
369 safi = SAFI_MULTICAST;
370 else if (strmatch(safi_str, "unicast"))
371 safi = SAFI_UNICAST;
372 else if (strmatch(safi_str, "vpn"))
373 safi = SAFI_MPLS_VPN;
81cf0de5
CS
374 else if (strmatch(safi_str, "evpn"))
375 safi = SAFI_EVPN;
d62a17ae 376 else if (strmatch(safi_str, "labeled-unicast"))
377 safi = SAFI_LABELED_UNICAST;
7c40bf39 378 else if (strmatch(safi_str, "flowspec"))
379 safi = SAFI_FLOWSPEC;
d62a17ae 380 return safi;
381}
382
383int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
384 safi_t *safi)
385{
386 int ret = 0;
387 if (argv_find(argv, argc, "unicast", index)) {
388 ret = 1;
389 if (safi)
390 *safi = SAFI_UNICAST;
391 } else if (argv_find(argv, argc, "multicast", index)) {
392 ret = 1;
393 if (safi)
394 *safi = SAFI_MULTICAST;
395 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
396 ret = 1;
397 if (safi)
398 *safi = SAFI_LABELED_UNICAST;
399 } else if (argv_find(argv, argc, "vpn", index)) {
400 ret = 1;
401 if (safi)
402 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
403 } else if (argv_find(argv, argc, "evpn", index)) {
404 ret = 1;
405 if (safi)
406 *safi = SAFI_EVPN;
7c40bf39 407 } else if (argv_find(argv, argc, "flowspec", index)) {
408 ret = 1;
409 if (safi)
410 *safi = SAFI_FLOWSPEC;
d62a17ae 411 }
412 return ret;
46f296b4
LB
413}
414
5d5393b9
DL
415int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
416 enum bgp_instance_type inst_type)
417{
418 int ret = bgp_get(bgp, as, name, inst_type);
419
420 if (ret == BGP_CREATED) {
421 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
422 DFLT_BGP_CONNECT_RETRY);
423
424 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 425 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 426 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 427 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
5d5393b9 428 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 429 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 430 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 431 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
5d5393b9
DL
432
433 ret = BGP_SUCCESS;
434 }
435 return ret;
436}
437
7eeee51e 438/*
f212a857 439 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 440 *
f212a857
DS
441 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
442 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
443 * to appropriate values for the calling function. This is to allow the
444 * calling function to make decisions appropriate for the show command
445 * that is being parsed.
446 *
447 * The show commands are generally of the form:
d62a17ae 448 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
449 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
450 *
451 * Since we use argv_find if the show command in particular doesn't have:
452 * [ip]
18c57037 453 * [<view|vrf> VIEWVRFNAME]
375a2e67 454 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
455 * The command parsing should still be ok.
456 *
457 * vty -> The vty for the command so we can output some useful data in
458 * the event of a parse error in the vrf.
459 * argv -> The command tokens
460 * argc -> How many command tokens we have
d62a17ae 461 * idx -> The current place in the command, generally should be 0 for this
462 * function
7eeee51e
DS
463 * afi -> The parsed afi if it was included in the show command, returned here
464 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 465 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 466 * use_json -> json is configured or not
7eeee51e
DS
467 *
468 * The function returns the correct location in the parse tree for the
469 * last token found.
0e37c258
DS
470 *
471 * Returns 0 for failure to parse correctly, else the idx position of where
472 * it found the last token.
7eeee51e 473 */
d62a17ae 474int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
475 struct cmd_token **argv, int argc,
476 int *idx, afi_t *afi, safi_t *safi,
9f049418 477 struct bgp **bgp, bool use_json)
d62a17ae 478{
479 char *vrf_name = NULL;
480
481 assert(afi);
482 assert(safi);
483 assert(bgp);
484
485 if (argv_find(argv, argc, "ip", idx))
486 *afi = AFI_IP;
487
9a8bdf1c 488 if (argv_find(argv, argc, "view", idx))
d62a17ae 489 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
490 else if (argv_find(argv, argc, "vrf", idx)) {
491 vrf_name = argv[*idx + 1]->arg;
492 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
493 vrf_name = NULL;
494 }
495 if (vrf_name) {
d62a17ae 496 if (strmatch(vrf_name, "all"))
497 *bgp = NULL;
498 else {
499 *bgp = bgp_lookup_by_name(vrf_name);
500 if (!*bgp) {
52e5b8c4
SP
501 if (use_json) {
502 json_object *json = NULL;
503 json = json_object_new_object();
504 json_object_string_add(
505 json, "warning",
506 "View/Vrf is unknown");
507 vty_out(vty, "%s\n",
508 json_object_to_json_string_ext(json,
509 JSON_C_TO_STRING_PRETTY));
510 json_object_free(json);
511 }
ca61fd25
DS
512 else
513 vty_out(vty, "View/Vrf %s is unknown\n",
514 vrf_name);
d62a17ae 515 *idx = 0;
516 return 0;
517 }
518 }
519 } else {
520 *bgp = bgp_get_default();
521 if (!*bgp) {
52e5b8c4
SP
522 if (use_json) {
523 json_object *json = NULL;
524 json = json_object_new_object();
525 json_object_string_add(
526 json, "warning",
527 "Default BGP instance not found");
528 vty_out(vty, "%s\n",
529 json_object_to_json_string_ext(json,
530 JSON_C_TO_STRING_PRETTY));
531 json_object_free(json);
532 }
ca61fd25
DS
533 else
534 vty_out(vty,
535 "Default BGP instance not found\n");
d62a17ae 536 *idx = 0;
537 return 0;
538 }
539 }
540
541 if (argv_find_and_parse_afi(argv, argc, idx, afi))
542 argv_find_and_parse_safi(argv, argc, idx, safi);
543
544 *idx += 1;
545 return *idx;
546}
547
548static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
549{
550 struct interface *ifp = NULL;
551
552 if (su->sa.sa_family == AF_INET)
553 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
554 else if (su->sa.sa_family == AF_INET6)
555 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
556 su->sin6.sin6_scope_id,
557 bgp->vrf_id);
558
559 if (ifp)
560 return 1;
561
562 return 0;
718e3744 563}
564
565/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
566/* This is used only for configuration, so disallow if attempted on
567 * a dynamic neighbor.
568 */
d62a17ae 569static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
570{
571 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
572 int ret;
573 union sockunion su;
574 struct peer *peer;
575
576 if (!bgp) {
577 return NULL;
578 }
579
580 ret = str2sockunion(ip_str, &su);
581 if (ret < 0) {
582 peer = peer_lookup_by_conf_if(bgp, ip_str);
583 if (!peer) {
584 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
585 == NULL) {
586 vty_out(vty,
587 "%% Malformed address or name: %s\n",
588 ip_str);
589 return NULL;
590 }
591 }
592 } else {
593 peer = peer_lookup(bgp, &su);
594 if (!peer) {
595 vty_out(vty,
596 "%% Specify remote-as or peer-group commands first\n");
597 return NULL;
598 }
599 if (peer_dynamic_neighbor(peer)) {
600 vty_out(vty,
601 "%% Operation not allowed on a dynamic neighbor\n");
602 return NULL;
603 }
604 }
605 return peer;
718e3744 606}
607
608/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
609/* This is used only for configuration, so disallow if attempted on
610 * a dynamic neighbor.
611 */
d62a17ae 612struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
613{
614 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
615 int ret;
616 union sockunion su;
617 struct peer *peer = NULL;
618 struct peer_group *group = NULL;
619
620 if (!bgp) {
621 return NULL;
622 }
623
624 ret = str2sockunion(peer_str, &su);
625 if (ret == 0) {
626 /* IP address, locate peer. */
627 peer = peer_lookup(bgp, &su);
628 } else {
629 /* Not IP, could match either peer configured on interface or a
630 * group. */
631 peer = peer_lookup_by_conf_if(bgp, peer_str);
632 if (!peer)
633 group = peer_group_lookup(bgp, peer_str);
634 }
635
636 if (peer) {
637 if (peer_dynamic_neighbor(peer)) {
638 vty_out(vty,
639 "%% Operation not allowed on a dynamic neighbor\n");
640 return NULL;
641 }
642
643 return peer;
644 }
645
646 if (group)
647 return group->conf;
648
649 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
650
651 return NULL;
652}
653
654int bgp_vty_return(struct vty *vty, int ret)
655{
656 const char *str = NULL;
657
658 switch (ret) {
659 case BGP_ERR_INVALID_VALUE:
660 str = "Invalid value";
661 break;
662 case BGP_ERR_INVALID_FLAG:
663 str = "Invalid flag";
664 break;
665 case BGP_ERR_PEER_GROUP_SHUTDOWN:
666 str = "Peer-group has been shutdown. Activate the peer-group first";
667 break;
668 case BGP_ERR_PEER_FLAG_CONFLICT:
669 str = "Can't set override-capability and strict-capability-match at the same time";
670 break;
671 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
672 str = "Specify remote-as or peer-group remote AS first";
673 break;
674 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
675 str = "Cannot change the peer-group. Deconfigure first";
676 break;
677 case BGP_ERR_PEER_GROUP_MISMATCH:
678 str = "Peer is not a member of this peer-group";
679 break;
680 case BGP_ERR_PEER_FILTER_CONFLICT:
681 str = "Prefix/distribute list can not co-exist";
682 break;
683 case BGP_ERR_NOT_INTERNAL_PEER:
684 str = "Invalid command. Not an internal neighbor";
685 break;
686 case BGP_ERR_REMOVE_PRIVATE_AS:
687 str = "remove-private-AS cannot be configured for IBGP peers";
688 break;
689 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
690 str = "Local-AS allowed only for EBGP peers";
691 break;
692 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
693 str = "Cannot have local-as same as BGP AS number";
694 break;
695 case BGP_ERR_TCPSIG_FAILED:
696 str = "Error while applying TCP-Sig to session(s)";
697 break;
698 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
699 str = "ebgp-multihop and ttl-security cannot be configured together";
700 break;
701 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
702 str = "ttl-security only allowed for EBGP peers";
703 break;
704 case BGP_ERR_AS_OVERRIDE:
705 str = "as-override cannot be configured for IBGP peers";
706 break;
707 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
708 str = "Invalid limit for number of dynamic neighbors";
709 break;
710 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
711 str = "Dynamic neighbor listen range already exists";
712 break;
713 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
714 str = "Operation not allowed on a dynamic neighbor";
715 break;
716 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
717 str = "Operation not allowed on a directly connected neighbor";
718 break;
719 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 720 str = GR_INVALID;
721 break;
722 case BGP_ERR_GR_INVALID_CMD:
723 str = "The Graceful Restart command used is not valid at this moment.";
724 break;
725 case BGP_ERR_GR_OPERATION_FAILED:
726 str = "The Graceful Restart Operation failed due to an err.";
727 break;
728 case BGP_GR_NO_OPERATION:
729 str = GR_NO_OPER;
d62a17ae 730 break;
731 }
732 if (str) {
733 vty_out(vty, "%% %s\n", str);
734 return CMD_WARNING_CONFIG_FAILED;
735 }
736 return CMD_SUCCESS;
718e3744 737}
738
7aafcaca 739/* BGP clear sort. */
d62a17ae 740enum clear_sort {
741 clear_all,
742 clear_peer,
743 clear_group,
744 clear_external,
745 clear_as
7aafcaca
DS
746};
747
d62a17ae 748static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
749 safi_t safi, int error)
750{
751 switch (error) {
752 case BGP_ERR_AF_UNCONFIGURED:
753 vty_out(vty,
754 "%%BGP: Enable %s address family for the neighbor %s\n",
5cb5f4d0 755 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 756 break;
757 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
758 vty_out(vty,
759 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
760 peer->host);
761 break;
762 default:
763 break;
764 }
7aafcaca
DS
765}
766
dc912615
DS
767static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
768 struct listnode *nnode, enum bgp_clear_type stype)
769{
770 int ret = 0;
771
772 /* if afi/.safi not specified, spin thru all of them */
773 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
774 afi_t tmp_afi;
775 safi_t tmp_safi;
776
777 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
778 if (!peer->afc[tmp_afi][tmp_safi])
779 continue;
780
781 if (stype == BGP_CLEAR_SOFT_NONE)
782 ret = peer_clear(peer, &nnode);
783 else
784 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
785 stype);
786 }
787 /* if afi specified and safi not, spin thru safis on this afi */
788 } else if (safi == SAFI_UNSPEC) {
789 safi_t tmp_safi;
790
791 for (tmp_safi = SAFI_UNICAST;
792 tmp_safi < SAFI_MAX; tmp_safi++) {
793 if (!peer->afc[afi][tmp_safi])
794 continue;
795
796 if (stype == BGP_CLEAR_SOFT_NONE)
797 ret = peer_clear(peer, &nnode);
798 else
799 ret = peer_clear_soft(peer, afi,
800 tmp_safi, stype);
801 }
802 /* both afi/safi specified, let the caller know if not defined */
803 } else {
804 if (!peer->afc[afi][safi])
805 return 1;
806
807 if (stype == BGP_CLEAR_SOFT_NONE)
808 ret = peer_clear(peer, &nnode);
809 else
810 ret = peer_clear_soft(peer, afi, safi, stype);
811 }
812
813 return ret;
814}
815
7aafcaca 816/* `clear ip bgp' functions. */
d62a17ae 817static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
818 enum clear_sort sort, enum bgp_clear_type stype,
819 const char *arg)
820{
dc912615 821 int ret = 0;
3ae8bfa5 822 bool found = false;
d62a17ae 823 struct peer *peer;
dc95985f 824
825 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 826
827 /* Clear all neighbors. */
828 /*
829 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
830 * nodes on the BGP instance as that may get freed if it is a
831 * doppelganger
d62a17ae 832 */
833 if (sort == clear_all) {
834 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 835
836 bgp_peer_gr_flags_update(peer);
837
36235319 838 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 839 gr_router_detected = true;
840
dc912615
DS
841 ret = bgp_peer_clear(peer, afi, safi, nnode,
842 stype);
d62a17ae 843
844 if (ret < 0)
845 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 846 }
847
36235319
QY
848 if (gr_router_detected
849 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 850 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
851 } else if (!gr_router_detected
852 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 853 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 854 }
d62a17ae 855
856 /* This is to apply read-only mode on this clear. */
857 if (stype == BGP_CLEAR_SOFT_NONE)
858 bgp->update_delay_over = 0;
859
860 return CMD_SUCCESS;
7aafcaca
DS
861 }
862
3ae8bfa5 863 /* Clear specified neighbor. */
d62a17ae 864 if (sort == clear_peer) {
865 union sockunion su;
d62a17ae 866
867 /* Make sockunion for lookup. */
868 ret = str2sockunion(arg, &su);
869 if (ret < 0) {
870 peer = peer_lookup_by_conf_if(bgp, arg);
871 if (!peer) {
872 peer = peer_lookup_by_hostname(bgp, arg);
873 if (!peer) {
874 vty_out(vty,
875 "Malformed address or name: %s\n",
876 arg);
877 return CMD_WARNING;
878 }
879 }
880 } else {
881 peer = peer_lookup(bgp, &su);
882 if (!peer) {
883 vty_out(vty,
884 "%%BGP: Unknown neighbor - \"%s\"\n",
885 arg);
886 return CMD_WARNING;
887 }
888 }
7aafcaca 889
dc95985f 890 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
891 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
892
dc912615
DS
893 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
894
895 /* if afi/safi not defined for this peer, let caller know */
896 if (ret == 1)
3ae8bfa5 897 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 898
d62a17ae 899 if (ret < 0)
900 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 901
d62a17ae 902 return CMD_SUCCESS;
7aafcaca 903 }
7aafcaca 904
3ae8bfa5 905 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 906 if (sort == clear_group) {
907 struct peer_group *group;
7aafcaca 908
d62a17ae 909 group = peer_group_lookup(bgp, arg);
910 if (!group) {
911 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
912 return CMD_WARNING;
913 }
914
915 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
dc912615 916 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 917
d62a17ae 918 if (ret < 0)
919 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
920 else
921 found = true;
d62a17ae 922 }
3ae8bfa5
PM
923
924 if (!found)
925 vty_out(vty,
926 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 927 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 928
d62a17ae 929 return CMD_SUCCESS;
7aafcaca 930 }
7aafcaca 931
3ae8bfa5 932 /* Clear all external (eBGP) neighbors. */
d62a17ae 933 if (sort == clear_external) {
934 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
935 if (peer->sort == BGP_PEER_IBGP)
936 continue;
7aafcaca 937
dc95985f 938 bgp_peer_gr_flags_update(peer);
939
36235319 940 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 941 gr_router_detected = true;
dc95985f 942
dc912615 943 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
7aafcaca 944
d62a17ae 945 if (ret < 0)
946 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
947 else
948 found = true;
d62a17ae 949 }
3ae8bfa5 950
36235319
QY
951 if (gr_router_detected
952 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 953 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
954 } else if (!gr_router_detected
955 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 956 bgp_zebra_send_capabilities(bgp, true);
957 }
958
3ae8bfa5
PM
959 if (!found)
960 vty_out(vty,
961 "%%BGP: No external %s peer is configured\n",
5cb5f4d0 962 get_afi_safi_str(afi, safi, false));
3ae8bfa5 963
d62a17ae 964 return CMD_SUCCESS;
965 }
966
3ae8bfa5 967 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 968 if (sort == clear_as) {
3ae8bfa5 969 as_t as = strtoul(arg, NULL, 10);
d62a17ae 970
971 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
972 if (peer->as != as)
973 continue;
974
dc95985f 975 bgp_peer_gr_flags_update(peer);
976
36235319 977 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 978 gr_router_detected = true;
dc95985f 979
dc912615 980 ret = bgp_peer_clear(peer, afi, safi, nnode, stype);
d62a17ae 981
982 if (ret < 0)
983 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
984 else
985 found = true;
d62a17ae 986 }
3ae8bfa5 987
36235319
QY
988 if (gr_router_detected
989 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 990 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
991 } else if (!gr_router_detected
992 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 993 bgp_zebra_send_capabilities(bgp, true);
994 }
995
3ae8bfa5 996 if (!found)
d62a17ae 997 vty_out(vty,
3ae8bfa5 998 "%%BGP: No %s peer is configured with AS %s\n",
5cb5f4d0 999 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1000
d62a17ae 1001 return CMD_SUCCESS;
1002 }
1003
1004 return CMD_SUCCESS;
1005}
1006
1007static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1008 safi_t safi, enum clear_sort sort,
1009 enum bgp_clear_type stype, const char *arg)
1010{
1011 struct bgp *bgp;
1012
1013 /* BGP structure lookup. */
1014 if (name) {
1015 bgp = bgp_lookup_by_name(name);
1016 if (bgp == NULL) {
1017 vty_out(vty, "Can't find BGP instance %s\n", name);
1018 return CMD_WARNING;
1019 }
1020 } else {
1021 bgp = bgp_get_default();
1022 if (bgp == NULL) {
1023 vty_out(vty, "No BGP process is configured\n");
1024 return CMD_WARNING;
1025 }
1026 }
1027
1028 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1029}
1030
1031/* clear soft inbound */
d62a17ae 1032static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1033{
99b3ebd3
NS
1034 afi_t afi;
1035 safi_t safi;
1036
1037 FOREACH_AFI_SAFI (afi, safi)
1038 bgp_clear_vty(vty, name, afi, safi, clear_all,
1039 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1040}
1041
1042/* clear soft outbound */
d62a17ae 1043static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1044{
99b3ebd3
NS
1045 afi_t afi;
1046 safi_t safi;
1047
1048 FOREACH_AFI_SAFI (afi, safi)
1049 bgp_clear_vty(vty, name, afi, safi, clear_all,
1050 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1051}
1052
1053
f787d7a0 1054#ifndef VTYSH_EXTRACT_PL
2e4c2296 1055#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1056#endif
1057
8029b216
AK
1058DEFUN_HIDDEN (bgp_local_mac,
1059 bgp_local_mac_cmd,
093e3f23 1060 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1061 BGP_STR
1062 "Local MAC config\n"
1063 "VxLAN Network Identifier\n"
1064 "VNI number\n"
1065 "local mac\n"
1066 "mac address\n"
1067 "mac-mobility sequence\n"
1068 "seq number\n")
1069{
1070 int rv;
1071 vni_t vni;
1072 struct ethaddr mac;
1073 struct ipaddr ip;
1074 uint32_t seq;
1075 struct bgp *bgp;
1076
1077 vni = strtoul(argv[3]->arg, NULL, 10);
1078 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1079 vty_out(vty, "%% Malformed MAC address\n");
1080 return CMD_WARNING;
1081 }
1082 memset(&ip, 0, sizeof(ip));
1083 seq = strtoul(argv[7]->arg, NULL, 10);
1084
1085 bgp = bgp_get_default();
1086 if (!bgp) {
1087 vty_out(vty, "Default BGP instance is not there\n");
1088 return CMD_WARNING;
1089 }
1090
1091 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
1092 if (rv < 0) {
1093 vty_out(vty, "Internal error\n");
1094 return CMD_WARNING;
1095 }
1096
1097 return CMD_SUCCESS;
1098}
1099
1100DEFUN_HIDDEN (no_bgp_local_mac,
1101 no_bgp_local_mac_cmd,
093e3f23 1102 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1103 NO_STR
1104 BGP_STR
1105 "Local MAC config\n"
1106 "VxLAN Network Identifier\n"
1107 "VNI number\n"
1108 "local mac\n"
1109 "mac address\n")
1110{
1111 int rv;
1112 vni_t vni;
1113 struct ethaddr mac;
1114 struct ipaddr ip;
1115 struct bgp *bgp;
1116
1117 vni = strtoul(argv[4]->arg, NULL, 10);
1118 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1119 vty_out(vty, "%% Malformed MAC address\n");
1120 return CMD_WARNING;
1121 }
1122 memset(&ip, 0, sizeof(ip));
1123
1124 bgp = bgp_get_default();
1125 if (!bgp) {
1126 vty_out(vty, "Default BGP instance is not there\n");
1127 return CMD_WARNING;
1128 }
1129
ec0ab544 1130 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1131 if (rv < 0) {
1132 vty_out(vty, "Internal error\n");
1133 return CMD_WARNING;
1134 }
1135
1136 return CMD_SUCCESS;
1137}
1138
718e3744 1139DEFUN (no_synchronization,
1140 no_synchronization_cmd,
1141 "no synchronization",
1142 NO_STR
1143 "Perform IGP synchronization\n")
1144{
d62a17ae 1145 return CMD_SUCCESS;
718e3744 1146}
1147
1148DEFUN (no_auto_summary,
1149 no_auto_summary_cmd,
1150 "no auto-summary",
1151 NO_STR
1152 "Enable automatic network number summarization\n")
1153{
d62a17ae 1154 return CMD_SUCCESS;
718e3744 1155}
3d515fd9 1156
718e3744 1157/* "router bgp" commands. */
505e5056 1158DEFUN_NOSH (router_bgp,
f412b39a 1159 router_bgp_cmd,
2ed9fe4a 1160 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1161 ROUTER_STR
1162 BGP_STR
31500417
DW
1163 AS_STR
1164 BGP_INSTANCE_HELP_STR)
718e3744 1165{
d62a17ae 1166 int idx_asn = 2;
1167 int idx_view_vrf = 3;
1168 int idx_vrf = 4;
ecec9495 1169 int is_new_bgp = 0;
d62a17ae 1170 int ret;
1171 as_t as;
1172 struct bgp *bgp;
1173 const char *name = NULL;
1174 enum bgp_instance_type inst_type;
1175
1176 // "router bgp" without an ASN
1177 if (argc == 2) {
1178 // Pending: Make VRF option available for ASN less config
1179 bgp = bgp_get_default();
1180
1181 if (bgp == NULL) {
1182 vty_out(vty, "%% No BGP process is configured\n");
1183 return CMD_WARNING_CONFIG_FAILED;
1184 }
1185
1186 if (listcount(bm->bgp) > 1) {
996c9314 1187 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1188 return CMD_WARNING_CONFIG_FAILED;
1189 }
1190 }
1191
1192 // "router bgp X"
1193 else {
1194 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1195
1196 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1197 if (argc > 3) {
1198 name = argv[idx_vrf]->arg;
1199
9a8bdf1c
PG
1200 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1201 if (strmatch(name, VRF_DEFAULT_NAME))
1202 name = NULL;
1203 else
1204 inst_type = BGP_INSTANCE_TYPE_VRF;
1205 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1206 inst_type = BGP_INSTANCE_TYPE_VIEW;
1207 }
1208
ecec9495
AD
1209 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1210 is_new_bgp = (bgp_lookup(as, name) == NULL);
1211
5d5393b9 1212 ret = bgp_get_vty(&bgp, &as, name, inst_type);
d62a17ae 1213 switch (ret) {
d62a17ae 1214 case BGP_ERR_AS_MISMATCH:
1215 vty_out(vty, "BGP is already running; AS is %u\n", as);
1216 return CMD_WARNING_CONFIG_FAILED;
1217 case BGP_ERR_INSTANCE_MISMATCH:
1218 vty_out(vty,
1219 "BGP instance name and AS number mismatch\n");
1220 vty_out(vty,
1221 "BGP instance is already running; AS is %u\n",
1222 as);
1223 return CMD_WARNING_CONFIG_FAILED;
1224 }
1225
3bd70bf8
PZ
1226 /*
1227 * If we just instantiated the default instance, complete
1228 * any pending VRF-VPN leaking that was configured via
1229 * earlier "router bgp X vrf FOO" blocks.
1230 */
ecec9495 1231 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
3bd70bf8
PZ
1232 vpn_leak_postchange_all();
1233
48381346
CS
1234 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1235 bgp_vpn_leak_export(bgp);
d62a17ae 1236 /* Pending: handle when user tries to change a view to vrf n vv.
1237 */
1238 }
1239
0b5131c9
MK
1240 /* unset the auto created flag as the user config is now present */
1241 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 1242 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1243
1244 return CMD_SUCCESS;
718e3744 1245}
1246
718e3744 1247/* "no router bgp" commands. */
1248DEFUN (no_router_bgp,
1249 no_router_bgp_cmd,
2ed9fe4a 1250 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
718e3744 1251 NO_STR
1252 ROUTER_STR
1253 BGP_STR
31500417
DW
1254 AS_STR
1255 BGP_INSTANCE_HELP_STR)
718e3744 1256{
d62a17ae 1257 int idx_asn = 3;
1258 int idx_vrf = 5;
1259 as_t as;
1260 struct bgp *bgp;
1261 const char *name = NULL;
718e3744 1262
d62a17ae 1263 // "no router bgp" without an ASN
1264 if (argc == 3) {
1265 // Pending: Make VRF option available for ASN less config
1266 bgp = bgp_get_default();
718e3744 1267
d62a17ae 1268 if (bgp == NULL) {
1269 vty_out(vty, "%% No BGP process is configured\n");
1270 return CMD_WARNING_CONFIG_FAILED;
1271 }
7fb21a9f 1272
d62a17ae 1273 if (listcount(bm->bgp) > 1) {
996c9314 1274 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1275 return CMD_WARNING_CONFIG_FAILED;
1276 }
0b5131c9
MK
1277
1278 if (bgp->l3vni) {
1279 vty_out(vty, "%% Please unconfigure l3vni %u",
1280 bgp->l3vni);
1281 return CMD_WARNING_CONFIG_FAILED;
1282 }
d62a17ae 1283 } else {
1284 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1285
d62a17ae 1286 if (argc > 4)
1287 name = argv[idx_vrf]->arg;
7fb21a9f 1288
d62a17ae 1289 /* Lookup bgp structure. */
1290 bgp = bgp_lookup(as, name);
1291 if (!bgp) {
1292 vty_out(vty, "%% Can't find BGP instance\n");
1293 return CMD_WARNING_CONFIG_FAILED;
1294 }
0b5131c9
MK
1295
1296 if (bgp->l3vni) {
dd5868c2 1297 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1298 bgp->l3vni);
1299 return CMD_WARNING_CONFIG_FAILED;
1300 }
dd5868c2
DS
1301
1302 /* Cannot delete default instance if vrf instances exist */
1303 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1304 struct listnode *node;
1305 struct bgp *tmp_bgp;
1306
1307 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1308 if (tmp_bgp->inst_type
1309 == BGP_INSTANCE_TYPE_VRF) {
1310 vty_out(vty,
1311 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1312 return CMD_WARNING_CONFIG_FAILED;
1313 }
1314 }
1315 }
d62a17ae 1316 }
718e3744 1317
9ecf931b
CS
1318 if (bgp_vpn_leak_unimport(bgp, vty))
1319 return CMD_WARNING_CONFIG_FAILED;
1320
d62a17ae 1321 bgp_delete(bgp);
718e3744 1322
d62a17ae 1323 return CMD_SUCCESS;
718e3744 1324}
1325
6b0655a2 1326
718e3744 1327/* BGP router-id. */
1328
f787d7a0 1329DEFPY (bgp_router_id,
718e3744 1330 bgp_router_id_cmd,
1331 "bgp router-id A.B.C.D",
1332 BGP_STR
1333 "Override configured router identifier\n"
1334 "Manually configured router identifier\n")
1335{
d62a17ae 1336 VTY_DECLVAR_CONTEXT(bgp, bgp);
1337 bgp_router_id_static_set(bgp, router_id);
1338 return CMD_SUCCESS;
718e3744 1339}
1340
f787d7a0 1341DEFPY (no_bgp_router_id,
718e3744 1342 no_bgp_router_id_cmd,
31500417 1343 "no bgp router-id [A.B.C.D]",
718e3744 1344 NO_STR
1345 BGP_STR
31500417
DW
1346 "Override configured router identifier\n"
1347 "Manually configured router identifier\n")
718e3744 1348{
d62a17ae 1349 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1350
d62a17ae 1351 if (router_id_str) {
1352 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1353 vty_out(vty, "%% BGP router-id doesn't match\n");
1354 return CMD_WARNING_CONFIG_FAILED;
1355 }
e018c7cc 1356 }
718e3744 1357
d62a17ae 1358 router_id.s_addr = 0;
1359 bgp_router_id_static_set(bgp, router_id);
718e3744 1360
d62a17ae 1361 return CMD_SUCCESS;
718e3744 1362}
1363
6b0655a2 1364
718e3744 1365/* BGP Cluster ID. */
718e3744 1366DEFUN (bgp_cluster_id,
1367 bgp_cluster_id_cmd,
838758ac 1368 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1369 BGP_STR
1370 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1371 "Route-Reflector Cluster-id in IP address format\n"
1372 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1373{
d62a17ae 1374 VTY_DECLVAR_CONTEXT(bgp, bgp);
1375 int idx_ipv4 = 2;
1376 int ret;
1377 struct in_addr cluster;
718e3744 1378
d62a17ae 1379 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1380 if (!ret) {
1381 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1382 return CMD_WARNING_CONFIG_FAILED;
1383 }
718e3744 1384
d62a17ae 1385 bgp_cluster_id_set(bgp, &cluster);
1386 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1387
d62a17ae 1388 return CMD_SUCCESS;
718e3744 1389}
1390
718e3744 1391DEFUN (no_bgp_cluster_id,
1392 no_bgp_cluster_id_cmd,
c7178fe7 1393 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1394 NO_STR
1395 BGP_STR
838758ac
DW
1396 "Configure Route-Reflector Cluster-id\n"
1397 "Route-Reflector Cluster-id in IP address format\n"
1398 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1399{
d62a17ae 1400 VTY_DECLVAR_CONTEXT(bgp, bgp);
1401 bgp_cluster_id_unset(bgp);
1402 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1403
d62a17ae 1404 return CMD_SUCCESS;
718e3744 1405}
1406
718e3744 1407DEFUN (bgp_confederation_identifier,
1408 bgp_confederation_identifier_cmd,
9ccf14f7 1409 "bgp confederation identifier (1-4294967295)",
718e3744 1410 "BGP specific commands\n"
1411 "AS confederation parameters\n"
1412 "AS number\n"
1413 "Set routing domain confederation AS\n")
1414{
d62a17ae 1415 VTY_DECLVAR_CONTEXT(bgp, bgp);
1416 int idx_number = 3;
1417 as_t as;
718e3744 1418
d62a17ae 1419 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1420
d62a17ae 1421 bgp_confederation_id_set(bgp, as);
718e3744 1422
d62a17ae 1423 return CMD_SUCCESS;
718e3744 1424}
1425
1426DEFUN (no_bgp_confederation_identifier,
1427 no_bgp_confederation_identifier_cmd,
838758ac 1428 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1429 NO_STR
1430 "BGP specific commands\n"
1431 "AS confederation parameters\n"
3a2d747c
QY
1432 "AS number\n"
1433 "Set routing domain confederation AS\n")
718e3744 1434{
d62a17ae 1435 VTY_DECLVAR_CONTEXT(bgp, bgp);
1436 bgp_confederation_id_unset(bgp);
718e3744 1437
d62a17ae 1438 return CMD_SUCCESS;
718e3744 1439}
1440
718e3744 1441DEFUN (bgp_confederation_peers,
1442 bgp_confederation_peers_cmd,
12dcf78e 1443 "bgp confederation peers (1-4294967295)...",
718e3744 1444 "BGP specific commands\n"
1445 "AS confederation parameters\n"
1446 "Peer ASs in BGP confederation\n"
1447 AS_STR)
1448{
d62a17ae 1449 VTY_DECLVAR_CONTEXT(bgp, bgp);
1450 int idx_asn = 3;
1451 as_t as;
1452 int i;
718e3744 1453
d62a17ae 1454 for (i = idx_asn; i < argc; i++) {
1455 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1456
d62a17ae 1457 if (bgp->as == as) {
1458 vty_out(vty,
1459 "%% Local member-AS not allowed in confed peer list\n");
1460 continue;
1461 }
718e3744 1462
d62a17ae 1463 bgp_confederation_peers_add(bgp, as);
1464 }
1465 return CMD_SUCCESS;
718e3744 1466}
1467
1468DEFUN (no_bgp_confederation_peers,
1469 no_bgp_confederation_peers_cmd,
e83a9414 1470 "no bgp confederation peers (1-4294967295)...",
718e3744 1471 NO_STR
1472 "BGP specific commands\n"
1473 "AS confederation parameters\n"
1474 "Peer ASs in BGP confederation\n"
1475 AS_STR)
1476{
d62a17ae 1477 VTY_DECLVAR_CONTEXT(bgp, bgp);
1478 int idx_asn = 4;
1479 as_t as;
1480 int i;
718e3744 1481
d62a17ae 1482 for (i = idx_asn; i < argc; i++) {
1483 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1484
d62a17ae 1485 bgp_confederation_peers_remove(bgp, as);
1486 }
1487 return CMD_SUCCESS;
718e3744 1488}
6b0655a2 1489
5e242b0d
DS
1490/**
1491 * Central routine for maximum-paths configuration.
1492 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1493 * @set: 1 for setting values, 0 for removing the max-paths config.
1494 */
d62a17ae 1495static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1496 const char *mpaths, uint16_t options,
d62a17ae 1497 int set)
1498{
1499 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1500 uint16_t maxpaths = 0;
d62a17ae 1501 int ret;
1502 afi_t afi;
1503 safi_t safi;
1504
1505 afi = bgp_node_afi(vty);
1506 safi = bgp_node_safi(vty);
1507
1508 if (set) {
1509 maxpaths = strtol(mpaths, NULL, 10);
1510 if (maxpaths > multipath_num) {
1511 vty_out(vty,
1512 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1513 maxpaths, multipath_num);
1514 return CMD_WARNING_CONFIG_FAILED;
1515 }
1516 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1517 options);
1518 } else
1519 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1520
1521 if (ret < 0) {
1522 vty_out(vty,
1523 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1524 (set == 1) ? "" : "un",
1525 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1526 maxpaths, afi, safi);
1527 return CMD_WARNING_CONFIG_FAILED;
1528 }
1529
1530 bgp_recalculate_all_bestpaths(bgp);
1531
1532 return CMD_SUCCESS;
165b5fff
JB
1533}
1534
abc920f8
DS
1535DEFUN (bgp_maxmed_admin,
1536 bgp_maxmed_admin_cmd,
1537 "bgp max-med administrative ",
1538 BGP_STR
1539 "Advertise routes with max-med\n"
1540 "Administratively applied, for an indefinite period\n")
1541{
d62a17ae 1542 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1543
d62a17ae 1544 bgp->v_maxmed_admin = 1;
1545 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1546
d62a17ae 1547 bgp_maxmed_update(bgp);
abc920f8 1548
d62a17ae 1549 return CMD_SUCCESS;
abc920f8
DS
1550}
1551
1552DEFUN (bgp_maxmed_admin_medv,
1553 bgp_maxmed_admin_medv_cmd,
4668a151 1554 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1555 BGP_STR
1556 "Advertise routes with max-med\n"
1557 "Administratively applied, for an indefinite period\n"
1558 "Max MED value to be used\n")
1559{
d62a17ae 1560 VTY_DECLVAR_CONTEXT(bgp, bgp);
1561 int idx_number = 3;
abc920f8 1562
d62a17ae 1563 bgp->v_maxmed_admin = 1;
1564 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1565
d62a17ae 1566 bgp_maxmed_update(bgp);
abc920f8 1567
d62a17ae 1568 return CMD_SUCCESS;
abc920f8
DS
1569}
1570
1571DEFUN (no_bgp_maxmed_admin,
1572 no_bgp_maxmed_admin_cmd,
4668a151 1573 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1574 NO_STR
1575 BGP_STR
1576 "Advertise routes with max-med\n"
838758ac
DW
1577 "Administratively applied, for an indefinite period\n"
1578 "Max MED value to be used\n")
abc920f8 1579{
d62a17ae 1580 VTY_DECLVAR_CONTEXT(bgp, bgp);
1581 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1582 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1583 bgp_maxmed_update(bgp);
abc920f8 1584
d62a17ae 1585 return CMD_SUCCESS;
abc920f8
DS
1586}
1587
abc920f8
DS
1588DEFUN (bgp_maxmed_onstartup,
1589 bgp_maxmed_onstartup_cmd,
4668a151 1590 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1591 BGP_STR
1592 "Advertise routes with max-med\n"
1593 "Effective on a startup\n"
1594 "Time (seconds) period for max-med\n"
1595 "Max MED value to be used\n")
1596{
d62a17ae 1597 VTY_DECLVAR_CONTEXT(bgp, bgp);
1598 int idx = 0;
4668a151 1599
d62a17ae 1600 argv_find(argv, argc, "(5-86400)", &idx);
1601 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1602 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1603 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1604 else
1605 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1606
d62a17ae 1607 bgp_maxmed_update(bgp);
abc920f8 1608
d62a17ae 1609 return CMD_SUCCESS;
abc920f8
DS
1610}
1611
1612DEFUN (no_bgp_maxmed_onstartup,
1613 no_bgp_maxmed_onstartup_cmd,
4668a151 1614 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1615 NO_STR
1616 BGP_STR
1617 "Advertise routes with max-med\n"
838758ac
DW
1618 "Effective on a startup\n"
1619 "Time (seconds) period for max-med\n"
1620 "Max MED value to be used\n")
abc920f8 1621{
d62a17ae 1622 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1623
d62a17ae 1624 /* Cancel max-med onstartup if its on */
1625 if (bgp->t_maxmed_onstartup) {
1626 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1627 bgp->maxmed_onstartup_over = 1;
1628 }
abc920f8 1629
d62a17ae 1630 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1631 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1632
d62a17ae 1633 bgp_maxmed_update(bgp);
abc920f8 1634
d62a17ae 1635 return CMD_SUCCESS;
abc920f8
DS
1636}
1637
d62a17ae 1638static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1639 const char *wait)
f188f2c4 1640{
d62a17ae 1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a
QY
1642 uint16_t update_delay;
1643 uint16_t establish_wait;
f188f2c4 1644
d62a17ae 1645 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1646
d62a17ae 1647 if (!wait) /* update-delay <delay> */
1648 {
1649 bgp->v_update_delay = update_delay;
1650 bgp->v_establish_wait = bgp->v_update_delay;
1651 return CMD_SUCCESS;
1652 }
f188f2c4 1653
d62a17ae 1654 /* update-delay <delay> <establish-wait> */
1655 establish_wait = atoi(wait);
1656 if (update_delay < establish_wait) {
1657 vty_out(vty,
1658 "%%Failed: update-delay less than the establish-wait!\n");
1659 return CMD_WARNING_CONFIG_FAILED;
1660 }
f188f2c4 1661
d62a17ae 1662 bgp->v_update_delay = update_delay;
1663 bgp->v_establish_wait = establish_wait;
f188f2c4 1664
d62a17ae 1665 return CMD_SUCCESS;
f188f2c4
DS
1666}
1667
d62a17ae 1668static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1669{
d62a17ae 1670 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1671
d62a17ae 1672 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1673 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1674
d62a17ae 1675 return CMD_SUCCESS;
f188f2c4
DS
1676}
1677
2b791107 1678void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1679{
d62a17ae 1680 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1681 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1682 if (bgp->v_update_delay != bgp->v_establish_wait)
1683 vty_out(vty, " %d", bgp->v_establish_wait);
1684 vty_out(vty, "\n");
1685 }
f188f2c4
DS
1686}
1687
1688
1689/* Update-delay configuration */
1690DEFUN (bgp_update_delay,
1691 bgp_update_delay_cmd,
6147e2c6 1692 "update-delay (0-3600)",
f188f2c4
DS
1693 "Force initial delay for best-path and updates\n"
1694 "Seconds\n")
1695{
d62a17ae 1696 int idx_number = 1;
1697 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1698}
1699
1700DEFUN (bgp_update_delay_establish_wait,
1701 bgp_update_delay_establish_wait_cmd,
6147e2c6 1702 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1703 "Force initial delay for best-path and updates\n"
1704 "Seconds\n"
f188f2c4
DS
1705 "Seconds\n")
1706{
d62a17ae 1707 int idx_number = 1;
1708 int idx_number_2 = 2;
1709 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1710 argv[idx_number_2]->arg);
f188f2c4
DS
1711}
1712
1713/* Update-delay deconfiguration */
1714DEFUN (no_bgp_update_delay,
1715 no_bgp_update_delay_cmd,
838758ac
DW
1716 "no update-delay [(0-3600) [(1-3600)]]",
1717 NO_STR
f188f2c4 1718 "Force initial delay for best-path and updates\n"
838758ac 1719 "Seconds\n"
7111c1a0 1720 "Seconds\n")
f188f2c4 1721{
d62a17ae 1722 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1723}
1724
5e242b0d 1725
8fa7732f
QY
1726static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1727 bool set)
cb1faec9 1728{
d62a17ae 1729 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1730
8fa7732f
QY
1731 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1732 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1733
1734 return CMD_SUCCESS;
1735}
1736
8fa7732f
QY
1737static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
1738 bool set)
555e09d4
QY
1739{
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741
8fa7732f
QY
1742 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1743 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1744
d62a17ae 1745 return CMD_SUCCESS;
cb1faec9
DS
1746}
1747
2b791107 1748void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1749{
555e09d4
QY
1750 uint32_t quanta =
1751 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1752 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1753 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1754}
1755
555e09d4
QY
1756void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1757{
1758 uint32_t quanta =
1759 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1760 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1761 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1762}
cb1faec9 1763
8fa7732f
QY
1764/* Packet quanta configuration
1765 *
1766 * XXX: The value set here controls the size of a stack buffer in the IO
1767 * thread. When changing these limits be careful to prevent stack overflow.
1768 *
1769 * Furthermore, the maximums used here should correspond to
1770 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1771 */
1772DEFPY (bgp_wpkt_quanta,
cb1faec9 1773 bgp_wpkt_quanta_cmd,
8fa7732f 1774 "[no] write-quanta (1-64)$quanta",
d7fa34c1 1775 NO_STR
8fa7732f 1776 "How many packets to write to peer socket per run\n"
cb1faec9
DS
1777 "Number of packets\n")
1778{
8fa7732f 1779 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
cb1faec9
DS
1780}
1781
8fa7732f 1782DEFPY (bgp_rpkt_quanta,
555e09d4 1783 bgp_rpkt_quanta_cmd,
8fa7732f 1784 "[no] read-quanta (1-10)$quanta",
555e09d4
QY
1785 NO_STR
1786 "How many packets to read from peer socket per I/O cycle\n"
1787 "Number of packets\n")
1788{
8fa7732f 1789 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
1790}
1791
2b791107 1792void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1793{
37a333fe 1794 if (!bgp->heuristic_coalesce)
d62a17ae 1795 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1796}
1797
1798
1799DEFUN (bgp_coalesce_time,
1800 bgp_coalesce_time_cmd,
6147e2c6 1801 "coalesce-time (0-4294967295)",
3f9c7369
DS
1802 "Subgroup coalesce timer\n"
1803 "Subgroup coalesce timer value (in ms)\n")
1804{
d62a17ae 1805 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1806
d62a17ae 1807 int idx = 0;
1808 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1809 bgp->heuristic_coalesce = false;
d62a17ae 1810 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1811 return CMD_SUCCESS;
3f9c7369
DS
1812}
1813
1814DEFUN (no_bgp_coalesce_time,
1815 no_bgp_coalesce_time_cmd,
6147e2c6 1816 "no coalesce-time (0-4294967295)",
3a2d747c 1817 NO_STR
3f9c7369
DS
1818 "Subgroup coalesce timer\n"
1819 "Subgroup coalesce timer value (in ms)\n")
1820{
d62a17ae 1821 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1822
37a333fe 1823 bgp->heuristic_coalesce = true;
d62a17ae 1824 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1825 return CMD_SUCCESS;
3f9c7369
DS
1826}
1827
5e242b0d
DS
1828/* Maximum-paths configuration */
1829DEFUN (bgp_maxpaths,
1830 bgp_maxpaths_cmd,
6319fd63 1831 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1832 "Forward packets over multiple paths\n"
1833 "Number of paths\n")
1834{
d62a17ae 1835 int idx_number = 1;
1836 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1837 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1838}
1839
d62a17ae 1840ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1841 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1842 "Forward packets over multiple paths\n"
1843 "Number of paths\n")
596c17ba 1844
165b5fff
JB
1845DEFUN (bgp_maxpaths_ibgp,
1846 bgp_maxpaths_ibgp_cmd,
6319fd63 1847 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1848 "Forward packets over multiple paths\n"
1849 "iBGP-multipath\n"
1850 "Number of paths\n")
1851{
d62a17ae 1852 int idx_number = 2;
1853 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1854 argv[idx_number]->arg, 0, 1);
5e242b0d 1855}
165b5fff 1856
d62a17ae 1857ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1858 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1859 "Forward packets over multiple paths\n"
1860 "iBGP-multipath\n"
1861 "Number of paths\n")
596c17ba 1862
5e242b0d
DS
1863DEFUN (bgp_maxpaths_ibgp_cluster,
1864 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1865 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1866 "Forward packets over multiple paths\n"
1867 "iBGP-multipath\n"
1868 "Number of paths\n"
1869 "Match the cluster length\n")
1870{
d62a17ae 1871 int idx_number = 2;
1872 return bgp_maxpaths_config_vty(
1873 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1874 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1875}
1876
d62a17ae 1877ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1878 "maximum-paths ibgp " CMD_RANGE_STR(
1879 1, MULTIPATH_NUM) " equal-cluster-length",
1880 "Forward packets over multiple paths\n"
1881 "iBGP-multipath\n"
1882 "Number of paths\n"
1883 "Match the cluster length\n")
596c17ba 1884
165b5fff
JB
1885DEFUN (no_bgp_maxpaths,
1886 no_bgp_maxpaths_cmd,
6319fd63 1887 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1888 NO_STR
1889 "Forward packets over multiple paths\n"
1890 "Number of paths\n")
1891{
d62a17ae 1892 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1893}
1894
d62a17ae 1895ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1896 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1897 "Forward packets over multiple paths\n"
1898 "Number of paths\n")
596c17ba 1899
165b5fff
JB
1900DEFUN (no_bgp_maxpaths_ibgp,
1901 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1902 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1903 NO_STR
1904 "Forward packets over multiple paths\n"
1905 "iBGP-multipath\n"
838758ac
DW
1906 "Number of paths\n"
1907 "Match the cluster length\n")
165b5fff 1908{
d62a17ae 1909 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1910}
1911
d62a17ae 1912ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1913 "no maximum-paths ibgp [" CMD_RANGE_STR(
1914 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1915 NO_STR
1916 "Forward packets over multiple paths\n"
1917 "iBGP-multipath\n"
1918 "Number of paths\n"
1919 "Match the cluster length\n")
596c17ba 1920
dd65f45e
DL
1921static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
1922 afi_t afi, safi_t safi)
165b5fff 1923{
d62a17ae 1924 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1925 vty_out(vty, " maximum-paths %d\n",
1926 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1927 }
165b5fff 1928
d62a17ae 1929 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1930 vty_out(vty, " maximum-paths ibgp %d",
1931 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1932 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1933 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1934 vty_out(vty, " equal-cluster-length");
1935 vty_out(vty, "\n");
1936 }
165b5fff 1937}
6b0655a2 1938
718e3744 1939/* BGP timers. */
1940
1941DEFUN (bgp_timers,
1942 bgp_timers_cmd,
6147e2c6 1943 "timers bgp (0-65535) (0-65535)",
718e3744 1944 "Adjust routing timers\n"
1945 "BGP timers\n"
1946 "Keepalive interval\n"
1947 "Holdtime\n")
1948{
d62a17ae 1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
1950 int idx_number = 2;
1951 int idx_number_2 = 3;
1952 unsigned long keepalive = 0;
1953 unsigned long holdtime = 0;
718e3744 1954
d62a17ae 1955 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1956 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1957
d62a17ae 1958 /* Holdtime value check. */
1959 if (holdtime < 3 && holdtime != 0) {
1960 vty_out(vty,
1961 "%% hold time value must be either 0 or greater than 3\n");
1962 return CMD_WARNING_CONFIG_FAILED;
1963 }
718e3744 1964
5d5393b9 1965 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY);
718e3744 1966
d62a17ae 1967 return CMD_SUCCESS;
718e3744 1968}
1969
1970DEFUN (no_bgp_timers,
1971 no_bgp_timers_cmd,
838758ac 1972 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1973 NO_STR
1974 "Adjust routing timers\n"
838758ac
DW
1975 "BGP timers\n"
1976 "Keepalive interval\n"
1977 "Holdtime\n")
718e3744 1978{
d62a17ae 1979 VTY_DECLVAR_CONTEXT(bgp, bgp);
5d5393b9
DL
1980 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
1981 DFLT_BGP_CONNECT_RETRY);
718e3744 1982
d62a17ae 1983 return CMD_SUCCESS;
718e3744 1984}
1985
6b0655a2 1986
718e3744 1987DEFUN (bgp_client_to_client_reflection,
1988 bgp_client_to_client_reflection_cmd,
1989 "bgp client-to-client reflection",
1990 "BGP specific commands\n"
1991 "Configure client to client route reflection\n"
1992 "reflection of routes allowed\n")
1993{
d62a17ae 1994 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 1995 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 1996 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1997
d62a17ae 1998 return CMD_SUCCESS;
718e3744 1999}
2000
2001DEFUN (no_bgp_client_to_client_reflection,
2002 no_bgp_client_to_client_reflection_cmd,
2003 "no bgp client-to-client reflection",
2004 NO_STR
2005 "BGP specific commands\n"
2006 "Configure client to client route reflection\n"
2007 "reflection of routes allowed\n")
2008{
d62a17ae 2009 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2010 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
d62a17ae 2011 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2012
d62a17ae 2013 return CMD_SUCCESS;
718e3744 2014}
2015
2016/* "bgp always-compare-med" configuration. */
2017DEFUN (bgp_always_compare_med,
2018 bgp_always_compare_med_cmd,
2019 "bgp always-compare-med",
2020 "BGP specific commands\n"
2021 "Allow comparing MED from different neighbors\n")
2022{
d62a17ae 2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2024 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2025 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2026
d62a17ae 2027 return CMD_SUCCESS;
718e3744 2028}
2029
2030DEFUN (no_bgp_always_compare_med,
2031 no_bgp_always_compare_med_cmd,
2032 "no bgp always-compare-med",
2033 NO_STR
2034 "BGP specific commands\n"
2035 "Allow comparing MED from different neighbors\n")
2036{
d62a17ae 2037 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2038 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
d62a17ae 2039 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2040
d62a17ae 2041 return CMD_SUCCESS;
718e3744 2042}
6b0655a2 2043
9dac9fc8
DA
2044
2045DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2046 "bgp ebgp-requires-policy",
2047 "BGP specific commands\n"
2048 "Require in and out policy for eBGP peers (RFC8212)\n")
2049{
2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
2052 return CMD_SUCCESS;
2053}
2054
2055DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2056 "no bgp ebgp-requires-policy",
2057 NO_STR
2058 "BGP specific commands\n"
2059 "Require in and out policy for eBGP peers (RFC8212)\n")
2060{
2061 VTY_DECLVAR_CONTEXT(bgp, bgp);
2062 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
2063 return CMD_SUCCESS;
2064}
2065
fb29348a
DA
2066DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2067 "bgp reject-as-sets",
2068 "BGP specific commands\n"
2069 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2070{
2071 VTY_DECLVAR_CONTEXT(bgp, bgp);
2072 struct listnode *node, *nnode;
2073 struct peer *peer;
2074
2075 bgp->reject_as_sets = BGP_REJECT_AS_SETS_ENABLED;
2076
2077 /* Reset existing BGP sessions to reject routes
2078 * with aspath containing AS_SET or AS_CONFED_SET.
2079 */
2080 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2081 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2082 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2083 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2084 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2085 }
2086 }
2087
2088 return CMD_SUCCESS;
2089}
2090
2091DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2092 "no bgp reject-as-sets",
2093 NO_STR
2094 "BGP specific commands\n"
2095 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2096{
2097 VTY_DECLVAR_CONTEXT(bgp, bgp);
2098 struct listnode *node, *nnode;
2099 struct peer *peer;
2100
2101 bgp->reject_as_sets = BGP_REJECT_AS_SETS_DISABLED;
2102
2103 /* Reset existing BGP sessions to reject routes
2104 * with aspath containing AS_SET or AS_CONFED_SET.
2105 */
2106 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2107 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2108 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2109 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2110 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2111 }
2112 }
2113
2114 return CMD_SUCCESS;
2115}
9dac9fc8 2116
718e3744 2117/* "bgp deterministic-med" configuration. */
2118DEFUN (bgp_deterministic_med,
2119 bgp_deterministic_med_cmd,
2120 "bgp deterministic-med",
2121 "BGP specific commands\n"
2122 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2123{
d62a17ae 2124 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 2125
892fedb6
DA
2126 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2127 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2128 bgp_recalculate_all_bestpaths(bgp);
2129 }
7aafcaca 2130
d62a17ae 2131 return CMD_SUCCESS;
718e3744 2132}
2133
2134DEFUN (no_bgp_deterministic_med,
2135 no_bgp_deterministic_med_cmd,
2136 "no bgp deterministic-med",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2140{
d62a17ae 2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
2142 int bestpath_per_as_used;
2143 afi_t afi;
2144 safi_t safi;
2145 struct peer *peer;
2146 struct listnode *node, *nnode;
2147
892fedb6 2148 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
d62a17ae 2149 bestpath_per_as_used = 0;
2150
2151 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc 2152 FOREACH_AFI_SAFI (afi, safi)
dcc68b5e
MS
2153 if (bgp_addpath_dmed_required(
2154 peer->addpath_type[afi][safi])) {
05c7a1cc
QY
2155 bestpath_per_as_used = 1;
2156 break;
2157 }
d62a17ae 2158
2159 if (bestpath_per_as_used)
2160 break;
2161 }
2162
2163 if (bestpath_per_as_used) {
2164 vty_out(vty,
2165 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2166 return CMD_WARNING_CONFIG_FAILED;
2167 } else {
892fedb6 2168 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
d62a17ae 2169 bgp_recalculate_all_bestpaths(bgp);
2170 }
2171 }
2172
2173 return CMD_SUCCESS;
718e3744 2174}
538621f2 2175
055679e9 2176/* "bgp graceful-restart mode" configuration. */
538621f2 2177DEFUN (bgp_graceful_restart,
2ba1fe69 2178 bgp_graceful_restart_cmd,
2179 "bgp graceful-restart",
2180 "BGP specific commands\n"
2181 GR_CMD
055679e9 2182 )
538621f2 2183{
055679e9 2184 int ret = BGP_GR_FAILURE;
2185
2186 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2187 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2188
d62a17ae 2189 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2190
2191 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2192
36235319
QY
2193 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2194 ret);
5cce3f05 2195
055679e9 2196 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2197 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2198 vty_out(vty,
2199 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2200 return bgp_vty_return(vty, ret);
538621f2 2201}
2202
2203DEFUN (no_bgp_graceful_restart,
2ba1fe69 2204 no_bgp_graceful_restart_cmd,
2205 "no bgp graceful-restart",
2206 NO_STR
2207 "BGP specific commands\n"
2208 NO_GR_CMD
055679e9 2209 )
538621f2 2210{
d62a17ae 2211 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2212
2213 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2214 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2215
2216 int ret = BGP_GR_FAILURE;
2217
2218 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2219
36235319
QY
2220 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2221 ret);
5cce3f05 2222
055679e9 2223 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2224 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2225 vty_out(vty,
2226 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2227
2228 return bgp_vty_return(vty, ret);
538621f2 2229}
2230
93406d87 2231DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2232 bgp_graceful_restart_stalepath_time_cmd,
2233 "bgp graceful-restart stalepath-time (1-4095)",
2234 "BGP specific commands\n"
2235 "Graceful restart capability parameters\n"
2236 "Set the max time to hold onto restarting peer's stale paths\n"
2237 "Delay value (seconds)\n")
93406d87 2238{
d62a17ae 2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240 int idx_number = 3;
d7c0a89a 2241 uint32_t stalepath;
93406d87 2242
d62a17ae 2243 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2244 bgp->stalepath_time = stalepath;
2245 return CMD_SUCCESS;
93406d87 2246}
2247
eb6f1b41 2248DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2249 bgp_graceful_restart_restart_time_cmd,
2250 "bgp graceful-restart restart-time (1-4095)",
2251 "BGP specific commands\n"
2252 "Graceful restart capability parameters\n"
2253 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2254 "Delay value (seconds)\n")
eb6f1b41 2255{
d62a17ae 2256 VTY_DECLVAR_CONTEXT(bgp, bgp);
2257 int idx_number = 3;
d7c0a89a 2258 uint32_t restart;
eb6f1b41 2259
d62a17ae 2260 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2261 bgp->restart_time = restart;
2262 return CMD_SUCCESS;
eb6f1b41
PG
2263}
2264
cfd47646 2265DEFUN (bgp_graceful_restart_select_defer_time,
2266 bgp_graceful_restart_select_defer_time_cmd,
2267 "bgp graceful-restart select-defer-time (0-3600)",
2268 "BGP specific commands\n"
2269 "Graceful restart capability parameters\n"
2270 "Set the time to defer the BGP route selection after restart\n"
2271 "Delay value (seconds, 0 - disable)\n")
2272{
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 int idx_number = 3;
2275 uint32_t defer_time;
2276
2277 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2278 bgp->select_defer_time = defer_time;
2279 if (defer_time == 0)
892fedb6 2280 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2281 else
892fedb6 2282 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2283
2284 return CMD_SUCCESS;
2285}
2286
93406d87 2287DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2288 no_bgp_graceful_restart_stalepath_time_cmd,
2289 "no bgp graceful-restart stalepath-time [(1-4095)]",
2290 NO_STR
2291 "BGP specific commands\n"
2292 "Graceful restart capability parameters\n"
2293 "Set the max time to hold onto restarting peer's stale paths\n"
2294 "Delay value (seconds)\n")
93406d87 2295{
d62a17ae 2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2297
d62a17ae 2298 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2299 return CMD_SUCCESS;
93406d87 2300}
2301
eb6f1b41 2302DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2303 no_bgp_graceful_restart_restart_time_cmd,
2304 "no bgp graceful-restart restart-time [(1-4095)]",
2305 NO_STR
2306 "BGP specific commands\n"
2307 "Graceful restart capability parameters\n"
2308 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2309 "Delay value (seconds)\n")
eb6f1b41 2310{
d62a17ae 2311 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2312
d62a17ae 2313 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2314 return CMD_SUCCESS;
eb6f1b41
PG
2315}
2316
cfd47646 2317DEFUN (no_bgp_graceful_restart_select_defer_time,
2318 no_bgp_graceful_restart_select_defer_time_cmd,
2319 "no bgp graceful-restart select-defer-time [(0-3600)]",
2320 NO_STR
2321 "BGP specific commands\n"
2322 "Graceful restart capability parameters\n"
2323 "Set the time to defer the BGP route selection after restart\n"
2324 "Delay value (seconds)\n")
2325{
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327
2328 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2329 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2330
2331 return CMD_SUCCESS;
2332}
2333
43fc21b3 2334DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2335 bgp_graceful_restart_preserve_fw_cmd,
2336 "bgp graceful-restart preserve-fw-state",
2337 "BGP specific commands\n"
2338 "Graceful restart capability parameters\n"
2339 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2340{
d62a17ae 2341 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2342 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2343 return CMD_SUCCESS;
43fc21b3
JC
2344}
2345
2346DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2347 no_bgp_graceful_restart_preserve_fw_cmd,
2348 "no bgp graceful-restart preserve-fw-state",
2349 NO_STR
2350 "BGP specific commands\n"
2351 "Graceful restart capability parameters\n"
2352 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2353{
d62a17ae 2354 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2355 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2356 return CMD_SUCCESS;
43fc21b3
JC
2357}
2358
055679e9 2359DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2360 bgp_graceful_restart_disable_cmd,
2361 "bgp graceful-restart-disable",
2362 "BGP specific commands\n"
2363 GR_DISABLE)
055679e9 2364{
2365 int ret = BGP_GR_FAILURE;
2366
2367 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2368 zlog_debug(
2ba1fe69 2369 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2370
055679e9 2371 VTY_DECLVAR_CONTEXT(bgp, bgp);
2372
2373 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2374
dc95985f 2375 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2376 bgp->peer, ret);
5cce3f05 2377
055679e9 2378 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2379 zlog_debug(
2ba1fe69 2380 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2381 vty_out(vty,
2382 "Graceful restart configuration changed, reset all peers to take effect\n");
2383
055679e9 2384 return bgp_vty_return(vty, ret);
2385}
2386
2387DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2388 no_bgp_graceful_restart_disable_cmd,
2389 "no bgp graceful-restart-disable",
2390 NO_STR
2391 "BGP specific commands\n"
2392 NO_GR_DISABLE
055679e9 2393 )
2394{
2395 VTY_DECLVAR_CONTEXT(bgp, bgp);
2396
2397 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2398 zlog_debug(
2ba1fe69 2399 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2400
2401 int ret = BGP_GR_FAILURE;
2402
2403 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2404
36235319
QY
2405 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2406 ret);
5cce3f05 2407
055679e9 2408 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2409 zlog_debug(
2ba1fe69 2410 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2411 vty_out(vty,
2412 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2413
2414 return bgp_vty_return(vty, ret);
2415}
2416
2417DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2418 bgp_neighbor_graceful_restart_set_cmd,
2419 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2420 NEIGHBOR_STR
2421 NEIGHBOR_ADDR_STR2
2422 GR_NEIGHBOR_CMD
055679e9 2423 )
2424{
2425 int idx_peer = 1;
2426 struct peer *peer;
2427 int ret = BGP_GR_FAILURE;
2428
dc95985f 2429 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2430
055679e9 2431 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2432 zlog_debug(
2ba1fe69 2433 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2434
055679e9 2435 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2436 if (!peer)
2437 return CMD_WARNING_CONFIG_FAILED;
2438
2439 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2440
dc95985f 2441 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2442 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2443
2444 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2445 zlog_debug(
2ba1fe69 2446 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2447 vty_out(vty,
2448 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2449
2450 return bgp_vty_return(vty, ret);
2451}
2452
2453DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2454 no_bgp_neighbor_graceful_restart_set_cmd,
2455 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2456 NO_STR
2457 NEIGHBOR_STR
2458 NEIGHBOR_ADDR_STR2
2459 NO_GR_NEIGHBOR_CMD
055679e9 2460 )
2461{
2462 int idx_peer = 2;
2463 int ret = BGP_GR_FAILURE;
2464 struct peer *peer;
2465
dc95985f 2466 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2467
055679e9 2468 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2469 if (!peer)
2470 return CMD_WARNING_CONFIG_FAILED;
2471
2472 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2473 zlog_debug(
2ba1fe69 2474 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2475
2476 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2477
dc95985f 2478 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2479 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2480
2481 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2482 zlog_debug(
2ba1fe69 2483 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2484 vty_out(vty,
2485 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2486
2487 return bgp_vty_return(vty, ret);
2488}
2489
2490DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2491 bgp_neighbor_graceful_restart_helper_set_cmd,
2492 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2493 NEIGHBOR_STR
2494 NEIGHBOR_ADDR_STR2
2495 GR_NEIGHBOR_HELPER_CMD
055679e9 2496 )
2497{
2498 int idx_peer = 1;
2499 struct peer *peer;
2500 int ret = BGP_GR_FAILURE;
2501
dc95985f 2502 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2503
055679e9 2504 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2505 zlog_debug(
2ba1fe69 2506 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2507
055679e9 2508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2509
055679e9 2510 if (!peer)
2511 return CMD_WARNING_CONFIG_FAILED;
2512
2513
2514 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2515
dc95985f 2516 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2517 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2518
055679e9 2519 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2520 zlog_debug(
2ba1fe69 2521 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2522 vty_out(vty,
2523 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2524
2525 return bgp_vty_return(vty, ret);
2526}
2527
2528DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2529 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2530 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2531 NO_STR
2532 NEIGHBOR_STR
2533 NEIGHBOR_ADDR_STR2
2534 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2535 )
2536{
2537 int idx_peer = 2;
2538 int ret = BGP_GR_FAILURE;
2539 struct peer *peer;
2540
dc95985f 2541 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2542
055679e9 2543 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2544 if (!peer)
2545 return CMD_WARNING_CONFIG_FAILED;
2546
2547 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2548 zlog_debug(
2ba1fe69 2549 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2550
36235319 2551 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2552
dc95985f 2553 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2554 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2555
2556 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2557 zlog_debug(
2ba1fe69 2558 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2559 vty_out(vty,
2560 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2561
2562 return bgp_vty_return(vty, ret);
2563}
2564
2565DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2566 bgp_neighbor_graceful_restart_disable_set_cmd,
2567 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2568 NEIGHBOR_STR
2569 NEIGHBOR_ADDR_STR2
2570 GR_NEIGHBOR_DISABLE_CMD
055679e9 2571 )
2572{
2573 int idx_peer = 1;
2574 struct peer *peer;
2575 int ret = BGP_GR_FAILURE;
2576
dc95985f 2577 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2578
055679e9 2579 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2580 zlog_debug(
2ba1fe69 2581 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2582
2583 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2584 if (!peer)
2585 return CMD_WARNING_CONFIG_FAILED;
2586
36235319 2587 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2588
2589 if (peer->bgp->t_startup)
2590 bgp_peer_gr_flags_update(peer);
2591
dc95985f 2592 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2593 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2594
055679e9 2595 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2596 zlog_debug(
2ba1fe69 2597 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2598 vty_out(vty,
2599 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2600
2601 return bgp_vty_return(vty, ret);
2602}
2603
2604DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2605 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2606 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2607 NO_STR
2608 NEIGHBOR_STR
2609 NEIGHBOR_ADDR_STR2
2610 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2611 )
2612{
2613 int idx_peer = 2;
2614 int ret = BGP_GR_FAILURE;
2615 struct peer *peer;
2616
dc95985f 2617 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2618
055679e9 2619 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2620 if (!peer)
2621 return CMD_WARNING_CONFIG_FAILED;
2622
2623 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2624 zlog_debug(
2ba1fe69 2625 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2626
2627 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2628
dc95985f 2629 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2630 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2631
2632 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2633 zlog_debug(
2ba1fe69 2634 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2635 vty_out(vty,
2636 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2637
2638 return bgp_vty_return(vty, ret);
2639}
2640
d6e3c15b 2641DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2642 bgp_graceful_restart_disable_eor_cmd,
2643 "bgp graceful-restart disable-eor",
2644 "BGP specific commands\n"
2645 "Graceful restart configuration parameters\n"
2646 "Disable EOR Check\n")
2647{
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2649 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2650
d6e3c15b 2651 return CMD_SUCCESS;
2652}
2653
2654DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2655 no_bgp_graceful_restart_disable_eor_cmd,
2656 "no bgp graceful-restart disable-eor",
2657 NO_STR
2658 "BGP specific commands\n"
2659 "Graceful restart configuration parameters\n"
2660 "Disable EOR Check\n")
2661{
2662 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2663 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2664
2665 return CMD_SUCCESS;
2666}
2667
2668DEFUN (bgp_graceful_restart_rib_stale_time,
2669 bgp_graceful_restart_rib_stale_time_cmd,
2670 "bgp graceful-restart rib-stale-time (1-3600)",
2671 "BGP specific commands\n"
2672 "Graceful restart configuration parameters\n"
2673 "Specify the stale route removal timer in rib\n"
2674 "Delay value (seconds)\n")
2675{
2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
2677 int idx_number = 3;
2678 uint32_t stale_time;
2679
2680 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2681 bgp->rib_stale_time = stale_time;
2682 /* Send the stale timer update message to RIB */
2683 if (bgp_zebra_stale_timer_update(bgp))
2684 return CMD_WARNING;
2685
2686 return CMD_SUCCESS;
2687}
2688
2689DEFUN (no_bgp_graceful_restart_rib_stale_time,
2690 no_bgp_graceful_restart_rib_stale_time_cmd,
2691 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2692 NO_STR
2693 "BGP specific commands\n"
2694 "Graceful restart configuration parameters\n"
2695 "Specify the stale route removal timer in rib\n"
2696 "Delay value (seconds)\n")
2697{
2698 VTY_DECLVAR_CONTEXT(bgp, bgp);
2699
2700 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2701 /* Send the stale timer update message to RIB */
2702 if (bgp_zebra_stale_timer_update(bgp))
2703 return CMD_WARNING;
2704
d6e3c15b 2705 return CMD_SUCCESS;
2706}
2707
7f323236
DW
2708/* "bgp graceful-shutdown" configuration */
2709DEFUN (bgp_graceful_shutdown,
2710 bgp_graceful_shutdown_cmd,
2711 "bgp graceful-shutdown",
2712 BGP_STR
2713 "Graceful shutdown parameters\n")
2714{
2715 VTY_DECLVAR_CONTEXT(bgp, bgp);
2716
892fedb6
DA
2717 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2718 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2719 bgp_static_redo_import_check(bgp);
2720 bgp_redistribute_redo(bgp);
2721 bgp_clear_star_soft_out(vty, bgp->name);
2722 bgp_clear_star_soft_in(vty, bgp->name);
2723 }
2724
2725 return CMD_SUCCESS;
2726}
2727
2728DEFUN (no_bgp_graceful_shutdown,
2729 no_bgp_graceful_shutdown_cmd,
2730 "no bgp graceful-shutdown",
2731 NO_STR
2732 BGP_STR
2733 "Graceful shutdown parameters\n")
2734{
2735 VTY_DECLVAR_CONTEXT(bgp, bgp);
2736
892fedb6
DA
2737 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2738 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
7f323236
DW
2739 bgp_static_redo_import_check(bgp);
2740 bgp_redistribute_redo(bgp);
2741 bgp_clear_star_soft_out(vty, bgp->name);
2742 bgp_clear_star_soft_in(vty, bgp->name);
2743 }
2744
2745 return CMD_SUCCESS;
2746}
2747
718e3744 2748/* "bgp fast-external-failover" configuration. */
2749DEFUN (bgp_fast_external_failover,
2750 bgp_fast_external_failover_cmd,
2751 "bgp fast-external-failover",
2752 BGP_STR
2753 "Immediately reset session if a link to a directly connected external peer goes down\n")
2754{
d62a17ae 2755 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2756 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2757 return CMD_SUCCESS;
718e3744 2758}
2759
2760DEFUN (no_bgp_fast_external_failover,
2761 no_bgp_fast_external_failover_cmd,
2762 "no bgp fast-external-failover",
2763 NO_STR
2764 BGP_STR
2765 "Immediately reset session if a link to a directly connected external peer goes down\n")
2766{
d62a17ae 2767 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2768 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
d62a17ae 2769 return CMD_SUCCESS;
718e3744 2770}
6b0655a2 2771
718e3744 2772/* "bgp bestpath compare-routerid" configuration. */
2773DEFUN (bgp_bestpath_compare_router_id,
2774 bgp_bestpath_compare_router_id_cmd,
2775 "bgp bestpath compare-routerid",
2776 "BGP specific commands\n"
2777 "Change the default bestpath selection\n"
2778 "Compare router-id for identical EBGP paths\n")
2779{
d62a17ae 2780 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2781 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2782 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2783
d62a17ae 2784 return CMD_SUCCESS;
718e3744 2785}
2786
2787DEFUN (no_bgp_bestpath_compare_router_id,
2788 no_bgp_bestpath_compare_router_id_cmd,
2789 "no bgp bestpath compare-routerid",
2790 NO_STR
2791 "BGP specific commands\n"
2792 "Change the default bestpath selection\n"
2793 "Compare router-id for identical EBGP paths\n")
2794{
d62a17ae 2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2796 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
d62a17ae 2797 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2798
d62a17ae 2799 return CMD_SUCCESS;
718e3744 2800}
6b0655a2 2801
718e3744 2802/* "bgp bestpath as-path ignore" configuration. */
2803DEFUN (bgp_bestpath_aspath_ignore,
2804 bgp_bestpath_aspath_ignore_cmd,
2805 "bgp bestpath as-path ignore",
2806 "BGP specific commands\n"
2807 "Change the default bestpath selection\n"
2808 "AS-path attribute\n"
2809 "Ignore as-path length in selecting a route\n")
2810{
d62a17ae 2811 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2812 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2813 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2814
d62a17ae 2815 return CMD_SUCCESS;
718e3744 2816}
2817
2818DEFUN (no_bgp_bestpath_aspath_ignore,
2819 no_bgp_bestpath_aspath_ignore_cmd,
2820 "no bgp bestpath as-path ignore",
2821 NO_STR
2822 "BGP specific commands\n"
2823 "Change the default bestpath selection\n"
2824 "AS-path attribute\n"
2825 "Ignore as-path length in selecting a route\n")
2826{
d62a17ae 2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2828 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
d62a17ae 2829 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2830
d62a17ae 2831 return CMD_SUCCESS;
718e3744 2832}
6b0655a2 2833
6811845b 2834/* "bgp bestpath as-path confed" configuration. */
2835DEFUN (bgp_bestpath_aspath_confed,
2836 bgp_bestpath_aspath_confed_cmd,
2837 "bgp bestpath as-path confed",
2838 "BGP specific commands\n"
2839 "Change the default bestpath selection\n"
2840 "AS-path attribute\n"
2841 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2842{
d62a17ae 2843 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2844 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2845 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2846
d62a17ae 2847 return CMD_SUCCESS;
6811845b 2848}
2849
2850DEFUN (no_bgp_bestpath_aspath_confed,
2851 no_bgp_bestpath_aspath_confed_cmd,
2852 "no bgp bestpath as-path confed",
2853 NO_STR
2854 "BGP specific commands\n"
2855 "Change the default bestpath selection\n"
2856 "AS-path attribute\n"
2857 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2858{
d62a17ae 2859 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2860 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
d62a17ae 2861 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2862
d62a17ae 2863 return CMD_SUCCESS;
6811845b 2864}
6b0655a2 2865
2fdd455c
PM
2866/* "bgp bestpath as-path multipath-relax" configuration. */
2867DEFUN (bgp_bestpath_aspath_multipath_relax,
2868 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2869 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2870 "BGP specific commands\n"
2871 "Change the default bestpath selection\n"
2872 "AS-path attribute\n"
2873 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2874 "Generate an AS_SET\n"
16fc1eec
DS
2875 "Do not generate an AS_SET\n")
2876{
d62a17ae 2877 VTY_DECLVAR_CONTEXT(bgp, bgp);
2878 int idx = 0;
892fedb6 2879 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2880
d62a17ae 2881 /* no-as-set is now the default behavior so we can silently
2882 * ignore it */
2883 if (argv_find(argv, argc, "as-set", &idx))
892fedb6 2884 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2885 else
892fedb6 2886 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2887
d62a17ae 2888 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2889
d62a17ae 2890 return CMD_SUCCESS;
16fc1eec
DS
2891}
2892
219178b6
DW
2893DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2894 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2895 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2896 NO_STR
2897 "BGP specific commands\n"
2898 "Change the default bestpath selection\n"
2899 "AS-path attribute\n"
2900 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2901 "Generate an AS_SET\n"
16fc1eec
DS
2902 "Do not generate an AS_SET\n")
2903{
d62a17ae 2904 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
2905 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2906 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 2907 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2908
d62a17ae 2909 return CMD_SUCCESS;
2fdd455c 2910}
6b0655a2 2911
848973c7 2912/* "bgp log-neighbor-changes" configuration. */
2913DEFUN (bgp_log_neighbor_changes,
2914 bgp_log_neighbor_changes_cmd,
2915 "bgp log-neighbor-changes",
2916 "BGP specific commands\n"
2917 "Log neighbor up/down and reset reason\n")
2918{
d62a17ae 2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2920 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2921 return CMD_SUCCESS;
848973c7 2922}
2923
2924DEFUN (no_bgp_log_neighbor_changes,
2925 no_bgp_log_neighbor_changes_cmd,
2926 "no bgp log-neighbor-changes",
2927 NO_STR
2928 "BGP specific commands\n"
2929 "Log neighbor up/down and reset reason\n")
2930{
d62a17ae 2931 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2932 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
d62a17ae 2933 return CMD_SUCCESS;
848973c7 2934}
6b0655a2 2935
718e3744 2936/* "bgp bestpath med" configuration. */
2937DEFUN (bgp_bestpath_med,
2938 bgp_bestpath_med_cmd,
2d8c1a4d 2939 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2940 "BGP specific commands\n"
2941 "Change the default bestpath selection\n"
2942 "MED attribute\n"
2943 "Compare MED among confederation paths\n"
838758ac
DW
2944 "Treat missing MED as the least preferred one\n"
2945 "Treat missing MED as the least preferred one\n"
2946 "Compare MED among confederation paths\n")
718e3744 2947{
d62a17ae 2948 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2949
d62a17ae 2950 int idx = 0;
2951 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2952 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2953 idx = 0;
2954 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2955 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2956
d62a17ae 2957 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2958
d62a17ae 2959 return CMD_SUCCESS;
718e3744 2960}
2961
718e3744 2962DEFUN (no_bgp_bestpath_med,
2963 no_bgp_bestpath_med_cmd,
2d8c1a4d 2964 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2965 NO_STR
2966 "BGP specific commands\n"
2967 "Change the default bestpath selection\n"
2968 "MED attribute\n"
2969 "Compare MED among confederation paths\n"
3a2d747c
QY
2970 "Treat missing MED as the least preferred one\n"
2971 "Treat missing MED as the least preferred one\n"
2972 "Compare MED among confederation paths\n")
718e3744 2973{
d62a17ae 2974 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2975
d62a17ae 2976 int idx = 0;
2977 if (argv_find(argv, argc, "confed", &idx))
892fedb6 2978 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 2979 idx = 0;
2980 if (argv_find(argv, argc, "missing-as-worst", &idx))
892fedb6 2981 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2982
d62a17ae 2983 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2984
d62a17ae 2985 return CMD_SUCCESS;
718e3744 2986}
2987
718e3744 2988/* "no bgp default ipv4-unicast". */
2989DEFUN (no_bgp_default_ipv4_unicast,
2990 no_bgp_default_ipv4_unicast_cmd,
2991 "no bgp default ipv4-unicast",
2992 NO_STR
2993 "BGP specific commands\n"
2994 "Configure BGP defaults\n"
2995 "Activate ipv4-unicast for a peer by default\n")
2996{
d62a17ae 2997 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2998 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 2999 return CMD_SUCCESS;
718e3744 3000}
3001
3002DEFUN (bgp_default_ipv4_unicast,
3003 bgp_default_ipv4_unicast_cmd,
3004 "bgp default ipv4-unicast",
3005 "BGP specific commands\n"
3006 "Configure BGP defaults\n"
3007 "Activate ipv4-unicast for a peer by default\n")
3008{
d62a17ae 3009 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3010 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3011 return CMD_SUCCESS;
718e3744 3012}
6b0655a2 3013
04b6bdc0
DW
3014/* Display hostname in certain command outputs */
3015DEFUN (bgp_default_show_hostname,
3016 bgp_default_show_hostname_cmd,
3017 "bgp default show-hostname",
3018 "BGP specific commands\n"
3019 "Configure BGP defaults\n"
0437e105 3020 "Show hostname in certain command outputs\n")
04b6bdc0 3021{
d62a17ae 3022 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3023 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3024 return CMD_SUCCESS;
04b6bdc0
DW
3025}
3026
3027DEFUN (no_bgp_default_show_hostname,
3028 no_bgp_default_show_hostname_cmd,
3029 "no bgp default show-hostname",
3030 NO_STR
3031 "BGP specific commands\n"
3032 "Configure BGP defaults\n"
0437e105 3033 "Show hostname in certain command outputs\n")
04b6bdc0 3034{
d62a17ae 3035 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3036 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
d62a17ae 3037 return CMD_SUCCESS;
04b6bdc0
DW
3038}
3039
8233ef81 3040/* "bgp network import-check" configuration. */
718e3744 3041DEFUN (bgp_network_import_check,
3042 bgp_network_import_check_cmd,
5623e905 3043 "bgp network import-check",
718e3744 3044 "BGP specific commands\n"
3045 "BGP network command\n"
5623e905 3046 "Check BGP network route exists in IGP\n")
718e3744 3047{
d62a17ae 3048 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3049 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3050 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3051 bgp_static_redo_import_check(bgp);
3052 }
078430f6 3053
d62a17ae 3054 return CMD_SUCCESS;
718e3744 3055}
3056
d62a17ae 3057ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3058 "bgp network import-check exact",
3059 "BGP specific commands\n"
3060 "BGP network command\n"
3061 "Check BGP network route exists in IGP\n"
3062 "Match route precisely\n")
8233ef81 3063
718e3744 3064DEFUN (no_bgp_network_import_check,
3065 no_bgp_network_import_check_cmd,
5623e905 3066 "no bgp network import-check",
718e3744 3067 NO_STR
3068 "BGP specific commands\n"
3069 "BGP network command\n"
3070 "Check BGP network route exists in IGP\n")
3071{
d62a17ae 3072 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6
DA
3073 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3074 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
d62a17ae 3075 bgp_static_redo_import_check(bgp);
3076 }
5623e905 3077
d62a17ae 3078 return CMD_SUCCESS;
718e3744 3079}
6b0655a2 3080
718e3744 3081DEFUN (bgp_default_local_preference,
3082 bgp_default_local_preference_cmd,
6147e2c6 3083 "bgp default local-preference (0-4294967295)",
718e3744 3084 "BGP specific commands\n"
3085 "Configure BGP defaults\n"
3086 "local preference (higher=more preferred)\n"
3087 "Configure default local preference value\n")
3088{
d62a17ae 3089 VTY_DECLVAR_CONTEXT(bgp, bgp);
3090 int idx_number = 3;
d7c0a89a 3091 uint32_t local_pref;
718e3744 3092
d62a17ae 3093 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3094
d62a17ae 3095 bgp_default_local_preference_set(bgp, local_pref);
3096 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3097
d62a17ae 3098 return CMD_SUCCESS;
718e3744 3099}
3100
3101DEFUN (no_bgp_default_local_preference,
3102 no_bgp_default_local_preference_cmd,
838758ac 3103 "no bgp default local-preference [(0-4294967295)]",
718e3744 3104 NO_STR
3105 "BGP specific commands\n"
3106 "Configure BGP defaults\n"
838758ac
DW
3107 "local preference (higher=more preferred)\n"
3108 "Configure default local preference value\n")
718e3744 3109{
d62a17ae 3110 VTY_DECLVAR_CONTEXT(bgp, bgp);
3111 bgp_default_local_preference_unset(bgp);
3112 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3113
d62a17ae 3114 return CMD_SUCCESS;
718e3744 3115}
3116
6b0655a2 3117
3f9c7369
DS
3118DEFUN (bgp_default_subgroup_pkt_queue_max,
3119 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 3120 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
3121 "BGP specific commands\n"
3122 "Configure BGP defaults\n"
3123 "subgroup-pkt-queue-max\n"
3124 "Configure subgroup packet queue max\n")
8bd9d948 3125{
d62a17ae 3126 VTY_DECLVAR_CONTEXT(bgp, bgp);
3127 int idx_number = 3;
d7c0a89a 3128 uint32_t max_size;
8bd9d948 3129
d62a17ae 3130 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3131
d62a17ae 3132 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 3133
d62a17ae 3134 return CMD_SUCCESS;
3f9c7369
DS
3135}
3136
3137DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3138 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 3139 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
3140 NO_STR
3141 "BGP specific commands\n"
3142 "Configure BGP defaults\n"
838758ac
DW
3143 "subgroup-pkt-queue-max\n"
3144 "Configure subgroup packet queue max\n")
3f9c7369 3145{
d62a17ae 3146 VTY_DECLVAR_CONTEXT(bgp, bgp);
3147 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3148 return CMD_SUCCESS;
8bd9d948
DS
3149}
3150
813d4307 3151
8bd9d948
DS
3152DEFUN (bgp_rr_allow_outbound_policy,
3153 bgp_rr_allow_outbound_policy_cmd,
3154 "bgp route-reflector allow-outbound-policy",
3155 "BGP specific commands\n"
3156 "Allow modifications made by out route-map\n"
3157 "on ibgp neighbors\n")
3158{
d62a17ae 3159 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3160
892fedb6
DA
3161 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3162 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3163 update_group_announce_rrclients(bgp);
3164 bgp_clear_star_soft_out(vty, bgp->name);
3165 }
8bd9d948 3166
d62a17ae 3167 return CMD_SUCCESS;
8bd9d948
DS
3168}
3169
3170DEFUN (no_bgp_rr_allow_outbound_policy,
3171 no_bgp_rr_allow_outbound_policy_cmd,
3172 "no bgp route-reflector allow-outbound-policy",
3173 NO_STR
3174 "BGP specific commands\n"
3175 "Allow modifications made by out route-map\n"
3176 "on ibgp neighbors\n")
3177{
d62a17ae 3178 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3179
892fedb6
DA
3180 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3181 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
d62a17ae 3182 update_group_announce_rrclients(bgp);
3183 bgp_clear_star_soft_out(vty, bgp->name);
3184 }
8bd9d948 3185
d62a17ae 3186 return CMD_SUCCESS;
8bd9d948
DS
3187}
3188
f14e6fdb
DS
3189DEFUN (bgp_listen_limit,
3190 bgp_listen_limit_cmd,
9ccf14f7 3191 "bgp listen limit (1-5000)",
f14e6fdb 3192 "BGP specific commands\n"
1601a46f 3193 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3194 "Maximum number of BGP Dynamic Neighbors that can be created\n"
f14e6fdb
DS
3195 "Configure Dynamic Neighbors listen limit value\n")
3196{
d62a17ae 3197 VTY_DECLVAR_CONTEXT(bgp, bgp);
3198 int idx_number = 3;
3199 int listen_limit;
f14e6fdb 3200
d62a17ae 3201 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3202
d62a17ae 3203 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3204
d62a17ae 3205 return CMD_SUCCESS;
f14e6fdb
DS
3206}
3207
3208DEFUN (no_bgp_listen_limit,
3209 no_bgp_listen_limit_cmd,
838758ac 3210 "no bgp listen limit [(1-5000)]",
1601a46f 3211 NO_STR
f14e6fdb 3212 "BGP specific commands\n"
1601a46f 3213 "BGP Dynamic Neighbors listen commands\n"
85bb4595 3214 "Maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac 3215 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3216{
d62a17ae 3217 VTY_DECLVAR_CONTEXT(bgp, bgp);
3218 bgp_listen_limit_unset(bgp);
3219 return CMD_SUCCESS;
f14e6fdb
DS
3220}
3221
3222
20eb8864 3223/*
3224 * Check if this listen range is already configured. Check for exact
3225 * match or overlap based on input.
3226 */
d62a17ae 3227static struct peer_group *listen_range_exists(struct bgp *bgp,
3228 struct prefix *range, int exact)
3229{
3230 struct listnode *node, *nnode;
3231 struct listnode *node1, *nnode1;
3232 struct peer_group *group;
3233 struct prefix *lr;
3234 afi_t afi;
3235 int match;
3236
3237 afi = family2afi(range->family);
3238 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3239 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3240 lr)) {
3241 if (exact)
3242 match = prefix_same(range, lr);
3243 else
3244 match = (prefix_match(range, lr)
3245 || prefix_match(lr, range));
3246 if (match)
3247 return group;
3248 }
3249 }
3250
3251 return NULL;
20eb8864 3252}
3253
f14e6fdb
DS
3254DEFUN (bgp_listen_range,
3255 bgp_listen_range_cmd,
d7b9898c 3256 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3257 "BGP specific commands\n"
d7fa34c1
QY
3258 "Configure BGP dynamic neighbors listen range\n"
3259 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3260 NEIGHBOR_ADDR_STR
3261 "Member of the peer-group\n"
3262 "Peer-group name\n")
f14e6fdb 3263{
d62a17ae 3264 VTY_DECLVAR_CONTEXT(bgp, bgp);
3265 struct prefix range;
3266 struct peer_group *group, *existing_group;
3267 afi_t afi;
3268 int ret;
3269 int idx = 0;
3270
3271 argv_find(argv, argc, "A.B.C.D/M", &idx);
3272 argv_find(argv, argc, "X:X::X:X/M", &idx);
3273 char *prefix = argv[idx]->arg;
d7b9898c 3274 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3275 char *peergroup = argv[idx]->arg;
3276
3277 /* Convert IP prefix string to struct prefix. */
3278 ret = str2prefix(prefix, &range);
3279 if (!ret) {
3280 vty_out(vty, "%% Malformed listen range\n");
3281 return CMD_WARNING_CONFIG_FAILED;
3282 }
3283
3284 afi = family2afi(range.family);
3285
3286 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3287 vty_out(vty,
3288 "%% Malformed listen range (link-local address)\n");
3289 return CMD_WARNING_CONFIG_FAILED;
3290 }
3291
3292 apply_mask(&range);
3293
3294 /* Check if same listen range is already configured. */
3295 existing_group = listen_range_exists(bgp, &range, 1);
3296 if (existing_group) {
3297 if (strcmp(existing_group->name, peergroup) == 0)
3298 return CMD_SUCCESS;
3299 else {
3300 vty_out(vty,
3301 "%% Same listen range is attached to peer-group %s\n",
3302 existing_group->name);
3303 return CMD_WARNING_CONFIG_FAILED;
3304 }
3305 }
3306
3307 /* Check if an overlapping listen range exists. */
3308 if (listen_range_exists(bgp, &range, 0)) {
3309 vty_out(vty,
3310 "%% Listen range overlaps with existing listen range\n");
3311 return CMD_WARNING_CONFIG_FAILED;
3312 }
3313
3314 group = peer_group_lookup(bgp, peergroup);
3315 if (!group) {
3316 vty_out(vty, "%% Configure the peer-group first\n");
3317 return CMD_WARNING_CONFIG_FAILED;
3318 }
3319
3320 ret = peer_group_listen_range_add(group, &range);
3321 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3322}
3323
3324DEFUN (no_bgp_listen_range,
3325 no_bgp_listen_range_cmd,
d7b9898c 3326 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3327 NO_STR
f14e6fdb 3328 "BGP specific commands\n"
d7fa34c1
QY
3329 "Unconfigure BGP dynamic neighbors listen range\n"
3330 "Unconfigure BGP dynamic neighbors listen range\n"
3331 NEIGHBOR_ADDR_STR
3332 "Member of the peer-group\n"
3333 "Peer-group name\n")
f14e6fdb 3334{
d62a17ae 3335 VTY_DECLVAR_CONTEXT(bgp, bgp);
3336 struct prefix range;
3337 struct peer_group *group;
3338 afi_t afi;
3339 int ret;
3340 int idx = 0;
3341
3342 argv_find(argv, argc, "A.B.C.D/M", &idx);
3343 argv_find(argv, argc, "X:X::X:X/M", &idx);
3344 char *prefix = argv[idx]->arg;
21d88a71 3345 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3346 char *peergroup = argv[idx]->arg;
3347
3348 /* Convert IP prefix string to struct prefix. */
3349 ret = str2prefix(prefix, &range);
3350 if (!ret) {
3351 vty_out(vty, "%% Malformed listen range\n");
3352 return CMD_WARNING_CONFIG_FAILED;
3353 }
3354
3355 afi = family2afi(range.family);
3356
3357 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3358 vty_out(vty,
3359 "%% Malformed listen range (link-local address)\n");
3360 return CMD_WARNING_CONFIG_FAILED;
3361 }
3362
3363 apply_mask(&range);
3364
3365 group = peer_group_lookup(bgp, peergroup);
3366 if (!group) {
3367 vty_out(vty, "%% Peer-group does not exist\n");
3368 return CMD_WARNING_CONFIG_FAILED;
3369 }
3370
3371 ret = peer_group_listen_range_del(group, &range);
3372 return bgp_vty_return(vty, ret);
3373}
3374
2b791107 3375void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3376{
3377 struct peer_group *group;
3378 struct listnode *node, *nnode, *rnode, *nrnode;
3379 struct prefix *range;
3380 afi_t afi;
3381 char buf[PREFIX2STR_BUFFER];
3382
3383 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3384 vty_out(vty, " bgp listen limit %d\n",
3385 bgp->dynamic_neighbors_limit);
3386
3387 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3388 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3389 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3390 nrnode, range)) {
3391 prefix2str(range, buf, sizeof(buf));
3392 vty_out(vty,
3393 " bgp listen range %s peer-group %s\n",
3394 buf, group->name);
3395 }
3396 }
3397 }
f14e6fdb
DS
3398}
3399
3400
907f92c8
DS
3401DEFUN (bgp_disable_connected_route_check,
3402 bgp_disable_connected_route_check_cmd,
3403 "bgp disable-ebgp-connected-route-check",
3404 "BGP specific commands\n"
3405 "Disable checking if nexthop is connected on ebgp sessions\n")
3406{
d62a17ae 3407 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3408 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3409 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 3410
d62a17ae 3411 return CMD_SUCCESS;
907f92c8
DS
3412}
3413
3414DEFUN (no_bgp_disable_connected_route_check,
3415 no_bgp_disable_connected_route_check_cmd,
3416 "no bgp disable-ebgp-connected-route-check",
3417 NO_STR
3418 "BGP specific commands\n"
3419 "Disable checking if nexthop is connected on ebgp sessions\n")
3420{
d62a17ae 3421 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3422 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
d62a17ae 3423 bgp_clear_star_soft_in(vty, bgp->name);
3424
3425 return CMD_SUCCESS;
3426}
3427
3428
3429static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3430 const char *as_str, afi_t afi, safi_t safi)
3431{
3432 VTY_DECLVAR_CONTEXT(bgp, bgp);
3433 int ret;
3434 as_t as;
3435 int as_type = AS_SPECIFIED;
3436 union sockunion su;
3437
3438 if (as_str[0] == 'i') {
3439 as = 0;
3440 as_type = AS_INTERNAL;
3441 } else if (as_str[0] == 'e') {
3442 as = 0;
3443 as_type = AS_EXTERNAL;
3444 } else {
3445 /* Get AS number. */
3446 as = strtoul(as_str, NULL, 10);
3447 }
3448
390485fd 3449 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3450 ret = str2sockunion(peer_str, &su);
3451 if (ret < 0) {
390485fd
DS
3452 struct peer *peer;
3453
3454 /* Check if existing interface peer */
3455 peer = peer_lookup_by_conf_if(bgp, peer_str);
3456
d62a17ae 3457 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3458 safi);
390485fd
DS
3459
3460 /* if not interface peer, check peer-group settings */
3461 if (ret < 0 && !peer) {
d62a17ae 3462 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3463 if (ret < 0) {
3464 vty_out(vty,
390485fd 3465 "%% Create the peer-group or interface first\n");
d62a17ae 3466 return CMD_WARNING_CONFIG_FAILED;
3467 }
3468 return CMD_SUCCESS;
3469 }
3470 } else {
3471 if (peer_address_self_check(bgp, &su)) {
3472 vty_out(vty,
3473 "%% Can not configure the local system as neighbor\n");
3474 return CMD_WARNING_CONFIG_FAILED;
3475 }
3476 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3477 }
3478
3479 /* This peer belongs to peer group. */
3480 switch (ret) {
3481 case BGP_ERR_PEER_GROUP_MEMBER:
3482 vty_out(vty,
faa16034 3483 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3484 return CMD_WARNING_CONFIG_FAILED;
3485 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3486 vty_out(vty,
faa16034 3487 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3488 return CMD_WARNING_CONFIG_FAILED;
3489 }
3490 return bgp_vty_return(vty, ret);
718e3744 3491}
3492
f26845f9
QY
3493DEFUN (bgp_default_shutdown,
3494 bgp_default_shutdown_cmd,
3495 "[no] bgp default shutdown",
3496 NO_STR
3497 BGP_STR
3498 "Configure BGP defaults\n"
b012cbe2 3499 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
3500{
3501 VTY_DECLVAR_CONTEXT(bgp, bgp);
3502 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
3503 return CMD_SUCCESS;
3504}
3505
718e3744 3506DEFUN (neighbor_remote_as,
3507 neighbor_remote_as_cmd,
3a2d747c 3508 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 3509 NEIGHBOR_STR
3510 NEIGHBOR_ADDR_STR2
3511 "Specify a BGP neighbor\n"
d7fa34c1 3512 AS_STR
3a2d747c
QY
3513 "Internal BGP peer\n"
3514 "External BGP peer\n")
718e3744 3515{
d62a17ae 3516 int idx_peer = 1;
3517 int idx_remote_as = 3;
3518 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
3519 argv[idx_remote_as]->arg, AFI_IP,
3520 SAFI_UNICAST);
3521}
3522
3523static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
3524 afi_t afi, safi_t safi, int v6only,
3525 const char *peer_group_name,
3526 const char *as_str)
3527{
3528 VTY_DECLVAR_CONTEXT(bgp, bgp);
3529 as_t as = 0;
3530 int as_type = AS_UNSPECIFIED;
3531 struct peer *peer;
3532 struct peer_group *group;
3533 int ret = 0;
3534 union sockunion su;
3535
3536 group = peer_group_lookup(bgp, conf_if);
3537
3538 if (group) {
3539 vty_out(vty, "%% Name conflict with peer-group \n");
3540 return CMD_WARNING_CONFIG_FAILED;
3541 }
3542
3543 if (as_str) {
3544 if (as_str[0] == 'i') {
3545 as_type = AS_INTERNAL;
3546 } else if (as_str[0] == 'e') {
3547 as_type = AS_EXTERNAL;
3548 } else {
3549 /* Get AS number. */
3550 as = strtoul(as_str, NULL, 10);
3551 as_type = AS_SPECIFIED;
3552 }
3553 }
3554
3555 peer = peer_lookup_by_conf_if(bgp, conf_if);
3556 if (peer) {
3557 if (as_str)
cc4d4ce8 3558 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 3559 afi, safi);
3560 } else {
892fedb6 3561 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 3562 && afi == AFI_IP && safi == SAFI_UNICAST)
3563 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3564 as_type, 0, 0, NULL);
3565 else
3566 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
3567 as_type, afi, safi, NULL);
3568
3569 if (!peer) {
3570 vty_out(vty, "%% BGP failed to create peer\n");
3571 return CMD_WARNING_CONFIG_FAILED;
3572 }
3573
3574 if (v6only)
527de3dc 3575 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3576
3577 /* Request zebra to initiate IPv6 RAs on this interface. We do
3578 * this
3579 * any unnumbered peer in order to not worry about run-time
3580 * transitions
3581 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
3582 * address
3583 * gets deleted later etc.)
3584 */
3585 if (peer->ifp)
3586 bgp_zebra_initiate_radv(bgp, peer);
3587 }
3588
3589 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
3590 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
3591 if (v6only)
527de3dc 3592 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3593 else
527de3dc 3594 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 3595
3596 /* v6only flag changed. Reset bgp seesion */
3597 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
3598 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
3599 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
3600 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
3601 } else
3602 bgp_session_reset(peer);
3603 }
3604
9fb964de
PM
3605 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3606 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3607 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 3608 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 3609 }
d62a17ae 3610
3611 if (peer_group_name) {
3612 group = peer_group_lookup(bgp, peer_group_name);
3613 if (!group) {
3614 vty_out(vty, "%% Configure the peer-group first\n");
3615 return CMD_WARNING_CONFIG_FAILED;
3616 }
3617
3618 ret = peer_group_bind(bgp, &su, peer, group, &as);
3619 }
3620
3621 return bgp_vty_return(vty, ret);
a80beece
DS
3622}
3623
4c48cf63
DW
3624DEFUN (neighbor_interface_config,
3625 neighbor_interface_config_cmd,
d7b9898c 3626 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
3627 NEIGHBOR_STR
3628 "Interface name or neighbor tag\n"
31500417
DW
3629 "Enable BGP on interface\n"
3630 "Member of the peer-group\n"
16cedbb0 3631 "Peer-group name\n")
4c48cf63 3632{
d62a17ae 3633 int idx_word = 1;
3634 int idx_peer_group_word = 4;
31500417 3635
d62a17ae 3636 if (argc > idx_peer_group_word)
3637 return peer_conf_interface_get(
3638 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3639 argv[idx_peer_group_word]->arg, NULL);
3640 else
3641 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3642 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
3643}
3644
4c48cf63
DW
3645DEFUN (neighbor_interface_config_v6only,
3646 neighbor_interface_config_v6only_cmd,
d7b9898c 3647 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
3648 NEIGHBOR_STR
3649 "Interface name or neighbor tag\n"
3650 "Enable BGP on interface\n"
31500417
DW
3651 "Enable BGP with v6 link-local only\n"
3652 "Member of the peer-group\n"
16cedbb0 3653 "Peer-group name\n")
4c48cf63 3654{
d62a17ae 3655 int idx_word = 1;
3656 int idx_peer_group_word = 5;
31500417 3657
d62a17ae 3658 if (argc > idx_peer_group_word)
3659 return peer_conf_interface_get(
3660 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3661 argv[idx_peer_group_word]->arg, NULL);
31500417 3662
d62a17ae 3663 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3664 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
3665}
3666
a80beece 3667
b3a39dc5
DD
3668DEFUN (neighbor_interface_config_remote_as,
3669 neighbor_interface_config_remote_as_cmd,
3a2d747c 3670 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3671 NEIGHBOR_STR
3672 "Interface name or neighbor tag\n"
3673 "Enable BGP on interface\n"
3a2d747c 3674 "Specify a BGP neighbor\n"
d7fa34c1 3675 AS_STR
3a2d747c
QY
3676 "Internal BGP peer\n"
3677 "External BGP peer\n")
b3a39dc5 3678{
d62a17ae 3679 int idx_word = 1;
3680 int idx_remote_as = 4;
3681 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3682 SAFI_UNICAST, 0, NULL,
3683 argv[idx_remote_as]->arg);
b3a39dc5
DD
3684}
3685
3686DEFUN (neighbor_interface_v6only_config_remote_as,
3687 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 3688 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
3689 NEIGHBOR_STR
3690 "Interface name or neighbor tag\n"
3a2d747c 3691 "Enable BGP with v6 link-local only\n"
b3a39dc5 3692 "Enable BGP on interface\n"
3a2d747c 3693 "Specify a BGP neighbor\n"
d7fa34c1 3694 AS_STR
3a2d747c
QY
3695 "Internal BGP peer\n"
3696 "External BGP peer\n")
b3a39dc5 3697{
d62a17ae 3698 int idx_word = 1;
3699 int idx_remote_as = 5;
3700 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3701 SAFI_UNICAST, 1, NULL,
3702 argv[idx_remote_as]->arg);
b3a39dc5
DD
3703}
3704
718e3744 3705DEFUN (neighbor_peer_group,
3706 neighbor_peer_group_cmd,
3707 "neighbor WORD peer-group",
3708 NEIGHBOR_STR
a80beece 3709 "Interface name or neighbor tag\n"
718e3744 3710 "Configure peer-group\n")
3711{
d62a17ae 3712 VTY_DECLVAR_CONTEXT(bgp, bgp);
3713 int idx_word = 1;
3714 struct peer *peer;
3715 struct peer_group *group;
718e3744 3716
d62a17ae 3717 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3718 if (peer) {
3719 vty_out(vty, "%% Name conflict with interface: \n");
3720 return CMD_WARNING_CONFIG_FAILED;
3721 }
718e3744 3722
d62a17ae 3723 group = peer_group_get(bgp, argv[idx_word]->arg);
3724 if (!group) {
3725 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3726 return CMD_WARNING_CONFIG_FAILED;
3727 }
718e3744 3728
d62a17ae 3729 return CMD_SUCCESS;
718e3744 3730}
3731
3732DEFUN (no_neighbor,
3733 no_neighbor_cmd,
dab8cd00 3734 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 3735 NO_STR
3736 NEIGHBOR_STR
3a2d747c
QY
3737 NEIGHBOR_ADDR_STR2
3738 "Specify a BGP neighbor\n"
3739 AS_STR
3740 "Internal BGP peer\n"
3741 "External BGP peer\n")
718e3744 3742{
d62a17ae 3743 VTY_DECLVAR_CONTEXT(bgp, bgp);
3744 int idx_peer = 2;
3745 int ret;
3746 union sockunion su;
3747 struct peer_group *group;
3748 struct peer *peer;
3749 struct peer *other;
3750
3751 ret = str2sockunion(argv[idx_peer]->arg, &su);
3752 if (ret < 0) {
3753 /* look up for neighbor by interface name config. */
3754 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3755 if (peer) {
3756 /* Request zebra to terminate IPv6 RAs on this
3757 * interface. */
3758 if (peer->ifp)
3759 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3760 peer_notify_unconfig(peer);
d62a17ae 3761 peer_delete(peer);
3762 return CMD_SUCCESS;
3763 }
f14e6fdb 3764
d62a17ae 3765 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
3766 if (group) {
3767 peer_group_notify_unconfig(group);
d62a17ae 3768 peer_group_delete(group);
4e2786df 3769 } else {
d62a17ae 3770 vty_out(vty, "%% Create the peer-group first\n");
3771 return CMD_WARNING_CONFIG_FAILED;
3772 }
3773 } else {
3774 peer = peer_lookup(bgp, &su);
3775 if (peer) {
3776 if (peer_dynamic_neighbor(peer)) {
3777 vty_out(vty,
3778 "%% Operation not allowed on a dynamic neighbor\n");
3779 return CMD_WARNING_CONFIG_FAILED;
3780 }
3781
3782 other = peer->doppelganger;
4e2786df 3783 peer_notify_unconfig(peer);
d62a17ae 3784 peer_delete(peer);
4e2786df
DA
3785 if (other && other->status != Deleted) {
3786 peer_notify_unconfig(other);
d62a17ae 3787 peer_delete(other);
4e2786df 3788 }
d62a17ae 3789 }
1ff9a340 3790 }
718e3744 3791
d62a17ae 3792 return CMD_SUCCESS;
718e3744 3793}
3794
a80beece
DS
3795DEFUN (no_neighbor_interface_config,
3796 no_neighbor_interface_config_cmd,
d7b9898c 3797 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3798 NO_STR
3799 NEIGHBOR_STR
3800 "Interface name\n"
31500417
DW
3801 "Configure BGP on interface\n"
3802 "Enable BGP with v6 link-local only\n"
3803 "Member of the peer-group\n"
16cedbb0 3804 "Peer-group name\n"
3a2d747c
QY
3805 "Specify a BGP neighbor\n"
3806 AS_STR
3807 "Internal BGP peer\n"
3808 "External BGP peer\n")
a80beece 3809{
d62a17ae 3810 VTY_DECLVAR_CONTEXT(bgp, bgp);
3811 int idx_word = 2;
3812 struct peer *peer;
3813
3814 /* look up for neighbor by interface name config. */
3815 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3816 if (peer) {
3817 /* Request zebra to terminate IPv6 RAs on this interface. */
3818 if (peer->ifp)
3819 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 3820 peer_notify_unconfig(peer);
d62a17ae 3821 peer_delete(peer);
3822 } else {
3823 vty_out(vty, "%% Create the bgp interface first\n");
3824 return CMD_WARNING_CONFIG_FAILED;
3825 }
3826 return CMD_SUCCESS;
a80beece
DS
3827}
3828
718e3744 3829DEFUN (no_neighbor_peer_group,
3830 no_neighbor_peer_group_cmd,
3831 "no neighbor WORD peer-group",
3832 NO_STR
3833 NEIGHBOR_STR
3834 "Neighbor tag\n"
3835 "Configure peer-group\n")
3836{
d62a17ae 3837 VTY_DECLVAR_CONTEXT(bgp, bgp);
3838 int idx_word = 2;
3839 struct peer_group *group;
718e3744 3840
d62a17ae 3841 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
3842 if (group) {
3843 peer_group_notify_unconfig(group);
d62a17ae 3844 peer_group_delete(group);
4e2786df 3845 } else {
d62a17ae 3846 vty_out(vty, "%% Create the peer-group first\n");
3847 return CMD_WARNING_CONFIG_FAILED;
3848 }
3849 return CMD_SUCCESS;
718e3744 3850}
3851
a80beece
DS
3852DEFUN (no_neighbor_interface_peer_group_remote_as,
3853 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3854 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3855 NO_STR
3856 NEIGHBOR_STR
a80beece 3857 "Interface name or neighbor tag\n"
718e3744 3858 "Specify a BGP neighbor\n"
3a2d747c
QY
3859 AS_STR
3860 "Internal BGP peer\n"
3861 "External BGP peer\n")
718e3744 3862{
d62a17ae 3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 int idx_word = 2;
3865 struct peer_group *group;
3866 struct peer *peer;
3867
3868 /* look up for neighbor by interface name config. */
3869 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3870 if (peer) {
390485fd 3871 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 3872 return CMD_SUCCESS;
3873 }
3874
3875 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3876 if (group)
3877 peer_group_remote_as_delete(group);
3878 else {
3879 vty_out(vty, "%% Create the peer-group or interface first\n");
3880 return CMD_WARNING_CONFIG_FAILED;
3881 }
3882 return CMD_SUCCESS;
718e3744 3883}
6b0655a2 3884
718e3744 3885DEFUN (neighbor_local_as,
3886 neighbor_local_as_cmd,
9ccf14f7 3887 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3888 NEIGHBOR_STR
3889 NEIGHBOR_ADDR_STR2
3890 "Specify a local-as number\n"
3891 "AS number used as local AS\n")
3892{
d62a17ae 3893 int idx_peer = 1;
3894 int idx_number = 3;
3895 struct peer *peer;
3896 int ret;
3897 as_t as;
718e3744 3898
d62a17ae 3899 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3900 if (!peer)
3901 return CMD_WARNING_CONFIG_FAILED;
718e3744 3902
d62a17ae 3903 as = strtoul(argv[idx_number]->arg, NULL, 10);
3904 ret = peer_local_as_set(peer, as, 0, 0);
3905 return bgp_vty_return(vty, ret);
718e3744 3906}
3907
3908DEFUN (neighbor_local_as_no_prepend,
3909 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3910 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3911 NEIGHBOR_STR
3912 NEIGHBOR_ADDR_STR2
3913 "Specify a local-as number\n"
3914 "AS number used as local AS\n"
3915 "Do not prepend local-as to updates from ebgp peers\n")
3916{
d62a17ae 3917 int idx_peer = 1;
3918 int idx_number = 3;
3919 struct peer *peer;
3920 int ret;
3921 as_t as;
718e3744 3922
d62a17ae 3923 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3924 if (!peer)
3925 return CMD_WARNING_CONFIG_FAILED;
718e3744 3926
d62a17ae 3927 as = strtoul(argv[idx_number]->arg, NULL, 10);
3928 ret = peer_local_as_set(peer, as, 1, 0);
3929 return bgp_vty_return(vty, ret);
718e3744 3930}
3931
9d3f9705
AC
3932DEFUN (neighbor_local_as_no_prepend_replace_as,
3933 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3934 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3935 NEIGHBOR_STR
3936 NEIGHBOR_ADDR_STR2
3937 "Specify a local-as number\n"
3938 "AS number used as local AS\n"
3939 "Do not prepend local-as to updates from ebgp peers\n"
3940 "Do not prepend local-as to updates from ibgp peers\n")
3941{
d62a17ae 3942 int idx_peer = 1;
3943 int idx_number = 3;
3944 struct peer *peer;
3945 int ret;
3946 as_t as;
9d3f9705 3947
d62a17ae 3948 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3949 if (!peer)
3950 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3951
d62a17ae 3952 as = strtoul(argv[idx_number]->arg, NULL, 10);
3953 ret = peer_local_as_set(peer, as, 1, 1);
3954 return bgp_vty_return(vty, ret);
9d3f9705
AC
3955}
3956
718e3744 3957DEFUN (no_neighbor_local_as,
3958 no_neighbor_local_as_cmd,
a636c635 3959 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3960 NO_STR
3961 NEIGHBOR_STR
3962 NEIGHBOR_ADDR_STR2
a636c635
DW
3963 "Specify a local-as number\n"
3964 "AS number used as local AS\n"
3965 "Do not prepend local-as to updates from ebgp peers\n"
3966 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3967{
d62a17ae 3968 int idx_peer = 2;
3969 struct peer *peer;
3970 int ret;
718e3744 3971
d62a17ae 3972 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3973 if (!peer)
3974 return CMD_WARNING_CONFIG_FAILED;
718e3744 3975
d62a17ae 3976 ret = peer_local_as_unset(peer);
3977 return bgp_vty_return(vty, ret);
718e3744 3978}
3979
718e3744 3980
3f9c7369
DS
3981DEFUN (neighbor_solo,
3982 neighbor_solo_cmd,
9ccf14f7 3983 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3984 NEIGHBOR_STR
3985 NEIGHBOR_ADDR_STR2
3986 "Solo peer - part of its own update group\n")
3987{
d62a17ae 3988 int idx_peer = 1;
3989 struct peer *peer;
3990 int ret;
3f9c7369 3991
d62a17ae 3992 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3993 if (!peer)
3994 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3995
d62a17ae 3996 ret = update_group_adjust_soloness(peer, 1);
3997 return bgp_vty_return(vty, ret);
3f9c7369
DS
3998}
3999
4000DEFUN (no_neighbor_solo,
4001 no_neighbor_solo_cmd,
9ccf14f7 4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4003 NO_STR
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
4006 "Solo peer - part of its own update group\n")
4007{
d62a17ae 4008 int idx_peer = 2;
4009 struct peer *peer;
4010 int ret;
3f9c7369 4011
d62a17ae 4012 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4013 if (!peer)
4014 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4015
d62a17ae 4016 ret = update_group_adjust_soloness(peer, 0);
4017 return bgp_vty_return(vty, ret);
3f9c7369
DS
4018}
4019
0df7c91f
PJ
4020DEFUN (neighbor_password,
4021 neighbor_password_cmd,
9ccf14f7 4022 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Set a password\n"
4026 "The password\n")
4027{
d62a17ae 4028 int idx_peer = 1;
4029 int idx_line = 3;
4030 struct peer *peer;
4031 int ret;
0df7c91f 4032
d62a17ae 4033 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4034 if (!peer)
4035 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4036
d62a17ae 4037 ret = peer_password_set(peer, argv[idx_line]->arg);
4038 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4039}
4040
4041DEFUN (no_neighbor_password,
4042 no_neighbor_password_cmd,
a636c635 4043 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4044 NO_STR
4045 NEIGHBOR_STR
4046 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4047 "Set a password\n"
4048 "The password\n")
0df7c91f 4049{
d62a17ae 4050 int idx_peer = 2;
4051 struct peer *peer;
4052 int ret;
0df7c91f 4053
d62a17ae 4054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4055 if (!peer)
4056 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4057
d62a17ae 4058 ret = peer_password_unset(peer);
4059 return bgp_vty_return(vty, ret);
0df7c91f 4060}
6b0655a2 4061
718e3744 4062DEFUN (neighbor_activate,
4063 neighbor_activate_cmd,
9ccf14f7 4064 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Enable the Address Family for this Neighbor\n")
4068{
d62a17ae 4069 int idx_peer = 1;
4070 int ret;
4071 struct peer *peer;
718e3744 4072
d62a17ae 4073 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4074 if (!peer)
4075 return CMD_WARNING_CONFIG_FAILED;
718e3744 4076
d62a17ae 4077 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4078 return bgp_vty_return(vty, ret);
718e3744 4079}
4080
d62a17ae 4081ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4082 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4084 "Enable the Address Family for this Neighbor\n")
596c17ba 4085
718e3744 4086DEFUN (no_neighbor_activate,
4087 no_neighbor_activate_cmd,
9ccf14f7 4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4089 NO_STR
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "Enable the Address Family for this Neighbor\n")
4093{
d62a17ae 4094 int idx_peer = 2;
4095 int ret;
4096 struct peer *peer;
718e3744 4097
d62a17ae 4098 /* Lookup peer. */
4099 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4100 if (!peer)
4101 return CMD_WARNING_CONFIG_FAILED;
718e3744 4102
d62a17ae 4103 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4104 return bgp_vty_return(vty, ret);
718e3744 4105}
6b0655a2 4106
d62a17ae 4107ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4108 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4110 "Enable the Address Family for this Neighbor\n")
596c17ba 4111
718e3744 4112DEFUN (neighbor_set_peer_group,
4113 neighbor_set_peer_group_cmd,
d7b9898c 4114 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4115 NEIGHBOR_STR
a80beece 4116 NEIGHBOR_ADDR_STR2
718e3744 4117 "Member of the peer-group\n"
16cedbb0 4118 "Peer-group name\n")
718e3744 4119{
d62a17ae 4120 VTY_DECLVAR_CONTEXT(bgp, bgp);
4121 int idx_peer = 1;
4122 int idx_word = 3;
4123 int ret;
4124 as_t as;
4125 union sockunion su;
4126 struct peer *peer;
4127 struct peer_group *group;
4128
d62a17ae 4129 ret = str2sockunion(argv[idx_peer]->arg, &su);
4130 if (ret < 0) {
4131 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4132 if (!peer) {
4133 vty_out(vty, "%% Malformed address or name: %s\n",
4134 argv[idx_peer]->arg);
4135 return CMD_WARNING_CONFIG_FAILED;
4136 }
4137 } else {
4138 if (peer_address_self_check(bgp, &su)) {
4139 vty_out(vty,
4140 "%% Can not configure the local system as neighbor\n");
4141 return CMD_WARNING_CONFIG_FAILED;
4142 }
4143
4144 /* Disallow for dynamic neighbor. */
4145 peer = peer_lookup(bgp, &su);
4146 if (peer && peer_dynamic_neighbor(peer)) {
4147 vty_out(vty,
4148 "%% Operation not allowed on a dynamic neighbor\n");
4149 return CMD_WARNING_CONFIG_FAILED;
4150 }
4151 }
4152
4153 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4154 if (!group) {
4155 vty_out(vty, "%% Configure the peer-group first\n");
4156 return CMD_WARNING_CONFIG_FAILED;
4157 }
4158
4159 ret = peer_group_bind(bgp, &su, peer, group, &as);
4160
4161 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4162 vty_out(vty,
4163 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4164 as);
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 return bgp_vty_return(vty, ret);
4169}
4170
4171ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4172 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4173 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4174 "Member of the peer-group\n"
4175 "Peer-group name\n")
596c17ba 4176
718e3744 4177DEFUN (no_neighbor_set_peer_group,
4178 no_neighbor_set_peer_group_cmd,
d7b9898c 4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4180 NO_STR
4181 NEIGHBOR_STR
a80beece 4182 NEIGHBOR_ADDR_STR2
718e3744 4183 "Member of the peer-group\n"
16cedbb0 4184 "Peer-group name\n")
718e3744 4185{
d62a17ae 4186 VTY_DECLVAR_CONTEXT(bgp, bgp);
4187 int idx_peer = 2;
4188 int idx_word = 4;
4189 int ret;
4190 struct peer *peer;
4191 struct peer_group *group;
4192
4193 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4194 if (!peer)
4195 return CMD_WARNING_CONFIG_FAILED;
4196
4197 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4198 if (!group) {
4199 vty_out(vty, "%% Configure the peer-group first\n");
4200 return CMD_WARNING_CONFIG_FAILED;
4201 }
718e3744 4202
4e2786df 4203 peer_notify_unconfig(peer);
827ed707 4204 ret = peer_delete(peer);
718e3744 4205
d62a17ae 4206 return bgp_vty_return(vty, ret);
718e3744 4207}
6b0655a2 4208
d62a17ae 4209ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4210 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4211 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4212 "Member of the peer-group\n"
4213 "Peer-group name\n")
596c17ba 4214
d62a17ae 4215static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4216 uint32_t flag, int set)
718e3744 4217{
d62a17ae 4218 int ret;
4219 struct peer *peer;
718e3744 4220
d62a17ae 4221 peer = peer_and_group_lookup_vty(vty, ip_str);
4222 if (!peer)
4223 return CMD_WARNING_CONFIG_FAILED;
718e3744 4224
7ebe625c
QY
4225 /*
4226 * If 'neighbor <interface>', then this is for directly connected peers,
4227 * we should not accept disable-connected-check.
4228 */
4229 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4230 vty_out(vty,
4231 "%s is directly connected peer, cannot accept disable-"
4232 "connected-check\n",
4233 ip_str);
4234 return CMD_WARNING_CONFIG_FAILED;
4235 }
4236
d62a17ae 4237 if (!set && flag == PEER_FLAG_SHUTDOWN)
4238 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4239
d62a17ae 4240 if (set)
4241 ret = peer_flag_set(peer, flag);
4242 else
4243 ret = peer_flag_unset(peer, flag);
718e3744 4244
d62a17ae 4245 return bgp_vty_return(vty, ret);
718e3744 4246}
4247
47cbc09b 4248static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4249{
d62a17ae 4250 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4251}
4252
d62a17ae 4253static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4254 uint32_t flag)
718e3744 4255{
d62a17ae 4256 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4257}
4258
4259/* neighbor passive. */
4260DEFUN (neighbor_passive,
4261 neighbor_passive_cmd,
9ccf14f7 4262 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4263 NEIGHBOR_STR
4264 NEIGHBOR_ADDR_STR2
4265 "Don't send open messages to this neighbor\n")
4266{
d62a17ae 4267 int idx_peer = 1;
4268 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4269}
4270
4271DEFUN (no_neighbor_passive,
4272 no_neighbor_passive_cmd,
9ccf14f7 4273 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4274 NO_STR
4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
4277 "Don't send open messages to this neighbor\n")
4278{
d62a17ae 4279 int idx_peer = 2;
4280 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4281}
6b0655a2 4282
718e3744 4283/* neighbor shutdown. */
73d70fa6
DL
4284DEFUN (neighbor_shutdown_msg,
4285 neighbor_shutdown_msg_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4287 NEIGHBOR_STR
4288 NEIGHBOR_ADDR_STR2
73d70fa6
DL
4289 "Administratively shut down this neighbor\n"
4290 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
4291 "Shutdown message\n")
718e3744 4292{
d62a17ae 4293 int idx_peer = 1;
73d70fa6 4294
d62a17ae 4295 if (argc >= 5) {
4296 struct peer *peer =
4297 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4298 char *message;
73d70fa6 4299
d62a17ae 4300 if (!peer)
4301 return CMD_WARNING_CONFIG_FAILED;
4302 message = argv_concat(argv, argc, 4);
4303 peer_tx_shutdown_message_set(peer, message);
4304 XFREE(MTYPE_TMP, message);
4305 }
73d70fa6 4306
d62a17ae 4307 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4308}
4309
d62a17ae 4310ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4311 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4312 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4313 "Administratively shut down this neighbor\n")
73d70fa6
DL
4314
4315DEFUN (no_neighbor_shutdown_msg,
4316 no_neighbor_shutdown_msg_cmd,
4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Administratively shut down this neighbor\n"
4322 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
4323 "Shutdown message\n")
718e3744 4324{
d62a17ae 4325 int idx_peer = 2;
73d70fa6 4326
d62a17ae 4327 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4328 PEER_FLAG_SHUTDOWN);
718e3744 4329}
6b0655a2 4330
d62a17ae 4331ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4332 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4333 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4334 "Administratively shut down this neighbor\n")
73d70fa6 4335
718e3744 4336/* neighbor capability dynamic. */
4337DEFUN (neighbor_capability_dynamic,
4338 neighbor_capability_dynamic_cmd,
9ccf14f7 4339 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4340 NEIGHBOR_STR
4341 NEIGHBOR_ADDR_STR2
4342 "Advertise capability to the peer\n"
4343 "Advertise dynamic capability to this neighbor\n")
4344{
d62a17ae 4345 int idx_peer = 1;
4346 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4347 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4348}
4349
4350DEFUN (no_neighbor_capability_dynamic,
4351 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4352 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4353 NO_STR
4354 NEIGHBOR_STR
4355 NEIGHBOR_ADDR_STR2
4356 "Advertise capability to the peer\n"
4357 "Advertise dynamic capability to this neighbor\n")
4358{
d62a17ae 4359 int idx_peer = 2;
4360 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4361 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4362}
6b0655a2 4363
718e3744 4364/* neighbor dont-capability-negotiate */
4365DEFUN (neighbor_dont_capability_negotiate,
4366 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4367 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4368 NEIGHBOR_STR
4369 NEIGHBOR_ADDR_STR2
4370 "Do not perform capability negotiation\n")
4371{
d62a17ae 4372 int idx_peer = 1;
4373 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4374 PEER_FLAG_DONT_CAPABILITY);
718e3744 4375}
4376
4377DEFUN (no_neighbor_dont_capability_negotiate,
4378 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4379 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4380 NO_STR
4381 NEIGHBOR_STR
4382 NEIGHBOR_ADDR_STR2
4383 "Do not perform capability negotiation\n")
4384{
d62a17ae 4385 int idx_peer = 2;
4386 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4387 PEER_FLAG_DONT_CAPABILITY);
718e3744 4388}
6b0655a2 4389
8a92a8a0
DS
4390/* neighbor capability extended next hop encoding */
4391DEFUN (neighbor_capability_enhe,
4392 neighbor_capability_enhe_cmd,
9ccf14f7 4393 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Advertise capability to the peer\n"
4397 "Advertise extended next-hop capability to the peer\n")
4398{
d62a17ae 4399 int idx_peer = 1;
4400 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4401 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4402}
4403
4404DEFUN (no_neighbor_capability_enhe,
4405 no_neighbor_capability_enhe_cmd,
9ccf14f7 4406 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
4407 NO_STR
4408 NEIGHBOR_STR
4409 NEIGHBOR_ADDR_STR2
4410 "Advertise capability to the peer\n"
4411 "Advertise extended next-hop capability to the peer\n")
4412{
d62a17ae 4413 int idx_peer = 2;
4414 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4415 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
4416}
4417
d62a17ae 4418static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4419 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 4420 int set)
718e3744 4421{
d62a17ae 4422 int ret;
4423 struct peer *peer;
718e3744 4424
d62a17ae 4425 peer = peer_and_group_lookup_vty(vty, peer_str);
4426 if (!peer)
4427 return CMD_WARNING_CONFIG_FAILED;
718e3744 4428
d62a17ae 4429 if (set)
4430 ret = peer_af_flag_set(peer, afi, safi, flag);
4431 else
4432 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 4433
d62a17ae 4434 return bgp_vty_return(vty, ret);
718e3744 4435}
4436
d62a17ae 4437static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4438 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4439{
d62a17ae 4440 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 4441}
4442
d62a17ae 4443static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 4444 afi_t afi, safi_t safi, uint32_t flag)
718e3744 4445{
d62a17ae 4446 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 4447}
6b0655a2 4448
718e3744 4449/* neighbor capability orf prefix-list. */
4450DEFUN (neighbor_capability_orf_prefix,
4451 neighbor_capability_orf_prefix_cmd,
9ccf14f7 4452 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4453 NEIGHBOR_STR
4454 NEIGHBOR_ADDR_STR2
4455 "Advertise capability to the peer\n"
4456 "Advertise ORF capability to the peer\n"
4457 "Advertise prefixlist ORF capability to this neighbor\n"
4458 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4459 "Capability to RECEIVE the ORF from this neighbor\n"
4460 "Capability to SEND the ORF to this neighbor\n")
4461{
d62a17ae 4462 int idx_peer = 1;
4463 int idx_send_recv = 5;
d7c0a89a 4464 uint16_t flag = 0;
d62a17ae 4465
4466 if (strmatch(argv[idx_send_recv]->text, "send"))
4467 flag = PEER_FLAG_ORF_PREFIX_SM;
4468 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4469 flag = PEER_FLAG_ORF_PREFIX_RM;
4470 else if (strmatch(argv[idx_send_recv]->text, "both"))
4471 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4472 else {
4473 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4474 return CMD_WARNING_CONFIG_FAILED;
4475 }
4476
4477 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4478 bgp_node_safi(vty), flag);
4479}
4480
4481ALIAS_HIDDEN(
4482 neighbor_capability_orf_prefix,
4483 neighbor_capability_orf_prefix_hidden_cmd,
4484 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4485 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4486 "Advertise capability to the peer\n"
4487 "Advertise ORF capability to the peer\n"
4488 "Advertise prefixlist ORF capability to this neighbor\n"
4489 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4490 "Capability to RECEIVE the ORF from this neighbor\n"
4491 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4492
718e3744 4493DEFUN (no_neighbor_capability_orf_prefix,
4494 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 4495 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 4496 NO_STR
4497 NEIGHBOR_STR
4498 NEIGHBOR_ADDR_STR2
4499 "Advertise capability to the peer\n"
4500 "Advertise ORF capability to the peer\n"
4501 "Advertise prefixlist ORF capability to this neighbor\n"
4502 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4503 "Capability to RECEIVE the ORF from this neighbor\n"
4504 "Capability to SEND the ORF to this neighbor\n")
4505{
d62a17ae 4506 int idx_peer = 2;
4507 int idx_send_recv = 6;
d7c0a89a 4508 uint16_t flag = 0;
d62a17ae 4509
4510 if (strmatch(argv[idx_send_recv]->text, "send"))
4511 flag = PEER_FLAG_ORF_PREFIX_SM;
4512 else if (strmatch(argv[idx_send_recv]->text, "receive"))
4513 flag = PEER_FLAG_ORF_PREFIX_RM;
4514 else if (strmatch(argv[idx_send_recv]->text, "both"))
4515 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
4516 else {
4517 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
4518 return CMD_WARNING_CONFIG_FAILED;
4519 }
4520
4521 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4522 bgp_node_afi(vty), bgp_node_safi(vty),
4523 flag);
4524}
4525
4526ALIAS_HIDDEN(
4527 no_neighbor_capability_orf_prefix,
4528 no_neighbor_capability_orf_prefix_hidden_cmd,
4529 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
4530 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4531 "Advertise capability to the peer\n"
4532 "Advertise ORF capability to the peer\n"
4533 "Advertise prefixlist ORF capability to this neighbor\n"
4534 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
4535 "Capability to RECEIVE the ORF from this neighbor\n"
4536 "Capability to SEND the ORF to this neighbor\n")
596c17ba 4537
718e3744 4538/* neighbor next-hop-self. */
4539DEFUN (neighbor_nexthop_self,
4540 neighbor_nexthop_self_cmd,
9ccf14f7 4541 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4542 NEIGHBOR_STR
4543 NEIGHBOR_ADDR_STR2
a538debe 4544 "Disable the next hop calculation for this neighbor\n")
718e3744 4545{
d62a17ae 4546 int idx_peer = 1;
4547 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4548 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 4549}
9e7a53c1 4550
d62a17ae 4551ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
4552 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4554 "Disable the next hop calculation for this neighbor\n")
596c17ba 4555
a538debe
DS
4556/* neighbor next-hop-self. */
4557DEFUN (neighbor_nexthop_self_force,
4558 neighbor_nexthop_self_force_cmd,
9ccf14f7 4559 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "Disable the next hop calculation for this neighbor\n"
4563 "Set the next hop to self for reflected routes\n")
4564{
d62a17ae 4565 int idx_peer = 1;
4566 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4567 bgp_node_safi(vty),
4568 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 4569}
4570
d62a17ae 4571ALIAS_HIDDEN(neighbor_nexthop_self_force,
4572 neighbor_nexthop_self_force_hidden_cmd,
4573 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4574 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4575 "Disable the next hop calculation for this neighbor\n"
4576 "Set the next hop to self for reflected routes\n")
596c17ba 4577
1bc4e531
DA
4578ALIAS_HIDDEN(neighbor_nexthop_self_force,
4579 neighbor_nexthop_self_all_hidden_cmd,
4580 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4581 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4582 "Disable the next hop calculation for this neighbor\n"
4583 "Set the next hop to self for reflected routes\n")
4584
718e3744 4585DEFUN (no_neighbor_nexthop_self,
4586 no_neighbor_nexthop_self_cmd,
9ccf14f7 4587 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 4588 NO_STR
4589 NEIGHBOR_STR
4590 NEIGHBOR_ADDR_STR2
a538debe 4591 "Disable the next hop calculation for this neighbor\n")
718e3744 4592{
d62a17ae 4593 int idx_peer = 2;
4594 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4595 bgp_node_afi(vty), bgp_node_safi(vty),
4596 PEER_FLAG_NEXTHOP_SELF);
718e3744 4597}
6b0655a2 4598
d62a17ae 4599ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
4600 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
4601 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4602 "Disable the next hop calculation for this neighbor\n")
596c17ba 4603
88b8ed8d 4604DEFUN (no_neighbor_nexthop_self_force,
a538debe 4605 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Disable the next hop calculation for this neighbor\n"
4611 "Set the next hop to self for reflected routes\n")
88b8ed8d 4612{
d62a17ae 4613 int idx_peer = 2;
4614 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4615 bgp_node_afi(vty), bgp_node_safi(vty),
4616 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 4617}
a538debe 4618
d62a17ae 4619ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4620 no_neighbor_nexthop_self_force_hidden_cmd,
4621 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4622 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4623 "Disable the next hop calculation for this neighbor\n"
4624 "Set the next hop to self for reflected routes\n")
596c17ba 4625
1bc4e531
DA
4626ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4627 no_neighbor_nexthop_self_all_hidden_cmd,
4628 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
4629 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4630 "Disable the next hop calculation for this neighbor\n"
4631 "Set the next hop to self for reflected routes\n")
4632
c7122e14
DS
4633/* neighbor as-override */
4634DEFUN (neighbor_as_override,
4635 neighbor_as_override_cmd,
9ccf14f7 4636 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Override ASNs in outbound updates if aspath equals remote-as\n")
4640{
d62a17ae 4641 int idx_peer = 1;
4642 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4643 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4644}
4645
d62a17ae 4646ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4647 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4649 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4650
c7122e14
DS
4651DEFUN (no_neighbor_as_override,
4652 no_neighbor_as_override_cmd,
9ccf14f7 4653 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
4654 NO_STR
4655 NEIGHBOR_STR
4656 NEIGHBOR_ADDR_STR2
4657 "Override ASNs in outbound updates if aspath equals remote-as\n")
4658{
d62a17ae 4659 int idx_peer = 2;
4660 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4661 bgp_node_afi(vty), bgp_node_safi(vty),
4662 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
4663}
4664
d62a17ae 4665ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4666 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4667 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4668 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 4669
718e3744 4670/* neighbor remove-private-AS. */
4671DEFUN (neighbor_remove_private_as,
4672 neighbor_remove_private_as_cmd,
9ccf14f7 4673 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4674 NEIGHBOR_STR
4675 NEIGHBOR_ADDR_STR2
5000f21c 4676 "Remove private ASNs in outbound updates\n")
718e3744 4677{
d62a17ae 4678 int idx_peer = 1;
4679 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4680 bgp_node_safi(vty),
4681 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4682}
4683
d62a17ae 4684ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4685 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4686 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4687 "Remove private ASNs in outbound updates\n")
596c17ba 4688
5000f21c
DS
4689DEFUN (neighbor_remove_private_as_all,
4690 neighbor_remove_private_as_all_cmd,
9ccf14f7 4691 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4692 NEIGHBOR_STR
4693 NEIGHBOR_ADDR_STR2
4694 "Remove private ASNs in outbound updates\n"
efd7904e 4695 "Apply to all AS numbers\n")
5000f21c 4696{
d62a17ae 4697 int idx_peer = 1;
4698 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4699 bgp_node_safi(vty),
4700 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
4701}
4702
d62a17ae 4703ALIAS_HIDDEN(neighbor_remove_private_as_all,
4704 neighbor_remove_private_as_all_hidden_cmd,
4705 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4707 "Remove private ASNs in outbound updates\n"
4708 "Apply to all AS numbers")
596c17ba 4709
5000f21c
DS
4710DEFUN (neighbor_remove_private_as_replace_as,
4711 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4712 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4713 NEIGHBOR_STR
4714 NEIGHBOR_ADDR_STR2
4715 "Remove private ASNs in outbound updates\n"
4716 "Replace private ASNs with our ASN in outbound updates\n")
4717{
d62a17ae 4718 int idx_peer = 1;
4719 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4720 bgp_node_safi(vty),
4721 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
4722}
4723
d62a17ae 4724ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4725 neighbor_remove_private_as_replace_as_hidden_cmd,
4726 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4727 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4728 "Remove private ASNs in outbound updates\n"
4729 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4730
5000f21c
DS
4731DEFUN (neighbor_remove_private_as_all_replace_as,
4732 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4733 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4734 NEIGHBOR_STR
4735 NEIGHBOR_ADDR_STR2
4736 "Remove private ASNs in outbound updates\n"
16cedbb0 4737 "Apply to all AS numbers\n"
5000f21c
DS
4738 "Replace private ASNs with our ASN in outbound updates\n")
4739{
d62a17ae 4740 int idx_peer = 1;
4741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4742 bgp_node_safi(vty),
4743 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4744}
4745
d62a17ae 4746ALIAS_HIDDEN(
4747 neighbor_remove_private_as_all_replace_as,
4748 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4749 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4750 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4751 "Remove private ASNs in outbound updates\n"
4752 "Apply to all AS numbers\n"
4753 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4754
718e3744 4755DEFUN (no_neighbor_remove_private_as,
4756 no_neighbor_remove_private_as_cmd,
9ccf14f7 4757 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4758 NO_STR
4759 NEIGHBOR_STR
4760 NEIGHBOR_ADDR_STR2
5000f21c 4761 "Remove private ASNs in outbound updates\n")
718e3744 4762{
d62a17ae 4763 int idx_peer = 2;
4764 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4765 bgp_node_afi(vty), bgp_node_safi(vty),
4766 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4767}
6b0655a2 4768
d62a17ae 4769ALIAS_HIDDEN(no_neighbor_remove_private_as,
4770 no_neighbor_remove_private_as_hidden_cmd,
4771 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4773 "Remove private ASNs in outbound updates\n")
596c17ba 4774
88b8ed8d 4775DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4776 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4777 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4778 NO_STR
4779 NEIGHBOR_STR
4780 NEIGHBOR_ADDR_STR2
4781 "Remove private ASNs in outbound updates\n"
16cedbb0 4782 "Apply to all AS numbers\n")
88b8ed8d 4783{
d62a17ae 4784 int idx_peer = 2;
4785 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4786 bgp_node_afi(vty), bgp_node_safi(vty),
4787 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 4788}
5000f21c 4789
d62a17ae 4790ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4791 no_neighbor_remove_private_as_all_hidden_cmd,
4792 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4793 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4794 "Remove private ASNs in outbound updates\n"
4795 "Apply to all AS numbers\n")
596c17ba 4796
88b8ed8d 4797DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4798 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4799 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4800 NO_STR
4801 NEIGHBOR_STR
4802 NEIGHBOR_ADDR_STR2
4803 "Remove private ASNs in outbound updates\n"
4804 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4805{
d62a17ae 4806 int idx_peer = 2;
4807 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4808 bgp_node_afi(vty), bgp_node_safi(vty),
4809 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 4810}
5000f21c 4811
d62a17ae 4812ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4813 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4814 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4815 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4816 "Remove private ASNs in outbound updates\n"
4817 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4818
88b8ed8d 4819DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4820 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4821 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4822 NO_STR
4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
4825 "Remove private ASNs in outbound updates\n"
16cedbb0 4826 "Apply to all AS numbers\n"
5000f21c 4827 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4828{
d62a17ae 4829 int idx_peer = 2;
4830 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4831 bgp_node_afi(vty), bgp_node_safi(vty),
4832 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4833}
5000f21c 4834
d62a17ae 4835ALIAS_HIDDEN(
4836 no_neighbor_remove_private_as_all_replace_as,
4837 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4838 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4840 "Remove private ASNs in outbound updates\n"
4841 "Apply to all AS numbers\n"
4842 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4843
5000f21c 4844
718e3744 4845/* neighbor send-community. */
4846DEFUN (neighbor_send_community,
4847 neighbor_send_community_cmd,
9ccf14f7 4848 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4849 NEIGHBOR_STR
4850 NEIGHBOR_ADDR_STR2
4851 "Send Community attribute to this neighbor\n")
4852{
d62a17ae 4853 int idx_peer = 1;
27c05d4d 4854
d62a17ae 4855 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4856 bgp_node_safi(vty),
4857 PEER_FLAG_SEND_COMMUNITY);
718e3744 4858}
4859
d62a17ae 4860ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4861 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4863 "Send Community attribute to this neighbor\n")
596c17ba 4864
718e3744 4865DEFUN (no_neighbor_send_community,
4866 no_neighbor_send_community_cmd,
9ccf14f7 4867 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4868 NO_STR
4869 NEIGHBOR_STR
4870 NEIGHBOR_ADDR_STR2
4871 "Send Community attribute to this neighbor\n")
4872{
d62a17ae 4873 int idx_peer = 2;
27c05d4d 4874
d62a17ae 4875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4876 bgp_node_afi(vty), bgp_node_safi(vty),
4877 PEER_FLAG_SEND_COMMUNITY);
718e3744 4878}
6b0655a2 4879
d62a17ae 4880ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4881 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4882 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4883 "Send Community attribute to this neighbor\n")
596c17ba 4884
718e3744 4885/* neighbor send-community extended. */
4886DEFUN (neighbor_send_community_type,
4887 neighbor_send_community_type_cmd,
57d187bc 4888 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4889 NEIGHBOR_STR
4890 NEIGHBOR_ADDR_STR2
4891 "Send Community attribute to this neighbor\n"
4892 "Send Standard and Extended Community attributes\n"
57d187bc 4893 "Send Standard, Large and Extended Community attributes\n"
718e3744 4894 "Send Extended Community attributes\n"
57d187bc
JS
4895 "Send Standard Community attributes\n"
4896 "Send Large Community attributes\n")
718e3744 4897{
27c05d4d 4898 int idx_peer = 1;
d7c0a89a 4899 uint32_t flag = 0;
27c05d4d 4900 const char *type = argv[argc - 1]->text;
d62a17ae 4901
27c05d4d 4902 if (strmatch(type, "standard")) {
d62a17ae 4903 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
27c05d4d 4904 } else if (strmatch(type, "extended")) {
d62a17ae 4905 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4906 } else if (strmatch(type, "large")) {
d62a17ae 4907 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
27c05d4d 4908 } else if (strmatch(type, "both")) {
d62a17ae 4909 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4910 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d 4911 } else { /* if (strmatch(type, "all")) */
d62a17ae 4912 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4913 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4914 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4915 }
4916
27c05d4d 4917 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
d62a17ae 4918 bgp_node_safi(vty), flag);
4919}
4920
4921ALIAS_HIDDEN(
4922 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4923 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4925 "Send Community attribute to this neighbor\n"
4926 "Send Standard and Extended Community attributes\n"
4927 "Send Standard, Large and Extended Community attributes\n"
4928 "Send Extended Community attributes\n"
4929 "Send Standard Community attributes\n"
4930 "Send Large Community attributes\n")
596c17ba 4931
718e3744 4932DEFUN (no_neighbor_send_community_type,
4933 no_neighbor_send_community_type_cmd,
57d187bc 4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4935 NO_STR
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
4938 "Send Community attribute to this neighbor\n"
4939 "Send Standard and Extended Community attributes\n"
57d187bc 4940 "Send Standard, Large and Extended Community attributes\n"
718e3744 4941 "Send Extended Community attributes\n"
57d187bc
JS
4942 "Send Standard Community attributes\n"
4943 "Send Large Community attributes\n")
718e3744 4944{
d62a17ae 4945 int idx_peer = 2;
27c05d4d 4946 uint32_t flag = 0;
d62a17ae 4947 const char *type = argv[argc - 1]->text;
4948
27c05d4d
PM
4949 if (strmatch(type, "standard")) {
4950 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4951 } else if (strmatch(type, "extended")) {
4952 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4953 } else if (strmatch(type, "large")) {
4954 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4955 } else if (strmatch(type, "both")) {
4956 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4957 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4958 } else { /* if (strmatch(type, "all")) */
4959 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4960 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4961 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4962 }
4963
4964 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4965 bgp_node_afi(vty), bgp_node_safi(vty),
4966 flag);
d62a17ae 4967}
4968
4969ALIAS_HIDDEN(
4970 no_neighbor_send_community_type,
4971 no_neighbor_send_community_type_hidden_cmd,
4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Send Community attribute to this neighbor\n"
4975 "Send Standard and Extended Community attributes\n"
4976 "Send Standard, Large and Extended Community attributes\n"
4977 "Send Extended Community attributes\n"
4978 "Send Standard Community attributes\n"
4979 "Send Large Community attributes\n")
596c17ba 4980
718e3744 4981/* neighbor soft-reconfig. */
4982DEFUN (neighbor_soft_reconfiguration,
4983 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4984 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4985 NEIGHBOR_STR
4986 NEIGHBOR_ADDR_STR2
4987 "Per neighbor soft reconfiguration\n"
4988 "Allow inbound soft reconfiguration for this neighbor\n")
4989{
d62a17ae 4990 int idx_peer = 1;
4991 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4992 bgp_node_safi(vty),
4993 PEER_FLAG_SOFT_RECONFIG);
718e3744 4994}
4995
d62a17ae 4996ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4997 neighbor_soft_reconfiguration_hidden_cmd,
4998 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4999 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5000 "Per neighbor soft reconfiguration\n"
5001 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5002
718e3744 5003DEFUN (no_neighbor_soft_reconfiguration,
5004 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5005 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5006 NO_STR
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Per neighbor soft reconfiguration\n"
5010 "Allow inbound soft reconfiguration for this neighbor\n")
5011{
d62a17ae 5012 int idx_peer = 2;
5013 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5014 bgp_node_afi(vty), bgp_node_safi(vty),
5015 PEER_FLAG_SOFT_RECONFIG);
718e3744 5016}
6b0655a2 5017
d62a17ae 5018ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5019 no_neighbor_soft_reconfiguration_hidden_cmd,
5020 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5021 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5022 "Per neighbor soft reconfiguration\n"
5023 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5024
718e3744 5025DEFUN (neighbor_route_reflector_client,
5026 neighbor_route_reflector_client_cmd,
9ccf14f7 5027 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR2
5030 "Configure a neighbor as Route Reflector client\n")
5031{
d62a17ae 5032 int idx_peer = 1;
5033 struct peer *peer;
718e3744 5034
5035
d62a17ae 5036 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5037 if (!peer)
5038 return CMD_WARNING_CONFIG_FAILED;
718e3744 5039
d62a17ae 5040 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5041 bgp_node_safi(vty),
5042 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5043}
5044
d62a17ae 5045ALIAS_HIDDEN(neighbor_route_reflector_client,
5046 neighbor_route_reflector_client_hidden_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5048 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5049 "Configure a neighbor as Route Reflector client\n")
596c17ba 5050
718e3744 5051DEFUN (no_neighbor_route_reflector_client,
5052 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5053 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5054 NO_STR
5055 NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "Configure a neighbor as Route Reflector client\n")
5058{
d62a17ae 5059 int idx_peer = 2;
5060 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5061 bgp_node_afi(vty), bgp_node_safi(vty),
5062 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5063}
6b0655a2 5064
d62a17ae 5065ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5066 no_neighbor_route_reflector_client_hidden_cmd,
5067 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5068 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5069 "Configure a neighbor as Route Reflector client\n")
596c17ba 5070
718e3744 5071/* neighbor route-server-client. */
5072DEFUN (neighbor_route_server_client,
5073 neighbor_route_server_client_cmd,
9ccf14f7 5074 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Configure a neighbor as Route Server client\n")
5078{
d62a17ae 5079 int idx_peer = 1;
5080 struct peer *peer;
2a3d5731 5081
d62a17ae 5082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 if (!peer)
5084 return CMD_WARNING_CONFIG_FAILED;
5085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5086 bgp_node_safi(vty),
5087 PEER_FLAG_RSERVER_CLIENT);
718e3744 5088}
5089
d62a17ae 5090ALIAS_HIDDEN(neighbor_route_server_client,
5091 neighbor_route_server_client_hidden_cmd,
5092 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5094 "Configure a neighbor as Route Server client\n")
596c17ba 5095
718e3744 5096DEFUN (no_neighbor_route_server_client,
5097 no_neighbor_route_server_client_cmd,
9ccf14f7 5098 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5099 NO_STR
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Configure a neighbor as Route Server client\n")
fee0f4c6 5103{
d62a17ae 5104 int idx_peer = 2;
5105 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5106 bgp_node_afi(vty), bgp_node_safi(vty),
5107 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5108}
6b0655a2 5109
d62a17ae 5110ALIAS_HIDDEN(no_neighbor_route_server_client,
5111 no_neighbor_route_server_client_hidden_cmd,
5112 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5113 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5114 "Configure a neighbor as Route Server client\n")
596c17ba 5115
fee0f4c6 5116DEFUN (neighbor_nexthop_local_unchanged,
5117 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5118 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "Configure treatment of outgoing link-local nexthop attribute\n"
5122 "Leave link-local nexthop unchanged for this peer\n")
5123{
d62a17ae 5124 int idx_peer = 1;
5125 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5126 bgp_node_safi(vty),
5127 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5128}
6b0655a2 5129
fee0f4c6 5130DEFUN (no_neighbor_nexthop_local_unchanged,
5131 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Configure treatment of outgoing link-local-nexthop attribute\n"
5137 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5138{
d62a17ae 5139 int idx_peer = 2;
5140 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5141 bgp_node_afi(vty), bgp_node_safi(vty),
5142 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5143}
6b0655a2 5144
718e3744 5145DEFUN (neighbor_attr_unchanged,
5146 neighbor_attr_unchanged_cmd,
a8206004 5147 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5148 NEIGHBOR_STR
5149 NEIGHBOR_ADDR_STR2
5150 "BGP attribute is propagated unchanged to this neighbor\n"
5151 "As-path attribute\n"
5152 "Nexthop attribute\n"
a8206004 5153 "Med attribute\n")
718e3744 5154{
d62a17ae 5155 int idx = 0;
8eeb0335
DW
5156 char *peer_str = argv[1]->arg;
5157 struct peer *peer;
d7c0a89a 5158 uint16_t flags = 0;
8eeb0335
DW
5159 afi_t afi = bgp_node_afi(vty);
5160 safi_t safi = bgp_node_safi(vty);
5161
5162 peer = peer_and_group_lookup_vty(vty, peer_str);
5163 if (!peer)
5164 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5165
5166 if (argv_find(argv, argc, "as-path", &idx))
5167 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5168 idx = 0;
5169 if (argv_find(argv, argc, "next-hop", &idx))
5170 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5171 idx = 0;
5172 if (argv_find(argv, argc, "med", &idx))
5173 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5174
8eeb0335
DW
5175 /* no flags means all of them! */
5176 if (!flags) {
d62a17ae 5177 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5178 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5179 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 5180 } else {
a4d82a8a
PZ
5181 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
5182 && peer_af_flag_check(peer, afi, safi,
5183 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
5184 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5185 PEER_FLAG_AS_PATH_UNCHANGED);
5186 }
5187
a4d82a8a
PZ
5188 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
5189 && peer_af_flag_check(peer, afi, safi,
5190 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
5191 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5192 PEER_FLAG_NEXTHOP_UNCHANGED);
5193 }
5194
a4d82a8a
PZ
5195 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
5196 && peer_af_flag_check(peer, afi, safi,
5197 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
5198 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5199 PEER_FLAG_MED_UNCHANGED);
5200 }
d62a17ae 5201 }
5202
8eeb0335 5203 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 5204}
5205
5206ALIAS_HIDDEN(
5207 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5208 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5210 "BGP attribute is propagated unchanged to this neighbor\n"
5211 "As-path attribute\n"
5212 "Nexthop attribute\n"
5213 "Med attribute\n")
596c17ba 5214
718e3744 5215DEFUN (no_neighbor_attr_unchanged,
5216 no_neighbor_attr_unchanged_cmd,
a8206004 5217 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5218 NO_STR
718e3744 5219 NEIGHBOR_STR
5220 NEIGHBOR_ADDR_STR2
31500417
DW
5221 "BGP attribute is propagated unchanged to this neighbor\n"
5222 "As-path attribute\n"
40e718b5 5223 "Nexthop attribute\n"
a8206004 5224 "Med attribute\n")
718e3744 5225{
d62a17ae 5226 int idx = 0;
5227 char *peer = argv[2]->arg;
d7c0a89a 5228 uint16_t flags = 0;
d62a17ae 5229
5230 if (argv_find(argv, argc, "as-path", &idx))
5231 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5232 idx = 0;
5233 if (argv_find(argv, argc, "next-hop", &idx))
5234 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5235 idx = 0;
5236 if (argv_find(argv, argc, "med", &idx))
5237 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5238
5239 if (!flags) // no flags means all of them!
5240 {
5241 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
5242 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
5243 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
5244 }
5245
5246 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
5247 bgp_node_safi(vty), flags);
5248}
5249
5250ALIAS_HIDDEN(
5251 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5252 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5253 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5254 "BGP attribute is propagated unchanged to this neighbor\n"
5255 "As-path attribute\n"
5256 "Nexthop attribute\n"
5257 "Med attribute\n")
718e3744 5258
718e3744 5259/* EBGP multihop configuration. */
d62a17ae 5260static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5261 const char *ttl_str)
718e3744 5262{
d62a17ae 5263 struct peer *peer;
5264 unsigned int ttl;
718e3744 5265
d62a17ae 5266 peer = peer_and_group_lookup_vty(vty, ip_str);
5267 if (!peer)
5268 return CMD_WARNING_CONFIG_FAILED;
718e3744 5269
d62a17ae 5270 if (peer->conf_if)
5271 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5272
d62a17ae 5273 if (!ttl_str)
5274 ttl = MAXTTL;
5275 else
5276 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5277
d62a17ae 5278 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5279}
5280
d62a17ae 5281static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5282{
d62a17ae 5283 struct peer *peer;
718e3744 5284
d62a17ae 5285 peer = peer_and_group_lookup_vty(vty, ip_str);
5286 if (!peer)
5287 return CMD_WARNING_CONFIG_FAILED;
718e3744 5288
d62a17ae 5289 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 5290}
5291
5292/* neighbor ebgp-multihop. */
5293DEFUN (neighbor_ebgp_multihop,
5294 neighbor_ebgp_multihop_cmd,
9ccf14f7 5295 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 5296 NEIGHBOR_STR
5297 NEIGHBOR_ADDR_STR2
5298 "Allow EBGP neighbors not on directly connected networks\n")
5299{
d62a17ae 5300 int idx_peer = 1;
5301 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5302}
5303
5304DEFUN (neighbor_ebgp_multihop_ttl,
5305 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 5306 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 5307 NEIGHBOR_STR
5308 NEIGHBOR_ADDR_STR2
5309 "Allow EBGP neighbors not on directly connected networks\n"
5310 "maximum hop count\n")
5311{
d62a17ae 5312 int idx_peer = 1;
5313 int idx_number = 3;
5314 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
5315 argv[idx_number]->arg);
718e3744 5316}
5317
5318DEFUN (no_neighbor_ebgp_multihop,
5319 no_neighbor_ebgp_multihop_cmd,
a636c635 5320 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 5321 NO_STR
5322 NEIGHBOR_STR
5323 NEIGHBOR_ADDR_STR2
a636c635
DW
5324 "Allow EBGP neighbors not on directly connected networks\n"
5325 "maximum hop count\n")
718e3744 5326{
d62a17ae 5327 int idx_peer = 2;
5328 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5329}
5330
6b0655a2 5331
6ffd2079 5332/* disable-connected-check */
5333DEFUN (neighbor_disable_connected_check,
5334 neighbor_disable_connected_check_cmd,
7ebe625c 5335 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5336 NEIGHBOR_STR
7ebe625c 5337 NEIGHBOR_ADDR_STR2
a636c635
DW
5338 "one-hop away EBGP peer using loopback address\n"
5339 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5340{
d62a17ae 5341 int idx_peer = 1;
5342 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5343 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5344}
5345
5346DEFUN (no_neighbor_disable_connected_check,
5347 no_neighbor_disable_connected_check_cmd,
7ebe625c 5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 5349 NO_STR
5350 NEIGHBOR_STR
7ebe625c 5351 NEIGHBOR_ADDR_STR2
a636c635
DW
5352 "one-hop away EBGP peer using loopback address\n"
5353 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 5354{
d62a17ae 5355 int idx_peer = 2;
5356 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5357 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 5358}
5359
47cbc09b
PM
5360
5361/* enforce-first-as */
5362DEFUN (neighbor_enforce_first_as,
5363 neighbor_enforce_first_as_cmd,
5364 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5365 NEIGHBOR_STR
5366 NEIGHBOR_ADDR_STR2
5367 "Enforce the first AS for EBGP routes\n")
5368{
5369 int idx_peer = 1;
5370
5371 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5372 PEER_FLAG_ENFORCE_FIRST_AS);
5373}
5374
5375DEFUN (no_neighbor_enforce_first_as,
5376 no_neighbor_enforce_first_as_cmd,
5377 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
5378 NO_STR
5379 NEIGHBOR_STR
5380 NEIGHBOR_ADDR_STR2
5381 "Enforce the first AS for EBGP routes\n")
5382{
5383 int idx_peer = 2;
5384
5385 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5386 PEER_FLAG_ENFORCE_FIRST_AS);
5387}
5388
5389
718e3744 5390DEFUN (neighbor_description,
5391 neighbor_description_cmd,
e961923c 5392 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 5393 NEIGHBOR_STR
5394 NEIGHBOR_ADDR_STR2
5395 "Neighbor specific description\n"
5396 "Up to 80 characters describing this neighbor\n")
5397{
d62a17ae 5398 int idx_peer = 1;
5399 int idx_line = 3;
5400 struct peer *peer;
5401 char *str;
718e3744 5402
d62a17ae 5403 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5404 if (!peer)
5405 return CMD_WARNING_CONFIG_FAILED;
718e3744 5406
d62a17ae 5407 str = argv_concat(argv, argc, idx_line);
718e3744 5408
d62a17ae 5409 peer_description_set(peer, str);
718e3744 5410
d62a17ae 5411 XFREE(MTYPE_TMP, str);
718e3744 5412
d62a17ae 5413 return CMD_SUCCESS;
718e3744 5414}
5415
5416DEFUN (no_neighbor_description,
5417 no_neighbor_description_cmd,
a14810f4 5418 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 5419 NO_STR
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
a14810f4 5422 "Neighbor specific description\n")
718e3744 5423{
d62a17ae 5424 int idx_peer = 2;
5425 struct peer *peer;
718e3744 5426
d62a17ae 5427 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5428 if (!peer)
5429 return CMD_WARNING_CONFIG_FAILED;
718e3744 5430
d62a17ae 5431 peer_description_unset(peer);
718e3744 5432
d62a17ae 5433 return CMD_SUCCESS;
718e3744 5434}
5435
a14810f4
PM
5436ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
5437 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
5438 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5439 "Neighbor specific description\n"
5440 "Up to 80 characters describing this neighbor\n")
6b0655a2 5441
718e3744 5442/* Neighbor update-source. */
d62a17ae 5443static int peer_update_source_vty(struct vty *vty, const char *peer_str,
5444 const char *source_str)
5445{
5446 struct peer *peer;
5447 struct prefix p;
a14810f4 5448 union sockunion su;
d62a17ae 5449
5450 peer = peer_and_group_lookup_vty(vty, peer_str);
5451 if (!peer)
5452 return CMD_WARNING_CONFIG_FAILED;
5453
5454 if (peer->conf_if)
5455 return CMD_WARNING;
5456
5457 if (source_str) {
a14810f4 5458 if (str2sockunion(source_str, &su) == 0)
d62a17ae 5459 peer_update_source_addr_set(peer, &su);
5460 else {
5461 if (str2prefix(source_str, &p)) {
5462 vty_out(vty,
5463 "%% Invalid update-source, remove prefix length \n");
5464 return CMD_WARNING_CONFIG_FAILED;
5465 } else
5466 peer_update_source_if_set(peer, source_str);
5467 }
5468 } else
5469 peer_update_source_unset(peer);
5470
5471 return CMD_SUCCESS;
5472}
5473
5474#define BGP_UPDATE_SOURCE_HELP_STR \
5475 "IPv4 address\n" \
5476 "IPv6 address\n" \
5477 "Interface name (requires zebra to be running)\n"
369688c0 5478
718e3744 5479DEFUN (neighbor_update_source,
5480 neighbor_update_source_cmd,
9ccf14f7 5481 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 5482 NEIGHBOR_STR
5483 NEIGHBOR_ADDR_STR2
5484 "Source of routing updates\n"
369688c0 5485 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5486{
d62a17ae 5487 int idx_peer = 1;
5488 int idx_peer_2 = 3;
5489 return peer_update_source_vty(vty, argv[idx_peer]->arg,
5490 argv[idx_peer_2]->arg);
718e3744 5491}
5492
5493DEFUN (no_neighbor_update_source,
5494 no_neighbor_update_source_cmd,
c7178fe7 5495 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 5496 NO_STR
5497 NEIGHBOR_STR
5498 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
5499 "Source of routing updates\n"
5500 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 5501{
d62a17ae 5502 int idx_peer = 2;
5503 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5504}
6b0655a2 5505
d62a17ae 5506static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
5507 afi_t afi, safi_t safi,
5508 const char *rmap, int set)
718e3744 5509{
d62a17ae 5510 int ret;
5511 struct peer *peer;
80912664 5512 struct route_map *route_map = NULL;
718e3744 5513
d62a17ae 5514 peer = peer_and_group_lookup_vty(vty, peer_str);
5515 if (!peer)
5516 return CMD_WARNING_CONFIG_FAILED;
718e3744 5517
1de27621 5518 if (set) {
80912664
DS
5519 if (rmap)
5520 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
5521 ret = peer_default_originate_set(peer, afi, safi,
5522 rmap, route_map);
5523 } else
d62a17ae 5524 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 5525
d62a17ae 5526 return bgp_vty_return(vty, ret);
718e3744 5527}
5528
5529/* neighbor default-originate. */
5530DEFUN (neighbor_default_originate,
5531 neighbor_default_originate_cmd,
9ccf14f7 5532 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 5533 NEIGHBOR_STR
5534 NEIGHBOR_ADDR_STR2
5535 "Originate default route to this neighbor\n")
5536{
d62a17ae 5537 int idx_peer = 1;
5538 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5539 bgp_node_afi(vty),
5540 bgp_node_safi(vty), NULL, 1);
718e3744 5541}
5542
d62a17ae 5543ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
5544 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
5545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Originate default route to this neighbor\n")
596c17ba 5547
718e3744 5548DEFUN (neighbor_default_originate_rmap,
5549 neighbor_default_originate_rmap_cmd,
9ccf14f7 5550 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 5551 NEIGHBOR_STR
5552 NEIGHBOR_ADDR_STR2
5553 "Originate default route to this neighbor\n"
5554 "Route-map to specify criteria to originate default\n"
5555 "route-map name\n")
5556{
d62a17ae 5557 int idx_peer = 1;
5558 int idx_word = 4;
5559 return peer_default_originate_set_vty(
5560 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5561 argv[idx_word]->arg, 1);
718e3744 5562}
5563
d62a17ae 5564ALIAS_HIDDEN(
5565 neighbor_default_originate_rmap,
5566 neighbor_default_originate_rmap_hidden_cmd,
5567 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
5568 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5569 "Originate default route to this neighbor\n"
5570 "Route-map to specify criteria to originate default\n"
5571 "route-map name\n")
596c17ba 5572
718e3744 5573DEFUN (no_neighbor_default_originate,
5574 no_neighbor_default_originate_cmd,
a636c635 5575 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 5576 NO_STR
5577 NEIGHBOR_STR
5578 NEIGHBOR_ADDR_STR2
a636c635
DW
5579 "Originate default route to this neighbor\n"
5580 "Route-map to specify criteria to originate default\n"
5581 "route-map name\n")
718e3744 5582{
d62a17ae 5583 int idx_peer = 2;
5584 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
5585 bgp_node_afi(vty),
5586 bgp_node_safi(vty), NULL, 0);
718e3744 5587}
5588
d62a17ae 5589ALIAS_HIDDEN(
5590 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
5591 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
5592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5593 "Originate default route to this neighbor\n"
5594 "Route-map to specify criteria to originate default\n"
5595 "route-map name\n")
596c17ba 5596
6b0655a2 5597
718e3744 5598/* Set neighbor's BGP port. */
d62a17ae 5599static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
5600 const char *port_str)
5601{
5602 struct peer *peer;
d7c0a89a 5603 uint16_t port;
d62a17ae 5604 struct servent *sp;
5605
5606 peer = peer_lookup_vty(vty, ip_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 if (!port_str) {
5611 sp = getservbyname("bgp", "tcp");
5612 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
5613 } else {
5614 port = strtoul(port_str, NULL, 10);
5615 }
718e3744 5616
d62a17ae 5617 peer_port_set(peer, port);
718e3744 5618
d62a17ae 5619 return CMD_SUCCESS;
718e3744 5620}
5621
f418446b 5622/* Set specified peer's BGP port. */
718e3744 5623DEFUN (neighbor_port,
5624 neighbor_port_cmd,
9ccf14f7 5625 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 5626 NEIGHBOR_STR
5627 NEIGHBOR_ADDR_STR
5628 "Neighbor's BGP port\n"
5629 "TCP port number\n")
5630{
d62a17ae 5631 int idx_ip = 1;
5632 int idx_number = 3;
5633 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5634 argv[idx_number]->arg);
718e3744 5635}
5636
5637DEFUN (no_neighbor_port,
5638 no_neighbor_port_cmd,
9ccf14f7 5639 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 5640 NO_STR
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR
8334fd5a
DW
5643 "Neighbor's BGP port\n"
5644 "TCP port number\n")
718e3744 5645{
d62a17ae 5646 int idx_ip = 2;
5647 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 5648}
5649
6b0655a2 5650
718e3744 5651/* neighbor weight. */
d62a17ae 5652static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5653 safi_t safi, const char *weight_str)
718e3744 5654{
d62a17ae 5655 int ret;
5656 struct peer *peer;
5657 unsigned long weight;
718e3744 5658
d62a17ae 5659 peer = peer_and_group_lookup_vty(vty, ip_str);
5660 if (!peer)
5661 return CMD_WARNING_CONFIG_FAILED;
718e3744 5662
d62a17ae 5663 weight = strtoul(weight_str, NULL, 10);
718e3744 5664
d62a17ae 5665 ret = peer_weight_set(peer, afi, safi, weight);
5666 return bgp_vty_return(vty, ret);
718e3744 5667}
5668
d62a17ae 5669static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5670 safi_t safi)
718e3744 5671{
d62a17ae 5672 int ret;
5673 struct peer *peer;
718e3744 5674
d62a17ae 5675 peer = peer_and_group_lookup_vty(vty, ip_str);
5676 if (!peer)
5677 return CMD_WARNING_CONFIG_FAILED;
718e3744 5678
d62a17ae 5679 ret = peer_weight_unset(peer, afi, safi);
5680 return bgp_vty_return(vty, ret);
718e3744 5681}
5682
5683DEFUN (neighbor_weight,
5684 neighbor_weight_cmd,
9ccf14f7 5685 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 5686 NEIGHBOR_STR
5687 NEIGHBOR_ADDR_STR2
5688 "Set default weight for routes from this neighbor\n"
5689 "default weight\n")
5690{
d62a17ae 5691 int idx_peer = 1;
5692 int idx_number = 3;
5693 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5694 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 5695}
5696
d62a17ae 5697ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5698 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5700 "Set default weight for routes from this neighbor\n"
5701 "default weight\n")
596c17ba 5702
718e3744 5703DEFUN (no_neighbor_weight,
5704 no_neighbor_weight_cmd,
9ccf14f7 5705 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5706 NO_STR
5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5709 "Set default weight for routes from this neighbor\n"
5710 "default weight\n")
718e3744 5711{
d62a17ae 5712 int idx_peer = 2;
5713 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5714 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 5715}
5716
d62a17ae 5717ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5719 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5720 "Set default weight for routes from this neighbor\n"
5721 "default weight\n")
596c17ba 5722
6b0655a2 5723
718e3744 5724/* Override capability negotiation. */
5725DEFUN (neighbor_override_capability,
5726 neighbor_override_capability_cmd,
9ccf14f7 5727 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Override capability negotiation result\n")
5731{
d62a17ae 5732 int idx_peer = 1;
5733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5734 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5735}
5736
5737DEFUN (no_neighbor_override_capability,
5738 no_neighbor_override_capability_cmd,
9ccf14f7 5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5740 NO_STR
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Override capability negotiation result\n")
5744{
d62a17ae 5745 int idx_peer = 2;
5746 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5747 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5748}
6b0655a2 5749
718e3744 5750DEFUN (neighbor_strict_capability,
5751 neighbor_strict_capability_cmd,
9fb964de 5752 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5753 NEIGHBOR_STR
9fb964de 5754 NEIGHBOR_ADDR_STR2
718e3744 5755 "Strict capability negotiation match\n")
5756{
9fb964de
PM
5757 int idx_peer = 1;
5758
5759 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 5760 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5761}
5762
5763DEFUN (no_neighbor_strict_capability,
5764 no_neighbor_strict_capability_cmd,
9fb964de 5765 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 5766 NO_STR
5767 NEIGHBOR_STR
9fb964de 5768 NEIGHBOR_ADDR_STR2
718e3744 5769 "Strict capability negotiation match\n")
5770{
9fb964de
PM
5771 int idx_peer = 2;
5772
5773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 5774 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5775}
6b0655a2 5776
d62a17ae 5777static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5778 const char *keep_str, const char *hold_str)
718e3744 5779{
d62a17ae 5780 int ret;
5781 struct peer *peer;
d7c0a89a
QY
5782 uint32_t keepalive;
5783 uint32_t holdtime;
718e3744 5784
d62a17ae 5785 peer = peer_and_group_lookup_vty(vty, ip_str);
5786 if (!peer)
5787 return CMD_WARNING_CONFIG_FAILED;
718e3744 5788
d62a17ae 5789 keepalive = strtoul(keep_str, NULL, 10);
5790 holdtime = strtoul(hold_str, NULL, 10);
718e3744 5791
d62a17ae 5792 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 5793
d62a17ae 5794 return bgp_vty_return(vty, ret);
718e3744 5795}
6b0655a2 5796
d62a17ae 5797static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5798{
d62a17ae 5799 int ret;
5800 struct peer *peer;
718e3744 5801
d62a17ae 5802 peer = peer_and_group_lookup_vty(vty, ip_str);
5803 if (!peer)
5804 return CMD_WARNING_CONFIG_FAILED;
718e3744 5805
d62a17ae 5806 ret = peer_timers_unset(peer);
718e3744 5807
d62a17ae 5808 return bgp_vty_return(vty, ret);
718e3744 5809}
5810
5811DEFUN (neighbor_timers,
5812 neighbor_timers_cmd,
9ccf14f7 5813 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5814 NEIGHBOR_STR
5815 NEIGHBOR_ADDR_STR2
5816 "BGP per neighbor timers\n"
5817 "Keepalive interval\n"
5818 "Holdtime\n")
5819{
d62a17ae 5820 int idx_peer = 1;
5821 int idx_number = 3;
5822 int idx_number_2 = 4;
5823 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5824 argv[idx_number]->arg,
5825 argv[idx_number_2]->arg);
718e3744 5826}
5827
5828DEFUN (no_neighbor_timers,
5829 no_neighbor_timers_cmd,
9ccf14f7 5830 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5831 NO_STR
5832 NEIGHBOR_STR
5833 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5834 "BGP per neighbor timers\n"
5835 "Keepalive interval\n"
5836 "Holdtime\n")
718e3744 5837{
d62a17ae 5838 int idx_peer = 2;
5839 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5840}
6b0655a2 5841
813d4307 5842
d62a17ae 5843static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5844 const char *time_str)
718e3744 5845{
d62a17ae 5846 int ret;
5847 struct peer *peer;
d7c0a89a 5848 uint32_t connect;
718e3744 5849
d62a17ae 5850 peer = peer_and_group_lookup_vty(vty, ip_str);
5851 if (!peer)
5852 return CMD_WARNING_CONFIG_FAILED;
718e3744 5853
d62a17ae 5854 connect = strtoul(time_str, NULL, 10);
718e3744 5855
d62a17ae 5856 ret = peer_timers_connect_set(peer, connect);
718e3744 5857
d62a17ae 5858 return bgp_vty_return(vty, ret);
718e3744 5859}
5860
d62a17ae 5861static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5862{
d62a17ae 5863 int ret;
5864 struct peer *peer;
718e3744 5865
d62a17ae 5866 peer = peer_and_group_lookup_vty(vty, ip_str);
5867 if (!peer)
5868 return CMD_WARNING_CONFIG_FAILED;
718e3744 5869
d62a17ae 5870 ret = peer_timers_connect_unset(peer);
718e3744 5871
d62a17ae 5872 return bgp_vty_return(vty, ret);
718e3744 5873}
5874
5875DEFUN (neighbor_timers_connect,
5876 neighbor_timers_connect_cmd,
9ccf14f7 5877 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5878 NEIGHBOR_STR
966f821c 5879 NEIGHBOR_ADDR_STR2
718e3744 5880 "BGP per neighbor timers\n"
5881 "BGP connect timer\n"
5882 "Connect timer\n")
5883{
d62a17ae 5884 int idx_peer = 1;
5885 int idx_number = 4;
5886 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5887 argv[idx_number]->arg);
718e3744 5888}
5889
5890DEFUN (no_neighbor_timers_connect,
5891 no_neighbor_timers_connect_cmd,
9ccf14f7 5892 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5893 NO_STR
5894 NEIGHBOR_STR
966f821c 5895 NEIGHBOR_ADDR_STR2
718e3744 5896 "BGP per neighbor timers\n"
8334fd5a
DW
5897 "BGP connect timer\n"
5898 "Connect timer\n")
718e3744 5899{
d62a17ae 5900 int idx_peer = 2;
5901 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5902}
5903
6b0655a2 5904
d62a17ae 5905static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5906 const char *time_str, int set)
718e3744 5907{
d62a17ae 5908 int ret;
5909 struct peer *peer;
d7c0a89a 5910 uint32_t routeadv = 0;
718e3744 5911
d62a17ae 5912 peer = peer_and_group_lookup_vty(vty, ip_str);
5913 if (!peer)
5914 return CMD_WARNING_CONFIG_FAILED;
718e3744 5915
d62a17ae 5916 if (time_str)
5917 routeadv = strtoul(time_str, NULL, 10);
718e3744 5918
d62a17ae 5919 if (set)
5920 ret = peer_advertise_interval_set(peer, routeadv);
5921 else
5922 ret = peer_advertise_interval_unset(peer);
718e3744 5923
d62a17ae 5924 return bgp_vty_return(vty, ret);
718e3744 5925}
5926
5927DEFUN (neighbor_advertise_interval,
5928 neighbor_advertise_interval_cmd,
9ccf14f7 5929 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5930 NEIGHBOR_STR
966f821c 5931 NEIGHBOR_ADDR_STR2
718e3744 5932 "Minimum interval between sending BGP routing updates\n"
5933 "time in seconds\n")
5934{
d62a17ae 5935 int idx_peer = 1;
5936 int idx_number = 3;
5937 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5938 argv[idx_number]->arg, 1);
718e3744 5939}
5940
5941DEFUN (no_neighbor_advertise_interval,
5942 no_neighbor_advertise_interval_cmd,
9ccf14f7 5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5944 NO_STR
5945 NEIGHBOR_STR
966f821c 5946 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5947 "Minimum interval between sending BGP routing updates\n"
5948 "time in seconds\n")
718e3744 5949{
d62a17ae 5950 int idx_peer = 2;
5951 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5952}
5953
6b0655a2 5954
518f0eb1
DS
5955/* Time to wait before processing route-map updates */
5956DEFUN (bgp_set_route_map_delay_timer,
5957 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5958 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5959 SET_STR
5960 "BGP route-map delay timer\n"
5961 "Time in secs to wait before processing route-map changes\n"
f414725f 5962 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5963{
d62a17ae 5964 int idx_number = 3;
d7c0a89a 5965 uint32_t rmap_delay_timer;
d62a17ae 5966
5967 if (argv[idx_number]->arg) {
5968 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5969 bm->rmap_update_timer = rmap_delay_timer;
5970
5971 /* if the dynamic update handling is being disabled, and a timer
5972 * is
5973 * running, stop the timer and act as if the timer has already
5974 * fired.
5975 */
5976 if (!rmap_delay_timer && bm->t_rmap_update) {
5977 BGP_TIMER_OFF(bm->t_rmap_update);
5978 thread_execute(bm->master, bgp_route_map_update_timer,
5979 NULL, 0);
5980 }
5981 return CMD_SUCCESS;
5982 } else {
5983 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5984 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5985 }
518f0eb1
DS
5986}
5987
5988DEFUN (no_bgp_set_route_map_delay_timer,
5989 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5990 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5991 NO_STR
3a2d747c 5992 BGP_STR
518f0eb1 5993 "Default BGP route-map delay timer\n"
8334fd5a
DW
5994 "Reset to default time to wait for processing route-map changes\n"
5995 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5996{
518f0eb1 5997
d62a17ae 5998 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5999
d62a17ae 6000 return CMD_SUCCESS;
518f0eb1
DS
6001}
6002
f414725f 6003
718e3744 6004/* neighbor interface */
d62a17ae 6005static int peer_interface_vty(struct vty *vty, const char *ip_str,
6006 const char *str)
718e3744 6007{
d62a17ae 6008 struct peer *peer;
718e3744 6009
d62a17ae 6010 peer = peer_lookup_vty(vty, ip_str);
6011 if (!peer || peer->conf_if) {
6012 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6013 return CMD_WARNING_CONFIG_FAILED;
6014 }
718e3744 6015
d62a17ae 6016 if (str)
6017 peer_interface_set(peer, str);
6018 else
6019 peer_interface_unset(peer);
718e3744 6020
d62a17ae 6021 return CMD_SUCCESS;
718e3744 6022}
6023
6024DEFUN (neighbor_interface,
6025 neighbor_interface_cmd,
9ccf14f7 6026 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR
6029 "Interface\n"
6030 "Interface name\n")
6031{
d62a17ae 6032 int idx_ip = 1;
6033 int idx_word = 3;
6034 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6035}
6036
6037DEFUN (no_neighbor_interface,
6038 no_neighbor_interface_cmd,
9ccf14f7 6039 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6040 NO_STR
6041 NEIGHBOR_STR
16cedbb0 6042 NEIGHBOR_ADDR_STR2
718e3744 6043 "Interface\n"
6044 "Interface name\n")
6045{
d62a17ae 6046 int idx_peer = 2;
6047 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6048}
6b0655a2 6049
718e3744 6050DEFUN (neighbor_distribute_list,
6051 neighbor_distribute_list_cmd,
9ccf14f7 6052 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6053 NEIGHBOR_STR
6054 NEIGHBOR_ADDR_STR2
6055 "Filter updates to/from this neighbor\n"
6056 "IP access-list number\n"
6057 "IP access-list number (expanded range)\n"
6058 "IP Access-list name\n"
6059 "Filter incoming updates\n"
6060 "Filter outgoing updates\n")
6061{
d62a17ae 6062 int idx_peer = 1;
6063 int idx_acl = 3;
6064 int direct, ret;
6065 struct peer *peer;
a8206004 6066
d62a17ae 6067 const char *pstr = argv[idx_peer]->arg;
6068 const char *acl = argv[idx_acl]->arg;
6069 const char *inout = argv[argc - 1]->text;
a8206004 6070
d62a17ae 6071 peer = peer_and_group_lookup_vty(vty, pstr);
6072 if (!peer)
6073 return CMD_WARNING_CONFIG_FAILED;
a8206004 6074
d62a17ae 6075 /* Check filter direction. */
6076 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6077 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6078 direct, acl);
a8206004 6079
d62a17ae 6080 return bgp_vty_return(vty, ret);
718e3744 6081}
6082
d62a17ae 6083ALIAS_HIDDEN(
6084 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6085 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6086 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6087 "Filter updates to/from this neighbor\n"
6088 "IP access-list number\n"
6089 "IP access-list number (expanded range)\n"
6090 "IP Access-list name\n"
6091 "Filter incoming updates\n"
6092 "Filter outgoing updates\n")
596c17ba 6093
718e3744 6094DEFUN (no_neighbor_distribute_list,
6095 no_neighbor_distribute_list_cmd,
9ccf14f7 6096 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6097 NO_STR
6098 NEIGHBOR_STR
6099 NEIGHBOR_ADDR_STR2
6100 "Filter updates to/from this neighbor\n"
6101 "IP access-list number\n"
6102 "IP access-list number (expanded range)\n"
6103 "IP Access-list name\n"
6104 "Filter incoming updates\n"
6105 "Filter outgoing updates\n")
6106{
d62a17ae 6107 int idx_peer = 2;
6108 int direct, ret;
6109 struct peer *peer;
a8206004 6110
d62a17ae 6111 const char *pstr = argv[idx_peer]->arg;
6112 const char *inout = argv[argc - 1]->text;
a8206004 6113
d62a17ae 6114 peer = peer_and_group_lookup_vty(vty, pstr);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
a8206004 6117
d62a17ae 6118 /* Check filter direction. */
6119 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6120 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6121 direct);
a8206004 6122
d62a17ae 6123 return bgp_vty_return(vty, ret);
718e3744 6124}
6b0655a2 6125
d62a17ae 6126ALIAS_HIDDEN(
6127 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6128 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6129 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6130 "Filter updates to/from this neighbor\n"
6131 "IP access-list number\n"
6132 "IP access-list number (expanded range)\n"
6133 "IP Access-list name\n"
6134 "Filter incoming updates\n"
6135 "Filter outgoing updates\n")
596c17ba 6136
718e3744 6137/* Set prefix list to the peer. */
d62a17ae 6138static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6139 afi_t afi, safi_t safi,
6140 const char *name_str,
6141 const char *direct_str)
718e3744 6142{
d62a17ae 6143 int ret;
d62a17ae 6144 int direct = FILTER_IN;
cf9ac8bf 6145 struct peer *peer;
718e3744 6146
d62a17ae 6147 peer = peer_and_group_lookup_vty(vty, ip_str);
6148 if (!peer)
6149 return CMD_WARNING_CONFIG_FAILED;
718e3744 6150
d62a17ae 6151 /* Check filter direction. */
6152 if (strncmp(direct_str, "i", 1) == 0)
6153 direct = FILTER_IN;
6154 else if (strncmp(direct_str, "o", 1) == 0)
6155 direct = FILTER_OUT;
718e3744 6156
d62a17ae 6157 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6158
d62a17ae 6159 return bgp_vty_return(vty, ret);
718e3744 6160}
6161
d62a17ae 6162static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6163 afi_t afi, safi_t safi,
6164 const char *direct_str)
718e3744 6165{
d62a17ae 6166 int ret;
6167 struct peer *peer;
6168 int direct = FILTER_IN;
718e3744 6169
d62a17ae 6170 peer = peer_and_group_lookup_vty(vty, ip_str);
6171 if (!peer)
6172 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6173
d62a17ae 6174 /* Check filter direction. */
6175 if (strncmp(direct_str, "i", 1) == 0)
6176 direct = FILTER_IN;
6177 else if (strncmp(direct_str, "o", 1) == 0)
6178 direct = FILTER_OUT;
718e3744 6179
d62a17ae 6180 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6181
d62a17ae 6182 return bgp_vty_return(vty, ret);
718e3744 6183}
6184
6185DEFUN (neighbor_prefix_list,
6186 neighbor_prefix_list_cmd,
9ccf14f7 6187 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6188 NEIGHBOR_STR
6189 NEIGHBOR_ADDR_STR2
6190 "Filter updates to/from this neighbor\n"
6191 "Name of a prefix list\n"
6192 "Filter incoming updates\n"
6193 "Filter outgoing updates\n")
6194{
d62a17ae 6195 int idx_peer = 1;
6196 int idx_word = 3;
6197 int idx_in_out = 4;
6198 return peer_prefix_list_set_vty(
6199 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6200 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6201}
6202
d62a17ae 6203ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6205 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6206 "Filter updates to/from this neighbor\n"
6207 "Name of a prefix list\n"
6208 "Filter incoming updates\n"
6209 "Filter outgoing updates\n")
596c17ba 6210
718e3744 6211DEFUN (no_neighbor_prefix_list,
6212 no_neighbor_prefix_list_cmd,
9ccf14f7 6213 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6214 NO_STR
6215 NEIGHBOR_STR
6216 NEIGHBOR_ADDR_STR2
6217 "Filter updates to/from this neighbor\n"
6218 "Name of a prefix list\n"
6219 "Filter incoming updates\n"
6220 "Filter outgoing updates\n")
6221{
d62a17ae 6222 int idx_peer = 2;
6223 int idx_in_out = 5;
6224 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6225 bgp_node_afi(vty), bgp_node_safi(vty),
6226 argv[idx_in_out]->arg);
718e3744 6227}
6b0655a2 6228
d62a17ae 6229ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6230 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6231 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6232 "Filter updates to/from this neighbor\n"
6233 "Name of a prefix list\n"
6234 "Filter incoming updates\n"
6235 "Filter outgoing updates\n")
596c17ba 6236
d62a17ae 6237static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6238 safi_t safi, const char *name_str,
6239 const char *direct_str)
718e3744 6240{
d62a17ae 6241 int ret;
6242 struct peer *peer;
6243 int direct = FILTER_IN;
718e3744 6244
d62a17ae 6245 peer = peer_and_group_lookup_vty(vty, ip_str);
6246 if (!peer)
6247 return CMD_WARNING_CONFIG_FAILED;
718e3744 6248
d62a17ae 6249 /* Check filter direction. */
6250 if (strncmp(direct_str, "i", 1) == 0)
6251 direct = FILTER_IN;
6252 else if (strncmp(direct_str, "o", 1) == 0)
6253 direct = FILTER_OUT;
718e3744 6254
d62a17ae 6255 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6256
d62a17ae 6257 return bgp_vty_return(vty, ret);
718e3744 6258}
6259
d62a17ae 6260static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6261 safi_t safi, const char *direct_str)
718e3744 6262{
d62a17ae 6263 int ret;
6264 struct peer *peer;
6265 int direct = FILTER_IN;
718e3744 6266
d62a17ae 6267 peer = peer_and_group_lookup_vty(vty, ip_str);
6268 if (!peer)
6269 return CMD_WARNING_CONFIG_FAILED;
718e3744 6270
d62a17ae 6271 /* Check filter direction. */
6272 if (strncmp(direct_str, "i", 1) == 0)
6273 direct = FILTER_IN;
6274 else if (strncmp(direct_str, "o", 1) == 0)
6275 direct = FILTER_OUT;
718e3744 6276
d62a17ae 6277 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6278
d62a17ae 6279 return bgp_vty_return(vty, ret);
718e3744 6280}
6281
6282DEFUN (neighbor_filter_list,
6283 neighbor_filter_list_cmd,
9ccf14f7 6284 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Establish BGP filters\n"
6288 "AS path access-list name\n"
6289 "Filter incoming routes\n"
6290 "Filter outgoing routes\n")
6291{
d62a17ae 6292 int idx_peer = 1;
6293 int idx_word = 3;
6294 int idx_in_out = 4;
6295 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6296 bgp_node_safi(vty), argv[idx_word]->arg,
6297 argv[idx_in_out]->arg);
718e3744 6298}
6299
d62a17ae 6300ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
6301 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6302 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6303 "Establish BGP filters\n"
6304 "AS path access-list name\n"
6305 "Filter incoming routes\n"
6306 "Filter outgoing routes\n")
596c17ba 6307
718e3744 6308DEFUN (no_neighbor_filter_list,
6309 no_neighbor_filter_list_cmd,
9ccf14f7 6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6311 NO_STR
6312 NEIGHBOR_STR
6313 NEIGHBOR_ADDR_STR2
6314 "Establish BGP filters\n"
6315 "AS path access-list name\n"
6316 "Filter incoming routes\n"
6317 "Filter outgoing routes\n")
6318{
d62a17ae 6319 int idx_peer = 2;
6320 int idx_in_out = 5;
6321 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
6322 bgp_node_afi(vty), bgp_node_safi(vty),
6323 argv[idx_in_out]->arg);
718e3744 6324}
6b0655a2 6325
d62a17ae 6326ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
6327 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
6328 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6329 "Establish BGP filters\n"
6330 "AS path access-list name\n"
6331 "Filter incoming routes\n"
6332 "Filter outgoing routes\n")
596c17ba 6333
718e3744 6334/* Set route-map to the peer. */
d62a17ae 6335static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
6336 afi_t afi, safi_t safi, const char *name_str,
6337 const char *direct_str)
718e3744 6338{
d62a17ae 6339 int ret;
6340 struct peer *peer;
6341 int direct = RMAP_IN;
1de27621 6342 struct route_map *route_map;
718e3744 6343
d62a17ae 6344 peer = peer_and_group_lookup_vty(vty, ip_str);
6345 if (!peer)
6346 return CMD_WARNING_CONFIG_FAILED;
718e3744 6347
d62a17ae 6348 /* Check filter direction. */
6349 if (strncmp(direct_str, "in", 2) == 0)
6350 direct = RMAP_IN;
6351 else if (strncmp(direct_str, "o", 1) == 0)
6352 direct = RMAP_OUT;
718e3744 6353
1de27621
DA
6354 route_map = route_map_lookup_warn_noexist(vty, name_str);
6355 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 6356
d62a17ae 6357 return bgp_vty_return(vty, ret);
718e3744 6358}
6359
d62a17ae 6360static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
6361 afi_t afi, safi_t safi,
6362 const char *direct_str)
718e3744 6363{
d62a17ae 6364 int ret;
6365 struct peer *peer;
6366 int direct = RMAP_IN;
718e3744 6367
d62a17ae 6368 peer = peer_and_group_lookup_vty(vty, ip_str);
6369 if (!peer)
6370 return CMD_WARNING_CONFIG_FAILED;
718e3744 6371
d62a17ae 6372 /* Check filter direction. */
6373 if (strncmp(direct_str, "in", 2) == 0)
6374 direct = RMAP_IN;
6375 else if (strncmp(direct_str, "o", 1) == 0)
6376 direct = RMAP_OUT;
718e3744 6377
d62a17ae 6378 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 6379
d62a17ae 6380 return bgp_vty_return(vty, ret);
718e3744 6381}
6382
6383DEFUN (neighbor_route_map,
6384 neighbor_route_map_cmd,
9ccf14f7 6385 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6386 NEIGHBOR_STR
6387 NEIGHBOR_ADDR_STR2
6388 "Apply route map to neighbor\n"
6389 "Name of route map\n"
6390 "Apply map to incoming routes\n"
2a3d5731 6391 "Apply map to outbound routes\n")
718e3744 6392{
d62a17ae 6393 int idx_peer = 1;
6394 int idx_word = 3;
6395 int idx_in_out = 4;
6396 return peer_route_map_set_vty(
6397 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6398 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6399}
6400
d62a17ae 6401ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
6402 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6404 "Apply route map to neighbor\n"
6405 "Name of route map\n"
6406 "Apply map to incoming routes\n"
6407 "Apply map to outbound routes\n")
596c17ba 6408
718e3744 6409DEFUN (no_neighbor_route_map,
6410 no_neighbor_route_map_cmd,
9ccf14f7 6411 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 6412 NO_STR
6413 NEIGHBOR_STR
6414 NEIGHBOR_ADDR_STR2
6415 "Apply route map to neighbor\n"
6416 "Name of route map\n"
6417 "Apply map to incoming routes\n"
2a3d5731 6418 "Apply map to outbound routes\n")
718e3744 6419{
d62a17ae 6420 int idx_peer = 2;
6421 int idx_in_out = 5;
6422 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
6423 bgp_node_afi(vty), bgp_node_safi(vty),
6424 argv[idx_in_out]->arg);
718e3744 6425}
6b0655a2 6426
d62a17ae 6427ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
6428 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
6429 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6430 "Apply route map to neighbor\n"
6431 "Name of route map\n"
6432 "Apply map to incoming routes\n"
6433 "Apply map to outbound routes\n")
596c17ba 6434
718e3744 6435/* Set unsuppress-map to the peer. */
d62a17ae 6436static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
6437 afi_t afi, safi_t safi,
6438 const char *name_str)
718e3744 6439{
d62a17ae 6440 int ret;
6441 struct peer *peer;
1de27621 6442 struct route_map *route_map;
718e3744 6443
d62a17ae 6444 peer = peer_and_group_lookup_vty(vty, ip_str);
6445 if (!peer)
6446 return CMD_WARNING_CONFIG_FAILED;
718e3744 6447
1de27621
DA
6448 route_map = route_map_lookup_warn_noexist(vty, name_str);
6449 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 6450
d62a17ae 6451 return bgp_vty_return(vty, ret);
718e3744 6452}
6453
6454/* Unset route-map from the peer. */
d62a17ae 6455static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
6456 afi_t afi, safi_t safi)
718e3744 6457{
d62a17ae 6458 int ret;
6459 struct peer *peer;
718e3744 6460
d62a17ae 6461 peer = peer_and_group_lookup_vty(vty, ip_str);
6462 if (!peer)
6463 return CMD_WARNING_CONFIG_FAILED;
718e3744 6464
d62a17ae 6465 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 6466
d62a17ae 6467 return bgp_vty_return(vty, ret);
718e3744 6468}
6469
6470DEFUN (neighbor_unsuppress_map,
6471 neighbor_unsuppress_map_cmd,
9ccf14f7 6472 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6473 NEIGHBOR_STR
6474 NEIGHBOR_ADDR_STR2
6475 "Route-map to selectively unsuppress suppressed routes\n"
6476 "Name of route map\n")
6477{
d62a17ae 6478 int idx_peer = 1;
6479 int idx_word = 3;
6480 return peer_unsuppress_map_set_vty(
6481 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6482 argv[idx_word]->arg);
718e3744 6483}
6484
d62a17ae 6485ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
6486 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6487 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6488 "Route-map to selectively unsuppress suppressed routes\n"
6489 "Name of route map\n")
596c17ba 6490
718e3744 6491DEFUN (no_neighbor_unsuppress_map,
6492 no_neighbor_unsuppress_map_cmd,
9ccf14f7 6493 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 6494 NO_STR
6495 NEIGHBOR_STR
6496 NEIGHBOR_ADDR_STR2
6497 "Route-map to selectively unsuppress suppressed routes\n"
6498 "Name of route map\n")
6499{
d62a17ae 6500 int idx_peer = 2;
6501 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
6502 bgp_node_afi(vty),
6503 bgp_node_safi(vty));
718e3744 6504}
6b0655a2 6505
d62a17ae 6506ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
6507 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
6508 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6509 "Route-map to selectively unsuppress suppressed routes\n"
6510 "Name of route map\n")
596c17ba 6511
d62a17ae 6512static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
6513 afi_t afi, safi_t safi,
6514 const char *num_str,
6515 const char *threshold_str, int warning,
6516 const char *restart_str)
718e3744 6517{
d62a17ae 6518 int ret;
6519 struct peer *peer;
d7c0a89a
QY
6520 uint32_t max;
6521 uint8_t threshold;
6522 uint16_t restart;
718e3744 6523
d62a17ae 6524 peer = peer_and_group_lookup_vty(vty, ip_str);
6525 if (!peer)
6526 return CMD_WARNING_CONFIG_FAILED;
718e3744 6527
d62a17ae 6528 max = strtoul(num_str, NULL, 10);
6529 if (threshold_str)
6530 threshold = atoi(threshold_str);
6531 else
6532 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 6533
d62a17ae 6534 if (restart_str)
6535 restart = atoi(restart_str);
6536 else
6537 restart = 0;
0a486e5f 6538
d62a17ae 6539 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
6540 restart);
718e3744 6541
d62a17ae 6542 return bgp_vty_return(vty, ret);
718e3744 6543}
6544
d62a17ae 6545static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
6546 afi_t afi, safi_t safi)
718e3744 6547{
d62a17ae 6548 int ret;
6549 struct peer *peer;
718e3744 6550
d62a17ae 6551 peer = peer_and_group_lookup_vty(vty, ip_str);
6552 if (!peer)
6553 return CMD_WARNING_CONFIG_FAILED;
718e3744 6554
d62a17ae 6555 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 6556
d62a17ae 6557 return bgp_vty_return(vty, ret);
718e3744 6558}
6559
fde246e8
DA
6560/* Maximum number of prefix to be sent to the neighbor. */
6561DEFUN(neighbor_maximum_prefix_out,
6562 neighbor_maximum_prefix_out_cmd,
6563 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
6564 NEIGHBOR_STR
6565 NEIGHBOR_ADDR_STR2
6566 "Maximum number of prefixes to be sent to this peer\n"
6567 "Maximum no. of prefix limit\n")
6568{
6569 int idx_peer = 1;
6570 int idx_number = 3;
6571 struct peer *peer;
6572 uint32_t max;
6573 afi_t afi = bgp_node_afi(vty);
6574 safi_t safi = bgp_node_safi(vty);
6575
6576 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6577 if (!peer)
6578 return CMD_WARNING_CONFIG_FAILED;
6579
6580 max = strtoul(argv[idx_number]->arg, NULL, 10);
6581
6582 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
6583 peer->pmax_out[afi][safi] = max;
6584
6585 return CMD_SUCCESS;
6586}
6587
6588DEFUN(no_neighbor_maximum_prefix_out,
6589 no_neighbor_maximum_prefix_out_cmd,
6590 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
6591 NO_STR
6592 NEIGHBOR_STR
6593 NEIGHBOR_ADDR_STR2
6594 "Maximum number of prefixes to be sent to this peer\n")
6595{
6596 int idx_peer = 2;
6597 struct peer *peer;
6598 afi_t afi = bgp_node_afi(vty);
6599 safi_t safi = bgp_node_safi(vty);
6600
6601 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6602 if (!peer)
6603 return CMD_WARNING_CONFIG_FAILED;
6604
6605 peer->pmax_out[afi][safi] = 0;
6606
6607 return CMD_SUCCESS;
6608}
6609
718e3744 6610/* Maximum number of prefix configuration. prefix count is different
6611 for each peer configuration. So this configuration can be set for
6612 each peer configuration. */
6613DEFUN (neighbor_maximum_prefix,
6614 neighbor_maximum_prefix_cmd,
9ccf14f7 6615 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 6616 NEIGHBOR_STR
6617 NEIGHBOR_ADDR_STR2
6618 "Maximum number of prefix accept from this peer\n"
6619 "maximum no. of prefix limit\n")
6620{
d62a17ae 6621 int idx_peer = 1;
6622 int idx_number = 3;
6623 return peer_maximum_prefix_set_vty(
6624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6625 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 6626}
6627
d62a17ae 6628ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
6629 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
6630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6631 "Maximum number of prefix accept from this peer\n"
6632 "maximum no. of prefix limit\n")
596c17ba 6633
e0701b79 6634DEFUN (neighbor_maximum_prefix_threshold,
6635 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 6636 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 6637 NEIGHBOR_STR
6638 NEIGHBOR_ADDR_STR2
6639 "Maximum number of prefix accept from this peer\n"
6640 "maximum no. of prefix limit\n"
6641 "Threshold value (%) at which to generate a warning msg\n")
6642{
d62a17ae 6643 int idx_peer = 1;
6644 int idx_number = 3;
6645 int idx_number_2 = 4;
6646 return peer_maximum_prefix_set_vty(
6647 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6648 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 6649}
e0701b79 6650
d62a17ae 6651ALIAS_HIDDEN(
6652 neighbor_maximum_prefix_threshold,
6653 neighbor_maximum_prefix_threshold_hidden_cmd,
6654 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
6655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6656 "Maximum number of prefix accept from this peer\n"
6657 "maximum no. of prefix limit\n"
6658 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 6659
718e3744 6660DEFUN (neighbor_maximum_prefix_warning,
6661 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 6662 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 6663 NEIGHBOR_STR
6664 NEIGHBOR_ADDR_STR2
6665 "Maximum number of prefix accept from this peer\n"
6666 "maximum no. of prefix limit\n"
6667 "Only give warning message when limit is exceeded\n")
6668{
d62a17ae 6669 int idx_peer = 1;
6670 int idx_number = 3;
6671 return peer_maximum_prefix_set_vty(
6672 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6673 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 6674}
6675
d62a17ae 6676ALIAS_HIDDEN(
6677 neighbor_maximum_prefix_warning,
6678 neighbor_maximum_prefix_warning_hidden_cmd,
6679 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6681 "Maximum number of prefix accept from this peer\n"
6682 "maximum no. of prefix limit\n"
6683 "Only give warning message when limit is exceeded\n")
596c17ba 6684
e0701b79 6685DEFUN (neighbor_maximum_prefix_threshold_warning,
6686 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 6687 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 6688 NEIGHBOR_STR
6689 NEIGHBOR_ADDR_STR2
6690 "Maximum number of prefix accept from this peer\n"
6691 "maximum no. of prefix limit\n"
6692 "Threshold value (%) at which to generate a warning msg\n"
6693 "Only give warning message when limit is exceeded\n")
6694{
d62a17ae 6695 int idx_peer = 1;
6696 int idx_number = 3;
6697 int idx_number_2 = 4;
6698 return peer_maximum_prefix_set_vty(
6699 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6700 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 6701}
6702
d62a17ae 6703ALIAS_HIDDEN(
6704 neighbor_maximum_prefix_threshold_warning,
6705 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6706 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6707 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6708 "Maximum number of prefix accept from this peer\n"
6709 "maximum no. of prefix limit\n"
6710 "Threshold value (%) at which to generate a warning msg\n"
6711 "Only give warning message when limit is exceeded\n")
596c17ba 6712
0a486e5f 6713DEFUN (neighbor_maximum_prefix_restart,
6714 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6715 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6716 NEIGHBOR_STR
6717 NEIGHBOR_ADDR_STR2
6718 "Maximum number of prefix accept from this peer\n"
6719 "maximum no. of prefix limit\n"
6720 "Restart bgp connection after limit is exceeded\n"
efd7904e 6721 "Restart interval in minutes\n")
0a486e5f 6722{
d62a17ae 6723 int idx_peer = 1;
6724 int idx_number = 3;
6725 int idx_number_2 = 5;
6726 return peer_maximum_prefix_set_vty(
6727 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6728 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6729}
6730
d62a17ae 6731ALIAS_HIDDEN(
6732 neighbor_maximum_prefix_restart,
6733 neighbor_maximum_prefix_restart_hidden_cmd,
6734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6736 "Maximum number of prefix accept from this peer\n"
6737 "maximum no. of prefix limit\n"
6738 "Restart bgp connection after limit is exceeded\n"
efd7904e 6739 "Restart interval in minutes\n")
596c17ba 6740
0a486e5f 6741DEFUN (neighbor_maximum_prefix_threshold_restart,
6742 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6744 NEIGHBOR_STR
6745 NEIGHBOR_ADDR_STR2
16cedbb0 6746 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6747 "maximum no. of prefix limit\n"
6748 "Threshold value (%) at which to generate a warning msg\n"
6749 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6750 "Restart interval in minutes\n")
0a486e5f 6751{
d62a17ae 6752 int idx_peer = 1;
6753 int idx_number = 3;
6754 int idx_number_2 = 4;
6755 int idx_number_3 = 6;
6756 return peer_maximum_prefix_set_vty(
6757 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6758 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6759 argv[idx_number_3]->arg);
6760}
6761
6762ALIAS_HIDDEN(
6763 neighbor_maximum_prefix_threshold_restart,
6764 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6765 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6767 "Maximum number of prefixes to accept from this peer\n"
6768 "maximum no. of prefix limit\n"
6769 "Threshold value (%) at which to generate a warning msg\n"
6770 "Restart bgp connection after limit is exceeded\n"
6771 "Restart interval in minutes\n")
596c17ba 6772
718e3744 6773DEFUN (no_neighbor_maximum_prefix,
6774 no_neighbor_maximum_prefix_cmd,
d04c479d 6775 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6776 NO_STR
6777 NEIGHBOR_STR
6778 NEIGHBOR_ADDR_STR2
16cedbb0 6779 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6780 "maximum no. of prefix limit\n"
6781 "Threshold value (%) at which to generate a warning msg\n"
6782 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6783 "Restart interval in minutes\n"
31500417 6784 "Only give warning message when limit is exceeded\n")
718e3744 6785{
d62a17ae 6786 int idx_peer = 2;
6787 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6788 bgp_node_afi(vty),
6789 bgp_node_safi(vty));
718e3744 6790}
e52702f2 6791
d62a17ae 6792ALIAS_HIDDEN(
6793 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6794 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6795 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6796 "Maximum number of prefixes to accept from this peer\n"
6797 "maximum no. of prefix limit\n"
6798 "Threshold value (%) at which to generate a warning msg\n"
6799 "Restart bgp connection after limit is exceeded\n"
6800 "Restart interval in minutes\n"
6801 "Only give warning message when limit is exceeded\n")
596c17ba 6802
718e3744 6803
718e3744 6804/* "neighbor allowas-in" */
6805DEFUN (neighbor_allowas_in,
6806 neighbor_allowas_in_cmd,
fd8503f5 6807 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6808 NEIGHBOR_STR
6809 NEIGHBOR_ADDR_STR2
31500417 6810 "Accept as-path with my AS present in it\n"
f79f7a7b 6811 "Number of occurrences of AS number\n"
fd8503f5 6812 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6813{
d62a17ae 6814 int idx_peer = 1;
6815 int idx_number_origin = 3;
6816 int ret;
6817 int origin = 0;
6818 struct peer *peer;
6819 int allow_num = 0;
6820
6821 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6822 if (!peer)
6823 return CMD_WARNING_CONFIG_FAILED;
6824
6825 if (argc <= idx_number_origin)
6826 allow_num = 3;
6827 else {
6828 if (argv[idx_number_origin]->type == WORD_TKN)
6829 origin = 1;
6830 else
6831 allow_num = atoi(argv[idx_number_origin]->arg);
6832 }
6833
6834 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6835 allow_num, origin);
6836
6837 return bgp_vty_return(vty, ret);
6838}
6839
6840ALIAS_HIDDEN(
6841 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6842 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6844 "Accept as-path with my AS present in it\n"
f79f7a7b 6845 "Number of occurrences of AS number\n"
d62a17ae 6846 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6847
718e3744 6848DEFUN (no_neighbor_allowas_in,
6849 no_neighbor_allowas_in_cmd,
fd8503f5 6850 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6851 NO_STR
6852 NEIGHBOR_STR
6853 NEIGHBOR_ADDR_STR2
8334fd5a 6854 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6855 "Number of occurrences of AS number\n"
fd8503f5 6856 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6857{
d62a17ae 6858 int idx_peer = 2;
6859 int ret;
6860 struct peer *peer;
718e3744 6861
d62a17ae 6862 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6863 if (!peer)
6864 return CMD_WARNING_CONFIG_FAILED;
718e3744 6865
d62a17ae 6866 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6867 bgp_node_safi(vty));
718e3744 6868
d62a17ae 6869 return bgp_vty_return(vty, ret);
718e3744 6870}
6b0655a2 6871
d62a17ae 6872ALIAS_HIDDEN(
6873 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6874 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6876 "allow local ASN appears in aspath attribute\n"
f79f7a7b 6877 "Number of occurrences of AS number\n"
d62a17ae 6878 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 6879
fa411a21
NH
6880DEFUN (neighbor_ttl_security,
6881 neighbor_ttl_security_cmd,
7ebe625c 6882 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 6883 NEIGHBOR_STR
7ebe625c 6884 NEIGHBOR_ADDR_STR2
16cedbb0 6885 "BGP ttl-security parameters\n"
d7fa34c1
QY
6886 "Specify the maximum number of hops to the BGP peer\n"
6887 "Number of hops to BGP peer\n")
fa411a21 6888{
d62a17ae 6889 int idx_peer = 1;
6890 int idx_number = 4;
6891 struct peer *peer;
6892 int gtsm_hops;
6893
6894 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6895 if (!peer)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6899
7ebe625c
QY
6900 /*
6901 * If 'neighbor swpX', then this is for directly connected peers,
6902 * we should not accept a ttl-security hops value greater than 1.
6903 */
6904 if (peer->conf_if && (gtsm_hops > 1)) {
6905 vty_out(vty,
6906 "%s is directly connected peer, hops cannot exceed 1\n",
6907 argv[idx_peer]->arg);
6908 return CMD_WARNING_CONFIG_FAILED;
6909 }
6910
d62a17ae 6911 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6912}
6913
6914DEFUN (no_neighbor_ttl_security,
6915 no_neighbor_ttl_security_cmd,
7ebe625c 6916 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6917 NO_STR
6918 NEIGHBOR_STR
7ebe625c 6919 NEIGHBOR_ADDR_STR2
16cedbb0 6920 "BGP ttl-security parameters\n"
3a2d747c
QY
6921 "Specify the maximum number of hops to the BGP peer\n"
6922 "Number of hops to BGP peer\n")
fa411a21 6923{
d62a17ae 6924 int idx_peer = 2;
6925 struct peer *peer;
fa411a21 6926
d62a17ae 6927 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6928 if (!peer)
6929 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6930
d62a17ae 6931 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6932}
6b0655a2 6933
adbac85e
DW
6934DEFUN (neighbor_addpath_tx_all_paths,
6935 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6936 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6937 NEIGHBOR_STR
6938 NEIGHBOR_ADDR_STR2
6939 "Use addpath to advertise all paths to a neighbor\n")
6940{
d62a17ae 6941 int idx_peer = 1;
6942 struct peer *peer;
adbac85e 6943
d62a17ae 6944 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6945 if (!peer)
6946 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6947
dcc68b5e
MS
6948 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6949 BGP_ADDPATH_ALL);
6950 return CMD_SUCCESS;
adbac85e
DW
6951}
6952
d62a17ae 6953ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6954 neighbor_addpath_tx_all_paths_hidden_cmd,
6955 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6958
adbac85e
DW
6959DEFUN (no_neighbor_addpath_tx_all_paths,
6960 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6961 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6962 NO_STR
6963 NEIGHBOR_STR
6964 NEIGHBOR_ADDR_STR2
6965 "Use addpath to advertise all paths to a neighbor\n")
6966{
d62a17ae 6967 int idx_peer = 2;
dcc68b5e
MS
6968 struct peer *peer;
6969
6970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6971 if (!peer)
6972 return CMD_WARNING_CONFIG_FAILED;
6973
6974 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6975 != BGP_ADDPATH_ALL) {
6976 vty_out(vty,
6977 "%% Peer not currently configured to transmit all paths.");
6978 return CMD_WARNING_CONFIG_FAILED;
6979 }
6980
6981 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6982 BGP_ADDPATH_NONE);
6983
6984 return CMD_SUCCESS;
adbac85e
DW
6985}
6986
d62a17ae 6987ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6988 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6989 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6990 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6991 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6992
06370dac
DW
6993DEFUN (neighbor_addpath_tx_bestpath_per_as,
6994 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6995 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6996 NEIGHBOR_STR
6997 NEIGHBOR_ADDR_STR2
6998 "Use addpath to advertise the bestpath per each neighboring AS\n")
6999{
d62a17ae 7000 int idx_peer = 1;
7001 struct peer *peer;
06370dac 7002
d62a17ae 7003 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7004 if (!peer)
7005 return CMD_WARNING_CONFIG_FAILED;
06370dac 7006
dcc68b5e
MS
7007 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7008 BGP_ADDPATH_BEST_PER_AS);
7009
7010 return CMD_SUCCESS;
06370dac
DW
7011}
7012
d62a17ae 7013ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7014 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7015 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7018
06370dac
DW
7019DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7020 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7021 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7022 NO_STR
7023 NEIGHBOR_STR
7024 NEIGHBOR_ADDR_STR2
7025 "Use addpath to advertise the bestpath per each neighboring AS\n")
7026{
d62a17ae 7027 int idx_peer = 2;
dcc68b5e
MS
7028 struct peer *peer;
7029
7030 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7031 if (!peer)
7032 return CMD_WARNING_CONFIG_FAILED;
7033
7034 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7035 != BGP_ADDPATH_BEST_PER_AS) {
7036 vty_out(vty,
7037 "%% Peer not currently configured to transmit all best path per as.");
7038 return CMD_WARNING_CONFIG_FAILED;
7039 }
7040
7041 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7042 BGP_ADDPATH_NONE);
7043
7044 return CMD_SUCCESS;
06370dac
DW
7045}
7046
d62a17ae 7047ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7048 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7049 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7051 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7052
2b31007c
RZ
7053DEFPY(
7054 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7055 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7056 NEIGHBOR_STR
7057 NEIGHBOR_ADDR_STR2
7058 "Detect AS loops before sending to neighbor\n")
7059{
7060 struct peer *peer;
7061
7062 peer = peer_and_group_lookup_vty(vty, neighbor);
7063 if (!peer)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 peer->as_path_loop_detection = true;
7067
7068 return CMD_SUCCESS;
7069}
7070
7071DEFPY(
7072 no_neighbor_aspath_loop_detection,
7073 no_neighbor_aspath_loop_detection_cmd,
7074 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7075 NO_STR
7076 NEIGHBOR_STR
7077 NEIGHBOR_ADDR_STR2
7078 "Detect AS loops before sending to neighbor\n")
7079{
7080 struct peer *peer;
7081
7082 peer = peer_and_group_lookup_vty(vty, neighbor);
7083 if (!peer)
7084 return CMD_WARNING_CONFIG_FAILED;
7085
7086 peer->as_path_loop_detection = false;
7087
7088 return CMD_SUCCESS;
7089}
7090
b9c7bc5a
PZ
7091static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
7092 struct ecommunity **list)
ddb5b488 7093{
b9c7bc5a
PZ
7094 struct ecommunity *ecom = NULL;
7095 struct ecommunity *ecomadd;
ddb5b488 7096
b9c7bc5a 7097 for (; argc; --argc, ++argv) {
ddb5b488 7098
b9c7bc5a
PZ
7099 ecomadd = ecommunity_str2com(argv[0]->arg,
7100 ECOMMUNITY_ROUTE_TARGET, 0);
7101 if (!ecomadd) {
7102 vty_out(vty, "Malformed community-list value\n");
7103 if (ecom)
7104 ecommunity_free(&ecom);
7105 return CMD_WARNING_CONFIG_FAILED;
7106 }
ddb5b488 7107
b9c7bc5a
PZ
7108 if (ecom) {
7109 ecommunity_merge(ecom, ecomadd);
7110 ecommunity_free(&ecomadd);
7111 } else {
7112 ecom = ecomadd;
7113 }
7114 }
7115
7116 if (*list) {
7117 ecommunity_free(&*list);
ddb5b488 7118 }
b9c7bc5a
PZ
7119 *list = ecom;
7120
7121 return CMD_SUCCESS;
ddb5b488
PZ
7122}
7123
0ca70ba5
DS
7124/*
7125 * v2vimport is true if we are handling a `import vrf ...` command
7126 */
7127static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7128{
0ca70ba5
DS
7129 afi_t afi;
7130
ddb5b488 7131 switch (vty->node) {
b9c7bc5a 7132 case BGP_IPV4_NODE:
0ca70ba5
DS
7133 afi = AFI_IP;
7134 break;
b9c7bc5a 7135 case BGP_IPV6_NODE:
0ca70ba5
DS
7136 afi = AFI_IP6;
7137 break;
ddb5b488
PZ
7138 default:
7139 vty_out(vty,
b9c7bc5a 7140 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7141 return AFI_MAX;
ddb5b488 7142 }
69b07479 7143
0ca70ba5
DS
7144 if (!v2vimport) {
7145 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7146 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7147 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7148 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7149 vty_out(vty,
7150 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7151 return AFI_MAX;
7152 }
7153 } else {
7154 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7155 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7156 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7157 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7158 vty_out(vty,
7159 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7160 return AFI_MAX;
7161 }
7162 }
7163 return afi;
ddb5b488
PZ
7164}
7165
b9c7bc5a
PZ
7166DEFPY (af_rd_vpn_export,
7167 af_rd_vpn_export_cmd,
7168 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7169 NO_STR
ddb5b488 7170 "Specify route distinguisher\n"
b9c7bc5a
PZ
7171 "Between current address-family and vpn\n"
7172 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7173 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7174{
7175 VTY_DECLVAR_CONTEXT(bgp, bgp);
7176 struct prefix_rd prd;
7177 int ret;
ddb5b488 7178 afi_t afi;
b9c7bc5a
PZ
7179 int idx = 0;
7180 int yes = 1;
ddb5b488 7181
b9c7bc5a 7182 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7183 yes = 0;
b9c7bc5a
PZ
7184
7185 if (yes) {
7186 ret = str2prefix_rd(rd_str, &prd);
7187 if (!ret) {
7188 vty_out(vty, "%% Malformed rd\n");
7189 return CMD_WARNING_CONFIG_FAILED;
7190 }
ddb5b488
PZ
7191 }
7192
0ca70ba5 7193 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7194 if (afi == AFI_MAX)
7195 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7196
69b07479
DS
7197 /*
7198 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7199 */
7200 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7201 bgp_get_default(), bgp);
ddb5b488 7202
69b07479
DS
7203 if (yes) {
7204 bgp->vpn_policy[afi].tovpn_rd = prd;
7205 SET_FLAG(bgp->vpn_policy[afi].flags,
7206 BGP_VPN_POLICY_TOVPN_RD_SET);
7207 } else {
7208 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7209 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7210 }
7211
69b07479
DS
7212 /* post-change: re-export vpn routes */
7213 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7214 bgp_get_default(), bgp);
7215
ddb5b488
PZ
7216 return CMD_SUCCESS;
7217}
7218
b9c7bc5a
PZ
7219ALIAS (af_rd_vpn_export,
7220 af_no_rd_vpn_export_cmd,
7221 "no rd vpn export",
ddb5b488 7222 NO_STR
b9c7bc5a
PZ
7223 "Specify route distinguisher\n"
7224 "Between current address-family and vpn\n"
7225 "For routes leaked from current address-family to vpn\n")
ddb5b488 7226
b9c7bc5a
PZ
7227DEFPY (af_label_vpn_export,
7228 af_label_vpn_export_cmd,
e70e9f8e 7229 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7230 NO_STR
ddb5b488 7231 "label value for VRF\n"
b9c7bc5a
PZ
7232 "Between current address-family and vpn\n"
7233 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
7234 "Label Value <0-1048575>\n"
7235 "Automatically assign a label\n")
ddb5b488
PZ
7236{
7237 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7238 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 7239 afi_t afi;
b9c7bc5a
PZ
7240 int idx = 0;
7241 int yes = 1;
7242
7243 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7244 yes = 0;
ddb5b488 7245
21a16cc2
PZ
7246 /* If "no ...", squash trailing parameter */
7247 if (!yes)
7248 label_auto = NULL;
7249
e70e9f8e
PZ
7250 if (yes) {
7251 if (!label_auto)
7252 label = label_val; /* parser should force unsigned */
7253 }
ddb5b488 7254
0ca70ba5 7255 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7256 if (afi == AFI_MAX)
7257 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 7258
e70e9f8e 7259
69b07479
DS
7260 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7261 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
7262 /* no change */
7263 return CMD_SUCCESS;
e70e9f8e 7264
69b07479
DS
7265 /*
7266 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7267 */
7268 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7269 bgp_get_default(), bgp);
7270
7271 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
7272 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
7273
7274 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
7275
7276 /*
7277 * label has previously been automatically
7278 * assigned by labelpool: release it
7279 *
7280 * NB if tovpn_label == MPLS_LABEL_NONE it
7281 * means the automatic assignment is in flight
7282 * and therefore the labelpool callback must
7283 * detect that the auto label is not needed.
7284 */
7285
7286 bgp_lp_release(LP_TYPE_VRF,
7287 &bgp->vpn_policy[afi],
7288 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 7289 }
69b07479
DS
7290 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7291 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7292 }
ddb5b488 7293
69b07479
DS
7294 bgp->vpn_policy[afi].tovpn_label = label;
7295 if (label_auto) {
7296 SET_FLAG(bgp->vpn_policy[afi].flags,
7297 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
7298 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
7299 vpn_leak_label_callback);
ddb5b488
PZ
7300 }
7301
69b07479
DS
7302 /* post-change: re-export vpn routes */
7303 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7304 bgp_get_default(), bgp);
7305
ddb5b488
PZ
7306 return CMD_SUCCESS;
7307}
7308
b9c7bc5a
PZ
7309ALIAS (af_label_vpn_export,
7310 af_no_label_vpn_export_cmd,
7311 "no label vpn export",
7312 NO_STR
7313 "label value for VRF\n"
7314 "Between current address-family and vpn\n"
7315 "For routes leaked from current address-family to vpn\n")
ddb5b488 7316
b9c7bc5a
PZ
7317DEFPY (af_nexthop_vpn_export,
7318 af_nexthop_vpn_export_cmd,
7319 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
7320 NO_STR
ddb5b488 7321 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
7322 "Between current address-family and vpn\n"
7323 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7324 "IPv4 prefix\n"
7325 "IPv6 prefix\n")
7326{
7327 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 7328 afi_t afi;
ddb5b488 7329 struct prefix p;
b9c7bc5a
PZ
7330 int idx = 0;
7331 int yes = 1;
ddb5b488 7332
b9c7bc5a 7333 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7334 yes = 0;
b9c7bc5a
PZ
7335
7336 if (yes) {
7337 if (!sockunion2hostprefix(nexthop_str, &p))
7338 return CMD_WARNING_CONFIG_FAILED;
7339 }
ddb5b488 7340
0ca70ba5 7341 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7342 if (afi == AFI_MAX)
7343 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7344
69b07479
DS
7345 /*
7346 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7347 */
7348 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7349 bgp_get_default(), bgp);
ddb5b488 7350
69b07479
DS
7351 if (yes) {
7352 bgp->vpn_policy[afi].tovpn_nexthop = p;
7353 SET_FLAG(bgp->vpn_policy[afi].flags,
7354 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
7355 } else {
7356 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7357 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
7358 }
7359
69b07479
DS
7360 /* post-change: re-export vpn routes */
7361 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7362 bgp_get_default(), bgp);
7363
ddb5b488
PZ
7364 return CMD_SUCCESS;
7365}
7366
b9c7bc5a
PZ
7367ALIAS (af_nexthop_vpn_export,
7368 af_no_nexthop_vpn_export_cmd,
7369 "no nexthop vpn export",
ddb5b488 7370 NO_STR
b9c7bc5a
PZ
7371 "Specify next hop to use for VRF advertised prefixes\n"
7372 "Between current address-family and vpn\n"
7373 "For routes leaked from current address-family to vpn\n")
ddb5b488 7374
b9c7bc5a 7375static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 7376{
b9c7bc5a
PZ
7377 if (!strcmp(dstr, "import")) {
7378 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7379 } else if (!strcmp(dstr, "export")) {
7380 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7381 } else if (!strcmp(dstr, "both")) {
7382 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
7383 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
7384 } else {
7385 vty_out(vty, "%% direction parse error\n");
7386 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7387 }
ddb5b488
PZ
7388 return CMD_SUCCESS;
7389}
7390
b9c7bc5a
PZ
7391DEFPY (af_rt_vpn_imexport,
7392 af_rt_vpn_imexport_cmd,
7393 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
7394 NO_STR
7395 "Specify route target list\n"
ddb5b488 7396 "Specify route target list\n"
b9c7bc5a
PZ
7397 "Between current address-family and vpn\n"
7398 "For routes leaked from vpn to current address-family: match any\n"
7399 "For routes leaked from current address-family to vpn: set\n"
7400 "both import: match any and export: set\n"
ddb5b488
PZ
7401 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7402{
7403 VTY_DECLVAR_CONTEXT(bgp, bgp);
7404 int ret;
7405 struct ecommunity *ecom = NULL;
7406 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7407 vpn_policy_direction_t dir;
7408 afi_t afi;
7409 int idx = 0;
b9c7bc5a 7410 int yes = 1;
ddb5b488 7411
b9c7bc5a 7412 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7413 yes = 0;
b9c7bc5a 7414
0ca70ba5 7415 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7416 if (afi == AFI_MAX)
7417 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7418
b9c7bc5a 7419 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7420 if (ret != CMD_SUCCESS)
7421 return ret;
7422
b9c7bc5a
PZ
7423 if (yes) {
7424 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7425 vty_out(vty, "%% Missing RTLIST\n");
7426 return CMD_WARNING_CONFIG_FAILED;
7427 }
7428 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7429 if (ret != CMD_SUCCESS) {
7430 return ret;
7431 }
ddb5b488
PZ
7432 }
7433
69b07479
DS
7434 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7435 if (!dodir[dir])
ddb5b488 7436 continue;
ddb5b488 7437
69b07479 7438 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7439
69b07479
DS
7440 if (yes) {
7441 if (bgp->vpn_policy[afi].rtlist[dir])
7442 ecommunity_free(
7443 &bgp->vpn_policy[afi].rtlist[dir]);
7444 bgp->vpn_policy[afi].rtlist[dir] =
7445 ecommunity_dup(ecom);
7446 } else {
7447 if (bgp->vpn_policy[afi].rtlist[dir])
7448 ecommunity_free(
7449 &bgp->vpn_policy[afi].rtlist[dir]);
7450 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 7451 }
69b07479
DS
7452
7453 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7454 }
69b07479 7455
d555f3e9
PZ
7456 if (ecom)
7457 ecommunity_free(&ecom);
ddb5b488
PZ
7458
7459 return CMD_SUCCESS;
7460}
7461
b9c7bc5a
PZ
7462ALIAS (af_rt_vpn_imexport,
7463 af_no_rt_vpn_imexport_cmd,
7464 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
7465 NO_STR
7466 "Specify route target list\n"
b9c7bc5a
PZ
7467 "Specify route target list\n"
7468 "Between current address-family and vpn\n"
7469 "For routes leaked from vpn to current address-family\n"
7470 "For routes leaked from current address-family to vpn\n"
7471 "both import and export\n")
7472
7473DEFPY (af_route_map_vpn_imexport,
7474 af_route_map_vpn_imexport_cmd,
7475/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
7476 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
7477 NO_STR
ddb5b488 7478 "Specify route map\n"
b9c7bc5a
PZ
7479 "Between current address-family and vpn\n"
7480 "For routes leaked from vpn to current address-family\n"
7481 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7482 "name of route-map\n")
7483{
7484 VTY_DECLVAR_CONTEXT(bgp, bgp);
7485 int ret;
7486 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
7487 vpn_policy_direction_t dir;
7488 afi_t afi;
ddb5b488 7489 int idx = 0;
b9c7bc5a 7490 int yes = 1;
ddb5b488 7491
b9c7bc5a 7492 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7493 yes = 0;
b9c7bc5a 7494
0ca70ba5 7495 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7496 if (afi == AFI_MAX)
7497 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7498
b9c7bc5a 7499 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
7500 if (ret != CMD_SUCCESS)
7501 return ret;
7502
69b07479
DS
7503 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
7504 if (!dodir[dir])
ddb5b488 7505 continue;
ddb5b488 7506
69b07479 7507 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 7508
69b07479
DS
7509 if (yes) {
7510 if (bgp->vpn_policy[afi].rmap_name[dir])
7511 XFREE(MTYPE_ROUTE_MAP_NAME,
7512 bgp->vpn_policy[afi].rmap_name[dir]);
7513 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
7514 MTYPE_ROUTE_MAP_NAME, rmap_str);
7515 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7516 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7517 if (!bgp->vpn_policy[afi].rmap[dir])
7518 return CMD_SUCCESS;
7519 } else {
7520 if (bgp->vpn_policy[afi].rmap_name[dir])
7521 XFREE(MTYPE_ROUTE_MAP_NAME,
7522 bgp->vpn_policy[afi].rmap_name[dir]);
7523 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7524 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 7525 }
69b07479
DS
7526
7527 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
7528 }
7529
7530 return CMD_SUCCESS;
7531}
7532
b9c7bc5a
PZ
7533ALIAS (af_route_map_vpn_imexport,
7534 af_no_route_map_vpn_imexport_cmd,
7535 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
7536 NO_STR
7537 "Specify route map\n"
b9c7bc5a
PZ
7538 "Between current address-family and vpn\n"
7539 "For routes leaked from vpn to current address-family\n"
7540 "For routes leaked from current address-family to vpn\n")
7541
bb4f6190
DS
7542DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
7543 "[no] import vrf route-map RMAP$rmap_str",
7544 NO_STR
7545 "Import routes from another VRF\n"
7546 "Vrf routes being filtered\n"
7547 "Specify route map\n"
7548 "name of route-map\n")
7549{
7550 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
7551 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
7552 afi_t afi;
7553 int idx = 0;
7554 int yes = 1;
7555 struct bgp *bgp_default;
7556
7557 if (argv_find(argv, argc, "no", &idx))
7558 yes = 0;
7559
0ca70ba5 7560 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
7561 if (afi == AFI_MAX)
7562 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
7563
7564 bgp_default = bgp_get_default();
7565 if (!bgp_default) {
7566 int32_t ret;
7567 as_t as = bgp->as;
7568
7569 /* Auto-create assuming the same AS */
5d5393b9
DL
7570 ret = bgp_get_vty(&bgp_default, &as, NULL,
7571 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
7572
7573 if (ret) {
7574 vty_out(vty,
7575 "VRF default is not configured as a bgp instance\n");
7576 return CMD_WARNING;
7577 }
7578 }
7579
69b07479 7580 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 7581
69b07479
DS
7582 if (yes) {
7583 if (bgp->vpn_policy[afi].rmap_name[dir])
7584 XFREE(MTYPE_ROUTE_MAP_NAME,
7585 bgp->vpn_policy[afi].rmap_name[dir]);
7586 bgp->vpn_policy[afi].rmap_name[dir] =
7587 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
7588 bgp->vpn_policy[afi].rmap[dir] =
1de27621 7589 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
7590 if (!bgp->vpn_policy[afi].rmap[dir])
7591 return CMD_SUCCESS;
7592 } else {
7593 if (bgp->vpn_policy[afi].rmap_name[dir])
7594 XFREE(MTYPE_ROUTE_MAP_NAME,
7595 bgp->vpn_policy[afi].rmap_name[dir]);
7596 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
7597 bgp->vpn_policy[afi].rmap[dir] = NULL;
bb4f6190
DS
7598 }
7599
69b07479
DS
7600 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7601
bb4f6190
DS
7602 return CMD_SUCCESS;
7603}
7604
7605ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
7606 "no import vrf route-map",
7607 NO_STR
7608 "Import routes from another VRF\n"
7609 "Vrf routes being filtered\n"
7610 "Specify route map\n")
7611
4d1b335c
DA
7612DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
7613 "[no] import vrf VIEWVRFNAME$import_name",
7614 NO_STR
7615 "Import routes from another VRF\n"
7616 "VRF to import from\n"
7617 "The name of the VRF\n")
12a844a5
DS
7618{
7619 VTY_DECLVAR_CONTEXT(bgp, bgp);
7620 struct listnode *node;
79ef8664
DS
7621 struct bgp *vrf_bgp, *bgp_default;
7622 int32_t ret = 0;
7623 as_t as = bgp->as;
12a844a5
DS
7624 bool remove = false;
7625 int32_t idx = 0;
7626 char *vname;
a8dadcf6 7627 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
7628 safi_t safi;
7629 afi_t afi;
7630
867f0cca 7631 if (import_name == NULL) {
7632 vty_out(vty, "%% Missing import name\n");
7633 return CMD_WARNING;
7634 }
7635
12a844a5
DS
7636 if (argv_find(argv, argc, "no", &idx))
7637 remove = true;
7638
0ca70ba5
DS
7639 afi = vpn_policy_getafi(vty, bgp, true);
7640 if (afi == AFI_MAX)
7641 return CMD_WARNING_CONFIG_FAILED;
7642
12a844a5
DS
7643 safi = bgp_node_safi(vty);
7644
25679caa 7645 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 7646 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
7647 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
7648 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
7649 remove ? "unimport" : "import", import_name);
7650 return CMD_WARNING;
7651 }
7652
79ef8664
DS
7653 bgp_default = bgp_get_default();
7654 if (!bgp_default) {
7655 /* Auto-create assuming the same AS */
5d5393b9
DL
7656 ret = bgp_get_vty(&bgp_default, &as, NULL,
7657 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
7658
7659 if (ret) {
7660 vty_out(vty,
7661 "VRF default is not configured as a bgp instance\n");
7662 return CMD_WARNING;
7663 }
7664 }
7665
12a844a5
DS
7666 vrf_bgp = bgp_lookup_by_name(import_name);
7667 if (!vrf_bgp) {
5742e42b 7668 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
7669 vrf_bgp = bgp_default;
7670 else
0fb8d6e6 7671 /* Auto-create assuming the same AS */
5d5393b9 7672 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 7673
6e2c7fe6 7674 if (ret) {
020a3f60
DS
7675 vty_out(vty,
7676 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
7677 import_name);
7678 return CMD_WARNING;
7679 }
12a844a5
DS
7680 }
7681
12a844a5 7682 if (remove) {
44338987 7683 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 7684 } else {
44338987 7685 /* Already importing from "import_vrf"? */
12a844a5
DS
7686 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
7687 vname)) {
7688 if (strcmp(vname, import_name) == 0)
7689 return CMD_WARNING;
7690 }
7691
44338987 7692 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
7693 }
7694
7695 return CMD_SUCCESS;
7696}
7697
b9c7bc5a
PZ
7698/* This command is valid only in a bgp vrf instance or the default instance */
7699DEFPY (bgp_imexport_vpn,
7700 bgp_imexport_vpn_cmd,
7701 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
7702 NO_STR
7703 "Import routes to this address-family\n"
7704 "Export routes from this address-family\n"
7705 "to/from default instance VPN RIB\n")
ddb5b488
PZ
7706{
7707 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 7708 int previous_state;
ddb5b488 7709 afi_t afi;
b9c7bc5a 7710 safi_t safi;
ddb5b488 7711 int idx = 0;
b9c7bc5a
PZ
7712 int yes = 1;
7713 int flag;
7714 vpn_policy_direction_t dir;
ddb5b488 7715
b9c7bc5a 7716 if (argv_find(argv, argc, "no", &idx))
d555f3e9 7717 yes = 0;
ddb5b488 7718
b9c7bc5a
PZ
7719 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7720 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 7721
b9c7bc5a
PZ
7722 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7723 return CMD_WARNING_CONFIG_FAILED;
7724 }
ddb5b488 7725
b9c7bc5a
PZ
7726 afi = bgp_node_afi(vty);
7727 safi = bgp_node_safi(vty);
7728 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7729 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7730 return CMD_WARNING_CONFIG_FAILED;
7731 }
ddb5b488 7732
b9c7bc5a
PZ
7733 if (!strcmp(direction_str, "import")) {
7734 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7735 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7736 } else if (!strcmp(direction_str, "export")) {
7737 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7738 dir = BGP_VPN_POLICY_DIR_TOVPN;
7739 } else {
7740 vty_out(vty, "%% unknown direction %s\n", direction_str);
7741 return CMD_WARNING_CONFIG_FAILED;
7742 }
7743
7744 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 7745
b9c7bc5a
PZ
7746 if (yes) {
7747 SET_FLAG(bgp->af_flags[afi][safi], flag);
7748 if (!previous_state) {
7749 /* trigger export current vrf */
ddb5b488
PZ
7750 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7751 }
b9c7bc5a
PZ
7752 } else {
7753 if (previous_state) {
7754 /* trigger un-export current vrf */
7755 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7756 }
7757 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
7758 }
7759
7760 return CMD_SUCCESS;
7761}
7762
301ad80a
PG
7763DEFPY (af_routetarget_import,
7764 af_routetarget_import_cmd,
7765 "[no] <rt|route-target> redirect import RTLIST...",
7766 NO_STR
7767 "Specify route target list\n"
7768 "Specify route target list\n"
7769 "Flow-spec redirect type route target\n"
7770 "Import routes to this address-family\n"
7771 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7772{
7773 VTY_DECLVAR_CONTEXT(bgp, bgp);
7774 int ret;
7775 struct ecommunity *ecom = NULL;
301ad80a
PG
7776 afi_t afi;
7777 int idx = 0;
7778 int yes = 1;
7779
7780 if (argv_find(argv, argc, "no", &idx))
7781 yes = 0;
7782
0ca70ba5 7783 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7784 if (afi == AFI_MAX)
7785 return CMD_WARNING_CONFIG_FAILED;
7786
301ad80a
PG
7787 if (yes) {
7788 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7789 vty_out(vty, "%% Missing RTLIST\n");
7790 return CMD_WARNING_CONFIG_FAILED;
7791 }
7792 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7793 if (ret != CMD_SUCCESS)
7794 return ret;
7795 }
69b07479
DS
7796
7797 if (yes) {
7798 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7799 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7800 .import_redirect_rtlist);
69b07479
DS
7801 bgp->vpn_policy[afi].import_redirect_rtlist =
7802 ecommunity_dup(ecom);
7803 } else {
7804 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7805 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 7806 .import_redirect_rtlist);
69b07479 7807 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 7808 }
69b07479 7809
301ad80a
PG
7810 if (ecom)
7811 ecommunity_free(&ecom);
7812
7813 return CMD_SUCCESS;
7814}
7815
505e5056 7816DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 7817 address_family_ipv4_safi_cmd,
7818 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7819 "Enter Address Family command mode\n"
7820 "Address Family\n"
7821 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 7822{
f51bae9c 7823
d62a17ae 7824 if (argc == 3) {
2131d5cf 7825 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7826 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7827 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7828 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7829 && safi != SAFI_EVPN) {
31947174
MK
7830 vty_out(vty,
7831 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7832 return CMD_WARNING_CONFIG_FAILED;
7833 }
d62a17ae 7834 vty->node = bgp_node_type(AFI_IP, safi);
7835 } else
7836 vty->node = BGP_IPV4_NODE;
718e3744 7837
d62a17ae 7838 return CMD_SUCCESS;
718e3744 7839}
7840
505e5056 7841DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 7842 address_family_ipv6_safi_cmd,
7843 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7844 "Enter Address Family command mode\n"
7845 "Address Family\n"
7846 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 7847{
d62a17ae 7848 if (argc == 3) {
2131d5cf 7849 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7850 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
7851 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7852 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 7853 && safi != SAFI_EVPN) {
31947174
MK
7854 vty_out(vty,
7855 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
7856 return CMD_WARNING_CONFIG_FAILED;
7857 }
d62a17ae 7858 vty->node = bgp_node_type(AFI_IP6, safi);
7859 } else
7860 vty->node = BGP_IPV6_NODE;
25ffbdc1 7861
d62a17ae 7862 return CMD_SUCCESS;
25ffbdc1 7863}
718e3744 7864
d6902373 7865#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 7866DEFUN_NOSH (address_family_vpnv4,
718e3744 7867 address_family_vpnv4_cmd,
8334fd5a 7868 "address-family vpnv4 [unicast]",
718e3744 7869 "Enter Address Family command mode\n"
8c3deaae 7870 "Address Family\n"
3a2d747c 7871 "Address Family modifier\n")
718e3744 7872{
d62a17ae 7873 vty->node = BGP_VPNV4_NODE;
7874 return CMD_SUCCESS;
718e3744 7875}
7876
505e5056 7877DEFUN_NOSH (address_family_vpnv6,
8ecd3266 7878 address_family_vpnv6_cmd,
8334fd5a 7879 "address-family vpnv6 [unicast]",
8ecd3266 7880 "Enter Address Family command mode\n"
8c3deaae 7881 "Address Family\n"
3a2d747c 7882 "Address Family modifier\n")
8ecd3266 7883{
d62a17ae 7884 vty->node = BGP_VPNV6_NODE;
7885 return CMD_SUCCESS;
8ecd3266 7886}
64e4a6c5 7887#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 7888
505e5056 7889DEFUN_NOSH (address_family_evpn,
4e0b7b6d 7890 address_family_evpn_cmd,
7111c1a0 7891 "address-family l2vpn evpn",
4e0b7b6d 7892 "Enter Address Family command mode\n"
7111c1a0
QY
7893 "Address Family\n"
7894 "Address Family modifier\n")
4e0b7b6d 7895{
2131d5cf 7896 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 7897 vty->node = BGP_EVPN_NODE;
7898 return CMD_SUCCESS;
4e0b7b6d
PG
7899}
7900
505e5056 7901DEFUN_NOSH (exit_address_family,
718e3744 7902 exit_address_family_cmd,
7903 "exit-address-family",
7904 "Exit from Address Family configuration mode\n")
7905{
d62a17ae 7906 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7907 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7908 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7909 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
7910 || vty->node == BGP_EVPN_NODE
7911 || vty->node == BGP_FLOWSPECV4_NODE
7912 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 7913 vty->node = BGP_NODE;
7914 return CMD_SUCCESS;
718e3744 7915}
6b0655a2 7916
8ad7271d 7917/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 7918static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7919 const char *ip_str, afi_t afi, safi_t safi,
7920 struct prefix_rd *prd)
7921{
7922 int ret;
7923 struct prefix match;
7924 struct bgp_node *rn;
7925 struct bgp_node *rm;
7926 struct bgp *bgp;
7927 struct bgp_table *table;
7928 struct bgp_table *rib;
7929
7930 /* BGP structure lookup. */
7931 if (view_name) {
7932 bgp = bgp_lookup_by_name(view_name);
7933 if (bgp == NULL) {
7934 vty_out(vty, "%% Can't find BGP instance %s\n",
7935 view_name);
7936 return CMD_WARNING;
7937 }
7938 } else {
7939 bgp = bgp_get_default();
7940 if (bgp == NULL) {
7941 vty_out(vty, "%% No BGP process is configured\n");
7942 return CMD_WARNING;
7943 }
7944 }
7945
7946 /* Check IP address argument. */
7947 ret = str2prefix(ip_str, &match);
7948 if (!ret) {
7949 vty_out(vty, "%% address is malformed\n");
7950 return CMD_WARNING;
7951 }
7952
7953 match.family = afi2family(afi);
7954 rib = bgp->rib[afi][safi];
7955
7956 if (safi == SAFI_MPLS_VPN) {
7957 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7958 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7959 continue;
7960
67009e22
DS
7961 table = bgp_node_get_bgp_table_info(rn);
7962 if (table != NULL) {
7963
d62a17ae 7964 if ((rm = bgp_node_match(table, &match))
7965 != NULL) {
7966 if (rm->p.prefixlen
7967 == match.prefixlen) {
343cdb61 7968 SET_FLAG(rm->flags,
d62a17ae 7969 BGP_NODE_USER_CLEAR);
7970 bgp_process(bgp, rm, afi, safi);
7971 }
7972 bgp_unlock_node(rm);
7973 }
7974 }
7975 }
7976 } else {
7977 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7978 if (rn->p.prefixlen == match.prefixlen) {
7979 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7980 bgp_process(bgp, rn, afi, safi);
7981 }
7982 bgp_unlock_node(rn);
7983 }
7984 }
7985
7986 return CMD_SUCCESS;
8ad7271d
DS
7987}
7988
b09b5ae0 7989/* one clear bgp command to rule them all */
718e3744 7990DEFUN (clear_ip_bgp_all,
7991 clear_ip_bgp_all_cmd,
453c92f6 7992 "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 7993 CLEAR_STR
7994 IP_STR
7995 BGP_STR
838758ac 7996 BGP_INSTANCE_HELP_STR
510afcd6 7997 BGP_AFI_HELP_STR
fd5e7b70 7998 "Address Family\n"
510afcd6 7999 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8000 "Address Family modifier\n"
b09b5ae0 8001 "Clear all peers\n"
453c92f6 8002 "BGP IPv4 neighbor to clear\n"
a80beece 8003 "BGP IPv6 neighbor to clear\n"
838758ac 8004 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8005 "Clear peers with the AS number\n"
8006 "Clear all external peers\n"
718e3744 8007 "Clear all members of peer-group\n"
b09b5ae0 8008 "BGP peer-group name\n"
b09b5ae0
DW
8009 BGP_SOFT_STR
8010 BGP_SOFT_IN_STR
b09b5ae0
DW
8011 BGP_SOFT_OUT_STR
8012 BGP_SOFT_IN_STR
8013 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8014 BGP_SOFT_OUT_STR)
718e3744 8015{
d62a17ae 8016 char *vrf = NULL;
8017
dc912615
DS
8018 afi_t afi = AFI_UNSPEC;
8019 safi_t safi = SAFI_UNSPEC;
d62a17ae 8020 enum clear_sort clr_sort = clear_peer;
8021 enum bgp_clear_type clr_type;
8022 char *clr_arg = NULL;
8023
8024 int idx = 0;
8025
8026 /* clear [ip] bgp */
8027 if (argv_find(argv, argc, "ip", &idx))
8028 afi = AFI_IP;
8029
9a8bdf1c
PG
8030 /* [<vrf> VIEWVRFNAME] */
8031 if (argv_find(argv, argc, "vrf", &idx)) {
8032 vrf = argv[idx + 1]->arg;
8033 idx += 2;
8034 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8035 vrf = NULL;
8036 } else if (argv_find(argv, argc, "view", &idx)) {
8037 /* [<view> VIEWVRFNAME] */
d62a17ae 8038 vrf = argv[idx + 1]->arg;
8039 idx += 2;
8040 }
d62a17ae 8041 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8042 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8043 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8044
d7b9898c 8045 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8046 if (argv_find(argv, argc, "*", &idx)) {
8047 clr_sort = clear_all;
8048 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8049 clr_sort = clear_peer;
8050 clr_arg = argv[idx]->arg;
8051 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8052 clr_sort = clear_peer;
8053 clr_arg = argv[idx]->arg;
8054 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8055 clr_sort = clear_group;
8056 idx++;
8057 clr_arg = argv[idx]->arg;
d7b9898c 8058 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8059 clr_sort = clear_peer;
8060 clr_arg = argv[idx]->arg;
8fa7d444
DS
8061 } else if (argv_find(argv, argc, "WORD", &idx)) {
8062 clr_sort = clear_peer;
8063 clr_arg = argv[idx]->arg;
d62a17ae 8064 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8065 clr_sort = clear_as;
8066 clr_arg = argv[idx]->arg;
8067 } else if (argv_find(argv, argc, "external", &idx)) {
8068 clr_sort = clear_external;
8069 }
8070
8071 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8072 if (argv_find(argv, argc, "soft", &idx)) {
8073 if (argv_find(argv, argc, "in", &idx)
8074 || argv_find(argv, argc, "out", &idx))
8075 clr_type = strmatch(argv[idx]->text, "in")
8076 ? BGP_CLEAR_SOFT_IN
8077 : BGP_CLEAR_SOFT_OUT;
8078 else
8079 clr_type = BGP_CLEAR_SOFT_BOTH;
8080 } else if (argv_find(argv, argc, "in", &idx)) {
8081 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8082 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8083 : BGP_CLEAR_SOFT_IN;
8084 } else if (argv_find(argv, argc, "out", &idx)) {
8085 clr_type = BGP_CLEAR_SOFT_OUT;
8086 } else
8087 clr_type = BGP_CLEAR_SOFT_NONE;
8088
8089 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 8090}
01080f7c 8091
8ad7271d
DS
8092DEFUN (clear_ip_bgp_prefix,
8093 clear_ip_bgp_prefix_cmd,
18c57037 8094 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8095 CLEAR_STR
8096 IP_STR
8097 BGP_STR
838758ac 8098 BGP_INSTANCE_HELP_STR
8ad7271d 8099 "Clear bestpath and re-advertise\n"
0c7b1b01 8100 "IPv4 prefix\n")
8ad7271d 8101{
d62a17ae 8102 char *vrf = NULL;
8103 char *prefix = NULL;
8ad7271d 8104
d62a17ae 8105 int idx = 0;
01080f7c 8106
d62a17ae 8107 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8108 if (argv_find(argv, argc, "vrf", &idx)) {
8109 vrf = argv[idx + 1]->arg;
8110 idx += 2;
8111 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8112 vrf = NULL;
8113 } else if (argv_find(argv, argc, "view", &idx)) {
8114 /* [<view> VIEWVRFNAME] */
8115 vrf = argv[idx + 1]->arg;
8116 idx += 2;
8117 }
0c7b1b01 8118
d62a17ae 8119 prefix = argv[argc - 1]->arg;
8ad7271d 8120
d62a17ae 8121 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8122}
8ad7271d 8123
b09b5ae0
DW
8124DEFUN (clear_bgp_ipv6_safi_prefix,
8125 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8126 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8127 CLEAR_STR
3a2d747c 8128 IP_STR
718e3744 8129 BGP_STR
8c3deaae 8130 "Address Family\n"
46f296b4 8131 BGP_SAFI_HELP_STR
b09b5ae0 8132 "Clear bestpath and re-advertise\n"
0c7b1b01 8133 "IPv6 prefix\n")
718e3744 8134{
9b475e76
PG
8135 int idx_safi = 0;
8136 int idx_ipv6_prefix = 0;
8137 safi_t safi = SAFI_UNICAST;
8138 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8139 argv[idx_ipv6_prefix]->arg : NULL;
8140
8141 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8142 return bgp_clear_prefix(
9b475e76
PG
8143 vty, NULL, prefix, AFI_IP6,
8144 safi, NULL);
838758ac 8145}
01080f7c 8146
b09b5ae0
DW
8147DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8148 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8149 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8150 CLEAR_STR
3a2d747c 8151 IP_STR
718e3744 8152 BGP_STR
838758ac 8153 BGP_INSTANCE_HELP_STR
8c3deaae 8154 "Address Family\n"
46f296b4 8155 BGP_SAFI_HELP_STR
b09b5ae0 8156 "Clear bestpath and re-advertise\n"
0c7b1b01 8157 "IPv6 prefix\n")
718e3744 8158{
9b475e76 8159 int idx_safi = 0;
9a8bdf1c 8160 int idx_vrfview = 0;
9b475e76
PG
8161 int idx_ipv6_prefix = 0;
8162 safi_t safi = SAFI_UNICAST;
8163 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8164 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8165 char *vrfview = NULL;
9b475e76 8166
9a8bdf1c
PG
8167 /* [<view|vrf> VIEWVRFNAME] */
8168 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8169 vrfview = argv[idx_vrfview + 1]->arg;
8170 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8171 vrfview = NULL;
8172 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8173 /* [<view> VIEWVRFNAME] */
8174 vrfview = argv[idx_vrfview + 1]->arg;
8175 }
9b475e76
PG
8176 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8177
d62a17ae 8178 return bgp_clear_prefix(
9b475e76
PG
8179 vty, vrfview, prefix,
8180 AFI_IP6, safi, NULL);
718e3744 8181}
8182
b09b5ae0
DW
8183DEFUN (show_bgp_views,
8184 show_bgp_views_cmd,
d6e3c605 8185 "show [ip] bgp views",
b09b5ae0 8186 SHOW_STR
d6e3c605 8187 IP_STR
01080f7c 8188 BGP_STR
b09b5ae0 8189 "Show the defined BGP views\n")
01080f7c 8190{
d62a17ae 8191 struct list *inst = bm->bgp;
8192 struct listnode *node;
8193 struct bgp *bgp;
01080f7c 8194
d62a17ae 8195 vty_out(vty, "Defined BGP views:\n");
8196 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8197 /* Skip VRFs. */
8198 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
8199 continue;
8200 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
8201 bgp->as);
8202 }
e52702f2 8203
d62a17ae 8204 return CMD_SUCCESS;
e0081f70
ML
8205}
8206
8386ac43 8207DEFUN (show_bgp_vrfs,
8208 show_bgp_vrfs_cmd,
d6e3c605 8209 "show [ip] bgp vrfs [json]",
8386ac43 8210 SHOW_STR
d6e3c605 8211 IP_STR
8386ac43 8212 BGP_STR
8213 "Show BGP VRFs\n"
9973d184 8214 JSON_STR)
8386ac43 8215{
fe1dc5a3 8216 char buf[ETHER_ADDR_STRLEN];
d62a17ae 8217 struct list *inst = bm->bgp;
8218 struct listnode *node;
8219 struct bgp *bgp;
9f049418 8220 bool uj = use_json(argc, argv);
d62a17ae 8221 json_object *json = NULL;
8222 json_object *json_vrfs = NULL;
8223 int count = 0;
d62a17ae 8224
d62a17ae 8225 if (uj) {
8226 json = json_object_new_object();
8227 json_vrfs = json_object_new_object();
8228 }
8229
8230 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
8231 const char *name, *type;
8232 struct peer *peer;
7fe96307 8233 struct listnode *node2, *nnode2;
d62a17ae 8234 int peers_cfg, peers_estb;
8235 json_object *json_vrf = NULL;
d62a17ae 8236
8237 /* Skip Views. */
8238 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
8239 continue;
8240
8241 count++;
efb4077a 8242 if (!uj && count == 1) {
fe1dc5a3 8243 vty_out(vty,
efb4077a 8244 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 8245 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
8246 "#PeersEstb", "Name");
8247 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
8248 "L3-VNI", "RouterMAC", "Interface");
8249 }
d62a17ae 8250
8251 peers_cfg = peers_estb = 0;
8252 if (uj)
8253 json_vrf = json_object_new_object();
8254
8255
7fe96307 8256 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 8257 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8258 continue;
8259 peers_cfg++;
8260 if (peer->status == Established)
8261 peers_estb++;
8262 }
8263
8264 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 8265 name = VRF_DEFAULT_NAME;
d62a17ae 8266 type = "DFLT";
8267 } else {
8268 name = bgp->name;
8269 type = "VRF";
8270 }
8271
a8bf7d9c 8272
d62a17ae 8273 if (uj) {
a4d82a8a
PZ
8274 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8275 ? -1
8276 : (int64_t)bgp->vrf_id;
d62a17ae 8277 json_object_string_add(json_vrf, "type", type);
8278 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8279 json_object_string_add(json_vrf, "routerId",
8280 inet_ntoa(bgp->router_id));
8281 json_object_int_add(json_vrf, "numConfiguredPeers",
8282 peers_cfg);
8283 json_object_int_add(json_vrf, "numEstablishedPeers",
8284 peers_estb);
8285
fe1dc5a3 8286 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
8287 json_object_string_add(
8288 json_vrf, "rmac",
8289 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
8290 json_object_string_add(json_vrf, "interface",
8291 ifindex2ifname(bgp->l3vni_svi_ifindex,
8292 bgp->vrf_id));
d62a17ae 8293 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 8294 } else {
fe1dc5a3 8295 vty_out(vty,
efb4077a 8296 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
8297 type,
8298 bgp->vrf_id == VRF_UNKNOWN ? -1
8299 : (int)bgp->vrf_id,
8300 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
8301 peers_estb, name);
8302 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
8303 bgp->l3vni,
8304 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
8305 ifindex2ifname(bgp->l3vni_svi_ifindex,
8306 bgp->vrf_id));
8307 }
d62a17ae 8308 }
8309
8310 if (uj) {
8311 json_object_object_add(json, "vrfs", json_vrfs);
8312
8313 json_object_int_add(json, "totalVrfs", count);
8314
996c9314
LB
8315 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8316 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 8317 json_object_free(json);
8318 } else {
8319 if (count)
8320 vty_out(vty,
8321 "\nTotal number of VRFs (including default): %d\n",
8322 count);
8323 }
8324
8325 return CMD_SUCCESS;
8386ac43 8326}
8327
48ecf8f5
DS
8328DEFUN (show_bgp_mac_hash,
8329 show_bgp_mac_hash_cmd,
8330 "show bgp mac hash",
8331 SHOW_STR
8332 BGP_STR
8333 "Mac Address\n"
8334 "Mac Address database\n")
8335{
8336 bgp_mac_dump_table(vty);
8337
8338 return CMD_SUCCESS;
8339}
acf71666 8340
e3b78da8 8341static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 8342{
0291c246 8343 struct vty *vty = (struct vty *)args;
e3b78da8 8344 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 8345
60466a63 8346 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
8347 tip->refcnt);
8348}
8349
8350static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
8351{
8352 vty_out(vty, "self nexthop database:\n");
af97a18b 8353 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
8354
8355 vty_out(vty, "Tunnel-ip database:\n");
8356 hash_iterate(bgp->tip_hash,
e3b78da8 8357 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
8358 vty);
8359}
8360
15c81ca4
DS
8361DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
8362 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
8363 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
8364 "martian next-hops\n"
8365 "martian next-hop database\n")
acf71666 8366{
0291c246 8367 struct bgp *bgp = NULL;
15c81ca4 8368 int idx = 0;
9a8bdf1c
PG
8369 char *name = NULL;
8370
8371 /* [<vrf> VIEWVRFNAME] */
8372 if (argv_find(argv, argc, "vrf", &idx)) {
8373 name = argv[idx + 1]->arg;
8374 if (name && strmatch(name, VRF_DEFAULT_NAME))
8375 name = NULL;
8376 } else if (argv_find(argv, argc, "view", &idx))
8377 /* [<view> VIEWVRFNAME] */
8378 name = argv[idx + 1]->arg;
8379 if (name)
8380 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
8381 else
8382 bgp = bgp_get_default();
acf71666 8383
acf71666
MK
8384 if (!bgp) {
8385 vty_out(vty, "%% No BGP process is configured\n");
8386 return CMD_WARNING;
8387 }
8388 bgp_show_martian_nexthops(vty, bgp);
8389
8390 return CMD_SUCCESS;
8391}
8392
f412b39a 8393DEFUN (show_bgp_memory,
4bf6a362 8394 show_bgp_memory_cmd,
7fa12b13 8395 "show [ip] bgp memory",
4bf6a362 8396 SHOW_STR
3a2d747c 8397 IP_STR
4bf6a362
PJ
8398 BGP_STR
8399 "Global BGP memory statistics\n")
8400{
d62a17ae 8401 char memstrbuf[MTYPE_MEMSTR_LEN];
8402 unsigned long count;
8403
8404 /* RIB related usage stats */
8405 count = mtype_stats_alloc(MTYPE_BGP_NODE);
8406 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
8407 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8408 count * sizeof(struct bgp_node)));
8409
8410 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
8411 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
8412 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 8413 count * sizeof(struct bgp_path_info)));
d62a17ae 8414 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
8415 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
8416 count,
4b7e6066
DS
8417 mtype_memstr(
8418 memstrbuf, sizeof(memstrbuf),
8419 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 8420
8421 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
8422 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
8423 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8424 count * sizeof(struct bgp_static)));
8425
8426 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
8427 vty_out(vty, "%ld Packets, using %s of memory\n", count,
8428 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8429 count * sizeof(struct bpacket)));
8430
8431 /* Adj-In/Out */
8432 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
8433 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
8434 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8435 count * sizeof(struct bgp_adj_in)));
8436 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
8437 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
8438 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8439 count * sizeof(struct bgp_adj_out)));
8440
8441 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
8442 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
8443 count,
8444 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8445 count * sizeof(struct bgp_nexthop_cache)));
8446
8447 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
8448 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
8449 count,
8450 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8451 count * sizeof(struct bgp_damp_info)));
8452
8453 /* Attributes */
8454 count = attr_count();
8455 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
8456 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8457 count * sizeof(struct attr)));
8458
8459 if ((count = attr_unknown_count()))
8460 vty_out(vty, "%ld unknown attributes\n", count);
8461
8462 /* AS_PATH attributes */
8463 count = aspath_count();
8464 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
8465 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8466 count * sizeof(struct aspath)));
8467
8468 count = mtype_stats_alloc(MTYPE_AS_SEG);
8469 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
8470 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8471 count * sizeof(struct assegment)));
8472
8473 /* Other attributes */
8474 if ((count = community_count()))
8475 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8476 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8477 count * sizeof(struct community)));
d62a17ae 8478 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
8479 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
8480 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8481 count * sizeof(struct ecommunity)));
d62a17ae 8482 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
8483 vty_out(vty,
8484 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
8485 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8486 count * sizeof(struct lcommunity)));
d62a17ae 8487
8488 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
8489 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
8490 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8491 count * sizeof(struct cluster_list)));
8492
8493 /* Peer related usage */
8494 count = mtype_stats_alloc(MTYPE_BGP_PEER);
8495 vty_out(vty, "%ld peers, using %s of memory\n", count,
8496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8497 count * sizeof(struct peer)));
8498
8499 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
8500 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
8501 mtype_memstr(memstrbuf, sizeof(memstrbuf),
8502 count * sizeof(struct peer_group)));
8503
8504 /* Other */
d62a17ae 8505 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
8506 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
8507 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
8508 count * sizeof(regex_t)));
d62a17ae 8509 return CMD_SUCCESS;
4bf6a362 8510}
fee0f4c6 8511
57a9c8a8
DS
8512static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
8513{
8514 json_object *bestpath = json_object_new_object();
8515
892fedb6 8516 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
8517 json_object_string_add(bestpath, "asPath", "ignore");
8518
892fedb6 8519 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
8520 json_object_string_add(bestpath, "asPath", "confed");
8521
892fedb6
DA
8522 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
8523 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 8524 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8525 "as-set");
8526 else
a4d82a8a 8527 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
8528 "true");
8529 } else
a4d82a8a 8530 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 8531
892fedb6 8532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 8533 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
8534 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
8535 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
8536 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 8537 json_object_string_add(bestpath, "med", "confed");
892fedb6 8538 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
8539 json_object_string_add(bestpath, "med",
8540 "missing-as-worst");
8541 else
8542 json_object_string_add(bestpath, "med", "true");
8543 }
8544
8545 json_object_object_add(json, "bestPath", bestpath);
8546}
8547
3577f1c5
DD
8548/* Print the error code/subcode for why the peer is down */
8549static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
8550 json_object *json_peer, bool use_json)
8551{
8552 const char *code_str;
8553 const char *subcode_str;
8554
8555 if (use_json) {
8556 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8557 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8558 char errorcodesubcode_hexstr[5];
8559 char errorcodesubcode_str[256];
8560
8561 code_str = bgp_notify_code_str(peer->notify.code);
8562 subcode_str = bgp_notify_subcode_str(
8563 peer->notify.code,
8564 peer->notify.subcode);
8565
8566 sprintf(errorcodesubcode_hexstr, "%02X%02X",
8567 peer->notify.code, peer->notify.subcode);
8568 json_object_string_add(json_peer,
8569 "lastErrorCodeSubcode",
8570 errorcodesubcode_hexstr);
8571 snprintf(errorcodesubcode_str, 255, "%s%s",
8572 code_str, subcode_str);
8573 json_object_string_add(json_peer,
8574 "lastNotificationReason",
8575 errorcodesubcode_str);
8576 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8577 && peer->notify.code == BGP_NOTIFY_CEASE
8578 && (peer->notify.subcode
8579 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8580 || peer->notify.subcode
8581 == BGP_NOTIFY_CEASE_ADMIN_RESET)
8582 && peer->notify.length) {
8583 char msgbuf[1024];
8584 const char *msg_str;
8585
8586 msg_str = bgp_notify_admin_message(
8587 msgbuf, sizeof(msgbuf),
8588 (uint8_t *)peer->notify.data,
8589 peer->notify.length);
8590 if (msg_str)
8591 json_object_string_add(
8592 json_peer,
8593 "lastShutdownDescription",
8594 msg_str);
8595 }
8596
c258527b 8597 }
3577f1c5
DD
8598 json_object_string_add(json_peer, "lastResetDueTo",
8599 peer_down_str[(int)peer->last_reset]);
05912a17
DD
8600 json_object_int_add(json_peer, "lastResetCode",
8601 peer->last_reset);
3577f1c5
DD
8602 } else {
8603 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
8604 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
8605 code_str = bgp_notify_code_str(peer->notify.code);
8606 subcode_str =
8607 bgp_notify_subcode_str(peer->notify.code,
8608 peer->notify.subcode);
8609 vty_out(vty, " Notification %s (%s%s)\n",
8610 peer->last_reset == PEER_DOWN_NOTIFY_SEND
8611 ? "sent"
8612 : "received",
8613 code_str, subcode_str);
8614 } else {
8615 vty_out(vty, " %s\n",
8616 peer_down_str[(int)peer->last_reset]);
8617 }
8618 }
8619}
8620
8621static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
8622 safi_t safi)
8623{
8624 return ((peer->status != Established) ||
8625 !peer->afc_recv[afi][safi]);
8626}
8627
8628static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
8629 struct peer *peer, json_object *json_peer,
8630 int max_neighbor_width, bool use_json)
8631{
8632 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8633 int len;
8634
8635 if (use_json) {
8636 if (peer_dynamic_neighbor(peer))
8637 json_object_boolean_true_add(json_peer,
8638 "dynamicPeer");
8639 if (peer->hostname)
8640 json_object_string_add(json_peer, "hostname",
8641 peer->hostname);
8642
8643 if (peer->domainname)
8644 json_object_string_add(json_peer, "domainname",
8645 peer->domainname);
8646 json_object_int_add(json_peer, "connectionsEstablished",
8647 peer->established);
8648 json_object_int_add(json_peer, "connectionsDropped",
8649 peer->dropped);
8650 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8651 use_json, json_peer);
8652 if (peer->status == Established)
8653 json_object_string_add(json_peer, "lastResetDueTo",
8654 "AFI/SAFI Not Negotiated");
8655 else
8656 bgp_show_peer_reset(NULL, peer, json_peer, true);
8657 } else {
8658 dn_flag[1] = '\0';
8659 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
8660 if (peer->hostname
892fedb6 8661 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
8662 len = vty_out(vty, "%s%s(%s)", dn_flag,
8663 peer->hostname, peer->host);
8664 else
8665 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8666
8667 /* pad the neighbor column with spaces */
8668 if (len < max_neighbor_width)
8669 vty_out(vty, "%*s", max_neighbor_width - len,
8670 " ");
8671 vty_out(vty, "%7d %7d %8s", peer->established,
8672 peer->dropped,
8673 peer_uptime(peer->uptime, timebuf,
8674 BGP_UPTIME_LEN, 0, NULL));
8675 if (peer->status == Established)
8676 vty_out(vty, " AFI/SAFI Not Negotiated\n");
8677 else
8678 bgp_show_peer_reset(vty, peer, NULL,
8679 false);
8680 }
8681}
c258527b 8682
3577f1c5 8683
718e3744 8684/* Show BGP peer's summary information. */
d62a17ae 8685static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
3577f1c5 8686 bool show_failed, bool use_json)
d62a17ae 8687{
8688 struct peer *peer;
8689 struct listnode *node, *nnode;
8690 unsigned int count = 0, dn_count = 0;
8691 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
8692 char neighbor_buf[VTY_BUFSIZ];
8693 int neighbor_col_default_width = 16;
3577f1c5 8694 int len, failed_count = 0;
d62a17ae 8695 int max_neighbor_width = 0;
8696 int pfx_rcd_safi;
3c13337d 8697 json_object *json = NULL;
d62a17ae 8698 json_object *json_peer = NULL;
8699 json_object *json_peers = NULL;
50e05855 8700 struct peer_af *paf;
d62a17ae 8701
8702 /* labeled-unicast routes are installed in the unicast table so in order
8703 * to
8704 * display the correct PfxRcd value we must look at SAFI_UNICAST
8705 */
3577f1c5 8706
d62a17ae 8707 if (safi == SAFI_LABELED_UNICAST)
8708 pfx_rcd_safi = SAFI_UNICAST;
8709 else
8710 pfx_rcd_safi = safi;
8711
8712 if (use_json) {
3c13337d 8713 json = json_object_new_object();
d62a17ae 8714 json_peers = json_object_new_object();
3577f1c5
DD
8715 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8716 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8717 continue;
8718
8719 if (peer->afc[afi][safi]) {
8720 /* See if we have at least a single failed peer */
8721 if (bgp_has_peer_failed(peer, afi, safi))
8722 failed_count++;
8723 count++;
8724 }
8725 if (peer_dynamic_neighbor(peer))
8726 dn_count++;
8727 }
c258527b 8728
d62a17ae 8729 } else {
8730 /* Loop over all neighbors that will be displayed to determine
8731 * how many
8732 * characters are needed for the Neighbor column
8733 */
8734 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8735 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8736 continue;
8737
8738 if (peer->afc[afi][safi]) {
8739 memset(dn_flag, '\0', sizeof(dn_flag));
8740 if (peer_dynamic_neighbor(peer))
8741 dn_flag[0] = '*';
8742
8743 if (peer->hostname
892fedb6
DA
8744 && CHECK_FLAG(bgp->flags,
8745 BGP_FLAG_SHOW_HOSTNAME))
d62a17ae 8746 sprintf(neighbor_buf, "%s%s(%s) ",
8747 dn_flag, peer->hostname,
8748 peer->host);
8749 else
8750 sprintf(neighbor_buf, "%s%s ", dn_flag,
8751 peer->host);
8752
8753 len = strlen(neighbor_buf);
8754
8755 if (len > max_neighbor_width)
8756 max_neighbor_width = len;
c258527b 8757
3577f1c5
DD
8758 /* See if we have at least a single failed peer */
8759 if (bgp_has_peer_failed(peer, afi, safi))
8760 failed_count++;
8761 count++;
d62a17ae 8762 }
8763 }
f933309e 8764
d62a17ae 8765 /* Originally we displayed the Neighbor column as 16
8766 * characters wide so make that the default
8767 */
8768 if (max_neighbor_width < neighbor_col_default_width)
8769 max_neighbor_width = neighbor_col_default_width;
8770 }
f933309e 8771
3577f1c5
DD
8772 if (show_failed && !failed_count) {
8773 if (use_json) {
8774 json_object_int_add(json, "failedPeersCount", 0);
8775 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 8776 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
8777
8778 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8779 json, JSON_C_TO_STRING_PRETTY));
8780 json_object_free(json);
8781 } else {
8782 vty_out(vty, "%% No failed BGP neighbors found\n");
8783 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8784 }
8785 return CMD_SUCCESS;
8786 }
c258527b 8787
3577f1c5 8788 count = 0; /* Reset the value as its used again */
d62a17ae 8789 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8790 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8791 continue;
8792
ea47320b
DL
8793 if (!peer->afc[afi][safi])
8794 continue;
d62a17ae 8795
ea47320b
DL
8796 if (!count) {
8797 unsigned long ents;
8798 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 8799 int64_t vrf_id_ui;
d62a17ae 8800
a4d82a8a
PZ
8801 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
8802 ? -1
8803 : (int64_t)bgp->vrf_id;
ea47320b
DL
8804
8805 /* Usage summary and header */
8806 if (use_json) {
8807 json_object_string_add(
8808 json, "routerId",
8809 inet_ntoa(bgp->router_id));
60466a63
QY
8810 json_object_int_add(json, "as", bgp->as);
8811 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
8812 json_object_string_add(
8813 json, "vrfName",
8814 (bgp->inst_type
8815 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 8816 ? VRF_DEFAULT_NAME
ea47320b
DL
8817 : bgp->name);
8818 } else {
8819 vty_out(vty,
8820 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 8821 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
8822 bgp->vrf_id == VRF_UNKNOWN
8823 ? -1
8824 : (int)bgp->vrf_id);
ea47320b
DL
8825 vty_out(vty, "\n");
8826 }
d62a17ae 8827
ea47320b 8828 if (bgp_update_delay_configured(bgp)) {
d62a17ae 8829 if (use_json) {
ea47320b 8830 json_object_int_add(
60466a63 8831 json, "updateDelayLimit",
ea47320b 8832 bgp->v_update_delay);
d62a17ae 8833
ea47320b
DL
8834 if (bgp->v_update_delay
8835 != bgp->v_establish_wait)
d62a17ae 8836 json_object_int_add(
8837 json,
ea47320b
DL
8838 "updateDelayEstablishWait",
8839 bgp->v_establish_wait);
d62a17ae 8840
60466a63 8841 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8842 json_object_string_add(
8843 json,
8844 "updateDelayFirstNeighbor",
8845 bgp->update_delay_begin_time);
8846 json_object_boolean_true_add(
8847 json,
8848 "updateDelayInProgress");
8849 } else {
8850 if (bgp->update_delay_over) {
d62a17ae 8851 json_object_string_add(
8852 json,
8853 "updateDelayFirstNeighbor",
8854 bgp->update_delay_begin_time);
ea47320b 8855 json_object_string_add(
d62a17ae 8856 json,
ea47320b
DL
8857 "updateDelayBestpathResumed",
8858 bgp->update_delay_end_time);
8859 json_object_string_add(
d62a17ae 8860 json,
ea47320b
DL
8861 "updateDelayZebraUpdateResume",
8862 bgp->update_delay_zebra_resume_time);
8863 json_object_string_add(
8864 json,
8865 "updateDelayPeerUpdateResume",
8866 bgp->update_delay_peers_resume_time);
d62a17ae 8867 }
ea47320b
DL
8868 }
8869 } else {
8870 vty_out(vty,
8871 "Read-only mode update-delay limit: %d seconds\n",
8872 bgp->v_update_delay);
8873 if (bgp->v_update_delay
8874 != bgp->v_establish_wait)
d62a17ae 8875 vty_out(vty,
ea47320b
DL
8876 " Establish wait: %d seconds\n",
8877 bgp->v_establish_wait);
d62a17ae 8878
60466a63 8879 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
8880 vty_out(vty,
8881 " First neighbor established: %s\n",
8882 bgp->update_delay_begin_time);
8883 vty_out(vty,
8884 " Delay in progress\n");
8885 } else {
8886 if (bgp->update_delay_over) {
d62a17ae 8887 vty_out(vty,
8888 " First neighbor established: %s\n",
8889 bgp->update_delay_begin_time);
8890 vty_out(vty,
ea47320b
DL
8891 " Best-paths resumed: %s\n",
8892 bgp->update_delay_end_time);
8893 vty_out(vty,
8894 " zebra update resumed: %s\n",
8895 bgp->update_delay_zebra_resume_time);
8896 vty_out(vty,
8897 " peers update resumed: %s\n",
8898 bgp->update_delay_peers_resume_time);
d62a17ae 8899 }
8900 }
8901 }
ea47320b 8902 }
d62a17ae 8903
ea47320b
DL
8904 if (use_json) {
8905 if (bgp_maxmed_onstartup_configured(bgp)
8906 && bgp->maxmed_active)
8907 json_object_boolean_true_add(
60466a63 8908 json, "maxMedOnStartup");
ea47320b
DL
8909 if (bgp->v_maxmed_admin)
8910 json_object_boolean_true_add(
60466a63 8911 json, "maxMedAdministrative");
d62a17ae 8912
ea47320b
DL
8913 json_object_int_add(
8914 json, "tableVersion",
60466a63 8915 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 8916
60466a63
QY
8917 ents = bgp_table_count(bgp->rib[afi][safi]);
8918 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
8919 json_object_int_add(
8920 json, "ribMemory",
8921 ents * sizeof(struct bgp_node));
d62a17ae 8922
210ec2a0 8923 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
8924 json_object_int_add(json, "peerCount", ents);
8925 json_object_int_add(json, "peerMemory",
8926 ents * sizeof(struct peer));
d62a17ae 8927
ea47320b
DL
8928 if ((ents = listcount(bgp->group))) {
8929 json_object_int_add(
60466a63 8930 json, "peerGroupCount", ents);
ea47320b
DL
8931 json_object_int_add(
8932 json, "peerGroupMemory",
996c9314
LB
8933 ents * sizeof(struct
8934 peer_group));
ea47320b 8935 }
d62a17ae 8936
ea47320b
DL
8937 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8938 BGP_CONFIG_DAMPENING))
8939 json_object_boolean_true_add(
60466a63 8940 json, "dampeningEnabled");
ea47320b
DL
8941 } else {
8942 if (bgp_maxmed_onstartup_configured(bgp)
8943 && bgp->maxmed_active)
d62a17ae 8944 vty_out(vty,
ea47320b
DL
8945 "Max-med on-startup active\n");
8946 if (bgp->v_maxmed_admin)
d62a17ae 8947 vty_out(vty,
ea47320b 8948 "Max-med administrative active\n");
d62a17ae 8949
60466a63
QY
8950 vty_out(vty, "BGP table version %" PRIu64 "\n",
8951 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 8952
60466a63 8953 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
8954 vty_out(vty,
8955 "RIB entries %ld, using %s of memory\n",
8956 ents,
996c9314
LB
8957 mtype_memstr(memstrbuf,
8958 sizeof(memstrbuf),
8959 ents * sizeof(struct
8960 bgp_node)));
ea47320b
DL
8961
8962 /* Peer related usage */
210ec2a0 8963 ents = bgp->af_peer_count[afi][safi];
60466a63 8964 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
8965 ents,
8966 mtype_memstr(
60466a63
QY
8967 memstrbuf, sizeof(memstrbuf),
8968 ents * sizeof(struct peer)));
ea47320b
DL
8969
8970 if ((ents = listcount(bgp->group)))
d62a17ae 8971 vty_out(vty,
ea47320b 8972 "Peer groups %ld, using %s of memory\n",
d62a17ae 8973 ents,
8974 mtype_memstr(
8975 memstrbuf,
8976 sizeof(memstrbuf),
996c9314
LB
8977 ents * sizeof(struct
8978 peer_group)));
d62a17ae 8979
ea47320b
DL
8980 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8981 BGP_CONFIG_DAMPENING))
60466a63 8982 vty_out(vty, "Dampening enabled.\n");
ea47320b 8983 vty_out(vty, "\n");
d62a17ae 8984
ea47320b
DL
8985 /* Subtract 8 here because 'Neighbor' is
8986 * 8 characters */
8987 vty_out(vty, "Neighbor");
60466a63
QY
8988 vty_out(vty, "%*s", max_neighbor_width - 8,
8989 " ");
3577f1c5
DD
8990 if (show_failed)
8991 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
8992 else
8993 vty_out(vty,
ea47320b 8994 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 8995 }
ea47320b 8996 }
d62a17ae 8997
ea47320b 8998 count++;
3577f1c5
DD
8999 /* Works for both failed & successful cases */
9000 if (peer_dynamic_neighbor(peer))
9001 dn_count++;
d62a17ae 9002
ea47320b 9003 if (use_json) {
3577f1c5
DD
9004 json_peer = NULL;
9005
9006 if (show_failed &&
9007 bgp_has_peer_failed(peer, afi, safi)) {
9008 json_peer = json_object_new_object();
9009 bgp_show_failed_summary(vty, bgp, peer,
9010 json_peer, 0, use_json);
9011 } else if (!show_failed) {
9012 json_peer = json_object_new_object();
9013 if (peer_dynamic_neighbor(peer)) {
9014 json_object_boolean_true_add(json_peer,
9015 "dynamicPeer");
9016 }
d62a17ae 9017
3577f1c5
DD
9018 if (peer->hostname)
9019 json_object_string_add(json_peer, "hostname",
9020 peer->hostname);
9021
9022 if (peer->domainname)
9023 json_object_string_add(json_peer, "domainname",
9024 peer->domainname);
9025
9026 json_object_int_add(json_peer, "remoteAs", peer->as);
9027 json_object_int_add(json_peer, "version", 4);
9028 json_object_int_add(json_peer, "msgRcvd",
9029 PEER_TOTAL_RX(peer));
9030 json_object_int_add(json_peer, "msgSent",
9031 PEER_TOTAL_TX(peer));
9032
9033 json_object_int_add(json_peer, "tableVersion",
9034 peer->version[afi][safi]);
9035 json_object_int_add(json_peer, "outq",
9036 peer->obuf->count);
9037 json_object_int_add(json_peer, "inq", 0);
9038 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9039 use_json, json_peer);
9040
9041 /*
9042 * Adding "pfxRcd" field to match with the corresponding
9043 * CLI. "prefixReceivedCount" will be deprecated in
9044 * future.
9045 */
9046 json_object_int_add(json_peer, "prefixReceivedCount",
9047 peer->pcount[afi][pfx_rcd_safi]);
9048 json_object_int_add(json_peer, "pfxRcd",
9049 peer->pcount[afi][pfx_rcd_safi]);
9050
9051 paf = peer_af_find(peer, afi, pfx_rcd_safi);
9052 if (paf && PAF_SUBGRP(paf))
9053 json_object_int_add(json_peer,
9054 "pfxSnt",
9055 (PAF_SUBGRP(paf))->scount);
9056 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9057 json_object_string_add(json_peer, "state",
9058 "Idle (Admin)");
9059 else if (peer->afc_recv[afi][safi])
9060 json_object_string_add(
9061 json_peer, "state",
9062 lookup_msg(bgp_status_msg, peer->status,
9063 NULL));
9064 else if (CHECK_FLAG(peer->sflags,
9065 PEER_STATUS_PREFIX_OVERFLOW))
9066 json_object_string_add(json_peer, "state",
9067 "Idle (PfxCt)");
9068 else
9069 json_object_string_add(
9070 json_peer, "state",
9071 lookup_msg(bgp_status_msg, peer->status,
9072 NULL));
200116db
DD
9073 json_object_int_add(json_peer, "connectionsEstablished",
9074 peer->established);
9075 json_object_int_add(json_peer, "connectionsDropped",
9076 peer->dropped);
b4e9dcba 9077 }
3577f1c5
DD
9078 /* Avoid creating empty peer dicts in JSON */
9079 if (json_peer == NULL)
9080 continue;
ea47320b
DL
9081
9082 if (peer->conf_if)
60466a63 9083 json_object_string_add(json_peer, "idType",
ea47320b
DL
9084 "interface");
9085 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9086 json_object_string_add(json_peer, "idType",
9087 "ipv4");
ea47320b 9088 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9089 json_object_string_add(json_peer, "idType",
9090 "ipv6");
ea47320b
DL
9091 json_object_object_add(json_peers, peer->host,
9092 json_peer);
9093 } else {
3577f1c5
DD
9094 if (show_failed &&
9095 bgp_has_peer_failed(peer, afi, safi)) {
9096 bgp_show_failed_summary(vty, bgp, peer, NULL,
9097 max_neighbor_width,
9098 use_json);
9099 } else if (!show_failed) {
9100 memset(dn_flag, '\0', sizeof(dn_flag));
9101 if (peer_dynamic_neighbor(peer)) {
9102 dn_flag[0] = '*';
9103 }
d62a17ae 9104
3577f1c5 9105 if (peer->hostname
892fedb6
DA
9106 && CHECK_FLAG(bgp->flags,
9107 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9108 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9109 peer->hostname,
9110 peer->host);
d62a17ae 9111 else
3577f1c5
DD
9112 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9113
9114 /* pad the neighbor column with spaces */
9115 if (len < max_neighbor_width)
9116 vty_out(vty, "%*s", max_neighbor_width - len,
9117 " ");
9118
9119 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
9120 peer->as, PEER_TOTAL_RX(peer),
9121 PEER_TOTAL_TX(peer), peer->version[afi][safi],
9122 0, peer->obuf->count,
9123 peer_uptime(peer->uptime, timebuf,
9124 BGP_UPTIME_LEN, 0, NULL));
9125
9126 if (peer->status == Established)
9127 if (peer->afc_recv[afi][safi])
a0a87037
DA
9128 vty_out(vty, " %12" PRIu32,
9129 peer->pcount
9130 [afi]
9131 [pfx_rcd_safi]);
3577f1c5
DD
9132 else
9133 vty_out(vty, " NoNeg");
9134 else {
9135 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
9136 vty_out(vty, " Idle (Admin)");
9137 else if (CHECK_FLAG(
9138 peer->sflags,
9139 PEER_STATUS_PREFIX_OVERFLOW))
9140 vty_out(vty, " Idle (PfxCt)");
9141 else
9142 vty_out(vty, " %12s",
9143 lookup_msg(bgp_status_msg,
9144 peer->status, NULL));
9145 }
9146 vty_out(vty, "\n");
d62a17ae 9147 }
3577f1c5 9148
d62a17ae 9149 }
9150 }
f933309e 9151
d62a17ae 9152 if (use_json) {
9153 json_object_object_add(json, "peers", json_peers);
3577f1c5 9154 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 9155 json_object_int_add(json, "totalPeers", count);
9156 json_object_int_add(json, "dynamicPeers", dn_count);
9157
3577f1c5
DD
9158 if (!show_failed)
9159 bgp_show_bestpath_json(bgp, json);
57a9c8a8 9160
996c9314
LB
9161 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9162 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9163 json_object_free(json);
9164 } else {
9165 if (count)
9166 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9167 else {
d6ceaca3 9168 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 9169 get_afi_safi_str(afi, safi, false));
d62a17ae 9170 }
b05a1c8b 9171
d6ceaca3 9172 if (dn_count) {
d62a17ae 9173 vty_out(vty, "* - dynamic neighbor\n");
9174 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
9175 dn_count, bgp->dynamic_neighbors_limit);
9176 }
9177 }
1ff9a340 9178
d62a17ae 9179 return CMD_SUCCESS;
718e3744 9180}
9181
d62a17ae 9182static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
3577f1c5 9183 int safi, bool show_failed, bool use_json)
d62a17ae 9184{
9185 int is_first = 1;
9186 int afi_wildcard = (afi == AFI_MAX);
9187 int safi_wildcard = (safi == SAFI_MAX);
9188 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 9189 bool nbr_output = false;
d62a17ae 9190
9191 if (use_json && is_wildcard)
9192 vty_out(vty, "{\n");
9193 if (afi_wildcard)
9194 afi = 1; /* AFI_IP */
9195 while (afi < AFI_MAX) {
9196 if (safi_wildcard)
9197 safi = 1; /* SAFI_UNICAST */
9198 while (safi < SAFI_MAX) {
318cac96 9199 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 9200 nbr_output = true;
f86897b9 9201
d62a17ae 9202 if (is_wildcard) {
9203 /*
9204 * So limit output to those afi/safi
9205 * pairs that
9206 * actualy have something interesting in
9207 * them
9208 */
9209 if (use_json) {
d62a17ae 9210 if (!is_first)
9211 vty_out(vty, ",\n");
9212 else
9213 is_first = 0;
9214
9215 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
9216 get_afi_safi_str(afi,
9217 safi,
9218 true));
d62a17ae 9219 } else {
9220 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
9221 get_afi_safi_str(afi,
9222 safi,
9223 false));
d62a17ae 9224 }
9225 }
3577f1c5
DD
9226 bgp_show_summary(vty, bgp, afi, safi, show_failed,
9227 use_json);
d62a17ae 9228 }
9229 safi++;
d62a17ae 9230 if (!safi_wildcard)
9231 safi = SAFI_MAX;
9232 }
9233 afi++;
ee851c8c 9234 if (!afi_wildcard)
d62a17ae 9235 afi = AFI_MAX;
9236 }
9237
9238 if (use_json && is_wildcard)
9239 vty_out(vty, "}\n");
ca61fd25
DS
9240 else if (!nbr_output) {
9241 if (use_json)
9242 vty_out(vty, "{}\n");
9243 else
9244 vty_out(vty, "%% No BGP neighbors found\n");
9245 }
d62a17ae 9246}
9247
9248static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5
DD
9249 safi_t safi, bool show_failed,
9250 bool use_json)
d62a17ae 9251{
9252 struct listnode *node, *nnode;
9253 struct bgp *bgp;
d62a17ae 9254 int is_first = 1;
9f049418 9255 bool nbr_output = false;
d62a17ae 9256
9257 if (use_json)
9258 vty_out(vty, "{\n");
9259
9260 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 9261 nbr_output = true;
d62a17ae 9262 if (use_json) {
d62a17ae 9263 if (!is_first)
9264 vty_out(vty, ",\n");
9265 else
9266 is_first = 0;
9267
9268 vty_out(vty, "\"%s\":",
9269 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9270 ? VRF_DEFAULT_NAME
d62a17ae 9271 : bgp->name);
9272 } else {
9273 vty_out(vty, "\nInstance %s:\n",
9274 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9275 ? VRF_DEFAULT_NAME
d62a17ae 9276 : bgp->name);
9277 }
3577f1c5
DD
9278 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9279 use_json);
d62a17ae 9280 }
9281
9282 if (use_json)
9283 vty_out(vty, "}\n");
9f049418
DS
9284 else if (!nbr_output)
9285 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 9286}
9287
9288int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
3577f1c5 9289 safi_t safi, bool show_failed, bool use_json)
d62a17ae 9290{
9291 struct bgp *bgp;
9292
9293 if (name) {
9294 if (strmatch(name, "all")) {
9295 bgp_show_all_instances_summary_vty(vty, afi, safi,
3577f1c5 9296 show_failed,
d62a17ae 9297 use_json);
9298 return CMD_SUCCESS;
9299 } else {
9300 bgp = bgp_lookup_by_name(name);
9301
9302 if (!bgp) {
9303 if (use_json)
9304 vty_out(vty, "{}\n");
9305 else
9306 vty_out(vty,
ca61fd25 9307 "%% BGP instance not found\n");
d62a17ae 9308 return CMD_WARNING;
9309 }
9310
f86897b9 9311 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
3577f1c5 9312 show_failed, use_json);
d62a17ae 9313 return CMD_SUCCESS;
9314 }
9315 }
9316
9317 bgp = bgp_get_default();
9318
9319 if (bgp)
3577f1c5
DD
9320 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
9321 use_json);
9f049418 9322 else {
ca61fd25
DS
9323 if (use_json)
9324 vty_out(vty, "{}\n");
9325 else
9326 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
9327 return CMD_WARNING;
9328 }
d62a17ae 9329
9330 return CMD_SUCCESS;
4fb25c53
DW
9331}
9332
716b2d8a 9333/* `show [ip] bgp summary' commands. */
47fc97cc 9334DEFUN (show_ip_bgp_summary,
718e3744 9335 show_ip_bgp_summary_cmd,
3577f1c5 9336 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
718e3744 9337 SHOW_STR
9338 IP_STR
9339 BGP_STR
8386ac43 9340 BGP_INSTANCE_HELP_STR
46f296b4 9341 BGP_AFI_HELP_STR
dd6bd0f1 9342 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 9343 "Summary of BGP neighbor status\n"
3577f1c5 9344 "Show only sessions not in Established state\n"
9973d184 9345 JSON_STR)
718e3744 9346{
d62a17ae 9347 char *vrf = NULL;
9348 afi_t afi = AFI_MAX;
9349 safi_t safi = SAFI_MAX;
3577f1c5 9350 bool show_failed = false;
d62a17ae 9351
9352 int idx = 0;
9353
9354 /* show [ip] bgp */
9355 if (argv_find(argv, argc, "ip", &idx))
9356 afi = AFI_IP;
9a8bdf1c
PG
9357 /* [<vrf> VIEWVRFNAME] */
9358 if (argv_find(argv, argc, "vrf", &idx)) {
9359 vrf = argv[idx + 1]->arg;
9360 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9361 vrf = NULL;
9362 } else if (argv_find(argv, argc, "view", &idx))
9363 /* [<view> VIEWVRFNAME] */
9364 vrf = argv[idx + 1]->arg;
d62a17ae 9365 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9366 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
9367 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9368 }
9369
3577f1c5
DD
9370 if (argv_find(argv, argc, "failed", &idx))
9371 show_failed = true;
9372
9f049418 9373 bool uj = use_json(argc, argv);
d62a17ae 9374
3577f1c5 9375 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
d62a17ae 9376}
9377
5cb5f4d0 9378const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 9379{
5cb5f4d0
DD
9380 if (for_json)
9381 return get_afi_safi_json_str(afi, safi);
d62a17ae 9382 else
5cb5f4d0 9383 return get_afi_safi_vty_str(afi, safi);
27162734
LB
9384}
9385
d62a17ae 9386
9387static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
9388 afi_t afi, safi_t safi,
d7c0a89a
QY
9389 uint16_t adv_smcap, uint16_t adv_rmcap,
9390 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 9391 bool use_json, json_object *json_pref)
d62a17ae 9392{
9393 /* Send-Mode */
9394 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9395 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
9396 if (use_json) {
9397 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
9398 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9399 json_object_string_add(json_pref, "sendMode",
9400 "advertisedAndReceived");
9401 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9402 json_object_string_add(json_pref, "sendMode",
9403 "advertised");
9404 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9405 json_object_string_add(json_pref, "sendMode",
9406 "received");
9407 } else {
9408 vty_out(vty, " Send-mode: ");
9409 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
9410 vty_out(vty, "advertised");
9411 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
9412 vty_out(vty, "%sreceived",
9413 CHECK_FLAG(p->af_cap[afi][safi],
9414 adv_smcap)
9415 ? ", "
9416 : "");
9417 vty_out(vty, "\n");
9418 }
9419 }
9420
9421 /* Receive-Mode */
9422 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9423 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
9424 if (use_json) {
9425 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
9426 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9427 json_object_string_add(json_pref, "recvMode",
9428 "advertisedAndReceived");
9429 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9430 json_object_string_add(json_pref, "recvMode",
9431 "advertised");
9432 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9433 json_object_string_add(json_pref, "recvMode",
9434 "received");
9435 } else {
9436 vty_out(vty, " Receive-mode: ");
9437 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
9438 vty_out(vty, "advertised");
9439 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
9440 vty_out(vty, "%sreceived",
9441 CHECK_FLAG(p->af_cap[afi][safi],
9442 adv_rmcap)
9443 ? ", "
9444 : "");
9445 vty_out(vty, "\n");
9446 }
9447 }
9448}
9449
13909c4f
DS
9450static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
9451 struct peer *p,
9452 bool use_json,
9453 json_object *json)
2986cac2 9454{
9455 bool rbit_status = 0;
9456
9457 if (!use_json)
9458 vty_out(vty, "\n R bit : ");
9459
13909c4f
DS
9460 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
9461 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
9462 && (p->status == Established)) {
2986cac2 9463
9464 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
9465 rbit_status = 1;
9466 else
9467 rbit_status = 0;
9468 }
9469
9470 if (rbit_status) {
9471 if (use_json)
13909c4f 9472 json_object_boolean_true_add(json, "rBit");
2986cac2 9473 else
9474 vty_out(vty, "True\n");
9475 } else {
9476 if (use_json)
13909c4f 9477 json_object_boolean_false_add(json, "rBit");
2986cac2 9478 else
9479 vty_out(vty, "False\n");
9480 }
9481}
9482
13909c4f
DS
9483static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
9484 struct peer *peer,
9485 bool use_json,
9486 json_object *json)
2986cac2 9487{
2bb5d39b 9488 const char *mode = "NotApplicable";
2986cac2 9489
9490 if (!use_json)
9491 vty_out(vty, "\n Remote GR Mode : ");
9492
13909c4f
DS
9493 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9494 && (peer->status == Established)) {
2986cac2 9495
13909c4f
DS
9496 if ((peer->nsf_af_count == 0)
9497 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9498
2986cac2 9499 mode = "Disable";
9500
13909c4f
DS
9501 } else if (peer->nsf_af_count == 0
9502 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9503
2986cac2 9504 mode = "Helper";
9505
13909c4f
DS
9506 } else if (peer->nsf_af_count != 0
9507 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 9508
2986cac2 9509 mode = "Restart";
2986cac2 9510 }
9511 }
9512
9513 if (use_json) {
13909c4f 9514 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 9515 } else
9516 vty_out(vty, mode, "\n");
9517}
9518
13909c4f
DS
9519static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
9520 struct peer *p,
9521 bool use_json,
9522 json_object *json)
2986cac2 9523{
9524 const char *mode = "Invalid";
9525
9526 if (!use_json)
9527 vty_out(vty, " Local GR Mode : ");
9528
9529 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
9530 mode = "Helper";
9531 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
9532 mode = "Restart";
9533 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
9534 mode = "Disable";
2ba1fe69 9535 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 9536 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
9537 mode = "Helper*";
9538 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
9539 mode = "Restart*";
9540 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
9541 mode = "Disable*";
9542 else
9543 mode = "Invalid*";
2ba1fe69 9544 }
2986cac2 9545
9546 if (use_json) {
13909c4f 9547 json_object_string_add(json, "localGrMode", mode);
2986cac2 9548 } else {
9549 vty_out(vty, mode, "\n");
9550 }
9551}
9552
13909c4f
DS
9553static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
9554 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 9555{
2ba1fe69 9556 afi_t afi;
9557 safi_t safi;
2986cac2 9558 json_object *json_afi_safi = NULL;
9559 json_object *json_timer = NULL;
9560 json_object *json_endofrib_status = NULL;
9e3b51a7 9561 bool eor_flag = false;
2986cac2 9562
9563 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9564 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
9565 if (!peer->afc[afi][safi])
9566 continue;
2986cac2 9567
13909c4f
DS
9568 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
9569 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
9570 continue;
9e3b51a7 9571
13909c4f
DS
9572 if (use_json) {
9573 json_afi_safi = json_object_new_object();
9574 json_endofrib_status = json_object_new_object();
9575 json_timer = json_object_new_object();
9576 }
2986cac2 9577
13909c4f
DS
9578 if (peer->eor_stime[afi][safi]
9579 >= peer->pkt_stime[afi][safi])
9580 eor_flag = true;
9581 else
9582 eor_flag = false;
2986cac2 9583
13909c4f
DS
9584 if (!use_json) {
9585 vty_out(vty, " %s :\n",
9586 get_afi_safi_str(afi, safi, false));
2986cac2 9587
13909c4f 9588 vty_out(vty, " F bit : ");
698ba8d0 9589 }
2986cac2 9590
13909c4f
DS
9591 if (peer->nsf[afi][safi]
9592 && CHECK_FLAG(peer->af_cap[afi][safi],
9593 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 9594
13909c4f
DS
9595 if (use_json) {
9596 json_object_boolean_true_add(
2986cac2 9597 json_afi_safi, "fBit");
13909c4f
DS
9598 } else
9599 vty_out(vty, "True\n");
9600 } else {
9601 if (use_json)
9602 json_object_boolean_false_add(
9603 json_afi_safi, "fBit");
9604 else
9605 vty_out(vty, "False\n");
9606 }
2986cac2 9607
13909c4f
DS
9608 if (!use_json)
9609 vty_out(vty, " End-of-RIB Received : ");
2986cac2 9610
13909c4f
DS
9611 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9612 PEER_STATUS_EOR_RECEIVED)) {
9613 if (use_json)
9614 json_object_boolean_true_add(
2986cac2 9615 json_endofrib_status,
13909c4f
DS
9616 "endOfRibRecv");
9617 else
9618 vty_out(vty, "Yes\n");
9619 } else {
9620 if (use_json)
9621 json_object_boolean_false_add(
2986cac2 9622 json_endofrib_status,
13909c4f
DS
9623 "endOfRibRecv");
9624 else
9625 vty_out(vty, "No\n");
9626 }
2986cac2 9627
13909c4f
DS
9628 if (!use_json)
9629 vty_out(vty, " End-of-RIB Send : ");
2986cac2 9630
13909c4f
DS
9631 if (CHECK_FLAG(peer->af_sflags[afi][safi],
9632 PEER_STATUS_EOR_SEND)) {
9633 if (use_json) {
9634 json_object_boolean_true_add(
2986cac2 9635 json_endofrib_status,
13909c4f 9636 "endOfRibSend");
9e3b51a7 9637
13909c4f
DS
9638 PRINT_EOR_JSON(eor_flag);
9639 } else {
9640 vty_out(vty, "Yes\n");
9641 vty_out(vty,
9e3b51a7 9642 " EoRSentAfterUpdate : ");
2986cac2 9643
13909c4f
DS
9644 PRINT_EOR(eor_flag);
9645 }
9646 } else {
9647 if (use_json) {
9648 json_object_boolean_false_add(
2986cac2 9649 json_endofrib_status,
13909c4f
DS
9650 "endOfRibSend");
9651 json_object_boolean_false_add(
9e3b51a7 9652 json_endofrib_status,
13909c4f
DS
9653 "endOfRibSentAfterUpdate");
9654 } else {
9655 vty_out(vty, "No\n");
9656 vty_out(vty,
9e3b51a7 9657 " EoRSentAfterUpdate : ");
13909c4f 9658 vty_out(vty, "No\n");
2986cac2 9659 }
13909c4f 9660 }
2986cac2 9661
13909c4f
DS
9662 if (use_json) {
9663 json_object_int_add(json_timer,
9664 "stalePathTimer",
9665 peer->bgp->stalepath_time);
2986cac2 9666
13909c4f
DS
9667 if (peer->t_gr_stale != NULL) {
9668 json_object_int_add(
2986cac2 9669 json_timer,
9670 "stalePathTimerRemaining",
9671 thread_timer_remain_second(
13909c4f
DS
9672 peer->t_gr_stale));
9673 }
3a75afa4 9674
13909c4f
DS
9675 /* Display Configured Selection
9676 * Deferral only when when
9677 * Gr mode is enabled.
9678 */
9679 if (CHECK_FLAG(peer->flags,
9680 PEER_FLAG_GRACEFUL_RESTART)) {
9681 json_object_int_add(
3a75afa4 9682 json_timer,
2986cac2 9683 "selectionDeferralTimer",
9684 peer->bgp->stalepath_time);
13909c4f 9685 }
2986cac2 9686
13909c4f
DS
9687 if (peer->bgp->gr_info[afi][safi]
9688 .t_select_deferral
9689 != NULL) {
2986cac2 9690
13909c4f 9691 json_object_int_add(
2986cac2 9692 json_timer,
9693 "selectionDeferralTimerRemaining",
9694 thread_timer_remain_second(
13909c4f
DS
9695 peer->bgp
9696 ->gr_info[afi]
9697 [safi]
9698 .t_select_deferral));
9699 }
9700 } else {
9701 vty_out(vty, " Timers:\n");
2986cac2 9702
13909c4f
DS
9703 vty_out(vty, "%*s", 6, "");
9704 vty_out(vty,
9705 "Configured Stale Path Time(sec)%*s: %u\n",
9706 8, "", peer->bgp->stalepath_time);
2986cac2 9707
13909c4f 9708 if (peer->t_gr_stale != NULL) {
2986cac2 9709 vty_out(vty, "%*s", 6, "");
9710 vty_out(vty,
2986cac2 9711 "Stale Path Remaining(sec)%*s: %ld\n",
9712 14, "",
9713 thread_timer_remain_second(
13909c4f
DS
9714 peer->t_gr_stale));
9715 }
9716 /* Display Configured Selection
9717 * Deferral only when when
9718 * Gr mode is enabled.
9719 */
9720 if (CHECK_FLAG(peer->flags,
9721 PEER_FLAG_GRACEFUL_RESTART)) {
9722 vty_out(vty, "%*s", 6, "");
9723 vty_out(vty,
3a75afa4 9724 "Configured Selection Deferral Time(sec): %u\n",
9725 peer->bgp->select_defer_time);
13909c4f 9726 }
2986cac2 9727
13909c4f
DS
9728 if (peer->bgp->gr_info[afi][safi]
9729 .t_select_deferral
9730 != NULL) {
2986cac2 9731
13909c4f
DS
9732 vty_out(vty, "%*s", 6, "");
9733 vty_out(vty,
2986cac2 9734 "Selection Deferral Time Remaining(sec) : %ld\n",
9735 thread_timer_remain_second(
13909c4f
DS
9736 peer->bgp
9737 ->gr_info[afi]
9738 [safi]
9739 .t_select_deferral));
2986cac2 9740 }
9741 }
13909c4f
DS
9742 if (use_json) {
9743 json_object_object_add(json_afi_safi,
9744 "endOfRibStatus",
9745 json_endofrib_status);
9746 json_object_object_add(json_afi_safi, "timers",
9747 json_timer);
9748 json_object_object_add(
9749 json, get_afi_safi_str(afi, safi, true),
9750 json_afi_safi);
9751 }
2986cac2 9752 }
9753 }
9754}
9755
36235319
QY
9756static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
9757 struct peer *p,
9758 bool use_json,
9759 json_object *json)
2986cac2 9760{
9761 if (use_json) {
9762 json_object *json_timer = NULL;
9763
9764 json_timer = json_object_new_object();
9765
13909c4f
DS
9766 json_object_int_add(json_timer, "configuredRestartTimer",
9767 p->bgp->restart_time);
2986cac2 9768
13909c4f
DS
9769 json_object_int_add(json_timer, "receivedRestartTimer",
9770 p->v_gr_restart);
2986cac2 9771
13909c4f
DS
9772 if (p->t_gr_restart != NULL)
9773 json_object_int_add(
9774 json_timer, "restartTimerRemaining",
9775 thread_timer_remain_second(p->t_gr_restart));
2986cac2 9776
9777 json_object_object_add(json, "timers", json_timer);
9778 } else {
9779
9780 vty_out(vty, " Timers :\n");
13909c4f
DS
9781 vty_out(vty, " Configured Restart Time(sec) : %u\n",
9782 p->bgp->restart_time);
2986cac2 9783
13909c4f
DS
9784 vty_out(vty, " Received Restart Time(sec) : %u\n",
9785 p->v_gr_restart);
9786 if (p->t_gr_restart != NULL)
2986cac2 9787 vty_out(vty,
13909c4f
DS
9788 " Restart Time Remaining(sec) : %ld\n",
9789 thread_timer_remain_second(p->t_gr_restart));
36235319
QY
9790 if (p->t_gr_restart != NULL) {
9791 vty_out(vty,
9792 " Restart Time Remaining(sec) : %ld\n",
9793 thread_timer_remain_second(p->t_gr_restart));
9794 }
2986cac2 9795 }
9796}
9797
9798static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 9799 bool use_json, json_object *json)
2986cac2 9800{
9801 char buf[SU_ADDRSTRLEN] = {0};
9802 char dn_flag[2] = {0};
9803 char neighborAddr[INET6_ADDRSTRLEN] = {0};
9804
2986cac2 9805 if (!p->conf_if && peer_dynamic_neighbor(p))
9806 dn_flag[0] = '*';
9807
9808 if (p->conf_if) {
9809 if (use_json)
13909c4f
DS
9810 json_object_string_add(
9811 json, "neighborAddr",
2986cac2 9812 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
9813 ? "none"
9814 : sockunion2str(&p->su, buf,
9815 SU_ADDRSTRLEN));
2986cac2 9816 else
13909c4f 9817 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 9818 BGP_PEER_SU_UNSPEC(p)
9819 ? "none"
9820 : sockunion2str(&p->su, buf,
9821 SU_ADDRSTRLEN));
9822 } else {
9823 sprintf(neighborAddr, "%s%s", dn_flag, p->host);
9824
9825 if (use_json)
36235319
QY
9826 json_object_string_add(json, "neighborAddr",
9827 neighborAddr);
2986cac2 9828 else
36235319 9829 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 9830 }
9831
9832 /* more gr info in new format */
9833 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
9834}
9835
d62a17ae 9836static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 9837 safi_t safi, bool use_json,
d62a17ae 9838 json_object *json_neigh)
9839{
0291c246
MK
9840 struct bgp_filter *filter;
9841 struct peer_af *paf;
9842 char orf_pfx_name[BUFSIZ];
9843 int orf_pfx_count;
9844 json_object *json_af = NULL;
9845 json_object *json_prefA = NULL;
9846 json_object *json_prefB = NULL;
9847 json_object *json_addr = NULL;
d62a17ae 9848
9849 if (use_json) {
9850 json_addr = json_object_new_object();
9851 json_af = json_object_new_object();
9852 filter = &p->filter[afi][safi];
9853
9854 if (peer_group_active(p))
9855 json_object_string_add(json_addr, "peerGroupMember",
9856 p->group->name);
9857
9858 paf = peer_af_find(p, afi, safi);
9859 if (paf && PAF_SUBGRP(paf)) {
9860 json_object_int_add(json_addr, "updateGroupId",
9861 PAF_UPDGRP(paf)->id);
9862 json_object_int_add(json_addr, "subGroupId",
9863 PAF_SUBGRP(paf)->id);
9864 json_object_int_add(json_addr, "packetQueueLength",
9865 bpacket_queue_virtual_length(paf));
9866 }
9867
9868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9869 || CHECK_FLAG(p->af_cap[afi][safi],
9870 PEER_CAP_ORF_PREFIX_SM_RCV)
9871 || CHECK_FLAG(p->af_cap[afi][safi],
9872 PEER_CAP_ORF_PREFIX_RM_ADV)
9873 || CHECK_FLAG(p->af_cap[afi][safi],
9874 PEER_CAP_ORF_PREFIX_RM_RCV)) {
9875 json_object_int_add(json_af, "orfType",
9876 ORF_TYPE_PREFIX);
9877 json_prefA = json_object_new_object();
9878 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
9879 PEER_CAP_ORF_PREFIX_SM_ADV,
9880 PEER_CAP_ORF_PREFIX_RM_ADV,
9881 PEER_CAP_ORF_PREFIX_SM_RCV,
9882 PEER_CAP_ORF_PREFIX_RM_RCV,
9883 use_json, json_prefA);
9884 json_object_object_add(json_af, "orfPrefixList",
9885 json_prefA);
9886 }
9887
9888 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9889 || CHECK_FLAG(p->af_cap[afi][safi],
9890 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9891 || CHECK_FLAG(p->af_cap[afi][safi],
9892 PEER_CAP_ORF_PREFIX_RM_ADV)
9893 || CHECK_FLAG(p->af_cap[afi][safi],
9894 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
9895 json_object_int_add(json_af, "orfOldType",
9896 ORF_TYPE_PREFIX_OLD);
9897 json_prefB = json_object_new_object();
9898 bgp_show_peer_afi_orf_cap(
9899 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
9900 PEER_CAP_ORF_PREFIX_RM_ADV,
9901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
9902 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
9903 json_prefB);
9904 json_object_object_add(json_af, "orfOldPrefixList",
9905 json_prefB);
9906 }
9907
9908 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
9909 || CHECK_FLAG(p->af_cap[afi][safi],
9910 PEER_CAP_ORF_PREFIX_SM_RCV)
9911 || CHECK_FLAG(p->af_cap[afi][safi],
9912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
9913 || CHECK_FLAG(p->af_cap[afi][safi],
9914 PEER_CAP_ORF_PREFIX_RM_ADV)
9915 || CHECK_FLAG(p->af_cap[afi][safi],
9916 PEER_CAP_ORF_PREFIX_RM_RCV)
9917 || CHECK_FLAG(p->af_cap[afi][safi],
9918 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
9919 json_object_object_add(json_addr, "afDependentCap",
9920 json_af);
9921 else
9922 json_object_free(json_af);
9923
9924 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
9925 orf_pfx_count = prefix_bgp_show_prefix_list(
9926 NULL, afi, orf_pfx_name, use_json);
9927
9928 if (CHECK_FLAG(p->af_sflags[afi][safi],
9929 PEER_STATUS_ORF_PREFIX_SEND)
9930 || orf_pfx_count) {
9931 if (CHECK_FLAG(p->af_sflags[afi][safi],
9932 PEER_STATUS_ORF_PREFIX_SEND))
9933 json_object_boolean_true_add(json_neigh,
9934 "orfSent");
9935 if (orf_pfx_count)
9936 json_object_int_add(json_addr, "orfRecvCounter",
9937 orf_pfx_count);
9938 }
9939 if (CHECK_FLAG(p->af_sflags[afi][safi],
9940 PEER_STATUS_ORF_WAIT_REFRESH))
9941 json_object_string_add(
9942 json_addr, "orfFirstUpdate",
9943 "deferredUntilORFOrRouteRefreshRecvd");
9944
9945 if (CHECK_FLAG(p->af_flags[afi][safi],
9946 PEER_FLAG_REFLECTOR_CLIENT))
9947 json_object_boolean_true_add(json_addr,
9948 "routeReflectorClient");
9949 if (CHECK_FLAG(p->af_flags[afi][safi],
9950 PEER_FLAG_RSERVER_CLIENT))
9951 json_object_boolean_true_add(json_addr,
9952 "routeServerClient");
9953 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9954 json_object_boolean_true_add(json_addr,
9955 "inboundSoftConfigPermit");
9956
9957 if (CHECK_FLAG(p->af_flags[afi][safi],
9958 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9959 json_object_boolean_true_add(
9960 json_addr,
9961 "privateAsNumsAllReplacedInUpdatesToNbr");
9962 else if (CHECK_FLAG(p->af_flags[afi][safi],
9963 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9964 json_object_boolean_true_add(
9965 json_addr,
9966 "privateAsNumsReplacedInUpdatesToNbr");
9967 else if (CHECK_FLAG(p->af_flags[afi][safi],
9968 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9969 json_object_boolean_true_add(
9970 json_addr,
9971 "privateAsNumsAllRemovedInUpdatesToNbr");
9972 else if (CHECK_FLAG(p->af_flags[afi][safi],
9973 PEER_FLAG_REMOVE_PRIVATE_AS))
9974 json_object_boolean_true_add(
9975 json_addr,
9976 "privateAsNumsRemovedInUpdatesToNbr");
9977
dcc68b5e
MS
9978 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9979 json_object_boolean_true_add(
9980 json_addr,
9981 bgp_addpath_names(p->addpath_type[afi][safi])
9982 ->type_json_name);
d62a17ae 9983
9984 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9985 json_object_string_add(json_addr,
9986 "overrideASNsInOutboundUpdates",
9987 "ifAspathEqualRemoteAs");
9988
9989 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9990 || CHECK_FLAG(p->af_flags[afi][safi],
9991 PEER_FLAG_FORCE_NEXTHOP_SELF))
9992 json_object_boolean_true_add(json_addr,
9993 "routerAlwaysNextHop");
9994 if (CHECK_FLAG(p->af_flags[afi][safi],
9995 PEER_FLAG_AS_PATH_UNCHANGED))
9996 json_object_boolean_true_add(
9997 json_addr, "unchangedAsPathPropogatedToNbr");
9998 if (CHECK_FLAG(p->af_flags[afi][safi],
9999 PEER_FLAG_NEXTHOP_UNCHANGED))
10000 json_object_boolean_true_add(
10001 json_addr, "unchangedNextHopPropogatedToNbr");
10002 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10003 json_object_boolean_true_add(
10004 json_addr, "unchangedMedPropogatedToNbr");
10005 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10006 || CHECK_FLAG(p->af_flags[afi][safi],
10007 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10008 if (CHECK_FLAG(p->af_flags[afi][safi],
10009 PEER_FLAG_SEND_COMMUNITY)
10010 && CHECK_FLAG(p->af_flags[afi][safi],
10011 PEER_FLAG_SEND_EXT_COMMUNITY))
10012 json_object_string_add(json_addr,
10013 "commAttriSentToNbr",
10014 "extendedAndStandard");
10015 else if (CHECK_FLAG(p->af_flags[afi][safi],
10016 PEER_FLAG_SEND_EXT_COMMUNITY))
10017 json_object_string_add(json_addr,
10018 "commAttriSentToNbr",
10019 "extended");
10020 else
10021 json_object_string_add(json_addr,
10022 "commAttriSentToNbr",
10023 "standard");
10024 }
10025 if (CHECK_FLAG(p->af_flags[afi][safi],
10026 PEER_FLAG_DEFAULT_ORIGINATE)) {
10027 if (p->default_rmap[afi][safi].name)
10028 json_object_string_add(
10029 json_addr, "defaultRouteMap",
10030 p->default_rmap[afi][safi].name);
10031
10032 if (paf && PAF_SUBGRP(paf)
10033 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10034 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10035 json_object_boolean_true_add(json_addr,
10036 "defaultSent");
10037 else
10038 json_object_boolean_true_add(json_addr,
10039 "defaultNotSent");
10040 }
10041
dff8f48d 10042 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10043 if (is_evpn_enabled())
60466a63
QY
10044 json_object_boolean_true_add(
10045 json_addr, "advertiseAllVnis");
dff8f48d
MK
10046 }
10047
d62a17ae 10048 if (filter->plist[FILTER_IN].name
10049 || filter->dlist[FILTER_IN].name
10050 || filter->aslist[FILTER_IN].name
10051 || filter->map[RMAP_IN].name)
10052 json_object_boolean_true_add(json_addr,
10053 "inboundPathPolicyConfig");
10054 if (filter->plist[FILTER_OUT].name
10055 || filter->dlist[FILTER_OUT].name
10056 || filter->aslist[FILTER_OUT].name
10057 || filter->map[RMAP_OUT].name || filter->usmap.name)
10058 json_object_boolean_true_add(
10059 json_addr, "outboundPathPolicyConfig");
10060
10061 /* prefix-list */
10062 if (filter->plist[FILTER_IN].name)
10063 json_object_string_add(json_addr,
10064 "incomingUpdatePrefixFilterList",
10065 filter->plist[FILTER_IN].name);
10066 if (filter->plist[FILTER_OUT].name)
10067 json_object_string_add(json_addr,
10068 "outgoingUpdatePrefixFilterList",
10069 filter->plist[FILTER_OUT].name);
10070
10071 /* distribute-list */
10072 if (filter->dlist[FILTER_IN].name)
10073 json_object_string_add(
10074 json_addr, "incomingUpdateNetworkFilterList",
10075 filter->dlist[FILTER_IN].name);
10076 if (filter->dlist[FILTER_OUT].name)
10077 json_object_string_add(
10078 json_addr, "outgoingUpdateNetworkFilterList",
10079 filter->dlist[FILTER_OUT].name);
10080
10081 /* filter-list. */
10082 if (filter->aslist[FILTER_IN].name)
10083 json_object_string_add(json_addr,
10084 "incomingUpdateAsPathFilterList",
10085 filter->aslist[FILTER_IN].name);
10086 if (filter->aslist[FILTER_OUT].name)
10087 json_object_string_add(json_addr,
10088 "outgoingUpdateAsPathFilterList",
10089 filter->aslist[FILTER_OUT].name);
10090
10091 /* route-map. */
10092 if (filter->map[RMAP_IN].name)
10093 json_object_string_add(
10094 json_addr, "routeMapForIncomingAdvertisements",
10095 filter->map[RMAP_IN].name);
10096 if (filter->map[RMAP_OUT].name)
10097 json_object_string_add(
10098 json_addr, "routeMapForOutgoingAdvertisements",
10099 filter->map[RMAP_OUT].name);
10100
9dac9fc8
DA
10101 /* ebgp-requires-policy (inbound) */
10102 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10103 && !bgp_inbound_policy_exists(p, filter))
10104 json_object_string_add(
10105 json_addr, "inboundEbgpRequiresPolicy",
10106 "Inbound updates discarded due to missing policy");
10107
10108 /* ebgp-requires-policy (outbound) */
10109 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10110 && (!bgp_outbound_policy_exists(p, filter)))
10111 json_object_string_add(
10112 json_addr, "outboundEbgpRequiresPolicy",
10113 "Outbound updates discarded due to missing policy");
10114
d62a17ae 10115 /* unsuppress-map */
10116 if (filter->usmap.name)
10117 json_object_string_add(json_addr,
10118 "selectiveUnsuppressRouteMap",
10119 filter->usmap.name);
10120
10121 /* Receive prefix count */
10122 json_object_int_add(json_addr, "acceptedPrefixCounter",
10123 p->pcount[afi][safi]);
50e05855
AD
10124 if (paf && PAF_SUBGRP(paf))
10125 json_object_int_add(json_addr, "sentPrefixCounter",
10126 (PAF_SUBGRP(paf))->scount);
d62a17ae 10127
fde246e8
DA
10128 /* Maximum prefix */
10129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10130 json_object_int_add(json_addr, "prefixOutAllowedMax",
10131 p->pmax_out[afi][safi]);
10132
d62a17ae 10133 /* Maximum prefix */
10134 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
10135 json_object_int_add(json_addr, "prefixAllowedMax",
10136 p->pmax[afi][safi]);
10137 if (CHECK_FLAG(p->af_flags[afi][safi],
10138 PEER_FLAG_MAX_PREFIX_WARNING))
10139 json_object_boolean_true_add(
10140 json_addr, "prefixAllowedMaxWarning");
10141 json_object_int_add(json_addr,
10142 "prefixAllowedWarningThresh",
10143 p->pmax_threshold[afi][safi]);
10144 if (p->pmax_restart[afi][safi])
10145 json_object_int_add(
10146 json_addr,
10147 "prefixAllowedRestartIntervalMsecs",
10148 p->pmax_restart[afi][safi] * 60000);
10149 }
2986cac2 10150 json_object_object_add(json_neigh,
36235319 10151 get_afi_safi_str(afi, safi, true),
d62a17ae 10152 json_addr);
10153
10154 } else {
10155 filter = &p->filter[afi][safi];
10156
10157 vty_out(vty, " For address family: %s\n",
5cb5f4d0 10158 get_afi_safi_str(afi, safi, false));
d62a17ae 10159
10160 if (peer_group_active(p))
10161 vty_out(vty, " %s peer-group member\n",
10162 p->group->name);
10163
10164 paf = peer_af_find(p, afi, safi);
10165 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
10166 vty_out(vty, " Update group %" PRIu64
10167 ", subgroup %" PRIu64 "\n",
d62a17ae 10168 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
10169 vty_out(vty, " Packet Queue length %d\n",
10170 bpacket_queue_virtual_length(paf));
10171 } else {
10172 vty_out(vty, " Not part of any update group\n");
10173 }
10174 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10175 || CHECK_FLAG(p->af_cap[afi][safi],
10176 PEER_CAP_ORF_PREFIX_SM_RCV)
10177 || CHECK_FLAG(p->af_cap[afi][safi],
10178 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10179 || CHECK_FLAG(p->af_cap[afi][safi],
10180 PEER_CAP_ORF_PREFIX_RM_ADV)
10181 || CHECK_FLAG(p->af_cap[afi][safi],
10182 PEER_CAP_ORF_PREFIX_RM_RCV)
10183 || CHECK_FLAG(p->af_cap[afi][safi],
10184 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10185 vty_out(vty, " AF-dependant capabilities:\n");
10186
10187 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10188 || CHECK_FLAG(p->af_cap[afi][safi],
10189 PEER_CAP_ORF_PREFIX_SM_RCV)
10190 || CHECK_FLAG(p->af_cap[afi][safi],
10191 PEER_CAP_ORF_PREFIX_RM_ADV)
10192 || CHECK_FLAG(p->af_cap[afi][safi],
10193 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10194 vty_out(vty,
10195 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10196 ORF_TYPE_PREFIX);
10197 bgp_show_peer_afi_orf_cap(
10198 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10199 PEER_CAP_ORF_PREFIX_RM_ADV,
10200 PEER_CAP_ORF_PREFIX_SM_RCV,
10201 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
10202 }
10203 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10204 || CHECK_FLAG(p->af_cap[afi][safi],
10205 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10206 || CHECK_FLAG(p->af_cap[afi][safi],
10207 PEER_CAP_ORF_PREFIX_RM_ADV)
10208 || CHECK_FLAG(p->af_cap[afi][safi],
10209 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10210 vty_out(vty,
10211 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
10212 ORF_TYPE_PREFIX_OLD);
10213 bgp_show_peer_afi_orf_cap(
10214 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10215 PEER_CAP_ORF_PREFIX_RM_ADV,
10216 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10217 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
10218 }
10219
10220 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
10221 orf_pfx_count = prefix_bgp_show_prefix_list(
10222 NULL, afi, orf_pfx_name, use_json);
10223
10224 if (CHECK_FLAG(p->af_sflags[afi][safi],
10225 PEER_STATUS_ORF_PREFIX_SEND)
10226 || orf_pfx_count) {
10227 vty_out(vty, " Outbound Route Filter (ORF):");
10228 if (CHECK_FLAG(p->af_sflags[afi][safi],
10229 PEER_STATUS_ORF_PREFIX_SEND))
10230 vty_out(vty, " sent;");
10231 if (orf_pfx_count)
10232 vty_out(vty, " received (%d entries)",
10233 orf_pfx_count);
10234 vty_out(vty, "\n");
10235 }
10236 if (CHECK_FLAG(p->af_sflags[afi][safi],
10237 PEER_STATUS_ORF_WAIT_REFRESH))
10238 vty_out(vty,
10239 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
10240
10241 if (CHECK_FLAG(p->af_flags[afi][safi],
10242 PEER_FLAG_REFLECTOR_CLIENT))
10243 vty_out(vty, " Route-Reflector Client\n");
10244 if (CHECK_FLAG(p->af_flags[afi][safi],
10245 PEER_FLAG_RSERVER_CLIENT))
10246 vty_out(vty, " Route-Server Client\n");
10247 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10248 vty_out(vty,
10249 " Inbound soft reconfiguration allowed\n");
10250
10251 if (CHECK_FLAG(p->af_flags[afi][safi],
10252 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10253 vty_out(vty,
10254 " Private AS numbers (all) replaced in updates to this neighbor\n");
10255 else if (CHECK_FLAG(p->af_flags[afi][safi],
10256 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10257 vty_out(vty,
10258 " Private AS numbers replaced in updates to this neighbor\n");
10259 else if (CHECK_FLAG(p->af_flags[afi][safi],
10260 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10261 vty_out(vty,
10262 " Private AS numbers (all) removed in updates to this neighbor\n");
10263 else if (CHECK_FLAG(p->af_flags[afi][safi],
10264 PEER_FLAG_REMOVE_PRIVATE_AS))
10265 vty_out(vty,
10266 " Private AS numbers removed in updates to this neighbor\n");
10267
dcc68b5e
MS
10268 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10269 vty_out(vty, " %s\n",
10270 bgp_addpath_names(p->addpath_type[afi][safi])
10271 ->human_description);
d62a17ae 10272
10273 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10274 vty_out(vty,
10275 " Override ASNs in outbound updates if aspath equals remote-as\n");
10276
10277 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10278 || CHECK_FLAG(p->af_flags[afi][safi],
10279 PEER_FLAG_FORCE_NEXTHOP_SELF))
10280 vty_out(vty, " NEXT_HOP is always this router\n");
10281 if (CHECK_FLAG(p->af_flags[afi][safi],
10282 PEER_FLAG_AS_PATH_UNCHANGED))
10283 vty_out(vty,
10284 " AS_PATH is propagated unchanged to this neighbor\n");
10285 if (CHECK_FLAG(p->af_flags[afi][safi],
10286 PEER_FLAG_NEXTHOP_UNCHANGED))
10287 vty_out(vty,
10288 " NEXT_HOP is propagated unchanged to this neighbor\n");
10289 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10290 vty_out(vty,
10291 " MED is propagated unchanged to this neighbor\n");
10292 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10293 || CHECK_FLAG(p->af_flags[afi][safi],
10294 PEER_FLAG_SEND_EXT_COMMUNITY)
10295 || CHECK_FLAG(p->af_flags[afi][safi],
10296 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
10297 vty_out(vty,
10298 " Community attribute sent to this neighbor");
10299 if (CHECK_FLAG(p->af_flags[afi][safi],
10300 PEER_FLAG_SEND_COMMUNITY)
10301 && CHECK_FLAG(p->af_flags[afi][safi],
10302 PEER_FLAG_SEND_EXT_COMMUNITY)
10303 && CHECK_FLAG(p->af_flags[afi][safi],
10304 PEER_FLAG_SEND_LARGE_COMMUNITY))
10305 vty_out(vty, "(all)\n");
10306 else if (CHECK_FLAG(p->af_flags[afi][safi],
10307 PEER_FLAG_SEND_LARGE_COMMUNITY))
10308 vty_out(vty, "(large)\n");
10309 else if (CHECK_FLAG(p->af_flags[afi][safi],
10310 PEER_FLAG_SEND_EXT_COMMUNITY))
10311 vty_out(vty, "(extended)\n");
10312 else
10313 vty_out(vty, "(standard)\n");
10314 }
10315 if (CHECK_FLAG(p->af_flags[afi][safi],
10316 PEER_FLAG_DEFAULT_ORIGINATE)) {
10317 vty_out(vty, " Default information originate,");
10318
10319 if (p->default_rmap[afi][safi].name)
10320 vty_out(vty, " default route-map %s%s,",
10321 p->default_rmap[afi][safi].map ? "*"
10322 : "",
10323 p->default_rmap[afi][safi].name);
10324 if (paf && PAF_SUBGRP(paf)
10325 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10326 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10327 vty_out(vty, " default sent\n");
10328 else
10329 vty_out(vty, " default not sent\n");
10330 }
10331
dff8f48d
MK
10332 /* advertise-vni-all */
10333 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10334 if (is_evpn_enabled())
dff8f48d
MK
10335 vty_out(vty, " advertise-all-vni\n");
10336 }
10337
d62a17ae 10338 if (filter->plist[FILTER_IN].name
10339 || filter->dlist[FILTER_IN].name
10340 || filter->aslist[FILTER_IN].name
10341 || filter->map[RMAP_IN].name)
10342 vty_out(vty, " Inbound path policy configured\n");
10343 if (filter->plist[FILTER_OUT].name
10344 || filter->dlist[FILTER_OUT].name
10345 || filter->aslist[FILTER_OUT].name
10346 || filter->map[RMAP_OUT].name || filter->usmap.name)
10347 vty_out(vty, " Outbound path policy configured\n");
10348
10349 /* prefix-list */
10350 if (filter->plist[FILTER_IN].name)
10351 vty_out(vty,
10352 " Incoming update prefix filter list is %s%s\n",
10353 filter->plist[FILTER_IN].plist ? "*" : "",
10354 filter->plist[FILTER_IN].name);
10355 if (filter->plist[FILTER_OUT].name)
10356 vty_out(vty,
10357 " Outgoing update prefix filter list is %s%s\n",
10358 filter->plist[FILTER_OUT].plist ? "*" : "",
10359 filter->plist[FILTER_OUT].name);
10360
10361 /* distribute-list */
10362 if (filter->dlist[FILTER_IN].name)
10363 vty_out(vty,
10364 " Incoming update network filter list is %s%s\n",
10365 filter->dlist[FILTER_IN].alist ? "*" : "",
10366 filter->dlist[FILTER_IN].name);
10367 if (filter->dlist[FILTER_OUT].name)
10368 vty_out(vty,
10369 " Outgoing update network filter list is %s%s\n",
10370 filter->dlist[FILTER_OUT].alist ? "*" : "",
10371 filter->dlist[FILTER_OUT].name);
10372
10373 /* filter-list. */
10374 if (filter->aslist[FILTER_IN].name)
10375 vty_out(vty,
10376 " Incoming update AS path filter list is %s%s\n",
10377 filter->aslist[FILTER_IN].aslist ? "*" : "",
10378 filter->aslist[FILTER_IN].name);
10379 if (filter->aslist[FILTER_OUT].name)
10380 vty_out(vty,
10381 " Outgoing update AS path filter list is %s%s\n",
10382 filter->aslist[FILTER_OUT].aslist ? "*" : "",
10383 filter->aslist[FILTER_OUT].name);
10384
10385 /* route-map. */
10386 if (filter->map[RMAP_IN].name)
10387 vty_out(vty,
10388 " Route map for incoming advertisements is %s%s\n",
10389 filter->map[RMAP_IN].map ? "*" : "",
10390 filter->map[RMAP_IN].name);
10391 if (filter->map[RMAP_OUT].name)
10392 vty_out(vty,
10393 " Route map for outgoing advertisements is %s%s\n",
10394 filter->map[RMAP_OUT].map ? "*" : "",
10395 filter->map[RMAP_OUT].name);
10396
9dac9fc8
DA
10397 /* ebgp-requires-policy (inbound) */
10398 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10399 && !bgp_inbound_policy_exists(p, filter))
10400 vty_out(vty,
10401 " Inbound updates discarded due to missing policy\n");
10402
10403 /* ebgp-requires-policy (outbound) */
10404 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
10405 && !bgp_outbound_policy_exists(p, filter))
10406 vty_out(vty,
10407 " Outbound updates discarded due to missing policy\n");
10408
d62a17ae 10409 /* unsuppress-map */
10410 if (filter->usmap.name)
10411 vty_out(vty,
10412 " Route map for selective unsuppress is %s%s\n",
10413 filter->usmap.map ? "*" : "",
10414 filter->usmap.name);
10415
10416 /* Receive prefix count */
a0a87037
DA
10417 vty_out(vty, " %" PRIu32 " accepted prefixes\n",
10418 p->pcount[afi][safi]);
d62a17ae 10419
fde246e8
DA
10420 /* maximum-prefix-out */
10421 if (CHECK_FLAG(p->af_flags[afi][safi],
10422 PEER_FLAG_MAX_PREFIX_OUT))
10423 vty_out(vty,
10424 " Maximum allowed prefixes sent %" PRIu32 "\n",
10425 p->pmax_out[afi][safi]);
10426
d62a17ae 10427 /* Maximum prefix */
10428 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037
DA
10429 vty_out(vty,
10430 " Maximum prefixes allowed %" PRIu32 "%s\n",
d62a17ae 10431 p->pmax[afi][safi],
10432 CHECK_FLAG(p->af_flags[afi][safi],
10433 PEER_FLAG_MAX_PREFIX_WARNING)
10434 ? " (warning-only)"
10435 : "");
10436 vty_out(vty, " Threshold for warning message %d%%",
10437 p->pmax_threshold[afi][safi]);
10438 if (p->pmax_restart[afi][safi])
10439 vty_out(vty, ", restart interval %d min",
10440 p->pmax_restart[afi][safi]);
10441 vty_out(vty, "\n");
10442 }
10443
10444 vty_out(vty, "\n");
10445 }
10446}
10447
9f049418 10448static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 10449 json_object *json)
718e3744 10450{
d62a17ae 10451 struct bgp *bgp;
10452 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
10453 char timebuf[BGP_UPTIME_LEN];
10454 char dn_flag[2];
d62a17ae 10455 afi_t afi;
10456 safi_t safi;
d7c0a89a
QY
10457 uint16_t i;
10458 uint8_t *msg;
d62a17ae 10459 json_object *json_neigh = NULL;
10460 time_t epoch_tbuf;
718e3744 10461
d62a17ae 10462 bgp = p->bgp;
10463
10464 if (use_json)
10465 json_neigh = json_object_new_object();
10466
10467 memset(dn_flag, '\0', sizeof(dn_flag));
10468 if (!p->conf_if && peer_dynamic_neighbor(p))
10469 dn_flag[0] = '*';
10470
10471 if (!use_json) {
10472 if (p->conf_if) /* Configured interface name. */
10473 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
10474 BGP_PEER_SU_UNSPEC(p)
10475 ? "None"
10476 : sockunion2str(&p->su, buf,
10477 SU_ADDRSTRLEN));
10478 else /* Configured IP address. */
10479 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
10480 p->host);
10481 }
10482
10483 if (use_json) {
10484 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
10485 json_object_string_add(json_neigh, "bgpNeighborAddr",
10486 "none");
10487 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
10488 json_object_string_add(
10489 json_neigh, "bgpNeighborAddr",
10490 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
10491
10492 json_object_int_add(json_neigh, "remoteAs", p->as);
10493
10494 if (p->change_local_as)
10495 json_object_int_add(json_neigh, "localAs",
10496 p->change_local_as);
10497 else
10498 json_object_int_add(json_neigh, "localAs", p->local_as);
10499
10500 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
10501 json_object_boolean_true_add(json_neigh,
10502 "localAsNoPrepend");
10503
10504 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
10505 json_object_boolean_true_add(json_neigh,
10506 "localAsReplaceAs");
10507 } else {
10508 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
10509 || (p->as_type == AS_INTERNAL))
10510 vty_out(vty, "remote AS %u, ", p->as);
10511 else
10512 vty_out(vty, "remote AS Unspecified, ");
10513 vty_out(vty, "local AS %u%s%s, ",
10514 p->change_local_as ? p->change_local_as : p->local_as,
10515 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
10516 ? " no-prepend"
10517 : "",
10518 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
10519 ? " replace-as"
10520 : "");
10521 }
faa16034
DS
10522 /* peer type internal or confed-internal */
10523 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 10524 if (use_json) {
10525 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10526 json_object_boolean_true_add(
10527 json_neigh, "nbrConfedInternalLink");
10528 else
10529 json_object_boolean_true_add(json_neigh,
10530 "nbrInternalLink");
10531 } else {
10532 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10533 vty_out(vty, "confed-internal link\n");
10534 else
10535 vty_out(vty, "internal link\n");
10536 }
faa16034
DS
10537 /* peer type external or confed-external */
10538 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 10539 if (use_json) {
10540 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
10541 json_object_boolean_true_add(
10542 json_neigh, "nbrConfedExternalLink");
10543 else
10544 json_object_boolean_true_add(json_neigh,
10545 "nbrExternalLink");
10546 } else {
10547 if (bgp_confederation_peers_check(bgp, p->as))
10548 vty_out(vty, "confed-external link\n");
10549 else
10550 vty_out(vty, "external link\n");
10551 }
faa16034
DS
10552 } else {
10553 if (use_json)
10554 json_object_boolean_true_add(json_neigh,
10555 "nbrUnspecifiedLink");
10556 else
10557 vty_out(vty, "unspecified link\n");
d62a17ae 10558 }
10559
10560 /* Description. */
10561 if (p->desc) {
10562 if (use_json)
10563 json_object_string_add(json_neigh, "nbrDesc", p->desc);
10564 else
10565 vty_out(vty, " Description: %s\n", p->desc);
10566 }
10567
10568 if (p->hostname) {
10569 if (use_json) {
10570 if (p->hostname)
10571 json_object_string_add(json_neigh, "hostname",
10572 p->hostname);
10573
10574 if (p->domainname)
10575 json_object_string_add(json_neigh, "domainname",
10576 p->domainname);
10577 } else {
10578 if (p->domainname && (p->domainname[0] != '\0'))
10579 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
10580 p->domainname);
10581 else
10582 vty_out(vty, "Hostname: %s\n", p->hostname);
10583 }
10584 }
10585
10586 /* Peer-group */
10587 if (p->group) {
10588 if (use_json) {
10589 json_object_string_add(json_neigh, "peerGroup",
10590 p->group->name);
10591
10592 if (dn_flag[0]) {
10593 struct prefix prefix, *range = NULL;
10594
10595 sockunion2hostprefix(&(p->su), &prefix);
10596 range = peer_group_lookup_dynamic_neighbor_range(
10597 p->group, &prefix);
10598
10599 if (range) {
10600 prefix2str(range, buf1, sizeof(buf1));
10601 json_object_string_add(
10602 json_neigh,
10603 "peerSubnetRangeGroup", buf1);
10604 }
10605 }
10606 } else {
10607 vty_out(vty,
10608 " Member of peer-group %s for session parameters\n",
10609 p->group->name);
10610
10611 if (dn_flag[0]) {
10612 struct prefix prefix, *range = NULL;
10613
10614 sockunion2hostprefix(&(p->su), &prefix);
10615 range = peer_group_lookup_dynamic_neighbor_range(
10616 p->group, &prefix);
10617
10618 if (range) {
10619 prefix2str(range, buf1, sizeof(buf1));
10620 vty_out(vty,
10621 " Belongs to the subnet range group: %s\n",
10622 buf1);
10623 }
10624 }
10625 }
10626 }
10627
10628 if (use_json) {
10629 /* Administrative shutdown. */
10630 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10631 json_object_boolean_true_add(json_neigh,
10632 "adminShutDown");
10633
10634 /* BGP Version. */
10635 json_object_int_add(json_neigh, "bgpVersion", 4);
10636 json_object_string_add(
10637 json_neigh, "remoteRouterId",
10638 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
10639 json_object_string_add(
10640 json_neigh, "localRouterId",
10641 inet_ntop(AF_INET, &bgp->router_id, buf1,
10642 sizeof(buf1)));
d62a17ae 10643
10644 /* Confederation */
10645 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10646 && bgp_confederation_peers_check(bgp, p->as))
10647 json_object_boolean_true_add(json_neigh,
10648 "nbrCommonAdmin");
10649
10650 /* Status. */
10651 json_object_string_add(
10652 json_neigh, "bgpState",
10653 lookup_msg(bgp_status_msg, p->status, NULL));
10654
10655 if (p->status == Established) {
10656 time_t uptime;
d62a17ae 10657
10658 uptime = bgp_clock();
10659 uptime -= p->uptime;
d62a17ae 10660 epoch_tbuf = time(NULL) - uptime;
10661
d3c7efed
DS
10662 json_object_int_add(json_neigh, "bgpTimerUpMsec",
10663 uptime * 1000);
d62a17ae 10664 json_object_string_add(json_neigh, "bgpTimerUpString",
10665 peer_uptime(p->uptime, timebuf,
10666 BGP_UPTIME_LEN, 0,
10667 NULL));
10668 json_object_int_add(json_neigh,
10669 "bgpTimerUpEstablishedEpoch",
10670 epoch_tbuf);
10671 }
10672
10673 else if (p->status == Active) {
10674 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10675 json_object_string_add(json_neigh, "bgpStateIs",
10676 "passive");
10677 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10678 json_object_string_add(json_neigh, "bgpStateIs",
10679 "passiveNSF");
10680 }
10681
10682 /* read timer */
10683 time_t uptime;
10684 struct tm *tm;
10685
10686 uptime = bgp_clock();
10687 uptime -= p->readtime;
10688 tm = gmtime(&uptime);
10689 json_object_int_add(json_neigh, "bgpTimerLastRead",
10690 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10691 + (tm->tm_hour * 3600000));
10692
10693 uptime = bgp_clock();
10694 uptime -= p->last_write;
10695 tm = gmtime(&uptime);
10696 json_object_int_add(json_neigh, "bgpTimerLastWrite",
10697 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10698 + (tm->tm_hour * 3600000));
10699
10700 uptime = bgp_clock();
10701 uptime -= p->update_time;
10702 tm = gmtime(&uptime);
10703 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
10704 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
10705 + (tm->tm_hour * 3600000));
10706
10707 /* Configured timer values. */
10708 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
10709 p->v_holdtime * 1000);
10710 json_object_int_add(json_neigh,
10711 "bgpTimerKeepAliveIntervalMsecs",
10712 p->v_keepalive * 1000);
b90a8e13 10713 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10714 json_object_int_add(json_neigh,
10715 "bgpTimerConfiguredHoldTimeMsecs",
10716 p->holdtime * 1000);
10717 json_object_int_add(
10718 json_neigh,
10719 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10720 p->keepalive * 1000);
5d5393b9
DL
10721 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10722 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10723 json_object_int_add(json_neigh,
10724 "bgpTimerConfiguredHoldTimeMsecs",
10725 bgp->default_holdtime);
10726 json_object_int_add(
10727 json_neigh,
10728 "bgpTimerConfiguredKeepAliveIntervalMsecs",
10729 bgp->default_keepalive);
d62a17ae 10730 }
10731 } else {
10732 /* Administrative shutdown. */
10733 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
10734 vty_out(vty, " Administratively shut down\n");
10735
10736 /* BGP Version. */
10737 vty_out(vty, " BGP version 4");
0e38aeb4 10738 vty_out(vty, ", remote router ID %s",
d62a17ae 10739 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
10740 vty_out(vty, ", local router ID %s\n",
10741 inet_ntop(AF_INET, &bgp->router_id, buf1,
10742 sizeof(buf1)));
d62a17ae 10743
10744 /* Confederation */
10745 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
10746 && bgp_confederation_peers_check(bgp, p->as))
10747 vty_out(vty,
10748 " Neighbor under common administration\n");
10749
10750 /* Status. */
10751 vty_out(vty, " BGP state = %s",
10752 lookup_msg(bgp_status_msg, p->status, NULL));
10753
10754 if (p->status == Established)
10755 vty_out(vty, ", up for %8s",
10756 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
10757 0, NULL));
10758
10759 else if (p->status == Active) {
10760 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
10761 vty_out(vty, " (passive)");
10762 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
10763 vty_out(vty, " (NSF passive)");
10764 }
10765 vty_out(vty, "\n");
10766
10767 /* read timer */
10768 vty_out(vty, " Last read %s",
10769 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
10770 NULL));
10771 vty_out(vty, ", Last write %s\n",
10772 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
10773 NULL));
10774
10775 /* Configured timer values. */
10776 vty_out(vty,
10777 " Hold time is %d, keepalive interval is %d seconds\n",
10778 p->v_holdtime, p->v_keepalive);
b90a8e13 10779 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 10780 vty_out(vty, " Configured hold time is %d",
10781 p->holdtime);
10782 vty_out(vty, ", keepalive interval is %d seconds\n",
10783 p->keepalive);
5d5393b9
DL
10784 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
10785 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
10786 vty_out(vty, " Configured hold time is %d",
10787 bgp->default_holdtime);
10788 vty_out(vty, ", keepalive interval is %d seconds\n",
10789 bgp->default_keepalive);
d62a17ae 10790 }
10791 }
10792 /* Capability. */
10793 if (p->status == Established) {
10794 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
10795 || p->afc_recv[AFI_IP][SAFI_UNICAST]
10796 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
10797 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
10798 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
10799 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
10800 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
10801 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
10802 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
10803 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
10804 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
10805 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 10806 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
10807 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 10808 || p->afc_adv[AFI_IP][SAFI_ENCAP]
10809 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 10810 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
10811 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 10812 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
10813 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
10814 if (use_json) {
10815 json_object *json_cap = NULL;
10816
10817 json_cap = json_object_new_object();
10818
10819 /* AS4 */
10820 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10821 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10822 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
10823 && CHECK_FLAG(p->cap,
10824 PEER_CAP_AS4_RCV))
10825 json_object_string_add(
10826 json_cap, "4byteAs",
10827 "advertisedAndReceived");
10828 else if (CHECK_FLAG(p->cap,
10829 PEER_CAP_AS4_ADV))
10830 json_object_string_add(
10831 json_cap, "4byteAs",
10832 "advertised");
10833 else if (CHECK_FLAG(p->cap,
10834 PEER_CAP_AS4_RCV))
10835 json_object_string_add(
10836 json_cap, "4byteAs",
10837 "received");
10838 }
10839
10840 /* AddPath */
10841 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10842 || CHECK_FLAG(p->cap,
10843 PEER_CAP_ADDPATH_ADV)) {
10844 json_object *json_add = NULL;
10845 const char *print_store;
10846
10847 json_add = json_object_new_object();
10848
05c7a1cc
QY
10849 FOREACH_AFI_SAFI (afi, safi) {
10850 json_object *json_sub = NULL;
10851 json_sub =
10852 json_object_new_object();
5cb5f4d0
DD
10853 print_store = get_afi_safi_str(
10854 afi, safi, true);
d62a17ae 10855
05c7a1cc
QY
10856 if (CHECK_FLAG(
10857 p->af_cap[afi]
10858 [safi],
10859 PEER_CAP_ADDPATH_AF_TX_ADV)
10860 || CHECK_FLAG(
10861 p->af_cap[afi]
10862 [safi],
10863 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 10864 if (CHECK_FLAG(
10865 p->af_cap
10866 [afi]
10867 [safi],
10868 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 10869 && CHECK_FLAG(
d62a17ae 10870 p->af_cap
10871 [afi]
10872 [safi],
05c7a1cc
QY
10873 PEER_CAP_ADDPATH_AF_TX_RCV))
10874 json_object_boolean_true_add(
10875 json_sub,
10876 "txAdvertisedAndReceived");
10877 else if (
10878 CHECK_FLAG(
10879 p->af_cap
10880 [afi]
10881 [safi],
10882 PEER_CAP_ADDPATH_AF_TX_ADV))
10883 json_object_boolean_true_add(
10884 json_sub,
10885 "txAdvertised");
10886 else if (
10887 CHECK_FLAG(
10888 p->af_cap
10889 [afi]
10890 [safi],
10891 PEER_CAP_ADDPATH_AF_TX_RCV))
10892 json_object_boolean_true_add(
10893 json_sub,
10894 "txReceived");
10895 }
d62a17ae 10896
05c7a1cc
QY
10897 if (CHECK_FLAG(
10898 p->af_cap[afi]
10899 [safi],
10900 PEER_CAP_ADDPATH_AF_RX_ADV)
10901 || CHECK_FLAG(
10902 p->af_cap[afi]
10903 [safi],
10904 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 10905 if (CHECK_FLAG(
10906 p->af_cap
10907 [afi]
10908 [safi],
10909 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 10910 && CHECK_FLAG(
d62a17ae 10911 p->af_cap
10912 [afi]
10913 [safi],
10914 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
10915 json_object_boolean_true_add(
10916 json_sub,
10917 "rxAdvertisedAndReceived");
10918 else if (
10919 CHECK_FLAG(
10920 p->af_cap
10921 [afi]
10922 [safi],
10923 PEER_CAP_ADDPATH_AF_RX_ADV))
10924 json_object_boolean_true_add(
10925 json_sub,
10926 "rxAdvertised");
10927 else if (
10928 CHECK_FLAG(
10929 p->af_cap
10930 [afi]
10931 [safi],
10932 PEER_CAP_ADDPATH_AF_RX_RCV))
10933 json_object_boolean_true_add(
10934 json_sub,
10935 "rxReceived");
d62a17ae 10936 }
10937
05c7a1cc
QY
10938 if (CHECK_FLAG(
10939 p->af_cap[afi]
10940 [safi],
10941 PEER_CAP_ADDPATH_AF_TX_ADV)
10942 || CHECK_FLAG(
10943 p->af_cap[afi]
10944 [safi],
10945 PEER_CAP_ADDPATH_AF_TX_RCV)
10946 || CHECK_FLAG(
10947 p->af_cap[afi]
10948 [safi],
10949 PEER_CAP_ADDPATH_AF_RX_ADV)
10950 || CHECK_FLAG(
10951 p->af_cap[afi]
10952 [safi],
10953 PEER_CAP_ADDPATH_AF_RX_RCV))
10954 json_object_object_add(
10955 json_add,
10956 print_store,
10957 json_sub);
10958 else
10959 json_object_free(
10960 json_sub);
10961 }
10962
d62a17ae 10963 json_object_object_add(
10964 json_cap, "addPath", json_add);
10965 }
10966
10967 /* Dynamic */
10968 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10969 || CHECK_FLAG(p->cap,
10970 PEER_CAP_DYNAMIC_ADV)) {
10971 if (CHECK_FLAG(p->cap,
10972 PEER_CAP_DYNAMIC_ADV)
10973 && CHECK_FLAG(p->cap,
10974 PEER_CAP_DYNAMIC_RCV))
10975 json_object_string_add(
10976 json_cap, "dynamic",
10977 "advertisedAndReceived");
10978 else if (CHECK_FLAG(
10979 p->cap,
10980 PEER_CAP_DYNAMIC_ADV))
10981 json_object_string_add(
10982 json_cap, "dynamic",
10983 "advertised");
10984 else if (CHECK_FLAG(
10985 p->cap,
10986 PEER_CAP_DYNAMIC_RCV))
10987 json_object_string_add(
10988 json_cap, "dynamic",
10989 "received");
10990 }
10991
10992 /* Extended nexthop */
10993 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10994 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10995 json_object *json_nxt = NULL;
10996 const char *print_store;
10997
10998
10999 if (CHECK_FLAG(p->cap,
11000 PEER_CAP_ENHE_ADV)
11001 && CHECK_FLAG(p->cap,
11002 PEER_CAP_ENHE_RCV))
11003 json_object_string_add(
11004 json_cap,
11005 "extendedNexthop",
11006 "advertisedAndReceived");
11007 else if (CHECK_FLAG(p->cap,
11008 PEER_CAP_ENHE_ADV))
11009 json_object_string_add(
11010 json_cap,
11011 "extendedNexthop",
11012 "advertised");
11013 else if (CHECK_FLAG(p->cap,
11014 PEER_CAP_ENHE_RCV))
11015 json_object_string_add(
11016 json_cap,
11017 "extendedNexthop",
11018 "received");
11019
11020 if (CHECK_FLAG(p->cap,
11021 PEER_CAP_ENHE_RCV)) {
11022 json_nxt =
11023 json_object_new_object();
11024
11025 for (safi = SAFI_UNICAST;
11026 safi < SAFI_MAX; safi++) {
11027 if (CHECK_FLAG(
11028 p->af_cap
11029 [AFI_IP]
11030 [safi],
11031 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11032 print_store = get_afi_safi_str(
d62a17ae 11033 AFI_IP,
5cb5f4d0 11034 safi, true);
d62a17ae 11035 json_object_string_add(
11036 json_nxt,
11037 print_store,
54f29523 11038 "recieved"); /* misspelled for compatibility */
d62a17ae 11039 }
11040 }
11041 json_object_object_add(
11042 json_cap,
11043 "extendedNexthopFamililesByPeer",
11044 json_nxt);
11045 }
11046 }
11047
11048 /* Route Refresh */
11049 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11050 || CHECK_FLAG(p->cap,
11051 PEER_CAP_REFRESH_NEW_RCV)
11052 || CHECK_FLAG(p->cap,
11053 PEER_CAP_REFRESH_OLD_RCV)) {
11054 if (CHECK_FLAG(p->cap,
11055 PEER_CAP_REFRESH_ADV)
11056 && (CHECK_FLAG(
11057 p->cap,
11058 PEER_CAP_REFRESH_NEW_RCV)
11059 || CHECK_FLAG(
11060 p->cap,
11061 PEER_CAP_REFRESH_OLD_RCV))) {
11062 if (CHECK_FLAG(
11063 p->cap,
11064 PEER_CAP_REFRESH_OLD_RCV)
11065 && CHECK_FLAG(
11066 p->cap,
11067 PEER_CAP_REFRESH_NEW_RCV))
11068 json_object_string_add(
11069 json_cap,
11070 "routeRefresh",
11071 "advertisedAndReceivedOldNew");
11072 else {
11073 if (CHECK_FLAG(
11074 p->cap,
11075 PEER_CAP_REFRESH_OLD_RCV))
11076 json_object_string_add(
11077 json_cap,
11078 "routeRefresh",
11079 "advertisedAndReceivedOld");
11080 else
11081 json_object_string_add(
11082 json_cap,
11083 "routeRefresh",
11084 "advertisedAndReceivedNew");
11085 }
11086 } else if (
11087 CHECK_FLAG(
11088 p->cap,
11089 PEER_CAP_REFRESH_ADV))
11090 json_object_string_add(
11091 json_cap,
11092 "routeRefresh",
11093 "advertised");
11094 else if (
11095 CHECK_FLAG(
11096 p->cap,
11097 PEER_CAP_REFRESH_NEW_RCV)
11098 || CHECK_FLAG(
11099 p->cap,
11100 PEER_CAP_REFRESH_OLD_RCV))
11101 json_object_string_add(
11102 json_cap,
11103 "routeRefresh",
11104 "received");
11105 }
11106
11107 /* Multiprotocol Extensions */
11108 json_object *json_multi = NULL;
11109 json_multi = json_object_new_object();
11110
05c7a1cc
QY
11111 FOREACH_AFI_SAFI (afi, safi) {
11112 if (p->afc_adv[afi][safi]
11113 || p->afc_recv[afi][safi]) {
11114 json_object *json_exten = NULL;
11115 json_exten =
11116 json_object_new_object();
11117
d62a17ae 11118 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11119 && p->afc_recv[afi][safi])
11120 json_object_boolean_true_add(
11121 json_exten,
11122 "advertisedAndReceived");
11123 else if (p->afc_adv[afi][safi])
11124 json_object_boolean_true_add(
11125 json_exten,
11126 "advertised");
11127 else if (p->afc_recv[afi][safi])
11128 json_object_boolean_true_add(
11129 json_exten,
11130 "received");
d62a17ae 11131
05c7a1cc
QY
11132 json_object_object_add(
11133 json_multi,
5cb5f4d0
DD
11134 get_afi_safi_str(afi,
11135 safi,
11136 true),
05c7a1cc 11137 json_exten);
d62a17ae 11138 }
11139 }
11140 json_object_object_add(
11141 json_cap, "multiprotocolExtensions",
11142 json_multi);
11143
d77114b7 11144 /* Hostname capabilities */
60466a63 11145 json_object *json_hname = NULL;
d77114b7
MK
11146
11147 json_hname = json_object_new_object();
11148
11149 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
11150 json_object_string_add(
60466a63
QY
11151 json_hname, "advHostName",
11152 bgp->peer_self->hostname
11153 ? bgp->peer_self
11154 ->hostname
d77114b7
MK
11155 : "n/a");
11156 json_object_string_add(
60466a63
QY
11157 json_hname, "advDomainName",
11158 bgp->peer_self->domainname
11159 ? bgp->peer_self
11160 ->domainname
d77114b7
MK
11161 : "n/a");
11162 }
11163
11164
11165 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
11166 json_object_string_add(
60466a63
QY
11167 json_hname, "rcvHostName",
11168 p->hostname ? p->hostname
11169 : "n/a");
d77114b7 11170 json_object_string_add(
60466a63
QY
11171 json_hname, "rcvDomainName",
11172 p->domainname ? p->domainname
11173 : "n/a");
d77114b7
MK
11174 }
11175
60466a63 11176 json_object_object_add(json_cap, "hostName",
d77114b7
MK
11177 json_hname);
11178
d62a17ae 11179 /* Gracefull Restart */
11180 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11181 || CHECK_FLAG(p->cap,
11182 PEER_CAP_RESTART_ADV)) {
11183 if (CHECK_FLAG(p->cap,
11184 PEER_CAP_RESTART_ADV)
11185 && CHECK_FLAG(p->cap,
11186 PEER_CAP_RESTART_RCV))
11187 json_object_string_add(
11188 json_cap,
11189 "gracefulRestart",
11190 "advertisedAndReceived");
11191 else if (CHECK_FLAG(
11192 p->cap,
11193 PEER_CAP_RESTART_ADV))
11194 json_object_string_add(
11195 json_cap,
11196 "gracefulRestartCapability",
11197 "advertised");
11198 else if (CHECK_FLAG(
11199 p->cap,
11200 PEER_CAP_RESTART_RCV))
11201 json_object_string_add(
11202 json_cap,
11203 "gracefulRestartCapability",
11204 "received");
11205
11206 if (CHECK_FLAG(p->cap,
11207 PEER_CAP_RESTART_RCV)) {
11208 int restart_af_count = 0;
11209 json_object *json_restart =
11210 NULL;
11211 json_restart =
11212 json_object_new_object();
11213
11214 json_object_int_add(
11215 json_cap,
11216 "gracefulRestartRemoteTimerMsecs",
11217 p->v_gr_restart * 1000);
11218
05c7a1cc
QY
11219 FOREACH_AFI_SAFI (afi, safi) {
11220 if (CHECK_FLAG(
11221 p->af_cap
11222 [afi]
11223 [safi],
11224 PEER_CAP_RESTART_AF_RCV)) {
11225 json_object *
11226 json_sub =
11227 NULL;
11228 json_sub =
11229 json_object_new_object();
11230
d62a17ae 11231 if (CHECK_FLAG(
11232 p->af_cap
11233 [afi]
11234 [safi],
05c7a1cc
QY
11235 PEER_CAP_RESTART_AF_PRESERVE_RCV))
11236 json_object_boolean_true_add(
11237 json_sub,
11238 "preserved");
11239 restart_af_count++;
11240 json_object_object_add(
11241 json_restart,
5cb5f4d0 11242 get_afi_safi_str(
05c7a1cc 11243 afi,
5cb5f4d0
DD
11244 safi,
11245 true),
05c7a1cc 11246 json_sub);
d62a17ae 11247 }
11248 }
11249 if (!restart_af_count) {
11250 json_object_string_add(
11251 json_cap,
11252 "addressFamiliesByPeer",
11253 "none");
11254 json_object_free(
11255 json_restart);
11256 } else
11257 json_object_object_add(
11258 json_cap,
11259 "addressFamiliesByPeer",
11260 json_restart);
11261 }
11262 }
11263 json_object_object_add(json_neigh,
11264 "neighborCapabilities",
11265 json_cap);
11266 } else {
11267 vty_out(vty, " Neighbor capabilities:\n");
11268
11269 /* AS4 */
11270 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11271 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11272 vty_out(vty, " 4 Byte AS:");
11273 if (CHECK_FLAG(p->cap,
11274 PEER_CAP_AS4_ADV))
11275 vty_out(vty, " advertised");
11276 if (CHECK_FLAG(p->cap,
11277 PEER_CAP_AS4_RCV))
11278 vty_out(vty, " %sreceived",
11279 CHECK_FLAG(
11280 p->cap,
11281 PEER_CAP_AS4_ADV)
11282 ? "and "
11283 : "");
11284 vty_out(vty, "\n");
11285 }
11286
11287 /* AddPath */
11288 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11289 || CHECK_FLAG(p->cap,
11290 PEER_CAP_ADDPATH_ADV)) {
11291 vty_out(vty, " AddPath:\n");
11292
05c7a1cc
QY
11293 FOREACH_AFI_SAFI (afi, safi) {
11294 if (CHECK_FLAG(
11295 p->af_cap[afi]
11296 [safi],
11297 PEER_CAP_ADDPATH_AF_TX_ADV)
11298 || CHECK_FLAG(
11299 p->af_cap[afi]
11300 [safi],
11301 PEER_CAP_ADDPATH_AF_TX_RCV)) {
11302 vty_out(vty,
11303 " %s: TX ",
5cb5f4d0 11304 get_afi_safi_str(
05c7a1cc 11305 afi,
5cb5f4d0
DD
11306 safi,
11307 false));
05c7a1cc 11308
d62a17ae 11309 if (CHECK_FLAG(
11310 p->af_cap
11311 [afi]
11312 [safi],
05c7a1cc 11313 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 11314 vty_out(vty,
05c7a1cc 11315 "advertised %s",
5cb5f4d0 11316 get_afi_safi_str(
d62a17ae 11317 afi,
5cb5f4d0
DD
11318 safi,
11319 false));
d62a17ae 11320
05c7a1cc
QY
11321 if (CHECK_FLAG(
11322 p->af_cap
11323 [afi]
11324 [safi],
11325 PEER_CAP_ADDPATH_AF_TX_RCV))
11326 vty_out(vty,
11327 "%sreceived",
11328 CHECK_FLAG(
11329 p->af_cap
11330 [afi]
11331 [safi],
11332 PEER_CAP_ADDPATH_AF_TX_ADV)
11333 ? " and "
11334 : "");
d62a17ae 11335
05c7a1cc
QY
11336 vty_out(vty, "\n");
11337 }
d62a17ae 11338
05c7a1cc
QY
11339 if (CHECK_FLAG(
11340 p->af_cap[afi]
11341 [safi],
11342 PEER_CAP_ADDPATH_AF_RX_ADV)
11343 || CHECK_FLAG(
11344 p->af_cap[afi]
11345 [safi],
11346 PEER_CAP_ADDPATH_AF_RX_RCV)) {
11347 vty_out(vty,
11348 " %s: RX ",
5cb5f4d0 11349 get_afi_safi_str(
05c7a1cc 11350 afi,
5cb5f4d0
DD
11351 safi,
11352 false));
d62a17ae 11353
11354 if (CHECK_FLAG(
11355 p->af_cap
11356 [afi]
11357 [safi],
05c7a1cc 11358 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 11359 vty_out(vty,
05c7a1cc 11360 "advertised %s",
5cb5f4d0 11361 get_afi_safi_str(
d62a17ae 11362 afi,
5cb5f4d0
DD
11363 safi,
11364 false));
d62a17ae 11365
05c7a1cc
QY
11366 if (CHECK_FLAG(
11367 p->af_cap
11368 [afi]
11369 [safi],
11370 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 11371 vty_out(vty,
05c7a1cc
QY
11372 "%sreceived",
11373 CHECK_FLAG(
11374 p->af_cap
11375 [afi]
11376 [safi],
11377 PEER_CAP_ADDPATH_AF_RX_ADV)
11378 ? " and "
11379 : "");
11380
11381 vty_out(vty, "\n");
d62a17ae 11382 }
05c7a1cc 11383 }
d62a17ae 11384 }
11385
11386 /* Dynamic */
11387 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11388 || CHECK_FLAG(p->cap,
11389 PEER_CAP_DYNAMIC_ADV)) {
11390 vty_out(vty, " Dynamic:");
11391 if (CHECK_FLAG(p->cap,
11392 PEER_CAP_DYNAMIC_ADV))
11393 vty_out(vty, " advertised");
11394 if (CHECK_FLAG(p->cap,
11395 PEER_CAP_DYNAMIC_RCV))
11396 vty_out(vty, " %sreceived",
11397 CHECK_FLAG(
11398 p->cap,
11399 PEER_CAP_DYNAMIC_ADV)
11400 ? "and "
11401 : "");
11402 vty_out(vty, "\n");
11403 }
11404
11405 /* Extended nexthop */
11406 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11407 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11408 vty_out(vty, " Extended nexthop:");
11409 if (CHECK_FLAG(p->cap,
11410 PEER_CAP_ENHE_ADV))
11411 vty_out(vty, " advertised");
11412 if (CHECK_FLAG(p->cap,
11413 PEER_CAP_ENHE_RCV))
11414 vty_out(vty, " %sreceived",
11415 CHECK_FLAG(
11416 p->cap,
11417 PEER_CAP_ENHE_ADV)
11418 ? "and "
11419 : "");
11420 vty_out(vty, "\n");
11421
11422 if (CHECK_FLAG(p->cap,
11423 PEER_CAP_ENHE_RCV)) {
11424 vty_out(vty,
11425 " Address families by peer:\n ");
11426 for (safi = SAFI_UNICAST;
11427 safi < SAFI_MAX; safi++)
11428 if (CHECK_FLAG(
11429 p->af_cap
11430 [AFI_IP]
11431 [safi],
11432 PEER_CAP_ENHE_AF_RCV))
11433 vty_out(vty,
11434 " %s\n",
5cb5f4d0 11435 get_afi_safi_str(
d62a17ae 11436 AFI_IP,
5cb5f4d0
DD
11437 safi,
11438 false));
d62a17ae 11439 }
11440 }
11441
11442 /* Route Refresh */
11443 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11444 || CHECK_FLAG(p->cap,
11445 PEER_CAP_REFRESH_NEW_RCV)
11446 || CHECK_FLAG(p->cap,
11447 PEER_CAP_REFRESH_OLD_RCV)) {
11448 vty_out(vty, " Route refresh:");
11449 if (CHECK_FLAG(p->cap,
11450 PEER_CAP_REFRESH_ADV))
11451 vty_out(vty, " advertised");
11452 if (CHECK_FLAG(p->cap,
11453 PEER_CAP_REFRESH_NEW_RCV)
11454 || CHECK_FLAG(
11455 p->cap,
11456 PEER_CAP_REFRESH_OLD_RCV))
11457 vty_out(vty, " %sreceived(%s)",
11458 CHECK_FLAG(
11459 p->cap,
11460 PEER_CAP_REFRESH_ADV)
11461 ? "and "
11462 : "",
11463 (CHECK_FLAG(
11464 p->cap,
11465 PEER_CAP_REFRESH_OLD_RCV)
11466 && CHECK_FLAG(
11467 p->cap,
11468 PEER_CAP_REFRESH_NEW_RCV))
11469 ? "old & new"
11470 : CHECK_FLAG(
11471 p->cap,
11472 PEER_CAP_REFRESH_OLD_RCV)
11473 ? "old"
11474 : "new");
11475
11476 vty_out(vty, "\n");
11477 }
11478
11479 /* Multiprotocol Extensions */
05c7a1cc
QY
11480 FOREACH_AFI_SAFI (afi, safi)
11481 if (p->afc_adv[afi][safi]
11482 || p->afc_recv[afi][safi]) {
11483 vty_out(vty,
11484 " Address Family %s:",
5cb5f4d0
DD
11485 get_afi_safi_str(
11486 afi,
11487 safi,
11488 false));
05c7a1cc 11489 if (p->afc_adv[afi][safi])
d62a17ae 11490 vty_out(vty,
05c7a1cc
QY
11491 " advertised");
11492 if (p->afc_recv[afi][safi])
11493 vty_out(vty,
11494 " %sreceived",
11495 p->afc_adv[afi]
11496 [safi]
11497 ? "and "
11498 : "");
11499 vty_out(vty, "\n");
11500 }
d62a17ae 11501
11502 /* Hostname capability */
60466a63 11503 vty_out(vty, " Hostname Capability:");
d77114b7
MK
11504
11505 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
11506 vty_out(vty,
11507 " advertised (name: %s,domain name: %s)",
60466a63
QY
11508 bgp->peer_self->hostname
11509 ? bgp->peer_self
11510 ->hostname
d77114b7 11511 : "n/a",
60466a63
QY
11512 bgp->peer_self->domainname
11513 ? bgp->peer_self
11514 ->domainname
d77114b7
MK
11515 : "n/a");
11516 } else {
11517 vty_out(vty, " not advertised");
d62a17ae 11518 }
11519
d77114b7 11520 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
11521 vty_out(vty,
11522 " received (name: %s,domain name: %s)",
60466a63
QY
11523 p->hostname ? p->hostname
11524 : "n/a",
11525 p->domainname ? p->domainname
11526 : "n/a");
d77114b7
MK
11527 } else {
11528 vty_out(vty, " not received");
11529 }
11530
11531 vty_out(vty, "\n");
11532
d62a17ae 11533 /* Gracefull Restart */
11534 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
11535 || CHECK_FLAG(p->cap,
11536 PEER_CAP_RESTART_ADV)) {
11537 vty_out(vty,
11538 " Graceful Restart Capabilty:");
11539 if (CHECK_FLAG(p->cap,
11540 PEER_CAP_RESTART_ADV))
11541 vty_out(vty, " advertised");
11542 if (CHECK_FLAG(p->cap,
11543 PEER_CAP_RESTART_RCV))
11544 vty_out(vty, " %sreceived",
11545 CHECK_FLAG(
11546 p->cap,
11547 PEER_CAP_RESTART_ADV)
11548 ? "and "
11549 : "");
11550 vty_out(vty, "\n");
11551
11552 if (CHECK_FLAG(p->cap,
11553 PEER_CAP_RESTART_RCV)) {
11554 int restart_af_count = 0;
11555
11556 vty_out(vty,
11557 " Remote Restart timer is %d seconds\n",
11558 p->v_gr_restart);
11559 vty_out(vty,
11560 " Address families by peer:\n ");
11561
05c7a1cc
QY
11562 FOREACH_AFI_SAFI (afi, safi)
11563 if (CHECK_FLAG(
11564 p->af_cap
11565 [afi]
11566 [safi],
11567 PEER_CAP_RESTART_AF_RCV)) {
11568 vty_out(vty,
11569 "%s%s(%s)",
11570 restart_af_count
11571 ? ", "
11572 : "",
5cb5f4d0 11573 get_afi_safi_str(
05c7a1cc 11574 afi,
5cb5f4d0
DD
11575 safi,
11576 false),
05c7a1cc
QY
11577 CHECK_FLAG(
11578 p->af_cap
11579 [afi]
11580 [safi],
11581 PEER_CAP_RESTART_AF_PRESERVE_RCV)
11582 ? "preserved"
11583 : "not preserved");
11584 restart_af_count++;
11585 }
d62a17ae 11586 if (!restart_af_count)
11587 vty_out(vty, "none");
11588 vty_out(vty, "\n");
11589 }
2986cac2 11590 } /* Gracefull Restart */
d62a17ae 11591 }
11592 }
11593 }
11594
11595 /* graceful restart information */
d62a17ae 11596 json_object *json_grace = NULL;
11597 json_object *json_grace_send = NULL;
11598 json_object *json_grace_recv = NULL;
11599 int eor_send_af_count = 0;
11600 int eor_receive_af_count = 0;
11601
11602 if (use_json) {
11603 json_grace = json_object_new_object();
11604 json_grace_send = json_object_new_object();
11605 json_grace_recv = json_object_new_object();
11606
36235319
QY
11607 if ((p->status == Established)
11608 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
11609 FOREACH_AFI_SAFI (afi, safi) {
11610 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 11611 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
11612 json_object_boolean_true_add(
11613 json_grace_send,
5cb5f4d0
DD
11614 get_afi_safi_str(afi,
11615 safi,
11616 true));
05c7a1cc 11617 eor_send_af_count++;
d62a17ae 11618 }
11619 }
05c7a1cc
QY
11620 FOREACH_AFI_SAFI (afi, safi) {
11621 if (CHECK_FLAG(
36235319
QY
11622 p->af_sflags[afi][safi],
11623 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
11624 json_object_boolean_true_add(
11625 json_grace_recv,
5cb5f4d0
DD
11626 get_afi_safi_str(afi,
11627 safi,
11628 true));
05c7a1cc 11629 eor_receive_af_count++;
d62a17ae 11630 }
11631 }
11632 }
36235319
QY
11633 json_object_object_add(json_grace, "endOfRibSend",
11634 json_grace_send);
11635 json_object_object_add(json_grace, "endOfRibRecv",
11636 json_grace_recv);
d62a17ae 11637
d62a17ae 11638
11639 if (p->t_gr_restart)
11640 json_object_int_add(json_grace,
11641 "gracefulRestartTimerMsecs",
11642 thread_timer_remain_second(
11643 p->t_gr_restart)
11644 * 1000);
11645
11646 if (p->t_gr_stale)
11647 json_object_int_add(
11648 json_grace,
11649 "gracefulStalepathTimerMsecs",
11650 thread_timer_remain_second(
11651 p->t_gr_stale)
11652 * 1000);
2986cac2 11653 /* more gr info in new format */
11654 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 11655 json_grace);
d62a17ae 11656 json_object_object_add(
11657 json_neigh, "gracefulRestartInfo", json_grace);
11658 } else {
2986cac2 11659 vty_out(vty, " Graceful restart informations:\n");
36235319
QY
11660 if ((p->status == Established)
11661 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11662
d62a17ae 11663 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
11664 FOREACH_AFI_SAFI (afi, safi) {
11665 if (CHECK_FLAG(p->af_sflags[afi][safi],
11666 PEER_STATUS_EOR_SEND)) {
11667 vty_out(vty, "%s%s",
11668 eor_send_af_count ? ", "
11669 : "",
36235319
QY
11670 get_afi_safi_str(
11671 afi, safi,
11672 false));
05c7a1cc 11673 eor_send_af_count++;
d62a17ae 11674 }
11675 }
11676 vty_out(vty, "\n");
11677 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
11678 FOREACH_AFI_SAFI (afi, safi) {
11679 if (CHECK_FLAG(
11680 p->af_sflags[afi][safi],
11681 PEER_STATUS_EOR_RECEIVED)) {
11682 vty_out(vty, "%s%s",
11683 eor_receive_af_count
11684 ? ", "
11685 : "",
5cb5f4d0
DD
11686 get_afi_safi_str(afi,
11687 safi,
11688 false));
05c7a1cc 11689 eor_receive_af_count++;
d62a17ae 11690 }
11691 }
11692 vty_out(vty, "\n");
11693 }
11694
11695 if (p->t_gr_restart)
11696 vty_out(vty,
11697 " The remaining time of restart timer is %ld\n",
11698 thread_timer_remain_second(
11699 p->t_gr_restart));
11700
11701 if (p->t_gr_stale)
11702 vty_out(vty,
11703 " The remaining time of stalepath timer is %ld\n",
11704 thread_timer_remain_second(
11705 p->t_gr_stale));
2986cac2 11706
11707 /* more gr info in new format */
11708 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 11709 }
2986cac2 11710
d62a17ae 11711 if (use_json) {
11712 json_object *json_stat = NULL;
11713 json_stat = json_object_new_object();
11714 /* Packet counts. */
11715 json_object_int_add(json_stat, "depthInq", 0);
11716 json_object_int_add(json_stat, "depthOutq",
11717 (unsigned long)p->obuf->count);
0112e9e0
QY
11718 json_object_int_add(json_stat, "opensSent",
11719 atomic_load_explicit(&p->open_out,
11720 memory_order_relaxed));
11721 json_object_int_add(json_stat, "opensRecv",
11722 atomic_load_explicit(&p->open_in,
11723 memory_order_relaxed));
d62a17ae 11724 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
11725 atomic_load_explicit(&p->notify_out,
11726 memory_order_relaxed));
d62a17ae 11727 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
11728 atomic_load_explicit(&p->notify_in,
11729 memory_order_relaxed));
11730 json_object_int_add(json_stat, "updatesSent",
11731 atomic_load_explicit(&p->update_out,
11732 memory_order_relaxed));
11733 json_object_int_add(json_stat, "updatesRecv",
11734 atomic_load_explicit(&p->update_in,
11735 memory_order_relaxed));
d62a17ae 11736 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
11737 atomic_load_explicit(&p->keepalive_out,
11738 memory_order_relaxed));
d62a17ae 11739 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
11740 atomic_load_explicit(&p->keepalive_in,
11741 memory_order_relaxed));
d62a17ae 11742 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
11743 atomic_load_explicit(&p->refresh_out,
11744 memory_order_relaxed));
d62a17ae 11745 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
11746 atomic_load_explicit(&p->refresh_in,
11747 memory_order_relaxed));
d62a17ae 11748 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
11749 atomic_load_explicit(&p->dynamic_cap_out,
11750 memory_order_relaxed));
d62a17ae 11751 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
11752 atomic_load_explicit(&p->dynamic_cap_in,
11753 memory_order_relaxed));
11754 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
11755 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 11756 json_object_object_add(json_neigh, "messageStats", json_stat);
11757 } else {
11758 /* Packet counts. */
11759 vty_out(vty, " Message statistics:\n");
11760 vty_out(vty, " Inq depth is 0\n");
11761 vty_out(vty, " Outq depth is %lu\n",
11762 (unsigned long)p->obuf->count);
11763 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
11764 vty_out(vty, " Opens: %10d %10d\n",
11765 atomic_load_explicit(&p->open_out,
11766 memory_order_relaxed),
11767 atomic_load_explicit(&p->open_in,
11768 memory_order_relaxed));
11769 vty_out(vty, " Notifications: %10d %10d\n",
11770 atomic_load_explicit(&p->notify_out,
11771 memory_order_relaxed),
11772 atomic_load_explicit(&p->notify_in,
11773 memory_order_relaxed));
11774 vty_out(vty, " Updates: %10d %10d\n",
11775 atomic_load_explicit(&p->update_out,
11776 memory_order_relaxed),
11777 atomic_load_explicit(&p->update_in,
11778 memory_order_relaxed));
11779 vty_out(vty, " Keepalives: %10d %10d\n",
11780 atomic_load_explicit(&p->keepalive_out,
11781 memory_order_relaxed),
11782 atomic_load_explicit(&p->keepalive_in,
11783 memory_order_relaxed));
11784 vty_out(vty, " Route Refresh: %10d %10d\n",
11785 atomic_load_explicit(&p->refresh_out,
11786 memory_order_relaxed),
11787 atomic_load_explicit(&p->refresh_in,
11788 memory_order_relaxed));
d62a17ae 11789 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
11790 atomic_load_explicit(&p->dynamic_cap_out,
11791 memory_order_relaxed),
11792 atomic_load_explicit(&p->dynamic_cap_in,
11793 memory_order_relaxed));
11794 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
11795 PEER_TOTAL_RX(p));
d62a17ae 11796 }
11797
11798 if (use_json) {
11799 /* advertisement-interval */
11800 json_object_int_add(json_neigh,
11801 "minBtwnAdvertisementRunsTimerMsecs",
11802 p->v_routeadv * 1000);
11803
11804 /* Update-source. */
11805 if (p->update_if || p->update_source) {
11806 if (p->update_if)
11807 json_object_string_add(json_neigh,
11808 "updateSource",
11809 p->update_if);
11810 else if (p->update_source)
11811 json_object_string_add(
11812 json_neigh, "updateSource",
11813 sockunion2str(p->update_source, buf1,
11814 SU_ADDRSTRLEN));
11815 }
11816 } else {
11817 /* advertisement-interval */
11818 vty_out(vty,
11819 " Minimum time between advertisement runs is %d seconds\n",
11820 p->v_routeadv);
11821
11822 /* Update-source. */
11823 if (p->update_if || p->update_source) {
11824 vty_out(vty, " Update source is ");
11825 if (p->update_if)
11826 vty_out(vty, "%s", p->update_if);
11827 else if (p->update_source)
11828 vty_out(vty, "%s",
11829 sockunion2str(p->update_source, buf1,
11830 SU_ADDRSTRLEN));
11831 vty_out(vty, "\n");
11832 }
11833
11834 vty_out(vty, "\n");
11835 }
11836
11837 /* Address Family Information */
11838 json_object *json_hold = NULL;
11839
11840 if (use_json)
11841 json_hold = json_object_new_object();
11842
05c7a1cc
QY
11843 FOREACH_AFI_SAFI (afi, safi)
11844 if (p->afc[afi][safi])
11845 bgp_show_peer_afi(vty, p, afi, safi, use_json,
11846 json_hold);
d62a17ae 11847
11848 if (use_json) {
11849 json_object_object_add(json_neigh, "addressFamilyInfo",
11850 json_hold);
11851 json_object_int_add(json_neigh, "connectionsEstablished",
11852 p->established);
11853 json_object_int_add(json_neigh, "connectionsDropped",
11854 p->dropped);
11855 } else
11856 vty_out(vty, " Connections established %d; dropped %d\n",
11857 p->established, p->dropped);
11858
11859 if (!p->last_reset) {
11860 if (use_json)
11861 json_object_string_add(json_neigh, "lastReset",
11862 "never");
11863 else
11864 vty_out(vty, " Last reset never\n");
11865 } else {
11866 if (use_json) {
11867 time_t uptime;
11868 struct tm *tm;
11869
11870 uptime = bgp_clock();
11871 uptime -= p->resettime;
11872 tm = gmtime(&uptime);
11873 json_object_int_add(json_neigh, "lastResetTimerMsecs",
11874 (tm->tm_sec * 1000)
11875 + (tm->tm_min * 60000)
11876 + (tm->tm_hour * 3600000));
3577f1c5 11877 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 11878 } else {
11879 vty_out(vty, " Last reset %s, ",
11880 peer_uptime(p->resettime, timebuf,
11881 BGP_UPTIME_LEN, 0, NULL));
11882
3577f1c5 11883 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 11884 if (p->last_reset_cause_size) {
11885 msg = p->last_reset_cause;
11886 vty_out(vty,
11887 " Message received that caused BGP to send a NOTIFICATION:\n ");
11888 for (i = 1; i <= p->last_reset_cause_size;
11889 i++) {
11890 vty_out(vty, "%02X", *msg++);
11891
11892 if (i != p->last_reset_cause_size) {
11893 if (i % 16 == 0) {
11894 vty_out(vty, "\n ");
11895 } else if (i % 4 == 0) {
11896 vty_out(vty, " ");
11897 }
11898 }
11899 }
11900 vty_out(vty, "\n");
11901 }
11902 }
11903 }
11904
11905 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
11906 if (use_json)
11907 json_object_boolean_true_add(json_neigh,
11908 "prefixesConfigExceedMax");
11909 else
11910 vty_out(vty,
11911 " Peer had exceeded the max. no. of prefixes configured.\n");
11912
11913 if (p->t_pmax_restart) {
11914 if (use_json) {
11915 json_object_boolean_true_add(
11916 json_neigh, "reducePrefixNumFrom");
11917 json_object_int_add(json_neigh,
11918 "restartInTimerMsec",
11919 thread_timer_remain_second(
11920 p->t_pmax_restart)
11921 * 1000);
11922 } else
11923 vty_out(vty,
11924 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
11925 p->host, thread_timer_remain_second(
11926 p->t_pmax_restart));
d62a17ae 11927 } else {
11928 if (use_json)
11929 json_object_boolean_true_add(
11930 json_neigh,
11931 "reducePrefixNumAndClearIpBgp");
11932 else
11933 vty_out(vty,
11934 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
11935 p->host);
11936 }
11937 }
11938
11939 /* EBGP Multihop and GTSM */
11940 if (p->sort != BGP_PEER_IBGP) {
11941 if (use_json) {
11942 if (p->gtsm_hops > 0)
11943 json_object_int_add(json_neigh,
11944 "externalBgpNbrMaxHopsAway",
11945 p->gtsm_hops);
c8d6f0d6 11946 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11947 json_object_int_add(json_neigh,
11948 "externalBgpNbrMaxHopsAway",
11949 p->ttl);
11950 } else {
11951 if (p->gtsm_hops > 0)
11952 vty_out(vty,
11953 " External BGP neighbor may be up to %d hops away.\n",
11954 p->gtsm_hops);
c8d6f0d6 11955 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 11956 vty_out(vty,
11957 " External BGP neighbor may be up to %d hops away.\n",
11958 p->ttl);
11959 }
11960 } else {
11961 if (p->gtsm_hops > 0) {
11962 if (use_json)
11963 json_object_int_add(json_neigh,
11964 "internalBgpNbrMaxHopsAway",
11965 p->gtsm_hops);
11966 else
11967 vty_out(vty,
11968 " Internal BGP neighbor may be up to %d hops away.\n",
11969 p->gtsm_hops);
11970 }
11971 }
11972
11973 /* Local address. */
11974 if (p->su_local) {
11975 if (use_json) {
11976 json_object_string_add(json_neigh, "hostLocal",
11977 sockunion2str(p->su_local, buf1,
11978 SU_ADDRSTRLEN));
11979 json_object_int_add(json_neigh, "portLocal",
11980 ntohs(p->su_local->sin.sin_port));
11981 } else
11982 vty_out(vty, "Local host: %s, Local port: %d\n",
11983 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
11984 ntohs(p->su_local->sin.sin_port));
11985 }
11986
11987 /* Remote address. */
11988 if (p->su_remote) {
11989 if (use_json) {
11990 json_object_string_add(json_neigh, "hostForeign",
11991 sockunion2str(p->su_remote, buf1,
11992 SU_ADDRSTRLEN));
11993 json_object_int_add(json_neigh, "portForeign",
11994 ntohs(p->su_remote->sin.sin_port));
11995 } else
11996 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
11997 sockunion2str(p->su_remote, buf1,
11998 SU_ADDRSTRLEN),
11999 ntohs(p->su_remote->sin.sin_port));
12000 }
12001
12002 /* Nexthop display. */
12003 if (p->su_local) {
12004 if (use_json) {
12005 json_object_string_add(json_neigh, "nexthop",
12006 inet_ntop(AF_INET,
12007 &p->nexthop.v4, buf1,
12008 sizeof(buf1)));
12009 json_object_string_add(json_neigh, "nexthopGlobal",
12010 inet_ntop(AF_INET6,
12011 &p->nexthop.v6_global,
12012 buf1, sizeof(buf1)));
12013 json_object_string_add(json_neigh, "nexthopLocal",
12014 inet_ntop(AF_INET6,
12015 &p->nexthop.v6_local,
12016 buf1, sizeof(buf1)));
12017 if (p->shared_network)
12018 json_object_string_add(json_neigh,
12019 "bgpConnection",
12020 "sharedNetwork");
12021 else
12022 json_object_string_add(json_neigh,
12023 "bgpConnection",
12024 "nonSharedNetwork");
12025 } else {
12026 vty_out(vty, "Nexthop: %s\n",
12027 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12028 sizeof(buf1)));
12029 vty_out(vty, "Nexthop global: %s\n",
12030 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12031 sizeof(buf1)));
12032 vty_out(vty, "Nexthop local: %s\n",
12033 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12034 sizeof(buf1)));
12035 vty_out(vty, "BGP connection: %s\n",
12036 p->shared_network ? "shared network"
12037 : "non shared network");
12038 }
12039 }
12040
12041 /* Timer information. */
12042 if (use_json) {
12043 json_object_int_add(json_neigh, "connectRetryTimer",
12044 p->v_connect);
12045 if (p->status == Established && p->rtt)
12046 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12047 p->rtt);
12048 if (p->t_start)
12049 json_object_int_add(
12050 json_neigh, "nextStartTimerDueInMsecs",
12051 thread_timer_remain_second(p->t_start) * 1000);
12052 if (p->t_connect)
12053 json_object_int_add(
12054 json_neigh, "nextConnectTimerDueInMsecs",
12055 thread_timer_remain_second(p->t_connect)
12056 * 1000);
12057 if (p->t_routeadv) {
12058 json_object_int_add(json_neigh, "mraiInterval",
12059 p->v_routeadv);
12060 json_object_int_add(
12061 json_neigh, "mraiTimerExpireInMsecs",
12062 thread_timer_remain_second(p->t_routeadv)
12063 * 1000);
12064 }
12065 if (p->password)
12066 json_object_int_add(json_neigh, "authenticationEnabled",
12067 1);
12068
12069 if (p->t_read)
12070 json_object_string_add(json_neigh, "readThread", "on");
12071 else
12072 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12073
12074 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12075 json_object_string_add(json_neigh, "writeThread", "on");
12076 else
12077 json_object_string_add(json_neigh, "writeThread",
12078 "off");
12079 } else {
12080 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12081 p->v_connect);
12082 if (p->status == Established && p->rtt)
12083 vty_out(vty, "Estimated round trip time: %d ms\n",
12084 p->rtt);
12085 if (p->t_start)
12086 vty_out(vty, "Next start timer due in %ld seconds\n",
12087 thread_timer_remain_second(p->t_start));
12088 if (p->t_connect)
12089 vty_out(vty, "Next connect timer due in %ld seconds\n",
12090 thread_timer_remain_second(p->t_connect));
12091 if (p->t_routeadv)
12092 vty_out(vty,
12093 "MRAI (interval %u) timer expires in %ld seconds\n",
12094 p->v_routeadv,
12095 thread_timer_remain_second(p->t_routeadv));
12096 if (p->password)
12097 vty_out(vty, "Peer Authentication Enabled\n");
12098
cac9e917 12099 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12100 p->t_read ? "on" : "off",
12101 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12102 ? "on"
cac9e917 12103 : "off", p->fd);
d62a17ae 12104 }
12105
12106 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12107 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12108 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12109
12110 if (!use_json)
12111 vty_out(vty, "\n");
12112
12113 /* BFD information. */
12114 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12115
12116 if (use_json) {
12117 if (p->conf_if) /* Configured interface name. */
12118 json_object_object_add(json, p->conf_if, json_neigh);
12119 else /* Configured IP address. */
12120 json_object_object_add(json, p->host, json_neigh);
12121 }
12122}
12123
36235319
QY
12124static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
12125 enum show_type type,
12126 union sockunion *su,
12127 const char *conf_if, afi_t afi,
12128 bool use_json, json_object *json)
2986cac2 12129{
12130 struct listnode *node, *nnode;
12131 struct peer *peer;
12132 int find = 0;
12133 safi_t safi = SAFI_UNICAST;
12134 json_object *json_neighbor = NULL;
12135
12136 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12137
12138 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12139 continue;
12140
12141 if ((peer->afc[afi][safi]) == 0)
12142 continue;
12143
12144 if (use_json)
12145 json_neighbor = json_object_new_object();
12146
2ba1fe69 12147 if (type == show_all) {
2986cac2 12148 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 12149 json_neighbor);
2986cac2 12150
12151 if (use_json)
13909c4f
DS
12152 json_object_object_add(json, peer->host,
12153 json_neighbor);
2986cac2 12154
2ba1fe69 12155 } else if (type == show_peer) {
2986cac2 12156 if (conf_if) {
12157 if ((peer->conf_if
13909c4f
DS
12158 && !strcmp(peer->conf_if, conf_if))
12159 || (peer->hostname
2986cac2 12160 && !strcmp(peer->hostname, conf_if))) {
12161 find = 1;
13909c4f
DS
12162 bgp_show_peer_gr_status(vty, peer,
12163 use_json,
12164 json_neighbor);
2986cac2 12165 }
12166 } else {
12167 if (sockunion_same(&peer->su, su)) {
12168 find = 1;
13909c4f
DS
12169 bgp_show_peer_gr_status(vty, peer,
12170 use_json,
12171 json_neighbor);
2986cac2 12172 }
12173 }
13909c4f
DS
12174 if (use_json && find)
12175 json_object_object_add(json, peer->host,
12176 json_neighbor);
2986cac2 12177 }
12178
12179 if (find)
12180 break;
12181 }
12182
12183 if (type == show_peer && !find) {
12184 if (use_json)
13909c4f 12185 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 12186 else
12187 vty_out(vty, "%% No such neighbor\n");
12188 }
12189 if (use_json) {
13909c4f
DS
12190 vty_out(vty, "%s\n",
12191 json_object_to_json_string_ext(
12192 json, JSON_C_TO_STRING_PRETTY));
2986cac2 12193 } else {
12194 vty_out(vty, "\n");
12195 }
12196
12197 return CMD_SUCCESS;
12198}
12199
d62a17ae 12200static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
12201 enum show_type type, union sockunion *su,
9f049418 12202 const char *conf_if, bool use_json,
d62a17ae 12203 json_object *json)
12204{
12205 struct listnode *node, *nnode;
12206 struct peer *peer;
12207 int find = 0;
9f049418 12208 bool nbr_output = false;
d1927ebe
AS
12209 afi_t afi = AFI_MAX;
12210 safi_t safi = SAFI_MAX;
12211
12212 if (type == show_ipv4_peer || type == show_ipv4_all) {
12213 afi = AFI_IP;
12214 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
12215 afi = AFI_IP6;
12216 }
d62a17ae 12217
12218 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
12219 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
12220 continue;
12221
12222 switch (type) {
12223 case show_all:
12224 bgp_show_peer(vty, peer, use_json, json);
9f049418 12225 nbr_output = true;
d62a17ae 12226 break;
12227 case show_peer:
12228 if (conf_if) {
12229 if ((peer->conf_if
12230 && !strcmp(peer->conf_if, conf_if))
12231 || (peer->hostname
12232 && !strcmp(peer->hostname, conf_if))) {
12233 find = 1;
12234 bgp_show_peer(vty, peer, use_json,
12235 json);
12236 }
12237 } else {
12238 if (sockunion_same(&peer->su, su)) {
12239 find = 1;
12240 bgp_show_peer(vty, peer, use_json,
12241 json);
12242 }
12243 }
12244 break;
d1927ebe
AS
12245 case show_ipv4_peer:
12246 case show_ipv6_peer:
12247 FOREACH_SAFI (safi) {
12248 if (peer->afc[afi][safi]) {
12249 if (conf_if) {
12250 if ((peer->conf_if
12251 && !strcmp(peer->conf_if, conf_if))
12252 || (peer->hostname
12253 && !strcmp(peer->hostname, conf_if))) {
12254 find = 1;
12255 bgp_show_peer(vty, peer, use_json,
12256 json);
12257 break;
12258 }
12259 } else {
12260 if (sockunion_same(&peer->su, su)) {
12261 find = 1;
12262 bgp_show_peer(vty, peer, use_json,
12263 json);
12264 break;
12265 }
12266 }
12267 }
12268 }
12269 break;
12270 case show_ipv4_all:
12271 case show_ipv6_all:
12272 FOREACH_SAFI (safi) {
12273 if (peer->afc[afi][safi]) {
12274 bgp_show_peer(vty, peer, use_json, json);
12275 nbr_output = true;
12276 break;
12277 }
12278 }
12279 break;
d62a17ae 12280 }
12281 }
12282
d1927ebe
AS
12283 if ((type == show_peer || type == show_ipv4_peer ||
12284 type == show_ipv6_peer) && !find) {
d62a17ae 12285 if (use_json)
12286 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
12287 else
88b7d255 12288 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 12289 }
12290
d1927ebe
AS
12291 if (type != show_peer && type != show_ipv4_peer &&
12292 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 12293 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 12294
d62a17ae 12295 if (use_json) {
996c9314
LB
12296 vty_out(vty, "%s\n", json_object_to_json_string_ext(
12297 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 12298 } else {
12299 vty_out(vty, "\n");
12300 }
12301
12302 return CMD_SUCCESS;
12303}
12304
36235319
QY
12305static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
12306 enum show_type type,
12307 const char *ip_str,
12308 afi_t afi, bool use_json)
2986cac2 12309{
12310
12311 int ret;
12312 struct bgp *bgp;
12313 union sockunion su;
12314 json_object *json = NULL;
12315
12316 bgp = bgp_get_default();
12317
13909c4f
DS
12318 if (!bgp)
12319 return;
2986cac2 12320
13909c4f
DS
12321 if (!use_json)
12322 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
12323 NULL);
2986cac2 12324
13909c4f
DS
12325 json = json_object_new_object();
12326 if (ip_str) {
12327 ret = str2sockunion(ip_str, &su);
12328 if (ret < 0)
12329 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
12330 ip_str, afi,
12331 use_json, json);
12332 else
12333 bgp_show_neighbor_graceful_restart(
12334 vty, bgp, type, &su, NULL, afi, use_json, json);
12335 } else
12336 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
12337 afi, use_json, json);
12338 json_object_free(json);
2986cac2 12339}
12340
d62a17ae 12341static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
12342 enum show_type type,
12343 const char *ip_str,
9f049418 12344 bool use_json)
d62a17ae 12345{
0291c246
MK
12346 struct listnode *node, *nnode;
12347 struct bgp *bgp;
71aedaa3 12348 union sockunion su;
0291c246 12349 json_object *json = NULL;
71aedaa3 12350 int ret, is_first = 1;
9f049418 12351 bool nbr_output = false;
d62a17ae 12352
12353 if (use_json)
12354 vty_out(vty, "{\n");
12355
12356 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 12357 nbr_output = true;
d62a17ae 12358 if (use_json) {
12359 if (!(json = json_object_new_object())) {
af4c2728 12360 flog_err(
e50f7cfd 12361 EC_BGP_JSON_MEM_ERROR,
d62a17ae 12362 "Unable to allocate memory for JSON object");
12363 vty_out(vty,
12364 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
12365 return;
12366 }
12367
12368 json_object_int_add(json, "vrfId",
12369 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
12370 ? -1
12371 : (int64_t)bgp->vrf_id);
d62a17ae 12372 json_object_string_add(
12373 json, "vrfName",
12374 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12375 ? VRF_DEFAULT_NAME
d62a17ae 12376 : bgp->name);
12377
12378 if (!is_first)
12379 vty_out(vty, ",\n");
12380 else
12381 is_first = 0;
12382
12383 vty_out(vty, "\"%s\":",
12384 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12385 ? VRF_DEFAULT_NAME
d62a17ae 12386 : bgp->name);
12387 } else {
12388 vty_out(vty, "\nInstance %s:\n",
12389 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 12390 ? VRF_DEFAULT_NAME
d62a17ae 12391 : bgp->name);
12392 }
71aedaa3 12393
d1927ebe
AS
12394 if (type == show_peer || type == show_ipv4_peer ||
12395 type == show_ipv6_peer) {
71aedaa3
DS
12396 ret = str2sockunion(ip_str, &su);
12397 if (ret < 0)
12398 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12399 use_json, json);
12400 else
12401 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12402 use_json, json);
12403 } else {
d1927ebe 12404 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
12405 use_json, json);
12406 }
b77004d6 12407 json_object_free(json);
d62a17ae 12408 }
12409
01cbfd04 12410 if (use_json) {
d62a17ae 12411 vty_out(vty, "}\n");
01cbfd04
QY
12412 json_object_free(json);
12413 }
9f049418
DS
12414 else if (!nbr_output)
12415 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12416}
12417
12418static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
12419 enum show_type type, const char *ip_str,
9f049418 12420 bool use_json)
d62a17ae 12421{
12422 int ret;
12423 struct bgp *bgp;
12424 union sockunion su;
12425 json_object *json = NULL;
12426
12427 if (name) {
12428 if (strmatch(name, "all")) {
71aedaa3
DS
12429 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
12430 use_json);
d62a17ae 12431 return CMD_SUCCESS;
12432 } else {
12433 bgp = bgp_lookup_by_name(name);
12434 if (!bgp) {
12435 if (use_json) {
12436 json = json_object_new_object();
d62a17ae 12437 vty_out(vty, "%s\n",
12438 json_object_to_json_string_ext(
12439 json,
12440 JSON_C_TO_STRING_PRETTY));
12441 json_object_free(json);
12442 } else
12443 vty_out(vty,
9f049418 12444 "%% BGP instance not found\n");
d62a17ae 12445
12446 return CMD_WARNING;
12447 }
12448 }
12449 } else {
12450 bgp = bgp_get_default();
12451 }
12452
12453 if (bgp) {
12454 json = json_object_new_object();
12455 if (ip_str) {
12456 ret = str2sockunion(ip_str, &su);
12457 if (ret < 0)
12458 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
12459 use_json, json);
12460 else
12461 bgp_show_neighbor(vty, bgp, type, &su, NULL,
12462 use_json, json);
12463 } else {
12464 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
12465 json);
12466 }
12467 json_object_free(json);
ca61fd25
DS
12468 } else {
12469 if (use_json)
12470 vty_out(vty, "{}\n");
12471 else
12472 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 12473 }
12474
12475 return CMD_SUCCESS;
4fb25c53
DW
12476}
12477
2986cac2 12478
12479
12480/* "show [ip] bgp neighbors graceful-restart" commands. */
12481DEFUN (show_ip_bgp_neighbors_gracrful_restart,
12482 show_ip_bgp_neighbors_graceful_restart_cmd,
12483 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
12484 SHOW_STR
12485 BGP_STR
12486 IP_STR
12487 IPV6_STR
12488 NEIGHBOR_STR
12489 "Neighbor to display information about\n"
12490 "Neighbor to display information about\n"
12491 "Neighbor on BGP configured interface\n"
12492 GR_SHOW
12493 JSON_STR)
12494{
12495 char *sh_arg = NULL;
12496 enum show_type sh_type;
12497 int idx = 0;
12498 afi_t afi = AFI_MAX;
2986cac2 12499 bool uj = use_json(argc, argv);
12500
36235319 12501 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 12502 afi = AFI_MAX;
12503
12504 idx++;
12505
12506 if (argv_find(argv, argc, "A.B.C.D", &idx)
12507 || argv_find(argv, argc, "X:X::X:X", &idx)
12508 || argv_find(argv, argc, "WORD", &idx)) {
12509 sh_type = show_peer;
12510 sh_arg = argv[idx]->arg;
12511 } else
12512 sh_type = show_all;
12513
12514 if (!argv_find(argv, argc, "graceful-restart", &idx))
12515 return CMD_SUCCESS;
12516
12517
36235319
QY
12518 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
12519 afi, uj);
2986cac2 12520}
12521
716b2d8a 12522/* "show [ip] bgp neighbors" commands. */
718e3744 12523DEFUN (show_ip_bgp_neighbors,
12524 show_ip_bgp_neighbors_cmd,
24345e82 12525 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 12526 SHOW_STR
12527 IP_STR
12528 BGP_STR
f2a8972b 12529 BGP_INSTANCE_HELP_STR
8c3deaae
QY
12530 "Address Family\n"
12531 "Address Family\n"
718e3744 12532 "Detailed information on TCP and BGP neighbor connections\n"
12533 "Neighbor to display information about\n"
a80beece 12534 "Neighbor to display information about\n"
91d37724 12535 "Neighbor on BGP configured interface\n"
9973d184 12536 JSON_STR)
718e3744 12537{
d62a17ae 12538 char *vrf = NULL;
12539 char *sh_arg = NULL;
12540 enum show_type sh_type;
d1927ebe 12541 afi_t afi = AFI_MAX;
718e3744 12542
9f049418 12543 bool uj = use_json(argc, argv);
718e3744 12544
d62a17ae 12545 int idx = 0;
718e3744 12546
9a8bdf1c
PG
12547 /* [<vrf> VIEWVRFNAME] */
12548 if (argv_find(argv, argc, "vrf", &idx)) {
12549 vrf = argv[idx + 1]->arg;
12550 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12551 vrf = NULL;
12552 } else if (argv_find(argv, argc, "view", &idx))
12553 /* [<view> VIEWVRFNAME] */
d62a17ae 12554 vrf = argv[idx + 1]->arg;
718e3744 12555
d62a17ae 12556 idx++;
d1927ebe
AS
12557
12558 if (argv_find(argv, argc, "ipv4", &idx)) {
12559 sh_type = show_ipv4_all;
12560 afi = AFI_IP;
12561 } else if (argv_find(argv, argc, "ipv6", &idx)) {
12562 sh_type = show_ipv6_all;
12563 afi = AFI_IP6;
12564 } else {
12565 sh_type = show_all;
12566 }
12567
d62a17ae 12568 if (argv_find(argv, argc, "A.B.C.D", &idx)
12569 || argv_find(argv, argc, "X:X::X:X", &idx)
12570 || argv_find(argv, argc, "WORD", &idx)) {
12571 sh_type = show_peer;
12572 sh_arg = argv[idx]->arg;
d1927ebe
AS
12573 }
12574
12575 if (sh_type == show_peer && afi == AFI_IP) {
12576 sh_type = show_ipv4_peer;
12577 } else if (sh_type == show_peer && afi == AFI_IP6) {
12578 sh_type = show_ipv6_peer;
12579 }
856ca177 12580
d62a17ae 12581 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 12582}
12583
716b2d8a 12584/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 12585 paths' and `show ip mbgp paths'. Those functions results are the
12586 same.*/
f412b39a 12587DEFUN (show_ip_bgp_paths,
718e3744 12588 show_ip_bgp_paths_cmd,
46f296b4 12589 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 12590 SHOW_STR
12591 IP_STR
12592 BGP_STR
46f296b4 12593 BGP_SAFI_HELP_STR
718e3744 12594 "Path information\n")
12595{
d62a17ae 12596 vty_out(vty, "Address Refcnt Path\n");
12597 aspath_print_all_vty(vty);
12598 return CMD_SUCCESS;
718e3744 12599}
12600
718e3744 12601#include "hash.h"
12602
e3b78da8 12603static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12604 struct vty *vty)
718e3744 12605{
d62a17ae 12606 struct community *com;
718e3744 12607
e3b78da8 12608 com = (struct community *)bucket->data;
3f65c5b1 12609 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 12610 community_str(com, false));
718e3744 12611}
12612
12613/* Show BGP's community internal data. */
f412b39a 12614DEFUN (show_ip_bgp_community_info,
718e3744 12615 show_ip_bgp_community_info_cmd,
bec37ba5 12616 "show [ip] bgp community-info",
718e3744 12617 SHOW_STR
12618 IP_STR
12619 BGP_STR
12620 "List all bgp community information\n")
12621{
d62a17ae 12622 vty_out(vty, "Address Refcnt Community\n");
718e3744 12623
d62a17ae 12624 hash_iterate(community_hash(),
e3b78da8 12625 (void (*)(struct hash_bucket *,
d62a17ae 12626 void *))community_show_all_iterator,
12627 vty);
718e3744 12628
d62a17ae 12629 return CMD_SUCCESS;
718e3744 12630}
12631
e3b78da8 12632static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 12633 struct vty *vty)
57d187bc 12634{
d62a17ae 12635 struct lcommunity *lcom;
57d187bc 12636
e3b78da8 12637 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 12638 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 12639 lcommunity_str(lcom, false));
57d187bc
JS
12640}
12641
12642/* Show BGP's community internal data. */
12643DEFUN (show_ip_bgp_lcommunity_info,
12644 show_ip_bgp_lcommunity_info_cmd,
12645 "show ip bgp large-community-info",
12646 SHOW_STR
12647 IP_STR
12648 BGP_STR
12649 "List all bgp large-community information\n")
12650{
d62a17ae 12651 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 12652
d62a17ae 12653 hash_iterate(lcommunity_hash(),
e3b78da8 12654 (void (*)(struct hash_bucket *,
d62a17ae 12655 void *))lcommunity_show_all_iterator,
12656 vty);
57d187bc 12657
d62a17ae 12658 return CMD_SUCCESS;
57d187bc 12659}
2986cac2 12660/* Graceful Restart */
12661
12662static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
12663 struct bgp *bgp,
12664 bool use_json,
12665 json_object *json)
2986cac2 12666{
57d187bc
JS
12667
12668
2986cac2 12669 vty_out(vty, "\n%s", SHOW_GR_HEADER);
12670
7318ae88 12671 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 12672
12673 switch (bgp_global_gr_mode) {
12674
12675 case GLOBAL_HELPER:
13909c4f 12676 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 12677 break;
12678
12679 case GLOBAL_GR:
13909c4f 12680 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 12681 break;
12682
12683 case GLOBAL_DISABLE:
13909c4f 12684 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 12685 break;
12686
12687 case GLOBAL_INVALID:
2986cac2 12688 vty_out(vty,
2ba1fe69 12689 "Global BGP GR Mode Invalid\n");
2986cac2 12690 break;
12691 }
12692 vty_out(vty, "\n");
12693}
12694
36235319
QY
12695static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
12696 enum show_type type,
12697 const char *ip_str,
12698 afi_t afi, bool use_json)
2986cac2 12699{
12700 if ((afi == AFI_MAX) && (ip_str == NULL)) {
12701 afi = AFI_IP;
12702
12703 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
12704
36235319
QY
12705 bgp_show_neighbor_graceful_restart_vty(
12706 vty, type, ip_str, afi, use_json);
2986cac2 12707 afi++;
12708 }
12709 } else if (afi != AFI_MAX) {
36235319
QY
12710 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
12711 use_json);
2986cac2 12712 } else {
12713 return CMD_ERR_INCOMPLETE;
12714 }
12715
12716 return CMD_SUCCESS;
12717}
12718/* Graceful Restart */
12719
f412b39a 12720DEFUN (show_ip_bgp_attr_info,
718e3744 12721 show_ip_bgp_attr_info_cmd,
bec37ba5 12722 "show [ip] bgp attribute-info",
718e3744 12723 SHOW_STR
12724 IP_STR
12725 BGP_STR
12726 "List all bgp attribute information\n")
12727{
d62a17ae 12728 attr_show_all(vty);
12729 return CMD_SUCCESS;
718e3744 12730}
6b0655a2 12731
03915806
CS
12732static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
12733 afi_t afi, safi_t safi,
12734 bool use_json, json_object *json)
53089bec 12735{
12736 struct bgp *bgp;
12737 struct listnode *node;
12738 char *vname;
12739 char buf1[INET6_ADDRSTRLEN];
12740 char *ecom_str;
12741 vpn_policy_direction_t dir;
12742
03915806 12743 if (json) {
b46dfd20
DS
12744 json_object *json_import_vrfs = NULL;
12745 json_object *json_export_vrfs = NULL;
12746
b46dfd20
DS
12747 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12748
53089bec 12749 if (!bgp) {
b46dfd20
DS
12750 vty_out(vty, "%s\n",
12751 json_object_to_json_string_ext(
12752 json,
12753 JSON_C_TO_STRING_PRETTY));
12754 json_object_free(json);
12755
53089bec 12756 return CMD_WARNING;
12757 }
b46dfd20 12758
94d4c685
DS
12759 /* Provide context for the block */
12760 json_object_string_add(json, "vrf", name ? name : "default");
12761 json_object_string_add(json, "afiSafi",
5cb5f4d0 12762 get_afi_safi_str(afi, safi, true));
94d4c685 12763
b46dfd20
DS
12764 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12765 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
12766 json_object_string_add(json, "importFromVrfs", "none");
12767 json_object_string_add(json, "importRts", "none");
12768 } else {
6ce24e52
DS
12769 json_import_vrfs = json_object_new_array();
12770
b46dfd20
DS
12771 for (ALL_LIST_ELEMENTS_RO(
12772 bgp->vpn_policy[afi].import_vrf,
12773 node, vname))
12774 json_object_array_add(json_import_vrfs,
12775 json_object_new_string(vname));
12776
b20875ea
CS
12777 json_object_object_add(json, "importFromVrfs",
12778 json_import_vrfs);
b46dfd20 12779 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12780 if (bgp->vpn_policy[afi].rtlist[dir]) {
12781 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12782 bgp->vpn_policy[afi].rtlist[dir],
12783 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12784 json_object_string_add(json, "importRts",
12785 ecom_str);
12786 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12787 } else
12788 json_object_string_add(json, "importRts",
12789 "none");
b46dfd20
DS
12790 }
12791
12792 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12793 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
12794 json_object_string_add(json, "exportToVrfs", "none");
12795 json_object_string_add(json, "routeDistinguisher",
12796 "none");
12797 json_object_string_add(json, "exportRts", "none");
12798 } else {
6ce24e52
DS
12799 json_export_vrfs = json_object_new_array();
12800
b46dfd20
DS
12801 for (ALL_LIST_ELEMENTS_RO(
12802 bgp->vpn_policy[afi].export_vrf,
12803 node, vname))
12804 json_object_array_add(json_export_vrfs,
12805 json_object_new_string(vname));
12806 json_object_object_add(json, "exportToVrfs",
12807 json_export_vrfs);
12808 json_object_string_add(json, "routeDistinguisher",
12809 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12810 buf1, RD_ADDRSTRLEN));
12811
12812 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12813 if (bgp->vpn_policy[afi].rtlist[dir]) {
12814 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12815 bgp->vpn_policy[afi].rtlist[dir],
12816 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12817 json_object_string_add(json, "exportRts",
12818 ecom_str);
12819 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12820 } else
12821 json_object_string_add(json, "exportRts",
12822 "none");
b46dfd20
DS
12823 }
12824
03915806
CS
12825 if (use_json) {
12826 vty_out(vty, "%s\n",
12827 json_object_to_json_string_ext(json,
b46dfd20 12828 JSON_C_TO_STRING_PRETTY));
03915806
CS
12829 json_object_free(json);
12830 }
53089bec 12831 } else {
b46dfd20
DS
12832 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
12833
53089bec 12834 if (!bgp) {
b46dfd20 12835 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 12836 return CMD_WARNING;
12837 }
53089bec 12838
b46dfd20
DS
12839 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12840 BGP_CONFIG_VRF_TO_VRF_IMPORT))
12841 vty_out(vty,
12842 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 12843 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12844 else {
12845 vty_out(vty,
12846 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 12847 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12848
12849 for (ALL_LIST_ELEMENTS_RO(
12850 bgp->vpn_policy[afi].import_vrf,
12851 node, vname))
12852 vty_out(vty, " %s\n", vname);
12853
12854 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
12855 ecom_str = NULL;
12856 if (bgp->vpn_policy[afi].rtlist[dir]) {
12857 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12858 bgp->vpn_policy[afi].rtlist[dir],
12859 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 12860 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 12861
b20875ea
CS
12862 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12863 } else
12864 vty_out(vty, "Import RT(s):\n");
53089bec 12865 }
53089bec 12866
b46dfd20
DS
12867 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
12868 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12869 vty_out(vty,
12870 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 12871 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12872 else {
12873 vty_out(vty,
04c9077f 12874 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 12875 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
12876
12877 for (ALL_LIST_ELEMENTS_RO(
12878 bgp->vpn_policy[afi].export_vrf,
12879 node, vname))
12880 vty_out(vty, " %s\n", vname);
12881
12882 vty_out(vty, "RD: %s\n",
12883 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
12884 buf1, RD_ADDRSTRLEN));
12885
12886 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
12887 if (bgp->vpn_policy[afi].rtlist[dir]) {
12888 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
12889 bgp->vpn_policy[afi].rtlist[dir],
12890 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
12891 vty_out(vty, "Export RT: %s\n", ecom_str);
12892 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
12893 } else
12894 vty_out(vty, "Import RT(s):\n");
53089bec 12895 }
53089bec 12896 }
12897
12898 return CMD_SUCCESS;
12899}
12900
03915806
CS
12901static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
12902 safi_t safi, bool use_json)
12903{
12904 struct listnode *node, *nnode;
12905 struct bgp *bgp;
12906 char *vrf_name = NULL;
12907 json_object *json = NULL;
12908 json_object *json_vrf = NULL;
12909 json_object *json_vrfs = NULL;
12910
12911 if (use_json) {
12912 json = json_object_new_object();
12913 json_vrfs = json_object_new_object();
12914 }
12915
12916 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
12917
12918 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
12919 vrf_name = bgp->name;
12920
12921 if (use_json) {
12922 json_vrf = json_object_new_object();
12923 } else {
12924 vty_out(vty, "\nInstance %s:\n",
12925 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12926 ? VRF_DEFAULT_NAME : bgp->name);
12927 }
12928 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
12929 if (use_json) {
12930 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
12931 json_object_object_add(json_vrfs,
12932 VRF_DEFAULT_NAME, json_vrf);
12933 else
12934 json_object_object_add(json_vrfs, vrf_name,
12935 json_vrf);
12936 }
12937 }
12938
12939 if (use_json) {
12940 json_object_object_add(json, "vrfs", json_vrfs);
12941 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
12942 JSON_C_TO_STRING_PRETTY));
12943 json_object_free(json);
12944 }
12945
12946 return CMD_SUCCESS;
12947}
12948
53089bec 12949/* "show [ip] bgp route-leak" command. */
12950DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
12951 show_ip_bgp_route_leak_cmd,
12952 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
12953 SHOW_STR
12954 IP_STR
12955 BGP_STR
12956 BGP_INSTANCE_HELP_STR
12957 BGP_AFI_HELP_STR
12958 BGP_SAFI_HELP_STR
12959 "Route leaking information\n"
12960 JSON_STR)
53089bec 12961{
12962 char *vrf = NULL;
12963 afi_t afi = AFI_MAX;
12964 safi_t safi = SAFI_MAX;
12965
9f049418 12966 bool uj = use_json(argc, argv);
53089bec 12967 int idx = 0;
03915806 12968 json_object *json = NULL;
53089bec 12969
12970 /* show [ip] bgp */
12971 if (argv_find(argv, argc, "ip", &idx)) {
12972 afi = AFI_IP;
12973 safi = SAFI_UNICAST;
12974 }
12975 /* [vrf VIEWVRFNAME] */
12976 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
12977 vty_out(vty,
12978 "%% This command is not applicable to BGP views\n");
53089bec 12979 return CMD_WARNING;
12980 }
12981
9a8bdf1c
PG
12982 if (argv_find(argv, argc, "vrf", &idx)) {
12983 vrf = argv[idx + 1]->arg;
12984 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
12985 vrf = NULL;
12986 }
53089bec 12987 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
12988 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
12989 argv_find_and_parse_safi(argv, argc, &idx, &safi);
12990 }
12991
12992 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
12993 vty_out(vty,
12994 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 12995 return CMD_WARNING;
12996 }
12997
03915806
CS
12998 if (vrf && strmatch(vrf, "all"))
12999 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13000
13001 if (uj)
13002 json = json_object_new_object();
13003
13004 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13005}
13006
d62a17ae 13007static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13008 safi_t safi)
f186de26 13009{
d62a17ae 13010 struct listnode *node, *nnode;
13011 struct bgp *bgp;
f186de26 13012
d62a17ae 13013 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13014 vty_out(vty, "\nInstance %s:\n",
13015 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13016 ? VRF_DEFAULT_NAME
d62a17ae 13017 : bgp->name);
13018 update_group_show(bgp, afi, safi, vty, 0);
13019 }
f186de26 13020}
13021
d62a17ae 13022static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13023 int safi, uint64_t subgrp_id)
4fb25c53 13024{
d62a17ae 13025 struct bgp *bgp;
4fb25c53 13026
d62a17ae 13027 if (name) {
13028 if (strmatch(name, "all")) {
13029 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13030 return CMD_SUCCESS;
13031 } else {
13032 bgp = bgp_lookup_by_name(name);
13033 }
13034 } else {
13035 bgp = bgp_get_default();
13036 }
4fb25c53 13037
d62a17ae 13038 if (bgp)
13039 update_group_show(bgp, afi, safi, vty, subgrp_id);
13040 return CMD_SUCCESS;
4fb25c53
DW
13041}
13042
8fe8a7f6
DS
13043DEFUN (show_ip_bgp_updgrps,
13044 show_ip_bgp_updgrps_cmd,
c1a44e43 13045 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13046 SHOW_STR
13047 IP_STR
13048 BGP_STR
13049 BGP_INSTANCE_HELP_STR
c9e571b4 13050 BGP_AFI_HELP_STR
9bedbb1e 13051 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13052 "Detailed info about dynamic update groups\n"
13053 "Specific subgroup to display detailed info for\n")
8386ac43 13054{
d62a17ae 13055 char *vrf = NULL;
13056 afi_t afi = AFI_IP6;
13057 safi_t safi = SAFI_UNICAST;
13058 uint64_t subgrp_id = 0;
13059
13060 int idx = 0;
13061
13062 /* show [ip] bgp */
13063 if (argv_find(argv, argc, "ip", &idx))
13064 afi = AFI_IP;
9a8bdf1c
PG
13065 /* [<vrf> VIEWVRFNAME] */
13066 if (argv_find(argv, argc, "vrf", &idx)) {
13067 vrf = argv[idx + 1]->arg;
13068 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13069 vrf = NULL;
13070 } else if (argv_find(argv, argc, "view", &idx))
13071 /* [<view> VIEWVRFNAME] */
13072 vrf = argv[idx + 1]->arg;
d62a17ae 13073 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13074 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13075 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13076 }
5bf15956 13077
d62a17ae 13078 /* get subgroup id, if provided */
13079 idx = argc - 1;
13080 if (argv[idx]->type == VARIABLE_TKN)
13081 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13082
d62a17ae 13083 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13084}
13085
f186de26 13086DEFUN (show_bgp_instance_all_ipv6_updgrps,
13087 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13088 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13089 SHOW_STR
716b2d8a 13090 IP_STR
f186de26 13091 BGP_STR
13092 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13093 "Detailed info about dynamic update groups\n")
f186de26 13094{
d62a17ae 13095 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13096 return CMD_SUCCESS;
f186de26 13097}
13098
43d3f4fc
DS
13099DEFUN (show_bgp_l2vpn_evpn_updgrps,
13100 show_bgp_l2vpn_evpn_updgrps_cmd,
13101 "show [ip] bgp l2vpn evpn update-groups",
13102 SHOW_STR
13103 IP_STR
13104 BGP_STR
13105 "l2vpn address family\n"
13106 "evpn sub-address family\n"
13107 "Detailed info about dynamic update groups\n")
13108{
13109 char *vrf = NULL;
13110 uint64_t subgrp_id = 0;
13111
13112 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
13113 return CMD_SUCCESS;
13114}
13115
5bf15956
DW
13116DEFUN (show_bgp_updgrps_stats,
13117 show_bgp_updgrps_stats_cmd,
716b2d8a 13118 "show [ip] bgp update-groups statistics",
3f9c7369 13119 SHOW_STR
716b2d8a 13120 IP_STR
3f9c7369 13121 BGP_STR
0c7b1b01 13122 "Detailed info about dynamic update groups\n"
3f9c7369
DS
13123 "Statistics\n")
13124{
d62a17ae 13125 struct bgp *bgp;
3f9c7369 13126
d62a17ae 13127 bgp = bgp_get_default();
13128 if (bgp)
13129 update_group_show_stats(bgp, vty);
3f9c7369 13130
d62a17ae 13131 return CMD_SUCCESS;
3f9c7369
DS
13132}
13133
8386ac43 13134DEFUN (show_bgp_instance_updgrps_stats,
13135 show_bgp_instance_updgrps_stats_cmd,
18c57037 13136 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 13137 SHOW_STR
716b2d8a 13138 IP_STR
8386ac43 13139 BGP_STR
13140 BGP_INSTANCE_HELP_STR
0c7b1b01 13141 "Detailed info about dynamic update groups\n"
8386ac43 13142 "Statistics\n")
13143{
d62a17ae 13144 int idx_word = 3;
13145 struct bgp *bgp;
8386ac43 13146
d62a17ae 13147 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
13148 if (bgp)
13149 update_group_show_stats(bgp, vty);
8386ac43 13150
d62a17ae 13151 return CMD_SUCCESS;
8386ac43 13152}
13153
d62a17ae 13154static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
13155 afi_t afi, safi_t safi,
13156 const char *what, uint64_t subgrp_id)
3f9c7369 13157{
d62a17ae 13158 struct bgp *bgp;
8386ac43 13159
d62a17ae 13160 if (name)
13161 bgp = bgp_lookup_by_name(name);
13162 else
13163 bgp = bgp_get_default();
8386ac43 13164
d62a17ae 13165 if (bgp) {
13166 if (!strcmp(what, "advertise-queue"))
13167 update_group_show_adj_queue(bgp, afi, safi, vty,
13168 subgrp_id);
13169 else if (!strcmp(what, "advertised-routes"))
13170 update_group_show_advertised(bgp, afi, safi, vty,
13171 subgrp_id);
13172 else if (!strcmp(what, "packet-queue"))
13173 update_group_show_packet_queue(bgp, afi, safi, vty,
13174 subgrp_id);
13175 }
3f9c7369
DS
13176}
13177
dc64bdec
QY
13178DEFPY(show_ip_bgp_instance_updgrps_adj_s,
13179 show_ip_bgp_instance_updgrps_adj_s_cmd,
13180 "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",
13181 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
13182 BGP_SAFI_HELP_STR
13183 "Detailed info about dynamic update groups\n"
13184 "Specific subgroup to display info for\n"
13185 "Advertisement queue\n"
13186 "Announced routes\n"
13187 "Packet queue\n")
3f9c7369 13188{
dc64bdec
QY
13189 uint64_t subgrp_id = 0;
13190 afi_t afiz;
13191 safi_t safiz;
13192 if (sgid)
13193 subgrp_id = strtoull(sgid, NULL, 10);
13194
13195 if (!ip && !afi)
13196 afiz = AFI_IP6;
13197 if (!ip && afi)
13198 afiz = bgp_vty_afi_from_str(afi);
13199 if (ip && !afi)
13200 afiz = AFI_IP;
13201 if (ip && afi) {
13202 afiz = bgp_vty_afi_from_str(afi);
13203 if (afiz != AFI_IP)
13204 vty_out(vty,
13205 "%% Cannot specify both 'ip' and 'ipv6'\n");
13206 return CMD_WARNING;
13207 }
d62a17ae 13208
dc64bdec 13209 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 13210
dc64bdec 13211 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 13212 return CMD_SUCCESS;
13213}
13214
d62a17ae 13215static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
13216{
13217 struct listnode *node, *nnode;
13218 struct prefix *range;
13219 struct peer *conf;
13220 struct peer *peer;
13221 char buf[PREFIX2STR_BUFFER];
13222 afi_t afi;
13223 safi_t safi;
13224 const char *peer_status;
13225 const char *af_str;
13226 int lr_count;
13227 int dynamic;
13228 int af_cfgd;
13229
13230 conf = group->conf;
13231
13232 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
3b61f610
QY
13233 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13234 group->name, conf->as);
d62a17ae 13235 } else if (conf->as_type == AS_INTERNAL) {
3b61f610
QY
13236 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
13237 group->name, group->bgp->as);
d62a17ae 13238 } else {
13239 vty_out(vty, "\nBGP peer-group %s\n", group->name);
13240 }
f14e6fdb 13241
d62a17ae 13242 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
13243 vty_out(vty, " Peer-group type is internal\n");
13244 else
13245 vty_out(vty, " Peer-group type is external\n");
13246
13247 /* Display AFs configured. */
13248 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
13249 FOREACH_AFI_SAFI (afi, safi) {
13250 if (conf->afc[afi][safi]) {
13251 af_cfgd = 1;
5cb5f4d0 13252 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 13253 }
05c7a1cc 13254 }
d62a17ae 13255 if (!af_cfgd)
13256 vty_out(vty, " none\n");
13257 else
13258 vty_out(vty, "\n");
13259
13260 /* Display listen ranges (for dynamic neighbors), if any */
13261 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
13262 if (afi == AFI_IP)
13263 af_str = "IPv4";
13264 else if (afi == AFI_IP6)
13265 af_str = "IPv6";
13266 else
13267 af_str = "???";
13268 lr_count = listcount(group->listen_range[afi]);
13269 if (lr_count) {
13270 vty_out(vty, " %d %s listen range(s)\n", lr_count,
13271 af_str);
13272
13273
13274 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
13275 nnode, range)) {
13276 prefix2str(range, buf, sizeof(buf));
13277 vty_out(vty, " %s\n", buf);
13278 }
13279 }
13280 }
f14e6fdb 13281
d62a17ae 13282 /* Display group members and their status */
13283 if (listcount(group->peer)) {
13284 vty_out(vty, " Peer-group members:\n");
13285 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
13286 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
13287 peer_status = "Idle (Admin)";
13288 else if (CHECK_FLAG(peer->sflags,
13289 PEER_STATUS_PREFIX_OVERFLOW))
13290 peer_status = "Idle (PfxCt)";
13291 else
13292 peer_status = lookup_msg(bgp_status_msg,
13293 peer->status, NULL);
13294
13295 dynamic = peer_dynamic_neighbor(peer);
13296 vty_out(vty, " %s %s %s \n", peer->host,
13297 dynamic ? "(dynamic)" : "", peer_status);
13298 }
13299 }
f14e6fdb 13300
d62a17ae 13301 return CMD_SUCCESS;
13302}
13303
ff9959b0
QY
13304static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
13305 const char *group_name)
d62a17ae 13306{
ff9959b0 13307 struct bgp *bgp;
d62a17ae 13308 struct listnode *node, *nnode;
13309 struct peer_group *group;
ff9959b0
QY
13310 bool found = false;
13311
13312 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13313
13314 if (!bgp) {
9f049418 13315 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
13316 return CMD_WARNING;
13317 }
d62a17ae 13318
13319 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
13320 if (group_name) {
13321 if (strmatch(group->name, group_name)) {
d62a17ae 13322 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
13323 found = true;
13324 break;
d62a17ae 13325 }
ff9959b0
QY
13326 } else {
13327 bgp_show_one_peer_group(vty, group);
d62a17ae 13328 }
f14e6fdb 13329 }
f14e6fdb 13330
ff9959b0 13331 if (group_name && !found)
d62a17ae 13332 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 13333
d62a17ae 13334 return CMD_SUCCESS;
f14e6fdb
DS
13335}
13336
f14e6fdb
DS
13337DEFUN (show_ip_bgp_peer_groups,
13338 show_ip_bgp_peer_groups_cmd,
18c57037 13339 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
13340 SHOW_STR
13341 IP_STR
13342 BGP_STR
8386ac43 13343 BGP_INSTANCE_HELP_STR
d6e3c605
QY
13344 "Detailed information on BGP peer groups\n"
13345 "Peer group name\n")
f14e6fdb 13346{
d62a17ae 13347 char *vrf, *pg;
d62a17ae 13348 int idx = 0;
f14e6fdb 13349
a4d82a8a
PZ
13350 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
13351 : NULL;
d62a17ae 13352 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 13353
ff9959b0 13354 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 13355}
3f9c7369 13356
d6e3c605 13357
718e3744 13358/* Redistribute VTY commands. */
13359
718e3744 13360DEFUN (bgp_redistribute_ipv4,
13361 bgp_redistribute_ipv4_cmd,
40d1cbfb 13362 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 13363 "Redistribute information from another routing protocol\n"
ab0181ee 13364 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 13365{
d62a17ae 13366 VTY_DECLVAR_CONTEXT(bgp, bgp);
13367 int idx_protocol = 1;
13368 int type;
718e3744 13369
d62a17ae 13370 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13371 if (type < 0) {
13372 vty_out(vty, "%% Invalid route type\n");
13373 return CMD_WARNING_CONFIG_FAILED;
13374 }
7f323236 13375
d62a17ae 13376 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13377 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 13378}
13379
d62a17ae 13380ALIAS_HIDDEN(
13381 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
13382 "redistribute " FRR_IP_REDIST_STR_BGPD,
13383 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 13384
718e3744 13385DEFUN (bgp_redistribute_ipv4_rmap,
13386 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 13387 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 13388 "Redistribute information from another routing protocol\n"
ab0181ee 13389 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13390 "Route map reference\n"
13391 "Pointer to route-map entries\n")
13392{
d62a17ae 13393 VTY_DECLVAR_CONTEXT(bgp, bgp);
13394 int idx_protocol = 1;
13395 int idx_word = 3;
13396 int type;
13397 struct bgp_redist *red;
e923dd62 13398 bool changed;
1de27621
DA
13399 struct route_map *route_map = route_map_lookup_warn_noexist(
13400 vty, argv[idx_word]->arg);
718e3744 13401
d62a17ae 13402 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13403 if (type < 0) {
13404 vty_out(vty, "%% Invalid route type\n");
13405 return CMD_WARNING_CONFIG_FAILED;
13406 }
718e3744 13407
d62a17ae 13408 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13409 changed =
13410 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13411 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 13412}
13413
d62a17ae 13414ALIAS_HIDDEN(
13415 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
13416 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
13417 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13418 "Route map reference\n"
13419 "Pointer to route-map entries\n")
596c17ba 13420
718e3744 13421DEFUN (bgp_redistribute_ipv4_metric,
13422 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 13423 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13424 "Redistribute information from another routing protocol\n"
ab0181ee 13425 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13426 "Metric for redistributed routes\n"
13427 "Default metric\n")
13428{
d62a17ae 13429 VTY_DECLVAR_CONTEXT(bgp, bgp);
13430 int idx_protocol = 1;
13431 int idx_number = 3;
13432 int type;
d7c0a89a 13433 uint32_t metric;
d62a17ae 13434 struct bgp_redist *red;
e923dd62 13435 bool changed;
d62a17ae 13436
13437 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13438 if (type < 0) {
13439 vty_out(vty, "%% Invalid route type\n");
13440 return CMD_WARNING_CONFIG_FAILED;
13441 }
13442 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13443
13444 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13445 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13446 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13447}
13448
13449ALIAS_HIDDEN(
13450 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
13451 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
13452 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13453 "Metric for redistributed routes\n"
13454 "Default metric\n")
596c17ba 13455
718e3744 13456DEFUN (bgp_redistribute_ipv4_rmap_metric,
13457 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 13458 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13459 "Redistribute information from another routing protocol\n"
ab0181ee 13460 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13461 "Route map reference\n"
13462 "Pointer to route-map entries\n"
13463 "Metric for redistributed routes\n"
13464 "Default metric\n")
13465{
d62a17ae 13466 VTY_DECLVAR_CONTEXT(bgp, bgp);
13467 int idx_protocol = 1;
13468 int idx_word = 3;
13469 int idx_number = 5;
13470 int type;
d7c0a89a 13471 uint32_t metric;
d62a17ae 13472 struct bgp_redist *red;
e923dd62 13473 bool changed;
1de27621
DA
13474 struct route_map *route_map =
13475 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13476
13477 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13478 if (type < 0) {
13479 vty_out(vty, "%% Invalid route type\n");
13480 return CMD_WARNING_CONFIG_FAILED;
13481 }
13482 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13483
13484 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
13485 changed =
13486 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13487 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
13488 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13489}
13490
13491ALIAS_HIDDEN(
13492 bgp_redistribute_ipv4_rmap_metric,
13493 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
13494 "redistribute " FRR_IP_REDIST_STR_BGPD
13495 " route-map WORD metric (0-4294967295)",
13496 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13497 "Route map reference\n"
13498 "Pointer to route-map entries\n"
13499 "Metric for redistributed routes\n"
13500 "Default metric\n")
596c17ba 13501
718e3744 13502DEFUN (bgp_redistribute_ipv4_metric_rmap,
13503 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 13504 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13505 "Redistribute information from another routing protocol\n"
ab0181ee 13506 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 13507 "Metric for redistributed routes\n"
13508 "Default metric\n"
13509 "Route map reference\n"
13510 "Pointer to route-map entries\n")
13511{
d62a17ae 13512 VTY_DECLVAR_CONTEXT(bgp, bgp);
13513 int idx_protocol = 1;
13514 int idx_number = 3;
13515 int idx_word = 5;
13516 int type;
d7c0a89a 13517 uint32_t metric;
d62a17ae 13518 struct bgp_redist *red;
e923dd62 13519 bool changed;
1de27621
DA
13520 struct route_map *route_map =
13521 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13522
13523 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13524 if (type < 0) {
13525 vty_out(vty, "%% Invalid route type\n");
13526 return CMD_WARNING_CONFIG_FAILED;
13527 }
13528 metric = strtoul(argv[idx_number]->arg, NULL, 10);
13529
13530 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 13531 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
13532 changed |=
13533 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13534 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 13535}
13536
13537ALIAS_HIDDEN(
13538 bgp_redistribute_ipv4_metric_rmap,
13539 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
13540 "redistribute " FRR_IP_REDIST_STR_BGPD
13541 " metric (0-4294967295) route-map WORD",
13542 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13543 "Metric for redistributed routes\n"
13544 "Default metric\n"
13545 "Route map reference\n"
13546 "Pointer to route-map entries\n")
596c17ba 13547
7c8ff89e
DS
13548DEFUN (bgp_redistribute_ipv4_ospf,
13549 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 13550 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
13551 "Redistribute information from another routing protocol\n"
13552 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13553 "Non-main Kernel Routing Table\n"
13554 "Instance ID/Table ID\n")
7c8ff89e 13555{
d62a17ae 13556 VTY_DECLVAR_CONTEXT(bgp, bgp);
13557 int idx_ospf_table = 1;
13558 int idx_number = 2;
d7c0a89a
QY
13559 unsigned short instance;
13560 unsigned short protocol;
7c8ff89e 13561
d62a17ae 13562 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 13563
d62a17ae 13564 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13565 protocol = ZEBRA_ROUTE_OSPF;
13566 else
13567 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 13568
d62a17ae 13569 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13570 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
13571}
13572
d62a17ae 13573ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
13574 "redistribute <ospf|table> (1-65535)",
13575 "Redistribute information from another routing protocol\n"
13576 "Open Shortest Path First (OSPFv2)\n"
13577 "Non-main Kernel Routing Table\n"
13578 "Instance ID/Table ID\n")
596c17ba 13579
7c8ff89e
DS
13580DEFUN (bgp_redistribute_ipv4_ospf_rmap,
13581 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 13582 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
13583 "Redistribute information from another routing protocol\n"
13584 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13585 "Non-main Kernel Routing Table\n"
13586 "Instance ID/Table ID\n"
7c8ff89e
DS
13587 "Route map reference\n"
13588 "Pointer to route-map entries\n")
13589{
d62a17ae 13590 VTY_DECLVAR_CONTEXT(bgp, bgp);
13591 int idx_ospf_table = 1;
13592 int idx_number = 2;
13593 int idx_word = 4;
13594 struct bgp_redist *red;
d7c0a89a 13595 unsigned short instance;
d62a17ae 13596 int protocol;
e923dd62 13597 bool changed;
1de27621
DA
13598 struct route_map *route_map =
13599 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13600
13601 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13602 protocol = ZEBRA_ROUTE_OSPF;
13603 else
13604 protocol = ZEBRA_ROUTE_TABLE;
13605
13606 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13607 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13608 changed =
13609 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13610 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13611}
13612
13613ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
13614 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
13615 "redistribute <ospf|table> (1-65535) route-map WORD",
13616 "Redistribute information from another routing protocol\n"
13617 "Open Shortest Path First (OSPFv2)\n"
13618 "Non-main Kernel Routing Table\n"
13619 "Instance ID/Table ID\n"
13620 "Route map reference\n"
13621 "Pointer to route-map entries\n")
596c17ba 13622
7c8ff89e
DS
13623DEFUN (bgp_redistribute_ipv4_ospf_metric,
13624 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 13625 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
13626 "Redistribute information from another routing protocol\n"
13627 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13628 "Non-main Kernel Routing Table\n"
13629 "Instance ID/Table ID\n"
7c8ff89e
DS
13630 "Metric for redistributed routes\n"
13631 "Default metric\n")
13632{
d62a17ae 13633 VTY_DECLVAR_CONTEXT(bgp, bgp);
13634 int idx_ospf_table = 1;
13635 int idx_number = 2;
13636 int idx_number_2 = 4;
d7c0a89a 13637 uint32_t metric;
d62a17ae 13638 struct bgp_redist *red;
d7c0a89a 13639 unsigned short instance;
d62a17ae 13640 int protocol;
e923dd62 13641 bool changed;
d62a17ae 13642
13643 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13644 protocol = ZEBRA_ROUTE_OSPF;
13645 else
13646 protocol = ZEBRA_ROUTE_TABLE;
13647
13648 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13649 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13650
13651 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13652 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13653 metric);
13654 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13655}
13656
13657ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
13658 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
13659 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
13660 "Redistribute information from another routing protocol\n"
13661 "Open Shortest Path First (OSPFv2)\n"
13662 "Non-main Kernel Routing Table\n"
13663 "Instance ID/Table ID\n"
13664 "Metric for redistributed routes\n"
13665 "Default metric\n")
596c17ba 13666
7c8ff89e
DS
13667DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
13668 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 13669 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
13670 "Redistribute information from another routing protocol\n"
13671 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13672 "Non-main Kernel Routing Table\n"
13673 "Instance ID/Table ID\n"
7c8ff89e
DS
13674 "Route map reference\n"
13675 "Pointer to route-map entries\n"
13676 "Metric for redistributed routes\n"
13677 "Default metric\n")
13678{
d62a17ae 13679 VTY_DECLVAR_CONTEXT(bgp, bgp);
13680 int idx_ospf_table = 1;
13681 int idx_number = 2;
13682 int idx_word = 4;
13683 int idx_number_2 = 6;
d7c0a89a 13684 uint32_t metric;
d62a17ae 13685 struct bgp_redist *red;
d7c0a89a 13686 unsigned short instance;
d62a17ae 13687 int protocol;
e923dd62 13688 bool changed;
1de27621
DA
13689 struct route_map *route_map =
13690 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13691
13692 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13693 protocol = ZEBRA_ROUTE_OSPF;
13694 else
13695 protocol = ZEBRA_ROUTE_TABLE;
13696
13697 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13698 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13699
13700 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
13701 changed =
13702 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13703 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13704 metric);
13705 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13706}
13707
13708ALIAS_HIDDEN(
13709 bgp_redistribute_ipv4_ospf_rmap_metric,
13710 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
13711 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
13712 "Redistribute information from another routing protocol\n"
13713 "Open Shortest Path First (OSPFv2)\n"
13714 "Non-main Kernel Routing Table\n"
13715 "Instance ID/Table ID\n"
13716 "Route map reference\n"
13717 "Pointer to route-map entries\n"
13718 "Metric for redistributed routes\n"
13719 "Default metric\n")
596c17ba 13720
7c8ff89e
DS
13721DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
13722 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 13723 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
13724 "Redistribute information from another routing protocol\n"
13725 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
13726 "Non-main Kernel Routing Table\n"
13727 "Instance ID/Table ID\n"
7c8ff89e
DS
13728 "Metric for redistributed routes\n"
13729 "Default metric\n"
13730 "Route map reference\n"
13731 "Pointer to route-map entries\n")
13732{
d62a17ae 13733 VTY_DECLVAR_CONTEXT(bgp, bgp);
13734 int idx_ospf_table = 1;
13735 int idx_number = 2;
13736 int idx_number_2 = 4;
13737 int idx_word = 6;
d7c0a89a 13738 uint32_t metric;
d62a17ae 13739 struct bgp_redist *red;
d7c0a89a 13740 unsigned short instance;
d62a17ae 13741 int protocol;
e923dd62 13742 bool changed;
1de27621
DA
13743 struct route_map *route_map =
13744 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13745
13746 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13747 protocol = ZEBRA_ROUTE_OSPF;
13748 else
13749 protocol = ZEBRA_ROUTE_TABLE;
13750
13751 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13752 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
13753
13754 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 13755 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
13756 metric);
1de27621
DA
13757 changed |=
13758 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13759 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 13760}
13761
13762ALIAS_HIDDEN(
13763 bgp_redistribute_ipv4_ospf_metric_rmap,
13764 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
13765 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
13766 "Redistribute information from another routing protocol\n"
13767 "Open Shortest Path First (OSPFv2)\n"
13768 "Non-main Kernel Routing Table\n"
13769 "Instance ID/Table ID\n"
13770 "Metric for redistributed routes\n"
13771 "Default metric\n"
13772 "Route map reference\n"
13773 "Pointer to route-map entries\n")
596c17ba 13774
7c8ff89e
DS
13775DEFUN (no_bgp_redistribute_ipv4_ospf,
13776 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 13777 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
13778 NO_STR
13779 "Redistribute information from another routing protocol\n"
13780 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 13781 "Non-main Kernel Routing Table\n"
31500417
DW
13782 "Instance ID/Table ID\n"
13783 "Metric for redistributed routes\n"
13784 "Default metric\n"
13785 "Route map reference\n"
13786 "Pointer to route-map entries\n")
7c8ff89e 13787{
d62a17ae 13788 VTY_DECLVAR_CONTEXT(bgp, bgp);
13789 int idx_ospf_table = 2;
13790 int idx_number = 3;
d7c0a89a 13791 unsigned short instance;
d62a17ae 13792 int protocol;
13793
13794 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
13795 protocol = ZEBRA_ROUTE_OSPF;
13796 else
13797 protocol = ZEBRA_ROUTE_TABLE;
13798
13799 instance = strtoul(argv[idx_number]->arg, NULL, 10);
13800 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
13801}
13802
13803ALIAS_HIDDEN(
13804 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 13805 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13806 NO_STR
13807 "Redistribute information from another routing protocol\n"
13808 "Open Shortest Path First (OSPFv2)\n"
13809 "Non-main Kernel Routing Table\n"
13810 "Instance ID/Table ID\n"
13811 "Metric for redistributed routes\n"
13812 "Default metric\n"
13813 "Route map reference\n"
13814 "Pointer to route-map entries\n")
596c17ba 13815
718e3744 13816DEFUN (no_bgp_redistribute_ipv4,
13817 no_bgp_redistribute_ipv4_cmd,
e27957c0 13818 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 13819 NO_STR
13820 "Redistribute information from another routing protocol\n"
3b14d86e 13821 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
13822 "Metric for redistributed routes\n"
13823 "Default metric\n"
13824 "Route map reference\n"
13825 "Pointer to route-map entries\n")
718e3744 13826{
d62a17ae 13827 VTY_DECLVAR_CONTEXT(bgp, bgp);
13828 int idx_protocol = 2;
13829 int type;
13830
13831 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
13832 if (type < 0) {
13833 vty_out(vty, "%% Invalid route type\n");
13834 return CMD_WARNING_CONFIG_FAILED;
13835 }
13836 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
13837}
13838
13839ALIAS_HIDDEN(
13840 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
13841 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 13842 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 13843 NO_STR
13844 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
13845 "Metric for redistributed routes\n"
13846 "Default metric\n"
13847 "Route map reference\n"
13848 "Pointer to route-map entries\n")
596c17ba 13849
718e3744 13850DEFUN (bgp_redistribute_ipv6,
13851 bgp_redistribute_ipv6_cmd,
40d1cbfb 13852 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 13853 "Redistribute information from another routing protocol\n"
ab0181ee 13854 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 13855{
d62a17ae 13856 VTY_DECLVAR_CONTEXT(bgp, bgp);
13857 int idx_protocol = 1;
13858 int type;
718e3744 13859
d62a17ae 13860 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13861 if (type < 0) {
13862 vty_out(vty, "%% Invalid route type\n");
13863 return CMD_WARNING_CONFIG_FAILED;
13864 }
718e3744 13865
d62a17ae 13866 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13867 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 13868}
13869
13870DEFUN (bgp_redistribute_ipv6_rmap,
13871 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 13872 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 13873 "Redistribute information from another routing protocol\n"
ab0181ee 13874 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13875 "Route map reference\n"
13876 "Pointer to route-map entries\n")
13877{
d62a17ae 13878 VTY_DECLVAR_CONTEXT(bgp, bgp);
13879 int idx_protocol = 1;
13880 int idx_word = 3;
13881 int type;
13882 struct bgp_redist *red;
e923dd62 13883 bool changed;
1de27621
DA
13884 struct route_map *route_map =
13885 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 13886
d62a17ae 13887 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13888 if (type < 0) {
13889 vty_out(vty, "%% Invalid route type\n");
13890 return CMD_WARNING_CONFIG_FAILED;
13891 }
718e3744 13892
d62a17ae 13893 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13894 changed =
13895 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13896 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13897}
13898
13899DEFUN (bgp_redistribute_ipv6_metric,
13900 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 13901 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 13902 "Redistribute information from another routing protocol\n"
ab0181ee 13903 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13904 "Metric for redistributed routes\n"
13905 "Default metric\n")
13906{
d62a17ae 13907 VTY_DECLVAR_CONTEXT(bgp, bgp);
13908 int idx_protocol = 1;
13909 int idx_number = 3;
13910 int type;
d7c0a89a 13911 uint32_t metric;
d62a17ae 13912 struct bgp_redist *red;
e923dd62 13913 bool changed;
d62a17ae 13914
13915 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13916 if (type < 0) {
13917 vty_out(vty, "%% Invalid route type\n");
13918 return CMD_WARNING_CONFIG_FAILED;
13919 }
13920 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13921
d62a17ae 13922 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13923 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
13924 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13925}
13926
13927DEFUN (bgp_redistribute_ipv6_rmap_metric,
13928 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 13929 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 13930 "Redistribute information from another routing protocol\n"
ab0181ee 13931 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13932 "Route map reference\n"
13933 "Pointer to route-map entries\n"
13934 "Metric for redistributed routes\n"
13935 "Default metric\n")
13936{
d62a17ae 13937 VTY_DECLVAR_CONTEXT(bgp, bgp);
13938 int idx_protocol = 1;
13939 int idx_word = 3;
13940 int idx_number = 5;
13941 int type;
d7c0a89a 13942 uint32_t metric;
d62a17ae 13943 struct bgp_redist *red;
e923dd62 13944 bool changed;
1de27621
DA
13945 struct route_map *route_map =
13946 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13947
13948 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13949 if (type < 0) {
13950 vty_out(vty, "%% Invalid route type\n");
13951 return CMD_WARNING_CONFIG_FAILED;
13952 }
13953 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13954
d62a17ae 13955 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
13956 changed =
13957 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13958 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
13959 metric);
13960 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13961}
13962
13963DEFUN (bgp_redistribute_ipv6_metric_rmap,
13964 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 13965 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 13966 "Redistribute information from another routing protocol\n"
ab0181ee 13967 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 13968 "Metric for redistributed routes\n"
13969 "Default metric\n"
13970 "Route map reference\n"
13971 "Pointer to route-map entries\n")
13972{
d62a17ae 13973 VTY_DECLVAR_CONTEXT(bgp, bgp);
13974 int idx_protocol = 1;
13975 int idx_number = 3;
13976 int idx_word = 5;
13977 int type;
d7c0a89a 13978 uint32_t metric;
d62a17ae 13979 struct bgp_redist *red;
e923dd62 13980 bool changed;
1de27621
DA
13981 struct route_map *route_map =
13982 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 13983
13984 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
13985 if (type < 0) {
13986 vty_out(vty, "%% Invalid route type\n");
13987 return CMD_WARNING_CONFIG_FAILED;
13988 }
13989 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 13990
d62a17ae 13991 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 13992 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
13993 metric);
1de27621
DA
13994 changed |=
13995 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 13996 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 13997}
13998
13999DEFUN (no_bgp_redistribute_ipv6,
14000 no_bgp_redistribute_ipv6_cmd,
e27957c0 14001 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14002 NO_STR
14003 "Redistribute information from another routing protocol\n"
3b14d86e 14004 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14005 "Metric for redistributed routes\n"
14006 "Default metric\n"
14007 "Route map reference\n"
14008 "Pointer to route-map entries\n")
718e3744 14009{
d62a17ae 14010 VTY_DECLVAR_CONTEXT(bgp, bgp);
14011 int idx_protocol = 2;
14012 int type;
718e3744 14013
d62a17ae 14014 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14015 if (type < 0) {
14016 vty_out(vty, "%% Invalid route type\n");
14017 return CMD_WARNING_CONFIG_FAILED;
14018 }
718e3744 14019
d62a17ae 14020 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14021}
14022
dd65f45e
DL
14023static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14024 afi_t afi, safi_t safi)
d62a17ae 14025{
14026 int i;
14027
14028 /* Unicast redistribution only. */
14029 if (safi != SAFI_UNICAST)
2b791107 14030 return;
d62a17ae 14031
14032 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14033 /* Redistribute BGP does not make sense. */
14034 if (i != ZEBRA_ROUTE_BGP) {
14035 struct list *red_list;
14036 struct listnode *node;
14037 struct bgp_redist *red;
14038
14039 red_list = bgp->redist[afi][i];
14040 if (!red_list)
14041 continue;
14042
14043 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14044 /* "redistribute" configuration. */
14045 vty_out(vty, " redistribute %s",
14046 zebra_route_string(i));
14047 if (red->instance)
14048 vty_out(vty, " %d", red->instance);
14049 if (red->redist_metric_flag)
14050 vty_out(vty, " metric %u",
14051 red->redist_metric);
14052 if (red->rmap.name)
14053 vty_out(vty, " route-map %s",
14054 red->rmap.name);
14055 vty_out(vty, "\n");
14056 }
14057 }
14058 }
718e3744 14059}
6b0655a2 14060
dd65f45e
DL
14061/* peer-group helpers for config-write */
14062
14063static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14064{
14065 if (!peer_group_active(peer)) {
14066 if (CHECK_FLAG(peer->flags_invert, flag))
14067 return !CHECK_FLAG(peer->flags, flag);
14068 else
14069 return !!CHECK_FLAG(peer->flags, flag);
14070 }
14071
14072 return !!CHECK_FLAG(peer->flags_override, flag);
14073}
14074
14075static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14076 uint32_t flag)
14077{
14078 if (!peer_group_active(peer)) {
14079 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14080 return !peer_af_flag_check(peer, afi, safi, flag);
14081 else
14082 return !!peer_af_flag_check(peer, afi, safi, flag);
14083 }
14084
14085 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14086}
14087
14088static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14089 uint8_t type, int direct)
14090{
14091 struct bgp_filter *filter;
14092
14093 if (peer_group_active(peer))
14094 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14095 type);
14096
14097 filter = &peer->filter[afi][safi];
14098 switch (type) {
14099 case PEER_FT_DISTRIBUTE_LIST:
14100 return !!(filter->dlist[direct].name);
14101 case PEER_FT_FILTER_LIST:
14102 return !!(filter->aslist[direct].name);
14103 case PEER_FT_PREFIX_LIST:
14104 return !!(filter->plist[direct].name);
14105 case PEER_FT_ROUTE_MAP:
14106 return !!(filter->map[direct].name);
14107 case PEER_FT_UNSUPPRESS_MAP:
14108 return !!(filter->usmap.name);
14109 default:
14110 return false;
14111 }
14112}
14113
14114/* Return true if the addpath type is set for peer and different from
14115 * peer-group.
14116 */
14117static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi)
14118{
14119 enum bgp_addpath_strat type, g_type;
14120
14121 type = peer->addpath_type[afi][safi];
14122
14123 if (type != BGP_ADDPATH_NONE) {
14124 if (peer_group_active(peer)) {
14125 g_type = peer->group->conf->addpath_type[afi][safi];
14126
14127 if (type != g_type)
14128 return 1;
14129 else
14130 return 0;
14131 }
14132
14133 return 1;
14134 }
14135
14136 return 0;
14137}
14138
b9c7bc5a 14139/* This is part of the address-family block (unicast only) */
dd65f45e 14140static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
14141 afi_t afi)
14142{
b9c7bc5a 14143 int indent = 2;
ddb5b488 14144
8a066a70
PG
14145 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
14146 if (listcount(bgp->vpn_policy[afi].import_vrf))
14147 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
14148 bgp->vpn_policy[afi]
bb4f6190 14149 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
14150 else
14151 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
14152 bgp->vpn_policy[afi]
14153 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
14154 }
12a844a5
DS
14155 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14156 BGP_CONFIG_VRF_TO_VRF_IMPORT)
14157 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
14158 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14159 return;
14160
e70e9f8e
PZ
14161 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14162 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
14163
14164 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
14165
14166 } else {
14167 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
14168 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
14169 bgp->vpn_policy[afi].tovpn_label);
14170 }
ddb5b488
PZ
14171 }
14172 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14173 BGP_VPN_POLICY_TOVPN_RD_SET)) {
14174 char buf[RD_ADDRSTRLEN];
b9c7bc5a 14175 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
14176 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
14177 sizeof(buf)));
14178 }
14179 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
14180 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
14181
14182 char buf[PREFIX_STRLEN];
14183 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
14184 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
14185 sizeof(buf))) {
14186
b9c7bc5a
PZ
14187 vty_out(vty, "%*snexthop vpn export %s\n",
14188 indent, "", buf);
ddb5b488
PZ
14189 }
14190 }
14191 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
14192 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
14193 && ecommunity_cmp(
14194 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14195 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
14196
14197 char *b = ecommunity_ecom2str(
14198 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14199 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14200 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
14201 XFREE(MTYPE_ECOMMUNITY_STR, b);
14202 } else {
14203 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
14204 char *b = ecommunity_ecom2str(
14205 bgp->vpn_policy[afi]
14206 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
14207 ECOMMUNITY_FORMAT_ROUTE_MAP,
14208 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14209 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
14210 XFREE(MTYPE_ECOMMUNITY_STR, b);
14211 }
14212 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
14213 char *b = ecommunity_ecom2str(
14214 bgp->vpn_policy[afi]
14215 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
14216 ECOMMUNITY_FORMAT_ROUTE_MAP,
14217 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 14218 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
14219 XFREE(MTYPE_ECOMMUNITY_STR, b);
14220 }
14221 }
bb4f6190
DS
14222
14223 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 14224 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
14225 bgp->vpn_policy[afi]
14226 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 14227
301ad80a
PG
14228 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
14229 char *b = ecommunity_ecom2str(
14230 bgp->vpn_policy[afi]
14231 .import_redirect_rtlist,
14232 ECOMMUNITY_FORMAT_ROUTE_MAP,
14233 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 14234
301ad80a
PG
14235 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
14236 XFREE(MTYPE_ECOMMUNITY_STR, b);
14237 }
ddb5b488
PZ
14238}
14239
dd65f45e
DL
14240static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
14241 afi_t afi, safi_t safi)
14242{
14243 struct bgp_filter *filter;
14244 char *addr;
14245
14246 addr = peer->host;
14247 filter = &peer->filter[afi][safi];
14248
14249 /* distribute-list. */
14250 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14251 FILTER_IN))
14252 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
14253 filter->dlist[FILTER_IN].name);
14254
14255 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
14256 FILTER_OUT))
14257 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
14258 filter->dlist[FILTER_OUT].name);
14259
14260 /* prefix-list. */
14261 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14262 FILTER_IN))
14263 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
14264 filter->plist[FILTER_IN].name);
14265
14266 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
14267 FILTER_OUT))
14268 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
14269 filter->plist[FILTER_OUT].name);
14270
14271 /* route-map. */
14272 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
14273 vty_out(vty, " neighbor %s route-map %s in\n", addr,
14274 filter->map[RMAP_IN].name);
14275
14276 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
14277 RMAP_OUT))
14278 vty_out(vty, " neighbor %s route-map %s out\n", addr,
14279 filter->map[RMAP_OUT].name);
14280
14281 /* unsuppress-map */
14282 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
14283 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
14284 filter->usmap.name);
14285
14286 /* filter-list. */
14287 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14288 FILTER_IN))
14289 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
14290 filter->aslist[FILTER_IN].name);
14291
14292 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
14293 FILTER_OUT))
14294 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
14295 filter->aslist[FILTER_OUT].name);
14296}
14297
14298/* BGP peer configuration display function. */
14299static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
14300 struct peer *peer)
14301{
14302 struct peer *g_peer = NULL;
14303 char buf[SU_ADDRSTRLEN];
14304 char *addr;
14305 int if_pg_printed = false;
14306 int if_ras_printed = false;
14307
14308 /* Skip dynamic neighbors. */
14309 if (peer_dynamic_neighbor(peer))
14310 return;
14311
14312 if (peer->conf_if)
14313 addr = peer->conf_if;
14314 else
14315 addr = peer->host;
14316
14317 /************************************
14318 ****** Global to the neighbor ******
14319 ************************************/
14320 if (peer->conf_if) {
14321 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
14322 vty_out(vty, " neighbor %s interface v6only", addr);
14323 else
14324 vty_out(vty, " neighbor %s interface", addr);
14325
14326 if (peer_group_active(peer)) {
14327 vty_out(vty, " peer-group %s", peer->group->name);
14328 if_pg_printed = true;
14329 } else if (peer->as_type == AS_SPECIFIED) {
14330 vty_out(vty, " remote-as %u", peer->as);
14331 if_ras_printed = true;
14332 } else if (peer->as_type == AS_INTERNAL) {
14333 vty_out(vty, " remote-as internal");
14334 if_ras_printed = true;
14335 } else if (peer->as_type == AS_EXTERNAL) {
14336 vty_out(vty, " remote-as external");
14337 if_ras_printed = true;
14338 }
14339
14340 vty_out(vty, "\n");
14341 }
14342
14343 /* remote-as and peer-group */
14344 /* peer is a member of a peer-group */
14345 if (peer_group_active(peer)) {
14346 g_peer = peer->group->conf;
14347
14348 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
14349 if (peer->as_type == AS_SPECIFIED) {
14350 vty_out(vty, " neighbor %s remote-as %u\n",
14351 addr, peer->as);
14352 } else if (peer->as_type == AS_INTERNAL) {
14353 vty_out(vty,
14354 " neighbor %s remote-as internal\n",
14355 addr);
14356 } else if (peer->as_type == AS_EXTERNAL) {
14357 vty_out(vty,
14358 " neighbor %s remote-as external\n",
14359 addr);
14360 }
14361 }
14362
14363 /* For swpX peers we displayed the peer-group
14364 * via 'neighbor swpX interface peer-group PGNAME' */
14365 if (!if_pg_printed)
14366 vty_out(vty, " neighbor %s peer-group %s\n", addr,
14367 peer->group->name);
14368 }
14369
14370 /* peer is NOT a member of a peer-group */
14371 else {
14372 /* peer is a peer-group, declare the peer-group */
14373 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
14374 vty_out(vty, " neighbor %s peer-group\n", addr);
14375 }
14376
14377 if (!if_ras_printed) {
14378 if (peer->as_type == AS_SPECIFIED) {
14379 vty_out(vty, " neighbor %s remote-as %u\n",
14380 addr, peer->as);
14381 } else if (peer->as_type == AS_INTERNAL) {
14382 vty_out(vty,
14383 " neighbor %s remote-as internal\n",
14384 addr);
14385 } else if (peer->as_type == AS_EXTERNAL) {
14386 vty_out(vty,
14387 " neighbor %s remote-as external\n",
14388 addr);
14389 }
14390 }
14391 }
14392
14393 /* local-as */
14394 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
14395 vty_out(vty, " neighbor %s local-as %u", addr,
14396 peer->change_local_as);
14397 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
14398 vty_out(vty, " no-prepend");
14399 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
14400 vty_out(vty, " replace-as");
14401 vty_out(vty, "\n");
14402 }
14403
14404 /* description */
14405 if (peer->desc) {
14406 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
14407 }
14408
14409 /* shutdown */
14410 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
14411 if (peer->tx_shutdown_message)
14412 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
14413 peer->tx_shutdown_message);
14414 else
14415 vty_out(vty, " neighbor %s shutdown\n", addr);
14416 }
14417
14418 /* bfd */
14419 if (peer->bfd_info) {
14420 if (!peer_group_active(peer) || !g_peer->bfd_info) {
14421 bgp_bfd_peer_config_write(vty, peer, addr);
14422 }
14423 }
14424
14425 /* password */
14426 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
14427 vty_out(vty, " neighbor %s password %s\n", addr,
14428 peer->password);
14429
14430 /* neighbor solo */
14431 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
14432 if (!peer_group_active(peer)) {
14433 vty_out(vty, " neighbor %s solo\n", addr);
14434 }
14435 }
14436
14437 /* BGP port */
14438 if (peer->port != BGP_PORT_DEFAULT) {
14439 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
14440 }
14441
14442 /* Local interface name */
14443 if (peer->ifname) {
14444 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
14445 }
14446
14447 /* passive */
14448 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
14449 vty_out(vty, " neighbor %s passive\n", addr);
14450
14451 /* ebgp-multihop */
14452 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
14453 && !(peer->gtsm_hops != 0 && peer->ttl == MAXTTL)) {
14454 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
14455 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
14456 peer->ttl);
14457 }
14458 }
14459
14460 /* ttl-security hops */
14461 if (peer->gtsm_hops != 0) {
14462 if (!peer_group_active(peer)
14463 || g_peer->gtsm_hops != peer->gtsm_hops) {
14464 vty_out(vty, " neighbor %s ttl-security hops %d\n",
14465 addr, peer->gtsm_hops);
14466 }
14467 }
14468
14469 /* disable-connected-check */
14470 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
14471 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
14472
14473 /* enforce-first-as */
14474 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
14475 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
14476
14477 /* update-source */
14478 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
14479 if (peer->update_source)
14480 vty_out(vty, " neighbor %s update-source %s\n", addr,
14481 sockunion2str(peer->update_source, buf,
14482 SU_ADDRSTRLEN));
14483 else if (peer->update_if)
14484 vty_out(vty, " neighbor %s update-source %s\n", addr,
14485 peer->update_if);
14486 }
14487
14488 /* advertisement-interval */
14489 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
14490 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
14491 peer->routeadv);
14492
14493 /* timers */
14494 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
14495 vty_out(vty, " neighbor %s timers %u %u\n", addr,
14496 peer->keepalive, peer->holdtime);
14497
14498 /* timers connect */
14499 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
14500 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14501 peer->connect);
5d5393b9
DL
14502 /* need special-case handling for changed default values due to
14503 * config profile / version (because there is no "timers bgp connect"
14504 * command, we need to save this per-peer :/)
14505 */
14506 else if (!peer_group_active(peer) && !peer->connect &&
14507 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
14508 vty_out(vty, " neighbor %s timers connect %u\n", addr,
14509 peer->bgp->default_connect_retry);
dd65f45e
DL
14510
14511 /* capability dynamic */
14512 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
14513 vty_out(vty, " neighbor %s capability dynamic\n", addr);
14514
14515 /* capability extended-nexthop */
14516 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
14517 if (!peer->conf_if) {
14518 if (CHECK_FLAG(peer->flags_invert,
14519 PEER_FLAG_CAPABILITY_ENHE))
14520 vty_out(vty,
14521 " no neighbor %s capability extended-nexthop\n",
14522 addr);
14523 else
14524 vty_out(vty,
14525 " neighbor %s capability extended-nexthop\n",
14526 addr);
14527 }
14528 }
14529
14530 /* dont-capability-negotiation */
14531 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
14532 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
14533
14534 /* override-capability */
14535 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
14536 vty_out(vty, " neighbor %s override-capability\n", addr);
14537
14538 /* strict-capability-match */
14539 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
14540 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
14541
14542 /* Sender side AS path loop detection. */
14543 if (peer->as_path_loop_detection)
14544 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
14545 addr);
cfd47646 14546
14547 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14548 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 14549
14550 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 14551 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 14552 vty_out(vty,
14553 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
14554 } else if (CHECK_FLAG(
14555 peer->peer_gr_new_status_flag,
14556 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 14557 vty_out(vty,
14558 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
14559 } else if (
14560 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
14561 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
14562 && !(CHECK_FLAG(
14563 peer->peer_gr_new_status_flag,
14564 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
14565 vty_out(vty, " neighbor %s graceful-restart-disable\n",
14566 addr);
cfd47646 14567 }
14568 }
dd65f45e
DL
14569}
14570
14571/* BGP peer configuration display function. */
14572static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
14573 struct peer *peer, afi_t afi, safi_t safi)
14574{
14575 struct peer *g_peer = NULL;
14576 char *addr;
14577 bool flag_scomm, flag_secomm, flag_slcomm;
14578
14579 /* Skip dynamic neighbors. */
14580 if (peer_dynamic_neighbor(peer))
14581 return;
14582
14583 if (peer->conf_if)
14584 addr = peer->conf_if;
14585 else
14586 addr = peer->host;
14587
14588 /************************************
14589 ****** Per AF to the neighbor ******
14590 ************************************/
14591 if (peer_group_active(peer)) {
14592 g_peer = peer->group->conf;
14593
14594 /* If the peer-group is active but peer is not, print a 'no
14595 * activate' */
14596 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
14597 vty_out(vty, " no neighbor %s activate\n", addr);
14598 }
14599
14600 /* If the peer-group is not active but peer is, print an
14601 'activate' */
14602 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
14603 vty_out(vty, " neighbor %s activate\n", addr);
14604 }
14605 } else {
14606 if (peer->afc[afi][safi]) {
14607 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14608 if (CHECK_FLAG(bgp->flags,
14609 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14610 vty_out(vty, " neighbor %s activate\n",
14611 addr);
14612 }
14613 } else
14614 vty_out(vty, " neighbor %s activate\n", addr);
14615 } else {
14616 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
14617 if (!CHECK_FLAG(bgp->flags,
14618 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
14619 vty_out(vty,
14620 " no neighbor %s activate\n",
14621 addr);
14622 }
14623 }
14624 }
14625 }
14626
14627 /* addpath TX knobs */
14628 if (peergroup_af_addpath_check(peer, afi, safi)) {
14629 switch (peer->addpath_type[afi][safi]) {
14630 case BGP_ADDPATH_ALL:
14631 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
14632 addr);
14633 break;
14634 case BGP_ADDPATH_BEST_PER_AS:
14635 vty_out(vty,
14636 " neighbor %s addpath-tx-bestpath-per-AS\n",
14637 addr);
14638 break;
14639 case BGP_ADDPATH_MAX:
14640 case BGP_ADDPATH_NONE:
14641 break;
14642 }
14643 }
14644
14645 /* ORF capability. */
14646 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
14647 || peergroup_af_flag_check(peer, afi, safi,
14648 PEER_FLAG_ORF_PREFIX_RM)) {
14649 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
14650
14651 if (peergroup_af_flag_check(peer, afi, safi,
14652 PEER_FLAG_ORF_PREFIX_SM)
14653 && peergroup_af_flag_check(peer, afi, safi,
14654 PEER_FLAG_ORF_PREFIX_RM))
14655 vty_out(vty, " both");
14656 else if (peergroup_af_flag_check(peer, afi, safi,
14657 PEER_FLAG_ORF_PREFIX_SM))
14658 vty_out(vty, " send");
14659 else
14660 vty_out(vty, " receive");
14661 vty_out(vty, "\n");
14662 }
14663
14664 /* BGP flag dampening. */
14665 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14666 BGP_CONFIG_DAMPENING))
14667 bgp_config_write_damp(vty, afi, safi);
14668
14669 /* Route reflector client. */
14670 if (peergroup_af_flag_check(peer, afi, safi,
14671 PEER_FLAG_REFLECTOR_CLIENT)) {
14672 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
14673 }
14674
14675 /* next-hop-self force */
14676 if (peergroup_af_flag_check(peer, afi, safi,
14677 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
14678 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
14679 }
14680
14681 /* next-hop-self */
14682 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
14683 vty_out(vty, " neighbor %s next-hop-self\n", addr);
14684 }
14685
14686 /* remove-private-AS */
14687 if (peergroup_af_flag_check(peer, afi, safi,
14688 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
14689 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
14690 addr);
14691 }
14692
14693 else if (peergroup_af_flag_check(peer, afi, safi,
14694 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
14695 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
14696 addr);
14697 }
14698
14699 else if (peergroup_af_flag_check(peer, afi, safi,
14700 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
14701 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
14702 }
14703
14704 else if (peergroup_af_flag_check(peer, afi, safi,
14705 PEER_FLAG_REMOVE_PRIVATE_AS)) {
14706 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
14707 }
14708
14709 /* as-override */
14710 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
14711 vty_out(vty, " neighbor %s as-override\n", addr);
14712 }
14713
14714 /* send-community print. */
14715 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
14716 PEER_FLAG_SEND_COMMUNITY);
14717 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
14718 PEER_FLAG_SEND_EXT_COMMUNITY);
14719 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
14720 PEER_FLAG_SEND_LARGE_COMMUNITY);
14721
14722 if (flag_scomm && flag_secomm && flag_slcomm) {
14723 vty_out(vty, " no neighbor %s send-community all\n", addr);
14724 } else {
14725 if (flag_scomm)
14726 vty_out(vty, " no neighbor %s send-community\n", addr);
14727 if (flag_secomm)
14728 vty_out(vty,
14729 " no neighbor %s send-community extended\n",
14730 addr);
14731
14732 if (flag_slcomm)
14733 vty_out(vty, " no neighbor %s send-community large\n",
14734 addr);
14735 }
14736
14737 /* Default information */
14738 if (peergroup_af_flag_check(peer, afi, safi,
14739 PEER_FLAG_DEFAULT_ORIGINATE)) {
14740 vty_out(vty, " neighbor %s default-originate", addr);
14741
14742 if (peer->default_rmap[afi][safi].name)
14743 vty_out(vty, " route-map %s",
14744 peer->default_rmap[afi][safi].name);
14745
14746 vty_out(vty, "\n");
14747 }
14748
14749 /* Soft reconfiguration inbound. */
14750 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
14751 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
14752 addr);
14753 }
14754
14755 /* maximum-prefix. */
14756 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
14757 vty_out(vty, " neighbor %s maximum-prefix %" PRIu32, addr,
14758 peer->pmax[afi][safi]);
14759
14760 if (peer->pmax_threshold[afi][safi]
14761 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
14762 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
14763 if (peer_af_flag_check(peer, afi, safi,
14764 PEER_FLAG_MAX_PREFIX_WARNING))
14765 vty_out(vty, " warning-only");
14766 if (peer->pmax_restart[afi][safi])
14767 vty_out(vty, " restart %u",
14768 peer->pmax_restart[afi][safi]);
14769
14770 vty_out(vty, "\n");
14771 }
14772
fde246e8
DA
14773 /* maximum-prefix-out */
14774 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
14775 vty_out(vty, " neighbor %s maximum-prefix-out %" PRIu32 "\n",
14776 addr, peer->pmax_out[afi][safi]);
14777
dd65f45e
DL
14778 /* Route server client. */
14779 if (peergroup_af_flag_check(peer, afi, safi,
14780 PEER_FLAG_RSERVER_CLIENT)) {
14781 vty_out(vty, " neighbor %s route-server-client\n", addr);
14782 }
14783
14784 /* Nexthop-local unchanged. */
14785 if (peergroup_af_flag_check(peer, afi, safi,
14786 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
14787 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
14788 }
14789
14790 /* allowas-in <1-10> */
14791 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
14792 if (peer_af_flag_check(peer, afi, safi,
14793 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
14794 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
14795 } else if (peer->allowas_in[afi][safi] == 3) {
14796 vty_out(vty, " neighbor %s allowas-in\n", addr);
14797 } else {
14798 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
14799 peer->allowas_in[afi][safi]);
14800 }
14801 }
14802
14803 /* weight */
14804 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
14805 vty_out(vty, " neighbor %s weight %lu\n", addr,
14806 peer->weight[afi][safi]);
14807
14808 /* Filter. */
14809 bgp_config_write_filter(vty, peer, afi, safi);
14810
14811 /* atribute-unchanged. */
14812 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
14813 || (safi != SAFI_EVPN
14814 && peer_af_flag_check(peer, afi, safi,
14815 PEER_FLAG_NEXTHOP_UNCHANGED))
14816 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
14817
14818 if (!peer_group_active(peer)
14819 || peergroup_af_flag_check(peer, afi, safi,
14820 PEER_FLAG_AS_PATH_UNCHANGED)
14821 || peergroup_af_flag_check(peer, afi, safi,
14822 PEER_FLAG_NEXTHOP_UNCHANGED)
14823 || peergroup_af_flag_check(peer, afi, safi,
14824 PEER_FLAG_MED_UNCHANGED)) {
14825
14826 vty_out(vty,
14827 " neighbor %s attribute-unchanged%s%s%s\n",
14828 addr,
14829 peer_af_flag_check(peer, afi, safi,
14830 PEER_FLAG_AS_PATH_UNCHANGED)
14831 ? " as-path"
14832 : "",
14833 peer_af_flag_check(peer, afi, safi,
14834 PEER_FLAG_NEXTHOP_UNCHANGED)
14835 ? " next-hop"
14836 : "",
14837 peer_af_flag_check(peer, afi, safi,
14838 PEER_FLAG_MED_UNCHANGED)
14839 ? " med"
14840 : "");
14841 }
14842 }
14843}
14844
14845/* Address family based peer configuration display. */
14846static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
14847 safi_t safi)
14848{
14849 struct peer *peer;
14850 struct peer_group *group;
14851 struct listnode *node, *nnode;
14852
14853
14854 vty_frame(vty, " !\n address-family ");
14855 if (afi == AFI_IP) {
14856 if (safi == SAFI_UNICAST)
14857 vty_frame(vty, "ipv4 unicast");
14858 else if (safi == SAFI_LABELED_UNICAST)
14859 vty_frame(vty, "ipv4 labeled-unicast");
14860 else if (safi == SAFI_MULTICAST)
14861 vty_frame(vty, "ipv4 multicast");
14862 else if (safi == SAFI_MPLS_VPN)
14863 vty_frame(vty, "ipv4 vpn");
14864 else if (safi == SAFI_ENCAP)
14865 vty_frame(vty, "ipv4 encap");
14866 else if (safi == SAFI_FLOWSPEC)
14867 vty_frame(vty, "ipv4 flowspec");
14868 } else if (afi == AFI_IP6) {
14869 if (safi == SAFI_UNICAST)
14870 vty_frame(vty, "ipv6 unicast");
14871 else if (safi == SAFI_LABELED_UNICAST)
14872 vty_frame(vty, "ipv6 labeled-unicast");
14873 else if (safi == SAFI_MULTICAST)
14874 vty_frame(vty, "ipv6 multicast");
14875 else if (safi == SAFI_MPLS_VPN)
14876 vty_frame(vty, "ipv6 vpn");
14877 else if (safi == SAFI_ENCAP)
14878 vty_frame(vty, "ipv6 encap");
14879 else if (safi == SAFI_FLOWSPEC)
14880 vty_frame(vty, "ipv6 flowspec");
14881 } else if (afi == AFI_L2VPN) {
14882 if (safi == SAFI_EVPN)
14883 vty_frame(vty, "l2vpn evpn");
14884 }
14885 vty_frame(vty, "\n");
14886
14887 bgp_config_write_distance(vty, bgp, afi, safi);
14888
14889 bgp_config_write_network(vty, bgp, afi, safi);
14890
14891 bgp_config_write_redistribute(vty, bgp, afi, safi);
14892
14893 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
14894 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
14895
14896 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14897 /* Skip dynamic neighbors. */
14898 if (peer_dynamic_neighbor(peer))
14899 continue;
14900
14901 /* Do not display doppelganger peers */
14902 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14903 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
14904 }
14905
14906 bgp_config_write_maxpaths(vty, bgp, afi, safi);
14907 bgp_config_write_table_map(vty, bgp, afi, safi);
14908
14909 if (safi == SAFI_EVPN)
14910 bgp_config_write_evpn_info(vty, bgp, afi, safi);
14911
14912 if (safi == SAFI_FLOWSPEC)
14913 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
14914
14915 if (safi == SAFI_UNICAST) {
14916 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
14917 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14918 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
14919
14920 vty_out(vty, " export vpn\n");
14921 }
14922 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14923 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
14924
14925 vty_out(vty, " import vpn\n");
14926 }
14927 if (CHECK_FLAG(bgp->af_flags[afi][safi],
14928 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14929 char *name;
14930
14931 for (ALL_LIST_ELEMENTS_RO(
14932 bgp->vpn_policy[afi].import_vrf, node,
14933 name))
14934 vty_out(vty, " import vrf %s\n", name);
14935 }
14936 }
14937
14938 vty_endframe(vty, " exit-address-family\n");
14939}
14940
14941int bgp_config_write(struct vty *vty)
14942{
14943 struct bgp *bgp;
14944 struct peer_group *group;
14945 struct peer *peer;
14946 struct listnode *node, *nnode;
14947 struct listnode *mnode, *mnnode;
14948
14949 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
14950 vty_out(vty, "bgp route-map delay-timer %u\n",
14951 bm->rmap_update_timer);
14952
14953 /* BGP configuration. */
14954 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
14955
14956 /* skip all auto created vrf as they dont have user config */
14957 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
14958 continue;
14959
14960 /* Router bgp ASN */
14961 vty_out(vty, "router bgp %u", bgp->as);
14962
14963 if (bgp->name)
14964 vty_out(vty, " %s %s",
14965 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
14966 ? "view" : "vrf", bgp->name);
14967 vty_out(vty, "\n");
14968
14969 /* BGP fast-external-failover. */
14970 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
14971 vty_out(vty, " no bgp fast-external-failover\n");
14972
14973 /* BGP router ID. */
14974 if (bgp->router_id_static.s_addr != 0)
14975 vty_out(vty, " bgp router-id %s\n",
14976 inet_ntoa(bgp->router_id_static));
14977
14978 /* BGP log-neighbor-changes. */
892fedb6 14979 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 14980 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 14981 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
14982 CHECK_FLAG(bgp->flags,
14983 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
14984 ? ""
14985 : "no ");
14986
14987 /* BGP configuration. */
892fedb6 14988 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
14989 vty_out(vty, " bgp always-compare-med\n");
14990
14991 /* RFC8212 default eBGP policy. */
14992 if (bgp->ebgp_requires_policy
14993 == DEFAULT_EBGP_POLICY_ENABLED)
14994 vty_out(vty, " bgp ebgp-requires-policy\n");
14995
14996 /* draft-ietf-idr-deprecate-as-set-confed-set */
14997 if (bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED)
14998 vty_out(vty, " bgp reject-as-sets\n");
14999
15000 /* BGP default ipv4-unicast. */
892fedb6 15001 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15002 vty_out(vty, " no bgp default ipv4-unicast\n");
15003
15004 /* BGP default local-preference. */
15005 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15006 vty_out(vty, " bgp default local-preference %u\n",
15007 bgp->default_local_pref);
15008
15009 /* BGP default show-hostname */
892fedb6 15010 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15011 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15012 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15013 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15014 ? ""
15015 : "no ");
15016
15017 /* BGP default subgroup-pkt-queue-max. */
15018 if (bgp->default_subgroup_pkt_queue_max
15019 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15020 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15021 bgp->default_subgroup_pkt_queue_max);
15022
15023 /* BGP client-to-client reflection. */
892fedb6 15024 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15025 vty_out(vty, " no bgp client-to-client reflection\n");
15026
15027 /* BGP cluster ID. */
15028 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15029 vty_out(vty, " bgp cluster-id %s\n",
15030 inet_ntoa(bgp->cluster_id));
15031
15032 /* Disable ebgp connected nexthop check */
892fedb6 15033 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15034 vty_out(vty,
15035 " bgp disable-ebgp-connected-route-check\n");
15036
15037 /* Confederation identifier*/
15038 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15039 vty_out(vty, " bgp confederation identifier %u\n",
15040 bgp->confed_id);
15041
15042 /* Confederation peer */
15043 if (bgp->confed_peers_cnt > 0) {
15044 int i;
15045
15046 vty_out(vty, " bgp confederation peers");
15047
15048 for (i = 0; i < bgp->confed_peers_cnt; i++)
15049 vty_out(vty, " %u", bgp->confed_peers[i]);
15050
15051 vty_out(vty, "\n");
15052 }
15053
15054 /* BGP deterministic-med. */
892fedb6 15055 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15056 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15057 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15058 CHECK_FLAG(bgp->flags,
15059 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15060 ? ""
15061 : "no ");
15062
15063 /* BGP update-delay. */
15064 bgp_config_write_update_delay(vty, bgp);
15065
15066 if (bgp->v_maxmed_onstartup
15067 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
15068 vty_out(vty, " bgp max-med on-startup %u",
15069 bgp->v_maxmed_onstartup);
15070 if (bgp->maxmed_onstartup_value
15071 != BGP_MAXMED_VALUE_DEFAULT)
15072 vty_out(vty, " %u",
15073 bgp->maxmed_onstartup_value);
15074 vty_out(vty, "\n");
15075 }
15076 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
15077 vty_out(vty, " bgp max-med administrative");
15078 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
15079 vty_out(vty, " %u", bgp->maxmed_admin_value);
15080 vty_out(vty, "\n");
15081 }
15082
15083 /* write quanta */
15084 bgp_config_write_wpkt_quanta(vty, bgp);
15085 /* read quanta */
15086 bgp_config_write_rpkt_quanta(vty, bgp);
15087
15088 /* coalesce time */
15089 bgp_config_write_coalesce_time(vty, bgp);
15090
15091 /* BGP graceful-restart. */
15092 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
15093 vty_out(vty,
15094 " bgp graceful-restart stalepath-time %u\n",
15095 bgp->stalepath_time);
cfd47646 15096
dd65f45e
DL
15097 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
15098 vty_out(vty, " bgp graceful-restart restart-time %u\n",
15099 bgp->restart_time);
cfd47646 15100
15101 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
15102 vty_out(vty,
15103 " bgp graceful-restart select-defer-time %u\n",
15104 bgp->select_defer_time);
15105
15106 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
15107 vty_out(vty, " bgp graceful-restart\n");
15108
cfd47646 15109 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
15110 vty_out(vty, " bgp graceful-restart-disable\n");
15111
dd65f45e 15112 /* BGP graceful-shutdown */
892fedb6 15113 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
dd65f45e
DL
15114 vty_out(vty, " bgp graceful-shutdown\n");
15115
15116 /* BGP graceful-restart Preserve State F bit. */
892fedb6 15117 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
15118 vty_out(vty,
15119 " bgp graceful-restart preserve-fw-state\n");
15120
dc95985f 15121 /* Stale timer for RIB */
15122 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
15123 vty_out(vty,
15124 " bgp graceful-restart rib-stale-time %u\n",
15125 bgp->rib_stale_time);
15126
dd65f45e 15127 /* BGP bestpath method. */
892fedb6 15128 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 15129 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 15130 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
15131 vty_out(vty, " bgp bestpath as-path confed\n");
15132
892fedb6
DA
15133 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
15134 if (CHECK_FLAG(bgp->flags,
15135 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
15136 vty_out(vty,
15137 " bgp bestpath as-path multipath-relax as-set\n");
15138 } else {
15139 vty_out(vty,
15140 " bgp bestpath as-path multipath-relax\n");
15141 }
15142 }
15143
892fedb6 15144 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
15145 vty_out(vty,
15146 " bgp route-reflector allow-outbound-policy\n");
15147 }
892fedb6 15148 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 15149 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
15150 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
15151 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 15152 vty_out(vty, " bgp bestpath med");
892fedb6 15153 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 15154 vty_out(vty, " confed");
892fedb6
DA
15155 if (CHECK_FLAG(bgp->flags,
15156 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
15157 vty_out(vty, " missing-as-worst");
15158 vty_out(vty, "\n");
15159 }
15160
15161 /* BGP network import check. */
892fedb6 15162 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 15163 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 15164 vty_out(vty, " %sbgp network import-check\n",
892fedb6 15165 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
15166 ? ""
15167 : "no ");
15168
15169 /* BGP timers configuration. */
5d5393b9
DL
15170 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
15171 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
15172 vty_out(vty, " timers bgp %u %u\n",
15173 bgp->default_keepalive, bgp->default_holdtime);
15174
15175 /* peer-group */
15176 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15177 bgp_config_write_peer_global(vty, bgp, group->conf);
15178 }
15179
15180 /* Normal neighbor configuration. */
15181 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15182 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15183 bgp_config_write_peer_global(vty, bgp, peer);
15184 }
15185
15186 /* listen range and limit for dynamic BGP neighbors */
15187 bgp_config_write_listen(vty, bgp);
15188
15189 /*
15190 * BGP default autoshutdown neighbors
15191 *
15192 * This must be placed after any peer and peer-group
15193 * configuration, to avoid setting all peers to shutdown after
15194 * a daemon restart, which is undesired behavior. (see #2286)
15195 */
15196 if (bgp->autoshutdown)
15197 vty_out(vty, " bgp default shutdown\n");
15198
15199 /* IPv4 unicast configuration. */
15200 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
15201
15202 /* IPv4 multicast configuration. */
15203 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
15204
15205 /* IPv4 labeled-unicast configuration. */
15206 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
15207
15208 /* IPv4 VPN configuration. */
15209 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
15210
15211 /* ENCAPv4 configuration. */
15212 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
15213
15214 /* FLOWSPEC v4 configuration. */
15215 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
15216
15217 /* IPv6 unicast configuration. */
15218 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
15219
15220 /* IPv6 multicast configuration. */
15221 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
15222
15223 /* IPv6 labeled-unicast configuration. */
15224 bgp_config_write_family(vty, bgp, AFI_IP6,
15225 SAFI_LABELED_UNICAST);
15226
15227 /* IPv6 VPN configuration. */
15228 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
15229
15230 /* ENCAPv6 configuration. */
15231 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
15232
15233 /* FLOWSPEC v6 configuration. */
15234 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
15235
15236 /* EVPN configuration. */
15237 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
15238
15239 hook_call(bgp_inst_config_write, bgp, vty);
15240
15241#if ENABLE_BGP_VNC
15242 bgp_rfapi_cfg_write(vty, bgp);
15243#endif
15244
15245 vty_out(vty, "!\n");
15246 }
15247 return 0;
15248}
15249
ddb5b488 15250
718e3744 15251/* BGP node structure. */
d62a17ae 15252static struct cmd_node bgp_node = {
9d303b37 15253 BGP_NODE, "%s(config-router)# ", 1,
718e3744 15254};
15255
d62a17ae 15256static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 15257 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 15258};
15259
d62a17ae 15260static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 15261 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 15262};
15263
d62a17ae 15264static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 15265 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15266};
15267
d62a17ae 15268static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 15269 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 15270};
15271
d62a17ae 15272static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 15273 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 15274};
15275
d62a17ae 15276static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 15277 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
15278};
15279
d62a17ae 15280static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
15281 "%s(config-router-af)# ", 1};
6b0655a2 15282
d62a17ae 15283static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
15284 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 15285
d62a17ae 15286static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
15287 "%s(config-router-evpn)# ", 1};
4e0b7b6d 15288
d62a17ae 15289static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
15290 "%s(config-router-af-vni)# ", 1};
90e60aa7 15291
7c40bf39 15292static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
15293 "%s(config-router-af)# ", 1};
15294
15295static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
15296 "%s(config-router-af-vpnv6)# ", 1};
15297
d62a17ae 15298static void community_list_vty(void);
1f8ae70b 15299
d62a17ae 15300static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 15301{
d62a17ae 15302 struct bgp *bgp;
15303 struct peer *peer;
d62a17ae 15304 struct listnode *lnbgp, *lnpeer;
b8a815e5 15305
d62a17ae 15306 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15307 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
15308 /* only provide suggestions on the appropriate input
15309 * token type,
15310 * they'll otherwise show up multiple times */
15311 enum cmd_token_type match_type;
15312 char *name = peer->host;
d48ed3e0 15313
d62a17ae 15314 if (peer->conf_if) {
15315 match_type = VARIABLE_TKN;
15316 name = peer->conf_if;
15317 } else if (strchr(peer->host, ':'))
15318 match_type = IPV6_TKN;
15319 else
15320 match_type = IPV4_TKN;
d48ed3e0 15321
d62a17ae 15322 if (token->type != match_type)
15323 continue;
d48ed3e0 15324
d62a17ae 15325 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
15326 }
d62a17ae 15327 }
b8a815e5
DL
15328}
15329
15330static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 15331 {.varname = "neighbor", .completions = bgp_ac_neighbor},
15332 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 15333 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 15334 {.completions = NULL}};
15335
47a306a0
DS
15336static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
15337{
15338 struct bgp *bgp;
15339 struct peer_group *group;
15340 struct listnode *lnbgp, *lnpeer;
15341
15342 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
15343 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
15344 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
15345 group->name));
15346 }
15347}
15348
15349static const struct cmd_variable_handler bgp_var_peergroup[] = {
15350 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
15351 {.completions = NULL} };
15352
d62a17ae 15353void bgp_vty_init(void)
15354{
15355 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 15356 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 15357
15358 /* Install bgp top node. */
15359 install_node(&bgp_node, bgp_config_write);
15360 install_node(&bgp_ipv4_unicast_node, NULL);
15361 install_node(&bgp_ipv4_multicast_node, NULL);
15362 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
15363 install_node(&bgp_ipv6_unicast_node, NULL);
15364 install_node(&bgp_ipv6_multicast_node, NULL);
15365 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
15366 install_node(&bgp_vpnv4_node, NULL);
15367 install_node(&bgp_vpnv6_node, NULL);
15368 install_node(&bgp_evpn_node, NULL);
15369 install_node(&bgp_evpn_vni_node, NULL);
7c40bf39 15370 install_node(&bgp_flowspecv4_node, NULL);
15371 install_node(&bgp_flowspecv6_node, NULL);
d62a17ae 15372
15373 /* Install default VTY commands to new nodes. */
15374 install_default(BGP_NODE);
15375 install_default(BGP_IPV4_NODE);
15376 install_default(BGP_IPV4M_NODE);
15377 install_default(BGP_IPV4L_NODE);
15378 install_default(BGP_IPV6_NODE);
15379 install_default(BGP_IPV6M_NODE);
15380 install_default(BGP_IPV6L_NODE);
15381 install_default(BGP_VPNV4_NODE);
15382 install_default(BGP_VPNV6_NODE);
7c40bf39 15383 install_default(BGP_FLOWSPECV4_NODE);
15384 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 15385 install_default(BGP_EVPN_NODE);
15386 install_default(BGP_EVPN_VNI_NODE);
15387
8029b216
AK
15388 /* "bgp local-mac" hidden commands. */
15389 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
15390 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
15391
d62a17ae 15392 /* bgp route-map delay-timer commands. */
15393 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
15394 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15395
15396 /* Dummy commands (Currently not supported) */
15397 install_element(BGP_NODE, &no_synchronization_cmd);
15398 install_element(BGP_NODE, &no_auto_summary_cmd);
15399
15400 /* "router bgp" commands. */
15401 install_element(CONFIG_NODE, &router_bgp_cmd);
15402
15403 /* "no router bgp" commands. */
15404 install_element(CONFIG_NODE, &no_router_bgp_cmd);
15405
15406 /* "bgp router-id" commands. */
15407 install_element(BGP_NODE, &bgp_router_id_cmd);
15408 install_element(BGP_NODE, &no_bgp_router_id_cmd);
15409
15410 /* "bgp cluster-id" commands. */
15411 install_element(BGP_NODE, &bgp_cluster_id_cmd);
15412 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
15413
15414 /* "bgp confederation" commands. */
15415 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
15416 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
15417
15418 /* "bgp confederation peers" commands. */
15419 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
15420 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
15421
15422 /* bgp max-med command */
15423 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
15424 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
15425 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
15426 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
15427 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
15428
15429 /* bgp disable-ebgp-connected-nh-check */
15430 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
15431 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
15432
15433 /* bgp update-delay command */
15434 install_element(BGP_NODE, &bgp_update_delay_cmd);
15435 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
15436 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
15437
15438 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 15439 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 15440
15441 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
15442 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
15443
15444 /* "maximum-paths" commands. */
15445 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
15446 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
15447 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
15448 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
15449 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
15450 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
15451 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
15452 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
15453 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
15454 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
15455 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15456 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
15457 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
15458 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15459 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
15460
15461 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
15462 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
15463 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
15464 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
15465 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
15466
15467 /* "timers bgp" commands. */
15468 install_element(BGP_NODE, &bgp_timers_cmd);
15469 install_element(BGP_NODE, &no_bgp_timers_cmd);
15470
15471 /* route-map delay-timer commands - per instance for backwards compat.
15472 */
15473 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
15474 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
15475
15476 /* "bgp client-to-client reflection" commands */
15477 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
15478 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
15479
15480 /* "bgp always-compare-med" commands */
15481 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
15482 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
15483
9dac9fc8
DA
15484 /* bgp ebgp-requires-policy */
15485 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
15486 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
15487
fb29348a
DA
15488 /* bgp reject-as-sets */
15489 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
15490 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
15491
d62a17ae 15492 /* "bgp deterministic-med" commands */
15493 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
15494 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
15495
055679e9 15496 /* "bgp graceful-restart" command */
36235319
QY
15497 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
15498 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 15499
15500 /* "bgp graceful-restart-disable" command */
36235319
QY
15501 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
15502 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 15503
15504 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
15505 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
15506 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 15507
15508 /* "neighbor a:b:c:d graceful-restart-disable" command */
15509 install_element(BGP_NODE,
15510 &bgp_neighbor_graceful_restart_disable_set_cmd);
15511 install_element(BGP_NODE,
15512 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
15513
15514 /* "neighbor a:b:c:d graceful-restart-helper" command */
15515 install_element(BGP_NODE,
15516 &bgp_neighbor_graceful_restart_helper_set_cmd);
15517 install_element(BGP_NODE,
15518 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
15519
d62a17ae 15520 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
15521 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
15522 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
15523 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 15524 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 15525 install_element(BGP_NODE,
15526 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 15527 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
15528 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
15529
d6e3c15b 15530 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
15531 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 15532 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
15533 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 15534
7f323236
DW
15535 /* "bgp graceful-shutdown" commands */
15536 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
15537 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
15538
d62a17ae 15539 /* "bgp fast-external-failover" commands */
15540 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
15541 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
15542
d62a17ae 15543 /* "bgp bestpath compare-routerid" commands */
15544 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
15545 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
15546
15547 /* "bgp bestpath as-path ignore" commands */
15548 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
15549 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
15550
15551 /* "bgp bestpath as-path confed" commands */
15552 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
15553 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
15554
15555 /* "bgp bestpath as-path multipath-relax" commands */
15556 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
15557 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
15558
15559 /* "bgp log-neighbor-changes" commands */
15560 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
15561 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
15562
15563 /* "bgp bestpath med" commands */
15564 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
15565 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
15566
15567 /* "no bgp default ipv4-unicast" commands. */
15568 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
15569 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
15570
15571 /* "bgp network import-check" commands. */
15572 install_element(BGP_NODE, &bgp_network_import_check_cmd);
15573 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
15574 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
15575
15576 /* "bgp default local-preference" commands. */
15577 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
15578 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
15579
15580 /* bgp default show-hostname */
15581 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
15582 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
15583
15584 /* "bgp default subgroup-pkt-queue-max" commands. */
15585 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
15586 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
15587
15588 /* bgp ibgp-allow-policy-mods command */
15589 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
15590 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
15591
15592 /* "bgp listen limit" commands. */
15593 install_element(BGP_NODE, &bgp_listen_limit_cmd);
15594 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
15595
15596 /* "bgp listen range" commands. */
15597 install_element(BGP_NODE, &bgp_listen_range_cmd);
15598 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
15599
8175f54a 15600 /* "bgp default shutdown" command */
f26845f9
QY
15601 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
15602
d62a17ae 15603 /* "neighbor remote-as" commands. */
15604 install_element(BGP_NODE, &neighbor_remote_as_cmd);
15605 install_element(BGP_NODE, &neighbor_interface_config_cmd);
15606 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
15607 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
15608 install_element(BGP_NODE,
15609 &neighbor_interface_v6only_config_remote_as_cmd);
15610 install_element(BGP_NODE, &no_neighbor_cmd);
15611 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
15612
15613 /* "neighbor peer-group" commands. */
15614 install_element(BGP_NODE, &neighbor_peer_group_cmd);
15615 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
15616 install_element(BGP_NODE,
15617 &no_neighbor_interface_peer_group_remote_as_cmd);
15618
15619 /* "neighbor local-as" commands. */
15620 install_element(BGP_NODE, &neighbor_local_as_cmd);
15621 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
15622 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
15623 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
15624
15625 /* "neighbor solo" commands. */
15626 install_element(BGP_NODE, &neighbor_solo_cmd);
15627 install_element(BGP_NODE, &no_neighbor_solo_cmd);
15628
15629 /* "neighbor password" commands. */
15630 install_element(BGP_NODE, &neighbor_password_cmd);
15631 install_element(BGP_NODE, &no_neighbor_password_cmd);
15632
15633 /* "neighbor activate" commands. */
15634 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
15635 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
15636 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
15637 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
15638 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
15639 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
15640 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
15641 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
15642 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 15643 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
15644 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 15645 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
15646
15647 /* "no neighbor activate" commands. */
15648 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
15649 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
15650 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
15651 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
15652 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
15653 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
15654 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
15655 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
15656 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 15657 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
15658 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 15659 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
15660
15661 /* "neighbor peer-group" set commands. */
15662 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
15663 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15664 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
15665 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
15666 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
15667 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
15668 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
15669 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 15670 install_element(BGP_FLOWSPECV4_NODE,
15671 &neighbor_set_peer_group_hidden_cmd);
15672 install_element(BGP_FLOWSPECV6_NODE,
15673 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 15674
15675 /* "no neighbor peer-group unset" commands. */
15676 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
15677 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15678 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15679 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15680 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15681 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15682 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
15683 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 15684 install_element(BGP_FLOWSPECV4_NODE,
15685 &no_neighbor_set_peer_group_hidden_cmd);
15686 install_element(BGP_FLOWSPECV6_NODE,
15687 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 15688
15689 /* "neighbor softreconfiguration inbound" commands.*/
15690 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
15691 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
15692 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
15693 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15694 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
15695 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15696 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
15697 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15698 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
15699 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
15700 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
15701 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
15702 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
15703 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
15704 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
15705 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
15706 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
15707 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 15708 install_element(BGP_FLOWSPECV4_NODE,
15709 &neighbor_soft_reconfiguration_cmd);
15710 install_element(BGP_FLOWSPECV4_NODE,
15711 &no_neighbor_soft_reconfiguration_cmd);
15712 install_element(BGP_FLOWSPECV6_NODE,
15713 &neighbor_soft_reconfiguration_cmd);
15714 install_element(BGP_FLOWSPECV6_NODE,
15715 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
15716 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
15717 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 15718
15719 /* "neighbor attribute-unchanged" commands. */
15720 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
15721 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
15722 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
15723 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
15724 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
15725 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
15726 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
15727 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
15728 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
15729 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
15730 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
15731 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
15732 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
15733 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
15734 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
15735 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
15736 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
15737 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
15738
15739 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
15740 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
15741
15742 /* "nexthop-local unchanged" commands */
15743 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
15744 install_element(BGP_IPV6_NODE,
15745 &no_neighbor_nexthop_local_unchanged_cmd);
15746
15747 /* "neighbor next-hop-self" commands. */
15748 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
15749 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
15750 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
15751 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
15752 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
15753 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
15754 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
15755 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
15756 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
15757 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
15758 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
15759 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
15760 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
15761 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
15762 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
15763 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
15764 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
15765 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
15766 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
15767 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 15768
15769 /* "neighbor next-hop-self force" commands. */
15770 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
15771 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
15772 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15773 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15774 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
15775 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15776 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15777 install_element(BGP_IPV4_NODE,
15778 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15779 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
15780 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15781 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15782 install_element(BGP_IPV4M_NODE,
15783 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15784 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
15785 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15786 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15787 install_element(BGP_IPV4L_NODE,
15788 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15789 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
15790 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15791 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15792 install_element(BGP_IPV6_NODE,
15793 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15794 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
15795 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15796 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15797 install_element(BGP_IPV6M_NODE,
15798 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15799 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
15800 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15801 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15802 install_element(BGP_IPV6L_NODE,
15803 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15804 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
15805 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15806 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15807 install_element(BGP_VPNV4_NODE,
15808 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15809 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
15810 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
15811 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
15812 install_element(BGP_VPNV6_NODE,
15813 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 15814
15815 /* "neighbor as-override" commands. */
15816 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
15817 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
15818 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
15819 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
15820 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
15821 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
15822 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
15823 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
15824 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
15825 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
15826 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
15827 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
15828 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
15829 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
15830 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
15831 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
15832 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
15833 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
15834
15835 /* "neighbor remove-private-AS" commands. */
15836 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
15837 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
15838 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
15839 install_element(BGP_NODE,
15840 &no_neighbor_remove_private_as_all_hidden_cmd);
15841 install_element(BGP_NODE,
15842 &neighbor_remove_private_as_replace_as_hidden_cmd);
15843 install_element(BGP_NODE,
15844 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
15845 install_element(BGP_NODE,
15846 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
15847 install_element(
15848 BGP_NODE,
15849 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
15850 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
15851 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
15852 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
15853 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15854 install_element(BGP_IPV4_NODE,
15855 &neighbor_remove_private_as_replace_as_cmd);
15856 install_element(BGP_IPV4_NODE,
15857 &no_neighbor_remove_private_as_replace_as_cmd);
15858 install_element(BGP_IPV4_NODE,
15859 &neighbor_remove_private_as_all_replace_as_cmd);
15860 install_element(BGP_IPV4_NODE,
15861 &no_neighbor_remove_private_as_all_replace_as_cmd);
15862 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
15863 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
15864 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
15865 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
15866 install_element(BGP_IPV4M_NODE,
15867 &neighbor_remove_private_as_replace_as_cmd);
15868 install_element(BGP_IPV4M_NODE,
15869 &no_neighbor_remove_private_as_replace_as_cmd);
15870 install_element(BGP_IPV4M_NODE,
15871 &neighbor_remove_private_as_all_replace_as_cmd);
15872 install_element(BGP_IPV4M_NODE,
15873 &no_neighbor_remove_private_as_all_replace_as_cmd);
15874 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
15875 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
15876 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
15877 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
15878 install_element(BGP_IPV4L_NODE,
15879 &neighbor_remove_private_as_replace_as_cmd);
15880 install_element(BGP_IPV4L_NODE,
15881 &no_neighbor_remove_private_as_replace_as_cmd);
15882 install_element(BGP_IPV4L_NODE,
15883 &neighbor_remove_private_as_all_replace_as_cmd);
15884 install_element(BGP_IPV4L_NODE,
15885 &no_neighbor_remove_private_as_all_replace_as_cmd);
15886 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
15887 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
15888 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
15889 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15890 install_element(BGP_IPV6_NODE,
15891 &neighbor_remove_private_as_replace_as_cmd);
15892 install_element(BGP_IPV6_NODE,
15893 &no_neighbor_remove_private_as_replace_as_cmd);
15894 install_element(BGP_IPV6_NODE,
15895 &neighbor_remove_private_as_all_replace_as_cmd);
15896 install_element(BGP_IPV6_NODE,
15897 &no_neighbor_remove_private_as_all_replace_as_cmd);
15898 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
15899 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
15900 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
15901 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
15902 install_element(BGP_IPV6M_NODE,
15903 &neighbor_remove_private_as_replace_as_cmd);
15904 install_element(BGP_IPV6M_NODE,
15905 &no_neighbor_remove_private_as_replace_as_cmd);
15906 install_element(BGP_IPV6M_NODE,
15907 &neighbor_remove_private_as_all_replace_as_cmd);
15908 install_element(BGP_IPV6M_NODE,
15909 &no_neighbor_remove_private_as_all_replace_as_cmd);
15910 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
15911 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
15912 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
15913 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
15914 install_element(BGP_IPV6L_NODE,
15915 &neighbor_remove_private_as_replace_as_cmd);
15916 install_element(BGP_IPV6L_NODE,
15917 &no_neighbor_remove_private_as_replace_as_cmd);
15918 install_element(BGP_IPV6L_NODE,
15919 &neighbor_remove_private_as_all_replace_as_cmd);
15920 install_element(BGP_IPV6L_NODE,
15921 &no_neighbor_remove_private_as_all_replace_as_cmd);
15922 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
15923 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
15924 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
15925 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
15926 install_element(BGP_VPNV4_NODE,
15927 &neighbor_remove_private_as_replace_as_cmd);
15928 install_element(BGP_VPNV4_NODE,
15929 &no_neighbor_remove_private_as_replace_as_cmd);
15930 install_element(BGP_VPNV4_NODE,
15931 &neighbor_remove_private_as_all_replace_as_cmd);
15932 install_element(BGP_VPNV4_NODE,
15933 &no_neighbor_remove_private_as_all_replace_as_cmd);
15934 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
15935 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
15936 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
15937 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
15938 install_element(BGP_VPNV6_NODE,
15939 &neighbor_remove_private_as_replace_as_cmd);
15940 install_element(BGP_VPNV6_NODE,
15941 &no_neighbor_remove_private_as_replace_as_cmd);
15942 install_element(BGP_VPNV6_NODE,
15943 &neighbor_remove_private_as_all_replace_as_cmd);
15944 install_element(BGP_VPNV6_NODE,
15945 &no_neighbor_remove_private_as_all_replace_as_cmd);
15946
15947 /* "neighbor send-community" commands.*/
15948 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
15949 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
15950 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
15951 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
15952 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
15953 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
15954 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
15955 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
15956 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
15957 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
15958 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
15959 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
15960 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
15961 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
15962 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
15963 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
15964 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
15965 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
15966 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
15967 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
15968 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
15969 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
15970 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
15971 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
15972 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
15973 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
15974 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
15975 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
15976 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
15977 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
15978 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
15979 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
15980 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
15981 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
15982 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
15983 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
15984
15985 /* "neighbor route-reflector" commands.*/
15986 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
15987 install_element(BGP_NODE,
15988 &no_neighbor_route_reflector_client_hidden_cmd);
15989 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
15990 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
15991 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
15992 install_element(BGP_IPV4M_NODE,
15993 &no_neighbor_route_reflector_client_cmd);
15994 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
15995 install_element(BGP_IPV4L_NODE,
15996 &no_neighbor_route_reflector_client_cmd);
15997 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
15998 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
15999 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
16000 install_element(BGP_IPV6M_NODE,
16001 &no_neighbor_route_reflector_client_cmd);
16002 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
16003 install_element(BGP_IPV6L_NODE,
16004 &no_neighbor_route_reflector_client_cmd);
16005 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
16006 install_element(BGP_VPNV4_NODE,
16007 &no_neighbor_route_reflector_client_cmd);
16008 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
16009 install_element(BGP_VPNV6_NODE,
16010 &no_neighbor_route_reflector_client_cmd);
7c40bf39 16011 install_element(BGP_FLOWSPECV4_NODE,
16012 &neighbor_route_reflector_client_cmd);
16013 install_element(BGP_FLOWSPECV4_NODE,
16014 &no_neighbor_route_reflector_client_cmd);
16015 install_element(BGP_FLOWSPECV6_NODE,
16016 &neighbor_route_reflector_client_cmd);
16017 install_element(BGP_FLOWSPECV6_NODE,
16018 &no_neighbor_route_reflector_client_cmd);
d62a17ae 16019 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
16020 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
16021
16022 /* "neighbor route-server" commands.*/
16023 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
16024 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
16025 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
16026 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
16027 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
16028 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
16029 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
16030 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
16031 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
16032 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
16033 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
16034 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
16035 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
16036 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
16037 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
16038 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
16039 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
16040 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
16041 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
16042 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 16043 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
16044 install_element(BGP_FLOWSPECV4_NODE,
16045 &no_neighbor_route_server_client_cmd);
16046 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
16047 install_element(BGP_FLOWSPECV6_NODE,
16048 &no_neighbor_route_server_client_cmd);
d62a17ae 16049
16050 /* "neighbor addpath-tx-all-paths" commands.*/
16051 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
16052 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
16053 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16054 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16055 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16056 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16057 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16058 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16059 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16060 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16061 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
16062 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16063 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
16064 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16065 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
16066 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16067 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
16068 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
16069
16070 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
16071 install_element(BGP_NODE,
16072 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16073 install_element(BGP_NODE,
16074 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
16075 install_element(BGP_IPV4_NODE,
16076 &neighbor_addpath_tx_bestpath_per_as_cmd);
16077 install_element(BGP_IPV4_NODE,
16078 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16079 install_element(BGP_IPV4M_NODE,
16080 &neighbor_addpath_tx_bestpath_per_as_cmd);
16081 install_element(BGP_IPV4M_NODE,
16082 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16083 install_element(BGP_IPV4L_NODE,
16084 &neighbor_addpath_tx_bestpath_per_as_cmd);
16085 install_element(BGP_IPV4L_NODE,
16086 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16087 install_element(BGP_IPV6_NODE,
16088 &neighbor_addpath_tx_bestpath_per_as_cmd);
16089 install_element(BGP_IPV6_NODE,
16090 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16091 install_element(BGP_IPV6M_NODE,
16092 &neighbor_addpath_tx_bestpath_per_as_cmd);
16093 install_element(BGP_IPV6M_NODE,
16094 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16095 install_element(BGP_IPV6L_NODE,
16096 &neighbor_addpath_tx_bestpath_per_as_cmd);
16097 install_element(BGP_IPV6L_NODE,
16098 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16099 install_element(BGP_VPNV4_NODE,
16100 &neighbor_addpath_tx_bestpath_per_as_cmd);
16101 install_element(BGP_VPNV4_NODE,
16102 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16103 install_element(BGP_VPNV6_NODE,
16104 &neighbor_addpath_tx_bestpath_per_as_cmd);
16105 install_element(BGP_VPNV6_NODE,
16106 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
16107
2b31007c
RZ
16108 /* "neighbor sender-as-path-loop-detection" commands. */
16109 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
16110 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
16111
d62a17ae 16112 /* "neighbor passive" commands. */
16113 install_element(BGP_NODE, &neighbor_passive_cmd);
16114 install_element(BGP_NODE, &no_neighbor_passive_cmd);
16115
16116
16117 /* "neighbor shutdown" commands. */
16118 install_element(BGP_NODE, &neighbor_shutdown_cmd);
16119 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
16120 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
16121 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
16122
16123 /* "neighbor capability extended-nexthop" commands.*/
16124 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
16125 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
16126
16127 /* "neighbor capability orf prefix-list" commands.*/
16128 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
16129 install_element(BGP_NODE,
16130 &no_neighbor_capability_orf_prefix_hidden_cmd);
16131 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
16132 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
16133 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
16134 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16135 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
16136 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16137 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
16138 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
16139 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
16140 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
16141 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
16142 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
16143
16144 /* "neighbor capability dynamic" commands.*/
16145 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
16146 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
16147
16148 /* "neighbor dont-capability-negotiate" commands. */
16149 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
16150 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
16151
16152 /* "neighbor ebgp-multihop" commands. */
16153 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
16154 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
16155 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
16156
16157 /* "neighbor disable-connected-check" commands. */
16158 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
16159 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
16160
47cbc09b
PM
16161 /* "neighbor enforce-first-as" commands. */
16162 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
16163 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
16164
d62a17ae 16165 /* "neighbor description" commands. */
16166 install_element(BGP_NODE, &neighbor_description_cmd);
16167 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 16168 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 16169
16170 /* "neighbor update-source" commands. "*/
16171 install_element(BGP_NODE, &neighbor_update_source_cmd);
16172 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
16173
16174 /* "neighbor default-originate" commands. */
16175 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
16176 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
16177 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
16178 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
16179 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
16180 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
16181 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
16182 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
16183 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
16184 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
16185 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
16186 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
16187 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
16188 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
16189 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
16190 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
16191 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
16192 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
16193 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
16194 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
16195 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
16196
16197 /* "neighbor port" commands. */
16198 install_element(BGP_NODE, &neighbor_port_cmd);
16199 install_element(BGP_NODE, &no_neighbor_port_cmd);
16200
16201 /* "neighbor weight" commands. */
16202 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
16203 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
16204
16205 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
16206 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
16207 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
16208 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
16209 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
16210 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
16211 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
16212 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
16213 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
16214 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
16215 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
16216 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
16217 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
16218 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
16219 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
16220 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
16221
16222 /* "neighbor override-capability" commands. */
16223 install_element(BGP_NODE, &neighbor_override_capability_cmd);
16224 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
16225
16226 /* "neighbor strict-capability-match" commands. */
16227 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
16228 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
16229
16230 /* "neighbor timers" commands. */
16231 install_element(BGP_NODE, &neighbor_timers_cmd);
16232 install_element(BGP_NODE, &no_neighbor_timers_cmd);
16233
16234 /* "neighbor timers connect" commands. */
16235 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
16236 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
16237
16238 /* "neighbor advertisement-interval" commands. */
16239 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
16240 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
16241
16242 /* "neighbor interface" commands. */
16243 install_element(BGP_NODE, &neighbor_interface_cmd);
16244 install_element(BGP_NODE, &no_neighbor_interface_cmd);
16245
16246 /* "neighbor distribute" commands. */
16247 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
16248 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
16249 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
16250 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
16251 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
16252 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
16253 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
16254 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
16255 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
16256 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
16257 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
16258 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
16259 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
16260 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
16261 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
16262 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
16263 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
16264 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
16265
16266 /* "neighbor prefix-list" commands. */
16267 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
16268 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
16269 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
16270 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
16271 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
16272 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
16273 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
16274 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
16275 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
16276 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
16277 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
16278 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
16279 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
16280 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
16281 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
16282 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
16283 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
16284 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 16285 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
16286 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
16287 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
16288 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 16289
16290 /* "neighbor filter-list" commands. */
16291 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
16292 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
16293 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
16294 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
16295 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
16296 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
16297 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
16298 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
16299 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
16300 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
16301 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
16302 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
16303 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
16304 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
16305 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
16306 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
16307 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
16308 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 16309 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
16310 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
16311 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
16312 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 16313
16314 /* "neighbor route-map" commands. */
16315 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
16316 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
16317 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
16318 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
16319 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
16320 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
16321 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
16322 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
16323 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
16324 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
16325 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
16326 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
16327 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
16328 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
16329 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
16330 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
16331 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
16332 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 16333 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
16334 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
16335 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
16336 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
16337 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
16338 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 16339
16340 /* "neighbor unsuppress-map" commands. */
16341 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
16342 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
16343 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
16344 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
16345 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
16346 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
16347 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
16348 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
16349 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
16350 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
16351 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
16352 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
16353 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
16354 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
16355 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
16356 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
16357 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
16358 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
16359
fde246e8
DA
16360 /* neighbor maximum-prefix-out commands. */
16361 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
16362 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
16363 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
16364 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16365 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
16366 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16367 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
16368 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16369 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
16370 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16371 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
16372 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
16373 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
16374 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
16375 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
16376 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
16377 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
16378 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
16379
d62a17ae 16380 /* "neighbor maximum-prefix" commands. */
16381 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
16382 install_element(BGP_NODE,
16383 &neighbor_maximum_prefix_threshold_hidden_cmd);
16384 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
16385 install_element(BGP_NODE,
16386 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
16387 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
16388 install_element(BGP_NODE,
16389 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
16390 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
16391 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
16392 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16393 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16394 install_element(BGP_IPV4_NODE,
16395 &neighbor_maximum_prefix_threshold_warning_cmd);
16396 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16397 install_element(BGP_IPV4_NODE,
16398 &neighbor_maximum_prefix_threshold_restart_cmd);
16399 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
16400 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
16401 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16402 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
16403 install_element(BGP_IPV4M_NODE,
16404 &neighbor_maximum_prefix_threshold_warning_cmd);
16405 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
16406 install_element(BGP_IPV4M_NODE,
16407 &neighbor_maximum_prefix_threshold_restart_cmd);
16408 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
16409 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
16410 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16411 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
16412 install_element(BGP_IPV4L_NODE,
16413 &neighbor_maximum_prefix_threshold_warning_cmd);
16414 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
16415 install_element(BGP_IPV4L_NODE,
16416 &neighbor_maximum_prefix_threshold_restart_cmd);
16417 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
16418 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
16419 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16420 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16421 install_element(BGP_IPV6_NODE,
16422 &neighbor_maximum_prefix_threshold_warning_cmd);
16423 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16424 install_element(BGP_IPV6_NODE,
16425 &neighbor_maximum_prefix_threshold_restart_cmd);
16426 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
16427 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
16428 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
16429 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
16430 install_element(BGP_IPV6M_NODE,
16431 &neighbor_maximum_prefix_threshold_warning_cmd);
16432 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
16433 install_element(BGP_IPV6M_NODE,
16434 &neighbor_maximum_prefix_threshold_restart_cmd);
16435 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
16436 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
16437 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
16438 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
16439 install_element(BGP_IPV6L_NODE,
16440 &neighbor_maximum_prefix_threshold_warning_cmd);
16441 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
16442 install_element(BGP_IPV6L_NODE,
16443 &neighbor_maximum_prefix_threshold_restart_cmd);
16444 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
16445 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
16446 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
16447 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
16448 install_element(BGP_VPNV4_NODE,
16449 &neighbor_maximum_prefix_threshold_warning_cmd);
16450 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
16451 install_element(BGP_VPNV4_NODE,
16452 &neighbor_maximum_prefix_threshold_restart_cmd);
16453 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
16454 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
16455 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
16456 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
16457 install_element(BGP_VPNV6_NODE,
16458 &neighbor_maximum_prefix_threshold_warning_cmd);
16459 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
16460 install_element(BGP_VPNV6_NODE,
16461 &neighbor_maximum_prefix_threshold_restart_cmd);
16462 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
16463
16464 /* "neighbor allowas-in" */
16465 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
16466 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
16467 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
16468 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
16469 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
16470 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
16471 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
16472 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
16473 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
16474 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
16475 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
16476 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
16477 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
16478 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
16479 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
16480 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
16481 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
16482 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
16483 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
16484 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
16485
16486 /* address-family commands. */
16487 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
16488 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 16489#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 16490 install_element(BGP_NODE, &address_family_vpnv4_cmd);
16491 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 16492#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 16493
d62a17ae 16494 install_element(BGP_NODE, &address_family_evpn_cmd);
16495
16496 /* "exit-address-family" command. */
16497 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
16498 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
16499 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
16500 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
16501 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
16502 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
16503 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
16504 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 16505 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
16506 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 16507 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
16508
16509 /* "clear ip bgp commands" */
16510 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
16511
16512 /* clear ip bgp prefix */
16513 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
16514 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
16515 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
16516
16517 /* "show [ip] bgp summary" commands. */
16518 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 16519 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 16520 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 16521 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 16522 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
16523 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 16524 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
16525
16526 /* "show [ip] bgp neighbors" commands. */
16527 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
16528
36235319 16529 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 16530
d62a17ae 16531 /* "show [ip] bgp peer-group" commands. */
16532 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
16533
16534 /* "show [ip] bgp paths" commands. */
16535 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
16536
16537 /* "show [ip] bgp community" commands. */
16538 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
16539
16540 /* "show ip bgp large-community" commands. */
16541 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
16542 /* "show [ip] bgp attribute-info" commands. */
16543 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 16544 /* "show [ip] bgp route-leak" command */
16545 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 16546
16547 /* "redistribute" commands. */
16548 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
16549 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
16550 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
16551 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
16552 install_element(BGP_NODE,
16553 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
16554 install_element(BGP_NODE,
16555 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
16556 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
16557 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
16558 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
16559 install_element(BGP_NODE,
16560 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
16561 install_element(BGP_NODE,
16562 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
16563 install_element(BGP_NODE,
16564 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
16565 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
16566 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
16567 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
16568 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
16569 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
16570 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
16571 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
16572 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
16573 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
16574 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
16575 install_element(BGP_IPV4_NODE,
16576 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
16577 install_element(BGP_IPV4_NODE,
16578 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
16579 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
16580 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
16581 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
16582 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
16583 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
16584 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
16585
b9c7bc5a
PZ
16586 /* import|export vpn [route-map WORD] */
16587 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
16588 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 16589
12a844a5
DS
16590 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
16591 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
16592
d62a17ae 16593 /* ttl_security commands */
16594 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
16595 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
16596
16597 /* "show [ip] bgp memory" commands. */
16598 install_element(VIEW_NODE, &show_bgp_memory_cmd);
16599
acf71666
MK
16600 /* "show bgp martian next-hop" */
16601 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
16602
48ecf8f5
DS
16603 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
16604
d62a17ae 16605 /* "show [ip] bgp views" commands. */
16606 install_element(VIEW_NODE, &show_bgp_views_cmd);
16607
16608 /* "show [ip] bgp vrfs" commands. */
16609 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
16610
16611 /* Community-list. */
16612 community_list_vty();
ddb5b488
PZ
16613
16614 /* vpn-policy commands */
b9c7bc5a
PZ
16615 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
16616 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
16617 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
16618 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
16619 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
16620 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
16621 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
16622 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
16623 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
16624 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
16625 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
16626 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 16627
301ad80a
PG
16628 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
16629 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
16630
b9c7bc5a
PZ
16631 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
16632 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
16633 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
16634 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
16635 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
16636 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
16637 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
16638 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
16639 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
16640 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
16641 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
16642 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 16643}
6b0655a2 16644
718e3744 16645#include "memory.h"
16646#include "bgp_regex.h"
16647#include "bgp_clist.h"
16648#include "bgp_ecommunity.h"
16649
16650/* VTY functions. */
16651
16652/* Direction value to string conversion. */
d62a17ae 16653static const char *community_direct_str(int direct)
16654{
16655 switch (direct) {
16656 case COMMUNITY_DENY:
16657 return "deny";
16658 case COMMUNITY_PERMIT:
16659 return "permit";
16660 default:
16661 return "unknown";
16662 }
718e3744 16663}
16664
16665/* Display error string. */
d62a17ae 16666static void community_list_perror(struct vty *vty, int ret)
16667{
16668 switch (ret) {
16669 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
16670 vty_out(vty, "%% Can't find community-list\n");
16671 break;
16672 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
16673 vty_out(vty, "%% Malformed community-list value\n");
16674 break;
16675 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
16676 vty_out(vty,
16677 "%% Community name conflict, previously defined as standard community\n");
16678 break;
16679 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
16680 vty_out(vty,
16681 "%% Community name conflict, previously defined as expanded community\n");
16682 break;
16683 }
718e3744 16684}
16685
5bf15956
DW
16686/* "community-list" keyword help string. */
16687#define COMMUNITY_LIST_STR "Add a community list entry\n"
16688
7336e101
SP
16689/*community-list standard */
16690DEFUN (community_list_standard,
16691 bgp_community_list_standard_cmd,
2f8cc0e5 16692 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 16693 BGP_STR
718e3744 16694 COMMUNITY_LIST_STR
16695 "Community list number (standard)\n"
5bf15956 16696 "Add an standard community-list entry\n"
718e3744 16697 "Community list name\n"
2f8cc0e5
DA
16698 "Sequence number of an entry\n"
16699 "Sequence number\n"
718e3744 16700 "Specify community to reject\n"
16701 "Specify community to accept\n"
16702 COMMUNITY_VAL_STR)
16703{
d62a17ae 16704 char *cl_name_or_number = NULL;
2f8cc0e5 16705 char *seq = NULL;
d62a17ae 16706 int direct = 0;
16707 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 16708 int idx = 0;
7336e101 16709
2f8cc0e5
DA
16710 argv_find(argv, argc, "(1-4294967295)", &idx);
16711 if (idx)
16712 seq = argv[idx]->arg;
16713
16714 idx = 0;
d62a17ae 16715 argv_find(argv, argc, "(1-99)", &idx);
16716 argv_find(argv, argc, "WORD", &idx);
16717 cl_name_or_number = argv[idx]->arg;
16718 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16719 : COMMUNITY_DENY;
16720 argv_find(argv, argc, "AA:NN", &idx);
16721 char *str = argv_concat(argv, argc, idx);
42f914d4 16722
2f8cc0e5
DA
16723 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16724 direct, style);
42f914d4 16725
d62a17ae 16726 XFREE(MTYPE_TMP, str);
42f914d4 16727
d62a17ae 16728 if (ret < 0) {
16729 /* Display error string. */
16730 community_list_perror(vty, ret);
16731 return CMD_WARNING_CONFIG_FAILED;
16732 }
42f914d4 16733
d62a17ae 16734 return CMD_SUCCESS;
718e3744 16735}
16736
7336e101
SP
16737DEFUN (no_community_list_standard_all,
16738 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 16739 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16740 NO_STR
16741 BGP_STR
16742 COMMUNITY_LIST_STR
16743 "Community list number (standard)\n"
16744 "Add an standard community-list entry\n"
16745 "Community list name\n"
2f8cc0e5
DA
16746 "Sequence number of an entry\n"
16747 "Sequence number\n"
7336e101
SP
16748 "Specify community to reject\n"
16749 "Specify community to accept\n"
16750 COMMUNITY_VAL_STR)
718e3744 16751{
d62a17ae 16752 char *cl_name_or_number = NULL;
174b5cb9 16753 char *str = NULL;
d62a17ae 16754 int direct = 0;
16755 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 16756 char *seq = NULL;
d62a17ae 16757 int idx = 0;
7336e101 16758
2f8cc0e5
DA
16759 argv_find(argv, argc, "(1-4294967295)", &idx);
16760 if (idx)
16761 seq = argv[idx]->arg;
16762
16763 idx = 0;
174b5cb9
DA
16764 argv_find(argv, argc, "permit", &idx);
16765 argv_find(argv, argc, "deny", &idx);
16766
16767 if (idx) {
16768 direct = argv_find(argv, argc, "permit", &idx)
16769 ? COMMUNITY_PERMIT
16770 : COMMUNITY_DENY;
16771
16772 idx = 0;
16773 argv_find(argv, argc, "AA:NN", &idx);
16774 str = argv_concat(argv, argc, idx);
16775 }
16776
16777 idx = 0;
d62a17ae 16778 argv_find(argv, argc, "(1-99)", &idx);
16779 argv_find(argv, argc, "WORD", &idx);
16780 cl_name_or_number = argv[idx]->arg;
42f914d4 16781
2f8cc0e5 16782 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16783 direct, style);
42f914d4 16784
d62a17ae 16785 XFREE(MTYPE_TMP, str);
daf9ddbb 16786
d62a17ae 16787 if (ret < 0) {
16788 community_list_perror(vty, ret);
16789 return CMD_WARNING_CONFIG_FAILED;
16790 }
42f914d4 16791
d62a17ae 16792 return CMD_SUCCESS;
718e3744 16793}
7336e101 16794
174b5cb9
DA
16795ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
16796 "no bgp community-list <(1-99)|standard WORD>",
16797 NO_STR BGP_STR COMMUNITY_LIST_STR
16798 "Community list number (standard)\n"
16799 "Add an standard community-list entry\n"
16800 "Community list name\n")
16801
7336e101
SP
16802/*community-list expanded */
16803DEFUN (community_list_expanded_all,
16804 bgp_community_list_expanded_all_cmd,
2f8cc0e5 16805 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16806 BGP_STR
16807 COMMUNITY_LIST_STR
718e3744 16808 "Community list number (expanded)\n"
5bf15956 16809 "Add an expanded community-list entry\n"
718e3744 16810 "Community list name\n"
2f8cc0e5
DA
16811 "Sequence number of an entry\n"
16812 "Sequence number\n"
718e3744 16813 "Specify community to reject\n"
16814 "Specify community to accept\n"
16815 COMMUNITY_VAL_STR)
16816{
d62a17ae 16817 char *cl_name_or_number = NULL;
2f8cc0e5 16818 char *seq = NULL;
d62a17ae 16819 int direct = 0;
16820 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16821 int idx = 0;
7b9a4750 16822
2f8cc0e5
DA
16823 argv_find(argv, argc, "(1-4294967295)", &idx);
16824 if (idx)
16825 seq = argv[idx]->arg;
16826
16827 idx = 0;
16828
d62a17ae 16829 argv_find(argv, argc, "(100-500)", &idx);
16830 argv_find(argv, argc, "WORD", &idx);
16831 cl_name_or_number = argv[idx]->arg;
16832 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
16833 : COMMUNITY_DENY;
16834 argv_find(argv, argc, "AA:NN", &idx);
16835 char *str = argv_concat(argv, argc, idx);
42f914d4 16836
2f8cc0e5
DA
16837 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
16838 direct, style);
42f914d4 16839
d62a17ae 16840 XFREE(MTYPE_TMP, str);
42f914d4 16841
d62a17ae 16842 if (ret < 0) {
16843 /* Display error string. */
16844 community_list_perror(vty, ret);
16845 return CMD_WARNING_CONFIG_FAILED;
16846 }
42f914d4 16847
d62a17ae 16848 return CMD_SUCCESS;
718e3744 16849}
16850
7336e101
SP
16851DEFUN (no_community_list_expanded_all,
16852 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 16853 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
16854 NO_STR
16855 BGP_STR
16856 COMMUNITY_LIST_STR
16857 "Community list number (expanded)\n"
16858 "Add an expanded community-list entry\n"
16859 "Community list name\n"
2f8cc0e5
DA
16860 "Sequence number of an entry\n"
16861 "Sequence number\n"
7336e101
SP
16862 "Specify community to reject\n"
16863 "Specify community to accept\n"
16864 COMMUNITY_VAL_STR)
718e3744 16865{
d62a17ae 16866 char *cl_name_or_number = NULL;
2f8cc0e5 16867 char *seq = NULL;
174b5cb9 16868 char *str = NULL;
d62a17ae 16869 int direct = 0;
16870 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 16871 int idx = 0;
174b5cb9 16872
2f8cc0e5
DA
16873 argv_find(argv, argc, "(1-4294967295)", &idx);
16874 if (idx)
16875 seq = argv[idx]->arg;
16876
16877 idx = 0;
174b5cb9
DA
16878 argv_find(argv, argc, "permit", &idx);
16879 argv_find(argv, argc, "deny", &idx);
16880
16881 if (idx) {
16882 direct = argv_find(argv, argc, "permit", &idx)
16883 ? COMMUNITY_PERMIT
16884 : COMMUNITY_DENY;
16885
16886 idx = 0;
16887 argv_find(argv, argc, "AA:NN", &idx);
16888 str = argv_concat(argv, argc, idx);
7336e101 16889 }
174b5cb9
DA
16890
16891 idx = 0;
d62a17ae 16892 argv_find(argv, argc, "(100-500)", &idx);
16893 argv_find(argv, argc, "WORD", &idx);
16894 cl_name_or_number = argv[idx]->arg;
42f914d4 16895
2f8cc0e5 16896 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 16897 direct, style);
42f914d4 16898
d62a17ae 16899 XFREE(MTYPE_TMP, str);
daf9ddbb 16900
d62a17ae 16901 if (ret < 0) {
16902 community_list_perror(vty, ret);
16903 return CMD_WARNING_CONFIG_FAILED;
16904 }
42f914d4 16905
d62a17ae 16906 return CMD_SUCCESS;
718e3744 16907}
16908
174b5cb9
DA
16909ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
16910 "no bgp community-list <(100-500)|expanded WORD>",
16911 NO_STR IP_STR COMMUNITY_LIST_STR
16912 "Community list number (expanded)\n"
16913 "Add an expanded community-list entry\n"
16914 "Community list name\n")
16915
8d9b8ed9
PM
16916/* Return configuration string of community-list entry. */
16917static const char *community_list_config_str(struct community_entry *entry)
16918{
16919 const char *str;
16920
16921 if (entry->any)
16922 str = "";
16923 else {
16924 if (entry->style == COMMUNITY_LIST_STANDARD)
16925 str = community_str(entry->u.com, false);
16926 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
16927 str = lcommunity_str(entry->u.lcom, false);
16928 else
16929 str = entry->config;
16930 }
16931 return str;
16932}
16933
d62a17ae 16934static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 16935{
d62a17ae 16936 struct community_entry *entry;
718e3744 16937
d62a17ae 16938 for (entry = list->head; entry; entry = entry->next) {
16939 if (entry == list->head) {
16940 if (all_digit(list->name))
16941 vty_out(vty, "Community %s list %s\n",
16942 entry->style == COMMUNITY_LIST_STANDARD
16943 ? "standard"
16944 : "(expanded) access",
16945 list->name);
16946 else
16947 vty_out(vty, "Named Community %s list %s\n",
16948 entry->style == COMMUNITY_LIST_STANDARD
16949 ? "standard"
16950 : "expanded",
16951 list->name);
16952 }
16953 if (entry->any)
16954 vty_out(vty, " %s\n",
16955 community_direct_str(entry->direct));
16956 else
16957 vty_out(vty, " %s %s\n",
16958 community_direct_str(entry->direct),
8d9b8ed9 16959 community_list_config_str(entry));
d62a17ae 16960 }
718e3744 16961}
16962
7336e101
SP
16963DEFUN (show_community_list,
16964 show_bgp_community_list_cmd,
16965 "show bgp community-list",
718e3744 16966 SHOW_STR
7336e101 16967 BGP_STR
718e3744 16968 "List community-list\n")
16969{
d62a17ae 16970 struct community_list *list;
16971 struct community_list_master *cm;
718e3744 16972
d62a17ae 16973 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
16974 if (!cm)
16975 return CMD_SUCCESS;
718e3744 16976
d62a17ae 16977 for (list = cm->num.head; list; list = list->next)
16978 community_list_show(vty, list);
718e3744 16979
d62a17ae 16980 for (list = cm->str.head; list; list = list->next)
16981 community_list_show(vty, list);
718e3744 16982
d62a17ae 16983 return CMD_SUCCESS;
718e3744 16984}
16985
7336e101
SP
16986DEFUN (show_community_list_arg,
16987 show_bgp_community_list_arg_cmd,
960b69b9 16988 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
16989 SHOW_STR
16990 BGP_STR
718e3744 16991 "List community-list\n"
16992 "Community-list number\n"
960b69b9 16993 "Community-list name\n"
16994 "Detailed information on community-list\n")
718e3744 16995{
d62a17ae 16996 int idx_comm_list = 3;
16997 struct community_list *list;
718e3744 16998
e237b0d2 16999 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17000 COMMUNITY_LIST_MASTER);
17001 if (!list) {
17002 vty_out(vty, "%% Can't find community-list\n");
17003 return CMD_WARNING;
17004 }
718e3744 17005
d62a17ae 17006 community_list_show(vty, list);
718e3744 17007
d62a17ae 17008 return CMD_SUCCESS;
718e3744 17009}
6b0655a2 17010
57d187bc
JS
17011/*
17012 * Large Community code.
17013 */
d62a17ae 17014static int lcommunity_list_set_vty(struct vty *vty, int argc,
17015 struct cmd_token **argv, int style,
17016 int reject_all_digit_name)
17017{
17018 int ret;
17019 int direct;
17020 char *str;
17021 int idx = 0;
17022 char *cl_name;
2f8cc0e5
DA
17023 char *seq = NULL;
17024
17025 argv_find(argv, argc, "(1-4294967295)", &idx);
17026 if (idx)
17027 seq = argv[idx]->arg;
d62a17ae 17028
2f8cc0e5 17029 idx = 0;
d62a17ae 17030 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17031 : COMMUNITY_DENY;
17032
17033 /* All digit name check. */
17034 idx = 0;
17035 argv_find(argv, argc, "WORD", &idx);
17036 argv_find(argv, argc, "(1-99)", &idx);
17037 argv_find(argv, argc, "(100-500)", &idx);
17038 cl_name = argv[idx]->arg;
17039 if (reject_all_digit_name && all_digit(cl_name)) {
17040 vty_out(vty, "%% Community name cannot have all digits\n");
17041 return CMD_WARNING_CONFIG_FAILED;
17042 }
17043
17044 idx = 0;
17045 argv_find(argv, argc, "AA:BB:CC", &idx);
17046 argv_find(argv, argc, "LINE", &idx);
17047 /* Concat community string argument. */
17048 if (idx)
17049 str = argv_concat(argv, argc, idx);
17050 else
17051 str = NULL;
17052
2f8cc0e5 17053 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 17054
17055 /* Free temporary community list string allocated by
17056 argv_concat(). */
0a22ddfb 17057 XFREE(MTYPE_TMP, str);
d62a17ae 17058
17059 if (ret < 0) {
17060 community_list_perror(vty, ret);
17061 return CMD_WARNING_CONFIG_FAILED;
17062 }
17063 return CMD_SUCCESS;
17064}
17065
17066static int lcommunity_list_unset_vty(struct vty *vty, int argc,
17067 struct cmd_token **argv, int style)
17068{
17069 int ret;
17070 int direct = 0;
17071 char *str = NULL;
17072 int idx = 0;
2f8cc0e5 17073 char *seq = NULL;
d62a17ae 17074
2f8cc0e5
DA
17075 argv_find(argv, argc, "(1-4294967295)", &idx);
17076 if (idx)
17077 seq = argv[idx]->arg;
d62a17ae 17078
2f8cc0e5 17079 idx = 0;
d62a17ae 17080 argv_find(argv, argc, "permit", &idx);
17081 argv_find(argv, argc, "deny", &idx);
17082
17083 if (idx) {
17084 /* Check the list direct. */
17085 if (strncmp(argv[idx]->arg, "p", 1) == 0)
17086 direct = COMMUNITY_PERMIT;
17087 else
17088 direct = COMMUNITY_DENY;
17089
17090 idx = 0;
17091 argv_find(argv, argc, "LINE", &idx);
17092 argv_find(argv, argc, "AA:AA:NN", &idx);
17093 /* Concat community string argument. */
17094 str = argv_concat(argv, argc, idx);
17095 }
17096
17097 idx = 0;
17098 argv_find(argv, argc, "(1-99)", &idx);
17099 argv_find(argv, argc, "(100-500)", &idx);
17100 argv_find(argv, argc, "WORD", &idx);
17101
17102 /* Unset community list. */
2f8cc0e5 17103 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 17104 style);
17105
17106 /* Free temporary community list string allocated by
17107 argv_concat(). */
0a22ddfb 17108 XFREE(MTYPE_TMP, str);
d62a17ae 17109
17110 if (ret < 0) {
17111 community_list_perror(vty, ret);
17112 return CMD_WARNING_CONFIG_FAILED;
17113 }
17114
17115 return CMD_SUCCESS;
57d187bc
JS
17116}
17117
17118/* "large-community-list" keyword help string. */
17119#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
17120#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
17121
7336e101
SP
17122DEFUN (lcommunity_list_standard,
17123 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17124 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17125 BGP_STR
17126 LCOMMUNITY_LIST_STR
17127 "Large Community list number (standard)\n"
2f8cc0e5
DA
17128 "Sequence number of an entry\n"
17129 "Sequence number\n"
7336e101
SP
17130 "Specify large community to reject\n"
17131 "Specify large community to accept\n"
17132 LCOMMUNITY_VAL_STR)
52951b63 17133{
d62a17ae 17134 return lcommunity_list_set_vty(vty, argc, argv,
17135 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
17136}
17137
7336e101
SP
17138DEFUN (lcommunity_list_expanded,
17139 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17140 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17141 BGP_STR
17142 LCOMMUNITY_LIST_STR
17143 "Large Community list number (expanded)\n"
2f8cc0e5
DA
17144 "Sequence number of an entry\n"
17145 "Sequence number\n"
7336e101
SP
17146 "Specify large community to reject\n"
17147 "Specify large community to accept\n"
17148 "An ordered list as a regular-expression\n")
57d187bc 17149{
d62a17ae 17150 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17151 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
17152}
17153
7336e101
SP
17154DEFUN (lcommunity_list_name_standard,
17155 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17156 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
17157 BGP_STR
17158 LCOMMUNITY_LIST_STR
17159 "Specify standard large-community-list\n"
17160 "Large Community list name\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 LCOMMUNITY_VAL_STR)
52951b63 17166{
d62a17ae 17167 return lcommunity_list_set_vty(vty, argc, argv,
17168 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
17169}
17170
7336e101
SP
17171DEFUN (lcommunity_list_name_expanded,
17172 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17173 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17174 BGP_STR
17175 LCOMMUNITY_LIST_STR
17176 "Specify expanded 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 "An ordered list as a regular-expression\n")
57d187bc 17183{
d62a17ae 17184 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 17185 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
17186}
17187
4378f57c
DA
17188DEFUN (no_lcommunity_list_all,
17189 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
17190 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
17191 NO_STR
17192 BGP_STR
17193 LCOMMUNITY_LIST_STR
17194 "Large Community list number (standard)\n"
17195 "Large Community list number (expanded)\n"
17196 "Large Community list name\n")
57d187bc 17197{
7336e101
SP
17198 return lcommunity_list_unset_vty(vty, argc, argv,
17199 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17200}
17201
4378f57c
DA
17202DEFUN (no_lcommunity_list_name_standard_all,
17203 no_bgp_lcommunity_list_name_standard_all_cmd,
17204 "no bgp large-community-list standard WORD",
17205 NO_STR
17206 BGP_STR
17207 LCOMMUNITY_LIST_STR
17208 "Specify standard large-community-list\n"
17209 "Large Community list name\n")
17210{
17211 return lcommunity_list_unset_vty(vty, argc, argv,
17212 LARGE_COMMUNITY_LIST_STANDARD);
17213}
17214
7336e101
SP
17215DEFUN (no_lcommunity_list_name_expanded_all,
17216 no_bgp_lcommunity_list_name_expanded_all_cmd,
17217 "no bgp large-community-list expanded WORD",
17218 NO_STR
17219 BGP_STR
17220 LCOMMUNITY_LIST_STR
17221 "Specify expanded large-community-list\n"
17222 "Large Community list name\n")
57d187bc 17223{
d62a17ae 17224 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17225 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17226}
17227
7336e101
SP
17228DEFUN (no_lcommunity_list_standard,
17229 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 17230 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17231 NO_STR
17232 BGP_STR
17233 LCOMMUNITY_LIST_STR
17234 "Large Community list number (standard)\n"
2f8cc0e5
DA
17235 "Sequence number of an entry\n"
17236 "Sequence number\n"
7336e101
SP
17237 "Specify large community to reject\n"
17238 "Specify large community to accept\n"
17239 LCOMMUNITY_VAL_STR)
57d187bc 17240{
d62a17ae 17241 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17242 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17243}
17244
7336e101
SP
17245DEFUN (no_lcommunity_list_expanded,
17246 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 17247 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17248 NO_STR
17249 BGP_STR
17250 LCOMMUNITY_LIST_STR
17251 "Large Community list number (expanded)\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 "An ordered list as a regular-expression\n")
57d187bc 17257{
d62a17ae 17258 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17259 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17260}
17261
7336e101
SP
17262DEFUN (no_lcommunity_list_name_standard,
17263 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 17264 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
17265 NO_STR
17266 BGP_STR
17267 LCOMMUNITY_LIST_STR
17268 "Specify standard large-community-list\n"
17269 "Large Community list name\n"
2f8cc0e5
DA
17270 "Sequence number of an entry\n"
17271 "Sequence number\n"
7336e101
SP
17272 "Specify large community to reject\n"
17273 "Specify large community to accept\n"
17274 LCOMMUNITY_VAL_STR)
57d187bc 17275{
d62a17ae 17276 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17277 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
17278}
17279
7336e101
SP
17280DEFUN (no_lcommunity_list_name_expanded,
17281 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 17282 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17283 NO_STR
17284 BGP_STR
17285 LCOMMUNITY_LIST_STR
17286 "Specify expanded large-community-list\n"
17287 "Large community list name\n"
2f8cc0e5
DA
17288 "Sequence number of an entry\n"
17289 "Sequence number\n"
7336e101
SP
17290 "Specify large community to reject\n"
17291 "Specify large community to accept\n"
17292 "An ordered list as a regular-expression\n")
57d187bc 17293{
d62a17ae 17294 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 17295 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
17296}
17297
d62a17ae 17298static void lcommunity_list_show(struct vty *vty, struct community_list *list)
17299{
17300 struct community_entry *entry;
17301
17302 for (entry = list->head; entry; entry = entry->next) {
17303 if (entry == list->head) {
17304 if (all_digit(list->name))
17305 vty_out(vty, "Large community %s list %s\n",
169b72c8 17306 entry->style ==
17307 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17308 ? "standard"
17309 : "(expanded) access",
17310 list->name);
17311 else
17312 vty_out(vty,
17313 "Named large community %s list %s\n",
169b72c8 17314 entry->style ==
17315 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 17316 ? "standard"
17317 : "expanded",
17318 list->name);
17319 }
17320 if (entry->any)
17321 vty_out(vty, " %s\n",
17322 community_direct_str(entry->direct));
17323 else
17324 vty_out(vty, " %s %s\n",
17325 community_direct_str(entry->direct),
8d9b8ed9 17326 community_list_config_str(entry));
d62a17ae 17327 }
57d187bc
JS
17328}
17329
7336e101
SP
17330DEFUN (show_lcommunity_list,
17331 show_bgp_lcommunity_list_cmd,
17332 "show bgp large-community-list",
57d187bc 17333 SHOW_STR
7336e101 17334 BGP_STR
57d187bc
JS
17335 "List large-community list\n")
17336{
d62a17ae 17337 struct community_list *list;
17338 struct community_list_master *cm;
57d187bc 17339
d62a17ae 17340 cm = community_list_master_lookup(bgp_clist,
17341 LARGE_COMMUNITY_LIST_MASTER);
17342 if (!cm)
17343 return CMD_SUCCESS;
57d187bc 17344
d62a17ae 17345 for (list = cm->num.head; list; list = list->next)
17346 lcommunity_list_show(vty, list);
57d187bc 17347
d62a17ae 17348 for (list = cm->str.head; list; list = list->next)
17349 lcommunity_list_show(vty, list);
57d187bc 17350
d62a17ae 17351 return CMD_SUCCESS;
57d187bc
JS
17352}
17353
7336e101
SP
17354DEFUN (show_lcommunity_list_arg,
17355 show_bgp_lcommunity_list_arg_cmd,
960b69b9 17356 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
17357 SHOW_STR
17358 BGP_STR
57d187bc 17359 "List large-community list\n"
960b69b9 17360 "Large-community-list number\n"
17361 "Large-community-list name\n"
17362 "Detailed information on large-community-list\n")
57d187bc 17363{
d62a17ae 17364 struct community_list *list;
57d187bc 17365
e237b0d2 17366 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 17367 LARGE_COMMUNITY_LIST_MASTER);
17368 if (!list) {
960b69b9 17369 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 17370 return CMD_WARNING;
17371 }
57d187bc 17372
d62a17ae 17373 lcommunity_list_show(vty, list);
57d187bc 17374
d62a17ae 17375 return CMD_SUCCESS;
57d187bc
JS
17376}
17377
718e3744 17378/* "extcommunity-list" keyword help string. */
17379#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
17380#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
17381
7336e101
SP
17382DEFUN (extcommunity_list_standard,
17383 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 17384 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17385 BGP_STR
718e3744 17386 EXTCOMMUNITY_LIST_STR
17387 "Extended Community list number (standard)\n"
718e3744 17388 "Specify standard extcommunity-list\n"
5bf15956 17389 "Community list name\n"
2f8cc0e5
DA
17390 "Sequence number of an entry\n"
17391 "Sequence number\n"
718e3744 17392 "Specify community to reject\n"
17393 "Specify community to accept\n"
17394 EXTCOMMUNITY_VAL_STR)
17395{
d62a17ae 17396 int style = EXTCOMMUNITY_LIST_STANDARD;
17397 int direct = 0;
17398 char *cl_number_or_name = NULL;
2f8cc0e5 17399 char *seq = NULL;
42f914d4 17400
d62a17ae 17401 int idx = 0;
7b9a4750 17402
d62a17ae 17403 argv_find(argv, argc, "(1-99)", &idx);
17404 argv_find(argv, argc, "WORD", &idx);
17405 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17406
17407 argv_find(argv, argc, "(1-4294967295)", &idx);
17408 if (idx)
17409 seq = argv[idx]->arg;
17410
d62a17ae 17411 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17412 : COMMUNITY_DENY;
17413 argv_find(argv, argc, "AA:NN", &idx);
17414 char *str = argv_concat(argv, argc, idx);
42f914d4 17415
2f8cc0e5 17416 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17417 direct, style);
42f914d4 17418
d62a17ae 17419 XFREE(MTYPE_TMP, str);
42f914d4 17420
d62a17ae 17421 if (ret < 0) {
17422 community_list_perror(vty, ret);
17423 return CMD_WARNING_CONFIG_FAILED;
17424 }
42f914d4 17425
d62a17ae 17426 return CMD_SUCCESS;
718e3744 17427}
17428
7336e101
SP
17429DEFUN (extcommunity_list_name_expanded,
17430 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 17431 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17432 BGP_STR
17433 EXTCOMMUNITY_LIST_STR
5bf15956 17434 "Extended Community list number (expanded)\n"
718e3744 17435 "Specify expanded extcommunity-list\n"
17436 "Extended Community list name\n"
2f8cc0e5
DA
17437 "Sequence number of an entry\n"
17438 "Sequence number\n"
718e3744 17439 "Specify community to reject\n"
17440 "Specify community to accept\n"
17441 "An ordered list as a regular-expression\n")
17442{
d62a17ae 17443 int style = EXTCOMMUNITY_LIST_EXPANDED;
17444 int direct = 0;
17445 char *cl_number_or_name = NULL;
2f8cc0e5 17446 char *seq = NULL;
d62a17ae 17447 int idx = 0;
7336e101 17448
d62a17ae 17449 argv_find(argv, argc, "(100-500)", &idx);
17450 argv_find(argv, argc, "WORD", &idx);
17451 cl_number_or_name = argv[idx]->arg;
2f8cc0e5
DA
17452
17453 argv_find(argv, argc, "(1-4294967295)", &idx);
17454 if (idx)
17455 seq = argv[idx]->arg;
17456
d62a17ae 17457 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17458 : COMMUNITY_DENY;
17459 argv_find(argv, argc, "LINE", &idx);
17460 char *str = argv_concat(argv, argc, idx);
42f914d4 17461
2f8cc0e5 17462 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 17463 direct, style);
42f914d4 17464
d62a17ae 17465 XFREE(MTYPE_TMP, str);
42f914d4 17466
d62a17ae 17467 if (ret < 0) {
17468 community_list_perror(vty, ret);
17469 return CMD_WARNING_CONFIG_FAILED;
17470 }
42f914d4 17471
d62a17ae 17472 return CMD_SUCCESS;
718e3744 17473}
17474
7336e101
SP
17475DEFUN (no_extcommunity_list_standard_all,
17476 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 17477 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17478 NO_STR
17479 BGP_STR
17480 EXTCOMMUNITY_LIST_STR
813d4307 17481 "Extended Community list number (standard)\n"
718e3744 17482 "Specify standard extcommunity-list\n"
5bf15956 17483 "Community list name\n"
2f8cc0e5
DA
17484 "Sequence number of an entry\n"
17485 "Sequence number\n"
718e3744 17486 "Specify community to reject\n"
17487 "Specify community to accept\n"
17488 EXTCOMMUNITY_VAL_STR)
17489{
d62a17ae 17490 int style = EXTCOMMUNITY_LIST_STANDARD;
17491 int direct = 0;
17492 char *cl_number_or_name = NULL;
d4455c89 17493 char *str = NULL;
2f8cc0e5 17494 char *seq = NULL;
d62a17ae 17495 int idx = 0;
d4455c89 17496
2f8cc0e5
DA
17497 argv_find(argv, argc, "(1-4294967295)", &idx);
17498 if (idx)
17499 seq = argv[idx]->arg;
17500
17501 idx = 0;
d4455c89
DA
17502 argv_find(argv, argc, "permit", &idx);
17503 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
17504 if (idx) {
17505 direct = argv_find(argv, argc, "permit", &idx)
17506 ? COMMUNITY_PERMIT
17507 : COMMUNITY_DENY;
17508
17509 idx = 0;
17510 argv_find(argv, argc, "AA:NN", &idx);
17511 str = argv_concat(argv, argc, idx);
17512 }
17513
17514 idx = 0;
d62a17ae 17515 argv_find(argv, argc, "(1-99)", &idx);
17516 argv_find(argv, argc, "WORD", &idx);
17517 cl_number_or_name = argv[idx]->arg;
42f914d4 17518
d62a17ae 17519 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17520 seq, direct, style);
42f914d4 17521
d62a17ae 17522 XFREE(MTYPE_TMP, str);
42f914d4 17523
d62a17ae 17524 if (ret < 0) {
17525 community_list_perror(vty, ret);
17526 return CMD_WARNING_CONFIG_FAILED;
17527 }
42f914d4 17528
d62a17ae 17529 return CMD_SUCCESS;
718e3744 17530}
17531
d4455c89
DA
17532ALIAS(no_extcommunity_list_standard_all,
17533 no_bgp_extcommunity_list_standard_all_list_cmd,
17534 "no bgp extcommunity-list <(1-99)|standard WORD>",
17535 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17536 "Extended Community list number (standard)\n"
17537 "Specify standard extcommunity-list\n"
17538 "Community list name\n")
17539
7336e101
SP
17540DEFUN (no_extcommunity_list_expanded_all,
17541 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 17542 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
17543 NO_STR
17544 BGP_STR
17545 EXTCOMMUNITY_LIST_STR
718e3744 17546 "Extended Community list number (expanded)\n"
718e3744 17547 "Specify expanded extcommunity-list\n"
5bf15956 17548 "Extended Community list name\n"
2f8cc0e5
DA
17549 "Sequence number of an entry\n"
17550 "Sequence number\n"
718e3744 17551 "Specify community to reject\n"
17552 "Specify community to accept\n"
17553 "An ordered list as a regular-expression\n")
17554{
d62a17ae 17555 int style = EXTCOMMUNITY_LIST_EXPANDED;
17556 int direct = 0;
17557 char *cl_number_or_name = NULL;
d4455c89 17558 char *str = NULL;
2f8cc0e5 17559 char *seq = NULL;
d62a17ae 17560 int idx = 0;
d4455c89 17561
2f8cc0e5
DA
17562 argv_find(argv, argc, "(1-4294967295)", &idx);
17563 if (idx)
17564 seq = argv[idx]->arg;
17565
17566 idx = 0;
d4455c89
DA
17567 argv_find(argv, argc, "permit", &idx);
17568 argv_find(argv, argc, "deny", &idx);
17569
17570 if (idx) {
17571 direct = argv_find(argv, argc, "permit", &idx)
17572 ? COMMUNITY_PERMIT
17573 : COMMUNITY_DENY;
17574
17575 idx = 0;
17576 argv_find(argv, argc, "LINE", &idx);
17577 str = argv_concat(argv, argc, idx);
17578 }
17579
17580 idx = 0;
d62a17ae 17581 argv_find(argv, argc, "(100-500)", &idx);
17582 argv_find(argv, argc, "WORD", &idx);
17583 cl_number_or_name = argv[idx]->arg;
42f914d4 17584
d62a17ae 17585 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 17586 seq, direct, style);
42f914d4 17587
d62a17ae 17588 XFREE(MTYPE_TMP, str);
42f914d4 17589
d62a17ae 17590 if (ret < 0) {
17591 community_list_perror(vty, ret);
17592 return CMD_WARNING_CONFIG_FAILED;
17593 }
42f914d4 17594
d62a17ae 17595 return CMD_SUCCESS;
718e3744 17596}
17597
d4455c89
DA
17598ALIAS(no_extcommunity_list_expanded_all,
17599 no_bgp_extcommunity_list_expanded_all_list_cmd,
17600 "no bgp extcommunity-list <(100-500)|expanded WORD>",
17601 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
17602 "Extended Community list number (expanded)\n"
17603 "Specify expanded extcommunity-list\n"
17604 "Extended Community list name\n")
17605
d62a17ae 17606static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 17607{
d62a17ae 17608 struct community_entry *entry;
718e3744 17609
d62a17ae 17610 for (entry = list->head; entry; entry = entry->next) {
17611 if (entry == list->head) {
17612 if (all_digit(list->name))
17613 vty_out(vty, "Extended community %s list %s\n",
17614 entry->style == EXTCOMMUNITY_LIST_STANDARD
17615 ? "standard"
17616 : "(expanded) access",
17617 list->name);
17618 else
17619 vty_out(vty,
17620 "Named extended community %s list %s\n",
17621 entry->style == EXTCOMMUNITY_LIST_STANDARD
17622 ? "standard"
17623 : "expanded",
17624 list->name);
17625 }
17626 if (entry->any)
17627 vty_out(vty, " %s\n",
17628 community_direct_str(entry->direct));
17629 else
17630 vty_out(vty, " %s %s\n",
17631 community_direct_str(entry->direct),
8d9b8ed9 17632 community_list_config_str(entry));
d62a17ae 17633 }
718e3744 17634}
17635
7336e101
SP
17636DEFUN (show_extcommunity_list,
17637 show_bgp_extcommunity_list_cmd,
17638 "show bgp extcommunity-list",
718e3744 17639 SHOW_STR
7336e101 17640 BGP_STR
718e3744 17641 "List extended-community list\n")
17642{
d62a17ae 17643 struct community_list *list;
17644 struct community_list_master *cm;
718e3744 17645
d62a17ae 17646 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17647 if (!cm)
17648 return CMD_SUCCESS;
718e3744 17649
d62a17ae 17650 for (list = cm->num.head; list; list = list->next)
17651 extcommunity_list_show(vty, list);
718e3744 17652
d62a17ae 17653 for (list = cm->str.head; list; list = list->next)
17654 extcommunity_list_show(vty, list);
718e3744 17655
d62a17ae 17656 return CMD_SUCCESS;
718e3744 17657}
17658
7336e101
SP
17659DEFUN (show_extcommunity_list_arg,
17660 show_bgp_extcommunity_list_arg_cmd,
960b69b9 17661 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
17662 SHOW_STR
17663 BGP_STR
718e3744 17664 "List extended-community list\n"
17665 "Extcommunity-list number\n"
960b69b9 17666 "Extcommunity-list name\n"
17667 "Detailed information on extcommunity-list\n")
718e3744 17668{
d62a17ae 17669 int idx_comm_list = 3;
17670 struct community_list *list;
718e3744 17671
e237b0d2 17672 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 17673 EXTCOMMUNITY_LIST_MASTER);
17674 if (!list) {
17675 vty_out(vty, "%% Can't find extcommunity-list\n");
17676 return CMD_WARNING;
17677 }
718e3744 17678
d62a17ae 17679 extcommunity_list_show(vty, list);
718e3744 17680
d62a17ae 17681 return CMD_SUCCESS;
718e3744 17682}
6b0655a2 17683
718e3744 17684/* Display community-list and extcommunity-list configuration. */
d62a17ae 17685static int community_list_config_write(struct vty *vty)
17686{
17687 struct community_list *list;
17688 struct community_entry *entry;
17689 struct community_list_master *cm;
17690 int write = 0;
17691
17692 /* Community-list. */
17693 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
17694
17695 for (list = cm->num.head; list; list = list->next)
17696 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17697 vty_out(vty,
17698 "bgp community-list %s seq %" PRId64 " %s %s\n",
17699 list->name, entry->seq,
d62a17ae 17700 community_direct_str(entry->direct),
17701 community_list_config_str(entry));
17702 write++;
17703 }
17704 for (list = cm->str.head; list; list = list->next)
17705 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17706 vty_out(vty,
17707 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 17708 entry->style == COMMUNITY_LIST_STANDARD
17709 ? "standard"
17710 : "expanded",
2f8cc0e5
DA
17711 list->name, entry->seq,
17712 community_direct_str(entry->direct),
d62a17ae 17713 community_list_config_str(entry));
17714 write++;
17715 }
17716
17717 /* Extcommunity-list. */
17718 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
17719
17720 for (list = cm->num.head; list; list = list->next)
17721 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17722 vty_out(vty,
17723 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
17724 list->name, entry->seq,
17725 community_direct_str(entry->direct),
d62a17ae 17726 community_list_config_str(entry));
17727 write++;
17728 }
17729 for (list = cm->str.head; list; list = list->next)
17730 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17731 vty_out(vty,
17732 "bgp extcommunity-list %s %s seq %" PRId64
17733 " %s %s\n",
d62a17ae 17734 entry->style == EXTCOMMUNITY_LIST_STANDARD
17735 ? "standard"
17736 : "expanded",
2f8cc0e5
DA
17737 list->name, entry->seq,
17738 community_direct_str(entry->direct),
d62a17ae 17739 community_list_config_str(entry));
17740 write++;
17741 }
17742
17743
17744 /* lcommunity-list. */
17745 cm = community_list_master_lookup(bgp_clist,
17746 LARGE_COMMUNITY_LIST_MASTER);
17747
17748 for (list = cm->num.head; list; list = list->next)
17749 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17750 vty_out(vty,
17751 "bgp large-community-list %s seq %" PRId64
17752 " %s %s\n",
17753 list->name, entry->seq,
17754 community_direct_str(entry->direct),
d62a17ae 17755 community_list_config_str(entry));
17756 write++;
17757 }
17758 for (list = cm->str.head; list; list = list->next)
17759 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
17760 vty_out(vty,
17761 "bgp large-community-list %s %s seq %" PRId64
17762 " %s %s\n",
17763
d62a17ae 17764 entry->style == LARGE_COMMUNITY_LIST_STANDARD
17765 ? "standard"
17766 : "expanded",
2f8cc0e5 17767 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 17768 community_list_config_str(entry));
17769 write++;
17770 }
17771
17772 return write;
17773}
17774
17775static struct cmd_node community_list_node = {
17776 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 17777};
17778
d62a17ae 17779static void community_list_vty(void)
17780{
17781 install_node(&community_list_node, community_list_config_write);
17782
17783 /* Community-list. */
7336e101
SP
17784 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
17785 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
17786 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 17787 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 17788 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 17789 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
17790 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
17791 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 17792
17793 /* Extcommunity-list. */
7336e101
SP
17794 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
17795 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
17796 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
17797 install_element(CONFIG_NODE,
17798 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 17799 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
17800 install_element(CONFIG_NODE,
17801 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
17802 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
17803 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 17804
17805 /* Large Community List */
7336e101 17806 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
17807 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
17808 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 17809 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
17810 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
17811 install_element(CONFIG_NODE,
17812 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
17813 install_element(CONFIG_NODE,
17814 &no_bgp_lcommunity_list_name_expanded_all_cmd);
17815 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
17816 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
17817 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
17818 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
17819 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
17820 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 17821}