]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #11180 from fdumontet6WIND/flag_pre_post
[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 */
309 for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk))
310 listnode_delete(bgp->srv6_locator_chunks, chunk);
311
312 /* refresh functions */
313 for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func))
314 listnode_delete(bgp->srv6_functions, func);
315
316 /* refresh tovpn_sid */
317 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) {
318 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF)
319 continue;
320
321 /* refresh vpnv4 tovpn_sid */
322 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid;
323 if (tovpn_sid)
324 XFREE(MTYPE_BGP_SRV6_SID,
325 bgp_vrf->vpn_policy[AFI_IP].tovpn_sid);
326
327 /* refresh vpnv6 tovpn_sid */
328 tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid;
329 if (tovpn_sid)
330 XFREE(MTYPE_BGP_SRV6_SID,
331 bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid);
332 }
333
334 /* update vpn bgp processes */
335 vpn_leak_postchange_all();
336
337 /* clear locator name */
338 memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name));
339
340 return 0;
341}
342
718e3744 343/* Utility function to get address family from current node. */
d62a17ae 344afi_t bgp_node_afi(struct vty *vty)
345{
346 afi_t afi;
347 switch (vty->node) {
348 case BGP_IPV6_NODE:
349 case BGP_IPV6M_NODE:
350 case BGP_IPV6L_NODE:
351 case BGP_VPNV6_NODE:
7c40bf39 352 case BGP_FLOWSPECV6_NODE:
d62a17ae 353 afi = AFI_IP6;
354 break;
355 case BGP_EVPN_NODE:
356 afi = AFI_L2VPN;
357 break;
358 default:
359 afi = AFI_IP;
360 break;
361 }
362 return afi;
718e3744 363}
364
365/* Utility function to get subsequent address family from current
366 node. */
d62a17ae 367safi_t bgp_node_safi(struct vty *vty)
368{
369 safi_t safi;
370 switch (vty->node) {
371 case BGP_VPNV4_NODE:
372 case BGP_VPNV6_NODE:
373 safi = SAFI_MPLS_VPN;
374 break;
375 case BGP_IPV4M_NODE:
376 case BGP_IPV6M_NODE:
377 safi = SAFI_MULTICAST;
378 break;
379 case BGP_EVPN_NODE:
380 safi = SAFI_EVPN;
381 break;
382 case BGP_IPV4L_NODE:
383 case BGP_IPV6L_NODE:
384 safi = SAFI_LABELED_UNICAST;
385 break;
7c40bf39 386 case BGP_FLOWSPECV4_NODE:
387 case BGP_FLOWSPECV6_NODE:
388 safi = SAFI_FLOWSPEC;
389 break;
d62a17ae 390 default:
391 safi = SAFI_UNICAST;
392 break;
393 }
394 return safi;
718e3744 395}
396
55f91488
QY
397/**
398 * Converts an AFI in string form to afi_t
399 *
400 * @param afi string, one of
401 * - "ipv4"
402 * - "ipv6"
81cf0de5 403 * - "l2vpn"
55f91488
QY
404 * @return the corresponding afi_t
405 */
d62a17ae 406afi_t bgp_vty_afi_from_str(const char *afi_str)
407{
408 afi_t afi = AFI_MAX; /* unknown */
409 if (strmatch(afi_str, "ipv4"))
410 afi = AFI_IP;
411 else if (strmatch(afi_str, "ipv6"))
412 afi = AFI_IP6;
81cf0de5
CS
413 else if (strmatch(afi_str, "l2vpn"))
414 afi = AFI_L2VPN;
d62a17ae 415 return afi;
416}
417
418int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
419 afi_t *afi)
420{
421 int ret = 0;
422 if (argv_find(argv, argc, "ipv4", index)) {
423 ret = 1;
424 if (afi)
425 *afi = AFI_IP;
426 } else if (argv_find(argv, argc, "ipv6", index)) {
427 ret = 1;
428 if (afi)
429 *afi = AFI_IP6;
8688b3e7
DS
430 } else if (argv_find(argv, argc, "l2vpn", index)) {
431 ret = 1;
432 if (afi)
433 *afi = AFI_L2VPN;
d62a17ae 434 }
435 return ret;
46f296b4
LB
436}
437
375a2e67 438/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 439safi_t bgp_vty_safi_from_str(const char *safi_str)
440{
441 safi_t safi = SAFI_MAX; /* unknown */
442 if (strmatch(safi_str, "multicast"))
443 safi = SAFI_MULTICAST;
444 else if (strmatch(safi_str, "unicast"))
445 safi = SAFI_UNICAST;
446 else if (strmatch(safi_str, "vpn"))
447 safi = SAFI_MPLS_VPN;
81cf0de5
CS
448 else if (strmatch(safi_str, "evpn"))
449 safi = SAFI_EVPN;
d62a17ae 450 else if (strmatch(safi_str, "labeled-unicast"))
451 safi = SAFI_LABELED_UNICAST;
7c40bf39 452 else if (strmatch(safi_str, "flowspec"))
453 safi = SAFI_FLOWSPEC;
d62a17ae 454 return safi;
455}
456
457int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
458 safi_t *safi)
459{
460 int ret = 0;
461 if (argv_find(argv, argc, "unicast", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_UNICAST;
465 } else if (argv_find(argv, argc, "multicast", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_MULTICAST;
469 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
470 ret = 1;
471 if (safi)
472 *safi = SAFI_LABELED_UNICAST;
473 } else if (argv_find(argv, argc, "vpn", index)) {
474 ret = 1;
475 if (safi)
476 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
477 } else if (argv_find(argv, argc, "evpn", index)) {
478 ret = 1;
479 if (safi)
480 *safi = SAFI_EVPN;
7c40bf39 481 } else if (argv_find(argv, argc, "flowspec", index)) {
482 ret = 1;
483 if (safi)
484 *safi = SAFI_FLOWSPEC;
d62a17ae 485 }
486 return ret;
46f296b4
LB
487}
488
b16bcbba
TA
489/*
490 * Convert an afi_t/safi_t pair to matching BGP_DEFAULT_AF* flag.
491 *
492 * afi
493 * address-family identifier
494 *
495 * safi
496 * subsequent address-family identifier
497 *
498 * Returns:
499 * default_af string corresponding to the supplied afi/safi pair.
500 * If afi/safi is invalid or if flag for afi/safi doesn't exist,
501 * return -1.
502 */
503static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
504{
505 switch (afi) {
506 case AFI_IP:
507 switch (safi) {
508 case SAFI_UNICAST:
509 return "ipv4-unicast";
510 case SAFI_MULTICAST:
511 return "ipv4-multicast";
512 case SAFI_MPLS_VPN:
513 return "ipv4-vpn";
514 case SAFI_ENCAP:
515 return "ipv4-encap";
516 case SAFI_LABELED_UNICAST:
517 return "ipv4-labeled-unicast";
518 case SAFI_FLOWSPEC:
519 return "ipv4-flowspec";
520 default:
521 return "unknown-afi/safi";
522 }
523 break;
524 case AFI_IP6:
525 switch (safi) {
526 case SAFI_UNICAST:
527 return "ipv6-unicast";
528 case SAFI_MULTICAST:
529 return "ipv6-multicast";
530 case SAFI_MPLS_VPN:
531 return "ipv6-vpn";
532 case SAFI_ENCAP:
533 return "ipv6-encap";
534 case SAFI_LABELED_UNICAST:
535 return "ipv6-labeled-unicast";
536 case SAFI_FLOWSPEC:
537 return "ipv6-flowspec";
538 default:
539 return "unknown-afi/safi";
540 }
541 break;
542 case AFI_L2VPN:
543 switch (safi) {
544 case SAFI_EVPN:
545 return "l2vpn-evpn";
546 default:
547 return "unknown-afi/safi";
548 }
549 case AFI_UNSPEC:
550 case AFI_MAX:
551 return "unknown-afi/safi";
552 }
553 /* all AFIs are accounted for above, so this shouldn't happen */
554 return "unknown-afi/safi";
555}
556
5d5393b9
DL
557int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
558 enum bgp_instance_type inst_type)
559{
560 int ret = bgp_get(bgp, as, name, inst_type);
561
562 if (ret == BGP_CREATED) {
563 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 564 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
565
566 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 567 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 568 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 569 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
570 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
571 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 572 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 573 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 574 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 575 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
576 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
577 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
578 if (DFLT_BGP_SUPPRESS_DUPLICATES)
579 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
f2ca5c5b
DA
580 if (DFLT_BGP_GRACEFUL_NOTIFICATION)
581 SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
1ae314be
DA
582 if (DFLT_BGP_HARD_ADMIN_RESET)
583 SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET);
5d5393b9
DL
584
585 ret = BGP_SUCCESS;
586 }
587 return ret;
588}
589
7eeee51e 590/*
f212a857 591 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 592 *
f212a857
DS
593 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
594 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
595 * to appropriate values for the calling function. This is to allow the
596 * calling function to make decisions appropriate for the show command
597 * that is being parsed.
598 *
599 * The show commands are generally of the form:
d62a17ae 600 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
601 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
602 *
603 * Since we use argv_find if the show command in particular doesn't have:
604 * [ip]
18c57037 605 * [<view|vrf> VIEWVRFNAME]
375a2e67 606 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
607 * The command parsing should still be ok.
608 *
609 * vty -> The vty for the command so we can output some useful data in
610 * the event of a parse error in the vrf.
611 * argv -> The command tokens
612 * argc -> How many command tokens we have
d62a17ae 613 * idx -> The current place in the command, generally should be 0 for this
614 * function
7eeee51e
DS
615 * afi -> The parsed afi if it was included in the show command, returned here
616 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 617 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 618 * use_json -> json is configured or not
7eeee51e
DS
619 *
620 * The function returns the correct location in the parse tree for the
621 * last token found.
0e37c258
DS
622 *
623 * Returns 0 for failure to parse correctly, else the idx position of where
624 * it found the last token.
7eeee51e 625 */
d62a17ae 626int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
627 struct cmd_token **argv, int argc,
628 int *idx, afi_t *afi, safi_t *safi,
9f049418 629 struct bgp **bgp, bool use_json)
d62a17ae 630{
631 char *vrf_name = NULL;
632
633 assert(afi);
634 assert(safi);
635 assert(bgp);
636
637 if (argv_find(argv, argc, "ip", idx))
638 *afi = AFI_IP;
639
9a8bdf1c 640 if (argv_find(argv, argc, "view", idx))
d62a17ae 641 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
642 else if (argv_find(argv, argc, "vrf", idx)) {
643 vrf_name = argv[*idx + 1]->arg;
644 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
645 vrf_name = NULL;
646 }
647 if (vrf_name) {
d62a17ae 648 if (strmatch(vrf_name, "all"))
649 *bgp = NULL;
650 else {
651 *bgp = bgp_lookup_by_name(vrf_name);
652 if (!*bgp) {
52e5b8c4
SP
653 if (use_json) {
654 json_object *json = NULL;
655 json = json_object_new_object();
656 json_object_string_add(
657 json, "warning",
658 "View/Vrf is unknown");
75eeda93 659 vty_json(vty, json);
52e5b8c4 660 }
ca61fd25
DS
661 else
662 vty_out(vty, "View/Vrf %s is unknown\n",
663 vrf_name);
d62a17ae 664 *idx = 0;
665 return 0;
666 }
667 }
668 } else {
669 *bgp = bgp_get_default();
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 "Default BGP instance not found");
75eeda93 677 vty_json(vty, json);
52e5b8c4 678 }
ca61fd25
DS
679 else
680 vty_out(vty,
681 "Default BGP instance not found\n");
d62a17ae 682 *idx = 0;
683 return 0;
684 }
685 }
686
687 if (argv_find_and_parse_afi(argv, argc, idx, afi))
688 argv_find_and_parse_safi(argv, argc, idx, safi);
689
690 *idx += 1;
691 return *idx;
692}
693
28c6e247 694static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 695{
696 struct interface *ifp = NULL;
4122b697
DA
697 struct listnode *node;
698 struct bgp_listener *listener;
699 union sockunion all_su;
d62a17ae 700
4122b697 701 if (su->sa.sa_family == AF_INET) {
3d2a2725 702 (void)str2sockunion("0.0.0.0", &all_su);
d62a17ae 703 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
4122b697 704 } else if (su->sa.sa_family == AF_INET6) {
3d2a2725 705 (void)str2sockunion("::", &all_su);
d62a17ae 706 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
707 su->sin6.sin6_scope_id,
708 bgp->vrf_id);
4122b697 709 }
d62a17ae 710
4122b697
DA
711 if (ifp) {
712 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
713 if (sockunion_family(su) !=
714 sockunion_family(&listener->su))
715 continue;
716
717 /* If 0.0.0.0/:: is a listener, then treat as self and
718 * reject.
719 */
720 if (!sockunion_cmp(&listener->su, su) ||
721 !sockunion_cmp(&listener->su, &all_su))
722 return true;
723 }
724 }
d62a17ae 725
3dc339cd 726 return false;
718e3744 727}
728
28c6e247
IR
729/* Utility function for looking up peer from VTY. */
730/* This is used only for configuration, so disallow if attempted on
731 * a dynamic neighbor.
732 */
733static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
734{
735 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
736 int ret;
737 union sockunion su;
738 struct peer *peer;
739
740 if (!bgp) {
741 return NULL;
742 }
743
744 ret = str2sockunion(ip_str, &su);
745 if (ret < 0) {
746 peer = peer_lookup_by_conf_if(bgp, ip_str);
747 if (!peer) {
748 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
749 == NULL) {
750 vty_out(vty,
751 "%% Malformed address or name: %s\n",
752 ip_str);
753 return NULL;
754 }
755 }
756 } else {
757 peer = peer_lookup(bgp, &su);
758 if (!peer) {
759 vty_out(vty,
760 "%% Specify remote-as or peer-group commands first\n");
761 return NULL;
762 }
763 if (peer_dynamic_neighbor(peer)) {
764 vty_out(vty,
765 "%% Operation not allowed on a dynamic neighbor\n");
766 return NULL;
767 }
768 }
769 return peer;
770}
771
718e3744 772/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
773/* This is used only for configuration, so disallow if attempted on
774 * a dynamic neighbor.
775 */
d62a17ae 776struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
777{
778 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
779 int ret;
780 union sockunion su;
781 struct peer *peer = NULL;
782 struct peer_group *group = NULL;
783
784 if (!bgp) {
785 return NULL;
786 }
787
788 ret = str2sockunion(peer_str, &su);
789 if (ret == 0) {
790 /* IP address, locate peer. */
791 peer = peer_lookup(bgp, &su);
792 } else {
793 /* Not IP, could match either peer configured on interface or a
794 * group. */
795 peer = peer_lookup_by_conf_if(bgp, peer_str);
796 if (!peer)
797 group = peer_group_lookup(bgp, peer_str);
798 }
799
800 if (peer) {
801 if (peer_dynamic_neighbor(peer)) {
802 vty_out(vty,
803 "%% Operation not allowed on a dynamic neighbor\n");
804 return NULL;
805 }
806
807 return peer;
808 }
809
810 if (group)
811 return group->conf;
812
813 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
814
815 return NULL;
816}
817
4b7e23e9 818int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
d62a17ae 819{
820 const char *str = NULL;
821
822 switch (ret) {
4b7e23e9
DS
823 case BGP_SUCCESS:
824 case BGP_CREATED:
825 case BGP_GR_NO_OPERATION:
826 break;
d62a17ae 827 case BGP_ERR_INVALID_VALUE:
828 str = "Invalid value";
829 break;
830 case BGP_ERR_INVALID_FLAG:
831 str = "Invalid flag";
832 break;
833 case BGP_ERR_PEER_GROUP_SHUTDOWN:
834 str = "Peer-group has been shutdown. Activate the peer-group first";
835 break;
836 case BGP_ERR_PEER_FLAG_CONFLICT:
837 str = "Can't set override-capability and strict-capability-match at the same time";
838 break;
839 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
840 str = "Specify remote-as or peer-group remote AS first";
841 break;
842 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
843 str = "Cannot change the peer-group. Deconfigure first";
844 break;
845 case BGP_ERR_PEER_GROUP_MISMATCH:
846 str = "Peer is not a member of this peer-group";
847 break;
848 case BGP_ERR_PEER_FILTER_CONFLICT:
849 str = "Prefix/distribute list can not co-exist";
850 break;
851 case BGP_ERR_NOT_INTERNAL_PEER:
852 str = "Invalid command. Not an internal neighbor";
853 break;
854 case BGP_ERR_REMOVE_PRIVATE_AS:
855 str = "remove-private-AS cannot be configured for IBGP peers";
856 break;
857 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
858 str = "Local-AS allowed only for EBGP peers";
859 break;
860 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
861 str = "Cannot have local-as same as BGP AS number";
862 break;
863 case BGP_ERR_TCPSIG_FAILED:
864 str = "Error while applying TCP-Sig to session(s)";
865 break;
866 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
867 str = "ebgp-multihop and ttl-security cannot be configured together";
868 break;
869 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
870 str = "ttl-security only allowed for EBGP peers";
871 break;
872 case BGP_ERR_AS_OVERRIDE:
873 str = "as-override cannot be configured for IBGP peers";
874 break;
875 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
876 str = "Invalid limit for number of dynamic neighbors";
877 break;
878 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
879 str = "Dynamic neighbor listen range already exists";
880 break;
881 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
882 str = "Operation not allowed on a dynamic neighbor";
883 break;
884 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
885 str = "Operation not allowed on a directly connected neighbor";
886 break;
887 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 888 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 889 break;
890 case BGP_ERR_GR_INVALID_CMD:
891 str = "The Graceful Restart command used is not valid at this moment.";
892 break;
893 case BGP_ERR_GR_OPERATION_FAILED:
894 str = "The Graceful Restart Operation failed due to an err.";
895 break;
6dcea6fe
DS
896 case BGP_ERR_PEER_GROUP_MEMBER:
897 str = "Peer-group member cannot override remote-as of peer-group.";
898 break;
899 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
900 str = "Peer-group members must be all internal or all external.";
901 break;
4b7e23e9
DS
902 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_NOT_FOUND:
903 str = "Range specified cannot be deleted because it is not part of current config.";
904 break;
905 case BGP_ERR_INSTANCE_MISMATCH:
906 str = "Instance specified does not match the current instance.";
907 break;
908 case BGP_ERR_NO_INTERFACE_CONFIG:
909 str = "Interface specified is not being used for interface based peer.";
910 break;
911 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
912 str = "No configuration already specified for soft reconfiguration.";
913 break;
914 case BGP_ERR_AS_MISMATCH:
915 str = "BGP is already running.";
916 break;
917 case BGP_ERR_AF_UNCONFIGURED:
918 str = "AFI/SAFI specified is not currently configured.";
919 break;
920 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
921 str = "AS specified for local as is the same as the remote as and this is not allowed.";
922 break;
923 case BGP_ERR_INVALID_AS:
924 str = "Confederation AS specified is the same AS as our AS.";
925 break;
d62a17ae 926 }
927 if (str) {
928 vty_out(vty, "%% %s\n", str);
929 return CMD_WARNING_CONFIG_FAILED;
930 }
931 return CMD_SUCCESS;
718e3744 932}
933
7aafcaca 934/* BGP clear sort. */
d62a17ae 935enum clear_sort {
936 clear_all,
937 clear_peer,
938 clear_group,
939 clear_external,
940 clear_as
7aafcaca
DS
941};
942
1ca2fd11
IR
943static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
944 safi_t safi, int error)
d62a17ae 945{
946 switch (error) {
947 case BGP_ERR_AF_UNCONFIGURED:
1ca2fd11 948 vty_out(vty,
664b6f18 949 "%% BGP: Enable %s address family for the neighbor %s\n",
1ca2fd11 950 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 951 break;
952 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
1ca2fd11 953 vty_out(vty,
664b6f18 954 "%% BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
d62a17ae 955 peer->host);
956 break;
957 default:
958 break;
959 }
7aafcaca
DS
960}
961
dc912615 962static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 963 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
964{
965 int ret = 0;
2adac256 966 struct peer_af *paf;
dc912615
DS
967
968 /* if afi/.safi not specified, spin thru all of them */
969 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
970 afi_t tmp_afi;
971 safi_t tmp_safi;
0e5cdd59
DS
972 enum bgp_af_index index;
973
974 for (index = BGP_AF_START; index < BGP_AF_MAX; index++) {
975 paf = peer->peer_af_array[index];
976 if (!paf)
977 continue;
dc912615 978
2adac256
DA
979 if (paf && paf->subgroup)
980 SET_FLAG(paf->subgroup->sflags,
981 SUBGRP_STATUS_FORCE_UPDATES);
982
0e5cdd59
DS
983 tmp_afi = paf->afi;
984 tmp_safi = paf->safi;
dc912615
DS
985 if (!peer->afc[tmp_afi][tmp_safi])
986 continue;
987
988 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 989 ret = peer_clear(peer, nnode);
dc912615
DS
990 else
991 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
992 stype);
993 }
994 /* if afi specified and safi not, spin thru safis on this afi */
995 } else if (safi == SAFI_UNSPEC) {
996 safi_t tmp_safi;
997
998 for (tmp_safi = SAFI_UNICAST;
999 tmp_safi < SAFI_MAX; tmp_safi++) {
1000 if (!peer->afc[afi][tmp_safi])
1001 continue;
1002
2adac256
DA
1003 paf = peer_af_find(peer, afi, tmp_safi);
1004 if (paf && paf->subgroup)
1005 SET_FLAG(paf->subgroup->sflags,
1006 SUBGRP_STATUS_FORCE_UPDATES);
1007
dc912615 1008 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1009 ret = peer_clear(peer, nnode);
dc912615
DS
1010 else
1011 ret = peer_clear_soft(peer, afi,
1012 tmp_safi, stype);
1013 }
1014 /* both afi/safi specified, let the caller know if not defined */
1015 } else {
1016 if (!peer->afc[afi][safi])
1017 return 1;
1018
2adac256
DA
1019 paf = peer_af_find(peer, afi, safi);
1020 if (paf && paf->subgroup)
1021 SET_FLAG(paf->subgroup->sflags,
1022 SUBGRP_STATUS_FORCE_UPDATES);
1023
dc912615 1024 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 1025 ret = peer_clear(peer, nnode);
dc912615
DS
1026 else
1027 ret = peer_clear_soft(peer, afi, safi, stype);
1028 }
1029
1030 return ret;
1031}
1032
7aafcaca 1033/* `clear ip bgp' functions. */
1ca2fd11 1034static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 1035 enum clear_sort sort, enum bgp_clear_type stype,
1ca2fd11 1036 const char *arg)
d62a17ae 1037{
dc912615 1038 int ret = 0;
3ae8bfa5 1039 bool found = false;
d62a17ae 1040 struct peer *peer;
dc95985f 1041
1042 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 1043
1044 /* Clear all neighbors. */
1045 /*
1046 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
1047 * nodes on the BGP instance as that may get freed if it is a
1048 * doppelganger
d62a17ae 1049 */
1050 if (sort == clear_all) {
1051 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 1052
1053 bgp_peer_gr_flags_update(peer);
1054
36235319 1055 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 1056 gr_router_detected = true;
1057
c368171c 1058 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 1059 stype);
d62a17ae 1060
1061 if (ret < 0)
1ca2fd11 1062 bgp_clear_vty_error(vty, peer, afi, safi, ret);
dc95985f 1063 }
1064
36235319
QY
1065 if (gr_router_detected
1066 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1067 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1068 } else if (!gr_router_detected
1069 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1070 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 1071 }
d62a17ae 1072
1073 /* This is to apply read-only mode on this clear. */
1074 if (stype == BGP_CLEAR_SOFT_NONE)
1075 bgp->update_delay_over = 0;
1076
1077 return CMD_SUCCESS;
7aafcaca
DS
1078 }
1079
3ae8bfa5 1080 /* Clear specified neighbor. */
d62a17ae 1081 if (sort == clear_peer) {
1082 union sockunion su;
d62a17ae 1083
1084 /* Make sockunion for lookup. */
1085 ret = str2sockunion(arg, &su);
1086 if (ret < 0) {
1087 peer = peer_lookup_by_conf_if(bgp, arg);
1088 if (!peer) {
1089 peer = peer_lookup_by_hostname(bgp, arg);
1090 if (!peer) {
1ca2fd11
IR
1091 vty_out(vty,
1092 "Malformed address or name: %s\n",
d62a17ae 1093 arg);
1094 return CMD_WARNING;
1095 }
1096 }
1097 } else {
1098 peer = peer_lookup(bgp, &su);
1099 if (!peer) {
1ca2fd11 1100 vty_out(vty,
664b6f18 1101 "%% BGP: Unknown neighbor - \"%s\"\n",
1ca2fd11 1102 arg);
d62a17ae 1103 return CMD_WARNING;
1104 }
1105 }
7aafcaca 1106
dc95985f 1107 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1108 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1109
dc912615
DS
1110 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1111
1112 /* if afi/safi not defined for this peer, let caller know */
1113 if (ret == 1)
3ae8bfa5 1114 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1115
d62a17ae 1116 if (ret < 0)
1ca2fd11 1117 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 1118
d62a17ae 1119 return CMD_SUCCESS;
7aafcaca 1120 }
7aafcaca 1121
3ae8bfa5 1122 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1123 if (sort == clear_group) {
1124 struct peer_group *group;
7aafcaca 1125
d62a17ae 1126 group = peer_group_lookup(bgp, arg);
1127 if (!group) {
664b6f18 1128 vty_out(vty, "%% BGP: No such peer-group %s\n", arg);
d62a17ae 1129 return CMD_WARNING;
1130 }
1131
1132 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1133 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1134
d62a17ae 1135 if (ret < 0)
1ca2fd11 1136 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1137 else
1138 found = true;
d62a17ae 1139 }
3ae8bfa5
PM
1140
1141 if (!found)
1ca2fd11 1142 vty_out(vty,
664b6f18 1143 "%% BGP: No %s peer belonging to peer-group %s is configured\n",
5cb5f4d0 1144 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1145
d62a17ae 1146 return CMD_SUCCESS;
7aafcaca 1147 }
7aafcaca 1148
3ae8bfa5 1149 /* Clear all external (eBGP) neighbors. */
d62a17ae 1150 if (sort == clear_external) {
1151 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1152 if (peer->sort == BGP_PEER_IBGP)
1153 continue;
7aafcaca 1154
dc95985f 1155 bgp_peer_gr_flags_update(peer);
1156
36235319 1157 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1158 gr_router_detected = true;
dc95985f 1159
c368171c 1160 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1161
d62a17ae 1162 if (ret < 0)
1ca2fd11 1163 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1164 else
1165 found = true;
d62a17ae 1166 }
3ae8bfa5 1167
36235319
QY
1168 if (gr_router_detected
1169 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1170 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1171 } else if (!gr_router_detected
1172 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1173 bgp_zebra_send_capabilities(bgp, true);
1174 }
1175
3ae8bfa5 1176 if (!found)
1ca2fd11 1177 vty_out(vty,
664b6f18 1178 "%% BGP: No external %s peer is configured\n",
1ca2fd11 1179 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1180
d62a17ae 1181 return CMD_SUCCESS;
1182 }
1183
3ae8bfa5 1184 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1185 if (sort == clear_as) {
3ae8bfa5 1186 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1187
1188 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1189 if (peer->as != as)
1190 continue;
1191
dc95985f 1192 bgp_peer_gr_flags_update(peer);
1193
36235319 1194 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1195 gr_router_detected = true;
dc95985f 1196
c368171c 1197 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1198
1199 if (ret < 0)
1ca2fd11 1200 bgp_clear_vty_error(vty, peer, afi, safi, ret);
3ae8bfa5
PM
1201 else
1202 found = true;
d62a17ae 1203 }
3ae8bfa5 1204
36235319
QY
1205 if (gr_router_detected
1206 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1207 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1208 } else if (!gr_router_detected
1209 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1210 bgp_zebra_send_capabilities(bgp, true);
1211 }
1212
3ae8bfa5 1213 if (!found)
1ca2fd11 1214 vty_out(vty,
664b6f18 1215 "%% BGP: No %s peer is configured with AS %s\n",
1ca2fd11 1216 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1217
d62a17ae 1218 return CMD_SUCCESS;
1219 }
1220
1221 return CMD_SUCCESS;
1222}
1223
1ca2fd11
IR
1224static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
1225 safi_t safi, enum clear_sort sort,
1226 enum bgp_clear_type stype, const char *arg)
d62a17ae 1227{
1228 struct bgp *bgp;
1229
1230 /* BGP structure lookup. */
1231 if (name) {
1232 bgp = bgp_lookup_by_name(name);
1233 if (bgp == NULL) {
1ca2fd11 1234 vty_out(vty, "Can't find BGP instance %s\n", name);
d62a17ae 1235 return CMD_WARNING;
1236 }
1237 } else {
1238 bgp = bgp_get_default();
1239 if (bgp == NULL) {
1ca2fd11 1240 vty_out(vty, "No BGP process is configured\n");
d62a17ae 1241 return CMD_WARNING;
1242 }
1243 }
1244
1ca2fd11 1245 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
1246}
1247
1248/* clear soft inbound */
1ca2fd11 1249static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 1250{
99b3ebd3
NS
1251 afi_t afi;
1252 safi_t safi;
1253
1ca2fd11
IR
1254 FOREACH_AFI_SAFI (afi, safi)
1255 bgp_clear_vty(vty, name, afi, safi, clear_all,
1256 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
1257}
1258
1259/* clear soft outbound */
1ca2fd11 1260static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 1261{
99b3ebd3
NS
1262 afi_t afi;
1263 safi_t safi;
1264
1ca2fd11
IR
1265 FOREACH_AFI_SAFI (afi, safi)
1266 bgp_clear_vty(vty, name, afi, safi, clear_all,
1267 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
1268}
1269
1270
f787d7a0 1271#ifndef VTYSH_EXTRACT_PL
2e4c2296 1272#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1273#endif
1274
8029b216
AK
1275DEFUN_HIDDEN (bgp_local_mac,
1276 bgp_local_mac_cmd,
093e3f23 1277 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1278 BGP_STR
1279 "Local MAC config\n"
1280 "VxLAN Network Identifier\n"
1281 "VNI number\n"
1282 "local mac\n"
1283 "mac address\n"
1284 "mac-mobility sequence\n"
1285 "seq number\n")
1286{
1287 int rv;
1288 vni_t vni;
1289 struct ethaddr mac;
1290 struct ipaddr ip;
1291 uint32_t seq;
1292 struct bgp *bgp;
1293
1294 vni = strtoul(argv[3]->arg, NULL, 10);
1295 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1296 vty_out(vty, "%% Malformed MAC address\n");
1297 return CMD_WARNING;
1298 }
1299 memset(&ip, 0, sizeof(ip));
1300 seq = strtoul(argv[7]->arg, NULL, 10);
1301
1302 bgp = bgp_get_default();
1303 if (!bgp) {
1304 vty_out(vty, "Default BGP instance is not there\n");
1305 return CMD_WARNING;
1306 }
1307
b5e140c8
AK
1308 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1309 zero_esi);
8029b216
AK
1310 if (rv < 0) {
1311 vty_out(vty, "Internal error\n");
1312 return CMD_WARNING;
1313 }
1314
1315 return CMD_SUCCESS;
1316}
1317
1318DEFUN_HIDDEN (no_bgp_local_mac,
1319 no_bgp_local_mac_cmd,
093e3f23 1320 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1321 NO_STR
1322 BGP_STR
1323 "Local MAC config\n"
1324 "VxLAN Network Identifier\n"
1325 "VNI number\n"
1326 "local mac\n"
1327 "mac address\n")
1328{
1329 int rv;
1330 vni_t vni;
1331 struct ethaddr mac;
1332 struct ipaddr ip;
1333 struct bgp *bgp;
1334
1335 vni = strtoul(argv[4]->arg, NULL, 10);
1336 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1337 vty_out(vty, "%% Malformed MAC address\n");
1338 return CMD_WARNING;
1339 }
1340 memset(&ip, 0, sizeof(ip));
1341
1342 bgp = bgp_get_default();
1343 if (!bgp) {
1344 vty_out(vty, "Default BGP instance is not there\n");
1345 return CMD_WARNING;
1346 }
1347
ec0ab544 1348 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
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
718e3744 1357DEFUN (no_synchronization,
1358 no_synchronization_cmd,
1359 "no synchronization",
1360 NO_STR
1361 "Perform IGP synchronization\n")
1362{
d62a17ae 1363 return CMD_SUCCESS;
718e3744 1364}
1365
1366DEFUN (no_auto_summary,
1367 no_auto_summary_cmd,
1368 "no auto-summary",
1369 NO_STR
1370 "Enable automatic network number summarization\n")
1371{
d62a17ae 1372 return CMD_SUCCESS;
718e3744 1373}
3d515fd9 1374
718e3744 1375/* "router bgp" commands. */
1ca2fd11
IR
1376DEFUN_NOSH (router_bgp,
1377 router_bgp_cmd,
1378 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1379 ROUTER_STR
1380 BGP_STR
1381 AS_STR
1382 BGP_INSTANCE_HELP_STR)
718e3744 1383{
d62a17ae 1384 int idx_asn = 2;
1385 int idx_view_vrf = 3;
1386 int idx_vrf = 4;
1ca2fd11
IR
1387 int is_new_bgp = 0;
1388 int ret;
d62a17ae 1389 as_t as;
1390 struct bgp *bgp;
1391 const char *name = NULL;
1392 enum bgp_instance_type inst_type;
1393
1394 // "router bgp" without an ASN
1395 if (argc == 2) {
1396 // Pending: Make VRF option available for ASN less config
1abef40f 1397 bgp = bgp_get_default();
d62a17ae 1398
1abef40f 1399 if (bgp == NULL) {
d62a17ae 1400 vty_out(vty, "%% No BGP process is configured\n");
1401 return CMD_WARNING_CONFIG_FAILED;
1402 }
1403
1404 if (listcount(bm->bgp) > 1) {
996c9314 1405 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1406 return CMD_WARNING_CONFIG_FAILED;
1407 }
1408 }
1409
1410 // "router bgp X"
1411 else {
ff8a8a7a 1412 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1ca2fd11 1413
cc413e2a
DA
1414 if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
1415 vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
1416 BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
1417
d62a17ae 1418 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1419 if (argc > 3) {
1420 name = argv[idx_vrf]->arg;
1421
9a8bdf1c
PG
1422 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1423 if (strmatch(name, VRF_DEFAULT_NAME))
1424 name = NULL;
1425 else
1426 inst_type = BGP_INSTANCE_TYPE_VRF;
1ca2fd11 1427 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
d62a17ae 1428 inst_type = BGP_INSTANCE_TYPE_VIEW;
d62a17ae 1429 }
1430
1ca2fd11
IR
1431 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1432 is_new_bgp = (bgp_lookup(as, name) == NULL);
3bd70bf8 1433
1ca2fd11
IR
1434 ret = bgp_get_vty(&bgp, &as, name, inst_type);
1435 switch (ret) {
1436 case BGP_ERR_AS_MISMATCH:
1437 vty_out(vty, "BGP is already running; AS is %u\n", as);
1438 return CMD_WARNING_CONFIG_FAILED;
1439 case BGP_ERR_INSTANCE_MISMATCH:
1440 vty_out(vty,
1441 "BGP instance name and AS number mismatch\n");
1442 vty_out(vty,
1443 "BGP instance is already running; AS is %u\n",
1444 as);
1445 return CMD_WARNING_CONFIG_FAILED;
ff8a8a7a 1446 }
1ca2fd11
IR
1447
1448 /*
1449 * If we just instantiated the default instance, complete
1450 * any pending VRF-VPN leaking that was configured via
1451 * earlier "router bgp X vrf FOO" blocks.
1452 */
1453 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1454 vpn_leak_postchange_all();
1455
1456 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1457 bgp_vpn_leak_export(bgp);
1458 /* Pending: handle when user tries to change a view to vrf n vv.
1459 */
d62a17ae 1460 }
1461
1ca2fd11
IR
1462 /* unset the auto created flag as the user config is now present */
1463 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1464 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1465
1466 return CMD_SUCCESS;
718e3744 1467}
1468
718e3744 1469/* "no router bgp" commands. */
1ca2fd11
IR
1470DEFUN (no_router_bgp,
1471 no_router_bgp_cmd,
1472 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1473 NO_STR
1474 ROUTER_STR
1475 BGP_STR
1476 AS_STR
1477 BGP_INSTANCE_HELP_STR)
718e3744 1478{
4fd9919e 1479 int idx_asn = 3;
d62a17ae 1480 int idx_vrf = 5;
1ca2fd11 1481 as_t as;
4fd9919e 1482 struct bgp *bgp;
d62a17ae 1483 const char *name = NULL;
718e3744 1484
d62a17ae 1485 // "no router bgp" without an ASN
1486 if (argc == 3) {
1487 // Pending: Make VRF option available for ASN less config
8382083a 1488 bgp = bgp_get_default();
718e3744 1489
8382083a 1490 if (bgp == NULL) {
d62a17ae 1491 vty_out(vty, "%% No BGP process is configured\n");
1492 return CMD_WARNING_CONFIG_FAILED;
1493 }
7fb21a9f 1494
d62a17ae 1495 if (listcount(bm->bgp) > 1) {
996c9314 1496 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1497 return CMD_WARNING_CONFIG_FAILED;
1498 }
4fd9919e 1499
4fd9919e 1500 if (bgp->l3vni) {
be125e6f 1501 vty_out(vty, "%% Please unconfigure l3vni %u\n",
4fd9919e
IR
1502 bgp->l3vni);
1503 return CMD_WARNING_CONFIG_FAILED;
1504 }
d62a17ae 1505 } else {
4fd9919e
IR
1506 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1507
1ca42c8d 1508 if (argc > 4) {
d62a17ae 1509 name = argv[idx_vrf]->arg;
1ca42c8d
IR
1510 if (strmatch(argv[idx_vrf - 1]->text, "vrf")
1511 && strmatch(name, VRF_DEFAULT_NAME))
1512 name = NULL;
1513 }
7fb21a9f 1514
4fd9919e
IR
1515 /* Lookup bgp structure. */
1516 bgp = bgp_lookup(as, name);
1517 if (!bgp) {
1518 vty_out(vty, "%% Can't find BGP instance\n");
1519 return CMD_WARNING_CONFIG_FAILED;
1520 }
1521
1522 if (bgp->l3vni) {
1523 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1524 bgp->l3vni);
1525 return CMD_WARNING_CONFIG_FAILED;
1526 }
1527
1528 /* Cannot delete default instance if vrf instances exist */
1529 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1530 struct listnode *node;
1531 struct bgp *tmp_bgp;
1532
1533 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1534 if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
1535 continue;
1536 if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1537 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1538 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1539 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
1540 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1541 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1542 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1543 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
1544 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
1545 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1546 CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
1547 BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
1548 (bgp == bgp_get_evpn() &&
1549 (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1550 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
1551 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1552 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
1553 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1554 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
1555 CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
1556 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
1557 (tmp_bgp->vnihash && hashcount(tmp_bgp->vnihash))) {
1558 vty_out(vty,
1559 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1560 return CMD_WARNING_CONFIG_FAILED;
1561 }
1562 }
1563 }
d62a17ae 1564 }
718e3744 1565
1ca2fd11 1566 bgp_delete(bgp);
718e3744 1567
1ca2fd11 1568 return CMD_SUCCESS;
718e3744 1569}
1570
718e3744 1571
ff8a8a7a
CS
1572/* BGP router-id. */
1573
1ca2fd11
IR
1574DEFPY (bgp_router_id,
1575 bgp_router_id_cmd,
1576 "bgp router-id A.B.C.D",
1577 BGP_STR
1578 "Override configured router identifier\n"
1579 "Manually configured router identifier\n")
718e3744 1580{
1ca2fd11
IR
1581 VTY_DECLVAR_CONTEXT(bgp, bgp);
1582 bgp_router_id_static_set(bgp, router_id);
1583 return CMD_SUCCESS;
ff8a8a7a 1584}
718e3744 1585
1ca2fd11
IR
1586DEFPY (no_bgp_router_id,
1587 no_bgp_router_id_cmd,
1588 "no bgp router-id [A.B.C.D]",
1589 NO_STR
1590 BGP_STR
1591 "Override configured router identifier\n"
1592 "Manually configured router identifier\n")
ff8a8a7a 1593{
1ca2fd11 1594 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1595
1ca2fd11
IR
1596 if (router_id_str) {
1597 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1598 vty_out(vty, "%% BGP router-id doesn't match\n");
1599 return CMD_WARNING_CONFIG_FAILED;
1600 }
1601 }
718e3744 1602
1ca2fd11
IR
1603 router_id.s_addr = 0;
1604 bgp_router_id_static_set(bgp, router_id);
1605
1606 return CMD_SUCCESS;
ff8a8a7a 1607}
6b0655a2 1608
ed0e57e3 1609DEFPY(bgp_community_alias, bgp_community_alias_cmd,
b4ad2fae 1610 "[no$no] bgp community alias WORD$community ALIAS_NAME$alias_name",
ed0e57e3
DA
1611 NO_STR BGP_STR
1612 "Add community specific parameters\n"
1613 "Create an alias for a community\n"
1614 "Community (AA:BB or AA:BB:CC)\n"
1615 "Alias name\n")
1616{
1617 struct community_alias ca1;
1618 struct community_alias ca2;
1619 struct community_alias *lookup_community;
1620 struct community_alias *lookup_alias;
1621
1622 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1623 vty_out(vty, "Invalid community format\n");
1624 return CMD_WARNING;
1625 }
1626
1627 memset(&ca1, 0, sizeof(ca1));
1628 memset(&ca2, 0, sizeof(ca2));
1629 strlcpy(ca1.community, community, sizeof(ca1.community));
b4ad2fae 1630 strlcpy(ca1.alias, alias_name, sizeof(ca1.alias));
ed0e57e3
DA
1631
1632 lookup_community = bgp_ca_community_lookup(&ca1);
1633 lookup_alias = bgp_ca_alias_lookup(&ca1);
1634
1635 if (no) {
1636 bgp_ca_alias_delete(&ca1);
1637 bgp_ca_community_delete(&ca1);
1638 } else {
1639 if (lookup_alias) {
1640 /* Lookup if community hash table has an item
1641 * with the same alias name.
1642 */
1643 strlcpy(ca2.community, lookup_alias->community,
1644 sizeof(ca2.community));
1645 if (bgp_ca_community_lookup(&ca2)) {
1646 vty_out(vty,
1647 "community (%s) already has this alias (%s)\n",
1648 lookup_alias->community,
1649 lookup_alias->alias);
1650 return CMD_WARNING;
1651 }
1652 bgp_ca_alias_delete(&ca1);
1653 }
1654
1655 if (lookup_community)
1656 bgp_ca_community_delete(&ca1);
1657
1658 bgp_ca_alias_insert(&ca1);
1659 bgp_ca_community_insert(&ca1);
1660 }
1661
1662 return CMD_SUCCESS;
1663}
1664
9acb67cb
DS
1665DEFPY (bgp_global_suppress_fib_pending,
1666 bgp_global_suppress_fib_pending_cmd,
1667 "[no] bgp suppress-fib-pending",
1668 NO_STR
1669 BGP_STR
1670 "Advertise only routes that are programmed in kernel to peers globally\n")
1671{
1672 bm_wait_for_fib_set(!no);
1673
1674 return CMD_SUCCESS;
1675}
1676
c208c586
S
1677DEFPY (bgp_suppress_fib_pending,
1678 bgp_suppress_fib_pending_cmd,
1679 "[no] bgp suppress-fib-pending",
1680 NO_STR
1681 BGP_STR
1682 "Advertise only routes that are programmed in kernel to peers\n")
1683{
1684 VTY_DECLVAR_CONTEXT(bgp, bgp);
1685
1686 bgp_suppress_fib_pending_set(bgp, !no);
1687 return CMD_SUCCESS;
1688}
1689
1690
718e3744 1691/* BGP Cluster ID. */
1ca2fd11
IR
1692DEFUN (bgp_cluster_id,
1693 bgp_cluster_id_cmd,
1694 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1695 BGP_STR
1696 "Configure Route-Reflector Cluster-id\n"
1697 "Route-Reflector Cluster-id in IP address format\n"
1698 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1699{
1ca2fd11 1700 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1701 int idx_ipv4 = 2;
1ca2fd11
IR
1702 int ret;
1703 struct in_addr cluster;
1704
1705 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1706 if (!ret) {
1707 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1708 return CMD_WARNING_CONFIG_FAILED;
1709 }
718e3744 1710
1ca2fd11
IR
1711 bgp_cluster_id_set(bgp, &cluster);
1712 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1713
1ca2fd11 1714 return CMD_SUCCESS;
718e3744 1715}
1716
1ca2fd11
IR
1717DEFUN (no_bgp_cluster_id,
1718 no_bgp_cluster_id_cmd,
1719 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1720 NO_STR
1721 BGP_STR
1722 "Configure Route-Reflector Cluster-id\n"
1723 "Route-Reflector Cluster-id in IP address format\n"
1724 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1725{
1ca2fd11
IR
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_cluster_id_unset(bgp);
1728 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1729
1ca2fd11 1730 return CMD_SUCCESS;
718e3744 1731}
1732
c163f297
DS
1733DEFPY (bgp_norib,
1734 bgp_norib_cmd,
1735 "bgp no-rib",
1736 BGP_STR
1737 "Disable BGP route installation to RIB (Zebra)\n")
1738{
1739 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1740 vty_out(vty,
1741 "%% No-RIB option is already set, nothing to do here.\n");
1742 return CMD_SUCCESS;
1743 }
1744
1745 bgp_option_norib_set_runtime();
1746
1747 return CMD_SUCCESS;
1748}
1749
1750DEFPY (no_bgp_norib,
1751 no_bgp_norib_cmd,
1752 "no bgp no-rib",
1753 NO_STR
1754 BGP_STR
1755 "Disable BGP route installation to RIB (Zebra)\n")
1756{
1757 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1758 vty_out(vty,
1759 "%% No-RIB option is not set, nothing to do here.\n");
1760 return CMD_SUCCESS;
1761 }
1762
1763 bgp_option_norib_unset_runtime();
1764
1765 return CMD_SUCCESS;
1766}
1767
e46723a5
DS
1768DEFPY (no_bgp_send_extra_data,
1769 no_bgp_send_extra_data_cmd,
1770 "[no] bgp send-extra-data zebra",
1771 NO_STR
1772 BGP_STR
1773 "Extra data to Zebra for display/use\n"
1774 "To zebra\n")
1775{
ec0acb80
DA
1776 if (no)
1777 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1778 else
1779 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1780
1781 return CMD_SUCCESS;
1782}
1783
1ca2fd11
IR
1784DEFUN (bgp_confederation_identifier,
1785 bgp_confederation_identifier_cmd,
1786 "bgp confederation identifier (1-4294967295)",
e9273987 1787 BGP_STR
1ca2fd11
IR
1788 "AS confederation parameters\n"
1789 "AS number\n"
1790 "Set routing domain confederation AS\n")
718e3744 1791{
1ca2fd11 1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1793 int idx_number = 3;
1ca2fd11 1794 as_t as;
718e3744 1795
1ca2fd11 1796 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1797
1ca2fd11 1798 bgp_confederation_id_set(bgp, as);
718e3744 1799
1ca2fd11 1800 return CMD_SUCCESS;
718e3744 1801}
1802
1ca2fd11
IR
1803DEFUN (no_bgp_confederation_identifier,
1804 no_bgp_confederation_identifier_cmd,
1805 "no bgp confederation identifier [(1-4294967295)]",
1806 NO_STR
e9273987 1807 BGP_STR
1ca2fd11
IR
1808 "AS confederation parameters\n"
1809 "AS number\n"
1810 "Set routing domain confederation AS\n")
ff8a8a7a 1811{
1ca2fd11
IR
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_confederation_id_unset(bgp);
1814
1815 return CMD_SUCCESS;
ff8a8a7a
CS
1816}
1817
1ca2fd11
IR
1818DEFUN (bgp_confederation_peers,
1819 bgp_confederation_peers_cmd,
1820 "bgp confederation peers (1-4294967295)...",
e9273987 1821 BGP_STR
1ca2fd11
IR
1822 "AS confederation parameters\n"
1823 "Peer ASs in BGP confederation\n"
1824 AS_STR)
718e3744 1825{
1ca2fd11 1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1827 int idx_asn = 3;
1ca2fd11 1828 as_t as;
d62a17ae 1829 int i;
718e3744 1830
1ca2fd11
IR
1831 for (i = idx_asn; i < argc; i++) {
1832 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1833
1ca2fd11
IR
1834 if (bgp->as == as) {
1835 vty_out(vty,
1836 "%% Local member-AS not allowed in confed peer list\n");
1837 continue;
1838 }
1839
1840 bgp_confederation_peers_add(bgp, as);
1841 }
1842 return CMD_SUCCESS;
718e3744 1843}
1844
1ca2fd11
IR
1845DEFUN (no_bgp_confederation_peers,
1846 no_bgp_confederation_peers_cmd,
1847 "no bgp confederation peers (1-4294967295)...",
1848 NO_STR
e9273987 1849 BGP_STR
1ca2fd11
IR
1850 "AS confederation parameters\n"
1851 "Peer ASs in BGP confederation\n"
1852 AS_STR)
718e3744 1853{
1ca2fd11 1854 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1855 int idx_asn = 4;
1ca2fd11 1856 as_t as;
d62a17ae 1857 int i;
718e3744 1858
1ca2fd11
IR
1859 for (i = idx_asn; i < argc; i++) {
1860 as = strtoul(argv[i]->arg, NULL, 10);
ff8a8a7a 1861
1ca2fd11
IR
1862 bgp_confederation_peers_remove(bgp, as);
1863 }
1864 return CMD_SUCCESS;
718e3744 1865}
6b0655a2 1866
5e242b0d
DS
1867/**
1868 * Central routine for maximum-paths configuration.
1869 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1870 * @set: 1 for setting values, 0 for removing the max-paths config.
1871 */
585f1adc
IR
1872static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1873 const char *mpaths, uint16_t options,
1874 int set)
d62a17ae 1875{
585f1adc
IR
1876 VTY_DECLVAR_CONTEXT(bgp, bgp);
1877 uint16_t maxpaths = 0;
d62a17ae 1878 int ret;
585f1adc
IR
1879 afi_t afi;
1880 safi_t safi;
1881
1882 afi = bgp_node_afi(vty);
1883 safi = bgp_node_safi(vty);
d62a17ae 1884
1885 if (set) {
585f1adc 1886 maxpaths = strtol(mpaths, NULL, 10);
d62a17ae 1887 if (maxpaths > multipath_num) {
585f1adc 1888 vty_out(vty,
d62a17ae 1889 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1890 maxpaths, multipath_num);
1891 return CMD_WARNING_CONFIG_FAILED;
1892 }
1893 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1894 options);
1895 } else
1896 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1897
1898 if (ret < 0) {
585f1adc 1899 vty_out(vty,
d62a17ae 1900 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1901 (set == 1) ? "" : "un",
1902 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1903 maxpaths, afi, safi);
1904 return CMD_WARNING_CONFIG_FAILED;
1905 }
1906
1907 bgp_recalculate_all_bestpaths(bgp);
1908
1909 return CMD_SUCCESS;
165b5fff
JB
1910}
1911
1ca2fd11
IR
1912DEFUN (bgp_maxmed_admin,
1913 bgp_maxmed_admin_cmd,
1914 "bgp max-med administrative ",
1915 BGP_STR
1916 "Advertise routes with max-med\n"
1917 "Administratively applied, for an indefinite period\n")
abc920f8 1918{
1ca2fd11 1919 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1920
1ca2fd11
IR
1921 bgp->v_maxmed_admin = 1;
1922 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
ff8a8a7a 1923
1ca2fd11 1924 bgp_maxmed_update(bgp);
abc920f8 1925
1ca2fd11 1926 return CMD_SUCCESS;
ff8a8a7a
CS
1927}
1928
1ca2fd11
IR
1929DEFUN (bgp_maxmed_admin_medv,
1930 bgp_maxmed_admin_medv_cmd,
1931 "bgp max-med administrative (0-4294967295)",
1932 BGP_STR
1933 "Advertise routes with max-med\n"
1934 "Administratively applied, for an indefinite period\n"
1935 "Max MED value to be used\n")
abc920f8 1936{
1ca2fd11 1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1938 int idx_number = 3;
abc920f8 1939
1ca2fd11
IR
1940 bgp->v_maxmed_admin = 1;
1941 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1942
1ca2fd11 1943 bgp_maxmed_update(bgp);
abc920f8 1944
1ca2fd11 1945 return CMD_SUCCESS;
abc920f8
DS
1946}
1947
1ca2fd11
IR
1948DEFUN (no_bgp_maxmed_admin,
1949 no_bgp_maxmed_admin_cmd,
1950 "no bgp max-med administrative [(0-4294967295)]",
1951 NO_STR
1952 BGP_STR
1953 "Advertise routes with max-med\n"
1954 "Administratively applied, for an indefinite period\n"
1955 "Max MED value to be used\n")
abc920f8 1956{
1ca2fd11
IR
1957 VTY_DECLVAR_CONTEXT(bgp, bgp);
1958 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1959 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1960 bgp_maxmed_update(bgp);
ff8a8a7a 1961
1ca2fd11 1962 return CMD_SUCCESS;
abc920f8
DS
1963}
1964
1ca2fd11
IR
1965DEFUN (bgp_maxmed_onstartup,
1966 bgp_maxmed_onstartup_cmd,
1967 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1968 BGP_STR
1969 "Advertise routes with max-med\n"
1970 "Effective on a startup\n"
1971 "Time (seconds) period for max-med\n"
1972 "Max MED value to be used\n")
abc920f8 1973{
1ca2fd11 1974 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 1975 int idx = 0;
4668a151 1976
9b01d289
DA
1977 if (argv_find(argv, argc, "(5-86400)", &idx))
1978 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1979 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1ca2fd11 1980 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
d62a17ae 1981 else
1ca2fd11 1982 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1983
1ca2fd11
IR
1984 bgp_maxmed_update(bgp);
1985
1986 return CMD_SUCCESS;
abc920f8
DS
1987}
1988
1ca2fd11
IR
1989DEFUN (no_bgp_maxmed_onstartup,
1990 no_bgp_maxmed_onstartup_cmd,
1991 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1992 NO_STR
1993 BGP_STR
1994 "Advertise routes with max-med\n"
1995 "Effective on a startup\n"
1996 "Time (seconds) period for max-med\n"
1997 "Max MED value to be used\n")
abc920f8 1998{
1ca2fd11
IR
1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000
2001 /* Cancel max-med onstartup if its on */
2002 if (bgp->t_maxmed_onstartup) {
2003 thread_cancel(&bgp->t_maxmed_onstartup);
2004 bgp->maxmed_onstartup_over = 1;
2005 }
abc920f8 2006
1ca2fd11
IR
2007 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
2008 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 2009
1ca2fd11
IR
2010 bgp_maxmed_update(bgp);
2011
2012 return CMD_SUCCESS;
abc920f8
DS
2013}
2014
d70583f7
D
2015static int bgp_global_update_delay_config_vty(struct vty *vty,
2016 uint16_t update_delay,
2017 uint16_t establish_wait)
2018{
2019 struct listnode *node, *nnode;
2020 struct bgp *bgp;
2021 bool vrf_cfg = false;
2022
2023 /*
2024 * See if update-delay is set per-vrf and warn user to delete it
2025 * Note that we only need to check this if this is the first time
2026 * setting the global config.
2027 */
2028 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
2029 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2030 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
2031 vty_out(vty,
2032 "%% update-delay configuration found in vrf %s\n",
2033 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
2034 ? VRF_DEFAULT_NAME
2035 : bgp->name);
2036 vrf_cfg = true;
2037 }
2038 }
2039 }
2040
2041 if (vrf_cfg) {
2042 vty_out(vty,
2043 "%%Failed: global update-delay config not permitted\n");
2044 return CMD_WARNING;
2045 }
2046
2047 if (!establish_wait) { /* update-delay <delay> */
2048 bm->v_update_delay = update_delay;
2049 bm->v_establish_wait = bm->v_update_delay;
2050 } else {
2051 /* update-delay <delay> <establish-wait> */
2052 if (update_delay < establish_wait) {
2053 vty_out(vty,
2054 "%%Failed: update-delay less than the establish-wait!\n");
2055 return CMD_WARNING_CONFIG_FAILED;
2056 }
2057
2058 bm->v_update_delay = update_delay;
2059 bm->v_establish_wait = establish_wait;
2060 }
2061
2062 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2063 bgp->v_update_delay = bm->v_update_delay;
2064 bgp->v_establish_wait = bm->v_establish_wait;
2065 }
2066
2067 return CMD_SUCCESS;
2068}
2069
2070static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
2071{
2072 struct listnode *node, *nnode;
2073 struct bgp *bgp;
2074
2075 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
2076 bm->v_establish_wait = bm->v_update_delay;
2077
2078 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2079 bgp->v_update_delay = bm->v_update_delay;
2080 bgp->v_establish_wait = bm->v_establish_wait;
2081 }
2082
2083 return CMD_SUCCESS;
2084}
2085
2086static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
2087 uint16_t establish_wait)
f188f2c4 2088{
d62a17ae 2089 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2090
d70583f7
D
2091 /* if configured globally, per-instance config is not allowed */
2092 if (bm->v_update_delay) {
2093 vty_out(vty,
2094 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
2095 return CMD_WARNING_CONFIG_FAILED;
2096 }
2097
f188f2c4 2098
d70583f7 2099 if (!establish_wait) /* update-delay <delay> */
d62a17ae 2100 {
2101 bgp->v_update_delay = update_delay;
2102 bgp->v_establish_wait = bgp->v_update_delay;
2103 return CMD_SUCCESS;
2104 }
f188f2c4 2105
d62a17ae 2106 /* update-delay <delay> <establish-wait> */
d62a17ae 2107 if (update_delay < establish_wait) {
2108 vty_out(vty,
2109 "%%Failed: update-delay less than the establish-wait!\n");
2110 return CMD_WARNING_CONFIG_FAILED;
2111 }
f188f2c4 2112
d62a17ae 2113 bgp->v_update_delay = update_delay;
2114 bgp->v_establish_wait = establish_wait;
f188f2c4 2115
d62a17ae 2116 return CMD_SUCCESS;
f188f2c4
DS
2117}
2118
d62a17ae 2119static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2120{
d62a17ae 2121 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2122
d70583f7
D
2123 /* If configured globally, cannot remove from one bgp instance */
2124 if (bm->v_update_delay) {
2125 vty_out(vty,
2126 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2127 return CMD_WARNING_CONFIG_FAILED;
2128 }
d62a17ae 2129 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2130 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2131
d62a17ae 2132 return CMD_SUCCESS;
f188f2c4
DS
2133}
2134
2b791107 2135void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2136{
d70583f7
D
2137 /* If configured globally, no need to display per-instance value */
2138 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2139 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2140 if (bgp->v_update_delay != bgp->v_establish_wait)
2141 vty_out(vty, " %d", bgp->v_establish_wait);
2142 vty_out(vty, "\n");
2143 }
f188f2c4
DS
2144}
2145
d70583f7
D
2146/* Global update-delay configuration */
2147DEFPY (bgp_global_update_delay,
2148 bgp_global_update_delay_cmd,
2149 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2150 BGP_STR
2151 "Force initial delay for best-path and updates for all bgp instances\n"
2152 "Max delay in seconds\n"
2153 "Establish wait in seconds\n")
2154{
2155 return bgp_global_update_delay_config_vty(vty, delay, wait);
2156}
f188f2c4 2157
d70583f7
D
2158/* Global update-delay deconfiguration */
2159DEFPY (no_bgp_global_update_delay,
2160 no_bgp_global_update_delay_cmd,
2161 "no bgp update-delay [(0-3600) [(1-3600)]]",
2162 NO_STR
2163 BGP_STR
f188f2c4 2164 "Force initial delay for best-path and updates\n"
d70583f7
D
2165 "Max delay in seconds\n"
2166 "Establish wait in seconds\n")
f188f2c4 2167{
d70583f7 2168 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2169}
2170
d70583f7
D
2171/* Update-delay configuration */
2172
2173DEFPY (bgp_update_delay,
2174 bgp_update_delay_cmd,
2175 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2176 "Force initial delay for best-path and updates\n"
d70583f7
D
2177 "Max delay in seconds\n"
2178 "Establish wait in seconds\n")
f188f2c4 2179{
d70583f7 2180 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2181}
2182
2183/* Update-delay deconfiguration */
d70583f7 2184DEFPY (no_bgp_update_delay,
f188f2c4 2185 no_bgp_update_delay_cmd,
838758ac
DW
2186 "no update-delay [(0-3600) [(1-3600)]]",
2187 NO_STR
f188f2c4 2188 "Force initial delay for best-path and updates\n"
d70583f7
D
2189 "Max delay in seconds\n"
2190 "Establish wait in seconds\n")
f188f2c4 2191{
d62a17ae 2192 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2193}
2194
5e242b0d 2195
1ca2fd11
IR
2196static int bgp_wpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2197 bool set)
cb1faec9 2198{
1ca2fd11
IR
2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
2200
8fa7732f
QY
2201 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2202 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2203
2204 return CMD_SUCCESS;
2205}
2206
1ca2fd11
IR
2207static int bgp_rpkt_quanta_config_vty(struct vty *vty, uint32_t quanta,
2208 bool set)
555e09d4 2209{
1ca2fd11
IR
2210 VTY_DECLVAR_CONTEXT(bgp, bgp);
2211
8fa7732f
QY
2212 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2213 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2214
d62a17ae 2215 return CMD_SUCCESS;
cb1faec9
DS
2216}
2217
2b791107 2218void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2219{
555e09d4
QY
2220 uint32_t quanta =
2221 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2222 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2223 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2224}
2225
555e09d4
QY
2226void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2227{
2228 uint32_t quanta =
2229 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2230 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2231 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2232}
cb1faec9 2233
8fa7732f
QY
2234/* Packet quanta configuration
2235 *
2236 * XXX: The value set here controls the size of a stack buffer in the IO
2237 * thread. When changing these limits be careful to prevent stack overflow.
2238 *
2239 * Furthermore, the maximums used here should correspond to
2240 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2241 */
1ca2fd11
IR
2242DEFPY (bgp_wpkt_quanta,
2243 bgp_wpkt_quanta_cmd,
2244 "[no] write-quanta (1-64)$quanta",
2245 NO_STR
2246 "How many packets to write to peer socket per run\n"
2247 "Number of packets\n")
2248{
2249 return bgp_wpkt_quanta_config_vty(vty, quanta, !no);
2250}
cb1faec9 2251
1ca2fd11
IR
2252DEFPY (bgp_rpkt_quanta,
2253 bgp_rpkt_quanta_cmd,
2254 "[no] read-quanta (1-10)$quanta",
2255 NO_STR
2256 "How many packets to read from peer socket per I/O cycle\n"
2257 "Number of packets\n")
2258{
2259 return bgp_rpkt_quanta_config_vty(vty, quanta, !no);
555e09d4
QY
2260}
2261
2b791107 2262void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2263{
37a333fe 2264 if (!bgp->heuristic_coalesce)
d62a17ae 2265 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2266}
2267
4668a151 2268
1ca2fd11
IR
2269DEFUN (bgp_coalesce_time,
2270 bgp_coalesce_time_cmd,
2271 "coalesce-time (0-4294967295)",
2272 "Subgroup coalesce timer\n"
2273 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2274{
1ca2fd11 2275 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 2276
1ca2fd11 2277 int idx = 0;
9b01d289 2278
1ca2fd11 2279 bgp->heuristic_coalesce = false;
9b01d289
DA
2280
2281 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2282 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
2283
1ca2fd11 2284 return CMD_SUCCESS;
3f9c7369
DS
2285}
2286
1ca2fd11
IR
2287DEFUN (no_bgp_coalesce_time,
2288 no_bgp_coalesce_time_cmd,
2289 "no coalesce-time (0-4294967295)",
2290 NO_STR
2291 "Subgroup coalesce timer\n"
2292 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2293{
1ca2fd11 2294 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 2295
1ca2fd11
IR
2296 bgp->heuristic_coalesce = true;
2297 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
2298 return CMD_SUCCESS;
3f9c7369
DS
2299}
2300
5e242b0d 2301/* Maximum-paths configuration */
585f1adc
IR
2302DEFUN (bgp_maxpaths,
2303 bgp_maxpaths_cmd,
2304 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2305 "Forward packets over multiple paths\n"
2306 "Number of paths\n")
5e242b0d 2307{
d62a17ae 2308 int idx_number = 1;
585f1adc
IR
2309 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2310 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2311}
2312
d62a17ae 2313ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2314 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2315 "Forward packets over multiple paths\n"
2316 "Number of paths\n")
596c17ba 2317
585f1adc
IR
2318DEFUN (bgp_maxpaths_ibgp,
2319 bgp_maxpaths_ibgp_cmd,
2320 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2321 "Forward packets over multiple paths\n"
2322 "iBGP-multipath\n"
2323 "Number of paths\n")
165b5fff 2324{
d62a17ae 2325 int idx_number = 2;
585f1adc
IR
2326 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2327 argv[idx_number]->arg, 0, 1);
5e242b0d 2328}
165b5fff 2329
d62a17ae 2330ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2331 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2332 "Forward packets over multiple paths\n"
2333 "iBGP-multipath\n"
2334 "Number of paths\n")
596c17ba 2335
585f1adc
IR
2336DEFUN (bgp_maxpaths_ibgp_cluster,
2337 bgp_maxpaths_ibgp_cluster_cmd,
2338 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2339 "Forward packets over multiple paths\n"
2340 "iBGP-multipath\n"
2341 "Number of paths\n"
2342 "Match the cluster length\n")
5e242b0d 2343{
d62a17ae 2344 int idx_number = 2;
aa53c036
DS
2345 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2346 argv[idx_number]->arg, true, 1);
165b5fff
JB
2347}
2348
d62a17ae 2349ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2350 "maximum-paths ibgp " CMD_RANGE_STR(
2351 1, MULTIPATH_NUM) " equal-cluster-length",
2352 "Forward packets over multiple paths\n"
2353 "iBGP-multipath\n"
2354 "Number of paths\n"
2355 "Match the cluster length\n")
596c17ba 2356
585f1adc
IR
2357DEFUN (no_bgp_maxpaths,
2358 no_bgp_maxpaths_cmd,
2359 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2360 NO_STR
2361 "Forward packets over multiple paths\n"
2362 "Number of paths\n")
165b5fff 2363{
585f1adc 2364 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2365}
2366
d62a17ae 2367ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2368 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2369 "Forward packets over multiple paths\n"
2370 "Number of paths\n")
596c17ba 2371
585f1adc
IR
2372DEFUN (no_bgp_maxpaths_ibgp,
2373 no_bgp_maxpaths_ibgp_cmd,
2374 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2375 NO_STR
2376 "Forward packets over multiple paths\n"
2377 "iBGP-multipath\n"
2378 "Number of paths\n"
2379 "Match the cluster length\n")
165b5fff 2380{
585f1adc 2381 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2382}
2383
d62a17ae 2384ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2385 "no maximum-paths ibgp [" CMD_RANGE_STR(
2386 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2387 NO_STR
2388 "Forward packets over multiple paths\n"
2389 "iBGP-multipath\n"
2390 "Number of paths\n"
2391 "Match the cluster length\n")
596c17ba 2392
dd65f45e
DL
2393static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2394 afi_t afi, safi_t safi)
165b5fff 2395{
00908b7a 2396 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2397 vty_out(vty, " maximum-paths %d\n",
2398 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2399 }
165b5fff 2400
00908b7a 2401 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2402 vty_out(vty, " maximum-paths ibgp %d",
2403 bgp->maxpaths[afi][safi].maxpaths_ibgp);
aa53c036 2404 if (bgp->maxpaths[afi][safi].same_clusterlen)
d62a17ae 2405 vty_out(vty, " equal-cluster-length");
2406 vty_out(vty, "\n");
2407 }
165b5fff 2408}
6b0655a2 2409
718e3744 2410/* BGP timers. */
2411
1ca2fd11
IR
2412DEFUN (bgp_timers,
2413 bgp_timers_cmd,
2414 "timers bgp (0-65535) (0-65535)",
2415 "Adjust routing timers\n"
2416 "BGP timers\n"
2417 "Keepalive interval\n"
2418 "Holdtime\n")
718e3744 2419{
1ca2fd11 2420 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 2421 int idx_number = 2;
2422 int idx_number_2 = 3;
1ca2fd11
IR
2423 unsigned long keepalive = 0;
2424 unsigned long holdtime = 0;
718e3744 2425
1ca2fd11
IR
2426 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
2427 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 2428
1ca2fd11
IR
2429 /* Holdtime value check. */
2430 if (holdtime < 3 && holdtime != 0) {
2431 vty_out(vty,
2432 "%% hold time value must be either 0 or greater than 3\n");
2433 return CMD_WARNING_CONFIG_FAILED;
2434 }
718e3744 2435
1ca2fd11
IR
2436 bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY,
2437 BGP_DEFAULT_DELAYOPEN);
718e3744 2438
1ca2fd11 2439 return CMD_SUCCESS;
718e3744 2440}
2441
1ca2fd11
IR
2442DEFUN (no_bgp_timers,
2443 no_bgp_timers_cmd,
2444 "no timers bgp [(0-65535) (0-65535)]",
2445 NO_STR
2446 "Adjust routing timers\n"
2447 "BGP timers\n"
2448 "Keepalive interval\n"
2449 "Holdtime\n")
718e3744 2450{
1ca2fd11
IR
2451 VTY_DECLVAR_CONTEXT(bgp, bgp);
2452 bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
2453 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
ff8a8a7a 2454
1ca2fd11 2455 return CMD_SUCCESS;
718e3744 2456}
2457
b042667a
TI
2458/* BGP minimum holdtime. */
2459
2460DEFUN(bgp_minimum_holdtime, bgp_minimum_holdtime_cmd,
2461 "bgp minimum-holdtime (1-65535)",
2462 "BGP specific commands\n"
2463 "BGP minimum holdtime\n"
2464 "Seconds\n")
2465{
2466 VTY_DECLVAR_CONTEXT(bgp, bgp);
2467 int idx_number = 2;
2468 unsigned long min_holdtime;
2469
2470 min_holdtime = strtoul(argv[idx_number]->arg, NULL, 10);
2471
2472 bgp->default_min_holdtime = min_holdtime;
2473
2474 return CMD_SUCCESS;
2475}
2476
2477DEFUN(no_bgp_minimum_holdtime, no_bgp_minimum_holdtime_cmd,
2478 "no bgp minimum-holdtime [(1-65535)]",
2479 NO_STR
2480 "BGP specific commands\n"
2481 "BGP minimum holdtime\n"
2482 "Seconds\n")
2483{
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485
2486 bgp->default_min_holdtime = 0;
2487
2488 return CMD_SUCCESS;
2489}
ff8a8a7a 2490
1ca2fd11
IR
2491DEFUN (bgp_client_to_client_reflection,
2492 bgp_client_to_client_reflection_cmd,
2493 "bgp client-to-client reflection",
e9273987 2494 BGP_STR
1ca2fd11
IR
2495 "Configure client to client route reflection\n"
2496 "reflection of routes allowed\n")
718e3744 2497{
1ca2fd11
IR
2498 VTY_DECLVAR_CONTEXT(bgp, bgp);
2499 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2500 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2501
1ca2fd11 2502 return CMD_SUCCESS;
718e3744 2503}
2504
1ca2fd11
IR
2505DEFUN (no_bgp_client_to_client_reflection,
2506 no_bgp_client_to_client_reflection_cmd,
2507 "no bgp client-to-client reflection",
2508 NO_STR
e9273987 2509 BGP_STR
1ca2fd11
IR
2510 "Configure client to client route reflection\n"
2511 "reflection of routes allowed\n")
718e3744 2512{
1ca2fd11
IR
2513 VTY_DECLVAR_CONTEXT(bgp, bgp);
2514 SET_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT);
2515 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 2516
1ca2fd11 2517 return CMD_SUCCESS;
718e3744 2518}
2519
2520/* "bgp always-compare-med" configuration. */
1ca2fd11
IR
2521DEFUN (bgp_always_compare_med,
2522 bgp_always_compare_med_cmd,
2523 "bgp always-compare-med",
e9273987 2524 BGP_STR
1ca2fd11 2525 "Allow comparing MED from different neighbors\n")
718e3744 2526{
1ca2fd11
IR
2527 VTY_DECLVAR_CONTEXT(bgp, bgp);
2528 SET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2529 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2530
1ca2fd11 2531 return CMD_SUCCESS;
718e3744 2532}
2533
1ca2fd11
IR
2534DEFUN (no_bgp_always_compare_med,
2535 no_bgp_always_compare_med_cmd,
2536 "no bgp always-compare-med",
2537 NO_STR
e9273987 2538 BGP_STR
1ca2fd11 2539 "Allow comparing MED from different neighbors\n")
718e3744 2540{
1ca2fd11
IR
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 UNSET_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED);
2543 bgp_recalculate_all_bestpaths(bgp);
6b0655a2 2544
1ca2fd11 2545 return CMD_SUCCESS;
2adac256
DA
2546}
2547
2adac256 2548
1ca2fd11
IR
2549DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
2550 "bgp ebgp-requires-policy",
e9273987 2551 BGP_STR
1ca2fd11 2552 "Require in and out policy for eBGP peers (RFC8212)\n")
2adac256 2553{
1ca2fd11
IR
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555 SET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2556 return CMD_SUCCESS;
2adac256
DA
2557}
2558
1ca2fd11
IR
2559DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
2560 "no bgp ebgp-requires-policy",
2561 NO_STR
e9273987 2562 BGP_STR
1ca2fd11 2563 "Require in and out policy for eBGP peers (RFC8212)\n")
ff8a8a7a 2564{
1ca2fd11
IR
2565 VTY_DECLVAR_CONTEXT(bgp, bgp);
2566 UNSET_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2567 return CMD_SUCCESS;
ff8a8a7a 2568}
9dac9fc8 2569
1ca2fd11
IR
2570DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
2571 "bgp suppress-duplicates",
e9273987 2572 BGP_STR
1ca2fd11 2573 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2574{
1ca2fd11
IR
2575 VTY_DECLVAR_CONTEXT(bgp, bgp);
2576 SET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2577 return CMD_SUCCESS;
9dac9fc8
DA
2578}
2579
1ca2fd11
IR
2580DEFUN(no_bgp_suppress_duplicates, no_bgp_suppress_duplicates_cmd,
2581 "no bgp suppress-duplicates",
2582 NO_STR
e9273987 2583 BGP_STR
1ca2fd11 2584 "Suppress duplicate updates if the route actually not changed\n")
9dac9fc8 2585{
1ca2fd11
IR
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 UNSET_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
2588 return CMD_SUCCESS;
9dac9fc8
DA
2589}
2590
fb29348a
DA
2591DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2592 "bgp reject-as-sets",
e9273987 2593 BGP_STR
fb29348a
DA
2594 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2595{
2596 VTY_DECLVAR_CONTEXT(bgp, bgp);
2597 struct listnode *node, *nnode;
2598 struct peer *peer;
2599
7f972cd8 2600 bgp->reject_as_sets = true;
fb29348a
DA
2601
2602 /* Reset existing BGP sessions to reject routes
2603 * with aspath containing AS_SET or AS_CONFED_SET.
2604 */
2605 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2606 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2607 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2608 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2609 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2610 }
2611 }
2612
2613 return CMD_SUCCESS;
2614}
2615
2616DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2617 "no bgp reject-as-sets",
2618 NO_STR
e9273987 2619 BGP_STR
fb29348a
DA
2620 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2621{
2622 VTY_DECLVAR_CONTEXT(bgp, bgp);
2623 struct listnode *node, *nnode;
2624 struct peer *peer;
2625
7f972cd8 2626 bgp->reject_as_sets = false;
fb29348a
DA
2627
2628 /* Reset existing BGP sessions to reject routes
2629 * with aspath containing AS_SET or AS_CONFED_SET.
2630 */
2631 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2632 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2633 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2634 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2635 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2636 }
2637 }
2638
2639 return CMD_SUCCESS;
2640}
9dac9fc8 2641
718e3744 2642/* "bgp deterministic-med" configuration. */
1ca2fd11 2643DEFUN (bgp_deterministic_med,
718e3744 2644 bgp_deterministic_med_cmd,
2645 "bgp deterministic-med",
e9273987 2646 BGP_STR
718e3744 2647 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2648{
1ca2fd11
IR
2649 VTY_DECLVAR_CONTEXT(bgp, bgp);
2650
2651 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2652 SET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2653 bgp_recalculate_all_bestpaths(bgp);
2654 }
7aafcaca 2655
1ca2fd11 2656 return CMD_SUCCESS;
718e3744 2657}
2658
1ca2fd11 2659DEFUN (no_bgp_deterministic_med,
718e3744 2660 no_bgp_deterministic_med_cmd,
2661 "no bgp deterministic-med",
2662 NO_STR
e9273987 2663 BGP_STR
718e3744 2664 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2665{
1ca2fd11
IR
2666 VTY_DECLVAR_CONTEXT(bgp, bgp);
2667 int bestpath_per_as_used;
2668 afi_t afi;
2669 safi_t safi;
2670 struct peer *peer;
2671 struct listnode *node, *nnode;
2672
2673 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
2674 bestpath_per_as_used = 0;
2675
2676 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2677 FOREACH_AFI_SAFI (afi, safi)
2678 if (bgp_addpath_dmed_required(
2679 peer->addpath_type[afi][safi])) {
2680 bestpath_per_as_used = 1;
2681 break;
2682 }
2683
2684 if (bestpath_per_as_used)
2685 break;
2686 }
2687
2688 if (bestpath_per_as_used) {
2689 vty_out(vty,
2690 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
2691 return CMD_WARNING_CONFIG_FAILED;
2692 } else {
2693 UNSET_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED);
2694 bgp_recalculate_all_bestpaths(bgp);
2695 }
2696 }
d62a17ae 2697
1ca2fd11 2698 return CMD_SUCCESS;
718e3744 2699}
538621f2 2700
055679e9 2701/* "bgp graceful-restart mode" configuration. */
538621f2 2702DEFUN (bgp_graceful_restart,
2ba1fe69 2703 bgp_graceful_restart_cmd,
2704 "bgp graceful-restart",
e9273987 2705 BGP_STR
2ba1fe69 2706 GR_CMD
055679e9 2707 )
538621f2 2708{
055679e9 2709 int ret = BGP_GR_FAILURE;
2710
2711 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2712 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2713
d62a17ae 2714 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2715
2716 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2717
36235319
QY
2718 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2719 ret);
5cce3f05 2720
055679e9 2721 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2722 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2723 vty_out(vty,
2724 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2725 return bgp_vty_return(vty, ret);
538621f2 2726}
2727
2728DEFUN (no_bgp_graceful_restart,
2ba1fe69 2729 no_bgp_graceful_restart_cmd,
2730 "no bgp graceful-restart",
2731 NO_STR
e9273987 2732 BGP_STR
2ba1fe69 2733 NO_GR_CMD
055679e9 2734 )
538621f2 2735{
d62a17ae 2736 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2737
2738 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2739 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2740
2741 int ret = BGP_GR_FAILURE;
2742
2743 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2744
36235319
QY
2745 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2746 ret);
5cce3f05 2747
055679e9 2748 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2749 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2750 vty_out(vty,
2751 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2752
2753 return bgp_vty_return(vty, ret);
538621f2 2754}
2755
93406d87 2756DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2757 bgp_graceful_restart_stalepath_time_cmd,
2758 "bgp graceful-restart stalepath-time (1-4095)",
e9273987 2759 BGP_STR
2ba1fe69 2760 "Graceful restart capability parameters\n"
2761 "Set the max time to hold onto restarting peer's stale paths\n"
2762 "Delay value (seconds)\n")
93406d87 2763{
d62a17ae 2764 VTY_DECLVAR_CONTEXT(bgp, bgp);
2765 int idx_number = 3;
d7c0a89a 2766 uint32_t stalepath;
93406d87 2767
d62a17ae 2768 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2769 bgp->stalepath_time = stalepath;
2770 return CMD_SUCCESS;
93406d87 2771}
2772
eb6f1b41 2773DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2774 bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2775 "bgp graceful-restart restart-time (0-4095)",
e9273987 2776 BGP_STR
2ba1fe69 2777 "Graceful restart capability parameters\n"
2778 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2779 "Delay value (seconds)\n")
eb6f1b41 2780{
d62a17ae 2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 int idx_number = 3;
d7c0a89a 2783 uint32_t restart;
eb6f1b41 2784
d62a17ae 2785 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2786 bgp->restart_time = restart;
2787 return CMD_SUCCESS;
eb6f1b41
PG
2788}
2789
cfd47646 2790DEFUN (bgp_graceful_restart_select_defer_time,
2791 bgp_graceful_restart_select_defer_time_cmd,
2792 "bgp graceful-restart select-defer-time (0-3600)",
e9273987 2793 BGP_STR
cfd47646 2794 "Graceful restart capability parameters\n"
2795 "Set the time to defer the BGP route selection after restart\n"
2796 "Delay value (seconds, 0 - disable)\n")
2797{
2798 VTY_DECLVAR_CONTEXT(bgp, bgp);
2799 int idx_number = 3;
2800 uint32_t defer_time;
2801
2802 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2803 bgp->select_defer_time = defer_time;
2804 if (defer_time == 0)
892fedb6 2805 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2806 else
892fedb6 2807 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2808
2809 return CMD_SUCCESS;
2810}
2811
93406d87 2812DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2813 no_bgp_graceful_restart_stalepath_time_cmd,
2814 "no bgp graceful-restart stalepath-time [(1-4095)]",
2815 NO_STR
e9273987 2816 BGP_STR
2ba1fe69 2817 "Graceful restart capability parameters\n"
2818 "Set the max time to hold onto restarting peer's stale paths\n"
2819 "Delay value (seconds)\n")
93406d87 2820{
d62a17ae 2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2822
d62a17ae 2823 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2824 return CMD_SUCCESS;
93406d87 2825}
2826
eb6f1b41 2827DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2828 no_bgp_graceful_restart_restart_time_cmd,
dcbebfd3 2829 "no bgp graceful-restart restart-time [(0-4095)]",
2ba1fe69 2830 NO_STR
e9273987 2831 BGP_STR
2ba1fe69 2832 "Graceful restart capability parameters\n"
2833 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2834 "Delay value (seconds)\n")
eb6f1b41 2835{
d62a17ae 2836 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2837
d62a17ae 2838 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2839 return CMD_SUCCESS;
eb6f1b41
PG
2840}
2841
cfd47646 2842DEFUN (no_bgp_graceful_restart_select_defer_time,
2843 no_bgp_graceful_restart_select_defer_time_cmd,
2844 "no bgp graceful-restart select-defer-time [(0-3600)]",
2845 NO_STR
e9273987 2846 BGP_STR
cfd47646 2847 "Graceful restart capability parameters\n"
2848 "Set the time to defer the BGP route selection after restart\n"
2849 "Delay value (seconds)\n")
2850{
2851 VTY_DECLVAR_CONTEXT(bgp, bgp);
2852
2853 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2854 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2855
2856 return CMD_SUCCESS;
2857}
2858
43fc21b3 2859DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2860 bgp_graceful_restart_preserve_fw_cmd,
2861 "bgp graceful-restart preserve-fw-state",
e9273987 2862 BGP_STR
2ba1fe69 2863 "Graceful restart capability parameters\n"
2864 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2865{
d62a17ae 2866 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2867 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2868 return CMD_SUCCESS;
43fc21b3
JC
2869}
2870
2871DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2872 no_bgp_graceful_restart_preserve_fw_cmd,
2873 "no bgp graceful-restart preserve-fw-state",
2874 NO_STR
e9273987 2875 BGP_STR
2ba1fe69 2876 "Graceful restart capability parameters\n"
2877 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2878{
d62a17ae 2879 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2880 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2881 return CMD_SUCCESS;
43fc21b3
JC
2882}
2883
f2ca5c5b
DA
2884DEFPY (bgp_graceful_restart_notification,
2885 bgp_graceful_restart_notification_cmd,
2886 "[no$no] bgp graceful-restart notification",
2887 NO_STR
2888 BGP_STR
2889 "Graceful restart capability parameters\n"
2890 "Indicate Graceful Restart support for BGP NOTIFICATION messages\n")
2891{
2892 VTY_DECLVAR_CONTEXT(bgp, bgp);
2893
2894 if (no)
2895 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2896 else
2897 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION);
2898
2899 return CMD_SUCCESS;
2900}
2901
1ae314be
DA
2902DEFPY (bgp_administrative_reset,
2903 bgp_administrative_reset_cmd,
2904 "[no$no] bgp hard-administrative-reset",
2905 NO_STR
2906 BGP_STR
2907 "Send Hard Reset CEASE Notification for 'Administrative Reset'\n")
2908{
2909 VTY_DECLVAR_CONTEXT(bgp, bgp);
2910
2911 if (no)
2912 UNSET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2913 else
2914 SET_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET);
2915
2916 return CMD_SUCCESS;
2917}
2918
055679e9 2919DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2920 bgp_graceful_restart_disable_cmd,
2921 "bgp graceful-restart-disable",
e9273987 2922 BGP_STR
2ba1fe69 2923 GR_DISABLE)
055679e9 2924{
2925 int ret = BGP_GR_FAILURE;
2926
2927 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2928 zlog_debug(
2ba1fe69 2929 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2930
055679e9 2931 VTY_DECLVAR_CONTEXT(bgp, bgp);
2932
2933 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2934
dc95985f 2935 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2936 bgp->peer, ret);
5cce3f05 2937
055679e9 2938 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2939 zlog_debug(
2ba1fe69 2940 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2941 vty_out(vty,
2942 "Graceful restart configuration changed, reset all peers to take effect\n");
2943
055679e9 2944 return bgp_vty_return(vty, ret);
2945}
2946
2947DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2948 no_bgp_graceful_restart_disable_cmd,
2949 "no bgp graceful-restart-disable",
2950 NO_STR
e9273987 2951 BGP_STR
2ba1fe69 2952 NO_GR_DISABLE
055679e9 2953 )
2954{
2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956
2957 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2958 zlog_debug(
2ba1fe69 2959 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2960
2961 int ret = BGP_GR_FAILURE;
2962
2963 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2964
36235319
QY
2965 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2966 ret);
5cce3f05 2967
055679e9 2968 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2969 zlog_debug(
2ba1fe69 2970 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2971 vty_out(vty,
2972 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2973
2974 return bgp_vty_return(vty, ret);
2975}
2976
2977DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2978 bgp_neighbor_graceful_restart_set_cmd,
2979 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2980 NEIGHBOR_STR
2981 NEIGHBOR_ADDR_STR2
2982 GR_NEIGHBOR_CMD
055679e9 2983 )
2984{
2985 int idx_peer = 1;
2986 struct peer *peer;
2987 int ret = BGP_GR_FAILURE;
2988
dc95985f 2989 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2990
055679e9 2991 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2992 zlog_debug(
2ba1fe69 2993 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2994
055679e9 2995 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2996 if (!peer)
2997 return CMD_WARNING_CONFIG_FAILED;
2998
2999 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
3000
dc95985f 3001 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3002 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3003
3004 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3005 zlog_debug(
2ba1fe69 3006 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3007 vty_out(vty,
3008 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3009
3010 return bgp_vty_return(vty, ret);
3011}
3012
3013DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3014 no_bgp_neighbor_graceful_restart_set_cmd,
3015 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3016 NO_STR
3017 NEIGHBOR_STR
3018 NEIGHBOR_ADDR_STR2
3019 NO_GR_NEIGHBOR_CMD
055679e9 3020 )
3021{
3022 int idx_peer = 2;
3023 int ret = BGP_GR_FAILURE;
3024 struct peer *peer;
3025
dc95985f 3026 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3027
055679e9 3028 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3029 if (!peer)
3030 return CMD_WARNING_CONFIG_FAILED;
3031
3032 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3033 zlog_debug(
2ba1fe69 3034 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3035
3036 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3037
dc95985f 3038 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3039 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3040
3041 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3042 zlog_debug(
2ba1fe69 3043 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3044 vty_out(vty,
3045 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3046
3047 return bgp_vty_return(vty, ret);
3048}
3049
3050DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3051 bgp_neighbor_graceful_restart_helper_set_cmd,
3052 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3053 NEIGHBOR_STR
3054 NEIGHBOR_ADDR_STR2
3055 GR_NEIGHBOR_HELPER_CMD
055679e9 3056 )
3057{
3058 int idx_peer = 1;
3059 struct peer *peer;
3060 int ret = BGP_GR_FAILURE;
3061
dc95985f 3062 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3063
055679e9 3064 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3065 zlog_debug(
2ba1fe69 3066 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3067
055679e9 3068 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3069
055679e9 3070 if (!peer)
3071 return CMD_WARNING_CONFIG_FAILED;
3072
3073
3074 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3075
dc95985f 3076 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3077 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3078
055679e9 3079 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3080 zlog_debug(
2ba1fe69 3081 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3082 vty_out(vty,
3083 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3084
3085 return bgp_vty_return(vty, ret);
3086}
3087
3088DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3089 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3090 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3091 NO_STR
3092 NEIGHBOR_STR
3093 NEIGHBOR_ADDR_STR2
3094 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3095 )
3096{
3097 int idx_peer = 2;
3098 int ret = BGP_GR_FAILURE;
3099 struct peer *peer;
3100
dc95985f 3101 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3102
055679e9 3103 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3104 if (!peer)
3105 return CMD_WARNING_CONFIG_FAILED;
3106
3107 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3108 zlog_debug(
2ba1fe69 3109 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3110
36235319 3111 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3112
dc95985f 3113 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3114 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3115
3116 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3117 zlog_debug(
2ba1fe69 3118 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3119 vty_out(vty,
3120 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3121
3122 return bgp_vty_return(vty, ret);
3123}
3124
3125DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3126 bgp_neighbor_graceful_restart_disable_set_cmd,
3127 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3128 NEIGHBOR_STR
3129 NEIGHBOR_ADDR_STR2
3130 GR_NEIGHBOR_DISABLE_CMD
055679e9 3131 )
3132{
3133 int idx_peer = 1;
3134 struct peer *peer;
3135 int ret = BGP_GR_FAILURE;
3136
dc95985f 3137 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3138
055679e9 3139 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3140 zlog_debug(
2ba1fe69 3141 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3142
3143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3144 if (!peer)
3145 return CMD_WARNING_CONFIG_FAILED;
3146
36235319 3147 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3148
3149 if (peer->bgp->t_startup)
3150 bgp_peer_gr_flags_update(peer);
3151
dc95985f 3152 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3153 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3154
055679e9 3155 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3156 zlog_debug(
2ba1fe69 3157 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3158 vty_out(vty,
3159 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3160
3161 return bgp_vty_return(vty, ret);
3162}
3163
3164DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3165 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3166 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3167 NO_STR
3168 NEIGHBOR_STR
3169 NEIGHBOR_ADDR_STR2
3170 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3171 )
3172{
3173 int idx_peer = 2;
3174 int ret = BGP_GR_FAILURE;
3175 struct peer *peer;
3176
dc95985f 3177 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3178
055679e9 3179 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3180 if (!peer)
3181 return CMD_WARNING_CONFIG_FAILED;
3182
3183 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3184 zlog_debug(
2ba1fe69 3185 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3186
3187 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3188
dc95985f 3189 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3190 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3191
3192 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3193 zlog_debug(
2ba1fe69 3194 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3195 vty_out(vty,
3196 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3197
3198 return bgp_vty_return(vty, ret);
3199}
3200
d6e3c15b 3201DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3202 bgp_graceful_restart_disable_eor_cmd,
3203 "bgp graceful-restart disable-eor",
e9273987 3204 BGP_STR
d6e3c15b 3205 "Graceful restart configuration parameters\n"
3206 "Disable EOR Check\n")
3207{
3208 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3209 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3210
d6e3c15b 3211 return CMD_SUCCESS;
3212}
3213
3214DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3215 no_bgp_graceful_restart_disable_eor_cmd,
3216 "no bgp graceful-restart disable-eor",
3217 NO_STR
e9273987 3218 BGP_STR
d6e3c15b 3219 "Graceful restart configuration parameters\n"
3220 "Disable EOR Check\n")
3221{
3222 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3223 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3224
3225 return CMD_SUCCESS;
3226}
3227
3228DEFUN (bgp_graceful_restart_rib_stale_time,
3229 bgp_graceful_restart_rib_stale_time_cmd,
3230 "bgp graceful-restart rib-stale-time (1-3600)",
e9273987 3231 BGP_STR
dc95985f 3232 "Graceful restart configuration parameters\n"
3233 "Specify the stale route removal timer in rib\n"
3234 "Delay value (seconds)\n")
3235{
3236 VTY_DECLVAR_CONTEXT(bgp, bgp);
3237 int idx_number = 3;
3238 uint32_t stale_time;
3239
3240 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3241 bgp->rib_stale_time = stale_time;
3242 /* Send the stale timer update message to RIB */
3243 if (bgp_zebra_stale_timer_update(bgp))
3244 return CMD_WARNING;
3245
3246 return CMD_SUCCESS;
3247}
3248
3249DEFUN (no_bgp_graceful_restart_rib_stale_time,
3250 no_bgp_graceful_restart_rib_stale_time_cmd,
3251 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3252 NO_STR
e9273987 3253 BGP_STR
dc95985f 3254 "Graceful restart configuration parameters\n"
3255 "Specify the stale route removal timer in rib\n"
3256 "Delay value (seconds)\n")
3257{
3258 VTY_DECLVAR_CONTEXT(bgp, bgp);
3259
3260 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3261 /* Send the stale timer update message to RIB */
3262 if (bgp_zebra_stale_timer_update(bgp))
3263 return CMD_WARNING;
3264
d6e3c15b 3265 return CMD_SUCCESS;
3266}
3267
8606be87 3268DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd,
7f8a9a24
DA
3269 "bgp long-lived-graceful-restart stale-time (1-4294967295)",
3270 BGP_STR
8606be87
DA
3271 "Enable Long-lived Graceful Restart\n"
3272 "Specifies maximum time to wait before purging long-lived stale routes\n"
3273 "Stale time value (seconds)\n")
3274{
3275 VTY_DECLVAR_CONTEXT(bgp, bgp);
3276
3277 uint32_t llgr_stale_time;
3278
3279 llgr_stale_time = strtoul(argv[3]->arg, NULL, 10);
3280 bgp->llgr_stale_time = llgr_stale_time;
3281
3282 return CMD_SUCCESS;
3283}
3284
3285DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd,
7f8a9a24 3286 "no bgp long-lived-graceful-restart stale-time [(1-4294967295)]",
8606be87
DA
3287 NO_STR BGP_STR
3288 "Enable Long-lived Graceful Restart\n"
3289 "Specifies maximum time to wait before purging long-lived stale routes\n"
3290 "Stale time value (seconds)\n")
3291{
3292 VTY_DECLVAR_CONTEXT(bgp, bgp);
3293
3294 bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME;
3295
3296 return CMD_SUCCESS;
3297}
3298
1ca2fd11
IR
3299static inline void bgp_initiate_graceful_shut_unshut(struct vty *vty,
3300 struct bgp *bgp)
05bd726c 3301{
3302 bgp_static_redo_import_check(bgp);
3303 bgp_redistribute_redo(bgp);
1ca2fd11
IR
3304 bgp_clear_star_soft_out(vty, bgp->name);
3305 bgp_clear_star_soft_in(vty, bgp->name);
05bd726c 3306}
3307
3308static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3309{
3310 struct listnode *node, *nnode;
3311 struct bgp *bgp;
3312 bool vrf_cfg = false;
3313
3314 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3315 return CMD_SUCCESS;
3316
3317 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3318 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3319 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3320 vty_out(vty,
3321 "%% graceful-shutdown configuration found in vrf %s\n",
3322 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3323 VRF_DEFAULT_NAME : bgp->name);
3324 vrf_cfg = true;
3325 }
3326 }
3327
3328 if (vrf_cfg) {
3329 vty_out(vty,
3330 "%%Failed: global graceful-shutdown not permitted\n");
3331 return CMD_WARNING;
3332 }
3333
3334 /* Set flag globally */
3335 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3336
3337 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3338 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3339 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3340
3341 return CMD_SUCCESS;
3342}
3343
3344static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3345{
3346 struct listnode *node, *nnode;
3347 struct bgp *bgp;
3348
3349 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3350 return CMD_SUCCESS;
3351
3352 /* Unset flag globally */
3353 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3354
3355 /* Initiate processing for all BGP instances. */
1ca2fd11
IR
3356 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
3357 bgp_initiate_graceful_shut_unshut(vty, bgp);
05bd726c 3358
3359 return CMD_SUCCESS;
3360}
3361
7f323236
DW
3362/* "bgp graceful-shutdown" configuration */
3363DEFUN (bgp_graceful_shutdown,
3364 bgp_graceful_shutdown_cmd,
3365 "bgp graceful-shutdown",
3366 BGP_STR
3367 "Graceful shutdown parameters\n")
3368{
05bd726c 3369 if (vty->node == CONFIG_NODE)
3370 return bgp_global_graceful_shutdown_config_vty(vty);
3371
1ca2fd11 3372 VTY_DECLVAR_CONTEXT(bgp, bgp);
7f323236 3373
1ca2fd11
IR
3374 /* if configured globally, per-instance config is not allowed */
3375 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3376 vty_out(vty,
3377 "%%Failed: per-vrf graceful-shutdown config not permitted with global graceful-shutdown\n");
3378 return CMD_WARNING_CONFIG_FAILED;
3379 }
3380
3381 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3382 SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3383 bgp_initiate_graceful_shut_unshut(vty, bgp);
3384 }
3385
3386 return CMD_SUCCESS;
7f323236
DW
3387}
3388
1ca2fd11 3389DEFUN (no_bgp_graceful_shutdown,
7f323236
DW
3390 no_bgp_graceful_shutdown_cmd,
3391 "no bgp graceful-shutdown",
3392 NO_STR
3393 BGP_STR
3394 "Graceful shutdown parameters\n")
3395{
05bd726c 3396 if (vty->node == CONFIG_NODE)
3397 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3398
1ca2fd11 3399 VTY_DECLVAR_CONTEXT(bgp, bgp);
05bd726c 3400
1ca2fd11
IR
3401 /* If configured globally, cannot remove from one bgp instance */
3402 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) {
3403 vty_out(vty,
3404 "%%Failed: bgp graceful-shutdown configured globally. Delete per-vrf not permitted\n");
3405 return CMD_WARNING_CONFIG_FAILED;
3406 }
7f323236 3407
1ca2fd11
IR
3408 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3409 UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN);
3410 bgp_initiate_graceful_shut_unshut(vty, bgp);
3411 }
3412
3413 return CMD_SUCCESS;
7f323236
DW
3414}
3415
718e3744 3416/* "bgp fast-external-failover" configuration. */
1ca2fd11 3417DEFUN (bgp_fast_external_failover,
718e3744 3418 bgp_fast_external_failover_cmd,
3419 "bgp fast-external-failover",
3420 BGP_STR
3421 "Immediately reset session if a link to a directly connected external peer goes down\n")
3422{
1ca2fd11
IR
3423 VTY_DECLVAR_CONTEXT(bgp, bgp);
3424 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3425 return CMD_SUCCESS;
718e3744 3426}
3427
1ca2fd11 3428DEFUN (no_bgp_fast_external_failover,
718e3744 3429 no_bgp_fast_external_failover_cmd,
3430 "no bgp fast-external-failover",
3431 NO_STR
3432 BGP_STR
3433 "Immediately reset session if a link to a directly connected external peer goes down\n")
3434{
1ca2fd11
IR
3435 VTY_DECLVAR_CONTEXT(bgp, bgp);
3436 SET_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER);
3437 return CMD_SUCCESS;
718e3744 3438}
6b0655a2 3439
718e3744 3440/* "bgp bestpath compare-routerid" configuration. */
1ca2fd11
IR
3441DEFUN (bgp_bestpath_compare_router_id,
3442 bgp_bestpath_compare_router_id_cmd,
3443 "bgp bestpath compare-routerid",
e9273987 3444 BGP_STR
1ca2fd11
IR
3445 "Change the default bestpath selection\n"
3446 "Compare router-id for identical EBGP paths\n")
718e3744 3447{
1ca2fd11
IR
3448 VTY_DECLVAR_CONTEXT(bgp, bgp);
3449 SET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3450 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3451
1ca2fd11 3452 return CMD_SUCCESS;
718e3744 3453}
3454
1ca2fd11
IR
3455DEFUN (no_bgp_bestpath_compare_router_id,
3456 no_bgp_bestpath_compare_router_id_cmd,
3457 "no bgp bestpath compare-routerid",
3458 NO_STR
e9273987 3459 BGP_STR
1ca2fd11
IR
3460 "Change the default bestpath selection\n"
3461 "Compare router-id for identical EBGP paths\n")
718e3744 3462{
1ca2fd11
IR
3463 VTY_DECLVAR_CONTEXT(bgp, bgp);
3464 UNSET_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID);
3465 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3466
1ca2fd11 3467 return CMD_SUCCESS;
718e3744 3468}
6b0655a2 3469
718e3744 3470/* "bgp bestpath as-path ignore" configuration. */
1ca2fd11
IR
3471DEFUN (bgp_bestpath_aspath_ignore,
3472 bgp_bestpath_aspath_ignore_cmd,
3473 "bgp bestpath as-path ignore",
e9273987 3474 BGP_STR
1ca2fd11
IR
3475 "Change the default bestpath selection\n"
3476 "AS-path attribute\n"
3477 "Ignore as-path length in selecting a route\n")
718e3744 3478{
1ca2fd11
IR
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3481 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3482
1ca2fd11 3483 return CMD_SUCCESS;
718e3744 3484}
3485
1ca2fd11
IR
3486DEFUN (no_bgp_bestpath_aspath_ignore,
3487 no_bgp_bestpath_aspath_ignore_cmd,
3488 "no bgp bestpath as-path ignore",
3489 NO_STR
e9273987 3490 BGP_STR
1ca2fd11
IR
3491 "Change the default bestpath selection\n"
3492 "AS-path attribute\n"
3493 "Ignore as-path length in selecting a route\n")
718e3744 3494{
1ca2fd11
IR
3495 VTY_DECLVAR_CONTEXT(bgp, bgp);
3496 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE);
3497 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3498
1ca2fd11 3499 return CMD_SUCCESS;
718e3744 3500}
6b0655a2 3501
6811845b 3502/* "bgp bestpath as-path confed" configuration. */
1ca2fd11 3503DEFUN (bgp_bestpath_aspath_confed,
6811845b 3504 bgp_bestpath_aspath_confed_cmd,
3505 "bgp bestpath as-path confed",
e9273987 3506 BGP_STR
6811845b 3507 "Change the default bestpath selection\n"
3508 "AS-path attribute\n"
3509 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3510{
1ca2fd11
IR
3511 VTY_DECLVAR_CONTEXT(bgp, bgp);
3512 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3513 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3514
1ca2fd11 3515 return CMD_SUCCESS;
6811845b 3516}
3517
1ca2fd11 3518DEFUN (no_bgp_bestpath_aspath_confed,
6811845b 3519 no_bgp_bestpath_aspath_confed_cmd,
3520 "no bgp bestpath as-path confed",
3521 NO_STR
e9273987 3522 BGP_STR
6811845b 3523 "Change the default bestpath selection\n"
3524 "AS-path attribute\n"
3525 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3526{
1ca2fd11
IR
3527 VTY_DECLVAR_CONTEXT(bgp, bgp);
3528 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED);
3529 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3530
1ca2fd11 3531 return CMD_SUCCESS;
6811845b 3532}
6b0655a2 3533
2fdd455c 3534/* "bgp bestpath as-path multipath-relax" configuration. */
1ca2fd11 3535DEFUN (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3536 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3537 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
e9273987 3538 BGP_STR
16fc1eec
DS
3539 "Change the default bestpath selection\n"
3540 "AS-path attribute\n"
3541 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3542 "Generate an AS_SET\n"
16fc1eec
DS
3543 "Do not generate an AS_SET\n")
3544{
1ca2fd11 3545 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3546 int idx = 0;
1ca2fd11 3547 SET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 3548
1ca2fd11
IR
3549 /* no-as-set is now the default behavior so we can silently
3550 * ignore it */
d62a17ae 3551 if (argv_find(argv, argc, "as-set", &idx))
1ca2fd11 3552 SET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
d62a17ae 3553 else
1ca2fd11 3554 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca 3555
1ca2fd11
IR
3556 bgp_recalculate_all_bestpaths(bgp);
3557
3558 return CMD_SUCCESS;
16fc1eec
DS
3559}
3560
1ca2fd11 3561DEFUN (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3562 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3563 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec 3564 NO_STR
e9273987 3565 BGP_STR
16fc1eec
DS
3566 "Change the default bestpath selection\n"
3567 "AS-path attribute\n"
3568 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3569 "Generate an AS_SET\n"
16fc1eec
DS
3570 "Do not generate an AS_SET\n")
3571{
1ca2fd11
IR
3572 VTY_DECLVAR_CONTEXT(bgp, bgp);
3573 UNSET_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
3574 UNSET_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
3575 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3576
1ca2fd11 3577 return CMD_SUCCESS;
2fdd455c 3578}
6b0655a2 3579
ee88563a
JM
3580/* "bgp bestpath peer-type multipath-relax" configuration. */
3581DEFUN(bgp_bestpath_peer_type_multipath_relax,
3582 bgp_bestpath_peer_type_multipath_relax_cmd,
3583 "bgp bestpath peer-type multipath-relax",
3584 BGP_STR
3585 "Change the default bestpath selection\n"
3586 "Peer type\n"
3587 "Allow load sharing across routes learned from different peer types\n")
3588{
3589 VTY_DECLVAR_CONTEXT(bgp, bgp);
3590 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3591 bgp_recalculate_all_bestpaths(bgp);
3592
3593 return CMD_SUCCESS;
3594}
3595
3596DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3597 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3598 "no bgp bestpath peer-type multipath-relax",
3599 NO_STR BGP_STR
3600 "Change the default bestpath selection\n"
3601 "Peer type\n"
3602 "Allow load sharing across routes learned from different peer types\n")
3603{
3604 VTY_DECLVAR_CONTEXT(bgp, bgp);
3605 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3606 bgp_recalculate_all_bestpaths(bgp);
3607
3608 return CMD_SUCCESS;
3609}
3610
848973c7 3611/* "bgp log-neighbor-changes" configuration. */
1ca2fd11
IR
3612DEFUN (bgp_log_neighbor_changes,
3613 bgp_log_neighbor_changes_cmd,
3614 "bgp log-neighbor-changes",
e9273987 3615 BGP_STR
1ca2fd11 3616 "Log neighbor up/down and reset reason\n")
848973c7 3617{
1ca2fd11
IR
3618 VTY_DECLVAR_CONTEXT(bgp, bgp);
3619 SET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3620 return CMD_SUCCESS;
848973c7 3621}
3622
1ca2fd11
IR
3623DEFUN (no_bgp_log_neighbor_changes,
3624 no_bgp_log_neighbor_changes_cmd,
3625 "no bgp log-neighbor-changes",
3626 NO_STR
e9273987 3627 BGP_STR
1ca2fd11 3628 "Log neighbor up/down and reset reason\n")
848973c7 3629{
1ca2fd11
IR
3630 VTY_DECLVAR_CONTEXT(bgp, bgp);
3631 UNSET_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
3632 return CMD_SUCCESS;
848973c7 3633}
6b0655a2 3634
718e3744 3635/* "bgp bestpath med" configuration. */
1ca2fd11 3636DEFUN (bgp_bestpath_med,
718e3744 3637 bgp_bestpath_med_cmd,
2d8c1a4d 3638 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
e9273987 3639 BGP_STR
718e3744 3640 "Change the default bestpath selection\n"
3641 "MED attribute\n"
3642 "Compare MED among confederation paths\n"
838758ac
DW
3643 "Treat missing MED as the least preferred one\n"
3644 "Treat missing MED as the least preferred one\n"
3645 "Compare MED among confederation paths\n")
718e3744 3646{
1ca2fd11 3647 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3648
1ca2fd11 3649 int idx = 0;
d62a17ae 3650 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3651 SET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3652 idx = 0;
3653 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11 3654 SET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 3655
1ca2fd11 3656 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 3657
1ca2fd11 3658 return CMD_SUCCESS;
718e3744 3659}
3660
1ca2fd11 3661DEFUN (no_bgp_bestpath_med,
718e3744 3662 no_bgp_bestpath_med_cmd,
2d8c1a4d 3663 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3664 NO_STR
e9273987 3665 BGP_STR
718e3744 3666 "Change the default bestpath selection\n"
3667 "MED attribute\n"
3668 "Compare MED among confederation paths\n"
3a2d747c
QY
3669 "Treat missing MED as the least preferred one\n"
3670 "Treat missing MED as the least preferred one\n"
3671 "Compare MED among confederation paths\n")
718e3744 3672{
1ca2fd11 3673 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3674
1ca2fd11 3675 int idx = 0;
d62a17ae 3676 if (argv_find(argv, argc, "confed", &idx))
1ca2fd11 3677 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_CONFED);
d62a17ae 3678 idx = 0;
3679 if (argv_find(argv, argc, "missing-as-worst", &idx))
1ca2fd11
IR
3680 UNSET_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST);
3681
3682 bgp_recalculate_all_bestpaths(bgp);
718e3744 3683
1ca2fd11 3684 return CMD_SUCCESS;
718e3744 3685}
3686
f7e1c681 3687/* "bgp bestpath bandwidth" configuration. */
3688DEFPY (bgp_bestpath_bw,
3689 bgp_bestpath_bw_cmd,
ad36d216 3690 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
e9273987 3691 BGP_STR
f7e1c681 3692 "Change the default bestpath selection\n"
3693 "Link Bandwidth attribute\n"
3694 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3695 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3696 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3697{
3698 VTY_DECLVAR_CONTEXT(bgp, bgp);
3699 afi_t afi;
3700 safi_t safi;
3701
ad36d216
DS
3702 if (!bw_cfg) {
3703 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3704 return CMD_ERR_INCOMPLETE;
f7e1c681 3705 }
ad36d216
DS
3706 if (!strcmp(bw_cfg, "ignore"))
3707 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3708 else if (!strcmp(bw_cfg, "skip-missing"))
3709 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3710 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3711 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3712 else
3713 return CMD_ERR_NO_MATCH;
f7e1c681 3714
3715 /* This config is used in route install, so redo that. */
3716 FOREACH_AFI_SAFI (afi, safi) {
3717 if (!bgp_fibupd_safi(safi))
3718 continue;
3719 bgp_zebra_announce_table(bgp, afi, safi);
3720 }
3721
3722 return CMD_SUCCESS;
3723}
3724
ad36d216
DS
3725DEFPY (no_bgp_bestpath_bw,
3726 no_bgp_bestpath_bw_cmd,
3727 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3728 NO_STR
e9273987 3729 BGP_STR
ad36d216
DS
3730 "Change the default bestpath selection\n"
3731 "Link Bandwidth attribute\n"
3732 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3733 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3734 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3735{
3736 VTY_DECLVAR_CONTEXT(bgp, bgp);
3737 afi_t afi;
3738 safi_t safi;
3739
3740 bgp->lb_handling = BGP_LINK_BW_ECMP;
3741
3742 /* This config is used in route install, so redo that. */
3743 FOREACH_AFI_SAFI (afi, safi) {
3744 if (!bgp_fibupd_safi(safi))
3745 continue;
3746 bgp_zebra_announce_table(bgp, afi, safi);
3747 }
3748 return CMD_SUCCESS;
3749}
3750
b16bcbba 3751DEFPY(bgp_default_afi_safi, bgp_default_afi_safi_cmd,
38d11af5
TA
3752 "[no] bgp default <ipv4-unicast|"
3753 "ipv4-multicast|"
3754 "ipv4-vpn|"
3755 "ipv4-labeled-unicast|"
3756 "ipv4-flowspec|"
3757 "ipv6-unicast|"
3758 "ipv6-multicast|"
3759 "ipv6-vpn|"
3760 "ipv6-labeled-unicast|"
3761 "ipv6-flowspec|"
3762 "l2vpn-evpn>$afi_safi",
b16bcbba 3763 NO_STR
e9273987 3764 BGP_STR
e84c59af 3765 "Configure BGP defaults\n"
b16bcbba 3766 "Activate ipv4-unicast for a peer by default\n"
38d11af5
TA
3767 "Activate ipv4-multicast for a peer by default\n"
3768 "Activate ipv4-vpn for a peer by default\n"
3769 "Activate ipv4-labeled-unicast for a peer by default\n"
3770 "Activate ipv4-flowspec for a peer by default\n"
3771 "Activate ipv6-unicast for a peer by default\n"
3772 "Activate ipv6-multicast for a peer by default\n"
3773 "Activate ipv6-vpn for a peer by default\n"
3774 "Activate ipv6-labeled-unicast for a peer by default\n"
3775 "Activate ipv6-flowspec for a peer by default\n"
3776 "Activate l2vpn-evpn for a peer by default\n")
e84c59af
DA
3777{
3778 VTY_DECLVAR_CONTEXT(bgp, bgp);
b16bcbba
TA
3779 char afi_safi_str[strlen(afi_safi) + 1];
3780 char *afi_safi_str_tok;
e84c59af 3781
b16bcbba
TA
3782 strlcpy(afi_safi_str, afi_safi, sizeof(afi_safi_str));
3783 char *afi_str = strtok_r(afi_safi_str, "-", &afi_safi_str_tok);
3784 char *safi_str = strtok_r(NULL, "-", &afi_safi_str_tok);
3785 afi_t afi = bgp_vty_afi_from_str(afi_str);
38d11af5 3786 safi_t safi;
e84c59af 3787
38d11af5
TA
3788 if (strmatch(safi_str, "labeled"))
3789 safi = bgp_vty_safi_from_str("labeled-unicast");
3790 else
3791 safi = bgp_vty_safi_from_str(safi_str);
b16bcbba
TA
3792
3793 if (no)
3794 bgp->default_af[afi][safi] = false;
38d11af5
TA
3795 else {
3796 if ((safi == SAFI_LABELED_UNICAST
3797 && bgp->default_af[afi][SAFI_UNICAST])
3798 || (safi == SAFI_UNICAST
3799 && bgp->default_af[afi][SAFI_LABELED_UNICAST]))
3800 bgp_vty_return(vty, BGP_ERR_PEER_SAFI_CONFLICT);
3801 else
3802 bgp->default_af[afi][safi] = true;
3803 }
718e3744 3804
d62a17ae 3805 return CMD_SUCCESS;
718e3744 3806}
6b0655a2 3807
04b6bdc0 3808/* Display hostname in certain command outputs */
1ca2fd11 3809DEFUN (bgp_default_show_hostname,
04b6bdc0
DW
3810 bgp_default_show_hostname_cmd,
3811 "bgp default show-hostname",
e9273987 3812 BGP_STR
04b6bdc0 3813 "Configure BGP defaults\n"
0437e105 3814 "Show hostname in certain command outputs\n")
04b6bdc0 3815{
1ca2fd11
IR
3816 VTY_DECLVAR_CONTEXT(bgp, bgp);
3817 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3818 return CMD_SUCCESS;
ff8a8a7a
CS
3819}
3820
1ca2fd11
IR
3821DEFUN (no_bgp_default_show_hostname,
3822 no_bgp_default_show_hostname_cmd,
3823 "no bgp default show-hostname",
3824 NO_STR
e9273987 3825 BGP_STR
1ca2fd11
IR
3826 "Configure BGP defaults\n"
3827 "Show hostname in certain command outputs\n")
ff8a8a7a 3828{
1ca2fd11
IR
3829 VTY_DECLVAR_CONTEXT(bgp, bgp);
3830 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME);
3831 return CMD_SUCCESS;
04b6bdc0
DW
3832}
3833
aef999a2 3834/* Display hostname in certain command outputs */
1d80f243
IR
3835DEFUN (bgp_default_show_nexthop_hostname,
3836 bgp_default_show_nexthop_hostname_cmd,
3837 "bgp default show-nexthop-hostname",
e9273987 3838 BGP_STR
1d80f243
IR
3839 "Configure BGP defaults\n"
3840 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3841{
1ca2fd11
IR
3842 VTY_DECLVAR_CONTEXT(bgp, bgp);
3843 SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3844 return CMD_SUCCESS;
aef999a2
DA
3845}
3846
3847DEFUN (no_bgp_default_show_nexthop_hostname,
3848 no_bgp_default_show_nexthop_hostname_cmd,
3849 "no bgp default show-nexthop-hostname",
3850 NO_STR
e9273987 3851 BGP_STR
aef999a2
DA
3852 "Configure BGP defaults\n"
3853 "Show hostname for nexthop in certain command outputs\n")
3854{
1ca2fd11
IR
3855 VTY_DECLVAR_CONTEXT(bgp, bgp);
3856 UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
3857 return CMD_SUCCESS;
aef999a2
DA
3858}
3859
8233ef81 3860/* "bgp network import-check" configuration. */
1ca2fd11
IR
3861DEFUN (bgp_network_import_check,
3862 bgp_network_import_check_cmd,
3863 "bgp network import-check",
e9273987 3864 BGP_STR
1ca2fd11
IR
3865 "BGP network command\n"
3866 "Check BGP network route exists in IGP\n")
718e3744 3867{
1ca2fd11
IR
3868 VTY_DECLVAR_CONTEXT(bgp, bgp);
3869 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3870 SET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3871 bgp_static_redo_import_check(bgp);
3872 }
078430f6 3873
1ca2fd11 3874 return CMD_SUCCESS;
718e3744 3875}
3876
d62a17ae 3877ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3878 "bgp network import-check exact",
e9273987 3879 BGP_STR
d62a17ae 3880 "BGP network command\n"
3881 "Check BGP network route exists in IGP\n"
3882 "Match route precisely\n")
8233ef81 3883
1ca2fd11
IR
3884DEFUN (no_bgp_network_import_check,
3885 no_bgp_network_import_check_cmd,
3886 "no bgp network import-check",
3887 NO_STR
e9273987 3888 BGP_STR
1ca2fd11
IR
3889 "BGP network command\n"
3890 "Check BGP network route exists in IGP\n")
718e3744 3891{
1ca2fd11
IR
3892 VTY_DECLVAR_CONTEXT(bgp, bgp);
3893 if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
3894 UNSET_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK);
3895 bgp_static_redo_import_check(bgp);
3896 }
6b0655a2 3897
1ca2fd11 3898 return CMD_SUCCESS;
ff8a8a7a 3899}
718e3744 3900
1ca2fd11
IR
3901DEFUN (bgp_default_local_preference,
3902 bgp_default_local_preference_cmd,
3903 "bgp default local-preference (0-4294967295)",
e9273987 3904 BGP_STR
1ca2fd11
IR
3905 "Configure BGP defaults\n"
3906 "local preference (higher=more preferred)\n"
3907 "Configure default local preference value\n")
ff8a8a7a 3908{
1ca2fd11 3909 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3910 int idx_number = 3;
1ca2fd11 3911 uint32_t local_pref;
718e3744 3912
1ca2fd11 3913 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 3914
1ca2fd11
IR
3915 bgp_default_local_preference_set(bgp, local_pref);
3916 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 3917
1ca2fd11 3918 return CMD_SUCCESS;
718e3744 3919}
3920
1ca2fd11
IR
3921DEFUN (no_bgp_default_local_preference,
3922 no_bgp_default_local_preference_cmd,
3923 "no bgp default local-preference [(0-4294967295)]",
3924 NO_STR
e9273987 3925 BGP_STR
1ca2fd11
IR
3926 "Configure BGP defaults\n"
3927 "local preference (higher=more preferred)\n"
3928 "Configure default local preference value\n")
ff8a8a7a 3929{
1ca2fd11
IR
3930 VTY_DECLVAR_CONTEXT(bgp, bgp);
3931 bgp_default_local_preference_unset(bgp);
3932 bgp_clear_star_soft_in(vty, bgp->name);
3933
3934 return CMD_SUCCESS;
ff8a8a7a 3935}
6b0655a2 3936
ff8a8a7a 3937
1ca2fd11
IR
3938DEFUN (bgp_default_subgroup_pkt_queue_max,
3939 bgp_default_subgroup_pkt_queue_max_cmd,
3940 "bgp default subgroup-pkt-queue-max (20-100)",
e9273987 3941 BGP_STR
1ca2fd11
IR
3942 "Configure BGP defaults\n"
3943 "subgroup-pkt-queue-max\n"
3944 "Configure subgroup packet queue max\n")
8bd9d948 3945{
1ca2fd11 3946 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 3947 int idx_number = 3;
1ca2fd11 3948 uint32_t max_size;
3f9c7369 3949
1ca2fd11 3950 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 3951
1ca2fd11 3952 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
ff8a8a7a 3953
1ca2fd11 3954 return CMD_SUCCESS;
8bd9d948
DS
3955}
3956
1ca2fd11
IR
3957DEFUN (no_bgp_default_subgroup_pkt_queue_max,
3958 no_bgp_default_subgroup_pkt_queue_max_cmd,
3959 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3960 NO_STR
e9273987 3961 BGP_STR
1ca2fd11
IR
3962 "Configure BGP defaults\n"
3963 "subgroup-pkt-queue-max\n"
3964 "Configure subgroup packet queue max\n")
ff8a8a7a 3965{
1ca2fd11
IR
3966 VTY_DECLVAR_CONTEXT(bgp, bgp);
3967 bgp_default_subgroup_pkt_queue_max_unset(bgp);
3968 return CMD_SUCCESS;
ff8a8a7a 3969}
813d4307 3970
8bd9d948 3971
1ca2fd11
IR
3972DEFUN (bgp_rr_allow_outbound_policy,
3973 bgp_rr_allow_outbound_policy_cmd,
3974 "bgp route-reflector allow-outbound-policy",
e9273987 3975 BGP_STR
1ca2fd11
IR
3976 "Allow modifications made by out route-map\n"
3977 "on ibgp neighbors\n")
ff8a8a7a 3978{
1ca2fd11 3979 VTY_DECLVAR_CONTEXT(bgp, bgp);
ff8a8a7a 3980
1ca2fd11
IR
3981 if (!CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
3982 SET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3983 update_group_announce_rrclients(bgp);
3984 bgp_clear_star_soft_out(vty, bgp->name);
3985 }
8bd9d948 3986
1ca2fd11
IR
3987 return CMD_SUCCESS;
3988}
ff8a8a7a 3989
1ca2fd11
IR
3990DEFUN (no_bgp_rr_allow_outbound_policy,
3991 no_bgp_rr_allow_outbound_policy_cmd,
3992 "no bgp route-reflector allow-outbound-policy",
3993 NO_STR
e9273987 3994 BGP_STR
1ca2fd11
IR
3995 "Allow modifications made by out route-map\n"
3996 "on ibgp neighbors\n")
8bd9d948 3997{
1ca2fd11 3998 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 3999
1ca2fd11
IR
4000 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
4001 UNSET_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
4002 update_group_announce_rrclients(bgp);
4003 bgp_clear_star_soft_out(vty, bgp->name);
d62a17ae 4004 }
8bd9d948 4005
1ca2fd11 4006 return CMD_SUCCESS;
8bd9d948
DS
4007}
4008
1ca2fd11
IR
4009DEFUN (bgp_listen_limit,
4010 bgp_listen_limit_cmd,
4011 "bgp listen limit (1-65535)",
e9273987 4012 BGP_STR
1ca2fd11
IR
4013 "BGP Dynamic Neighbors listen commands\n"
4014 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4015 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4016{
1ca2fd11 4017 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4018 int idx_number = 3;
1ca2fd11
IR
4019 int listen_limit;
4020
4021 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 4022
1ca2fd11 4023 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 4024
1ca2fd11 4025 return CMD_SUCCESS;
f14e6fdb
DS
4026}
4027
1ca2fd11
IR
4028DEFUN (no_bgp_listen_limit,
4029 no_bgp_listen_limit_cmd,
4030 "no bgp listen limit [(1-65535)]",
4031 NO_STR
e9273987 4032 BGP_STR
1ca2fd11
IR
4033 "BGP Dynamic Neighbors listen commands\n"
4034 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4035 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4036{
1ca2fd11
IR
4037 VTY_DECLVAR_CONTEXT(bgp, bgp);
4038 bgp_listen_limit_unset(bgp);
4039 return CMD_SUCCESS;
f14e6fdb
DS
4040}
4041
4042
20eb8864 4043/*
4044 * Check if this listen range is already configured. Check for exact
4045 * match or overlap based on input.
4046 */
d62a17ae 4047static struct peer_group *listen_range_exists(struct bgp *bgp,
4048 struct prefix *range, int exact)
4049{
4050 struct listnode *node, *nnode;
4051 struct listnode *node1, *nnode1;
4052 struct peer_group *group;
4053 struct prefix *lr;
4054 afi_t afi;
4055 int match;
4056
4057 afi = family2afi(range->family);
4058 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4059 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4060 lr)) {
4061 if (exact)
4062 match = prefix_same(range, lr);
4063 else
4064 match = (prefix_match(range, lr)
4065 || prefix_match(lr, range));
4066 if (match)
4067 return group;
4068 }
4069 }
4070
4071 return NULL;
20eb8864 4072}
4073
f14e6fdb
DS
4074DEFUN (bgp_listen_range,
4075 bgp_listen_range_cmd,
d7b9898c 4076 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
e9273987 4077 BGP_STR
d7fa34c1
QY
4078 "Configure BGP dynamic neighbors listen range\n"
4079 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4080 NEIGHBOR_ADDR_STR
4081 "Member of the peer-group\n"
4082 "Peer-group name\n")
f14e6fdb 4083{
d62a17ae 4084 VTY_DECLVAR_CONTEXT(bgp, bgp);
4085 struct prefix range;
4086 struct peer_group *group, *existing_group;
4087 afi_t afi;
4088 int ret;
4089 int idx = 0;
4090
4091 argv_find(argv, argc, "A.B.C.D/M", &idx);
4092 argv_find(argv, argc, "X:X::X:X/M", &idx);
4093 char *prefix = argv[idx]->arg;
d7b9898c 4094 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4095 char *peergroup = argv[idx]->arg;
4096
4097 /* Convert IP prefix string to struct prefix. */
4098 ret = str2prefix(prefix, &range);
4099 if (!ret) {
4100 vty_out(vty, "%% Malformed listen range\n");
4101 return CMD_WARNING_CONFIG_FAILED;
4102 }
4103
4104 afi = family2afi(range.family);
4105
4106 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4107 vty_out(vty,
4108 "%% Malformed listen range (link-local address)\n");
4109 return CMD_WARNING_CONFIG_FAILED;
4110 }
4111
4112 apply_mask(&range);
4113
4114 /* Check if same listen range is already configured. */
4115 existing_group = listen_range_exists(bgp, &range, 1);
4116 if (existing_group) {
4117 if (strcmp(existing_group->name, peergroup) == 0)
4118 return CMD_SUCCESS;
4119 else {
4120 vty_out(vty,
4121 "%% Same listen range is attached to peer-group %s\n",
4122 existing_group->name);
4123 return CMD_WARNING_CONFIG_FAILED;
4124 }
4125 }
4126
4127 /* Check if an overlapping listen range exists. */
4128 if (listen_range_exists(bgp, &range, 0)) {
4129 vty_out(vty,
4130 "%% Listen range overlaps with existing listen range\n");
4131 return CMD_WARNING_CONFIG_FAILED;
4132 }
4133
4134 group = peer_group_lookup(bgp, peergroup);
4135 if (!group) {
4136 vty_out(vty, "%% Configure the peer-group first\n");
4137 return CMD_WARNING_CONFIG_FAILED;
4138 }
4139
4140 ret = peer_group_listen_range_add(group, &range);
4141 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4142}
4143
4144DEFUN (no_bgp_listen_range,
4145 no_bgp_listen_range_cmd,
d7b9898c 4146 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4147 NO_STR
e9273987 4148 BGP_STR
d7fa34c1
QY
4149 "Unconfigure BGP dynamic neighbors listen range\n"
4150 "Unconfigure BGP dynamic neighbors listen range\n"
4151 NEIGHBOR_ADDR_STR
4152 "Member of the peer-group\n"
4153 "Peer-group name\n")
f14e6fdb 4154{
d62a17ae 4155 VTY_DECLVAR_CONTEXT(bgp, bgp);
4156 struct prefix range;
4157 struct peer_group *group;
4158 afi_t afi;
4159 int ret;
4160 int idx = 0;
4161
4162 argv_find(argv, argc, "A.B.C.D/M", &idx);
4163 argv_find(argv, argc, "X:X::X:X/M", &idx);
4164 char *prefix = argv[idx]->arg;
21d88a71 4165 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4166 char *peergroup = argv[idx]->arg;
4167
4168 /* Convert IP prefix string to struct prefix. */
4169 ret = str2prefix(prefix, &range);
4170 if (!ret) {
4171 vty_out(vty, "%% Malformed listen range\n");
4172 return CMD_WARNING_CONFIG_FAILED;
4173 }
4174
4175 afi = family2afi(range.family);
4176
4177 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4178 vty_out(vty,
4179 "%% Malformed listen range (link-local address)\n");
4180 return CMD_WARNING_CONFIG_FAILED;
4181 }
4182
4183 apply_mask(&range);
4184
4185 group = peer_group_lookup(bgp, peergroup);
4186 if (!group) {
4187 vty_out(vty, "%% Peer-group does not exist\n");
4188 return CMD_WARNING_CONFIG_FAILED;
4189 }
4190
4191 ret = peer_group_listen_range_del(group, &range);
4192 return bgp_vty_return(vty, ret);
4193}
4194
2b791107 4195void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4196{
4197 struct peer_group *group;
4198 struct listnode *node, *nnode, *rnode, *nrnode;
4199 struct prefix *range;
4200 afi_t afi;
d62a17ae 4201
4202 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4203 vty_out(vty, " bgp listen limit %d\n",
4204 bgp->dynamic_neighbors_limit);
4205
4206 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4207 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4208 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4209 nrnode, range)) {
d62a17ae 4210 vty_out(vty,
2dbe669b
DA
4211 " bgp listen range %pFX peer-group %s\n",
4212 range, group->name);
d62a17ae 4213 }
4214 }
4215 }
f14e6fdb
DS
4216}
4217
4218
1ca2fd11
IR
4219DEFUN (bgp_disable_connected_route_check,
4220 bgp_disable_connected_route_check_cmd,
4221 "bgp disable-ebgp-connected-route-check",
e9273987 4222 BGP_STR
1ca2fd11 4223 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4224{
1ca2fd11
IR
4225 VTY_DECLVAR_CONTEXT(bgp, bgp);
4226 SET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4227 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 4228
1ca2fd11 4229 return CMD_SUCCESS;
907f92c8
DS
4230}
4231
1ca2fd11
IR
4232DEFUN (no_bgp_disable_connected_route_check,
4233 no_bgp_disable_connected_route_check_cmd,
4234 "no bgp disable-ebgp-connected-route-check",
4235 NO_STR
e9273987 4236 BGP_STR
1ca2fd11 4237 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4238{
1ca2fd11
IR
4239 VTY_DECLVAR_CONTEXT(bgp, bgp);
4240 UNSET_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
4241 bgp_clear_star_soft_in(vty, bgp->name);
d62a17ae 4242
1ca2fd11 4243 return CMD_SUCCESS;
d62a17ae 4244}
4245
4246
28c6e247
IR
4247static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
4248 const char *as_str)
4249{
4250 VTY_DECLVAR_CONTEXT(bgp, bgp);
4251 int ret;
4252 as_t as;
4253 int as_type = AS_SPECIFIED;
4254 union sockunion su;
4255
4256 if (as_str[0] == 'i') {
4257 as = 0;
4258 as_type = AS_INTERNAL;
4259 } else if (as_str[0] == 'e') {
4260 as = 0;
4261 as_type = AS_EXTERNAL;
4262 } else {
4263 /* Get AS number. */
4264 as = strtoul(as_str, NULL, 10);
4265 }
4266
4267 /* If peer is peer group or interface peer, call proper function. */
4268 ret = str2sockunion(peer_str, &su);
4269 if (ret < 0) {
4270 struct peer *peer;
4271
4272 /* Check if existing interface peer */
4273 peer = peer_lookup_by_conf_if(bgp, peer_str);
4274
4275 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
4276
4277 /* if not interface peer, check peer-group settings */
4278 if (ret < 0 && !peer) {
4279 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
4280 if (ret < 0) {
4281 vty_out(vty,
4282 "%% Create the peer-group or interface first\n");
4283 return CMD_WARNING_CONFIG_FAILED;
4284 }
4285 return CMD_SUCCESS;
4286 }
4287 } else {
4288 if (peer_address_self_check(bgp, &su)) {
4289 vty_out(vty,
4290 "%% Can not configure the local system as neighbor\n");
4291 return CMD_WARNING_CONFIG_FAILED;
4292 }
4293 ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
4294 }
4295
28c6e247
IR
4296 return bgp_vty_return(vty, ret);
4297}
4298
1ca2fd11
IR
4299DEFUN (bgp_default_shutdown,
4300 bgp_default_shutdown_cmd,
4301 "[no] bgp default shutdown",
4302 NO_STR
4303 BGP_STR
4304 "Configure BGP defaults\n"
4305 "Apply administrative shutdown to newly configured peers\n")
ff8a8a7a 4306{
1ca2fd11
IR
4307 VTY_DECLVAR_CONTEXT(bgp, bgp);
4308 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
4309 return CMD_SUCCESS;
f26845f9
QY
4310}
4311
736b68f3
DS
4312DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4313 BGP_STR
9ddf4b81 4314 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4315 "Add a shutdown message (RFC 8203)\n"
4316 "Shutdown message\n")
9cf59432 4317{
736b68f3 4318 char *msgstr = NULL;
8389c83a 4319
9cf59432
DS
4320 VTY_DECLVAR_CONTEXT(bgp, bgp);
4321
8389c83a 4322 if (argc > 3)
f80e35b6 4323 msgstr = argv_concat(argv, argc, 3);
8389c83a 4324
b776f48c
DA
4325 if (msgstr && strlen(msgstr) > BGP_ADMIN_SHUTDOWN_MSG_LEN) {
4326 vty_out(vty, "%% Shutdown message size exceeded %d\n",
4327 BGP_ADMIN_SHUTDOWN_MSG_LEN);
4328 return CMD_WARNING_CONFIG_FAILED;
4329 }
4330
8389c83a
DS
4331 bgp_shutdown_enable(bgp, msgstr);
4332 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4333
4334 return CMD_SUCCESS;
4335}
4336
736b68f3 4337DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4338 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4339{
4340 VTY_DECLVAR_CONTEXT(bgp, bgp);
4341
4342 bgp_shutdown_enable(bgp, NULL);
4343
4344 return CMD_SUCCESS;
4345}
8389c83a 4346
736b68f3 4347DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4348 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4349{
4350 VTY_DECLVAR_CONTEXT(bgp, bgp);
4351
4352 bgp_shutdown_disable(bgp);
4353
4354 return CMD_SUCCESS;
4355}
4356
9ddf4b81 4357ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4358 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4359 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4360 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4361
28c6e247
IR
4362DEFUN (neighbor_remote_as,
4363 neighbor_remote_as_cmd,
4364 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4365 NEIGHBOR_STR
4366 NEIGHBOR_ADDR_STR2
4367 "Specify a BGP neighbor\n"
4368 AS_STR
4369 "Internal BGP peer\n"
4370 "External BGP peer\n")
718e3744 4371{
d62a17ae 4372 int idx_peer = 1;
4373 int idx_remote_as = 3;
28c6e247
IR
4374 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4375 argv[idx_remote_as]->arg);
d62a17ae 4376}
f852eb98
PG
4377/* Enable fast convergence of bgp sessions. If this is enabled, bgp
4378 * sessions do not wait for hold timer expiry to bring down the sessions
4379 * when nexthop becomes unreachable
4380 */
4381DEFUN(bgp_fast_convergence, bgp_fast_convergence_cmd, "bgp fast-convergence",
4382 BGP_STR "Fast convergence for bgp sessions\n")
4383{
4384 VTY_DECLVAR_CONTEXT(bgp, bgp);
4385 bgp->fast_convergence = true;
4386
4387 return CMD_SUCCESS;
4388}
4389
4390DEFUN(no_bgp_fast_convergence, no_bgp_fast_convergence_cmd,
4391 "no bgp fast-convergence",
4392 NO_STR BGP_STR "Fast convergence for bgp sessions\n")
4393{
4394 VTY_DECLVAR_CONTEXT(bgp, bgp);
4395 bgp->fast_convergence = false;
4396
4397 return CMD_SUCCESS;
4398}
d62a17ae 4399
28c6e247
IR
4400static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4401 int v6only,
4402 const char *peer_group_name,
4403 const char *as_str)
d62a17ae 4404{
28c6e247
IR
4405 VTY_DECLVAR_CONTEXT(bgp, bgp);
4406 as_t as = 0;
4407 int as_type = AS_UNSPECIFIED;
d62a17ae 4408 struct peer *peer;
4409 struct peer_group *group;
4410 int ret = 0;
d62a17ae 4411
4412 group = peer_group_lookup(bgp, conf_if);
4413
4414 if (group) {
28c6e247
IR
4415 vty_out(vty, "%% Name conflict with peer-group \n");
4416 return CMD_WARNING_CONFIG_FAILED;
4417 }
4418
4419 if (as_str) {
4420 if (as_str[0] == 'i') {
4421 as_type = AS_INTERNAL;
4422 } else if (as_str[0] == 'e') {
4423 as_type = AS_EXTERNAL;
4424 } else {
4425 /* Get AS number. */
4426 as = strtoul(as_str, NULL, 10);
4427 as_type = AS_SPECIFIED;
4428 }
d62a17ae 4429 }
4430
4431 peer = peer_lookup_by_conf_if(bgp, conf_if);
4432 if (peer) {
28c6e247 4433 if (as_str)
e84c59af 4434 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4435 } else {
e84c59af
DA
4436 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4437 NULL);
d62a17ae 4438
4439 if (!peer) {
28c6e247
IR
4440 vty_out(vty, "%% BGP failed to create peer\n");
4441 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4442 }
4443
4444 if (v6only)
527de3dc 4445 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4446
4447 /* Request zebra to initiate IPv6 RAs on this interface. We do
4448 * this
4449 * any unnumbered peer in order to not worry about run-time
4450 * transitions
4451 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4452 * address
4453 * gets deleted later etc.)
4454 */
4455 if (peer->ifp)
4456 bgp_zebra_initiate_radv(bgp, peer);
4457 }
4458
4459 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4460 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4461 if (v6only)
527de3dc 4462 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4463 else
527de3dc 4464 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4465
4466 /* v6only flag changed. Reset bgp seesion */
4467 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4468 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4469 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4470 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4471 } else
4472 bgp_session_reset(peer);
4473 }
4474
9fb964de
PM
4475 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4476 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4477 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4478 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4479 }
d62a17ae 4480
4481 if (peer_group_name) {
4482 group = peer_group_lookup(bgp, peer_group_name);
4483 if (!group) {
28c6e247
IR
4484 vty_out(vty, "%% Configure the peer-group first\n");
4485 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4486 }
4487
8395c1f8 4488 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4489 }
4490
28c6e247 4491 return bgp_vty_return(vty, ret);
a80beece
DS
4492}
4493
28c6e247
IR
4494DEFUN (neighbor_interface_config,
4495 neighbor_interface_config_cmd,
4496 "neighbor WORD interface [peer-group PGNAME]",
4497 NEIGHBOR_STR
4498 "Interface name or neighbor tag\n"
4499 "Enable BGP on interface\n"
4500 "Member of the peer-group\n"
4501 "Peer-group name\n")
4c48cf63 4502{
d62a17ae 4503 int idx_word = 1;
4504 int idx_peer_group_word = 4;
f4b8ec07 4505
d62a17ae 4506 if (argc > idx_peer_group_word)
28c6e247
IR
4507 return peer_conf_interface_get(
4508 vty, argv[idx_word]->arg, 0,
4509 argv[idx_peer_group_word]->arg, NULL);
4510 else
4511 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0,
4512 NULL, NULL);
4c48cf63
DW
4513}
4514
28c6e247
IR
4515DEFUN (neighbor_interface_config_v6only,
4516 neighbor_interface_config_v6only_cmd,
4517 "neighbor WORD interface v6only [peer-group PGNAME]",
4518 NEIGHBOR_STR
4519 "Interface name or neighbor tag\n"
4520 "Enable BGP on interface\n"
4521 "Enable BGP with v6 link-local only\n"
4522 "Member of the peer-group\n"
4523 "Peer-group name\n")
4c48cf63 4524{
d62a17ae 4525 int idx_word = 1;
4526 int idx_peer_group_word = 5;
31500417 4527
d62a17ae 4528 if (argc > idx_peer_group_word)
28c6e247
IR
4529 return peer_conf_interface_get(
4530 vty, argv[idx_word]->arg, 1,
4531 argv[idx_peer_group_word]->arg, NULL);
31500417 4532
28c6e247 4533 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL, NULL);
4c48cf63
DW
4534}
4535
a80beece 4536
28c6e247
IR
4537DEFUN (neighbor_interface_config_remote_as,
4538 neighbor_interface_config_remote_as_cmd,
4539 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4540 NEIGHBOR_STR
4541 "Interface name or neighbor tag\n"
4542 "Enable BGP on interface\n"
4543 "Specify a BGP neighbor\n"
4544 AS_STR
4545 "Internal BGP peer\n"
4546 "External BGP peer\n")
b3a39dc5 4547{
d62a17ae 4548 int idx_word = 1;
4549 int idx_remote_as = 4;
28c6e247
IR
4550 return peer_conf_interface_get(vty, argv[idx_word]->arg, 0, NULL,
4551 argv[idx_remote_as]->arg);
b3a39dc5
DD
4552}
4553
28c6e247
IR
4554DEFUN (neighbor_interface_v6only_config_remote_as,
4555 neighbor_interface_v6only_config_remote_as_cmd,
4556 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4557 NEIGHBOR_STR
4558 "Interface name or neighbor tag\n"
4559 "Enable BGP with v6 link-local only\n"
4560 "Enable BGP on interface\n"
4561 "Specify a BGP neighbor\n"
4562 AS_STR
4563 "Internal BGP peer\n"
4564 "External BGP peer\n")
b3a39dc5 4565{
d62a17ae 4566 int idx_word = 1;
4567 int idx_remote_as = 5;
28c6e247
IR
4568 return peer_conf_interface_get(vty, argv[idx_word]->arg, 1, NULL,
4569 argv[idx_remote_as]->arg);
b3a39dc5
DD
4570}
4571
28c6e247
IR
4572DEFUN (neighbor_peer_group,
4573 neighbor_peer_group_cmd,
4574 "neighbor WORD peer-group",
4575 NEIGHBOR_STR
4576 "Interface name or neighbor tag\n"
4577 "Configure peer-group\n")
718e3744 4578{
28c6e247 4579 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4580 int idx_word = 1;
28c6e247
IR
4581 struct peer *peer;
4582 struct peer_group *group;
718e3744 4583
28c6e247
IR
4584 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4585 if (peer) {
4586 vty_out(vty, "%% Name conflict with interface: \n");
4587 return CMD_WARNING_CONFIG_FAILED;
4588 }
718e3744 4589
28c6e247
IR
4590 group = peer_group_get(bgp, argv[idx_word]->arg);
4591 if (!group) {
4592 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4593 return CMD_WARNING_CONFIG_FAILED;
4594 }
718e3744 4595
28c6e247 4596 return CMD_SUCCESS;
718e3744 4597}
4598
1d80f243
IR
4599DEFUN (no_neighbor,
4600 no_neighbor_cmd,
4601 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4602 NO_STR
4603 NEIGHBOR_STR
4604 NEIGHBOR_ADDR_STR2
4605 "Specify a BGP neighbor\n"
4606 AS_STR
4607 "Internal BGP peer\n"
4608 "External BGP peer\n")
718e3744 4609{
28c6e247 4610 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4611 int idx_peer = 2;
28c6e247 4612 int ret;
d62a17ae 4613 union sockunion su;
28c6e247
IR
4614 struct peer_group *group;
4615 struct peer *peer;
4616 struct peer *other;
d62a17ae 4617
28c6e247
IR
4618 ret = str2sockunion(argv[idx_peer]->arg, &su);
4619 if (ret < 0) {
4620 /* look up for neighbor by interface name config. */
4621 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4622 if (peer) {
4623 /* Request zebra to terminate IPv6 RAs on this
4624 * interface. */
4625 if (peer->ifp)
4626 bgp_zebra_terminate_radv(peer->bgp, peer);
4627 peer_notify_unconfig(peer);
4628 peer_delete(peer);
4629 return CMD_SUCCESS;
d62a17ae 4630 }
28c6e247
IR
4631
4632 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4633 if (group) {
4634 peer_group_notify_unconfig(group);
4635 peer_group_delete(group);
4e2786df 4636 } else {
28c6e247 4637 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4638 return CMD_WARNING_CONFIG_FAILED;
4639 }
28c6e247
IR
4640 } else {
4641 peer = peer_lookup(bgp, &su);
4642 if (peer) {
4643 if (peer_dynamic_neighbor(peer)) {
4644 vty_out(vty,
4645 "%% Operation not allowed on a dynamic neighbor\n");
4646 return CMD_WARNING_CONFIG_FAILED;
4647 }
d62a17ae 4648
28c6e247 4649 other = peer->doppelganger;
f4b8ec07 4650
28c6e247
IR
4651 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4652 bgp_zebra_terminate_radv(peer->bgp, peer);
f4b8ec07 4653
28c6e247
IR
4654 peer_notify_unconfig(peer);
4655 peer_delete(peer);
4656 if (other && other->status != Deleted) {
4657 peer_notify_unconfig(other);
4658 peer_delete(other);
4659 }
4660 }
4661 }
4662
4663 return CMD_SUCCESS;
a80beece
DS
4664}
4665
28c6e247
IR
4666DEFUN (no_neighbor_interface_config,
4667 no_neighbor_interface_config_cmd,
4668 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4669 NO_STR
4670 NEIGHBOR_STR
4671 "Interface name\n"
4672 "Configure BGP on interface\n"
4673 "Enable BGP with v6 link-local only\n"
4674 "Member of the peer-group\n"
4675 "Peer-group name\n"
4676 "Specify a BGP neighbor\n"
4677 AS_STR
4678 "Internal BGP peer\n"
4679 "External BGP peer\n")
718e3744 4680{
28c6e247 4681 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4682 int idx_word = 2;
28c6e247 4683 struct peer *peer;
718e3744 4684
28c6e247
IR
4685 /* look up for neighbor by interface name config. */
4686 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4687 if (peer) {
4688 /* Request zebra to terminate IPv6 RAs on this interface. */
4689 if (peer->ifp)
4690 bgp_zebra_terminate_radv(peer->bgp, peer);
4691 peer_notify_unconfig(peer);
4692 peer_delete(peer);
4693 } else {
4694 vty_out(vty, "%% Create the bgp interface first\n");
4695 return CMD_WARNING_CONFIG_FAILED;
4696 }
4697 return CMD_SUCCESS;
718e3744 4698}
4699
28c6e247
IR
4700DEFUN (no_neighbor_peer_group,
4701 no_neighbor_peer_group_cmd,
4702 "no neighbor WORD peer-group",
4703 NO_STR
4704 NEIGHBOR_STR
4705 "Neighbor tag\n"
4706 "Configure peer-group\n")
718e3744 4707{
28c6e247
IR
4708 VTY_DECLVAR_CONTEXT(bgp, bgp);
4709 int idx_word = 2;
4710 struct peer_group *group;
f4b8ec07 4711
28c6e247
IR
4712 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4713 if (group) {
4714 peer_group_notify_unconfig(group);
4715 peer_group_delete(group);
f4b8ec07 4716 } else {
28c6e247 4717 vty_out(vty, "%% Create the peer-group first\n");
d62a17ae 4718 return CMD_WARNING_CONFIG_FAILED;
4719 }
28c6e247
IR
4720 return CMD_SUCCESS;
4721}
f4b8ec07 4722
28c6e247
IR
4723DEFUN (no_neighbor_interface_peer_group_remote_as,
4724 no_neighbor_interface_peer_group_remote_as_cmd,
4725 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4726 NO_STR
4727 NEIGHBOR_STR
4728 "Interface name or neighbor tag\n"
4729 "Specify a BGP neighbor\n"
4730 AS_STR
4731 "Internal BGP peer\n"
4732 "External BGP peer\n")
4733{
4734 VTY_DECLVAR_CONTEXT(bgp, bgp);
4735 int idx_word = 2;
4736 struct peer_group *group;
4737 struct peer *peer;
f4b8ec07 4738
28c6e247
IR
4739 /* look up for neighbor by interface name config. */
4740 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4741 if (peer) {
4742 peer_as_change(peer, 0, AS_UNSPECIFIED);
4743 return CMD_SUCCESS;
4744 }
f4b8ec07 4745
28c6e247
IR
4746 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4747 if (group)
4748 peer_group_remote_as_delete(group);
4749 else {
4750 vty_out(vty, "%% Create the peer-group or interface first\n");
4751 return CMD_WARNING_CONFIG_FAILED;
4752 }
4753 return CMD_SUCCESS;
718e3744 4754}
6b0655a2 4755
28c6e247
IR
4756DEFUN (neighbor_local_as,
4757 neighbor_local_as_cmd,
4758 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4759 NEIGHBOR_STR
4760 NEIGHBOR_ADDR_STR2
4761 "Specify a local-as number\n"
4762 "AS number used as local AS\n")
718e3744 4763{
d62a17ae 4764 int idx_peer = 1;
4765 int idx_number = 3;
28c6e247
IR
4766 struct peer *peer;
4767 int ret;
4768 as_t as;
718e3744 4769
28c6e247
IR
4770 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4771 if (!peer)
d62a17ae 4772 return CMD_WARNING_CONFIG_FAILED;
718e3744 4773
28c6e247
IR
4774 as = strtoul(argv[idx_number]->arg, NULL, 10);
4775 ret = peer_local_as_set(peer, as, 0, 0);
4776 return bgp_vty_return(vty, ret);
718e3744 4777}
4778
28c6e247
IR
4779DEFUN (neighbor_local_as_no_prepend,
4780 neighbor_local_as_no_prepend_cmd,
4781 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4782 NEIGHBOR_STR
4783 NEIGHBOR_ADDR_STR2
4784 "Specify a local-as number\n"
4785 "AS number used as local AS\n"
4786 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4787{
d62a17ae 4788 int idx_peer = 1;
4789 int idx_number = 3;
28c6e247
IR
4790 struct peer *peer;
4791 int ret;
4792 as_t as;
718e3744 4793
28c6e247
IR
4794 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4795 if (!peer)
d62a17ae 4796 return CMD_WARNING_CONFIG_FAILED;
718e3744 4797
28c6e247
IR
4798 as = strtoul(argv[idx_number]->arg, NULL, 10);
4799 ret = peer_local_as_set(peer, as, 1, 0);
4800 return bgp_vty_return(vty, ret);
718e3744 4801}
4802
28c6e247
IR
4803DEFUN (neighbor_local_as_no_prepend_replace_as,
4804 neighbor_local_as_no_prepend_replace_as_cmd,
4805 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Specify a local-as number\n"
4809 "AS number used as local AS\n"
4810 "Do not prepend local-as to updates from ebgp peers\n"
4811 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4812{
d62a17ae 4813 int idx_peer = 1;
4814 int idx_number = 3;
28c6e247
IR
4815 struct peer *peer;
4816 int ret;
4817 as_t as;
9d3f9705 4818
28c6e247
IR
4819 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4820 if (!peer)
d62a17ae 4821 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4822
28c6e247
IR
4823 as = strtoul(argv[idx_number]->arg, NULL, 10);
4824 ret = peer_local_as_set(peer, as, 1, 1);
4825 return bgp_vty_return(vty, ret);
9d3f9705
AC
4826}
4827
28c6e247
IR
4828DEFUN (no_neighbor_local_as,
4829 no_neighbor_local_as_cmd,
4830 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4831 NO_STR
4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Specify a local-as number\n"
4835 "AS number used as local AS\n"
4836 "Do not prepend local-as to updates from ebgp peers\n"
4837 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4838{
d62a17ae 4839 int idx_peer = 2;
28c6e247
IR
4840 struct peer *peer;
4841 int ret;
718e3744 4842
28c6e247
IR
4843 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4844 if (!peer)
d62a17ae 4845 return CMD_WARNING_CONFIG_FAILED;
718e3744 4846
28c6e247
IR
4847 ret = peer_local_as_unset(peer);
4848 return bgp_vty_return(vty, ret);
718e3744 4849}
4850
718e3744 4851
3f9c7369
DS
4852DEFUN (neighbor_solo,
4853 neighbor_solo_cmd,
9ccf14f7 4854 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Solo peer - part of its own update group\n")
4858{
d62a17ae 4859 int idx_peer = 1;
4860 struct peer *peer;
4861 int ret;
3f9c7369 4862
d62a17ae 4863 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4864 if (!peer)
4865 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4866
d62a17ae 4867 ret = update_group_adjust_soloness(peer, 1);
4868 return bgp_vty_return(vty, ret);
3f9c7369
DS
4869}
4870
4871DEFUN (no_neighbor_solo,
4872 no_neighbor_solo_cmd,
9ccf14f7 4873 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4874 NO_STR
4875 NEIGHBOR_STR
4876 NEIGHBOR_ADDR_STR2
4877 "Solo peer - part of its own update group\n")
4878{
d62a17ae 4879 int idx_peer = 2;
4880 struct peer *peer;
4881 int ret;
3f9c7369 4882
d62a17ae 4883 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4884 if (!peer)
4885 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4886
d62a17ae 4887 ret = update_group_adjust_soloness(peer, 0);
4888 return bgp_vty_return(vty, ret);
3f9c7369
DS
4889}
4890
28c6e247
IR
4891DEFUN (neighbor_password,
4892 neighbor_password_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Set a password\n"
4897 "The password\n")
0df7c91f 4898{
d62a17ae 4899 int idx_peer = 1;
4900 int idx_line = 3;
28c6e247
IR
4901 struct peer *peer;
4902 int ret;
0df7c91f 4903
28c6e247
IR
4904 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4905 if (!peer)
d62a17ae 4906 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4907
28c6e247
IR
4908 ret = peer_password_set(peer, argv[idx_line]->arg);
4909 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4910}
4911
28c6e247
IR
4912DEFUN (no_neighbor_password,
4913 no_neighbor_password_cmd,
4914 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4915 NO_STR
4916 NEIGHBOR_STR
4917 NEIGHBOR_ADDR_STR2
4918 "Set a password\n"
4919 "The password\n")
0df7c91f 4920{
d62a17ae 4921 int idx_peer = 2;
28c6e247
IR
4922 struct peer *peer;
4923 int ret;
0df7c91f 4924
28c6e247
IR
4925 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4926 if (!peer)
d62a17ae 4927 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4928
28c6e247
IR
4929 ret = peer_password_unset(peer);
4930 return bgp_vty_return(vty, ret);
0df7c91f 4931}
6b0655a2 4932
28c6e247
IR
4933DEFUN (neighbor_activate,
4934 neighbor_activate_cmd,
4935 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
4938 "Enable the Address Family for this Neighbor\n")
718e3744 4939{
d62a17ae 4940 int idx_peer = 1;
28c6e247
IR
4941 int ret;
4942 struct peer *peer;
56ceae84 4943
28c6e247
IR
4944 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4945 if (!peer)
d62a17ae 4946 return CMD_WARNING_CONFIG_FAILED;
718e3744 4947
28c6e247
IR
4948 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4949 return bgp_vty_return(vty, ret);
718e3744 4950}
4951
d62a17ae 4952ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4953 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4954 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4955 "Enable the Address Family for this Neighbor\n")
596c17ba 4956
28c6e247
IR
4957DEFUN (no_neighbor_activate,
4958 no_neighbor_activate_cmd,
4959 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4960 NO_STR
4961 NEIGHBOR_STR
4962 NEIGHBOR_ADDR_STR2
4963 "Enable the Address Family for this Neighbor\n")
718e3744 4964{
d62a17ae 4965 int idx_peer = 2;
28c6e247
IR
4966 int ret;
4967 struct peer *peer;
f4b8ec07 4968
28c6e247
IR
4969 /* Lookup peer. */
4970 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4971 if (!peer)
d62a17ae 4972 return CMD_WARNING_CONFIG_FAILED;
718e3744 4973
28c6e247
IR
4974 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4975 return bgp_vty_return(vty, ret);
718e3744 4976}
6b0655a2 4977
d62a17ae 4978ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4981 "Enable the Address Family for this Neighbor\n")
596c17ba 4982
28c6e247
IR
4983DEFUN (neighbor_set_peer_group,
4984 neighbor_set_peer_group_cmd,
4985 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4986 NEIGHBOR_STR
4987 NEIGHBOR_ADDR_STR2
4988 "Member of the peer-group\n"
4989 "Peer-group name\n")
718e3744 4990{
28c6e247 4991 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 4992 int idx_peer = 1;
4993 int idx_word = 3;
28c6e247
IR
4994 int ret;
4995 as_t as;
4996 union sockunion su;
4997 struct peer *peer;
4998 struct peer_group *group;
4999
5000 ret = str2sockunion(argv[idx_peer]->arg, &su);
5001 if (ret < 0) {
5002 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5003 if (!peer) {
5004 vty_out(vty, "%% Malformed address or name: %s\n",
5005 argv[idx_peer]->arg);
5006 return CMD_WARNING_CONFIG_FAILED;
5007 }
5008 } else {
5009 if (peer_address_self_check(bgp, &su)) {
5010 vty_out(vty,
5011 "%% Can not configure the local system as neighbor\n");
5012 return CMD_WARNING_CONFIG_FAILED;
5013 }
2a059a54 5014
28c6e247
IR
5015 /* Disallow for dynamic neighbor. */
5016 peer = peer_lookup(bgp, &su);
5017 if (peer && peer_dynamic_neighbor(peer)) {
5018 vty_out(vty,
5019 "%% Operation not allowed on a dynamic neighbor\n");
5020 return CMD_WARNING_CONFIG_FAILED;
5021 }
5022 }
5023
5024 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5025 if (!group) {
5026 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5027 return CMD_WARNING_CONFIG_FAILED;
28c6e247 5028 }
d62a17ae 5029
28c6e247 5030 ret = peer_group_bind(bgp, &su, peer, group, &as);
2a059a54 5031
28c6e247 5032 return bgp_vty_return(vty, ret);
d62a17ae 5033}
5034
5035ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5036 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5037 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5038 "Member of the peer-group\n"
5039 "Peer-group name\n")
596c17ba 5040
28c6e247
IR
5041DEFUN (no_neighbor_set_peer_group,
5042 no_neighbor_set_peer_group_cmd,
5043 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5044 NO_STR
5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR2
5047 "Member of the peer-group\n"
5048 "Peer-group name\n")
718e3744 5049{
28c6e247 5050 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5051 int idx_peer = 2;
28c6e247
IR
5052 int idx_word = 4;
5053 int ret;
5054 struct peer *peer;
5055 struct peer_group *group;
d62a17ae 5056
28c6e247
IR
5057 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
5058 if (!peer)
d62a17ae 5059 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5060
28c6e247
IR
5061 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5062 if (!group) {
5063 vty_out(vty, "%% Configure the peer-group first\n");
5064 return CMD_WARNING_CONFIG_FAILED;
5065 }
718e3744 5066
28c6e247
IR
5067 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
5068 bgp_zebra_terminate_radv(peer->bgp, peer);
5069
5070 peer_notify_unconfig(peer);
5071 ret = peer_delete(peer);
5072
5073 return bgp_vty_return(vty, ret);
718e3744 5074}
6b0655a2 5075
d62a17ae 5076ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5077 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5078 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5079 "Member of the peer-group\n"
5080 "Peer-group name\n")
596c17ba 5081
d62a17ae 5082static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5083 uint32_t flag, int set)
718e3744 5084{
d62a17ae 5085 int ret;
5086 struct peer *peer;
718e3744 5087
d62a17ae 5088 peer = peer_and_group_lookup_vty(vty, ip_str);
5089 if (!peer)
5090 return CMD_WARNING_CONFIG_FAILED;
718e3744 5091
7ebe625c
QY
5092 /*
5093 * If 'neighbor <interface>', then this is for directly connected peers,
5094 * we should not accept disable-connected-check.
5095 */
5096 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5097 vty_out(vty,
3efd0893 5098 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5099 ip_str);
5100 return CMD_WARNING_CONFIG_FAILED;
5101 }
5102
d62a17ae 5103 if (!set && flag == PEER_FLAG_SHUTDOWN)
5104 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5105
d62a17ae 5106 if (set)
5107 ret = peer_flag_set(peer, flag);
5108 else
5109 ret = peer_flag_unset(peer, flag);
718e3744 5110
d62a17ae 5111 return bgp_vty_return(vty, ret);
718e3744 5112}
5113
47cbc09b 5114static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5115{
d62a17ae 5116 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5117}
5118
d62a17ae 5119static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5120 uint32_t flag)
718e3744 5121{
d62a17ae 5122 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5123}
5124
5125/* neighbor passive. */
28c6e247
IR
5126DEFUN (neighbor_passive,
5127 neighbor_passive_cmd,
5128 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5129 NEIGHBOR_STR
5130 NEIGHBOR_ADDR_STR2
5131 "Don't send open messages to this neighbor\n")
718e3744 5132{
d62a17ae 5133 int idx_peer = 1;
28c6e247 5134 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5135}
5136
28c6e247
IR
5137DEFUN (no_neighbor_passive,
5138 no_neighbor_passive_cmd,
5139 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5140 NO_STR
5141 NEIGHBOR_STR
5142 NEIGHBOR_ADDR_STR2
5143 "Don't send open messages to this neighbor\n")
718e3744 5144{
d62a17ae 5145 int idx_peer = 2;
28c6e247 5146 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 5147}
6b0655a2 5148
718e3744 5149/* neighbor shutdown. */
28c6e247
IR
5150DEFUN (neighbor_shutdown_msg,
5151 neighbor_shutdown_msg_cmd,
5152 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "Administratively shut down this neighbor\n"
5156 "Add a shutdown message (RFC 8203)\n"
5157 "Shutdown message\n")
718e3744 5158{
d62a17ae 5159 int idx_peer = 1;
73d70fa6 5160
d62a17ae 5161 if (argc >= 5) {
28c6e247
IR
5162 struct peer *peer =
5163 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
d62a17ae 5164 char *message;
73d70fa6 5165
28c6e247
IR
5166 if (!peer)
5167 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5168 message = argv_concat(argv, argc, 4);
28c6e247
IR
5169 peer_tx_shutdown_message_set(peer, message);
5170 XFREE(MTYPE_TMP, message);
d62a17ae 5171 }
73d70fa6 5172
28c6e247 5173 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 5174}
5175
1d80f243 5176ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5177 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5179 "Administratively shut down this neighbor\n")
73d70fa6 5180
28c6e247
IR
5181DEFUN (no_neighbor_shutdown_msg,
5182 no_neighbor_shutdown_msg_cmd,
5183 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5184 NO_STR
5185 NEIGHBOR_STR
5186 NEIGHBOR_ADDR_STR2
5187 "Administratively shut down this neighbor\n"
5188 "Remove a shutdown message (RFC 8203)\n"
5189 "Shutdown message\n")
718e3744 5190{
d62a17ae 5191 int idx_peer = 2;
73d70fa6 5192
28c6e247
IR
5193 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5194 PEER_FLAG_SHUTDOWN);
718e3744 5195}
6b0655a2 5196
1d80f243 5197ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5198 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5199 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5200 "Administratively shut down this neighbor\n")
73d70fa6 5201
8336c896
DA
5202DEFUN(neighbor_shutdown_rtt,
5203 neighbor_shutdown_rtt_cmd,
5204 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5205 NEIGHBOR_STR
5206 NEIGHBOR_ADDR_STR2
5207 "Administratively shut down this neighbor\n"
5208 "Shutdown if round-trip-time is higher than expected\n"
5209 "Round-trip-time in milliseconds\n"
5210 "Specify the number of keepalives before shutdown\n"
5211 "The number of keepalives with higher RTT to shutdown\n")
5212{
5213 int idx_peer = 1;
5214 int idx_rtt = 4;
5215 int idx_count = 0;
5216 struct peer *peer;
5217
5218 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5219
5220 if (!peer)
5221 return CMD_WARNING_CONFIG_FAILED;
5222
5223 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5224
5225 if (argv_find(argv, argc, "count", &idx_count))
5226 peer->rtt_keepalive_conf =
5227 strtol(argv[idx_count + 1]->arg, NULL, 10);
5228
5229 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5230 PEER_FLAG_RTT_SHUTDOWN);
5231}
5232
5233DEFUN(no_neighbor_shutdown_rtt,
5234 no_neighbor_shutdown_rtt_cmd,
5235 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5236 NO_STR
5237 NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "Administratively shut down this neighbor\n"
5240 "Shutdown if round-trip-time is higher than expected\n"
5241 "Round-trip-time in milliseconds\n"
5242 "Specify the number of keepalives before shutdown\n"
5243 "The number of keepalives with higher RTT to shutdown\n")
5244{
5245 int idx_peer = 2;
5246 struct peer *peer;
5247
5248 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5249
5250 if (!peer)
5251 return CMD_WARNING_CONFIG_FAILED;
5252
5253 peer->rtt_expected = 0;
5254 peer->rtt_keepalive_conf = 1;
5255
5256 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5257 PEER_FLAG_RTT_SHUTDOWN);
5258}
5259
718e3744 5260/* neighbor capability dynamic. */
28c6e247
IR
5261DEFUN (neighbor_capability_dynamic,
5262 neighbor_capability_dynamic_cmd,
5263 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5264 NEIGHBOR_STR
5265 NEIGHBOR_ADDR_STR2
5266 "Advertise capability to the peer\n"
5267 "Advertise dynamic capability to this neighbor\n")
718e3744 5268{
d62a17ae 5269 int idx_peer = 1;
28c6e247
IR
5270 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5271 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5272}
5273
28c6e247
IR
5274DEFUN (no_neighbor_capability_dynamic,
5275 no_neighbor_capability_dynamic_cmd,
5276 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5277 NO_STR
5278 NEIGHBOR_STR
5279 NEIGHBOR_ADDR_STR2
5280 "Advertise capability to the peer\n"
5281 "Advertise dynamic capability to this neighbor\n")
718e3744 5282{
d62a17ae 5283 int idx_peer = 2;
28c6e247
IR
5284 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5285 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 5286}
6b0655a2 5287
718e3744 5288/* neighbor dont-capability-negotiate */
5289DEFUN (neighbor_dont_capability_negotiate,
5290 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5291 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5292 NEIGHBOR_STR
5293 NEIGHBOR_ADDR_STR2
5294 "Do not perform capability negotiation\n")
5295{
d62a17ae 5296 int idx_peer = 1;
5297 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5298 PEER_FLAG_DONT_CAPABILITY);
718e3744 5299}
5300
5301DEFUN (no_neighbor_dont_capability_negotiate,
5302 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5303 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5304 NO_STR
5305 NEIGHBOR_STR
5306 NEIGHBOR_ADDR_STR2
5307 "Do not perform capability negotiation\n")
5308{
28c6e247
IR
5309 int idx_peer = 2;
5310 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5311 PEER_FLAG_DONT_CAPABILITY);
f4b8ec07
CS
5312}
5313
28c6e247
IR
5314/* neighbor capability extended next hop encoding */
5315DEFUN (neighbor_capability_enhe,
5316 neighbor_capability_enhe_cmd,
5317 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5318 NEIGHBOR_STR
5319 NEIGHBOR_ADDR_STR2
5320 "Advertise capability to the peer\n"
5321 "Advertise extended next-hop capability to the peer\n")
f4b8ec07 5322{
28c6e247 5323 int idx_peer = 1;
c4786405
DS
5324 struct peer *peer;
5325
5326 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5327 if (peer && peer->conf_if)
5328 return CMD_SUCCESS;
5329
28c6e247
IR
5330 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5331 PEER_FLAG_CAPABILITY_ENHE);
5332}
f4b8ec07 5333
28c6e247
IR
5334DEFUN (no_neighbor_capability_enhe,
5335 no_neighbor_capability_enhe_cmd,
5336 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5337 NO_STR
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Advertise capability to the peer\n"
5341 "Advertise extended next-hop capability to the peer\n")
5342{
5343 int idx_peer = 2;
c4786405
DS
5344 struct peer *peer;
5345
5346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5347 if (peer && peer->conf_if) {
5348 vty_out(vty,
5349 "Peer %s cannot have capability extended-nexthop turned off\n",
5350 argv[idx_peer]->arg);
5351 return CMD_WARNING_CONFIG_FAILED;
5352 }
5353
28c6e247
IR
5354 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5355 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5356}
5357
d62a17ae 5358static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5359 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5360 int set)
718e3744 5361{
d62a17ae 5362 int ret;
5363 struct peer *peer;
718e3744 5364
d62a17ae 5365 peer = peer_and_group_lookup_vty(vty, peer_str);
5366 if (!peer)
5367 return CMD_WARNING_CONFIG_FAILED;
718e3744 5368
d62a17ae 5369 if (set)
5370 ret = peer_af_flag_set(peer, afi, safi, flag);
5371 else
5372 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5373
d62a17ae 5374 return bgp_vty_return(vty, ret);
718e3744 5375}
5376
d62a17ae 5377static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5378 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5379{
d62a17ae 5380 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5381}
5382
d62a17ae 5383static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5384 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5385{
d62a17ae 5386 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5387}
6b0655a2 5388
718e3744 5389/* neighbor capability orf prefix-list. */
5390DEFUN (neighbor_capability_orf_prefix,
5391 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5392 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5393 NEIGHBOR_STR
5394 NEIGHBOR_ADDR_STR2
5395 "Advertise capability to the peer\n"
5396 "Advertise ORF capability to the peer\n"
5397 "Advertise prefixlist ORF capability to this neighbor\n"
5398 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5399 "Capability to RECEIVE the ORF from this neighbor\n"
5400 "Capability to SEND the ORF to this neighbor\n")
5401{
d62a17ae 5402 int idx_send_recv = 5;
db45f64d
DS
5403 char *peer_str = argv[1]->arg;
5404 struct peer *peer;
5405 afi_t afi = bgp_node_afi(vty);
5406 safi_t safi = bgp_node_safi(vty);
d62a17ae 5407
db45f64d
DS
5408 peer = peer_and_group_lookup_vty(vty, peer_str);
5409 if (!peer)
d62a17ae 5410 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5411
db45f64d
DS
5412 if (strmatch(argv[idx_send_recv]->text, "send"))
5413 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5414 PEER_FLAG_ORF_PREFIX_SM);
5415
5416 if (strmatch(argv[idx_send_recv]->text, "receive"))
5417 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5418 PEER_FLAG_ORF_PREFIX_RM);
5419
5420 if (strmatch(argv[idx_send_recv]->text, "both"))
5421 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5422 PEER_FLAG_ORF_PREFIX_SM)
5423 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5424 PEER_FLAG_ORF_PREFIX_RM);
5425
5426 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5427}
5428
5429ALIAS_HIDDEN(
5430 neighbor_capability_orf_prefix,
5431 neighbor_capability_orf_prefix_hidden_cmd,
5432 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5434 "Advertise capability to the peer\n"
5435 "Advertise ORF capability to the peer\n"
5436 "Advertise prefixlist ORF capability to this neighbor\n"
5437 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5438 "Capability to RECEIVE the ORF from this neighbor\n"
5439 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5440
718e3744 5441DEFUN (no_neighbor_capability_orf_prefix,
5442 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5443 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5444 NO_STR
5445 NEIGHBOR_STR
5446 NEIGHBOR_ADDR_STR2
5447 "Advertise capability to the peer\n"
5448 "Advertise ORF capability to the peer\n"
5449 "Advertise prefixlist ORF capability to this neighbor\n"
5450 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5451 "Capability to RECEIVE the ORF from this neighbor\n"
5452 "Capability to SEND the ORF to this neighbor\n")
5453{
d62a17ae 5454 int idx_send_recv = 6;
db45f64d
DS
5455 char *peer_str = argv[2]->arg;
5456 struct peer *peer;
5457 afi_t afi = bgp_node_afi(vty);
5458 safi_t safi = bgp_node_safi(vty);
d62a17ae 5459
db45f64d
DS
5460 peer = peer_and_group_lookup_vty(vty, peer_str);
5461 if (!peer)
d62a17ae 5462 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5463
db45f64d
DS
5464 if (strmatch(argv[idx_send_recv]->text, "send"))
5465 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5466 PEER_FLAG_ORF_PREFIX_SM);
5467
5468 if (strmatch(argv[idx_send_recv]->text, "receive"))
5469 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5470 PEER_FLAG_ORF_PREFIX_RM);
5471
5472 if (strmatch(argv[idx_send_recv]->text, "both"))
5473 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5474 PEER_FLAG_ORF_PREFIX_SM)
5475 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5476 PEER_FLAG_ORF_PREFIX_RM);
5477
5478 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5479}
5480
5481ALIAS_HIDDEN(
5482 no_neighbor_capability_orf_prefix,
5483 no_neighbor_capability_orf_prefix_hidden_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5486 "Advertise capability to the peer\n"
5487 "Advertise ORF capability to the peer\n"
5488 "Advertise prefixlist ORF capability to this neighbor\n"
5489 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5490 "Capability to RECEIVE the ORF from this neighbor\n"
5491 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5492
718e3744 5493/* neighbor next-hop-self. */
28c6e247
IR
5494DEFUN (neighbor_nexthop_self,
5495 neighbor_nexthop_self_cmd,
5496 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5497 NEIGHBOR_STR
5498 NEIGHBOR_ADDR_STR2
5499 "Disable the next hop calculation for this neighbor\n")
718e3744 5500{
d62a17ae 5501 int idx_peer = 1;
28c6e247
IR
5502 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5503 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5504}
9e7a53c1 5505
d62a17ae 5506ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5507 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5508 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5509 "Disable the next hop calculation for this neighbor\n")
596c17ba 5510
f4b8ec07 5511/* neighbor next-hop-self. */
28c6e247
IR
5512DEFUN (neighbor_nexthop_self_force,
5513 neighbor_nexthop_self_force_cmd,
5514 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5515 NEIGHBOR_STR
5516 NEIGHBOR_ADDR_STR2
5517 "Disable the next hop calculation for this neighbor\n"
5518 "Set the next hop to self for reflected routes\n")
f4b8ec07
CS
5519{
5520 int idx_peer = 1;
28c6e247
IR
5521 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5522 bgp_node_safi(vty),
5523 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5524}
5525
d62a17ae 5526ALIAS_HIDDEN(neighbor_nexthop_self_force,
5527 neighbor_nexthop_self_force_hidden_cmd,
5528 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5529 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5530 "Disable the next hop calculation for this neighbor\n"
5531 "Set the next hop to self for reflected routes\n")
596c17ba 5532
1bc4e531
DA
5533ALIAS_HIDDEN(neighbor_nexthop_self_force,
5534 neighbor_nexthop_self_all_hidden_cmd,
5535 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5536 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5537 "Disable the next hop calculation for this neighbor\n"
5538 "Set the next hop to self for reflected routes\n")
5539
28c6e247
IR
5540DEFUN (no_neighbor_nexthop_self,
5541 no_neighbor_nexthop_self_cmd,
5542 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5543 NO_STR
5544 NEIGHBOR_STR
5545 NEIGHBOR_ADDR_STR2
5546 "Disable the next hop calculation for this neighbor\n")
718e3744 5547{
d62a17ae 5548 int idx_peer = 2;
28c6e247
IR
5549 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5550 bgp_node_afi(vty), bgp_node_safi(vty),
5551 PEER_FLAG_NEXTHOP_SELF);
718e3744 5552}
6b0655a2 5553
d62a17ae 5554ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5555 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5556 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5557 "Disable the next hop calculation for this neighbor\n")
596c17ba 5558
28c6e247
IR
5559DEFUN (no_neighbor_nexthop_self_force,
5560 no_neighbor_nexthop_self_force_cmd,
5561 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5562 NO_STR
5563 NEIGHBOR_STR
5564 NEIGHBOR_ADDR_STR2
5565 "Disable the next hop calculation for this neighbor\n"
5566 "Set the next hop to self for reflected routes\n")
88b8ed8d 5567{
d62a17ae 5568 int idx_peer = 2;
28c6e247
IR
5569 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5570 bgp_node_afi(vty), bgp_node_safi(vty),
5571 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5572}
a538debe 5573
d62a17ae 5574ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5575 no_neighbor_nexthop_self_force_hidden_cmd,
5576 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5577 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Disable the next hop calculation for this neighbor\n"
5579 "Set the next hop to self for reflected routes\n")
596c17ba 5580
1bc4e531
DA
5581ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5582 no_neighbor_nexthop_self_all_hidden_cmd,
5583 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5585 "Disable the next hop calculation for this neighbor\n"
5586 "Set the next hop to self for reflected routes\n")
5587
c7122e14 5588/* neighbor as-override */
28c6e247
IR
5589DEFUN (neighbor_as_override,
5590 neighbor_as_override_cmd,
5591 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5592 NEIGHBOR_STR
5593 NEIGHBOR_ADDR_STR2
5594 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5595{
d62a17ae 5596 int idx_peer = 1;
28c6e247
IR
5597 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5598 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5599}
5600
d62a17ae 5601ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5602 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5603 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5605
28c6e247
IR
5606DEFUN (no_neighbor_as_override,
5607 no_neighbor_as_override_cmd,
5608 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5609 NO_STR
5610 NEIGHBOR_STR
5611 NEIGHBOR_ADDR_STR2
5612 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5613{
d62a17ae 5614 int idx_peer = 2;
28c6e247
IR
5615 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5616 bgp_node_afi(vty), bgp_node_safi(vty),
5617 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5618}
5619
d62a17ae 5620ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5621 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5622 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5623 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5624
718e3744 5625/* neighbor remove-private-AS. */
28c6e247
IR
5626DEFUN (neighbor_remove_private_as,
5627 neighbor_remove_private_as_cmd,
5628 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5629 NEIGHBOR_STR
5630 NEIGHBOR_ADDR_STR2
5631 "Remove private ASNs in outbound updates\n")
718e3744 5632{
d62a17ae 5633 int idx_peer = 1;
28c6e247
IR
5634 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5635 bgp_node_safi(vty),
5636 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5637}
5638
d62a17ae 5639ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Remove private ASNs in outbound updates\n")
596c17ba 5643
28c6e247
IR
5644DEFUN (neighbor_remove_private_as_all,
5645 neighbor_remove_private_as_all_cmd,
5646 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5647 NEIGHBOR_STR
5648 NEIGHBOR_ADDR_STR2
5649 "Remove private ASNs in outbound updates\n"
5650 "Apply to all AS numbers\n")
5000f21c 5651{
d62a17ae 5652 int idx_peer = 1;
28c6e247
IR
5653 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5654 bgp_node_safi(vty),
5655 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5656}
5657
d62a17ae 5658ALIAS_HIDDEN(neighbor_remove_private_as_all,
5659 neighbor_remove_private_as_all_hidden_cmd,
5660 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5661 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5662 "Remove private ASNs in outbound updates\n"
5663 "Apply to all AS numbers")
596c17ba 5664
28c6e247
IR
5665DEFUN (neighbor_remove_private_as_replace_as,
5666 neighbor_remove_private_as_replace_as_cmd,
5667 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5668 NEIGHBOR_STR
5669 NEIGHBOR_ADDR_STR2
5670 "Remove private ASNs in outbound updates\n"
5671 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5672{
d62a17ae 5673 int idx_peer = 1;
28c6e247
IR
5674 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5675 bgp_node_safi(vty),
5676 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5677}
5678
d62a17ae 5679ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5680 neighbor_remove_private_as_replace_as_hidden_cmd,
5681 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5683 "Remove private ASNs in outbound updates\n"
5684 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5685
28c6e247
IR
5686DEFUN (neighbor_remove_private_as_all_replace_as,
5687 neighbor_remove_private_as_all_replace_as_cmd,
5688 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5689 NEIGHBOR_STR
5690 NEIGHBOR_ADDR_STR2
5691 "Remove private ASNs in outbound updates\n"
5692 "Apply to all AS numbers\n"
5693 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5694{
d62a17ae 5695 int idx_peer = 1;
28c6e247
IR
5696 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5697 bgp_node_safi(vty),
5698 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5699}
5700
d62a17ae 5701ALIAS_HIDDEN(
5702 neighbor_remove_private_as_all_replace_as,
5703 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5704 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5705 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5706 "Remove private ASNs in outbound updates\n"
5707 "Apply to all AS numbers\n"
5708 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5709
28c6e247
IR
5710DEFUN (no_neighbor_remove_private_as,
5711 no_neighbor_remove_private_as_cmd,
5712 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5713 NO_STR
5714 NEIGHBOR_STR
5715 NEIGHBOR_ADDR_STR2
5716 "Remove private ASNs in outbound updates\n")
718e3744 5717{
d62a17ae 5718 int idx_peer = 2;
28c6e247
IR
5719 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5720 bgp_node_afi(vty), bgp_node_safi(vty),
5721 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5722}
6b0655a2 5723
d62a17ae 5724ALIAS_HIDDEN(no_neighbor_remove_private_as,
5725 no_neighbor_remove_private_as_hidden_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5727 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5728 "Remove private ASNs in outbound updates\n")
596c17ba 5729
28c6e247
IR
5730DEFUN (no_neighbor_remove_private_as_all,
5731 no_neighbor_remove_private_as_all_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5733 NO_STR
5734 NEIGHBOR_STR
5735 NEIGHBOR_ADDR_STR2
5736 "Remove private ASNs in outbound updates\n"
5737 "Apply to all AS numbers\n")
88b8ed8d 5738{
d62a17ae 5739 int idx_peer = 2;
28c6e247
IR
5740 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5741 bgp_node_afi(vty), bgp_node_safi(vty),
5742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5743}
5000f21c 5744
d62a17ae 5745ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5746 no_neighbor_remove_private_as_all_hidden_cmd,
5747 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5748 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Remove private ASNs in outbound updates\n"
5750 "Apply to all AS numbers\n")
596c17ba 5751
28c6e247
IR
5752DEFUN (no_neighbor_remove_private_as_replace_as,
5753 no_neighbor_remove_private_as_replace_as_cmd,
5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5755 NO_STR
5756 NEIGHBOR_STR
5757 NEIGHBOR_ADDR_STR2
5758 "Remove private ASNs in outbound updates\n"
5759 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5760{
d62a17ae 5761 int idx_peer = 2;
28c6e247
IR
5762 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5763 bgp_node_afi(vty), bgp_node_safi(vty),
5764 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5765}
5000f21c 5766
d62a17ae 5767ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5768 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5769 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5770 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5771 "Remove private ASNs in outbound updates\n"
5772 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5773
28c6e247
IR
5774DEFUN (no_neighbor_remove_private_as_all_replace_as,
5775 no_neighbor_remove_private_as_all_replace_as_cmd,
5776 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5777 NO_STR
5778 NEIGHBOR_STR
5779 NEIGHBOR_ADDR_STR2
5780 "Remove private ASNs in outbound updates\n"
5781 "Apply to all AS numbers\n"
5782 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5783{
d62a17ae 5784 int idx_peer = 2;
28c6e247
IR
5785 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5786 bgp_node_afi(vty), bgp_node_safi(vty),
5787 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5788}
5000f21c 5789
d62a17ae 5790ALIAS_HIDDEN(
5791 no_neighbor_remove_private_as_all_replace_as,
5792 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5793 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5794 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5795 "Remove private ASNs in outbound updates\n"
5796 "Apply to all AS numbers\n"
5797 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5798
5000f21c 5799
718e3744 5800/* neighbor send-community. */
28c6e247
IR
5801DEFUN (neighbor_send_community,
5802 neighbor_send_community_cmd,
5803 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5804 NEIGHBOR_STR
5805 NEIGHBOR_ADDR_STR2
5806 "Send Community attribute to this neighbor\n")
718e3744 5807{
d62a17ae 5808 int idx_peer = 1;
27c05d4d 5809
f63d4054
IR
5810 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5811 bgp_node_safi(vty),
5812 PEER_FLAG_SEND_COMMUNITY);
718e3744 5813}
5814
d62a17ae 5815ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Send Community attribute to this neighbor\n")
596c17ba 5819
28c6e247
IR
5820DEFUN (no_neighbor_send_community,
5821 no_neighbor_send_community_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5823 NO_STR
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Send Community attribute to this neighbor\n")
718e3744 5827{
d62a17ae 5828 int idx_peer = 2;
27c05d4d 5829
f63d4054
IR
5830 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5831 bgp_node_afi(vty), bgp_node_safi(vty),
5832 PEER_FLAG_SEND_COMMUNITY);
718e3744 5833}
6b0655a2 5834
d62a17ae 5835ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5836 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5837 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5838 "Send Community attribute to this neighbor\n")
596c17ba 5839
718e3744 5840/* neighbor send-community extended. */
28c6e247
IR
5841DEFUN (neighbor_send_community_type,
5842 neighbor_send_community_type_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Send Community attribute to this neighbor\n"
5847 "Send Standard and Extended Community attributes\n"
5848 "Send Standard, Large and Extended Community attributes\n"
5849 "Send Extended Community attributes\n"
5850 "Send Standard Community attributes\n"
5851 "Send Large Community attributes\n")
718e3744 5852{
27c05d4d 5853 const char *type = argv[argc - 1]->text;
db45f64d 5854 char *peer_str = argv[1]->arg;
28c6e247 5855 struct peer *peer;
db45f64d 5856 afi_t afi = bgp_node_afi(vty);
28c6e247 5857 safi_t safi = bgp_node_safi(vty);
f4b8ec07 5858
28c6e247
IR
5859 peer = peer_and_group_lookup_vty(vty, peer_str);
5860 if (!peer)
5861 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07 5862
28c6e247
IR
5863 if (strmatch(type, "standard"))
5864 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5865 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5866
28c6e247
IR
5867 if (strmatch(type, "extended"))
5868 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5869 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5870
28c6e247
IR
5871 if (strmatch(type, "large"))
5872 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5873 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07 5874
28c6e247
IR
5875 if (strmatch(type, "both")) {
5876 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5877 PEER_FLAG_SEND_COMMUNITY)
5878 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5879 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5880 }
28c6e247
IR
5881 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5882 PEER_FLAG_SEND_COMMUNITY)
5883 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5884 PEER_FLAG_SEND_EXT_COMMUNITY)
5885 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5886 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5887}
5888
5889ALIAS_HIDDEN(
5890 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5891 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5892 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5893 "Send Community attribute to this neighbor\n"
5894 "Send Standard and Extended Community attributes\n"
5895 "Send Standard, Large and Extended Community attributes\n"
5896 "Send Extended Community attributes\n"
5897 "Send Standard Community attributes\n"
5898 "Send Large Community attributes\n")
596c17ba 5899
28c6e247
IR
5900DEFUN (no_neighbor_send_community_type,
5901 no_neighbor_send_community_type_cmd,
5902 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5903 NO_STR
5904 NEIGHBOR_STR
5905 NEIGHBOR_ADDR_STR2
5906 "Send Community attribute to this neighbor\n"
5907 "Send Standard and Extended Community attributes\n"
5908 "Send Standard, Large and Extended Community attributes\n"
5909 "Send Extended Community attributes\n"
5910 "Send Standard Community attributes\n"
5911 "Send Large Community attributes\n")
718e3744 5912{
d62a17ae 5913 const char *type = argv[argc - 1]->text;
db45f64d 5914 char *peer_str = argv[2]->arg;
28c6e247 5915 struct peer *peer;
db45f64d
DS
5916 afi_t afi = bgp_node_afi(vty);
5917 safi_t safi = bgp_node_safi(vty);
5918
28c6e247
IR
5919 peer = peer_and_group_lookup_vty(vty, peer_str);
5920 if (!peer)
f4b8ec07
CS
5921 return CMD_WARNING_CONFIG_FAILED;
5922
28c6e247
IR
5923 if (strmatch(type, "standard"))
5924 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5925 PEER_FLAG_SEND_COMMUNITY);
f4b8ec07 5926
28c6e247
IR
5927 if (strmatch(type, "extended"))
5928 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5929 PEER_FLAG_SEND_EXT_COMMUNITY);
f4b8ec07 5930
28c6e247
IR
5931 if (strmatch(type, "large"))
5932 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5933 PEER_FLAG_SEND_LARGE_COMMUNITY);
f4b8ec07
CS
5934
5935 if (strmatch(type, "both")) {
db45f64d 5936
28c6e247
IR
5937 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5938 PEER_FLAG_SEND_COMMUNITY)
5939 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5940 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5941 }
5942
28c6e247
IR
5943 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5944 PEER_FLAG_SEND_COMMUNITY)
5945 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_SEND_EXT_COMMUNITY)
5947 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5948 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5949}
5950
5951ALIAS_HIDDEN(
5952 no_neighbor_send_community_type,
5953 no_neighbor_send_community_type_hidden_cmd,
5954 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5955 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5956 "Send Community attribute to this neighbor\n"
5957 "Send Standard and Extended Community attributes\n"
5958 "Send Standard, Large and Extended Community attributes\n"
5959 "Send Extended Community attributes\n"
5960 "Send Standard Community attributes\n"
5961 "Send Large Community attributes\n")
596c17ba 5962
718e3744 5963/* neighbor soft-reconfig. */
28c6e247
IR
5964DEFUN (neighbor_soft_reconfiguration,
5965 neighbor_soft_reconfiguration_cmd,
5966 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5967 NEIGHBOR_STR
5968 NEIGHBOR_ADDR_STR2
5969 "Per neighbor soft reconfiguration\n"
5970 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5971{
d62a17ae 5972 int idx_peer = 1;
28c6e247
IR
5973 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5974 bgp_node_safi(vty),
5975 PEER_FLAG_SOFT_RECONFIG);
718e3744 5976}
5977
d62a17ae 5978ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5979 neighbor_soft_reconfiguration_hidden_cmd,
5980 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5981 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5982 "Per neighbor soft reconfiguration\n"
5983 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5984
28c6e247
IR
5985DEFUN (no_neighbor_soft_reconfiguration,
5986 no_neighbor_soft_reconfiguration_cmd,
5987 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5988 NO_STR
5989 NEIGHBOR_STR
5990 NEIGHBOR_ADDR_STR2
5991 "Per neighbor soft reconfiguration\n"
5992 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 5993{
d62a17ae 5994 int idx_peer = 2;
28c6e247
IR
5995 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5996 bgp_node_afi(vty), bgp_node_safi(vty),
5997 PEER_FLAG_SOFT_RECONFIG);
718e3744 5998}
6b0655a2 5999
d62a17ae 6000ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6001 no_neighbor_soft_reconfiguration_hidden_cmd,
6002 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6004 "Per neighbor soft reconfiguration\n"
6005 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6006
28c6e247
IR
6007DEFUN (neighbor_route_reflector_client,
6008 neighbor_route_reflector_client_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6010 NEIGHBOR_STR
6011 NEIGHBOR_ADDR_STR2
6012 "Configure a neighbor as Route Reflector client\n")
718e3744 6013{
d62a17ae 6014 int idx_peer = 1;
28c6e247 6015 struct peer *peer;
718e3744 6016
6017
28c6e247
IR
6018 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6019 if (!peer)
d62a17ae 6020 return CMD_WARNING_CONFIG_FAILED;
718e3744 6021
28c6e247
IR
6022 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6023 bgp_node_safi(vty),
6024 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6025}
6026
d62a17ae 6027ALIAS_HIDDEN(neighbor_route_reflector_client,
6028 neighbor_route_reflector_client_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Configure a neighbor as Route Reflector client\n")
596c17ba 6032
28c6e247
IR
6033DEFUN (no_neighbor_route_reflector_client,
6034 no_neighbor_route_reflector_client_cmd,
6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6036 NO_STR
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Configure a neighbor as Route Reflector client\n")
718e3744 6040{
d62a17ae 6041 int idx_peer = 2;
28c6e247
IR
6042 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6043 bgp_node_afi(vty), bgp_node_safi(vty),
6044 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 6045}
6b0655a2 6046
d62a17ae 6047ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6048 no_neighbor_route_reflector_client_hidden_cmd,
6049 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "Configure a neighbor as Route Reflector client\n")
596c17ba 6052
718e3744 6053/* neighbor route-server-client. */
28c6e247
IR
6054DEFUN (neighbor_route_server_client,
6055 neighbor_route_server_client_cmd,
6056 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6057 NEIGHBOR_STR
6058 NEIGHBOR_ADDR_STR2
6059 "Configure a neighbor as Route Server client\n")
718e3744 6060{
d62a17ae 6061 int idx_peer = 1;
28c6e247 6062 struct peer *peer;
f4b8ec07 6063
28c6e247
IR
6064 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6065 if (!peer)
d62a17ae 6066 return CMD_WARNING_CONFIG_FAILED;
28c6e247
IR
6067 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6068 bgp_node_safi(vty),
6069 PEER_FLAG_RSERVER_CLIENT);
718e3744 6070}
6071
d62a17ae 6072ALIAS_HIDDEN(neighbor_route_server_client,
6073 neighbor_route_server_client_hidden_cmd,
6074 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6075 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6076 "Configure a neighbor as Route Server client\n")
596c17ba 6077
28c6e247
IR
6078DEFUN (no_neighbor_route_server_client,
6079 no_neighbor_route_server_client_cmd,
6080 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6081 NO_STR
6082 NEIGHBOR_STR
6083 NEIGHBOR_ADDR_STR2
6084 "Configure a neighbor as Route Server client\n")
fee0f4c6 6085{
d62a17ae 6086 int idx_peer = 2;
28c6e247
IR
6087 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6088 bgp_node_afi(vty), bgp_node_safi(vty),
6089 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 6090}
6b0655a2 6091
d62a17ae 6092ALIAS_HIDDEN(no_neighbor_route_server_client,
6093 no_neighbor_route_server_client_hidden_cmd,
6094 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6095 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6096 "Configure a neighbor as Route Server client\n")
596c17ba 6097
fee0f4c6 6098DEFUN (neighbor_nexthop_local_unchanged,
6099 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6100 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Configure treatment of outgoing link-local nexthop attribute\n"
6104 "Leave link-local nexthop unchanged for this peer\n")
6105{
d62a17ae 6106 int idx_peer = 1;
6107 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6108 bgp_node_safi(vty),
6109 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6110}
6b0655a2 6111
fee0f4c6 6112DEFUN (no_neighbor_nexthop_local_unchanged,
6113 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6114 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6115 NO_STR
6116 NEIGHBOR_STR
6117 NEIGHBOR_ADDR_STR2
6118 "Configure treatment of outgoing link-local-nexthop attribute\n"
6119 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6120{
d62a17ae 6121 int idx_peer = 2;
6122 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6123 bgp_node_afi(vty), bgp_node_safi(vty),
6124 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6125}
6b0655a2 6126
28c6e247
IR
6127DEFUN (neighbor_attr_unchanged,
6128 neighbor_attr_unchanged_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "BGP attribute is propagated unchanged to this neighbor\n"
6133 "As-path attribute\n"
6134 "Nexthop attribute\n"
6135 "Med attribute\n")
718e3744 6136{
d62a17ae 6137 int idx = 0;
8eeb0335 6138 char *peer_str = argv[1]->arg;
28c6e247 6139 struct peer *peer;
db45f64d
DS
6140 bool aspath = false;
6141 bool nexthop = false;
6142 bool med = false;
8eeb0335
DW
6143 afi_t afi = bgp_node_afi(vty);
6144 safi_t safi = bgp_node_safi(vty);
28c6e247 6145 int ret = 0;
f4b8ec07 6146
28c6e247
IR
6147 peer = peer_and_group_lookup_vty(vty, peer_str);
6148 if (!peer)
8eeb0335 6149 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6150
6151 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6152 aspath = true;
6153
d62a17ae 6154 idx = 0;
6155 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6156 nexthop = true;
6157
d62a17ae 6158 idx = 0;
6159 if (argv_find(argv, argc, "med", &idx))
db45f64d 6160 med = true;
d62a17ae 6161
8eeb0335 6162 /* no flags means all of them! */
db45f64d 6163 if (!aspath && !nexthop && !med) {
28c6e247
IR
6164 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
6165 PEER_FLAG_AS_PATH_UNCHANGED);
6166 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6167 PEER_FLAG_NEXTHOP_UNCHANGED);
6168 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6169 PEER_FLAG_MED_UNCHANGED);
8eeb0335 6170 } else {
28c6e247
IR
6171 if (!aspath) {
6172 if (peer_af_flag_check(peer, afi, safi,
6173 PEER_FLAG_AS_PATH_UNCHANGED)) {
6174 ret |= peer_af_flag_unset_vty(
6175 vty, peer_str, afi, safi,
6176 PEER_FLAG_AS_PATH_UNCHANGED);
6177 }
6178 } else
6179 ret |= peer_af_flag_set_vty(
6180 vty, peer_str, afi, safi,
6181 PEER_FLAG_AS_PATH_UNCHANGED);
6182
6183 if (!nexthop) {
6184 if (peer_af_flag_check(peer, afi, safi,
6185 PEER_FLAG_NEXTHOP_UNCHANGED)) {
6186 ret |= peer_af_flag_unset_vty(
6187 vty, peer_str, afi, safi,
6188 PEER_FLAG_NEXTHOP_UNCHANGED);
6189 }
6190 } else
6191 ret |= peer_af_flag_set_vty(
6192 vty, peer_str, afi, safi,
6193 PEER_FLAG_NEXTHOP_UNCHANGED);
6194
6195 if (!med) {
6196 if (peer_af_flag_check(peer, afi, safi,
6197 PEER_FLAG_MED_UNCHANGED)) {
6198 ret |= peer_af_flag_unset_vty(
6199 vty, peer_str, afi, safi,
6200 PEER_FLAG_MED_UNCHANGED);
6201 }
6202 } else
6203 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
6204 PEER_FLAG_MED_UNCHANGED);
d62a17ae 6205 }
6206
28c6e247 6207 return ret;
d62a17ae 6208}
6209
6210ALIAS_HIDDEN(
6211 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6212 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6213 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6214 "BGP attribute is propagated unchanged to this neighbor\n"
6215 "As-path attribute\n"
6216 "Nexthop attribute\n"
6217 "Med attribute\n")
596c17ba 6218
28c6e247
IR
6219DEFUN (no_neighbor_attr_unchanged,
6220 no_neighbor_attr_unchanged_cmd,
6221 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6222 NO_STR
6223 NEIGHBOR_STR
6224 NEIGHBOR_ADDR_STR2
6225 "BGP attribute is propagated unchanged to this neighbor\n"
6226 "As-path attribute\n"
6227 "Nexthop attribute\n"
6228 "Med attribute\n")
718e3744 6229{
d62a17ae 6230 int idx = 0;
db45f64d 6231 char *peer_str = argv[2]->arg;
28c6e247 6232 struct peer *peer;
db45f64d
DS
6233 bool aspath = false;
6234 bool nexthop = false;
6235 bool med = false;
6236 afi_t afi = bgp_node_afi(vty);
6237 safi_t safi = bgp_node_safi(vty);
28c6e247 6238 int ret = 0;
f4b8ec07 6239
28c6e247
IR
6240 peer = peer_and_group_lookup_vty(vty, peer_str);
6241 if (!peer)
db45f64d 6242 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6243
6244 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6245 aspath = true;
6246
d62a17ae 6247 idx = 0;
6248 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6249 nexthop = true;
6250
d62a17ae 6251 idx = 0;
6252 if (argv_find(argv, argc, "med", &idx))
db45f64d 6253 med = true;
d62a17ae 6254
28c6e247
IR
6255 if (!aspath && !nexthop && !med) // no flags means all of them!
6256 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6257 PEER_FLAG_AS_PATH_UNCHANGED)
6258 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6259 PEER_FLAG_NEXTHOP_UNCHANGED)
6260 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6261 PEER_FLAG_MED_UNCHANGED);
db45f64d
DS
6262
6263 if (aspath)
28c6e247
IR
6264 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6265 PEER_FLAG_AS_PATH_UNCHANGED);
db45f64d
DS
6266
6267 if (nexthop)
28c6e247
IR
6268 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6269 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 6270
db45f64d 6271 if (med)
28c6e247
IR
6272 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
6273 PEER_FLAG_MED_UNCHANGED);
db45f64d 6274
28c6e247 6275 return ret;
d62a17ae 6276}
6277
6278ALIAS_HIDDEN(
6279 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6280 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6281 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6282 "BGP attribute is propagated unchanged to this neighbor\n"
6283 "As-path attribute\n"
6284 "Nexthop attribute\n"
6285 "Med attribute\n")
718e3744 6286
28c6e247
IR
6287/* EBGP multihop configuration. */
6288static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
6289 const char *ttl_str)
718e3744 6290{
28c6e247
IR
6291 struct peer *peer;
6292 unsigned int ttl;
718e3744 6293
28c6e247
IR
6294 peer = peer_and_group_lookup_vty(vty, ip_str);
6295 if (!peer)
d62a17ae 6296 return CMD_WARNING_CONFIG_FAILED;
718e3744 6297
28c6e247
IR
6298 if (peer->conf_if)
6299 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
6300
6301 if (!ttl_str)
6302 ttl = MAXTTL;
6303 else
6304 ttl = strtoul(ttl_str, NULL, 10);
718e3744 6305
28c6e247 6306 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 6307}
6308
28c6e247 6309static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6310{
28c6e247 6311 struct peer *peer;
718e3744 6312
28c6e247
IR
6313 peer = peer_and_group_lookup_vty(vty, ip_str);
6314 if (!peer)
d62a17ae 6315 return CMD_WARNING_CONFIG_FAILED;
718e3744 6316
28c6e247 6317 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6318}
6319
28c6e247
IR
6320/* neighbor ebgp-multihop. */
6321DEFUN (neighbor_ebgp_multihop,
6322 neighbor_ebgp_multihop_cmd,
6323 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6324 NEIGHBOR_STR
6325 NEIGHBOR_ADDR_STR2
6326 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6327{
28c6e247
IR
6328 int idx_peer = 1;
6329 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
6330}
f4b8ec07 6331
28c6e247
IR
6332DEFUN (neighbor_ebgp_multihop_ttl,
6333 neighbor_ebgp_multihop_ttl_cmd,
6334 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6335 NEIGHBOR_STR
6336 NEIGHBOR_ADDR_STR2
6337 "Allow EBGP neighbors not on directly connected networks\n"
6338 "maximum hop count\n")
6339{
6340 int idx_peer = 1;
6341 int idx_number = 3;
6342 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6343 argv[idx_number]->arg);
6344}
f4b8ec07 6345
28c6e247
IR
6346DEFUN (no_neighbor_ebgp_multihop,
6347 no_neighbor_ebgp_multihop_cmd,
6348 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6349 NO_STR
6350 NEIGHBOR_STR
6351 NEIGHBOR_ADDR_STR2
6352 "Allow EBGP neighbors not on directly connected networks\n"
6353 "maximum hop count\n")
6354{
6355 int idx_peer = 2;
6356 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6357}
6358
6b0655a2 6359
6ffd2079 6360/* disable-connected-check */
28c6e247
IR
6361DEFUN (neighbor_disable_connected_check,
6362 neighbor_disable_connected_check_cmd,
6363 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6364 NEIGHBOR_STR
6365 NEIGHBOR_ADDR_STR2
6366 "one-hop away EBGP peer using loopback address\n"
6367 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6368{
d62a17ae 6369 int idx_peer = 1;
28c6e247
IR
6370 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6371 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6372}
6373
28c6e247
IR
6374DEFUN (no_neighbor_disable_connected_check,
6375 no_neighbor_disable_connected_check_cmd,
6376 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6377 NO_STR
6378 NEIGHBOR_STR
6379 NEIGHBOR_ADDR_STR2
6380 "one-hop away EBGP peer using loopback address\n"
6381 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6382{
d62a17ae 6383 int idx_peer = 2;
28c6e247
IR
6384 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6385 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6386}
6387
7ab294ea
DA
6388/* disable-link-bw-encoding-ieee */
6389DEFUN(neighbor_disable_link_bw_encoding_ieee,
6390 neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6391 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6393 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6394{
6395 int idx_peer = 1;
6396
6397 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6398 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6399}
6400
7ab294ea
DA
6401DEFUN(no_neighbor_disable_link_bw_encoding_ieee,
6402 no_neighbor_disable_link_bw_encoding_ieee_cmd,
27aa23a4
DA
6403 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-link-bw-encoding-ieee",
6404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7ab294ea 6405 "Disable IEEE floating-point encoding for extended community bandwidth\n")
27aa23a4
DA
6406{
6407 int idx_peer = 2;
6408
6409 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6410 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE);
6411}
6412
d08c0c80
DA
6413/* extended-optional-parameters */
6414DEFUN(neighbor_extended_optional_parameters,
6415 neighbor_extended_optional_parameters_cmd,
6416 "neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6417 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6418 "Force the extended optional parameters format for OPEN messages\n")
6419{
6420 int idx_peer = 1;
6421
6422 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6423 PEER_FLAG_EXTENDED_OPT_PARAMS);
6424}
6425
6426DEFUN(no_neighbor_extended_optional_parameters,
6427 no_neighbor_extended_optional_parameters_cmd,
6428 "no neighbor <A.B.C.D|X:X::X:X|WORD> extended-optional-parameters",
6429 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6430 "Force the extended optional parameters format for OPEN messages\n")
6431{
6432 int idx_peer = 2;
6433
6434 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6435 PEER_FLAG_EXTENDED_OPT_PARAMS);
6436}
47cbc09b
PM
6437
6438/* enforce-first-as */
28c6e247
IR
6439DEFUN (neighbor_enforce_first_as,
6440 neighbor_enforce_first_as_cmd,
6441 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6442 NEIGHBOR_STR
6443 NEIGHBOR_ADDR_STR2
6444 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6445{
6446 int idx_peer = 1;
f4b8ec07 6447
28c6e247
IR
6448 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6449 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6450}
6451
28c6e247
IR
6452DEFUN (no_neighbor_enforce_first_as,
6453 no_neighbor_enforce_first_as_cmd,
6454 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6455 NO_STR
6456 NEIGHBOR_STR
6457 NEIGHBOR_ADDR_STR2
6458 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6459{
6460 int idx_peer = 2;
f4b8ec07 6461
28c6e247
IR
6462 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6463 PEER_FLAG_ENFORCE_FIRST_AS);
47cbc09b
PM
6464}
6465
6466
28c6e247
IR
6467DEFUN (neighbor_description,
6468 neighbor_description_cmd,
6469 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6470 NEIGHBOR_STR
6471 NEIGHBOR_ADDR_STR2
6472 "Neighbor specific description\n"
6473 "Up to 80 characters describing this neighbor\n")
718e3744 6474{
d62a17ae 6475 int idx_peer = 1;
6476 int idx_line = 3;
28c6e247 6477 struct peer *peer;
d62a17ae 6478 char *str;
718e3744 6479
28c6e247
IR
6480 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6481 if (!peer)
d62a17ae 6482 return CMD_WARNING_CONFIG_FAILED;
718e3744 6483
d62a17ae 6484 str = argv_concat(argv, argc, idx_line);
718e3744 6485
28c6e247 6486 peer_description_set(peer, str);
718e3744 6487
d62a17ae 6488 XFREE(MTYPE_TMP, str);
718e3744 6489
28c6e247 6490 return CMD_SUCCESS;
718e3744 6491}
6492
28c6e247
IR
6493DEFUN (no_neighbor_description,
6494 no_neighbor_description_cmd,
6495 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
6496 NO_STR
6497 NEIGHBOR_STR
6498 NEIGHBOR_ADDR_STR2
6499 "Neighbor specific description\n")
718e3744 6500{
d62a17ae 6501 int idx_peer = 2;
28c6e247 6502 struct peer *peer;
f4b8ec07 6503
28c6e247
IR
6504 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6505 if (!peer)
d62a17ae 6506 return CMD_WARNING_CONFIG_FAILED;
718e3744 6507
28c6e247 6508 peer_description_unset(peer);
718e3744 6509
28c6e247 6510 return CMD_SUCCESS;
718e3744 6511}
6512
1d80f243 6513ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
6514 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6515 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6516 "Neighbor specific description\n"
6517 "Up to 80 characters describing this neighbor\n")
6b0655a2 6518
28c6e247
IR
6519/* Neighbor update-source. */
6520static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6521 const char *source_str)
6522{
6523 struct peer *peer;
6524 struct prefix p;
6525 union sockunion su;
6526
6527 peer = peer_and_group_lookup_vty(vty, peer_str);
6528 if (!peer)
6529 return CMD_WARNING_CONFIG_FAILED;
6530
6531 if (peer->conf_if)
6532 return CMD_WARNING;
6533
6534 if (source_str) {
6535 if (str2sockunion(source_str, &su) == 0)
6536 peer_update_source_addr_set(peer, &su);
6537 else {
6538 if (str2prefix(source_str, &p)) {
6539 vty_out(vty,
6540 "%% Invalid update-source, remove prefix length \n");
6541 return CMD_WARNING_CONFIG_FAILED;
6542 } else
6543 peer_update_source_if_set(peer, source_str);
6544 }
6545 } else
6546 peer_update_source_unset(peer);
6547
6548 return CMD_SUCCESS;
6549}
6550
d62a17ae 6551#define BGP_UPDATE_SOURCE_HELP_STR \
6552 "IPv4 address\n" \
6553 "IPv6 address\n" \
6554 "Interface name (requires zebra to be running)\n"
369688c0 6555
28c6e247
IR
6556DEFUN (neighbor_update_source,
6557 neighbor_update_source_cmd,
6558 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
6559 NEIGHBOR_STR
6560 NEIGHBOR_ADDR_STR2
6561 "Source of routing updates\n"
6562 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6563{
d62a17ae 6564 int idx_peer = 1;
6565 int idx_peer_2 = 3;
28c6e247 6566 return peer_update_source_vty(vty, argv[idx_peer]->arg,
d62a17ae 6567 argv[idx_peer_2]->arg);
718e3744 6568}
6569
28c6e247
IR
6570DEFUN (no_neighbor_update_source,
6571 no_neighbor_update_source_cmd,
6572 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
6573 NO_STR
6574 NEIGHBOR_STR
6575 NEIGHBOR_ADDR_STR2
6576 "Source of routing updates\n"
6577 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6578{
d62a17ae 6579 int idx_peer = 2;
28c6e247 6580 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6581}
6b0655a2 6582
d62a17ae 6583static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6584 afi_t afi, safi_t safi,
6585 const char *rmap, int set)
718e3744 6586{
d62a17ae 6587 int ret;
6588 struct peer *peer;
80912664 6589 struct route_map *route_map = NULL;
718e3744 6590
d62a17ae 6591 peer = peer_and_group_lookup_vty(vty, peer_str);
6592 if (!peer)
6593 return CMD_WARNING_CONFIG_FAILED;
718e3744 6594
1de27621 6595 if (set) {
80912664
DS
6596 if (rmap)
6597 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6598 ret = peer_default_originate_set(peer, afi, safi,
6599 rmap, route_map);
6600 } else
d62a17ae 6601 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6602
d62a17ae 6603 return bgp_vty_return(vty, ret);
718e3744 6604}
6605
6606/* neighbor default-originate. */
6607DEFUN (neighbor_default_originate,
6608 neighbor_default_originate_cmd,
9ccf14f7 6609 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6610 NEIGHBOR_STR
6611 NEIGHBOR_ADDR_STR2
6612 "Originate default route to this neighbor\n")
6613{
d62a17ae 6614 int idx_peer = 1;
6615 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6616 bgp_node_afi(vty),
6617 bgp_node_safi(vty), NULL, 1);
718e3744 6618}
6619
d62a17ae 6620ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6621 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6622 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6623 "Originate default route to this neighbor\n")
596c17ba 6624
718e3744 6625DEFUN (neighbor_default_originate_rmap,
6626 neighbor_default_originate_rmap_cmd,
9ccf14f7 6627 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6628 NEIGHBOR_STR
6629 NEIGHBOR_ADDR_STR2
6630 "Originate default route to this neighbor\n"
6631 "Route-map to specify criteria to originate default\n"
6632 "route-map name\n")
6633{
d62a17ae 6634 int idx_peer = 1;
6635 int idx_word = 4;
6636 return peer_default_originate_set_vty(
6637 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6638 argv[idx_word]->arg, 1);
718e3744 6639}
6640
d62a17ae 6641ALIAS_HIDDEN(
6642 neighbor_default_originate_rmap,
6643 neighbor_default_originate_rmap_hidden_cmd,
6644 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6646 "Originate default route to this neighbor\n"
6647 "Route-map to specify criteria to originate default\n"
6648 "route-map name\n")
596c17ba 6649
718e3744 6650DEFUN (no_neighbor_default_originate,
6651 no_neighbor_default_originate_cmd,
a636c635 6652 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6653 NO_STR
6654 NEIGHBOR_STR
6655 NEIGHBOR_ADDR_STR2
a636c635
DW
6656 "Originate default route to this neighbor\n"
6657 "Route-map to specify criteria to originate default\n"
6658 "route-map name\n")
718e3744 6659{
d62a17ae 6660 int idx_peer = 2;
6661 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6662 bgp_node_afi(vty),
6663 bgp_node_safi(vty), NULL, 0);
718e3744 6664}
6665
d62a17ae 6666ALIAS_HIDDEN(
6667 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6668 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6669 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6670 "Originate default route to this neighbor\n"
6671 "Route-map to specify criteria to originate default\n"
6672 "route-map name\n")
596c17ba 6673
6b0655a2 6674
28c6e247
IR
6675/* Set neighbor's BGP port. */
6676static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6677 const char *port_str)
718e3744 6678{
28c6e247
IR
6679 struct peer *peer;
6680 uint16_t port;
6681 struct servent *sp;
6682
6683 peer = peer_lookup_vty(vty, ip_str);
6684 if (!peer)
6685 return CMD_WARNING_CONFIG_FAILED;
6686
6687 if (!port_str) {
6688 sp = getservbyname("bgp", "tcp");
6689 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6690 } else {
6691 port = strtoul(port_str, NULL, 10);
6692 }
718e3744 6693
28c6e247 6694 peer_port_set(peer, port);
718e3744 6695
28c6e247
IR
6696 return CMD_SUCCESS;
6697}
f4b8ec07 6698
28c6e247
IR
6699/* Set specified peer's BGP port. */
6700DEFUN (neighbor_port,
6701 neighbor_port_cmd,
6702 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
6703 NEIGHBOR_STR
6704 NEIGHBOR_ADDR_STR
6705 "Neighbor's BGP port\n"
6706 "TCP port number\n")
6707{
6708 int idx_ip = 1;
6709 int idx_number = 3;
6710 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6711 argv[idx_number]->arg);
f4b8ec07 6712}
6b0655a2 6713
28c6e247
IR
6714DEFUN (no_neighbor_port,
6715 no_neighbor_port_cmd,
6716 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
6717 NO_STR
6718 NEIGHBOR_STR
6719 NEIGHBOR_ADDR_STR
6720 "Neighbor's BGP port\n"
6721 "TCP port number\n")
718e3744 6722{
f4b8ec07 6723 int idx_ip = 2;
28c6e247
IR
6724 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
6725}
6726
6727
6728/* neighbor weight. */
6729static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6730 safi_t safi, const char *weight_str)
6731{
6732 int ret;
6733 struct peer *peer;
6734 unsigned long weight;
718e3744 6735
28c6e247
IR
6736 peer = peer_and_group_lookup_vty(vty, ip_str);
6737 if (!peer)
6738 return CMD_WARNING_CONFIG_FAILED;
718e3744 6739
28c6e247 6740 weight = strtoul(weight_str, NULL, 10);
718e3744 6741
28c6e247
IR
6742 ret = peer_weight_set(peer, afi, safi, weight);
6743 return bgp_vty_return(vty, ret);
718e3744 6744}
6745
28c6e247
IR
6746static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6747 safi_t safi)
718e3744 6748{
28c6e247
IR
6749 int ret;
6750 struct peer *peer;
f4b8ec07 6751
28c6e247
IR
6752 peer = peer_and_group_lookup_vty(vty, ip_str);
6753 if (!peer)
d62a17ae 6754 return CMD_WARNING_CONFIG_FAILED;
718e3744 6755
28c6e247
IR
6756 ret = peer_weight_unset(peer, afi, safi);
6757 return bgp_vty_return(vty, ret);
6758}
f4b8ec07 6759
28c6e247
IR
6760DEFUN (neighbor_weight,
6761 neighbor_weight_cmd,
6762 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6763 NEIGHBOR_STR
6764 NEIGHBOR_ADDR_STR2
6765 "Set default weight for routes from this neighbor\n"
6766 "default weight\n")
6767{
6768 int idx_peer = 1;
6769 int idx_number = 3;
6770 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6771 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6772}
6773
d62a17ae 6774ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6775 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6776 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6777 "Set default weight for routes from this neighbor\n"
6778 "default weight\n")
596c17ba 6779
28c6e247
IR
6780DEFUN (no_neighbor_weight,
6781 no_neighbor_weight_cmd,
6782 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6783 NO_STR
6784 NEIGHBOR_STR
6785 NEIGHBOR_ADDR_STR2
6786 "Set default weight for routes from this neighbor\n"
6787 "default weight\n")
718e3744 6788{
d62a17ae 6789 int idx_peer = 2;
28c6e247
IR
6790 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6791 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6792}
6793
d62a17ae 6794ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6795 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6796 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6797 "Set default weight for routes from this neighbor\n"
6798 "default weight\n")
596c17ba 6799
6b0655a2 6800
718e3744 6801/* Override capability negotiation. */
c36bc05f
IR
6802DEFUN (neighbor_override_capability,
6803 neighbor_override_capability_cmd,
6804 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6805 NEIGHBOR_STR
6806 NEIGHBOR_ADDR_STR2
6807 "Override capability negotiation result\n")
718e3744 6808{
d62a17ae 6809 int idx_peer = 1;
c36bc05f
IR
6810 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6811 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6812}
6813
c36bc05f
IR
6814DEFUN (no_neighbor_override_capability,
6815 no_neighbor_override_capability_cmd,
6816 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
6817 NO_STR
6818 NEIGHBOR_STR
6819 NEIGHBOR_ADDR_STR2
6820 "Override capability negotiation result\n")
718e3744 6821{
d62a17ae 6822 int idx_peer = 2;
c36bc05f
IR
6823 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6824 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6825}
6b0655a2 6826
c36bc05f
IR
6827DEFUN (neighbor_strict_capability,
6828 neighbor_strict_capability_cmd,
6829 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6830 NEIGHBOR_STR
6831 NEIGHBOR_ADDR_STR2
6832 "Strict capability negotiation match\n")
718e3744 6833{
9fb964de
PM
6834 int idx_peer = 1;
6835
c36bc05f
IR
6836 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6837 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6838}
6839
c36bc05f
IR
6840DEFUN (no_neighbor_strict_capability,
6841 no_neighbor_strict_capability_cmd,
6842 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
6843 NO_STR
6844 NEIGHBOR_STR
6845 NEIGHBOR_ADDR_STR2
6846 "Strict capability negotiation match\n")
718e3744 6847{
9fb964de 6848 int idx_peer = 2;
8611c7f3 6849
c36bc05f
IR
6850 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6851 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6852}
6b0655a2 6853
28c6e247
IR
6854static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6855 const char *keep_str, const char *hold_str)
718e3744 6856{
28c6e247
IR
6857 int ret;
6858 struct peer *peer;
6859 uint32_t keepalive;
6860 uint32_t holdtime;
718e3744 6861
28c6e247
IR
6862 peer = peer_and_group_lookup_vty(vty, ip_str);
6863 if (!peer)
d62a17ae 6864 return CMD_WARNING_CONFIG_FAILED;
718e3744 6865
28c6e247
IR
6866 keepalive = strtoul(keep_str, NULL, 10);
6867 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6868
28c6e247 6869 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6870
28c6e247 6871 return bgp_vty_return(vty, ret);
718e3744 6872}
6b0655a2 6873
28c6e247 6874static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6875{
28c6e247
IR
6876 int ret;
6877 struct peer *peer;
718e3744 6878
28c6e247
IR
6879 peer = peer_and_group_lookup_vty(vty, ip_str);
6880 if (!peer)
d62a17ae 6881 return CMD_WARNING_CONFIG_FAILED;
718e3744 6882
28c6e247 6883 ret = peer_timers_unset(peer);
718e3744 6884
28c6e247 6885 return bgp_vty_return(vty, ret);
718e3744 6886}
6b0655a2 6887
28c6e247
IR
6888DEFUN (neighbor_timers,
6889 neighbor_timers_cmd,
6890 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
6891 NEIGHBOR_STR
6892 NEIGHBOR_ADDR_STR2
6893 "BGP per neighbor timers\n"
6894 "Keepalive interval\n"
6895 "Holdtime\n")
718e3744 6896{
f4b8ec07 6897 int idx_peer = 1;
28c6e247
IR
6898 int idx_number = 3;
6899 int idx_number_2 = 4;
6900 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6901 argv[idx_number]->arg,
6902 argv[idx_number_2]->arg);
6903}
6904
6905DEFUN (no_neighbor_timers,
6906 no_neighbor_timers_cmd,
6907 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
6908 NO_STR
6909 NEIGHBOR_STR
6910 NEIGHBOR_ADDR_STR2
6911 "BGP per neighbor timers\n"
6912 "Keepalive interval\n"
6913 "Holdtime\n")
6914{
6915 int idx_peer = 2;
6916 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
6917}
6918
6919
6920static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6921 const char *time_str)
6922{
6923 int ret;
6924 struct peer *peer;
6925 uint32_t connect;
718e3744 6926
28c6e247
IR
6927 peer = peer_and_group_lookup_vty(vty, ip_str);
6928 if (!peer)
d62a17ae 6929 return CMD_WARNING_CONFIG_FAILED;
718e3744 6930
28c6e247
IR
6931 connect = strtoul(time_str, NULL, 10);
6932
6933 ret = peer_timers_connect_set(peer, connect);
718e3744 6934
28c6e247 6935 return bgp_vty_return(vty, ret);
718e3744 6936}
6937
28c6e247 6938static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6939{
28c6e247
IR
6940 int ret;
6941 struct peer *peer;
718e3744 6942
28c6e247
IR
6943 peer = peer_and_group_lookup_vty(vty, ip_str);
6944 if (!peer)
d62a17ae 6945 return CMD_WARNING_CONFIG_FAILED;
718e3744 6946
28c6e247
IR
6947 ret = peer_timers_connect_unset(peer);
6948
6949 return bgp_vty_return(vty, ret);
6950}
6951
6952DEFUN (neighbor_timers_connect,
6953 neighbor_timers_connect_cmd,
6954 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
6955 NEIGHBOR_STR
6956 NEIGHBOR_ADDR_STR2
6957 "BGP per neighbor timers\n"
6958 "BGP connect timer\n"
6959 "Connect timer\n")
6960{
6961 int idx_peer = 1;
6962 int idx_number = 4;
6963 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6964 argv[idx_number]->arg);
6965}
718e3744 6966
28c6e247
IR
6967DEFUN (no_neighbor_timers_connect,
6968 no_neighbor_timers_connect_cmd,
6969 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
6970 NO_STR
6971 NEIGHBOR_STR
6972 NEIGHBOR_ADDR_STR2
6973 "BGP per neighbor timers\n"
6974 "BGP connect timer\n"
6975 "Connect timer\n")
6976{
6977 int idx_peer = 2;
6978 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6979}
6980
d43114f3
DS
6981DEFPY (neighbor_timers_delayopen,
6982 neighbor_timers_delayopen_cmd,
6983 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
6984 NEIGHBOR_STR
6985 NEIGHBOR_ADDR_STR2
6986 "BGP per neighbor timers\n"
6987 "RFC 4271 DelayOpenTimer\n"
6988 "DelayOpenTime timer interval\n")
6989{
6990 struct peer *peer;
6991
6992 peer = peer_and_group_lookup_vty(vty, neighbor);
6993 if (!peer)
6994 return CMD_WARNING_CONFIG_FAILED;
6995
6996 if (!interval) {
6997 if (peer_timers_delayopen_unset(peer))
6998 return CMD_WARNING_CONFIG_FAILED;
6999 } else {
7000 if (peer_timers_delayopen_set(peer, interval))
7001 return CMD_WARNING_CONFIG_FAILED;
7002 }
7003
7004 return CMD_SUCCESS;
7005}
7006
7007DEFPY (no_neighbor_timers_delayopen,
7008 no_neighbor_timers_delayopen_cmd,
7009 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7010 NO_STR
7011 NEIGHBOR_STR
7012 NEIGHBOR_ADDR_STR2
7013 "BGP per neighbor timers\n"
7014 "RFC 4271 DelayOpenTimer\n"
7015 "DelayOpenTime timer interval\n")
7016{
7017 struct peer *peer;
7018
7019 peer = peer_and_group_lookup_vty(vty, neighbor);
7020 if (!peer)
7021 return CMD_WARNING_CONFIG_FAILED;
7022
7023 if (peer_timers_delayopen_unset(peer))
7024 return CMD_WARNING_CONFIG_FAILED;
7025
7026 return CMD_SUCCESS;
7027}
7028
28c6e247
IR
7029static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
7030 const char *time_str, int set)
718e3744 7031{
28c6e247
IR
7032 int ret;
7033 struct peer *peer;
7034 uint32_t routeadv = 0;
718e3744 7035
28c6e247
IR
7036 peer = peer_and_group_lookup_vty(vty, ip_str);
7037 if (!peer)
d62a17ae 7038 return CMD_WARNING_CONFIG_FAILED;
718e3744 7039
28c6e247
IR
7040 if (time_str)
7041 routeadv = strtoul(time_str, NULL, 10);
7042
7043 if (set)
7044 ret = peer_advertise_interval_set(peer, routeadv);
7045 else
7046 ret = peer_advertise_interval_unset(peer);
718e3744 7047
28c6e247 7048 return bgp_vty_return(vty, ret);
718e3744 7049}
7050
28c6e247
IR
7051DEFUN (neighbor_advertise_interval,
7052 neighbor_advertise_interval_cmd,
7053 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7054 NEIGHBOR_STR
7055 NEIGHBOR_ADDR_STR2
7056 "Minimum interval between sending BGP routing updates\n"
7057 "time in seconds\n")
718e3744 7058{
28c6e247
IR
7059 int idx_peer = 1;
7060 int idx_number = 3;
7061 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
7062 argv[idx_number]->arg, 1);
7063}
f4b8ec07 7064
28c6e247
IR
7065DEFUN (no_neighbor_advertise_interval,
7066 no_neighbor_advertise_interval_cmd,
7067 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7068 NO_STR
7069 NEIGHBOR_STR
7070 NEIGHBOR_ADDR_STR2
7071 "Minimum interval between sending BGP routing updates\n"
7072 "time in seconds\n")
7073{
7074 int idx_peer = 2;
7075 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 7076}
7077
6b0655a2 7078
518f0eb1
DS
7079/* Time to wait before processing route-map updates */
7080DEFUN (bgp_set_route_map_delay_timer,
7081 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7082 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7083 SET_STR
7084 "BGP route-map delay timer\n"
7085 "Time in secs to wait before processing route-map changes\n"
f414725f 7086 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7087{
d62a17ae 7088 int idx_number = 3;
d7c0a89a 7089 uint32_t rmap_delay_timer;
d62a17ae 7090
7091 if (argv[idx_number]->arg) {
7092 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7093 bm->rmap_update_timer = rmap_delay_timer;
7094
7095 /* if the dynamic update handling is being disabled, and a timer
7096 * is
7097 * running, stop the timer and act as if the timer has already
7098 * fired.
7099 */
7100 if (!rmap_delay_timer && bm->t_rmap_update) {
7101 BGP_TIMER_OFF(bm->t_rmap_update);
7102 thread_execute(bm->master, bgp_route_map_update_timer,
7103 NULL, 0);
7104 }
7105 return CMD_SUCCESS;
7106 } else {
7107 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7108 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7109 }
518f0eb1
DS
7110}
7111
7112DEFUN (no_bgp_set_route_map_delay_timer,
7113 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7114 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7115 NO_STR
3a2d747c 7116 BGP_STR
518f0eb1 7117 "Default BGP route-map delay timer\n"
8334fd5a
DW
7118 "Reset to default time to wait for processing route-map changes\n"
7119 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7120{
518f0eb1 7121
d62a17ae 7122 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7123
d62a17ae 7124 return CMD_SUCCESS;
518f0eb1
DS
7125}
7126
28c6e247
IR
7127/* neighbor interface */
7128static int peer_interface_vty(struct vty *vty, const char *ip_str,
7129 const char *str)
718e3744 7130{
28c6e247 7131 struct peer *peer;
718e3744 7132
28c6e247
IR
7133 peer = peer_lookup_vty(vty, ip_str);
7134 if (!peer || peer->conf_if) {
7135 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
7136 return CMD_WARNING_CONFIG_FAILED;
7137 }
718e3744 7138
28c6e247
IR
7139 if (str)
7140 peer_interface_set(peer, str);
7141 else
7142 peer_interface_unset(peer);
718e3744 7143
28c6e247 7144 return CMD_SUCCESS;
718e3744 7145}
7146
28c6e247
IR
7147DEFUN (neighbor_interface,
7148 neighbor_interface_cmd,
7149 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7150 NEIGHBOR_STR
7151 NEIGHBOR_ADDR_STR
7152 "Interface\n"
7153 "Interface name\n")
718e3744 7154{
28c6e247
IR
7155 int idx_ip = 1;
7156 int idx_word = 3;
294d8425 7157
28c6e247
IR
7158 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
7159}
f4b8ec07 7160
28c6e247
IR
7161DEFUN (no_neighbor_interface,
7162 no_neighbor_interface_cmd,
294d8425 7163 "no neighbor <A.B.C.D|X:X::X:X> interface WORD",
28c6e247
IR
7164 NO_STR
7165 NEIGHBOR_STR
294d8425 7166 NEIGHBOR_ADDR_STR
28c6e247
IR
7167 "Interface\n"
7168 "Interface name\n")
7169{
7170 int idx_peer = 2;
294d8425 7171
28c6e247 7172 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 7173}
6b0655a2 7174
718e3744 7175DEFUN (neighbor_distribute_list,
7176 neighbor_distribute_list_cmd,
c60dec36 7177 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7178 NEIGHBOR_STR
7179 NEIGHBOR_ADDR_STR2
7180 "Filter updates to/from this neighbor\n"
718e3744 7181 "IP Access-list name\n"
7182 "Filter incoming updates\n"
7183 "Filter outgoing updates\n")
7184{
d62a17ae 7185 int idx_peer = 1;
7186 int idx_acl = 3;
7187 int direct, ret;
7188 struct peer *peer;
a8206004 7189
d62a17ae 7190 const char *pstr = argv[idx_peer]->arg;
7191 const char *acl = argv[idx_acl]->arg;
7192 const char *inout = argv[argc - 1]->text;
a8206004 7193
d62a17ae 7194 peer = peer_and_group_lookup_vty(vty, pstr);
7195 if (!peer)
7196 return CMD_WARNING_CONFIG_FAILED;
a8206004 7197
d62a17ae 7198 /* Check filter direction. */
7199 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7200 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7201 direct, acl);
a8206004 7202
d62a17ae 7203 return bgp_vty_return(vty, ret);
718e3744 7204}
7205
d62a17ae 7206ALIAS_HIDDEN(
7207 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
c60dec36 7208 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7210 "Filter updates to/from this neighbor\n"
d62a17ae 7211 "IP Access-list name\n"
7212 "Filter incoming updates\n"
7213 "Filter outgoing updates\n")
596c17ba 7214
718e3744 7215DEFUN (no_neighbor_distribute_list,
7216 no_neighbor_distribute_list_cmd,
c60dec36 7217 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
718e3744 7218 NO_STR
7219 NEIGHBOR_STR
7220 NEIGHBOR_ADDR_STR2
7221 "Filter updates to/from this neighbor\n"
718e3744 7222 "IP Access-list name\n"
7223 "Filter incoming updates\n"
7224 "Filter outgoing updates\n")
7225{
d62a17ae 7226 int idx_peer = 2;
7227 int direct, ret;
7228 struct peer *peer;
a8206004 7229
d62a17ae 7230 const char *pstr = argv[idx_peer]->arg;
7231 const char *inout = argv[argc - 1]->text;
a8206004 7232
d62a17ae 7233 peer = peer_and_group_lookup_vty(vty, pstr);
7234 if (!peer)
7235 return CMD_WARNING_CONFIG_FAILED;
a8206004 7236
d62a17ae 7237 /* Check filter direction. */
7238 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7239 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7240 direct);
a8206004 7241
d62a17ae 7242 return bgp_vty_return(vty, ret);
718e3744 7243}
6b0655a2 7244
d62a17ae 7245ALIAS_HIDDEN(
7246 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
c60dec36 7247 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list ACCESSLIST_NAME <in|out>",
d62a17ae 7248 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7249 "Filter updates to/from this neighbor\n"
d62a17ae 7250 "IP Access-list name\n"
7251 "Filter incoming updates\n"
7252 "Filter outgoing updates\n")
596c17ba 7253
718e3744 7254/* Set prefix list to the peer. */
642ef664
IR
7255static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
7256 afi_t afi, safi_t safi,
7257 const char *name_str,
7258 const char *direct_str)
718e3744 7259{
642ef664
IR
7260 int ret;
7261 int direct = FILTER_IN;
7262 struct peer *peer;
718e3744 7263
642ef664
IR
7264 peer = peer_and_group_lookup_vty(vty, ip_str);
7265 if (!peer)
d62a17ae 7266 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7267
642ef664
IR
7268 /* Check filter direction. */
7269 if (strncmp(direct_str, "i", 1) == 0)
7270 direct = FILTER_IN;
7271 else if (strncmp(direct_str, "o", 1) == 0)
7272 direct = FILTER_OUT;
718e3744 7273
642ef664 7274 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 7275
642ef664
IR
7276 return bgp_vty_return(vty, ret);
7277}
7278
7279static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
7280 afi_t afi, safi_t safi,
7281 const char *direct_str)
7282{
7283 int ret;
7284 struct peer *peer;
7285 int direct = FILTER_IN;
7286
7287 peer = peer_and_group_lookup_vty(vty, ip_str);
7288 if (!peer)
7289 return CMD_WARNING_CONFIG_FAILED;
7290
7291 /* Check filter direction. */
7292 if (strncmp(direct_str, "i", 1) == 0)
7293 direct = FILTER_IN;
7294 else if (strncmp(direct_str, "o", 1) == 0)
7295 direct = FILTER_OUT;
7296
7297 ret = peer_prefix_list_unset(peer, afi, safi, direct);
7298
7299 return bgp_vty_return(vty, ret);
7300}
7301
7302DEFUN (neighbor_prefix_list,
7303 neighbor_prefix_list_cmd,
7304 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "Filter updates to/from this neighbor\n"
7308 "Name of a prefix list\n"
7309 "Filter incoming updates\n"
7310 "Filter outgoing updates\n")
7311{
7312 int idx_peer = 1;
7313 int idx_word = 3;
7314 int idx_in_out = 4;
7315 return peer_prefix_list_set_vty(
7316 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7317 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7318}
7319
d62a17ae 7320ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7321 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7323 "Filter updates to/from this neighbor\n"
7324 "Name of a prefix list\n"
7325 "Filter incoming updates\n"
7326 "Filter outgoing updates\n")
596c17ba 7327
642ef664
IR
7328DEFUN (no_neighbor_prefix_list,
7329 no_neighbor_prefix_list_cmd,
7330 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7331 NO_STR
7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Filter updates to/from this neighbor\n"
7335 "Name of a prefix list\n"
7336 "Filter incoming updates\n"
7337 "Filter outgoing updates\n")
7338{
7339 int idx_peer = 2;
7340 int idx_in_out = 5;
7341 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
7342 bgp_node_afi(vty), bgp_node_safi(vty),
7343 argv[idx_in_out]->arg);
7344}
7345
7346ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
7347 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7348 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7349 "Filter updates to/from this neighbor\n"
7350 "Name of a prefix list\n"
7351 "Filter incoming updates\n"
7352 "Filter outgoing updates\n")
7353
d62a17ae 7354static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7355 safi_t safi, const char *name_str,
7356 const char *direct_str)
718e3744 7357{
d62a17ae 7358 int ret;
7359 struct peer *peer;
7360 int direct = FILTER_IN;
718e3744 7361
d62a17ae 7362 peer = peer_and_group_lookup_vty(vty, ip_str);
7363 if (!peer)
7364 return CMD_WARNING_CONFIG_FAILED;
718e3744 7365
d62a17ae 7366 /* Check filter direction. */
7367 if (strncmp(direct_str, "i", 1) == 0)
7368 direct = FILTER_IN;
7369 else if (strncmp(direct_str, "o", 1) == 0)
7370 direct = FILTER_OUT;
718e3744 7371
d62a17ae 7372 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7373
d62a17ae 7374 return bgp_vty_return(vty, ret);
718e3744 7375}
7376
d62a17ae 7377static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7378 safi_t safi, const char *direct_str)
718e3744 7379{
d62a17ae 7380 int ret;
7381 struct peer *peer;
7382 int direct = FILTER_IN;
718e3744 7383
d62a17ae 7384 peer = peer_and_group_lookup_vty(vty, ip_str);
7385 if (!peer)
7386 return CMD_WARNING_CONFIG_FAILED;
718e3744 7387
d62a17ae 7388 /* Check filter direction. */
7389 if (strncmp(direct_str, "i", 1) == 0)
7390 direct = FILTER_IN;
7391 else if (strncmp(direct_str, "o", 1) == 0)
7392 direct = FILTER_OUT;
718e3744 7393
d62a17ae 7394 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7395
d62a17ae 7396 return bgp_vty_return(vty, ret);
718e3744 7397}
7398
7399DEFUN (neighbor_filter_list,
7400 neighbor_filter_list_cmd,
de71d43e 7401 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7402 NEIGHBOR_STR
7403 NEIGHBOR_ADDR_STR2
7404 "Establish BGP filters\n"
7405 "AS path access-list name\n"
7406 "Filter incoming routes\n"
7407 "Filter outgoing routes\n")
7408{
d62a17ae 7409 int idx_peer = 1;
7410 int idx_word = 3;
7411 int idx_in_out = 4;
7412 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7413 bgp_node_safi(vty), argv[idx_word]->arg,
7414 argv[idx_in_out]->arg);
718e3744 7415}
7416
d62a17ae 7417ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
de71d43e 7418 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7420 "Establish BGP filters\n"
7421 "AS path access-list name\n"
7422 "Filter incoming routes\n"
7423 "Filter outgoing routes\n")
596c17ba 7424
718e3744 7425DEFUN (no_neighbor_filter_list,
7426 no_neighbor_filter_list_cmd,
de71d43e 7427 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
718e3744 7428 NO_STR
7429 NEIGHBOR_STR
7430 NEIGHBOR_ADDR_STR2
7431 "Establish BGP filters\n"
7432 "AS path access-list name\n"
7433 "Filter incoming routes\n"
7434 "Filter outgoing routes\n")
7435{
d62a17ae 7436 int idx_peer = 2;
7437 int idx_in_out = 5;
7438 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7439 bgp_node_afi(vty), bgp_node_safi(vty),
7440 argv[idx_in_out]->arg);
718e3744 7441}
6b0655a2 7442
d62a17ae 7443ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
de71d43e 7444 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list AS_PATH_FILTER_NAME <in|out>",
d62a17ae 7445 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7446 "Establish BGP filters\n"
7447 "AS path access-list name\n"
7448 "Filter incoming routes\n"
7449 "Filter outgoing routes\n")
596c17ba 7450
7f7940e6
MK
7451/* Set advertise-map to the peer. */
7452static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7453 afi_t afi, safi_t safi,
cf2ad4d8
MK
7454 const char *advertise_str,
7455 const char *condition_str, bool condition,
7456 bool set)
7f7940e6
MK
7457{
7458 int ret = CMD_WARNING_CONFIG_FAILED;
7459 struct peer *peer;
7460 struct route_map *advertise_map;
7461 struct route_map *condition_map;
7462
7463 peer = peer_and_group_lookup_vty(vty, ip_str);
7464 if (!peer)
7465 return ret;
7466
7467 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7468 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7469
cf2ad4d8
MK
7470 if (set)
7471 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7472 advertise_map, condition_str,
7473 condition_map, condition);
7474 else
7475 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7476 advertise_map, condition_str,
7477 condition_map, condition);
7f7940e6
MK
7478
7479 return bgp_vty_return(vty, ret);
7480}
7481
389e4f92
QY
7482DEFPY (bgp_condadv_period,
7483 bgp_condadv_period_cmd,
7484 "[no$no] bgp conditional-advertisement timer (5-240)$period",
7485 NO_STR
7486 BGP_STR
7487 "Conditional advertisement settings\n"
7488 "Set period to rescan BGP table to check if condition is met\n"
7489 "Period between BGP table scans, in seconds; default 60\n")
7490{
7491 VTY_DECLVAR_CONTEXT(bgp, bgp);
7492
7493 bgp->condition_check_period =
7494 no ? DEFAULT_CONDITIONAL_ROUTES_POLL_TIME : period;
7495
7496 return CMD_SUCCESS;
7497}
7498
cf2ad4d8 7499DEFPY (neighbor_advertise_map,
7f7940e6 7500 neighbor_advertise_map_cmd,
3ccddc25 7501 "[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 7502 NO_STR
7f7940e6
MK
7503 NEIGHBOR_STR
7504 NEIGHBOR_ADDR_STR2
7505 "Route-map to conditionally advertise routes\n"
7506 "Name of advertise map\n"
7507 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7508 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7509 "Name of the exist or non exist map\n")
7f7940e6 7510{
7f7940e6
MK
7511 bool condition = CONDITION_EXIST;
7512
52b84062 7513 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
7514 condition = CONDITION_NON_EXIST;
7515
52b84062
MK
7516 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7517 bgp_node_safi(vty), advertise_str,
7518 condition_str, condition, !no);
7f7940e6
MK
7519}
7520
7521ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
3ccddc25 7522 "[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
7523 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7524 "Route-map to conditionally advertise routes\n"
7525 "Name of advertise map\n"
7526 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 7527 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 7528 "Name of the exist or non exist map\n")
7f7940e6 7529
718e3744 7530/* Set route-map to the peer. */
0ea8d871
IR
7531static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7532 afi_t afi, safi_t safi, const char *name_str,
7533 const char *direct_str)
718e3744 7534{
0ea8d871
IR
7535 int ret;
7536 struct peer *peer;
7537 int direct = RMAP_IN;
7538 struct route_map *route_map;
718e3744 7539
0ea8d871
IR
7540 peer = peer_and_group_lookup_vty(vty, ip_str);
7541 if (!peer)
d62a17ae 7542 return CMD_WARNING_CONFIG_FAILED;
718e3744 7543
0ea8d871
IR
7544 /* Check filter direction. */
7545 if (strncmp(direct_str, "in", 2) == 0)
7546 direct = RMAP_IN;
7547 else if (strncmp(direct_str, "o", 1) == 0)
7548 direct = RMAP_OUT;
718e3744 7549
0ea8d871
IR
7550 route_map = route_map_lookup_warn_noexist(vty, name_str);
7551 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7552
0ea8d871
IR
7553 return bgp_vty_return(vty, ret);
7554}
7555
7556static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7557 afi_t afi, safi_t safi,
7558 const char *direct_str)
7559{
7560 int ret;
7561 struct peer *peer;
7562 int direct = RMAP_IN;
7563
7564 peer = peer_and_group_lookup_vty(vty, ip_str);
7565 if (!peer)
7566 return CMD_WARNING_CONFIG_FAILED;
7567
7568 /* Check filter direction. */
7569 if (strncmp(direct_str, "in", 2) == 0)
7570 direct = RMAP_IN;
7571 else if (strncmp(direct_str, "o", 1) == 0)
7572 direct = RMAP_OUT;
7573
7574 ret = peer_route_map_unset(peer, afi, safi, direct);
7575
7576 return bgp_vty_return(vty, ret);
7577}
7578
7579DEFUN (neighbor_route_map,
7580 neighbor_route_map_cmd,
7581 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7582 NEIGHBOR_STR
7583 NEIGHBOR_ADDR_STR2
7584 "Apply route map to neighbor\n"
7585 "Name of route map\n"
7586 "Apply map to incoming routes\n"
7587 "Apply map to outbound routes\n")
7588{
7589 int idx_peer = 1;
7590 int idx_word = 3;
7591 int idx_in_out = 4;
7592 return peer_route_map_set_vty(
7593 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7594 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7595}
7596
d6d7ed37
IR
7597ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7598 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7599 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7600 "Apply route map to neighbor\n"
7601 "Name of route map\n"
7602 "Apply map to incoming routes\n"
7603 "Apply map to outbound routes\n")
7604
0ea8d871
IR
7605DEFUN (no_neighbor_route_map,
7606 no_neighbor_route_map_cmd,
7607 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7608 NO_STR
7609 NEIGHBOR_STR
7610 NEIGHBOR_ADDR_STR2
7611 "Apply route map to neighbor\n"
7612 "Name of route map\n"
7613 "Apply map to incoming routes\n"
7614 "Apply map to outbound routes\n")
7615{
7616 int idx_peer = 2;
7617 int idx_in_out = 5;
7618 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7619 bgp_node_afi(vty), bgp_node_safi(vty),
7620 argv[idx_in_out]->arg);
7621}
7622
7623ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
d6d7ed37
IR
7624 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7625 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7626 "Apply route map to neighbor\n"
7627 "Name of route map\n"
7628 "Apply map to incoming routes\n"
7629 "Apply map to outbound routes\n")
7630
718e3744 7631/* Set unsuppress-map to the peer. */
d62a17ae 7632static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7633 afi_t afi, safi_t safi,
7634 const char *name_str)
718e3744 7635{
d62a17ae 7636 int ret;
7637 struct peer *peer;
1de27621 7638 struct route_map *route_map;
718e3744 7639
d62a17ae 7640 peer = peer_and_group_lookup_vty(vty, ip_str);
7641 if (!peer)
7642 return CMD_WARNING_CONFIG_FAILED;
718e3744 7643
1de27621
DA
7644 route_map = route_map_lookup_warn_noexist(vty, name_str);
7645 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7646
d62a17ae 7647 return bgp_vty_return(vty, ret);
718e3744 7648}
7649
7650/* Unset route-map from the peer. */
d62a17ae 7651static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7652 afi_t afi, safi_t safi)
718e3744 7653{
d62a17ae 7654 int ret;
7655 struct peer *peer;
718e3744 7656
d62a17ae 7657 peer = peer_and_group_lookup_vty(vty, ip_str);
7658 if (!peer)
7659 return CMD_WARNING_CONFIG_FAILED;
718e3744 7660
d62a17ae 7661 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7662
d62a17ae 7663 return bgp_vty_return(vty, ret);
718e3744 7664}
7665
7666DEFUN (neighbor_unsuppress_map,
7667 neighbor_unsuppress_map_cmd,
9ccf14f7 7668 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7669 NEIGHBOR_STR
7670 NEIGHBOR_ADDR_STR2
7671 "Route-map to selectively unsuppress suppressed routes\n"
7672 "Name of route map\n")
7673{
d62a17ae 7674 int idx_peer = 1;
7675 int idx_word = 3;
7676 return peer_unsuppress_map_set_vty(
7677 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7678 argv[idx_word]->arg);
718e3744 7679}
7680
d62a17ae 7681ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7682 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7684 "Route-map to selectively unsuppress suppressed routes\n"
7685 "Name of route map\n")
596c17ba 7686
718e3744 7687DEFUN (no_neighbor_unsuppress_map,
7688 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7689 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7690 NO_STR
7691 NEIGHBOR_STR
7692 NEIGHBOR_ADDR_STR2
7693 "Route-map to selectively unsuppress suppressed routes\n"
7694 "Name of route map\n")
7695{
d62a17ae 7696 int idx_peer = 2;
7697 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7698 bgp_node_afi(vty),
7699 bgp_node_safi(vty));
718e3744 7700}
6b0655a2 7701
d62a17ae 7702ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7703 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7704 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7705 "Route-map to selectively unsuppress suppressed routes\n"
7706 "Name of route map\n")
596c17ba 7707
7e62b792
IR
7708static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7709 afi_t afi, safi_t safi,
7710 const char *num_str,
7711 const char *threshold_str, int warning,
7712 const char *restart_str,
7713 const char *force_str)
7714{
7715 int ret;
7716 struct peer *peer;
7717 uint32_t max;
7718 uint8_t threshold;
7719 uint16_t restart;
7720
7721 peer = peer_and_group_lookup_vty(vty, ip_str);
7722 if (!peer)
7723 return CMD_WARNING_CONFIG_FAILED;
7724
7725 max = strtoul(num_str, NULL, 10);
7726 if (threshold_str)
7727 threshold = atoi(threshold_str);
7728 else
7729 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
7730
7731 if (restart_str)
7732 restart = atoi(restart_str);
7733 else
7734 restart = 0;
7735
7736 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
7737 restart, force_str ? true : false);
7738
7739 return bgp_vty_return(vty, ret);
7740}
7741
7742static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7743 afi_t afi, safi_t safi)
7744{
7745 int ret;
7746 struct peer *peer;
7747
7748 peer = peer_and_group_lookup_vty(vty, ip_str);
7749 if (!peer)
7750 return CMD_WARNING_CONFIG_FAILED;
7751
7752 ret = peer_maximum_prefix_unset(peer, afi, safi);
7753
7754 return bgp_vty_return(vty, ret);
7755}
7756
fde246e8 7757/* Maximum number of prefix to be sent to the neighbor. */
1d80f243
IR
7758DEFUN(neighbor_maximum_prefix_out,
7759 neighbor_maximum_prefix_out_cmd,
7760 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7761 NEIGHBOR_STR
7762 NEIGHBOR_ADDR_STR2
7763 "Maximum number of prefixes to be sent to this peer\n"
7764 "Maximum no. of prefix limit\n")
fde246e8 7765{
80444d30 7766 int ret;
fde246e8
DA
7767 int idx_peer = 1;
7768 int idx_number = 3;
7e62b792
IR
7769 struct peer *peer;
7770 uint32_t max;
fde246e8
DA
7771 afi_t afi = bgp_node_afi(vty);
7772 safi_t safi = bgp_node_safi(vty);
7773
7e62b792
IR
7774 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7775 if (!peer)
fde246e8
DA
7776 return CMD_WARNING_CONFIG_FAILED;
7777
7e62b792 7778 max = strtoul(argv[idx_number]->arg, NULL, 10);
fde246e8 7779
80444d30 7780 ret = peer_maximum_prefix_out_set(peer, afi, safi, max);
fde246e8 7781
80444d30 7782 return bgp_vty_return(vty, ret);
fde246e8
DA
7783}
7784
1d80f243
IR
7785DEFUN(no_neighbor_maximum_prefix_out,
7786 no_neighbor_maximum_prefix_out_cmd,
bc03c622 7787 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out [(1-4294967295)]",
1d80f243
IR
7788 NO_STR
7789 NEIGHBOR_STR
7790 NEIGHBOR_ADDR_STR2
bc03c622
LS
7791 "Maximum number of prefixes to be sent to this peer\n"
7792 "Maximum no. of prefix limit\n")
fde246e8 7793{
80444d30 7794 int ret;
fde246e8 7795 int idx_peer = 2;
7e62b792 7796 struct peer *peer;
fde246e8
DA
7797 afi_t afi = bgp_node_afi(vty);
7798 safi_t safi = bgp_node_safi(vty);
7799
7e62b792
IR
7800 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7801 if (!peer)
fde246e8
DA
7802 return CMD_WARNING_CONFIG_FAILED;
7803
80444d30 7804 ret = peer_maximum_prefix_out_unset(peer, afi, safi);
fde246e8 7805
80444d30 7806 return bgp_vty_return(vty, ret);
fde246e8
DA
7807}
7808
9cbd06e0
DA
7809/* Maximum number of prefix configuration. Prefix count is different
7810 for each peer configuration. So this configuration can be set for
718e3744 7811 each peer configuration. */
1d80f243
IR
7812DEFUN (neighbor_maximum_prefix,
7813 neighbor_maximum_prefix_cmd,
7814 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
7815 NEIGHBOR_STR
7816 NEIGHBOR_ADDR_STR2
7817 "Maximum number of prefix accept from this peer\n"
7818 "maximum no. of prefix limit\n"
7819 "Force checking all received routes not only accepted\n")
718e3744 7820{
d62a17ae 7821 int idx_peer = 1;
7822 int idx_number = 3;
9cbd06e0 7823 int idx_force = 0;
7e62b792 7824 char *force = NULL;
9cbd06e0
DA
7825
7826 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7827 force = argv[idx_force]->arg;
9cbd06e0 7828
7e62b792
IR
7829 return peer_maximum_prefix_set_vty(
7830 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7831 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7832}
7833
d62a17ae 7834ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7835 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7837 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7838 "maximum no. of prefix limit\n"
7839 "Force checking all received routes not only accepted\n")
596c17ba 7840
1d80f243
IR
7841DEFUN (neighbor_maximum_prefix_threshold,
7842 neighbor_maximum_prefix_threshold_cmd,
7843 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
7844 NEIGHBOR_STR
7845 NEIGHBOR_ADDR_STR2
7846 "Maximum number of prefix accept from this peer\n"
7847 "maximum no. of prefix limit\n"
7848 "Threshold value (%) at which to generate a warning msg\n"
7849 "Force checking all received routes not only accepted\n")
e0701b79 7850{
d62a17ae 7851 int idx_peer = 1;
7852 int idx_number = 3;
7853 int idx_number_2 = 4;
9cbd06e0 7854 int idx_force = 0;
7e62b792 7855 char *force = NULL;
9cbd06e0
DA
7856
7857 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7858 force = argv[idx_force]->arg;
9cbd06e0 7859
7e62b792
IR
7860 return peer_maximum_prefix_set_vty(
7861 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7862 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7863}
e0701b79 7864
d62a17ae 7865ALIAS_HIDDEN(
7866 neighbor_maximum_prefix_threshold,
7867 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7868 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7870 "Maximum number of prefix accept from this peer\n"
7871 "maximum no. of prefix limit\n"
9cbd06e0
DA
7872 "Threshold value (%) at which to generate a warning msg\n"
7873 "Force checking all received routes not only accepted\n")
596c17ba 7874
1d80f243
IR
7875DEFUN (neighbor_maximum_prefix_warning,
7876 neighbor_maximum_prefix_warning_cmd,
7877 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
7878 NEIGHBOR_STR
7879 NEIGHBOR_ADDR_STR2
7880 "Maximum number of prefix accept from this peer\n"
7881 "maximum no. of prefix limit\n"
7882 "Only give warning message when limit is exceeded\n"
7883 "Force checking all received routes not only accepted\n")
718e3744 7884{
d62a17ae 7885 int idx_peer = 1;
7886 int idx_number = 3;
9cbd06e0 7887 int idx_force = 0;
7e62b792 7888 char *force = NULL;
9cbd06e0
DA
7889
7890 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7891 force = argv[idx_force]->arg;
9cbd06e0 7892
7e62b792
IR
7893 return peer_maximum_prefix_set_vty(
7894 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7895 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7896}
7897
d62a17ae 7898ALIAS_HIDDEN(
7899 neighbor_maximum_prefix_warning,
7900 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7901 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7902 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7903 "Maximum number of prefix accept from this peer\n"
7904 "maximum no. of prefix limit\n"
9cbd06e0
DA
7905 "Only give warning message when limit is exceeded\n"
7906 "Force checking all received routes not only accepted\n")
596c17ba 7907
1d80f243
IR
7908DEFUN (neighbor_maximum_prefix_threshold_warning,
7909 neighbor_maximum_prefix_threshold_warning_cmd,
7910 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
7911 NEIGHBOR_STR
7912 NEIGHBOR_ADDR_STR2
7913 "Maximum number of prefix accept from this peer\n"
7914 "maximum no. of prefix limit\n"
7915 "Threshold value (%) at which to generate a warning msg\n"
7916 "Only give warning message when limit is exceeded\n"
7917 "Force checking all received routes not only accepted\n")
e0701b79 7918{
d62a17ae 7919 int idx_peer = 1;
7920 int idx_number = 3;
7921 int idx_number_2 = 4;
9cbd06e0 7922 int idx_force = 0;
7e62b792 7923 char *force = NULL;
9cbd06e0
DA
7924
7925 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7926 force = argv[idx_force]->arg;
9cbd06e0 7927
7e62b792
IR
7928 return peer_maximum_prefix_set_vty(
7929 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7930 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7931}
7932
d62a17ae 7933ALIAS_HIDDEN(
7934 neighbor_maximum_prefix_threshold_warning,
7935 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7936 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7937 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7938 "Maximum number of prefix accept from this peer\n"
7939 "maximum no. of prefix limit\n"
7940 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7941 "Only give warning message when limit is exceeded\n"
7942 "Force checking all received routes not only accepted\n")
596c17ba 7943
1d80f243
IR
7944DEFUN (neighbor_maximum_prefix_restart,
7945 neighbor_maximum_prefix_restart_cmd,
7946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
7947 NEIGHBOR_STR
7948 NEIGHBOR_ADDR_STR2
7949 "Maximum number of prefix accept from this peer\n"
7950 "maximum no. of prefix limit\n"
7951 "Restart bgp connection after limit is exceeded\n"
7952 "Restart interval in minutes\n"
7953 "Force checking all received routes not only accepted\n")
0a486e5f 7954{
d62a17ae 7955 int idx_peer = 1;
7956 int idx_number = 3;
7957 int idx_number_2 = 5;
9cbd06e0 7958 int idx_force = 0;
7e62b792 7959 char *force = NULL;
9cbd06e0
DA
7960
7961 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 7962 force = argv[idx_force]->arg;
9cbd06e0 7963
7e62b792
IR
7964 return peer_maximum_prefix_set_vty(
7965 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7966 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7967}
7968
d62a17ae 7969ALIAS_HIDDEN(
7970 neighbor_maximum_prefix_restart,
7971 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7974 "Maximum number of prefix accept from this peer\n"
7975 "maximum no. of prefix limit\n"
7976 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7977 "Restart interval in minutes\n"
7978 "Force checking all received routes not only accepted\n")
596c17ba 7979
1d80f243
IR
7980DEFUN (neighbor_maximum_prefix_threshold_restart,
7981 neighbor_maximum_prefix_threshold_restart_cmd,
7982 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
7983 NEIGHBOR_STR
7984 NEIGHBOR_ADDR_STR2
7985 "Maximum number of prefixes to accept from this peer\n"
7986 "maximum no. of prefix limit\n"
7987 "Threshold value (%) at which to generate a warning msg\n"
7988 "Restart bgp connection after limit is exceeded\n"
7989 "Restart interval in minutes\n"
7990 "Force checking all received routes not only accepted\n")
0a486e5f 7991{
d62a17ae 7992 int idx_peer = 1;
7993 int idx_number = 3;
7994 int idx_number_2 = 4;
7995 int idx_number_3 = 6;
9cbd06e0 7996 int idx_force = 0;
7e62b792 7997 char *force = NULL;
9cbd06e0
DA
7998
7999 if (argv_find(argv, argc, "force", &idx_force))
7e62b792 8000 force = argv[idx_force]->arg;
9cbd06e0 8001
7e62b792
IR
8002 return peer_maximum_prefix_set_vty(
8003 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8004 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
8005 argv[idx_number_3]->arg, force);
d62a17ae 8006}
8007
8008ALIAS_HIDDEN(
8009 neighbor_maximum_prefix_threshold_restart,
8010 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8011 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8012 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8013 "Maximum number of prefixes to accept from this peer\n"
8014 "maximum no. of prefix limit\n"
8015 "Threshold value (%) at which to generate a warning msg\n"
8016 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8017 "Restart interval in minutes\n"
8018 "Force checking all received routes not only accepted\n")
596c17ba 8019
1d80f243
IR
8020DEFUN (no_neighbor_maximum_prefix,
8021 no_neighbor_maximum_prefix_cmd,
8022 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8023 NO_STR
8024 NEIGHBOR_STR
8025 NEIGHBOR_ADDR_STR2
8026 "Maximum number of prefixes to accept from this peer\n"
8027 "maximum no. of prefix limit\n"
8028 "Threshold value (%) at which to generate a warning msg\n"
8029 "Restart bgp connection after limit is exceeded\n"
8030 "Restart interval in minutes\n"
8031 "Only give warning message when limit is exceeded\n"
8032 "Force checking all received routes not only accepted\n")
718e3744 8033{
d62a17ae 8034 int idx_peer = 2;
7e62b792
IR
8035 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
8036 bgp_node_afi(vty),
8037 bgp_node_safi(vty));
718e3744 8038}
e52702f2 8039
d62a17ae 8040ALIAS_HIDDEN(
8041 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8042 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8043 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8044 "Maximum number of prefixes to accept from this peer\n"
8045 "maximum no. of prefix limit\n"
8046 "Threshold value (%) at which to generate a warning msg\n"
8047 "Restart bgp connection after limit is exceeded\n"
8048 "Restart interval in minutes\n"
9cbd06e0
DA
8049 "Only give warning message when limit is exceeded\n"
8050 "Force checking all received routes not only accepted\n")
596c17ba 8051
718e3744 8052
718e3744 8053/* "neighbor allowas-in" */
8054DEFUN (neighbor_allowas_in,
8055 neighbor_allowas_in_cmd,
fd8503f5 8056 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8057 NEIGHBOR_STR
8058 NEIGHBOR_ADDR_STR2
31500417 8059 "Accept as-path with my AS present in it\n"
f79f7a7b 8060 "Number of occurrences of AS number\n"
fd8503f5 8061 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8062{
d62a17ae 8063 int idx_peer = 1;
8064 int idx_number_origin = 3;
8065 int ret;
8066 int origin = 0;
8067 struct peer *peer;
8068 int allow_num = 0;
8069
8070 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8071 if (!peer)
8072 return CMD_WARNING_CONFIG_FAILED;
8073
8074 if (argc <= idx_number_origin)
8075 allow_num = 3;
8076 else {
8077 if (argv[idx_number_origin]->type == WORD_TKN)
8078 origin = 1;
8079 else
8080 allow_num = atoi(argv[idx_number_origin]->arg);
8081 }
8082
8083 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8084 allow_num, origin);
8085
8086 return bgp_vty_return(vty, ret);
8087}
8088
8089ALIAS_HIDDEN(
8090 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8091 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8093 "Accept as-path with my AS present in it\n"
f79f7a7b 8094 "Number of occurrences of AS number\n"
d62a17ae 8095 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8096
718e3744 8097DEFUN (no_neighbor_allowas_in,
8098 no_neighbor_allowas_in_cmd,
fd8503f5 8099 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8100 NO_STR
8101 NEIGHBOR_STR
8102 NEIGHBOR_ADDR_STR2
8334fd5a 8103 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8104 "Number of occurrences of AS number\n"
fd8503f5 8105 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8106{
d62a17ae 8107 int idx_peer = 2;
8108 int ret;
8109 struct peer *peer;
718e3744 8110
d62a17ae 8111 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8112 if (!peer)
8113 return CMD_WARNING_CONFIG_FAILED;
718e3744 8114
d62a17ae 8115 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8116 bgp_node_safi(vty));
718e3744 8117
d62a17ae 8118 return bgp_vty_return(vty, ret);
718e3744 8119}
6b0655a2 8120
d62a17ae 8121ALIAS_HIDDEN(
8122 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8123 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8124 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8125 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8126 "Number of occurrences of AS number\n"
d62a17ae 8127 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8128
28c6e247
IR
8129DEFUN (neighbor_ttl_security,
8130 neighbor_ttl_security_cmd,
8131 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8132 NEIGHBOR_STR
8133 NEIGHBOR_ADDR_STR2
8134 "BGP ttl-security parameters\n"
8135 "Specify the maximum number of hops to the BGP peer\n"
8136 "Number of hops to BGP peer\n")
fa411a21 8137{
d62a17ae 8138 int idx_peer = 1;
8139 int idx_number = 4;
28c6e247
IR
8140 struct peer *peer;
8141 int gtsm_hops;
d62a17ae 8142
28c6e247
IR
8143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8144 if (!peer)
d62a17ae 8145 return CMD_WARNING_CONFIG_FAILED;
8146
28c6e247
IR
8147 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
8148
8149 /*
8150 * If 'neighbor swpX', then this is for directly connected peers,
8151 * we should not accept a ttl-security hops value greater than 1.
8152 */
8153 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
8154 vty_out(vty,
8155 "%s is directly connected peer, hops cannot exceed 1\n",
8156 argv[idx_peer]->arg);
8157 return CMD_WARNING_CONFIG_FAILED;
8158 }
7ebe625c 8159
28c6e247 8160 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
8161}
8162
1d80f243
IR
8163DEFUN (no_neighbor_ttl_security,
8164 no_neighbor_ttl_security_cmd,
8165 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8166 NO_STR
8167 NEIGHBOR_STR
8168 NEIGHBOR_ADDR_STR2
8169 "BGP ttl-security parameters\n"
8170 "Specify the maximum number of hops to the BGP peer\n"
8171 "Number of hops to BGP peer\n")
fa411a21 8172{
d62a17ae 8173 int idx_peer = 2;
28c6e247 8174 struct peer *peer;
fa411a21 8175
28c6e247
IR
8176 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8177 if (!peer)
d62a17ae 8178 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8179
28c6e247 8180 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 8181}
6b0655a2 8182
7c0e4312
DA
8183/* disable-addpath-rx */
8184DEFUN(neighbor_disable_addpath_rx,
8185 neighbor_disable_addpath_rx_cmd,
8186 "neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8187 NEIGHBOR_STR
8188 NEIGHBOR_ADDR_STR2
8189 "Do not accept additional paths\n")
8190{
8191 char *peer_str = argv[1]->arg;
8192 struct peer *peer;
8193 afi_t afi = bgp_node_afi(vty);
8194 safi_t safi = bgp_node_safi(vty);
8195
8196 peer = peer_and_group_lookup_vty(vty, peer_str);
8197 if (!peer)
8198 return CMD_WARNING_CONFIG_FAILED;
8199
8200 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
8201 PEER_FLAG_DISABLE_ADDPATH_RX);
8202}
8203
8204DEFUN(no_neighbor_disable_addpath_rx,
8205 no_neighbor_disable_addpath_rx_cmd,
8206 "no neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx",
8207 NO_STR
8208 NEIGHBOR_STR
8209 NEIGHBOR_ADDR_STR2
8210 "Do not accept additional paths\n")
8211{
8212 char *peer_str = argv[2]->arg;
8213 struct peer *peer;
8214 afi_t afi = bgp_node_afi(vty);
8215 safi_t safi = bgp_node_safi(vty);
8216
8217 peer = peer_and_group_lookup_vty(vty, peer_str);
8218 if (!peer)
8219 return CMD_WARNING_CONFIG_FAILED;
8220
8221 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
8222 PEER_FLAG_DISABLE_ADDPATH_RX);
8223}
8224
adbac85e
DW
8225DEFUN (neighbor_addpath_tx_all_paths,
8226 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8227 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8228 NEIGHBOR_STR
8229 NEIGHBOR_ADDR_STR2
8230 "Use addpath to advertise all paths to a neighbor\n")
8231{
d62a17ae 8232 int idx_peer = 1;
8233 struct peer *peer;
adbac85e 8234
d62a17ae 8235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8236 if (!peer)
8237 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8238
dcc68b5e
MS
8239 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8240 BGP_ADDPATH_ALL);
8241 return CMD_SUCCESS;
adbac85e
DW
8242}
8243
d62a17ae 8244ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8245 neighbor_addpath_tx_all_paths_hidden_cmd,
8246 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8247 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8248 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8249
adbac85e
DW
8250DEFUN (no_neighbor_addpath_tx_all_paths,
8251 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8252 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8253 NO_STR
8254 NEIGHBOR_STR
8255 NEIGHBOR_ADDR_STR2
8256 "Use addpath to advertise all paths to a neighbor\n")
8257{
d62a17ae 8258 int idx_peer = 2;
dcc68b5e
MS
8259 struct peer *peer;
8260
8261 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8262 if (!peer)
8263 return CMD_WARNING_CONFIG_FAILED;
8264
8265 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8266 != BGP_ADDPATH_ALL) {
8267 vty_out(vty,
8268 "%% Peer not currently configured to transmit all paths.");
8269 return CMD_WARNING_CONFIG_FAILED;
8270 }
8271
8272 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8273 BGP_ADDPATH_NONE);
8274
8275 return CMD_SUCCESS;
adbac85e
DW
8276}
8277
d62a17ae 8278ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8279 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8280 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8281 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8282 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8283
06370dac
DW
8284DEFUN (neighbor_addpath_tx_bestpath_per_as,
8285 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8286 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8287 NEIGHBOR_STR
8288 NEIGHBOR_ADDR_STR2
8289 "Use addpath to advertise the bestpath per each neighboring AS\n")
8290{
d62a17ae 8291 int idx_peer = 1;
8292 struct peer *peer;
06370dac 8293
d62a17ae 8294 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8295 if (!peer)
8296 return CMD_WARNING_CONFIG_FAILED;
06370dac 8297
dcc68b5e
MS
8298 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8299 BGP_ADDPATH_BEST_PER_AS);
8300
8301 return CMD_SUCCESS;
06370dac
DW
8302}
8303
d62a17ae 8304ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8305 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8306 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8308 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8309
06370dac
DW
8310DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8311 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8312 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8313 NO_STR
8314 NEIGHBOR_STR
8315 NEIGHBOR_ADDR_STR2
8316 "Use addpath to advertise the bestpath per each neighboring AS\n")
8317{
d62a17ae 8318 int idx_peer = 2;
dcc68b5e
MS
8319 struct peer *peer;
8320
8321 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8322 if (!peer)
8323 return CMD_WARNING_CONFIG_FAILED;
8324
8325 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8326 != BGP_ADDPATH_BEST_PER_AS) {
8327 vty_out(vty,
8328 "%% Peer not currently configured to transmit all best path per as.");
8329 return CMD_WARNING_CONFIG_FAILED;
8330 }
8331
8332 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8333 BGP_ADDPATH_NONE);
8334
8335 return CMD_SUCCESS;
06370dac
DW
8336}
8337
d62a17ae 8338ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8339 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8340 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8341 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8342 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8343
2b31007c
RZ
8344DEFPY(
8345 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8346 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8347 NEIGHBOR_STR
8348 NEIGHBOR_ADDR_STR2
8349 "Detect AS loops before sending to neighbor\n")
8350{
8351 struct peer *peer;
8352
8353 peer = peer_and_group_lookup_vty(vty, neighbor);
8354 if (!peer)
8355 return CMD_WARNING_CONFIG_FAILED;
8356
8357 peer->as_path_loop_detection = true;
8358
8359 return CMD_SUCCESS;
8360}
8361
8362DEFPY(
8363 no_neighbor_aspath_loop_detection,
8364 no_neighbor_aspath_loop_detection_cmd,
8365 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8366 NO_STR
8367 NEIGHBOR_STR
8368 NEIGHBOR_ADDR_STR2
8369 "Detect AS loops before sending to neighbor\n")
8370{
8371 struct peer *peer;
8372
8373 peer = peer_and_group_lookup_vty(vty, neighbor);
8374 if (!peer)
8375 return CMD_WARNING_CONFIG_FAILED;
8376
8377 peer->as_path_loop_detection = false;
8378
8379 return CMD_SUCCESS;
8380}
8381
b9c7bc5a 8382static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8383 struct ecommunity **list, bool is_rt6)
ddb5b488 8384{
b9c7bc5a
PZ
8385 struct ecommunity *ecom = NULL;
8386 struct ecommunity *ecomadd;
ddb5b488 8387
b9c7bc5a 8388 for (; argc; --argc, ++argv) {
9a659715
PG
8389 if (is_rt6)
8390 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8391 ECOMMUNITY_ROUTE_TARGET,
8392 0);
8393 else
8394 ecomadd = ecommunity_str2com(argv[0]->arg,
8395 ECOMMUNITY_ROUTE_TARGET,
8396 0);
b9c7bc5a
PZ
8397 if (!ecomadd) {
8398 vty_out(vty, "Malformed community-list value\n");
8399 if (ecom)
8400 ecommunity_free(&ecom);
8401 return CMD_WARNING_CONFIG_FAILED;
8402 }
ddb5b488 8403
b9c7bc5a
PZ
8404 if (ecom) {
8405 ecommunity_merge(ecom, ecomadd);
8406 ecommunity_free(&ecomadd);
8407 } else {
8408 ecom = ecomadd;
8409 }
8410 }
8411
8412 if (*list) {
8413 ecommunity_free(&*list);
ddb5b488 8414 }
b9c7bc5a
PZ
8415 *list = ecom;
8416
8417 return CMD_SUCCESS;
ddb5b488
PZ
8418}
8419
0ca70ba5
DS
8420/*
8421 * v2vimport is true if we are handling a `import vrf ...` command
8422 */
8423static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 8424{
0ca70ba5
DS
8425 afi_t afi;
8426
ddb5b488 8427 switch (vty->node) {
b9c7bc5a 8428 case BGP_IPV4_NODE:
0ca70ba5
DS
8429 afi = AFI_IP;
8430 break;
b9c7bc5a 8431 case BGP_IPV6_NODE:
0ca70ba5
DS
8432 afi = AFI_IP6;
8433 break;
ddb5b488
PZ
8434 default:
8435 vty_out(vty,
b9c7bc5a 8436 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 8437 return AFI_MAX;
ddb5b488 8438 }
69b07479 8439
0ca70ba5
DS
8440 if (!v2vimport) {
8441 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8442 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8443 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8444 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8445 vty_out(vty,
8446 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
8447 return AFI_MAX;
8448 }
8449 } else {
8450 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8451 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8452 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8453 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8454 vty_out(vty,
8455 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
8456 return AFI_MAX;
8457 }
8458 }
8459 return afi;
ddb5b488
PZ
8460}
8461
585f1adc
IR
8462DEFPY (af_rd_vpn_export,
8463 af_rd_vpn_export_cmd,
8464 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
8465 NO_STR
8466 "Specify route distinguisher\n"
8467 "Between current address-family and vpn\n"
8468 "For routes leaked from current address-family to vpn\n"
8469 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 8470{
585f1adc
IR
8471 VTY_DECLVAR_CONTEXT(bgp, bgp);
8472 struct prefix_rd prd;
8473 int ret;
ddb5b488 8474 afi_t afi;
b9c7bc5a 8475 int idx = 0;
585f1adc 8476 bool yes = true;
b9c7bc5a 8477
585f1adc
IR
8478 if (argv_find(argv, argc, "no", &idx))
8479 yes = false;
ddb5b488 8480
585f1adc
IR
8481 if (yes) {
8482 ret = str2prefix_rd(rd_str, &prd);
8483 if (!ret) {
8484 vty_out(vty, "%% Malformed rd\n");
8485 return CMD_WARNING_CONFIG_FAILED;
8486 }
8487 }
ddb5b488 8488
585f1adc
IR
8489 afi = vpn_policy_getafi(vty, bgp, false);
8490 if (afi == AFI_MAX)
8491 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8492
585f1adc
IR
8493 /*
8494 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8495 */
8496 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8497 bgp_get_default(), bgp);
ddb5b488 8498
585f1adc
IR
8499 if (yes) {
8500 bgp->vpn_policy[afi].tovpn_rd = prd;
8501 SET_FLAG(bgp->vpn_policy[afi].flags,
8502 BGP_VPN_POLICY_TOVPN_RD_SET);
8503 } else {
8504 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8505 BGP_VPN_POLICY_TOVPN_RD_SET);
8506 }
69b07479 8507
585f1adc
IR
8508 /* post-change: re-export vpn routes */
8509 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8510 bgp_get_default(), bgp);
8511
8512 return CMD_SUCCESS;
ddb5b488
PZ
8513}
8514
b9c7bc5a
PZ
8515ALIAS (af_rd_vpn_export,
8516 af_no_rd_vpn_export_cmd,
8517 "no rd vpn export",
ddb5b488 8518 NO_STR
b9c7bc5a
PZ
8519 "Specify route distinguisher\n"
8520 "Between current address-family and vpn\n"
8521 "For routes leaked from current address-family to vpn\n")
ddb5b488 8522
b9c7bc5a
PZ
8523DEFPY (af_label_vpn_export,
8524 af_label_vpn_export_cmd,
e70e9f8e 8525 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8526 NO_STR
ddb5b488 8527 "label value for VRF\n"
b9c7bc5a
PZ
8528 "Between current address-family and vpn\n"
8529 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8530 "Label Value <0-1048575>\n"
8531 "Automatically assign a label\n")
ddb5b488
PZ
8532{
8533 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8534 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8535 afi_t afi;
b9c7bc5a 8536 int idx = 0;
c6423c31 8537 bool yes = true;
b9c7bc5a
PZ
8538
8539 if (argv_find(argv, argc, "no", &idx))
c6423c31 8540 yes = false;
ddb5b488 8541
21a16cc2
PZ
8542 /* If "no ...", squash trailing parameter */
8543 if (!yes)
8544 label_auto = NULL;
8545
e70e9f8e
PZ
8546 if (yes) {
8547 if (!label_auto)
8548 label = label_val; /* parser should force unsigned */
8549 }
ddb5b488 8550
0ca70ba5 8551 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8552 if (afi == AFI_MAX)
8553 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8554
e70e9f8e 8555
69b07479
DS
8556 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8557 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8558 /* no change */
8559 return CMD_SUCCESS;
e70e9f8e 8560
69b07479
DS
8561 /*
8562 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8563 */
8564 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8565 bgp_get_default(), bgp);
8566
8567 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8568 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8569
8570 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8571
8572 /*
8573 * label has previously been automatically
8574 * assigned by labelpool: release it
8575 *
8576 * NB if tovpn_label == MPLS_LABEL_NONE it
8577 * means the automatic assignment is in flight
8578 * and therefore the labelpool callback must
8579 * detect that the auto label is not needed.
8580 */
8581
8582 bgp_lp_release(LP_TYPE_VRF,
8583 &bgp->vpn_policy[afi],
8584 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8585 }
69b07479
DS
8586 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8587 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8588 }
ddb5b488 8589
69b07479
DS
8590 bgp->vpn_policy[afi].tovpn_label = label;
8591 if (label_auto) {
8592 SET_FLAG(bgp->vpn_policy[afi].flags,
8593 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8594 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8595 vpn_leak_label_callback);
ddb5b488
PZ
8596 }
8597
69b07479
DS
8598 /* post-change: re-export vpn routes */
8599 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8600 bgp_get_default(), bgp);
8601
0d020cd6 8602 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
8603 return CMD_SUCCESS;
8604}
8605
b72c9e14
HS
8606DEFPY (af_sid_vpn_export,
8607 af_sid_vpn_export_cmd,
8608 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
8609 NO_STR
8610 "sid value for VRF\n"
8611 "Between current address-family and vpn\n"
8612 "For routes leaked from current address-family to vpn\n"
8613 "Sid allocation index\n"
8614 "Automatically assign a label\n")
8615{
8616 VTY_DECLVAR_CONTEXT(bgp, bgp);
8617 afi_t afi;
8618 int debug = 0;
8619 int idx = 0;
8620 bool yes = true;
8621
8622 if (argv_find(argv, argc, "no", &idx))
8623 yes = false;
8624 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
8625 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
8626
8627 afi = vpn_policy_getafi(vty, bgp, false);
8628 if (afi == AFI_MAX)
8629 return CMD_WARNING_CONFIG_FAILED;
8630
8631 if (!yes) {
8632 /* implement me */
4d4c404b 8633 vty_out(vty, "It's not implemented\n");
b72c9e14
HS
8634 return CMD_WARNING_CONFIG_FAILED;
8635 }
8636
8637 /* skip when it's already configured */
8638 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8639 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8640 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
8641 return CMD_SUCCESS;
8642
7de4c885
HS
8643 /*
8644 * mode change between sid_idx and sid_auto isn't supported.
8645 * user must negate sid vpn export when they want to change the mode
8646 */
b72c9e14
HS
8647 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
8648 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8649 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
8650 vty_out(vty, "it's already configured as %s.\n",
8651 sid_auto ? "auto-mode" : "idx-mode");
8652 return CMD_WARNING_CONFIG_FAILED;
8653 }
8654
8655 /* pre-change */
8656 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8657 bgp_get_default(), bgp);
8658
8659 if (sid_auto) {
8660 /* SID allocation auto-mode */
8661 if (debug)
8662 zlog_debug("%s: auto sid alloc.", __func__);
8663 SET_FLAG(bgp->vpn_policy[afi].flags,
8664 BGP_VPN_POLICY_TOVPN_SID_AUTO);
8665 } else {
8666 /* SID allocation index-mode */
8667 if (debug)
8668 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
8669 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
8670 }
8671
8672 /* post-change */
8673 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8674 bgp_get_default(), bgp);
8675 return CMD_SUCCESS;
8676}
8677
b9c7bc5a
PZ
8678ALIAS (af_label_vpn_export,
8679 af_no_label_vpn_export_cmd,
8680 "no label vpn export",
8681 NO_STR
8682 "label value for VRF\n"
8683 "Between current address-family and vpn\n"
8684 "For routes leaked from current address-family to vpn\n")
ddb5b488 8685
585f1adc 8686DEFPY (af_nexthop_vpn_export,
b9c7bc5a 8687 af_nexthop_vpn_export_cmd,
8c85ca28 8688 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8689 NO_STR
ddb5b488 8690 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8691 "Between current address-family and vpn\n"
8692 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8693 "IPv4 prefix\n"
8694 "IPv6 prefix\n")
8695{
585f1adc 8696 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8697 afi_t afi;
ddb5b488
PZ
8698 struct prefix p;
8699
8c85ca28
QY
8700 if (!no) {
8701 if (!nexthop_su) {
8702 vty_out(vty, "%% Nexthop required\n");
8703 return CMD_WARNING_CONFIG_FAILED;
8704 }
8c85ca28 8705 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8706 return CMD_WARNING_CONFIG_FAILED;
8707 }
ddb5b488 8708
585f1adc
IR
8709 afi = vpn_policy_getafi(vty, bgp, false);
8710 if (afi == AFI_MAX)
8711 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8712
585f1adc
IR
8713 /*
8714 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8715 */
8716 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8717 bgp_get_default(), bgp);
ddb5b488 8718
585f1adc
IR
8719 if (!no) {
8720 bgp->vpn_policy[afi].tovpn_nexthop = p;
8721 SET_FLAG(bgp->vpn_policy[afi].flags,
8722 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8723 } else {
8724 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8725 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8726 }
69b07479 8727
585f1adc
IR
8728 /* post-change: re-export vpn routes */
8729 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8730 bgp_get_default(), bgp);
37a87b8f 8731
585f1adc 8732 return CMD_SUCCESS;
ddb5b488
PZ
8733}
8734
b9c7bc5a 8735static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8736{
b9c7bc5a
PZ
8737 if (!strcmp(dstr, "import")) {
8738 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8739 } else if (!strcmp(dstr, "export")) {
8740 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8741 } else if (!strcmp(dstr, "both")) {
8742 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8743 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8744 } else {
8745 vty_out(vty, "%% direction parse error\n");
8746 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8747 }
ddb5b488
PZ
8748 return CMD_SUCCESS;
8749}
8750
b9c7bc5a
PZ
8751DEFPY (af_rt_vpn_imexport,
8752 af_rt_vpn_imexport_cmd,
8753 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8754 NO_STR
8755 "Specify route target list\n"
ddb5b488 8756 "Specify route target list\n"
b9c7bc5a
PZ
8757 "Between current address-family and vpn\n"
8758 "For routes leaked from vpn to current address-family: match any\n"
8759 "For routes leaked from current address-family to vpn: set\n"
8760 "both import: match any and export: set\n"
ddb5b488
PZ
8761 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8762{
8763 VTY_DECLVAR_CONTEXT(bgp, bgp);
8764 int ret;
8765 struct ecommunity *ecom = NULL;
8766 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 8767 enum vpn_policy_direction dir;
ddb5b488
PZ
8768 afi_t afi;
8769 int idx = 0;
c6423c31 8770 bool yes = true;
ddb5b488 8771
b9c7bc5a 8772 if (argv_find(argv, argc, "no", &idx))
c6423c31 8773 yes = false;
b9c7bc5a 8774
0ca70ba5 8775 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8776 if (afi == AFI_MAX)
8777 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8778
b9c7bc5a 8779 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8780 if (ret != CMD_SUCCESS)
8781 return ret;
8782
b9c7bc5a
PZ
8783 if (yes) {
8784 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8785 vty_out(vty, "%% Missing RTLIST\n");
8786 return CMD_WARNING_CONFIG_FAILED;
8787 }
c6423c31 8788 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8789 if (ret != CMD_SUCCESS) {
8790 return ret;
8791 }
ddb5b488
PZ
8792 }
8793
69b07479
DS
8794 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8795 if (!dodir[dir])
ddb5b488 8796 continue;
ddb5b488 8797
69b07479 8798 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8799
69b07479
DS
8800 if (yes) {
8801 if (bgp->vpn_policy[afi].rtlist[dir])
8802 ecommunity_free(
8803 &bgp->vpn_policy[afi].rtlist[dir]);
8804 bgp->vpn_policy[afi].rtlist[dir] =
8805 ecommunity_dup(ecom);
8806 } else {
8807 if (bgp->vpn_policy[afi].rtlist[dir])
8808 ecommunity_free(
8809 &bgp->vpn_policy[afi].rtlist[dir]);
8810 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8811 }
69b07479
DS
8812
8813 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8814 }
69b07479 8815
d555f3e9
PZ
8816 if (ecom)
8817 ecommunity_free(&ecom);
ddb5b488
PZ
8818
8819 return CMD_SUCCESS;
8820}
8821
b9c7bc5a
PZ
8822ALIAS (af_rt_vpn_imexport,
8823 af_no_rt_vpn_imexport_cmd,
8824 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8825 NO_STR
8826 "Specify route target list\n"
b9c7bc5a
PZ
8827 "Specify route target list\n"
8828 "Between current address-family and vpn\n"
8829 "For routes leaked from vpn to current address-family\n"
8830 "For routes leaked from current address-family to vpn\n"
8831 "both import and export\n")
8832
585f1adc 8833DEFPY (af_route_map_vpn_imexport,
b9c7bc5a
PZ
8834 af_route_map_vpn_imexport_cmd,
8835/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8836 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8837 NO_STR
ddb5b488 8838 "Specify route map\n"
b9c7bc5a
PZ
8839 "Between current address-family and vpn\n"
8840 "For routes leaked from vpn to current address-family\n"
8841 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8842 "name of route-map\n")
8843{
585f1adc
IR
8844 VTY_DECLVAR_CONTEXT(bgp, bgp);
8845 int ret;
8846 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9c2fd3fe 8847 enum vpn_policy_direction dir;
ddb5b488 8848 afi_t afi;
ddb5b488 8849 int idx = 0;
585f1adc 8850 bool yes = true;
ddb5b488 8851
585f1adc
IR
8852 if (argv_find(argv, argc, "no", &idx))
8853 yes = false;
ddb5b488 8854
585f1adc
IR
8855 afi = vpn_policy_getafi(vty, bgp, false);
8856 if (afi == AFI_MAX)
8857 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8858
585f1adc
IR
8859 ret = vpn_policy_getdirs(vty, direction_str, dodir);
8860 if (ret != CMD_SUCCESS)
8861 return ret;
ddb5b488 8862
585f1adc
IR
8863 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8864 if (!dodir[dir])
8865 continue;
69b07479 8866
585f1adc
IR
8867 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8868
8869 if (yes) {
8870 if (bgp->vpn_policy[afi].rmap_name[dir])
8871 XFREE(MTYPE_ROUTE_MAP_NAME,
8872 bgp->vpn_policy[afi].rmap_name[dir]);
8873 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8874 MTYPE_ROUTE_MAP_NAME, rmap_str);
8875 bgp->vpn_policy[afi].rmap[dir] =
8876 route_map_lookup_warn_noexist(vty, rmap_str);
8877 if (!bgp->vpn_policy[afi].rmap[dir])
8878 return CMD_SUCCESS;
8879 } else {
8880 if (bgp->vpn_policy[afi].rmap_name[dir])
8881 XFREE(MTYPE_ROUTE_MAP_NAME,
8882 bgp->vpn_policy[afi].rmap_name[dir]);
8883 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8884 bgp->vpn_policy[afi].rmap[dir] = NULL;
8885 }
8886
8887 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8888 }
ddb5b488 8889
585f1adc 8890 return CMD_SUCCESS;
ddb5b488
PZ
8891}
8892
b9c7bc5a
PZ
8893ALIAS (af_route_map_vpn_imexport,
8894 af_no_route_map_vpn_imexport_cmd,
8895 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8896 NO_STR
8897 "Specify route map\n"
b9c7bc5a
PZ
8898 "Between current address-family and vpn\n"
8899 "For routes leaked from vpn to current address-family\n"
8900 "For routes leaked from current address-family to vpn\n")
8901
bb4f6190 8902DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8903 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8904 "Import routes from another VRF\n"
8905 "Vrf routes being filtered\n"
8906 "Specify route map\n"
8907 "name of route-map\n")
8908{
8909 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 8910 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
bb4f6190 8911 afi_t afi;
bb4f6190
DS
8912 struct bgp *bgp_default;
8913
0ca70ba5 8914 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8915 if (afi == AFI_MAX)
8916 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8917
8918 bgp_default = bgp_get_default();
8919 if (!bgp_default) {
8920 int32_t ret;
8921 as_t as = bgp->as;
8922
8923 /* Auto-create assuming the same AS */
5d5393b9
DL
8924 ret = bgp_get_vty(&bgp_default, &as, NULL,
8925 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8926
8927 if (ret) {
8928 vty_out(vty,
8929 "VRF default is not configured as a bgp instance\n");
8930 return CMD_WARNING;
8931 }
8932 }
8933
69b07479 8934 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8935
ae6a6fb4
DS
8936 if (bgp->vpn_policy[afi].rmap_name[dir])
8937 XFREE(MTYPE_ROUTE_MAP_NAME,
8938 bgp->vpn_policy[afi].rmap_name[dir]);
8939 bgp->vpn_policy[afi].rmap_name[dir] =
8940 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8941 bgp->vpn_policy[afi].rmap[dir] =
8942 route_map_lookup_warn_noexist(vty, rmap_str);
8943 if (!bgp->vpn_policy[afi].rmap[dir])
8944 return CMD_SUCCESS;
8945
8946 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8947 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8948
69b07479
DS
8949 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8950
bb4f6190
DS
8951 return CMD_SUCCESS;
8952}
8953
ae6a6fb4
DS
8954DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8955 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8956 NO_STR
8957 "Import routes from another VRF\n"
8958 "Vrf routes being filtered\n"
ae6a6fb4
DS
8959 "Specify route map\n"
8960 "name of route-map\n")
8961{
8962 VTY_DECLVAR_CONTEXT(bgp, bgp);
9c2fd3fe 8963 enum vpn_policy_direction dir = BGP_VPN_POLICY_DIR_FROMVPN;
ae6a6fb4
DS
8964 afi_t afi;
8965
8966 afi = vpn_policy_getafi(vty, bgp, true);
8967 if (afi == AFI_MAX)
8968 return CMD_WARNING_CONFIG_FAILED;
8969
8970 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8971
8972 if (bgp->vpn_policy[afi].rmap_name[dir])
8973 XFREE(MTYPE_ROUTE_MAP_NAME,
8974 bgp->vpn_policy[afi].rmap_name[dir]);
8975 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8976 bgp->vpn_policy[afi].rmap[dir] = NULL;
8977
8978 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8979 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8980 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8981
8982 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8983
8984 return CMD_SUCCESS;
8985}
bb4f6190 8986
585f1adc
IR
8987DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8988 "[no] import vrf VIEWVRFNAME$import_name",
8989 NO_STR
8990 "Import routes from another VRF\n"
8991 "VRF to import from\n"
8992 "The name of the VRF\n")
12a844a5 8993{
585f1adc
IR
8994 VTY_DECLVAR_CONTEXT(bgp, bgp);
8995 struct listnode *node;
8996 struct bgp *vrf_bgp, *bgp_default;
8997 int32_t ret = 0;
8998 as_t as = bgp->as;
8999 bool remove = false;
9000 int32_t idx = 0;
9001 char *vname;
9002 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
9003 safi_t safi;
9004 afi_t afi;
9005
867f0cca 9006 if (import_name == NULL) {
9007 vty_out(vty, "%% Missing import name\n");
9008 return CMD_WARNING;
9009 }
9010
ae6a6fb4
DS
9011 if (strcmp(import_name, "route-map") == 0) {
9012 vty_out(vty, "%% Must include route-map name\n");
9013 return CMD_WARNING;
9014 }
9015
585f1adc
IR
9016 if (argv_find(argv, argc, "no", &idx))
9017 remove = true;
9018
9019 afi = vpn_policy_getafi(vty, bgp, true);
9020 if (afi == AFI_MAX)
9021 return CMD_WARNING_CONFIG_FAILED;
9022
12a844a5
DS
9023 safi = bgp_node_safi(vty);
9024
585f1adc
IR
9025 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
9026 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
9027 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
9028 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
9029 remove ? "unimport" : "import", import_name);
9030 return CMD_WARNING;
9031 }
25679caa 9032
585f1adc
IR
9033 bgp_default = bgp_get_default();
9034 if (!bgp_default) {
9035 /* Auto-create assuming the same AS */
9036 ret = bgp_get_vty(&bgp_default, &as, NULL,
9037 BGP_INSTANCE_TYPE_DEFAULT);
12a844a5 9038
585f1adc
IR
9039 if (ret) {
9040 vty_out(vty,
9041 "VRF default is not configured as a bgp instance\n");
9042 return CMD_WARNING;
9043 }
9044 }
12a844a5 9045
585f1adc
IR
9046 vrf_bgp = bgp_lookup_by_name(import_name);
9047 if (!vrf_bgp) {
9048 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
9049 vrf_bgp = bgp_default;
9050 else
9051 /* Auto-create assuming the same AS */
9052 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
9053
9054 if (ret) {
9055 vty_out(vty,
9056 "VRF %s is not configured as a bgp instance\n",
9057 import_name);
9058 return CMD_WARNING;
9059 }
9060 }
9061
9062 if (remove) {
9063 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
9064 } else {
9065 /* Already importing from "import_vrf"? */
9066 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
9067 vname)) {
9068 if (strcmp(vname, import_name) == 0)
9069 return CMD_WARNING;
9070 }
9071
9072 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
9073 }
9074
9075 return CMD_SUCCESS;
12a844a5
DS
9076}
9077
b9c7bc5a 9078/* This command is valid only in a bgp vrf instance or the default instance */
585f1adc 9079DEFPY (bgp_imexport_vpn,
b9c7bc5a
PZ
9080 bgp_imexport_vpn_cmd,
9081 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9082 NO_STR
9083 "Import routes to this address-family\n"
9084 "Export routes from this address-family\n"
9085 "to/from default instance VPN RIB\n")
ddb5b488 9086{
585f1adc
IR
9087 VTY_DECLVAR_CONTEXT(bgp, bgp);
9088 int previous_state;
37a87b8f 9089 afi_t afi;
585f1adc
IR
9090 safi_t safi;
9091 int idx = 0;
9092 bool yes = true;
9093 int flag;
9c2fd3fe 9094 enum vpn_policy_direction dir;
585f1adc
IR
9095
9096 if (argv_find(argv, argc, "no", &idx))
9097 yes = false;
9098
9099 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
9100 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
9101
9102 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
9103 return CMD_WARNING_CONFIG_FAILED;
9104 }
ddb5b488 9105
b9c7bc5a
PZ
9106 afi = bgp_node_afi(vty);
9107 safi = bgp_node_safi(vty);
585f1adc
IR
9108 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
9109 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
9110 return CMD_WARNING_CONFIG_FAILED;
9111 }
ddb5b488 9112
b9c7bc5a 9113 if (!strcmp(direction_str, "import")) {
585f1adc
IR
9114 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
9115 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b9c7bc5a 9116 } else if (!strcmp(direction_str, "export")) {
585f1adc
IR
9117 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
9118 dir = BGP_VPN_POLICY_DIR_TOVPN;
b9c7bc5a
PZ
9119 } else {
9120 vty_out(vty, "%% unknown direction %s\n", direction_str);
9121 return CMD_WARNING_CONFIG_FAILED;
9122 }
9123
585f1adc 9124 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 9125
585f1adc
IR
9126 if (yes) {
9127 SET_FLAG(bgp->af_flags[afi][safi], flag);
9128 if (!previous_state) {
9129 /* trigger export current vrf */
9130 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9131 }
9132 } else {
9133 if (previous_state) {
9134 /* trigger un-export current vrf */
9135 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9136 }
9137 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
9138 }
37a87b8f 9139
1ca2fd11
IR
9140 hook_call(bgp_snmp_init_stats, bgp);
9141
585f1adc 9142 return CMD_SUCCESS;
ddb5b488
PZ
9143}
9144
301ad80a
PG
9145DEFPY (af_routetarget_import,
9146 af_routetarget_import_cmd,
9a659715 9147 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9148 NO_STR
9149 "Specify route target list\n"
9150 "Specify route target list\n"
9a659715
PG
9151 "Specify route target list\n"
9152 "Specify route target list\n"
301ad80a
PG
9153 "Flow-spec redirect type route target\n"
9154 "Import routes to this address-family\n"
9a659715 9155 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9156{
9157 VTY_DECLVAR_CONTEXT(bgp, bgp);
9158 int ret;
9159 struct ecommunity *ecom = NULL;
301ad80a 9160 afi_t afi;
9a659715 9161 int idx = 0, idx_unused = 0;
c6423c31
PG
9162 bool yes = true;
9163 bool rt6 = false;
301ad80a
PG
9164
9165 if (argv_find(argv, argc, "no", &idx))
c6423c31 9166 yes = false;
301ad80a 9167
9a659715
PG
9168 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9169 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9170 rt6 = true;
301ad80a 9171
0ca70ba5 9172 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9173 if (afi == AFI_MAX)
9174 return CMD_WARNING_CONFIG_FAILED;
9175
9a659715
PG
9176 if (rt6 && afi != AFI_IP6)
9177 return CMD_WARNING_CONFIG_FAILED;
9178
301ad80a
PG
9179 if (yes) {
9180 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9181 vty_out(vty, "%% Missing RTLIST\n");
9182 return CMD_WARNING_CONFIG_FAILED;
9183 }
9a659715 9184 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9185 if (ret != CMD_SUCCESS)
9186 return ret;
9187 }
69b07479
DS
9188
9189 if (yes) {
9190 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9191 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9192 .import_redirect_rtlist);
69b07479
DS
9193 bgp->vpn_policy[afi].import_redirect_rtlist =
9194 ecommunity_dup(ecom);
9195 } else {
9196 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9197 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9198 .import_redirect_rtlist);
69b07479 9199 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9200 }
69b07479 9201
301ad80a
PG
9202 if (ecom)
9203 ecommunity_free(&ecom);
9204
9205 return CMD_SUCCESS;
9206}
9207
505e5056 9208DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9209 address_family_ipv4_safi_cmd,
9210 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9211 "Enter Address Family command mode\n"
9212 "Address Family\n"
9213 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9214{
f51bae9c 9215
d62a17ae 9216 if (argc == 3) {
585f1adc
IR
9217 VTY_DECLVAR_CONTEXT(bgp, bgp);
9218 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9219 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9220 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9221 && safi != SAFI_EVPN) {
31947174
MK
9222 vty_out(vty,
9223 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9224 return CMD_WARNING_CONFIG_FAILED;
9225 }
585f1adc
IR
9226 vty->node = bgp_node_type(AFI_IP, safi);
9227 } else
9228 vty->node = BGP_IPV4_NODE;
718e3744 9229
d62a17ae 9230 return CMD_SUCCESS;
718e3744 9231}
9232
505e5056 9233DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9234 address_family_ipv6_safi_cmd,
9235 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9236 "Enter Address Family command mode\n"
9237 "Address Family\n"
9238 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9239{
d62a17ae 9240 if (argc == 3) {
585f1adc
IR
9241 VTY_DECLVAR_CONTEXT(bgp, bgp);
9242 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
9243 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
a4d82a8a 9244 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9245 && safi != SAFI_EVPN) {
31947174
MK
9246 vty_out(vty,
9247 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9248 return CMD_WARNING_CONFIG_FAILED;
9249 }
585f1adc
IR
9250 vty->node = bgp_node_type(AFI_IP6, safi);
9251 } else
9252 vty->node = BGP_IPV6_NODE;
25ffbdc1 9253
d62a17ae 9254 return CMD_SUCCESS;
25ffbdc1 9255}
718e3744 9256
d6902373 9257#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9258DEFUN_NOSH (address_family_vpnv4,
718e3744 9259 address_family_vpnv4_cmd,
8334fd5a 9260 "address-family vpnv4 [unicast]",
718e3744 9261 "Enter Address Family command mode\n"
8c3deaae 9262 "Address Family\n"
3a2d747c 9263 "Address Family modifier\n")
718e3744 9264{
d62a17ae 9265 vty->node = BGP_VPNV4_NODE;
9266 return CMD_SUCCESS;
718e3744 9267}
9268
505e5056 9269DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9270 address_family_vpnv6_cmd,
8334fd5a 9271 "address-family vpnv6 [unicast]",
8ecd3266 9272 "Enter Address Family command mode\n"
8c3deaae 9273 "Address Family\n"
3a2d747c 9274 "Address Family modifier\n")
8ecd3266 9275{
d62a17ae 9276 vty->node = BGP_VPNV6_NODE;
9277 return CMD_SUCCESS;
8ecd3266 9278}
64e4a6c5 9279#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9280
505e5056 9281DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9282 address_family_evpn_cmd,
7111c1a0 9283 "address-family l2vpn evpn",
4e0b7b6d 9284 "Enter Address Family command mode\n"
7111c1a0
QY
9285 "Address Family\n"
9286 "Address Family modifier\n")
4e0b7b6d 9287{
2131d5cf 9288 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9289 vty->node = BGP_EVPN_NODE;
9290 return CMD_SUCCESS;
4e0b7b6d
PG
9291}
9292
bfaab44d
HS
9293DEFUN_NOSH (bgp_segment_routing_srv6,
9294 bgp_segment_routing_srv6_cmd,
9295 "segment-routing srv6",
9296 "Segment-Routing configuration\n"
9297 "Segment-Routing SRv6 configuration\n")
9298{
9299 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9300 bgp->srv6_enabled = true;
bfaab44d
HS
9301 vty->node = BGP_SRV6_NODE;
9302 return CMD_SUCCESS;
9303}
9304
0249b8b6
HS
9305DEFUN (no_bgp_segment_routing_srv6,
9306 no_bgp_segment_routing_srv6_cmd,
9307 "no segment-routing srv6",
9308 NO_STR
9309 "Segment-Routing configuration\n"
9310 "Segment-Routing SRv6 configuration\n")
9311{
9312 VTY_DECLVAR_CONTEXT(bgp, bgp);
9313
9314 if (strlen(bgp->srv6_locator_name) > 0)
9315 if (bgp_srv6_locator_unset(bgp) < 0)
9316 return CMD_WARNING_CONFIG_FAILED;
9317
9318 bgp->srv6_enabled = false;
9319 return CMD_SUCCESS;
9320}
9321
a0281b2e
HS
9322DEFPY (bgp_srv6_locator,
9323 bgp_srv6_locator_cmd,
9324 "locator NAME$name",
9325 "Specify SRv6 locator\n"
9326 "Specify SRv6 locator\n")
9327{
9328 VTY_DECLVAR_CONTEXT(bgp, bgp);
7de4c885 9329 int ret;
a0281b2e
HS
9330
9331 if (strlen(bgp->srv6_locator_name) > 0
9332 && strcmp(name, bgp->srv6_locator_name) != 0) {
9333 vty_out(vty, "srv6 locator is already configured\n");
9334 return CMD_WARNING_CONFIG_FAILED;
7de4c885
HS
9335 }
9336
9337 snprintf(bgp->srv6_locator_name,
9338 sizeof(bgp->srv6_locator_name), "%s", name);
a0281b2e 9339
7de4c885 9340 ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
a0281b2e
HS
9341 if (ret < 0)
9342 return CMD_WARNING_CONFIG_FAILED;
9343
9344 return CMD_SUCCESS;
9345}
9346
0249b8b6
HS
9347DEFPY (no_bgp_srv6_locator,
9348 no_bgp_srv6_locator_cmd,
9349 "no locator NAME$name",
9350 NO_STR
9351 "Specify SRv6 locator\n"
9352 "Specify SRv6 locator\n")
9353{
9354 VTY_DECLVAR_CONTEXT(bgp, bgp);
9355
9356 /* when locator isn't configured, do nothing */
9357 if (strlen(bgp->srv6_locator_name) < 1)
9358 return CMD_SUCCESS;
9359
9360 /* name validation */
9361 if (strcmp(name, bgp->srv6_locator_name) != 0) {
9362 vty_out(vty, "%% No srv6 locator is configured\n");
9363 return CMD_WARNING_CONFIG_FAILED;
9364 }
9365
9366 /* unset locator */
9367 if (bgp_srv6_locator_unset(bgp) < 0)
9368 return CMD_WARNING_CONFIG_FAILED;
9369
9370 return CMD_SUCCESS;
9371}
9372
ea372e81
HS
9373DEFPY (show_bgp_srv6,
9374 show_bgp_srv6_cmd,
9375 "show bgp segment-routing srv6",
9376 SHOW_STR
9377 BGP_STR
9378 "BGP Segment Routing\n"
9379 "BGP Segment Routing SRv6\n")
9380{
9381 struct bgp *bgp;
9382 struct listnode *node;
1c21a234 9383 struct srv6_locator_chunk *chunk;
ea372e81
HS
9384 struct bgp_srv6_function *func;
9385 struct in6_addr *tovpn4_sid;
9386 struct in6_addr *tovpn6_sid;
9387 char buf[256];
9388 char buf_tovpn4_sid[256];
9389 char buf_tovpn6_sid[256];
9390
9391 bgp = bgp_get_default();
96db4340 9392 if (!bgp)
ea372e81
HS
9393 return CMD_SUCCESS;
9394
9395 vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
9396 vty_out(vty, "locator_chunks:\n");
9397 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
1c21a234 9398 prefix2str(&chunk->prefix, buf, sizeof(buf));
ea372e81
HS
9399 vty_out(vty, "- %s\n", buf);
9400 }
9401
9402 vty_out(vty, "functions:\n");
9403 for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
9404 inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
9405 vty_out(vty, "- sid: %s\n", buf);
9406 vty_out(vty, " locator: %s\n", func->locator_name);
9407 }
9408
9409 vty_out(vty, "bgps:\n");
9410 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
9411 vty_out(vty, "- name: %s\n",
9412 bgp->name ? bgp->name : "default");
9413
9414 tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
9415 tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
9416 if (tovpn4_sid)
9417 inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
9418 sizeof(buf_tovpn4_sid));
9419 if (tovpn6_sid)
9420 inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
9421 sizeof(buf_tovpn6_sid));
9422
9423 vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
9424 tovpn4_sid ? buf_tovpn4_sid : "none");
9425 vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
9426 tovpn6_sid ? buf_tovpn6_sid : "none");
9427 }
9428
9429 return CMD_SUCCESS;
9430}
9431
505e5056 9432DEFUN_NOSH (exit_address_family,
718e3744 9433 exit_address_family_cmd,
9434 "exit-address-family",
9435 "Exit from Address Family configuration mode\n")
9436{
d62a17ae 9437 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9438 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9439 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9440 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9441 || vty->node == BGP_EVPN_NODE
9442 || vty->node == BGP_FLOWSPECV4_NODE
9443 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9444 vty->node = BGP_NODE;
9445 return CMD_SUCCESS;
718e3744 9446}
6b0655a2 9447
8ad7271d 9448/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9449static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9450 const char *ip_str, afi_t afi, safi_t safi,
9451 struct prefix_rd *prd)
9452{
9453 int ret;
9454 struct prefix match;
9bcb3eef
DS
9455 struct bgp_dest *dest;
9456 struct bgp_dest *rm;
d62a17ae 9457 struct bgp *bgp;
9458 struct bgp_table *table;
9459 struct bgp_table *rib;
9460
9461 /* BGP structure lookup. */
9462 if (view_name) {
9463 bgp = bgp_lookup_by_name(view_name);
9464 if (bgp == NULL) {
9465 vty_out(vty, "%% Can't find BGP instance %s\n",
9466 view_name);
9467 return CMD_WARNING;
9468 }
9469 } else {
9470 bgp = bgp_get_default();
9471 if (bgp == NULL) {
9472 vty_out(vty, "%% No BGP process is configured\n");
9473 return CMD_WARNING;
9474 }
9475 }
9476
9477 /* Check IP address argument. */
9478 ret = str2prefix(ip_str, &match);
9479 if (!ret) {
9480 vty_out(vty, "%% address is malformed\n");
9481 return CMD_WARNING;
9482 }
9483
9484 match.family = afi2family(afi);
9485 rib = bgp->rib[afi][safi];
9486
9487 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9488 for (dest = bgp_table_top(rib); dest;
9489 dest = bgp_route_next(dest)) {
9490 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9491
9bcb3eef 9492 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9493 continue;
9494
9bcb3eef 9495 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9496 if (table == NULL)
9497 continue;
9498
4953391b
DA
9499 rm = bgp_node_match(table, &match);
9500 if (rm != NULL) {
b54892e0 9501 const struct prefix *rm_p =
9bcb3eef 9502 bgp_dest_get_prefix(rm);
b54892e0
DS
9503
9504 if (rm_p->prefixlen == match.prefixlen) {
9505 SET_FLAG(rm->flags,
9506 BGP_NODE_USER_CLEAR);
9507 bgp_process(bgp, rm, afi, safi);
d62a17ae 9508 }
9bcb3eef 9509 bgp_dest_unlock_node(rm);
d62a17ae 9510 }
9511 }
9512 } else {
4953391b
DA
9513 dest = bgp_node_match(rib, &match);
9514 if (dest != NULL) {
9bcb3eef 9515 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9516
9bcb3eef
DS
9517 if (dest_p->prefixlen == match.prefixlen) {
9518 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9519 bgp_process(bgp, dest, afi, safi);
d62a17ae 9520 }
9bcb3eef 9521 bgp_dest_unlock_node(dest);
d62a17ae 9522 }
9523 }
9524
9525 return CMD_SUCCESS;
8ad7271d
DS
9526}
9527
b09b5ae0 9528/* one clear bgp command to rule them all */
718e3744 9529DEFUN (clear_ip_bgp_all,
9530 clear_ip_bgp_all_cmd,
3cb14f26 9531 "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 9532 CLEAR_STR
9533 IP_STR
9534 BGP_STR
838758ac 9535 BGP_INSTANCE_HELP_STR
510afcd6 9536 BGP_AFI_HELP_STR
fd5e7b70 9537 "Address Family\n"
510afcd6 9538 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9539 "Address Family modifier\n"
b09b5ae0 9540 "Clear all peers\n"
453c92f6 9541 "BGP IPv4 neighbor to clear\n"
a80beece 9542 "BGP IPv6 neighbor to clear\n"
838758ac 9543 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9544 "Clear peers with the AS number\n"
9545 "Clear all external peers\n"
718e3744 9546 "Clear all members of peer-group\n"
b09b5ae0 9547 "BGP peer-group name\n"
b09b5ae0
DW
9548 BGP_SOFT_STR
9549 BGP_SOFT_IN_STR
b09b5ae0
DW
9550 BGP_SOFT_OUT_STR
9551 BGP_SOFT_IN_STR
9552 "Push out prefix-list ORF and do inbound soft reconfig\n"
3cb14f26
DS
9553 BGP_SOFT_OUT_STR
9554 "Reset message statistics\n")
718e3744 9555{
d62a17ae 9556 char *vrf = NULL;
9557
dc912615
DS
9558 afi_t afi = AFI_UNSPEC;
9559 safi_t safi = SAFI_UNSPEC;
d62a17ae 9560 enum clear_sort clr_sort = clear_peer;
9561 enum bgp_clear_type clr_type;
9562 char *clr_arg = NULL;
9563
9564 int idx = 0;
9565
9566 /* clear [ip] bgp */
9567 if (argv_find(argv, argc, "ip", &idx))
9568 afi = AFI_IP;
9569
9a8bdf1c
PG
9570 /* [<vrf> VIEWVRFNAME] */
9571 if (argv_find(argv, argc, "vrf", &idx)) {
9572 vrf = argv[idx + 1]->arg;
9573 idx += 2;
9574 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9575 vrf = NULL;
9576 } else if (argv_find(argv, argc, "view", &idx)) {
9577 /* [<view> VIEWVRFNAME] */
d62a17ae 9578 vrf = argv[idx + 1]->arg;
9579 idx += 2;
9580 }
d62a17ae 9581 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9582 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9583 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9584
d7b9898c 9585 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 9586 if (argv_find(argv, argc, "*", &idx)) {
9587 clr_sort = clear_all;
9588 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9589 clr_sort = clear_peer;
9590 clr_arg = argv[idx]->arg;
9591 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9592 clr_sort = clear_peer;
9593 clr_arg = argv[idx]->arg;
9594 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9595 clr_sort = clear_group;
9596 idx++;
9597 clr_arg = argv[idx]->arg;
d7b9898c 9598 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 9599 clr_sort = clear_peer;
9600 clr_arg = argv[idx]->arg;
8fa7d444
DS
9601 } else if (argv_find(argv, argc, "WORD", &idx)) {
9602 clr_sort = clear_peer;
9603 clr_arg = argv[idx]->arg;
d62a17ae 9604 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9605 clr_sort = clear_as;
9606 clr_arg = argv[idx]->arg;
9607 } else if (argv_find(argv, argc, "external", &idx)) {
9608 clr_sort = clear_external;
9609 }
9610
3cb14f26 9611 /* [<soft [<in|out>]|in [prefix-filter]|out|message-stats>] */
d62a17ae 9612 if (argv_find(argv, argc, "soft", &idx)) {
9613 if (argv_find(argv, argc, "in", &idx)
9614 || argv_find(argv, argc, "out", &idx))
9615 clr_type = strmatch(argv[idx]->text, "in")
9616 ? BGP_CLEAR_SOFT_IN
9617 : BGP_CLEAR_SOFT_OUT;
9618 else
9619 clr_type = BGP_CLEAR_SOFT_BOTH;
9620 } else if (argv_find(argv, argc, "in", &idx)) {
9621 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9622 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9623 : BGP_CLEAR_SOFT_IN;
9624 } else if (argv_find(argv, argc, "out", &idx)) {
9625 clr_type = BGP_CLEAR_SOFT_OUT;
3cb14f26
DS
9626 } else if (argv_find(argv, argc, "message-stats", &idx)) {
9627 clr_type = BGP_CLEAR_MESSAGE_STATS;
d62a17ae 9628 } else
9629 clr_type = BGP_CLEAR_SOFT_NONE;
9630
1ca2fd11 9631 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 9632}
01080f7c 9633
8ad7271d
DS
9634DEFUN (clear_ip_bgp_prefix,
9635 clear_ip_bgp_prefix_cmd,
18c57037 9636 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
9637 CLEAR_STR
9638 IP_STR
9639 BGP_STR
838758ac 9640 BGP_INSTANCE_HELP_STR
8ad7271d 9641 "Clear bestpath and re-advertise\n"
0c7b1b01 9642 "IPv4 prefix\n")
8ad7271d 9643{
d62a17ae 9644 char *vrf = NULL;
9645 char *prefix = NULL;
8ad7271d 9646
d62a17ae 9647 int idx = 0;
01080f7c 9648
d62a17ae 9649 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
9650 if (argv_find(argv, argc, "vrf", &idx)) {
9651 vrf = argv[idx + 1]->arg;
9652 idx += 2;
9653 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9654 vrf = NULL;
9655 } else if (argv_find(argv, argc, "view", &idx)) {
9656 /* [<view> VIEWVRFNAME] */
9657 vrf = argv[idx + 1]->arg;
9658 idx += 2;
9659 }
0c7b1b01 9660
d62a17ae 9661 prefix = argv[argc - 1]->arg;
8ad7271d 9662
d62a17ae 9663 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 9664}
8ad7271d 9665
b09b5ae0
DW
9666DEFUN (clear_bgp_ipv6_safi_prefix,
9667 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 9668 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9669 CLEAR_STR
3a2d747c 9670 IP_STR
718e3744 9671 BGP_STR
8c3deaae 9672 "Address Family\n"
46f296b4 9673 BGP_SAFI_HELP_STR
b09b5ae0 9674 "Clear bestpath and re-advertise\n"
0c7b1b01 9675 "IPv6 prefix\n")
718e3744 9676{
9b475e76
PG
9677 int idx_safi = 0;
9678 int idx_ipv6_prefix = 0;
9679 safi_t safi = SAFI_UNICAST;
9680 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9681 argv[idx_ipv6_prefix]->arg : NULL;
9682
9683 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 9684 return bgp_clear_prefix(
9b475e76
PG
9685 vty, NULL, prefix, AFI_IP6,
9686 safi, NULL);
838758ac 9687}
01080f7c 9688
b09b5ae0
DW
9689DEFUN (clear_bgp_instance_ipv6_safi_prefix,
9690 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 9691 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 9692 CLEAR_STR
3a2d747c 9693 IP_STR
718e3744 9694 BGP_STR
838758ac 9695 BGP_INSTANCE_HELP_STR
8c3deaae 9696 "Address Family\n"
46f296b4 9697 BGP_SAFI_HELP_STR
b09b5ae0 9698 "Clear bestpath and re-advertise\n"
0c7b1b01 9699 "IPv6 prefix\n")
718e3744 9700{
9b475e76 9701 int idx_safi = 0;
9a8bdf1c 9702 int idx_vrfview = 0;
9b475e76
PG
9703 int idx_ipv6_prefix = 0;
9704 safi_t safi = SAFI_UNICAST;
9705 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
9706 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 9707 char *vrfview = NULL;
9b475e76 9708
9a8bdf1c
PG
9709 /* [<view|vrf> VIEWVRFNAME] */
9710 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
9711 vrfview = argv[idx_vrfview + 1]->arg;
9712 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
9713 vrfview = NULL;
9714 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
9715 /* [<view> VIEWVRFNAME] */
9716 vrfview = argv[idx_vrfview + 1]->arg;
9717 }
9b475e76
PG
9718 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
9719
d62a17ae 9720 return bgp_clear_prefix(
9b475e76
PG
9721 vty, vrfview, prefix,
9722 AFI_IP6, safi, NULL);
718e3744 9723}
9724
b09b5ae0
DW
9725DEFUN (show_bgp_views,
9726 show_bgp_views_cmd,
d6e3c605 9727 "show [ip] bgp views",
b09b5ae0 9728 SHOW_STR
d6e3c605 9729 IP_STR
01080f7c 9730 BGP_STR
b09b5ae0 9731 "Show the defined BGP views\n")
01080f7c 9732{
d62a17ae 9733 struct list *inst = bm->bgp;
9734 struct listnode *node;
9735 struct bgp *bgp;
01080f7c 9736
d62a17ae 9737 vty_out(vty, "Defined BGP views:\n");
9738 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9739 /* Skip VRFs. */
9740 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9741 continue;
9742 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9743 bgp->as);
9744 }
e52702f2 9745
d62a17ae 9746 return CMD_SUCCESS;
e0081f70
ML
9747}
9748
8386ac43 9749DEFUN (show_bgp_vrfs,
9750 show_bgp_vrfs_cmd,
d6e3c605 9751 "show [ip] bgp vrfs [json]",
8386ac43 9752 SHOW_STR
d6e3c605 9753 IP_STR
8386ac43 9754 BGP_STR
9755 "Show BGP VRFs\n"
9973d184 9756 JSON_STR)
8386ac43 9757{
fe1dc5a3 9758 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9759 struct list *inst = bm->bgp;
9760 struct listnode *node;
9761 struct bgp *bgp;
9f049418 9762 bool uj = use_json(argc, argv);
d62a17ae 9763 json_object *json = NULL;
9764 json_object *json_vrfs = NULL;
9765 int count = 0;
d62a17ae 9766
d62a17ae 9767 if (uj) {
9768 json = json_object_new_object();
9769 json_vrfs = json_object_new_object();
9770 }
9771
9772 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9773 const char *name, *type;
9774 struct peer *peer;
7fe96307 9775 struct listnode *node2, *nnode2;
d62a17ae 9776 int peers_cfg, peers_estb;
9777 json_object *json_vrf = NULL;
d62a17ae 9778
9779 /* Skip Views. */
9780 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9781 continue;
9782
9783 count++;
efb4077a 9784 if (!uj && count == 1) {
fe1dc5a3 9785 vty_out(vty,
efb4077a 9786 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9787 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9788 "#PeersEstb", "Name");
9789 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9790 "L3-VNI", "RouterMAC", "Interface");
9791 }
d62a17ae 9792
9793 peers_cfg = peers_estb = 0;
9794 if (uj)
9795 json_vrf = json_object_new_object();
9796
9797
7fe96307 9798 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9799 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9800 continue;
9801 peers_cfg++;
feb17238 9802 if (peer_established(peer))
d62a17ae 9803 peers_estb++;
9804 }
9805
9806 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9807 name = VRF_DEFAULT_NAME;
d62a17ae 9808 type = "DFLT";
9809 } else {
9810 name = bgp->name;
9811 type = "VRF";
9812 }
9813
a8bf7d9c 9814
d62a17ae 9815 if (uj) {
a4d82a8a
PZ
9816 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9817 ? -1
9818 : (int64_t)bgp->vrf_id;
23d0a753
DA
9819 char buf[BUFSIZ] = {0};
9820
d62a17ae 9821 json_object_string_add(json_vrf, "type", type);
9822 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
c949c771
DA
9823 json_object_string_addf(json_vrf, "routerId", "%pI4",
9824 &bgp->router_id);
d62a17ae 9825 json_object_int_add(json_vrf, "numConfiguredPeers",
9826 peers_cfg);
9827 json_object_int_add(json_vrf, "numEstablishedPeers",
9828 peers_estb);
9829
fe1dc5a3 9830 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9831 json_object_string_add(
9832 json_vrf, "rmac",
9833 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9834 json_object_string_add(json_vrf, "interface",
9835 ifindex2ifname(bgp->l3vni_svi_ifindex,
9836 bgp->vrf_id));
d62a17ae 9837 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9838 } else {
23d0a753 9839 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9840 type,
9841 bgp->vrf_id == VRF_UNKNOWN ? -1
9842 : (int)bgp->vrf_id,
23d0a753 9843 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9844 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9845 bgp->l3vni,
9846 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9847 ifindex2ifname(bgp->l3vni_svi_ifindex,
9848 bgp->vrf_id));
9849 }
d62a17ae 9850 }
9851
9852 if (uj) {
9853 json_object_object_add(json, "vrfs", json_vrfs);
9854
9855 json_object_int_add(json, "totalVrfs", count);
9856
75eeda93 9857 vty_json(vty, json);
d62a17ae 9858 } else {
9859 if (count)
9860 vty_out(vty,
9861 "\nTotal number of VRFs (including default): %d\n",
9862 count);
9863 }
9864
9865 return CMD_SUCCESS;
8386ac43 9866}
9867
48ecf8f5
DS
9868DEFUN (show_bgp_mac_hash,
9869 show_bgp_mac_hash_cmd,
9870 "show bgp mac hash",
9871 SHOW_STR
9872 BGP_STR
9873 "Mac Address\n"
9874 "Mac Address database\n")
9875{
9876 bgp_mac_dump_table(vty);
9877
9878 return CMD_SUCCESS;
9879}
acf71666 9880
e3b78da8 9881static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9882{
0291c246 9883 struct vty *vty = (struct vty *)args;
e3b78da8 9884 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9885
23d0a753 9886 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9887}
9888
9889static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9890{
9891 vty_out(vty, "self nexthop database:\n");
af97a18b 9892 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9893
9894 vty_out(vty, "Tunnel-ip database:\n");
9895 hash_iterate(bgp->tip_hash,
e3b78da8 9896 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9897 vty);
9898}
9899
15c81ca4
DS
9900DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9901 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9902 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9903 "martian next-hops\n"
9904 "martian next-hop database\n")
acf71666 9905{
0291c246 9906 struct bgp *bgp = NULL;
15c81ca4 9907 int idx = 0;
9a8bdf1c
PG
9908 char *name = NULL;
9909
9910 /* [<vrf> VIEWVRFNAME] */
9911 if (argv_find(argv, argc, "vrf", &idx)) {
9912 name = argv[idx + 1]->arg;
9913 if (name && strmatch(name, VRF_DEFAULT_NAME))
9914 name = NULL;
9915 } else if (argv_find(argv, argc, "view", &idx))
9916 /* [<view> VIEWVRFNAME] */
9917 name = argv[idx + 1]->arg;
9918 if (name)
9919 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9920 else
9921 bgp = bgp_get_default();
acf71666 9922
acf71666
MK
9923 if (!bgp) {
9924 vty_out(vty, "%% No BGP process is configured\n");
9925 return CMD_WARNING;
9926 }
9927 bgp_show_martian_nexthops(vty, bgp);
9928
9929 return CMD_SUCCESS;
9930}
9931
f412b39a 9932DEFUN (show_bgp_memory,
4bf6a362 9933 show_bgp_memory_cmd,
7fa12b13 9934 "show [ip] bgp memory",
4bf6a362 9935 SHOW_STR
3a2d747c 9936 IP_STR
4bf6a362
PJ
9937 BGP_STR
9938 "Global BGP memory statistics\n")
9939{
d62a17ae 9940 char memstrbuf[MTYPE_MEMSTR_LEN];
9941 unsigned long count;
9942
9943 /* RIB related usage stats */
9944 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9945 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9946 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9947 count * sizeof(struct bgp_dest)));
d62a17ae 9948
9949 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9950 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9951 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9952 count * sizeof(struct bgp_path_info)));
d62a17ae 9953 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9954 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9955 count,
4b7e6066
DS
9956 mtype_memstr(
9957 memstrbuf, sizeof(memstrbuf),
9958 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9959
9960 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9961 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9962 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9963 count * sizeof(struct bgp_static)));
9964
9965 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9966 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9967 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9968 count * sizeof(struct bpacket)));
9969
9970 /* Adj-In/Out */
9971 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9972 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9973 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9974 count * sizeof(struct bgp_adj_in)));
9975 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9976 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9977 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9978 count * sizeof(struct bgp_adj_out)));
9979
9980 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9981 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9982 count,
9983 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9984 count * sizeof(struct bgp_nexthop_cache)));
9985
9986 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9987 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9988 count,
9989 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9990 count * sizeof(struct bgp_damp_info)));
9991
9992 /* Attributes */
9993 count = attr_count();
9994 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9995 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9996 count * sizeof(struct attr)));
9997
9998 if ((count = attr_unknown_count()))
9999 vty_out(vty, "%ld unknown attributes\n", count);
10000
10001 /* AS_PATH attributes */
10002 count = aspath_count();
10003 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10004 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10005 count * sizeof(struct aspath)));
10006
10007 count = mtype_stats_alloc(MTYPE_AS_SEG);
10008 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10009 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10010 count * sizeof(struct assegment)));
10011
10012 /* Other attributes */
10013 if ((count = community_count()))
10014 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10015 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10016 count * sizeof(struct community)));
d62a17ae 10017 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10018 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10019 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10020 count * sizeof(struct ecommunity)));
d62a17ae 10021 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10022 vty_out(vty,
10023 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10024 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10025 count * sizeof(struct lcommunity)));
d62a17ae 10026
10027 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10028 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10029 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10030 count * sizeof(struct cluster_list)));
10031
10032 /* Peer related usage */
10033 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10034 vty_out(vty, "%ld peers, using %s of memory\n", count,
10035 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10036 count * sizeof(struct peer)));
10037
10038 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10039 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10040 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10041 count * sizeof(struct peer_group)));
10042
10043 /* Other */
d62a17ae 10044 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10045 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10046 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10047 count * sizeof(regex_t)));
d62a17ae 10048 return CMD_SUCCESS;
4bf6a362 10049}
fee0f4c6 10050
57a9c8a8
DS
10051static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10052{
10053 json_object *bestpath = json_object_new_object();
10054
892fedb6 10055 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10056 json_object_string_add(bestpath, "asPath", "ignore");
10057
892fedb6 10058 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10059 json_object_string_add(bestpath, "asPath", "confed");
10060
892fedb6
DA
10061 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10062 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10063 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10064 "as-set");
10065 else
a4d82a8a 10066 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10067 "true");
10068 } else
a4d82a8a 10069 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10070
ee88563a
JM
10071 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10072 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10073
892fedb6 10074 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10075 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10076 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10077 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10078 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10079 json_object_string_add(bestpath, "med", "confed");
892fedb6 10080 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10081 json_object_string_add(bestpath, "med",
10082 "missing-as-worst");
10083 else
10084 json_object_string_add(bestpath, "med", "true");
10085 }
10086
10087 json_object_object_add(json, "bestPath", bestpath);
10088}
10089
3577f1c5
DD
10090/* Print the error code/subcode for why the peer is down */
10091static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10092 json_object *json_peer, bool use_json)
10093{
10094 const char *code_str;
10095 const char *subcode_str;
10096
10097 if (use_json) {
10098 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10099 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10100 char errorcodesubcode_hexstr[5];
10101 char errorcodesubcode_str[256];
10102
10103 code_str = bgp_notify_code_str(peer->notify.code);
10104 subcode_str = bgp_notify_subcode_str(
10105 peer->notify.code,
10106 peer->notify.subcode);
10107
772270f3
QY
10108 snprintf(errorcodesubcode_hexstr,
10109 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10110 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10111 json_object_string_add(json_peer,
10112 "lastErrorCodeSubcode",
10113 errorcodesubcode_hexstr);
10114 snprintf(errorcodesubcode_str, 255, "%s%s",
10115 code_str, subcode_str);
10116 json_object_string_add(json_peer,
10117 "lastNotificationReason",
10118 errorcodesubcode_str);
eea685b6
DA
10119 json_object_boolean_add(json_peer,
10120 "lastNotificationHardReset",
10121 peer->notify.hard_reset);
3577f1c5
DD
10122 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10123 && peer->notify.code == BGP_NOTIFY_CEASE
10124 && (peer->notify.subcode
10125 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10126 || peer->notify.subcode
10127 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10128 && peer->notify.length) {
10129 char msgbuf[1024];
10130 const char *msg_str;
10131
10132 msg_str = bgp_notify_admin_message(
10133 msgbuf, sizeof(msgbuf),
10134 (uint8_t *)peer->notify.data,
10135 peer->notify.length);
10136 if (msg_str)
10137 json_object_string_add(
10138 json_peer,
10139 "lastShutdownDescription",
10140 msg_str);
10141 }
10142
c258527b 10143 }
3577f1c5
DD
10144 json_object_string_add(json_peer, "lastResetDueTo",
10145 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10146 json_object_int_add(json_peer, "lastResetCode",
10147 peer->last_reset);
3577f1c5
DD
10148 } else {
10149 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10150 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10151 code_str = bgp_notify_code_str(peer->notify.code);
10152 subcode_str =
10153 bgp_notify_subcode_str(peer->notify.code,
10154 peer->notify.subcode);
eea685b6 10155 vty_out(vty, " Notification %s (%s%s%s)\n",
3577f1c5 10156 peer->last_reset == PEER_DOWN_NOTIFY_SEND
eea685b6
DA
10157 ? "sent"
10158 : "received",
10159 code_str, subcode_str,
10160 peer->notify.hard_reset
10161 ? bgp_notify_subcode_str(
10162 BGP_NOTIFY_CEASE,
10163 BGP_NOTIFY_CEASE_HARD_RESET)
10164 : "");
3577f1c5 10165 } else {
e91c24c8 10166 vty_out(vty, " %s\n",
3577f1c5
DD
10167 peer_down_str[(int)peer->last_reset]);
10168 }
10169 }
10170}
10171
10172static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10173 safi_t safi)
10174{
feb17238 10175 return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]);
3577f1c5
DD
10176}
10177
10178static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10179 struct peer *peer, json_object *json_peer,
10180 int max_neighbor_width, bool use_json)
10181{
10182 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10183 int len;
10184
10185 if (use_json) {
10186 if (peer_dynamic_neighbor(peer))
10187 json_object_boolean_true_add(json_peer,
10188 "dynamicPeer");
10189 if (peer->hostname)
10190 json_object_string_add(json_peer, "hostname",
10191 peer->hostname);
10192
10193 if (peer->domainname)
10194 json_object_string_add(json_peer, "domainname",
10195 peer->domainname);
10196 json_object_int_add(json_peer, "connectionsEstablished",
10197 peer->established);
10198 json_object_int_add(json_peer, "connectionsDropped",
10199 peer->dropped);
10200 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10201 use_json, json_peer);
feb17238 10202 if (peer_established(peer))
3577f1c5
DD
10203 json_object_string_add(json_peer, "lastResetDueTo",
10204 "AFI/SAFI Not Negotiated");
10205 else
10206 bgp_show_peer_reset(NULL, peer, json_peer, true);
10207 } else {
10208 dn_flag[1] = '\0';
10209 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10210 if (peer->hostname
892fedb6 10211 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10212 len = vty_out(vty, "%s%s(%s)", dn_flag,
10213 peer->hostname, peer->host);
10214 else
10215 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10216
10217 /* pad the neighbor column with spaces */
10218 if (len < max_neighbor_width)
10219 vty_out(vty, "%*s", max_neighbor_width - len,
10220 " ");
e91c24c8 10221 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10222 peer->dropped,
10223 peer_uptime(peer->uptime, timebuf,
10224 BGP_UPTIME_LEN, 0, NULL));
feb17238 10225 if (peer_established(peer))
3577f1c5
DD
10226 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10227 else
10228 bgp_show_peer_reset(vty, peer, NULL,
10229 false);
10230 }
10231}
c258527b 10232
565e9ddd 10233/* Strip peer's description to the given size. */
cb75bb31
DA
10234static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10235{
10236 static char stripped[BUFSIZ];
cb75bb31
DA
10237 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10238
cb75bb31
DA
10239 strlcpy(stripped, desc, len + 1);
10240
10241 return stripped;
10242}
3577f1c5 10243
8c1d4cd5
LS
10244/* Determine whether var peer should be filtered out of the summary. */
10245static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10246 struct peer *fpeer, int as_type,
10247 as_t as)
10248{
10249
10250 /* filter neighbor XXXX */
10251 if (fpeer && fpeer != peer)
10252 return true;
10253
10254 /* filter remote-as (internal|external) */
10255 if (as_type != AS_UNSPECIFIED) {
10256 if (peer->as_type == AS_SPECIFIED) {
10257 if (as_type == AS_INTERNAL) {
10258 if (peer->as != peer->local_as)
10259 return true;
10260 } else if (peer->as == peer->local_as)
10261 return true;
10262 } else if (as_type != peer->as_type)
10263 return true;
10264 } else if (as && as != peer->as) /* filter remote-as XXX */
10265 return true;
10266
10267 return false;
10268}
10269
565e9ddd
DA
10270/* Show BGP peer's summary information.
10271 *
10272 * Peer's description is stripped according to if `wide` option is given
10273 * or not.
10274 *
10275 * When adding new columns to `show bgp summary` output, please make
10276 * sure `Desc` is the lastest column to show because it can contain
10277 * whitespaces and the whole output will be tricky.
10278 */
d62a17ae 10279static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10280 struct peer *fpeer, int as_type, as_t as,
96c81f66 10281 uint16_t show_flags)
d62a17ae 10282{
10283 struct peer *peer;
10284 struct listnode *node, *nnode;
10285 unsigned int count = 0, dn_count = 0;
10286 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10287 char neighbor_buf[VTY_BUFSIZ];
10288 int neighbor_col_default_width = 16;
3577f1c5 10289 int len, failed_count = 0;
ce1944f0 10290 unsigned int filtered_count = 0;
d62a17ae 10291 int max_neighbor_width = 0;
10292 int pfx_rcd_safi;
3c13337d 10293 json_object *json = NULL;
d62a17ae 10294 json_object *json_peer = NULL;
10295 json_object *json_peers = NULL;
50e05855 10296 struct peer_af *paf;
d3ada366 10297 struct bgp_filter *filter;
85eeb029
DA
10298 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10299 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10300 bool show_established =
10301 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10302 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
96c81f66 10303 bool show_terse = CHECK_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
d62a17ae 10304
10305 /* labeled-unicast routes are installed in the unicast table so in order
10306 * to
10307 * display the correct PfxRcd value we must look at SAFI_UNICAST
10308 */
3577f1c5 10309
d62a17ae 10310 if (safi == SAFI_LABELED_UNICAST)
10311 pfx_rcd_safi = SAFI_UNICAST;
10312 else
10313 pfx_rcd_safi = safi;
10314
10315 if (use_json) {
3c13337d 10316 json = json_object_new_object();
d62a17ae 10317 json_peers = json_object_new_object();
3577f1c5 10318 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10319 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10320 as_type, as)) {
ce1944f0 10321 filtered_count++;
8c1d4cd5
LS
10322 count++;
10323 continue;
10324 }
10325
3577f1c5
DD
10326 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10327 continue;
10328
10329 if (peer->afc[afi][safi]) {
10330 /* See if we have at least a single failed peer */
10331 if (bgp_has_peer_failed(peer, afi, safi))
10332 failed_count++;
10333 count++;
10334 }
10335 if (peer_dynamic_neighbor(peer))
10336 dn_count++;
10337 }
c258527b 10338
d62a17ae 10339 } else {
10340 /* Loop over all neighbors that will be displayed to determine
10341 * how many
10342 * characters are needed for the Neighbor column
10343 */
10344 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10345 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10346 as_type, as)) {
ce1944f0 10347 filtered_count++;
8c1d4cd5
LS
10348 count++;
10349 continue;
10350 }
10351
d62a17ae 10352 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10353 continue;
10354
10355 if (peer->afc[afi][safi]) {
10356 memset(dn_flag, '\0', sizeof(dn_flag));
10357 if (peer_dynamic_neighbor(peer))
10358 dn_flag[0] = '*';
10359
10360 if (peer->hostname
892fedb6
DA
10361 && CHECK_FLAG(bgp->flags,
10362 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10363 snprintf(neighbor_buf,
10364 sizeof(neighbor_buf),
10365 "%s%s(%s) ", dn_flag,
10366 peer->hostname, peer->host);
d62a17ae 10367 else
772270f3
QY
10368 snprintf(neighbor_buf,
10369 sizeof(neighbor_buf), "%s%s ",
10370 dn_flag, peer->host);
d62a17ae 10371
10372 len = strlen(neighbor_buf);
10373
10374 if (len > max_neighbor_width)
10375 max_neighbor_width = len;
c258527b 10376
3577f1c5
DD
10377 /* See if we have at least a single failed peer */
10378 if (bgp_has_peer_failed(peer, afi, safi))
10379 failed_count++;
10380 count++;
d62a17ae 10381 }
10382 }
f933309e 10383
d62a17ae 10384 /* Originally we displayed the Neighbor column as 16
10385 * characters wide so make that the default
10386 */
10387 if (max_neighbor_width < neighbor_col_default_width)
10388 max_neighbor_width = neighbor_col_default_width;
10389 }
f933309e 10390
3577f1c5
DD
10391 if (show_failed && !failed_count) {
10392 if (use_json) {
10393 json_object_int_add(json, "failedPeersCount", 0);
10394 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10395 json_object_int_add(json, "totalPeers", count);
3577f1c5 10396
75eeda93 10397 vty_json(vty, json);
3577f1c5
DD
10398 } else {
10399 vty_out(vty, "%% No failed BGP neighbors found\n");
3577f1c5
DD
10400 }
10401 return CMD_SUCCESS;
10402 }
c258527b 10403
3577f1c5 10404 count = 0; /* Reset the value as its used again */
ce1944f0 10405 filtered_count = 0;
800867d8 10406 dn_count = 0;
d62a17ae 10407 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10408 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10409 continue;
10410
ea47320b
DL
10411 if (!peer->afc[afi][safi])
10412 continue;
d62a17ae 10413
ea47320b
DL
10414 if (!count) {
10415 unsigned long ents;
10416 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10417 int64_t vrf_id_ui;
d62a17ae 10418
a4d82a8a
PZ
10419 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10420 ? -1
10421 : (int64_t)bgp->vrf_id;
ea47320b
DL
10422
10423 /* Usage summary and header */
10424 if (use_json) {
c949c771
DA
10425 json_object_string_addf(json, "routerId",
10426 "%pI4",
10427 &bgp->router_id);
60466a63
QY
10428 json_object_int_add(json, "as", bgp->as);
10429 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10430 json_object_string_add(
10431 json, "vrfName",
10432 (bgp->inst_type
10433 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10434 ? VRF_DEFAULT_NAME
ea47320b
DL
10435 : bgp->name);
10436 } else {
10437 vty_out(vty,
23d0a753
DA
10438 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10439 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10440 bgp->vrf_id == VRF_UNKNOWN
10441 ? -1
10442 : (int)bgp->vrf_id);
ea47320b
DL
10443 vty_out(vty, "\n");
10444 }
d62a17ae 10445
ea47320b 10446 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10447 if (use_json) {
ea47320b 10448 json_object_int_add(
60466a63 10449 json, "updateDelayLimit",
ea47320b 10450 bgp->v_update_delay);
d62a17ae 10451
ea47320b
DL
10452 if (bgp->v_update_delay
10453 != bgp->v_establish_wait)
d62a17ae 10454 json_object_int_add(
10455 json,
ea47320b
DL
10456 "updateDelayEstablishWait",
10457 bgp->v_establish_wait);
d62a17ae 10458
60466a63 10459 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10460 json_object_string_add(
10461 json,
10462 "updateDelayFirstNeighbor",
10463 bgp->update_delay_begin_time);
10464 json_object_boolean_true_add(
10465 json,
10466 "updateDelayInProgress");
10467 } else {
10468 if (bgp->update_delay_over) {
d62a17ae 10469 json_object_string_add(
10470 json,
10471 "updateDelayFirstNeighbor",
10472 bgp->update_delay_begin_time);
ea47320b 10473 json_object_string_add(
d62a17ae 10474 json,
ea47320b
DL
10475 "updateDelayBestpathResumed",
10476 bgp->update_delay_end_time);
10477 json_object_string_add(
d62a17ae 10478 json,
ea47320b
DL
10479 "updateDelayZebraUpdateResume",
10480 bgp->update_delay_zebra_resume_time);
10481 json_object_string_add(
10482 json,
10483 "updateDelayPeerUpdateResume",
10484 bgp->update_delay_peers_resume_time);
d62a17ae 10485 }
ea47320b
DL
10486 }
10487 } else {
10488 vty_out(vty,
10489 "Read-only mode update-delay limit: %d seconds\n",
10490 bgp->v_update_delay);
10491 if (bgp->v_update_delay
10492 != bgp->v_establish_wait)
d62a17ae 10493 vty_out(vty,
ea47320b
DL
10494 " Establish wait: %d seconds\n",
10495 bgp->v_establish_wait);
d62a17ae 10496
60466a63 10497 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10498 vty_out(vty,
10499 " First neighbor established: %s\n",
10500 bgp->update_delay_begin_time);
10501 vty_out(vty,
10502 " Delay in progress\n");
10503 } else {
10504 if (bgp->update_delay_over) {
d62a17ae 10505 vty_out(vty,
10506 " First neighbor established: %s\n",
10507 bgp->update_delay_begin_time);
10508 vty_out(vty,
ea47320b
DL
10509 " Best-paths resumed: %s\n",
10510 bgp->update_delay_end_time);
10511 vty_out(vty,
10512 " zebra update resumed: %s\n",
10513 bgp->update_delay_zebra_resume_time);
10514 vty_out(vty,
10515 " peers update resumed: %s\n",
10516 bgp->update_delay_peers_resume_time);
d62a17ae 10517 }
10518 }
10519 }
ea47320b 10520 }
d62a17ae 10521
ea47320b
DL
10522 if (use_json) {
10523 if (bgp_maxmed_onstartup_configured(bgp)
10524 && bgp->maxmed_active)
10525 json_object_boolean_true_add(
60466a63 10526 json, "maxMedOnStartup");
ea47320b
DL
10527 if (bgp->v_maxmed_admin)
10528 json_object_boolean_true_add(
60466a63 10529 json, "maxMedAdministrative");
d62a17ae 10530
ea47320b
DL
10531 json_object_int_add(
10532 json, "tableVersion",
60466a63 10533 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10534
60466a63
QY
10535 ents = bgp_table_count(bgp->rib[afi][safi]);
10536 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10537 json_object_int_add(
10538 json, "ribMemory",
9bcb3eef 10539 ents * sizeof(struct bgp_dest));
d62a17ae 10540
210ec2a0 10541 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10542 json_object_int_add(json, "peerCount", ents);
10543 json_object_int_add(json, "peerMemory",
10544 ents * sizeof(struct peer));
d62a17ae 10545
ea47320b
DL
10546 if ((ents = listcount(bgp->group))) {
10547 json_object_int_add(
60466a63 10548 json, "peerGroupCount", ents);
ea47320b
DL
10549 json_object_int_add(
10550 json, "peerGroupMemory",
996c9314
LB
10551 ents * sizeof(struct
10552 peer_group));
ea47320b 10553 }
d62a17ae 10554
ea47320b
DL
10555 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10556 BGP_CONFIG_DAMPENING))
10557 json_object_boolean_true_add(
60466a63 10558 json, "dampeningEnabled");
ea47320b 10559 } else {
96c81f66
LS
10560 if (!show_terse) {
10561 if (bgp_maxmed_onstartup_configured(bgp)
10562 && bgp->maxmed_active)
10563 vty_out(vty,
10564 "Max-med on-startup active\n");
10565 if (bgp->v_maxmed_admin)
10566 vty_out(vty,
10567 "Max-med administrative active\n");
d62a17ae 10568
96c81f66
LS
10569 vty_out(vty,
10570 "BGP table version %" PRIu64
10571 "\n",
10572 bgp_table_version(
10573 bgp->rib[afi][safi]));
ea47320b 10574
96c81f66
LS
10575 ents = bgp_table_count(
10576 bgp->rib[afi][safi]);
d62a17ae 10577 vty_out(vty,
96c81f66 10578 "RIB entries %ld, using %s of memory\n",
d62a17ae 10579 ents,
10580 mtype_memstr(
10581 memstrbuf,
10582 sizeof(memstrbuf),
96c81f66
LS
10583 ents
10584 * sizeof(
10585 struct
10586 bgp_dest)));
d62a17ae 10587
96c81f66
LS
10588 /* Peer related usage */
10589 ents = bgp->af_peer_count[afi][safi];
10590 vty_out(vty,
10591 "Peers %ld, using %s of memory\n",
10592 ents,
10593 mtype_memstr(
10594 memstrbuf,
10595 sizeof(memstrbuf),
10596 ents
10597 * sizeof(
10598 struct
10599 peer)));
d62a17ae 10600
96c81f66
LS
10601 if ((ents = listcount(bgp->group)))
10602 vty_out(vty,
10603 "Peer groups %ld, using %s of memory\n",
10604 ents,
10605 mtype_memstr(
10606 memstrbuf,
10607 sizeof(memstrbuf),
10608 ents
10609 * sizeof(
10610 struct
10611 peer_group)));
10612
10613 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10614 BGP_CONFIG_DAMPENING))
10615 vty_out(vty,
10616 "Dampening enabled.\n");
10617 }
10618 if (show_failed) {
10619 vty_out(vty, "\n");
10620
10621 /* Subtract 8 here because 'Neighbor' is
10622 * 8 characters */
10623 vty_out(vty, "Neighbor");
10624 vty_out(vty, "%*s",
10625 max_neighbor_width - 8, " ");
85eeb029
DA
10626 vty_out(vty,
10627 BGP_SHOW_SUMMARY_HEADER_FAILED);
96c81f66 10628 }
d62a17ae 10629 }
ea47320b 10630 }
d62a17ae 10631
d55811cc 10632 paf = peer_af_find(peer, afi, safi);
d3ada366 10633 filter = &peer->filter[afi][safi];
db92d226 10634
ea47320b 10635 count++;
3577f1c5
DD
10636 /* Works for both failed & successful cases */
10637 if (peer_dynamic_neighbor(peer))
10638 dn_count++;
d62a17ae 10639
ea47320b 10640 if (use_json) {
3577f1c5 10641 json_peer = NULL;
8c1d4cd5 10642 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10643 as_type, as)) {
10644 filtered_count++;
8c1d4cd5 10645 continue;
ce1944f0 10646 }
3577f1c5
DD
10647 if (show_failed &&
10648 bgp_has_peer_failed(peer, afi, safi)) {
10649 json_peer = json_object_new_object();
10650 bgp_show_failed_summary(vty, bgp, peer,
10651 json_peer, 0, use_json);
10652 } else if (!show_failed) {
10b49f14 10653 if (show_established
ce1944f0
LS
10654 && bgp_has_peer_failed(peer, afi, safi)) {
10655 filtered_count++;
10b49f14 10656 continue;
ce1944f0 10657 }
10b49f14 10658
3577f1c5
DD
10659 json_peer = json_object_new_object();
10660 if (peer_dynamic_neighbor(peer)) {
10661 json_object_boolean_true_add(json_peer,
10662 "dynamicPeer");
10663 }
d62a17ae 10664
3577f1c5
DD
10665 if (peer->hostname)
10666 json_object_string_add(json_peer, "hostname",
10667 peer->hostname);
10668
10669 if (peer->domainname)
10670 json_object_string_add(json_peer, "domainname",
10671 peer->domainname);
10672
10673 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
10674 json_object_int_add(
10675 json_peer, "localAs",
10676 peer->change_local_as
10677 ? peer->change_local_as
10678 : peer->local_as);
3577f1c5
DD
10679 json_object_int_add(json_peer, "version", 4);
10680 json_object_int_add(json_peer, "msgRcvd",
10681 PEER_TOTAL_RX(peer));
10682 json_object_int_add(json_peer, "msgSent",
10683 PEER_TOTAL_TX(peer));
10684
43aa5965
QY
10685 atomic_size_t outq_count, inq_count;
10686 outq_count = atomic_load_explicit(
10687 &peer->obuf->count,
10688 memory_order_relaxed);
10689 inq_count = atomic_load_explicit(
10690 &peer->ibuf->count,
10691 memory_order_relaxed);
10692
3577f1c5
DD
10693 json_object_int_add(json_peer, "tableVersion",
10694 peer->version[afi][safi]);
10695 json_object_int_add(json_peer, "outq",
43aa5965
QY
10696 outq_count);
10697 json_object_int_add(json_peer, "inq",
10698 inq_count);
3577f1c5
DD
10699 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10700 use_json, json_peer);
10701
3577f1c5
DD
10702 json_object_int_add(json_peer, "pfxRcd",
10703 peer->pcount[afi][pfx_rcd_safi]);
10704
3577f1c5 10705 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
10706 json_object_int_add(
10707 json_peer, "pfxSnt",
10708 (PAF_SUBGRP(paf))->scount);
10709 else
10710 json_object_int_add(json_peer, "pfxSnt",
10711 0);
0e1f8ab5
DA
10712
10713 /* BGP FSM state */
cb9196e7 10714 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
10715 || CHECK_FLAG(peer->bgp->flags,
10716 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
10717 json_object_string_add(json_peer,
10718 "state",
3577f1c5
DD
10719 "Idle (Admin)");
10720 else if (peer->afc_recv[afi][safi])
10721 json_object_string_add(
0e1f8ab5
DA
10722 json_peer, "state",
10723 lookup_msg(bgp_status_msg,
10724 peer->status, NULL));
10725 else if (CHECK_FLAG(
10726 peer->sflags,
10727 PEER_STATUS_PREFIX_OVERFLOW))
10728 json_object_string_add(json_peer,
10729 "state",
3577f1c5
DD
10730 "Idle (PfxCt)");
10731 else
10732 json_object_string_add(
0e1f8ab5
DA
10733 json_peer, "state",
10734 lookup_msg(bgp_status_msg,
10735 peer->status, NULL));
10736
10737 /* BGP peer state */
10738 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
10739 || CHECK_FLAG(peer->bgp->flags,
10740 BGP_FLAG_SHUTDOWN))
10741 json_object_string_add(json_peer,
10742 "peerState",
10743 "Admin");
10744 else if (CHECK_FLAG(
10745 peer->sflags,
10746 PEER_STATUS_PREFIX_OVERFLOW))
10747 json_object_string_add(json_peer,
10748 "peerState",
10749 "PfxCt");
10750 else if (CHECK_FLAG(peer->flags,
10751 PEER_FLAG_PASSIVE))
10752 json_object_string_add(json_peer,
10753 "peerState",
10754 "Passive");
10755 else if (CHECK_FLAG(peer->sflags,
10756 PEER_STATUS_NSF_WAIT))
10757 json_object_string_add(json_peer,
10758 "peerState",
10759 "NSF passive");
10760 else if (CHECK_FLAG(
10761 peer->bgp->flags,
10762 BGP_FLAG_EBGP_REQUIRES_POLICY)
10763 && (!bgp_inbound_policy_exists(peer,
10764 filter)
10765 || !bgp_outbound_policy_exists(
10766 peer, filter)))
10767 json_object_string_add(json_peer,
10768 "peerState",
10769 "Policy");
10770 else
10771 json_object_string_add(
10772 json_peer, "peerState", "OK");
10773
200116db
DD
10774 json_object_int_add(json_peer, "connectionsEstablished",
10775 peer->established);
10776 json_object_int_add(json_peer, "connectionsDropped",
10777 peer->dropped);
aa72bd7e
PG
10778 if (peer->desc)
10779 json_object_string_add(
10780 json_peer, "desc", peer->desc);
b4e9dcba 10781 }
3577f1c5
DD
10782 /* Avoid creating empty peer dicts in JSON */
10783 if (json_peer == NULL)
10784 continue;
ea47320b
DL
10785
10786 if (peer->conf_if)
60466a63 10787 json_object_string_add(json_peer, "idType",
ea47320b
DL
10788 "interface");
10789 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
10790 json_object_string_add(json_peer, "idType",
10791 "ipv4");
ea47320b 10792 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
10793 json_object_string_add(json_peer, "idType",
10794 "ipv6");
ea47320b
DL
10795 json_object_object_add(json_peers, peer->host,
10796 json_peer);
10797 } else {
8c1d4cd5 10798 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
ce1944f0
LS
10799 as_type, as)) {
10800 filtered_count++;
8c1d4cd5 10801 continue;
ce1944f0 10802 }
3577f1c5
DD
10803 if (show_failed &&
10804 bgp_has_peer_failed(peer, afi, safi)) {
10805 bgp_show_failed_summary(vty, bgp, peer, NULL,
10806 max_neighbor_width,
10807 use_json);
10808 } else if (!show_failed) {
10b49f14 10809 if (show_established
ce1944f0
LS
10810 && bgp_has_peer_failed(peer, afi, safi)) {
10811 filtered_count++;
10b49f14 10812 continue;
ce1944f0 10813 }
96c81f66
LS
10814
10815 if ((count - filtered_count) == 1) {
10816 /* display headline before the first
10817 * neighbor line */
10818 vty_out(vty, "\n");
10819
10820 /* Subtract 8 here because 'Neighbor' is
10821 * 8 characters */
10822 vty_out(vty, "Neighbor");
10823 vty_out(vty, "%*s",
10824 max_neighbor_width - 8, " ");
10825 vty_out(vty,
10826 show_wide
10827 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10828 : BGP_SHOW_SUMMARY_HEADER_ALL);
10829 }
10830
3577f1c5
DD
10831 memset(dn_flag, '\0', sizeof(dn_flag));
10832 if (peer_dynamic_neighbor(peer)) {
10833 dn_flag[0] = '*';
10834 }
d62a17ae 10835
3577f1c5 10836 if (peer->hostname
892fedb6
DA
10837 && CHECK_FLAG(bgp->flags,
10838 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 10839 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
10840 peer->hostname,
10841 peer->host);
d62a17ae 10842 else
3577f1c5
DD
10843 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10844
10845 /* pad the neighbor column with spaces */
10846 if (len < max_neighbor_width)
10847 vty_out(vty, "%*s", max_neighbor_width - len,
10848 " ");
10849
43aa5965
QY
10850 atomic_size_t outq_count, inq_count;
10851 outq_count = atomic_load_explicit(
10852 &peer->obuf->count,
10853 memory_order_relaxed);
10854 inq_count = atomic_load_explicit(
10855 &peer->ibuf->count,
10856 memory_order_relaxed);
10857
85eeb029
DA
10858 if (show_wide)
10859 vty_out(vty,
10860 "4 %10u %10u %9u %9u %8" PRIu64
10861 " %4zu %4zu %8s",
10862 peer->as,
10863 peer->change_local_as
10864 ? peer->change_local_as
10865 : peer->local_as,
10866 PEER_TOTAL_RX(peer),
10867 PEER_TOTAL_TX(peer),
10868 peer->version[afi][safi],
10869 inq_count, outq_count,
10870 peer_uptime(peer->uptime,
10871 timebuf,
10872 BGP_UPTIME_LEN, 0,
10873 NULL));
10874 else
10875 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
10876 " %4zu %4zu %8s",
10877 peer->as, PEER_TOTAL_RX(peer),
10878 PEER_TOTAL_TX(peer),
10879 peer->version[afi][safi],
10880 inq_count, outq_count,
10881 peer_uptime(peer->uptime,
10882 timebuf,
10883 BGP_UPTIME_LEN, 0,
10884 NULL));
3577f1c5 10885
feb17238 10886 if (peer_established(peer)) {
d3ada366
DA
10887 if (peer->afc_recv[afi][safi]) {
10888 if (CHECK_FLAG(
10889 bgp->flags,
10890 BGP_FLAG_EBGP_REQUIRES_POLICY)
10891 && !bgp_inbound_policy_exists(
10892 peer, filter))
10893 vty_out(vty, " %12s",
10894 "(Policy)");
10895 else
10896 vty_out(vty,
6cde4b45 10897 " %12u",
d3ada366
DA
10898 peer->pcount
10899 [afi]
10900 [pfx_rcd_safi]);
10901 } else {
749d0f27 10902 vty_out(vty, " NoNeg");
d3ada366 10903 }
db92d226 10904
d3ada366
DA
10905 if (paf && PAF_SUBGRP(paf)) {
10906 if (CHECK_FLAG(
10907 bgp->flags,
10908 BGP_FLAG_EBGP_REQUIRES_POLICY)
10909 && !bgp_outbound_policy_exists(
10910 peer, filter))
10911 vty_out(vty, " %8s",
10912 "(Policy)");
10913 else
10914 vty_out(vty,
6cde4b45 10915 " %8u",
d3ada366
DA
10916 (PAF_SUBGRP(
10917 paf))
10918 ->scount);
749d0f27
DA
10919 } else {
10920 vty_out(vty, " NoNeg");
d3ada366 10921 }
db92d226 10922 } else {
736b68f3
DS
10923 if (CHECK_FLAG(peer->flags,
10924 PEER_FLAG_SHUTDOWN)
10925 || CHECK_FLAG(peer->bgp->flags,
10926 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10927 vty_out(vty, " Idle (Admin)");
10928 else if (CHECK_FLAG(
10929 peer->sflags,
10930 PEER_STATUS_PREFIX_OVERFLOW))
10931 vty_out(vty, " Idle (PfxCt)");
10932 else
10933 vty_out(vty, " %12s",
10934 lookup_msg(bgp_status_msg,
10935 peer->status, NULL));
db92d226 10936
6cde4b45 10937 vty_out(vty, " %8u", 0);
3577f1c5 10938 }
565e9ddd
DA
10939 /* Make sure `Desc` column is the lastest in
10940 * the output.
10941 */
aa72bd7e 10942 if (peer->desc)
cb75bb31
DA
10943 vty_out(vty, " %s",
10944 bgp_peer_description_stripped(
85eeb029
DA
10945 peer->desc,
10946 show_wide ? 64 : 20));
aa72bd7e
PG
10947 else
10948 vty_out(vty, " N/A");
3577f1c5 10949 vty_out(vty, "\n");
d62a17ae 10950 }
3577f1c5 10951
d62a17ae 10952 }
10953 }
f933309e 10954
d62a17ae 10955 if (use_json) {
10956 json_object_object_add(json, "peers", json_peers);
3577f1c5 10957 json_object_int_add(json, "failedPeers", failed_count);
ce1944f0
LS
10958 json_object_int_add(json, "displayedPeers",
10959 count - filtered_count);
d62a17ae 10960 json_object_int_add(json, "totalPeers", count);
10961 json_object_int_add(json, "dynamicPeers", dn_count);
10962
3577f1c5
DD
10963 if (!show_failed)
10964 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10965
75eeda93 10966 vty_json(vty, json);
d62a17ae 10967 } else {
ce1944f0 10968 if (count) {
96c81f66
LS
10969 if (filtered_count == count)
10970 vty_out(vty, "\n%% No matching neighbor\n");
10971 else {
10972 if (show_failed)
10973 vty_out(vty, "\nDisplayed neighbors %d",
10974 failed_count);
10975 else if (as_type != AS_UNSPECIFIED || as
10976 || fpeer || show_established)
ce1944f0
LS
10977 vty_out(vty, "\nDisplayed neighbors %d",
10978 count - filtered_count);
96c81f66
LS
10979
10980 vty_out(vty, "\nTotal number of neighbors %d\n",
10981 count);
ce1944f0 10982 }
ce1944f0 10983 } else {
d6ceaca3 10984 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10985 get_afi_safi_str(afi, safi, false));
d62a17ae 10986 }
b05a1c8b 10987
d6ceaca3 10988 if (dn_count) {
d62a17ae 10989 vty_out(vty, "* - dynamic neighbor\n");
10990 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10991 dn_count, bgp->dynamic_neighbors_limit);
10992 }
10993 }
1ff9a340 10994
d62a17ae 10995 return CMD_SUCCESS;
718e3744 10996}
10997
d62a17ae 10998static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5 10999 int safi, struct peer *fpeer, int as_type,
96c81f66 11000 as_t as, uint16_t show_flags)
d62a17ae 11001{
11002 int is_first = 1;
11003 int afi_wildcard = (afi == AFI_MAX);
11004 int safi_wildcard = (safi == SAFI_MAX);
11005 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11006 bool nbr_output = false;
85eeb029 11007 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11008
11009 if (use_json && is_wildcard)
11010 vty_out(vty, "{\n");
11011 if (afi_wildcard)
11012 afi = 1; /* AFI_IP */
11013 while (afi < AFI_MAX) {
11014 if (safi_wildcard)
11015 safi = 1; /* SAFI_UNICAST */
11016 while (safi < SAFI_MAX) {
318cac96 11017 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11018 nbr_output = true;
f86897b9 11019
d62a17ae 11020 if (is_wildcard) {
11021 /*
11022 * So limit output to those afi/safi
11023 * pairs that
11024 * actualy have something interesting in
11025 * them
11026 */
11027 if (use_json) {
d62a17ae 11028 if (!is_first)
11029 vty_out(vty, ",\n");
11030 else
11031 is_first = 0;
11032
11033 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11034 get_afi_safi_str(afi,
11035 safi,
11036 true));
d62a17ae 11037 } else {
6cac2fcc
LS
11038 vty_out(vty,
11039 "\n%s Summary (%s):\n",
5cb5f4d0
DD
11040 get_afi_safi_str(afi,
11041 safi,
6cac2fcc
LS
11042 false),
11043 bgp->name_pretty);
d62a17ae 11044 }
11045 }
8c1d4cd5
LS
11046 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11047 as_type, as, show_flags);
d62a17ae 11048 }
11049 safi++;
d62a17ae 11050 if (!safi_wildcard)
11051 safi = SAFI_MAX;
11052 }
11053 afi++;
ee851c8c 11054 if (!afi_wildcard)
d62a17ae 11055 afi = AFI_MAX;
11056 }
11057
11058 if (use_json && is_wildcard)
11059 vty_out(vty, "}\n");
ca61fd25
DS
11060 else if (!nbr_output) {
11061 if (use_json)
11062 vty_out(vty, "{}\n");
11063 else
6cac2fcc
LS
11064 vty_out(vty, "%% No BGP neighbors found in %s\n",
11065 bgp->name_pretty);
ca61fd25 11066 }
d62a17ae 11067}
11068
11069static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11070 safi_t safi,
11071 const char *neighbor,
11072 int as_type, as_t as,
96c81f66 11073 uint16_t show_flags)
d62a17ae 11074{
11075 struct listnode *node, *nnode;
11076 struct bgp *bgp;
8c1d4cd5 11077 struct peer *fpeer = NULL;
d62a17ae 11078 int is_first = 1;
9f049418 11079 bool nbr_output = false;
85eeb029 11080 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11081
11082 if (use_json)
11083 vty_out(vty, "{\n");
11084
11085 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11086 nbr_output = true;
d62a17ae 11087 if (use_json) {
d62a17ae 11088 if (!is_first)
11089 vty_out(vty, ",\n");
11090 else
11091 is_first = 0;
11092
11093 vty_out(vty, "\"%s\":",
11094 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11095 ? VRF_DEFAULT_NAME
d62a17ae 11096 : bgp->name);
d62a17ae 11097 }
8c1d4cd5
LS
11098 if (neighbor) {
11099 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11100 use_json);
11101 if (!fpeer)
11102 continue;
11103 }
11104 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11105 as, show_flags);
d62a17ae 11106 }
11107
11108 if (use_json)
11109 vty_out(vty, "}\n");
9f049418
DS
11110 else if (!nbr_output)
11111 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11112}
11113
11114int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5 11115 safi_t safi, const char *neighbor, int as_type,
96c81f66 11116 as_t as, uint16_t show_flags)
d62a17ae 11117{
11118 struct bgp *bgp;
85eeb029 11119 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11120 struct peer *fpeer = NULL;
d62a17ae 11121
11122 if (name) {
11123 if (strmatch(name, "all")) {
85eeb029 11124 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11125 neighbor, as_type,
11126 as, show_flags);
d62a17ae 11127 return CMD_SUCCESS;
11128 } else {
11129 bgp = bgp_lookup_by_name(name);
11130
11131 if (!bgp) {
11132 if (use_json)
11133 vty_out(vty, "{}\n");
11134 else
11135 vty_out(vty,
ca61fd25 11136 "%% BGP instance not found\n");
d62a17ae 11137 return CMD_WARNING;
11138 }
11139
8c1d4cd5
LS
11140 if (neighbor) {
11141 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11142 use_json);
11143 if (!fpeer)
11144 return CMD_WARNING;
11145 }
11146 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11147 as_type, as, show_flags);
d62a17ae 11148 return CMD_SUCCESS;
11149 }
11150 }
11151
11152 bgp = bgp_get_default();
11153
8c1d4cd5
LS
11154 if (bgp) {
11155 if (neighbor) {
11156 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11157 use_json);
11158 if (!fpeer)
11159 return CMD_WARNING;
11160 }
11161 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11162 as, show_flags);
11163 } else {
ca61fd25
DS
11164 if (use_json)
11165 vty_out(vty, "{}\n");
11166 else
11167 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11168 return CMD_WARNING;
11169 }
d62a17ae 11170
11171 return CMD_SUCCESS;
4fb25c53
DW
11172}
11173
716b2d8a 11174/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11175DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11176 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11177 " [" BGP_SAFI_WITH_LABEL_CMD_STR
96c81f66 11178 "]] [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
11179 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11180 BGP_SAFI_WITH_LABEL_HELP_STR
11181 "Display the entries for all address families\n"
11182 "Summary of BGP neighbor status\n"
11183 "Show only sessions in Established state\n"
11184 "Show only sessions not in Established state\n"
11185 "Show only the specified neighbor session\n"
11186 "Neighbor to display information about\n"
11187 "Neighbor to display information about\n"
11188 "Neighbor on BGP configured interface\n"
11189 "Show only the specified remote AS sessions\n"
11190 "AS number\n"
11191 "Internal (iBGP) AS sessions\n"
11192 "External (eBGP) AS sessions\n"
96c81f66 11193 "Shorten the information on BGP instances\n"
8c1d4cd5 11194 "Increase table width for longer output\n" JSON_STR)
718e3744 11195{
d62a17ae 11196 char *vrf = NULL;
11197 afi_t afi = AFI_MAX;
11198 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11199 as_t as = 0; /* 0 means AS filter not set */
11200 int as_type = AS_UNSPECIFIED;
96c81f66 11201 uint16_t show_flags = 0;
d62a17ae 11202
11203 int idx = 0;
11204
11205 /* show [ip] bgp */
96f3485c 11206 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11207 afi = AFI_IP;
9a8bdf1c
PG
11208 /* [<vrf> VIEWVRFNAME] */
11209 if (argv_find(argv, argc, "vrf", &idx)) {
11210 vrf = argv[idx + 1]->arg;
11211 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11212 vrf = NULL;
11213 } else if (argv_find(argv, argc, "view", &idx))
11214 /* [<view> VIEWVRFNAME] */
11215 vrf = argv[idx + 1]->arg;
d62a17ae 11216 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11217 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11218 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11219 }
11220
3577f1c5 11221 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11222 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11223
10b49f14 11224 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11225 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11226
8c1d4cd5
LS
11227 if (argv_find(argv, argc, "remote-as", &idx)) {
11228 if (argv[idx + 1]->arg[0] == 'i')
11229 as_type = AS_INTERNAL;
11230 else if (argv[idx + 1]->arg[0] == 'e')
11231 as_type = AS_EXTERNAL;
11232 else
11233 as = (as_t)atoi(argv[idx + 1]->arg);
11234 }
11235
96c81f66
LS
11236 if (argv_find(argv, argc, "terse", &idx))
11237 SET_FLAG(show_flags, BGP_SHOW_OPT_TERSE);
11238
85eeb029
DA
11239 if (argv_find(argv, argc, "wide", &idx))
11240 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11241
11242 if (argv_find(argv, argc, "json", &idx))
11243 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11244
8c1d4cd5
LS
11245 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11246 show_flags);
d62a17ae 11247}
11248
5cb5f4d0 11249const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11250{
5cb5f4d0
DD
11251 if (for_json)
11252 return get_afi_safi_json_str(afi, safi);
d62a17ae 11253 else
5cb5f4d0 11254 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11255}
11256
d62a17ae 11257
11258static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11259 afi_t afi, safi_t safi,
d7c0a89a
QY
11260 uint16_t adv_smcap, uint16_t adv_rmcap,
11261 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11262 bool use_json, json_object *json_pref)
d62a17ae 11263{
11264 /* Send-Mode */
11265 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11266 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11267 if (use_json) {
11268 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11269 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11270 json_object_string_add(json_pref, "sendMode",
11271 "advertisedAndReceived");
11272 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11273 json_object_string_add(json_pref, "sendMode",
11274 "advertised");
11275 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11276 json_object_string_add(json_pref, "sendMode",
11277 "received");
11278 } else {
11279 vty_out(vty, " Send-mode: ");
11280 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11281 vty_out(vty, "advertised");
11282 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11283 vty_out(vty, "%sreceived",
11284 CHECK_FLAG(p->af_cap[afi][safi],
11285 adv_smcap)
11286 ? ", "
11287 : "");
11288 vty_out(vty, "\n");
11289 }
11290 }
11291
11292 /* Receive-Mode */
11293 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11294 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11295 if (use_json) {
11296 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11297 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11298 json_object_string_add(json_pref, "recvMode",
11299 "advertisedAndReceived");
11300 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11301 json_object_string_add(json_pref, "recvMode",
11302 "advertised");
11303 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11304 json_object_string_add(json_pref, "recvMode",
11305 "received");
11306 } else {
11307 vty_out(vty, " Receive-mode: ");
11308 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11309 vty_out(vty, "advertised");
11310 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11311 vty_out(vty, "%sreceived",
11312 CHECK_FLAG(p->af_cap[afi][safi],
11313 adv_rmcap)
11314 ? ", "
11315 : "");
11316 vty_out(vty, "\n");
11317 }
11318 }
11319}
11320
eea685b6
DA
11321static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty,
11322 struct peer *p,
11323 bool use_json,
11324 json_object *json)
2986cac2 11325{
eea685b6
DA
11326 bool rbit = false;
11327 bool nbit = false;
2986cac2 11328
13909c4f
DS
11329 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11330 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
feb17238 11331 && (peer_established(p))) {
eea685b6
DA
11332 rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV);
11333 nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV);
2986cac2 11334 }
11335
eea685b6
DA
11336 if (use_json) {
11337 json_object_boolean_add(json, "rBit", rbit);
11338 json_object_boolean_add(json, "nBit", nbit);
2986cac2 11339 } else {
eea685b6
DA
11340 vty_out(vty, "\n R bit: %s", rbit ? "True" : "False");
11341 vty_out(vty, "\n N bit: %s\n", nbit ? "True" : "False");
2986cac2 11342 }
11343}
11344
13909c4f
DS
11345static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11346 struct peer *peer,
11347 bool use_json,
11348 json_object *json)
2986cac2 11349{
2bb5d39b 11350 const char *mode = "NotApplicable";
2986cac2 11351
11352 if (!use_json)
a53ca37b 11353 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11354
13909c4f 11355 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
feb17238 11356 && (peer_established(peer))) {
2986cac2 11357
13909c4f
DS
11358 if ((peer->nsf_af_count == 0)
11359 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11360
2986cac2 11361 mode = "Disable";
11362
13909c4f
DS
11363 } else if (peer->nsf_af_count == 0
11364 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11365
2986cac2 11366 mode = "Helper";
11367
13909c4f
DS
11368 } else if (peer->nsf_af_count != 0
11369 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11370
2986cac2 11371 mode = "Restart";
2986cac2 11372 }
11373 }
11374
11375 if (use_json) {
13909c4f 11376 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11377 } else
11378 vty_out(vty, mode, "\n");
11379}
11380
13909c4f
DS
11381static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11382 struct peer *p,
11383 bool use_json,
11384 json_object *json)
2986cac2 11385{
11386 const char *mode = "Invalid";
11387
11388 if (!use_json)
a53ca37b 11389 vty_out(vty, " Local GR Mode: ");
2986cac2 11390
11391 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11392 mode = "Helper";
11393 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11394 mode = "Restart";
11395 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11396 mode = "Disable";
2ba1fe69 11397 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11398 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11399 mode = "Helper*";
11400 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11401 mode = "Restart*";
11402 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11403 mode = "Disable*";
11404 else
11405 mode = "Invalid*";
2ba1fe69 11406 }
2986cac2 11407
11408 if (use_json) {
13909c4f 11409 json_object_string_add(json, "localGrMode", mode);
2986cac2 11410 } else {
11411 vty_out(vty, mode, "\n");
11412 }
11413}
11414
13909c4f
DS
11415static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11416 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11417{
2ba1fe69 11418 afi_t afi;
11419 safi_t safi;
2986cac2 11420 json_object *json_afi_safi = NULL;
11421 json_object *json_timer = NULL;
11422 json_object *json_endofrib_status = NULL;
9e3b51a7 11423 bool eor_flag = false;
2986cac2 11424
df8d723c
DA
11425 FOREACH_AFI_SAFI_NSF (afi, safi) {
11426 if (!peer->afc[afi][safi])
11427 continue;
2986cac2 11428
df8d723c
DA
11429 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) ||
11430 !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11431 continue;
9e3b51a7 11432
df8d723c
DA
11433 if (use_json) {
11434 json_afi_safi = json_object_new_object();
11435 json_endofrib_status = json_object_new_object();
11436 json_timer = json_object_new_object();
11437 }
2986cac2 11438
df8d723c
DA
11439 if (peer->eor_stime[afi][safi] >= peer->pkt_stime[afi][safi])
11440 eor_flag = true;
11441 else
11442 eor_flag = false;
2986cac2 11443
df8d723c
DA
11444 if (!use_json) {
11445 vty_out(vty, " %s:\n",
11446 get_afi_safi_str(afi, safi, false));
2986cac2 11447
df8d723c
DA
11448 vty_out(vty, " F bit: ");
11449 }
2986cac2 11450
df8d723c
DA
11451 if (peer->nsf[afi][safi] &&
11452 CHECK_FLAG(peer->af_cap[afi][safi],
11453 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11454
df8d723c
DA
11455 if (use_json) {
11456 json_object_boolean_true_add(json_afi_safi,
11457 "fBit");
11458 } else
11459 vty_out(vty, "True\n");
11460 } else {
11461 if (use_json)
11462 json_object_boolean_false_add(json_afi_safi,
11463 "fBit");
11464 else
11465 vty_out(vty, "False\n");
11466 }
2986cac2 11467
df8d723c
DA
11468 if (!use_json)
11469 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11470
df8d723c
DA
11471 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11472 PEER_STATUS_EOR_SEND)) {
11473 if (use_json) {
11474 json_object_boolean_true_add(
11475 json_endofrib_status, "endOfRibSend");
9e3b51a7 11476
df8d723c
DA
11477 PRINT_EOR_JSON(eor_flag);
11478 } else {
11479 vty_out(vty, "Yes\n");
11480 vty_out(vty,
11481 " End-of-RIB sent after update: ");
2986cac2 11482
df8d723c
DA
11483 PRINT_EOR(eor_flag);
11484 }
11485 } else {
11486 if (use_json) {
11487 json_object_boolean_false_add(
11488 json_endofrib_status, "endOfRibSend");
11489 json_object_boolean_false_add(
11490 json_endofrib_status,
11491 "endOfRibSentAfterUpdate");
13909c4f 11492 } else {
df8d723c
DA
11493 vty_out(vty, "No\n");
11494 vty_out(vty,
11495 " End-of-RIB sent after update: ");
11496 vty_out(vty, "No\n");
13909c4f 11497 }
df8d723c 11498 }
2986cac2 11499
df8d723c
DA
11500 if (!use_json)
11501 vty_out(vty, " End-of-RIB received: ");
a53ca37b 11502
df8d723c
DA
11503 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11504 PEER_STATUS_EOR_RECEIVED)) {
11505 if (use_json)
11506 json_object_boolean_true_add(
11507 json_endofrib_status, "endOfRibRecv");
11508 else
11509 vty_out(vty, "Yes\n");
11510 } else {
11511 if (use_json)
11512 json_object_boolean_false_add(
11513 json_endofrib_status, "endOfRibRecv");
11514 else
11515 vty_out(vty, "No\n");
11516 }
11517
11518 if (use_json) {
11519 json_object_int_add(json_timer, "stalePathTimer",
11520 peer->bgp->stalepath_time);
11521
11522 if (peer->t_gr_stale != NULL) {
11523 json_object_int_add(json_timer,
11524 "stalePathTimerRemaining",
11525 thread_timer_remain_second(
11526 peer->t_gr_stale));
a53ca37b
DA
11527 }
11528
df8d723c
DA
11529 /* Display Configured Selection
11530 * Deferral only when when
11531 * Gr mode is enabled.
11532 */
11533 if (CHECK_FLAG(peer->flags,
11534 PEER_FLAG_GRACEFUL_RESTART)) {
13909c4f 11535 json_object_int_add(json_timer,
df8d723c 11536 "selectionDeferralTimer",
13909c4f 11537 peer->bgp->stalepath_time);
df8d723c 11538 }
2986cac2 11539
df8d723c
DA
11540 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11541 NULL) {
2986cac2 11542
df8d723c
DA
11543 json_object_int_add(
11544 json_timer,
11545 "selectionDeferralTimerRemaining",
11546 thread_timer_remain_second(
11547 peer->bgp->gr_info[afi][safi]
11548 .t_select_deferral));
11549 }
11550 } else {
11551 vty_out(vty, " Timers:\n");
11552 vty_out(vty,
11553 " Configured Stale Path Time(sec): %u\n",
11554 peer->bgp->stalepath_time);
2986cac2 11555
df8d723c 11556 if (peer->t_gr_stale != NULL)
13909c4f 11557 vty_out(vty,
df8d723c
DA
11558 " Stale Path Remaining(sec): %ld\n",
11559 thread_timer_remain_second(
11560 peer->t_gr_stale));
11561 /* Display Configured Selection
11562 * Deferral only when when
11563 * Gr mode is enabled.
11564 */
11565 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
11566 vty_out(vty,
11567 " Configured Selection Deferral Time(sec): %u\n",
11568 peer->bgp->select_defer_time);
2986cac2 11569
df8d723c
DA
11570 if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
11571 NULL)
11572 vty_out(vty,
11573 " Selection Deferral Time Remaining(sec): %ld\n",
11574 thread_timer_remain_second(
11575 peer->bgp->gr_info[afi][safi]
11576 .t_select_deferral));
11577 }
11578 if (use_json) {
11579 json_object_object_add(json_afi_safi, "endOfRibStatus",
11580 json_endofrib_status);
11581 json_object_object_add(json_afi_safi, "timers",
11582 json_timer);
11583 json_object_object_add(
11584 json, get_afi_safi_str(afi, safi, true),
11585 json_afi_safi);
2986cac2 11586 }
11587 }
11588}
11589
36235319
QY
11590static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11591 struct peer *p,
11592 bool use_json,
11593 json_object *json)
2986cac2 11594{
11595 if (use_json) {
11596 json_object *json_timer = NULL;
11597
11598 json_timer = json_object_new_object();
11599
13909c4f
DS
11600 json_object_int_add(json_timer, "configuredRestartTimer",
11601 p->bgp->restart_time);
2986cac2 11602
13909c4f
DS
11603 json_object_int_add(json_timer, "receivedRestartTimer",
11604 p->v_gr_restart);
2986cac2 11605
13909c4f
DS
11606 if (p->t_gr_restart != NULL)
11607 json_object_int_add(
11608 json_timer, "restartTimerRemaining",
11609 thread_timer_remain_second(p->t_gr_restart));
2986cac2 11610
11611 json_object_object_add(json, "timers", json_timer);
11612 } else {
11613
a53ca37b
DA
11614 vty_out(vty, " Timers:\n");
11615 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 11616 p->bgp->restart_time);
2986cac2 11617
a53ca37b 11618 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
11619 p->v_gr_restart);
11620 if (p->t_gr_restart != NULL)
a53ca37b 11621 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 11622 thread_timer_remain_second(p->t_gr_restart));
36235319 11623 if (p->t_gr_restart != NULL) {
a53ca37b 11624 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
11625 thread_timer_remain_second(p->t_gr_restart));
11626 }
2986cac2 11627 }
11628}
11629
11630static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 11631 bool use_json, json_object *json)
2986cac2 11632{
11633 char buf[SU_ADDRSTRLEN] = {0};
11634 char dn_flag[2] = {0};
2b7165e7
QY
11635 /* '*' + v6 address of neighbor */
11636 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 11637
2986cac2 11638 if (!p->conf_if && peer_dynamic_neighbor(p))
11639 dn_flag[0] = '*';
11640
11641 if (p->conf_if) {
11642 if (use_json)
13909c4f
DS
11643 json_object_string_add(
11644 json, "neighborAddr",
2986cac2 11645 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
11646 ? "none"
11647 : sockunion2str(&p->su, buf,
11648 SU_ADDRSTRLEN));
2986cac2 11649 else
13909c4f 11650 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 11651 BGP_PEER_SU_UNSPEC(p)
11652 ? "none"
11653 : sockunion2str(&p->su, buf,
11654 SU_ADDRSTRLEN));
11655 } else {
772270f3
QY
11656 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11657 p->host);
2986cac2 11658
11659 if (use_json)
36235319
QY
11660 json_object_string_add(json, "neighborAddr",
11661 neighborAddr);
2986cac2 11662 else
36235319 11663 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 11664 }
11665
11666 /* more gr info in new format */
11667 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11668}
11669
d62a17ae 11670static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 11671 safi_t safi, bool use_json,
d62a17ae 11672 json_object *json_neigh)
11673{
0291c246
MK
11674 struct bgp_filter *filter;
11675 struct peer_af *paf;
11676 char orf_pfx_name[BUFSIZ];
11677 int orf_pfx_count;
11678 json_object *json_af = NULL;
11679 json_object *json_prefA = NULL;
11680 json_object *json_prefB = NULL;
11681 json_object *json_addr = NULL;
fa36596c 11682 json_object *json_advmap = NULL;
d62a17ae 11683
11684 if (use_json) {
11685 json_addr = json_object_new_object();
11686 json_af = json_object_new_object();
11687 filter = &p->filter[afi][safi];
11688
11689 if (peer_group_active(p))
11690 json_object_string_add(json_addr, "peerGroupMember",
11691 p->group->name);
11692
11693 paf = peer_af_find(p, afi, safi);
11694 if (paf && PAF_SUBGRP(paf)) {
11695 json_object_int_add(json_addr, "updateGroupId",
11696 PAF_UPDGRP(paf)->id);
11697 json_object_int_add(json_addr, "subGroupId",
11698 PAF_SUBGRP(paf)->id);
11699 json_object_int_add(json_addr, "packetQueueLength",
11700 bpacket_queue_virtual_length(paf));
11701 }
11702
11703 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11704 || CHECK_FLAG(p->af_cap[afi][safi],
11705 PEER_CAP_ORF_PREFIX_SM_RCV)
11706 || CHECK_FLAG(p->af_cap[afi][safi],
11707 PEER_CAP_ORF_PREFIX_RM_ADV)
11708 || CHECK_FLAG(p->af_cap[afi][safi],
11709 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11710 json_object_int_add(json_af, "orfType",
11711 ORF_TYPE_PREFIX);
11712 json_prefA = json_object_new_object();
11713 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11714 PEER_CAP_ORF_PREFIX_SM_ADV,
11715 PEER_CAP_ORF_PREFIX_RM_ADV,
11716 PEER_CAP_ORF_PREFIX_SM_RCV,
11717 PEER_CAP_ORF_PREFIX_RM_RCV,
11718 use_json, json_prefA);
11719 json_object_object_add(json_af, "orfPrefixList",
11720 json_prefA);
11721 }
11722
11723 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11724 || CHECK_FLAG(p->af_cap[afi][safi],
11725 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11726 || CHECK_FLAG(p->af_cap[afi][safi],
11727 PEER_CAP_ORF_PREFIX_RM_ADV)
11728 || CHECK_FLAG(p->af_cap[afi][safi],
11729 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11730 json_object_int_add(json_af, "orfOldType",
11731 ORF_TYPE_PREFIX_OLD);
11732 json_prefB = json_object_new_object();
11733 bgp_show_peer_afi_orf_cap(
11734 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11735 PEER_CAP_ORF_PREFIX_RM_ADV,
11736 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11737 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11738 json_prefB);
11739 json_object_object_add(json_af, "orfOldPrefixList",
11740 json_prefB);
11741 }
11742
11743 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11744 || CHECK_FLAG(p->af_cap[afi][safi],
11745 PEER_CAP_ORF_PREFIX_SM_RCV)
11746 || CHECK_FLAG(p->af_cap[afi][safi],
11747 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11748 || CHECK_FLAG(p->af_cap[afi][safi],
11749 PEER_CAP_ORF_PREFIX_RM_ADV)
11750 || CHECK_FLAG(p->af_cap[afi][safi],
11751 PEER_CAP_ORF_PREFIX_RM_RCV)
11752 || CHECK_FLAG(p->af_cap[afi][safi],
11753 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11754 json_object_object_add(json_addr, "afDependentCap",
11755 json_af);
11756 else
11757 json_object_free(json_af);
11758
772270f3
QY
11759 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11760 p->host, afi, safi);
d62a17ae 11761 orf_pfx_count = prefix_bgp_show_prefix_list(
11762 NULL, afi, orf_pfx_name, use_json);
11763
11764 if (CHECK_FLAG(p->af_sflags[afi][safi],
11765 PEER_STATUS_ORF_PREFIX_SEND)
11766 || orf_pfx_count) {
11767 if (CHECK_FLAG(p->af_sflags[afi][safi],
11768 PEER_STATUS_ORF_PREFIX_SEND))
11769 json_object_boolean_true_add(json_neigh,
11770 "orfSent");
11771 if (orf_pfx_count)
11772 json_object_int_add(json_addr, "orfRecvCounter",
11773 orf_pfx_count);
11774 }
11775 if (CHECK_FLAG(p->af_sflags[afi][safi],
11776 PEER_STATUS_ORF_WAIT_REFRESH))
11777 json_object_string_add(
11778 json_addr, "orfFirstUpdate",
11779 "deferredUntilORFOrRouteRefreshRecvd");
11780
11781 if (CHECK_FLAG(p->af_flags[afi][safi],
11782 PEER_FLAG_REFLECTOR_CLIENT))
11783 json_object_boolean_true_add(json_addr,
11784 "routeReflectorClient");
11785 if (CHECK_FLAG(p->af_flags[afi][safi],
11786 PEER_FLAG_RSERVER_CLIENT))
11787 json_object_boolean_true_add(json_addr,
11788 "routeServerClient");
11789 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11790 json_object_boolean_true_add(json_addr,
11791 "inboundSoftConfigPermit");
11792
11793 if (CHECK_FLAG(p->af_flags[afi][safi],
11794 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11795 json_object_boolean_true_add(
11796 json_addr,
11797 "privateAsNumsAllReplacedInUpdatesToNbr");
11798 else if (CHECK_FLAG(p->af_flags[afi][safi],
11799 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11800 json_object_boolean_true_add(
11801 json_addr,
11802 "privateAsNumsReplacedInUpdatesToNbr");
11803 else if (CHECK_FLAG(p->af_flags[afi][safi],
11804 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11805 json_object_boolean_true_add(
11806 json_addr,
11807 "privateAsNumsAllRemovedInUpdatesToNbr");
11808 else if (CHECK_FLAG(p->af_flags[afi][safi],
11809 PEER_FLAG_REMOVE_PRIVATE_AS))
11810 json_object_boolean_true_add(
11811 json_addr,
11812 "privateAsNumsRemovedInUpdatesToNbr");
11813
dcc68b5e
MS
11814 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11815 json_object_boolean_true_add(
11816 json_addr,
11817 bgp_addpath_names(p->addpath_type[afi][safi])
11818 ->type_json_name);
d62a17ae 11819
11820 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11821 json_object_string_add(json_addr,
11822 "overrideASNsInOutboundUpdates",
11823 "ifAspathEqualRemoteAs");
11824
11825 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11826 || CHECK_FLAG(p->af_flags[afi][safi],
11827 PEER_FLAG_FORCE_NEXTHOP_SELF))
11828 json_object_boolean_true_add(json_addr,
11829 "routerAlwaysNextHop");
11830 if (CHECK_FLAG(p->af_flags[afi][safi],
11831 PEER_FLAG_AS_PATH_UNCHANGED))
11832 json_object_boolean_true_add(
11833 json_addr, "unchangedAsPathPropogatedToNbr");
11834 if (CHECK_FLAG(p->af_flags[afi][safi],
11835 PEER_FLAG_NEXTHOP_UNCHANGED))
11836 json_object_boolean_true_add(
11837 json_addr, "unchangedNextHopPropogatedToNbr");
11838 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11839 json_object_boolean_true_add(
11840 json_addr, "unchangedMedPropogatedToNbr");
11841 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11842 || CHECK_FLAG(p->af_flags[afi][safi],
11843 PEER_FLAG_SEND_EXT_COMMUNITY)) {
11844 if (CHECK_FLAG(p->af_flags[afi][safi],
11845 PEER_FLAG_SEND_COMMUNITY)
11846 && CHECK_FLAG(p->af_flags[afi][safi],
11847 PEER_FLAG_SEND_EXT_COMMUNITY))
11848 json_object_string_add(json_addr,
11849 "commAttriSentToNbr",
11850 "extendedAndStandard");
11851 else if (CHECK_FLAG(p->af_flags[afi][safi],
11852 PEER_FLAG_SEND_EXT_COMMUNITY))
11853 json_object_string_add(json_addr,
11854 "commAttriSentToNbr",
11855 "extended");
11856 else
11857 json_object_string_add(json_addr,
11858 "commAttriSentToNbr",
11859 "standard");
11860 }
11861 if (CHECK_FLAG(p->af_flags[afi][safi],
11862 PEER_FLAG_DEFAULT_ORIGINATE)) {
11863 if (p->default_rmap[afi][safi].name)
11864 json_object_string_add(
11865 json_addr, "defaultRouteMap",
11866 p->default_rmap[afi][safi].name);
11867
11868 if (paf && PAF_SUBGRP(paf)
11869 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11870 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11871 json_object_boolean_true_add(json_addr,
11872 "defaultSent");
11873 else
11874 json_object_boolean_true_add(json_addr,
11875 "defaultNotSent");
11876 }
11877
dff8f48d 11878 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11879 if (is_evpn_enabled())
60466a63
QY
11880 json_object_boolean_true_add(
11881 json_addr, "advertiseAllVnis");
dff8f48d
MK
11882 }
11883
d62a17ae 11884 if (filter->plist[FILTER_IN].name
11885 || filter->dlist[FILTER_IN].name
11886 || filter->aslist[FILTER_IN].name
11887 || filter->map[RMAP_IN].name)
11888 json_object_boolean_true_add(json_addr,
11889 "inboundPathPolicyConfig");
11890 if (filter->plist[FILTER_OUT].name
11891 || filter->dlist[FILTER_OUT].name
11892 || filter->aslist[FILTER_OUT].name
11893 || filter->map[RMAP_OUT].name || filter->usmap.name)
11894 json_object_boolean_true_add(
11895 json_addr, "outboundPathPolicyConfig");
11896
11897 /* prefix-list */
11898 if (filter->plist[FILTER_IN].name)
11899 json_object_string_add(json_addr,
11900 "incomingUpdatePrefixFilterList",
11901 filter->plist[FILTER_IN].name);
11902 if (filter->plist[FILTER_OUT].name)
11903 json_object_string_add(json_addr,
11904 "outgoingUpdatePrefixFilterList",
11905 filter->plist[FILTER_OUT].name);
11906
11907 /* distribute-list */
11908 if (filter->dlist[FILTER_IN].name)
11909 json_object_string_add(
11910 json_addr, "incomingUpdateNetworkFilterList",
11911 filter->dlist[FILTER_IN].name);
11912 if (filter->dlist[FILTER_OUT].name)
11913 json_object_string_add(
11914 json_addr, "outgoingUpdateNetworkFilterList",
11915 filter->dlist[FILTER_OUT].name);
11916
11917 /* filter-list. */
11918 if (filter->aslist[FILTER_IN].name)
11919 json_object_string_add(json_addr,
11920 "incomingUpdateAsPathFilterList",
11921 filter->aslist[FILTER_IN].name);
11922 if (filter->aslist[FILTER_OUT].name)
11923 json_object_string_add(json_addr,
11924 "outgoingUpdateAsPathFilterList",
11925 filter->aslist[FILTER_OUT].name);
11926
11927 /* route-map. */
11928 if (filter->map[RMAP_IN].name)
11929 json_object_string_add(
11930 json_addr, "routeMapForIncomingAdvertisements",
11931 filter->map[RMAP_IN].name);
11932 if (filter->map[RMAP_OUT].name)
11933 json_object_string_add(
11934 json_addr, "routeMapForOutgoingAdvertisements",
11935 filter->map[RMAP_OUT].name);
11936
9dac9fc8 11937 /* ebgp-requires-policy (inbound) */
1d3fdccf 11938 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11939 && !bgp_inbound_policy_exists(p, filter))
11940 json_object_string_add(
11941 json_addr, "inboundEbgpRequiresPolicy",
11942 "Inbound updates discarded due to missing policy");
11943
11944 /* ebgp-requires-policy (outbound) */
1d3fdccf 11945 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11946 && (!bgp_outbound_policy_exists(p, filter)))
11947 json_object_string_add(
11948 json_addr, "outboundEbgpRequiresPolicy",
11949 "Outbound updates discarded due to missing policy");
11950
d62a17ae 11951 /* unsuppress-map */
11952 if (filter->usmap.name)
11953 json_object_string_add(json_addr,
11954 "selectiveUnsuppressRouteMap",
11955 filter->usmap.name);
11956
fa36596c
MK
11957 /* advertise-map */
11958 if (filter->advmap.aname) {
11959 json_advmap = json_object_new_object();
11960 json_object_string_add(json_advmap, "condition",
11961 filter->advmap.condition
11962 ? "EXIST"
11963 : "NON_EXIST");
11964 json_object_string_add(json_advmap, "conditionMap",
11965 filter->advmap.cname);
11966 json_object_string_add(json_advmap, "advertiseMap",
11967 filter->advmap.aname);
11968 json_object_string_add(json_advmap, "advertiseStatus",
11969 filter->advmap.update_type
11970 == ADVERTISE
11971 ? "Advertise"
11972 : "Withdraw");
11973 json_object_object_add(json_addr, "advertiseMap",
11974 json_advmap);
11975 }
11976
d62a17ae 11977 /* Receive prefix count */
11978 json_object_int_add(json_addr, "acceptedPrefixCounter",
11979 p->pcount[afi][safi]);
50e05855
AD
11980 if (paf && PAF_SUBGRP(paf))
11981 json_object_int_add(json_addr, "sentPrefixCounter",
11982 (PAF_SUBGRP(paf))->scount);
d62a17ae 11983
fde246e8
DA
11984 /* Maximum prefix */
11985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
11986 json_object_int_add(json_addr, "prefixOutAllowedMax",
11987 p->pmax_out[afi][safi]);
11988
d62a17ae 11989 /* Maximum prefix */
11990 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11991 json_object_int_add(json_addr, "prefixAllowedMax",
11992 p->pmax[afi][safi]);
11993 if (CHECK_FLAG(p->af_flags[afi][safi],
11994 PEER_FLAG_MAX_PREFIX_WARNING))
11995 json_object_boolean_true_add(
11996 json_addr, "prefixAllowedMaxWarning");
11997 json_object_int_add(json_addr,
11998 "prefixAllowedWarningThresh",
11999 p->pmax_threshold[afi][safi]);
12000 if (p->pmax_restart[afi][safi])
12001 json_object_int_add(
12002 json_addr,
12003 "prefixAllowedRestartIntervalMsecs",
12004 p->pmax_restart[afi][safi] * 60000);
12005 }
2986cac2 12006 json_object_object_add(json_neigh,
36235319 12007 get_afi_safi_str(afi, safi, true),
d62a17ae 12008 json_addr);
12009
12010 } else {
12011 filter = &p->filter[afi][safi];
12012
12013 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12014 get_afi_safi_str(afi, safi, false));
d62a17ae 12015
12016 if (peer_group_active(p))
12017 vty_out(vty, " %s peer-group member\n",
12018 p->group->name);
12019
12020 paf = peer_af_find(p, afi, safi);
12021 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12022 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12023 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12024 vty_out(vty, " Packet Queue length %d\n",
12025 bpacket_queue_virtual_length(paf));
12026 } else {
12027 vty_out(vty, " Not part of any update group\n");
12028 }
12029 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12030 || CHECK_FLAG(p->af_cap[afi][safi],
12031 PEER_CAP_ORF_PREFIX_SM_RCV)
12032 || CHECK_FLAG(p->af_cap[afi][safi],
12033 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12034 || CHECK_FLAG(p->af_cap[afi][safi],
12035 PEER_CAP_ORF_PREFIX_RM_ADV)
12036 || CHECK_FLAG(p->af_cap[afi][safi],
12037 PEER_CAP_ORF_PREFIX_RM_RCV)
12038 || CHECK_FLAG(p->af_cap[afi][safi],
12039 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12040 vty_out(vty, " AF-dependant capabilities:\n");
12041
12042 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12043 || CHECK_FLAG(p->af_cap[afi][safi],
12044 PEER_CAP_ORF_PREFIX_SM_RCV)
12045 || CHECK_FLAG(p->af_cap[afi][safi],
12046 PEER_CAP_ORF_PREFIX_RM_ADV)
12047 || CHECK_FLAG(p->af_cap[afi][safi],
12048 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12049 vty_out(vty,
12050 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12051 ORF_TYPE_PREFIX);
12052 bgp_show_peer_afi_orf_cap(
12053 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12054 PEER_CAP_ORF_PREFIX_RM_ADV,
12055 PEER_CAP_ORF_PREFIX_SM_RCV,
12056 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12057 }
12058 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12059 || CHECK_FLAG(p->af_cap[afi][safi],
12060 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12061 || CHECK_FLAG(p->af_cap[afi][safi],
12062 PEER_CAP_ORF_PREFIX_RM_ADV)
12063 || CHECK_FLAG(p->af_cap[afi][safi],
12064 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12065 vty_out(vty,
12066 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12067 ORF_TYPE_PREFIX_OLD);
12068 bgp_show_peer_afi_orf_cap(
12069 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12070 PEER_CAP_ORF_PREFIX_RM_ADV,
12071 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12072 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12073 }
12074
772270f3
QY
12075 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12076 p->host, afi, safi);
d62a17ae 12077 orf_pfx_count = prefix_bgp_show_prefix_list(
12078 NULL, afi, orf_pfx_name, use_json);
12079
12080 if (CHECK_FLAG(p->af_sflags[afi][safi],
12081 PEER_STATUS_ORF_PREFIX_SEND)
12082 || orf_pfx_count) {
12083 vty_out(vty, " Outbound Route Filter (ORF):");
12084 if (CHECK_FLAG(p->af_sflags[afi][safi],
12085 PEER_STATUS_ORF_PREFIX_SEND))
12086 vty_out(vty, " sent;");
12087 if (orf_pfx_count)
12088 vty_out(vty, " received (%d entries)",
12089 orf_pfx_count);
12090 vty_out(vty, "\n");
12091 }
12092 if (CHECK_FLAG(p->af_sflags[afi][safi],
12093 PEER_STATUS_ORF_WAIT_REFRESH))
12094 vty_out(vty,
12095 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12096
12097 if (CHECK_FLAG(p->af_flags[afi][safi],
12098 PEER_FLAG_REFLECTOR_CLIENT))
12099 vty_out(vty, " Route-Reflector Client\n");
12100 if (CHECK_FLAG(p->af_flags[afi][safi],
12101 PEER_FLAG_RSERVER_CLIENT))
12102 vty_out(vty, " Route-Server Client\n");
12103 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12104 vty_out(vty,
12105 " Inbound soft reconfiguration allowed\n");
12106
12107 if (CHECK_FLAG(p->af_flags[afi][safi],
12108 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12109 vty_out(vty,
12110 " Private AS numbers (all) replaced in updates to this neighbor\n");
12111 else if (CHECK_FLAG(p->af_flags[afi][safi],
12112 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12113 vty_out(vty,
12114 " Private AS numbers replaced in updates to this neighbor\n");
12115 else if (CHECK_FLAG(p->af_flags[afi][safi],
12116 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12117 vty_out(vty,
12118 " Private AS numbers (all) removed in updates to this neighbor\n");
12119 else if (CHECK_FLAG(p->af_flags[afi][safi],
12120 PEER_FLAG_REMOVE_PRIVATE_AS))
12121 vty_out(vty,
12122 " Private AS numbers removed in updates to this neighbor\n");
12123
dcc68b5e
MS
12124 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12125 vty_out(vty, " %s\n",
12126 bgp_addpath_names(p->addpath_type[afi][safi])
12127 ->human_description);
d62a17ae 12128
12129 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12130 vty_out(vty,
12131 " Override ASNs in outbound updates if aspath equals remote-as\n");
12132
12133 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12134 || CHECK_FLAG(p->af_flags[afi][safi],
12135 PEER_FLAG_FORCE_NEXTHOP_SELF))
12136 vty_out(vty, " NEXT_HOP is always this router\n");
12137 if (CHECK_FLAG(p->af_flags[afi][safi],
12138 PEER_FLAG_AS_PATH_UNCHANGED))
12139 vty_out(vty,
12140 " AS_PATH is propagated unchanged to this neighbor\n");
12141 if (CHECK_FLAG(p->af_flags[afi][safi],
12142 PEER_FLAG_NEXTHOP_UNCHANGED))
12143 vty_out(vty,
12144 " NEXT_HOP is propagated unchanged to this neighbor\n");
12145 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12146 vty_out(vty,
12147 " MED is propagated unchanged to this neighbor\n");
12148 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12149 || CHECK_FLAG(p->af_flags[afi][safi],
12150 PEER_FLAG_SEND_EXT_COMMUNITY)
12151 || CHECK_FLAG(p->af_flags[afi][safi],
12152 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12153 vty_out(vty,
12154 " Community attribute sent to this neighbor");
12155 if (CHECK_FLAG(p->af_flags[afi][safi],
12156 PEER_FLAG_SEND_COMMUNITY)
12157 && CHECK_FLAG(p->af_flags[afi][safi],
12158 PEER_FLAG_SEND_EXT_COMMUNITY)
12159 && CHECK_FLAG(p->af_flags[afi][safi],
12160 PEER_FLAG_SEND_LARGE_COMMUNITY))
12161 vty_out(vty, "(all)\n");
12162 else if (CHECK_FLAG(p->af_flags[afi][safi],
12163 PEER_FLAG_SEND_LARGE_COMMUNITY))
12164 vty_out(vty, "(large)\n");
12165 else if (CHECK_FLAG(p->af_flags[afi][safi],
12166 PEER_FLAG_SEND_EXT_COMMUNITY))
12167 vty_out(vty, "(extended)\n");
12168 else
12169 vty_out(vty, "(standard)\n");
12170 }
12171 if (CHECK_FLAG(p->af_flags[afi][safi],
12172 PEER_FLAG_DEFAULT_ORIGINATE)) {
12173 vty_out(vty, " Default information originate,");
12174
12175 if (p->default_rmap[afi][safi].name)
12176 vty_out(vty, " default route-map %s%s,",
12177 p->default_rmap[afi][safi].map ? "*"
12178 : "",
12179 p->default_rmap[afi][safi].name);
12180 if (paf && PAF_SUBGRP(paf)
12181 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12182 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12183 vty_out(vty, " default sent\n");
12184 else
12185 vty_out(vty, " default not sent\n");
12186 }
12187
dff8f48d
MK
12188 /* advertise-vni-all */
12189 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12190 if (is_evpn_enabled())
dff8f48d
MK
12191 vty_out(vty, " advertise-all-vni\n");
12192 }
12193
d62a17ae 12194 if (filter->plist[FILTER_IN].name
12195 || filter->dlist[FILTER_IN].name
12196 || filter->aslist[FILTER_IN].name
12197 || filter->map[RMAP_IN].name)
12198 vty_out(vty, " Inbound path policy configured\n");
12199 if (filter->plist[FILTER_OUT].name
12200 || filter->dlist[FILTER_OUT].name
12201 || filter->aslist[FILTER_OUT].name
12202 || filter->map[RMAP_OUT].name || filter->usmap.name)
12203 vty_out(vty, " Outbound path policy configured\n");
12204
12205 /* prefix-list */
12206 if (filter->plist[FILTER_IN].name)
12207 vty_out(vty,
12208 " Incoming update prefix filter list is %s%s\n",
12209 filter->plist[FILTER_IN].plist ? "*" : "",
12210 filter->plist[FILTER_IN].name);
12211 if (filter->plist[FILTER_OUT].name)
12212 vty_out(vty,
12213 " Outgoing update prefix filter list is %s%s\n",
12214 filter->plist[FILTER_OUT].plist ? "*" : "",
12215 filter->plist[FILTER_OUT].name);
12216
12217 /* distribute-list */
12218 if (filter->dlist[FILTER_IN].name)
12219 vty_out(vty,
12220 " Incoming update network filter list is %s%s\n",
12221 filter->dlist[FILTER_IN].alist ? "*" : "",
12222 filter->dlist[FILTER_IN].name);
12223 if (filter->dlist[FILTER_OUT].name)
12224 vty_out(vty,
12225 " Outgoing update network filter list is %s%s\n",
12226 filter->dlist[FILTER_OUT].alist ? "*" : "",
12227 filter->dlist[FILTER_OUT].name);
12228
12229 /* filter-list. */
12230 if (filter->aslist[FILTER_IN].name)
12231 vty_out(vty,
12232 " Incoming update AS path filter list is %s%s\n",
12233 filter->aslist[FILTER_IN].aslist ? "*" : "",
12234 filter->aslist[FILTER_IN].name);
12235 if (filter->aslist[FILTER_OUT].name)
12236 vty_out(vty,
12237 " Outgoing update AS path filter list is %s%s\n",
12238 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12239 filter->aslist[FILTER_OUT].name);
12240
12241 /* route-map. */
12242 if (filter->map[RMAP_IN].name)
12243 vty_out(vty,
12244 " Route map for incoming advertisements is %s%s\n",
12245 filter->map[RMAP_IN].map ? "*" : "",
12246 filter->map[RMAP_IN].name);
12247 if (filter->map[RMAP_OUT].name)
12248 vty_out(vty,
12249 " Route map for outgoing advertisements is %s%s\n",
12250 filter->map[RMAP_OUT].map ? "*" : "",
12251 filter->map[RMAP_OUT].name);
12252
9dac9fc8 12253 /* ebgp-requires-policy (inbound) */
1d3fdccf 12254 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12255 && !bgp_inbound_policy_exists(p, filter))
12256 vty_out(vty,
12257 " Inbound updates discarded due to missing policy\n");
12258
12259 /* ebgp-requires-policy (outbound) */
1d3fdccf 12260 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12261 && !bgp_outbound_policy_exists(p, filter))
12262 vty_out(vty,
12263 " Outbound updates discarded due to missing policy\n");
12264
d62a17ae 12265 /* unsuppress-map */
12266 if (filter->usmap.name)
12267 vty_out(vty,
12268 " Route map for selective unsuppress is %s%s\n",
12269 filter->usmap.map ? "*" : "",
12270 filter->usmap.name);
12271
7f7940e6
MK
12272 /* advertise-map */
12273 if (filter->advmap.aname && filter->advmap.cname)
12274 vty_out(vty,
12275 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12276 filter->advmap.condition ? "EXIST"
12277 : "NON_EXIST",
12278 filter->advmap.cmap ? "*" : "",
12279 filter->advmap.cname,
12280 filter->advmap.amap ? "*" : "",
12281 filter->advmap.aname,
fa36596c 12282 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12283 ? "Advertise"
12284 : "Withdraw");
7f7940e6 12285
d62a17ae 12286 /* Receive prefix count */
6cde4b45 12287 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12288 p->pcount[afi][safi]);
d62a17ae 12289
fde246e8
DA
12290 /* maximum-prefix-out */
12291 if (CHECK_FLAG(p->af_flags[afi][safi],
12292 PEER_FLAG_MAX_PREFIX_OUT))
12293 vty_out(vty,
6cde4b45 12294 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12295 p->pmax_out[afi][safi]);
12296
d62a17ae 12297 /* Maximum prefix */
12298 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12299 vty_out(vty,
6cde4b45 12300 " Maximum prefixes allowed %u%s\n",
d62a17ae 12301 p->pmax[afi][safi],
12302 CHECK_FLAG(p->af_flags[afi][safi],
12303 PEER_FLAG_MAX_PREFIX_WARNING)
12304 ? " (warning-only)"
12305 : "");
12306 vty_out(vty, " Threshold for warning message %d%%",
12307 p->pmax_threshold[afi][safi]);
12308 if (p->pmax_restart[afi][safi])
12309 vty_out(vty, ", restart interval %d min",
12310 p->pmax_restart[afi][safi]);
12311 vty_out(vty, "\n");
12312 }
12313
12314 vty_out(vty, "\n");
12315 }
12316}
12317
9f049418 12318static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12319 json_object *json)
718e3744 12320{
d62a17ae 12321 struct bgp *bgp;
12322 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12323 char timebuf[BGP_UPTIME_LEN];
12324 char dn_flag[2];
d62a17ae 12325 afi_t afi;
12326 safi_t safi;
d7c0a89a
QY
12327 uint16_t i;
12328 uint8_t *msg;
d62a17ae 12329 json_object *json_neigh = NULL;
12330 time_t epoch_tbuf;
4ab46701 12331 uint32_t sync_tcp_mss;
718e3744 12332
d62a17ae 12333 bgp = p->bgp;
12334
12335 if (use_json)
12336 json_neigh = json_object_new_object();
12337
12338 memset(dn_flag, '\0', sizeof(dn_flag));
12339 if (!p->conf_if && peer_dynamic_neighbor(p))
12340 dn_flag[0] = '*';
12341
12342 if (!use_json) {
12343 if (p->conf_if) /* Configured interface name. */
12344 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12345 BGP_PEER_SU_UNSPEC(p)
12346 ? "None"
12347 : sockunion2str(&p->su, buf,
12348 SU_ADDRSTRLEN));
12349 else /* Configured IP address. */
12350 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12351 p->host);
12352 }
12353
12354 if (use_json) {
12355 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12356 json_object_string_add(json_neigh, "bgpNeighborAddr",
12357 "none");
12358 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12359 json_object_string_add(
12360 json_neigh, "bgpNeighborAddr",
12361 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12362
12363 json_object_int_add(json_neigh, "remoteAs", p->as);
12364
12365 if (p->change_local_as)
12366 json_object_int_add(json_neigh, "localAs",
12367 p->change_local_as);
12368 else
12369 json_object_int_add(json_neigh, "localAs", p->local_as);
12370
12371 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12372 json_object_boolean_true_add(json_neigh,
12373 "localAsNoPrepend");
12374
12375 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12376 json_object_boolean_true_add(json_neigh,
12377 "localAsReplaceAs");
12378 } else {
12379 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12380 || (p->as_type == AS_INTERNAL))
12381 vty_out(vty, "remote AS %u, ", p->as);
12382 else
12383 vty_out(vty, "remote AS Unspecified, ");
12384 vty_out(vty, "local AS %u%s%s, ",
12385 p->change_local_as ? p->change_local_as : p->local_as,
12386 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12387 ? " no-prepend"
12388 : "",
12389 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12390 ? " replace-as"
12391 : "");
12392 }
faa16034
DS
12393 /* peer type internal or confed-internal */
12394 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12395 if (use_json) {
12396 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12397 json_object_boolean_true_add(
12398 json_neigh, "nbrConfedInternalLink");
12399 else
12400 json_object_boolean_true_add(json_neigh,
12401 "nbrInternalLink");
12402 } else {
12403 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12404 vty_out(vty, "confed-internal link\n");
12405 else
12406 vty_out(vty, "internal link\n");
12407 }
faa16034
DS
12408 /* peer type external or confed-external */
12409 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12410 if (use_json) {
12411 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12412 json_object_boolean_true_add(
12413 json_neigh, "nbrConfedExternalLink");
12414 else
12415 json_object_boolean_true_add(json_neigh,
12416 "nbrExternalLink");
12417 } else {
12418 if (bgp_confederation_peers_check(bgp, p->as))
12419 vty_out(vty, "confed-external link\n");
12420 else
12421 vty_out(vty, "external link\n");
12422 }
faa16034
DS
12423 } else {
12424 if (use_json)
12425 json_object_boolean_true_add(json_neigh,
12426 "nbrUnspecifiedLink");
12427 else
12428 vty_out(vty, "unspecified link\n");
d62a17ae 12429 }
12430
12431 /* Description. */
12432 if (p->desc) {
12433 if (use_json)
12434 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12435 else
12436 vty_out(vty, " Description: %s\n", p->desc);
12437 }
12438
12439 if (p->hostname) {
12440 if (use_json) {
12441 if (p->hostname)
12442 json_object_string_add(json_neigh, "hostname",
12443 p->hostname);
12444
12445 if (p->domainname)
12446 json_object_string_add(json_neigh, "domainname",
12447 p->domainname);
12448 } else {
12449 if (p->domainname && (p->domainname[0] != '\0'))
12450 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12451 p->domainname);
12452 else
12453 vty_out(vty, "Hostname: %s\n", p->hostname);
12454 }
12455 }
12456
12457 /* Peer-group */
12458 if (p->group) {
12459 if (use_json) {
12460 json_object_string_add(json_neigh, "peerGroup",
12461 p->group->name);
12462
12463 if (dn_flag[0]) {
12464 struct prefix prefix, *range = NULL;
12465
0154d8ce
DS
12466 if (sockunion2hostprefix(&(p->su), &prefix))
12467 range = peer_group_lookup_dynamic_neighbor_range(
12468 p->group, &prefix);
d62a17ae 12469
12470 if (range) {
67d7e256 12471 json_object_string_addf(
d62a17ae 12472 json_neigh,
67d7e256
DA
12473 "peerSubnetRangeGroup", "%pFX",
12474 range);
d62a17ae 12475 }
12476 }
12477 } else {
12478 vty_out(vty,
12479 " Member of peer-group %s for session parameters\n",
12480 p->group->name);
12481
12482 if (dn_flag[0]) {
12483 struct prefix prefix, *range = NULL;
12484
0154d8ce
DS
12485 if (sockunion2hostprefix(&(p->su), &prefix))
12486 range = peer_group_lookup_dynamic_neighbor_range(
12487 p->group, &prefix);
d62a17ae 12488
12489 if (range) {
d62a17ae 12490 vty_out(vty,
1b78780b
DL
12491 " Belongs to the subnet range group: %pFX\n",
12492 range);
d62a17ae 12493 }
12494 }
12495 }
12496 }
12497
12498 if (use_json) {
12499 /* Administrative shutdown. */
cb9196e7
DS
12500 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12501 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12502 json_object_boolean_true_add(json_neigh,
12503 "adminShutDown");
12504
12505 /* BGP Version. */
12506 json_object_int_add(json_neigh, "bgpVersion", 4);
c949c771
DA
12507 json_object_string_addf(json_neigh, "remoteRouterId", "%pI4",
12508 &p->remote_id);
12509 json_object_string_addf(json_neigh, "localRouterId", "%pI4",
12510 &bgp->router_id);
d62a17ae 12511
12512 /* Confederation */
12513 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12514 && bgp_confederation_peers_check(bgp, p->as))
12515 json_object_boolean_true_add(json_neigh,
12516 "nbrCommonAdmin");
12517
12518 /* Status. */
12519 json_object_string_add(
12520 json_neigh, "bgpState",
12521 lookup_msg(bgp_status_msg, p->status, NULL));
12522
feb17238 12523 if (peer_established(p)) {
d62a17ae 12524 time_t uptime;
d62a17ae 12525
12526 uptime = bgp_clock();
12527 uptime -= p->uptime;
d62a17ae 12528 epoch_tbuf = time(NULL) - uptime;
12529
d3c7efed
DS
12530 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12531 uptime * 1000);
d62a17ae 12532 json_object_string_add(json_neigh, "bgpTimerUpString",
12533 peer_uptime(p->uptime, timebuf,
12534 BGP_UPTIME_LEN, 0,
12535 NULL));
12536 json_object_int_add(json_neigh,
12537 "bgpTimerUpEstablishedEpoch",
12538 epoch_tbuf);
12539 }
12540
12541 else if (p->status == Active) {
12542 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12543 json_object_string_add(json_neigh, "bgpStateIs",
12544 "passive");
12545 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12546 json_object_string_add(json_neigh, "bgpStateIs",
12547 "passiveNSF");
12548 }
12549
12550 /* read timer */
12551 time_t uptime;
a2700b50 12552 struct tm tm;
d62a17ae 12553
12554 uptime = bgp_clock();
12555 uptime -= p->readtime;
a2700b50
MS
12556 gmtime_r(&uptime, &tm);
12557
d62a17ae 12558 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12559 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12560 + (tm.tm_hour * 3600000));
d62a17ae 12561
12562 uptime = bgp_clock();
12563 uptime -= p->last_write;
a2700b50
MS
12564 gmtime_r(&uptime, &tm);
12565
d62a17ae 12566 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12567 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12568 + (tm.tm_hour * 3600000));
d62a17ae 12569
12570 uptime = bgp_clock();
12571 uptime -= p->update_time;
a2700b50
MS
12572 gmtime_r(&uptime, &tm);
12573
d62a17ae 12574 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12575 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12576 + (tm.tm_hour * 3600000));
d62a17ae 12577
12578 /* Configured timer values. */
12579 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12580 p->v_holdtime * 1000);
12581 json_object_int_add(json_neigh,
12582 "bgpTimerKeepAliveIntervalMsecs",
12583 p->v_keepalive * 1000);
d43114f3
DS
12584 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12585 json_object_int_add(json_neigh,
12586 "bgpTimerDelayOpenTimeMsecs",
12587 p->v_delayopen * 1000);
12588 }
12589
4ab46701
AR
12590 /* Configured and Synced tcp-mss value for peer */
12591 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12592 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12593 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
12594 p->tcp_mss);
12595 json_object_int_add(json_neigh, "bgpTcpMssSynced",
12596 sync_tcp_mss);
12597 }
12598
b90a8e13 12599 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12600 json_object_int_add(json_neigh,
12601 "bgpTimerConfiguredHoldTimeMsecs",
12602 p->holdtime * 1000);
12603 json_object_int_add(
12604 json_neigh,
12605 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12606 p->keepalive * 1000);
5d5393b9
DL
12607 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12608 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12609 json_object_int_add(json_neigh,
12610 "bgpTimerConfiguredHoldTimeMsecs",
12611 bgp->default_holdtime);
12612 json_object_int_add(
12613 json_neigh,
12614 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12615 bgp->default_keepalive);
d62a17ae 12616 }
d08c0c80
DA
12617
12618 /* Extended Optional Parameters Length for BGP OPEN Message */
12619 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12620 json_object_boolean_true_add(
12621 json_neigh, "extendedOptionalParametersLength");
12622 else
12623 json_object_boolean_false_add(
12624 json_neigh, "extendedOptionalParametersLength");
6e37924b
DA
12625
12626 /* Conditional advertisements */
12627 json_object_int_add(
12628 json_neigh,
12629 "bgpTimerConfiguredConditionalAdvertisementsSec",
12630 bgp->condition_check_period);
12631 if (thread_is_scheduled(bgp->t_condition_check))
12632 json_object_int_add(
12633 json_neigh,
12634 "bgpTimerUntilConditionalAdvertisementsSec",
12635 thread_timer_remain_second(
12636 bgp->t_condition_check));
d62a17ae 12637 } else {
12638 /* Administrative shutdown. */
cb9196e7
DS
12639 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12640 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12641 vty_out(vty, " Administratively shut down\n");
12642
12643 /* BGP Version. */
12644 vty_out(vty, " BGP version 4");
0e38aeb4 12645 vty_out(vty, ", remote router ID %s",
d62a17ae 12646 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
12647 vty_out(vty, ", local router ID %s\n",
12648 inet_ntop(AF_INET, &bgp->router_id, buf1,
12649 sizeof(buf1)));
d62a17ae 12650
12651 /* Confederation */
12652 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12653 && bgp_confederation_peers_check(bgp, p->as))
12654 vty_out(vty,
12655 " Neighbor under common administration\n");
12656
12657 /* Status. */
12658 vty_out(vty, " BGP state = %s",
12659 lookup_msg(bgp_status_msg, p->status, NULL));
12660
feb17238 12661 if (peer_established(p))
d62a17ae 12662 vty_out(vty, ", up for %8s",
12663 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12664 0, NULL));
12665
12666 else if (p->status == Active) {
12667 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12668 vty_out(vty, " (passive)");
12669 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12670 vty_out(vty, " (NSF passive)");
12671 }
12672 vty_out(vty, "\n");
12673
12674 /* read timer */
12675 vty_out(vty, " Last read %s",
12676 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12677 NULL));
12678 vty_out(vty, ", Last write %s\n",
12679 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12680 NULL));
12681
12682 /* Configured timer values. */
12683 vty_out(vty,
12684 " Hold time is %d, keepalive interval is %d seconds\n",
12685 p->v_holdtime, p->v_keepalive);
b90a8e13 12686 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 12687 vty_out(vty, " Configured hold time is %d",
12688 p->holdtime);
12689 vty_out(vty, ", keepalive interval is %d seconds\n",
12690 p->keepalive);
5d5393b9
DL
12691 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12692 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
12693 vty_out(vty, " Configured hold time is %d",
12694 bgp->default_holdtime);
12695 vty_out(vty, ", keepalive interval is %d seconds\n",
12696 bgp->default_keepalive);
d62a17ae 12697 }
d43114f3
DS
12698 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12699 vty_out(vty,
12700 " Configured DelayOpenTime is %d seconds\n",
12701 p->delayopen);
4ab46701
AR
12702
12703 /* Configured and synced tcp-mss value for peer */
12704 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
12705 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
12706 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
12707 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
12708 }
d08c0c80
DA
12709
12710 /* Extended Optional Parameters Length for BGP OPEN Message */
12711 if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p))
12712 vty_out(vty,
12713 " Extended Optional Parameters Length is enabled\n");
6e37924b
DA
12714
12715 /* Conditional advertisements */
12716 vty_out(vty,
12717 " Configured conditional advertisements interval is %d seconds\n",
12718 bgp->condition_check_period);
12719 if (thread_is_scheduled(bgp->t_condition_check))
12720 vty_out(vty,
12721 " Time until conditional advertisements begin is %lu seconds\n",
12722 thread_timer_remain_second(
12723 bgp->t_condition_check));
d62a17ae 12724 }
12725 /* Capability. */
10711563
DA
12726 if (peer_established(p) &&
12727 (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) {
12728 if (use_json) {
12729 json_object *json_cap = NULL;
d62a17ae 12730
10711563 12731 json_cap = json_object_new_object();
d62a17ae 12732
10711563
DA
12733 /* AS4 */
12734 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
12735 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12736 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV) &&
12737 CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
ef56aee4 12738 json_object_string_add(
10711563 12739 json_cap, "4byteAs",
ef56aee4 12740 "advertisedAndReceived");
10711563
DA
12741 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
12742 json_object_string_add(json_cap,
12743 "4byteAs",
12744 "advertised");
12745 else if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
12746 json_object_string_add(json_cap,
12747 "4byteAs",
12748 "received");
12749 }
ef56aee4 12750
10711563
DA
12751 /* Extended Message Support */
12752 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV) &&
12753 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
12754 json_object_string_add(json_cap,
12755 "extendedMessage",
12756 "advertisedAndReceived");
12757 else if (CHECK_FLAG(p->cap,
12758 PEER_CAP_EXTENDED_MESSAGE_ADV))
12759 json_object_string_add(json_cap,
12760 "extendedMessage",
12761 "advertised");
12762 else if (CHECK_FLAG(p->cap,
12763 PEER_CAP_EXTENDED_MESSAGE_RCV))
12764 json_object_string_add(json_cap,
12765 "extendedMessage",
12766 "received");
ef56aee4 12767
10711563
DA
12768 /* AddPath */
12769 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
12770 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
12771 json_object *json_add = NULL;
12772 const char *print_store;
d62a17ae 12773
10711563 12774 json_add = json_object_new_object();
d62a17ae 12775
10711563
DA
12776 FOREACH_AFI_SAFI (afi, safi) {
12777 json_object *json_sub = NULL;
12778 json_sub = json_object_new_object();
12779 print_store = get_afi_safi_str(
12780 afi, safi, true);
d62a17ae 12781
10711563
DA
12782 if (CHECK_FLAG(
12783 p->af_cap[afi][safi],
12784 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12785 CHECK_FLAG(
12786 p->af_cap[afi][safi],
12787 PEER_CAP_ADDPATH_AF_TX_RCV)) {
05c7a1cc
QY
12788 if (CHECK_FLAG(
12789 p->af_cap[afi]
12790 [safi],
10711563
DA
12791 PEER_CAP_ADDPATH_AF_TX_ADV) &&
12792 CHECK_FLAG(
05c7a1cc
QY
12793 p->af_cap[afi]
12794 [safi],
10711563
DA
12795 PEER_CAP_ADDPATH_AF_TX_RCV))
12796 json_object_boolean_true_add(
12797 json_sub,
12798 "txAdvertisedAndReceived");
12799 else if (
12800 CHECK_FLAG(
12801 p->af_cap[afi]
12802 [safi],
12803 PEER_CAP_ADDPATH_AF_TX_ADV))
12804 json_object_boolean_true_add(
12805 json_sub,
12806 "txAdvertised");
12807 else if (
12808 CHECK_FLAG(
12809 p->af_cap[afi]
12810 [safi],
12811 PEER_CAP_ADDPATH_AF_TX_RCV))
12812 json_object_boolean_true_add(
12813 json_sub,
12814 "txReceived");
12815 }
d62a17ae 12816
10711563
DA
12817 if (CHECK_FLAG(
12818 p->af_cap[afi][safi],
12819 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12820 CHECK_FLAG(
12821 p->af_cap[afi][safi],
12822 PEER_CAP_ADDPATH_AF_RX_RCV)) {
05c7a1cc
QY
12823 if (CHECK_FLAG(
12824 p->af_cap[afi]
12825 [safi],
10711563
DA
12826 PEER_CAP_ADDPATH_AF_RX_ADV) &&
12827 CHECK_FLAG(
12828 p->af_cap[afi]
12829 [safi],
12830 PEER_CAP_ADDPATH_AF_RX_RCV))
12831 json_object_boolean_true_add(
12832 json_sub,
12833 "rxAdvertisedAndReceived");
12834 else if (
12835 CHECK_FLAG(
12836 p->af_cap[afi]
12837 [safi],
12838 PEER_CAP_ADDPATH_AF_RX_ADV))
12839 json_object_boolean_true_add(
12840 json_sub,
12841 "rxAdvertised");
12842 else if (
12843 CHECK_FLAG(
12844 p->af_cap[afi]
12845 [safi],
12846 PEER_CAP_ADDPATH_AF_RX_RCV))
12847 json_object_boolean_true_add(
12848 json_sub,
12849 "rxReceived");
05c7a1cc
QY
12850 }
12851
10711563
DA
12852 if (CHECK_FLAG(
12853 p->af_cap[afi][safi],
12854 PEER_CAP_ADDPATH_AF_TX_ADV) ||
12855 CHECK_FLAG(
12856 p->af_cap[afi][safi],
12857 PEER_CAP_ADDPATH_AF_TX_RCV) ||
12858 CHECK_FLAG(
12859 p->af_cap[afi][safi],
12860 PEER_CAP_ADDPATH_AF_RX_ADV) ||
12861 CHECK_FLAG(
12862 p->af_cap[afi][safi],
12863 PEER_CAP_ADDPATH_AF_RX_RCV))
12864 json_object_object_add(
12865 json_add, print_store,
12866 json_sub);
12867 else
12868 json_object_free(json_sub);
d62a17ae 12869 }
12870
10711563
DA
12871 json_object_object_add(json_cap, "addPath",
12872 json_add);
12873 }
d62a17ae 12874
10711563
DA
12875 /* Dynamic */
12876 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
12877 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
12878 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV) &&
12879 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
12880 json_object_string_add(
12881 json_cap, "dynamic",
12882 "advertisedAndReceived");
12883 else if (CHECK_FLAG(p->cap,
12884 PEER_CAP_DYNAMIC_ADV))
12885 json_object_string_add(json_cap,
12886 "dynamic",
12887 "advertised");
12888 else if (CHECK_FLAG(p->cap,
12889 PEER_CAP_DYNAMIC_RCV))
12890 json_object_string_add(json_cap,
12891 "dynamic",
12892 "received");
12893 }
d62a17ae 12894
10711563
DA
12895 /* Extended nexthop */
12896 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
12897 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12898 json_object *json_nxt = NULL;
12899 const char *print_store;
d62a17ae 12900
d62a17ae 12901
10711563
DA
12902 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV) &&
12903 CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12904 json_object_string_add(
12905 json_cap, "extendedNexthop",
12906 "advertisedAndReceived");
12907 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
12908 json_object_string_add(
12909 json_cap, "extendedNexthop",
12910 "advertised");
12911 else if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
12912 json_object_string_add(
12913 json_cap, "extendedNexthop",
12914 "received");
d62a17ae 12915
10711563
DA
12916 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
12917 json_nxt = json_object_new_object();
d62a17ae 12918
10711563
DA
12919 for (safi = SAFI_UNICAST;
12920 safi < SAFI_MAX; safi++) {
12921 if (CHECK_FLAG(
12922 p->af_cap[AFI_IP]
12923 [safi],
12924 PEER_CAP_ENHE_AF_RCV)) {
12925 print_store =
12926 get_afi_safi_str(
d62a17ae 12927 AFI_IP,
10711563
DA
12928 safi,
12929 true);
12930 json_object_string_add(
12931 json_nxt,
12932 print_store,
12933 "recieved"); /* misspelled for compatibility */
d62a17ae 12934 }
d62a17ae 12935 }
10711563
DA
12936 json_object_object_add(
12937 json_cap,
12938 "extendedNexthopFamililesByPeer",
12939 json_nxt);
d62a17ae 12940 }
10711563 12941 }
d62a17ae 12942
10711563
DA
12943 /* Long-lived Graceful Restart */
12944 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
12945 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
12946 json_object *json_llgr = NULL;
12947 const char *afi_safi_str;
8606be87 12948
10711563
DA
12949 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV) &&
12950 CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12951 json_object_string_add(
12952 json_cap,
12953 "longLivedGracefulRestart",
12954 "advertisedAndReceived");
12955 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
12956 json_object_string_add(
12957 json_cap,
12958 "longLivedGracefulRestart",
12959 "advertised");
12960 else if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
12961 json_object_string_add(
12962 json_cap,
12963 "longLivedGracefulRestart",
12964 "received");
8606be87 12965
10711563
DA
12966 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
12967 json_llgr = json_object_new_object();
8606be87 12968
10711563
DA
12969 FOREACH_AFI_SAFI (afi, safi) {
12970 if (CHECK_FLAG(
12971 p->af_cap[afi]
12972 [safi],
12973 PEER_CAP_ENHE_AF_RCV)) {
12974 afi_safi_str =
12975 get_afi_safi_str(
8606be87
DA
12976 afi,
12977 safi,
12978 true);
10711563
DA
12979 json_object_string_add(
12980 json_llgr,
12981 afi_safi_str,
12982 "received");
8606be87 12983 }
8606be87 12984 }
10711563
DA
12985 json_object_object_add(
12986 json_cap,
12987 "longLivedGracefulRestartByPeer",
12988 json_llgr);
8606be87 12989 }
10711563 12990 }
8606be87 12991
10711563
DA
12992 /* Route Refresh */
12993 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
12994 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
12995 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
12996 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) &&
12997 (CHECK_FLAG(p->cap,
12998 PEER_CAP_REFRESH_NEW_RCV) ||
12999 CHECK_FLAG(p->cap,
13000 PEER_CAP_REFRESH_OLD_RCV))) {
13001 if (CHECK_FLAG(
13002 p->cap,
13003 PEER_CAP_REFRESH_OLD_RCV) &&
13004 CHECK_FLAG(
13005 p->cap,
13006 PEER_CAP_REFRESH_NEW_RCV))
13007 json_object_string_add(
13008 json_cap,
13009 "routeRefresh",
13010 "advertisedAndReceivedOldNew");
13011 else {
d62a17ae 13012 if (CHECK_FLAG(
13013 p->cap,
10711563 13014 PEER_CAP_REFRESH_OLD_RCV))
d62a17ae 13015 json_object_string_add(
13016 json_cap,
13017 "routeRefresh",
10711563
DA
13018 "advertisedAndReceivedOld");
13019 else
13020 json_object_string_add(
13021 json_cap,
13022 "routeRefresh",
13023 "advertisedAndReceivedNew");
d62a17ae 13024 }
10711563
DA
13025 } else if (CHECK_FLAG(p->cap,
13026 PEER_CAP_REFRESH_ADV))
13027 json_object_string_add(json_cap,
13028 "routeRefresh",
13029 "advertised");
13030 else if (CHECK_FLAG(p->cap,
13031 PEER_CAP_REFRESH_NEW_RCV) ||
13032 CHECK_FLAG(p->cap,
13033 PEER_CAP_REFRESH_OLD_RCV))
13034 json_object_string_add(json_cap,
13035 "routeRefresh",
13036 "received");
13037 }
d62a17ae 13038
10711563
DA
13039 /* Enhanced Route Refresh */
13040 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13041 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13042 if (CHECK_FLAG(p->cap,
13043 PEER_CAP_ENHANCED_RR_ADV) &&
13044 CHECK_FLAG(p->cap,
13045 PEER_CAP_ENHANCED_RR_RCV))
d77114b7 13046 json_object_string_add(
10711563
DA
13047 json_cap,
13048 "enhancedRouteRefresh",
13049 "advertisedAndReceived");
13050 else if (CHECK_FLAG(p->cap,
13051 PEER_CAP_ENHANCED_RR_ADV))
d77114b7 13052 json_object_string_add(
10711563
DA
13053 json_cap,
13054 "enhancedRouteRefresh",
13055 "advertised");
13056 else if (CHECK_FLAG(p->cap,
9af52ccf 13057 PEER_CAP_ENHANCED_RR_RCV))
10711563
DA
13058 json_object_string_add(
13059 json_cap,
13060 "enhancedRouteRefresh",
13061 "received");
13062 }
d77114b7 13063
10711563
DA
13064 /* Multiprotocol Extensions */
13065 json_object *json_multi = NULL;
d77114b7 13066
10711563 13067 json_multi = json_object_new_object();
d77114b7 13068
10711563
DA
13069 FOREACH_AFI_SAFI (afi, safi) {
13070 if (p->afc_adv[afi][safi] ||
13071 p->afc_recv[afi][safi]) {
13072 json_object *json_exten = NULL;
13073 json_exten = json_object_new_object();
13074
13075 if (p->afc_adv[afi][safi] &&
13076 p->afc_recv[afi][safi])
13077 json_object_boolean_true_add(
13078 json_exten,
9af52ccf 13079 "advertisedAndReceived");
10711563
DA
13080 else if (p->afc_adv[afi][safi])
13081 json_object_boolean_true_add(
13082 json_exten,
9af52ccf 13083 "advertised");
10711563
DA
13084 else if (p->afc_recv[afi][safi])
13085 json_object_boolean_true_add(
13086 json_exten, "received");
9af52ccf 13087
10711563
DA
13088 json_object_object_add(
13089 json_multi,
13090 get_afi_safi_str(afi, safi,
13091 true),
13092 json_exten);
13093 }
13094 }
13095 json_object_object_add(json_cap,
13096 "multiprotocolExtensions",
13097 json_multi);
d62a17ae 13098
10711563
DA
13099 /* Hostname capabilities */
13100 json_object *json_hname = NULL;
d62a17ae 13101
10711563 13102 json_hname = json_object_new_object();
d62a17ae 13103
10711563
DA
13104 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13105 json_object_string_add(
13106 json_hname, "advHostName",
13107 bgp->peer_self->hostname
13108 ? bgp->peer_self->hostname
13109 : "n/a");
13110 json_object_string_add(
13111 json_hname, "advDomainName",
13112 bgp->peer_self->domainname
13113 ? bgp->peer_self->domainname
13114 : "n/a");
13115 }
d77114b7 13116
d77114b7 13117
10711563
DA
13118 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13119 json_object_string_add(
13120 json_hname, "rcvHostName",
13121 p->hostname ? p->hostname : "n/a");
13122 json_object_string_add(
13123 json_hname, "rcvDomainName",
13124 p->domainname ? p->domainname : "n/a");
13125 }
d77114b7 13126
10711563
DA
13127 json_object_object_add(json_cap, "hostName",
13128 json_hname);
d77114b7 13129
17be83bf 13130 /* Graceful Restart */
10711563
DA
13131 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13132 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13133 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) &&
13134 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
d77114b7 13135 json_object_string_add(
10711563
DA
13136 json_cap, "gracefulRestart",
13137 "advertisedAndReceived");
13138 else if (CHECK_FLAG(p->cap,
13139 PEER_CAP_RESTART_ADV))
d77114b7 13140 json_object_string_add(
10711563
DA
13141 json_cap,
13142 "gracefulRestartCapability",
13143 "advertised");
13144 else if (CHECK_FLAG(p->cap,
13145 PEER_CAP_RESTART_RCV))
13146 json_object_string_add(
13147 json_cap,
13148 "gracefulRestartCapability",
13149 "received");
d77114b7 13150
10711563
DA
13151 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13152 int restart_af_count = 0;
13153 json_object *json_restart = NULL;
13154 json_restart = json_object_new_object();
d62a17ae 13155
10711563
DA
13156 json_object_int_add(
13157 json_cap,
13158 "gracefulRestartRemoteTimerMsecs",
13159 p->v_gr_restart * 1000);
d62a17ae 13160
10711563 13161 FOREACH_AFI_SAFI (afi, safi) {
05c7a1cc
QY
13162 if (CHECK_FLAG(
13163 p->af_cap[afi]
13164 [safi],
10711563
DA
13165 PEER_CAP_RESTART_AF_RCV)) {
13166 json_object *json_sub =
13167 NULL;
13168 json_sub =
13169 json_object_new_object();
d62a17ae 13170
05c7a1cc
QY
13171 if (CHECK_FLAG(
13172 p->af_cap
13173 [afi]
13174 [safi],
10711563
DA
13175 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13176 json_object_boolean_true_add(
13177 json_sub,
13178 "preserved");
13179 restart_af_count++;
d62a17ae 13180 json_object_object_add(
10711563
DA
13181 json_restart,
13182 get_afi_safi_str(
13183 afi,
13184 safi,
13185 true),
13186 json_sub);
d62a17ae 13187 }
d62a17ae 13188 }
10711563
DA
13189 if (!restart_af_count) {
13190 json_object_string_add(
13191 json_cap,
13192 "addressFamiliesByPeer",
13193 "none");
13194 json_object_free(json_restart);
13195 } else
13196 json_object_object_add(
13197 json_cap,
13198 "addressFamiliesByPeer",
13199 json_restart);
d62a17ae 13200 }
10711563
DA
13201 }
13202 json_object_object_add(
13203 json_neigh, "neighborCapabilities", json_cap);
13204 } else {
13205 vty_out(vty, " Neighbor capabilities:\n");
13206
13207 /* AS4 */
13208 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV) ||
13209 CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13210 vty_out(vty, " 4 Byte AS:");
13211 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV))
13212 vty_out(vty, " advertised");
13213 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV))
13214 vty_out(vty, " %sreceived",
13215 CHECK_FLAG(p->cap,
13216 PEER_CAP_AS4_ADV)
13217 ? "and "
13218 : "");
13219 vty_out(vty, "\n");
13220 }
d62a17ae 13221
10711563
DA
13222 /* Extended Message Support */
13223 if (CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_RCV) ||
13224 CHECK_FLAG(p->cap, PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13225 vty_out(vty, " Extended Message:");
ef56aee4 13226 if (CHECK_FLAG(p->cap,
10711563
DA
13227 PEER_CAP_EXTENDED_MESSAGE_ADV))
13228 vty_out(vty, " advertised");
13229 if (CHECK_FLAG(p->cap,
13230 PEER_CAP_EXTENDED_MESSAGE_RCV))
13231 vty_out(vty, " %sreceived",
13232 CHECK_FLAG(
13233 p->cap,
13234 PEER_CAP_EXTENDED_MESSAGE_ADV)
13235 ? "and "
13236 : "");
13237 vty_out(vty, "\n");
13238 }
d62a17ae 13239
10711563
DA
13240 /* AddPath */
13241 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV) ||
13242 CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_ADV)) {
13243 vty_out(vty, " AddPath:\n");
d62a17ae 13244
10711563 13245 FOREACH_AFI_SAFI (afi, safi) {
ef56aee4 13246 if (CHECK_FLAG(
10711563
DA
13247 p->af_cap[afi][safi],
13248 PEER_CAP_ADDPATH_AF_TX_ADV) ||
13249 CHECK_FLAG(
13250 p->af_cap[afi][safi],
13251 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13252 vty_out(vty, " %s: TX ",
13253 get_afi_safi_str(
13254 afi, safi,
13255 false));
ef56aee4 13256
10711563
DA
13257 if (CHECK_FLAG(
13258 p->af_cap[afi]
13259 [safi],
13260 PEER_CAP_ADDPATH_AF_TX_ADV))
13261 vty_out(vty,
13262 "advertised");
d62a17ae 13263
05c7a1cc
QY
13264 if (CHECK_FLAG(
13265 p->af_cap[afi]
13266 [safi],
10711563 13267 PEER_CAP_ADDPATH_AF_TX_RCV))
05c7a1cc 13268 vty_out(vty,
10711563
DA
13269 "%sreceived",
13270 CHECK_FLAG(
13271 p->af_cap
13272 [afi]
13273 [safi],
13274 PEER_CAP_ADDPATH_AF_TX_ADV)
13275 ? " and "
13276 : "");
05c7a1cc 13277
10711563
DA
13278 vty_out(vty, "\n");
13279 }
d62a17ae 13280
9af52ccf 13281 if (CHECK_FLAG(
10711563
DA
13282 p->af_cap[afi][safi],
13283 PEER_CAP_ADDPATH_AF_RX_ADV) ||
13284 CHECK_FLAG(
13285 p->af_cap[afi][safi],
13286 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13287 vty_out(vty, " %s: RX ",
5cb5f4d0 13288 get_afi_safi_str(
10711563
DA
13289 afi, safi,
13290 false));
d62a17ae 13291
05c7a1cc
QY
13292 if (CHECK_FLAG(
13293 p->af_cap[afi]
13294 [safi],
10711563 13295 PEER_CAP_ADDPATH_AF_RX_ADV))
05c7a1cc 13296 vty_out(vty,
10711563 13297 "advertised");
d62a17ae 13298
10711563
DA
13299 if (CHECK_FLAG(
13300 p->af_cap[afi]
13301 [safi],
13302 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc 13303 vty_out(vty,
10711563
DA
13304 "%sreceived",
13305 CHECK_FLAG(
13306 p->af_cap
13307 [afi]
13308 [safi],
13309 PEER_CAP_ADDPATH_AF_RX_ADV)
13310 ? " and "
05c7a1cc 13311 : "");
d62a17ae 13312
05c7a1cc 13313 vty_out(vty, "\n");
05c7a1cc 13314 }
d62a17ae 13315 }
10711563 13316 }
d62a17ae 13317
10711563
DA
13318 /* Dynamic */
13319 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV) ||
13320 CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV)) {
13321 vty_out(vty, " Dynamic:");
13322 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_ADV))
13323 vty_out(vty, " advertised");
13324 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV))
13325 vty_out(vty, " %sreceived",
13326 CHECK_FLAG(p->cap,
13327 PEER_CAP_DYNAMIC_ADV)
13328 ? "and "
13329 : "");
13330 vty_out(vty, "\n");
13331 }
d62a17ae 13332
10711563
DA
13333 /* Extended nexthop */
13334 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV) ||
13335 CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13336 vty_out(vty, " Extended nexthop:");
13337 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV))
13338 vty_out(vty, " advertised");
13339 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV))
13340 vty_out(vty, " %sreceived",
13341 CHECK_FLAG(p->cap,
13342 PEER_CAP_ENHE_ADV)
13343 ? "and "
13344 : "");
13345 vty_out(vty, "\n");
d62a17ae 13346
10711563 13347 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)) {
57f7feb6 13348 vty_out(vty,
10711563
DA
13349 " Address families by peer:\n ");
13350 for (safi = SAFI_UNICAST;
13351 safi < SAFI_MAX; safi++)
13352 if (CHECK_FLAG(
13353 p->af_cap[AFI_IP]
13354 [safi],
13355 PEER_CAP_ENHE_AF_RCV))
13356 vty_out(vty,
13357 " %s\n",
13358 get_afi_safi_str(
13359 AFI_IP,
13360 safi,
13361 false));
d62a17ae 13362 }
10711563 13363 }
d62a17ae 13364
10711563
DA
13365 /* Long-lived Graceful Restart */
13366 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV) ||
13367 CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV)) {
13368 vty_out(vty,
13369 " Long-lived Graceful Restart:");
13370 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_ADV))
13371 vty_out(vty, " advertised");
13372 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV))
13373 vty_out(vty, " %sreceived",
13374 CHECK_FLAG(p->cap,
13375 PEER_CAP_LLGR_ADV)
13376 ? "and "
13377 : "");
13378 vty_out(vty, "\n");
8606be87 13379
10711563 13380 if (CHECK_FLAG(p->cap, PEER_CAP_LLGR_RCV)) {
57f7feb6 13381 vty_out(vty,
10711563
DA
13382 " Address families by peer:\n");
13383 FOREACH_AFI_SAFI (afi, safi)
13384 if (CHECK_FLAG(
13385 p->af_cap[afi]
13386 [safi],
13387 PEER_CAP_LLGR_AF_RCV))
13388 vty_out(vty,
13389 " %s\n",
13390 get_afi_safi_str(
13391 afi,
13392 safi,
13393 false));
8606be87 13394 }
10711563 13395 }
8606be87 13396
10711563
DA
13397 /* Route Refresh */
13398 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ||
13399 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) ||
13400 CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) {
13401 vty_out(vty, " Route refresh:");
13402 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV))
13403 vty_out(vty, " advertised");
13404 if (CHECK_FLAG(p->cap,
13405 PEER_CAP_REFRESH_NEW_RCV) ||
13406 CHECK_FLAG(p->cap,
13407 PEER_CAP_REFRESH_OLD_RCV))
13408 vty_out(vty, " %sreceived(%s)",
13409 CHECK_FLAG(p->cap,
13410 PEER_CAP_REFRESH_ADV)
13411 ? "and "
13412 : "",
13413 (CHECK_FLAG(
13414 p->cap,
13415 PEER_CAP_REFRESH_OLD_RCV) &&
13416 CHECK_FLAG(
13417 p->cap,
13418 PEER_CAP_REFRESH_NEW_RCV))
13419 ? "old & new"
13420 : CHECK_FLAG(
13421 p->cap,
13422 PEER_CAP_REFRESH_OLD_RCV)
13423 ? "old"
13424 : "new");
d62a17ae 13425
d77114b7 13426 vty_out(vty, "\n");
10711563 13427 }
d62a17ae 13428
10711563
DA
13429 /* Enhanced Route Refresh */
13430 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV) ||
13431 CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_RCV)) {
13432 vty_out(vty, " Enhanced Route Refresh:");
13433 if (CHECK_FLAG(p->cap,
13434 PEER_CAP_ENHANCED_RR_ADV))
13435 vty_out(vty, " advertised");
13436 if (CHECK_FLAG(p->cap,
13437 PEER_CAP_ENHANCED_RR_RCV))
13438 vty_out(vty, " %sreceived",
13439 CHECK_FLAG(p->cap,
13440 PEER_CAP_REFRESH_ADV)
13441 ? "and "
13442 : "");
13443 vty_out(vty, "\n");
13444 }
13445
13446 /* Multiprotocol Extensions */
13447 FOREACH_AFI_SAFI (afi, safi)
13448 if (p->afc_adv[afi][safi] ||
13449 p->afc_recv[afi][safi]) {
13450 vty_out(vty, " Address Family %s:",
13451 get_afi_safi_str(afi, safi,
13452 false));
13453 if (p->afc_adv[afi][safi])
9af52ccf 13454 vty_out(vty, " advertised");
10711563 13455 if (p->afc_recv[afi][safi])
9af52ccf 13456 vty_out(vty, " %sreceived",
10711563 13457 p->afc_adv[afi][safi]
9af52ccf
DA
13458 ? "and "
13459 : "");
13460 vty_out(vty, "\n");
13461 }
13462
10711563
DA
13463 /* Hostname capability */
13464 vty_out(vty, " Hostname Capability:");
d62a17ae 13465
10711563
DA
13466 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13467 vty_out(vty,
13468 " advertised (name: %s,domain name: %s)",
13469 bgp->peer_self->hostname
13470 ? bgp->peer_self->hostname
13471 : "n/a",
13472 bgp->peer_self->domainname
13473 ? bgp->peer_self->domainname
13474 : "n/a");
13475 } else {
13476 vty_out(vty, " not advertised");
13477 }
d77114b7 13478
10711563
DA
13479 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13480 vty_out(vty,
13481 " received (name: %s,domain name: %s)",
13482 p->hostname ? p->hostname : "n/a",
13483 p->domainname ? p->domainname : "n/a");
13484 } else {
13485 vty_out(vty, " not received");
d62a17ae 13486 }
d62a17ae 13487
10711563 13488 vty_out(vty, "\n");
d77114b7 13489
10711563
DA
13490 /* Graceful Restart */
13491 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) ||
13492 CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) {
13493 vty_out(vty,
13494 " Graceful Restart Capability:");
13495 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV))
13496 vty_out(vty, " advertised");
13497 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
13498 vty_out(vty, " %sreceived",
13499 CHECK_FLAG(p->cap,
13500 PEER_CAP_RESTART_ADV)
13501 ? "and "
13502 : "");
d77114b7
MK
13503 vty_out(vty, "\n");
13504
10711563
DA
13505 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13506 int restart_af_count = 0;
d62a17ae 13507
10711563
DA
13508 vty_out(vty,
13509 " Remote Restart timer is %d seconds\n",
13510 p->v_gr_restart);
13511 vty_out(vty,
13512 " Address families by peer:\n ");
d62a17ae 13513
10711563
DA
13514 FOREACH_AFI_SAFI (afi, safi)
13515 if (CHECK_FLAG(
13516 p->af_cap[afi]
13517 [safi],
13518 PEER_CAP_RESTART_AF_RCV)) {
13519 vty_out(vty, "%s%s(%s)",
13520 restart_af_count
13521 ? ", "
13522 : "",
13523 get_afi_safi_str(
13524 afi,
13525 safi,
13526 false),
13527 CHECK_FLAG(
13528 p->af_cap
13529 [afi]
13530 [safi],
13531 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13532 ? "preserved"
13533 : "not preserved");
13534 restart_af_count++;
13535 }
13536 if (!restart_af_count)
13537 vty_out(vty, "none");
13538 vty_out(vty, "\n");
13539 }
17be83bf 13540 } /* Graceful Restart */
d62a17ae 13541 }
13542 }
13543
13544 /* graceful restart information */
10711563
DA
13545 json_object *json_grace = NULL;
13546 json_object *json_grace_send = NULL;
13547 json_object *json_grace_recv = NULL;
13548 int eor_send_af_count = 0;
13549 int eor_receive_af_count = 0;
d62a17ae 13550
10711563
DA
13551 if (use_json) {
13552 json_grace = json_object_new_object();
13553 json_grace_send = json_object_new_object();
13554 json_grace_recv = json_object_new_object();
13555
13556 if ((peer_established(p)) &&
13557 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13558 FOREACH_AFI_SAFI (afi, safi) {
13559 if (CHECK_FLAG(p->af_sflags[afi][safi],
13560 PEER_STATUS_EOR_SEND)) {
13561 json_object_boolean_true_add(
13562 json_grace_send,
13563 get_afi_safi_str(afi, safi,
13564 true));
13565 eor_send_af_count++;
d62a17ae 13566 }
10711563
DA
13567 }
13568 FOREACH_AFI_SAFI (afi, safi) {
13569 if (CHECK_FLAG(p->af_sflags[afi][safi],
13570 PEER_STATUS_EOR_RECEIVED)) {
13571 json_object_boolean_true_add(
13572 json_grace_recv,
13573 get_afi_safi_str(afi, safi,
13574 true));
13575 eor_receive_af_count++;
d62a17ae 13576 }
13577 }
10711563
DA
13578 }
13579 json_object_object_add(json_grace, "endOfRibSend",
13580 json_grace_send);
13581 json_object_object_add(json_grace, "endOfRibRecv",
13582 json_grace_recv);
d62a17ae 13583
d62a17ae 13584
10711563
DA
13585 if (p->t_gr_restart)
13586 json_object_int_add(
13587 json_grace, "gracefulRestartTimerMsecs",
13588 thread_timer_remain_second(p->t_gr_restart) *
13589 1000);
2986cac2 13590
10711563
DA
13591 if (p->t_gr_stale)
13592 json_object_int_add(
13593 json_grace, "gracefulStalepathTimerMsecs",
13594 thread_timer_remain_second(p->t_gr_stale) *
13595 1000);
13596 /* more gr info in new format */
13597 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json_grace);
13598 json_object_object_add(json_neigh, "gracefulRestartInfo",
13599 json_grace);
13600 } else {
13601 vty_out(vty, " Graceful restart information:\n");
13602 if ((peer_established(p)) &&
13603 CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13604
13605 vty_out(vty, " End-of-RIB send: ");
13606 FOREACH_AFI_SAFI (afi, safi) {
13607 if (CHECK_FLAG(p->af_sflags[afi][safi],
13608 PEER_STATUS_EOR_SEND)) {
13609 vty_out(vty, "%s%s",
13610 eor_send_af_count ? ", " : "",
13611 get_afi_safi_str(afi, safi,
13612 false));
13613 eor_send_af_count++;
d62a17ae 13614 }
10711563
DA
13615 }
13616 vty_out(vty, "\n");
13617 vty_out(vty, " End-of-RIB received: ");
13618 FOREACH_AFI_SAFI (afi, safi) {
13619 if (CHECK_FLAG(p->af_sflags[afi][safi],
13620 PEER_STATUS_EOR_RECEIVED)) {
13621 vty_out(vty, "%s%s",
13622 eor_receive_af_count ? ", "
13623 : "",
13624 get_afi_safi_str(afi, safi,
13625 false));
13626 eor_receive_af_count++;
d62a17ae 13627 }
d62a17ae 13628 }
10711563
DA
13629 vty_out(vty, "\n");
13630 }
d62a17ae 13631
10711563
DA
13632 if (p->t_gr_restart)
13633 vty_out(vty,
13634 " The remaining time of restart timer is %ld\n",
13635 thread_timer_remain_second(p->t_gr_restart));
d62a17ae 13636
10711563
DA
13637 if (p->t_gr_stale)
13638 vty_out(vty,
13639 " The remaining time of stalepath timer is %ld\n",
13640 thread_timer_remain_second(p->t_gr_stale));
2986cac2 13641
10711563
DA
13642 /* more gr info in new format */
13643 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13644 }
2986cac2 13645
d62a17ae 13646 if (use_json) {
13647 json_object *json_stat = NULL;
13648 json_stat = json_object_new_object();
13649 /* Packet counts. */
43aa5965
QY
13650
13651 atomic_size_t outq_count, inq_count;
13652 outq_count = atomic_load_explicit(&p->obuf->count,
13653 memory_order_relaxed);
13654 inq_count = atomic_load_explicit(&p->ibuf->count,
13655 memory_order_relaxed);
13656
13657 json_object_int_add(json_stat, "depthInq",
13658 (unsigned long)inq_count);
d62a17ae 13659 json_object_int_add(json_stat, "depthOutq",
43aa5965 13660 (unsigned long)outq_count);
0112e9e0
QY
13661 json_object_int_add(json_stat, "opensSent",
13662 atomic_load_explicit(&p->open_out,
13663 memory_order_relaxed));
13664 json_object_int_add(json_stat, "opensRecv",
13665 atomic_load_explicit(&p->open_in,
13666 memory_order_relaxed));
d62a17ae 13667 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
13668 atomic_load_explicit(&p->notify_out,
13669 memory_order_relaxed));
d62a17ae 13670 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
13671 atomic_load_explicit(&p->notify_in,
13672 memory_order_relaxed));
13673 json_object_int_add(json_stat, "updatesSent",
13674 atomic_load_explicit(&p->update_out,
13675 memory_order_relaxed));
13676 json_object_int_add(json_stat, "updatesRecv",
13677 atomic_load_explicit(&p->update_in,
13678 memory_order_relaxed));
d62a17ae 13679 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
13680 atomic_load_explicit(&p->keepalive_out,
13681 memory_order_relaxed));
d62a17ae 13682 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
13683 atomic_load_explicit(&p->keepalive_in,
13684 memory_order_relaxed));
d62a17ae 13685 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
13686 atomic_load_explicit(&p->refresh_out,
13687 memory_order_relaxed));
d62a17ae 13688 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
13689 atomic_load_explicit(&p->refresh_in,
13690 memory_order_relaxed));
d62a17ae 13691 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
13692 atomic_load_explicit(&p->dynamic_cap_out,
13693 memory_order_relaxed));
d62a17ae 13694 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
13695 atomic_load_explicit(&p->dynamic_cap_in,
13696 memory_order_relaxed));
13697 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13698 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 13699 json_object_object_add(json_neigh, "messageStats", json_stat);
13700 } else {
cb93e0a2
IS
13701 atomic_size_t outq_count, inq_count, open_out, open_in,
13702 notify_out, notify_in, update_out, update_in,
13703 keepalive_out, keepalive_in, refresh_out, refresh_in,
13704 dynamic_cap_out, dynamic_cap_in;
43aa5965
QY
13705 outq_count = atomic_load_explicit(&p->obuf->count,
13706 memory_order_relaxed);
13707 inq_count = atomic_load_explicit(&p->ibuf->count,
13708 memory_order_relaxed);
cb93e0a2
IS
13709 open_out = atomic_load_explicit(&p->open_out,
13710 memory_order_relaxed);
13711 open_in =
13712 atomic_load_explicit(&p->open_in, memory_order_relaxed);
13713 notify_out = atomic_load_explicit(&p->notify_out,
13714 memory_order_relaxed);
13715 notify_in = atomic_load_explicit(&p->notify_in,
13716 memory_order_relaxed);
13717 update_out = atomic_load_explicit(&p->update_out,
13718 memory_order_relaxed);
13719 update_in = atomic_load_explicit(&p->update_in,
13720 memory_order_relaxed);
13721 keepalive_out = atomic_load_explicit(&p->keepalive_out,
13722 memory_order_relaxed);
13723 keepalive_in = atomic_load_explicit(&p->keepalive_in,
13724 memory_order_relaxed);
13725 refresh_out = atomic_load_explicit(&p->refresh_out,
13726 memory_order_relaxed);
13727 refresh_in = atomic_load_explicit(&p->refresh_in,
13728 memory_order_relaxed);
13729 dynamic_cap_out = atomic_load_explicit(&p->dynamic_cap_out,
13730 memory_order_relaxed);
13731 dynamic_cap_in = atomic_load_explicit(&p->dynamic_cap_in,
13732 memory_order_relaxed);
43aa5965 13733
d62a17ae 13734 /* Packet counts. */
13735 vty_out(vty, " Message statistics:\n");
43aa5965
QY
13736 vty_out(vty, " Inq depth is %zu\n", inq_count);
13737 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 13738 vty_out(vty, " Sent Rcvd\n");
cb93e0a2
IS
13739 vty_out(vty, " Opens: %10zu %10zu\n", open_out,
13740 open_in);
13741 vty_out(vty, " Notifications: %10zu %10zu\n", notify_out,
13742 notify_in);
13743 vty_out(vty, " Updates: %10zu %10zu\n", update_out,
13744 update_in);
13745 vty_out(vty, " Keepalives: %10zu %10zu\n", keepalive_out,
13746 keepalive_in);
13747 vty_out(vty, " Route Refresh: %10zu %10zu\n", refresh_out,
13748 refresh_in);
13749 vty_out(vty, " Capability: %10zu %10zu\n",
13750 dynamic_cap_out, dynamic_cap_in);
13751 vty_out(vty, " Total: %10u %10u\n",
13752 (uint32_t)PEER_TOTAL_TX(p), (uint32_t)PEER_TOTAL_RX(p));
d62a17ae 13753 }
13754
13755 if (use_json) {
13756 /* advertisement-interval */
13757 json_object_int_add(json_neigh,
13758 "minBtwnAdvertisementRunsTimerMsecs",
13759 p->v_routeadv * 1000);
13760
13761 /* Update-source. */
13762 if (p->update_if || p->update_source) {
13763 if (p->update_if)
13764 json_object_string_add(json_neigh,
13765 "updateSource",
13766 p->update_if);
13767 else if (p->update_source)
13768 json_object_string_add(
13769 json_neigh, "updateSource",
13770 sockunion2str(p->update_source, buf1,
13771 SU_ADDRSTRLEN));
13772 }
13773 } else {
13774 /* advertisement-interval */
13775 vty_out(vty,
13776 " Minimum time between advertisement runs is %d seconds\n",
13777 p->v_routeadv);
13778
13779 /* Update-source. */
13780 if (p->update_if || p->update_source) {
13781 vty_out(vty, " Update source is ");
13782 if (p->update_if)
13783 vty_out(vty, "%s", p->update_if);
13784 else if (p->update_source)
13785 vty_out(vty, "%s",
13786 sockunion2str(p->update_source, buf1,
13787 SU_ADDRSTRLEN));
13788 vty_out(vty, "\n");
13789 }
13790
13791 vty_out(vty, "\n");
13792 }
13793
13794 /* Address Family Information */
13795 json_object *json_hold = NULL;
13796
13797 if (use_json)
13798 json_hold = json_object_new_object();
13799
05c7a1cc
QY
13800 FOREACH_AFI_SAFI (afi, safi)
13801 if (p->afc[afi][safi])
13802 bgp_show_peer_afi(vty, p, afi, safi, use_json,
13803 json_hold);
d62a17ae 13804
13805 if (use_json) {
13806 json_object_object_add(json_neigh, "addressFamilyInfo",
13807 json_hold);
13808 json_object_int_add(json_neigh, "connectionsEstablished",
13809 p->established);
13810 json_object_int_add(json_neigh, "connectionsDropped",
13811 p->dropped);
13812 } else
13813 vty_out(vty, " Connections established %d; dropped %d\n",
13814 p->established, p->dropped);
13815
13816 if (!p->last_reset) {
13817 if (use_json)
13818 json_object_string_add(json_neigh, "lastReset",
13819 "never");
13820 else
13821 vty_out(vty, " Last reset never\n");
13822 } else {
13823 if (use_json) {
13824 time_t uptime;
a2700b50 13825 struct tm tm;
d62a17ae 13826
13827 uptime = bgp_clock();
13828 uptime -= p->resettime;
a2700b50
MS
13829 gmtime_r(&uptime, &tm);
13830
d62a17ae 13831 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
13832 (tm.tm_sec * 1000)
13833 + (tm.tm_min * 60000)
13834 + (tm.tm_hour * 3600000));
3577f1c5 13835 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 13836 } else {
13837 vty_out(vty, " Last reset %s, ",
13838 peer_uptime(p->resettime, timebuf,
13839 BGP_UPTIME_LEN, 0, NULL));
13840
3577f1c5 13841 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 13842 if (p->last_reset_cause_size) {
13843 msg = p->last_reset_cause;
13844 vty_out(vty,
13845 " Message received that caused BGP to send a NOTIFICATION:\n ");
13846 for (i = 1; i <= p->last_reset_cause_size;
13847 i++) {
13848 vty_out(vty, "%02X", *msg++);
13849
13850 if (i != p->last_reset_cause_size) {
13851 if (i % 16 == 0) {
13852 vty_out(vty, "\n ");
13853 } else if (i % 4 == 0) {
13854 vty_out(vty, " ");
13855 }
13856 }
13857 }
13858 vty_out(vty, "\n");
13859 }
13860 }
13861 }
13862
13863 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
13864 if (use_json)
13865 json_object_boolean_true_add(json_neigh,
13866 "prefixesConfigExceedMax");
13867 else
13868 vty_out(vty,
13869 " Peer had exceeded the max. no. of prefixes configured.\n");
13870
13871 if (p->t_pmax_restart) {
13872 if (use_json) {
13873 json_object_boolean_true_add(
13874 json_neigh, "reducePrefixNumFrom");
13875 json_object_int_add(json_neigh,
13876 "restartInTimerMsec",
13877 thread_timer_remain_second(
13878 p->t_pmax_restart)
13879 * 1000);
13880 } else
13881 vty_out(vty,
13882 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
13883 p->host, thread_timer_remain_second(
13884 p->t_pmax_restart));
d62a17ae 13885 } else {
13886 if (use_json)
13887 json_object_boolean_true_add(
13888 json_neigh,
13889 "reducePrefixNumAndClearIpBgp");
13890 else
13891 vty_out(vty,
13892 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
13893 p->host);
13894 }
13895 }
13896
13897 /* EBGP Multihop and GTSM */
13898 if (p->sort != BGP_PEER_IBGP) {
13899 if (use_json) {
e2521429 13900 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13901 json_object_int_add(json_neigh,
13902 "externalBgpNbrMaxHopsAway",
13903 p->gtsm_hops);
c8d6f0d6 13904 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13905 json_object_int_add(json_neigh,
13906 "externalBgpNbrMaxHopsAway",
13907 p->ttl);
13908 } else {
e2521429 13909 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 13910 vty_out(vty,
13911 " External BGP neighbor may be up to %d hops away.\n",
13912 p->gtsm_hops);
c8d6f0d6 13913 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 13914 vty_out(vty,
13915 " External BGP neighbor may be up to %d hops away.\n",
13916 p->ttl);
13917 }
13918 } else {
e2521429 13919 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 13920 if (use_json)
13921 json_object_int_add(json_neigh,
13922 "internalBgpNbrMaxHopsAway",
13923 p->gtsm_hops);
13924 else
13925 vty_out(vty,
13926 " Internal BGP neighbor may be up to %d hops away.\n",
13927 p->gtsm_hops);
13928 }
13929 }
13930
13931 /* Local address. */
13932 if (p->su_local) {
13933 if (use_json) {
13934 json_object_string_add(json_neigh, "hostLocal",
13935 sockunion2str(p->su_local, buf1,
13936 SU_ADDRSTRLEN));
13937 json_object_int_add(json_neigh, "portLocal",
13938 ntohs(p->su_local->sin.sin_port));
13939 } else
13940 vty_out(vty, "Local host: %s, Local port: %d\n",
13941 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
13942 ntohs(p->su_local->sin.sin_port));
13943 }
13944
13945 /* Remote address. */
13946 if (p->su_remote) {
13947 if (use_json) {
13948 json_object_string_add(json_neigh, "hostForeign",
13949 sockunion2str(p->su_remote, buf1,
13950 SU_ADDRSTRLEN));
13951 json_object_int_add(json_neigh, "portForeign",
13952 ntohs(p->su_remote->sin.sin_port));
13953 } else
13954 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
13955 sockunion2str(p->su_remote, buf1,
13956 SU_ADDRSTRLEN),
13957 ntohs(p->su_remote->sin.sin_port));
13958 }
13959
13960 /* Nexthop display. */
13961 if (p->su_local) {
13962 if (use_json) {
c949c771
DA
13963 json_object_string_addf(json_neigh, "nexthop", "%pI4",
13964 &p->nexthop.v4);
13965 json_object_string_addf(json_neigh, "nexthopGlobal",
13966 "%pI6", &p->nexthop.v6_global);
13967 json_object_string_addf(json_neigh, "nexthopLocal",
13968 "%pI6", &p->nexthop.v6_local);
d62a17ae 13969 if (p->shared_network)
13970 json_object_string_add(json_neigh,
13971 "bgpConnection",
13972 "sharedNetwork");
13973 else
13974 json_object_string_add(json_neigh,
13975 "bgpConnection",
13976 "nonSharedNetwork");
13977 } else {
13978 vty_out(vty, "Nexthop: %s\n",
13979 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
13980 sizeof(buf1)));
13981 vty_out(vty, "Nexthop global: %s\n",
13982 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
13983 sizeof(buf1)));
13984 vty_out(vty, "Nexthop local: %s\n",
13985 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
13986 sizeof(buf1)));
13987 vty_out(vty, "BGP connection: %s\n",
13988 p->shared_network ? "shared network"
13989 : "non shared network");
13990 }
13991 }
13992
13993 /* Timer information. */
13994 if (use_json) {
13995 json_object_int_add(json_neigh, "connectRetryTimer",
13996 p->v_connect);
feb17238 13997 if (peer_established(p) && p->rtt)
d62a17ae 13998 json_object_int_add(json_neigh, "estimatedRttInMsecs",
13999 p->rtt);
14000 if (p->t_start)
14001 json_object_int_add(
14002 json_neigh, "nextStartTimerDueInMsecs",
14003 thread_timer_remain_second(p->t_start) * 1000);
14004 if (p->t_connect)
14005 json_object_int_add(
14006 json_neigh, "nextConnectTimerDueInMsecs",
14007 thread_timer_remain_second(p->t_connect)
14008 * 1000);
14009 if (p->t_routeadv) {
14010 json_object_int_add(json_neigh, "mraiInterval",
14011 p->v_routeadv);
14012 json_object_int_add(
14013 json_neigh, "mraiTimerExpireInMsecs",
14014 thread_timer_remain_second(p->t_routeadv)
14015 * 1000);
14016 }
14017 if (p->password)
14018 json_object_int_add(json_neigh, "authenticationEnabled",
14019 1);
14020
14021 if (p->t_read)
14022 json_object_string_add(json_neigh, "readThread", "on");
14023 else
14024 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14025
14026 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14027 json_object_string_add(json_neigh, "writeThread", "on");
14028 else
14029 json_object_string_add(json_neigh, "writeThread",
14030 "off");
14031 } else {
14032 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14033 p->v_connect);
feb17238 14034 if (peer_established(p) && p->rtt)
d62a17ae 14035 vty_out(vty, "Estimated round trip time: %d ms\n",
14036 p->rtt);
14037 if (p->t_start)
14038 vty_out(vty, "Next start timer due in %ld seconds\n",
14039 thread_timer_remain_second(p->t_start));
14040 if (p->t_connect)
14041 vty_out(vty, "Next connect timer due in %ld seconds\n",
14042 thread_timer_remain_second(p->t_connect));
14043 if (p->t_routeadv)
14044 vty_out(vty,
14045 "MRAI (interval %u) timer expires in %ld seconds\n",
14046 p->v_routeadv,
14047 thread_timer_remain_second(p->t_routeadv));
14048 if (p->password)
14049 vty_out(vty, "Peer Authentication Enabled\n");
14050
cac9e917 14051 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14052 p->t_read ? "on" : "off",
14053 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14054 ? "on"
cac9e917 14055 : "off", p->fd);
d62a17ae 14056 }
14057
14058 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14059 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14060 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14061
14062 if (!use_json)
14063 vty_out(vty, "\n");
14064
14065 /* BFD information. */
21bfce98
RZ
14066 if (p->bfd_config)
14067 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14068
14069 if (use_json) {
14070 if (p->conf_if) /* Configured interface name. */
14071 json_object_object_add(json, p->conf_if, json_neigh);
14072 else /* Configured IP address. */
14073 json_object_object_add(json, p->host, json_neigh);
14074 }
14075}
14076
36235319
QY
14077static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14078 enum show_type type,
14079 union sockunion *su,
14080 const char *conf_if, afi_t afi,
74a630b6 14081 bool use_json)
2986cac2 14082{
14083 struct listnode *node, *nnode;
14084 struct peer *peer;
14085 int find = 0;
14086 safi_t safi = SAFI_UNICAST;
74a630b6 14087 json_object *json = NULL;
2986cac2 14088 json_object *json_neighbor = NULL;
14089
74a630b6
NT
14090 if (use_json) {
14091 json = json_object_new_object();
14092 json_neighbor = json_object_new_object();
14093 }
14094
2986cac2 14095 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14096
14097 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14098 continue;
14099
14100 if ((peer->afc[afi][safi]) == 0)
14101 continue;
14102
2ba1fe69 14103 if (type == show_all) {
2986cac2 14104 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14105 json_neighbor);
2986cac2 14106
74a630b6 14107 if (use_json) {
13909c4f
DS
14108 json_object_object_add(json, peer->host,
14109 json_neighbor);
74a630b6
NT
14110 json_neighbor = NULL;
14111 }
2986cac2 14112
2ba1fe69 14113 } else if (type == show_peer) {
2986cac2 14114 if (conf_if) {
14115 if ((peer->conf_if
13909c4f
DS
14116 && !strcmp(peer->conf_if, conf_if))
14117 || (peer->hostname
2986cac2 14118 && !strcmp(peer->hostname, conf_if))) {
14119 find = 1;
13909c4f
DS
14120 bgp_show_peer_gr_status(vty, peer,
14121 use_json,
14122 json_neighbor);
2986cac2 14123 }
14124 } else {
14125 if (sockunion_same(&peer->su, su)) {
14126 find = 1;
13909c4f
DS
14127 bgp_show_peer_gr_status(vty, peer,
14128 use_json,
14129 json_neighbor);
2986cac2 14130 }
14131 }
13909c4f
DS
14132 if (use_json && find)
14133 json_object_object_add(json, peer->host,
14134 json_neighbor);
2986cac2 14135 }
14136
74a630b6
NT
14137 if (find) {
14138 json_neighbor = NULL;
2986cac2 14139 break;
74a630b6 14140 }
2986cac2 14141 }
14142
14143 if (type == show_peer && !find) {
14144 if (use_json)
13909c4f 14145 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14146 else
14147 vty_out(vty, "%% No such neighbor\n");
14148 }
14149 if (use_json) {
74a630b6
NT
14150 if (json_neighbor)
14151 json_object_free(json_neighbor);
75eeda93 14152 vty_json(vty, json);
2986cac2 14153 } else {
14154 vty_out(vty, "\n");
14155 }
14156
14157 return CMD_SUCCESS;
14158}
14159
d62a17ae 14160static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14161 enum show_type type, union sockunion *su,
9f049418 14162 const char *conf_if, bool use_json,
d62a17ae 14163 json_object *json)
14164{
14165 struct listnode *node, *nnode;
14166 struct peer *peer;
14167 int find = 0;
9f049418 14168 bool nbr_output = false;
d1927ebe
AS
14169 afi_t afi = AFI_MAX;
14170 safi_t safi = SAFI_MAX;
14171
14172 if (type == show_ipv4_peer || type == show_ipv4_all) {
14173 afi = AFI_IP;
14174 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14175 afi = AFI_IP6;
14176 }
d62a17ae 14177
14178 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14179 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14180 continue;
14181
14182 switch (type) {
14183 case show_all:
14184 bgp_show_peer(vty, peer, use_json, json);
9f049418 14185 nbr_output = true;
d62a17ae 14186 break;
14187 case show_peer:
14188 if (conf_if) {
14189 if ((peer->conf_if
14190 && !strcmp(peer->conf_if, conf_if))
14191 || (peer->hostname
14192 && !strcmp(peer->hostname, conf_if))) {
14193 find = 1;
14194 bgp_show_peer(vty, peer, use_json,
14195 json);
14196 }
14197 } else {
14198 if (sockunion_same(&peer->su, su)) {
14199 find = 1;
14200 bgp_show_peer(vty, peer, use_json,
14201 json);
14202 }
14203 }
14204 break;
d1927ebe
AS
14205 case show_ipv4_peer:
14206 case show_ipv6_peer:
14207 FOREACH_SAFI (safi) {
14208 if (peer->afc[afi][safi]) {
14209 if (conf_if) {
14210 if ((peer->conf_if
14211 && !strcmp(peer->conf_if, conf_if))
14212 || (peer->hostname
14213 && !strcmp(peer->hostname, conf_if))) {
14214 find = 1;
14215 bgp_show_peer(vty, peer, use_json,
14216 json);
14217 break;
14218 }
14219 } else {
14220 if (sockunion_same(&peer->su, su)) {
14221 find = 1;
14222 bgp_show_peer(vty, peer, use_json,
14223 json);
14224 break;
14225 }
14226 }
14227 }
14228 }
14229 break;
14230 case show_ipv4_all:
14231 case show_ipv6_all:
14232 FOREACH_SAFI (safi) {
14233 if (peer->afc[afi][safi]) {
14234 bgp_show_peer(vty, peer, use_json, json);
14235 nbr_output = true;
14236 break;
14237 }
14238 }
14239 break;
d62a17ae 14240 }
14241 }
14242
d1927ebe
AS
14243 if ((type == show_peer || type == show_ipv4_peer ||
14244 type == show_ipv6_peer) && !find) {
d62a17ae 14245 if (use_json)
14246 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14247 else
88b7d255 14248 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14249 }
14250
d1927ebe
AS
14251 if (type != show_peer && type != show_ipv4_peer &&
14252 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14253 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14254
d62a17ae 14255 if (use_json) {
996c9314
LB
14256 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14257 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14258 } else {
14259 vty_out(vty, "\n");
14260 }
14261
14262 return CMD_SUCCESS;
14263}
14264
36235319
QY
14265static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14266 enum show_type type,
14267 const char *ip_str,
14268 afi_t afi, bool use_json)
2986cac2 14269{
14270
14271 int ret;
14272 struct bgp *bgp;
14273 union sockunion su;
2986cac2 14274
14275 bgp = bgp_get_default();
14276
13909c4f
DS
14277 if (!bgp)
14278 return;
2986cac2 14279
13909c4f
DS
14280 if (!use_json)
14281 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14282 NULL);
2986cac2 14283
13909c4f
DS
14284 if (ip_str) {
14285 ret = str2sockunion(ip_str, &su);
14286 if (ret < 0)
13909c4f 14287 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14288 vty, bgp, type, NULL, ip_str, afi, use_json);
14289 else
14290 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14291 NULL, afi, use_json);
13909c4f
DS
14292 } else
14293 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14294 afi, use_json);
2986cac2 14295}
14296
d62a17ae 14297static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14298 enum show_type type,
14299 const char *ip_str,
9f049418 14300 bool use_json)
d62a17ae 14301{
0291c246
MK
14302 struct listnode *node, *nnode;
14303 struct bgp *bgp;
71aedaa3 14304 union sockunion su;
0291c246 14305 json_object *json = NULL;
71aedaa3 14306 int ret, is_first = 1;
9f049418 14307 bool nbr_output = false;
d62a17ae 14308
14309 if (use_json)
14310 vty_out(vty, "{\n");
14311
14312 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14313 nbr_output = true;
d62a17ae 14314 if (use_json) {
14315 if (!(json = json_object_new_object())) {
af4c2728 14316 flog_err(
e50f7cfd 14317 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14318 "Unable to allocate memory for JSON object");
14319 vty_out(vty,
14320 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14321 return;
14322 }
14323
14324 json_object_int_add(json, "vrfId",
14325 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14326 ? -1
14327 : (int64_t)bgp->vrf_id);
d62a17ae 14328 json_object_string_add(
14329 json, "vrfName",
14330 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14331 ? VRF_DEFAULT_NAME
d62a17ae 14332 : bgp->name);
14333
14334 if (!is_first)
14335 vty_out(vty, ",\n");
14336 else
14337 is_first = 0;
14338
14339 vty_out(vty, "\"%s\":",
14340 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14341 ? VRF_DEFAULT_NAME
d62a17ae 14342 : bgp->name);
14343 } else {
14344 vty_out(vty, "\nInstance %s:\n",
14345 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14346 ? VRF_DEFAULT_NAME
d62a17ae 14347 : bgp->name);
14348 }
71aedaa3 14349
d1927ebe
AS
14350 if (type == show_peer || type == show_ipv4_peer ||
14351 type == show_ipv6_peer) {
71aedaa3
DS
14352 ret = str2sockunion(ip_str, &su);
14353 if (ret < 0)
14354 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14355 use_json, json);
14356 else
14357 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14358 use_json, json);
14359 } else {
d1927ebe 14360 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14361 use_json, json);
14362 }
b77004d6 14363 json_object_free(json);
121067e9 14364 json = NULL;
d62a17ae 14365 }
14366
3e78a6ce 14367 if (use_json)
d62a17ae 14368 vty_out(vty, "}\n");
9f049418
DS
14369 else if (!nbr_output)
14370 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14371}
14372
14373static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14374 enum show_type type, const char *ip_str,
9f049418 14375 bool use_json)
d62a17ae 14376{
14377 int ret;
14378 struct bgp *bgp;
14379 union sockunion su;
14380 json_object *json = NULL;
14381
14382 if (name) {
14383 if (strmatch(name, "all")) {
71aedaa3
DS
14384 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14385 use_json);
d62a17ae 14386 return CMD_SUCCESS;
14387 } else {
14388 bgp = bgp_lookup_by_name(name);
14389 if (!bgp) {
14390 if (use_json) {
14391 json = json_object_new_object();
75eeda93 14392 vty_json(vty, json);
d62a17ae 14393 } else
14394 vty_out(vty,
9f049418 14395 "%% BGP instance not found\n");
d62a17ae 14396
14397 return CMD_WARNING;
14398 }
14399 }
14400 } else {
14401 bgp = bgp_get_default();
14402 }
14403
14404 if (bgp) {
14405 json = json_object_new_object();
14406 if (ip_str) {
14407 ret = str2sockunion(ip_str, &su);
14408 if (ret < 0)
14409 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14410 use_json, json);
14411 else
14412 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14413 use_json, json);
14414 } else {
14415 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14416 json);
14417 }
14418 json_object_free(json);
ca61fd25
DS
14419 } else {
14420 if (use_json)
14421 vty_out(vty, "{}\n");
14422 else
14423 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14424 }
14425
14426 return CMD_SUCCESS;
4fb25c53
DW
14427}
14428
2986cac2 14429
14430
14431/* "show [ip] bgp neighbors graceful-restart" commands. */
14432DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14433 show_ip_bgp_neighbors_graceful_restart_cmd,
14434 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14435 SHOW_STR
14436 BGP_STR
14437 IP_STR
14438 IPV6_STR
14439 NEIGHBOR_STR
14440 "Neighbor to display information about\n"
14441 "Neighbor to display information about\n"
14442 "Neighbor on BGP configured interface\n"
14443 GR_SHOW
14444 JSON_STR)
14445{
14446 char *sh_arg = NULL;
14447 enum show_type sh_type;
14448 int idx = 0;
14449 afi_t afi = AFI_MAX;
2986cac2 14450 bool uj = use_json(argc, argv);
14451
36235319 14452 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14453 afi = AFI_MAX;
14454
14455 idx++;
14456
14457 if (argv_find(argv, argc, "A.B.C.D", &idx)
14458 || argv_find(argv, argc, "X:X::X:X", &idx)
14459 || argv_find(argv, argc, "WORD", &idx)) {
14460 sh_type = show_peer;
14461 sh_arg = argv[idx]->arg;
14462 } else
14463 sh_type = show_all;
14464
14465 if (!argv_find(argv, argc, "graceful-restart", &idx))
14466 return CMD_SUCCESS;
14467
14468
36235319
QY
14469 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14470 afi, uj);
2986cac2 14471}
14472
716b2d8a 14473/* "show [ip] bgp neighbors" commands. */
718e3744 14474DEFUN (show_ip_bgp_neighbors,
14475 show_ip_bgp_neighbors_cmd,
24345e82 14476 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14477 SHOW_STR
14478 IP_STR
14479 BGP_STR
f2a8972b 14480 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14481 "Address Family\n"
14482 "Address Family\n"
718e3744 14483 "Detailed information on TCP and BGP neighbor connections\n"
14484 "Neighbor to display information about\n"
a80beece 14485 "Neighbor to display information about\n"
91d37724 14486 "Neighbor on BGP configured interface\n"
9973d184 14487 JSON_STR)
718e3744 14488{
d62a17ae 14489 char *vrf = NULL;
14490 char *sh_arg = NULL;
14491 enum show_type sh_type;
d1927ebe 14492 afi_t afi = AFI_MAX;
718e3744 14493
9f049418 14494 bool uj = use_json(argc, argv);
718e3744 14495
d62a17ae 14496 int idx = 0;
718e3744 14497
9a8bdf1c
PG
14498 /* [<vrf> VIEWVRFNAME] */
14499 if (argv_find(argv, argc, "vrf", &idx)) {
14500 vrf = argv[idx + 1]->arg;
14501 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14502 vrf = NULL;
14503 } else if (argv_find(argv, argc, "view", &idx))
14504 /* [<view> VIEWVRFNAME] */
d62a17ae 14505 vrf = argv[idx + 1]->arg;
718e3744 14506
d62a17ae 14507 idx++;
d1927ebe
AS
14508
14509 if (argv_find(argv, argc, "ipv4", &idx)) {
14510 sh_type = show_ipv4_all;
14511 afi = AFI_IP;
14512 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14513 sh_type = show_ipv6_all;
14514 afi = AFI_IP6;
14515 } else {
14516 sh_type = show_all;
14517 }
14518
d62a17ae 14519 if (argv_find(argv, argc, "A.B.C.D", &idx)
14520 || argv_find(argv, argc, "X:X::X:X", &idx)
14521 || argv_find(argv, argc, "WORD", &idx)) {
14522 sh_type = show_peer;
14523 sh_arg = argv[idx]->arg;
d1927ebe
AS
14524 }
14525
14526 if (sh_type == show_peer && afi == AFI_IP) {
14527 sh_type = show_ipv4_peer;
14528 } else if (sh_type == show_peer && afi == AFI_IP6) {
14529 sh_type = show_ipv6_peer;
14530 }
856ca177 14531
d62a17ae 14532 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 14533}
14534
716b2d8a 14535/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 14536 paths' and `show ip mbgp paths'. Those functions results are the
14537 same.*/
f412b39a 14538DEFUN (show_ip_bgp_paths,
718e3744 14539 show_ip_bgp_paths_cmd,
46f296b4 14540 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 14541 SHOW_STR
14542 IP_STR
14543 BGP_STR
46f296b4 14544 BGP_SAFI_HELP_STR
718e3744 14545 "Path information\n")
14546{
d62a17ae 14547 vty_out(vty, "Address Refcnt Path\n");
14548 aspath_print_all_vty(vty);
14549 return CMD_SUCCESS;
718e3744 14550}
14551
718e3744 14552#include "hash.h"
14553
e3b78da8 14554static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14555 struct vty *vty)
718e3744 14556{
d62a17ae 14557 struct community *com;
718e3744 14558
e3b78da8 14559 com = (struct community *)bucket->data;
3f65c5b1 14560 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
c0945b78 14561 community_str(com, false, false));
718e3744 14562}
14563
14564/* Show BGP's community internal data. */
f412b39a 14565DEFUN (show_ip_bgp_community_info,
718e3744 14566 show_ip_bgp_community_info_cmd,
bec37ba5 14567 "show [ip] bgp community-info",
718e3744 14568 SHOW_STR
14569 IP_STR
14570 BGP_STR
14571 "List all bgp community information\n")
14572{
d62a17ae 14573 vty_out(vty, "Address Refcnt Community\n");
718e3744 14574
d62a17ae 14575 hash_iterate(community_hash(),
e3b78da8 14576 (void (*)(struct hash_bucket *,
d62a17ae 14577 void *))community_show_all_iterator,
14578 vty);
718e3744 14579
d62a17ae 14580 return CMD_SUCCESS;
718e3744 14581}
14582
e3b78da8 14583static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 14584 struct vty *vty)
57d187bc 14585{
d62a17ae 14586 struct lcommunity *lcom;
57d187bc 14587
e3b78da8 14588 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 14589 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
c0945b78 14590 lcommunity_str(lcom, false, false));
57d187bc
JS
14591}
14592
14593/* Show BGP's community internal data. */
14594DEFUN (show_ip_bgp_lcommunity_info,
14595 show_ip_bgp_lcommunity_info_cmd,
14596 "show ip bgp large-community-info",
14597 SHOW_STR
14598 IP_STR
14599 BGP_STR
14600 "List all bgp large-community information\n")
14601{
d62a17ae 14602 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 14603
d62a17ae 14604 hash_iterate(lcommunity_hash(),
e3b78da8 14605 (void (*)(struct hash_bucket *,
d62a17ae 14606 void *))lcommunity_show_all_iterator,
14607 vty);
57d187bc 14608
d62a17ae 14609 return CMD_SUCCESS;
57d187bc 14610}
2986cac2 14611/* Graceful Restart */
14612
14613static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
14614 struct bgp *bgp,
14615 bool use_json,
14616 json_object *json)
2986cac2 14617{
57d187bc
JS
14618
14619
2986cac2 14620 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14621
7318ae88 14622 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 14623
14624 switch (bgp_global_gr_mode) {
14625
14626 case GLOBAL_HELPER:
13909c4f 14627 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 14628 break;
14629
14630 case GLOBAL_GR:
13909c4f 14631 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 14632 break;
14633
14634 case GLOBAL_DISABLE:
13909c4f 14635 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 14636 break;
14637
14638 case GLOBAL_INVALID:
2986cac2 14639 vty_out(vty,
2ba1fe69 14640 "Global BGP GR Mode Invalid\n");
2986cac2 14641 break;
14642 }
14643 vty_out(vty, "\n");
14644}
14645
36235319
QY
14646static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14647 enum show_type type,
14648 const char *ip_str,
14649 afi_t afi, bool use_json)
2986cac2 14650{
14651 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14652 afi = AFI_IP;
14653
14654 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14655
36235319
QY
14656 bgp_show_neighbor_graceful_restart_vty(
14657 vty, type, ip_str, afi, use_json);
2986cac2 14658 afi++;
14659 }
14660 } else if (afi != AFI_MAX) {
36235319
QY
14661 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14662 use_json);
2986cac2 14663 } else {
14664 return CMD_ERR_INCOMPLETE;
14665 }
14666
14667 return CMD_SUCCESS;
14668}
14669/* Graceful Restart */
14670
f412b39a 14671DEFUN (show_ip_bgp_attr_info,
718e3744 14672 show_ip_bgp_attr_info_cmd,
bec37ba5 14673 "show [ip] bgp attribute-info",
718e3744 14674 SHOW_STR
14675 IP_STR
14676 BGP_STR
14677 "List all bgp attribute information\n")
14678{
d62a17ae 14679 attr_show_all(vty);
14680 return CMD_SUCCESS;
718e3744 14681}
6b0655a2 14682
03915806
CS
14683static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14684 afi_t afi, safi_t safi,
14685 bool use_json, json_object *json)
53089bec 14686{
14687 struct bgp *bgp;
14688 struct listnode *node;
14689 char *vname;
14690 char buf1[INET6_ADDRSTRLEN];
14691 char *ecom_str;
9c2fd3fe 14692 enum vpn_policy_direction dir;
53089bec 14693
03915806 14694 if (json) {
b46dfd20
DS
14695 json_object *json_import_vrfs = NULL;
14696 json_object *json_export_vrfs = NULL;
14697
b46dfd20
DS
14698 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14699
53089bec 14700 if (!bgp) {
75eeda93 14701 vty_json(vty, json);
b46dfd20 14702
53089bec 14703 return CMD_WARNING;
14704 }
b46dfd20 14705
94d4c685
DS
14706 /* Provide context for the block */
14707 json_object_string_add(json, "vrf", name ? name : "default");
14708 json_object_string_add(json, "afiSafi",
5cb5f4d0 14709 get_afi_safi_str(afi, safi, true));
94d4c685 14710
b46dfd20
DS
14711 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14712 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14713 json_object_string_add(json, "importFromVrfs", "none");
14714 json_object_string_add(json, "importRts", "none");
14715 } else {
6ce24e52
DS
14716 json_import_vrfs = json_object_new_array();
14717
b46dfd20
DS
14718 for (ALL_LIST_ELEMENTS_RO(
14719 bgp->vpn_policy[afi].import_vrf,
14720 node, vname))
14721 json_object_array_add(json_import_vrfs,
14722 json_object_new_string(vname));
14723
b20875ea
CS
14724 json_object_object_add(json, "importFromVrfs",
14725 json_import_vrfs);
b46dfd20 14726 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14727 if (bgp->vpn_policy[afi].rtlist[dir]) {
14728 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14729 bgp->vpn_policy[afi].rtlist[dir],
14730 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14731 json_object_string_add(json, "importRts",
14732 ecom_str);
14733 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14734 } else
14735 json_object_string_add(json, "importRts",
14736 "none");
b46dfd20
DS
14737 }
14738
14739 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14740 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14741 json_object_string_add(json, "exportToVrfs", "none");
14742 json_object_string_add(json, "routeDistinguisher",
14743 "none");
14744 json_object_string_add(json, "exportRts", "none");
14745 } else {
6ce24e52
DS
14746 json_export_vrfs = json_object_new_array();
14747
b46dfd20
DS
14748 for (ALL_LIST_ELEMENTS_RO(
14749 bgp->vpn_policy[afi].export_vrf,
14750 node, vname))
14751 json_object_array_add(json_export_vrfs,
14752 json_object_new_string(vname));
14753 json_object_object_add(json, "exportToVrfs",
14754 json_export_vrfs);
14755 json_object_string_add(json, "routeDistinguisher",
14756 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14757 buf1, RD_ADDRSTRLEN));
14758
14759 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14760 if (bgp->vpn_policy[afi].rtlist[dir]) {
14761 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14762 bgp->vpn_policy[afi].rtlist[dir],
14763 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14764 json_object_string_add(json, "exportRts",
14765 ecom_str);
14766 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14767 } else
14768 json_object_string_add(json, "exportRts",
14769 "none");
b46dfd20
DS
14770 }
14771
03915806 14772 if (use_json) {
75eeda93 14773 vty_json(vty, json);
03915806 14774 }
53089bec 14775 } else {
b46dfd20
DS
14776 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14777
53089bec 14778 if (!bgp) {
b46dfd20 14779 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 14780 return CMD_WARNING;
14781 }
53089bec 14782
b46dfd20
DS
14783 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14784 BGP_CONFIG_VRF_TO_VRF_IMPORT))
14785 vty_out(vty,
14786 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 14787 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14788 else {
14789 vty_out(vty,
14790 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 14791 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14792
14793 for (ALL_LIST_ELEMENTS_RO(
14794 bgp->vpn_policy[afi].import_vrf,
14795 node, vname))
14796 vty_out(vty, " %s\n", vname);
14797
14798 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
14799 ecom_str = NULL;
14800 if (bgp->vpn_policy[afi].rtlist[dir]) {
14801 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14802 bgp->vpn_policy[afi].rtlist[dir],
14803 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 14804 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 14805
b20875ea
CS
14806 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14807 } else
14808 vty_out(vty, "Import RT(s):\n");
53089bec 14809 }
53089bec 14810
b46dfd20
DS
14811 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14812 BGP_CONFIG_VRF_TO_VRF_EXPORT))
14813 vty_out(vty,
14814 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 14815 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14816 else {
14817 vty_out(vty,
04c9077f 14818 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 14819 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
14820
14821 for (ALL_LIST_ELEMENTS_RO(
14822 bgp->vpn_policy[afi].export_vrf,
14823 node, vname))
14824 vty_out(vty, " %s\n", vname);
14825
14826 vty_out(vty, "RD: %s\n",
14827 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14828 buf1, RD_ADDRSTRLEN));
14829
14830 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
14831 if (bgp->vpn_policy[afi].rtlist[dir]) {
14832 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
14833 bgp->vpn_policy[afi].rtlist[dir],
14834 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
14835 vty_out(vty, "Export RT: %s\n", ecom_str);
14836 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14837 } else
14838 vty_out(vty, "Import RT(s):\n");
53089bec 14839 }
53089bec 14840 }
14841
14842 return CMD_SUCCESS;
14843}
14844
03915806
CS
14845static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
14846 safi_t safi, bool use_json)
14847{
14848 struct listnode *node, *nnode;
14849 struct bgp *bgp;
14850 char *vrf_name = NULL;
14851 json_object *json = NULL;
14852 json_object *json_vrf = NULL;
14853 json_object *json_vrfs = NULL;
14854
14855 if (use_json) {
14856 json = json_object_new_object();
14857 json_vrfs = json_object_new_object();
14858 }
14859
14860 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14861
14862 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
14863 vrf_name = bgp->name;
14864
14865 if (use_json) {
14866 json_vrf = json_object_new_object();
14867 } else {
14868 vty_out(vty, "\nInstance %s:\n",
14869 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14870 ? VRF_DEFAULT_NAME : bgp->name);
14871 }
14872 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
14873 if (use_json) {
14874 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14875 json_object_object_add(json_vrfs,
14876 VRF_DEFAULT_NAME, json_vrf);
14877 else
14878 json_object_object_add(json_vrfs, vrf_name,
14879 json_vrf);
14880 }
14881 }
14882
14883 if (use_json) {
14884 json_object_object_add(json, "vrfs", json_vrfs);
75eeda93 14885 vty_json(vty, json);
03915806
CS
14886 }
14887
14888 return CMD_SUCCESS;
14889}
14890
53089bec 14891/* "show [ip] bgp route-leak" command. */
14892DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
14893 show_ip_bgp_route_leak_cmd,
14894 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
14895 SHOW_STR
14896 IP_STR
14897 BGP_STR
14898 BGP_INSTANCE_HELP_STR
14899 BGP_AFI_HELP_STR
14900 BGP_SAFI_HELP_STR
14901 "Route leaking information\n"
14902 JSON_STR)
53089bec 14903{
14904 char *vrf = NULL;
14905 afi_t afi = AFI_MAX;
14906 safi_t safi = SAFI_MAX;
14907
9f049418 14908 bool uj = use_json(argc, argv);
53089bec 14909 int idx = 0;
03915806 14910 json_object *json = NULL;
53089bec 14911
14912 /* show [ip] bgp */
14913 if (argv_find(argv, argc, "ip", &idx)) {
14914 afi = AFI_IP;
14915 safi = SAFI_UNICAST;
14916 }
14917 /* [vrf VIEWVRFNAME] */
14918 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
14919 vty_out(vty,
14920 "%% This command is not applicable to BGP views\n");
53089bec 14921 return CMD_WARNING;
14922 }
14923
9a8bdf1c
PG
14924 if (argv_find(argv, argc, "vrf", &idx)) {
14925 vrf = argv[idx + 1]->arg;
14926 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14927 vrf = NULL;
14928 }
53089bec 14929 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
c48349e3 14930 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
53089bec 14931 argv_find_and_parse_safi(argv, argc, &idx, &safi);
53089bec 14932
14933 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
14934 vty_out(vty,
14935 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 14936 return CMD_WARNING;
14937 }
14938
03915806
CS
14939 if (vrf && strmatch(vrf, "all"))
14940 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
14941
14942 if (uj)
14943 json = json_object_new_object();
14944
14945 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 14946}
14947
d62a17ae 14948static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
14949 safi_t safi)
f186de26 14950{
d62a17ae 14951 struct listnode *node, *nnode;
14952 struct bgp *bgp;
f186de26 14953
d62a17ae 14954 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14955 vty_out(vty, "\nInstance %s:\n",
14956 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14957 ? VRF_DEFAULT_NAME
d62a17ae 14958 : bgp->name);
14959 update_group_show(bgp, afi, safi, vty, 0);
14960 }
f186de26 14961}
14962
d62a17ae 14963static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
14964 int safi, uint64_t subgrp_id)
4fb25c53 14965{
d62a17ae 14966 struct bgp *bgp;
4fb25c53 14967
d62a17ae 14968 if (name) {
14969 if (strmatch(name, "all")) {
14970 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
14971 return CMD_SUCCESS;
14972 } else {
14973 bgp = bgp_lookup_by_name(name);
14974 }
14975 } else {
14976 bgp = bgp_get_default();
14977 }
4fb25c53 14978
d62a17ae 14979 if (bgp)
14980 update_group_show(bgp, afi, safi, vty, subgrp_id);
14981 return CMD_SUCCESS;
4fb25c53
DW
14982}
14983
8fe8a7f6
DS
14984DEFUN (show_ip_bgp_updgrps,
14985 show_ip_bgp_updgrps_cmd,
c1a44e43 14986 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 14987 SHOW_STR
14988 IP_STR
14989 BGP_STR
14990 BGP_INSTANCE_HELP_STR
c9e571b4 14991 BGP_AFI_HELP_STR
9bedbb1e 14992 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
14993 "Detailed info about dynamic update groups\n"
14994 "Specific subgroup to display detailed info for\n")
8386ac43 14995{
d62a17ae 14996 char *vrf = NULL;
14997 afi_t afi = AFI_IP6;
14998 safi_t safi = SAFI_UNICAST;
14999 uint64_t subgrp_id = 0;
15000
15001 int idx = 0;
15002
15003 /* show [ip] bgp */
15004 if (argv_find(argv, argc, "ip", &idx))
15005 afi = AFI_IP;
9a8bdf1c
PG
15006 /* [<vrf> VIEWVRFNAME] */
15007 if (argv_find(argv, argc, "vrf", &idx)) {
15008 vrf = argv[idx + 1]->arg;
15009 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15010 vrf = NULL;
15011 } else if (argv_find(argv, argc, "view", &idx))
15012 /* [<view> VIEWVRFNAME] */
15013 vrf = argv[idx + 1]->arg;
d62a17ae 15014 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15015 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15016 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15017 }
5bf15956 15018
d62a17ae 15019 /* get subgroup id, if provided */
15020 idx = argc - 1;
15021 if (argv[idx]->type == VARIABLE_TKN)
15022 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15023
d62a17ae 15024 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15025}
15026
f186de26 15027DEFUN (show_bgp_instance_all_ipv6_updgrps,
15028 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15029 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15030 SHOW_STR
716b2d8a 15031 IP_STR
f186de26 15032 BGP_STR
15033 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15034 "Detailed info about dynamic update groups\n")
f186de26 15035{
d62a17ae 15036 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15037 return CMD_SUCCESS;
f186de26 15038}
15039
43d3f4fc
DS
15040DEFUN (show_bgp_l2vpn_evpn_updgrps,
15041 show_bgp_l2vpn_evpn_updgrps_cmd,
15042 "show [ip] bgp l2vpn evpn update-groups",
15043 SHOW_STR
15044 IP_STR
15045 BGP_STR
15046 "l2vpn address family\n"
15047 "evpn sub-address family\n"
15048 "Detailed info about dynamic update groups\n")
15049{
15050 char *vrf = NULL;
15051 uint64_t subgrp_id = 0;
15052
15053 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15054 return CMD_SUCCESS;
15055}
15056
5bf15956
DW
15057DEFUN (show_bgp_updgrps_stats,
15058 show_bgp_updgrps_stats_cmd,
716b2d8a 15059 "show [ip] bgp update-groups statistics",
3f9c7369 15060 SHOW_STR
716b2d8a 15061 IP_STR
3f9c7369 15062 BGP_STR
0c7b1b01 15063 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15064 "Statistics\n")
15065{
d62a17ae 15066 struct bgp *bgp;
3f9c7369 15067
d62a17ae 15068 bgp = bgp_get_default();
15069 if (bgp)
15070 update_group_show_stats(bgp, vty);
3f9c7369 15071
d62a17ae 15072 return CMD_SUCCESS;
3f9c7369
DS
15073}
15074
8386ac43 15075DEFUN (show_bgp_instance_updgrps_stats,
15076 show_bgp_instance_updgrps_stats_cmd,
18c57037 15077 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15078 SHOW_STR
716b2d8a 15079 IP_STR
8386ac43 15080 BGP_STR
15081 BGP_INSTANCE_HELP_STR
0c7b1b01 15082 "Detailed info about dynamic update groups\n"
8386ac43 15083 "Statistics\n")
15084{
d62a17ae 15085 int idx_word = 3;
15086 struct bgp *bgp;
8386ac43 15087
d62a17ae 15088 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15089 if (bgp)
15090 update_group_show_stats(bgp, vty);
8386ac43 15091
d62a17ae 15092 return CMD_SUCCESS;
8386ac43 15093}
15094
d62a17ae 15095static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15096 afi_t afi, safi_t safi,
15097 const char *what, uint64_t subgrp_id)
3f9c7369 15098{
d62a17ae 15099 struct bgp *bgp;
8386ac43 15100
d62a17ae 15101 if (name)
15102 bgp = bgp_lookup_by_name(name);
15103 else
15104 bgp = bgp_get_default();
8386ac43 15105
d62a17ae 15106 if (bgp) {
15107 if (!strcmp(what, "advertise-queue"))
15108 update_group_show_adj_queue(bgp, afi, safi, vty,
15109 subgrp_id);
15110 else if (!strcmp(what, "advertised-routes"))
15111 update_group_show_advertised(bgp, afi, safi, vty,
15112 subgrp_id);
15113 else if (!strcmp(what, "packet-queue"))
15114 update_group_show_packet_queue(bgp, afi, safi, vty,
15115 subgrp_id);
15116 }
3f9c7369
DS
15117}
15118
dc64bdec
QY
15119DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15120 show_ip_bgp_instance_updgrps_adj_s_cmd,
15121 "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",
15122 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15123 BGP_SAFI_HELP_STR
15124 "Detailed info about dynamic update groups\n"
15125 "Specific subgroup to display info for\n"
15126 "Advertisement queue\n"
15127 "Announced routes\n"
15128 "Packet queue\n")
3f9c7369 15129{
dc64bdec
QY
15130 uint64_t subgrp_id = 0;
15131 afi_t afiz;
15132 safi_t safiz;
15133 if (sgid)
15134 subgrp_id = strtoull(sgid, NULL, 10);
15135
15136 if (!ip && !afi)
15137 afiz = AFI_IP6;
15138 if (!ip && afi)
15139 afiz = bgp_vty_afi_from_str(afi);
15140 if (ip && !afi)
15141 afiz = AFI_IP;
15142 if (ip && afi) {
15143 afiz = bgp_vty_afi_from_str(afi);
15144 if (afiz != AFI_IP)
15145 vty_out(vty,
15146 "%% Cannot specify both 'ip' and 'ipv6'\n");
15147 return CMD_WARNING;
15148 }
d62a17ae 15149
dc64bdec 15150 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15151
dc64bdec 15152 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15153 return CMD_SUCCESS;
15154}
15155
6f4eacf3
DA
15156static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15157 json_object *json)
d62a17ae 15158{
15159 struct listnode *node, *nnode;
15160 struct prefix *range;
15161 struct peer *conf;
15162 struct peer *peer;
d62a17ae 15163 afi_t afi;
15164 safi_t safi;
15165 const char *peer_status;
d62a17ae 15166 int lr_count;
15167 int dynamic;
6f4eacf3
DA
15168 bool af_cfgd;
15169 json_object *json_peer_group = NULL;
15170 json_object *json_peer_group_afc = NULL;
15171 json_object *json_peer_group_members = NULL;
15172 json_object *json_peer_group_dynamic = NULL;
15173 json_object *json_peer_group_dynamic_af = NULL;
15174 json_object *json_peer_group_ranges = NULL;
d62a17ae 15175
15176 conf = group->conf;
15177
6f4eacf3
DA
15178 if (json) {
15179 json_peer_group = json_object_new_object();
15180 json_peer_group_afc = json_object_new_array();
15181 }
15182
d62a17ae 15183 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15184 if (json)
15185 json_object_int_add(json_peer_group, "remoteAs",
15186 conf->as);
15187 else
15188 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15189 group->name, conf->as);
d62a17ae 15190 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15191 if (json)
15192 json_object_int_add(json_peer_group, "remoteAs",
15193 group->bgp->as);
15194 else
15195 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15196 group->name, group->bgp->as);
d62a17ae 15197 } else {
6f4eacf3
DA
15198 if (!json)
15199 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15200 }
f14e6fdb 15201
6f4eacf3
DA
15202 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15203 if (json)
15204 json_object_string_add(json_peer_group, "type",
15205 "internal");
15206 else
15207 vty_out(vty, " Peer-group type is internal\n");
15208 } else {
15209 if (json)
15210 json_object_string_add(json_peer_group, "type",
15211 "external");
15212 else
15213 vty_out(vty, " Peer-group type is external\n");
15214 }
d62a17ae 15215
15216 /* Display AFs configured. */
6f4eacf3
DA
15217 if (!json)
15218 vty_out(vty, " Configured address-families:");
15219
05c7a1cc
QY
15220 FOREACH_AFI_SAFI (afi, safi) {
15221 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15222 af_cfgd = true;
15223 if (json)
15224 json_object_array_add(
15225 json_peer_group_afc,
15226 json_object_new_string(get_afi_safi_str(
15227 afi, safi, false)));
15228 else
15229 vty_out(vty, " %s;",
15230 get_afi_safi_str(afi, safi, false));
d62a17ae 15231 }
05c7a1cc 15232 }
6f4eacf3
DA
15233
15234 if (json) {
15235 json_object_object_add(json_peer_group,
15236 "addressFamiliesConfigured",
15237 json_peer_group_afc);
15238 } else {
15239 if (!af_cfgd)
15240 vty_out(vty, " none\n");
15241 else
15242 vty_out(vty, "\n");
15243 }
d62a17ae 15244
15245 /* Display listen ranges (for dynamic neighbors), if any */
15246 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15247 lr_count = listcount(group->listen_range[afi]);
15248 if (lr_count) {
6f4eacf3
DA
15249 if (json) {
15250 if (!json_peer_group_dynamic)
15251 json_peer_group_dynamic =
15252 json_object_new_object();
15253
15254 json_peer_group_dynamic_af =
15255 json_object_new_object();
15256 json_peer_group_ranges =
15257 json_object_new_array();
15258 json_object_int_add(json_peer_group_dynamic_af,
15259 "count", lr_count);
15260 } else {
15261 vty_out(vty, " %d %s listen range(s)\n",
15262 lr_count, afi2str(afi));
15263 }
d62a17ae 15264
15265 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15266 nnode, range)) {
15267 if (json) {
15268 char buf[BUFSIZ];
15269
15270 snprintfrr(buf, sizeof(buf), "%pFX",
15271 range);
15272
15273 json_object_array_add(
15274 json_peer_group_ranges,
15275 json_object_new_string(buf));
15276 } else {
15277 vty_out(vty, " %pFX\n", range);
15278 }
15279 }
15280
15281 if (json) {
15282 json_object_object_add(
15283 json_peer_group_dynamic_af, "ranges",
15284 json_peer_group_ranges);
15285
15286 json_object_object_add(
15287 json_peer_group_dynamic, afi2str(afi),
15288 json_peer_group_dynamic_af);
15289 }
d62a17ae 15290 }
15291 }
f14e6fdb 15292
6f4eacf3
DA
15293 if (json_peer_group_dynamic)
15294 json_object_object_add(json_peer_group, "dynamicRanges",
15295 json_peer_group_dynamic);
15296
d62a17ae 15297 /* Display group members and their status */
15298 if (listcount(group->peer)) {
6f4eacf3
DA
15299 if (json)
15300 json_peer_group_members = json_object_new_object();
15301 else
15302 vty_out(vty, " Peer-group members:\n");
d62a17ae 15303 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15304 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15305 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15306 peer_status = "Idle (Admin)";
15307 else if (CHECK_FLAG(peer->sflags,
15308 PEER_STATUS_PREFIX_OVERFLOW))
15309 peer_status = "Idle (PfxCt)";
15310 else
15311 peer_status = lookup_msg(bgp_status_msg,
15312 peer->status, NULL);
15313
15314 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15315
15316 if (json) {
15317 json_object *json_peer_group_member =
15318 json_object_new_object();
15319
15320 json_object_string_add(json_peer_group_member,
15321 "status", peer_status);
15322
15323 if (dynamic)
15324 json_object_boolean_true_add(
15325 json_peer_group_member,
15326 "dynamic");
15327
15328 json_object_object_add(json_peer_group_members,
15329 peer->host,
15330 json_peer_group_member);
15331 } else {
15332 vty_out(vty, " %s %s %s \n", peer->host,
15333 dynamic ? "(dynamic)" : "",
15334 peer_status);
15335 }
d62a17ae 15336 }
6f4eacf3
DA
15337 if (json)
15338 json_object_object_add(json_peer_group, "members",
15339 json_peer_group_members);
d62a17ae 15340 }
f14e6fdb 15341
6f4eacf3
DA
15342 if (json)
15343 json_object_object_add(json, group->name, json_peer_group);
15344
d62a17ae 15345 return CMD_SUCCESS;
15346}
15347
ff9959b0 15348static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15349 const char *group_name, bool uj)
d62a17ae 15350{
ff9959b0 15351 struct bgp *bgp;
d62a17ae 15352 struct listnode *node, *nnode;
15353 struct peer_group *group;
ff9959b0 15354 bool found = false;
6f4eacf3
DA
15355 json_object *json = NULL;
15356
15357 if (uj)
15358 json = json_object_new_object();
ff9959b0
QY
15359
15360 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15361
15362 if (!bgp) {
c48349e3 15363 if (uj)
75eeda93 15364 vty_json(vty, json);
c48349e3 15365 else
6f4eacf3 15366 vty_out(vty, "%% BGP instance not found\n");
6f4eacf3 15367
ff9959b0
QY
15368 return CMD_WARNING;
15369 }
d62a17ae 15370
15371 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15372 if (group_name) {
15373 if (strmatch(group->name, group_name)) {
6f4eacf3 15374 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15375 found = true;
15376 break;
d62a17ae 15377 }
ff9959b0 15378 } else {
6f4eacf3 15379 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15380 }
f14e6fdb 15381 }
f14e6fdb 15382
6f4eacf3 15383 if (group_name && !found && !uj)
d62a17ae 15384 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15385
c48349e3 15386 if (uj)
75eeda93 15387 vty_json(vty, json);
6f4eacf3 15388
d62a17ae 15389 return CMD_SUCCESS;
f14e6fdb
DS
15390}
15391
6f4eacf3
DA
15392DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15393 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15394 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15395 "Detailed information on BGP peer groups\n"
15396 "Peer group name\n" JSON_STR)
f14e6fdb 15397{
d62a17ae 15398 char *vrf, *pg;
d62a17ae 15399 int idx = 0;
6f4eacf3 15400 bool uj = use_json(argc, argv);
f14e6fdb 15401
a4d82a8a
PZ
15402 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15403 : NULL;
d62a17ae 15404 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15405
6f4eacf3 15406 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15407}
3f9c7369 15408
d6e3c605 15409
718e3744 15410/* Redistribute VTY commands. */
15411
585f1adc
IR
15412DEFUN (bgp_redistribute_ipv4,
15413 bgp_redistribute_ipv4_cmd,
15414 "redistribute " FRR_IP_REDIST_STR_BGPD,
15415 "Redistribute information from another routing protocol\n"
15416 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15417{
585f1adc 15418 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15419 int idx_protocol = 1;
585f1adc 15420 int type;
37a87b8f 15421
585f1adc
IR
15422 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15423 if (type < 0) {
15424 vty_out(vty, "%% Invalid route type\n");
15425 return CMD_WARNING_CONFIG_FAILED;
15426 }
7f323236 15427
585f1adc
IR
15428 bgp_redist_add(bgp, AFI_IP, type, 0);
15429 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 15430}
15431
d62a17ae 15432ALIAS_HIDDEN(
15433 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15434 "redistribute " FRR_IP_REDIST_STR_BGPD,
15435 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15436
585f1adc
IR
15437DEFUN (bgp_redistribute_ipv4_rmap,
15438 bgp_redistribute_ipv4_rmap_cmd,
15439 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15440 "Redistribute information from another routing protocol\n"
15441 FRR_IP_REDIST_HELP_STR_BGPD
15442 "Route map reference\n"
15443 "Pointer to route-map entries\n")
718e3744 15444{
585f1adc 15445 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15446 int idx_protocol = 1;
15447 int idx_word = 3;
585f1adc
IR
15448 int type;
15449 struct bgp_redist *red;
15450 bool changed;
15451 struct route_map *route_map = route_map_lookup_warn_noexist(
15452 vty, argv[idx_word]->arg);
15453
15454 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15455 if (type < 0) {
15456 vty_out(vty, "%% Invalid route type\n");
15457 return CMD_WARNING_CONFIG_FAILED;
15458 }
37a87b8f 15459
585f1adc
IR
15460 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15461 changed =
15462 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15463 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 15464}
15465
d62a17ae 15466ALIAS_HIDDEN(
15467 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15468 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15469 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15470 "Route map reference\n"
15471 "Pointer to route-map entries\n")
596c17ba 15472
585f1adc
IR
15473DEFUN (bgp_redistribute_ipv4_metric,
15474 bgp_redistribute_ipv4_metric_cmd,
15475 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15476 "Redistribute information from another routing protocol\n"
15477 FRR_IP_REDIST_HELP_STR_BGPD
15478 "Metric for redistributed routes\n"
15479 "Default metric\n")
718e3744 15480{
585f1adc 15481 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15482 int idx_protocol = 1;
15483 int idx_number = 3;
585f1adc
IR
15484 int type;
15485 uint32_t metric;
15486 struct bgp_redist *red;
15487 bool changed;
15488
15489 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15490 if (type < 0) {
15491 vty_out(vty, "%% Invalid route type\n");
15492 return CMD_WARNING_CONFIG_FAILED;
15493 }
15494 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15495
585f1adc
IR
15496 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15497 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15498 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15499}
15500
15501ALIAS_HIDDEN(
15502 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15503 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15504 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15505 "Metric for redistributed routes\n"
15506 "Default metric\n")
596c17ba 15507
585f1adc
IR
15508DEFUN (bgp_redistribute_ipv4_rmap_metric,
15509 bgp_redistribute_ipv4_rmap_metric_cmd,
15510 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15511 "Redistribute information from another routing protocol\n"
15512 FRR_IP_REDIST_HELP_STR_BGPD
15513 "Route map reference\n"
15514 "Pointer to route-map entries\n"
15515 "Metric for redistributed routes\n"
15516 "Default metric\n")
718e3744 15517{
585f1adc 15518 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15519 int idx_protocol = 1;
15520 int idx_word = 3;
15521 int idx_number = 5;
585f1adc
IR
15522 int type;
15523 uint32_t metric;
15524 struct bgp_redist *red;
15525 bool changed;
15526 struct route_map *route_map =
15527 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15528
15529 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15530 if (type < 0) {
15531 vty_out(vty, "%% Invalid route type\n");
15532 return CMD_WARNING_CONFIG_FAILED;
15533 }
15534 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15535
585f1adc
IR
15536 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15537 changed =
15538 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15539 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15540 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15541}
15542
15543ALIAS_HIDDEN(
15544 bgp_redistribute_ipv4_rmap_metric,
15545 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15546 "redistribute " FRR_IP_REDIST_STR_BGPD
15547 " route-map WORD metric (0-4294967295)",
15548 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15549 "Route map reference\n"
15550 "Pointer to route-map entries\n"
15551 "Metric for redistributed routes\n"
15552 "Default metric\n")
596c17ba 15553
585f1adc
IR
15554DEFUN (bgp_redistribute_ipv4_metric_rmap,
15555 bgp_redistribute_ipv4_metric_rmap_cmd,
15556 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
15557 "Redistribute information from another routing protocol\n"
15558 FRR_IP_REDIST_HELP_STR_BGPD
15559 "Metric for redistributed routes\n"
15560 "Default metric\n"
15561 "Route map reference\n"
15562 "Pointer to route-map entries\n")
718e3744 15563{
585f1adc 15564 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15565 int idx_protocol = 1;
37a87b8f 15566 int idx_number = 3;
585f1adc
IR
15567 int idx_word = 5;
15568 int type;
15569 uint32_t metric;
15570 struct bgp_redist *red;
15571 bool changed;
15572 struct route_map *route_map =
15573 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15574
15575 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15576 if (type < 0) {
15577 vty_out(vty, "%% Invalid route type\n");
15578 return CMD_WARNING_CONFIG_FAILED;
15579 }
15580 metric = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 15581
585f1adc
IR
15582 red = bgp_redist_add(bgp, AFI_IP, type, 0);
15583 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
15584 changed |=
15585 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15586 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 15587}
15588
15589ALIAS_HIDDEN(
15590 bgp_redistribute_ipv4_metric_rmap,
15591 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15592 "redistribute " FRR_IP_REDIST_STR_BGPD
15593 " metric (0-4294967295) route-map WORD",
15594 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15595 "Metric for redistributed routes\n"
15596 "Default metric\n"
15597 "Route map reference\n"
15598 "Pointer to route-map entries\n")
596c17ba 15599
585f1adc
IR
15600DEFUN (bgp_redistribute_ipv4_ospf,
15601 bgp_redistribute_ipv4_ospf_cmd,
15602 "redistribute <ospf|table> (1-65535)",
15603 "Redistribute information from another routing protocol\n"
15604 "Open Shortest Path First (OSPFv2)\n"
15605 "Non-main Kernel Routing Table\n"
15606 "Instance ID/Table ID\n")
7c8ff89e 15607{
585f1adc
IR
15608 VTY_DECLVAR_CONTEXT(bgp, bgp);
15609 int idx_ospf_table = 1;
d62a17ae 15610 int idx_number = 2;
585f1adc
IR
15611 unsigned short instance;
15612 unsigned short protocol;
7c8ff89e 15613
585f1adc 15614 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 15615
585f1adc
IR
15616 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15617 protocol = ZEBRA_ROUTE_OSPF;
15618 else
15619 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 15620
585f1adc
IR
15621 bgp_redist_add(bgp, AFI_IP, protocol, instance);
15622 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
15623}
15624
d62a17ae 15625ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15626 "redistribute <ospf|table> (1-65535)",
15627 "Redistribute information from another routing protocol\n"
15628 "Open Shortest Path First (OSPFv2)\n"
15629 "Non-main Kernel Routing Table\n"
15630 "Instance ID/Table ID\n")
596c17ba 15631
585f1adc
IR
15632DEFUN (bgp_redistribute_ipv4_ospf_rmap,
15633 bgp_redistribute_ipv4_ospf_rmap_cmd,
15634 "redistribute <ospf|table> (1-65535) route-map WORD",
15635 "Redistribute information from another routing protocol\n"
15636 "Open Shortest Path First (OSPFv2)\n"
15637 "Non-main Kernel Routing Table\n"
15638 "Instance ID/Table ID\n"
15639 "Route map reference\n"
15640 "Pointer to route-map entries\n")
7c8ff89e 15641{
585f1adc
IR
15642 VTY_DECLVAR_CONTEXT(bgp, bgp);
15643 int idx_ospf_table = 1;
d62a17ae 15644 int idx_number = 2;
15645 int idx_word = 4;
585f1adc
IR
15646 struct bgp_redist *red;
15647 unsigned short instance;
15648 int protocol;
15649 bool changed;
15650 struct route_map *route_map =
15651 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15652
15653 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15654 protocol = ZEBRA_ROUTE_OSPF;
15655 else
15656 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15657
585f1adc
IR
15658 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15659 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15660 changed =
15661 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15662 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15663}
15664
15665ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15666 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15667 "redistribute <ospf|table> (1-65535) route-map WORD",
15668 "Redistribute information from another routing protocol\n"
15669 "Open Shortest Path First (OSPFv2)\n"
15670 "Non-main Kernel Routing Table\n"
15671 "Instance ID/Table ID\n"
15672 "Route map reference\n"
15673 "Pointer to route-map entries\n")
596c17ba 15674
585f1adc
IR
15675DEFUN (bgp_redistribute_ipv4_ospf_metric,
15676 bgp_redistribute_ipv4_ospf_metric_cmd,
15677 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15678 "Redistribute information from another routing protocol\n"
15679 "Open Shortest Path First (OSPFv2)\n"
15680 "Non-main Kernel Routing Table\n"
15681 "Instance ID/Table ID\n"
15682 "Metric for redistributed routes\n"
15683 "Default metric\n")
7c8ff89e 15684{
585f1adc
IR
15685 VTY_DECLVAR_CONTEXT(bgp, bgp);
15686 int idx_ospf_table = 1;
d62a17ae 15687 int idx_number = 2;
15688 int idx_number_2 = 4;
585f1adc
IR
15689 uint32_t metric;
15690 struct bgp_redist *red;
15691 unsigned short instance;
15692 int protocol;
15693 bool changed;
15694
15695 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15696 protocol = ZEBRA_ROUTE_OSPF;
15697 else
15698 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15699
585f1adc
IR
15700 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15701 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15702
585f1adc
IR
15703 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15704 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15705 metric);
15706 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15707}
15708
15709ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15710 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15711 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15712 "Redistribute information from another routing protocol\n"
15713 "Open Shortest Path First (OSPFv2)\n"
15714 "Non-main Kernel Routing Table\n"
15715 "Instance ID/Table ID\n"
15716 "Metric for redistributed routes\n"
15717 "Default metric\n")
596c17ba 15718
585f1adc
IR
15719DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
15720 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15721 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15722 "Redistribute information from another routing protocol\n"
15723 "Open Shortest Path First (OSPFv2)\n"
15724 "Non-main Kernel Routing Table\n"
15725 "Instance ID/Table ID\n"
15726 "Route map reference\n"
15727 "Pointer to route-map entries\n"
15728 "Metric for redistributed routes\n"
15729 "Default metric\n")
7c8ff89e 15730{
585f1adc
IR
15731 VTY_DECLVAR_CONTEXT(bgp, bgp);
15732 int idx_ospf_table = 1;
d62a17ae 15733 int idx_number = 2;
15734 int idx_word = 4;
15735 int idx_number_2 = 6;
585f1adc
IR
15736 uint32_t metric;
15737 struct bgp_redist *red;
15738 unsigned short instance;
15739 int protocol;
15740 bool changed;
15741 struct route_map *route_map =
15742 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15743
15744 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15745 protocol = ZEBRA_ROUTE_OSPF;
15746 else
15747 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15748
585f1adc
IR
15749 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15750 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15751
585f1adc
IR
15752 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15753 changed =
15754 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15755 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15756 metric);
15757 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15758}
15759
15760ALIAS_HIDDEN(
15761 bgp_redistribute_ipv4_ospf_rmap_metric,
15762 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15763 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15764 "Redistribute information from another routing protocol\n"
15765 "Open Shortest Path First (OSPFv2)\n"
15766 "Non-main Kernel Routing Table\n"
15767 "Instance ID/Table ID\n"
15768 "Route map reference\n"
15769 "Pointer to route-map entries\n"
15770 "Metric for redistributed routes\n"
15771 "Default metric\n")
596c17ba 15772
585f1adc
IR
15773DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
15774 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15775 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15776 "Redistribute information from another routing protocol\n"
15777 "Open Shortest Path First (OSPFv2)\n"
15778 "Non-main Kernel Routing Table\n"
15779 "Instance ID/Table ID\n"
15780 "Metric for redistributed routes\n"
15781 "Default metric\n"
15782 "Route map reference\n"
15783 "Pointer to route-map entries\n")
7c8ff89e 15784{
585f1adc
IR
15785 VTY_DECLVAR_CONTEXT(bgp, bgp);
15786 int idx_ospf_table = 1;
d62a17ae 15787 int idx_number = 2;
15788 int idx_number_2 = 4;
15789 int idx_word = 6;
585f1adc
IR
15790 uint32_t metric;
15791 struct bgp_redist *red;
15792 unsigned short instance;
15793 int protocol;
15794 bool changed;
15795 struct route_map *route_map =
15796 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15797
15798 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15799 protocol = ZEBRA_ROUTE_OSPF;
15800 else
15801 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15802
585f1adc
IR
15803 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15804 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
d62a17ae 15805
585f1adc
IR
15806 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
15807 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
15808 metric);
15809 changed |=
15810 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15811 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 15812}
15813
15814ALIAS_HIDDEN(
15815 bgp_redistribute_ipv4_ospf_metric_rmap,
15816 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15817 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15818 "Redistribute information from another routing protocol\n"
15819 "Open Shortest Path First (OSPFv2)\n"
15820 "Non-main Kernel Routing Table\n"
15821 "Instance ID/Table ID\n"
15822 "Metric for redistributed routes\n"
15823 "Default metric\n"
15824 "Route map reference\n"
15825 "Pointer to route-map entries\n")
596c17ba 15826
585f1adc
IR
15827DEFUN (no_bgp_redistribute_ipv4_ospf,
15828 no_bgp_redistribute_ipv4_ospf_cmd,
15829 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15830 NO_STR
15831 "Redistribute information from another routing protocol\n"
15832 "Open Shortest Path First (OSPFv2)\n"
15833 "Non-main Kernel Routing Table\n"
15834 "Instance ID/Table ID\n"
15835 "Metric for redistributed routes\n"
15836 "Default metric\n"
15837 "Route map reference\n"
15838 "Pointer to route-map entries\n")
7c8ff89e 15839{
585f1adc
IR
15840 VTY_DECLVAR_CONTEXT(bgp, bgp);
15841 int idx_ospf_table = 2;
d62a17ae 15842 int idx_number = 3;
585f1adc
IR
15843 unsigned short instance;
15844 int protocol;
37a87b8f 15845
585f1adc
IR
15846 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
15847 protocol = ZEBRA_ROUTE_OSPF;
15848 else
15849 protocol = ZEBRA_ROUTE_TABLE;
d62a17ae 15850
585f1adc
IR
15851 instance = strtoul(argv[idx_number]->arg, NULL, 10);
15852 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
d62a17ae 15853}
15854
15855ALIAS_HIDDEN(
15856 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 15857 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15858 NO_STR
15859 "Redistribute information from another routing protocol\n"
15860 "Open Shortest Path First (OSPFv2)\n"
15861 "Non-main Kernel Routing Table\n"
15862 "Instance ID/Table ID\n"
15863 "Metric for redistributed routes\n"
15864 "Default metric\n"
15865 "Route map reference\n"
15866 "Pointer to route-map entries\n")
596c17ba 15867
585f1adc
IR
15868DEFUN (no_bgp_redistribute_ipv4,
15869 no_bgp_redistribute_ipv4_cmd,
15870 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15871 NO_STR
15872 "Redistribute information from another routing protocol\n"
15873 FRR_IP_REDIST_HELP_STR_BGPD
15874 "Metric for redistributed routes\n"
15875 "Default metric\n"
15876 "Route map reference\n"
15877 "Pointer to route-map entries\n")
718e3744 15878{
585f1adc 15879 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15880 int idx_protocol = 2;
585f1adc 15881 int type;
d62a17ae 15882
585f1adc
IR
15883 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
15884 if (type < 0) {
15885 vty_out(vty, "%% Invalid route type\n");
15886 return CMD_WARNING_CONFIG_FAILED;
15887 }
15888 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
d62a17ae 15889}
15890
15891ALIAS_HIDDEN(
15892 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15893 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 15894 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 15895 NO_STR
15896 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15897 "Metric for redistributed routes\n"
15898 "Default metric\n"
15899 "Route map reference\n"
15900 "Pointer to route-map entries\n")
596c17ba 15901
585f1adc
IR
15902DEFUN (bgp_redistribute_ipv6,
15903 bgp_redistribute_ipv6_cmd,
15904 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15905 "Redistribute information from another routing protocol\n"
15906 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 15907{
585f1adc 15908 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15909 int idx_protocol = 1;
585f1adc 15910 int type;
718e3744 15911
585f1adc
IR
15912 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15913 if (type < 0) {
15914 vty_out(vty, "%% Invalid route type\n");
15915 return CMD_WARNING_CONFIG_FAILED;
15916 }
718e3744 15917
585f1adc
IR
15918 bgp_redist_add(bgp, AFI_IP6, type, 0);
15919 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 15920}
15921
585f1adc
IR
15922DEFUN (bgp_redistribute_ipv6_rmap,
15923 bgp_redistribute_ipv6_rmap_cmd,
15924 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
15925 "Redistribute information from another routing protocol\n"
15926 FRR_IP6_REDIST_HELP_STR_BGPD
15927 "Route map reference\n"
15928 "Pointer to route-map entries\n")
718e3744 15929{
585f1adc 15930 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15931 int idx_protocol = 1;
15932 int idx_word = 3;
585f1adc
IR
15933 int type;
15934 struct bgp_redist *red;
15935 bool changed;
15936 struct route_map *route_map =
15937 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15938
15939 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15940 if (type < 0) {
15941 vty_out(vty, "%% Invalid route type\n");
15942 return CMD_WARNING_CONFIG_FAILED;
15943 }
37a87b8f 15944
585f1adc
IR
15945 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15946 changed =
15947 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
15948 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15949}
15950
585f1adc 15951DEFUN (bgp_redistribute_ipv6_metric,
718e3744 15952 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 15953 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 15954 "Redistribute information from another routing protocol\n"
ab0181ee 15955 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 15956 "Metric for redistributed routes\n"
15957 "Default metric\n")
15958{
585f1adc 15959 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15960 int idx_protocol = 1;
15961 int idx_number = 3;
585f1adc
IR
15962 int type;
15963 uint32_t metric;
15964 struct bgp_redist *red;
15965 bool changed;
15966
15967 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
15968 if (type < 0) {
15969 vty_out(vty, "%% Invalid route type\n");
15970 return CMD_WARNING_CONFIG_FAILED;
15971 }
15972 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 15973
585f1adc
IR
15974 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
15975 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
15976 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 15977}
15978
585f1adc
IR
15979DEFUN (bgp_redistribute_ipv6_rmap_metric,
15980 bgp_redistribute_ipv6_rmap_metric_cmd,
15981 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
15982 "Redistribute information from another routing protocol\n"
15983 FRR_IP6_REDIST_HELP_STR_BGPD
15984 "Route map reference\n"
15985 "Pointer to route-map entries\n"
15986 "Metric for redistributed routes\n"
15987 "Default metric\n")
718e3744 15988{
585f1adc 15989 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 15990 int idx_protocol = 1;
15991 int idx_word = 3;
15992 int idx_number = 5;
585f1adc
IR
15993 int type;
15994 uint32_t metric;
15995 struct bgp_redist *red;
15996 bool changed;
15997 struct route_map *route_map =
15998 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
15999
16000 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16001 if (type < 0) {
16002 vty_out(vty, "%% Invalid route type\n");
16003 return CMD_WARNING_CONFIG_FAILED;
16004 }
16005 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16006
585f1adc
IR
16007 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16008 changed =
16009 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16010 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
16011 metric);
16012 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16013}
16014
585f1adc
IR
16015DEFUN (bgp_redistribute_ipv6_metric_rmap,
16016 bgp_redistribute_ipv6_metric_rmap_cmd,
16017 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
16018 "Redistribute information from another routing protocol\n"
16019 FRR_IP6_REDIST_HELP_STR_BGPD
16020 "Metric for redistributed routes\n"
16021 "Default metric\n"
16022 "Route map reference\n"
16023 "Pointer to route-map entries\n")
718e3744 16024{
585f1adc 16025 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16026 int idx_protocol = 1;
37a87b8f 16027 int idx_number = 3;
585f1adc
IR
16028 int idx_word = 5;
16029 int type;
16030 uint32_t metric;
16031 struct bgp_redist *red;
16032 bool changed;
16033 struct route_map *route_map =
16034 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
16035
16036 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16037 if (type < 0) {
16038 vty_out(vty, "%% Invalid route type\n");
16039 return CMD_WARNING_CONFIG_FAILED;
16040 }
16041 metric = strtoul(argv[idx_number]->arg, NULL, 10);
37a87b8f 16042
585f1adc
IR
16043 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
16044 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
16045 metric);
16046 changed |=
16047 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
16048 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 16049}
16050
585f1adc
IR
16051DEFUN (no_bgp_redistribute_ipv6,
16052 no_bgp_redistribute_ipv6_cmd,
16053 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16054 NO_STR
16055 "Redistribute information from another routing protocol\n"
16056 FRR_IP6_REDIST_HELP_STR_BGPD
16057 "Metric for redistributed routes\n"
16058 "Default metric\n"
16059 "Route map reference\n"
16060 "Pointer to route-map entries\n")
718e3744 16061{
585f1adc 16062 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 16063 int idx_protocol = 2;
585f1adc 16064 int type;
37a87b8f 16065
585f1adc
IR
16066 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
16067 if (type < 0) {
16068 vty_out(vty, "%% Invalid route type\n");
16069 return CMD_WARNING_CONFIG_FAILED;
16070 }
718e3744 16071
585f1adc 16072 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
d62a17ae 16073}
16074
4ab46701
AR
16075/* Neighbor update tcp-mss. */
16076static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16077 const char *tcp_mss_str)
16078{
16079 struct peer *peer;
16080 uint32_t tcp_mss_val = 0;
16081
16082 peer = peer_and_group_lookup_vty(vty, peer_str);
16083 if (!peer)
16084 return CMD_WARNING_CONFIG_FAILED;
16085
16086 if (tcp_mss_str) {
16087 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16088 peer_tcp_mss_set(peer, tcp_mss_val);
16089 } else {
16090 peer_tcp_mss_unset(peer);
16091 }
16092
16093 return CMD_SUCCESS;
16094}
16095
16096DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16097 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16098 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16099 "TCP max segment size\n"
16100 "TCP MSS value\n")
16101{
16102 int peer_index = 1;
16103 int mss_index = 3;
16104
16105 vty_out(vty,
16106 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16107 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16108 argv[mss_index]->arg);
16109}
16110
16111DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16112 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16113 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16114 "TCP max segment size\n"
16115 "TCP MSS value\n")
16116{
16117 int peer_index = 2;
16118
16119 vty_out(vty,
16120 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16121 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16122}
16123
dd65f45e
DL
16124static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16125 afi_t afi, safi_t safi)
d62a17ae 16126{
16127 int i;
16128
16129 /* Unicast redistribution only. */
16130 if (safi != SAFI_UNICAST)
2b791107 16131 return;
d62a17ae 16132
16133 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16134 /* Redistribute BGP does not make sense. */
16135 if (i != ZEBRA_ROUTE_BGP) {
16136 struct list *red_list;
16137 struct listnode *node;
16138 struct bgp_redist *red;
16139
16140 red_list = bgp->redist[afi][i];
16141 if (!red_list)
16142 continue;
16143
16144 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16145 /* "redistribute" configuration. */
16146 vty_out(vty, " redistribute %s",
16147 zebra_route_string(i));
16148 if (red->instance)
16149 vty_out(vty, " %d", red->instance);
16150 if (red->redist_metric_flag)
16151 vty_out(vty, " metric %u",
16152 red->redist_metric);
16153 if (red->rmap.name)
16154 vty_out(vty, " route-map %s",
16155 red->rmap.name);
16156 vty_out(vty, "\n");
16157 }
16158 }
16159 }
718e3744 16160}
6b0655a2 16161
dd65f45e
DL
16162/* peer-group helpers for config-write */
16163
16164static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16165{
16166 if (!peer_group_active(peer)) {
16167 if (CHECK_FLAG(peer->flags_invert, flag))
16168 return !CHECK_FLAG(peer->flags, flag);
16169 else
16170 return !!CHECK_FLAG(peer->flags, flag);
16171 }
16172
16173 return !!CHECK_FLAG(peer->flags_override, flag);
16174}
16175
16176static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16177 uint32_t flag)
16178{
16179 if (!peer_group_active(peer)) {
16180 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16181 return !peer_af_flag_check(peer, afi, safi, flag);
16182 else
16183 return !!peer_af_flag_check(peer, afi, safi, flag);
16184 }
16185
16186 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16187}
16188
16189static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16190 uint8_t type, int direct)
16191{
16192 struct bgp_filter *filter;
16193
16194 if (peer_group_active(peer))
16195 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16196 type);
16197
16198 filter = &peer->filter[afi][safi];
16199 switch (type) {
16200 case PEER_FT_DISTRIBUTE_LIST:
16201 return !!(filter->dlist[direct].name);
16202 case PEER_FT_FILTER_LIST:
16203 return !!(filter->aslist[direct].name);
16204 case PEER_FT_PREFIX_LIST:
16205 return !!(filter->plist[direct].name);
16206 case PEER_FT_ROUTE_MAP:
16207 return !!(filter->map[direct].name);
16208 case PEER_FT_UNSUPPRESS_MAP:
16209 return !!(filter->usmap.name);
7f7940e6
MK
16210 case PEER_FT_ADVERTISE_MAP:
16211 return !!(filter->advmap.aname
16212 && ((filter->advmap.condition == direct)
16213 && filter->advmap.cname));
dd65f45e
DL
16214 default:
16215 return false;
16216 }
16217}
16218
16219/* Return true if the addpath type is set for peer and different from
16220 * peer-group.
16221 */
3dc339cd
DA
16222static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16223 safi_t safi)
dd65f45e
DL
16224{
16225 enum bgp_addpath_strat type, g_type;
16226
16227 type = peer->addpath_type[afi][safi];
16228
16229 if (type != BGP_ADDPATH_NONE) {
16230 if (peer_group_active(peer)) {
16231 g_type = peer->group->conf->addpath_type[afi][safi];
16232
16233 if (type != g_type)
3dc339cd 16234 return true;
dd65f45e 16235 else
3dc339cd 16236 return false;
dd65f45e
DL
16237 }
16238
3dc339cd 16239 return true;
dd65f45e
DL
16240 }
16241
3dc339cd 16242 return false;
dd65f45e
DL
16243}
16244
b9c7bc5a 16245/* This is part of the address-family block (unicast only) */
dd65f45e 16246static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16247 afi_t afi)
16248{
b9c7bc5a 16249 int indent = 2;
53970de3 16250 uint32_t tovpn_sid_index = 0;
ddb5b488 16251
8a066a70 16252 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16253 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16254 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16255 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16256 bgp->vpn_policy[afi]
bb4f6190 16257 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16258 else
16259 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16260 bgp->vpn_policy[afi]
16261 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16262 }
12a844a5
DS
16263 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16264 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16265 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16266 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16267 return;
16268
e70e9f8e
PZ
16269 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16270 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16271
16272 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16273
16274 } else {
16275 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16276 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16277 bgp->vpn_policy[afi].tovpn_label);
16278 }
ddb5b488 16279 }
53970de3
RS
16280
16281 tovpn_sid_index = bgp->vpn_policy[afi].tovpn_sid_index;
16282 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16283 BGP_VPN_POLICY_TOVPN_SID_AUTO)) {
16284 vty_out(vty, "%*ssid vpn export %s\n", indent, "", "auto");
16285 } else if (tovpn_sid_index != 0) {
16286 vty_out(vty, "%*ssid vpn export %d\n", indent, "",
16287 tovpn_sid_index);
16288 }
16289
ddb5b488
PZ
16290 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16291 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16292 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16293 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16294 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16295 sizeof(buf)));
16296 }
16297 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16298 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16299
16300 char buf[PREFIX_STRLEN];
16301 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16302 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16303 sizeof(buf))) {
16304
b9c7bc5a
PZ
16305 vty_out(vty, "%*snexthop vpn export %s\n",
16306 indent, "", buf);
ddb5b488
PZ
16307 }
16308 }
16309 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16310 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16311 && ecommunity_cmp(
16312 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16313 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16314
16315 char *b = ecommunity_ecom2str(
16316 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16317 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16318 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16319 XFREE(MTYPE_ECOMMUNITY_STR, b);
16320 } else {
16321 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16322 char *b = ecommunity_ecom2str(
16323 bgp->vpn_policy[afi]
16324 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16325 ECOMMUNITY_FORMAT_ROUTE_MAP,
16326 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16327 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16328 XFREE(MTYPE_ECOMMUNITY_STR, b);
16329 }
16330 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16331 char *b = ecommunity_ecom2str(
16332 bgp->vpn_policy[afi]
16333 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16334 ECOMMUNITY_FORMAT_ROUTE_MAP,
16335 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16336 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16337 XFREE(MTYPE_ECOMMUNITY_STR, b);
16338 }
16339 }
bb4f6190
DS
16340
16341 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16342 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16343 bgp->vpn_policy[afi]
16344 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16345
301ad80a
PG
16346 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16347 char *b = ecommunity_ecom2str(
16348 bgp->vpn_policy[afi]
16349 .import_redirect_rtlist,
16350 ECOMMUNITY_FORMAT_ROUTE_MAP,
16351 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16352
9a659715
PG
16353 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16354 != ECOMMUNITY_SIZE)
c6423c31 16355 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16356 indent, "", b);
16357 else
16358 vty_out(vty, "%*srt redirect import %s\n",
16359 indent, "", b);
301ad80a
PG
16360 XFREE(MTYPE_ECOMMUNITY_STR, b);
16361 }
ddb5b488
PZ
16362}
16363
dd65f45e
DL
16364static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16365 afi_t afi, safi_t safi)
16366{
16367 struct bgp_filter *filter;
16368 char *addr;
16369
16370 addr = peer->host;
16371 filter = &peer->filter[afi][safi];
16372
16373 /* distribute-list. */
16374 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16375 FILTER_IN))
16376 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16377 filter->dlist[FILTER_IN].name);
16378
16379 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16380 FILTER_OUT))
16381 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16382 filter->dlist[FILTER_OUT].name);
16383
16384 /* prefix-list. */
16385 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16386 FILTER_IN))
16387 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16388 filter->plist[FILTER_IN].name);
16389
16390 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16391 FILTER_OUT))
16392 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16393 filter->plist[FILTER_OUT].name);
16394
16395 /* route-map. */
16396 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16397 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16398 filter->map[RMAP_IN].name);
16399
16400 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16401 RMAP_OUT))
16402 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16403 filter->map[RMAP_OUT].name);
16404
16405 /* unsuppress-map */
16406 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16407 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16408 filter->usmap.name);
16409
7f7940e6
MK
16410 /* advertise-map : always applied in OUT direction*/
16411 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16412 CONDITION_NON_EXIST))
16413 vty_out(vty,
16414 " neighbor %s advertise-map %s non-exist-map %s\n",
16415 addr, filter->advmap.aname, filter->advmap.cname);
16416
16417 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16418 CONDITION_EXIST))
16419 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16420 addr, filter->advmap.aname, filter->advmap.cname);
16421
dd65f45e
DL
16422 /* filter-list. */
16423 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16424 FILTER_IN))
16425 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16426 filter->aslist[FILTER_IN].name);
16427
16428 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16429 FILTER_OUT))
16430 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16431 filter->aslist[FILTER_OUT].name);
16432}
16433
16434/* BGP peer configuration display function. */
16435static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16436 struct peer *peer)
16437{
16438 struct peer *g_peer = NULL;
16439 char buf[SU_ADDRSTRLEN];
16440 char *addr;
16441 int if_pg_printed = false;
16442 int if_ras_printed = false;
16443
16444 /* Skip dynamic neighbors. */
16445 if (peer_dynamic_neighbor(peer))
16446 return;
16447
16448 if (peer->conf_if)
16449 addr = peer->conf_if;
16450 else
16451 addr = peer->host;
16452
16453 /************************************
16454 ****** Global to the neighbor ******
16455 ************************************/
16456 if (peer->conf_if) {
16457 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16458 vty_out(vty, " neighbor %s interface v6only", addr);
16459 else
16460 vty_out(vty, " neighbor %s interface", addr);
16461
16462 if (peer_group_active(peer)) {
16463 vty_out(vty, " peer-group %s", peer->group->name);
16464 if_pg_printed = true;
16465 } else if (peer->as_type == AS_SPECIFIED) {
16466 vty_out(vty, " remote-as %u", peer->as);
16467 if_ras_printed = true;
16468 } else if (peer->as_type == AS_INTERNAL) {
16469 vty_out(vty, " remote-as internal");
16470 if_ras_printed = true;
16471 } else if (peer->as_type == AS_EXTERNAL) {
16472 vty_out(vty, " remote-as external");
16473 if_ras_printed = true;
16474 }
16475
16476 vty_out(vty, "\n");
16477 }
16478
16479 /* remote-as and peer-group */
16480 /* peer is a member of a peer-group */
16481 if (peer_group_active(peer)) {
16482 g_peer = peer->group->conf;
16483
16484 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16485 if (peer->as_type == AS_SPECIFIED) {
16486 vty_out(vty, " neighbor %s remote-as %u\n",
16487 addr, peer->as);
16488 } else if (peer->as_type == AS_INTERNAL) {
16489 vty_out(vty,
16490 " neighbor %s remote-as internal\n",
16491 addr);
16492 } else if (peer->as_type == AS_EXTERNAL) {
16493 vty_out(vty,
16494 " neighbor %s remote-as external\n",
16495 addr);
16496 }
16497 }
16498
16499 /* For swpX peers we displayed the peer-group
16500 * via 'neighbor swpX interface peer-group PGNAME' */
16501 if (!if_pg_printed)
16502 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16503 peer->group->name);
16504 }
16505
16506 /* peer is NOT a member of a peer-group */
16507 else {
16508 /* peer is a peer-group, declare the peer-group */
16509 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16510 vty_out(vty, " neighbor %s peer-group\n", addr);
16511 }
16512
16513 if (!if_ras_printed) {
16514 if (peer->as_type == AS_SPECIFIED) {
16515 vty_out(vty, " neighbor %s remote-as %u\n",
16516 addr, peer->as);
16517 } else if (peer->as_type == AS_INTERNAL) {
16518 vty_out(vty,
16519 " neighbor %s remote-as internal\n",
16520 addr);
16521 } else if (peer->as_type == AS_EXTERNAL) {
16522 vty_out(vty,
16523 " neighbor %s remote-as external\n",
16524 addr);
16525 }
16526 }
16527 }
16528
16529 /* local-as */
16530 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16531 vty_out(vty, " neighbor %s local-as %u", addr,
16532 peer->change_local_as);
16533 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16534 vty_out(vty, " no-prepend");
16535 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16536 vty_out(vty, " replace-as");
16537 vty_out(vty, "\n");
16538 }
16539
16540 /* description */
16541 if (peer->desc) {
16542 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16543 }
16544
16545 /* shutdown */
16546 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16547 if (peer->tx_shutdown_message)
16548 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16549 peer->tx_shutdown_message);
16550 else
16551 vty_out(vty, " neighbor %s shutdown\n", addr);
16552 }
16553
8336c896
DA
16554 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16555 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16556 peer->rtt_expected, peer->rtt_keepalive_conf);
16557
dd65f45e 16558 /* bfd */
21bfce98
RZ
16559 if (peer->bfd_config)
16560 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
16561
16562 /* password */
16563 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16564 vty_out(vty, " neighbor %s password %s\n", addr,
16565 peer->password);
16566
16567 /* neighbor solo */
16568 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16569 if (!peer_group_active(peer)) {
16570 vty_out(vty, " neighbor %s solo\n", addr);
16571 }
16572 }
16573
16574 /* BGP port */
16575 if (peer->port != BGP_PORT_DEFAULT) {
16576 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16577 }
16578
16579 /* Local interface name */
16580 if (peer->ifname) {
16581 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16582 }
16583
4ab46701
AR
16584 /* TCP max segment size */
16585 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
16586 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
16587
dd65f45e
DL
16588 /* passive */
16589 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16590 vty_out(vty, " neighbor %s passive\n", addr);
16591
16592 /* ebgp-multihop */
16593 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
16594 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16595 && peer->ttl == MAXTTL)) {
dd65f45e
DL
16596 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16597 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16598 peer->ttl);
16599 }
16600 }
16601
16602 /* ttl-security hops */
e2521429 16603 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
16604 if (!peer_group_active(peer)
16605 || g_peer->gtsm_hops != peer->gtsm_hops) {
16606 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16607 addr, peer->gtsm_hops);
16608 }
16609 }
16610
16611 /* disable-connected-check */
16612 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16613 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16614
27aa23a4
DA
16615 /* link-bw-encoding-ieee */
16616 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE))
16617 vty_out(vty, " neighbor %s disable-link-bw-encoding-ieee\n",
16618 addr);
16619
d08c0c80
DA
16620 /* extended-optional-parameters */
16621 if (peergroup_flag_check(peer, PEER_FLAG_EXTENDED_OPT_PARAMS))
16622 vty_out(vty, " neighbor %s extended-optional-parameters\n",
16623 addr);
16624
dd65f45e
DL
16625 /* enforce-first-as */
16626 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16627 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16628
16629 /* update-source */
16630 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16631 if (peer->update_source)
16632 vty_out(vty, " neighbor %s update-source %s\n", addr,
16633 sockunion2str(peer->update_source, buf,
16634 SU_ADDRSTRLEN));
16635 else if (peer->update_if)
16636 vty_out(vty, " neighbor %s update-source %s\n", addr,
16637 peer->update_if);
16638 }
16639
16640 /* advertisement-interval */
16641 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16642 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16643 peer->routeadv);
16644
16645 /* timers */
16646 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16647 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16648 peer->keepalive, peer->holdtime);
16649
16650 /* timers connect */
16651 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16652 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16653 peer->connect);
5d5393b9
DL
16654 /* need special-case handling for changed default values due to
16655 * config profile / version (because there is no "timers bgp connect"
16656 * command, we need to save this per-peer :/)
16657 */
16658 else if (!peer_group_active(peer) && !peer->connect &&
16659 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16660 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16661 peer->bgp->default_connect_retry);
dd65f45e 16662
d43114f3
DS
16663 /* timers delayopen */
16664 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16665 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16666 peer->delayopen);
16667 /* Save config even though flag is not set if default values have been
16668 * changed
16669 */
16670 else if (!peer_group_active(peer) && !peer->delayopen
16671 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16672 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16673 peer->bgp->default_delayopen);
16674
dd65f45e
DL
16675 /* capability dynamic */
16676 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16677 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16678
16679 /* capability extended-nexthop */
16680 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
8e89adc1
DS
16681 if (CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE) &&
16682 !peer->conf_if)
843770f6
DA
16683 vty_out(vty,
16684 " no neighbor %s capability extended-nexthop\n",
16685 addr);
16686 else if (!peer->conf_if)
16687 vty_out(vty,
16688 " neighbor %s capability extended-nexthop\n",
16689 addr);
dd65f45e
DL
16690 }
16691
16692 /* dont-capability-negotiation */
16693 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16694 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16695
16696 /* override-capability */
16697 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16698 vty_out(vty, " neighbor %s override-capability\n", addr);
16699
16700 /* strict-capability-match */
16701 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16702 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16703
16704 /* Sender side AS path loop detection. */
16705 if (peer->as_path_loop_detection)
16706 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16707 addr);
cfd47646 16708
16709 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16710 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 16711
16712 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 16713 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 16714 vty_out(vty,
16715 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
16716 } else if (CHECK_FLAG(
16717 peer->peer_gr_new_status_flag,
16718 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 16719 vty_out(vty,
16720 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
16721 } else if (
16722 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16723 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16724 && !(CHECK_FLAG(
16725 peer->peer_gr_new_status_flag,
16726 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16727 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16728 addr);
cfd47646 16729 }
16730 }
dd65f45e
DL
16731}
16732
16733/* BGP peer configuration display function. */
16734static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16735 struct peer *peer, afi_t afi, safi_t safi)
16736{
16737 struct peer *g_peer = NULL;
16738 char *addr;
16739 bool flag_scomm, flag_secomm, flag_slcomm;
16740
16741 /* Skip dynamic neighbors. */
16742 if (peer_dynamic_neighbor(peer))
16743 return;
16744
16745 if (peer->conf_if)
16746 addr = peer->conf_if;
16747 else
16748 addr = peer->host;
16749
16750 /************************************
16751 ****** Per AF to the neighbor ******
16752 ************************************/
16753 if (peer_group_active(peer)) {
16754 g_peer = peer->group->conf;
16755
16756 /* If the peer-group is active but peer is not, print a 'no
16757 * activate' */
16758 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16759 vty_out(vty, " no neighbor %s activate\n", addr);
16760 }
16761
16762 /* If the peer-group is not active but peer is, print an
16763 'activate' */
16764 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16765 vty_out(vty, " neighbor %s activate\n", addr);
16766 }
16767 } else {
16768 if (peer->afc[afi][safi]) {
38d11af5
TA
16769 if (safi == SAFI_ENCAP)
16770 vty_out(vty, " neighbor %s activate\n", addr);
16771 else if (!bgp->default_af[afi][safi])
dd65f45e
DL
16772 vty_out(vty, " neighbor %s activate\n", addr);
16773 } else {
38d11af5
TA
16774 if (bgp->default_af[afi][safi])
16775 vty_out(vty, " no neighbor %s activate\n",
16776 addr);
dd65f45e
DL
16777 }
16778 }
16779
16780 /* addpath TX knobs */
16781 if (peergroup_af_addpath_check(peer, afi, safi)) {
16782 switch (peer->addpath_type[afi][safi]) {
16783 case BGP_ADDPATH_ALL:
16784 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16785 addr);
16786 break;
16787 case BGP_ADDPATH_BEST_PER_AS:
16788 vty_out(vty,
16789 " neighbor %s addpath-tx-bestpath-per-AS\n",
16790 addr);
16791 break;
16792 case BGP_ADDPATH_MAX:
16793 case BGP_ADDPATH_NONE:
16794 break;
16795 }
16796 }
16797
7c0e4312
DA
16798 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DISABLE_ADDPATH_RX))
16799 vty_out(vty, " neighbor %s disable-addpath-rx\n", addr);
16800
dd65f45e
DL
16801 /* ORF capability. */
16802 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16803 || peergroup_af_flag_check(peer, afi, safi,
16804 PEER_FLAG_ORF_PREFIX_RM)) {
16805 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16806
16807 if (peergroup_af_flag_check(peer, afi, safi,
16808 PEER_FLAG_ORF_PREFIX_SM)
16809 && peergroup_af_flag_check(peer, afi, safi,
16810 PEER_FLAG_ORF_PREFIX_RM))
16811 vty_out(vty, " both");
16812 else if (peergroup_af_flag_check(peer, afi, safi,
16813 PEER_FLAG_ORF_PREFIX_SM))
16814 vty_out(vty, " send");
16815 else
16816 vty_out(vty, " receive");
16817 vty_out(vty, "\n");
16818 }
16819
dd65f45e
DL
16820 /* Route reflector client. */
16821 if (peergroup_af_flag_check(peer, afi, safi,
16822 PEER_FLAG_REFLECTOR_CLIENT)) {
16823 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16824 }
16825
16826 /* next-hop-self force */
16827 if (peergroup_af_flag_check(peer, afi, safi,
16828 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16829 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16830 }
16831
16832 /* next-hop-self */
16833 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16834 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16835 }
16836
16837 /* remove-private-AS */
16838 if (peergroup_af_flag_check(peer, afi, safi,
16839 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16840 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16841 addr);
16842 }
16843
16844 else if (peergroup_af_flag_check(peer, afi, safi,
16845 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16846 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16847 addr);
16848 }
16849
16850 else if (peergroup_af_flag_check(peer, afi, safi,
16851 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16852 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16853 }
16854
16855 else if (peergroup_af_flag_check(peer, afi, safi,
16856 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16857 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16858 }
16859
16860 /* as-override */
16861 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16862 vty_out(vty, " neighbor %s as-override\n", addr);
16863 }
16864
16865 /* send-community print. */
16866 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16867 PEER_FLAG_SEND_COMMUNITY);
16868 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16869 PEER_FLAG_SEND_EXT_COMMUNITY);
16870 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16871 PEER_FLAG_SEND_LARGE_COMMUNITY);
16872
16873 if (flag_scomm && flag_secomm && flag_slcomm) {
16874 vty_out(vty, " no neighbor %s send-community all\n", addr);
16875 } else {
16876 if (flag_scomm)
16877 vty_out(vty, " no neighbor %s send-community\n", addr);
16878 if (flag_secomm)
16879 vty_out(vty,
16880 " no neighbor %s send-community extended\n",
16881 addr);
16882
16883 if (flag_slcomm)
16884 vty_out(vty, " no neighbor %s send-community large\n",
16885 addr);
16886 }
16887
16888 /* Default information */
16889 if (peergroup_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_DEFAULT_ORIGINATE)) {
16891 vty_out(vty, " neighbor %s default-originate", addr);
16892
16893 if (peer->default_rmap[afi][safi].name)
16894 vty_out(vty, " route-map %s",
16895 peer->default_rmap[afi][safi].name);
16896
16897 vty_out(vty, "\n");
16898 }
16899
16900 /* Soft reconfiguration inbound. */
16901 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16902 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16903 addr);
16904 }
16905
16906 /* maximum-prefix. */
16907 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 16908 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
16909 peer->pmax[afi][safi]);
16910
16911 if (peer->pmax_threshold[afi][safi]
16912 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16913 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16914 if (peer_af_flag_check(peer, afi, safi,
16915 PEER_FLAG_MAX_PREFIX_WARNING))
16916 vty_out(vty, " warning-only");
16917 if (peer->pmax_restart[afi][safi])
16918 vty_out(vty, " restart %u",
16919 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
16920 if (peer_af_flag_check(peer, afi, safi,
16921 PEER_FLAG_MAX_PREFIX_FORCE))
16922 vty_out(vty, " force");
dd65f45e
DL
16923
16924 vty_out(vty, "\n");
16925 }
16926
fde246e8
DA
16927 /* maximum-prefix-out */
16928 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 16929 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
16930 addr, peer->pmax_out[afi][safi]);
16931
dd65f45e
DL
16932 /* Route server client. */
16933 if (peergroup_af_flag_check(peer, afi, safi,
16934 PEER_FLAG_RSERVER_CLIENT)) {
16935 vty_out(vty, " neighbor %s route-server-client\n", addr);
16936 }
16937
16938 /* Nexthop-local unchanged. */
16939 if (peergroup_af_flag_check(peer, afi, safi,
16940 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16941 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16942 }
16943
16944 /* allowas-in <1-10> */
16945 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16946 if (peer_af_flag_check(peer, afi, safi,
16947 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16948 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16949 } else if (peer->allowas_in[afi][safi] == 3) {
16950 vty_out(vty, " neighbor %s allowas-in\n", addr);
16951 } else {
16952 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16953 peer->allowas_in[afi][safi]);
16954 }
16955 }
16956
16957 /* weight */
16958 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16959 vty_out(vty, " neighbor %s weight %lu\n", addr,
16960 peer->weight[afi][safi]);
16961
16962 /* Filter. */
16963 bgp_config_write_filter(vty, peer, afi, safi);
16964
16965 /* atribute-unchanged. */
16966 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16967 || (safi != SAFI_EVPN
16968 && peer_af_flag_check(peer, afi, safi,
16969 PEER_FLAG_NEXTHOP_UNCHANGED))
16970 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16971
16972 if (!peer_group_active(peer)
16973 || peergroup_af_flag_check(peer, afi, safi,
16974 PEER_FLAG_AS_PATH_UNCHANGED)
16975 || peergroup_af_flag_check(peer, afi, safi,
16976 PEER_FLAG_NEXTHOP_UNCHANGED)
16977 || peergroup_af_flag_check(peer, afi, safi,
16978 PEER_FLAG_MED_UNCHANGED)) {
16979
16980 vty_out(vty,
16981 " neighbor %s attribute-unchanged%s%s%s\n",
16982 addr,
16983 peer_af_flag_check(peer, afi, safi,
16984 PEER_FLAG_AS_PATH_UNCHANGED)
16985 ? " as-path"
16986 : "",
16987 peer_af_flag_check(peer, afi, safi,
16988 PEER_FLAG_NEXTHOP_UNCHANGED)
16989 ? " next-hop"
16990 : "",
16991 peer_af_flag_check(peer, afi, safi,
16992 PEER_FLAG_MED_UNCHANGED)
16993 ? " med"
16994 : "");
16995 }
16996 }
16997}
16998
16999/* Address family based peer configuration display. */
17000static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17001 safi_t safi)
17002{
17003 struct peer *peer;
17004 struct peer_group *group;
17005 struct listnode *node, *nnode;
17006
17007
17008 vty_frame(vty, " !\n address-family ");
17009 if (afi == AFI_IP) {
17010 if (safi == SAFI_UNICAST)
17011 vty_frame(vty, "ipv4 unicast");
17012 else if (safi == SAFI_LABELED_UNICAST)
17013 vty_frame(vty, "ipv4 labeled-unicast");
17014 else if (safi == SAFI_MULTICAST)
17015 vty_frame(vty, "ipv4 multicast");
17016 else if (safi == SAFI_MPLS_VPN)
17017 vty_frame(vty, "ipv4 vpn");
17018 else if (safi == SAFI_ENCAP)
17019 vty_frame(vty, "ipv4 encap");
17020 else if (safi == SAFI_FLOWSPEC)
17021 vty_frame(vty, "ipv4 flowspec");
17022 } else if (afi == AFI_IP6) {
17023 if (safi == SAFI_UNICAST)
17024 vty_frame(vty, "ipv6 unicast");
17025 else if (safi == SAFI_LABELED_UNICAST)
17026 vty_frame(vty, "ipv6 labeled-unicast");
17027 else if (safi == SAFI_MULTICAST)
17028 vty_frame(vty, "ipv6 multicast");
17029 else if (safi == SAFI_MPLS_VPN)
17030 vty_frame(vty, "ipv6 vpn");
17031 else if (safi == SAFI_ENCAP)
17032 vty_frame(vty, "ipv6 encap");
17033 else if (safi == SAFI_FLOWSPEC)
17034 vty_frame(vty, "ipv6 flowspec");
17035 } else if (afi == AFI_L2VPN) {
17036 if (safi == SAFI_EVPN)
17037 vty_frame(vty, "l2vpn evpn");
17038 }
17039 vty_frame(vty, "\n");
17040
17041 bgp_config_write_distance(vty, bgp, afi, safi);
17042
17043 bgp_config_write_network(vty, bgp, afi, safi);
17044
17045 bgp_config_write_redistribute(vty, bgp, afi, safi);
17046
8a4e7fe6
DA
17047 /* BGP flag dampening. */
17048 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6c75f4b3 17049 bgp_config_write_damp(vty, afi, safi);
8a4e7fe6 17050
dd65f45e
DL
17051 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17052 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17053
17054 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17055 /* Do not display doppelganger peers */
17056 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17057 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17058 }
17059
17060 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17061 bgp_config_write_table_map(vty, bgp, afi, safi);
17062
17063 if (safi == SAFI_EVPN)
17064 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17065
17066 if (safi == SAFI_FLOWSPEC)
17067 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17068
17069 if (safi == SAFI_UNICAST) {
17070 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17071 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17072 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17073
17074 vty_out(vty, " export vpn\n");
17075 }
17076 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17077 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17078
17079 vty_out(vty, " import vpn\n");
17080 }
17081 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17082 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17083 char *name;
17084
17085 for (ALL_LIST_ELEMENTS_RO(
17086 bgp->vpn_policy[afi].import_vrf, node,
17087 name))
17088 vty_out(vty, " import vrf %s\n", name);
17089 }
17090 }
17091
17092 vty_endframe(vty, " exit-address-family\n");
17093}
17094
17095int bgp_config_write(struct vty *vty)
17096{
17097 struct bgp *bgp;
17098 struct peer_group *group;
17099 struct peer *peer;
17100 struct listnode *node, *nnode;
17101 struct listnode *mnode, *mnnode;
b16bcbba
TA
17102 afi_t afi;
17103 safi_t safi;
dd65f45e
DL
17104
17105 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17106 vty_out(vty, "bgp route-map delay-timer %u\n",
17107 bm->rmap_update_timer);
17108
d70583f7
D
17109 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17110 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17111 if (bm->v_update_delay != bm->v_establish_wait)
17112 vty_out(vty, " %d", bm->v_establish_wait);
17113 vty_out(vty, "\n");
17114 }
17115
9acb67cb
DS
17116 if (bm->wait_for_fib)
17117 vty_out(vty, "bgp suppress-fib-pending\n");
17118
05bd726c 17119 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17120 vty_out(vty, "bgp graceful-shutdown\n");
17121
c163f297
DS
17122 /* No-RIB (Zebra) option flag configuration */
17123 if (bgp_option_check(BGP_OPT_NO_FIB))
17124 vty_out(vty, "bgp no-rib\n");
17125
870791a3
IR
17126 if (CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17127 vty_out(vty, "bgp send-extra-data zebra\n");
e46723a5 17128
dd65f45e
DL
17129 /* BGP configuration. */
17130 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17131
17132 /* skip all auto created vrf as they dont have user config */
17133 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17134 continue;
17135
17136 /* Router bgp ASN */
17137 vty_out(vty, "router bgp %u", bgp->as);
17138
17139 if (bgp->name)
17140 vty_out(vty, " %s %s",
17141 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17142 ? "view" : "vrf", bgp->name);
17143 vty_out(vty, "\n");
17144
17145 /* BGP fast-external-failover. */
17146 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17147 vty_out(vty, " no bgp fast-external-failover\n");
17148
17149 /* BGP router ID. */
3a6290bd 17150 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17151 vty_out(vty, " bgp router-id %pI4\n",
17152 &bgp->router_id_static);
dd65f45e 17153
c208c586
S
17154 /* Suppress fib pending */
17155 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17156 vty_out(vty, " bgp suppress-fib-pending\n");
17157
dd65f45e 17158 /* BGP log-neighbor-changes. */
892fedb6 17159 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17160 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17161 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17162 CHECK_FLAG(bgp->flags,
17163 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17164 ? ""
17165 : "no ");
17166
17167 /* BGP configuration. */
892fedb6 17168 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17169 vty_out(vty, " bgp always-compare-med\n");
17170
17171 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17172 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17173 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17174 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17175 CHECK_FLAG(bgp->flags,
17176 BGP_FLAG_EBGP_REQUIRES_POLICY)
17177 ? ""
17178 : "no ");
dd65f45e
DL
17179
17180 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17181 if (bgp->reject_as_sets)
dd65f45e
DL
17182 vty_out(vty, " bgp reject-as-sets\n");
17183
2adac256
DA
17184 /* Suppress duplicate updates if the route actually not changed
17185 */
17186 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17187 != SAVE_BGP_SUPPRESS_DUPLICATES)
17188 vty_out(vty, " %sbgp suppress-duplicates\n",
17189 CHECK_FLAG(bgp->flags,
17190 BGP_FLAG_SUPPRESS_DUPLICATES)
17191 ? ""
17192 : "no ");
17193
1ae314be
DA
17194 /* Send Hard Reset CEASE Notification for 'Administrative Reset'
17195 */
17196 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_HARD_ADMIN_RESET) !=
17197 SAVE_BGP_HARD_ADMIN_RESET)
17198 vty_out(vty, " %sbgp hard-administrative-reset\n",
17199 CHECK_FLAG(bgp->flags,
17200 BGP_FLAG_HARD_ADMIN_RESET)
17201 ? ""
17202 : "no ");
17203
b16bcbba
TA
17204 /* BGP default <afi>-<safi> */
17205 FOREACH_AFI_SAFI (afi, safi) {
17206 if (afi == AFI_IP && safi == SAFI_UNICAST) {
17207 if (!bgp->default_af[afi][safi])
17208 vty_out(vty, " no bgp default %s\n",
17209 get_bgp_default_af_flag(afi,
17210 safi));
17211 } else if (bgp->default_af[afi][safi])
17212 vty_out(vty, " bgp default %s\n",
17213 get_bgp_default_af_flag(afi, safi));
17214 }
e84c59af 17215
dd65f45e
DL
17216 /* BGP default local-preference. */
17217 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17218 vty_out(vty, " bgp default local-preference %u\n",
17219 bgp->default_local_pref);
17220
17221 /* BGP default show-hostname */
892fedb6 17222 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17223 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17224 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17225 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17226 ? ""
17227 : "no ");
17228
aef999a2
DA
17229 /* BGP default show-nexthop-hostname */
17230 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17231 != SAVE_BGP_SHOW_HOSTNAME)
17232 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17233 CHECK_FLAG(bgp->flags,
17234 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17235 ? ""
17236 : "no ");
17237
dd65f45e
DL
17238 /* BGP default subgroup-pkt-queue-max. */
17239 if (bgp->default_subgroup_pkt_queue_max
17240 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17241 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17242 bgp->default_subgroup_pkt_queue_max);
17243
17244 /* BGP client-to-client reflection. */
892fedb6 17245 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17246 vty_out(vty, " no bgp client-to-client reflection\n");
17247
17248 /* BGP cluster ID. */
17249 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17250 vty_out(vty, " bgp cluster-id %pI4\n",
17251 &bgp->cluster_id);
dd65f45e
DL
17252
17253 /* Disable ebgp connected nexthop check */
892fedb6 17254 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17255 vty_out(vty,
17256 " bgp disable-ebgp-connected-route-check\n");
17257
17258 /* Confederation identifier*/
17259 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17260 vty_out(vty, " bgp confederation identifier %u\n",
17261 bgp->confed_id);
17262
17263 /* Confederation peer */
17264 if (bgp->confed_peers_cnt > 0) {
17265 int i;
17266
17267 vty_out(vty, " bgp confederation peers");
17268
17269 for (i = 0; i < bgp->confed_peers_cnt; i++)
17270 vty_out(vty, " %u", bgp->confed_peers[i]);
17271
17272 vty_out(vty, "\n");
17273 }
17274
17275 /* BGP deterministic-med. */
892fedb6 17276 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17277 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17278 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17279 CHECK_FLAG(bgp->flags,
17280 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17281 ? ""
17282 : "no ");
17283
17284 /* BGP update-delay. */
17285 bgp_config_write_update_delay(vty, bgp);
17286
17287 if (bgp->v_maxmed_onstartup
17288 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17289 vty_out(vty, " bgp max-med on-startup %u",
17290 bgp->v_maxmed_onstartup);
17291 if (bgp->maxmed_onstartup_value
17292 != BGP_MAXMED_VALUE_DEFAULT)
17293 vty_out(vty, " %u",
17294 bgp->maxmed_onstartup_value);
17295 vty_out(vty, "\n");
17296 }
17297 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17298 vty_out(vty, " bgp max-med administrative");
17299 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17300 vty_out(vty, " %u", bgp->maxmed_admin_value);
17301 vty_out(vty, "\n");
17302 }
17303
17304 /* write quanta */
17305 bgp_config_write_wpkt_quanta(vty, bgp);
17306 /* read quanta */
17307 bgp_config_write_rpkt_quanta(vty, bgp);
17308
17309 /* coalesce time */
17310 bgp_config_write_coalesce_time(vty, bgp);
17311
05bd726c 17312 /* BGP per-instance graceful-shutdown */
17313 /* BGP-wide settings and per-instance settings are mutually
17314 * exclusive.
17315 */
17316 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17317 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17318 vty_out(vty, " bgp graceful-shutdown\n");
17319
8606be87
DA
17320 /* Long-lived Graceful Restart */
17321 if (bgp->llgr_stale_time != BGP_DEFAULT_LLGR_STALE_TIME)
17322 vty_out(vty,
17323 " bgp long-lived-graceful-restart stale-time %u\n",
17324 bgp->llgr_stale_time);
17325
dd65f45e
DL
17326 /* BGP graceful-restart. */
17327 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17328 vty_out(vty,
17329 " bgp graceful-restart stalepath-time %u\n",
17330 bgp->stalepath_time);
cfd47646 17331
dd65f45e
DL
17332 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17333 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17334 bgp->restart_time);
cfd47646 17335
f2ca5c5b
DA
17336 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION) !=
17337 SAVE_BGP_GRACEFUL_NOTIFICATION)
17338 vty_out(vty, " %sbgp graceful-restart notification\n",
17339 CHECK_FLAG(bgp->flags,
17340 BGP_FLAG_GRACEFUL_NOTIFICATION)
17341 ? ""
17342 : "no ");
17343
cfd47646 17344 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17345 vty_out(vty,
17346 " bgp graceful-restart select-defer-time %u\n",
17347 bgp->select_defer_time);
17348
17349 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17350 vty_out(vty, " bgp graceful-restart\n");
17351
cfd47646 17352 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17353 vty_out(vty, " bgp graceful-restart-disable\n");
17354
dd65f45e 17355 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17356 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17357 vty_out(vty,
17358 " bgp graceful-restart preserve-fw-state\n");
17359
dc95985f 17360 /* Stale timer for RIB */
17361 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17362 vty_out(vty,
17363 " bgp graceful-restart rib-stale-time %u\n",
17364 bgp->rib_stale_time);
17365
dd65f45e 17366 /* BGP bestpath method. */
892fedb6 17367 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17368 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17369 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17370 vty_out(vty, " bgp bestpath as-path confed\n");
17371
892fedb6
DA
17372 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17373 if (CHECK_FLAG(bgp->flags,
17374 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17375 vty_out(vty,
17376 " bgp bestpath as-path multipath-relax as-set\n");
17377 } else {
17378 vty_out(vty,
17379 " bgp bestpath as-path multipath-relax\n");
17380 }
17381 }
17382
892fedb6 17383 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17384 vty_out(vty,
17385 " bgp route-reflector allow-outbound-policy\n");
17386 }
892fedb6 17387 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17388 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17389 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17390 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17391 vty_out(vty, " bgp bestpath med");
892fedb6 17392 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17393 vty_out(vty, " confed");
892fedb6
DA
17394 if (CHECK_FLAG(bgp->flags,
17395 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17396 vty_out(vty, " missing-as-worst");
17397 vty_out(vty, "\n");
17398 }
17399
ee88563a
JM
17400 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17401 vty_out(vty,
17402 " bgp bestpath peer-type multipath-relax\n");
17403
f7e1c681 17404 /* Link bandwidth handling. */
17405 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17406 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17407 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17408 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17409 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17410 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17411
dd65f45e 17412 /* BGP network import check. */
892fedb6 17413 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17414 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17415 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17416 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17417 ? ""
17418 : "no ");
17419
17420 /* BGP timers configuration. */
5d5393b9 17421 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17422 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17423 vty_out(vty, " timers bgp %u %u\n",
17424 bgp->default_keepalive, bgp->default_holdtime);
17425
b042667a
TI
17426 /* BGP minimum holdtime configuration. */
17427 if (bgp->default_min_holdtime != SAVE_BGP_HOLDTIME
17428 && bgp->default_min_holdtime != 0)
17429 vty_out(vty, " bgp minimum-holdtime %u\n",
17430 bgp->default_min_holdtime);
17431
389e4f92
QY
17432 /* Conditional advertisement timer configuration */
17433 if (bgp->condition_check_period
17434 != DEFAULT_CONDITIONAL_ROUTES_POLL_TIME)
17435 vty_out(vty,
17436 " bgp conditional-advertisement timer %u\n",
17437 bgp->condition_check_period);
17438
dd65f45e
DL
17439 /* peer-group */
17440 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17441 bgp_config_write_peer_global(vty, bgp, group->conf);
17442 }
17443
17444 /* Normal neighbor configuration. */
17445 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17446 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17447 bgp_config_write_peer_global(vty, bgp, peer);
17448 }
17449
17450 /* listen range and limit for dynamic BGP neighbors */
17451 bgp_config_write_listen(vty, bgp);
17452
17453 /*
17454 * BGP default autoshutdown neighbors
17455 *
17456 * This must be placed after any peer and peer-group
17457 * configuration, to avoid setting all peers to shutdown after
17458 * a daemon restart, which is undesired behavior. (see #2286)
17459 */
17460 if (bgp->autoshutdown)
17461 vty_out(vty, " bgp default shutdown\n");
17462
9cf59432
DS
17463 /* BGP instance administrative shutdown */
17464 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17465 vty_out(vty, " bgp shutdown\n");
17466
f852eb98
PG
17467 if (bgp->fast_convergence)
17468 vty_out(vty, " bgp fast-convergence\n");
17469
a0281b2e
HS
17470 if (bgp->srv6_enabled) {
17471 vty_frame(vty, " !\n segment-routing srv6\n");
96db4340 17472 if (strlen(bgp->srv6_locator_name))
a0281b2e
HS
17473 vty_out(vty, " locator %s\n",
17474 bgp->srv6_locator_name);
ff7c3ee1 17475 vty_endframe(vty, " exit\n");
a0281b2e
HS
17476 }
17477
17478
dd65f45e
DL
17479 /* IPv4 unicast configuration. */
17480 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17481
17482 /* IPv4 multicast configuration. */
17483 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17484
17485 /* IPv4 labeled-unicast configuration. */
17486 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17487
17488 /* IPv4 VPN configuration. */
17489 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17490
17491 /* ENCAPv4 configuration. */
17492 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17493
17494 /* FLOWSPEC v4 configuration. */
17495 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17496
17497 /* IPv6 unicast configuration. */
17498 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17499
17500 /* IPv6 multicast configuration. */
17501 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17502
17503 /* IPv6 labeled-unicast configuration. */
17504 bgp_config_write_family(vty, bgp, AFI_IP6,
17505 SAFI_LABELED_UNICAST);
17506
17507 /* IPv6 VPN configuration. */
17508 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17509
17510 /* ENCAPv6 configuration. */
17511 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17512
17513 /* FLOWSPEC v6 configuration. */
17514 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17515
17516 /* EVPN configuration. */
17517 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17518
17519 hook_call(bgp_inst_config_write, bgp, vty);
17520
49e5a4a0 17521#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17522 bgp_rfapi_cfg_write(vty, bgp);
17523#endif
17524
07679ad9 17525 vty_out(vty, "exit\n");
dd65f45e
DL
17526 vty_out(vty, "!\n");
17527 }
17528 return 0;
17529}
17530
ddb5b488 17531
718e3744 17532/* BGP node structure. */
d62a17ae 17533static struct cmd_node bgp_node = {
f4b8291f 17534 .name = "bgp",
62b346ee 17535 .node = BGP_NODE,
24389580 17536 .parent_node = CONFIG_NODE,
62b346ee 17537 .prompt = "%s(config-router)# ",
612c2c15 17538 .config_write = bgp_config_write,
718e3744 17539};
17540
d62a17ae 17541static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17542 .name = "bgp ipv4 unicast",
62b346ee 17543 .node = BGP_IPV4_NODE,
24389580 17544 .parent_node = BGP_NODE,
62b346ee 17545 .prompt = "%s(config-router-af)# ",
dd2c81b8 17546 .no_xpath = true,
718e3744 17547};
17548
d62a17ae 17549static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17550 .name = "bgp ipv4 multicast",
62b346ee 17551 .node = BGP_IPV4M_NODE,
24389580 17552 .parent_node = BGP_NODE,
62b346ee 17553 .prompt = "%s(config-router-af)# ",
dd2c81b8 17554 .no_xpath = true,
718e3744 17555};
17556
d62a17ae 17557static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17558 .name = "bgp ipv4 labeled unicast",
62b346ee 17559 .node = BGP_IPV4L_NODE,
24389580 17560 .parent_node = BGP_NODE,
62b346ee 17561 .prompt = "%s(config-router-af)# ",
dd2c81b8 17562 .no_xpath = true,
f51bae9c
DS
17563};
17564
d62a17ae 17565static struct cmd_node bgp_ipv6_unicast_node = {
a17cfb3f 17566 .name = "bgp ipv6 unicast",
62b346ee 17567 .node = BGP_IPV6_NODE,
24389580 17568 .parent_node = BGP_NODE,
62b346ee 17569 .prompt = "%s(config-router-af)# ",
dd2c81b8 17570 .no_xpath = true,
718e3744 17571};
17572
d62a17ae 17573static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17574 .name = "bgp ipv6 multicast",
62b346ee 17575 .node = BGP_IPV6M_NODE,
24389580 17576 .parent_node = BGP_NODE,
62b346ee 17577 .prompt = "%s(config-router-af)# ",
dd2c81b8 17578 .no_xpath = true,
25ffbdc1 17579};
17580
d62a17ae 17581static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17582 .name = "bgp ipv6 labeled unicast",
62b346ee 17583 .node = BGP_IPV6L_NODE,
24389580 17584 .parent_node = BGP_NODE,
62b346ee 17585 .prompt = "%s(config-router-af)# ",
dd2c81b8 17586 .no_xpath = true,
f51bae9c
DS
17587};
17588
62b346ee 17589static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17590 .name = "bgp vpnv4",
62b346ee 17591 .node = BGP_VPNV4_NODE,
24389580 17592 .parent_node = BGP_NODE,
62b346ee 17593 .prompt = "%s(config-router-af)# ",
dd2c81b8 17594 .no_xpath = true,
62b346ee 17595};
6b0655a2 17596
62b346ee 17597static struct cmd_node bgp_vpnv6_node = {
f4b8291f 17598 .name = "bgp vpnv6",
62b346ee 17599 .node = BGP_VPNV6_NODE,
24389580 17600 .parent_node = BGP_NODE,
62b346ee 17601 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17602 .no_xpath = true,
62b346ee 17603};
8ecd3266 17604
62b346ee 17605static struct cmd_node bgp_evpn_node = {
f4b8291f 17606 .name = "bgp evpn",
62b346ee 17607 .node = BGP_EVPN_NODE,
24389580 17608 .parent_node = BGP_NODE,
62b346ee 17609 .prompt = "%s(config-router-evpn)# ",
dd2c81b8 17610 .no_xpath = true,
62b346ee 17611};
4e0b7b6d 17612
62b346ee 17613static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 17614 .name = "bgp evpn vni",
62b346ee 17615 .node = BGP_EVPN_VNI_NODE,
24389580 17616 .parent_node = BGP_EVPN_NODE,
62b346ee 17617 .prompt = "%s(config-router-af-vni)# ",
62b346ee 17618};
90e60aa7 17619
62b346ee 17620static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 17621 .name = "bgp ipv4 flowspec",
62b346ee 17622 .node = BGP_FLOWSPECV4_NODE,
24389580 17623 .parent_node = BGP_NODE,
62b346ee 17624 .prompt = "%s(config-router-af)# ",
dd2c81b8 17625 .no_xpath = true,
62b346ee 17626};
7c40bf39 17627
62b346ee 17628static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 17629 .name = "bgp ipv6 flowspec",
62b346ee 17630 .node = BGP_FLOWSPECV6_NODE,
24389580 17631 .parent_node = BGP_NODE,
62b346ee 17632 .prompt = "%s(config-router-af-vpnv6)# ",
dd2c81b8 17633 .no_xpath = true,
62b346ee 17634};
7c40bf39 17635
bfaab44d
HS
17636static struct cmd_node bgp_srv6_node = {
17637 .name = "bgp srv6",
17638 .node = BGP_SRV6_NODE,
17639 .parent_node = BGP_NODE,
17640 .prompt = "%s(config-router-srv6)# ",
17641};
17642
d62a17ae 17643static void community_list_vty(void);
1f8ae70b 17644
8c20061f
DA
17645static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17646{
17647 struct bgp *bgp;
17648 struct peer_group *group;
17649 struct listnode *lnbgp, *lnpeer;
17650
17651 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17652 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17653 vector_set(comps,
17654 XSTRDUP(MTYPE_COMPLETION, group->name));
17655 }
17656}
17657
17658static void bgp_ac_peer(vector comps, struct cmd_token *token)
b8a815e5 17659{
d62a17ae 17660 struct bgp *bgp;
17661 struct peer *peer;
d62a17ae 17662 struct listnode *lnbgp, *lnpeer;
b8a815e5 17663
d62a17ae 17664 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17665 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17666 /* only provide suggestions on the appropriate input
17667 * token type,
17668 * they'll otherwise show up multiple times */
17669 enum cmd_token_type match_type;
17670 char *name = peer->host;
d48ed3e0 17671
d62a17ae 17672 if (peer->conf_if) {
17673 match_type = VARIABLE_TKN;
17674 name = peer->conf_if;
17675 } else if (strchr(peer->host, ':'))
17676 match_type = IPV6_TKN;
17677 else
17678 match_type = IPV4_TKN;
d48ed3e0 17679
d62a17ae 17680 if (token->type != match_type)
17681 continue;
d48ed3e0 17682
d62a17ae 17683 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17684 }
d62a17ae 17685 }
b8a815e5
DL
17686}
17687
8c20061f
DA
17688static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17689{
17690 bgp_ac_peer(comps, token);
84de1483
DA
17691
17692 if (token->type == VARIABLE_TKN)
17693 bgp_ac_peergroup(comps, token);
8c20061f
DA
17694}
17695
b8a815e5 17696static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 17697 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17698 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 17699 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 17700 {.completions = NULL}};
17701
47a306a0
DS
17702static const struct cmd_variable_handler bgp_var_peergroup[] = {
17703 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17704 {.completions = NULL} };
17705
aa24a36a
DA
17706DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
17707
17708static struct thread *t_bgp_cfg;
17709
17710bool bgp_config_inprocess(void)
17711{
17712 return thread_is_scheduled(t_bgp_cfg);
17713}
17714
17715static void bgp_config_finish(struct thread *t)
17716{
17717 struct listnode *node;
17718 struct bgp *bgp;
17719
17720 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp))
17721 hook_call(bgp_config_end, bgp);
17722}
17723
17724static void bgp_config_start(void)
17725{
17726#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
17727 THREAD_OFF(t_bgp_cfg);
17728 thread_add_timer(bm->master, bgp_config_finish, NULL,
17729 BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
17730}
17731
17732/* When we receive a hook the configuration is read,
17733 * we start a timer to make sure we postpone sending
17734 * EoR before route-maps are processed.
17735 * This is especially valid if using `bgp route-map delay-timer`.
17736 */
17737static void bgp_config_end(void)
17738{
17739#define BGP_POST_CONFIG_DELAY_SECONDS 1
17740 uint32_t bgp_post_config_delay =
17741 thread_is_scheduled(bm->t_rmap_update)
17742 ? thread_timer_remain_second(bm->t_rmap_update)
17743 : BGP_POST_CONFIG_DELAY_SECONDS;
17744
17745 /* If BGP config processing thread isn't running, then
17746 * we can return and rely it's properly handled.
17747 */
17748 if (!bgp_config_inprocess())
17749 return;
17750
17751 THREAD_OFF(t_bgp_cfg);
17752
17753 /* Start a new timer to make sure we don't send EoR
17754 * before route-maps are processed.
17755 */
17756 thread_add_timer(bm->master, bgp_config_finish, NULL,
17757 bgp_post_config_delay, &t_bgp_cfg);
17758}
17759
d62a17ae 17760void bgp_vty_init(void)
17761{
17762 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 17763 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 17764
aa24a36a
DA
17765 cmd_init_config_callbacks(bgp_config_start, bgp_config_end);
17766
d62a17ae 17767 /* Install bgp top node. */
612c2c15
DL
17768 install_node(&bgp_node);
17769 install_node(&bgp_ipv4_unicast_node);
17770 install_node(&bgp_ipv4_multicast_node);
17771 install_node(&bgp_ipv4_labeled_unicast_node);
17772 install_node(&bgp_ipv6_unicast_node);
17773 install_node(&bgp_ipv6_multicast_node);
17774 install_node(&bgp_ipv6_labeled_unicast_node);
17775 install_node(&bgp_vpnv4_node);
17776 install_node(&bgp_vpnv6_node);
17777 install_node(&bgp_evpn_node);
17778 install_node(&bgp_evpn_vni_node);
17779 install_node(&bgp_flowspecv4_node);
17780 install_node(&bgp_flowspecv6_node);
bfaab44d 17781 install_node(&bgp_srv6_node);
d62a17ae 17782
17783 /* Install default VTY commands to new nodes. */
17784 install_default(BGP_NODE);
17785 install_default(BGP_IPV4_NODE);
17786 install_default(BGP_IPV4M_NODE);
17787 install_default(BGP_IPV4L_NODE);
17788 install_default(BGP_IPV6_NODE);
17789 install_default(BGP_IPV6M_NODE);
17790 install_default(BGP_IPV6L_NODE);
17791 install_default(BGP_VPNV4_NODE);
17792 install_default(BGP_VPNV6_NODE);
7c40bf39 17793 install_default(BGP_FLOWSPECV4_NODE);
17794 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 17795 install_default(BGP_EVPN_NODE);
17796 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 17797 install_default(BGP_SRV6_NODE);
d62a17ae 17798
8029b216
AK
17799 /* "bgp local-mac" hidden commands. */
17800 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17801 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17802
9acb67cb
DS
17803 /* "bgp suppress-fib-pending" global */
17804 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17805
d62a17ae 17806 /* bgp route-map delay-timer commands. */
17807 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17808 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17809
f852eb98
PG
17810 /* bgp fast-convergence command */
17811 install_element(BGP_NODE, &bgp_fast_convergence_cmd);
17812 install_element(BGP_NODE, &no_bgp_fast_convergence_cmd);
17813
d70583f7
D
17814 /* global bgp update-delay command */
17815 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17816 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17817
05bd726c 17818 /* global bgp graceful-shutdown command */
17819 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17820 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17821
d62a17ae 17822 /* Dummy commands (Currently not supported) */
17823 install_element(BGP_NODE, &no_synchronization_cmd);
17824 install_element(BGP_NODE, &no_auto_summary_cmd);
17825
17826 /* "router bgp" commands. */
17827 install_element(CONFIG_NODE, &router_bgp_cmd);
17828
17829 /* "no router bgp" commands. */
17830 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17831
17832 /* "bgp router-id" commands. */
17833 install_element(BGP_NODE, &bgp_router_id_cmd);
17834 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17835
c208c586
S
17836 /* "bgp suppress-fib-pending" command */
17837 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17838
d62a17ae 17839 /* "bgp cluster-id" commands. */
17840 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17841 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17842
c163f297
DS
17843 /* "bgp no-rib" commands. */
17844 install_element(CONFIG_NODE, &bgp_norib_cmd);
17845 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17846
e46723a5
DS
17847 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17848
d62a17ae 17849 /* "bgp confederation" commands. */
17850 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17851 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17852
17853 /* "bgp confederation peers" commands. */
17854 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17855 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17856
17857 /* bgp max-med command */
17858 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17859 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17860 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17861 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17862 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17863
17864 /* bgp disable-ebgp-connected-nh-check */
17865 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17866 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17867
17868 /* bgp update-delay command */
17869 install_element(BGP_NODE, &bgp_update_delay_cmd);
17870 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 17871
17872 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 17873 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 17874
17875 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17876 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17877
17878 /* "maximum-paths" commands. */
17879 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17880 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17881 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17882 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17883 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17884 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17885 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17886 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17887 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17888 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17889 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17890 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17891 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17892 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17893 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17894
39edabac
PG
17895 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17896 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17897 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17898 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17899 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 17900 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17901 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17902 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17903 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17904 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17905
17906 /* "timers bgp" commands. */
17907 install_element(BGP_NODE, &bgp_timers_cmd);
17908 install_element(BGP_NODE, &no_bgp_timers_cmd);
17909
b042667a
TI
17910 /* "minimum-holdtime" commands. */
17911 install_element(BGP_NODE, &bgp_minimum_holdtime_cmd);
17912 install_element(BGP_NODE, &no_bgp_minimum_holdtime_cmd);
17913
d62a17ae 17914 /* route-map delay-timer commands - per instance for backwards compat.
17915 */
17916 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17917 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17918
17919 /* "bgp client-to-client reflection" commands */
17920 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17921 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17922
17923 /* "bgp always-compare-med" commands */
17924 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17925 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17926
9dac9fc8
DA
17927 /* bgp ebgp-requires-policy */
17928 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17929 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17930
2adac256
DA
17931 /* bgp suppress-duplicates */
17932 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17933 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17934
fb29348a
DA
17935 /* bgp reject-as-sets */
17936 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17937 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17938
d62a17ae 17939 /* "bgp deterministic-med" commands */
17940 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17941 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17942
055679e9 17943 /* "bgp graceful-restart" command */
36235319
QY
17944 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17945 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 17946
17947 /* "bgp graceful-restart-disable" command */
36235319
QY
17948 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17949 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 17950
17951 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
17952 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17953 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 17954
17955 /* "neighbor a:b:c:d graceful-restart-disable" command */
17956 install_element(BGP_NODE,
17957 &bgp_neighbor_graceful_restart_disable_set_cmd);
17958 install_element(BGP_NODE,
17959 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17960
17961 /* "neighbor a:b:c:d graceful-restart-helper" command */
17962 install_element(BGP_NODE,
17963 &bgp_neighbor_graceful_restart_helper_set_cmd);
17964 install_element(BGP_NODE,
17965 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17966
d62a17ae 17967 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17968 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17969 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17970 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 17971 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 17972 install_element(BGP_NODE,
17973 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 17974 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17975 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
f2ca5c5b 17976 install_element(BGP_NODE, &bgp_graceful_restart_notification_cmd);
d62a17ae 17977
d6e3c15b 17978 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17979 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 17980 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17981 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 17982
7f323236
DW
17983 /* "bgp graceful-shutdown" commands */
17984 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17985 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17986
1ae314be
DA
17987 /* "bgp hard-administrative-reset" commands */
17988 install_element(BGP_NODE, &bgp_administrative_reset_cmd);
17989
8606be87
DA
17990 /* "bgp long-lived-graceful-restart" commands */
17991 install_element(BGP_NODE, &bgp_llgr_stalepath_time_cmd);
17992 install_element(BGP_NODE, &no_bgp_llgr_stalepath_time_cmd);
17993
d62a17ae 17994 /* "bgp fast-external-failover" commands */
17995 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17996 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17997
d62a17ae 17998 /* "bgp bestpath compare-routerid" commands */
17999 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18000 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18001
18002 /* "bgp bestpath as-path ignore" commands */
18003 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18004 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18005
18006 /* "bgp bestpath as-path confed" commands */
18007 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18008 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18009
18010 /* "bgp bestpath as-path multipath-relax" commands */
18011 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18012 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18013
ee88563a
JM
18014 /* "bgp bestpath peer-type multipath-relax" commands */
18015 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18016 install_element(BGP_NODE,
18017 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18018
d62a17ae 18019 /* "bgp log-neighbor-changes" commands */
18020 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18021 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18022
18023 /* "bgp bestpath med" commands */
18024 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18025 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18026
f7e1c681 18027 /* "bgp bestpath bandwidth" commands */
18028 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18029 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18030
b16bcbba
TA
18031 /* "no bgp default <afi>-<safi>" commands. */
18032 install_element(BGP_NODE, &bgp_default_afi_safi_cmd);
e84c59af 18033
d62a17ae 18034 /* "bgp network import-check" commands. */
18035 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18036 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18037 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18038
18039 /* "bgp default local-preference" commands. */
18040 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18041 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18042
18043 /* bgp default show-hostname */
18044 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18045 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18046
aef999a2
DA
18047 /* bgp default show-nexthop-hostname */
18048 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18049 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18050
d62a17ae 18051 /* "bgp default subgroup-pkt-queue-max" commands. */
18052 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18053 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18054
18055 /* bgp ibgp-allow-policy-mods command */
18056 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18057 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18058
18059 /* "bgp listen limit" commands. */
18060 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18061 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18062
18063 /* "bgp listen range" commands. */
18064 install_element(BGP_NODE, &bgp_listen_range_cmd);
18065 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18066
8175f54a 18067 /* "bgp default shutdown" command */
f26845f9 18068 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18069
18070 /* "bgp shutdown" commands */
18071 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18072 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18073 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18074 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18075
d62a17ae 18076 /* "neighbor remote-as" commands. */
18077 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18078 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18079 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18080 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18081 install_element(BGP_NODE,
18082 &neighbor_interface_v6only_config_remote_as_cmd);
18083 install_element(BGP_NODE, &no_neighbor_cmd);
18084 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18085
18086 /* "neighbor peer-group" commands. */
18087 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18088 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18089 install_element(BGP_NODE,
18090 &no_neighbor_interface_peer_group_remote_as_cmd);
18091
18092 /* "neighbor local-as" commands. */
18093 install_element(BGP_NODE, &neighbor_local_as_cmd);
18094 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18095 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18096 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18097
18098 /* "neighbor solo" commands. */
18099 install_element(BGP_NODE, &neighbor_solo_cmd);
18100 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18101
18102 /* "neighbor password" commands. */
18103 install_element(BGP_NODE, &neighbor_password_cmd);
18104 install_element(BGP_NODE, &no_neighbor_password_cmd);
18105
18106 /* "neighbor activate" commands. */
18107 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18108 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18109 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18110 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18111 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18112 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18113 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18114 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18115 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18116 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18117 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18118 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18119
18120 /* "no neighbor activate" commands. */
18121 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18122 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18123 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18124 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18125 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18126 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18127 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18128 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18129 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18130 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18131 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18132 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18133
18134 /* "neighbor peer-group" set commands. */
18135 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18136 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18137 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18138 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18139 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18140 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18141 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18142 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18143 install_element(BGP_FLOWSPECV4_NODE,
18144 &neighbor_set_peer_group_hidden_cmd);
18145 install_element(BGP_FLOWSPECV6_NODE,
18146 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18147
18148 /* "no neighbor peer-group unset" commands. */
18149 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18150 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18151 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18152 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18153 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18154 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18155 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18156 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18157 install_element(BGP_FLOWSPECV4_NODE,
18158 &no_neighbor_set_peer_group_hidden_cmd);
18159 install_element(BGP_FLOWSPECV6_NODE,
18160 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18161
18162 /* "neighbor softreconfiguration inbound" commands.*/
18163 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18164 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18165 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18166 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18167 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18168 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18169 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18170 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18171 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18172 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18173 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18174 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18175 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18176 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18177 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18178 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18179 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18180 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18181 install_element(BGP_FLOWSPECV4_NODE,
18182 &neighbor_soft_reconfiguration_cmd);
18183 install_element(BGP_FLOWSPECV4_NODE,
18184 &no_neighbor_soft_reconfiguration_cmd);
18185 install_element(BGP_FLOWSPECV6_NODE,
18186 &neighbor_soft_reconfiguration_cmd);
18187 install_element(BGP_FLOWSPECV6_NODE,
18188 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18189 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18190 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18191
18192 /* "neighbor attribute-unchanged" commands. */
18193 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18194 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18195 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18196 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18197 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18198 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18199 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18200 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18201 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18202 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18203 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18204 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18205 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18206 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18207 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18208 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18209 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18210 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18211
18212 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18213 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18214
b8ad84d2
PG
18215 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18216 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18217 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18218 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18219
d62a17ae 18220 /* "nexthop-local unchanged" commands */
18221 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18222 install_element(BGP_IPV6_NODE,
18223 &no_neighbor_nexthop_local_unchanged_cmd);
18224
18225 /* "neighbor next-hop-self" commands. */
18226 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18227 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18228 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18229 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18230 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18231 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18232 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18233 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18234 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18235 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18236 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18237 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18238 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18239 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18240 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18241 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18242 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18243 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18244 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18245 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18246
18247 /* "neighbor next-hop-self force" commands. */
18248 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18249 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18250 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18251 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18252 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18253 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18254 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18255 install_element(BGP_IPV4_NODE,
18256 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18257 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18258 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18259 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18260 install_element(BGP_IPV4M_NODE,
18261 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18262 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18263 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18264 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18265 install_element(BGP_IPV4L_NODE,
18266 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18267 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18268 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18269 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18270 install_element(BGP_IPV6_NODE,
18271 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18272 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18273 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18274 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18275 install_element(BGP_IPV6M_NODE,
18276 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18277 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18278 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18279 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18280 install_element(BGP_IPV6L_NODE,
18281 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18282 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18283 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18284 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18285 install_element(BGP_VPNV4_NODE,
18286 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18287 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18288 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18289 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18290 install_element(BGP_VPNV6_NODE,
18291 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18292 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18293 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18294
18295 /* "neighbor as-override" commands. */
18296 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18297 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18298 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18299 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18300 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18301 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18302 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18303 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18304 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18305 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18306 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18307 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18308 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18309 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18310 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18311 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18312 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18313 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18314
18315 /* "neighbor remove-private-AS" commands. */
18316 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18317 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18318 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18319 install_element(BGP_NODE,
18320 &no_neighbor_remove_private_as_all_hidden_cmd);
18321 install_element(BGP_NODE,
18322 &neighbor_remove_private_as_replace_as_hidden_cmd);
18323 install_element(BGP_NODE,
18324 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18325 install_element(BGP_NODE,
18326 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18327 install_element(
18328 BGP_NODE,
18329 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18330 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18331 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18332 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18333 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18334 install_element(BGP_IPV4_NODE,
18335 &neighbor_remove_private_as_replace_as_cmd);
18336 install_element(BGP_IPV4_NODE,
18337 &no_neighbor_remove_private_as_replace_as_cmd);
18338 install_element(BGP_IPV4_NODE,
18339 &neighbor_remove_private_as_all_replace_as_cmd);
18340 install_element(BGP_IPV4_NODE,
18341 &no_neighbor_remove_private_as_all_replace_as_cmd);
18342 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18343 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18344 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18345 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18346 install_element(BGP_IPV4M_NODE,
18347 &neighbor_remove_private_as_replace_as_cmd);
18348 install_element(BGP_IPV4M_NODE,
18349 &no_neighbor_remove_private_as_replace_as_cmd);
18350 install_element(BGP_IPV4M_NODE,
18351 &neighbor_remove_private_as_all_replace_as_cmd);
18352 install_element(BGP_IPV4M_NODE,
18353 &no_neighbor_remove_private_as_all_replace_as_cmd);
18354 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18355 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18356 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18357 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18358 install_element(BGP_IPV4L_NODE,
18359 &neighbor_remove_private_as_replace_as_cmd);
18360 install_element(BGP_IPV4L_NODE,
18361 &no_neighbor_remove_private_as_replace_as_cmd);
18362 install_element(BGP_IPV4L_NODE,
18363 &neighbor_remove_private_as_all_replace_as_cmd);
18364 install_element(BGP_IPV4L_NODE,
18365 &no_neighbor_remove_private_as_all_replace_as_cmd);
18366 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18367 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18368 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18369 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18370 install_element(BGP_IPV6_NODE,
18371 &neighbor_remove_private_as_replace_as_cmd);
18372 install_element(BGP_IPV6_NODE,
18373 &no_neighbor_remove_private_as_replace_as_cmd);
18374 install_element(BGP_IPV6_NODE,
18375 &neighbor_remove_private_as_all_replace_as_cmd);
18376 install_element(BGP_IPV6_NODE,
18377 &no_neighbor_remove_private_as_all_replace_as_cmd);
18378 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18379 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18380 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18381 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18382 install_element(BGP_IPV6M_NODE,
18383 &neighbor_remove_private_as_replace_as_cmd);
18384 install_element(BGP_IPV6M_NODE,
18385 &no_neighbor_remove_private_as_replace_as_cmd);
18386 install_element(BGP_IPV6M_NODE,
18387 &neighbor_remove_private_as_all_replace_as_cmd);
18388 install_element(BGP_IPV6M_NODE,
18389 &no_neighbor_remove_private_as_all_replace_as_cmd);
18390 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18391 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18392 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18393 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18394 install_element(BGP_IPV6L_NODE,
18395 &neighbor_remove_private_as_replace_as_cmd);
18396 install_element(BGP_IPV6L_NODE,
18397 &no_neighbor_remove_private_as_replace_as_cmd);
18398 install_element(BGP_IPV6L_NODE,
18399 &neighbor_remove_private_as_all_replace_as_cmd);
18400 install_element(BGP_IPV6L_NODE,
18401 &no_neighbor_remove_private_as_all_replace_as_cmd);
18402 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18403 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18404 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18405 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18406 install_element(BGP_VPNV4_NODE,
18407 &neighbor_remove_private_as_replace_as_cmd);
18408 install_element(BGP_VPNV4_NODE,
18409 &no_neighbor_remove_private_as_replace_as_cmd);
18410 install_element(BGP_VPNV4_NODE,
18411 &neighbor_remove_private_as_all_replace_as_cmd);
18412 install_element(BGP_VPNV4_NODE,
18413 &no_neighbor_remove_private_as_all_replace_as_cmd);
18414 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18415 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18416 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18417 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18418 install_element(BGP_VPNV6_NODE,
18419 &neighbor_remove_private_as_replace_as_cmd);
18420 install_element(BGP_VPNV6_NODE,
18421 &no_neighbor_remove_private_as_replace_as_cmd);
18422 install_element(BGP_VPNV6_NODE,
18423 &neighbor_remove_private_as_all_replace_as_cmd);
18424 install_element(BGP_VPNV6_NODE,
18425 &no_neighbor_remove_private_as_all_replace_as_cmd);
18426
18427 /* "neighbor send-community" commands.*/
18428 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18429 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18430 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18431 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18432 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18433 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18434 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18435 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18436 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18437 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18438 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18439 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18440 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18441 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18442 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18443 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18444 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18445 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18446 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18447 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18448 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18449 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18450 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18451 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18452 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18453 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18454 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18455 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18456 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18457 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18458 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18459 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18460 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18461 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18462 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18463 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18464
18465 /* "neighbor route-reflector" commands.*/
18466 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18467 install_element(BGP_NODE,
18468 &no_neighbor_route_reflector_client_hidden_cmd);
18469 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18470 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18471 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18472 install_element(BGP_IPV4M_NODE,
18473 &no_neighbor_route_reflector_client_cmd);
18474 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18475 install_element(BGP_IPV4L_NODE,
18476 &no_neighbor_route_reflector_client_cmd);
18477 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18478 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18479 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18480 install_element(BGP_IPV6M_NODE,
18481 &no_neighbor_route_reflector_client_cmd);
18482 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18483 install_element(BGP_IPV6L_NODE,
18484 &no_neighbor_route_reflector_client_cmd);
18485 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18486 install_element(BGP_VPNV4_NODE,
18487 &no_neighbor_route_reflector_client_cmd);
18488 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18489 install_element(BGP_VPNV6_NODE,
18490 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18491 install_element(BGP_FLOWSPECV4_NODE,
18492 &neighbor_route_reflector_client_cmd);
18493 install_element(BGP_FLOWSPECV4_NODE,
18494 &no_neighbor_route_reflector_client_cmd);
18495 install_element(BGP_FLOWSPECV6_NODE,
18496 &neighbor_route_reflector_client_cmd);
18497 install_element(BGP_FLOWSPECV6_NODE,
18498 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18499 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18500 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18501
18502 /* "neighbor route-server" commands.*/
18503 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18504 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18505 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18506 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18507 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18508 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18509 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18510 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18511 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18512 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18513 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18514 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18515 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18516 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18517 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18518 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18519 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18520 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18521 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18522 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18523 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18524 install_element(BGP_FLOWSPECV4_NODE,
18525 &no_neighbor_route_server_client_cmd);
18526 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18527 install_element(BGP_FLOWSPECV6_NODE,
18528 &no_neighbor_route_server_client_cmd);
d62a17ae 18529
7c0e4312
DA
18530 /* "neighbor disable-addpath-rx" commands. */
18531 install_element(BGP_IPV4_NODE, &neighbor_disable_addpath_rx_cmd);
18532 install_element(BGP_IPV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18533 install_element(BGP_IPV4M_NODE, &neighbor_disable_addpath_rx_cmd);
18534 install_element(BGP_IPV4M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18535 install_element(BGP_IPV4L_NODE, &neighbor_disable_addpath_rx_cmd);
18536 install_element(BGP_IPV4L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18537 install_element(BGP_IPV6_NODE, &neighbor_disable_addpath_rx_cmd);
18538 install_element(BGP_IPV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18539 install_element(BGP_IPV6M_NODE, &neighbor_disable_addpath_rx_cmd);
18540 install_element(BGP_IPV6M_NODE, &no_neighbor_disable_addpath_rx_cmd);
18541 install_element(BGP_IPV6L_NODE, &neighbor_disable_addpath_rx_cmd);
18542 install_element(BGP_IPV6L_NODE, &no_neighbor_disable_addpath_rx_cmd);
18543 install_element(BGP_VPNV4_NODE, &neighbor_disable_addpath_rx_cmd);
18544 install_element(BGP_VPNV4_NODE, &no_neighbor_disable_addpath_rx_cmd);
18545 install_element(BGP_VPNV6_NODE, &neighbor_disable_addpath_rx_cmd);
18546 install_element(BGP_VPNV6_NODE, &no_neighbor_disable_addpath_rx_cmd);
18547
d62a17ae 18548 /* "neighbor addpath-tx-all-paths" commands.*/
18549 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18550 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18551 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18552 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18553 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18554 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18555 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18556 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18557 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18558 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18559 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18560 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18561 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18562 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18563 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18564 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18565 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18566 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18567
18568 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18569 install_element(BGP_NODE,
18570 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18571 install_element(BGP_NODE,
18572 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18573 install_element(BGP_IPV4_NODE,
18574 &neighbor_addpath_tx_bestpath_per_as_cmd);
18575 install_element(BGP_IPV4_NODE,
18576 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18577 install_element(BGP_IPV4M_NODE,
18578 &neighbor_addpath_tx_bestpath_per_as_cmd);
18579 install_element(BGP_IPV4M_NODE,
18580 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18581 install_element(BGP_IPV4L_NODE,
18582 &neighbor_addpath_tx_bestpath_per_as_cmd);
18583 install_element(BGP_IPV4L_NODE,
18584 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18585 install_element(BGP_IPV6_NODE,
18586 &neighbor_addpath_tx_bestpath_per_as_cmd);
18587 install_element(BGP_IPV6_NODE,
18588 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18589 install_element(BGP_IPV6M_NODE,
18590 &neighbor_addpath_tx_bestpath_per_as_cmd);
18591 install_element(BGP_IPV6M_NODE,
18592 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18593 install_element(BGP_IPV6L_NODE,
18594 &neighbor_addpath_tx_bestpath_per_as_cmd);
18595 install_element(BGP_IPV6L_NODE,
18596 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18597 install_element(BGP_VPNV4_NODE,
18598 &neighbor_addpath_tx_bestpath_per_as_cmd);
18599 install_element(BGP_VPNV4_NODE,
18600 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18601 install_element(BGP_VPNV6_NODE,
18602 &neighbor_addpath_tx_bestpath_per_as_cmd);
18603 install_element(BGP_VPNV6_NODE,
18604 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18605
2b31007c
RZ
18606 /* "neighbor sender-as-path-loop-detection" commands. */
18607 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18608 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18609
d62a17ae 18610 /* "neighbor passive" commands. */
18611 install_element(BGP_NODE, &neighbor_passive_cmd);
18612 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18613
18614
18615 /* "neighbor shutdown" commands. */
18616 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18617 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18618 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18619 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18620 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18621 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18622
18623 /* "neighbor capability extended-nexthop" commands.*/
18624 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18625 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18626
18627 /* "neighbor capability orf prefix-list" commands.*/
18628 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18629 install_element(BGP_NODE,
18630 &no_neighbor_capability_orf_prefix_hidden_cmd);
18631 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18632 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18633 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18634 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18635 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18636 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18637 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18638 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18639 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18640 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18641 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18642 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18643
18644 /* "neighbor capability dynamic" commands.*/
18645 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18646 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18647
18648 /* "neighbor dont-capability-negotiate" commands. */
18649 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18650 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18651
18652 /* "neighbor ebgp-multihop" commands. */
18653 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18654 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18655 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18656
18657 /* "neighbor disable-connected-check" commands. */
18658 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18659 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18660
7ab294ea
DA
18661 /* "neighbor disable-link-bw-encoding-ieee" commands. */
18662 install_element(BGP_NODE, &neighbor_disable_link_bw_encoding_ieee_cmd);
18663 install_element(BGP_NODE,
18664 &no_neighbor_disable_link_bw_encoding_ieee_cmd);
27aa23a4 18665
d08c0c80
DA
18666 /* "neighbor extended-optional-parameters" commands. */
18667 install_element(BGP_NODE, &neighbor_extended_optional_parameters_cmd);
18668 install_element(BGP_NODE,
18669 &no_neighbor_extended_optional_parameters_cmd);
18670
47cbc09b
PM
18671 /* "neighbor enforce-first-as" commands. */
18672 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18673 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18674
d62a17ae 18675 /* "neighbor description" commands. */
18676 install_element(BGP_NODE, &neighbor_description_cmd);
18677 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18678 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18679
18680 /* "neighbor update-source" commands. "*/
18681 install_element(BGP_NODE, &neighbor_update_source_cmd);
18682 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18683
18684 /* "neighbor default-originate" commands. */
18685 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18686 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18687 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18688 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18689 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18690 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18691 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18692 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18693 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18694 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18695 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18696 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18697 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18698 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18699 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18700 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18701 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18702 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18703 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18704 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18705 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18706
18707 /* "neighbor port" commands. */
18708 install_element(BGP_NODE, &neighbor_port_cmd);
18709 install_element(BGP_NODE, &no_neighbor_port_cmd);
18710
18711 /* "neighbor weight" commands. */
18712 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18713 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18714
18715 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18716 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18717 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18718 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18719 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18720 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18721 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18722 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18723 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18724 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18725 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18726 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18727 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18728 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18729 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18730 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18731
18732 /* "neighbor override-capability" commands. */
18733 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18734 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18735
18736 /* "neighbor strict-capability-match" commands. */
18737 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18738 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18739
18740 /* "neighbor timers" commands. */
18741 install_element(BGP_NODE, &neighbor_timers_cmd);
18742 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18743
18744 /* "neighbor timers connect" commands. */
18745 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18746 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18747
d43114f3
DS
18748 /* "neighbor timers delayopen" commands. */
18749 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18750 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18751
d62a17ae 18752 /* "neighbor advertisement-interval" commands. */
18753 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18754 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18755
18756 /* "neighbor interface" commands. */
18757 install_element(BGP_NODE, &neighbor_interface_cmd);
18758 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18759
18760 /* "neighbor distribute" commands. */
18761 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18762 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18763 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18764 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18765 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18766 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18767 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18768 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18769 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18770 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18771 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18772 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18773 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18774 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18775 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18776 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18777 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18778 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18779
18780 /* "neighbor prefix-list" commands. */
18781 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
642ef664 18782 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
d62a17ae 18783 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18784 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18785 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
642ef664 18786 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18787 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
642ef664 18788 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18789 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18790 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18791 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
642ef664 18792 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18793 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
642ef664 18794 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18795 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18796 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18797 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18798 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18799 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
642ef664 18800 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 18801 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
642ef664 18802 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 18803
18804 /* "neighbor filter-list" commands. */
18805 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18806 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18807 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18808 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18809 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18810 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18811 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18812 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18813 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18814 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18815 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18816 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18817 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18818 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18819 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18820 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18821 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18822 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 18823 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18824 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18825 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18826 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 18827
18828 /* "neighbor route-map" commands. */
d6d7ed37
IR
18829 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
18830 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
d62a17ae 18831 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18832 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18833 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
0ea8d871 18834 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18835 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
0ea8d871 18836 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18837 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18838 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18839 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
0ea8d871 18840 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18841 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
0ea8d871 18842 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18843 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18844 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18845 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18846 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18847 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
0ea8d871 18848 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
7c40bf39 18849 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
0ea8d871 18850 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549 18851 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
0ea8d871 18852 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 18853
18854 /* "neighbor unsuppress-map" commands. */
18855 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18856 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18857 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18858 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18859 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18860 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18861 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18862 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18863 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18864 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18865 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18866 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18867 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18868 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18869 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18870 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18871 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18872 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18873
7f7940e6 18874 /* "neighbor advertise-map" commands. */
389e4f92 18875 install_element(BGP_NODE, &bgp_condadv_period_cmd);
7f7940e6 18876 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 18877 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18878 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18879 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18880 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18881 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18882 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18883 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18884 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 18885
fde246e8
DA
18886 /* neighbor maximum-prefix-out commands. */
18887 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18888 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18889 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18890 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18891 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18892 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18893 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18894 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18895 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18896 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18897 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18898 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18899 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18900 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18901 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18902 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18903 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18904 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18905
d62a17ae 18906 /* "neighbor maximum-prefix" commands. */
18907 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18908 install_element(BGP_NODE,
18909 &neighbor_maximum_prefix_threshold_hidden_cmd);
18910 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18911 install_element(BGP_NODE,
18912 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18913 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18914 install_element(BGP_NODE,
18915 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18916 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18917 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18918 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18919 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18920 install_element(BGP_IPV4_NODE,
18921 &neighbor_maximum_prefix_threshold_warning_cmd);
18922 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18923 install_element(BGP_IPV4_NODE,
18924 &neighbor_maximum_prefix_threshold_restart_cmd);
18925 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18926 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18927 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18928 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18929 install_element(BGP_IPV4M_NODE,
18930 &neighbor_maximum_prefix_threshold_warning_cmd);
18931 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18932 install_element(BGP_IPV4M_NODE,
18933 &neighbor_maximum_prefix_threshold_restart_cmd);
18934 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18935 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18936 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18937 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18938 install_element(BGP_IPV4L_NODE,
18939 &neighbor_maximum_prefix_threshold_warning_cmd);
18940 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18941 install_element(BGP_IPV4L_NODE,
18942 &neighbor_maximum_prefix_threshold_restart_cmd);
18943 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18944 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18945 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18946 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18947 install_element(BGP_IPV6_NODE,
18948 &neighbor_maximum_prefix_threshold_warning_cmd);
18949 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18950 install_element(BGP_IPV6_NODE,
18951 &neighbor_maximum_prefix_threshold_restart_cmd);
18952 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18953 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18954 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18955 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18956 install_element(BGP_IPV6M_NODE,
18957 &neighbor_maximum_prefix_threshold_warning_cmd);
18958 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18959 install_element(BGP_IPV6M_NODE,
18960 &neighbor_maximum_prefix_threshold_restart_cmd);
18961 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18962 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18963 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18964 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18965 install_element(BGP_IPV6L_NODE,
18966 &neighbor_maximum_prefix_threshold_warning_cmd);
18967 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18968 install_element(BGP_IPV6L_NODE,
18969 &neighbor_maximum_prefix_threshold_restart_cmd);
18970 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18971 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18972 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18973 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18974 install_element(BGP_VPNV4_NODE,
18975 &neighbor_maximum_prefix_threshold_warning_cmd);
18976 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18977 install_element(BGP_VPNV4_NODE,
18978 &neighbor_maximum_prefix_threshold_restart_cmd);
18979 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18980 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18981 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18982 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18983 install_element(BGP_VPNV6_NODE,
18984 &neighbor_maximum_prefix_threshold_warning_cmd);
18985 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18986 install_element(BGP_VPNV6_NODE,
18987 &neighbor_maximum_prefix_threshold_restart_cmd);
18988 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18989
18990 /* "neighbor allowas-in" */
18991 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18992 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18993 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18994 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18995 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18996 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18997 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18998 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18999 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19000 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19001 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19002 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19003 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19004 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19005 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19006 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19007 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19008 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19009 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19010 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19011
19012 /* address-family commands. */
19013 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19014 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19015#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19016 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19017 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19018#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19019
d62a17ae 19020 install_element(BGP_NODE, &address_family_evpn_cmd);
19021
19022 /* "exit-address-family" command. */
19023 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19024 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19025 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19026 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19027 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19028 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19029 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19030 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19031 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19032 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19033 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19034
19035 /* "clear ip bgp commands" */
19036 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19037
19038 /* clear ip bgp prefix */
19039 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19040 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19041 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19042
19043 /* "show [ip] bgp summary" commands. */
19044 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19045 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19046 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19047 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19048 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19049 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19050 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19051
19052 /* "show [ip] bgp neighbors" commands. */
19053 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19054
36235319 19055 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19056
d62a17ae 19057 /* "show [ip] bgp peer-group" commands. */
19058 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19059
19060 /* "show [ip] bgp paths" commands. */
19061 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19062
19063 /* "show [ip] bgp community" commands. */
19064 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19065
19066 /* "show ip bgp large-community" commands. */
19067 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19068 /* "show [ip] bgp attribute-info" commands. */
19069 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19070 /* "show [ip] bgp route-leak" command */
19071 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19072
19073 /* "redistribute" commands. */
19074 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19075 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19076 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19077 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19078 install_element(BGP_NODE,
19079 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19080 install_element(BGP_NODE,
19081 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19082 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19083 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19084 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19085 install_element(BGP_NODE,
19086 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19087 install_element(BGP_NODE,
19088 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19089 install_element(BGP_NODE,
19090 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19091 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19092 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19093 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19094 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19095 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19096 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19097 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19098 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19099 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19100 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19101 install_element(BGP_IPV4_NODE,
19102 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19103 install_element(BGP_IPV4_NODE,
19104 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19105 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19106 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19107 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19108 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19109 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19110 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19111
b9c7bc5a
PZ
19112 /* import|export vpn [route-map WORD] */
19113 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19114 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19115
12a844a5
DS
19116 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19117 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19118
d62a17ae 19119 /* ttl_security commands */
19120 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19121 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19122
19123 /* "show [ip] bgp memory" commands. */
19124 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19125
acf71666
MK
19126 /* "show bgp martian next-hop" */
19127 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19128
48ecf8f5
DS
19129 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19130
d62a17ae 19131 /* "show [ip] bgp views" commands. */
19132 install_element(VIEW_NODE, &show_bgp_views_cmd);
19133
19134 /* "show [ip] bgp vrfs" commands. */
19135 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19136
19137 /* Community-list. */
19138 community_list_vty();
ddb5b488 19139
ed0e57e3
DA
19140 community_alias_vty();
19141
ddb5b488 19142 /* vpn-policy commands */
b9c7bc5a
PZ
19143 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19144 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19145 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19146 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19147 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19148 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19149 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19150 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19151 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19152 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19153 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19154 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19155
301ad80a
PG
19156 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19157 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19158
b9c7bc5a
PZ
19159 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19160 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19161 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19162 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19163 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19164 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19165 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19166 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19167 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19168 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19169
19170 /* tcp-mss command */
19171 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19172 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19173
19174 /* srv6 commands */
ea372e81 19175 install_element(VIEW_NODE, &show_bgp_srv6_cmd);
bfaab44d 19176 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
0249b8b6 19177 install_element(BGP_NODE, &no_bgp_segment_routing_srv6_cmd);
a0281b2e 19178 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
0249b8b6 19179 install_element(BGP_SRV6_NODE, &no_bgp_srv6_locator_cmd);
b72c9e14
HS
19180 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19181 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19182}
6b0655a2 19183
718e3744 19184#include "memory.h"
19185#include "bgp_regex.h"
19186#include "bgp_clist.h"
19187#include "bgp_ecommunity.h"
19188
19189/* VTY functions. */
19190
19191/* Direction value to string conversion. */
d62a17ae 19192static const char *community_direct_str(int direct)
19193{
19194 switch (direct) {
19195 case COMMUNITY_DENY:
19196 return "deny";
19197 case COMMUNITY_PERMIT:
19198 return "permit";
19199 default:
19200 return "unknown";
19201 }
718e3744 19202}
19203
19204/* Display error string. */
d62a17ae 19205static void community_list_perror(struct vty *vty, int ret)
19206{
19207 switch (ret) {
19208 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19209 vty_out(vty, "%% Can't find community-list\n");
19210 break;
19211 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19212 vty_out(vty, "%% Malformed community-list value\n");
19213 break;
19214 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19215 vty_out(vty,
19216 "%% Community name conflict, previously defined as standard community\n");
19217 break;
19218 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19219 vty_out(vty,
19220 "%% Community name conflict, previously defined as expanded community\n");
19221 break;
19222 }
718e3744 19223}
19224
5bf15956
DW
19225/* "community-list" keyword help string. */
19226#define COMMUNITY_LIST_STR "Add a community list entry\n"
19227
7336e101
SP
19228/*community-list standard */
19229DEFUN (community_list_standard,
19230 bgp_community_list_standard_cmd,
a2099c1d 19231 "bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19232 BGP_STR
718e3744 19233 COMMUNITY_LIST_STR
19234 "Community list number (standard)\n"
5bf15956 19235 "Add an standard community-list entry\n"
718e3744 19236 "Community list name\n"
2f8cc0e5
DA
19237 "Sequence number of an entry\n"
19238 "Sequence number\n"
718e3744 19239 "Specify community to reject\n"
19240 "Specify community to accept\n"
19241 COMMUNITY_VAL_STR)
19242{
d62a17ae 19243 char *cl_name_or_number = NULL;
2f8cc0e5 19244 char *seq = NULL;
d62a17ae 19245 int direct = 0;
19246 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19247 int idx = 0;
7336e101 19248
e34627f9 19249 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19250 seq = argv[idx]->arg;
19251
19252 idx = 0;
d62a17ae 19253 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19254 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19255 cl_name_or_number = argv[idx]->arg;
19256 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19257 : COMMUNITY_DENY;
19258 argv_find(argv, argc, "AA:NN", &idx);
19259 char *str = argv_concat(argv, argc, idx);
42f914d4 19260
2f8cc0e5
DA
19261 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19262 direct, style);
42f914d4 19263
d62a17ae 19264 XFREE(MTYPE_TMP, str);
42f914d4 19265
d62a17ae 19266 if (ret < 0) {
19267 /* Display error string. */
19268 community_list_perror(vty, ret);
19269 return CMD_WARNING_CONFIG_FAILED;
19270 }
42f914d4 19271
d62a17ae 19272 return CMD_SUCCESS;
718e3744 19273}
19274
7336e101
SP
19275DEFUN (no_community_list_standard_all,
19276 no_bgp_community_list_standard_all_cmd,
a2099c1d 19277 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19278 NO_STR
19279 BGP_STR
19280 COMMUNITY_LIST_STR
19281 "Community list number (standard)\n"
19282 "Add an standard community-list entry\n"
19283 "Community list name\n"
2f8cc0e5
DA
19284 "Sequence number of an entry\n"
19285 "Sequence number\n"
7336e101
SP
19286 "Specify community to reject\n"
19287 "Specify community to accept\n"
19288 COMMUNITY_VAL_STR)
718e3744 19289{
d62a17ae 19290 char *cl_name_or_number = NULL;
174b5cb9 19291 char *str = NULL;
d62a17ae 19292 int direct = 0;
19293 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19294 char *seq = NULL;
d62a17ae 19295 int idx = 0;
7336e101 19296
e34627f9 19297 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19298 seq = argv[idx]->arg;
19299
19300 idx = 0;
174b5cb9
DA
19301 argv_find(argv, argc, "permit", &idx);
19302 argv_find(argv, argc, "deny", &idx);
19303
19304 if (idx) {
19305 direct = argv_find(argv, argc, "permit", &idx)
19306 ? COMMUNITY_PERMIT
19307 : COMMUNITY_DENY;
19308
19309 idx = 0;
19310 argv_find(argv, argc, "AA:NN", &idx);
19311 str = argv_concat(argv, argc, idx);
19312 }
19313
19314 idx = 0;
d62a17ae 19315 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19316 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19317 cl_name_or_number = argv[idx]->arg;
42f914d4 19318
2f8cc0e5 19319 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19320 direct, style);
42f914d4 19321
d62a17ae 19322 XFREE(MTYPE_TMP, str);
daf9ddbb 19323
d62a17ae 19324 if (ret < 0) {
19325 community_list_perror(vty, ret);
19326 return CMD_WARNING_CONFIG_FAILED;
19327 }
42f914d4 19328
d62a17ae 19329 return CMD_SUCCESS;
718e3744 19330}
7336e101 19331
174b5cb9 19332ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
a2099c1d 19333 "no bgp community-list <(1-99)|standard COMMUNITY_LIST_NAME>",
174b5cb9
DA
19334 NO_STR BGP_STR COMMUNITY_LIST_STR
19335 "Community list number (standard)\n"
19336 "Add an standard community-list entry\n"
19337 "Community list name\n")
19338
7336e101
SP
19339/*community-list expanded */
19340DEFUN (community_list_expanded_all,
19341 bgp_community_list_expanded_all_cmd,
a2099c1d 19342 "bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19343 BGP_STR
19344 COMMUNITY_LIST_STR
718e3744 19345 "Community list number (expanded)\n"
5bf15956 19346 "Add an expanded community-list entry\n"
718e3744 19347 "Community list name\n"
2f8cc0e5
DA
19348 "Sequence number of an entry\n"
19349 "Sequence number\n"
718e3744 19350 "Specify community to reject\n"
19351 "Specify community to accept\n"
19352 COMMUNITY_VAL_STR)
19353{
d62a17ae 19354 char *cl_name_or_number = NULL;
2f8cc0e5 19355 char *seq = NULL;
d62a17ae 19356 int direct = 0;
19357 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19358 int idx = 0;
7b9a4750 19359
e34627f9 19360 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19361 seq = argv[idx]->arg;
19362
19363 idx = 0;
19364
d62a17ae 19365 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19366 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19367 cl_name_or_number = argv[idx]->arg;
19368 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19369 : COMMUNITY_DENY;
19370 argv_find(argv, argc, "AA:NN", &idx);
19371 char *str = argv_concat(argv, argc, idx);
42f914d4 19372
2f8cc0e5
DA
19373 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19374 direct, style);
42f914d4 19375
d62a17ae 19376 XFREE(MTYPE_TMP, str);
42f914d4 19377
d62a17ae 19378 if (ret < 0) {
19379 /* Display error string. */
19380 community_list_perror(vty, ret);
19381 return CMD_WARNING_CONFIG_FAILED;
19382 }
42f914d4 19383
d62a17ae 19384 return CMD_SUCCESS;
718e3744 19385}
19386
7336e101
SP
19387DEFUN (no_community_list_expanded_all,
19388 no_bgp_community_list_expanded_all_cmd,
a2099c1d 19389 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19390 NO_STR
19391 BGP_STR
19392 COMMUNITY_LIST_STR
19393 "Community list number (expanded)\n"
19394 "Add an expanded community-list entry\n"
19395 "Community list name\n"
2f8cc0e5
DA
19396 "Sequence number of an entry\n"
19397 "Sequence number\n"
7336e101
SP
19398 "Specify community to reject\n"
19399 "Specify community to accept\n"
19400 COMMUNITY_VAL_STR)
718e3744 19401{
d62a17ae 19402 char *cl_name_or_number = NULL;
2f8cc0e5 19403 char *seq = NULL;
174b5cb9 19404 char *str = NULL;
d62a17ae 19405 int direct = 0;
19406 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19407 int idx = 0;
174b5cb9 19408
e34627f9 19409 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19410 seq = argv[idx]->arg;
19411
19412 idx = 0;
174b5cb9
DA
19413 argv_find(argv, argc, "permit", &idx);
19414 argv_find(argv, argc, "deny", &idx);
19415
19416 if (idx) {
19417 direct = argv_find(argv, argc, "permit", &idx)
19418 ? COMMUNITY_PERMIT
19419 : COMMUNITY_DENY;
19420
19421 idx = 0;
19422 argv_find(argv, argc, "AA:NN", &idx);
19423 str = argv_concat(argv, argc, idx);
7336e101 19424 }
174b5cb9
DA
19425
19426 idx = 0;
d62a17ae 19427 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19428 argv_find(argv, argc, "COMMUNITY_LIST_NAME", &idx);
d62a17ae 19429 cl_name_or_number = argv[idx]->arg;
42f914d4 19430
2f8cc0e5 19431 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19432 direct, style);
42f914d4 19433
d62a17ae 19434 XFREE(MTYPE_TMP, str);
daf9ddbb 19435
d62a17ae 19436 if (ret < 0) {
19437 community_list_perror(vty, ret);
19438 return CMD_WARNING_CONFIG_FAILED;
19439 }
42f914d4 19440
d62a17ae 19441 return CMD_SUCCESS;
718e3744 19442}
19443
36d4bb44
EB
19444ALIAS(no_community_list_expanded_all,
19445 no_bgp_community_list_expanded_all_list_cmd,
a2099c1d 19446 "no bgp community-list <(100-500)|expanded COMMUNITY_LIST_NAME>",
36d4bb44 19447 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19448 "Community list number (expanded)\n"
19449 "Add an expanded community-list entry\n"
19450 "Community list name\n")
19451
8d9b8ed9
PM
19452/* Return configuration string of community-list entry. */
19453static const char *community_list_config_str(struct community_entry *entry)
19454{
19455 const char *str;
19456
19457 if (entry->any)
19458 str = "";
19459 else {
19460 if (entry->style == COMMUNITY_LIST_STANDARD)
c0945b78 19461 str = community_str(entry->u.com, false, false);
8d9b8ed9 19462 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
c0945b78 19463 str = lcommunity_str(entry->u.lcom, false, false);
8d9b8ed9
PM
19464 else
19465 str = entry->config;
19466 }
19467 return str;
19468}
19469
d62a17ae 19470static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19471{
d62a17ae 19472 struct community_entry *entry;
718e3744 19473
d62a17ae 19474 for (entry = list->head; entry; entry = entry->next) {
19475 if (entry == list->head) {
19476 if (all_digit(list->name))
19477 vty_out(vty, "Community %s list %s\n",
19478 entry->style == COMMUNITY_LIST_STANDARD
19479 ? "standard"
19480 : "(expanded) access",
19481 list->name);
19482 else
19483 vty_out(vty, "Named Community %s list %s\n",
19484 entry->style == COMMUNITY_LIST_STANDARD
19485 ? "standard"
19486 : "expanded",
19487 list->name);
19488 }
19489 if (entry->any)
19490 vty_out(vty, " %s\n",
19491 community_direct_str(entry->direct));
19492 else
19493 vty_out(vty, " %s %s\n",
19494 community_direct_str(entry->direct),
8d9b8ed9 19495 community_list_config_str(entry));
d62a17ae 19496 }
718e3744 19497}
19498
7336e101
SP
19499DEFUN (show_community_list,
19500 show_bgp_community_list_cmd,
19501 "show bgp community-list",
718e3744 19502 SHOW_STR
7336e101 19503 BGP_STR
718e3744 19504 "List community-list\n")
19505{
d62a17ae 19506 struct community_list *list;
19507 struct community_list_master *cm;
718e3744 19508
d62a17ae 19509 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19510 if (!cm)
19511 return CMD_SUCCESS;
718e3744 19512
d62a17ae 19513 for (list = cm->num.head; list; list = list->next)
19514 community_list_show(vty, list);
718e3744 19515
d62a17ae 19516 for (list = cm->str.head; list; list = list->next)
19517 community_list_show(vty, list);
718e3744 19518
d62a17ae 19519 return CMD_SUCCESS;
718e3744 19520}
19521
7336e101
SP
19522DEFUN (show_community_list_arg,
19523 show_bgp_community_list_arg_cmd,
a2099c1d 19524 "show bgp community-list <(1-500)|COMMUNITY_LIST_NAME> detail",
7336e101
SP
19525 SHOW_STR
19526 BGP_STR
718e3744 19527 "List community-list\n"
19528 "Community-list number\n"
960b69b9 19529 "Community-list name\n"
19530 "Detailed information on community-list\n")
718e3744 19531{
d62a17ae 19532 int idx_comm_list = 3;
19533 struct community_list *list;
718e3744 19534
e237b0d2 19535 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19536 COMMUNITY_LIST_MASTER);
19537 if (!list) {
19538 vty_out(vty, "%% Can't find community-list\n");
19539 return CMD_WARNING;
19540 }
718e3744 19541
d62a17ae 19542 community_list_show(vty, list);
718e3744 19543
d62a17ae 19544 return CMD_SUCCESS;
718e3744 19545}
6b0655a2 19546
57d187bc
JS
19547/*
19548 * Large Community code.
19549 */
d62a17ae 19550static int lcommunity_list_set_vty(struct vty *vty, int argc,
19551 struct cmd_token **argv, int style,
19552 int reject_all_digit_name)
19553{
19554 int ret;
19555 int direct;
19556 char *str;
19557 int idx = 0;
19558 char *cl_name;
2f8cc0e5
DA
19559 char *seq = NULL;
19560
a08032fe 19561 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19562 seq = argv[idx]->arg;
d62a17ae 19563
2f8cc0e5 19564 idx = 0;
d62a17ae 19565 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19566 : COMMUNITY_DENY;
19567
19568 /* All digit name check. */
19569 idx = 0;
a2099c1d 19570 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19571 argv_find(argv, argc, "(1-99)", &idx);
19572 argv_find(argv, argc, "(100-500)", &idx);
19573 cl_name = argv[idx]->arg;
19574 if (reject_all_digit_name && all_digit(cl_name)) {
19575 vty_out(vty, "%% Community name cannot have all digits\n");
19576 return CMD_WARNING_CONFIG_FAILED;
19577 }
19578
19579 idx = 0;
19580 argv_find(argv, argc, "AA:BB:CC", &idx);
19581 argv_find(argv, argc, "LINE", &idx);
19582 /* Concat community string argument. */
19583 if (idx)
19584 str = argv_concat(argv, argc, idx);
19585 else
19586 str = NULL;
19587
2f8cc0e5 19588 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19589
19590 /* Free temporary community list string allocated by
19591 argv_concat(). */
0a22ddfb 19592 XFREE(MTYPE_TMP, str);
d62a17ae 19593
19594 if (ret < 0) {
19595 community_list_perror(vty, ret);
19596 return CMD_WARNING_CONFIG_FAILED;
19597 }
19598 return CMD_SUCCESS;
19599}
19600
19601static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19602 struct cmd_token **argv, int style)
19603{
19604 int ret;
19605 int direct = 0;
19606 char *str = NULL;
19607 int idx = 0;
2f8cc0e5 19608 char *seq = NULL;
d62a17ae 19609
a08032fe 19610 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19611 seq = argv[idx]->arg;
d62a17ae 19612
2f8cc0e5 19613 idx = 0;
d62a17ae 19614 argv_find(argv, argc, "permit", &idx);
19615 argv_find(argv, argc, "deny", &idx);
19616
19617 if (idx) {
19618 /* Check the list direct. */
19619 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19620 direct = COMMUNITY_PERMIT;
19621 else
19622 direct = COMMUNITY_DENY;
19623
19624 idx = 0;
19625 argv_find(argv, argc, "LINE", &idx);
19626 argv_find(argv, argc, "AA:AA:NN", &idx);
19627 /* Concat community string argument. */
19628 str = argv_concat(argv, argc, idx);
19629 }
19630
19631 idx = 0;
19632 argv_find(argv, argc, "(1-99)", &idx);
19633 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19634 argv_find(argv, argc, "LCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19635
19636 /* Unset community list. */
2f8cc0e5 19637 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19638 style);
19639
19640 /* Free temporary community list string allocated by
19641 argv_concat(). */
0a22ddfb 19642 XFREE(MTYPE_TMP, str);
d62a17ae 19643
19644 if (ret < 0) {
19645 community_list_perror(vty, ret);
19646 return CMD_WARNING_CONFIG_FAILED;
19647 }
19648
19649 return CMD_SUCCESS;
57d187bc
JS
19650}
19651
19652/* "large-community-list" keyword help string. */
19653#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19654#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19655
7336e101
SP
19656DEFUN (lcommunity_list_standard,
19657 bgp_lcommunity_list_standard_cmd,
a08032fe 19658 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19659 BGP_STR
19660 LCOMMUNITY_LIST_STR
19661 "Large Community list number (standard)\n"
2f8cc0e5
DA
19662 "Sequence number of an entry\n"
19663 "Sequence number\n"
7336e101
SP
19664 "Specify large community to reject\n"
19665 "Specify large community to accept\n"
19666 LCOMMUNITY_VAL_STR)
52951b63 19667{
d62a17ae 19668 return lcommunity_list_set_vty(vty, argc, argv,
19669 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19670}
19671
7336e101
SP
19672DEFUN (lcommunity_list_expanded,
19673 bgp_lcommunity_list_expanded_cmd,
a08032fe 19674 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19675 BGP_STR
19676 LCOMMUNITY_LIST_STR
19677 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19678 "Sequence number of an entry\n"
19679 "Sequence number\n"
7336e101
SP
19680 "Specify large community to reject\n"
19681 "Specify large community to accept\n"
19682 "An ordered list as a regular-expression\n")
57d187bc 19683{
d62a17ae 19684 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19685 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19686}
19687
7336e101
SP
19688DEFUN (lcommunity_list_name_standard,
19689 bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19690 "bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19691 BGP_STR
19692 LCOMMUNITY_LIST_STR
19693 "Specify standard large-community-list\n"
19694 "Large Community list name\n"
2f8cc0e5
DA
19695 "Sequence number of an entry\n"
19696 "Sequence number\n"
7336e101
SP
19697 "Specify large community to reject\n"
19698 "Specify large community to accept\n"
19699 LCOMMUNITY_VAL_STR)
52951b63 19700{
d62a17ae 19701 return lcommunity_list_set_vty(vty, argc, argv,
19702 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19703}
19704
7336e101
SP
19705DEFUN (lcommunity_list_name_expanded,
19706 bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19707 "bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19708 BGP_STR
19709 LCOMMUNITY_LIST_STR
19710 "Specify expanded large-community-list\n"
19711 "Large Community list name\n"
2f8cc0e5
DA
19712 "Sequence number of an entry\n"
19713 "Sequence number\n"
7336e101
SP
19714 "Specify large community to reject\n"
19715 "Specify large community to accept\n"
19716 "An ordered list as a regular-expression\n")
57d187bc 19717{
d62a17ae 19718 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19719 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
19720}
19721
4378f57c
DA
19722DEFUN (no_lcommunity_list_all,
19723 no_bgp_lcommunity_list_all_cmd,
a2099c1d 19724 "no bgp large-community-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME>",
7336e101
SP
19725 NO_STR
19726 BGP_STR
19727 LCOMMUNITY_LIST_STR
19728 "Large Community list number (standard)\n"
19729 "Large Community list number (expanded)\n"
19730 "Large Community list name\n")
57d187bc 19731{
7336e101
SP
19732 return lcommunity_list_unset_vty(vty, argc, argv,
19733 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19734}
19735
4378f57c
DA
19736DEFUN (no_lcommunity_list_name_standard_all,
19737 no_bgp_lcommunity_list_name_standard_all_cmd,
a2099c1d 19738 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME",
4378f57c
DA
19739 NO_STR
19740 BGP_STR
19741 LCOMMUNITY_LIST_STR
19742 "Specify standard large-community-list\n"
19743 "Large Community list name\n")
19744{
19745 return lcommunity_list_unset_vty(vty, argc, argv,
19746 LARGE_COMMUNITY_LIST_STANDARD);
19747}
19748
7336e101
SP
19749DEFUN (no_lcommunity_list_name_expanded_all,
19750 no_bgp_lcommunity_list_name_expanded_all_cmd,
a2099c1d 19751 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME",
7336e101
SP
19752 NO_STR
19753 BGP_STR
19754 LCOMMUNITY_LIST_STR
19755 "Specify expanded large-community-list\n"
19756 "Large Community list name\n")
57d187bc 19757{
d62a17ae 19758 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19759 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19760}
19761
7336e101
SP
19762DEFUN (no_lcommunity_list_standard,
19763 no_bgp_lcommunity_list_standard_cmd,
a08032fe 19764 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19765 NO_STR
19766 BGP_STR
19767 LCOMMUNITY_LIST_STR
19768 "Large Community list number (standard)\n"
2f8cc0e5
DA
19769 "Sequence number of an entry\n"
19770 "Sequence number\n"
7336e101
SP
19771 "Specify large community to reject\n"
19772 "Specify large community to accept\n"
19773 LCOMMUNITY_VAL_STR)
57d187bc 19774{
d62a17ae 19775 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19776 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19777}
19778
7336e101
SP
19779DEFUN (no_lcommunity_list_expanded,
19780 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 19781 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19782 NO_STR
19783 BGP_STR
19784 LCOMMUNITY_LIST_STR
19785 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19786 "Sequence number of an entry\n"
19787 "Sequence number\n"
7336e101
SP
19788 "Specify large community to reject\n"
19789 "Specify large community to accept\n"
19790 "An ordered list as a regular-expression\n")
57d187bc 19791{
d62a17ae 19792 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19793 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19794}
19795
7336e101
SP
19796DEFUN (no_lcommunity_list_name_standard,
19797 no_bgp_lcommunity_list_name_standard_cmd,
a2099c1d 19798 "no bgp large-community-list standard LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
19799 NO_STR
19800 BGP_STR
19801 LCOMMUNITY_LIST_STR
19802 "Specify standard large-community-list\n"
19803 "Large Community list name\n"
2f8cc0e5
DA
19804 "Sequence number of an entry\n"
19805 "Sequence number\n"
7336e101
SP
19806 "Specify large community to reject\n"
19807 "Specify large community to accept\n"
19808 LCOMMUNITY_VAL_STR)
57d187bc 19809{
d62a17ae 19810 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19811 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
19812}
19813
7336e101
SP
19814DEFUN (no_lcommunity_list_name_expanded,
19815 no_bgp_lcommunity_list_name_expanded_cmd,
a2099c1d 19816 "no bgp large-community-list expanded LCOMMUNITY_LIST_NAME [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19817 NO_STR
19818 BGP_STR
19819 LCOMMUNITY_LIST_STR
19820 "Specify expanded large-community-list\n"
19821 "Large community list name\n"
2f8cc0e5
DA
19822 "Sequence number of an entry\n"
19823 "Sequence number\n"
7336e101
SP
19824 "Specify large community to reject\n"
19825 "Specify large community to accept\n"
19826 "An ordered list as a regular-expression\n")
57d187bc 19827{
d62a17ae 19828 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 19829 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
19830}
19831
d62a17ae 19832static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19833{
19834 struct community_entry *entry;
19835
19836 for (entry = list->head; entry; entry = entry->next) {
19837 if (entry == list->head) {
19838 if (all_digit(list->name))
19839 vty_out(vty, "Large community %s list %s\n",
169b72c8 19840 entry->style ==
19841 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19842 ? "standard"
19843 : "(expanded) access",
19844 list->name);
19845 else
19846 vty_out(vty,
19847 "Named large community %s list %s\n",
169b72c8 19848 entry->style ==
19849 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 19850 ? "standard"
19851 : "expanded",
19852 list->name);
19853 }
19854 if (entry->any)
19855 vty_out(vty, " %s\n",
19856 community_direct_str(entry->direct));
19857 else
19858 vty_out(vty, " %s %s\n",
19859 community_direct_str(entry->direct),
8d9b8ed9 19860 community_list_config_str(entry));
d62a17ae 19861 }
57d187bc
JS
19862}
19863
7336e101
SP
19864DEFUN (show_lcommunity_list,
19865 show_bgp_lcommunity_list_cmd,
19866 "show bgp large-community-list",
57d187bc 19867 SHOW_STR
7336e101 19868 BGP_STR
57d187bc
JS
19869 "List large-community list\n")
19870{
d62a17ae 19871 struct community_list *list;
19872 struct community_list_master *cm;
57d187bc 19873
d62a17ae 19874 cm = community_list_master_lookup(bgp_clist,
19875 LARGE_COMMUNITY_LIST_MASTER);
19876 if (!cm)
19877 return CMD_SUCCESS;
57d187bc 19878
d62a17ae 19879 for (list = cm->num.head; list; list = list->next)
19880 lcommunity_list_show(vty, list);
57d187bc 19881
d62a17ae 19882 for (list = cm->str.head; list; list = list->next)
19883 lcommunity_list_show(vty, list);
57d187bc 19884
d62a17ae 19885 return CMD_SUCCESS;
57d187bc
JS
19886}
19887
7336e101
SP
19888DEFUN (show_lcommunity_list_arg,
19889 show_bgp_lcommunity_list_arg_cmd,
a2099c1d 19890 "show bgp large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> detail",
7336e101
SP
19891 SHOW_STR
19892 BGP_STR
57d187bc 19893 "List large-community list\n"
960b69b9 19894 "Large-community-list number\n"
19895 "Large-community-list name\n"
19896 "Detailed information on large-community-list\n")
57d187bc 19897{
d62a17ae 19898 struct community_list *list;
57d187bc 19899
e237b0d2 19900 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 19901 LARGE_COMMUNITY_LIST_MASTER);
19902 if (!list) {
960b69b9 19903 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 19904 return CMD_WARNING;
19905 }
57d187bc 19906
d62a17ae 19907 lcommunity_list_show(vty, list);
57d187bc 19908
d62a17ae 19909 return CMD_SUCCESS;
57d187bc
JS
19910}
19911
718e3744 19912/* "extcommunity-list" keyword help string. */
19913#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19914#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19915
7336e101
SP
19916DEFUN (extcommunity_list_standard,
19917 bgp_extcommunity_list_standard_cmd,
a2099c1d 19918 "bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19919 BGP_STR
718e3744 19920 EXTCOMMUNITY_LIST_STR
19921 "Extended Community list number (standard)\n"
718e3744 19922 "Specify standard extcommunity-list\n"
5bf15956 19923 "Community list name\n"
2f8cc0e5
DA
19924 "Sequence number of an entry\n"
19925 "Sequence number\n"
718e3744 19926 "Specify community to reject\n"
19927 "Specify community to accept\n"
19928 EXTCOMMUNITY_VAL_STR)
19929{
d62a17ae 19930 int style = EXTCOMMUNITY_LIST_STANDARD;
19931 int direct = 0;
19932 char *cl_number_or_name = NULL;
2f8cc0e5 19933 char *seq = NULL;
42f914d4 19934
d62a17ae 19935 int idx = 0;
7b9a4750 19936
d62a17ae 19937 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 19938 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19939 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19940
a08032fe 19941 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19942 seq = argv[idx]->arg;
19943
d62a17ae 19944 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19945 : COMMUNITY_DENY;
19946 argv_find(argv, argc, "AA:NN", &idx);
19947 char *str = argv_concat(argv, argc, idx);
42f914d4 19948
2f8cc0e5 19949 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19950 direct, style);
42f914d4 19951
d62a17ae 19952 XFREE(MTYPE_TMP, str);
42f914d4 19953
d62a17ae 19954 if (ret < 0) {
19955 community_list_perror(vty, ret);
19956 return CMD_WARNING_CONFIG_FAILED;
19957 }
42f914d4 19958
d62a17ae 19959 return CMD_SUCCESS;
718e3744 19960}
19961
7336e101
SP
19962DEFUN (extcommunity_list_name_expanded,
19963 bgp_extcommunity_list_name_expanded_cmd,
a2099c1d 19964 "bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19965 BGP_STR
19966 EXTCOMMUNITY_LIST_STR
5bf15956 19967 "Extended Community list number (expanded)\n"
718e3744 19968 "Specify expanded extcommunity-list\n"
19969 "Extended Community list name\n"
2f8cc0e5
DA
19970 "Sequence number of an entry\n"
19971 "Sequence number\n"
718e3744 19972 "Specify community to reject\n"
19973 "Specify community to accept\n"
19974 "An ordered list as a regular-expression\n")
19975{
d62a17ae 19976 int style = EXTCOMMUNITY_LIST_EXPANDED;
19977 int direct = 0;
19978 char *cl_number_or_name = NULL;
2f8cc0e5 19979 char *seq = NULL;
d62a17ae 19980 int idx = 0;
7336e101 19981
d62a17ae 19982 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 19983 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 19984 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 19985
a08032fe 19986 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
19987 seq = argv[idx]->arg;
19988
d62a17ae 19989 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19990 : COMMUNITY_DENY;
19991 argv_find(argv, argc, "LINE", &idx);
19992 char *str = argv_concat(argv, argc, idx);
42f914d4 19993
2f8cc0e5 19994 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 19995 direct, style);
42f914d4 19996
d62a17ae 19997 XFREE(MTYPE_TMP, str);
42f914d4 19998
d62a17ae 19999 if (ret < 0) {
20000 community_list_perror(vty, ret);
20001 return CMD_WARNING_CONFIG_FAILED;
20002 }
42f914d4 20003
d62a17ae 20004 return CMD_SUCCESS;
718e3744 20005}
20006
7336e101
SP
20007DEFUN (no_extcommunity_list_standard_all,
20008 no_bgp_extcommunity_list_standard_all_cmd,
a2099c1d 20009 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20010 NO_STR
20011 BGP_STR
20012 EXTCOMMUNITY_LIST_STR
813d4307 20013 "Extended Community list number (standard)\n"
718e3744 20014 "Specify standard extcommunity-list\n"
5bf15956 20015 "Community list name\n"
2f8cc0e5
DA
20016 "Sequence number of an entry\n"
20017 "Sequence number\n"
718e3744 20018 "Specify community to reject\n"
20019 "Specify community to accept\n"
20020 EXTCOMMUNITY_VAL_STR)
20021{
d62a17ae 20022 int style = EXTCOMMUNITY_LIST_STANDARD;
20023 int direct = 0;
20024 char *cl_number_or_name = NULL;
d4455c89 20025 char *str = NULL;
2f8cc0e5 20026 char *seq = NULL;
d62a17ae 20027 int idx = 0;
d4455c89 20028
a08032fe 20029 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20030 seq = argv[idx]->arg;
20031
20032 idx = 0;
d4455c89
DA
20033 argv_find(argv, argc, "permit", &idx);
20034 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20035 if (idx) {
20036 direct = argv_find(argv, argc, "permit", &idx)
20037 ? COMMUNITY_PERMIT
20038 : COMMUNITY_DENY;
20039
20040 idx = 0;
20041 argv_find(argv, argc, "AA:NN", &idx);
20042 str = argv_concat(argv, argc, idx);
20043 }
20044
20045 idx = 0;
d62a17ae 20046 argv_find(argv, argc, "(1-99)", &idx);
a2099c1d 20047 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20048 cl_number_or_name = argv[idx]->arg;
42f914d4 20049
d62a17ae 20050 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20051 seq, direct, style);
42f914d4 20052
d62a17ae 20053 XFREE(MTYPE_TMP, str);
42f914d4 20054
d62a17ae 20055 if (ret < 0) {
20056 community_list_perror(vty, ret);
20057 return CMD_WARNING_CONFIG_FAILED;
20058 }
42f914d4 20059
d62a17ae 20060 return CMD_SUCCESS;
718e3744 20061}
20062
d4455c89
DA
20063ALIAS(no_extcommunity_list_standard_all,
20064 no_bgp_extcommunity_list_standard_all_list_cmd,
a2099c1d 20065 "no bgp extcommunity-list <(1-99)|standard EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20066 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20067 "Extended Community list number (standard)\n"
20068 "Specify standard extcommunity-list\n"
20069 "Community list name\n")
20070
7336e101
SP
20071DEFUN (no_extcommunity_list_expanded_all,
20072 no_bgp_extcommunity_list_expanded_all_cmd,
a2099c1d 20073 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20074 NO_STR
20075 BGP_STR
20076 EXTCOMMUNITY_LIST_STR
718e3744 20077 "Extended Community list number (expanded)\n"
718e3744 20078 "Specify expanded extcommunity-list\n"
5bf15956 20079 "Extended Community list name\n"
2f8cc0e5
DA
20080 "Sequence number of an entry\n"
20081 "Sequence number\n"
718e3744 20082 "Specify community to reject\n"
20083 "Specify community to accept\n"
20084 "An ordered list as a regular-expression\n")
20085{
d62a17ae 20086 int style = EXTCOMMUNITY_LIST_EXPANDED;
20087 int direct = 0;
20088 char *cl_number_or_name = NULL;
d4455c89 20089 char *str = NULL;
2f8cc0e5 20090 char *seq = NULL;
d62a17ae 20091 int idx = 0;
d4455c89 20092
a08032fe 20093 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20094 seq = argv[idx]->arg;
20095
20096 idx = 0;
d4455c89
DA
20097 argv_find(argv, argc, "permit", &idx);
20098 argv_find(argv, argc, "deny", &idx);
20099
20100 if (idx) {
20101 direct = argv_find(argv, argc, "permit", &idx)
20102 ? COMMUNITY_PERMIT
20103 : COMMUNITY_DENY;
20104
20105 idx = 0;
20106 argv_find(argv, argc, "LINE", &idx);
20107 str = argv_concat(argv, argc, idx);
20108 }
20109
20110 idx = 0;
d62a17ae 20111 argv_find(argv, argc, "(100-500)", &idx);
a2099c1d 20112 argv_find(argv, argc, "EXTCOMMUNITY_LIST_NAME", &idx);
d62a17ae 20113 cl_number_or_name = argv[idx]->arg;
42f914d4 20114
d62a17ae 20115 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20116 seq, direct, style);
42f914d4 20117
d62a17ae 20118 XFREE(MTYPE_TMP, str);
42f914d4 20119
d62a17ae 20120 if (ret < 0) {
20121 community_list_perror(vty, ret);
20122 return CMD_WARNING_CONFIG_FAILED;
20123 }
42f914d4 20124
d62a17ae 20125 return CMD_SUCCESS;
718e3744 20126}
20127
d4455c89
DA
20128ALIAS(no_extcommunity_list_expanded_all,
20129 no_bgp_extcommunity_list_expanded_all_list_cmd,
a2099c1d 20130 "no bgp extcommunity-list <(100-500)|expanded EXTCOMMUNITY_LIST_NAME>",
36d4bb44 20131 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20132 "Extended Community list number (expanded)\n"
20133 "Specify expanded extcommunity-list\n"
20134 "Extended Community list name\n")
20135
d62a17ae 20136static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20137{
d62a17ae 20138 struct community_entry *entry;
718e3744 20139
d62a17ae 20140 for (entry = list->head; entry; entry = entry->next) {
20141 if (entry == list->head) {
20142 if (all_digit(list->name))
20143 vty_out(vty, "Extended community %s list %s\n",
20144 entry->style == EXTCOMMUNITY_LIST_STANDARD
20145 ? "standard"
20146 : "(expanded) access",
20147 list->name);
20148 else
20149 vty_out(vty,
20150 "Named extended community %s list %s\n",
20151 entry->style == EXTCOMMUNITY_LIST_STANDARD
20152 ? "standard"
20153 : "expanded",
20154 list->name);
20155 }
20156 if (entry->any)
20157 vty_out(vty, " %s\n",
20158 community_direct_str(entry->direct));
20159 else
20160 vty_out(vty, " %s %s\n",
20161 community_direct_str(entry->direct),
8d9b8ed9 20162 community_list_config_str(entry));
d62a17ae 20163 }
718e3744 20164}
20165
7336e101
SP
20166DEFUN (show_extcommunity_list,
20167 show_bgp_extcommunity_list_cmd,
20168 "show bgp extcommunity-list",
718e3744 20169 SHOW_STR
7336e101 20170 BGP_STR
718e3744 20171 "List extended-community list\n")
20172{
d62a17ae 20173 struct community_list *list;
20174 struct community_list_master *cm;
718e3744 20175
d62a17ae 20176 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20177 if (!cm)
20178 return CMD_SUCCESS;
718e3744 20179
d62a17ae 20180 for (list = cm->num.head; list; list = list->next)
20181 extcommunity_list_show(vty, list);
718e3744 20182
d62a17ae 20183 for (list = cm->str.head; list; list = list->next)
20184 extcommunity_list_show(vty, list);
718e3744 20185
d62a17ae 20186 return CMD_SUCCESS;
718e3744 20187}
20188
7336e101
SP
20189DEFUN (show_extcommunity_list_arg,
20190 show_bgp_extcommunity_list_arg_cmd,
a2099c1d 20191 "show bgp extcommunity-list <(1-500)|EXTCOMMUNITY_LIST_NAME> detail",
7336e101
SP
20192 SHOW_STR
20193 BGP_STR
718e3744 20194 "List extended-community list\n"
20195 "Extcommunity-list number\n"
960b69b9 20196 "Extcommunity-list name\n"
20197 "Detailed information on extcommunity-list\n")
718e3744 20198{
d62a17ae 20199 int idx_comm_list = 3;
20200 struct community_list *list;
718e3744 20201
e237b0d2 20202 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20203 EXTCOMMUNITY_LIST_MASTER);
20204 if (!list) {
20205 vty_out(vty, "%% Can't find extcommunity-list\n");
20206 return CMD_WARNING;
20207 }
718e3744 20208
d62a17ae 20209 extcommunity_list_show(vty, list);
718e3744 20210
d62a17ae 20211 return CMD_SUCCESS;
718e3744 20212}
6b0655a2 20213
718e3744 20214/* Display community-list and extcommunity-list configuration. */
d62a17ae 20215static int community_list_config_write(struct vty *vty)
20216{
20217 struct community_list *list;
20218 struct community_entry *entry;
20219 struct community_list_master *cm;
20220 int write = 0;
20221
20222 /* Community-list. */
20223 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20224
20225 for (list = cm->num.head; list; list = list->next)
20226 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20227 vty_out(vty,
20228 "bgp community-list %s seq %" PRId64 " %s %s\n",
20229 list->name, entry->seq,
d62a17ae 20230 community_direct_str(entry->direct),
20231 community_list_config_str(entry));
20232 write++;
20233 }
20234 for (list = cm->str.head; list; list = list->next)
20235 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20236 vty_out(vty,
20237 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20238 entry->style == COMMUNITY_LIST_STANDARD
20239 ? "standard"
20240 : "expanded",
2f8cc0e5
DA
20241 list->name, entry->seq,
20242 community_direct_str(entry->direct),
d62a17ae 20243 community_list_config_str(entry));
20244 write++;
20245 }
20246
20247 /* Extcommunity-list. */
20248 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20249
20250 for (list = cm->num.head; list; list = list->next)
20251 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20252 vty_out(vty,
20253 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20254 list->name, entry->seq,
20255 community_direct_str(entry->direct),
d62a17ae 20256 community_list_config_str(entry));
20257 write++;
20258 }
20259 for (list = cm->str.head; list; list = list->next)
20260 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20261 vty_out(vty,
6cde4b45 20262 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20263 entry->style == EXTCOMMUNITY_LIST_STANDARD
20264 ? "standard"
20265 : "expanded",
2f8cc0e5
DA
20266 list->name, entry->seq,
20267 community_direct_str(entry->direct),
d62a17ae 20268 community_list_config_str(entry));
20269 write++;
20270 }
20271
20272
20273 /* lcommunity-list. */
20274 cm = community_list_master_lookup(bgp_clist,
20275 LARGE_COMMUNITY_LIST_MASTER);
20276
20277 for (list = cm->num.head; list; list = list->next)
20278 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20279 vty_out(vty,
6cde4b45 20280 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20281 list->name, entry->seq,
20282 community_direct_str(entry->direct),
d62a17ae 20283 community_list_config_str(entry));
20284 write++;
20285 }
20286 for (list = cm->str.head; list; list = list->next)
20287 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20288 vty_out(vty,
6cde4b45 20289 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20290
d62a17ae 20291 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20292 ? "standard"
20293 : "expanded",
2f8cc0e5 20294 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20295 community_list_config_str(entry));
20296 write++;
20297 }
20298
20299 return write;
20300}
20301
612c2c15 20302static int community_list_config_write(struct vty *vty);
d62a17ae 20303static struct cmd_node community_list_node = {
f4b8291f 20304 .name = "community list",
62b346ee
DL
20305 .node = COMMUNITY_LIST_NODE,
20306 .prompt = "",
612c2c15 20307 .config_write = community_list_config_write,
718e3744 20308};
20309
d62a17ae 20310static void community_list_vty(void)
20311{
612c2c15 20312 install_node(&community_list_node);
d62a17ae 20313
20314 /* Community-list. */
7336e101
SP
20315 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20316 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20317 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20318 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20319 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20320 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20321 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20322 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20323
20324 /* Extcommunity-list. */
7336e101
SP
20325 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20326 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20327 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20328 install_element(CONFIG_NODE,
20329 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20330 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20331 install_element(CONFIG_NODE,
20332 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20333 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20334 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20335
20336 /* Large Community List */
7336e101 20337 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20338 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20339 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20340 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20341 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20342 install_element(CONFIG_NODE,
20343 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20344 install_element(CONFIG_NODE,
20345 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20346 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20347 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20348 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20349 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20350 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20351 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
225096bc
DA
20352
20353 bgp_community_list_command_completion_setup();
5bf15956 20354}
ed0e57e3
DA
20355
20356static struct cmd_node community_alias_node = {
20357 .name = "community alias",
20358 .node = COMMUNITY_ALIAS_NODE,
20359 .prompt = "",
20360 .config_write = bgp_community_alias_write,
20361};
20362
20363void community_alias_vty(void)
20364{
20365 install_node(&community_alias_node);
20366
20367 /* Community-list. */
20368 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
b4ad2fae
DS
20369
20370 bgp_community_alias_command_completion_setup();
ed0e57e3 20371}