]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #11879 from mobash-rasool/fixes2
[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"
4122b697 57#include "bgpd/bgp_network.h"
718e3744 58#include "bgpd/bgp_open.h"
4bf6a362 59#include "bgpd/bgp_regex.h"
718e3744 60#include "bgpd/bgp_route.h"
c016b6c7 61#include "bgpd/bgp_mplsvpn.h"
718e3744 62#include "bgpd/bgp_zebra.h"
fee0f4c6 63#include "bgpd/bgp_table.h"
94f2b392 64#include "bgpd/bgp_vty.h"
165b5fff 65#include "bgpd/bgp_mpath.h"
cb1faec9 66#include "bgpd/bgp_packet.h"
3f9c7369 67#include "bgpd/bgp_updgrp.h"
c43ed2e4 68#include "bgpd/bgp_bfd.h"
555e09d4 69#include "bgpd/bgp_io.h"
94c2f693 70#include "bgpd/bgp_evpn.h"
dd65f45e 71#include "bgpd/bgp_evpn_vty.h"
b5e140c8 72#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 73#include "bgpd/bgp_addpath.h"
48ecf8f5 74#include "bgpd/bgp_mac.h"
dd65f45e 75#include "bgpd/bgp_flowspec.h"
389e4f92 76#include "bgpd/bgp_conditional_adv.h"
49e5a4a0 77#ifdef ENABLE_BGP_VNC
dd65f45e
DL
78#include "bgpd/rfapi/bgp_rfapi_cfg.h"
79#endif
80
5d5393b9 81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
67b0f40c 88);
5d5393b9 89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
67b0f40c 92);
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
67b0f40c 96);
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
67b0f40c 100);
5d5393b9 101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
67b0f40c 104);
5d5393b9
DL
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
67b0f40c 108);
5d5393b9
DL
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
67b0f40c 112);
5d5393b9
DL
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
67b0f40c 116);
1d3fdccf
DA
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
67b0f40c 121);
2adac256
DA
122FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
67b0f40c 125);
f2ca5c5b
DA
126FRR_CFG_DEFAULT_BOOL(BGP_GRACEFUL_NOTIFICATION,
127 { .val_bool = false, .match_version = "< 8.3", },
128 { .val_bool = true },
129);
1ae314be
DA
130FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET,
131 { .val_bool = false, .match_version = "< 8.3", },
132 { .val_bool = true },
133);
5d5393b9 134
dd65f45e
DL
135DEFINE_HOOK(bgp_inst_config_write,
136 (struct bgp *bgp, struct vty *vty),
8451921b
DL
137 (bgp, vty));
138DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
1ca2fd11 139DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
718e3744 140
d62a17ae 141static struct peer_group *listen_range_exists(struct bgp *bgp,
142 struct prefix *range, int exact);
143
055679e9 144/* Show BGP peer's information. */
145enum show_type {
146 show_all,
147 show_peer,
148 show_ipv4_all,
149 show_ipv6_all,
150 show_ipv4_peer,
151 show_ipv6_peer
152};
153
36235319
QY
154static struct peer_group *listen_range_exists(struct bgp *bgp,
155 struct prefix *range, int exact);
2986cac2 156
36235319
QY
157static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
158 struct bgp *bgp,
159 bool use_json,
160 json_object *json);
2986cac2 161
36235319
QY
162static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
163 enum show_type type,
164 const char *ip_str,
165 afi_t afi, bool use_json);
2986cac2 166
d62a17ae 167static enum node_type bgp_node_type(afi_t afi, safi_t safi)
168{
169 switch (afi) {
170 case AFI_IP:
171 switch (safi) {
172 case SAFI_UNICAST:
173 return BGP_IPV4_NODE;
d62a17ae 174 case SAFI_MULTICAST:
175 return BGP_IPV4M_NODE;
d62a17ae 176 case SAFI_LABELED_UNICAST:
177 return BGP_IPV4L_NODE;
d62a17ae 178 case SAFI_MPLS_VPN:
179 return BGP_VPNV4_NODE;
7c40bf39 180 case SAFI_FLOWSPEC:
181 return BGP_FLOWSPECV4_NODE;
5c525538
RW
182 default:
183 /* not expected */
184 return BGP_IPV4_NODE;
d62a17ae 185 }
d62a17ae 186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
d62a17ae 190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
d62a17ae 192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
d62a17ae 194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
7c40bf39 196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
5c525538
RW
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
d62a17ae 201 }
d62a17ae 202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
b26f891d 204 case AFI_UNSPEC:
d62a17ae 205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
d62a17ae 208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
f51bae9c 212}
20eb8864 213
5cb5f4d0
DD
214static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215{
7d0d37de
DS
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
5cb5f4d0
DD
248}
249
250/*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257{
7d0d37de
DS
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
5cb5f4d0
DD
290}
291
0249b8b6
HS
292/* unset srv6 locator */
293static int bgp_srv6_locator_unset(struct bgp *bgp)
294{
295 int ret;
296 struct listnode *node, *nnode;
1c21a234 297 struct srv6_locator_chunk *chunk;
0249b8b6
HS
298 struct bgp_srv6_function *func;
299 struct bgp *bgp_vrf;
300 struct in6_addr *tovpn_sid;
301
302 /* release chunk notification via ZAPI */
303 ret = bgp_zebra_srv6_manager_release_locator_chunk(
304 bgp->srv6_locator_name);
305 if (ret < 0)
306 return -1;
307
308 /* refresh chunks */
03852f67 309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) {
0249b8b6 310 listnode_delete(bgp->srv6_locator_chunks, chunk);
03852f67
CS
311 srv6_locator_chunk_free(chunk);
312 }
0249b8b6
HS
313
314 /* refresh functions */
bda15542 315 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) {
0249b8b6 316 listnode_delete(bgp->srv6_functions, func);
bda15542
CS
317 XFREE(MTYPE_BGP_SRV6_FUNCTION, func);
318 }
0249b8b6
HS
319
320 /* refresh tovpn_sid */
321 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
322 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
323 continue;
324
325 /* refresh vpnv4 tovpn_sid */
326 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
327 if (tovpn_sid)
328 XFREE(MTYPE_BGP_SRV6_SID,
329 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
330
331 /* refresh vpnv6 tovpn_sid */
332 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
333 if (tovpn_sid)
334 XFREE(MTYPE_BGP_SRV6_SID,
335 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
336 }
337
338 /* update vpn bgp processes */
339 vpn_leak_postchange_all();
340
f8e9c702
CS
341 /* refresh tovpn_sid_locator */
342 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
343 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
344 continue;
345
346 /* refresh vpnv4 tovpn_sid_locator */
347 XFREE(MTYPE_BGP_SRV6_SID,
348 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid_locator);
349
350 /* refresh vpnv6 tovpn_sid_locator */
351 XFREE(MTYPE_BGP_SRV6_SID,
352 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid_locator);
353 }
354
0249b8b6
HS
355 /* clear locator name */
356 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
357
358 return 0;
359}
360
718e3744 361/* Utility function to get address family from current node. */
d62a17ae 362afi_t bgp_node_afi(struct vty *vty)
363{
364 afi_t afi;
365 switch (vty->node) {
366 case BGP_IPV6_NODE:
367 case BGP_IPV6M_NODE:
368 case BGP_IPV6L_NODE:
369 case BGP_VPNV6_NODE:
7c40bf39 370 case BGP_FLOWSPECV6_NODE:
d62a17ae 371 afi = AFI_IP6;
372 break;
373 case BGP_EVPN_NODE:
374 afi = AFI_L2VPN;
375 break;
376 default:
377 afi = AFI_IP;
378 break;
379 }
380 return afi;
718e3744 381}
382
383/* Utility function to get subsequent address family from current
384 node. */
d62a17ae 385safi_t bgp_node_safi(struct vty *vty)
386{
387 safi_t safi;
388 switch (vty->node) {
389 case BGP_VPNV4_NODE:
390 case BGP_VPNV6_NODE:
391 safi = SAFI_MPLS_VPN;
392 break;
393 case BGP_IPV4M_NODE:
394 case BGP_IPV6M_NODE:
395 safi = SAFI_MULTICAST;
396 break;
397 case BGP_EVPN_NODE:
398 safi = SAFI_EVPN;
399 break;
400 case BGP_IPV4L_NODE:
401 case BGP_IPV6L_NODE:
402 safi = SAFI_LABELED_UNICAST;
403 break;
7c40bf39 404 case BGP_FLOWSPECV4_NODE:
405 case BGP_FLOWSPECV6_NODE:
406 safi = SAFI_FLOWSPEC;
407 break;
d62a17ae 408 default:
409 safi = SAFI_UNICAST;
410 break;
411 }
412 return safi;
718e3744 413}
414
55f91488
QY
415/**
416 * Converts an AFI in string form to afi_t
417 *
418 * @param afi string, one of
419 * - "ipv4"
420 * - "ipv6"
81cf0de5 421 * - "l2vpn"
55f91488
QY
422 * @return the corresponding afi_t
423 */
d62a17ae 424afi_t bgp_vty_afi_from_str(const char *afi_str)
425{
426 afi_t afi = AFI_MAX; /* unknown */
427 if (strmatch(afi_str, "ipv4"))
428 afi = AFI_IP;
429 else if (strmatch(afi_str, "ipv6"))
430 afi = AFI_IP6;
81cf0de5
CS
431 else if (strmatch(afi_str, "l2vpn"))
432 afi = AFI_L2VPN;
d62a17ae 433 return afi;
434}
435
436int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
437 afi_t *afi)
438{
439 int ret = 0;
440 if (argv_find(argv, argc, "ipv4", index)) {
441 ret = 1;
442 if (afi)
443 *afi = AFI_IP;
444 } else if (argv_find(argv, argc, "ipv6", index)) {
445 ret = 1;
446 if (afi)
447 *afi = AFI_IP6;
8688b3e7
DS
448 } else if (argv_find(argv, argc, "l2vpn", index)) {
449 ret = 1;
450 if (afi)
451 *afi = AFI_L2VPN;
d62a17ae 452 }
453 return ret;
46f296b4
LB
454}
455
375a2e67 456/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 457safi_t bgp_vty_safi_from_str(const char *safi_str)
458{
459 safi_t safi = SAFI_MAX; /* unknown */
460 if (strmatch(safi_str, "multicast"))
461 safi = SAFI_MULTICAST;
462 else if (strmatch(safi_str, "unicast"))
463 safi = SAFI_UNICAST;
464 else if (strmatch(safi_str, "vpn"))
465 safi = SAFI_MPLS_VPN;
81cf0de5
CS
466 else if (strmatch(safi_str, "evpn"))
467 safi = SAFI_EVPN;
d62a17ae 468 else if (strmatch(safi_str, "labeled-unicast"))
469 safi = SAFI_LABELED_UNICAST;
7c40bf39 470 else if (strmatch(safi_str, "flowspec"))
471 safi = SAFI_FLOWSPEC;
d62a17ae 472 return safi;
473}
474
475int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
476 safi_t *safi)
477{
478 int ret = 0;
479 if (argv_find(argv, argc, "unicast", index)) {
480 ret = 1;
481 if (safi)
482 *safi = SAFI_UNICAST;
483 } else if (argv_find(argv, argc, "multicast", index)) {
484 ret = 1;
485 if (safi)
486 *safi = SAFI_MULTICAST;
487 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
488 ret = 1;
489 if (safi)
490 *safi = SAFI_LABELED_UNICAST;
491 } else if (argv_find(argv, argc, "vpn", index)) {
492 ret = 1;
493 if (safi)
494 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
495 } else if (argv_find(argv, argc, "evpn", index)) {
496 ret = 1;
497 if (safi)
498 *safi = SAFI_EVPN;
7c40bf39 499 } else if (argv_find(argv, argc, "flowspec", index)) {
500 ret = 1;
501 if (safi)
502 *safi = SAFI_FLOWSPEC;
d62a17ae 503 }
504 return ret;
46f296b4
LB
505}
506
b16bcbba
TA
507/*
508 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
509 *
510 * afi
511 * address-family identifier
512 *
513 * safi
514 * subsequent address-family identifier
515 *
516 * Returns:
517 * default_af string corresponding to the supplied afi/safi pair.
518 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
519 * return -1.
520 */
521static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
522{
523 switch (afi) {
524 case AFI_IP:
525 switch (safi) {
526 case SAFI_UNICAST:
527 return "ipv4-unicast";
528 case SAFI_MULTICAST:
529 return "ipv4-multicast";
530 case SAFI_MPLS_VPN:
531 return "ipv4-vpn";
532 case SAFI_ENCAP:
533 return "ipv4-encap";
534 case SAFI_LABELED_UNICAST:
535 return "ipv4-labeled-unicast";
536 case SAFI_FLOWSPEC:
537 return "ipv4-flowspec";
538 default:
539 return "unknown-afi/safi";
540 }
541 break;
542 case AFI_IP6:
543 switch (safi) {
544 case SAFI_UNICAST:
545 return "ipv6-unicast";
546 case SAFI_MULTICAST:
547 return "ipv6-multicast";
548 case SAFI_MPLS_VPN:
549 return "ipv6-vpn";
550 case SAFI_ENCAP:
551 return "ipv6-encap";
552 case SAFI_LABELED_UNICAST:
553 return "ipv6-labeled-unicast";
554 case SAFI_FLOWSPEC:
555 return "ipv6-flowspec";
556 default:
557 return "unknown-afi/safi";
558 }
559 break;
560 case AFI_L2VPN:
561 switch (safi) {
562 case SAFI_EVPN:
563 return "l2vpn-evpn";
564 default:
565 return "unknown-afi/safi";
566 }
567 case AFI_UNSPEC:
568 case AFI_MAX:
569 return "unknown-afi/safi";
570 }
571 /* all AFIs are accounted for above, so this shouldn't happen */
572 return "unknown-afi/safi";
573}
574
5d5393b9
DL
575int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
576 enum bgp_instance_type inst_type)
577{
578 int ret = bgp_get(bgp, as, name, inst_type);
579
580 if (ret == BGP_CREATED) {
581 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 582 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
583
584 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 585 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 586 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 587 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
588 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
589 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 590 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 591 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 592 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 593 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
594 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
595 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
596 if (DFLT_BGP_SUPPRESS_DUPLICATES)
597 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
598 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
599 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
600 if (DFLT_BGP_HARD_ADMIN_RESET)
601 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
602
603 ret = BGP_SUCCESS;
604 }
605 return ret;
606}
607
7eeee51e 608/*
f212a857 609 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 610 *
f212a857
DS
611 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
612 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
613 * to appropriate values for the calling function. This is to allow the
614 * calling function to make decisions appropriate for the show command
615 * that is being parsed.
616 *
617 * The show commands are generally of the form:
d62a17ae 618 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
619 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
620 *
621 * Since we use argv_find if the show command in particular doesn't have:
622 * [ip]
18c57037 623 * [<view|vrf> VIEWVRFNAME]
375a2e67 624 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
625 * The command parsing should still be ok.
626 *
627 * vty -> The vty for the command so we can output some useful data in
628 * the event of a parse error in the vrf.
629 * argv -> The command tokens
630 * argc -> How many command tokens we have
d62a17ae 631 * idx -> The current place in the command, generally should be 0 for this
632 * function
7eeee51e
DS
633 * afi -> The parsed afi if it was included in the show command, returned here
634 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 635 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 636 * use_json -> json is configured or not
7eeee51e
DS
637 *
638 * The function returns the correct location in the parse tree for the
639 * last token found.
0e37c258
DS
640 *
641 * Returns 0 for failure to parse correctly, else the idx position of where
642 * it found the last token.
7eeee51e 643 */
d62a17ae 644int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
645 struct cmd_token **argv, int argc,
646 int *idx, afi_t *afi, safi_t *safi,
9f049418 647 struct bgp **bgp, bool use_json)
d62a17ae 648{
649 char *vrf_name = NULL;
650
651 assert(afi);
652 assert(safi);
653 assert(bgp);
654
655 if (argv_find(argv, argc, "ip", idx))
656 *afi = AFI_IP;
657
9a8bdf1c 658 if (argv_find(argv, argc, "view", idx))
d62a17ae 659 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
660 else if (argv_find(argv, argc, "vrf", idx)) {
661 vrf_name = argv[*idx + 1]->arg;
662 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
663 vrf_name = NULL;
664 }
665 if (vrf_name) {
d62a17ae 666 if (strmatch(vrf_name, "all"))
667 *bgp = NULL;
668 else {
669 *bgp = bgp_lookup_by_name(vrf_name);
670 if (!*bgp) {
52e5b8c4
SP
671 if (use_json) {
672 json_object *json = NULL;
673 json = json_object_new_object();
674 json_object_string_add(
675 json, "warning",
676 "View/Vrf is unknown");
75eeda93 677 vty_json(vty, json);
52e5b8c4 678 }
ca61fd25
DS
679 else
680 vty_out(vty, "View/Vrf %s is unknown\n",
681 vrf_name);
d62a17ae 682 *idx = 0;
683 return 0;
684 }
685 }
686 } else {
687 *bgp = bgp_get_default();
688 if (!*bgp) {
52e5b8c4
SP
689 if (use_json) {
690 json_object *json = NULL;
691 json = json_object_new_object();
692 json_object_string_add(
693 json, "warning",
694 "Default BGP instance not found");
75eeda93 695 vty_json(vty, json);
52e5b8c4 696 }
ca61fd25
DS
697 else
698 vty_out(vty,
699 "Default BGP instance not found\n");
d62a17ae 700 *idx = 0;
701 return 0;
702 }
703 }
704
705 if (argv_find_and_parse_afi(argv, argc, idx, afi))
706 argv_find_and_parse_safi(argv, argc, idx, safi);
707
708 *idx += 1;
709 return *idx;
710}
711
28c6e247 712static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 713{
714 struct interface *ifp = NULL;
4122b697
DA
715 struct listnode *node;
716 struct bgp_listener *listener;
717 union sockunion all_su;
d62a17ae 718
4122b697 719 if (su->sa.sa_family == AF_INET) {
3d2a2725 720 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 721 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 722 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 723 (void)str2sockunion("::", &all_su);
d62a17ae 724 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
725 su->sin6.sin6_scope_id,
726 bgp->vrf_id);
4122b697 727 }
d62a17ae 728
4122b697
DA
729 if (ifp) {
730 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
731 if (sockunion_family(su) !=
732 sockunion_family(&listener->su))
733 continue;
734
735 /* If 0.0.0.0/:: is a listener, then treat as self and
736 * reject.
737 */
738 if (!sockunion_cmp(&listener->su, su) ||
739 !sockunion_cmp(&listener->su, &all_su))
740 return true;
741 }
742 }
d62a17ae 743
3dc339cd 744 return false;
718e3744 745}
746
28c6e247
IR
747/* Utility function for looking up peer from VTY. */
748/* This is used only for configuration, so disallow if attempted on
749 * a dynamic neighbor.
750 */
751static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
752{
753 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
754 int ret;
755 union sockunion su;
756 struct peer *peer;
757
758 if (!bgp) {
759 return NULL;
760 }
761
762 ret = str2sockunion(ip_str, &su);
763 if (ret < 0) {
764 peer = peer_lookup_by_conf_if(bgp, ip_str);
765 if (!peer) {
766 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
767 == NULL) {
768 vty_out(vty,
769 "%% Malformed address or name: %s\n",
770 ip_str);
771 return NULL;
772 }
773 }
774 } else {
775 peer = peer_lookup(bgp, &su);
776 if (!peer) {
777 vty_out(vty,
778 "%% Specify remote-as or peer-group commands first\n");
779 return NULL;
780 }
781 if (peer_dynamic_neighbor(peer)) {
782 vty_out(vty,
783 "%% Operation not allowed on a dynamic neighbor\n");
784 return NULL;
785 }
786 }
787 return peer;
788}
789
718e3744 790/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
791/* This is used only for configuration, so disallow if attempted on
792 * a dynamic neighbor.
793 */
d62a17ae 794struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
795{
796 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
797 int ret;
798 union sockunion su;
799 struct peer *peer = NULL;
800 struct peer_group *group = NULL;
801
802 if (!bgp) {
803 return NULL;
804 }
805
806 ret = str2sockunion(peer_str, &su);
807 if (ret == 0) {
808 /* IP address, locate peer. */
809 peer = peer_lookup(bgp, &su);
810 } else {
811 /* Not IP, could match either peer configured on interface or a
812 * group. */
813 peer = peer_lookup_by_conf_if(bgp, peer_str);
814 if (!peer)
815 group = peer_group_lookup(bgp, peer_str);
816 }
817
818 if (peer) {
819 if (peer_dynamic_neighbor(peer)) {
820 vty_out(vty,
821 "%% Operation not allowed on a dynamic neighbor\n");
822 return NULL;
823 }
824
825 return peer;
826 }
827
828 if (group)
829 return group->conf;
830
831 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
832
833 return NULL;
834}
835
4b7e23e9 836int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 837{
838 const char *str = NULL;
839
840 switch (ret) {
4b7e23e9
DS
841 case BGP_SUCCESS:
842 case BGP_CREATED:
843 case BGP_GR_NO_OPERATION:
844 break;
d62a17ae 845 case BGP_ERR_INVALID_VALUE:
846 str = "Invalid value";
847 break;
848 case BGP_ERR_INVALID_FLAG:
849 str = "Invalid flag";
850 break;
851 case BGP_ERR_PEER_GROUP_SHUTDOWN:
852 str = "Peer-group has been shutdown. Activate the peer-group first";
853 break;
854 case BGP_ERR_PEER_FLAG_CONFLICT:
855 str = "Can't set override-capability and strict-capability-match at the same time";
856 break;
857 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
858 str = "Specify remote-as or peer-group remote AS first";
859 break;
860 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
861 str = "Cannot change the peer-group. Deconfigure first";
862 break;
863 case BGP_ERR_PEER_GROUP_MISMATCH:
864 str = "Peer is not a member of this peer-group";
865 break;
866 case BGP_ERR_PEER_FILTER_CONFLICT:
867 str = "Prefix/distribute list can not co-exist";
868 break;
869 case BGP_ERR_NOT_INTERNAL_PEER:
870 str = "Invalid command. Not an internal neighbor";
871 break;
872 case BGP_ERR_REMOVE_PRIVATE_AS:
873 str = "remove-private-AS cannot be configured for IBGP peers";
874 break;
875 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
876 str = "Local-AS allowed only for EBGP peers";
877 break;
878 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
879 str = "Cannot have local-as same as BGP AS number";
880 break;
881 case BGP_ERR_TCPSIG_FAILED:
882 str = "Error while applying TCP-Sig to session(s)";
883 break;
884 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
885 str = "ebgp-multihop and ttl-security cannot be configured together";
886 break;
887 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
888 str = "ttl-security only allowed for EBGP peers";
889 break;
890 case BGP_ERR_AS_OVERRIDE:
891 str = "as-override cannot be configured for IBGP peers";
892 break;
893 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
894 str = "Invalid limit for number of dynamic neighbors";
895 break;
896 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
897 str = "Dynamic neighbor listen range already exists";
898 break;
899 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
900 str = "Operation not allowed on a dynamic neighbor";
901 break;
902 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
903 str = "Operation not allowed on a directly connected neighbor";
904 break;
905 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 906 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 907 break;
908 case BGP_ERR_GR_INVALID_CMD:
909 str = "The Graceful Restart command used is not valid at this moment.";
910 break;
911 case BGP_ERR_GR_OPERATION_FAILED:
912 str = "The Graceful Restart Operation failed due to an err.";
913 break;
6dcea6fe
DS
914 case BGP_ERR_PEER_GROUP_MEMBER:
915 str = "Peer-group member cannot override remote-as of peer-group.";
916 break;
917 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
918 str = "Peer-group members must be all internal or all external.";
919 break;
4b7e23e9
DS
920 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
921 str = "Range specified cannot be deleted because it is not part of current config.";
922 break;
923 case BGP_ERR_INSTANCE_MISMATCH:
924 str = "Instance specified does not match the current instance.";
925 break;
926 case BGP_ERR_NO_INTERFACE_CONFIG:
927 str = "Interface specified is not being used for interface based peer.";
928 break;
929 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
930 str = "No configuration already specified for soft reconfiguration.";
931 break;
932 case BGP_ERR_AS_MISMATCH:
933 str = "BGP is already running.";
934 break;
935 case BGP_ERR_AF_UNCONFIGURED:
936 str = "AFI/SAFI specified is not currently configured.";
937 break;
938 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
939 str = "AS specified for local as is the same as the remote as and this is not allowed.";
940 break;
941 case BGP_ERR_INVALID_AS:
942 str = "Confederation AS specified is the same AS as our AS.";
943 break;
d864dd9e
EB
944 case BGP_ERR_INVALID_ROLE_NAME:
945 str = "Invalid role name";
946 break;
947 case BGP_ERR_INVALID_INTERNAL_ROLE:
8f2d6021 948 str = "External roles can be set only on eBGP session";
d864dd9e 949 break;
d62a17ae 950 }
951 if (str) {
952 vty_out(vty, "%% %s\n", str);
953 return CMD_WARNING_CONFIG_FAILED;
954 }
955 return CMD_SUCCESS;
718e3744 956}
957
7aafcaca 958/* BGP clear sort. */
d62a17ae 959enum clear_sort {
960 clear_all,
961 clear_peer,
962 clear_group,
963 clear_external,
964 clear_as
7aafcaca
DS
965};
966
1ca2fd11
IR
967static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
968 safi_t safi, int error)
d62a17ae 969{
970 switch (error) {
971 case BGP_ERR_AF_UNCONFIGURED:
a486300b
PG
972 if (vty)
973 vty_out(vty,
974 "%% BGP: Enable %s address family for the neighbor %s\n",
975 get_afi_safi_str(afi, safi, false), peer->host);
976 else
977 zlog_warn(
1af6e82b 978 "%% BGP: Enable %s address family for the neighbor %s",
a486300b 979 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 980 break;
981 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
a486300b
PG
982 if (vty)
983 vty_out(vty,
984 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
985 peer->host);
986 else
987 zlog_warn(
1af6e82b 988 "%% BGP: Inbound soft reconfig for %s not possible as it has neither refresh capability, nor inbound soft reconfig",
a486300b 989 peer->host);
d62a17ae 990 break;
991 default:
992 break;
993 }
7aafcaca
DS
994}
995
dc912615 996static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 997 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
998{
999 int ret = 0;
2adac256 1000 struct peer_af *paf;
dc912615
DS
1001
1002 /* if afi/.safi not specified, spin thru all of them */
1003 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
1004 afi_t tmp_afi;
1005 safi_t tmp_safi;
0e5cdd59
DS
1006 enum bgp_af_index index;
1007
1008 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
1009 paf = peer->peer_af_array[index];
1010 if (!paf)
1011 continue;
dc912615 1012
2adac256
DA
1013 if (paf && paf->subgroup)
1014 SET_FLAG(paf->subgroup->sflags,
1015 SUBGRP_STATUS_FORCE_UPDATES);
1016
0e5cdd59
DS
1017 tmp_afi = paf->afi;
1018 tmp_safi = paf->safi;
dc912615
DS
1019 if (!peer->afc[tmp_afi][tmp_safi])
1020 continue;
1021
1022 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1023 ret = peer_clear(peer, nnode);
dc912615
DS
1024 else
1025 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
1026 stype);
1027 }
1028 /* if afi specified and safi not, spin thru safis on this afi */
1029 } else if (safi == SAFI_UNSPEC) {
1030 safi_t tmp_safi;
1031
1032 for (tmp_safi = SAFI_UNICAST;
1033 tmp_safi < SAFI_MAX; tmp_safi++) {
1034 if (!peer->afc[afi][tmp_safi])
1035 continue;
1036
2adac256
DA
1037 paf = peer_af_find(peer, afi, tmp_safi);
1038 if (paf && paf->subgroup)
1039 SET_FLAG(paf->subgroup->sflags,
1040 SUBGRP_STATUS_FORCE_UPDATES);
1041
dc912615 1042 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1043 ret = peer_clear(peer, nnode);
dc912615
DS
1044 else
1045 ret = peer_clear_soft(peer, afi,
1046 tmp_safi, stype);
1047 }
1048 /* both afi/safi specified, let the caller know if not defined */
1049 } else {
1050 if (!peer->afc[afi][safi])
1051 return 1;
1052
2adac256
DA
1053 paf = peer_af_find(peer, afi, safi);
1054 if (paf && paf->subgroup)
1055 SET_FLAG(paf->subgroup->sflags,
1056 SUBGRP_STATUS_FORCE_UPDATES);
1057
dc912615 1058 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1059 ret = peer_clear(peer, nnode);
dc912615
DS
1060 else
1061 ret = peer_clear_soft(peer, afi, safi, stype);
1062 }
1063
1064 return ret;
1065}
1066
7aafcaca 1067/* `clear ip bgp' functions. */
1ca2fd11 1068static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1069 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1070 const char *arg)
d62a17ae 1071{
dc912615 1072 int ret = 0;
3ae8bfa5 1073 bool found = false;
d62a17ae 1074 struct peer *peer;
dc95985f 1075
1076 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1077
1078 /* Clear all neighbors. */
1079 /*
1080 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1081 * nodes on the BGP instance as that may get freed if it is a
1082 * doppelganger
d62a17ae 1083 */
1084 if (sort == clear_all) {
1085 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1086
1087 bgp_peer_gr_flags_update(peer);
1088
36235319 1089 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1090 gr_router_detected = true;
1091
c368171c 1092 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1093 stype);
d62a17ae 1094
1095 if (ret < 0)
1ca2fd11 1096 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1097 }
1098
36235319
QY
1099 if (gr_router_detected
1100 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1101 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1102 } else if (!gr_router_detected
1103 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1104 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1105 }
d62a17ae 1106
1107 /* This is to apply read-only mode on this clear. */
1108 if (stype == BGP_CLEAR_SOFT_NONE)
1109 bgp->update_delay_over = 0;
1110
1111 return CMD_SUCCESS;
7aafcaca
DS
1112 }
1113
3ae8bfa5 1114 /* Clear specified neighbor. */
d62a17ae 1115 if (sort == clear_peer) {
1116 union sockunion su;
d62a17ae 1117
1118 /* Make sockunion for lookup. */
1119 ret = str2sockunion(arg, &su);
1120 if (ret < 0) {
1121 peer = peer_lookup_by_conf_if(bgp, arg);
1122 if (!peer) {
1123 peer = peer_lookup_by_hostname(bgp, arg);
1124 if (!peer) {
1ca2fd11
IR
1125 vty_out(vty,
1126 "Malformed address or name: %s\n",
d62a17ae 1127 arg);
1128 return CMD_WARNING;
1129 }
1130 }
1131 } else {
1132 peer = peer_lookup(bgp, &su);
1133 if (!peer) {
1ca2fd11 1134 vty_out(vty,
664b6f18 1135 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1136 arg);
d62a17ae 1137 return CMD_WARNING;
1138 }
1139 }
7aafcaca 1140
dc95985f 1141 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1142 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1143
dc912615
DS
1144 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1145
1146 /* if afi/safi not defined for this peer, let caller know */
1147 if (ret == 1)
3ae8bfa5 1148 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1149
d62a17ae 1150 if (ret < 0)
1ca2fd11 1151 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1152
d62a17ae 1153 return CMD_SUCCESS;
7aafcaca 1154 }
7aafcaca 1155
3ae8bfa5 1156 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1157 if (sort == clear_group) {
1158 struct peer_group *group;
7aafcaca 1159
d62a17ae 1160 group = peer_group_lookup(bgp, arg);
1161 if (!group) {
664b6f18 1162 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1163 return CMD_WARNING;
1164 }
1165
1166 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1167 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1168
d62a17ae 1169 if (ret < 0)
1ca2fd11 1170 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1171 else
1172 found = true;
d62a17ae 1173 }
3ae8bfa5
PM
1174
1175 if (!found)
1ca2fd11 1176 vty_out(vty,
664b6f18 1177 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1178 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1179
d62a17ae 1180 return CMD_SUCCESS;
7aafcaca 1181 }
7aafcaca 1182
3ae8bfa5 1183 /* Clear all external (eBGP) neighbors. */
d62a17ae 1184 if (sort == clear_external) {
1185 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1186 if (peer->sort == BGP_PEER_IBGP)
1187 continue;
7aafcaca 1188
dc95985f 1189 bgp_peer_gr_flags_update(peer);
1190
36235319 1191 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1192 gr_router_detected = true;
dc95985f 1193
c368171c 1194 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1195
d62a17ae 1196 if (ret < 0)
1ca2fd11 1197 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1198 else
1199 found = true;
d62a17ae 1200 }
3ae8bfa5 1201
36235319
QY
1202 if (gr_router_detected
1203 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1204 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1205 } else if (!gr_router_detected
1206 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1207 bgp_zebra_send_capabilities(bgp, true);
1208 }
1209
3ae8bfa5 1210 if (!found)
1ca2fd11 1211 vty_out(vty,
664b6f18 1212 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1213 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1214
d62a17ae 1215 return CMD_SUCCESS;
1216 }
1217
3ae8bfa5 1218 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1219 if (sort == clear_as) {
3ae8bfa5 1220 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1221
1222 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1223 if (peer->as != as)
1224 continue;
1225
dc95985f 1226 bgp_peer_gr_flags_update(peer);
1227
36235319 1228 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1229 gr_router_detected = true;
dc95985f 1230
c368171c 1231 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1232
1233 if (ret < 0)
1ca2fd11 1234 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1235 else
1236 found = true;
d62a17ae 1237 }
3ae8bfa5 1238
36235319
QY
1239 if (gr_router_detected
1240 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1241 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1242 } else if (!gr_router_detected
1243 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1244 bgp_zebra_send_capabilities(bgp, true);
1245 }
1246
3ae8bfa5 1247 if (!found)
1ca2fd11 1248 vty_out(vty,
664b6f18 1249 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1250 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1251
d62a17ae 1252 return CMD_SUCCESS;
1253 }
1254
1255 return CMD_SUCCESS;
1256}
1257
1ca2fd11
IR
1258static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1259 safi_t safi, enum clear_sort sort,
1260 enum bgp_clear_type stype, const char *arg)
d62a17ae 1261{
1262 struct bgp *bgp;
1263
1264 /* BGP structure lookup. */
1265 if (name) {
1266 bgp = bgp_lookup_by_name(name);
1267 if (bgp == NULL) {
1ca2fd11 1268 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1269 return CMD_WARNING;
1270 }
1271 } else {
1272 bgp = bgp_get_default();
1273 if (bgp == NULL) {
1ca2fd11 1274 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1275 return CMD_WARNING;
1276 }
1277 }
1278
1ca2fd11 1279 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1280}
1281
1282/* clear soft inbound */
1ca2fd11 1283static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1284{
99b3ebd3
NS
1285 afi_t afi;
1286 safi_t safi;
1287
1ca2fd11
IR
1288 FOREACH_AFI_SAFI (afi, safi)
1289 bgp_clear_vty(vty, name, afi, safi, clear_all,
1290 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1291}
1292
1293/* clear soft outbound */
1ca2fd11 1294static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1295{
99b3ebd3
NS
1296 afi_t afi;
1297 safi_t safi;
1298
1ca2fd11
IR
1299 FOREACH_AFI_SAFI (afi, safi)
1300 bgp_clear_vty(vty, name, afi, safi, clear_all,
1301 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1302}
1303
1304
a486300b
PG
1305void bgp_clear_soft_in(struct bgp *bgp, afi_t afi, safi_t safi)
1306{
1307 bgp_clear(NULL, bgp, afi, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL);
1308}
1309
f787d7a0 1310#ifndef VTYSH_EXTRACT_PL
2e4c2296 1311#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1312#endif
1313
8029b216
AK
1314DEFUN_HIDDEN (bgp_local_mac,
1315 bgp_local_mac_cmd,
093e3f23 1316 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1317 BGP_STR
1318 "Local MAC config\n"
1319 "VxLAN Network Identifier\n"
1320 "VNI number\n"
1321 "local mac\n"
1322 "mac address\n"
1323 "mac-mobility sequence\n"
1324 "seq number\n")
1325{
1326 int rv;
1327 vni_t vni;
1328 struct ethaddr mac;
1329 struct ipaddr ip;
1330 uint32_t seq;
1331 struct bgp *bgp;
1332
1333 vni = strtoul(argv[3]->arg, NULL, 10);
1334 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1335 vty_out(vty, "%% Malformed MAC address\n");
1336 return CMD_WARNING;
1337 }
1338 memset(&ip, 0, sizeof(ip));
1339 seq = strtoul(argv[7]->arg, NULL, 10);
1340
1341 bgp = bgp_get_default();
1342 if (!bgp) {
1343 vty_out(vty, "Default BGP instance is not there\n");
1344 return CMD_WARNING;
1345 }
1346
b5e140c8
AK
1347 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1348 zero_esi);
8029b216
AK
1349 if (rv < 0) {
1350 vty_out(vty, "Internal error\n");
1351 return CMD_WARNING;
1352 }
1353
1354 return CMD_SUCCESS;
1355}
1356
1357DEFUN_HIDDEN (no_bgp_local_mac,
1358 no_bgp_local_mac_cmd,
093e3f23 1359 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1360 NO_STR
1361 BGP_STR
1362 "Local MAC config\n"
1363 "VxLAN Network Identifier\n"
1364 "VNI number\n"
1365 "local mac\n"
1366 "mac address\n")
1367{
1368 int rv;
1369 vni_t vni;
1370 struct ethaddr mac;
1371 struct ipaddr ip;
1372 struct bgp *bgp;
1373
1374 vni = strtoul(argv[4]->arg, NULL, 10);
1375 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1376 vty_out(vty, "%% Malformed MAC address\n");
1377 return CMD_WARNING;
1378 }
1379 memset(&ip, 0, sizeof(ip));
1380
1381 bgp = bgp_get_default();
1382 if (!bgp) {
1383 vty_out(vty, "Default BGP instance is not there\n");
1384 return CMD_WARNING;
1385 }
1386
ec0ab544 1387 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1388 if (rv < 0) {
1389 vty_out(vty, "Internal error\n");
1390 return CMD_WARNING;
1391 }
1392
1393 return CMD_SUCCESS;
1394}
1395
718e3744 1396DEFUN (no_synchronization,
1397 no_synchronization_cmd,
1398 "no synchronization",
1399 NO_STR
1400 "Perform IGP synchronization\n")
1401{
d62a17ae 1402 return CMD_SUCCESS;
718e3744 1403}
1404
1405DEFUN (no_auto_summary,
1406 no_auto_summary_cmd,
1407 "no auto-summary",
1408 NO_STR
1409 "Enable automatic network number summarization\n")
1410{
d62a17ae 1411 return CMD_SUCCESS;
718e3744 1412}
3d515fd9 1413
718e3744 1414/* "router bgp" commands. */
1ca2fd11
IR
1415DEFUN_NOSH (router_bgp,
1416 router_bgp_cmd,
1417 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1418 ROUTER_STR
1419 BGP_STR
1420 AS_STR
1421 BGP_INSTANCE_HELP_STR)
718e3744 1422{
d62a17ae 1423 int idx_asn = 2;
1424 int idx_view_vrf = 3;
1425 int idx_vrf = 4;
1ca2fd11
IR
1426 int is_new_bgp = 0;
1427 int ret;
d62a17ae 1428 as_t as;
1429 struct bgp *bgp;
1430 const char *name = NULL;
1431 enum bgp_instance_type inst_type;
1432
1433 // "router bgp" without an ASN
1434 if (argc == 2) {
1435 // Pending: Make VRF option available for ASN less config
1abef40f 1436 bgp = bgp_get_default();
d62a17ae 1437
1abef40f 1438 if (bgp == NULL) {
d62a17ae 1439 vty_out(vty, "%% No BGP process is configured\n");
1440 return CMD_WARNING_CONFIG_FAILED;
1441 }
1442
1443 if (listcount(bm->bgp) > 1) {
996c9314 1444 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1445 return CMD_WARNING_CONFIG_FAILED;
1446 }
1447 }
1448
1449 // "router bgp X"
1450 else {
ff8a8a7a 1451 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1452
cc413e2a
DA
1453 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1454 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1455 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1456
d62a17ae 1457 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1458 if (argc > 3) {
1459 name = argv[idx_vrf]->arg;
1460
9a8bdf1c
PG
1461 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1462 if (strmatch(name, VRF_DEFAULT_NAME))
1463 name = NULL;
1464 else
1465 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1466 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1467 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1468 }
1469
1ca2fd11
IR
1470 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1471 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1472
1ca2fd11
IR
1473 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1474 switch (ret) {
1475 case BGP_ERR_AS_MISMATCH:
1476 vty_out(vty, "BGP is already running; AS is %u\n", as);
1477 return CMD_WARNING_CONFIG_FAILED;
1478 case BGP_ERR_INSTANCE_MISMATCH:
1479 vty_out(vty,
1480 "BGP instance name and AS number mismatch\n");
1481 vty_out(vty,
1482 "BGP instance is already running; AS is %u\n",
1483 as);
1484 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1485 }
1ca2fd11
IR
1486
1487 /*
1488 * If we just instantiated the default instance, complete
1489 * any pending VRF-VPN leaking that was configured via
1490 * earlier "router bgp X vrf FOO" blocks.
1491 */
1492 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1493 vpn_leak_postchange_all();
1494
1495 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1496 bgp_vpn_leak_export(bgp);
1497 /* Pending: handle when user tries to change a view to vrf n vv.
1498 */
d62a17ae 1499 }
1500
1ca2fd11
IR
1501 /* unset the auto created flag as the user config is now present */
1502 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1503 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1504
1505 return CMD_SUCCESS;
718e3744 1506}
1507
718e3744 1508/* "no router bgp" commands. */
1ca2fd11
IR
1509DEFUN (no_router_bgp,
1510 no_router_bgp_cmd,
1511 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1512 NO_STR
1513 ROUTER_STR
1514 BGP_STR
1515 AS_STR
1516 BGP_INSTANCE_HELP_STR)
718e3744 1517{
4fd9919e 1518 int idx_asn = 3;
d62a17ae 1519 int idx_vrf = 5;
1ca2fd11 1520 as_t as;
4fd9919e 1521 struct bgp *bgp;
d62a17ae 1522 const char *name = NULL;
718e3744 1523
d62a17ae 1524 // "no router bgp" without an ASN
1525 if (argc == 3) {
1526 // Pending: Make VRF option available for ASN less config
8382083a 1527 bgp = bgp_get_default();
718e3744 1528
8382083a 1529 if (bgp == NULL) {
d62a17ae 1530 vty_out(vty, "%% No BGP process is configured\n");
1531 return CMD_WARNING_CONFIG_FAILED;
1532 }
7fb21a9f 1533
d62a17ae 1534 if (listcount(bm->bgp) > 1) {
996c9314 1535 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1536 return CMD_WARNING_CONFIG_FAILED;
1537 }
4fd9919e 1538
4fd9919e 1539 if (bgp->l3vni) {
be125e6f 1540 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1541 bgp->l3vni);
1542 return CMD_WARNING_CONFIG_FAILED;
1543 }
d62a17ae 1544 } else {
4fd9919e
IR
1545 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1546
1ca42c8d 1547 if (argc > 4) {
d62a17ae 1548 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1549 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1550 && strmatch(name, VRF_DEFAULT_NAME))
1551 name = NULL;
1552 }
7fb21a9f 1553
4fd9919e
IR
1554 /* Lookup bgp structure. */
1555 bgp = bgp_lookup(as, name);
1556 if (!bgp) {
1557 vty_out(vty, "%% Can't find BGP instance\n");
1558 return CMD_WARNING_CONFIG_FAILED;
1559 }
1560
1561 if (bgp->l3vni) {
1562 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1563 bgp->l3vni);
1564 return CMD_WARNING_CONFIG_FAILED;
1565 }
1566
1567 /* Cannot delete default instance if vrf instances exist */
1568 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1569 struct listnode *node;
1570 struct bgp *tmp_bgp;
1571
1572 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1573 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1574 continue;
1575 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1576 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1577 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1578 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1579 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1580 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1581 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1582 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1583 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1584 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1585 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1586 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1587 (bgp == bgp_get_evpn() &&
1588 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1589 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1590 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1591 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1592 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1593 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1594 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1595 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
f33bf7c0 1596 (hashcount(tmp_bgp->vnihash))) {
4fd9919e
IR
1597 vty_out(vty,
1598 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1599 return CMD_WARNING_CONFIG_FAILED;
1600 }
1601 }
1602 }
d62a17ae 1603 }
718e3744 1604
1ca2fd11 1605 bgp_delete(bgp);
718e3744 1606
1ca2fd11 1607 return CMD_SUCCESS;
718e3744 1608}
1609
425bd64b
PS
1610/* bgp session-dscp */
1611
1612DEFPY (bgp_session_dscp,
1613 bgp_session_dscp_cmd,
1614 "bgp session-dscp (0-63)$dscp",
1615 BGP_STR
1616 "Override default (C6) bgp TCP session DSCP value\n"
1617 "Manually configured dscp parameter\n")
1618{
1619 bm->tcp_dscp = dscp << 2;
1620
1621 return CMD_SUCCESS;
1622}
1623
1624DEFPY (no_bgp_session_dscp,
1625 no_bgp_session_dscp_cmd,
1626 "no bgp session-dscp [(0-63)]",
1627 NO_STR
1628 BGP_STR
1629 "Override default (C6) bgp TCP session DSCP value\n"
1630 "Manually configured dscp parameter\n")
1631{
1632 bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL;
1633
1634 return CMD_SUCCESS;
1635}
718e3744 1636
ff8a8a7a
CS
1637/* BGP router-id. */
1638
1ca2fd11
IR
1639DEFPY (bgp_router_id,
1640 bgp_router_id_cmd,
1641 "bgp router-id A.B.C.D",
1642 BGP_STR
1643 "Override configured router identifier\n"
1644 "Manually configured router identifier\n")
718e3744 1645{
1ca2fd11
IR
1646 VTY_DECLVAR_CONTEXT(bgp, bgp);
1647 bgp_router_id_static_set(bgp, router_id);
1648 return CMD_SUCCESS;
ff8a8a7a 1649}
718e3744 1650
1ca2fd11
IR
1651DEFPY (no_bgp_router_id,
1652 no_bgp_router_id_cmd,
1653 "no bgp router-id [A.B.C.D]",
1654 NO_STR
1655 BGP_STR
1656 "Override configured router identifier\n"
1657 "Manually configured router identifier\n")
ff8a8a7a 1658{
1ca2fd11 1659 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1660
1ca2fd11
IR
1661 if (router_id_str) {
1662 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1663 vty_out(vty, "%% BGP router-id doesn't match\n");
1664 return CMD_WARNING_CONFIG_FAILED;
1665 }
1666 }
718e3744 1667
1ca2fd11
IR
1668 router_id.s_addr = 0;
1669 bgp_router_id_static_set(bgp, router_id);
1670
1671 return CMD_SUCCESS;
ff8a8a7a 1672}
6b0655a2 1673
ed0e57e3 1674DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1675 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1676 NO_STR BGP_STR
1677 "Add community specific parameters\n"
1678 "Create an alias for a community\n"
1679 "Community (AA:BB or AA:BB:CC)\n"
1680 "Alias name\n")
1681{
8cfa1e78 1682 struct community_alias ca = {};
ed0e57e3
DA
1683 struct community_alias *lookup_community;
1684 struct community_alias *lookup_alias;
d13d137a
DA
1685 struct community *comm;
1686 struct lcommunity *lcomm;
1687 uint8_t invalid = 0;
ed0e57e3 1688
d13d137a
DA
1689 comm = community_str2com(community);
1690 if (!comm)
1691 invalid++;
1692 community_free(&comm);
1693
1694 lcomm = lcommunity_str2com(community);
1695 if (!lcomm)
1696 invalid++;
1697 lcommunity_free(&lcomm);
1698
1699 if (invalid > 1) {
ed0e57e3
DA
1700 vty_out(vty, "Invalid community format\n");
1701 return CMD_WARNING;
1702 }
1703
8cfa1e78
DA
1704 strlcpy(ca.community, community, sizeof(ca.community));
1705 strlcpy(ca.alias, alias_name, sizeof(ca.alias));
ed0e57e3 1706
8cfa1e78
DA
1707 lookup_community = bgp_ca_community_lookup(&ca);
1708 lookup_alias = bgp_ca_alias_lookup(&ca);
ed0e57e3
DA
1709
1710 if (no) {
8cfa1e78
DA
1711 bgp_ca_alias_delete(&ca);
1712 bgp_ca_community_delete(&ca);
ed0e57e3
DA
1713 } else {
1714 if (lookup_alias) {
1715 /* Lookup if community hash table has an item
1716 * with the same alias name.
1717 */
8cfa1e78
DA
1718 strlcpy(ca.community, lookup_alias->community,
1719 sizeof(ca.community));
1720 if (bgp_ca_community_lookup(&ca)) {
ed0e57e3
DA
1721 vty_out(vty,
1722 "community (%s) already has this alias (%s)\n",
1723 lookup_alias->community,
1724 lookup_alias->alias);
1725 return CMD_WARNING;
1726 }
8cfa1e78 1727 bgp_ca_alias_delete(&ca);
ed0e57e3
DA
1728 }
1729
8cfa1e78
DA
1730 if (lookup_community) {
1731 /* Lookup if alias hash table has an item
1732 * with the same community.
1733 */
1734 strlcpy(ca.alias, lookup_community->alias,
1735 sizeof(ca.alias));
1736 if (bgp_ca_alias_lookup(&ca)) {
1737 vty_out(vty,
1738 "alias (%s) already has this community (%s)\n",
1739 lookup_community->alias,
1740 lookup_community->community);
1741 return CMD_WARNING;
1742 }
1743 bgp_ca_community_delete(&ca);
1744 }
ed0e57e3 1745
8cfa1e78
DA
1746 bgp_ca_alias_insert(&ca);
1747 bgp_ca_community_insert(&ca);
ed0e57e3
DA
1748 }
1749
1750 return CMD_SUCCESS;
1751}
1752
9acb67cb
DS
1753DEFPY (bgp_global_suppress_fib_pending,
1754 bgp_global_suppress_fib_pending_cmd,
1755 "[no] bgp suppress-fib-pending",
1756 NO_STR
1757 BGP_STR
1758 "Advertise only routes that are programmed in kernel to peers globally\n")
1759{
1760 bm_wait_for_fib_set(!no);
1761
1762 return CMD_SUCCESS;
1763}
1764
c208c586
S
1765DEFPY (bgp_suppress_fib_pending,
1766 bgp_suppress_fib_pending_cmd,
1767 "[no] bgp suppress-fib-pending",
1768 NO_STR
1769 BGP_STR
1770 "Advertise only routes that are programmed in kernel to peers\n")
1771{
1772 VTY_DECLVAR_CONTEXT(bgp, bgp);
1773
1774 bgp_suppress_fib_pending_set(bgp, !no);
1775 return CMD_SUCCESS;
1776}
1777
1778
718e3744 1779/* BGP Cluster ID. */
1ca2fd11
IR
1780DEFUN (bgp_cluster_id,
1781 bgp_cluster_id_cmd,
1782 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1783 BGP_STR
1784 "Configure Route-Reflector Cluster-id\n"
1785 "Route-Reflector Cluster-id in IP address format\n"
1786 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1787{
1ca2fd11 1788 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1789 int idx_ipv4 = 2;
1ca2fd11
IR
1790 int ret;
1791 struct in_addr cluster;
1792
1793 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1794 if (!ret) {
1795 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1796 return CMD_WARNING_CONFIG_FAILED;
1797 }
718e3744 1798
1ca2fd11
IR
1799 bgp_cluster_id_set(bgp, &cluster);
1800 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1801
1ca2fd11 1802 return CMD_SUCCESS;
718e3744 1803}
1804
1ca2fd11
IR
1805DEFUN (no_bgp_cluster_id,
1806 no_bgp_cluster_id_cmd,
1807 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1808 NO_STR
1809 BGP_STR
1810 "Configure Route-Reflector Cluster-id\n"
1811 "Route-Reflector Cluster-id in IP address format\n"
1812 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1813{
1ca2fd11
IR
1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 bgp_cluster_id_unset(bgp);
1816 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1817
1ca2fd11 1818 return CMD_SUCCESS;
718e3744 1819}
1820
c163f297
DS
1821DEFPY (bgp_norib,
1822 bgp_norib_cmd,
1823 "bgp no-rib",
1824 BGP_STR
1825 "Disable BGP route installation to RIB (Zebra)\n")
1826{
1827 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1828 vty_out(vty,
1829 "%% No-RIB option is already set, nothing to do here.\n");
1830 return CMD_SUCCESS;
1831 }
1832
1833 bgp_option_norib_set_runtime();
1834
1835 return CMD_SUCCESS;
1836}
1837
1838DEFPY (no_bgp_norib,
1839 no_bgp_norib_cmd,
1840 "no bgp no-rib",
1841 NO_STR
1842 BGP_STR
1843 "Disable BGP route installation to RIB (Zebra)\n")
1844{
1845 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1846 vty_out(vty,
1847 "%% No-RIB option is not set, nothing to do here.\n");
1848 return CMD_SUCCESS;
1849 }
1850
1851 bgp_option_norib_unset_runtime();
1852
1853 return CMD_SUCCESS;
1854}
1855
e46723a5
DS
1856DEFPY (no_bgp_send_extra_data,
1857 no_bgp_send_extra_data_cmd,
1858 "[no] bgp send-extra-data zebra",
1859 NO_STR
1860 BGP_STR
1861 "Extra data to Zebra for display/use\n"
1862 "To zebra\n")
1863{
ec0acb80
DA
1864 if (no)
1865 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1866 else
1867 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1868
1869 return CMD_SUCCESS;
1870}
1871
1ca2fd11
IR
1872DEFUN (bgp_confederation_identifier,
1873 bgp_confederation_identifier_cmd,
1874 "bgp confederation identifier (1-4294967295)",
e9273987 1875 BGP_STR
1ca2fd11
IR
1876 "AS confederation parameters\n"
1877 "AS number\n"
1878 "Set routing domain confederation AS\n")
718e3744 1879{
1ca2fd11 1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1881 int idx_number = 3;
1ca2fd11 1882 as_t as;
718e3744 1883
1ca2fd11 1884 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1885
1ca2fd11 1886 bgp_confederation_id_set(bgp, as);
718e3744 1887
1ca2fd11 1888 return CMD_SUCCESS;
718e3744 1889}
1890
1ca2fd11
IR
1891DEFUN (no_bgp_confederation_identifier,
1892 no_bgp_confederation_identifier_cmd,
1893 "no bgp confederation identifier [(1-4294967295)]",
1894 NO_STR
e9273987 1895 BGP_STR
1ca2fd11
IR
1896 "AS confederation parameters\n"
1897 "AS number\n"
1898 "Set routing domain confederation AS\n")
ff8a8a7a 1899{
1ca2fd11
IR
1900 VTY_DECLVAR_CONTEXT(bgp, bgp);
1901 bgp_confederation_id_unset(bgp);
1902
1903 return CMD_SUCCESS;
ff8a8a7a
CS
1904}
1905
1ca2fd11
IR
1906DEFUN (bgp_confederation_peers,
1907 bgp_confederation_peers_cmd,
1908 "bgp confederation peers (1-4294967295)...",
e9273987 1909 BGP_STR
1ca2fd11
IR
1910 "AS confederation parameters\n"
1911 "Peer ASs in BGP confederation\n"
1912 AS_STR)
718e3744 1913{
1ca2fd11 1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1915 int idx_asn = 3;
1ca2fd11 1916 as_t as;
d62a17ae 1917 int i;
718e3744 1918
1ca2fd11
IR
1919 for (i = idx_asn; i < argc; i++) {
1920 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1921
1ca2fd11
IR
1922 if (bgp->as == as) {
1923 vty_out(vty,
1924 "%% Local member-AS not allowed in confed peer list\n");
1925 continue;
1926 }
1927
1928 bgp_confederation_peers_add(bgp, as);
1929 }
1930 return CMD_SUCCESS;
718e3744 1931}
1932
1ca2fd11
IR
1933DEFUN (no_bgp_confederation_peers,
1934 no_bgp_confederation_peers_cmd,
1935 "no bgp confederation peers (1-4294967295)...",
1936 NO_STR
e9273987 1937 BGP_STR
1ca2fd11
IR
1938 "AS confederation parameters\n"
1939 "Peer ASs in BGP confederation\n"
1940 AS_STR)
718e3744 1941{
1ca2fd11 1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1943 int idx_asn = 4;
1ca2fd11 1944 as_t as;
d62a17ae 1945 int i;
718e3744 1946
1ca2fd11
IR
1947 for (i = idx_asn; i < argc; i++) {
1948 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1949
1ca2fd11
IR
1950 bgp_confederation_peers_remove(bgp, as);
1951 }
1952 return CMD_SUCCESS;
718e3744 1953}
6b0655a2 1954
5e242b0d
DS
1955/**
1956 * Central routine for maximum-paths configuration.
1957 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1958 * @set: 1 for setting values, 0 for removing the max-paths config.
1959 */
585f1adc
IR
1960static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1961 const char *mpaths, uint16_t options,
1962 int set)
d62a17ae 1963{
585f1adc
IR
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 uint16_t maxpaths = 0;
d62a17ae 1966 int ret;
585f1adc
IR
1967 afi_t afi;
1968 safi_t safi;
1969
1970 afi = bgp_node_afi(vty);
1971 safi = bgp_node_safi(vty);
d62a17ae 1972
1973 if (set) {
585f1adc 1974 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1975 if (maxpaths > multipath_num) {
585f1adc 1976 vty_out(vty,
d62a17ae 1977 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1978 maxpaths, multipath_num);
1979 return CMD_WARNING_CONFIG_FAILED;
1980 }
1981 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1982 options);
1983 } else
1984 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1985
1986 if (ret < 0) {
585f1adc 1987 vty_out(vty,
d62a17ae 1988 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1989 (set == 1) ? "" : "un",
1990 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1991 maxpaths, afi, safi);
1992 return CMD_WARNING_CONFIG_FAILED;
1993 }
1994
1995 bgp_recalculate_all_bestpaths(bgp);
1996
1997 return CMD_SUCCESS;
165b5fff
JB
1998}
1999
1ca2fd11
IR
2000DEFUN (bgp_maxmed_admin,
2001 bgp_maxmed_admin_cmd,
2002 "bgp max-med administrative ",
2003 BGP_STR
2004 "Advertise routes with max-med\n"
2005 "Administratively applied, for an indefinite period\n")
abc920f8 2006{
1ca2fd11 2007 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 2008
1ca2fd11
IR
2009 bgp->v_maxmed_admin = 1;
2010 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 2011
1ca2fd11 2012 bgp_maxmed_update(bgp);
abc920f8 2013
1ca2fd11 2014 return CMD_SUCCESS;
ff8a8a7a
CS
2015}
2016
1ca2fd11
IR
2017DEFUN (bgp_maxmed_admin_medv,
2018 bgp_maxmed_admin_medv_cmd,
2019 "bgp max-med administrative (0-4294967295)",
2020 BGP_STR
2021 "Advertise routes with max-med\n"
2022 "Administratively applied, for an indefinite period\n"
2023 "Max MED value to be used\n")
abc920f8 2024{
1ca2fd11 2025 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2026 int idx_number = 3;
abc920f8 2027
1ca2fd11
IR
2028 bgp->v_maxmed_admin = 1;
2029 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 2030
1ca2fd11 2031 bgp_maxmed_update(bgp);
abc920f8 2032
1ca2fd11 2033 return CMD_SUCCESS;
abc920f8
DS
2034}
2035
1ca2fd11
IR
2036DEFUN (no_bgp_maxmed_admin,
2037 no_bgp_maxmed_admin_cmd,
2038 "no bgp max-med administrative [(0-4294967295)]",
2039 NO_STR
2040 BGP_STR
2041 "Advertise routes with max-med\n"
2042 "Administratively applied, for an indefinite period\n"
2043 "Max MED value to be used\n")
abc920f8 2044{
1ca2fd11
IR
2045 VTY_DECLVAR_CONTEXT(bgp, bgp);
2046 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
2047 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
2048 bgp_maxmed_update(bgp);
ff8a8a7a 2049
1ca2fd11 2050 return CMD_SUCCESS;
abc920f8
DS
2051}
2052
1ca2fd11
IR
2053DEFUN (bgp_maxmed_onstartup,
2054 bgp_maxmed_onstartup_cmd,
2055 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
2056 BGP_STR
2057 "Advertise routes with max-med\n"
2058 "Effective on a startup\n"
2059 "Time (seconds) period for max-med\n"
2060 "Max MED value to be used\n")
abc920f8 2061{
1ca2fd11 2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2063 int idx = 0;
4668a151 2064
9b01d289
DA
2065 if (argv_find(argv, argc, "(5-86400)", &idx))
2066 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2067 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 2068 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 2069 else
1ca2fd11 2070 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2071
1ca2fd11
IR
2072 bgp_maxmed_update(bgp);
2073
2074 return CMD_SUCCESS;
abc920f8
DS
2075}
2076
1ca2fd11
IR
2077DEFUN (no_bgp_maxmed_onstartup,
2078 no_bgp_maxmed_onstartup_cmd,
2079 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
2080 NO_STR
2081 BGP_STR
2082 "Advertise routes with max-med\n"
2083 "Effective on a startup\n"
2084 "Time (seconds) period for max-med\n"
2085 "Max MED value to be used\n")
abc920f8 2086{
1ca2fd11
IR
2087 VTY_DECLVAR_CONTEXT(bgp, bgp);
2088
2089 /* Cancel max-med onstartup if its on */
2090 if (bgp->t_maxmed_onstartup) {
c3aaa89a 2091 THREAD_OFF(bgp->t_maxmed_onstartup);
1ca2fd11
IR
2092 bgp->maxmed_onstartup_over = 1;
2093 }
abc920f8 2094
1ca2fd11
IR
2095 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2096 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2097
1ca2fd11
IR
2098 bgp_maxmed_update(bgp);
2099
2100 return CMD_SUCCESS;
abc920f8
DS
2101}
2102
d70583f7
D
2103static int bgp_global_update_delay_config_vty(struct vty *vty,
2104 uint16_t update_delay,
2105 uint16_t establish_wait)
2106{
2107 struct listnode *node, *nnode;
2108 struct bgp *bgp;
2109 bool vrf_cfg = false;
2110
2111 /*
2112 * See if update-delay is set per-vrf and warn user to delete it
2113 * Note that we only need to check this if this is the first time
2114 * setting the global config.
2115 */
2116 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2117 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2118 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2119 vty_out(vty,
2120 "%% update-delay configuration found in vrf %s\n",
2121 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2122 ? VRF_DEFAULT_NAME
2123 : bgp->name);
2124 vrf_cfg = true;
2125 }
2126 }
2127 }
2128
2129 if (vrf_cfg) {
2130 vty_out(vty,
2131 "%%Failed: global update-delay config not permitted\n");
2132 return CMD_WARNING;
2133 }
2134
2135 if (!establish_wait) { /* update-delay <delay> */
2136 bm->v_update_delay = update_delay;
2137 bm->v_establish_wait = bm->v_update_delay;
2138 } else {
2139 /* update-delay <delay> <establish-wait> */
2140 if (update_delay < establish_wait) {
2141 vty_out(vty,
2142 "%%Failed: update-delay less than the establish-wait!\n");
2143 return CMD_WARNING_CONFIG_FAILED;
2144 }
2145
2146 bm->v_update_delay = update_delay;
2147 bm->v_establish_wait = establish_wait;
2148 }
2149
2150 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2151 bgp->v_update_delay = bm->v_update_delay;
2152 bgp->v_establish_wait = bm->v_establish_wait;
2153 }
2154
2155 return CMD_SUCCESS;
2156}
2157
2158static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2159{
2160 struct listnode *node, *nnode;
2161 struct bgp *bgp;
2162
2163 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2164 bm->v_establish_wait = bm->v_update_delay;
2165
2166 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2167 bgp->v_update_delay = bm->v_update_delay;
2168 bgp->v_establish_wait = bm->v_establish_wait;
2169 }
2170
2171 return CMD_SUCCESS;
2172}
2173
2174static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2175 uint16_t establish_wait)
f188f2c4 2176{
d62a17ae 2177 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2178
d70583f7
D
2179 /* if configured globally, per-instance config is not allowed */
2180 if (bm->v_update_delay) {
2181 vty_out(vty,
2182 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2183 return CMD_WARNING_CONFIG_FAILED;
2184 }
2185
f188f2c4 2186
d70583f7 2187 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2188 {
2189 bgp->v_update_delay = update_delay;
2190 bgp->v_establish_wait = bgp->v_update_delay;
2191 return CMD_SUCCESS;
2192 }
f188f2c4 2193
d62a17ae 2194 /* update-delay <delay> <establish-wait> */
d62a17ae 2195 if (update_delay < establish_wait) {
2196 vty_out(vty,
2197 "%%Failed: update-delay less than the establish-wait!\n");
2198 return CMD_WARNING_CONFIG_FAILED;
2199 }
f188f2c4 2200
d62a17ae 2201 bgp->v_update_delay = update_delay;
2202 bgp->v_establish_wait = establish_wait;
f188f2c4 2203
d62a17ae 2204 return CMD_SUCCESS;
f188f2c4
DS
2205}
2206
d62a17ae 2207static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2208{
d62a17ae 2209 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2210
d70583f7
D
2211 /* If configured globally, cannot remove from one bgp instance */
2212 if (bm->v_update_delay) {
2213 vty_out(vty,
2214 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2215 return CMD_WARNING_CONFIG_FAILED;
2216 }
d62a17ae 2217 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2218 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2219
d62a17ae 2220 return CMD_SUCCESS;
f188f2c4
DS
2221}
2222
2b791107 2223void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2224{
d70583f7
D
2225 /* If configured globally, no need to display per-instance value */
2226 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2227 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2228 if (bgp->v_update_delay != bgp->v_establish_wait)
2229 vty_out(vty, " %d", bgp->v_establish_wait);
2230 vty_out(vty, "\n");
2231 }
f188f2c4
DS
2232}
2233
d70583f7
D
2234/* Global update-delay configuration */
2235DEFPY (bgp_global_update_delay,
2236 bgp_global_update_delay_cmd,
2237 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2238 BGP_STR
2239 "Force initial delay for best-path and updates for all bgp instances\n"
2240 "Max delay in seconds\n"
2241 "Establish wait in seconds\n")
2242{
2243 return bgp_global_update_delay_config_vty(vty, delay, wait);
2244}
f188f2c4 2245
d70583f7
D
2246/* Global update-delay deconfiguration */
2247DEFPY (no_bgp_global_update_delay,
2248 no_bgp_global_update_delay_cmd,
2249 "no bgp update-delay [(0-3600) [(1-3600)]]",
2250 NO_STR
2251 BGP_STR
f188f2c4 2252 "Force initial delay for best-path and updates\n"
d70583f7
D
2253 "Max delay in seconds\n"
2254 "Establish wait in seconds\n")
f188f2c4 2255{
d70583f7 2256 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2257}
2258
d70583f7
D
2259/* Update-delay configuration */
2260
2261DEFPY (bgp_update_delay,
2262 bgp_update_delay_cmd,
2263 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2264 "Force initial delay for best-path and updates\n"
d70583f7
D
2265 "Max delay in seconds\n"
2266 "Establish wait in seconds\n")
f188f2c4 2267{
d70583f7 2268 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2269}
2270
2271/* Update-delay deconfiguration */
d70583f7 2272DEFPY (no_bgp_update_delay,
f188f2c4 2273 no_bgp_update_delay_cmd,
838758ac
DW
2274 "no update-delay [(0-3600) [(1-3600)]]",
2275 NO_STR
f188f2c4 2276 "Force initial delay for best-path and updates\n"
d70583f7
D
2277 "Max delay in seconds\n"
2278 "Establish wait in seconds\n")
f188f2c4 2279{
d62a17ae 2280 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2281}
2282
5e242b0d 2283
1ca2fd11
IR
2284static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2285 bool set)
cb1faec9 2286{
1ca2fd11
IR
2287 VTY_DECLVAR_CONTEXT(bgp, bgp);
2288
8fa7732f
QY
2289 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2290 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2291
2292 return CMD_SUCCESS;
2293}
2294
1ca2fd11
IR
2295static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2296 bool set)
555e09d4 2297{
1ca2fd11
IR
2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
2299
8fa7732f
QY
2300 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2301 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2302
d62a17ae 2303 return CMD_SUCCESS;
cb1faec9
DS
2304}
2305
2b791107 2306void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2307{
555e09d4
QY
2308 uint32_t quanta =
2309 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2310 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2311 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2312}
2313
555e09d4
QY
2314void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2315{
2316 uint32_t quanta =
2317 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2318 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2319 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2320}
cb1faec9 2321
8fa7732f
QY
2322/* Packet quanta configuration
2323 *
2324 * XXX: The value set here controls the size of a stack buffer in the IO
2325 * thread. When changing these limits be careful to prevent stack overflow.
2326 *
2327 * Furthermore, the maximums used here should correspond to
2328 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2329 */
1ca2fd11
IR
2330DEFPY (bgp_wpkt_quanta,
2331 bgp_wpkt_quanta_cmd,
2332 "[no] write-quanta (1-64)$quanta",
2333 NO_STR
2334 "How many packets to write to peer socket per run\n"
2335 "Number of packets\n")
2336{
2337 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2338}
cb1faec9 2339
1ca2fd11
IR
2340DEFPY (bgp_rpkt_quanta,
2341 bgp_rpkt_quanta_cmd,
2342 "[no] read-quanta (1-10)$quanta",
2343 NO_STR
2344 "How many packets to read from peer socket per I/O cycle\n"
2345 "Number of packets\n")
2346{
2347 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2348}
2349
2b791107 2350void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2351{
37a333fe 2352 if (!bgp->heuristic_coalesce)
d62a17ae 2353 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2354}
2355
4668a151 2356
1ca2fd11
IR
2357DEFUN (bgp_coalesce_time,
2358 bgp_coalesce_time_cmd,
2359 "coalesce-time (0-4294967295)",
2360 "Subgroup coalesce timer\n"
2361 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2362{
1ca2fd11 2363 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2364
1ca2fd11 2365 int idx = 0;
9b01d289 2366
1ca2fd11 2367 bgp->heuristic_coalesce = false;
9b01d289
DA
2368
2369 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2370 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2371
1ca2fd11 2372 return CMD_SUCCESS;
3f9c7369
DS
2373}
2374
1ca2fd11
IR
2375DEFUN (no_bgp_coalesce_time,
2376 no_bgp_coalesce_time_cmd,
2377 "no coalesce-time (0-4294967295)",
2378 NO_STR
2379 "Subgroup coalesce timer\n"
2380 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2381{
1ca2fd11 2382 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2383
1ca2fd11
IR
2384 bgp->heuristic_coalesce = true;
2385 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2386 return CMD_SUCCESS;
3f9c7369
DS
2387}
2388
5e242b0d 2389/* Maximum-paths configuration */
585f1adc
IR
2390DEFUN (bgp_maxpaths,
2391 bgp_maxpaths_cmd,
2392 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2393 "Forward packets over multiple paths\n"
2394 "Number of paths\n")
5e242b0d 2395{
d62a17ae 2396 int idx_number = 1;
585f1adc
IR
2397 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2398 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2399}
2400
d62a17ae 2401ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2402 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2403 "Forward packets over multiple paths\n"
2404 "Number of paths\n")
596c17ba 2405
585f1adc
IR
2406DEFUN (bgp_maxpaths_ibgp,
2407 bgp_maxpaths_ibgp_cmd,
2408 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2409 "Forward packets over multiple paths\n"
2410 "iBGP-multipath\n"
2411 "Number of paths\n")
165b5fff 2412{
d62a17ae 2413 int idx_number = 2;
585f1adc
IR
2414 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2415 argv[idx_number]->arg, 0, 1);
5e242b0d 2416}
165b5fff 2417
d62a17ae 2418ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2419 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2420 "Forward packets over multiple paths\n"
2421 "iBGP-multipath\n"
2422 "Number of paths\n")
596c17ba 2423
585f1adc
IR
2424DEFUN (bgp_maxpaths_ibgp_cluster,
2425 bgp_maxpaths_ibgp_cluster_cmd,
2426 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2427 "Forward packets over multiple paths\n"
2428 "iBGP-multipath\n"
2429 "Number of paths\n"
2430 "Match the cluster length\n")
5e242b0d 2431{
d62a17ae 2432 int idx_number = 2;
aa53c036
DS
2433 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2434 argv[idx_number]->arg, true, 1);
165b5fff
JB
2435}
2436
d62a17ae 2437ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2438 "maximum-paths ibgp " CMD_RANGE_STR(
2439 1, MULTIPATH_NUM) " equal-cluster-length",
2440 "Forward packets over multiple paths\n"
2441 "iBGP-multipath\n"
2442 "Number of paths\n"
2443 "Match the cluster length\n")
596c17ba 2444
585f1adc
IR
2445DEFUN (no_bgp_maxpaths,
2446 no_bgp_maxpaths_cmd,
2447 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2448 NO_STR
2449 "Forward packets over multiple paths\n"
2450 "Number of paths\n")
165b5fff 2451{
585f1adc 2452 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2453}
2454
d62a17ae 2455ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2456 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2457 "Forward packets over multiple paths\n"
2458 "Number of paths\n")
596c17ba 2459
585f1adc
IR
2460DEFUN (no_bgp_maxpaths_ibgp,
2461 no_bgp_maxpaths_ibgp_cmd,
2462 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2463 NO_STR
2464 "Forward packets over multiple paths\n"
2465 "iBGP-multipath\n"
2466 "Number of paths\n"
2467 "Match the cluster length\n")
165b5fff 2468{
585f1adc 2469 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2470}
2471
d62a17ae 2472ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2473 "no maximum-paths ibgp [" CMD_RANGE_STR(
2474 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2475 NO_STR
2476 "Forward packets over multiple paths\n"
2477 "iBGP-multipath\n"
2478 "Number of paths\n"
2479 "Match the cluster length\n")
596c17ba 2480
dd65f45e
DL
2481static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2482 afi_t afi, safi_t safi)
165b5fff 2483{
00908b7a 2484 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2485 vty_out(vty, " maximum-paths %d\n",
2486 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2487 }
165b5fff 2488
00908b7a 2489 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2490 vty_out(vty, " maximum-paths ibgp %d",
2491 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2492 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2493 vty_out(vty, " equal-cluster-length");
2494 vty_out(vty, "\n");
2495 }
165b5fff 2496}
6b0655a2 2497
718e3744 2498/* BGP timers. */
2499
1ca2fd11
IR
2500DEFUN (bgp_timers,
2501 bgp_timers_cmd,
2502 "timers bgp (0-65535) (0-65535)",
2503 "Adjust routing timers\n"
2504 "BGP timers\n"
2505 "Keepalive interval\n"
2506 "Holdtime\n")
718e3744 2507{
1ca2fd11 2508 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2509 int idx_number = 2;
2510 int idx_number_2 = 3;
1ca2fd11
IR
2511 unsigned long keepalive = 0;
2512 unsigned long holdtime = 0;
718e3744 2513
1ca2fd11
IR
2514 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2515 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2516
1ca2fd11
IR
2517 /* Holdtime value check. */
2518 if (holdtime < 3 && holdtime != 0) {
2519 vty_out(vty,
2520 "%% hold time value must be either 0 or greater than 3\n");
2521 return CMD_WARNING_CONFIG_FAILED;
2522 }
718e3744 2523
1ca2fd11
IR
2524 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2525 BGP_DEFAULT_DELAYOPEN);
718e3744 2526
1ca2fd11 2527 return CMD_SUCCESS;
718e3744 2528}
2529
1ca2fd11
IR
2530DEFUN (no_bgp_timers,
2531 no_bgp_timers_cmd,
2532 "no timers bgp [(0-65535) (0-65535)]",
2533 NO_STR
2534 "Adjust routing timers\n"
2535 "BGP timers\n"
2536 "Keepalive interval\n"
2537 "Holdtime\n")
718e3744 2538{
1ca2fd11
IR
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2541 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2542
1ca2fd11 2543 return CMD_SUCCESS;
718e3744 2544}
2545
b042667a
TI
2546/* BGP minimum holdtime. */
2547
2548DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2549 "bgp minimum-holdtime (1-65535)",
2550 "BGP specific commands\n"
2551 "BGP minimum holdtime\n"
2552 "Seconds\n")
2553{
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555 int idx_number = 2;
2556 unsigned long min_holdtime;
2557
2558 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2559
2560 bgp->default_min_holdtime = min_holdtime;
2561
2562 return CMD_SUCCESS;
2563}
2564
2565DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2566 "no bgp minimum-holdtime [(1-65535)]",
2567 NO_STR
2568 "BGP specific commands\n"
2569 "BGP minimum holdtime\n"
2570 "Seconds\n")
2571{
2572 VTY_DECLVAR_CONTEXT(bgp, bgp);
2573
2574 bgp->default_min_holdtime = 0;
2575
2576 return CMD_SUCCESS;
2577}
ff8a8a7a 2578
1ca2fd11
IR
2579DEFUN (bgp_client_to_client_reflection,
2580 bgp_client_to_client_reflection_cmd,
2581 "bgp client-to-client reflection",
e9273987 2582 BGP_STR
1ca2fd11
IR
2583 "Configure client to client route reflection\n"
2584 "reflection of routes allowed\n")
718e3744 2585{
1ca2fd11
IR
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2588 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2589
1ca2fd11 2590 return CMD_SUCCESS;
718e3744 2591}
2592
1ca2fd11
IR
2593DEFUN (no_bgp_client_to_client_reflection,
2594 no_bgp_client_to_client_reflection_cmd,
2595 "no bgp client-to-client reflection",
2596 NO_STR
e9273987 2597 BGP_STR
1ca2fd11
IR
2598 "Configure client to client route reflection\n"
2599 "reflection of routes allowed\n")
718e3744 2600{
1ca2fd11
IR
2601 VTY_DECLVAR_CONTEXT(bgp, bgp);
2602 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2603 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2604
1ca2fd11 2605 return CMD_SUCCESS;
718e3744 2606}
2607
2608/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2609DEFUN (bgp_always_compare_med,
2610 bgp_always_compare_med_cmd,
2611 "bgp always-compare-med",
e9273987 2612 BGP_STR
1ca2fd11 2613 "Allow comparing MED from different neighbors\n")
718e3744 2614{
1ca2fd11
IR
2615 VTY_DECLVAR_CONTEXT(bgp, bgp);
2616 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2617 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2618
1ca2fd11 2619 return CMD_SUCCESS;
718e3744 2620}
2621
1ca2fd11
IR
2622DEFUN (no_bgp_always_compare_med,
2623 no_bgp_always_compare_med_cmd,
2624 "no bgp always-compare-med",
2625 NO_STR
e9273987 2626 BGP_STR
1ca2fd11 2627 "Allow comparing MED from different neighbors\n")
718e3744 2628{
1ca2fd11
IR
2629 VTY_DECLVAR_CONTEXT(bgp, bgp);
2630 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2631 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2632
1ca2fd11 2633 return CMD_SUCCESS;
2adac256
DA
2634}
2635
2adac256 2636
1ca2fd11
IR
2637DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2638 "bgp ebgp-requires-policy",
e9273987 2639 BGP_STR
1ca2fd11 2640 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2641{
1ca2fd11
IR
2642 VTY_DECLVAR_CONTEXT(bgp, bgp);
2643 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2644 return CMD_SUCCESS;
2adac256
DA
2645}
2646
1ca2fd11
IR
2647DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2648 "no bgp ebgp-requires-policy",
2649 NO_STR
e9273987 2650 BGP_STR
1ca2fd11 2651 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2652{
1ca2fd11
IR
2653 VTY_DECLVAR_CONTEXT(bgp, bgp);
2654 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2655 return CMD_SUCCESS;
ff8a8a7a 2656}
9dac9fc8 2657
1ca2fd11
IR
2658DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2659 "bgp suppress-duplicates",
e9273987 2660 BGP_STR
1ca2fd11 2661 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2662{
1ca2fd11
IR
2663 VTY_DECLVAR_CONTEXT(bgp, bgp);
2664 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2665 return CMD_SUCCESS;
9dac9fc8
DA
2666}
2667
1ca2fd11
IR
2668DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2669 "no bgp suppress-duplicates",
2670 NO_STR
e9273987 2671 BGP_STR
1ca2fd11 2672 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2673{
1ca2fd11
IR
2674 VTY_DECLVAR_CONTEXT(bgp, bgp);
2675 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2676 return CMD_SUCCESS;
9dac9fc8
DA
2677}
2678
fb29348a
DA
2679DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2680 "bgp reject-as-sets",
e9273987 2681 BGP_STR
fb29348a
DA
2682 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2683{
2684 VTY_DECLVAR_CONTEXT(bgp, bgp);
2685 struct listnode *node, *nnode;
2686 struct peer *peer;
2687
7f972cd8 2688 bgp->reject_as_sets = true;
fb29348a
DA
2689
2690 /* Reset existing BGP sessions to reject routes
2691 * with aspath containing AS_SET or AS_CONFED_SET.
2692 */
2693 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2694 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2695 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2696 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2697 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2698 }
2699 }
2700
2701 return CMD_SUCCESS;
2702}
2703
2704DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2705 "no bgp reject-as-sets",
2706 NO_STR
e9273987 2707 BGP_STR
fb29348a
DA
2708 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2709{
2710 VTY_DECLVAR_CONTEXT(bgp, bgp);
2711 struct listnode *node, *nnode;
2712 struct peer *peer;
2713
7f972cd8 2714 bgp->reject_as_sets = false;
fb29348a
DA
2715
2716 /* Reset existing BGP sessions to reject routes
2717 * with aspath containing AS_SET or AS_CONFED_SET.
2718 */
2719 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2720 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2721 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2722 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2723 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2724 }
2725 }
2726
2727 return CMD_SUCCESS;
2728}
9dac9fc8 2729
718e3744 2730/* "bgp deterministic-med" configuration. */
1ca2fd11 2731DEFUN (bgp_deterministic_med,
718e3744 2732 bgp_deterministic_med_cmd,
2733 "bgp deterministic-med",
e9273987 2734 BGP_STR
718e3744 2735 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2736{
1ca2fd11
IR
2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
2738
2739 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2740 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2741 bgp_recalculate_all_bestpaths(bgp);
2742 }
7aafcaca 2743
1ca2fd11 2744 return CMD_SUCCESS;
718e3744 2745}
2746
1ca2fd11 2747DEFUN (no_bgp_deterministic_med,
718e3744 2748 no_bgp_deterministic_med_cmd,
2749 "no bgp deterministic-med",
2750 NO_STR
e9273987 2751 BGP_STR
718e3744 2752 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2753{
1ca2fd11
IR
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755 int bestpath_per_as_used;
2756 afi_t afi;
2757 safi_t safi;
2758 struct peer *peer;
2759 struct listnode *node, *nnode;
2760
2761 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2762 bestpath_per_as_used = 0;
2763
2764 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2765 FOREACH_AFI_SAFI (afi, safi)
2766 if (bgp_addpath_dmed_required(
2767 peer->addpath_type[afi][safi])) {
2768 bestpath_per_as_used = 1;
2769 break;
2770 }
2771
2772 if (bestpath_per_as_used)
2773 break;
2774 }
2775
2776 if (bestpath_per_as_used) {
2777 vty_out(vty,
2778 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2779 return CMD_WARNING_CONFIG_FAILED;
2780 } else {
2781 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2782 bgp_recalculate_all_bestpaths(bgp);
2783 }
2784 }
d62a17ae 2785
1ca2fd11 2786 return CMD_SUCCESS;
718e3744 2787}
538621f2 2788
055679e9 2789/* "bgp graceful-restart mode" configuration. */
538621f2 2790DEFUN (bgp_graceful_restart,
2ba1fe69 2791 bgp_graceful_restart_cmd,
2792 "bgp graceful-restart",
e9273987 2793 BGP_STR
2ba1fe69 2794 GR_CMD
055679e9 2795 )
538621f2 2796{
055679e9 2797 int ret = BGP_GR_FAILURE;
2798
2799 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2800 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2801
d62a17ae 2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2803
2804 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2805
36235319
QY
2806 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2807 ret);
5cce3f05 2808
055679e9 2809 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2810 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2811 vty_out(vty,
2812 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2813 return bgp_vty_return(vty, ret);
538621f2 2814}
2815
2816DEFUN (no_bgp_graceful_restart,
2ba1fe69 2817 no_bgp_graceful_restart_cmd,
2818 "no bgp graceful-restart",
2819 NO_STR
e9273987 2820 BGP_STR
2ba1fe69 2821 NO_GR_CMD
055679e9 2822 )
538621f2 2823{
d62a17ae 2824 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2825
2826 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2827 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2828
2829 int ret = BGP_GR_FAILURE;
2830
2831 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2832
36235319
QY
2833 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2834 ret);
5cce3f05 2835
055679e9 2836 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2837 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2838 vty_out(vty,
2839 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2840
2841 return bgp_vty_return(vty, ret);
538621f2 2842}
2843
93406d87 2844DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2845 bgp_graceful_restart_stalepath_time_cmd,
2846 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2847 BGP_STR
2ba1fe69 2848 "Graceful restart capability parameters\n"
2849 "Set the max time to hold onto restarting peer's stale paths\n"
2850 "Delay value (seconds)\n")
93406d87 2851{
d62a17ae 2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
2853 int idx_number = 3;
d7c0a89a 2854 uint32_t stalepath;
93406d87 2855
d62a17ae 2856 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2857 bgp->stalepath_time = stalepath;
2858 return CMD_SUCCESS;
93406d87 2859}
2860
eb6f1b41 2861DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2862 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2863 "bgp graceful-restart restart-time (0-4095)",
e9273987 2864 BGP_STR
2ba1fe69 2865 "Graceful restart capability parameters\n"
2866 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2867 "Delay value (seconds)\n")
eb6f1b41 2868{
d62a17ae 2869 VTY_DECLVAR_CONTEXT(bgp, bgp);
2870 int idx_number = 3;
d7c0a89a 2871 uint32_t restart;
eb6f1b41 2872
d62a17ae 2873 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2874 bgp->restart_time = restart;
2875 return CMD_SUCCESS;
eb6f1b41
PG
2876}
2877
cfd47646 2878DEFUN (bgp_graceful_restart_select_defer_time,
2879 bgp_graceful_restart_select_defer_time_cmd,
2880 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2881 BGP_STR
cfd47646 2882 "Graceful restart capability parameters\n"
2883 "Set the time to defer the BGP route selection after restart\n"
2884 "Delay value (seconds, 0 - disable)\n")
2885{
2886 VTY_DECLVAR_CONTEXT(bgp, bgp);
2887 int idx_number = 3;
2888 uint32_t defer_time;
2889
2890 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2891 bgp->select_defer_time = defer_time;
2892 if (defer_time == 0)
892fedb6 2893 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2894 else
892fedb6 2895 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2896
2897 return CMD_SUCCESS;
2898}
2899
93406d87 2900DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2901 no_bgp_graceful_restart_stalepath_time_cmd,
2902 "no bgp graceful-restart stalepath-time [(1-4095)]",
2903 NO_STR
e9273987 2904 BGP_STR
2ba1fe69 2905 "Graceful restart capability parameters\n"
2906 "Set the max time to hold onto restarting peer's stale paths\n"
2907 "Delay value (seconds)\n")
93406d87 2908{
d62a17ae 2909 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2910
d62a17ae 2911 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2912 return CMD_SUCCESS;
93406d87 2913}
2914
eb6f1b41 2915DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2916 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2917 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2918 NO_STR
e9273987 2919 BGP_STR
2ba1fe69 2920 "Graceful restart capability parameters\n"
2921 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2922 "Delay value (seconds)\n")
eb6f1b41 2923{
d62a17ae 2924 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2925
d62a17ae 2926 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2927 return CMD_SUCCESS;
eb6f1b41
PG
2928}
2929
cfd47646 2930DEFUN (no_bgp_graceful_restart_select_defer_time,
2931 no_bgp_graceful_restart_select_defer_time_cmd,
2932 "no bgp graceful-restart select-defer-time [(0-3600)]",
2933 NO_STR
e9273987 2934 BGP_STR
cfd47646 2935 "Graceful restart capability parameters\n"
2936 "Set the time to defer the BGP route selection after restart\n"
2937 "Delay value (seconds)\n")
2938{
2939 VTY_DECLVAR_CONTEXT(bgp, bgp);
2940
2941 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2942 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2943
2944 return CMD_SUCCESS;
2945}
2946
43fc21b3 2947DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2948 bgp_graceful_restart_preserve_fw_cmd,
2949 "bgp graceful-restart preserve-fw-state",
e9273987 2950 BGP_STR
2ba1fe69 2951 "Graceful restart capability parameters\n"
2952 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2953{
d62a17ae 2954 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2955 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2956 return CMD_SUCCESS;
43fc21b3
JC
2957}
2958
2959DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2960 no_bgp_graceful_restart_preserve_fw_cmd,
2961 "no bgp graceful-restart preserve-fw-state",
2962 NO_STR
e9273987 2963 BGP_STR
2ba1fe69 2964 "Graceful restart capability parameters\n"
2965 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2966{
d62a17ae 2967 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2968 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2969 return CMD_SUCCESS;
43fc21b3
JC
2970}
2971
f2ca5c5b
DA
2972DEFPY (bgp_graceful_restart_notification,
2973 bgp_graceful_restart_notification_cmd,
2974 "[no$no] bgp graceful-restart notification",
2975 NO_STR
2976 BGP_STR
2977 "Graceful restart capability parameters\n"
2978 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2979{
2980 VTY_DECLVAR_CONTEXT(bgp, bgp);
2981
2982 if (no)
2983 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2984 else
2985 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2986
2987 return CMD_SUCCESS;
2988}
2989
1ae314be
DA
2990DEFPY (bgp_administrative_reset,
2991 bgp_administrative_reset_cmd,
2992 "[no$no] bgp hard-administrative-reset",
2993 NO_STR
2994 BGP_STR
2995 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2996{
2997 VTY_DECLVAR_CONTEXT(bgp, bgp);
2998
2999 if (no)
3000 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3001 else
3002 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
3003
3004 return CMD_SUCCESS;
3005}
3006
055679e9 3007DEFUN (bgp_graceful_restart_disable,
2ba1fe69 3008 bgp_graceful_restart_disable_cmd,
3009 "bgp graceful-restart-disable",
e9273987 3010 BGP_STR
2ba1fe69 3011 GR_DISABLE)
055679e9 3012{
3013 int ret = BGP_GR_FAILURE;
3014
3015 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3016 zlog_debug(
2ba1fe69 3017 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 3018
055679e9 3019 VTY_DECLVAR_CONTEXT(bgp, bgp);
3020
3021 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
3022
dc95985f 3023 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
3024 bgp->peer, ret);
5cce3f05 3025
055679e9 3026 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3027 zlog_debug(
2ba1fe69 3028 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 3029 vty_out(vty,
3030 "Graceful restart configuration changed, reset all peers to take effect\n");
3031
055679e9 3032 return bgp_vty_return(vty, ret);
3033}
3034
3035DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 3036 no_bgp_graceful_restart_disable_cmd,
3037 "no bgp graceful-restart-disable",
3038 NO_STR
e9273987 3039 BGP_STR
2ba1fe69 3040 NO_GR_DISABLE
055679e9 3041 )
3042{
3043 VTY_DECLVAR_CONTEXT(bgp, bgp);
3044
3045 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3046 zlog_debug(
2ba1fe69 3047 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 3048
3049 int ret = BGP_GR_FAILURE;
3050
3051 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
3052
36235319
QY
3053 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
3054 ret);
5cce3f05 3055
055679e9 3056 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3057 zlog_debug(
2ba1fe69 3058 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 3059 vty_out(vty,
3060 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 3061
3062 return bgp_vty_return(vty, ret);
3063}
3064
3065DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 3066 bgp_neighbor_graceful_restart_set_cmd,
3067 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3068 NEIGHBOR_STR
3069 NEIGHBOR_ADDR_STR2
3070 GR_NEIGHBOR_CMD
055679e9 3071 )
3072{
3073 int idx_peer = 1;
3074 struct peer *peer;
3075 int ret = BGP_GR_FAILURE;
3076
dc95985f 3077 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3078
055679e9 3079 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3080 zlog_debug(
2ba1fe69 3081 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 3082
055679e9 3083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3084 if (!peer)
3085 return CMD_WARNING_CONFIG_FAILED;
3086
3087 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3088
dc95985f 3089 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3090 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3091
3092 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3093 zlog_debug(
2ba1fe69 3094 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3095 vty_out(vty,
3096 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3097
3098 return bgp_vty_return(vty, ret);
3099}
3100
3101DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3102 no_bgp_neighbor_graceful_restart_set_cmd,
3103 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3104 NO_STR
3105 NEIGHBOR_STR
3106 NEIGHBOR_ADDR_STR2
3107 NO_GR_NEIGHBOR_CMD
055679e9 3108 )
3109{
3110 int idx_peer = 2;
3111 int ret = BGP_GR_FAILURE;
3112 struct peer *peer;
3113
dc95985f 3114 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3115
055679e9 3116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3117 if (!peer)
3118 return CMD_WARNING_CONFIG_FAILED;
3119
3120 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3121 zlog_debug(
2ba1fe69 3122 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3123
3124 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3125
dc95985f 3126 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3127 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3128
3129 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3130 zlog_debug(
2ba1fe69 3131 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3132 vty_out(vty,
3133 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3134
3135 return bgp_vty_return(vty, ret);
3136}
3137
3138DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3139 bgp_neighbor_graceful_restart_helper_set_cmd,
3140 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3141 NEIGHBOR_STR
3142 NEIGHBOR_ADDR_STR2
3143 GR_NEIGHBOR_HELPER_CMD
055679e9 3144 )
3145{
3146 int idx_peer = 1;
3147 struct peer *peer;
3148 int ret = BGP_GR_FAILURE;
3149
dc95985f 3150 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3151
055679e9 3152 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3153 zlog_debug(
2ba1fe69 3154 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3155
055679e9 3156 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3157
055679e9 3158 if (!peer)
3159 return CMD_WARNING_CONFIG_FAILED;
3160
3161
3162 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3163
dc95985f 3164 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3165 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3166
055679e9 3167 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3168 zlog_debug(
2ba1fe69 3169 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3170 vty_out(vty,
3171 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3172
3173 return bgp_vty_return(vty, ret);
3174}
3175
3176DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3177 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3178 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3179 NO_STR
3180 NEIGHBOR_STR
3181 NEIGHBOR_ADDR_STR2
3182 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3183 )
3184{
3185 int idx_peer = 2;
3186 int ret = BGP_GR_FAILURE;
3187 struct peer *peer;
3188
dc95985f 3189 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3190
055679e9 3191 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3192 if (!peer)
3193 return CMD_WARNING_CONFIG_FAILED;
3194
3195 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3196 zlog_debug(
2ba1fe69 3197 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3198
36235319 3199 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3200
dc95985f 3201 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3202 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3203
3204 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3205 zlog_debug(
2ba1fe69 3206 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3207 vty_out(vty,
3208 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3209
3210 return bgp_vty_return(vty, ret);
3211}
3212
3213DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3214 bgp_neighbor_graceful_restart_disable_set_cmd,
3215 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3216 NEIGHBOR_STR
3217 NEIGHBOR_ADDR_STR2
3218 GR_NEIGHBOR_DISABLE_CMD
055679e9 3219 )
3220{
3221 int idx_peer = 1;
3222 struct peer *peer;
3223 int ret = BGP_GR_FAILURE;
3224
dc95985f 3225 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3226
055679e9 3227 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3228 zlog_debug(
2ba1fe69 3229 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3230
3231 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3232 if (!peer)
3233 return CMD_WARNING_CONFIG_FAILED;
3234
36235319 3235 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3236
3237 if (peer->bgp->t_startup)
3238 bgp_peer_gr_flags_update(peer);
3239
dc95985f 3240 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3241 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3242
055679e9 3243 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3244 zlog_debug(
2ba1fe69 3245 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3246 vty_out(vty,
3247 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3248
3249 return bgp_vty_return(vty, ret);
3250}
3251
3252DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3253 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3254 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3255 NO_STR
3256 NEIGHBOR_STR
3257 NEIGHBOR_ADDR_STR2
3258 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3259 )
3260{
3261 int idx_peer = 2;
3262 int ret = BGP_GR_FAILURE;
3263 struct peer *peer;
3264
dc95985f 3265 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3266
055679e9 3267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3268 if (!peer)
3269 return CMD_WARNING_CONFIG_FAILED;
3270
3271 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3272 zlog_debug(
2ba1fe69 3273 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3274
3275 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3276
dc95985f 3277 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3278 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3279
3280 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3281 zlog_debug(
2ba1fe69 3282 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3283 vty_out(vty,
3284 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3285
3286 return bgp_vty_return(vty, ret);
3287}
3288
d6e3c15b 3289DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3290 bgp_graceful_restart_disable_eor_cmd,
3291 "bgp graceful-restart disable-eor",
e9273987 3292 BGP_STR
d6e3c15b 3293 "Graceful restart configuration parameters\n"
3294 "Disable EOR Check\n")
3295{
3296 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3297 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3298
d6e3c15b 3299 return CMD_SUCCESS;
3300}
3301
3302DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3303 no_bgp_graceful_restart_disable_eor_cmd,
3304 "no bgp graceful-restart disable-eor",
3305 NO_STR
e9273987 3306 BGP_STR
d6e3c15b 3307 "Graceful restart configuration parameters\n"
3308 "Disable EOR Check\n")
3309{
3310 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3311 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3312
3313 return CMD_SUCCESS;
3314}
3315
3316DEFUN (bgp_graceful_restart_rib_stale_time,
3317 bgp_graceful_restart_rib_stale_time_cmd,
3318 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3319 BGP_STR
dc95985f 3320 "Graceful restart configuration parameters\n"
3321 "Specify the stale route removal timer in rib\n"
3322 "Delay value (seconds)\n")
3323{
3324 VTY_DECLVAR_CONTEXT(bgp, bgp);
3325 int idx_number = 3;
3326 uint32_t stale_time;
3327
3328 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3329 bgp->rib_stale_time = stale_time;
3330 /* Send the stale timer update message to RIB */
3331 if (bgp_zebra_stale_timer_update(bgp))
3332 return CMD_WARNING;
3333
3334 return CMD_SUCCESS;
3335}
3336
3337DEFUN (no_bgp_graceful_restart_rib_stale_time,
3338 no_bgp_graceful_restart_rib_stale_time_cmd,
3339 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3340 NO_STR
e9273987 3341 BGP_STR
dc95985f 3342 "Graceful restart configuration parameters\n"
3343 "Specify the stale route removal timer in rib\n"
3344 "Delay value (seconds)\n")
3345{
3346 VTY_DECLVAR_CONTEXT(bgp, bgp);
3347
3348 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3349 /* Send the stale timer update message to RIB */
3350 if (bgp_zebra_stale_timer_update(bgp))
3351 return CMD_WARNING;
3352
d6e3c15b 3353 return CMD_SUCCESS;
3354}
3355
8606be87 3356DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3357 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3358 BGP_STR
8606be87
DA
3359 "Enable Long-lived Graceful Restart\n"
3360 "Specifies maximum time to wait before purging long-lived stale routes\n"
3361 "Stale time value (seconds)\n")
3362{
3363 VTY_DECLVAR_CONTEXT(bgp, bgp);
3364
3365 uint32_t llgr_stale_time;
3366
3367 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3368 bgp->llgr_stale_time = llgr_stale_time;
3369
3370 return CMD_SUCCESS;
3371}
3372
3373DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3374 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3375 NO_STR BGP_STR
3376 "Enable Long-lived Graceful Restart\n"
3377 "Specifies maximum time to wait before purging long-lived stale routes\n"
3378 "Stale time value (seconds)\n")
3379{
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381
3382 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3383
3384 return CMD_SUCCESS;
3385}
3386
1ca2fd11
IR
3387static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3388 struct bgp *bgp)
05bd726c 3389{
3390 bgp_static_redo_import_check(bgp);
3391 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3392 bgp_clear_star_soft_out(vty, bgp->name);
3393 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3394}
3395
3396static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3397{
3398 struct listnode *node, *nnode;
3399 struct bgp *bgp;
3400 bool vrf_cfg = false;
3401
3402 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3403 return CMD_SUCCESS;
3404
3405 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3406 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3407 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3408 vty_out(vty,
3409 "%% graceful-shutdown configuration found in vrf %s\n",
3410 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3411 VRF_DEFAULT_NAME : bgp->name);
3412 vrf_cfg = true;
3413 }
3414 }
3415
3416 if (vrf_cfg) {
3417 vty_out(vty,
3418 "%%Failed: global graceful-shutdown not permitted\n");
3419 return CMD_WARNING;
3420 }
3421
3422 /* Set flag globally */
3423 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3424
3425 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3426 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3427 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3428
3429 return CMD_SUCCESS;
3430}
3431
3432static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3433{
3434 struct listnode *node, *nnode;
3435 struct bgp *bgp;
3436
3437 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3438 return CMD_SUCCESS;
3439
3440 /* Unset flag globally */
3441 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3442
3443 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3444 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3445 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3446
3447 return CMD_SUCCESS;
3448}
3449
7f323236
DW
3450/* "bgp graceful-shutdown" configuration */
3451DEFUN (bgp_graceful_shutdown,
3452 bgp_graceful_shutdown_cmd,
3453 "bgp graceful-shutdown",
3454 BGP_STR
3455 "Graceful shutdown parameters\n")
3456{
05bd726c 3457 if (vty->node == CONFIG_NODE)
3458 return bgp_global_graceful_shutdown_config_vty(vty);
3459
1ca2fd11 3460 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3461
1ca2fd11
IR
3462 /* if configured globally, per-instance config is not allowed */
3463 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3464 vty_out(vty,
3465 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3466 return CMD_WARNING_CONFIG_FAILED;
3467 }
3468
3469 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3470 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3471 bgp_initiate_graceful_shut_unshut(vty, bgp);
3472 }
3473
3474 return CMD_SUCCESS;
7f323236
DW
3475}
3476
1ca2fd11 3477DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3478 no_bgp_graceful_shutdown_cmd,
3479 "no bgp graceful-shutdown",
3480 NO_STR
3481 BGP_STR
3482 "Graceful shutdown parameters\n")
3483{
05bd726c 3484 if (vty->node == CONFIG_NODE)
3485 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3486
1ca2fd11 3487 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3488
1ca2fd11
IR
3489 /* If configured globally, cannot remove from one bgp instance */
3490 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3491 vty_out(vty,
3492 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3493 return CMD_WARNING_CONFIG_FAILED;
3494 }
7f323236 3495
1ca2fd11
IR
3496 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3497 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3498 bgp_initiate_graceful_shut_unshut(vty, bgp);
3499 }
3500
3501 return CMD_SUCCESS;
7f323236
DW
3502}
3503
718e3744 3504/* "bgp fast-external-failover" configuration. */
1ca2fd11 3505DEFUN (bgp_fast_external_failover,
718e3744 3506 bgp_fast_external_failover_cmd,
3507 "bgp fast-external-failover",
3508 BGP_STR
3509 "Immediately reset session if a link to a directly connected external peer goes down\n")
3510{
1ca2fd11
IR
3511 VTY_DECLVAR_CONTEXT(bgp, bgp);
3512 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3513 return CMD_SUCCESS;
718e3744 3514}
3515
1ca2fd11 3516DEFUN (no_bgp_fast_external_failover,
718e3744 3517 no_bgp_fast_external_failover_cmd,
3518 "no bgp fast-external-failover",
3519 NO_STR
3520 BGP_STR
3521 "Immediately reset session if a link to a directly connected external peer goes down\n")
3522{
1ca2fd11
IR
3523 VTY_DECLVAR_CONTEXT(bgp, bgp);
3524 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3525 return CMD_SUCCESS;
718e3744 3526}
6b0655a2 3527
718e3744 3528/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3529DEFUN (bgp_bestpath_compare_router_id,
3530 bgp_bestpath_compare_router_id_cmd,
3531 "bgp bestpath compare-routerid",
e9273987 3532 BGP_STR
1ca2fd11
IR
3533 "Change the default bestpath selection\n"
3534 "Compare router-id for identical EBGP paths\n")
718e3744 3535{
1ca2fd11
IR
3536 VTY_DECLVAR_CONTEXT(bgp, bgp);
3537 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3538 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3539
1ca2fd11 3540 return CMD_SUCCESS;
718e3744 3541}
3542
1ca2fd11
IR
3543DEFUN (no_bgp_bestpath_compare_router_id,
3544 no_bgp_bestpath_compare_router_id_cmd,
3545 "no bgp bestpath compare-routerid",
3546 NO_STR
e9273987 3547 BGP_STR
1ca2fd11
IR
3548 "Change the default bestpath selection\n"
3549 "Compare router-id for identical EBGP paths\n")
718e3744 3550{
1ca2fd11
IR
3551 VTY_DECLVAR_CONTEXT(bgp, bgp);
3552 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3553 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3554
1ca2fd11 3555 return CMD_SUCCESS;
718e3744 3556}
6b0655a2 3557
718e3744 3558/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3559DEFUN (bgp_bestpath_aspath_ignore,
3560 bgp_bestpath_aspath_ignore_cmd,
3561 "bgp bestpath as-path ignore",
e9273987 3562 BGP_STR
1ca2fd11
IR
3563 "Change the default bestpath selection\n"
3564 "AS-path attribute\n"
3565 "Ignore as-path length in selecting a route\n")
718e3744 3566{
1ca2fd11
IR
3567 VTY_DECLVAR_CONTEXT(bgp, bgp);
3568 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3569 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3570
1ca2fd11 3571 return CMD_SUCCESS;
718e3744 3572}
3573
1ca2fd11
IR
3574DEFUN (no_bgp_bestpath_aspath_ignore,
3575 no_bgp_bestpath_aspath_ignore_cmd,
3576 "no bgp bestpath as-path ignore",
3577 NO_STR
e9273987 3578 BGP_STR
1ca2fd11
IR
3579 "Change the default bestpath selection\n"
3580 "AS-path attribute\n"
3581 "Ignore as-path length in selecting a route\n")
718e3744 3582{
1ca2fd11
IR
3583 VTY_DECLVAR_CONTEXT(bgp, bgp);
3584 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3585 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3586
1ca2fd11 3587 return CMD_SUCCESS;
718e3744 3588}
6b0655a2 3589
6811845b 3590/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3591DEFUN (bgp_bestpath_aspath_confed,
6811845b 3592 bgp_bestpath_aspath_confed_cmd,
3593 "bgp bestpath as-path confed",
e9273987 3594 BGP_STR
6811845b 3595 "Change the default bestpath selection\n"
3596 "AS-path attribute\n"
3597 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3598{
1ca2fd11
IR
3599 VTY_DECLVAR_CONTEXT(bgp, bgp);
3600 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3601 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3602
1ca2fd11 3603 return CMD_SUCCESS;
6811845b 3604}
3605
1ca2fd11 3606DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3607 no_bgp_bestpath_aspath_confed_cmd,
3608 "no bgp bestpath as-path confed",
3609 NO_STR
e9273987 3610 BGP_STR
6811845b 3611 "Change the default bestpath selection\n"
3612 "AS-path attribute\n"
3613 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3614{
1ca2fd11
IR
3615 VTY_DECLVAR_CONTEXT(bgp, bgp);
3616 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3617 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3618
1ca2fd11 3619 return CMD_SUCCESS;
6811845b 3620}
6b0655a2 3621
2fdd455c 3622/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3623DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3624 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3625 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3626 BGP_STR
16fc1eec
DS
3627 "Change the default bestpath selection\n"
3628 "AS-path attribute\n"
3629 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3630 "Generate an AS_SET\n"
16fc1eec
DS
3631 "Do not generate an AS_SET\n")
3632{
1ca2fd11 3633 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3634 int idx = 0;
1ca2fd11 3635 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3636
1ca2fd11
IR
3637 /* no-as-set is now the default behavior so we can silently
3638 * ignore it */
d62a17ae 3639 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3640 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3641 else
1ca2fd11 3642 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3643
1ca2fd11
IR
3644 bgp_recalculate_all_bestpaths(bgp);
3645
3646 return CMD_SUCCESS;
16fc1eec
DS
3647}
3648
1ca2fd11 3649DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3650 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3651 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3652 NO_STR
e9273987 3653 BGP_STR
16fc1eec
DS
3654 "Change the default bestpath selection\n"
3655 "AS-path attribute\n"
3656 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3657 "Generate an AS_SET\n"
16fc1eec
DS
3658 "Do not generate an AS_SET\n")
3659{
1ca2fd11
IR
3660 VTY_DECLVAR_CONTEXT(bgp, bgp);
3661 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3662 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3663 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3664
1ca2fd11 3665 return CMD_SUCCESS;
2fdd455c 3666}
6b0655a2 3667
ee88563a
JM
3668/* "bgp bestpath peer-type multipath-relax" configuration. */
3669DEFUN(bgp_bestpath_peer_type_multipath_relax,
3670 bgp_bestpath_peer_type_multipath_relax_cmd,
3671 "bgp bestpath peer-type multipath-relax",
3672 BGP_STR
3673 "Change the default bestpath selection\n"
3674 "Peer type\n"
3675 "Allow load sharing across routes learned from different peer types\n")
3676{
3677 VTY_DECLVAR_CONTEXT(bgp, bgp);
3678 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3679 bgp_recalculate_all_bestpaths(bgp);
3680
3681 return CMD_SUCCESS;
3682}
3683
3684DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3685 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3686 "no bgp bestpath peer-type multipath-relax",
3687 NO_STR BGP_STR
3688 "Change the default bestpath selection\n"
3689 "Peer type\n"
3690 "Allow load sharing across routes learned from different peer types\n")
3691{
3692 VTY_DECLVAR_CONTEXT(bgp, bgp);
3693 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3694 bgp_recalculate_all_bestpaths(bgp);
3695
3696 return CMD_SUCCESS;
3697}
3698
848973c7 3699/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3700DEFUN (bgp_log_neighbor_changes,
3701 bgp_log_neighbor_changes_cmd,
3702 "bgp log-neighbor-changes",
e9273987 3703 BGP_STR
1ca2fd11 3704 "Log neighbor up/down and reset reason\n")
848973c7 3705{
1ca2fd11
IR
3706 VTY_DECLVAR_CONTEXT(bgp, bgp);
3707 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3708 return CMD_SUCCESS;
848973c7 3709}
3710
1ca2fd11
IR
3711DEFUN (no_bgp_log_neighbor_changes,
3712 no_bgp_log_neighbor_changes_cmd,
3713 "no bgp log-neighbor-changes",
3714 NO_STR
e9273987 3715 BGP_STR
1ca2fd11 3716 "Log neighbor up/down and reset reason\n")
848973c7 3717{
1ca2fd11
IR
3718 VTY_DECLVAR_CONTEXT(bgp, bgp);
3719 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3720 return CMD_SUCCESS;
848973c7 3721}
6b0655a2 3722
718e3744 3723/* "bgp bestpath med" configuration. */
1ca2fd11 3724DEFUN (bgp_bestpath_med,
718e3744 3725 bgp_bestpath_med_cmd,
2d8c1a4d 3726 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3727 BGP_STR
718e3744 3728 "Change the default bestpath selection\n"
3729 "MED attribute\n"
3730 "Compare MED among confederation paths\n"
838758ac
DW
3731 "Treat missing MED as the least preferred one\n"
3732 "Treat missing MED as the least preferred one\n"
3733 "Compare MED among confederation paths\n")
718e3744 3734{
1ca2fd11 3735 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3736
1ca2fd11 3737 int idx = 0;
d62a17ae 3738 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3739 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3740 idx = 0;
3741 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3742 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3743
1ca2fd11 3744 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3745
1ca2fd11 3746 return CMD_SUCCESS;
718e3744 3747}
3748
1ca2fd11 3749DEFUN (no_bgp_bestpath_med,
718e3744 3750 no_bgp_bestpath_med_cmd,
2d8c1a4d 3751 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3752 NO_STR
e9273987 3753 BGP_STR
718e3744 3754 "Change the default bestpath selection\n"
3755 "MED attribute\n"
3756 "Compare MED among confederation paths\n"
3a2d747c
QY
3757 "Treat missing MED as the least preferred one\n"
3758 "Treat missing MED as the least preferred one\n"
3759 "Compare MED among confederation paths\n")
718e3744 3760{
1ca2fd11 3761 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3762
1ca2fd11 3763 int idx = 0;
d62a17ae 3764 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3765 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3766 idx = 0;
3767 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3768 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3769
3770 bgp_recalculate_all_bestpaths(bgp);
718e3744 3771
1ca2fd11 3772 return CMD_SUCCESS;
718e3744 3773}
3774
f7e1c681 3775/* "bgp bestpath bandwidth" configuration. */
3776DEFPY (bgp_bestpath_bw,
3777 bgp_bestpath_bw_cmd,
ad36d216 3778 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3779 BGP_STR
f7e1c681 3780 "Change the default bestpath selection\n"
3781 "Link Bandwidth attribute\n"
3782 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3783 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3784 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3785{
3786 VTY_DECLVAR_CONTEXT(bgp, bgp);
3787 afi_t afi;
3788 safi_t safi;
3789
ad36d216
DS
3790 if (!bw_cfg) {
3791 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3792 return CMD_ERR_INCOMPLETE;
f7e1c681 3793 }
ad36d216
DS
3794 if (!strcmp(bw_cfg, "ignore"))
3795 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3796 else if (!strcmp(bw_cfg, "skip-missing"))
3797 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3798 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3799 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3800 else
3801 return CMD_ERR_NO_MATCH;
f7e1c681 3802
3803 /* This config is used in route install, so redo that. */
3804 FOREACH_AFI_SAFI (afi, safi) {
3805 if (!bgp_fibupd_safi(safi))
3806 continue;
3807 bgp_zebra_announce_table(bgp, afi, safi);
3808 }
3809
3810 return CMD_SUCCESS;
3811}
3812
ad36d216
DS
3813DEFPY (no_bgp_bestpath_bw,
3814 no_bgp_bestpath_bw_cmd,
3815 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3816 NO_STR
e9273987 3817 BGP_STR
ad36d216
DS
3818 "Change the default bestpath selection\n"
3819 "Link Bandwidth attribute\n"
3820 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3821 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3822 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3823{
3824 VTY_DECLVAR_CONTEXT(bgp, bgp);
3825 afi_t afi;
3826 safi_t safi;
3827
3828 bgp->lb_handling = BGP_LINK_BW_ECMP;
3829
3830 /* This config is used in route install, so redo that. */
3831 FOREACH_AFI_SAFI (afi, safi) {
3832 if (!bgp_fibupd_safi(safi))
3833 continue;
3834 bgp_zebra_announce_table(bgp, afi, safi);
3835 }
3836 return CMD_SUCCESS;
3837}
3838
b16bcbba 3839DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3840 "[no] bgp default <ipv4-unicast|"
3841 "ipv4-multicast|"
3842 "ipv4-vpn|"
3843 "ipv4-labeled-unicast|"
3844 "ipv4-flowspec|"
3845 "ipv6-unicast|"
3846 "ipv6-multicast|"
3847 "ipv6-vpn|"
3848 "ipv6-labeled-unicast|"
3849 "ipv6-flowspec|"
3850 "l2vpn-evpn>$afi_safi",
b16bcbba 3851 NO_STR
e9273987 3852 BGP_STR
e84c59af 3853 "Configure BGP defaults\n"
b16bcbba 3854 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3855 "Activate ipv4-multicast for a peer by default\n"
3856 "Activate ipv4-vpn for a peer by default\n"
3857 "Activate ipv4-labeled-unicast for a peer by default\n"
3858 "Activate ipv4-flowspec for a peer by default\n"
3859 "Activate ipv6-unicast for a peer by default\n"
3860 "Activate ipv6-multicast for a peer by default\n"
3861 "Activate ipv6-vpn for a peer by default\n"
3862 "Activate ipv6-labeled-unicast for a peer by default\n"
3863 "Activate ipv6-flowspec for a peer by default\n"
3864 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3865{
3866 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3867 char afi_safi_str[strlen(afi_safi) + 1];
3868 char *afi_safi_str_tok;
e84c59af 3869
b16bcbba
TA
3870 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3871 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3872 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3873 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3874 safi_t safi;
e84c59af 3875
d880a643
DS
3876 /*
3877 * Impossible situation but making coverity happy
3878 */
3879 assert(afi != AFI_MAX);
3880
38d11af5
TA
3881 if (strmatch(safi_str, "labeled"))
3882 safi = bgp_vty_safi_from_str("labeled-unicast");
3883 else
3884 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba 3885
f609bcd6 3886 assert(safi != SAFI_MAX);
b16bcbba
TA
3887 if (no)
3888 bgp->default_af[afi][safi] = false;
38d11af5
TA
3889 else {
3890 if ((safi == SAFI_LABELED_UNICAST
3891 && bgp->default_af[afi][SAFI_UNICAST])
3892 || (safi == SAFI_UNICAST
3893 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3894 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3895 else
3896 bgp->default_af[afi][safi] = true;
3897 }
718e3744 3898
d62a17ae 3899 return CMD_SUCCESS;
718e3744 3900}
6b0655a2 3901
04b6bdc0 3902/* Display hostname in certain command outputs */
1ca2fd11 3903DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3904 bgp_default_show_hostname_cmd,
3905 "bgp default show-hostname",
e9273987 3906 BGP_STR
04b6bdc0 3907 "Configure BGP defaults\n"
0437e105 3908 "Show hostname in certain command outputs\n")
04b6bdc0 3909{
1ca2fd11
IR
3910 VTY_DECLVAR_CONTEXT(bgp, bgp);
3911 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3912 return CMD_SUCCESS;
ff8a8a7a
CS
3913}
3914
1ca2fd11
IR
3915DEFUN (no_bgp_default_show_hostname,
3916 no_bgp_default_show_hostname_cmd,
3917 "no bgp default show-hostname",
3918 NO_STR
e9273987 3919 BGP_STR
1ca2fd11
IR
3920 "Configure BGP defaults\n"
3921 "Show hostname in certain command outputs\n")
ff8a8a7a 3922{
1ca2fd11
IR
3923 VTY_DECLVAR_CONTEXT(bgp, bgp);
3924 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3925 return CMD_SUCCESS;
04b6bdc0
DW
3926}
3927
aef999a2 3928/* Display hostname in certain command outputs */
1d80f243
IR
3929DEFUN (bgp_default_show_nexthop_hostname,
3930 bgp_default_show_nexthop_hostname_cmd,
3931 "bgp default show-nexthop-hostname",
e9273987 3932 BGP_STR
1d80f243
IR
3933 "Configure BGP defaults\n"
3934 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3935{
1ca2fd11
IR
3936 VTY_DECLVAR_CONTEXT(bgp, bgp);
3937 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3938 return CMD_SUCCESS;
aef999a2
DA
3939}
3940
3941DEFUN (no_bgp_default_show_nexthop_hostname,
3942 no_bgp_default_show_nexthop_hostname_cmd,
3943 "no bgp default show-nexthop-hostname",
3944 NO_STR
e9273987 3945 BGP_STR
aef999a2
DA
3946 "Configure BGP defaults\n"
3947 "Show hostname for nexthop in certain command outputs\n")
3948{
1ca2fd11
IR
3949 VTY_DECLVAR_CONTEXT(bgp, bgp);
3950 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3951 return CMD_SUCCESS;
aef999a2
DA
3952}
3953
8233ef81 3954/* "bgp network import-check" configuration. */
1ca2fd11
IR
3955DEFUN (bgp_network_import_check,
3956 bgp_network_import_check_cmd,
3957 "bgp network import-check",
e9273987 3958 BGP_STR
1ca2fd11
IR
3959 "BGP network command\n"
3960 "Check BGP network route exists in IGP\n")
718e3744 3961{
1ca2fd11
IR
3962 VTY_DECLVAR_CONTEXT(bgp, bgp);
3963 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3964 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3965 bgp_static_redo_import_check(bgp);
3966 }
078430f6 3967
1ca2fd11 3968 return CMD_SUCCESS;
718e3744 3969}
3970
d62a17ae 3971ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3972 "bgp network import-check exact",
e9273987 3973 BGP_STR
d62a17ae 3974 "BGP network command\n"
3975 "Check BGP network route exists in IGP\n"
3976 "Match route precisely\n")
8233ef81 3977
1ca2fd11
IR
3978DEFUN (no_bgp_network_import_check,
3979 no_bgp_network_import_check_cmd,
3980 "no bgp network import-check",
3981 NO_STR
e9273987 3982 BGP_STR
1ca2fd11
IR
3983 "BGP network command\n"
3984 "Check BGP network route exists in IGP\n")
718e3744 3985{
1ca2fd11
IR
3986 VTY_DECLVAR_CONTEXT(bgp, bgp);
3987 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3988 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3989 bgp_static_redo_import_check(bgp);
3990 }
6b0655a2 3991
1ca2fd11 3992 return CMD_SUCCESS;
ff8a8a7a 3993}
718e3744 3994
1ca2fd11
IR
3995DEFUN (bgp_default_local_preference,
3996 bgp_default_local_preference_cmd,
3997 "bgp default local-preference (0-4294967295)",
e9273987 3998 BGP_STR
1ca2fd11
IR
3999 "Configure BGP defaults\n"
4000 "local preference (higher=more preferred)\n"
4001 "Configure default local preference value\n")
ff8a8a7a 4002{
1ca2fd11 4003 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4004 int idx_number = 3;
1ca2fd11 4005 uint32_t local_pref;
718e3744 4006
1ca2fd11 4007 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 4008
1ca2fd11
IR
4009 bgp_default_local_preference_set(bgp, local_pref);
4010 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 4011
1ca2fd11 4012 return CMD_SUCCESS;
718e3744 4013}
4014
1ca2fd11
IR
4015DEFUN (no_bgp_default_local_preference,
4016 no_bgp_default_local_preference_cmd,
4017 "no bgp default local-preference [(0-4294967295)]",
4018 NO_STR
e9273987 4019 BGP_STR
1ca2fd11
IR
4020 "Configure BGP defaults\n"
4021 "local preference (higher=more preferred)\n"
4022 "Configure default local preference value\n")
ff8a8a7a 4023{
1ca2fd11
IR
4024 VTY_DECLVAR_CONTEXT(bgp, bgp);
4025 bgp_default_local_preference_unset(bgp);
4026 bgp_clear_star_soft_in(vty, bgp->name);
4027
4028 return CMD_SUCCESS;
ff8a8a7a 4029}
6b0655a2 4030
ff8a8a7a 4031
1ca2fd11
IR
4032DEFUN (bgp_default_subgroup_pkt_queue_max,
4033 bgp_default_subgroup_pkt_queue_max_cmd,
4034 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 4035 BGP_STR
1ca2fd11
IR
4036 "Configure BGP defaults\n"
4037 "subgroup-pkt-queue-max\n"
4038 "Configure subgroup packet queue max\n")
8bd9d948 4039{
1ca2fd11 4040 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4041 int idx_number = 3;
1ca2fd11 4042 uint32_t max_size;
3f9c7369 4043
1ca2fd11 4044 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 4045
1ca2fd11 4046 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 4047
1ca2fd11 4048 return CMD_SUCCESS;
8bd9d948
DS
4049}
4050
1ca2fd11
IR
4051DEFUN (no_bgp_default_subgroup_pkt_queue_max,
4052 no_bgp_default_subgroup_pkt_queue_max_cmd,
4053 "no bgp default subgroup-pkt-queue-max [(20-100)]",
4054 NO_STR
e9273987 4055 BGP_STR
1ca2fd11
IR
4056 "Configure BGP defaults\n"
4057 "subgroup-pkt-queue-max\n"
4058 "Configure subgroup packet queue max\n")
ff8a8a7a 4059{
1ca2fd11
IR
4060 VTY_DECLVAR_CONTEXT(bgp, bgp);
4061 bgp_default_subgroup_pkt_queue_max_unset(bgp);
4062 return CMD_SUCCESS;
ff8a8a7a 4063}
813d4307 4064
8bd9d948 4065
1ca2fd11
IR
4066DEFUN (bgp_rr_allow_outbound_policy,
4067 bgp_rr_allow_outbound_policy_cmd,
4068 "bgp route-reflector allow-outbound-policy",
e9273987 4069 BGP_STR
1ca2fd11
IR
4070 "Allow modifications made by out route-map\n"
4071 "on ibgp neighbors\n")
ff8a8a7a 4072{
1ca2fd11 4073 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 4074
1ca2fd11
IR
4075 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4076 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4077 update_group_announce_rrclients(bgp);
4078 bgp_clear_star_soft_out(vty, bgp->name);
4079 }
8bd9d948 4080
1ca2fd11
IR
4081 return CMD_SUCCESS;
4082}
ff8a8a7a 4083
1ca2fd11
IR
4084DEFUN (no_bgp_rr_allow_outbound_policy,
4085 no_bgp_rr_allow_outbound_policy_cmd,
4086 "no bgp route-reflector allow-outbound-policy",
4087 NO_STR
e9273987 4088 BGP_STR
1ca2fd11
IR
4089 "Allow modifications made by out route-map\n"
4090 "on ibgp neighbors\n")
8bd9d948 4091{
1ca2fd11 4092 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 4093
1ca2fd11
IR
4094 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4095 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4096 update_group_announce_rrclients(bgp);
4097 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4098 }
8bd9d948 4099
1ca2fd11 4100 return CMD_SUCCESS;
8bd9d948
DS
4101}
4102
1ca2fd11
IR
4103DEFUN (bgp_listen_limit,
4104 bgp_listen_limit_cmd,
4105 "bgp listen limit (1-65535)",
e9273987 4106 BGP_STR
1ca2fd11
IR
4107 "BGP Dynamic Neighbors listen commands\n"
4108 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4109 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4110{
1ca2fd11 4111 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4112 int idx_number = 3;
1ca2fd11
IR
4113 int listen_limit;
4114
4115 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4116
1ca2fd11 4117 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4118
1ca2fd11 4119 return CMD_SUCCESS;
f14e6fdb
DS
4120}
4121
1ca2fd11
IR
4122DEFUN (no_bgp_listen_limit,
4123 no_bgp_listen_limit_cmd,
4124 "no bgp listen limit [(1-65535)]",
4125 NO_STR
e9273987 4126 BGP_STR
1ca2fd11
IR
4127 "BGP Dynamic Neighbors listen commands\n"
4128 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4129 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4130{
1ca2fd11
IR
4131 VTY_DECLVAR_CONTEXT(bgp, bgp);
4132 bgp_listen_limit_unset(bgp);
4133 return CMD_SUCCESS;
f14e6fdb
DS
4134}
4135
4136
20eb8864 4137/*
4138 * Check if this listen range is already configured. Check for exact
4139 * match or overlap based on input.
4140 */
d62a17ae 4141static struct peer_group *listen_range_exists(struct bgp *bgp,
4142 struct prefix *range, int exact)
4143{
4144 struct listnode *node, *nnode;
4145 struct listnode *node1, *nnode1;
4146 struct peer_group *group;
4147 struct prefix *lr;
4148 afi_t afi;
4149 int match;
4150
4151 afi = family2afi(range->family);
4152 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4153 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4154 lr)) {
4155 if (exact)
4156 match = prefix_same(range, lr);
4157 else
4158 match = (prefix_match(range, lr)
4159 || prefix_match(lr, range));
4160 if (match)
4161 return group;
4162 }
4163 }
4164
4165 return NULL;
20eb8864 4166}
4167
f14e6fdb
DS
4168DEFUN (bgp_listen_range,
4169 bgp_listen_range_cmd,
d7b9898c 4170 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4171 BGP_STR
d7fa34c1
QY
4172 "Configure BGP dynamic neighbors listen range\n"
4173 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4174 NEIGHBOR_ADDR_STR
4175 "Member of the peer-group\n"
4176 "Peer-group name\n")
f14e6fdb 4177{
d62a17ae 4178 VTY_DECLVAR_CONTEXT(bgp, bgp);
4179 struct prefix range;
4180 struct peer_group *group, *existing_group;
4181 afi_t afi;
4182 int ret;
4183 int idx = 0;
4184
4185 argv_find(argv, argc, "A.B.C.D/M", &idx);
4186 argv_find(argv, argc, "X:X::X:X/M", &idx);
4187 char *prefix = argv[idx]->arg;
d7b9898c 4188 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4189 char *peergroup = argv[idx]->arg;
4190
4191 /* Convert IP prefix string to struct prefix. */
4192 ret = str2prefix(prefix, &range);
4193 if (!ret) {
4194 vty_out(vty, "%% Malformed listen range\n");
4195 return CMD_WARNING_CONFIG_FAILED;
4196 }
4197
4198 afi = family2afi(range.family);
4199
4200 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4201 vty_out(vty,
4202 "%% Malformed listen range (link-local address)\n");
4203 return CMD_WARNING_CONFIG_FAILED;
4204 }
4205
4206 apply_mask(&range);
4207
4208 /* Check if same listen range is already configured. */
4209 existing_group = listen_range_exists(bgp, &range, 1);
4210 if (existing_group) {
4211 if (strcmp(existing_group->name, peergroup) == 0)
4212 return CMD_SUCCESS;
4213 else {
4214 vty_out(vty,
4215 "%% Same listen range is attached to peer-group %s\n",
4216 existing_group->name);
4217 return CMD_WARNING_CONFIG_FAILED;
4218 }
4219 }
4220
4221 /* Check if an overlapping listen range exists. */
4222 if (listen_range_exists(bgp, &range, 0)) {
4223 vty_out(vty,
4224 "%% Listen range overlaps with existing listen range\n");
4225 return CMD_WARNING_CONFIG_FAILED;
4226 }
4227
4228 group = peer_group_lookup(bgp, peergroup);
4229 if (!group) {
4230 vty_out(vty, "%% Configure the peer-group first\n");
4231 return CMD_WARNING_CONFIG_FAILED;
4232 }
4233
4234 ret = peer_group_listen_range_add(group, &range);
4235 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4236}
4237
4238DEFUN (no_bgp_listen_range,
4239 no_bgp_listen_range_cmd,
d7b9898c 4240 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4241 NO_STR
e9273987 4242 BGP_STR
d7fa34c1
QY
4243 "Unconfigure BGP dynamic neighbors listen range\n"
4244 "Unconfigure BGP dynamic neighbors listen range\n"
4245 NEIGHBOR_ADDR_STR
4246 "Member of the peer-group\n"
4247 "Peer-group name\n")
f14e6fdb 4248{
d62a17ae 4249 VTY_DECLVAR_CONTEXT(bgp, bgp);
4250 struct prefix range;
4251 struct peer_group *group;
4252 afi_t afi;
4253 int ret;
4254 int idx = 0;
4255
4256 argv_find(argv, argc, "A.B.C.D/M", &idx);
4257 argv_find(argv, argc, "X:X::X:X/M", &idx);
4258 char *prefix = argv[idx]->arg;
21d88a71 4259 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4260 char *peergroup = argv[idx]->arg;
4261
4262 /* Convert IP prefix string to struct prefix. */
4263 ret = str2prefix(prefix, &range);
4264 if (!ret) {
4265 vty_out(vty, "%% Malformed listen range\n");
4266 return CMD_WARNING_CONFIG_FAILED;
4267 }
4268
4269 afi = family2afi(range.family);
4270
4271 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4272 vty_out(vty,
4273 "%% Malformed listen range (link-local address)\n");
4274 return CMD_WARNING_CONFIG_FAILED;
4275 }
4276
4277 apply_mask(&range);
4278
4279 group = peer_group_lookup(bgp, peergroup);
4280 if (!group) {
4281 vty_out(vty, "%% Peer-group does not exist\n");
4282 return CMD_WARNING_CONFIG_FAILED;
4283 }
4284
4285 ret = peer_group_listen_range_del(group, &range);
4286 return bgp_vty_return(vty, ret);
4287}
4288
2b791107 4289void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4290{
4291 struct peer_group *group;
4292 struct listnode *node, *nnode, *rnode, *nrnode;
4293 struct prefix *range;
4294 afi_t afi;
d62a17ae 4295
4296 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4297 vty_out(vty, " bgp listen limit %d\n",
4298 bgp->dynamic_neighbors_limit);
4299
4300 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4301 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4302 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4303 nrnode, range)) {
d62a17ae 4304 vty_out(vty,
2dbe669b
DA
4305 " bgp listen range %pFX peer-group %s\n",
4306 range, group->name);
d62a17ae 4307 }
4308 }
4309 }
f14e6fdb
DS
4310}
4311
4312
1ca2fd11
IR
4313DEFUN (bgp_disable_connected_route_check,
4314 bgp_disable_connected_route_check_cmd,
4315 "bgp disable-ebgp-connected-route-check",
e9273987 4316 BGP_STR
1ca2fd11 4317 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4318{
1ca2fd11
IR
4319 VTY_DECLVAR_CONTEXT(bgp, bgp);
4320 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4321 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4322
1ca2fd11 4323 return CMD_SUCCESS;
907f92c8
DS
4324}
4325
1ca2fd11
IR
4326DEFUN (no_bgp_disable_connected_route_check,
4327 no_bgp_disable_connected_route_check_cmd,
4328 "no bgp disable-ebgp-connected-route-check",
4329 NO_STR
e9273987 4330 BGP_STR
1ca2fd11 4331 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4332{
1ca2fd11
IR
4333 VTY_DECLVAR_CONTEXT(bgp, bgp);
4334 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4335 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4336
1ca2fd11 4337 return CMD_SUCCESS;
d62a17ae 4338}
4339
4340
28c6e247
IR
4341static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4342 const char *as_str)
4343{
4344 VTY_DECLVAR_CONTEXT(bgp, bgp);
4345 int ret;
4346 as_t as;
4347 int as_type = AS_SPECIFIED;
4348 union sockunion su;
4349
4350 if (as_str[0] == 'i') {
4351 as = 0;
4352 as_type = AS_INTERNAL;
4353 } else if (as_str[0] == 'e') {
4354 as = 0;
4355 as_type = AS_EXTERNAL;
4356 } else {
4357 /* Get AS number. */
4358 as = strtoul(as_str, NULL, 10);
4359 }
4360
4361 /* If peer is peer group or interface peer, call proper function. */
4362 ret = str2sockunion(peer_str, &su);
4363 if (ret < 0) {
4364 struct peer *peer;
4365
4366 /* Check if existing interface peer */
4367 peer = peer_lookup_by_conf_if(bgp, peer_str);
4368
4369 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4370
4371 /* if not interface peer, check peer-group settings */
4372 if (ret < 0 && !peer) {
4373 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4374 if (ret < 0) {
4375 vty_out(vty,
4376 "%% Create the peer-group or interface first\n");
4377 return CMD_WARNING_CONFIG_FAILED;
4378 }
4379 return CMD_SUCCESS;
4380 }
4381 } else {
4382 if (peer_address_self_check(bgp, &su)) {
4383 vty_out(vty,
4384 "%% Can not configure the local system as neighbor\n");
4385 return CMD_WARNING_CONFIG_FAILED;
4386 }
4387 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4388 }
4389
28c6e247
IR
4390 return bgp_vty_return(vty, ret);
4391}
4392
1ca2fd11
IR
4393DEFUN (bgp_default_shutdown,
4394 bgp_default_shutdown_cmd,
4395 "[no] bgp default shutdown",
4396 NO_STR
4397 BGP_STR
4398 "Configure BGP defaults\n"
4399 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4400{
1ca2fd11
IR
4401 VTY_DECLVAR_CONTEXT(bgp, bgp);
4402 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4403 return CMD_SUCCESS;
f26845f9
QY
4404}
4405
736b68f3
DS
4406DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4407 BGP_STR
9ddf4b81 4408 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4409 "Add a shutdown message (RFC 8203)\n"
4410 "Shutdown message\n")
9cf59432 4411{
736b68f3 4412 char *msgstr = NULL;
8389c83a 4413
9cf59432
DS
4414 VTY_DECLVAR_CONTEXT(bgp, bgp);
4415
8389c83a 4416 if (argc > 3)
f80e35b6 4417 msgstr = argv_concat(argv, argc, 3);
8389c83a 4418
b776f48c
DA
4419 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4420 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4421 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4422 return CMD_WARNING_CONFIG_FAILED;
4423 }
4424
8389c83a
DS
4425 bgp_shutdown_enable(bgp, msgstr);
4426 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4427
4428 return CMD_SUCCESS;
4429}
4430
736b68f3 4431DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4432 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4433{
4434 VTY_DECLVAR_CONTEXT(bgp, bgp);
4435
4436 bgp_shutdown_enable(bgp, NULL);
4437
4438 return CMD_SUCCESS;
4439}
8389c83a 4440
736b68f3 4441DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4442 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4443{
4444 VTY_DECLVAR_CONTEXT(bgp, bgp);
4445
4446 bgp_shutdown_disable(bgp);
4447
4448 return CMD_SUCCESS;
4449}
4450
9ddf4b81 4451ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4452 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4453 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4454 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4455
28c6e247
IR
4456DEFUN (neighbor_remote_as,
4457 neighbor_remote_as_cmd,
4458 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "Specify a BGP neighbor\n"
4462 AS_STR
4463 "Internal BGP peer\n"
4464 "External BGP peer\n")
718e3744 4465{
d62a17ae 4466 int idx_peer = 1;
4467 int idx_remote_as = 3;
28c6e247
IR
4468 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4469 argv[idx_remote_as]->arg);
d62a17ae 4470}
8666265e
DS
4471
4472DEFPY (bgp_allow_martian,
4473 bgp_allow_martian_cmd,
4474 "[no]$no bgp allow-martian-nexthop",
4475 NO_STR
4476 BGP_STR
4477 "Allow Martian nexthops to be received in the NLRI from a peer\n")
4478{
4479 VTY_DECLVAR_CONTEXT(bgp, bgp);
4480
4481 if (no)
4482 bgp->allow_martian = false;
4483 else
4484 bgp->allow_martian = true;
4485
4486 return CMD_SUCCESS;
4487}
4488
f852eb98
PG
4489/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4490 * sessions do not wait for hold timer expiry to bring down the sessions
4491 * when nexthop becomes unreachable
4492 */
4493DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4494 BGP_STR "Fast convergence for bgp sessions\n")
4495{
4496 VTY_DECLVAR_CONTEXT(bgp, bgp);
4497 bgp->fast_convergence = true;
4498
4499 return CMD_SUCCESS;
4500}
4501
4502DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4503 "no bgp fast-convergence",
4504 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4505{
4506 VTY_DECLVAR_CONTEXT(bgp, bgp);
4507 bgp->fast_convergence = false;
4508
4509 return CMD_SUCCESS;
4510}
d62a17ae 4511
28c6e247
IR
4512static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4513 int v6only,
4514 const char *peer_group_name,
4515 const char *as_str)
d62a17ae 4516{
28c6e247
IR
4517 VTY_DECLVAR_CONTEXT(bgp, bgp);
4518 as_t as = 0;
4519 int as_type = AS_UNSPECIFIED;
d62a17ae 4520 struct peer *peer;
4521 struct peer_group *group;
4522 int ret = 0;
d62a17ae 4523
4524 group = peer_group_lookup(bgp, conf_if);
4525
4526 if (group) {
28c6e247
IR
4527 vty_out(vty, "%% Name conflict with peer-group \n");
4528 return CMD_WARNING_CONFIG_FAILED;
4529 }
4530
4531 if (as_str) {
4532 if (as_str[0] == 'i') {
4533 as_type = AS_INTERNAL;
4534 } else if (as_str[0] == 'e') {
4535 as_type = AS_EXTERNAL;
4536 } else {
4537 /* Get AS number. */
4538 as = strtoul(as_str, NULL, 10);
4539 as_type = AS_SPECIFIED;
4540 }
d62a17ae 4541 }
4542
4543 peer = peer_lookup_by_conf_if(bgp, conf_if);
4544 if (peer) {
28c6e247 4545 if (as_str)
e84c59af 4546 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4547 } else {
e84c59af
DA
4548 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4549 NULL);
d62a17ae 4550
4551 if (!peer) {
28c6e247
IR
4552 vty_out(vty, "%% BGP failed to create peer\n");
4553 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4554 }
4555
4556 if (v6only)
527de3dc 4557 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4558
4559 /* Request zebra to initiate IPv6 RAs on this interface. We do
4560 * this
4561 * any unnumbered peer in order to not worry about run-time
4562 * transitions
4563 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4564 * address
4565 * gets deleted later etc.)
4566 */
4567 if (peer->ifp)
4568 bgp_zebra_initiate_radv(bgp, peer);
4569 }
4570
4571 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4572 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4573 if (v6only)
527de3dc 4574 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4575 else
527de3dc 4576 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4577
4578 /* v6only flag changed. Reset bgp seesion */
4579 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4580 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4581 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4582 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4583 } else
4584 bgp_session_reset(peer);
4585 }
4586
9fb964de
PM
4587 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4588 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4589 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4590 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4591 }
d62a17ae 4592
4593 if (peer_group_name) {
4594 group = peer_group_lookup(bgp, peer_group_name);
4595 if (!group) {
28c6e247
IR
4596 vty_out(vty, "%% Configure the peer-group first\n");
4597 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4598 }
4599
8395c1f8 4600 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4601 }
4602
28c6e247 4603 return bgp_vty_return(vty, ret);
a80beece
DS
4604}
4605
28c6e247
IR
4606DEFUN (neighbor_interface_config,
4607 neighbor_interface_config_cmd,
4608 "neighbor WORD interface [peer-group PGNAME]",
4609 NEIGHBOR_STR
4610 "Interface name or neighbor tag\n"
4611 "Enable BGP on interface\n"
4612 "Member of the peer-group\n"
4613 "Peer-group name\n")
4c48cf63 4614{
d62a17ae 4615 int idx_word = 1;
4616 int idx_peer_group_word = 4;
f4b8ec07 4617
d62a17ae 4618 if (argc > idx_peer_group_word)
28c6e247
IR
4619 return peer_conf_interface_get(
4620 vty, argv[idx_word]->arg, 0,
4621 argv[idx_peer_group_word]->arg, NULL);
4622 else
4623 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4624 NULL, NULL);
4c48cf63
DW
4625}
4626
28c6e247
IR
4627DEFUN (neighbor_interface_config_v6only,
4628 neighbor_interface_config_v6only_cmd,
4629 "neighbor WORD interface v6only [peer-group PGNAME]",
4630 NEIGHBOR_STR
4631 "Interface name or neighbor tag\n"
4632 "Enable BGP on interface\n"
4633 "Enable BGP with v6 link-local only\n"
4634 "Member of the peer-group\n"
4635 "Peer-group name\n")
4c48cf63 4636{
d62a17ae 4637 int idx_word = 1;
4638 int idx_peer_group_word = 5;
31500417 4639
d62a17ae 4640 if (argc > idx_peer_group_word)
28c6e247
IR
4641 return peer_conf_interface_get(
4642 vty, argv[idx_word]->arg, 1,
4643 argv[idx_peer_group_word]->arg, NULL);
31500417 4644
28c6e247 4645 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4646}
4647
a80beece 4648
28c6e247
IR
4649DEFUN (neighbor_interface_config_remote_as,
4650 neighbor_interface_config_remote_as_cmd,
4651 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4652 NEIGHBOR_STR
4653 "Interface name or neighbor tag\n"
4654 "Enable BGP on interface\n"
4655 "Specify a BGP neighbor\n"
4656 AS_STR
4657 "Internal BGP peer\n"
4658 "External BGP peer\n")
b3a39dc5 4659{
d62a17ae 4660 int idx_word = 1;
4661 int idx_remote_as = 4;
28c6e247
IR
4662 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4663 argv[idx_remote_as]->arg);
b3a39dc5
DD
4664}
4665
28c6e247
IR
4666DEFUN (neighbor_interface_v6only_config_remote_as,
4667 neighbor_interface_v6only_config_remote_as_cmd,
4668 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4669 NEIGHBOR_STR
4670 "Interface name or neighbor tag\n"
4671 "Enable BGP with v6 link-local only\n"
4672 "Enable BGP on interface\n"
4673 "Specify a BGP neighbor\n"
4674 AS_STR
4675 "Internal BGP peer\n"
4676 "External BGP peer\n")
b3a39dc5 4677{
d62a17ae 4678 int idx_word = 1;
4679 int idx_remote_as = 5;
28c6e247
IR
4680 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4681 argv[idx_remote_as]->arg);
b3a39dc5
DD
4682}
4683
28c6e247
IR
4684DEFUN (neighbor_peer_group,
4685 neighbor_peer_group_cmd,
4686 "neighbor WORD peer-group",
4687 NEIGHBOR_STR
4688 "Interface name or neighbor tag\n"
4689 "Configure peer-group\n")
718e3744 4690{
28c6e247 4691 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4692 int idx_word = 1;
28c6e247
IR
4693 struct peer *peer;
4694 struct peer_group *group;
718e3744 4695
28c6e247
IR
4696 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4697 if (peer) {
4698 vty_out(vty, "%% Name conflict with interface: \n");
4699 return CMD_WARNING_CONFIG_FAILED;
4700 }
718e3744 4701
28c6e247
IR
4702 group = peer_group_get(bgp, argv[idx_word]->arg);
4703 if (!group) {
4704 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4705 return CMD_WARNING_CONFIG_FAILED;
4706 }
718e3744 4707
28c6e247 4708 return CMD_SUCCESS;
718e3744 4709}
4710
1d80f243
IR
4711DEFUN (no_neighbor,
4712 no_neighbor_cmd,
4713 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4714 NO_STR
4715 NEIGHBOR_STR
4716 NEIGHBOR_ADDR_STR2
4717 "Specify a BGP neighbor\n"
4718 AS_STR
4719 "Internal BGP peer\n"
4720 "External BGP peer\n")
718e3744 4721{
28c6e247 4722 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4723 int idx_peer = 2;
28c6e247 4724 int ret;
d62a17ae 4725 union sockunion su;
28c6e247
IR
4726 struct peer_group *group;
4727 struct peer *peer;
4728 struct peer *other;
d62a17ae 4729
28c6e247
IR
4730 ret = str2sockunion(argv[idx_peer]->arg, &su);
4731 if (ret < 0) {
4732 /* look up for neighbor by interface name config. */
4733 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4734 if (peer) {
4735 /* Request zebra to terminate IPv6 RAs on this
4736 * interface. */
4737 if (peer->ifp)
4738 bgp_zebra_terminate_radv(peer->bgp, peer);
4739 peer_notify_unconfig(peer);
4740 peer_delete(peer);
4741 return CMD_SUCCESS;
d62a17ae 4742 }
28c6e247
IR
4743
4744 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4745 if (group) {
4746 peer_group_notify_unconfig(group);
4747 peer_group_delete(group);
4e2786df 4748 } else {
28c6e247 4749 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4750 return CMD_WARNING_CONFIG_FAILED;
4751 }
28c6e247
IR
4752 } else {
4753 peer = peer_lookup(bgp, &su);
4754 if (peer) {
4755 if (peer_dynamic_neighbor(peer)) {
4756 vty_out(vty,
4757 "%% Operation not allowed on a dynamic neighbor\n");
4758 return CMD_WARNING_CONFIG_FAILED;
4759 }
d62a17ae 4760
28c6e247 4761 other = peer->doppelganger;
f4b8ec07 4762
28c6e247
IR
4763 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4764 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4765
28c6e247
IR
4766 peer_notify_unconfig(peer);
4767 peer_delete(peer);
4768 if (other && other->status != Deleted) {
4769 peer_notify_unconfig(other);
4770 peer_delete(other);
4771 }
4772 }
4773 }
4774
4775 return CMD_SUCCESS;
a80beece
DS
4776}
4777
28c6e247
IR
4778DEFUN (no_neighbor_interface_config,
4779 no_neighbor_interface_config_cmd,
4780 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4781 NO_STR
4782 NEIGHBOR_STR
4783 "Interface name\n"
4784 "Configure BGP on interface\n"
4785 "Enable BGP with v6 link-local only\n"
4786 "Member of the peer-group\n"
4787 "Peer-group name\n"
4788 "Specify a BGP neighbor\n"
4789 AS_STR
4790 "Internal BGP peer\n"
4791 "External BGP peer\n")
718e3744 4792{
28c6e247 4793 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4794 int idx_word = 2;
28c6e247 4795 struct peer *peer;
718e3744 4796
28c6e247
IR
4797 /* look up for neighbor by interface name config. */
4798 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4799 if (peer) {
4800 /* Request zebra to terminate IPv6 RAs on this interface. */
4801 if (peer->ifp)
4802 bgp_zebra_terminate_radv(peer->bgp, peer);
4803 peer_notify_unconfig(peer);
4804 peer_delete(peer);
4805 } else {
4806 vty_out(vty, "%% Create the bgp interface first\n");
4807 return CMD_WARNING_CONFIG_FAILED;
4808 }
4809 return CMD_SUCCESS;
718e3744 4810}
4811
28c6e247
IR
4812DEFUN (no_neighbor_peer_group,
4813 no_neighbor_peer_group_cmd,
4814 "no neighbor WORD peer-group",
4815 NO_STR
4816 NEIGHBOR_STR
4817 "Neighbor tag\n"
4818 "Configure peer-group\n")
718e3744 4819{
28c6e247
IR
4820 VTY_DECLVAR_CONTEXT(bgp, bgp);
4821 int idx_word = 2;
4822 struct peer_group *group;
f4b8ec07 4823
28c6e247
IR
4824 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4825 if (group) {
4826 peer_group_notify_unconfig(group);
4827 peer_group_delete(group);
f4b8ec07 4828 } else {
28c6e247 4829 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4830 return CMD_WARNING_CONFIG_FAILED;
4831 }
28c6e247
IR
4832 return CMD_SUCCESS;
4833}
f4b8ec07 4834
28c6e247
IR
4835DEFUN (no_neighbor_interface_peer_group_remote_as,
4836 no_neighbor_interface_peer_group_remote_as_cmd,
4837 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4838 NO_STR
4839 NEIGHBOR_STR
4840 "Interface name or neighbor tag\n"
4841 "Specify a BGP neighbor\n"
4842 AS_STR
4843 "Internal BGP peer\n"
4844 "External BGP peer\n")
4845{
4846 VTY_DECLVAR_CONTEXT(bgp, bgp);
4847 int idx_word = 2;
4848 struct peer_group *group;
4849 struct peer *peer;
f4b8ec07 4850
28c6e247
IR
4851 /* look up for neighbor by interface name config. */
4852 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4853 if (peer) {
4854 peer_as_change(peer, 0, AS_UNSPECIFIED);
4855 return CMD_SUCCESS;
4856 }
f4b8ec07 4857
28c6e247
IR
4858 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4859 if (group)
4860 peer_group_remote_as_delete(group);
4861 else {
4862 vty_out(vty, "%% Create the peer-group or interface first\n");
4863 return CMD_WARNING_CONFIG_FAILED;
4864 }
4865 return CMD_SUCCESS;
718e3744 4866}
6b0655a2 4867
28c6e247
IR
4868DEFUN (neighbor_local_as,
4869 neighbor_local_as_cmd,
4870 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4871 NEIGHBOR_STR
4872 NEIGHBOR_ADDR_STR2
4873 "Specify a local-as number\n"
4874 "AS number used as local AS\n")
718e3744 4875{
d62a17ae 4876 int idx_peer = 1;
4877 int idx_number = 3;
28c6e247
IR
4878 struct peer *peer;
4879 int ret;
4880 as_t as;
718e3744 4881
28c6e247
IR
4882 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4883 if (!peer)
d62a17ae 4884 return CMD_WARNING_CONFIG_FAILED;
718e3744 4885
28c6e247
IR
4886 as = strtoul(argv[idx_number]->arg, NULL, 10);
4887 ret = peer_local_as_set(peer, as, 0, 0);
4888 return bgp_vty_return(vty, ret);
718e3744 4889}
4890
28c6e247
IR
4891DEFUN (neighbor_local_as_no_prepend,
4892 neighbor_local_as_no_prepend_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Specify a local-as number\n"
4897 "AS number used as local AS\n"
4898 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4899{
d62a17ae 4900 int idx_peer = 1;
4901 int idx_number = 3;
28c6e247
IR
4902 struct peer *peer;
4903 int ret;
4904 as_t as;
718e3744 4905
28c6e247
IR
4906 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4907 if (!peer)
d62a17ae 4908 return CMD_WARNING_CONFIG_FAILED;
718e3744 4909
28c6e247
IR
4910 as = strtoul(argv[idx_number]->arg, NULL, 10);
4911 ret = peer_local_as_set(peer, as, 1, 0);
4912 return bgp_vty_return(vty, ret);
718e3744 4913}
4914
28c6e247
IR
4915DEFUN (neighbor_local_as_no_prepend_replace_as,
4916 neighbor_local_as_no_prepend_replace_as_cmd,
4917 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4918 NEIGHBOR_STR
4919 NEIGHBOR_ADDR_STR2
4920 "Specify a local-as number\n"
4921 "AS number used as local AS\n"
4922 "Do not prepend local-as to updates from ebgp peers\n"
4923 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4924{
d62a17ae 4925 int idx_peer = 1;
4926 int idx_number = 3;
28c6e247
IR
4927 struct peer *peer;
4928 int ret;
4929 as_t as;
9d3f9705 4930
28c6e247
IR
4931 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4932 if (!peer)
d62a17ae 4933 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4934
28c6e247
IR
4935 as = strtoul(argv[idx_number]->arg, NULL, 10);
4936 ret = peer_local_as_set(peer, as, 1, 1);
4937 return bgp_vty_return(vty, ret);
9d3f9705
AC
4938}
4939
28c6e247
IR
4940DEFUN (no_neighbor_local_as,
4941 no_neighbor_local_as_cmd,
4942 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4943 NO_STR
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Specify a local-as number\n"
4947 "AS number used as local AS\n"
4948 "Do not prepend local-as to updates from ebgp peers\n"
4949 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4950{
d62a17ae 4951 int idx_peer = 2;
28c6e247
IR
4952 struct peer *peer;
4953 int ret;
718e3744 4954
28c6e247
IR
4955 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4956 if (!peer)
d62a17ae 4957 return CMD_WARNING_CONFIG_FAILED;
718e3744 4958
28c6e247
IR
4959 ret = peer_local_as_unset(peer);
4960 return bgp_vty_return(vty, ret);
718e3744 4961}
4962
718e3744 4963
3f9c7369
DS
4964DEFUN (neighbor_solo,
4965 neighbor_solo_cmd,
9ccf14f7 4966 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Solo peer - part of its own update group\n")
4970{
d62a17ae 4971 int idx_peer = 1;
4972 struct peer *peer;
4973 int ret;
3f9c7369 4974
d62a17ae 4975 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4976 if (!peer)
4977 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4978
d62a17ae 4979 ret = update_group_adjust_soloness(peer, 1);
4980 return bgp_vty_return(vty, ret);
3f9c7369
DS
4981}
4982
4983DEFUN (no_neighbor_solo,
4984 no_neighbor_solo_cmd,
9ccf14f7 4985 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4986 NO_STR
4987 NEIGHBOR_STR
4988 NEIGHBOR_ADDR_STR2
4989 "Solo peer - part of its own update group\n")
4990{
d62a17ae 4991 int idx_peer = 2;
4992 struct peer *peer;
4993 int ret;
3f9c7369 4994
d62a17ae 4995 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4996 if (!peer)
4997 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4998
d62a17ae 4999 ret = update_group_adjust_soloness(peer, 0);
5000 return bgp_vty_return(vty, ret);
3f9c7369
DS
5001}
5002
28c6e247
IR
5003DEFUN (neighbor_password,
5004 neighbor_password_cmd,
5005 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Set a password\n"
5009 "The password\n")
0df7c91f 5010{
d62a17ae 5011 int idx_peer = 1;
5012 int idx_line = 3;
28c6e247
IR
5013 struct peer *peer;
5014 int ret;
0df7c91f 5015
28c6e247
IR
5016 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5017 if (!peer)
d62a17ae 5018 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5019
28c6e247
IR
5020 ret = peer_password_set(peer, argv[idx_line]->arg);
5021 return bgp_vty_return(vty, ret);
0df7c91f
PJ
5022}
5023
28c6e247
IR
5024DEFUN (no_neighbor_password,
5025 no_neighbor_password_cmd,
5026 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
5027 NO_STR
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR2
5030 "Set a password\n"
5031 "The password\n")
0df7c91f 5032{
d62a17ae 5033 int idx_peer = 2;
28c6e247
IR
5034 struct peer *peer;
5035 int ret;
0df7c91f 5036
28c6e247
IR
5037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5038 if (!peer)
d62a17ae 5039 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 5040
28c6e247
IR
5041 ret = peer_password_unset(peer);
5042 return bgp_vty_return(vty, ret);
0df7c91f 5043}
6b0655a2 5044
28c6e247
IR
5045DEFUN (neighbor_activate,
5046 neighbor_activate_cmd,
5047 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5048 NEIGHBOR_STR
5049 NEIGHBOR_ADDR_STR2
5050 "Enable the Address Family for this Neighbor\n")
718e3744 5051{
d62a17ae 5052 int idx_peer = 1;
28c6e247
IR
5053 int ret;
5054 struct peer *peer;
56ceae84 5055
28c6e247
IR
5056 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5057 if (!peer)
d62a17ae 5058 return CMD_WARNING_CONFIG_FAILED;
718e3744 5059
28c6e247
IR
5060 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5061 return bgp_vty_return(vty, ret);
718e3744 5062}
5063
d62a17ae 5064ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
5065 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5067 "Enable the Address Family for this Neighbor\n")
596c17ba 5068
28c6e247
IR
5069DEFUN (no_neighbor_activate,
5070 no_neighbor_activate_cmd,
5071 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5072 NO_STR
5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "Enable the Address Family for this Neighbor\n")
718e3744 5076{
d62a17ae 5077 int idx_peer = 2;
28c6e247
IR
5078 int ret;
5079 struct peer *peer;
f4b8ec07 5080
28c6e247
IR
5081 /* Lookup peer. */
5082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5083 if (!peer)
d62a17ae 5084 return CMD_WARNING_CONFIG_FAILED;
718e3744 5085
28c6e247
IR
5086 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
5087 return bgp_vty_return(vty, ret);
718e3744 5088}
6b0655a2 5089
d62a17ae 5090ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5091 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5092 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5093 "Enable the Address Family for this Neighbor\n")
596c17ba 5094
28c6e247
IR
5095DEFUN (neighbor_set_peer_group,
5096 neighbor_set_peer_group_cmd,
5097 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5098 NEIGHBOR_STR
5099 NEIGHBOR_ADDR_STR2
5100 "Member of the peer-group\n"
5101 "Peer-group name\n")
718e3744 5102{
28c6e247 5103 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5104 int idx_peer = 1;
5105 int idx_word = 3;
28c6e247
IR
5106 int ret;
5107 as_t as;
5108 union sockunion su;
5109 struct peer *peer;
5110 struct peer_group *group;
5111
5112 ret = str2sockunion(argv[idx_peer]->arg, &su);
5113 if (ret < 0) {
5114 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5115 if (!peer) {
5116 vty_out(vty, "%% Malformed address or name: %s\n",
5117 argv[idx_peer]->arg);
5118 return CMD_WARNING_CONFIG_FAILED;
5119 }
5120 } else {
5121 if (peer_address_self_check(bgp, &su)) {
5122 vty_out(vty,
5123 "%% Can not configure the local system as neighbor\n");
5124 return CMD_WARNING_CONFIG_FAILED;
5125 }
2a059a54 5126
28c6e247
IR
5127 /* Disallow for dynamic neighbor. */
5128 peer = peer_lookup(bgp, &su);
5129 if (peer && peer_dynamic_neighbor(peer)) {
5130 vty_out(vty,
5131 "%% Operation not allowed on a dynamic neighbor\n");
5132 return CMD_WARNING_CONFIG_FAILED;
5133 }
5134 }
5135
5136 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5137 if (!group) {
5138 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5139 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5140 }
d62a17ae 5141
28c6e247 5142 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5143
28c6e247 5144 return bgp_vty_return(vty, ret);
d62a17ae 5145}
5146
5147ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5148 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5150 "Member of the peer-group\n"
5151 "Peer-group name\n")
596c17ba 5152
28c6e247
IR
5153DEFUN (no_neighbor_set_peer_group,
5154 no_neighbor_set_peer_group_cmd,
5155 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5156 NO_STR
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "Member of the peer-group\n"
5160 "Peer-group name\n")
718e3744 5161{
28c6e247 5162 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5163 int idx_peer = 2;
28c6e247
IR
5164 int idx_word = 4;
5165 int ret;
5166 struct peer *peer;
5167 struct peer_group *group;
d62a17ae 5168
28c6e247
IR
5169 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5170 if (!peer)
d62a17ae 5171 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5172
28c6e247
IR
5173 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5174 if (!group) {
5175 vty_out(vty, "%% Configure the peer-group first\n");
5176 return CMD_WARNING_CONFIG_FAILED;
5177 }
718e3744 5178
28c6e247
IR
5179 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5180 bgp_zebra_terminate_radv(peer->bgp, peer);
5181
5182 peer_notify_unconfig(peer);
5183 ret = peer_delete(peer);
5184
5185 return bgp_vty_return(vty, ret);
718e3744 5186}
6b0655a2 5187
d62a17ae 5188ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5189 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5190 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5191 "Member of the peer-group\n"
5192 "Peer-group name\n")
596c17ba 5193
d62a17ae 5194static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
83194f39 5195 uint64_t flag, int set)
718e3744 5196{
d62a17ae 5197 int ret;
5198 struct peer *peer;
718e3744 5199
d62a17ae 5200 peer = peer_and_group_lookup_vty(vty, ip_str);
5201 if (!peer)
5202 return CMD_WARNING_CONFIG_FAILED;
718e3744 5203
7ebe625c
QY
5204 /*
5205 * If 'neighbor <interface>', then this is for directly connected peers,
5206 * we should not accept disable-connected-check.
5207 */
5208 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5209 vty_out(vty,
3efd0893 5210 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5211 ip_str);
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
d62a17ae 5215 if (!set && flag == PEER_FLAG_SHUTDOWN)
5216 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5217
d62a17ae 5218 if (set)
5219 ret = peer_flag_set(peer, flag);
5220 else
5221 ret = peer_flag_unset(peer, flag);
718e3744 5222
d62a17ae 5223 return bgp_vty_return(vty, ret);
718e3744 5224}
5225
83194f39 5226static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint64_t flag)
718e3744 5227{
d62a17ae 5228 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5229}
5230
d62a17ae 5231static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
83194f39 5232 uint64_t flag)
718e3744 5233{
d62a17ae 5234 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5235}
5236
5237/* neighbor passive. */
28c6e247
IR
5238DEFUN (neighbor_passive,
5239 neighbor_passive_cmd,
5240 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5241 NEIGHBOR_STR
5242 NEIGHBOR_ADDR_STR2
5243 "Don't send open messages to this neighbor\n")
718e3744 5244{
d62a17ae 5245 int idx_peer = 1;
28c6e247 5246 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5247}
5248
28c6e247
IR
5249DEFUN (no_neighbor_passive,
5250 no_neighbor_passive_cmd,
5251 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5252 NO_STR
5253 NEIGHBOR_STR
5254 NEIGHBOR_ADDR_STR2
5255 "Don't send open messages to this neighbor\n")
718e3744 5256{
d62a17ae 5257 int idx_peer = 2;
28c6e247 5258 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5259}
6b0655a2 5260
718e3744 5261/* neighbor shutdown. */
28c6e247
IR
5262DEFUN (neighbor_shutdown_msg,
5263 neighbor_shutdown_msg_cmd,
5264 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5265 NEIGHBOR_STR
5266 NEIGHBOR_ADDR_STR2
5267 "Administratively shut down this neighbor\n"
5268 "Add a shutdown message (RFC 8203)\n"
5269 "Shutdown message\n")
718e3744 5270{
d62a17ae 5271 int idx_peer = 1;
73d70fa6 5272
d62a17ae 5273 if (argc >= 5) {
28c6e247
IR
5274 struct peer *peer =
5275 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5276 char *message;
73d70fa6 5277
28c6e247
IR
5278 if (!peer)
5279 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5280 message = argv_concat(argv, argc, 4);
28c6e247
IR
5281 peer_tx_shutdown_message_set(peer, message);
5282 XFREE(MTYPE_TMP, message);
d62a17ae 5283 }
73d70fa6 5284
28c6e247 5285 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5286}
5287
1d80f243 5288ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5289 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5291 "Administratively shut down this neighbor\n")
73d70fa6 5292
28c6e247
IR
5293DEFUN (no_neighbor_shutdown_msg,
5294 no_neighbor_shutdown_msg_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Administratively shut down this neighbor\n"
5300 "Remove a shutdown message (RFC 8203)\n"
5301 "Shutdown message\n")
718e3744 5302{
d62a17ae 5303 int idx_peer = 2;
73d70fa6 5304
28c6e247
IR
5305 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5306 PEER_FLAG_SHUTDOWN);
718e3744 5307}
6b0655a2 5308
1d80f243 5309ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5310 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5311 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5312 "Administratively shut down this neighbor\n")
73d70fa6 5313
8336c896
DA
5314DEFUN(neighbor_shutdown_rtt,
5315 neighbor_shutdown_rtt_cmd,
5316 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5317 NEIGHBOR_STR
5318 NEIGHBOR_ADDR_STR2
5319 "Administratively shut down this neighbor\n"
5320 "Shutdown if round-trip-time is higher than expected\n"
5321 "Round-trip-time in milliseconds\n"
5322 "Specify the number of keepalives before shutdown\n"
5323 "The number of keepalives with higher RTT to shutdown\n")
5324{
5325 int idx_peer = 1;
5326 int idx_rtt = 4;
5327 int idx_count = 0;
5328 struct peer *peer;
5329
5330 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5331
5332 if (!peer)
5333 return CMD_WARNING_CONFIG_FAILED;
5334
5335 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5336
5337 if (argv_find(argv, argc, "count", &idx_count))
5338 peer->rtt_keepalive_conf =
5339 strtol(argv[idx_count + 1]->arg, NULL, 10);
5340
5341 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5342 PEER_FLAG_RTT_SHUTDOWN);
5343}
5344
5345DEFUN(no_neighbor_shutdown_rtt,
5346 no_neighbor_shutdown_rtt_cmd,
5347 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5348 NO_STR
5349 NEIGHBOR_STR
5350 NEIGHBOR_ADDR_STR2
5351 "Administratively shut down this neighbor\n"
5352 "Shutdown if round-trip-time is higher than expected\n"
5353 "Round-trip-time in milliseconds\n"
5354 "Specify the number of keepalives before shutdown\n"
5355 "The number of keepalives with higher RTT to shutdown\n")
5356{
5357 int idx_peer = 2;
5358 struct peer *peer;
5359
5360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5361
5362 if (!peer)
5363 return CMD_WARNING_CONFIG_FAILED;
5364
5365 peer->rtt_expected = 0;
5366 peer->rtt_keepalive_conf = 1;
5367
5368 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5369 PEER_FLAG_RTT_SHUTDOWN);
5370}
5371
718e3744 5372/* neighbor capability dynamic. */
28c6e247
IR
5373DEFUN (neighbor_capability_dynamic,
5374 neighbor_capability_dynamic_cmd,
5375 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5376 NEIGHBOR_STR
5377 NEIGHBOR_ADDR_STR2
5378 "Advertise capability to the peer\n"
5379 "Advertise dynamic capability to this neighbor\n")
718e3744 5380{
d62a17ae 5381 int idx_peer = 1;
28c6e247
IR
5382 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5383 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5384}
5385
28c6e247
IR
5386DEFUN (no_neighbor_capability_dynamic,
5387 no_neighbor_capability_dynamic_cmd,
5388 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5389 NO_STR
5390 NEIGHBOR_STR
5391 NEIGHBOR_ADDR_STR2
5392 "Advertise capability to the peer\n"
5393 "Advertise dynamic capability to this neighbor\n")
718e3744 5394{
d62a17ae 5395 int idx_peer = 2;
28c6e247
IR
5396 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5397 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5398}
6b0655a2 5399
718e3744 5400/* neighbor dont-capability-negotiate */
5401DEFUN (neighbor_dont_capability_negotiate,
5402 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5403 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5404 NEIGHBOR_STR
5405 NEIGHBOR_ADDR_STR2
5406 "Do not perform capability negotiation\n")
5407{
d62a17ae 5408 int idx_peer = 1;
5409 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5410 PEER_FLAG_DONT_CAPABILITY);
718e3744 5411}
5412
5413DEFUN (no_neighbor_dont_capability_negotiate,
5414 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5415 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5416 NO_STR
5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Do not perform capability negotiation\n")
5420{
28c6e247
IR
5421 int idx_peer = 2;
5422 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5423 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5424}
5425
28c6e247
IR
5426/* neighbor capability extended next hop encoding */
5427DEFUN (neighbor_capability_enhe,
5428 neighbor_capability_enhe_cmd,
5429 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5430 NEIGHBOR_STR
5431 NEIGHBOR_ADDR_STR2
5432 "Advertise capability to the peer\n"
5433 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5434{
28c6e247 5435 int idx_peer = 1;
c4786405
DS
5436 struct peer *peer;
5437
5438 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5439 if (peer && peer->conf_if)
5440 return CMD_SUCCESS;
5441
28c6e247
IR
5442 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5443 PEER_FLAG_CAPABILITY_ENHE);
5444}
f4b8ec07 5445
28c6e247
IR
5446DEFUN (no_neighbor_capability_enhe,
5447 no_neighbor_capability_enhe_cmd,
5448 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5449 NO_STR
5450 NEIGHBOR_STR
5451 NEIGHBOR_ADDR_STR2
5452 "Advertise capability to the peer\n"
5453 "Advertise extended next-hop capability to the peer\n")
5454{
5455 int idx_peer = 2;
c4786405
DS
5456 struct peer *peer;
5457
5458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5459 if (peer && peer->conf_if) {
5460 vty_out(vty,
5461 "Peer %s cannot have capability extended-nexthop turned off\n",
5462 argv[idx_peer]->arg);
5463 return CMD_WARNING_CONFIG_FAILED;
5464 }
5465
28c6e247
IR
5466 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5467 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5468}
5469
d62a17ae 5470static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5471 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5472 int set)
718e3744 5473{
d62a17ae 5474 int ret;
5475 struct peer *peer;
718e3744 5476
d62a17ae 5477 peer = peer_and_group_lookup_vty(vty, peer_str);
5478 if (!peer)
5479 return CMD_WARNING_CONFIG_FAILED;
718e3744 5480
d62a17ae 5481 if (set)
5482 ret = peer_af_flag_set(peer, afi, safi, flag);
5483 else
5484 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5485
d62a17ae 5486 return bgp_vty_return(vty, ret);
718e3744 5487}
5488
d62a17ae 5489static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5490 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5491{
d62a17ae 5492 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5493}
5494
d62a17ae 5495static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5496 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5497{
d62a17ae 5498 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5499}
6b0655a2 5500
718e3744 5501/* neighbor capability orf prefix-list. */
5502DEFUN (neighbor_capability_orf_prefix,
5503 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5504 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise ORF capability to the peer\n"
5509 "Advertise prefixlist ORF capability to this neighbor\n"
5510 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5511 "Capability to RECEIVE the ORF from this neighbor\n"
5512 "Capability to SEND the ORF to this neighbor\n")
5513{
d62a17ae 5514 int idx_send_recv = 5;
db45f64d
DS
5515 char *peer_str = argv[1]->arg;
5516 struct peer *peer;
5517 afi_t afi = bgp_node_afi(vty);
5518 safi_t safi = bgp_node_safi(vty);
d62a17ae 5519
db45f64d
DS
5520 peer = peer_and_group_lookup_vty(vty, peer_str);
5521 if (!peer)
d62a17ae 5522 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5523
db45f64d
DS
5524 if (strmatch(argv[idx_send_recv]->text, "send"))
5525 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5526 PEER_FLAG_ORF_PREFIX_SM);
5527
5528 if (strmatch(argv[idx_send_recv]->text, "receive"))
5529 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5530 PEER_FLAG_ORF_PREFIX_RM);
5531
5532 if (strmatch(argv[idx_send_recv]->text, "both"))
5533 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5534 PEER_FLAG_ORF_PREFIX_SM)
5535 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5536 PEER_FLAG_ORF_PREFIX_RM);
5537
5538 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5539}
5540
5541ALIAS_HIDDEN(
5542 neighbor_capability_orf_prefix,
5543 neighbor_capability_orf_prefix_hidden_cmd,
5544 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5545 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Advertise capability to the peer\n"
5547 "Advertise ORF capability to the peer\n"
5548 "Advertise prefixlist ORF capability to this neighbor\n"
5549 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5550 "Capability to RECEIVE the ORF from this neighbor\n"
5551 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5552
718e3744 5553DEFUN (no_neighbor_capability_orf_prefix,
5554 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5555 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5556 NO_STR
5557 NEIGHBOR_STR
5558 NEIGHBOR_ADDR_STR2
5559 "Advertise capability to the peer\n"
5560 "Advertise ORF capability to the peer\n"
5561 "Advertise prefixlist ORF capability to this neighbor\n"
5562 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5563 "Capability to RECEIVE the ORF from this neighbor\n"
5564 "Capability to SEND the ORF to this neighbor\n")
5565{
d62a17ae 5566 int idx_send_recv = 6;
db45f64d
DS
5567 char *peer_str = argv[2]->arg;
5568 struct peer *peer;
5569 afi_t afi = bgp_node_afi(vty);
5570 safi_t safi = bgp_node_safi(vty);
d62a17ae 5571
db45f64d
DS
5572 peer = peer_and_group_lookup_vty(vty, peer_str);
5573 if (!peer)
d62a17ae 5574 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5575
db45f64d
DS
5576 if (strmatch(argv[idx_send_recv]->text, "send"))
5577 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5578 PEER_FLAG_ORF_PREFIX_SM);
5579
5580 if (strmatch(argv[idx_send_recv]->text, "receive"))
5581 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5582 PEER_FLAG_ORF_PREFIX_RM);
5583
5584 if (strmatch(argv[idx_send_recv]->text, "both"))
5585 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5586 PEER_FLAG_ORF_PREFIX_SM)
5587 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5588 PEER_FLAG_ORF_PREFIX_RM);
5589
5590 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5591}
5592
5593ALIAS_HIDDEN(
5594 no_neighbor_capability_orf_prefix,
5595 no_neighbor_capability_orf_prefix_hidden_cmd,
5596 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5597 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5598 "Advertise capability to the peer\n"
5599 "Advertise ORF capability to the peer\n"
5600 "Advertise prefixlist ORF capability to this neighbor\n"
5601 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5602 "Capability to RECEIVE the ORF from this neighbor\n"
5603 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5604
718e3744 5605/* neighbor next-hop-self. */
28c6e247
IR
5606DEFUN (neighbor_nexthop_self,
5607 neighbor_nexthop_self_cmd,
5608 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5609 NEIGHBOR_STR
5610 NEIGHBOR_ADDR_STR2
5611 "Disable the next hop calculation for this neighbor\n")
718e3744 5612{
d62a17ae 5613 int idx_peer = 1;
28c6e247
IR
5614 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5615 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5616}
9e7a53c1 5617
d62a17ae 5618ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5619 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5620 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5621 "Disable the next hop calculation for this neighbor\n")
596c17ba 5622
f4b8ec07 5623/* neighbor next-hop-self. */
28c6e247
IR
5624DEFUN (neighbor_nexthop_self_force,
5625 neighbor_nexthop_self_force_cmd,
5626 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Disable the next hop calculation for this neighbor\n"
5630 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5631{
5632 int idx_peer = 1;
28c6e247
IR
5633 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5634 bgp_node_safi(vty),
5635 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5636}
5637
d62a17ae 5638ALIAS_HIDDEN(neighbor_nexthop_self_force,
5639 neighbor_nexthop_self_force_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Disable the next hop calculation for this neighbor\n"
5643 "Set the next hop to self for reflected routes\n")
596c17ba 5644
1bc4e531
DA
5645ALIAS_HIDDEN(neighbor_nexthop_self_force,
5646 neighbor_nexthop_self_all_hidden_cmd,
5647 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5649 "Disable the next hop calculation for this neighbor\n"
5650 "Set the next hop to self for reflected routes\n")
5651
28c6e247
IR
5652DEFUN (no_neighbor_nexthop_self,
5653 no_neighbor_nexthop_self_cmd,
5654 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5655 NO_STR
5656 NEIGHBOR_STR
5657 NEIGHBOR_ADDR_STR2
5658 "Disable the next hop calculation for this neighbor\n")
718e3744 5659{
d62a17ae 5660 int idx_peer = 2;
28c6e247
IR
5661 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5662 bgp_node_afi(vty), bgp_node_safi(vty),
5663 PEER_FLAG_NEXTHOP_SELF);
718e3744 5664}
6b0655a2 5665
d62a17ae 5666ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Disable the next hop calculation for this neighbor\n")
596c17ba 5670
28c6e247
IR
5671DEFUN (no_neighbor_nexthop_self_force,
5672 no_neighbor_nexthop_self_force_cmd,
5673 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5674 NO_STR
5675 NEIGHBOR_STR
5676 NEIGHBOR_ADDR_STR2
5677 "Disable the next hop calculation for this neighbor\n"
5678 "Set the next hop to self for reflected routes\n")
88b8ed8d 5679{
d62a17ae 5680 int idx_peer = 2;
28c6e247
IR
5681 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5682 bgp_node_afi(vty), bgp_node_safi(vty),
5683 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5684}
a538debe 5685
d62a17ae 5686ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5687 no_neighbor_nexthop_self_force_hidden_cmd,
5688 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5689 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5690 "Disable the next hop calculation for this neighbor\n"
5691 "Set the next hop to self for reflected routes\n")
596c17ba 5692
1bc4e531
DA
5693ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5694 no_neighbor_nexthop_self_all_hidden_cmd,
5695 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5696 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5697 "Disable the next hop calculation for this neighbor\n"
5698 "Set the next hop to self for reflected routes\n")
5699
c7122e14 5700/* neighbor as-override */
28c6e247
IR
5701DEFUN (neighbor_as_override,
5702 neighbor_as_override_cmd,
5703 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5704 NEIGHBOR_STR
5705 NEIGHBOR_ADDR_STR2
5706 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5707{
d62a17ae 5708 int idx_peer = 1;
28c6e247
IR
5709 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5710 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5711}
5712
d62a17ae 5713ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5714 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5717
28c6e247
IR
5718DEFUN (no_neighbor_as_override,
5719 no_neighbor_as_override_cmd,
5720 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5721 NO_STR
5722 NEIGHBOR_STR
5723 NEIGHBOR_ADDR_STR2
5724 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5725{
d62a17ae 5726 int idx_peer = 2;
28c6e247
IR
5727 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5728 bgp_node_afi(vty), bgp_node_safi(vty),
5729 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5730}
5731
d62a17ae 5732ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5733 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5734 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5735 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5736
718e3744 5737/* neighbor remove-private-AS. */
28c6e247
IR
5738DEFUN (neighbor_remove_private_as,
5739 neighbor_remove_private_as_cmd,
5740 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
5743 "Remove private ASNs in outbound updates\n")
718e3744 5744{
d62a17ae 5745 int idx_peer = 1;
28c6e247
IR
5746 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5747 bgp_node_safi(vty),
5748 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5749}
5750
d62a17ae 5751ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5753 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5754 "Remove private ASNs in outbound updates\n")
596c17ba 5755
28c6e247
IR
5756DEFUN (neighbor_remove_private_as_all,
5757 neighbor_remove_private_as_all_cmd,
5758 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5759 NEIGHBOR_STR
5760 NEIGHBOR_ADDR_STR2
5761 "Remove private ASNs in outbound updates\n"
5762 "Apply to all AS numbers\n")
5000f21c 5763{
d62a17ae 5764 int idx_peer = 1;
28c6e247
IR
5765 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5766 bgp_node_safi(vty),
5767 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5768}
5769
d62a17ae 5770ALIAS_HIDDEN(neighbor_remove_private_as_all,
5771 neighbor_remove_private_as_all_hidden_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Remove private ASNs in outbound updates\n"
5775 "Apply to all AS numbers")
596c17ba 5776
28c6e247
IR
5777DEFUN (neighbor_remove_private_as_replace_as,
5778 neighbor_remove_private_as_replace_as_cmd,
5779 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Remove private ASNs in outbound updates\n"
5783 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5784{
d62a17ae 5785 int idx_peer = 1;
28c6e247
IR
5786 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5787 bgp_node_safi(vty),
5788 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5789}
5790
d62a17ae 5791ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5792 neighbor_remove_private_as_replace_as_hidden_cmd,
5793 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5794 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5795 "Remove private ASNs in outbound updates\n"
5796 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5797
28c6e247
IR
5798DEFUN (neighbor_remove_private_as_all_replace_as,
5799 neighbor_remove_private_as_all_replace_as_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Remove private ASNs in outbound updates\n"
5804 "Apply to all AS numbers\n"
5805 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5806{
d62a17ae 5807 int idx_peer = 1;
28c6e247
IR
5808 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5809 bgp_node_safi(vty),
5810 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5811}
5812
d62a17ae 5813ALIAS_HIDDEN(
5814 neighbor_remove_private_as_all_replace_as,
5815 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Remove private ASNs in outbound updates\n"
5819 "Apply to all AS numbers\n"
5820 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5821
28c6e247
IR
5822DEFUN (no_neighbor_remove_private_as,
5823 no_neighbor_remove_private_as_cmd,
5824 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5825 NO_STR
5826 NEIGHBOR_STR
5827 NEIGHBOR_ADDR_STR2
5828 "Remove private ASNs in outbound updates\n")
718e3744 5829{
d62a17ae 5830 int idx_peer = 2;
28c6e247
IR
5831 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5832 bgp_node_afi(vty), bgp_node_safi(vty),
5833 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5834}
6b0655a2 5835
d62a17ae 5836ALIAS_HIDDEN(no_neighbor_remove_private_as,
5837 no_neighbor_remove_private_as_hidden_cmd,
5838 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5840 "Remove private ASNs in outbound updates\n")
596c17ba 5841
28c6e247
IR
5842DEFUN (no_neighbor_remove_private_as_all,
5843 no_neighbor_remove_private_as_all_cmd,
5844 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5845 NO_STR
5846 NEIGHBOR_STR
5847 NEIGHBOR_ADDR_STR2
5848 "Remove private ASNs in outbound updates\n"
5849 "Apply to all AS numbers\n")
88b8ed8d 5850{
d62a17ae 5851 int idx_peer = 2;
28c6e247
IR
5852 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5853 bgp_node_afi(vty), bgp_node_safi(vty),
5854 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5855}
5000f21c 5856
d62a17ae 5857ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5858 no_neighbor_remove_private_as_all_hidden_cmd,
5859 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5860 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Remove private ASNs in outbound updates\n"
5862 "Apply to all AS numbers\n")
596c17ba 5863
28c6e247
IR
5864DEFUN (no_neighbor_remove_private_as_replace_as,
5865 no_neighbor_remove_private_as_replace_as_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5867 NO_STR
5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR2
5870 "Remove private ASNs in outbound updates\n"
5871 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5872{
d62a17ae 5873 int idx_peer = 2;
28c6e247
IR
5874 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5875 bgp_node_afi(vty), bgp_node_safi(vty),
5876 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5877}
5000f21c 5878
d62a17ae 5879ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5880 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5881 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5882 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5883 "Remove private ASNs in outbound updates\n"
5884 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5885
28c6e247
IR
5886DEFUN (no_neighbor_remove_private_as_all_replace_as,
5887 no_neighbor_remove_private_as_all_replace_as_cmd,
5888 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5889 NO_STR
5890 NEIGHBOR_STR
5891 NEIGHBOR_ADDR_STR2
5892 "Remove private ASNs in outbound updates\n"
5893 "Apply to all AS numbers\n"
5894 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5895{
d62a17ae 5896 int idx_peer = 2;
28c6e247
IR
5897 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5898 bgp_node_afi(vty), bgp_node_safi(vty),
5899 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5900}
5000f21c 5901
d62a17ae 5902ALIAS_HIDDEN(
5903 no_neighbor_remove_private_as_all_replace_as,
5904 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5905 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5906 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Remove private ASNs in outbound updates\n"
5908 "Apply to all AS numbers\n"
5909 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5910
5000f21c 5911
718e3744 5912/* neighbor send-community. */
28c6e247
IR
5913DEFUN (neighbor_send_community,
5914 neighbor_send_community_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5916 NEIGHBOR_STR
5917 NEIGHBOR_ADDR_STR2
5918 "Send Community attribute to this neighbor\n")
718e3744 5919{
d62a17ae 5920 int idx_peer = 1;
27c05d4d 5921
f63d4054
IR
5922 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5923 bgp_node_safi(vty),
5924 PEER_FLAG_SEND_COMMUNITY);
718e3744 5925}
5926
d62a17ae 5927ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5928 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5929 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5930 "Send Community attribute to this neighbor\n")
596c17ba 5931
28c6e247
IR
5932DEFUN (no_neighbor_send_community,
5933 no_neighbor_send_community_cmd,
5934 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5935 NO_STR
5936 NEIGHBOR_STR
5937 NEIGHBOR_ADDR_STR2
5938 "Send Community attribute to this neighbor\n")
718e3744 5939{
d62a17ae 5940 int idx_peer = 2;
27c05d4d 5941
f63d4054
IR
5942 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5943 bgp_node_afi(vty), bgp_node_safi(vty),
5944 PEER_FLAG_SEND_COMMUNITY);
718e3744 5945}
6b0655a2 5946
d62a17ae 5947ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5948 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5949 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5950 "Send Community attribute to this neighbor\n")
596c17ba 5951
718e3744 5952/* neighbor send-community extended. */
28c6e247
IR
5953DEFUN (neighbor_send_community_type,
5954 neighbor_send_community_type_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Send Community attribute to this neighbor\n"
5959 "Send Standard and Extended Community attributes\n"
5960 "Send Standard, Large and Extended Community attributes\n"
5961 "Send Extended Community attributes\n"
5962 "Send Standard Community attributes\n"
5963 "Send Large Community attributes\n")
718e3744 5964{
27c05d4d 5965 const char *type = argv[argc - 1]->text;
db45f64d 5966 char *peer_str = argv[1]->arg;
28c6e247 5967 struct peer *peer;
db45f64d 5968 afi_t afi = bgp_node_afi(vty);
28c6e247 5969 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5970
28c6e247
IR
5971 peer = peer_and_group_lookup_vty(vty, peer_str);
5972 if (!peer)
5973 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5974
28c6e247
IR
5975 if (strmatch(type, "standard"))
5976 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5977 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5978
28c6e247
IR
5979 if (strmatch(type, "extended"))
5980 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5981 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5982
28c6e247
IR
5983 if (strmatch(type, "large"))
5984 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5985 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5986
28c6e247
IR
5987 if (strmatch(type, "both")) {
5988 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5989 PEER_FLAG_SEND_COMMUNITY)
5990 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5991 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5992 }
28c6e247
IR
5993 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5994 PEER_FLAG_SEND_COMMUNITY)
5995 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5996 PEER_FLAG_SEND_EXT_COMMUNITY)
5997 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5998 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5999}
6000
6001ALIAS_HIDDEN(
6002 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6003 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6004 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6005 "Send Community attribute to this neighbor\n"
6006 "Send Standard and Extended Community attributes\n"
6007 "Send Standard, Large and Extended Community attributes\n"
6008 "Send Extended Community attributes\n"
6009 "Send Standard Community attributes\n"
6010 "Send Large Community attributes\n")
596c17ba 6011
28c6e247
IR
6012DEFUN (no_neighbor_send_community_type,
6013 no_neighbor_send_community_type_cmd,
6014 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6015 NO_STR
6016 NEIGHBOR_STR
6017 NEIGHBOR_ADDR_STR2
6018 "Send Community attribute to this neighbor\n"
6019 "Send Standard and Extended Community attributes\n"
6020 "Send Standard, Large and Extended Community attributes\n"
6021 "Send Extended Community attributes\n"
6022 "Send Standard Community attributes\n"
6023 "Send Large Community attributes\n")
718e3744 6024{
d62a17ae 6025 const char *type = argv[argc - 1]->text;
db45f64d 6026 char *peer_str = argv[2]->arg;
28c6e247 6027 struct peer *peer;
db45f64d
DS
6028 afi_t afi = bgp_node_afi(vty);
6029 safi_t safi = bgp_node_safi(vty);
6030
28c6e247
IR
6031 peer = peer_and_group_lookup_vty(vty, peer_str);
6032 if (!peer)
f4b8ec07
CS
6033 return CMD_WARNING_CONFIG_FAILED;
6034
28c6e247
IR
6035 if (strmatch(type, "standard"))
6036 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6037 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 6038
28c6e247
IR
6039 if (strmatch(type, "extended"))
6040 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6041 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 6042
28c6e247
IR
6043 if (strmatch(type, "large"))
6044 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6045 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
6046
6047 if (strmatch(type, "both")) {
db45f64d 6048
28c6e247
IR
6049 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6050 PEER_FLAG_SEND_COMMUNITY)
6051 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6052 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
6053 }
6054
28c6e247
IR
6055 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6056 PEER_FLAG_SEND_COMMUNITY)
6057 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6058 PEER_FLAG_SEND_EXT_COMMUNITY)
6059 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6060 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 6061}
6062
6063ALIAS_HIDDEN(
6064 no_neighbor_send_community_type,
6065 no_neighbor_send_community_type_hidden_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6068 "Send Community attribute to this neighbor\n"
6069 "Send Standard and Extended Community attributes\n"
6070 "Send Standard, Large and Extended Community attributes\n"
6071 "Send Extended Community attributes\n"
6072 "Send Standard Community attributes\n"
6073 "Send Large Community attributes\n")
596c17ba 6074
718e3744 6075/* neighbor soft-reconfig. */
28c6e247
IR
6076DEFUN (neighbor_soft_reconfiguration,
6077 neighbor_soft_reconfiguration_cmd,
6078 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6079 NEIGHBOR_STR
6080 NEIGHBOR_ADDR_STR2
6081 "Per neighbor soft reconfiguration\n"
6082 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6083{
d62a17ae 6084 int idx_peer = 1;
28c6e247
IR
6085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6086 bgp_node_safi(vty),
6087 PEER_FLAG_SOFT_RECONFIG);
718e3744 6088}
6089
d62a17ae 6090ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6091 neighbor_soft_reconfiguration_hidden_cmd,
6092 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6093 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6094 "Per neighbor soft reconfiguration\n"
6095 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6096
28c6e247
IR
6097DEFUN (no_neighbor_soft_reconfiguration,
6098 no_neighbor_soft_reconfiguration_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6100 NO_STR
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Per neighbor soft reconfiguration\n"
6104 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6105{
d62a17ae 6106 int idx_peer = 2;
28c6e247
IR
6107 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6108 bgp_node_afi(vty), bgp_node_safi(vty),
6109 PEER_FLAG_SOFT_RECONFIG);
718e3744 6110}
6b0655a2 6111
d62a17ae 6112ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6113 no_neighbor_soft_reconfiguration_hidden_cmd,
6114 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6116 "Per neighbor soft reconfiguration\n"
6117 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6118
28c6e247
IR
6119DEFUN (neighbor_route_reflector_client,
6120 neighbor_route_reflector_client_cmd,
6121 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6122 NEIGHBOR_STR
6123 NEIGHBOR_ADDR_STR2
6124 "Configure a neighbor as Route Reflector client\n")
718e3744 6125{
d62a17ae 6126 int idx_peer = 1;
28c6e247 6127 struct peer *peer;
718e3744 6128
6129
28c6e247
IR
6130 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6131 if (!peer)
d62a17ae 6132 return CMD_WARNING_CONFIG_FAILED;
718e3744 6133
28c6e247
IR
6134 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6135 bgp_node_safi(vty),
6136 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6137}
6138
d62a17ae 6139ALIAS_HIDDEN(neighbor_route_reflector_client,
6140 neighbor_route_reflector_client_hidden_cmd,
6141 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6143 "Configure a neighbor as Route Reflector client\n")
596c17ba 6144
28c6e247
IR
6145DEFUN (no_neighbor_route_reflector_client,
6146 no_neighbor_route_reflector_client_cmd,
6147 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6148 NO_STR
6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
6151 "Configure a neighbor as Route Reflector client\n")
718e3744 6152{
d62a17ae 6153 int idx_peer = 2;
28c6e247
IR
6154 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6155 bgp_node_afi(vty), bgp_node_safi(vty),
6156 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6157}
6b0655a2 6158
d62a17ae 6159ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6160 no_neighbor_route_reflector_client_hidden_cmd,
6161 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6162 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6163 "Configure a neighbor as Route Reflector client\n")
596c17ba 6164
718e3744 6165/* neighbor route-server-client. */
28c6e247
IR
6166DEFUN (neighbor_route_server_client,
6167 neighbor_route_server_client_cmd,
6168 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6169 NEIGHBOR_STR
6170 NEIGHBOR_ADDR_STR2
6171 "Configure a neighbor as Route Server client\n")
718e3744 6172{
d62a17ae 6173 int idx_peer = 1;
28c6e247 6174 struct peer *peer;
f4b8ec07 6175
28c6e247
IR
6176 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6177 if (!peer)
d62a17ae 6178 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6179 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6180 bgp_node_safi(vty),
6181 PEER_FLAG_RSERVER_CLIENT);
718e3744 6182}
6183
d62a17ae 6184ALIAS_HIDDEN(neighbor_route_server_client,
6185 neighbor_route_server_client_hidden_cmd,
6186 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6187 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6188 "Configure a neighbor as Route Server client\n")
596c17ba 6189
28c6e247
IR
6190DEFUN (no_neighbor_route_server_client,
6191 no_neighbor_route_server_client_cmd,
6192 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6193 NO_STR
6194 NEIGHBOR_STR
6195 NEIGHBOR_ADDR_STR2
6196 "Configure a neighbor as Route Server client\n")
fee0f4c6 6197{
d62a17ae 6198 int idx_peer = 2;
28c6e247
IR
6199 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6200 bgp_node_afi(vty), bgp_node_safi(vty),
6201 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6202}
6b0655a2 6203
d62a17ae 6204ALIAS_HIDDEN(no_neighbor_route_server_client,
6205 no_neighbor_route_server_client_hidden_cmd,
6206 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6208 "Configure a neighbor as Route Server client\n")
596c17ba 6209
fee0f4c6 6210DEFUN (neighbor_nexthop_local_unchanged,
6211 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6212 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6213 NEIGHBOR_STR
6214 NEIGHBOR_ADDR_STR2
6215 "Configure treatment of outgoing link-local nexthop attribute\n"
6216 "Leave link-local nexthop unchanged for this peer\n")
6217{
d62a17ae 6218 int idx_peer = 1;
6219 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6220 bgp_node_safi(vty),
6221 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6222}
6b0655a2 6223
fee0f4c6 6224DEFUN (no_neighbor_nexthop_local_unchanged,
6225 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6226 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6227 NO_STR
6228 NEIGHBOR_STR
6229 NEIGHBOR_ADDR_STR2
6230 "Configure treatment of outgoing link-local-nexthop attribute\n"
6231 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6232{
d62a17ae 6233 int idx_peer = 2;
6234 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6235 bgp_node_afi(vty), bgp_node_safi(vty),
6236 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6237}
6b0655a2 6238
28c6e247
IR
6239DEFUN (neighbor_attr_unchanged,
6240 neighbor_attr_unchanged_cmd,
6241 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6242 NEIGHBOR_STR
6243 NEIGHBOR_ADDR_STR2
6244 "BGP attribute is propagated unchanged to this neighbor\n"
6245 "As-path attribute\n"
6246 "Nexthop attribute\n"
6247 "Med attribute\n")
718e3744 6248{
d62a17ae 6249 int idx = 0;
8eeb0335 6250 char *peer_str = argv[1]->arg;
28c6e247 6251 struct peer *peer;
db45f64d
DS
6252 bool aspath = false;
6253 bool nexthop = false;
6254 bool med = false;
8eeb0335
DW
6255 afi_t afi = bgp_node_afi(vty);
6256 safi_t safi = bgp_node_safi(vty);
28c6e247 6257 int ret = 0;
f4b8ec07 6258
28c6e247
IR
6259 peer = peer_and_group_lookup_vty(vty, peer_str);
6260 if (!peer)
8eeb0335 6261 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6262
6263 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6264 aspath = true;
6265
d62a17ae 6266 idx = 0;
6267 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6268 nexthop = true;
6269
d62a17ae 6270 idx = 0;
6271 if (argv_find(argv, argc, "med", &idx))
db45f64d 6272 med = true;
d62a17ae 6273
8eeb0335 6274 /* no flags means all of them! */
db45f64d 6275 if (!aspath && !nexthop && !med) {
28c6e247
IR
6276 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6277 PEER_FLAG_AS_PATH_UNCHANGED);
6278 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6279 PEER_FLAG_NEXTHOP_UNCHANGED);
6280 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6281 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6282 } else {
28c6e247
IR
6283 if (!aspath) {
6284 if (peer_af_flag_check(peer, afi, safi,
6285 PEER_FLAG_AS_PATH_UNCHANGED)) {
6286 ret |= peer_af_flag_unset_vty(
6287 vty, peer_str, afi, safi,
6288 PEER_FLAG_AS_PATH_UNCHANGED);
6289 }
6290 } else
6291 ret |= peer_af_flag_set_vty(
6292 vty, peer_str, afi, safi,
6293 PEER_FLAG_AS_PATH_UNCHANGED);
6294
6295 if (!nexthop) {
6296 if (peer_af_flag_check(peer, afi, safi,
6297 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6298 ret |= peer_af_flag_unset_vty(
6299 vty, peer_str, afi, safi,
6300 PEER_FLAG_NEXTHOP_UNCHANGED);
6301 }
6302 } else
6303 ret |= peer_af_flag_set_vty(
6304 vty, peer_str, afi, safi,
6305 PEER_FLAG_NEXTHOP_UNCHANGED);
6306
6307 if (!med) {
6308 if (peer_af_flag_check(peer, afi, safi,
6309 PEER_FLAG_MED_UNCHANGED)) {
6310 ret |= peer_af_flag_unset_vty(
6311 vty, peer_str, afi, safi,
6312 PEER_FLAG_MED_UNCHANGED);
6313 }
6314 } else
6315 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6316 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6317 }
6318
28c6e247 6319 return ret;
d62a17ae 6320}
6321
6322ALIAS_HIDDEN(
6323 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6324 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6325 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6326 "BGP attribute is propagated unchanged to this neighbor\n"
6327 "As-path attribute\n"
6328 "Nexthop attribute\n"
6329 "Med attribute\n")
596c17ba 6330
28c6e247
IR
6331DEFUN (no_neighbor_attr_unchanged,
6332 no_neighbor_attr_unchanged_cmd,
6333 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6334 NO_STR
6335 NEIGHBOR_STR
6336 NEIGHBOR_ADDR_STR2
6337 "BGP attribute is propagated unchanged to this neighbor\n"
6338 "As-path attribute\n"
6339 "Nexthop attribute\n"
6340 "Med attribute\n")
718e3744 6341{
d62a17ae 6342 int idx = 0;
db45f64d 6343 char *peer_str = argv[2]->arg;
28c6e247 6344 struct peer *peer;
db45f64d
DS
6345 bool aspath = false;
6346 bool nexthop = false;
6347 bool med = false;
6348 afi_t afi = bgp_node_afi(vty);
6349 safi_t safi = bgp_node_safi(vty);
28c6e247 6350 int ret = 0;
f4b8ec07 6351
28c6e247
IR
6352 peer = peer_and_group_lookup_vty(vty, peer_str);
6353 if (!peer)
db45f64d 6354 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6355
6356 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6357 aspath = true;
6358
d62a17ae 6359 idx = 0;
6360 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6361 nexthop = true;
6362
d62a17ae 6363 idx = 0;
6364 if (argv_find(argv, argc, "med", &idx))
db45f64d 6365 med = true;
d62a17ae 6366
28c6e247
IR
6367 if (!aspath && !nexthop && !med) // no flags means all of them!
6368 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6369 PEER_FLAG_AS_PATH_UNCHANGED)
6370 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6371 PEER_FLAG_NEXTHOP_UNCHANGED)
6372 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6373 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6374
6375 if (aspath)
28c6e247
IR
6376 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6377 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6378
6379 if (nexthop)
28c6e247
IR
6380 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6381 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6382
db45f64d 6383 if (med)
28c6e247
IR
6384 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6385 PEER_FLAG_MED_UNCHANGED);
db45f64d 6386
28c6e247 6387 return ret;
d62a17ae 6388}
6389
6390ALIAS_HIDDEN(
6391 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6392 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6393 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6394 "BGP attribute is propagated unchanged to this neighbor\n"
6395 "As-path attribute\n"
6396 "Nexthop attribute\n"
6397 "Med attribute\n")
718e3744 6398
28c6e247
IR
6399/* EBGP multihop configuration. */
6400static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6401 const char *ttl_str)
718e3744 6402{
28c6e247
IR
6403 struct peer *peer;
6404 unsigned int ttl;
718e3744 6405
28c6e247
IR
6406 peer = peer_and_group_lookup_vty(vty, ip_str);
6407 if (!peer)
d62a17ae 6408 return CMD_WARNING_CONFIG_FAILED;
718e3744 6409
28c6e247
IR
6410 if (peer->conf_if)
6411 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6412
6413 if (!ttl_str)
6414 ttl = MAXTTL;
6415 else
6416 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6417
28c6e247 6418 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6419}
6420
28c6e247 6421static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6422{
28c6e247 6423 struct peer *peer;
718e3744 6424
28c6e247
IR
6425 peer = peer_and_group_lookup_vty(vty, ip_str);
6426 if (!peer)
d62a17ae 6427 return CMD_WARNING_CONFIG_FAILED;
718e3744 6428
28c6e247 6429 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6430}
6431
28c6e247
IR
6432/* neighbor ebgp-multihop. */
6433DEFUN (neighbor_ebgp_multihop,
6434 neighbor_ebgp_multihop_cmd,
6435 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6436 NEIGHBOR_STR
6437 NEIGHBOR_ADDR_STR2
6438 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6439{
28c6e247
IR
6440 int idx_peer = 1;
6441 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6442}
f4b8ec07 6443
28c6e247
IR
6444DEFUN (neighbor_ebgp_multihop_ttl,
6445 neighbor_ebgp_multihop_ttl_cmd,
6446 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6447 NEIGHBOR_STR
6448 NEIGHBOR_ADDR_STR2
6449 "Allow EBGP neighbors not on directly connected networks\n"
6450 "maximum hop count\n")
6451{
6452 int idx_peer = 1;
6453 int idx_number = 3;
6454 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6455 argv[idx_number]->arg);
6456}
f4b8ec07 6457
28c6e247
IR
6458DEFUN (no_neighbor_ebgp_multihop,
6459 no_neighbor_ebgp_multihop_cmd,
6460 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6461 NO_STR
6462 NEIGHBOR_STR
6463 NEIGHBOR_ADDR_STR2
6464 "Allow EBGP neighbors not on directly connected networks\n"
6465 "maximum hop count\n")
6466{
6467 int idx_peer = 2;
6468 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6469}
6470
d864dd9e
EB
6471static uint8_t get_role_by_name(const char *role_str)
6472{
6473 if (strncmp(role_str, "peer", 2) == 0)
6474 return ROLE_PEER;
6475 if (strncmp(role_str, "provider", 2) == 0)
6476 return ROLE_PROVIDER;
6477 if (strncmp(role_str, "customer", 2) == 0)
6478 return ROLE_CUSTOMER;
6479 if (strncmp(role_str, "rs-server", 4) == 0)
6480 return ROLE_RS_SERVER;
6481 if (strncmp(role_str, "rs-client", 4) == 0)
6482 return ROLE_RS_CLIENT;
8f2d6021 6483 return ROLE_UNDEFINED;
d864dd9e
EB
6484}
6485
6486static int peer_role_set_vty(struct vty *vty, const char *ip_str,
8f2d6021 6487 const char *role_str, bool strict_mode)
d864dd9e
EB
6488{
6489 struct peer *peer;
6490
7dddd1f7 6491 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6492 if (!peer)
6493 return CMD_WARNING_CONFIG_FAILED;
6494 uint8_t role = get_role_by_name(role_str);
6495
8f2d6021 6496 if (role == ROLE_UNDEFINED)
d864dd9e
EB
6497 return bgp_vty_return(vty, BGP_ERR_INVALID_ROLE_NAME);
6498 return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode));
6499}
6500
6501static int peer_role_unset_vty(struct vty *vty, const char *ip_str)
6502{
6503 struct peer *peer;
6504
7dddd1f7 6505 peer = peer_and_group_lookup_vty(vty, ip_str);
d864dd9e
EB
6506 if (!peer)
6507 return CMD_WARNING_CONFIG_FAILED;
6508 return bgp_vty_return(vty, peer_role_unset(peer));
6509}
6510
8f2d6021 6511DEFPY(neighbor_role,
d864dd9e
EB
6512 neighbor_role_cmd,
6513 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer>",
6514 NEIGHBOR_STR
6515 NEIGHBOR_ADDR_STR2
6516 "Set session role\n"
6517 ROLE_STR)
6518{
6519 int idx_peer = 1;
6520 int idx_role = 3;
6521
6522 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6523 false);
d864dd9e
EB
6524}
6525
8f2d6021 6526DEFPY(neighbor_role_strict,
d864dd9e
EB
6527 neighbor_role_strict_cmd,
6528 "neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> strict-mode",
6529 NEIGHBOR_STR
6530 NEIGHBOR_ADDR_STR2
6531 "Set session role\n"
6532 ROLE_STR
6533 "Use additional restriction on peer\n")
6534{
6535 int idx_peer = 1;
6536 int idx_role = 3;
6537
6538 return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg,
8f2d6021 6539 true);
d864dd9e
EB
6540}
6541
8f2d6021 6542DEFPY(no_neighbor_role,
d864dd9e
EB
6543 no_neighbor_role_cmd,
6544 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-role <provider|rs-server|rs-client|customer|peer> [strict-mode]",
6545 NO_STR
6546 NEIGHBOR_STR
6547 NEIGHBOR_ADDR_STR2
8f2d6021 6548 "Set session role\n"
d864dd9e 6549 ROLE_STR
8f2d6021 6550 "Use additional restriction on peer\n")
d864dd9e
EB
6551{
6552 int idx_peer = 2;
6553
6554 return peer_role_unset_vty(vty, argv[idx_peer]->arg);
6555}
6b0655a2 6556
6ffd2079 6557/* disable-connected-check */
28c6e247
IR
6558DEFUN (neighbor_disable_connected_check,
6559 neighbor_disable_connected_check_cmd,
6560 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6561 NEIGHBOR_STR
6562 NEIGHBOR_ADDR_STR2
6563 "one-hop away EBGP peer using loopback address\n"
6564 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6565{
d62a17ae 6566 int idx_peer = 1;
28c6e247
IR
6567 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6568 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6569}
6570
28c6e247
IR
6571DEFUN (no_neighbor_disable_connected_check,
6572 no_neighbor_disable_connected_check_cmd,
6573 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6574 NO_STR
6575 NEIGHBOR_STR
6576 NEIGHBOR_ADDR_STR2
6577 "one-hop away EBGP peer using loopback address\n"
6578 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6579{
d62a17ae 6580 int idx_peer = 2;
28c6e247
IR
6581 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6582 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6583}
6584
7ab294ea
DA
6585/* disable-link-bw-encoding-ieee */
6586DEFUN(neighbor_disable_link_bw_encoding_ieee,
6587 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6588 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6589 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6590 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6591{
6592 int idx_peer = 1;
6593
6594 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6595 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6596}
6597
7ab294ea
DA
6598DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6599 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6600 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6601 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6602 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6603{
6604 int idx_peer = 2;
6605
6606 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6607 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6608}
6609
d08c0c80
DA
6610/* extended-optional-parameters */
6611DEFUN(neighbor_extended_optional_parameters,
6612 neighbor_extended_optional_parameters_cmd,
6613 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6614 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6615 "Force the extended optional parameters format for OPEN messages\n")
6616{
6617 int idx_peer = 1;
6618
6619 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6620 PEER_FLAG_EXTENDED_OPT_PARAMS);
6621}
6622
6623DEFUN(no_neighbor_extended_optional_parameters,
6624 no_neighbor_extended_optional_parameters_cmd,
6625 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6627 "Force the extended optional parameters format for OPEN messages\n")
6628{
6629 int idx_peer = 2;
6630
6631 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6632 PEER_FLAG_EXTENDED_OPT_PARAMS);
6633}
47cbc09b
PM
6634
6635/* enforce-first-as */
28c6e247
IR
6636DEFUN (neighbor_enforce_first_as,
6637 neighbor_enforce_first_as_cmd,
6638 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR2
6641 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6642{
6643 int idx_peer = 1;
f4b8ec07 6644
28c6e247
IR
6645 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6646 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6647}
6648
28c6e247
IR
6649DEFUN (no_neighbor_enforce_first_as,
6650 no_neighbor_enforce_first_as_cmd,
6651 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6652 NO_STR
6653 NEIGHBOR_STR
6654 NEIGHBOR_ADDR_STR2
6655 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6656{
6657 int idx_peer = 2;
f4b8ec07 6658
28c6e247
IR
6659 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6660 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6661}
6662
6663
28c6e247
IR
6664DEFUN (neighbor_description,
6665 neighbor_description_cmd,
6666 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6667 NEIGHBOR_STR
6668 NEIGHBOR_ADDR_STR2
6669 "Neighbor specific description\n"
6670 "Up to 80 characters describing this neighbor\n")
718e3744 6671{
d62a17ae 6672 int idx_peer = 1;
6673 int idx_line = 3;
28c6e247 6674 struct peer *peer;
d62a17ae 6675 char *str;
718e3744 6676
28c6e247
IR
6677 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6678 if (!peer)
d62a17ae 6679 return CMD_WARNING_CONFIG_FAILED;
718e3744 6680
d62a17ae 6681 str = argv_concat(argv, argc, idx_line);
718e3744 6682
28c6e247 6683 peer_description_set(peer, str);
718e3744 6684
d62a17ae 6685 XFREE(MTYPE_TMP, str);
718e3744 6686
28c6e247 6687 return CMD_SUCCESS;
718e3744 6688}
6689
28c6e247
IR
6690DEFUN (no_neighbor_description,
6691 no_neighbor_description_cmd,
6692 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6693 NO_STR
6694 NEIGHBOR_STR
6695 NEIGHBOR_ADDR_STR2
6696 "Neighbor specific description\n")
718e3744 6697{
d62a17ae 6698 int idx_peer = 2;
28c6e247 6699 struct peer *peer;
f4b8ec07 6700
28c6e247
IR
6701 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6702 if (!peer)
d62a17ae 6703 return CMD_WARNING_CONFIG_FAILED;
718e3744 6704
28c6e247 6705 peer_description_unset(peer);
718e3744 6706
28c6e247 6707 return CMD_SUCCESS;
718e3744 6708}
6709
1d80f243 6710ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6711 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6713 "Neighbor specific description\n"
6714 "Up to 80 characters describing this neighbor\n")
6b0655a2 6715
28c6e247
IR
6716/* Neighbor update-source. */
6717static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6718 const char *source_str)
6719{
6720 struct peer *peer;
6721 struct prefix p;
6722 union sockunion su;
6723
6724 peer = peer_and_group_lookup_vty(vty, peer_str);
6725 if (!peer)
6726 return CMD_WARNING_CONFIG_FAILED;
6727
6728 if (peer->conf_if)
6729 return CMD_WARNING;
6730
6731 if (source_str) {
6732 if (str2sockunion(source_str, &su) == 0)
6733 peer_update_source_addr_set(peer, &su);
6734 else {
6735 if (str2prefix(source_str, &p)) {
6736 vty_out(vty,
6737 "%% Invalid update-source, remove prefix length \n");
6738 return CMD_WARNING_CONFIG_FAILED;
6739 } else
6740 peer_update_source_if_set(peer, source_str);
6741 }
6742 } else
6743 peer_update_source_unset(peer);
6744
6745 return CMD_SUCCESS;
6746}
6747
d62a17ae 6748#define BGP_UPDATE_SOURCE_HELP_STR \
6749 "IPv4 address\n" \
6750 "IPv6 address\n" \
6751 "Interface name (requires zebra to be running)\n"
369688c0 6752
28c6e247
IR
6753DEFUN (neighbor_update_source,
6754 neighbor_update_source_cmd,
6755 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6756 NEIGHBOR_STR
6757 NEIGHBOR_ADDR_STR2
6758 "Source of routing updates\n"
6759 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6760{
d62a17ae 6761 int idx_peer = 1;
6762 int idx_peer_2 = 3;
28c6e247 6763 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6764 argv[idx_peer_2]->arg);
718e3744 6765}
6766
28c6e247
IR
6767DEFUN (no_neighbor_update_source,
6768 no_neighbor_update_source_cmd,
6769 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6770 NO_STR
6771 NEIGHBOR_STR
6772 NEIGHBOR_ADDR_STR2
6773 "Source of routing updates\n"
6774 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6775{
d62a17ae 6776 int idx_peer = 2;
28c6e247 6777 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6778}
6b0655a2 6779
d62a17ae 6780static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6781 afi_t afi, safi_t safi,
6782 const char *rmap, int set)
718e3744 6783{
d62a17ae 6784 int ret;
6785 struct peer *peer;
80912664 6786 struct route_map *route_map = NULL;
718e3744 6787
d62a17ae 6788 peer = peer_and_group_lookup_vty(vty, peer_str);
6789 if (!peer)
6790 return CMD_WARNING_CONFIG_FAILED;
718e3744 6791
1de27621 6792 if (set) {
80912664
DS
6793 if (rmap)
6794 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6795 ret = peer_default_originate_set(peer, afi, safi,
6796 rmap, route_map);
6797 } else
d62a17ae 6798 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6799
d62a17ae 6800 return bgp_vty_return(vty, ret);
718e3744 6801}
6802
6803/* neighbor default-originate. */
6804DEFUN (neighbor_default_originate,
6805 neighbor_default_originate_cmd,
9ccf14f7 6806 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6807 NEIGHBOR_STR
6808 NEIGHBOR_ADDR_STR2
6809 "Originate default route to this neighbor\n")
6810{
d62a17ae 6811 int idx_peer = 1;
6812 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6813 bgp_node_afi(vty),
6814 bgp_node_safi(vty), NULL, 1);
718e3744 6815}
6816
d62a17ae 6817ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6818 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6819 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6820 "Originate default route to this neighbor\n")
596c17ba 6821
718e3744 6822DEFUN (neighbor_default_originate_rmap,
6823 neighbor_default_originate_rmap_cmd,
70dd370f 6824 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
718e3744 6825 NEIGHBOR_STR
6826 NEIGHBOR_ADDR_STR2
6827 "Originate default route to this neighbor\n"
6828 "Route-map to specify criteria to originate default\n"
6829 "route-map name\n")
6830{
d62a17ae 6831 int idx_peer = 1;
6832 int idx_word = 4;
6833 return peer_default_originate_set_vty(
6834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6835 argv[idx_word]->arg, 1);
718e3744 6836}
6837
d62a17ae 6838ALIAS_HIDDEN(
6839 neighbor_default_originate_rmap,
6840 neighbor_default_originate_rmap_hidden_cmd,
70dd370f 6841 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map RMAP_NAME",
d62a17ae 6842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6843 "Originate default route to this neighbor\n"
6844 "Route-map to specify criteria to originate default\n"
6845 "route-map name\n")
596c17ba 6846
718e3744 6847DEFUN (no_neighbor_default_originate,
6848 no_neighbor_default_originate_cmd,
70dd370f 6849 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
718e3744 6850 NO_STR
6851 NEIGHBOR_STR
6852 NEIGHBOR_ADDR_STR2
a636c635
DW
6853 "Originate default route to this neighbor\n"
6854 "Route-map to specify criteria to originate default\n"
6855 "route-map name\n")
718e3744 6856{
d62a17ae 6857 int idx_peer = 2;
6858 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6859 bgp_node_afi(vty),
6860 bgp_node_safi(vty), NULL, 0);
718e3744 6861}
6862
d62a17ae 6863ALIAS_HIDDEN(
6864 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
70dd370f 6865 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map RMAP_NAME]",
d62a17ae 6866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6867 "Originate default route to this neighbor\n"
6868 "Route-map to specify criteria to originate default\n"
6869 "route-map name\n")
596c17ba 6870
6b0655a2 6871
28c6e247
IR
6872/* Set neighbor's BGP port. */
6873static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6874 const char *port_str)
718e3744 6875{
28c6e247
IR
6876 struct peer *peer;
6877 uint16_t port;
6878 struct servent *sp;
6879
a3aecc99 6880 peer = peer_and_group_lookup_vty(vty, ip_str);
28c6e247
IR
6881 if (!peer)
6882 return CMD_WARNING_CONFIG_FAILED;
6883
6884 if (!port_str) {
6885 sp = getservbyname("bgp", "tcp");
6886 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6887 } else {
6888 port = strtoul(port_str, NULL, 10);
6889 }
718e3744 6890
28c6e247 6891 peer_port_set(peer, port);
718e3744 6892
28c6e247
IR
6893 return CMD_SUCCESS;
6894}
f4b8ec07 6895
28c6e247
IR
6896/* Set specified peer's BGP port. */
6897DEFUN (neighbor_port,
6898 neighbor_port_cmd,
a3aecc99 6899 "neighbor <A.B.C.D|X:X::X:X|WORD> port (0-65535)",
28c6e247 6900 NEIGHBOR_STR
a3aecc99 6901 NEIGHBOR_ADDR_STR2
28c6e247
IR
6902 "Neighbor's BGP port\n"
6903 "TCP port number\n")
6904{
6905 int idx_ip = 1;
6906 int idx_number = 3;
6907 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6908 argv[idx_number]->arg);
f4b8ec07 6909}
6b0655a2 6910
28c6e247
IR
6911DEFUN (no_neighbor_port,
6912 no_neighbor_port_cmd,
a3aecc99 6913 "no neighbor <A.B.C.D|X:X::X:X|WORD> port [(0-65535)]",
28c6e247
IR
6914 NO_STR
6915 NEIGHBOR_STR
a3aecc99 6916 NEIGHBOR_ADDR_STR2
28c6e247
IR
6917 "Neighbor's BGP port\n"
6918 "TCP port number\n")
718e3744 6919{
f4b8ec07 6920 int idx_ip = 2;
28c6e247
IR
6921 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6922}
6923
6924
6925/* neighbor weight. */
6926static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6927 safi_t safi, const char *weight_str)
6928{
6929 int ret;
6930 struct peer *peer;
6931 unsigned long weight;
718e3744 6932
28c6e247
IR
6933 peer = peer_and_group_lookup_vty(vty, ip_str);
6934 if (!peer)
6935 return CMD_WARNING_CONFIG_FAILED;
718e3744 6936
28c6e247 6937 weight = strtoul(weight_str, NULL, 10);
718e3744 6938
28c6e247
IR
6939 ret = peer_weight_set(peer, afi, safi, weight);
6940 return bgp_vty_return(vty, ret);
718e3744 6941}
6942
28c6e247
IR
6943static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6944 safi_t safi)
718e3744 6945{
28c6e247
IR
6946 int ret;
6947 struct peer *peer;
f4b8ec07 6948
28c6e247
IR
6949 peer = peer_and_group_lookup_vty(vty, ip_str);
6950 if (!peer)
d62a17ae 6951 return CMD_WARNING_CONFIG_FAILED;
718e3744 6952
28c6e247
IR
6953 ret = peer_weight_unset(peer, afi, safi);
6954 return bgp_vty_return(vty, ret);
6955}
f4b8ec07 6956
28c6e247
IR
6957DEFUN (neighbor_weight,
6958 neighbor_weight_cmd,
6959 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6960 NEIGHBOR_STR
6961 NEIGHBOR_ADDR_STR2
6962 "Set default weight for routes from this neighbor\n"
6963 "default weight\n")
6964{
6965 int idx_peer = 1;
6966 int idx_number = 3;
6967 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6968 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6969}
6970
d62a17ae 6971ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6972 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6974 "Set default weight for routes from this neighbor\n"
6975 "default weight\n")
596c17ba 6976
28c6e247
IR
6977DEFUN (no_neighbor_weight,
6978 no_neighbor_weight_cmd,
6979 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6980 NO_STR
6981 NEIGHBOR_STR
6982 NEIGHBOR_ADDR_STR2
6983 "Set default weight for routes from this neighbor\n"
6984 "default weight\n")
718e3744 6985{
d62a17ae 6986 int idx_peer = 2;
28c6e247
IR
6987 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6988 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6989}
6990
d62a17ae 6991ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6992 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6994 "Set default weight for routes from this neighbor\n"
6995 "default weight\n")
596c17ba 6996
6b0655a2 6997
718e3744 6998/* Override capability negotiation. */
c36bc05f
IR
6999DEFUN (neighbor_override_capability,
7000 neighbor_override_capability_cmd,
7001 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7002 NEIGHBOR_STR
7003 NEIGHBOR_ADDR_STR2
7004 "Override capability negotiation result\n")
718e3744 7005{
d62a17ae 7006 int idx_peer = 1;
c36bc05f
IR
7007 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7008 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7009}
7010
c36bc05f
IR
7011DEFUN (no_neighbor_override_capability,
7012 no_neighbor_override_capability_cmd,
7013 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7014 NO_STR
7015 NEIGHBOR_STR
7016 NEIGHBOR_ADDR_STR2
7017 "Override capability negotiation result\n")
718e3744 7018{
d62a17ae 7019 int idx_peer = 2;
c36bc05f
IR
7020 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7021 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 7022}
6b0655a2 7023
c36bc05f
IR
7024DEFUN (neighbor_strict_capability,
7025 neighbor_strict_capability_cmd,
7026 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7027 NEIGHBOR_STR
7028 NEIGHBOR_ADDR_STR2
7029 "Strict capability negotiation match\n")
718e3744 7030{
9fb964de
PM
7031 int idx_peer = 1;
7032
c36bc05f
IR
7033 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
7034 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7035}
7036
c36bc05f
IR
7037DEFUN (no_neighbor_strict_capability,
7038 no_neighbor_strict_capability_cmd,
7039 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7040 NO_STR
7041 NEIGHBOR_STR
7042 NEIGHBOR_ADDR_STR2
7043 "Strict capability negotiation match\n")
718e3744 7044{
9fb964de 7045 int idx_peer = 2;
8611c7f3 7046
c36bc05f
IR
7047 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
7048 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 7049}
6b0655a2 7050
28c6e247
IR
7051static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
7052 const char *keep_str, const char *hold_str)
718e3744 7053{
28c6e247
IR
7054 int ret;
7055 struct peer *peer;
7056 uint32_t keepalive;
7057 uint32_t holdtime;
718e3744 7058
28c6e247
IR
7059 peer = peer_and_group_lookup_vty(vty, ip_str);
7060 if (!peer)
d62a17ae 7061 return CMD_WARNING_CONFIG_FAILED;
718e3744 7062
28c6e247
IR
7063 keepalive = strtoul(keep_str, NULL, 10);
7064 holdtime = strtoul(hold_str, NULL, 10);
718e3744 7065
28c6e247 7066 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 7067
28c6e247 7068 return bgp_vty_return(vty, ret);
718e3744 7069}
6b0655a2 7070
28c6e247 7071static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7072{
28c6e247
IR
7073 int ret;
7074 struct peer *peer;
718e3744 7075
28c6e247
IR
7076 peer = peer_and_group_lookup_vty(vty, ip_str);
7077 if (!peer)
d62a17ae 7078 return CMD_WARNING_CONFIG_FAILED;
718e3744 7079
28c6e247 7080 ret = peer_timers_unset(peer);
718e3744 7081
28c6e247 7082 return bgp_vty_return(vty, ret);
718e3744 7083}
6b0655a2 7084
28c6e247
IR
7085DEFUN (neighbor_timers,
7086 neighbor_timers_cmd,
7087 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7088 NEIGHBOR_STR
7089 NEIGHBOR_ADDR_STR2
7090 "BGP per neighbor timers\n"
7091 "Keepalive interval\n"
7092 "Holdtime\n")
718e3744 7093{
f4b8ec07 7094 int idx_peer = 1;
28c6e247
IR
7095 int idx_number = 3;
7096 int idx_number_2 = 4;
7097 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
7098 argv[idx_number]->arg,
7099 argv[idx_number_2]->arg);
7100}
7101
7102DEFUN (no_neighbor_timers,
7103 no_neighbor_timers_cmd,
7104 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7105 NO_STR
7106 NEIGHBOR_STR
7107 NEIGHBOR_ADDR_STR2
7108 "BGP per neighbor timers\n"
7109 "Keepalive interval\n"
7110 "Holdtime\n")
7111{
7112 int idx_peer = 2;
7113 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
7114}
7115
7116
7117static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
7118 const char *time_str)
7119{
7120 int ret;
7121 struct peer *peer;
7122 uint32_t connect;
718e3744 7123
28c6e247
IR
7124 peer = peer_and_group_lookup_vty(vty, ip_str);
7125 if (!peer)
d62a17ae 7126 return CMD_WARNING_CONFIG_FAILED;
718e3744 7127
28c6e247
IR
7128 connect = strtoul(time_str, NULL, 10);
7129
7130 ret = peer_timers_connect_set(peer, connect);
718e3744 7131
28c6e247 7132 return bgp_vty_return(vty, ret);
718e3744 7133}
7134
28c6e247 7135static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 7136{
28c6e247
IR
7137 int ret;
7138 struct peer *peer;
718e3744 7139
28c6e247
IR
7140 peer = peer_and_group_lookup_vty(vty, ip_str);
7141 if (!peer)
d62a17ae 7142 return CMD_WARNING_CONFIG_FAILED;
718e3744 7143
28c6e247
IR
7144 ret = peer_timers_connect_unset(peer);
7145
7146 return bgp_vty_return(vty, ret);
7147}
7148
7149DEFUN (neighbor_timers_connect,
7150 neighbor_timers_connect_cmd,
7151 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7152 NEIGHBOR_STR
7153 NEIGHBOR_ADDR_STR2
7154 "BGP per neighbor timers\n"
7155 "BGP connect timer\n"
7156 "Connect timer\n")
7157{
7158 int idx_peer = 1;
7159 int idx_number = 4;
7160 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
7161 argv[idx_number]->arg);
7162}
718e3744 7163
28c6e247
IR
7164DEFUN (no_neighbor_timers_connect,
7165 no_neighbor_timers_connect_cmd,
7166 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7167 NO_STR
7168 NEIGHBOR_STR
7169 NEIGHBOR_ADDR_STR2
7170 "BGP per neighbor timers\n"
7171 "BGP connect timer\n"
7172 "Connect timer\n")
7173{
7174 int idx_peer = 2;
7175 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 7176}
7177
d43114f3
DS
7178DEFPY (neighbor_timers_delayopen,
7179 neighbor_timers_delayopen_cmd,
7180 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7181 NEIGHBOR_STR
7182 NEIGHBOR_ADDR_STR2
7183 "BGP per neighbor timers\n"
7184 "RFC 4271 DelayOpenTimer\n"
7185 "DelayOpenTime timer interval\n")
7186{
7187 struct peer *peer;
7188
7189 peer = peer_and_group_lookup_vty(vty, neighbor);
7190 if (!peer)
7191 return CMD_WARNING_CONFIG_FAILED;
7192
7193 if (!interval) {
7194 if (peer_timers_delayopen_unset(peer))
7195 return CMD_WARNING_CONFIG_FAILED;
7196 } else {
7197 if (peer_timers_delayopen_set(peer, interval))
7198 return CMD_WARNING_CONFIG_FAILED;
7199 }
7200
7201 return CMD_SUCCESS;
7202}
7203
7204DEFPY (no_neighbor_timers_delayopen,
7205 no_neighbor_timers_delayopen_cmd,
7206 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7207 NO_STR
7208 NEIGHBOR_STR
7209 NEIGHBOR_ADDR_STR2
7210 "BGP per neighbor timers\n"
7211 "RFC 4271 DelayOpenTimer\n"
7212 "DelayOpenTime timer interval\n")
7213{
7214 struct peer *peer;
7215
7216 peer = peer_and_group_lookup_vty(vty, neighbor);
7217 if (!peer)
7218 return CMD_WARNING_CONFIG_FAILED;
7219
7220 if (peer_timers_delayopen_unset(peer))
7221 return CMD_WARNING_CONFIG_FAILED;
7222
7223 return CMD_SUCCESS;
7224}
7225
28c6e247
IR
7226static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7227 const char *time_str, int set)
718e3744 7228{
28c6e247
IR
7229 int ret;
7230 struct peer *peer;
7231 uint32_t routeadv = 0;
718e3744 7232
28c6e247
IR
7233 peer = peer_and_group_lookup_vty(vty, ip_str);
7234 if (!peer)
d62a17ae 7235 return CMD_WARNING_CONFIG_FAILED;
718e3744 7236
28c6e247
IR
7237 if (time_str)
7238 routeadv = strtoul(time_str, NULL, 10);
7239
7240 if (set)
7241 ret = peer_advertise_interval_set(peer, routeadv);
7242 else
7243 ret = peer_advertise_interval_unset(peer);
718e3744 7244
28c6e247 7245 return bgp_vty_return(vty, ret);
718e3744 7246}
7247
28c6e247
IR
7248DEFUN (neighbor_advertise_interval,
7249 neighbor_advertise_interval_cmd,
7250 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7251 NEIGHBOR_STR
7252 NEIGHBOR_ADDR_STR2
7253 "Minimum interval between sending BGP routing updates\n"
7254 "time in seconds\n")
718e3744 7255{
28c6e247
IR
7256 int idx_peer = 1;
7257 int idx_number = 3;
7258 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7259 argv[idx_number]->arg, 1);
7260}
f4b8ec07 7261
28c6e247
IR
7262DEFUN (no_neighbor_advertise_interval,
7263 no_neighbor_advertise_interval_cmd,
7264 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7265 NO_STR
7266 NEIGHBOR_STR
7267 NEIGHBOR_ADDR_STR2
7268 "Minimum interval between sending BGP routing updates\n"
7269 "time in seconds\n")
7270{
7271 int idx_peer = 2;
7272 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7273}
7274
6b0655a2 7275
518f0eb1
DS
7276/* Time to wait before processing route-map updates */
7277DEFUN (bgp_set_route_map_delay_timer,
7278 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7279 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7280 SET_STR
7281 "BGP route-map delay timer\n"
7282 "Time in secs to wait before processing route-map changes\n"
f414725f 7283 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7284{
d62a17ae 7285 int idx_number = 3;
d7c0a89a 7286 uint32_t rmap_delay_timer;
d62a17ae 7287
7288 if (argv[idx_number]->arg) {
7289 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7290 bm->rmap_update_timer = rmap_delay_timer;
7291
7292 /* if the dynamic update handling is being disabled, and a timer
7293 * is
7294 * running, stop the timer and act as if the timer has already
7295 * fired.
7296 */
7297 if (!rmap_delay_timer && bm->t_rmap_update) {
fa5806c3 7298 THREAD_OFF(bm->t_rmap_update);
d62a17ae 7299 thread_execute(bm->master, bgp_route_map_update_timer,
7300 NULL, 0);
7301 }
7302 return CMD_SUCCESS;
7303 } else {
7304 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7305 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7306 }
518f0eb1
DS
7307}
7308
7309DEFUN (no_bgp_set_route_map_delay_timer,
7310 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7311 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7312 NO_STR
3a2d747c 7313 BGP_STR
518f0eb1 7314 "Default BGP route-map delay timer\n"
8334fd5a
DW
7315 "Reset to default time to wait for processing route-map changes\n"
7316 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7317{
518f0eb1 7318
d62a17ae 7319 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7320
d62a17ae 7321 return CMD_SUCCESS;
518f0eb1
DS
7322}
7323
28c6e247
IR
7324/* neighbor interface */
7325static int peer_interface_vty(struct vty *vty, const char *ip_str,
7326 const char *str)
718e3744 7327{
28c6e247 7328 struct peer *peer;
718e3744 7329
28c6e247
IR
7330 peer = peer_lookup_vty(vty, ip_str);
7331 if (!peer || peer->conf_if) {
7332 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7333 return CMD_WARNING_CONFIG_FAILED;
7334 }
718e3744 7335
28c6e247
IR
7336 if (str)
7337 peer_interface_set(peer, str);
7338 else
7339 peer_interface_unset(peer);
718e3744 7340
28c6e247 7341 return CMD_SUCCESS;
718e3744 7342}
7343
28c6e247
IR
7344DEFUN (neighbor_interface,
7345 neighbor_interface_cmd,
7346 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7347 NEIGHBOR_STR
7348 NEIGHBOR_ADDR_STR
7349 "Interface\n"
7350 "Interface name\n")
718e3744 7351{
28c6e247
IR
7352 int idx_ip = 1;
7353 int idx_word = 3;
294d8425 7354
28c6e247
IR
7355 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7356}
f4b8ec07 7357
28c6e247
IR
7358DEFUN (no_neighbor_interface,
7359 no_neighbor_interface_cmd,
294d8425 7360 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7361 NO_STR
7362 NEIGHBOR_STR
294d8425 7363 NEIGHBOR_ADDR_STR
28c6e247
IR
7364 "Interface\n"
7365 "Interface name\n")
7366{
7367 int idx_peer = 2;
294d8425 7368
28c6e247 7369 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7370}
6b0655a2 7371
718e3744 7372DEFUN (neighbor_distribute_list,
7373 neighbor_distribute_list_cmd,
c60dec36 7374 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7375 NEIGHBOR_STR
7376 NEIGHBOR_ADDR_STR2
7377 "Filter updates to/from this neighbor\n"
718e3744 7378 "IP Access-list name\n"
7379 "Filter incoming updates\n"
7380 "Filter outgoing updates\n")
7381{
d62a17ae 7382 int idx_peer = 1;
7383 int idx_acl = 3;
7384 int direct, ret;
7385 struct peer *peer;
a8206004 7386
d62a17ae 7387 const char *pstr = argv[idx_peer]->arg;
7388 const char *acl = argv[idx_acl]->arg;
7389 const char *inout = argv[argc - 1]->text;
a8206004 7390
d62a17ae 7391 peer = peer_and_group_lookup_vty(vty, pstr);
7392 if (!peer)
7393 return CMD_WARNING_CONFIG_FAILED;
a8206004 7394
d62a17ae 7395 /* Check filter direction. */
7396 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7397 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7398 direct, acl);
a8206004 7399
d62a17ae 7400 return bgp_vty_return(vty, ret);
718e3744 7401}
7402
d62a17ae 7403ALIAS_HIDDEN(
7404 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7405 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7406 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7407 "Filter updates to/from this neighbor\n"
d62a17ae 7408 "IP Access-list name\n"
7409 "Filter incoming updates\n"
7410 "Filter outgoing updates\n")
596c17ba 7411
718e3744 7412DEFUN (no_neighbor_distribute_list,
7413 no_neighbor_distribute_list_cmd,
c60dec36 7414 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7415 NO_STR
7416 NEIGHBOR_STR
7417 NEIGHBOR_ADDR_STR2
7418 "Filter updates to/from this neighbor\n"
718e3744 7419 "IP Access-list name\n"
7420 "Filter incoming updates\n"
7421 "Filter outgoing updates\n")
7422{
d62a17ae 7423 int idx_peer = 2;
7424 int direct, ret;
7425 struct peer *peer;
a8206004 7426
d62a17ae 7427 const char *pstr = argv[idx_peer]->arg;
7428 const char *inout = argv[argc - 1]->text;
a8206004 7429
d62a17ae 7430 peer = peer_and_group_lookup_vty(vty, pstr);
7431 if (!peer)
7432 return CMD_WARNING_CONFIG_FAILED;
a8206004 7433
d62a17ae 7434 /* Check filter direction. */
7435 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7436 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7437 direct);
a8206004 7438
d62a17ae 7439 return bgp_vty_return(vty, ret);
718e3744 7440}
6b0655a2 7441
d62a17ae 7442ALIAS_HIDDEN(
7443 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7444 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7445 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7446 "Filter updates to/from this neighbor\n"
d62a17ae 7447 "IP Access-list name\n"
7448 "Filter incoming updates\n"
7449 "Filter outgoing updates\n")
596c17ba 7450
718e3744 7451/* Set prefix list to the peer. */
642ef664
IR
7452static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7453 afi_t afi, safi_t safi,
7454 const char *name_str,
7455 const char *direct_str)
718e3744 7456{
642ef664
IR
7457 int ret;
7458 int direct = FILTER_IN;
7459 struct peer *peer;
718e3744 7460
642ef664
IR
7461 peer = peer_and_group_lookup_vty(vty, ip_str);
7462 if (!peer)
d62a17ae 7463 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7464
642ef664
IR
7465 /* Check filter direction. */
7466 if (strncmp(direct_str, "i", 1) == 0)
7467 direct = FILTER_IN;
7468 else if (strncmp(direct_str, "o", 1) == 0)
7469 direct = FILTER_OUT;
718e3744 7470
642ef664 7471 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7472
642ef664
IR
7473 return bgp_vty_return(vty, ret);
7474}
7475
7476static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7477 afi_t afi, safi_t safi,
7478 const char *direct_str)
7479{
7480 int ret;
7481 struct peer *peer;
7482 int direct = FILTER_IN;
7483
7484 peer = peer_and_group_lookup_vty(vty, ip_str);
7485 if (!peer)
7486 return CMD_WARNING_CONFIG_FAILED;
7487
7488 /* Check filter direction. */
7489 if (strncmp(direct_str, "i", 1) == 0)
7490 direct = FILTER_IN;
7491 else if (strncmp(direct_str, "o", 1) == 0)
7492 direct = FILTER_OUT;
7493
7494 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7495
7496 return bgp_vty_return(vty, ret);
7497}
7498
7499DEFUN (neighbor_prefix_list,
7500 neighbor_prefix_list_cmd,
7501 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7502 NEIGHBOR_STR
7503 NEIGHBOR_ADDR_STR2
7504 "Filter updates to/from this neighbor\n"
7505 "Name of a prefix list\n"
7506 "Filter incoming updates\n"
7507 "Filter outgoing updates\n")
7508{
7509 int idx_peer = 1;
7510 int idx_word = 3;
7511 int idx_in_out = 4;
7512 return peer_prefix_list_set_vty(
7513 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7514 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7515}
7516
d62a17ae 7517ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7518 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7519 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7520 "Filter updates to/from this neighbor\n"
7521 "Name of a prefix list\n"
7522 "Filter incoming updates\n"
7523 "Filter outgoing updates\n")
596c17ba 7524
642ef664
IR
7525DEFUN (no_neighbor_prefix_list,
7526 no_neighbor_prefix_list_cmd,
7527 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7528 NO_STR
7529 NEIGHBOR_STR
7530 NEIGHBOR_ADDR_STR2
7531 "Filter updates to/from this neighbor\n"
7532 "Name of a prefix list\n"
7533 "Filter incoming updates\n"
7534 "Filter outgoing updates\n")
7535{
7536 int idx_peer = 2;
7537 int idx_in_out = 5;
7538 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7539 bgp_node_afi(vty), bgp_node_safi(vty),
7540 argv[idx_in_out]->arg);
7541}
7542
7543ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7544 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7545 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7546 "Filter updates to/from this neighbor\n"
7547 "Name of a prefix list\n"
7548 "Filter incoming updates\n"
7549 "Filter outgoing updates\n")
7550
d62a17ae 7551static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7552 safi_t safi, const char *name_str,
7553 const char *direct_str)
718e3744 7554{
d62a17ae 7555 int ret;
7556 struct peer *peer;
7557 int direct = FILTER_IN;
718e3744 7558
d62a17ae 7559 peer = peer_and_group_lookup_vty(vty, ip_str);
7560 if (!peer)
7561 return CMD_WARNING_CONFIG_FAILED;
718e3744 7562
d62a17ae 7563 /* Check filter direction. */
7564 if (strncmp(direct_str, "i", 1) == 0)
7565 direct = FILTER_IN;
7566 else if (strncmp(direct_str, "o", 1) == 0)
7567 direct = FILTER_OUT;
718e3744 7568
d62a17ae 7569 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7570
d62a17ae 7571 return bgp_vty_return(vty, ret);
718e3744 7572}
7573
d62a17ae 7574static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7575 safi_t safi, const char *direct_str)
718e3744 7576{
d62a17ae 7577 int ret;
7578 struct peer *peer;
7579 int direct = FILTER_IN;
718e3744 7580
d62a17ae 7581 peer = peer_and_group_lookup_vty(vty, ip_str);
7582 if (!peer)
7583 return CMD_WARNING_CONFIG_FAILED;
718e3744 7584
d62a17ae 7585 /* Check filter direction. */
7586 if (strncmp(direct_str, "i", 1) == 0)
7587 direct = FILTER_IN;
7588 else if (strncmp(direct_str, "o", 1) == 0)
7589 direct = FILTER_OUT;
718e3744 7590
d62a17ae 7591 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7592
d62a17ae 7593 return bgp_vty_return(vty, ret);
718e3744 7594}
7595
7596DEFUN (neighbor_filter_list,
7597 neighbor_filter_list_cmd,
de71d43e 7598 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7599 NEIGHBOR_STR
7600 NEIGHBOR_ADDR_STR2
7601 "Establish BGP filters\n"
7602 "AS path access-list name\n"
7603 "Filter incoming routes\n"
7604 "Filter outgoing routes\n")
7605{
d62a17ae 7606 int idx_peer = 1;
7607 int idx_word = 3;
7608 int idx_in_out = 4;
7609 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7610 bgp_node_safi(vty), argv[idx_word]->arg,
7611 argv[idx_in_out]->arg);
718e3744 7612}
7613
d62a17ae 7614ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7615 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7616 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7617 "Establish BGP filters\n"
7618 "AS path access-list name\n"
7619 "Filter incoming routes\n"
7620 "Filter outgoing routes\n")
596c17ba 7621
718e3744 7622DEFUN (no_neighbor_filter_list,
7623 no_neighbor_filter_list_cmd,
de71d43e 7624 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7625 NO_STR
7626 NEIGHBOR_STR
7627 NEIGHBOR_ADDR_STR2
7628 "Establish BGP filters\n"
7629 "AS path access-list name\n"
7630 "Filter incoming routes\n"
7631 "Filter outgoing routes\n")
7632{
d62a17ae 7633 int idx_peer = 2;
7634 int idx_in_out = 5;
7635 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7636 bgp_node_afi(vty), bgp_node_safi(vty),
7637 argv[idx_in_out]->arg);
718e3744 7638}
6b0655a2 7639
d62a17ae 7640ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7641 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7643 "Establish BGP filters\n"
7644 "AS path access-list name\n"
7645 "Filter incoming routes\n"
7646 "Filter outgoing routes\n")
596c17ba 7647
7f7940e6
MK
7648/* Set advertise-map to the peer. */
7649static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7650 afi_t afi, safi_t safi,
cf2ad4d8
MK
7651 const char *advertise_str,
7652 const char *condition_str, bool condition,
7653 bool set)
7f7940e6
MK
7654{
7655 int ret = CMD_WARNING_CONFIG_FAILED;
7656 struct peer *peer;
7657 struct route_map *advertise_map;
7658 struct route_map *condition_map;
7659
7660 peer = peer_and_group_lookup_vty(vty, ip_str);
7661 if (!peer)
7662 return ret;
7663
7664 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7665 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7666
cf2ad4d8
MK
7667 if (set)
7668 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7669 advertise_map, condition_str,
7670 condition_map, condition);
7671 else
7672 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7673 advertise_map, condition_str,
7674 condition_map, condition);
7f7940e6
MK
7675
7676 return bgp_vty_return(vty, ret);
7677}
7678
389e4f92
QY
7679DEFPY (bgp_condadv_period,
7680 bgp_condadv_period_cmd,
7681 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7682 NO_STR
7683 BGP_STR
7684 "Conditional advertisement settings\n"
7685 "Set period to rescan BGP table to check if condition is met\n"
7686 "Period between BGP table scans, in seconds; default 60\n")
7687{
7688 VTY_DECLVAR_CONTEXT(bgp, bgp);
7689
7690 bgp->condition_check_period =
7691 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7692
7693 return CMD_SUCCESS;
7694}
7695
cf2ad4d8 7696DEFPY (neighbor_advertise_map,
7f7940e6 7697 neighbor_advertise_map_cmd,
3ccddc25 7698 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
cf2ad4d8 7699 NO_STR
7f7940e6
MK
7700 NEIGHBOR_STR
7701 NEIGHBOR_ADDR_STR2
7702 "Route-map to conditionally advertise routes\n"
7703 "Name of advertise map\n"
7704 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7705 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7706 "Name of the exist or non exist map\n")
7f7940e6 7707{
7f7940e6
MK
7708 bool condition = CONDITION_EXIST;
7709
52b84062 7710 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7711 condition = CONDITION_NON_EXIST;
7712
52b84062
MK
7713 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7714 bgp_node_safi(vty), advertise_str,
7715 condition_str, condition, !no);
7f7940e6
MK
7716}
7717
7718ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7719 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map RMAP_NAME$advertise_str <exist-map|non-exist-map>$exist RMAP_NAME$condition_str",
7f7940e6
MK
7720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7721 "Route-map to conditionally advertise routes\n"
7722 "Name of advertise map\n"
7723 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7724 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7725 "Name of the exist or non exist map\n")
7f7940e6 7726
718e3744 7727/* Set route-map to the peer. */
0ea8d871
IR
7728static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7729 afi_t afi, safi_t safi, const char *name_str,
7730 const char *direct_str)
718e3744 7731{
0ea8d871
IR
7732 int ret;
7733 struct peer *peer;
7734 int direct = RMAP_IN;
7735 struct route_map *route_map;
718e3744 7736
0ea8d871
IR
7737 peer = peer_and_group_lookup_vty(vty, ip_str);
7738 if (!peer)
d62a17ae 7739 return CMD_WARNING_CONFIG_FAILED;
718e3744 7740
0ea8d871
IR
7741 /* Check filter direction. */
7742 if (strncmp(direct_str, "in", 2) == 0)
7743 direct = RMAP_IN;
7744 else if (strncmp(direct_str, "o", 1) == 0)
7745 direct = RMAP_OUT;
718e3744 7746
0ea8d871
IR
7747 route_map = route_map_lookup_warn_noexist(vty, name_str);
7748 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7749
0ea8d871
IR
7750 return bgp_vty_return(vty, ret);
7751}
7752
7753static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7754 afi_t afi, safi_t safi,
7755 const char *direct_str)
7756{
7757 int ret;
7758 struct peer *peer;
7759 int direct = RMAP_IN;
7760
7761 peer = peer_and_group_lookup_vty(vty, ip_str);
7762 if (!peer)
7763 return CMD_WARNING_CONFIG_FAILED;
7764
7765 /* Check filter direction. */
7766 if (strncmp(direct_str, "in", 2) == 0)
7767 direct = RMAP_IN;
7768 else if (strncmp(direct_str, "o", 1) == 0)
7769 direct = RMAP_OUT;
7770
7771 ret = peer_route_map_unset(peer, afi, safi, direct);
7772
7773 return bgp_vty_return(vty, ret);
7774}
7775
7776DEFUN (neighbor_route_map,
7777 neighbor_route_map_cmd,
70dd370f 7778 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7779 NEIGHBOR_STR
7780 NEIGHBOR_ADDR_STR2
7781 "Apply route map to neighbor\n"
7782 "Name of route map\n"
7783 "Apply map to incoming routes\n"
7784 "Apply map to outbound routes\n")
7785{
7786 int idx_peer = 1;
7787 int idx_word = 3;
7788 int idx_in_out = 4;
7789 return peer_route_map_set_vty(
7790 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7791 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7792}
7793
d6d7ed37 7794ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
70dd370f 7795 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7797 "Apply route map to neighbor\n"
7798 "Name of route map\n"
7799 "Apply map to incoming routes\n"
7800 "Apply map to outbound routes\n")
7801
0ea8d871
IR
7802DEFUN (no_neighbor_route_map,
7803 no_neighbor_route_map_cmd,
70dd370f 7804 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
0ea8d871
IR
7805 NO_STR
7806 NEIGHBOR_STR
7807 NEIGHBOR_ADDR_STR2
7808 "Apply route map to neighbor\n"
7809 "Name of route map\n"
7810 "Apply map to incoming routes\n"
7811 "Apply map to outbound routes\n")
7812{
7813 int idx_peer = 2;
7814 int idx_in_out = 5;
7815 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7816 bgp_node_afi(vty), bgp_node_safi(vty),
7817 argv[idx_in_out]->arg);
7818}
7819
7820ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
70dd370f 7821 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map RMAP_NAME <in|out>",
d6d7ed37
IR
7822 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7823 "Apply route map to neighbor\n"
7824 "Name of route map\n"
7825 "Apply map to incoming routes\n"
7826 "Apply map to outbound routes\n")
7827
718e3744 7828/* Set unsuppress-map to the peer. */
d62a17ae 7829static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7830 afi_t afi, safi_t safi,
7831 const char *name_str)
718e3744 7832{
d62a17ae 7833 int ret;
7834 struct peer *peer;
1de27621 7835 struct route_map *route_map;
718e3744 7836
d62a17ae 7837 peer = peer_and_group_lookup_vty(vty, ip_str);
7838 if (!peer)
7839 return CMD_WARNING_CONFIG_FAILED;
718e3744 7840
1de27621
DA
7841 route_map = route_map_lookup_warn_noexist(vty, name_str);
7842 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7843
d62a17ae 7844 return bgp_vty_return(vty, ret);
718e3744 7845}
7846
7847/* Unset route-map from the peer. */
d62a17ae 7848static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7849 afi_t afi, safi_t safi)
718e3744 7850{
d62a17ae 7851 int ret;
7852 struct peer *peer;
718e3744 7853
d62a17ae 7854 peer = peer_and_group_lookup_vty(vty, ip_str);
7855 if (!peer)
7856 return CMD_WARNING_CONFIG_FAILED;
718e3744 7857
d62a17ae 7858 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7859
d62a17ae 7860 return bgp_vty_return(vty, ret);
718e3744 7861}
7862
7863DEFUN (neighbor_unsuppress_map,
7864 neighbor_unsuppress_map_cmd,
9ccf14f7 7865 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7866 NEIGHBOR_STR
7867 NEIGHBOR_ADDR_STR2
7868 "Route-map to selectively unsuppress suppressed routes\n"
7869 "Name of route map\n")
7870{
d62a17ae 7871 int idx_peer = 1;
7872 int idx_word = 3;
7873 return peer_unsuppress_map_set_vty(
7874 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7875 argv[idx_word]->arg);
718e3744 7876}
7877
d62a17ae 7878ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7879 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7881 "Route-map to selectively unsuppress suppressed routes\n"
7882 "Name of route map\n")
596c17ba 7883
718e3744 7884DEFUN (no_neighbor_unsuppress_map,
7885 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7886 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7887 NO_STR
7888 NEIGHBOR_STR
7889 NEIGHBOR_ADDR_STR2
7890 "Route-map to selectively unsuppress suppressed routes\n"
7891 "Name of route map\n")
7892{
d62a17ae 7893 int idx_peer = 2;
7894 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7895 bgp_node_afi(vty),
7896 bgp_node_safi(vty));
718e3744 7897}
6b0655a2 7898
d62a17ae 7899ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7900 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7902 "Route-map to selectively unsuppress suppressed routes\n"
7903 "Name of route map\n")
596c17ba 7904
7e62b792
IR
7905static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7906 afi_t afi, safi_t safi,
7907 const char *num_str,
7908 const char *threshold_str, int warning,
7909 const char *restart_str,
7910 const char *force_str)
7911{
7912 int ret;
7913 struct peer *peer;
7914 uint32_t max;
7915 uint8_t threshold;
7916 uint16_t restart;
7917
7918 peer = peer_and_group_lookup_vty(vty, ip_str);
7919 if (!peer)
7920 return CMD_WARNING_CONFIG_FAILED;
7921
7922 max = strtoul(num_str, NULL, 10);
7923 if (threshold_str)
7924 threshold = atoi(threshold_str);
7925 else
7926 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7927
7928 if (restart_str)
7929 restart = atoi(restart_str);
7930 else
7931 restart = 0;
7932
7933 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7934 restart, force_str ? true : false);
7935
7936 return bgp_vty_return(vty, ret);
7937}
7938
7939static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7940 afi_t afi, safi_t safi)
7941{
7942 int ret;
7943 struct peer *peer;
7944
7945 peer = peer_and_group_lookup_vty(vty, ip_str);
7946 if (!peer)
7947 return CMD_WARNING_CONFIG_FAILED;
7948
7949 ret = peer_maximum_prefix_unset(peer, afi, safi);
7950
7951 return bgp_vty_return(vty, ret);
7952}
7953
fde246e8 7954/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7955DEFUN(neighbor_maximum_prefix_out,
7956 neighbor_maximum_prefix_out_cmd,
7957 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7958 NEIGHBOR_STR
7959 NEIGHBOR_ADDR_STR2
7960 "Maximum number of prefixes to be sent to this peer\n"
7961 "Maximum no. of prefix limit\n")
fde246e8 7962{
80444d30 7963 int ret;
fde246e8
DA
7964 int idx_peer = 1;
7965 int idx_number = 3;
7e62b792
IR
7966 struct peer *peer;
7967 uint32_t max;
fde246e8
DA
7968 afi_t afi = bgp_node_afi(vty);
7969 safi_t safi = bgp_node_safi(vty);
7970
7e62b792
IR
7971 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7972 if (!peer)
fde246e8
DA
7973 return CMD_WARNING_CONFIG_FAILED;
7974
7e62b792 7975 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7976
80444d30 7977 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7978
80444d30 7979 return bgp_vty_return(vty, ret);
fde246e8
DA
7980}
7981
1d80f243
IR
7982DEFUN(no_neighbor_maximum_prefix_out,
7983 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7984 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7985 NO_STR
7986 NEIGHBOR_STR
7987 NEIGHBOR_ADDR_STR2
bc03c622
LS
7988 "Maximum number of prefixes to be sent to this peer\n"
7989 "Maximum no. of prefix limit\n")
fde246e8 7990{
80444d30 7991 int ret;
fde246e8 7992 int idx_peer = 2;
7e62b792 7993 struct peer *peer;
fde246e8
DA
7994 afi_t afi = bgp_node_afi(vty);
7995 safi_t safi = bgp_node_safi(vty);
7996
7e62b792
IR
7997 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7998 if (!peer)
fde246e8
DA
7999 return CMD_WARNING_CONFIG_FAILED;
8000
80444d30 8001 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 8002
80444d30 8003 return bgp_vty_return(vty, ret);
fde246e8
DA
8004}
8005
9cbd06e0
DA
8006/* Maximum number of prefix configuration. Prefix count is different
8007 for each peer configuration. So this configuration can be set for
718e3744 8008 each peer configuration. */
1d80f243
IR
8009DEFUN (neighbor_maximum_prefix,
8010 neighbor_maximum_prefix_cmd,
8011 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8012 NEIGHBOR_STR
8013 NEIGHBOR_ADDR_STR2
8014 "Maximum number of prefix accept from this peer\n"
8015 "maximum no. of prefix limit\n"
8016 "Force checking all received routes not only accepted\n")
718e3744 8017{
d62a17ae 8018 int idx_peer = 1;
8019 int idx_number = 3;
9cbd06e0 8020 int idx_force = 0;
7e62b792 8021 char *force = NULL;
9cbd06e0
DA
8022
8023 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8024 force = argv[idx_force]->arg;
9cbd06e0 8025
7e62b792
IR
8026 return peer_maximum_prefix_set_vty(
8027 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8028 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 8029}
8030
d62a17ae 8031ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8033 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8034 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8035 "maximum no. of prefix limit\n"
8036 "Force checking all received routes not only accepted\n")
596c17ba 8037
1d80f243
IR
8038DEFUN (neighbor_maximum_prefix_threshold,
8039 neighbor_maximum_prefix_threshold_cmd,
8040 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8041 NEIGHBOR_STR
8042 NEIGHBOR_ADDR_STR2
8043 "Maximum number of prefix accept from this peer\n"
8044 "maximum no. of prefix limit\n"
8045 "Threshold value (%) at which to generate a warning msg\n"
8046 "Force checking all received routes not only accepted\n")
e0701b79 8047{
d62a17ae 8048 int idx_peer = 1;
8049 int idx_number = 3;
8050 int idx_number_2 = 4;
9cbd06e0 8051 int idx_force = 0;
7e62b792 8052 char *force = NULL;
9cbd06e0
DA
8053
8054 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8055 force = argv[idx_force]->arg;
9cbd06e0 8056
7e62b792
IR
8057 return peer_maximum_prefix_set_vty(
8058 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8059 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 8060}
e0701b79 8061
d62a17ae 8062ALIAS_HIDDEN(
8063 neighbor_maximum_prefix_threshold,
8064 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8065 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8067 "Maximum number of prefix accept from this peer\n"
8068 "maximum no. of prefix limit\n"
9cbd06e0
DA
8069 "Threshold value (%) at which to generate a warning msg\n"
8070 "Force checking all received routes not only accepted\n")
596c17ba 8071
1d80f243
IR
8072DEFUN (neighbor_maximum_prefix_warning,
8073 neighbor_maximum_prefix_warning_cmd,
8074 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8075 NEIGHBOR_STR
8076 NEIGHBOR_ADDR_STR2
8077 "Maximum number of prefix accept from this peer\n"
8078 "maximum no. of prefix limit\n"
8079 "Only give warning message when limit is exceeded\n"
8080 "Force checking all received routes not only accepted\n")
718e3744 8081{
d62a17ae 8082 int idx_peer = 1;
8083 int idx_number = 3;
9cbd06e0 8084 int idx_force = 0;
7e62b792 8085 char *force = NULL;
9cbd06e0
DA
8086
8087 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8088 force = argv[idx_force]->arg;
9cbd06e0 8089
7e62b792
IR
8090 return peer_maximum_prefix_set_vty(
8091 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8092 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 8093}
8094
d62a17ae 8095ALIAS_HIDDEN(
8096 neighbor_maximum_prefix_warning,
8097 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8098 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8099 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8100 "Maximum number of prefix accept from this peer\n"
8101 "maximum no. of prefix limit\n"
9cbd06e0
DA
8102 "Only give warning message when limit is exceeded\n"
8103 "Force checking all received routes not only accepted\n")
596c17ba 8104
1d80f243
IR
8105DEFUN (neighbor_maximum_prefix_threshold_warning,
8106 neighbor_maximum_prefix_threshold_warning_cmd,
8107 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8108 NEIGHBOR_STR
8109 NEIGHBOR_ADDR_STR2
8110 "Maximum number of prefix accept from this peer\n"
8111 "maximum no. of prefix limit\n"
8112 "Threshold value (%) at which to generate a warning msg\n"
8113 "Only give warning message when limit is exceeded\n"
8114 "Force checking all received routes not only accepted\n")
e0701b79 8115{
d62a17ae 8116 int idx_peer = 1;
8117 int idx_number = 3;
8118 int idx_number_2 = 4;
9cbd06e0 8119 int idx_force = 0;
7e62b792 8120 char *force = NULL;
9cbd06e0
DA
8121
8122 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8123 force = argv[idx_force]->arg;
9cbd06e0 8124
7e62b792
IR
8125 return peer_maximum_prefix_set_vty(
8126 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8127 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 8128}
8129
d62a17ae 8130ALIAS_HIDDEN(
8131 neighbor_maximum_prefix_threshold_warning,
8132 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8133 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8134 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8135 "Maximum number of prefix accept from this peer\n"
8136 "maximum no. of prefix limit\n"
8137 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8138 "Only give warning message when limit is exceeded\n"
8139 "Force checking all received routes not only accepted\n")
596c17ba 8140
1d80f243
IR
8141DEFUN (neighbor_maximum_prefix_restart,
8142 neighbor_maximum_prefix_restart_cmd,
8143 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8144 NEIGHBOR_STR
8145 NEIGHBOR_ADDR_STR2
8146 "Maximum number of prefix accept from this peer\n"
8147 "maximum no. of prefix limit\n"
8148 "Restart bgp connection after limit is exceeded\n"
8149 "Restart interval in minutes\n"
8150 "Force checking all received routes not only accepted\n")
0a486e5f 8151{
d62a17ae 8152 int idx_peer = 1;
8153 int idx_number = 3;
8154 int idx_number_2 = 5;
9cbd06e0 8155 int idx_force = 0;
7e62b792 8156 char *force = NULL;
9cbd06e0
DA
8157
8158 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8159 force = argv[idx_force]->arg;
9cbd06e0 8160
7e62b792
IR
8161 return peer_maximum_prefix_set_vty(
8162 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8163 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 8164}
8165
d62a17ae 8166ALIAS_HIDDEN(
8167 neighbor_maximum_prefix_restart,
8168 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8169 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8170 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8171 "Maximum number of prefix accept from this peer\n"
8172 "maximum no. of prefix limit\n"
8173 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8174 "Restart interval in minutes\n"
8175 "Force checking all received routes not only accepted\n")
596c17ba 8176
1d80f243
IR
8177DEFUN (neighbor_maximum_prefix_threshold_restart,
8178 neighbor_maximum_prefix_threshold_restart_cmd,
8179 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8180 NEIGHBOR_STR
8181 NEIGHBOR_ADDR_STR2
8182 "Maximum number of prefixes to accept from this peer\n"
8183 "maximum no. of prefix limit\n"
8184 "Threshold value (%) at which to generate a warning msg\n"
8185 "Restart bgp connection after limit is exceeded\n"
8186 "Restart interval in minutes\n"
8187 "Force checking all received routes not only accepted\n")
0a486e5f 8188{
d62a17ae 8189 int idx_peer = 1;
8190 int idx_number = 3;
8191 int idx_number_2 = 4;
8192 int idx_number_3 = 6;
9cbd06e0 8193 int idx_force = 0;
7e62b792 8194 char *force = NULL;
9cbd06e0
DA
8195
8196 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8197 force = argv[idx_force]->arg;
9cbd06e0 8198
7e62b792
IR
8199 return peer_maximum_prefix_set_vty(
8200 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8201 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8202 argv[idx_number_3]->arg, force);
d62a17ae 8203}
8204
8205ALIAS_HIDDEN(
8206 neighbor_maximum_prefix_threshold_restart,
8207 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8208 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8210 "Maximum number of prefixes to accept from this peer\n"
8211 "maximum no. of prefix limit\n"
8212 "Threshold value (%) at which to generate a warning msg\n"
8213 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8214 "Restart interval in minutes\n"
8215 "Force checking all received routes not only accepted\n")
596c17ba 8216
1d80f243
IR
8217DEFUN (no_neighbor_maximum_prefix,
8218 no_neighbor_maximum_prefix_cmd,
8219 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8220 NO_STR
8221 NEIGHBOR_STR
8222 NEIGHBOR_ADDR_STR2
8223 "Maximum number of prefixes to accept from this peer\n"
8224 "maximum no. of prefix limit\n"
8225 "Threshold value (%) at which to generate a warning msg\n"
8226 "Restart bgp connection after limit is exceeded\n"
8227 "Restart interval in minutes\n"
8228 "Only give warning message when limit is exceeded\n"
8229 "Force checking all received routes not only accepted\n")
718e3744 8230{
d62a17ae 8231 int idx_peer = 2;
7e62b792
IR
8232 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8233 bgp_node_afi(vty),
8234 bgp_node_safi(vty));
718e3744 8235}
e52702f2 8236
d62a17ae 8237ALIAS_HIDDEN(
8238 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8239 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8240 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8241 "Maximum number of prefixes to accept from this peer\n"
8242 "maximum no. of prefix limit\n"
8243 "Threshold value (%) at which to generate a warning msg\n"
8244 "Restart bgp connection after limit is exceeded\n"
8245 "Restart interval in minutes\n"
9cbd06e0
DA
8246 "Only give warning message when limit is exceeded\n"
8247 "Force checking all received routes not only accepted\n")
596c17ba 8248
01da2d26
DA
8249/* "neighbor soo" */
8250DEFPY (neighbor_soo,
8251 neighbor_soo_cmd,
8252 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo ASN:NN_OR_IP-ADDRESS:NN$soo",
8253 NEIGHBOR_STR
8254 NEIGHBOR_ADDR_STR2
8255 "Set the Site-of-Origin (SoO) extended community\n"
8256 "VPN extended community\n")
8257{
8258 struct peer *peer;
8259 afi_t afi = bgp_node_afi(vty);
8260 safi_t safi = bgp_node_safi(vty);
8261 struct ecommunity *ecomm_soo;
8262
8263 peer = peer_and_group_lookup_vty(vty, neighbor);
8264 if (!peer)
8265 return CMD_WARNING_CONFIG_FAILED;
8266
8267 ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0);
8268 if (!ecomm_soo) {
8269 vty_out(vty, "%% Malformed SoO extended community\n");
8270 return CMD_WARNING;
8271 }
8272 ecommunity_str(ecomm_soo);
8273
8274 if (!ecommunity_match(peer->soo[afi][safi], ecomm_soo)) {
8275 ecommunity_free(&peer->soo[afi][safi]);
8276 peer->soo[afi][safi] = ecomm_soo;
8277 peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO);
8278 }
8279
8280 return bgp_vty_return(vty,
8281 peer_af_flag_set(peer, afi, safi, PEER_FLAG_SOO));
8282}
8283
8284DEFPY (no_neighbor_soo,
8285 no_neighbor_soo_cmd,
8286 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor soo [ASN:NN_OR_IP-ADDRESS:NN$soo]",
8287 NO_STR
8288 NEIGHBOR_STR
8289 NEIGHBOR_ADDR_STR2
8290 "Set the Site-of-Origin (SoO) extended community\n"
8291 "VPN extended community\n")
8292{
8293 struct peer *peer;
8294 afi_t afi = bgp_node_afi(vty);
8295 safi_t safi = bgp_node_safi(vty);
8296
8297 peer = peer_and_group_lookup_vty(vty, neighbor);
8298 if (!peer)
8299 return CMD_WARNING_CONFIG_FAILED;
8300
8301 ecommunity_free(&peer->soo[afi][safi]);
8302
8303 return bgp_vty_return(
8304 vty, peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO));
8305}
718e3744 8306
718e3744 8307/* "neighbor allowas-in" */
8308DEFUN (neighbor_allowas_in,
8309 neighbor_allowas_in_cmd,
fd8503f5 8310 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8311 NEIGHBOR_STR
8312 NEIGHBOR_ADDR_STR2
31500417 8313 "Accept as-path with my AS present in it\n"
f79f7a7b 8314 "Number of occurrences of AS number\n"
fd8503f5 8315 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8316{
d62a17ae 8317 int idx_peer = 1;
8318 int idx_number_origin = 3;
8319 int ret;
8320 int origin = 0;
8321 struct peer *peer;
8322 int allow_num = 0;
8323
8324 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8325 if (!peer)
8326 return CMD_WARNING_CONFIG_FAILED;
8327
8328 if (argc <= idx_number_origin)
8329 allow_num = 3;
8330 else {
8331 if (argv[idx_number_origin]->type == WORD_TKN)
8332 origin = 1;
8333 else
8334 allow_num = atoi(argv[idx_number_origin]->arg);
8335 }
8336
8337 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8338 allow_num, origin);
8339
8340 return bgp_vty_return(vty, ret);
8341}
8342
8343ALIAS_HIDDEN(
8344 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8345 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8347 "Accept as-path with my AS present in it\n"
f79f7a7b 8348 "Number of occurrences of AS number\n"
d62a17ae 8349 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8350
718e3744 8351DEFUN (no_neighbor_allowas_in,
8352 no_neighbor_allowas_in_cmd,
fd8503f5 8353 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8354 NO_STR
8355 NEIGHBOR_STR
8356 NEIGHBOR_ADDR_STR2
8334fd5a 8357 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8358 "Number of occurrences of AS number\n"
fd8503f5 8359 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8360{
d62a17ae 8361 int idx_peer = 2;
8362 int ret;
8363 struct peer *peer;
718e3744 8364
d62a17ae 8365 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8366 if (!peer)
8367 return CMD_WARNING_CONFIG_FAILED;
718e3744 8368
d62a17ae 8369 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8370 bgp_node_safi(vty));
718e3744 8371
d62a17ae 8372 return bgp_vty_return(vty, ret);
718e3744 8373}
6b0655a2 8374
d62a17ae 8375ALIAS_HIDDEN(
8376 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8377 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8378 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8379 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8380 "Number of occurrences of AS number\n"
d62a17ae 8381 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8382
28c6e247
IR
8383DEFUN (neighbor_ttl_security,
8384 neighbor_ttl_security_cmd,
8385 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8386 NEIGHBOR_STR
8387 NEIGHBOR_ADDR_STR2
8388 "BGP ttl-security parameters\n"
8389 "Specify the maximum number of hops to the BGP peer\n"
8390 "Number of hops to BGP peer\n")
fa411a21 8391{
d62a17ae 8392 int idx_peer = 1;
8393 int idx_number = 4;
28c6e247
IR
8394 struct peer *peer;
8395 int gtsm_hops;
d62a17ae 8396
28c6e247
IR
8397 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8398 if (!peer)
d62a17ae 8399 return CMD_WARNING_CONFIG_FAILED;
8400
28c6e247
IR
8401 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8402
8403 /*
8404 * If 'neighbor swpX', then this is for directly connected peers,
8405 * we should not accept a ttl-security hops value greater than 1.
8406 */
8407 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8408 vty_out(vty,
8409 "%s is directly connected peer, hops cannot exceed 1\n",
8410 argv[idx_peer]->arg);
8411 return CMD_WARNING_CONFIG_FAILED;
8412 }
7ebe625c 8413
28c6e247 8414 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8415}
8416
1d80f243
IR
8417DEFUN (no_neighbor_ttl_security,
8418 no_neighbor_ttl_security_cmd,
8419 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8420 NO_STR
8421 NEIGHBOR_STR
8422 NEIGHBOR_ADDR_STR2
8423 "BGP ttl-security parameters\n"
8424 "Specify the maximum number of hops to the BGP peer\n"
8425 "Number of hops to BGP peer\n")
fa411a21 8426{
d62a17ae 8427 int idx_peer = 2;
28c6e247 8428 struct peer *peer;
fa411a21 8429
28c6e247
IR
8430 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8431 if (!peer)
d62a17ae 8432 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8433
28c6e247 8434 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8435}
6b0655a2 8436
7c0e4312
DA
8437/* disable-addpath-rx */
8438DEFUN(neighbor_disable_addpath_rx,
8439 neighbor_disable_addpath_rx_cmd,
8440 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8441 NEIGHBOR_STR
8442 NEIGHBOR_ADDR_STR2
8443 "Do not accept additional paths\n")
8444{
8445 char *peer_str = argv[1]->arg;
8446 struct peer *peer;
8447 afi_t afi = bgp_node_afi(vty);
8448 safi_t safi = bgp_node_safi(vty);
8449
8450 peer = peer_and_group_lookup_vty(vty, peer_str);
8451 if (!peer)
8452 return CMD_WARNING_CONFIG_FAILED;
8453
8454 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8455 PEER_FLAG_DISABLE_ADDPATH_RX);
8456}
8457
8458DEFUN(no_neighbor_disable_addpath_rx,
8459 no_neighbor_disable_addpath_rx_cmd,
8460 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8461 NO_STR
8462 NEIGHBOR_STR
8463 NEIGHBOR_ADDR_STR2
8464 "Do not accept additional paths\n")
8465{
8466 char *peer_str = argv[2]->arg;
8467 struct peer *peer;
8468 afi_t afi = bgp_node_afi(vty);
8469 safi_t safi = bgp_node_safi(vty);
8470
8471 peer = peer_and_group_lookup_vty(vty, peer_str);
8472 if (!peer)
8473 return CMD_WARNING_CONFIG_FAILED;
8474
8475 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8476 PEER_FLAG_DISABLE_ADDPATH_RX);
8477}
8478
adbac85e
DW
8479DEFUN (neighbor_addpath_tx_all_paths,
8480 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8481 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8482 NEIGHBOR_STR
8483 NEIGHBOR_ADDR_STR2
8484 "Use addpath to advertise all paths to a neighbor\n")
8485{
d62a17ae 8486 int idx_peer = 1;
8487 struct peer *peer;
adbac85e 8488
d62a17ae 8489 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8490 if (!peer)
8491 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8492
dcc68b5e
MS
8493 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8494 BGP_ADDPATH_ALL);
8495 return CMD_SUCCESS;
adbac85e
DW
8496}
8497
d62a17ae 8498ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8499 neighbor_addpath_tx_all_paths_hidden_cmd,
8500 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8501 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8502 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8503
adbac85e
DW
8504DEFUN (no_neighbor_addpath_tx_all_paths,
8505 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8506 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8507 NO_STR
8508 NEIGHBOR_STR
8509 NEIGHBOR_ADDR_STR2
8510 "Use addpath to advertise all paths to a neighbor\n")
8511{
d62a17ae 8512 int idx_peer = 2;
dcc68b5e
MS
8513 struct peer *peer;
8514
8515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8516 if (!peer)
8517 return CMD_WARNING_CONFIG_FAILED;
8518
8519 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8520 != BGP_ADDPATH_ALL) {
8521 vty_out(vty,
8522 "%% Peer not currently configured to transmit all paths.");
8523 return CMD_WARNING_CONFIG_FAILED;
8524 }
8525
8526 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8527 BGP_ADDPATH_NONE);
8528
8529 return CMD_SUCCESS;
adbac85e
DW
8530}
8531
d62a17ae 8532ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8533 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8534 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8535 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8536 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8537
06370dac
DW
8538DEFUN (neighbor_addpath_tx_bestpath_per_as,
8539 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8540 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8541 NEIGHBOR_STR
8542 NEIGHBOR_ADDR_STR2
8543 "Use addpath to advertise the bestpath per each neighboring AS\n")
8544{
d62a17ae 8545 int idx_peer = 1;
8546 struct peer *peer;
06370dac 8547
d62a17ae 8548 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8549 if (!peer)
8550 return CMD_WARNING_CONFIG_FAILED;
06370dac 8551
dcc68b5e
MS
8552 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8553 BGP_ADDPATH_BEST_PER_AS);
8554
8555 return CMD_SUCCESS;
06370dac
DW
8556}
8557
d62a17ae 8558ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8559 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8560 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8562 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8563
06370dac
DW
8564DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8565 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8566 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8567 NO_STR
8568 NEIGHBOR_STR
8569 NEIGHBOR_ADDR_STR2
8570 "Use addpath to advertise the bestpath per each neighboring AS\n")
8571{
d62a17ae 8572 int idx_peer = 2;
dcc68b5e
MS
8573 struct peer *peer;
8574
8575 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8576 if (!peer)
8577 return CMD_WARNING_CONFIG_FAILED;
8578
8579 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8580 != BGP_ADDPATH_BEST_PER_AS) {
8581 vty_out(vty,
8582 "%% Peer not currently configured to transmit all best path per as.");
8583 return CMD_WARNING_CONFIG_FAILED;
8584 }
8585
8586 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8587 BGP_ADDPATH_NONE);
8588
8589 return CMD_SUCCESS;
06370dac
DW
8590}
8591
d62a17ae 8592ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8593 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8594 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8595 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8596 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8597
2b31007c
RZ
8598DEFPY(
8599 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8600 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8601 NEIGHBOR_STR
8602 NEIGHBOR_ADDR_STR2
8603 "Detect AS loops before sending to neighbor\n")
8604{
8605 struct peer *peer;
8606
8607 peer = peer_and_group_lookup_vty(vty, neighbor);
8608 if (!peer)
8609 return CMD_WARNING_CONFIG_FAILED;
8610
8611 peer->as_path_loop_detection = true;
8612
8613 return CMD_SUCCESS;
8614}
8615
8616DEFPY(
8617 no_neighbor_aspath_loop_detection,
8618 no_neighbor_aspath_loop_detection_cmd,
8619 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8620 NO_STR
8621 NEIGHBOR_STR
8622 NEIGHBOR_ADDR_STR2
8623 "Detect AS loops before sending to neighbor\n")
8624{
8625 struct peer *peer;
8626
8627 peer = peer_and_group_lookup_vty(vty, neighbor);
8628 if (!peer)
8629 return CMD_WARNING_CONFIG_FAILED;
8630
8631 peer->as_path_loop_detection = false;
8632
8633 return CMD_SUCCESS;
8634}
8635
b9c7bc5a 8636static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8637 struct ecommunity **list, bool is_rt6)
ddb5b488 8638{
b9c7bc5a
PZ
8639 struct ecommunity *ecom = NULL;
8640 struct ecommunity *ecomadd;
ddb5b488 8641
b9c7bc5a 8642 for (; argc; --argc, ++argv) {
9a659715
PG
8643 if (is_rt6)
8644 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8645 ECOMMUNITY_ROUTE_TARGET,
8646 0);
8647 else
8648 ecomadd = ecommunity_str2com(argv[0]->arg,
8649 ECOMMUNITY_ROUTE_TARGET,
8650 0);
b9c7bc5a
PZ
8651 if (!ecomadd) {
8652 vty_out(vty, "Malformed community-list value\n");
8653 if (ecom)
8654 ecommunity_free(&ecom);
8655 return CMD_WARNING_CONFIG_FAILED;
8656 }
ddb5b488 8657
b9c7bc5a
PZ
8658 if (ecom) {
8659 ecommunity_merge(ecom, ecomadd);
8660 ecommunity_free(&ecomadd);
8661 } else {
8662 ecom = ecomadd;
8663 }
8664 }
8665
8666 if (*list) {
8667 ecommunity_free(&*list);
ddb5b488 8668 }
b9c7bc5a
PZ
8669 *list = ecom;
8670
8671 return CMD_SUCCESS;
ddb5b488
PZ
8672}
8673
0ca70ba5
DS
8674/*
8675 * v2vimport is true if we are handling a `import vrf ...` command
8676 */
8677static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8678{
0ca70ba5
DS
8679 afi_t afi;
8680
ddb5b488 8681 switch (vty->node) {
b9c7bc5a 8682 case BGP_IPV4_NODE:
0ca70ba5
DS
8683 afi = AFI_IP;
8684 break;
b9c7bc5a 8685 case BGP_IPV6_NODE:
0ca70ba5
DS
8686 afi = AFI_IP6;
8687 break;
ddb5b488
PZ
8688 default:
8689 vty_out(vty,
b9c7bc5a 8690 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8691 return AFI_MAX;
ddb5b488 8692 }
69b07479 8693
0ca70ba5
DS
8694 if (!v2vimport) {
8695 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8696 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8697 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8698 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8699 vty_out(vty,
8700 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8701 return AFI_MAX;
8702 }
8703 } else {
8704 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8705 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8706 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8707 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8708 vty_out(vty,
8709 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8710 return AFI_MAX;
8711 }
8712 }
8713 return afi;
ddb5b488
PZ
8714}
8715
585f1adc
IR
8716DEFPY (af_rd_vpn_export,
8717 af_rd_vpn_export_cmd,
8718 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8719 NO_STR
8720 "Specify route distinguisher\n"
8721 "Between current address-family and vpn\n"
8722 "For routes leaked from current address-family to vpn\n"
8723 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8724{
585f1adc
IR
8725 VTY_DECLVAR_CONTEXT(bgp, bgp);
8726 struct prefix_rd prd;
8727 int ret;
ddb5b488 8728 afi_t afi;
b9c7bc5a 8729 int idx = 0;
585f1adc 8730 bool yes = true;
b9c7bc5a 8731
585f1adc
IR
8732 if (argv_find(argv, argc, "no", &idx))
8733 yes = false;
ddb5b488 8734
585f1adc
IR
8735 if (yes) {
8736 ret = str2prefix_rd(rd_str, &prd);
8737 if (!ret) {
8738 vty_out(vty, "%% Malformed rd\n");
8739 return CMD_WARNING_CONFIG_FAILED;
8740 }
8741 }
ddb5b488 8742
585f1adc
IR
8743 afi = vpn_policy_getafi(vty, bgp, false);
8744 if (afi == AFI_MAX)
8745 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8746
585f1adc
IR
8747 /*
8748 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8749 */
8750 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8751 bgp_get_default(), bgp);
ddb5b488 8752
585f1adc
IR
8753 if (yes) {
8754 bgp->vpn_policy[afi].tovpn_rd = prd;
8755 SET_FLAG(bgp->vpn_policy[afi].flags,
8756 BGP_VPN_POLICY_TOVPN_RD_SET);
8757 } else {
8758 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8759 BGP_VPN_POLICY_TOVPN_RD_SET);
8760 }
69b07479 8761
585f1adc
IR
8762 /* post-change: re-export vpn routes */
8763 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8764 bgp_get_default(), bgp);
8765
8766 return CMD_SUCCESS;
ddb5b488
PZ
8767}
8768
b9c7bc5a
PZ
8769ALIAS (af_rd_vpn_export,
8770 af_no_rd_vpn_export_cmd,
8771 "no rd vpn export",
ddb5b488 8772 NO_STR
b9c7bc5a
PZ
8773 "Specify route distinguisher\n"
8774 "Between current address-family and vpn\n"
8775 "For routes leaked from current address-family to vpn\n")
ddb5b488 8776
b9c7bc5a
PZ
8777DEFPY (af_label_vpn_export,
8778 af_label_vpn_export_cmd,
e70e9f8e 8779 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8780 NO_STR
ddb5b488 8781 "label value for VRF\n"
b9c7bc5a
PZ
8782 "Between current address-family and vpn\n"
8783 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8784 "Label Value <0-1048575>\n"
8785 "Automatically assign a label\n")
ddb5b488
PZ
8786{
8787 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8788 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8789 afi_t afi;
b9c7bc5a 8790 int idx = 0;
c6423c31 8791 bool yes = true;
b9c7bc5a
PZ
8792
8793 if (argv_find(argv, argc, "no", &idx))
c6423c31 8794 yes = false;
ddb5b488 8795
21a16cc2
PZ
8796 /* If "no ...", squash trailing parameter */
8797 if (!yes)
8798 label_auto = NULL;
8799
e70e9f8e
PZ
8800 if (yes) {
8801 if (!label_auto)
8802 label = label_val; /* parser should force unsigned */
8803 }
ddb5b488 8804
0ca70ba5 8805 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8806 if (afi == AFI_MAX)
8807 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8808
e70e9f8e 8809
69b07479
DS
8810 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8811 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8812 /* no change */
8813 return CMD_SUCCESS;
e70e9f8e 8814
69b07479
DS
8815 /*
8816 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8817 */
8818 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8819 bgp_get_default(), bgp);
8820
8821 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8822 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8823
8824 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8825
8826 /*
8827 * label has previously been automatically
8828 * assigned by labelpool: release it
8829 *
8830 * NB if tovpn_label == MPLS_LABEL_NONE it
8831 * means the automatic assignment is in flight
8832 * and therefore the labelpool callback must
8833 * detect that the auto label is not needed.
8834 */
8835
8836 bgp_lp_release(LP_TYPE_VRF,
8837 &bgp->vpn_policy[afi],
8838 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8839 }
69b07479
DS
8840 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8841 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8842 }
ddb5b488 8843
69b07479
DS
8844 bgp->vpn_policy[afi].tovpn_label = label;
8845 if (label_auto) {
8846 SET_FLAG(bgp->vpn_policy[afi].flags,
8847 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8848 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8849 vpn_leak_label_callback);
ddb5b488
PZ
8850 }
8851
69b07479
DS
8852 /* post-change: re-export vpn routes */
8853 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8854 bgp_get_default(), bgp);
8855
0d020cd6 8856 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8857 return CMD_SUCCESS;
8858}
8859
b72c9e14
HS
8860DEFPY (af_sid_vpn_export,
8861 af_sid_vpn_export_cmd,
8862 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8863 NO_STR
8864 "sid value for VRF\n"
8865 "Between current address-family and vpn\n"
8866 "For routes leaked from current address-family to vpn\n"
8867 "Sid allocation index\n"
8868 "Automatically assign a label\n")
8869{
8870 VTY_DECLVAR_CONTEXT(bgp, bgp);
8871 afi_t afi;
8872 int debug = 0;
8873 int idx = 0;
8874 bool yes = true;
8875
8876 if (argv_find(argv, argc, "no", &idx))
8877 yes = false;
8878 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8879 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8880
8881 afi = vpn_policy_getafi(vty, bgp, false);
8882 if (afi == AFI_MAX)
8883 return CMD_WARNING_CONFIG_FAILED;
8884
8885 if (!yes) {
8886 /* implement me */
4d4c404b 8887 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
8888 return CMD_WARNING_CONFIG_FAILED;
8889 }
8890
8891 /* skip when it's already configured */
8892 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8893 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8894 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8895 return CMD_SUCCESS;
8896
7de4c885
HS
8897 /*
8898 * mode change between sid_idx and sid_auto isn't supported.
8899 * user must negate sid vpn export when they want to change the mode
8900 */
b72c9e14
HS
8901 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8902 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8903 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8904 vty_out(vty, "it's already configured as %s.\n",
8905 sid_auto ? "auto-mode" : "idx-mode");
8906 return CMD_WARNING_CONFIG_FAILED;
8907 }
8908
8909 /* pre-change */
8910 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8911 bgp_get_default(), bgp);
8912
8913 if (sid_auto) {
8914 /* SID allocation auto-mode */
8915 if (debug)
8916 zlog_debug("%s: auto sid alloc.", __func__);
8917 SET_FLAG(bgp->vpn_policy[afi].flags,
8918 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8919 } else {
8920 /* SID allocation index-mode */
8921 if (debug)
8922 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8923 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8924 }
8925
8926 /* post-change */
8927 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8928 bgp_get_default(), bgp);
8929 return CMD_SUCCESS;
8930}
8931
b9c7bc5a
PZ
8932ALIAS (af_label_vpn_export,
8933 af_no_label_vpn_export_cmd,
8934 "no label vpn export",
8935 NO_STR
8936 "label value for VRF\n"
8937 "Between current address-family and vpn\n"
8938 "For routes leaked from current address-family to vpn\n")
ddb5b488 8939
585f1adc 8940DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8941 af_nexthop_vpn_export_cmd,
8c85ca28 8942 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8943 NO_STR
ddb5b488 8944 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8945 "Between current address-family and vpn\n"
8946 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8947 "IPv4 prefix\n"
8948 "IPv6 prefix\n")
8949{
585f1adc 8950 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8951 afi_t afi;
ddb5b488
PZ
8952 struct prefix p;
8953
8c85ca28
QY
8954 if (!no) {
8955 if (!nexthop_su) {
8956 vty_out(vty, "%% Nexthop required\n");
8957 return CMD_WARNING_CONFIG_FAILED;
8958 }
8c85ca28 8959 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8960 return CMD_WARNING_CONFIG_FAILED;
8961 }
ddb5b488 8962
585f1adc
IR
8963 afi = vpn_policy_getafi(vty, bgp, false);
8964 if (afi == AFI_MAX)
8965 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8966
585f1adc
IR
8967 /*
8968 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8969 */
8970 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8971 bgp_get_default(), bgp);
ddb5b488 8972
585f1adc
IR
8973 if (!no) {
8974 bgp->vpn_policy[afi].tovpn_nexthop = p;
8975 SET_FLAG(bgp->vpn_policy[afi].flags,
8976 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8977 } else {
8978 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8979 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8980 }
69b07479 8981
585f1adc
IR
8982 /* post-change: re-export vpn routes */
8983 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8984 bgp_get_default(), bgp);
37a87b8f 8985
585f1adc 8986 return CMD_SUCCESS;
ddb5b488
PZ
8987}
8988
b9c7bc5a 8989static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8990{
b9c7bc5a
PZ
8991 if (!strcmp(dstr, "import")) {
8992 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8993 } else if (!strcmp(dstr, "export")) {
8994 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8995 } else if (!strcmp(dstr, "both")) {
8996 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8997 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8998 } else {
8999 vty_out(vty, "%% direction parse error\n");
9000 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9001 }
ddb5b488
PZ
9002 return CMD_SUCCESS;
9003}
9004
b9c7bc5a
PZ
9005DEFPY (af_rt_vpn_imexport,
9006 af_rt_vpn_imexport_cmd,
9007 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9008 NO_STR
9009 "Specify route target list\n"
ddb5b488 9010 "Specify route target list\n"
b9c7bc5a
PZ
9011 "Between current address-family and vpn\n"
9012 "For routes leaked from vpn to current address-family: match any\n"
9013 "For routes leaked from current address-family to vpn: set\n"
9014 "both import: match any and export: set\n"
ddb5b488
PZ
9015 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9016{
9017 VTY_DECLVAR_CONTEXT(bgp, bgp);
9018 int ret;
9019 struct ecommunity *ecom = NULL;
9020 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9021 enum vpn_policy_direction dir;
ddb5b488
PZ
9022 afi_t afi;
9023 int idx = 0;
c6423c31 9024 bool yes = true;
ddb5b488 9025
b9c7bc5a 9026 if (argv_find(argv, argc, "no", &idx))
c6423c31 9027 yes = false;
b9c7bc5a 9028
0ca70ba5 9029 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9030 if (afi == AFI_MAX)
9031 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9032
b9c7bc5a 9033 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9034 if (ret != CMD_SUCCESS)
9035 return ret;
9036
b9c7bc5a
PZ
9037 if (yes) {
9038 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9039 vty_out(vty, "%% Missing RTLIST\n");
9040 return CMD_WARNING_CONFIG_FAILED;
9041 }
c6423c31 9042 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9043 if (ret != CMD_SUCCESS) {
9044 return ret;
9045 }
ddb5b488
PZ
9046 }
9047
69b07479
DS
9048 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9049 if (!dodir[dir])
ddb5b488 9050 continue;
ddb5b488 9051
69b07479 9052 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9053
69b07479
DS
9054 if (yes) {
9055 if (bgp->vpn_policy[afi].rtlist[dir])
9056 ecommunity_free(
9057 &bgp->vpn_policy[afi].rtlist[dir]);
9058 bgp->vpn_policy[afi].rtlist[dir] =
9059 ecommunity_dup(ecom);
9060 } else {
9061 if (bgp->vpn_policy[afi].rtlist[dir])
9062 ecommunity_free(
9063 &bgp->vpn_policy[afi].rtlist[dir]);
9064 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9065 }
69b07479
DS
9066
9067 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9068 }
69b07479 9069
d555f3e9
PZ
9070 if (ecom)
9071 ecommunity_free(&ecom);
ddb5b488
PZ
9072
9073 return CMD_SUCCESS;
9074}
9075
b9c7bc5a
PZ
9076ALIAS (af_rt_vpn_imexport,
9077 af_no_rt_vpn_imexport_cmd,
9078 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9079 NO_STR
9080 "Specify route target list\n"
b9c7bc5a
PZ
9081 "Specify route target list\n"
9082 "Between current address-family and vpn\n"
9083 "For routes leaked from vpn to current address-family\n"
9084 "For routes leaked from current address-family to vpn\n"
9085 "both import and export\n")
9086
585f1adc 9087DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9088 af_route_map_vpn_imexport_cmd,
9089/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9090 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9091 NO_STR
ddb5b488 9092 "Specify route map\n"
b9c7bc5a
PZ
9093 "Between current address-family and vpn\n"
9094 "For routes leaked from vpn to current address-family\n"
9095 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9096 "name of route-map\n")
9097{
585f1adc
IR
9098 VTY_DECLVAR_CONTEXT(bgp, bgp);
9099 int ret;
9100 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 9101 enum vpn_policy_direction dir;
ddb5b488 9102 afi_t afi;
ddb5b488 9103 int idx = 0;
585f1adc 9104 bool yes = true;
ddb5b488 9105
585f1adc
IR
9106 if (argv_find(argv, argc, "no", &idx))
9107 yes = false;
ddb5b488 9108
585f1adc
IR
9109 afi = vpn_policy_getafi(vty, bgp, false);
9110 if (afi == AFI_MAX)
9111 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9112
585f1adc
IR
9113 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9114 if (ret != CMD_SUCCESS)
9115 return ret;
ddb5b488 9116
585f1adc
IR
9117 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9118 if (!dodir[dir])
9119 continue;
69b07479 9120
585f1adc
IR
9121 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9122
9123 if (yes) {
9124 if (bgp->vpn_policy[afi].rmap_name[dir])
9125 XFREE(MTYPE_ROUTE_MAP_NAME,
9126 bgp->vpn_policy[afi].rmap_name[dir]);
9127 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
9128 MTYPE_ROUTE_MAP_NAME, rmap_str);
9129 bgp->vpn_policy[afi].rmap[dir] =
9130 route_map_lookup_warn_noexist(vty, rmap_str);
9131 if (!bgp->vpn_policy[afi].rmap[dir])
9132 return CMD_SUCCESS;
9133 } else {
9134 if (bgp->vpn_policy[afi].rmap_name[dir])
9135 XFREE(MTYPE_ROUTE_MAP_NAME,
9136 bgp->vpn_policy[afi].rmap_name[dir]);
9137 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9138 bgp->vpn_policy[afi].rmap[dir] = NULL;
9139 }
9140
9141 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9142 }
ddb5b488 9143
585f1adc 9144 return CMD_SUCCESS;
ddb5b488
PZ
9145}
9146
b9c7bc5a
PZ
9147ALIAS (af_route_map_vpn_imexport,
9148 af_no_route_map_vpn_imexport_cmd,
9149 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9150 NO_STR
9151 "Specify route map\n"
b9c7bc5a
PZ
9152 "Between current address-family and vpn\n"
9153 "For routes leaked from vpn to current address-family\n"
9154 "For routes leaked from current address-family to vpn\n")
9155
bb4f6190 9156DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9157 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9158 "Import routes from another VRF\n"
9159 "Vrf routes being filtered\n"
9160 "Specify route map\n"
9161 "name of route-map\n")
9162{
9163 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9164 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 9165 afi_t afi;
bb4f6190
DS
9166 struct bgp *bgp_default;
9167
0ca70ba5 9168 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9169 if (afi == AFI_MAX)
9170 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9171
9172 bgp_default = bgp_get_default();
9173 if (!bgp_default) {
9174 int32_t ret;
9175 as_t as = bgp->as;
9176
9177 /* Auto-create assuming the same AS */
5d5393b9
DL
9178 ret = bgp_get_vty(&bgp_default, &as, NULL,
9179 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9180
9181 if (ret) {
9182 vty_out(vty,
9183 "VRF default is not configured as a bgp instance\n");
9184 return CMD_WARNING;
9185 }
9186 }
9187
69b07479 9188 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9189
ae6a6fb4
DS
9190 if (bgp->vpn_policy[afi].rmap_name[dir])
9191 XFREE(MTYPE_ROUTE_MAP_NAME,
9192 bgp->vpn_policy[afi].rmap_name[dir]);
9193 bgp->vpn_policy[afi].rmap_name[dir] =
9194 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9195 bgp->vpn_policy[afi].rmap[dir] =
9196 route_map_lookup_warn_noexist(vty, rmap_str);
9197 if (!bgp->vpn_policy[afi].rmap[dir])
9198 return CMD_SUCCESS;
9199
9200 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9201 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9202
69b07479
DS
9203 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9204
bb4f6190
DS
9205 return CMD_SUCCESS;
9206}
9207
ae6a6fb4
DS
9208DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9209 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9210 NO_STR
9211 "Import routes from another VRF\n"
9212 "Vrf routes being filtered\n"
ae6a6fb4
DS
9213 "Specify route map\n"
9214 "name of route-map\n")
9215{
9216 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 9217 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
9218 afi_t afi;
9219
9220 afi = vpn_policy_getafi(vty, bgp, true);
9221 if (afi == AFI_MAX)
9222 return CMD_WARNING_CONFIG_FAILED;
9223
9224 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9225
9226 if (bgp->vpn_policy[afi].rmap_name[dir])
9227 XFREE(MTYPE_ROUTE_MAP_NAME,
9228 bgp->vpn_policy[afi].rmap_name[dir]);
9229 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9230 bgp->vpn_policy[afi].rmap[dir] = NULL;
9231
9232 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9233 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9234 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9235
9236 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9237
9238 return CMD_SUCCESS;
9239}
bb4f6190 9240
585f1adc
IR
9241DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
9242 "[no] import vrf VIEWVRFNAME$import_name",
9243 NO_STR
9244 "Import routes from another VRF\n"
9245 "VRF to import from\n"
9246 "The name of the VRF\n")
12a844a5 9247{
585f1adc
IR
9248 VTY_DECLVAR_CONTEXT(bgp, bgp);
9249 struct listnode *node;
9250 struct bgp *vrf_bgp, *bgp_default;
9251 int32_t ret = 0;
9252 as_t as = bgp->as;
9253 bool remove = false;
9254 int32_t idx = 0;
9255 char *vname;
9256 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9257 safi_t safi;
9258 afi_t afi;
9259
867f0cca 9260 if (import_name == NULL) {
9261 vty_out(vty, "%% Missing import name\n");
9262 return CMD_WARNING;
9263 }
9264
ae6a6fb4
DS
9265 if (strcmp(import_name, "route-map") == 0) {
9266 vty_out(vty, "%% Must include route-map name\n");
9267 return CMD_WARNING;
9268 }
9269
585f1adc
IR
9270 if (argv_find(argv, argc, "no", &idx))
9271 remove = true;
9272
9273 afi = vpn_policy_getafi(vty, bgp, true);
9274 if (afi == AFI_MAX)
9275 return CMD_WARNING_CONFIG_FAILED;
9276
12a844a5
DS
9277 safi = bgp_node_safi(vty);
9278
585f1adc
IR
9279 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9280 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9281 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9282 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9283 remove ? "unimport" : "import", import_name);
9284 return CMD_WARNING;
9285 }
25679caa 9286
585f1adc
IR
9287 bgp_default = bgp_get_default();
9288 if (!bgp_default) {
9289 /* Auto-create assuming the same AS */
9290 ret = bgp_get_vty(&bgp_default, &as, NULL,
9291 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 9292
585f1adc
IR
9293 if (ret) {
9294 vty_out(vty,
9295 "VRF default is not configured as a bgp instance\n");
9296 return CMD_WARNING;
9297 }
9298 }
12a844a5 9299
585f1adc
IR
9300 vrf_bgp = bgp_lookup_by_name(import_name);
9301 if (!vrf_bgp) {
9302 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9303 vrf_bgp = bgp_default;
9304 else
9305 /* Auto-create assuming the same AS */
9306 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9307
9308 if (ret) {
9309 vty_out(vty,
9310 "VRF %s is not configured as a bgp instance\n",
9311 import_name);
9312 return CMD_WARNING;
9313 }
9314 }
9315
9316 if (remove) {
9317 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9318 } else {
9319 /* Already importing from "import_vrf"? */
9320 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9321 vname)) {
9322 if (strcmp(vname, import_name) == 0)
9323 return CMD_WARNING;
9324 }
9325
9326 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9327 }
9328
9329 return CMD_SUCCESS;
12a844a5
DS
9330}
9331
b9c7bc5a 9332/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9333DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9334 bgp_imexport_vpn_cmd,
9335 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9336 NO_STR
9337 "Import routes to this address-family\n"
9338 "Export routes from this address-family\n"
9339 "to/from default instance VPN RIB\n")
ddb5b488 9340{
585f1adc
IR
9341 VTY_DECLVAR_CONTEXT(bgp, bgp);
9342 int previous_state;
37a87b8f 9343 afi_t afi;
585f1adc
IR
9344 safi_t safi;
9345 int idx = 0;
9346 bool yes = true;
9347 int flag;
9c2fd3fe 9348 enum vpn_policy_direction dir;
585f1adc
IR
9349
9350 if (argv_find(argv, argc, "no", &idx))
9351 yes = false;
9352
9353 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9354 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9355
9356 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9357 return CMD_WARNING_CONFIG_FAILED;
9358 }
ddb5b488 9359
b9c7bc5a
PZ
9360 afi = bgp_node_afi(vty);
9361 safi = bgp_node_safi(vty);
585f1adc
IR
9362 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9363 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9364 return CMD_WARNING_CONFIG_FAILED;
9365 }
ddb5b488 9366
b9c7bc5a 9367 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9368 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9369 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9370 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9371 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9372 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9373 } else {
9374 vty_out(vty, "%% unknown direction %s\n", direction_str);
9375 return CMD_WARNING_CONFIG_FAILED;
9376 }
9377
585f1adc 9378 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9379
585f1adc
IR
9380 if (yes) {
9381 SET_FLAG(bgp->af_flags[afi][safi], flag);
9382 if (!previous_state) {
9383 /* trigger export current vrf */
9384 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9385 }
9386 } else {
9387 if (previous_state) {
9388 /* trigger un-export current vrf */
9389 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9390 }
9391 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9392 }
37a87b8f 9393
1ca2fd11
IR
9394 hook_call(bgp_snmp_init_stats, bgp);
9395
585f1adc 9396 return CMD_SUCCESS;
ddb5b488
PZ
9397}
9398
301ad80a
PG
9399DEFPY (af_routetarget_import,
9400 af_routetarget_import_cmd,
9a659715 9401 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9402 NO_STR
9403 "Specify route target list\n"
9404 "Specify route target list\n"
9a659715
PG
9405 "Specify route target list\n"
9406 "Specify route target list\n"
301ad80a
PG
9407 "Flow-spec redirect type route target\n"
9408 "Import routes to this address-family\n"
9a659715 9409 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9410{
9411 VTY_DECLVAR_CONTEXT(bgp, bgp);
9412 int ret;
9413 struct ecommunity *ecom = NULL;
301ad80a 9414 afi_t afi;
9a659715 9415 int idx = 0, idx_unused = 0;
c6423c31
PG
9416 bool yes = true;
9417 bool rt6 = false;
301ad80a
PG
9418
9419 if (argv_find(argv, argc, "no", &idx))
c6423c31 9420 yes = false;
301ad80a 9421
9a659715
PG
9422 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9423 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9424 rt6 = true;
301ad80a 9425
0ca70ba5 9426 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9427 if (afi == AFI_MAX)
9428 return CMD_WARNING_CONFIG_FAILED;
9429
9a659715
PG
9430 if (rt6 && afi != AFI_IP6)
9431 return CMD_WARNING_CONFIG_FAILED;
9432
301ad80a
PG
9433 if (yes) {
9434 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9435 vty_out(vty, "%% Missing RTLIST\n");
9436 return CMD_WARNING_CONFIG_FAILED;
9437 }
9a659715 9438 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9439 if (ret != CMD_SUCCESS)
9440 return ret;
9441 }
69b07479
DS
9442
9443 if (yes) {
9444 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9445 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9446 .import_redirect_rtlist);
69b07479
DS
9447 bgp->vpn_policy[afi].import_redirect_rtlist =
9448 ecommunity_dup(ecom);
9449 } else {
9450 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9451 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9452 .import_redirect_rtlist);
69b07479 9453 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9454 }
69b07479 9455
301ad80a
PG
9456 if (ecom)
9457 ecommunity_free(&ecom);
9458
9459 return CMD_SUCCESS;
9460}
9461
505e5056 9462DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9463 address_family_ipv4_safi_cmd,
9464 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9465 "Enter Address Family command mode\n"
00e6edb9 9466 BGP_AF_STR
7c40bf39 9467 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9468{
f51bae9c 9469
d62a17ae 9470 if (argc == 3) {
585f1adc
IR
9471 VTY_DECLVAR_CONTEXT(bgp, bgp);
9472 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9473 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9474 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9475 && safi != SAFI_EVPN) {
31947174
MK
9476 vty_out(vty,
9477 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9478 return CMD_WARNING_CONFIG_FAILED;
9479 }
585f1adc
IR
9480 vty->node = bgp_node_type(AFI_IP, safi);
9481 } else
9482 vty->node = BGP_IPV4_NODE;
718e3744 9483
d62a17ae 9484 return CMD_SUCCESS;
718e3744 9485}
9486
505e5056 9487DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9488 address_family_ipv6_safi_cmd,
9489 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9490 "Enter Address Family command mode\n"
00e6edb9 9491 BGP_AF_STR
7c40bf39 9492 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9493{
d62a17ae 9494 if (argc == 3) {
585f1adc
IR
9495 VTY_DECLVAR_CONTEXT(bgp, bgp);
9496 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9497 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9498 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9499 && safi != SAFI_EVPN) {
31947174
MK
9500 vty_out(vty,
9501 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9502 return CMD_WARNING_CONFIG_FAILED;
9503 }
585f1adc
IR
9504 vty->node = bgp_node_type(AFI_IP6, safi);
9505 } else
9506 vty->node = BGP_IPV6_NODE;
25ffbdc1 9507
d62a17ae 9508 return CMD_SUCCESS;
25ffbdc1 9509}
718e3744 9510
d6902373 9511#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9512DEFUN_NOSH (address_family_vpnv4,
718e3744 9513 address_family_vpnv4_cmd,
8334fd5a 9514 "address-family vpnv4 [unicast]",
718e3744 9515 "Enter Address Family command mode\n"
00e6edb9
DA
9516 BGP_AF_STR
9517 BGP_AF_MODIFIER_STR)
718e3744 9518{
d62a17ae 9519 vty->node = BGP_VPNV4_NODE;
9520 return CMD_SUCCESS;
718e3744 9521}
9522
505e5056 9523DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9524 address_family_vpnv6_cmd,
8334fd5a 9525 "address-family vpnv6 [unicast]",
8ecd3266 9526 "Enter Address Family command mode\n"
00e6edb9
DA
9527 BGP_AF_STR
9528 BGP_AF_MODIFIER_STR)
8ecd3266 9529{
d62a17ae 9530 vty->node = BGP_VPNV6_NODE;
9531 return CMD_SUCCESS;
8ecd3266 9532}
64e4a6c5 9533#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9534
505e5056 9535DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9536 address_family_evpn_cmd,
7111c1a0 9537 "address-family l2vpn evpn",
4e0b7b6d 9538 "Enter Address Family command mode\n"
00e6edb9
DA
9539 BGP_AF_STR
9540 BGP_AF_MODIFIER_STR)
4e0b7b6d 9541{
2131d5cf 9542 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9543 vty->node = BGP_EVPN_NODE;
9544 return CMD_SUCCESS;
4e0b7b6d
PG
9545}
9546
bfaab44d
HS
9547DEFUN_NOSH (bgp_segment_routing_srv6,
9548 bgp_segment_routing_srv6_cmd,
9549 "segment-routing srv6",
9550 "Segment-Routing configuration\n"
9551 "Segment-Routing SRv6 configuration\n")
9552{
9553 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9554 bgp->srv6_enabled = true;
bfaab44d
HS
9555 vty->node = BGP_SRV6_NODE;
9556 return CMD_SUCCESS;
9557}
9558
0249b8b6
HS
9559DEFUN (no_bgp_segment_routing_srv6,
9560 no_bgp_segment_routing_srv6_cmd,
9561 "no segment-routing srv6",
9562 NO_STR
9563 "Segment-Routing configuration\n"
9564 "Segment-Routing SRv6 configuration\n")
9565{
9566 VTY_DECLVAR_CONTEXT(bgp, bgp);
9567
9568 if (strlen(bgp->srv6_locator_name) > 0)
9569 if (bgp_srv6_locator_unset(bgp) < 0)
9570 return CMD_WARNING_CONFIG_FAILED;
9571
9572 bgp->srv6_enabled = false;
9573 return CMD_SUCCESS;
9574}
9575
a0281b2e
HS
9576DEFPY (bgp_srv6_locator,
9577 bgp_srv6_locator_cmd,
9578 "locator NAME$name",
9579 "Specify SRv6 locator\n"
9580 "Specify SRv6 locator\n")
9581{
9582 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9583 int ret;
a0281b2e
HS
9584
9585 if (strlen(bgp->srv6_locator_name) > 0
9586 && strcmp(name, bgp->srv6_locator_name) != 0) {
9587 vty_out(vty, "srv6 locator is already configured\n");
9588 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9589 }
9590
9591 snprintf(bgp->srv6_locator_name,
9592 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9593
7de4c885 9594 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9595 if (ret < 0)
9596 return CMD_WARNING_CONFIG_FAILED;
9597
9598 return CMD_SUCCESS;
9599}
9600
0249b8b6
HS
9601DEFPY (no_bgp_srv6_locator,
9602 no_bgp_srv6_locator_cmd,
9603 "no locator NAME$name",
9604 NO_STR
9605 "Specify SRv6 locator\n"
9606 "Specify SRv6 locator\n")
9607{
9608 VTY_DECLVAR_CONTEXT(bgp, bgp);
9609
9610 /* when locator isn't configured, do nothing */
9611 if (strlen(bgp->srv6_locator_name) < 1)
9612 return CMD_SUCCESS;
9613
9614 /* name validation */
9615 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9616 vty_out(vty, "%% No srv6 locator is configured\n");
9617 return CMD_WARNING_CONFIG_FAILED;
9618 }
9619
9620 /* unset locator */
9621 if (bgp_srv6_locator_unset(bgp) < 0)
9622 return CMD_WARNING_CONFIG_FAILED;
9623
9624 return CMD_SUCCESS;
9625}
9626
ea372e81
HS
9627DEFPY (show_bgp_srv6,
9628 show_bgp_srv6_cmd,
9629 "show bgp segment-routing srv6",
9630 SHOW_STR
9631 BGP_STR
9632 "BGP Segment Routing\n"
9633 "BGP Segment Routing SRv6\n")
9634{
9635 struct bgp *bgp;
9636 struct listnode *node;
1c21a234 9637 struct srv6_locator_chunk *chunk;
ea372e81
HS
9638 struct bgp_srv6_function *func;
9639 struct in6_addr *tovpn4_sid;
9640 struct in6_addr *tovpn6_sid;
9641 char buf[256];
9642 char buf_tovpn4_sid[256];
9643 char buf_tovpn6_sid[256];
9644
9645 bgp = bgp_get_default();
96db4340 9646 if (!bgp)
ea372e81
HS
9647 return CMD_SUCCESS;
9648
9649 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9650 vty_out(vty, "locator_chunks:\n");
511211bf
DA
9651 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk))
9652 vty_out(vty, "- %pFX\n", &chunk->prefix);
ea372e81
HS
9653
9654 vty_out(vty, "functions:\n");
9655 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9656 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9657 vty_out(vty, "- sid: %s\n", buf);
9658 vty_out(vty, " locator: %s\n", func->locator_name);
9659 }
9660
9661 vty_out(vty, "bgps:\n");
9662 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9663 vty_out(vty, "- name: %s\n",
9664 bgp->name ? bgp->name : "default");
9665
9666 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9667 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9668 if (tovpn4_sid)
9669 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9670 sizeof(buf_tovpn4_sid));
9671 if (tovpn6_sid)
9672 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9673 sizeof(buf_tovpn6_sid));
9674
9675 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9676 tovpn4_sid ? buf_tovpn4_sid : "none");
9677 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9678 tovpn6_sid ? buf_tovpn6_sid : "none");
9679 }
9680
9681 return CMD_SUCCESS;
9682}
9683
505e5056 9684DEFUN_NOSH (exit_address_family,
718e3744 9685 exit_address_family_cmd,
9686 "exit-address-family",
9687 "Exit from Address Family configuration mode\n")
9688{
d62a17ae 9689 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9690 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9691 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9692 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9693 || vty->node == BGP_EVPN_NODE
9694 || vty->node == BGP_FLOWSPECV4_NODE
9695 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9696 vty->node = BGP_NODE;
9697 return CMD_SUCCESS;
718e3744 9698}
6b0655a2 9699
8ad7271d 9700/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9701static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9702 const char *ip_str, afi_t afi, safi_t safi,
9703 struct prefix_rd *prd)
9704{
9705 int ret;
9706 struct prefix match;
9bcb3eef
DS
9707 struct bgp_dest *dest;
9708 struct bgp_dest *rm;
d62a17ae 9709 struct bgp *bgp;
9710 struct bgp_table *table;
9711 struct bgp_table *rib;
9712
9713 /* BGP structure lookup. */
9714 if (view_name) {
9715 bgp = bgp_lookup_by_name(view_name);
9716 if (bgp == NULL) {
9717 vty_out(vty, "%% Can't find BGP instance %s\n",
9718 view_name);
9719 return CMD_WARNING;
9720 }
9721 } else {
9722 bgp = bgp_get_default();
9723 if (bgp == NULL) {
9724 vty_out(vty, "%% No BGP process is configured\n");
9725 return CMD_WARNING;
9726 }
9727 }
9728
9729 /* Check IP address argument. */
9730 ret = str2prefix(ip_str, &match);
9731 if (!ret) {
9732 vty_out(vty, "%% address is malformed\n");
9733 return CMD_WARNING;
9734 }
9735
9736 match.family = afi2family(afi);
9737 rib = bgp->rib[afi][safi];
9738
9739 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9740 for (dest = bgp_table_top(rib); dest;
9741 dest = bgp_route_next(dest)) {
9742 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9743
9bcb3eef 9744 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9745 continue;
9746
9bcb3eef 9747 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9748 if (table == NULL)
9749 continue;
9750
4953391b
DA
9751 rm = bgp_node_match(table, &match);
9752 if (rm != NULL) {
b54892e0 9753 const struct prefix *rm_p =
9bcb3eef 9754 bgp_dest_get_prefix(rm);
b54892e0
DS
9755
9756 if (rm_p->prefixlen == match.prefixlen) {
9757 SET_FLAG(rm->flags,
9758 BGP_NODE_USER_CLEAR);
9759 bgp_process(bgp, rm, afi, safi);
d62a17ae 9760 }
9bcb3eef 9761 bgp_dest_unlock_node(rm);
d62a17ae 9762 }
9763 }
9764 } else {
4953391b
DA
9765 dest = bgp_node_match(rib, &match);
9766 if (dest != NULL) {
9bcb3eef 9767 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9768
9bcb3eef
DS
9769 if (dest_p->prefixlen == match.prefixlen) {
9770 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9771 bgp_process(bgp, dest, afi, safi);
d62a17ae 9772 }
9bcb3eef 9773 bgp_dest_unlock_node(dest);
d62a17ae 9774 }
9775 }
9776
9777 return CMD_SUCCESS;
8ad7271d
DS
9778}
9779
b09b5ae0 9780/* one clear bgp command to rule them all */
718e3744 9781DEFUN (clear_ip_bgp_all,
9782 clear_ip_bgp_all_cmd,
3cb14f26 9783 "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|message-stats>]",
718e3744 9784 CLEAR_STR
9785 IP_STR
9786 BGP_STR
838758ac 9787 BGP_INSTANCE_HELP_STR
510afcd6 9788 BGP_AFI_HELP_STR
00e6edb9 9789 BGP_AF_STR
510afcd6 9790 BGP_SAFI_WITH_LABEL_HELP_STR
00e6edb9 9791 BGP_AF_MODIFIER_STR
b09b5ae0 9792 "Clear all peers\n"
453c92f6 9793 "BGP IPv4 neighbor to clear\n"
a80beece 9794 "BGP IPv6 neighbor to clear\n"
838758ac 9795 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9796 "Clear peers with the AS number\n"
9797 "Clear all external peers\n"
718e3744 9798 "Clear all members of peer-group\n"
b09b5ae0 9799 "BGP peer-group name\n"
b09b5ae0
DW
9800 BGP_SOFT_STR
9801 BGP_SOFT_IN_STR
b09b5ae0
DW
9802 BGP_SOFT_OUT_STR
9803 BGP_SOFT_IN_STR
9804 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9805 BGP_SOFT_OUT_STR
9806 "Reset message statistics\n")
718e3744 9807{
d62a17ae 9808 char *vrf = NULL;
9809
dc912615
DS
9810 afi_t afi = AFI_UNSPEC;
9811 safi_t safi = SAFI_UNSPEC;
d62a17ae 9812 enum clear_sort clr_sort = clear_peer;
9813 enum bgp_clear_type clr_type;
9814 char *clr_arg = NULL;
9815
9816 int idx = 0;
9817
9818 /* clear [ip] bgp */
9819 if (argv_find(argv, argc, "ip", &idx))
9820 afi = AFI_IP;
9821
9a8bdf1c
PG
9822 /* [<vrf> VIEWVRFNAME] */
9823 if (argv_find(argv, argc, "vrf", &idx)) {
9824 vrf = argv[idx + 1]->arg;
9825 idx += 2;
9826 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9827 vrf = NULL;
9828 } else if (argv_find(argv, argc, "view", &idx)) {
9829 /* [<view> VIEWVRFNAME] */
d62a17ae 9830 vrf = argv[idx + 1]->arg;
9831 idx += 2;
9832 }
d62a17ae 9833 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9834 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9835 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9836
d7b9898c 9837 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9838 if (argv_find(argv, argc, "*", &idx)) {
9839 clr_sort = clear_all;
9840 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9841 clr_sort = clear_peer;
9842 clr_arg = argv[idx]->arg;
9843 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9844 clr_sort = clear_peer;
9845 clr_arg = argv[idx]->arg;
9846 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9847 clr_sort = clear_group;
9848 idx++;
9849 clr_arg = argv[idx]->arg;
d7b9898c 9850 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9851 clr_sort = clear_peer;
9852 clr_arg = argv[idx]->arg;
8fa7d444
DS
9853 } else if (argv_find(argv, argc, "WORD", &idx)) {
9854 clr_sort = clear_peer;
9855 clr_arg = argv[idx]->arg;
d62a17ae 9856 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9857 clr_sort = clear_as;
9858 clr_arg = argv[idx]->arg;
9859 } else if (argv_find(argv, argc, "external", &idx)) {
9860 clr_sort = clear_external;
9861 }
9862
3cb14f26 9863 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9864 if (argv_find(argv, argc, "soft", &idx)) {
9865 if (argv_find(argv, argc, "in", &idx)
9866 || argv_find(argv, argc, "out", &idx))
9867 clr_type = strmatch(argv[idx]->text, "in")
9868 ? BGP_CLEAR_SOFT_IN
9869 : BGP_CLEAR_SOFT_OUT;
9870 else
9871 clr_type = BGP_CLEAR_SOFT_BOTH;
9872 } else if (argv_find(argv, argc, "in", &idx)) {
9873 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9874 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9875 : BGP_CLEAR_SOFT_IN;
9876 } else if (argv_find(argv, argc, "out", &idx)) {
9877 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9878 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9879 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9880 } else
9881 clr_type = BGP_CLEAR_SOFT_NONE;
9882
1ca2fd11 9883 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9884}
01080f7c 9885
8ad7271d
DS
9886DEFUN (clear_ip_bgp_prefix,
9887 clear_ip_bgp_prefix_cmd,
18c57037 9888 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9889 CLEAR_STR
9890 IP_STR
9891 BGP_STR
838758ac 9892 BGP_INSTANCE_HELP_STR
8ad7271d 9893 "Clear bestpath and re-advertise\n"
0c7b1b01 9894 "IPv4 prefix\n")
8ad7271d 9895{
d62a17ae 9896 char *vrf = NULL;
9897 char *prefix = NULL;
8ad7271d 9898
d62a17ae 9899 int idx = 0;
01080f7c 9900
d62a17ae 9901 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9902 if (argv_find(argv, argc, "vrf", &idx)) {
9903 vrf = argv[idx + 1]->arg;
9904 idx += 2;
9905 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9906 vrf = NULL;
9907 } else if (argv_find(argv, argc, "view", &idx)) {
9908 /* [<view> VIEWVRFNAME] */
9909 vrf = argv[idx + 1]->arg;
9910 idx += 2;
9911 }
0c7b1b01 9912
d62a17ae 9913 prefix = argv[argc - 1]->arg;
8ad7271d 9914
d62a17ae 9915 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9916}
8ad7271d 9917
b09b5ae0
DW
9918DEFUN (clear_bgp_ipv6_safi_prefix,
9919 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9920 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9921 CLEAR_STR
3a2d747c 9922 IP_STR
718e3744 9923 BGP_STR
00e6edb9 9924 BGP_AF_STR
46f296b4 9925 BGP_SAFI_HELP_STR
b09b5ae0 9926 "Clear bestpath and re-advertise\n"
0c7b1b01 9927 "IPv6 prefix\n")
718e3744 9928{
9b475e76
PG
9929 int idx_safi = 0;
9930 int idx_ipv6_prefix = 0;
9931 safi_t safi = SAFI_UNICAST;
9932 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9933 argv[idx_ipv6_prefix]->arg : NULL;
9934
9935 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9936 return bgp_clear_prefix(
9b475e76
PG
9937 vty, NULL, prefix, AFI_IP6,
9938 safi, NULL);
838758ac 9939}
01080f7c 9940
b09b5ae0
DW
9941DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9942 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9943 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9944 CLEAR_STR
3a2d747c 9945 IP_STR
718e3744 9946 BGP_STR
838758ac 9947 BGP_INSTANCE_HELP_STR
00e6edb9 9948 BGP_AF_STR
46f296b4 9949 BGP_SAFI_HELP_STR
b09b5ae0 9950 "Clear bestpath and re-advertise\n"
0c7b1b01 9951 "IPv6 prefix\n")
718e3744 9952{
9b475e76 9953 int idx_safi = 0;
9a8bdf1c 9954 int idx_vrfview = 0;
9b475e76
PG
9955 int idx_ipv6_prefix = 0;
9956 safi_t safi = SAFI_UNICAST;
9957 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9958 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9959 char *vrfview = NULL;
9b475e76 9960
9a8bdf1c
PG
9961 /* [<view|vrf> VIEWVRFNAME] */
9962 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9963 vrfview = argv[idx_vrfview + 1]->arg;
9964 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9965 vrfview = NULL;
9966 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9967 /* [<view> VIEWVRFNAME] */
9968 vrfview = argv[idx_vrfview + 1]->arg;
9969 }
9b475e76
PG
9970 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9971
d62a17ae 9972 return bgp_clear_prefix(
9b475e76
PG
9973 vty, vrfview, prefix,
9974 AFI_IP6, safi, NULL);
718e3744 9975}
9976
b09b5ae0
DW
9977DEFUN (show_bgp_views,
9978 show_bgp_views_cmd,
d6e3c605 9979 "show [ip] bgp views",
b09b5ae0 9980 SHOW_STR
d6e3c605 9981 IP_STR
01080f7c 9982 BGP_STR
b09b5ae0 9983 "Show the defined BGP views\n")
01080f7c 9984{
d62a17ae 9985 struct list *inst = bm->bgp;
9986 struct listnode *node;
9987 struct bgp *bgp;
01080f7c 9988
d62a17ae 9989 vty_out(vty, "Defined BGP views:\n");
9990 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9991 /* Skip VRFs. */
9992 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9993 continue;
9994 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9995 bgp->as);
9996 }
e52702f2 9997
d62a17ae 9998 return CMD_SUCCESS;
e0081f70
ML
9999}
10000
8386ac43 10001DEFUN (show_bgp_vrfs,
10002 show_bgp_vrfs_cmd,
d6e3c605 10003 "show [ip] bgp vrfs [json]",
8386ac43 10004 SHOW_STR
d6e3c605 10005 IP_STR
8386ac43 10006 BGP_STR
10007 "Show BGP VRFs\n"
9973d184 10008 JSON_STR)
8386ac43 10009{
fe1dc5a3 10010 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10011 struct list *inst = bm->bgp;
10012 struct listnode *node;
10013 struct bgp *bgp;
9f049418 10014 bool uj = use_json(argc, argv);
d62a17ae 10015 json_object *json = NULL;
10016 json_object *json_vrfs = NULL;
10017 int count = 0;
d62a17ae 10018
d62a17ae 10019 if (uj) {
10020 json = json_object_new_object();
10021 json_vrfs = json_object_new_object();
10022 }
10023
10024 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10025 const char *name, *type;
10026 struct peer *peer;
7fe96307 10027 struct listnode *node2, *nnode2;
d62a17ae 10028 int peers_cfg, peers_estb;
10029 json_object *json_vrf = NULL;
d62a17ae 10030
10031 /* Skip Views. */
10032 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10033 continue;
10034
10035 count++;
efb4077a 10036 if (!uj && count == 1) {
fe1dc5a3 10037 vty_out(vty,
efb4077a 10038 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10039 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10040 "#PeersEstb", "Name");
10041 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10042 "L3-VNI", "RouterMAC", "Interface");
10043 }
d62a17ae 10044
10045 peers_cfg = peers_estb = 0;
10046 if (uj)
10047 json_vrf = json_object_new_object();
10048
10049
7fe96307 10050 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10051 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10052 continue;
10053 peers_cfg++;
feb17238 10054 if (peer_established(peer))
d62a17ae 10055 peers_estb++;
10056 }
10057
10058 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10059 name = VRF_DEFAULT_NAME;
d62a17ae 10060 type = "DFLT";
10061 } else {
10062 name = bgp->name;
10063 type = "VRF";
10064 }
10065
a8bf7d9c 10066
d62a17ae 10067 if (uj) {
a4d82a8a
PZ
10068 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10069 ? -1
10070 : (int64_t)bgp->vrf_id;
23d0a753
DA
10071 char buf[BUFSIZ] = {0};
10072
d62a17ae 10073 json_object_string_add(json_vrf, "type", type);
10074 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
10075 json_object_string_addf(json_vrf, "routerId", "%pI4",
10076 &bgp->router_id);
d62a17ae 10077 json_object_int_add(json_vrf, "numConfiguredPeers",
10078 peers_cfg);
10079 json_object_int_add(json_vrf, "numEstablishedPeers",
10080 peers_estb);
10081
fe1dc5a3 10082 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10083 json_object_string_add(
10084 json_vrf, "rmac",
10085 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10086 json_object_string_add(json_vrf, "interface",
10087 ifindex2ifname(bgp->l3vni_svi_ifindex,
10088 bgp->vrf_id));
d62a17ae 10089 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10090 } else {
23d0a753 10091 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10092 type,
10093 bgp->vrf_id == VRF_UNKNOWN ? -1
10094 : (int)bgp->vrf_id,
23d0a753 10095 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10096 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10097 bgp->l3vni,
10098 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10099 ifindex2ifname(bgp->l3vni_svi_ifindex,
10100 bgp->vrf_id));
10101 }
d62a17ae 10102 }
10103
10104 if (uj) {
10105 json_object_object_add(json, "vrfs", json_vrfs);
10106
10107 json_object_int_add(json, "totalVrfs", count);
10108
75eeda93 10109 vty_json(vty, json);
d62a17ae 10110 } else {
10111 if (count)
10112 vty_out(vty,
10113 "\nTotal number of VRFs (including default): %d\n",
10114 count);
10115 }
10116
10117 return CMD_SUCCESS;
8386ac43 10118}
10119
48ecf8f5
DS
10120DEFUN (show_bgp_mac_hash,
10121 show_bgp_mac_hash_cmd,
10122 "show bgp mac hash",
10123 SHOW_STR
10124 BGP_STR
10125 "Mac Address\n"
10126 "Mac Address database\n")
10127{
10128 bgp_mac_dump_table(vty);
10129
10130 return CMD_SUCCESS;
10131}
acf71666 10132
e3b78da8 10133static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10134{
0291c246 10135 struct vty *vty = (struct vty *)args;
e3b78da8 10136 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10137
23d0a753 10138 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10139}
10140
10141static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10142{
10143 vty_out(vty, "self nexthop database:\n");
af97a18b 10144 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10145
10146 vty_out(vty, "Tunnel-ip database:\n");
10147 hash_iterate(bgp->tip_hash,
e3b78da8 10148 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10149 vty);
10150}
10151
15c81ca4
DS
10152DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10153 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10154 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10155 "martian next-hops\n"
10156 "martian next-hop database\n")
acf71666 10157{
0291c246 10158 struct bgp *bgp = NULL;
15c81ca4 10159 int idx = 0;
9a8bdf1c
PG
10160 char *name = NULL;
10161
10162 /* [<vrf> VIEWVRFNAME] */
10163 if (argv_find(argv, argc, "vrf", &idx)) {
10164 name = argv[idx + 1]->arg;
10165 if (name && strmatch(name, VRF_DEFAULT_NAME))
10166 name = NULL;
10167 } else if (argv_find(argv, argc, "view", &idx))
10168 /* [<view> VIEWVRFNAME] */
10169 name = argv[idx + 1]->arg;
10170 if (name)
10171 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10172 else
10173 bgp = bgp_get_default();
acf71666 10174
acf71666
MK
10175 if (!bgp) {
10176 vty_out(vty, "%% No BGP process is configured\n");
10177 return CMD_WARNING;
10178 }
10179 bgp_show_martian_nexthops(vty, bgp);
10180
10181 return CMD_SUCCESS;
10182}
10183
f412b39a 10184DEFUN (show_bgp_memory,
4bf6a362 10185 show_bgp_memory_cmd,
7fa12b13 10186 "show [ip] bgp memory",
4bf6a362 10187 SHOW_STR
3a2d747c 10188 IP_STR
4bf6a362
PJ
10189 BGP_STR
10190 "Global BGP memory statistics\n")
10191{
d62a17ae 10192 char memstrbuf[MTYPE_MEMSTR_LEN];
10193 unsigned long count;
10194
10195 /* RIB related usage stats */
10196 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10197 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10198 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10199 count * sizeof(struct bgp_dest)));
d62a17ae 10200
10201 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10202 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10203 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10204 count * sizeof(struct bgp_path_info)));
d62a17ae 10205 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10206 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10207 count,
4b7e6066
DS
10208 mtype_memstr(
10209 memstrbuf, sizeof(memstrbuf),
10210 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10211
10212 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10213 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10214 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10215 count * sizeof(struct bgp_static)));
10216
10217 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10218 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10219 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10220 count * sizeof(struct bpacket)));
10221
10222 /* Adj-In/Out */
10223 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10224 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10225 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10226 count * sizeof(struct bgp_adj_in)));
10227 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10228 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10229 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10230 count * sizeof(struct bgp_adj_out)));
10231
10232 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10233 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10234 count,
10235 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10236 count * sizeof(struct bgp_nexthop_cache)));
10237
10238 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10239 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10240 count,
10241 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10242 count * sizeof(struct bgp_damp_info)));
10243
10244 /* Attributes */
10245 count = attr_count();
10246 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10247 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10248 count * sizeof(struct attr)));
10249
10250 if ((count = attr_unknown_count()))
10251 vty_out(vty, "%ld unknown attributes\n", count);
10252
10253 /* AS_PATH attributes */
10254 count = aspath_count();
10255 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10256 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10257 count * sizeof(struct aspath)));
10258
10259 count = mtype_stats_alloc(MTYPE_AS_SEG);
10260 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10261 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10262 count * sizeof(struct assegment)));
10263
10264 /* Other attributes */
10265 if ((count = community_count()))
10266 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10267 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10268 count * sizeof(struct community)));
d62a17ae 10269 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
145f7619
DA
10270 vty_out(vty,
10271 "%ld BGP ext-community entries, using %s of memory\n",
10272 count,
10273 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10274 count * sizeof(struct ecommunity)));
d62a17ae 10275 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10276 vty_out(vty,
10277 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10278 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10279 count * sizeof(struct lcommunity)));
d62a17ae 10280
10281 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10282 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10283 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10284 count * sizeof(struct cluster_list)));
10285
10286 /* Peer related usage */
10287 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10288 vty_out(vty, "%ld peers, using %s of memory\n", count,
10289 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10290 count * sizeof(struct peer)));
10291
10292 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10293 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10294 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10295 count * sizeof(struct peer_group)));
10296
10297 /* Other */
d62a17ae 10298 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10299 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10300 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10301 count * sizeof(regex_t)));
d62a17ae 10302 return CMD_SUCCESS;
4bf6a362 10303}
fee0f4c6 10304
57a9c8a8
DS
10305static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10306{
10307 json_object *bestpath = json_object_new_object();
10308
892fedb6 10309 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10310 json_object_string_add(bestpath, "asPath", "ignore");
10311
892fedb6 10312 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10313 json_object_string_add(bestpath, "asPath", "confed");
10314
892fedb6
DA
10315 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10316 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10317 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10318 "as-set");
10319 else
a4d82a8a 10320 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10321 "true");
10322 } else
a4d82a8a 10323 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10324
ee88563a
JM
10325 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10326 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10327
892fedb6 10328 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10329 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10330 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10331 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10332 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10333 json_object_string_add(bestpath, "med", "confed");
892fedb6 10334 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10335 json_object_string_add(bestpath, "med",
10336 "missing-as-worst");
10337 else
10338 json_object_string_add(bestpath, "med", "true");
10339 }
10340
10341 json_object_object_add(json, "bestPath", bestpath);
10342}
10343
3577f1c5
DD
10344/* Print the error code/subcode for why the peer is down */
10345static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10346 json_object *json_peer, bool use_json)
10347{
10348 const char *code_str;
10349 const char *subcode_str;
10350
10351 if (use_json) {
10352 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10353 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10354 char errorcodesubcode_hexstr[5];
10355 char errorcodesubcode_str[256];
10356
10357 code_str = bgp_notify_code_str(peer->notify.code);
10358 subcode_str = bgp_notify_subcode_str(
10359 peer->notify.code,
10360 peer->notify.subcode);
10361
772270f3
QY
10362 snprintf(errorcodesubcode_hexstr,
10363 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10364 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10365 json_object_string_add(json_peer,
10366 "lastErrorCodeSubcode",
10367 errorcodesubcode_hexstr);
10368 snprintf(errorcodesubcode_str, 255, "%s%s",
10369 code_str, subcode_str);
10370 json_object_string_add(json_peer,
10371 "lastNotificationReason",
10372 errorcodesubcode_str);
eea685b6
DA
10373 json_object_boolean_add(json_peer,
10374 "lastNotificationHardReset",
10375 peer->notify.hard_reset);
3577f1c5
DD
10376 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10377 && peer->notify.code == BGP_NOTIFY_CEASE
10378 && (peer->notify.subcode
10379 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10380 || peer->notify.subcode
10381 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10382 && peer->notify.length) {
10383 char msgbuf[1024];
10384 const char *msg_str;
10385
10386 msg_str = bgp_notify_admin_message(
10387 msgbuf, sizeof(msgbuf),
10388 (uint8_t *)peer->notify.data,
10389 peer->notify.length);
10390 if (msg_str)
10391 json_object_string_add(
10392 json_peer,
10393 "lastShutdownDescription",
10394 msg_str);
10395 }
10396
c258527b 10397 }
3577f1c5
DD
10398 json_object_string_add(json_peer, "lastResetDueTo",
10399 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10400 json_object_int_add(json_peer, "lastResetCode",
10401 peer->last_reset);
3577f1c5
DD
10402 } else {
10403 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10404 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10405 code_str = bgp_notify_code_str(peer->notify.code);
10406 subcode_str =
10407 bgp_notify_subcode_str(peer->notify.code,
10408 peer->notify.subcode);
eea685b6 10409 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10410 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10411 ? "sent"
10412 : "received",
10413 code_str, subcode_str,
10414 peer->notify.hard_reset
10415 ? bgp_notify_subcode_str(
10416 BGP_NOTIFY_CEASE,
10417 BGP_NOTIFY_CEASE_HARD_RESET)
10418 : "");
3577f1c5 10419 } else {
e91c24c8 10420 vty_out(vty, " %s\n",
3577f1c5
DD
10421 peer_down_str[(int)peer->last_reset]);
10422 }
10423 }
10424}
10425
10426static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10427 safi_t safi)
10428{
feb17238 10429 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10430}
10431
10432static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10433 struct peer *peer, json_object *json_peer,
10434 int max_neighbor_width, bool use_json)
10435{
10436 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10437 int len;
10438
10439 if (use_json) {
10440 if (peer_dynamic_neighbor(peer))
10441 json_object_boolean_true_add(json_peer,
10442 "dynamicPeer");
10443 if (peer->hostname)
10444 json_object_string_add(json_peer, "hostname",
10445 peer->hostname);
10446
10447 if (peer->domainname)
10448 json_object_string_add(json_peer, "domainname",
10449 peer->domainname);
10450 json_object_int_add(json_peer, "connectionsEstablished",
10451 peer->established);
10452 json_object_int_add(json_peer, "connectionsDropped",
10453 peer->dropped);
10454 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10455 use_json, json_peer);
feb17238 10456 if (peer_established(peer))
3577f1c5
DD
10457 json_object_string_add(json_peer, "lastResetDueTo",
10458 "AFI/SAFI Not Negotiated");
10459 else
10460 bgp_show_peer_reset(NULL, peer, json_peer, true);
10461 } else {
10462 dn_flag[1] = '\0';
10463 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10464 if (peer->hostname
892fedb6 10465 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10466 len = vty_out(vty, "%s%s(%s)", dn_flag,
10467 peer->hostname, peer->host);
10468 else
10469 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10470
10471 /* pad the neighbor column with spaces */
10472 if (len < max_neighbor_width)
10473 vty_out(vty, "%*s", max_neighbor_width - len,
10474 " ");
e91c24c8 10475 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10476 peer->dropped,
10477 peer_uptime(peer->uptime, timebuf,
10478 BGP_UPTIME_LEN, 0, NULL));
feb17238 10479 if (peer_established(peer))
3577f1c5
DD
10480 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10481 else
10482 bgp_show_peer_reset(vty, peer, NULL,
10483 false);
10484 }
10485}
c258527b 10486
565e9ddd 10487/* Strip peer's description to the given size. */
cb75bb31
DA
10488static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10489{
10490 static char stripped[BUFSIZ];
64541ffa
FD
10491 uint32_t i = 0;
10492 uint32_t last_space = 0;
cb75bb31 10493
64541ffa
FD
10494 while (i < size) {
10495 if (*(desc + i) == 0) {
10496 stripped[i] = '\0';
10497 return stripped;
10498 }
10499 if (i != 0 && *(desc + i) == ' ' && last_space != i - 1)
10500 last_space = i;
10501 stripped[i] = *(desc + i);
10502 i++;
10503 }
10504
10505 if (last_space > size)
10506 stripped[size + 1] = '\0';
10507 else
10508 stripped[last_space] = '\0';
cb75bb31
DA
10509
10510 return stripped;
10511}
3577f1c5 10512
8c1d4cd5
LS
10513/* Determine whether var peer should be filtered out of the summary. */
10514static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10515 struct peer *fpeer, int as_type,
10516 as_t as)
10517{
10518
10519 /* filter neighbor XXXX */
10520 if (fpeer && fpeer != peer)
10521 return true;
10522
10523 /* filter remote-as (internal|external) */
10524 if (as_type != AS_UNSPECIFIED) {
10525 if (peer->as_type == AS_SPECIFIED) {
10526 if (as_type == AS_INTERNAL) {
10527 if (peer->as != peer->local_as)
10528 return true;
10529 } else if (peer->as == peer->local_as)
10530 return true;
10531 } else if (as_type != peer->as_type)
10532 return true;
10533 } else if (as && as != peer->as) /* filter remote-as XXX */
10534 return true;
10535
10536 return false;
10537}
10538
565e9ddd
DA
10539/* Show BGP peer's summary information.
10540 *
10541 * Peer's description is stripped according to if `wide` option is given
10542 * or not.
10543 *
10544 * When adding new columns to `show bgp summary` output, please make
10545 * sure `Desc` is the lastest column to show because it can contain
10546 * whitespaces and the whole output will be tricky.
10547 */
d62a17ae 10548static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10549 struct peer *fpeer, int as_type, as_t as,
96c81f66 10550 uint16_t show_flags)
d62a17ae 10551{
10552 struct peer *peer;
10553 struct listnode *node, *nnode;
10554 unsigned int count = 0, dn_count = 0;
10555 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10556 char neighbor_buf[VTY_BUFSIZ];
10557 int neighbor_col_default_width = 16;
3577f1c5 10558 int len, failed_count = 0;
ce1944f0 10559 unsigned int filtered_count = 0;
d62a17ae 10560 int max_neighbor_width = 0;
10561 int pfx_rcd_safi;
3c13337d 10562 json_object *json = NULL;
d62a17ae 10563 json_object *json_peer = NULL;
10564 json_object *json_peers = NULL;
50e05855 10565 struct peer_af *paf;
d3ada366 10566 struct bgp_filter *filter;
85eeb029
DA
10567 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10568 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10569 bool show_established =
10570 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10571 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10572 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10573
10574 /* labeled-unicast routes are installed in the unicast table so in order
10575 * to
10576 * display the correct PfxRcd value we must look at SAFI_UNICAST
10577 */
3577f1c5 10578
d62a17ae 10579 if (safi == SAFI_LABELED_UNICAST)
10580 pfx_rcd_safi = SAFI_UNICAST;
10581 else
10582 pfx_rcd_safi = safi;
10583
10584 if (use_json) {
3c13337d 10585 json = json_object_new_object();
d62a17ae 10586 json_peers = json_object_new_object();
3577f1c5 10587 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10588 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10589 as_type, as)) {
ce1944f0 10590 filtered_count++;
8c1d4cd5
LS
10591 count++;
10592 continue;
10593 }
10594
3577f1c5
DD
10595 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10596 continue;
10597
10598 if (peer->afc[afi][safi]) {
10599 /* See if we have at least a single failed peer */
10600 if (bgp_has_peer_failed(peer, afi, safi))
10601 failed_count++;
10602 count++;
10603 }
10604 if (peer_dynamic_neighbor(peer))
10605 dn_count++;
10606 }
c258527b 10607
d62a17ae 10608 } else {
10609 /* Loop over all neighbors that will be displayed to determine
10610 * how many
10611 * characters are needed for the Neighbor column
10612 */
10613 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10614 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10615 as_type, as)) {
ce1944f0 10616 filtered_count++;
8c1d4cd5
LS
10617 count++;
10618 continue;
10619 }
10620
d62a17ae 10621 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10622 continue;
10623
10624 if (peer->afc[afi][safi]) {
10625 memset(dn_flag, '\0', sizeof(dn_flag));
10626 if (peer_dynamic_neighbor(peer))
10627 dn_flag[0] = '*';
10628
10629 if (peer->hostname
892fedb6
DA
10630 && CHECK_FLAG(bgp->flags,
10631 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10632 snprintf(neighbor_buf,
10633 sizeof(neighbor_buf),
10634 "%s%s(%s) ", dn_flag,
10635 peer->hostname, peer->host);
d62a17ae 10636 else
772270f3
QY
10637 snprintf(neighbor_buf,
10638 sizeof(neighbor_buf), "%s%s ",
10639 dn_flag, peer->host);
d62a17ae 10640
10641 len = strlen(neighbor_buf);
10642
10643 if (len > max_neighbor_width)
10644 max_neighbor_width = len;
c258527b 10645
3577f1c5
DD
10646 /* See if we have at least a single failed peer */
10647 if (bgp_has_peer_failed(peer, afi, safi))
10648 failed_count++;
10649 count++;
d62a17ae 10650 }
10651 }
f933309e 10652
d62a17ae 10653 /* Originally we displayed the Neighbor column as 16
10654 * characters wide so make that the default
10655 */
10656 if (max_neighbor_width < neighbor_col_default_width)
10657 max_neighbor_width = neighbor_col_default_width;
10658 }
f933309e 10659
3577f1c5
DD
10660 if (show_failed && !failed_count) {
10661 if (use_json) {
10662 json_object_int_add(json, "failedPeersCount", 0);
10663 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10664 json_object_int_add(json, "totalPeers", count);
3577f1c5 10665
75eeda93 10666 vty_json(vty, json);
3577f1c5
DD
10667 } else {
10668 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10669 }
10670 return CMD_SUCCESS;
10671 }
c258527b 10672
3577f1c5 10673 count = 0; /* Reset the value as its used again */
ce1944f0 10674 filtered_count = 0;
800867d8 10675 dn_count = 0;
d62a17ae 10676 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10677 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10678 continue;
10679
ea47320b
DL
10680 if (!peer->afc[afi][safi])
10681 continue;
d62a17ae 10682
ea47320b
DL
10683 if (!count) {
10684 unsigned long ents;
10685 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10686 int64_t vrf_id_ui;
d62a17ae 10687
a4d82a8a
PZ
10688 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10689 ? -1
10690 : (int64_t)bgp->vrf_id;
ea47320b
DL
10691
10692 /* Usage summary and header */
10693 if (use_json) {
c949c771
DA
10694 json_object_string_addf(json, "routerId",
10695 "%pI4",
10696 &bgp->router_id);
60466a63
QY
10697 json_object_int_add(json, "as", bgp->as);
10698 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10699 json_object_string_add(
10700 json, "vrfName",
10701 (bgp->inst_type
10702 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10703 ? VRF_DEFAULT_NAME
ea47320b
DL
10704 : bgp->name);
10705 } else {
10706 vty_out(vty,
23d0a753
DA
10707 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10708 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10709 bgp->vrf_id == VRF_UNKNOWN
10710 ? -1
10711 : (int)bgp->vrf_id);
ea47320b
DL
10712 vty_out(vty, "\n");
10713 }
d62a17ae 10714
ea47320b 10715 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10716 if (use_json) {
ea47320b 10717 json_object_int_add(
60466a63 10718 json, "updateDelayLimit",
ea47320b 10719 bgp->v_update_delay);
d62a17ae 10720
ea47320b
DL
10721 if (bgp->v_update_delay
10722 != bgp->v_establish_wait)
d62a17ae 10723 json_object_int_add(
10724 json,
ea47320b
DL
10725 "updateDelayEstablishWait",
10726 bgp->v_establish_wait);
d62a17ae 10727
60466a63 10728 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10729 json_object_string_add(
10730 json,
10731 "updateDelayFirstNeighbor",
10732 bgp->update_delay_begin_time);
10733 json_object_boolean_true_add(
10734 json,
10735 "updateDelayInProgress");
10736 } else {
10737 if (bgp->update_delay_over) {
d62a17ae 10738 json_object_string_add(
10739 json,
10740 "updateDelayFirstNeighbor",
10741 bgp->update_delay_begin_time);
ea47320b 10742 json_object_string_add(
d62a17ae 10743 json,
ea47320b
DL
10744 "updateDelayBestpathResumed",
10745 bgp->update_delay_end_time);
10746 json_object_string_add(
d62a17ae 10747 json,
ea47320b
DL
10748 "updateDelayZebraUpdateResume",
10749 bgp->update_delay_zebra_resume_time);
10750 json_object_string_add(
10751 json,
10752 "updateDelayPeerUpdateResume",
10753 bgp->update_delay_peers_resume_time);
d62a17ae 10754 }
ea47320b
DL
10755 }
10756 } else {
10757 vty_out(vty,
10758 "Read-only mode update-delay limit: %d seconds\n",
10759 bgp->v_update_delay);
10760 if (bgp->v_update_delay
10761 != bgp->v_establish_wait)
d62a17ae 10762 vty_out(vty,
ea47320b
DL
10763 " Establish wait: %d seconds\n",
10764 bgp->v_establish_wait);
d62a17ae 10765
60466a63 10766 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10767 vty_out(vty,
10768 " First neighbor established: %s\n",
10769 bgp->update_delay_begin_time);
10770 vty_out(vty,
10771 " Delay in progress\n");
10772 } else {
10773 if (bgp->update_delay_over) {
d62a17ae 10774 vty_out(vty,
10775 " First neighbor established: %s\n",
10776 bgp->update_delay_begin_time);
10777 vty_out(vty,
ea47320b
DL
10778 " Best-paths resumed: %s\n",
10779 bgp->update_delay_end_time);
10780 vty_out(vty,
10781 " zebra update resumed: %s\n",
10782 bgp->update_delay_zebra_resume_time);
10783 vty_out(vty,
10784 " peers update resumed: %s\n",
10785 bgp->update_delay_peers_resume_time);
d62a17ae 10786 }
10787 }
10788 }
ea47320b 10789 }
d62a17ae 10790
ea47320b
DL
10791 if (use_json) {
10792 if (bgp_maxmed_onstartup_configured(bgp)
10793 && bgp->maxmed_active)
10794 json_object_boolean_true_add(
60466a63 10795 json, "maxMedOnStartup");
ea47320b
DL
10796 if (bgp->v_maxmed_admin)
10797 json_object_boolean_true_add(
60466a63 10798 json, "maxMedAdministrative");
d62a17ae 10799
ea47320b
DL
10800 json_object_int_add(
10801 json, "tableVersion",
60466a63 10802 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10803
60466a63
QY
10804 ents = bgp_table_count(bgp->rib[afi][safi]);
10805 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10806 json_object_int_add(
10807 json, "ribMemory",
9bcb3eef 10808 ents * sizeof(struct bgp_dest));
d62a17ae 10809
210ec2a0 10810 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10811 json_object_int_add(json, "peerCount", ents);
10812 json_object_int_add(json, "peerMemory",
10813 ents * sizeof(struct peer));
d62a17ae 10814
ea47320b
DL
10815 if ((ents = listcount(bgp->group))) {
10816 json_object_int_add(
60466a63 10817 json, "peerGroupCount", ents);
ea47320b
DL
10818 json_object_int_add(
10819 json, "peerGroupMemory",
996c9314
LB
10820 ents * sizeof(struct
10821 peer_group));
ea47320b 10822 }
d62a17ae 10823
ea47320b
DL
10824 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10825 BGP_CONFIG_DAMPENING))
10826 json_object_boolean_true_add(
60466a63 10827 json, "dampeningEnabled");
ea47320b 10828 } else {
96c81f66
LS
10829 if (!show_terse) {
10830 if (bgp_maxmed_onstartup_configured(bgp)
10831 && bgp->maxmed_active)
10832 vty_out(vty,
10833 "Max-med on-startup active\n");
10834 if (bgp->v_maxmed_admin)
10835 vty_out(vty,
10836 "Max-med administrative active\n");
d62a17ae 10837
96c81f66
LS
10838 vty_out(vty,
10839 "BGP table version %" PRIu64
10840 "\n",
10841 bgp_table_version(
10842 bgp->rib[afi][safi]));
ea47320b 10843
96c81f66
LS
10844 ents = bgp_table_count(
10845 bgp->rib[afi][safi]);
d62a17ae 10846 vty_out(vty,
96c81f66 10847 "RIB entries %ld, using %s of memory\n",
d62a17ae 10848 ents,
10849 mtype_memstr(
10850 memstrbuf,
10851 sizeof(memstrbuf),
96c81f66
LS
10852 ents
10853 * sizeof(
10854 struct
10855 bgp_dest)));
d62a17ae 10856
96c81f66
LS
10857 /* Peer related usage */
10858 ents = bgp->af_peer_count[afi][safi];
10859 vty_out(vty,
10860 "Peers %ld, using %s of memory\n",
10861 ents,
10862 mtype_memstr(
10863 memstrbuf,
10864 sizeof(memstrbuf),
10865 ents
10866 * sizeof(
10867 struct
10868 peer)));
d62a17ae 10869
96c81f66
LS
10870 if ((ents = listcount(bgp->group)))
10871 vty_out(vty,
10872 "Peer groups %ld, using %s of memory\n",
10873 ents,
10874 mtype_memstr(
10875 memstrbuf,
10876 sizeof(memstrbuf),
10877 ents
10878 * sizeof(
10879 struct
10880 peer_group)));
10881
10882 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10883 BGP_CONFIG_DAMPENING))
10884 vty_out(vty,
10885 "Dampening enabled.\n");
10886 }
10887 if (show_failed) {
10888 vty_out(vty, "\n");
10889
10890 /* Subtract 8 here because 'Neighbor' is
10891 * 8 characters */
10892 vty_out(vty, "Neighbor");
10893 vty_out(vty, "%*s",
10894 max_neighbor_width - 8, " ");
85eeb029
DA
10895 vty_out(vty,
10896 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10897 }
d62a17ae 10898 }
ea47320b 10899 }
d62a17ae 10900
d55811cc 10901 paf = peer_af_find(peer, afi, safi);
d3ada366 10902 filter = &peer->filter[afi][safi];
db92d226 10903
ea47320b 10904 count++;
3577f1c5
DD
10905 /* Works for both failed & successful cases */
10906 if (peer_dynamic_neighbor(peer))
10907 dn_count++;
d62a17ae 10908
ea47320b 10909 if (use_json) {
3577f1c5 10910 json_peer = NULL;
8c1d4cd5 10911 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10912 as_type, as)) {
10913 filtered_count++;
8c1d4cd5 10914 continue;
ce1944f0 10915 }
3577f1c5
DD
10916 if (show_failed &&
10917 bgp_has_peer_failed(peer, afi, safi)) {
10918 json_peer = json_object_new_object();
10919 bgp_show_failed_summary(vty, bgp, peer,
10920 json_peer, 0, use_json);
10921 } else if (!show_failed) {
10b49f14 10922 if (show_established
ce1944f0
LS
10923 && bgp_has_peer_failed(peer, afi, safi)) {
10924 filtered_count++;
10b49f14 10925 continue;
ce1944f0 10926 }
10b49f14 10927
3577f1c5
DD
10928 json_peer = json_object_new_object();
10929 if (peer_dynamic_neighbor(peer)) {
10930 json_object_boolean_true_add(json_peer,
10931 "dynamicPeer");
10932 }
d62a17ae 10933
3577f1c5
DD
10934 if (peer->hostname)
10935 json_object_string_add(json_peer, "hostname",
10936 peer->hostname);
10937
10938 if (peer->domainname)
10939 json_object_string_add(json_peer, "domainname",
10940 peer->domainname);
10941
10942 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10943 json_object_int_add(
10944 json_peer, "localAs",
10945 peer->change_local_as
10946 ? peer->change_local_as
10947 : peer->local_as);
3577f1c5
DD
10948 json_object_int_add(json_peer, "version", 4);
10949 json_object_int_add(json_peer, "msgRcvd",
10950 PEER_TOTAL_RX(peer));
10951 json_object_int_add(json_peer, "msgSent",
10952 PEER_TOTAL_TX(peer));
10953
43aa5965
QY
10954 atomic_size_t outq_count, inq_count;
10955 outq_count = atomic_load_explicit(
10956 &peer->obuf->count,
10957 memory_order_relaxed);
10958 inq_count = atomic_load_explicit(
10959 &peer->ibuf->count,
10960 memory_order_relaxed);
10961
3577f1c5
DD
10962 json_object_int_add(json_peer, "tableVersion",
10963 peer->version[afi][safi]);
10964 json_object_int_add(json_peer, "outq",
43aa5965
QY
10965 outq_count);
10966 json_object_int_add(json_peer, "inq",
10967 inq_count);
3577f1c5
DD
10968 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10969 use_json, json_peer);
10970
3577f1c5
DD
10971 json_object_int_add(json_peer, "pfxRcd",
10972 peer->pcount[afi][pfx_rcd_safi]);
10973
3577f1c5 10974 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10975 json_object_int_add(
10976 json_peer, "pfxSnt",
10977 (PAF_SUBGRP(paf))->scount);
10978 else
10979 json_object_int_add(json_peer, "pfxSnt",
10980 0);
0e1f8ab5
DA
10981
10982 /* BGP FSM state */
cb9196e7 10983 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10984 || CHECK_FLAG(peer->bgp->flags,
10985 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10986 json_object_string_add(json_peer,
10987 "state",
3577f1c5
DD
10988 "Idle (Admin)");
10989 else if (peer->afc_recv[afi][safi])
10990 json_object_string_add(
0e1f8ab5
DA
10991 json_peer, "state",
10992 lookup_msg(bgp_status_msg,
10993 peer->status, NULL));
10994 else if (CHECK_FLAG(
10995 peer->sflags,
10996 PEER_STATUS_PREFIX_OVERFLOW))
10997 json_object_string_add(json_peer,
10998 "state",
3577f1c5
DD
10999 "Idle (PfxCt)");
11000 else
11001 json_object_string_add(
0e1f8ab5
DA
11002 json_peer, "state",
11003 lookup_msg(bgp_status_msg,
11004 peer->status, NULL));
11005
11006 /* BGP peer state */
11007 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11008 || CHECK_FLAG(peer->bgp->flags,
11009 BGP_FLAG_SHUTDOWN))
11010 json_object_string_add(json_peer,
11011 "peerState",
11012 "Admin");
11013 else if (CHECK_FLAG(
11014 peer->sflags,
11015 PEER_STATUS_PREFIX_OVERFLOW))
11016 json_object_string_add(json_peer,
11017 "peerState",
11018 "PfxCt");
11019 else if (CHECK_FLAG(peer->flags,
11020 PEER_FLAG_PASSIVE))
11021 json_object_string_add(json_peer,
11022 "peerState",
11023 "Passive");
11024 else if (CHECK_FLAG(peer->sflags,
11025 PEER_STATUS_NSF_WAIT))
11026 json_object_string_add(json_peer,
11027 "peerState",
11028 "NSF passive");
11029 else if (CHECK_FLAG(
11030 peer->bgp->flags,
11031 BGP_FLAG_EBGP_REQUIRES_POLICY)
11032 && (!bgp_inbound_policy_exists(peer,
11033 filter)
11034 || !bgp_outbound_policy_exists(
11035 peer, filter)))
11036 json_object_string_add(json_peer,
11037 "peerState",
11038 "Policy");
11039 else
11040 json_object_string_add(
11041 json_peer, "peerState", "OK");
11042
200116db
DD
11043 json_object_int_add(json_peer, "connectionsEstablished",
11044 peer->established);
11045 json_object_int_add(json_peer, "connectionsDropped",
11046 peer->dropped);
aa72bd7e
PG
11047 if (peer->desc)
11048 json_object_string_add(
11049 json_peer, "desc", peer->desc);
b4e9dcba 11050 }
3577f1c5
DD
11051 /* Avoid creating empty peer dicts in JSON */
11052 if (json_peer == NULL)
11053 continue;
ea47320b
DL
11054
11055 if (peer->conf_if)
60466a63 11056 json_object_string_add(json_peer, "idType",
ea47320b
DL
11057 "interface");
11058 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11059 json_object_string_add(json_peer, "idType",
11060 "ipv4");
ea47320b 11061 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11062 json_object_string_add(json_peer, "idType",
11063 "ipv6");
ea47320b
DL
11064 json_object_object_add(json_peers, peer->host,
11065 json_peer);
11066 } else {
8c1d4cd5 11067 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
11068 as_type, as)) {
11069 filtered_count++;
8c1d4cd5 11070 continue;
ce1944f0 11071 }
3577f1c5
DD
11072 if (show_failed &&
11073 bgp_has_peer_failed(peer, afi, safi)) {
11074 bgp_show_failed_summary(vty, bgp, peer, NULL,
11075 max_neighbor_width,
11076 use_json);
11077 } else if (!show_failed) {
10b49f14 11078 if (show_established
ce1944f0
LS
11079 && bgp_has_peer_failed(peer, afi, safi)) {
11080 filtered_count++;
10b49f14 11081 continue;
ce1944f0 11082 }
96c81f66
LS
11083
11084 if ((count - filtered_count) == 1) {
11085 /* display headline before the first
11086 * neighbor line */
11087 vty_out(vty, "\n");
11088
11089 /* Subtract 8 here because 'Neighbor' is
11090 * 8 characters */
11091 vty_out(vty, "Neighbor");
11092 vty_out(vty, "%*s",
11093 max_neighbor_width - 8, " ");
11094 vty_out(vty,
11095 show_wide
11096 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11097 : BGP_SHOW_SUMMARY_HEADER_ALL);
11098 }
11099
3577f1c5
DD
11100 memset(dn_flag, '\0', sizeof(dn_flag));
11101 if (peer_dynamic_neighbor(peer)) {
11102 dn_flag[0] = '*';
11103 }
d62a17ae 11104
3577f1c5 11105 if (peer->hostname
892fedb6
DA
11106 && CHECK_FLAG(bgp->flags,
11107 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11108 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11109 peer->hostname,
11110 peer->host);
d62a17ae 11111 else
3577f1c5
DD
11112 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11113
11114 /* pad the neighbor column with spaces */
11115 if (len < max_neighbor_width)
11116 vty_out(vty, "%*s", max_neighbor_width - len,
11117 " ");
11118
43aa5965
QY
11119 atomic_size_t outq_count, inq_count;
11120 outq_count = atomic_load_explicit(
11121 &peer->obuf->count,
11122 memory_order_relaxed);
11123 inq_count = atomic_load_explicit(
11124 &peer->ibuf->count,
11125 memory_order_relaxed);
11126
85eeb029
DA
11127 if (show_wide)
11128 vty_out(vty,
11129 "4 %10u %10u %9u %9u %8" PRIu64
11130 " %4zu %4zu %8s",
11131 peer->as,
11132 peer->change_local_as
11133 ? peer->change_local_as
11134 : peer->local_as,
11135 PEER_TOTAL_RX(peer),
11136 PEER_TOTAL_TX(peer),
11137 peer->version[afi][safi],
11138 inq_count, outq_count,
11139 peer_uptime(peer->uptime,
11140 timebuf,
11141 BGP_UPTIME_LEN, 0,
11142 NULL));
11143 else
11144 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11145 " %4zu %4zu %8s",
11146 peer->as, PEER_TOTAL_RX(peer),
11147 PEER_TOTAL_TX(peer),
11148 peer->version[afi][safi],
11149 inq_count, outq_count,
11150 peer_uptime(peer->uptime,
11151 timebuf,
11152 BGP_UPTIME_LEN, 0,
11153 NULL));
3577f1c5 11154
feb17238 11155 if (peer_established(peer)) {
d3ada366
DA
11156 if (peer->afc_recv[afi][safi]) {
11157 if (CHECK_FLAG(
11158 bgp->flags,
11159 BGP_FLAG_EBGP_REQUIRES_POLICY)
11160 && !bgp_inbound_policy_exists(
11161 peer, filter))
11162 vty_out(vty, " %12s",
11163 "(Policy)");
11164 else
11165 vty_out(vty,
6cde4b45 11166 " %12u",
d3ada366
DA
11167 peer->pcount
11168 [afi]
11169 [pfx_rcd_safi]);
11170 } else {
749d0f27 11171 vty_out(vty, " NoNeg");
d3ada366 11172 }
db92d226 11173
d3ada366
DA
11174 if (paf && PAF_SUBGRP(paf)) {
11175 if (CHECK_FLAG(
11176 bgp->flags,
11177 BGP_FLAG_EBGP_REQUIRES_POLICY)
11178 && !bgp_outbound_policy_exists(
11179 peer, filter))
11180 vty_out(vty, " %8s",
11181 "(Policy)");
11182 else
11183 vty_out(vty,
6cde4b45 11184 " %8u",
d3ada366
DA
11185 (PAF_SUBGRP(
11186 paf))
11187 ->scount);
749d0f27
DA
11188 } else {
11189 vty_out(vty, " NoNeg");
d3ada366 11190 }
db92d226 11191 } else {
736b68f3
DS
11192 if (CHECK_FLAG(peer->flags,
11193 PEER_FLAG_SHUTDOWN)
11194 || CHECK_FLAG(peer->bgp->flags,
11195 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11196 vty_out(vty, " Idle (Admin)");
11197 else if (CHECK_FLAG(
11198 peer->sflags,
11199 PEER_STATUS_PREFIX_OVERFLOW))
11200 vty_out(vty, " Idle (PfxCt)");
11201 else
11202 vty_out(vty, " %12s",
11203 lookup_msg(bgp_status_msg,
11204 peer->status, NULL));
db92d226 11205
6cde4b45 11206 vty_out(vty, " %8u", 0);
3577f1c5 11207 }
565e9ddd
DA
11208 /* Make sure `Desc` column is the lastest in
11209 * the output.
11210 */
aa72bd7e 11211 if (peer->desc)
cb75bb31
DA
11212 vty_out(vty, " %s",
11213 bgp_peer_description_stripped(
85eeb029
DA
11214 peer->desc,
11215 show_wide ? 64 : 20));
aa72bd7e
PG
11216 else
11217 vty_out(vty, " N/A");
3577f1c5 11218 vty_out(vty, "\n");
d62a17ae 11219 }
3577f1c5 11220
d62a17ae 11221 }
11222 }
f933309e 11223
d62a17ae 11224 if (use_json) {
11225 json_object_object_add(json, "peers", json_peers);
3577f1c5 11226 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
11227 json_object_int_add(json, "displayedPeers",
11228 count - filtered_count);
d62a17ae 11229 json_object_int_add(json, "totalPeers", count);
11230 json_object_int_add(json, "dynamicPeers", dn_count);
11231
3577f1c5
DD
11232 if (!show_failed)
11233 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11234
75eeda93 11235 vty_json(vty, json);
d62a17ae 11236 } else {
ce1944f0 11237 if (count) {
96c81f66
LS
11238 if (filtered_count == count)
11239 vty_out(vty, "\n%% No matching neighbor\n");
11240 else {
11241 if (show_failed)
11242 vty_out(vty, "\nDisplayed neighbors %d",
11243 failed_count);
11244 else if (as_type != AS_UNSPECIFIED || as
11245 || fpeer || show_established)
ce1944f0
LS
11246 vty_out(vty, "\nDisplayed neighbors %d",
11247 count - filtered_count);
96c81f66
LS
11248
11249 vty_out(vty, "\nTotal number of neighbors %d\n",
11250 count);
ce1944f0 11251 }
ce1944f0 11252 } else {
d6ceaca3 11253 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11254 get_afi_safi_str(afi, safi, false));
d62a17ae 11255 }
b05a1c8b 11256
d6ceaca3 11257 if (dn_count) {
d62a17ae 11258 vty_out(vty, "* - dynamic neighbor\n");
11259 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11260 dn_count, bgp->dynamic_neighbors_limit);
11261 }
11262 }
1ff9a340 11263
d62a17ae 11264 return CMD_SUCCESS;
718e3744 11265}
11266
d62a17ae 11267static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 11268 int safi, struct peer *fpeer, int as_type,
96c81f66 11269 as_t as, uint16_t show_flags)
d62a17ae 11270{
11271 int is_first = 1;
11272 int afi_wildcard = (afi == AFI_MAX);
11273 int safi_wildcard = (safi == SAFI_MAX);
11274 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11275 bool nbr_output = false;
85eeb029 11276 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11277
11278 if (use_json && is_wildcard)
11279 vty_out(vty, "{\n");
11280 if (afi_wildcard)
11281 afi = 1; /* AFI_IP */
11282 while (afi < AFI_MAX) {
11283 if (safi_wildcard)
11284 safi = 1; /* SAFI_UNICAST */
11285 while (safi < SAFI_MAX) {
318cac96 11286 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11287 nbr_output = true;
f86897b9 11288
d62a17ae 11289 if (is_wildcard) {
11290 /*
11291 * So limit output to those afi/safi
11292 * pairs that
11293 * actualy have something interesting in
11294 * them
11295 */
11296 if (use_json) {
d62a17ae 11297 if (!is_first)
11298 vty_out(vty, ",\n");
11299 else
11300 is_first = 0;
11301
11302 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11303 get_afi_safi_str(afi,
11304 safi,
11305 true));
d62a17ae 11306 } else {
6cac2fcc
LS
11307 vty_out(vty,
11308 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11309 get_afi_safi_str(afi,
11310 safi,
6cac2fcc
LS
11311 false),
11312 bgp->name_pretty);
d62a17ae 11313 }
11314 }
8c1d4cd5
LS
11315 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11316 as_type, as, show_flags);
d62a17ae 11317 }
11318 safi++;
d62a17ae 11319 if (!safi_wildcard)
11320 safi = SAFI_MAX;
11321 }
11322 afi++;
ee851c8c 11323 if (!afi_wildcard)
d62a17ae 11324 afi = AFI_MAX;
11325 }
11326
11327 if (use_json && is_wildcard)
11328 vty_out(vty, "}\n");
ca61fd25
DS
11329 else if (!nbr_output) {
11330 if (use_json)
11331 vty_out(vty, "{}\n");
11332 else
6cac2fcc
LS
11333 vty_out(vty, "%% No BGP neighbors found in %s\n",
11334 bgp->name_pretty);
ca61fd25 11335 }
d62a17ae 11336}
11337
11338static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11339 safi_t safi,
11340 const char *neighbor,
11341 int as_type, as_t as,
96c81f66 11342 uint16_t show_flags)
d62a17ae 11343{
11344 struct listnode *node, *nnode;
11345 struct bgp *bgp;
8c1d4cd5 11346 struct peer *fpeer = NULL;
d62a17ae 11347 int is_first = 1;
9f049418 11348 bool nbr_output = false;
85eeb029 11349 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11350
11351 if (use_json)
11352 vty_out(vty, "{\n");
11353
11354 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11355 nbr_output = true;
d62a17ae 11356 if (use_json) {
d62a17ae 11357 if (!is_first)
11358 vty_out(vty, ",\n");
11359 else
11360 is_first = 0;
11361
11362 vty_out(vty, "\"%s\":",
11363 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11364 ? VRF_DEFAULT_NAME
d62a17ae 11365 : bgp->name);
d62a17ae 11366 }
8c1d4cd5
LS
11367 if (neighbor) {
11368 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11369 use_json);
11370 if (!fpeer)
11371 continue;
11372 }
11373 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11374 as, show_flags);
d62a17ae 11375 }
11376
11377 if (use_json)
11378 vty_out(vty, "}\n");
9f049418
DS
11379 else if (!nbr_output)
11380 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11381}
11382
11383int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11384 safi_t safi, const char *neighbor, int as_type,
96c81f66 11385 as_t as, uint16_t show_flags)
d62a17ae 11386{
11387 struct bgp *bgp;
85eeb029 11388 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11389 struct peer *fpeer = NULL;
d62a17ae 11390
11391 if (name) {
11392 if (strmatch(name, "all")) {
85eeb029 11393 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11394 neighbor, as_type,
11395 as, show_flags);
d62a17ae 11396 return CMD_SUCCESS;
11397 } else {
11398 bgp = bgp_lookup_by_name(name);
11399
11400 if (!bgp) {
11401 if (use_json)
11402 vty_out(vty, "{}\n");
11403 else
11404 vty_out(vty,
ca61fd25 11405 "%% BGP instance not found\n");
d62a17ae 11406 return CMD_WARNING;
11407 }
11408
8c1d4cd5
LS
11409 if (neighbor) {
11410 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11411 use_json);
11412 if (!fpeer)
11413 return CMD_WARNING;
11414 }
11415 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11416 as_type, as, show_flags);
d62a17ae 11417 return CMD_SUCCESS;
11418 }
11419 }
11420
11421 bgp = bgp_get_default();
11422
8c1d4cd5
LS
11423 if (bgp) {
11424 if (neighbor) {
11425 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11426 use_json);
11427 if (!fpeer)
11428 return CMD_WARNING;
11429 }
11430 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11431 as, show_flags);
11432 } else {
ca61fd25
DS
11433 if (use_json)
11434 vty_out(vty, "{}\n");
11435 else
11436 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11437 return CMD_WARNING;
11438 }
d62a17ae 11439
11440 return CMD_SUCCESS;
4fb25c53
DW
11441}
11442
716b2d8a 11443/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11444DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11445 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11446 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11447 "]] [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
11448 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11449 BGP_SAFI_WITH_LABEL_HELP_STR
11450 "Display the entries for all address families\n"
11451 "Summary of BGP neighbor status\n"
11452 "Show only sessions in Established state\n"
11453 "Show only sessions not in Established state\n"
11454 "Show only the specified neighbor session\n"
11455 "Neighbor to display information about\n"
11456 "Neighbor to display information about\n"
11457 "Neighbor on BGP configured interface\n"
11458 "Show only the specified remote AS sessions\n"
11459 "AS number\n"
11460 "Internal (iBGP) AS sessions\n"
11461 "External (eBGP) AS sessions\n"
96c81f66 11462 "Shorten the information on BGP instances\n"
8c1d4cd5 11463 "Increase table width for longer output\n" JSON_STR)
718e3744 11464{
d62a17ae 11465 char *vrf = NULL;
11466 afi_t afi = AFI_MAX;
11467 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11468 as_t as = 0; /* 0 means AS filter not set */
11469 int as_type = AS_UNSPECIFIED;
96c81f66 11470 uint16_t show_flags = 0;
d62a17ae 11471
11472 int idx = 0;
11473
11474 /* show [ip] bgp */
96f3485c 11475 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11476 afi = AFI_IP;
9a8bdf1c
PG
11477 /* [<vrf> VIEWVRFNAME] */
11478 if (argv_find(argv, argc, "vrf", &idx)) {
11479 vrf = argv[idx + 1]->arg;
11480 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11481 vrf = NULL;
11482 } else if (argv_find(argv, argc, "view", &idx))
11483 /* [<view> VIEWVRFNAME] */
11484 vrf = argv[idx + 1]->arg;
d62a17ae 11485 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11486 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11487 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11488 }
11489
3577f1c5 11490 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11491 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11492
10b49f14 11493 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11494 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11495
8c1d4cd5
LS
11496 if (argv_find(argv, argc, "remote-as", &idx)) {
11497 if (argv[idx + 1]->arg[0] == 'i')
11498 as_type = AS_INTERNAL;
11499 else if (argv[idx + 1]->arg[0] == 'e')
11500 as_type = AS_EXTERNAL;
11501 else
11502 as = (as_t)atoi(argv[idx + 1]->arg);
11503 }
11504
96c81f66
LS
11505 if (argv_find(argv, argc, "terse", &idx))
11506 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11507
85eeb029
DA
11508 if (argv_find(argv, argc, "wide", &idx))
11509 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11510
11511 if (argv_find(argv, argc, "json", &idx))
11512 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11513
8c1d4cd5
LS
11514 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11515 show_flags);
d62a17ae 11516}
11517
5cb5f4d0 11518const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11519{
5cb5f4d0
DD
11520 if (for_json)
11521 return get_afi_safi_json_str(afi, safi);
d62a17ae 11522 else
5cb5f4d0 11523 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11524}
11525
d62a17ae 11526
11527static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11528 afi_t afi, safi_t safi,
d7c0a89a
QY
11529 uint16_t adv_smcap, uint16_t adv_rmcap,
11530 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11531 bool use_json, json_object *json_pref)
d62a17ae 11532{
11533 /* Send-Mode */
11534 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11535 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11536 if (use_json) {
11537 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11538 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11539 json_object_string_add(json_pref, "sendMode",
11540 "advertisedAndReceived");
11541 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11542 json_object_string_add(json_pref, "sendMode",
11543 "advertised");
11544 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11545 json_object_string_add(json_pref, "sendMode",
11546 "received");
11547 } else {
11548 vty_out(vty, " Send-mode: ");
11549 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11550 vty_out(vty, "advertised");
11551 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11552 vty_out(vty, "%sreceived",
11553 CHECK_FLAG(p->af_cap[afi][safi],
11554 adv_smcap)
11555 ? ", "
11556 : "");
11557 vty_out(vty, "\n");
11558 }
11559 }
11560
11561 /* Receive-Mode */
11562 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11563 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11564 if (use_json) {
11565 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11566 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11567 json_object_string_add(json_pref, "recvMode",
11568 "advertisedAndReceived");
11569 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11570 json_object_string_add(json_pref, "recvMode",
11571 "advertised");
11572 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11573 json_object_string_add(json_pref, "recvMode",
11574 "received");
11575 } else {
11576 vty_out(vty, " Receive-mode: ");
11577 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11578 vty_out(vty, "advertised");
11579 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11580 vty_out(vty, "%sreceived",
11581 CHECK_FLAG(p->af_cap[afi][safi],
11582 adv_rmcap)
11583 ? ", "
11584 : "");
11585 vty_out(vty, "\n");
11586 }
11587 }
11588}
11589
eea685b6
DA
11590static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11591 struct peer *p,
11592 bool use_json,
11593 json_object *json)
2986cac2 11594{
eea685b6
DA
11595 bool rbit = false;
11596 bool nbit = false;
2986cac2 11597
13909c4f
DS
11598 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11599 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11600 && (peer_established(p))) {
eea685b6
DA
11601 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11602 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 11603 }
11604
eea685b6
DA
11605 if (use_json) {
11606 json_object_boolean_add(json, "rBit", rbit);
11607 json_object_boolean_add(json, "nBit", nbit);
2986cac2 11608 } else {
eea685b6
DA
11609 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11610 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 11611 }
11612}
11613
13909c4f
DS
11614static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11615 struct peer *peer,
11616 bool use_json,
11617 json_object *json)
2986cac2 11618{
2bb5d39b 11619 const char *mode = "NotApplicable";
2986cac2 11620
11621 if (!use_json)
a53ca37b 11622 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11623
13909c4f 11624 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11625 && (peer_established(peer))) {
2986cac2 11626
13909c4f
DS
11627 if ((peer->nsf_af_count == 0)
11628 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11629
2986cac2 11630 mode = "Disable";
11631
13909c4f
DS
11632 } else if (peer->nsf_af_count == 0
11633 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11634
2986cac2 11635 mode = "Helper";
11636
13909c4f
DS
11637 } else if (peer->nsf_af_count != 0
11638 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11639
2986cac2 11640 mode = "Restart";
2986cac2 11641 }
11642 }
11643
11644 if (use_json) {
13909c4f 11645 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11646 } else
11647 vty_out(vty, mode, "\n");
11648}
11649
13909c4f
DS
11650static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11651 struct peer *p,
11652 bool use_json,
11653 json_object *json)
2986cac2 11654{
11655 const char *mode = "Invalid";
11656
11657 if (!use_json)
a53ca37b 11658 vty_out(vty, " Local GR Mode: ");
2986cac2 11659
11660 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11661 mode = "Helper";
11662 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11663 mode = "Restart";
11664 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11665 mode = "Disable";
2ba1fe69 11666 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11667 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11668 mode = "Helper*";
11669 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11670 mode = "Restart*";
11671 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11672 mode = "Disable*";
11673 else
11674 mode = "Invalid*";
2ba1fe69 11675 }
2986cac2 11676
11677 if (use_json) {
13909c4f 11678 json_object_string_add(json, "localGrMode", mode);
2986cac2 11679 } else {
11680 vty_out(vty, mode, "\n");
11681 }
11682}
11683
13909c4f
DS
11684static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11685 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11686{
2ba1fe69 11687 afi_t afi;
11688 safi_t safi;
2986cac2 11689 json_object *json_afi_safi = NULL;
11690 json_object *json_timer = NULL;
11691 json_object *json_endofrib_status = NULL;
9e3b51a7 11692 bool eor_flag = false;
2986cac2 11693
df8d723c
DA
11694 FOREACH_AFI_SAFI_NSF (afi, safi) {
11695 if (!peer->afc[afi][safi])
11696 continue;
2986cac2 11697
df8d723c
DA
11698 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11699 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11700 continue;
9e3b51a7 11701
df8d723c
DA
11702 if (use_json) {
11703 json_afi_safi = json_object_new_object();
11704 json_endofrib_status = json_object_new_object();
11705 json_timer = json_object_new_object();
11706 }
2986cac2 11707
df8d723c
DA
11708 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11709 eor_flag = true;
11710 else
11711 eor_flag = false;
2986cac2 11712
df8d723c
DA
11713 if (!use_json) {
11714 vty_out(vty, " %s:\n",
11715 get_afi_safi_str(afi, safi, false));
2986cac2 11716
df8d723c
DA
11717 vty_out(vty, " F bit: ");
11718 }
2986cac2 11719
df8d723c
DA
11720 if (peer->nsf[afi][safi] &&
11721 CHECK_FLAG(peer->af_cap[afi][safi],
11722 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11723
df8d723c
DA
11724 if (use_json) {
11725 json_object_boolean_true_add(json_afi_safi,
11726 "fBit");
11727 } else
11728 vty_out(vty, "True\n");
11729 } else {
11730 if (use_json)
11731 json_object_boolean_false_add(json_afi_safi,
11732 "fBit");
11733 else
11734 vty_out(vty, "False\n");
11735 }
2986cac2 11736
df8d723c
DA
11737 if (!use_json)
11738 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11739
df8d723c
DA
11740 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11741 PEER_STATUS_EOR_SEND)) {
11742 if (use_json) {
11743 json_object_boolean_true_add(
11744 json_endofrib_status, "endOfRibSend");
9e3b51a7 11745
df8d723c
DA
11746 PRINT_EOR_JSON(eor_flag);
11747 } else {
11748 vty_out(vty, "Yes\n");
11749 vty_out(vty,
11750 " End-of-RIB sent after update: ");
2986cac2 11751
df8d723c
DA
11752 PRINT_EOR(eor_flag);
11753 }
11754 } else {
11755 if (use_json) {
11756 json_object_boolean_false_add(
11757 json_endofrib_status, "endOfRibSend");
11758 json_object_boolean_false_add(
11759 json_endofrib_status,
11760 "endOfRibSentAfterUpdate");
13909c4f 11761 } else {
df8d723c
DA
11762 vty_out(vty, "No\n");
11763 vty_out(vty,
11764 " End-of-RIB sent after update: ");
11765 vty_out(vty, "No\n");
13909c4f 11766 }
df8d723c 11767 }
2986cac2 11768
df8d723c
DA
11769 if (!use_json)
11770 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11771
df8d723c
DA
11772 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11773 PEER_STATUS_EOR_RECEIVED)) {
11774 if (use_json)
11775 json_object_boolean_true_add(
11776 json_endofrib_status, "endOfRibRecv");
11777 else
11778 vty_out(vty, "Yes\n");
11779 } else {
11780 if (use_json)
11781 json_object_boolean_false_add(
11782 json_endofrib_status, "endOfRibRecv");
11783 else
11784 vty_out(vty, "No\n");
11785 }
11786
11787 if (use_json) {
11788 json_object_int_add(json_timer, "stalePathTimer",
11789 peer->bgp->stalepath_time);
11790
11791 if (peer->t_gr_stale != NULL) {
11792 json_object_int_add(json_timer,
11793 "stalePathTimerRemaining",
11794 thread_timer_remain_second(
11795 peer->t_gr_stale));
a53ca37b
DA
11796 }
11797
df8d723c
DA
11798 /* Display Configured Selection
11799 * Deferral only when when
11800 * Gr mode is enabled.
11801 */
11802 if (CHECK_FLAG(peer->flags,
11803 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11804 json_object_int_add(json_timer,
df8d723c 11805 "selectionDeferralTimer",
13909c4f 11806 peer->bgp->stalepath_time);
df8d723c 11807 }
2986cac2 11808
df8d723c
DA
11809 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11810 NULL) {
2986cac2 11811
df8d723c
DA
11812 json_object_int_add(
11813 json_timer,
11814 "selectionDeferralTimerRemaining",
11815 thread_timer_remain_second(
11816 peer->bgp->gr_info[afi][safi]
11817 .t_select_deferral));
11818 }
11819 } else {
11820 vty_out(vty, " Timers:\n");
11821 vty_out(vty,
11822 " Configured Stale Path Time(sec): %u\n",
11823 peer->bgp->stalepath_time);
2986cac2 11824
df8d723c 11825 if (peer->t_gr_stale != NULL)
13909c4f 11826 vty_out(vty,
df8d723c
DA
11827 " Stale Path Remaining(sec): %ld\n",
11828 thread_timer_remain_second(
11829 peer->t_gr_stale));
11830 /* Display Configured Selection
11831 * Deferral only when when
11832 * Gr mode is enabled.
11833 */
11834 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11835 vty_out(vty,
11836 " Configured Selection Deferral Time(sec): %u\n",
11837 peer->bgp->select_defer_time);
2986cac2 11838
df8d723c
DA
11839 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11840 NULL)
11841 vty_out(vty,
11842 " Selection Deferral Time Remaining(sec): %ld\n",
11843 thread_timer_remain_second(
11844 peer->bgp->gr_info[afi][safi]
11845 .t_select_deferral));
11846 }
11847 if (use_json) {
11848 json_object_object_add(json_afi_safi, "endOfRibStatus",
11849 json_endofrib_status);
11850 json_object_object_add(json_afi_safi, "timers",
11851 json_timer);
11852 json_object_object_add(
11853 json, get_afi_safi_str(afi, safi, true),
11854 json_afi_safi);
2986cac2 11855 }
11856 }
11857}
11858
36235319
QY
11859static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11860 struct peer *p,
11861 bool use_json,
11862 json_object *json)
2986cac2 11863{
11864 if (use_json) {
11865 json_object *json_timer = NULL;
11866
11867 json_timer = json_object_new_object();
11868
13909c4f
DS
11869 json_object_int_add(json_timer, "configuredRestartTimer",
11870 p->bgp->restart_time);
2986cac2 11871
13909c4f
DS
11872 json_object_int_add(json_timer, "receivedRestartTimer",
11873 p->v_gr_restart);
2986cac2 11874
13909c4f
DS
11875 if (p->t_gr_restart != NULL)
11876 json_object_int_add(
11877 json_timer, "restartTimerRemaining",
11878 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11879
11880 json_object_object_add(json, "timers", json_timer);
11881 } else {
11882
a53ca37b
DA
11883 vty_out(vty, " Timers:\n");
11884 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11885 p->bgp->restart_time);
2986cac2 11886
a53ca37b 11887 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11888 p->v_gr_restart);
11889 if (p->t_gr_restart != NULL)
a53ca37b 11890 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11891 thread_timer_remain_second(p->t_gr_restart));
36235319 11892 if (p->t_gr_restart != NULL) {
a53ca37b 11893 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11894 thread_timer_remain_second(p->t_gr_restart));
11895 }
2986cac2 11896 }
11897}
11898
11899static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11900 bool use_json, json_object *json)
2986cac2 11901{
2986cac2 11902 char dn_flag[2] = {0};
2b7165e7
QY
11903 /* '*' + v6 address of neighbor */
11904 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11905
2986cac2 11906 if (!p->conf_if && peer_dynamic_neighbor(p))
11907 dn_flag[0] = '*';
11908
11909 if (p->conf_if) {
11910 if (use_json)
47e12884
DA
11911 json_object_string_addf(json, "neighborAddr", "%pSU",
11912 &p->su);
2986cac2 11913 else
47e12884
DA
11914 vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
11915 &p->su);
2986cac2 11916 } else {
772270f3
QY
11917 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11918 p->host);
2986cac2 11919
11920 if (use_json)
36235319
QY
11921 json_object_string_add(json, "neighborAddr",
11922 neighborAddr);
2986cac2 11923 else
36235319 11924 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11925 }
11926
11927 /* more gr info in new format */
11928 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11929}
11930
d62a17ae 11931static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11932 safi_t safi, bool use_json,
d62a17ae 11933 json_object *json_neigh)
11934{
0291c246
MK
11935 struct bgp_filter *filter;
11936 struct peer_af *paf;
11937 char orf_pfx_name[BUFSIZ];
11938 int orf_pfx_count;
11939 json_object *json_af = NULL;
11940 json_object *json_prefA = NULL;
11941 json_object *json_prefB = NULL;
11942 json_object *json_addr = NULL;
fa36596c 11943 json_object *json_advmap = NULL;
d62a17ae 11944
11945 if (use_json) {
11946 json_addr = json_object_new_object();
11947 json_af = json_object_new_object();
11948 filter = &p->filter[afi][safi];
11949
11950 if (peer_group_active(p))
11951 json_object_string_add(json_addr, "peerGroupMember",
11952 p->group->name);
11953
11954 paf = peer_af_find(p, afi, safi);
11955 if (paf && PAF_SUBGRP(paf)) {
11956 json_object_int_add(json_addr, "updateGroupId",
11957 PAF_UPDGRP(paf)->id);
11958 json_object_int_add(json_addr, "subGroupId",
11959 PAF_SUBGRP(paf)->id);
11960 json_object_int_add(json_addr, "packetQueueLength",
11961 bpacket_queue_virtual_length(paf));
11962 }
11963
11964 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11965 || CHECK_FLAG(p->af_cap[afi][safi],
11966 PEER_CAP_ORF_PREFIX_SM_RCV)
11967 || CHECK_FLAG(p->af_cap[afi][safi],
11968 PEER_CAP_ORF_PREFIX_RM_ADV)
11969 || CHECK_FLAG(p->af_cap[afi][safi],
11970 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11971 json_object_int_add(json_af, "orfType",
11972 ORF_TYPE_PREFIX);
11973 json_prefA = json_object_new_object();
11974 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11975 PEER_CAP_ORF_PREFIX_SM_ADV,
11976 PEER_CAP_ORF_PREFIX_RM_ADV,
11977 PEER_CAP_ORF_PREFIX_SM_RCV,
11978 PEER_CAP_ORF_PREFIX_RM_RCV,
11979 use_json, json_prefA);
11980 json_object_object_add(json_af, "orfPrefixList",
11981 json_prefA);
11982 }
11983
11984 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11985 || CHECK_FLAG(p->af_cap[afi][safi],
11986 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11987 || CHECK_FLAG(p->af_cap[afi][safi],
11988 PEER_CAP_ORF_PREFIX_RM_ADV)
11989 || CHECK_FLAG(p->af_cap[afi][safi],
11990 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11991 json_object_int_add(json_af, "orfOldType",
11992 ORF_TYPE_PREFIX_OLD);
11993 json_prefB = json_object_new_object();
11994 bgp_show_peer_afi_orf_cap(
11995 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11996 PEER_CAP_ORF_PREFIX_RM_ADV,
11997 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11998 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11999 json_prefB);
12000 json_object_object_add(json_af, "orfOldPrefixList",
12001 json_prefB);
12002 }
12003
12004 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12005 || CHECK_FLAG(p->af_cap[afi][safi],
12006 PEER_CAP_ORF_PREFIX_SM_RCV)
12007 || CHECK_FLAG(p->af_cap[afi][safi],
12008 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12009 || CHECK_FLAG(p->af_cap[afi][safi],
12010 PEER_CAP_ORF_PREFIX_RM_ADV)
12011 || CHECK_FLAG(p->af_cap[afi][safi],
12012 PEER_CAP_ORF_PREFIX_RM_RCV)
12013 || CHECK_FLAG(p->af_cap[afi][safi],
12014 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12015 json_object_object_add(json_addr, "afDependentCap",
12016 json_af);
12017 else
12018 json_object_free(json_af);
12019
772270f3
QY
12020 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12021 p->host, afi, safi);
d62a17ae 12022 orf_pfx_count = prefix_bgp_show_prefix_list(
12023 NULL, afi, orf_pfx_name, use_json);
12024
12025 if (CHECK_FLAG(p->af_sflags[afi][safi],
12026 PEER_STATUS_ORF_PREFIX_SEND)
12027 || orf_pfx_count) {
12028 if (CHECK_FLAG(p->af_sflags[afi][safi],
12029 PEER_STATUS_ORF_PREFIX_SEND))
12030 json_object_boolean_true_add(json_neigh,
12031 "orfSent");
12032 if (orf_pfx_count)
12033 json_object_int_add(json_addr, "orfRecvCounter",
12034 orf_pfx_count);
12035 }
12036 if (CHECK_FLAG(p->af_sflags[afi][safi],
12037 PEER_STATUS_ORF_WAIT_REFRESH))
12038 json_object_string_add(
12039 json_addr, "orfFirstUpdate",
12040 "deferredUntilORFOrRouteRefreshRecvd");
12041
12042 if (CHECK_FLAG(p->af_flags[afi][safi],
12043 PEER_FLAG_REFLECTOR_CLIENT))
12044 json_object_boolean_true_add(json_addr,
12045 "routeReflectorClient");
12046 if (CHECK_FLAG(p->af_flags[afi][safi],
12047 PEER_FLAG_RSERVER_CLIENT))
12048 json_object_boolean_true_add(json_addr,
12049 "routeServerClient");
12050 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12051 json_object_boolean_true_add(json_addr,
12052 "inboundSoftConfigPermit");
12053
12054 if (CHECK_FLAG(p->af_flags[afi][safi],
12055 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12056 json_object_boolean_true_add(
12057 json_addr,
12058 "privateAsNumsAllReplacedInUpdatesToNbr");
12059 else if (CHECK_FLAG(p->af_flags[afi][safi],
12060 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12061 json_object_boolean_true_add(
12062 json_addr,
12063 "privateAsNumsReplacedInUpdatesToNbr");
12064 else if (CHECK_FLAG(p->af_flags[afi][safi],
12065 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12066 json_object_boolean_true_add(
12067 json_addr,
12068 "privateAsNumsAllRemovedInUpdatesToNbr");
12069 else if (CHECK_FLAG(p->af_flags[afi][safi],
12070 PEER_FLAG_REMOVE_PRIVATE_AS))
12071 json_object_boolean_true_add(
12072 json_addr,
12073 "privateAsNumsRemovedInUpdatesToNbr");
12074
dcc68b5e
MS
12075 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12076 json_object_boolean_true_add(
12077 json_addr,
12078 bgp_addpath_names(p->addpath_type[afi][safi])
12079 ->type_json_name);
d62a17ae 12080
12081 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12082 json_object_string_add(json_addr,
12083 "overrideASNsInOutboundUpdates",
12084 "ifAspathEqualRemoteAs");
12085
12086 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12087 || CHECK_FLAG(p->af_flags[afi][safi],
12088 PEER_FLAG_FORCE_NEXTHOP_SELF))
12089 json_object_boolean_true_add(json_addr,
12090 "routerAlwaysNextHop");
12091 if (CHECK_FLAG(p->af_flags[afi][safi],
12092 PEER_FLAG_AS_PATH_UNCHANGED))
12093 json_object_boolean_true_add(
12094 json_addr, "unchangedAsPathPropogatedToNbr");
12095 if (CHECK_FLAG(p->af_flags[afi][safi],
12096 PEER_FLAG_NEXTHOP_UNCHANGED))
12097 json_object_boolean_true_add(
12098 json_addr, "unchangedNextHopPropogatedToNbr");
12099 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12100 json_object_boolean_true_add(
12101 json_addr, "unchangedMedPropogatedToNbr");
12102 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12103 || CHECK_FLAG(p->af_flags[afi][safi],
12104 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12105 if (CHECK_FLAG(p->af_flags[afi][safi],
12106 PEER_FLAG_SEND_COMMUNITY)
12107 && CHECK_FLAG(p->af_flags[afi][safi],
12108 PEER_FLAG_SEND_EXT_COMMUNITY))
12109 json_object_string_add(json_addr,
12110 "commAttriSentToNbr",
12111 "extendedAndStandard");
12112 else if (CHECK_FLAG(p->af_flags[afi][safi],
12113 PEER_FLAG_SEND_EXT_COMMUNITY))
12114 json_object_string_add(json_addr,
12115 "commAttriSentToNbr",
12116 "extended");
12117 else
12118 json_object_string_add(json_addr,
12119 "commAttriSentToNbr",
12120 "standard");
12121 }
12122 if (CHECK_FLAG(p->af_flags[afi][safi],
12123 PEER_FLAG_DEFAULT_ORIGINATE)) {
12124 if (p->default_rmap[afi][safi].name)
12125 json_object_string_add(
12126 json_addr, "defaultRouteMap",
12127 p->default_rmap[afi][safi].name);
12128
12129 if (paf && PAF_SUBGRP(paf)
12130 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12131 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12132 json_object_boolean_true_add(json_addr,
12133 "defaultSent");
12134 else
12135 json_object_boolean_true_add(json_addr,
12136 "defaultNotSent");
12137 }
12138
dff8f48d 12139 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12140 if (is_evpn_enabled())
60466a63
QY
12141 json_object_boolean_true_add(
12142 json_addr, "advertiseAllVnis");
dff8f48d
MK
12143 }
12144
d62a17ae 12145 if (filter->plist[FILTER_IN].name
12146 || filter->dlist[FILTER_IN].name
12147 || filter->aslist[FILTER_IN].name
12148 || filter->map[RMAP_IN].name)
12149 json_object_boolean_true_add(json_addr,
12150 "inboundPathPolicyConfig");
12151 if (filter->plist[FILTER_OUT].name
12152 || filter->dlist[FILTER_OUT].name
12153 || filter->aslist[FILTER_OUT].name
12154 || filter->map[RMAP_OUT].name || filter->usmap.name)
12155 json_object_boolean_true_add(
12156 json_addr, "outboundPathPolicyConfig");
12157
12158 /* prefix-list */
12159 if (filter->plist[FILTER_IN].name)
12160 json_object_string_add(json_addr,
12161 "incomingUpdatePrefixFilterList",
12162 filter->plist[FILTER_IN].name);
12163 if (filter->plist[FILTER_OUT].name)
12164 json_object_string_add(json_addr,
12165 "outgoingUpdatePrefixFilterList",
12166 filter->plist[FILTER_OUT].name);
12167
12168 /* distribute-list */
12169 if (filter->dlist[FILTER_IN].name)
12170 json_object_string_add(
12171 json_addr, "incomingUpdateNetworkFilterList",
12172 filter->dlist[FILTER_IN].name);
12173 if (filter->dlist[FILTER_OUT].name)
12174 json_object_string_add(
12175 json_addr, "outgoingUpdateNetworkFilterList",
12176 filter->dlist[FILTER_OUT].name);
12177
12178 /* filter-list. */
12179 if (filter->aslist[FILTER_IN].name)
12180 json_object_string_add(json_addr,
12181 "incomingUpdateAsPathFilterList",
12182 filter->aslist[FILTER_IN].name);
12183 if (filter->aslist[FILTER_OUT].name)
12184 json_object_string_add(json_addr,
12185 "outgoingUpdateAsPathFilterList",
12186 filter->aslist[FILTER_OUT].name);
12187
12188 /* route-map. */
12189 if (filter->map[RMAP_IN].name)
12190 json_object_string_add(
12191 json_addr, "routeMapForIncomingAdvertisements",
12192 filter->map[RMAP_IN].name);
12193 if (filter->map[RMAP_OUT].name)
12194 json_object_string_add(
12195 json_addr, "routeMapForOutgoingAdvertisements",
12196 filter->map[RMAP_OUT].name);
12197
9dac9fc8 12198 /* ebgp-requires-policy (inbound) */
1d3fdccf 12199 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12200 && !bgp_inbound_policy_exists(p, filter))
12201 json_object_string_add(
12202 json_addr, "inboundEbgpRequiresPolicy",
12203 "Inbound updates discarded due to missing policy");
12204
12205 /* ebgp-requires-policy (outbound) */
1d3fdccf 12206 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12207 && (!bgp_outbound_policy_exists(p, filter)))
12208 json_object_string_add(
12209 json_addr, "outboundEbgpRequiresPolicy",
12210 "Outbound updates discarded due to missing policy");
12211
d62a17ae 12212 /* unsuppress-map */
12213 if (filter->usmap.name)
12214 json_object_string_add(json_addr,
12215 "selectiveUnsuppressRouteMap",
12216 filter->usmap.name);
12217
fa36596c
MK
12218 /* advertise-map */
12219 if (filter->advmap.aname) {
12220 json_advmap = json_object_new_object();
12221 json_object_string_add(json_advmap, "condition",
12222 filter->advmap.condition
12223 ? "EXIST"
12224 : "NON_EXIST");
12225 json_object_string_add(json_advmap, "conditionMap",
12226 filter->advmap.cname);
12227 json_object_string_add(json_advmap, "advertiseMap",
12228 filter->advmap.aname);
ecf2b628
QY
12229 json_object_string_add(
12230 json_advmap, "advertiseStatus",
12231 filter->advmap.update_type ==
12232 UPDATE_TYPE_ADVERTISE
12233 ? "Advertise"
12234 : "Withdraw");
fa36596c
MK
12235 json_object_object_add(json_addr, "advertiseMap",
12236 json_advmap);
12237 }
12238
d62a17ae 12239 /* Receive prefix count */
12240 json_object_int_add(json_addr, "acceptedPrefixCounter",
12241 p->pcount[afi][safi]);
50e05855
AD
12242 if (paf && PAF_SUBGRP(paf))
12243 json_object_int_add(json_addr, "sentPrefixCounter",
12244 (PAF_SUBGRP(paf))->scount);
d62a17ae 12245
fde246e8
DA
12246 /* Maximum prefix */
12247 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12248 json_object_int_add(json_addr, "prefixOutAllowedMax",
12249 p->pmax_out[afi][safi]);
12250
d62a17ae 12251 /* Maximum prefix */
12252 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12253 json_object_int_add(json_addr, "prefixAllowedMax",
12254 p->pmax[afi][safi]);
12255 if (CHECK_FLAG(p->af_flags[afi][safi],
12256 PEER_FLAG_MAX_PREFIX_WARNING))
12257 json_object_boolean_true_add(
12258 json_addr, "prefixAllowedMaxWarning");
12259 json_object_int_add(json_addr,
12260 "prefixAllowedWarningThresh",
12261 p->pmax_threshold[afi][safi]);
12262 if (p->pmax_restart[afi][safi])
12263 json_object_int_add(
12264 json_addr,
12265 "prefixAllowedRestartIntervalMsecs",
12266 p->pmax_restart[afi][safi] * 60000);
12267 }
2986cac2 12268 json_object_object_add(json_neigh,
36235319 12269 get_afi_safi_str(afi, safi, true),
d62a17ae 12270 json_addr);
12271
12272 } else {
12273 filter = &p->filter[afi][safi];
12274
12275 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12276 get_afi_safi_str(afi, safi, false));
d62a17ae 12277
12278 if (peer_group_active(p))
12279 vty_out(vty, " %s peer-group member\n",
12280 p->group->name);
12281
12282 paf = peer_af_find(p, afi, safi);
12283 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12284 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12285 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12286 vty_out(vty, " Packet Queue length %d\n",
12287 bpacket_queue_virtual_length(paf));
12288 } else {
12289 vty_out(vty, " Not part of any update group\n");
12290 }
12291 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12292 || CHECK_FLAG(p->af_cap[afi][safi],
12293 PEER_CAP_ORF_PREFIX_SM_RCV)
12294 || CHECK_FLAG(p->af_cap[afi][safi],
12295 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12296 || CHECK_FLAG(p->af_cap[afi][safi],
12297 PEER_CAP_ORF_PREFIX_RM_ADV)
12298 || CHECK_FLAG(p->af_cap[afi][safi],
12299 PEER_CAP_ORF_PREFIX_RM_RCV)
12300 || CHECK_FLAG(p->af_cap[afi][safi],
12301 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12302 vty_out(vty, " AF-dependant capabilities:\n");
12303
12304 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12305 || CHECK_FLAG(p->af_cap[afi][safi],
12306 PEER_CAP_ORF_PREFIX_SM_RCV)
12307 || CHECK_FLAG(p->af_cap[afi][safi],
12308 PEER_CAP_ORF_PREFIX_RM_ADV)
12309 || CHECK_FLAG(p->af_cap[afi][safi],
12310 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12311 vty_out(vty,
12312 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12313 ORF_TYPE_PREFIX);
12314 bgp_show_peer_afi_orf_cap(
12315 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12316 PEER_CAP_ORF_PREFIX_RM_ADV,
12317 PEER_CAP_ORF_PREFIX_SM_RCV,
12318 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12319 }
12320 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12321 || CHECK_FLAG(p->af_cap[afi][safi],
12322 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12323 || CHECK_FLAG(p->af_cap[afi][safi],
12324 PEER_CAP_ORF_PREFIX_RM_ADV)
12325 || CHECK_FLAG(p->af_cap[afi][safi],
12326 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12327 vty_out(vty,
12328 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12329 ORF_TYPE_PREFIX_OLD);
12330 bgp_show_peer_afi_orf_cap(
12331 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12332 PEER_CAP_ORF_PREFIX_RM_ADV,
12333 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12334 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12335 }
12336
772270f3
QY
12337 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12338 p->host, afi, safi);
d62a17ae 12339 orf_pfx_count = prefix_bgp_show_prefix_list(
12340 NULL, afi, orf_pfx_name, use_json);
12341
12342 if (CHECK_FLAG(p->af_sflags[afi][safi],
12343 PEER_STATUS_ORF_PREFIX_SEND)
12344 || orf_pfx_count) {
12345 vty_out(vty, " Outbound Route Filter (ORF):");
12346 if (CHECK_FLAG(p->af_sflags[afi][safi],
12347 PEER_STATUS_ORF_PREFIX_SEND))
12348 vty_out(vty, " sent;");
12349 if (orf_pfx_count)
12350 vty_out(vty, " received (%d entries)",
12351 orf_pfx_count);
12352 vty_out(vty, "\n");
12353 }
12354 if (CHECK_FLAG(p->af_sflags[afi][safi],
12355 PEER_STATUS_ORF_WAIT_REFRESH))
12356 vty_out(vty,
12357 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12358
12359 if (CHECK_FLAG(p->af_flags[afi][safi],
12360 PEER_FLAG_REFLECTOR_CLIENT))
12361 vty_out(vty, " Route-Reflector Client\n");
12362 if (CHECK_FLAG(p->af_flags[afi][safi],
12363 PEER_FLAG_RSERVER_CLIENT))
12364 vty_out(vty, " Route-Server Client\n");
12365 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12366 vty_out(vty,
12367 " Inbound soft reconfiguration allowed\n");
12368
12369 if (CHECK_FLAG(p->af_flags[afi][safi],
12370 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12371 vty_out(vty,
12372 " Private AS numbers (all) replaced in updates to this neighbor\n");
12373 else if (CHECK_FLAG(p->af_flags[afi][safi],
12374 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12375 vty_out(vty,
12376 " Private AS numbers replaced in updates to this neighbor\n");
12377 else if (CHECK_FLAG(p->af_flags[afi][safi],
12378 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12379 vty_out(vty,
12380 " Private AS numbers (all) removed in updates to this neighbor\n");
12381 else if (CHECK_FLAG(p->af_flags[afi][safi],
12382 PEER_FLAG_REMOVE_PRIVATE_AS))
12383 vty_out(vty,
12384 " Private AS numbers removed in updates to this neighbor\n");
12385
dcc68b5e
MS
12386 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12387 vty_out(vty, " %s\n",
12388 bgp_addpath_names(p->addpath_type[afi][safi])
12389 ->human_description);
d62a17ae 12390
12391 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12392 vty_out(vty,
12393 " Override ASNs in outbound updates if aspath equals remote-as\n");
12394
12395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12396 || CHECK_FLAG(p->af_flags[afi][safi],
12397 PEER_FLAG_FORCE_NEXTHOP_SELF))
12398 vty_out(vty, " NEXT_HOP is always this router\n");
12399 if (CHECK_FLAG(p->af_flags[afi][safi],
12400 PEER_FLAG_AS_PATH_UNCHANGED))
12401 vty_out(vty,
12402 " AS_PATH is propagated unchanged to this neighbor\n");
12403 if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_NEXTHOP_UNCHANGED))
12405 vty_out(vty,
12406 " NEXT_HOP is propagated unchanged to this neighbor\n");
12407 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12408 vty_out(vty,
12409 " MED is propagated unchanged to this neighbor\n");
12410 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12411 || CHECK_FLAG(p->af_flags[afi][safi],
12412 PEER_FLAG_SEND_EXT_COMMUNITY)
12413 || CHECK_FLAG(p->af_flags[afi][safi],
12414 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12415 vty_out(vty,
12416 " Community attribute sent to this neighbor");
12417 if (CHECK_FLAG(p->af_flags[afi][safi],
12418 PEER_FLAG_SEND_COMMUNITY)
12419 && CHECK_FLAG(p->af_flags[afi][safi],
12420 PEER_FLAG_SEND_EXT_COMMUNITY)
12421 && CHECK_FLAG(p->af_flags[afi][safi],
12422 PEER_FLAG_SEND_LARGE_COMMUNITY))
12423 vty_out(vty, "(all)\n");
12424 else if (CHECK_FLAG(p->af_flags[afi][safi],
12425 PEER_FLAG_SEND_LARGE_COMMUNITY))
12426 vty_out(vty, "(large)\n");
12427 else if (CHECK_FLAG(p->af_flags[afi][safi],
12428 PEER_FLAG_SEND_EXT_COMMUNITY))
12429 vty_out(vty, "(extended)\n");
12430 else
12431 vty_out(vty, "(standard)\n");
12432 }
12433 if (CHECK_FLAG(p->af_flags[afi][safi],
12434 PEER_FLAG_DEFAULT_ORIGINATE)) {
12435 vty_out(vty, " Default information originate,");
12436
12437 if (p->default_rmap[afi][safi].name)
12438 vty_out(vty, " default route-map %s%s,",
12439 p->default_rmap[afi][safi].map ? "*"
12440 : "",
12441 p->default_rmap[afi][safi].name);
12442 if (paf && PAF_SUBGRP(paf)
12443 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12444 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12445 vty_out(vty, " default sent\n");
12446 else
12447 vty_out(vty, " default not sent\n");
12448 }
12449
dff8f48d
MK
12450 /* advertise-vni-all */
12451 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12452 if (is_evpn_enabled())
dff8f48d
MK
12453 vty_out(vty, " advertise-all-vni\n");
12454 }
12455
d62a17ae 12456 if (filter->plist[FILTER_IN].name
12457 || filter->dlist[FILTER_IN].name
12458 || filter->aslist[FILTER_IN].name
12459 || filter->map[RMAP_IN].name)
12460 vty_out(vty, " Inbound path policy configured\n");
12461 if (filter->plist[FILTER_OUT].name
12462 || filter->dlist[FILTER_OUT].name
12463 || filter->aslist[FILTER_OUT].name
12464 || filter->map[RMAP_OUT].name || filter->usmap.name)
12465 vty_out(vty, " Outbound path policy configured\n");
12466
12467 /* prefix-list */
12468 if (filter->plist[FILTER_IN].name)
12469 vty_out(vty,
12470 " Incoming update prefix filter list is %s%s\n",
12471 filter->plist[FILTER_IN].plist ? "*" : "",
12472 filter->plist[FILTER_IN].name);
12473 if (filter->plist[FILTER_OUT].name)
12474 vty_out(vty,
12475 " Outgoing update prefix filter list is %s%s\n",
12476 filter->plist[FILTER_OUT].plist ? "*" : "",
12477 filter->plist[FILTER_OUT].name);
12478
12479 /* distribute-list */
12480 if (filter->dlist[FILTER_IN].name)
12481 vty_out(vty,
12482 " Incoming update network filter list is %s%s\n",
12483 filter->dlist[FILTER_IN].alist ? "*" : "",
12484 filter->dlist[FILTER_IN].name);
12485 if (filter->dlist[FILTER_OUT].name)
12486 vty_out(vty,
12487 " Outgoing update network filter list is %s%s\n",
12488 filter->dlist[FILTER_OUT].alist ? "*" : "",
12489 filter->dlist[FILTER_OUT].name);
12490
12491 /* filter-list. */
12492 if (filter->aslist[FILTER_IN].name)
12493 vty_out(vty,
12494 " Incoming update AS path filter list is %s%s\n",
12495 filter->aslist[FILTER_IN].aslist ? "*" : "",
12496 filter->aslist[FILTER_IN].name);
12497 if (filter->aslist[FILTER_OUT].name)
12498 vty_out(vty,
12499 " Outgoing update AS path filter list is %s%s\n",
12500 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12501 filter->aslist[FILTER_OUT].name);
12502
12503 /* route-map. */
12504 if (filter->map[RMAP_IN].name)
12505 vty_out(vty,
12506 " Route map for incoming advertisements is %s%s\n",
12507 filter->map[RMAP_IN].map ? "*" : "",
12508 filter->map[RMAP_IN].name);
12509 if (filter->map[RMAP_OUT].name)
12510 vty_out(vty,
12511 " Route map for outgoing advertisements is %s%s\n",
12512 filter->map[RMAP_OUT].map ? "*" : "",
12513 filter->map[RMAP_OUT].name);
12514
9dac9fc8 12515 /* ebgp-requires-policy (inbound) */
1d3fdccf 12516 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12517 && !bgp_inbound_policy_exists(p, filter))
12518 vty_out(vty,
12519 " Inbound updates discarded due to missing policy\n");
12520
12521 /* ebgp-requires-policy (outbound) */
1d3fdccf 12522 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12523 && !bgp_outbound_policy_exists(p, filter))
12524 vty_out(vty,
12525 " Outbound updates discarded due to missing policy\n");
12526
d62a17ae 12527 /* unsuppress-map */
12528 if (filter->usmap.name)
12529 vty_out(vty,
12530 " Route map for selective unsuppress is %s%s\n",
12531 filter->usmap.map ? "*" : "",
12532 filter->usmap.name);
12533
7f7940e6
MK
12534 /* advertise-map */
12535 if (filter->advmap.aname && filter->advmap.cname)
12536 vty_out(vty,
12537 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12538 filter->advmap.condition ? "EXIST"
12539 : "NON_EXIST",
12540 filter->advmap.cmap ? "*" : "",
12541 filter->advmap.cname,
12542 filter->advmap.amap ? "*" : "",
12543 filter->advmap.aname,
ecf2b628
QY
12544 filter->advmap.update_type ==
12545 UPDATE_TYPE_ADVERTISE
c385f82a
MK
12546 ? "Advertise"
12547 : "Withdraw");
7f7940e6 12548
d62a17ae 12549 /* Receive prefix count */
6cde4b45 12550 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12551 p->pcount[afi][safi]);
d62a17ae 12552
fde246e8
DA
12553 /* maximum-prefix-out */
12554 if (CHECK_FLAG(p->af_flags[afi][safi],
12555 PEER_FLAG_MAX_PREFIX_OUT))
12556 vty_out(vty,
6cde4b45 12557 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12558 p->pmax_out[afi][safi]);
12559
d62a17ae 12560 /* Maximum prefix */
12561 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12562 vty_out(vty,
6cde4b45 12563 " Maximum prefixes allowed %u%s\n",
d62a17ae 12564 p->pmax[afi][safi],
12565 CHECK_FLAG(p->af_flags[afi][safi],
12566 PEER_FLAG_MAX_PREFIX_WARNING)
12567 ? " (warning-only)"
12568 : "");
12569 vty_out(vty, " Threshold for warning message %d%%",
12570 p->pmax_threshold[afi][safi]);
12571 if (p->pmax_restart[afi][safi])
12572 vty_out(vty, ", restart interval %d min",
12573 p->pmax_restart[afi][safi]);
12574 vty_out(vty, "\n");
12575 }
12576
12577 vty_out(vty, "\n");
12578 }
12579}
12580
9f049418 12581static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12582 json_object *json)
718e3744 12583{
d62a17ae 12584 struct bgp *bgp;
47e12884 12585 char buf1[PREFIX2STR_BUFFER];
d62a17ae 12586 char timebuf[BGP_UPTIME_LEN];
12587 char dn_flag[2];
d62a17ae 12588 afi_t afi;
12589 safi_t safi;
d7c0a89a
QY
12590 uint16_t i;
12591 uint8_t *msg;
d62a17ae 12592 json_object *json_neigh = NULL;
12593 time_t epoch_tbuf;
4ab46701 12594 uint32_t sync_tcp_mss;
718e3744 12595
d62a17ae 12596 bgp = p->bgp;
12597
12598 if (use_json)
12599 json_neigh = json_object_new_object();
12600
12601 memset(dn_flag, '\0', sizeof(dn_flag));
12602 if (!p->conf_if && peer_dynamic_neighbor(p))
12603 dn_flag[0] = '*';
12604
12605 if (!use_json) {
12606 if (p->conf_if) /* Configured interface name. */
47e12884
DA
12607 vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
12608 &p->su);
d62a17ae 12609 else /* Configured IP address. */
12610 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12611 p->host);
12612 }
12613
12614 if (use_json) {
12615 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12616 json_object_string_add(json_neigh, "bgpNeighborAddr",
12617 "none");
12618 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
47e12884
DA
12619 json_object_string_addf(json_neigh, "bgpNeighborAddr",
12620 "%pSU", &p->su);
d62a17ae 12621
12622 json_object_int_add(json_neigh, "remoteAs", p->as);
12623
12624 if (p->change_local_as)
12625 json_object_int_add(json_neigh, "localAs",
12626 p->change_local_as);
12627 else
12628 json_object_int_add(json_neigh, "localAs", p->local_as);
12629
12630 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12631 json_object_boolean_true_add(json_neigh,
12632 "localAsNoPrepend");
12633
12634 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12635 json_object_boolean_true_add(json_neigh,
12636 "localAsReplaceAs");
12637 } else {
12638 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12639 || (p->as_type == AS_INTERNAL))
12640 vty_out(vty, "remote AS %u, ", p->as);
12641 else
12642 vty_out(vty, "remote AS Unspecified, ");
12643 vty_out(vty, "local AS %u%s%s, ",
12644 p->change_local_as ? p->change_local_as : p->local_as,
12645 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12646 ? " no-prepend"
12647 : "",
12648 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12649 ? " replace-as"
12650 : "");
12651 }
faa16034
DS
12652 /* peer type internal or confed-internal */
12653 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12654 if (use_json) {
12655 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12656 json_object_boolean_true_add(
12657 json_neigh, "nbrConfedInternalLink");
12658 else
12659 json_object_boolean_true_add(json_neigh,
12660 "nbrInternalLink");
12661 } else {
12662 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12663 vty_out(vty, "confed-internal link\n");
12664 else
12665 vty_out(vty, "internal link\n");
12666 }
faa16034
DS
12667 /* peer type external or confed-external */
12668 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12669 if (use_json) {
12670 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12671 json_object_boolean_true_add(
12672 json_neigh, "nbrConfedExternalLink");
12673 else
12674 json_object_boolean_true_add(json_neigh,
12675 "nbrExternalLink");
12676 } else {
12677 if (bgp_confederation_peers_check(bgp, p->as))
12678 vty_out(vty, "confed-external link\n");
12679 else
12680 vty_out(vty, "external link\n");
12681 }
faa16034
DS
12682 } else {
12683 if (use_json)
12684 json_object_boolean_true_add(json_neigh,
12685 "nbrUnspecifiedLink");
12686 else
12687 vty_out(vty, "unspecified link\n");
d62a17ae 12688 }
12689
d864dd9e
EB
12690 /* Roles */
12691 if (use_json) {
12692 json_object_string_add(json_neigh, "localRole",
8f2d6021
EB
12693 bgp_get_name_by_role(p->local_role));
12694 json_object_string_add(json_neigh, "remoteRole",
12695 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12696 } else {
12697 vty_out(vty, " Local Role: %s\n",
8f2d6021
EB
12698 bgp_get_name_by_role(p->local_role));
12699 vty_out(vty, " Remote Role: %s\n",
12700 bgp_get_name_by_role(p->remote_role));
d864dd9e
EB
12701 }
12702
12703
d62a17ae 12704 /* Description. */
12705 if (p->desc) {
12706 if (use_json)
12707 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12708 else
12709 vty_out(vty, " Description: %s\n", p->desc);
12710 }
12711
12712 if (p->hostname) {
12713 if (use_json) {
12714 if (p->hostname)
12715 json_object_string_add(json_neigh, "hostname",
12716 p->hostname);
12717
12718 if (p->domainname)
12719 json_object_string_add(json_neigh, "domainname",
12720 p->domainname);
12721 } else {
12722 if (p->domainname && (p->domainname[0] != '\0'))
12723 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12724 p->domainname);
12725 else
12726 vty_out(vty, "Hostname: %s\n", p->hostname);
12727 }
12728 }
12729
12730 /* Peer-group */
12731 if (p->group) {
12732 if (use_json) {
12733 json_object_string_add(json_neigh, "peerGroup",
12734 p->group->name);
12735
12736 if (dn_flag[0]) {
12737 struct prefix prefix, *range = NULL;
12738
0154d8ce
DS
12739 if (sockunion2hostprefix(&(p->su), &prefix))
12740 range = peer_group_lookup_dynamic_neighbor_range(
12741 p->group, &prefix);
d62a17ae 12742
12743 if (range) {
67d7e256 12744 json_object_string_addf(
d62a17ae 12745 json_neigh,
67d7e256
DA
12746 "peerSubnetRangeGroup", "%pFX",
12747 range);
d62a17ae 12748 }
12749 }
12750 } else {
12751 vty_out(vty,
12752 " Member of peer-group %s for session parameters\n",
12753 p->group->name);
12754
12755 if (dn_flag[0]) {
12756 struct prefix prefix, *range = NULL;
12757
0154d8ce
DS
12758 if (sockunion2hostprefix(&(p->su), &prefix))
12759 range = peer_group_lookup_dynamic_neighbor_range(
12760 p->group, &prefix);
d62a17ae 12761
12762 if (range) {
d62a17ae 12763 vty_out(vty,
1b78780b
DL
12764 " Belongs to the subnet range group: %pFX\n",
12765 range);
d62a17ae 12766 }
12767 }
12768 }
12769 }
12770
12771 if (use_json) {
12772 /* Administrative shutdown. */
cb9196e7
DS
12773 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12774 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12775 json_object_boolean_true_add(json_neigh,
12776 "adminShutDown");
12777
12778 /* BGP Version. */
12779 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12780 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12781 &p->remote_id);
12782 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12783 &bgp->router_id);
d62a17ae 12784
12785 /* Confederation */
12786 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12787 && bgp_confederation_peers_check(bgp, p->as))
12788 json_object_boolean_true_add(json_neigh,
12789 "nbrCommonAdmin");
12790
12791 /* Status. */
12792 json_object_string_add(
12793 json_neigh, "bgpState",
12794 lookup_msg(bgp_status_msg, p->status, NULL));
12795
feb17238 12796 if (peer_established(p)) {
d62a17ae 12797 time_t uptime;
d62a17ae 12798
083ec940 12799 uptime = monotime(NULL);
d62a17ae 12800 uptime -= p->uptime;
d62a17ae 12801 epoch_tbuf = time(NULL) - uptime;
12802
d3c7efed
DS
12803 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12804 uptime * 1000);
d62a17ae 12805 json_object_string_add(json_neigh, "bgpTimerUpString",
12806 peer_uptime(p->uptime, timebuf,
12807 BGP_UPTIME_LEN, 0,
12808 NULL));
12809 json_object_int_add(json_neigh,
12810 "bgpTimerUpEstablishedEpoch",
12811 epoch_tbuf);
12812 }
12813
12814 else if (p->status == Active) {
12815 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12816 json_object_string_add(json_neigh, "bgpStateIs",
12817 "passive");
12818 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12819 json_object_string_add(json_neigh, "bgpStateIs",
12820 "passiveNSF");
12821 }
12822
12823 /* read timer */
12824 time_t uptime;
a2700b50 12825 struct tm tm;
d62a17ae 12826
083ec940 12827 uptime = monotime(NULL);
d62a17ae 12828 uptime -= p->readtime;
a2700b50
MS
12829 gmtime_r(&uptime, &tm);
12830
d62a17ae 12831 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12832 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12833 + (tm.tm_hour * 3600000));
d62a17ae 12834
083ec940 12835 uptime = monotime(NULL);
d62a17ae 12836 uptime -= p->last_write;
a2700b50
MS
12837 gmtime_r(&uptime, &tm);
12838
d62a17ae 12839 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12840 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12841 + (tm.tm_hour * 3600000));
d62a17ae 12842
083ec940 12843 uptime = monotime(NULL);
d62a17ae 12844 uptime -= p->update_time;
a2700b50
MS
12845 gmtime_r(&uptime, &tm);
12846
d62a17ae 12847 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12848 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12849 + (tm.tm_hour * 3600000));
d62a17ae 12850
12851 /* Configured timer values. */
9b1b9623
TA
12852 json_object_int_add(json_neigh,
12853 "bgpTimerConfiguredHoldTimeMsecs",
e93d5c29
TA
12854 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12855 ? p->holdtime * 1000
12856 : bgp->default_holdtime * 1000);
12857 json_object_int_add(json_neigh,
12858 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12859 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12860 ? p->keepalive * 1000
12861 : bgp->default_keepalive * 1000);
d62a17ae 12862 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12863 p->v_holdtime * 1000);
12864 json_object_int_add(json_neigh,
12865 "bgpTimerKeepAliveIntervalMsecs",
12866 p->v_keepalive * 1000);
d43114f3
DS
12867 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12868 json_object_int_add(json_neigh,
12869 "bgpTimerDelayOpenTimeMsecs",
12870 p->v_delayopen * 1000);
12871 }
12872
4ab46701
AR
12873 /* Configured and Synced tcp-mss value for peer */
12874 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12875 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12876 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12877 p->tcp_mss);
12878 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12879 sync_tcp_mss);
12880 }
12881
d08c0c80
DA
12882 /* Extended Optional Parameters Length for BGP OPEN Message */
12883 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12884 json_object_boolean_true_add(
12885 json_neigh, "extendedOptionalParametersLength");
12886 else
12887 json_object_boolean_false_add(
12888 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
12889
12890 /* Conditional advertisements */
12891 json_object_int_add(
12892 json_neigh,
12893 "bgpTimerConfiguredConditionalAdvertisementsSec",
12894 bgp->condition_check_period);
12895 if (thread_is_scheduled(bgp->t_condition_check))
12896 json_object_int_add(
12897 json_neigh,
12898 "bgpTimerUntilConditionalAdvertisementsSec",
12899 thread_timer_remain_second(
12900 bgp->t_condition_check));
d62a17ae 12901 } else {
12902 /* Administrative shutdown. */
cb9196e7
DS
12903 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12904 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12905 vty_out(vty, " Administratively shut down\n");
12906
12907 /* BGP Version. */
12908 vty_out(vty, " BGP version 4");
0e38aeb4 12909 vty_out(vty, ", remote router ID %s",
d62a17ae 12910 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12911 vty_out(vty, ", local router ID %s\n",
12912 inet_ntop(AF_INET, &bgp->router_id, buf1,
12913 sizeof(buf1)));
d62a17ae 12914
12915 /* Confederation */
12916 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12917 && bgp_confederation_peers_check(bgp, p->as))
12918 vty_out(vty,
12919 " Neighbor under common administration\n");
12920
12921 /* Status. */
12922 vty_out(vty, " BGP state = %s",
12923 lookup_msg(bgp_status_msg, p->status, NULL));
12924
feb17238 12925 if (peer_established(p))
d62a17ae 12926 vty_out(vty, ", up for %8s",
12927 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12928 0, NULL));
12929
12930 else if (p->status == Active) {
12931 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12932 vty_out(vty, " (passive)");
12933 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12934 vty_out(vty, " (NSF passive)");
12935 }
12936 vty_out(vty, "\n");
12937
12938 /* read timer */
12939 vty_out(vty, " Last read %s",
12940 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12941 NULL));
12942 vty_out(vty, ", Last write %s\n",
12943 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12944 NULL));
12945
12946 /* Configured timer values. */
12947 vty_out(vty,
e93d5c29 12948 " Hold time is %d seconds, keepalive interval is %d seconds\n",
d62a17ae 12949 p->v_holdtime, p->v_keepalive);
e93d5c29
TA
12950 vty_out(vty, " Configured hold time is %d seconds",
12951 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12952 ? p->holdtime
12953 : bgp->default_holdtime);
9b1b9623 12954 vty_out(vty, ", keepalive interval is %d seconds\n",
e93d5c29
TA
12955 CHECK_FLAG(p->flags, PEER_FLAG_TIMER)
12956 ? p->keepalive
12957 : bgp->default_keepalive);
d43114f3
DS
12958 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12959 vty_out(vty,
12960 " Configured DelayOpenTime is %d seconds\n",
12961 p->delayopen);
4ab46701
AR
12962
12963 /* Configured and synced tcp-mss value for peer */
12964 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12965 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12966 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12967 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12968 }
d08c0c80
DA
12969
12970 /* Extended Optional Parameters Length for BGP OPEN Message */
12971 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12972 vty_out(vty,
12973 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
12974
12975 /* Conditional advertisements */
12976 vty_out(vty,
12977 " Configured conditional advertisements interval is %d seconds\n",
12978 bgp->condition_check_period);
12979 if (thread_is_scheduled(bgp->t_condition_check))
12980 vty_out(vty,
12981 " Time until conditional advertisements begin is %lu seconds\n",
12982 thread_timer_remain_second(
12983 bgp->t_condition_check));
d62a17ae 12984 }
12985 /* Capability. */
10711563
DA
12986 if (peer_established(p) &&
12987 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12988 if (use_json) {
12989 json_object *json_cap = NULL;
d62a17ae 12990
10711563 12991 json_cap = json_object_new_object();
d62a17ae 12992
10711563
DA
12993 /* AS4 */
12994 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12995 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12996 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12997 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12998 json_object_string_add(
10711563 12999 json_cap, "4byteAs",
ef56aee4 13000 "advertisedAndReceived");
10711563
DA
13001 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13002 json_object_string_add(json_cap,
13003 "4byteAs",
13004 "advertised");
13005 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13006 json_object_string_add(json_cap,
13007 "4byteAs",
13008 "received");
13009 }
ef56aee4 13010
10711563
DA
13011 /* Extended Message Support */
13012 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
13013 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
13014 json_object_string_add(json_cap,
13015 "extendedMessage",
13016 "advertisedAndReceived");
13017 else if (CHECK_FLAG(p->cap,
13018 PEER_CAP_EXTENDED_MESSAGE_ADV))
13019 json_object_string_add(json_cap,
13020 "extendedMessage",
13021 "advertised");
13022 else if (CHECK_FLAG(p->cap,
13023 PEER_CAP_EXTENDED_MESSAGE_RCV))
13024 json_object_string_add(json_cap,
13025 "extendedMessage",
13026 "received");
ef56aee4 13027
10711563
DA
13028 /* AddPath */
13029 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13030 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13031 json_object *json_add = NULL;
13032 const char *print_store;
d62a17ae 13033
10711563 13034 json_add = json_object_new_object();
d62a17ae 13035
10711563
DA
13036 FOREACH_AFI_SAFI (afi, safi) {
13037 json_object *json_sub = NULL;
13038 json_sub = json_object_new_object();
13039 print_store = get_afi_safi_str(
13040 afi, safi, true);
d62a17ae 13041
10711563
DA
13042 if (CHECK_FLAG(
13043 p->af_cap[afi][safi],
13044 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13045 CHECK_FLAG(
13046 p->af_cap[afi][safi],
13047 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
13048 if (CHECK_FLAG(
13049 p->af_cap[afi]
13050 [safi],
10711563
DA
13051 PEER_CAP_ADDPATH_AF_TX_ADV) &&
13052 CHECK_FLAG(
05c7a1cc
QY
13053 p->af_cap[afi]
13054 [safi],
10711563
DA
13055 PEER_CAP_ADDPATH_AF_TX_RCV))
13056 json_object_boolean_true_add(
13057 json_sub,
13058 "txAdvertisedAndReceived");
13059 else if (
13060 CHECK_FLAG(
13061 p->af_cap[afi]
13062 [safi],
13063 PEER_CAP_ADDPATH_AF_TX_ADV))
13064 json_object_boolean_true_add(
13065 json_sub,
13066 "txAdvertised");
13067 else if (
13068 CHECK_FLAG(
13069 p->af_cap[afi]
13070 [safi],
13071 PEER_CAP_ADDPATH_AF_TX_RCV))
13072 json_object_boolean_true_add(
13073 json_sub,
13074 "txReceived");
13075 }
d62a17ae 13076
10711563
DA
13077 if (CHECK_FLAG(
13078 p->af_cap[afi][safi],
13079 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13080 CHECK_FLAG(
13081 p->af_cap[afi][safi],
13082 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
13083 if (CHECK_FLAG(
13084 p->af_cap[afi]
13085 [safi],
10711563
DA
13086 PEER_CAP_ADDPATH_AF_RX_ADV) &&
13087 CHECK_FLAG(
13088 p->af_cap[afi]
13089 [safi],
13090 PEER_CAP_ADDPATH_AF_RX_RCV))
13091 json_object_boolean_true_add(
13092 json_sub,
13093 "rxAdvertisedAndReceived");
13094 else if (
13095 CHECK_FLAG(
13096 p->af_cap[afi]
13097 [safi],
13098 PEER_CAP_ADDPATH_AF_RX_ADV))
13099 json_object_boolean_true_add(
13100 json_sub,
13101 "rxAdvertised");
13102 else if (
13103 CHECK_FLAG(
13104 p->af_cap[afi]
13105 [safi],
13106 PEER_CAP_ADDPATH_AF_RX_RCV))
13107 json_object_boolean_true_add(
13108 json_sub,
13109 "rxReceived");
05c7a1cc
QY
13110 }
13111
10711563
DA
13112 if (CHECK_FLAG(
13113 p->af_cap[afi][safi],
13114 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13115 CHECK_FLAG(
13116 p->af_cap[afi][safi],
13117 PEER_CAP_ADDPATH_AF_TX_RCV) ||
13118 CHECK_FLAG(
13119 p->af_cap[afi][safi],
13120 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13121 CHECK_FLAG(
13122 p->af_cap[afi][safi],
13123 PEER_CAP_ADDPATH_AF_RX_RCV))
13124 json_object_object_add(
13125 json_add, print_store,
13126 json_sub);
13127 else
13128 json_object_free(json_sub);
d62a17ae 13129 }
13130
10711563
DA
13131 json_object_object_add(json_cap, "addPath",
13132 json_add);
13133 }
d62a17ae 13134
10711563
DA
13135 /* Dynamic */
13136 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13137 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13138 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
13139 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13140 json_object_string_add(
13141 json_cap, "dynamic",
13142 "advertisedAndReceived");
13143 else if (CHECK_FLAG(p->cap,
13144 PEER_CAP_DYNAMIC_ADV))
13145 json_object_string_add(json_cap,
13146 "dynamic",
13147 "advertised");
13148 else if (CHECK_FLAG(p->cap,
13149 PEER_CAP_DYNAMIC_RCV))
13150 json_object_string_add(json_cap,
13151 "dynamic",
13152 "received");
13153 }
d62a17ae 13154
d864dd9e
EB
13155 /* Role */
13156 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13157 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13158 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV) &&
13159 CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13160 json_object_string_add(
13161 json_cap, "role",
13162 "advertisedAndReceived");
13163 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13164 json_object_string_add(json_cap, "role",
13165 "advertised");
13166 else if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13167 json_object_string_add(json_cap, "role",
13168 "received");
13169 }
13170
10711563
DA
13171 /* Extended nexthop */
13172 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13173 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13174 json_object *json_nxt = NULL;
13175 const char *print_store;
d62a17ae 13176
d62a17ae 13177
10711563
DA
13178 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
13179 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13180 json_object_string_add(
13181 json_cap, "extendedNexthop",
13182 "advertisedAndReceived");
13183 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13184 json_object_string_add(
13185 json_cap, "extendedNexthop",
13186 "advertised");
13187 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13188 json_object_string_add(
13189 json_cap, "extendedNexthop",
13190 "received");
d62a17ae 13191
10711563
DA
13192 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
13193 json_nxt = json_object_new_object();
d62a17ae 13194
10711563
DA
13195 for (safi = SAFI_UNICAST;
13196 safi < SAFI_MAX; safi++) {
13197 if (CHECK_FLAG(
13198 p->af_cap[AFI_IP]
13199 [safi],
13200 PEER_CAP_ENHE_AF_RCV)) {
13201 print_store =
13202 get_afi_safi_str(
d62a17ae 13203 AFI_IP,
10711563
DA
13204 safi,
13205 true);
13206 json_object_string_add(
13207 json_nxt,
13208 print_store,
13209 "recieved"); /* misspelled for compatibility */
d62a17ae 13210 }
d62a17ae 13211 }
10711563
DA
13212 json_object_object_add(
13213 json_cap,
13214 "extendedNexthopFamililesByPeer",
13215 json_nxt);
d62a17ae 13216 }
10711563 13217 }
d62a17ae 13218
10711563
DA
13219 /* Long-lived Graceful Restart */
13220 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13221 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13222 json_object *json_llgr = NULL;
13223 const char *afi_safi_str;
8606be87 13224
10711563
DA
13225 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
13226 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13227 json_object_string_add(
13228 json_cap,
13229 "longLivedGracefulRestart",
13230 "advertisedAndReceived");
13231 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13232 json_object_string_add(
13233 json_cap,
13234 "longLivedGracefulRestart",
13235 "advertised");
13236 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13237 json_object_string_add(
13238 json_cap,
13239 "longLivedGracefulRestart",
13240 "received");
8606be87 13241
10711563
DA
13242 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
13243 json_llgr = json_object_new_object();
8606be87 13244
10711563
DA
13245 FOREACH_AFI_SAFI (afi, safi) {
13246 if (CHECK_FLAG(
13247 p->af_cap[afi]
13248 [safi],
13249 PEER_CAP_ENHE_AF_RCV)) {
13250 afi_safi_str =
13251 get_afi_safi_str(
8606be87
DA
13252 afi,
13253 safi,
13254 true);
10711563
DA
13255 json_object_string_add(
13256 json_llgr,
13257 afi_safi_str,
13258 "received");
8606be87 13259 }
8606be87 13260 }
10711563
DA
13261 json_object_object_add(
13262 json_cap,
13263 "longLivedGracefulRestartByPeer",
13264 json_llgr);
8606be87 13265 }
10711563 13266 }
8606be87 13267
10711563
DA
13268 /* Route Refresh */
13269 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13270 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13271 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13272 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
13273 (CHECK_FLAG(p->cap,
13274 PEER_CAP_REFRESH_NEW_RCV) ||
13275 CHECK_FLAG(p->cap,
13276 PEER_CAP_REFRESH_OLD_RCV))) {
13277 if (CHECK_FLAG(
13278 p->cap,
13279 PEER_CAP_REFRESH_OLD_RCV) &&
13280 CHECK_FLAG(
13281 p->cap,
13282 PEER_CAP_REFRESH_NEW_RCV))
13283 json_object_string_add(
13284 json_cap,
13285 "routeRefresh",
13286 "advertisedAndReceivedOldNew");
13287 else {
d62a17ae 13288 if (CHECK_FLAG(
13289 p->cap,
10711563 13290 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13291 json_object_string_add(
13292 json_cap,
13293 "routeRefresh",
10711563
DA
13294 "advertisedAndReceivedOld");
13295 else
13296 json_object_string_add(
13297 json_cap,
13298 "routeRefresh",
13299 "advertisedAndReceivedNew");
d62a17ae 13300 }
10711563
DA
13301 } else if (CHECK_FLAG(p->cap,
13302 PEER_CAP_REFRESH_ADV))
13303 json_object_string_add(json_cap,
13304 "routeRefresh",
13305 "advertised");
13306 else if (CHECK_FLAG(p->cap,
13307 PEER_CAP_REFRESH_NEW_RCV) ||
13308 CHECK_FLAG(p->cap,
13309 PEER_CAP_REFRESH_OLD_RCV))
13310 json_object_string_add(json_cap,
13311 "routeRefresh",
13312 "received");
13313 }
d62a17ae 13314
10711563
DA
13315 /* Enhanced Route Refresh */
13316 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13317 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13318 if (CHECK_FLAG(p->cap,
13319 PEER_CAP_ENHANCED_RR_ADV) &&
13320 CHECK_FLAG(p->cap,
13321 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13322 json_object_string_add(
10711563
DA
13323 json_cap,
13324 "enhancedRouteRefresh",
13325 "advertisedAndReceived");
13326 else if (CHECK_FLAG(p->cap,
13327 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13328 json_object_string_add(
10711563
DA
13329 json_cap,
13330 "enhancedRouteRefresh",
13331 "advertised");
13332 else if (CHECK_FLAG(p->cap,
9af52ccf 13333 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13334 json_object_string_add(
13335 json_cap,
13336 "enhancedRouteRefresh",
13337 "received");
13338 }
d77114b7 13339
10711563
DA
13340 /* Multiprotocol Extensions */
13341 json_object *json_multi = NULL;
d77114b7 13342
10711563 13343 json_multi = json_object_new_object();
d77114b7 13344
10711563
DA
13345 FOREACH_AFI_SAFI (afi, safi) {
13346 if (p->afc_adv[afi][safi] ||
13347 p->afc_recv[afi][safi]) {
13348 json_object *json_exten = NULL;
13349 json_exten = json_object_new_object();
13350
13351 if (p->afc_adv[afi][safi] &&
13352 p->afc_recv[afi][safi])
13353 json_object_boolean_true_add(
13354 json_exten,
9af52ccf 13355 "advertisedAndReceived");
10711563
DA
13356 else if (p->afc_adv[afi][safi])
13357 json_object_boolean_true_add(
13358 json_exten,
9af52ccf 13359 "advertised");
10711563
DA
13360 else if (p->afc_recv[afi][safi])
13361 json_object_boolean_true_add(
13362 json_exten, "received");
9af52ccf 13363
10711563
DA
13364 json_object_object_add(
13365 json_multi,
13366 get_afi_safi_str(afi, safi,
13367 true),
13368 json_exten);
13369 }
13370 }
13371 json_object_object_add(json_cap,
13372 "multiprotocolExtensions",
13373 json_multi);
d62a17ae 13374
10711563
DA
13375 /* Hostname capabilities */
13376 json_object *json_hname = NULL;
d62a17ae 13377
10711563 13378 json_hname = json_object_new_object();
d62a17ae 13379
10711563
DA
13380 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13381 json_object_string_add(
13382 json_hname, "advHostName",
13383 bgp->peer_self->hostname
13384 ? bgp->peer_self->hostname
13385 : "n/a");
13386 json_object_string_add(
13387 json_hname, "advDomainName",
13388 bgp->peer_self->domainname
13389 ? bgp->peer_self->domainname
13390 : "n/a");
13391 }
d77114b7 13392
d77114b7 13393
10711563
DA
13394 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13395 json_object_string_add(
13396 json_hname, "rcvHostName",
13397 p->hostname ? p->hostname : "n/a");
13398 json_object_string_add(
13399 json_hname, "rcvDomainName",
13400 p->domainname ? p->domainname : "n/a");
13401 }
d77114b7 13402
10711563
DA
13403 json_object_object_add(json_cap, "hostName",
13404 json_hname);
d77114b7 13405
17be83bf 13406 /* Graceful Restart */
10711563
DA
13407 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13408 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13409 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13410 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13411 json_object_string_add(
10711563
DA
13412 json_cap, "gracefulRestart",
13413 "advertisedAndReceived");
13414 else if (CHECK_FLAG(p->cap,
13415 PEER_CAP_RESTART_ADV))
d77114b7 13416 json_object_string_add(
10711563
DA
13417 json_cap,
13418 "gracefulRestartCapability",
13419 "advertised");
13420 else if (CHECK_FLAG(p->cap,
13421 PEER_CAP_RESTART_RCV))
13422 json_object_string_add(
13423 json_cap,
13424 "gracefulRestartCapability",
13425 "received");
d77114b7 13426
10711563
DA
13427 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13428 int restart_af_count = 0;
13429 json_object *json_restart = NULL;
13430 json_restart = json_object_new_object();
d62a17ae 13431
10711563
DA
13432 json_object_int_add(
13433 json_cap,
13434 "gracefulRestartRemoteTimerMsecs",
13435 p->v_gr_restart * 1000);
d62a17ae 13436
10711563 13437 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13438 if (CHECK_FLAG(
13439 p->af_cap[afi]
13440 [safi],
10711563
DA
13441 PEER_CAP_RESTART_AF_RCV)) {
13442 json_object *json_sub =
13443 NULL;
13444 json_sub =
13445 json_object_new_object();
d62a17ae 13446
05c7a1cc
QY
13447 if (CHECK_FLAG(
13448 p->af_cap
13449 [afi]
13450 [safi],
10711563
DA
13451 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13452 json_object_boolean_true_add(
13453 json_sub,
13454 "preserved");
13455 restart_af_count++;
d62a17ae 13456 json_object_object_add(
10711563
DA
13457 json_restart,
13458 get_afi_safi_str(
13459 afi,
13460 safi,
13461 true),
13462 json_sub);
d62a17ae 13463 }
d62a17ae 13464 }
10711563
DA
13465 if (!restart_af_count) {
13466 json_object_string_add(
13467 json_cap,
13468 "addressFamiliesByPeer",
13469 "none");
13470 json_object_free(json_restart);
13471 } else
13472 json_object_object_add(
13473 json_cap,
13474 "addressFamiliesByPeer",
13475 json_restart);
d62a17ae 13476 }
10711563
DA
13477 }
13478 json_object_object_add(
13479 json_neigh, "neighborCapabilities", json_cap);
13480 } else {
13481 vty_out(vty, " Neighbor capabilities:\n");
13482
13483 /* AS4 */
13484 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13485 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13486 vty_out(vty, " 4 Byte AS:");
13487 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13488 vty_out(vty, " advertised");
13489 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13490 vty_out(vty, " %sreceived",
13491 CHECK_FLAG(p->cap,
13492 PEER_CAP_AS4_ADV)
13493 ? "and "
13494 : "");
13495 vty_out(vty, "\n");
13496 }
d62a17ae 13497
10711563
DA
13498 /* Extended Message Support */
13499 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13500 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13501 vty_out(vty, " Extended Message:");
ef56aee4 13502 if (CHECK_FLAG(p->cap,
10711563
DA
13503 PEER_CAP_EXTENDED_MESSAGE_ADV))
13504 vty_out(vty, " advertised");
13505 if (CHECK_FLAG(p->cap,
13506 PEER_CAP_EXTENDED_MESSAGE_RCV))
13507 vty_out(vty, " %sreceived",
13508 CHECK_FLAG(
13509 p->cap,
13510 PEER_CAP_EXTENDED_MESSAGE_ADV)
13511 ? "and "
13512 : "");
13513 vty_out(vty, "\n");
13514 }
d62a17ae 13515
10711563
DA
13516 /* AddPath */
13517 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13518 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13519 vty_out(vty, " AddPath:\n");
d62a17ae 13520
10711563 13521 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13522 if (CHECK_FLAG(
10711563
DA
13523 p->af_cap[afi][safi],
13524 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13525 CHECK_FLAG(
13526 p->af_cap[afi][safi],
13527 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13528 vty_out(vty, " %s: TX ",
13529 get_afi_safi_str(
13530 afi, safi,
13531 false));
ef56aee4 13532
10711563
DA
13533 if (CHECK_FLAG(
13534 p->af_cap[afi]
13535 [safi],
13536 PEER_CAP_ADDPATH_AF_TX_ADV))
13537 vty_out(vty,
13538 "advertised");
d62a17ae 13539
05c7a1cc
QY
13540 if (CHECK_FLAG(
13541 p->af_cap[afi]
13542 [safi],
10711563 13543 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13544 vty_out(vty,
10711563
DA
13545 "%sreceived",
13546 CHECK_FLAG(
13547 p->af_cap
13548 [afi]
13549 [safi],
13550 PEER_CAP_ADDPATH_AF_TX_ADV)
13551 ? " and "
13552 : "");
05c7a1cc 13553
10711563
DA
13554 vty_out(vty, "\n");
13555 }
d62a17ae 13556
9af52ccf 13557 if (CHECK_FLAG(
10711563
DA
13558 p->af_cap[afi][safi],
13559 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13560 CHECK_FLAG(
13561 p->af_cap[afi][safi],
13562 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13563 vty_out(vty, " %s: RX ",
5cb5f4d0 13564 get_afi_safi_str(
10711563
DA
13565 afi, safi,
13566 false));
d62a17ae 13567
05c7a1cc
QY
13568 if (CHECK_FLAG(
13569 p->af_cap[afi]
13570 [safi],
10711563 13571 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13572 vty_out(vty,
10711563 13573 "advertised");
d62a17ae 13574
10711563
DA
13575 if (CHECK_FLAG(
13576 p->af_cap[afi]
13577 [safi],
13578 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13579 vty_out(vty,
10711563
DA
13580 "%sreceived",
13581 CHECK_FLAG(
13582 p->af_cap
13583 [afi]
13584 [safi],
13585 PEER_CAP_ADDPATH_AF_RX_ADV)
13586 ? " and "
05c7a1cc 13587 : "");
d62a17ae 13588
05c7a1cc 13589 vty_out(vty, "\n");
05c7a1cc 13590 }
d62a17ae 13591 }
10711563 13592 }
d62a17ae 13593
10711563
DA
13594 /* Dynamic */
13595 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13596 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13597 vty_out(vty, " Dynamic:");
13598 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13599 vty_out(vty, " advertised");
13600 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13601 vty_out(vty, " %sreceived",
13602 CHECK_FLAG(p->cap,
13603 PEER_CAP_DYNAMIC_ADV)
13604 ? "and "
13605 : "");
13606 vty_out(vty, "\n");
13607 }
d62a17ae 13608
d864dd9e
EB
13609 /* Role */
13610 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV) ||
13611 CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV)) {
13612 vty_out(vty, " Role:");
13613 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_ADV))
13614 vty_out(vty, " advertised");
13615 if (CHECK_FLAG(p->cap, PEER_CAP_ROLE_RCV))
13616 vty_out(vty, " %sreceived",
13617 CHECK_FLAG(p->cap,
13618 PEER_CAP_ROLE_ADV)
13619 ? "and "
13620 : "");
13621 vty_out(vty, "\n");
13622 }
13623
10711563
DA
13624 /* Extended nexthop */
13625 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13626 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13627 vty_out(vty, " Extended nexthop:");
13628 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13629 vty_out(vty, " advertised");
13630 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13631 vty_out(vty, " %sreceived",
13632 CHECK_FLAG(p->cap,
13633 PEER_CAP_ENHE_ADV)
13634 ? "and "
13635 : "");
13636 vty_out(vty, "\n");
d62a17ae 13637
10711563 13638 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13639 vty_out(vty,
10711563
DA
13640 " Address families by peer:\n ");
13641 for (safi = SAFI_UNICAST;
13642 safi < SAFI_MAX; safi++)
13643 if (CHECK_FLAG(
13644 p->af_cap[AFI_IP]
13645 [safi],
13646 PEER_CAP_ENHE_AF_RCV))
13647 vty_out(vty,
13648 " %s\n",
13649 get_afi_safi_str(
13650 AFI_IP,
13651 safi,
13652 false));
d62a17ae 13653 }
10711563 13654 }
d62a17ae 13655
10711563
DA
13656 /* Long-lived Graceful Restart */
13657 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13658 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13659 vty_out(vty,
13660 " Long-lived Graceful Restart:");
13661 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13662 vty_out(vty, " advertised");
13663 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13664 vty_out(vty, " %sreceived",
13665 CHECK_FLAG(p->cap,
13666 PEER_CAP_LLGR_ADV)
13667 ? "and "
13668 : "");
13669 vty_out(vty, "\n");
8606be87 13670
10711563 13671 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13672 vty_out(vty,
10711563
DA
13673 " Address families by peer:\n");
13674 FOREACH_AFI_SAFI (afi, safi)
13675 if (CHECK_FLAG(
13676 p->af_cap[afi]
13677 [safi],
13678 PEER_CAP_LLGR_AF_RCV))
13679 vty_out(vty,
13680 " %s\n",
13681 get_afi_safi_str(
13682 afi,
13683 safi,
13684 false));
8606be87 13685 }
10711563 13686 }
8606be87 13687
10711563
DA
13688 /* Route Refresh */
13689 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13690 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13691 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13692 vty_out(vty, " Route refresh:");
13693 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13694 vty_out(vty, " advertised");
13695 if (CHECK_FLAG(p->cap,
13696 PEER_CAP_REFRESH_NEW_RCV) ||
13697 CHECK_FLAG(p->cap,
13698 PEER_CAP_REFRESH_OLD_RCV))
13699 vty_out(vty, " %sreceived(%s)",
13700 CHECK_FLAG(p->cap,
13701 PEER_CAP_REFRESH_ADV)
13702 ? "and "
13703 : "",
13704 (CHECK_FLAG(
13705 p->cap,
13706 PEER_CAP_REFRESH_OLD_RCV) &&
13707 CHECK_FLAG(
13708 p->cap,
13709 PEER_CAP_REFRESH_NEW_RCV))
13710 ? "old & new"
13711 : CHECK_FLAG(
13712 p->cap,
13713 PEER_CAP_REFRESH_OLD_RCV)
13714 ? "old"
13715 : "new");
d62a17ae 13716
d77114b7 13717 vty_out(vty, "\n");
10711563 13718 }
d62a17ae 13719
10711563
DA
13720 /* Enhanced Route Refresh */
13721 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13722 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13723 vty_out(vty, " Enhanced Route Refresh:");
13724 if (CHECK_FLAG(p->cap,
13725 PEER_CAP_ENHANCED_RR_ADV))
13726 vty_out(vty, " advertised");
13727 if (CHECK_FLAG(p->cap,
13728 PEER_CAP_ENHANCED_RR_RCV))
13729 vty_out(vty, " %sreceived",
13730 CHECK_FLAG(p->cap,
13731 PEER_CAP_REFRESH_ADV)
13732 ? "and "
13733 : "");
13734 vty_out(vty, "\n");
13735 }
13736
13737 /* Multiprotocol Extensions */
13738 FOREACH_AFI_SAFI (afi, safi)
13739 if (p->afc_adv[afi][safi] ||
13740 p->afc_recv[afi][safi]) {
13741 vty_out(vty, " Address Family %s:",
13742 get_afi_safi_str(afi, safi,
13743 false));
13744 if (p->afc_adv[afi][safi])
9af52ccf 13745 vty_out(vty, " advertised");
10711563 13746 if (p->afc_recv[afi][safi])
9af52ccf 13747 vty_out(vty, " %sreceived",
10711563 13748 p->afc_adv[afi][safi]
9af52ccf
DA
13749 ? "and "
13750 : "");
13751 vty_out(vty, "\n");
13752 }
13753
10711563
DA
13754 /* Hostname capability */
13755 vty_out(vty, " Hostname Capability:");
d62a17ae 13756
10711563
DA
13757 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13758 vty_out(vty,
13759 " advertised (name: %s,domain name: %s)",
13760 bgp->peer_self->hostname
13761 ? bgp->peer_self->hostname
13762 : "n/a",
13763 bgp->peer_self->domainname
13764 ? bgp->peer_self->domainname
13765 : "n/a");
13766 } else {
13767 vty_out(vty, " not advertised");
13768 }
d77114b7 13769
10711563
DA
13770 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13771 vty_out(vty,
13772 " received (name: %s,domain name: %s)",
13773 p->hostname ? p->hostname : "n/a",
13774 p->domainname ? p->domainname : "n/a");
13775 } else {
13776 vty_out(vty, " not received");
d62a17ae 13777 }
d62a17ae 13778
10711563 13779 vty_out(vty, "\n");
d77114b7 13780
10711563
DA
13781 /* Graceful Restart */
13782 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13783 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13784 vty_out(vty,
13785 " Graceful Restart Capability:");
13786 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13787 vty_out(vty, " advertised");
13788 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13789 vty_out(vty, " %sreceived",
13790 CHECK_FLAG(p->cap,
13791 PEER_CAP_RESTART_ADV)
13792 ? "and "
13793 : "");
d77114b7
MK
13794 vty_out(vty, "\n");
13795
10711563
DA
13796 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13797 int restart_af_count = 0;
d62a17ae 13798
10711563
DA
13799 vty_out(vty,
13800 " Remote Restart timer is %d seconds\n",
13801 p->v_gr_restart);
13802 vty_out(vty,
13803 " Address families by peer:\n ");
d62a17ae 13804
10711563
DA
13805 FOREACH_AFI_SAFI (afi, safi)
13806 if (CHECK_FLAG(
13807 p->af_cap[afi]
13808 [safi],
13809 PEER_CAP_RESTART_AF_RCV)) {
13810 vty_out(vty, "%s%s(%s)",
13811 restart_af_count
13812 ? ", "
13813 : "",
13814 get_afi_safi_str(
13815 afi,
13816 safi,
13817 false),
13818 CHECK_FLAG(
13819 p->af_cap
13820 [afi]
13821 [safi],
13822 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13823 ? "preserved"
13824 : "not preserved");
13825 restart_af_count++;
13826 }
13827 if (!restart_af_count)
13828 vty_out(vty, "none");
13829 vty_out(vty, "\n");
13830 }
17be83bf 13831 } /* Graceful Restart */
d62a17ae 13832 }
13833 }
13834
13835 /* graceful restart information */
10711563
DA
13836 json_object *json_grace = NULL;
13837 json_object *json_grace_send = NULL;
13838 json_object *json_grace_recv = NULL;
13839 int eor_send_af_count = 0;
13840 int eor_receive_af_count = 0;
d62a17ae 13841
10711563
DA
13842 if (use_json) {
13843 json_grace = json_object_new_object();
13844 json_grace_send = json_object_new_object();
13845 json_grace_recv = json_object_new_object();
13846
13847 if ((peer_established(p)) &&
13848 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13849 FOREACH_AFI_SAFI (afi, safi) {
13850 if (CHECK_FLAG(p->af_sflags[afi][safi],
13851 PEER_STATUS_EOR_SEND)) {
13852 json_object_boolean_true_add(
13853 json_grace_send,
13854 get_afi_safi_str(afi, safi,
13855 true));
13856 eor_send_af_count++;
d62a17ae 13857 }
10711563
DA
13858 }
13859 FOREACH_AFI_SAFI (afi, safi) {
13860 if (CHECK_FLAG(p->af_sflags[afi][safi],
13861 PEER_STATUS_EOR_RECEIVED)) {
13862 json_object_boolean_true_add(
13863 json_grace_recv,
13864 get_afi_safi_str(afi, safi,
13865 true));
13866 eor_receive_af_count++;
d62a17ae 13867 }
13868 }
10711563
DA
13869 }
13870 json_object_object_add(json_grace, "endOfRibSend",
13871 json_grace_send);
13872 json_object_object_add(json_grace, "endOfRibRecv",
13873 json_grace_recv);
d62a17ae 13874
d62a17ae 13875
10711563
DA
13876 if (p->t_gr_restart)
13877 json_object_int_add(
13878 json_grace, "gracefulRestartTimerMsecs",
13879 thread_timer_remain_second(p->t_gr_restart) *
13880 1000);
2986cac2 13881
10711563
DA
13882 if (p->t_gr_stale)
13883 json_object_int_add(
13884 json_grace, "gracefulStalepathTimerMsecs",
13885 thread_timer_remain_second(p->t_gr_stale) *
13886 1000);
13887 /* more gr info in new format */
13888 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13889 json_object_object_add(json_neigh, "gracefulRestartInfo",
13890 json_grace);
13891 } else {
13892 vty_out(vty, " Graceful restart information:\n");
13893 if ((peer_established(p)) &&
13894 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13895
13896 vty_out(vty, " End-of-RIB send: ");
13897 FOREACH_AFI_SAFI (afi, safi) {
13898 if (CHECK_FLAG(p->af_sflags[afi][safi],
13899 PEER_STATUS_EOR_SEND)) {
13900 vty_out(vty, "%s%s",
13901 eor_send_af_count ? ", " : "",
13902 get_afi_safi_str(afi, safi,
13903 false));
13904 eor_send_af_count++;
d62a17ae 13905 }
10711563
DA
13906 }
13907 vty_out(vty, "\n");
13908 vty_out(vty, " End-of-RIB received: ");
13909 FOREACH_AFI_SAFI (afi, safi) {
13910 if (CHECK_FLAG(p->af_sflags[afi][safi],
13911 PEER_STATUS_EOR_RECEIVED)) {
13912 vty_out(vty, "%s%s",
13913 eor_receive_af_count ? ", "
13914 : "",
13915 get_afi_safi_str(afi, safi,
13916 false));
13917 eor_receive_af_count++;
d62a17ae 13918 }
d62a17ae 13919 }
10711563
DA
13920 vty_out(vty, "\n");
13921 }
d62a17ae 13922
10711563
DA
13923 if (p->t_gr_restart)
13924 vty_out(vty,
13925 " The remaining time of restart timer is %ld\n",
13926 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13927
10711563
DA
13928 if (p->t_gr_stale)
13929 vty_out(vty,
13930 " The remaining time of stalepath timer is %ld\n",
13931 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13932
10711563
DA
13933 /* more gr info in new format */
13934 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13935 }
2986cac2 13936
d62a17ae 13937 if (use_json) {
13938 json_object *json_stat = NULL;
13939 json_stat = json_object_new_object();
13940 /* Packet counts. */
43aa5965
QY
13941
13942 atomic_size_t outq_count, inq_count;
13943 outq_count = atomic_load_explicit(&p->obuf->count,
13944 memory_order_relaxed);
13945 inq_count = atomic_load_explicit(&p->ibuf->count,
13946 memory_order_relaxed);
13947
13948 json_object_int_add(json_stat, "depthInq",
13949 (unsigned long)inq_count);
d62a17ae 13950 json_object_int_add(json_stat, "depthOutq",
43aa5965 13951 (unsigned long)outq_count);
0112e9e0
QY
13952 json_object_int_add(json_stat, "opensSent",
13953 atomic_load_explicit(&p->open_out,
13954 memory_order_relaxed));
13955 json_object_int_add(json_stat, "opensRecv",
13956 atomic_load_explicit(&p->open_in,
13957 memory_order_relaxed));
d62a17ae 13958 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13959 atomic_load_explicit(&p->notify_out,
13960 memory_order_relaxed));
d62a17ae 13961 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13962 atomic_load_explicit(&p->notify_in,
13963 memory_order_relaxed));
13964 json_object_int_add(json_stat, "updatesSent",
13965 atomic_load_explicit(&p->update_out,
13966 memory_order_relaxed));
13967 json_object_int_add(json_stat, "updatesRecv",
13968 atomic_load_explicit(&p->update_in,
13969 memory_order_relaxed));
d62a17ae 13970 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13971 atomic_load_explicit(&p->keepalive_out,
13972 memory_order_relaxed));
d62a17ae 13973 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13974 atomic_load_explicit(&p->keepalive_in,
13975 memory_order_relaxed));
d62a17ae 13976 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13977 atomic_load_explicit(&p->refresh_out,
13978 memory_order_relaxed));
d62a17ae 13979 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13980 atomic_load_explicit(&p->refresh_in,
13981 memory_order_relaxed));
d62a17ae 13982 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13983 atomic_load_explicit(&p->dynamic_cap_out,
13984 memory_order_relaxed));
d62a17ae 13985 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13986 atomic_load_explicit(&p->dynamic_cap_in,
13987 memory_order_relaxed));
13988 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13989 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13990 json_object_object_add(json_neigh, "messageStats", json_stat);
13991 } else {
cb93e0a2
IS
13992 atomic_size_t outq_count, inq_count, open_out, open_in,
13993 notify_out, notify_in, update_out, update_in,
13994 keepalive_out, keepalive_in, refresh_out, refresh_in,
13995 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
13996 outq_count = atomic_load_explicit(&p->obuf->count,
13997 memory_order_relaxed);
13998 inq_count = atomic_load_explicit(&p->ibuf->count,
13999 memory_order_relaxed);
cb93e0a2
IS
14000 open_out = atomic_load_explicit(&p->open_out,
14001 memory_order_relaxed);
14002 open_in =
14003 atomic_load_explicit(&p->open_in, memory_order_relaxed);
14004 notify_out = atomic_load_explicit(&p->notify_out,
14005 memory_order_relaxed);
14006 notify_in = atomic_load_explicit(&p->notify_in,
14007 memory_order_relaxed);
14008 update_out = atomic_load_explicit(&p->update_out,
14009 memory_order_relaxed);
14010 update_in = atomic_load_explicit(&p->update_in,
14011 memory_order_relaxed);
14012 keepalive_out = atomic_load_explicit(&p->keepalive_out,
14013 memory_order_relaxed);
14014 keepalive_in = atomic_load_explicit(&p->keepalive_in,
14015 memory_order_relaxed);
14016 refresh_out = atomic_load_explicit(&p->refresh_out,
14017 memory_order_relaxed);
14018 refresh_in = atomic_load_explicit(&p->refresh_in,
14019 memory_order_relaxed);
14020 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
14021 memory_order_relaxed);
14022 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
14023 memory_order_relaxed);
43aa5965 14024
d62a17ae 14025 /* Packet counts. */
14026 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14027 vty_out(vty, " Inq depth is %zu\n", inq_count);
14028 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14029 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
14030 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
14031 open_in);
14032 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
14033 notify_in);
14034 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
14035 update_in);
14036 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
14037 keepalive_in);
14038 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
14039 refresh_in);
14040 vty_out(vty, " Capability: %10zu %10zu\n",
14041 dynamic_cap_out, dynamic_cap_in);
14042 vty_out(vty, " Total: %10u %10u\n",
14043 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 14044 }
14045
14046 if (use_json) {
14047 /* advertisement-interval */
14048 json_object_int_add(json_neigh,
14049 "minBtwnAdvertisementRunsTimerMsecs",
14050 p->v_routeadv * 1000);
14051
14052 /* Update-source. */
14053 if (p->update_if || p->update_source) {
14054 if (p->update_if)
14055 json_object_string_add(json_neigh,
14056 "updateSource",
14057 p->update_if);
14058 else if (p->update_source)
47e12884
DA
14059 json_object_string_addf(json_neigh,
14060 "updateSource", "%pSU",
14061 p->update_source);
d62a17ae 14062 }
14063 } else {
14064 /* advertisement-interval */
14065 vty_out(vty,
14066 " Minimum time between advertisement runs is %d seconds\n",
14067 p->v_routeadv);
14068
14069 /* Update-source. */
14070 if (p->update_if || p->update_source) {
14071 vty_out(vty, " Update source is ");
14072 if (p->update_if)
14073 vty_out(vty, "%s", p->update_if);
14074 else if (p->update_source)
47e12884 14075 vty_out(vty, "%pSU", p->update_source);
d62a17ae 14076 vty_out(vty, "\n");
14077 }
14078
14079 vty_out(vty, "\n");
14080 }
14081
14082 /* Address Family Information */
14083 json_object *json_hold = NULL;
14084
14085 if (use_json)
14086 json_hold = json_object_new_object();
14087
05c7a1cc
QY
14088 FOREACH_AFI_SAFI (afi, safi)
14089 if (p->afc[afi][safi])
14090 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14091 json_hold);
d62a17ae 14092
14093 if (use_json) {
14094 json_object_object_add(json_neigh, "addressFamilyInfo",
14095 json_hold);
14096 json_object_int_add(json_neigh, "connectionsEstablished",
14097 p->established);
14098 json_object_int_add(json_neigh, "connectionsDropped",
14099 p->dropped);
14100 } else
14101 vty_out(vty, " Connections established %d; dropped %d\n",
14102 p->established, p->dropped);
14103
14104 if (!p->last_reset) {
14105 if (use_json)
14106 json_object_string_add(json_neigh, "lastReset",
14107 "never");
14108 else
14109 vty_out(vty, " Last reset never\n");
14110 } else {
14111 if (use_json) {
14112 time_t uptime;
a2700b50 14113 struct tm tm;
d62a17ae 14114
083ec940 14115 uptime = monotime(NULL);
d62a17ae 14116 uptime -= p->resettime;
a2700b50
MS
14117 gmtime_r(&uptime, &tm);
14118
d62a17ae 14119 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14120 (tm.tm_sec * 1000)
14121 + (tm.tm_min * 60000)
14122 + (tm.tm_hour * 3600000));
3577f1c5 14123 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14124 } else {
14125 vty_out(vty, " Last reset %s, ",
14126 peer_uptime(p->resettime, timebuf,
14127 BGP_UPTIME_LEN, 0, NULL));
14128
3577f1c5 14129 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14130 if (p->last_reset_cause_size) {
14131 msg = p->last_reset_cause;
14132 vty_out(vty,
14133 " Message received that caused BGP to send a NOTIFICATION:\n ");
14134 for (i = 1; i <= p->last_reset_cause_size;
14135 i++) {
14136 vty_out(vty, "%02X", *msg++);
14137
14138 if (i != p->last_reset_cause_size) {
14139 if (i % 16 == 0) {
14140 vty_out(vty, "\n ");
14141 } else if (i % 4 == 0) {
14142 vty_out(vty, " ");
14143 }
14144 }
14145 }
14146 vty_out(vty, "\n");
14147 }
14148 }
14149 }
14150
14151 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14152 if (use_json)
14153 json_object_boolean_true_add(json_neigh,
14154 "prefixesConfigExceedMax");
14155 else
14156 vty_out(vty,
14157 " Peer had exceeded the max. no. of prefixes configured.\n");
14158
14159 if (p->t_pmax_restart) {
14160 if (use_json) {
14161 json_object_boolean_true_add(
14162 json_neigh, "reducePrefixNumFrom");
14163 json_object_int_add(json_neigh,
14164 "restartInTimerMsec",
14165 thread_timer_remain_second(
14166 p->t_pmax_restart)
14167 * 1000);
14168 } else
14169 vty_out(vty,
14170 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14171 p->host, thread_timer_remain_second(
14172 p->t_pmax_restart));
d62a17ae 14173 } else {
14174 if (use_json)
14175 json_object_boolean_true_add(
14176 json_neigh,
14177 "reducePrefixNumAndClearIpBgp");
14178 else
14179 vty_out(vty,
14180 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14181 p->host);
14182 }
14183 }
14184
14185 /* EBGP Multihop and GTSM */
14186 if (p->sort != BGP_PEER_IBGP) {
14187 if (use_json) {
e2521429 14188 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14189 json_object_int_add(json_neigh,
14190 "externalBgpNbrMaxHopsAway",
14191 p->gtsm_hops);
be8d1733 14192 else
d62a17ae 14193 json_object_int_add(json_neigh,
14194 "externalBgpNbrMaxHopsAway",
14195 p->ttl);
14196 } else {
e2521429 14197 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14198 vty_out(vty,
14199 " External BGP neighbor may be up to %d hops away.\n",
14200 p->gtsm_hops);
be8d1733 14201 else
d62a17ae 14202 vty_out(vty,
14203 " External BGP neighbor may be up to %d hops away.\n",
14204 p->ttl);
14205 }
14206 } else {
be8d1733
DA
14207 if (use_json) {
14208 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14209 json_object_int_add(json_neigh,
14210 "internalBgpNbrMaxHopsAway",
14211 p->gtsm_hops);
14212 else
be8d1733
DA
14213 json_object_int_add(json_neigh,
14214 "internalBgpNbrMaxHopsAway",
14215 p->ttl);
14216 } else {
14217 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14218 vty_out(vty,
14219 " Internal BGP neighbor may be up to %d hops away.\n",
14220 p->gtsm_hops);
be8d1733
DA
14221 else
14222 vty_out(vty,
14223 " Internal BGP neighbor may be up to %d hops away.\n",
14224 p->ttl);
d62a17ae 14225 }
14226 }
14227
14228 /* Local address. */
14229 if (p->su_local) {
14230 if (use_json) {
47e12884
DA
14231 json_object_string_addf(json_neigh, "hostLocal", "%pSU",
14232 p->su_local);
d62a17ae 14233 json_object_int_add(json_neigh, "portLocal",
14234 ntohs(p->su_local->sin.sin_port));
14235 } else
47e12884
DA
14236 vty_out(vty, "Local host: %pSU, Local port: %d\n",
14237 p->su_local, ntohs(p->su_local->sin.sin_port));
1e592331
DS
14238 } else {
14239 if (use_json) {
14240 json_object_string_add(json_neigh, "hostLocal",
14241 "Unknown");
14242 json_object_int_add(json_neigh, "portLocal", -1);
14243 }
d62a17ae 14244 }
14245
14246 /* Remote address. */
14247 if (p->su_remote) {
14248 if (use_json) {
47e12884
DA
14249 json_object_string_addf(json_neigh, "hostForeign",
14250 "%pSU", p->su_remote);
d62a17ae 14251 json_object_int_add(json_neigh, "portForeign",
14252 ntohs(p->su_remote->sin.sin_port));
14253 } else
47e12884
DA
14254 vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
14255 p->su_remote,
d62a17ae 14256 ntohs(p->su_remote->sin.sin_port));
1e592331
DS
14257 } else {
14258 if (use_json) {
14259 json_object_string_add(json_neigh, "hostForeign",
14260 "Unknown");
14261 json_object_int_add(json_neigh, "portForeign", -1);
14262 }
d62a17ae 14263 }
14264
14265 /* Nexthop display. */
14266 if (p->su_local) {
14267 if (use_json) {
c949c771
DA
14268 json_object_string_addf(json_neigh, "nexthop", "%pI4",
14269 &p->nexthop.v4);
14270 json_object_string_addf(json_neigh, "nexthopGlobal",
14271 "%pI6", &p->nexthop.v6_global);
14272 json_object_string_addf(json_neigh, "nexthopLocal",
14273 "%pI6", &p->nexthop.v6_local);
d62a17ae 14274 if (p->shared_network)
14275 json_object_string_add(json_neigh,
14276 "bgpConnection",
14277 "sharedNetwork");
14278 else
14279 json_object_string_add(json_neigh,
14280 "bgpConnection",
14281 "nonSharedNetwork");
14282 } else {
14283 vty_out(vty, "Nexthop: %s\n",
14284 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14285 sizeof(buf1)));
14286 vty_out(vty, "Nexthop global: %s\n",
14287 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14288 sizeof(buf1)));
14289 vty_out(vty, "Nexthop local: %s\n",
14290 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14291 sizeof(buf1)));
14292 vty_out(vty, "BGP connection: %s\n",
14293 p->shared_network ? "shared network"
14294 : "non shared network");
14295 }
14296 }
14297
14298 /* Timer information. */
14299 if (use_json) {
14300 json_object_int_add(json_neigh, "connectRetryTimer",
14301 p->v_connect);
feb17238 14302 if (peer_established(p) && p->rtt)
d62a17ae 14303 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14304 p->rtt);
14305 if (p->t_start)
14306 json_object_int_add(
14307 json_neigh, "nextStartTimerDueInMsecs",
14308 thread_timer_remain_second(p->t_start) * 1000);
14309 if (p->t_connect)
14310 json_object_int_add(
14311 json_neigh, "nextConnectTimerDueInMsecs",
14312 thread_timer_remain_second(p->t_connect)
14313 * 1000);
14314 if (p->t_routeadv) {
14315 json_object_int_add(json_neigh, "mraiInterval",
14316 p->v_routeadv);
14317 json_object_int_add(
14318 json_neigh, "mraiTimerExpireInMsecs",
14319 thread_timer_remain_second(p->t_routeadv)
14320 * 1000);
14321 }
14322 if (p->password)
14323 json_object_int_add(json_neigh, "authenticationEnabled",
14324 1);
14325
14326 if (p->t_read)
14327 json_object_string_add(json_neigh, "readThread", "on");
14328 else
14329 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14330
14331 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14332 json_object_string_add(json_neigh, "writeThread", "on");
14333 else
14334 json_object_string_add(json_neigh, "writeThread",
14335 "off");
14336 } else {
14337 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14338 p->v_connect);
feb17238 14339 if (peer_established(p) && p->rtt)
d62a17ae 14340 vty_out(vty, "Estimated round trip time: %d ms\n",
14341 p->rtt);
14342 if (p->t_start)
14343 vty_out(vty, "Next start timer due in %ld seconds\n",
14344 thread_timer_remain_second(p->t_start));
14345 if (p->t_connect)
14346 vty_out(vty, "Next connect timer due in %ld seconds\n",
14347 thread_timer_remain_second(p->t_connect));
14348 if (p->t_routeadv)
14349 vty_out(vty,
14350 "MRAI (interval %u) timer expires in %ld seconds\n",
14351 p->v_routeadv,
14352 thread_timer_remain_second(p->t_routeadv));
14353 if (p->password)
14354 vty_out(vty, "Peer Authentication Enabled\n");
14355
cac9e917 14356 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14357 p->t_read ? "on" : "off",
14358 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14359 ? "on"
cac9e917 14360 : "off", p->fd);
d62a17ae 14361 }
14362
14363 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14364 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14365 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14366
14367 if (!use_json)
14368 vty_out(vty, "\n");
14369
14370 /* BFD information. */
21bfce98
RZ
14371 if (p->bfd_config)
14372 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14373
14374 if (use_json) {
14375 if (p->conf_if) /* Configured interface name. */
14376 json_object_object_add(json, p->conf_if, json_neigh);
14377 else /* Configured IP address. */
14378 json_object_object_add(json, p->host, json_neigh);
14379 }
14380}
14381
36235319
QY
14382static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14383 enum show_type type,
14384 union sockunion *su,
14385 const char *conf_if, afi_t afi,
74a630b6 14386 bool use_json)
2986cac2 14387{
14388 struct listnode *node, *nnode;
14389 struct peer *peer;
14390 int find = 0;
14391 safi_t safi = SAFI_UNICAST;
74a630b6 14392 json_object *json = NULL;
2986cac2 14393 json_object *json_neighbor = NULL;
14394
74a630b6
NT
14395 if (use_json) {
14396 json = json_object_new_object();
14397 json_neighbor = json_object_new_object();
14398 }
14399
2986cac2 14400 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14401
14402 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14403 continue;
14404
14405 if ((peer->afc[afi][safi]) == 0)
14406 continue;
14407
2ba1fe69 14408 if (type == show_all) {
2986cac2 14409 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14410 json_neighbor);
2986cac2 14411
74a630b6 14412 if (use_json) {
13909c4f
DS
14413 json_object_object_add(json, peer->host,
14414 json_neighbor);
74a630b6
NT
14415 json_neighbor = NULL;
14416 }
2986cac2 14417
2ba1fe69 14418 } else if (type == show_peer) {
2986cac2 14419 if (conf_if) {
14420 if ((peer->conf_if
13909c4f
DS
14421 && !strcmp(peer->conf_if, conf_if))
14422 || (peer->hostname
2986cac2 14423 && !strcmp(peer->hostname, conf_if))) {
14424 find = 1;
13909c4f
DS
14425 bgp_show_peer_gr_status(vty, peer,
14426 use_json,
14427 json_neighbor);
2986cac2 14428 }
14429 } else {
14430 if (sockunion_same(&peer->su, su)) {
14431 find = 1;
13909c4f
DS
14432 bgp_show_peer_gr_status(vty, peer,
14433 use_json,
14434 json_neighbor);
2986cac2 14435 }
14436 }
13909c4f
DS
14437 if (use_json && find)
14438 json_object_object_add(json, peer->host,
14439 json_neighbor);
2986cac2 14440 }
14441
74a630b6
NT
14442 if (find) {
14443 json_neighbor = NULL;
2986cac2 14444 break;
74a630b6 14445 }
2986cac2 14446 }
14447
14448 if (type == show_peer && !find) {
14449 if (use_json)
13909c4f 14450 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14451 else
14452 vty_out(vty, "%% No such neighbor\n");
14453 }
14454 if (use_json) {
74a630b6
NT
14455 if (json_neighbor)
14456 json_object_free(json_neighbor);
75eeda93 14457 vty_json(vty, json);
2986cac2 14458 } else {
14459 vty_out(vty, "\n");
14460 }
14461
14462 return CMD_SUCCESS;
14463}
14464
d62a17ae 14465static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14466 enum show_type type, union sockunion *su,
9f049418 14467 const char *conf_if, bool use_json,
d62a17ae 14468 json_object *json)
14469{
14470 struct listnode *node, *nnode;
14471 struct peer *peer;
14472 int find = 0;
9f049418 14473 bool nbr_output = false;
d1927ebe
AS
14474 afi_t afi = AFI_MAX;
14475 safi_t safi = SAFI_MAX;
14476
14477 if (type == show_ipv4_peer || type == show_ipv4_all) {
14478 afi = AFI_IP;
14479 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14480 afi = AFI_IP6;
14481 }
d62a17ae 14482
14483 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14484 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14485 continue;
14486
14487 switch (type) {
14488 case show_all:
14489 bgp_show_peer(vty, peer, use_json, json);
9f049418 14490 nbr_output = true;
d62a17ae 14491 break;
14492 case show_peer:
14493 if (conf_if) {
14494 if ((peer->conf_if
14495 && !strcmp(peer->conf_if, conf_if))
14496 || (peer->hostname
14497 && !strcmp(peer->hostname, conf_if))) {
14498 find = 1;
14499 bgp_show_peer(vty, peer, use_json,
14500 json);
14501 }
14502 } else {
14503 if (sockunion_same(&peer->su, su)) {
14504 find = 1;
14505 bgp_show_peer(vty, peer, use_json,
14506 json);
14507 }
14508 }
14509 break;
d1927ebe
AS
14510 case show_ipv4_peer:
14511 case show_ipv6_peer:
14512 FOREACH_SAFI (safi) {
14513 if (peer->afc[afi][safi]) {
14514 if (conf_if) {
14515 if ((peer->conf_if
14516 && !strcmp(peer->conf_if, conf_if))
14517 || (peer->hostname
14518 && !strcmp(peer->hostname, conf_if))) {
14519 find = 1;
14520 bgp_show_peer(vty, peer, use_json,
14521 json);
14522 break;
14523 }
14524 } else {
14525 if (sockunion_same(&peer->su, su)) {
14526 find = 1;
14527 bgp_show_peer(vty, peer, use_json,
14528 json);
14529 break;
14530 }
14531 }
14532 }
14533 }
14534 break;
14535 case show_ipv4_all:
14536 case show_ipv6_all:
14537 FOREACH_SAFI (safi) {
14538 if (peer->afc[afi][safi]) {
14539 bgp_show_peer(vty, peer, use_json, json);
14540 nbr_output = true;
14541 break;
14542 }
14543 }
14544 break;
d62a17ae 14545 }
14546 }
14547
d1927ebe
AS
14548 if ((type == show_peer || type == show_ipv4_peer ||
14549 type == show_ipv6_peer) && !find) {
d62a17ae 14550 if (use_json)
14551 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14552 else
88b7d255 14553 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14554 }
14555
d1927ebe
AS
14556 if (type != show_peer && type != show_ipv4_peer &&
14557 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14558 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14559
d62a17ae 14560 if (use_json) {
996c9314
LB
14561 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14562 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14563 } else {
14564 vty_out(vty, "\n");
14565 }
14566
14567 return CMD_SUCCESS;
14568}
14569
36235319
QY
14570static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14571 enum show_type type,
14572 const char *ip_str,
14573 afi_t afi, bool use_json)
2986cac2 14574{
14575
14576 int ret;
14577 struct bgp *bgp;
14578 union sockunion su;
2986cac2 14579
14580 bgp = bgp_get_default();
14581
13909c4f
DS
14582 if (!bgp)
14583 return;
2986cac2 14584
13909c4f
DS
14585 if (!use_json)
14586 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14587 NULL);
2986cac2 14588
13909c4f
DS
14589 if (ip_str) {
14590 ret = str2sockunion(ip_str, &su);
14591 if (ret < 0)
13909c4f 14592 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14593 vty, bgp, type, NULL, ip_str, afi, use_json);
14594 else
14595 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14596 NULL, afi, use_json);
13909c4f
DS
14597 } else
14598 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14599 afi, use_json);
2986cac2 14600}
14601
d62a17ae 14602static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14603 enum show_type type,
14604 const char *ip_str,
9f049418 14605 bool use_json)
d62a17ae 14606{
0291c246
MK
14607 struct listnode *node, *nnode;
14608 struct bgp *bgp;
71aedaa3 14609 union sockunion su;
0291c246 14610 json_object *json = NULL;
71aedaa3 14611 int ret, is_first = 1;
9f049418 14612 bool nbr_output = false;
d62a17ae 14613
14614 if (use_json)
14615 vty_out(vty, "{\n");
14616
14617 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14618 nbr_output = true;
d62a17ae 14619 if (use_json) {
14620 if (!(json = json_object_new_object())) {
af4c2728 14621 flog_err(
e50f7cfd 14622 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14623 "Unable to allocate memory for JSON object");
14624 vty_out(vty,
14625 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14626 return;
14627 }
14628
14629 json_object_int_add(json, "vrfId",
14630 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14631 ? -1
14632 : (int64_t)bgp->vrf_id);
d62a17ae 14633 json_object_string_add(
14634 json, "vrfName",
14635 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14636 ? VRF_DEFAULT_NAME
d62a17ae 14637 : bgp->name);
14638
14639 if (!is_first)
14640 vty_out(vty, ",\n");
14641 else
14642 is_first = 0;
14643
14644 vty_out(vty, "\"%s\":",
14645 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14646 ? VRF_DEFAULT_NAME
d62a17ae 14647 : bgp->name);
14648 } else {
14649 vty_out(vty, "\nInstance %s:\n",
14650 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14651 ? VRF_DEFAULT_NAME
d62a17ae 14652 : bgp->name);
14653 }
71aedaa3 14654
d1927ebe
AS
14655 if (type == show_peer || type == show_ipv4_peer ||
14656 type == show_ipv6_peer) {
71aedaa3
DS
14657 ret = str2sockunion(ip_str, &su);
14658 if (ret < 0)
14659 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14660 use_json, json);
14661 else
14662 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14663 use_json, json);
14664 } else {
d1927ebe 14665 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14666 use_json, json);
14667 }
b77004d6 14668 json_object_free(json);
121067e9 14669 json = NULL;
d62a17ae 14670 }
14671
3e78a6ce 14672 if (use_json)
d62a17ae 14673 vty_out(vty, "}\n");
9f049418
DS
14674 else if (!nbr_output)
14675 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14676}
14677
14678static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14679 enum show_type type, const char *ip_str,
9f049418 14680 bool use_json)
d62a17ae 14681{
14682 int ret;
14683 struct bgp *bgp;
14684 union sockunion su;
14685 json_object *json = NULL;
14686
14687 if (name) {
14688 if (strmatch(name, "all")) {
71aedaa3
DS
14689 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14690 use_json);
d62a17ae 14691 return CMD_SUCCESS;
14692 } else {
14693 bgp = bgp_lookup_by_name(name);
14694 if (!bgp) {
14695 if (use_json) {
14696 json = json_object_new_object();
75eeda93 14697 vty_json(vty, json);
d62a17ae 14698 } else
14699 vty_out(vty,
9f049418 14700 "%% BGP instance not found\n");
d62a17ae 14701
14702 return CMD_WARNING;
14703 }
14704 }
14705 } else {
14706 bgp = bgp_get_default();
14707 }
14708
14709 if (bgp) {
14710 json = json_object_new_object();
14711 if (ip_str) {
14712 ret = str2sockunion(ip_str, &su);
14713 if (ret < 0)
14714 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14715 use_json, json);
14716 else
14717 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14718 use_json, json);
14719 } else {
14720 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14721 json);
14722 }
14723 json_object_free(json);
ca61fd25
DS
14724 } else {
14725 if (use_json)
14726 vty_out(vty, "{}\n");
14727 else
14728 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14729 }
14730
14731 return CMD_SUCCESS;
4fb25c53
DW
14732}
14733
2986cac2 14734
14735
14736/* "show [ip] bgp neighbors graceful-restart" commands. */
14737DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14738 show_ip_bgp_neighbors_graceful_restart_cmd,
14739 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14740 SHOW_STR
14741 BGP_STR
14742 IP_STR
14743 IPV6_STR
14744 NEIGHBOR_STR
14745 "Neighbor to display information about\n"
14746 "Neighbor to display information about\n"
14747 "Neighbor on BGP configured interface\n"
14748 GR_SHOW
14749 JSON_STR)
14750{
14751 char *sh_arg = NULL;
14752 enum show_type sh_type;
14753 int idx = 0;
14754 afi_t afi = AFI_MAX;
2986cac2 14755 bool uj = use_json(argc, argv);
14756
36235319 14757 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14758 afi = AFI_MAX;
14759
14760 idx++;
14761
14762 if (argv_find(argv, argc, "A.B.C.D", &idx)
14763 || argv_find(argv, argc, "X:X::X:X", &idx)
14764 || argv_find(argv, argc, "WORD", &idx)) {
14765 sh_type = show_peer;
14766 sh_arg = argv[idx]->arg;
14767 } else
14768 sh_type = show_all;
14769
14770 if (!argv_find(argv, argc, "graceful-restart", &idx))
14771 return CMD_SUCCESS;
14772
14773
36235319
QY
14774 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14775 afi, uj);
2986cac2 14776}
14777
716b2d8a 14778/* "show [ip] bgp neighbors" commands. */
718e3744 14779DEFUN (show_ip_bgp_neighbors,
14780 show_ip_bgp_neighbors_cmd,
24345e82 14781 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14782 SHOW_STR
14783 IP_STR
14784 BGP_STR
f2a8972b 14785 BGP_INSTANCE_HELP_STR
00e6edb9
DA
14786 BGP_AF_STR
14787 BGP_AF_STR
718e3744 14788 "Detailed information on TCP and BGP neighbor connections\n"
14789 "Neighbor to display information about\n"
a80beece 14790 "Neighbor to display information about\n"
91d37724 14791 "Neighbor on BGP configured interface\n"
9973d184 14792 JSON_STR)
718e3744 14793{
d62a17ae 14794 char *vrf = NULL;
14795 char *sh_arg = NULL;
14796 enum show_type sh_type;
d1927ebe 14797 afi_t afi = AFI_MAX;
718e3744 14798
9f049418 14799 bool uj = use_json(argc, argv);
718e3744 14800
d62a17ae 14801 int idx = 0;
718e3744 14802
9a8bdf1c
PG
14803 /* [<vrf> VIEWVRFNAME] */
14804 if (argv_find(argv, argc, "vrf", &idx)) {
14805 vrf = argv[idx + 1]->arg;
14806 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14807 vrf = NULL;
14808 } else if (argv_find(argv, argc, "view", &idx))
14809 /* [<view> VIEWVRFNAME] */
d62a17ae 14810 vrf = argv[idx + 1]->arg;
718e3744 14811
d62a17ae 14812 idx++;
d1927ebe
AS
14813
14814 if (argv_find(argv, argc, "ipv4", &idx)) {
14815 sh_type = show_ipv4_all;
14816 afi = AFI_IP;
14817 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14818 sh_type = show_ipv6_all;
14819 afi = AFI_IP6;
14820 } else {
14821 sh_type = show_all;
14822 }
14823
d62a17ae 14824 if (argv_find(argv, argc, "A.B.C.D", &idx)
14825 || argv_find(argv, argc, "X:X::X:X", &idx)
14826 || argv_find(argv, argc, "WORD", &idx)) {
14827 sh_type = show_peer;
14828 sh_arg = argv[idx]->arg;
d1927ebe
AS
14829 }
14830
14831 if (sh_type == show_peer && afi == AFI_IP) {
14832 sh_type = show_ipv4_peer;
14833 } else if (sh_type == show_peer && afi == AFI_IP6) {
14834 sh_type = show_ipv6_peer;
14835 }
856ca177 14836
d62a17ae 14837 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14838}
14839
716b2d8a 14840/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14841 paths' and `show ip mbgp paths'. Those functions results are the
14842 same.*/
f412b39a 14843DEFUN (show_ip_bgp_paths,
718e3744 14844 show_ip_bgp_paths_cmd,
46f296b4 14845 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14846 SHOW_STR
14847 IP_STR
14848 BGP_STR
46f296b4 14849 BGP_SAFI_HELP_STR
718e3744 14850 "Path information\n")
14851{
d62a17ae 14852 vty_out(vty, "Address Refcnt Path\n");
14853 aspath_print_all_vty(vty);
14854 return CMD_SUCCESS;
718e3744 14855}
14856
718e3744 14857#include "hash.h"
14858
e3b78da8 14859static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14860 struct vty *vty)
718e3744 14861{
d62a17ae 14862 struct community *com;
718e3744 14863
e3b78da8 14864 com = (struct community *)bucket->data;
3f65c5b1 14865 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 14866 community_str(com, false, false));
718e3744 14867}
14868
14869/* Show BGP's community internal data. */
f412b39a 14870DEFUN (show_ip_bgp_community_info,
718e3744 14871 show_ip_bgp_community_info_cmd,
bec37ba5 14872 "show [ip] bgp community-info",
718e3744 14873 SHOW_STR
14874 IP_STR
14875 BGP_STR
14876 "List all bgp community information\n")
14877{
d62a17ae 14878 vty_out(vty, "Address Refcnt Community\n");
718e3744 14879
d62a17ae 14880 hash_iterate(community_hash(),
e3b78da8 14881 (void (*)(struct hash_bucket *,
d62a17ae 14882 void *))community_show_all_iterator,
14883 vty);
718e3744 14884
d62a17ae 14885 return CMD_SUCCESS;
718e3744 14886}
14887
e3b78da8 14888static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14889 struct vty *vty)
57d187bc 14890{
d62a17ae 14891 struct lcommunity *lcom;
57d187bc 14892
e3b78da8 14893 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14894 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 14895 lcommunity_str(lcom, false, false));
57d187bc
JS
14896}
14897
14898/* Show BGP's community internal data. */
14899DEFUN (show_ip_bgp_lcommunity_info,
14900 show_ip_bgp_lcommunity_info_cmd,
14901 "show ip bgp large-community-info",
14902 SHOW_STR
14903 IP_STR
14904 BGP_STR
14905 "List all bgp large-community information\n")
14906{
d62a17ae 14907 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14908
d62a17ae 14909 hash_iterate(lcommunity_hash(),
e3b78da8 14910 (void (*)(struct hash_bucket *,
d62a17ae 14911 void *))lcommunity_show_all_iterator,
14912 vty);
57d187bc 14913
d62a17ae 14914 return CMD_SUCCESS;
57d187bc 14915}
2986cac2 14916/* Graceful Restart */
14917
14918static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14919 struct bgp *bgp,
14920 bool use_json,
14921 json_object *json)
2986cac2 14922{
57d187bc
JS
14923
14924
2986cac2 14925 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14926
7318ae88 14927 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14928
14929 switch (bgp_global_gr_mode) {
14930
14931 case GLOBAL_HELPER:
13909c4f 14932 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14933 break;
14934
14935 case GLOBAL_GR:
13909c4f 14936 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14937 break;
14938
14939 case GLOBAL_DISABLE:
13909c4f 14940 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14941 break;
14942
14943 case GLOBAL_INVALID:
2986cac2 14944 vty_out(vty,
2ba1fe69 14945 "Global BGP GR Mode Invalid\n");
2986cac2 14946 break;
14947 }
14948 vty_out(vty, "\n");
14949}
14950
36235319
QY
14951static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14952 enum show_type type,
14953 const char *ip_str,
14954 afi_t afi, bool use_json)
2986cac2 14955{
14956 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14957 afi = AFI_IP;
14958
14959 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14960
36235319
QY
14961 bgp_show_neighbor_graceful_restart_vty(
14962 vty, type, ip_str, afi, use_json);
2986cac2 14963 afi++;
14964 }
14965 } else if (afi != AFI_MAX) {
36235319
QY
14966 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14967 use_json);
2986cac2 14968 } else {
14969 return CMD_ERR_INCOMPLETE;
14970 }
14971
14972 return CMD_SUCCESS;
14973}
14974/* Graceful Restart */
14975
f412b39a 14976DEFUN (show_ip_bgp_attr_info,
718e3744 14977 show_ip_bgp_attr_info_cmd,
bec37ba5 14978 "show [ip] bgp attribute-info",
718e3744 14979 SHOW_STR
14980 IP_STR
14981 BGP_STR
14982 "List all bgp attribute information\n")
14983{
d62a17ae 14984 attr_show_all(vty);
14985 return CMD_SUCCESS;
718e3744 14986}
6b0655a2 14987
03915806
CS
14988static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14989 afi_t afi, safi_t safi,
14990 bool use_json, json_object *json)
53089bec 14991{
14992 struct bgp *bgp;
14993 struct listnode *node;
14994 char *vname;
14995 char buf1[INET6_ADDRSTRLEN];
14996 char *ecom_str;
9c2fd3fe 14997 enum vpn_policy_direction dir;
53089bec 14998
03915806 14999 if (json) {
b46dfd20
DS
15000 json_object *json_import_vrfs = NULL;
15001 json_object *json_export_vrfs = NULL;
15002
b46dfd20
DS
15003 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15004
53089bec 15005 if (!bgp) {
75eeda93 15006 vty_json(vty, json);
b46dfd20 15007
53089bec 15008 return CMD_WARNING;
15009 }
b46dfd20 15010
94d4c685
DS
15011 /* Provide context for the block */
15012 json_object_string_add(json, "vrf", name ? name : "default");
15013 json_object_string_add(json, "afiSafi",
5cb5f4d0 15014 get_afi_safi_str(afi, safi, true));
94d4c685 15015
b46dfd20
DS
15016 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15017 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15018 json_object_string_add(json, "importFromVrfs", "none");
15019 json_object_string_add(json, "importRts", "none");
15020 } else {
6ce24e52
DS
15021 json_import_vrfs = json_object_new_array();
15022
b46dfd20
DS
15023 for (ALL_LIST_ELEMENTS_RO(
15024 bgp->vpn_policy[afi].import_vrf,
15025 node, vname))
15026 json_object_array_add(json_import_vrfs,
15027 json_object_new_string(vname));
15028
b20875ea
CS
15029 json_object_object_add(json, "importFromVrfs",
15030 json_import_vrfs);
b46dfd20 15031 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15032 if (bgp->vpn_policy[afi].rtlist[dir]) {
15033 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15034 bgp->vpn_policy[afi].rtlist[dir],
15035 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15036 json_object_string_add(json, "importRts",
15037 ecom_str);
15038 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15039 } else
15040 json_object_string_add(json, "importRts",
15041 "none");
b46dfd20
DS
15042 }
15043
15044 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15045 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15046 json_object_string_add(json, "exportToVrfs", "none");
15047 json_object_string_add(json, "routeDistinguisher",
15048 "none");
15049 json_object_string_add(json, "exportRts", "none");
15050 } else {
6ce24e52
DS
15051 json_export_vrfs = json_object_new_array();
15052
b46dfd20
DS
15053 for (ALL_LIST_ELEMENTS_RO(
15054 bgp->vpn_policy[afi].export_vrf,
15055 node, vname))
15056 json_object_array_add(json_export_vrfs,
15057 json_object_new_string(vname));
15058 json_object_object_add(json, "exportToVrfs",
15059 json_export_vrfs);
15060 json_object_string_add(json, "routeDistinguisher",
15061 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15062 buf1, RD_ADDRSTRLEN));
15063
15064 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15065 if (bgp->vpn_policy[afi].rtlist[dir]) {
15066 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15067 bgp->vpn_policy[afi].rtlist[dir],
15068 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15069 json_object_string_add(json, "exportRts",
15070 ecom_str);
15071 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15072 } else
15073 json_object_string_add(json, "exportRts",
15074 "none");
b46dfd20
DS
15075 }
15076
03915806 15077 if (use_json) {
75eeda93 15078 vty_json(vty, json);
03915806 15079 }
53089bec 15080 } else {
b46dfd20
DS
15081 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15082
53089bec 15083 if (!bgp) {
b46dfd20 15084 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15085 return CMD_WARNING;
15086 }
53089bec 15087
b46dfd20
DS
15088 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15089 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15090 vty_out(vty,
15091 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15092 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15093 else {
15094 vty_out(vty,
15095 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15096 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15097
15098 for (ALL_LIST_ELEMENTS_RO(
15099 bgp->vpn_policy[afi].import_vrf,
15100 node, vname))
15101 vty_out(vty, " %s\n", vname);
15102
15103 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15104 ecom_str = NULL;
15105 if (bgp->vpn_policy[afi].rtlist[dir]) {
15106 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15107 bgp->vpn_policy[afi].rtlist[dir],
15108 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15109 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15110
b20875ea
CS
15111 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15112 } else
15113 vty_out(vty, "Import RT(s):\n");
53089bec 15114 }
53089bec 15115
b46dfd20
DS
15116 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15117 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15118 vty_out(vty,
15119 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15120 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15121 else {
15122 vty_out(vty,
04c9077f 15123 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15124 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15125
15126 for (ALL_LIST_ELEMENTS_RO(
15127 bgp->vpn_policy[afi].export_vrf,
15128 node, vname))
15129 vty_out(vty, " %s\n", vname);
15130
15131 vty_out(vty, "RD: %s\n",
15132 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15133 buf1, RD_ADDRSTRLEN));
15134
15135 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15136 if (bgp->vpn_policy[afi].rtlist[dir]) {
15137 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15138 bgp->vpn_policy[afi].rtlist[dir],
15139 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15140 vty_out(vty, "Export RT: %s\n", ecom_str);
15141 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15142 } else
15143 vty_out(vty, "Import RT(s):\n");
53089bec 15144 }
53089bec 15145 }
15146
15147 return CMD_SUCCESS;
15148}
15149
03915806
CS
15150static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15151 safi_t safi, bool use_json)
15152{
15153 struct listnode *node, *nnode;
15154 struct bgp *bgp;
15155 char *vrf_name = NULL;
15156 json_object *json = NULL;
15157 json_object *json_vrf = NULL;
15158 json_object *json_vrfs = NULL;
15159
15160 if (use_json) {
15161 json = json_object_new_object();
15162 json_vrfs = json_object_new_object();
15163 }
15164
15165 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15166
15167 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15168 vrf_name = bgp->name;
15169
15170 if (use_json) {
15171 json_vrf = json_object_new_object();
15172 } else {
15173 vty_out(vty, "\nInstance %s:\n",
15174 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15175 ? VRF_DEFAULT_NAME : bgp->name);
15176 }
15177 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15178 if (use_json) {
15179 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15180 json_object_object_add(json_vrfs,
15181 VRF_DEFAULT_NAME, json_vrf);
15182 else
15183 json_object_object_add(json_vrfs, vrf_name,
15184 json_vrf);
15185 }
15186 }
15187
15188 if (use_json) {
15189 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 15190 vty_json(vty, json);
03915806
CS
15191 }
15192
15193 return CMD_SUCCESS;
15194}
15195
53089bec 15196/* "show [ip] bgp route-leak" command. */
15197DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15198 show_ip_bgp_route_leak_cmd,
15199 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15200 SHOW_STR
15201 IP_STR
15202 BGP_STR
15203 BGP_INSTANCE_HELP_STR
15204 BGP_AFI_HELP_STR
15205 BGP_SAFI_HELP_STR
15206 "Route leaking information\n"
15207 JSON_STR)
53089bec 15208{
15209 char *vrf = NULL;
15210 afi_t afi = AFI_MAX;
15211 safi_t safi = SAFI_MAX;
15212
9f049418 15213 bool uj = use_json(argc, argv);
53089bec 15214 int idx = 0;
03915806 15215 json_object *json = NULL;
53089bec 15216
15217 /* show [ip] bgp */
15218 if (argv_find(argv, argc, "ip", &idx)) {
15219 afi = AFI_IP;
15220 safi = SAFI_UNICAST;
15221 }
15222 /* [vrf VIEWVRFNAME] */
15223 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15224 vty_out(vty,
15225 "%% This command is not applicable to BGP views\n");
53089bec 15226 return CMD_WARNING;
15227 }
15228
9a8bdf1c
PG
15229 if (argv_find(argv, argc, "vrf", &idx)) {
15230 vrf = argv[idx + 1]->arg;
15231 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15232 vrf = NULL;
15233 }
53089bec 15234 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 15235 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 15236 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 15237
15238 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15239 vty_out(vty,
15240 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15241 return CMD_WARNING;
15242 }
15243
03915806
CS
15244 if (vrf && strmatch(vrf, "all"))
15245 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15246
15247 if (uj)
15248 json = json_object_new_object();
15249
15250 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15251}
15252
d62a17ae 15253static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15254 safi_t safi)
f186de26 15255{
d62a17ae 15256 struct listnode *node, *nnode;
15257 struct bgp *bgp;
f186de26 15258
d62a17ae 15259 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15260 vty_out(vty, "\nInstance %s:\n",
15261 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15262 ? VRF_DEFAULT_NAME
d62a17ae 15263 : bgp->name);
15264 update_group_show(bgp, afi, safi, vty, 0);
15265 }
f186de26 15266}
15267
d62a17ae 15268static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15269 int safi, uint64_t subgrp_id)
4fb25c53 15270{
d62a17ae 15271 struct bgp *bgp;
4fb25c53 15272
d62a17ae 15273 if (name) {
15274 if (strmatch(name, "all")) {
15275 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15276 return CMD_SUCCESS;
15277 } else {
15278 bgp = bgp_lookup_by_name(name);
15279 }
15280 } else {
15281 bgp = bgp_get_default();
15282 }
4fb25c53 15283
d62a17ae 15284 if (bgp)
15285 update_group_show(bgp, afi, safi, vty, subgrp_id);
15286 return CMD_SUCCESS;
4fb25c53
DW
15287}
15288
8fe8a7f6
DS
15289DEFUN (show_ip_bgp_updgrps,
15290 show_ip_bgp_updgrps_cmd,
c1a44e43 15291 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15292 SHOW_STR
15293 IP_STR
15294 BGP_STR
15295 BGP_INSTANCE_HELP_STR
c9e571b4 15296 BGP_AFI_HELP_STR
9bedbb1e 15297 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15298 "Detailed info about dynamic update groups\n"
15299 "Specific subgroup to display detailed info for\n")
8386ac43 15300{
d62a17ae 15301 char *vrf = NULL;
15302 afi_t afi = AFI_IP6;
15303 safi_t safi = SAFI_UNICAST;
15304 uint64_t subgrp_id = 0;
15305
15306 int idx = 0;
15307
15308 /* show [ip] bgp */
15309 if (argv_find(argv, argc, "ip", &idx))
15310 afi = AFI_IP;
9a8bdf1c
PG
15311 /* [<vrf> VIEWVRFNAME] */
15312 if (argv_find(argv, argc, "vrf", &idx)) {
15313 vrf = argv[idx + 1]->arg;
15314 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15315 vrf = NULL;
15316 } else if (argv_find(argv, argc, "view", &idx))
15317 /* [<view> VIEWVRFNAME] */
15318 vrf = argv[idx + 1]->arg;
d62a17ae 15319 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15320 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15321 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15322 }
5bf15956 15323
d62a17ae 15324 /* get subgroup id, if provided */
15325 idx = argc - 1;
15326 if (argv[idx]->type == VARIABLE_TKN)
15327 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15328
d62a17ae 15329 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15330}
15331
f186de26 15332DEFUN (show_bgp_instance_all_ipv6_updgrps,
15333 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15334 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15335 SHOW_STR
716b2d8a 15336 IP_STR
f186de26 15337 BGP_STR
15338 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15339 "Detailed info about dynamic update groups\n")
f186de26 15340{
d62a17ae 15341 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15342 return CMD_SUCCESS;
f186de26 15343}
15344
43d3f4fc
DS
15345DEFUN (show_bgp_l2vpn_evpn_updgrps,
15346 show_bgp_l2vpn_evpn_updgrps_cmd,
15347 "show [ip] bgp l2vpn evpn update-groups",
15348 SHOW_STR
15349 IP_STR
15350 BGP_STR
15351 "l2vpn address family\n"
15352 "evpn sub-address family\n"
15353 "Detailed info about dynamic update groups\n")
15354{
15355 char *vrf = NULL;
15356 uint64_t subgrp_id = 0;
15357
15358 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15359 return CMD_SUCCESS;
15360}
15361
5bf15956
DW
15362DEFUN (show_bgp_updgrps_stats,
15363 show_bgp_updgrps_stats_cmd,
716b2d8a 15364 "show [ip] bgp update-groups statistics",
3f9c7369 15365 SHOW_STR
716b2d8a 15366 IP_STR
3f9c7369 15367 BGP_STR
0c7b1b01 15368 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15369 "Statistics\n")
15370{
d62a17ae 15371 struct bgp *bgp;
3f9c7369 15372
d62a17ae 15373 bgp = bgp_get_default();
15374 if (bgp)
15375 update_group_show_stats(bgp, vty);
3f9c7369 15376
d62a17ae 15377 return CMD_SUCCESS;
3f9c7369
DS
15378}
15379
8386ac43 15380DEFUN (show_bgp_instance_updgrps_stats,
15381 show_bgp_instance_updgrps_stats_cmd,
18c57037 15382 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15383 SHOW_STR
716b2d8a 15384 IP_STR
8386ac43 15385 BGP_STR
15386 BGP_INSTANCE_HELP_STR
0c7b1b01 15387 "Detailed info about dynamic update groups\n"
8386ac43 15388 "Statistics\n")
15389{
d62a17ae 15390 int idx_word = 3;
15391 struct bgp *bgp;
8386ac43 15392
d62a17ae 15393 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15394 if (bgp)
15395 update_group_show_stats(bgp, vty);
8386ac43 15396
d62a17ae 15397 return CMD_SUCCESS;
8386ac43 15398}
15399
d62a17ae 15400static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15401 afi_t afi, safi_t safi,
15402 const char *what, uint64_t subgrp_id)
3f9c7369 15403{
d62a17ae 15404 struct bgp *bgp;
8386ac43 15405
d62a17ae 15406 if (name)
15407 bgp = bgp_lookup_by_name(name);
15408 else
15409 bgp = bgp_get_default();
8386ac43 15410
d62a17ae 15411 if (bgp) {
15412 if (!strcmp(what, "advertise-queue"))
15413 update_group_show_adj_queue(bgp, afi, safi, vty,
15414 subgrp_id);
15415 else if (!strcmp(what, "advertised-routes"))
15416 update_group_show_advertised(bgp, afi, safi, vty,
15417 subgrp_id);
15418 else if (!strcmp(what, "packet-queue"))
15419 update_group_show_packet_queue(bgp, afi, safi, vty,
15420 subgrp_id);
15421 }
3f9c7369
DS
15422}
15423
dc64bdec
QY
15424DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15425 show_ip_bgp_instance_updgrps_adj_s_cmd,
15426 "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",
15427 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15428 BGP_SAFI_HELP_STR
15429 "Detailed info about dynamic update groups\n"
15430 "Specific subgroup to display info for\n"
15431 "Advertisement queue\n"
15432 "Announced routes\n"
15433 "Packet queue\n")
3f9c7369 15434{
dc64bdec
QY
15435 uint64_t subgrp_id = 0;
15436 afi_t afiz;
15437 safi_t safiz;
15438 if (sgid)
15439 subgrp_id = strtoull(sgid, NULL, 10);
15440
15441 if (!ip && !afi)
15442 afiz = AFI_IP6;
15443 if (!ip && afi)
15444 afiz = bgp_vty_afi_from_str(afi);
15445 if (ip && !afi)
15446 afiz = AFI_IP;
15447 if (ip && afi) {
15448 afiz = bgp_vty_afi_from_str(afi);
15449 if (afiz != AFI_IP)
15450 vty_out(vty,
15451 "%% Cannot specify both 'ip' and 'ipv6'\n");
15452 return CMD_WARNING;
15453 }
d62a17ae 15454
dc64bdec 15455 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15456
dc64bdec 15457 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15458 return CMD_SUCCESS;
15459}
15460
6f4eacf3
DA
15461static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15462 json_object *json)
d62a17ae 15463{
15464 struct listnode *node, *nnode;
15465 struct prefix *range;
15466 struct peer *conf;
15467 struct peer *peer;
d62a17ae 15468 afi_t afi;
15469 safi_t safi;
15470 const char *peer_status;
d62a17ae 15471 int lr_count;
15472 int dynamic;
6f4eacf3
DA
15473 bool af_cfgd;
15474 json_object *json_peer_group = NULL;
15475 json_object *json_peer_group_afc = NULL;
15476 json_object *json_peer_group_members = NULL;
15477 json_object *json_peer_group_dynamic = NULL;
15478 json_object *json_peer_group_dynamic_af = NULL;
15479 json_object *json_peer_group_ranges = NULL;
d62a17ae 15480
15481 conf = group->conf;
15482
6f4eacf3
DA
15483 if (json) {
15484 json_peer_group = json_object_new_object();
15485 json_peer_group_afc = json_object_new_array();
15486 }
15487
d62a17ae 15488 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15489 if (json)
15490 json_object_int_add(json_peer_group, "remoteAs",
15491 conf->as);
15492 else
15493 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15494 group->name, conf->as);
d62a17ae 15495 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15496 if (json)
15497 json_object_int_add(json_peer_group, "remoteAs",
15498 group->bgp->as);
15499 else
15500 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15501 group->name, group->bgp->as);
d62a17ae 15502 } else {
6f4eacf3
DA
15503 if (!json)
15504 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15505 }
f14e6fdb 15506
6f4eacf3
DA
15507 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15508 if (json)
15509 json_object_string_add(json_peer_group, "type",
15510 "internal");
15511 else
15512 vty_out(vty, " Peer-group type is internal\n");
15513 } else {
15514 if (json)
15515 json_object_string_add(json_peer_group, "type",
15516 "external");
15517 else
15518 vty_out(vty, " Peer-group type is external\n");
15519 }
d62a17ae 15520
15521 /* Display AFs configured. */
6f4eacf3
DA
15522 if (!json)
15523 vty_out(vty, " Configured address-families:");
15524
05c7a1cc
QY
15525 FOREACH_AFI_SAFI (afi, safi) {
15526 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15527 af_cfgd = true;
15528 if (json)
15529 json_object_array_add(
15530 json_peer_group_afc,
15531 json_object_new_string(get_afi_safi_str(
15532 afi, safi, false)));
15533 else
15534 vty_out(vty, " %s;",
15535 get_afi_safi_str(afi, safi, false));
d62a17ae 15536 }
05c7a1cc 15537 }
6f4eacf3
DA
15538
15539 if (json) {
15540 json_object_object_add(json_peer_group,
15541 "addressFamiliesConfigured",
15542 json_peer_group_afc);
15543 } else {
15544 if (!af_cfgd)
15545 vty_out(vty, " none\n");
15546 else
15547 vty_out(vty, "\n");
15548 }
d62a17ae 15549
15550 /* Display listen ranges (for dynamic neighbors), if any */
15551 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15552 lr_count = listcount(group->listen_range[afi]);
15553 if (lr_count) {
6f4eacf3
DA
15554 if (json) {
15555 if (!json_peer_group_dynamic)
15556 json_peer_group_dynamic =
15557 json_object_new_object();
15558
15559 json_peer_group_dynamic_af =
15560 json_object_new_object();
15561 json_peer_group_ranges =
15562 json_object_new_array();
15563 json_object_int_add(json_peer_group_dynamic_af,
15564 "count", lr_count);
15565 } else {
15566 vty_out(vty, " %d %s listen range(s)\n",
15567 lr_count, afi2str(afi));
15568 }
d62a17ae 15569
15570 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15571 nnode, range)) {
15572 if (json) {
15573 char buf[BUFSIZ];
15574
15575 snprintfrr(buf, sizeof(buf), "%pFX",
15576 range);
15577
15578 json_object_array_add(
15579 json_peer_group_ranges,
15580 json_object_new_string(buf));
15581 } else {
15582 vty_out(vty, " %pFX\n", range);
15583 }
15584 }
15585
15586 if (json) {
15587 json_object_object_add(
15588 json_peer_group_dynamic_af, "ranges",
15589 json_peer_group_ranges);
15590
15591 json_object_object_add(
15592 json_peer_group_dynamic, afi2str(afi),
15593 json_peer_group_dynamic_af);
15594 }
d62a17ae 15595 }
15596 }
f14e6fdb 15597
6f4eacf3
DA
15598 if (json_peer_group_dynamic)
15599 json_object_object_add(json_peer_group, "dynamicRanges",
15600 json_peer_group_dynamic);
15601
d62a17ae 15602 /* Display group members and their status */
15603 if (listcount(group->peer)) {
6f4eacf3
DA
15604 if (json)
15605 json_peer_group_members = json_object_new_object();
15606 else
15607 vty_out(vty, " Peer-group members:\n");
d62a17ae 15608 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15609 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15610 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15611 peer_status = "Idle (Admin)";
15612 else if (CHECK_FLAG(peer->sflags,
15613 PEER_STATUS_PREFIX_OVERFLOW))
15614 peer_status = "Idle (PfxCt)";
15615 else
15616 peer_status = lookup_msg(bgp_status_msg,
15617 peer->status, NULL);
15618
15619 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15620
15621 if (json) {
15622 json_object *json_peer_group_member =
15623 json_object_new_object();
15624
15625 json_object_string_add(json_peer_group_member,
15626 "status", peer_status);
15627
15628 if (dynamic)
15629 json_object_boolean_true_add(
15630 json_peer_group_member,
15631 "dynamic");
15632
15633 json_object_object_add(json_peer_group_members,
15634 peer->host,
15635 json_peer_group_member);
15636 } else {
15637 vty_out(vty, " %s %s %s \n", peer->host,
15638 dynamic ? "(dynamic)" : "",
15639 peer_status);
15640 }
d62a17ae 15641 }
6f4eacf3
DA
15642 if (json)
15643 json_object_object_add(json_peer_group, "members",
15644 json_peer_group_members);
d62a17ae 15645 }
f14e6fdb 15646
6f4eacf3
DA
15647 if (json)
15648 json_object_object_add(json, group->name, json_peer_group);
15649
d62a17ae 15650 return CMD_SUCCESS;
15651}
15652
ff9959b0 15653static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15654 const char *group_name, bool uj)
d62a17ae 15655{
ff9959b0 15656 struct bgp *bgp;
d62a17ae 15657 struct listnode *node, *nnode;
15658 struct peer_group *group;
ff9959b0 15659 bool found = false;
6f4eacf3
DA
15660 json_object *json = NULL;
15661
15662 if (uj)
15663 json = json_object_new_object();
ff9959b0
QY
15664
15665 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15666
15667 if (!bgp) {
c48349e3 15668 if (uj)
75eeda93 15669 vty_json(vty, json);
c48349e3 15670 else
6f4eacf3 15671 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15672
ff9959b0
QY
15673 return CMD_WARNING;
15674 }
d62a17ae 15675
15676 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15677 if (group_name) {
15678 if (strmatch(group->name, group_name)) {
6f4eacf3 15679 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15680 found = true;
15681 break;
d62a17ae 15682 }
ff9959b0 15683 } else {
6f4eacf3 15684 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15685 }
f14e6fdb 15686 }
f14e6fdb 15687
6f4eacf3 15688 if (group_name && !found && !uj)
d62a17ae 15689 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15690
c48349e3 15691 if (uj)
75eeda93 15692 vty_json(vty, json);
6f4eacf3 15693
d62a17ae 15694 return CMD_SUCCESS;
f14e6fdb
DS
15695}
15696
6f4eacf3
DA
15697DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15698 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15699 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15700 "Detailed information on BGP peer groups\n"
15701 "Peer group name\n" JSON_STR)
f14e6fdb 15702{
d62a17ae 15703 char *vrf, *pg;
d62a17ae 15704 int idx = 0;
6f4eacf3 15705 bool uj = use_json(argc, argv);
f14e6fdb 15706
a4d82a8a
PZ
15707 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15708 : NULL;
d62a17ae 15709 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15710
6f4eacf3 15711 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15712}
3f9c7369 15713
d6e3c605 15714
718e3744 15715/* Redistribute VTY commands. */
15716
585f1adc
IR
15717DEFUN (bgp_redistribute_ipv4,
15718 bgp_redistribute_ipv4_cmd,
15719 "redistribute " FRR_IP_REDIST_STR_BGPD,
15720 "Redistribute information from another routing protocol\n"
15721 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15722{
585f1adc 15723 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15724 int idx_protocol = 1;
585f1adc 15725 int type;
37a87b8f 15726
585f1adc
IR
15727 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15728 if (type < 0) {
15729 vty_out(vty, "%% Invalid route type\n");
15730 return CMD_WARNING_CONFIG_FAILED;
15731 }
7f323236 15732
585f1adc
IR
15733 bgp_redist_add(bgp, AFI_IP, type, 0);
15734 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15735}
15736
d62a17ae 15737ALIAS_HIDDEN(
15738 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15739 "redistribute " FRR_IP_REDIST_STR_BGPD,
15740 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15741
585f1adc
IR
15742DEFUN (bgp_redistribute_ipv4_rmap,
15743 bgp_redistribute_ipv4_rmap_cmd,
70dd370f 15744 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
15745 "Redistribute information from another routing protocol\n"
15746 FRR_IP_REDIST_HELP_STR_BGPD
15747 "Route map reference\n"
15748 "Pointer to route-map entries\n")
718e3744 15749{
585f1adc 15750 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15751 int idx_protocol = 1;
15752 int idx_word = 3;
585f1adc
IR
15753 int type;
15754 struct bgp_redist *red;
15755 bool changed;
15756 struct route_map *route_map = route_map_lookup_warn_noexist(
15757 vty, argv[idx_word]->arg);
15758
15759 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15760 if (type < 0) {
15761 vty_out(vty, "%% Invalid route type\n");
15762 return CMD_WARNING_CONFIG_FAILED;
15763 }
37a87b8f 15764
585f1adc
IR
15765 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15766 changed =
15767 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15768 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15769}
15770
d62a17ae 15771ALIAS_HIDDEN(
15772 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
70dd370f 15773 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME",
d62a17ae 15774 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15775 "Route map reference\n"
15776 "Pointer to route-map entries\n")
596c17ba 15777
585f1adc
IR
15778DEFUN (bgp_redistribute_ipv4_metric,
15779 bgp_redistribute_ipv4_metric_cmd,
15780 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15781 "Redistribute information from another routing protocol\n"
15782 FRR_IP_REDIST_HELP_STR_BGPD
15783 "Metric for redistributed routes\n"
15784 "Default metric\n")
718e3744 15785{
585f1adc 15786 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15787 int idx_protocol = 1;
15788 int idx_number = 3;
585f1adc
IR
15789 int type;
15790 uint32_t metric;
15791 struct bgp_redist *red;
15792 bool changed;
15793
15794 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15795 if (type < 0) {
15796 vty_out(vty, "%% Invalid route type\n");
15797 return CMD_WARNING_CONFIG_FAILED;
15798 }
15799 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15800
585f1adc
IR
15801 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15802 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15803 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15804}
15805
15806ALIAS_HIDDEN(
15807 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15808 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15809 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15810 "Metric for redistributed routes\n"
15811 "Default metric\n")
596c17ba 15812
585f1adc
IR
15813DEFUN (bgp_redistribute_ipv4_rmap_metric,
15814 bgp_redistribute_ipv4_rmap_metric_cmd,
70dd370f 15815 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
15816 "Redistribute information from another routing protocol\n"
15817 FRR_IP_REDIST_HELP_STR_BGPD
15818 "Route map reference\n"
15819 "Pointer to route-map entries\n"
15820 "Metric for redistributed routes\n"
15821 "Default metric\n")
718e3744 15822{
585f1adc 15823 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15824 int idx_protocol = 1;
15825 int idx_word = 3;
15826 int idx_number = 5;
585f1adc
IR
15827 int type;
15828 uint32_t metric;
15829 struct bgp_redist *red;
15830 bool changed;
15831 struct route_map *route_map =
15832 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15833
15834 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15835 if (type < 0) {
15836 vty_out(vty, "%% Invalid route type\n");
15837 return CMD_WARNING_CONFIG_FAILED;
15838 }
15839 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15840
585f1adc
IR
15841 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15842 changed =
15843 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15844 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15845 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15846}
15847
15848ALIAS_HIDDEN(
15849 bgp_redistribute_ipv4_rmap_metric,
15850 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15851 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 15852 " route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 15853 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15854 "Route map reference\n"
15855 "Pointer to route-map entries\n"
15856 "Metric for redistributed routes\n"
15857 "Default metric\n")
596c17ba 15858
585f1adc
IR
15859DEFUN (bgp_redistribute_ipv4_metric_rmap,
15860 bgp_redistribute_ipv4_metric_rmap_cmd,
70dd370f 15861 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
15862 "Redistribute information from another routing protocol\n"
15863 FRR_IP_REDIST_HELP_STR_BGPD
15864 "Metric for redistributed routes\n"
15865 "Default metric\n"
15866 "Route map reference\n"
15867 "Pointer to route-map entries\n")
718e3744 15868{
585f1adc 15869 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15870 int idx_protocol = 1;
37a87b8f 15871 int idx_number = 3;
585f1adc
IR
15872 int idx_word = 5;
15873 int type;
15874 uint32_t metric;
15875 struct bgp_redist *red;
15876 bool changed;
15877 struct route_map *route_map =
15878 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15879
15880 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15881 if (type < 0) {
15882 vty_out(vty, "%% Invalid route type\n");
15883 return CMD_WARNING_CONFIG_FAILED;
15884 }
15885 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15886
585f1adc
IR
15887 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15888 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15889 changed |=
15890 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15891 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15892}
15893
15894ALIAS_HIDDEN(
15895 bgp_redistribute_ipv4_metric_rmap,
15896 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15897 "redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 15898 " metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 15899 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15900 "Metric for redistributed routes\n"
15901 "Default metric\n"
15902 "Route map reference\n"
15903 "Pointer to route-map entries\n")
596c17ba 15904
585f1adc
IR
15905DEFUN (bgp_redistribute_ipv4_ospf,
15906 bgp_redistribute_ipv4_ospf_cmd,
15907 "redistribute <ospf|table> (1-65535)",
15908 "Redistribute information from another routing protocol\n"
15909 "Open Shortest Path First (OSPFv2)\n"
15910 "Non-main Kernel Routing Table\n"
15911 "Instance ID/Table ID\n")
7c8ff89e 15912{
585f1adc
IR
15913 VTY_DECLVAR_CONTEXT(bgp, bgp);
15914 int idx_ospf_table = 1;
d62a17ae 15915 int idx_number = 2;
585f1adc
IR
15916 unsigned short instance;
15917 unsigned short protocol;
7c8ff89e 15918
585f1adc 15919 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15920
585f1adc
IR
15921 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15922 protocol = ZEBRA_ROUTE_OSPF;
15923 else
15924 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15925
585f1adc
IR
15926 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15927 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15928}
15929
d62a17ae 15930ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15931 "redistribute <ospf|table> (1-65535)",
15932 "Redistribute information from another routing protocol\n"
15933 "Open Shortest Path First (OSPFv2)\n"
15934 "Non-main Kernel Routing Table\n"
15935 "Instance ID/Table ID\n")
596c17ba 15936
585f1adc
IR
15937DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15938 bgp_redistribute_ipv4_ospf_rmap_cmd,
70dd370f 15939 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
585f1adc
IR
15940 "Redistribute information from another routing protocol\n"
15941 "Open Shortest Path First (OSPFv2)\n"
15942 "Non-main Kernel Routing Table\n"
15943 "Instance ID/Table ID\n"
15944 "Route map reference\n"
15945 "Pointer to route-map entries\n")
7c8ff89e 15946{
585f1adc
IR
15947 VTY_DECLVAR_CONTEXT(bgp, bgp);
15948 int idx_ospf_table = 1;
d62a17ae 15949 int idx_number = 2;
15950 int idx_word = 4;
585f1adc
IR
15951 struct bgp_redist *red;
15952 unsigned short instance;
15953 int protocol;
15954 bool changed;
15955 struct route_map *route_map =
15956 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15957
15958 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15959 protocol = ZEBRA_ROUTE_OSPF;
15960 else
15961 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15962
585f1adc
IR
15963 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15964 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15965 changed =
15966 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15967 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15968}
15969
15970ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15971 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
70dd370f 15972 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
d62a17ae 15973 "Redistribute information from another routing protocol\n"
15974 "Open Shortest Path First (OSPFv2)\n"
15975 "Non-main Kernel Routing Table\n"
15976 "Instance ID/Table ID\n"
15977 "Route map reference\n"
15978 "Pointer to route-map entries\n")
596c17ba 15979
585f1adc
IR
15980DEFUN (bgp_redistribute_ipv4_ospf_metric,
15981 bgp_redistribute_ipv4_ospf_metric_cmd,
15982 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15983 "Redistribute information from another routing protocol\n"
15984 "Open Shortest Path First (OSPFv2)\n"
15985 "Non-main Kernel Routing Table\n"
15986 "Instance ID/Table ID\n"
15987 "Metric for redistributed routes\n"
15988 "Default metric\n")
7c8ff89e 15989{
585f1adc
IR
15990 VTY_DECLVAR_CONTEXT(bgp, bgp);
15991 int idx_ospf_table = 1;
d62a17ae 15992 int idx_number = 2;
15993 int idx_number_2 = 4;
585f1adc
IR
15994 uint32_t metric;
15995 struct bgp_redist *red;
15996 unsigned short instance;
15997 int protocol;
15998 bool changed;
15999
16000 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16001 protocol = ZEBRA_ROUTE_OSPF;
16002 else
16003 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16004
585f1adc
IR
16005 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16006 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16007
585f1adc
IR
16008 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16009 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16010 metric);
16011 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16012}
16013
16014ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16015 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16016 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16017 "Redistribute information from another routing protocol\n"
16018 "Open Shortest Path First (OSPFv2)\n"
16019 "Non-main Kernel Routing Table\n"
16020 "Instance ID/Table ID\n"
16021 "Metric for redistributed routes\n"
16022 "Default metric\n")
596c17ba 16023
585f1adc
IR
16024DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
16025 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
70dd370f 16026 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16027 "Redistribute information from another routing protocol\n"
16028 "Open Shortest Path First (OSPFv2)\n"
16029 "Non-main Kernel Routing Table\n"
16030 "Instance ID/Table ID\n"
16031 "Route map reference\n"
16032 "Pointer to route-map entries\n"
16033 "Metric for redistributed routes\n"
16034 "Default metric\n")
7c8ff89e 16035{
585f1adc
IR
16036 VTY_DECLVAR_CONTEXT(bgp, bgp);
16037 int idx_ospf_table = 1;
d62a17ae 16038 int idx_number = 2;
16039 int idx_word = 4;
16040 int idx_number_2 = 6;
585f1adc
IR
16041 uint32_t metric;
16042 struct bgp_redist *red;
16043 unsigned short instance;
16044 int protocol;
16045 bool changed;
16046 struct route_map *route_map =
16047 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16048
16049 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16050 protocol = ZEBRA_ROUTE_OSPF;
16051 else
16052 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16053
585f1adc
IR
16054 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16055 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16056
585f1adc
IR
16057 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16058 changed =
16059 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16060 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16061 metric);
16062 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16063}
16064
16065ALIAS_HIDDEN(
16066 bgp_redistribute_ipv4_ospf_rmap_metric,
16067 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
70dd370f 16068 "redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
d62a17ae 16069 "Redistribute information from another routing protocol\n"
16070 "Open Shortest Path First (OSPFv2)\n"
16071 "Non-main Kernel Routing Table\n"
16072 "Instance ID/Table ID\n"
16073 "Route map reference\n"
16074 "Pointer to route-map entries\n"
16075 "Metric for redistributed routes\n"
16076 "Default metric\n")
596c17ba 16077
585f1adc
IR
16078DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
16079 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
70dd370f 16080 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16081 "Redistribute information from another routing protocol\n"
16082 "Open Shortest Path First (OSPFv2)\n"
16083 "Non-main Kernel Routing Table\n"
16084 "Instance ID/Table ID\n"
16085 "Metric for redistributed routes\n"
16086 "Default metric\n"
16087 "Route map reference\n"
16088 "Pointer to route-map entries\n")
7c8ff89e 16089{
585f1adc
IR
16090 VTY_DECLVAR_CONTEXT(bgp, bgp);
16091 int idx_ospf_table = 1;
d62a17ae 16092 int idx_number = 2;
16093 int idx_number_2 = 4;
16094 int idx_word = 6;
585f1adc
IR
16095 uint32_t metric;
16096 struct bgp_redist *red;
16097 unsigned short instance;
16098 int protocol;
16099 bool changed;
16100 struct route_map *route_map =
16101 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16102
16103 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16104 protocol = ZEBRA_ROUTE_OSPF;
16105 else
16106 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16107
585f1adc
IR
16108 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16109 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 16110
585f1adc
IR
16111 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
16112 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
16113 metric);
16114 changed |=
16115 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16116 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 16117}
16118
16119ALIAS_HIDDEN(
16120 bgp_redistribute_ipv4_ospf_metric_rmap,
16121 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
70dd370f 16122 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
d62a17ae 16123 "Redistribute information from another routing protocol\n"
16124 "Open Shortest Path First (OSPFv2)\n"
16125 "Non-main Kernel Routing Table\n"
16126 "Instance ID/Table ID\n"
16127 "Metric for redistributed routes\n"
16128 "Default metric\n"
16129 "Route map reference\n"
16130 "Pointer to route-map entries\n")
596c17ba 16131
585f1adc
IR
16132DEFUN (no_bgp_redistribute_ipv4_ospf,
16133 no_bgp_redistribute_ipv4_ospf_cmd,
70dd370f 16134 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16135 NO_STR
16136 "Redistribute information from another routing protocol\n"
16137 "Open Shortest Path First (OSPFv2)\n"
16138 "Non-main Kernel Routing Table\n"
16139 "Instance ID/Table ID\n"
16140 "Metric for redistributed routes\n"
16141 "Default metric\n"
16142 "Route map reference\n"
16143 "Pointer to route-map entries\n")
7c8ff89e 16144{
585f1adc
IR
16145 VTY_DECLVAR_CONTEXT(bgp, bgp);
16146 int idx_ospf_table = 2;
d62a17ae 16147 int idx_number = 3;
585f1adc
IR
16148 unsigned short instance;
16149 int protocol;
37a87b8f 16150
585f1adc
IR
16151 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
16152 protocol = ZEBRA_ROUTE_OSPF;
16153 else
16154 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 16155
585f1adc
IR
16156 instance = strtoul(argv[idx_number]->arg, NULL, 10);
16157 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 16158}
16159
16160ALIAS_HIDDEN(
16161 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
70dd370f 16162 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16163 NO_STR
16164 "Redistribute information from another routing protocol\n"
16165 "Open Shortest Path First (OSPFv2)\n"
16166 "Non-main Kernel Routing Table\n"
16167 "Instance ID/Table ID\n"
16168 "Metric for redistributed routes\n"
16169 "Default metric\n"
16170 "Route map reference\n"
16171 "Pointer to route-map entries\n")
596c17ba 16172
585f1adc
IR
16173DEFUN (no_bgp_redistribute_ipv4,
16174 no_bgp_redistribute_ipv4_cmd,
70dd370f 16175 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16176 NO_STR
16177 "Redistribute information from another routing protocol\n"
16178 FRR_IP_REDIST_HELP_STR_BGPD
16179 "Metric for redistributed routes\n"
16180 "Default metric\n"
16181 "Route map reference\n"
16182 "Pointer to route-map entries\n")
718e3744 16183{
585f1adc 16184 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16185 int idx_protocol = 2;
585f1adc 16186 int type;
d62a17ae 16187
585f1adc
IR
16188 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
16189 if (type < 0) {
16190 vty_out(vty, "%% Invalid route type\n");
16191 return CMD_WARNING_CONFIG_FAILED;
16192 }
16193 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 16194}
16195
16196ALIAS_HIDDEN(
16197 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16198 "no redistribute " FRR_IP_REDIST_STR_BGPD
70dd370f 16199 " [{metric (0-4294967295)|route-map RMAP_NAME}]",
d62a17ae 16200 NO_STR
16201 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16202 "Metric for redistributed routes\n"
16203 "Default metric\n"
16204 "Route map reference\n"
16205 "Pointer to route-map entries\n")
596c17ba 16206
585f1adc
IR
16207DEFUN (bgp_redistribute_ipv6,
16208 bgp_redistribute_ipv6_cmd,
16209 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16210 "Redistribute information from another routing protocol\n"
16211 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16212{
585f1adc 16213 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16214 int idx_protocol = 1;
585f1adc 16215 int type;
718e3744 16216
585f1adc
IR
16217 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16218 if (type < 0) {
16219 vty_out(vty, "%% Invalid route type\n");
16220 return CMD_WARNING_CONFIG_FAILED;
16221 }
718e3744 16222
585f1adc
IR
16223 bgp_redist_add(bgp, AFI_IP6, type, 0);
16224 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 16225}
16226
585f1adc
IR
16227DEFUN (bgp_redistribute_ipv6_rmap,
16228 bgp_redistribute_ipv6_rmap_cmd,
70dd370f 16229 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME",
585f1adc
IR
16230 "Redistribute information from another routing protocol\n"
16231 FRR_IP6_REDIST_HELP_STR_BGPD
16232 "Route map reference\n"
16233 "Pointer to route-map entries\n")
718e3744 16234{
585f1adc 16235 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16236 int idx_protocol = 1;
16237 int idx_word = 3;
585f1adc
IR
16238 int type;
16239 struct bgp_redist *red;
16240 bool changed;
16241 struct route_map *route_map =
16242 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16243
16244 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16245 if (type < 0) {
16246 vty_out(vty, "%% Invalid route type\n");
16247 return CMD_WARNING_CONFIG_FAILED;
16248 }
37a87b8f 16249
585f1adc
IR
16250 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16251 changed =
16252 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16253 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16254}
16255
585f1adc 16256DEFUN (bgp_redistribute_ipv6_metric,
718e3744 16257 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16258 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16259 "Redistribute information from another routing protocol\n"
ab0181ee 16260 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16261 "Metric for redistributed routes\n"
16262 "Default metric\n")
16263{
585f1adc 16264 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16265 int idx_protocol = 1;
16266 int idx_number = 3;
585f1adc
IR
16267 int type;
16268 uint32_t metric;
16269 struct bgp_redist *red;
16270 bool changed;
16271
16272 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16273 if (type < 0) {
16274 vty_out(vty, "%% Invalid route type\n");
16275 return CMD_WARNING_CONFIG_FAILED;
16276 }
16277 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16278
585f1adc
IR
16279 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16280 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
16281 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16282}
16283
585f1adc
IR
16284DEFUN (bgp_redistribute_ipv6_rmap_metric,
16285 bgp_redistribute_ipv6_rmap_metric_cmd,
70dd370f 16286 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map RMAP_NAME metric (0-4294967295)",
585f1adc
IR
16287 "Redistribute information from another routing protocol\n"
16288 FRR_IP6_REDIST_HELP_STR_BGPD
16289 "Route map reference\n"
16290 "Pointer to route-map entries\n"
16291 "Metric for redistributed routes\n"
16292 "Default metric\n")
718e3744 16293{
585f1adc 16294 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16295 int idx_protocol = 1;
16296 int idx_word = 3;
16297 int idx_number = 5;
585f1adc
IR
16298 int type;
16299 uint32_t metric;
16300 struct bgp_redist *red;
16301 bool changed;
16302 struct route_map *route_map =
16303 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16304
16305 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16306 if (type < 0) {
16307 vty_out(vty, "%% Invalid route type\n");
16308 return CMD_WARNING_CONFIG_FAILED;
16309 }
16310 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16311
585f1adc
IR
16312 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16313 changed =
16314 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16315 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16316 metric);
16317 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16318}
16319
585f1adc
IR
16320DEFUN (bgp_redistribute_ipv6_metric_rmap,
16321 bgp_redistribute_ipv6_metric_rmap_cmd,
70dd370f 16322 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map RMAP_NAME",
585f1adc
IR
16323 "Redistribute information from another routing protocol\n"
16324 FRR_IP6_REDIST_HELP_STR_BGPD
16325 "Metric for redistributed routes\n"
16326 "Default metric\n"
16327 "Route map reference\n"
16328 "Pointer to route-map entries\n")
718e3744 16329{
585f1adc 16330 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16331 int idx_protocol = 1;
37a87b8f 16332 int idx_number = 3;
585f1adc
IR
16333 int idx_word = 5;
16334 int type;
16335 uint32_t metric;
16336 struct bgp_redist *red;
16337 bool changed;
16338 struct route_map *route_map =
16339 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16340
16341 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16342 if (type < 0) {
16343 vty_out(vty, "%% Invalid route type\n");
16344 return CMD_WARNING_CONFIG_FAILED;
16345 }
16346 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16347
585f1adc
IR
16348 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16349 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16350 metric);
16351 changed |=
16352 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16353 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16354}
16355
585f1adc
IR
16356DEFUN (no_bgp_redistribute_ipv6,
16357 no_bgp_redistribute_ipv6_cmd,
70dd370f 16358 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map RMAP_NAME}]",
585f1adc
IR
16359 NO_STR
16360 "Redistribute information from another routing protocol\n"
16361 FRR_IP6_REDIST_HELP_STR_BGPD
16362 "Metric for redistributed routes\n"
16363 "Default metric\n"
16364 "Route map reference\n"
16365 "Pointer to route-map entries\n")
718e3744 16366{
585f1adc 16367 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16368 int idx_protocol = 2;
585f1adc 16369 int type;
37a87b8f 16370
585f1adc
IR
16371 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16372 if (type < 0) {
16373 vty_out(vty, "%% Invalid route type\n");
16374 return CMD_WARNING_CONFIG_FAILED;
16375 }
718e3744 16376
585f1adc 16377 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16378}
16379
4ab46701
AR
16380/* Neighbor update tcp-mss. */
16381static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16382 const char *tcp_mss_str)
16383{
16384 struct peer *peer;
16385 uint32_t tcp_mss_val = 0;
16386
16387 peer = peer_and_group_lookup_vty(vty, peer_str);
16388 if (!peer)
16389 return CMD_WARNING_CONFIG_FAILED;
16390
16391 if (tcp_mss_str) {
16392 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16393 peer_tcp_mss_set(peer, tcp_mss_val);
16394 } else {
16395 peer_tcp_mss_unset(peer);
16396 }
16397
16398 return CMD_SUCCESS;
16399}
16400
16401DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16402 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16404 "TCP max segment size\n"
16405 "TCP MSS value\n")
16406{
16407 int peer_index = 1;
16408 int mss_index = 3;
16409
16410 vty_out(vty,
16411 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16412 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16413 argv[mss_index]->arg);
16414}
16415
16416DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16417 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16418 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16419 "TCP max segment size\n"
16420 "TCP MSS value\n")
16421{
16422 int peer_index = 2;
16423
16424 vty_out(vty,
16425 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16426 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16427}
16428
a486300b
PG
16429DEFPY(bgp_retain_route_target, bgp_retain_route_target_cmd,
16430 "[no$no] bgp retain route-target all",
16431 NO_STR BGP_STR
16432 "Retain BGP updates\n"
16433 "Retain BGP updates based on route-target values\n"
16434 "Retain all BGP updates\n")
16435{
16436 bool check;
16437 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
16438
16439 check = CHECK_FLAG(bgp->af_flags[bgp_node_afi(vty)][bgp_node_safi(vty)],
16440 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16441 if (check != !no) {
16442 if (!no)
16443 SET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16444 [bgp_node_safi(vty)],
16445 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16446 else
16447 UNSET_FLAG(bgp->af_flags[bgp_node_afi(vty)]
16448 [bgp_node_safi(vty)],
16449 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL);
16450 /* trigger a flush to re-sync with ADJ-RIB-in */
16451 bgp_clear(vty, bgp, bgp_node_afi(vty), bgp_node_safi(vty),
16452 clear_all, BGP_CLEAR_SOFT_IN, NULL);
16453 }
16454 return CMD_SUCCESS;
16455}
16456
dd65f45e
DL
16457static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16458 afi_t afi, safi_t safi)
d62a17ae 16459{
16460 int i;
16461
16462 /* Unicast redistribution only. */
16463 if (safi != SAFI_UNICAST)
2b791107 16464 return;
d62a17ae 16465
16466 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16467 /* Redistribute BGP does not make sense. */
16468 if (i != ZEBRA_ROUTE_BGP) {
16469 struct list *red_list;
16470 struct listnode *node;
16471 struct bgp_redist *red;
16472
16473 red_list = bgp->redist[afi][i];
16474 if (!red_list)
16475 continue;
16476
16477 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16478 /* "redistribute" configuration. */
16479 vty_out(vty, " redistribute %s",
16480 zebra_route_string(i));
16481 if (red->instance)
16482 vty_out(vty, " %d", red->instance);
16483 if (red->redist_metric_flag)
16484 vty_out(vty, " metric %u",
16485 red->redist_metric);
16486 if (red->rmap.name)
16487 vty_out(vty, " route-map %s",
16488 red->rmap.name);
16489 vty_out(vty, "\n");
16490 }
16491 }
16492 }
718e3744 16493}
6b0655a2 16494
dd65f45e
DL
16495/* peer-group helpers for config-write */
16496
83194f39 16497static bool peergroup_flag_check(struct peer *peer, uint64_t flag)
dd65f45e
DL
16498{
16499 if (!peer_group_active(peer)) {
16500 if (CHECK_FLAG(peer->flags_invert, flag))
16501 return !CHECK_FLAG(peer->flags, flag);
16502 else
16503 return !!CHECK_FLAG(peer->flags, flag);
16504 }
16505
16506 return !!CHECK_FLAG(peer->flags_override, flag);
16507}
16508
16509static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16510 uint32_t flag)
16511{
16512 if (!peer_group_active(peer)) {
16513 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16514 return !peer_af_flag_check(peer, afi, safi, flag);
16515 else
16516 return !!peer_af_flag_check(peer, afi, safi, flag);
16517 }
16518
16519 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16520}
16521
16522static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16523 uint8_t type, int direct)
16524{
16525 struct bgp_filter *filter;
16526
16527 if (peer_group_active(peer))
16528 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16529 type);
16530
16531 filter = &peer->filter[afi][safi];
16532 switch (type) {
16533 case PEER_FT_DISTRIBUTE_LIST:
16534 return !!(filter->dlist[direct].name);
16535 case PEER_FT_FILTER_LIST:
16536 return !!(filter->aslist[direct].name);
16537 case PEER_FT_PREFIX_LIST:
16538 return !!(filter->plist[direct].name);
16539 case PEER_FT_ROUTE_MAP:
16540 return !!(filter->map[direct].name);
16541 case PEER_FT_UNSUPPRESS_MAP:
16542 return !!(filter->usmap.name);
7f7940e6
MK
16543 case PEER_FT_ADVERTISE_MAP:
16544 return !!(filter->advmap.aname
16545 && ((filter->advmap.condition == direct)
16546 && filter->advmap.cname));
dd65f45e
DL
16547 default:
16548 return false;
16549 }
16550}
16551
16552/* Return true if the addpath type is set for peer and different from
16553 * peer-group.
16554 */
3dc339cd
DA
16555static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16556 safi_t safi)
dd65f45e
DL
16557{
16558 enum bgp_addpath_strat type, g_type;
16559
16560 type = peer->addpath_type[afi][safi];
16561
16562 if (type != BGP_ADDPATH_NONE) {
16563 if (peer_group_active(peer)) {
16564 g_type = peer->group->conf->addpath_type[afi][safi];
16565
16566 if (type != g_type)
3dc339cd 16567 return true;
dd65f45e 16568 else
3dc339cd 16569 return false;
dd65f45e
DL
16570 }
16571
3dc339cd 16572 return true;
dd65f45e
DL
16573 }
16574
3dc339cd 16575 return false;
dd65f45e
DL
16576}
16577
b9c7bc5a 16578/* This is part of the address-family block (unicast only) */
dd65f45e 16579static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16580 afi_t afi)
16581{
b9c7bc5a 16582 int indent = 2;
53970de3 16583 uint32_t tovpn_sid_index = 0;
ddb5b488 16584
8a066a70 16585 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16586 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16587 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16588 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16589 bgp->vpn_policy[afi]
bb4f6190 16590 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16591 else
16592 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16593 bgp->vpn_policy[afi]
16594 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16595 }
12a844a5
DS
16596 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16597 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16598 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16599 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16600 return;
16601
e70e9f8e
PZ
16602 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16603 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16604
16605 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16606
16607 } else {
16608 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16609 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16610 bgp->vpn_policy[afi].tovpn_label);
16611 }
ddb5b488 16612 }
53970de3
RS
16613
16614 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16615 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16616 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16617 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16618 } else if (tovpn_sid_index != 0) {
16619 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16620 tovpn_sid_index);
16621 }
16622
ddb5b488
PZ
16623 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16624 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16625 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16626 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16627 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16628 sizeof(buf)));
16629 }
16630 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16631 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16632
16633 char buf[PREFIX_STRLEN];
16634 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16635 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16636 sizeof(buf))) {
16637
b9c7bc5a
PZ
16638 vty_out(vty, "%*snexthop vpn export %s\n",
16639 indent, "", buf);
ddb5b488
PZ
16640 }
16641 }
16642 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16643 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16644 && ecommunity_cmp(
16645 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16646 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16647
16648 char *b = ecommunity_ecom2str(
16649 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16650 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16651 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16652 XFREE(MTYPE_ECOMMUNITY_STR, b);
16653 } else {
16654 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16655 char *b = ecommunity_ecom2str(
16656 bgp->vpn_policy[afi]
16657 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16658 ECOMMUNITY_FORMAT_ROUTE_MAP,
16659 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16660 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16661 XFREE(MTYPE_ECOMMUNITY_STR, b);
16662 }
16663 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16664 char *b = ecommunity_ecom2str(
16665 bgp->vpn_policy[afi]
16666 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16667 ECOMMUNITY_FORMAT_ROUTE_MAP,
16668 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16669 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16670 XFREE(MTYPE_ECOMMUNITY_STR, b);
16671 }
16672 }
bb4f6190
DS
16673
16674 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16675 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16676 bgp->vpn_policy[afi]
16677 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16678
301ad80a
PG
16679 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16680 char *b = ecommunity_ecom2str(
16681 bgp->vpn_policy[afi]
16682 .import_redirect_rtlist,
16683 ECOMMUNITY_FORMAT_ROUTE_MAP,
16684 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16685
9a659715
PG
16686 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16687 != ECOMMUNITY_SIZE)
c6423c31 16688 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16689 indent, "", b);
16690 else
16691 vty_out(vty, "%*srt redirect import %s\n",
16692 indent, "", b);
301ad80a
PG
16693 XFREE(MTYPE_ECOMMUNITY_STR, b);
16694 }
ddb5b488
PZ
16695}
16696
dd65f45e
DL
16697static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16698 afi_t afi, safi_t safi)
16699{
16700 struct bgp_filter *filter;
16701 char *addr;
16702
16703 addr = peer->host;
16704 filter = &peer->filter[afi][safi];
16705
16706 /* distribute-list. */
16707 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16708 FILTER_IN))
16709 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16710 filter->dlist[FILTER_IN].name);
16711
16712 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16713 FILTER_OUT))
16714 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16715 filter->dlist[FILTER_OUT].name);
16716
16717 /* prefix-list. */
16718 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16719 FILTER_IN))
16720 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16721 filter->plist[FILTER_IN].name);
16722
16723 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16724 FILTER_OUT))
16725 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16726 filter->plist[FILTER_OUT].name);
16727
16728 /* route-map. */
16729 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16730 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16731 filter->map[RMAP_IN].name);
16732
16733 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16734 RMAP_OUT))
16735 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16736 filter->map[RMAP_OUT].name);
16737
16738 /* unsuppress-map */
16739 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16740 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16741 filter->usmap.name);
16742
7f7940e6
MK
16743 /* advertise-map : always applied in OUT direction*/
16744 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16745 CONDITION_NON_EXIST))
16746 vty_out(vty,
16747 " neighbor %s advertise-map %s non-exist-map %s\n",
16748 addr, filter->advmap.aname, filter->advmap.cname);
16749
16750 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16751 CONDITION_EXIST))
16752 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16753 addr, filter->advmap.aname, filter->advmap.cname);
16754
dd65f45e
DL
16755 /* filter-list. */
16756 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16757 FILTER_IN))
16758 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16759 filter->aslist[FILTER_IN].name);
16760
16761 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16762 FILTER_OUT))
16763 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16764 filter->aslist[FILTER_OUT].name);
16765}
16766
16767/* BGP peer configuration display function. */
16768static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16769 struct peer *peer)
16770{
16771 struct peer *g_peer = NULL;
dd65f45e
DL
16772 char *addr;
16773 int if_pg_printed = false;
16774 int if_ras_printed = false;
16775
16776 /* Skip dynamic neighbors. */
16777 if (peer_dynamic_neighbor(peer))
16778 return;
16779
16780 if (peer->conf_if)
16781 addr = peer->conf_if;
16782 else
16783 addr = peer->host;
16784
16785 /************************************
16786 ****** Global to the neighbor ******
16787 ************************************/
16788 if (peer->conf_if) {
16789 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16790 vty_out(vty, " neighbor %s interface v6only", addr);
16791 else
16792 vty_out(vty, " neighbor %s interface", addr);
16793
16794 if (peer_group_active(peer)) {
16795 vty_out(vty, " peer-group %s", peer->group->name);
16796 if_pg_printed = true;
16797 } else if (peer->as_type == AS_SPECIFIED) {
16798 vty_out(vty, " remote-as %u", peer->as);
16799 if_ras_printed = true;
16800 } else if (peer->as_type == AS_INTERNAL) {
16801 vty_out(vty, " remote-as internal");
16802 if_ras_printed = true;
16803 } else if (peer->as_type == AS_EXTERNAL) {
16804 vty_out(vty, " remote-as external");
16805 if_ras_printed = true;
16806 }
16807
16808 vty_out(vty, "\n");
16809 }
16810
16811 /* remote-as and peer-group */
16812 /* peer is a member of a peer-group */
16813 if (peer_group_active(peer)) {
16814 g_peer = peer->group->conf;
16815
16816 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16817 if (peer->as_type == AS_SPECIFIED) {
16818 vty_out(vty, " neighbor %s remote-as %u\n",
16819 addr, peer->as);
16820 } else if (peer->as_type == AS_INTERNAL) {
16821 vty_out(vty,
16822 " neighbor %s remote-as internal\n",
16823 addr);
16824 } else if (peer->as_type == AS_EXTERNAL) {
16825 vty_out(vty,
16826 " neighbor %s remote-as external\n",
16827 addr);
16828 }
16829 }
16830
16831 /* For swpX peers we displayed the peer-group
16832 * via 'neighbor swpX interface peer-group PGNAME' */
16833 if (!if_pg_printed)
16834 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16835 peer->group->name);
16836 }
16837
16838 /* peer is NOT a member of a peer-group */
16839 else {
16840 /* peer is a peer-group, declare the peer-group */
16841 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16842 vty_out(vty, " neighbor %s peer-group\n", addr);
16843 }
16844
16845 if (!if_ras_printed) {
16846 if (peer->as_type == AS_SPECIFIED) {
16847 vty_out(vty, " neighbor %s remote-as %u\n",
16848 addr, peer->as);
16849 } else if (peer->as_type == AS_INTERNAL) {
16850 vty_out(vty,
16851 " neighbor %s remote-as internal\n",
16852 addr);
16853 } else if (peer->as_type == AS_EXTERNAL) {
16854 vty_out(vty,
16855 " neighbor %s remote-as external\n",
16856 addr);
16857 }
16858 }
16859 }
16860
16861 /* local-as */
16862 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16863 vty_out(vty, " neighbor %s local-as %u", addr,
16864 peer->change_local_as);
16865 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16866 vty_out(vty, " no-prepend");
16867 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16868 vty_out(vty, " replace-as");
16869 vty_out(vty, "\n");
16870 }
16871
16872 /* description */
16873 if (peer->desc) {
16874 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16875 }
16876
16877 /* shutdown */
16878 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16879 if (peer->tx_shutdown_message)
16880 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16881 peer->tx_shutdown_message);
16882 else
16883 vty_out(vty, " neighbor %s shutdown\n", addr);
16884 }
16885
8336c896
DA
16886 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16887 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16888 peer->rtt_expected, peer->rtt_keepalive_conf);
16889
dd65f45e 16890 /* bfd */
21bfce98
RZ
16891 if (peer->bfd_config)
16892 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16893
16894 /* password */
16895 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16896 vty_out(vty, " neighbor %s password %s\n", addr,
16897 peer->password);
16898
16899 /* neighbor solo */
16900 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16901 if (!peer_group_active(peer)) {
16902 vty_out(vty, " neighbor %s solo\n", addr);
16903 }
16904 }
16905
16906 /* BGP port */
16907 if (peer->port != BGP_PORT_DEFAULT) {
16908 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16909 }
16910
16911 /* Local interface name */
16912 if (peer->ifname) {
16913 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16914 }
16915
4ab46701
AR
16916 /* TCP max segment size */
16917 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16918 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16919
dd65f45e
DL
16920 /* passive */
16921 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16922 vty_out(vty, " neighbor %s passive\n", addr);
16923
16924 /* ebgp-multihop */
16925 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16926 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16927 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16928 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16929 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16930 peer->ttl);
16931 }
16932 }
16933
d864dd9e 16934 /* role */
7dddd1f7
DA
16935 if (peergroup_flag_check(peer, PEER_FLAG_ROLE) &&
16936 peer->local_role != ROLE_UNDEFINED)
d864dd9e 16937 vty_out(vty, " neighbor %s local-role %s%s\n", addr,
8f2d6021 16938 bgp_get_name_by_role(peer->local_role),
7dddd1f7 16939 CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)
d864dd9e
EB
16940 ? " strict-mode"
16941 : "");
d864dd9e 16942
dd65f45e 16943 /* ttl-security hops */
e2521429 16944 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16945 if (!peer_group_active(peer)
16946 || g_peer->gtsm_hops != peer->gtsm_hops) {
16947 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16948 addr, peer->gtsm_hops);
16949 }
16950 }
16951
16952 /* disable-connected-check */
16953 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16954 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16955
27aa23a4
DA
16956 /* link-bw-encoding-ieee */
16957 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16958 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16959 addr);
16960
d08c0c80
DA
16961 /* extended-optional-parameters */
16962 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16963 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16964 addr);
16965
dd65f45e
DL
16966 /* enforce-first-as */
16967 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16968 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16969
16970 /* update-source */
16971 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16972 if (peer->update_source)
47e12884
DA
16973 vty_out(vty, " neighbor %s update-source %pSU\n", addr,
16974 peer->update_source);
dd65f45e
DL
16975 else if (peer->update_if)
16976 vty_out(vty, " neighbor %s update-source %s\n", addr,
16977 peer->update_if);
16978 }
16979
16980 /* advertisement-interval */
16981 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16982 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16983 peer->routeadv);
16984
16985 /* timers */
16986 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16987 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16988 peer->keepalive, peer->holdtime);
16989
16990 /* timers connect */
16991 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16992 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16993 peer->connect);
5d5393b9
DL
16994 /* need special-case handling for changed default values due to
16995 * config profile / version (because there is no "timers bgp connect"
16996 * command, we need to save this per-peer :/)
16997 */
16998 else if (!peer_group_active(peer) && !peer->connect &&
16999 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17000 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17001 peer->bgp->default_connect_retry);
dd65f45e 17002
d43114f3
DS
17003 /* timers delayopen */
17004 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17005 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17006 peer->delayopen);
17007 /* Save config even though flag is not set if default values have been
17008 * changed
17009 */
17010 else if (!peer_group_active(peer) && !peer->delayopen
17011 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17012 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17013 peer->bgp->default_delayopen);
17014
dd65f45e
DL
17015 /* capability dynamic */
17016 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17017 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17018
17019 /* capability extended-nexthop */
17020 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
17021 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
17022 !peer->conf_if)
843770f6
DA
17023 vty_out(vty,
17024 " no neighbor %s capability extended-nexthop\n",
17025 addr);
17026 else if (!peer->conf_if)
17027 vty_out(vty,
17028 " neighbor %s capability extended-nexthop\n",
17029 addr);
dd65f45e
DL
17030 }
17031
17032 /* dont-capability-negotiation */
17033 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17034 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17035
17036 /* override-capability */
17037 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17038 vty_out(vty, " neighbor %s override-capability\n", addr);
17039
17040 /* strict-capability-match */
17041 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17042 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17043
17044 /* Sender side AS path loop detection. */
17045 if (peer->as_path_loop_detection)
17046 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17047 addr);
cfd47646 17048
17049 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17050 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17051
17052 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17053 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17054 vty_out(vty,
17055 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17056 } else if (CHECK_FLAG(
17057 peer->peer_gr_new_status_flag,
17058 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17059 vty_out(vty,
17060 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17061 } else if (
17062 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17063 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17064 && !(CHECK_FLAG(
17065 peer->peer_gr_new_status_flag,
17066 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17067 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17068 addr);
cfd47646 17069 }
17070 }
dd65f45e
DL
17071}
17072
17073/* BGP peer configuration display function. */
17074static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17075 struct peer *peer, afi_t afi, safi_t safi)
17076{
17077 struct peer *g_peer = NULL;
17078 char *addr;
17079 bool flag_scomm, flag_secomm, flag_slcomm;
17080
17081 /* Skip dynamic neighbors. */
17082 if (peer_dynamic_neighbor(peer))
17083 return;
17084
17085 if (peer->conf_if)
17086 addr = peer->conf_if;
17087 else
17088 addr = peer->host;
17089
17090 /************************************
17091 ****** Per AF to the neighbor ******
17092 ************************************/
17093 if (peer_group_active(peer)) {
17094 g_peer = peer->group->conf;
17095
17096 /* If the peer-group is active but peer is not, print a 'no
17097 * activate' */
17098 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17099 vty_out(vty, " no neighbor %s activate\n", addr);
17100 }
17101
17102 /* If the peer-group is not active but peer is, print an
17103 'activate' */
17104 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17105 vty_out(vty, " neighbor %s activate\n", addr);
17106 }
17107 } else {
17108 if (peer->afc[afi][safi]) {
38d11af5
TA
17109 if (safi == SAFI_ENCAP)
17110 vty_out(vty, " neighbor %s activate\n", addr);
17111 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
17112 vty_out(vty, " neighbor %s activate\n", addr);
17113 } else {
38d11af5
TA
17114 if (bgp->default_af[afi][safi])
17115 vty_out(vty, " no neighbor %s activate\n",
17116 addr);
dd65f45e
DL
17117 }
17118 }
17119
17120 /* addpath TX knobs */
17121 if (peergroup_af_addpath_check(peer, afi, safi)) {
17122 switch (peer->addpath_type[afi][safi]) {
17123 case BGP_ADDPATH_ALL:
17124 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17125 addr);
17126 break;
17127 case BGP_ADDPATH_BEST_PER_AS:
17128 vty_out(vty,
17129 " neighbor %s addpath-tx-bestpath-per-AS\n",
17130 addr);
17131 break;
17132 case BGP_ADDPATH_MAX:
17133 case BGP_ADDPATH_NONE:
17134 break;
17135 }
17136 }
17137
7c0e4312
DA
17138 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
17139 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
17140
dd65f45e
DL
17141 /* ORF capability. */
17142 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17143 || peergroup_af_flag_check(peer, afi, safi,
17144 PEER_FLAG_ORF_PREFIX_RM)) {
17145 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17146
17147 if (peergroup_af_flag_check(peer, afi, safi,
17148 PEER_FLAG_ORF_PREFIX_SM)
17149 && peergroup_af_flag_check(peer, afi, safi,
17150 PEER_FLAG_ORF_PREFIX_RM))
17151 vty_out(vty, " both");
17152 else if (peergroup_af_flag_check(peer, afi, safi,
17153 PEER_FLAG_ORF_PREFIX_SM))
17154 vty_out(vty, " send");
17155 else
17156 vty_out(vty, " receive");
17157 vty_out(vty, "\n");
17158 }
17159
dd65f45e
DL
17160 /* Route reflector client. */
17161 if (peergroup_af_flag_check(peer, afi, safi,
17162 PEER_FLAG_REFLECTOR_CLIENT)) {
17163 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17164 }
17165
17166 /* next-hop-self force */
17167 if (peergroup_af_flag_check(peer, afi, safi,
17168 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17169 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17170 }
17171
17172 /* next-hop-self */
17173 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17174 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17175 }
17176
17177 /* remove-private-AS */
17178 if (peergroup_af_flag_check(peer, afi, safi,
17179 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17180 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17181 addr);
17182 }
17183
17184 else if (peergroup_af_flag_check(peer, afi, safi,
17185 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17186 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17187 addr);
17188 }
17189
17190 else if (peergroup_af_flag_check(peer, afi, safi,
17191 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17192 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17193 }
17194
17195 else if (peergroup_af_flag_check(peer, afi, safi,
17196 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17197 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17198 }
17199
17200 /* as-override */
17201 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17202 vty_out(vty, " neighbor %s as-override\n", addr);
17203 }
17204
17205 /* send-community print. */
17206 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17207 PEER_FLAG_SEND_COMMUNITY);
17208 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17209 PEER_FLAG_SEND_EXT_COMMUNITY);
17210 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17211 PEER_FLAG_SEND_LARGE_COMMUNITY);
17212
17213 if (flag_scomm && flag_secomm && flag_slcomm) {
17214 vty_out(vty, " no neighbor %s send-community all\n", addr);
17215 } else {
17216 if (flag_scomm)
17217 vty_out(vty, " no neighbor %s send-community\n", addr);
17218 if (flag_secomm)
17219 vty_out(vty,
17220 " no neighbor %s send-community extended\n",
17221 addr);
17222
17223 if (flag_slcomm)
17224 vty_out(vty, " no neighbor %s send-community large\n",
17225 addr);
17226 }
17227
17228 /* Default information */
17229 if (peergroup_af_flag_check(peer, afi, safi,
17230 PEER_FLAG_DEFAULT_ORIGINATE)) {
17231 vty_out(vty, " neighbor %s default-originate", addr);
17232
17233 if (peer->default_rmap[afi][safi].name)
17234 vty_out(vty, " route-map %s",
17235 peer->default_rmap[afi][safi].name);
17236
17237 vty_out(vty, "\n");
17238 }
17239
17240 /* Soft reconfiguration inbound. */
17241 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17242 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17243 addr);
17244 }
17245
17246 /* maximum-prefix. */
17247 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17248 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17249 peer->pmax[afi][safi]);
17250
17251 if (peer->pmax_threshold[afi][safi]
17252 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17253 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17254 if (peer_af_flag_check(peer, afi, safi,
17255 PEER_FLAG_MAX_PREFIX_WARNING))
17256 vty_out(vty, " warning-only");
17257 if (peer->pmax_restart[afi][safi])
17258 vty_out(vty, " restart %u",
17259 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17260 if (peer_af_flag_check(peer, afi, safi,
17261 PEER_FLAG_MAX_PREFIX_FORCE))
17262 vty_out(vty, " force");
dd65f45e
DL
17263
17264 vty_out(vty, "\n");
17265 }
17266
fde246e8
DA
17267 /* maximum-prefix-out */
17268 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17269 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17270 addr, peer->pmax_out[afi][safi]);
17271
dd65f45e
DL
17272 /* Route server client. */
17273 if (peergroup_af_flag_check(peer, afi, safi,
17274 PEER_FLAG_RSERVER_CLIENT)) {
17275 vty_out(vty, " neighbor %s route-server-client\n", addr);
17276 }
17277
17278 /* Nexthop-local unchanged. */
17279 if (peergroup_af_flag_check(peer, afi, safi,
17280 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17281 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17282 }
17283
17284 /* allowas-in <1-10> */
17285 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17286 if (peer_af_flag_check(peer, afi, safi,
17287 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17288 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17289 } else if (peer->allowas_in[afi][safi] == 3) {
17290 vty_out(vty, " neighbor %s allowas-in\n", addr);
17291 } else {
17292 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17293 peer->allowas_in[afi][safi]);
17294 }
17295 }
17296
01da2d26
DA
17297 /* soo */
17298 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOO)) {
17299 char *soo_str = ecommunity_ecom2str(
17300 peer->soo[afi][safi], ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
17301
17302 vty_out(vty, " neighbor %s soo %s\n", addr, soo_str);
17303 XFREE(MTYPE_ECOMMUNITY_STR, soo_str);
17304 }
17305
dd65f45e
DL
17306 /* weight */
17307 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17308 vty_out(vty, " neighbor %s weight %lu\n", addr,
17309 peer->weight[afi][safi]);
17310
17311 /* Filter. */
17312 bgp_config_write_filter(vty, peer, afi, safi);
17313
17314 /* atribute-unchanged. */
17315 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17316 || (safi != SAFI_EVPN
17317 && peer_af_flag_check(peer, afi, safi,
17318 PEER_FLAG_NEXTHOP_UNCHANGED))
17319 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17320
17321 if (!peer_group_active(peer)
17322 || peergroup_af_flag_check(peer, afi, safi,
17323 PEER_FLAG_AS_PATH_UNCHANGED)
17324 || peergroup_af_flag_check(peer, afi, safi,
17325 PEER_FLAG_NEXTHOP_UNCHANGED)
17326 || peergroup_af_flag_check(peer, afi, safi,
17327 PEER_FLAG_MED_UNCHANGED)) {
17328
17329 vty_out(vty,
17330 " neighbor %s attribute-unchanged%s%s%s\n",
17331 addr,
17332 peer_af_flag_check(peer, afi, safi,
17333 PEER_FLAG_AS_PATH_UNCHANGED)
17334 ? " as-path"
17335 : "",
17336 peer_af_flag_check(peer, afi, safi,
17337 PEER_FLAG_NEXTHOP_UNCHANGED)
17338 ? " next-hop"
17339 : "",
17340 peer_af_flag_check(peer, afi, safi,
17341 PEER_FLAG_MED_UNCHANGED)
17342 ? " med"
17343 : "");
17344 }
17345 }
17346}
17347
a486300b
PG
17348static void bgp_vpn_config_write(struct vty *vty, struct bgp *bgp, afi_t afi,
17349 safi_t safi)
17350{
17351 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
17352 BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL))
17353 vty_out(vty, " no bgp retain route-target all\n");
17354}
17355
dd65f45e
DL
17356/* Address family based peer configuration display. */
17357static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17358 safi_t safi)
17359{
17360 struct peer *peer;
17361 struct peer_group *group;
17362 struct listnode *node, *nnode;
17363
17364
17365 vty_frame(vty, " !\n address-family ");
17366 if (afi == AFI_IP) {
17367 if (safi == SAFI_UNICAST)
17368 vty_frame(vty, "ipv4 unicast");
17369 else if (safi == SAFI_LABELED_UNICAST)
17370 vty_frame(vty, "ipv4 labeled-unicast");
17371 else if (safi == SAFI_MULTICAST)
17372 vty_frame(vty, "ipv4 multicast");
17373 else if (safi == SAFI_MPLS_VPN)
17374 vty_frame(vty, "ipv4 vpn");
17375 else if (safi == SAFI_ENCAP)
17376 vty_frame(vty, "ipv4 encap");
17377 else if (safi == SAFI_FLOWSPEC)
17378 vty_frame(vty, "ipv4 flowspec");
17379 } else if (afi == AFI_IP6) {
17380 if (safi == SAFI_UNICAST)
17381 vty_frame(vty, "ipv6 unicast");
17382 else if (safi == SAFI_LABELED_UNICAST)
17383 vty_frame(vty, "ipv6 labeled-unicast");
17384 else if (safi == SAFI_MULTICAST)
17385 vty_frame(vty, "ipv6 multicast");
17386 else if (safi == SAFI_MPLS_VPN)
17387 vty_frame(vty, "ipv6 vpn");
17388 else if (safi == SAFI_ENCAP)
17389 vty_frame(vty, "ipv6 encap");
17390 else if (safi == SAFI_FLOWSPEC)
17391 vty_frame(vty, "ipv6 flowspec");
17392 } else if (afi == AFI_L2VPN) {
17393 if (safi == SAFI_EVPN)
17394 vty_frame(vty, "l2vpn evpn");
17395 }
17396 vty_frame(vty, "\n");
17397
17398 bgp_config_write_distance(vty, bgp, afi, safi);
17399
17400 bgp_config_write_network(vty, bgp, afi, safi);
17401
17402 bgp_config_write_redistribute(vty, bgp, afi, safi);
17403
8a4e7fe6
DA
17404 /* BGP flag dampening. */
17405 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17406 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17407
dd65f45e
DL
17408 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17409 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17410
17411 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17412 /* Do not display doppelganger peers */
17413 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17414 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17415 }
17416
17417 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17418 bgp_config_write_table_map(vty, bgp, afi, safi);
17419
17420 if (safi == SAFI_EVPN)
17421 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17422
17423 if (safi == SAFI_FLOWSPEC)
17424 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17425
a486300b
PG
17426 if (safi == SAFI_MPLS_VPN)
17427 bgp_vpn_config_write(vty, bgp, afi, safi);
17428
dd65f45e
DL
17429 if (safi == SAFI_UNICAST) {
17430 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17431 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17432 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17433
17434 vty_out(vty, " export vpn\n");
17435 }
17436 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17437 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17438
17439 vty_out(vty, " import vpn\n");
17440 }
17441 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17442 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17443 char *name;
17444
17445 for (ALL_LIST_ELEMENTS_RO(
17446 bgp->vpn_policy[afi].import_vrf, node,
17447 name))
17448 vty_out(vty, " import vrf %s\n", name);
17449 }
17450 }
17451
17452 vty_endframe(vty, " exit-address-family\n");
17453}
17454
17455int bgp_config_write(struct vty *vty)
17456{
17457 struct bgp *bgp;
17458 struct peer_group *group;
17459 struct peer *peer;
17460 struct listnode *node, *nnode;
17461 struct listnode *mnode, *mnnode;
b16bcbba
TA
17462 afi_t afi;
17463 safi_t safi;
dd65f45e
DL
17464
17465 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17466 vty_out(vty, "bgp route-map delay-timer %u\n",
17467 bm->rmap_update_timer);
17468
d70583f7
D
17469 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17470 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17471 if (bm->v_update_delay != bm->v_establish_wait)
17472 vty_out(vty, " %d", bm->v_establish_wait);
17473 vty_out(vty, "\n");
17474 }
17475
9acb67cb
DS
17476 if (bm->wait_for_fib)
17477 vty_out(vty, "bgp suppress-fib-pending\n");
17478
05bd726c 17479 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17480 vty_out(vty, "bgp graceful-shutdown\n");
17481
c163f297
DS
17482 /* No-RIB (Zebra) option flag configuration */
17483 if (bgp_option_check(BGP_OPT_NO_FIB))
17484 vty_out(vty, "bgp no-rib\n");
17485
870791a3
IR
17486 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17487 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17488
425bd64b
PS
17489 /* BGP session DSCP value */
17490 if (bm->tcp_dscp != IPTOS_PREC_INTERNETCONTROL)
17491 vty_out(vty, "bgp session-dscp %u\n", bm->tcp_dscp >> 2);
17492
dd65f45e
DL
17493 /* BGP configuration. */
17494 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17495
17496 /* skip all auto created vrf as they dont have user config */
17497 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17498 continue;
17499
17500 /* Router bgp ASN */
17501 vty_out(vty, "router bgp %u", bgp->as);
17502
17503 if (bgp->name)
17504 vty_out(vty, " %s %s",
17505 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17506 ? "view" : "vrf", bgp->name);
17507 vty_out(vty, "\n");
17508
17509 /* BGP fast-external-failover. */
17510 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17511 vty_out(vty, " no bgp fast-external-failover\n");
17512
17513 /* BGP router ID. */
3a6290bd 17514 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17515 vty_out(vty, " bgp router-id %pI4\n",
17516 &bgp->router_id_static);
dd65f45e 17517
c208c586
S
17518 /* Suppress fib pending */
17519 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17520 vty_out(vty, " bgp suppress-fib-pending\n");
17521
dd65f45e 17522 /* BGP log-neighbor-changes. */
892fedb6 17523 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17524 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17525 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17526 CHECK_FLAG(bgp->flags,
17527 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17528 ? ""
17529 : "no ");
17530
17531 /* BGP configuration. */
892fedb6 17532 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17533 vty_out(vty, " bgp always-compare-med\n");
17534
17535 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17536 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17537 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17538 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17539 CHECK_FLAG(bgp->flags,
17540 BGP_FLAG_EBGP_REQUIRES_POLICY)
17541 ? ""
17542 : "no ");
dd65f45e
DL
17543
17544 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17545 if (bgp->reject_as_sets)
dd65f45e
DL
17546 vty_out(vty, " bgp reject-as-sets\n");
17547
2adac256
DA
17548 /* Suppress duplicate updates if the route actually not changed
17549 */
17550 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17551 != SAVE_BGP_SUPPRESS_DUPLICATES)
17552 vty_out(vty, " %sbgp suppress-duplicates\n",
17553 CHECK_FLAG(bgp->flags,
17554 BGP_FLAG_SUPPRESS_DUPLICATES)
17555 ? ""
17556 : "no ");
17557
1ae314be
DA
17558 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17559 */
17560 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17561 SAVE_BGP_HARD_ADMIN_RESET)
17562 vty_out(vty, " %sbgp hard-administrative-reset\n",
17563 CHECK_FLAG(bgp->flags,
17564 BGP_FLAG_HARD_ADMIN_RESET)
17565 ? ""
17566 : "no ");
17567
b16bcbba
TA
17568 /* BGP default <afi>-<safi> */
17569 FOREACH_AFI_SAFI (afi, safi) {
17570 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17571 if (!bgp->default_af[afi][safi])
17572 vty_out(vty, " no bgp default %s\n",
17573 get_bgp_default_af_flag(afi,
17574 safi));
17575 } else if (bgp->default_af[afi][safi])
17576 vty_out(vty, " bgp default %s\n",
17577 get_bgp_default_af_flag(afi, safi));
17578 }
e84c59af 17579
dd65f45e
DL
17580 /* BGP default local-preference. */
17581 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17582 vty_out(vty, " bgp default local-preference %u\n",
17583 bgp->default_local_pref);
17584
17585 /* BGP default show-hostname */
892fedb6 17586 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17587 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17588 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17589 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17590 ? ""
17591 : "no ");
17592
aef999a2
DA
17593 /* BGP default show-nexthop-hostname */
17594 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17595 != SAVE_BGP_SHOW_HOSTNAME)
17596 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17597 CHECK_FLAG(bgp->flags,
17598 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17599 ? ""
17600 : "no ");
17601
dd65f45e
DL
17602 /* BGP default subgroup-pkt-queue-max. */
17603 if (bgp->default_subgroup_pkt_queue_max
17604 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17605 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17606 bgp->default_subgroup_pkt_queue_max);
17607
17608 /* BGP client-to-client reflection. */
892fedb6 17609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17610 vty_out(vty, " no bgp client-to-client reflection\n");
17611
17612 /* BGP cluster ID. */
17613 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17614 vty_out(vty, " bgp cluster-id %pI4\n",
17615 &bgp->cluster_id);
dd65f45e
DL
17616
17617 /* Disable ebgp connected nexthop check */
892fedb6 17618 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17619 vty_out(vty,
17620 " bgp disable-ebgp-connected-route-check\n");
17621
17622 /* Confederation identifier*/
17623 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17624 vty_out(vty, " bgp confederation identifier %u\n",
17625 bgp->confed_id);
17626
17627 /* Confederation peer */
17628 if (bgp->confed_peers_cnt > 0) {
17629 int i;
17630
17631 vty_out(vty, " bgp confederation peers");
17632
17633 for (i = 0; i < bgp->confed_peers_cnt; i++)
17634 vty_out(vty, " %u", bgp->confed_peers[i]);
17635
17636 vty_out(vty, "\n");
17637 }
17638
17639 /* BGP deterministic-med. */
892fedb6 17640 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17641 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17642 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17643 CHECK_FLAG(bgp->flags,
17644 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17645 ? ""
17646 : "no ");
17647
17648 /* BGP update-delay. */
17649 bgp_config_write_update_delay(vty, bgp);
17650
17651 if (bgp->v_maxmed_onstartup
17652 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17653 vty_out(vty, " bgp max-med on-startup %u",
17654 bgp->v_maxmed_onstartup);
17655 if (bgp->maxmed_onstartup_value
17656 != BGP_MAXMED_VALUE_DEFAULT)
17657 vty_out(vty, " %u",
17658 bgp->maxmed_onstartup_value);
17659 vty_out(vty, "\n");
17660 }
17661 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17662 vty_out(vty, " bgp max-med administrative");
17663 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17664 vty_out(vty, " %u", bgp->maxmed_admin_value);
17665 vty_out(vty, "\n");
17666 }
17667
17668 /* write quanta */
17669 bgp_config_write_wpkt_quanta(vty, bgp);
17670 /* read quanta */
17671 bgp_config_write_rpkt_quanta(vty, bgp);
17672
17673 /* coalesce time */
17674 bgp_config_write_coalesce_time(vty, bgp);
17675
05bd726c 17676 /* BGP per-instance graceful-shutdown */
17677 /* BGP-wide settings and per-instance settings are mutually
17678 * exclusive.
17679 */
17680 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17681 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17682 vty_out(vty, " bgp graceful-shutdown\n");
17683
8606be87
DA
17684 /* Long-lived Graceful Restart */
17685 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17686 vty_out(vty,
17687 " bgp long-lived-graceful-restart stale-time %u\n",
17688 bgp->llgr_stale_time);
17689
dd65f45e
DL
17690 /* BGP graceful-restart. */
17691 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17692 vty_out(vty,
17693 " bgp graceful-restart stalepath-time %u\n",
17694 bgp->stalepath_time);
cfd47646 17695
dd65f45e
DL
17696 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17697 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17698 bgp->restart_time);
cfd47646 17699
f2ca5c5b
DA
17700 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17701 SAVE_BGP_GRACEFUL_NOTIFICATION)
17702 vty_out(vty, " %sbgp graceful-restart notification\n",
17703 CHECK_FLAG(bgp->flags,
17704 BGP_FLAG_GRACEFUL_NOTIFICATION)
17705 ? ""
17706 : "no ");
17707
cfd47646 17708 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17709 vty_out(vty,
17710 " bgp graceful-restart select-defer-time %u\n",
17711 bgp->select_defer_time);
17712
17713 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17714 vty_out(vty, " bgp graceful-restart\n");
17715
cfd47646 17716 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17717 vty_out(vty, " bgp graceful-restart-disable\n");
17718
dd65f45e 17719 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17720 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17721 vty_out(vty,
17722 " bgp graceful-restart preserve-fw-state\n");
17723
dc95985f 17724 /* Stale timer for RIB */
17725 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17726 vty_out(vty,
17727 " bgp graceful-restart rib-stale-time %u\n",
17728 bgp->rib_stale_time);
17729
dd65f45e 17730 /* BGP bestpath method. */
892fedb6 17731 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17732 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17733 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17734 vty_out(vty, " bgp bestpath as-path confed\n");
17735
892fedb6
DA
17736 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17737 if (CHECK_FLAG(bgp->flags,
17738 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17739 vty_out(vty,
17740 " bgp bestpath as-path multipath-relax as-set\n");
17741 } else {
17742 vty_out(vty,
17743 " bgp bestpath as-path multipath-relax\n");
17744 }
17745 }
17746
892fedb6 17747 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17748 vty_out(vty,
17749 " bgp route-reflector allow-outbound-policy\n");
17750 }
892fedb6 17751 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17752 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17753 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17754 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17755 vty_out(vty, " bgp bestpath med");
892fedb6 17756 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17757 vty_out(vty, " confed");
892fedb6
DA
17758 if (CHECK_FLAG(bgp->flags,
17759 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17760 vty_out(vty, " missing-as-worst");
17761 vty_out(vty, "\n");
17762 }
17763
ee88563a
JM
17764 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17765 vty_out(vty,
17766 " bgp bestpath peer-type multipath-relax\n");
17767
f7e1c681 17768 /* Link bandwidth handling. */
17769 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17770 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17771 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17772 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17773 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17774 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17775
dd65f45e 17776 /* BGP network import check. */
892fedb6 17777 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17778 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17779 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17780 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17781 ? ""
17782 : "no ");
17783
17784 /* BGP timers configuration. */
5d5393b9 17785 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17786 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17787 vty_out(vty, " timers bgp %u %u\n",
17788 bgp->default_keepalive, bgp->default_holdtime);
17789
b042667a
TI
17790 /* BGP minimum holdtime configuration. */
17791 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17792 && bgp->default_min_holdtime != 0)
17793 vty_out(vty, " bgp minimum-holdtime %u\n",
17794 bgp->default_min_holdtime);
17795
389e4f92
QY
17796 /* Conditional advertisement timer configuration */
17797 if (bgp->condition_check_period
17798 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17799 vty_out(vty,
17800 " bgp conditional-advertisement timer %u\n",
17801 bgp->condition_check_period);
17802
dd65f45e
DL
17803 /* peer-group */
17804 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17805 bgp_config_write_peer_global(vty, bgp, group->conf);
17806 }
17807
17808 /* Normal neighbor configuration. */
17809 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17810 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17811 bgp_config_write_peer_global(vty, bgp, peer);
17812 }
17813
17814 /* listen range and limit for dynamic BGP neighbors */
17815 bgp_config_write_listen(vty, bgp);
17816
17817 /*
17818 * BGP default autoshutdown neighbors
17819 *
17820 * This must be placed after any peer and peer-group
17821 * configuration, to avoid setting all peers to shutdown after
17822 * a daemon restart, which is undesired behavior. (see #2286)
17823 */
17824 if (bgp->autoshutdown)
17825 vty_out(vty, " bgp default shutdown\n");
17826
9cf59432
DS
17827 /* BGP instance administrative shutdown */
17828 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17829 vty_out(vty, " bgp shutdown\n");
17830
8666265e
DS
17831 if (bgp->allow_martian)
17832 vty_out(vty, " bgp allow-martian-nexthop\n");
17833
f852eb98
PG
17834 if (bgp->fast_convergence)
17835 vty_out(vty, " bgp fast-convergence\n");
17836
a0281b2e
HS
17837 if (bgp->srv6_enabled) {
17838 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17839 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17840 vty_out(vty, " locator %s\n",
17841 bgp->srv6_locator_name);
ff7c3ee1 17842 vty_endframe(vty, " exit\n");
a0281b2e
HS
17843 }
17844
17845
dd65f45e
DL
17846 /* IPv4 unicast configuration. */
17847 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17848
17849 /* IPv4 multicast configuration. */
17850 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17851
17852 /* IPv4 labeled-unicast configuration. */
17853 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17854
17855 /* IPv4 VPN configuration. */
17856 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17857
17858 /* ENCAPv4 configuration. */
17859 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17860
17861 /* FLOWSPEC v4 configuration. */
17862 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17863
17864 /* IPv6 unicast configuration. */
17865 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17866
17867 /* IPv6 multicast configuration. */
17868 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17869
17870 /* IPv6 labeled-unicast configuration. */
17871 bgp_config_write_family(vty, bgp, AFI_IP6,
17872 SAFI_LABELED_UNICAST);
17873
17874 /* IPv6 VPN configuration. */
17875 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17876
17877 /* ENCAPv6 configuration. */
17878 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17879
17880 /* FLOWSPEC v6 configuration. */
17881 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17882
17883 /* EVPN configuration. */
17884 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17885
17886 hook_call(bgp_inst_config_write, bgp, vty);
17887
49e5a4a0 17888#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17889 bgp_rfapi_cfg_write(vty, bgp);
17890#endif
17891
07679ad9 17892 vty_out(vty, "exit\n");
dd65f45e
DL
17893 vty_out(vty, "!\n");
17894 }
17895 return 0;
17896}
17897
ddb5b488 17898
718e3744 17899/* BGP node structure. */
d62a17ae 17900static struct cmd_node bgp_node = {
f4b8291f 17901 .name = "bgp",
62b346ee 17902 .node = BGP_NODE,
24389580 17903 .parent_node = CONFIG_NODE,
62b346ee 17904 .prompt = "%s(config-router)# ",
612c2c15 17905 .config_write = bgp_config_write,
718e3744 17906};
17907
d62a17ae 17908static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17909 .name = "bgp ipv4 unicast",
62b346ee 17910 .node = BGP_IPV4_NODE,
24389580 17911 .parent_node = BGP_NODE,
62b346ee 17912 .prompt = "%s(config-router-af)# ",
dd2c81b8 17913 .no_xpath = true,
718e3744 17914};
17915
d62a17ae 17916static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17917 .name = "bgp ipv4 multicast",
62b346ee 17918 .node = BGP_IPV4M_NODE,
24389580 17919 .parent_node = BGP_NODE,
62b346ee 17920 .prompt = "%s(config-router-af)# ",
dd2c81b8 17921 .no_xpath = true,
718e3744 17922};
17923
d62a17ae 17924static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17925 .name = "bgp ipv4 labeled unicast",
62b346ee 17926 .node = BGP_IPV4L_NODE,
24389580 17927 .parent_node = BGP_NODE,
62b346ee 17928 .prompt = "%s(config-router-af)# ",
dd2c81b8 17929 .no_xpath = true,
f51bae9c
DS
17930};
17931
d62a17ae 17932static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17933 .name = "bgp ipv6 unicast",
62b346ee 17934 .node = BGP_IPV6_NODE,
24389580 17935 .parent_node = BGP_NODE,
62b346ee 17936 .prompt = "%s(config-router-af)# ",
dd2c81b8 17937 .no_xpath = true,
718e3744 17938};
17939
d62a17ae 17940static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17941 .name = "bgp ipv6 multicast",
62b346ee 17942 .node = BGP_IPV6M_NODE,
24389580 17943 .parent_node = BGP_NODE,
62b346ee 17944 .prompt = "%s(config-router-af)# ",
dd2c81b8 17945 .no_xpath = true,
25ffbdc1 17946};
17947
d62a17ae 17948static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17949 .name = "bgp ipv6 labeled unicast",
62b346ee 17950 .node = BGP_IPV6L_NODE,
24389580 17951 .parent_node = BGP_NODE,
62b346ee 17952 .prompt = "%s(config-router-af)# ",
dd2c81b8 17953 .no_xpath = true,
f51bae9c
DS
17954};
17955
62b346ee 17956static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17957 .name = "bgp vpnv4",
62b346ee 17958 .node = BGP_VPNV4_NODE,
24389580 17959 .parent_node = BGP_NODE,
62b346ee 17960 .prompt = "%s(config-router-af)# ",
dd2c81b8 17961 .no_xpath = true,
62b346ee 17962};
6b0655a2 17963
62b346ee 17964static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17965 .name = "bgp vpnv6",
62b346ee 17966 .node = BGP_VPNV6_NODE,
24389580 17967 .parent_node = BGP_NODE,
62b346ee 17968 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17969 .no_xpath = true,
62b346ee 17970};
8ecd3266 17971
62b346ee 17972static struct cmd_node bgp_evpn_node = {
f4b8291f 17973 .name = "bgp evpn",
62b346ee 17974 .node = BGP_EVPN_NODE,
24389580 17975 .parent_node = BGP_NODE,
62b346ee 17976 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17977 .no_xpath = true,
62b346ee 17978};
4e0b7b6d 17979
62b346ee 17980static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17981 .name = "bgp evpn vni",
62b346ee 17982 .node = BGP_EVPN_VNI_NODE,
24389580 17983 .parent_node = BGP_EVPN_NODE,
62b346ee 17984 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17985};
90e60aa7 17986
62b346ee 17987static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17988 .name = "bgp ipv4 flowspec",
62b346ee 17989 .node = BGP_FLOWSPECV4_NODE,
24389580 17990 .parent_node = BGP_NODE,
62b346ee 17991 .prompt = "%s(config-router-af)# ",
dd2c81b8 17992 .no_xpath = true,
62b346ee 17993};
7c40bf39 17994
62b346ee 17995static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17996 .name = "bgp ipv6 flowspec",
62b346ee 17997 .node = BGP_FLOWSPECV6_NODE,
24389580 17998 .parent_node = BGP_NODE,
62b346ee 17999 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 18000 .no_xpath = true,
62b346ee 18001};
7c40bf39 18002
bfaab44d
HS
18003static struct cmd_node bgp_srv6_node = {
18004 .name = "bgp srv6",
18005 .node = BGP_SRV6_NODE,
18006 .parent_node = BGP_NODE,
18007 .prompt = "%s(config-router-srv6)# ",
18008};
18009
d62a17ae 18010static void community_list_vty(void);
1f8ae70b 18011
8c20061f
DA
18012static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18013{
18014 struct bgp *bgp;
18015 struct peer_group *group;
18016 struct listnode *lnbgp, *lnpeer;
18017
18018 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18019 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18020 vector_set(comps,
18021 XSTRDUP(MTYPE_COMPLETION, group->name));
18022 }
18023}
18024
18025static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 18026{
d62a17ae 18027 struct bgp *bgp;
18028 struct peer *peer;
d62a17ae 18029 struct listnode *lnbgp, *lnpeer;
b8a815e5 18030
d62a17ae 18031 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18032 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18033 /* only provide suggestions on the appropriate input
18034 * token type,
18035 * they'll otherwise show up multiple times */
18036 enum cmd_token_type match_type;
18037 char *name = peer->host;
d48ed3e0 18038
d62a17ae 18039 if (peer->conf_if) {
18040 match_type = VARIABLE_TKN;
18041 name = peer->conf_if;
18042 } else if (strchr(peer->host, ':'))
18043 match_type = IPV6_TKN;
18044 else
18045 match_type = IPV4_TKN;
d48ed3e0 18046
d62a17ae 18047 if (token->type != match_type)
18048 continue;
d48ed3e0 18049
d62a17ae 18050 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18051 }
d62a17ae 18052 }
b8a815e5
DL
18053}
18054
8c20061f
DA
18055static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
18056{
18057 bgp_ac_peer(comps, token);
84de1483
DA
18058
18059 if (token->type == VARIABLE_TKN)
18060 bgp_ac_peergroup(comps, token);
8c20061f
DA
18061}
18062
b8a815e5 18063static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18064 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18065 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18066 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18067 {.completions = NULL}};
18068
47a306a0
DS
18069static const struct cmd_variable_handler bgp_var_peergroup[] = {
18070 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18071 {.completions = NULL} };
18072
aa24a36a
DA
18073DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
18074
18075static struct thread *t_bgp_cfg;
18076
18077bool bgp_config_inprocess(void)
18078{
18079 return thread_is_scheduled(t_bgp_cfg);
18080}
18081
18082static void bgp_config_finish(struct thread *t)
18083{
18084 struct listnode *node;
18085 struct bgp *bgp;
18086
18087 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
18088 hook_call(bgp_config_end, bgp);
18089}
18090
18091static void bgp_config_start(void)
18092{
18093#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
18094 THREAD_OFF(t_bgp_cfg);
18095 thread_add_timer(bm->master, bgp_config_finish, NULL,
18096 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
18097}
18098
18099/* When we receive a hook the configuration is read,
18100 * we start a timer to make sure we postpone sending
18101 * EoR before route-maps are processed.
18102 * This is especially valid if using `bgp route-map delay-timer`.
18103 */
18104static void bgp_config_end(void)
18105{
18106#define BGP_POST_CONFIG_DELAY_SECONDS 1
18107 uint32_t bgp_post_config_delay =
18108 thread_is_scheduled(bm->t_rmap_update)
18109 ? thread_timer_remain_second(bm->t_rmap_update)
18110 : BGP_POST_CONFIG_DELAY_SECONDS;
18111
18112 /* If BGP config processing thread isn't running, then
18113 * we can return and rely it's properly handled.
18114 */
18115 if (!bgp_config_inprocess())
18116 return;
18117
18118 THREAD_OFF(t_bgp_cfg);
18119
18120 /* Start a new timer to make sure we don't send EoR
18121 * before route-maps are processed.
18122 */
18123 thread_add_timer(bm->master, bgp_config_finish, NULL,
18124 bgp_post_config_delay, &t_bgp_cfg);
18125}
18126
d62a17ae 18127void bgp_vty_init(void)
18128{
18129 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18130 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18131
aa24a36a
DA
18132 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
18133
d62a17ae 18134 /* Install bgp top node. */
612c2c15
DL
18135 install_node(&bgp_node);
18136 install_node(&bgp_ipv4_unicast_node);
18137 install_node(&bgp_ipv4_multicast_node);
18138 install_node(&bgp_ipv4_labeled_unicast_node);
18139 install_node(&bgp_ipv6_unicast_node);
18140 install_node(&bgp_ipv6_multicast_node);
18141 install_node(&bgp_ipv6_labeled_unicast_node);
18142 install_node(&bgp_vpnv4_node);
18143 install_node(&bgp_vpnv6_node);
18144 install_node(&bgp_evpn_node);
18145 install_node(&bgp_evpn_vni_node);
18146 install_node(&bgp_flowspecv4_node);
18147 install_node(&bgp_flowspecv6_node);
bfaab44d 18148 install_node(&bgp_srv6_node);
d62a17ae 18149
18150 /* Install default VTY commands to new nodes. */
18151 install_default(BGP_NODE);
18152 install_default(BGP_IPV4_NODE);
18153 install_default(BGP_IPV4M_NODE);
18154 install_default(BGP_IPV4L_NODE);
18155 install_default(BGP_IPV6_NODE);
18156 install_default(BGP_IPV6M_NODE);
18157 install_default(BGP_IPV6L_NODE);
18158 install_default(BGP_VPNV4_NODE);
18159 install_default(BGP_VPNV6_NODE);
7c40bf39 18160 install_default(BGP_FLOWSPECV4_NODE);
18161 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18162 install_default(BGP_EVPN_NODE);
18163 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18164 install_default(BGP_SRV6_NODE);
d62a17ae 18165
8029b216
AK
18166 /* "bgp local-mac" hidden commands. */
18167 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18168 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18169
9acb67cb
DS
18170 /* "bgp suppress-fib-pending" global */
18171 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18172
d62a17ae 18173 /* bgp route-map delay-timer commands. */
18174 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18175 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18176
8666265e
DS
18177 install_element(BGP_NODE, &bgp_allow_martian_cmd);
18178
f852eb98
PG
18179 /* bgp fast-convergence command */
18180 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
18181 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
18182
d70583f7
D
18183 /* global bgp update-delay command */
18184 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18185 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18186
05bd726c 18187 /* global bgp graceful-shutdown command */
18188 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18189 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18190
d62a17ae 18191 /* Dummy commands (Currently not supported) */
18192 install_element(BGP_NODE, &no_synchronization_cmd);
18193 install_element(BGP_NODE, &no_auto_summary_cmd);
18194
18195 /* "router bgp" commands. */
18196 install_element(CONFIG_NODE, &router_bgp_cmd);
18197
18198 /* "no router bgp" commands. */
18199 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18200
425bd64b
PS
18201 /* "bgp session-dscp command */
18202 install_element(CONFIG_NODE, &bgp_session_dscp_cmd);
18203 install_element(CONFIG_NODE, &no_bgp_session_dscp_cmd);
18204
d62a17ae 18205 /* "bgp router-id" commands. */
18206 install_element(BGP_NODE, &bgp_router_id_cmd);
18207 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18208
c208c586
S
18209 /* "bgp suppress-fib-pending" command */
18210 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18211
d62a17ae 18212 /* "bgp cluster-id" commands. */
18213 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18214 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18215
c163f297
DS
18216 /* "bgp no-rib" commands. */
18217 install_element(CONFIG_NODE, &bgp_norib_cmd);
18218 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18219
e46723a5
DS
18220 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18221
d62a17ae 18222 /* "bgp confederation" commands. */
18223 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18224 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18225
18226 /* "bgp confederation peers" commands. */
18227 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18228 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18229
18230 /* bgp max-med command */
18231 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18232 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18233 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18234 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18235 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18236
d864dd9e
EB
18237 /* "neighbor role" commands. */
18238 install_element(BGP_NODE, &neighbor_role_cmd);
18239 install_element(BGP_NODE, &neighbor_role_strict_cmd);
18240 install_element(BGP_NODE, &no_neighbor_role_cmd);
18241
d62a17ae 18242 /* bgp disable-ebgp-connected-nh-check */
18243 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18244 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18245
18246 /* bgp update-delay command */
18247 install_element(BGP_NODE, &bgp_update_delay_cmd);
18248 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18249
18250 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18251 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18252
18253 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18254 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18255
18256 /* "maximum-paths" commands. */
18257 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18258 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18259 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18260 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18261 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18262 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18263 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18264 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18265 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18266 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18267 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18268 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18269 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18270 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18271 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18272
39edabac
PG
18273 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18274 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18275 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18276 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18277 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18278 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18279 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18280 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18281 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18282 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18283
18284 /* "timers bgp" commands. */
18285 install_element(BGP_NODE, &bgp_timers_cmd);
18286 install_element(BGP_NODE, &no_bgp_timers_cmd);
18287
b042667a
TI
18288 /* "minimum-holdtime" commands. */
18289 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
18290 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
18291
d62a17ae 18292 /* route-map delay-timer commands - per instance for backwards compat.
18293 */
18294 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18295 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18296
18297 /* "bgp client-to-client reflection" commands */
18298 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18299 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18300
18301 /* "bgp always-compare-med" commands */
18302 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18303 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18304
9dac9fc8
DA
18305 /* bgp ebgp-requires-policy */
18306 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18307 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18308
2adac256
DA
18309 /* bgp suppress-duplicates */
18310 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18311 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18312
fb29348a
DA
18313 /* bgp reject-as-sets */
18314 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18315 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18316
d62a17ae 18317 /* "bgp deterministic-med" commands */
18318 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18319 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18320
055679e9 18321 /* "bgp graceful-restart" command */
36235319
QY
18322 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18323 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18324
18325 /* "bgp graceful-restart-disable" command */
36235319
QY
18326 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18327 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18328
18329 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18330 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18331 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18332
18333 /* "neighbor a:b:c:d graceful-restart-disable" command */
18334 install_element(BGP_NODE,
18335 &bgp_neighbor_graceful_restart_disable_set_cmd);
18336 install_element(BGP_NODE,
18337 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18338
18339 /* "neighbor a:b:c:d graceful-restart-helper" command */
18340 install_element(BGP_NODE,
18341 &bgp_neighbor_graceful_restart_helper_set_cmd);
18342 install_element(BGP_NODE,
18343 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18344
d62a17ae 18345 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18346 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18347 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18348 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18349 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18350 install_element(BGP_NODE,
18351 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18352 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18353 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 18354 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 18355
d6e3c15b 18356 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18357 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18358 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18359 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18360
7f323236
DW
18361 /* "bgp graceful-shutdown" commands */
18362 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18363 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18364
1ae314be
DA
18365 /* "bgp hard-administrative-reset" commands */
18366 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
18367
8606be87
DA
18368 /* "bgp long-lived-graceful-restart" commands */
18369 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
18370 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
18371
d62a17ae 18372 /* "bgp fast-external-failover" commands */
18373 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18374 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18375
d62a17ae 18376 /* "bgp bestpath compare-routerid" commands */
18377 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18378 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18379
18380 /* "bgp bestpath as-path ignore" commands */
18381 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18382 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18383
18384 /* "bgp bestpath as-path confed" commands */
18385 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18386 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18387
18388 /* "bgp bestpath as-path multipath-relax" commands */
18389 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18390 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18391
ee88563a
JM
18392 /* "bgp bestpath peer-type multipath-relax" commands */
18393 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18394 install_element(BGP_NODE,
18395 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18396
d62a17ae 18397 /* "bgp log-neighbor-changes" commands */
18398 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18399 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18400
18401 /* "bgp bestpath med" commands */
18402 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18403 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18404
f7e1c681 18405 /* "bgp bestpath bandwidth" commands */
18406 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18407 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18408
b16bcbba
TA
18409 /* "no bgp default <afi>-<safi>" commands. */
18410 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18411
d62a17ae 18412 /* "bgp network import-check" commands. */
18413 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18414 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18415 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18416
18417 /* "bgp default local-preference" commands. */
18418 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18419 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18420
18421 /* bgp default show-hostname */
18422 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18423 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18424
aef999a2
DA
18425 /* bgp default show-nexthop-hostname */
18426 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18427 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18428
d62a17ae 18429 /* "bgp default subgroup-pkt-queue-max" commands. */
18430 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18431 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18432
18433 /* bgp ibgp-allow-policy-mods command */
18434 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18435 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18436
18437 /* "bgp listen limit" commands. */
18438 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18439 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18440
18441 /* "bgp listen range" commands. */
18442 install_element(BGP_NODE, &bgp_listen_range_cmd);
18443 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18444
8175f54a 18445 /* "bgp default shutdown" command */
f26845f9 18446 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18447
18448 /* "bgp shutdown" commands */
18449 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18450 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18451 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18452 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18453
d62a17ae 18454 /* "neighbor remote-as" commands. */
18455 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18456 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18457 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18458 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18459 install_element(BGP_NODE,
18460 &neighbor_interface_v6only_config_remote_as_cmd);
18461 install_element(BGP_NODE, &no_neighbor_cmd);
18462 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18463
18464 /* "neighbor peer-group" commands. */
18465 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18466 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18467 install_element(BGP_NODE,
18468 &no_neighbor_interface_peer_group_remote_as_cmd);
18469
18470 /* "neighbor local-as" commands. */
18471 install_element(BGP_NODE, &neighbor_local_as_cmd);
18472 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18473 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18474 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18475
18476 /* "neighbor solo" commands. */
18477 install_element(BGP_NODE, &neighbor_solo_cmd);
18478 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18479
18480 /* "neighbor password" commands. */
18481 install_element(BGP_NODE, &neighbor_password_cmd);
18482 install_element(BGP_NODE, &no_neighbor_password_cmd);
18483
18484 /* "neighbor activate" commands. */
18485 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18486 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18487 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18488 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18489 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18490 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18491 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18492 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18493 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18494 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18495 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18496 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18497
18498 /* "no neighbor activate" commands. */
18499 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18500 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18501 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18502 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18503 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18504 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18505 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18506 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18507 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18508 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18509 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18510 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18511
18512 /* "neighbor peer-group" set commands. */
18513 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18514 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18515 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18516 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18517 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18518 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18519 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18520 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18521 install_element(BGP_FLOWSPECV4_NODE,
18522 &neighbor_set_peer_group_hidden_cmd);
18523 install_element(BGP_FLOWSPECV6_NODE,
18524 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18525
18526 /* "no neighbor peer-group unset" commands. */
18527 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18528 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18529 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18530 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18531 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18532 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18533 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18534 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18535 install_element(BGP_FLOWSPECV4_NODE,
18536 &no_neighbor_set_peer_group_hidden_cmd);
18537 install_element(BGP_FLOWSPECV6_NODE,
18538 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18539
18540 /* "neighbor softreconfiguration inbound" commands.*/
18541 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18542 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18543 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18544 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18545 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18546 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18547 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18548 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18549 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18550 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18551 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18552 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18553 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18554 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18555 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18556 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18557 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18558 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18559 install_element(BGP_FLOWSPECV4_NODE,
18560 &neighbor_soft_reconfiguration_cmd);
18561 install_element(BGP_FLOWSPECV4_NODE,
18562 &no_neighbor_soft_reconfiguration_cmd);
18563 install_element(BGP_FLOWSPECV6_NODE,
18564 &neighbor_soft_reconfiguration_cmd);
18565 install_element(BGP_FLOWSPECV6_NODE,
18566 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18567 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18568 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18569
18570 /* "neighbor attribute-unchanged" commands. */
18571 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18572 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18573 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18574 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18575 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18576 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18577 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18578 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18579 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18580 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18581 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18582 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18583 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18584 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18585 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18586 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18587 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18588 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18589
18590 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18591 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18592
b8ad84d2
PG
18593 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18594 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18595 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18596 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18597
d62a17ae 18598 /* "nexthop-local unchanged" commands */
18599 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18600 install_element(BGP_IPV6_NODE,
18601 &no_neighbor_nexthop_local_unchanged_cmd);
18602
18603 /* "neighbor next-hop-self" commands. */
18604 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18605 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18606 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18607 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18608 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18609 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18610 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18611 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18612 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18613 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18614 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18615 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18616 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18617 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18618 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18619 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18620 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18621 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18622 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18623 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18624
18625 /* "neighbor next-hop-self force" commands. */
18626 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18627 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18628 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18629 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18630 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18631 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18632 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18633 install_element(BGP_IPV4_NODE,
18634 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18635 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18636 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18637 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18638 install_element(BGP_IPV4M_NODE,
18639 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18640 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18641 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18642 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18643 install_element(BGP_IPV4L_NODE,
18644 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18645 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18646 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18647 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18648 install_element(BGP_IPV6_NODE,
18649 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18650 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18651 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18652 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18653 install_element(BGP_IPV6M_NODE,
18654 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18655 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18656 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18657 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18658 install_element(BGP_IPV6L_NODE,
18659 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18660 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18661 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18662 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18663 install_element(BGP_VPNV4_NODE,
18664 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18665 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18666 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18667 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18668 install_element(BGP_VPNV6_NODE,
18669 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18670 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18671 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18672
18673 /* "neighbor as-override" commands. */
18674 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18675 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18676 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18677 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18678 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18679 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18680 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18681 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18682 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18683 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18684 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18685 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18686 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18687 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18688 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18689 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18690 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18691 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18692
18693 /* "neighbor remove-private-AS" commands. */
18694 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18695 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18696 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18697 install_element(BGP_NODE,
18698 &no_neighbor_remove_private_as_all_hidden_cmd);
18699 install_element(BGP_NODE,
18700 &neighbor_remove_private_as_replace_as_hidden_cmd);
18701 install_element(BGP_NODE,
18702 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18703 install_element(BGP_NODE,
18704 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18705 install_element(
18706 BGP_NODE,
18707 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18708 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18709 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18710 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18711 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18712 install_element(BGP_IPV4_NODE,
18713 &neighbor_remove_private_as_replace_as_cmd);
18714 install_element(BGP_IPV4_NODE,
18715 &no_neighbor_remove_private_as_replace_as_cmd);
18716 install_element(BGP_IPV4_NODE,
18717 &neighbor_remove_private_as_all_replace_as_cmd);
18718 install_element(BGP_IPV4_NODE,
18719 &no_neighbor_remove_private_as_all_replace_as_cmd);
18720 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18721 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18722 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18723 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18724 install_element(BGP_IPV4M_NODE,
18725 &neighbor_remove_private_as_replace_as_cmd);
18726 install_element(BGP_IPV4M_NODE,
18727 &no_neighbor_remove_private_as_replace_as_cmd);
18728 install_element(BGP_IPV4M_NODE,
18729 &neighbor_remove_private_as_all_replace_as_cmd);
18730 install_element(BGP_IPV4M_NODE,
18731 &no_neighbor_remove_private_as_all_replace_as_cmd);
18732 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18733 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18734 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18735 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18736 install_element(BGP_IPV4L_NODE,
18737 &neighbor_remove_private_as_replace_as_cmd);
18738 install_element(BGP_IPV4L_NODE,
18739 &no_neighbor_remove_private_as_replace_as_cmd);
18740 install_element(BGP_IPV4L_NODE,
18741 &neighbor_remove_private_as_all_replace_as_cmd);
18742 install_element(BGP_IPV4L_NODE,
18743 &no_neighbor_remove_private_as_all_replace_as_cmd);
18744 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18745 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18746 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18747 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18748 install_element(BGP_IPV6_NODE,
18749 &neighbor_remove_private_as_replace_as_cmd);
18750 install_element(BGP_IPV6_NODE,
18751 &no_neighbor_remove_private_as_replace_as_cmd);
18752 install_element(BGP_IPV6_NODE,
18753 &neighbor_remove_private_as_all_replace_as_cmd);
18754 install_element(BGP_IPV6_NODE,
18755 &no_neighbor_remove_private_as_all_replace_as_cmd);
18756 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18757 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18758 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18759 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18760 install_element(BGP_IPV6M_NODE,
18761 &neighbor_remove_private_as_replace_as_cmd);
18762 install_element(BGP_IPV6M_NODE,
18763 &no_neighbor_remove_private_as_replace_as_cmd);
18764 install_element(BGP_IPV6M_NODE,
18765 &neighbor_remove_private_as_all_replace_as_cmd);
18766 install_element(BGP_IPV6M_NODE,
18767 &no_neighbor_remove_private_as_all_replace_as_cmd);
18768 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18769 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18770 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18771 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18772 install_element(BGP_IPV6L_NODE,
18773 &neighbor_remove_private_as_replace_as_cmd);
18774 install_element(BGP_IPV6L_NODE,
18775 &no_neighbor_remove_private_as_replace_as_cmd);
18776 install_element(BGP_IPV6L_NODE,
18777 &neighbor_remove_private_as_all_replace_as_cmd);
18778 install_element(BGP_IPV6L_NODE,
18779 &no_neighbor_remove_private_as_all_replace_as_cmd);
18780 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18781 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18782 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18783 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18784 install_element(BGP_VPNV4_NODE,
18785 &neighbor_remove_private_as_replace_as_cmd);
18786 install_element(BGP_VPNV4_NODE,
18787 &no_neighbor_remove_private_as_replace_as_cmd);
18788 install_element(BGP_VPNV4_NODE,
18789 &neighbor_remove_private_as_all_replace_as_cmd);
18790 install_element(BGP_VPNV4_NODE,
18791 &no_neighbor_remove_private_as_all_replace_as_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18793 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18794 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18795 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18796 install_element(BGP_VPNV6_NODE,
18797 &neighbor_remove_private_as_replace_as_cmd);
18798 install_element(BGP_VPNV6_NODE,
18799 &no_neighbor_remove_private_as_replace_as_cmd);
18800 install_element(BGP_VPNV6_NODE,
18801 &neighbor_remove_private_as_all_replace_as_cmd);
18802 install_element(BGP_VPNV6_NODE,
18803 &no_neighbor_remove_private_as_all_replace_as_cmd);
18804
18805 /* "neighbor send-community" commands.*/
18806 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18807 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18808 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18809 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18810 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18811 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18812 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18813 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18814 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18815 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18816 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18817 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18818 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18819 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18820 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18821 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18822 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18823 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18824 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18825 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18826 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18827 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18828 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18829 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18830 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18831 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18832 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18833 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18834 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18835 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18836 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18837 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18838 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18839 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18840 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18841 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18842
18843 /* "neighbor route-reflector" commands.*/
18844 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18845 install_element(BGP_NODE,
18846 &no_neighbor_route_reflector_client_hidden_cmd);
18847 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18848 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18849 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18850 install_element(BGP_IPV4M_NODE,
18851 &no_neighbor_route_reflector_client_cmd);
18852 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18853 install_element(BGP_IPV4L_NODE,
18854 &no_neighbor_route_reflector_client_cmd);
18855 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18856 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18857 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18858 install_element(BGP_IPV6M_NODE,
18859 &no_neighbor_route_reflector_client_cmd);
18860 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18861 install_element(BGP_IPV6L_NODE,
18862 &no_neighbor_route_reflector_client_cmd);
18863 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18864 install_element(BGP_VPNV4_NODE,
18865 &no_neighbor_route_reflector_client_cmd);
18866 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18867 install_element(BGP_VPNV6_NODE,
18868 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18869 install_element(BGP_FLOWSPECV4_NODE,
18870 &neighbor_route_reflector_client_cmd);
18871 install_element(BGP_FLOWSPECV4_NODE,
18872 &no_neighbor_route_reflector_client_cmd);
18873 install_element(BGP_FLOWSPECV6_NODE,
18874 &neighbor_route_reflector_client_cmd);
18875 install_element(BGP_FLOWSPECV6_NODE,
18876 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18877 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18878 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18879
18880 /* "neighbor route-server" commands.*/
18881 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18882 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18883 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18884 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18885 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18886 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18887 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18888 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18889 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18890 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18891 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18892 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18893 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18894 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18895 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18896 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18897 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18898 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18899 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18900 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18901 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18902 install_element(BGP_FLOWSPECV4_NODE,
18903 &no_neighbor_route_server_client_cmd);
18904 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18905 install_element(BGP_FLOWSPECV6_NODE,
18906 &no_neighbor_route_server_client_cmd);
d62a17ae 18907
7c0e4312
DA
18908 /* "neighbor disable-addpath-rx" commands. */
18909 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18910 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18911 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18912 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18913 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18914 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18915 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18916 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18917 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18918 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18919 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18920 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18921 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18922 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18923 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18924 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18925
d62a17ae 18926 /* "neighbor addpath-tx-all-paths" commands.*/
18927 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18928 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18929 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18930 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18931 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18932 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18933 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18934 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18935 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18936 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18937 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18938 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18939 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18940 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18941 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18942 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18943 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18944 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18945
18946 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18947 install_element(BGP_NODE,
18948 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18949 install_element(BGP_NODE,
18950 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18951 install_element(BGP_IPV4_NODE,
18952 &neighbor_addpath_tx_bestpath_per_as_cmd);
18953 install_element(BGP_IPV4_NODE,
18954 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18955 install_element(BGP_IPV4M_NODE,
18956 &neighbor_addpath_tx_bestpath_per_as_cmd);
18957 install_element(BGP_IPV4M_NODE,
18958 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18959 install_element(BGP_IPV4L_NODE,
18960 &neighbor_addpath_tx_bestpath_per_as_cmd);
18961 install_element(BGP_IPV4L_NODE,
18962 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18963 install_element(BGP_IPV6_NODE,
18964 &neighbor_addpath_tx_bestpath_per_as_cmd);
18965 install_element(BGP_IPV6_NODE,
18966 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18967 install_element(BGP_IPV6M_NODE,
18968 &neighbor_addpath_tx_bestpath_per_as_cmd);
18969 install_element(BGP_IPV6M_NODE,
18970 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18971 install_element(BGP_IPV6L_NODE,
18972 &neighbor_addpath_tx_bestpath_per_as_cmd);
18973 install_element(BGP_IPV6L_NODE,
18974 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18975 install_element(BGP_VPNV4_NODE,
18976 &neighbor_addpath_tx_bestpath_per_as_cmd);
18977 install_element(BGP_VPNV4_NODE,
18978 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18979 install_element(BGP_VPNV6_NODE,
18980 &neighbor_addpath_tx_bestpath_per_as_cmd);
18981 install_element(BGP_VPNV6_NODE,
18982 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18983
2b31007c
RZ
18984 /* "neighbor sender-as-path-loop-detection" commands. */
18985 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18986 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18987
d62a17ae 18988 /* "neighbor passive" commands. */
18989 install_element(BGP_NODE, &neighbor_passive_cmd);
18990 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18991
18992
18993 /* "neighbor shutdown" commands. */
18994 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18995 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18996 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18997 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18998 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18999 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19000
19001 /* "neighbor capability extended-nexthop" commands.*/
19002 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19003 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19004
19005 /* "neighbor capability orf prefix-list" commands.*/
19006 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19007 install_element(BGP_NODE,
19008 &no_neighbor_capability_orf_prefix_hidden_cmd);
19009 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19010 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19011 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19012 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19013 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19014 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19015 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19016 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19017 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19018 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19019 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19020 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19021
19022 /* "neighbor capability dynamic" commands.*/
19023 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19024 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19025
19026 /* "neighbor dont-capability-negotiate" commands. */
19027 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19028 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19029
19030 /* "neighbor ebgp-multihop" commands. */
19031 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19032 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19033 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19034
19035 /* "neighbor disable-connected-check" commands. */
19036 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19037 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19038
7ab294ea
DA
19039 /* "neighbor disable-link-bw-encoding-ieee" commands. */
19040 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
19041 install_element(BGP_NODE,
19042 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 19043
d08c0c80
DA
19044 /* "neighbor extended-optional-parameters" commands. */
19045 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
19046 install_element(BGP_NODE,
19047 &no_neighbor_extended_optional_parameters_cmd);
19048
47cbc09b
PM
19049 /* "neighbor enforce-first-as" commands. */
19050 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19051 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19052
d62a17ae 19053 /* "neighbor description" commands. */
19054 install_element(BGP_NODE, &neighbor_description_cmd);
19055 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19056 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19057
19058 /* "neighbor update-source" commands. "*/
19059 install_element(BGP_NODE, &neighbor_update_source_cmd);
19060 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19061
19062 /* "neighbor default-originate" commands. */
19063 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19064 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19065 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19066 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19067 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19068 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19069 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19070 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19071 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19072 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19073 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19074 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19075 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19076 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19077 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19078 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19079 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19080 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19081 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19082 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19083 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19084
19085 /* "neighbor port" commands. */
19086 install_element(BGP_NODE, &neighbor_port_cmd);
19087 install_element(BGP_NODE, &no_neighbor_port_cmd);
19088
19089 /* "neighbor weight" commands. */
19090 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19091 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19092
19093 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19094 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19095 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19096 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19097 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19098 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19099 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19100 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19101 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19102 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19103 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19104 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19105 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19106 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19107 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19108 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19109
19110 /* "neighbor override-capability" commands. */
19111 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19112 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19113
19114 /* "neighbor strict-capability-match" commands. */
19115 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19116 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19117
19118 /* "neighbor timers" commands. */
19119 install_element(BGP_NODE, &neighbor_timers_cmd);
19120 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19121
19122 /* "neighbor timers connect" commands. */
19123 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19124 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19125
d43114f3
DS
19126 /* "neighbor timers delayopen" commands. */
19127 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19128 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19129
d62a17ae 19130 /* "neighbor advertisement-interval" commands. */
19131 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19132 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19133
19134 /* "neighbor interface" commands. */
19135 install_element(BGP_NODE, &neighbor_interface_cmd);
19136 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19137
19138 /* "neighbor distribute" commands. */
19139 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19140 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19141 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19142 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19143 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19144 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19145 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19146 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19147 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19148 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19149 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19150 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19151 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19152 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19153 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19154 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19155 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19156 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19157
19158 /* "neighbor prefix-list" commands. */
19159 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 19160 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 19161 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19162 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19163 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 19164 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19165 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 19166 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19167 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19168 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19169 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 19170 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19171 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 19172 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19173 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19174 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19175 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19176 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19177 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 19178 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 19179 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 19180 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 19181
19182 /* "neighbor filter-list" commands. */
19183 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19184 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19185 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19186 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19187 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19188 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19189 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19190 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19191 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19192 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19193 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19194 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19195 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19196 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19197 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19198 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19199 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19200 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19201 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19202 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19203 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19204 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19205
19206 /* "neighbor route-map" commands. */
d6d7ed37
IR
19207 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
19208 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 19209 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19210 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19211 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 19212 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19213 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 19214 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19215 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19216 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19217 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 19218 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19219 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 19220 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19221 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19222 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19223 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19224 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19225 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 19226 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 19227 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 19228 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 19229 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 19230 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 19231
19232 /* "neighbor unsuppress-map" commands. */
19233 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19234 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19235 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19236 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19237 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19238 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19239 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19240 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19241 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19242 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19243 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19244 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19245 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19246 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19247 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19248 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19249 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19250 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19251
7f7940e6 19252 /* "neighbor advertise-map" commands. */
389e4f92 19253 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 19254 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19255 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19256 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19257 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19258 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19259 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19260 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19261 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19262 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19263
fde246e8
DA
19264 /* neighbor maximum-prefix-out commands. */
19265 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19266 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19267 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19268 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19269 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19270 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19271 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19272 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19273 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19274 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19275 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19276 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19277 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19278 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19279 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19280 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19281 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19282 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19283
d62a17ae 19284 /* "neighbor maximum-prefix" commands. */
19285 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19286 install_element(BGP_NODE,
19287 &neighbor_maximum_prefix_threshold_hidden_cmd);
19288 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19289 install_element(BGP_NODE,
19290 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19291 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19292 install_element(BGP_NODE,
19293 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19294 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19295 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19296 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19297 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19298 install_element(BGP_IPV4_NODE,
19299 &neighbor_maximum_prefix_threshold_warning_cmd);
19300 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19301 install_element(BGP_IPV4_NODE,
19302 &neighbor_maximum_prefix_threshold_restart_cmd);
19303 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19304 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19305 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19306 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19307 install_element(BGP_IPV4M_NODE,
19308 &neighbor_maximum_prefix_threshold_warning_cmd);
19309 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19310 install_element(BGP_IPV4M_NODE,
19311 &neighbor_maximum_prefix_threshold_restart_cmd);
19312 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19313 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19314 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19315 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19316 install_element(BGP_IPV4L_NODE,
19317 &neighbor_maximum_prefix_threshold_warning_cmd);
19318 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19319 install_element(BGP_IPV4L_NODE,
19320 &neighbor_maximum_prefix_threshold_restart_cmd);
19321 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19322 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19323 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19324 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19325 install_element(BGP_IPV6_NODE,
19326 &neighbor_maximum_prefix_threshold_warning_cmd);
19327 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19328 install_element(BGP_IPV6_NODE,
19329 &neighbor_maximum_prefix_threshold_restart_cmd);
19330 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19331 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19332 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19333 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19334 install_element(BGP_IPV6M_NODE,
19335 &neighbor_maximum_prefix_threshold_warning_cmd);
19336 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19337 install_element(BGP_IPV6M_NODE,
19338 &neighbor_maximum_prefix_threshold_restart_cmd);
19339 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19340 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19341 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19342 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19343 install_element(BGP_IPV6L_NODE,
19344 &neighbor_maximum_prefix_threshold_warning_cmd);
19345 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19346 install_element(BGP_IPV6L_NODE,
19347 &neighbor_maximum_prefix_threshold_restart_cmd);
19348 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19349 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19350 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19351 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19352 install_element(BGP_VPNV4_NODE,
19353 &neighbor_maximum_prefix_threshold_warning_cmd);
19354 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19355 install_element(BGP_VPNV4_NODE,
19356 &neighbor_maximum_prefix_threshold_restart_cmd);
19357 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19358 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19359 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19360 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19361 install_element(BGP_VPNV6_NODE,
19362 &neighbor_maximum_prefix_threshold_warning_cmd);
19363 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19364 install_element(BGP_VPNV6_NODE,
19365 &neighbor_maximum_prefix_threshold_restart_cmd);
19366 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19367
19368 /* "neighbor allowas-in" */
19369 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19370 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19371 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19372 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19373 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19374 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19375 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19376 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19377 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19378 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19379 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19380 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19381 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19382 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19383 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19384 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19385 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19386 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19387 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19388 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19389
01da2d26
DA
19390 /* "neighbor soo" */
19391 install_element(BGP_IPV4_NODE, &neighbor_soo_cmd);
19392 install_element(BGP_IPV4_NODE, &no_neighbor_soo_cmd);
19393 install_element(BGP_IPV4M_NODE, &neighbor_soo_cmd);
19394 install_element(BGP_IPV4M_NODE, &no_neighbor_soo_cmd);
19395 install_element(BGP_IPV4L_NODE, &neighbor_soo_cmd);
19396 install_element(BGP_IPV4L_NODE, &no_neighbor_soo_cmd);
19397 install_element(BGP_IPV6_NODE, &neighbor_soo_cmd);
19398 install_element(BGP_IPV6_NODE, &no_neighbor_soo_cmd);
19399 install_element(BGP_IPV6M_NODE, &neighbor_soo_cmd);
19400 install_element(BGP_IPV6M_NODE, &no_neighbor_soo_cmd);
19401 install_element(BGP_IPV6L_NODE, &neighbor_soo_cmd);
19402 install_element(BGP_IPV6L_NODE, &no_neighbor_soo_cmd);
19403 install_element(BGP_VPNV4_NODE, &neighbor_soo_cmd);
19404 install_element(BGP_VPNV4_NODE, &no_neighbor_soo_cmd);
19405 install_element(BGP_VPNV6_NODE, &neighbor_soo_cmd);
19406 install_element(BGP_VPNV6_NODE, &no_neighbor_soo_cmd);
19407 install_element(BGP_EVPN_NODE, &neighbor_soo_cmd);
19408 install_element(BGP_EVPN_NODE, &no_neighbor_soo_cmd);
19409
d62a17ae 19410 /* address-family commands. */
19411 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19412 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19413#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19414 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19415 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19416#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19417
d62a17ae 19418 install_element(BGP_NODE, &address_family_evpn_cmd);
19419
19420 /* "exit-address-family" command. */
19421 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19422 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19423 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19424 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19425 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19426 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19427 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19428 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19429 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19430 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19431 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19432
a486300b
PG
19433 /* BGP retain all route-target */
19434 install_element(BGP_VPNV4_NODE, &bgp_retain_route_target_cmd);
19435 install_element(BGP_VPNV6_NODE, &bgp_retain_route_target_cmd);
19436
d62a17ae 19437 /* "clear ip bgp commands" */
19438 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19439
19440 /* clear ip bgp prefix */
19441 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19442 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19443 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19444
19445 /* "show [ip] bgp summary" commands. */
19446 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19447 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19448 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19449 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19450 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19451 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19452 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19453
19454 /* "show [ip] bgp neighbors" commands. */
19455 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19456
36235319 19457 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19458
d62a17ae 19459 /* "show [ip] bgp peer-group" commands. */
19460 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19461
19462 /* "show [ip] bgp paths" commands. */
19463 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19464
19465 /* "show [ip] bgp community" commands. */
19466 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19467
19468 /* "show ip bgp large-community" commands. */
19469 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19470 /* "show [ip] bgp attribute-info" commands. */
19471 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19472 /* "show [ip] bgp route-leak" command */
19473 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19474
19475 /* "redistribute" commands. */
19476 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19477 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19478 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19479 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19480 install_element(BGP_NODE,
19481 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19482 install_element(BGP_NODE,
19483 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19484 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19485 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19486 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19487 install_element(BGP_NODE,
19488 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19489 install_element(BGP_NODE,
19490 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19491 install_element(BGP_NODE,
19492 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19493 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19494 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19495 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19496 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19497 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19498 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19499 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19500 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19501 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19502 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19503 install_element(BGP_IPV4_NODE,
19504 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19505 install_element(BGP_IPV4_NODE,
19506 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19507 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19508 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19509 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19510 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19511 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19512 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19513
70dd370f 19514 /* import|export vpn [route-map RMAP_NAME] */
b9c7bc5a
PZ
19515 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19516 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19517
12a844a5
DS
19518 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19519 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19520
d62a17ae 19521 /* ttl_security commands */
19522 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19523 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19524
19525 /* "show [ip] bgp memory" commands. */
19526 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19527
acf71666
MK
19528 /* "show bgp martian next-hop" */
19529 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19530
48ecf8f5
DS
19531 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19532
d62a17ae 19533 /* "show [ip] bgp views" commands. */
19534 install_element(VIEW_NODE, &show_bgp_views_cmd);
19535
19536 /* "show [ip] bgp vrfs" commands. */
19537 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19538
19539 /* Community-list. */
19540 community_list_vty();
ddb5b488 19541
ed0e57e3
DA
19542 community_alias_vty();
19543
ddb5b488 19544 /* vpn-policy commands */
b9c7bc5a
PZ
19545 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19546 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19547 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19548 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19549 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19550 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19551 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19552 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19553 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19554 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19555 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19556 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19557
301ad80a
PG
19558 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19559 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19560
b9c7bc5a
PZ
19561 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19562 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19563 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19564 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19565 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19566 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19567 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19568 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19569 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19570 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19571
19572 /* tcp-mss command */
19573 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19574 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19575
19576 /* srv6 commands */
ea372e81 19577 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 19578 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 19579 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 19580 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 19581 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
19582 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19583 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19584}
6b0655a2 19585
718e3744 19586#include "memory.h"
19587#include "bgp_regex.h"
19588#include "bgp_clist.h"
19589#include "bgp_ecommunity.h"
19590
19591/* VTY functions. */
19592
19593/* Direction value to string conversion. */
d62a17ae 19594static const char *community_direct_str(int direct)
19595{
19596 switch (direct) {
19597 case COMMUNITY_DENY:
19598 return "deny";
19599 case COMMUNITY_PERMIT:
19600 return "permit";
19601 default:
19602 return "unknown";
19603 }
718e3744 19604}
19605
19606/* Display error string. */
d62a17ae 19607static void community_list_perror(struct vty *vty, int ret)
19608{
19609 switch (ret) {
19610 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19611 vty_out(vty, "%% Can't find community-list\n");
19612 break;
19613 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19614 vty_out(vty, "%% Malformed community-list value\n");
19615 break;
19616 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19617 vty_out(vty,
19618 "%% Community name conflict, previously defined as standard community\n");
19619 break;
19620 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19621 vty_out(vty,
19622 "%% Community name conflict, previously defined as expanded community\n");
19623 break;
19624 }
718e3744 19625}
19626
5bf15956
DW
19627/* "community-list" keyword help string. */
19628#define COMMUNITY_LIST_STR "Add a community list entry\n"
19629
7336e101
SP
19630/*community-list standard */
19631DEFUN (community_list_standard,
19632 bgp_community_list_standard_cmd,
a2099c1d 19633 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19634 BGP_STR
718e3744 19635 COMMUNITY_LIST_STR
19636 "Community list number (standard)\n"
5bf15956 19637 "Add an standard community-list entry\n"
718e3744 19638 "Community list name\n"
2f8cc0e5
DA
19639 "Sequence number of an entry\n"
19640 "Sequence number\n"
718e3744 19641 "Specify community to reject\n"
19642 "Specify community to accept\n"
19643 COMMUNITY_VAL_STR)
19644{
d62a17ae 19645 char *cl_name_or_number = NULL;
2f8cc0e5 19646 char *seq = NULL;
d62a17ae 19647 int direct = 0;
19648 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19649 int idx = 0;
7336e101 19650
e34627f9 19651 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19652 seq = argv[idx]->arg;
19653
19654 idx = 0;
d62a17ae 19655 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19656 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19657 cl_name_or_number = argv[idx]->arg;
19658 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19659 : COMMUNITY_DENY;
19660 argv_find(argv, argc, "AA:NN", &idx);
19661 char *str = argv_concat(argv, argc, idx);
42f914d4 19662
2f8cc0e5
DA
19663 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19664 direct, style);
42f914d4 19665
d62a17ae 19666 XFREE(MTYPE_TMP, str);
42f914d4 19667
d62a17ae 19668 if (ret < 0) {
19669 /* Display error string. */
19670 community_list_perror(vty, ret);
19671 return CMD_WARNING_CONFIG_FAILED;
19672 }
42f914d4 19673
d62a17ae 19674 return CMD_SUCCESS;
718e3744 19675}
19676
7336e101
SP
19677DEFUN (no_community_list_standard_all,
19678 no_bgp_community_list_standard_all_cmd,
a2099c1d 19679 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19680 NO_STR
19681 BGP_STR
19682 COMMUNITY_LIST_STR
19683 "Community list number (standard)\n"
19684 "Add an standard community-list entry\n"
19685 "Community list name\n"
2f8cc0e5
DA
19686 "Sequence number of an entry\n"
19687 "Sequence number\n"
7336e101
SP
19688 "Specify community to reject\n"
19689 "Specify community to accept\n"
19690 COMMUNITY_VAL_STR)
718e3744 19691{
d62a17ae 19692 char *cl_name_or_number = NULL;
174b5cb9 19693 char *str = NULL;
d62a17ae 19694 int direct = 0;
19695 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19696 char *seq = NULL;
d62a17ae 19697 int idx = 0;
7336e101 19698
e34627f9 19699 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19700 seq = argv[idx]->arg;
19701
19702 idx = 0;
174b5cb9
DA
19703 argv_find(argv, argc, "permit", &idx);
19704 argv_find(argv, argc, "deny", &idx);
19705
19706 if (idx) {
19707 direct = argv_find(argv, argc, "permit", &idx)
19708 ? COMMUNITY_PERMIT
19709 : COMMUNITY_DENY;
19710
19711 idx = 0;
19712 argv_find(argv, argc, "AA:NN", &idx);
19713 str = argv_concat(argv, argc, idx);
19714 }
19715
19716 idx = 0;
d62a17ae 19717 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19718 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19719 cl_name_or_number = argv[idx]->arg;
42f914d4 19720
2f8cc0e5 19721 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19722 direct, style);
42f914d4 19723
d62a17ae 19724 XFREE(MTYPE_TMP, str);
daf9ddbb 19725
d62a17ae 19726 if (ret < 0) {
19727 community_list_perror(vty, ret);
19728 return CMD_WARNING_CONFIG_FAILED;
19729 }
42f914d4 19730
d62a17ae 19731 return CMD_SUCCESS;
718e3744 19732}
7336e101 19733
174b5cb9 19734ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19735 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19736 NO_STR BGP_STR COMMUNITY_LIST_STR
19737 "Community list number (standard)\n"
19738 "Add an standard community-list entry\n"
19739 "Community list name\n")
19740
7336e101
SP
19741/*community-list expanded */
19742DEFUN (community_list_expanded_all,
19743 bgp_community_list_expanded_all_cmd,
a2099c1d 19744 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19745 BGP_STR
19746 COMMUNITY_LIST_STR
718e3744 19747 "Community list number (expanded)\n"
5bf15956 19748 "Add an expanded community-list entry\n"
718e3744 19749 "Community list name\n"
2f8cc0e5
DA
19750 "Sequence number of an entry\n"
19751 "Sequence number\n"
718e3744 19752 "Specify community to reject\n"
19753 "Specify community to accept\n"
19754 COMMUNITY_VAL_STR)
19755{
d62a17ae 19756 char *cl_name_or_number = NULL;
2f8cc0e5 19757 char *seq = NULL;
d62a17ae 19758 int direct = 0;
19759 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19760 int idx = 0;
7b9a4750 19761
e34627f9 19762 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19763 seq = argv[idx]->arg;
19764
19765 idx = 0;
19766
d62a17ae 19767 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19768 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19769 cl_name_or_number = argv[idx]->arg;
19770 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19771 : COMMUNITY_DENY;
19772 argv_find(argv, argc, "AA:NN", &idx);
19773 char *str = argv_concat(argv, argc, idx);
42f914d4 19774
2f8cc0e5
DA
19775 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19776 direct, style);
42f914d4 19777
d62a17ae 19778 XFREE(MTYPE_TMP, str);
42f914d4 19779
d62a17ae 19780 if (ret < 0) {
19781 /* Display error string. */
19782 community_list_perror(vty, ret);
19783 return CMD_WARNING_CONFIG_FAILED;
19784 }
42f914d4 19785
d62a17ae 19786 return CMD_SUCCESS;
718e3744 19787}
19788
7336e101
SP
19789DEFUN (no_community_list_expanded_all,
19790 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19791 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19792 NO_STR
19793 BGP_STR
19794 COMMUNITY_LIST_STR
19795 "Community list number (expanded)\n"
19796 "Add an expanded community-list entry\n"
19797 "Community list name\n"
2f8cc0e5
DA
19798 "Sequence number of an entry\n"
19799 "Sequence number\n"
7336e101
SP
19800 "Specify community to reject\n"
19801 "Specify community to accept\n"
19802 COMMUNITY_VAL_STR)
718e3744 19803{
d62a17ae 19804 char *cl_name_or_number = NULL;
2f8cc0e5 19805 char *seq = NULL;
174b5cb9 19806 char *str = NULL;
d62a17ae 19807 int direct = 0;
19808 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19809 int idx = 0;
174b5cb9 19810
e34627f9 19811 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19812 seq = argv[idx]->arg;
19813
19814 idx = 0;
174b5cb9
DA
19815 argv_find(argv, argc, "permit", &idx);
19816 argv_find(argv, argc, "deny", &idx);
19817
19818 if (idx) {
19819 direct = argv_find(argv, argc, "permit", &idx)
19820 ? COMMUNITY_PERMIT
19821 : COMMUNITY_DENY;
19822
19823 idx = 0;
19824 argv_find(argv, argc, "AA:NN", &idx);
19825 str = argv_concat(argv, argc, idx);
7336e101 19826 }
174b5cb9
DA
19827
19828 idx = 0;
d62a17ae 19829 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19830 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19831 cl_name_or_number = argv[idx]->arg;
42f914d4 19832
2f8cc0e5 19833 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19834 direct, style);
42f914d4 19835
d62a17ae 19836 XFREE(MTYPE_TMP, str);
daf9ddbb 19837
d62a17ae 19838 if (ret < 0) {
19839 community_list_perror(vty, ret);
19840 return CMD_WARNING_CONFIG_FAILED;
19841 }
42f914d4 19842
d62a17ae 19843 return CMD_SUCCESS;
718e3744 19844}
19845
36d4bb44
EB
19846ALIAS(no_community_list_expanded_all,
19847 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19848 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19849 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19850 "Community list number (expanded)\n"
19851 "Add an expanded community-list entry\n"
19852 "Community list name\n")
19853
8d9b8ed9
PM
19854/* Return configuration string of community-list entry. */
19855static const char *community_list_config_str(struct community_entry *entry)
19856{
19857 const char *str;
19858
19859 if (entry->any)
19860 str = "";
19861 else {
19862 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 19863 str = community_str(entry->u.com, false, false);
8d9b8ed9 19864 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 19865 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
19866 else
19867 str = entry->config;
19868 }
19869 return str;
19870}
19871
d62a17ae 19872static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19873{
d62a17ae 19874 struct community_entry *entry;
718e3744 19875
d62a17ae 19876 for (entry = list->head; entry; entry = entry->next) {
19877 if (entry == list->head) {
19878 if (all_digit(list->name))
19879 vty_out(vty, "Community %s list %s\n",
19880 entry->style == COMMUNITY_LIST_STANDARD
19881 ? "standard"
19882 : "(expanded) access",
19883 list->name);
19884 else
19885 vty_out(vty, "Named Community %s list %s\n",
19886 entry->style == COMMUNITY_LIST_STANDARD
19887 ? "standard"
19888 : "expanded",
19889 list->name);
19890 }
19891 if (entry->any)
19892 vty_out(vty, " %s\n",
19893 community_direct_str(entry->direct));
19894 else
19895 vty_out(vty, " %s %s\n",
19896 community_direct_str(entry->direct),
8d9b8ed9 19897 community_list_config_str(entry));
d62a17ae 19898 }
718e3744 19899}
19900
7336e101
SP
19901DEFUN (show_community_list,
19902 show_bgp_community_list_cmd,
19903 "show bgp community-list",
718e3744 19904 SHOW_STR
7336e101 19905 BGP_STR
718e3744 19906 "List community-list\n")
19907{
d62a17ae 19908 struct community_list *list;
19909 struct community_list_master *cm;
718e3744 19910
d62a17ae 19911 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19912 if (!cm)
19913 return CMD_SUCCESS;
718e3744 19914
d62a17ae 19915 for (list = cm->num.head; list; list = list->next)
19916 community_list_show(vty, list);
718e3744 19917
d62a17ae 19918 for (list = cm->str.head; list; list = list->next)
19919 community_list_show(vty, list);
718e3744 19920
d62a17ae 19921 return CMD_SUCCESS;
718e3744 19922}
19923
7336e101
SP
19924DEFUN (show_community_list_arg,
19925 show_bgp_community_list_arg_cmd,
a2099c1d 19926 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19927 SHOW_STR
19928 BGP_STR
718e3744 19929 "List community-list\n"
19930 "Community-list number\n"
960b69b9 19931 "Community-list name\n"
19932 "Detailed information on community-list\n")
718e3744 19933{
d62a17ae 19934 int idx_comm_list = 3;
19935 struct community_list *list;
718e3744 19936
e237b0d2 19937 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19938 COMMUNITY_LIST_MASTER);
19939 if (!list) {
19940 vty_out(vty, "%% Can't find community-list\n");
19941 return CMD_WARNING;
19942 }
718e3744 19943
d62a17ae 19944 community_list_show(vty, list);
718e3744 19945
d62a17ae 19946 return CMD_SUCCESS;
718e3744 19947}
6b0655a2 19948
57d187bc
JS
19949/*
19950 * Large Community code.
19951 */
d62a17ae 19952static int lcommunity_list_set_vty(struct vty *vty, int argc,
19953 struct cmd_token **argv, int style,
19954 int reject_all_digit_name)
19955{
19956 int ret;
19957 int direct;
19958 char *str;
19959 int idx = 0;
19960 char *cl_name;
2f8cc0e5
DA
19961 char *seq = NULL;
19962
a08032fe 19963 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19964 seq = argv[idx]->arg;
d62a17ae 19965
2f8cc0e5 19966 idx = 0;
d62a17ae 19967 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19968 : COMMUNITY_DENY;
19969
19970 /* All digit name check. */
19971 idx = 0;
a2099c1d 19972 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19973 argv_find(argv, argc, "(1-99)", &idx);
19974 argv_find(argv, argc, "(100-500)", &idx);
19975 cl_name = argv[idx]->arg;
19976 if (reject_all_digit_name && all_digit(cl_name)) {
19977 vty_out(vty, "%% Community name cannot have all digits\n");
19978 return CMD_WARNING_CONFIG_FAILED;
19979 }
19980
19981 idx = 0;
19982 argv_find(argv, argc, "AA:BB:CC", &idx);
19983 argv_find(argv, argc, "LINE", &idx);
19984 /* Concat community string argument. */
19985 if (idx)
19986 str = argv_concat(argv, argc, idx);
19987 else
19988 str = NULL;
19989
2f8cc0e5 19990 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19991
19992 /* Free temporary community list string allocated by
19993 argv_concat(). */
0a22ddfb 19994 XFREE(MTYPE_TMP, str);
d62a17ae 19995
19996 if (ret < 0) {
19997 community_list_perror(vty, ret);
19998 return CMD_WARNING_CONFIG_FAILED;
19999 }
20000 return CMD_SUCCESS;
20001}
20002
20003static int lcommunity_list_unset_vty(struct vty *vty, int argc,
20004 struct cmd_token **argv, int style)
20005{
20006 int ret;
20007 int direct = 0;
20008 char *str = NULL;
20009 int idx = 0;
2f8cc0e5 20010 char *seq = NULL;
d62a17ae 20011
a08032fe 20012 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20013 seq = argv[idx]->arg;
d62a17ae 20014
2f8cc0e5 20015 idx = 0;
d62a17ae 20016 argv_find(argv, argc, "permit", &idx);
20017 argv_find(argv, argc, "deny", &idx);
20018
20019 if (idx) {
20020 /* Check the list direct. */
20021 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20022 direct = COMMUNITY_PERMIT;
20023 else
20024 direct = COMMUNITY_DENY;
20025
20026 idx = 0;
20027 argv_find(argv, argc, "LINE", &idx);
20028 argv_find(argv, argc, "AA:AA:NN", &idx);
20029 /* Concat community string argument. */
20030 str = argv_concat(argv, argc, idx);
20031 }
20032
20033 idx = 0;
20034 argv_find(argv, argc, "(1-99)", &idx);
20035 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20036 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20037
20038 /* Unset community list. */
2f8cc0e5 20039 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20040 style);
20041
20042 /* Free temporary community list string allocated by
20043 argv_concat(). */
0a22ddfb 20044 XFREE(MTYPE_TMP, str);
d62a17ae 20045
20046 if (ret < 0) {
20047 community_list_perror(vty, ret);
20048 return CMD_WARNING_CONFIG_FAILED;
20049 }
20050
20051 return CMD_SUCCESS;
57d187bc
JS
20052}
20053
20054/* "large-community-list" keyword help string. */
20055#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20056#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20057
7336e101
SP
20058DEFUN (lcommunity_list_standard,
20059 bgp_lcommunity_list_standard_cmd,
a08032fe 20060 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20061 BGP_STR
20062 LCOMMUNITY_LIST_STR
20063 "Large Community list number (standard)\n"
2f8cc0e5
DA
20064 "Sequence number of an entry\n"
20065 "Sequence number\n"
7336e101
SP
20066 "Specify large community to reject\n"
20067 "Specify large community to accept\n"
20068 LCOMMUNITY_VAL_STR)
52951b63 20069{
d62a17ae 20070 return lcommunity_list_set_vty(vty, argc, argv,
20071 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20072}
20073
7336e101
SP
20074DEFUN (lcommunity_list_expanded,
20075 bgp_lcommunity_list_expanded_cmd,
a08032fe 20076 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20077 BGP_STR
20078 LCOMMUNITY_LIST_STR
20079 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20080 "Sequence number of an entry\n"
20081 "Sequence number\n"
7336e101
SP
20082 "Specify large community to reject\n"
20083 "Specify large community to accept\n"
20084 "An ordered list as a regular-expression\n")
57d187bc 20085{
d62a17ae 20086 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20087 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20088}
20089
7336e101
SP
20090DEFUN (lcommunity_list_name_standard,
20091 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20092 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20093 BGP_STR
20094 LCOMMUNITY_LIST_STR
20095 "Specify standard large-community-list\n"
20096 "Large Community list name\n"
2f8cc0e5
DA
20097 "Sequence number of an entry\n"
20098 "Sequence number\n"
7336e101
SP
20099 "Specify large community to reject\n"
20100 "Specify large community to accept\n"
20101 LCOMMUNITY_VAL_STR)
52951b63 20102{
d62a17ae 20103 return lcommunity_list_set_vty(vty, argc, argv,
20104 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20105}
20106
7336e101
SP
20107DEFUN (lcommunity_list_name_expanded,
20108 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20109 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20110 BGP_STR
20111 LCOMMUNITY_LIST_STR
20112 "Specify expanded large-community-list\n"
20113 "Large Community list name\n"
2f8cc0e5
DA
20114 "Sequence number of an entry\n"
20115 "Sequence number\n"
7336e101
SP
20116 "Specify large community to reject\n"
20117 "Specify large community to accept\n"
20118 "An ordered list as a regular-expression\n")
57d187bc 20119{
d62a17ae 20120 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20121 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20122}
20123
4378f57c
DA
20124DEFUN (no_lcommunity_list_all,
20125 no_bgp_lcommunity_list_all_cmd,
a2099c1d 20126 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
20127 NO_STR
20128 BGP_STR
20129 LCOMMUNITY_LIST_STR
20130 "Large Community list number (standard)\n"
20131 "Large Community list number (expanded)\n"
20132 "Large Community list name\n")
57d187bc 20133{
7336e101
SP
20134 return lcommunity_list_unset_vty(vty, argc, argv,
20135 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20136}
20137
4378f57c
DA
20138DEFUN (no_lcommunity_list_name_standard_all,
20139 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 20140 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
20141 NO_STR
20142 BGP_STR
20143 LCOMMUNITY_LIST_STR
20144 "Specify standard large-community-list\n"
20145 "Large Community list name\n")
20146{
20147 return lcommunity_list_unset_vty(vty, argc, argv,
20148 LARGE_COMMUNITY_LIST_STANDARD);
20149}
20150
7336e101
SP
20151DEFUN (no_lcommunity_list_name_expanded_all,
20152 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 20153 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
20154 NO_STR
20155 BGP_STR
20156 LCOMMUNITY_LIST_STR
20157 "Specify expanded large-community-list\n"
20158 "Large Community list name\n")
57d187bc 20159{
d62a17ae 20160 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20161 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20162}
20163
7336e101
SP
20164DEFUN (no_lcommunity_list_standard,
20165 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20166 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20167 NO_STR
20168 BGP_STR
20169 LCOMMUNITY_LIST_STR
20170 "Large Community list number (standard)\n"
2f8cc0e5
DA
20171 "Sequence number of an entry\n"
20172 "Sequence number\n"
7336e101
SP
20173 "Specify large community to reject\n"
20174 "Specify large community to accept\n"
20175 LCOMMUNITY_VAL_STR)
57d187bc 20176{
d62a17ae 20177 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20178 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20179}
20180
7336e101
SP
20181DEFUN (no_lcommunity_list_expanded,
20182 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20183 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20184 NO_STR
20185 BGP_STR
20186 LCOMMUNITY_LIST_STR
20187 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20188 "Sequence number of an entry\n"
20189 "Sequence number\n"
7336e101
SP
20190 "Specify large community to reject\n"
20191 "Specify large community to accept\n"
20192 "An ordered list as a regular-expression\n")
57d187bc 20193{
d62a17ae 20194 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20195 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20196}
20197
7336e101
SP
20198DEFUN (no_lcommunity_list_name_standard,
20199 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 20200 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20201 NO_STR
20202 BGP_STR
20203 LCOMMUNITY_LIST_STR
20204 "Specify standard large-community-list\n"
20205 "Large Community list name\n"
2f8cc0e5
DA
20206 "Sequence number of an entry\n"
20207 "Sequence number\n"
7336e101
SP
20208 "Specify large community to reject\n"
20209 "Specify large community to accept\n"
20210 LCOMMUNITY_VAL_STR)
57d187bc 20211{
d62a17ae 20212 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20213 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20214}
20215
7336e101
SP
20216DEFUN (no_lcommunity_list_name_expanded,
20217 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 20218 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20219 NO_STR
20220 BGP_STR
20221 LCOMMUNITY_LIST_STR
20222 "Specify expanded large-community-list\n"
20223 "Large community list name\n"
2f8cc0e5
DA
20224 "Sequence number of an entry\n"
20225 "Sequence number\n"
7336e101
SP
20226 "Specify large community to reject\n"
20227 "Specify large community to accept\n"
20228 "An ordered list as a regular-expression\n")
57d187bc 20229{
d62a17ae 20230 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20231 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20232}
20233
d62a17ae 20234static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20235{
20236 struct community_entry *entry;
20237
20238 for (entry = list->head; entry; entry = entry->next) {
20239 if (entry == list->head) {
20240 if (all_digit(list->name))
20241 vty_out(vty, "Large community %s list %s\n",
169b72c8 20242 entry->style ==
20243 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20244 ? "standard"
20245 : "(expanded) access",
20246 list->name);
20247 else
20248 vty_out(vty,
20249 "Named large community %s list %s\n",
169b72c8 20250 entry->style ==
20251 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20252 ? "standard"
20253 : "expanded",
20254 list->name);
20255 }
20256 if (entry->any)
20257 vty_out(vty, " %s\n",
20258 community_direct_str(entry->direct));
20259 else
20260 vty_out(vty, " %s %s\n",
20261 community_direct_str(entry->direct),
8d9b8ed9 20262 community_list_config_str(entry));
d62a17ae 20263 }
57d187bc
JS
20264}
20265
7336e101
SP
20266DEFUN (show_lcommunity_list,
20267 show_bgp_lcommunity_list_cmd,
20268 "show bgp large-community-list",
57d187bc 20269 SHOW_STR
7336e101 20270 BGP_STR
57d187bc
JS
20271 "List large-community list\n")
20272{
d62a17ae 20273 struct community_list *list;
20274 struct community_list_master *cm;
57d187bc 20275
d62a17ae 20276 cm = community_list_master_lookup(bgp_clist,
20277 LARGE_COMMUNITY_LIST_MASTER);
20278 if (!cm)
20279 return CMD_SUCCESS;
57d187bc 20280
d62a17ae 20281 for (list = cm->num.head; list; list = list->next)
20282 lcommunity_list_show(vty, list);
57d187bc 20283
d62a17ae 20284 for (list = cm->str.head; list; list = list->next)
20285 lcommunity_list_show(vty, list);
57d187bc 20286
d62a17ae 20287 return CMD_SUCCESS;
57d187bc
JS
20288}
20289
7336e101
SP
20290DEFUN (show_lcommunity_list_arg,
20291 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 20292 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20293 SHOW_STR
20294 BGP_STR
57d187bc 20295 "List large-community list\n"
960b69b9 20296 "Large-community-list number\n"
20297 "Large-community-list name\n"
20298 "Detailed information on large-community-list\n")
57d187bc 20299{
d62a17ae 20300 struct community_list *list;
57d187bc 20301
e237b0d2 20302 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20303 LARGE_COMMUNITY_LIST_MASTER);
20304 if (!list) {
960b69b9 20305 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20306 return CMD_WARNING;
20307 }
57d187bc 20308
d62a17ae 20309 lcommunity_list_show(vty, list);
57d187bc 20310
d62a17ae 20311 return CMD_SUCCESS;
57d187bc
JS
20312}
20313
718e3744 20314/* "extcommunity-list" keyword help string. */
20315#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20316#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20317
7336e101
SP
20318DEFUN (extcommunity_list_standard,
20319 bgp_extcommunity_list_standard_cmd,
a2099c1d 20320 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20321 BGP_STR
718e3744 20322 EXTCOMMUNITY_LIST_STR
20323 "Extended Community list number (standard)\n"
718e3744 20324 "Specify standard extcommunity-list\n"
5bf15956 20325 "Community list name\n"
2f8cc0e5
DA
20326 "Sequence number of an entry\n"
20327 "Sequence number\n"
718e3744 20328 "Specify community to reject\n"
20329 "Specify community to accept\n"
20330 EXTCOMMUNITY_VAL_STR)
20331{
d62a17ae 20332 int style = EXTCOMMUNITY_LIST_STANDARD;
20333 int direct = 0;
20334 char *cl_number_or_name = NULL;
2f8cc0e5 20335 char *seq = NULL;
42f914d4 20336
d62a17ae 20337 int idx = 0;
7b9a4750 20338
d62a17ae 20339 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20340 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20341 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20342
a08032fe 20343 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20344 seq = argv[idx]->arg;
20345
d62a17ae 20346 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20347 : COMMUNITY_DENY;
20348 argv_find(argv, argc, "AA:NN", &idx);
20349 char *str = argv_concat(argv, argc, idx);
42f914d4 20350
2f8cc0e5 20351 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20352 direct, style);
42f914d4 20353
d62a17ae 20354 XFREE(MTYPE_TMP, str);
42f914d4 20355
d62a17ae 20356 if (ret < 0) {
20357 community_list_perror(vty, ret);
20358 return CMD_WARNING_CONFIG_FAILED;
20359 }
42f914d4 20360
d62a17ae 20361 return CMD_SUCCESS;
718e3744 20362}
20363
7336e101
SP
20364DEFUN (extcommunity_list_name_expanded,
20365 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 20366 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20367 BGP_STR
20368 EXTCOMMUNITY_LIST_STR
5bf15956 20369 "Extended Community list number (expanded)\n"
718e3744 20370 "Specify expanded extcommunity-list\n"
20371 "Extended Community list name\n"
2f8cc0e5
DA
20372 "Sequence number of an entry\n"
20373 "Sequence number\n"
718e3744 20374 "Specify community to reject\n"
20375 "Specify community to accept\n"
20376 "An ordered list as a regular-expression\n")
20377{
d62a17ae 20378 int style = EXTCOMMUNITY_LIST_EXPANDED;
20379 int direct = 0;
20380 char *cl_number_or_name = NULL;
2f8cc0e5 20381 char *seq = NULL;
d62a17ae 20382 int idx = 0;
7336e101 20383
d62a17ae 20384 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20385 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20386 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20387
a08032fe 20388 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20389 seq = argv[idx]->arg;
20390
d62a17ae 20391 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20392 : COMMUNITY_DENY;
20393 argv_find(argv, argc, "LINE", &idx);
20394 char *str = argv_concat(argv, argc, idx);
42f914d4 20395
2f8cc0e5 20396 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20397 direct, style);
42f914d4 20398
d62a17ae 20399 XFREE(MTYPE_TMP, str);
42f914d4 20400
d62a17ae 20401 if (ret < 0) {
20402 community_list_perror(vty, ret);
20403 return CMD_WARNING_CONFIG_FAILED;
20404 }
42f914d4 20405
d62a17ae 20406 return CMD_SUCCESS;
718e3744 20407}
20408
7336e101
SP
20409DEFUN (no_extcommunity_list_standard_all,
20410 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 20411 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20412 NO_STR
20413 BGP_STR
20414 EXTCOMMUNITY_LIST_STR
813d4307 20415 "Extended Community list number (standard)\n"
718e3744 20416 "Specify standard extcommunity-list\n"
5bf15956 20417 "Community list name\n"
2f8cc0e5
DA
20418 "Sequence number of an entry\n"
20419 "Sequence number\n"
718e3744 20420 "Specify community to reject\n"
20421 "Specify community to accept\n"
20422 EXTCOMMUNITY_VAL_STR)
20423{
d62a17ae 20424 int style = EXTCOMMUNITY_LIST_STANDARD;
20425 int direct = 0;
20426 char *cl_number_or_name = NULL;
d4455c89 20427 char *str = NULL;
2f8cc0e5 20428 char *seq = NULL;
d62a17ae 20429 int idx = 0;
d4455c89 20430
a08032fe 20431 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20432 seq = argv[idx]->arg;
20433
20434 idx = 0;
d4455c89
DA
20435 argv_find(argv, argc, "permit", &idx);
20436 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20437 if (idx) {
20438 direct = argv_find(argv, argc, "permit", &idx)
20439 ? COMMUNITY_PERMIT
20440 : COMMUNITY_DENY;
20441
20442 idx = 0;
20443 argv_find(argv, argc, "AA:NN", &idx);
20444 str = argv_concat(argv, argc, idx);
20445 }
20446
20447 idx = 0;
d62a17ae 20448 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20449 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20450 cl_number_or_name = argv[idx]->arg;
42f914d4 20451
d62a17ae 20452 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20453 seq, direct, style);
42f914d4 20454
d62a17ae 20455 XFREE(MTYPE_TMP, str);
42f914d4 20456
d62a17ae 20457 if (ret < 0) {
20458 community_list_perror(vty, ret);
20459 return CMD_WARNING_CONFIG_FAILED;
20460 }
42f914d4 20461
d62a17ae 20462 return CMD_SUCCESS;
718e3744 20463}
20464
d4455c89
DA
20465ALIAS(no_extcommunity_list_standard_all,
20466 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 20467 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20468 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20469 "Extended Community list number (standard)\n"
20470 "Specify standard extcommunity-list\n"
20471 "Community list name\n")
20472
7336e101
SP
20473DEFUN (no_extcommunity_list_expanded_all,
20474 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 20475 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20476 NO_STR
20477 BGP_STR
20478 EXTCOMMUNITY_LIST_STR
718e3744 20479 "Extended Community list number (expanded)\n"
718e3744 20480 "Specify expanded extcommunity-list\n"
5bf15956 20481 "Extended Community list name\n"
2f8cc0e5
DA
20482 "Sequence number of an entry\n"
20483 "Sequence number\n"
718e3744 20484 "Specify community to reject\n"
20485 "Specify community to accept\n"
20486 "An ordered list as a regular-expression\n")
20487{
d62a17ae 20488 int style = EXTCOMMUNITY_LIST_EXPANDED;
20489 int direct = 0;
20490 char *cl_number_or_name = NULL;
d4455c89 20491 char *str = NULL;
2f8cc0e5 20492 char *seq = NULL;
d62a17ae 20493 int idx = 0;
d4455c89 20494
a08032fe 20495 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20496 seq = argv[idx]->arg;
20497
20498 idx = 0;
d4455c89
DA
20499 argv_find(argv, argc, "permit", &idx);
20500 argv_find(argv, argc, "deny", &idx);
20501
20502 if (idx) {
20503 direct = argv_find(argv, argc, "permit", &idx)
20504 ? COMMUNITY_PERMIT
20505 : COMMUNITY_DENY;
20506
20507 idx = 0;
20508 argv_find(argv, argc, "LINE", &idx);
20509 str = argv_concat(argv, argc, idx);
20510 }
20511
20512 idx = 0;
d62a17ae 20513 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20514 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20515 cl_number_or_name = argv[idx]->arg;
42f914d4 20516
d62a17ae 20517 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20518 seq, direct, style);
42f914d4 20519
d62a17ae 20520 XFREE(MTYPE_TMP, str);
42f914d4 20521
d62a17ae 20522 if (ret < 0) {
20523 community_list_perror(vty, ret);
20524 return CMD_WARNING_CONFIG_FAILED;
20525 }
42f914d4 20526
d62a17ae 20527 return CMD_SUCCESS;
718e3744 20528}
20529
d4455c89
DA
20530ALIAS(no_extcommunity_list_expanded_all,
20531 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 20532 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20533 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20534 "Extended Community list number (expanded)\n"
20535 "Specify expanded extcommunity-list\n"
20536 "Extended Community list name\n")
20537
d62a17ae 20538static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20539{
d62a17ae 20540 struct community_entry *entry;
718e3744 20541
d62a17ae 20542 for (entry = list->head; entry; entry = entry->next) {
20543 if (entry == list->head) {
20544 if (all_digit(list->name))
20545 vty_out(vty, "Extended community %s list %s\n",
20546 entry->style == EXTCOMMUNITY_LIST_STANDARD
20547 ? "standard"
20548 : "(expanded) access",
20549 list->name);
20550 else
20551 vty_out(vty,
20552 "Named extended community %s list %s\n",
20553 entry->style == EXTCOMMUNITY_LIST_STANDARD
20554 ? "standard"
20555 : "expanded",
20556 list->name);
20557 }
20558 if (entry->any)
20559 vty_out(vty, " %s\n",
20560 community_direct_str(entry->direct));
20561 else
20562 vty_out(vty, " %s %s\n",
20563 community_direct_str(entry->direct),
8d9b8ed9 20564 community_list_config_str(entry));
d62a17ae 20565 }
718e3744 20566}
20567
7336e101
SP
20568DEFUN (show_extcommunity_list,
20569 show_bgp_extcommunity_list_cmd,
20570 "show bgp extcommunity-list",
718e3744 20571 SHOW_STR
7336e101 20572 BGP_STR
718e3744 20573 "List extended-community list\n")
20574{
d62a17ae 20575 struct community_list *list;
20576 struct community_list_master *cm;
718e3744 20577
d62a17ae 20578 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20579 if (!cm)
20580 return CMD_SUCCESS;
718e3744 20581
d62a17ae 20582 for (list = cm->num.head; list; list = list->next)
20583 extcommunity_list_show(vty, list);
718e3744 20584
d62a17ae 20585 for (list = cm->str.head; list; list = list->next)
20586 extcommunity_list_show(vty, list);
718e3744 20587
d62a17ae 20588 return CMD_SUCCESS;
718e3744 20589}
20590
7336e101
SP
20591DEFUN (show_extcommunity_list_arg,
20592 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20593 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20594 SHOW_STR
20595 BGP_STR
718e3744 20596 "List extended-community list\n"
20597 "Extcommunity-list number\n"
960b69b9 20598 "Extcommunity-list name\n"
20599 "Detailed information on extcommunity-list\n")
718e3744 20600{
d62a17ae 20601 int idx_comm_list = 3;
20602 struct community_list *list;
718e3744 20603
e237b0d2 20604 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20605 EXTCOMMUNITY_LIST_MASTER);
20606 if (!list) {
20607 vty_out(vty, "%% Can't find extcommunity-list\n");
20608 return CMD_WARNING;
20609 }
718e3744 20610
d62a17ae 20611 extcommunity_list_show(vty, list);
718e3744 20612
d62a17ae 20613 return CMD_SUCCESS;
718e3744 20614}
6b0655a2 20615
718e3744 20616/* Display community-list and extcommunity-list configuration. */
d62a17ae 20617static int community_list_config_write(struct vty *vty)
20618{
20619 struct community_list *list;
20620 struct community_entry *entry;
20621 struct community_list_master *cm;
20622 int write = 0;
20623
20624 /* Community-list. */
20625 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20626
20627 for (list = cm->num.head; list; list = list->next)
20628 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20629 vty_out(vty,
20630 "bgp community-list %s seq %" PRId64 " %s %s\n",
20631 list->name, entry->seq,
d62a17ae 20632 community_direct_str(entry->direct),
20633 community_list_config_str(entry));
20634 write++;
20635 }
20636 for (list = cm->str.head; list; list = list->next)
20637 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20638 vty_out(vty,
20639 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20640 entry->style == COMMUNITY_LIST_STANDARD
20641 ? "standard"
20642 : "expanded",
2f8cc0e5
DA
20643 list->name, entry->seq,
20644 community_direct_str(entry->direct),
d62a17ae 20645 community_list_config_str(entry));
20646 write++;
20647 }
20648
20649 /* Extcommunity-list. */
20650 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20651
20652 for (list = cm->num.head; list; list = list->next)
20653 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20654 vty_out(vty,
20655 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20656 list->name, entry->seq,
20657 community_direct_str(entry->direct),
d62a17ae 20658 community_list_config_str(entry));
20659 write++;
20660 }
20661 for (list = cm->str.head; list; list = list->next)
20662 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20663 vty_out(vty,
6cde4b45 20664 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20665 entry->style == EXTCOMMUNITY_LIST_STANDARD
20666 ? "standard"
20667 : "expanded",
2f8cc0e5
DA
20668 list->name, entry->seq,
20669 community_direct_str(entry->direct),
d62a17ae 20670 community_list_config_str(entry));
20671 write++;
20672 }
20673
20674
20675 /* lcommunity-list. */
20676 cm = community_list_master_lookup(bgp_clist,
20677 LARGE_COMMUNITY_LIST_MASTER);
20678
20679 for (list = cm->num.head; list; list = list->next)
20680 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20681 vty_out(vty,
6cde4b45 20682 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20683 list->name, entry->seq,
20684 community_direct_str(entry->direct),
d62a17ae 20685 community_list_config_str(entry));
20686 write++;
20687 }
20688 for (list = cm->str.head; list; list = list->next)
20689 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20690 vty_out(vty,
6cde4b45 20691 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20692
d62a17ae 20693 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20694 ? "standard"
20695 : "expanded",
2f8cc0e5 20696 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20697 community_list_config_str(entry));
20698 write++;
20699 }
20700
20701 return write;
20702}
20703
612c2c15 20704static int community_list_config_write(struct vty *vty);
d62a17ae 20705static struct cmd_node community_list_node = {
f4b8291f 20706 .name = "community list",
62b346ee
DL
20707 .node = COMMUNITY_LIST_NODE,
20708 .prompt = "",
612c2c15 20709 .config_write = community_list_config_write,
718e3744 20710};
20711
d62a17ae 20712static void community_list_vty(void)
20713{
612c2c15 20714 install_node(&community_list_node);
d62a17ae 20715
20716 /* Community-list. */
7336e101
SP
20717 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20718 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20719 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20720 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20721 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20722 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20723 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20724 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20725
20726 /* Extcommunity-list. */
7336e101
SP
20727 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20728 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20729 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20730 install_element(CONFIG_NODE,
20731 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20732 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20733 install_element(CONFIG_NODE,
20734 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20735 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20736 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20737
20738 /* Large Community List */
7336e101 20739 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20740 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20741 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20742 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20743 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20744 install_element(CONFIG_NODE,
20745 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20746 install_element(CONFIG_NODE,
20747 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20748 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20749 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20750 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20751 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20752 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20753 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20754
20755 bgp_community_list_command_completion_setup();
5bf15956 20756}
ed0e57e3
DA
20757
20758static struct cmd_node community_alias_node = {
20759 .name = "community alias",
20760 .node = COMMUNITY_ALIAS_NODE,
20761 .prompt = "",
20762 .config_write = bgp_community_alias_write,
20763};
20764
20765void community_alias_vty(void)
20766{
20767 install_node(&community_alias_node);
20768
20769 /* Community-list. */
20770 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20771
20772 bgp_community_alias_command_completion_setup();
ed0e57e3 20773}