]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
pathd: rework config printing code
[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"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4bf6a362 56#include "bgpd/bgp_nexthop.h"
718e3744 57#include "bgpd/bgp_open.h"
4bf6a362 58#include "bgpd/bgp_regex.h"
718e3744 59#include "bgpd/bgp_route.h"
c016b6c7 60#include "bgpd/bgp_mplsvpn.h"
718e3744 61#include "bgpd/bgp_zebra.h"
fee0f4c6 62#include "bgpd/bgp_table.h"
94f2b392 63#include "bgpd/bgp_vty.h"
165b5fff 64#include "bgpd/bgp_mpath.h"
cb1faec9 65#include "bgpd/bgp_packet.h"
3f9c7369 66#include "bgpd/bgp_updgrp.h"
c43ed2e4 67#include "bgpd/bgp_bfd.h"
555e09d4 68#include "bgpd/bgp_io.h"
94c2f693 69#include "bgpd/bgp_evpn.h"
dd65f45e 70#include "bgpd/bgp_evpn_vty.h"
b5e140c8 71#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 72#include "bgpd/bgp_addpath.h"
48ecf8f5 73#include "bgpd/bgp_mac.h"
dd65f45e 74#include "bgpd/bgp_flowspec.h"
389e4f92 75#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 76#ifdef ENABLE_BGP_VNC
dd65f45e
DL
77#include "bgpd/rfapi/bgp_rfapi_cfg.h"
78#endif
79
5d5393b9 80FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
81 {
82 .val_bool = false,
83 .match_profile = "traditional",
84 .match_version = "< 7.4",
85 },
86 { .val_bool = true },
67b0f40c 87);
5d5393b9 88FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
89 { .val_bool = true, .match_profile = "datacenter", },
90 { .val_bool = false },
67b0f40c 91);
aef999a2
DA
92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
5d5393b9 96FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9
DL
104FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
105 { .val_ulong = 10, .match_profile = "datacenter", },
106 { .val_ulong = 120 },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
109 { .val_ulong = 9, .match_profile = "datacenter", },
110 { .val_ulong = 180 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
113 { .val_ulong = 3, .match_profile = "datacenter", },
114 { .val_ulong = 60 },
67b0f40c 115);
1d3fdccf
DA
116FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
117 { .val_bool = false, .match_profile = "datacenter", },
118 { .val_bool = false, .match_version = "< 7.4", },
119 { .val_bool = true },
67b0f40c 120);
2adac256
DA
121FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
122 { .val_bool = false, .match_version = "< 7.6", },
123 { .val_bool = true },
67b0f40c 124);
5d5393b9 125
dd65f45e
DL
126DEFINE_HOOK(bgp_inst_config_write,
127 (struct bgp *bgp, struct vty *vty),
8451921b
DL
128 (bgp, vty));
129DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 130DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 131
d62a17ae 132static struct peer_group *listen_range_exists(struct bgp *bgp,
133 struct prefix *range, int exact);
134
055679e9 135/* Show BGP peer's information. */
136enum show_type {
137 show_all,
138 show_peer,
139 show_ipv4_all,
140 show_ipv6_all,
141 show_ipv4_peer,
142 show_ipv6_peer
143};
144
36235319
QY
145static struct peer_group *listen_range_exists(struct bgp *bgp,
146 struct prefix *range, int exact);
2986cac2 147
36235319
QY
148static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
149 struct bgp *bgp,
150 bool use_json,
151 json_object *json);
2986cac2 152
36235319
QY
153static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
154 enum show_type type,
155 const char *ip_str,
156 afi_t afi, bool use_json);
2986cac2 157
d62a17ae 158static enum node_type bgp_node_type(afi_t afi, safi_t safi)
159{
160 switch (afi) {
161 case AFI_IP:
162 switch (safi) {
163 case SAFI_UNICAST:
164 return BGP_IPV4_NODE;
d62a17ae 165 case SAFI_MULTICAST:
166 return BGP_IPV4M_NODE;
d62a17ae 167 case SAFI_LABELED_UNICAST:
168 return BGP_IPV4L_NODE;
d62a17ae 169 case SAFI_MPLS_VPN:
170 return BGP_VPNV4_NODE;
7c40bf39 171 case SAFI_FLOWSPEC:
172 return BGP_FLOWSPECV4_NODE;
5c525538
RW
173 default:
174 /* not expected */
175 return BGP_IPV4_NODE;
d62a17ae 176 }
177 break;
178 case AFI_IP6:
179 switch (safi) {
180 case SAFI_UNICAST:
181 return BGP_IPV6_NODE;
d62a17ae 182 case SAFI_MULTICAST:
183 return BGP_IPV6M_NODE;
d62a17ae 184 case SAFI_LABELED_UNICAST:
185 return BGP_IPV6L_NODE;
d62a17ae 186 case SAFI_MPLS_VPN:
187 return BGP_VPNV6_NODE;
7c40bf39 188 case SAFI_FLOWSPEC:
189 return BGP_FLOWSPECV6_NODE;
5c525538
RW
190 default:
191 /* not expected */
192 return BGP_IPV4_NODE;
d62a17ae 193 }
194 break;
195 case AFI_L2VPN:
196 return BGP_EVPN_NODE;
b26f891d 197 case AFI_UNSPEC:
d62a17ae 198 case AFI_MAX:
199 // We should never be here but to clarify the switch statement..
200 return BGP_IPV4_NODE;
d62a17ae 201 }
202
203 // Impossible to happen
204 return BGP_IPV4_NODE;
f51bae9c 205}
20eb8864 206
5cb5f4d0
DD
207static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
208{
7d0d37de
DS
209 if (afi == AFI_IP) {
210 if (safi == SAFI_UNICAST)
211 return "IPv4 Unicast";
212 if (safi == SAFI_MULTICAST)
213 return "IPv4 Multicast";
214 if (safi == SAFI_LABELED_UNICAST)
215 return "IPv4 Labeled Unicast";
216 if (safi == SAFI_MPLS_VPN)
217 return "IPv4 VPN";
218 if (safi == SAFI_ENCAP)
219 return "IPv4 Encap";
220 if (safi == SAFI_FLOWSPEC)
221 return "IPv4 Flowspec";
222 } else if (afi == AFI_IP6) {
223 if (safi == SAFI_UNICAST)
224 return "IPv6 Unicast";
225 if (safi == SAFI_MULTICAST)
226 return "IPv6 Multicast";
227 if (safi == SAFI_LABELED_UNICAST)
228 return "IPv6 Labeled Unicast";
229 if (safi == SAFI_MPLS_VPN)
230 return "IPv6 VPN";
231 if (safi == SAFI_ENCAP)
232 return "IPv6 Encap";
233 if (safi == SAFI_FLOWSPEC)
234 return "IPv6 Flowspec";
235 } else if (afi == AFI_L2VPN) {
236 if (safi == SAFI_EVPN)
237 return "L2VPN EVPN";
238 }
239
240 return "Unknown";
5cb5f4d0
DD
241}
242
243/*
244 * Please note that we have intentionally camelCased
245 * the return strings here. So if you want
246 * to use this function, please ensure you
247 * are doing this within json output
248 */
249static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
250{
7d0d37de
DS
251 if (afi == AFI_IP) {
252 if (safi == SAFI_UNICAST)
253 return "ipv4Unicast";
254 if (safi == SAFI_MULTICAST)
255 return "ipv4Multicast";
256 if (safi == SAFI_LABELED_UNICAST)
257 return "ipv4LabeledUnicast";
258 if (safi == SAFI_MPLS_VPN)
259 return "ipv4Vpn";
260 if (safi == SAFI_ENCAP)
261 return "ipv4Encap";
262 if (safi == SAFI_FLOWSPEC)
263 return "ipv4Flowspec";
264 } else if (afi == AFI_IP6) {
265 if (safi == SAFI_UNICAST)
266 return "ipv6Unicast";
267 if (safi == SAFI_MULTICAST)
268 return "ipv6Multicast";
269 if (safi == SAFI_LABELED_UNICAST)
270 return "ipv6LabeledUnicast";
271 if (safi == SAFI_MPLS_VPN)
272 return "ipv6Vpn";
273 if (safi == SAFI_ENCAP)
274 return "ipv6Encap";
275 if (safi == SAFI_FLOWSPEC)
276 return "ipv6Flowspec";
277 } else if (afi == AFI_L2VPN) {
278 if (safi == SAFI_EVPN)
279 return "l2VpnEvpn";
280 }
281
282 return "Unknown";
5cb5f4d0
DD
283}
284
718e3744 285/* Utility function to get address family from current node. */
d62a17ae 286afi_t bgp_node_afi(struct vty *vty)
287{
288 afi_t afi;
289 switch (vty->node) {
290 case BGP_IPV6_NODE:
291 case BGP_IPV6M_NODE:
292 case BGP_IPV6L_NODE:
293 case BGP_VPNV6_NODE:
7c40bf39 294 case BGP_FLOWSPECV6_NODE:
d62a17ae 295 afi = AFI_IP6;
296 break;
297 case BGP_EVPN_NODE:
298 afi = AFI_L2VPN;
299 break;
300 default:
301 afi = AFI_IP;
302 break;
303 }
304 return afi;
718e3744 305}
306
307/* Utility function to get subsequent address family from current
308 node. */
d62a17ae 309safi_t bgp_node_safi(struct vty *vty)
310{
311 safi_t safi;
312 switch (vty->node) {
313 case BGP_VPNV4_NODE:
314 case BGP_VPNV6_NODE:
315 safi = SAFI_MPLS_VPN;
316 break;
317 case BGP_IPV4M_NODE:
318 case BGP_IPV6M_NODE:
319 safi = SAFI_MULTICAST;
320 break;
321 case BGP_EVPN_NODE:
322 safi = SAFI_EVPN;
323 break;
324 case BGP_IPV4L_NODE:
325 case BGP_IPV6L_NODE:
326 safi = SAFI_LABELED_UNICAST;
327 break;
7c40bf39 328 case BGP_FLOWSPECV4_NODE:
329 case BGP_FLOWSPECV6_NODE:
330 safi = SAFI_FLOWSPEC;
331 break;
d62a17ae 332 default:
333 safi = SAFI_UNICAST;
334 break;
335 }
336 return safi;
718e3744 337}
338
55f91488
QY
339/**
340 * Converts an AFI in string form to afi_t
341 *
342 * @param afi string, one of
343 * - "ipv4"
344 * - "ipv6"
81cf0de5 345 * - "l2vpn"
55f91488
QY
346 * @return the corresponding afi_t
347 */
d62a17ae 348afi_t bgp_vty_afi_from_str(const char *afi_str)
349{
350 afi_t afi = AFI_MAX; /* unknown */
351 if (strmatch(afi_str, "ipv4"))
352 afi = AFI_IP;
353 else if (strmatch(afi_str, "ipv6"))
354 afi = AFI_IP6;
81cf0de5
CS
355 else if (strmatch(afi_str, "l2vpn"))
356 afi = AFI_L2VPN;
d62a17ae 357 return afi;
358}
359
360int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
361 afi_t *afi)
362{
363 int ret = 0;
364 if (argv_find(argv, argc, "ipv4", index)) {
365 ret = 1;
366 if (afi)
367 *afi = AFI_IP;
368 } else if (argv_find(argv, argc, "ipv6", index)) {
369 ret = 1;
370 if (afi)
371 *afi = AFI_IP6;
8688b3e7
DS
372 } else if (argv_find(argv, argc, "l2vpn", index)) {
373 ret = 1;
374 if (afi)
375 *afi = AFI_L2VPN;
d62a17ae 376 }
377 return ret;
46f296b4
LB
378}
379
375a2e67 380/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 381safi_t bgp_vty_safi_from_str(const char *safi_str)
382{
383 safi_t safi = SAFI_MAX; /* unknown */
384 if (strmatch(safi_str, "multicast"))
385 safi = SAFI_MULTICAST;
386 else if (strmatch(safi_str, "unicast"))
387 safi = SAFI_UNICAST;
388 else if (strmatch(safi_str, "vpn"))
389 safi = SAFI_MPLS_VPN;
81cf0de5
CS
390 else if (strmatch(safi_str, "evpn"))
391 safi = SAFI_EVPN;
d62a17ae 392 else if (strmatch(safi_str, "labeled-unicast"))
393 safi = SAFI_LABELED_UNICAST;
7c40bf39 394 else if (strmatch(safi_str, "flowspec"))
395 safi = SAFI_FLOWSPEC;
d62a17ae 396 return safi;
397}
398
399int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
400 safi_t *safi)
401{
402 int ret = 0;
403 if (argv_find(argv, argc, "unicast", index)) {
404 ret = 1;
405 if (safi)
406 *safi = SAFI_UNICAST;
407 } else if (argv_find(argv, argc, "multicast", index)) {
408 ret = 1;
409 if (safi)
410 *safi = SAFI_MULTICAST;
411 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
412 ret = 1;
413 if (safi)
414 *safi = SAFI_LABELED_UNICAST;
415 } else if (argv_find(argv, argc, "vpn", index)) {
416 ret = 1;
417 if (safi)
418 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
419 } else if (argv_find(argv, argc, "evpn", index)) {
420 ret = 1;
421 if (safi)
422 *safi = SAFI_EVPN;
7c40bf39 423 } else if (argv_find(argv, argc, "flowspec", index)) {
424 ret = 1;
425 if (safi)
426 *safi = SAFI_FLOWSPEC;
d62a17ae 427 }
428 return ret;
46f296b4
LB
429}
430
b16bcbba
TA
431/*
432 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
433 *
434 * afi
435 * address-family identifier
436 *
437 * safi
438 * subsequent address-family identifier
439 *
440 * Returns:
441 * default_af string corresponding to the supplied afi/safi pair.
442 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
443 * return -1.
444 */
445static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
446{
447 switch (afi) {
448 case AFI_IP:
449 switch (safi) {
450 case SAFI_UNICAST:
451 return "ipv4-unicast";
452 case SAFI_MULTICAST:
453 return "ipv4-multicast";
454 case SAFI_MPLS_VPN:
455 return "ipv4-vpn";
456 case SAFI_ENCAP:
457 return "ipv4-encap";
458 case SAFI_LABELED_UNICAST:
459 return "ipv4-labeled-unicast";
460 case SAFI_FLOWSPEC:
461 return "ipv4-flowspec";
462 default:
463 return "unknown-afi/safi";
464 }
465 break;
466 case AFI_IP6:
467 switch (safi) {
468 case SAFI_UNICAST:
469 return "ipv6-unicast";
470 case SAFI_MULTICAST:
471 return "ipv6-multicast";
472 case SAFI_MPLS_VPN:
473 return "ipv6-vpn";
474 case SAFI_ENCAP:
475 return "ipv6-encap";
476 case SAFI_LABELED_UNICAST:
477 return "ipv6-labeled-unicast";
478 case SAFI_FLOWSPEC:
479 return "ipv6-flowspec";
480 default:
481 return "unknown-afi/safi";
482 }
483 break;
484 case AFI_L2VPN:
485 switch (safi) {
486 case SAFI_EVPN:
487 return "l2vpn-evpn";
488 default:
489 return "unknown-afi/safi";
490 }
491 case AFI_UNSPEC:
492 case AFI_MAX:
493 return "unknown-afi/safi";
494 }
495 /* all AFIs are accounted for above, so this shouldn't happen */
496 return "unknown-afi/safi";
497}
498
5d5393b9
DL
499int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
500 enum bgp_instance_type inst_type)
501{
502 int ret = bgp_get(bgp, as, name, inst_type);
503
504 if (ret == BGP_CREATED) {
505 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 506 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
507
508 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 509 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 510 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 511 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
512 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
513 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 514 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 515 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 516 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 517 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
518 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
519 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
520 if (DFLT_BGP_SUPPRESS_DUPLICATES)
521 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
522
523 ret = BGP_SUCCESS;
524 }
525 return ret;
526}
527
7eeee51e 528/*
f212a857 529 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 530 *
f212a857
DS
531 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
532 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
533 * to appropriate values for the calling function. This is to allow the
534 * calling function to make decisions appropriate for the show command
535 * that is being parsed.
536 *
537 * The show commands are generally of the form:
d62a17ae 538 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
539 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
540 *
541 * Since we use argv_find if the show command in particular doesn't have:
542 * [ip]
18c57037 543 * [<view|vrf> VIEWVRFNAME]
375a2e67 544 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
545 * The command parsing should still be ok.
546 *
547 * vty -> The vty for the command so we can output some useful data in
548 * the event of a parse error in the vrf.
549 * argv -> The command tokens
550 * argc -> How many command tokens we have
d62a17ae 551 * idx -> The current place in the command, generally should be 0 for this
552 * function
7eeee51e
DS
553 * afi -> The parsed afi if it was included in the show command, returned here
554 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 555 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 556 * use_json -> json is configured or not
7eeee51e
DS
557 *
558 * The function returns the correct location in the parse tree for the
559 * last token found.
0e37c258
DS
560 *
561 * Returns 0 for failure to parse correctly, else the idx position of where
562 * it found the last token.
7eeee51e 563 */
d62a17ae 564int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
565 struct cmd_token **argv, int argc,
566 int *idx, afi_t *afi, safi_t *safi,
9f049418 567 struct bgp **bgp, bool use_json)
d62a17ae 568{
569 char *vrf_name = NULL;
570
571 assert(afi);
572 assert(safi);
573 assert(bgp);
574
575 if (argv_find(argv, argc, "ip", idx))
576 *afi = AFI_IP;
577
9a8bdf1c 578 if (argv_find(argv, argc, "view", idx))
d62a17ae 579 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
580 else if (argv_find(argv, argc, "vrf", idx)) {
581 vrf_name = argv[*idx + 1]->arg;
582 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
583 vrf_name = NULL;
584 }
585 if (vrf_name) {
d62a17ae 586 if (strmatch(vrf_name, "all"))
587 *bgp = NULL;
588 else {
589 *bgp = bgp_lookup_by_name(vrf_name);
590 if (!*bgp) {
52e5b8c4
SP
591 if (use_json) {
592 json_object *json = NULL;
593 json = json_object_new_object();
594 json_object_string_add(
595 json, "warning",
596 "View/Vrf is unknown");
597 vty_out(vty, "%s\n",
598 json_object_to_json_string_ext(json,
599 JSON_C_TO_STRING_PRETTY));
600 json_object_free(json);
601 }
ca61fd25
DS
602 else
603 vty_out(vty, "View/Vrf %s is unknown\n",
604 vrf_name);
d62a17ae 605 *idx = 0;
606 return 0;
607 }
608 }
609 } else {
610 *bgp = bgp_get_default();
611 if (!*bgp) {
52e5b8c4
SP
612 if (use_json) {
613 json_object *json = NULL;
614 json = json_object_new_object();
615 json_object_string_add(
616 json, "warning",
617 "Default BGP instance not found");
618 vty_out(vty, "%s\n",
619 json_object_to_json_string_ext(json,
620 JSON_C_TO_STRING_PRETTY));
621 json_object_free(json);
622 }
ca61fd25
DS
623 else
624 vty_out(vty,
625 "Default BGP instance not found\n");
d62a17ae 626 *idx = 0;
627 return 0;
628 }
629 }
630
631 if (argv_find_and_parse_afi(argv, argc, idx, afi))
632 argv_find_and_parse_safi(argv, argc, idx, safi);
633
634 *idx += 1;
635 return *idx;
636}
637
28c6e247 638static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 639{
640 struct interface *ifp = NULL;
641
642 if (su->sa.sa_family == AF_INET)
643 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
644 else if (su->sa.sa_family == AF_INET6)
645 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
646 su->sin6.sin6_scope_id,
647 bgp->vrf_id);
648
649 if (ifp)
3dc339cd 650 return true;
d62a17ae 651
3dc339cd 652 return false;
718e3744 653}
654
28c6e247
IR
655/* Utility function for looking up peer from VTY. */
656/* This is used only for configuration, so disallow if attempted on
657 * a dynamic neighbor.
658 */
659static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
660{
661 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
662 int ret;
663 union sockunion su;
664 struct peer *peer;
665
666 if (!bgp) {
667 return NULL;
668 }
669
670 ret = str2sockunion(ip_str, &su);
671 if (ret < 0) {
672 peer = peer_lookup_by_conf_if(bgp, ip_str);
673 if (!peer) {
674 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
675 == NULL) {
676 vty_out(vty,
677 "%% Malformed address or name: %s\n",
678 ip_str);
679 return NULL;
680 }
681 }
682 } else {
683 peer = peer_lookup(bgp, &su);
684 if (!peer) {
685 vty_out(vty,
686 "%% Specify remote-as or peer-group commands first\n");
687 return NULL;
688 }
689 if (peer_dynamic_neighbor(peer)) {
690 vty_out(vty,
691 "%% Operation not allowed on a dynamic neighbor\n");
692 return NULL;
693 }
694 }
695 return peer;
696}
697
718e3744 698/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
699/* This is used only for configuration, so disallow if attempted on
700 * a dynamic neighbor.
701 */
d62a17ae 702struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
703{
704 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
705 int ret;
706 union sockunion su;
707 struct peer *peer = NULL;
708 struct peer_group *group = NULL;
709
710 if (!bgp) {
711 return NULL;
712 }
713
714 ret = str2sockunion(peer_str, &su);
715 if (ret == 0) {
716 /* IP address, locate peer. */
717 peer = peer_lookup(bgp, &su);
718 } else {
719 /* Not IP, could match either peer configured on interface or a
720 * group. */
721 peer = peer_lookup_by_conf_if(bgp, peer_str);
722 if (!peer)
723 group = peer_group_lookup(bgp, peer_str);
724 }
725
726 if (peer) {
727 if (peer_dynamic_neighbor(peer)) {
728 vty_out(vty,
729 "%% Operation not allowed on a dynamic neighbor\n");
730 return NULL;
731 }
732
733 return peer;
734 }
735
736 if (group)
737 return group->conf;
738
739 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
740
741 return NULL;
742}
743
744int bgp_vty_return(struct vty *vty, int ret)
745{
746 const char *str = NULL;
747
748 switch (ret) {
749 case BGP_ERR_INVALID_VALUE:
750 str = "Invalid value";
751 break;
752 case BGP_ERR_INVALID_FLAG:
753 str = "Invalid flag";
754 break;
755 case BGP_ERR_PEER_GROUP_SHUTDOWN:
756 str = "Peer-group has been shutdown. Activate the peer-group first";
757 break;
758 case BGP_ERR_PEER_FLAG_CONFLICT:
759 str = "Can't set override-capability and strict-capability-match at the same time";
760 break;
761 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
762 str = "Specify remote-as or peer-group remote AS first";
763 break;
764 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
765 str = "Cannot change the peer-group. Deconfigure first";
766 break;
767 case BGP_ERR_PEER_GROUP_MISMATCH:
768 str = "Peer is not a member of this peer-group";
769 break;
770 case BGP_ERR_PEER_FILTER_CONFLICT:
771 str = "Prefix/distribute list can not co-exist";
772 break;
773 case BGP_ERR_NOT_INTERNAL_PEER:
774 str = "Invalid command. Not an internal neighbor";
775 break;
776 case BGP_ERR_REMOVE_PRIVATE_AS:
777 str = "remove-private-AS cannot be configured for IBGP peers";
778 break;
779 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
780 str = "Local-AS allowed only for EBGP peers";
781 break;
782 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
783 str = "Cannot have local-as same as BGP AS number";
784 break;
785 case BGP_ERR_TCPSIG_FAILED:
786 str = "Error while applying TCP-Sig to session(s)";
787 break;
788 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
789 str = "ebgp-multihop and ttl-security cannot be configured together";
790 break;
791 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
792 str = "ttl-security only allowed for EBGP peers";
793 break;
794 case BGP_ERR_AS_OVERRIDE:
795 str = "as-override cannot be configured for IBGP peers";
796 break;
797 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
798 str = "Invalid limit for number of dynamic neighbors";
799 break;
800 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
801 str = "Dynamic neighbor listen range already exists";
802 break;
803 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
804 str = "Operation not allowed on a dynamic neighbor";
805 break;
806 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
807 str = "Operation not allowed on a directly connected neighbor";
808 break;
809 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 810 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 811 break;
812 case BGP_ERR_GR_INVALID_CMD:
813 str = "The Graceful Restart command used is not valid at this moment.";
814 break;
815 case BGP_ERR_GR_OPERATION_FAILED:
816 str = "The Graceful Restart Operation failed due to an err.";
817 break;
d62a17ae 818 }
819 if (str) {
820 vty_out(vty, "%% %s\n", str);
821 return CMD_WARNING_CONFIG_FAILED;
822 }
823 return CMD_SUCCESS;
718e3744 824}
825
7aafcaca 826/* BGP clear sort. */
d62a17ae 827enum clear_sort {
828 clear_all,
829 clear_peer,
830 clear_group,
831 clear_external,
832 clear_as
7aafcaca
DS
833};
834
1ca2fd11
IR
835static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
836 safi_t safi, int error)
d62a17ae 837{
838 switch (error) {
839 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11
IR
840 vty_out(vty,
841 "%%BGP: Enable %s address family for the neighbor %s\n",
842 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 843 break;
844 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11
IR
845 vty_out(vty,
846 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 847 peer->host);
848 break;
849 default:
850 break;
851 }
7aafcaca
DS
852}
853
dc912615 854static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 855 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
856{
857 int ret = 0;
2adac256 858 struct peer_af *paf;
dc912615
DS
859
860 /* if afi/.safi not specified, spin thru all of them */
861 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
862 afi_t tmp_afi;
863 safi_t tmp_safi;
864
865 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
866 paf = peer_af_find(peer, tmp_afi, tmp_safi);
867 if (paf && paf->subgroup)
868 SET_FLAG(paf->subgroup->sflags,
869 SUBGRP_STATUS_FORCE_UPDATES);
870
dc912615
DS
871 if (!peer->afc[tmp_afi][tmp_safi])
872 continue;
873
874 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 875 ret = peer_clear(peer, nnode);
dc912615
DS
876 else
877 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
878 stype);
879 }
880 /* if afi specified and safi not, spin thru safis on this afi */
881 } else if (safi == SAFI_UNSPEC) {
882 safi_t tmp_safi;
883
884 for (tmp_safi = SAFI_UNICAST;
885 tmp_safi < SAFI_MAX; tmp_safi++) {
886 if (!peer->afc[afi][tmp_safi])
887 continue;
888
2adac256
DA
889 paf = peer_af_find(peer, afi, tmp_safi);
890 if (paf && paf->subgroup)
891 SET_FLAG(paf->subgroup->sflags,
892 SUBGRP_STATUS_FORCE_UPDATES);
893
dc912615 894 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 895 ret = peer_clear(peer, nnode);
dc912615
DS
896 else
897 ret = peer_clear_soft(peer, afi,
898 tmp_safi, stype);
899 }
900 /* both afi/safi specified, let the caller know if not defined */
901 } else {
902 if (!peer->afc[afi][safi])
903 return 1;
904
2adac256
DA
905 paf = peer_af_find(peer, afi, safi);
906 if (paf && paf->subgroup)
907 SET_FLAG(paf->subgroup->sflags,
908 SUBGRP_STATUS_FORCE_UPDATES);
909
dc912615 910 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 911 ret = peer_clear(peer, nnode);
dc912615
DS
912 else
913 ret = peer_clear_soft(peer, afi, safi, stype);
914 }
915
916 return ret;
917}
918
7aafcaca 919/* `clear ip bgp' functions. */
1ca2fd11 920static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 921 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 922 const char *arg)
d62a17ae 923{
dc912615 924 int ret = 0;
3ae8bfa5 925 bool found = false;
d62a17ae 926 struct peer *peer;
dc95985f 927
928 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 929
930 /* Clear all neighbors. */
931 /*
932 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
933 * nodes on the BGP instance as that may get freed if it is a
934 * doppelganger
d62a17ae 935 */
936 if (sort == clear_all) {
937 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 938
939 bgp_peer_gr_flags_update(peer);
940
36235319 941 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 942 gr_router_detected = true;
943
c368171c 944 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 945 stype);
d62a17ae 946
947 if (ret < 0)
1ca2fd11 948 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 949 }
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);
04b6bdc0 957 }
d62a17ae 958
959 /* This is to apply read-only mode on this clear. */
960 if (stype == BGP_CLEAR_SOFT_NONE)
961 bgp->update_delay_over = 0;
962
963 return CMD_SUCCESS;
7aafcaca
DS
964 }
965
3ae8bfa5 966 /* Clear specified neighbor. */
d62a17ae 967 if (sort == clear_peer) {
968 union sockunion su;
d62a17ae 969
970 /* Make sockunion for lookup. */
971 ret = str2sockunion(arg, &su);
972 if (ret < 0) {
973 peer = peer_lookup_by_conf_if(bgp, arg);
974 if (!peer) {
975 peer = peer_lookup_by_hostname(bgp, arg);
976 if (!peer) {
1ca2fd11
IR
977 vty_out(vty,
978 "Malformed address or name: %s\n",
d62a17ae 979 arg);
980 return CMD_WARNING;
981 }
982 }
983 } else {
984 peer = peer_lookup(bgp, &su);
985 if (!peer) {
1ca2fd11
IR
986 vty_out(vty,
987 "%%BGP: Unknown neighbor - \"%s\"\n",
988 arg);
d62a17ae 989 return CMD_WARNING;
990 }
991 }
7aafcaca 992
dc95985f 993 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
994 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
995
dc912615
DS
996 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
997
998 /* if afi/safi not defined for this peer, let caller know */
999 if (ret == 1)
3ae8bfa5 1000 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1001
d62a17ae 1002 if (ret < 0)
1ca2fd11 1003 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1004
d62a17ae 1005 return CMD_SUCCESS;
7aafcaca 1006 }
7aafcaca 1007
3ae8bfa5 1008 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1009 if (sort == clear_group) {
1010 struct peer_group *group;
7aafcaca 1011
d62a17ae 1012 group = peer_group_lookup(bgp, arg);
1013 if (!group) {
1ca2fd11 1014 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
d62a17ae 1015 return CMD_WARNING;
1016 }
1017
1018 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1019 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1020
d62a17ae 1021 if (ret < 0)
1ca2fd11 1022 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1023 else
1024 found = true;
d62a17ae 1025 }
3ae8bfa5
PM
1026
1027 if (!found)
1ca2fd11
IR
1028 vty_out(vty,
1029 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1030 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1031
d62a17ae 1032 return CMD_SUCCESS;
7aafcaca 1033 }
7aafcaca 1034
3ae8bfa5 1035 /* Clear all external (eBGP) neighbors. */
d62a17ae 1036 if (sort == clear_external) {
1037 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1038 if (peer->sort == BGP_PEER_IBGP)
1039 continue;
7aafcaca 1040
dc95985f 1041 bgp_peer_gr_flags_update(peer);
1042
36235319 1043 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1044 gr_router_detected = true;
dc95985f 1045
c368171c 1046 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1047
d62a17ae 1048 if (ret < 0)
1ca2fd11 1049 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1050 else
1051 found = true;
d62a17ae 1052 }
3ae8bfa5 1053
36235319
QY
1054 if (gr_router_detected
1055 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1056 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1057 } else if (!gr_router_detected
1058 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1059 bgp_zebra_send_capabilities(bgp, true);
1060 }
1061
3ae8bfa5 1062 if (!found)
1ca2fd11
IR
1063 vty_out(vty,
1064 "%%BGP: No external %s peer is configured\n",
1065 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1066
d62a17ae 1067 return CMD_SUCCESS;
1068 }
1069
3ae8bfa5 1070 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1071 if (sort == clear_as) {
3ae8bfa5 1072 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1073
1074 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1075 if (peer->as != as)
1076 continue;
1077
dc95985f 1078 bgp_peer_gr_flags_update(peer);
1079
36235319 1080 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1081 gr_router_detected = true;
dc95985f 1082
c368171c 1083 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1084
1085 if (ret < 0)
1ca2fd11 1086 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1087 else
1088 found = true;
d62a17ae 1089 }
3ae8bfa5 1090
36235319
QY
1091 if (gr_router_detected
1092 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1093 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1094 } else if (!gr_router_detected
1095 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1096 bgp_zebra_send_capabilities(bgp, true);
1097 }
1098
3ae8bfa5 1099 if (!found)
1ca2fd11
IR
1100 vty_out(vty,
1101 "%%BGP: No %s peer is configured with AS %s\n",
1102 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1103
d62a17ae 1104 return CMD_SUCCESS;
1105 }
1106
1107 return CMD_SUCCESS;
1108}
1109
1ca2fd11
IR
1110static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1111 safi_t safi, enum clear_sort sort,
1112 enum bgp_clear_type stype, const char *arg)
d62a17ae 1113{
1114 struct bgp *bgp;
1115
1116 /* BGP structure lookup. */
1117 if (name) {
1118 bgp = bgp_lookup_by_name(name);
1119 if (bgp == NULL) {
1ca2fd11 1120 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1121 return CMD_WARNING;
1122 }
1123 } else {
1124 bgp = bgp_get_default();
1125 if (bgp == NULL) {
1ca2fd11 1126 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1127 return CMD_WARNING;
1128 }
1129 }
1130
1ca2fd11 1131 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1132}
1133
1134/* clear soft inbound */
1ca2fd11 1135static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1136{
99b3ebd3
NS
1137 afi_t afi;
1138 safi_t safi;
1139
1ca2fd11
IR
1140 FOREACH_AFI_SAFI (afi, safi)
1141 bgp_clear_vty(vty, name, afi, safi, clear_all,
1142 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1143}
1144
1145/* clear soft outbound */
1ca2fd11 1146static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1147{
99b3ebd3
NS
1148 afi_t afi;
1149 safi_t safi;
1150
1ca2fd11
IR
1151 FOREACH_AFI_SAFI (afi, safi)
1152 bgp_clear_vty(vty, name, afi, safi, clear_all,
1153 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1154}
1155
1156
f787d7a0 1157#ifndef VTYSH_EXTRACT_PL
2e4c2296 1158#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1159#endif
1160
8029b216
AK
1161DEFUN_HIDDEN (bgp_local_mac,
1162 bgp_local_mac_cmd,
093e3f23 1163 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1164 BGP_STR
1165 "Local MAC config\n"
1166 "VxLAN Network Identifier\n"
1167 "VNI number\n"
1168 "local mac\n"
1169 "mac address\n"
1170 "mac-mobility sequence\n"
1171 "seq number\n")
1172{
1173 int rv;
1174 vni_t vni;
1175 struct ethaddr mac;
1176 struct ipaddr ip;
1177 uint32_t seq;
1178 struct bgp *bgp;
1179
1180 vni = strtoul(argv[3]->arg, NULL, 10);
1181 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1182 vty_out(vty, "%% Malformed MAC address\n");
1183 return CMD_WARNING;
1184 }
1185 memset(&ip, 0, sizeof(ip));
1186 seq = strtoul(argv[7]->arg, NULL, 10);
1187
1188 bgp = bgp_get_default();
1189 if (!bgp) {
1190 vty_out(vty, "Default BGP instance is not there\n");
1191 return CMD_WARNING;
1192 }
1193
b5e140c8
AK
1194 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1195 zero_esi);
8029b216
AK
1196 if (rv < 0) {
1197 vty_out(vty, "Internal error\n");
1198 return CMD_WARNING;
1199 }
1200
1201 return CMD_SUCCESS;
1202}
1203
1204DEFUN_HIDDEN (no_bgp_local_mac,
1205 no_bgp_local_mac_cmd,
093e3f23 1206 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1207 NO_STR
1208 BGP_STR
1209 "Local MAC config\n"
1210 "VxLAN Network Identifier\n"
1211 "VNI number\n"
1212 "local mac\n"
1213 "mac address\n")
1214{
1215 int rv;
1216 vni_t vni;
1217 struct ethaddr mac;
1218 struct ipaddr ip;
1219 struct bgp *bgp;
1220
1221 vni = strtoul(argv[4]->arg, NULL, 10);
1222 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1223 vty_out(vty, "%% Malformed MAC address\n");
1224 return CMD_WARNING;
1225 }
1226 memset(&ip, 0, sizeof(ip));
1227
1228 bgp = bgp_get_default();
1229 if (!bgp) {
1230 vty_out(vty, "Default BGP instance is not there\n");
1231 return CMD_WARNING;
1232 }
1233
ec0ab544 1234 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1235 if (rv < 0) {
1236 vty_out(vty, "Internal error\n");
1237 return CMD_WARNING;
1238 }
1239
1240 return CMD_SUCCESS;
1241}
1242
718e3744 1243DEFUN (no_synchronization,
1244 no_synchronization_cmd,
1245 "no synchronization",
1246 NO_STR
1247 "Perform IGP synchronization\n")
1248{
d62a17ae 1249 return CMD_SUCCESS;
718e3744 1250}
1251
1252DEFUN (no_auto_summary,
1253 no_auto_summary_cmd,
1254 "no auto-summary",
1255 NO_STR
1256 "Enable automatic network number summarization\n")
1257{
d62a17ae 1258 return CMD_SUCCESS;
718e3744 1259}
3d515fd9 1260
718e3744 1261/* "router bgp" commands. */
1ca2fd11
IR
1262DEFUN_NOSH (router_bgp,
1263 router_bgp_cmd,
1264 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1265 ROUTER_STR
1266 BGP_STR
1267 AS_STR
1268 BGP_INSTANCE_HELP_STR)
718e3744 1269{
d62a17ae 1270 int idx_asn = 2;
1271 int idx_view_vrf = 3;
1272 int idx_vrf = 4;
1ca2fd11
IR
1273 int is_new_bgp = 0;
1274 int ret;
d62a17ae 1275 as_t as;
1276 struct bgp *bgp;
1277 const char *name = NULL;
1278 enum bgp_instance_type inst_type;
1279
1280 // "router bgp" without an ASN
1281 if (argc == 2) {
1282 // Pending: Make VRF option available for ASN less config
1abef40f 1283 bgp = bgp_get_default();
d62a17ae 1284
1abef40f 1285 if (bgp == NULL) {
d62a17ae 1286 vty_out(vty, "%% No BGP process is configured\n");
1287 return CMD_WARNING_CONFIG_FAILED;
1288 }
1289
1290 if (listcount(bm->bgp) > 1) {
996c9314 1291 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1292 return CMD_WARNING_CONFIG_FAILED;
1293 }
1294 }
1295
1296 // "router bgp X"
1297 else {
ff8a8a7a 1298 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1299
d62a17ae 1300 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1301 if (argc > 3) {
1302 name = argv[idx_vrf]->arg;
1303
9a8bdf1c
PG
1304 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1305 if (strmatch(name, VRF_DEFAULT_NAME))
1306 name = NULL;
1307 else
1308 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1309 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1310 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1311 }
1312
1ca2fd11
IR
1313 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1314 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1315
1ca2fd11
IR
1316 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1317 switch (ret) {
1318 case BGP_ERR_AS_MISMATCH:
1319 vty_out(vty, "BGP is already running; AS is %u\n", as);
1320 return CMD_WARNING_CONFIG_FAILED;
1321 case BGP_ERR_INSTANCE_MISMATCH:
1322 vty_out(vty,
1323 "BGP instance name and AS number mismatch\n");
1324 vty_out(vty,
1325 "BGP instance is already running; AS is %u\n",
1326 as);
1327 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1328 }
1ca2fd11
IR
1329
1330 /*
1331 * If we just instantiated the default instance, complete
1332 * any pending VRF-VPN leaking that was configured via
1333 * earlier "router bgp X vrf FOO" blocks.
1334 */
1335 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1336 vpn_leak_postchange_all();
1337
1338 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1339 bgp_vpn_leak_export(bgp);
1340 /* Pending: handle when user tries to change a view to vrf n vv.
1341 */
d62a17ae 1342 }
1343
1ca2fd11
IR
1344 /* unset the auto created flag as the user config is now present */
1345 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1346 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1347
1348 return CMD_SUCCESS;
718e3744 1349}
1350
718e3744 1351/* "no router bgp" commands. */
1ca2fd11
IR
1352DEFUN (no_router_bgp,
1353 no_router_bgp_cmd,
1354 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1355 NO_STR
1356 ROUTER_STR
1357 BGP_STR
1358 AS_STR
1359 BGP_INSTANCE_HELP_STR)
718e3744 1360{
4fd9919e 1361 int idx_asn = 3;
d62a17ae 1362 int idx_vrf = 5;
1ca2fd11 1363 as_t as;
4fd9919e 1364 struct bgp *bgp;
d62a17ae 1365 const char *name = NULL;
718e3744 1366
d62a17ae 1367 // "no router bgp" without an ASN
1368 if (argc == 3) {
1369 // Pending: Make VRF option available for ASN less config
8382083a 1370 bgp = bgp_get_default();
718e3744 1371
8382083a 1372 if (bgp == NULL) {
d62a17ae 1373 vty_out(vty, "%% No BGP process is configured\n");
1374 return CMD_WARNING_CONFIG_FAILED;
1375 }
7fb21a9f 1376
d62a17ae 1377 if (listcount(bm->bgp) > 1) {
996c9314 1378 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1379 return CMD_WARNING_CONFIG_FAILED;
1380 }
4fd9919e 1381
4fd9919e
IR
1382 if (bgp->l3vni) {
1383 vty_out(vty, "%% Please unconfigure l3vni %u",
1384 bgp->l3vni);
1385 return CMD_WARNING_CONFIG_FAILED;
1386 }
d62a17ae 1387 } else {
4fd9919e
IR
1388 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1389
d62a17ae 1390 if (argc > 4)
1391 name = argv[idx_vrf]->arg;
7fb21a9f 1392
4fd9919e
IR
1393 /* Lookup bgp structure. */
1394 bgp = bgp_lookup(as, name);
1395 if (!bgp) {
1396 vty_out(vty, "%% Can't find BGP instance\n");
1397 return CMD_WARNING_CONFIG_FAILED;
1398 }
1399
1400 if (bgp->l3vni) {
1401 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1402 bgp->l3vni);
1403 return CMD_WARNING_CONFIG_FAILED;
1404 }
1405
1406 /* Cannot delete default instance if vrf instances exist */
1407 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1408 struct listnode *node;
1409 struct bgp *tmp_bgp;
1410
1411 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1412 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1413 continue;
1414 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1415 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1416 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1417 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1418 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1419 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1420 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1421 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1422 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1423 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1424 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1425 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1426 (bgp == bgp_get_evpn() &&
1427 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1428 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1429 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1430 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1431 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1432 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1433 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1434 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1435 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1436 vty_out(vty,
1437 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1438 return CMD_WARNING_CONFIG_FAILED;
1439 }
1440 }
1441 }
d62a17ae 1442 }
718e3744 1443
1ca2fd11 1444 bgp_delete(bgp);
718e3744 1445
1ca2fd11 1446 return CMD_SUCCESS;
718e3744 1447}
1448
718e3744 1449
ff8a8a7a
CS
1450/* BGP router-id. */
1451
1ca2fd11
IR
1452DEFPY (bgp_router_id,
1453 bgp_router_id_cmd,
1454 "bgp router-id A.B.C.D",
1455 BGP_STR
1456 "Override configured router identifier\n"
1457 "Manually configured router identifier\n")
718e3744 1458{
1ca2fd11
IR
1459 VTY_DECLVAR_CONTEXT(bgp, bgp);
1460 bgp_router_id_static_set(bgp, router_id);
1461 return CMD_SUCCESS;
ff8a8a7a 1462}
718e3744 1463
1ca2fd11
IR
1464DEFPY (no_bgp_router_id,
1465 no_bgp_router_id_cmd,
1466 "no bgp router-id [A.B.C.D]",
1467 NO_STR
1468 BGP_STR
1469 "Override configured router identifier\n"
1470 "Manually configured router identifier\n")
ff8a8a7a 1471{
1ca2fd11 1472 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1473
1ca2fd11
IR
1474 if (router_id_str) {
1475 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1476 vty_out(vty, "%% BGP router-id doesn't match\n");
1477 return CMD_WARNING_CONFIG_FAILED;
1478 }
1479 }
718e3744 1480
1ca2fd11
IR
1481 router_id.s_addr = 0;
1482 bgp_router_id_static_set(bgp, router_id);
1483
1484 return CMD_SUCCESS;
ff8a8a7a 1485}
6b0655a2 1486
ed0e57e3 1487DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1488 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1489 NO_STR BGP_STR
1490 "Add community specific parameters\n"
1491 "Create an alias for a community\n"
1492 "Community (AA:BB or AA:BB:CC)\n"
1493 "Alias name\n")
1494{
1495 struct community_alias ca1;
1496 struct community_alias ca2;
1497 struct community_alias *lookup_community;
1498 struct community_alias *lookup_alias;
1499
1500 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1501 vty_out(vty, "Invalid community format\n");
1502 return CMD_WARNING;
1503 }
1504
1505 memset(&ca1, 0, sizeof(ca1));
1506 memset(&ca2, 0, sizeof(ca2));
1507 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1508 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1509
1510 lookup_community = bgp_ca_community_lookup(&ca1);
1511 lookup_alias = bgp_ca_alias_lookup(&ca1);
1512
1513 if (no) {
1514 bgp_ca_alias_delete(&ca1);
1515 bgp_ca_community_delete(&ca1);
1516 } else {
1517 if (lookup_alias) {
1518 /* Lookup if community hash table has an item
1519 * with the same alias name.
1520 */
1521 strlcpy(ca2.community, lookup_alias->community,
1522 sizeof(ca2.community));
1523 if (bgp_ca_community_lookup(&ca2)) {
1524 vty_out(vty,
1525 "community (%s) already has this alias (%s)\n",
1526 lookup_alias->community,
1527 lookup_alias->alias);
1528 return CMD_WARNING;
1529 }
1530 bgp_ca_alias_delete(&ca1);
1531 }
1532
1533 if (lookup_community)
1534 bgp_ca_community_delete(&ca1);
1535
1536 bgp_ca_alias_insert(&ca1);
1537 bgp_ca_community_insert(&ca1);
1538 }
1539
1540 return CMD_SUCCESS;
1541}
1542
9acb67cb
DS
1543DEFPY (bgp_global_suppress_fib_pending,
1544 bgp_global_suppress_fib_pending_cmd,
1545 "[no] bgp suppress-fib-pending",
1546 NO_STR
1547 BGP_STR
1548 "Advertise only routes that are programmed in kernel to peers globally\n")
1549{
1550 bm_wait_for_fib_set(!no);
1551
1552 return CMD_SUCCESS;
1553}
1554
c208c586
S
1555DEFPY (bgp_suppress_fib_pending,
1556 bgp_suppress_fib_pending_cmd,
1557 "[no] bgp suppress-fib-pending",
1558 NO_STR
1559 BGP_STR
1560 "Advertise only routes that are programmed in kernel to peers\n")
1561{
1562 VTY_DECLVAR_CONTEXT(bgp, bgp);
1563
1564 bgp_suppress_fib_pending_set(bgp, !no);
1565 return CMD_SUCCESS;
1566}
1567
1568
718e3744 1569/* BGP Cluster ID. */
1ca2fd11
IR
1570DEFUN (bgp_cluster_id,
1571 bgp_cluster_id_cmd,
1572 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1573 BGP_STR
1574 "Configure Route-Reflector Cluster-id\n"
1575 "Route-Reflector Cluster-id in IP address format\n"
1576 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1577{
1ca2fd11 1578 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1579 int idx_ipv4 = 2;
1ca2fd11
IR
1580 int ret;
1581 struct in_addr cluster;
1582
1583 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1584 if (!ret) {
1585 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1586 return CMD_WARNING_CONFIG_FAILED;
1587 }
718e3744 1588
1ca2fd11
IR
1589 bgp_cluster_id_set(bgp, &cluster);
1590 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1591
1ca2fd11 1592 return CMD_SUCCESS;
718e3744 1593}
1594
1ca2fd11
IR
1595DEFUN (no_bgp_cluster_id,
1596 no_bgp_cluster_id_cmd,
1597 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1598 NO_STR
1599 BGP_STR
1600 "Configure Route-Reflector Cluster-id\n"
1601 "Route-Reflector Cluster-id in IP address format\n"
1602 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1603{
1ca2fd11
IR
1604 VTY_DECLVAR_CONTEXT(bgp, bgp);
1605 bgp_cluster_id_unset(bgp);
1606 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1607
1ca2fd11 1608 return CMD_SUCCESS;
718e3744 1609}
1610
c163f297
DS
1611DEFPY (bgp_norib,
1612 bgp_norib_cmd,
1613 "bgp no-rib",
1614 BGP_STR
1615 "Disable BGP route installation to RIB (Zebra)\n")
1616{
1617 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1618 vty_out(vty,
1619 "%% No-RIB option is already set, nothing to do here.\n");
1620 return CMD_SUCCESS;
1621 }
1622
1623 bgp_option_norib_set_runtime();
1624
1625 return CMD_SUCCESS;
1626}
1627
1628DEFPY (no_bgp_norib,
1629 no_bgp_norib_cmd,
1630 "no bgp no-rib",
1631 NO_STR
1632 BGP_STR
1633 "Disable BGP route installation to RIB (Zebra)\n")
1634{
1635 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1636 vty_out(vty,
1637 "%% No-RIB option is not set, nothing to do here.\n");
1638 return CMD_SUCCESS;
1639 }
1640
1641 bgp_option_norib_unset_runtime();
1642
1643 return CMD_SUCCESS;
1644}
1645
e46723a5
DS
1646DEFPY (no_bgp_send_extra_data,
1647 no_bgp_send_extra_data_cmd,
1648 "[no] bgp send-extra-data zebra",
1649 NO_STR
1650 BGP_STR
1651 "Extra data to Zebra for display/use\n"
1652 "To zebra\n")
1653{
ec0acb80
DA
1654 if (no)
1655 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1656 else
1657 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1658
1659 return CMD_SUCCESS;
1660}
1661
1ca2fd11
IR
1662DEFUN (bgp_confederation_identifier,
1663 bgp_confederation_identifier_cmd,
1664 "bgp confederation identifier (1-4294967295)",
1665 "BGP specific commands\n"
1666 "AS confederation parameters\n"
1667 "AS number\n"
1668 "Set routing domain confederation AS\n")
718e3744 1669{
1ca2fd11 1670 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1671 int idx_number = 3;
1ca2fd11 1672 as_t as;
718e3744 1673
1ca2fd11 1674 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1675
1ca2fd11 1676 bgp_confederation_id_set(bgp, as);
718e3744 1677
1ca2fd11 1678 return CMD_SUCCESS;
718e3744 1679}
1680
1ca2fd11
IR
1681DEFUN (no_bgp_confederation_identifier,
1682 no_bgp_confederation_identifier_cmd,
1683 "no bgp confederation identifier [(1-4294967295)]",
1684 NO_STR
1685 "BGP specific commands\n"
1686 "AS confederation parameters\n"
1687 "AS number\n"
1688 "Set routing domain confederation AS\n")
ff8a8a7a 1689{
1ca2fd11
IR
1690 VTY_DECLVAR_CONTEXT(bgp, bgp);
1691 bgp_confederation_id_unset(bgp);
1692
1693 return CMD_SUCCESS;
ff8a8a7a
CS
1694}
1695
1ca2fd11
IR
1696DEFUN (bgp_confederation_peers,
1697 bgp_confederation_peers_cmd,
1698 "bgp confederation peers (1-4294967295)...",
1699 "BGP specific commands\n"
1700 "AS confederation parameters\n"
1701 "Peer ASs in BGP confederation\n"
1702 AS_STR)
718e3744 1703{
1ca2fd11 1704 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1705 int idx_asn = 3;
1ca2fd11 1706 as_t as;
d62a17ae 1707 int i;
718e3744 1708
1ca2fd11
IR
1709 for (i = idx_asn; i < argc; i++) {
1710 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1711
1ca2fd11
IR
1712 if (bgp->as == as) {
1713 vty_out(vty,
1714 "%% Local member-AS not allowed in confed peer list\n");
1715 continue;
1716 }
1717
1718 bgp_confederation_peers_add(bgp, as);
1719 }
1720 return CMD_SUCCESS;
718e3744 1721}
1722
1ca2fd11
IR
1723DEFUN (no_bgp_confederation_peers,
1724 no_bgp_confederation_peers_cmd,
1725 "no bgp confederation peers (1-4294967295)...",
1726 NO_STR
1727 "BGP specific commands\n"
1728 "AS confederation parameters\n"
1729 "Peer ASs in BGP confederation\n"
1730 AS_STR)
718e3744 1731{
1ca2fd11 1732 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1733 int idx_asn = 4;
1ca2fd11 1734 as_t as;
d62a17ae 1735 int i;
718e3744 1736
1ca2fd11
IR
1737 for (i = idx_asn; i < argc; i++) {
1738 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1739
1ca2fd11
IR
1740 bgp_confederation_peers_remove(bgp, as);
1741 }
1742 return CMD_SUCCESS;
718e3744 1743}
6b0655a2 1744
5e242b0d
DS
1745/**
1746 * Central routine for maximum-paths configuration.
1747 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1748 * @set: 1 for setting values, 0 for removing the max-paths config.
1749 */
585f1adc
IR
1750static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1751 const char *mpaths, uint16_t options,
1752 int set)
d62a17ae 1753{
585f1adc
IR
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755 uint16_t maxpaths = 0;
d62a17ae 1756 int ret;
585f1adc
IR
1757 afi_t afi;
1758 safi_t safi;
1759
1760 afi = bgp_node_afi(vty);
1761 safi = bgp_node_safi(vty);
d62a17ae 1762
1763 if (set) {
585f1adc 1764 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1765 if (maxpaths > multipath_num) {
585f1adc 1766 vty_out(vty,
d62a17ae 1767 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1768 maxpaths, multipath_num);
1769 return CMD_WARNING_CONFIG_FAILED;
1770 }
1771 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1772 options);
1773 } else
1774 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1775
1776 if (ret < 0) {
585f1adc 1777 vty_out(vty,
d62a17ae 1778 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1779 (set == 1) ? "" : "un",
1780 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1781 maxpaths, afi, safi);
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
1784
1785 bgp_recalculate_all_bestpaths(bgp);
1786
1787 return CMD_SUCCESS;
165b5fff
JB
1788}
1789
1ca2fd11
IR
1790DEFUN (bgp_maxmed_admin,
1791 bgp_maxmed_admin_cmd,
1792 "bgp max-med administrative ",
1793 BGP_STR
1794 "Advertise routes with max-med\n"
1795 "Administratively applied, for an indefinite period\n")
abc920f8 1796{
1ca2fd11 1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1798
1ca2fd11
IR
1799 bgp->v_maxmed_admin = 1;
1800 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1801
1ca2fd11 1802 bgp_maxmed_update(bgp);
abc920f8 1803
1ca2fd11 1804 return CMD_SUCCESS;
ff8a8a7a
CS
1805}
1806
1ca2fd11
IR
1807DEFUN (bgp_maxmed_admin_medv,
1808 bgp_maxmed_admin_medv_cmd,
1809 "bgp max-med administrative (0-4294967295)",
1810 BGP_STR
1811 "Advertise routes with max-med\n"
1812 "Administratively applied, for an indefinite period\n"
1813 "Max MED value to be used\n")
abc920f8 1814{
1ca2fd11 1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1816 int idx_number = 3;
abc920f8 1817
1ca2fd11
IR
1818 bgp->v_maxmed_admin = 1;
1819 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1820
1ca2fd11 1821 bgp_maxmed_update(bgp);
abc920f8 1822
1ca2fd11 1823 return CMD_SUCCESS;
abc920f8
DS
1824}
1825
1ca2fd11
IR
1826DEFUN (no_bgp_maxmed_admin,
1827 no_bgp_maxmed_admin_cmd,
1828 "no bgp max-med administrative [(0-4294967295)]",
1829 NO_STR
1830 BGP_STR
1831 "Advertise routes with max-med\n"
1832 "Administratively applied, for an indefinite period\n"
1833 "Max MED value to be used\n")
abc920f8 1834{
1ca2fd11
IR
1835 VTY_DECLVAR_CONTEXT(bgp, bgp);
1836 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1837 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1838 bgp_maxmed_update(bgp);
ff8a8a7a 1839
1ca2fd11 1840 return CMD_SUCCESS;
abc920f8
DS
1841}
1842
1ca2fd11
IR
1843DEFUN (bgp_maxmed_onstartup,
1844 bgp_maxmed_onstartup_cmd,
1845 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1846 BGP_STR
1847 "Advertise routes with max-med\n"
1848 "Effective on a startup\n"
1849 "Time (seconds) period for max-med\n"
1850 "Max MED value to be used\n")
abc920f8 1851{
1ca2fd11 1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1853 int idx = 0;
4668a151 1854
d62a17ae 1855 argv_find(argv, argc, "(5-86400)", &idx);
1ca2fd11 1856 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1857 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1858 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1859 else
1ca2fd11 1860 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1861
1ca2fd11
IR
1862 bgp_maxmed_update(bgp);
1863
1864 return CMD_SUCCESS;
abc920f8
DS
1865}
1866
1ca2fd11
IR
1867DEFUN (no_bgp_maxmed_onstartup,
1868 no_bgp_maxmed_onstartup_cmd,
1869 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1870 NO_STR
1871 BGP_STR
1872 "Advertise routes with max-med\n"
1873 "Effective on a startup\n"
1874 "Time (seconds) period for max-med\n"
1875 "Max MED value to be used\n")
abc920f8 1876{
1ca2fd11
IR
1877 VTY_DECLVAR_CONTEXT(bgp, bgp);
1878
1879 /* Cancel max-med onstartup if its on */
1880 if (bgp->t_maxmed_onstartup) {
1881 thread_cancel(&bgp->t_maxmed_onstartup);
1882 bgp->maxmed_onstartup_over = 1;
1883 }
abc920f8 1884
1ca2fd11
IR
1885 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1886 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1887
1ca2fd11
IR
1888 bgp_maxmed_update(bgp);
1889
1890 return CMD_SUCCESS;
abc920f8
DS
1891}
1892
d70583f7
D
1893static int bgp_global_update_delay_config_vty(struct vty *vty,
1894 uint16_t update_delay,
1895 uint16_t establish_wait)
1896{
1897 struct listnode *node, *nnode;
1898 struct bgp *bgp;
1899 bool vrf_cfg = false;
1900
1901 /*
1902 * See if update-delay is set per-vrf and warn user to delete it
1903 * Note that we only need to check this if this is the first time
1904 * setting the global config.
1905 */
1906 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1907 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1908 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1909 vty_out(vty,
1910 "%% update-delay configuration found in vrf %s\n",
1911 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1912 ? VRF_DEFAULT_NAME
1913 : bgp->name);
1914 vrf_cfg = true;
1915 }
1916 }
1917 }
1918
1919 if (vrf_cfg) {
1920 vty_out(vty,
1921 "%%Failed: global update-delay config not permitted\n");
1922 return CMD_WARNING;
1923 }
1924
1925 if (!establish_wait) { /* update-delay <delay> */
1926 bm->v_update_delay = update_delay;
1927 bm->v_establish_wait = bm->v_update_delay;
1928 } else {
1929 /* update-delay <delay> <establish-wait> */
1930 if (update_delay < establish_wait) {
1931 vty_out(vty,
1932 "%%Failed: update-delay less than the establish-wait!\n");
1933 return CMD_WARNING_CONFIG_FAILED;
1934 }
1935
1936 bm->v_update_delay = update_delay;
1937 bm->v_establish_wait = establish_wait;
1938 }
1939
1940 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1941 bgp->v_update_delay = bm->v_update_delay;
1942 bgp->v_establish_wait = bm->v_establish_wait;
1943 }
1944
1945 return CMD_SUCCESS;
1946}
1947
1948static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1949{
1950 struct listnode *node, *nnode;
1951 struct bgp *bgp;
1952
1953 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1954 bm->v_establish_wait = bm->v_update_delay;
1955
1956 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1957 bgp->v_update_delay = bm->v_update_delay;
1958 bgp->v_establish_wait = bm->v_establish_wait;
1959 }
1960
1961 return CMD_SUCCESS;
1962}
1963
1964static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1965 uint16_t establish_wait)
f188f2c4 1966{
d62a17ae 1967 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1968
d70583f7
D
1969 /* if configured globally, per-instance config is not allowed */
1970 if (bm->v_update_delay) {
1971 vty_out(vty,
1972 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1973 return CMD_WARNING_CONFIG_FAILED;
1974 }
1975
f188f2c4 1976
d70583f7 1977 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1978 {
1979 bgp->v_update_delay = update_delay;
1980 bgp->v_establish_wait = bgp->v_update_delay;
1981 return CMD_SUCCESS;
1982 }
f188f2c4 1983
d62a17ae 1984 /* update-delay <delay> <establish-wait> */
d62a17ae 1985 if (update_delay < establish_wait) {
1986 vty_out(vty,
1987 "%%Failed: update-delay less than the establish-wait!\n");
1988 return CMD_WARNING_CONFIG_FAILED;
1989 }
f188f2c4 1990
d62a17ae 1991 bgp->v_update_delay = update_delay;
1992 bgp->v_establish_wait = establish_wait;
f188f2c4 1993
d62a17ae 1994 return CMD_SUCCESS;
f188f2c4
DS
1995}
1996
d62a17ae 1997static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1998{
d62a17ae 1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2000
d70583f7
D
2001 /* If configured globally, cannot remove from one bgp instance */
2002 if (bm->v_update_delay) {
2003 vty_out(vty,
2004 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2005 return CMD_WARNING_CONFIG_FAILED;
2006 }
d62a17ae 2007 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2008 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2009
d62a17ae 2010 return CMD_SUCCESS;
f188f2c4
DS
2011}
2012
2b791107 2013void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2014{
d70583f7
D
2015 /* If configured globally, no need to display per-instance value */
2016 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2017 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2018 if (bgp->v_update_delay != bgp->v_establish_wait)
2019 vty_out(vty, " %d", bgp->v_establish_wait);
2020 vty_out(vty, "\n");
2021 }
f188f2c4
DS
2022}
2023
d70583f7
D
2024/* Global update-delay configuration */
2025DEFPY (bgp_global_update_delay,
2026 bgp_global_update_delay_cmd,
2027 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2028 BGP_STR
2029 "Force initial delay for best-path and updates for all bgp instances\n"
2030 "Max delay in seconds\n"
2031 "Establish wait in seconds\n")
2032{
2033 return bgp_global_update_delay_config_vty(vty, delay, wait);
2034}
f188f2c4 2035
d70583f7
D
2036/* Global update-delay deconfiguration */
2037DEFPY (no_bgp_global_update_delay,
2038 no_bgp_global_update_delay_cmd,
2039 "no bgp update-delay [(0-3600) [(1-3600)]]",
2040 NO_STR
2041 BGP_STR
f188f2c4 2042 "Force initial delay for best-path and updates\n"
d70583f7
D
2043 "Max delay in seconds\n"
2044 "Establish wait in seconds\n")
f188f2c4 2045{
d70583f7 2046 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2047}
2048
d70583f7
D
2049/* Update-delay configuration */
2050
2051DEFPY (bgp_update_delay,
2052 bgp_update_delay_cmd,
2053 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2054 "Force initial delay for best-path and updates\n"
d70583f7
D
2055 "Max delay in seconds\n"
2056 "Establish wait in seconds\n")
f188f2c4 2057{
d70583f7 2058 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2059}
2060
2061/* Update-delay deconfiguration */
d70583f7 2062DEFPY (no_bgp_update_delay,
f188f2c4 2063 no_bgp_update_delay_cmd,
838758ac
DW
2064 "no update-delay [(0-3600) [(1-3600)]]",
2065 NO_STR
f188f2c4 2066 "Force initial delay for best-path and updates\n"
d70583f7
D
2067 "Max delay in seconds\n"
2068 "Establish wait in seconds\n")
f188f2c4 2069{
d62a17ae 2070 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2071}
2072
5e242b0d 2073
1ca2fd11
IR
2074static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2075 bool set)
cb1faec9 2076{
1ca2fd11
IR
2077 VTY_DECLVAR_CONTEXT(bgp, bgp);
2078
8fa7732f
QY
2079 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2080 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2081
2082 return CMD_SUCCESS;
2083}
2084
1ca2fd11
IR
2085static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2086 bool set)
555e09d4 2087{
1ca2fd11
IR
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
8fa7732f
QY
2090 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2091 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2092
d62a17ae 2093 return CMD_SUCCESS;
cb1faec9
DS
2094}
2095
2b791107 2096void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2097{
555e09d4
QY
2098 uint32_t quanta =
2099 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2100 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2101 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2102}
2103
555e09d4
QY
2104void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2105{
2106 uint32_t quanta =
2107 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2108 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2109 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2110}
cb1faec9 2111
8fa7732f
QY
2112/* Packet quanta configuration
2113 *
2114 * XXX: The value set here controls the size of a stack buffer in the IO
2115 * thread. When changing these limits be careful to prevent stack overflow.
2116 *
2117 * Furthermore, the maximums used here should correspond to
2118 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2119 */
1ca2fd11
IR
2120DEFPY (bgp_wpkt_quanta,
2121 bgp_wpkt_quanta_cmd,
2122 "[no] write-quanta (1-64)$quanta",
2123 NO_STR
2124 "How many packets to write to peer socket per run\n"
2125 "Number of packets\n")
2126{
2127 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2128}
cb1faec9 2129
1ca2fd11
IR
2130DEFPY (bgp_rpkt_quanta,
2131 bgp_rpkt_quanta_cmd,
2132 "[no] read-quanta (1-10)$quanta",
2133 NO_STR
2134 "How many packets to read from peer socket per I/O cycle\n"
2135 "Number of packets\n")
2136{
2137 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2138}
2139
2b791107 2140void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2141{
37a333fe 2142 if (!bgp->heuristic_coalesce)
d62a17ae 2143 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2144}
2145
4668a151 2146
1ca2fd11
IR
2147DEFUN (bgp_coalesce_time,
2148 bgp_coalesce_time_cmd,
2149 "coalesce-time (0-4294967295)",
2150 "Subgroup coalesce timer\n"
2151 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2152{
1ca2fd11 2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2154
1ca2fd11 2155 int idx = 0;
d62a17ae 2156 argv_find(argv, argc, "(0-4294967295)", &idx);
1ca2fd11
IR
2157 bgp->heuristic_coalesce = false;
2158 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2159 return CMD_SUCCESS;
3f9c7369
DS
2160}
2161
1ca2fd11
IR
2162DEFUN (no_bgp_coalesce_time,
2163 no_bgp_coalesce_time_cmd,
2164 "no coalesce-time (0-4294967295)",
2165 NO_STR
2166 "Subgroup coalesce timer\n"
2167 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2168{
1ca2fd11 2169 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2170
1ca2fd11
IR
2171 bgp->heuristic_coalesce = true;
2172 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2173 return CMD_SUCCESS;
3f9c7369
DS
2174}
2175
5e242b0d 2176/* Maximum-paths configuration */
585f1adc
IR
2177DEFUN (bgp_maxpaths,
2178 bgp_maxpaths_cmd,
2179 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2180 "Forward packets over multiple paths\n"
2181 "Number of paths\n")
5e242b0d 2182{
d62a17ae 2183 int idx_number = 1;
585f1adc
IR
2184 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2185 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2186}
2187
d62a17ae 2188ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2189 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2190 "Forward packets over multiple paths\n"
2191 "Number of paths\n")
596c17ba 2192
585f1adc
IR
2193DEFUN (bgp_maxpaths_ibgp,
2194 bgp_maxpaths_ibgp_cmd,
2195 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2196 "Forward packets over multiple paths\n"
2197 "iBGP-multipath\n"
2198 "Number of paths\n")
165b5fff 2199{
d62a17ae 2200 int idx_number = 2;
585f1adc
IR
2201 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2202 argv[idx_number]->arg, 0, 1);
5e242b0d 2203}
165b5fff 2204
d62a17ae 2205ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2206 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2207 "Forward packets over multiple paths\n"
2208 "iBGP-multipath\n"
2209 "Number of paths\n")
596c17ba 2210
585f1adc
IR
2211DEFUN (bgp_maxpaths_ibgp_cluster,
2212 bgp_maxpaths_ibgp_cluster_cmd,
2213 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2214 "Forward packets over multiple paths\n"
2215 "iBGP-multipath\n"
2216 "Number of paths\n"
2217 "Match the cluster length\n")
5e242b0d 2218{
d62a17ae 2219 int idx_number = 2;
585f1adc
IR
2220 return bgp_maxpaths_config_vty(
2221 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2222 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2223}
2224
d62a17ae 2225ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2226 "maximum-paths ibgp " CMD_RANGE_STR(
2227 1, MULTIPATH_NUM) " equal-cluster-length",
2228 "Forward packets over multiple paths\n"
2229 "iBGP-multipath\n"
2230 "Number of paths\n"
2231 "Match the cluster length\n")
596c17ba 2232
585f1adc
IR
2233DEFUN (no_bgp_maxpaths,
2234 no_bgp_maxpaths_cmd,
2235 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2236 NO_STR
2237 "Forward packets over multiple paths\n"
2238 "Number of paths\n")
165b5fff 2239{
585f1adc 2240 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2241}
2242
d62a17ae 2243ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2244 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2245 "Forward packets over multiple paths\n"
2246 "Number of paths\n")
596c17ba 2247
585f1adc
IR
2248DEFUN (no_bgp_maxpaths_ibgp,
2249 no_bgp_maxpaths_ibgp_cmd,
2250 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2251 NO_STR
2252 "Forward packets over multiple paths\n"
2253 "iBGP-multipath\n"
2254 "Number of paths\n"
2255 "Match the cluster length\n")
165b5fff 2256{
585f1adc 2257 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2258}
2259
d62a17ae 2260ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2261 "no maximum-paths ibgp [" CMD_RANGE_STR(
2262 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2263 NO_STR
2264 "Forward packets over multiple paths\n"
2265 "iBGP-multipath\n"
2266 "Number of paths\n"
2267 "Match the cluster length\n")
596c17ba 2268
dd65f45e
DL
2269static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2270 afi_t afi, safi_t safi)
165b5fff 2271{
00908b7a 2272 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2273 vty_out(vty, " maximum-paths %d\n",
2274 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2275 }
165b5fff 2276
00908b7a 2277 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2278 vty_out(vty, " maximum-paths ibgp %d",
2279 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2280 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2281 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2282 vty_out(vty, " equal-cluster-length");
2283 vty_out(vty, "\n");
2284 }
165b5fff 2285}
6b0655a2 2286
718e3744 2287/* BGP timers. */
2288
1ca2fd11
IR
2289DEFUN (bgp_timers,
2290 bgp_timers_cmd,
2291 "timers bgp (0-65535) (0-65535)",
2292 "Adjust routing timers\n"
2293 "BGP timers\n"
2294 "Keepalive interval\n"
2295 "Holdtime\n")
718e3744 2296{
1ca2fd11 2297 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2298 int idx_number = 2;
2299 int idx_number_2 = 3;
1ca2fd11
IR
2300 unsigned long keepalive = 0;
2301 unsigned long holdtime = 0;
718e3744 2302
1ca2fd11
IR
2303 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2304 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2305
1ca2fd11
IR
2306 /* Holdtime value check. */
2307 if (holdtime < 3 && holdtime != 0) {
2308 vty_out(vty,
2309 "%% hold time value must be either 0 or greater than 3\n");
2310 return CMD_WARNING_CONFIG_FAILED;
2311 }
718e3744 2312
1ca2fd11
IR
2313 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2314 BGP_DEFAULT_DELAYOPEN);
718e3744 2315
1ca2fd11 2316 return CMD_SUCCESS;
718e3744 2317}
2318
1ca2fd11
IR
2319DEFUN (no_bgp_timers,
2320 no_bgp_timers_cmd,
2321 "no timers bgp [(0-65535) (0-65535)]",
2322 NO_STR
2323 "Adjust routing timers\n"
2324 "BGP timers\n"
2325 "Keepalive interval\n"
2326 "Holdtime\n")
718e3744 2327{
1ca2fd11
IR
2328 VTY_DECLVAR_CONTEXT(bgp, bgp);
2329 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2330 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2331
1ca2fd11 2332 return CMD_SUCCESS;
718e3744 2333}
2334
ff8a8a7a 2335
1ca2fd11
IR
2336DEFUN (bgp_client_to_client_reflection,
2337 bgp_client_to_client_reflection_cmd,
2338 "bgp client-to-client reflection",
2339 "BGP specific commands\n"
2340 "Configure client to client route reflection\n"
2341 "reflection of routes allowed\n")
718e3744 2342{
1ca2fd11
IR
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2345 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2346
1ca2fd11 2347 return CMD_SUCCESS;
718e3744 2348}
2349
1ca2fd11
IR
2350DEFUN (no_bgp_client_to_client_reflection,
2351 no_bgp_client_to_client_reflection_cmd,
2352 "no bgp client-to-client reflection",
2353 NO_STR
2354 "BGP specific commands\n"
2355 "Configure client to client route reflection\n"
2356 "reflection of routes allowed\n")
718e3744 2357{
1ca2fd11
IR
2358 VTY_DECLVAR_CONTEXT(bgp, bgp);
2359 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2360 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2361
1ca2fd11 2362 return CMD_SUCCESS;
718e3744 2363}
2364
2365/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2366DEFUN (bgp_always_compare_med,
2367 bgp_always_compare_med_cmd,
2368 "bgp always-compare-med",
2369 "BGP specific commands\n"
2370 "Allow comparing MED from different neighbors\n")
718e3744 2371{
1ca2fd11
IR
2372 VTY_DECLVAR_CONTEXT(bgp, bgp);
2373 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2374 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2375
1ca2fd11 2376 return CMD_SUCCESS;
718e3744 2377}
2378
1ca2fd11
IR
2379DEFUN (no_bgp_always_compare_med,
2380 no_bgp_always_compare_med_cmd,
2381 "no bgp always-compare-med",
2382 NO_STR
2383 "BGP specific commands\n"
2384 "Allow comparing MED from different neighbors\n")
718e3744 2385{
1ca2fd11
IR
2386 VTY_DECLVAR_CONTEXT(bgp, bgp);
2387 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2388 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2389
1ca2fd11 2390 return CMD_SUCCESS;
2adac256
DA
2391}
2392
2adac256 2393
1ca2fd11
IR
2394DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2395 "bgp ebgp-requires-policy",
2396 "BGP specific commands\n"
2397 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2398{
1ca2fd11
IR
2399 VTY_DECLVAR_CONTEXT(bgp, bgp);
2400 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2401 return CMD_SUCCESS;
2adac256
DA
2402}
2403
1ca2fd11
IR
2404DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2405 "no bgp ebgp-requires-policy",
2406 NO_STR
2407 "BGP specific commands\n"
2408 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2409{
1ca2fd11
IR
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2412 return CMD_SUCCESS;
ff8a8a7a 2413}
9dac9fc8 2414
1ca2fd11
IR
2415DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2416 "bgp suppress-duplicates",
2417 "BGP specific commands\n"
2418 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2419{
1ca2fd11
IR
2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
2421 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2422 return CMD_SUCCESS;
9dac9fc8
DA
2423}
2424
1ca2fd11
IR
2425DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2426 "no bgp suppress-duplicates",
2427 NO_STR
2428 "BGP specific commands\n"
2429 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2430{
1ca2fd11
IR
2431 VTY_DECLVAR_CONTEXT(bgp, bgp);
2432 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2433 return CMD_SUCCESS;
9dac9fc8
DA
2434}
2435
fb29348a
DA
2436DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2437 "bgp reject-as-sets",
2438 "BGP specific commands\n"
2439 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2440{
2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
2442 struct listnode *node, *nnode;
2443 struct peer *peer;
2444
7f972cd8 2445 bgp->reject_as_sets = true;
fb29348a
DA
2446
2447 /* Reset existing BGP sessions to reject routes
2448 * with aspath containing AS_SET or AS_CONFED_SET.
2449 */
2450 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2451 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2452 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2453 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2454 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2455 }
2456 }
2457
2458 return CMD_SUCCESS;
2459}
2460
2461DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2462 "no bgp reject-as-sets",
2463 NO_STR
2464 "BGP specific commands\n"
2465 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2466{
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 struct listnode *node, *nnode;
2469 struct peer *peer;
2470
7f972cd8 2471 bgp->reject_as_sets = false;
fb29348a
DA
2472
2473 /* Reset existing BGP sessions to reject routes
2474 * with aspath containing AS_SET or AS_CONFED_SET.
2475 */
2476 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2477 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2478 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2479 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2480 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2481 }
2482 }
2483
2484 return CMD_SUCCESS;
2485}
9dac9fc8 2486
718e3744 2487/* "bgp deterministic-med" configuration. */
1ca2fd11 2488DEFUN (bgp_deterministic_med,
718e3744 2489 bgp_deterministic_med_cmd,
2490 "bgp deterministic-med",
2491 "BGP specific commands\n"
2492 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2493{
1ca2fd11
IR
2494 VTY_DECLVAR_CONTEXT(bgp, bgp);
2495
2496 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2497 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2498 bgp_recalculate_all_bestpaths(bgp);
2499 }
7aafcaca 2500
1ca2fd11 2501 return CMD_SUCCESS;
718e3744 2502}
2503
1ca2fd11 2504DEFUN (no_bgp_deterministic_med,
718e3744 2505 no_bgp_deterministic_med_cmd,
2506 "no bgp deterministic-med",
2507 NO_STR
2508 "BGP specific commands\n"
2509 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2510{
1ca2fd11
IR
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 int bestpath_per_as_used;
2513 afi_t afi;
2514 safi_t safi;
2515 struct peer *peer;
2516 struct listnode *node, *nnode;
2517
2518 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2519 bestpath_per_as_used = 0;
2520
2521 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2522 FOREACH_AFI_SAFI (afi, safi)
2523 if (bgp_addpath_dmed_required(
2524 peer->addpath_type[afi][safi])) {
2525 bestpath_per_as_used = 1;
2526 break;
2527 }
2528
2529 if (bestpath_per_as_used)
2530 break;
2531 }
2532
2533 if (bestpath_per_as_used) {
2534 vty_out(vty,
2535 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2536 return CMD_WARNING_CONFIG_FAILED;
2537 } else {
2538 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2539 bgp_recalculate_all_bestpaths(bgp);
2540 }
2541 }
d62a17ae 2542
1ca2fd11 2543 return CMD_SUCCESS;
718e3744 2544}
538621f2 2545
055679e9 2546/* "bgp graceful-restart mode" configuration. */
538621f2 2547DEFUN (bgp_graceful_restart,
2ba1fe69 2548 bgp_graceful_restart_cmd,
2549 "bgp graceful-restart",
2550 "BGP specific commands\n"
2551 GR_CMD
055679e9 2552 )
538621f2 2553{
055679e9 2554 int ret = BGP_GR_FAILURE;
2555
2556 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2557 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2558
d62a17ae 2559 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2560
2561 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2562
36235319
QY
2563 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2564 ret);
5cce3f05 2565
055679e9 2566 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2567 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2568 vty_out(vty,
2569 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2570 return bgp_vty_return(vty, ret);
538621f2 2571}
2572
2573DEFUN (no_bgp_graceful_restart,
2ba1fe69 2574 no_bgp_graceful_restart_cmd,
2575 "no bgp graceful-restart",
2576 NO_STR
2577 "BGP specific commands\n"
2578 NO_GR_CMD
055679e9 2579 )
538621f2 2580{
d62a17ae 2581 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2582
2583 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2584 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2585
2586 int ret = BGP_GR_FAILURE;
2587
2588 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2589
36235319
QY
2590 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2591 ret);
5cce3f05 2592
055679e9 2593 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2594 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2595 vty_out(vty,
2596 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2597
2598 return bgp_vty_return(vty, ret);
538621f2 2599}
2600
93406d87 2601DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2602 bgp_graceful_restart_stalepath_time_cmd,
2603 "bgp graceful-restart stalepath-time (1-4095)",
2604 "BGP specific commands\n"
2605 "Graceful restart capability parameters\n"
2606 "Set the max time to hold onto restarting peer's stale paths\n"
2607 "Delay value (seconds)\n")
93406d87 2608{
d62a17ae 2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 int idx_number = 3;
d7c0a89a 2611 uint32_t stalepath;
93406d87 2612
d62a17ae 2613 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2614 bgp->stalepath_time = stalepath;
2615 return CMD_SUCCESS;
93406d87 2616}
2617
eb6f1b41 2618DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2619 bgp_graceful_restart_restart_time_cmd,
2620 "bgp graceful-restart restart-time (1-4095)",
2621 "BGP specific commands\n"
2622 "Graceful restart capability parameters\n"
2623 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2624 "Delay value (seconds)\n")
eb6f1b41 2625{
d62a17ae 2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627 int idx_number = 3;
d7c0a89a 2628 uint32_t restart;
eb6f1b41 2629
d62a17ae 2630 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2631 bgp->restart_time = restart;
2632 return CMD_SUCCESS;
eb6f1b41
PG
2633}
2634
cfd47646 2635DEFUN (bgp_graceful_restart_select_defer_time,
2636 bgp_graceful_restart_select_defer_time_cmd,
2637 "bgp graceful-restart select-defer-time (0-3600)",
2638 "BGP specific commands\n"
2639 "Graceful restart capability parameters\n"
2640 "Set the time to defer the BGP route selection after restart\n"
2641 "Delay value (seconds, 0 - disable)\n")
2642{
2643 VTY_DECLVAR_CONTEXT(bgp, bgp);
2644 int idx_number = 3;
2645 uint32_t defer_time;
2646
2647 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2648 bgp->select_defer_time = defer_time;
2649 if (defer_time == 0)
892fedb6 2650 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2651 else
892fedb6 2652 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2653
2654 return CMD_SUCCESS;
2655}
2656
93406d87 2657DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2658 no_bgp_graceful_restart_stalepath_time_cmd,
2659 "no bgp graceful-restart stalepath-time [(1-4095)]",
2660 NO_STR
2661 "BGP specific commands\n"
2662 "Graceful restart capability parameters\n"
2663 "Set the max time to hold onto restarting peer's stale paths\n"
2664 "Delay value (seconds)\n")
93406d87 2665{
d62a17ae 2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2667
d62a17ae 2668 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2669 return CMD_SUCCESS;
93406d87 2670}
2671
eb6f1b41 2672DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2673 no_bgp_graceful_restart_restart_time_cmd,
2674 "no bgp graceful-restart restart-time [(1-4095)]",
2675 NO_STR
2676 "BGP specific commands\n"
2677 "Graceful restart capability parameters\n"
2678 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2679 "Delay value (seconds)\n")
eb6f1b41 2680{
d62a17ae 2681 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2682
d62a17ae 2683 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2684 return CMD_SUCCESS;
eb6f1b41
PG
2685}
2686
cfd47646 2687DEFUN (no_bgp_graceful_restart_select_defer_time,
2688 no_bgp_graceful_restart_select_defer_time_cmd,
2689 "no bgp graceful-restart select-defer-time [(0-3600)]",
2690 NO_STR
2691 "BGP specific commands\n"
2692 "Graceful restart capability parameters\n"
2693 "Set the time to defer the BGP route selection after restart\n"
2694 "Delay value (seconds)\n")
2695{
2696 VTY_DECLVAR_CONTEXT(bgp, bgp);
2697
2698 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2699 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2700
2701 return CMD_SUCCESS;
2702}
2703
43fc21b3 2704DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2705 bgp_graceful_restart_preserve_fw_cmd,
2706 "bgp graceful-restart preserve-fw-state",
2707 "BGP specific commands\n"
2708 "Graceful restart capability parameters\n"
2709 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2710{
d62a17ae 2711 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2712 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2713 return CMD_SUCCESS;
43fc21b3
JC
2714}
2715
2716DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2717 no_bgp_graceful_restart_preserve_fw_cmd,
2718 "no bgp graceful-restart preserve-fw-state",
2719 NO_STR
2720 "BGP specific commands\n"
2721 "Graceful restart capability parameters\n"
2722 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2723{
d62a17ae 2724 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2725 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2726 return CMD_SUCCESS;
43fc21b3
JC
2727}
2728
055679e9 2729DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2730 bgp_graceful_restart_disable_cmd,
2731 "bgp graceful-restart-disable",
2732 "BGP specific commands\n"
2733 GR_DISABLE)
055679e9 2734{
2735 int ret = BGP_GR_FAILURE;
2736
2737 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2738 zlog_debug(
2ba1fe69 2739 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2740
055679e9 2741 VTY_DECLVAR_CONTEXT(bgp, bgp);
2742
2743 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2744
dc95985f 2745 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2746 bgp->peer, ret);
5cce3f05 2747
055679e9 2748 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2749 zlog_debug(
2ba1fe69 2750 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2751 vty_out(vty,
2752 "Graceful restart configuration changed, reset all peers to take effect\n");
2753
055679e9 2754 return bgp_vty_return(vty, ret);
2755}
2756
2757DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2758 no_bgp_graceful_restart_disable_cmd,
2759 "no bgp graceful-restart-disable",
2760 NO_STR
2761 "BGP specific commands\n"
2762 NO_GR_DISABLE
055679e9 2763 )
2764{
2765 VTY_DECLVAR_CONTEXT(bgp, bgp);
2766
2767 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2768 zlog_debug(
2ba1fe69 2769 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2770
2771 int ret = BGP_GR_FAILURE;
2772
2773 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2774
36235319
QY
2775 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2776 ret);
5cce3f05 2777
055679e9 2778 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2779 zlog_debug(
2ba1fe69 2780 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2781 vty_out(vty,
2782 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2783
2784 return bgp_vty_return(vty, ret);
2785}
2786
2787DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2788 bgp_neighbor_graceful_restart_set_cmd,
2789 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2790 NEIGHBOR_STR
2791 NEIGHBOR_ADDR_STR2
2792 GR_NEIGHBOR_CMD
055679e9 2793 )
2794{
2795 int idx_peer = 1;
2796 struct peer *peer;
2797 int ret = BGP_GR_FAILURE;
2798
dc95985f 2799 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2800
055679e9 2801 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2802 zlog_debug(
2ba1fe69 2803 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2804
055679e9 2805 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2806 if (!peer)
2807 return CMD_WARNING_CONFIG_FAILED;
2808
2809 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2810
dc95985f 2811 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2812 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2813
2814 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2815 zlog_debug(
2ba1fe69 2816 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2817 vty_out(vty,
2818 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2819
2820 return bgp_vty_return(vty, ret);
2821}
2822
2823DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2824 no_bgp_neighbor_graceful_restart_set_cmd,
2825 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2826 NO_STR
2827 NEIGHBOR_STR
2828 NEIGHBOR_ADDR_STR2
2829 NO_GR_NEIGHBOR_CMD
055679e9 2830 )
2831{
2832 int idx_peer = 2;
2833 int ret = BGP_GR_FAILURE;
2834 struct peer *peer;
2835
dc95985f 2836 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2837
055679e9 2838 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2839 if (!peer)
2840 return CMD_WARNING_CONFIG_FAILED;
2841
2842 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2843 zlog_debug(
2ba1fe69 2844 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2845
2846 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2847
dc95985f 2848 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2849 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2850
2851 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2852 zlog_debug(
2ba1fe69 2853 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2854 vty_out(vty,
2855 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2856
2857 return bgp_vty_return(vty, ret);
2858}
2859
2860DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2861 bgp_neighbor_graceful_restart_helper_set_cmd,
2862 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2863 NEIGHBOR_STR
2864 NEIGHBOR_ADDR_STR2
2865 GR_NEIGHBOR_HELPER_CMD
055679e9 2866 )
2867{
2868 int idx_peer = 1;
2869 struct peer *peer;
2870 int ret = BGP_GR_FAILURE;
2871
dc95985f 2872 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2873
055679e9 2874 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2875 zlog_debug(
2ba1fe69 2876 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2877
055679e9 2878 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2879
055679e9 2880 if (!peer)
2881 return CMD_WARNING_CONFIG_FAILED;
2882
2883
2884 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2885
dc95985f 2886 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2887 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2888
055679e9 2889 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2890 zlog_debug(
2ba1fe69 2891 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2892 vty_out(vty,
2893 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2894
2895 return bgp_vty_return(vty, ret);
2896}
2897
2898DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2899 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2900 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2901 NO_STR
2902 NEIGHBOR_STR
2903 NEIGHBOR_ADDR_STR2
2904 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2905 )
2906{
2907 int idx_peer = 2;
2908 int ret = BGP_GR_FAILURE;
2909 struct peer *peer;
2910
dc95985f 2911 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2912
055679e9 2913 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2914 if (!peer)
2915 return CMD_WARNING_CONFIG_FAILED;
2916
2917 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2918 zlog_debug(
2ba1fe69 2919 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2920
36235319 2921 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2922
dc95985f 2923 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2924 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2925
2926 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2927 zlog_debug(
2ba1fe69 2928 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2929 vty_out(vty,
2930 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2931
2932 return bgp_vty_return(vty, ret);
2933}
2934
2935DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2936 bgp_neighbor_graceful_restart_disable_set_cmd,
2937 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2938 NEIGHBOR_STR
2939 NEIGHBOR_ADDR_STR2
2940 GR_NEIGHBOR_DISABLE_CMD
055679e9 2941 )
2942{
2943 int idx_peer = 1;
2944 struct peer *peer;
2945 int ret = BGP_GR_FAILURE;
2946
dc95985f 2947 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2948
055679e9 2949 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2950 zlog_debug(
2ba1fe69 2951 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2952
2953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2954 if (!peer)
2955 return CMD_WARNING_CONFIG_FAILED;
2956
36235319 2957 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2958
2959 if (peer->bgp->t_startup)
2960 bgp_peer_gr_flags_update(peer);
2961
dc95985f 2962 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2963 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2964
055679e9 2965 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2966 zlog_debug(
2ba1fe69 2967 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2968 vty_out(vty,
2969 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2970
2971 return bgp_vty_return(vty, ret);
2972}
2973
2974DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2975 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2976 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2977 NO_STR
2978 NEIGHBOR_STR
2979 NEIGHBOR_ADDR_STR2
2980 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2981 )
2982{
2983 int idx_peer = 2;
2984 int ret = BGP_GR_FAILURE;
2985 struct peer *peer;
2986
dc95985f 2987 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2988
055679e9 2989 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2990 if (!peer)
2991 return CMD_WARNING_CONFIG_FAILED;
2992
2993 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2994 zlog_debug(
2ba1fe69 2995 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2996
2997 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2998
dc95985f 2999 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3000 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3001
3002 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3003 zlog_debug(
2ba1fe69 3004 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3005 vty_out(vty,
3006 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3007
3008 return bgp_vty_return(vty, ret);
3009}
3010
d6e3c15b 3011DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3012 bgp_graceful_restart_disable_eor_cmd,
3013 "bgp graceful-restart disable-eor",
3014 "BGP specific commands\n"
3015 "Graceful restart configuration parameters\n"
3016 "Disable EOR Check\n")
3017{
3018 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3019 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3020
d6e3c15b 3021 return CMD_SUCCESS;
3022}
3023
3024DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3025 no_bgp_graceful_restart_disable_eor_cmd,
3026 "no bgp graceful-restart disable-eor",
3027 NO_STR
3028 "BGP specific commands\n"
3029 "Graceful restart configuration parameters\n"
3030 "Disable EOR Check\n")
3031{
3032 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3033 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3034
3035 return CMD_SUCCESS;
3036}
3037
3038DEFUN (bgp_graceful_restart_rib_stale_time,
3039 bgp_graceful_restart_rib_stale_time_cmd,
3040 "bgp graceful-restart rib-stale-time (1-3600)",
3041 "BGP specific commands\n"
3042 "Graceful restart configuration parameters\n"
3043 "Specify the stale route removal timer in rib\n"
3044 "Delay value (seconds)\n")
3045{
3046 VTY_DECLVAR_CONTEXT(bgp, bgp);
3047 int idx_number = 3;
3048 uint32_t stale_time;
3049
3050 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3051 bgp->rib_stale_time = stale_time;
3052 /* Send the stale timer update message to RIB */
3053 if (bgp_zebra_stale_timer_update(bgp))
3054 return CMD_WARNING;
3055
3056 return CMD_SUCCESS;
3057}
3058
3059DEFUN (no_bgp_graceful_restart_rib_stale_time,
3060 no_bgp_graceful_restart_rib_stale_time_cmd,
3061 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3062 NO_STR
3063 "BGP specific commands\n"
3064 "Graceful restart configuration parameters\n"
3065 "Specify the stale route removal timer in rib\n"
3066 "Delay value (seconds)\n")
3067{
3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069
3070 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3071 /* Send the stale timer update message to RIB */
3072 if (bgp_zebra_stale_timer_update(bgp))
3073 return CMD_WARNING;
3074
d6e3c15b 3075 return CMD_SUCCESS;
3076}
3077
1ca2fd11
IR
3078static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3079 struct bgp *bgp)
05bd726c 3080{
3081 bgp_static_redo_import_check(bgp);
3082 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3083 bgp_clear_star_soft_out(vty, bgp->name);
3084 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3085}
3086
3087static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3088{
3089 struct listnode *node, *nnode;
3090 struct bgp *bgp;
3091 bool vrf_cfg = false;
3092
3093 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3094 return CMD_SUCCESS;
3095
3096 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3097 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3098 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3099 vty_out(vty,
3100 "%% graceful-shutdown configuration found in vrf %s\n",
3101 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3102 VRF_DEFAULT_NAME : bgp->name);
3103 vrf_cfg = true;
3104 }
3105 }
3106
3107 if (vrf_cfg) {
3108 vty_out(vty,
3109 "%%Failed: global graceful-shutdown not permitted\n");
3110 return CMD_WARNING;
3111 }
3112
3113 /* Set flag globally */
3114 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3115
3116 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3118 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3119
3120 return CMD_SUCCESS;
3121}
3122
3123static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3124{
3125 struct listnode *node, *nnode;
3126 struct bgp *bgp;
3127
3128 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3129 return CMD_SUCCESS;
3130
3131 /* Unset flag globally */
3132 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3133
3134 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3135 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3136 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3137
3138 return CMD_SUCCESS;
3139}
3140
7f323236
DW
3141/* "bgp graceful-shutdown" configuration */
3142DEFUN (bgp_graceful_shutdown,
3143 bgp_graceful_shutdown_cmd,
3144 "bgp graceful-shutdown",
3145 BGP_STR
3146 "Graceful shutdown parameters\n")
3147{
05bd726c 3148 if (vty->node == CONFIG_NODE)
3149 return bgp_global_graceful_shutdown_config_vty(vty);
3150
1ca2fd11 3151 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3152
1ca2fd11
IR
3153 /* if configured globally, per-instance config is not allowed */
3154 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3155 vty_out(vty,
3156 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3157 return CMD_WARNING_CONFIG_FAILED;
3158 }
3159
3160 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3161 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3162 bgp_initiate_graceful_shut_unshut(vty, bgp);
3163 }
3164
3165 return CMD_SUCCESS;
7f323236
DW
3166}
3167
1ca2fd11 3168DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3169 no_bgp_graceful_shutdown_cmd,
3170 "no bgp graceful-shutdown",
3171 NO_STR
3172 BGP_STR
3173 "Graceful shutdown parameters\n")
3174{
05bd726c 3175 if (vty->node == CONFIG_NODE)
3176 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3177
1ca2fd11 3178 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3179
1ca2fd11
IR
3180 /* If configured globally, cannot remove from one bgp instance */
3181 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3182 vty_out(vty,
3183 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3184 return CMD_WARNING_CONFIG_FAILED;
3185 }
7f323236 3186
1ca2fd11
IR
3187 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3188 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3189 bgp_initiate_graceful_shut_unshut(vty, bgp);
3190 }
3191
3192 return CMD_SUCCESS;
7f323236
DW
3193}
3194
718e3744 3195/* "bgp fast-external-failover" configuration. */
1ca2fd11 3196DEFUN (bgp_fast_external_failover,
718e3744 3197 bgp_fast_external_failover_cmd,
3198 "bgp fast-external-failover",
3199 BGP_STR
3200 "Immediately reset session if a link to a directly connected external peer goes down\n")
3201{
1ca2fd11
IR
3202 VTY_DECLVAR_CONTEXT(bgp, bgp);
3203 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3204 return CMD_SUCCESS;
718e3744 3205}
3206
1ca2fd11 3207DEFUN (no_bgp_fast_external_failover,
718e3744 3208 no_bgp_fast_external_failover_cmd,
3209 "no bgp fast-external-failover",
3210 NO_STR
3211 BGP_STR
3212 "Immediately reset session if a link to a directly connected external peer goes down\n")
3213{
1ca2fd11
IR
3214 VTY_DECLVAR_CONTEXT(bgp, bgp);
3215 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3216 return CMD_SUCCESS;
718e3744 3217}
6b0655a2 3218
718e3744 3219/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3220DEFUN (bgp_bestpath_compare_router_id,
3221 bgp_bestpath_compare_router_id_cmd,
3222 "bgp bestpath compare-routerid",
3223 "BGP specific commands\n"
3224 "Change the default bestpath selection\n"
3225 "Compare router-id for identical EBGP paths\n")
718e3744 3226{
1ca2fd11
IR
3227 VTY_DECLVAR_CONTEXT(bgp, bgp);
3228 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3229 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3230
1ca2fd11 3231 return CMD_SUCCESS;
718e3744 3232}
3233
1ca2fd11
IR
3234DEFUN (no_bgp_bestpath_compare_router_id,
3235 no_bgp_bestpath_compare_router_id_cmd,
3236 "no bgp bestpath compare-routerid",
3237 NO_STR
3238 "BGP specific commands\n"
3239 "Change the default bestpath selection\n"
3240 "Compare router-id for identical EBGP paths\n")
718e3744 3241{
1ca2fd11
IR
3242 VTY_DECLVAR_CONTEXT(bgp, bgp);
3243 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3244 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3245
1ca2fd11 3246 return CMD_SUCCESS;
718e3744 3247}
6b0655a2 3248
718e3744 3249/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3250DEFUN (bgp_bestpath_aspath_ignore,
3251 bgp_bestpath_aspath_ignore_cmd,
3252 "bgp bestpath as-path ignore",
3253 "BGP specific commands\n"
3254 "Change the default bestpath selection\n"
3255 "AS-path attribute\n"
3256 "Ignore as-path length in selecting a route\n")
718e3744 3257{
1ca2fd11
IR
3258 VTY_DECLVAR_CONTEXT(bgp, bgp);
3259 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3260 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3261
1ca2fd11 3262 return CMD_SUCCESS;
718e3744 3263}
3264
1ca2fd11
IR
3265DEFUN (no_bgp_bestpath_aspath_ignore,
3266 no_bgp_bestpath_aspath_ignore_cmd,
3267 "no bgp bestpath as-path ignore",
3268 NO_STR
3269 "BGP specific commands\n"
3270 "Change the default bestpath selection\n"
3271 "AS-path attribute\n"
3272 "Ignore as-path length in selecting a route\n")
718e3744 3273{
1ca2fd11
IR
3274 VTY_DECLVAR_CONTEXT(bgp, bgp);
3275 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3276 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3277
1ca2fd11 3278 return CMD_SUCCESS;
718e3744 3279}
6b0655a2 3280
6811845b 3281/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3282DEFUN (bgp_bestpath_aspath_confed,
6811845b 3283 bgp_bestpath_aspath_confed_cmd,
3284 "bgp bestpath as-path confed",
3285 "BGP specific commands\n"
3286 "Change the default bestpath selection\n"
3287 "AS-path attribute\n"
3288 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3289{
1ca2fd11
IR
3290 VTY_DECLVAR_CONTEXT(bgp, bgp);
3291 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3292 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3293
1ca2fd11 3294 return CMD_SUCCESS;
6811845b 3295}
3296
1ca2fd11 3297DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3298 no_bgp_bestpath_aspath_confed_cmd,
3299 "no bgp bestpath as-path confed",
3300 NO_STR
3301 "BGP specific commands\n"
3302 "Change the default bestpath selection\n"
3303 "AS-path attribute\n"
3304 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3305{
1ca2fd11
IR
3306 VTY_DECLVAR_CONTEXT(bgp, bgp);
3307 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3308 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3309
1ca2fd11 3310 return CMD_SUCCESS;
6811845b 3311}
6b0655a2 3312
2fdd455c 3313/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3314DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3315 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3316 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3317 "BGP specific commands\n"
3318 "Change the default bestpath selection\n"
3319 "AS-path attribute\n"
3320 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3321 "Generate an AS_SET\n"
16fc1eec
DS
3322 "Do not generate an AS_SET\n")
3323{
1ca2fd11 3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3325 int idx = 0;
1ca2fd11 3326 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3327
1ca2fd11
IR
3328 /* no-as-set is now the default behavior so we can silently
3329 * ignore it */
d62a17ae 3330 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3331 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3332 else
1ca2fd11 3333 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3334
1ca2fd11
IR
3335 bgp_recalculate_all_bestpaths(bgp);
3336
3337 return CMD_SUCCESS;
16fc1eec
DS
3338}
3339
1ca2fd11 3340DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3341 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3342 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3343 NO_STR
3344 "BGP specific commands\n"
3345 "Change the default bestpath selection\n"
3346 "AS-path attribute\n"
3347 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3348 "Generate an AS_SET\n"
16fc1eec
DS
3349 "Do not generate an AS_SET\n")
3350{
1ca2fd11
IR
3351 VTY_DECLVAR_CONTEXT(bgp, bgp);
3352 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3353 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3354 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3355
1ca2fd11 3356 return CMD_SUCCESS;
2fdd455c 3357}
6b0655a2 3358
ee88563a
JM
3359/* "bgp bestpath peer-type multipath-relax" configuration. */
3360DEFUN(bgp_bestpath_peer_type_multipath_relax,
3361 bgp_bestpath_peer_type_multipath_relax_cmd,
3362 "bgp bestpath peer-type multipath-relax",
3363 BGP_STR
3364 "Change the default bestpath selection\n"
3365 "Peer type\n"
3366 "Allow load sharing across routes learned from different peer types\n")
3367{
3368 VTY_DECLVAR_CONTEXT(bgp, bgp);
3369 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3370 bgp_recalculate_all_bestpaths(bgp);
3371
3372 return CMD_SUCCESS;
3373}
3374
3375DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3376 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3377 "no bgp bestpath peer-type multipath-relax",
3378 NO_STR BGP_STR
3379 "Change the default bestpath selection\n"
3380 "Peer type\n"
3381 "Allow load sharing across routes learned from different peer types\n")
3382{
3383 VTY_DECLVAR_CONTEXT(bgp, bgp);
3384 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3385 bgp_recalculate_all_bestpaths(bgp);
3386
3387 return CMD_SUCCESS;
3388}
3389
848973c7 3390/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3391DEFUN (bgp_log_neighbor_changes,
3392 bgp_log_neighbor_changes_cmd,
3393 "bgp log-neighbor-changes",
3394 "BGP specific commands\n"
3395 "Log neighbor up/down and reset reason\n")
848973c7 3396{
1ca2fd11
IR
3397 VTY_DECLVAR_CONTEXT(bgp, bgp);
3398 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3399 return CMD_SUCCESS;
848973c7 3400}
3401
1ca2fd11
IR
3402DEFUN (no_bgp_log_neighbor_changes,
3403 no_bgp_log_neighbor_changes_cmd,
3404 "no bgp log-neighbor-changes",
3405 NO_STR
3406 "BGP specific commands\n"
3407 "Log neighbor up/down and reset reason\n")
848973c7 3408{
1ca2fd11
IR
3409 VTY_DECLVAR_CONTEXT(bgp, bgp);
3410 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3411 return CMD_SUCCESS;
848973c7 3412}
6b0655a2 3413
718e3744 3414/* "bgp bestpath med" configuration. */
1ca2fd11 3415DEFUN (bgp_bestpath_med,
718e3744 3416 bgp_bestpath_med_cmd,
2d8c1a4d 3417 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3418 "BGP specific commands\n"
3419 "Change the default bestpath selection\n"
3420 "MED attribute\n"
3421 "Compare MED among confederation paths\n"
838758ac
DW
3422 "Treat missing MED as the least preferred one\n"
3423 "Treat missing MED as the least preferred one\n"
3424 "Compare MED among confederation paths\n")
718e3744 3425{
1ca2fd11 3426 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3427
1ca2fd11 3428 int idx = 0;
d62a17ae 3429 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3430 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3431 idx = 0;
3432 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3433 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3434
1ca2fd11 3435 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3436
1ca2fd11 3437 return CMD_SUCCESS;
718e3744 3438}
3439
1ca2fd11 3440DEFUN (no_bgp_bestpath_med,
718e3744 3441 no_bgp_bestpath_med_cmd,
2d8c1a4d 3442 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3443 NO_STR
3444 "BGP specific commands\n"
3445 "Change the default bestpath selection\n"
3446 "MED attribute\n"
3447 "Compare MED among confederation paths\n"
3a2d747c
QY
3448 "Treat missing MED as the least preferred one\n"
3449 "Treat missing MED as the least preferred one\n"
3450 "Compare MED among confederation paths\n")
718e3744 3451{
1ca2fd11 3452 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3453
1ca2fd11 3454 int idx = 0;
d62a17ae 3455 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3456 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3457 idx = 0;
3458 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3459 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3460
3461 bgp_recalculate_all_bestpaths(bgp);
718e3744 3462
1ca2fd11 3463 return CMD_SUCCESS;
718e3744 3464}
3465
f7e1c681 3466/* "bgp bestpath bandwidth" configuration. */
3467DEFPY (bgp_bestpath_bw,
3468 bgp_bestpath_bw_cmd,
ad36d216 3469 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3470 "BGP specific commands\n"
3471 "Change the default bestpath selection\n"
3472 "Link Bandwidth attribute\n"
3473 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3474 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3475 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3476{
3477 VTY_DECLVAR_CONTEXT(bgp, bgp);
3478 afi_t afi;
3479 safi_t safi;
3480
ad36d216
DS
3481 if (!bw_cfg) {
3482 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3483 return CMD_ERR_INCOMPLETE;
f7e1c681 3484 }
ad36d216
DS
3485 if (!strcmp(bw_cfg, "ignore"))
3486 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3487 else if (!strcmp(bw_cfg, "skip-missing"))
3488 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3489 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3490 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3491 else
3492 return CMD_ERR_NO_MATCH;
f7e1c681 3493
3494 /* This config is used in route install, so redo that. */
3495 FOREACH_AFI_SAFI (afi, safi) {
3496 if (!bgp_fibupd_safi(safi))
3497 continue;
3498 bgp_zebra_announce_table(bgp, afi, safi);
3499 }
3500
3501 return CMD_SUCCESS;
3502}
3503
ad36d216
DS
3504DEFPY (no_bgp_bestpath_bw,
3505 no_bgp_bestpath_bw_cmd,
3506 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3507 NO_STR
3508 "BGP specific commands\n"
3509 "Change the default bestpath selection\n"
3510 "Link Bandwidth attribute\n"
3511 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3512 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3513 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3514{
3515 VTY_DECLVAR_CONTEXT(bgp, bgp);
3516 afi_t afi;
3517 safi_t safi;
3518
3519 bgp->lb_handling = BGP_LINK_BW_ECMP;
3520
3521 /* This config is used in route install, so redo that. */
3522 FOREACH_AFI_SAFI (afi, safi) {
3523 if (!bgp_fibupd_safi(safi))
3524 continue;
3525 bgp_zebra_announce_table(bgp, afi, safi);
3526 }
3527 return CMD_SUCCESS;
3528}
3529
b16bcbba 3530DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3531 "[no] bgp default <ipv4-unicast|"
3532 "ipv4-multicast|"
3533 "ipv4-vpn|"
3534 "ipv4-labeled-unicast|"
3535 "ipv4-flowspec|"
3536 "ipv6-unicast|"
3537 "ipv6-multicast|"
3538 "ipv6-vpn|"
3539 "ipv6-labeled-unicast|"
3540 "ipv6-flowspec|"
3541 "l2vpn-evpn>$afi_safi",
b16bcbba 3542 NO_STR
e84c59af
DA
3543 "BGP specific commands\n"
3544 "Configure BGP defaults\n"
b16bcbba 3545 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3546 "Activate ipv4-multicast for a peer by default\n"
3547 "Activate ipv4-vpn for a peer by default\n"
3548 "Activate ipv4-labeled-unicast for a peer by default\n"
3549 "Activate ipv4-flowspec for a peer by default\n"
3550 "Activate ipv6-unicast for a peer by default\n"
3551 "Activate ipv6-multicast for a peer by default\n"
3552 "Activate ipv6-vpn for a peer by default\n"
3553 "Activate ipv6-labeled-unicast for a peer by default\n"
3554 "Activate ipv6-flowspec for a peer by default\n"
3555 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3556{
3557 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3558 char afi_safi_str[strlen(afi_safi) + 1];
3559 char *afi_safi_str_tok;
e84c59af 3560
b16bcbba
TA
3561 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3562 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3563 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3564 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3565 safi_t safi;
e84c59af 3566
38d11af5
TA
3567 if (strmatch(safi_str, "labeled"))
3568 safi = bgp_vty_safi_from_str("labeled-unicast");
3569 else
3570 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3571
3572 if (no)
3573 bgp->default_af[afi][safi] = false;
38d11af5
TA
3574 else {
3575 if ((safi == SAFI_LABELED_UNICAST
3576 && bgp->default_af[afi][SAFI_UNICAST])
3577 || (safi == SAFI_UNICAST
3578 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3579 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3580 else
3581 bgp->default_af[afi][safi] = true;
3582 }
718e3744 3583
d62a17ae 3584 return CMD_SUCCESS;
718e3744 3585}
6b0655a2 3586
04b6bdc0 3587/* Display hostname in certain command outputs */
1ca2fd11 3588DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3589 bgp_default_show_hostname_cmd,
3590 "bgp default show-hostname",
3591 "BGP specific commands\n"
3592 "Configure BGP defaults\n"
0437e105 3593 "Show hostname in certain command outputs\n")
04b6bdc0 3594{
1ca2fd11
IR
3595 VTY_DECLVAR_CONTEXT(bgp, bgp);
3596 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3597 return CMD_SUCCESS;
ff8a8a7a
CS
3598}
3599
1ca2fd11
IR
3600DEFUN (no_bgp_default_show_hostname,
3601 no_bgp_default_show_hostname_cmd,
3602 "no bgp default show-hostname",
3603 NO_STR
3604 "BGP specific commands\n"
3605 "Configure BGP defaults\n"
3606 "Show hostname in certain command outputs\n")
ff8a8a7a 3607{
1ca2fd11
IR
3608 VTY_DECLVAR_CONTEXT(bgp, bgp);
3609 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3610 return CMD_SUCCESS;
04b6bdc0
DW
3611}
3612
aef999a2 3613/* Display hostname in certain command outputs */
1d80f243
IR
3614DEFUN (bgp_default_show_nexthop_hostname,
3615 bgp_default_show_nexthop_hostname_cmd,
3616 "bgp default show-nexthop-hostname",
3617 "BGP specific commands\n"
3618 "Configure BGP defaults\n"
3619 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3620{
1ca2fd11
IR
3621 VTY_DECLVAR_CONTEXT(bgp, bgp);
3622 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3623 return CMD_SUCCESS;
aef999a2
DA
3624}
3625
3626DEFUN (no_bgp_default_show_nexthop_hostname,
3627 no_bgp_default_show_nexthop_hostname_cmd,
3628 "no bgp default show-nexthop-hostname",
3629 NO_STR
3630 "BGP specific commands\n"
3631 "Configure BGP defaults\n"
3632 "Show hostname for nexthop in certain command outputs\n")
3633{
1ca2fd11
IR
3634 VTY_DECLVAR_CONTEXT(bgp, bgp);
3635 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3636 return CMD_SUCCESS;
aef999a2
DA
3637}
3638
8233ef81 3639/* "bgp network import-check" configuration. */
1ca2fd11
IR
3640DEFUN (bgp_network_import_check,
3641 bgp_network_import_check_cmd,
3642 "bgp network import-check",
3643 "BGP specific commands\n"
3644 "BGP network command\n"
3645 "Check BGP network route exists in IGP\n")
718e3744 3646{
1ca2fd11
IR
3647 VTY_DECLVAR_CONTEXT(bgp, bgp);
3648 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3649 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3650 bgp_static_redo_import_check(bgp);
3651 }
078430f6 3652
1ca2fd11 3653 return CMD_SUCCESS;
718e3744 3654}
3655
d62a17ae 3656ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3657 "bgp network import-check exact",
3658 "BGP specific commands\n"
3659 "BGP network command\n"
3660 "Check BGP network route exists in IGP\n"
3661 "Match route precisely\n")
8233ef81 3662
1ca2fd11
IR
3663DEFUN (no_bgp_network_import_check,
3664 no_bgp_network_import_check_cmd,
3665 "no bgp network import-check",
3666 NO_STR
3667 "BGP specific commands\n"
3668 "BGP network command\n"
3669 "Check BGP network route exists in IGP\n")
718e3744 3670{
1ca2fd11
IR
3671 VTY_DECLVAR_CONTEXT(bgp, bgp);
3672 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3673 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3674 bgp_static_redo_import_check(bgp);
3675 }
6b0655a2 3676
1ca2fd11 3677 return CMD_SUCCESS;
ff8a8a7a 3678}
718e3744 3679
1ca2fd11
IR
3680DEFUN (bgp_default_local_preference,
3681 bgp_default_local_preference_cmd,
3682 "bgp default local-preference (0-4294967295)",
3683 "BGP specific commands\n"
3684 "Configure BGP defaults\n"
3685 "local preference (higher=more preferred)\n"
3686 "Configure default local preference value\n")
ff8a8a7a 3687{
1ca2fd11 3688 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3689 int idx_number = 3;
1ca2fd11 3690 uint32_t local_pref;
718e3744 3691
1ca2fd11 3692 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3693
1ca2fd11
IR
3694 bgp_default_local_preference_set(bgp, local_pref);
3695 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3696
1ca2fd11 3697 return CMD_SUCCESS;
718e3744 3698}
3699
1ca2fd11
IR
3700DEFUN (no_bgp_default_local_preference,
3701 no_bgp_default_local_preference_cmd,
3702 "no bgp default local-preference [(0-4294967295)]",
3703 NO_STR
3704 "BGP specific commands\n"
3705 "Configure BGP defaults\n"
3706 "local preference (higher=more preferred)\n"
3707 "Configure default local preference value\n")
ff8a8a7a 3708{
1ca2fd11
IR
3709 VTY_DECLVAR_CONTEXT(bgp, bgp);
3710 bgp_default_local_preference_unset(bgp);
3711 bgp_clear_star_soft_in(vty, bgp->name);
3712
3713 return CMD_SUCCESS;
ff8a8a7a 3714}
6b0655a2 3715
ff8a8a7a 3716
1ca2fd11
IR
3717DEFUN (bgp_default_subgroup_pkt_queue_max,
3718 bgp_default_subgroup_pkt_queue_max_cmd,
3719 "bgp default subgroup-pkt-queue-max (20-100)",
3720 "BGP specific commands\n"
3721 "Configure BGP defaults\n"
3722 "subgroup-pkt-queue-max\n"
3723 "Configure subgroup packet queue max\n")
8bd9d948 3724{
1ca2fd11 3725 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3726 int idx_number = 3;
1ca2fd11 3727 uint32_t max_size;
3f9c7369 3728
1ca2fd11 3729 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3730
1ca2fd11 3731 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3732
1ca2fd11 3733 return CMD_SUCCESS;
8bd9d948
DS
3734}
3735
1ca2fd11
IR
3736DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3737 no_bgp_default_subgroup_pkt_queue_max_cmd,
3738 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3739 NO_STR
3740 "BGP specific commands\n"
3741 "Configure BGP defaults\n"
3742 "subgroup-pkt-queue-max\n"
3743 "Configure subgroup packet queue max\n")
ff8a8a7a 3744{
1ca2fd11
IR
3745 VTY_DECLVAR_CONTEXT(bgp, bgp);
3746 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3747 return CMD_SUCCESS;
ff8a8a7a 3748}
813d4307 3749
8bd9d948 3750
1ca2fd11
IR
3751DEFUN (bgp_rr_allow_outbound_policy,
3752 bgp_rr_allow_outbound_policy_cmd,
3753 "bgp route-reflector allow-outbound-policy",
3754 "BGP specific commands\n"
3755 "Allow modifications made by out route-map\n"
3756 "on ibgp neighbors\n")
ff8a8a7a 3757{
1ca2fd11 3758 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3759
1ca2fd11
IR
3760 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3761 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3762 update_group_announce_rrclients(bgp);
3763 bgp_clear_star_soft_out(vty, bgp->name);
3764 }
8bd9d948 3765
1ca2fd11
IR
3766 return CMD_SUCCESS;
3767}
ff8a8a7a 3768
1ca2fd11
IR
3769DEFUN (no_bgp_rr_allow_outbound_policy,
3770 no_bgp_rr_allow_outbound_policy_cmd,
3771 "no bgp route-reflector allow-outbound-policy",
3772 NO_STR
3773 "BGP specific commands\n"
3774 "Allow modifications made by out route-map\n"
3775 "on ibgp neighbors\n")
8bd9d948 3776{
1ca2fd11 3777 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3778
1ca2fd11
IR
3779 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3780 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3781 update_group_announce_rrclients(bgp);
3782 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 3783 }
8bd9d948 3784
1ca2fd11 3785 return CMD_SUCCESS;
8bd9d948
DS
3786}
3787
1ca2fd11
IR
3788DEFUN (bgp_listen_limit,
3789 bgp_listen_limit_cmd,
3790 "bgp listen limit (1-65535)",
3791 "BGP specific commands\n"
3792 "BGP Dynamic Neighbors listen commands\n"
3793 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3794 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3795{
1ca2fd11 3796 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3797 int idx_number = 3;
1ca2fd11
IR
3798 int listen_limit;
3799
3800 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 3801
1ca2fd11 3802 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 3803
1ca2fd11 3804 return CMD_SUCCESS;
f14e6fdb
DS
3805}
3806
1ca2fd11
IR
3807DEFUN (no_bgp_listen_limit,
3808 no_bgp_listen_limit_cmd,
3809 "no bgp listen limit [(1-65535)]",
3810 NO_STR
3811 "BGP specific commands\n"
3812 "BGP Dynamic Neighbors listen commands\n"
3813 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3814 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3815{
1ca2fd11
IR
3816 VTY_DECLVAR_CONTEXT(bgp, bgp);
3817 bgp_listen_limit_unset(bgp);
3818 return CMD_SUCCESS;
f14e6fdb
DS
3819}
3820
3821
20eb8864 3822/*
3823 * Check if this listen range is already configured. Check for exact
3824 * match or overlap based on input.
3825 */
d62a17ae 3826static struct peer_group *listen_range_exists(struct bgp *bgp,
3827 struct prefix *range, int exact)
3828{
3829 struct listnode *node, *nnode;
3830 struct listnode *node1, *nnode1;
3831 struct peer_group *group;
3832 struct prefix *lr;
3833 afi_t afi;
3834 int match;
3835
3836 afi = family2afi(range->family);
3837 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3838 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3839 lr)) {
3840 if (exact)
3841 match = prefix_same(range, lr);
3842 else
3843 match = (prefix_match(range, lr)
3844 || prefix_match(lr, range));
3845 if (match)
3846 return group;
3847 }
3848 }
3849
3850 return NULL;
20eb8864 3851}
3852
f14e6fdb
DS
3853DEFUN (bgp_listen_range,
3854 bgp_listen_range_cmd,
d7b9898c 3855 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3856 "BGP specific commands\n"
d7fa34c1
QY
3857 "Configure BGP dynamic neighbors listen range\n"
3858 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3859 NEIGHBOR_ADDR_STR
3860 "Member of the peer-group\n"
3861 "Peer-group name\n")
f14e6fdb 3862{
d62a17ae 3863 VTY_DECLVAR_CONTEXT(bgp, bgp);
3864 struct prefix range;
3865 struct peer_group *group, *existing_group;
3866 afi_t afi;
3867 int ret;
3868 int idx = 0;
3869
3870 argv_find(argv, argc, "A.B.C.D/M", &idx);
3871 argv_find(argv, argc, "X:X::X:X/M", &idx);
3872 char *prefix = argv[idx]->arg;
d7b9898c 3873 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3874 char *peergroup = argv[idx]->arg;
3875
3876 /* Convert IP prefix string to struct prefix. */
3877 ret = str2prefix(prefix, &range);
3878 if (!ret) {
3879 vty_out(vty, "%% Malformed listen range\n");
3880 return CMD_WARNING_CONFIG_FAILED;
3881 }
3882
3883 afi = family2afi(range.family);
3884
3885 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3886 vty_out(vty,
3887 "%% Malformed listen range (link-local address)\n");
3888 return CMD_WARNING_CONFIG_FAILED;
3889 }
3890
3891 apply_mask(&range);
3892
3893 /* Check if same listen range is already configured. */
3894 existing_group = listen_range_exists(bgp, &range, 1);
3895 if (existing_group) {
3896 if (strcmp(existing_group->name, peergroup) == 0)
3897 return CMD_SUCCESS;
3898 else {
3899 vty_out(vty,
3900 "%% Same listen range is attached to peer-group %s\n",
3901 existing_group->name);
3902 return CMD_WARNING_CONFIG_FAILED;
3903 }
3904 }
3905
3906 /* Check if an overlapping listen range exists. */
3907 if (listen_range_exists(bgp, &range, 0)) {
3908 vty_out(vty,
3909 "%% Listen range overlaps with existing listen range\n");
3910 return CMD_WARNING_CONFIG_FAILED;
3911 }
3912
3913 group = peer_group_lookup(bgp, peergroup);
3914 if (!group) {
3915 vty_out(vty, "%% Configure the peer-group first\n");
3916 return CMD_WARNING_CONFIG_FAILED;
3917 }
3918
3919 ret = peer_group_listen_range_add(group, &range);
3920 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3921}
3922
3923DEFUN (no_bgp_listen_range,
3924 no_bgp_listen_range_cmd,
d7b9898c 3925 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3926 NO_STR
f14e6fdb 3927 "BGP specific commands\n"
d7fa34c1
QY
3928 "Unconfigure BGP dynamic neighbors listen range\n"
3929 "Unconfigure BGP dynamic neighbors listen range\n"
3930 NEIGHBOR_ADDR_STR
3931 "Member of the peer-group\n"
3932 "Peer-group name\n")
f14e6fdb 3933{
d62a17ae 3934 VTY_DECLVAR_CONTEXT(bgp, bgp);
3935 struct prefix range;
3936 struct peer_group *group;
3937 afi_t afi;
3938 int ret;
3939 int idx = 0;
3940
3941 argv_find(argv, argc, "A.B.C.D/M", &idx);
3942 argv_find(argv, argc, "X:X::X:X/M", &idx);
3943 char *prefix = argv[idx]->arg;
21d88a71 3944 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3945 char *peergroup = argv[idx]->arg;
3946
3947 /* Convert IP prefix string to struct prefix. */
3948 ret = str2prefix(prefix, &range);
3949 if (!ret) {
3950 vty_out(vty, "%% Malformed listen range\n");
3951 return CMD_WARNING_CONFIG_FAILED;
3952 }
3953
3954 afi = family2afi(range.family);
3955
3956 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3957 vty_out(vty,
3958 "%% Malformed listen range (link-local address)\n");
3959 return CMD_WARNING_CONFIG_FAILED;
3960 }
3961
3962 apply_mask(&range);
3963
3964 group = peer_group_lookup(bgp, peergroup);
3965 if (!group) {
3966 vty_out(vty, "%% Peer-group does not exist\n");
3967 return CMD_WARNING_CONFIG_FAILED;
3968 }
3969
3970 ret = peer_group_listen_range_del(group, &range);
3971 return bgp_vty_return(vty, ret);
3972}
3973
2b791107 3974void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3975{
3976 struct peer_group *group;
3977 struct listnode *node, *nnode, *rnode, *nrnode;
3978 struct prefix *range;
3979 afi_t afi;
d62a17ae 3980
3981 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3982 vty_out(vty, " bgp listen limit %d\n",
3983 bgp->dynamic_neighbors_limit);
3984
3985 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3986 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3987 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3988 nrnode, range)) {
d62a17ae 3989 vty_out(vty,
2dbe669b
DA
3990 " bgp listen range %pFX peer-group %s\n",
3991 range, group->name);
d62a17ae 3992 }
3993 }
3994 }
f14e6fdb
DS
3995}
3996
3997
1ca2fd11
IR
3998DEFUN (bgp_disable_connected_route_check,
3999 bgp_disable_connected_route_check_cmd,
4000 "bgp disable-ebgp-connected-route-check",
4001 "BGP specific commands\n"
4002 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4003{
1ca2fd11
IR
4004 VTY_DECLVAR_CONTEXT(bgp, bgp);
4005 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4006 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4007
1ca2fd11 4008 return CMD_SUCCESS;
907f92c8
DS
4009}
4010
1ca2fd11
IR
4011DEFUN (no_bgp_disable_connected_route_check,
4012 no_bgp_disable_connected_route_check_cmd,
4013 "no bgp disable-ebgp-connected-route-check",
4014 NO_STR
4015 "BGP specific commands\n"
4016 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4017{
1ca2fd11
IR
4018 VTY_DECLVAR_CONTEXT(bgp, bgp);
4019 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4020 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4021
1ca2fd11 4022 return CMD_SUCCESS;
d62a17ae 4023}
4024
4025
28c6e247
IR
4026static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4027 const char *as_str)
4028{
4029 VTY_DECLVAR_CONTEXT(bgp, bgp);
4030 int ret;
4031 as_t as;
4032 int as_type = AS_SPECIFIED;
4033 union sockunion su;
4034
4035 if (as_str[0] == 'i') {
4036 as = 0;
4037 as_type = AS_INTERNAL;
4038 } else if (as_str[0] == 'e') {
4039 as = 0;
4040 as_type = AS_EXTERNAL;
4041 } else {
4042 /* Get AS number. */
4043 as = strtoul(as_str, NULL, 10);
4044 }
4045
4046 /* If peer is peer group or interface peer, call proper function. */
4047 ret = str2sockunion(peer_str, &su);
4048 if (ret < 0) {
4049 struct peer *peer;
4050
4051 /* Check if existing interface peer */
4052 peer = peer_lookup_by_conf_if(bgp, peer_str);
4053
4054 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4055
4056 /* if not interface peer, check peer-group settings */
4057 if (ret < 0 && !peer) {
4058 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4059 if (ret < 0) {
4060 vty_out(vty,
4061 "%% Create the peer-group or interface first\n");
4062 return CMD_WARNING_CONFIG_FAILED;
4063 }
4064 return CMD_SUCCESS;
4065 }
4066 } else {
4067 if (peer_address_self_check(bgp, &su)) {
4068 vty_out(vty,
4069 "%% Can not configure the local system as neighbor\n");
4070 return CMD_WARNING_CONFIG_FAILED;
4071 }
4072 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4073 }
4074
4075 /* This peer belongs to peer group. */
4076 switch (ret) {
4077 case BGP_ERR_PEER_GROUP_MEMBER:
4078 vty_out(vty,
4079 "%% Peer-group member cannot override remote-as of peer-group\n");
4080 return CMD_WARNING_CONFIG_FAILED;
4081 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
4082 vty_out(vty,
4083 "%% Peer-group members must be all internal or all external\n");
4084 return CMD_WARNING_CONFIG_FAILED;
4085 }
4086 return bgp_vty_return(vty, ret);
4087}
4088
1ca2fd11
IR
4089DEFUN (bgp_default_shutdown,
4090 bgp_default_shutdown_cmd,
4091 "[no] bgp default shutdown",
4092 NO_STR
4093 BGP_STR
4094 "Configure BGP defaults\n"
4095 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4096{
1ca2fd11
IR
4097 VTY_DECLVAR_CONTEXT(bgp, bgp);
4098 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4099 return CMD_SUCCESS;
f26845f9
QY
4100}
4101
736b68f3
DS
4102DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4103 BGP_STR
9ddf4b81 4104 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4105 "Add a shutdown message (RFC 8203)\n"
4106 "Shutdown message\n")
9cf59432 4107{
736b68f3 4108 char *msgstr = NULL;
8389c83a 4109
9cf59432
DS
4110 VTY_DECLVAR_CONTEXT(bgp, bgp);
4111
8389c83a 4112 if (argc > 3)
f80e35b6 4113 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4114
4115 bgp_shutdown_enable(bgp, msgstr);
4116 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4117
4118 return CMD_SUCCESS;
4119}
4120
736b68f3 4121DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4122 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4123{
4124 VTY_DECLVAR_CONTEXT(bgp, bgp);
4125
4126 bgp_shutdown_enable(bgp, NULL);
4127
4128 return CMD_SUCCESS;
4129}
8389c83a 4130
736b68f3 4131DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4132 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4133{
4134 VTY_DECLVAR_CONTEXT(bgp, bgp);
4135
4136 bgp_shutdown_disable(bgp);
4137
4138 return CMD_SUCCESS;
4139}
4140
9ddf4b81 4141ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4142 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4143 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4144 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4145
28c6e247
IR
4146DEFUN (neighbor_remote_as,
4147 neighbor_remote_as_cmd,
4148 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4149 NEIGHBOR_STR
4150 NEIGHBOR_ADDR_STR2
4151 "Specify a BGP neighbor\n"
4152 AS_STR
4153 "Internal BGP peer\n"
4154 "External BGP peer\n")
718e3744 4155{
d62a17ae 4156 int idx_peer = 1;
4157 int idx_remote_as = 3;
28c6e247
IR
4158 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4159 argv[idx_remote_as]->arg);
d62a17ae 4160}
4161
28c6e247
IR
4162static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4163 int v6only,
4164 const char *peer_group_name,
4165 const char *as_str)
d62a17ae 4166{
28c6e247
IR
4167 VTY_DECLVAR_CONTEXT(bgp, bgp);
4168 as_t as = 0;
4169 int as_type = AS_UNSPECIFIED;
d62a17ae 4170 struct peer *peer;
4171 struct peer_group *group;
4172 int ret = 0;
d62a17ae 4173
4174 group = peer_group_lookup(bgp, conf_if);
4175
4176 if (group) {
28c6e247
IR
4177 vty_out(vty, "%% Name conflict with peer-group \n");
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180
4181 if (as_str) {
4182 if (as_str[0] == 'i') {
4183 as_type = AS_INTERNAL;
4184 } else if (as_str[0] == 'e') {
4185 as_type = AS_EXTERNAL;
4186 } else {
4187 /* Get AS number. */
4188 as = strtoul(as_str, NULL, 10);
4189 as_type = AS_SPECIFIED;
4190 }
d62a17ae 4191 }
4192
4193 peer = peer_lookup_by_conf_if(bgp, conf_if);
4194 if (peer) {
28c6e247 4195 if (as_str)
e84c59af 4196 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4197 } else {
e84c59af
DA
4198 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4199 NULL);
d62a17ae 4200
4201 if (!peer) {
28c6e247
IR
4202 vty_out(vty, "%% BGP failed to create peer\n");
4203 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4204 }
4205
4206 if (v6only)
527de3dc 4207 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4208
4209 /* Request zebra to initiate IPv6 RAs on this interface. We do
4210 * this
4211 * any unnumbered peer in order to not worry about run-time
4212 * transitions
4213 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4214 * address
4215 * gets deleted later etc.)
4216 */
4217 if (peer->ifp)
4218 bgp_zebra_initiate_radv(bgp, peer);
4219 }
4220
4221 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4222 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4223 if (v6only)
527de3dc 4224 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4225 else
527de3dc 4226 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4227
4228 /* v6only flag changed. Reset bgp seesion */
4229 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4230 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4231 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4232 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4233 } else
4234 bgp_session_reset(peer);
4235 }
4236
9fb964de
PM
4237 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4238 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4239 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4240 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4241 }
d62a17ae 4242
4243 if (peer_group_name) {
4244 group = peer_group_lookup(bgp, peer_group_name);
4245 if (!group) {
28c6e247
IR
4246 vty_out(vty, "%% Configure the peer-group first\n");
4247 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4248 }
4249
8395c1f8 4250 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4251 }
4252
28c6e247 4253 return bgp_vty_return(vty, ret);
a80beece
DS
4254}
4255
28c6e247
IR
4256DEFUN (neighbor_interface_config,
4257 neighbor_interface_config_cmd,
4258 "neighbor WORD interface [peer-group PGNAME]",
4259 NEIGHBOR_STR
4260 "Interface name or neighbor tag\n"
4261 "Enable BGP on interface\n"
4262 "Member of the peer-group\n"
4263 "Peer-group name\n")
4c48cf63 4264{
d62a17ae 4265 int idx_word = 1;
4266 int idx_peer_group_word = 4;
f4b8ec07 4267
d62a17ae 4268 if (argc > idx_peer_group_word)
28c6e247
IR
4269 return peer_conf_interface_get(
4270 vty, argv[idx_word]->arg, 0,
4271 argv[idx_peer_group_word]->arg, NULL);
4272 else
4273 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4274 NULL, NULL);
4c48cf63
DW
4275}
4276
28c6e247
IR
4277DEFUN (neighbor_interface_config_v6only,
4278 neighbor_interface_config_v6only_cmd,
4279 "neighbor WORD interface v6only [peer-group PGNAME]",
4280 NEIGHBOR_STR
4281 "Interface name or neighbor tag\n"
4282 "Enable BGP on interface\n"
4283 "Enable BGP with v6 link-local only\n"
4284 "Member of the peer-group\n"
4285 "Peer-group name\n")
4c48cf63 4286{
d62a17ae 4287 int idx_word = 1;
4288 int idx_peer_group_word = 5;
31500417 4289
d62a17ae 4290 if (argc > idx_peer_group_word)
28c6e247
IR
4291 return peer_conf_interface_get(
4292 vty, argv[idx_word]->arg, 1,
4293 argv[idx_peer_group_word]->arg, NULL);
31500417 4294
28c6e247 4295 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4296}
4297
a80beece 4298
28c6e247
IR
4299DEFUN (neighbor_interface_config_remote_as,
4300 neighbor_interface_config_remote_as_cmd,
4301 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4302 NEIGHBOR_STR
4303 "Interface name or neighbor tag\n"
4304 "Enable BGP on interface\n"
4305 "Specify a BGP neighbor\n"
4306 AS_STR
4307 "Internal BGP peer\n"
4308 "External BGP peer\n")
b3a39dc5 4309{
d62a17ae 4310 int idx_word = 1;
4311 int idx_remote_as = 4;
28c6e247
IR
4312 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4313 argv[idx_remote_as]->arg);
b3a39dc5
DD
4314}
4315
28c6e247
IR
4316DEFUN (neighbor_interface_v6only_config_remote_as,
4317 neighbor_interface_v6only_config_remote_as_cmd,
4318 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4319 NEIGHBOR_STR
4320 "Interface name or neighbor tag\n"
4321 "Enable BGP with v6 link-local only\n"
4322 "Enable BGP on interface\n"
4323 "Specify a BGP neighbor\n"
4324 AS_STR
4325 "Internal BGP peer\n"
4326 "External BGP peer\n")
b3a39dc5 4327{
d62a17ae 4328 int idx_word = 1;
4329 int idx_remote_as = 5;
28c6e247
IR
4330 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4331 argv[idx_remote_as]->arg);
b3a39dc5
DD
4332}
4333
28c6e247
IR
4334DEFUN (neighbor_peer_group,
4335 neighbor_peer_group_cmd,
4336 "neighbor WORD peer-group",
4337 NEIGHBOR_STR
4338 "Interface name or neighbor tag\n"
4339 "Configure peer-group\n")
718e3744 4340{
28c6e247 4341 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4342 int idx_word = 1;
28c6e247
IR
4343 struct peer *peer;
4344 struct peer_group *group;
718e3744 4345
28c6e247
IR
4346 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4347 if (peer) {
4348 vty_out(vty, "%% Name conflict with interface: \n");
4349 return CMD_WARNING_CONFIG_FAILED;
4350 }
718e3744 4351
28c6e247
IR
4352 group = peer_group_get(bgp, argv[idx_word]->arg);
4353 if (!group) {
4354 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4355 return CMD_WARNING_CONFIG_FAILED;
4356 }
718e3744 4357
28c6e247 4358 return CMD_SUCCESS;
718e3744 4359}
4360
1d80f243
IR
4361DEFUN (no_neighbor,
4362 no_neighbor_cmd,
4363 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4364 NO_STR
4365 NEIGHBOR_STR
4366 NEIGHBOR_ADDR_STR2
4367 "Specify a BGP neighbor\n"
4368 AS_STR
4369 "Internal BGP peer\n"
4370 "External BGP peer\n")
718e3744 4371{
28c6e247 4372 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4373 int idx_peer = 2;
28c6e247 4374 int ret;
d62a17ae 4375 union sockunion su;
28c6e247
IR
4376 struct peer_group *group;
4377 struct peer *peer;
4378 struct peer *other;
d62a17ae 4379
28c6e247
IR
4380 ret = str2sockunion(argv[idx_peer]->arg, &su);
4381 if (ret < 0) {
4382 /* look up for neighbor by interface name config. */
4383 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4384 if (peer) {
4385 /* Request zebra to terminate IPv6 RAs on this
4386 * interface. */
4387 if (peer->ifp)
4388 bgp_zebra_terminate_radv(peer->bgp, peer);
4389 peer_notify_unconfig(peer);
4390 peer_delete(peer);
4391 return CMD_SUCCESS;
d62a17ae 4392 }
28c6e247
IR
4393
4394 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4395 if (group) {
4396 peer_group_notify_unconfig(group);
4397 peer_group_delete(group);
4e2786df 4398 } else {
28c6e247 4399 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4400 return CMD_WARNING_CONFIG_FAILED;
4401 }
28c6e247
IR
4402 } else {
4403 peer = peer_lookup(bgp, &su);
4404 if (peer) {
4405 if (peer_dynamic_neighbor(peer)) {
4406 vty_out(vty,
4407 "%% Operation not allowed on a dynamic neighbor\n");
4408 return CMD_WARNING_CONFIG_FAILED;
4409 }
d62a17ae 4410
28c6e247 4411 other = peer->doppelganger;
f4b8ec07 4412
28c6e247
IR
4413 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4414 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4415
28c6e247
IR
4416 peer_notify_unconfig(peer);
4417 peer_delete(peer);
4418 if (other && other->status != Deleted) {
4419 peer_notify_unconfig(other);
4420 peer_delete(other);
4421 }
4422 }
4423 }
4424
4425 return CMD_SUCCESS;
a80beece
DS
4426}
4427
28c6e247
IR
4428DEFUN (no_neighbor_interface_config,
4429 no_neighbor_interface_config_cmd,
4430 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4431 NO_STR
4432 NEIGHBOR_STR
4433 "Interface name\n"
4434 "Configure BGP on interface\n"
4435 "Enable BGP with v6 link-local only\n"
4436 "Member of the peer-group\n"
4437 "Peer-group name\n"
4438 "Specify a BGP neighbor\n"
4439 AS_STR
4440 "Internal BGP peer\n"
4441 "External BGP peer\n")
718e3744 4442{
28c6e247 4443 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4444 int idx_word = 2;
28c6e247 4445 struct peer *peer;
718e3744 4446
28c6e247
IR
4447 /* look up for neighbor by interface name config. */
4448 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4449 if (peer) {
4450 /* Request zebra to terminate IPv6 RAs on this interface. */
4451 if (peer->ifp)
4452 bgp_zebra_terminate_radv(peer->bgp, peer);
4453 peer_notify_unconfig(peer);
4454 peer_delete(peer);
4455 } else {
4456 vty_out(vty, "%% Create the bgp interface first\n");
4457 return CMD_WARNING_CONFIG_FAILED;
4458 }
4459 return CMD_SUCCESS;
718e3744 4460}
4461
28c6e247
IR
4462DEFUN (no_neighbor_peer_group,
4463 no_neighbor_peer_group_cmd,
4464 "no neighbor WORD peer-group",
4465 NO_STR
4466 NEIGHBOR_STR
4467 "Neighbor tag\n"
4468 "Configure peer-group\n")
718e3744 4469{
28c6e247
IR
4470 VTY_DECLVAR_CONTEXT(bgp, bgp);
4471 int idx_word = 2;
4472 struct peer_group *group;
f4b8ec07 4473
28c6e247
IR
4474 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4475 if (group) {
4476 peer_group_notify_unconfig(group);
4477 peer_group_delete(group);
f4b8ec07 4478 } else {
28c6e247 4479 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4480 return CMD_WARNING_CONFIG_FAILED;
4481 }
28c6e247
IR
4482 return CMD_SUCCESS;
4483}
f4b8ec07 4484
28c6e247
IR
4485DEFUN (no_neighbor_interface_peer_group_remote_as,
4486 no_neighbor_interface_peer_group_remote_as_cmd,
4487 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4488 NO_STR
4489 NEIGHBOR_STR
4490 "Interface name or neighbor tag\n"
4491 "Specify a BGP neighbor\n"
4492 AS_STR
4493 "Internal BGP peer\n"
4494 "External BGP peer\n")
4495{
4496 VTY_DECLVAR_CONTEXT(bgp, bgp);
4497 int idx_word = 2;
4498 struct peer_group *group;
4499 struct peer *peer;
f4b8ec07 4500
28c6e247
IR
4501 /* look up for neighbor by interface name config. */
4502 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4503 if (peer) {
4504 peer_as_change(peer, 0, AS_UNSPECIFIED);
4505 return CMD_SUCCESS;
4506 }
f4b8ec07 4507
28c6e247
IR
4508 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4509 if (group)
4510 peer_group_remote_as_delete(group);
4511 else {
4512 vty_out(vty, "%% Create the peer-group or interface first\n");
4513 return CMD_WARNING_CONFIG_FAILED;
4514 }
4515 return CMD_SUCCESS;
718e3744 4516}
6b0655a2 4517
28c6e247
IR
4518DEFUN (neighbor_local_as,
4519 neighbor_local_as_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "Specify a local-as number\n"
4524 "AS number used as local AS\n")
718e3744 4525{
d62a17ae 4526 int idx_peer = 1;
4527 int idx_number = 3;
28c6e247
IR
4528 struct peer *peer;
4529 int ret;
4530 as_t as;
718e3744 4531
28c6e247
IR
4532 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4533 if (!peer)
d62a17ae 4534 return CMD_WARNING_CONFIG_FAILED;
718e3744 4535
28c6e247
IR
4536 as = strtoul(argv[idx_number]->arg, NULL, 10);
4537 ret = peer_local_as_set(peer, as, 0, 0);
4538 return bgp_vty_return(vty, ret);
718e3744 4539}
4540
28c6e247
IR
4541DEFUN (neighbor_local_as_no_prepend,
4542 neighbor_local_as_no_prepend_cmd,
4543 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4544 NEIGHBOR_STR
4545 NEIGHBOR_ADDR_STR2
4546 "Specify a local-as number\n"
4547 "AS number used as local AS\n"
4548 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4549{
d62a17ae 4550 int idx_peer = 1;
4551 int idx_number = 3;
28c6e247
IR
4552 struct peer *peer;
4553 int ret;
4554 as_t as;
718e3744 4555
28c6e247
IR
4556 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4557 if (!peer)
d62a17ae 4558 return CMD_WARNING_CONFIG_FAILED;
718e3744 4559
28c6e247
IR
4560 as = strtoul(argv[idx_number]->arg, NULL, 10);
4561 ret = peer_local_as_set(peer, as, 1, 0);
4562 return bgp_vty_return(vty, ret);
718e3744 4563}
4564
28c6e247
IR
4565DEFUN (neighbor_local_as_no_prepend_replace_as,
4566 neighbor_local_as_no_prepend_replace_as_cmd,
4567 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4568 NEIGHBOR_STR
4569 NEIGHBOR_ADDR_STR2
4570 "Specify a local-as number\n"
4571 "AS number used as local AS\n"
4572 "Do not prepend local-as to updates from ebgp peers\n"
4573 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4574{
d62a17ae 4575 int idx_peer = 1;
4576 int idx_number = 3;
28c6e247
IR
4577 struct peer *peer;
4578 int ret;
4579 as_t as;
9d3f9705 4580
28c6e247
IR
4581 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4582 if (!peer)
d62a17ae 4583 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4584
28c6e247
IR
4585 as = strtoul(argv[idx_number]->arg, NULL, 10);
4586 ret = peer_local_as_set(peer, as, 1, 1);
4587 return bgp_vty_return(vty, ret);
9d3f9705
AC
4588}
4589
28c6e247
IR
4590DEFUN (no_neighbor_local_as,
4591 no_neighbor_local_as_cmd,
4592 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4593 NO_STR
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "Specify a local-as number\n"
4597 "AS number used as local AS\n"
4598 "Do not prepend local-as to updates from ebgp peers\n"
4599 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4600{
d62a17ae 4601 int idx_peer = 2;
28c6e247
IR
4602 struct peer *peer;
4603 int ret;
718e3744 4604
28c6e247
IR
4605 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4606 if (!peer)
d62a17ae 4607 return CMD_WARNING_CONFIG_FAILED;
718e3744 4608
28c6e247
IR
4609 ret = peer_local_as_unset(peer);
4610 return bgp_vty_return(vty, ret);
718e3744 4611}
4612
718e3744 4613
3f9c7369
DS
4614DEFUN (neighbor_solo,
4615 neighbor_solo_cmd,
9ccf14f7 4616 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4617 NEIGHBOR_STR
4618 NEIGHBOR_ADDR_STR2
4619 "Solo peer - part of its own update group\n")
4620{
d62a17ae 4621 int idx_peer = 1;
4622 struct peer *peer;
4623 int ret;
3f9c7369 4624
d62a17ae 4625 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4628
d62a17ae 4629 ret = update_group_adjust_soloness(peer, 1);
4630 return bgp_vty_return(vty, ret);
3f9c7369
DS
4631}
4632
4633DEFUN (no_neighbor_solo,
4634 no_neighbor_solo_cmd,
9ccf14f7 4635 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4636 NO_STR
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Solo peer - part of its own update group\n")
4640{
d62a17ae 4641 int idx_peer = 2;
4642 struct peer *peer;
4643 int ret;
3f9c7369 4644
d62a17ae 4645 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4646 if (!peer)
4647 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4648
d62a17ae 4649 ret = update_group_adjust_soloness(peer, 0);
4650 return bgp_vty_return(vty, ret);
3f9c7369
DS
4651}
4652
28c6e247
IR
4653DEFUN (neighbor_password,
4654 neighbor_password_cmd,
4655 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4656 NEIGHBOR_STR
4657 NEIGHBOR_ADDR_STR2
4658 "Set a password\n"
4659 "The password\n")
0df7c91f 4660{
d62a17ae 4661 int idx_peer = 1;
4662 int idx_line = 3;
28c6e247
IR
4663 struct peer *peer;
4664 int ret;
0df7c91f 4665
28c6e247
IR
4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
d62a17ae 4668 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4669
28c6e247
IR
4670 ret = peer_password_set(peer, argv[idx_line]->arg);
4671 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4672}
4673
28c6e247
IR
4674DEFUN (no_neighbor_password,
4675 no_neighbor_password_cmd,
4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4677 NO_STR
4678 NEIGHBOR_STR
4679 NEIGHBOR_ADDR_STR2
4680 "Set a password\n"
4681 "The password\n")
0df7c91f 4682{
d62a17ae 4683 int idx_peer = 2;
28c6e247
IR
4684 struct peer *peer;
4685 int ret;
0df7c91f 4686
28c6e247
IR
4687 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4688 if (!peer)
d62a17ae 4689 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4690
28c6e247
IR
4691 ret = peer_password_unset(peer);
4692 return bgp_vty_return(vty, ret);
0df7c91f 4693}
6b0655a2 4694
28c6e247
IR
4695DEFUN (neighbor_activate,
4696 neighbor_activate_cmd,
4697 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4698 NEIGHBOR_STR
4699 NEIGHBOR_ADDR_STR2
4700 "Enable the Address Family for this Neighbor\n")
718e3744 4701{
d62a17ae 4702 int idx_peer = 1;
28c6e247
IR
4703 int ret;
4704 struct peer *peer;
56ceae84 4705
28c6e247
IR
4706 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4707 if (!peer)
d62a17ae 4708 return CMD_WARNING_CONFIG_FAILED;
718e3744 4709
28c6e247
IR
4710 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4711 return bgp_vty_return(vty, ret);
718e3744 4712}
4713
d62a17ae 4714ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4715 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4716 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4717 "Enable the Address Family for this Neighbor\n")
596c17ba 4718
28c6e247
IR
4719DEFUN (no_neighbor_activate,
4720 no_neighbor_activate_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Enable the Address Family for this Neighbor\n")
718e3744 4726{
d62a17ae 4727 int idx_peer = 2;
28c6e247
IR
4728 int ret;
4729 struct peer *peer;
f4b8ec07 4730
28c6e247
IR
4731 /* Lookup peer. */
4732 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4733 if (!peer)
d62a17ae 4734 return CMD_WARNING_CONFIG_FAILED;
718e3744 4735
28c6e247
IR
4736 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4737 return bgp_vty_return(vty, ret);
718e3744 4738}
6b0655a2 4739
d62a17ae 4740ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4741 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4742 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4743 "Enable the Address Family for this Neighbor\n")
596c17ba 4744
28c6e247
IR
4745DEFUN (neighbor_set_peer_group,
4746 neighbor_set_peer_group_cmd,
4747 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4748 NEIGHBOR_STR
4749 NEIGHBOR_ADDR_STR2
4750 "Member of the peer-group\n"
4751 "Peer-group name\n")
718e3744 4752{
28c6e247 4753 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4754 int idx_peer = 1;
4755 int idx_word = 3;
28c6e247
IR
4756 int ret;
4757 as_t as;
4758 union sockunion su;
4759 struct peer *peer;
4760 struct peer_group *group;
4761
4762 ret = str2sockunion(argv[idx_peer]->arg, &su);
4763 if (ret < 0) {
4764 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4765 if (!peer) {
4766 vty_out(vty, "%% Malformed address or name: %s\n",
4767 argv[idx_peer]->arg);
4768 return CMD_WARNING_CONFIG_FAILED;
4769 }
4770 } else {
4771 if (peer_address_self_check(bgp, &su)) {
4772 vty_out(vty,
4773 "%% Can not configure the local system as neighbor\n");
4774 return CMD_WARNING_CONFIG_FAILED;
4775 }
2a059a54 4776
28c6e247
IR
4777 /* Disallow for dynamic neighbor. */
4778 peer = peer_lookup(bgp, &su);
4779 if (peer && peer_dynamic_neighbor(peer)) {
4780 vty_out(vty,
4781 "%% Operation not allowed on a dynamic neighbor\n");
4782 return CMD_WARNING_CONFIG_FAILED;
4783 }
4784 }
4785
4786 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4787 if (!group) {
4788 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 4789 return CMD_WARNING_CONFIG_FAILED;
28c6e247 4790 }
d62a17ae 4791
28c6e247 4792 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 4793
28c6e247
IR
4794 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4795 vty_out(vty,
4796 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4797 as);
4798 return CMD_WARNING_CONFIG_FAILED;
4799 }
4800
4801 return bgp_vty_return(vty, ret);
d62a17ae 4802}
4803
4804ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4805 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4806 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4807 "Member of the peer-group\n"
4808 "Peer-group name\n")
596c17ba 4809
28c6e247
IR
4810DEFUN (no_neighbor_set_peer_group,
4811 no_neighbor_set_peer_group_cmd,
4812 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4813 NO_STR
4814 NEIGHBOR_STR
4815 NEIGHBOR_ADDR_STR2
4816 "Member of the peer-group\n"
4817 "Peer-group name\n")
718e3744 4818{
28c6e247 4819 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4820 int idx_peer = 2;
28c6e247
IR
4821 int idx_word = 4;
4822 int ret;
4823 struct peer *peer;
4824 struct peer_group *group;
d62a17ae 4825
28c6e247
IR
4826 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4827 if (!peer)
d62a17ae 4828 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 4829
28c6e247
IR
4830 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4831 if (!group) {
4832 vty_out(vty, "%% Configure the peer-group first\n");
4833 return CMD_WARNING_CONFIG_FAILED;
4834 }
718e3744 4835
28c6e247
IR
4836 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4837 bgp_zebra_terminate_radv(peer->bgp, peer);
4838
4839 peer_notify_unconfig(peer);
4840 ret = peer_delete(peer);
4841
4842 return bgp_vty_return(vty, ret);
718e3744 4843}
6b0655a2 4844
d62a17ae 4845ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 4846 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4848 "Member of the peer-group\n"
4849 "Peer-group name\n")
596c17ba 4850
d62a17ae 4851static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4852 uint32_t flag, int set)
718e3744 4853{
d62a17ae 4854 int ret;
4855 struct peer *peer;
718e3744 4856
d62a17ae 4857 peer = peer_and_group_lookup_vty(vty, ip_str);
4858 if (!peer)
4859 return CMD_WARNING_CONFIG_FAILED;
718e3744 4860
7ebe625c
QY
4861 /*
4862 * If 'neighbor <interface>', then this is for directly connected peers,
4863 * we should not accept disable-connected-check.
4864 */
4865 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4866 vty_out(vty,
3efd0893 4867 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4868 ip_str);
4869 return CMD_WARNING_CONFIG_FAILED;
4870 }
4871
d62a17ae 4872 if (!set && flag == PEER_FLAG_SHUTDOWN)
4873 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4874
d62a17ae 4875 if (set)
4876 ret = peer_flag_set(peer, flag);
4877 else
4878 ret = peer_flag_unset(peer, flag);
718e3744 4879
d62a17ae 4880 return bgp_vty_return(vty, ret);
718e3744 4881}
4882
47cbc09b 4883static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4884{
d62a17ae 4885 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4886}
4887
d62a17ae 4888static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4889 uint32_t flag)
718e3744 4890{
d62a17ae 4891 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4892}
4893
4894/* neighbor passive. */
28c6e247
IR
4895DEFUN (neighbor_passive,
4896 neighbor_passive_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Don't send open messages to this neighbor\n")
718e3744 4901{
d62a17ae 4902 int idx_peer = 1;
28c6e247 4903 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4904}
4905
28c6e247
IR
4906DEFUN (no_neighbor_passive,
4907 no_neighbor_passive_cmd,
4908 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
4909 NO_STR
4910 NEIGHBOR_STR
4911 NEIGHBOR_ADDR_STR2
4912 "Don't send open messages to this neighbor\n")
718e3744 4913{
d62a17ae 4914 int idx_peer = 2;
28c6e247 4915 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4916}
6b0655a2 4917
718e3744 4918/* neighbor shutdown. */
28c6e247
IR
4919DEFUN (neighbor_shutdown_msg,
4920 neighbor_shutdown_msg_cmd,
4921 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4922 NEIGHBOR_STR
4923 NEIGHBOR_ADDR_STR2
4924 "Administratively shut down this neighbor\n"
4925 "Add a shutdown message (RFC 8203)\n"
4926 "Shutdown message\n")
718e3744 4927{
d62a17ae 4928 int idx_peer = 1;
73d70fa6 4929
d62a17ae 4930 if (argc >= 5) {
28c6e247
IR
4931 struct peer *peer =
4932 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 4933 char *message;
73d70fa6 4934
28c6e247
IR
4935 if (!peer)
4936 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4937 message = argv_concat(argv, argc, 4);
28c6e247
IR
4938 peer_tx_shutdown_message_set(peer, message);
4939 XFREE(MTYPE_TMP, message);
d62a17ae 4940 }
73d70fa6 4941
28c6e247 4942 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4943}
4944
1d80f243 4945ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 4946 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4948 "Administratively shut down this neighbor\n")
73d70fa6 4949
28c6e247
IR
4950DEFUN (no_neighbor_shutdown_msg,
4951 no_neighbor_shutdown_msg_cmd,
4952 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4953 NO_STR
4954 NEIGHBOR_STR
4955 NEIGHBOR_ADDR_STR2
4956 "Administratively shut down this neighbor\n"
4957 "Remove a shutdown message (RFC 8203)\n"
4958 "Shutdown message\n")
718e3744 4959{
d62a17ae 4960 int idx_peer = 2;
73d70fa6 4961
28c6e247
IR
4962 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4963 PEER_FLAG_SHUTDOWN);
718e3744 4964}
6b0655a2 4965
1d80f243 4966ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 4967 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4969 "Administratively shut down this neighbor\n")
73d70fa6 4970
8336c896
DA
4971DEFUN(neighbor_shutdown_rtt,
4972 neighbor_shutdown_rtt_cmd,
4973 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4974 NEIGHBOR_STR
4975 NEIGHBOR_ADDR_STR2
4976 "Administratively shut down this neighbor\n"
4977 "Shutdown if round-trip-time is higher than expected\n"
4978 "Round-trip-time in milliseconds\n"
4979 "Specify the number of keepalives before shutdown\n"
4980 "The number of keepalives with higher RTT to shutdown\n")
4981{
4982 int idx_peer = 1;
4983 int idx_rtt = 4;
4984 int idx_count = 0;
4985 struct peer *peer;
4986
4987 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4988
4989 if (!peer)
4990 return CMD_WARNING_CONFIG_FAILED;
4991
4992 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4993
4994 if (argv_find(argv, argc, "count", &idx_count))
4995 peer->rtt_keepalive_conf =
4996 strtol(argv[idx_count + 1]->arg, NULL, 10);
4997
4998 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4999 PEER_FLAG_RTT_SHUTDOWN);
5000}
5001
5002DEFUN(no_neighbor_shutdown_rtt,
5003 no_neighbor_shutdown_rtt_cmd,
5004 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5005 NO_STR
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Administratively shut down this neighbor\n"
5009 "Shutdown if round-trip-time is higher than expected\n"
5010 "Round-trip-time in milliseconds\n"
5011 "Specify the number of keepalives before shutdown\n"
5012 "The number of keepalives with higher RTT to shutdown\n")
5013{
5014 int idx_peer = 2;
5015 struct peer *peer;
5016
5017 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5018
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 peer->rtt_expected = 0;
5023 peer->rtt_keepalive_conf = 1;
5024
5025 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5026 PEER_FLAG_RTT_SHUTDOWN);
5027}
5028
718e3744 5029/* neighbor capability dynamic. */
28c6e247
IR
5030DEFUN (neighbor_capability_dynamic,
5031 neighbor_capability_dynamic_cmd,
5032 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5033 NEIGHBOR_STR
5034 NEIGHBOR_ADDR_STR2
5035 "Advertise capability to the peer\n"
5036 "Advertise dynamic capability to this neighbor\n")
718e3744 5037{
d62a17ae 5038 int idx_peer = 1;
28c6e247
IR
5039 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5040 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5041}
5042
28c6e247
IR
5043DEFUN (no_neighbor_capability_dynamic,
5044 no_neighbor_capability_dynamic_cmd,
5045 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5046 NO_STR
5047 NEIGHBOR_STR
5048 NEIGHBOR_ADDR_STR2
5049 "Advertise capability to the peer\n"
5050 "Advertise dynamic capability to this neighbor\n")
718e3744 5051{
d62a17ae 5052 int idx_peer = 2;
28c6e247
IR
5053 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5054 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5055}
6b0655a2 5056
718e3744 5057/* neighbor dont-capability-negotiate */
5058DEFUN (neighbor_dont_capability_negotiate,
5059 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5060 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "Do not perform capability negotiation\n")
5064{
d62a17ae 5065 int idx_peer = 1;
5066 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5067 PEER_FLAG_DONT_CAPABILITY);
718e3744 5068}
5069
5070DEFUN (no_neighbor_dont_capability_negotiate,
5071 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Do not perform capability negotiation\n")
5077{
28c6e247
IR
5078 int idx_peer = 2;
5079 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5080 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5081}
5082
28c6e247
IR
5083/* neighbor capability extended next hop encoding */
5084DEFUN (neighbor_capability_enhe,
5085 neighbor_capability_enhe_cmd,
5086 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5087 NEIGHBOR_STR
5088 NEIGHBOR_ADDR_STR2
5089 "Advertise capability to the peer\n"
5090 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5091{
28c6e247
IR
5092 int idx_peer = 1;
5093 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5094 PEER_FLAG_CAPABILITY_ENHE);
5095}
f4b8ec07 5096
28c6e247
IR
5097DEFUN (no_neighbor_capability_enhe,
5098 no_neighbor_capability_enhe_cmd,
5099 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5100 NO_STR
5101 NEIGHBOR_STR
5102 NEIGHBOR_ADDR_STR2
5103 "Advertise capability to the peer\n"
5104 "Advertise extended next-hop capability to the peer\n")
5105{
5106 int idx_peer = 2;
5107 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5108 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5109}
5110
d62a17ae 5111static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5112 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5113 int set)
718e3744 5114{
d62a17ae 5115 int ret;
5116 struct peer *peer;
718e3744 5117
d62a17ae 5118 peer = peer_and_group_lookup_vty(vty, peer_str);
5119 if (!peer)
5120 return CMD_WARNING_CONFIG_FAILED;
718e3744 5121
d62a17ae 5122 if (set)
5123 ret = peer_af_flag_set(peer, afi, safi, flag);
5124 else
5125 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5126
d62a17ae 5127 return bgp_vty_return(vty, ret);
718e3744 5128}
5129
d62a17ae 5130static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5131 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5132{
d62a17ae 5133 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5134}
5135
d62a17ae 5136static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5137 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5138{
d62a17ae 5139 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5140}
6b0655a2 5141
718e3744 5142/* neighbor capability orf prefix-list. */
5143DEFUN (neighbor_capability_orf_prefix,
5144 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5145 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5146 NEIGHBOR_STR
5147 NEIGHBOR_ADDR_STR2
5148 "Advertise capability to the peer\n"
5149 "Advertise ORF capability to the peer\n"
5150 "Advertise prefixlist ORF capability to this neighbor\n"
5151 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5152 "Capability to RECEIVE the ORF from this neighbor\n"
5153 "Capability to SEND the ORF to this neighbor\n")
5154{
d62a17ae 5155 int idx_send_recv = 5;
db45f64d
DS
5156 char *peer_str = argv[1]->arg;
5157 struct peer *peer;
5158 afi_t afi = bgp_node_afi(vty);
5159 safi_t safi = bgp_node_safi(vty);
d62a17ae 5160
db45f64d
DS
5161 peer = peer_and_group_lookup_vty(vty, peer_str);
5162 if (!peer)
d62a17ae 5163 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5164
db45f64d
DS
5165 if (strmatch(argv[idx_send_recv]->text, "send"))
5166 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5167 PEER_FLAG_ORF_PREFIX_SM);
5168
5169 if (strmatch(argv[idx_send_recv]->text, "receive"))
5170 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5171 PEER_FLAG_ORF_PREFIX_RM);
5172
5173 if (strmatch(argv[idx_send_recv]->text, "both"))
5174 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5175 PEER_FLAG_ORF_PREFIX_SM)
5176 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5177 PEER_FLAG_ORF_PREFIX_RM);
5178
5179 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5180}
5181
5182ALIAS_HIDDEN(
5183 neighbor_capability_orf_prefix,
5184 neighbor_capability_orf_prefix_hidden_cmd,
5185 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5186 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5187 "Advertise capability to the peer\n"
5188 "Advertise ORF capability to the peer\n"
5189 "Advertise prefixlist ORF capability to this neighbor\n"
5190 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5191 "Capability to RECEIVE the ORF from this neighbor\n"
5192 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5193
718e3744 5194DEFUN (no_neighbor_capability_orf_prefix,
5195 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5196 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5197 NO_STR
5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Advertise capability to the peer\n"
5201 "Advertise ORF capability to the peer\n"
5202 "Advertise prefixlist ORF capability to this neighbor\n"
5203 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5204 "Capability to RECEIVE the ORF from this neighbor\n"
5205 "Capability to SEND the ORF to this neighbor\n")
5206{
d62a17ae 5207 int idx_send_recv = 6;
db45f64d
DS
5208 char *peer_str = argv[2]->arg;
5209 struct peer *peer;
5210 afi_t afi = bgp_node_afi(vty);
5211 safi_t safi = bgp_node_safi(vty);
d62a17ae 5212
db45f64d
DS
5213 peer = peer_and_group_lookup_vty(vty, peer_str);
5214 if (!peer)
d62a17ae 5215 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5216
db45f64d
DS
5217 if (strmatch(argv[idx_send_recv]->text, "send"))
5218 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5219 PEER_FLAG_ORF_PREFIX_SM);
5220
5221 if (strmatch(argv[idx_send_recv]->text, "receive"))
5222 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5223 PEER_FLAG_ORF_PREFIX_RM);
5224
5225 if (strmatch(argv[idx_send_recv]->text, "both"))
5226 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5227 PEER_FLAG_ORF_PREFIX_SM)
5228 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5229 PEER_FLAG_ORF_PREFIX_RM);
5230
5231 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5232}
5233
5234ALIAS_HIDDEN(
5235 no_neighbor_capability_orf_prefix,
5236 no_neighbor_capability_orf_prefix_hidden_cmd,
5237 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5238 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5239 "Advertise capability to the peer\n"
5240 "Advertise ORF capability to the peer\n"
5241 "Advertise prefixlist ORF capability to this neighbor\n"
5242 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5243 "Capability to RECEIVE the ORF from this neighbor\n"
5244 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5245
718e3744 5246/* neighbor next-hop-self. */
28c6e247
IR
5247DEFUN (neighbor_nexthop_self,
5248 neighbor_nexthop_self_cmd,
5249 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Disable the next hop calculation for this neighbor\n")
718e3744 5253{
d62a17ae 5254 int idx_peer = 1;
28c6e247
IR
5255 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5256 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5257}
9e7a53c1 5258
d62a17ae 5259ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5260 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5261 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5262 "Disable the next hop calculation for this neighbor\n")
596c17ba 5263
f4b8ec07 5264/* neighbor next-hop-self. */
28c6e247
IR
5265DEFUN (neighbor_nexthop_self_force,
5266 neighbor_nexthop_self_force_cmd,
5267 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR2
5270 "Disable the next hop calculation for this neighbor\n"
5271 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5272{
5273 int idx_peer = 1;
28c6e247
IR
5274 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5275 bgp_node_safi(vty),
5276 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5277}
5278
d62a17ae 5279ALIAS_HIDDEN(neighbor_nexthop_self_force,
5280 neighbor_nexthop_self_force_hidden_cmd,
5281 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5282 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5283 "Disable the next hop calculation for this neighbor\n"
5284 "Set the next hop to self for reflected routes\n")
596c17ba 5285
1bc4e531
DA
5286ALIAS_HIDDEN(neighbor_nexthop_self_force,
5287 neighbor_nexthop_self_all_hidden_cmd,
5288 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5289 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5290 "Disable the next hop calculation for this neighbor\n"
5291 "Set the next hop to self for reflected routes\n")
5292
28c6e247
IR
5293DEFUN (no_neighbor_nexthop_self,
5294 no_neighbor_nexthop_self_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Disable the next hop calculation for this neighbor\n")
718e3744 5300{
d62a17ae 5301 int idx_peer = 2;
28c6e247
IR
5302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5303 bgp_node_afi(vty), bgp_node_safi(vty),
5304 PEER_FLAG_NEXTHOP_SELF);
718e3744 5305}
6b0655a2 5306
d62a17ae 5307ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5310 "Disable the next hop calculation for this neighbor\n")
596c17ba 5311
28c6e247
IR
5312DEFUN (no_neighbor_nexthop_self_force,
5313 no_neighbor_nexthop_self_force_cmd,
5314 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5315 NO_STR
5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5318 "Disable the next hop calculation for this neighbor\n"
5319 "Set the next hop to self for reflected routes\n")
88b8ed8d 5320{
d62a17ae 5321 int idx_peer = 2;
28c6e247
IR
5322 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5323 bgp_node_afi(vty), bgp_node_safi(vty),
5324 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5325}
a538debe 5326
d62a17ae 5327ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5328 no_neighbor_nexthop_self_force_hidden_cmd,
5329 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5330 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5331 "Disable the next hop calculation for this neighbor\n"
5332 "Set the next hop to self for reflected routes\n")
596c17ba 5333
1bc4e531
DA
5334ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5335 no_neighbor_nexthop_self_all_hidden_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5337 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5338 "Disable the next hop calculation for this neighbor\n"
5339 "Set the next hop to self for reflected routes\n")
5340
c7122e14 5341/* neighbor as-override */
28c6e247
IR
5342DEFUN (neighbor_as_override,
5343 neighbor_as_override_cmd,
5344 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5345 NEIGHBOR_STR
5346 NEIGHBOR_ADDR_STR2
5347 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5348{
d62a17ae 5349 int idx_peer = 1;
28c6e247
IR
5350 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5351 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5352}
5353
d62a17ae 5354ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5355 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5357 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5358
28c6e247
IR
5359DEFUN (no_neighbor_as_override,
5360 no_neighbor_as_override_cmd,
5361 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5362 NO_STR
5363 NEIGHBOR_STR
5364 NEIGHBOR_ADDR_STR2
5365 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5366{
d62a17ae 5367 int idx_peer = 2;
28c6e247
IR
5368 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5369 bgp_node_afi(vty), bgp_node_safi(vty),
5370 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5371}
5372
d62a17ae 5373ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5374 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5375 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5376 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5377
718e3744 5378/* neighbor remove-private-AS. */
28c6e247
IR
5379DEFUN (neighbor_remove_private_as,
5380 neighbor_remove_private_as_cmd,
5381 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5382 NEIGHBOR_STR
5383 NEIGHBOR_ADDR_STR2
5384 "Remove private ASNs in outbound updates\n")
718e3744 5385{
d62a17ae 5386 int idx_peer = 1;
28c6e247
IR
5387 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5388 bgp_node_safi(vty),
5389 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5390}
5391
d62a17ae 5392ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5395 "Remove private ASNs in outbound updates\n")
596c17ba 5396
28c6e247
IR
5397DEFUN (neighbor_remove_private_as_all,
5398 neighbor_remove_private_as_all_cmd,
5399 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5400 NEIGHBOR_STR
5401 NEIGHBOR_ADDR_STR2
5402 "Remove private ASNs in outbound updates\n"
5403 "Apply to all AS numbers\n")
5000f21c 5404{
d62a17ae 5405 int idx_peer = 1;
28c6e247
IR
5406 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5407 bgp_node_safi(vty),
5408 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5409}
5410
d62a17ae 5411ALIAS_HIDDEN(neighbor_remove_private_as_all,
5412 neighbor_remove_private_as_all_hidden_cmd,
5413 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5415 "Remove private ASNs in outbound updates\n"
5416 "Apply to all AS numbers")
596c17ba 5417
28c6e247
IR
5418DEFUN (neighbor_remove_private_as_replace_as,
5419 neighbor_remove_private_as_replace_as_cmd,
5420 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5421 NEIGHBOR_STR
5422 NEIGHBOR_ADDR_STR2
5423 "Remove private ASNs in outbound updates\n"
5424 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5425{
d62a17ae 5426 int idx_peer = 1;
28c6e247
IR
5427 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5428 bgp_node_safi(vty),
5429 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5430}
5431
d62a17ae 5432ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5433 neighbor_remove_private_as_replace_as_hidden_cmd,
5434 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5435 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5436 "Remove private ASNs in outbound updates\n"
5437 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5438
28c6e247
IR
5439DEFUN (neighbor_remove_private_as_all_replace_as,
5440 neighbor_remove_private_as_all_replace_as_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Remove private ASNs in outbound updates\n"
5445 "Apply to all AS numbers\n"
5446 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5447{
d62a17ae 5448 int idx_peer = 1;
28c6e247
IR
5449 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5450 bgp_node_safi(vty),
5451 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5452}
5453
d62a17ae 5454ALIAS_HIDDEN(
5455 neighbor_remove_private_as_all_replace_as,
5456 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Remove private ASNs in outbound updates\n"
5460 "Apply to all AS numbers\n"
5461 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5462
28c6e247
IR
5463DEFUN (no_neighbor_remove_private_as,
5464 no_neighbor_remove_private_as_cmd,
5465 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5466 NO_STR
5467 NEIGHBOR_STR
5468 NEIGHBOR_ADDR_STR2
5469 "Remove private ASNs in outbound updates\n")
718e3744 5470{
d62a17ae 5471 int idx_peer = 2;
28c6e247
IR
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5475}
6b0655a2 5476
d62a17ae 5477ALIAS_HIDDEN(no_neighbor_remove_private_as,
5478 no_neighbor_remove_private_as_hidden_cmd,
5479 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5480 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5481 "Remove private ASNs in outbound updates\n")
596c17ba 5482
28c6e247
IR
5483DEFUN (no_neighbor_remove_private_as_all,
5484 no_neighbor_remove_private_as_all_cmd,
5485 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5486 NO_STR
5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Remove private ASNs in outbound updates\n"
5490 "Apply to all AS numbers\n")
88b8ed8d 5491{
d62a17ae 5492 int idx_peer = 2;
28c6e247
IR
5493 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5494 bgp_node_afi(vty), bgp_node_safi(vty),
5495 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5496}
5000f21c 5497
d62a17ae 5498ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5499 no_neighbor_remove_private_as_all_hidden_cmd,
5500 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Remove private ASNs in outbound updates\n"
5503 "Apply to all AS numbers\n")
596c17ba 5504
28c6e247
IR
5505DEFUN (no_neighbor_remove_private_as_replace_as,
5506 no_neighbor_remove_private_as_replace_as_cmd,
5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5508 NO_STR
5509 NEIGHBOR_STR
5510 NEIGHBOR_ADDR_STR2
5511 "Remove private ASNs in outbound updates\n"
5512 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5513{
d62a17ae 5514 int idx_peer = 2;
28c6e247
IR
5515 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5516 bgp_node_afi(vty), bgp_node_safi(vty),
5517 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5518}
5000f21c 5519
d62a17ae 5520ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5521 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5522 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5523 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5524 "Remove private ASNs in outbound updates\n"
5525 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5526
28c6e247
IR
5527DEFUN (no_neighbor_remove_private_as_all_replace_as,
5528 no_neighbor_remove_private_as_all_replace_as_cmd,
5529 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5530 NO_STR
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Remove private ASNs in outbound updates\n"
5534 "Apply to all AS numbers\n"
5535 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5536{
d62a17ae 5537 int idx_peer = 2;
28c6e247
IR
5538 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5539 bgp_node_afi(vty), bgp_node_safi(vty),
5540 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5541}
5000f21c 5542
d62a17ae 5543ALIAS_HIDDEN(
5544 no_neighbor_remove_private_as_all_replace_as,
5545 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5546 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5547 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5548 "Remove private ASNs in outbound updates\n"
5549 "Apply to all AS numbers\n"
5550 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5551
5000f21c 5552
718e3744 5553/* neighbor send-community. */
28c6e247
IR
5554DEFUN (neighbor_send_community,
5555 neighbor_send_community_cmd,
5556 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5557 NEIGHBOR_STR
5558 NEIGHBOR_ADDR_STR2
5559 "Send Community attribute to this neighbor\n")
718e3744 5560{
d62a17ae 5561 int idx_peer = 1;
27c05d4d 5562
f63d4054
IR
5563 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5564 bgp_node_safi(vty),
5565 PEER_FLAG_SEND_COMMUNITY);
718e3744 5566}
5567
d62a17ae 5568ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5569 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5570 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5571 "Send Community attribute to this neighbor\n")
596c17ba 5572
28c6e247
IR
5573DEFUN (no_neighbor_send_community,
5574 no_neighbor_send_community_cmd,
5575 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5576 NO_STR
5577 NEIGHBOR_STR
5578 NEIGHBOR_ADDR_STR2
5579 "Send Community attribute to this neighbor\n")
718e3744 5580{
d62a17ae 5581 int idx_peer = 2;
27c05d4d 5582
f63d4054
IR
5583 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5584 bgp_node_afi(vty), bgp_node_safi(vty),
5585 PEER_FLAG_SEND_COMMUNITY);
718e3744 5586}
6b0655a2 5587
d62a17ae 5588ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5589 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5590 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5591 "Send Community attribute to this neighbor\n")
596c17ba 5592
718e3744 5593/* neighbor send-community extended. */
28c6e247
IR
5594DEFUN (neighbor_send_community_type,
5595 neighbor_send_community_type_cmd,
5596 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5597 NEIGHBOR_STR
5598 NEIGHBOR_ADDR_STR2
5599 "Send Community attribute to this neighbor\n"
5600 "Send Standard and Extended Community attributes\n"
5601 "Send Standard, Large and Extended Community attributes\n"
5602 "Send Extended Community attributes\n"
5603 "Send Standard Community attributes\n"
5604 "Send Large Community attributes\n")
718e3744 5605{
27c05d4d 5606 const char *type = argv[argc - 1]->text;
db45f64d 5607 char *peer_str = argv[1]->arg;
28c6e247 5608 struct peer *peer;
db45f64d 5609 afi_t afi = bgp_node_afi(vty);
28c6e247 5610 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5611
28c6e247
IR
5612 peer = peer_and_group_lookup_vty(vty, peer_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5615
28c6e247
IR
5616 if (strmatch(type, "standard"))
5617 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5619
28c6e247
IR
5620 if (strmatch(type, "extended"))
5621 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5622 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5623
28c6e247
IR
5624 if (strmatch(type, "large"))
5625 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5626 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5627
28c6e247
IR
5628 if (strmatch(type, "both")) {
5629 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5630 PEER_FLAG_SEND_COMMUNITY)
5631 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5632 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5633 }
28c6e247
IR
5634 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5635 PEER_FLAG_SEND_COMMUNITY)
5636 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5637 PEER_FLAG_SEND_EXT_COMMUNITY)
5638 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5639 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5640}
5641
5642ALIAS_HIDDEN(
5643 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Send Community attribute to this neighbor\n"
5647 "Send Standard and Extended Community attributes\n"
5648 "Send Standard, Large and Extended Community attributes\n"
5649 "Send Extended Community attributes\n"
5650 "Send Standard Community attributes\n"
5651 "Send Large Community attributes\n")
596c17ba 5652
28c6e247
IR
5653DEFUN (no_neighbor_send_community_type,
5654 no_neighbor_send_community_type_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5656 NO_STR
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Send Community attribute to this neighbor\n"
5660 "Send Standard and Extended Community attributes\n"
5661 "Send Standard, Large and Extended Community attributes\n"
5662 "Send Extended Community attributes\n"
5663 "Send Standard Community attributes\n"
5664 "Send Large Community attributes\n")
718e3744 5665{
d62a17ae 5666 const char *type = argv[argc - 1]->text;
db45f64d 5667 char *peer_str = argv[2]->arg;
28c6e247 5668 struct peer *peer;
db45f64d
DS
5669 afi_t afi = bgp_node_afi(vty);
5670 safi_t safi = bgp_node_safi(vty);
5671
28c6e247
IR
5672 peer = peer_and_group_lookup_vty(vty, peer_str);
5673 if (!peer)
f4b8ec07
CS
5674 return CMD_WARNING_CONFIG_FAILED;
5675
28c6e247
IR
5676 if (strmatch(type, "standard"))
5677 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5678 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5679
28c6e247
IR
5680 if (strmatch(type, "extended"))
5681 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5682 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5683
28c6e247
IR
5684 if (strmatch(type, "large"))
5685 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5686 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5687
5688 if (strmatch(type, "both")) {
db45f64d 5689
28c6e247
IR
5690 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5691 PEER_FLAG_SEND_COMMUNITY)
5692 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5693 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5694 }
5695
28c6e247
IR
5696 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5697 PEER_FLAG_SEND_COMMUNITY)
5698 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5699 PEER_FLAG_SEND_EXT_COMMUNITY)
5700 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5701 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5702}
5703
5704ALIAS_HIDDEN(
5705 no_neighbor_send_community_type,
5706 no_neighbor_send_community_type_hidden_cmd,
5707 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5708 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5709 "Send Community attribute to this neighbor\n"
5710 "Send Standard and Extended Community attributes\n"
5711 "Send Standard, Large and Extended Community attributes\n"
5712 "Send Extended Community attributes\n"
5713 "Send Standard Community attributes\n"
5714 "Send Large Community attributes\n")
596c17ba 5715
718e3744 5716/* neighbor soft-reconfig. */
28c6e247
IR
5717DEFUN (neighbor_soft_reconfiguration,
5718 neighbor_soft_reconfiguration_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Per neighbor soft reconfiguration\n"
5723 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5724{
d62a17ae 5725 int idx_peer = 1;
28c6e247
IR
5726 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5727 bgp_node_safi(vty),
5728 PEER_FLAG_SOFT_RECONFIG);
718e3744 5729}
5730
d62a17ae 5731ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5732 neighbor_soft_reconfiguration_hidden_cmd,
5733 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5734 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5735 "Per neighbor soft reconfiguration\n"
5736 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5737
28c6e247
IR
5738DEFUN (no_neighbor_soft_reconfiguration,
5739 no_neighbor_soft_reconfiguration_cmd,
5740 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5741 NO_STR
5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Per neighbor soft reconfiguration\n"
5745 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5746{
d62a17ae 5747 int idx_peer = 2;
28c6e247
IR
5748 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5749 bgp_node_afi(vty), bgp_node_safi(vty),
5750 PEER_FLAG_SOFT_RECONFIG);
718e3744 5751}
6b0655a2 5752
d62a17ae 5753ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5754 no_neighbor_soft_reconfiguration_hidden_cmd,
5755 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5757 "Per neighbor soft reconfiguration\n"
5758 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5759
28c6e247
IR
5760DEFUN (neighbor_route_reflector_client,
5761 neighbor_route_reflector_client_cmd,
5762 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5763 NEIGHBOR_STR
5764 NEIGHBOR_ADDR_STR2
5765 "Configure a neighbor as Route Reflector client\n")
718e3744 5766{
d62a17ae 5767 int idx_peer = 1;
28c6e247 5768 struct peer *peer;
718e3744 5769
5770
28c6e247
IR
5771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5772 if (!peer)
d62a17ae 5773 return CMD_WARNING_CONFIG_FAILED;
718e3744 5774
28c6e247
IR
5775 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5776 bgp_node_safi(vty),
5777 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5778}
5779
d62a17ae 5780ALIAS_HIDDEN(neighbor_route_reflector_client,
5781 neighbor_route_reflector_client_hidden_cmd,
5782 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5783 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5784 "Configure a neighbor as Route Reflector client\n")
596c17ba 5785
28c6e247
IR
5786DEFUN (no_neighbor_route_reflector_client,
5787 no_neighbor_route_reflector_client_cmd,
5788 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5789 NO_STR
5790 NEIGHBOR_STR
5791 NEIGHBOR_ADDR_STR2
5792 "Configure a neighbor as Route Reflector client\n")
718e3744 5793{
d62a17ae 5794 int idx_peer = 2;
28c6e247
IR
5795 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5796 bgp_node_afi(vty), bgp_node_safi(vty),
5797 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5798}
6b0655a2 5799
d62a17ae 5800ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5801 no_neighbor_route_reflector_client_hidden_cmd,
5802 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5804 "Configure a neighbor as Route Reflector client\n")
596c17ba 5805
718e3744 5806/* neighbor route-server-client. */
28c6e247
IR
5807DEFUN (neighbor_route_server_client,
5808 neighbor_route_server_client_cmd,
5809 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5810 NEIGHBOR_STR
5811 NEIGHBOR_ADDR_STR2
5812 "Configure a neighbor as Route Server client\n")
718e3744 5813{
d62a17ae 5814 int idx_peer = 1;
28c6e247 5815 struct peer *peer;
f4b8ec07 5816
28c6e247
IR
5817 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5818 if (!peer)
d62a17ae 5819 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
5820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5821 bgp_node_safi(vty),
5822 PEER_FLAG_RSERVER_CLIENT);
718e3744 5823}
5824
d62a17ae 5825ALIAS_HIDDEN(neighbor_route_server_client,
5826 neighbor_route_server_client_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Configure a neighbor as Route Server client\n")
596c17ba 5830
28c6e247
IR
5831DEFUN (no_neighbor_route_server_client,
5832 no_neighbor_route_server_client_cmd,
5833 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5834 NO_STR
5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
5837 "Configure a neighbor as Route Server client\n")
fee0f4c6 5838{
d62a17ae 5839 int idx_peer = 2;
28c6e247
IR
5840 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5841 bgp_node_afi(vty), bgp_node_safi(vty),
5842 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5843}
6b0655a2 5844
d62a17ae 5845ALIAS_HIDDEN(no_neighbor_route_server_client,
5846 no_neighbor_route_server_client_hidden_cmd,
5847 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5849 "Configure a neighbor as Route Server client\n")
596c17ba 5850
fee0f4c6 5851DEFUN (neighbor_nexthop_local_unchanged,
5852 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5853 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5854 NEIGHBOR_STR
5855 NEIGHBOR_ADDR_STR2
5856 "Configure treatment of outgoing link-local nexthop attribute\n"
5857 "Leave link-local nexthop unchanged for this peer\n")
5858{
d62a17ae 5859 int idx_peer = 1;
5860 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5861 bgp_node_safi(vty),
5862 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5863}
6b0655a2 5864
fee0f4c6 5865DEFUN (no_neighbor_nexthop_local_unchanged,
5866 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5867 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5868 NO_STR
5869 NEIGHBOR_STR
5870 NEIGHBOR_ADDR_STR2
5871 "Configure treatment of outgoing link-local-nexthop attribute\n"
5872 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5873{
d62a17ae 5874 int idx_peer = 2;
5875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5876 bgp_node_afi(vty), bgp_node_safi(vty),
5877 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5878}
6b0655a2 5879
28c6e247
IR
5880DEFUN (neighbor_attr_unchanged,
5881 neighbor_attr_unchanged_cmd,
5882 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
5885 "BGP attribute is propagated unchanged to this neighbor\n"
5886 "As-path attribute\n"
5887 "Nexthop attribute\n"
5888 "Med attribute\n")
718e3744 5889{
d62a17ae 5890 int idx = 0;
8eeb0335 5891 char *peer_str = argv[1]->arg;
28c6e247 5892 struct peer *peer;
db45f64d
DS
5893 bool aspath = false;
5894 bool nexthop = false;
5895 bool med = false;
8eeb0335
DW
5896 afi_t afi = bgp_node_afi(vty);
5897 safi_t safi = bgp_node_safi(vty);
28c6e247 5898 int ret = 0;
f4b8ec07 5899
28c6e247
IR
5900 peer = peer_and_group_lookup_vty(vty, peer_str);
5901 if (!peer)
8eeb0335 5902 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5903
5904 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5905 aspath = true;
5906
d62a17ae 5907 idx = 0;
5908 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5909 nexthop = true;
5910
d62a17ae 5911 idx = 0;
5912 if (argv_find(argv, argc, "med", &idx))
db45f64d 5913 med = true;
d62a17ae 5914
8eeb0335 5915 /* no flags means all of them! */
db45f64d 5916 if (!aspath && !nexthop && !med) {
28c6e247
IR
5917 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5918 PEER_FLAG_AS_PATH_UNCHANGED);
5919 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5920 PEER_FLAG_NEXTHOP_UNCHANGED);
5921 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5922 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5923 } else {
28c6e247
IR
5924 if (!aspath) {
5925 if (peer_af_flag_check(peer, afi, safi,
5926 PEER_FLAG_AS_PATH_UNCHANGED)) {
5927 ret |= peer_af_flag_unset_vty(
5928 vty, peer_str, afi, safi,
5929 PEER_FLAG_AS_PATH_UNCHANGED);
5930 }
5931 } else
5932 ret |= peer_af_flag_set_vty(
5933 vty, peer_str, afi, safi,
5934 PEER_FLAG_AS_PATH_UNCHANGED);
5935
5936 if (!nexthop) {
5937 if (peer_af_flag_check(peer, afi, safi,
5938 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5939 ret |= peer_af_flag_unset_vty(
5940 vty, peer_str, afi, safi,
5941 PEER_FLAG_NEXTHOP_UNCHANGED);
5942 }
5943 } else
5944 ret |= peer_af_flag_set_vty(
5945 vty, peer_str, afi, safi,
5946 PEER_FLAG_NEXTHOP_UNCHANGED);
5947
5948 if (!med) {
5949 if (peer_af_flag_check(peer, afi, safi,
5950 PEER_FLAG_MED_UNCHANGED)) {
5951 ret |= peer_af_flag_unset_vty(
5952 vty, peer_str, afi, safi,
5953 PEER_FLAG_MED_UNCHANGED);
5954 }
5955 } else
5956 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5957 PEER_FLAG_MED_UNCHANGED);
d62a17ae 5958 }
5959
28c6e247 5960 return ret;
d62a17ae 5961}
5962
5963ALIAS_HIDDEN(
5964 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "BGP attribute is propagated unchanged to this neighbor\n"
5968 "As-path attribute\n"
5969 "Nexthop attribute\n"
5970 "Med attribute\n")
596c17ba 5971
28c6e247
IR
5972DEFUN (no_neighbor_attr_unchanged,
5973 no_neighbor_attr_unchanged_cmd,
5974 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5975 NO_STR
5976 NEIGHBOR_STR
5977 NEIGHBOR_ADDR_STR2
5978 "BGP attribute is propagated unchanged to this neighbor\n"
5979 "As-path attribute\n"
5980 "Nexthop attribute\n"
5981 "Med attribute\n")
718e3744 5982{
d62a17ae 5983 int idx = 0;
db45f64d 5984 char *peer_str = argv[2]->arg;
28c6e247 5985 struct peer *peer;
db45f64d
DS
5986 bool aspath = false;
5987 bool nexthop = false;
5988 bool med = false;
5989 afi_t afi = bgp_node_afi(vty);
5990 safi_t safi = bgp_node_safi(vty);
28c6e247 5991 int ret = 0;
f4b8ec07 5992
28c6e247
IR
5993 peer = peer_and_group_lookup_vty(vty, peer_str);
5994 if (!peer)
db45f64d 5995 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5996
5997 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5998 aspath = true;
5999
d62a17ae 6000 idx = 0;
6001 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6002 nexthop = true;
6003
d62a17ae 6004 idx = 0;
6005 if (argv_find(argv, argc, "med", &idx))
db45f64d 6006 med = true;
d62a17ae 6007
28c6e247
IR
6008 if (!aspath && !nexthop && !med) // no flags means all of them!
6009 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6010 PEER_FLAG_AS_PATH_UNCHANGED)
6011 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6012 PEER_FLAG_NEXTHOP_UNCHANGED)
6013 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6014 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6015
6016 if (aspath)
28c6e247
IR
6017 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6018 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6019
6020 if (nexthop)
28c6e247
IR
6021 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6022 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6023
db45f64d 6024 if (med)
28c6e247
IR
6025 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6026 PEER_FLAG_MED_UNCHANGED);
db45f64d 6027
28c6e247 6028 return ret;
d62a17ae 6029}
6030
6031ALIAS_HIDDEN(
6032 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6033 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6035 "BGP attribute is propagated unchanged to this neighbor\n"
6036 "As-path attribute\n"
6037 "Nexthop attribute\n"
6038 "Med attribute\n")
718e3744 6039
28c6e247
IR
6040/* EBGP multihop configuration. */
6041static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6042 const char *ttl_str)
718e3744 6043{
28c6e247
IR
6044 struct peer *peer;
6045 unsigned int ttl;
718e3744 6046
28c6e247
IR
6047 peer = peer_and_group_lookup_vty(vty, ip_str);
6048 if (!peer)
d62a17ae 6049 return CMD_WARNING_CONFIG_FAILED;
718e3744 6050
28c6e247
IR
6051 if (peer->conf_if)
6052 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6053
6054 if (!ttl_str)
6055 ttl = MAXTTL;
6056 else
6057 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6058
28c6e247 6059 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6060}
6061
28c6e247 6062static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6063{
28c6e247 6064 struct peer *peer;
718e3744 6065
28c6e247
IR
6066 peer = peer_and_group_lookup_vty(vty, ip_str);
6067 if (!peer)
d62a17ae 6068 return CMD_WARNING_CONFIG_FAILED;
718e3744 6069
28c6e247 6070 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6071}
6072
28c6e247
IR
6073/* neighbor ebgp-multihop. */
6074DEFUN (neighbor_ebgp_multihop,
6075 neighbor_ebgp_multihop_cmd,
6076 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6077 NEIGHBOR_STR
6078 NEIGHBOR_ADDR_STR2
6079 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6080{
28c6e247
IR
6081 int idx_peer = 1;
6082 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6083}
f4b8ec07 6084
28c6e247
IR
6085DEFUN (neighbor_ebgp_multihop_ttl,
6086 neighbor_ebgp_multihop_ttl_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6088 NEIGHBOR_STR
6089 NEIGHBOR_ADDR_STR2
6090 "Allow EBGP neighbors not on directly connected networks\n"
6091 "maximum hop count\n")
6092{
6093 int idx_peer = 1;
6094 int idx_number = 3;
6095 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6096 argv[idx_number]->arg);
6097}
f4b8ec07 6098
28c6e247
IR
6099DEFUN (no_neighbor_ebgp_multihop,
6100 no_neighbor_ebgp_multihop_cmd,
6101 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6102 NO_STR
6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
6105 "Allow EBGP neighbors not on directly connected networks\n"
6106 "maximum hop count\n")
6107{
6108 int idx_peer = 2;
6109 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6110}
6111
6b0655a2 6112
6ffd2079 6113/* disable-connected-check */
28c6e247
IR
6114DEFUN (neighbor_disable_connected_check,
6115 neighbor_disable_connected_check_cmd,
6116 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "one-hop away EBGP peer using loopback address\n"
6120 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6121{
d62a17ae 6122 int idx_peer = 1;
28c6e247
IR
6123 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6124 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6125}
6126
28c6e247
IR
6127DEFUN (no_neighbor_disable_connected_check,
6128 no_neighbor_disable_connected_check_cmd,
6129 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6130 NO_STR
6131 NEIGHBOR_STR
6132 NEIGHBOR_ADDR_STR2
6133 "one-hop away EBGP peer using loopback address\n"
6134 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6135{
d62a17ae 6136 int idx_peer = 2;
28c6e247
IR
6137 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6138 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6139}
6140
47cbc09b
PM
6141
6142/* enforce-first-as */
28c6e247
IR
6143DEFUN (neighbor_enforce_first_as,
6144 neighbor_enforce_first_as_cmd,
6145 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6146 NEIGHBOR_STR
6147 NEIGHBOR_ADDR_STR2
6148 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6149{
6150 int idx_peer = 1;
f4b8ec07 6151
28c6e247
IR
6152 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6153 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6154}
6155
28c6e247
IR
6156DEFUN (no_neighbor_enforce_first_as,
6157 no_neighbor_enforce_first_as_cmd,
6158 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6159 NO_STR
6160 NEIGHBOR_STR
6161 NEIGHBOR_ADDR_STR2
6162 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6163{
6164 int idx_peer = 2;
f4b8ec07 6165
28c6e247
IR
6166 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6167 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6168}
6169
6170
28c6e247
IR
6171DEFUN (neighbor_description,
6172 neighbor_description_cmd,
6173 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "Neighbor specific description\n"
6177 "Up to 80 characters describing this neighbor\n")
718e3744 6178{
d62a17ae 6179 int idx_peer = 1;
6180 int idx_line = 3;
28c6e247 6181 struct peer *peer;
d62a17ae 6182 char *str;
718e3744 6183
28c6e247
IR
6184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6185 if (!peer)
d62a17ae 6186 return CMD_WARNING_CONFIG_FAILED;
718e3744 6187
d62a17ae 6188 str = argv_concat(argv, argc, idx_line);
718e3744 6189
28c6e247 6190 peer_description_set(peer, str);
718e3744 6191
d62a17ae 6192 XFREE(MTYPE_TMP, str);
718e3744 6193
28c6e247 6194 return CMD_SUCCESS;
718e3744 6195}
6196
28c6e247
IR
6197DEFUN (no_neighbor_description,
6198 no_neighbor_description_cmd,
6199 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6200 NO_STR
6201 NEIGHBOR_STR
6202 NEIGHBOR_ADDR_STR2
6203 "Neighbor specific description\n")
718e3744 6204{
d62a17ae 6205 int idx_peer = 2;
28c6e247 6206 struct peer *peer;
f4b8ec07 6207
28c6e247
IR
6208 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6209 if (!peer)
d62a17ae 6210 return CMD_WARNING_CONFIG_FAILED;
718e3744 6211
28c6e247 6212 peer_description_unset(peer);
718e3744 6213
28c6e247 6214 return CMD_SUCCESS;
718e3744 6215}
6216
1d80f243 6217ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6218 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6219 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6220 "Neighbor specific description\n"
6221 "Up to 80 characters describing this neighbor\n")
6b0655a2 6222
28c6e247
IR
6223/* Neighbor update-source. */
6224static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6225 const char *source_str)
6226{
6227 struct peer *peer;
6228 struct prefix p;
6229 union sockunion su;
6230
6231 peer = peer_and_group_lookup_vty(vty, peer_str);
6232 if (!peer)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 if (peer->conf_if)
6236 return CMD_WARNING;
6237
6238 if (source_str) {
6239 if (str2sockunion(source_str, &su) == 0)
6240 peer_update_source_addr_set(peer, &su);
6241 else {
6242 if (str2prefix(source_str, &p)) {
6243 vty_out(vty,
6244 "%% Invalid update-source, remove prefix length \n");
6245 return CMD_WARNING_CONFIG_FAILED;
6246 } else
6247 peer_update_source_if_set(peer, source_str);
6248 }
6249 } else
6250 peer_update_source_unset(peer);
6251
6252 return CMD_SUCCESS;
6253}
6254
d62a17ae 6255#define BGP_UPDATE_SOURCE_HELP_STR \
6256 "IPv4 address\n" \
6257 "IPv6 address\n" \
6258 "Interface name (requires zebra to be running)\n"
369688c0 6259
28c6e247
IR
6260DEFUN (neighbor_update_source,
6261 neighbor_update_source_cmd,
6262 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6263 NEIGHBOR_STR
6264 NEIGHBOR_ADDR_STR2
6265 "Source of routing updates\n"
6266 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6267{
d62a17ae 6268 int idx_peer = 1;
6269 int idx_peer_2 = 3;
28c6e247 6270 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6271 argv[idx_peer_2]->arg);
718e3744 6272}
6273
28c6e247
IR
6274DEFUN (no_neighbor_update_source,
6275 no_neighbor_update_source_cmd,
6276 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6277 NO_STR
6278 NEIGHBOR_STR
6279 NEIGHBOR_ADDR_STR2
6280 "Source of routing updates\n"
6281 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6282{
d62a17ae 6283 int idx_peer = 2;
28c6e247 6284 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6285}
6b0655a2 6286
d62a17ae 6287static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6288 afi_t afi, safi_t safi,
6289 const char *rmap, int set)
718e3744 6290{
d62a17ae 6291 int ret;
6292 struct peer *peer;
80912664 6293 struct route_map *route_map = NULL;
718e3744 6294
d62a17ae 6295 peer = peer_and_group_lookup_vty(vty, peer_str);
6296 if (!peer)
6297 return CMD_WARNING_CONFIG_FAILED;
718e3744 6298
1de27621 6299 if (set) {
80912664
DS
6300 if (rmap)
6301 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6302 ret = peer_default_originate_set(peer, afi, safi,
6303 rmap, route_map);
6304 } else
d62a17ae 6305 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6306
d62a17ae 6307 return bgp_vty_return(vty, ret);
718e3744 6308}
6309
6310/* neighbor default-originate. */
6311DEFUN (neighbor_default_originate,
6312 neighbor_default_originate_cmd,
9ccf14f7 6313 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6314 NEIGHBOR_STR
6315 NEIGHBOR_ADDR_STR2
6316 "Originate default route to this neighbor\n")
6317{
d62a17ae 6318 int idx_peer = 1;
6319 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6320 bgp_node_afi(vty),
6321 bgp_node_safi(vty), NULL, 1);
718e3744 6322}
6323
d62a17ae 6324ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6325 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6327 "Originate default route to this neighbor\n")
596c17ba 6328
718e3744 6329DEFUN (neighbor_default_originate_rmap,
6330 neighbor_default_originate_rmap_cmd,
9ccf14f7 6331 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6332 NEIGHBOR_STR
6333 NEIGHBOR_ADDR_STR2
6334 "Originate default route to this neighbor\n"
6335 "Route-map to specify criteria to originate default\n"
6336 "route-map name\n")
6337{
d62a17ae 6338 int idx_peer = 1;
6339 int idx_word = 4;
6340 return peer_default_originate_set_vty(
6341 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6342 argv[idx_word]->arg, 1);
718e3744 6343}
6344
d62a17ae 6345ALIAS_HIDDEN(
6346 neighbor_default_originate_rmap,
6347 neighbor_default_originate_rmap_hidden_cmd,
6348 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6349 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6350 "Originate default route to this neighbor\n"
6351 "Route-map to specify criteria to originate default\n"
6352 "route-map name\n")
596c17ba 6353
718e3744 6354DEFUN (no_neighbor_default_originate,
6355 no_neighbor_default_originate_cmd,
a636c635 6356 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6357 NO_STR
6358 NEIGHBOR_STR
6359 NEIGHBOR_ADDR_STR2
a636c635
DW
6360 "Originate default route to this neighbor\n"
6361 "Route-map to specify criteria to originate default\n"
6362 "route-map name\n")
718e3744 6363{
d62a17ae 6364 int idx_peer = 2;
6365 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6366 bgp_node_afi(vty),
6367 bgp_node_safi(vty), NULL, 0);
718e3744 6368}
6369
d62a17ae 6370ALIAS_HIDDEN(
6371 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6372 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6373 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6374 "Originate default route to this neighbor\n"
6375 "Route-map to specify criteria to originate default\n"
6376 "route-map name\n")
596c17ba 6377
6b0655a2 6378
28c6e247
IR
6379/* Set neighbor's BGP port. */
6380static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6381 const char *port_str)
718e3744 6382{
28c6e247
IR
6383 struct peer *peer;
6384 uint16_t port;
6385 struct servent *sp;
6386
6387 peer = peer_lookup_vty(vty, ip_str);
6388 if (!peer)
6389 return CMD_WARNING_CONFIG_FAILED;
6390
6391 if (!port_str) {
6392 sp = getservbyname("bgp", "tcp");
6393 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6394 } else {
6395 port = strtoul(port_str, NULL, 10);
6396 }
718e3744 6397
28c6e247 6398 peer_port_set(peer, port);
718e3744 6399
28c6e247
IR
6400 return CMD_SUCCESS;
6401}
f4b8ec07 6402
28c6e247
IR
6403/* Set specified peer's BGP port. */
6404DEFUN (neighbor_port,
6405 neighbor_port_cmd,
6406 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6407 NEIGHBOR_STR
6408 NEIGHBOR_ADDR_STR
6409 "Neighbor's BGP port\n"
6410 "TCP port number\n")
6411{
6412 int idx_ip = 1;
6413 int idx_number = 3;
6414 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6415 argv[idx_number]->arg);
f4b8ec07 6416}
6b0655a2 6417
28c6e247
IR
6418DEFUN (no_neighbor_port,
6419 no_neighbor_port_cmd,
6420 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR
6424 "Neighbor's BGP port\n"
6425 "TCP port number\n")
718e3744 6426{
f4b8ec07 6427 int idx_ip = 2;
28c6e247
IR
6428 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6429}
6430
6431
6432/* neighbor weight. */
6433static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6434 safi_t safi, const char *weight_str)
6435{
6436 int ret;
6437 struct peer *peer;
6438 unsigned long weight;
718e3744 6439
28c6e247
IR
6440 peer = peer_and_group_lookup_vty(vty, ip_str);
6441 if (!peer)
6442 return CMD_WARNING_CONFIG_FAILED;
718e3744 6443
28c6e247 6444 weight = strtoul(weight_str, NULL, 10);
718e3744 6445
28c6e247
IR
6446 ret = peer_weight_set(peer, afi, safi, weight);
6447 return bgp_vty_return(vty, ret);
718e3744 6448}
6449
28c6e247
IR
6450static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6451 safi_t safi)
718e3744 6452{
28c6e247
IR
6453 int ret;
6454 struct peer *peer;
f4b8ec07 6455
28c6e247
IR
6456 peer = peer_and_group_lookup_vty(vty, ip_str);
6457 if (!peer)
d62a17ae 6458 return CMD_WARNING_CONFIG_FAILED;
718e3744 6459
28c6e247
IR
6460 ret = peer_weight_unset(peer, afi, safi);
6461 return bgp_vty_return(vty, ret);
6462}
f4b8ec07 6463
28c6e247
IR
6464DEFUN (neighbor_weight,
6465 neighbor_weight_cmd,
6466 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6467 NEIGHBOR_STR
6468 NEIGHBOR_ADDR_STR2
6469 "Set default weight for routes from this neighbor\n"
6470 "default weight\n")
6471{
6472 int idx_peer = 1;
6473 int idx_number = 3;
6474 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6475 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6476}
6477
d62a17ae 6478ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6479 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6480 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6481 "Set default weight for routes from this neighbor\n"
6482 "default weight\n")
596c17ba 6483
28c6e247
IR
6484DEFUN (no_neighbor_weight,
6485 no_neighbor_weight_cmd,
6486 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6487 NO_STR
6488 NEIGHBOR_STR
6489 NEIGHBOR_ADDR_STR2
6490 "Set default weight for routes from this neighbor\n"
6491 "default weight\n")
718e3744 6492{
d62a17ae 6493 int idx_peer = 2;
28c6e247
IR
6494 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6495 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6496}
6497
d62a17ae 6498ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6499 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6500 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6501 "Set default weight for routes from this neighbor\n"
6502 "default weight\n")
596c17ba 6503
6b0655a2 6504
718e3744 6505/* Override capability negotiation. */
c36bc05f
IR
6506DEFUN (neighbor_override_capability,
6507 neighbor_override_capability_cmd,
6508 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6509 NEIGHBOR_STR
6510 NEIGHBOR_ADDR_STR2
6511 "Override capability negotiation result\n")
718e3744 6512{
d62a17ae 6513 int idx_peer = 1;
c36bc05f
IR
6514 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6515 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6516}
6517
c36bc05f
IR
6518DEFUN (no_neighbor_override_capability,
6519 no_neighbor_override_capability_cmd,
6520 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6521 NO_STR
6522 NEIGHBOR_STR
6523 NEIGHBOR_ADDR_STR2
6524 "Override capability negotiation result\n")
718e3744 6525{
d62a17ae 6526 int idx_peer = 2;
c36bc05f
IR
6527 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6528 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6529}
6b0655a2 6530
c36bc05f
IR
6531DEFUN (neighbor_strict_capability,
6532 neighbor_strict_capability_cmd,
6533 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6534 NEIGHBOR_STR
6535 NEIGHBOR_ADDR_STR2
6536 "Strict capability negotiation match\n")
718e3744 6537{
9fb964de
PM
6538 int idx_peer = 1;
6539
c36bc05f
IR
6540 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6541 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6542}
6543
c36bc05f
IR
6544DEFUN (no_neighbor_strict_capability,
6545 no_neighbor_strict_capability_cmd,
6546 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6547 NO_STR
6548 NEIGHBOR_STR
6549 NEIGHBOR_ADDR_STR2
6550 "Strict capability negotiation match\n")
718e3744 6551{
9fb964de 6552 int idx_peer = 2;
8611c7f3 6553
c36bc05f
IR
6554 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6555 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6556}
6b0655a2 6557
28c6e247
IR
6558static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6559 const char *keep_str, const char *hold_str)
718e3744 6560{
28c6e247
IR
6561 int ret;
6562 struct peer *peer;
6563 uint32_t keepalive;
6564 uint32_t holdtime;
718e3744 6565
28c6e247
IR
6566 peer = peer_and_group_lookup_vty(vty, ip_str);
6567 if (!peer)
d62a17ae 6568 return CMD_WARNING_CONFIG_FAILED;
718e3744 6569
28c6e247
IR
6570 keepalive = strtoul(keep_str, NULL, 10);
6571 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6572
28c6e247 6573 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6574
28c6e247 6575 return bgp_vty_return(vty, ret);
718e3744 6576}
6b0655a2 6577
28c6e247 6578static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6579{
28c6e247
IR
6580 int ret;
6581 struct peer *peer;
718e3744 6582
28c6e247
IR
6583 peer = peer_and_group_lookup_vty(vty, ip_str);
6584 if (!peer)
d62a17ae 6585 return CMD_WARNING_CONFIG_FAILED;
718e3744 6586
28c6e247 6587 ret = peer_timers_unset(peer);
718e3744 6588
28c6e247 6589 return bgp_vty_return(vty, ret);
718e3744 6590}
6b0655a2 6591
28c6e247
IR
6592DEFUN (neighbor_timers,
6593 neighbor_timers_cmd,
6594 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6595 NEIGHBOR_STR
6596 NEIGHBOR_ADDR_STR2
6597 "BGP per neighbor timers\n"
6598 "Keepalive interval\n"
6599 "Holdtime\n")
718e3744 6600{
f4b8ec07 6601 int idx_peer = 1;
28c6e247
IR
6602 int idx_number = 3;
6603 int idx_number_2 = 4;
6604 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6605 argv[idx_number]->arg,
6606 argv[idx_number_2]->arg);
6607}
6608
6609DEFUN (no_neighbor_timers,
6610 no_neighbor_timers_cmd,
6611 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6612 NO_STR
6613 NEIGHBOR_STR
6614 NEIGHBOR_ADDR_STR2
6615 "BGP per neighbor timers\n"
6616 "Keepalive interval\n"
6617 "Holdtime\n")
6618{
6619 int idx_peer = 2;
6620 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6621}
6622
6623
6624static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6625 const char *time_str)
6626{
6627 int ret;
6628 struct peer *peer;
6629 uint32_t connect;
718e3744 6630
28c6e247
IR
6631 peer = peer_and_group_lookup_vty(vty, ip_str);
6632 if (!peer)
d62a17ae 6633 return CMD_WARNING_CONFIG_FAILED;
718e3744 6634
28c6e247
IR
6635 connect = strtoul(time_str, NULL, 10);
6636
6637 ret = peer_timers_connect_set(peer, connect);
718e3744 6638
28c6e247 6639 return bgp_vty_return(vty, ret);
718e3744 6640}
6641
28c6e247 6642static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6643{
28c6e247
IR
6644 int ret;
6645 struct peer *peer;
718e3744 6646
28c6e247
IR
6647 peer = peer_and_group_lookup_vty(vty, ip_str);
6648 if (!peer)
d62a17ae 6649 return CMD_WARNING_CONFIG_FAILED;
718e3744 6650
28c6e247
IR
6651 ret = peer_timers_connect_unset(peer);
6652
6653 return bgp_vty_return(vty, ret);
6654}
6655
6656DEFUN (neighbor_timers_connect,
6657 neighbor_timers_connect_cmd,
6658 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6659 NEIGHBOR_STR
6660 NEIGHBOR_ADDR_STR2
6661 "BGP per neighbor timers\n"
6662 "BGP connect timer\n"
6663 "Connect timer\n")
6664{
6665 int idx_peer = 1;
6666 int idx_number = 4;
6667 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6668 argv[idx_number]->arg);
6669}
718e3744 6670
28c6e247
IR
6671DEFUN (no_neighbor_timers_connect,
6672 no_neighbor_timers_connect_cmd,
6673 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6674 NO_STR
6675 NEIGHBOR_STR
6676 NEIGHBOR_ADDR_STR2
6677 "BGP per neighbor timers\n"
6678 "BGP connect timer\n"
6679 "Connect timer\n")
6680{
6681 int idx_peer = 2;
6682 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6683}
6684
d43114f3
DS
6685DEFPY (neighbor_timers_delayopen,
6686 neighbor_timers_delayopen_cmd,
6687 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6688 NEIGHBOR_STR
6689 NEIGHBOR_ADDR_STR2
6690 "BGP per neighbor timers\n"
6691 "RFC 4271 DelayOpenTimer\n"
6692 "DelayOpenTime timer interval\n")
6693{
6694 struct peer *peer;
6695
6696 peer = peer_and_group_lookup_vty(vty, neighbor);
6697 if (!peer)
6698 return CMD_WARNING_CONFIG_FAILED;
6699
6700 if (!interval) {
6701 if (peer_timers_delayopen_unset(peer))
6702 return CMD_WARNING_CONFIG_FAILED;
6703 } else {
6704 if (peer_timers_delayopen_set(peer, interval))
6705 return CMD_WARNING_CONFIG_FAILED;
6706 }
6707
6708 return CMD_SUCCESS;
6709}
6710
6711DEFPY (no_neighbor_timers_delayopen,
6712 no_neighbor_timers_delayopen_cmd,
6713 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
6714 NO_STR
6715 NEIGHBOR_STR
6716 NEIGHBOR_ADDR_STR2
6717 "BGP per neighbor timers\n"
6718 "RFC 4271 DelayOpenTimer\n"
6719 "DelayOpenTime timer interval\n")
6720{
6721 struct peer *peer;
6722
6723 peer = peer_and_group_lookup_vty(vty, neighbor);
6724 if (!peer)
6725 return CMD_WARNING_CONFIG_FAILED;
6726
6727 if (peer_timers_delayopen_unset(peer))
6728 return CMD_WARNING_CONFIG_FAILED;
6729
6730 return CMD_SUCCESS;
6731}
6732
28c6e247
IR
6733static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6734 const char *time_str, int set)
718e3744 6735{
28c6e247
IR
6736 int ret;
6737 struct peer *peer;
6738 uint32_t routeadv = 0;
718e3744 6739
28c6e247
IR
6740 peer = peer_and_group_lookup_vty(vty, ip_str);
6741 if (!peer)
d62a17ae 6742 return CMD_WARNING_CONFIG_FAILED;
718e3744 6743
28c6e247
IR
6744 if (time_str)
6745 routeadv = strtoul(time_str, NULL, 10);
6746
6747 if (set)
6748 ret = peer_advertise_interval_set(peer, routeadv);
6749 else
6750 ret = peer_advertise_interval_unset(peer);
718e3744 6751
28c6e247 6752 return bgp_vty_return(vty, ret);
718e3744 6753}
6754
28c6e247
IR
6755DEFUN (neighbor_advertise_interval,
6756 neighbor_advertise_interval_cmd,
6757 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
6758 NEIGHBOR_STR
6759 NEIGHBOR_ADDR_STR2
6760 "Minimum interval between sending BGP routing updates\n"
6761 "time in seconds\n")
718e3744 6762{
28c6e247
IR
6763 int idx_peer = 1;
6764 int idx_number = 3;
6765 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6766 argv[idx_number]->arg, 1);
6767}
f4b8ec07 6768
28c6e247
IR
6769DEFUN (no_neighbor_advertise_interval,
6770 no_neighbor_advertise_interval_cmd,
6771 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
6772 NO_STR
6773 NEIGHBOR_STR
6774 NEIGHBOR_ADDR_STR2
6775 "Minimum interval between sending BGP routing updates\n"
6776 "time in seconds\n")
6777{
6778 int idx_peer = 2;
6779 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6780}
6781
6b0655a2 6782
518f0eb1
DS
6783/* Time to wait before processing route-map updates */
6784DEFUN (bgp_set_route_map_delay_timer,
6785 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6786 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6787 SET_STR
6788 "BGP route-map delay timer\n"
6789 "Time in secs to wait before processing route-map changes\n"
f414725f 6790 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6791{
d62a17ae 6792 int idx_number = 3;
d7c0a89a 6793 uint32_t rmap_delay_timer;
d62a17ae 6794
6795 if (argv[idx_number]->arg) {
6796 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6797 bm->rmap_update_timer = rmap_delay_timer;
6798
6799 /* if the dynamic update handling is being disabled, and a timer
6800 * is
6801 * running, stop the timer and act as if the timer has already
6802 * fired.
6803 */
6804 if (!rmap_delay_timer && bm->t_rmap_update) {
6805 BGP_TIMER_OFF(bm->t_rmap_update);
6806 thread_execute(bm->master, bgp_route_map_update_timer,
6807 NULL, 0);
6808 }
6809 return CMD_SUCCESS;
6810 } else {
6811 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6812 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6813 }
518f0eb1
DS
6814}
6815
6816DEFUN (no_bgp_set_route_map_delay_timer,
6817 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6818 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6819 NO_STR
3a2d747c 6820 BGP_STR
518f0eb1 6821 "Default BGP route-map delay timer\n"
8334fd5a
DW
6822 "Reset to default time to wait for processing route-map changes\n"
6823 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6824{
518f0eb1 6825
d62a17ae 6826 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6827
d62a17ae 6828 return CMD_SUCCESS;
518f0eb1
DS
6829}
6830
28c6e247
IR
6831/* neighbor interface */
6832static int peer_interface_vty(struct vty *vty, const char *ip_str,
6833 const char *str)
718e3744 6834{
28c6e247 6835 struct peer *peer;
718e3744 6836
28c6e247
IR
6837 peer = peer_lookup_vty(vty, ip_str);
6838 if (!peer || peer->conf_if) {
6839 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6840 return CMD_WARNING_CONFIG_FAILED;
6841 }
718e3744 6842
28c6e247
IR
6843 if (str)
6844 peer_interface_set(peer, str);
6845 else
6846 peer_interface_unset(peer);
718e3744 6847
28c6e247 6848 return CMD_SUCCESS;
718e3744 6849}
6850
28c6e247
IR
6851DEFUN (neighbor_interface,
6852 neighbor_interface_cmd,
6853 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
6854 NEIGHBOR_STR
6855 NEIGHBOR_ADDR_STR
6856 "Interface\n"
6857 "Interface name\n")
718e3744 6858{
28c6e247
IR
6859 int idx_ip = 1;
6860 int idx_word = 3;
6861 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
6862}
f4b8ec07 6863
28c6e247
IR
6864DEFUN (no_neighbor_interface,
6865 no_neighbor_interface_cmd,
6866 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
6867 NO_STR
6868 NEIGHBOR_STR
6869 NEIGHBOR_ADDR_STR2
6870 "Interface\n"
6871 "Interface name\n")
6872{
6873 int idx_peer = 2;
6874 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6875}
6b0655a2 6876
718e3744 6877DEFUN (neighbor_distribute_list,
6878 neighbor_distribute_list_cmd,
9ccf14f7 6879 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6880 NEIGHBOR_STR
6881 NEIGHBOR_ADDR_STR2
6882 "Filter updates to/from this neighbor\n"
6883 "IP access-list number\n"
6884 "IP access-list number (expanded range)\n"
6885 "IP Access-list name\n"
6886 "Filter incoming updates\n"
6887 "Filter outgoing updates\n")
6888{
d62a17ae 6889 int idx_peer = 1;
6890 int idx_acl = 3;
6891 int direct, ret;
6892 struct peer *peer;
a8206004 6893
d62a17ae 6894 const char *pstr = argv[idx_peer]->arg;
6895 const char *acl = argv[idx_acl]->arg;
6896 const char *inout = argv[argc - 1]->text;
a8206004 6897
d62a17ae 6898 peer = peer_and_group_lookup_vty(vty, pstr);
6899 if (!peer)
6900 return CMD_WARNING_CONFIG_FAILED;
a8206004 6901
d62a17ae 6902 /* Check filter direction. */
6903 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6904 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6905 direct, acl);
a8206004 6906
d62a17ae 6907 return bgp_vty_return(vty, ret);
718e3744 6908}
6909
d62a17ae 6910ALIAS_HIDDEN(
6911 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6912 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6913 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6914 "Filter updates to/from this neighbor\n"
6915 "IP access-list number\n"
6916 "IP access-list number (expanded range)\n"
6917 "IP Access-list name\n"
6918 "Filter incoming updates\n"
6919 "Filter outgoing updates\n")
596c17ba 6920
718e3744 6921DEFUN (no_neighbor_distribute_list,
6922 no_neighbor_distribute_list_cmd,
9ccf14f7 6923 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6924 NO_STR
6925 NEIGHBOR_STR
6926 NEIGHBOR_ADDR_STR2
6927 "Filter updates to/from this neighbor\n"
6928 "IP access-list number\n"
6929 "IP access-list number (expanded range)\n"
6930 "IP Access-list name\n"
6931 "Filter incoming updates\n"
6932 "Filter outgoing updates\n")
6933{
d62a17ae 6934 int idx_peer = 2;
6935 int direct, ret;
6936 struct peer *peer;
a8206004 6937
d62a17ae 6938 const char *pstr = argv[idx_peer]->arg;
6939 const char *inout = argv[argc - 1]->text;
a8206004 6940
d62a17ae 6941 peer = peer_and_group_lookup_vty(vty, pstr);
6942 if (!peer)
6943 return CMD_WARNING_CONFIG_FAILED;
a8206004 6944
d62a17ae 6945 /* Check filter direction. */
6946 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6947 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6948 direct);
a8206004 6949
d62a17ae 6950 return bgp_vty_return(vty, ret);
718e3744 6951}
6b0655a2 6952
d62a17ae 6953ALIAS_HIDDEN(
6954 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6955 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6957 "Filter updates to/from this neighbor\n"
6958 "IP access-list number\n"
6959 "IP access-list number (expanded range)\n"
6960 "IP Access-list name\n"
6961 "Filter incoming updates\n"
6962 "Filter outgoing updates\n")
596c17ba 6963
718e3744 6964/* Set prefix list to the peer. */
642ef664
IR
6965static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6966 afi_t afi, safi_t safi,
6967 const char *name_str,
6968 const char *direct_str)
718e3744 6969{
642ef664
IR
6970 int ret;
6971 int direct = FILTER_IN;
6972 struct peer *peer;
718e3744 6973
642ef664
IR
6974 peer = peer_and_group_lookup_vty(vty, ip_str);
6975 if (!peer)
d62a17ae 6976 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6977
642ef664
IR
6978 /* Check filter direction. */
6979 if (strncmp(direct_str, "i", 1) == 0)
6980 direct = FILTER_IN;
6981 else if (strncmp(direct_str, "o", 1) == 0)
6982 direct = FILTER_OUT;
718e3744 6983
642ef664 6984 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6985
642ef664
IR
6986 return bgp_vty_return(vty, ret);
6987}
6988
6989static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6990 afi_t afi, safi_t safi,
6991 const char *direct_str)
6992{
6993 int ret;
6994 struct peer *peer;
6995 int direct = FILTER_IN;
6996
6997 peer = peer_and_group_lookup_vty(vty, ip_str);
6998 if (!peer)
6999 return CMD_WARNING_CONFIG_FAILED;
7000
7001 /* Check filter direction. */
7002 if (strncmp(direct_str, "i", 1) == 0)
7003 direct = FILTER_IN;
7004 else if (strncmp(direct_str, "o", 1) == 0)
7005 direct = FILTER_OUT;
7006
7007 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7008
7009 return bgp_vty_return(vty, ret);
7010}
7011
7012DEFUN (neighbor_prefix_list,
7013 neighbor_prefix_list_cmd,
7014 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7015 NEIGHBOR_STR
7016 NEIGHBOR_ADDR_STR2
7017 "Filter updates to/from this neighbor\n"
7018 "Name of a prefix list\n"
7019 "Filter incoming updates\n"
7020 "Filter outgoing updates\n")
7021{
7022 int idx_peer = 1;
7023 int idx_word = 3;
7024 int idx_in_out = 4;
7025 return peer_prefix_list_set_vty(
7026 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7027 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7028}
7029
d62a17ae 7030ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7031 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7032 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7033 "Filter updates to/from this neighbor\n"
7034 "Name of a prefix list\n"
7035 "Filter incoming updates\n"
7036 "Filter outgoing updates\n")
596c17ba 7037
642ef664
IR
7038DEFUN (no_neighbor_prefix_list,
7039 no_neighbor_prefix_list_cmd,
7040 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7041 NO_STR
7042 NEIGHBOR_STR
7043 NEIGHBOR_ADDR_STR2
7044 "Filter updates to/from this neighbor\n"
7045 "Name of a prefix list\n"
7046 "Filter incoming updates\n"
7047 "Filter outgoing updates\n")
7048{
7049 int idx_peer = 2;
7050 int idx_in_out = 5;
7051 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7052 bgp_node_afi(vty), bgp_node_safi(vty),
7053 argv[idx_in_out]->arg);
7054}
7055
7056ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7057 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7059 "Filter updates to/from this neighbor\n"
7060 "Name of a prefix list\n"
7061 "Filter incoming updates\n"
7062 "Filter outgoing updates\n")
7063
d62a17ae 7064static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7065 safi_t safi, const char *name_str,
7066 const char *direct_str)
718e3744 7067{
d62a17ae 7068 int ret;
7069 struct peer *peer;
7070 int direct = FILTER_IN;
718e3744 7071
d62a17ae 7072 peer = peer_and_group_lookup_vty(vty, ip_str);
7073 if (!peer)
7074 return CMD_WARNING_CONFIG_FAILED;
718e3744 7075
d62a17ae 7076 /* Check filter direction. */
7077 if (strncmp(direct_str, "i", 1) == 0)
7078 direct = FILTER_IN;
7079 else if (strncmp(direct_str, "o", 1) == 0)
7080 direct = FILTER_OUT;
718e3744 7081
d62a17ae 7082 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7083
d62a17ae 7084 return bgp_vty_return(vty, ret);
718e3744 7085}
7086
d62a17ae 7087static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7088 safi_t safi, const char *direct_str)
718e3744 7089{
d62a17ae 7090 int ret;
7091 struct peer *peer;
7092 int direct = FILTER_IN;
718e3744 7093
d62a17ae 7094 peer = peer_and_group_lookup_vty(vty, ip_str);
7095 if (!peer)
7096 return CMD_WARNING_CONFIG_FAILED;
718e3744 7097
d62a17ae 7098 /* Check filter direction. */
7099 if (strncmp(direct_str, "i", 1) == 0)
7100 direct = FILTER_IN;
7101 else if (strncmp(direct_str, "o", 1) == 0)
7102 direct = FILTER_OUT;
718e3744 7103
d62a17ae 7104 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7105
d62a17ae 7106 return bgp_vty_return(vty, ret);
718e3744 7107}
7108
7109DEFUN (neighbor_filter_list,
7110 neighbor_filter_list_cmd,
9ccf14f7 7111 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7112 NEIGHBOR_STR
7113 NEIGHBOR_ADDR_STR2
7114 "Establish BGP filters\n"
7115 "AS path access-list name\n"
7116 "Filter incoming routes\n"
7117 "Filter outgoing routes\n")
7118{
d62a17ae 7119 int idx_peer = 1;
7120 int idx_word = 3;
7121 int idx_in_out = 4;
7122 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7123 bgp_node_safi(vty), argv[idx_word]->arg,
7124 argv[idx_in_out]->arg);
718e3744 7125}
7126
d62a17ae 7127ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7128 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7129 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7130 "Establish BGP filters\n"
7131 "AS path access-list name\n"
7132 "Filter incoming routes\n"
7133 "Filter outgoing routes\n")
596c17ba 7134
718e3744 7135DEFUN (no_neighbor_filter_list,
7136 no_neighbor_filter_list_cmd,
9ccf14f7 7137 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7138 NO_STR
7139 NEIGHBOR_STR
7140 NEIGHBOR_ADDR_STR2
7141 "Establish BGP filters\n"
7142 "AS path access-list name\n"
7143 "Filter incoming routes\n"
7144 "Filter outgoing routes\n")
7145{
d62a17ae 7146 int idx_peer = 2;
7147 int idx_in_out = 5;
7148 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7149 bgp_node_afi(vty), bgp_node_safi(vty),
7150 argv[idx_in_out]->arg);
718e3744 7151}
6b0655a2 7152
d62a17ae 7153ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7154 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7156 "Establish BGP filters\n"
7157 "AS path access-list name\n"
7158 "Filter incoming routes\n"
7159 "Filter outgoing routes\n")
596c17ba 7160
7f7940e6
MK
7161/* Set advertise-map to the peer. */
7162static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7163 afi_t afi, safi_t safi,
cf2ad4d8
MK
7164 const char *advertise_str,
7165 const char *condition_str, bool condition,
7166 bool set)
7f7940e6
MK
7167{
7168 int ret = CMD_WARNING_CONFIG_FAILED;
7169 struct peer *peer;
7170 struct route_map *advertise_map;
7171 struct route_map *condition_map;
7172
7173 peer = peer_and_group_lookup_vty(vty, ip_str);
7174 if (!peer)
7175 return ret;
7176
7177 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7178 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7179
cf2ad4d8
MK
7180 if (set)
7181 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7182 advertise_map, condition_str,
7183 condition_map, condition);
7184 else
7185 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7186 advertise_map, condition_str,
7187 condition_map, condition);
7f7940e6
MK
7188
7189 return bgp_vty_return(vty, ret);
7190}
7191
389e4f92
QY
7192DEFPY (bgp_condadv_period,
7193 bgp_condadv_period_cmd,
7194 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7195 NO_STR
7196 BGP_STR
7197 "Conditional advertisement settings\n"
7198 "Set period to rescan BGP table to check if condition is met\n"
7199 "Period between BGP table scans, in seconds; default 60\n")
7200{
7201 VTY_DECLVAR_CONTEXT(bgp, bgp);
7202
7203 bgp->condition_check_period =
7204 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7205
7206 return CMD_SUCCESS;
7207}
7208
cf2ad4d8 7209DEFPY (neighbor_advertise_map,
7f7940e6 7210 neighbor_advertise_map_cmd,
52b84062 7211 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
cf2ad4d8 7212 NO_STR
7f7940e6
MK
7213 NEIGHBOR_STR
7214 NEIGHBOR_ADDR_STR2
7215 "Route-map to conditionally advertise routes\n"
7216 "Name of advertise map\n"
7217 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7218 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7219 "Name of the exist or non exist map\n")
7f7940e6 7220{
7f7940e6
MK
7221 bool condition = CONDITION_EXIST;
7222
52b84062 7223 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7224 condition = CONDITION_NON_EXIST;
7225
52b84062
MK
7226 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7227 bgp_node_safi(vty), advertise_str,
7228 condition_str, condition, !no);
7f7940e6
MK
7229}
7230
7231ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 7232 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
7f7940e6
MK
7233 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7234 "Route-map to conditionally advertise routes\n"
7235 "Name of advertise map\n"
7236 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7237 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7238 "Name of the exist or non exist map\n")
7f7940e6 7239
718e3744 7240/* Set route-map to the peer. */
0ea8d871
IR
7241static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7242 afi_t afi, safi_t safi, const char *name_str,
7243 const char *direct_str)
718e3744 7244{
0ea8d871
IR
7245 int ret;
7246 struct peer *peer;
7247 int direct = RMAP_IN;
7248 struct route_map *route_map;
718e3744 7249
0ea8d871
IR
7250 peer = peer_and_group_lookup_vty(vty, ip_str);
7251 if (!peer)
d62a17ae 7252 return CMD_WARNING_CONFIG_FAILED;
718e3744 7253
0ea8d871
IR
7254 /* Check filter direction. */
7255 if (strncmp(direct_str, "in", 2) == 0)
7256 direct = RMAP_IN;
7257 else if (strncmp(direct_str, "o", 1) == 0)
7258 direct = RMAP_OUT;
718e3744 7259
0ea8d871
IR
7260 route_map = route_map_lookup_warn_noexist(vty, name_str);
7261 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7262
0ea8d871
IR
7263 return bgp_vty_return(vty, ret);
7264}
7265
7266static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7267 afi_t afi, safi_t safi,
7268 const char *direct_str)
7269{
7270 int ret;
7271 struct peer *peer;
7272 int direct = RMAP_IN;
7273
7274 peer = peer_and_group_lookup_vty(vty, ip_str);
7275 if (!peer)
7276 return CMD_WARNING_CONFIG_FAILED;
7277
7278 /* Check filter direction. */
7279 if (strncmp(direct_str, "in", 2) == 0)
7280 direct = RMAP_IN;
7281 else if (strncmp(direct_str, "o", 1) == 0)
7282 direct = RMAP_OUT;
7283
7284 ret = peer_route_map_unset(peer, afi, safi, direct);
7285
7286 return bgp_vty_return(vty, ret);
7287}
7288
7289DEFUN (neighbor_route_map,
7290 neighbor_route_map_cmd,
7291 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7292 NEIGHBOR_STR
7293 NEIGHBOR_ADDR_STR2
7294 "Apply route map to neighbor\n"
7295 "Name of route map\n"
7296 "Apply map to incoming routes\n"
7297 "Apply map to outbound routes\n")
7298{
7299 int idx_peer = 1;
7300 int idx_word = 3;
7301 int idx_in_out = 4;
7302 return peer_route_map_set_vty(
7303 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7304 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7305}
7306
d6d7ed37
IR
7307ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7308 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7310 "Apply route map to neighbor\n"
7311 "Name of route map\n"
7312 "Apply map to incoming routes\n"
7313 "Apply map to outbound routes\n")
7314
0ea8d871
IR
7315DEFUN (no_neighbor_route_map,
7316 no_neighbor_route_map_cmd,
7317 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7318 NO_STR
7319 NEIGHBOR_STR
7320 NEIGHBOR_ADDR_STR2
7321 "Apply route map to neighbor\n"
7322 "Name of route map\n"
7323 "Apply map to incoming routes\n"
7324 "Apply map to outbound routes\n")
7325{
7326 int idx_peer = 2;
7327 int idx_in_out = 5;
7328 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7329 bgp_node_afi(vty), bgp_node_safi(vty),
7330 argv[idx_in_out]->arg);
7331}
7332
7333ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7334 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7335 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7336 "Apply route map to neighbor\n"
7337 "Name of route map\n"
7338 "Apply map to incoming routes\n"
7339 "Apply map to outbound routes\n")
7340
718e3744 7341/* Set unsuppress-map to the peer. */
d62a17ae 7342static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7343 afi_t afi, safi_t safi,
7344 const char *name_str)
718e3744 7345{
d62a17ae 7346 int ret;
7347 struct peer *peer;
1de27621 7348 struct route_map *route_map;
718e3744 7349
d62a17ae 7350 peer = peer_and_group_lookup_vty(vty, ip_str);
7351 if (!peer)
7352 return CMD_WARNING_CONFIG_FAILED;
718e3744 7353
1de27621
DA
7354 route_map = route_map_lookup_warn_noexist(vty, name_str);
7355 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7356
d62a17ae 7357 return bgp_vty_return(vty, ret);
718e3744 7358}
7359
7360/* Unset route-map from the peer. */
d62a17ae 7361static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7362 afi_t afi, safi_t safi)
718e3744 7363{
d62a17ae 7364 int ret;
7365 struct peer *peer;
718e3744 7366
d62a17ae 7367 peer = peer_and_group_lookup_vty(vty, ip_str);
7368 if (!peer)
7369 return CMD_WARNING_CONFIG_FAILED;
718e3744 7370
d62a17ae 7371 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7372
d62a17ae 7373 return bgp_vty_return(vty, ret);
718e3744 7374}
7375
7376DEFUN (neighbor_unsuppress_map,
7377 neighbor_unsuppress_map_cmd,
9ccf14f7 7378 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7379 NEIGHBOR_STR
7380 NEIGHBOR_ADDR_STR2
7381 "Route-map to selectively unsuppress suppressed routes\n"
7382 "Name of route map\n")
7383{
d62a17ae 7384 int idx_peer = 1;
7385 int idx_word = 3;
7386 return peer_unsuppress_map_set_vty(
7387 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7388 argv[idx_word]->arg);
718e3744 7389}
7390
d62a17ae 7391ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7392 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7393 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7394 "Route-map to selectively unsuppress suppressed routes\n"
7395 "Name of route map\n")
596c17ba 7396
718e3744 7397DEFUN (no_neighbor_unsuppress_map,
7398 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7399 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7400 NO_STR
7401 NEIGHBOR_STR
7402 NEIGHBOR_ADDR_STR2
7403 "Route-map to selectively unsuppress suppressed routes\n"
7404 "Name of route map\n")
7405{
d62a17ae 7406 int idx_peer = 2;
7407 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7408 bgp_node_afi(vty),
7409 bgp_node_safi(vty));
718e3744 7410}
6b0655a2 7411
d62a17ae 7412ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7413 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7415 "Route-map to selectively unsuppress suppressed routes\n"
7416 "Name of route map\n")
596c17ba 7417
7e62b792
IR
7418static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7419 afi_t afi, safi_t safi,
7420 const char *num_str,
7421 const char *threshold_str, int warning,
7422 const char *restart_str,
7423 const char *force_str)
7424{
7425 int ret;
7426 struct peer *peer;
7427 uint32_t max;
7428 uint8_t threshold;
7429 uint16_t restart;
7430
7431 peer = peer_and_group_lookup_vty(vty, ip_str);
7432 if (!peer)
7433 return CMD_WARNING_CONFIG_FAILED;
7434
7435 max = strtoul(num_str, NULL, 10);
7436 if (threshold_str)
7437 threshold = atoi(threshold_str);
7438 else
7439 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7440
7441 if (restart_str)
7442 restart = atoi(restart_str);
7443 else
7444 restart = 0;
7445
7446 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7447 restart, force_str ? true : false);
7448
7449 return bgp_vty_return(vty, ret);
7450}
7451
7452static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7453 afi_t afi, safi_t safi)
7454{
7455 int ret;
7456 struct peer *peer;
7457
7458 peer = peer_and_group_lookup_vty(vty, ip_str);
7459 if (!peer)
7460 return CMD_WARNING_CONFIG_FAILED;
7461
7462 ret = peer_maximum_prefix_unset(peer, afi, safi);
7463
7464 return bgp_vty_return(vty, ret);
7465}
7466
fde246e8 7467/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7468DEFUN(neighbor_maximum_prefix_out,
7469 neighbor_maximum_prefix_out_cmd,
7470 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7471 NEIGHBOR_STR
7472 NEIGHBOR_ADDR_STR2
7473 "Maximum number of prefixes to be sent to this peer\n"
7474 "Maximum no. of prefix limit\n")
fde246e8
DA
7475{
7476 int idx_peer = 1;
7477 int idx_number = 3;
7e62b792
IR
7478 struct peer *peer;
7479 uint32_t max;
fde246e8
DA
7480 afi_t afi = bgp_node_afi(vty);
7481 safi_t safi = bgp_node_safi(vty);
7482
7e62b792
IR
7483 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7484 if (!peer)
fde246e8
DA
7485 return CMD_WARNING_CONFIG_FAILED;
7486
7e62b792 7487 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7488
7e62b792
IR
7489 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7490 peer->pmax_out[afi][safi] = max;
fde246e8 7491
7e62b792 7492 return CMD_SUCCESS;
fde246e8
DA
7493}
7494
1d80f243
IR
7495DEFUN(no_neighbor_maximum_prefix_out,
7496 no_neighbor_maximum_prefix_out_cmd,
7497 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7498 NO_STR
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR2
7501 "Maximum number of prefixes to be sent to this peer\n")
fde246e8
DA
7502{
7503 int idx_peer = 2;
7e62b792 7504 struct peer *peer;
fde246e8
DA
7505 afi_t afi = bgp_node_afi(vty);
7506 safi_t safi = bgp_node_safi(vty);
7507
7e62b792
IR
7508 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7509 if (!peer)
fde246e8
DA
7510 return CMD_WARNING_CONFIG_FAILED;
7511
7e62b792
IR
7512 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7513 peer->pmax_out[afi][safi] = 0;
fde246e8 7514
7e62b792 7515 return CMD_SUCCESS;
fde246e8
DA
7516}
7517
9cbd06e0
DA
7518/* Maximum number of prefix configuration. Prefix count is different
7519 for each peer configuration. So this configuration can be set for
718e3744 7520 each peer configuration. */
1d80f243
IR
7521DEFUN (neighbor_maximum_prefix,
7522 neighbor_maximum_prefix_cmd,
7523 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7524 NEIGHBOR_STR
7525 NEIGHBOR_ADDR_STR2
7526 "Maximum number of prefix accept from this peer\n"
7527 "maximum no. of prefix limit\n"
7528 "Force checking all received routes not only accepted\n")
718e3744 7529{
d62a17ae 7530 int idx_peer = 1;
7531 int idx_number = 3;
9cbd06e0 7532 int idx_force = 0;
7e62b792 7533 char *force = NULL;
9cbd06e0
DA
7534
7535 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7536 force = argv[idx_force]->arg;
9cbd06e0 7537
7e62b792
IR
7538 return peer_maximum_prefix_set_vty(
7539 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7540 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7541}
7542
d62a17ae 7543ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7544 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7547 "maximum no. of prefix limit\n"
7548 "Force checking all received routes not only accepted\n")
596c17ba 7549
1d80f243
IR
7550DEFUN (neighbor_maximum_prefix_threshold,
7551 neighbor_maximum_prefix_threshold_cmd,
7552 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7553 NEIGHBOR_STR
7554 NEIGHBOR_ADDR_STR2
7555 "Maximum number of prefix accept from this peer\n"
7556 "maximum no. of prefix limit\n"
7557 "Threshold value (%) at which to generate a warning msg\n"
7558 "Force checking all received routes not only accepted\n")
e0701b79 7559{
d62a17ae 7560 int idx_peer = 1;
7561 int idx_number = 3;
7562 int idx_number_2 = 4;
9cbd06e0 7563 int idx_force = 0;
7e62b792 7564 char *force = NULL;
9cbd06e0
DA
7565
7566 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7567 force = argv[idx_force]->arg;
9cbd06e0 7568
7e62b792
IR
7569 return peer_maximum_prefix_set_vty(
7570 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7571 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7572}
e0701b79 7573
d62a17ae 7574ALIAS_HIDDEN(
7575 neighbor_maximum_prefix_threshold,
7576 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7577 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7578 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7579 "Maximum number of prefix accept from this peer\n"
7580 "maximum no. of prefix limit\n"
9cbd06e0
DA
7581 "Threshold value (%) at which to generate a warning msg\n"
7582 "Force checking all received routes not only accepted\n")
596c17ba 7583
1d80f243
IR
7584DEFUN (neighbor_maximum_prefix_warning,
7585 neighbor_maximum_prefix_warning_cmd,
7586 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7587 NEIGHBOR_STR
7588 NEIGHBOR_ADDR_STR2
7589 "Maximum number of prefix accept from this peer\n"
7590 "maximum no. of prefix limit\n"
7591 "Only give warning message when limit is exceeded\n"
7592 "Force checking all received routes not only accepted\n")
718e3744 7593{
d62a17ae 7594 int idx_peer = 1;
7595 int idx_number = 3;
9cbd06e0 7596 int idx_force = 0;
7e62b792 7597 char *force = NULL;
9cbd06e0
DA
7598
7599 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7600 force = argv[idx_force]->arg;
9cbd06e0 7601
7e62b792
IR
7602 return peer_maximum_prefix_set_vty(
7603 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7604 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7605}
7606
d62a17ae 7607ALIAS_HIDDEN(
7608 neighbor_maximum_prefix_warning,
7609 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7610 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7611 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7612 "Maximum number of prefix accept from this peer\n"
7613 "maximum no. of prefix limit\n"
9cbd06e0
DA
7614 "Only give warning message when limit is exceeded\n"
7615 "Force checking all received routes not only accepted\n")
596c17ba 7616
1d80f243
IR
7617DEFUN (neighbor_maximum_prefix_threshold_warning,
7618 neighbor_maximum_prefix_threshold_warning_cmd,
7619 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7620 NEIGHBOR_STR
7621 NEIGHBOR_ADDR_STR2
7622 "Maximum number of prefix accept from this peer\n"
7623 "maximum no. of prefix limit\n"
7624 "Threshold value (%) at which to generate a warning msg\n"
7625 "Only give warning message when limit is exceeded\n"
7626 "Force checking all received routes not only accepted\n")
e0701b79 7627{
d62a17ae 7628 int idx_peer = 1;
7629 int idx_number = 3;
7630 int idx_number_2 = 4;
9cbd06e0 7631 int idx_force = 0;
7e62b792 7632 char *force = NULL;
9cbd06e0
DA
7633
7634 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7635 force = argv[idx_force]->arg;
9cbd06e0 7636
7e62b792
IR
7637 return peer_maximum_prefix_set_vty(
7638 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7639 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7640}
7641
d62a17ae 7642ALIAS_HIDDEN(
7643 neighbor_maximum_prefix_threshold_warning,
7644 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7645 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7646 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7647 "Maximum number of prefix accept from this peer\n"
7648 "maximum no. of prefix limit\n"
7649 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7650 "Only give warning message when limit is exceeded\n"
7651 "Force checking all received routes not only accepted\n")
596c17ba 7652
1d80f243
IR
7653DEFUN (neighbor_maximum_prefix_restart,
7654 neighbor_maximum_prefix_restart_cmd,
7655 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7656 NEIGHBOR_STR
7657 NEIGHBOR_ADDR_STR2
7658 "Maximum number of prefix accept from this peer\n"
7659 "maximum no. of prefix limit\n"
7660 "Restart bgp connection after limit is exceeded\n"
7661 "Restart interval in minutes\n"
7662 "Force checking all received routes not only accepted\n")
0a486e5f 7663{
d62a17ae 7664 int idx_peer = 1;
7665 int idx_number = 3;
7666 int idx_number_2 = 5;
9cbd06e0 7667 int idx_force = 0;
7e62b792 7668 char *force = NULL;
9cbd06e0
DA
7669
7670 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7671 force = argv[idx_force]->arg;
9cbd06e0 7672
7e62b792
IR
7673 return peer_maximum_prefix_set_vty(
7674 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7675 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7676}
7677
d62a17ae 7678ALIAS_HIDDEN(
7679 neighbor_maximum_prefix_restart,
7680 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7681 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7683 "Maximum number of prefix accept from this peer\n"
7684 "maximum no. of prefix limit\n"
7685 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7686 "Restart interval in minutes\n"
7687 "Force checking all received routes not only accepted\n")
596c17ba 7688
1d80f243
IR
7689DEFUN (neighbor_maximum_prefix_threshold_restart,
7690 neighbor_maximum_prefix_threshold_restart_cmd,
7691 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7692 NEIGHBOR_STR
7693 NEIGHBOR_ADDR_STR2
7694 "Maximum number of prefixes to accept from this peer\n"
7695 "maximum no. of prefix limit\n"
7696 "Threshold value (%) at which to generate a warning msg\n"
7697 "Restart bgp connection after limit is exceeded\n"
7698 "Restart interval in minutes\n"
7699 "Force checking all received routes not only accepted\n")
0a486e5f 7700{
d62a17ae 7701 int idx_peer = 1;
7702 int idx_number = 3;
7703 int idx_number_2 = 4;
7704 int idx_number_3 = 6;
9cbd06e0 7705 int idx_force = 0;
7e62b792 7706 char *force = NULL;
9cbd06e0
DA
7707
7708 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7709 force = argv[idx_force]->arg;
9cbd06e0 7710
7e62b792
IR
7711 return peer_maximum_prefix_set_vty(
7712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7713 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
7714 argv[idx_number_3]->arg, force);
d62a17ae 7715}
7716
7717ALIAS_HIDDEN(
7718 neighbor_maximum_prefix_threshold_restart,
7719 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7722 "Maximum number of prefixes to accept from this peer\n"
7723 "maximum no. of prefix limit\n"
7724 "Threshold value (%) at which to generate a warning msg\n"
7725 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7726 "Restart interval in minutes\n"
7727 "Force checking all received routes not only accepted\n")
596c17ba 7728
1d80f243
IR
7729DEFUN (no_neighbor_maximum_prefix,
7730 no_neighbor_maximum_prefix_cmd,
7731 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
7732 NO_STR
7733 NEIGHBOR_STR
7734 NEIGHBOR_ADDR_STR2
7735 "Maximum number of prefixes to accept from this peer\n"
7736 "maximum no. of prefix limit\n"
7737 "Threshold value (%) at which to generate a warning msg\n"
7738 "Restart bgp connection after limit is exceeded\n"
7739 "Restart interval in minutes\n"
7740 "Only give warning message when limit is exceeded\n"
7741 "Force checking all received routes not only accepted\n")
718e3744 7742{
d62a17ae 7743 int idx_peer = 2;
7e62b792
IR
7744 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7745 bgp_node_afi(vty),
7746 bgp_node_safi(vty));
718e3744 7747}
e52702f2 7748
d62a17ae 7749ALIAS_HIDDEN(
7750 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7751 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7752 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7753 "Maximum number of prefixes to accept from this peer\n"
7754 "maximum no. of prefix limit\n"
7755 "Threshold value (%) at which to generate a warning msg\n"
7756 "Restart bgp connection after limit is exceeded\n"
7757 "Restart interval in minutes\n"
9cbd06e0
DA
7758 "Only give warning message when limit is exceeded\n"
7759 "Force checking all received routes not only accepted\n")
596c17ba 7760
718e3744 7761
718e3744 7762/* "neighbor allowas-in" */
7763DEFUN (neighbor_allowas_in,
7764 neighbor_allowas_in_cmd,
fd8503f5 7765 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7766 NEIGHBOR_STR
7767 NEIGHBOR_ADDR_STR2
31500417 7768 "Accept as-path with my AS present in it\n"
f79f7a7b 7769 "Number of occurrences of AS number\n"
fd8503f5 7770 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7771{
d62a17ae 7772 int idx_peer = 1;
7773 int idx_number_origin = 3;
7774 int ret;
7775 int origin = 0;
7776 struct peer *peer;
7777 int allow_num = 0;
7778
7779 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7780 if (!peer)
7781 return CMD_WARNING_CONFIG_FAILED;
7782
7783 if (argc <= idx_number_origin)
7784 allow_num = 3;
7785 else {
7786 if (argv[idx_number_origin]->type == WORD_TKN)
7787 origin = 1;
7788 else
7789 allow_num = atoi(argv[idx_number_origin]->arg);
7790 }
7791
7792 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7793 allow_num, origin);
7794
7795 return bgp_vty_return(vty, ret);
7796}
7797
7798ALIAS_HIDDEN(
7799 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7800 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7802 "Accept as-path with my AS present in it\n"
f79f7a7b 7803 "Number of occurrences of AS number\n"
d62a17ae 7804 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7805
718e3744 7806DEFUN (no_neighbor_allowas_in,
7807 no_neighbor_allowas_in_cmd,
fd8503f5 7808 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7809 NO_STR
7810 NEIGHBOR_STR
7811 NEIGHBOR_ADDR_STR2
8334fd5a 7812 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7813 "Number of occurrences of AS number\n"
fd8503f5 7814 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7815{
d62a17ae 7816 int idx_peer = 2;
7817 int ret;
7818 struct peer *peer;
718e3744 7819
d62a17ae 7820 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7821 if (!peer)
7822 return CMD_WARNING_CONFIG_FAILED;
718e3744 7823
d62a17ae 7824 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7825 bgp_node_safi(vty));
718e3744 7826
d62a17ae 7827 return bgp_vty_return(vty, ret);
718e3744 7828}
6b0655a2 7829
d62a17ae 7830ALIAS_HIDDEN(
7831 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7832 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7833 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7834 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7835 "Number of occurrences of AS number\n"
d62a17ae 7836 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7837
28c6e247
IR
7838DEFUN (neighbor_ttl_security,
7839 neighbor_ttl_security_cmd,
7840 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7841 NEIGHBOR_STR
7842 NEIGHBOR_ADDR_STR2
7843 "BGP ttl-security parameters\n"
7844 "Specify the maximum number of hops to the BGP peer\n"
7845 "Number of hops to BGP peer\n")
fa411a21 7846{
d62a17ae 7847 int idx_peer = 1;
7848 int idx_number = 4;
28c6e247
IR
7849 struct peer *peer;
7850 int gtsm_hops;
d62a17ae 7851
28c6e247
IR
7852 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7853 if (!peer)
d62a17ae 7854 return CMD_WARNING_CONFIG_FAILED;
7855
28c6e247
IR
7856 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7857
7858 /*
7859 * If 'neighbor swpX', then this is for directly connected peers,
7860 * we should not accept a ttl-security hops value greater than 1.
7861 */
7862 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7863 vty_out(vty,
7864 "%s is directly connected peer, hops cannot exceed 1\n",
7865 argv[idx_peer]->arg);
7866 return CMD_WARNING_CONFIG_FAILED;
7867 }
7ebe625c 7868
28c6e247 7869 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7870}
7871
1d80f243
IR
7872DEFUN (no_neighbor_ttl_security,
7873 no_neighbor_ttl_security_cmd,
7874 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
7875 NO_STR
7876 NEIGHBOR_STR
7877 NEIGHBOR_ADDR_STR2
7878 "BGP ttl-security parameters\n"
7879 "Specify the maximum number of hops to the BGP peer\n"
7880 "Number of hops to BGP peer\n")
fa411a21 7881{
d62a17ae 7882 int idx_peer = 2;
28c6e247 7883 struct peer *peer;
fa411a21 7884
28c6e247
IR
7885 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7886 if (!peer)
d62a17ae 7887 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7888
28c6e247 7889 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7890}
6b0655a2 7891
adbac85e
DW
7892DEFUN (neighbor_addpath_tx_all_paths,
7893 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7894 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7895 NEIGHBOR_STR
7896 NEIGHBOR_ADDR_STR2
7897 "Use addpath to advertise all paths to a neighbor\n")
7898{
d62a17ae 7899 int idx_peer = 1;
7900 struct peer *peer;
adbac85e 7901
d62a17ae 7902 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7903 if (!peer)
7904 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7905
dcc68b5e
MS
7906 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7907 BGP_ADDPATH_ALL);
7908 return CMD_SUCCESS;
adbac85e
DW
7909}
7910
d62a17ae 7911ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7912 neighbor_addpath_tx_all_paths_hidden_cmd,
7913 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7914 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7915 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7916
adbac85e
DW
7917DEFUN (no_neighbor_addpath_tx_all_paths,
7918 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7919 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7920 NO_STR
7921 NEIGHBOR_STR
7922 NEIGHBOR_ADDR_STR2
7923 "Use addpath to advertise all paths to a neighbor\n")
7924{
d62a17ae 7925 int idx_peer = 2;
dcc68b5e
MS
7926 struct peer *peer;
7927
7928 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7929 if (!peer)
7930 return CMD_WARNING_CONFIG_FAILED;
7931
7932 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7933 != BGP_ADDPATH_ALL) {
7934 vty_out(vty,
7935 "%% Peer not currently configured to transmit all paths.");
7936 return CMD_WARNING_CONFIG_FAILED;
7937 }
7938
7939 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7940 BGP_ADDPATH_NONE);
7941
7942 return CMD_SUCCESS;
adbac85e
DW
7943}
7944
d62a17ae 7945ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7946 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7947 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7949 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7950
06370dac
DW
7951DEFUN (neighbor_addpath_tx_bestpath_per_as,
7952 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7953 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7954 NEIGHBOR_STR
7955 NEIGHBOR_ADDR_STR2
7956 "Use addpath to advertise the bestpath per each neighboring AS\n")
7957{
d62a17ae 7958 int idx_peer = 1;
7959 struct peer *peer;
06370dac 7960
d62a17ae 7961 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7962 if (!peer)
7963 return CMD_WARNING_CONFIG_FAILED;
06370dac 7964
dcc68b5e
MS
7965 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7966 BGP_ADDPATH_BEST_PER_AS);
7967
7968 return CMD_SUCCESS;
06370dac
DW
7969}
7970
d62a17ae 7971ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7972 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7973 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7975 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7976
06370dac
DW
7977DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7978 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7979 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7980 NO_STR
7981 NEIGHBOR_STR
7982 NEIGHBOR_ADDR_STR2
7983 "Use addpath to advertise the bestpath per each neighboring AS\n")
7984{
d62a17ae 7985 int idx_peer = 2;
dcc68b5e
MS
7986 struct peer *peer;
7987
7988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7989 if (!peer)
7990 return CMD_WARNING_CONFIG_FAILED;
7991
7992 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7993 != BGP_ADDPATH_BEST_PER_AS) {
7994 vty_out(vty,
7995 "%% Peer not currently configured to transmit all best path per as.");
7996 return CMD_WARNING_CONFIG_FAILED;
7997 }
7998
7999 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8000 BGP_ADDPATH_NONE);
8001
8002 return CMD_SUCCESS;
06370dac
DW
8003}
8004
d62a17ae 8005ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8006 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8007 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8008 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8009 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8010
2b31007c
RZ
8011DEFPY(
8012 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8013 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8014 NEIGHBOR_STR
8015 NEIGHBOR_ADDR_STR2
8016 "Detect AS loops before sending to neighbor\n")
8017{
8018 struct peer *peer;
8019
8020 peer = peer_and_group_lookup_vty(vty, neighbor);
8021 if (!peer)
8022 return CMD_WARNING_CONFIG_FAILED;
8023
8024 peer->as_path_loop_detection = true;
8025
8026 return CMD_SUCCESS;
8027}
8028
8029DEFPY(
8030 no_neighbor_aspath_loop_detection,
8031 no_neighbor_aspath_loop_detection_cmd,
8032 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8033 NO_STR
8034 NEIGHBOR_STR
8035 NEIGHBOR_ADDR_STR2
8036 "Detect AS loops before sending to neighbor\n")
8037{
8038 struct peer *peer;
8039
8040 peer = peer_and_group_lookup_vty(vty, neighbor);
8041 if (!peer)
8042 return CMD_WARNING_CONFIG_FAILED;
8043
8044 peer->as_path_loop_detection = false;
8045
8046 return CMD_SUCCESS;
8047}
8048
b9c7bc5a 8049static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8050 struct ecommunity **list, bool is_rt6)
ddb5b488 8051{
b9c7bc5a
PZ
8052 struct ecommunity *ecom = NULL;
8053 struct ecommunity *ecomadd;
ddb5b488 8054
b9c7bc5a 8055 for (; argc; --argc, ++argv) {
9a659715
PG
8056 if (is_rt6)
8057 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8058 ECOMMUNITY_ROUTE_TARGET,
8059 0);
8060 else
8061 ecomadd = ecommunity_str2com(argv[0]->arg,
8062 ECOMMUNITY_ROUTE_TARGET,
8063 0);
b9c7bc5a
PZ
8064 if (!ecomadd) {
8065 vty_out(vty, "Malformed community-list value\n");
8066 if (ecom)
8067 ecommunity_free(&ecom);
8068 return CMD_WARNING_CONFIG_FAILED;
8069 }
ddb5b488 8070
b9c7bc5a
PZ
8071 if (ecom) {
8072 ecommunity_merge(ecom, ecomadd);
8073 ecommunity_free(&ecomadd);
8074 } else {
8075 ecom = ecomadd;
8076 }
8077 }
8078
8079 if (*list) {
8080 ecommunity_free(&*list);
ddb5b488 8081 }
b9c7bc5a
PZ
8082 *list = ecom;
8083
8084 return CMD_SUCCESS;
ddb5b488
PZ
8085}
8086
0ca70ba5
DS
8087/*
8088 * v2vimport is true if we are handling a `import vrf ...` command
8089 */
8090static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8091{
0ca70ba5
DS
8092 afi_t afi;
8093
ddb5b488 8094 switch (vty->node) {
b9c7bc5a 8095 case BGP_IPV4_NODE:
0ca70ba5
DS
8096 afi = AFI_IP;
8097 break;
b9c7bc5a 8098 case BGP_IPV6_NODE:
0ca70ba5
DS
8099 afi = AFI_IP6;
8100 break;
ddb5b488
PZ
8101 default:
8102 vty_out(vty,
b9c7bc5a 8103 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8104 return AFI_MAX;
ddb5b488 8105 }
69b07479 8106
0ca70ba5
DS
8107 if (!v2vimport) {
8108 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8109 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8110 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8111 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8112 vty_out(vty,
8113 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8114 return AFI_MAX;
8115 }
8116 } else {
8117 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8118 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8119 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8120 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8121 vty_out(vty,
8122 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8123 return AFI_MAX;
8124 }
8125 }
8126 return afi;
ddb5b488
PZ
8127}
8128
585f1adc
IR
8129DEFPY (af_rd_vpn_export,
8130 af_rd_vpn_export_cmd,
8131 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8132 NO_STR
8133 "Specify route distinguisher\n"
8134 "Between current address-family and vpn\n"
8135 "For routes leaked from current address-family to vpn\n"
8136 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8137{
585f1adc
IR
8138 VTY_DECLVAR_CONTEXT(bgp, bgp);
8139 struct prefix_rd prd;
8140 int ret;
ddb5b488 8141 afi_t afi;
b9c7bc5a 8142 int idx = 0;
585f1adc 8143 bool yes = true;
b9c7bc5a 8144
585f1adc
IR
8145 if (argv_find(argv, argc, "no", &idx))
8146 yes = false;
ddb5b488 8147
585f1adc
IR
8148 if (yes) {
8149 ret = str2prefix_rd(rd_str, &prd);
8150 if (!ret) {
8151 vty_out(vty, "%% Malformed rd\n");
8152 return CMD_WARNING_CONFIG_FAILED;
8153 }
8154 }
ddb5b488 8155
585f1adc
IR
8156 afi = vpn_policy_getafi(vty, bgp, false);
8157 if (afi == AFI_MAX)
8158 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8159
585f1adc
IR
8160 /*
8161 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8162 */
8163 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8164 bgp_get_default(), bgp);
ddb5b488 8165
585f1adc
IR
8166 if (yes) {
8167 bgp->vpn_policy[afi].tovpn_rd = prd;
8168 SET_FLAG(bgp->vpn_policy[afi].flags,
8169 BGP_VPN_POLICY_TOVPN_RD_SET);
8170 } else {
8171 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8172 BGP_VPN_POLICY_TOVPN_RD_SET);
8173 }
69b07479 8174
585f1adc
IR
8175 /* post-change: re-export vpn routes */
8176 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8177 bgp_get_default(), bgp);
8178
8179 return CMD_SUCCESS;
ddb5b488
PZ
8180}
8181
b9c7bc5a
PZ
8182ALIAS (af_rd_vpn_export,
8183 af_no_rd_vpn_export_cmd,
8184 "no rd vpn export",
ddb5b488 8185 NO_STR
b9c7bc5a
PZ
8186 "Specify route distinguisher\n"
8187 "Between current address-family and vpn\n"
8188 "For routes leaked from current address-family to vpn\n")
ddb5b488 8189
b9c7bc5a
PZ
8190DEFPY (af_label_vpn_export,
8191 af_label_vpn_export_cmd,
e70e9f8e 8192 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8193 NO_STR
ddb5b488 8194 "label value for VRF\n"
b9c7bc5a
PZ
8195 "Between current address-family and vpn\n"
8196 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8197 "Label Value <0-1048575>\n"
8198 "Automatically assign a label\n")
ddb5b488
PZ
8199{
8200 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8201 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8202 afi_t afi;
b9c7bc5a 8203 int idx = 0;
c6423c31 8204 bool yes = true;
b9c7bc5a
PZ
8205
8206 if (argv_find(argv, argc, "no", &idx))
c6423c31 8207 yes = false;
ddb5b488 8208
21a16cc2
PZ
8209 /* If "no ...", squash trailing parameter */
8210 if (!yes)
8211 label_auto = NULL;
8212
e70e9f8e
PZ
8213 if (yes) {
8214 if (!label_auto)
8215 label = label_val; /* parser should force unsigned */
8216 }
ddb5b488 8217
0ca70ba5 8218 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8219 if (afi == AFI_MAX)
8220 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8221
e70e9f8e 8222
69b07479
DS
8223 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8224 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8225 /* no change */
8226 return CMD_SUCCESS;
e70e9f8e 8227
69b07479
DS
8228 /*
8229 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8230 */
8231 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8232 bgp_get_default(), bgp);
8233
8234 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8235 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8236
8237 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8238
8239 /*
8240 * label has previously been automatically
8241 * assigned by labelpool: release it
8242 *
8243 * NB if tovpn_label == MPLS_LABEL_NONE it
8244 * means the automatic assignment is in flight
8245 * and therefore the labelpool callback must
8246 * detect that the auto label is not needed.
8247 */
8248
8249 bgp_lp_release(LP_TYPE_VRF,
8250 &bgp->vpn_policy[afi],
8251 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8252 }
69b07479
DS
8253 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8254 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8255 }
ddb5b488 8256
69b07479
DS
8257 bgp->vpn_policy[afi].tovpn_label = label;
8258 if (label_auto) {
8259 SET_FLAG(bgp->vpn_policy[afi].flags,
8260 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8261 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8262 vpn_leak_label_callback);
ddb5b488
PZ
8263 }
8264
69b07479
DS
8265 /* post-change: re-export vpn routes */
8266 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8267 bgp_get_default(), bgp);
8268
0d020cd6 8269 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8270 return CMD_SUCCESS;
8271}
8272
b72c9e14
HS
8273DEFPY (af_sid_vpn_export,
8274 af_sid_vpn_export_cmd,
8275 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8276 NO_STR
8277 "sid value for VRF\n"
8278 "Between current address-family and vpn\n"
8279 "For routes leaked from current address-family to vpn\n"
8280 "Sid allocation index\n"
8281 "Automatically assign a label\n")
8282{
8283 VTY_DECLVAR_CONTEXT(bgp, bgp);
8284 afi_t afi;
8285 int debug = 0;
8286 int idx = 0;
8287 bool yes = true;
8288
8289 if (argv_find(argv, argc, "no", &idx))
8290 yes = false;
8291 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8292 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8293
8294 afi = vpn_policy_getafi(vty, bgp, false);
8295 if (afi == AFI_MAX)
8296 return CMD_WARNING_CONFIG_FAILED;
8297
8298 if (!yes) {
8299 /* implement me */
8300 vty_out(vty, "It's not implemented");
8301 return CMD_WARNING_CONFIG_FAILED;
8302 }
8303
8304 /* skip when it's already configured */
8305 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8306 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8307 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8308 return CMD_SUCCESS;
8309
7de4c885
HS
8310 /*
8311 * mode change between sid_idx and sid_auto isn't supported.
8312 * user must negate sid vpn export when they want to change the mode
8313 */
b72c9e14
HS
8314 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8315 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8316 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8317 vty_out(vty, "it's already configured as %s.\n",
8318 sid_auto ? "auto-mode" : "idx-mode");
8319 return CMD_WARNING_CONFIG_FAILED;
8320 }
8321
8322 /* pre-change */
8323 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8324 bgp_get_default(), bgp);
8325
8326 if (sid_auto) {
8327 /* SID allocation auto-mode */
8328 if (debug)
8329 zlog_debug("%s: auto sid alloc.", __func__);
8330 SET_FLAG(bgp->vpn_policy[afi].flags,
8331 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8332 } else {
8333 /* SID allocation index-mode */
8334 if (debug)
8335 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8336 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8337 }
8338
8339 /* post-change */
8340 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8341 bgp_get_default(), bgp);
8342 return CMD_SUCCESS;
8343}
8344
b9c7bc5a
PZ
8345ALIAS (af_label_vpn_export,
8346 af_no_label_vpn_export_cmd,
8347 "no label vpn export",
8348 NO_STR
8349 "label value for VRF\n"
8350 "Between current address-family and vpn\n"
8351 "For routes leaked from current address-family to vpn\n")
ddb5b488 8352
585f1adc 8353DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8354 af_nexthop_vpn_export_cmd,
8c85ca28 8355 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8356 NO_STR
ddb5b488 8357 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8358 "Between current address-family and vpn\n"
8359 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8360 "IPv4 prefix\n"
8361 "IPv6 prefix\n")
8362{
585f1adc 8363 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8364 afi_t afi;
ddb5b488
PZ
8365 struct prefix p;
8366
8c85ca28
QY
8367 if (!no) {
8368 if (!nexthop_su) {
8369 vty_out(vty, "%% Nexthop required\n");
8370 return CMD_WARNING_CONFIG_FAILED;
8371 }
8c85ca28 8372 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8373 return CMD_WARNING_CONFIG_FAILED;
8374 }
ddb5b488 8375
585f1adc
IR
8376 afi = vpn_policy_getafi(vty, bgp, false);
8377 if (afi == AFI_MAX)
8378 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8379
585f1adc
IR
8380 /*
8381 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8382 */
8383 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8384 bgp_get_default(), bgp);
ddb5b488 8385
585f1adc
IR
8386 if (!no) {
8387 bgp->vpn_policy[afi].tovpn_nexthop = p;
8388 SET_FLAG(bgp->vpn_policy[afi].flags,
8389 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8390 } else {
8391 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8392 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8393 }
69b07479 8394
585f1adc
IR
8395 /* post-change: re-export vpn routes */
8396 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8397 bgp_get_default(), bgp);
37a87b8f 8398
585f1adc 8399 return CMD_SUCCESS;
ddb5b488
PZ
8400}
8401
b9c7bc5a 8402static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8403{
b9c7bc5a
PZ
8404 if (!strcmp(dstr, "import")) {
8405 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8406 } else if (!strcmp(dstr, "export")) {
8407 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8408 } else if (!strcmp(dstr, "both")) {
8409 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8410 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8411 } else {
8412 vty_out(vty, "%% direction parse error\n");
8413 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8414 }
ddb5b488
PZ
8415 return CMD_SUCCESS;
8416}
8417
b9c7bc5a
PZ
8418DEFPY (af_rt_vpn_imexport,
8419 af_rt_vpn_imexport_cmd,
8420 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8421 NO_STR
8422 "Specify route target list\n"
ddb5b488 8423 "Specify route target list\n"
b9c7bc5a
PZ
8424 "Between current address-family and vpn\n"
8425 "For routes leaked from vpn to current address-family: match any\n"
8426 "For routes leaked from current address-family to vpn: set\n"
8427 "both import: match any and export: set\n"
ddb5b488
PZ
8428 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8429{
8430 VTY_DECLVAR_CONTEXT(bgp, bgp);
8431 int ret;
8432 struct ecommunity *ecom = NULL;
8433 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8434 vpn_policy_direction_t dir;
8435 afi_t afi;
8436 int idx = 0;
c6423c31 8437 bool yes = true;
ddb5b488 8438
b9c7bc5a 8439 if (argv_find(argv, argc, "no", &idx))
c6423c31 8440 yes = false;
b9c7bc5a 8441
0ca70ba5 8442 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8443 if (afi == AFI_MAX)
8444 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8445
b9c7bc5a 8446 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8447 if (ret != CMD_SUCCESS)
8448 return ret;
8449
b9c7bc5a
PZ
8450 if (yes) {
8451 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8452 vty_out(vty, "%% Missing RTLIST\n");
8453 return CMD_WARNING_CONFIG_FAILED;
8454 }
c6423c31 8455 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8456 if (ret != CMD_SUCCESS) {
8457 return ret;
8458 }
ddb5b488
PZ
8459 }
8460
69b07479
DS
8461 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8462 if (!dodir[dir])
ddb5b488 8463 continue;
ddb5b488 8464
69b07479 8465 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8466
69b07479
DS
8467 if (yes) {
8468 if (bgp->vpn_policy[afi].rtlist[dir])
8469 ecommunity_free(
8470 &bgp->vpn_policy[afi].rtlist[dir]);
8471 bgp->vpn_policy[afi].rtlist[dir] =
8472 ecommunity_dup(ecom);
8473 } else {
8474 if (bgp->vpn_policy[afi].rtlist[dir])
8475 ecommunity_free(
8476 &bgp->vpn_policy[afi].rtlist[dir]);
8477 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8478 }
69b07479
DS
8479
8480 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8481 }
69b07479 8482
d555f3e9
PZ
8483 if (ecom)
8484 ecommunity_free(&ecom);
ddb5b488
PZ
8485
8486 return CMD_SUCCESS;
8487}
8488
b9c7bc5a
PZ
8489ALIAS (af_rt_vpn_imexport,
8490 af_no_rt_vpn_imexport_cmd,
8491 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8492 NO_STR
8493 "Specify route target list\n"
b9c7bc5a
PZ
8494 "Specify route target list\n"
8495 "Between current address-family and vpn\n"
8496 "For routes leaked from vpn to current address-family\n"
8497 "For routes leaked from current address-family to vpn\n"
8498 "both import and export\n")
8499
585f1adc 8500DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8501 af_route_map_vpn_imexport_cmd,
8502/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8503 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8504 NO_STR
ddb5b488 8505 "Specify route map\n"
b9c7bc5a
PZ
8506 "Between current address-family and vpn\n"
8507 "For routes leaked from vpn to current address-family\n"
8508 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8509 "name of route-map\n")
8510{
585f1adc
IR
8511 VTY_DECLVAR_CONTEXT(bgp, bgp);
8512 int ret;
8513 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
8514 vpn_policy_direction_t dir;
ddb5b488 8515 afi_t afi;
ddb5b488 8516 int idx = 0;
585f1adc 8517 bool yes = true;
ddb5b488 8518
585f1adc
IR
8519 if (argv_find(argv, argc, "no", &idx))
8520 yes = false;
ddb5b488 8521
585f1adc
IR
8522 afi = vpn_policy_getafi(vty, bgp, false);
8523 if (afi == AFI_MAX)
8524 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8525
585f1adc
IR
8526 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8527 if (ret != CMD_SUCCESS)
8528 return ret;
ddb5b488 8529
585f1adc
IR
8530 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8531 if (!dodir[dir])
8532 continue;
69b07479 8533
585f1adc
IR
8534 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8535
8536 if (yes) {
8537 if (bgp->vpn_policy[afi].rmap_name[dir])
8538 XFREE(MTYPE_ROUTE_MAP_NAME,
8539 bgp->vpn_policy[afi].rmap_name[dir]);
8540 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8541 MTYPE_ROUTE_MAP_NAME, rmap_str);
8542 bgp->vpn_policy[afi].rmap[dir] =
8543 route_map_lookup_warn_noexist(vty, rmap_str);
8544 if (!bgp->vpn_policy[afi].rmap[dir])
8545 return CMD_SUCCESS;
8546 } else {
8547 if (bgp->vpn_policy[afi].rmap_name[dir])
8548 XFREE(MTYPE_ROUTE_MAP_NAME,
8549 bgp->vpn_policy[afi].rmap_name[dir]);
8550 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8551 bgp->vpn_policy[afi].rmap[dir] = NULL;
8552 }
8553
8554 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8555 }
ddb5b488 8556
585f1adc 8557 return CMD_SUCCESS;
ddb5b488
PZ
8558}
8559
b9c7bc5a
PZ
8560ALIAS (af_route_map_vpn_imexport,
8561 af_no_route_map_vpn_imexport_cmd,
8562 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8563 NO_STR
8564 "Specify route map\n"
b9c7bc5a
PZ
8565 "Between current address-family and vpn\n"
8566 "For routes leaked from vpn to current address-family\n"
8567 "For routes leaked from current address-family to vpn\n")
8568
bb4f6190 8569DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8570 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8571 "Import routes from another VRF\n"
8572 "Vrf routes being filtered\n"
8573 "Specify route map\n"
8574 "name of route-map\n")
8575{
8576 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8577 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8578 afi_t afi;
bb4f6190
DS
8579 struct bgp *bgp_default;
8580
0ca70ba5 8581 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8582 if (afi == AFI_MAX)
8583 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8584
8585 bgp_default = bgp_get_default();
8586 if (!bgp_default) {
8587 int32_t ret;
8588 as_t as = bgp->as;
8589
8590 /* Auto-create assuming the same AS */
5d5393b9
DL
8591 ret = bgp_get_vty(&bgp_default, &as, NULL,
8592 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8593
8594 if (ret) {
8595 vty_out(vty,
8596 "VRF default is not configured as a bgp instance\n");
8597 return CMD_WARNING;
8598 }
8599 }
8600
69b07479 8601 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8602
ae6a6fb4
DS
8603 if (bgp->vpn_policy[afi].rmap_name[dir])
8604 XFREE(MTYPE_ROUTE_MAP_NAME,
8605 bgp->vpn_policy[afi].rmap_name[dir]);
8606 bgp->vpn_policy[afi].rmap_name[dir] =
8607 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8608 bgp->vpn_policy[afi].rmap[dir] =
8609 route_map_lookup_warn_noexist(vty, rmap_str);
8610 if (!bgp->vpn_policy[afi].rmap[dir])
8611 return CMD_SUCCESS;
8612
8613 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8614 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8615
69b07479
DS
8616 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8617
bb4f6190
DS
8618 return CMD_SUCCESS;
8619}
8620
ae6a6fb4
DS
8621DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8622 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8623 NO_STR
8624 "Import routes from another VRF\n"
8625 "Vrf routes being filtered\n"
ae6a6fb4
DS
8626 "Specify route map\n"
8627 "name of route-map\n")
8628{
8629 VTY_DECLVAR_CONTEXT(bgp, bgp);
8630 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8631 afi_t afi;
8632
8633 afi = vpn_policy_getafi(vty, bgp, true);
8634 if (afi == AFI_MAX)
8635 return CMD_WARNING_CONFIG_FAILED;
8636
8637 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8638
8639 if (bgp->vpn_policy[afi].rmap_name[dir])
8640 XFREE(MTYPE_ROUTE_MAP_NAME,
8641 bgp->vpn_policy[afi].rmap_name[dir]);
8642 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8643 bgp->vpn_policy[afi].rmap[dir] = NULL;
8644
8645 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8646 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8647 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8648
8649 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8650
8651 return CMD_SUCCESS;
8652}
bb4f6190 8653
585f1adc
IR
8654DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8655 "[no] import vrf VIEWVRFNAME$import_name",
8656 NO_STR
8657 "Import routes from another VRF\n"
8658 "VRF to import from\n"
8659 "The name of the VRF\n")
12a844a5 8660{
585f1adc
IR
8661 VTY_DECLVAR_CONTEXT(bgp, bgp);
8662 struct listnode *node;
8663 struct bgp *vrf_bgp, *bgp_default;
8664 int32_t ret = 0;
8665 as_t as = bgp->as;
8666 bool remove = false;
8667 int32_t idx = 0;
8668 char *vname;
8669 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8670 safi_t safi;
8671 afi_t afi;
8672
867f0cca 8673 if (import_name == NULL) {
8674 vty_out(vty, "%% Missing import name\n");
8675 return CMD_WARNING;
8676 }
8677
ae6a6fb4
DS
8678 if (strcmp(import_name, "route-map") == 0) {
8679 vty_out(vty, "%% Must include route-map name\n");
8680 return CMD_WARNING;
8681 }
8682
585f1adc
IR
8683 if (argv_find(argv, argc, "no", &idx))
8684 remove = true;
8685
8686 afi = vpn_policy_getafi(vty, bgp, true);
8687 if (afi == AFI_MAX)
8688 return CMD_WARNING_CONFIG_FAILED;
8689
12a844a5
DS
8690 safi = bgp_node_safi(vty);
8691
585f1adc
IR
8692 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
8693 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
8694 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8695 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8696 remove ? "unimport" : "import", import_name);
8697 return CMD_WARNING;
8698 }
25679caa 8699
585f1adc
IR
8700 bgp_default = bgp_get_default();
8701 if (!bgp_default) {
8702 /* Auto-create assuming the same AS */
8703 ret = bgp_get_vty(&bgp_default, &as, NULL,
8704 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 8705
585f1adc
IR
8706 if (ret) {
8707 vty_out(vty,
8708 "VRF default is not configured as a bgp instance\n");
8709 return CMD_WARNING;
8710 }
8711 }
12a844a5 8712
585f1adc
IR
8713 vrf_bgp = bgp_lookup_by_name(import_name);
8714 if (!vrf_bgp) {
8715 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
8716 vrf_bgp = bgp_default;
8717 else
8718 /* Auto-create assuming the same AS */
8719 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
8720
8721 if (ret) {
8722 vty_out(vty,
8723 "VRF %s is not configured as a bgp instance\n",
8724 import_name);
8725 return CMD_WARNING;
8726 }
8727 }
8728
8729 if (remove) {
8730 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
8731 } else {
8732 /* Already importing from "import_vrf"? */
8733 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8734 vname)) {
8735 if (strcmp(vname, import_name) == 0)
8736 return CMD_WARNING;
8737 }
8738
8739 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
8740 }
8741
8742 return CMD_SUCCESS;
12a844a5
DS
8743}
8744
b9c7bc5a 8745/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 8746DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
8747 bgp_imexport_vpn_cmd,
8748 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8749 NO_STR
8750 "Import routes to this address-family\n"
8751 "Export routes from this address-family\n"
8752 "to/from default instance VPN RIB\n")
ddb5b488 8753{
585f1adc
IR
8754 VTY_DECLVAR_CONTEXT(bgp, bgp);
8755 int previous_state;
37a87b8f 8756 afi_t afi;
585f1adc
IR
8757 safi_t safi;
8758 int idx = 0;
8759 bool yes = true;
8760 int flag;
8761 vpn_policy_direction_t dir;
8762
8763 if (argv_find(argv, argc, "no", &idx))
8764 yes = false;
8765
8766 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8767 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
8768
8769 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8770 return CMD_WARNING_CONFIG_FAILED;
8771 }
ddb5b488 8772
b9c7bc5a
PZ
8773 afi = bgp_node_afi(vty);
8774 safi = bgp_node_safi(vty);
585f1adc
IR
8775 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8776 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8777 return CMD_WARNING_CONFIG_FAILED;
8778 }
ddb5b488 8779
b9c7bc5a 8780 if (!strcmp(direction_str, "import")) {
585f1adc
IR
8781 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8782 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 8783 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
8784 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8785 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
8786 } else {
8787 vty_out(vty, "%% unknown direction %s\n", direction_str);
8788 return CMD_WARNING_CONFIG_FAILED;
8789 }
8790
585f1adc 8791 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8792
585f1adc
IR
8793 if (yes) {
8794 SET_FLAG(bgp->af_flags[afi][safi], flag);
8795 if (!previous_state) {
8796 /* trigger export current vrf */
8797 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8798 }
8799 } else {
8800 if (previous_state) {
8801 /* trigger un-export current vrf */
8802 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8803 }
8804 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
8805 }
37a87b8f 8806
1ca2fd11
IR
8807 hook_call(bgp_snmp_init_stats, bgp);
8808
585f1adc 8809 return CMD_SUCCESS;
ddb5b488
PZ
8810}
8811
301ad80a
PG
8812DEFPY (af_routetarget_import,
8813 af_routetarget_import_cmd,
9a659715 8814 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8815 NO_STR
8816 "Specify route target list\n"
8817 "Specify route target list\n"
9a659715
PG
8818 "Specify route target list\n"
8819 "Specify route target list\n"
301ad80a
PG
8820 "Flow-spec redirect type route target\n"
8821 "Import routes to this address-family\n"
9a659715 8822 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8823{
8824 VTY_DECLVAR_CONTEXT(bgp, bgp);
8825 int ret;
8826 struct ecommunity *ecom = NULL;
301ad80a 8827 afi_t afi;
9a659715 8828 int idx = 0, idx_unused = 0;
c6423c31
PG
8829 bool yes = true;
8830 bool rt6 = false;
301ad80a
PG
8831
8832 if (argv_find(argv, argc, "no", &idx))
c6423c31 8833 yes = false;
301ad80a 8834
9a659715
PG
8835 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8836 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 8837 rt6 = true;
301ad80a 8838
0ca70ba5 8839 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8840 if (afi == AFI_MAX)
8841 return CMD_WARNING_CONFIG_FAILED;
8842
9a659715
PG
8843 if (rt6 && afi != AFI_IP6)
8844 return CMD_WARNING_CONFIG_FAILED;
8845
301ad80a
PG
8846 if (yes) {
8847 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8848 vty_out(vty, "%% Missing RTLIST\n");
8849 return CMD_WARNING_CONFIG_FAILED;
8850 }
9a659715 8851 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8852 if (ret != CMD_SUCCESS)
8853 return ret;
8854 }
69b07479
DS
8855
8856 if (yes) {
8857 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8858 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8859 .import_redirect_rtlist);
69b07479
DS
8860 bgp->vpn_policy[afi].import_redirect_rtlist =
8861 ecommunity_dup(ecom);
8862 } else {
8863 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8864 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8865 .import_redirect_rtlist);
69b07479 8866 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8867 }
69b07479 8868
301ad80a
PG
8869 if (ecom)
8870 ecommunity_free(&ecom);
8871
8872 return CMD_SUCCESS;
8873}
8874
505e5056 8875DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8876 address_family_ipv4_safi_cmd,
8877 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8878 "Enter Address Family command mode\n"
8879 "Address Family\n"
8880 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8881{
f51bae9c 8882
d62a17ae 8883 if (argc == 3) {
585f1adc
IR
8884 VTY_DECLVAR_CONTEXT(bgp, bgp);
8885 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8886 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 8887 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8888 && safi != SAFI_EVPN) {
31947174
MK
8889 vty_out(vty,
8890 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8891 return CMD_WARNING_CONFIG_FAILED;
8892 }
585f1adc
IR
8893 vty->node = bgp_node_type(AFI_IP, safi);
8894 } else
8895 vty->node = BGP_IPV4_NODE;
718e3744 8896
d62a17ae 8897 return CMD_SUCCESS;
718e3744 8898}
8899
505e5056 8900DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8901 address_family_ipv6_safi_cmd,
8902 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8903 "Enter Address Family command mode\n"
8904 "Address Family\n"
8905 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8906{
d62a17ae 8907 if (argc == 3) {
585f1adc
IR
8908 VTY_DECLVAR_CONTEXT(bgp, bgp);
8909 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
8910 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 8911 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8912 && safi != SAFI_EVPN) {
31947174
MK
8913 vty_out(vty,
8914 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8915 return CMD_WARNING_CONFIG_FAILED;
8916 }
585f1adc
IR
8917 vty->node = bgp_node_type(AFI_IP6, safi);
8918 } else
8919 vty->node = BGP_IPV6_NODE;
25ffbdc1 8920
d62a17ae 8921 return CMD_SUCCESS;
25ffbdc1 8922}
718e3744 8923
d6902373 8924#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8925DEFUN_NOSH (address_family_vpnv4,
718e3744 8926 address_family_vpnv4_cmd,
8334fd5a 8927 "address-family vpnv4 [unicast]",
718e3744 8928 "Enter Address Family command mode\n"
8c3deaae 8929 "Address Family\n"
3a2d747c 8930 "Address Family modifier\n")
718e3744 8931{
d62a17ae 8932 vty->node = BGP_VPNV4_NODE;
8933 return CMD_SUCCESS;
718e3744 8934}
8935
505e5056 8936DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8937 address_family_vpnv6_cmd,
8334fd5a 8938 "address-family vpnv6 [unicast]",
8ecd3266 8939 "Enter Address Family command mode\n"
8c3deaae 8940 "Address Family\n"
3a2d747c 8941 "Address Family modifier\n")
8ecd3266 8942{
d62a17ae 8943 vty->node = BGP_VPNV6_NODE;
8944 return CMD_SUCCESS;
8ecd3266 8945}
64e4a6c5 8946#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8947
505e5056 8948DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8949 address_family_evpn_cmd,
7111c1a0 8950 "address-family l2vpn evpn",
4e0b7b6d 8951 "Enter Address Family command mode\n"
7111c1a0
QY
8952 "Address Family\n"
8953 "Address Family modifier\n")
4e0b7b6d 8954{
2131d5cf 8955 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8956 vty->node = BGP_EVPN_NODE;
8957 return CMD_SUCCESS;
4e0b7b6d
PG
8958}
8959
bfaab44d
HS
8960DEFUN_NOSH (bgp_segment_routing_srv6,
8961 bgp_segment_routing_srv6_cmd,
8962 "segment-routing srv6",
8963 "Segment-Routing configuration\n"
8964 "Segment-Routing SRv6 configuration\n")
8965{
8966 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 8967 bgp->srv6_enabled = true;
bfaab44d
HS
8968 vty->node = BGP_SRV6_NODE;
8969 return CMD_SUCCESS;
8970}
8971
a0281b2e
HS
8972DEFPY (bgp_srv6_locator,
8973 bgp_srv6_locator_cmd,
8974 "locator NAME$name",
8975 "Specify SRv6 locator\n"
8976 "Specify SRv6 locator\n")
8977{
8978 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 8979 int ret;
a0281b2e
HS
8980
8981 if (strlen(bgp->srv6_locator_name) > 0
8982 && strcmp(name, bgp->srv6_locator_name) != 0) {
8983 vty_out(vty, "srv6 locator is already configured\n");
8984 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
8985 }
8986
8987 snprintf(bgp->srv6_locator_name,
8988 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 8989
7de4c885 8990 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
8991 if (ret < 0)
8992 return CMD_WARNING_CONFIG_FAILED;
8993
8994 return CMD_SUCCESS;
8995}
8996
ea372e81
HS
8997DEFPY (show_bgp_srv6,
8998 show_bgp_srv6_cmd,
8999 "show bgp segment-routing srv6",
9000 SHOW_STR
9001 BGP_STR
9002 "BGP Segment Routing\n"
9003 "BGP Segment Routing SRv6\n")
9004{
9005 struct bgp *bgp;
9006 struct listnode *node;
9007 struct prefix_ipv6 *chunk;
9008 struct bgp_srv6_function *func;
9009 struct in6_addr *tovpn4_sid;
9010 struct in6_addr *tovpn6_sid;
9011 char buf[256];
9012 char buf_tovpn4_sid[256];
9013 char buf_tovpn6_sid[256];
9014
9015 bgp = bgp_get_default();
96db4340 9016 if (!bgp)
ea372e81
HS
9017 return CMD_SUCCESS;
9018
9019 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9020 vty_out(vty, "locator_chunks:\n");
9021 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
9022 prefix2str(chunk, buf, sizeof(buf));
9023 vty_out(vty, "- %s\n", buf);
9024 }
9025
9026 vty_out(vty, "functions:\n");
9027 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9028 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9029 vty_out(vty, "- sid: %s\n", buf);
9030 vty_out(vty, " locator: %s\n", func->locator_name);
9031 }
9032
9033 vty_out(vty, "bgps:\n");
9034 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9035 vty_out(vty, "- name: %s\n",
9036 bgp->name ? bgp->name : "default");
9037
9038 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9039 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9040 if (tovpn4_sid)
9041 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9042 sizeof(buf_tovpn4_sid));
9043 if (tovpn6_sid)
9044 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9045 sizeof(buf_tovpn6_sid));
9046
9047 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9048 tovpn4_sid ? buf_tovpn4_sid : "none");
9049 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9050 tovpn6_sid ? buf_tovpn6_sid : "none");
9051 }
9052
9053 return CMD_SUCCESS;
9054}
9055
505e5056 9056DEFUN_NOSH (exit_address_family,
718e3744 9057 exit_address_family_cmd,
9058 "exit-address-family",
9059 "Exit from Address Family configuration mode\n")
9060{
d62a17ae 9061 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9062 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9063 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9064 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9065 || vty->node == BGP_EVPN_NODE
9066 || vty->node == BGP_FLOWSPECV4_NODE
9067 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9068 vty->node = BGP_NODE;
9069 return CMD_SUCCESS;
718e3744 9070}
6b0655a2 9071
8ad7271d 9072/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9073static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9074 const char *ip_str, afi_t afi, safi_t safi,
9075 struct prefix_rd *prd)
9076{
9077 int ret;
9078 struct prefix match;
9bcb3eef
DS
9079 struct bgp_dest *dest;
9080 struct bgp_dest *rm;
d62a17ae 9081 struct bgp *bgp;
9082 struct bgp_table *table;
9083 struct bgp_table *rib;
9084
9085 /* BGP structure lookup. */
9086 if (view_name) {
9087 bgp = bgp_lookup_by_name(view_name);
9088 if (bgp == NULL) {
9089 vty_out(vty, "%% Can't find BGP instance %s\n",
9090 view_name);
9091 return CMD_WARNING;
9092 }
9093 } else {
9094 bgp = bgp_get_default();
9095 if (bgp == NULL) {
9096 vty_out(vty, "%% No BGP process is configured\n");
9097 return CMD_WARNING;
9098 }
9099 }
9100
9101 /* Check IP address argument. */
9102 ret = str2prefix(ip_str, &match);
9103 if (!ret) {
9104 vty_out(vty, "%% address is malformed\n");
9105 return CMD_WARNING;
9106 }
9107
9108 match.family = afi2family(afi);
9109 rib = bgp->rib[afi][safi];
9110
9111 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9112 for (dest = bgp_table_top(rib); dest;
9113 dest = bgp_route_next(dest)) {
9114 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9115
9bcb3eef 9116 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9117 continue;
9118
9bcb3eef 9119 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9120 if (table == NULL)
9121 continue;
9122
4953391b
DA
9123 rm = bgp_node_match(table, &match);
9124 if (rm != NULL) {
b54892e0 9125 const struct prefix *rm_p =
9bcb3eef 9126 bgp_dest_get_prefix(rm);
b54892e0
DS
9127
9128 if (rm_p->prefixlen == match.prefixlen) {
9129 SET_FLAG(rm->flags,
9130 BGP_NODE_USER_CLEAR);
9131 bgp_process(bgp, rm, afi, safi);
d62a17ae 9132 }
9bcb3eef 9133 bgp_dest_unlock_node(rm);
d62a17ae 9134 }
9135 }
9136 } else {
4953391b
DA
9137 dest = bgp_node_match(rib, &match);
9138 if (dest != NULL) {
9bcb3eef 9139 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9140
9bcb3eef
DS
9141 if (dest_p->prefixlen == match.prefixlen) {
9142 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9143 bgp_process(bgp, dest, afi, safi);
d62a17ae 9144 }
9bcb3eef 9145 bgp_dest_unlock_node(dest);
d62a17ae 9146 }
9147 }
9148
9149 return CMD_SUCCESS;
8ad7271d
DS
9150}
9151
b09b5ae0 9152/* one clear bgp command to rule them all */
718e3744 9153DEFUN (clear_ip_bgp_all,
9154 clear_ip_bgp_all_cmd,
453c92f6 9155 "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 9156 CLEAR_STR
9157 IP_STR
9158 BGP_STR
838758ac 9159 BGP_INSTANCE_HELP_STR
510afcd6 9160 BGP_AFI_HELP_STR
fd5e7b70 9161 "Address Family\n"
510afcd6 9162 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9163 "Address Family modifier\n"
b09b5ae0 9164 "Clear all peers\n"
453c92f6 9165 "BGP IPv4 neighbor to clear\n"
a80beece 9166 "BGP IPv6 neighbor to clear\n"
838758ac 9167 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9168 "Clear peers with the AS number\n"
9169 "Clear all external peers\n"
718e3744 9170 "Clear all members of peer-group\n"
b09b5ae0 9171 "BGP peer-group name\n"
b09b5ae0
DW
9172 BGP_SOFT_STR
9173 BGP_SOFT_IN_STR
b09b5ae0
DW
9174 BGP_SOFT_OUT_STR
9175 BGP_SOFT_IN_STR
9176 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9177 BGP_SOFT_OUT_STR)
718e3744 9178{
d62a17ae 9179 char *vrf = NULL;
9180
dc912615
DS
9181 afi_t afi = AFI_UNSPEC;
9182 safi_t safi = SAFI_UNSPEC;
d62a17ae 9183 enum clear_sort clr_sort = clear_peer;
9184 enum bgp_clear_type clr_type;
9185 char *clr_arg = NULL;
9186
9187 int idx = 0;
9188
9189 /* clear [ip] bgp */
9190 if (argv_find(argv, argc, "ip", &idx))
9191 afi = AFI_IP;
9192
9a8bdf1c
PG
9193 /* [<vrf> VIEWVRFNAME] */
9194 if (argv_find(argv, argc, "vrf", &idx)) {
9195 vrf = argv[idx + 1]->arg;
9196 idx += 2;
9197 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9198 vrf = NULL;
9199 } else if (argv_find(argv, argc, "view", &idx)) {
9200 /* [<view> VIEWVRFNAME] */
d62a17ae 9201 vrf = argv[idx + 1]->arg;
9202 idx += 2;
9203 }
d62a17ae 9204 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9205 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9206 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9207
d7b9898c 9208 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9209 if (argv_find(argv, argc, "*", &idx)) {
9210 clr_sort = clear_all;
9211 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9212 clr_sort = clear_peer;
9213 clr_arg = argv[idx]->arg;
9214 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9215 clr_sort = clear_peer;
9216 clr_arg = argv[idx]->arg;
9217 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9218 clr_sort = clear_group;
9219 idx++;
9220 clr_arg = argv[idx]->arg;
d7b9898c 9221 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9222 clr_sort = clear_peer;
9223 clr_arg = argv[idx]->arg;
8fa7d444
DS
9224 } else if (argv_find(argv, argc, "WORD", &idx)) {
9225 clr_sort = clear_peer;
9226 clr_arg = argv[idx]->arg;
d62a17ae 9227 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9228 clr_sort = clear_as;
9229 clr_arg = argv[idx]->arg;
9230 } else if (argv_find(argv, argc, "external", &idx)) {
9231 clr_sort = clear_external;
9232 }
9233
9234 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9235 if (argv_find(argv, argc, "soft", &idx)) {
9236 if (argv_find(argv, argc, "in", &idx)
9237 || argv_find(argv, argc, "out", &idx))
9238 clr_type = strmatch(argv[idx]->text, "in")
9239 ? BGP_CLEAR_SOFT_IN
9240 : BGP_CLEAR_SOFT_OUT;
9241 else
9242 clr_type = BGP_CLEAR_SOFT_BOTH;
9243 } else if (argv_find(argv, argc, "in", &idx)) {
9244 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9245 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9246 : BGP_CLEAR_SOFT_IN;
9247 } else if (argv_find(argv, argc, "out", &idx)) {
9248 clr_type = BGP_CLEAR_SOFT_OUT;
9249 } else
9250 clr_type = BGP_CLEAR_SOFT_NONE;
9251
1ca2fd11 9252 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9253}
01080f7c 9254
8ad7271d
DS
9255DEFUN (clear_ip_bgp_prefix,
9256 clear_ip_bgp_prefix_cmd,
18c57037 9257 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9258 CLEAR_STR
9259 IP_STR
9260 BGP_STR
838758ac 9261 BGP_INSTANCE_HELP_STR
8ad7271d 9262 "Clear bestpath and re-advertise\n"
0c7b1b01 9263 "IPv4 prefix\n")
8ad7271d 9264{
d62a17ae 9265 char *vrf = NULL;
9266 char *prefix = NULL;
8ad7271d 9267
d62a17ae 9268 int idx = 0;
01080f7c 9269
d62a17ae 9270 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9271 if (argv_find(argv, argc, "vrf", &idx)) {
9272 vrf = argv[idx + 1]->arg;
9273 idx += 2;
9274 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9275 vrf = NULL;
9276 } else if (argv_find(argv, argc, "view", &idx)) {
9277 /* [<view> VIEWVRFNAME] */
9278 vrf = argv[idx + 1]->arg;
9279 idx += 2;
9280 }
0c7b1b01 9281
d62a17ae 9282 prefix = argv[argc - 1]->arg;
8ad7271d 9283
d62a17ae 9284 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9285}
8ad7271d 9286
b09b5ae0
DW
9287DEFUN (clear_bgp_ipv6_safi_prefix,
9288 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9289 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9290 CLEAR_STR
3a2d747c 9291 IP_STR
718e3744 9292 BGP_STR
8c3deaae 9293 "Address Family\n"
46f296b4 9294 BGP_SAFI_HELP_STR
b09b5ae0 9295 "Clear bestpath and re-advertise\n"
0c7b1b01 9296 "IPv6 prefix\n")
718e3744 9297{
9b475e76
PG
9298 int idx_safi = 0;
9299 int idx_ipv6_prefix = 0;
9300 safi_t safi = SAFI_UNICAST;
9301 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9302 argv[idx_ipv6_prefix]->arg : NULL;
9303
9304 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9305 return bgp_clear_prefix(
9b475e76
PG
9306 vty, NULL, prefix, AFI_IP6,
9307 safi, NULL);
838758ac 9308}
01080f7c 9309
b09b5ae0
DW
9310DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9311 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9312 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9313 CLEAR_STR
3a2d747c 9314 IP_STR
718e3744 9315 BGP_STR
838758ac 9316 BGP_INSTANCE_HELP_STR
8c3deaae 9317 "Address Family\n"
46f296b4 9318 BGP_SAFI_HELP_STR
b09b5ae0 9319 "Clear bestpath and re-advertise\n"
0c7b1b01 9320 "IPv6 prefix\n")
718e3744 9321{
9b475e76 9322 int idx_safi = 0;
9a8bdf1c 9323 int idx_vrfview = 0;
9b475e76
PG
9324 int idx_ipv6_prefix = 0;
9325 safi_t safi = SAFI_UNICAST;
9326 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9327 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9328 char *vrfview = NULL;
9b475e76 9329
9a8bdf1c
PG
9330 /* [<view|vrf> VIEWVRFNAME] */
9331 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9332 vrfview = argv[idx_vrfview + 1]->arg;
9333 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9334 vrfview = NULL;
9335 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9336 /* [<view> VIEWVRFNAME] */
9337 vrfview = argv[idx_vrfview + 1]->arg;
9338 }
9b475e76
PG
9339 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9340
d62a17ae 9341 return bgp_clear_prefix(
9b475e76
PG
9342 vty, vrfview, prefix,
9343 AFI_IP6, safi, NULL);
718e3744 9344}
9345
b09b5ae0
DW
9346DEFUN (show_bgp_views,
9347 show_bgp_views_cmd,
d6e3c605 9348 "show [ip] bgp views",
b09b5ae0 9349 SHOW_STR
d6e3c605 9350 IP_STR
01080f7c 9351 BGP_STR
b09b5ae0 9352 "Show the defined BGP views\n")
01080f7c 9353{
d62a17ae 9354 struct list *inst = bm->bgp;
9355 struct listnode *node;
9356 struct bgp *bgp;
01080f7c 9357
d62a17ae 9358 vty_out(vty, "Defined BGP views:\n");
9359 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9360 /* Skip VRFs. */
9361 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9362 continue;
9363 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9364 bgp->as);
9365 }
e52702f2 9366
d62a17ae 9367 return CMD_SUCCESS;
e0081f70
ML
9368}
9369
8386ac43 9370DEFUN (show_bgp_vrfs,
9371 show_bgp_vrfs_cmd,
d6e3c605 9372 "show [ip] bgp vrfs [json]",
8386ac43 9373 SHOW_STR
d6e3c605 9374 IP_STR
8386ac43 9375 BGP_STR
9376 "Show BGP VRFs\n"
9973d184 9377 JSON_STR)
8386ac43 9378{
fe1dc5a3 9379 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9380 struct list *inst = bm->bgp;
9381 struct listnode *node;
9382 struct bgp *bgp;
9f049418 9383 bool uj = use_json(argc, argv);
d62a17ae 9384 json_object *json = NULL;
9385 json_object *json_vrfs = NULL;
9386 int count = 0;
d62a17ae 9387
d62a17ae 9388 if (uj) {
9389 json = json_object_new_object();
9390 json_vrfs = json_object_new_object();
9391 }
9392
9393 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9394 const char *name, *type;
9395 struct peer *peer;
7fe96307 9396 struct listnode *node2, *nnode2;
d62a17ae 9397 int peers_cfg, peers_estb;
9398 json_object *json_vrf = NULL;
d62a17ae 9399
9400 /* Skip Views. */
9401 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9402 continue;
9403
9404 count++;
efb4077a 9405 if (!uj && count == 1) {
fe1dc5a3 9406 vty_out(vty,
efb4077a 9407 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9408 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9409 "#PeersEstb", "Name");
9410 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9411 "L3-VNI", "RouterMAC", "Interface");
9412 }
d62a17ae 9413
9414 peers_cfg = peers_estb = 0;
9415 if (uj)
9416 json_vrf = json_object_new_object();
9417
9418
7fe96307 9419 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9420 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9421 continue;
9422 peers_cfg++;
feb17238 9423 if (peer_established(peer))
d62a17ae 9424 peers_estb++;
9425 }
9426
9427 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9428 name = VRF_DEFAULT_NAME;
d62a17ae 9429 type = "DFLT";
9430 } else {
9431 name = bgp->name;
9432 type = "VRF";
9433 }
9434
a8bf7d9c 9435
d62a17ae 9436 if (uj) {
a4d82a8a
PZ
9437 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9438 ? -1
9439 : (int64_t)bgp->vrf_id;
23d0a753
DA
9440 char buf[BUFSIZ] = {0};
9441
d62a17ae 9442 json_object_string_add(json_vrf, "type", type);
9443 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9444 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
9445 inet_ntop(AF_INET,
9446 &bgp->router_id, buf,
9447 sizeof(buf)));
d62a17ae 9448 json_object_int_add(json_vrf, "numConfiguredPeers",
9449 peers_cfg);
9450 json_object_int_add(json_vrf, "numEstablishedPeers",
9451 peers_estb);
9452
fe1dc5a3 9453 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9454 json_object_string_add(
9455 json_vrf, "rmac",
9456 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9457 json_object_string_add(json_vrf, "interface",
9458 ifindex2ifname(bgp->l3vni_svi_ifindex,
9459 bgp->vrf_id));
d62a17ae 9460 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9461 } else {
23d0a753 9462 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9463 type,
9464 bgp->vrf_id == VRF_UNKNOWN ? -1
9465 : (int)bgp->vrf_id,
23d0a753 9466 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9467 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9468 bgp->l3vni,
9469 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9470 ifindex2ifname(bgp->l3vni_svi_ifindex,
9471 bgp->vrf_id));
9472 }
d62a17ae 9473 }
9474
9475 if (uj) {
9476 json_object_object_add(json, "vrfs", json_vrfs);
9477
9478 json_object_int_add(json, "totalVrfs", count);
9479
996c9314
LB
9480 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9481 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9482 json_object_free(json);
9483 } else {
9484 if (count)
9485 vty_out(vty,
9486 "\nTotal number of VRFs (including default): %d\n",
9487 count);
9488 }
9489
9490 return CMD_SUCCESS;
8386ac43 9491}
9492
48ecf8f5
DS
9493DEFUN (show_bgp_mac_hash,
9494 show_bgp_mac_hash_cmd,
9495 "show bgp mac hash",
9496 SHOW_STR
9497 BGP_STR
9498 "Mac Address\n"
9499 "Mac Address database\n")
9500{
9501 bgp_mac_dump_table(vty);
9502
9503 return CMD_SUCCESS;
9504}
acf71666 9505
e3b78da8 9506static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9507{
0291c246 9508 struct vty *vty = (struct vty *)args;
e3b78da8 9509 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9510
23d0a753 9511 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9512}
9513
9514static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9515{
9516 vty_out(vty, "self nexthop database:\n");
af97a18b 9517 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9518
9519 vty_out(vty, "Tunnel-ip database:\n");
9520 hash_iterate(bgp->tip_hash,
e3b78da8 9521 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9522 vty);
9523}
9524
15c81ca4
DS
9525DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9526 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9527 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9528 "martian next-hops\n"
9529 "martian next-hop database\n")
acf71666 9530{
0291c246 9531 struct bgp *bgp = NULL;
15c81ca4 9532 int idx = 0;
9a8bdf1c
PG
9533 char *name = NULL;
9534
9535 /* [<vrf> VIEWVRFNAME] */
9536 if (argv_find(argv, argc, "vrf", &idx)) {
9537 name = argv[idx + 1]->arg;
9538 if (name && strmatch(name, VRF_DEFAULT_NAME))
9539 name = NULL;
9540 } else if (argv_find(argv, argc, "view", &idx))
9541 /* [<view> VIEWVRFNAME] */
9542 name = argv[idx + 1]->arg;
9543 if (name)
9544 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9545 else
9546 bgp = bgp_get_default();
acf71666 9547
acf71666
MK
9548 if (!bgp) {
9549 vty_out(vty, "%% No BGP process is configured\n");
9550 return CMD_WARNING;
9551 }
9552 bgp_show_martian_nexthops(vty, bgp);
9553
9554 return CMD_SUCCESS;
9555}
9556
f412b39a 9557DEFUN (show_bgp_memory,
4bf6a362 9558 show_bgp_memory_cmd,
7fa12b13 9559 "show [ip] bgp memory",
4bf6a362 9560 SHOW_STR
3a2d747c 9561 IP_STR
4bf6a362
PJ
9562 BGP_STR
9563 "Global BGP memory statistics\n")
9564{
d62a17ae 9565 char memstrbuf[MTYPE_MEMSTR_LEN];
9566 unsigned long count;
9567
9568 /* RIB related usage stats */
9569 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9570 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9571 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9572 count * sizeof(struct bgp_dest)));
d62a17ae 9573
9574 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9575 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9576 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9577 count * sizeof(struct bgp_path_info)));
d62a17ae 9578 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9579 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9580 count,
4b7e6066
DS
9581 mtype_memstr(
9582 memstrbuf, sizeof(memstrbuf),
9583 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9584
9585 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9586 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9587 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9588 count * sizeof(struct bgp_static)));
9589
9590 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9591 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9592 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9593 count * sizeof(struct bpacket)));
9594
9595 /* Adj-In/Out */
9596 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9597 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9598 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9599 count * sizeof(struct bgp_adj_in)));
9600 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9601 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9602 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9603 count * sizeof(struct bgp_adj_out)));
9604
9605 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9606 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9607 count,
9608 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9609 count * sizeof(struct bgp_nexthop_cache)));
9610
9611 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9612 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9613 count,
9614 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9615 count * sizeof(struct bgp_damp_info)));
9616
9617 /* Attributes */
9618 count = attr_count();
9619 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9620 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9621 count * sizeof(struct attr)));
9622
9623 if ((count = attr_unknown_count()))
9624 vty_out(vty, "%ld unknown attributes\n", count);
9625
9626 /* AS_PATH attributes */
9627 count = aspath_count();
9628 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9629 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9630 count * sizeof(struct aspath)));
9631
9632 count = mtype_stats_alloc(MTYPE_AS_SEG);
9633 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9634 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9635 count * sizeof(struct assegment)));
9636
9637 /* Other attributes */
9638 if ((count = community_count()))
9639 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9640 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9641 count * sizeof(struct community)));
d62a17ae 9642 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9643 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9644 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9645 count * sizeof(struct ecommunity)));
d62a17ae 9646 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9647 vty_out(vty,
9648 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9649 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9650 count * sizeof(struct lcommunity)));
d62a17ae 9651
9652 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9653 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9655 count * sizeof(struct cluster_list)));
9656
9657 /* Peer related usage */
9658 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9659 vty_out(vty, "%ld peers, using %s of memory\n", count,
9660 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9661 count * sizeof(struct peer)));
9662
9663 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9664 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9666 count * sizeof(struct peer_group)));
9667
9668 /* Other */
d62a17ae 9669 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9670 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9671 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9672 count * sizeof(regex_t)));
d62a17ae 9673 return CMD_SUCCESS;
4bf6a362 9674}
fee0f4c6 9675
57a9c8a8
DS
9676static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9677{
9678 json_object *bestpath = json_object_new_object();
9679
892fedb6 9680 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9681 json_object_string_add(bestpath, "asPath", "ignore");
9682
892fedb6 9683 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9684 json_object_string_add(bestpath, "asPath", "confed");
9685
892fedb6
DA
9686 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9687 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9688 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9689 "as-set");
9690 else
a4d82a8a 9691 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9692 "true");
9693 } else
a4d82a8a 9694 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9695
ee88563a
JM
9696 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
9697 json_object_boolean_true_add(bestpath, "peerTypeRelax");
9698
892fedb6 9699 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9700 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9701 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9702 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9703 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9704 json_object_string_add(bestpath, "med", "confed");
892fedb6 9705 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9706 json_object_string_add(bestpath, "med",
9707 "missing-as-worst");
9708 else
9709 json_object_string_add(bestpath, "med", "true");
9710 }
9711
9712 json_object_object_add(json, "bestPath", bestpath);
9713}
9714
3577f1c5
DD
9715/* Print the error code/subcode for why the peer is down */
9716static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9717 json_object *json_peer, bool use_json)
9718{
9719 const char *code_str;
9720 const char *subcode_str;
9721
9722 if (use_json) {
9723 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9724 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9725 char errorcodesubcode_hexstr[5];
9726 char errorcodesubcode_str[256];
9727
9728 code_str = bgp_notify_code_str(peer->notify.code);
9729 subcode_str = bgp_notify_subcode_str(
9730 peer->notify.code,
9731 peer->notify.subcode);
9732
772270f3
QY
9733 snprintf(errorcodesubcode_hexstr,
9734 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9735 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
9736 json_object_string_add(json_peer,
9737 "lastErrorCodeSubcode",
9738 errorcodesubcode_hexstr);
9739 snprintf(errorcodesubcode_str, 255, "%s%s",
9740 code_str, subcode_str);
9741 json_object_string_add(json_peer,
9742 "lastNotificationReason",
9743 errorcodesubcode_str);
9744 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9745 && peer->notify.code == BGP_NOTIFY_CEASE
9746 && (peer->notify.subcode
9747 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9748 || peer->notify.subcode
9749 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9750 && peer->notify.length) {
9751 char msgbuf[1024];
9752 const char *msg_str;
9753
9754 msg_str = bgp_notify_admin_message(
9755 msgbuf, sizeof(msgbuf),
9756 (uint8_t *)peer->notify.data,
9757 peer->notify.length);
9758 if (msg_str)
9759 json_object_string_add(
9760 json_peer,
9761 "lastShutdownDescription",
9762 msg_str);
9763 }
9764
c258527b 9765 }
3577f1c5
DD
9766 json_object_string_add(json_peer, "lastResetDueTo",
9767 peer_down_str[(int)peer->last_reset]);
05912a17
DD
9768 json_object_int_add(json_peer, "lastResetCode",
9769 peer->last_reset);
3577f1c5
DD
9770 } else {
9771 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9772 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9773 code_str = bgp_notify_code_str(peer->notify.code);
9774 subcode_str =
9775 bgp_notify_subcode_str(peer->notify.code,
9776 peer->notify.subcode);
9777 vty_out(vty, " Notification %s (%s%s)\n",
9778 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9779 ? "sent"
9780 : "received",
9781 code_str, subcode_str);
9782 } else {
e91c24c8 9783 vty_out(vty, " %s\n",
3577f1c5
DD
9784 peer_down_str[(int)peer->last_reset]);
9785 }
9786 }
9787}
9788
9789static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9790 safi_t safi)
9791{
feb17238 9792 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
9793}
9794
9795static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9796 struct peer *peer, json_object *json_peer,
9797 int max_neighbor_width, bool use_json)
9798{
9799 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9800 int len;
9801
9802 if (use_json) {
9803 if (peer_dynamic_neighbor(peer))
9804 json_object_boolean_true_add(json_peer,
9805 "dynamicPeer");
9806 if (peer->hostname)
9807 json_object_string_add(json_peer, "hostname",
9808 peer->hostname);
9809
9810 if (peer->domainname)
9811 json_object_string_add(json_peer, "domainname",
9812 peer->domainname);
9813 json_object_int_add(json_peer, "connectionsEstablished",
9814 peer->established);
9815 json_object_int_add(json_peer, "connectionsDropped",
9816 peer->dropped);
9817 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9818 use_json, json_peer);
feb17238 9819 if (peer_established(peer))
3577f1c5
DD
9820 json_object_string_add(json_peer, "lastResetDueTo",
9821 "AFI/SAFI Not Negotiated");
9822 else
9823 bgp_show_peer_reset(NULL, peer, json_peer, true);
9824 } else {
9825 dn_flag[1] = '\0';
9826 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9827 if (peer->hostname
892fedb6 9828 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
9829 len = vty_out(vty, "%s%s(%s)", dn_flag,
9830 peer->hostname, peer->host);
9831 else
9832 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9833
9834 /* pad the neighbor column with spaces */
9835 if (len < max_neighbor_width)
9836 vty_out(vty, "%*s", max_neighbor_width - len,
9837 " ");
e91c24c8 9838 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
9839 peer->dropped,
9840 peer_uptime(peer->uptime, timebuf,
9841 BGP_UPTIME_LEN, 0, NULL));
feb17238 9842 if (peer_established(peer))
3577f1c5
DD
9843 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9844 else
9845 bgp_show_peer_reset(vty, peer, NULL,
9846 false);
9847 }
9848}
c258527b 9849
cb75bb31
DA
9850/* If the peer's description includes whitespaces
9851 * then return the first occurrence. Also strip description
9852 * to the given size if needed.
9853 */
9854static char *bgp_peer_description_stripped(char *desc, uint32_t size)
9855{
9856 static char stripped[BUFSIZ];
9857 char *pnt;
9858 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
9859
9860 pnt = strchr(desc, ' ');
9861 if (pnt)
9862 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
9863 : size;
9864
9865 strlcpy(stripped, desc, len + 1);
9866
9867 return stripped;
9868}
3577f1c5 9869
8c1d4cd5
LS
9870/* Determine whether var peer should be filtered out of the summary. */
9871static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
9872 struct peer *fpeer, int as_type,
9873 as_t as)
9874{
9875
9876 /* filter neighbor XXXX */
9877 if (fpeer && fpeer != peer)
9878 return true;
9879
9880 /* filter remote-as (internal|external) */
9881 if (as_type != AS_UNSPECIFIED) {
9882 if (peer->as_type == AS_SPECIFIED) {
9883 if (as_type == AS_INTERNAL) {
9884 if (peer->as != peer->local_as)
9885 return true;
9886 } else if (peer->as == peer->local_as)
9887 return true;
9888 } else if (as_type != peer->as_type)
9889 return true;
9890 } else if (as && as != peer->as) /* filter remote-as XXX */
9891 return true;
9892
9893 return false;
9894}
9895
718e3744 9896/* Show BGP peer's summary information. */
d62a17ae 9897static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 9898 struct peer *fpeer, int as_type, as_t as,
96c81f66 9899 uint16_t show_flags)
d62a17ae 9900{
9901 struct peer *peer;
9902 struct listnode *node, *nnode;
9903 unsigned int count = 0, dn_count = 0;
9904 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9905 char neighbor_buf[VTY_BUFSIZ];
9906 int neighbor_col_default_width = 16;
3577f1c5 9907 int len, failed_count = 0;
ce1944f0 9908 unsigned int filtered_count = 0;
d62a17ae 9909 int max_neighbor_width = 0;
9910 int pfx_rcd_safi;
3c13337d 9911 json_object *json = NULL;
d62a17ae 9912 json_object *json_peer = NULL;
9913 json_object *json_peers = NULL;
50e05855 9914 struct peer_af *paf;
d3ada366 9915 struct bgp_filter *filter;
85eeb029
DA
9916 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
9917 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
9918 bool show_established =
9919 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
9920 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 9921 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 9922
9923 /* labeled-unicast routes are installed in the unicast table so in order
9924 * to
9925 * display the correct PfxRcd value we must look at SAFI_UNICAST
9926 */
3577f1c5 9927
d62a17ae 9928 if (safi == SAFI_LABELED_UNICAST)
9929 pfx_rcd_safi = SAFI_UNICAST;
9930 else
9931 pfx_rcd_safi = safi;
9932
9933 if (use_json) {
3c13337d 9934 json = json_object_new_object();
d62a17ae 9935 json_peers = json_object_new_object();
3577f1c5 9936 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
9937 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
9938 as_type, as)) {
ce1944f0 9939 filtered_count++;
8c1d4cd5
LS
9940 count++;
9941 continue;
9942 }
9943
3577f1c5
DD
9944 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9945 continue;
9946
9947 if (peer->afc[afi][safi]) {
9948 /* See if we have at least a single failed peer */
9949 if (bgp_has_peer_failed(peer, afi, safi))
9950 failed_count++;
9951 count++;
9952 }
9953 if (peer_dynamic_neighbor(peer))
9954 dn_count++;
9955 }
c258527b 9956
d62a17ae 9957 } else {
9958 /* Loop over all neighbors that will be displayed to determine
9959 * how many
9960 * characters are needed for the Neighbor column
9961 */
9962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
9963 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
9964 as_type, as)) {
ce1944f0 9965 filtered_count++;
8c1d4cd5
LS
9966 count++;
9967 continue;
9968 }
9969
d62a17ae 9970 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9971 continue;
9972
9973 if (peer->afc[afi][safi]) {
9974 memset(dn_flag, '\0', sizeof(dn_flag));
9975 if (peer_dynamic_neighbor(peer))
9976 dn_flag[0] = '*';
9977
9978 if (peer->hostname
892fedb6
DA
9979 && CHECK_FLAG(bgp->flags,
9980 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9981 snprintf(neighbor_buf,
9982 sizeof(neighbor_buf),
9983 "%s%s(%s) ", dn_flag,
9984 peer->hostname, peer->host);
d62a17ae 9985 else
772270f3
QY
9986 snprintf(neighbor_buf,
9987 sizeof(neighbor_buf), "%s%s ",
9988 dn_flag, peer->host);
d62a17ae 9989
9990 len = strlen(neighbor_buf);
9991
9992 if (len > max_neighbor_width)
9993 max_neighbor_width = len;
c258527b 9994
3577f1c5
DD
9995 /* See if we have at least a single failed peer */
9996 if (bgp_has_peer_failed(peer, afi, safi))
9997 failed_count++;
9998 count++;
d62a17ae 9999 }
10000 }
f933309e 10001
d62a17ae 10002 /* Originally we displayed the Neighbor column as 16
10003 * characters wide so make that the default
10004 */
10005 if (max_neighbor_width < neighbor_col_default_width)
10006 max_neighbor_width = neighbor_col_default_width;
10007 }
f933309e 10008
3577f1c5
DD
10009 if (show_failed && !failed_count) {
10010 if (use_json) {
10011 json_object_int_add(json, "failedPeersCount", 0);
10012 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10013 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10014
10015 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10016 json, JSON_C_TO_STRING_PRETTY));
10017 json_object_free(json);
10018 } else {
10019 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10020 }
10021 return CMD_SUCCESS;
10022 }
c258527b 10023
3577f1c5 10024 count = 0; /* Reset the value as its used again */
ce1944f0 10025 filtered_count = 0;
d62a17ae 10026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10027 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10028 continue;
10029
ea47320b
DL
10030 if (!peer->afc[afi][safi])
10031 continue;
d62a17ae 10032
ea47320b
DL
10033 if (!count) {
10034 unsigned long ents;
10035 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10036 int64_t vrf_id_ui;
d62a17ae 10037
a4d82a8a
PZ
10038 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10039 ? -1
10040 : (int64_t)bgp->vrf_id;
ea47320b
DL
10041
10042 /* Usage summary and header */
10043 if (use_json) {
23d0a753
DA
10044 char buf[BUFSIZ] = {0};
10045
ea47320b
DL
10046 json_object_string_add(
10047 json, "routerId",
23d0a753
DA
10048 inet_ntop(AF_INET, &bgp->router_id, buf,
10049 sizeof(buf)));
60466a63
QY
10050 json_object_int_add(json, "as", bgp->as);
10051 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10052 json_object_string_add(
10053 json, "vrfName",
10054 (bgp->inst_type
10055 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10056 ? VRF_DEFAULT_NAME
ea47320b
DL
10057 : bgp->name);
10058 } else {
10059 vty_out(vty,
23d0a753
DA
10060 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10061 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10062 bgp->vrf_id == VRF_UNKNOWN
10063 ? -1
10064 : (int)bgp->vrf_id);
ea47320b
DL
10065 vty_out(vty, "\n");
10066 }
d62a17ae 10067
ea47320b 10068 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10069 if (use_json) {
ea47320b 10070 json_object_int_add(
60466a63 10071 json, "updateDelayLimit",
ea47320b 10072 bgp->v_update_delay);
d62a17ae 10073
ea47320b
DL
10074 if (bgp->v_update_delay
10075 != bgp->v_establish_wait)
d62a17ae 10076 json_object_int_add(
10077 json,
ea47320b
DL
10078 "updateDelayEstablishWait",
10079 bgp->v_establish_wait);
d62a17ae 10080
60466a63 10081 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10082 json_object_string_add(
10083 json,
10084 "updateDelayFirstNeighbor",
10085 bgp->update_delay_begin_time);
10086 json_object_boolean_true_add(
10087 json,
10088 "updateDelayInProgress");
10089 } else {
10090 if (bgp->update_delay_over) {
d62a17ae 10091 json_object_string_add(
10092 json,
10093 "updateDelayFirstNeighbor",
10094 bgp->update_delay_begin_time);
ea47320b 10095 json_object_string_add(
d62a17ae 10096 json,
ea47320b
DL
10097 "updateDelayBestpathResumed",
10098 bgp->update_delay_end_time);
10099 json_object_string_add(
d62a17ae 10100 json,
ea47320b
DL
10101 "updateDelayZebraUpdateResume",
10102 bgp->update_delay_zebra_resume_time);
10103 json_object_string_add(
10104 json,
10105 "updateDelayPeerUpdateResume",
10106 bgp->update_delay_peers_resume_time);
d62a17ae 10107 }
ea47320b
DL
10108 }
10109 } else {
10110 vty_out(vty,
10111 "Read-only mode update-delay limit: %d seconds\n",
10112 bgp->v_update_delay);
10113 if (bgp->v_update_delay
10114 != bgp->v_establish_wait)
d62a17ae 10115 vty_out(vty,
ea47320b
DL
10116 " Establish wait: %d seconds\n",
10117 bgp->v_establish_wait);
d62a17ae 10118
60466a63 10119 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10120 vty_out(vty,
10121 " First neighbor established: %s\n",
10122 bgp->update_delay_begin_time);
10123 vty_out(vty,
10124 " Delay in progress\n");
10125 } else {
10126 if (bgp->update_delay_over) {
d62a17ae 10127 vty_out(vty,
10128 " First neighbor established: %s\n",
10129 bgp->update_delay_begin_time);
10130 vty_out(vty,
ea47320b
DL
10131 " Best-paths resumed: %s\n",
10132 bgp->update_delay_end_time);
10133 vty_out(vty,
10134 " zebra update resumed: %s\n",
10135 bgp->update_delay_zebra_resume_time);
10136 vty_out(vty,
10137 " peers update resumed: %s\n",
10138 bgp->update_delay_peers_resume_time);
d62a17ae 10139 }
10140 }
10141 }
ea47320b 10142 }
d62a17ae 10143
ea47320b
DL
10144 if (use_json) {
10145 if (bgp_maxmed_onstartup_configured(bgp)
10146 && bgp->maxmed_active)
10147 json_object_boolean_true_add(
60466a63 10148 json, "maxMedOnStartup");
ea47320b
DL
10149 if (bgp->v_maxmed_admin)
10150 json_object_boolean_true_add(
60466a63 10151 json, "maxMedAdministrative");
d62a17ae 10152
ea47320b
DL
10153 json_object_int_add(
10154 json, "tableVersion",
60466a63 10155 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10156
60466a63
QY
10157 ents = bgp_table_count(bgp->rib[afi][safi]);
10158 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10159 json_object_int_add(
10160 json, "ribMemory",
9bcb3eef 10161 ents * sizeof(struct bgp_dest));
d62a17ae 10162
210ec2a0 10163 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10164 json_object_int_add(json, "peerCount", ents);
10165 json_object_int_add(json, "peerMemory",
10166 ents * sizeof(struct peer));
d62a17ae 10167
ea47320b
DL
10168 if ((ents = listcount(bgp->group))) {
10169 json_object_int_add(
60466a63 10170 json, "peerGroupCount", ents);
ea47320b
DL
10171 json_object_int_add(
10172 json, "peerGroupMemory",
996c9314
LB
10173 ents * sizeof(struct
10174 peer_group));
ea47320b 10175 }
d62a17ae 10176
ea47320b
DL
10177 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10178 BGP_CONFIG_DAMPENING))
10179 json_object_boolean_true_add(
60466a63 10180 json, "dampeningEnabled");
ea47320b 10181 } else {
96c81f66
LS
10182 if (!show_terse) {
10183 if (bgp_maxmed_onstartup_configured(bgp)
10184 && bgp->maxmed_active)
10185 vty_out(vty,
10186 "Max-med on-startup active\n");
10187 if (bgp->v_maxmed_admin)
10188 vty_out(vty,
10189 "Max-med administrative active\n");
d62a17ae 10190
96c81f66
LS
10191 vty_out(vty,
10192 "BGP table version %" PRIu64
10193 "\n",
10194 bgp_table_version(
10195 bgp->rib[afi][safi]));
ea47320b 10196
96c81f66
LS
10197 ents = bgp_table_count(
10198 bgp->rib[afi][safi]);
d62a17ae 10199 vty_out(vty,
96c81f66 10200 "RIB entries %ld, using %s of memory\n",
d62a17ae 10201 ents,
10202 mtype_memstr(
10203 memstrbuf,
10204 sizeof(memstrbuf),
96c81f66
LS
10205 ents
10206 * sizeof(
10207 struct
10208 bgp_dest)));
d62a17ae 10209
96c81f66
LS
10210 /* Peer related usage */
10211 ents = bgp->af_peer_count[afi][safi];
10212 vty_out(vty,
10213 "Peers %ld, using %s of memory\n",
10214 ents,
10215 mtype_memstr(
10216 memstrbuf,
10217 sizeof(memstrbuf),
10218 ents
10219 * sizeof(
10220 struct
10221 peer)));
d62a17ae 10222
96c81f66
LS
10223 if ((ents = listcount(bgp->group)))
10224 vty_out(vty,
10225 "Peer groups %ld, using %s of memory\n",
10226 ents,
10227 mtype_memstr(
10228 memstrbuf,
10229 sizeof(memstrbuf),
10230 ents
10231 * sizeof(
10232 struct
10233 peer_group)));
10234
10235 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10236 BGP_CONFIG_DAMPENING))
10237 vty_out(vty,
10238 "Dampening enabled.\n");
10239 }
10240 if (show_failed) {
10241 vty_out(vty, "\n");
10242
10243 /* Subtract 8 here because 'Neighbor' is
10244 * 8 characters */
10245 vty_out(vty, "Neighbor");
10246 vty_out(vty, "%*s",
10247 max_neighbor_width - 8, " ");
85eeb029
DA
10248 vty_out(vty,
10249 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10250 }
d62a17ae 10251 }
ea47320b 10252 }
d62a17ae 10253
d55811cc 10254 paf = peer_af_find(peer, afi, safi);
d3ada366 10255 filter = &peer->filter[afi][safi];
db92d226 10256
ea47320b 10257 count++;
3577f1c5
DD
10258 /* Works for both failed & successful cases */
10259 if (peer_dynamic_neighbor(peer))
10260 dn_count++;
d62a17ae 10261
ea47320b 10262 if (use_json) {
3577f1c5 10263 json_peer = NULL;
8c1d4cd5 10264 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10265 as_type, as)) {
10266 filtered_count++;
8c1d4cd5 10267 continue;
ce1944f0 10268 }
3577f1c5
DD
10269 if (show_failed &&
10270 bgp_has_peer_failed(peer, afi, safi)) {
10271 json_peer = json_object_new_object();
10272 bgp_show_failed_summary(vty, bgp, peer,
10273 json_peer, 0, use_json);
10274 } else if (!show_failed) {
10b49f14 10275 if (show_established
ce1944f0
LS
10276 && bgp_has_peer_failed(peer, afi, safi)) {
10277 filtered_count++;
10b49f14 10278 continue;
ce1944f0 10279 }
10b49f14 10280
3577f1c5
DD
10281 json_peer = json_object_new_object();
10282 if (peer_dynamic_neighbor(peer)) {
10283 json_object_boolean_true_add(json_peer,
10284 "dynamicPeer");
10285 }
d62a17ae 10286
3577f1c5
DD
10287 if (peer->hostname)
10288 json_object_string_add(json_peer, "hostname",
10289 peer->hostname);
10290
10291 if (peer->domainname)
10292 json_object_string_add(json_peer, "domainname",
10293 peer->domainname);
10294
10295 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10296 json_object_int_add(
10297 json_peer, "localAs",
10298 peer->change_local_as
10299 ? peer->change_local_as
10300 : peer->local_as);
3577f1c5
DD
10301 json_object_int_add(json_peer, "version", 4);
10302 json_object_int_add(json_peer, "msgRcvd",
10303 PEER_TOTAL_RX(peer));
10304 json_object_int_add(json_peer, "msgSent",
10305 PEER_TOTAL_TX(peer));
10306
43aa5965
QY
10307 atomic_size_t outq_count, inq_count;
10308 outq_count = atomic_load_explicit(
10309 &peer->obuf->count,
10310 memory_order_relaxed);
10311 inq_count = atomic_load_explicit(
10312 &peer->ibuf->count,
10313 memory_order_relaxed);
10314
3577f1c5
DD
10315 json_object_int_add(json_peer, "tableVersion",
10316 peer->version[afi][safi]);
10317 json_object_int_add(json_peer, "outq",
43aa5965
QY
10318 outq_count);
10319 json_object_int_add(json_peer, "inq",
10320 inq_count);
3577f1c5
DD
10321 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10322 use_json, json_peer);
10323
3577f1c5
DD
10324 json_object_int_add(json_peer, "pfxRcd",
10325 peer->pcount[afi][pfx_rcd_safi]);
10326
3577f1c5 10327 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10328 json_object_int_add(
10329 json_peer, "pfxSnt",
10330 (PAF_SUBGRP(paf))->scount);
10331 else
10332 json_object_int_add(json_peer, "pfxSnt",
10333 0);
0e1f8ab5
DA
10334
10335 /* BGP FSM state */
cb9196e7 10336 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10337 || CHECK_FLAG(peer->bgp->flags,
10338 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10339 json_object_string_add(json_peer,
10340 "state",
3577f1c5
DD
10341 "Idle (Admin)");
10342 else if (peer->afc_recv[afi][safi])
10343 json_object_string_add(
0e1f8ab5
DA
10344 json_peer, "state",
10345 lookup_msg(bgp_status_msg,
10346 peer->status, NULL));
10347 else if (CHECK_FLAG(
10348 peer->sflags,
10349 PEER_STATUS_PREFIX_OVERFLOW))
10350 json_object_string_add(json_peer,
10351 "state",
3577f1c5
DD
10352 "Idle (PfxCt)");
10353 else
10354 json_object_string_add(
0e1f8ab5
DA
10355 json_peer, "state",
10356 lookup_msg(bgp_status_msg,
10357 peer->status, NULL));
10358
10359 /* BGP peer state */
10360 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10361 || CHECK_FLAG(peer->bgp->flags,
10362 BGP_FLAG_SHUTDOWN))
10363 json_object_string_add(json_peer,
10364 "peerState",
10365 "Admin");
10366 else if (CHECK_FLAG(
10367 peer->sflags,
10368 PEER_STATUS_PREFIX_OVERFLOW))
10369 json_object_string_add(json_peer,
10370 "peerState",
10371 "PfxCt");
10372 else if (CHECK_FLAG(peer->flags,
10373 PEER_FLAG_PASSIVE))
10374 json_object_string_add(json_peer,
10375 "peerState",
10376 "Passive");
10377 else if (CHECK_FLAG(peer->sflags,
10378 PEER_STATUS_NSF_WAIT))
10379 json_object_string_add(json_peer,
10380 "peerState",
10381 "NSF passive");
10382 else if (CHECK_FLAG(
10383 peer->bgp->flags,
10384 BGP_FLAG_EBGP_REQUIRES_POLICY)
10385 && (!bgp_inbound_policy_exists(peer,
10386 filter)
10387 || !bgp_outbound_policy_exists(
10388 peer, filter)))
10389 json_object_string_add(json_peer,
10390 "peerState",
10391 "Policy");
10392 else
10393 json_object_string_add(
10394 json_peer, "peerState", "OK");
10395
200116db
DD
10396 json_object_int_add(json_peer, "connectionsEstablished",
10397 peer->established);
10398 json_object_int_add(json_peer, "connectionsDropped",
10399 peer->dropped);
aa72bd7e
PG
10400 if (peer->desc)
10401 json_object_string_add(
10402 json_peer, "desc", peer->desc);
b4e9dcba 10403 }
3577f1c5
DD
10404 /* Avoid creating empty peer dicts in JSON */
10405 if (json_peer == NULL)
10406 continue;
ea47320b
DL
10407
10408 if (peer->conf_if)
60466a63 10409 json_object_string_add(json_peer, "idType",
ea47320b
DL
10410 "interface");
10411 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10412 json_object_string_add(json_peer, "idType",
10413 "ipv4");
ea47320b 10414 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10415 json_object_string_add(json_peer, "idType",
10416 "ipv6");
ea47320b
DL
10417 json_object_object_add(json_peers, peer->host,
10418 json_peer);
10419 } else {
8c1d4cd5 10420 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10421 as_type, as)) {
10422 filtered_count++;
8c1d4cd5 10423 continue;
ce1944f0 10424 }
3577f1c5
DD
10425 if (show_failed &&
10426 bgp_has_peer_failed(peer, afi, safi)) {
10427 bgp_show_failed_summary(vty, bgp, peer, NULL,
10428 max_neighbor_width,
10429 use_json);
10430 } else if (!show_failed) {
10b49f14 10431 if (show_established
ce1944f0
LS
10432 && bgp_has_peer_failed(peer, afi, safi)) {
10433 filtered_count++;
10b49f14 10434 continue;
ce1944f0 10435 }
96c81f66
LS
10436
10437 if ((count - filtered_count) == 1) {
10438 /* display headline before the first
10439 * neighbor line */
10440 vty_out(vty, "\n");
10441
10442 /* Subtract 8 here because 'Neighbor' is
10443 * 8 characters */
10444 vty_out(vty, "Neighbor");
10445 vty_out(vty, "%*s",
10446 max_neighbor_width - 8, " ");
10447 vty_out(vty,
10448 show_wide
10449 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10450 : BGP_SHOW_SUMMARY_HEADER_ALL);
10451 }
10452
3577f1c5
DD
10453 memset(dn_flag, '\0', sizeof(dn_flag));
10454 if (peer_dynamic_neighbor(peer)) {
10455 dn_flag[0] = '*';
10456 }
d62a17ae 10457
3577f1c5 10458 if (peer->hostname
892fedb6
DA
10459 && CHECK_FLAG(bgp->flags,
10460 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10461 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10462 peer->hostname,
10463 peer->host);
d62a17ae 10464 else
3577f1c5
DD
10465 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10466
10467 /* pad the neighbor column with spaces */
10468 if (len < max_neighbor_width)
10469 vty_out(vty, "%*s", max_neighbor_width - len,
10470 " ");
10471
43aa5965
QY
10472 atomic_size_t outq_count, inq_count;
10473 outq_count = atomic_load_explicit(
10474 &peer->obuf->count,
10475 memory_order_relaxed);
10476 inq_count = atomic_load_explicit(
10477 &peer->ibuf->count,
10478 memory_order_relaxed);
10479
85eeb029
DA
10480 if (show_wide)
10481 vty_out(vty,
10482 "4 %10u %10u %9u %9u %8" PRIu64
10483 " %4zu %4zu %8s",
10484 peer->as,
10485 peer->change_local_as
10486 ? peer->change_local_as
10487 : peer->local_as,
10488 PEER_TOTAL_RX(peer),
10489 PEER_TOTAL_TX(peer),
10490 peer->version[afi][safi],
10491 inq_count, outq_count,
10492 peer_uptime(peer->uptime,
10493 timebuf,
10494 BGP_UPTIME_LEN, 0,
10495 NULL));
10496 else
10497 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10498 " %4zu %4zu %8s",
10499 peer->as, PEER_TOTAL_RX(peer),
10500 PEER_TOTAL_TX(peer),
10501 peer->version[afi][safi],
10502 inq_count, outq_count,
10503 peer_uptime(peer->uptime,
10504 timebuf,
10505 BGP_UPTIME_LEN, 0,
10506 NULL));
3577f1c5 10507
feb17238 10508 if (peer_established(peer)) {
d3ada366
DA
10509 if (peer->afc_recv[afi][safi]) {
10510 if (CHECK_FLAG(
10511 bgp->flags,
10512 BGP_FLAG_EBGP_REQUIRES_POLICY)
10513 && !bgp_inbound_policy_exists(
10514 peer, filter))
10515 vty_out(vty, " %12s",
10516 "(Policy)");
10517 else
10518 vty_out(vty,
6cde4b45 10519 " %12u",
d3ada366
DA
10520 peer->pcount
10521 [afi]
10522 [pfx_rcd_safi]);
10523 } else {
749d0f27 10524 vty_out(vty, " NoNeg");
d3ada366 10525 }
db92d226 10526
d3ada366
DA
10527 if (paf && PAF_SUBGRP(paf)) {
10528 if (CHECK_FLAG(
10529 bgp->flags,
10530 BGP_FLAG_EBGP_REQUIRES_POLICY)
10531 && !bgp_outbound_policy_exists(
10532 peer, filter))
10533 vty_out(vty, " %8s",
10534 "(Policy)");
10535 else
10536 vty_out(vty,
6cde4b45 10537 " %8u",
d3ada366
DA
10538 (PAF_SUBGRP(
10539 paf))
10540 ->scount);
749d0f27
DA
10541 } else {
10542 vty_out(vty, " NoNeg");
d3ada366 10543 }
db92d226 10544 } else {
736b68f3
DS
10545 if (CHECK_FLAG(peer->flags,
10546 PEER_FLAG_SHUTDOWN)
10547 || CHECK_FLAG(peer->bgp->flags,
10548 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10549 vty_out(vty, " Idle (Admin)");
10550 else if (CHECK_FLAG(
10551 peer->sflags,
10552 PEER_STATUS_PREFIX_OVERFLOW))
10553 vty_out(vty, " Idle (PfxCt)");
10554 else
10555 vty_out(vty, " %12s",
10556 lookup_msg(bgp_status_msg,
10557 peer->status, NULL));
db92d226 10558
6cde4b45 10559 vty_out(vty, " %8u", 0);
3577f1c5 10560 }
aa72bd7e 10561 if (peer->desc)
cb75bb31
DA
10562 vty_out(vty, " %s",
10563 bgp_peer_description_stripped(
85eeb029
DA
10564 peer->desc,
10565 show_wide ? 64 : 20));
aa72bd7e
PG
10566 else
10567 vty_out(vty, " N/A");
3577f1c5 10568 vty_out(vty, "\n");
d62a17ae 10569 }
3577f1c5 10570
d62a17ae 10571 }
10572 }
f933309e 10573
d62a17ae 10574 if (use_json) {
10575 json_object_object_add(json, "peers", json_peers);
3577f1c5 10576 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10577 json_object_int_add(json, "displayedPeers",
10578 count - filtered_count);
d62a17ae 10579 json_object_int_add(json, "totalPeers", count);
10580 json_object_int_add(json, "dynamicPeers", dn_count);
10581
3577f1c5
DD
10582 if (!show_failed)
10583 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10584
996c9314
LB
10585 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10586 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10587 json_object_free(json);
10588 } else {
ce1944f0 10589 if (count) {
96c81f66
LS
10590 if (filtered_count == count)
10591 vty_out(vty, "\n%% No matching neighbor\n");
10592 else {
10593 if (show_failed)
10594 vty_out(vty, "\nDisplayed neighbors %d",
10595 failed_count);
10596 else if (as_type != AS_UNSPECIFIED || as
10597 || fpeer || show_established)
ce1944f0
LS
10598 vty_out(vty, "\nDisplayed neighbors %d",
10599 count - filtered_count);
96c81f66
LS
10600
10601 vty_out(vty, "\nTotal number of neighbors %d\n",
10602 count);
ce1944f0 10603 }
ce1944f0 10604 } else {
d6ceaca3 10605 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10606 get_afi_safi_str(afi, safi, false));
d62a17ae 10607 }
b05a1c8b 10608
d6ceaca3 10609 if (dn_count) {
d62a17ae 10610 vty_out(vty, "* - dynamic neighbor\n");
10611 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10612 dn_count, bgp->dynamic_neighbors_limit);
10613 }
10614 }
1ff9a340 10615
d62a17ae 10616 return CMD_SUCCESS;
718e3744 10617}
10618
d62a17ae 10619static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10620 int safi, struct peer *fpeer, int as_type,
96c81f66 10621 as_t as, uint16_t show_flags)
d62a17ae 10622{
10623 int is_first = 1;
10624 int afi_wildcard = (afi == AFI_MAX);
10625 int safi_wildcard = (safi == SAFI_MAX);
10626 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10627 bool nbr_output = false;
85eeb029 10628 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10629
10630 if (use_json && is_wildcard)
10631 vty_out(vty, "{\n");
10632 if (afi_wildcard)
10633 afi = 1; /* AFI_IP */
10634 while (afi < AFI_MAX) {
10635 if (safi_wildcard)
10636 safi = 1; /* SAFI_UNICAST */
10637 while (safi < SAFI_MAX) {
318cac96 10638 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10639 nbr_output = true;
f86897b9 10640
d62a17ae 10641 if (is_wildcard) {
10642 /*
10643 * So limit output to those afi/safi
10644 * pairs that
10645 * actualy have something interesting in
10646 * them
10647 */
10648 if (use_json) {
d62a17ae 10649 if (!is_first)
10650 vty_out(vty, ",\n");
10651 else
10652 is_first = 0;
10653
10654 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10655 get_afi_safi_str(afi,
10656 safi,
10657 true));
d62a17ae 10658 } else {
6cac2fcc
LS
10659 vty_out(vty,
10660 "\n%s Summary (%s):\n",
5cb5f4d0
DD
10661 get_afi_safi_str(afi,
10662 safi,
6cac2fcc
LS
10663 false),
10664 bgp->name_pretty);
d62a17ae 10665 }
10666 }
8c1d4cd5
LS
10667 bgp_show_summary(vty, bgp, afi, safi, fpeer,
10668 as_type, as, show_flags);
d62a17ae 10669 }
10670 safi++;
d62a17ae 10671 if (!safi_wildcard)
10672 safi = SAFI_MAX;
10673 }
10674 afi++;
ee851c8c 10675 if (!afi_wildcard)
d62a17ae 10676 afi = AFI_MAX;
10677 }
10678
10679 if (use_json && is_wildcard)
10680 vty_out(vty, "}\n");
ca61fd25
DS
10681 else if (!nbr_output) {
10682 if (use_json)
10683 vty_out(vty, "{}\n");
10684 else
6cac2fcc
LS
10685 vty_out(vty, "%% No BGP neighbors found in %s\n",
10686 bgp->name_pretty);
ca61fd25 10687 }
d62a17ae 10688}
10689
10690static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
10691 safi_t safi,
10692 const char *neighbor,
10693 int as_type, as_t as,
96c81f66 10694 uint16_t show_flags)
d62a17ae 10695{
10696 struct listnode *node, *nnode;
10697 struct bgp *bgp;
8c1d4cd5 10698 struct peer *fpeer = NULL;
d62a17ae 10699 int is_first = 1;
9f049418 10700 bool nbr_output = false;
85eeb029 10701 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 10702
10703 if (use_json)
10704 vty_out(vty, "{\n");
10705
10706 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10707 nbr_output = true;
d62a17ae 10708 if (use_json) {
d62a17ae 10709 if (!is_first)
10710 vty_out(vty, ",\n");
10711 else
10712 is_first = 0;
10713
10714 vty_out(vty, "\"%s\":",
10715 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10716 ? VRF_DEFAULT_NAME
d62a17ae 10717 : bgp->name);
d62a17ae 10718 }
8c1d4cd5
LS
10719 if (neighbor) {
10720 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10721 use_json);
10722 if (!fpeer)
10723 continue;
10724 }
10725 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10726 as, show_flags);
d62a17ae 10727 }
10728
10729 if (use_json)
10730 vty_out(vty, "}\n");
9f049418
DS
10731 else if (!nbr_output)
10732 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10733}
10734
10735int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 10736 safi_t safi, const char *neighbor, int as_type,
96c81f66 10737 as_t as, uint16_t show_flags)
d62a17ae 10738{
10739 struct bgp *bgp;
85eeb029 10740 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 10741 struct peer *fpeer = NULL;
d62a17ae 10742
10743 if (name) {
10744 if (strmatch(name, "all")) {
85eeb029 10745 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
10746 neighbor, as_type,
10747 as, show_flags);
d62a17ae 10748 return CMD_SUCCESS;
10749 } else {
10750 bgp = bgp_lookup_by_name(name);
10751
10752 if (!bgp) {
10753 if (use_json)
10754 vty_out(vty, "{}\n");
10755 else
10756 vty_out(vty,
ca61fd25 10757 "%% BGP instance not found\n");
d62a17ae 10758 return CMD_WARNING;
10759 }
10760
8c1d4cd5
LS
10761 if (neighbor) {
10762 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10763 use_json);
10764 if (!fpeer)
10765 return CMD_WARNING;
10766 }
10767 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
10768 as_type, as, show_flags);
d62a17ae 10769 return CMD_SUCCESS;
10770 }
10771 }
10772
10773 bgp = bgp_get_default();
10774
8c1d4cd5
LS
10775 if (bgp) {
10776 if (neighbor) {
10777 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
10778 use_json);
10779 if (!fpeer)
10780 return CMD_WARNING;
10781 }
10782 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
10783 as, show_flags);
10784 } else {
ca61fd25
DS
10785 if (use_json)
10786 vty_out(vty, "{}\n");
10787 else
10788 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
10789 return CMD_WARNING;
10790 }
d62a17ae 10791
10792 return CMD_SUCCESS;
4fb25c53
DW
10793}
10794
716b2d8a 10795/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
10796DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
10797 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
10798 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 10799 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
8c1d4cd5
LS
10800 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
10801 BGP_SAFI_WITH_LABEL_HELP_STR
10802 "Display the entries for all address families\n"
10803 "Summary of BGP neighbor status\n"
10804 "Show only sessions in Established state\n"
10805 "Show only sessions not in Established state\n"
10806 "Show only the specified neighbor session\n"
10807 "Neighbor to display information about\n"
10808 "Neighbor to display information about\n"
10809 "Neighbor on BGP configured interface\n"
10810 "Show only the specified remote AS sessions\n"
10811 "AS number\n"
10812 "Internal (iBGP) AS sessions\n"
10813 "External (eBGP) AS sessions\n"
96c81f66 10814 "Shorten the information on BGP instances\n"
8c1d4cd5 10815 "Increase table width for longer output\n" JSON_STR)
718e3744 10816{
d62a17ae 10817 char *vrf = NULL;
10818 afi_t afi = AFI_MAX;
10819 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
10820 as_t as = 0; /* 0 means AS filter not set */
10821 int as_type = AS_UNSPECIFIED;
96c81f66 10822 uint16_t show_flags = 0;
d62a17ae 10823
10824 int idx = 0;
10825
10826 /* show [ip] bgp */
96f3485c 10827 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 10828 afi = AFI_IP;
9a8bdf1c
PG
10829 /* [<vrf> VIEWVRFNAME] */
10830 if (argv_find(argv, argc, "vrf", &idx)) {
10831 vrf = argv[idx + 1]->arg;
10832 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10833 vrf = NULL;
10834 } else if (argv_find(argv, argc, "view", &idx))
10835 /* [<view> VIEWVRFNAME] */
10836 vrf = argv[idx + 1]->arg;
d62a17ae 10837 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10838 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10839 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10840 }
10841
3577f1c5 10842 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
10843 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10844
10b49f14 10845 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
10846 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10847
8c1d4cd5
LS
10848 if (argv_find(argv, argc, "remote-as", &idx)) {
10849 if (argv[idx + 1]->arg[0] == 'i')
10850 as_type = AS_INTERNAL;
10851 else if (argv[idx + 1]->arg[0] == 'e')
10852 as_type = AS_EXTERNAL;
10853 else
10854 as = (as_t)atoi(argv[idx + 1]->arg);
10855 }
10856
96c81f66
LS
10857 if (argv_find(argv, argc, "terse", &idx))
10858 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
10859
85eeb029
DA
10860 if (argv_find(argv, argc, "wide", &idx))
10861 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10862
10863 if (argv_find(argv, argc, "json", &idx))
10864 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 10865
8c1d4cd5
LS
10866 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
10867 show_flags);
d62a17ae 10868}
10869
5cb5f4d0 10870const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 10871{
5cb5f4d0
DD
10872 if (for_json)
10873 return get_afi_safi_json_str(afi, safi);
d62a17ae 10874 else
5cb5f4d0 10875 return get_afi_safi_vty_str(afi, safi);
27162734
LB
10876}
10877
d62a17ae 10878
10879static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10880 afi_t afi, safi_t safi,
d7c0a89a
QY
10881 uint16_t adv_smcap, uint16_t adv_rmcap,
10882 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 10883 bool use_json, json_object *json_pref)
d62a17ae 10884{
10885 /* Send-Mode */
10886 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10887 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10888 if (use_json) {
10889 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10890 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10891 json_object_string_add(json_pref, "sendMode",
10892 "advertisedAndReceived");
10893 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10894 json_object_string_add(json_pref, "sendMode",
10895 "advertised");
10896 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10897 json_object_string_add(json_pref, "sendMode",
10898 "received");
10899 } else {
10900 vty_out(vty, " Send-mode: ");
10901 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10902 vty_out(vty, "advertised");
10903 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10904 vty_out(vty, "%sreceived",
10905 CHECK_FLAG(p->af_cap[afi][safi],
10906 adv_smcap)
10907 ? ", "
10908 : "");
10909 vty_out(vty, "\n");
10910 }
10911 }
10912
10913 /* Receive-Mode */
10914 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10915 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10916 if (use_json) {
10917 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10918 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10919 json_object_string_add(json_pref, "recvMode",
10920 "advertisedAndReceived");
10921 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10922 json_object_string_add(json_pref, "recvMode",
10923 "advertised");
10924 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10925 json_object_string_add(json_pref, "recvMode",
10926 "received");
10927 } else {
10928 vty_out(vty, " Receive-mode: ");
10929 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10930 vty_out(vty, "advertised");
10931 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10932 vty_out(vty, "%sreceived",
10933 CHECK_FLAG(p->af_cap[afi][safi],
10934 adv_rmcap)
10935 ? ", "
10936 : "");
10937 vty_out(vty, "\n");
10938 }
10939 }
10940}
10941
13909c4f
DS
10942static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10943 struct peer *p,
10944 bool use_json,
10945 json_object *json)
2986cac2 10946{
08c2d52a 10947 bool rbit_status = false;
2986cac2 10948
10949 if (!use_json)
a53ca37b 10950 vty_out(vty, "\n R bit: ");
2986cac2 10951
13909c4f
DS
10952 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10953 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 10954 && (peer_established(p))) {
2986cac2 10955
10956 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 10957 rbit_status = true;
2986cac2 10958 else
08c2d52a 10959 rbit_status = false;
2986cac2 10960 }
10961
10962 if (rbit_status) {
10963 if (use_json)
13909c4f 10964 json_object_boolean_true_add(json, "rBit");
2986cac2 10965 else
10966 vty_out(vty, "True\n");
10967 } else {
10968 if (use_json)
13909c4f 10969 json_object_boolean_false_add(json, "rBit");
2986cac2 10970 else
10971 vty_out(vty, "False\n");
10972 }
10973}
10974
13909c4f
DS
10975static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10976 struct peer *peer,
10977 bool use_json,
10978 json_object *json)
2986cac2 10979{
2bb5d39b 10980 const char *mode = "NotApplicable";
2986cac2 10981
10982 if (!use_json)
a53ca37b 10983 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 10984
13909c4f 10985 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 10986 && (peer_established(peer))) {
2986cac2 10987
13909c4f
DS
10988 if ((peer->nsf_af_count == 0)
10989 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10990
2986cac2 10991 mode = "Disable";
10992
13909c4f
DS
10993 } else if (peer->nsf_af_count == 0
10994 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10995
2986cac2 10996 mode = "Helper";
10997
13909c4f
DS
10998 } else if (peer->nsf_af_count != 0
10999 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11000
2986cac2 11001 mode = "Restart";
2986cac2 11002 }
11003 }
11004
11005 if (use_json) {
13909c4f 11006 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11007 } else
11008 vty_out(vty, mode, "\n");
11009}
11010
13909c4f
DS
11011static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11012 struct peer *p,
11013 bool use_json,
11014 json_object *json)
2986cac2 11015{
11016 const char *mode = "Invalid";
11017
11018 if (!use_json)
a53ca37b 11019 vty_out(vty, " Local GR Mode: ");
2986cac2 11020
11021 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11022 mode = "Helper";
11023 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11024 mode = "Restart";
11025 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11026 mode = "Disable";
2ba1fe69 11027 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11028 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11029 mode = "Helper*";
11030 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11031 mode = "Restart*";
11032 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11033 mode = "Disable*";
11034 else
11035 mode = "Invalid*";
2ba1fe69 11036 }
2986cac2 11037
11038 if (use_json) {
13909c4f 11039 json_object_string_add(json, "localGrMode", mode);
2986cac2 11040 } else {
11041 vty_out(vty, mode, "\n");
11042 }
11043}
11044
13909c4f
DS
11045static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11046 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11047{
2ba1fe69 11048 afi_t afi;
11049 safi_t safi;
2986cac2 11050 json_object *json_afi_safi = NULL;
11051 json_object *json_timer = NULL;
11052 json_object *json_endofrib_status = NULL;
9e3b51a7 11053 bool eor_flag = false;
2986cac2 11054
11055 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11056 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11057 if (!peer->afc[afi][safi])
11058 continue;
2986cac2 11059
13909c4f
DS
11060 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11061 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11062 continue;
9e3b51a7 11063
13909c4f
DS
11064 if (use_json) {
11065 json_afi_safi = json_object_new_object();
11066 json_endofrib_status = json_object_new_object();
11067 json_timer = json_object_new_object();
11068 }
2986cac2 11069
13909c4f
DS
11070 if (peer->eor_stime[afi][safi]
11071 >= peer->pkt_stime[afi][safi])
11072 eor_flag = true;
11073 else
11074 eor_flag = false;
2986cac2 11075
13909c4f 11076 if (!use_json) {
a53ca37b 11077 vty_out(vty, " %s:\n",
13909c4f 11078 get_afi_safi_str(afi, safi, false));
2986cac2 11079
a53ca37b 11080 vty_out(vty, " F bit: ");
698ba8d0 11081 }
2986cac2 11082
13909c4f
DS
11083 if (peer->nsf[afi][safi]
11084 && CHECK_FLAG(peer->af_cap[afi][safi],
11085 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11086
13909c4f
DS
11087 if (use_json) {
11088 json_object_boolean_true_add(
2986cac2 11089 json_afi_safi, "fBit");
13909c4f
DS
11090 } else
11091 vty_out(vty, "True\n");
11092 } else {
11093 if (use_json)
11094 json_object_boolean_false_add(
11095 json_afi_safi, "fBit");
11096 else
11097 vty_out(vty, "False\n");
11098 }
2986cac2 11099
13909c4f 11100 if (!use_json)
a53ca37b 11101 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11102
13909c4f
DS
11103 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11104 PEER_STATUS_EOR_SEND)) {
11105 if (use_json) {
11106 json_object_boolean_true_add(
2986cac2 11107 json_endofrib_status,
13909c4f 11108 "endOfRibSend");
9e3b51a7 11109
13909c4f
DS
11110 PRINT_EOR_JSON(eor_flag);
11111 } else {
11112 vty_out(vty, "Yes\n");
11113 vty_out(vty,
a53ca37b 11114 " End-of-RIB sent after update: ");
2986cac2 11115
13909c4f
DS
11116 PRINT_EOR(eor_flag);
11117 }
11118 } else {
11119 if (use_json) {
11120 json_object_boolean_false_add(
2986cac2 11121 json_endofrib_status,
13909c4f
DS
11122 "endOfRibSend");
11123 json_object_boolean_false_add(
9e3b51a7 11124 json_endofrib_status,
13909c4f
DS
11125 "endOfRibSentAfterUpdate");
11126 } else {
11127 vty_out(vty, "No\n");
11128 vty_out(vty,
a53ca37b 11129 " End-of-RIB sent after update: ");
13909c4f 11130 vty_out(vty, "No\n");
2986cac2 11131 }
13909c4f 11132 }
2986cac2 11133
a53ca37b
DA
11134 if (!use_json)
11135 vty_out(vty, " End-of-RIB received: ");
11136
11137 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11138 PEER_STATUS_EOR_RECEIVED)) {
11139 if (use_json)
11140 json_object_boolean_true_add(
11141 json_endofrib_status,
11142 "endOfRibRecv");
11143 else
11144 vty_out(vty, "Yes\n");
11145 } else {
11146 if (use_json)
11147 json_object_boolean_false_add(
11148 json_endofrib_status,
11149 "endOfRibRecv");
11150 else
11151 vty_out(vty, "No\n");
11152 }
11153
13909c4f
DS
11154 if (use_json) {
11155 json_object_int_add(json_timer,
11156 "stalePathTimer",
11157 peer->bgp->stalepath_time);
2986cac2 11158
13909c4f
DS
11159 if (peer->t_gr_stale != NULL) {
11160 json_object_int_add(
2986cac2 11161 json_timer,
11162 "stalePathTimerRemaining",
11163 thread_timer_remain_second(
13909c4f
DS
11164 peer->t_gr_stale));
11165 }
3a75afa4 11166
13909c4f
DS
11167 /* Display Configured Selection
11168 * Deferral only when when
11169 * Gr mode is enabled.
11170 */
11171 if (CHECK_FLAG(peer->flags,
11172 PEER_FLAG_GRACEFUL_RESTART)) {
11173 json_object_int_add(
3a75afa4 11174 json_timer,
2986cac2 11175 "selectionDeferralTimer",
11176 peer->bgp->stalepath_time);
13909c4f 11177 }
2986cac2 11178
13909c4f
DS
11179 if (peer->bgp->gr_info[afi][safi]
11180 .t_select_deferral
11181 != NULL) {
2986cac2 11182
13909c4f 11183 json_object_int_add(
2986cac2 11184 json_timer,
11185 "selectionDeferralTimerRemaining",
11186 thread_timer_remain_second(
13909c4f
DS
11187 peer->bgp
11188 ->gr_info[afi]
11189 [safi]
11190 .t_select_deferral));
11191 }
11192 } else {
a53ca37b 11193 vty_out(vty, " Timers:\n");
13909c4f 11194 vty_out(vty,
a53ca37b
DA
11195 " Configured Stale Path Time(sec): %u\n",
11196 peer->bgp->stalepath_time);
2986cac2 11197
a53ca37b 11198 if (peer->t_gr_stale != NULL)
2986cac2 11199 vty_out(vty,
a53ca37b 11200 " Stale Path Remaining(sec): %ld\n",
2986cac2 11201 thread_timer_remain_second(
13909c4f 11202 peer->t_gr_stale));
13909c4f
DS
11203 /* Display Configured Selection
11204 * Deferral only when when
11205 * Gr mode is enabled.
11206 */
11207 if (CHECK_FLAG(peer->flags,
a53ca37b 11208 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11209 vty_out(vty,
a53ca37b 11210 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11211 peer->bgp->select_defer_time);
2986cac2 11212
13909c4f
DS
11213 if (peer->bgp->gr_info[afi][safi]
11214 .t_select_deferral
a53ca37b 11215 != NULL)
13909c4f 11216 vty_out(vty,
a53ca37b 11217 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11218 thread_timer_remain_second(
13909c4f
DS
11219 peer->bgp
11220 ->gr_info[afi]
11221 [safi]
11222 .t_select_deferral));
2986cac2 11223 }
13909c4f
DS
11224 if (use_json) {
11225 json_object_object_add(json_afi_safi,
11226 "endOfRibStatus",
11227 json_endofrib_status);
11228 json_object_object_add(json_afi_safi, "timers",
11229 json_timer);
11230 json_object_object_add(
11231 json, get_afi_safi_str(afi, safi, true),
11232 json_afi_safi);
11233 }
2986cac2 11234 }
11235 }
11236}
11237
36235319
QY
11238static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11239 struct peer *p,
11240 bool use_json,
11241 json_object *json)
2986cac2 11242{
11243 if (use_json) {
11244 json_object *json_timer = NULL;
11245
11246 json_timer = json_object_new_object();
11247
13909c4f
DS
11248 json_object_int_add(json_timer, "configuredRestartTimer",
11249 p->bgp->restart_time);
2986cac2 11250
13909c4f
DS
11251 json_object_int_add(json_timer, "receivedRestartTimer",
11252 p->v_gr_restart);
2986cac2 11253
13909c4f
DS
11254 if (p->t_gr_restart != NULL)
11255 json_object_int_add(
11256 json_timer, "restartTimerRemaining",
11257 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11258
11259 json_object_object_add(json, "timers", json_timer);
11260 } else {
11261
a53ca37b
DA
11262 vty_out(vty, " Timers:\n");
11263 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11264 p->bgp->restart_time);
2986cac2 11265
a53ca37b 11266 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11267 p->v_gr_restart);
11268 if (p->t_gr_restart != NULL)
a53ca37b 11269 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11270 thread_timer_remain_second(p->t_gr_restart));
36235319 11271 if (p->t_gr_restart != NULL) {
a53ca37b 11272 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11273 thread_timer_remain_second(p->t_gr_restart));
11274 }
2986cac2 11275 }
11276}
11277
11278static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11279 bool use_json, json_object *json)
2986cac2 11280{
11281 char buf[SU_ADDRSTRLEN] = {0};
11282 char dn_flag[2] = {0};
2b7165e7
QY
11283 /* '*' + v6 address of neighbor */
11284 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11285
2986cac2 11286 if (!p->conf_if && peer_dynamic_neighbor(p))
11287 dn_flag[0] = '*';
11288
11289 if (p->conf_if) {
11290 if (use_json)
13909c4f
DS
11291 json_object_string_add(
11292 json, "neighborAddr",
2986cac2 11293 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11294 ? "none"
11295 : sockunion2str(&p->su, buf,
11296 SU_ADDRSTRLEN));
2986cac2 11297 else
13909c4f 11298 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11299 BGP_PEER_SU_UNSPEC(p)
11300 ? "none"
11301 : sockunion2str(&p->su, buf,
11302 SU_ADDRSTRLEN));
11303 } else {
772270f3
QY
11304 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11305 p->host);
2986cac2 11306
11307 if (use_json)
36235319
QY
11308 json_object_string_add(json, "neighborAddr",
11309 neighborAddr);
2986cac2 11310 else
36235319 11311 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11312 }
11313
11314 /* more gr info in new format */
11315 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11316}
11317
d62a17ae 11318static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11319 safi_t safi, bool use_json,
d62a17ae 11320 json_object *json_neigh)
11321{
0291c246
MK
11322 struct bgp_filter *filter;
11323 struct peer_af *paf;
11324 char orf_pfx_name[BUFSIZ];
11325 int orf_pfx_count;
11326 json_object *json_af = NULL;
11327 json_object *json_prefA = NULL;
11328 json_object *json_prefB = NULL;
11329 json_object *json_addr = NULL;
fa36596c 11330 json_object *json_advmap = NULL;
d62a17ae 11331
11332 if (use_json) {
11333 json_addr = json_object_new_object();
11334 json_af = json_object_new_object();
11335 filter = &p->filter[afi][safi];
11336
11337 if (peer_group_active(p))
11338 json_object_string_add(json_addr, "peerGroupMember",
11339 p->group->name);
11340
11341 paf = peer_af_find(p, afi, safi);
11342 if (paf && PAF_SUBGRP(paf)) {
11343 json_object_int_add(json_addr, "updateGroupId",
11344 PAF_UPDGRP(paf)->id);
11345 json_object_int_add(json_addr, "subGroupId",
11346 PAF_SUBGRP(paf)->id);
11347 json_object_int_add(json_addr, "packetQueueLength",
11348 bpacket_queue_virtual_length(paf));
11349 }
11350
11351 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11352 || CHECK_FLAG(p->af_cap[afi][safi],
11353 PEER_CAP_ORF_PREFIX_SM_RCV)
11354 || CHECK_FLAG(p->af_cap[afi][safi],
11355 PEER_CAP_ORF_PREFIX_RM_ADV)
11356 || CHECK_FLAG(p->af_cap[afi][safi],
11357 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11358 json_object_int_add(json_af, "orfType",
11359 ORF_TYPE_PREFIX);
11360 json_prefA = json_object_new_object();
11361 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11362 PEER_CAP_ORF_PREFIX_SM_ADV,
11363 PEER_CAP_ORF_PREFIX_RM_ADV,
11364 PEER_CAP_ORF_PREFIX_SM_RCV,
11365 PEER_CAP_ORF_PREFIX_RM_RCV,
11366 use_json, json_prefA);
11367 json_object_object_add(json_af, "orfPrefixList",
11368 json_prefA);
11369 }
11370
11371 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11372 || CHECK_FLAG(p->af_cap[afi][safi],
11373 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11374 || CHECK_FLAG(p->af_cap[afi][safi],
11375 PEER_CAP_ORF_PREFIX_RM_ADV)
11376 || CHECK_FLAG(p->af_cap[afi][safi],
11377 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11378 json_object_int_add(json_af, "orfOldType",
11379 ORF_TYPE_PREFIX_OLD);
11380 json_prefB = json_object_new_object();
11381 bgp_show_peer_afi_orf_cap(
11382 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11383 PEER_CAP_ORF_PREFIX_RM_ADV,
11384 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11385 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11386 json_prefB);
11387 json_object_object_add(json_af, "orfOldPrefixList",
11388 json_prefB);
11389 }
11390
11391 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11392 || CHECK_FLAG(p->af_cap[afi][safi],
11393 PEER_CAP_ORF_PREFIX_SM_RCV)
11394 || CHECK_FLAG(p->af_cap[afi][safi],
11395 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11396 || CHECK_FLAG(p->af_cap[afi][safi],
11397 PEER_CAP_ORF_PREFIX_RM_ADV)
11398 || CHECK_FLAG(p->af_cap[afi][safi],
11399 PEER_CAP_ORF_PREFIX_RM_RCV)
11400 || CHECK_FLAG(p->af_cap[afi][safi],
11401 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11402 json_object_object_add(json_addr, "afDependentCap",
11403 json_af);
11404 else
11405 json_object_free(json_af);
11406
772270f3
QY
11407 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11408 p->host, afi, safi);
d62a17ae 11409 orf_pfx_count = prefix_bgp_show_prefix_list(
11410 NULL, afi, orf_pfx_name, use_json);
11411
11412 if (CHECK_FLAG(p->af_sflags[afi][safi],
11413 PEER_STATUS_ORF_PREFIX_SEND)
11414 || orf_pfx_count) {
11415 if (CHECK_FLAG(p->af_sflags[afi][safi],
11416 PEER_STATUS_ORF_PREFIX_SEND))
11417 json_object_boolean_true_add(json_neigh,
11418 "orfSent");
11419 if (orf_pfx_count)
11420 json_object_int_add(json_addr, "orfRecvCounter",
11421 orf_pfx_count);
11422 }
11423 if (CHECK_FLAG(p->af_sflags[afi][safi],
11424 PEER_STATUS_ORF_WAIT_REFRESH))
11425 json_object_string_add(
11426 json_addr, "orfFirstUpdate",
11427 "deferredUntilORFOrRouteRefreshRecvd");
11428
11429 if (CHECK_FLAG(p->af_flags[afi][safi],
11430 PEER_FLAG_REFLECTOR_CLIENT))
11431 json_object_boolean_true_add(json_addr,
11432 "routeReflectorClient");
11433 if (CHECK_FLAG(p->af_flags[afi][safi],
11434 PEER_FLAG_RSERVER_CLIENT))
11435 json_object_boolean_true_add(json_addr,
11436 "routeServerClient");
11437 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11438 json_object_boolean_true_add(json_addr,
11439 "inboundSoftConfigPermit");
11440
11441 if (CHECK_FLAG(p->af_flags[afi][safi],
11442 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11443 json_object_boolean_true_add(
11444 json_addr,
11445 "privateAsNumsAllReplacedInUpdatesToNbr");
11446 else if (CHECK_FLAG(p->af_flags[afi][safi],
11447 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11448 json_object_boolean_true_add(
11449 json_addr,
11450 "privateAsNumsReplacedInUpdatesToNbr");
11451 else if (CHECK_FLAG(p->af_flags[afi][safi],
11452 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11453 json_object_boolean_true_add(
11454 json_addr,
11455 "privateAsNumsAllRemovedInUpdatesToNbr");
11456 else if (CHECK_FLAG(p->af_flags[afi][safi],
11457 PEER_FLAG_REMOVE_PRIVATE_AS))
11458 json_object_boolean_true_add(
11459 json_addr,
11460 "privateAsNumsRemovedInUpdatesToNbr");
11461
dcc68b5e
MS
11462 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11463 json_object_boolean_true_add(
11464 json_addr,
11465 bgp_addpath_names(p->addpath_type[afi][safi])
11466 ->type_json_name);
d62a17ae 11467
11468 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11469 json_object_string_add(json_addr,
11470 "overrideASNsInOutboundUpdates",
11471 "ifAspathEqualRemoteAs");
11472
11473 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11474 || CHECK_FLAG(p->af_flags[afi][safi],
11475 PEER_FLAG_FORCE_NEXTHOP_SELF))
11476 json_object_boolean_true_add(json_addr,
11477 "routerAlwaysNextHop");
11478 if (CHECK_FLAG(p->af_flags[afi][safi],
11479 PEER_FLAG_AS_PATH_UNCHANGED))
11480 json_object_boolean_true_add(
11481 json_addr, "unchangedAsPathPropogatedToNbr");
11482 if (CHECK_FLAG(p->af_flags[afi][safi],
11483 PEER_FLAG_NEXTHOP_UNCHANGED))
11484 json_object_boolean_true_add(
11485 json_addr, "unchangedNextHopPropogatedToNbr");
11486 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11487 json_object_boolean_true_add(
11488 json_addr, "unchangedMedPropogatedToNbr");
11489 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11490 || CHECK_FLAG(p->af_flags[afi][safi],
11491 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11492 if (CHECK_FLAG(p->af_flags[afi][safi],
11493 PEER_FLAG_SEND_COMMUNITY)
11494 && CHECK_FLAG(p->af_flags[afi][safi],
11495 PEER_FLAG_SEND_EXT_COMMUNITY))
11496 json_object_string_add(json_addr,
11497 "commAttriSentToNbr",
11498 "extendedAndStandard");
11499 else if (CHECK_FLAG(p->af_flags[afi][safi],
11500 PEER_FLAG_SEND_EXT_COMMUNITY))
11501 json_object_string_add(json_addr,
11502 "commAttriSentToNbr",
11503 "extended");
11504 else
11505 json_object_string_add(json_addr,
11506 "commAttriSentToNbr",
11507 "standard");
11508 }
11509 if (CHECK_FLAG(p->af_flags[afi][safi],
11510 PEER_FLAG_DEFAULT_ORIGINATE)) {
11511 if (p->default_rmap[afi][safi].name)
11512 json_object_string_add(
11513 json_addr, "defaultRouteMap",
11514 p->default_rmap[afi][safi].name);
11515
11516 if (paf && PAF_SUBGRP(paf)
11517 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11518 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11519 json_object_boolean_true_add(json_addr,
11520 "defaultSent");
11521 else
11522 json_object_boolean_true_add(json_addr,
11523 "defaultNotSent");
11524 }
11525
dff8f48d 11526 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11527 if (is_evpn_enabled())
60466a63
QY
11528 json_object_boolean_true_add(
11529 json_addr, "advertiseAllVnis");
dff8f48d
MK
11530 }
11531
d62a17ae 11532 if (filter->plist[FILTER_IN].name
11533 || filter->dlist[FILTER_IN].name
11534 || filter->aslist[FILTER_IN].name
11535 || filter->map[RMAP_IN].name)
11536 json_object_boolean_true_add(json_addr,
11537 "inboundPathPolicyConfig");
11538 if (filter->plist[FILTER_OUT].name
11539 || filter->dlist[FILTER_OUT].name
11540 || filter->aslist[FILTER_OUT].name
11541 || filter->map[RMAP_OUT].name || filter->usmap.name)
11542 json_object_boolean_true_add(
11543 json_addr, "outboundPathPolicyConfig");
11544
11545 /* prefix-list */
11546 if (filter->plist[FILTER_IN].name)
11547 json_object_string_add(json_addr,
11548 "incomingUpdatePrefixFilterList",
11549 filter->plist[FILTER_IN].name);
11550 if (filter->plist[FILTER_OUT].name)
11551 json_object_string_add(json_addr,
11552 "outgoingUpdatePrefixFilterList",
11553 filter->plist[FILTER_OUT].name);
11554
11555 /* distribute-list */
11556 if (filter->dlist[FILTER_IN].name)
11557 json_object_string_add(
11558 json_addr, "incomingUpdateNetworkFilterList",
11559 filter->dlist[FILTER_IN].name);
11560 if (filter->dlist[FILTER_OUT].name)
11561 json_object_string_add(
11562 json_addr, "outgoingUpdateNetworkFilterList",
11563 filter->dlist[FILTER_OUT].name);
11564
11565 /* filter-list. */
11566 if (filter->aslist[FILTER_IN].name)
11567 json_object_string_add(json_addr,
11568 "incomingUpdateAsPathFilterList",
11569 filter->aslist[FILTER_IN].name);
11570 if (filter->aslist[FILTER_OUT].name)
11571 json_object_string_add(json_addr,
11572 "outgoingUpdateAsPathFilterList",
11573 filter->aslist[FILTER_OUT].name);
11574
11575 /* route-map. */
11576 if (filter->map[RMAP_IN].name)
11577 json_object_string_add(
11578 json_addr, "routeMapForIncomingAdvertisements",
11579 filter->map[RMAP_IN].name);
11580 if (filter->map[RMAP_OUT].name)
11581 json_object_string_add(
11582 json_addr, "routeMapForOutgoingAdvertisements",
11583 filter->map[RMAP_OUT].name);
11584
9dac9fc8 11585 /* ebgp-requires-policy (inbound) */
1d3fdccf 11586 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11587 && !bgp_inbound_policy_exists(p, filter))
11588 json_object_string_add(
11589 json_addr, "inboundEbgpRequiresPolicy",
11590 "Inbound updates discarded due to missing policy");
11591
11592 /* ebgp-requires-policy (outbound) */
1d3fdccf 11593 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11594 && (!bgp_outbound_policy_exists(p, filter)))
11595 json_object_string_add(
11596 json_addr, "outboundEbgpRequiresPolicy",
11597 "Outbound updates discarded due to missing policy");
11598
d62a17ae 11599 /* unsuppress-map */
11600 if (filter->usmap.name)
11601 json_object_string_add(json_addr,
11602 "selectiveUnsuppressRouteMap",
11603 filter->usmap.name);
11604
fa36596c
MK
11605 /* advertise-map */
11606 if (filter->advmap.aname) {
11607 json_advmap = json_object_new_object();
11608 json_object_string_add(json_advmap, "condition",
11609 filter->advmap.condition
11610 ? "EXIST"
11611 : "NON_EXIST");
11612 json_object_string_add(json_advmap, "conditionMap",
11613 filter->advmap.cname);
11614 json_object_string_add(json_advmap, "advertiseMap",
11615 filter->advmap.aname);
11616 json_object_string_add(json_advmap, "advertiseStatus",
11617 filter->advmap.update_type
11618 == ADVERTISE
11619 ? "Advertise"
11620 : "Withdraw");
11621 json_object_object_add(json_addr, "advertiseMap",
11622 json_advmap);
11623 }
11624
d62a17ae 11625 /* Receive prefix count */
11626 json_object_int_add(json_addr, "acceptedPrefixCounter",
11627 p->pcount[afi][safi]);
50e05855
AD
11628 if (paf && PAF_SUBGRP(paf))
11629 json_object_int_add(json_addr, "sentPrefixCounter",
11630 (PAF_SUBGRP(paf))->scount);
d62a17ae 11631
fde246e8
DA
11632 /* Maximum prefix */
11633 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11634 json_object_int_add(json_addr, "prefixOutAllowedMax",
11635 p->pmax_out[afi][safi]);
11636
d62a17ae 11637 /* Maximum prefix */
11638 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11639 json_object_int_add(json_addr, "prefixAllowedMax",
11640 p->pmax[afi][safi]);
11641 if (CHECK_FLAG(p->af_flags[afi][safi],
11642 PEER_FLAG_MAX_PREFIX_WARNING))
11643 json_object_boolean_true_add(
11644 json_addr, "prefixAllowedMaxWarning");
11645 json_object_int_add(json_addr,
11646 "prefixAllowedWarningThresh",
11647 p->pmax_threshold[afi][safi]);
11648 if (p->pmax_restart[afi][safi])
11649 json_object_int_add(
11650 json_addr,
11651 "prefixAllowedRestartIntervalMsecs",
11652 p->pmax_restart[afi][safi] * 60000);
11653 }
2986cac2 11654 json_object_object_add(json_neigh,
36235319 11655 get_afi_safi_str(afi, safi, true),
d62a17ae 11656 json_addr);
11657
11658 } else {
11659 filter = &p->filter[afi][safi];
11660
11661 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11662 get_afi_safi_str(afi, safi, false));
d62a17ae 11663
11664 if (peer_group_active(p))
11665 vty_out(vty, " %s peer-group member\n",
11666 p->group->name);
11667
11668 paf = peer_af_find(p, afi, safi);
11669 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11670 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11671 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11672 vty_out(vty, " Packet Queue length %d\n",
11673 bpacket_queue_virtual_length(paf));
11674 } else {
11675 vty_out(vty, " Not part of any update group\n");
11676 }
11677 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11678 || CHECK_FLAG(p->af_cap[afi][safi],
11679 PEER_CAP_ORF_PREFIX_SM_RCV)
11680 || CHECK_FLAG(p->af_cap[afi][safi],
11681 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11682 || CHECK_FLAG(p->af_cap[afi][safi],
11683 PEER_CAP_ORF_PREFIX_RM_ADV)
11684 || CHECK_FLAG(p->af_cap[afi][safi],
11685 PEER_CAP_ORF_PREFIX_RM_RCV)
11686 || CHECK_FLAG(p->af_cap[afi][safi],
11687 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11688 vty_out(vty, " AF-dependant capabilities:\n");
11689
11690 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11691 || CHECK_FLAG(p->af_cap[afi][safi],
11692 PEER_CAP_ORF_PREFIX_SM_RCV)
11693 || CHECK_FLAG(p->af_cap[afi][safi],
11694 PEER_CAP_ORF_PREFIX_RM_ADV)
11695 || CHECK_FLAG(p->af_cap[afi][safi],
11696 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11697 vty_out(vty,
11698 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11699 ORF_TYPE_PREFIX);
11700 bgp_show_peer_afi_orf_cap(
11701 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11702 PEER_CAP_ORF_PREFIX_RM_ADV,
11703 PEER_CAP_ORF_PREFIX_SM_RCV,
11704 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11705 }
11706 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11707 || CHECK_FLAG(p->af_cap[afi][safi],
11708 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11709 || CHECK_FLAG(p->af_cap[afi][safi],
11710 PEER_CAP_ORF_PREFIX_RM_ADV)
11711 || CHECK_FLAG(p->af_cap[afi][safi],
11712 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11713 vty_out(vty,
11714 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11715 ORF_TYPE_PREFIX_OLD);
11716 bgp_show_peer_afi_orf_cap(
11717 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11718 PEER_CAP_ORF_PREFIX_RM_ADV,
11719 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11720 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11721 }
11722
772270f3
QY
11723 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11724 p->host, afi, safi);
d62a17ae 11725 orf_pfx_count = prefix_bgp_show_prefix_list(
11726 NULL, afi, orf_pfx_name, use_json);
11727
11728 if (CHECK_FLAG(p->af_sflags[afi][safi],
11729 PEER_STATUS_ORF_PREFIX_SEND)
11730 || orf_pfx_count) {
11731 vty_out(vty, " Outbound Route Filter (ORF):");
11732 if (CHECK_FLAG(p->af_sflags[afi][safi],
11733 PEER_STATUS_ORF_PREFIX_SEND))
11734 vty_out(vty, " sent;");
11735 if (orf_pfx_count)
11736 vty_out(vty, " received (%d entries)",
11737 orf_pfx_count);
11738 vty_out(vty, "\n");
11739 }
11740 if (CHECK_FLAG(p->af_sflags[afi][safi],
11741 PEER_STATUS_ORF_WAIT_REFRESH))
11742 vty_out(vty,
11743 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11744
11745 if (CHECK_FLAG(p->af_flags[afi][safi],
11746 PEER_FLAG_REFLECTOR_CLIENT))
11747 vty_out(vty, " Route-Reflector Client\n");
11748 if (CHECK_FLAG(p->af_flags[afi][safi],
11749 PEER_FLAG_RSERVER_CLIENT))
11750 vty_out(vty, " Route-Server Client\n");
11751 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11752 vty_out(vty,
11753 " Inbound soft reconfiguration allowed\n");
11754
11755 if (CHECK_FLAG(p->af_flags[afi][safi],
11756 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11757 vty_out(vty,
11758 " Private AS numbers (all) replaced in updates to this neighbor\n");
11759 else if (CHECK_FLAG(p->af_flags[afi][safi],
11760 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11761 vty_out(vty,
11762 " Private AS numbers replaced in updates to this neighbor\n");
11763 else if (CHECK_FLAG(p->af_flags[afi][safi],
11764 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11765 vty_out(vty,
11766 " Private AS numbers (all) removed in updates to this neighbor\n");
11767 else if (CHECK_FLAG(p->af_flags[afi][safi],
11768 PEER_FLAG_REMOVE_PRIVATE_AS))
11769 vty_out(vty,
11770 " Private AS numbers removed in updates to this neighbor\n");
11771
dcc68b5e
MS
11772 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11773 vty_out(vty, " %s\n",
11774 bgp_addpath_names(p->addpath_type[afi][safi])
11775 ->human_description);
d62a17ae 11776
11777 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11778 vty_out(vty,
11779 " Override ASNs in outbound updates if aspath equals remote-as\n");
11780
11781 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11782 || CHECK_FLAG(p->af_flags[afi][safi],
11783 PEER_FLAG_FORCE_NEXTHOP_SELF))
11784 vty_out(vty, " NEXT_HOP is always this router\n");
11785 if (CHECK_FLAG(p->af_flags[afi][safi],
11786 PEER_FLAG_AS_PATH_UNCHANGED))
11787 vty_out(vty,
11788 " AS_PATH is propagated unchanged to this neighbor\n");
11789 if (CHECK_FLAG(p->af_flags[afi][safi],
11790 PEER_FLAG_NEXTHOP_UNCHANGED))
11791 vty_out(vty,
11792 " NEXT_HOP is propagated unchanged to this neighbor\n");
11793 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11794 vty_out(vty,
11795 " MED is propagated unchanged to this neighbor\n");
11796 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11797 || CHECK_FLAG(p->af_flags[afi][safi],
11798 PEER_FLAG_SEND_EXT_COMMUNITY)
11799 || CHECK_FLAG(p->af_flags[afi][safi],
11800 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11801 vty_out(vty,
11802 " Community attribute sent to this neighbor");
11803 if (CHECK_FLAG(p->af_flags[afi][safi],
11804 PEER_FLAG_SEND_COMMUNITY)
11805 && CHECK_FLAG(p->af_flags[afi][safi],
11806 PEER_FLAG_SEND_EXT_COMMUNITY)
11807 && CHECK_FLAG(p->af_flags[afi][safi],
11808 PEER_FLAG_SEND_LARGE_COMMUNITY))
11809 vty_out(vty, "(all)\n");
11810 else if (CHECK_FLAG(p->af_flags[afi][safi],
11811 PEER_FLAG_SEND_LARGE_COMMUNITY))
11812 vty_out(vty, "(large)\n");
11813 else if (CHECK_FLAG(p->af_flags[afi][safi],
11814 PEER_FLAG_SEND_EXT_COMMUNITY))
11815 vty_out(vty, "(extended)\n");
11816 else
11817 vty_out(vty, "(standard)\n");
11818 }
11819 if (CHECK_FLAG(p->af_flags[afi][safi],
11820 PEER_FLAG_DEFAULT_ORIGINATE)) {
11821 vty_out(vty, " Default information originate,");
11822
11823 if (p->default_rmap[afi][safi].name)
11824 vty_out(vty, " default route-map %s%s,",
11825 p->default_rmap[afi][safi].map ? "*"
11826 : "",
11827 p->default_rmap[afi][safi].name);
11828 if (paf && PAF_SUBGRP(paf)
11829 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11830 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11831 vty_out(vty, " default sent\n");
11832 else
11833 vty_out(vty, " default not sent\n");
11834 }
11835
dff8f48d
MK
11836 /* advertise-vni-all */
11837 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11838 if (is_evpn_enabled())
dff8f48d
MK
11839 vty_out(vty, " advertise-all-vni\n");
11840 }
11841
d62a17ae 11842 if (filter->plist[FILTER_IN].name
11843 || filter->dlist[FILTER_IN].name
11844 || filter->aslist[FILTER_IN].name
11845 || filter->map[RMAP_IN].name)
11846 vty_out(vty, " Inbound path policy configured\n");
11847 if (filter->plist[FILTER_OUT].name
11848 || filter->dlist[FILTER_OUT].name
11849 || filter->aslist[FILTER_OUT].name
11850 || filter->map[RMAP_OUT].name || filter->usmap.name)
11851 vty_out(vty, " Outbound path policy configured\n");
11852
11853 /* prefix-list */
11854 if (filter->plist[FILTER_IN].name)
11855 vty_out(vty,
11856 " Incoming update prefix filter list is %s%s\n",
11857 filter->plist[FILTER_IN].plist ? "*" : "",
11858 filter->plist[FILTER_IN].name);
11859 if (filter->plist[FILTER_OUT].name)
11860 vty_out(vty,
11861 " Outgoing update prefix filter list is %s%s\n",
11862 filter->plist[FILTER_OUT].plist ? "*" : "",
11863 filter->plist[FILTER_OUT].name);
11864
11865 /* distribute-list */
11866 if (filter->dlist[FILTER_IN].name)
11867 vty_out(vty,
11868 " Incoming update network filter list is %s%s\n",
11869 filter->dlist[FILTER_IN].alist ? "*" : "",
11870 filter->dlist[FILTER_IN].name);
11871 if (filter->dlist[FILTER_OUT].name)
11872 vty_out(vty,
11873 " Outgoing update network filter list is %s%s\n",
11874 filter->dlist[FILTER_OUT].alist ? "*" : "",
11875 filter->dlist[FILTER_OUT].name);
11876
11877 /* filter-list. */
11878 if (filter->aslist[FILTER_IN].name)
11879 vty_out(vty,
11880 " Incoming update AS path filter list is %s%s\n",
11881 filter->aslist[FILTER_IN].aslist ? "*" : "",
11882 filter->aslist[FILTER_IN].name);
11883 if (filter->aslist[FILTER_OUT].name)
11884 vty_out(vty,
11885 " Outgoing update AS path filter list is %s%s\n",
11886 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11887 filter->aslist[FILTER_OUT].name);
11888
11889 /* route-map. */
11890 if (filter->map[RMAP_IN].name)
11891 vty_out(vty,
11892 " Route map for incoming advertisements is %s%s\n",
11893 filter->map[RMAP_IN].map ? "*" : "",
11894 filter->map[RMAP_IN].name);
11895 if (filter->map[RMAP_OUT].name)
11896 vty_out(vty,
11897 " Route map for outgoing advertisements is %s%s\n",
11898 filter->map[RMAP_OUT].map ? "*" : "",
11899 filter->map[RMAP_OUT].name);
11900
9dac9fc8 11901 /* ebgp-requires-policy (inbound) */
1d3fdccf 11902 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11903 && !bgp_inbound_policy_exists(p, filter))
11904 vty_out(vty,
11905 " Inbound updates discarded due to missing policy\n");
11906
11907 /* ebgp-requires-policy (outbound) */
1d3fdccf 11908 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11909 && !bgp_outbound_policy_exists(p, filter))
11910 vty_out(vty,
11911 " Outbound updates discarded due to missing policy\n");
11912
d62a17ae 11913 /* unsuppress-map */
11914 if (filter->usmap.name)
11915 vty_out(vty,
11916 " Route map for selective unsuppress is %s%s\n",
11917 filter->usmap.map ? "*" : "",
11918 filter->usmap.name);
11919
7f7940e6
MK
11920 /* advertise-map */
11921 if (filter->advmap.aname && filter->advmap.cname)
11922 vty_out(vty,
11923 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
11924 filter->advmap.condition ? "EXIST"
11925 : "NON_EXIST",
11926 filter->advmap.cmap ? "*" : "",
11927 filter->advmap.cname,
11928 filter->advmap.amap ? "*" : "",
11929 filter->advmap.aname,
fa36596c 11930 filter->advmap.update_type == ADVERTISE
c385f82a
MK
11931 ? "Advertise"
11932 : "Withdraw");
7f7940e6 11933
d62a17ae 11934 /* Receive prefix count */
6cde4b45 11935 vty_out(vty, " %u accepted prefixes\n",
a0a87037 11936 p->pcount[afi][safi]);
d62a17ae 11937
fde246e8
DA
11938 /* maximum-prefix-out */
11939 if (CHECK_FLAG(p->af_flags[afi][safi],
11940 PEER_FLAG_MAX_PREFIX_OUT))
11941 vty_out(vty,
6cde4b45 11942 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
11943 p->pmax_out[afi][safi]);
11944
d62a17ae 11945 /* Maximum prefix */
11946 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 11947 vty_out(vty,
6cde4b45 11948 " Maximum prefixes allowed %u%s\n",
d62a17ae 11949 p->pmax[afi][safi],
11950 CHECK_FLAG(p->af_flags[afi][safi],
11951 PEER_FLAG_MAX_PREFIX_WARNING)
11952 ? " (warning-only)"
11953 : "");
11954 vty_out(vty, " Threshold for warning message %d%%",
11955 p->pmax_threshold[afi][safi]);
11956 if (p->pmax_restart[afi][safi])
11957 vty_out(vty, ", restart interval %d min",
11958 p->pmax_restart[afi][safi]);
11959 vty_out(vty, "\n");
11960 }
11961
11962 vty_out(vty, "\n");
11963 }
11964}
11965
9f049418 11966static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 11967 json_object *json)
718e3744 11968{
d62a17ae 11969 struct bgp *bgp;
11970 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11971 char timebuf[BGP_UPTIME_LEN];
11972 char dn_flag[2];
d62a17ae 11973 afi_t afi;
11974 safi_t safi;
d7c0a89a
QY
11975 uint16_t i;
11976 uint8_t *msg;
d62a17ae 11977 json_object *json_neigh = NULL;
11978 time_t epoch_tbuf;
4ab46701 11979 uint32_t sync_tcp_mss;
718e3744 11980
d62a17ae 11981 bgp = p->bgp;
11982
11983 if (use_json)
11984 json_neigh = json_object_new_object();
11985
11986 memset(dn_flag, '\0', sizeof(dn_flag));
11987 if (!p->conf_if && peer_dynamic_neighbor(p))
11988 dn_flag[0] = '*';
11989
11990 if (!use_json) {
11991 if (p->conf_if) /* Configured interface name. */
11992 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11993 BGP_PEER_SU_UNSPEC(p)
11994 ? "None"
11995 : sockunion2str(&p->su, buf,
11996 SU_ADDRSTRLEN));
11997 else /* Configured IP address. */
11998 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11999 p->host);
12000 }
12001
12002 if (use_json) {
12003 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12004 json_object_string_add(json_neigh, "bgpNeighborAddr",
12005 "none");
12006 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12007 json_object_string_add(
12008 json_neigh, "bgpNeighborAddr",
12009 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12010
12011 json_object_int_add(json_neigh, "remoteAs", p->as);
12012
12013 if (p->change_local_as)
12014 json_object_int_add(json_neigh, "localAs",
12015 p->change_local_as);
12016 else
12017 json_object_int_add(json_neigh, "localAs", p->local_as);
12018
12019 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12020 json_object_boolean_true_add(json_neigh,
12021 "localAsNoPrepend");
12022
12023 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12024 json_object_boolean_true_add(json_neigh,
12025 "localAsReplaceAs");
12026 } else {
12027 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12028 || (p->as_type == AS_INTERNAL))
12029 vty_out(vty, "remote AS %u, ", p->as);
12030 else
12031 vty_out(vty, "remote AS Unspecified, ");
12032 vty_out(vty, "local AS %u%s%s, ",
12033 p->change_local_as ? p->change_local_as : p->local_as,
12034 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12035 ? " no-prepend"
12036 : "",
12037 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12038 ? " replace-as"
12039 : "");
12040 }
faa16034
DS
12041 /* peer type internal or confed-internal */
12042 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12043 if (use_json) {
12044 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12045 json_object_boolean_true_add(
12046 json_neigh, "nbrConfedInternalLink");
12047 else
12048 json_object_boolean_true_add(json_neigh,
12049 "nbrInternalLink");
12050 } else {
12051 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12052 vty_out(vty, "confed-internal link\n");
12053 else
12054 vty_out(vty, "internal link\n");
12055 }
faa16034
DS
12056 /* peer type external or confed-external */
12057 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12058 if (use_json) {
12059 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12060 json_object_boolean_true_add(
12061 json_neigh, "nbrConfedExternalLink");
12062 else
12063 json_object_boolean_true_add(json_neigh,
12064 "nbrExternalLink");
12065 } else {
12066 if (bgp_confederation_peers_check(bgp, p->as))
12067 vty_out(vty, "confed-external link\n");
12068 else
12069 vty_out(vty, "external link\n");
12070 }
faa16034
DS
12071 } else {
12072 if (use_json)
12073 json_object_boolean_true_add(json_neigh,
12074 "nbrUnspecifiedLink");
12075 else
12076 vty_out(vty, "unspecified link\n");
d62a17ae 12077 }
12078
12079 /* Description. */
12080 if (p->desc) {
12081 if (use_json)
12082 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12083 else
12084 vty_out(vty, " Description: %s\n", p->desc);
12085 }
12086
12087 if (p->hostname) {
12088 if (use_json) {
12089 if (p->hostname)
12090 json_object_string_add(json_neigh, "hostname",
12091 p->hostname);
12092
12093 if (p->domainname)
12094 json_object_string_add(json_neigh, "domainname",
12095 p->domainname);
12096 } else {
12097 if (p->domainname && (p->domainname[0] != '\0'))
12098 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12099 p->domainname);
12100 else
12101 vty_out(vty, "Hostname: %s\n", p->hostname);
12102 }
12103 }
12104
12105 /* Peer-group */
12106 if (p->group) {
12107 if (use_json) {
12108 json_object_string_add(json_neigh, "peerGroup",
12109 p->group->name);
12110
12111 if (dn_flag[0]) {
12112 struct prefix prefix, *range = NULL;
12113
0154d8ce
DS
12114 if (sockunion2hostprefix(&(p->su), &prefix))
12115 range = peer_group_lookup_dynamic_neighbor_range(
12116 p->group, &prefix);
d62a17ae 12117
12118 if (range) {
12119 prefix2str(range, buf1, sizeof(buf1));
12120 json_object_string_add(
12121 json_neigh,
12122 "peerSubnetRangeGroup", buf1);
12123 }
12124 }
12125 } else {
12126 vty_out(vty,
12127 " Member of peer-group %s for session parameters\n",
12128 p->group->name);
12129
12130 if (dn_flag[0]) {
12131 struct prefix prefix, *range = NULL;
12132
0154d8ce
DS
12133 if (sockunion2hostprefix(&(p->su), &prefix))
12134 range = peer_group_lookup_dynamic_neighbor_range(
12135 p->group, &prefix);
d62a17ae 12136
12137 if (range) {
d62a17ae 12138 vty_out(vty,
1b78780b
DL
12139 " Belongs to the subnet range group: %pFX\n",
12140 range);
d62a17ae 12141 }
12142 }
12143 }
12144 }
12145
12146 if (use_json) {
12147 /* Administrative shutdown. */
cb9196e7
DS
12148 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12149 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12150 json_object_boolean_true_add(json_neigh,
12151 "adminShutDown");
12152
12153 /* BGP Version. */
12154 json_object_int_add(json_neigh, "bgpVersion", 4);
12155 json_object_string_add(
12156 json_neigh, "remoteRouterId",
12157 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12158 json_object_string_add(
12159 json_neigh, "localRouterId",
12160 inet_ntop(AF_INET, &bgp->router_id, buf1,
12161 sizeof(buf1)));
d62a17ae 12162
12163 /* Confederation */
12164 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12165 && bgp_confederation_peers_check(bgp, p->as))
12166 json_object_boolean_true_add(json_neigh,
12167 "nbrCommonAdmin");
12168
12169 /* Status. */
12170 json_object_string_add(
12171 json_neigh, "bgpState",
12172 lookup_msg(bgp_status_msg, p->status, NULL));
12173
feb17238 12174 if (peer_established(p)) {
d62a17ae 12175 time_t uptime;
d62a17ae 12176
12177 uptime = bgp_clock();
12178 uptime -= p->uptime;
d62a17ae 12179 epoch_tbuf = time(NULL) - uptime;
12180
d3c7efed
DS
12181 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12182 uptime * 1000);
d62a17ae 12183 json_object_string_add(json_neigh, "bgpTimerUpString",
12184 peer_uptime(p->uptime, timebuf,
12185 BGP_UPTIME_LEN, 0,
12186 NULL));
12187 json_object_int_add(json_neigh,
12188 "bgpTimerUpEstablishedEpoch",
12189 epoch_tbuf);
12190 }
12191
12192 else if (p->status == Active) {
12193 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12194 json_object_string_add(json_neigh, "bgpStateIs",
12195 "passive");
12196 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12197 json_object_string_add(json_neigh, "bgpStateIs",
12198 "passiveNSF");
12199 }
12200
12201 /* read timer */
12202 time_t uptime;
a2700b50 12203 struct tm tm;
d62a17ae 12204
12205 uptime = bgp_clock();
12206 uptime -= p->readtime;
a2700b50
MS
12207 gmtime_r(&uptime, &tm);
12208
d62a17ae 12209 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12210 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12211 + (tm.tm_hour * 3600000));
d62a17ae 12212
12213 uptime = bgp_clock();
12214 uptime -= p->last_write;
a2700b50
MS
12215 gmtime_r(&uptime, &tm);
12216
d62a17ae 12217 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12218 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12219 + (tm.tm_hour * 3600000));
d62a17ae 12220
12221 uptime = bgp_clock();
12222 uptime -= p->update_time;
a2700b50
MS
12223 gmtime_r(&uptime, &tm);
12224
d62a17ae 12225 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12226 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12227 + (tm.tm_hour * 3600000));
d62a17ae 12228
12229 /* Configured timer values. */
12230 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12231 p->v_holdtime * 1000);
12232 json_object_int_add(json_neigh,
12233 "bgpTimerKeepAliveIntervalMsecs",
12234 p->v_keepalive * 1000);
d43114f3
DS
12235 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12236 json_object_int_add(json_neigh,
12237 "bgpTimerDelayOpenTimeMsecs",
12238 p->v_delayopen * 1000);
12239 }
12240
4ab46701
AR
12241 /* Configured and Synced tcp-mss value for peer */
12242 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12243 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12244 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12245 p->tcp_mss);
12246 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12247 sync_tcp_mss);
12248 }
12249
b90a8e13 12250 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12251 json_object_int_add(json_neigh,
12252 "bgpTimerConfiguredHoldTimeMsecs",
12253 p->holdtime * 1000);
12254 json_object_int_add(
12255 json_neigh,
12256 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12257 p->keepalive * 1000);
5d5393b9
DL
12258 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12259 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12260 json_object_int_add(json_neigh,
12261 "bgpTimerConfiguredHoldTimeMsecs",
12262 bgp->default_holdtime);
12263 json_object_int_add(
12264 json_neigh,
12265 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12266 bgp->default_keepalive);
d62a17ae 12267 }
12268 } else {
12269 /* Administrative shutdown. */
cb9196e7
DS
12270 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12271 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12272 vty_out(vty, " Administratively shut down\n");
12273
12274 /* BGP Version. */
12275 vty_out(vty, " BGP version 4");
0e38aeb4 12276 vty_out(vty, ", remote router ID %s",
d62a17ae 12277 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12278 vty_out(vty, ", local router ID %s\n",
12279 inet_ntop(AF_INET, &bgp->router_id, buf1,
12280 sizeof(buf1)));
d62a17ae 12281
12282 /* Confederation */
12283 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12284 && bgp_confederation_peers_check(bgp, p->as))
12285 vty_out(vty,
12286 " Neighbor under common administration\n");
12287
12288 /* Status. */
12289 vty_out(vty, " BGP state = %s",
12290 lookup_msg(bgp_status_msg, p->status, NULL));
12291
feb17238 12292 if (peer_established(p))
d62a17ae 12293 vty_out(vty, ", up for %8s",
12294 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12295 0, NULL));
12296
12297 else if (p->status == Active) {
12298 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12299 vty_out(vty, " (passive)");
12300 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12301 vty_out(vty, " (NSF passive)");
12302 }
12303 vty_out(vty, "\n");
12304
12305 /* read timer */
12306 vty_out(vty, " Last read %s",
12307 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12308 NULL));
12309 vty_out(vty, ", Last write %s\n",
12310 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12311 NULL));
12312
12313 /* Configured timer values. */
12314 vty_out(vty,
12315 " Hold time is %d, keepalive interval is %d seconds\n",
12316 p->v_holdtime, p->v_keepalive);
b90a8e13 12317 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12318 vty_out(vty, " Configured hold time is %d",
12319 p->holdtime);
12320 vty_out(vty, ", keepalive interval is %d seconds\n",
12321 p->keepalive);
5d5393b9
DL
12322 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12323 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12324 vty_out(vty, " Configured hold time is %d",
12325 bgp->default_holdtime);
12326 vty_out(vty, ", keepalive interval is %d seconds\n",
12327 bgp->default_keepalive);
d62a17ae 12328 }
d43114f3
DS
12329 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12330 vty_out(vty,
12331 " Configured DelayOpenTime is %d seconds\n",
12332 p->delayopen);
4ab46701
AR
12333
12334 /* Configured and synced tcp-mss value for peer */
12335 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12336 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12337 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12338 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12339 }
d62a17ae 12340 }
12341 /* Capability. */
feb17238 12342 if (peer_established(p)) {
d62a17ae 12343 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12344 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12345 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12346 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12347 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12348 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12349 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12350 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12351 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12352 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12353 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12354 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 12355 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12356 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 12357 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12358 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 12359 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12360 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 12361 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12362 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12363 if (use_json) {
12364 json_object *json_cap = NULL;
12365
12366 json_cap = json_object_new_object();
12367
12368 /* AS4 */
12369 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12370 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12371 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12372 && CHECK_FLAG(p->cap,
12373 PEER_CAP_AS4_RCV))
12374 json_object_string_add(
12375 json_cap, "4byteAs",
12376 "advertisedAndReceived");
12377 else if (CHECK_FLAG(p->cap,
12378 PEER_CAP_AS4_ADV))
12379 json_object_string_add(
12380 json_cap, "4byteAs",
12381 "advertised");
12382 else if (CHECK_FLAG(p->cap,
12383 PEER_CAP_AS4_RCV))
12384 json_object_string_add(
12385 json_cap, "4byteAs",
12386 "received");
12387 }
12388
ef56aee4
DA
12389 /* Extended Message Support */
12390 if (CHECK_FLAG(p->cap,
12391 PEER_CAP_EXTENDED_MESSAGE_ADV)
12392 && CHECK_FLAG(
12393 p->cap,
12394 PEER_CAP_EXTENDED_MESSAGE_RCV))
12395 json_object_string_add(
12396 json_cap, "extendedMessage",
12397 "advertisedAndReceived");
12398 else if (CHECK_FLAG(
12399 p->cap,
12400 PEER_CAP_EXTENDED_MESSAGE_ADV))
12401 json_object_string_add(
12402 json_cap, "extendedMessage",
12403 "advertised");
12404 else if (CHECK_FLAG(
12405 p->cap,
12406 PEER_CAP_EXTENDED_MESSAGE_RCV))
12407 json_object_string_add(
12408 json_cap, "extendedMessage",
12409 "received");
12410
d62a17ae 12411 /* AddPath */
12412 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12413 || CHECK_FLAG(p->cap,
12414 PEER_CAP_ADDPATH_ADV)) {
12415 json_object *json_add = NULL;
12416 const char *print_store;
12417
12418 json_add = json_object_new_object();
12419
05c7a1cc
QY
12420 FOREACH_AFI_SAFI (afi, safi) {
12421 json_object *json_sub = NULL;
12422 json_sub =
12423 json_object_new_object();
5cb5f4d0
DD
12424 print_store = get_afi_safi_str(
12425 afi, safi, true);
d62a17ae 12426
05c7a1cc
QY
12427 if (CHECK_FLAG(
12428 p->af_cap[afi]
12429 [safi],
12430 PEER_CAP_ADDPATH_AF_TX_ADV)
12431 || CHECK_FLAG(
12432 p->af_cap[afi]
12433 [safi],
12434 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 12435 if (CHECK_FLAG(
12436 p->af_cap
12437 [afi]
12438 [safi],
12439 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 12440 && CHECK_FLAG(
d62a17ae 12441 p->af_cap
12442 [afi]
12443 [safi],
05c7a1cc
QY
12444 PEER_CAP_ADDPATH_AF_TX_RCV))
12445 json_object_boolean_true_add(
12446 json_sub,
12447 "txAdvertisedAndReceived");
12448 else if (
12449 CHECK_FLAG(
12450 p->af_cap
12451 [afi]
12452 [safi],
12453 PEER_CAP_ADDPATH_AF_TX_ADV))
12454 json_object_boolean_true_add(
12455 json_sub,
12456 "txAdvertised");
12457 else if (
12458 CHECK_FLAG(
12459 p->af_cap
12460 [afi]
12461 [safi],
12462 PEER_CAP_ADDPATH_AF_TX_RCV))
12463 json_object_boolean_true_add(
12464 json_sub,
12465 "txReceived");
12466 }
d62a17ae 12467
05c7a1cc
QY
12468 if (CHECK_FLAG(
12469 p->af_cap[afi]
12470 [safi],
12471 PEER_CAP_ADDPATH_AF_RX_ADV)
12472 || CHECK_FLAG(
12473 p->af_cap[afi]
12474 [safi],
12475 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 12476 if (CHECK_FLAG(
12477 p->af_cap
12478 [afi]
12479 [safi],
12480 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 12481 && CHECK_FLAG(
d62a17ae 12482 p->af_cap
12483 [afi]
12484 [safi],
12485 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
12486 json_object_boolean_true_add(
12487 json_sub,
12488 "rxAdvertisedAndReceived");
12489 else if (
12490 CHECK_FLAG(
12491 p->af_cap
12492 [afi]
12493 [safi],
12494 PEER_CAP_ADDPATH_AF_RX_ADV))
12495 json_object_boolean_true_add(
12496 json_sub,
12497 "rxAdvertised");
12498 else if (
12499 CHECK_FLAG(
12500 p->af_cap
12501 [afi]
12502 [safi],
12503 PEER_CAP_ADDPATH_AF_RX_RCV))
12504 json_object_boolean_true_add(
12505 json_sub,
12506 "rxReceived");
d62a17ae 12507 }
12508
05c7a1cc
QY
12509 if (CHECK_FLAG(
12510 p->af_cap[afi]
12511 [safi],
12512 PEER_CAP_ADDPATH_AF_TX_ADV)
12513 || CHECK_FLAG(
12514 p->af_cap[afi]
12515 [safi],
12516 PEER_CAP_ADDPATH_AF_TX_RCV)
12517 || CHECK_FLAG(
12518 p->af_cap[afi]
12519 [safi],
12520 PEER_CAP_ADDPATH_AF_RX_ADV)
12521 || CHECK_FLAG(
12522 p->af_cap[afi]
12523 [safi],
12524 PEER_CAP_ADDPATH_AF_RX_RCV))
12525 json_object_object_add(
12526 json_add,
12527 print_store,
12528 json_sub);
12529 else
12530 json_object_free(
12531 json_sub);
12532 }
12533
d62a17ae 12534 json_object_object_add(
12535 json_cap, "addPath", json_add);
12536 }
12537
12538 /* Dynamic */
12539 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12540 || CHECK_FLAG(p->cap,
12541 PEER_CAP_DYNAMIC_ADV)) {
12542 if (CHECK_FLAG(p->cap,
12543 PEER_CAP_DYNAMIC_ADV)
12544 && CHECK_FLAG(p->cap,
12545 PEER_CAP_DYNAMIC_RCV))
12546 json_object_string_add(
12547 json_cap, "dynamic",
12548 "advertisedAndReceived");
12549 else if (CHECK_FLAG(
12550 p->cap,
12551 PEER_CAP_DYNAMIC_ADV))
12552 json_object_string_add(
12553 json_cap, "dynamic",
12554 "advertised");
12555 else if (CHECK_FLAG(
12556 p->cap,
12557 PEER_CAP_DYNAMIC_RCV))
12558 json_object_string_add(
12559 json_cap, "dynamic",
12560 "received");
12561 }
12562
12563 /* Extended nexthop */
12564 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12565 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12566 json_object *json_nxt = NULL;
12567 const char *print_store;
12568
12569
12570 if (CHECK_FLAG(p->cap,
12571 PEER_CAP_ENHE_ADV)
12572 && CHECK_FLAG(p->cap,
12573 PEER_CAP_ENHE_RCV))
12574 json_object_string_add(
12575 json_cap,
12576 "extendedNexthop",
12577 "advertisedAndReceived");
12578 else if (CHECK_FLAG(p->cap,
12579 PEER_CAP_ENHE_ADV))
12580 json_object_string_add(
12581 json_cap,
12582 "extendedNexthop",
12583 "advertised");
12584 else if (CHECK_FLAG(p->cap,
12585 PEER_CAP_ENHE_RCV))
12586 json_object_string_add(
12587 json_cap,
12588 "extendedNexthop",
12589 "received");
12590
12591 if (CHECK_FLAG(p->cap,
12592 PEER_CAP_ENHE_RCV)) {
12593 json_nxt =
12594 json_object_new_object();
12595
12596 for (safi = SAFI_UNICAST;
12597 safi < SAFI_MAX; safi++) {
12598 if (CHECK_FLAG(
12599 p->af_cap
12600 [AFI_IP]
12601 [safi],
12602 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 12603 print_store = get_afi_safi_str(
d62a17ae 12604 AFI_IP,
5cb5f4d0 12605 safi, true);
d62a17ae 12606 json_object_string_add(
12607 json_nxt,
12608 print_store,
54f29523 12609 "recieved"); /* misspelled for compatibility */
d62a17ae 12610 }
12611 }
12612 json_object_object_add(
12613 json_cap,
12614 "extendedNexthopFamililesByPeer",
12615 json_nxt);
12616 }
12617 }
12618
12619 /* Route Refresh */
12620 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12621 || CHECK_FLAG(p->cap,
12622 PEER_CAP_REFRESH_NEW_RCV)
12623 || CHECK_FLAG(p->cap,
12624 PEER_CAP_REFRESH_OLD_RCV)) {
12625 if (CHECK_FLAG(p->cap,
12626 PEER_CAP_REFRESH_ADV)
12627 && (CHECK_FLAG(
12628 p->cap,
12629 PEER_CAP_REFRESH_NEW_RCV)
12630 || CHECK_FLAG(
12631 p->cap,
12632 PEER_CAP_REFRESH_OLD_RCV))) {
12633 if (CHECK_FLAG(
12634 p->cap,
12635 PEER_CAP_REFRESH_OLD_RCV)
12636 && CHECK_FLAG(
12637 p->cap,
12638 PEER_CAP_REFRESH_NEW_RCV))
12639 json_object_string_add(
12640 json_cap,
12641 "routeRefresh",
12642 "advertisedAndReceivedOldNew");
12643 else {
12644 if (CHECK_FLAG(
12645 p->cap,
12646 PEER_CAP_REFRESH_OLD_RCV))
12647 json_object_string_add(
12648 json_cap,
12649 "routeRefresh",
12650 "advertisedAndReceivedOld");
12651 else
12652 json_object_string_add(
12653 json_cap,
12654 "routeRefresh",
12655 "advertisedAndReceivedNew");
12656 }
12657 } else if (
12658 CHECK_FLAG(
12659 p->cap,
12660 PEER_CAP_REFRESH_ADV))
12661 json_object_string_add(
12662 json_cap,
12663 "routeRefresh",
12664 "advertised");
12665 else if (
12666 CHECK_FLAG(
12667 p->cap,
12668 PEER_CAP_REFRESH_NEW_RCV)
12669 || CHECK_FLAG(
12670 p->cap,
12671 PEER_CAP_REFRESH_OLD_RCV))
12672 json_object_string_add(
12673 json_cap,
12674 "routeRefresh",
12675 "received");
12676 }
12677
9af52ccf
DA
12678 /* Enhanced Route Refresh */
12679 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
12680 || CHECK_FLAG(p->cap,
12681 PEER_CAP_ENHANCED_RR_RCV)) {
12682 if (CHECK_FLAG(p->cap,
12683 PEER_CAP_ENHANCED_RR_ADV)
12684 && CHECK_FLAG(
12685 p->cap,
12686 PEER_CAP_ENHANCED_RR_RCV))
12687 json_object_string_add(
12688 json_cap,
12689 "enhancedRouteRefresh",
12690 "advertisedAndReceived");
12691 else if (
12692 CHECK_FLAG(
12693 p->cap,
12694 PEER_CAP_ENHANCED_RR_ADV))
12695 json_object_string_add(
12696 json_cap,
12697 "enhancedRouteRefresh",
12698 "advertised");
12699 else if (
12700 CHECK_FLAG(
12701 p->cap,
12702 PEER_CAP_ENHANCED_RR_RCV))
12703 json_object_string_add(
12704 json_cap,
12705 "enhancedRouteRefresh",
12706 "received");
12707 }
12708
d62a17ae 12709 /* Multiprotocol Extensions */
12710 json_object *json_multi = NULL;
12711 json_multi = json_object_new_object();
12712
05c7a1cc
QY
12713 FOREACH_AFI_SAFI (afi, safi) {
12714 if (p->afc_adv[afi][safi]
12715 || p->afc_recv[afi][safi]) {
12716 json_object *json_exten = NULL;
12717 json_exten =
12718 json_object_new_object();
12719
d62a17ae 12720 if (p->afc_adv[afi][safi]
05c7a1cc
QY
12721 && p->afc_recv[afi][safi])
12722 json_object_boolean_true_add(
12723 json_exten,
12724 "advertisedAndReceived");
12725 else if (p->afc_adv[afi][safi])
12726 json_object_boolean_true_add(
12727 json_exten,
12728 "advertised");
12729 else if (p->afc_recv[afi][safi])
12730 json_object_boolean_true_add(
12731 json_exten,
12732 "received");
d62a17ae 12733
05c7a1cc
QY
12734 json_object_object_add(
12735 json_multi,
5cb5f4d0
DD
12736 get_afi_safi_str(afi,
12737 safi,
12738 true),
05c7a1cc 12739 json_exten);
d62a17ae 12740 }
12741 }
12742 json_object_object_add(
12743 json_cap, "multiprotocolExtensions",
12744 json_multi);
12745
d77114b7 12746 /* Hostname capabilities */
60466a63 12747 json_object *json_hname = NULL;
d77114b7
MK
12748
12749 json_hname = json_object_new_object();
12750
12751 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12752 json_object_string_add(
60466a63
QY
12753 json_hname, "advHostName",
12754 bgp->peer_self->hostname
12755 ? bgp->peer_self
12756 ->hostname
d77114b7
MK
12757 : "n/a");
12758 json_object_string_add(
60466a63
QY
12759 json_hname, "advDomainName",
12760 bgp->peer_self->domainname
12761 ? bgp->peer_self
12762 ->domainname
d77114b7
MK
12763 : "n/a");
12764 }
12765
12766
12767 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12768 json_object_string_add(
60466a63
QY
12769 json_hname, "rcvHostName",
12770 p->hostname ? p->hostname
12771 : "n/a");
d77114b7 12772 json_object_string_add(
60466a63
QY
12773 json_hname, "rcvDomainName",
12774 p->domainname ? p->domainname
12775 : "n/a");
d77114b7
MK
12776 }
12777
60466a63 12778 json_object_object_add(json_cap, "hostName",
d77114b7
MK
12779 json_hname);
12780
d62a17ae 12781 /* Gracefull Restart */
12782 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12783 || CHECK_FLAG(p->cap,
12784 PEER_CAP_RESTART_ADV)) {
12785 if (CHECK_FLAG(p->cap,
12786 PEER_CAP_RESTART_ADV)
12787 && CHECK_FLAG(p->cap,
12788 PEER_CAP_RESTART_RCV))
12789 json_object_string_add(
12790 json_cap,
12791 "gracefulRestart",
12792 "advertisedAndReceived");
12793 else if (CHECK_FLAG(
12794 p->cap,
12795 PEER_CAP_RESTART_ADV))
12796 json_object_string_add(
12797 json_cap,
12798 "gracefulRestartCapability",
12799 "advertised");
12800 else if (CHECK_FLAG(
12801 p->cap,
12802 PEER_CAP_RESTART_RCV))
12803 json_object_string_add(
12804 json_cap,
12805 "gracefulRestartCapability",
12806 "received");
12807
12808 if (CHECK_FLAG(p->cap,
12809 PEER_CAP_RESTART_RCV)) {
12810 int restart_af_count = 0;
12811 json_object *json_restart =
12812 NULL;
12813 json_restart =
12814 json_object_new_object();
12815
12816 json_object_int_add(
12817 json_cap,
12818 "gracefulRestartRemoteTimerMsecs",
12819 p->v_gr_restart * 1000);
12820
05c7a1cc
QY
12821 FOREACH_AFI_SAFI (afi, safi) {
12822 if (CHECK_FLAG(
12823 p->af_cap
12824 [afi]
12825 [safi],
12826 PEER_CAP_RESTART_AF_RCV)) {
12827 json_object *
12828 json_sub =
12829 NULL;
12830 json_sub =
12831 json_object_new_object();
12832
d62a17ae 12833 if (CHECK_FLAG(
12834 p->af_cap
12835 [afi]
12836 [safi],
05c7a1cc
QY
12837 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12838 json_object_boolean_true_add(
12839 json_sub,
12840 "preserved");
12841 restart_af_count++;
12842 json_object_object_add(
12843 json_restart,
5cb5f4d0 12844 get_afi_safi_str(
05c7a1cc 12845 afi,
5cb5f4d0
DD
12846 safi,
12847 true),
05c7a1cc 12848 json_sub);
d62a17ae 12849 }
12850 }
12851 if (!restart_af_count) {
12852 json_object_string_add(
12853 json_cap,
12854 "addressFamiliesByPeer",
12855 "none");
12856 json_object_free(
12857 json_restart);
12858 } else
12859 json_object_object_add(
12860 json_cap,
12861 "addressFamiliesByPeer",
12862 json_restart);
12863 }
12864 }
12865 json_object_object_add(json_neigh,
12866 "neighborCapabilities",
12867 json_cap);
12868 } else {
12869 vty_out(vty, " Neighbor capabilities:\n");
12870
12871 /* AS4 */
12872 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12873 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12874 vty_out(vty, " 4 Byte AS:");
12875 if (CHECK_FLAG(p->cap,
12876 PEER_CAP_AS4_ADV))
12877 vty_out(vty, " advertised");
12878 if (CHECK_FLAG(p->cap,
12879 PEER_CAP_AS4_RCV))
12880 vty_out(vty, " %sreceived",
12881 CHECK_FLAG(
12882 p->cap,
12883 PEER_CAP_AS4_ADV)
12884 ? "and "
12885 : "");
12886 vty_out(vty, "\n");
12887 }
12888
ef56aee4
DA
12889 /* Extended Message Support */
12890 if (CHECK_FLAG(p->cap,
12891 PEER_CAP_EXTENDED_MESSAGE_RCV)
12892 || CHECK_FLAG(
12893 p->cap,
12894 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
12895 vty_out(vty, " Extended Message:");
12896 if (CHECK_FLAG(
12897 p->cap,
12898 PEER_CAP_EXTENDED_MESSAGE_ADV))
12899 vty_out(vty, " advertised");
12900 if (CHECK_FLAG(
12901 p->cap,
12902 PEER_CAP_EXTENDED_MESSAGE_RCV))
12903 vty_out(vty, " %sreceived",
12904 CHECK_FLAG(
12905 p->cap,
12906 PEER_CAP_EXTENDED_MESSAGE_ADV)
12907 ? "and "
12908 : "");
12909 vty_out(vty, "\n");
12910 }
12911
d62a17ae 12912 /* AddPath */
12913 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12914 || CHECK_FLAG(p->cap,
12915 PEER_CAP_ADDPATH_ADV)) {
12916 vty_out(vty, " AddPath:\n");
12917
05c7a1cc
QY
12918 FOREACH_AFI_SAFI (afi, safi) {
12919 if (CHECK_FLAG(
12920 p->af_cap[afi]
12921 [safi],
12922 PEER_CAP_ADDPATH_AF_TX_ADV)
12923 || CHECK_FLAG(
12924 p->af_cap[afi]
12925 [safi],
12926 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12927 vty_out(vty,
12928 " %s: TX ",
5cb5f4d0 12929 get_afi_safi_str(
05c7a1cc 12930 afi,
5cb5f4d0
DD
12931 safi,
12932 false));
05c7a1cc 12933
d62a17ae 12934 if (CHECK_FLAG(
12935 p->af_cap
12936 [afi]
12937 [safi],
05c7a1cc 12938 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 12939 vty_out(vty,
05c7a1cc 12940 "advertised %s",
5cb5f4d0 12941 get_afi_safi_str(
d62a17ae 12942 afi,
5cb5f4d0
DD
12943 safi,
12944 false));
d62a17ae 12945
05c7a1cc
QY
12946 if (CHECK_FLAG(
12947 p->af_cap
12948 [afi]
12949 [safi],
12950 PEER_CAP_ADDPATH_AF_TX_RCV))
12951 vty_out(vty,
12952 "%sreceived",
12953 CHECK_FLAG(
12954 p->af_cap
12955 [afi]
12956 [safi],
12957 PEER_CAP_ADDPATH_AF_TX_ADV)
12958 ? " and "
12959 : "");
d62a17ae 12960
05c7a1cc
QY
12961 vty_out(vty, "\n");
12962 }
d62a17ae 12963
05c7a1cc
QY
12964 if (CHECK_FLAG(
12965 p->af_cap[afi]
12966 [safi],
12967 PEER_CAP_ADDPATH_AF_RX_ADV)
12968 || CHECK_FLAG(
12969 p->af_cap[afi]
12970 [safi],
12971 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12972 vty_out(vty,
12973 " %s: RX ",
5cb5f4d0 12974 get_afi_safi_str(
05c7a1cc 12975 afi,
5cb5f4d0
DD
12976 safi,
12977 false));
d62a17ae 12978
12979 if (CHECK_FLAG(
12980 p->af_cap
12981 [afi]
12982 [safi],
05c7a1cc 12983 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 12984 vty_out(vty,
05c7a1cc 12985 "advertised %s",
5cb5f4d0 12986 get_afi_safi_str(
d62a17ae 12987 afi,
5cb5f4d0
DD
12988 safi,
12989 false));
d62a17ae 12990
05c7a1cc
QY
12991 if (CHECK_FLAG(
12992 p->af_cap
12993 [afi]
12994 [safi],
12995 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 12996 vty_out(vty,
05c7a1cc
QY
12997 "%sreceived",
12998 CHECK_FLAG(
12999 p->af_cap
13000 [afi]
13001 [safi],
13002 PEER_CAP_ADDPATH_AF_RX_ADV)
13003 ? " and "
13004 : "");
13005
13006 vty_out(vty, "\n");
d62a17ae 13007 }
05c7a1cc 13008 }
d62a17ae 13009 }
13010
13011 /* Dynamic */
13012 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13013 || CHECK_FLAG(p->cap,
13014 PEER_CAP_DYNAMIC_ADV)) {
13015 vty_out(vty, " Dynamic:");
13016 if (CHECK_FLAG(p->cap,
13017 PEER_CAP_DYNAMIC_ADV))
13018 vty_out(vty, " advertised");
13019 if (CHECK_FLAG(p->cap,
13020 PEER_CAP_DYNAMIC_RCV))
13021 vty_out(vty, " %sreceived",
13022 CHECK_FLAG(
13023 p->cap,
13024 PEER_CAP_DYNAMIC_ADV)
13025 ? "and "
13026 : "");
13027 vty_out(vty, "\n");
13028 }
13029
13030 /* Extended nexthop */
13031 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13032 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13033 vty_out(vty, " Extended nexthop:");
13034 if (CHECK_FLAG(p->cap,
13035 PEER_CAP_ENHE_ADV))
13036 vty_out(vty, " advertised");
13037 if (CHECK_FLAG(p->cap,
13038 PEER_CAP_ENHE_RCV))
13039 vty_out(vty, " %sreceived",
13040 CHECK_FLAG(
13041 p->cap,
13042 PEER_CAP_ENHE_ADV)
13043 ? "and "
13044 : "");
13045 vty_out(vty, "\n");
13046
13047 if (CHECK_FLAG(p->cap,
13048 PEER_CAP_ENHE_RCV)) {
13049 vty_out(vty,
13050 " Address families by peer:\n ");
13051 for (safi = SAFI_UNICAST;
13052 safi < SAFI_MAX; safi++)
13053 if (CHECK_FLAG(
13054 p->af_cap
13055 [AFI_IP]
13056 [safi],
13057 PEER_CAP_ENHE_AF_RCV))
13058 vty_out(vty,
13059 " %s\n",
5cb5f4d0 13060 get_afi_safi_str(
d62a17ae 13061 AFI_IP,
5cb5f4d0
DD
13062 safi,
13063 false));
d62a17ae 13064 }
13065 }
13066
13067 /* Route Refresh */
13068 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13069 || CHECK_FLAG(p->cap,
13070 PEER_CAP_REFRESH_NEW_RCV)
13071 || CHECK_FLAG(p->cap,
13072 PEER_CAP_REFRESH_OLD_RCV)) {
13073 vty_out(vty, " Route refresh:");
13074 if (CHECK_FLAG(p->cap,
13075 PEER_CAP_REFRESH_ADV))
13076 vty_out(vty, " advertised");
13077 if (CHECK_FLAG(p->cap,
13078 PEER_CAP_REFRESH_NEW_RCV)
13079 || CHECK_FLAG(
13080 p->cap,
13081 PEER_CAP_REFRESH_OLD_RCV))
13082 vty_out(vty, " %sreceived(%s)",
13083 CHECK_FLAG(
13084 p->cap,
13085 PEER_CAP_REFRESH_ADV)
13086 ? "and "
13087 : "",
13088 (CHECK_FLAG(
13089 p->cap,
13090 PEER_CAP_REFRESH_OLD_RCV)
13091 && CHECK_FLAG(
13092 p->cap,
13093 PEER_CAP_REFRESH_NEW_RCV))
13094 ? "old & new"
13095 : CHECK_FLAG(
13096 p->cap,
13097 PEER_CAP_REFRESH_OLD_RCV)
13098 ? "old"
13099 : "new");
13100
13101 vty_out(vty, "\n");
13102 }
13103
9af52ccf
DA
13104 /* Enhanced Route Refresh */
13105 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13106 || CHECK_FLAG(p->cap,
13107 PEER_CAP_ENHANCED_RR_RCV)) {
13108 vty_out(vty,
13109 " Enhanced Route Refresh:");
13110 if (CHECK_FLAG(
13111 p->cap,
13112 PEER_CAP_ENHANCED_RR_ADV))
13113 vty_out(vty, " advertised");
13114 if (CHECK_FLAG(
13115 p->cap,
13116 PEER_CAP_ENHANCED_RR_RCV))
13117 vty_out(vty, " %sreceived",
13118 CHECK_FLAG(
13119 p->cap,
13120 PEER_CAP_REFRESH_ADV)
13121 ? "and "
13122 : "");
13123 vty_out(vty, "\n");
13124 }
13125
d62a17ae 13126 /* Multiprotocol Extensions */
05c7a1cc
QY
13127 FOREACH_AFI_SAFI (afi, safi)
13128 if (p->afc_adv[afi][safi]
13129 || p->afc_recv[afi][safi]) {
13130 vty_out(vty,
13131 " Address Family %s:",
5cb5f4d0
DD
13132 get_afi_safi_str(
13133 afi,
13134 safi,
13135 false));
05c7a1cc 13136 if (p->afc_adv[afi][safi])
d62a17ae 13137 vty_out(vty,
05c7a1cc
QY
13138 " advertised");
13139 if (p->afc_recv[afi][safi])
13140 vty_out(vty,
13141 " %sreceived",
13142 p->afc_adv[afi]
13143 [safi]
13144 ? "and "
13145 : "");
13146 vty_out(vty, "\n");
13147 }
d62a17ae 13148
13149 /* Hostname capability */
60466a63 13150 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13151
13152 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13153 vty_out(vty,
13154 " advertised (name: %s,domain name: %s)",
60466a63
QY
13155 bgp->peer_self->hostname
13156 ? bgp->peer_self
13157 ->hostname
d77114b7 13158 : "n/a",
60466a63
QY
13159 bgp->peer_self->domainname
13160 ? bgp->peer_self
13161 ->domainname
d77114b7
MK
13162 : "n/a");
13163 } else {
13164 vty_out(vty, " not advertised");
d62a17ae 13165 }
13166
d77114b7 13167 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13168 vty_out(vty,
13169 " received (name: %s,domain name: %s)",
60466a63
QY
13170 p->hostname ? p->hostname
13171 : "n/a",
13172 p->domainname ? p->domainname
13173 : "n/a");
d77114b7
MK
13174 } else {
13175 vty_out(vty, " not received");
13176 }
13177
13178 vty_out(vty, "\n");
13179
61bfbd51 13180 /* Graceful Restart */
d62a17ae 13181 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13182 || CHECK_FLAG(p->cap,
13183 PEER_CAP_RESTART_ADV)) {
13184 vty_out(vty,
61bfbd51 13185 " Graceful Restart Capability:");
d62a17ae 13186 if (CHECK_FLAG(p->cap,
13187 PEER_CAP_RESTART_ADV))
13188 vty_out(vty, " advertised");
13189 if (CHECK_FLAG(p->cap,
13190 PEER_CAP_RESTART_RCV))
13191 vty_out(vty, " %sreceived",
13192 CHECK_FLAG(
13193 p->cap,
13194 PEER_CAP_RESTART_ADV)
13195 ? "and "
13196 : "");
13197 vty_out(vty, "\n");
13198
13199 if (CHECK_FLAG(p->cap,
13200 PEER_CAP_RESTART_RCV)) {
13201 int restart_af_count = 0;
13202
13203 vty_out(vty,
13204 " Remote Restart timer is %d seconds\n",
13205 p->v_gr_restart);
13206 vty_out(vty,
13207 " Address families by peer:\n ");
13208
05c7a1cc
QY
13209 FOREACH_AFI_SAFI (afi, safi)
13210 if (CHECK_FLAG(
13211 p->af_cap
13212 [afi]
13213 [safi],
13214 PEER_CAP_RESTART_AF_RCV)) {
13215 vty_out(vty,
13216 "%s%s(%s)",
13217 restart_af_count
13218 ? ", "
13219 : "",
5cb5f4d0 13220 get_afi_safi_str(
05c7a1cc 13221 afi,
5cb5f4d0
DD
13222 safi,
13223 false),
05c7a1cc
QY
13224 CHECK_FLAG(
13225 p->af_cap
13226 [afi]
13227 [safi],
13228 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13229 ? "preserved"
13230 : "not preserved");
13231 restart_af_count++;
13232 }
d62a17ae 13233 if (!restart_af_count)
13234 vty_out(vty, "none");
13235 vty_out(vty, "\n");
13236 }
2986cac2 13237 } /* Gracefull Restart */
d62a17ae 13238 }
13239 }
13240 }
13241
13242 /* graceful restart information */
d62a17ae 13243 json_object *json_grace = NULL;
13244 json_object *json_grace_send = NULL;
13245 json_object *json_grace_recv = NULL;
13246 int eor_send_af_count = 0;
13247 int eor_receive_af_count = 0;
13248
13249 if (use_json) {
13250 json_grace = json_object_new_object();
13251 json_grace_send = json_object_new_object();
13252 json_grace_recv = json_object_new_object();
13253
feb17238 13254 if ((peer_established(p))
36235319 13255 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
13256 FOREACH_AFI_SAFI (afi, safi) {
13257 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 13258 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
13259 json_object_boolean_true_add(
13260 json_grace_send,
5cb5f4d0
DD
13261 get_afi_safi_str(afi,
13262 safi,
13263 true));
05c7a1cc 13264 eor_send_af_count++;
d62a17ae 13265 }
13266 }
05c7a1cc
QY
13267 FOREACH_AFI_SAFI (afi, safi) {
13268 if (CHECK_FLAG(
36235319
QY
13269 p->af_sflags[afi][safi],
13270 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
13271 json_object_boolean_true_add(
13272 json_grace_recv,
5cb5f4d0
DD
13273 get_afi_safi_str(afi,
13274 safi,
13275 true));
05c7a1cc 13276 eor_receive_af_count++;
d62a17ae 13277 }
13278 }
13279 }
36235319
QY
13280 json_object_object_add(json_grace, "endOfRibSend",
13281 json_grace_send);
13282 json_object_object_add(json_grace, "endOfRibRecv",
13283 json_grace_recv);
d62a17ae 13284
d62a17ae 13285
13286 if (p->t_gr_restart)
13287 json_object_int_add(json_grace,
13288 "gracefulRestartTimerMsecs",
13289 thread_timer_remain_second(
13290 p->t_gr_restart)
13291 * 1000);
13292
13293 if (p->t_gr_stale)
13294 json_object_int_add(
13295 json_grace,
13296 "gracefulStalepathTimerMsecs",
13297 thread_timer_remain_second(
13298 p->t_gr_stale)
13299 * 1000);
2986cac2 13300 /* more gr info in new format */
13301 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 13302 json_grace);
d62a17ae 13303 json_object_object_add(
13304 json_neigh, "gracefulRestartInfo", json_grace);
13305 } else {
2089dd80 13306 vty_out(vty, " Graceful restart information:\n");
feb17238 13307 if ((peer_established(p))
36235319 13308 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 13309
d62a17ae 13310 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
13311 FOREACH_AFI_SAFI (afi, safi) {
13312 if (CHECK_FLAG(p->af_sflags[afi][safi],
13313 PEER_STATUS_EOR_SEND)) {
13314 vty_out(vty, "%s%s",
13315 eor_send_af_count ? ", "
13316 : "",
36235319
QY
13317 get_afi_safi_str(
13318 afi, safi,
13319 false));
05c7a1cc 13320 eor_send_af_count++;
d62a17ae 13321 }
13322 }
13323 vty_out(vty, "\n");
13324 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
13325 FOREACH_AFI_SAFI (afi, safi) {
13326 if (CHECK_FLAG(
13327 p->af_sflags[afi][safi],
13328 PEER_STATUS_EOR_RECEIVED)) {
13329 vty_out(vty, "%s%s",
13330 eor_receive_af_count
13331 ? ", "
13332 : "",
5cb5f4d0
DD
13333 get_afi_safi_str(afi,
13334 safi,
13335 false));
05c7a1cc 13336 eor_receive_af_count++;
d62a17ae 13337 }
13338 }
13339 vty_out(vty, "\n");
13340 }
13341
13342 if (p->t_gr_restart)
13343 vty_out(vty,
13344 " The remaining time of restart timer is %ld\n",
13345 thread_timer_remain_second(
13346 p->t_gr_restart));
13347
13348 if (p->t_gr_stale)
13349 vty_out(vty,
13350 " The remaining time of stalepath timer is %ld\n",
13351 thread_timer_remain_second(
13352 p->t_gr_stale));
2986cac2 13353
13354 /* more gr info in new format */
13355 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 13356 }
2986cac2 13357
d62a17ae 13358 if (use_json) {
13359 json_object *json_stat = NULL;
13360 json_stat = json_object_new_object();
13361 /* Packet counts. */
43aa5965
QY
13362
13363 atomic_size_t outq_count, inq_count;
13364 outq_count = atomic_load_explicit(&p->obuf->count,
13365 memory_order_relaxed);
13366 inq_count = atomic_load_explicit(&p->ibuf->count,
13367 memory_order_relaxed);
13368
13369 json_object_int_add(json_stat, "depthInq",
13370 (unsigned long)inq_count);
d62a17ae 13371 json_object_int_add(json_stat, "depthOutq",
43aa5965 13372 (unsigned long)outq_count);
0112e9e0
QY
13373 json_object_int_add(json_stat, "opensSent",
13374 atomic_load_explicit(&p->open_out,
13375 memory_order_relaxed));
13376 json_object_int_add(json_stat, "opensRecv",
13377 atomic_load_explicit(&p->open_in,
13378 memory_order_relaxed));
d62a17ae 13379 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13380 atomic_load_explicit(&p->notify_out,
13381 memory_order_relaxed));
d62a17ae 13382 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13383 atomic_load_explicit(&p->notify_in,
13384 memory_order_relaxed));
13385 json_object_int_add(json_stat, "updatesSent",
13386 atomic_load_explicit(&p->update_out,
13387 memory_order_relaxed));
13388 json_object_int_add(json_stat, "updatesRecv",
13389 atomic_load_explicit(&p->update_in,
13390 memory_order_relaxed));
d62a17ae 13391 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13392 atomic_load_explicit(&p->keepalive_out,
13393 memory_order_relaxed));
d62a17ae 13394 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13395 atomic_load_explicit(&p->keepalive_in,
13396 memory_order_relaxed));
d62a17ae 13397 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13398 atomic_load_explicit(&p->refresh_out,
13399 memory_order_relaxed));
d62a17ae 13400 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13401 atomic_load_explicit(&p->refresh_in,
13402 memory_order_relaxed));
d62a17ae 13403 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13404 atomic_load_explicit(&p->dynamic_cap_out,
13405 memory_order_relaxed));
d62a17ae 13406 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13407 atomic_load_explicit(&p->dynamic_cap_in,
13408 memory_order_relaxed));
13409 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13410 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13411 json_object_object_add(json_neigh, "messageStats", json_stat);
13412 } else {
43aa5965
QY
13413 atomic_size_t outq_count, inq_count;
13414 outq_count = atomic_load_explicit(&p->obuf->count,
13415 memory_order_relaxed);
13416 inq_count = atomic_load_explicit(&p->ibuf->count,
13417 memory_order_relaxed);
13418
d62a17ae 13419 /* Packet counts. */
13420 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13421 vty_out(vty, " Inq depth is %zu\n", inq_count);
13422 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13423 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
13424 vty_out(vty, " Opens: %10d %10d\n",
13425 atomic_load_explicit(&p->open_out,
13426 memory_order_relaxed),
13427 atomic_load_explicit(&p->open_in,
13428 memory_order_relaxed));
13429 vty_out(vty, " Notifications: %10d %10d\n",
13430 atomic_load_explicit(&p->notify_out,
13431 memory_order_relaxed),
13432 atomic_load_explicit(&p->notify_in,
13433 memory_order_relaxed));
13434 vty_out(vty, " Updates: %10d %10d\n",
13435 atomic_load_explicit(&p->update_out,
13436 memory_order_relaxed),
13437 atomic_load_explicit(&p->update_in,
13438 memory_order_relaxed));
13439 vty_out(vty, " Keepalives: %10d %10d\n",
13440 atomic_load_explicit(&p->keepalive_out,
13441 memory_order_relaxed),
13442 atomic_load_explicit(&p->keepalive_in,
13443 memory_order_relaxed));
13444 vty_out(vty, " Route Refresh: %10d %10d\n",
13445 atomic_load_explicit(&p->refresh_out,
13446 memory_order_relaxed),
13447 atomic_load_explicit(&p->refresh_in,
13448 memory_order_relaxed));
d62a17ae 13449 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
13450 atomic_load_explicit(&p->dynamic_cap_out,
13451 memory_order_relaxed),
13452 atomic_load_explicit(&p->dynamic_cap_in,
13453 memory_order_relaxed));
13454 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13455 PEER_TOTAL_RX(p));
d62a17ae 13456 }
13457
13458 if (use_json) {
13459 /* advertisement-interval */
13460 json_object_int_add(json_neigh,
13461 "minBtwnAdvertisementRunsTimerMsecs",
13462 p->v_routeadv * 1000);
13463
13464 /* Update-source. */
13465 if (p->update_if || p->update_source) {
13466 if (p->update_if)
13467 json_object_string_add(json_neigh,
13468 "updateSource",
13469 p->update_if);
13470 else if (p->update_source)
13471 json_object_string_add(
13472 json_neigh, "updateSource",
13473 sockunion2str(p->update_source, buf1,
13474 SU_ADDRSTRLEN));
13475 }
13476 } else {
13477 /* advertisement-interval */
13478 vty_out(vty,
13479 " Minimum time between advertisement runs is %d seconds\n",
13480 p->v_routeadv);
13481
13482 /* Update-source. */
13483 if (p->update_if || p->update_source) {
13484 vty_out(vty, " Update source is ");
13485 if (p->update_if)
13486 vty_out(vty, "%s", p->update_if);
13487 else if (p->update_source)
13488 vty_out(vty, "%s",
13489 sockunion2str(p->update_source, buf1,
13490 SU_ADDRSTRLEN));
13491 vty_out(vty, "\n");
13492 }
13493
13494 vty_out(vty, "\n");
13495 }
13496
13497 /* Address Family Information */
13498 json_object *json_hold = NULL;
13499
13500 if (use_json)
13501 json_hold = json_object_new_object();
13502
05c7a1cc
QY
13503 FOREACH_AFI_SAFI (afi, safi)
13504 if (p->afc[afi][safi])
13505 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13506 json_hold);
d62a17ae 13507
13508 if (use_json) {
13509 json_object_object_add(json_neigh, "addressFamilyInfo",
13510 json_hold);
13511 json_object_int_add(json_neigh, "connectionsEstablished",
13512 p->established);
13513 json_object_int_add(json_neigh, "connectionsDropped",
13514 p->dropped);
13515 } else
13516 vty_out(vty, " Connections established %d; dropped %d\n",
13517 p->established, p->dropped);
13518
13519 if (!p->last_reset) {
13520 if (use_json)
13521 json_object_string_add(json_neigh, "lastReset",
13522 "never");
13523 else
13524 vty_out(vty, " Last reset never\n");
13525 } else {
13526 if (use_json) {
13527 time_t uptime;
a2700b50 13528 struct tm tm;
d62a17ae 13529
13530 uptime = bgp_clock();
13531 uptime -= p->resettime;
a2700b50
MS
13532 gmtime_r(&uptime, &tm);
13533
d62a17ae 13534 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13535 (tm.tm_sec * 1000)
13536 + (tm.tm_min * 60000)
13537 + (tm.tm_hour * 3600000));
3577f1c5 13538 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13539 } else {
13540 vty_out(vty, " Last reset %s, ",
13541 peer_uptime(p->resettime, timebuf,
13542 BGP_UPTIME_LEN, 0, NULL));
13543
3577f1c5 13544 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13545 if (p->last_reset_cause_size) {
13546 msg = p->last_reset_cause;
13547 vty_out(vty,
13548 " Message received that caused BGP to send a NOTIFICATION:\n ");
13549 for (i = 1; i <= p->last_reset_cause_size;
13550 i++) {
13551 vty_out(vty, "%02X", *msg++);
13552
13553 if (i != p->last_reset_cause_size) {
13554 if (i % 16 == 0) {
13555 vty_out(vty, "\n ");
13556 } else if (i % 4 == 0) {
13557 vty_out(vty, " ");
13558 }
13559 }
13560 }
13561 vty_out(vty, "\n");
13562 }
13563 }
13564 }
13565
13566 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13567 if (use_json)
13568 json_object_boolean_true_add(json_neigh,
13569 "prefixesConfigExceedMax");
13570 else
13571 vty_out(vty,
13572 " Peer had exceeded the max. no. of prefixes configured.\n");
13573
13574 if (p->t_pmax_restart) {
13575 if (use_json) {
13576 json_object_boolean_true_add(
13577 json_neigh, "reducePrefixNumFrom");
13578 json_object_int_add(json_neigh,
13579 "restartInTimerMsec",
13580 thread_timer_remain_second(
13581 p->t_pmax_restart)
13582 * 1000);
13583 } else
13584 vty_out(vty,
13585 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13586 p->host, thread_timer_remain_second(
13587 p->t_pmax_restart));
d62a17ae 13588 } else {
13589 if (use_json)
13590 json_object_boolean_true_add(
13591 json_neigh,
13592 "reducePrefixNumAndClearIpBgp");
13593 else
13594 vty_out(vty,
13595 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13596 p->host);
13597 }
13598 }
13599
13600 /* EBGP Multihop and GTSM */
13601 if (p->sort != BGP_PEER_IBGP) {
13602 if (use_json) {
e2521429 13603 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13604 json_object_int_add(json_neigh,
13605 "externalBgpNbrMaxHopsAway",
13606 p->gtsm_hops);
c8d6f0d6 13607 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13608 json_object_int_add(json_neigh,
13609 "externalBgpNbrMaxHopsAway",
13610 p->ttl);
13611 } else {
e2521429 13612 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13613 vty_out(vty,
13614 " External BGP neighbor may be up to %d hops away.\n",
13615 p->gtsm_hops);
c8d6f0d6 13616 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13617 vty_out(vty,
13618 " External BGP neighbor may be up to %d hops away.\n",
13619 p->ttl);
13620 }
13621 } else {
e2521429 13622 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13623 if (use_json)
13624 json_object_int_add(json_neigh,
13625 "internalBgpNbrMaxHopsAway",
13626 p->gtsm_hops);
13627 else
13628 vty_out(vty,
13629 " Internal BGP neighbor may be up to %d hops away.\n",
13630 p->gtsm_hops);
13631 }
13632 }
13633
13634 /* Local address. */
13635 if (p->su_local) {
13636 if (use_json) {
13637 json_object_string_add(json_neigh, "hostLocal",
13638 sockunion2str(p->su_local, buf1,
13639 SU_ADDRSTRLEN));
13640 json_object_int_add(json_neigh, "portLocal",
13641 ntohs(p->su_local->sin.sin_port));
13642 } else
13643 vty_out(vty, "Local host: %s, Local port: %d\n",
13644 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13645 ntohs(p->su_local->sin.sin_port));
13646 }
13647
13648 /* Remote address. */
13649 if (p->su_remote) {
13650 if (use_json) {
13651 json_object_string_add(json_neigh, "hostForeign",
13652 sockunion2str(p->su_remote, buf1,
13653 SU_ADDRSTRLEN));
13654 json_object_int_add(json_neigh, "portForeign",
13655 ntohs(p->su_remote->sin.sin_port));
13656 } else
13657 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13658 sockunion2str(p->su_remote, buf1,
13659 SU_ADDRSTRLEN),
13660 ntohs(p->su_remote->sin.sin_port));
13661 }
13662
13663 /* Nexthop display. */
13664 if (p->su_local) {
13665 if (use_json) {
13666 json_object_string_add(json_neigh, "nexthop",
13667 inet_ntop(AF_INET,
13668 &p->nexthop.v4, buf1,
13669 sizeof(buf1)));
13670 json_object_string_add(json_neigh, "nexthopGlobal",
13671 inet_ntop(AF_INET6,
13672 &p->nexthop.v6_global,
13673 buf1, sizeof(buf1)));
13674 json_object_string_add(json_neigh, "nexthopLocal",
13675 inet_ntop(AF_INET6,
13676 &p->nexthop.v6_local,
13677 buf1, sizeof(buf1)));
13678 if (p->shared_network)
13679 json_object_string_add(json_neigh,
13680 "bgpConnection",
13681 "sharedNetwork");
13682 else
13683 json_object_string_add(json_neigh,
13684 "bgpConnection",
13685 "nonSharedNetwork");
13686 } else {
13687 vty_out(vty, "Nexthop: %s\n",
13688 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13689 sizeof(buf1)));
13690 vty_out(vty, "Nexthop global: %s\n",
13691 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13692 sizeof(buf1)));
13693 vty_out(vty, "Nexthop local: %s\n",
13694 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13695 sizeof(buf1)));
13696 vty_out(vty, "BGP connection: %s\n",
13697 p->shared_network ? "shared network"
13698 : "non shared network");
13699 }
13700 }
13701
13702 /* Timer information. */
13703 if (use_json) {
13704 json_object_int_add(json_neigh, "connectRetryTimer",
13705 p->v_connect);
feb17238 13706 if (peer_established(p) && p->rtt)
d62a17ae 13707 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13708 p->rtt);
13709 if (p->t_start)
13710 json_object_int_add(
13711 json_neigh, "nextStartTimerDueInMsecs",
13712 thread_timer_remain_second(p->t_start) * 1000);
13713 if (p->t_connect)
13714 json_object_int_add(
13715 json_neigh, "nextConnectTimerDueInMsecs",
13716 thread_timer_remain_second(p->t_connect)
13717 * 1000);
13718 if (p->t_routeadv) {
13719 json_object_int_add(json_neigh, "mraiInterval",
13720 p->v_routeadv);
13721 json_object_int_add(
13722 json_neigh, "mraiTimerExpireInMsecs",
13723 thread_timer_remain_second(p->t_routeadv)
13724 * 1000);
13725 }
13726 if (p->password)
13727 json_object_int_add(json_neigh, "authenticationEnabled",
13728 1);
13729
13730 if (p->t_read)
13731 json_object_string_add(json_neigh, "readThread", "on");
13732 else
13733 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
13734
13735 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 13736 json_object_string_add(json_neigh, "writeThread", "on");
13737 else
13738 json_object_string_add(json_neigh, "writeThread",
13739 "off");
13740 } else {
13741 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
13742 p->v_connect);
feb17238 13743 if (peer_established(p) && p->rtt)
d62a17ae 13744 vty_out(vty, "Estimated round trip time: %d ms\n",
13745 p->rtt);
13746 if (p->t_start)
13747 vty_out(vty, "Next start timer due in %ld seconds\n",
13748 thread_timer_remain_second(p->t_start));
13749 if (p->t_connect)
13750 vty_out(vty, "Next connect timer due in %ld seconds\n",
13751 thread_timer_remain_second(p->t_connect));
13752 if (p->t_routeadv)
13753 vty_out(vty,
13754 "MRAI (interval %u) timer expires in %ld seconds\n",
13755 p->v_routeadv,
13756 thread_timer_remain_second(p->t_routeadv));
13757 if (p->password)
13758 vty_out(vty, "Peer Authentication Enabled\n");
13759
cac9e917 13760 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
13761 p->t_read ? "on" : "off",
13762 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
13763 ? "on"
cac9e917 13764 : "off", p->fd);
d62a17ae 13765 }
13766
13767 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
13768 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
13769 bgp_capability_vty_out(vty, p, use_json, json_neigh);
13770
13771 if (!use_json)
13772 vty_out(vty, "\n");
13773
13774 /* BFD information. */
21bfce98
RZ
13775 if (p->bfd_config)
13776 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 13777
13778 if (use_json) {
13779 if (p->conf_if) /* Configured interface name. */
13780 json_object_object_add(json, p->conf_if, json_neigh);
13781 else /* Configured IP address. */
13782 json_object_object_add(json, p->host, json_neigh);
13783 }
13784}
13785
36235319
QY
13786static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13787 enum show_type type,
13788 union sockunion *su,
13789 const char *conf_if, afi_t afi,
74a630b6 13790 bool use_json)
2986cac2 13791{
13792 struct listnode *node, *nnode;
13793 struct peer *peer;
13794 int find = 0;
13795 safi_t safi = SAFI_UNICAST;
74a630b6 13796 json_object *json = NULL;
2986cac2 13797 json_object *json_neighbor = NULL;
13798
74a630b6
NT
13799 if (use_json) {
13800 json = json_object_new_object();
13801 json_neighbor = json_object_new_object();
13802 }
13803
2986cac2 13804 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13805
13806 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13807 continue;
13808
13809 if ((peer->afc[afi][safi]) == 0)
13810 continue;
13811
2ba1fe69 13812 if (type == show_all) {
2986cac2 13813 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13814 json_neighbor);
2986cac2 13815
74a630b6 13816 if (use_json) {
13909c4f
DS
13817 json_object_object_add(json, peer->host,
13818 json_neighbor);
74a630b6
NT
13819 json_neighbor = NULL;
13820 }
2986cac2 13821
2ba1fe69 13822 } else if (type == show_peer) {
2986cac2 13823 if (conf_if) {
13824 if ((peer->conf_if
13909c4f
DS
13825 && !strcmp(peer->conf_if, conf_if))
13826 || (peer->hostname
2986cac2 13827 && !strcmp(peer->hostname, conf_if))) {
13828 find = 1;
13909c4f
DS
13829 bgp_show_peer_gr_status(vty, peer,
13830 use_json,
13831 json_neighbor);
2986cac2 13832 }
13833 } else {
13834 if (sockunion_same(&peer->su, su)) {
13835 find = 1;
13909c4f
DS
13836 bgp_show_peer_gr_status(vty, peer,
13837 use_json,
13838 json_neighbor);
2986cac2 13839 }
13840 }
13909c4f
DS
13841 if (use_json && find)
13842 json_object_object_add(json, peer->host,
13843 json_neighbor);
2986cac2 13844 }
13845
74a630b6
NT
13846 if (find) {
13847 json_neighbor = NULL;
2986cac2 13848 break;
74a630b6 13849 }
2986cac2 13850 }
13851
13852 if (type == show_peer && !find) {
13853 if (use_json)
13909c4f 13854 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 13855 else
13856 vty_out(vty, "%% No such neighbor\n");
13857 }
13858 if (use_json) {
13909c4f
DS
13859 vty_out(vty, "%s\n",
13860 json_object_to_json_string_ext(
13861 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
13862
13863 if (json_neighbor)
13864 json_object_free(json_neighbor);
13865 json_object_free(json);
2986cac2 13866 } else {
13867 vty_out(vty, "\n");
13868 }
13869
13870 return CMD_SUCCESS;
13871}
13872
d62a17ae 13873static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13874 enum show_type type, union sockunion *su,
9f049418 13875 const char *conf_if, bool use_json,
d62a17ae 13876 json_object *json)
13877{
13878 struct listnode *node, *nnode;
13879 struct peer *peer;
13880 int find = 0;
9f049418 13881 bool nbr_output = false;
d1927ebe
AS
13882 afi_t afi = AFI_MAX;
13883 safi_t safi = SAFI_MAX;
13884
13885 if (type == show_ipv4_peer || type == show_ipv4_all) {
13886 afi = AFI_IP;
13887 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13888 afi = AFI_IP6;
13889 }
d62a17ae 13890
13891 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13892 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13893 continue;
13894
13895 switch (type) {
13896 case show_all:
13897 bgp_show_peer(vty, peer, use_json, json);
9f049418 13898 nbr_output = true;
d62a17ae 13899 break;
13900 case show_peer:
13901 if (conf_if) {
13902 if ((peer->conf_if
13903 && !strcmp(peer->conf_if, conf_if))
13904 || (peer->hostname
13905 && !strcmp(peer->hostname, conf_if))) {
13906 find = 1;
13907 bgp_show_peer(vty, peer, use_json,
13908 json);
13909 }
13910 } else {
13911 if (sockunion_same(&peer->su, su)) {
13912 find = 1;
13913 bgp_show_peer(vty, peer, use_json,
13914 json);
13915 }
13916 }
13917 break;
d1927ebe
AS
13918 case show_ipv4_peer:
13919 case show_ipv6_peer:
13920 FOREACH_SAFI (safi) {
13921 if (peer->afc[afi][safi]) {
13922 if (conf_if) {
13923 if ((peer->conf_if
13924 && !strcmp(peer->conf_if, conf_if))
13925 || (peer->hostname
13926 && !strcmp(peer->hostname, conf_if))) {
13927 find = 1;
13928 bgp_show_peer(vty, peer, use_json,
13929 json);
13930 break;
13931 }
13932 } else {
13933 if (sockunion_same(&peer->su, su)) {
13934 find = 1;
13935 bgp_show_peer(vty, peer, use_json,
13936 json);
13937 break;
13938 }
13939 }
13940 }
13941 }
13942 break;
13943 case show_ipv4_all:
13944 case show_ipv6_all:
13945 FOREACH_SAFI (safi) {
13946 if (peer->afc[afi][safi]) {
13947 bgp_show_peer(vty, peer, use_json, json);
13948 nbr_output = true;
13949 break;
13950 }
13951 }
13952 break;
d62a17ae 13953 }
13954 }
13955
d1927ebe
AS
13956 if ((type == show_peer || type == show_ipv4_peer ||
13957 type == show_ipv6_peer) && !find) {
d62a17ae 13958 if (use_json)
13959 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13960 else
88b7d255 13961 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 13962 }
13963
d1927ebe
AS
13964 if (type != show_peer && type != show_ipv4_peer &&
13965 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 13966 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 13967
d62a17ae 13968 if (use_json) {
996c9314
LB
13969 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13970 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 13971 } else {
13972 vty_out(vty, "\n");
13973 }
13974
13975 return CMD_SUCCESS;
13976}
13977
36235319
QY
13978static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13979 enum show_type type,
13980 const char *ip_str,
13981 afi_t afi, bool use_json)
2986cac2 13982{
13983
13984 int ret;
13985 struct bgp *bgp;
13986 union sockunion su;
2986cac2 13987
13988 bgp = bgp_get_default();
13989
13909c4f
DS
13990 if (!bgp)
13991 return;
2986cac2 13992
13909c4f
DS
13993 if (!use_json)
13994 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13995 NULL);
2986cac2 13996
13909c4f
DS
13997 if (ip_str) {
13998 ret = str2sockunion(ip_str, &su);
13999 if (ret < 0)
13909c4f 14000 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14001 vty, bgp, type, NULL, ip_str, afi, use_json);
14002 else
14003 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14004 NULL, afi, use_json);
13909c4f
DS
14005 } else
14006 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14007 afi, use_json);
2986cac2 14008}
14009
d62a17ae 14010static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14011 enum show_type type,
14012 const char *ip_str,
9f049418 14013 bool use_json)
d62a17ae 14014{
0291c246
MK
14015 struct listnode *node, *nnode;
14016 struct bgp *bgp;
71aedaa3 14017 union sockunion su;
0291c246 14018 json_object *json = NULL;
71aedaa3 14019 int ret, is_first = 1;
9f049418 14020 bool nbr_output = false;
d62a17ae 14021
14022 if (use_json)
14023 vty_out(vty, "{\n");
14024
14025 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14026 nbr_output = true;
d62a17ae 14027 if (use_json) {
14028 if (!(json = json_object_new_object())) {
af4c2728 14029 flog_err(
e50f7cfd 14030 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14031 "Unable to allocate memory for JSON object");
14032 vty_out(vty,
14033 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14034 return;
14035 }
14036
14037 json_object_int_add(json, "vrfId",
14038 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14039 ? -1
14040 : (int64_t)bgp->vrf_id);
d62a17ae 14041 json_object_string_add(
14042 json, "vrfName",
14043 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14044 ? VRF_DEFAULT_NAME
d62a17ae 14045 : bgp->name);
14046
14047 if (!is_first)
14048 vty_out(vty, ",\n");
14049 else
14050 is_first = 0;
14051
14052 vty_out(vty, "\"%s\":",
14053 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14054 ? VRF_DEFAULT_NAME
d62a17ae 14055 : bgp->name);
14056 } else {
14057 vty_out(vty, "\nInstance %s:\n",
14058 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14059 ? VRF_DEFAULT_NAME
d62a17ae 14060 : bgp->name);
14061 }
71aedaa3 14062
d1927ebe
AS
14063 if (type == show_peer || type == show_ipv4_peer ||
14064 type == show_ipv6_peer) {
71aedaa3
DS
14065 ret = str2sockunion(ip_str, &su);
14066 if (ret < 0)
14067 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14068 use_json, json);
14069 else
14070 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14071 use_json, json);
14072 } else {
d1927ebe 14073 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14074 use_json, json);
14075 }
b77004d6 14076 json_object_free(json);
121067e9 14077 json = NULL;
d62a17ae 14078 }
14079
3e78a6ce 14080 if (use_json)
d62a17ae 14081 vty_out(vty, "}\n");
9f049418
DS
14082 else if (!nbr_output)
14083 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14084}
14085
14086static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14087 enum show_type type, const char *ip_str,
9f049418 14088 bool use_json)
d62a17ae 14089{
14090 int ret;
14091 struct bgp *bgp;
14092 union sockunion su;
14093 json_object *json = NULL;
14094
14095 if (name) {
14096 if (strmatch(name, "all")) {
71aedaa3
DS
14097 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14098 use_json);
d62a17ae 14099 return CMD_SUCCESS;
14100 } else {
14101 bgp = bgp_lookup_by_name(name);
14102 if (!bgp) {
14103 if (use_json) {
14104 json = json_object_new_object();
d62a17ae 14105 vty_out(vty, "%s\n",
14106 json_object_to_json_string_ext(
14107 json,
14108 JSON_C_TO_STRING_PRETTY));
14109 json_object_free(json);
14110 } else
14111 vty_out(vty,
9f049418 14112 "%% BGP instance not found\n");
d62a17ae 14113
14114 return CMD_WARNING;
14115 }
14116 }
14117 } else {
14118 bgp = bgp_get_default();
14119 }
14120
14121 if (bgp) {
14122 json = json_object_new_object();
14123 if (ip_str) {
14124 ret = str2sockunion(ip_str, &su);
14125 if (ret < 0)
14126 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14127 use_json, json);
14128 else
14129 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14130 use_json, json);
14131 } else {
14132 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14133 json);
14134 }
14135 json_object_free(json);
ca61fd25
DS
14136 } else {
14137 if (use_json)
14138 vty_out(vty, "{}\n");
14139 else
14140 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14141 }
14142
14143 return CMD_SUCCESS;
4fb25c53
DW
14144}
14145
2986cac2 14146
14147
14148/* "show [ip] bgp neighbors graceful-restart" commands. */
14149DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14150 show_ip_bgp_neighbors_graceful_restart_cmd,
14151 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14152 SHOW_STR
14153 BGP_STR
14154 IP_STR
14155 IPV6_STR
14156 NEIGHBOR_STR
14157 "Neighbor to display information about\n"
14158 "Neighbor to display information about\n"
14159 "Neighbor on BGP configured interface\n"
14160 GR_SHOW
14161 JSON_STR)
14162{
14163 char *sh_arg = NULL;
14164 enum show_type sh_type;
14165 int idx = 0;
14166 afi_t afi = AFI_MAX;
2986cac2 14167 bool uj = use_json(argc, argv);
14168
36235319 14169 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14170 afi = AFI_MAX;
14171
14172 idx++;
14173
14174 if (argv_find(argv, argc, "A.B.C.D", &idx)
14175 || argv_find(argv, argc, "X:X::X:X", &idx)
14176 || argv_find(argv, argc, "WORD", &idx)) {
14177 sh_type = show_peer;
14178 sh_arg = argv[idx]->arg;
14179 } else
14180 sh_type = show_all;
14181
14182 if (!argv_find(argv, argc, "graceful-restart", &idx))
14183 return CMD_SUCCESS;
14184
14185
36235319
QY
14186 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14187 afi, uj);
2986cac2 14188}
14189
716b2d8a 14190/* "show [ip] bgp neighbors" commands. */
718e3744 14191DEFUN (show_ip_bgp_neighbors,
14192 show_ip_bgp_neighbors_cmd,
24345e82 14193 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14194 SHOW_STR
14195 IP_STR
14196 BGP_STR
f2a8972b 14197 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14198 "Address Family\n"
14199 "Address Family\n"
718e3744 14200 "Detailed information on TCP and BGP neighbor connections\n"
14201 "Neighbor to display information about\n"
a80beece 14202 "Neighbor to display information about\n"
91d37724 14203 "Neighbor on BGP configured interface\n"
9973d184 14204 JSON_STR)
718e3744 14205{
d62a17ae 14206 char *vrf = NULL;
14207 char *sh_arg = NULL;
14208 enum show_type sh_type;
d1927ebe 14209 afi_t afi = AFI_MAX;
718e3744 14210
9f049418 14211 bool uj = use_json(argc, argv);
718e3744 14212
d62a17ae 14213 int idx = 0;
718e3744 14214
9a8bdf1c
PG
14215 /* [<vrf> VIEWVRFNAME] */
14216 if (argv_find(argv, argc, "vrf", &idx)) {
14217 vrf = argv[idx + 1]->arg;
14218 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14219 vrf = NULL;
14220 } else if (argv_find(argv, argc, "view", &idx))
14221 /* [<view> VIEWVRFNAME] */
d62a17ae 14222 vrf = argv[idx + 1]->arg;
718e3744 14223
d62a17ae 14224 idx++;
d1927ebe
AS
14225
14226 if (argv_find(argv, argc, "ipv4", &idx)) {
14227 sh_type = show_ipv4_all;
14228 afi = AFI_IP;
14229 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14230 sh_type = show_ipv6_all;
14231 afi = AFI_IP6;
14232 } else {
14233 sh_type = show_all;
14234 }
14235
d62a17ae 14236 if (argv_find(argv, argc, "A.B.C.D", &idx)
14237 || argv_find(argv, argc, "X:X::X:X", &idx)
14238 || argv_find(argv, argc, "WORD", &idx)) {
14239 sh_type = show_peer;
14240 sh_arg = argv[idx]->arg;
d1927ebe
AS
14241 }
14242
14243 if (sh_type == show_peer && afi == AFI_IP) {
14244 sh_type = show_ipv4_peer;
14245 } else if (sh_type == show_peer && afi == AFI_IP6) {
14246 sh_type = show_ipv6_peer;
14247 }
856ca177 14248
d62a17ae 14249 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14250}
14251
716b2d8a 14252/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14253 paths' and `show ip mbgp paths'. Those functions results are the
14254 same.*/
f412b39a 14255DEFUN (show_ip_bgp_paths,
718e3744 14256 show_ip_bgp_paths_cmd,
46f296b4 14257 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14258 SHOW_STR
14259 IP_STR
14260 BGP_STR
46f296b4 14261 BGP_SAFI_HELP_STR
718e3744 14262 "Path information\n")
14263{
d62a17ae 14264 vty_out(vty, "Address Refcnt Path\n");
14265 aspath_print_all_vty(vty);
14266 return CMD_SUCCESS;
718e3744 14267}
14268
718e3744 14269#include "hash.h"
14270
e3b78da8 14271static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14272 struct vty *vty)
718e3744 14273{
d62a17ae 14274 struct community *com;
718e3744 14275
e3b78da8 14276 com = (struct community *)bucket->data;
3f65c5b1 14277 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 14278 community_str(com, false));
718e3744 14279}
14280
14281/* Show BGP's community internal data. */
f412b39a 14282DEFUN (show_ip_bgp_community_info,
718e3744 14283 show_ip_bgp_community_info_cmd,
bec37ba5 14284 "show [ip] bgp community-info",
718e3744 14285 SHOW_STR
14286 IP_STR
14287 BGP_STR
14288 "List all bgp community information\n")
14289{
d62a17ae 14290 vty_out(vty, "Address Refcnt Community\n");
718e3744 14291
d62a17ae 14292 hash_iterate(community_hash(),
e3b78da8 14293 (void (*)(struct hash_bucket *,
d62a17ae 14294 void *))community_show_all_iterator,
14295 vty);
718e3744 14296
d62a17ae 14297 return CMD_SUCCESS;
718e3744 14298}
14299
e3b78da8 14300static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14301 struct vty *vty)
57d187bc 14302{
d62a17ae 14303 struct lcommunity *lcom;
57d187bc 14304
e3b78da8 14305 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14306 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 14307 lcommunity_str(lcom, false));
57d187bc
JS
14308}
14309
14310/* Show BGP's community internal data. */
14311DEFUN (show_ip_bgp_lcommunity_info,
14312 show_ip_bgp_lcommunity_info_cmd,
14313 "show ip bgp large-community-info",
14314 SHOW_STR
14315 IP_STR
14316 BGP_STR
14317 "List all bgp large-community information\n")
14318{
d62a17ae 14319 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14320
d62a17ae 14321 hash_iterate(lcommunity_hash(),
e3b78da8 14322 (void (*)(struct hash_bucket *,
d62a17ae 14323 void *))lcommunity_show_all_iterator,
14324 vty);
57d187bc 14325
d62a17ae 14326 return CMD_SUCCESS;
57d187bc 14327}
2986cac2 14328/* Graceful Restart */
14329
14330static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14331 struct bgp *bgp,
14332 bool use_json,
14333 json_object *json)
2986cac2 14334{
57d187bc
JS
14335
14336
2986cac2 14337 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14338
7318ae88 14339 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14340
14341 switch (bgp_global_gr_mode) {
14342
14343 case GLOBAL_HELPER:
13909c4f 14344 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14345 break;
14346
14347 case GLOBAL_GR:
13909c4f 14348 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14349 break;
14350
14351 case GLOBAL_DISABLE:
13909c4f 14352 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14353 break;
14354
14355 case GLOBAL_INVALID:
2986cac2 14356 vty_out(vty,
2ba1fe69 14357 "Global BGP GR Mode Invalid\n");
2986cac2 14358 break;
14359 }
14360 vty_out(vty, "\n");
14361}
14362
36235319
QY
14363static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14364 enum show_type type,
14365 const char *ip_str,
14366 afi_t afi, bool use_json)
2986cac2 14367{
14368 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14369 afi = AFI_IP;
14370
14371 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14372
36235319
QY
14373 bgp_show_neighbor_graceful_restart_vty(
14374 vty, type, ip_str, afi, use_json);
2986cac2 14375 afi++;
14376 }
14377 } else if (afi != AFI_MAX) {
36235319
QY
14378 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14379 use_json);
2986cac2 14380 } else {
14381 return CMD_ERR_INCOMPLETE;
14382 }
14383
14384 return CMD_SUCCESS;
14385}
14386/* Graceful Restart */
14387
f412b39a 14388DEFUN (show_ip_bgp_attr_info,
718e3744 14389 show_ip_bgp_attr_info_cmd,
bec37ba5 14390 "show [ip] bgp attribute-info",
718e3744 14391 SHOW_STR
14392 IP_STR
14393 BGP_STR
14394 "List all bgp attribute information\n")
14395{
d62a17ae 14396 attr_show_all(vty);
14397 return CMD_SUCCESS;
718e3744 14398}
6b0655a2 14399
03915806
CS
14400static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14401 afi_t afi, safi_t safi,
14402 bool use_json, json_object *json)
53089bec 14403{
14404 struct bgp *bgp;
14405 struct listnode *node;
14406 char *vname;
14407 char buf1[INET6_ADDRSTRLEN];
14408 char *ecom_str;
14409 vpn_policy_direction_t dir;
14410
03915806 14411 if (json) {
b46dfd20
DS
14412 json_object *json_import_vrfs = NULL;
14413 json_object *json_export_vrfs = NULL;
14414
b46dfd20
DS
14415 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14416
53089bec 14417 if (!bgp) {
b46dfd20
DS
14418 vty_out(vty, "%s\n",
14419 json_object_to_json_string_ext(
14420 json,
14421 JSON_C_TO_STRING_PRETTY));
14422 json_object_free(json);
14423
53089bec 14424 return CMD_WARNING;
14425 }
b46dfd20 14426
94d4c685
DS
14427 /* Provide context for the block */
14428 json_object_string_add(json, "vrf", name ? name : "default");
14429 json_object_string_add(json, "afiSafi",
5cb5f4d0 14430 get_afi_safi_str(afi, safi, true));
94d4c685 14431
b46dfd20
DS
14432 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14433 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14434 json_object_string_add(json, "importFromVrfs", "none");
14435 json_object_string_add(json, "importRts", "none");
14436 } else {
6ce24e52
DS
14437 json_import_vrfs = json_object_new_array();
14438
b46dfd20
DS
14439 for (ALL_LIST_ELEMENTS_RO(
14440 bgp->vpn_policy[afi].import_vrf,
14441 node, vname))
14442 json_object_array_add(json_import_vrfs,
14443 json_object_new_string(vname));
14444
b20875ea
CS
14445 json_object_object_add(json, "importFromVrfs",
14446 json_import_vrfs);
b46dfd20 14447 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14448 if (bgp->vpn_policy[afi].rtlist[dir]) {
14449 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14450 bgp->vpn_policy[afi].rtlist[dir],
14451 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14452 json_object_string_add(json, "importRts",
14453 ecom_str);
14454 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14455 } else
14456 json_object_string_add(json, "importRts",
14457 "none");
b46dfd20
DS
14458 }
14459
14460 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14461 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14462 json_object_string_add(json, "exportToVrfs", "none");
14463 json_object_string_add(json, "routeDistinguisher",
14464 "none");
14465 json_object_string_add(json, "exportRts", "none");
14466 } else {
6ce24e52
DS
14467 json_export_vrfs = json_object_new_array();
14468
b46dfd20
DS
14469 for (ALL_LIST_ELEMENTS_RO(
14470 bgp->vpn_policy[afi].export_vrf,
14471 node, vname))
14472 json_object_array_add(json_export_vrfs,
14473 json_object_new_string(vname));
14474 json_object_object_add(json, "exportToVrfs",
14475 json_export_vrfs);
14476 json_object_string_add(json, "routeDistinguisher",
14477 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14478 buf1, RD_ADDRSTRLEN));
14479
14480 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14481 if (bgp->vpn_policy[afi].rtlist[dir]) {
14482 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14483 bgp->vpn_policy[afi].rtlist[dir],
14484 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14485 json_object_string_add(json, "exportRts",
14486 ecom_str);
14487 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14488 } else
14489 json_object_string_add(json, "exportRts",
14490 "none");
b46dfd20
DS
14491 }
14492
03915806
CS
14493 if (use_json) {
14494 vty_out(vty, "%s\n",
14495 json_object_to_json_string_ext(json,
b46dfd20 14496 JSON_C_TO_STRING_PRETTY));
03915806
CS
14497 json_object_free(json);
14498 }
53089bec 14499 } else {
b46dfd20
DS
14500 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14501
53089bec 14502 if (!bgp) {
b46dfd20 14503 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14504 return CMD_WARNING;
14505 }
53089bec 14506
b46dfd20
DS
14507 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14508 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14509 vty_out(vty,
14510 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14511 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14512 else {
14513 vty_out(vty,
14514 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14515 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14516
14517 for (ALL_LIST_ELEMENTS_RO(
14518 bgp->vpn_policy[afi].import_vrf,
14519 node, vname))
14520 vty_out(vty, " %s\n", vname);
14521
14522 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14523 ecom_str = NULL;
14524 if (bgp->vpn_policy[afi].rtlist[dir]) {
14525 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14526 bgp->vpn_policy[afi].rtlist[dir],
14527 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14528 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14529
b20875ea
CS
14530 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14531 } else
14532 vty_out(vty, "Import RT(s):\n");
53089bec 14533 }
53089bec 14534
b46dfd20
DS
14535 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14536 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14537 vty_out(vty,
14538 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14539 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14540 else {
14541 vty_out(vty,
04c9077f 14542 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14543 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14544
14545 for (ALL_LIST_ELEMENTS_RO(
14546 bgp->vpn_policy[afi].export_vrf,
14547 node, vname))
14548 vty_out(vty, " %s\n", vname);
14549
14550 vty_out(vty, "RD: %s\n",
14551 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14552 buf1, RD_ADDRSTRLEN));
14553
14554 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14555 if (bgp->vpn_policy[afi].rtlist[dir]) {
14556 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14557 bgp->vpn_policy[afi].rtlist[dir],
14558 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14559 vty_out(vty, "Export RT: %s\n", ecom_str);
14560 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14561 } else
14562 vty_out(vty, "Import RT(s):\n");
53089bec 14563 }
53089bec 14564 }
14565
14566 return CMD_SUCCESS;
14567}
14568
03915806
CS
14569static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14570 safi_t safi, bool use_json)
14571{
14572 struct listnode *node, *nnode;
14573 struct bgp *bgp;
14574 char *vrf_name = NULL;
14575 json_object *json = NULL;
14576 json_object *json_vrf = NULL;
14577 json_object *json_vrfs = NULL;
14578
14579 if (use_json) {
14580 json = json_object_new_object();
14581 json_vrfs = json_object_new_object();
14582 }
14583
14584 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14585
14586 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14587 vrf_name = bgp->name;
14588
14589 if (use_json) {
14590 json_vrf = json_object_new_object();
14591 } else {
14592 vty_out(vty, "\nInstance %s:\n",
14593 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14594 ? VRF_DEFAULT_NAME : bgp->name);
14595 }
14596 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14597 if (use_json) {
14598 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14599 json_object_object_add(json_vrfs,
14600 VRF_DEFAULT_NAME, json_vrf);
14601 else
14602 json_object_object_add(json_vrfs, vrf_name,
14603 json_vrf);
14604 }
14605 }
14606
14607 if (use_json) {
14608 json_object_object_add(json, "vrfs", json_vrfs);
14609 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
14610 JSON_C_TO_STRING_PRETTY));
14611 json_object_free(json);
14612 }
14613
14614 return CMD_SUCCESS;
14615}
14616
53089bec 14617/* "show [ip] bgp route-leak" command. */
14618DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14619 show_ip_bgp_route_leak_cmd,
14620 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14621 SHOW_STR
14622 IP_STR
14623 BGP_STR
14624 BGP_INSTANCE_HELP_STR
14625 BGP_AFI_HELP_STR
14626 BGP_SAFI_HELP_STR
14627 "Route leaking information\n"
14628 JSON_STR)
53089bec 14629{
14630 char *vrf = NULL;
14631 afi_t afi = AFI_MAX;
14632 safi_t safi = SAFI_MAX;
14633
9f049418 14634 bool uj = use_json(argc, argv);
53089bec 14635 int idx = 0;
03915806 14636 json_object *json = NULL;
53089bec 14637
14638 /* show [ip] bgp */
14639 if (argv_find(argv, argc, "ip", &idx)) {
14640 afi = AFI_IP;
14641 safi = SAFI_UNICAST;
14642 }
14643 /* [vrf VIEWVRFNAME] */
14644 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14645 vty_out(vty,
14646 "%% This command is not applicable to BGP views\n");
53089bec 14647 return CMD_WARNING;
14648 }
14649
9a8bdf1c
PG
14650 if (argv_find(argv, argc, "vrf", &idx)) {
14651 vrf = argv[idx + 1]->arg;
14652 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14653 vrf = NULL;
14654 }
53089bec 14655 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14656 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14657 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14658 }
14659
14660 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14661 vty_out(vty,
14662 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14663 return CMD_WARNING;
14664 }
14665
03915806
CS
14666 if (vrf && strmatch(vrf, "all"))
14667 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14668
14669 if (uj)
14670 json = json_object_new_object();
14671
14672 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14673}
14674
d62a17ae 14675static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14676 safi_t safi)
f186de26 14677{
d62a17ae 14678 struct listnode *node, *nnode;
14679 struct bgp *bgp;
f186de26 14680
d62a17ae 14681 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14682 vty_out(vty, "\nInstance %s:\n",
14683 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14684 ? VRF_DEFAULT_NAME
d62a17ae 14685 : bgp->name);
14686 update_group_show(bgp, afi, safi, vty, 0);
14687 }
f186de26 14688}
14689
d62a17ae 14690static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14691 int safi, uint64_t subgrp_id)
4fb25c53 14692{
d62a17ae 14693 struct bgp *bgp;
4fb25c53 14694
d62a17ae 14695 if (name) {
14696 if (strmatch(name, "all")) {
14697 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14698 return CMD_SUCCESS;
14699 } else {
14700 bgp = bgp_lookup_by_name(name);
14701 }
14702 } else {
14703 bgp = bgp_get_default();
14704 }
4fb25c53 14705
d62a17ae 14706 if (bgp)
14707 update_group_show(bgp, afi, safi, vty, subgrp_id);
14708 return CMD_SUCCESS;
4fb25c53
DW
14709}
14710
8fe8a7f6
DS
14711DEFUN (show_ip_bgp_updgrps,
14712 show_ip_bgp_updgrps_cmd,
c1a44e43 14713 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14714 SHOW_STR
14715 IP_STR
14716 BGP_STR
14717 BGP_INSTANCE_HELP_STR
c9e571b4 14718 BGP_AFI_HELP_STR
9bedbb1e 14719 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14720 "Detailed info about dynamic update groups\n"
14721 "Specific subgroup to display detailed info for\n")
8386ac43 14722{
d62a17ae 14723 char *vrf = NULL;
14724 afi_t afi = AFI_IP6;
14725 safi_t safi = SAFI_UNICAST;
14726 uint64_t subgrp_id = 0;
14727
14728 int idx = 0;
14729
14730 /* show [ip] bgp */
14731 if (argv_find(argv, argc, "ip", &idx))
14732 afi = AFI_IP;
9a8bdf1c
PG
14733 /* [<vrf> VIEWVRFNAME] */
14734 if (argv_find(argv, argc, "vrf", &idx)) {
14735 vrf = argv[idx + 1]->arg;
14736 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14737 vrf = NULL;
14738 } else if (argv_find(argv, argc, "view", &idx))
14739 /* [<view> VIEWVRFNAME] */
14740 vrf = argv[idx + 1]->arg;
d62a17ae 14741 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
14742 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
14743 argv_find_and_parse_safi(argv, argc, &idx, &safi);
14744 }
5bf15956 14745
d62a17ae 14746 /* get subgroup id, if provided */
14747 idx = argc - 1;
14748 if (argv[idx]->type == VARIABLE_TKN)
14749 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 14750
d62a17ae 14751 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
14752}
14753
f186de26 14754DEFUN (show_bgp_instance_all_ipv6_updgrps,
14755 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 14756 "show [ip] bgp <view|vrf> all update-groups",
f186de26 14757 SHOW_STR
716b2d8a 14758 IP_STR
f186de26 14759 BGP_STR
14760 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 14761 "Detailed info about dynamic update groups\n")
f186de26 14762{
d62a17ae 14763 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
14764 return CMD_SUCCESS;
f186de26 14765}
14766
43d3f4fc
DS
14767DEFUN (show_bgp_l2vpn_evpn_updgrps,
14768 show_bgp_l2vpn_evpn_updgrps_cmd,
14769 "show [ip] bgp l2vpn evpn update-groups",
14770 SHOW_STR
14771 IP_STR
14772 BGP_STR
14773 "l2vpn address family\n"
14774 "evpn sub-address family\n"
14775 "Detailed info about dynamic update groups\n")
14776{
14777 char *vrf = NULL;
14778 uint64_t subgrp_id = 0;
14779
14780 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14781 return CMD_SUCCESS;
14782}
14783
5bf15956
DW
14784DEFUN (show_bgp_updgrps_stats,
14785 show_bgp_updgrps_stats_cmd,
716b2d8a 14786 "show [ip] bgp update-groups statistics",
3f9c7369 14787 SHOW_STR
716b2d8a 14788 IP_STR
3f9c7369 14789 BGP_STR
0c7b1b01 14790 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14791 "Statistics\n")
14792{
d62a17ae 14793 struct bgp *bgp;
3f9c7369 14794
d62a17ae 14795 bgp = bgp_get_default();
14796 if (bgp)
14797 update_group_show_stats(bgp, vty);
3f9c7369 14798
d62a17ae 14799 return CMD_SUCCESS;
3f9c7369
DS
14800}
14801
8386ac43 14802DEFUN (show_bgp_instance_updgrps_stats,
14803 show_bgp_instance_updgrps_stats_cmd,
18c57037 14804 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14805 SHOW_STR
716b2d8a 14806 IP_STR
8386ac43 14807 BGP_STR
14808 BGP_INSTANCE_HELP_STR
0c7b1b01 14809 "Detailed info about dynamic update groups\n"
8386ac43 14810 "Statistics\n")
14811{
d62a17ae 14812 int idx_word = 3;
14813 struct bgp *bgp;
8386ac43 14814
d62a17ae 14815 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14816 if (bgp)
14817 update_group_show_stats(bgp, vty);
8386ac43 14818
d62a17ae 14819 return CMD_SUCCESS;
8386ac43 14820}
14821
d62a17ae 14822static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14823 afi_t afi, safi_t safi,
14824 const char *what, uint64_t subgrp_id)
3f9c7369 14825{
d62a17ae 14826 struct bgp *bgp;
8386ac43 14827
d62a17ae 14828 if (name)
14829 bgp = bgp_lookup_by_name(name);
14830 else
14831 bgp = bgp_get_default();
8386ac43 14832
d62a17ae 14833 if (bgp) {
14834 if (!strcmp(what, "advertise-queue"))
14835 update_group_show_adj_queue(bgp, afi, safi, vty,
14836 subgrp_id);
14837 else if (!strcmp(what, "advertised-routes"))
14838 update_group_show_advertised(bgp, afi, safi, vty,
14839 subgrp_id);
14840 else if (!strcmp(what, "packet-queue"))
14841 update_group_show_packet_queue(bgp, afi, safi, vty,
14842 subgrp_id);
14843 }
3f9c7369
DS
14844}
14845
dc64bdec
QY
14846DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14847 show_ip_bgp_instance_updgrps_adj_s_cmd,
14848 "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",
14849 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14850 BGP_SAFI_HELP_STR
14851 "Detailed info about dynamic update groups\n"
14852 "Specific subgroup to display info for\n"
14853 "Advertisement queue\n"
14854 "Announced routes\n"
14855 "Packet queue\n")
3f9c7369 14856{
dc64bdec
QY
14857 uint64_t subgrp_id = 0;
14858 afi_t afiz;
14859 safi_t safiz;
14860 if (sgid)
14861 subgrp_id = strtoull(sgid, NULL, 10);
14862
14863 if (!ip && !afi)
14864 afiz = AFI_IP6;
14865 if (!ip && afi)
14866 afiz = bgp_vty_afi_from_str(afi);
14867 if (ip && !afi)
14868 afiz = AFI_IP;
14869 if (ip && afi) {
14870 afiz = bgp_vty_afi_from_str(afi);
14871 if (afiz != AFI_IP)
14872 vty_out(vty,
14873 "%% Cannot specify both 'ip' and 'ipv6'\n");
14874 return CMD_WARNING;
14875 }
d62a17ae 14876
dc64bdec 14877 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 14878
dc64bdec 14879 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 14880 return CMD_SUCCESS;
14881}
14882
6f4eacf3
DA
14883static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
14884 json_object *json)
d62a17ae 14885{
14886 struct listnode *node, *nnode;
14887 struct prefix *range;
14888 struct peer *conf;
14889 struct peer *peer;
d62a17ae 14890 afi_t afi;
14891 safi_t safi;
14892 const char *peer_status;
d62a17ae 14893 int lr_count;
14894 int dynamic;
6f4eacf3
DA
14895 bool af_cfgd;
14896 json_object *json_peer_group = NULL;
14897 json_object *json_peer_group_afc = NULL;
14898 json_object *json_peer_group_members = NULL;
14899 json_object *json_peer_group_dynamic = NULL;
14900 json_object *json_peer_group_dynamic_af = NULL;
14901 json_object *json_peer_group_ranges = NULL;
d62a17ae 14902
14903 conf = group->conf;
14904
6f4eacf3
DA
14905 if (json) {
14906 json_peer_group = json_object_new_object();
14907 json_peer_group_afc = json_object_new_array();
14908 }
14909
d62a17ae 14910 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
14911 if (json)
14912 json_object_int_add(json_peer_group, "remoteAs",
14913 conf->as);
14914 else
14915 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14916 group->name, conf->as);
d62a17ae 14917 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
14918 if (json)
14919 json_object_int_add(json_peer_group, "remoteAs",
14920 group->bgp->as);
14921 else
14922 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
14923 group->name, group->bgp->as);
d62a17ae 14924 } else {
6f4eacf3
DA
14925 if (!json)
14926 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 14927 }
f14e6fdb 14928
6f4eacf3
DA
14929 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
14930 if (json)
14931 json_object_string_add(json_peer_group, "type",
14932 "internal");
14933 else
14934 vty_out(vty, " Peer-group type is internal\n");
14935 } else {
14936 if (json)
14937 json_object_string_add(json_peer_group, "type",
14938 "external");
14939 else
14940 vty_out(vty, " Peer-group type is external\n");
14941 }
d62a17ae 14942
14943 /* Display AFs configured. */
6f4eacf3
DA
14944 if (!json)
14945 vty_out(vty, " Configured address-families:");
14946
05c7a1cc
QY
14947 FOREACH_AFI_SAFI (afi, safi) {
14948 if (conf->afc[afi][safi]) {
6f4eacf3
DA
14949 af_cfgd = true;
14950 if (json)
14951 json_object_array_add(
14952 json_peer_group_afc,
14953 json_object_new_string(get_afi_safi_str(
14954 afi, safi, false)));
14955 else
14956 vty_out(vty, " %s;",
14957 get_afi_safi_str(afi, safi, false));
d62a17ae 14958 }
05c7a1cc 14959 }
6f4eacf3
DA
14960
14961 if (json) {
14962 json_object_object_add(json_peer_group,
14963 "addressFamiliesConfigured",
14964 json_peer_group_afc);
14965 } else {
14966 if (!af_cfgd)
14967 vty_out(vty, " none\n");
14968 else
14969 vty_out(vty, "\n");
14970 }
d62a17ae 14971
14972 /* Display listen ranges (for dynamic neighbors), if any */
14973 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 14974 lr_count = listcount(group->listen_range[afi]);
14975 if (lr_count) {
6f4eacf3
DA
14976 if (json) {
14977 if (!json_peer_group_dynamic)
14978 json_peer_group_dynamic =
14979 json_object_new_object();
14980
14981 json_peer_group_dynamic_af =
14982 json_object_new_object();
14983 json_peer_group_ranges =
14984 json_object_new_array();
14985 json_object_int_add(json_peer_group_dynamic_af,
14986 "count", lr_count);
14987 } else {
14988 vty_out(vty, " %d %s listen range(s)\n",
14989 lr_count, afi2str(afi));
14990 }
d62a17ae 14991
14992 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
14993 nnode, range)) {
14994 if (json) {
14995 char buf[BUFSIZ];
14996
14997 snprintfrr(buf, sizeof(buf), "%pFX",
14998 range);
14999
15000 json_object_array_add(
15001 json_peer_group_ranges,
15002 json_object_new_string(buf));
15003 } else {
15004 vty_out(vty, " %pFX\n", range);
15005 }
15006 }
15007
15008 if (json) {
15009 json_object_object_add(
15010 json_peer_group_dynamic_af, "ranges",
15011 json_peer_group_ranges);
15012
15013 json_object_object_add(
15014 json_peer_group_dynamic, afi2str(afi),
15015 json_peer_group_dynamic_af);
15016 }
d62a17ae 15017 }
15018 }
f14e6fdb 15019
6f4eacf3
DA
15020 if (json_peer_group_dynamic)
15021 json_object_object_add(json_peer_group, "dynamicRanges",
15022 json_peer_group_dynamic);
15023
d62a17ae 15024 /* Display group members and their status */
15025 if (listcount(group->peer)) {
6f4eacf3
DA
15026 if (json)
15027 json_peer_group_members = json_object_new_object();
15028 else
15029 vty_out(vty, " Peer-group members:\n");
d62a17ae 15030 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15031 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15032 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15033 peer_status = "Idle (Admin)";
15034 else if (CHECK_FLAG(peer->sflags,
15035 PEER_STATUS_PREFIX_OVERFLOW))
15036 peer_status = "Idle (PfxCt)";
15037 else
15038 peer_status = lookup_msg(bgp_status_msg,
15039 peer->status, NULL);
15040
15041 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15042
15043 if (json) {
15044 json_object *json_peer_group_member =
15045 json_object_new_object();
15046
15047 json_object_string_add(json_peer_group_member,
15048 "status", peer_status);
15049
15050 if (dynamic)
15051 json_object_boolean_true_add(
15052 json_peer_group_member,
15053 "dynamic");
15054
15055 json_object_object_add(json_peer_group_members,
15056 peer->host,
15057 json_peer_group_member);
15058 } else {
15059 vty_out(vty, " %s %s %s \n", peer->host,
15060 dynamic ? "(dynamic)" : "",
15061 peer_status);
15062 }
d62a17ae 15063 }
6f4eacf3
DA
15064 if (json)
15065 json_object_object_add(json_peer_group, "members",
15066 json_peer_group_members);
d62a17ae 15067 }
f14e6fdb 15068
6f4eacf3
DA
15069 if (json)
15070 json_object_object_add(json, group->name, json_peer_group);
15071
d62a17ae 15072 return CMD_SUCCESS;
15073}
15074
ff9959b0 15075static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15076 const char *group_name, bool uj)
d62a17ae 15077{
ff9959b0 15078 struct bgp *bgp;
d62a17ae 15079 struct listnode *node, *nnode;
15080 struct peer_group *group;
ff9959b0 15081 bool found = false;
6f4eacf3
DA
15082 json_object *json = NULL;
15083
15084 if (uj)
15085 json = json_object_new_object();
ff9959b0
QY
15086
15087 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15088
15089 if (!bgp) {
6f4eacf3
DA
15090 if (uj) {
15091 vty_out(vty, "%s\n",
15092 json_object_to_json_string_ext(
15093 json, JSON_C_TO_STRING_PRETTY));
15094 json_object_free(json);
15095 } else {
15096 vty_out(vty, "%% BGP instance not found\n");
15097 }
15098
ff9959b0
QY
15099 return CMD_WARNING;
15100 }
d62a17ae 15101
15102 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15103 if (group_name) {
15104 if (strmatch(group->name, group_name)) {
6f4eacf3 15105 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15106 found = true;
15107 break;
d62a17ae 15108 }
ff9959b0 15109 } else {
6f4eacf3 15110 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15111 }
f14e6fdb 15112 }
f14e6fdb 15113
6f4eacf3 15114 if (group_name && !found && !uj)
d62a17ae 15115 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15116
6f4eacf3
DA
15117 if (uj) {
15118 vty_out(vty, "%s\n",
15119 json_object_to_json_string_ext(
15120 json, JSON_C_TO_STRING_PRETTY));
15121 json_object_free(json);
15122 }
15123
d62a17ae 15124 return CMD_SUCCESS;
f14e6fdb
DS
15125}
15126
6f4eacf3
DA
15127DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15128 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15129 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15130 "Detailed information on BGP peer groups\n"
15131 "Peer group name\n" JSON_STR)
f14e6fdb 15132{
d62a17ae 15133 char *vrf, *pg;
d62a17ae 15134 int idx = 0;
6f4eacf3 15135 bool uj = use_json(argc, argv);
f14e6fdb 15136
a4d82a8a
PZ
15137 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15138 : NULL;
d62a17ae 15139 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15140
6f4eacf3 15141 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15142}
3f9c7369 15143
d6e3c605 15144
718e3744 15145/* Redistribute VTY commands. */
15146
585f1adc
IR
15147DEFUN (bgp_redistribute_ipv4,
15148 bgp_redistribute_ipv4_cmd,
15149 "redistribute " FRR_IP_REDIST_STR_BGPD,
15150 "Redistribute information from another routing protocol\n"
15151 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15152{
585f1adc 15153 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15154 int idx_protocol = 1;
585f1adc 15155 int type;
37a87b8f 15156
585f1adc
IR
15157 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15158 if (type < 0) {
15159 vty_out(vty, "%% Invalid route type\n");
15160 return CMD_WARNING_CONFIG_FAILED;
15161 }
7f323236 15162
585f1adc
IR
15163 bgp_redist_add(bgp, AFI_IP, type, 0);
15164 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15165}
15166
d62a17ae 15167ALIAS_HIDDEN(
15168 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15169 "redistribute " FRR_IP_REDIST_STR_BGPD,
15170 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15171
585f1adc
IR
15172DEFUN (bgp_redistribute_ipv4_rmap,
15173 bgp_redistribute_ipv4_rmap_cmd,
15174 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15175 "Redistribute information from another routing protocol\n"
15176 FRR_IP_REDIST_HELP_STR_BGPD
15177 "Route map reference\n"
15178 "Pointer to route-map entries\n")
718e3744 15179{
585f1adc 15180 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15181 int idx_protocol = 1;
15182 int idx_word = 3;
585f1adc
IR
15183 int type;
15184 struct bgp_redist *red;
15185 bool changed;
15186 struct route_map *route_map = route_map_lookup_warn_noexist(
15187 vty, argv[idx_word]->arg);
15188
15189 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15190 if (type < 0) {
15191 vty_out(vty, "%% Invalid route type\n");
15192 return CMD_WARNING_CONFIG_FAILED;
15193 }
37a87b8f 15194
585f1adc
IR
15195 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15196 changed =
15197 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15198 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15199}
15200
d62a17ae 15201ALIAS_HIDDEN(
15202 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15203 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15204 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15205 "Route map reference\n"
15206 "Pointer to route-map entries\n")
596c17ba 15207
585f1adc
IR
15208DEFUN (bgp_redistribute_ipv4_metric,
15209 bgp_redistribute_ipv4_metric_cmd,
15210 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15211 "Redistribute information from another routing protocol\n"
15212 FRR_IP_REDIST_HELP_STR_BGPD
15213 "Metric for redistributed routes\n"
15214 "Default metric\n")
718e3744 15215{
585f1adc 15216 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15217 int idx_protocol = 1;
15218 int idx_number = 3;
585f1adc
IR
15219 int type;
15220 uint32_t metric;
15221 struct bgp_redist *red;
15222 bool changed;
15223
15224 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15225 if (type < 0) {
15226 vty_out(vty, "%% Invalid route type\n");
15227 return CMD_WARNING_CONFIG_FAILED;
15228 }
15229 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15230
585f1adc
IR
15231 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15232 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15233 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15234}
15235
15236ALIAS_HIDDEN(
15237 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15238 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15239 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15240 "Metric for redistributed routes\n"
15241 "Default metric\n")
596c17ba 15242
585f1adc
IR
15243DEFUN (bgp_redistribute_ipv4_rmap_metric,
15244 bgp_redistribute_ipv4_rmap_metric_cmd,
15245 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15246 "Redistribute information from another routing protocol\n"
15247 FRR_IP_REDIST_HELP_STR_BGPD
15248 "Route map reference\n"
15249 "Pointer to route-map entries\n"
15250 "Metric for redistributed routes\n"
15251 "Default metric\n")
718e3744 15252{
585f1adc 15253 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15254 int idx_protocol = 1;
15255 int idx_word = 3;
15256 int idx_number = 5;
585f1adc
IR
15257 int type;
15258 uint32_t metric;
15259 struct bgp_redist *red;
15260 bool changed;
15261 struct route_map *route_map =
15262 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15263
15264 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15265 if (type < 0) {
15266 vty_out(vty, "%% Invalid route type\n");
15267 return CMD_WARNING_CONFIG_FAILED;
15268 }
15269 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15270
585f1adc
IR
15271 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15272 changed =
15273 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15274 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15275 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15276}
15277
15278ALIAS_HIDDEN(
15279 bgp_redistribute_ipv4_rmap_metric,
15280 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15281 "redistribute " FRR_IP_REDIST_STR_BGPD
15282 " route-map WORD metric (0-4294967295)",
15283 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15284 "Route map reference\n"
15285 "Pointer to route-map entries\n"
15286 "Metric for redistributed routes\n"
15287 "Default metric\n")
596c17ba 15288
585f1adc
IR
15289DEFUN (bgp_redistribute_ipv4_metric_rmap,
15290 bgp_redistribute_ipv4_metric_rmap_cmd,
15291 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15292 "Redistribute information from another routing protocol\n"
15293 FRR_IP_REDIST_HELP_STR_BGPD
15294 "Metric for redistributed routes\n"
15295 "Default metric\n"
15296 "Route map reference\n"
15297 "Pointer to route-map entries\n")
718e3744 15298{
585f1adc 15299 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15300 int idx_protocol = 1;
37a87b8f 15301 int idx_number = 3;
585f1adc
IR
15302 int idx_word = 5;
15303 int type;
15304 uint32_t metric;
15305 struct bgp_redist *red;
15306 bool changed;
15307 struct route_map *route_map =
15308 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15309
15310 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15311 if (type < 0) {
15312 vty_out(vty, "%% Invalid route type\n");
15313 return CMD_WARNING_CONFIG_FAILED;
15314 }
15315 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15316
585f1adc
IR
15317 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15318 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15319 changed |=
15320 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15321 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15322}
15323
15324ALIAS_HIDDEN(
15325 bgp_redistribute_ipv4_metric_rmap,
15326 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15327 "redistribute " FRR_IP_REDIST_STR_BGPD
15328 " metric (0-4294967295) route-map WORD",
15329 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15330 "Metric for redistributed routes\n"
15331 "Default metric\n"
15332 "Route map reference\n"
15333 "Pointer to route-map entries\n")
596c17ba 15334
585f1adc
IR
15335DEFUN (bgp_redistribute_ipv4_ospf,
15336 bgp_redistribute_ipv4_ospf_cmd,
15337 "redistribute <ospf|table> (1-65535)",
15338 "Redistribute information from another routing protocol\n"
15339 "Open Shortest Path First (OSPFv2)\n"
15340 "Non-main Kernel Routing Table\n"
15341 "Instance ID/Table ID\n")
7c8ff89e 15342{
585f1adc
IR
15343 VTY_DECLVAR_CONTEXT(bgp, bgp);
15344 int idx_ospf_table = 1;
d62a17ae 15345 int idx_number = 2;
585f1adc
IR
15346 unsigned short instance;
15347 unsigned short protocol;
7c8ff89e 15348
585f1adc 15349 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15350
585f1adc
IR
15351 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15352 protocol = ZEBRA_ROUTE_OSPF;
15353 else
15354 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15355
585f1adc
IR
15356 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15357 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15358}
15359
d62a17ae 15360ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15361 "redistribute <ospf|table> (1-65535)",
15362 "Redistribute information from another routing protocol\n"
15363 "Open Shortest Path First (OSPFv2)\n"
15364 "Non-main Kernel Routing Table\n"
15365 "Instance ID/Table ID\n")
596c17ba 15366
585f1adc
IR
15367DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15368 bgp_redistribute_ipv4_ospf_rmap_cmd,
15369 "redistribute <ospf|table> (1-65535) route-map WORD",
15370 "Redistribute information from another routing protocol\n"
15371 "Open Shortest Path First (OSPFv2)\n"
15372 "Non-main Kernel Routing Table\n"
15373 "Instance ID/Table ID\n"
15374 "Route map reference\n"
15375 "Pointer to route-map entries\n")
7c8ff89e 15376{
585f1adc
IR
15377 VTY_DECLVAR_CONTEXT(bgp, bgp);
15378 int idx_ospf_table = 1;
d62a17ae 15379 int idx_number = 2;
15380 int idx_word = 4;
585f1adc
IR
15381 struct bgp_redist *red;
15382 unsigned short instance;
15383 int protocol;
15384 bool changed;
15385 struct route_map *route_map =
15386 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15387
15388 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15389 protocol = ZEBRA_ROUTE_OSPF;
15390 else
15391 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15392
585f1adc
IR
15393 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15394 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15395 changed =
15396 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15397 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15398}
15399
15400ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15401 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15402 "redistribute <ospf|table> (1-65535) route-map WORD",
15403 "Redistribute information from another routing protocol\n"
15404 "Open Shortest Path First (OSPFv2)\n"
15405 "Non-main Kernel Routing Table\n"
15406 "Instance ID/Table ID\n"
15407 "Route map reference\n"
15408 "Pointer to route-map entries\n")
596c17ba 15409
585f1adc
IR
15410DEFUN (bgp_redistribute_ipv4_ospf_metric,
15411 bgp_redistribute_ipv4_ospf_metric_cmd,
15412 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15413 "Redistribute information from another routing protocol\n"
15414 "Open Shortest Path First (OSPFv2)\n"
15415 "Non-main Kernel Routing Table\n"
15416 "Instance ID/Table ID\n"
15417 "Metric for redistributed routes\n"
15418 "Default metric\n")
7c8ff89e 15419{
585f1adc
IR
15420 VTY_DECLVAR_CONTEXT(bgp, bgp);
15421 int idx_ospf_table = 1;
d62a17ae 15422 int idx_number = 2;
15423 int idx_number_2 = 4;
585f1adc
IR
15424 uint32_t metric;
15425 struct bgp_redist *red;
15426 unsigned short instance;
15427 int protocol;
15428 bool changed;
15429
15430 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15431 protocol = ZEBRA_ROUTE_OSPF;
15432 else
15433 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15434
585f1adc
IR
15435 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15436 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15437
585f1adc
IR
15438 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15439 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15440 metric);
15441 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15442}
15443
15444ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15445 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15446 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15447 "Redistribute information from another routing protocol\n"
15448 "Open Shortest Path First (OSPFv2)\n"
15449 "Non-main Kernel Routing Table\n"
15450 "Instance ID/Table ID\n"
15451 "Metric for redistributed routes\n"
15452 "Default metric\n")
596c17ba 15453
585f1adc
IR
15454DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15455 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15456 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15457 "Redistribute information from another routing protocol\n"
15458 "Open Shortest Path First (OSPFv2)\n"
15459 "Non-main Kernel Routing Table\n"
15460 "Instance ID/Table ID\n"
15461 "Route map reference\n"
15462 "Pointer to route-map entries\n"
15463 "Metric for redistributed routes\n"
15464 "Default metric\n")
7c8ff89e 15465{
585f1adc
IR
15466 VTY_DECLVAR_CONTEXT(bgp, bgp);
15467 int idx_ospf_table = 1;
d62a17ae 15468 int idx_number = 2;
15469 int idx_word = 4;
15470 int idx_number_2 = 6;
585f1adc
IR
15471 uint32_t metric;
15472 struct bgp_redist *red;
15473 unsigned short instance;
15474 int protocol;
15475 bool changed;
15476 struct route_map *route_map =
15477 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15478
15479 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15480 protocol = ZEBRA_ROUTE_OSPF;
15481 else
15482 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15483
585f1adc
IR
15484 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15485 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15486
585f1adc
IR
15487 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15488 changed =
15489 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15490 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15491 metric);
15492 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15493}
15494
15495ALIAS_HIDDEN(
15496 bgp_redistribute_ipv4_ospf_rmap_metric,
15497 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15498 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15499 "Redistribute information from another routing protocol\n"
15500 "Open Shortest Path First (OSPFv2)\n"
15501 "Non-main Kernel Routing Table\n"
15502 "Instance ID/Table ID\n"
15503 "Route map reference\n"
15504 "Pointer to route-map entries\n"
15505 "Metric for redistributed routes\n"
15506 "Default metric\n")
596c17ba 15507
585f1adc
IR
15508DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15509 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15510 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15511 "Redistribute information from another routing protocol\n"
15512 "Open Shortest Path First (OSPFv2)\n"
15513 "Non-main Kernel Routing Table\n"
15514 "Instance ID/Table ID\n"
15515 "Metric for redistributed routes\n"
15516 "Default metric\n"
15517 "Route map reference\n"
15518 "Pointer to route-map entries\n")
7c8ff89e 15519{
585f1adc
IR
15520 VTY_DECLVAR_CONTEXT(bgp, bgp);
15521 int idx_ospf_table = 1;
d62a17ae 15522 int idx_number = 2;
15523 int idx_number_2 = 4;
15524 int idx_word = 6;
585f1adc
IR
15525 uint32_t metric;
15526 struct bgp_redist *red;
15527 unsigned short instance;
15528 int protocol;
15529 bool changed;
15530 struct route_map *route_map =
15531 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15532
15533 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15534 protocol = ZEBRA_ROUTE_OSPF;
15535 else
15536 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15537
585f1adc
IR
15538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15539 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15540
585f1adc
IR
15541 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15542 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15543 metric);
15544 changed |=
15545 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15546 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15547}
15548
15549ALIAS_HIDDEN(
15550 bgp_redistribute_ipv4_ospf_metric_rmap,
15551 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15552 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15553 "Redistribute information from another routing protocol\n"
15554 "Open Shortest Path First (OSPFv2)\n"
15555 "Non-main Kernel Routing Table\n"
15556 "Instance ID/Table ID\n"
15557 "Metric for redistributed routes\n"
15558 "Default metric\n"
15559 "Route map reference\n"
15560 "Pointer to route-map entries\n")
596c17ba 15561
585f1adc
IR
15562DEFUN (no_bgp_redistribute_ipv4_ospf,
15563 no_bgp_redistribute_ipv4_ospf_cmd,
15564 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15565 NO_STR
15566 "Redistribute information from another routing protocol\n"
15567 "Open Shortest Path First (OSPFv2)\n"
15568 "Non-main Kernel Routing Table\n"
15569 "Instance ID/Table ID\n"
15570 "Metric for redistributed routes\n"
15571 "Default metric\n"
15572 "Route map reference\n"
15573 "Pointer to route-map entries\n")
7c8ff89e 15574{
585f1adc
IR
15575 VTY_DECLVAR_CONTEXT(bgp, bgp);
15576 int idx_ospf_table = 2;
d62a17ae 15577 int idx_number = 3;
585f1adc
IR
15578 unsigned short instance;
15579 int protocol;
37a87b8f 15580
585f1adc
IR
15581 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15582 protocol = ZEBRA_ROUTE_OSPF;
15583 else
15584 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15585
585f1adc
IR
15586 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15587 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15588}
15589
15590ALIAS_HIDDEN(
15591 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15592 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15593 NO_STR
15594 "Redistribute information from another routing protocol\n"
15595 "Open Shortest Path First (OSPFv2)\n"
15596 "Non-main Kernel Routing Table\n"
15597 "Instance ID/Table ID\n"
15598 "Metric for redistributed routes\n"
15599 "Default metric\n"
15600 "Route map reference\n"
15601 "Pointer to route-map entries\n")
596c17ba 15602
585f1adc
IR
15603DEFUN (no_bgp_redistribute_ipv4,
15604 no_bgp_redistribute_ipv4_cmd,
15605 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15606 NO_STR
15607 "Redistribute information from another routing protocol\n"
15608 FRR_IP_REDIST_HELP_STR_BGPD
15609 "Metric for redistributed routes\n"
15610 "Default metric\n"
15611 "Route map reference\n"
15612 "Pointer to route-map entries\n")
718e3744 15613{
585f1adc 15614 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15615 int idx_protocol = 2;
585f1adc 15616 int type;
d62a17ae 15617
585f1adc
IR
15618 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15619 if (type < 0) {
15620 vty_out(vty, "%% Invalid route type\n");
15621 return CMD_WARNING_CONFIG_FAILED;
15622 }
15623 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15624}
15625
15626ALIAS_HIDDEN(
15627 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15628 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15629 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15630 NO_STR
15631 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15632 "Metric for redistributed routes\n"
15633 "Default metric\n"
15634 "Route map reference\n"
15635 "Pointer to route-map entries\n")
596c17ba 15636
585f1adc
IR
15637DEFUN (bgp_redistribute_ipv6,
15638 bgp_redistribute_ipv6_cmd,
15639 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15640 "Redistribute information from another routing protocol\n"
15641 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15642{
585f1adc 15643 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15644 int idx_protocol = 1;
585f1adc 15645 int type;
718e3744 15646
585f1adc
IR
15647 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15648 if (type < 0) {
15649 vty_out(vty, "%% Invalid route type\n");
15650 return CMD_WARNING_CONFIG_FAILED;
15651 }
718e3744 15652
585f1adc
IR
15653 bgp_redist_add(bgp, AFI_IP6, type, 0);
15654 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15655}
15656
585f1adc
IR
15657DEFUN (bgp_redistribute_ipv6_rmap,
15658 bgp_redistribute_ipv6_rmap_cmd,
15659 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15660 "Redistribute information from another routing protocol\n"
15661 FRR_IP6_REDIST_HELP_STR_BGPD
15662 "Route map reference\n"
15663 "Pointer to route-map entries\n")
718e3744 15664{
585f1adc 15665 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15666 int idx_protocol = 1;
15667 int idx_word = 3;
585f1adc
IR
15668 int type;
15669 struct bgp_redist *red;
15670 bool changed;
15671 struct route_map *route_map =
15672 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15673
15674 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15675 if (type < 0) {
15676 vty_out(vty, "%% Invalid route type\n");
15677 return CMD_WARNING_CONFIG_FAILED;
15678 }
37a87b8f 15679
585f1adc
IR
15680 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15681 changed =
15682 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15683 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15684}
15685
585f1adc 15686DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15687 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15688 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15689 "Redistribute information from another routing protocol\n"
ab0181ee 15690 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15691 "Metric for redistributed routes\n"
15692 "Default metric\n")
15693{
585f1adc 15694 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15695 int idx_protocol = 1;
15696 int idx_number = 3;
585f1adc
IR
15697 int type;
15698 uint32_t metric;
15699 struct bgp_redist *red;
15700 bool changed;
15701
15702 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15703 if (type < 0) {
15704 vty_out(vty, "%% Invalid route type\n");
15705 return CMD_WARNING_CONFIG_FAILED;
15706 }
15707 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15708
585f1adc
IR
15709 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15710 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15711 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15712}
15713
585f1adc
IR
15714DEFUN (bgp_redistribute_ipv6_rmap_metric,
15715 bgp_redistribute_ipv6_rmap_metric_cmd,
15716 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15717 "Redistribute information from another routing protocol\n"
15718 FRR_IP6_REDIST_HELP_STR_BGPD
15719 "Route map reference\n"
15720 "Pointer to route-map entries\n"
15721 "Metric for redistributed routes\n"
15722 "Default metric\n")
718e3744 15723{
585f1adc 15724 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15725 int idx_protocol = 1;
15726 int idx_word = 3;
15727 int idx_number = 5;
585f1adc
IR
15728 int type;
15729 uint32_t metric;
15730 struct bgp_redist *red;
15731 bool changed;
15732 struct route_map *route_map =
15733 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15734
15735 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15736 if (type < 0) {
15737 vty_out(vty, "%% Invalid route type\n");
15738 return CMD_WARNING_CONFIG_FAILED;
15739 }
15740 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15741
585f1adc
IR
15742 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15743 changed =
15744 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15745 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
15746 metric);
15747 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15748}
15749
585f1adc
IR
15750DEFUN (bgp_redistribute_ipv6_metric_rmap,
15751 bgp_redistribute_ipv6_metric_rmap_cmd,
15752 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15753 "Redistribute information from another routing protocol\n"
15754 FRR_IP6_REDIST_HELP_STR_BGPD
15755 "Metric for redistributed routes\n"
15756 "Default metric\n"
15757 "Route map reference\n"
15758 "Pointer to route-map entries\n")
718e3744 15759{
585f1adc 15760 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15761 int idx_protocol = 1;
37a87b8f 15762 int idx_number = 3;
585f1adc
IR
15763 int idx_word = 5;
15764 int type;
15765 uint32_t metric;
15766 struct bgp_redist *red;
15767 bool changed;
15768 struct route_map *route_map =
15769 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15770
15771 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15772 if (type < 0) {
15773 vty_out(vty, "%% Invalid route type\n");
15774 return CMD_WARNING_CONFIG_FAILED;
15775 }
15776 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15777
585f1adc
IR
15778 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15779 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
15780 metric);
15781 changed |=
15782 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15783 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15784}
15785
585f1adc
IR
15786DEFUN (no_bgp_redistribute_ipv6,
15787 no_bgp_redistribute_ipv6_cmd,
15788 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15789 NO_STR
15790 "Redistribute information from another routing protocol\n"
15791 FRR_IP6_REDIST_HELP_STR_BGPD
15792 "Metric for redistributed routes\n"
15793 "Default metric\n"
15794 "Route map reference\n"
15795 "Pointer to route-map entries\n")
718e3744 15796{
585f1adc 15797 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15798 int idx_protocol = 2;
585f1adc 15799 int type;
37a87b8f 15800
585f1adc
IR
15801 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15802 if (type < 0) {
15803 vty_out(vty, "%% Invalid route type\n");
15804 return CMD_WARNING_CONFIG_FAILED;
15805 }
718e3744 15806
585f1adc 15807 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 15808}
15809
4ab46701
AR
15810/* Neighbor update tcp-mss. */
15811static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
15812 const char *tcp_mss_str)
15813{
15814 struct peer *peer;
15815 uint32_t tcp_mss_val = 0;
15816
15817 peer = peer_and_group_lookup_vty(vty, peer_str);
15818 if (!peer)
15819 return CMD_WARNING_CONFIG_FAILED;
15820
15821 if (tcp_mss_str) {
15822 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
15823 peer_tcp_mss_set(peer, tcp_mss_val);
15824 } else {
15825 peer_tcp_mss_unset(peer);
15826 }
15827
15828 return CMD_SUCCESS;
15829}
15830
15831DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
15832 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
15833 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15834 "TCP max segment size\n"
15835 "TCP MSS value\n")
15836{
15837 int peer_index = 1;
15838 int mss_index = 3;
15839
15840 vty_out(vty,
15841 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15842 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
15843 argv[mss_index]->arg);
15844}
15845
15846DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
15847 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
15848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
15849 "TCP max segment size\n"
15850 "TCP MSS value\n")
15851{
15852 int peer_index = 2;
15853
15854 vty_out(vty,
15855 " Warning: Reset BGP session for tcp-mss value to take effect\n");
15856 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
15857}
15858
dd65f45e
DL
15859static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
15860 afi_t afi, safi_t safi)
d62a17ae 15861{
15862 int i;
15863
15864 /* Unicast redistribution only. */
15865 if (safi != SAFI_UNICAST)
2b791107 15866 return;
d62a17ae 15867
15868 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
15869 /* Redistribute BGP does not make sense. */
15870 if (i != ZEBRA_ROUTE_BGP) {
15871 struct list *red_list;
15872 struct listnode *node;
15873 struct bgp_redist *red;
15874
15875 red_list = bgp->redist[afi][i];
15876 if (!red_list)
15877 continue;
15878
15879 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 15880 /* "redistribute" configuration. */
15881 vty_out(vty, " redistribute %s",
15882 zebra_route_string(i));
15883 if (red->instance)
15884 vty_out(vty, " %d", red->instance);
15885 if (red->redist_metric_flag)
15886 vty_out(vty, " metric %u",
15887 red->redist_metric);
15888 if (red->rmap.name)
15889 vty_out(vty, " route-map %s",
15890 red->rmap.name);
15891 vty_out(vty, "\n");
15892 }
15893 }
15894 }
718e3744 15895}
6b0655a2 15896
dd65f45e
DL
15897/* peer-group helpers for config-write */
15898
15899static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
15900{
15901 if (!peer_group_active(peer)) {
15902 if (CHECK_FLAG(peer->flags_invert, flag))
15903 return !CHECK_FLAG(peer->flags, flag);
15904 else
15905 return !!CHECK_FLAG(peer->flags, flag);
15906 }
15907
15908 return !!CHECK_FLAG(peer->flags_override, flag);
15909}
15910
15911static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
15912 uint32_t flag)
15913{
15914 if (!peer_group_active(peer)) {
15915 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
15916 return !peer_af_flag_check(peer, afi, safi, flag);
15917 else
15918 return !!peer_af_flag_check(peer, afi, safi, flag);
15919 }
15920
15921 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
15922}
15923
15924static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
15925 uint8_t type, int direct)
15926{
15927 struct bgp_filter *filter;
15928
15929 if (peer_group_active(peer))
15930 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
15931 type);
15932
15933 filter = &peer->filter[afi][safi];
15934 switch (type) {
15935 case PEER_FT_DISTRIBUTE_LIST:
15936 return !!(filter->dlist[direct].name);
15937 case PEER_FT_FILTER_LIST:
15938 return !!(filter->aslist[direct].name);
15939 case PEER_FT_PREFIX_LIST:
15940 return !!(filter->plist[direct].name);
15941 case PEER_FT_ROUTE_MAP:
15942 return !!(filter->map[direct].name);
15943 case PEER_FT_UNSUPPRESS_MAP:
15944 return !!(filter->usmap.name);
7f7940e6
MK
15945 case PEER_FT_ADVERTISE_MAP:
15946 return !!(filter->advmap.aname
15947 && ((filter->advmap.condition == direct)
15948 && filter->advmap.cname));
dd65f45e
DL
15949 default:
15950 return false;
15951 }
15952}
15953
15954/* Return true if the addpath type is set for peer and different from
15955 * peer-group.
15956 */
3dc339cd
DA
15957static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15958 safi_t safi)
dd65f45e
DL
15959{
15960 enum bgp_addpath_strat type, g_type;
15961
15962 type = peer->addpath_type[afi][safi];
15963
15964 if (type != BGP_ADDPATH_NONE) {
15965 if (peer_group_active(peer)) {
15966 g_type = peer->group->conf->addpath_type[afi][safi];
15967
15968 if (type != g_type)
3dc339cd 15969 return true;
dd65f45e 15970 else
3dc339cd 15971 return false;
dd65f45e
DL
15972 }
15973
3dc339cd 15974 return true;
dd65f45e
DL
15975 }
15976
3dc339cd 15977 return false;
dd65f45e
DL
15978}
15979
b9c7bc5a 15980/* This is part of the address-family block (unicast only) */
dd65f45e 15981static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
15982 afi_t afi)
15983{
b9c7bc5a 15984 int indent = 2;
53970de3 15985 uint32_t tovpn_sid_index = 0;
ddb5b488 15986
8a066a70 15987 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
15988 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15989 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
15990 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15991 bgp->vpn_policy[afi]
bb4f6190 15992 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
15993 else
15994 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15995 bgp->vpn_policy[afi]
15996 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15997 }
12a844a5
DS
15998 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15999 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16000 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16001 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16002 return;
16003
e70e9f8e
PZ
16004 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16005 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16006
16007 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16008
16009 } else {
16010 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16011 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16012 bgp->vpn_policy[afi].tovpn_label);
16013 }
ddb5b488 16014 }
53970de3
RS
16015
16016 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16017 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16018 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16019 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16020 } else if (tovpn_sid_index != 0) {
16021 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16022 tovpn_sid_index);
16023 }
16024
ddb5b488
PZ
16025 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16026 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16027 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16028 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16029 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16030 sizeof(buf)));
16031 }
16032 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16033 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16034
16035 char buf[PREFIX_STRLEN];
16036 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16037 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16038 sizeof(buf))) {
16039
b9c7bc5a
PZ
16040 vty_out(vty, "%*snexthop vpn export %s\n",
16041 indent, "", buf);
ddb5b488
PZ
16042 }
16043 }
16044 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16045 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16046 && ecommunity_cmp(
16047 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16048 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16049
16050 char *b = ecommunity_ecom2str(
16051 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16052 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16053 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16054 XFREE(MTYPE_ECOMMUNITY_STR, b);
16055 } else {
16056 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16057 char *b = ecommunity_ecom2str(
16058 bgp->vpn_policy[afi]
16059 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16060 ECOMMUNITY_FORMAT_ROUTE_MAP,
16061 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16062 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16063 XFREE(MTYPE_ECOMMUNITY_STR, b);
16064 }
16065 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16066 char *b = ecommunity_ecom2str(
16067 bgp->vpn_policy[afi]
16068 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16069 ECOMMUNITY_FORMAT_ROUTE_MAP,
16070 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16071 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16072 XFREE(MTYPE_ECOMMUNITY_STR, b);
16073 }
16074 }
bb4f6190
DS
16075
16076 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16077 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16078 bgp->vpn_policy[afi]
16079 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16080
301ad80a
PG
16081 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16082 char *b = ecommunity_ecom2str(
16083 bgp->vpn_policy[afi]
16084 .import_redirect_rtlist,
16085 ECOMMUNITY_FORMAT_ROUTE_MAP,
16086 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16087
9a659715
PG
16088 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16089 != ECOMMUNITY_SIZE)
c6423c31 16090 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16091 indent, "", b);
16092 else
16093 vty_out(vty, "%*srt redirect import %s\n",
16094 indent, "", b);
301ad80a
PG
16095 XFREE(MTYPE_ECOMMUNITY_STR, b);
16096 }
ddb5b488
PZ
16097}
16098
dd65f45e
DL
16099static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16100 afi_t afi, safi_t safi)
16101{
16102 struct bgp_filter *filter;
16103 char *addr;
16104
16105 addr = peer->host;
16106 filter = &peer->filter[afi][safi];
16107
16108 /* distribute-list. */
16109 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16110 FILTER_IN))
16111 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16112 filter->dlist[FILTER_IN].name);
16113
16114 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16115 FILTER_OUT))
16116 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16117 filter->dlist[FILTER_OUT].name);
16118
16119 /* prefix-list. */
16120 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16121 FILTER_IN))
16122 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16123 filter->plist[FILTER_IN].name);
16124
16125 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16126 FILTER_OUT))
16127 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16128 filter->plist[FILTER_OUT].name);
16129
16130 /* route-map. */
16131 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16132 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16133 filter->map[RMAP_IN].name);
16134
16135 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16136 RMAP_OUT))
16137 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16138 filter->map[RMAP_OUT].name);
16139
16140 /* unsuppress-map */
16141 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16142 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16143 filter->usmap.name);
16144
7f7940e6
MK
16145 /* advertise-map : always applied in OUT direction*/
16146 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16147 CONDITION_NON_EXIST))
16148 vty_out(vty,
16149 " neighbor %s advertise-map %s non-exist-map %s\n",
16150 addr, filter->advmap.aname, filter->advmap.cname);
16151
16152 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16153 CONDITION_EXIST))
16154 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16155 addr, filter->advmap.aname, filter->advmap.cname);
16156
dd65f45e
DL
16157 /* filter-list. */
16158 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16159 FILTER_IN))
16160 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16161 filter->aslist[FILTER_IN].name);
16162
16163 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16164 FILTER_OUT))
16165 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16166 filter->aslist[FILTER_OUT].name);
16167}
16168
16169/* BGP peer configuration display function. */
16170static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16171 struct peer *peer)
16172{
16173 struct peer *g_peer = NULL;
16174 char buf[SU_ADDRSTRLEN];
16175 char *addr;
16176 int if_pg_printed = false;
16177 int if_ras_printed = false;
16178
16179 /* Skip dynamic neighbors. */
16180 if (peer_dynamic_neighbor(peer))
16181 return;
16182
16183 if (peer->conf_if)
16184 addr = peer->conf_if;
16185 else
16186 addr = peer->host;
16187
16188 /************************************
16189 ****** Global to the neighbor ******
16190 ************************************/
16191 if (peer->conf_if) {
16192 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16193 vty_out(vty, " neighbor %s interface v6only", addr);
16194 else
16195 vty_out(vty, " neighbor %s interface", addr);
16196
16197 if (peer_group_active(peer)) {
16198 vty_out(vty, " peer-group %s", peer->group->name);
16199 if_pg_printed = true;
16200 } else if (peer->as_type == AS_SPECIFIED) {
16201 vty_out(vty, " remote-as %u", peer->as);
16202 if_ras_printed = true;
16203 } else if (peer->as_type == AS_INTERNAL) {
16204 vty_out(vty, " remote-as internal");
16205 if_ras_printed = true;
16206 } else if (peer->as_type == AS_EXTERNAL) {
16207 vty_out(vty, " remote-as external");
16208 if_ras_printed = true;
16209 }
16210
16211 vty_out(vty, "\n");
16212 }
16213
16214 /* remote-as and peer-group */
16215 /* peer is a member of a peer-group */
16216 if (peer_group_active(peer)) {
16217 g_peer = peer->group->conf;
16218
16219 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16220 if (peer->as_type == AS_SPECIFIED) {
16221 vty_out(vty, " neighbor %s remote-as %u\n",
16222 addr, peer->as);
16223 } else if (peer->as_type == AS_INTERNAL) {
16224 vty_out(vty,
16225 " neighbor %s remote-as internal\n",
16226 addr);
16227 } else if (peer->as_type == AS_EXTERNAL) {
16228 vty_out(vty,
16229 " neighbor %s remote-as external\n",
16230 addr);
16231 }
16232 }
16233
16234 /* For swpX peers we displayed the peer-group
16235 * via 'neighbor swpX interface peer-group PGNAME' */
16236 if (!if_pg_printed)
16237 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16238 peer->group->name);
16239 }
16240
16241 /* peer is NOT a member of a peer-group */
16242 else {
16243 /* peer is a peer-group, declare the peer-group */
16244 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16245 vty_out(vty, " neighbor %s peer-group\n", addr);
16246 }
16247
16248 if (!if_ras_printed) {
16249 if (peer->as_type == AS_SPECIFIED) {
16250 vty_out(vty, " neighbor %s remote-as %u\n",
16251 addr, peer->as);
16252 } else if (peer->as_type == AS_INTERNAL) {
16253 vty_out(vty,
16254 " neighbor %s remote-as internal\n",
16255 addr);
16256 } else if (peer->as_type == AS_EXTERNAL) {
16257 vty_out(vty,
16258 " neighbor %s remote-as external\n",
16259 addr);
16260 }
16261 }
16262 }
16263
16264 /* local-as */
16265 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16266 vty_out(vty, " neighbor %s local-as %u", addr,
16267 peer->change_local_as);
16268 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16269 vty_out(vty, " no-prepend");
16270 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16271 vty_out(vty, " replace-as");
16272 vty_out(vty, "\n");
16273 }
16274
16275 /* description */
16276 if (peer->desc) {
16277 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16278 }
16279
16280 /* shutdown */
16281 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16282 if (peer->tx_shutdown_message)
16283 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16284 peer->tx_shutdown_message);
16285 else
16286 vty_out(vty, " neighbor %s shutdown\n", addr);
16287 }
16288
8336c896
DA
16289 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16290 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16291 peer->rtt_expected, peer->rtt_keepalive_conf);
16292
dd65f45e 16293 /* bfd */
21bfce98
RZ
16294 if (peer->bfd_config)
16295 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16296
16297 /* password */
16298 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16299 vty_out(vty, " neighbor %s password %s\n", addr,
16300 peer->password);
16301
16302 /* neighbor solo */
16303 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16304 if (!peer_group_active(peer)) {
16305 vty_out(vty, " neighbor %s solo\n", addr);
16306 }
16307 }
16308
16309 /* BGP port */
16310 if (peer->port != BGP_PORT_DEFAULT) {
16311 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16312 }
16313
16314 /* Local interface name */
16315 if (peer->ifname) {
16316 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16317 }
16318
4ab46701
AR
16319 /* TCP max segment size */
16320 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16321 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16322
dd65f45e
DL
16323 /* passive */
16324 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16325 vty_out(vty, " neighbor %s passive\n", addr);
16326
16327 /* ebgp-multihop */
16328 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16329 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16330 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16331 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16332 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16333 peer->ttl);
16334 }
16335 }
16336
16337 /* ttl-security hops */
e2521429 16338 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16339 if (!peer_group_active(peer)
16340 || g_peer->gtsm_hops != peer->gtsm_hops) {
16341 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16342 addr, peer->gtsm_hops);
16343 }
16344 }
16345
16346 /* disable-connected-check */
16347 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16348 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16349
16350 /* enforce-first-as */
16351 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16352 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16353
16354 /* update-source */
16355 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16356 if (peer->update_source)
16357 vty_out(vty, " neighbor %s update-source %s\n", addr,
16358 sockunion2str(peer->update_source, buf,
16359 SU_ADDRSTRLEN));
16360 else if (peer->update_if)
16361 vty_out(vty, " neighbor %s update-source %s\n", addr,
16362 peer->update_if);
16363 }
16364
16365 /* advertisement-interval */
16366 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16367 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16368 peer->routeadv);
16369
16370 /* timers */
16371 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16372 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16373 peer->keepalive, peer->holdtime);
16374
16375 /* timers connect */
16376 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16377 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16378 peer->connect);
5d5393b9
DL
16379 /* need special-case handling for changed default values due to
16380 * config profile / version (because there is no "timers bgp connect"
16381 * command, we need to save this per-peer :/)
16382 */
16383 else if (!peer_group_active(peer) && !peer->connect &&
16384 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16385 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16386 peer->bgp->default_connect_retry);
dd65f45e 16387
d43114f3
DS
16388 /* timers delayopen */
16389 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16390 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16391 peer->delayopen);
16392 /* Save config even though flag is not set if default values have been
16393 * changed
16394 */
16395 else if (!peer_group_active(peer) && !peer->delayopen
16396 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16397 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16398 peer->bgp->default_delayopen);
16399
dd65f45e
DL
16400 /* capability dynamic */
16401 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16402 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16403
16404 /* capability extended-nexthop */
16405 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16406 if (!peer->conf_if) {
16407 if (CHECK_FLAG(peer->flags_invert,
16408 PEER_FLAG_CAPABILITY_ENHE))
16409 vty_out(vty,
16410 " no neighbor %s capability extended-nexthop\n",
16411 addr);
16412 else
16413 vty_out(vty,
16414 " neighbor %s capability extended-nexthop\n",
16415 addr);
16416 }
16417 }
16418
16419 /* dont-capability-negotiation */
16420 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16421 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16422
16423 /* override-capability */
16424 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16425 vty_out(vty, " neighbor %s override-capability\n", addr);
16426
16427 /* strict-capability-match */
16428 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16429 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16430
16431 /* Sender side AS path loop detection. */
16432 if (peer->as_path_loop_detection)
16433 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16434 addr);
cfd47646 16435
16436 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16437 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16438
16439 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16440 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16441 vty_out(vty,
16442 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16443 } else if (CHECK_FLAG(
16444 peer->peer_gr_new_status_flag,
16445 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16446 vty_out(vty,
16447 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16448 } else if (
16449 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16450 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16451 && !(CHECK_FLAG(
16452 peer->peer_gr_new_status_flag,
16453 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16454 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16455 addr);
cfd47646 16456 }
16457 }
dd65f45e
DL
16458}
16459
16460/* BGP peer configuration display function. */
16461static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16462 struct peer *peer, afi_t afi, safi_t safi)
16463{
16464 struct peer *g_peer = NULL;
16465 char *addr;
16466 bool flag_scomm, flag_secomm, flag_slcomm;
16467
16468 /* Skip dynamic neighbors. */
16469 if (peer_dynamic_neighbor(peer))
16470 return;
16471
16472 if (peer->conf_if)
16473 addr = peer->conf_if;
16474 else
16475 addr = peer->host;
16476
16477 /************************************
16478 ****** Per AF to the neighbor ******
16479 ************************************/
16480 if (peer_group_active(peer)) {
16481 g_peer = peer->group->conf;
16482
16483 /* If the peer-group is active but peer is not, print a 'no
16484 * activate' */
16485 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16486 vty_out(vty, " no neighbor %s activate\n", addr);
16487 }
16488
16489 /* If the peer-group is not active but peer is, print an
16490 'activate' */
16491 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16492 vty_out(vty, " neighbor %s activate\n", addr);
16493 }
16494 } else {
16495 if (peer->afc[afi][safi]) {
38d11af5
TA
16496 if (safi == SAFI_ENCAP)
16497 vty_out(vty, " neighbor %s activate\n", addr);
16498 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16499 vty_out(vty, " neighbor %s activate\n", addr);
16500 } else {
38d11af5
TA
16501 if (bgp->default_af[afi][safi])
16502 vty_out(vty, " no neighbor %s activate\n",
16503 addr);
dd65f45e
DL
16504 }
16505 }
16506
16507 /* addpath TX knobs */
16508 if (peergroup_af_addpath_check(peer, afi, safi)) {
16509 switch (peer->addpath_type[afi][safi]) {
16510 case BGP_ADDPATH_ALL:
16511 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16512 addr);
16513 break;
16514 case BGP_ADDPATH_BEST_PER_AS:
16515 vty_out(vty,
16516 " neighbor %s addpath-tx-bestpath-per-AS\n",
16517 addr);
16518 break;
16519 case BGP_ADDPATH_MAX:
16520 case BGP_ADDPATH_NONE:
16521 break;
16522 }
16523 }
16524
16525 /* ORF capability. */
16526 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16527 || peergroup_af_flag_check(peer, afi, safi,
16528 PEER_FLAG_ORF_PREFIX_RM)) {
16529 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16530
16531 if (peergroup_af_flag_check(peer, afi, safi,
16532 PEER_FLAG_ORF_PREFIX_SM)
16533 && peergroup_af_flag_check(peer, afi, safi,
16534 PEER_FLAG_ORF_PREFIX_RM))
16535 vty_out(vty, " both");
16536 else if (peergroup_af_flag_check(peer, afi, safi,
16537 PEER_FLAG_ORF_PREFIX_SM))
16538 vty_out(vty, " send");
16539 else
16540 vty_out(vty, " receive");
16541 vty_out(vty, "\n");
16542 }
16543
dd65f45e
DL
16544 /* Route reflector client. */
16545 if (peergroup_af_flag_check(peer, afi, safi,
16546 PEER_FLAG_REFLECTOR_CLIENT)) {
16547 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16548 }
16549
16550 /* next-hop-self force */
16551 if (peergroup_af_flag_check(peer, afi, safi,
16552 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16553 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16554 }
16555
16556 /* next-hop-self */
16557 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16558 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16559 }
16560
16561 /* remove-private-AS */
16562 if (peergroup_af_flag_check(peer, afi, safi,
16563 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16564 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16565 addr);
16566 }
16567
16568 else if (peergroup_af_flag_check(peer, afi, safi,
16569 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16570 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16571 addr);
16572 }
16573
16574 else if (peergroup_af_flag_check(peer, afi, safi,
16575 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16576 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16577 }
16578
16579 else if (peergroup_af_flag_check(peer, afi, safi,
16580 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16581 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16582 }
16583
16584 /* as-override */
16585 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16586 vty_out(vty, " neighbor %s as-override\n", addr);
16587 }
16588
16589 /* send-community print. */
16590 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16591 PEER_FLAG_SEND_COMMUNITY);
16592 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16593 PEER_FLAG_SEND_EXT_COMMUNITY);
16594 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16595 PEER_FLAG_SEND_LARGE_COMMUNITY);
16596
16597 if (flag_scomm && flag_secomm && flag_slcomm) {
16598 vty_out(vty, " no neighbor %s send-community all\n", addr);
16599 } else {
16600 if (flag_scomm)
16601 vty_out(vty, " no neighbor %s send-community\n", addr);
16602 if (flag_secomm)
16603 vty_out(vty,
16604 " no neighbor %s send-community extended\n",
16605 addr);
16606
16607 if (flag_slcomm)
16608 vty_out(vty, " no neighbor %s send-community large\n",
16609 addr);
16610 }
16611
16612 /* Default information */
16613 if (peergroup_af_flag_check(peer, afi, safi,
16614 PEER_FLAG_DEFAULT_ORIGINATE)) {
16615 vty_out(vty, " neighbor %s default-originate", addr);
16616
16617 if (peer->default_rmap[afi][safi].name)
16618 vty_out(vty, " route-map %s",
16619 peer->default_rmap[afi][safi].name);
16620
16621 vty_out(vty, "\n");
16622 }
16623
16624 /* Soft reconfiguration inbound. */
16625 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16626 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16627 addr);
16628 }
16629
16630 /* maximum-prefix. */
16631 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16632 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16633 peer->pmax[afi][safi]);
16634
16635 if (peer->pmax_threshold[afi][safi]
16636 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16637 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16638 if (peer_af_flag_check(peer, afi, safi,
16639 PEER_FLAG_MAX_PREFIX_WARNING))
16640 vty_out(vty, " warning-only");
16641 if (peer->pmax_restart[afi][safi])
16642 vty_out(vty, " restart %u",
16643 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16644 if (peer_af_flag_check(peer, afi, safi,
16645 PEER_FLAG_MAX_PREFIX_FORCE))
16646 vty_out(vty, " force");
dd65f45e
DL
16647
16648 vty_out(vty, "\n");
16649 }
16650
fde246e8
DA
16651 /* maximum-prefix-out */
16652 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16653 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16654 addr, peer->pmax_out[afi][safi]);
16655
dd65f45e
DL
16656 /* Route server client. */
16657 if (peergroup_af_flag_check(peer, afi, safi,
16658 PEER_FLAG_RSERVER_CLIENT)) {
16659 vty_out(vty, " neighbor %s route-server-client\n", addr);
16660 }
16661
16662 /* Nexthop-local unchanged. */
16663 if (peergroup_af_flag_check(peer, afi, safi,
16664 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16665 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16666 }
16667
16668 /* allowas-in <1-10> */
16669 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16670 if (peer_af_flag_check(peer, afi, safi,
16671 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16672 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16673 } else if (peer->allowas_in[afi][safi] == 3) {
16674 vty_out(vty, " neighbor %s allowas-in\n", addr);
16675 } else {
16676 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16677 peer->allowas_in[afi][safi]);
16678 }
16679 }
16680
16681 /* weight */
16682 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16683 vty_out(vty, " neighbor %s weight %lu\n", addr,
16684 peer->weight[afi][safi]);
16685
16686 /* Filter. */
16687 bgp_config_write_filter(vty, peer, afi, safi);
16688
16689 /* atribute-unchanged. */
16690 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16691 || (safi != SAFI_EVPN
16692 && peer_af_flag_check(peer, afi, safi,
16693 PEER_FLAG_NEXTHOP_UNCHANGED))
16694 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16695
16696 if (!peer_group_active(peer)
16697 || peergroup_af_flag_check(peer, afi, safi,
16698 PEER_FLAG_AS_PATH_UNCHANGED)
16699 || peergroup_af_flag_check(peer, afi, safi,
16700 PEER_FLAG_NEXTHOP_UNCHANGED)
16701 || peergroup_af_flag_check(peer, afi, safi,
16702 PEER_FLAG_MED_UNCHANGED)) {
16703
16704 vty_out(vty,
16705 " neighbor %s attribute-unchanged%s%s%s\n",
16706 addr,
16707 peer_af_flag_check(peer, afi, safi,
16708 PEER_FLAG_AS_PATH_UNCHANGED)
16709 ? " as-path"
16710 : "",
16711 peer_af_flag_check(peer, afi, safi,
16712 PEER_FLAG_NEXTHOP_UNCHANGED)
16713 ? " next-hop"
16714 : "",
16715 peer_af_flag_check(peer, afi, safi,
16716 PEER_FLAG_MED_UNCHANGED)
16717 ? " med"
16718 : "");
16719 }
16720 }
16721}
16722
16723/* Address family based peer configuration display. */
16724static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
16725 safi_t safi)
16726{
16727 struct peer *peer;
16728 struct peer_group *group;
16729 struct listnode *node, *nnode;
16730
16731
16732 vty_frame(vty, " !\n address-family ");
16733 if (afi == AFI_IP) {
16734 if (safi == SAFI_UNICAST)
16735 vty_frame(vty, "ipv4 unicast");
16736 else if (safi == SAFI_LABELED_UNICAST)
16737 vty_frame(vty, "ipv4 labeled-unicast");
16738 else if (safi == SAFI_MULTICAST)
16739 vty_frame(vty, "ipv4 multicast");
16740 else if (safi == SAFI_MPLS_VPN)
16741 vty_frame(vty, "ipv4 vpn");
16742 else if (safi == SAFI_ENCAP)
16743 vty_frame(vty, "ipv4 encap");
16744 else if (safi == SAFI_FLOWSPEC)
16745 vty_frame(vty, "ipv4 flowspec");
16746 } else if (afi == AFI_IP6) {
16747 if (safi == SAFI_UNICAST)
16748 vty_frame(vty, "ipv6 unicast");
16749 else if (safi == SAFI_LABELED_UNICAST)
16750 vty_frame(vty, "ipv6 labeled-unicast");
16751 else if (safi == SAFI_MULTICAST)
16752 vty_frame(vty, "ipv6 multicast");
16753 else if (safi == SAFI_MPLS_VPN)
16754 vty_frame(vty, "ipv6 vpn");
16755 else if (safi == SAFI_ENCAP)
16756 vty_frame(vty, "ipv6 encap");
16757 else if (safi == SAFI_FLOWSPEC)
16758 vty_frame(vty, "ipv6 flowspec");
16759 } else if (afi == AFI_L2VPN) {
16760 if (safi == SAFI_EVPN)
16761 vty_frame(vty, "l2vpn evpn");
16762 }
16763 vty_frame(vty, "\n");
16764
16765 bgp_config_write_distance(vty, bgp, afi, safi);
16766
16767 bgp_config_write_network(vty, bgp, afi, safi);
16768
16769 bgp_config_write_redistribute(vty, bgp, afi, safi);
16770
8a4e7fe6
DA
16771 /* BGP flag dampening. */
16772 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 16773 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 16774
dd65f45e
DL
16775 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
16776 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
16777
16778 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
16779 /* Do not display doppelganger peers */
16780 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16781 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
16782 }
16783
16784 bgp_config_write_maxpaths(vty, bgp, afi, safi);
16785 bgp_config_write_table_map(vty, bgp, afi, safi);
16786
16787 if (safi == SAFI_EVPN)
16788 bgp_config_write_evpn_info(vty, bgp, afi, safi);
16789
16790 if (safi == SAFI_FLOWSPEC)
16791 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
16792
16793 if (safi == SAFI_UNICAST) {
16794 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
16795 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16796 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
16797
16798 vty_out(vty, " export vpn\n");
16799 }
16800 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16801 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
16802
16803 vty_out(vty, " import vpn\n");
16804 }
16805 if (CHECK_FLAG(bgp->af_flags[afi][safi],
16806 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
16807 char *name;
16808
16809 for (ALL_LIST_ELEMENTS_RO(
16810 bgp->vpn_policy[afi].import_vrf, node,
16811 name))
16812 vty_out(vty, " import vrf %s\n", name);
16813 }
16814 }
16815
16816 vty_endframe(vty, " exit-address-family\n");
16817}
16818
16819int bgp_config_write(struct vty *vty)
16820{
16821 struct bgp *bgp;
16822 struct peer_group *group;
16823 struct peer *peer;
16824 struct listnode *node, *nnode;
16825 struct listnode *mnode, *mnnode;
b16bcbba
TA
16826 afi_t afi;
16827 safi_t safi;
dd65f45e
DL
16828
16829 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
16830 vty_out(vty, "bgp route-map delay-timer %u\n",
16831 bm->rmap_update_timer);
16832
d70583f7
D
16833 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
16834 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
16835 if (bm->v_update_delay != bm->v_establish_wait)
16836 vty_out(vty, " %d", bm->v_establish_wait);
16837 vty_out(vty, "\n");
16838 }
16839
9acb67cb
DS
16840 if (bm->wait_for_fib)
16841 vty_out(vty, "bgp suppress-fib-pending\n");
16842
05bd726c 16843 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16844 vty_out(vty, "bgp graceful-shutdown\n");
16845
c163f297
DS
16846 /* No-RIB (Zebra) option flag configuration */
16847 if (bgp_option_check(BGP_OPT_NO_FIB))
16848 vty_out(vty, "bgp no-rib\n");
16849
ec0acb80 16850 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
16851 vty_out(vty, "no bgp send-extra-data zebra\n");
16852
dd65f45e
DL
16853 /* BGP configuration. */
16854 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
16855
16856 /* skip all auto created vrf as they dont have user config */
16857 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
16858 continue;
16859
16860 /* Router bgp ASN */
16861 vty_out(vty, "router bgp %u", bgp->as);
16862
16863 if (bgp->name)
16864 vty_out(vty, " %s %s",
16865 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
16866 ? "view" : "vrf", bgp->name);
16867 vty_out(vty, "\n");
16868
16869 /* BGP fast-external-failover. */
16870 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
16871 vty_out(vty, " no bgp fast-external-failover\n");
16872
16873 /* BGP router ID. */
3a6290bd 16874 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
16875 vty_out(vty, " bgp router-id %pI4\n",
16876 &bgp->router_id_static);
dd65f45e 16877
c208c586
S
16878 /* Suppress fib pending */
16879 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
16880 vty_out(vty, " bgp suppress-fib-pending\n");
16881
dd65f45e 16882 /* BGP log-neighbor-changes. */
892fedb6 16883 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 16884 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 16885 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
16886 CHECK_FLAG(bgp->flags,
16887 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
16888 ? ""
16889 : "no ");
16890
16891 /* BGP configuration. */
892fedb6 16892 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
16893 vty_out(vty, " bgp always-compare-med\n");
16894
16895 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
16896 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
16897 != SAVE_BGP_EBGP_REQUIRES_POLICY)
16898 vty_out(vty, " %sbgp ebgp-requires-policy\n",
16899 CHECK_FLAG(bgp->flags,
16900 BGP_FLAG_EBGP_REQUIRES_POLICY)
16901 ? ""
16902 : "no ");
dd65f45e
DL
16903
16904 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 16905 if (bgp->reject_as_sets)
dd65f45e
DL
16906 vty_out(vty, " bgp reject-as-sets\n");
16907
2adac256
DA
16908 /* Suppress duplicate updates if the route actually not changed
16909 */
16910 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
16911 != SAVE_BGP_SUPPRESS_DUPLICATES)
16912 vty_out(vty, " %sbgp suppress-duplicates\n",
16913 CHECK_FLAG(bgp->flags,
16914 BGP_FLAG_SUPPRESS_DUPLICATES)
16915 ? ""
16916 : "no ");
16917
b16bcbba
TA
16918 /* BGP default <afi>-<safi> */
16919 FOREACH_AFI_SAFI (afi, safi) {
16920 if (afi == AFI_IP && safi == SAFI_UNICAST) {
16921 if (!bgp->default_af[afi][safi])
16922 vty_out(vty, " no bgp default %s\n",
16923 get_bgp_default_af_flag(afi,
16924 safi));
16925 } else if (bgp->default_af[afi][safi])
16926 vty_out(vty, " bgp default %s\n",
16927 get_bgp_default_af_flag(afi, safi));
16928 }
e84c59af 16929
dd65f45e
DL
16930 /* BGP default local-preference. */
16931 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
16932 vty_out(vty, " bgp default local-preference %u\n",
16933 bgp->default_local_pref);
16934
16935 /* BGP default show-hostname */
892fedb6 16936 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 16937 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 16938 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 16939 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
16940 ? ""
16941 : "no ");
16942
aef999a2
DA
16943 /* BGP default show-nexthop-hostname */
16944 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16945 != SAVE_BGP_SHOW_HOSTNAME)
16946 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
16947 CHECK_FLAG(bgp->flags,
16948 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
16949 ? ""
16950 : "no ");
16951
dd65f45e
DL
16952 /* BGP default subgroup-pkt-queue-max. */
16953 if (bgp->default_subgroup_pkt_queue_max
16954 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
16955 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
16956 bgp->default_subgroup_pkt_queue_max);
16957
16958 /* BGP client-to-client reflection. */
892fedb6 16959 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
16960 vty_out(vty, " no bgp client-to-client reflection\n");
16961
16962 /* BGP cluster ID. */
16963 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
16964 vty_out(vty, " bgp cluster-id %pI4\n",
16965 &bgp->cluster_id);
dd65f45e
DL
16966
16967 /* Disable ebgp connected nexthop check */
892fedb6 16968 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
16969 vty_out(vty,
16970 " bgp disable-ebgp-connected-route-check\n");
16971
16972 /* Confederation identifier*/
16973 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
16974 vty_out(vty, " bgp confederation identifier %u\n",
16975 bgp->confed_id);
16976
16977 /* Confederation peer */
16978 if (bgp->confed_peers_cnt > 0) {
16979 int i;
16980
16981 vty_out(vty, " bgp confederation peers");
16982
16983 for (i = 0; i < bgp->confed_peers_cnt; i++)
16984 vty_out(vty, " %u", bgp->confed_peers[i]);
16985
16986 vty_out(vty, "\n");
16987 }
16988
16989 /* BGP deterministic-med. */
892fedb6 16990 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 16991 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 16992 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
16993 CHECK_FLAG(bgp->flags,
16994 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
16995 ? ""
16996 : "no ");
16997
16998 /* BGP update-delay. */
16999 bgp_config_write_update_delay(vty, bgp);
17000
17001 if (bgp->v_maxmed_onstartup
17002 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17003 vty_out(vty, " bgp max-med on-startup %u",
17004 bgp->v_maxmed_onstartup);
17005 if (bgp->maxmed_onstartup_value
17006 != BGP_MAXMED_VALUE_DEFAULT)
17007 vty_out(vty, " %u",
17008 bgp->maxmed_onstartup_value);
17009 vty_out(vty, "\n");
17010 }
17011 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17012 vty_out(vty, " bgp max-med administrative");
17013 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17014 vty_out(vty, " %u", bgp->maxmed_admin_value);
17015 vty_out(vty, "\n");
17016 }
17017
17018 /* write quanta */
17019 bgp_config_write_wpkt_quanta(vty, bgp);
17020 /* read quanta */
17021 bgp_config_write_rpkt_quanta(vty, bgp);
17022
17023 /* coalesce time */
17024 bgp_config_write_coalesce_time(vty, bgp);
17025
05bd726c 17026 /* BGP per-instance graceful-shutdown */
17027 /* BGP-wide settings and per-instance settings are mutually
17028 * exclusive.
17029 */
17030 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17031 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17032 vty_out(vty, " bgp graceful-shutdown\n");
17033
dd65f45e
DL
17034 /* BGP graceful-restart. */
17035 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17036 vty_out(vty,
17037 " bgp graceful-restart stalepath-time %u\n",
17038 bgp->stalepath_time);
cfd47646 17039
dd65f45e
DL
17040 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17041 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17042 bgp->restart_time);
cfd47646 17043
17044 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17045 vty_out(vty,
17046 " bgp graceful-restart select-defer-time %u\n",
17047 bgp->select_defer_time);
17048
17049 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17050 vty_out(vty, " bgp graceful-restart\n");
17051
cfd47646 17052 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17053 vty_out(vty, " bgp graceful-restart-disable\n");
17054
dd65f45e 17055 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17056 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17057 vty_out(vty,
17058 " bgp graceful-restart preserve-fw-state\n");
17059
dc95985f 17060 /* Stale timer for RIB */
17061 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17062 vty_out(vty,
17063 " bgp graceful-restart rib-stale-time %u\n",
17064 bgp->rib_stale_time);
17065
dd65f45e 17066 /* BGP bestpath method. */
892fedb6 17067 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17068 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17069 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17070 vty_out(vty, " bgp bestpath as-path confed\n");
17071
892fedb6
DA
17072 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17073 if (CHECK_FLAG(bgp->flags,
17074 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17075 vty_out(vty,
17076 " bgp bestpath as-path multipath-relax as-set\n");
17077 } else {
17078 vty_out(vty,
17079 " bgp bestpath as-path multipath-relax\n");
17080 }
17081 }
17082
892fedb6 17083 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17084 vty_out(vty,
17085 " bgp route-reflector allow-outbound-policy\n");
17086 }
892fedb6 17087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17088 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17089 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17090 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17091 vty_out(vty, " bgp bestpath med");
892fedb6 17092 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17093 vty_out(vty, " confed");
892fedb6
DA
17094 if (CHECK_FLAG(bgp->flags,
17095 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17096 vty_out(vty, " missing-as-worst");
17097 vty_out(vty, "\n");
17098 }
17099
ee88563a
JM
17100 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17101 vty_out(vty,
17102 " bgp bestpath peer-type multipath-relax\n");
17103
f7e1c681 17104 /* Link bandwidth handling. */
17105 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17106 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17107 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17108 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17109 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17110 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17111
dd65f45e 17112 /* BGP network import check. */
892fedb6 17113 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17114 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17115 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17116 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17117 ? ""
17118 : "no ");
17119
17120 /* BGP timers configuration. */
5d5393b9 17121 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17122 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17123 vty_out(vty, " timers bgp %u %u\n",
17124 bgp->default_keepalive, bgp->default_holdtime);
17125
389e4f92
QY
17126 /* Conditional advertisement timer configuration */
17127 if (bgp->condition_check_period
17128 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17129 vty_out(vty,
17130 " bgp conditional-advertisement timer %u\n",
17131 bgp->condition_check_period);
17132
dd65f45e
DL
17133 /* peer-group */
17134 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17135 bgp_config_write_peer_global(vty, bgp, group->conf);
17136 }
17137
17138 /* Normal neighbor configuration. */
17139 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17140 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17141 bgp_config_write_peer_global(vty, bgp, peer);
17142 }
17143
17144 /* listen range and limit for dynamic BGP neighbors */
17145 bgp_config_write_listen(vty, bgp);
17146
17147 /*
17148 * BGP default autoshutdown neighbors
17149 *
17150 * This must be placed after any peer and peer-group
17151 * configuration, to avoid setting all peers to shutdown after
17152 * a daemon restart, which is undesired behavior. (see #2286)
17153 */
17154 if (bgp->autoshutdown)
17155 vty_out(vty, " bgp default shutdown\n");
17156
9cf59432
DS
17157 /* BGP instance administrative shutdown */
17158 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17159 vty_out(vty, " bgp shutdown\n");
17160
a0281b2e
HS
17161 if (bgp->srv6_enabled) {
17162 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17163 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17164 vty_out(vty, " locator %s\n",
17165 bgp->srv6_locator_name);
ff7c3ee1 17166 vty_endframe(vty, " exit\n");
a0281b2e
HS
17167 }
17168
17169
dd65f45e
DL
17170 /* IPv4 unicast configuration. */
17171 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17172
17173 /* IPv4 multicast configuration. */
17174 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17175
17176 /* IPv4 labeled-unicast configuration. */
17177 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17178
17179 /* IPv4 VPN configuration. */
17180 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17181
17182 /* ENCAPv4 configuration. */
17183 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17184
17185 /* FLOWSPEC v4 configuration. */
17186 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17187
17188 /* IPv6 unicast configuration. */
17189 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17190
17191 /* IPv6 multicast configuration. */
17192 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17193
17194 /* IPv6 labeled-unicast configuration. */
17195 bgp_config_write_family(vty, bgp, AFI_IP6,
17196 SAFI_LABELED_UNICAST);
17197
17198 /* IPv6 VPN configuration. */
17199 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17200
17201 /* ENCAPv6 configuration. */
17202 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17203
17204 /* FLOWSPEC v6 configuration. */
17205 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17206
17207 /* EVPN configuration. */
17208 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17209
17210 hook_call(bgp_inst_config_write, bgp, vty);
17211
49e5a4a0 17212#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17213 bgp_rfapi_cfg_write(vty, bgp);
17214#endif
17215
17216 vty_out(vty, "!\n");
17217 }
17218 return 0;
17219}
17220
ddb5b488 17221
718e3744 17222/* BGP node structure. */
d62a17ae 17223static struct cmd_node bgp_node = {
f4b8291f 17224 .name = "bgp",
62b346ee 17225 .node = BGP_NODE,
24389580 17226 .parent_node = CONFIG_NODE,
62b346ee 17227 .prompt = "%s(config-router)# ",
612c2c15 17228 .config_write = bgp_config_write,
718e3744 17229};
17230
d62a17ae 17231static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17232 .name = "bgp ipv4 unicast",
62b346ee 17233 .node = BGP_IPV4_NODE,
24389580 17234 .parent_node = BGP_NODE,
62b346ee 17235 .prompt = "%s(config-router-af)# ",
718e3744 17236};
17237
d62a17ae 17238static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17239 .name = "bgp ipv4 multicast",
62b346ee 17240 .node = BGP_IPV4M_NODE,
24389580 17241 .parent_node = BGP_NODE,
62b346ee 17242 .prompt = "%s(config-router-af)# ",
718e3744 17243};
17244
d62a17ae 17245static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17246 .name = "bgp ipv4 labeled unicast",
62b346ee 17247 .node = BGP_IPV4L_NODE,
24389580 17248 .parent_node = BGP_NODE,
62b346ee 17249 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17250};
17251
d62a17ae 17252static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17253 .name = "bgp ipv6 unicast",
62b346ee 17254 .node = BGP_IPV6_NODE,
24389580 17255 .parent_node = BGP_NODE,
62b346ee 17256 .prompt = "%s(config-router-af)# ",
718e3744 17257};
17258
d62a17ae 17259static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17260 .name = "bgp ipv6 multicast",
62b346ee 17261 .node = BGP_IPV6M_NODE,
24389580 17262 .parent_node = BGP_NODE,
62b346ee 17263 .prompt = "%s(config-router-af)# ",
25ffbdc1 17264};
17265
d62a17ae 17266static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17267 .name = "bgp ipv6 labeled unicast",
62b346ee 17268 .node = BGP_IPV6L_NODE,
24389580 17269 .parent_node = BGP_NODE,
62b346ee 17270 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17271};
17272
62b346ee 17273static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17274 .name = "bgp vpnv4",
62b346ee 17275 .node = BGP_VPNV4_NODE,
24389580 17276 .parent_node = BGP_NODE,
62b346ee 17277 .prompt = "%s(config-router-af)# ",
62b346ee 17278};
6b0655a2 17279
62b346ee 17280static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17281 .name = "bgp vpnv6",
62b346ee 17282 .node = BGP_VPNV6_NODE,
24389580 17283 .parent_node = BGP_NODE,
62b346ee 17284 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17285};
8ecd3266 17286
62b346ee 17287static struct cmd_node bgp_evpn_node = {
f4b8291f 17288 .name = "bgp evpn",
62b346ee 17289 .node = BGP_EVPN_NODE,
24389580 17290 .parent_node = BGP_NODE,
62b346ee 17291 .prompt = "%s(config-router-evpn)# ",
62b346ee 17292};
4e0b7b6d 17293
62b346ee 17294static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17295 .name = "bgp evpn vni",
62b346ee 17296 .node = BGP_EVPN_VNI_NODE,
24389580 17297 .parent_node = BGP_EVPN_NODE,
62b346ee 17298 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17299};
90e60aa7 17300
62b346ee 17301static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17302 .name = "bgp ipv4 flowspec",
62b346ee 17303 .node = BGP_FLOWSPECV4_NODE,
24389580 17304 .parent_node = BGP_NODE,
62b346ee 17305 .prompt = "%s(config-router-af)# ",
62b346ee 17306};
7c40bf39 17307
62b346ee 17308static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17309 .name = "bgp ipv6 flowspec",
62b346ee 17310 .node = BGP_FLOWSPECV6_NODE,
24389580 17311 .parent_node = BGP_NODE,
62b346ee 17312 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 17313};
7c40bf39 17314
bfaab44d
HS
17315static struct cmd_node bgp_srv6_node = {
17316 .name = "bgp srv6",
17317 .node = BGP_SRV6_NODE,
17318 .parent_node = BGP_NODE,
17319 .prompt = "%s(config-router-srv6)# ",
17320};
17321
d62a17ae 17322static void community_list_vty(void);
1f8ae70b 17323
d62a17ae 17324static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 17325{
d62a17ae 17326 struct bgp *bgp;
17327 struct peer *peer;
d62a17ae 17328 struct listnode *lnbgp, *lnpeer;
b8a815e5 17329
d62a17ae 17330 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17331 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17332 /* only provide suggestions on the appropriate input
17333 * token type,
17334 * they'll otherwise show up multiple times */
17335 enum cmd_token_type match_type;
17336 char *name = peer->host;
d48ed3e0 17337
d62a17ae 17338 if (peer->conf_if) {
17339 match_type = VARIABLE_TKN;
17340 name = peer->conf_if;
17341 } else if (strchr(peer->host, ':'))
17342 match_type = IPV6_TKN;
17343 else
17344 match_type = IPV4_TKN;
d48ed3e0 17345
d62a17ae 17346 if (token->type != match_type)
17347 continue;
d48ed3e0 17348
d62a17ae 17349 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17350 }
d62a17ae 17351 }
b8a815e5
DL
17352}
17353
17354static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17355 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17356 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17357 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17358 {.completions = NULL}};
17359
47a306a0
DS
17360static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17361{
17362 struct bgp *bgp;
17363 struct peer_group *group;
17364 struct listnode *lnbgp, *lnpeer;
17365
17366 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17367 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17368 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17369 group->name));
17370 }
17371}
17372
17373static const struct cmd_variable_handler bgp_var_peergroup[] = {
17374 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17375 {.completions = NULL} };
17376
d62a17ae 17377void bgp_vty_init(void)
17378{
17379 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17380 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17381
17382 /* Install bgp top node. */
612c2c15
DL
17383 install_node(&bgp_node);
17384 install_node(&bgp_ipv4_unicast_node);
17385 install_node(&bgp_ipv4_multicast_node);
17386 install_node(&bgp_ipv4_labeled_unicast_node);
17387 install_node(&bgp_ipv6_unicast_node);
17388 install_node(&bgp_ipv6_multicast_node);
17389 install_node(&bgp_ipv6_labeled_unicast_node);
17390 install_node(&bgp_vpnv4_node);
17391 install_node(&bgp_vpnv6_node);
17392 install_node(&bgp_evpn_node);
17393 install_node(&bgp_evpn_vni_node);
17394 install_node(&bgp_flowspecv4_node);
17395 install_node(&bgp_flowspecv6_node);
bfaab44d 17396 install_node(&bgp_srv6_node);
d62a17ae 17397
17398 /* Install default VTY commands to new nodes. */
17399 install_default(BGP_NODE);
17400 install_default(BGP_IPV4_NODE);
17401 install_default(BGP_IPV4M_NODE);
17402 install_default(BGP_IPV4L_NODE);
17403 install_default(BGP_IPV6_NODE);
17404 install_default(BGP_IPV6M_NODE);
17405 install_default(BGP_IPV6L_NODE);
17406 install_default(BGP_VPNV4_NODE);
17407 install_default(BGP_VPNV6_NODE);
7c40bf39 17408 install_default(BGP_FLOWSPECV4_NODE);
17409 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17410 install_default(BGP_EVPN_NODE);
17411 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17412 install_default(BGP_SRV6_NODE);
d62a17ae 17413
8029b216
AK
17414 /* "bgp local-mac" hidden commands. */
17415 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17416 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17417
9acb67cb
DS
17418 /* "bgp suppress-fib-pending" global */
17419 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17420
d62a17ae 17421 /* bgp route-map delay-timer commands. */
17422 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17423 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17424
d70583f7
D
17425 /* global bgp update-delay command */
17426 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17427 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17428
05bd726c 17429 /* global bgp graceful-shutdown command */
17430 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17431 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17432
d62a17ae 17433 /* Dummy commands (Currently not supported) */
17434 install_element(BGP_NODE, &no_synchronization_cmd);
17435 install_element(BGP_NODE, &no_auto_summary_cmd);
17436
17437 /* "router bgp" commands. */
17438 install_element(CONFIG_NODE, &router_bgp_cmd);
17439
17440 /* "no router bgp" commands. */
17441 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17442
17443 /* "bgp router-id" commands. */
17444 install_element(BGP_NODE, &bgp_router_id_cmd);
17445 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17446
c208c586
S
17447 /* "bgp suppress-fib-pending" command */
17448 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17449
d62a17ae 17450 /* "bgp cluster-id" commands. */
17451 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17452 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17453
c163f297
DS
17454 /* "bgp no-rib" commands. */
17455 install_element(CONFIG_NODE, &bgp_norib_cmd);
17456 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17457
e46723a5
DS
17458 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17459
d62a17ae 17460 /* "bgp confederation" commands. */
17461 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17462 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17463
17464 /* "bgp confederation peers" commands. */
17465 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17466 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17467
17468 /* bgp max-med command */
17469 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17470 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17471 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17472 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17473 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17474
17475 /* bgp disable-ebgp-connected-nh-check */
17476 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17477 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17478
17479 /* bgp update-delay command */
17480 install_element(BGP_NODE, &bgp_update_delay_cmd);
17481 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17482
17483 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17484 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17485
17486 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17487 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17488
17489 /* "maximum-paths" commands. */
17490 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17491 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17492 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17493 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17494 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17495 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17496 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17497 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17498 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17499 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17500 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17501 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17502 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17503 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17504 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17505
39edabac
PG
17506 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17507 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17508 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17509 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17510 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17511 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17512 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17513 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17514 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17515 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17516
17517 /* "timers bgp" commands. */
17518 install_element(BGP_NODE, &bgp_timers_cmd);
17519 install_element(BGP_NODE, &no_bgp_timers_cmd);
17520
17521 /* route-map delay-timer commands - per instance for backwards compat.
17522 */
17523 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17524 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17525
17526 /* "bgp client-to-client reflection" commands */
17527 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17528 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17529
17530 /* "bgp always-compare-med" commands */
17531 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17532 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17533
9dac9fc8
DA
17534 /* bgp ebgp-requires-policy */
17535 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17536 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17537
2adac256
DA
17538 /* bgp suppress-duplicates */
17539 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17540 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17541
fb29348a
DA
17542 /* bgp reject-as-sets */
17543 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17544 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17545
d62a17ae 17546 /* "bgp deterministic-med" commands */
17547 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17548 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17549
055679e9 17550 /* "bgp graceful-restart" command */
36235319
QY
17551 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17552 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17553
17554 /* "bgp graceful-restart-disable" command */
36235319
QY
17555 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17556 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17557
17558 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17559 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17560 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17561
17562 /* "neighbor a:b:c:d graceful-restart-disable" command */
17563 install_element(BGP_NODE,
17564 &bgp_neighbor_graceful_restart_disable_set_cmd);
17565 install_element(BGP_NODE,
17566 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17567
17568 /* "neighbor a:b:c:d graceful-restart-helper" command */
17569 install_element(BGP_NODE,
17570 &bgp_neighbor_graceful_restart_helper_set_cmd);
17571 install_element(BGP_NODE,
17572 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17573
d62a17ae 17574 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17575 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17576 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17577 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17578 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17579 install_element(BGP_NODE,
17580 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17581 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17582 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17583
d6e3c15b 17584 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17585 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17586 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17587 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17588
7f323236
DW
17589 /* "bgp graceful-shutdown" commands */
17590 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17591 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17592
d62a17ae 17593 /* "bgp fast-external-failover" commands */
17594 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17595 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17596
d62a17ae 17597 /* "bgp bestpath compare-routerid" commands */
17598 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17599 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17600
17601 /* "bgp bestpath as-path ignore" commands */
17602 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17603 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17604
17605 /* "bgp bestpath as-path confed" commands */
17606 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17607 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17608
17609 /* "bgp bestpath as-path multipath-relax" commands */
17610 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17611 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17612
ee88563a
JM
17613 /* "bgp bestpath peer-type multipath-relax" commands */
17614 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
17615 install_element(BGP_NODE,
17616 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
17617
d62a17ae 17618 /* "bgp log-neighbor-changes" commands */
17619 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17620 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17621
17622 /* "bgp bestpath med" commands */
17623 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17624 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17625
f7e1c681 17626 /* "bgp bestpath bandwidth" commands */
17627 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 17628 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 17629
b16bcbba
TA
17630 /* "no bgp default <afi>-<safi>" commands. */
17631 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 17632
d62a17ae 17633 /* "bgp network import-check" commands. */
17634 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17635 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17636 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17637
17638 /* "bgp default local-preference" commands. */
17639 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17640 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17641
17642 /* bgp default show-hostname */
17643 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17644 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17645
aef999a2
DA
17646 /* bgp default show-nexthop-hostname */
17647 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17648 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17649
d62a17ae 17650 /* "bgp default subgroup-pkt-queue-max" commands. */
17651 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17652 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17653
17654 /* bgp ibgp-allow-policy-mods command */
17655 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17656 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17657
17658 /* "bgp listen limit" commands. */
17659 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17660 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17661
17662 /* "bgp listen range" commands. */
17663 install_element(BGP_NODE, &bgp_listen_range_cmd);
17664 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17665
8175f54a 17666 /* "bgp default shutdown" command */
f26845f9 17667 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
17668
17669 /* "bgp shutdown" commands */
17670 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 17671 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 17672 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 17673 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 17674
d62a17ae 17675 /* "neighbor remote-as" commands. */
17676 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17677 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17678 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17679 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17680 install_element(BGP_NODE,
17681 &neighbor_interface_v6only_config_remote_as_cmd);
17682 install_element(BGP_NODE, &no_neighbor_cmd);
17683 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17684
17685 /* "neighbor peer-group" commands. */
17686 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17687 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17688 install_element(BGP_NODE,
17689 &no_neighbor_interface_peer_group_remote_as_cmd);
17690
17691 /* "neighbor local-as" commands. */
17692 install_element(BGP_NODE, &neighbor_local_as_cmd);
17693 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17694 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17695 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17696
17697 /* "neighbor solo" commands. */
17698 install_element(BGP_NODE, &neighbor_solo_cmd);
17699 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17700
17701 /* "neighbor password" commands. */
17702 install_element(BGP_NODE, &neighbor_password_cmd);
17703 install_element(BGP_NODE, &no_neighbor_password_cmd);
17704
17705 /* "neighbor activate" commands. */
17706 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17707 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17708 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17709 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17710 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17711 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17712 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17713 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17714 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 17715 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17716 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 17717 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17718
17719 /* "no neighbor activate" commands. */
17720 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17721 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17722 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17723 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17724 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17725 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17726 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17727 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17728 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 17729 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17730 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 17731 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17732
17733 /* "neighbor peer-group" set commands. */
17734 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
17735 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17736 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
17737 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
17738 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
17739 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
17740 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
17741 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 17742 install_element(BGP_FLOWSPECV4_NODE,
17743 &neighbor_set_peer_group_hidden_cmd);
17744 install_element(BGP_FLOWSPECV6_NODE,
17745 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 17746
17747 /* "no neighbor peer-group unset" commands. */
17748 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
17749 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17750 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17751 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17752 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17753 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17754 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
17755 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 17756 install_element(BGP_FLOWSPECV4_NODE,
17757 &no_neighbor_set_peer_group_hidden_cmd);
17758 install_element(BGP_FLOWSPECV6_NODE,
17759 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 17760
17761 /* "neighbor softreconfiguration inbound" commands.*/
17762 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
17763 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
17764 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
17765 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17766 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
17767 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17768 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
17769 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17770 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
17771 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
17772 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
17773 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
17774 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
17775 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
17776 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
17777 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
17778 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
17779 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 17780 install_element(BGP_FLOWSPECV4_NODE,
17781 &neighbor_soft_reconfiguration_cmd);
17782 install_element(BGP_FLOWSPECV4_NODE,
17783 &no_neighbor_soft_reconfiguration_cmd);
17784 install_element(BGP_FLOWSPECV6_NODE,
17785 &neighbor_soft_reconfiguration_cmd);
17786 install_element(BGP_FLOWSPECV6_NODE,
17787 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
17788 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
17789 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 17790
17791 /* "neighbor attribute-unchanged" commands. */
17792 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
17793 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
17794 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
17795 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
17796 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
17797 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
17798 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
17799 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
17800 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
17801 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
17802 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
17803 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
17804 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
17805 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
17806 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
17807 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
17808 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
17809 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
17810
17811 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
17812 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
17813
b8ad84d2
PG
17814 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
17815 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
17816 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
17817 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
17818
d62a17ae 17819 /* "nexthop-local unchanged" commands */
17820 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
17821 install_element(BGP_IPV6_NODE,
17822 &no_neighbor_nexthop_local_unchanged_cmd);
17823
17824 /* "neighbor next-hop-self" commands. */
17825 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
17826 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
17827 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
17828 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
17829 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
17830 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
17831 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
17832 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
17833 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
17834 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
17835 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
17836 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
17837 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
17838 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
17839 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
17840 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
17841 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
17842 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
17843 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
17844 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 17845
17846 /* "neighbor next-hop-self force" commands. */
17847 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
17848 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
17849 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17850 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17851 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
17852 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17853 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17854 install_element(BGP_IPV4_NODE,
17855 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17856 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
17857 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17858 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17859 install_element(BGP_IPV4M_NODE,
17860 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17861 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
17862 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17863 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17864 install_element(BGP_IPV4L_NODE,
17865 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17866 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
17867 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17868 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17869 install_element(BGP_IPV6_NODE,
17870 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17871 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
17872 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17873 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17874 install_element(BGP_IPV6M_NODE,
17875 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17876 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
17877 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17878 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17879 install_element(BGP_IPV6L_NODE,
17880 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17881 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
17882 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17883 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17884 install_element(BGP_VPNV4_NODE,
17885 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 17886 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
17887 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
17888 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
17889 install_element(BGP_VPNV6_NODE,
17890 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
17891 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
17892 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 17893
17894 /* "neighbor as-override" commands. */
17895 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
17896 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
17897 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
17898 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
17899 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
17900 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
17901 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
17902 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
17903 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
17904 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
17905 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
17906 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
17907 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
17908 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
17909 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
17910 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
17911 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
17912 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
17913
17914 /* "neighbor remove-private-AS" commands. */
17915 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
17916 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
17917 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
17918 install_element(BGP_NODE,
17919 &no_neighbor_remove_private_as_all_hidden_cmd);
17920 install_element(BGP_NODE,
17921 &neighbor_remove_private_as_replace_as_hidden_cmd);
17922 install_element(BGP_NODE,
17923 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
17924 install_element(BGP_NODE,
17925 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
17926 install_element(
17927 BGP_NODE,
17928 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
17929 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
17930 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
17931 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
17932 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
17933 install_element(BGP_IPV4_NODE,
17934 &neighbor_remove_private_as_replace_as_cmd);
17935 install_element(BGP_IPV4_NODE,
17936 &no_neighbor_remove_private_as_replace_as_cmd);
17937 install_element(BGP_IPV4_NODE,
17938 &neighbor_remove_private_as_all_replace_as_cmd);
17939 install_element(BGP_IPV4_NODE,
17940 &no_neighbor_remove_private_as_all_replace_as_cmd);
17941 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
17942 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
17943 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
17944 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
17945 install_element(BGP_IPV4M_NODE,
17946 &neighbor_remove_private_as_replace_as_cmd);
17947 install_element(BGP_IPV4M_NODE,
17948 &no_neighbor_remove_private_as_replace_as_cmd);
17949 install_element(BGP_IPV4M_NODE,
17950 &neighbor_remove_private_as_all_replace_as_cmd);
17951 install_element(BGP_IPV4M_NODE,
17952 &no_neighbor_remove_private_as_all_replace_as_cmd);
17953 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
17954 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
17955 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
17956 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
17957 install_element(BGP_IPV4L_NODE,
17958 &neighbor_remove_private_as_replace_as_cmd);
17959 install_element(BGP_IPV4L_NODE,
17960 &no_neighbor_remove_private_as_replace_as_cmd);
17961 install_element(BGP_IPV4L_NODE,
17962 &neighbor_remove_private_as_all_replace_as_cmd);
17963 install_element(BGP_IPV4L_NODE,
17964 &no_neighbor_remove_private_as_all_replace_as_cmd);
17965 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
17966 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
17967 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
17968 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
17969 install_element(BGP_IPV6_NODE,
17970 &neighbor_remove_private_as_replace_as_cmd);
17971 install_element(BGP_IPV6_NODE,
17972 &no_neighbor_remove_private_as_replace_as_cmd);
17973 install_element(BGP_IPV6_NODE,
17974 &neighbor_remove_private_as_all_replace_as_cmd);
17975 install_element(BGP_IPV6_NODE,
17976 &no_neighbor_remove_private_as_all_replace_as_cmd);
17977 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
17978 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
17979 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
17980 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
17981 install_element(BGP_IPV6M_NODE,
17982 &neighbor_remove_private_as_replace_as_cmd);
17983 install_element(BGP_IPV6M_NODE,
17984 &no_neighbor_remove_private_as_replace_as_cmd);
17985 install_element(BGP_IPV6M_NODE,
17986 &neighbor_remove_private_as_all_replace_as_cmd);
17987 install_element(BGP_IPV6M_NODE,
17988 &no_neighbor_remove_private_as_all_replace_as_cmd);
17989 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
17990 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
17991 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
17992 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
17993 install_element(BGP_IPV6L_NODE,
17994 &neighbor_remove_private_as_replace_as_cmd);
17995 install_element(BGP_IPV6L_NODE,
17996 &no_neighbor_remove_private_as_replace_as_cmd);
17997 install_element(BGP_IPV6L_NODE,
17998 &neighbor_remove_private_as_all_replace_as_cmd);
17999 install_element(BGP_IPV6L_NODE,
18000 &no_neighbor_remove_private_as_all_replace_as_cmd);
18001 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18002 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18003 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18004 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18005 install_element(BGP_VPNV4_NODE,
18006 &neighbor_remove_private_as_replace_as_cmd);
18007 install_element(BGP_VPNV4_NODE,
18008 &no_neighbor_remove_private_as_replace_as_cmd);
18009 install_element(BGP_VPNV4_NODE,
18010 &neighbor_remove_private_as_all_replace_as_cmd);
18011 install_element(BGP_VPNV4_NODE,
18012 &no_neighbor_remove_private_as_all_replace_as_cmd);
18013 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18014 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18015 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18016 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18017 install_element(BGP_VPNV6_NODE,
18018 &neighbor_remove_private_as_replace_as_cmd);
18019 install_element(BGP_VPNV6_NODE,
18020 &no_neighbor_remove_private_as_replace_as_cmd);
18021 install_element(BGP_VPNV6_NODE,
18022 &neighbor_remove_private_as_all_replace_as_cmd);
18023 install_element(BGP_VPNV6_NODE,
18024 &no_neighbor_remove_private_as_all_replace_as_cmd);
18025
18026 /* "neighbor send-community" commands.*/
18027 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18028 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18029 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18030 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18031 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18032 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18033 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18034 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18035 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18036 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18037 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18038 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18039 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18040 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18041 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18042 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18043 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18044 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18045 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18046 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18047 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18048 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18049 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18050 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18051 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18052 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18053 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18054 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18055 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18056 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18057 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18058 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18059 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18060 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18061 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18062 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18063
18064 /* "neighbor route-reflector" commands.*/
18065 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18066 install_element(BGP_NODE,
18067 &no_neighbor_route_reflector_client_hidden_cmd);
18068 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18069 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18070 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18071 install_element(BGP_IPV4M_NODE,
18072 &no_neighbor_route_reflector_client_cmd);
18073 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18074 install_element(BGP_IPV4L_NODE,
18075 &no_neighbor_route_reflector_client_cmd);
18076 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18077 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18078 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18079 install_element(BGP_IPV6M_NODE,
18080 &no_neighbor_route_reflector_client_cmd);
18081 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18082 install_element(BGP_IPV6L_NODE,
18083 &no_neighbor_route_reflector_client_cmd);
18084 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18085 install_element(BGP_VPNV4_NODE,
18086 &no_neighbor_route_reflector_client_cmd);
18087 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18088 install_element(BGP_VPNV6_NODE,
18089 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18090 install_element(BGP_FLOWSPECV4_NODE,
18091 &neighbor_route_reflector_client_cmd);
18092 install_element(BGP_FLOWSPECV4_NODE,
18093 &no_neighbor_route_reflector_client_cmd);
18094 install_element(BGP_FLOWSPECV6_NODE,
18095 &neighbor_route_reflector_client_cmd);
18096 install_element(BGP_FLOWSPECV6_NODE,
18097 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18098 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18099 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18100
18101 /* "neighbor route-server" commands.*/
18102 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18103 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18104 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18105 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18106 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18107 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18108 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18109 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18110 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18111 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18112 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18113 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18114 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18115 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18116 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18117 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18118 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18119 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18120 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18121 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18122 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18123 install_element(BGP_FLOWSPECV4_NODE,
18124 &no_neighbor_route_server_client_cmd);
18125 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18126 install_element(BGP_FLOWSPECV6_NODE,
18127 &no_neighbor_route_server_client_cmd);
d62a17ae 18128
18129 /* "neighbor addpath-tx-all-paths" commands.*/
18130 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18131 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18132 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18133 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18134 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18135 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18136 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18137 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18138 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18139 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18140 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18141 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18142 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18143 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18144 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18145 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18146 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18147 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18148
18149 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18150 install_element(BGP_NODE,
18151 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18152 install_element(BGP_NODE,
18153 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18154 install_element(BGP_IPV4_NODE,
18155 &neighbor_addpath_tx_bestpath_per_as_cmd);
18156 install_element(BGP_IPV4_NODE,
18157 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18158 install_element(BGP_IPV4M_NODE,
18159 &neighbor_addpath_tx_bestpath_per_as_cmd);
18160 install_element(BGP_IPV4M_NODE,
18161 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18162 install_element(BGP_IPV4L_NODE,
18163 &neighbor_addpath_tx_bestpath_per_as_cmd);
18164 install_element(BGP_IPV4L_NODE,
18165 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18166 install_element(BGP_IPV6_NODE,
18167 &neighbor_addpath_tx_bestpath_per_as_cmd);
18168 install_element(BGP_IPV6_NODE,
18169 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18170 install_element(BGP_IPV6M_NODE,
18171 &neighbor_addpath_tx_bestpath_per_as_cmd);
18172 install_element(BGP_IPV6M_NODE,
18173 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18174 install_element(BGP_IPV6L_NODE,
18175 &neighbor_addpath_tx_bestpath_per_as_cmd);
18176 install_element(BGP_IPV6L_NODE,
18177 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18178 install_element(BGP_VPNV4_NODE,
18179 &neighbor_addpath_tx_bestpath_per_as_cmd);
18180 install_element(BGP_VPNV4_NODE,
18181 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18182 install_element(BGP_VPNV6_NODE,
18183 &neighbor_addpath_tx_bestpath_per_as_cmd);
18184 install_element(BGP_VPNV6_NODE,
18185 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18186
2b31007c
RZ
18187 /* "neighbor sender-as-path-loop-detection" commands. */
18188 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18189 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18190
d62a17ae 18191 /* "neighbor passive" commands. */
18192 install_element(BGP_NODE, &neighbor_passive_cmd);
18193 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18194
18195
18196 /* "neighbor shutdown" commands. */
18197 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18198 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18199 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18200 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18201 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18202 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18203
18204 /* "neighbor capability extended-nexthop" commands.*/
18205 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18206 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18207
18208 /* "neighbor capability orf prefix-list" commands.*/
18209 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18210 install_element(BGP_NODE,
18211 &no_neighbor_capability_orf_prefix_hidden_cmd);
18212 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18213 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18214 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18215 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18216 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18217 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18218 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18219 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18220 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18221 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18222 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18223 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18224
18225 /* "neighbor capability dynamic" commands.*/
18226 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18227 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18228
18229 /* "neighbor dont-capability-negotiate" commands. */
18230 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18231 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18232
18233 /* "neighbor ebgp-multihop" commands. */
18234 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18235 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18236 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18237
18238 /* "neighbor disable-connected-check" commands. */
18239 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18240 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18241
47cbc09b
PM
18242 /* "neighbor enforce-first-as" commands. */
18243 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18244 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18245
d62a17ae 18246 /* "neighbor description" commands. */
18247 install_element(BGP_NODE, &neighbor_description_cmd);
18248 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18249 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18250
18251 /* "neighbor update-source" commands. "*/
18252 install_element(BGP_NODE, &neighbor_update_source_cmd);
18253 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18254
18255 /* "neighbor default-originate" commands. */
18256 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18257 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18258 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18259 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18260 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18261 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18262 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18263 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18264 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18265 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18266 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18267 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18268 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18269 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18270 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18271 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18272 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18273 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18274 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18275 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18276 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18277
18278 /* "neighbor port" commands. */
18279 install_element(BGP_NODE, &neighbor_port_cmd);
18280 install_element(BGP_NODE, &no_neighbor_port_cmd);
18281
18282 /* "neighbor weight" commands. */
18283 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18284 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18285
18286 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18287 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18288 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18289 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18290 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18291 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18292 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18293 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18294 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18295 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18296 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18297 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18298 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18299 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18300 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18301 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18302
18303 /* "neighbor override-capability" commands. */
18304 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18305 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18306
18307 /* "neighbor strict-capability-match" commands. */
18308 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18309 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18310
18311 /* "neighbor timers" commands. */
18312 install_element(BGP_NODE, &neighbor_timers_cmd);
18313 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18314
18315 /* "neighbor timers connect" commands. */
18316 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18317 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18318
d43114f3
DS
18319 /* "neighbor timers delayopen" commands. */
18320 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18321 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18322
d62a17ae 18323 /* "neighbor advertisement-interval" commands. */
18324 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18325 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18326
18327 /* "neighbor interface" commands. */
18328 install_element(BGP_NODE, &neighbor_interface_cmd);
18329 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18330
18331 /* "neighbor distribute" commands. */
18332 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18333 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18334 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18335 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18336 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18337 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18338 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18339 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18340 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18341 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18342 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18343 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18344 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18345 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18346 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18347 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18348 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18349 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18350
18351 /* "neighbor prefix-list" commands. */
18352 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18353 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18354 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18355 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18356 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18357 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18358 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18359 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18360 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18361 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18362 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18363 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18364 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18365 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18366 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18367 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18368 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18369 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18370 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18371 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18372 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18373 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18374
18375 /* "neighbor filter-list" commands. */
18376 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18377 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18378 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18379 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18380 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18381 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18382 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18383 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18384 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18385 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18386 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18387 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18388 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18389 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18390 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18391 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18392 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18393 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18394 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18395 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18396 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18397 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18398
18399 /* "neighbor route-map" commands. */
d6d7ed37
IR
18400 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18401 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18402 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18403 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18404 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18405 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18406 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18407 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18408 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18409 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18410 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18411 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18412 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18413 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18414 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18415 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18416 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18417 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18418 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18419 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18420 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18421 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18422 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18423 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18424
18425 /* "neighbor unsuppress-map" commands. */
18426 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18427 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18428 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18429 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18430 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18431 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18432 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18433 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18434 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18435 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18436 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18437 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18438 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18439 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18440 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18441 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18442 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18443 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18444
7f7940e6 18445 /* "neighbor advertise-map" commands. */
389e4f92 18446 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18447 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18448 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18449 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18450 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18451 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18452 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18453 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18454 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18455 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18456
fde246e8
DA
18457 /* neighbor maximum-prefix-out commands. */
18458 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18459 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18460 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18461 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18462 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18463 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18464 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18465 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18466 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18467 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18468 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18469 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18470 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18471 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18472 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18473 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18474 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18475 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18476
d62a17ae 18477 /* "neighbor maximum-prefix" commands. */
18478 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18479 install_element(BGP_NODE,
18480 &neighbor_maximum_prefix_threshold_hidden_cmd);
18481 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18482 install_element(BGP_NODE,
18483 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18484 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18485 install_element(BGP_NODE,
18486 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18487 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18488 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18489 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18490 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18491 install_element(BGP_IPV4_NODE,
18492 &neighbor_maximum_prefix_threshold_warning_cmd);
18493 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18494 install_element(BGP_IPV4_NODE,
18495 &neighbor_maximum_prefix_threshold_restart_cmd);
18496 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18497 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18498 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18499 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18500 install_element(BGP_IPV4M_NODE,
18501 &neighbor_maximum_prefix_threshold_warning_cmd);
18502 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18503 install_element(BGP_IPV4M_NODE,
18504 &neighbor_maximum_prefix_threshold_restart_cmd);
18505 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18506 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18507 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18508 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18509 install_element(BGP_IPV4L_NODE,
18510 &neighbor_maximum_prefix_threshold_warning_cmd);
18511 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18512 install_element(BGP_IPV4L_NODE,
18513 &neighbor_maximum_prefix_threshold_restart_cmd);
18514 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18515 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18516 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18517 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18518 install_element(BGP_IPV6_NODE,
18519 &neighbor_maximum_prefix_threshold_warning_cmd);
18520 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18521 install_element(BGP_IPV6_NODE,
18522 &neighbor_maximum_prefix_threshold_restart_cmd);
18523 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18524 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18525 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18526 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18527 install_element(BGP_IPV6M_NODE,
18528 &neighbor_maximum_prefix_threshold_warning_cmd);
18529 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18530 install_element(BGP_IPV6M_NODE,
18531 &neighbor_maximum_prefix_threshold_restart_cmd);
18532 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18533 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18534 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18535 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18536 install_element(BGP_IPV6L_NODE,
18537 &neighbor_maximum_prefix_threshold_warning_cmd);
18538 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18539 install_element(BGP_IPV6L_NODE,
18540 &neighbor_maximum_prefix_threshold_restart_cmd);
18541 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18542 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18543 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18544 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18545 install_element(BGP_VPNV4_NODE,
18546 &neighbor_maximum_prefix_threshold_warning_cmd);
18547 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18548 install_element(BGP_VPNV4_NODE,
18549 &neighbor_maximum_prefix_threshold_restart_cmd);
18550 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18551 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18552 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18553 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18554 install_element(BGP_VPNV6_NODE,
18555 &neighbor_maximum_prefix_threshold_warning_cmd);
18556 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18557 install_element(BGP_VPNV6_NODE,
18558 &neighbor_maximum_prefix_threshold_restart_cmd);
18559 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18560
18561 /* "neighbor allowas-in" */
18562 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18563 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18564 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18565 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18566 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18567 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18568 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18569 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18570 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18571 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18572 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18573 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18574 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18575 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18576 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18577 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18578 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18579 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18580 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18581 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18582
18583 /* address-family commands. */
18584 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18585 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 18586#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 18587 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18588 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 18589#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 18590
d62a17ae 18591 install_element(BGP_NODE, &address_family_evpn_cmd);
18592
18593 /* "exit-address-family" command. */
18594 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18595 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18596 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18597 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18598 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18599 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18600 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18601 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 18602 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18603 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 18604 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18605
18606 /* "clear ip bgp commands" */
18607 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18608
18609 /* clear ip bgp prefix */
18610 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18611 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18612 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18613
18614 /* "show [ip] bgp summary" commands. */
18615 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 18616 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 18617 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 18618 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 18619 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18620 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 18621 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18622
18623 /* "show [ip] bgp neighbors" commands. */
18624 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18625
36235319 18626 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 18627
d62a17ae 18628 /* "show [ip] bgp peer-group" commands. */
18629 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18630
18631 /* "show [ip] bgp paths" commands. */
18632 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18633
18634 /* "show [ip] bgp community" commands. */
18635 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18636
18637 /* "show ip bgp large-community" commands. */
18638 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18639 /* "show [ip] bgp attribute-info" commands. */
18640 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 18641 /* "show [ip] bgp route-leak" command */
18642 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 18643
18644 /* "redistribute" commands. */
18645 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18646 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18647 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18648 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18649 install_element(BGP_NODE,
18650 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18651 install_element(BGP_NODE,
18652 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18653 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18654 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18655 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18656 install_element(BGP_NODE,
18657 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18658 install_element(BGP_NODE,
18659 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18660 install_element(BGP_NODE,
18661 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18662 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18663 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18664 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18665 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18666 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18667 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18668 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18669 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18670 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18671 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18672 install_element(BGP_IPV4_NODE,
18673 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18674 install_element(BGP_IPV4_NODE,
18675 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18676 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18677 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18678 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18679 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18680 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18681 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18682
b9c7bc5a
PZ
18683 /* import|export vpn [route-map WORD] */
18684 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18685 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 18686
12a844a5
DS
18687 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18688 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18689
d62a17ae 18690 /* ttl_security commands */
18691 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18692 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18693
18694 /* "show [ip] bgp memory" commands. */
18695 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18696
acf71666
MK
18697 /* "show bgp martian next-hop" */
18698 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18699
48ecf8f5
DS
18700 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18701
d62a17ae 18702 /* "show [ip] bgp views" commands. */
18703 install_element(VIEW_NODE, &show_bgp_views_cmd);
18704
18705 /* "show [ip] bgp vrfs" commands. */
18706 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18707
18708 /* Community-list. */
18709 community_list_vty();
ddb5b488 18710
ed0e57e3
DA
18711 community_alias_vty();
18712
ddb5b488 18713 /* vpn-policy commands */
b9c7bc5a
PZ
18714 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18715 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18716 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18717 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18718 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18719 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18720 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18721 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18722 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18723 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
18724 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18725 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 18726
301ad80a
PG
18727 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18728 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18729
b9c7bc5a
PZ
18730 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18731 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18732 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18733 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
18734 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18735 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18736 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18737 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
18738 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18739 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
18740
18741 /* tcp-mss command */
18742 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
18743 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
18744
18745 /* srv6 commands */
ea372e81 18746 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 18747 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
a0281b2e 18748 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
b72c9e14
HS
18749 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
18750 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 18751}
6b0655a2 18752
718e3744 18753#include "memory.h"
18754#include "bgp_regex.h"
18755#include "bgp_clist.h"
18756#include "bgp_ecommunity.h"
18757
18758/* VTY functions. */
18759
18760/* Direction value to string conversion. */
d62a17ae 18761static const char *community_direct_str(int direct)
18762{
18763 switch (direct) {
18764 case COMMUNITY_DENY:
18765 return "deny";
18766 case COMMUNITY_PERMIT:
18767 return "permit";
18768 default:
18769 return "unknown";
18770 }
718e3744 18771}
18772
18773/* Display error string. */
d62a17ae 18774static void community_list_perror(struct vty *vty, int ret)
18775{
18776 switch (ret) {
18777 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
18778 vty_out(vty, "%% Can't find community-list\n");
18779 break;
18780 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
18781 vty_out(vty, "%% Malformed community-list value\n");
18782 break;
18783 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
18784 vty_out(vty,
18785 "%% Community name conflict, previously defined as standard community\n");
18786 break;
18787 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
18788 vty_out(vty,
18789 "%% Community name conflict, previously defined as expanded community\n");
18790 break;
18791 }
718e3744 18792}
18793
5bf15956
DW
18794/* "community-list" keyword help string. */
18795#define COMMUNITY_LIST_STR "Add a community list entry\n"
18796
7336e101
SP
18797/*community-list standard */
18798DEFUN (community_list_standard,
18799 bgp_community_list_standard_cmd,
a08032fe 18800 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 18801 BGP_STR
718e3744 18802 COMMUNITY_LIST_STR
18803 "Community list number (standard)\n"
5bf15956 18804 "Add an standard community-list entry\n"
718e3744 18805 "Community list name\n"
2f8cc0e5
DA
18806 "Sequence number of an entry\n"
18807 "Sequence number\n"
718e3744 18808 "Specify community to reject\n"
18809 "Specify community to accept\n"
18810 COMMUNITY_VAL_STR)
18811{
d62a17ae 18812 char *cl_name_or_number = NULL;
2f8cc0e5 18813 char *seq = NULL;
d62a17ae 18814 int direct = 0;
18815 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 18816 int idx = 0;
7336e101 18817
a08032fe 18818 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
18819 if (idx)
18820 seq = argv[idx]->arg;
18821
18822 idx = 0;
d62a17ae 18823 argv_find(argv, argc, "(1-99)", &idx);
18824 argv_find(argv, argc, "WORD", &idx);
18825 cl_name_or_number = argv[idx]->arg;
18826 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18827 : COMMUNITY_DENY;
18828 argv_find(argv, argc, "AA:NN", &idx);
18829 char *str = argv_concat(argv, argc, idx);
42f914d4 18830
2f8cc0e5
DA
18831 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18832 direct, style);
42f914d4 18833
d62a17ae 18834 XFREE(MTYPE_TMP, str);
42f914d4 18835
d62a17ae 18836 if (ret < 0) {
18837 /* Display error string. */
18838 community_list_perror(vty, ret);
18839 return CMD_WARNING_CONFIG_FAILED;
18840 }
42f914d4 18841
d62a17ae 18842 return CMD_SUCCESS;
718e3744 18843}
18844
7336e101
SP
18845DEFUN (no_community_list_standard_all,
18846 no_bgp_community_list_standard_all_cmd,
a08032fe 18847 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18848 NO_STR
18849 BGP_STR
18850 COMMUNITY_LIST_STR
18851 "Community list number (standard)\n"
18852 "Add an standard community-list entry\n"
18853 "Community list name\n"
2f8cc0e5
DA
18854 "Sequence number of an entry\n"
18855 "Sequence number\n"
7336e101
SP
18856 "Specify community to reject\n"
18857 "Specify community to accept\n"
18858 COMMUNITY_VAL_STR)
718e3744 18859{
d62a17ae 18860 char *cl_name_or_number = NULL;
174b5cb9 18861 char *str = NULL;
d62a17ae 18862 int direct = 0;
18863 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 18864 char *seq = NULL;
d62a17ae 18865 int idx = 0;
7336e101 18866
a08032fe 18867 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
18868 if (idx)
18869 seq = argv[idx]->arg;
18870
18871 idx = 0;
174b5cb9
DA
18872 argv_find(argv, argc, "permit", &idx);
18873 argv_find(argv, argc, "deny", &idx);
18874
18875 if (idx) {
18876 direct = argv_find(argv, argc, "permit", &idx)
18877 ? COMMUNITY_PERMIT
18878 : COMMUNITY_DENY;
18879
18880 idx = 0;
18881 argv_find(argv, argc, "AA:NN", &idx);
18882 str = argv_concat(argv, argc, idx);
18883 }
18884
18885 idx = 0;
d62a17ae 18886 argv_find(argv, argc, "(1-99)", &idx);
18887 argv_find(argv, argc, "WORD", &idx);
18888 cl_name_or_number = argv[idx]->arg;
42f914d4 18889
2f8cc0e5 18890 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 18891 direct, style);
42f914d4 18892
d62a17ae 18893 XFREE(MTYPE_TMP, str);
daf9ddbb 18894
d62a17ae 18895 if (ret < 0) {
18896 community_list_perror(vty, ret);
18897 return CMD_WARNING_CONFIG_FAILED;
18898 }
42f914d4 18899
d62a17ae 18900 return CMD_SUCCESS;
718e3744 18901}
7336e101 18902
174b5cb9
DA
18903ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
18904 "no bgp community-list <(1-99)|standard WORD>",
18905 NO_STR BGP_STR COMMUNITY_LIST_STR
18906 "Community list number (standard)\n"
18907 "Add an standard community-list entry\n"
18908 "Community list name\n")
18909
7336e101
SP
18910/*community-list expanded */
18911DEFUN (community_list_expanded_all,
18912 bgp_community_list_expanded_all_cmd,
a08032fe 18913 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18914 BGP_STR
18915 COMMUNITY_LIST_STR
718e3744 18916 "Community list number (expanded)\n"
5bf15956 18917 "Add an expanded community-list entry\n"
718e3744 18918 "Community list name\n"
2f8cc0e5
DA
18919 "Sequence number of an entry\n"
18920 "Sequence number\n"
718e3744 18921 "Specify community to reject\n"
18922 "Specify community to accept\n"
18923 COMMUNITY_VAL_STR)
18924{
d62a17ae 18925 char *cl_name_or_number = NULL;
2f8cc0e5 18926 char *seq = NULL;
d62a17ae 18927 int direct = 0;
18928 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18929 int idx = 0;
7b9a4750 18930
a08032fe 18931 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
18932 if (idx)
18933 seq = argv[idx]->arg;
18934
18935 idx = 0;
18936
d62a17ae 18937 argv_find(argv, argc, "(100-500)", &idx);
18938 argv_find(argv, argc, "WORD", &idx);
18939 cl_name_or_number = argv[idx]->arg;
18940 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18941 : COMMUNITY_DENY;
18942 argv_find(argv, argc, "AA:NN", &idx);
18943 char *str = argv_concat(argv, argc, idx);
42f914d4 18944
2f8cc0e5
DA
18945 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
18946 direct, style);
42f914d4 18947
d62a17ae 18948 XFREE(MTYPE_TMP, str);
42f914d4 18949
d62a17ae 18950 if (ret < 0) {
18951 /* Display error string. */
18952 community_list_perror(vty, ret);
18953 return CMD_WARNING_CONFIG_FAILED;
18954 }
42f914d4 18955
d62a17ae 18956 return CMD_SUCCESS;
718e3744 18957}
18958
7336e101
SP
18959DEFUN (no_community_list_expanded_all,
18960 no_bgp_community_list_expanded_all_cmd,
a08032fe 18961 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18962 NO_STR
18963 BGP_STR
18964 COMMUNITY_LIST_STR
18965 "Community list number (expanded)\n"
18966 "Add an expanded community-list entry\n"
18967 "Community list name\n"
2f8cc0e5
DA
18968 "Sequence number of an entry\n"
18969 "Sequence number\n"
7336e101
SP
18970 "Specify community to reject\n"
18971 "Specify community to accept\n"
18972 COMMUNITY_VAL_STR)
718e3744 18973{
d62a17ae 18974 char *cl_name_or_number = NULL;
2f8cc0e5 18975 char *seq = NULL;
174b5cb9 18976 char *str = NULL;
d62a17ae 18977 int direct = 0;
18978 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 18979 int idx = 0;
174b5cb9 18980
a08032fe 18981 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
18982 if (idx)
18983 seq = argv[idx]->arg;
18984
18985 idx = 0;
174b5cb9
DA
18986 argv_find(argv, argc, "permit", &idx);
18987 argv_find(argv, argc, "deny", &idx);
18988
18989 if (idx) {
18990 direct = argv_find(argv, argc, "permit", &idx)
18991 ? COMMUNITY_PERMIT
18992 : COMMUNITY_DENY;
18993
18994 idx = 0;
18995 argv_find(argv, argc, "AA:NN", &idx);
18996 str = argv_concat(argv, argc, idx);
7336e101 18997 }
174b5cb9
DA
18998
18999 idx = 0;
d62a17ae 19000 argv_find(argv, argc, "(100-500)", &idx);
19001 argv_find(argv, argc, "WORD", &idx);
19002 cl_name_or_number = argv[idx]->arg;
42f914d4 19003
2f8cc0e5 19004 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19005 direct, style);
42f914d4 19006
d62a17ae 19007 XFREE(MTYPE_TMP, str);
daf9ddbb 19008
d62a17ae 19009 if (ret < 0) {
19010 community_list_perror(vty, ret);
19011 return CMD_WARNING_CONFIG_FAILED;
19012 }
42f914d4 19013
d62a17ae 19014 return CMD_SUCCESS;
718e3744 19015}
19016
36d4bb44
EB
19017ALIAS(no_community_list_expanded_all,
19018 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19019 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19020 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19021 "Community list number (expanded)\n"
19022 "Add an expanded community-list entry\n"
19023 "Community list name\n")
19024
8d9b8ed9
PM
19025/* Return configuration string of community-list entry. */
19026static const char *community_list_config_str(struct community_entry *entry)
19027{
19028 const char *str;
19029
19030 if (entry->any)
19031 str = "";
19032 else {
19033 if (entry->style == COMMUNITY_LIST_STANDARD)
19034 str = community_str(entry->u.com, false);
19035 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19036 str = lcommunity_str(entry->u.lcom, false);
19037 else
19038 str = entry->config;
19039 }
19040 return str;
19041}
19042
d62a17ae 19043static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19044{
d62a17ae 19045 struct community_entry *entry;
718e3744 19046
d62a17ae 19047 for (entry = list->head; entry; entry = entry->next) {
19048 if (entry == list->head) {
19049 if (all_digit(list->name))
19050 vty_out(vty, "Community %s list %s\n",
19051 entry->style == COMMUNITY_LIST_STANDARD
19052 ? "standard"
19053 : "(expanded) access",
19054 list->name);
19055 else
19056 vty_out(vty, "Named Community %s list %s\n",
19057 entry->style == COMMUNITY_LIST_STANDARD
19058 ? "standard"
19059 : "expanded",
19060 list->name);
19061 }
19062 if (entry->any)
19063 vty_out(vty, " %s\n",
19064 community_direct_str(entry->direct));
19065 else
19066 vty_out(vty, " %s %s\n",
19067 community_direct_str(entry->direct),
8d9b8ed9 19068 community_list_config_str(entry));
d62a17ae 19069 }
718e3744 19070}
19071
7336e101
SP
19072DEFUN (show_community_list,
19073 show_bgp_community_list_cmd,
19074 "show bgp community-list",
718e3744 19075 SHOW_STR
7336e101 19076 BGP_STR
718e3744 19077 "List community-list\n")
19078{
d62a17ae 19079 struct community_list *list;
19080 struct community_list_master *cm;
718e3744 19081
d62a17ae 19082 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19083 if (!cm)
19084 return CMD_SUCCESS;
718e3744 19085
d62a17ae 19086 for (list = cm->num.head; list; list = list->next)
19087 community_list_show(vty, list);
718e3744 19088
d62a17ae 19089 for (list = cm->str.head; list; list = list->next)
19090 community_list_show(vty, list);
718e3744 19091
d62a17ae 19092 return CMD_SUCCESS;
718e3744 19093}
19094
7336e101
SP
19095DEFUN (show_community_list_arg,
19096 show_bgp_community_list_arg_cmd,
960b69b9 19097 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19098 SHOW_STR
19099 BGP_STR
718e3744 19100 "List community-list\n"
19101 "Community-list number\n"
960b69b9 19102 "Community-list name\n"
19103 "Detailed information on community-list\n")
718e3744 19104{
d62a17ae 19105 int idx_comm_list = 3;
19106 struct community_list *list;
718e3744 19107
e237b0d2 19108 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19109 COMMUNITY_LIST_MASTER);
19110 if (!list) {
19111 vty_out(vty, "%% Can't find community-list\n");
19112 return CMD_WARNING;
19113 }
718e3744 19114
d62a17ae 19115 community_list_show(vty, list);
718e3744 19116
d62a17ae 19117 return CMD_SUCCESS;
718e3744 19118}
6b0655a2 19119
57d187bc
JS
19120/*
19121 * Large Community code.
19122 */
d62a17ae 19123static int lcommunity_list_set_vty(struct vty *vty, int argc,
19124 struct cmd_token **argv, int style,
19125 int reject_all_digit_name)
19126{
19127 int ret;
19128 int direct;
19129 char *str;
19130 int idx = 0;
19131 char *cl_name;
2f8cc0e5
DA
19132 char *seq = NULL;
19133
a08032fe 19134 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19135 seq = argv[idx]->arg;
d62a17ae 19136
2f8cc0e5 19137 idx = 0;
d62a17ae 19138 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19139 : COMMUNITY_DENY;
19140
19141 /* All digit name check. */
19142 idx = 0;
19143 argv_find(argv, argc, "WORD", &idx);
19144 argv_find(argv, argc, "(1-99)", &idx);
19145 argv_find(argv, argc, "(100-500)", &idx);
19146 cl_name = argv[idx]->arg;
19147 if (reject_all_digit_name && all_digit(cl_name)) {
19148 vty_out(vty, "%% Community name cannot have all digits\n");
19149 return CMD_WARNING_CONFIG_FAILED;
19150 }
19151
19152 idx = 0;
19153 argv_find(argv, argc, "AA:BB:CC", &idx);
19154 argv_find(argv, argc, "LINE", &idx);
19155 /* Concat community string argument. */
19156 if (idx)
19157 str = argv_concat(argv, argc, idx);
19158 else
19159 str = NULL;
19160
2f8cc0e5 19161 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19162
19163 /* Free temporary community list string allocated by
19164 argv_concat(). */
0a22ddfb 19165 XFREE(MTYPE_TMP, str);
d62a17ae 19166
19167 if (ret < 0) {
19168 community_list_perror(vty, ret);
19169 return CMD_WARNING_CONFIG_FAILED;
19170 }
19171 return CMD_SUCCESS;
19172}
19173
19174static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19175 struct cmd_token **argv, int style)
19176{
19177 int ret;
19178 int direct = 0;
19179 char *str = NULL;
19180 int idx = 0;
2f8cc0e5 19181 char *seq = NULL;
d62a17ae 19182
a08032fe 19183 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19184 seq = argv[idx]->arg;
d62a17ae 19185
2f8cc0e5 19186 idx = 0;
d62a17ae 19187 argv_find(argv, argc, "permit", &idx);
19188 argv_find(argv, argc, "deny", &idx);
19189
19190 if (idx) {
19191 /* Check the list direct. */
19192 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19193 direct = COMMUNITY_PERMIT;
19194 else
19195 direct = COMMUNITY_DENY;
19196
19197 idx = 0;
19198 argv_find(argv, argc, "LINE", &idx);
19199 argv_find(argv, argc, "AA:AA:NN", &idx);
19200 /* Concat community string argument. */
19201 str = argv_concat(argv, argc, idx);
19202 }
19203
19204 idx = 0;
19205 argv_find(argv, argc, "(1-99)", &idx);
19206 argv_find(argv, argc, "(100-500)", &idx);
19207 argv_find(argv, argc, "WORD", &idx);
19208
19209 /* Unset community list. */
2f8cc0e5 19210 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19211 style);
19212
19213 /* Free temporary community list string allocated by
19214 argv_concat(). */
0a22ddfb 19215 XFREE(MTYPE_TMP, str);
d62a17ae 19216
19217 if (ret < 0) {
19218 community_list_perror(vty, ret);
19219 return CMD_WARNING_CONFIG_FAILED;
19220 }
19221
19222 return CMD_SUCCESS;
57d187bc
JS
19223}
19224
19225/* "large-community-list" keyword help string. */
19226#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19227#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19228
7336e101
SP
19229DEFUN (lcommunity_list_standard,
19230 bgp_lcommunity_list_standard_cmd,
a08032fe 19231 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19232 BGP_STR
19233 LCOMMUNITY_LIST_STR
19234 "Large Community list number (standard)\n"
2f8cc0e5
DA
19235 "Sequence number of an entry\n"
19236 "Sequence number\n"
7336e101
SP
19237 "Specify large community to reject\n"
19238 "Specify large community to accept\n"
19239 LCOMMUNITY_VAL_STR)
52951b63 19240{
d62a17ae 19241 return lcommunity_list_set_vty(vty, argc, argv,
19242 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19243}
19244
7336e101
SP
19245DEFUN (lcommunity_list_expanded,
19246 bgp_lcommunity_list_expanded_cmd,
a08032fe 19247 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19248 BGP_STR
19249 LCOMMUNITY_LIST_STR
19250 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19251 "Sequence number of an entry\n"
19252 "Sequence number\n"
7336e101
SP
19253 "Specify large community to reject\n"
19254 "Specify large community to accept\n"
19255 "An ordered list as a regular-expression\n")
57d187bc 19256{
d62a17ae 19257 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19258 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19259}
19260
7336e101
SP
19261DEFUN (lcommunity_list_name_standard,
19262 bgp_lcommunity_list_name_standard_cmd,
a08032fe 19263 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19264 BGP_STR
19265 LCOMMUNITY_LIST_STR
19266 "Specify standard large-community-list\n"
19267 "Large Community list name\n"
2f8cc0e5
DA
19268 "Sequence number of an entry\n"
19269 "Sequence number\n"
7336e101
SP
19270 "Specify large community to reject\n"
19271 "Specify large community to accept\n"
19272 LCOMMUNITY_VAL_STR)
52951b63 19273{
d62a17ae 19274 return lcommunity_list_set_vty(vty, argc, argv,
19275 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19276}
19277
7336e101
SP
19278DEFUN (lcommunity_list_name_expanded,
19279 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19280 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19281 BGP_STR
19282 LCOMMUNITY_LIST_STR
19283 "Specify expanded large-community-list\n"
19284 "Large Community list name\n"
2f8cc0e5
DA
19285 "Sequence number of an entry\n"
19286 "Sequence number\n"
7336e101
SP
19287 "Specify large community to reject\n"
19288 "Specify large community to accept\n"
19289 "An ordered list as a regular-expression\n")
57d187bc 19290{
d62a17ae 19291 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19292 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19293}
19294
4378f57c
DA
19295DEFUN (no_lcommunity_list_all,
19296 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
19297 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19298 NO_STR
19299 BGP_STR
19300 LCOMMUNITY_LIST_STR
19301 "Large Community list number (standard)\n"
19302 "Large Community list number (expanded)\n"
19303 "Large Community list name\n")
57d187bc 19304{
7336e101
SP
19305 return lcommunity_list_unset_vty(vty, argc, argv,
19306 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19307}
19308
4378f57c
DA
19309DEFUN (no_lcommunity_list_name_standard_all,
19310 no_bgp_lcommunity_list_name_standard_all_cmd,
19311 "no bgp large-community-list standard WORD",
19312 NO_STR
19313 BGP_STR
19314 LCOMMUNITY_LIST_STR
19315 "Specify standard large-community-list\n"
19316 "Large Community list name\n")
19317{
19318 return lcommunity_list_unset_vty(vty, argc, argv,
19319 LARGE_COMMUNITY_LIST_STANDARD);
19320}
19321
7336e101
SP
19322DEFUN (no_lcommunity_list_name_expanded_all,
19323 no_bgp_lcommunity_list_name_expanded_all_cmd,
19324 "no bgp large-community-list expanded WORD",
19325 NO_STR
19326 BGP_STR
19327 LCOMMUNITY_LIST_STR
19328 "Specify expanded large-community-list\n"
19329 "Large Community list name\n")
57d187bc 19330{
d62a17ae 19331 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19332 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19333}
19334
7336e101
SP
19335DEFUN (no_lcommunity_list_standard,
19336 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19337 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19338 NO_STR
19339 BGP_STR
19340 LCOMMUNITY_LIST_STR
19341 "Large Community list number (standard)\n"
2f8cc0e5
DA
19342 "Sequence number of an entry\n"
19343 "Sequence number\n"
7336e101
SP
19344 "Specify large community to reject\n"
19345 "Specify large community to accept\n"
19346 LCOMMUNITY_VAL_STR)
57d187bc 19347{
d62a17ae 19348 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19349 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19350}
19351
7336e101
SP
19352DEFUN (no_lcommunity_list_expanded,
19353 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19354 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19355 NO_STR
19356 BGP_STR
19357 LCOMMUNITY_LIST_STR
19358 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19359 "Sequence number of an entry\n"
19360 "Sequence number\n"
7336e101
SP
19361 "Specify large community to reject\n"
19362 "Specify large community to accept\n"
19363 "An ordered list as a regular-expression\n")
57d187bc 19364{
d62a17ae 19365 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19366 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19367}
19368
7336e101
SP
19369DEFUN (no_lcommunity_list_name_standard,
19370 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 19371 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19372 NO_STR
19373 BGP_STR
19374 LCOMMUNITY_LIST_STR
19375 "Specify standard large-community-list\n"
19376 "Large Community list name\n"
2f8cc0e5
DA
19377 "Sequence number of an entry\n"
19378 "Sequence number\n"
7336e101
SP
19379 "Specify large community to reject\n"
19380 "Specify large community to accept\n"
19381 LCOMMUNITY_VAL_STR)
57d187bc 19382{
d62a17ae 19383 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19384 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19385}
19386
7336e101
SP
19387DEFUN (no_lcommunity_list_name_expanded,
19388 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19389 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19390 NO_STR
19391 BGP_STR
19392 LCOMMUNITY_LIST_STR
19393 "Specify expanded large-community-list\n"
19394 "Large community list name\n"
2f8cc0e5
DA
19395 "Sequence number of an entry\n"
19396 "Sequence number\n"
7336e101
SP
19397 "Specify large community to reject\n"
19398 "Specify large community to accept\n"
19399 "An ordered list as a regular-expression\n")
57d187bc 19400{
d62a17ae 19401 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19402 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19403}
19404
d62a17ae 19405static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19406{
19407 struct community_entry *entry;
19408
19409 for (entry = list->head; entry; entry = entry->next) {
19410 if (entry == list->head) {
19411 if (all_digit(list->name))
19412 vty_out(vty, "Large community %s list %s\n",
169b72c8 19413 entry->style ==
19414 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19415 ? "standard"
19416 : "(expanded) access",
19417 list->name);
19418 else
19419 vty_out(vty,
19420 "Named large community %s list %s\n",
169b72c8 19421 entry->style ==
19422 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19423 ? "standard"
19424 : "expanded",
19425 list->name);
19426 }
19427 if (entry->any)
19428 vty_out(vty, " %s\n",
19429 community_direct_str(entry->direct));
19430 else
19431 vty_out(vty, " %s %s\n",
19432 community_direct_str(entry->direct),
8d9b8ed9 19433 community_list_config_str(entry));
d62a17ae 19434 }
57d187bc
JS
19435}
19436
7336e101
SP
19437DEFUN (show_lcommunity_list,
19438 show_bgp_lcommunity_list_cmd,
19439 "show bgp large-community-list",
57d187bc 19440 SHOW_STR
7336e101 19441 BGP_STR
57d187bc
JS
19442 "List large-community list\n")
19443{
d62a17ae 19444 struct community_list *list;
19445 struct community_list_master *cm;
57d187bc 19446
d62a17ae 19447 cm = community_list_master_lookup(bgp_clist,
19448 LARGE_COMMUNITY_LIST_MASTER);
19449 if (!cm)
19450 return CMD_SUCCESS;
57d187bc 19451
d62a17ae 19452 for (list = cm->num.head; list; list = list->next)
19453 lcommunity_list_show(vty, list);
57d187bc 19454
d62a17ae 19455 for (list = cm->str.head; list; list = list->next)
19456 lcommunity_list_show(vty, list);
57d187bc 19457
d62a17ae 19458 return CMD_SUCCESS;
57d187bc
JS
19459}
19460
7336e101
SP
19461DEFUN (show_lcommunity_list_arg,
19462 show_bgp_lcommunity_list_arg_cmd,
960b69b9 19463 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
19464 SHOW_STR
19465 BGP_STR
57d187bc 19466 "List large-community list\n"
960b69b9 19467 "Large-community-list number\n"
19468 "Large-community-list name\n"
19469 "Detailed information on large-community-list\n")
57d187bc 19470{
d62a17ae 19471 struct community_list *list;
57d187bc 19472
e237b0d2 19473 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19474 LARGE_COMMUNITY_LIST_MASTER);
19475 if (!list) {
960b69b9 19476 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19477 return CMD_WARNING;
19478 }
57d187bc 19479
d62a17ae 19480 lcommunity_list_show(vty, list);
57d187bc 19481
d62a17ae 19482 return CMD_SUCCESS;
57d187bc
JS
19483}
19484
718e3744 19485/* "extcommunity-list" keyword help string. */
19486#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19487#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19488
7336e101
SP
19489DEFUN (extcommunity_list_standard,
19490 bgp_extcommunity_list_standard_cmd,
a08032fe 19491 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19492 BGP_STR
718e3744 19493 EXTCOMMUNITY_LIST_STR
19494 "Extended Community list number (standard)\n"
718e3744 19495 "Specify standard extcommunity-list\n"
5bf15956 19496 "Community list name\n"
2f8cc0e5
DA
19497 "Sequence number of an entry\n"
19498 "Sequence number\n"
718e3744 19499 "Specify community to reject\n"
19500 "Specify community to accept\n"
19501 EXTCOMMUNITY_VAL_STR)
19502{
d62a17ae 19503 int style = EXTCOMMUNITY_LIST_STANDARD;
19504 int direct = 0;
19505 char *cl_number_or_name = NULL;
2f8cc0e5 19506 char *seq = NULL;
42f914d4 19507
d62a17ae 19508 int idx = 0;
7b9a4750 19509
d62a17ae 19510 argv_find(argv, argc, "(1-99)", &idx);
19511 argv_find(argv, argc, "WORD", &idx);
19512 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19513
a08032fe 19514 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19515 seq = argv[idx]->arg;
19516
d62a17ae 19517 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19518 : COMMUNITY_DENY;
19519 argv_find(argv, argc, "AA:NN", &idx);
19520 char *str = argv_concat(argv, argc, idx);
42f914d4 19521
2f8cc0e5 19522 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19523 direct, style);
42f914d4 19524
d62a17ae 19525 XFREE(MTYPE_TMP, str);
42f914d4 19526
d62a17ae 19527 if (ret < 0) {
19528 community_list_perror(vty, ret);
19529 return CMD_WARNING_CONFIG_FAILED;
19530 }
42f914d4 19531
d62a17ae 19532 return CMD_SUCCESS;
718e3744 19533}
19534
7336e101
SP
19535DEFUN (extcommunity_list_name_expanded,
19536 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 19537 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19538 BGP_STR
19539 EXTCOMMUNITY_LIST_STR
5bf15956 19540 "Extended Community list number (expanded)\n"
718e3744 19541 "Specify expanded extcommunity-list\n"
19542 "Extended Community list name\n"
2f8cc0e5
DA
19543 "Sequence number of an entry\n"
19544 "Sequence number\n"
718e3744 19545 "Specify community to reject\n"
19546 "Specify community to accept\n"
19547 "An ordered list as a regular-expression\n")
19548{
d62a17ae 19549 int style = EXTCOMMUNITY_LIST_EXPANDED;
19550 int direct = 0;
19551 char *cl_number_or_name = NULL;
2f8cc0e5 19552 char *seq = NULL;
d62a17ae 19553 int idx = 0;
7336e101 19554
d62a17ae 19555 argv_find(argv, argc, "(100-500)", &idx);
19556 argv_find(argv, argc, "WORD", &idx);
19557 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19558
a08032fe 19559 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19560 seq = argv[idx]->arg;
19561
d62a17ae 19562 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19563 : COMMUNITY_DENY;
19564 argv_find(argv, argc, "LINE", &idx);
19565 char *str = argv_concat(argv, argc, idx);
42f914d4 19566
2f8cc0e5 19567 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19568 direct, style);
42f914d4 19569
d62a17ae 19570 XFREE(MTYPE_TMP, str);
42f914d4 19571
d62a17ae 19572 if (ret < 0) {
19573 community_list_perror(vty, ret);
19574 return CMD_WARNING_CONFIG_FAILED;
19575 }
42f914d4 19576
d62a17ae 19577 return CMD_SUCCESS;
718e3744 19578}
19579
7336e101
SP
19580DEFUN (no_extcommunity_list_standard_all,
19581 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 19582 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19583 NO_STR
19584 BGP_STR
19585 EXTCOMMUNITY_LIST_STR
813d4307 19586 "Extended Community list number (standard)\n"
718e3744 19587 "Specify standard extcommunity-list\n"
5bf15956 19588 "Community list name\n"
2f8cc0e5
DA
19589 "Sequence number of an entry\n"
19590 "Sequence number\n"
718e3744 19591 "Specify community to reject\n"
19592 "Specify community to accept\n"
19593 EXTCOMMUNITY_VAL_STR)
19594{
d62a17ae 19595 int style = EXTCOMMUNITY_LIST_STANDARD;
19596 int direct = 0;
19597 char *cl_number_or_name = NULL;
d4455c89 19598 char *str = NULL;
2f8cc0e5 19599 char *seq = NULL;
d62a17ae 19600 int idx = 0;
d4455c89 19601
a08032fe 19602 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19603 seq = argv[idx]->arg;
19604
19605 idx = 0;
d4455c89
DA
19606 argv_find(argv, argc, "permit", &idx);
19607 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
19608 if (idx) {
19609 direct = argv_find(argv, argc, "permit", &idx)
19610 ? COMMUNITY_PERMIT
19611 : COMMUNITY_DENY;
19612
19613 idx = 0;
19614 argv_find(argv, argc, "AA:NN", &idx);
19615 str = argv_concat(argv, argc, idx);
19616 }
19617
19618 idx = 0;
d62a17ae 19619 argv_find(argv, argc, "(1-99)", &idx);
19620 argv_find(argv, argc, "WORD", &idx);
19621 cl_number_or_name = argv[idx]->arg;
42f914d4 19622
d62a17ae 19623 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19624 seq, direct, style);
42f914d4 19625
d62a17ae 19626 XFREE(MTYPE_TMP, str);
42f914d4 19627
d62a17ae 19628 if (ret < 0) {
19629 community_list_perror(vty, ret);
19630 return CMD_WARNING_CONFIG_FAILED;
19631 }
42f914d4 19632
d62a17ae 19633 return CMD_SUCCESS;
718e3744 19634}
19635
d4455c89
DA
19636ALIAS(no_extcommunity_list_standard_all,
19637 no_bgp_extcommunity_list_standard_all_list_cmd,
19638 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 19639 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19640 "Extended Community list number (standard)\n"
19641 "Specify standard extcommunity-list\n"
19642 "Community list name\n")
19643
7336e101
SP
19644DEFUN (no_extcommunity_list_expanded_all,
19645 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 19646 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19647 NO_STR
19648 BGP_STR
19649 EXTCOMMUNITY_LIST_STR
718e3744 19650 "Extended Community list number (expanded)\n"
718e3744 19651 "Specify expanded extcommunity-list\n"
5bf15956 19652 "Extended Community list name\n"
2f8cc0e5
DA
19653 "Sequence number of an entry\n"
19654 "Sequence number\n"
718e3744 19655 "Specify community to reject\n"
19656 "Specify community to accept\n"
19657 "An ordered list as a regular-expression\n")
19658{
d62a17ae 19659 int style = EXTCOMMUNITY_LIST_EXPANDED;
19660 int direct = 0;
19661 char *cl_number_or_name = NULL;
d4455c89 19662 char *str = NULL;
2f8cc0e5 19663 char *seq = NULL;
d62a17ae 19664 int idx = 0;
d4455c89 19665
a08032fe 19666 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19667 seq = argv[idx]->arg;
19668
19669 idx = 0;
d4455c89
DA
19670 argv_find(argv, argc, "permit", &idx);
19671 argv_find(argv, argc, "deny", &idx);
19672
19673 if (idx) {
19674 direct = argv_find(argv, argc, "permit", &idx)
19675 ? COMMUNITY_PERMIT
19676 : COMMUNITY_DENY;
19677
19678 idx = 0;
19679 argv_find(argv, argc, "LINE", &idx);
19680 str = argv_concat(argv, argc, idx);
19681 }
19682
19683 idx = 0;
d62a17ae 19684 argv_find(argv, argc, "(100-500)", &idx);
19685 argv_find(argv, argc, "WORD", &idx);
19686 cl_number_or_name = argv[idx]->arg;
42f914d4 19687
d62a17ae 19688 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 19689 seq, direct, style);
42f914d4 19690
d62a17ae 19691 XFREE(MTYPE_TMP, str);
42f914d4 19692
d62a17ae 19693 if (ret < 0) {
19694 community_list_perror(vty, ret);
19695 return CMD_WARNING_CONFIG_FAILED;
19696 }
42f914d4 19697
d62a17ae 19698 return CMD_SUCCESS;
718e3744 19699}
19700
d4455c89
DA
19701ALIAS(no_extcommunity_list_expanded_all,
19702 no_bgp_extcommunity_list_expanded_all_list_cmd,
19703 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 19704 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
19705 "Extended Community list number (expanded)\n"
19706 "Specify expanded extcommunity-list\n"
19707 "Extended Community list name\n")
19708
d62a17ae 19709static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 19710{
d62a17ae 19711 struct community_entry *entry;
718e3744 19712
d62a17ae 19713 for (entry = list->head; entry; entry = entry->next) {
19714 if (entry == list->head) {
19715 if (all_digit(list->name))
19716 vty_out(vty, "Extended community %s list %s\n",
19717 entry->style == EXTCOMMUNITY_LIST_STANDARD
19718 ? "standard"
19719 : "(expanded) access",
19720 list->name);
19721 else
19722 vty_out(vty,
19723 "Named extended community %s list %s\n",
19724 entry->style == EXTCOMMUNITY_LIST_STANDARD
19725 ? "standard"
19726 : "expanded",
19727 list->name);
19728 }
19729 if (entry->any)
19730 vty_out(vty, " %s\n",
19731 community_direct_str(entry->direct));
19732 else
19733 vty_out(vty, " %s %s\n",
19734 community_direct_str(entry->direct),
8d9b8ed9 19735 community_list_config_str(entry));
d62a17ae 19736 }
718e3744 19737}
19738
7336e101
SP
19739DEFUN (show_extcommunity_list,
19740 show_bgp_extcommunity_list_cmd,
19741 "show bgp extcommunity-list",
718e3744 19742 SHOW_STR
7336e101 19743 BGP_STR
718e3744 19744 "List extended-community list\n")
19745{
d62a17ae 19746 struct community_list *list;
19747 struct community_list_master *cm;
718e3744 19748
d62a17ae 19749 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19750 if (!cm)
19751 return CMD_SUCCESS;
718e3744 19752
d62a17ae 19753 for (list = cm->num.head; list; list = list->next)
19754 extcommunity_list_show(vty, list);
718e3744 19755
d62a17ae 19756 for (list = cm->str.head; list; list = list->next)
19757 extcommunity_list_show(vty, list);
718e3744 19758
d62a17ae 19759 return CMD_SUCCESS;
718e3744 19760}
19761
7336e101
SP
19762DEFUN (show_extcommunity_list_arg,
19763 show_bgp_extcommunity_list_arg_cmd,
960b69b9 19764 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
19765 SHOW_STR
19766 BGP_STR
718e3744 19767 "List extended-community list\n"
19768 "Extcommunity-list number\n"
960b69b9 19769 "Extcommunity-list name\n"
19770 "Detailed information on extcommunity-list\n")
718e3744 19771{
d62a17ae 19772 int idx_comm_list = 3;
19773 struct community_list *list;
718e3744 19774
e237b0d2 19775 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19776 EXTCOMMUNITY_LIST_MASTER);
19777 if (!list) {
19778 vty_out(vty, "%% Can't find extcommunity-list\n");
19779 return CMD_WARNING;
19780 }
718e3744 19781
d62a17ae 19782 extcommunity_list_show(vty, list);
718e3744 19783
d62a17ae 19784 return CMD_SUCCESS;
718e3744 19785}
6b0655a2 19786
718e3744 19787/* Display community-list and extcommunity-list configuration. */
d62a17ae 19788static int community_list_config_write(struct vty *vty)
19789{
19790 struct community_list *list;
19791 struct community_entry *entry;
19792 struct community_list_master *cm;
19793 int write = 0;
19794
19795 /* Community-list. */
19796 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19797
19798 for (list = cm->num.head; list; list = list->next)
19799 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19800 vty_out(vty,
19801 "bgp community-list %s seq %" PRId64 " %s %s\n",
19802 list->name, entry->seq,
d62a17ae 19803 community_direct_str(entry->direct),
19804 community_list_config_str(entry));
19805 write++;
19806 }
19807 for (list = cm->str.head; list; list = list->next)
19808 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19809 vty_out(vty,
19810 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 19811 entry->style == COMMUNITY_LIST_STANDARD
19812 ? "standard"
19813 : "expanded",
2f8cc0e5
DA
19814 list->name, entry->seq,
19815 community_direct_str(entry->direct),
d62a17ae 19816 community_list_config_str(entry));
19817 write++;
19818 }
19819
19820 /* Extcommunity-list. */
19821 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19822
19823 for (list = cm->num.head; list; list = list->next)
19824 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
19825 vty_out(vty,
19826 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
19827 list->name, entry->seq,
19828 community_direct_str(entry->direct),
d62a17ae 19829 community_list_config_str(entry));
19830 write++;
19831 }
19832 for (list = cm->str.head; list; list = list->next)
19833 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19834 vty_out(vty,
6cde4b45 19835 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 19836 entry->style == EXTCOMMUNITY_LIST_STANDARD
19837 ? "standard"
19838 : "expanded",
2f8cc0e5
DA
19839 list->name, entry->seq,
19840 community_direct_str(entry->direct),
d62a17ae 19841 community_list_config_str(entry));
19842 write++;
19843 }
19844
19845
19846 /* lcommunity-list. */
19847 cm = community_list_master_lookup(bgp_clist,
19848 LARGE_COMMUNITY_LIST_MASTER);
19849
19850 for (list = cm->num.head; list; list = list->next)
19851 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19852 vty_out(vty,
6cde4b45 19853 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
19854 list->name, entry->seq,
19855 community_direct_str(entry->direct),
d62a17ae 19856 community_list_config_str(entry));
19857 write++;
19858 }
19859 for (list = cm->str.head; list; list = list->next)
19860 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 19861 vty_out(vty,
6cde4b45 19862 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 19863
d62a17ae 19864 entry->style == LARGE_COMMUNITY_LIST_STANDARD
19865 ? "standard"
19866 : "expanded",
2f8cc0e5 19867 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 19868 community_list_config_str(entry));
19869 write++;
19870 }
19871
19872 return write;
19873}
19874
612c2c15 19875static int community_list_config_write(struct vty *vty);
d62a17ae 19876static struct cmd_node community_list_node = {
f4b8291f 19877 .name = "community list",
62b346ee
DL
19878 .node = COMMUNITY_LIST_NODE,
19879 .prompt = "",
612c2c15 19880 .config_write = community_list_config_write,
718e3744 19881};
19882
d62a17ae 19883static void community_list_vty(void)
19884{
612c2c15 19885 install_node(&community_list_node);
d62a17ae 19886
19887 /* Community-list. */
7336e101
SP
19888 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
19889 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
19890 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 19891 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 19892 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 19893 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
19894 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
19895 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 19896
19897 /* Extcommunity-list. */
7336e101
SP
19898 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
19899 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
19900 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
19901 install_element(CONFIG_NODE,
19902 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 19903 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
19904 install_element(CONFIG_NODE,
19905 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
19906 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
19907 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 19908
19909 /* Large Community List */
7336e101 19910 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
19911 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
19912 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 19913 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
19914 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
19915 install_element(CONFIG_NODE,
19916 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
19917 install_element(CONFIG_NODE,
19918 &no_bgp_lcommunity_list_name_expanded_all_cmd);
19919 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
19920 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
19921 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
19922 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
19923 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
19924 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
19925
19926 bgp_community_list_command_completion_setup();
5bf15956 19927}
ed0e57e3
DA
19928
19929static struct cmd_node community_alias_node = {
19930 .name = "community alias",
19931 .node = COMMUNITY_ALIAS_NODE,
19932 .prompt = "",
19933 .config_write = bgp_community_alias_write,
19934};
19935
19936void community_alias_vty(void)
19937{
19938 install_node(&community_alias_node);
19939
19940 /* Community-list. */
19941 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
19942
19943 bgp_community_alias_command_completion_setup();
ed0e57e3 19944}