]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #7343 from ton31337/fix/prefix2str_to_pFX
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
5cb5f4d0 25#include "lib_errors.h"
ec0ab544 26#include "lib/zclient.h"
718e3744 27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
3b8b1855 34#include "memory.h"
1c0d8808 35#include "lib_vty.h"
4bf6a362 36#include "hash.h"
3f9c7369 37#include "queue.h"
039f3a34 38#include "filter.h"
5d5ba018 39#include "frrstr.h"
718e3744 40
41#include "bgpd/bgpd.h"
48ecf8f5 42#include "bgpd/bgp_attr_evpn.h"
4bf6a362 43#include "bgpd/bgp_advertise.h"
718e3744 44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
4bf6a362 47#include "bgpd/bgp_ecommunity.h"
57d187bc 48#include "bgpd/bgp_lcommunity.h"
4bf6a362 49#include "bgpd/bgp_damp.h"
718e3744 50#include "bgpd/bgp_debug.h"
14454c9f 51#include "bgpd/bgp_errors.h"
e0701b79 52#include "bgpd/bgp_fsm.h"
4bf6a362 53#include "bgpd/bgp_nexthop.h"
718e3744 54#include "bgpd/bgp_open.h"
4bf6a362 55#include "bgpd/bgp_regex.h"
718e3744 56#include "bgpd/bgp_route.h"
c016b6c7 57#include "bgpd/bgp_mplsvpn.h"
718e3744 58#include "bgpd/bgp_zebra.h"
fee0f4c6 59#include "bgpd/bgp_table.h"
94f2b392 60#include "bgpd/bgp_vty.h"
165b5fff 61#include "bgpd/bgp_mpath.h"
cb1faec9 62#include "bgpd/bgp_packet.h"
3f9c7369 63#include "bgpd/bgp_updgrp.h"
c43ed2e4 64#include "bgpd/bgp_bfd.h"
555e09d4 65#include "bgpd/bgp_io.h"
94c2f693 66#include "bgpd/bgp_evpn.h"
dd65f45e 67#include "bgpd/bgp_evpn_vty.h"
b5e140c8 68#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 69#include "bgpd/bgp_addpath.h"
48ecf8f5 70#include "bgpd/bgp_mac.h"
dd65f45e 71#include "bgpd/bgp_flowspec.h"
49e5a4a0 72#ifdef ENABLE_BGP_VNC
dd65f45e
DL
73#include "bgpd/rfapi/bgp_rfapi_cfg.h"
74#endif
75
ff8a8a7a
CS
76#include "northbound.h"
77#include "northbound_cli.h"
78#include "bgpd/bgp_nb.h"
79
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 },
5d5393b9
DL
88)
89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
5d5393b9 92)
aef999a2
DA
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96)
5d5393b9 97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
5d5393b9
DL
100)
101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
5d5393b9
DL
104)
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108)
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112)
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
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 },
121)
5d5393b9 122
dd65f45e
DL
123DEFINE_HOOK(bgp_inst_config_write,
124 (struct bgp *bgp, struct vty *vty),
125 (bgp, vty))
718e3744 126
36235319
QY
127#define GR_NO_OPER \
128 "The Graceful Restart No Operation was executed as cmd same as previous one."
129#define GR_INVALID \
130 "The Graceful Restart command used is not valid at this moment."
d62a17ae 131static struct peer_group *listen_range_exists(struct bgp *bgp,
132 struct prefix *range, int exact);
133
055679e9 134/* Show BGP peer's information. */
135enum show_type {
136 show_all,
137 show_peer,
138 show_ipv4_all,
139 show_ipv6_all,
140 show_ipv4_peer,
141 show_ipv6_peer
142};
143
36235319
QY
144static struct peer_group *listen_range_exists(struct bgp *bgp,
145 struct prefix *range, int exact);
2986cac2 146
36235319
QY
147static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
148 struct bgp *bgp,
149 bool use_json,
150 json_object *json);
2986cac2 151
36235319
QY
152static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
153 enum show_type type,
154 const char *ip_str,
155 afi_t afi, bool use_json);
2986cac2 156
d62a17ae 157static enum node_type bgp_node_type(afi_t afi, safi_t safi)
158{
159 switch (afi) {
160 case AFI_IP:
161 switch (safi) {
162 case SAFI_UNICAST:
163 return BGP_IPV4_NODE;
d62a17ae 164 case SAFI_MULTICAST:
165 return BGP_IPV4M_NODE;
d62a17ae 166 case SAFI_LABELED_UNICAST:
167 return BGP_IPV4L_NODE;
d62a17ae 168 case SAFI_MPLS_VPN:
169 return BGP_VPNV4_NODE;
7c40bf39 170 case SAFI_FLOWSPEC:
171 return BGP_FLOWSPECV4_NODE;
5c525538
RW
172 default:
173 /* not expected */
174 return BGP_IPV4_NODE;
d62a17ae 175 }
176 break;
177 case AFI_IP6:
178 switch (safi) {
179 case SAFI_UNICAST:
180 return BGP_IPV6_NODE;
d62a17ae 181 case SAFI_MULTICAST:
182 return BGP_IPV6M_NODE;
d62a17ae 183 case SAFI_LABELED_UNICAST:
184 return BGP_IPV6L_NODE;
d62a17ae 185 case SAFI_MPLS_VPN:
186 return BGP_VPNV6_NODE;
7c40bf39 187 case SAFI_FLOWSPEC:
188 return BGP_FLOWSPECV6_NODE;
5c525538
RW
189 default:
190 /* not expected */
191 return BGP_IPV4_NODE;
d62a17ae 192 }
193 break;
194 case AFI_L2VPN:
195 return BGP_EVPN_NODE;
b26f891d 196 case AFI_UNSPEC:
d62a17ae 197 case AFI_MAX:
198 // We should never be here but to clarify the switch statement..
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201
202 // Impossible to happen
203 return BGP_IPV4_NODE;
f51bae9c 204}
20eb8864 205
5cb5f4d0
DD
206static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
207{
208 if (afi == AFI_IP && safi == SAFI_UNICAST)
209 return "IPv4 Unicast";
210 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
211 return "IPv4 Multicast";
212 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
213 return "IPv4 Labeled Unicast";
214 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
215 return "IPv4 VPN";
216 else if (afi == AFI_IP && safi == SAFI_ENCAP)
217 return "IPv4 Encap";
218 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
219 return "IPv4 Flowspec";
220 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
221 return "IPv6 Unicast";
222 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
223 return "IPv6 Multicast";
224 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
225 return "IPv6 Labeled Unicast";
226 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
227 return "IPv6 VPN";
228 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
229 return "IPv6 Encap";
230 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
231 return "IPv6 Flowspec";
232 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
233 return "L2VPN EVPN";
8e5509b0 234 else
5cb5f4d0 235 return "Unknown";
5cb5f4d0
DD
236}
237
238/*
239 * Please note that we have intentionally camelCased
240 * the return strings here. So if you want
241 * to use this function, please ensure you
242 * are doing this within json output
243 */
244static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
245{
246 if (afi == AFI_IP && safi == SAFI_UNICAST)
247 return "ipv4Unicast";
248 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
249 return "ipv4Multicast";
250 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
251 return "ipv4LabeledUnicast";
252 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
253 return "ipv4Vpn";
254 else if (afi == AFI_IP && safi == SAFI_ENCAP)
255 return "ipv4Encap";
256 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
257 return "ipv4Flowspec";
258 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
259 return "ipv6Unicast";
260 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
261 return "ipv6Multicast";
262 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
263 return "ipv6LabeledUnicast";
264 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
265 return "ipv6Vpn";
266 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
267 return "ipv6Encap";
268 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
269 return "ipv6Flowspec";
270 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
271 return "l2VpnEvpn";
8e5509b0 272 else
5cb5f4d0 273 return "Unknown";
5cb5f4d0
DD
274}
275
718e3744 276/* Utility function to get address family from current node. */
d62a17ae 277afi_t bgp_node_afi(struct vty *vty)
278{
279 afi_t afi;
280 switch (vty->node) {
281 case BGP_IPV6_NODE:
282 case BGP_IPV6M_NODE:
283 case BGP_IPV6L_NODE:
284 case BGP_VPNV6_NODE:
7c40bf39 285 case BGP_FLOWSPECV6_NODE:
d62a17ae 286 afi = AFI_IP6;
287 break;
288 case BGP_EVPN_NODE:
289 afi = AFI_L2VPN;
290 break;
291 default:
292 afi = AFI_IP;
293 break;
294 }
295 return afi;
718e3744 296}
297
298/* Utility function to get subsequent address family from current
299 node. */
d62a17ae 300safi_t bgp_node_safi(struct vty *vty)
301{
302 safi_t safi;
303 switch (vty->node) {
304 case BGP_VPNV4_NODE:
305 case BGP_VPNV6_NODE:
306 safi = SAFI_MPLS_VPN;
307 break;
308 case BGP_IPV4M_NODE:
309 case BGP_IPV6M_NODE:
310 safi = SAFI_MULTICAST;
311 break;
312 case BGP_EVPN_NODE:
313 safi = SAFI_EVPN;
314 break;
315 case BGP_IPV4L_NODE:
316 case BGP_IPV6L_NODE:
317 safi = SAFI_LABELED_UNICAST;
318 break;
7c40bf39 319 case BGP_FLOWSPECV4_NODE:
320 case BGP_FLOWSPECV6_NODE:
321 safi = SAFI_FLOWSPEC;
322 break;
d62a17ae 323 default:
324 safi = SAFI_UNICAST;
325 break;
326 }
327 return safi;
718e3744 328}
329
55f91488
QY
330/**
331 * Converts an AFI in string form to afi_t
332 *
333 * @param afi string, one of
334 * - "ipv4"
335 * - "ipv6"
81cf0de5 336 * - "l2vpn"
55f91488
QY
337 * @return the corresponding afi_t
338 */
d62a17ae 339afi_t bgp_vty_afi_from_str(const char *afi_str)
340{
341 afi_t afi = AFI_MAX; /* unknown */
342 if (strmatch(afi_str, "ipv4"))
343 afi = AFI_IP;
344 else if (strmatch(afi_str, "ipv6"))
345 afi = AFI_IP6;
81cf0de5
CS
346 else if (strmatch(afi_str, "l2vpn"))
347 afi = AFI_L2VPN;
d62a17ae 348 return afi;
349}
350
351int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
352 afi_t *afi)
353{
354 int ret = 0;
355 if (argv_find(argv, argc, "ipv4", index)) {
356 ret = 1;
357 if (afi)
358 *afi = AFI_IP;
359 } else if (argv_find(argv, argc, "ipv6", index)) {
360 ret = 1;
361 if (afi)
362 *afi = AFI_IP6;
8688b3e7
DS
363 } else if (argv_find(argv, argc, "l2vpn", index)) {
364 ret = 1;
365 if (afi)
366 *afi = AFI_L2VPN;
d62a17ae 367 }
368 return ret;
46f296b4
LB
369}
370
375a2e67 371/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 372safi_t bgp_vty_safi_from_str(const char *safi_str)
373{
374 safi_t safi = SAFI_MAX; /* unknown */
375 if (strmatch(safi_str, "multicast"))
376 safi = SAFI_MULTICAST;
377 else if (strmatch(safi_str, "unicast"))
378 safi = SAFI_UNICAST;
379 else if (strmatch(safi_str, "vpn"))
380 safi = SAFI_MPLS_VPN;
81cf0de5
CS
381 else if (strmatch(safi_str, "evpn"))
382 safi = SAFI_EVPN;
d62a17ae 383 else if (strmatch(safi_str, "labeled-unicast"))
384 safi = SAFI_LABELED_UNICAST;
7c40bf39 385 else if (strmatch(safi_str, "flowspec"))
386 safi = SAFI_FLOWSPEC;
d62a17ae 387 return safi;
388}
389
390int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
391 safi_t *safi)
392{
393 int ret = 0;
394 if (argv_find(argv, argc, "unicast", index)) {
395 ret = 1;
396 if (safi)
397 *safi = SAFI_UNICAST;
398 } else if (argv_find(argv, argc, "multicast", index)) {
399 ret = 1;
400 if (safi)
401 *safi = SAFI_MULTICAST;
402 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
403 ret = 1;
404 if (safi)
405 *safi = SAFI_LABELED_UNICAST;
406 } else if (argv_find(argv, argc, "vpn", index)) {
407 ret = 1;
408 if (safi)
409 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
410 } else if (argv_find(argv, argc, "evpn", index)) {
411 ret = 1;
412 if (safi)
413 *safi = SAFI_EVPN;
7c40bf39 414 } else if (argv_find(argv, argc, "flowspec", index)) {
415 ret = 1;
416 if (safi)
417 *safi = SAFI_FLOWSPEC;
d62a17ae 418 }
419 return ret;
46f296b4
LB
420}
421
5d5393b9
DL
422int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
423 enum bgp_instance_type inst_type)
424{
425 int ret = bgp_get(bgp, as, name, inst_type);
426
427 if (ret == BGP_CREATED) {
428 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
429 DFLT_BGP_CONNECT_RETRY);
430
431 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 432 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 433 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 434 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
435 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
436 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 437 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 438 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 439 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 440 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
441 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
442 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
5d5393b9
DL
443
444 ret = BGP_SUCCESS;
445 }
446 return ret;
447}
448
7eeee51e 449/*
f212a857 450 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 451 *
f212a857
DS
452 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
453 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
454 * to appropriate values for the calling function. This is to allow the
455 * calling function to make decisions appropriate for the show command
456 * that is being parsed.
457 *
458 * The show commands are generally of the form:
d62a17ae 459 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
460 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
461 *
462 * Since we use argv_find if the show command in particular doesn't have:
463 * [ip]
18c57037 464 * [<view|vrf> VIEWVRFNAME]
375a2e67 465 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
466 * The command parsing should still be ok.
467 *
468 * vty -> The vty for the command so we can output some useful data in
469 * the event of a parse error in the vrf.
470 * argv -> The command tokens
471 * argc -> How many command tokens we have
d62a17ae 472 * idx -> The current place in the command, generally should be 0 for this
473 * function
7eeee51e
DS
474 * afi -> The parsed afi if it was included in the show command, returned here
475 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 476 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 477 * use_json -> json is configured or not
7eeee51e
DS
478 *
479 * The function returns the correct location in the parse tree for the
480 * last token found.
0e37c258
DS
481 *
482 * Returns 0 for failure to parse correctly, else the idx position of where
483 * it found the last token.
7eeee51e 484 */
d62a17ae 485int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
486 struct cmd_token **argv, int argc,
487 int *idx, afi_t *afi, safi_t *safi,
9f049418 488 struct bgp **bgp, bool use_json)
d62a17ae 489{
490 char *vrf_name = NULL;
491
492 assert(afi);
493 assert(safi);
494 assert(bgp);
495
496 if (argv_find(argv, argc, "ip", idx))
497 *afi = AFI_IP;
498
9a8bdf1c 499 if (argv_find(argv, argc, "view", idx))
d62a17ae 500 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
501 else if (argv_find(argv, argc, "vrf", idx)) {
502 vrf_name = argv[*idx + 1]->arg;
503 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
504 vrf_name = NULL;
505 }
506 if (vrf_name) {
d62a17ae 507 if (strmatch(vrf_name, "all"))
508 *bgp = NULL;
509 else {
510 *bgp = bgp_lookup_by_name(vrf_name);
511 if (!*bgp) {
52e5b8c4
SP
512 if (use_json) {
513 json_object *json = NULL;
514 json = json_object_new_object();
515 json_object_string_add(
516 json, "warning",
517 "View/Vrf is unknown");
518 vty_out(vty, "%s\n",
519 json_object_to_json_string_ext(json,
520 JSON_C_TO_STRING_PRETTY));
521 json_object_free(json);
522 }
ca61fd25
DS
523 else
524 vty_out(vty, "View/Vrf %s is unknown\n",
525 vrf_name);
d62a17ae 526 *idx = 0;
527 return 0;
528 }
529 }
530 } else {
531 *bgp = bgp_get_default();
532 if (!*bgp) {
52e5b8c4
SP
533 if (use_json) {
534 json_object *json = NULL;
535 json = json_object_new_object();
536 json_object_string_add(
537 json, "warning",
538 "Default BGP instance not found");
539 vty_out(vty, "%s\n",
540 json_object_to_json_string_ext(json,
541 JSON_C_TO_STRING_PRETTY));
542 json_object_free(json);
543 }
ca61fd25
DS
544 else
545 vty_out(vty,
546 "Default BGP instance not found\n");
d62a17ae 547 *idx = 0;
548 return 0;
549 }
550 }
551
552 if (argv_find_and_parse_afi(argv, argc, idx, afi))
553 argv_find_and_parse_safi(argv, argc, idx, safi);
554
555 *idx += 1;
556 return *idx;
557}
558
3dc339cd 559static bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 560{
561 struct interface *ifp = NULL;
562
563 if (su->sa.sa_family == AF_INET)
564 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
565 else if (su->sa.sa_family == AF_INET6)
566 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
567 su->sin6.sin6_scope_id,
568 bgp->vrf_id);
569
570 if (ifp)
3dc339cd 571 return true;
d62a17ae 572
3dc339cd 573 return false;
718e3744 574}
575
576/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
577/* This is used only for configuration, so disallow if attempted on
578 * a dynamic neighbor.
579 */
d62a17ae 580static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
581{
582 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
583 int ret;
584 union sockunion su;
585 struct peer *peer;
586
587 if (!bgp) {
588 return NULL;
589 }
590
591 ret = str2sockunion(ip_str, &su);
592 if (ret < 0) {
593 peer = peer_lookup_by_conf_if(bgp, ip_str);
594 if (!peer) {
595 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
596 == NULL) {
597 vty_out(vty,
598 "%% Malformed address or name: %s\n",
599 ip_str);
600 return NULL;
601 }
602 }
603 } else {
604 peer = peer_lookup(bgp, &su);
605 if (!peer) {
606 vty_out(vty,
607 "%% Specify remote-as or peer-group commands first\n");
608 return NULL;
609 }
610 if (peer_dynamic_neighbor(peer)) {
611 vty_out(vty,
612 "%% Operation not allowed on a dynamic neighbor\n");
613 return NULL;
614 }
615 }
616 return peer;
718e3744 617}
618
619/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
620/* This is used only for configuration, so disallow if attempted on
621 * a dynamic neighbor.
622 */
d62a17ae 623struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
624{
625 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
626 int ret;
627 union sockunion su;
628 struct peer *peer = NULL;
629 struct peer_group *group = NULL;
630
631 if (!bgp) {
632 return NULL;
633 }
634
635 ret = str2sockunion(peer_str, &su);
636 if (ret == 0) {
637 /* IP address, locate peer. */
638 peer = peer_lookup(bgp, &su);
639 } else {
640 /* Not IP, could match either peer configured on interface or a
641 * group. */
642 peer = peer_lookup_by_conf_if(bgp, peer_str);
643 if (!peer)
644 group = peer_group_lookup(bgp, peer_str);
645 }
646
647 if (peer) {
648 if (peer_dynamic_neighbor(peer)) {
649 vty_out(vty,
650 "%% Operation not allowed on a dynamic neighbor\n");
651 return NULL;
652 }
653
654 return peer;
655 }
656
657 if (group)
658 return group->conf;
659
660 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
661
662 return NULL;
663}
664
665int bgp_vty_return(struct vty *vty, int ret)
666{
667 const char *str = NULL;
668
669 switch (ret) {
670 case BGP_ERR_INVALID_VALUE:
671 str = "Invalid value";
672 break;
673 case BGP_ERR_INVALID_FLAG:
674 str = "Invalid flag";
675 break;
676 case BGP_ERR_PEER_GROUP_SHUTDOWN:
677 str = "Peer-group has been shutdown. Activate the peer-group first";
678 break;
679 case BGP_ERR_PEER_FLAG_CONFLICT:
680 str = "Can't set override-capability and strict-capability-match at the same time";
681 break;
682 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
683 str = "Specify remote-as or peer-group remote AS first";
684 break;
685 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
686 str = "Cannot change the peer-group. Deconfigure first";
687 break;
688 case BGP_ERR_PEER_GROUP_MISMATCH:
689 str = "Peer is not a member of this peer-group";
690 break;
691 case BGP_ERR_PEER_FILTER_CONFLICT:
692 str = "Prefix/distribute list can not co-exist";
693 break;
694 case BGP_ERR_NOT_INTERNAL_PEER:
695 str = "Invalid command. Not an internal neighbor";
696 break;
697 case BGP_ERR_REMOVE_PRIVATE_AS:
698 str = "remove-private-AS cannot be configured for IBGP peers";
699 break;
700 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
701 str = "Local-AS allowed only for EBGP peers";
702 break;
703 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
704 str = "Cannot have local-as same as BGP AS number";
705 break;
706 case BGP_ERR_TCPSIG_FAILED:
707 str = "Error while applying TCP-Sig to session(s)";
708 break;
709 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
710 str = "ebgp-multihop and ttl-security cannot be configured together";
711 break;
712 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
713 str = "ttl-security only allowed for EBGP peers";
714 break;
715 case BGP_ERR_AS_OVERRIDE:
716 str = "as-override cannot be configured for IBGP peers";
717 break;
718 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
719 str = "Invalid limit for number of dynamic neighbors";
720 break;
721 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
722 str = "Dynamic neighbor listen range already exists";
723 break;
724 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
725 str = "Operation not allowed on a dynamic neighbor";
726 break;
727 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
728 str = "Operation not allowed on a directly connected neighbor";
729 break;
730 case BGP_ERR_PEER_SAFI_CONFLICT:
055679e9 731 str = GR_INVALID;
732 break;
733 case BGP_ERR_GR_INVALID_CMD:
734 str = "The Graceful Restart command used is not valid at this moment.";
735 break;
736 case BGP_ERR_GR_OPERATION_FAILED:
737 str = "The Graceful Restart Operation failed due to an err.";
738 break;
739 case BGP_GR_NO_OPERATION:
740 str = GR_NO_OPER;
d62a17ae 741 break;
742 }
743 if (str) {
744 vty_out(vty, "%% %s\n", str);
745 return CMD_WARNING_CONFIG_FAILED;
746 }
747 return CMD_SUCCESS;
718e3744 748}
749
7aafcaca 750/* BGP clear sort. */
d62a17ae 751enum clear_sort {
752 clear_all,
753 clear_peer,
754 clear_group,
755 clear_external,
756 clear_as
7aafcaca
DS
757};
758
ff8a8a7a
CS
759static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
760 int error, char *errmsg, size_t errmsg_len)
d62a17ae 761{
762 switch (error) {
763 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
764 snprintf(errmsg, errmsg_len,
765 "%%BGP: Enable %s address family for the neighbor %s",
766 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 767 break;
768 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
769 snprintf(
770 errmsg, errmsg_len,
771 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 772 peer->host);
773 break;
774 default:
775 break;
776 }
7aafcaca
DS
777}
778
dc912615 779static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 780 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
781{
782 int ret = 0;
783
784 /* if afi/.safi not specified, spin thru all of them */
785 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
786 afi_t tmp_afi;
787 safi_t tmp_safi;
788
789 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
790 if (!peer->afc[tmp_afi][tmp_safi])
791 continue;
792
793 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 794 ret = peer_clear(peer, nnode);
dc912615
DS
795 else
796 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
797 stype);
798 }
799 /* if afi specified and safi not, spin thru safis on this afi */
800 } else if (safi == SAFI_UNSPEC) {
801 safi_t tmp_safi;
802
803 for (tmp_safi = SAFI_UNICAST;
804 tmp_safi < SAFI_MAX; tmp_safi++) {
805 if (!peer->afc[afi][tmp_safi])
806 continue;
807
808 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 809 ret = peer_clear(peer, nnode);
dc912615
DS
810 else
811 ret = peer_clear_soft(peer, afi,
812 tmp_safi, stype);
813 }
814 /* both afi/safi specified, let the caller know if not defined */
815 } else {
816 if (!peer->afc[afi][safi])
817 return 1;
818
819 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 820 ret = peer_clear(peer, nnode);
dc912615
DS
821 else
822 ret = peer_clear_soft(peer, afi, safi, stype);
823 }
824
825 return ret;
826}
827
7aafcaca 828/* `clear ip bgp' functions. */
ff8a8a7a 829static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 830 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 831 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 832{
dc912615 833 int ret = 0;
3ae8bfa5 834 bool found = false;
d62a17ae 835 struct peer *peer;
dc95985f 836
837 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 838
839 /* Clear all neighbors. */
840 /*
841 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
842 * nodes on the BGP instance as that may get freed if it is a
843 * doppelganger
d62a17ae 844 */
845 if (sort == clear_all) {
846 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 847
848 bgp_peer_gr_flags_update(peer);
849
36235319 850 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 851 gr_router_detected = true;
852
c368171c 853 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 854 stype);
d62a17ae 855
856 if (ret < 0)
ff8a8a7a
CS
857 bgp_clear_vty_error(peer, afi, safi, ret,
858 errmsg, errmsg_len);
dc95985f 859 }
860
36235319
QY
861 if (gr_router_detected
862 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 863 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
864 } else if (!gr_router_detected
865 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 866 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 867 }
d62a17ae 868
869 /* This is to apply read-only mode on this clear. */
870 if (stype == BGP_CLEAR_SOFT_NONE)
871 bgp->update_delay_over = 0;
872
873 return CMD_SUCCESS;
7aafcaca
DS
874 }
875
3ae8bfa5 876 /* Clear specified neighbor. */
d62a17ae 877 if (sort == clear_peer) {
878 union sockunion su;
d62a17ae 879
880 /* Make sockunion for lookup. */
881 ret = str2sockunion(arg, &su);
882 if (ret < 0) {
883 peer = peer_lookup_by_conf_if(bgp, arg);
884 if (!peer) {
885 peer = peer_lookup_by_hostname(bgp, arg);
886 if (!peer) {
ff8a8a7a
CS
887 snprintf(
888 errmsg, errmsg_len,
889 "Malformed address or name: %s",
d62a17ae 890 arg);
891 return CMD_WARNING;
892 }
893 }
894 } else {
895 peer = peer_lookup(bgp, &su);
896 if (!peer) {
ff8a8a7a
CS
897 snprintf(errmsg, errmsg_len,
898 "%%BGP: Unknown neighbor - \"%s\"",
899 arg);
d62a17ae 900 return CMD_WARNING;
901 }
902 }
7aafcaca 903
dc95985f 904 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
905 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
906
dc912615
DS
907 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
908
909 /* if afi/safi not defined for this peer, let caller know */
910 if (ret == 1)
3ae8bfa5 911 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 912
d62a17ae 913 if (ret < 0)
ff8a8a7a
CS
914 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
915 errmsg_len);
7aafcaca 916
d62a17ae 917 return CMD_SUCCESS;
7aafcaca 918 }
7aafcaca 919
3ae8bfa5 920 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 921 if (sort == clear_group) {
922 struct peer_group *group;
7aafcaca 923
d62a17ae 924 group = peer_group_lookup(bgp, arg);
925 if (!group) {
ff8a8a7a
CS
926 snprintf(errmsg, errmsg_len,
927 "%%BGP: No such peer-group %s", arg);
d62a17ae 928 return CMD_WARNING;
929 }
930
931 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 932 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 933
d62a17ae 934 if (ret < 0)
ff8a8a7a
CS
935 bgp_clear_vty_error(peer, afi, safi, ret,
936 errmsg, errmsg_len);
3ae8bfa5
PM
937 else
938 found = true;
d62a17ae 939 }
3ae8bfa5
PM
940
941 if (!found)
ff8a8a7a
CS
942 snprintf(
943 errmsg, errmsg_len,
944 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 945 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 946
d62a17ae 947 return CMD_SUCCESS;
7aafcaca 948 }
7aafcaca 949
3ae8bfa5 950 /* Clear all external (eBGP) neighbors. */
d62a17ae 951 if (sort == clear_external) {
952 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
953 if (peer->sort == BGP_PEER_IBGP)
954 continue;
7aafcaca 955
dc95985f 956 bgp_peer_gr_flags_update(peer);
957
36235319 958 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 959 gr_router_detected = true;
dc95985f 960
c368171c 961 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 962
d62a17ae 963 if (ret < 0)
ff8a8a7a
CS
964 bgp_clear_vty_error(peer, afi, safi, ret,
965 errmsg, errmsg_len);
3ae8bfa5
PM
966 else
967 found = true;
d62a17ae 968 }
3ae8bfa5 969
36235319
QY
970 if (gr_router_detected
971 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 972 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
973 } else if (!gr_router_detected
974 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 975 bgp_zebra_send_capabilities(bgp, true);
976 }
977
3ae8bfa5 978 if (!found)
ff8a8a7a
CS
979 snprintf(errmsg, errmsg_len,
980 "%%BGP: No external %s peer is configured",
981 get_afi_safi_str(afi, safi, false));
3ae8bfa5 982
d62a17ae 983 return CMD_SUCCESS;
984 }
985
3ae8bfa5 986 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 987 if (sort == clear_as) {
3ae8bfa5 988 as_t as = strtoul(arg, NULL, 10);
d62a17ae 989
990 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
991 if (peer->as != as)
992 continue;
993
dc95985f 994 bgp_peer_gr_flags_update(peer);
995
36235319 996 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 997 gr_router_detected = true;
dc95985f 998
c368171c 999 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1000
1001 if (ret < 0)
ff8a8a7a
CS
1002 bgp_clear_vty_error(peer, afi, safi, ret,
1003 errmsg, errmsg_len);
3ae8bfa5
PM
1004 else
1005 found = true;
d62a17ae 1006 }
3ae8bfa5 1007
36235319
QY
1008 if (gr_router_detected
1009 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1010 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1011 } else if (!gr_router_detected
1012 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1013 bgp_zebra_send_capabilities(bgp, true);
1014 }
1015
3ae8bfa5 1016 if (!found)
ff8a8a7a
CS
1017 snprintf(errmsg, errmsg_len,
1018 "%%BGP: No %s peer is configured with AS %s",
1019 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1020
d62a17ae 1021 return CMD_SUCCESS;
1022 }
1023
1024 return CMD_SUCCESS;
1025}
1026
ff8a8a7a
CS
1027static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1028 enum clear_sort sort, enum bgp_clear_type stype,
1029 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1030{
1031 struct bgp *bgp;
1032
1033 /* BGP structure lookup. */
1034 if (name) {
1035 bgp = bgp_lookup_by_name(name);
1036 if (bgp == NULL) {
ff8a8a7a
CS
1037 snprintf(errmsg, errmsg_len,
1038 "Can't find BGP instance %s", name);
d62a17ae 1039 return CMD_WARNING;
1040 }
1041 } else {
1042 bgp = bgp_get_default();
1043 if (bgp == NULL) {
ff8a8a7a
CS
1044 snprintf(errmsg, errmsg_len,
1045 "No BGP process is configured");
d62a17ae 1046 return CMD_WARNING;
1047 }
1048 }
1049
ff8a8a7a 1050 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1051}
1052
1053/* clear soft inbound */
ff8a8a7a 1054int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1055{
99b3ebd3
NS
1056 afi_t afi;
1057 safi_t safi;
ff8a8a7a
CS
1058 int ret;
1059
1060 FOREACH_AFI_SAFI (afi, safi) {
1061 ret = bgp_clear_vty(name, afi, safi, clear_all,
1062 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1063 errmsg_len);
1064 if (ret != CMD_SUCCESS)
1065 return -1;
1066 }
99b3ebd3 1067
ff8a8a7a 1068 return 0;
7aafcaca
DS
1069}
1070
1071/* clear soft outbound */
ff8a8a7a 1072int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1073{
99b3ebd3
NS
1074 afi_t afi;
1075 safi_t safi;
ff8a8a7a 1076 int ret;
99b3ebd3 1077
ff8a8a7a
CS
1078 FOREACH_AFI_SAFI (afi, safi) {
1079 ret = bgp_clear_vty(name, afi, safi, clear_all,
1080 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1081 errmsg_len);
1082 if (ret != CMD_SUCCESS)
1083 return -1;
1084 }
1085
1086 return 0;
7aafcaca
DS
1087}
1088
1089
f787d7a0 1090#ifndef VTYSH_EXTRACT_PL
2e4c2296 1091#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1092#endif
1093
8029b216
AK
1094DEFUN_HIDDEN (bgp_local_mac,
1095 bgp_local_mac_cmd,
093e3f23 1096 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1097 BGP_STR
1098 "Local MAC config\n"
1099 "VxLAN Network Identifier\n"
1100 "VNI number\n"
1101 "local mac\n"
1102 "mac address\n"
1103 "mac-mobility sequence\n"
1104 "seq number\n")
1105{
1106 int rv;
1107 vni_t vni;
1108 struct ethaddr mac;
1109 struct ipaddr ip;
1110 uint32_t seq;
1111 struct bgp *bgp;
1112
1113 vni = strtoul(argv[3]->arg, NULL, 10);
1114 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1115 vty_out(vty, "%% Malformed MAC address\n");
1116 return CMD_WARNING;
1117 }
1118 memset(&ip, 0, sizeof(ip));
1119 seq = strtoul(argv[7]->arg, NULL, 10);
1120
1121 bgp = bgp_get_default();
1122 if (!bgp) {
1123 vty_out(vty, "Default BGP instance is not there\n");
1124 return CMD_WARNING;
1125 }
1126
b5e140c8
AK
1127 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1128 zero_esi);
8029b216
AK
1129 if (rv < 0) {
1130 vty_out(vty, "Internal error\n");
1131 return CMD_WARNING;
1132 }
1133
1134 return CMD_SUCCESS;
1135}
1136
1137DEFUN_HIDDEN (no_bgp_local_mac,
1138 no_bgp_local_mac_cmd,
093e3f23 1139 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1140 NO_STR
1141 BGP_STR
1142 "Local MAC config\n"
1143 "VxLAN Network Identifier\n"
1144 "VNI number\n"
1145 "local mac\n"
1146 "mac address\n")
1147{
1148 int rv;
1149 vni_t vni;
1150 struct ethaddr mac;
1151 struct ipaddr ip;
1152 struct bgp *bgp;
1153
1154 vni = strtoul(argv[4]->arg, NULL, 10);
1155 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1156 vty_out(vty, "%% Malformed MAC address\n");
1157 return CMD_WARNING;
1158 }
1159 memset(&ip, 0, sizeof(ip));
1160
1161 bgp = bgp_get_default();
1162 if (!bgp) {
1163 vty_out(vty, "Default BGP instance is not there\n");
1164 return CMD_WARNING;
1165 }
1166
ec0ab544 1167 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1168 if (rv < 0) {
1169 vty_out(vty, "Internal error\n");
1170 return CMD_WARNING;
1171 }
1172
1173 return CMD_SUCCESS;
1174}
1175
718e3744 1176DEFUN (no_synchronization,
1177 no_synchronization_cmd,
1178 "no synchronization",
1179 NO_STR
1180 "Perform IGP synchronization\n")
1181{
d62a17ae 1182 return CMD_SUCCESS;
718e3744 1183}
1184
1185DEFUN (no_auto_summary,
1186 no_auto_summary_cmd,
1187 "no auto-summary",
1188 NO_STR
1189 "Enable automatic network number summarization\n")
1190{
d62a17ae 1191 return CMD_SUCCESS;
718e3744 1192}
3d515fd9 1193
718e3744 1194/* "router bgp" commands. */
ff8a8a7a
CS
1195DEFUN_YANG_NOSH(router_bgp,
1196 router_bgp_cmd,
1197 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1198 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1199{
d62a17ae 1200 int idx_asn = 2;
1201 int idx_view_vrf = 3;
1202 int idx_vrf = 4;
ff8a8a7a 1203 int ret = CMD_SUCCESS;
d62a17ae 1204 as_t as;
1205 struct bgp *bgp;
1206 const char *name = NULL;
ff8a8a7a 1207 char as_str[12] = {'\0'};
d62a17ae 1208 enum bgp_instance_type inst_type;
ff8a8a7a 1209 char base_xpath[XPATH_MAXLEN];
d62a17ae 1210
1211 // "router bgp" without an ASN
1212 if (argc == 2) {
1213 // Pending: Make VRF option available for ASN less config
1214 bgp = bgp_get_default();
1215
1216 if (bgp == NULL) {
1217 vty_out(vty, "%% No BGP process is configured\n");
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220
1221 if (listcount(bm->bgp) > 1) {
996c9314 1222 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1223 return CMD_WARNING_CONFIG_FAILED;
1224 }
ff8a8a7a
CS
1225
1226 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
5ce106b7 1227 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
ff8a8a7a
CS
1228
1229 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1230 snprintf(as_str, 12, "%d", bgp->as);
87ce2564
CS
1231 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1232 as_str);
ff8a8a7a 1233 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1234 nb_cli_enqueue_change(vty,
1235 "./global/instance-type-view",
ff8a8a7a
CS
1236 NB_OP_MODIFY, "true");
1237 }
1238
a5ab756f 1239 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1240 ret = nb_cli_apply_changes(vty, base_xpath);
1241 if (ret == CMD_SUCCESS) {
1242 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1243
1244 /*
1245 * For backward compatibility with old commands we still
1246 * need to use the qobj infrastructure.
1247 */
1248 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1249 }
1250 return ret;
d62a17ae 1251 }
1252
1253 // "router bgp X"
1254 else {
d62a17ae 1255
ff8a8a7a 1256 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1257 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1258 if (argc > 3) {
1259 name = argv[idx_vrf]->arg;
1260
9a8bdf1c
PG
1261 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1262 if (strmatch(name, VRF_DEFAULT_NAME))
1263 name = NULL;
1264 else
1265 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1266 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1267 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1268 }
d62a17ae 1269 }
ff8a8a7a
CS
1270 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1271 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1272
1273 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1274 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1275 argv[idx_asn]->arg);
1276 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1277 nb_cli_enqueue_change(vty,
1278 "./global/instance-type-view",
ff8a8a7a 1279 NB_OP_MODIFY, "true");
d62a17ae 1280 }
1281
ff8a8a7a
CS
1282 nb_cli_pending_commit_check(vty);
1283 ret = nb_cli_apply_changes(vty, base_xpath);
1284 if (ret == CMD_SUCCESS) {
1285 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1286
ff8a8a7a
CS
1287 /*
1288 * For backward compatibility with old commands we still
1289 * need to use the qobj infrastructure.
1290 */
1291 bgp = bgp_lookup(as, name);
1292 if (bgp)
1293 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1294 }
d62a17ae 1295 }
1296
ff8a8a7a 1297 return ret;
718e3744 1298}
1299
718e3744 1300/* "no router bgp" commands. */
ff8a8a7a
CS
1301DEFUN_YANG(no_router_bgp,
1302 no_router_bgp_cmd,
1303 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1304 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1305{
d62a17ae 1306 int idx_asn = 3;
1307 int idx_vrf = 5;
ff8a8a7a 1308 as_t as = 0;
d62a17ae 1309 struct bgp *bgp;
1310 const char *name = NULL;
ff8a8a7a 1311 char base_xpath[XPATH_MAXLEN];
4b63e358 1312 const struct lyd_node *bgp_glb_dnode;
718e3744 1313
d62a17ae 1314 // "no router bgp" without an ASN
1315 if (argc == 3) {
1316 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1317 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1318 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1319
4b63e358
CS
1320 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1321 base_xpath);
1322 if (!bgp_glb_dnode) {
d62a17ae 1323 vty_out(vty, "%% No BGP process is configured\n");
1324 return CMD_WARNING_CONFIG_FAILED;
1325 }
7fb21a9f 1326
d62a17ae 1327 if (listcount(bm->bgp) > 1) {
996c9314 1328 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1329 return CMD_WARNING_CONFIG_FAILED;
1330 }
0b5131c9 1331
4b63e358
CS
1332 /* tcli mode bgp would not be set until apply stage. */
1333 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1334 if (!bgp)
1335 return CMD_SUCCESS;
1336
0b5131c9
MK
1337 if (bgp->l3vni) {
1338 vty_out(vty, "%% Please unconfigure l3vni %u",
1339 bgp->l3vni);
1340 return CMD_WARNING_CONFIG_FAILED;
1341 }
d62a17ae 1342 } else {
1343 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 1344
d62a17ae 1345 if (argc > 4)
1346 name = argv[idx_vrf]->arg;
7fb21a9f 1347
d62a17ae 1348 /* Lookup bgp structure. */
1349 bgp = bgp_lookup(as, name);
1350 if (!bgp) {
1351 vty_out(vty, "%% Can't find BGP instance\n");
1352 return CMD_WARNING_CONFIG_FAILED;
1353 }
0b5131c9
MK
1354
1355 if (bgp->l3vni) {
dd5868c2 1356 vty_out(vty, "%% Please unconfigure l3vni %u\n",
0b5131c9
MK
1357 bgp->l3vni);
1358 return CMD_WARNING_CONFIG_FAILED;
1359 }
dd5868c2
DS
1360
1361 /* Cannot delete default instance if vrf instances exist */
1362 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1363 struct listnode *node;
1364 struct bgp *tmp_bgp;
1365
1366 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1367 if (tmp_bgp->inst_type
1368 == BGP_INSTANCE_TYPE_VRF) {
1369 vty_out(vty,
1370 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1371 return CMD_WARNING_CONFIG_FAILED;
1372 }
1373 }
1374 }
d62a17ae 1375 }
ff8a8a7a
CS
1376 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1377 "frr-bgp:bgp", "bgp",
1378 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
718e3744 1379
ff8a8a7a 1380 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1381
ff8a8a7a 1382 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1383}
1384
ff8a8a7a
CS
1385void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1386 bool show_defaults)
1387{
1388 const struct lyd_node *vrf_dnode;
1389 const char *vrf_name;
1390 as_t as;
6b0655a2 1391
ff8a8a7a
CS
1392 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1393 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1394 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1395
ff8a8a7a
CS
1396 vty_out(vty, "!\n");
1397 vty_out(vty, "router bgp %u", as);
1398 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1399 vty_out(vty, " vrf %s", vrf_name);
1400 vty_out(vty, "\n");
718e3744 1401}
1402
ff8a8a7a
CS
1403/* BGP router-id. */
1404
1405DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1406 BGP_STR
1407 "Override configured router identifier\n"
1408 "Manually configured router identifier\n")
718e3744 1409{
87ce2564
CS
1410 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1411 router_id_str);
718e3744 1412
ff8a8a7a
CS
1413 return nb_cli_apply_changes(vty, NULL);
1414}
718e3744 1415
ff8a8a7a
CS
1416DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1417 NO_STR BGP_STR
1418 "Override configured router identifier\n"
1419 "Manually configured router identifier\n")
1420{
87ce2564 1421 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1422 router_id_str ? router_id_str : NULL);
718e3744 1423
ff8a8a7a 1424 return nb_cli_apply_changes(vty, NULL);
718e3744 1425}
1426
ff8a8a7a
CS
1427void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1428 bool show_defaults)
1429{
1430 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1431}
6b0655a2 1432
718e3744 1433/* BGP Cluster ID. */
ff8a8a7a
CS
1434DEFUN_YANG(bgp_cluster_id,
1435 bgp_cluster_id_cmd,
1436 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1437 BGP_STR
1438 "Configure Route-Reflector Cluster-id\n"
1439 "Route-Reflector Cluster-id in IP address format\n"
1440 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1441{
d62a17ae 1442 int idx_ipv4 = 2;
718e3744 1443
87ce2564
CS
1444 nb_cli_enqueue_change(
1445 vty, "./global/route-reflector/route-reflector-cluster-id",
1446 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1447
ff8a8a7a 1448 return nb_cli_apply_changes(vty, NULL);
718e3744 1449}
1450
ff8a8a7a
CS
1451DEFUN_YANG(no_bgp_cluster_id,
1452 no_bgp_cluster_id_cmd,
1453 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1454 NO_STR BGP_STR
1455 "Configure Route-Reflector Cluster-id\n"
1456 "Route-Reflector Cluster-id in IP address format\n"
1457 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1458{
87ce2564
CS
1459 nb_cli_enqueue_change(
1460 vty, "./global/route-reflector/route-reflector-cluster-id",
1461 NB_OP_DESTROY, NULL);
718e3744 1462
ff8a8a7a 1463 return nb_cli_apply_changes(vty, NULL);
718e3744 1464}
1465
c163f297
DS
1466DEFPY (bgp_norib,
1467 bgp_norib_cmd,
1468 "bgp no-rib",
1469 BGP_STR
1470 "Disable BGP route installation to RIB (Zebra)\n")
1471{
1472 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1473 vty_out(vty,
1474 "%% No-RIB option is already set, nothing to do here.\n");
1475 return CMD_SUCCESS;
1476 }
1477
1478 bgp_option_norib_set_runtime();
1479
1480 return CMD_SUCCESS;
1481}
1482
1483DEFPY (no_bgp_norib,
1484 no_bgp_norib_cmd,
1485 "no bgp no-rib",
1486 NO_STR
1487 BGP_STR
1488 "Disable BGP route installation to RIB (Zebra)\n")
1489{
1490 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1491 vty_out(vty,
1492 "%% No-RIB option is not set, nothing to do here.\n");
1493 return CMD_SUCCESS;
1494 }
1495
1496 bgp_option_norib_unset_runtime();
1497
1498 return CMD_SUCCESS;
1499}
1500
ff8a8a7a
CS
1501DEFUN_YANG(bgp_confederation_identifier,
1502 bgp_confederation_identifier_cmd,
1503 "bgp confederation identifier (1-4294967295)",
1504 "BGP specific commands\n"
1505 "AS confederation parameters\n"
1506 "AS number\n"
1507 "Set routing domain confederation AS\n")
718e3744 1508{
d62a17ae 1509 int idx_number = 3;
718e3744 1510
87ce2564
CS
1511 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1512 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1513
ff8a8a7a 1514 return nb_cli_apply_changes(vty, NULL);
718e3744 1515}
1516
ff8a8a7a
CS
1517DEFUN_YANG(no_bgp_confederation_identifier,
1518 no_bgp_confederation_identifier_cmd,
1519 "no bgp confederation identifier [(1-4294967295)]",
1520 NO_STR
1521 "BGP specific commands\n"
1522 "AS confederation parameters\n"
1523 "AS number\n"
1524 "Set routing domain confederation AS\n")
718e3744 1525{
87ce2564
CS
1526 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1527 NB_OP_DESTROY, NULL);
718e3744 1528
ff8a8a7a 1529 return nb_cli_apply_changes(vty, NULL);
718e3744 1530}
1531
ff8a8a7a
CS
1532void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1533 struct lyd_node *dnode,
1534 bool show_defaults)
1535{
1536 vty_out(vty, " bgp confederation identifier %u\n",
1537 yang_dnode_get_uint32(dnode, NULL));
1538}
1539
1540DEFUN_YANG(bgp_confederation_peers,
1541 bgp_confederation_peers_cmd,
1542 "bgp confederation peers (1-4294967295)...",
1543 "BGP specific commands\n"
1544 "AS confederation parameters\n"
1545 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1546{
d62a17ae 1547 int idx_asn = 3;
d62a17ae 1548 int i;
718e3744 1549
ff8a8a7a 1550 for (i = idx_asn; i < argc; i++)
87ce2564 1551 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1552 NB_OP_CREATE, argv[i]->arg);
718e3744 1553
ff8a8a7a 1554 return nb_cli_apply_changes(vty, NULL);
718e3744 1555}
1556
ff8a8a7a
CS
1557DEFUN_YANG(no_bgp_confederation_peers,
1558 no_bgp_confederation_peers_cmd,
1559 "no bgp confederation peers (1-4294967295)...",
1560 NO_STR
1561 "BGP specific commands\n"
1562 "AS confederation parameters\n"
1563 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1564{
d62a17ae 1565 int idx_asn = 4;
d62a17ae 1566 int i;
718e3744 1567
ff8a8a7a 1568 for (i = idx_asn; i < argc; i++)
87ce2564 1569 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1570 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1571
ff8a8a7a
CS
1572 return nb_cli_apply_changes(vty, NULL);
1573}
1574
1575void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1576 struct lyd_node *dnode,
1577 bool show_defaults)
1578{
1579 vty_out(vty, " bgp confederation peers %u \n",
1580 yang_dnode_get_uint32(dnode, NULL));
718e3744 1581}
6b0655a2 1582
5e242b0d
DS
1583/**
1584 * Central routine for maximum-paths configuration.
1585 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1586 * @set: 1 for setting values, 0 for removing the max-paths config.
1587 */
d62a17ae 1588static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
d7c0a89a 1589 const char *mpaths, uint16_t options,
d62a17ae 1590 int set)
1591{
1592 VTY_DECLVAR_CONTEXT(bgp, bgp);
d7c0a89a 1593 uint16_t maxpaths = 0;
d62a17ae 1594 int ret;
1595 afi_t afi;
1596 safi_t safi;
1597
1598 afi = bgp_node_afi(vty);
1599 safi = bgp_node_safi(vty);
1600
1601 if (set) {
1602 maxpaths = strtol(mpaths, NULL, 10);
1603 if (maxpaths > multipath_num) {
1604 vty_out(vty,
1605 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1606 maxpaths, multipath_num);
1607 return CMD_WARNING_CONFIG_FAILED;
1608 }
1609 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1610 options);
1611 } else
1612 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1613
1614 if (ret < 0) {
1615 vty_out(vty,
1616 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1617 (set == 1) ? "" : "un",
1618 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1619 maxpaths, afi, safi);
1620 return CMD_WARNING_CONFIG_FAILED;
1621 }
1622
1623 bgp_recalculate_all_bestpaths(bgp);
1624
1625 return CMD_SUCCESS;
165b5fff
JB
1626}
1627
ff8a8a7a
CS
1628void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1629 bool show_defaults)
abc920f8 1630{
ff8a8a7a
CS
1631 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1632 uint32_t med_admin_val;
abc920f8 1633
ff8a8a7a
CS
1634 vty_out(vty, " bgp max-med administrative");
1635 if ((med_admin_val =
1636 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1637 != BGP_MAXMED_VALUE_DEFAULT)
1638 vty_out(vty, " %u", med_admin_val);
1639 vty_out(vty, "\n");
1640 }
abc920f8 1641
ff8a8a7a
CS
1642 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1643 uint32_t onstartup_val;
abc920f8 1644
ff8a8a7a
CS
1645 vty_out(vty, " bgp max-med on-startup %u",
1646 yang_dnode_get_uint32(dnode,
1647 "./max-med-onstart-up-time"));
1648 onstartup_val = yang_dnode_get_uint32(
1649 dnode, "./max-med-onstart-up-value");
1650 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1651 vty_out(vty, " %u", onstartup_val);
1652
1653 vty_out(vty, "\n");
1654 }
abc920f8
DS
1655}
1656
ff8a8a7a
CS
1657DEFUN_YANG(bgp_maxmed_admin,
1658 bgp_maxmed_admin_cmd,
1659 "bgp max-med administrative ",
1660 BGP_STR
1661 "Advertise routes with max-med\n"
1662 "Administratively applied, for an indefinite period\n")
1663{
87ce2564 1664 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1665 NB_OP_MODIFY, "true");
1666
1667 return nb_cli_apply_changes(vty, NULL);
1668}
1669
1670DEFUN_YANG(bgp_maxmed_admin_medv,
1671 bgp_maxmed_admin_medv_cmd,
1672 "bgp max-med administrative (0-4294967295)",
1673 BGP_STR
1674 "Advertise routes with max-med\n"
1675 "Administratively applied, for an indefinite period\n"
1676 "Max MED value to be used\n")
abc920f8 1677{
d62a17ae 1678 int idx_number = 3;
abc920f8 1679
87ce2564 1680 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1681 NB_OP_MODIFY, "true");
abc920f8 1682
87ce2564
CS
1683 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1684 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1685
ff8a8a7a 1686 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1687}
1688
ff8a8a7a
CS
1689DEFUN_YANG(no_bgp_maxmed_admin,
1690 no_bgp_maxmed_admin_cmd,
1691 "no bgp max-med administrative [(0-4294967295)]",
1692 NO_STR BGP_STR
1693 "Advertise routes with max-med\n"
1694 "Administratively applied, for an indefinite period\n"
1695 "Max MED value to be used\n")
abc920f8 1696{
87ce2564 1697 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1698 NB_OP_MODIFY, "false");
abc920f8 1699
87ce2564
CS
1700 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1701 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1702
1703 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1704}
1705
ff8a8a7a
CS
1706DEFUN_YANG(bgp_maxmed_onstartup,
1707 bgp_maxmed_onstartup_cmd,
1708 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1709 BGP_STR
1710 "Advertise routes with max-med\n"
1711 "Effective on a startup\n"
1712 "Time (seconds) period for max-med\n"
1713 "Max MED value to be used\n")
abc920f8 1714{
d62a17ae 1715 int idx = 0;
4668a151 1716
d62a17ae 1717 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1718 nb_cli_enqueue_change(vty,
1719 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1720 NB_OP_MODIFY, argv[idx]->arg);
1721
d62a17ae 1722 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1723 nb_cli_enqueue_change(
1724 vty, "./global/med-config/max-med-onstart-up-value",
1725 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1726 else
87ce2564
CS
1727 nb_cli_enqueue_change(
1728 vty, "./global/med-config/max-med-onstart-up-value",
1729 NB_OP_MODIFY, NULL);
abc920f8 1730
ff8a8a7a 1731 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1732}
1733
ff8a8a7a
CS
1734DEFUN_YANG(no_bgp_maxmed_onstartup,
1735 no_bgp_maxmed_onstartup_cmd,
1736 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1737 NO_STR BGP_STR
1738 "Advertise routes with max-med\n"
1739 "Effective on a startup\n"
1740 "Time (seconds) period for max-med\n"
1741 "Max MED value to be used\n")
abc920f8 1742{
87ce2564
CS
1743 nb_cli_enqueue_change(vty,
1744 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1745 NB_OP_DESTROY, NULL);
abc920f8 1746
87ce2564
CS
1747 nb_cli_enqueue_change(vty,
1748 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1749 NB_OP_MODIFY, NULL);
abc920f8 1750
ff8a8a7a 1751 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1752}
1753
d70583f7
D
1754static int bgp_global_update_delay_config_vty(struct vty *vty,
1755 uint16_t update_delay,
1756 uint16_t establish_wait)
1757{
1758 struct listnode *node, *nnode;
1759 struct bgp *bgp;
1760 bool vrf_cfg = false;
1761
1762 /*
1763 * See if update-delay is set per-vrf and warn user to delete it
1764 * Note that we only need to check this if this is the first time
1765 * setting the global config.
1766 */
1767 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1768 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1769 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1770 vty_out(vty,
1771 "%% update-delay configuration found in vrf %s\n",
1772 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1773 ? VRF_DEFAULT_NAME
1774 : bgp->name);
1775 vrf_cfg = true;
1776 }
1777 }
1778 }
1779
1780 if (vrf_cfg) {
1781 vty_out(vty,
1782 "%%Failed: global update-delay config not permitted\n");
1783 return CMD_WARNING;
1784 }
1785
1786 if (!establish_wait) { /* update-delay <delay> */
1787 bm->v_update_delay = update_delay;
1788 bm->v_establish_wait = bm->v_update_delay;
1789 } else {
1790 /* update-delay <delay> <establish-wait> */
1791 if (update_delay < establish_wait) {
1792 vty_out(vty,
1793 "%%Failed: update-delay less than the establish-wait!\n");
1794 return CMD_WARNING_CONFIG_FAILED;
1795 }
1796
1797 bm->v_update_delay = update_delay;
1798 bm->v_establish_wait = establish_wait;
1799 }
1800
1801 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1802 bgp->v_update_delay = bm->v_update_delay;
1803 bgp->v_establish_wait = bm->v_establish_wait;
1804 }
1805
1806 return CMD_SUCCESS;
1807}
1808
1809static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1810{
1811 struct listnode *node, *nnode;
1812 struct bgp *bgp;
1813
1814 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1815 bm->v_establish_wait = bm->v_update_delay;
1816
1817 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1818 bgp->v_update_delay = bm->v_update_delay;
1819 bgp->v_establish_wait = bm->v_establish_wait;
1820 }
1821
1822 return CMD_SUCCESS;
1823}
1824
1825static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1826 uint16_t establish_wait)
f188f2c4 1827{
d62a17ae 1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1829
d70583f7
D
1830 /* if configured globally, per-instance config is not allowed */
1831 if (bm->v_update_delay) {
1832 vty_out(vty,
1833 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1834 return CMD_WARNING_CONFIG_FAILED;
1835 }
1836
f188f2c4 1837
d70583f7 1838 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1839 {
1840 bgp->v_update_delay = update_delay;
1841 bgp->v_establish_wait = bgp->v_update_delay;
1842 return CMD_SUCCESS;
1843 }
f188f2c4 1844
d62a17ae 1845 /* update-delay <delay> <establish-wait> */
d62a17ae 1846 if (update_delay < establish_wait) {
1847 vty_out(vty,
1848 "%%Failed: update-delay less than the establish-wait!\n");
1849 return CMD_WARNING_CONFIG_FAILED;
1850 }
f188f2c4 1851
d62a17ae 1852 bgp->v_update_delay = update_delay;
1853 bgp->v_establish_wait = establish_wait;
f188f2c4 1854
d62a17ae 1855 return CMD_SUCCESS;
f188f2c4
DS
1856}
1857
d62a17ae 1858static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1859{
d62a17ae 1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1861
d70583f7
D
1862 /* If configured globally, cannot remove from one bgp instance */
1863 if (bm->v_update_delay) {
1864 vty_out(vty,
1865 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
1866 return CMD_WARNING_CONFIG_FAILED;
1867 }
d62a17ae 1868 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1869 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1870
d62a17ae 1871 return CMD_SUCCESS;
f188f2c4
DS
1872}
1873
2b791107 1874void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1875{
d70583f7
D
1876 /* If configured globally, no need to display per-instance value */
1877 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 1878 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1879 if (bgp->v_update_delay != bgp->v_establish_wait)
1880 vty_out(vty, " %d", bgp->v_establish_wait);
1881 vty_out(vty, "\n");
1882 }
f188f2c4
DS
1883}
1884
d70583f7
D
1885/* Global update-delay configuration */
1886DEFPY (bgp_global_update_delay,
1887 bgp_global_update_delay_cmd,
1888 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
1889 BGP_STR
1890 "Force initial delay for best-path and updates for all bgp instances\n"
1891 "Max delay in seconds\n"
1892 "Establish wait in seconds\n")
1893{
1894 return bgp_global_update_delay_config_vty(vty, delay, wait);
1895}
f188f2c4 1896
d70583f7
D
1897/* Global update-delay deconfiguration */
1898DEFPY (no_bgp_global_update_delay,
1899 no_bgp_global_update_delay_cmd,
1900 "no bgp update-delay [(0-3600) [(1-3600)]]",
1901 NO_STR
1902 BGP_STR
f188f2c4 1903 "Force initial delay for best-path and updates\n"
d70583f7
D
1904 "Max delay in seconds\n"
1905 "Establish wait in seconds\n")
f188f2c4 1906{
d70583f7 1907 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
1908}
1909
d70583f7
D
1910/* Update-delay configuration */
1911
1912DEFPY (bgp_update_delay,
1913 bgp_update_delay_cmd,
1914 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 1915 "Force initial delay for best-path and updates\n"
d70583f7
D
1916 "Max delay in seconds\n"
1917 "Establish wait in seconds\n")
f188f2c4 1918{
d70583f7 1919 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
1920}
1921
1922/* Update-delay deconfiguration */
d70583f7 1923DEFPY (no_bgp_update_delay,
f188f2c4 1924 no_bgp_update_delay_cmd,
838758ac
DW
1925 "no update-delay [(0-3600) [(1-3600)]]",
1926 NO_STR
f188f2c4 1927 "Force initial delay for best-path and updates\n"
d70583f7
D
1928 "Max delay in seconds\n"
1929 "Establish wait in seconds\n")
f188f2c4 1930{
d62a17ae 1931 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1932}
1933
5e242b0d 1934
ff8a8a7a 1935int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 1936{
8fa7732f
QY
1937 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
1938 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
1939
1940 return CMD_SUCCESS;
1941}
1942
ff8a8a7a 1943int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 1944{
8fa7732f
QY
1945 quanta = set ? quanta : BGP_READ_PACKET_MAX;
1946 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 1947
d62a17ae 1948 return CMD_SUCCESS;
cb1faec9
DS
1949}
1950
2b791107 1951void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1952{
555e09d4
QY
1953 uint32_t quanta =
1954 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1955 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1956 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1957}
1958
555e09d4
QY
1959void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1960{
1961 uint32_t quanta =
1962 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1963 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1964 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1965}
cb1faec9 1966
8fa7732f
QY
1967/* Packet quanta configuration
1968 *
1969 * XXX: The value set here controls the size of a stack buffer in the IO
1970 * thread. When changing these limits be careful to prevent stack overflow.
1971 *
1972 * Furthermore, the maximums used here should correspond to
1973 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
1974 */
ff8a8a7a
CS
1975DEFPY_YANG(bgp_wpkt_quanta,
1976 bgp_wpkt_quanta_cmd,
1977 "[no] write-quanta (1-64)$quanta",
1978 NO_STR
1979 "How many packets to write to peer socket per run\n"
1980 "Number of packets\n")
1981{
1982 if (!no)
1983 nb_cli_enqueue_change(
1984 vty,
87ce2564 1985 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
1986 NB_OP_MODIFY, quanta_str);
1987 else
1988 nb_cli_enqueue_change(
1989 vty,
87ce2564 1990 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
1991 NB_OP_MODIFY, NULL);
1992
1993 return nb_cli_apply_changes(vty, NULL);
1994}
1995
1996DEFPY_YANG(bgp_rpkt_quanta,
1997 bgp_rpkt_quanta_cmd,
1998 "[no] read-quanta (1-10)$quanta",
1999 NO_STR
2000 "How many packets to read from peer socket per I/O cycle\n"
2001 "Number of packets\n")
2002{
2003 if (!no)
2004 nb_cli_enqueue_change(
2005 vty,
87ce2564 2006 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2007 NB_OP_MODIFY, quanta_str);
2008 else
2009 nb_cli_enqueue_change(
2010 vty,
87ce2564 2011 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2012 NB_OP_MODIFY, NULL);
cb1faec9 2013
ff8a8a7a 2014 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2015}
2016
2b791107 2017void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2018{
37a333fe 2019 if (!bgp->heuristic_coalesce)
d62a17ae 2020 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2021}
2022
ff8a8a7a
CS
2023void cli_show_router_global_update_group_config_coalesce_time(
2024 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2025{
ff8a8a7a
CS
2026 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2027}
2028
4668a151 2029
ff8a8a7a
CS
2030DEFUN_YANG(bgp_coalesce_time,
2031 bgp_coalesce_time_cmd,
2032 "coalesce-time (0-4294967295)",
2033 "Subgroup coalesce timer\n"
2034 "Subgroup coalesce timer value (in ms)\n")
2035{
d62a17ae 2036 int idx = 0;
ff8a8a7a 2037
d62a17ae 2038 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2039 nb_cli_enqueue_change(
2040 vty, "./global/global-update-group-config/coalesce-time",
2041 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2042
2043 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2044}
2045
ff8a8a7a
CS
2046DEFUN_YANG(no_bgp_coalesce_time,
2047 no_bgp_coalesce_time_cmd,
2048 "no coalesce-time (0-4294967295)",
2049 NO_STR
2050 "Subgroup coalesce timer\n"
2051 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2052{
87ce2564
CS
2053 nb_cli_enqueue_change(
2054 vty, "./global/global-update-group-config/coalesce-time",
2055 NB_OP_MODIFY, NULL);
4668a151 2056
ff8a8a7a 2057 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2058}
2059
5e242b0d
DS
2060/* Maximum-paths configuration */
2061DEFUN (bgp_maxpaths,
2062 bgp_maxpaths_cmd,
6319fd63 2063 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
2064 "Forward packets over multiple paths\n"
2065 "Number of paths\n")
2066{
d62a17ae 2067 int idx_number = 1;
2068 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
2069 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
2070}
2071
d62a17ae 2072ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2073 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2074 "Forward packets over multiple paths\n"
2075 "Number of paths\n")
596c17ba 2076
165b5fff
JB
2077DEFUN (bgp_maxpaths_ibgp,
2078 bgp_maxpaths_ibgp_cmd,
6319fd63 2079 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
2080 "Forward packets over multiple paths\n"
2081 "iBGP-multipath\n"
2082 "Number of paths\n")
2083{
d62a17ae 2084 int idx_number = 2;
2085 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
2086 argv[idx_number]->arg, 0, 1);
5e242b0d 2087}
165b5fff 2088
d62a17ae 2089ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2090 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2091 "Forward packets over multiple paths\n"
2092 "iBGP-multipath\n"
2093 "Number of paths\n")
596c17ba 2094
5e242b0d
DS
2095DEFUN (bgp_maxpaths_ibgp_cluster,
2096 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 2097 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
2098 "Forward packets over multiple paths\n"
2099 "iBGP-multipath\n"
2100 "Number of paths\n"
2101 "Match the cluster length\n")
2102{
d62a17ae 2103 int idx_number = 2;
2104 return bgp_maxpaths_config_vty(
2105 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
2106 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
2107}
2108
d62a17ae 2109ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2110 "maximum-paths ibgp " CMD_RANGE_STR(
2111 1, MULTIPATH_NUM) " equal-cluster-length",
2112 "Forward packets over multiple paths\n"
2113 "iBGP-multipath\n"
2114 "Number of paths\n"
2115 "Match the cluster length\n")
596c17ba 2116
165b5fff
JB
2117DEFUN (no_bgp_maxpaths,
2118 no_bgp_maxpaths_cmd,
6319fd63 2119 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
2120 NO_STR
2121 "Forward packets over multiple paths\n"
2122 "Number of paths\n")
2123{
d62a17ae 2124 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
2125}
2126
d62a17ae 2127ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2128 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2129 "Forward packets over multiple paths\n"
2130 "Number of paths\n")
596c17ba 2131
165b5fff
JB
2132DEFUN (no_bgp_maxpaths_ibgp,
2133 no_bgp_maxpaths_ibgp_cmd,
6319fd63 2134 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
2135 NO_STR
2136 "Forward packets over multiple paths\n"
2137 "iBGP-multipath\n"
838758ac
DW
2138 "Number of paths\n"
2139 "Match the cluster length\n")
165b5fff 2140{
d62a17ae 2141 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
2142}
2143
d62a17ae 2144ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2145 "no maximum-paths ibgp [" CMD_RANGE_STR(
2146 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2147 NO_STR
2148 "Forward packets over multiple paths\n"
2149 "iBGP-multipath\n"
2150 "Number of paths\n"
2151 "Match the cluster length\n")
596c17ba 2152
dd65f45e
DL
2153static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2154 afi_t afi, safi_t safi)
165b5fff 2155{
d62a17ae 2156 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 2157 vty_out(vty, " maximum-paths %d\n",
2158 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2159 }
165b5fff 2160
d62a17ae 2161 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 2162 vty_out(vty, " maximum-paths ibgp %d",
2163 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2164 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2165 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2166 vty_out(vty, " equal-cluster-length");
2167 vty_out(vty, "\n");
2168 }
165b5fff 2169}
6b0655a2 2170
718e3744 2171/* BGP timers. */
2172
ff8a8a7a
CS
2173DEFUN_YANG(bgp_timers,
2174 bgp_timers_cmd,
2175 "timers bgp (0-65535) (0-65535)",
2176 "Adjust routing timers\n"
2177 "BGP timers\n"
2178 "Keepalive interval\n"
2179 "Holdtime\n")
718e3744 2180{
d62a17ae 2181 int idx_number = 2;
2182 int idx_number_2 = 3;
718e3744 2183
87ce2564 2184 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2185 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2186 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2187 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2188
ff8a8a7a
CS
2189 return nb_cli_apply_changes(vty, NULL);
2190}
718e3744 2191
ff8a8a7a
CS
2192DEFUN_YANG(no_bgp_timers,
2193 no_bgp_timers_cmd,
2194 "no timers bgp [(0-65535) (0-65535)]",
2195 NO_STR
2196 "Adjust routing timers\n"
2197 "BGP timers\n"
2198 "Keepalive interval\n"
2199 "Holdtime\n")
2200{
87ce2564 2201 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2202 NB_OP_DESTROY, NULL);
87ce2564 2203 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2204 NB_OP_DESTROY, NULL);
718e3744 2205
ff8a8a7a 2206 return nb_cli_apply_changes(vty, NULL);
718e3744 2207}
2208
ff8a8a7a
CS
2209void cli_show_router_bgp_route_reflector(struct vty *vty,
2210 struct lyd_node *dnode,
2211 bool show_defaults)
718e3744 2212{
ff8a8a7a
CS
2213 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2214 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2215
ff8a8a7a
CS
2216 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2217 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2218
2219 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2220 vty_out(vty, " bgp cluster-id %s\n",
2221 yang_dnode_get_string(dnode,
2222 "./route-reflector-cluster-id"));
718e3744 2223}
2224
ff8a8a7a
CS
2225DEFUN_YANG(bgp_client_to_client_reflection,
2226 bgp_client_to_client_reflection_cmd,
2227 "bgp client-to-client reflection",
2228 "BGP specific commands\n"
2229 "Configure client to client route reflection\n"
2230 "reflection of routes allowed\n")
2231{
87ce2564 2232 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2233 NB_OP_MODIFY, "false");
6b0655a2 2234
ff8a8a7a
CS
2235 return nb_cli_apply_changes(vty, NULL);
2236}
2237
2238DEFUN_YANG(no_bgp_client_to_client_reflection,
2239 no_bgp_client_to_client_reflection_cmd,
2240 "no bgp client-to-client reflection",
2241 NO_STR
2242 "BGP specific commands\n"
2243 "Configure client to client route reflection\n"
2244 "reflection of routes allowed\n")
718e3744 2245{
87ce2564 2246 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2247 NB_OP_MODIFY, "true");
7aafcaca 2248
ff8a8a7a 2249 return nb_cli_apply_changes(vty, NULL);
718e3744 2250}
2251
ff8a8a7a
CS
2252void cli_show_router_bgp_route_selection(struct vty *vty,
2253 struct lyd_node *dnode,
2254 bool show_defaults)
718e3744 2255{
7aafcaca 2256
ff8a8a7a
CS
2257 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2258 vty_out(vty, " bgp always-compare-med\n");
2259
2260 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2261 vty_out(vty, " bgp bestpath as-path ignore\n");
2262
2263 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2264 vty_out(vty, " bgp bestpath as-path confed\n");
2265
2266 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2267 vty_out(vty, " bgp bestpath compare-routerid\n");
2268
2269 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2270 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2271 vty_out(vty,
2272 " bgp bestpath as-path multipath-relax as-set\n");
2273 else
2274 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2275 }
2276
2277 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2278 vty_out(vty, " bgp deterministic-med\n");
2279
2280 if (yang_dnode_get_bool(dnode, "./confed-med")
2281 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2282 vty_out(vty, " bgp bestpath med");
2283 if (yang_dnode_get_bool(dnode, "./confed-med"))
2284 vty_out(vty, " confed");
2285 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2286 vty_out(vty, " missing-as-worst");
2287 vty_out(vty, "\n");
2288 }
718e3744 2289}
2290
2291/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2292DEFUN_YANG(bgp_always_compare_med,
2293 bgp_always_compare_med_cmd,
2294 "bgp always-compare-med",
2295 "BGP specific commands\n"
2296 "Allow comparing MED from different neighbors\n")
718e3744 2297{
87ce2564
CS
2298 nb_cli_enqueue_change(
2299 vty, "./global/route-selection-options/always-compare-med",
2300 NB_OP_MODIFY, "true");
7aafcaca 2301
ff8a8a7a 2302 return nb_cli_apply_changes(vty, NULL);
718e3744 2303}
2304
ff8a8a7a
CS
2305DEFUN_YANG(no_bgp_always_compare_med,
2306 no_bgp_always_compare_med_cmd,
2307 "no bgp always-compare-med",
2308 NO_STR
2309 "BGP specific commands\n"
2310 "Allow comparing MED from different neighbors\n")
718e3744 2311{
87ce2564
CS
2312 nb_cli_enqueue_change(
2313 vty, "./global/route-selection-options/always-compare-med",
2314 NB_OP_MODIFY, "false");
7aafcaca 2315
ff8a8a7a 2316 return nb_cli_apply_changes(vty, NULL);
718e3744 2317}
6b0655a2 2318
ff8a8a7a
CS
2319DEFUN_YANG(bgp_ebgp_requires_policy,
2320 bgp_ebgp_requires_policy_cmd,
2321 "bgp ebgp-requires-policy",
2322 "BGP specific commands\n"
2323 "Require in and out policy for eBGP peers (RFC8212)\n")
2324{
87ce2564
CS
2325 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2326 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2327 return nb_cli_apply_changes(vty, NULL);
2328}
9dac9fc8 2329
ff8a8a7a
CS
2330DEFUN_YANG(no_bgp_ebgp_requires_policy,
2331 no_bgp_ebgp_requires_policy_cmd,
2332 "no bgp ebgp-requires-policy",
2333 NO_STR
2334 "BGP specific commands\n"
2335 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2336{
87ce2564
CS
2337 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2338 NB_OP_MODIFY, "false");
ff8a8a7a 2339 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2340}
2341
ff8a8a7a
CS
2342void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2343 struct lyd_node *dnode,
2344 bool show_defaults)
9dac9fc8 2345{
ff8a8a7a
CS
2346 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2347 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2348}
2349
fb29348a
DA
2350DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2351 "bgp reject-as-sets",
2352 "BGP specific commands\n"
2353 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2354{
2355 VTY_DECLVAR_CONTEXT(bgp, bgp);
2356 struct listnode *node, *nnode;
2357 struct peer *peer;
2358
7f972cd8 2359 bgp->reject_as_sets = true;
fb29348a
DA
2360
2361 /* Reset existing BGP sessions to reject routes
2362 * with aspath containing AS_SET or AS_CONFED_SET.
2363 */
2364 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2365 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2366 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2367 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2368 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2369 }
2370 }
2371
2372 return CMD_SUCCESS;
2373}
2374
2375DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2376 "no bgp reject-as-sets",
2377 NO_STR
2378 "BGP specific commands\n"
2379 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2380{
2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382 struct listnode *node, *nnode;
2383 struct peer *peer;
2384
7f972cd8 2385 bgp->reject_as_sets = false;
fb29348a
DA
2386
2387 /* Reset existing BGP sessions to reject routes
2388 * with aspath containing AS_SET or AS_CONFED_SET.
2389 */
2390 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2391 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2392 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2393 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2394 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2395 }
2396 }
2397
2398 return CMD_SUCCESS;
2399}
9dac9fc8 2400
718e3744 2401/* "bgp deterministic-med" configuration. */
ff8a8a7a 2402DEFUN_YANG (bgp_deterministic_med,
718e3744 2403 bgp_deterministic_med_cmd,
2404 "bgp deterministic-med",
2405 "BGP specific commands\n"
2406 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2407{
87ce2564
CS
2408 nb_cli_enqueue_change(
2409 vty, "./global/route-selection-options/deterministic-med",
2410 NB_OP_MODIFY, "true");
7aafcaca 2411
ff8a8a7a 2412 return nb_cli_apply_changes(vty, NULL);
718e3744 2413}
2414
ff8a8a7a 2415DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2416 no_bgp_deterministic_med_cmd,
2417 "no bgp deterministic-med",
2418 NO_STR
2419 "BGP specific commands\n"
2420 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2421{
87ce2564
CS
2422 nb_cli_enqueue_change(
2423 vty, "./global/route-selection-options/deterministic-med",
2424 NB_OP_MODIFY, "false");
d62a17ae 2425
ff8a8a7a 2426 return nb_cli_apply_changes(vty, NULL);
718e3744 2427}
538621f2 2428
055679e9 2429/* "bgp graceful-restart mode" configuration. */
538621f2 2430DEFUN (bgp_graceful_restart,
2ba1fe69 2431 bgp_graceful_restart_cmd,
2432 "bgp graceful-restart",
2433 "BGP specific commands\n"
2434 GR_CMD
055679e9 2435 )
538621f2 2436{
055679e9 2437 int ret = BGP_GR_FAILURE;
2438
2439 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2440 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2441
d62a17ae 2442 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2443
2444 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2445
36235319
QY
2446 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2447 ret);
5cce3f05 2448
055679e9 2449 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2450 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2451 vty_out(vty,
2452 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2453 return bgp_vty_return(vty, ret);
538621f2 2454}
2455
2456DEFUN (no_bgp_graceful_restart,
2ba1fe69 2457 no_bgp_graceful_restart_cmd,
2458 "no bgp graceful-restart",
2459 NO_STR
2460 "BGP specific commands\n"
2461 NO_GR_CMD
055679e9 2462 )
538621f2 2463{
d62a17ae 2464 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2465
2466 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2467 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2468
2469 int ret = BGP_GR_FAILURE;
2470
2471 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2472
36235319
QY
2473 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2474 ret);
5cce3f05 2475
055679e9 2476 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2477 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2478 vty_out(vty,
2479 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2480
2481 return bgp_vty_return(vty, ret);
538621f2 2482}
2483
93406d87 2484DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2485 bgp_graceful_restart_stalepath_time_cmd,
2486 "bgp graceful-restart stalepath-time (1-4095)",
2487 "BGP specific commands\n"
2488 "Graceful restart capability parameters\n"
2489 "Set the max time to hold onto restarting peer's stale paths\n"
2490 "Delay value (seconds)\n")
93406d87 2491{
d62a17ae 2492 VTY_DECLVAR_CONTEXT(bgp, bgp);
2493 int idx_number = 3;
d7c0a89a 2494 uint32_t stalepath;
93406d87 2495
d62a17ae 2496 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2497 bgp->stalepath_time = stalepath;
2498 return CMD_SUCCESS;
93406d87 2499}
2500
eb6f1b41 2501DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2502 bgp_graceful_restart_restart_time_cmd,
2503 "bgp graceful-restart restart-time (1-4095)",
2504 "BGP specific commands\n"
2505 "Graceful restart capability parameters\n"
2506 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2507 "Delay value (seconds)\n")
eb6f1b41 2508{
d62a17ae 2509 VTY_DECLVAR_CONTEXT(bgp, bgp);
2510 int idx_number = 3;
d7c0a89a 2511 uint32_t restart;
eb6f1b41 2512
d62a17ae 2513 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2514 bgp->restart_time = restart;
2515 return CMD_SUCCESS;
eb6f1b41
PG
2516}
2517
cfd47646 2518DEFUN (bgp_graceful_restart_select_defer_time,
2519 bgp_graceful_restart_select_defer_time_cmd,
2520 "bgp graceful-restart select-defer-time (0-3600)",
2521 "BGP specific commands\n"
2522 "Graceful restart capability parameters\n"
2523 "Set the time to defer the BGP route selection after restart\n"
2524 "Delay value (seconds, 0 - disable)\n")
2525{
2526 VTY_DECLVAR_CONTEXT(bgp, bgp);
2527 int idx_number = 3;
2528 uint32_t defer_time;
2529
2530 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2531 bgp->select_defer_time = defer_time;
2532 if (defer_time == 0)
892fedb6 2533 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2534 else
892fedb6 2535 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2536
2537 return CMD_SUCCESS;
2538}
2539
93406d87 2540DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2541 no_bgp_graceful_restart_stalepath_time_cmd,
2542 "no bgp graceful-restart stalepath-time [(1-4095)]",
2543 NO_STR
2544 "BGP specific commands\n"
2545 "Graceful restart capability parameters\n"
2546 "Set the max time to hold onto restarting peer's stale paths\n"
2547 "Delay value (seconds)\n")
93406d87 2548{
d62a17ae 2549 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2550
d62a17ae 2551 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2552 return CMD_SUCCESS;
93406d87 2553}
2554
eb6f1b41 2555DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2556 no_bgp_graceful_restart_restart_time_cmd,
2557 "no bgp graceful-restart restart-time [(1-4095)]",
2558 NO_STR
2559 "BGP specific commands\n"
2560 "Graceful restart capability parameters\n"
2561 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2562 "Delay value (seconds)\n")
eb6f1b41 2563{
d62a17ae 2564 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2565
d62a17ae 2566 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2567 return CMD_SUCCESS;
eb6f1b41
PG
2568}
2569
cfd47646 2570DEFUN (no_bgp_graceful_restart_select_defer_time,
2571 no_bgp_graceful_restart_select_defer_time_cmd,
2572 "no bgp graceful-restart select-defer-time [(0-3600)]",
2573 NO_STR
2574 "BGP specific commands\n"
2575 "Graceful restart capability parameters\n"
2576 "Set the time to defer the BGP route selection after restart\n"
2577 "Delay value (seconds)\n")
2578{
2579 VTY_DECLVAR_CONTEXT(bgp, bgp);
2580
2581 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2582 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2583
2584 return CMD_SUCCESS;
2585}
2586
43fc21b3 2587DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2588 bgp_graceful_restart_preserve_fw_cmd,
2589 "bgp graceful-restart preserve-fw-state",
2590 "BGP specific commands\n"
2591 "Graceful restart capability parameters\n"
2592 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2593{
d62a17ae 2594 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2595 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2596 return CMD_SUCCESS;
43fc21b3
JC
2597}
2598
2599DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2600 no_bgp_graceful_restart_preserve_fw_cmd,
2601 "no bgp graceful-restart preserve-fw-state",
2602 NO_STR
2603 "BGP specific commands\n"
2604 "Graceful restart capability parameters\n"
2605 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2606{
d62a17ae 2607 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2608 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2609 return CMD_SUCCESS;
43fc21b3
JC
2610}
2611
055679e9 2612DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2613 bgp_graceful_restart_disable_cmd,
2614 "bgp graceful-restart-disable",
2615 "BGP specific commands\n"
2616 GR_DISABLE)
055679e9 2617{
2618 int ret = BGP_GR_FAILURE;
2619
2620 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2621 zlog_debug(
2ba1fe69 2622 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2623
055679e9 2624 VTY_DECLVAR_CONTEXT(bgp, bgp);
2625
2626 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2627
dc95985f 2628 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2629 bgp->peer, ret);
5cce3f05 2630
055679e9 2631 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2632 zlog_debug(
2ba1fe69 2633 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2634 vty_out(vty,
2635 "Graceful restart configuration changed, reset all peers to take effect\n");
2636
055679e9 2637 return bgp_vty_return(vty, ret);
2638}
2639
2640DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2641 no_bgp_graceful_restart_disable_cmd,
2642 "no bgp graceful-restart-disable",
2643 NO_STR
2644 "BGP specific commands\n"
2645 NO_GR_DISABLE
055679e9 2646 )
2647{
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649
2650 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2651 zlog_debug(
2ba1fe69 2652 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2653
2654 int ret = BGP_GR_FAILURE;
2655
2656 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2657
36235319
QY
2658 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2659 ret);
5cce3f05 2660
055679e9 2661 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2662 zlog_debug(
2ba1fe69 2663 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2664 vty_out(vty,
2665 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2666
2667 return bgp_vty_return(vty, ret);
2668}
2669
2670DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2671 bgp_neighbor_graceful_restart_set_cmd,
2672 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2673 NEIGHBOR_STR
2674 NEIGHBOR_ADDR_STR2
2675 GR_NEIGHBOR_CMD
055679e9 2676 )
2677{
2678 int idx_peer = 1;
2679 struct peer *peer;
2680 int ret = BGP_GR_FAILURE;
2681
dc95985f 2682 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2683
055679e9 2684 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2685 zlog_debug(
2ba1fe69 2686 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2687
055679e9 2688 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2689 if (!peer)
2690 return CMD_WARNING_CONFIG_FAILED;
2691
2692 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2693
dc95985f 2694 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2695 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2696
2697 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2698 zlog_debug(
2ba1fe69 2699 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2700 vty_out(vty,
2701 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2702
2703 return bgp_vty_return(vty, ret);
2704}
2705
2706DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 2707 no_bgp_neighbor_graceful_restart_set_cmd,
2708 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2709 NO_STR
2710 NEIGHBOR_STR
2711 NEIGHBOR_ADDR_STR2
2712 NO_GR_NEIGHBOR_CMD
055679e9 2713 )
2714{
2715 int idx_peer = 2;
2716 int ret = BGP_GR_FAILURE;
2717 struct peer *peer;
2718
dc95985f 2719 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2720
055679e9 2721 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2722 if (!peer)
2723 return CMD_WARNING_CONFIG_FAILED;
2724
2725 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2726 zlog_debug(
2ba1fe69 2727 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 2728
2729 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
2730
dc95985f 2731 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2732 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2733
2734 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2735 zlog_debug(
2ba1fe69 2736 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2737 vty_out(vty,
2738 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2739
2740 return bgp_vty_return(vty, ret);
2741}
2742
2743DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 2744 bgp_neighbor_graceful_restart_helper_set_cmd,
2745 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2746 NEIGHBOR_STR
2747 NEIGHBOR_ADDR_STR2
2748 GR_NEIGHBOR_HELPER_CMD
055679e9 2749 )
2750{
2751 int idx_peer = 1;
2752 struct peer *peer;
2753 int ret = BGP_GR_FAILURE;
2754
dc95985f 2755 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2756
055679e9 2757 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2758 zlog_debug(
2ba1fe69 2759 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 2760
055679e9 2761 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2762
055679e9 2763 if (!peer)
2764 return CMD_WARNING_CONFIG_FAILED;
2765
2766
2767 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 2768
dc95985f 2769 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2770 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 2771
055679e9 2772 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2773 zlog_debug(
2ba1fe69 2774 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2775 vty_out(vty,
2776 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2777
2778 return bgp_vty_return(vty, ret);
2779}
2780
2781DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 2782 no_bgp_neighbor_graceful_restart_helper_set_cmd,
2783 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
2784 NO_STR
2785 NEIGHBOR_STR
2786 NEIGHBOR_ADDR_STR2
2787 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 2788 )
2789{
2790 int idx_peer = 2;
2791 int ret = BGP_GR_FAILURE;
2792 struct peer *peer;
2793
dc95985f 2794 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2795
055679e9 2796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2797 if (!peer)
2798 return CMD_WARNING_CONFIG_FAILED;
2799
2800 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2801 zlog_debug(
2ba1fe69 2802 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 2803
36235319 2804 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 2805
dc95985f 2806 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2807 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2808
2809 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2810 zlog_debug(
2ba1fe69 2811 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 2812 vty_out(vty,
2813 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2814
2815 return bgp_vty_return(vty, ret);
2816}
2817
2818DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 2819 bgp_neighbor_graceful_restart_disable_set_cmd,
2820 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2821 NEIGHBOR_STR
2822 NEIGHBOR_ADDR_STR2
2823 GR_NEIGHBOR_DISABLE_CMD
055679e9 2824 )
2825{
2826 int idx_peer = 1;
2827 struct peer *peer;
2828 int ret = BGP_GR_FAILURE;
2829
dc95985f 2830 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2831
055679e9 2832 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2833 zlog_debug(
2ba1fe69 2834 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2835
2836 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2837 if (!peer)
2838 return CMD_WARNING_CONFIG_FAILED;
2839
36235319 2840 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 2841
2842 if (peer->bgp->t_startup)
2843 bgp_peer_gr_flags_update(peer);
2844
dc95985f 2845 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2846 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2847
055679e9 2848 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2849 zlog_debug(
2ba1fe69 2850 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2851 vty_out(vty,
2852 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2853
2854 return bgp_vty_return(vty, ret);
2855}
2856
2857DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 2858 no_bgp_neighbor_graceful_restart_disable_set_cmd,
2859 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
2860 NO_STR
2861 NEIGHBOR_STR
2862 NEIGHBOR_ADDR_STR2
2863 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 2864 )
2865{
2866 int idx_peer = 2;
2867 int ret = BGP_GR_FAILURE;
2868 struct peer *peer;
2869
dc95985f 2870 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2871
055679e9 2872 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2873 if (!peer)
2874 return CMD_WARNING_CONFIG_FAILED;
2875
2876 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2877 zlog_debug(
2ba1fe69 2878 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 2879
2880 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
2881
dc95985f 2882 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2883 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2884
2885 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2886 zlog_debug(
2ba1fe69 2887 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 2888 vty_out(vty,
2889 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2890
2891 return bgp_vty_return(vty, ret);
2892}
2893
d6e3c15b 2894DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
2895 bgp_graceful_restart_disable_eor_cmd,
2896 "bgp graceful-restart disable-eor",
2897 "BGP specific commands\n"
2898 "Graceful restart configuration parameters\n"
2899 "Disable EOR Check\n")
2900{
2901 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2902 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2903
d6e3c15b 2904 return CMD_SUCCESS;
2905}
2906
2907DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
2908 no_bgp_graceful_restart_disable_eor_cmd,
2909 "no bgp graceful-restart disable-eor",
2910 NO_STR
2911 "BGP specific commands\n"
2912 "Graceful restart configuration parameters\n"
2913 "Disable EOR Check\n")
2914{
2915 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2916 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 2917
2918 return CMD_SUCCESS;
2919}
2920
2921DEFUN (bgp_graceful_restart_rib_stale_time,
2922 bgp_graceful_restart_rib_stale_time_cmd,
2923 "bgp graceful-restart rib-stale-time (1-3600)",
2924 "BGP specific commands\n"
2925 "Graceful restart configuration parameters\n"
2926 "Specify the stale route removal timer in rib\n"
2927 "Delay value (seconds)\n")
2928{
2929 VTY_DECLVAR_CONTEXT(bgp, bgp);
2930 int idx_number = 3;
2931 uint32_t stale_time;
2932
2933 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
2934 bgp->rib_stale_time = stale_time;
2935 /* Send the stale timer update message to RIB */
2936 if (bgp_zebra_stale_timer_update(bgp))
2937 return CMD_WARNING;
2938
2939 return CMD_SUCCESS;
2940}
2941
2942DEFUN (no_bgp_graceful_restart_rib_stale_time,
2943 no_bgp_graceful_restart_rib_stale_time_cmd,
2944 "no bgp graceful-restart rib-stale-time [(1-3600)]",
2945 NO_STR
2946 "BGP specific commands\n"
2947 "Graceful restart configuration parameters\n"
2948 "Specify the stale route removal timer in rib\n"
2949 "Delay value (seconds)\n")
2950{
2951 VTY_DECLVAR_CONTEXT(bgp, bgp);
2952
2953 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
2954 /* Send the stale timer update message to RIB */
2955 if (bgp_zebra_stale_timer_update(bgp))
2956 return CMD_WARNING;
2957
d6e3c15b 2958 return CMD_SUCCESS;
2959}
2960
ff8a8a7a
CS
2961static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
2962 char *errmsg,
2963 size_t errmsg_len)
05bd726c 2964{
2965 bgp_static_redo_import_check(bgp);
2966 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
2967 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
2968 return -1;
2969 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
2970 return -1;
2971
2972 return 0;
05bd726c 2973}
2974
2975static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
2976{
2977 struct listnode *node, *nnode;
2978 struct bgp *bgp;
2979 bool vrf_cfg = false;
ff8a8a7a 2980 char errmsg[BUFSIZ] = {'\0'};
05bd726c 2981
2982 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
2983 return CMD_SUCCESS;
2984
2985 /* See if graceful-shutdown is set per-vrf and warn user to delete */
2986 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
2987 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2988 vty_out(vty,
2989 "%% graceful-shutdown configuration found in vrf %s\n",
2990 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
2991 VRF_DEFAULT_NAME : bgp->name);
2992 vrf_cfg = true;
2993 }
2994 }
2995
2996 if (vrf_cfg) {
2997 vty_out(vty,
2998 "%%Failed: global graceful-shutdown not permitted\n");
2999 return CMD_WARNING;
3000 }
3001
3002 /* Set flag globally */
3003 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3004
3005 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3006 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3007 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3008 sizeof(errmsg))
3009 < 0)
3010 if (strlen(errmsg))
3011 vty_out(vty, "%s\n", errmsg);
3012 }
05bd726c 3013
3014 return CMD_SUCCESS;
3015}
3016
3017static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3018{
3019 struct listnode *node, *nnode;
3020 struct bgp *bgp;
ff8a8a7a 3021 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3022
3023 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3024 return CMD_SUCCESS;
3025
3026 /* Unset flag globally */
3027 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3028
3029 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3030 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3031 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3032 sizeof(errmsg))
3033 < 0)
3034 if (strlen(errmsg))
3035 vty_out(vty, "%s\n", errmsg);
3036 }
05bd726c 3037
3038 return CMD_SUCCESS;
3039}
3040
7f323236
DW
3041/* "bgp graceful-shutdown" configuration */
3042DEFUN (bgp_graceful_shutdown,
3043 bgp_graceful_shutdown_cmd,
3044 "bgp graceful-shutdown",
3045 BGP_STR
3046 "Graceful shutdown parameters\n")
3047{
05bd726c 3048 if (vty->node == CONFIG_NODE)
3049 return bgp_global_graceful_shutdown_config_vty(vty);
3050
87ce2564
CS
3051 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3052 NB_OP_MODIFY, "true");
7f323236 3053
ff8a8a7a 3054 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3055}
3056
ff8a8a7a 3057DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3058 no_bgp_graceful_shutdown_cmd,
3059 "no bgp graceful-shutdown",
3060 NO_STR
3061 BGP_STR
3062 "Graceful shutdown parameters\n")
3063{
05bd726c 3064 if (vty->node == CONFIG_NODE)
3065 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3066
87ce2564
CS
3067 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3068 NB_OP_MODIFY, "false");
05bd726c 3069
ff8a8a7a
CS
3070 return nb_cli_apply_changes(vty, NULL);
3071}
7f323236 3072
ff8a8a7a
CS
3073void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3074 struct lyd_node *dnode,
3075 bool show_defaults)
3076{
3077 if (yang_dnode_get_bool(dnode, NULL))
3078 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3079}
3080
718e3744 3081/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3082DEFUN_YANG (bgp_fast_external_failover,
718e3744 3083 bgp_fast_external_failover_cmd,
3084 "bgp fast-external-failover",
3085 BGP_STR
3086 "Immediately reset session if a link to a directly connected external peer goes down\n")
3087{
87ce2564
CS
3088 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3089 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3090
3091 return nb_cli_apply_changes(vty, NULL);
718e3744 3092}
3093
ff8a8a7a 3094DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3095 no_bgp_fast_external_failover_cmd,
3096 "no bgp fast-external-failover",
3097 NO_STR
3098 BGP_STR
3099 "Immediately reset session if a link to a directly connected external peer goes down\n")
3100{
87ce2564
CS
3101 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3102 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3103
3104 return nb_cli_apply_changes(vty, NULL);
3105}
3106
3107void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3108 struct lyd_node *dnode,
3109 bool show_defaults)
3110{
3111 if (!yang_dnode_get_bool(dnode, NULL))
3112 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3113}
6b0655a2 3114
718e3744 3115/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3116DEFUN_YANG(bgp_bestpath_compare_router_id,
3117 bgp_bestpath_compare_router_id_cmd,
3118 "bgp bestpath compare-routerid",
3119 "BGP specific commands\n"
3120 "Change the default bestpath selection\n"
3121 "Compare router-id for identical EBGP paths\n")
718e3744 3122{
ff8a8a7a 3123 nb_cli_enqueue_change(
87ce2564
CS
3124 vty,
3125 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3126 NB_OP_MODIFY, "true");
7aafcaca 3127
ff8a8a7a 3128 return nb_cli_apply_changes(vty, NULL);
718e3744 3129}
3130
ff8a8a7a
CS
3131DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3132 no_bgp_bestpath_compare_router_id_cmd,
3133 "no bgp bestpath compare-routerid",
3134 NO_STR
3135 "BGP specific commands\n"
3136 "Change the default bestpath selection\n"
3137 "Compare router-id for identical EBGP paths\n")
718e3744 3138{
ff8a8a7a 3139 nb_cli_enqueue_change(
87ce2564
CS
3140 vty,
3141 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3142 NB_OP_MODIFY, "false");
7aafcaca 3143
ff8a8a7a 3144 return nb_cli_apply_changes(vty, NULL);
718e3744 3145}
6b0655a2 3146
718e3744 3147/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3148DEFUN_YANG(bgp_bestpath_aspath_ignore,
3149 bgp_bestpath_aspath_ignore_cmd,
3150 "bgp bestpath as-path ignore",
3151 "BGP specific commands\n"
3152 "Change the default bestpath selection\n"
3153 "AS-path attribute\n"
3154 "Ignore as-path length in selecting a route\n")
718e3744 3155{
87ce2564
CS
3156 nb_cli_enqueue_change(
3157 vty, "./global/route-selection-options/ignore-as-path-length",
3158 NB_OP_MODIFY, "true");
7aafcaca 3159
ff8a8a7a 3160 return nb_cli_apply_changes(vty, NULL);
718e3744 3161}
3162
ff8a8a7a
CS
3163DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3164 no_bgp_bestpath_aspath_ignore_cmd,
3165 "no bgp bestpath as-path ignore",
3166 NO_STR
3167 "BGP specific commands\n"
3168 "Change the default bestpath selection\n"
3169 "AS-path attribute\n"
3170 "Ignore as-path length in selecting a route\n")
718e3744 3171{
87ce2564
CS
3172 nb_cli_enqueue_change(
3173 vty, "./global/route-selection-options/ignore-as-path-length",
3174 NB_OP_MODIFY, "false");
7aafcaca 3175
ff8a8a7a 3176 return nb_cli_apply_changes(vty, NULL);
718e3744 3177}
6b0655a2 3178
6811845b 3179/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3180DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3181 bgp_bestpath_aspath_confed_cmd,
3182 "bgp bestpath as-path confed",
3183 "BGP specific commands\n"
3184 "Change the default bestpath selection\n"
3185 "AS-path attribute\n"
3186 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3187{
87ce2564
CS
3188 nb_cli_enqueue_change(vty,
3189 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3190 NB_OP_MODIFY, "true");
7aafcaca 3191
ff8a8a7a 3192 return nb_cli_apply_changes(vty, NULL);
6811845b 3193}
3194
ff8a8a7a 3195DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3196 no_bgp_bestpath_aspath_confed_cmd,
3197 "no bgp bestpath as-path confed",
3198 NO_STR
3199 "BGP specific commands\n"
3200 "Change the default bestpath selection\n"
3201 "AS-path attribute\n"
3202 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3203{
87ce2564
CS
3204 nb_cli_enqueue_change(vty,
3205 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3206 NB_OP_MODIFY, "false");
7aafcaca 3207
ff8a8a7a 3208 return nb_cli_apply_changes(vty, NULL);
6811845b 3209}
6b0655a2 3210
2fdd455c 3211/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3212DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3213 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3214 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3215 "BGP specific commands\n"
3216 "Change the default bestpath selection\n"
3217 "AS-path attribute\n"
3218 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3219 "Generate an AS_SET\n"
16fc1eec
DS
3220 "Do not generate an AS_SET\n")
3221{
d62a17ae 3222 int idx = 0;
219178b6 3223
87ce2564
CS
3224 nb_cli_enqueue_change(
3225 vty, "./global/route-selection-options/allow-multiple-as",
3226 NB_OP_MODIFY, "true");
d62a17ae 3227 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3228 nb_cli_enqueue_change(
87ce2564
CS
3229 vty,
3230 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3231 NB_OP_MODIFY, "true");
d62a17ae 3232 else
ff8a8a7a 3233 nb_cli_enqueue_change(
87ce2564
CS
3234 vty,
3235 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3236 NB_OP_MODIFY, "false");
7aafcaca 3237
ff8a8a7a 3238 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3239}
3240
ff8a8a7a 3241DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3242 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3243 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3244 NO_STR
3245 "BGP specific commands\n"
3246 "Change the default bestpath selection\n"
3247 "AS-path attribute\n"
3248 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3249 "Generate an AS_SET\n"
16fc1eec
DS
3250 "Do not generate an AS_SET\n")
3251{
87ce2564
CS
3252 nb_cli_enqueue_change(
3253 vty, "./global/route-selection-options/allow-multiple-as",
3254 NB_OP_MODIFY, "false");
3255 nb_cli_enqueue_change(
3256 vty, "./global/route-selection-options/multi-path-as-set",
3257 NB_OP_MODIFY, "false");
7aafcaca 3258
ff8a8a7a 3259 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3260}
6b0655a2 3261
848973c7 3262/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3263DEFUN_YANG(bgp_log_neighbor_changes,
3264 bgp_log_neighbor_changes_cmd,
3265 "bgp log-neighbor-changes",
3266 "BGP specific commands\n"
3267 "Log neighbor up/down and reset reason\n")
848973c7 3268{
87ce2564
CS
3269 nb_cli_enqueue_change(
3270 vty, "./global/global-neighbor-config/log-neighbor-changes",
3271 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3272
3273 return nb_cli_apply_changes(vty, NULL);
848973c7 3274}
3275
ff8a8a7a
CS
3276DEFUN_YANG(no_bgp_log_neighbor_changes,
3277 no_bgp_log_neighbor_changes_cmd,
3278 "no bgp log-neighbor-changes",
3279 NO_STR
3280 "BGP specific commands\n"
3281 "Log neighbor up/down and reset reason\n")
848973c7 3282{
87ce2564
CS
3283 nb_cli_enqueue_change(
3284 vty, "./global/global-neighbor-config/log-neighbor-changes",
3285 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3286
3287 return nb_cli_apply_changes(vty, NULL);
848973c7 3288}
6b0655a2 3289
718e3744 3290/* "bgp bestpath med" configuration. */
ff8a8a7a 3291DEFUN_YANG (bgp_bestpath_med,
718e3744 3292 bgp_bestpath_med_cmd,
2d8c1a4d 3293 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3294 "BGP specific commands\n"
3295 "Change the default bestpath selection\n"
3296 "MED attribute\n"
3297 "Compare MED among confederation paths\n"
838758ac
DW
3298 "Treat missing MED as the least preferred one\n"
3299 "Treat missing MED as the least preferred one\n"
3300 "Compare MED among confederation paths\n")
718e3744 3301{
d62a17ae 3302 int idx = 0;
ff8a8a7a
CS
3303 bool confed = false;
3304 bool worst_med = false;
3305
3306
d62a17ae 3307 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3308 confed = true;
3309
87ce2564
CS
3310 nb_cli_enqueue_change(vty,
3311 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3312 NB_OP_MODIFY, confed ? "true" : "false");
3313
d62a17ae 3314 idx = 0;
3315 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3316 worst_med = true;
e52702f2 3317
87ce2564
CS
3318 nb_cli_enqueue_change(
3319 vty, "./global/route-selection-options/missing-as-worst-med",
3320 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3321
ff8a8a7a 3322 return nb_cli_apply_changes(vty, NULL);
718e3744 3323}
3324
ff8a8a7a 3325DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3326 no_bgp_bestpath_med_cmd,
2d8c1a4d 3327 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3328 NO_STR
3329 "BGP specific commands\n"
3330 "Change the default bestpath selection\n"
3331 "MED attribute\n"
3332 "Compare MED among confederation paths\n"
3a2d747c
QY
3333 "Treat missing MED as the least preferred one\n"
3334 "Treat missing MED as the least preferred one\n"
3335 "Compare MED among confederation paths\n")
718e3744 3336{
d62a17ae 3337 int idx = 0;
ff8a8a7a 3338
d62a17ae 3339 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3340 nb_cli_enqueue_change(
3341 vty, "./global/route-selection-options/confed-med",
3342 NB_OP_MODIFY, "false");
ff8a8a7a 3343
d62a17ae 3344 idx = 0;
3345 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3346 nb_cli_enqueue_change(
87ce2564
CS
3347 vty,
3348 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3349 NB_OP_MODIFY, "false");
718e3744 3350
ff8a8a7a 3351 return nb_cli_apply_changes(vty, NULL);
718e3744 3352}
3353
f7e1c681 3354/* "bgp bestpath bandwidth" configuration. */
3355DEFPY (bgp_bestpath_bw,
3356 bgp_bestpath_bw_cmd,
ad36d216 3357 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3358 "BGP specific commands\n"
3359 "Change the default bestpath selection\n"
3360 "Link Bandwidth attribute\n"
3361 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3362 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3363 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3364{
3365 VTY_DECLVAR_CONTEXT(bgp, bgp);
3366 afi_t afi;
3367 safi_t safi;
3368
ad36d216
DS
3369 if (!bw_cfg) {
3370 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3371 return CMD_ERR_INCOMPLETE;
f7e1c681 3372 }
ad36d216
DS
3373 if (!strcmp(bw_cfg, "ignore"))
3374 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3375 else if (!strcmp(bw_cfg, "skip-missing"))
3376 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3377 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3378 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3379 else
3380 return CMD_ERR_NO_MATCH;
f7e1c681 3381
3382 /* This config is used in route install, so redo that. */
3383 FOREACH_AFI_SAFI (afi, safi) {
3384 if (!bgp_fibupd_safi(safi))
3385 continue;
3386 bgp_zebra_announce_table(bgp, afi, safi);
3387 }
3388
3389 return CMD_SUCCESS;
3390}
3391
ad36d216
DS
3392DEFPY (no_bgp_bestpath_bw,
3393 no_bgp_bestpath_bw_cmd,
3394 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3395 NO_STR
3396 "BGP specific commands\n"
3397 "Change the default bestpath selection\n"
3398 "Link Bandwidth attribute\n"
3399 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3400 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3401 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3402{
3403 VTY_DECLVAR_CONTEXT(bgp, bgp);
3404 afi_t afi;
3405 safi_t safi;
3406
3407 bgp->lb_handling = BGP_LINK_BW_ECMP;
3408
3409 /* This config is used in route install, so redo that. */
3410 FOREACH_AFI_SAFI (afi, safi) {
3411 if (!bgp_fibupd_safi(safi))
3412 continue;
3413 bgp_zebra_announce_table(bgp, afi, safi);
3414 }
3415 return CMD_SUCCESS;
3416}
3417
718e3744 3418/* "no bgp default ipv4-unicast". */
3419DEFUN (no_bgp_default_ipv4_unicast,
3420 no_bgp_default_ipv4_unicast_cmd,
3421 "no bgp default ipv4-unicast",
3422 NO_STR
3423 "BGP specific commands\n"
3424 "Configure BGP defaults\n"
3425 "Activate ipv4-unicast for a peer by default\n")
3426{
d62a17ae 3427 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3428 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3429 return CMD_SUCCESS;
718e3744 3430}
3431
3432DEFUN (bgp_default_ipv4_unicast,
3433 bgp_default_ipv4_unicast_cmd,
3434 "bgp default ipv4-unicast",
3435 "BGP specific commands\n"
3436 "Configure BGP defaults\n"
3437 "Activate ipv4-unicast for a peer by default\n")
3438{
d62a17ae 3439 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3440 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3441 return CMD_SUCCESS;
718e3744 3442}
6b0655a2 3443
04b6bdc0 3444/* Display hostname in certain command outputs */
ff8a8a7a 3445DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3446 bgp_default_show_hostname_cmd,
3447 "bgp default show-hostname",
3448 "BGP specific commands\n"
3449 "Configure BGP defaults\n"
0437e105 3450 "Show hostname in certain command outputs\n")
04b6bdc0 3451{
87ce2564
CS
3452 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3453 "true");
ff8a8a7a
CS
3454
3455 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3456}
3457
ff8a8a7a
CS
3458DEFUN_YANG(no_bgp_default_show_hostname,
3459 no_bgp_default_show_hostname_cmd,
3460 "no bgp default show-hostname",
3461 NO_STR
3462 "BGP specific commands\n"
3463 "Configure BGP defaults\n"
3464 "Show hostname in certain command outputs\n")
04b6bdc0 3465{
87ce2564
CS
3466 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3467 "false");
ff8a8a7a
CS
3468
3469 return nb_cli_apply_changes(vty, NULL);
3470}
3471
3472void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3473 bool show_defaults)
3474{
3475 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3476 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3477}
3478
aef999a2
DA
3479/* Display hostname in certain command outputs */
3480DEFUN (bgp_default_show_nexthop_hostname,
3481 bgp_default_show_nexthop_hostname_cmd,
3482 "bgp default show-nexthop-hostname",
3483 "BGP specific commands\n"
3484 "Configure BGP defaults\n"
3485 "Show hostname for nexthop in certain command outputs\n")
3486{
87ce2564
CS
3487 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3488 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3489
3490 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3491}
3492
3493DEFUN (no_bgp_default_show_nexthop_hostname,
3494 no_bgp_default_show_nexthop_hostname_cmd,
3495 "no bgp default show-nexthop-hostname",
3496 NO_STR
3497 "BGP specific commands\n"
3498 "Configure BGP defaults\n"
3499 "Show hostname for nexthop in certain command outputs\n")
3500{
87ce2564
CS
3501 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3502 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3503
3504 return nb_cli_apply_changes(vty, NULL);
3505}
3506
3507void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3508 struct lyd_node *dnode,
3509 bool show_defaults)
3510{
3511 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3512 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3513}
3514
8233ef81 3515/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3516DEFUN_YANG(bgp_network_import_check,
3517 bgp_network_import_check_cmd,
3518 "bgp network import-check",
3519 "BGP specific commands\n"
3520 "BGP network command\n"
3521 "Check BGP network route exists in IGP\n")
718e3744 3522{
87ce2564
CS
3523 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3524 "true");
078430f6 3525
ff8a8a7a 3526 return nb_cli_apply_changes(vty, NULL);
718e3744 3527}
3528
d62a17ae 3529ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3530 "bgp network import-check exact",
3531 "BGP specific commands\n"
3532 "BGP network command\n"
3533 "Check BGP network route exists in IGP\n"
3534 "Match route precisely\n")
8233ef81 3535
ff8a8a7a
CS
3536DEFUN_YANG(no_bgp_network_import_check,
3537 no_bgp_network_import_check_cmd,
3538 "no bgp network import-check",
3539 NO_STR
3540 "BGP specific commands\n"
3541 "BGP network command\n"
3542 "Check BGP network route exists in IGP\n")
718e3744 3543{
87ce2564
CS
3544 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3545 "false");
5623e905 3546
ff8a8a7a 3547 return nb_cli_apply_changes(vty, NULL);
718e3744 3548}
6b0655a2 3549
ff8a8a7a
CS
3550void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3551 bool show_defaults)
718e3744 3552{
ff8a8a7a
CS
3553 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3554 vty_out(vty, " bgp network import-check\n");
3555}
718e3744 3556
ff8a8a7a
CS
3557DEFUN_YANG(bgp_default_local_preference,
3558 bgp_default_local_preference_cmd,
3559 "bgp default local-preference (0-4294967295)",
3560 "BGP specific commands\n"
3561 "Configure BGP defaults\n"
3562 "local preference (higher=more preferred)\n"
3563 "Configure default local preference value\n")
3564{
3565 int idx_number = 3;
718e3744 3566
87ce2564 3567 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3568 argv[idx_number]->arg);
718e3744 3569
ff8a8a7a 3570 return nb_cli_apply_changes(vty, NULL);
718e3744 3571}
3572
ff8a8a7a
CS
3573DEFUN_YANG(no_bgp_default_local_preference,
3574 no_bgp_default_local_preference_cmd,
3575 "no bgp default local-preference [(0-4294967295)]",
3576 NO_STR
3577 "BGP specific commands\n"
3578 "Configure BGP defaults\n"
3579 "local preference (higher=more preferred)\n"
3580 "Configure default local preference value\n")
718e3744 3581{
87ce2564 3582 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3583
ff8a8a7a 3584 return nb_cli_apply_changes(vty, NULL);
718e3744 3585}
3586
ff8a8a7a
CS
3587void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3588 bool show_defaults)
3589{
3590 vty_out(vty, " bgp default local-preference %u\n",
3591 yang_dnode_get_uint32(dnode, NULL));
3592}
6b0655a2 3593
ff8a8a7a
CS
3594
3595DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3596 bgp_default_subgroup_pkt_queue_max_cmd,
3597 "bgp default subgroup-pkt-queue-max (20-100)",
3598 "BGP specific commands\n"
3599 "Configure BGP defaults\n"
3600 "subgroup-pkt-queue-max\n"
3601 "Configure subgroup packet queue max\n")
8bd9d948 3602{
d62a17ae 3603 int idx_number = 3;
3f9c7369 3604
ff8a8a7a 3605 nb_cli_enqueue_change(
87ce2564
CS
3606 vty,
3607 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3608 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3609
ff8a8a7a 3610 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3611}
3612
ff8a8a7a
CS
3613DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3614 no_bgp_default_subgroup_pkt_queue_max_cmd,
3615 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3616 NO_STR
3617 "BGP specific commands\n"
3618 "Configure BGP defaults\n"
3619 "subgroup-pkt-queue-max\n"
3620 "Configure subgroup packet queue max\n")
3f9c7369 3621{
ff8a8a7a 3622 nb_cli_enqueue_change(
87ce2564
CS
3623 vty,
3624 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3625 NB_OP_MODIFY, NULL);
3626
3627 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3628}
3629
ff8a8a7a
CS
3630void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3631 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3632{
3633 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3634 yang_dnode_get_uint32(dnode, NULL));
3635}
813d4307 3636
ff8a8a7a
CS
3637DEFUN_YANG(bgp_rr_allow_outbound_policy,
3638 bgp_rr_allow_outbound_policy_cmd,
3639 "bgp route-reflector allow-outbound-policy",
3640 "BGP specific commands\n"
3641 "Allow modifications made by out route-map\n"
3642 "on ibgp neighbors\n")
8bd9d948 3643{
87ce2564
CS
3644 nb_cli_enqueue_change(vty,
3645 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3646 NB_OP_MODIFY, "true");
8bd9d948 3647
ff8a8a7a
CS
3648 return nb_cli_apply_changes(vty, NULL);
3649}
8bd9d948 3650
ff8a8a7a
CS
3651DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3652 no_bgp_rr_allow_outbound_policy_cmd,
3653 "no bgp route-reflector allow-outbound-policy",
3654 NO_STR
3655 "BGP specific commands\n"
3656 "Allow modifications made by out route-map\n"
3657 "on ibgp neighbors\n")
3658{
87ce2564
CS
3659 nb_cli_enqueue_change(vty,
3660 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
3661 NB_OP_MODIFY, "false");
3662
3663 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3664}
3665
ff8a8a7a
CS
3666
3667void cli_show_router_global_neighbor_config(struct vty *vty,
3668 struct lyd_node *dnode,
3669 bool show_defaults)
8bd9d948 3670{
ff8a8a7a
CS
3671 uint32_t write_quanta, read_quanta;
3672
3673 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3674 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 3675
ff8a8a7a
CS
3676 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3677 uint32_t listen_limit = yang_dnode_get_uint32(
3678 dnode, "./dynamic-neighbors-limit");
3679 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 3680 }
8bd9d948 3681
ff8a8a7a
CS
3682 write_quanta = yang_dnode_get_uint32(
3683 dnode, "./packet-quanta-config/wpkt-quanta");
3684 if (write_quanta != BGP_WRITE_PACKET_MAX)
3685 vty_out(vty, " write-quanta %d\n", write_quanta);
3686
3687 read_quanta = yang_dnode_get_uint32(
3688 dnode, "./packet-quanta-config/rpkt-quanta");
3689
3690 if (read_quanta != BGP_READ_PACKET_MAX)
3691 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
3692}
3693
ff8a8a7a
CS
3694DEFUN_YANG(bgp_listen_limit,
3695 bgp_listen_limit_cmd,
3696 "bgp listen limit (1-5000)",
3697 "BGP specific commands\n"
3698 "BGP Dynamic Neighbors listen commands\n"
3699 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3700 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3701{
d62a17ae 3702 int idx_number = 3;
f14e6fdb 3703
ff8a8a7a 3704 nb_cli_enqueue_change(
87ce2564 3705 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 3706 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 3707
ff8a8a7a 3708 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3709}
3710
ff8a8a7a
CS
3711DEFUN_YANG(no_bgp_listen_limit,
3712 no_bgp_listen_limit_cmd,
3713 "no bgp listen limit [(1-5000)]",
3714 NO_STR
3715 "BGP specific commands\n"
3716 "BGP Dynamic Neighbors listen commands\n"
3717 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3718 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 3719{
ff8a8a7a 3720 nb_cli_enqueue_change(
87ce2564 3721 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
3722 NB_OP_DESTROY, NULL);
3723
3724 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
3725}
3726
3727
20eb8864 3728/*
3729 * Check if this listen range is already configured. Check for exact
3730 * match or overlap based on input.
3731 */
d62a17ae 3732static struct peer_group *listen_range_exists(struct bgp *bgp,
3733 struct prefix *range, int exact)
3734{
3735 struct listnode *node, *nnode;
3736 struct listnode *node1, *nnode1;
3737 struct peer_group *group;
3738 struct prefix *lr;
3739 afi_t afi;
3740 int match;
3741
3742 afi = family2afi(range->family);
3743 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3744 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
3745 lr)) {
3746 if (exact)
3747 match = prefix_same(range, lr);
3748 else
3749 match = (prefix_match(range, lr)
3750 || prefix_match(lr, range));
3751 if (match)
3752 return group;
3753 }
3754 }
3755
3756 return NULL;
20eb8864 3757}
3758
f14e6fdb
DS
3759DEFUN (bgp_listen_range,
3760 bgp_listen_range_cmd,
d7b9898c 3761 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 3762 "BGP specific commands\n"
d7fa34c1
QY
3763 "Configure BGP dynamic neighbors listen range\n"
3764 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
3765 NEIGHBOR_ADDR_STR
3766 "Member of the peer-group\n"
3767 "Peer-group name\n")
f14e6fdb 3768{
d62a17ae 3769 VTY_DECLVAR_CONTEXT(bgp, bgp);
3770 struct prefix range;
3771 struct peer_group *group, *existing_group;
3772 afi_t afi;
3773 int ret;
3774 int idx = 0;
3775
3776 argv_find(argv, argc, "A.B.C.D/M", &idx);
3777 argv_find(argv, argc, "X:X::X:X/M", &idx);
3778 char *prefix = argv[idx]->arg;
d7b9898c 3779 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3780 char *peergroup = argv[idx]->arg;
3781
3782 /* Convert IP prefix string to struct prefix. */
3783 ret = str2prefix(prefix, &range);
3784 if (!ret) {
3785 vty_out(vty, "%% Malformed listen range\n");
3786 return CMD_WARNING_CONFIG_FAILED;
3787 }
3788
3789 afi = family2afi(range.family);
3790
3791 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3792 vty_out(vty,
3793 "%% Malformed listen range (link-local address)\n");
3794 return CMD_WARNING_CONFIG_FAILED;
3795 }
3796
3797 apply_mask(&range);
3798
3799 /* Check if same listen range is already configured. */
3800 existing_group = listen_range_exists(bgp, &range, 1);
3801 if (existing_group) {
3802 if (strcmp(existing_group->name, peergroup) == 0)
3803 return CMD_SUCCESS;
3804 else {
3805 vty_out(vty,
3806 "%% Same listen range is attached to peer-group %s\n",
3807 existing_group->name);
3808 return CMD_WARNING_CONFIG_FAILED;
3809 }
3810 }
3811
3812 /* Check if an overlapping listen range exists. */
3813 if (listen_range_exists(bgp, &range, 0)) {
3814 vty_out(vty,
3815 "%% Listen range overlaps with existing listen range\n");
3816 return CMD_WARNING_CONFIG_FAILED;
3817 }
3818
3819 group = peer_group_lookup(bgp, peergroup);
3820 if (!group) {
3821 vty_out(vty, "%% Configure the peer-group first\n");
3822 return CMD_WARNING_CONFIG_FAILED;
3823 }
3824
3825 ret = peer_group_listen_range_add(group, &range);
3826 return bgp_vty_return(vty, ret);
f14e6fdb
DS
3827}
3828
3829DEFUN (no_bgp_listen_range,
3830 no_bgp_listen_range_cmd,
d7b9898c 3831 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 3832 NO_STR
f14e6fdb 3833 "BGP specific commands\n"
d7fa34c1
QY
3834 "Unconfigure BGP dynamic neighbors listen range\n"
3835 "Unconfigure BGP dynamic neighbors listen range\n"
3836 NEIGHBOR_ADDR_STR
3837 "Member of the peer-group\n"
3838 "Peer-group name\n")
f14e6fdb 3839{
d62a17ae 3840 VTY_DECLVAR_CONTEXT(bgp, bgp);
3841 struct prefix range;
3842 struct peer_group *group;
3843 afi_t afi;
3844 int ret;
3845 int idx = 0;
3846
3847 argv_find(argv, argc, "A.B.C.D/M", &idx);
3848 argv_find(argv, argc, "X:X::X:X/M", &idx);
3849 char *prefix = argv[idx]->arg;
21d88a71 3850 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 3851 char *peergroup = argv[idx]->arg;
3852
3853 /* Convert IP prefix string to struct prefix. */
3854 ret = str2prefix(prefix, &range);
3855 if (!ret) {
3856 vty_out(vty, "%% Malformed listen range\n");
3857 return CMD_WARNING_CONFIG_FAILED;
3858 }
3859
3860 afi = family2afi(range.family);
3861
3862 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
3863 vty_out(vty,
3864 "%% Malformed listen range (link-local address)\n");
3865 return CMD_WARNING_CONFIG_FAILED;
3866 }
3867
3868 apply_mask(&range);
3869
3870 group = peer_group_lookup(bgp, peergroup);
3871 if (!group) {
3872 vty_out(vty, "%% Peer-group does not exist\n");
3873 return CMD_WARNING_CONFIG_FAILED;
3874 }
3875
3876 ret = peer_group_listen_range_del(group, &range);
3877 return bgp_vty_return(vty, ret);
3878}
3879
2b791107 3880void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 3881{
3882 struct peer_group *group;
3883 struct listnode *node, *nnode, *rnode, *nrnode;
3884 struct prefix *range;
3885 afi_t afi;
d62a17ae 3886
3887 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3888 vty_out(vty, " bgp listen limit %d\n",
3889 bgp->dynamic_neighbors_limit);
3890
3891 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3892 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3893 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3894 nrnode, range)) {
d62a17ae 3895 vty_out(vty,
2dbe669b
DA
3896 " bgp listen range %pFX peer-group %s\n",
3897 range, group->name);
d62a17ae 3898 }
3899 }
3900 }
f14e6fdb
DS
3901}
3902
3903
ff8a8a7a
CS
3904DEFUN_YANG(bgp_disable_connected_route_check,
3905 bgp_disable_connected_route_check_cmd,
3906 "bgp disable-ebgp-connected-route-check",
3907 "BGP specific commands\n"
3908 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 3909{
87ce2564
CS
3910 nb_cli_enqueue_change(vty,
3911 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 3912 NB_OP_MODIFY, "true");
7aafcaca 3913
ff8a8a7a 3914 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
3915}
3916
ff8a8a7a
CS
3917DEFUN_YANG(no_bgp_disable_connected_route_check,
3918 no_bgp_disable_connected_route_check_cmd,
3919 "no bgp disable-ebgp-connected-route-check",
3920 NO_STR
3921 "BGP specific commands\n"
3922 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 3923{
87ce2564
CS
3924 nb_cli_enqueue_change(vty,
3925 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 3926 NB_OP_MODIFY, "false");
d62a17ae 3927
ff8a8a7a 3928 return nb_cli_apply_changes(vty, NULL);
d62a17ae 3929}
3930
ff8a8a7a
CS
3931void cli_show_router_global_ebgp_multihop_connected_route_check(
3932 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3933{
3934 if (yang_dnode_get_bool(dnode, NULL))
3935 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
3936}
d62a17ae 3937
3938static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3939 const char *as_str, afi_t afi, safi_t safi)
3940{
3941 VTY_DECLVAR_CONTEXT(bgp, bgp);
3942 int ret;
3943 as_t as;
3944 int as_type = AS_SPECIFIED;
3945 union sockunion su;
3946
3947 if (as_str[0] == 'i') {
3948 as = 0;
3949 as_type = AS_INTERNAL;
3950 } else if (as_str[0] == 'e') {
3951 as = 0;
3952 as_type = AS_EXTERNAL;
3953 } else {
3954 /* Get AS number. */
3955 as = strtoul(as_str, NULL, 10);
3956 }
3957
390485fd 3958 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3959 ret = str2sockunion(peer_str, &su);
3960 if (ret < 0) {
390485fd
DS
3961 struct peer *peer;
3962
3963 /* Check if existing interface peer */
3964 peer = peer_lookup_by_conf_if(bgp, peer_str);
3965
d62a17ae 3966 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3967 safi);
390485fd
DS
3968
3969 /* if not interface peer, check peer-group settings */
3970 if (ret < 0 && !peer) {
d62a17ae 3971 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3972 if (ret < 0) {
3973 vty_out(vty,
390485fd 3974 "%% Create the peer-group or interface first\n");
d62a17ae 3975 return CMD_WARNING_CONFIG_FAILED;
3976 }
3977 return CMD_SUCCESS;
3978 }
3979 } else {
3980 if (peer_address_self_check(bgp, &su)) {
3981 vty_out(vty,
3982 "%% Can not configure the local system as neighbor\n");
3983 return CMD_WARNING_CONFIG_FAILED;
3984 }
3985 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3986 }
3987
3988 /* This peer belongs to peer group. */
3989 switch (ret) {
3990 case BGP_ERR_PEER_GROUP_MEMBER:
3991 vty_out(vty,
faa16034 3992 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3993 return CMD_WARNING_CONFIG_FAILED;
3994 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3995 vty_out(vty,
faa16034 3996 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3997 return CMD_WARNING_CONFIG_FAILED;
3998 }
3999 return bgp_vty_return(vty, ret);
718e3744 4000}
4001
ff8a8a7a
CS
4002DEFUN_YANG(bgp_default_shutdown,
4003 bgp_default_shutdown_cmd,
4004 "[no] bgp default shutdown",
4005 NO_STR BGP_STR
4006 "Configure BGP defaults\n"
4007 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4008{
87ce2564 4009 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4010 strmatch(argv[0]->text, "no") ? "false" : "true");
4011
4012 return nb_cli_apply_changes(vty, NULL);
4013}
4014
4015void cli_show_router_bgp_default_shutdown(struct vty *vty,
4016 struct lyd_node *dnode,
4017 bool show_defaults)
4018{
4019 if (yang_dnode_get_bool(dnode, NULL))
4020 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4021}
4022
736b68f3
DS
4023DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4024 BGP_STR
9ddf4b81 4025 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4026 "Add a shutdown message (RFC 8203)\n"
4027 "Shutdown message\n")
9cf59432 4028{
736b68f3 4029 char *msgstr = NULL;
8389c83a 4030
9cf59432
DS
4031 VTY_DECLVAR_CONTEXT(bgp, bgp);
4032
8389c83a 4033 if (argc > 3)
f80e35b6 4034 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4035
4036 bgp_shutdown_enable(bgp, msgstr);
4037 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4038
4039 return CMD_SUCCESS;
4040}
4041
736b68f3 4042DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4043 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4044{
4045 VTY_DECLVAR_CONTEXT(bgp, bgp);
4046
4047 bgp_shutdown_enable(bgp, NULL);
4048
4049 return CMD_SUCCESS;
4050}
8389c83a 4051
736b68f3 4052DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4053 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4054{
4055 VTY_DECLVAR_CONTEXT(bgp, bgp);
4056
4057 bgp_shutdown_disable(bgp);
4058
4059 return CMD_SUCCESS;
4060}
4061
9ddf4b81 4062ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4063 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4064 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4065 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4066
718e3744 4067DEFUN (neighbor_remote_as,
4068 neighbor_remote_as_cmd,
3a2d747c 4069 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 4070 NEIGHBOR_STR
4071 NEIGHBOR_ADDR_STR2
4072 "Specify a BGP neighbor\n"
d7fa34c1 4073 AS_STR
3a2d747c
QY
4074 "Internal BGP peer\n"
4075 "External BGP peer\n")
718e3744 4076{
d62a17ae 4077 int idx_peer = 1;
4078 int idx_remote_as = 3;
4079 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4080 argv[idx_remote_as]->arg, AFI_IP,
4081 SAFI_UNICAST);
4082}
4083
4084static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4085 afi_t afi, safi_t safi, int v6only,
4086 const char *peer_group_name,
4087 const char *as_str)
4088{
4089 VTY_DECLVAR_CONTEXT(bgp, bgp);
4090 as_t as = 0;
4091 int as_type = AS_UNSPECIFIED;
4092 struct peer *peer;
4093 struct peer_group *group;
4094 int ret = 0;
4095 union sockunion su;
4096
4097 group = peer_group_lookup(bgp, conf_if);
4098
4099 if (group) {
4100 vty_out(vty, "%% Name conflict with peer-group \n");
4101 return CMD_WARNING_CONFIG_FAILED;
4102 }
4103
4104 if (as_str) {
4105 if (as_str[0] == 'i') {
4106 as_type = AS_INTERNAL;
4107 } else if (as_str[0] == 'e') {
4108 as_type = AS_EXTERNAL;
4109 } else {
4110 /* Get AS number. */
4111 as = strtoul(as_str, NULL, 10);
4112 as_type = AS_SPECIFIED;
4113 }
4114 }
4115
4116 peer = peer_lookup_by_conf_if(bgp, conf_if);
4117 if (peer) {
4118 if (as_str)
cc4d4ce8 4119 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4120 afi, safi);
4121 } else {
892fedb6 4122 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4123 && afi == AFI_IP && safi == SAFI_UNICAST)
4124 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4125 as_type, 0, 0, NULL);
4126 else
4127 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4128 as_type, afi, safi, NULL);
4129
4130 if (!peer) {
4131 vty_out(vty, "%% BGP failed to create peer\n");
4132 return CMD_WARNING_CONFIG_FAILED;
4133 }
4134
4135 if (v6only)
527de3dc 4136 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4137
4138 /* Request zebra to initiate IPv6 RAs on this interface. We do
4139 * this
4140 * any unnumbered peer in order to not worry about run-time
4141 * transitions
4142 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4143 * address
4144 * gets deleted later etc.)
4145 */
4146 if (peer->ifp)
4147 bgp_zebra_initiate_radv(bgp, peer);
4148 }
4149
4150 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4151 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4152 if (v6only)
527de3dc 4153 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4154 else
527de3dc 4155 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4156
4157 /* v6only flag changed. Reset bgp seesion */
4158 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4159 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4160 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4161 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4162 } else
4163 bgp_session_reset(peer);
4164 }
4165
9fb964de
PM
4166 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4167 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4168 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4169 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4170 }
d62a17ae 4171
4172 if (peer_group_name) {
4173 group = peer_group_lookup(bgp, peer_group_name);
4174 if (!group) {
4175 vty_out(vty, "%% Configure the peer-group first\n");
4176 return CMD_WARNING_CONFIG_FAILED;
4177 }
4178
4179 ret = peer_group_bind(bgp, &su, peer, group, &as);
4180 }
4181
4182 return bgp_vty_return(vty, ret);
a80beece
DS
4183}
4184
4c48cf63
DW
4185DEFUN (neighbor_interface_config,
4186 neighbor_interface_config_cmd,
d7b9898c 4187 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
4188 NEIGHBOR_STR
4189 "Interface name or neighbor tag\n"
31500417
DW
4190 "Enable BGP on interface\n"
4191 "Member of the peer-group\n"
16cedbb0 4192 "Peer-group name\n")
4c48cf63 4193{
d62a17ae 4194 int idx_word = 1;
4195 int idx_peer_group_word = 4;
31500417 4196
d62a17ae 4197 if (argc > idx_peer_group_word)
4198 return peer_conf_interface_get(
4199 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
4200 argv[idx_peer_group_word]->arg, NULL);
4201 else
4202 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4203 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
4204}
4205
4c48cf63
DW
4206DEFUN (neighbor_interface_config_v6only,
4207 neighbor_interface_config_v6only_cmd,
d7b9898c 4208 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
4209 NEIGHBOR_STR
4210 "Interface name or neighbor tag\n"
4211 "Enable BGP on interface\n"
31500417
DW
4212 "Enable BGP with v6 link-local only\n"
4213 "Member of the peer-group\n"
16cedbb0 4214 "Peer-group name\n")
4c48cf63 4215{
d62a17ae 4216 int idx_word = 1;
4217 int idx_peer_group_word = 5;
31500417 4218
d62a17ae 4219 if (argc > idx_peer_group_word)
4220 return peer_conf_interface_get(
4221 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
4222 argv[idx_peer_group_word]->arg, NULL);
31500417 4223
d62a17ae 4224 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4225 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
4226}
4227
a80beece 4228
b3a39dc5
DD
4229DEFUN (neighbor_interface_config_remote_as,
4230 neighbor_interface_config_remote_as_cmd,
3a2d747c 4231 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4232 NEIGHBOR_STR
4233 "Interface name or neighbor tag\n"
4234 "Enable BGP on interface\n"
3a2d747c 4235 "Specify a BGP neighbor\n"
d7fa34c1 4236 AS_STR
3a2d747c
QY
4237 "Internal BGP peer\n"
4238 "External BGP peer\n")
b3a39dc5 4239{
d62a17ae 4240 int idx_word = 1;
4241 int idx_remote_as = 4;
4242 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4243 SAFI_UNICAST, 0, NULL,
4244 argv[idx_remote_as]->arg);
b3a39dc5
DD
4245}
4246
4247DEFUN (neighbor_interface_v6only_config_remote_as,
4248 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 4249 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4250 NEIGHBOR_STR
4251 "Interface name or neighbor tag\n"
3a2d747c 4252 "Enable BGP with v6 link-local only\n"
b3a39dc5 4253 "Enable BGP on interface\n"
3a2d747c 4254 "Specify a BGP neighbor\n"
d7fa34c1 4255 AS_STR
3a2d747c
QY
4256 "Internal BGP peer\n"
4257 "External BGP peer\n")
b3a39dc5 4258{
d62a17ae 4259 int idx_word = 1;
4260 int idx_remote_as = 5;
4261 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4262 SAFI_UNICAST, 1, NULL,
4263 argv[idx_remote_as]->arg);
b3a39dc5
DD
4264}
4265
718e3744 4266DEFUN (neighbor_peer_group,
4267 neighbor_peer_group_cmd,
4268 "neighbor WORD peer-group",
4269 NEIGHBOR_STR
a80beece 4270 "Interface name or neighbor tag\n"
718e3744 4271 "Configure peer-group\n")
4272{
d62a17ae 4273 VTY_DECLVAR_CONTEXT(bgp, bgp);
4274 int idx_word = 1;
4275 struct peer *peer;
4276 struct peer_group *group;
718e3744 4277
d62a17ae 4278 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4279 if (peer) {
4280 vty_out(vty, "%% Name conflict with interface: \n");
4281 return CMD_WARNING_CONFIG_FAILED;
4282 }
718e3744 4283
d62a17ae 4284 group = peer_group_get(bgp, argv[idx_word]->arg);
4285 if (!group) {
4286 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4287 return CMD_WARNING_CONFIG_FAILED;
4288 }
718e3744 4289
d62a17ae 4290 return CMD_SUCCESS;
718e3744 4291}
4292
4293DEFUN (no_neighbor,
4294 no_neighbor_cmd,
dab8cd00 4295 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 4296 NO_STR
4297 NEIGHBOR_STR
3a2d747c
QY
4298 NEIGHBOR_ADDR_STR2
4299 "Specify a BGP neighbor\n"
4300 AS_STR
4301 "Internal BGP peer\n"
4302 "External BGP peer\n")
718e3744 4303{
d62a17ae 4304 VTY_DECLVAR_CONTEXT(bgp, bgp);
4305 int idx_peer = 2;
4306 int ret;
4307 union sockunion su;
4308 struct peer_group *group;
4309 struct peer *peer;
4310 struct peer *other;
4311
4312 ret = str2sockunion(argv[idx_peer]->arg, &su);
4313 if (ret < 0) {
4314 /* look up for neighbor by interface name config. */
4315 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4316 if (peer) {
4317 /* Request zebra to terminate IPv6 RAs on this
4318 * interface. */
4319 if (peer->ifp)
4320 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4321 peer_notify_unconfig(peer);
d62a17ae 4322 peer_delete(peer);
4323 return CMD_SUCCESS;
4324 }
f14e6fdb 4325
d62a17ae 4326 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
4327 if (group) {
4328 peer_group_notify_unconfig(group);
d62a17ae 4329 peer_group_delete(group);
4e2786df 4330 } else {
d62a17ae 4331 vty_out(vty, "%% Create the peer-group first\n");
4332 return CMD_WARNING_CONFIG_FAILED;
4333 }
4334 } else {
4335 peer = peer_lookup(bgp, &su);
4336 if (peer) {
4337 if (peer_dynamic_neighbor(peer)) {
4338 vty_out(vty,
4339 "%% Operation not allowed on a dynamic neighbor\n");
4340 return CMD_WARNING_CONFIG_FAILED;
4341 }
4342
4343 other = peer->doppelganger;
b3a3290e
DS
4344
4345 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4346 bgp_zebra_terminate_radv(peer->bgp, peer);
4347
4e2786df 4348 peer_notify_unconfig(peer);
d62a17ae 4349 peer_delete(peer);
4e2786df
DA
4350 if (other && other->status != Deleted) {
4351 peer_notify_unconfig(other);
d62a17ae 4352 peer_delete(other);
4e2786df 4353 }
d62a17ae 4354 }
1ff9a340 4355 }
718e3744 4356
d62a17ae 4357 return CMD_SUCCESS;
718e3744 4358}
4359
a80beece
DS
4360DEFUN (no_neighbor_interface_config,
4361 no_neighbor_interface_config_cmd,
d7b9898c 4362 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
4363 NO_STR
4364 NEIGHBOR_STR
4365 "Interface name\n"
31500417
DW
4366 "Configure BGP on interface\n"
4367 "Enable BGP with v6 link-local only\n"
4368 "Member of the peer-group\n"
16cedbb0 4369 "Peer-group name\n"
3a2d747c
QY
4370 "Specify a BGP neighbor\n"
4371 AS_STR
4372 "Internal BGP peer\n"
4373 "External BGP peer\n")
a80beece 4374{
d62a17ae 4375 VTY_DECLVAR_CONTEXT(bgp, bgp);
4376 int idx_word = 2;
4377 struct peer *peer;
4378
4379 /* look up for neighbor by interface name config. */
4380 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4381 if (peer) {
4382 /* Request zebra to terminate IPv6 RAs on this interface. */
4383 if (peer->ifp)
4384 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4385 peer_notify_unconfig(peer);
d62a17ae 4386 peer_delete(peer);
4387 } else {
4388 vty_out(vty, "%% Create the bgp interface first\n");
4389 return CMD_WARNING_CONFIG_FAILED;
4390 }
4391 return CMD_SUCCESS;
a80beece
DS
4392}
4393
718e3744 4394DEFUN (no_neighbor_peer_group,
4395 no_neighbor_peer_group_cmd,
4396 "no neighbor WORD peer-group",
4397 NO_STR
4398 NEIGHBOR_STR
4399 "Neighbor tag\n"
4400 "Configure peer-group\n")
4401{
d62a17ae 4402 VTY_DECLVAR_CONTEXT(bgp, bgp);
4403 int idx_word = 2;
4404 struct peer_group *group;
718e3744 4405
d62a17ae 4406 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
4407 if (group) {
4408 peer_group_notify_unconfig(group);
d62a17ae 4409 peer_group_delete(group);
4e2786df 4410 } else {
d62a17ae 4411 vty_out(vty, "%% Create the peer-group first\n");
4412 return CMD_WARNING_CONFIG_FAILED;
4413 }
4414 return CMD_SUCCESS;
718e3744 4415}
4416
a80beece
DS
4417DEFUN (no_neighbor_interface_peer_group_remote_as,
4418 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 4419 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 4420 NO_STR
4421 NEIGHBOR_STR
a80beece 4422 "Interface name or neighbor tag\n"
718e3744 4423 "Specify a BGP neighbor\n"
3a2d747c
QY
4424 AS_STR
4425 "Internal BGP peer\n"
4426 "External BGP peer\n")
718e3744 4427{
d62a17ae 4428 VTY_DECLVAR_CONTEXT(bgp, bgp);
4429 int idx_word = 2;
4430 struct peer_group *group;
4431 struct peer *peer;
4432
4433 /* look up for neighbor by interface name config. */
4434 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4435 if (peer) {
390485fd 4436 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 4437 return CMD_SUCCESS;
4438 }
4439
4440 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4441 if (group)
4442 peer_group_remote_as_delete(group);
4443 else {
4444 vty_out(vty, "%% Create the peer-group or interface first\n");
4445 return CMD_WARNING_CONFIG_FAILED;
4446 }
4447 return CMD_SUCCESS;
718e3744 4448}
6b0655a2 4449
718e3744 4450DEFUN (neighbor_local_as,
4451 neighbor_local_as_cmd,
9ccf14f7 4452 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 4453 NEIGHBOR_STR
4454 NEIGHBOR_ADDR_STR2
4455 "Specify a local-as number\n"
4456 "AS number used as local AS\n")
4457{
d62a17ae 4458 int idx_peer = 1;
4459 int idx_number = 3;
4460 struct peer *peer;
4461 int ret;
4462 as_t as;
718e3744 4463
d62a17ae 4464 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4465 if (!peer)
4466 return CMD_WARNING_CONFIG_FAILED;
718e3744 4467
d62a17ae 4468 as = strtoul(argv[idx_number]->arg, NULL, 10);
4469 ret = peer_local_as_set(peer, as, 0, 0);
4470 return bgp_vty_return(vty, ret);
718e3744 4471}
4472
4473DEFUN (neighbor_local_as_no_prepend,
4474 neighbor_local_as_no_prepend_cmd,
9ccf14f7 4475 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 4476 NEIGHBOR_STR
4477 NEIGHBOR_ADDR_STR2
4478 "Specify a local-as number\n"
4479 "AS number used as local AS\n"
4480 "Do not prepend local-as to updates from ebgp peers\n")
4481{
d62a17ae 4482 int idx_peer = 1;
4483 int idx_number = 3;
4484 struct peer *peer;
4485 int ret;
4486 as_t as;
718e3744 4487
d62a17ae 4488 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4489 if (!peer)
4490 return CMD_WARNING_CONFIG_FAILED;
718e3744 4491
d62a17ae 4492 as = strtoul(argv[idx_number]->arg, NULL, 10);
4493 ret = peer_local_as_set(peer, as, 1, 0);
4494 return bgp_vty_return(vty, ret);
718e3744 4495}
4496
9d3f9705
AC
4497DEFUN (neighbor_local_as_no_prepend_replace_as,
4498 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 4499 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
4500 NEIGHBOR_STR
4501 NEIGHBOR_ADDR_STR2
4502 "Specify a local-as number\n"
4503 "AS number used as local AS\n"
4504 "Do not prepend local-as to updates from ebgp peers\n"
4505 "Do not prepend local-as to updates from ibgp peers\n")
4506{
d62a17ae 4507 int idx_peer = 1;
4508 int idx_number = 3;
4509 struct peer *peer;
4510 int ret;
4511 as_t as;
9d3f9705 4512
d62a17ae 4513 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4514 if (!peer)
4515 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4516
d62a17ae 4517 as = strtoul(argv[idx_number]->arg, NULL, 10);
4518 ret = peer_local_as_set(peer, as, 1, 1);
4519 return bgp_vty_return(vty, ret);
9d3f9705
AC
4520}
4521
718e3744 4522DEFUN (no_neighbor_local_as,
4523 no_neighbor_local_as_cmd,
a636c635 4524 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 4525 NO_STR
4526 NEIGHBOR_STR
4527 NEIGHBOR_ADDR_STR2
a636c635
DW
4528 "Specify a local-as number\n"
4529 "AS number used as local AS\n"
4530 "Do not prepend local-as to updates from ebgp peers\n"
4531 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4532{
d62a17ae 4533 int idx_peer = 2;
4534 struct peer *peer;
4535 int ret;
718e3744 4536
d62a17ae 4537 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4538 if (!peer)
4539 return CMD_WARNING_CONFIG_FAILED;
718e3744 4540
d62a17ae 4541 ret = peer_local_as_unset(peer);
4542 return bgp_vty_return(vty, ret);
718e3744 4543}
4544
718e3744 4545
3f9c7369
DS
4546DEFUN (neighbor_solo,
4547 neighbor_solo_cmd,
9ccf14f7 4548 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4549 NEIGHBOR_STR
4550 NEIGHBOR_ADDR_STR2
4551 "Solo peer - part of its own update group\n")
4552{
d62a17ae 4553 int idx_peer = 1;
4554 struct peer *peer;
4555 int ret;
3f9c7369 4556
d62a17ae 4557 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4558 if (!peer)
4559 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4560
d62a17ae 4561 ret = update_group_adjust_soloness(peer, 1);
4562 return bgp_vty_return(vty, ret);
3f9c7369
DS
4563}
4564
4565DEFUN (no_neighbor_solo,
4566 no_neighbor_solo_cmd,
9ccf14f7 4567 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4568 NO_STR
4569 NEIGHBOR_STR
4570 NEIGHBOR_ADDR_STR2
4571 "Solo peer - part of its own update group\n")
4572{
d62a17ae 4573 int idx_peer = 2;
4574 struct peer *peer;
4575 int ret;
3f9c7369 4576
d62a17ae 4577 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4578 if (!peer)
4579 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4580
d62a17ae 4581 ret = update_group_adjust_soloness(peer, 0);
4582 return bgp_vty_return(vty, ret);
3f9c7369
DS
4583}
4584
0df7c91f
PJ
4585DEFUN (neighbor_password,
4586 neighbor_password_cmd,
9ccf14f7 4587 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4588 NEIGHBOR_STR
4589 NEIGHBOR_ADDR_STR2
4590 "Set a password\n"
4591 "The password\n")
4592{
d62a17ae 4593 int idx_peer = 1;
4594 int idx_line = 3;
4595 struct peer *peer;
4596 int ret;
0df7c91f 4597
d62a17ae 4598 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4599 if (!peer)
4600 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4601
d62a17ae 4602 ret = peer_password_set(peer, argv[idx_line]->arg);
4603 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4604}
4605
4606DEFUN (no_neighbor_password,
4607 no_neighbor_password_cmd,
a636c635 4608 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4609 NO_STR
4610 NEIGHBOR_STR
4611 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4612 "Set a password\n"
4613 "The password\n")
0df7c91f 4614{
d62a17ae 4615 int idx_peer = 2;
4616 struct peer *peer;
4617 int ret;
0df7c91f 4618
d62a17ae 4619 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4620 if (!peer)
4621 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4622
d62a17ae 4623 ret = peer_password_unset(peer);
4624 return bgp_vty_return(vty, ret);
0df7c91f 4625}
6b0655a2 4626
718e3744 4627DEFUN (neighbor_activate,
4628 neighbor_activate_cmd,
9ccf14f7 4629 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4630 NEIGHBOR_STR
4631 NEIGHBOR_ADDR_STR2
4632 "Enable the Address Family for this Neighbor\n")
4633{
d62a17ae 4634 int idx_peer = 1;
4635 int ret;
4636 struct peer *peer;
718e3744 4637
d62a17ae 4638 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4639 if (!peer)
4640 return CMD_WARNING_CONFIG_FAILED;
718e3744 4641
d62a17ae 4642 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4643 return bgp_vty_return(vty, ret);
718e3744 4644}
4645
d62a17ae 4646ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4647 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4648 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4649 "Enable the Address Family for this Neighbor\n")
596c17ba 4650
718e3744 4651DEFUN (no_neighbor_activate,
4652 no_neighbor_activate_cmd,
9ccf14f7 4653 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4654 NO_STR
4655 NEIGHBOR_STR
4656 NEIGHBOR_ADDR_STR2
4657 "Enable the Address Family for this Neighbor\n")
4658{
d62a17ae 4659 int idx_peer = 2;
4660 int ret;
4661 struct peer *peer;
718e3744 4662
d62a17ae 4663 /* Lookup peer. */
4664 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4665 if (!peer)
4666 return CMD_WARNING_CONFIG_FAILED;
718e3744 4667
d62a17ae 4668 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4669 return bgp_vty_return(vty, ret);
718e3744 4670}
6b0655a2 4671
d62a17ae 4672ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4673 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4674 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4675 "Enable the Address Family for this Neighbor\n")
596c17ba 4676
718e3744 4677DEFUN (neighbor_set_peer_group,
4678 neighbor_set_peer_group_cmd,
d7b9898c 4679 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4680 NEIGHBOR_STR
a80beece 4681 NEIGHBOR_ADDR_STR2
718e3744 4682 "Member of the peer-group\n"
16cedbb0 4683 "Peer-group name\n")
718e3744 4684{
d62a17ae 4685 VTY_DECLVAR_CONTEXT(bgp, bgp);
4686 int idx_peer = 1;
4687 int idx_word = 3;
4688 int ret;
4689 as_t as;
4690 union sockunion su;
4691 struct peer *peer;
4692 struct peer_group *group;
4693
d62a17ae 4694 ret = str2sockunion(argv[idx_peer]->arg, &su);
4695 if (ret < 0) {
4696 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4697 if (!peer) {
4698 vty_out(vty, "%% Malformed address or name: %s\n",
4699 argv[idx_peer]->arg);
4700 return CMD_WARNING_CONFIG_FAILED;
4701 }
4702 } else {
4703 if (peer_address_self_check(bgp, &su)) {
4704 vty_out(vty,
4705 "%% Can not configure the local system as neighbor\n");
4706 return CMD_WARNING_CONFIG_FAILED;
4707 }
4708
4709 /* Disallow for dynamic neighbor. */
4710 peer = peer_lookup(bgp, &su);
4711 if (peer && peer_dynamic_neighbor(peer)) {
4712 vty_out(vty,
4713 "%% Operation not allowed on a dynamic neighbor\n");
4714 return CMD_WARNING_CONFIG_FAILED;
4715 }
4716 }
4717
4718 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4719 if (!group) {
4720 vty_out(vty, "%% Configure the peer-group first\n");
4721 return CMD_WARNING_CONFIG_FAILED;
4722 }
4723
4724 ret = peer_group_bind(bgp, &su, peer, group, &as);
4725
4726 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4727 vty_out(vty,
4728 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4729 as);
4730 return CMD_WARNING_CONFIG_FAILED;
4731 }
4732
4733 return bgp_vty_return(vty, ret);
4734}
4735
4736ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4737 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4738 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4739 "Member of the peer-group\n"
4740 "Peer-group name\n")
596c17ba 4741
718e3744 4742DEFUN (no_neighbor_set_peer_group,
4743 no_neighbor_set_peer_group_cmd,
d7b9898c 4744 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4745 NO_STR
4746 NEIGHBOR_STR
a80beece 4747 NEIGHBOR_ADDR_STR2
718e3744 4748 "Member of the peer-group\n"
16cedbb0 4749 "Peer-group name\n")
718e3744 4750{
d62a17ae 4751 VTY_DECLVAR_CONTEXT(bgp, bgp);
4752 int idx_peer = 2;
4753 int idx_word = 4;
4754 int ret;
4755 struct peer *peer;
4756 struct peer_group *group;
4757
4758 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4759 if (!peer)
4760 return CMD_WARNING_CONFIG_FAILED;
4761
4762 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4763 if (!group) {
4764 vty_out(vty, "%% Configure the peer-group first\n");
4765 return CMD_WARNING_CONFIG_FAILED;
4766 }
718e3744 4767
b3a3290e
DS
4768 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4769 bgp_zebra_terminate_radv(peer->bgp, peer);
4770
4e2786df 4771 peer_notify_unconfig(peer);
827ed707 4772 ret = peer_delete(peer);
718e3744 4773
d62a17ae 4774 return bgp_vty_return(vty, ret);
718e3744 4775}
6b0655a2 4776
d62a17ae 4777ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4778 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4779 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4780 "Member of the peer-group\n"
4781 "Peer-group name\n")
596c17ba 4782
d62a17ae 4783static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4784 uint32_t flag, int set)
718e3744 4785{
d62a17ae 4786 int ret;
4787 struct peer *peer;
718e3744 4788
d62a17ae 4789 peer = peer_and_group_lookup_vty(vty, ip_str);
4790 if (!peer)
4791 return CMD_WARNING_CONFIG_FAILED;
718e3744 4792
7ebe625c
QY
4793 /*
4794 * If 'neighbor <interface>', then this is for directly connected peers,
4795 * we should not accept disable-connected-check.
4796 */
4797 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4798 vty_out(vty,
3efd0893 4799 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4800 ip_str);
4801 return CMD_WARNING_CONFIG_FAILED;
4802 }
4803
d62a17ae 4804 if (!set && flag == PEER_FLAG_SHUTDOWN)
4805 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4806
d62a17ae 4807 if (set)
4808 ret = peer_flag_set(peer, flag);
4809 else
4810 ret = peer_flag_unset(peer, flag);
718e3744 4811
d62a17ae 4812 return bgp_vty_return(vty, ret);
718e3744 4813}
4814
47cbc09b 4815static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4816{
d62a17ae 4817 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4818}
4819
d62a17ae 4820static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4821 uint32_t flag)
718e3744 4822{
d62a17ae 4823 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4824}
4825
4826/* neighbor passive. */
4827DEFUN (neighbor_passive,
4828 neighbor_passive_cmd,
9ccf14f7 4829 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4830 NEIGHBOR_STR
4831 NEIGHBOR_ADDR_STR2
4832 "Don't send open messages to this neighbor\n")
4833{
d62a17ae 4834 int idx_peer = 1;
4835 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4836}
4837
4838DEFUN (no_neighbor_passive,
4839 no_neighbor_passive_cmd,
9ccf14f7 4840 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4841 NO_STR
4842 NEIGHBOR_STR
4843 NEIGHBOR_ADDR_STR2
4844 "Don't send open messages to this neighbor\n")
4845{
d62a17ae 4846 int idx_peer = 2;
4847 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4848}
6b0655a2 4849
718e3744 4850/* neighbor shutdown. */
73d70fa6
DL
4851DEFUN (neighbor_shutdown_msg,
4852 neighbor_shutdown_msg_cmd,
4853 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4854 NEIGHBOR_STR
4855 NEIGHBOR_ADDR_STR2
73d70fa6 4856 "Administratively shut down this neighbor\n"
70335e0a 4857 "Add a shutdown message (RFC 8203)\n"
73d70fa6 4858 "Shutdown message\n")
718e3744 4859{
d62a17ae 4860 int idx_peer = 1;
73d70fa6 4861
d62a17ae 4862 if (argc >= 5) {
4863 struct peer *peer =
4864 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4865 char *message;
73d70fa6 4866
d62a17ae 4867 if (!peer)
4868 return CMD_WARNING_CONFIG_FAILED;
4869 message = argv_concat(argv, argc, 4);
4870 peer_tx_shutdown_message_set(peer, message);
4871 XFREE(MTYPE_TMP, message);
4872 }
73d70fa6 4873
d62a17ae 4874 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4875}
4876
d62a17ae 4877ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4878 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4880 "Administratively shut down this neighbor\n")
73d70fa6
DL
4881
4882DEFUN (no_neighbor_shutdown_msg,
4883 no_neighbor_shutdown_msg_cmd,
4884 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4885 NO_STR
4886 NEIGHBOR_STR
4887 NEIGHBOR_ADDR_STR2
4888 "Administratively shut down this neighbor\n"
70335e0a 4889 "Remove a shutdown message (RFC 8203)\n"
73d70fa6 4890 "Shutdown message\n")
718e3744 4891{
d62a17ae 4892 int idx_peer = 2;
73d70fa6 4893
d62a17ae 4894 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4895 PEER_FLAG_SHUTDOWN);
718e3744 4896}
6b0655a2 4897
d62a17ae 4898ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4899 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4901 "Administratively shut down this neighbor\n")
73d70fa6 4902
8336c896
DA
4903DEFUN(neighbor_shutdown_rtt,
4904 neighbor_shutdown_rtt_cmd,
4905 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4906 NEIGHBOR_STR
4907 NEIGHBOR_ADDR_STR2
4908 "Administratively shut down this neighbor\n"
4909 "Shutdown if round-trip-time is higher than expected\n"
4910 "Round-trip-time in milliseconds\n"
4911 "Specify the number of keepalives before shutdown\n"
4912 "The number of keepalives with higher RTT to shutdown\n")
4913{
4914 int idx_peer = 1;
4915 int idx_rtt = 4;
4916 int idx_count = 0;
4917 struct peer *peer;
4918
4919 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4920
4921 if (!peer)
4922 return CMD_WARNING_CONFIG_FAILED;
4923
4924 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4925
4926 if (argv_find(argv, argc, "count", &idx_count))
4927 peer->rtt_keepalive_conf =
4928 strtol(argv[idx_count + 1]->arg, NULL, 10);
4929
4930 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4931 PEER_FLAG_RTT_SHUTDOWN);
4932}
4933
4934DEFUN(no_neighbor_shutdown_rtt,
4935 no_neighbor_shutdown_rtt_cmd,
4936 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
4937 NO_STR
4938 NEIGHBOR_STR
4939 NEIGHBOR_ADDR_STR2
4940 "Administratively shut down this neighbor\n"
4941 "Shutdown if round-trip-time is higher than expected\n"
4942 "Round-trip-time in milliseconds\n"
4943 "Specify the number of keepalives before shutdown\n"
4944 "The number of keepalives with higher RTT to shutdown\n")
4945{
4946 int idx_peer = 2;
4947 struct peer *peer;
4948
4949 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4950
4951 if (!peer)
4952 return CMD_WARNING_CONFIG_FAILED;
4953
4954 peer->rtt_expected = 0;
4955 peer->rtt_keepalive_conf = 1;
4956
4957 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4958 PEER_FLAG_RTT_SHUTDOWN);
4959}
4960
718e3744 4961/* neighbor capability dynamic. */
4962DEFUN (neighbor_capability_dynamic,
4963 neighbor_capability_dynamic_cmd,
9ccf14f7 4964 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR2
4967 "Advertise capability to the peer\n"
4968 "Advertise dynamic capability to this neighbor\n")
4969{
d62a17ae 4970 int idx_peer = 1;
4971 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4972 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4973}
4974
4975DEFUN (no_neighbor_capability_dynamic,
4976 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4978 NO_STR
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR2
4981 "Advertise capability to the peer\n"
4982 "Advertise dynamic capability to this neighbor\n")
4983{
d62a17ae 4984 int idx_peer = 2;
4985 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4986 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4987}
6b0655a2 4988
718e3744 4989/* neighbor dont-capability-negotiate */
4990DEFUN (neighbor_dont_capability_negotiate,
4991 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4992 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4993 NEIGHBOR_STR
4994 NEIGHBOR_ADDR_STR2
4995 "Do not perform capability negotiation\n")
4996{
d62a17ae 4997 int idx_peer = 1;
4998 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4999 PEER_FLAG_DONT_CAPABILITY);
718e3744 5000}
5001
5002DEFUN (no_neighbor_dont_capability_negotiate,
5003 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5004 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5005 NO_STR
5006 NEIGHBOR_STR
5007 NEIGHBOR_ADDR_STR2
5008 "Do not perform capability negotiation\n")
5009{
d62a17ae 5010 int idx_peer = 2;
5011 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5012 PEER_FLAG_DONT_CAPABILITY);
718e3744 5013}
6b0655a2 5014
8a92a8a0
DS
5015/* neighbor capability extended next hop encoding */
5016DEFUN (neighbor_capability_enhe,
5017 neighbor_capability_enhe_cmd,
9ccf14f7 5018 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5019 NEIGHBOR_STR
5020 NEIGHBOR_ADDR_STR2
5021 "Advertise capability to the peer\n"
5022 "Advertise extended next-hop capability to the peer\n")
5023{
d62a17ae 5024 int idx_peer = 1;
5025 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5026 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5027}
5028
5029DEFUN (no_neighbor_capability_enhe,
5030 no_neighbor_capability_enhe_cmd,
9ccf14f7 5031 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5032 NO_STR
5033 NEIGHBOR_STR
5034 NEIGHBOR_ADDR_STR2
5035 "Advertise capability to the peer\n"
5036 "Advertise extended next-hop capability to the peer\n")
5037{
d62a17ae 5038 int idx_peer = 2;
5039 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5040 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5041}
5042
d62a17ae 5043static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5044 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5045 int set)
718e3744 5046{
d62a17ae 5047 int ret;
5048 struct peer *peer;
718e3744 5049
d62a17ae 5050 peer = peer_and_group_lookup_vty(vty, peer_str);
5051 if (!peer)
5052 return CMD_WARNING_CONFIG_FAILED;
718e3744 5053
d62a17ae 5054 if (set)
5055 ret = peer_af_flag_set(peer, afi, safi, flag);
5056 else
5057 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5058
d62a17ae 5059 return bgp_vty_return(vty, ret);
718e3744 5060}
5061
d62a17ae 5062static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5063 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5064{
d62a17ae 5065 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5066}
5067
d62a17ae 5068static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5069 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5070{
d62a17ae 5071 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5072}
6b0655a2 5073
718e3744 5074/* neighbor capability orf prefix-list. */
5075DEFUN (neighbor_capability_orf_prefix,
5076 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5077 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5078 NEIGHBOR_STR
5079 NEIGHBOR_ADDR_STR2
5080 "Advertise capability to the peer\n"
5081 "Advertise ORF capability to the peer\n"
5082 "Advertise prefixlist ORF capability to this neighbor\n"
5083 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5084 "Capability to RECEIVE the ORF from this neighbor\n"
5085 "Capability to SEND the ORF to this neighbor\n")
5086{
d62a17ae 5087 int idx_send_recv = 5;
db45f64d
DS
5088 char *peer_str = argv[1]->arg;
5089 struct peer *peer;
5090 afi_t afi = bgp_node_afi(vty);
5091 safi_t safi = bgp_node_safi(vty);
d62a17ae 5092
db45f64d
DS
5093 peer = peer_and_group_lookup_vty(vty, peer_str);
5094 if (!peer)
d62a17ae 5095 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5096
db45f64d
DS
5097 if (strmatch(argv[idx_send_recv]->text, "send"))
5098 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5099 PEER_FLAG_ORF_PREFIX_SM);
5100
5101 if (strmatch(argv[idx_send_recv]->text, "receive"))
5102 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5103 PEER_FLAG_ORF_PREFIX_RM);
5104
5105 if (strmatch(argv[idx_send_recv]->text, "both"))
5106 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5107 PEER_FLAG_ORF_PREFIX_SM)
5108 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5109 PEER_FLAG_ORF_PREFIX_RM);
5110
5111 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5112}
5113
5114ALIAS_HIDDEN(
5115 neighbor_capability_orf_prefix,
5116 neighbor_capability_orf_prefix_hidden_cmd,
5117 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5119 "Advertise capability to the peer\n"
5120 "Advertise ORF capability to the peer\n"
5121 "Advertise prefixlist ORF capability to this neighbor\n"
5122 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5123 "Capability to RECEIVE the ORF from this neighbor\n"
5124 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5125
718e3744 5126DEFUN (no_neighbor_capability_orf_prefix,
5127 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5128 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5129 NO_STR
5130 NEIGHBOR_STR
5131 NEIGHBOR_ADDR_STR2
5132 "Advertise capability to the peer\n"
5133 "Advertise ORF capability to the peer\n"
5134 "Advertise prefixlist ORF capability to this neighbor\n"
5135 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5136 "Capability to RECEIVE the ORF from this neighbor\n"
5137 "Capability to SEND the ORF to this neighbor\n")
5138{
d62a17ae 5139 int idx_send_recv = 6;
db45f64d
DS
5140 char *peer_str = argv[2]->arg;
5141 struct peer *peer;
5142 afi_t afi = bgp_node_afi(vty);
5143 safi_t safi = bgp_node_safi(vty);
d62a17ae 5144
db45f64d
DS
5145 peer = peer_and_group_lookup_vty(vty, peer_str);
5146 if (!peer)
d62a17ae 5147 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5148
db45f64d
DS
5149 if (strmatch(argv[idx_send_recv]->text, "send"))
5150 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5151 PEER_FLAG_ORF_PREFIX_SM);
5152
5153 if (strmatch(argv[idx_send_recv]->text, "receive"))
5154 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5155 PEER_FLAG_ORF_PREFIX_RM);
5156
5157 if (strmatch(argv[idx_send_recv]->text, "both"))
5158 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5159 PEER_FLAG_ORF_PREFIX_SM)
5160 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5161 PEER_FLAG_ORF_PREFIX_RM);
5162
5163 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5164}
5165
5166ALIAS_HIDDEN(
5167 no_neighbor_capability_orf_prefix,
5168 no_neighbor_capability_orf_prefix_hidden_cmd,
5169 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5170 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5171 "Advertise capability to the peer\n"
5172 "Advertise ORF capability to the peer\n"
5173 "Advertise prefixlist ORF capability to this neighbor\n"
5174 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5175 "Capability to RECEIVE the ORF from this neighbor\n"
5176 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5177
718e3744 5178/* neighbor next-hop-self. */
5179DEFUN (neighbor_nexthop_self,
5180 neighbor_nexthop_self_cmd,
9ccf14f7 5181 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5182 NEIGHBOR_STR
5183 NEIGHBOR_ADDR_STR2
a538debe 5184 "Disable the next hop calculation for this neighbor\n")
718e3744 5185{
d62a17ae 5186 int idx_peer = 1;
5187 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5188 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5189}
9e7a53c1 5190
d62a17ae 5191ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5192 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5193 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5194 "Disable the next hop calculation for this neighbor\n")
596c17ba 5195
a538debe
DS
5196/* neighbor next-hop-self. */
5197DEFUN (neighbor_nexthop_self_force,
5198 neighbor_nexthop_self_force_cmd,
9ccf14f7 5199 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Disable the next hop calculation for this neighbor\n"
5203 "Set the next hop to self for reflected routes\n")
5204{
d62a17ae 5205 int idx_peer = 1;
5206 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5207 bgp_node_safi(vty),
5208 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5209}
5210
d62a17ae 5211ALIAS_HIDDEN(neighbor_nexthop_self_force,
5212 neighbor_nexthop_self_force_hidden_cmd,
5213 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5214 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5215 "Disable the next hop calculation for this neighbor\n"
5216 "Set the next hop to self for reflected routes\n")
596c17ba 5217
1bc4e531
DA
5218ALIAS_HIDDEN(neighbor_nexthop_self_force,
5219 neighbor_nexthop_self_all_hidden_cmd,
5220 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5222 "Disable the next hop calculation for this neighbor\n"
5223 "Set the next hop to self for reflected routes\n")
5224
718e3744 5225DEFUN (no_neighbor_nexthop_self,
5226 no_neighbor_nexthop_self_cmd,
9ccf14f7 5227 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5228 NO_STR
5229 NEIGHBOR_STR
5230 NEIGHBOR_ADDR_STR2
a538debe 5231 "Disable the next hop calculation for this neighbor\n")
718e3744 5232{
d62a17ae 5233 int idx_peer = 2;
5234 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5235 bgp_node_afi(vty), bgp_node_safi(vty),
5236 PEER_FLAG_NEXTHOP_SELF);
718e3744 5237}
6b0655a2 5238
d62a17ae 5239ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5240 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5242 "Disable the next hop calculation for this neighbor\n")
596c17ba 5243
88b8ed8d 5244DEFUN (no_neighbor_nexthop_self_force,
a538debe 5245 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 5246 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5247 NO_STR
5248 NEIGHBOR_STR
5249 NEIGHBOR_ADDR_STR2
5250 "Disable the next hop calculation for this neighbor\n"
5251 "Set the next hop to self for reflected routes\n")
88b8ed8d 5252{
d62a17ae 5253 int idx_peer = 2;
5254 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5255 bgp_node_afi(vty), bgp_node_safi(vty),
5256 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5257}
a538debe 5258
d62a17ae 5259ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5260 no_neighbor_nexthop_self_force_hidden_cmd,
5261 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5262 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5263 "Disable the next hop calculation for this neighbor\n"
5264 "Set the next hop to self for reflected routes\n")
596c17ba 5265
1bc4e531
DA
5266ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5267 no_neighbor_nexthop_self_all_hidden_cmd,
5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5269 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5270 "Disable the next hop calculation for this neighbor\n"
5271 "Set the next hop to self for reflected routes\n")
5272
c7122e14
DS
5273/* neighbor as-override */
5274DEFUN (neighbor_as_override,
5275 neighbor_as_override_cmd,
9ccf14f7 5276 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5277 NEIGHBOR_STR
5278 NEIGHBOR_ADDR_STR2
5279 "Override ASNs in outbound updates if aspath equals remote-as\n")
5280{
d62a17ae 5281 int idx_peer = 1;
5282 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5283 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5284}
5285
d62a17ae 5286ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5287 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5289 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5290
c7122e14
DS
5291DEFUN (no_neighbor_as_override,
5292 no_neighbor_as_override_cmd,
9ccf14f7 5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5294 NO_STR
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Override ASNs in outbound updates if aspath equals remote-as\n")
5298{
d62a17ae 5299 int idx_peer = 2;
5300 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5301 bgp_node_afi(vty), bgp_node_safi(vty),
5302 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5303}
5304
d62a17ae 5305ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5306 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5308 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5309
718e3744 5310/* neighbor remove-private-AS. */
5311DEFUN (neighbor_remove_private_as,
5312 neighbor_remove_private_as_cmd,
9ccf14f7 5313 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5314 NEIGHBOR_STR
5315 NEIGHBOR_ADDR_STR2
5000f21c 5316 "Remove private ASNs in outbound updates\n")
718e3744 5317{
d62a17ae 5318 int idx_peer = 1;
5319 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5320 bgp_node_safi(vty),
5321 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5322}
5323
d62a17ae 5324ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5325 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5327 "Remove private ASNs in outbound updates\n")
596c17ba 5328
5000f21c
DS
5329DEFUN (neighbor_remove_private_as_all,
5330 neighbor_remove_private_as_all_cmd,
9ccf14f7 5331 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5332 NEIGHBOR_STR
5333 NEIGHBOR_ADDR_STR2
5334 "Remove private ASNs in outbound updates\n"
efd7904e 5335 "Apply to all AS numbers\n")
5000f21c 5336{
d62a17ae 5337 int idx_peer = 1;
5338 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5339 bgp_node_safi(vty),
5340 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5341}
5342
d62a17ae 5343ALIAS_HIDDEN(neighbor_remove_private_as_all,
5344 neighbor_remove_private_as_all_hidden_cmd,
5345 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5346 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5347 "Remove private ASNs in outbound updates\n"
5348 "Apply to all AS numbers")
596c17ba 5349
5000f21c
DS
5350DEFUN (neighbor_remove_private_as_replace_as,
5351 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5352 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5353 NEIGHBOR_STR
5354 NEIGHBOR_ADDR_STR2
5355 "Remove private ASNs in outbound updates\n"
5356 "Replace private ASNs with our ASN in outbound updates\n")
5357{
d62a17ae 5358 int idx_peer = 1;
5359 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5360 bgp_node_safi(vty),
5361 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5362}
5363
d62a17ae 5364ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5365 neighbor_remove_private_as_replace_as_hidden_cmd,
5366 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5368 "Remove private ASNs in outbound updates\n"
5369 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5370
5000f21c
DS
5371DEFUN (neighbor_remove_private_as_all_replace_as,
5372 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5373 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Remove private ASNs in outbound updates\n"
16cedbb0 5377 "Apply to all AS numbers\n"
5000f21c
DS
5378 "Replace private ASNs with our ASN in outbound updates\n")
5379{
d62a17ae 5380 int idx_peer = 1;
5381 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5382 bgp_node_safi(vty),
5383 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5384}
5385
d62a17ae 5386ALIAS_HIDDEN(
5387 neighbor_remove_private_as_all_replace_as,
5388 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5389 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5390 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5391 "Remove private ASNs in outbound updates\n"
5392 "Apply to all AS numbers\n"
5393 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5394
718e3744 5395DEFUN (no_neighbor_remove_private_as,
5396 no_neighbor_remove_private_as_cmd,
9ccf14f7 5397 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5398 NO_STR
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR2
5000f21c 5401 "Remove private ASNs in outbound updates\n")
718e3744 5402{
d62a17ae 5403 int idx_peer = 2;
5404 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5405 bgp_node_afi(vty), bgp_node_safi(vty),
5406 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5407}
6b0655a2 5408
d62a17ae 5409ALIAS_HIDDEN(no_neighbor_remove_private_as,
5410 no_neighbor_remove_private_as_hidden_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5413 "Remove private ASNs in outbound updates\n")
596c17ba 5414
88b8ed8d 5415DEFUN (no_neighbor_remove_private_as_all,
5000f21c 5416 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 5417 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5418 NO_STR
5419 NEIGHBOR_STR
5420 NEIGHBOR_ADDR_STR2
5421 "Remove private ASNs in outbound updates\n"
16cedbb0 5422 "Apply to all AS numbers\n")
88b8ed8d 5423{
d62a17ae 5424 int idx_peer = 2;
5425 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5426 bgp_node_afi(vty), bgp_node_safi(vty),
5427 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5428}
5000f21c 5429
d62a17ae 5430ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5431 no_neighbor_remove_private_as_all_hidden_cmd,
5432 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5433 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5434 "Remove private ASNs in outbound updates\n"
5435 "Apply to all AS numbers\n")
596c17ba 5436
88b8ed8d 5437DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 5438 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5440 NO_STR
5441 NEIGHBOR_STR
5442 NEIGHBOR_ADDR_STR2
5443 "Remove private ASNs in outbound updates\n"
5444 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5445{
d62a17ae 5446 int idx_peer = 2;
5447 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5448 bgp_node_afi(vty), bgp_node_safi(vty),
5449 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5450}
5000f21c 5451
d62a17ae 5452ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5453 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5455 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5456 "Remove private ASNs in outbound updates\n"
5457 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5458
88b8ed8d 5459DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 5460 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5461 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5462 NO_STR
5463 NEIGHBOR_STR
5464 NEIGHBOR_ADDR_STR2
5465 "Remove private ASNs in outbound updates\n"
16cedbb0 5466 "Apply to all AS numbers\n"
5000f21c 5467 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5468{
d62a17ae 5469 int idx_peer = 2;
5470 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5471 bgp_node_afi(vty), bgp_node_safi(vty),
5472 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5473}
5000f21c 5474
d62a17ae 5475ALIAS_HIDDEN(
5476 no_neighbor_remove_private_as_all_replace_as,
5477 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5478 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5479 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5480 "Remove private ASNs in outbound updates\n"
5481 "Apply to all AS numbers\n"
5482 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5483
5000f21c 5484
718e3744 5485/* neighbor send-community. */
5486DEFUN (neighbor_send_community,
5487 neighbor_send_community_cmd,
9ccf14f7 5488 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5489 NEIGHBOR_STR
5490 NEIGHBOR_ADDR_STR2
5491 "Send Community attribute to this neighbor\n")
5492{
d62a17ae 5493 int idx_peer = 1;
27c05d4d 5494
d62a17ae 5495 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5496 bgp_node_safi(vty),
5497 PEER_FLAG_SEND_COMMUNITY);
718e3744 5498}
5499
d62a17ae 5500ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5501 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5502 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5503 "Send Community attribute to this neighbor\n")
596c17ba 5504
718e3744 5505DEFUN (no_neighbor_send_community,
5506 no_neighbor_send_community_cmd,
9ccf14f7 5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5508 NO_STR
5509 NEIGHBOR_STR
5510 NEIGHBOR_ADDR_STR2
5511 "Send Community attribute to this neighbor\n")
5512{
d62a17ae 5513 int idx_peer = 2;
27c05d4d 5514
d62a17ae 5515 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5516 bgp_node_afi(vty), bgp_node_safi(vty),
5517 PEER_FLAG_SEND_COMMUNITY);
718e3744 5518}
6b0655a2 5519
d62a17ae 5520ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5521 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5523 "Send Community attribute to this neighbor\n")
596c17ba 5524
718e3744 5525/* neighbor send-community extended. */
5526DEFUN (neighbor_send_community_type,
5527 neighbor_send_community_type_cmd,
57d187bc 5528 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Send Community attribute to this neighbor\n"
5532 "Send Standard and Extended Community attributes\n"
57d187bc 5533 "Send Standard, Large and Extended Community attributes\n"
718e3744 5534 "Send Extended Community attributes\n"
57d187bc
JS
5535 "Send Standard Community attributes\n"
5536 "Send Large Community attributes\n")
718e3744 5537{
27c05d4d 5538 const char *type = argv[argc - 1]->text;
db45f64d
DS
5539 char *peer_str = argv[1]->arg;
5540 struct peer *peer;
5541 afi_t afi = bgp_node_afi(vty);
5542 safi_t safi = bgp_node_safi(vty);
d62a17ae 5543
db45f64d
DS
5544 peer = peer_and_group_lookup_vty(vty, peer_str);
5545 if (!peer)
5546 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5547
db45f64d
DS
5548 if (strmatch(type, "standard"))
5549 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5550 PEER_FLAG_SEND_COMMUNITY);
5551
5552 if (strmatch(type, "extended"))
5553 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5554 PEER_FLAG_SEND_EXT_COMMUNITY);
5555
5556 if (strmatch(type, "large"))
5557 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5558 PEER_FLAG_SEND_LARGE_COMMUNITY);
5559
5560 if (strmatch(type, "both")) {
5561 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5562 PEER_FLAG_SEND_COMMUNITY)
5563 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5564 PEER_FLAG_SEND_EXT_COMMUNITY);
5565 }
5566 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5567 PEER_FLAG_SEND_COMMUNITY)
5568 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5569 PEER_FLAG_SEND_EXT_COMMUNITY)
5570 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5571 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5572}
5573
5574ALIAS_HIDDEN(
5575 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Send Community attribute to this neighbor\n"
5579 "Send Standard and Extended Community attributes\n"
5580 "Send Standard, Large and Extended Community attributes\n"
5581 "Send Extended Community attributes\n"
5582 "Send Standard Community attributes\n"
5583 "Send Large Community attributes\n")
596c17ba 5584
718e3744 5585DEFUN (no_neighbor_send_community_type,
5586 no_neighbor_send_community_type_cmd,
57d187bc 5587 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5588 NO_STR
5589 NEIGHBOR_STR
5590 NEIGHBOR_ADDR_STR2
5591 "Send Community attribute to this neighbor\n"
5592 "Send Standard and Extended Community attributes\n"
57d187bc 5593 "Send Standard, Large and Extended Community attributes\n"
718e3744 5594 "Send Extended Community attributes\n"
57d187bc
JS
5595 "Send Standard Community attributes\n"
5596 "Send Large Community attributes\n")
718e3744 5597{
d62a17ae 5598 const char *type = argv[argc - 1]->text;
db45f64d
DS
5599 char *peer_str = argv[2]->arg;
5600 struct peer *peer;
5601 afi_t afi = bgp_node_afi(vty);
5602 safi_t safi = bgp_node_safi(vty);
5603
5604 peer = peer_and_group_lookup_vty(vty, peer_str);
5605 if (!peer)
5606 return CMD_WARNING_CONFIG_FAILED;
5607
5608 if (strmatch(type, "standard"))
5609 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5610 PEER_FLAG_SEND_COMMUNITY);
5611
5612 if (strmatch(type, "extended"))
5613 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5614 PEER_FLAG_SEND_EXT_COMMUNITY);
5615
5616 if (strmatch(type, "large"))
5617 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5618 PEER_FLAG_SEND_LARGE_COMMUNITY);
5619
5620 if (strmatch(type, "both")) {
d62a17ae 5621
db45f64d
DS
5622 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5623 PEER_FLAG_SEND_COMMUNITY)
5624 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5625 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5626 }
5627
db45f64d
DS
5628 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5629 PEER_FLAG_SEND_COMMUNITY)
5630 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5631 PEER_FLAG_SEND_EXT_COMMUNITY)
5632 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5633 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5634}
5635
5636ALIAS_HIDDEN(
5637 no_neighbor_send_community_type,
5638 no_neighbor_send_community_type_hidden_cmd,
5639 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5640 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5641 "Send Community attribute to this neighbor\n"
5642 "Send Standard and Extended Community attributes\n"
5643 "Send Standard, Large and Extended Community attributes\n"
5644 "Send Extended Community attributes\n"
5645 "Send Standard Community attributes\n"
5646 "Send Large Community attributes\n")
596c17ba 5647
718e3744 5648/* neighbor soft-reconfig. */
5649DEFUN (neighbor_soft_reconfiguration,
5650 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5651 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Per neighbor soft reconfiguration\n"
5655 "Allow inbound soft reconfiguration for this neighbor\n")
5656{
d62a17ae 5657 int idx_peer = 1;
5658 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5659 bgp_node_safi(vty),
5660 PEER_FLAG_SOFT_RECONFIG);
718e3744 5661}
5662
d62a17ae 5663ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5664 neighbor_soft_reconfiguration_hidden_cmd,
5665 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5666 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5667 "Per neighbor soft reconfiguration\n"
5668 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5669
718e3744 5670DEFUN (no_neighbor_soft_reconfiguration,
5671 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5672 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5673 NO_STR
5674 NEIGHBOR_STR
5675 NEIGHBOR_ADDR_STR2
5676 "Per neighbor soft reconfiguration\n"
5677 "Allow inbound soft reconfiguration for this neighbor\n")
5678{
d62a17ae 5679 int idx_peer = 2;
5680 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5681 bgp_node_afi(vty), bgp_node_safi(vty),
5682 PEER_FLAG_SOFT_RECONFIG);
718e3744 5683}
6b0655a2 5684
d62a17ae 5685ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5686 no_neighbor_soft_reconfiguration_hidden_cmd,
5687 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5688 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5689 "Per neighbor soft reconfiguration\n"
5690 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5691
718e3744 5692DEFUN (neighbor_route_reflector_client,
5693 neighbor_route_reflector_client_cmd,
9ccf14f7 5694 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5695 NEIGHBOR_STR
5696 NEIGHBOR_ADDR_STR2
5697 "Configure a neighbor as Route Reflector client\n")
5698{
d62a17ae 5699 int idx_peer = 1;
5700 struct peer *peer;
718e3744 5701
5702
d62a17ae 5703 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5704 if (!peer)
5705 return CMD_WARNING_CONFIG_FAILED;
718e3744 5706
d62a17ae 5707 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5708 bgp_node_safi(vty),
5709 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5710}
5711
d62a17ae 5712ALIAS_HIDDEN(neighbor_route_reflector_client,
5713 neighbor_route_reflector_client_hidden_cmd,
5714 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5716 "Configure a neighbor as Route Reflector client\n")
596c17ba 5717
718e3744 5718DEFUN (no_neighbor_route_reflector_client,
5719 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5720 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5721 NO_STR
5722 NEIGHBOR_STR
5723 NEIGHBOR_ADDR_STR2
5724 "Configure a neighbor as Route Reflector client\n")
5725{
d62a17ae 5726 int idx_peer = 2;
5727 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5728 bgp_node_afi(vty), bgp_node_safi(vty),
5729 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5730}
6b0655a2 5731
d62a17ae 5732ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5733 no_neighbor_route_reflector_client_hidden_cmd,
5734 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5735 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Configure a neighbor as Route Reflector client\n")
596c17ba 5737
718e3744 5738/* neighbor route-server-client. */
5739DEFUN (neighbor_route_server_client,
5740 neighbor_route_server_client_cmd,
9ccf14f7 5741 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Configure a neighbor as Route Server client\n")
5745{
d62a17ae 5746 int idx_peer = 1;
5747 struct peer *peer;
2a3d5731 5748
d62a17ae 5749 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
5752 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5753 bgp_node_safi(vty),
5754 PEER_FLAG_RSERVER_CLIENT);
718e3744 5755}
5756
d62a17ae 5757ALIAS_HIDDEN(neighbor_route_server_client,
5758 neighbor_route_server_client_hidden_cmd,
5759 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Configure a neighbor as Route Server client\n")
596c17ba 5762
718e3744 5763DEFUN (no_neighbor_route_server_client,
5764 no_neighbor_route_server_client_cmd,
9ccf14f7 5765 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5766 NO_STR
5767 NEIGHBOR_STR
5768 NEIGHBOR_ADDR_STR2
5769 "Configure a neighbor as Route Server client\n")
fee0f4c6 5770{
d62a17ae 5771 int idx_peer = 2;
5772 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5773 bgp_node_afi(vty), bgp_node_safi(vty),
5774 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5775}
6b0655a2 5776
d62a17ae 5777ALIAS_HIDDEN(no_neighbor_route_server_client,
5778 no_neighbor_route_server_client_hidden_cmd,
5779 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5780 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5781 "Configure a neighbor as Route Server client\n")
596c17ba 5782
fee0f4c6 5783DEFUN (neighbor_nexthop_local_unchanged,
5784 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5785 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5786 NEIGHBOR_STR
5787 NEIGHBOR_ADDR_STR2
5788 "Configure treatment of outgoing link-local nexthop attribute\n"
5789 "Leave link-local nexthop unchanged for this peer\n")
5790{
d62a17ae 5791 int idx_peer = 1;
5792 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5793 bgp_node_safi(vty),
5794 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5795}
6b0655a2 5796
fee0f4c6 5797DEFUN (no_neighbor_nexthop_local_unchanged,
5798 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5799 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5800 NO_STR
5801 NEIGHBOR_STR
5802 NEIGHBOR_ADDR_STR2
5803 "Configure treatment of outgoing link-local-nexthop attribute\n"
5804 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5805{
d62a17ae 5806 int idx_peer = 2;
5807 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5808 bgp_node_afi(vty), bgp_node_safi(vty),
5809 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5810}
6b0655a2 5811
718e3744 5812DEFUN (neighbor_attr_unchanged,
5813 neighbor_attr_unchanged_cmd,
a8206004 5814 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5815 NEIGHBOR_STR
5816 NEIGHBOR_ADDR_STR2
5817 "BGP attribute is propagated unchanged to this neighbor\n"
5818 "As-path attribute\n"
5819 "Nexthop attribute\n"
a8206004 5820 "Med attribute\n")
718e3744 5821{
d62a17ae 5822 int idx = 0;
8eeb0335
DW
5823 char *peer_str = argv[1]->arg;
5824 struct peer *peer;
db45f64d
DS
5825 bool aspath = false;
5826 bool nexthop = false;
5827 bool med = false;
8eeb0335
DW
5828 afi_t afi = bgp_node_afi(vty);
5829 safi_t safi = bgp_node_safi(vty);
db45f64d 5830 int ret = 0;
8eeb0335
DW
5831
5832 peer = peer_and_group_lookup_vty(vty, peer_str);
5833 if (!peer)
5834 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5835
5836 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5837 aspath = true;
5838
d62a17ae 5839 idx = 0;
5840 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5841 nexthop = true;
5842
d62a17ae 5843 idx = 0;
5844 if (argv_find(argv, argc, "med", &idx))
db45f64d 5845 med = true;
d62a17ae 5846
8eeb0335 5847 /* no flags means all of them! */
db45f64d
DS
5848 if (!aspath && !nexthop && !med) {
5849 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5850 PEER_FLAG_AS_PATH_UNCHANGED);
5851 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5852 PEER_FLAG_NEXTHOP_UNCHANGED);
5853 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5854 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5855 } else {
db45f64d
DS
5856 if (!aspath) {
5857 if (peer_af_flag_check(peer, afi, safi,
5858 PEER_FLAG_AS_PATH_UNCHANGED)) {
5859 ret |= peer_af_flag_unset_vty(
5860 vty, peer_str, afi, safi,
5861 PEER_FLAG_AS_PATH_UNCHANGED);
5862 }
5863 } else
5864 ret |= peer_af_flag_set_vty(
5865 vty, peer_str, afi, safi,
5866 PEER_FLAG_AS_PATH_UNCHANGED);
5867
5868 if (!nexthop) {
5869 if (peer_af_flag_check(peer, afi, safi,
5870 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5871 ret |= peer_af_flag_unset_vty(
5872 vty, peer_str, afi, safi,
5873 PEER_FLAG_NEXTHOP_UNCHANGED);
5874 }
5875 } else
5876 ret |= peer_af_flag_set_vty(
5877 vty, peer_str, afi, safi,
5878 PEER_FLAG_NEXTHOP_UNCHANGED);
5879
5880 if (!med) {
5881 if (peer_af_flag_check(peer, afi, safi,
5882 PEER_FLAG_MED_UNCHANGED)) {
5883 ret |= peer_af_flag_unset_vty(
5884 vty, peer_str, afi, safi,
5885 PEER_FLAG_MED_UNCHANGED);
5886 }
5887 } else
5888 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5889 PEER_FLAG_MED_UNCHANGED);
d62a17ae 5890 }
5891
db45f64d 5892 return ret;
d62a17ae 5893}
5894
5895ALIAS_HIDDEN(
5896 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5897 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5899 "BGP attribute is propagated unchanged to this neighbor\n"
5900 "As-path attribute\n"
5901 "Nexthop attribute\n"
5902 "Med attribute\n")
596c17ba 5903
718e3744 5904DEFUN (no_neighbor_attr_unchanged,
5905 no_neighbor_attr_unchanged_cmd,
a8206004 5906 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5907 NO_STR
718e3744 5908 NEIGHBOR_STR
5909 NEIGHBOR_ADDR_STR2
31500417
DW
5910 "BGP attribute is propagated unchanged to this neighbor\n"
5911 "As-path attribute\n"
40e718b5 5912 "Nexthop attribute\n"
a8206004 5913 "Med attribute\n")
718e3744 5914{
d62a17ae 5915 int idx = 0;
db45f64d
DS
5916 char *peer_str = argv[2]->arg;
5917 struct peer *peer;
5918 bool aspath = false;
5919 bool nexthop = false;
5920 bool med = false;
5921 afi_t afi = bgp_node_afi(vty);
5922 safi_t safi = bgp_node_safi(vty);
5923 int ret = 0;
5924
5925 peer = peer_and_group_lookup_vty(vty, peer_str);
5926 if (!peer)
5927 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5928
5929 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5930 aspath = true;
5931
d62a17ae 5932 idx = 0;
5933 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5934 nexthop = true;
5935
d62a17ae 5936 idx = 0;
5937 if (argv_find(argv, argc, "med", &idx))
db45f64d 5938 med = true;
d62a17ae 5939
db45f64d
DS
5940 if (!aspath && !nexthop && !med) // no flags means all of them!
5941 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5942 PEER_FLAG_AS_PATH_UNCHANGED)
5943 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5944 PEER_FLAG_NEXTHOP_UNCHANGED)
5945 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_MED_UNCHANGED);
5947
5948 if (aspath)
5949 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5950 PEER_FLAG_AS_PATH_UNCHANGED);
5951
5952 if (nexthop)
5953 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5954 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 5955
db45f64d
DS
5956 if (med)
5957 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5958 PEER_FLAG_MED_UNCHANGED);
5959
5960 return ret;
d62a17ae 5961}
5962
5963ALIAS_HIDDEN(
5964 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5965 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5966 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "BGP attribute is propagated unchanged to this neighbor\n"
5968 "As-path attribute\n"
5969 "Nexthop attribute\n"
5970 "Med attribute\n")
718e3744 5971
718e3744 5972/* EBGP multihop configuration. */
d62a17ae 5973static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5974 const char *ttl_str)
718e3744 5975{
d62a17ae 5976 struct peer *peer;
5977 unsigned int ttl;
718e3744 5978
d62a17ae 5979 peer = peer_and_group_lookup_vty(vty, ip_str);
5980 if (!peer)
5981 return CMD_WARNING_CONFIG_FAILED;
718e3744 5982
d62a17ae 5983 if (peer->conf_if)
5984 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5985
d62a17ae 5986 if (!ttl_str)
5987 ttl = MAXTTL;
5988 else
5989 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5990
d62a17ae 5991 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5992}
5993
d62a17ae 5994static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5995{
d62a17ae 5996 struct peer *peer;
718e3744 5997
d62a17ae 5998 peer = peer_and_group_lookup_vty(vty, ip_str);
5999 if (!peer)
6000 return CMD_WARNING_CONFIG_FAILED;
718e3744 6001
d62a17ae 6002 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6003}
6004
6005/* neighbor ebgp-multihop. */
6006DEFUN (neighbor_ebgp_multihop,
6007 neighbor_ebgp_multihop_cmd,
9ccf14f7 6008 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Allow EBGP neighbors not on directly connected networks\n")
6012{
d62a17ae 6013 int idx_peer = 1;
6014 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6015}
6016
6017DEFUN (neighbor_ebgp_multihop_ttl,
6018 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 6019 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 6020 NEIGHBOR_STR
6021 NEIGHBOR_ADDR_STR2
6022 "Allow EBGP neighbors not on directly connected networks\n"
6023 "maximum hop count\n")
6024{
d62a17ae 6025 int idx_peer = 1;
6026 int idx_number = 3;
6027 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6028 argv[idx_number]->arg);
718e3744 6029}
6030
6031DEFUN (no_neighbor_ebgp_multihop,
6032 no_neighbor_ebgp_multihop_cmd,
a636c635 6033 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 6034 NO_STR
6035 NEIGHBOR_STR
6036 NEIGHBOR_ADDR_STR2
a636c635
DW
6037 "Allow EBGP neighbors not on directly connected networks\n"
6038 "maximum hop count\n")
718e3744 6039{
d62a17ae 6040 int idx_peer = 2;
6041 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6042}
6043
6b0655a2 6044
6ffd2079 6045/* disable-connected-check */
6046DEFUN (neighbor_disable_connected_check,
6047 neighbor_disable_connected_check_cmd,
7ebe625c 6048 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6049 NEIGHBOR_STR
7ebe625c 6050 NEIGHBOR_ADDR_STR2
a636c635
DW
6051 "one-hop away EBGP peer using loopback address\n"
6052 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6053{
d62a17ae 6054 int idx_peer = 1;
6055 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6056 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6057}
6058
6059DEFUN (no_neighbor_disable_connected_check,
6060 no_neighbor_disable_connected_check_cmd,
7ebe625c 6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6062 NO_STR
6063 NEIGHBOR_STR
7ebe625c 6064 NEIGHBOR_ADDR_STR2
a636c635
DW
6065 "one-hop away EBGP peer using loopback address\n"
6066 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6067{
d62a17ae 6068 int idx_peer = 2;
6069 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6070 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6071}
6072
47cbc09b
PM
6073
6074/* enforce-first-as */
6075DEFUN (neighbor_enforce_first_as,
6076 neighbor_enforce_first_as_cmd,
6077 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6078 NEIGHBOR_STR
6079 NEIGHBOR_ADDR_STR2
6080 "Enforce the first AS for EBGP routes\n")
6081{
6082 int idx_peer = 1;
6083
6084 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6085 PEER_FLAG_ENFORCE_FIRST_AS);
6086}
6087
6088DEFUN (no_neighbor_enforce_first_as,
6089 no_neighbor_enforce_first_as_cmd,
6090 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6091 NO_STR
6092 NEIGHBOR_STR
6093 NEIGHBOR_ADDR_STR2
6094 "Enforce the first AS for EBGP routes\n")
6095{
6096 int idx_peer = 2;
6097
6098 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6099 PEER_FLAG_ENFORCE_FIRST_AS);
6100}
6101
6102
718e3744 6103DEFUN (neighbor_description,
6104 neighbor_description_cmd,
e961923c 6105 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 6106 NEIGHBOR_STR
6107 NEIGHBOR_ADDR_STR2
6108 "Neighbor specific description\n"
6109 "Up to 80 characters describing this neighbor\n")
6110{
d62a17ae 6111 int idx_peer = 1;
6112 int idx_line = 3;
6113 struct peer *peer;
6114 char *str;
718e3744 6115
d62a17ae 6116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6117 if (!peer)
6118 return CMD_WARNING_CONFIG_FAILED;
718e3744 6119
d62a17ae 6120 str = argv_concat(argv, argc, idx_line);
718e3744 6121
d62a17ae 6122 peer_description_set(peer, str);
718e3744 6123
d62a17ae 6124 XFREE(MTYPE_TMP, str);
718e3744 6125
d62a17ae 6126 return CMD_SUCCESS;
718e3744 6127}
6128
6129DEFUN (no_neighbor_description,
6130 no_neighbor_description_cmd,
a14810f4 6131 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 6132 NO_STR
6133 NEIGHBOR_STR
6134 NEIGHBOR_ADDR_STR2
a14810f4 6135 "Neighbor specific description\n")
718e3744 6136{
d62a17ae 6137 int idx_peer = 2;
6138 struct peer *peer;
718e3744 6139
d62a17ae 6140 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6141 if (!peer)
6142 return CMD_WARNING_CONFIG_FAILED;
718e3744 6143
d62a17ae 6144 peer_description_unset(peer);
718e3744 6145
d62a17ae 6146 return CMD_SUCCESS;
718e3744 6147}
6148
a14810f4
PM
6149ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Neighbor specific description\n"
6153 "Up to 80 characters describing this neighbor\n")
6b0655a2 6154
718e3744 6155/* Neighbor update-source. */
d62a17ae 6156static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6157 const char *source_str)
6158{
6159 struct peer *peer;
6160 struct prefix p;
a14810f4 6161 union sockunion su;
d62a17ae 6162
6163 peer = peer_and_group_lookup_vty(vty, peer_str);
6164 if (!peer)
6165 return CMD_WARNING_CONFIG_FAILED;
6166
6167 if (peer->conf_if)
6168 return CMD_WARNING;
6169
6170 if (source_str) {
a14810f4 6171 if (str2sockunion(source_str, &su) == 0)
d62a17ae 6172 peer_update_source_addr_set(peer, &su);
6173 else {
6174 if (str2prefix(source_str, &p)) {
6175 vty_out(vty,
6176 "%% Invalid update-source, remove prefix length \n");
6177 return CMD_WARNING_CONFIG_FAILED;
6178 } else
6179 peer_update_source_if_set(peer, source_str);
6180 }
6181 } else
6182 peer_update_source_unset(peer);
6183
6184 return CMD_SUCCESS;
6185}
6186
6187#define BGP_UPDATE_SOURCE_HELP_STR \
6188 "IPv4 address\n" \
6189 "IPv6 address\n" \
6190 "Interface name (requires zebra to be running)\n"
369688c0 6191
718e3744 6192DEFUN (neighbor_update_source,
6193 neighbor_update_source_cmd,
9ccf14f7 6194 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 6195 NEIGHBOR_STR
6196 NEIGHBOR_ADDR_STR2
6197 "Source of routing updates\n"
369688c0 6198 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6199{
d62a17ae 6200 int idx_peer = 1;
6201 int idx_peer_2 = 3;
6202 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6203 argv[idx_peer_2]->arg);
718e3744 6204}
6205
6206DEFUN (no_neighbor_update_source,
6207 no_neighbor_update_source_cmd,
c7178fe7 6208 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 6209 NO_STR
6210 NEIGHBOR_STR
6211 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
6212 "Source of routing updates\n"
6213 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6214{
d62a17ae 6215 int idx_peer = 2;
6216 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6217}
6b0655a2 6218
d62a17ae 6219static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6220 afi_t afi, safi_t safi,
6221 const char *rmap, int set)
718e3744 6222{
d62a17ae 6223 int ret;
6224 struct peer *peer;
80912664 6225 struct route_map *route_map = NULL;
718e3744 6226
d62a17ae 6227 peer = peer_and_group_lookup_vty(vty, peer_str);
6228 if (!peer)
6229 return CMD_WARNING_CONFIG_FAILED;
718e3744 6230
1de27621 6231 if (set) {
80912664
DS
6232 if (rmap)
6233 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6234 ret = peer_default_originate_set(peer, afi, safi,
6235 rmap, route_map);
6236 } else
d62a17ae 6237 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6238
d62a17ae 6239 return bgp_vty_return(vty, ret);
718e3744 6240}
6241
6242/* neighbor default-originate. */
6243DEFUN (neighbor_default_originate,
6244 neighbor_default_originate_cmd,
9ccf14f7 6245 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6246 NEIGHBOR_STR
6247 NEIGHBOR_ADDR_STR2
6248 "Originate default route to this neighbor\n")
6249{
d62a17ae 6250 int idx_peer = 1;
6251 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6252 bgp_node_afi(vty),
6253 bgp_node_safi(vty), NULL, 1);
718e3744 6254}
6255
d62a17ae 6256ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6257 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6259 "Originate default route to this neighbor\n")
596c17ba 6260
718e3744 6261DEFUN (neighbor_default_originate_rmap,
6262 neighbor_default_originate_rmap_cmd,
9ccf14f7 6263 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6264 NEIGHBOR_STR
6265 NEIGHBOR_ADDR_STR2
6266 "Originate default route to this neighbor\n"
6267 "Route-map to specify criteria to originate default\n"
6268 "route-map name\n")
6269{
d62a17ae 6270 int idx_peer = 1;
6271 int idx_word = 4;
6272 return peer_default_originate_set_vty(
6273 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6274 argv[idx_word]->arg, 1);
718e3744 6275}
6276
d62a17ae 6277ALIAS_HIDDEN(
6278 neighbor_default_originate_rmap,
6279 neighbor_default_originate_rmap_hidden_cmd,
6280 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6282 "Originate default route to this neighbor\n"
6283 "Route-map to specify criteria to originate default\n"
6284 "route-map name\n")
596c17ba 6285
718e3744 6286DEFUN (no_neighbor_default_originate,
6287 no_neighbor_default_originate_cmd,
a636c635 6288 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6289 NO_STR
6290 NEIGHBOR_STR
6291 NEIGHBOR_ADDR_STR2
a636c635
DW
6292 "Originate default route to this neighbor\n"
6293 "Route-map to specify criteria to originate default\n"
6294 "route-map name\n")
718e3744 6295{
d62a17ae 6296 int idx_peer = 2;
6297 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6298 bgp_node_afi(vty),
6299 bgp_node_safi(vty), NULL, 0);
718e3744 6300}
6301
d62a17ae 6302ALIAS_HIDDEN(
6303 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6304 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6305 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6306 "Originate default route to this neighbor\n"
6307 "Route-map to specify criteria to originate default\n"
6308 "route-map name\n")
596c17ba 6309
6b0655a2 6310
718e3744 6311/* Set neighbor's BGP port. */
d62a17ae 6312static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6313 const char *port_str)
6314{
6315 struct peer *peer;
d7c0a89a 6316 uint16_t port;
d62a17ae 6317 struct servent *sp;
6318
6319 peer = peer_lookup_vty(vty, ip_str);
6320 if (!peer)
6321 return CMD_WARNING_CONFIG_FAILED;
6322
6323 if (!port_str) {
6324 sp = getservbyname("bgp", "tcp");
6325 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6326 } else {
6327 port = strtoul(port_str, NULL, 10);
6328 }
718e3744 6329
d62a17ae 6330 peer_port_set(peer, port);
718e3744 6331
d62a17ae 6332 return CMD_SUCCESS;
718e3744 6333}
6334
f418446b 6335/* Set specified peer's BGP port. */
718e3744 6336DEFUN (neighbor_port,
6337 neighbor_port_cmd,
9ccf14f7 6338 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 6339 NEIGHBOR_STR
6340 NEIGHBOR_ADDR_STR
6341 "Neighbor's BGP port\n"
6342 "TCP port number\n")
6343{
d62a17ae 6344 int idx_ip = 1;
6345 int idx_number = 3;
6346 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6347 argv[idx_number]->arg);
718e3744 6348}
6349
6350DEFUN (no_neighbor_port,
6351 no_neighbor_port_cmd,
9ccf14f7 6352 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 6353 NO_STR
6354 NEIGHBOR_STR
6355 NEIGHBOR_ADDR_STR
8334fd5a
DW
6356 "Neighbor's BGP port\n"
6357 "TCP port number\n")
718e3744 6358{
d62a17ae 6359 int idx_ip = 2;
6360 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 6361}
6362
6b0655a2 6363
718e3744 6364/* neighbor weight. */
d62a17ae 6365static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6366 safi_t safi, const char *weight_str)
718e3744 6367{
d62a17ae 6368 int ret;
6369 struct peer *peer;
6370 unsigned long weight;
718e3744 6371
d62a17ae 6372 peer = peer_and_group_lookup_vty(vty, ip_str);
6373 if (!peer)
6374 return CMD_WARNING_CONFIG_FAILED;
718e3744 6375
d62a17ae 6376 weight = strtoul(weight_str, NULL, 10);
718e3744 6377
d62a17ae 6378 ret = peer_weight_set(peer, afi, safi, weight);
6379 return bgp_vty_return(vty, ret);
718e3744 6380}
6381
d62a17ae 6382static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6383 safi_t safi)
718e3744 6384{
d62a17ae 6385 int ret;
6386 struct peer *peer;
718e3744 6387
d62a17ae 6388 peer = peer_and_group_lookup_vty(vty, ip_str);
6389 if (!peer)
6390 return CMD_WARNING_CONFIG_FAILED;
718e3744 6391
d62a17ae 6392 ret = peer_weight_unset(peer, afi, safi);
6393 return bgp_vty_return(vty, ret);
718e3744 6394}
6395
6396DEFUN (neighbor_weight,
6397 neighbor_weight_cmd,
9ccf14f7 6398 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 6399 NEIGHBOR_STR
6400 NEIGHBOR_ADDR_STR2
6401 "Set default weight for routes from this neighbor\n"
6402 "default weight\n")
6403{
d62a17ae 6404 int idx_peer = 1;
6405 int idx_number = 3;
6406 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6407 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6408}
6409
d62a17ae 6410ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6411 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6412 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6413 "Set default weight for routes from this neighbor\n"
6414 "default weight\n")
596c17ba 6415
718e3744 6416DEFUN (no_neighbor_weight,
6417 no_neighbor_weight_cmd,
9ccf14f7 6418 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 6419 NO_STR
6420 NEIGHBOR_STR
6421 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6422 "Set default weight for routes from this neighbor\n"
6423 "default weight\n")
718e3744 6424{
d62a17ae 6425 int idx_peer = 2;
6426 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6427 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6428}
6429
d62a17ae 6430ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6432 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6433 "Set default weight for routes from this neighbor\n"
6434 "default weight\n")
596c17ba 6435
6b0655a2 6436
718e3744 6437/* Override capability negotiation. */
6438DEFUN (neighbor_override_capability,
6439 neighbor_override_capability_cmd,
9ccf14f7 6440 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6441 NEIGHBOR_STR
6442 NEIGHBOR_ADDR_STR2
6443 "Override capability negotiation result\n")
6444{
d62a17ae 6445 int idx_peer = 1;
6446 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6447 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6448}
6449
6450DEFUN (no_neighbor_override_capability,
6451 no_neighbor_override_capability_cmd,
9ccf14f7 6452 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6453 NO_STR
6454 NEIGHBOR_STR
6455 NEIGHBOR_ADDR_STR2
6456 "Override capability negotiation result\n")
6457{
d62a17ae 6458 int idx_peer = 2;
6459 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6460 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6461}
6b0655a2 6462
718e3744 6463DEFUN (neighbor_strict_capability,
6464 neighbor_strict_capability_cmd,
9fb964de 6465 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6466 NEIGHBOR_STR
9fb964de 6467 NEIGHBOR_ADDR_STR2
718e3744 6468 "Strict capability negotiation match\n")
6469{
9fb964de
PM
6470 int idx_peer = 1;
6471
6472 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 6473 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6474}
6475
6476DEFUN (no_neighbor_strict_capability,
6477 no_neighbor_strict_capability_cmd,
9fb964de 6478 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6479 NO_STR
6480 NEIGHBOR_STR
9fb964de 6481 NEIGHBOR_ADDR_STR2
718e3744 6482 "Strict capability negotiation match\n")
6483{
9fb964de
PM
6484 int idx_peer = 2;
6485
6486 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 6487 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6488}
6b0655a2 6489
d62a17ae 6490static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6491 const char *keep_str, const char *hold_str)
718e3744 6492{
d62a17ae 6493 int ret;
6494 struct peer *peer;
d7c0a89a
QY
6495 uint32_t keepalive;
6496 uint32_t holdtime;
718e3744 6497
d62a17ae 6498 peer = peer_and_group_lookup_vty(vty, ip_str);
6499 if (!peer)
6500 return CMD_WARNING_CONFIG_FAILED;
718e3744 6501
d62a17ae 6502 keepalive = strtoul(keep_str, NULL, 10);
6503 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6504
d62a17ae 6505 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6506
d62a17ae 6507 return bgp_vty_return(vty, ret);
718e3744 6508}
6b0655a2 6509
d62a17ae 6510static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6511{
d62a17ae 6512 int ret;
6513 struct peer *peer;
718e3744 6514
d62a17ae 6515 peer = peer_and_group_lookup_vty(vty, ip_str);
6516 if (!peer)
6517 return CMD_WARNING_CONFIG_FAILED;
718e3744 6518
d62a17ae 6519 ret = peer_timers_unset(peer);
718e3744 6520
d62a17ae 6521 return bgp_vty_return(vty, ret);
718e3744 6522}
6523
6524DEFUN (neighbor_timers,
6525 neighbor_timers_cmd,
9ccf14f7 6526 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 6527 NEIGHBOR_STR
6528 NEIGHBOR_ADDR_STR2
6529 "BGP per neighbor timers\n"
6530 "Keepalive interval\n"
6531 "Holdtime\n")
6532{
d62a17ae 6533 int idx_peer = 1;
6534 int idx_number = 3;
6535 int idx_number_2 = 4;
6536 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6537 argv[idx_number]->arg,
6538 argv[idx_number_2]->arg);
718e3744 6539}
6540
6541DEFUN (no_neighbor_timers,
6542 no_neighbor_timers_cmd,
9ccf14f7 6543 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 6544 NO_STR
6545 NEIGHBOR_STR
6546 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6547 "BGP per neighbor timers\n"
6548 "Keepalive interval\n"
6549 "Holdtime\n")
718e3744 6550{
d62a17ae 6551 int idx_peer = 2;
6552 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6553}
6b0655a2 6554
813d4307 6555
d62a17ae 6556static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6557 const char *time_str)
718e3744 6558{
d62a17ae 6559 int ret;
6560 struct peer *peer;
d7c0a89a 6561 uint32_t connect;
718e3744 6562
d62a17ae 6563 peer = peer_and_group_lookup_vty(vty, ip_str);
6564 if (!peer)
6565 return CMD_WARNING_CONFIG_FAILED;
718e3744 6566
d62a17ae 6567 connect = strtoul(time_str, NULL, 10);
718e3744 6568
d62a17ae 6569 ret = peer_timers_connect_set(peer, connect);
718e3744 6570
d62a17ae 6571 return bgp_vty_return(vty, ret);
718e3744 6572}
6573
d62a17ae 6574static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6575{
d62a17ae 6576 int ret;
6577 struct peer *peer;
718e3744 6578
d62a17ae 6579 peer = peer_and_group_lookup_vty(vty, ip_str);
6580 if (!peer)
6581 return CMD_WARNING_CONFIG_FAILED;
718e3744 6582
d62a17ae 6583 ret = peer_timers_connect_unset(peer);
718e3744 6584
d62a17ae 6585 return bgp_vty_return(vty, ret);
718e3744 6586}
6587
6588DEFUN (neighbor_timers_connect,
6589 neighbor_timers_connect_cmd,
9ccf14f7 6590 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 6591 NEIGHBOR_STR
966f821c 6592 NEIGHBOR_ADDR_STR2
718e3744 6593 "BGP per neighbor timers\n"
6594 "BGP connect timer\n"
6595 "Connect timer\n")
6596{
d62a17ae 6597 int idx_peer = 1;
6598 int idx_number = 4;
6599 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6600 argv[idx_number]->arg);
718e3744 6601}
6602
6603DEFUN (no_neighbor_timers_connect,
6604 no_neighbor_timers_connect_cmd,
9ccf14f7 6605 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 6606 NO_STR
6607 NEIGHBOR_STR
966f821c 6608 NEIGHBOR_ADDR_STR2
718e3744 6609 "BGP per neighbor timers\n"
8334fd5a
DW
6610 "BGP connect timer\n"
6611 "Connect timer\n")
718e3744 6612{
d62a17ae 6613 int idx_peer = 2;
6614 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6615}
6616
6b0655a2 6617
d62a17ae 6618static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6619 const char *time_str, int set)
718e3744 6620{
d62a17ae 6621 int ret;
6622 struct peer *peer;
d7c0a89a 6623 uint32_t routeadv = 0;
718e3744 6624
d62a17ae 6625 peer = peer_and_group_lookup_vty(vty, ip_str);
6626 if (!peer)
6627 return CMD_WARNING_CONFIG_FAILED;
718e3744 6628
d62a17ae 6629 if (time_str)
6630 routeadv = strtoul(time_str, NULL, 10);
718e3744 6631
d62a17ae 6632 if (set)
6633 ret = peer_advertise_interval_set(peer, routeadv);
6634 else
6635 ret = peer_advertise_interval_unset(peer);
718e3744 6636
d62a17ae 6637 return bgp_vty_return(vty, ret);
718e3744 6638}
6639
6640DEFUN (neighbor_advertise_interval,
6641 neighbor_advertise_interval_cmd,
9ccf14f7 6642 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 6643 NEIGHBOR_STR
966f821c 6644 NEIGHBOR_ADDR_STR2
718e3744 6645 "Minimum interval between sending BGP routing updates\n"
6646 "time in seconds\n")
6647{
d62a17ae 6648 int idx_peer = 1;
6649 int idx_number = 3;
6650 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6651 argv[idx_number]->arg, 1);
718e3744 6652}
6653
6654DEFUN (no_neighbor_advertise_interval,
6655 no_neighbor_advertise_interval_cmd,
9ccf14f7 6656 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 6657 NO_STR
6658 NEIGHBOR_STR
966f821c 6659 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6660 "Minimum interval between sending BGP routing updates\n"
6661 "time in seconds\n")
718e3744 6662{
d62a17ae 6663 int idx_peer = 2;
6664 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6665}
6666
6b0655a2 6667
518f0eb1
DS
6668/* Time to wait before processing route-map updates */
6669DEFUN (bgp_set_route_map_delay_timer,
6670 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6671 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6672 SET_STR
6673 "BGP route-map delay timer\n"
6674 "Time in secs to wait before processing route-map changes\n"
f414725f 6675 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6676{
d62a17ae 6677 int idx_number = 3;
d7c0a89a 6678 uint32_t rmap_delay_timer;
d62a17ae 6679
6680 if (argv[idx_number]->arg) {
6681 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6682 bm->rmap_update_timer = rmap_delay_timer;
6683
6684 /* if the dynamic update handling is being disabled, and a timer
6685 * is
6686 * running, stop the timer and act as if the timer has already
6687 * fired.
6688 */
6689 if (!rmap_delay_timer && bm->t_rmap_update) {
6690 BGP_TIMER_OFF(bm->t_rmap_update);
6691 thread_execute(bm->master, bgp_route_map_update_timer,
6692 NULL, 0);
6693 }
6694 return CMD_SUCCESS;
6695 } else {
6696 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6697 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6698 }
518f0eb1
DS
6699}
6700
6701DEFUN (no_bgp_set_route_map_delay_timer,
6702 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6703 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6704 NO_STR
3a2d747c 6705 BGP_STR
518f0eb1 6706 "Default BGP route-map delay timer\n"
8334fd5a
DW
6707 "Reset to default time to wait for processing route-map changes\n"
6708 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6709{
518f0eb1 6710
d62a17ae 6711 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6712
d62a17ae 6713 return CMD_SUCCESS;
518f0eb1
DS
6714}
6715
718e3744 6716/* neighbor interface */
d62a17ae 6717static int peer_interface_vty(struct vty *vty, const char *ip_str,
6718 const char *str)
718e3744 6719{
d62a17ae 6720 struct peer *peer;
718e3744 6721
d62a17ae 6722 peer = peer_lookup_vty(vty, ip_str);
6723 if (!peer || peer->conf_if) {
6724 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6725 return CMD_WARNING_CONFIG_FAILED;
6726 }
718e3744 6727
d62a17ae 6728 if (str)
6729 peer_interface_set(peer, str);
6730 else
6731 peer_interface_unset(peer);
718e3744 6732
d62a17ae 6733 return CMD_SUCCESS;
718e3744 6734}
6735
6736DEFUN (neighbor_interface,
6737 neighbor_interface_cmd,
9ccf14f7 6738 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6739 NEIGHBOR_STR
6740 NEIGHBOR_ADDR_STR
6741 "Interface\n"
6742 "Interface name\n")
6743{
d62a17ae 6744 int idx_ip = 1;
6745 int idx_word = 3;
6746 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6747}
6748
6749DEFUN (no_neighbor_interface,
6750 no_neighbor_interface_cmd,
9ccf14f7 6751 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6752 NO_STR
6753 NEIGHBOR_STR
16cedbb0 6754 NEIGHBOR_ADDR_STR2
718e3744 6755 "Interface\n"
6756 "Interface name\n")
6757{
d62a17ae 6758 int idx_peer = 2;
6759 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6760}
6b0655a2 6761
718e3744 6762DEFUN (neighbor_distribute_list,
6763 neighbor_distribute_list_cmd,
9ccf14f7 6764 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6765 NEIGHBOR_STR
6766 NEIGHBOR_ADDR_STR2
6767 "Filter updates to/from this neighbor\n"
6768 "IP access-list number\n"
6769 "IP access-list number (expanded range)\n"
6770 "IP Access-list name\n"
6771 "Filter incoming updates\n"
6772 "Filter outgoing updates\n")
6773{
d62a17ae 6774 int idx_peer = 1;
6775 int idx_acl = 3;
6776 int direct, ret;
6777 struct peer *peer;
a8206004 6778
d62a17ae 6779 const char *pstr = argv[idx_peer]->arg;
6780 const char *acl = argv[idx_acl]->arg;
6781 const char *inout = argv[argc - 1]->text;
a8206004 6782
d62a17ae 6783 peer = peer_and_group_lookup_vty(vty, pstr);
6784 if (!peer)
6785 return CMD_WARNING_CONFIG_FAILED;
a8206004 6786
d62a17ae 6787 /* Check filter direction. */
6788 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6789 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6790 direct, acl);
a8206004 6791
d62a17ae 6792 return bgp_vty_return(vty, ret);
718e3744 6793}
6794
d62a17ae 6795ALIAS_HIDDEN(
6796 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6797 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6799 "Filter updates to/from this neighbor\n"
6800 "IP access-list number\n"
6801 "IP access-list number (expanded range)\n"
6802 "IP Access-list name\n"
6803 "Filter incoming updates\n"
6804 "Filter outgoing updates\n")
596c17ba 6805
718e3744 6806DEFUN (no_neighbor_distribute_list,
6807 no_neighbor_distribute_list_cmd,
9ccf14f7 6808 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6809 NO_STR
6810 NEIGHBOR_STR
6811 NEIGHBOR_ADDR_STR2
6812 "Filter updates to/from this neighbor\n"
6813 "IP access-list number\n"
6814 "IP access-list number (expanded range)\n"
6815 "IP Access-list name\n"
6816 "Filter incoming updates\n"
6817 "Filter outgoing updates\n")
6818{
d62a17ae 6819 int idx_peer = 2;
6820 int direct, ret;
6821 struct peer *peer;
a8206004 6822
d62a17ae 6823 const char *pstr = argv[idx_peer]->arg;
6824 const char *inout = argv[argc - 1]->text;
a8206004 6825
d62a17ae 6826 peer = peer_and_group_lookup_vty(vty, pstr);
6827 if (!peer)
6828 return CMD_WARNING_CONFIG_FAILED;
a8206004 6829
d62a17ae 6830 /* Check filter direction. */
6831 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6832 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6833 direct);
a8206004 6834
d62a17ae 6835 return bgp_vty_return(vty, ret);
718e3744 6836}
6b0655a2 6837
d62a17ae 6838ALIAS_HIDDEN(
6839 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6840 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6842 "Filter updates to/from this neighbor\n"
6843 "IP access-list number\n"
6844 "IP access-list number (expanded range)\n"
6845 "IP Access-list name\n"
6846 "Filter incoming updates\n"
6847 "Filter outgoing updates\n")
596c17ba 6848
718e3744 6849/* Set prefix list to the peer. */
d62a17ae 6850static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6851 afi_t afi, safi_t safi,
6852 const char *name_str,
6853 const char *direct_str)
718e3744 6854{
d62a17ae 6855 int ret;
d62a17ae 6856 int direct = FILTER_IN;
cf9ac8bf 6857 struct peer *peer;
718e3744 6858
d62a17ae 6859 peer = peer_and_group_lookup_vty(vty, ip_str);
6860 if (!peer)
6861 return CMD_WARNING_CONFIG_FAILED;
718e3744 6862
d62a17ae 6863 /* Check filter direction. */
6864 if (strncmp(direct_str, "i", 1) == 0)
6865 direct = FILTER_IN;
6866 else if (strncmp(direct_str, "o", 1) == 0)
6867 direct = FILTER_OUT;
718e3744 6868
d62a17ae 6869 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6870
d62a17ae 6871 return bgp_vty_return(vty, ret);
718e3744 6872}
6873
d62a17ae 6874static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6875 afi_t afi, safi_t safi,
6876 const char *direct_str)
718e3744 6877{
d62a17ae 6878 int ret;
6879 struct peer *peer;
6880 int direct = FILTER_IN;
718e3744 6881
d62a17ae 6882 peer = peer_and_group_lookup_vty(vty, ip_str);
6883 if (!peer)
6884 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6885
d62a17ae 6886 /* Check filter direction. */
6887 if (strncmp(direct_str, "i", 1) == 0)
6888 direct = FILTER_IN;
6889 else if (strncmp(direct_str, "o", 1) == 0)
6890 direct = FILTER_OUT;
718e3744 6891
d62a17ae 6892 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6893
d62a17ae 6894 return bgp_vty_return(vty, ret);
718e3744 6895}
6896
6897DEFUN (neighbor_prefix_list,
6898 neighbor_prefix_list_cmd,
9ccf14f7 6899 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6900 NEIGHBOR_STR
6901 NEIGHBOR_ADDR_STR2
6902 "Filter updates to/from this neighbor\n"
6903 "Name of a prefix list\n"
6904 "Filter incoming updates\n"
6905 "Filter outgoing updates\n")
6906{
d62a17ae 6907 int idx_peer = 1;
6908 int idx_word = 3;
6909 int idx_in_out = 4;
6910 return peer_prefix_list_set_vty(
6911 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6912 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6913}
6914
d62a17ae 6915ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6916 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6918 "Filter updates to/from this neighbor\n"
6919 "Name of a prefix list\n"
6920 "Filter incoming updates\n"
6921 "Filter outgoing updates\n")
596c17ba 6922
718e3744 6923DEFUN (no_neighbor_prefix_list,
6924 no_neighbor_prefix_list_cmd,
9ccf14f7 6925 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6926 NO_STR
6927 NEIGHBOR_STR
6928 NEIGHBOR_ADDR_STR2
6929 "Filter updates to/from this neighbor\n"
6930 "Name of a prefix list\n"
6931 "Filter incoming updates\n"
6932 "Filter outgoing updates\n")
6933{
d62a17ae 6934 int idx_peer = 2;
6935 int idx_in_out = 5;
6936 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6937 bgp_node_afi(vty), bgp_node_safi(vty),
6938 argv[idx_in_out]->arg);
718e3744 6939}
6b0655a2 6940
d62a17ae 6941ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6942 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6943 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6944 "Filter updates to/from this neighbor\n"
6945 "Name of a prefix list\n"
6946 "Filter incoming updates\n"
6947 "Filter outgoing updates\n")
596c17ba 6948
d62a17ae 6949static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6950 safi_t safi, const char *name_str,
6951 const char *direct_str)
718e3744 6952{
d62a17ae 6953 int ret;
6954 struct peer *peer;
6955 int direct = FILTER_IN;
718e3744 6956
d62a17ae 6957 peer = peer_and_group_lookup_vty(vty, ip_str);
6958 if (!peer)
6959 return CMD_WARNING_CONFIG_FAILED;
718e3744 6960
d62a17ae 6961 /* Check filter direction. */
6962 if (strncmp(direct_str, "i", 1) == 0)
6963 direct = FILTER_IN;
6964 else if (strncmp(direct_str, "o", 1) == 0)
6965 direct = FILTER_OUT;
718e3744 6966
d62a17ae 6967 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6968
d62a17ae 6969 return bgp_vty_return(vty, ret);
718e3744 6970}
6971
d62a17ae 6972static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6973 safi_t safi, const char *direct_str)
718e3744 6974{
d62a17ae 6975 int ret;
6976 struct peer *peer;
6977 int direct = FILTER_IN;
718e3744 6978
d62a17ae 6979 peer = peer_and_group_lookup_vty(vty, ip_str);
6980 if (!peer)
6981 return CMD_WARNING_CONFIG_FAILED;
718e3744 6982
d62a17ae 6983 /* Check filter direction. */
6984 if (strncmp(direct_str, "i", 1) == 0)
6985 direct = FILTER_IN;
6986 else if (strncmp(direct_str, "o", 1) == 0)
6987 direct = FILTER_OUT;
718e3744 6988
d62a17ae 6989 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6990
d62a17ae 6991 return bgp_vty_return(vty, ret);
718e3744 6992}
6993
6994DEFUN (neighbor_filter_list,
6995 neighbor_filter_list_cmd,
9ccf14f7 6996 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6997 NEIGHBOR_STR
6998 NEIGHBOR_ADDR_STR2
6999 "Establish BGP filters\n"
7000 "AS path access-list name\n"
7001 "Filter incoming routes\n"
7002 "Filter outgoing routes\n")
7003{
d62a17ae 7004 int idx_peer = 1;
7005 int idx_word = 3;
7006 int idx_in_out = 4;
7007 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7008 bgp_node_safi(vty), argv[idx_word]->arg,
7009 argv[idx_in_out]->arg);
718e3744 7010}
7011
d62a17ae 7012ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7013 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7014 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7015 "Establish BGP filters\n"
7016 "AS path access-list name\n"
7017 "Filter incoming routes\n"
7018 "Filter outgoing routes\n")
596c17ba 7019
718e3744 7020DEFUN (no_neighbor_filter_list,
7021 no_neighbor_filter_list_cmd,
9ccf14f7 7022 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7023 NO_STR
7024 NEIGHBOR_STR
7025 NEIGHBOR_ADDR_STR2
7026 "Establish BGP filters\n"
7027 "AS path access-list name\n"
7028 "Filter incoming routes\n"
7029 "Filter outgoing routes\n")
7030{
d62a17ae 7031 int idx_peer = 2;
7032 int idx_in_out = 5;
7033 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7034 bgp_node_afi(vty), bgp_node_safi(vty),
7035 argv[idx_in_out]->arg);
718e3744 7036}
6b0655a2 7037
d62a17ae 7038ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7039 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7041 "Establish BGP filters\n"
7042 "AS path access-list name\n"
7043 "Filter incoming routes\n"
7044 "Filter outgoing routes\n")
596c17ba 7045
718e3744 7046/* Set route-map to the peer. */
d62a17ae 7047static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7048 afi_t afi, safi_t safi, const char *name_str,
7049 const char *direct_str)
718e3744 7050{
d62a17ae 7051 int ret;
7052 struct peer *peer;
7053 int direct = RMAP_IN;
1de27621 7054 struct route_map *route_map;
718e3744 7055
d62a17ae 7056 peer = peer_and_group_lookup_vty(vty, ip_str);
7057 if (!peer)
7058 return CMD_WARNING_CONFIG_FAILED;
718e3744 7059
d62a17ae 7060 /* Check filter direction. */
7061 if (strncmp(direct_str, "in", 2) == 0)
7062 direct = RMAP_IN;
7063 else if (strncmp(direct_str, "o", 1) == 0)
7064 direct = RMAP_OUT;
718e3744 7065
1de27621
DA
7066 route_map = route_map_lookup_warn_noexist(vty, name_str);
7067 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7068
d62a17ae 7069 return bgp_vty_return(vty, ret);
718e3744 7070}
7071
d62a17ae 7072static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7073 afi_t afi, safi_t safi,
7074 const char *direct_str)
718e3744 7075{
d62a17ae 7076 int ret;
7077 struct peer *peer;
7078 int direct = RMAP_IN;
718e3744 7079
d62a17ae 7080 peer = peer_and_group_lookup_vty(vty, ip_str);
7081 if (!peer)
7082 return CMD_WARNING_CONFIG_FAILED;
718e3744 7083
d62a17ae 7084 /* Check filter direction. */
7085 if (strncmp(direct_str, "in", 2) == 0)
7086 direct = RMAP_IN;
7087 else if (strncmp(direct_str, "o", 1) == 0)
7088 direct = RMAP_OUT;
718e3744 7089
d62a17ae 7090 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 7091
d62a17ae 7092 return bgp_vty_return(vty, ret);
718e3744 7093}
7094
7095DEFUN (neighbor_route_map,
7096 neighbor_route_map_cmd,
9ccf14f7 7097 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7098 NEIGHBOR_STR
7099 NEIGHBOR_ADDR_STR2
7100 "Apply route map to neighbor\n"
7101 "Name of route map\n"
7102 "Apply map to incoming routes\n"
2a3d5731 7103 "Apply map to outbound routes\n")
718e3744 7104{
d62a17ae 7105 int idx_peer = 1;
7106 int idx_word = 3;
7107 int idx_in_out = 4;
7108 return peer_route_map_set_vty(
7109 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7110 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7111}
7112
d62a17ae 7113ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7114 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7115 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7116 "Apply route map to neighbor\n"
7117 "Name of route map\n"
7118 "Apply map to incoming routes\n"
7119 "Apply map to outbound routes\n")
596c17ba 7120
718e3744 7121DEFUN (no_neighbor_route_map,
7122 no_neighbor_route_map_cmd,
9ccf14f7 7123 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7124 NO_STR
7125 NEIGHBOR_STR
7126 NEIGHBOR_ADDR_STR2
7127 "Apply route map to neighbor\n"
7128 "Name of route map\n"
7129 "Apply map to incoming routes\n"
2a3d5731 7130 "Apply map to outbound routes\n")
718e3744 7131{
d62a17ae 7132 int idx_peer = 2;
7133 int idx_in_out = 5;
7134 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7135 bgp_node_afi(vty), bgp_node_safi(vty),
7136 argv[idx_in_out]->arg);
718e3744 7137}
6b0655a2 7138
d62a17ae 7139ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7140 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7141 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7142 "Apply route map to neighbor\n"
7143 "Name of route map\n"
7144 "Apply map to incoming routes\n"
7145 "Apply map to outbound routes\n")
596c17ba 7146
718e3744 7147/* Set unsuppress-map to the peer. */
d62a17ae 7148static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7149 afi_t afi, safi_t safi,
7150 const char *name_str)
718e3744 7151{
d62a17ae 7152 int ret;
7153 struct peer *peer;
1de27621 7154 struct route_map *route_map;
718e3744 7155
d62a17ae 7156 peer = peer_and_group_lookup_vty(vty, ip_str);
7157 if (!peer)
7158 return CMD_WARNING_CONFIG_FAILED;
718e3744 7159
1de27621
DA
7160 route_map = route_map_lookup_warn_noexist(vty, name_str);
7161 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7162
d62a17ae 7163 return bgp_vty_return(vty, ret);
718e3744 7164}
7165
7166/* Unset route-map from the peer. */
d62a17ae 7167static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7168 afi_t afi, safi_t safi)
718e3744 7169{
d62a17ae 7170 int ret;
7171 struct peer *peer;
718e3744 7172
d62a17ae 7173 peer = peer_and_group_lookup_vty(vty, ip_str);
7174 if (!peer)
7175 return CMD_WARNING_CONFIG_FAILED;
718e3744 7176
d62a17ae 7177 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7178
d62a17ae 7179 return bgp_vty_return(vty, ret);
718e3744 7180}
7181
7182DEFUN (neighbor_unsuppress_map,
7183 neighbor_unsuppress_map_cmd,
9ccf14f7 7184 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7185 NEIGHBOR_STR
7186 NEIGHBOR_ADDR_STR2
7187 "Route-map to selectively unsuppress suppressed routes\n"
7188 "Name of route map\n")
7189{
d62a17ae 7190 int idx_peer = 1;
7191 int idx_word = 3;
7192 return peer_unsuppress_map_set_vty(
7193 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7194 argv[idx_word]->arg);
718e3744 7195}
7196
d62a17ae 7197ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7198 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7199 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7200 "Route-map to selectively unsuppress suppressed routes\n"
7201 "Name of route map\n")
596c17ba 7202
718e3744 7203DEFUN (no_neighbor_unsuppress_map,
7204 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7205 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7206 NO_STR
7207 NEIGHBOR_STR
7208 NEIGHBOR_ADDR_STR2
7209 "Route-map to selectively unsuppress suppressed routes\n"
7210 "Name of route map\n")
7211{
d62a17ae 7212 int idx_peer = 2;
7213 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7214 bgp_node_afi(vty),
7215 bgp_node_safi(vty));
718e3744 7216}
6b0655a2 7217
d62a17ae 7218ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7219 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7221 "Route-map to selectively unsuppress suppressed routes\n"
7222 "Name of route map\n")
596c17ba 7223
d62a17ae 7224static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7225 afi_t afi, safi_t safi,
7226 const char *num_str,
7227 const char *threshold_str, int warning,
9cbd06e0
DA
7228 const char *restart_str,
7229 const char *force_str)
718e3744 7230{
d62a17ae 7231 int ret;
7232 struct peer *peer;
d7c0a89a
QY
7233 uint32_t max;
7234 uint8_t threshold;
7235 uint16_t restart;
718e3744 7236
d62a17ae 7237 peer = peer_and_group_lookup_vty(vty, ip_str);
7238 if (!peer)
7239 return CMD_WARNING_CONFIG_FAILED;
718e3744 7240
d62a17ae 7241 max = strtoul(num_str, NULL, 10);
7242 if (threshold_str)
7243 threshold = atoi(threshold_str);
7244 else
7245 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 7246
d62a17ae 7247 if (restart_str)
7248 restart = atoi(restart_str);
7249 else
7250 restart = 0;
0a486e5f 7251
d62a17ae 7252 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
9cbd06e0 7253 restart, force_str ? true : false);
718e3744 7254
d62a17ae 7255 return bgp_vty_return(vty, ret);
718e3744 7256}
7257
d62a17ae 7258static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7259 afi_t afi, safi_t safi)
718e3744 7260{
d62a17ae 7261 int ret;
7262 struct peer *peer;
718e3744 7263
d62a17ae 7264 peer = peer_and_group_lookup_vty(vty, ip_str);
7265 if (!peer)
7266 return CMD_WARNING_CONFIG_FAILED;
718e3744 7267
d62a17ae 7268 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 7269
d62a17ae 7270 return bgp_vty_return(vty, ret);
718e3744 7271}
7272
fde246e8
DA
7273/* Maximum number of prefix to be sent to the neighbor. */
7274DEFUN(neighbor_maximum_prefix_out,
7275 neighbor_maximum_prefix_out_cmd,
7276 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7277 NEIGHBOR_STR
7278 NEIGHBOR_ADDR_STR2
7279 "Maximum number of prefixes to be sent to this peer\n"
7280 "Maximum no. of prefix limit\n")
7281{
7282 int idx_peer = 1;
7283 int idx_number = 3;
7284 struct peer *peer;
7285 uint32_t max;
7286 afi_t afi = bgp_node_afi(vty);
7287 safi_t safi = bgp_node_safi(vty);
7288
7289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7290 if (!peer)
7291 return CMD_WARNING_CONFIG_FAILED;
7292
7293 max = strtoul(argv[idx_number]->arg, NULL, 10);
7294
7295 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7296 peer->pmax_out[afi][safi] = max;
7297
7298 return CMD_SUCCESS;
7299}
7300
7301DEFUN(no_neighbor_maximum_prefix_out,
7302 no_neighbor_maximum_prefix_out_cmd,
7303 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7304 NO_STR
7305 NEIGHBOR_STR
7306 NEIGHBOR_ADDR_STR2
7307 "Maximum number of prefixes to be sent to this peer\n")
7308{
7309 int idx_peer = 2;
7310 struct peer *peer;
7311 afi_t afi = bgp_node_afi(vty);
7312 safi_t safi = bgp_node_safi(vty);
7313
7314 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7315 if (!peer)
7316 return CMD_WARNING_CONFIG_FAILED;
7317
ae00326a 7318 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
7319 peer->pmax_out[afi][safi] = 0;
7320
7321 return CMD_SUCCESS;
7322}
7323
9cbd06e0
DA
7324/* Maximum number of prefix configuration. Prefix count is different
7325 for each peer configuration. So this configuration can be set for
718e3744 7326 each peer configuration. */
7327DEFUN (neighbor_maximum_prefix,
7328 neighbor_maximum_prefix_cmd,
9cbd06e0 7329 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 7330 NEIGHBOR_STR
7331 NEIGHBOR_ADDR_STR2
7332 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7333 "maximum no. of prefix limit\n"
7334 "Force checking all received routes not only accepted\n")
718e3744 7335{
d62a17ae 7336 int idx_peer = 1;
7337 int idx_number = 3;
9cbd06e0
DA
7338 int idx_force = 0;
7339 char *force = NULL;
7340
7341 if (argv_find(argv, argc, "force", &idx_force))
7342 force = argv[idx_force]->arg;
7343
d62a17ae 7344 return peer_maximum_prefix_set_vty(
7345 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7346 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7347}
7348
d62a17ae 7349ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7350 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7351 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7352 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7353 "maximum no. of prefix limit\n"
7354 "Force checking all received routes not only accepted\n")
596c17ba 7355
e0701b79 7356DEFUN (neighbor_maximum_prefix_threshold,
7357 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 7358 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 7359 NEIGHBOR_STR
7360 NEIGHBOR_ADDR_STR2
7361 "Maximum number of prefix accept from this peer\n"
7362 "maximum no. of prefix limit\n"
9cbd06e0
DA
7363 "Threshold value (%) at which to generate a warning msg\n"
7364 "Force checking all received routes not only accepted\n")
e0701b79 7365{
d62a17ae 7366 int idx_peer = 1;
7367 int idx_number = 3;
7368 int idx_number_2 = 4;
9cbd06e0
DA
7369 int idx_force = 0;
7370 char *force = NULL;
7371
7372 if (argv_find(argv, argc, "force", &idx_force))
7373 force = argv[idx_force]->arg;
7374
d62a17ae 7375 return peer_maximum_prefix_set_vty(
7376 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7377 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7378}
e0701b79 7379
d62a17ae 7380ALIAS_HIDDEN(
7381 neighbor_maximum_prefix_threshold,
7382 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7383 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7384 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7385 "Maximum number of prefix accept from this peer\n"
7386 "maximum no. of prefix limit\n"
9cbd06e0
DA
7387 "Threshold value (%) at which to generate a warning msg\n"
7388 "Force checking all received routes not only accepted\n")
596c17ba 7389
718e3744 7390DEFUN (neighbor_maximum_prefix_warning,
7391 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 7392 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 7393 NEIGHBOR_STR
7394 NEIGHBOR_ADDR_STR2
7395 "Maximum number of prefix accept from this peer\n"
7396 "maximum no. of prefix limit\n"
9cbd06e0
DA
7397 "Only give warning message when limit is exceeded\n"
7398 "Force checking all received routes not only accepted\n")
718e3744 7399{
d62a17ae 7400 int idx_peer = 1;
7401 int idx_number = 3;
9cbd06e0
DA
7402 int idx_force = 0;
7403 char *force = NULL;
7404
7405 if (argv_find(argv, argc, "force", &idx_force))
7406 force = argv[idx_force]->arg;
7407
d62a17ae 7408 return peer_maximum_prefix_set_vty(
7409 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7410 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7411}
7412
d62a17ae 7413ALIAS_HIDDEN(
7414 neighbor_maximum_prefix_warning,
7415 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7416 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7417 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7418 "Maximum number of prefix accept from this peer\n"
7419 "maximum no. of prefix limit\n"
9cbd06e0
DA
7420 "Only give warning message when limit is exceeded\n"
7421 "Force checking all received routes not only accepted\n")
596c17ba 7422
e0701b79 7423DEFUN (neighbor_maximum_prefix_threshold_warning,
7424 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 7425 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 7426 NEIGHBOR_STR
7427 NEIGHBOR_ADDR_STR2
7428 "Maximum number of prefix accept from this peer\n"
7429 "maximum no. of prefix limit\n"
7430 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7431 "Only give warning message when limit is exceeded\n"
7432 "Force checking all received routes not only accepted\n")
e0701b79 7433{
d62a17ae 7434 int idx_peer = 1;
7435 int idx_number = 3;
7436 int idx_number_2 = 4;
9cbd06e0
DA
7437 int idx_force = 0;
7438 char *force = NULL;
7439
7440 if (argv_find(argv, argc, "force", &idx_force))
7441 force = argv[idx_force]->arg;
7442
d62a17ae 7443 return peer_maximum_prefix_set_vty(
7444 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7445 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7446}
7447
d62a17ae 7448ALIAS_HIDDEN(
7449 neighbor_maximum_prefix_threshold_warning,
7450 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7451 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7452 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7453 "Maximum number of prefix accept from this peer\n"
7454 "maximum no. of prefix limit\n"
7455 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7456 "Only give warning message when limit is exceeded\n"
7457 "Force checking all received routes not only accepted\n")
596c17ba 7458
0a486e5f 7459DEFUN (neighbor_maximum_prefix_restart,
7460 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 7461 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 7462 NEIGHBOR_STR
7463 NEIGHBOR_ADDR_STR2
7464 "Maximum number of prefix accept from this peer\n"
7465 "maximum no. of prefix limit\n"
7466 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7467 "Restart interval in minutes\n"
7468 "Force checking all received routes not only accepted\n")
0a486e5f 7469{
d62a17ae 7470 int idx_peer = 1;
7471 int idx_number = 3;
7472 int idx_number_2 = 5;
9cbd06e0
DA
7473 int idx_force = 0;
7474 char *force = NULL;
7475
7476 if (argv_find(argv, argc, "force", &idx_force))
7477 force = argv[idx_force]->arg;
7478
d62a17ae 7479 return peer_maximum_prefix_set_vty(
7480 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7481 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7482}
7483
d62a17ae 7484ALIAS_HIDDEN(
7485 neighbor_maximum_prefix_restart,
7486 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7487 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7488 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7489 "Maximum number of prefix accept from this peer\n"
7490 "maximum no. of prefix limit\n"
7491 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7492 "Restart interval in minutes\n"
7493 "Force checking all received routes not only accepted\n")
596c17ba 7494
0a486e5f 7495DEFUN (neighbor_maximum_prefix_threshold_restart,
7496 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 7497 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 7498 NEIGHBOR_STR
7499 NEIGHBOR_ADDR_STR2
16cedbb0 7500 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 7501 "maximum no. of prefix limit\n"
7502 "Threshold value (%) at which to generate a warning msg\n"
7503 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7504 "Restart interval in minutes\n"
7505 "Force checking all received routes not only accepted\n")
0a486e5f 7506{
d62a17ae 7507 int idx_peer = 1;
7508 int idx_number = 3;
7509 int idx_number_2 = 4;
7510 int idx_number_3 = 6;
9cbd06e0
DA
7511 int idx_force = 0;
7512 char *force = NULL;
7513
7514 if (argv_find(argv, argc, "force", &idx_force))
7515 force = argv[idx_force]->arg;
7516
d62a17ae 7517 return peer_maximum_prefix_set_vty(
7518 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7519 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
9cbd06e0 7520 argv[idx_number_3]->arg, force);
d62a17ae 7521}
7522
7523ALIAS_HIDDEN(
7524 neighbor_maximum_prefix_threshold_restart,
7525 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7526 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7527 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7528 "Maximum number of prefixes to accept from this peer\n"
7529 "maximum no. of prefix limit\n"
7530 "Threshold value (%) at which to generate a warning msg\n"
7531 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7532 "Restart interval in minutes\n"
7533 "Force checking all received routes not only accepted\n")
596c17ba 7534
718e3744 7535DEFUN (no_neighbor_maximum_prefix,
7536 no_neighbor_maximum_prefix_cmd,
9cbd06e0 7537 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 7538 NO_STR
7539 NEIGHBOR_STR
7540 NEIGHBOR_ADDR_STR2
16cedbb0 7541 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
7542 "maximum no. of prefix limit\n"
7543 "Threshold value (%) at which to generate a warning msg\n"
7544 "Restart bgp connection after limit is exceeded\n"
16cedbb0 7545 "Restart interval in minutes\n"
9cbd06e0
DA
7546 "Only give warning message when limit is exceeded\n"
7547 "Force checking all received routes not only accepted\n")
718e3744 7548{
d62a17ae 7549 int idx_peer = 2;
7550 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7551 bgp_node_afi(vty),
7552 bgp_node_safi(vty));
718e3744 7553}
e52702f2 7554
d62a17ae 7555ALIAS_HIDDEN(
7556 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7557 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7558 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7559 "Maximum number of prefixes to accept from this peer\n"
7560 "maximum no. of prefix limit\n"
7561 "Threshold value (%) at which to generate a warning msg\n"
7562 "Restart bgp connection after limit is exceeded\n"
7563 "Restart interval in minutes\n"
9cbd06e0
DA
7564 "Only give warning message when limit is exceeded\n"
7565 "Force checking all received routes not only accepted\n")
596c17ba 7566
718e3744 7567
718e3744 7568/* "neighbor allowas-in" */
7569DEFUN (neighbor_allowas_in,
7570 neighbor_allowas_in_cmd,
fd8503f5 7571 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7572 NEIGHBOR_STR
7573 NEIGHBOR_ADDR_STR2
31500417 7574 "Accept as-path with my AS present in it\n"
f79f7a7b 7575 "Number of occurrences of AS number\n"
fd8503f5 7576 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7577{
d62a17ae 7578 int idx_peer = 1;
7579 int idx_number_origin = 3;
7580 int ret;
7581 int origin = 0;
7582 struct peer *peer;
7583 int allow_num = 0;
7584
7585 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7586 if (!peer)
7587 return CMD_WARNING_CONFIG_FAILED;
7588
7589 if (argc <= idx_number_origin)
7590 allow_num = 3;
7591 else {
7592 if (argv[idx_number_origin]->type == WORD_TKN)
7593 origin = 1;
7594 else
7595 allow_num = atoi(argv[idx_number_origin]->arg);
7596 }
7597
7598 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7599 allow_num, origin);
7600
7601 return bgp_vty_return(vty, ret);
7602}
7603
7604ALIAS_HIDDEN(
7605 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7606 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7607 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7608 "Accept as-path with my AS present in it\n"
f79f7a7b 7609 "Number of occurrences of AS number\n"
d62a17ae 7610 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7611
718e3744 7612DEFUN (no_neighbor_allowas_in,
7613 no_neighbor_allowas_in_cmd,
fd8503f5 7614 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7615 NO_STR
7616 NEIGHBOR_STR
7617 NEIGHBOR_ADDR_STR2
8334fd5a 7618 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7619 "Number of occurrences of AS number\n"
fd8503f5 7620 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7621{
d62a17ae 7622 int idx_peer = 2;
7623 int ret;
7624 struct peer *peer;
718e3744 7625
d62a17ae 7626 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7627 if (!peer)
7628 return CMD_WARNING_CONFIG_FAILED;
718e3744 7629
d62a17ae 7630 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7631 bgp_node_safi(vty));
718e3744 7632
d62a17ae 7633 return bgp_vty_return(vty, ret);
718e3744 7634}
6b0655a2 7635
d62a17ae 7636ALIAS_HIDDEN(
7637 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7638 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7640 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7641 "Number of occurrences of AS number\n"
d62a17ae 7642 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7643
fa411a21
NH
7644DEFUN (neighbor_ttl_security,
7645 neighbor_ttl_security_cmd,
7ebe625c 7646 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 7647 NEIGHBOR_STR
7ebe625c 7648 NEIGHBOR_ADDR_STR2
16cedbb0 7649 "BGP ttl-security parameters\n"
d7fa34c1
QY
7650 "Specify the maximum number of hops to the BGP peer\n"
7651 "Number of hops to BGP peer\n")
fa411a21 7652{
d62a17ae 7653 int idx_peer = 1;
7654 int idx_number = 4;
7655 struct peer *peer;
7656 int gtsm_hops;
7657
7658 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7659 if (!peer)
7660 return CMD_WARNING_CONFIG_FAILED;
7661
7662 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7663
7ebe625c
QY
7664 /*
7665 * If 'neighbor swpX', then this is for directly connected peers,
7666 * we should not accept a ttl-security hops value greater than 1.
7667 */
e2521429 7668 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
7669 vty_out(vty,
7670 "%s is directly connected peer, hops cannot exceed 1\n",
7671 argv[idx_peer]->arg);
7672 return CMD_WARNING_CONFIG_FAILED;
7673 }
7674
d62a17ae 7675 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7676}
7677
7678DEFUN (no_neighbor_ttl_security,
7679 no_neighbor_ttl_security_cmd,
7ebe625c 7680 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
7681 NO_STR
7682 NEIGHBOR_STR
7ebe625c 7683 NEIGHBOR_ADDR_STR2
16cedbb0 7684 "BGP ttl-security parameters\n"
3a2d747c
QY
7685 "Specify the maximum number of hops to the BGP peer\n"
7686 "Number of hops to BGP peer\n")
fa411a21 7687{
d62a17ae 7688 int idx_peer = 2;
7689 struct peer *peer;
fa411a21 7690
d62a17ae 7691 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7692 if (!peer)
7693 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7694
d62a17ae 7695 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7696}
6b0655a2 7697
adbac85e
DW
7698DEFUN (neighbor_addpath_tx_all_paths,
7699 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7700 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7701 NEIGHBOR_STR
7702 NEIGHBOR_ADDR_STR2
7703 "Use addpath to advertise all paths to a neighbor\n")
7704{
d62a17ae 7705 int idx_peer = 1;
7706 struct peer *peer;
adbac85e 7707
d62a17ae 7708 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7709 if (!peer)
7710 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7711
dcc68b5e
MS
7712 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7713 BGP_ADDPATH_ALL);
7714 return CMD_SUCCESS;
adbac85e
DW
7715}
7716
d62a17ae 7717ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7718 neighbor_addpath_tx_all_paths_hidden_cmd,
7719 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7721 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7722
adbac85e
DW
7723DEFUN (no_neighbor_addpath_tx_all_paths,
7724 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7725 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7726 NO_STR
7727 NEIGHBOR_STR
7728 NEIGHBOR_ADDR_STR2
7729 "Use addpath to advertise all paths to a neighbor\n")
7730{
d62a17ae 7731 int idx_peer = 2;
dcc68b5e
MS
7732 struct peer *peer;
7733
7734 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7735 if (!peer)
7736 return CMD_WARNING_CONFIG_FAILED;
7737
7738 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7739 != BGP_ADDPATH_ALL) {
7740 vty_out(vty,
7741 "%% Peer not currently configured to transmit all paths.");
7742 return CMD_WARNING_CONFIG_FAILED;
7743 }
7744
7745 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7746 BGP_ADDPATH_NONE);
7747
7748 return CMD_SUCCESS;
adbac85e
DW
7749}
7750
d62a17ae 7751ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7752 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7753 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7754 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7755 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7756
06370dac
DW
7757DEFUN (neighbor_addpath_tx_bestpath_per_as,
7758 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7759 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7760 NEIGHBOR_STR
7761 NEIGHBOR_ADDR_STR2
7762 "Use addpath to advertise the bestpath per each neighboring AS\n")
7763{
d62a17ae 7764 int idx_peer = 1;
7765 struct peer *peer;
06370dac 7766
d62a17ae 7767 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7768 if (!peer)
7769 return CMD_WARNING_CONFIG_FAILED;
06370dac 7770
dcc68b5e
MS
7771 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7772 BGP_ADDPATH_BEST_PER_AS);
7773
7774 return CMD_SUCCESS;
06370dac
DW
7775}
7776
d62a17ae 7777ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7778 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7779 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7781 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7782
06370dac
DW
7783DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7784 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7785 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7786 NO_STR
7787 NEIGHBOR_STR
7788 NEIGHBOR_ADDR_STR2
7789 "Use addpath to advertise the bestpath per each neighboring AS\n")
7790{
d62a17ae 7791 int idx_peer = 2;
dcc68b5e
MS
7792 struct peer *peer;
7793
7794 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7795 if (!peer)
7796 return CMD_WARNING_CONFIG_FAILED;
7797
7798 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7799 != BGP_ADDPATH_BEST_PER_AS) {
7800 vty_out(vty,
7801 "%% Peer not currently configured to transmit all best path per as.");
7802 return CMD_WARNING_CONFIG_FAILED;
7803 }
7804
7805 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7806 BGP_ADDPATH_NONE);
7807
7808 return CMD_SUCCESS;
06370dac
DW
7809}
7810
d62a17ae 7811ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7812 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7813 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7814 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7815 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7816
2b31007c
RZ
7817DEFPY(
7818 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7819 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7820 NEIGHBOR_STR
7821 NEIGHBOR_ADDR_STR2
7822 "Detect AS loops before sending to neighbor\n")
7823{
7824 struct peer *peer;
7825
7826 peer = peer_and_group_lookup_vty(vty, neighbor);
7827 if (!peer)
7828 return CMD_WARNING_CONFIG_FAILED;
7829
7830 peer->as_path_loop_detection = true;
7831
7832 return CMD_SUCCESS;
7833}
7834
7835DEFPY(
7836 no_neighbor_aspath_loop_detection,
7837 no_neighbor_aspath_loop_detection_cmd,
7838 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7839 NO_STR
7840 NEIGHBOR_STR
7841 NEIGHBOR_ADDR_STR2
7842 "Detect AS loops before sending to neighbor\n")
7843{
7844 struct peer *peer;
7845
7846 peer = peer_and_group_lookup_vty(vty, neighbor);
7847 if (!peer)
7848 return CMD_WARNING_CONFIG_FAILED;
7849
7850 peer->as_path_loop_detection = false;
7851
7852 return CMD_SUCCESS;
7853}
7854
b9c7bc5a 7855static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 7856 struct ecommunity **list, bool is_rt6)
ddb5b488 7857{
b9c7bc5a
PZ
7858 struct ecommunity *ecom = NULL;
7859 struct ecommunity *ecomadd;
ddb5b488 7860
b9c7bc5a 7861 for (; argc; --argc, ++argv) {
9a659715
PG
7862 if (is_rt6)
7863 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
7864 ECOMMUNITY_ROUTE_TARGET,
7865 0);
7866 else
7867 ecomadd = ecommunity_str2com(argv[0]->arg,
7868 ECOMMUNITY_ROUTE_TARGET,
7869 0);
b9c7bc5a
PZ
7870 if (!ecomadd) {
7871 vty_out(vty, "Malformed community-list value\n");
7872 if (ecom)
7873 ecommunity_free(&ecom);
7874 return CMD_WARNING_CONFIG_FAILED;
7875 }
ddb5b488 7876
b9c7bc5a
PZ
7877 if (ecom) {
7878 ecommunity_merge(ecom, ecomadd);
7879 ecommunity_free(&ecomadd);
7880 } else {
7881 ecom = ecomadd;
7882 }
7883 }
7884
7885 if (*list) {
7886 ecommunity_free(&*list);
ddb5b488 7887 }
b9c7bc5a
PZ
7888 *list = ecom;
7889
7890 return CMD_SUCCESS;
ddb5b488
PZ
7891}
7892
0ca70ba5
DS
7893/*
7894 * v2vimport is true if we are handling a `import vrf ...` command
7895 */
7896static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7897{
0ca70ba5
DS
7898 afi_t afi;
7899
ddb5b488 7900 switch (vty->node) {
b9c7bc5a 7901 case BGP_IPV4_NODE:
0ca70ba5
DS
7902 afi = AFI_IP;
7903 break;
b9c7bc5a 7904 case BGP_IPV6_NODE:
0ca70ba5
DS
7905 afi = AFI_IP6;
7906 break;
ddb5b488
PZ
7907 default:
7908 vty_out(vty,
b9c7bc5a 7909 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7910 return AFI_MAX;
ddb5b488 7911 }
69b07479 7912
0ca70ba5
DS
7913 if (!v2vimport) {
7914 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7915 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7916 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7917 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7918 vty_out(vty,
7919 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7920 return AFI_MAX;
7921 }
7922 } else {
7923 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7924 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7925 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7926 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7927 vty_out(vty,
7928 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7929 return AFI_MAX;
7930 }
7931 }
7932 return afi;
ddb5b488
PZ
7933}
7934
b9c7bc5a
PZ
7935DEFPY (af_rd_vpn_export,
7936 af_rd_vpn_export_cmd,
7937 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7938 NO_STR
ddb5b488 7939 "Specify route distinguisher\n"
b9c7bc5a
PZ
7940 "Between current address-family and vpn\n"
7941 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7942 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7943{
7944 VTY_DECLVAR_CONTEXT(bgp, bgp);
7945 struct prefix_rd prd;
7946 int ret;
ddb5b488 7947 afi_t afi;
b9c7bc5a 7948 int idx = 0;
c6423c31 7949 bool yes = true;
ddb5b488 7950
b9c7bc5a 7951 if (argv_find(argv, argc, "no", &idx))
c6423c31 7952 yes = false;
b9c7bc5a
PZ
7953
7954 if (yes) {
7955 ret = str2prefix_rd(rd_str, &prd);
7956 if (!ret) {
7957 vty_out(vty, "%% Malformed rd\n");
7958 return CMD_WARNING_CONFIG_FAILED;
7959 }
ddb5b488
PZ
7960 }
7961
0ca70ba5 7962 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7963 if (afi == AFI_MAX)
7964 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7965
69b07479
DS
7966 /*
7967 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7968 */
7969 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7970 bgp_get_default(), bgp);
ddb5b488 7971
69b07479
DS
7972 if (yes) {
7973 bgp->vpn_policy[afi].tovpn_rd = prd;
7974 SET_FLAG(bgp->vpn_policy[afi].flags,
7975 BGP_VPN_POLICY_TOVPN_RD_SET);
7976 } else {
7977 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7978 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7979 }
7980
69b07479
DS
7981 /* post-change: re-export vpn routes */
7982 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7983 bgp_get_default(), bgp);
7984
ddb5b488
PZ
7985 return CMD_SUCCESS;
7986}
7987
b9c7bc5a
PZ
7988ALIAS (af_rd_vpn_export,
7989 af_no_rd_vpn_export_cmd,
7990 "no rd vpn export",
ddb5b488 7991 NO_STR
b9c7bc5a
PZ
7992 "Specify route distinguisher\n"
7993 "Between current address-family and vpn\n"
7994 "For routes leaked from current address-family to vpn\n")
ddb5b488 7995
b9c7bc5a
PZ
7996DEFPY (af_label_vpn_export,
7997 af_label_vpn_export_cmd,
e70e9f8e 7998 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 7999 NO_STR
ddb5b488 8000 "label value for VRF\n"
b9c7bc5a
PZ
8001 "Between current address-family and vpn\n"
8002 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8003 "Label Value <0-1048575>\n"
8004 "Automatically assign a label\n")
ddb5b488
PZ
8005{
8006 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8007 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8008 afi_t afi;
b9c7bc5a 8009 int idx = 0;
c6423c31 8010 bool yes = true;
b9c7bc5a
PZ
8011
8012 if (argv_find(argv, argc, "no", &idx))
c6423c31 8013 yes = false;
ddb5b488 8014
21a16cc2
PZ
8015 /* If "no ...", squash trailing parameter */
8016 if (!yes)
8017 label_auto = NULL;
8018
e70e9f8e
PZ
8019 if (yes) {
8020 if (!label_auto)
8021 label = label_val; /* parser should force unsigned */
8022 }
ddb5b488 8023
0ca70ba5 8024 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8025 if (afi == AFI_MAX)
8026 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8027
e70e9f8e 8028
69b07479
DS
8029 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8030 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8031 /* no change */
8032 return CMD_SUCCESS;
e70e9f8e 8033
69b07479
DS
8034 /*
8035 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8036 */
8037 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8038 bgp_get_default(), bgp);
8039
8040 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8041 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8042
8043 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8044
8045 /*
8046 * label has previously been automatically
8047 * assigned by labelpool: release it
8048 *
8049 * NB if tovpn_label == MPLS_LABEL_NONE it
8050 * means the automatic assignment is in flight
8051 * and therefore the labelpool callback must
8052 * detect that the auto label is not needed.
8053 */
8054
8055 bgp_lp_release(LP_TYPE_VRF,
8056 &bgp->vpn_policy[afi],
8057 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8058 }
69b07479
DS
8059 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8060 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8061 }
ddb5b488 8062
69b07479
DS
8063 bgp->vpn_policy[afi].tovpn_label = label;
8064 if (label_auto) {
8065 SET_FLAG(bgp->vpn_policy[afi].flags,
8066 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8067 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8068 vpn_leak_label_callback);
ddb5b488
PZ
8069 }
8070
69b07479
DS
8071 /* post-change: re-export vpn routes */
8072 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8073 bgp_get_default(), bgp);
8074
ddb5b488
PZ
8075 return CMD_SUCCESS;
8076}
8077
b9c7bc5a
PZ
8078ALIAS (af_label_vpn_export,
8079 af_no_label_vpn_export_cmd,
8080 "no label vpn export",
8081 NO_STR
8082 "label value for VRF\n"
8083 "Between current address-family and vpn\n"
8084 "For routes leaked from current address-family to vpn\n")
ddb5b488 8085
b9c7bc5a
PZ
8086DEFPY (af_nexthop_vpn_export,
8087 af_nexthop_vpn_export_cmd,
8c85ca28 8088 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8089 NO_STR
ddb5b488 8090 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8091 "Between current address-family and vpn\n"
8092 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8093 "IPv4 prefix\n"
8094 "IPv6 prefix\n")
8095{
8096 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8097 afi_t afi;
ddb5b488
PZ
8098 struct prefix p;
8099
8c85ca28
QY
8100 if (!no) {
8101 if (!nexthop_su) {
8102 vty_out(vty, "%% Nexthop required\n");
8103 return CMD_WARNING_CONFIG_FAILED;
8104 }
8c85ca28 8105 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8106 return CMD_WARNING_CONFIG_FAILED;
8107 }
ddb5b488 8108
0ca70ba5 8109 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8110 if (afi == AFI_MAX)
8111 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8112
69b07479
DS
8113 /*
8114 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8115 */
8116 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8117 bgp_get_default(), bgp);
ddb5b488 8118
8c85ca28 8119 if (!no) {
69b07479
DS
8120 bgp->vpn_policy[afi].tovpn_nexthop = p;
8121 SET_FLAG(bgp->vpn_policy[afi].flags,
8122 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8123 } else {
8124 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8125 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
8126 }
8127
69b07479
DS
8128 /* post-change: re-export vpn routes */
8129 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8130 bgp_get_default(), bgp);
8131
ddb5b488
PZ
8132 return CMD_SUCCESS;
8133}
8134
b9c7bc5a 8135static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8136{
b9c7bc5a
PZ
8137 if (!strcmp(dstr, "import")) {
8138 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8139 } else if (!strcmp(dstr, "export")) {
8140 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8141 } else if (!strcmp(dstr, "both")) {
8142 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8143 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8144 } else {
8145 vty_out(vty, "%% direction parse error\n");
8146 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8147 }
ddb5b488
PZ
8148 return CMD_SUCCESS;
8149}
8150
b9c7bc5a
PZ
8151DEFPY (af_rt_vpn_imexport,
8152 af_rt_vpn_imexport_cmd,
8153 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8154 NO_STR
8155 "Specify route target list\n"
ddb5b488 8156 "Specify route target list\n"
b9c7bc5a
PZ
8157 "Between current address-family and vpn\n"
8158 "For routes leaked from vpn to current address-family: match any\n"
8159 "For routes leaked from current address-family to vpn: set\n"
8160 "both import: match any and export: set\n"
ddb5b488
PZ
8161 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8162{
8163 VTY_DECLVAR_CONTEXT(bgp, bgp);
8164 int ret;
8165 struct ecommunity *ecom = NULL;
8166 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8167 vpn_policy_direction_t dir;
8168 afi_t afi;
8169 int idx = 0;
c6423c31 8170 bool yes = true;
ddb5b488 8171
b9c7bc5a 8172 if (argv_find(argv, argc, "no", &idx))
c6423c31 8173 yes = false;
b9c7bc5a 8174
0ca70ba5 8175 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8176 if (afi == AFI_MAX)
8177 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8178
b9c7bc5a 8179 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8180 if (ret != CMD_SUCCESS)
8181 return ret;
8182
b9c7bc5a
PZ
8183 if (yes) {
8184 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8185 vty_out(vty, "%% Missing RTLIST\n");
8186 return CMD_WARNING_CONFIG_FAILED;
8187 }
c6423c31 8188 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8189 if (ret != CMD_SUCCESS) {
8190 return ret;
8191 }
ddb5b488
PZ
8192 }
8193
69b07479
DS
8194 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8195 if (!dodir[dir])
ddb5b488 8196 continue;
ddb5b488 8197
69b07479 8198 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8199
69b07479
DS
8200 if (yes) {
8201 if (bgp->vpn_policy[afi].rtlist[dir])
8202 ecommunity_free(
8203 &bgp->vpn_policy[afi].rtlist[dir]);
8204 bgp->vpn_policy[afi].rtlist[dir] =
8205 ecommunity_dup(ecom);
8206 } else {
8207 if (bgp->vpn_policy[afi].rtlist[dir])
8208 ecommunity_free(
8209 &bgp->vpn_policy[afi].rtlist[dir]);
8210 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8211 }
69b07479
DS
8212
8213 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8214 }
69b07479 8215
d555f3e9
PZ
8216 if (ecom)
8217 ecommunity_free(&ecom);
ddb5b488
PZ
8218
8219 return CMD_SUCCESS;
8220}
8221
b9c7bc5a
PZ
8222ALIAS (af_rt_vpn_imexport,
8223 af_no_rt_vpn_imexport_cmd,
8224 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8225 NO_STR
8226 "Specify route target list\n"
b9c7bc5a
PZ
8227 "Specify route target list\n"
8228 "Between current address-family and vpn\n"
8229 "For routes leaked from vpn to current address-family\n"
8230 "For routes leaked from current address-family to vpn\n"
8231 "both import and export\n")
8232
8233DEFPY (af_route_map_vpn_imexport,
8234 af_route_map_vpn_imexport_cmd,
8235/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8236 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8237 NO_STR
ddb5b488 8238 "Specify route map\n"
b9c7bc5a
PZ
8239 "Between current address-family and vpn\n"
8240 "For routes leaked from vpn to current address-family\n"
8241 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8242 "name of route-map\n")
8243{
8244 VTY_DECLVAR_CONTEXT(bgp, bgp);
8245 int ret;
8246 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8247 vpn_policy_direction_t dir;
8248 afi_t afi;
ddb5b488 8249 int idx = 0;
c6423c31 8250 bool yes = true;
ddb5b488 8251
b9c7bc5a 8252 if (argv_find(argv, argc, "no", &idx))
c6423c31 8253 yes = false;
b9c7bc5a 8254
0ca70ba5 8255 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8256 if (afi == AFI_MAX)
8257 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8258
b9c7bc5a 8259 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8260 if (ret != CMD_SUCCESS)
8261 return ret;
8262
69b07479
DS
8263 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8264 if (!dodir[dir])
ddb5b488 8265 continue;
ddb5b488 8266
69b07479 8267 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8268
69b07479
DS
8269 if (yes) {
8270 if (bgp->vpn_policy[afi].rmap_name[dir])
8271 XFREE(MTYPE_ROUTE_MAP_NAME,
8272 bgp->vpn_policy[afi].rmap_name[dir]);
8273 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8274 MTYPE_ROUTE_MAP_NAME, rmap_str);
8275 bgp->vpn_policy[afi].rmap[dir] =
1de27621 8276 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
8277 if (!bgp->vpn_policy[afi].rmap[dir])
8278 return CMD_SUCCESS;
8279 } else {
8280 if (bgp->vpn_policy[afi].rmap_name[dir])
8281 XFREE(MTYPE_ROUTE_MAP_NAME,
8282 bgp->vpn_policy[afi].rmap_name[dir]);
8283 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8284 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 8285 }
69b07479
DS
8286
8287 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
8288 }
8289
8290 return CMD_SUCCESS;
8291}
8292
b9c7bc5a
PZ
8293ALIAS (af_route_map_vpn_imexport,
8294 af_no_route_map_vpn_imexport_cmd,
8295 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8296 NO_STR
8297 "Specify route map\n"
b9c7bc5a
PZ
8298 "Between current address-family and vpn\n"
8299 "For routes leaked from vpn to current address-family\n"
8300 "For routes leaked from current address-family to vpn\n")
8301
bb4f6190 8302DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8303 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8304 "Import routes from another VRF\n"
8305 "Vrf routes being filtered\n"
8306 "Specify route map\n"
8307 "name of route-map\n")
8308{
8309 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8310 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8311 afi_t afi;
bb4f6190
DS
8312 struct bgp *bgp_default;
8313
0ca70ba5 8314 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8315 if (afi == AFI_MAX)
8316 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8317
8318 bgp_default = bgp_get_default();
8319 if (!bgp_default) {
8320 int32_t ret;
8321 as_t as = bgp->as;
8322
8323 /* Auto-create assuming the same AS */
5d5393b9
DL
8324 ret = bgp_get_vty(&bgp_default, &as, NULL,
8325 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8326
8327 if (ret) {
8328 vty_out(vty,
8329 "VRF default is not configured as a bgp instance\n");
8330 return CMD_WARNING;
8331 }
8332 }
8333
69b07479 8334 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8335
ae6a6fb4
DS
8336 if (bgp->vpn_policy[afi].rmap_name[dir])
8337 XFREE(MTYPE_ROUTE_MAP_NAME,
8338 bgp->vpn_policy[afi].rmap_name[dir]);
8339 bgp->vpn_policy[afi].rmap_name[dir] =
8340 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8341 bgp->vpn_policy[afi].rmap[dir] =
8342 route_map_lookup_warn_noexist(vty, rmap_str);
8343 if (!bgp->vpn_policy[afi].rmap[dir])
8344 return CMD_SUCCESS;
8345
8346 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8347 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8348
69b07479
DS
8349 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8350
bb4f6190
DS
8351 return CMD_SUCCESS;
8352}
8353
ae6a6fb4
DS
8354DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8355 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8356 NO_STR
8357 "Import routes from another VRF\n"
8358 "Vrf routes being filtered\n"
ae6a6fb4
DS
8359 "Specify route map\n"
8360 "name of route-map\n")
8361{
8362 VTY_DECLVAR_CONTEXT(bgp, bgp);
8363 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8364 afi_t afi;
8365
8366 afi = vpn_policy_getafi(vty, bgp, true);
8367 if (afi == AFI_MAX)
8368 return CMD_WARNING_CONFIG_FAILED;
8369
8370 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8371
8372 if (bgp->vpn_policy[afi].rmap_name[dir])
8373 XFREE(MTYPE_ROUTE_MAP_NAME,
8374 bgp->vpn_policy[afi].rmap_name[dir]);
8375 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8376 bgp->vpn_policy[afi].rmap[dir] = NULL;
8377
8378 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8379 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8380 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8381
8382 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8383
8384 return CMD_SUCCESS;
8385}
bb4f6190 8386
4d1b335c
DA
8387DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8388 "[no] import vrf VIEWVRFNAME$import_name",
8389 NO_STR
8390 "Import routes from another VRF\n"
8391 "VRF to import from\n"
8392 "The name of the VRF\n")
12a844a5
DS
8393{
8394 VTY_DECLVAR_CONTEXT(bgp, bgp);
8395 struct listnode *node;
79ef8664
DS
8396 struct bgp *vrf_bgp, *bgp_default;
8397 int32_t ret = 0;
8398 as_t as = bgp->as;
12a844a5
DS
8399 bool remove = false;
8400 int32_t idx = 0;
8401 char *vname;
a8dadcf6 8402 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8403 safi_t safi;
8404 afi_t afi;
8405
867f0cca 8406 if (import_name == NULL) {
8407 vty_out(vty, "%% Missing import name\n");
8408 return CMD_WARNING;
8409 }
8410
ae6a6fb4
DS
8411 if (strcmp(import_name, "route-map") == 0) {
8412 vty_out(vty, "%% Must include route-map name\n");
8413 return CMD_WARNING;
8414 }
8415
12a844a5
DS
8416 if (argv_find(argv, argc, "no", &idx))
8417 remove = true;
8418
0ca70ba5
DS
8419 afi = vpn_policy_getafi(vty, bgp, true);
8420 if (afi == AFI_MAX)
8421 return CMD_WARNING_CONFIG_FAILED;
8422
12a844a5
DS
8423 safi = bgp_node_safi(vty);
8424
25679caa 8425 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 8426 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
8427 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8428 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8429 remove ? "unimport" : "import", import_name);
8430 return CMD_WARNING;
8431 }
8432
79ef8664
DS
8433 bgp_default = bgp_get_default();
8434 if (!bgp_default) {
8435 /* Auto-create assuming the same AS */
5d5393b9
DL
8436 ret = bgp_get_vty(&bgp_default, &as, NULL,
8437 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
8438
8439 if (ret) {
8440 vty_out(vty,
8441 "VRF default is not configured as a bgp instance\n");
8442 return CMD_WARNING;
8443 }
8444 }
8445
12a844a5
DS
8446 vrf_bgp = bgp_lookup_by_name(import_name);
8447 if (!vrf_bgp) {
5742e42b 8448 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
8449 vrf_bgp = bgp_default;
8450 else
0fb8d6e6 8451 /* Auto-create assuming the same AS */
5d5393b9 8452 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 8453
6e2c7fe6 8454 if (ret) {
020a3f60
DS
8455 vty_out(vty,
8456 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
8457 import_name);
8458 return CMD_WARNING;
8459 }
12a844a5
DS
8460 }
8461
12a844a5 8462 if (remove) {
44338987 8463 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 8464 } else {
44338987 8465 /* Already importing from "import_vrf"? */
12a844a5
DS
8466 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8467 vname)) {
8468 if (strcmp(vname, import_name) == 0)
8469 return CMD_WARNING;
8470 }
8471
44338987 8472 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
8473 }
8474
8475 return CMD_SUCCESS;
8476}
8477
b9c7bc5a
PZ
8478/* This command is valid only in a bgp vrf instance or the default instance */
8479DEFPY (bgp_imexport_vpn,
8480 bgp_imexport_vpn_cmd,
8481 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8482 NO_STR
8483 "Import routes to this address-family\n"
8484 "Export routes from this address-family\n"
8485 "to/from default instance VPN RIB\n")
ddb5b488
PZ
8486{
8487 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8488 int previous_state;
ddb5b488 8489 afi_t afi;
b9c7bc5a 8490 safi_t safi;
ddb5b488 8491 int idx = 0;
c6423c31 8492 bool yes = true;
b9c7bc5a
PZ
8493 int flag;
8494 vpn_policy_direction_t dir;
ddb5b488 8495
b9c7bc5a 8496 if (argv_find(argv, argc, "no", &idx))
c6423c31 8497 yes = false;
ddb5b488 8498
b9c7bc5a
PZ
8499 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8500 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 8501
b9c7bc5a
PZ
8502 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8503 return CMD_WARNING_CONFIG_FAILED;
8504 }
ddb5b488 8505
b9c7bc5a
PZ
8506 afi = bgp_node_afi(vty);
8507 safi = bgp_node_safi(vty);
8508 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8509 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8510 return CMD_WARNING_CONFIG_FAILED;
8511 }
ddb5b488 8512
b9c7bc5a
PZ
8513 if (!strcmp(direction_str, "import")) {
8514 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8515 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8516 } else if (!strcmp(direction_str, "export")) {
8517 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8518 dir = BGP_VPN_POLICY_DIR_TOVPN;
8519 } else {
8520 vty_out(vty, "%% unknown direction %s\n", direction_str);
8521 return CMD_WARNING_CONFIG_FAILED;
8522 }
8523
8524 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8525
b9c7bc5a
PZ
8526 if (yes) {
8527 SET_FLAG(bgp->af_flags[afi][safi], flag);
8528 if (!previous_state) {
8529 /* trigger export current vrf */
ddb5b488
PZ
8530 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8531 }
b9c7bc5a
PZ
8532 } else {
8533 if (previous_state) {
8534 /* trigger un-export current vrf */
8535 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8536 }
8537 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
8538 }
8539
8540 return CMD_SUCCESS;
8541}
8542
301ad80a
PG
8543DEFPY (af_routetarget_import,
8544 af_routetarget_import_cmd,
9a659715 8545 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8546 NO_STR
8547 "Specify route target list\n"
8548 "Specify route target list\n"
9a659715
PG
8549 "Specify route target list\n"
8550 "Specify route target list\n"
301ad80a
PG
8551 "Flow-spec redirect type route target\n"
8552 "Import routes to this address-family\n"
9a659715 8553 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8554{
8555 VTY_DECLVAR_CONTEXT(bgp, bgp);
8556 int ret;
8557 struct ecommunity *ecom = NULL;
301ad80a 8558 afi_t afi;
9a659715 8559 int idx = 0, idx_unused = 0;
c6423c31
PG
8560 bool yes = true;
8561 bool rt6 = false;
301ad80a
PG
8562
8563 if (argv_find(argv, argc, "no", &idx))
c6423c31 8564 yes = false;
301ad80a 8565
9a659715
PG
8566 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8567 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 8568 rt6 = true;
301ad80a 8569
0ca70ba5 8570 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8571 if (afi == AFI_MAX)
8572 return CMD_WARNING_CONFIG_FAILED;
8573
9a659715
PG
8574 if (rt6 && afi != AFI_IP6)
8575 return CMD_WARNING_CONFIG_FAILED;
8576
301ad80a
PG
8577 if (yes) {
8578 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8579 vty_out(vty, "%% Missing RTLIST\n");
8580 return CMD_WARNING_CONFIG_FAILED;
8581 }
9a659715 8582 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8583 if (ret != CMD_SUCCESS)
8584 return ret;
8585 }
69b07479
DS
8586
8587 if (yes) {
8588 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8589 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8590 .import_redirect_rtlist);
69b07479
DS
8591 bgp->vpn_policy[afi].import_redirect_rtlist =
8592 ecommunity_dup(ecom);
8593 } else {
8594 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8595 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8596 .import_redirect_rtlist);
69b07479 8597 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8598 }
69b07479 8599
301ad80a
PG
8600 if (ecom)
8601 ecommunity_free(&ecom);
8602
8603 return CMD_SUCCESS;
8604}
8605
505e5056 8606DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8607 address_family_ipv4_safi_cmd,
8608 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8609 "Enter Address Family command mode\n"
8610 "Address Family\n"
8611 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8612{
f51bae9c 8613
d62a17ae 8614 if (argc == 3) {
2131d5cf 8615 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8616 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8617 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8618 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8619 && safi != SAFI_EVPN) {
31947174
MK
8620 vty_out(vty,
8621 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8622 return CMD_WARNING_CONFIG_FAILED;
8623 }
d62a17ae 8624 vty->node = bgp_node_type(AFI_IP, safi);
8625 } else
8626 vty->node = BGP_IPV4_NODE;
718e3744 8627
d62a17ae 8628 return CMD_SUCCESS;
718e3744 8629}
8630
505e5056 8631DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8632 address_family_ipv6_safi_cmd,
8633 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8634 "Enter Address Family command mode\n"
8635 "Address Family\n"
8636 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8637{
d62a17ae 8638 if (argc == 3) {
2131d5cf 8639 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8640 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8641 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8642 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8643 && safi != SAFI_EVPN) {
31947174
MK
8644 vty_out(vty,
8645 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8646 return CMD_WARNING_CONFIG_FAILED;
8647 }
d62a17ae 8648 vty->node = bgp_node_type(AFI_IP6, safi);
8649 } else
8650 vty->node = BGP_IPV6_NODE;
25ffbdc1 8651
d62a17ae 8652 return CMD_SUCCESS;
25ffbdc1 8653}
718e3744 8654
d6902373 8655#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8656DEFUN_NOSH (address_family_vpnv4,
718e3744 8657 address_family_vpnv4_cmd,
8334fd5a 8658 "address-family vpnv4 [unicast]",
718e3744 8659 "Enter Address Family command mode\n"
8c3deaae 8660 "Address Family\n"
3a2d747c 8661 "Address Family modifier\n")
718e3744 8662{
d62a17ae 8663 vty->node = BGP_VPNV4_NODE;
8664 return CMD_SUCCESS;
718e3744 8665}
8666
505e5056 8667DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8668 address_family_vpnv6_cmd,
8334fd5a 8669 "address-family vpnv6 [unicast]",
8ecd3266 8670 "Enter Address Family command mode\n"
8c3deaae 8671 "Address Family\n"
3a2d747c 8672 "Address Family modifier\n")
8ecd3266 8673{
d62a17ae 8674 vty->node = BGP_VPNV6_NODE;
8675 return CMD_SUCCESS;
8ecd3266 8676}
64e4a6c5 8677#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8678
505e5056 8679DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8680 address_family_evpn_cmd,
7111c1a0 8681 "address-family l2vpn evpn",
4e0b7b6d 8682 "Enter Address Family command mode\n"
7111c1a0
QY
8683 "Address Family\n"
8684 "Address Family modifier\n")
4e0b7b6d 8685{
2131d5cf 8686 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8687 vty->node = BGP_EVPN_NODE;
8688 return CMD_SUCCESS;
4e0b7b6d
PG
8689}
8690
505e5056 8691DEFUN_NOSH (exit_address_family,
718e3744 8692 exit_address_family_cmd,
8693 "exit-address-family",
8694 "Exit from Address Family configuration mode\n")
8695{
d62a17ae 8696 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8697 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8698 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8699 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8700 || vty->node == BGP_EVPN_NODE
8701 || vty->node == BGP_FLOWSPECV4_NODE
8702 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8703 vty->node = BGP_NODE;
8704 return CMD_SUCCESS;
718e3744 8705}
6b0655a2 8706
8ad7271d 8707/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8708static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8709 const char *ip_str, afi_t afi, safi_t safi,
8710 struct prefix_rd *prd)
8711{
8712 int ret;
8713 struct prefix match;
9bcb3eef
DS
8714 struct bgp_dest *dest;
8715 struct bgp_dest *rm;
d62a17ae 8716 struct bgp *bgp;
8717 struct bgp_table *table;
8718 struct bgp_table *rib;
8719
8720 /* BGP structure lookup. */
8721 if (view_name) {
8722 bgp = bgp_lookup_by_name(view_name);
8723 if (bgp == NULL) {
8724 vty_out(vty, "%% Can't find BGP instance %s\n",
8725 view_name);
8726 return CMD_WARNING;
8727 }
8728 } else {
8729 bgp = bgp_get_default();
8730 if (bgp == NULL) {
8731 vty_out(vty, "%% No BGP process is configured\n");
8732 return CMD_WARNING;
8733 }
8734 }
8735
8736 /* Check IP address argument. */
8737 ret = str2prefix(ip_str, &match);
8738 if (!ret) {
8739 vty_out(vty, "%% address is malformed\n");
8740 return CMD_WARNING;
8741 }
8742
8743 match.family = afi2family(afi);
8744 rib = bgp->rib[afi][safi];
8745
8746 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8747 for (dest = bgp_table_top(rib); dest;
8748 dest = bgp_route_next(dest)) {
8749 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8750
9bcb3eef 8751 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8752 continue;
8753
9bcb3eef 8754 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8755 if (table == NULL)
8756 continue;
8757
8758 if ((rm = bgp_node_match(table, &match)) != NULL) {
8759 const struct prefix *rm_p =
9bcb3eef 8760 bgp_dest_get_prefix(rm);
b54892e0
DS
8761
8762 if (rm_p->prefixlen == match.prefixlen) {
8763 SET_FLAG(rm->flags,
8764 BGP_NODE_USER_CLEAR);
8765 bgp_process(bgp, rm, afi, safi);
d62a17ae 8766 }
9bcb3eef 8767 bgp_dest_unlock_node(rm);
d62a17ae 8768 }
8769 }
8770 } else {
9bcb3eef
DS
8771 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8772 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8773
9bcb3eef
DS
8774 if (dest_p->prefixlen == match.prefixlen) {
8775 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8776 bgp_process(bgp, dest, afi, safi);
d62a17ae 8777 }
9bcb3eef 8778 bgp_dest_unlock_node(dest);
d62a17ae 8779 }
8780 }
8781
8782 return CMD_SUCCESS;
8ad7271d
DS
8783}
8784
b09b5ae0 8785/* one clear bgp command to rule them all */
718e3744 8786DEFUN (clear_ip_bgp_all,
8787 clear_ip_bgp_all_cmd,
453c92f6 8788 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
718e3744 8789 CLEAR_STR
8790 IP_STR
8791 BGP_STR
838758ac 8792 BGP_INSTANCE_HELP_STR
510afcd6 8793 BGP_AFI_HELP_STR
fd5e7b70 8794 "Address Family\n"
510afcd6 8795 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8796 "Address Family modifier\n"
b09b5ae0 8797 "Clear all peers\n"
453c92f6 8798 "BGP IPv4 neighbor to clear\n"
a80beece 8799 "BGP IPv6 neighbor to clear\n"
838758ac 8800 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8801 "Clear peers with the AS number\n"
8802 "Clear all external peers\n"
718e3744 8803 "Clear all members of peer-group\n"
b09b5ae0 8804 "BGP peer-group name\n"
b09b5ae0
DW
8805 BGP_SOFT_STR
8806 BGP_SOFT_IN_STR
b09b5ae0
DW
8807 BGP_SOFT_OUT_STR
8808 BGP_SOFT_IN_STR
8809 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8810 BGP_SOFT_OUT_STR)
718e3744 8811{
d62a17ae 8812 char *vrf = NULL;
8813
dc912615
DS
8814 afi_t afi = AFI_UNSPEC;
8815 safi_t safi = SAFI_UNSPEC;
d62a17ae 8816 enum clear_sort clr_sort = clear_peer;
8817 enum bgp_clear_type clr_type;
8818 char *clr_arg = NULL;
8819
8820 int idx = 0;
ff8a8a7a
CS
8821 char errmsg[BUFSIZ] = {'\0'};
8822 int ret;
d62a17ae 8823
8824 /* clear [ip] bgp */
8825 if (argv_find(argv, argc, "ip", &idx))
8826 afi = AFI_IP;
8827
9a8bdf1c
PG
8828 /* [<vrf> VIEWVRFNAME] */
8829 if (argv_find(argv, argc, "vrf", &idx)) {
8830 vrf = argv[idx + 1]->arg;
8831 idx += 2;
8832 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8833 vrf = NULL;
8834 } else if (argv_find(argv, argc, "view", &idx)) {
8835 /* [<view> VIEWVRFNAME] */
d62a17ae 8836 vrf = argv[idx + 1]->arg;
8837 idx += 2;
8838 }
d62a17ae 8839 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8840 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8841 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8842
d7b9898c 8843 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8844 if (argv_find(argv, argc, "*", &idx)) {
8845 clr_sort = clear_all;
8846 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8847 clr_sort = clear_peer;
8848 clr_arg = argv[idx]->arg;
8849 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8850 clr_sort = clear_peer;
8851 clr_arg = argv[idx]->arg;
8852 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8853 clr_sort = clear_group;
8854 idx++;
8855 clr_arg = argv[idx]->arg;
d7b9898c 8856 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8857 clr_sort = clear_peer;
8858 clr_arg = argv[idx]->arg;
8fa7d444
DS
8859 } else if (argv_find(argv, argc, "WORD", &idx)) {
8860 clr_sort = clear_peer;
8861 clr_arg = argv[idx]->arg;
d62a17ae 8862 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8863 clr_sort = clear_as;
8864 clr_arg = argv[idx]->arg;
8865 } else if (argv_find(argv, argc, "external", &idx)) {
8866 clr_sort = clear_external;
8867 }
8868
8869 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8870 if (argv_find(argv, argc, "soft", &idx)) {
8871 if (argv_find(argv, argc, "in", &idx)
8872 || argv_find(argv, argc, "out", &idx))
8873 clr_type = strmatch(argv[idx]->text, "in")
8874 ? BGP_CLEAR_SOFT_IN
8875 : BGP_CLEAR_SOFT_OUT;
8876 else
8877 clr_type = BGP_CLEAR_SOFT_BOTH;
8878 } else if (argv_find(argv, argc, "in", &idx)) {
8879 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8880 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8881 : BGP_CLEAR_SOFT_IN;
8882 } else if (argv_find(argv, argc, "out", &idx)) {
8883 clr_type = BGP_CLEAR_SOFT_OUT;
8884 } else
8885 clr_type = BGP_CLEAR_SOFT_NONE;
8886
ff8a8a7a
CS
8887 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
8888 sizeof(errmsg));
8889 if (ret != NB_OK)
8890 vty_out(vty, "Error description: %s\n", errmsg);
8891
8892 return ret;
838758ac 8893}
01080f7c 8894
8ad7271d
DS
8895DEFUN (clear_ip_bgp_prefix,
8896 clear_ip_bgp_prefix_cmd,
18c57037 8897 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8898 CLEAR_STR
8899 IP_STR
8900 BGP_STR
838758ac 8901 BGP_INSTANCE_HELP_STR
8ad7271d 8902 "Clear bestpath and re-advertise\n"
0c7b1b01 8903 "IPv4 prefix\n")
8ad7271d 8904{
d62a17ae 8905 char *vrf = NULL;
8906 char *prefix = NULL;
8ad7271d 8907
d62a17ae 8908 int idx = 0;
01080f7c 8909
d62a17ae 8910 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8911 if (argv_find(argv, argc, "vrf", &idx)) {
8912 vrf = argv[idx + 1]->arg;
8913 idx += 2;
8914 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8915 vrf = NULL;
8916 } else if (argv_find(argv, argc, "view", &idx)) {
8917 /* [<view> VIEWVRFNAME] */
8918 vrf = argv[idx + 1]->arg;
8919 idx += 2;
8920 }
0c7b1b01 8921
d62a17ae 8922 prefix = argv[argc - 1]->arg;
8ad7271d 8923
d62a17ae 8924 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8925}
8ad7271d 8926
b09b5ae0
DW
8927DEFUN (clear_bgp_ipv6_safi_prefix,
8928 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8929 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8930 CLEAR_STR
3a2d747c 8931 IP_STR
718e3744 8932 BGP_STR
8c3deaae 8933 "Address Family\n"
46f296b4 8934 BGP_SAFI_HELP_STR
b09b5ae0 8935 "Clear bestpath and re-advertise\n"
0c7b1b01 8936 "IPv6 prefix\n")
718e3744 8937{
9b475e76
PG
8938 int idx_safi = 0;
8939 int idx_ipv6_prefix = 0;
8940 safi_t safi = SAFI_UNICAST;
8941 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8942 argv[idx_ipv6_prefix]->arg : NULL;
8943
8944 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8945 return bgp_clear_prefix(
9b475e76
PG
8946 vty, NULL, prefix, AFI_IP6,
8947 safi, NULL);
838758ac 8948}
01080f7c 8949
b09b5ae0
DW
8950DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8951 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8952 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8953 CLEAR_STR
3a2d747c 8954 IP_STR
718e3744 8955 BGP_STR
838758ac 8956 BGP_INSTANCE_HELP_STR
8c3deaae 8957 "Address Family\n"
46f296b4 8958 BGP_SAFI_HELP_STR
b09b5ae0 8959 "Clear bestpath and re-advertise\n"
0c7b1b01 8960 "IPv6 prefix\n")
718e3744 8961{
9b475e76 8962 int idx_safi = 0;
9a8bdf1c 8963 int idx_vrfview = 0;
9b475e76
PG
8964 int idx_ipv6_prefix = 0;
8965 safi_t safi = SAFI_UNICAST;
8966 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8967 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8968 char *vrfview = NULL;
9b475e76 8969
9a8bdf1c
PG
8970 /* [<view|vrf> VIEWVRFNAME] */
8971 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8972 vrfview = argv[idx_vrfview + 1]->arg;
8973 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8974 vrfview = NULL;
8975 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8976 /* [<view> VIEWVRFNAME] */
8977 vrfview = argv[idx_vrfview + 1]->arg;
8978 }
9b475e76
PG
8979 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8980
d62a17ae 8981 return bgp_clear_prefix(
9b475e76
PG
8982 vty, vrfview, prefix,
8983 AFI_IP6, safi, NULL);
718e3744 8984}
8985
b09b5ae0
DW
8986DEFUN (show_bgp_views,
8987 show_bgp_views_cmd,
d6e3c605 8988 "show [ip] bgp views",
b09b5ae0 8989 SHOW_STR
d6e3c605 8990 IP_STR
01080f7c 8991 BGP_STR
b09b5ae0 8992 "Show the defined BGP views\n")
01080f7c 8993{
d62a17ae 8994 struct list *inst = bm->bgp;
8995 struct listnode *node;
8996 struct bgp *bgp;
01080f7c 8997
d62a17ae 8998 vty_out(vty, "Defined BGP views:\n");
8999 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9000 /* Skip VRFs. */
9001 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9002 continue;
9003 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9004 bgp->as);
9005 }
e52702f2 9006
d62a17ae 9007 return CMD_SUCCESS;
e0081f70
ML
9008}
9009
8386ac43 9010DEFUN (show_bgp_vrfs,
9011 show_bgp_vrfs_cmd,
d6e3c605 9012 "show [ip] bgp vrfs [json]",
8386ac43 9013 SHOW_STR
d6e3c605 9014 IP_STR
8386ac43 9015 BGP_STR
9016 "Show BGP VRFs\n"
9973d184 9017 JSON_STR)
8386ac43 9018{
fe1dc5a3 9019 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9020 struct list *inst = bm->bgp;
9021 struct listnode *node;
9022 struct bgp *bgp;
9f049418 9023 bool uj = use_json(argc, argv);
d62a17ae 9024 json_object *json = NULL;
9025 json_object *json_vrfs = NULL;
9026 int count = 0;
d62a17ae 9027
d62a17ae 9028 if (uj) {
9029 json = json_object_new_object();
9030 json_vrfs = json_object_new_object();
9031 }
9032
9033 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9034 const char *name, *type;
9035 struct peer *peer;
7fe96307 9036 struct listnode *node2, *nnode2;
d62a17ae 9037 int peers_cfg, peers_estb;
9038 json_object *json_vrf = NULL;
d62a17ae 9039
9040 /* Skip Views. */
9041 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9042 continue;
9043
9044 count++;
efb4077a 9045 if (!uj && count == 1) {
fe1dc5a3 9046 vty_out(vty,
efb4077a 9047 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9048 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9049 "#PeersEstb", "Name");
9050 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9051 "L3-VNI", "RouterMAC", "Interface");
9052 }
d62a17ae 9053
9054 peers_cfg = peers_estb = 0;
9055 if (uj)
9056 json_vrf = json_object_new_object();
9057
9058
7fe96307 9059 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9060 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9061 continue;
9062 peers_cfg++;
9063 if (peer->status == Established)
9064 peers_estb++;
9065 }
9066
9067 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9068 name = VRF_DEFAULT_NAME;
d62a17ae 9069 type = "DFLT";
9070 } else {
9071 name = bgp->name;
9072 type = "VRF";
9073 }
9074
a8bf7d9c 9075
d62a17ae 9076 if (uj) {
a4d82a8a
PZ
9077 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9078 ? -1
9079 : (int64_t)bgp->vrf_id;
23d0a753
DA
9080 char buf[BUFSIZ] = {0};
9081
d62a17ae 9082 json_object_string_add(json_vrf, "type", type);
9083 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9084 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
9085 inet_ntop(AF_INET,
9086 &bgp->router_id, buf,
9087 sizeof(buf)));
d62a17ae 9088 json_object_int_add(json_vrf, "numConfiguredPeers",
9089 peers_cfg);
9090 json_object_int_add(json_vrf, "numEstablishedPeers",
9091 peers_estb);
9092
fe1dc5a3 9093 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9094 json_object_string_add(
9095 json_vrf, "rmac",
9096 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9097 json_object_string_add(json_vrf, "interface",
9098 ifindex2ifname(bgp->l3vni_svi_ifindex,
9099 bgp->vrf_id));
d62a17ae 9100 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9101 } else {
23d0a753 9102 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
9103 type,
9104 bgp->vrf_id == VRF_UNKNOWN ? -1
9105 : (int)bgp->vrf_id,
23d0a753 9106 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
9107 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
9108 bgp->l3vni,
9109 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
9110 ifindex2ifname(bgp->l3vni_svi_ifindex,
9111 bgp->vrf_id));
9112 }
d62a17ae 9113 }
9114
9115 if (uj) {
9116 json_object_object_add(json, "vrfs", json_vrfs);
9117
9118 json_object_int_add(json, "totalVrfs", count);
9119
996c9314
LB
9120 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9121 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9122 json_object_free(json);
9123 } else {
9124 if (count)
9125 vty_out(vty,
9126 "\nTotal number of VRFs (including default): %d\n",
9127 count);
9128 }
9129
9130 return CMD_SUCCESS;
8386ac43 9131}
9132
48ecf8f5
DS
9133DEFUN (show_bgp_mac_hash,
9134 show_bgp_mac_hash_cmd,
9135 "show bgp mac hash",
9136 SHOW_STR
9137 BGP_STR
9138 "Mac Address\n"
9139 "Mac Address database\n")
9140{
9141 bgp_mac_dump_table(vty);
9142
9143 return CMD_SUCCESS;
9144}
acf71666 9145
e3b78da8 9146static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 9147{
0291c246 9148 struct vty *vty = (struct vty *)args;
e3b78da8 9149 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 9150
23d0a753 9151 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
9152}
9153
9154static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9155{
9156 vty_out(vty, "self nexthop database:\n");
af97a18b 9157 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9158
9159 vty_out(vty, "Tunnel-ip database:\n");
9160 hash_iterate(bgp->tip_hash,
e3b78da8 9161 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9162 vty);
9163}
9164
15c81ca4
DS
9165DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9166 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9167 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9168 "martian next-hops\n"
9169 "martian next-hop database\n")
acf71666 9170{
0291c246 9171 struct bgp *bgp = NULL;
15c81ca4 9172 int idx = 0;
9a8bdf1c
PG
9173 char *name = NULL;
9174
9175 /* [<vrf> VIEWVRFNAME] */
9176 if (argv_find(argv, argc, "vrf", &idx)) {
9177 name = argv[idx + 1]->arg;
9178 if (name && strmatch(name, VRF_DEFAULT_NAME))
9179 name = NULL;
9180 } else if (argv_find(argv, argc, "view", &idx))
9181 /* [<view> VIEWVRFNAME] */
9182 name = argv[idx + 1]->arg;
9183 if (name)
9184 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9185 else
9186 bgp = bgp_get_default();
acf71666 9187
acf71666
MK
9188 if (!bgp) {
9189 vty_out(vty, "%% No BGP process is configured\n");
9190 return CMD_WARNING;
9191 }
9192 bgp_show_martian_nexthops(vty, bgp);
9193
9194 return CMD_SUCCESS;
9195}
9196
f412b39a 9197DEFUN (show_bgp_memory,
4bf6a362 9198 show_bgp_memory_cmd,
7fa12b13 9199 "show [ip] bgp memory",
4bf6a362 9200 SHOW_STR
3a2d747c 9201 IP_STR
4bf6a362
PJ
9202 BGP_STR
9203 "Global BGP memory statistics\n")
9204{
d62a17ae 9205 char memstrbuf[MTYPE_MEMSTR_LEN];
9206 unsigned long count;
9207
9208 /* RIB related usage stats */
9209 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9210 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9211 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9212 count * sizeof(struct bgp_dest)));
d62a17ae 9213
9214 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9215 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9216 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9217 count * sizeof(struct bgp_path_info)));
d62a17ae 9218 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9219 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9220 count,
4b7e6066
DS
9221 mtype_memstr(
9222 memstrbuf, sizeof(memstrbuf),
9223 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9224
9225 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9226 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9227 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9228 count * sizeof(struct bgp_static)));
9229
9230 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9231 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9232 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9233 count * sizeof(struct bpacket)));
9234
9235 /* Adj-In/Out */
9236 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9237 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9238 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9239 count * sizeof(struct bgp_adj_in)));
9240 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9241 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9242 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9243 count * sizeof(struct bgp_adj_out)));
9244
9245 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9246 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9247 count,
9248 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9249 count * sizeof(struct bgp_nexthop_cache)));
9250
9251 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9252 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9253 count,
9254 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9255 count * sizeof(struct bgp_damp_info)));
9256
9257 /* Attributes */
9258 count = attr_count();
9259 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9260 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9261 count * sizeof(struct attr)));
9262
9263 if ((count = attr_unknown_count()))
9264 vty_out(vty, "%ld unknown attributes\n", count);
9265
9266 /* AS_PATH attributes */
9267 count = aspath_count();
9268 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9269 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9270 count * sizeof(struct aspath)));
9271
9272 count = mtype_stats_alloc(MTYPE_AS_SEG);
9273 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9274 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9275 count * sizeof(struct assegment)));
9276
9277 /* Other attributes */
9278 if ((count = community_count()))
9279 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9280 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9281 count * sizeof(struct community)));
d62a17ae 9282 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9283 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9284 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9285 count * sizeof(struct ecommunity)));
d62a17ae 9286 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9287 vty_out(vty,
9288 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9289 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9290 count * sizeof(struct lcommunity)));
d62a17ae 9291
9292 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9293 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9294 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9295 count * sizeof(struct cluster_list)));
9296
9297 /* Peer related usage */
9298 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9299 vty_out(vty, "%ld peers, using %s of memory\n", count,
9300 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9301 count * sizeof(struct peer)));
9302
9303 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9304 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9305 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9306 count * sizeof(struct peer_group)));
9307
9308 /* Other */
d62a17ae 9309 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9310 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9311 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9312 count * sizeof(regex_t)));
d62a17ae 9313 return CMD_SUCCESS;
4bf6a362 9314}
fee0f4c6 9315
57a9c8a8
DS
9316static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9317{
9318 json_object *bestpath = json_object_new_object();
9319
892fedb6 9320 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9321 json_object_string_add(bestpath, "asPath", "ignore");
9322
892fedb6 9323 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9324 json_object_string_add(bestpath, "asPath", "confed");
9325
892fedb6
DA
9326 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9327 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9328 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9329 "as-set");
9330 else
a4d82a8a 9331 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9332 "true");
9333 } else
a4d82a8a 9334 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9335
892fedb6 9336 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9337 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9338 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9339 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9340 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9341 json_object_string_add(bestpath, "med", "confed");
892fedb6 9342 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9343 json_object_string_add(bestpath, "med",
9344 "missing-as-worst");
9345 else
9346 json_object_string_add(bestpath, "med", "true");
9347 }
9348
9349 json_object_object_add(json, "bestPath", bestpath);
9350}
9351
3577f1c5
DD
9352/* Print the error code/subcode for why the peer is down */
9353static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9354 json_object *json_peer, bool use_json)
9355{
9356 const char *code_str;
9357 const char *subcode_str;
9358
9359 if (use_json) {
9360 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9361 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9362 char errorcodesubcode_hexstr[5];
9363 char errorcodesubcode_str[256];
9364
9365 code_str = bgp_notify_code_str(peer->notify.code);
9366 subcode_str = bgp_notify_subcode_str(
9367 peer->notify.code,
9368 peer->notify.subcode);
9369
772270f3
QY
9370 snprintf(errorcodesubcode_hexstr,
9371 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9372 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
9373 json_object_string_add(json_peer,
9374 "lastErrorCodeSubcode",
9375 errorcodesubcode_hexstr);
9376 snprintf(errorcodesubcode_str, 255, "%s%s",
9377 code_str, subcode_str);
9378 json_object_string_add(json_peer,
9379 "lastNotificationReason",
9380 errorcodesubcode_str);
9381 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9382 && peer->notify.code == BGP_NOTIFY_CEASE
9383 && (peer->notify.subcode
9384 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9385 || peer->notify.subcode
9386 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9387 && peer->notify.length) {
9388 char msgbuf[1024];
9389 const char *msg_str;
9390
9391 msg_str = bgp_notify_admin_message(
9392 msgbuf, sizeof(msgbuf),
9393 (uint8_t *)peer->notify.data,
9394 peer->notify.length);
9395 if (msg_str)
9396 json_object_string_add(
9397 json_peer,
9398 "lastShutdownDescription",
9399 msg_str);
9400 }
9401
c258527b 9402 }
3577f1c5
DD
9403 json_object_string_add(json_peer, "lastResetDueTo",
9404 peer_down_str[(int)peer->last_reset]);
05912a17
DD
9405 json_object_int_add(json_peer, "lastResetCode",
9406 peer->last_reset);
3577f1c5
DD
9407 } else {
9408 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9409 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9410 code_str = bgp_notify_code_str(peer->notify.code);
9411 subcode_str =
9412 bgp_notify_subcode_str(peer->notify.code,
9413 peer->notify.subcode);
9414 vty_out(vty, " Notification %s (%s%s)\n",
9415 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9416 ? "sent"
9417 : "received",
9418 code_str, subcode_str);
9419 } else {
e91c24c8 9420 vty_out(vty, " %s\n",
3577f1c5
DD
9421 peer_down_str[(int)peer->last_reset]);
9422 }
9423 }
9424}
9425
9426static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9427 safi_t safi)
9428{
9429 return ((peer->status != Established) ||
9430 !peer->afc_recv[afi][safi]);
9431}
9432
9433static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9434 struct peer *peer, json_object *json_peer,
9435 int max_neighbor_width, bool use_json)
9436{
9437 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9438 int len;
9439
9440 if (use_json) {
9441 if (peer_dynamic_neighbor(peer))
9442 json_object_boolean_true_add(json_peer,
9443 "dynamicPeer");
9444 if (peer->hostname)
9445 json_object_string_add(json_peer, "hostname",
9446 peer->hostname);
9447
9448 if (peer->domainname)
9449 json_object_string_add(json_peer, "domainname",
9450 peer->domainname);
9451 json_object_int_add(json_peer, "connectionsEstablished",
9452 peer->established);
9453 json_object_int_add(json_peer, "connectionsDropped",
9454 peer->dropped);
9455 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9456 use_json, json_peer);
9457 if (peer->status == Established)
9458 json_object_string_add(json_peer, "lastResetDueTo",
9459 "AFI/SAFI Not Negotiated");
9460 else
9461 bgp_show_peer_reset(NULL, peer, json_peer, true);
9462 } else {
9463 dn_flag[1] = '\0';
9464 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9465 if (peer->hostname
892fedb6 9466 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
9467 len = vty_out(vty, "%s%s(%s)", dn_flag,
9468 peer->hostname, peer->host);
9469 else
9470 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9471
9472 /* pad the neighbor column with spaces */
9473 if (len < max_neighbor_width)
9474 vty_out(vty, "%*s", max_neighbor_width - len,
9475 " ");
e91c24c8 9476 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
9477 peer->dropped,
9478 peer_uptime(peer->uptime, timebuf,
9479 BGP_UPTIME_LEN, 0, NULL));
9480 if (peer->status == Established)
9481 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9482 else
9483 bgp_show_peer_reset(vty, peer, NULL,
9484 false);
9485 }
9486}
c258527b 9487
3577f1c5 9488
718e3744 9489/* Show BGP peer's summary information. */
d62a17ae 9490static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
9491 bool show_failed, bool show_established,
9492 bool use_json)
d62a17ae 9493{
9494 struct peer *peer;
9495 struct listnode *node, *nnode;
9496 unsigned int count = 0, dn_count = 0;
9497 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9498 char neighbor_buf[VTY_BUFSIZ];
9499 int neighbor_col_default_width = 16;
3577f1c5 9500 int len, failed_count = 0;
d62a17ae 9501 int max_neighbor_width = 0;
9502 int pfx_rcd_safi;
3c13337d 9503 json_object *json = NULL;
d62a17ae 9504 json_object *json_peer = NULL;
9505 json_object *json_peers = NULL;
50e05855 9506 struct peer_af *paf;
d3ada366 9507 struct bgp_filter *filter;
d62a17ae 9508
9509 /* labeled-unicast routes are installed in the unicast table so in order
9510 * to
9511 * display the correct PfxRcd value we must look at SAFI_UNICAST
9512 */
3577f1c5 9513
d62a17ae 9514 if (safi == SAFI_LABELED_UNICAST)
9515 pfx_rcd_safi = SAFI_UNICAST;
9516 else
9517 pfx_rcd_safi = safi;
9518
9519 if (use_json) {
3c13337d 9520 json = json_object_new_object();
d62a17ae 9521 json_peers = json_object_new_object();
3577f1c5
DD
9522 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9523 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9524 continue;
9525
9526 if (peer->afc[afi][safi]) {
9527 /* See if we have at least a single failed peer */
9528 if (bgp_has_peer_failed(peer, afi, safi))
9529 failed_count++;
9530 count++;
9531 }
9532 if (peer_dynamic_neighbor(peer))
9533 dn_count++;
9534 }
c258527b 9535
d62a17ae 9536 } else {
9537 /* Loop over all neighbors that will be displayed to determine
9538 * how many
9539 * characters are needed for the Neighbor column
9540 */
9541 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9542 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9543 continue;
9544
9545 if (peer->afc[afi][safi]) {
9546 memset(dn_flag, '\0', sizeof(dn_flag));
9547 if (peer_dynamic_neighbor(peer))
9548 dn_flag[0] = '*';
9549
9550 if (peer->hostname
892fedb6
DA
9551 && CHECK_FLAG(bgp->flags,
9552 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9553 snprintf(neighbor_buf,
9554 sizeof(neighbor_buf),
9555 "%s%s(%s) ", dn_flag,
9556 peer->hostname, peer->host);
d62a17ae 9557 else
772270f3
QY
9558 snprintf(neighbor_buf,
9559 sizeof(neighbor_buf), "%s%s ",
9560 dn_flag, peer->host);
d62a17ae 9561
9562 len = strlen(neighbor_buf);
9563
9564 if (len > max_neighbor_width)
9565 max_neighbor_width = len;
c258527b 9566
3577f1c5
DD
9567 /* See if we have at least a single failed peer */
9568 if (bgp_has_peer_failed(peer, afi, safi))
9569 failed_count++;
9570 count++;
d62a17ae 9571 }
9572 }
f933309e 9573
d62a17ae 9574 /* Originally we displayed the Neighbor column as 16
9575 * characters wide so make that the default
9576 */
9577 if (max_neighbor_width < neighbor_col_default_width)
9578 max_neighbor_width = neighbor_col_default_width;
9579 }
f933309e 9580
3577f1c5
DD
9581 if (show_failed && !failed_count) {
9582 if (use_json) {
9583 json_object_int_add(json, "failedPeersCount", 0);
9584 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9585 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9586
9587 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9588 json, JSON_C_TO_STRING_PRETTY));
9589 json_object_free(json);
9590 } else {
9591 vty_out(vty, "%% No failed BGP neighbors found\n");
9592 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9593 }
9594 return CMD_SUCCESS;
9595 }
c258527b 9596
3577f1c5 9597 count = 0; /* Reset the value as its used again */
d62a17ae 9598 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9599 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9600 continue;
9601
ea47320b
DL
9602 if (!peer->afc[afi][safi])
9603 continue;
d62a17ae 9604
ea47320b
DL
9605 if (!count) {
9606 unsigned long ents;
9607 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9608 int64_t vrf_id_ui;
d62a17ae 9609
a4d82a8a
PZ
9610 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9611 ? -1
9612 : (int64_t)bgp->vrf_id;
ea47320b
DL
9613
9614 /* Usage summary and header */
9615 if (use_json) {
23d0a753
DA
9616 char buf[BUFSIZ] = {0};
9617
ea47320b
DL
9618 json_object_string_add(
9619 json, "routerId",
23d0a753
DA
9620 inet_ntop(AF_INET, &bgp->router_id, buf,
9621 sizeof(buf)));
60466a63
QY
9622 json_object_int_add(json, "as", bgp->as);
9623 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9624 json_object_string_add(
9625 json, "vrfName",
9626 (bgp->inst_type
9627 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9628 ? VRF_DEFAULT_NAME
ea47320b
DL
9629 : bgp->name);
9630 } else {
9631 vty_out(vty,
23d0a753
DA
9632 "BGP router identifier %pI4, local AS number %u vrf-id %d",
9633 &bgp->router_id, bgp->as,
a4d82a8a
PZ
9634 bgp->vrf_id == VRF_UNKNOWN
9635 ? -1
9636 : (int)bgp->vrf_id);
ea47320b
DL
9637 vty_out(vty, "\n");
9638 }
d62a17ae 9639
ea47320b 9640 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9641 if (use_json) {
ea47320b 9642 json_object_int_add(
60466a63 9643 json, "updateDelayLimit",
ea47320b 9644 bgp->v_update_delay);
d62a17ae 9645
ea47320b
DL
9646 if (bgp->v_update_delay
9647 != bgp->v_establish_wait)
d62a17ae 9648 json_object_int_add(
9649 json,
ea47320b
DL
9650 "updateDelayEstablishWait",
9651 bgp->v_establish_wait);
d62a17ae 9652
60466a63 9653 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9654 json_object_string_add(
9655 json,
9656 "updateDelayFirstNeighbor",
9657 bgp->update_delay_begin_time);
9658 json_object_boolean_true_add(
9659 json,
9660 "updateDelayInProgress");
9661 } else {
9662 if (bgp->update_delay_over) {
d62a17ae 9663 json_object_string_add(
9664 json,
9665 "updateDelayFirstNeighbor",
9666 bgp->update_delay_begin_time);
ea47320b 9667 json_object_string_add(
d62a17ae 9668 json,
ea47320b
DL
9669 "updateDelayBestpathResumed",
9670 bgp->update_delay_end_time);
9671 json_object_string_add(
d62a17ae 9672 json,
ea47320b
DL
9673 "updateDelayZebraUpdateResume",
9674 bgp->update_delay_zebra_resume_time);
9675 json_object_string_add(
9676 json,
9677 "updateDelayPeerUpdateResume",
9678 bgp->update_delay_peers_resume_time);
d62a17ae 9679 }
ea47320b
DL
9680 }
9681 } else {
9682 vty_out(vty,
9683 "Read-only mode update-delay limit: %d seconds\n",
9684 bgp->v_update_delay);
9685 if (bgp->v_update_delay
9686 != bgp->v_establish_wait)
d62a17ae 9687 vty_out(vty,
ea47320b
DL
9688 " Establish wait: %d seconds\n",
9689 bgp->v_establish_wait);
d62a17ae 9690
60466a63 9691 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9692 vty_out(vty,
9693 " First neighbor established: %s\n",
9694 bgp->update_delay_begin_time);
9695 vty_out(vty,
9696 " Delay in progress\n");
9697 } else {
9698 if (bgp->update_delay_over) {
d62a17ae 9699 vty_out(vty,
9700 " First neighbor established: %s\n",
9701 bgp->update_delay_begin_time);
9702 vty_out(vty,
ea47320b
DL
9703 " Best-paths resumed: %s\n",
9704 bgp->update_delay_end_time);
9705 vty_out(vty,
9706 " zebra update resumed: %s\n",
9707 bgp->update_delay_zebra_resume_time);
9708 vty_out(vty,
9709 " peers update resumed: %s\n",
9710 bgp->update_delay_peers_resume_time);
d62a17ae 9711 }
9712 }
9713 }
ea47320b 9714 }
d62a17ae 9715
ea47320b
DL
9716 if (use_json) {
9717 if (bgp_maxmed_onstartup_configured(bgp)
9718 && bgp->maxmed_active)
9719 json_object_boolean_true_add(
60466a63 9720 json, "maxMedOnStartup");
ea47320b
DL
9721 if (bgp->v_maxmed_admin)
9722 json_object_boolean_true_add(
60466a63 9723 json, "maxMedAdministrative");
d62a17ae 9724
ea47320b
DL
9725 json_object_int_add(
9726 json, "tableVersion",
60466a63 9727 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9728
60466a63
QY
9729 ents = bgp_table_count(bgp->rib[afi][safi]);
9730 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9731 json_object_int_add(
9732 json, "ribMemory",
9bcb3eef 9733 ents * sizeof(struct bgp_dest));
d62a17ae 9734
210ec2a0 9735 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9736 json_object_int_add(json, "peerCount", ents);
9737 json_object_int_add(json, "peerMemory",
9738 ents * sizeof(struct peer));
d62a17ae 9739
ea47320b
DL
9740 if ((ents = listcount(bgp->group))) {
9741 json_object_int_add(
60466a63 9742 json, "peerGroupCount", ents);
ea47320b
DL
9743 json_object_int_add(
9744 json, "peerGroupMemory",
996c9314
LB
9745 ents * sizeof(struct
9746 peer_group));
ea47320b 9747 }
d62a17ae 9748
ea47320b
DL
9749 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9750 BGP_CONFIG_DAMPENING))
9751 json_object_boolean_true_add(
60466a63 9752 json, "dampeningEnabled");
ea47320b
DL
9753 } else {
9754 if (bgp_maxmed_onstartup_configured(bgp)
9755 && bgp->maxmed_active)
d62a17ae 9756 vty_out(vty,
ea47320b
DL
9757 "Max-med on-startup active\n");
9758 if (bgp->v_maxmed_admin)
d62a17ae 9759 vty_out(vty,
ea47320b 9760 "Max-med administrative active\n");
d62a17ae 9761
60466a63
QY
9762 vty_out(vty, "BGP table version %" PRIu64 "\n",
9763 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9764
60466a63 9765 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9766 vty_out(vty,
9767 "RIB entries %ld, using %s of memory\n",
9768 ents,
9bcb3eef
DS
9769 mtype_memstr(
9770 memstrbuf, sizeof(memstrbuf),
9771 ents
9772 * sizeof(struct
9773 bgp_dest)));
ea47320b
DL
9774
9775 /* Peer related usage */
210ec2a0 9776 ents = bgp->af_peer_count[afi][safi];
60466a63 9777 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9778 ents,
9779 mtype_memstr(
60466a63
QY
9780 memstrbuf, sizeof(memstrbuf),
9781 ents * sizeof(struct peer)));
ea47320b
DL
9782
9783 if ((ents = listcount(bgp->group)))
d62a17ae 9784 vty_out(vty,
ea47320b 9785 "Peer groups %ld, using %s of memory\n",
d62a17ae 9786 ents,
9787 mtype_memstr(
9788 memstrbuf,
9789 sizeof(memstrbuf),
996c9314
LB
9790 ents * sizeof(struct
9791 peer_group)));
d62a17ae 9792
ea47320b
DL
9793 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9794 BGP_CONFIG_DAMPENING))
60466a63 9795 vty_out(vty, "Dampening enabled.\n");
ea47320b 9796 vty_out(vty, "\n");
d62a17ae 9797
ea47320b
DL
9798 /* Subtract 8 here because 'Neighbor' is
9799 * 8 characters */
9800 vty_out(vty, "Neighbor");
60466a63
QY
9801 vty_out(vty, "%*s", max_neighbor_width - 8,
9802 " ");
3577f1c5
DD
9803 if (show_failed)
9804 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9805 else
9806 vty_out(vty,
db92d226 9807 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 9808 }
ea47320b 9809 }
d62a17ae 9810
d55811cc 9811 paf = peer_af_find(peer, afi, safi);
d3ada366 9812 filter = &peer->filter[afi][safi];
db92d226 9813
ea47320b 9814 count++;
3577f1c5
DD
9815 /* Works for both failed & successful cases */
9816 if (peer_dynamic_neighbor(peer))
9817 dn_count++;
d62a17ae 9818
ea47320b 9819 if (use_json) {
3577f1c5
DD
9820 json_peer = NULL;
9821
9822 if (show_failed &&
9823 bgp_has_peer_failed(peer, afi, safi)) {
9824 json_peer = json_object_new_object();
9825 bgp_show_failed_summary(vty, bgp, peer,
9826 json_peer, 0, use_json);
9827 } else if (!show_failed) {
10b49f14
DA
9828 if (show_established
9829 && bgp_has_peer_failed(peer, afi, safi))
9830 continue;
9831
3577f1c5
DD
9832 json_peer = json_object_new_object();
9833 if (peer_dynamic_neighbor(peer)) {
9834 json_object_boolean_true_add(json_peer,
9835 "dynamicPeer");
9836 }
d62a17ae 9837
3577f1c5
DD
9838 if (peer->hostname)
9839 json_object_string_add(json_peer, "hostname",
9840 peer->hostname);
9841
9842 if (peer->domainname)
9843 json_object_string_add(json_peer, "domainname",
9844 peer->domainname);
9845
9846 json_object_int_add(json_peer, "remoteAs", peer->as);
9847 json_object_int_add(json_peer, "version", 4);
9848 json_object_int_add(json_peer, "msgRcvd",
9849 PEER_TOTAL_RX(peer));
9850 json_object_int_add(json_peer, "msgSent",
9851 PEER_TOTAL_TX(peer));
9852
43aa5965
QY
9853 atomic_size_t outq_count, inq_count;
9854 outq_count = atomic_load_explicit(
9855 &peer->obuf->count,
9856 memory_order_relaxed);
9857 inq_count = atomic_load_explicit(
9858 &peer->ibuf->count,
9859 memory_order_relaxed);
9860
3577f1c5
DD
9861 json_object_int_add(json_peer, "tableVersion",
9862 peer->version[afi][safi]);
9863 json_object_int_add(json_peer, "outq",
43aa5965
QY
9864 outq_count);
9865 json_object_int_add(json_peer, "inq",
9866 inq_count);
3577f1c5
DD
9867 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9868 use_json, json_peer);
9869
3577f1c5
DD
9870 json_object_int_add(json_peer, "pfxRcd",
9871 peer->pcount[afi][pfx_rcd_safi]);
9872
3577f1c5
DD
9873 if (paf && PAF_SUBGRP(paf))
9874 json_object_int_add(json_peer,
9875 "pfxSnt",
9876 (PAF_SUBGRP(paf))->scount);
cb9196e7 9877 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
9878 || CHECK_FLAG(peer->bgp->flags,
9879 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
9880 json_object_string_add(json_peer, "state",
9881 "Idle (Admin)");
9882 else if (peer->afc_recv[afi][safi])
9883 json_object_string_add(
9884 json_peer, "state",
9885 lookup_msg(bgp_status_msg, peer->status,
9886 NULL));
9887 else if (CHECK_FLAG(peer->sflags,
9888 PEER_STATUS_PREFIX_OVERFLOW))
9889 json_object_string_add(json_peer, "state",
9890 "Idle (PfxCt)");
9891 else
9892 json_object_string_add(
9893 json_peer, "state",
9894 lookup_msg(bgp_status_msg, peer->status,
9895 NULL));
200116db
DD
9896 json_object_int_add(json_peer, "connectionsEstablished",
9897 peer->established);
9898 json_object_int_add(json_peer, "connectionsDropped",
9899 peer->dropped);
b4e9dcba 9900 }
3577f1c5
DD
9901 /* Avoid creating empty peer dicts in JSON */
9902 if (json_peer == NULL)
9903 continue;
ea47320b
DL
9904
9905 if (peer->conf_if)
60466a63 9906 json_object_string_add(json_peer, "idType",
ea47320b
DL
9907 "interface");
9908 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9909 json_object_string_add(json_peer, "idType",
9910 "ipv4");
ea47320b 9911 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9912 json_object_string_add(json_peer, "idType",
9913 "ipv6");
ea47320b
DL
9914 json_object_object_add(json_peers, peer->host,
9915 json_peer);
9916 } else {
3577f1c5
DD
9917 if (show_failed &&
9918 bgp_has_peer_failed(peer, afi, safi)) {
9919 bgp_show_failed_summary(vty, bgp, peer, NULL,
9920 max_neighbor_width,
9921 use_json);
9922 } else if (!show_failed) {
10b49f14
DA
9923 if (show_established
9924 && bgp_has_peer_failed(peer, afi, safi))
9925 continue;
9926
3577f1c5
DD
9927 memset(dn_flag, '\0', sizeof(dn_flag));
9928 if (peer_dynamic_neighbor(peer)) {
9929 dn_flag[0] = '*';
9930 }
d62a17ae 9931
3577f1c5 9932 if (peer->hostname
892fedb6
DA
9933 && CHECK_FLAG(bgp->flags,
9934 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9935 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9936 peer->hostname,
9937 peer->host);
d62a17ae 9938 else
3577f1c5
DD
9939 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9940
9941 /* pad the neighbor column with spaces */
9942 if (len < max_neighbor_width)
9943 vty_out(vty, "%*s", max_neighbor_width - len,
9944 " ");
9945
43aa5965
QY
9946 atomic_size_t outq_count, inq_count;
9947 outq_count = atomic_load_explicit(
9948 &peer->obuf->count,
9949 memory_order_relaxed);
9950 inq_count = atomic_load_explicit(
9951 &peer->ibuf->count,
9952 memory_order_relaxed);
9953
566bdaf6 9954 vty_out(vty,
6cde4b45 9955 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 9956 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9957 PEER_TOTAL_TX(peer),
43aa5965
QY
9958 peer->version[afi][safi], inq_count,
9959 outq_count,
3577f1c5
DD
9960 peer_uptime(peer->uptime, timebuf,
9961 BGP_UPTIME_LEN, 0, NULL));
9962
db92d226 9963 if (peer->status == Established) {
d3ada366
DA
9964 if (peer->afc_recv[afi][safi]) {
9965 if (CHECK_FLAG(
9966 bgp->flags,
9967 BGP_FLAG_EBGP_REQUIRES_POLICY)
9968 && !bgp_inbound_policy_exists(
9969 peer, filter))
9970 vty_out(vty, " %12s",
9971 "(Policy)");
9972 else
9973 vty_out(vty,
6cde4b45 9974 " %12u",
d3ada366
DA
9975 peer->pcount
9976 [afi]
9977 [pfx_rcd_safi]);
9978 } else {
3577f1c5 9979 vty_out(vty, " NoNeg");
d3ada366 9980 }
db92d226 9981
d3ada366
DA
9982 if (paf && PAF_SUBGRP(paf)) {
9983 if (CHECK_FLAG(
9984 bgp->flags,
9985 BGP_FLAG_EBGP_REQUIRES_POLICY)
9986 && !bgp_outbound_policy_exists(
9987 peer, filter))
9988 vty_out(vty, " %8s",
9989 "(Policy)");
9990 else
9991 vty_out(vty,
6cde4b45 9992 " %8u",
d3ada366
DA
9993 (PAF_SUBGRP(
9994 paf))
9995 ->scount);
9996 }
db92d226 9997 } else {
736b68f3
DS
9998 if (CHECK_FLAG(peer->flags,
9999 PEER_FLAG_SHUTDOWN)
10000 || CHECK_FLAG(peer->bgp->flags,
10001 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10002 vty_out(vty, " Idle (Admin)");
10003 else if (CHECK_FLAG(
10004 peer->sflags,
10005 PEER_STATUS_PREFIX_OVERFLOW))
10006 vty_out(vty, " Idle (PfxCt)");
10007 else
10008 vty_out(vty, " %12s",
10009 lookup_msg(bgp_status_msg,
10010 peer->status, NULL));
db92d226 10011
6cde4b45 10012 vty_out(vty, " %8u", 0);
3577f1c5
DD
10013 }
10014 vty_out(vty, "\n");
d62a17ae 10015 }
3577f1c5 10016
d62a17ae 10017 }
10018 }
f933309e 10019
d62a17ae 10020 if (use_json) {
10021 json_object_object_add(json, "peers", json_peers);
3577f1c5 10022 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 10023 json_object_int_add(json, "totalPeers", count);
10024 json_object_int_add(json, "dynamicPeers", dn_count);
10025
3577f1c5
DD
10026 if (!show_failed)
10027 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10028
996c9314
LB
10029 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10030 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10031 json_object_free(json);
10032 } else {
10033 if (count)
10034 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10035 else {
d6ceaca3 10036 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10037 get_afi_safi_str(afi, safi, false));
d62a17ae 10038 }
b05a1c8b 10039
d6ceaca3 10040 if (dn_count) {
d62a17ae 10041 vty_out(vty, "* - dynamic neighbor\n");
10042 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10043 dn_count, bgp->dynamic_neighbors_limit);
10044 }
10045 }
1ff9a340 10046
d62a17ae 10047 return CMD_SUCCESS;
718e3744 10048}
10049
d62a17ae 10050static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
10051 int safi, bool show_failed,
10052 bool show_established, bool use_json)
d62a17ae 10053{
10054 int is_first = 1;
10055 int afi_wildcard = (afi == AFI_MAX);
10056 int safi_wildcard = (safi == SAFI_MAX);
10057 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10058 bool nbr_output = false;
d62a17ae 10059
10060 if (use_json && is_wildcard)
10061 vty_out(vty, "{\n");
10062 if (afi_wildcard)
10063 afi = 1; /* AFI_IP */
10064 while (afi < AFI_MAX) {
10065 if (safi_wildcard)
10066 safi = 1; /* SAFI_UNICAST */
10067 while (safi < SAFI_MAX) {
318cac96 10068 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10069 nbr_output = true;
f86897b9 10070
d62a17ae 10071 if (is_wildcard) {
10072 /*
10073 * So limit output to those afi/safi
10074 * pairs that
10075 * actualy have something interesting in
10076 * them
10077 */
10078 if (use_json) {
d62a17ae 10079 if (!is_first)
10080 vty_out(vty, ",\n");
10081 else
10082 is_first = 0;
10083
10084 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10085 get_afi_safi_str(afi,
10086 safi,
10087 true));
d62a17ae 10088 } else {
10089 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
10090 get_afi_safi_str(afi,
10091 safi,
10092 false));
d62a17ae 10093 }
10094 }
10b49f14
DA
10095 bgp_show_summary(vty, bgp, afi, safi,
10096 show_failed, show_established,
3577f1c5 10097 use_json);
d62a17ae 10098 }
10099 safi++;
d62a17ae 10100 if (!safi_wildcard)
10101 safi = SAFI_MAX;
10102 }
10103 afi++;
ee851c8c 10104 if (!afi_wildcard)
d62a17ae 10105 afi = AFI_MAX;
10106 }
10107
10108 if (use_json && is_wildcard)
10109 vty_out(vty, "}\n");
ca61fd25
DS
10110 else if (!nbr_output) {
10111 if (use_json)
10112 vty_out(vty, "{}\n");
10113 else
10114 vty_out(vty, "%% No BGP neighbors found\n");
10115 }
d62a17ae 10116}
10117
10118static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 10119 safi_t safi, bool show_failed,
10b49f14 10120 bool show_established,
3577f1c5 10121 bool use_json)
d62a17ae 10122{
10123 struct listnode *node, *nnode;
10124 struct bgp *bgp;
d62a17ae 10125 int is_first = 1;
9f049418 10126 bool nbr_output = false;
d62a17ae 10127
10128 if (use_json)
10129 vty_out(vty, "{\n");
10130
10131 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10132 nbr_output = true;
d62a17ae 10133 if (use_json) {
d62a17ae 10134 if (!is_first)
10135 vty_out(vty, ",\n");
10136 else
10137 is_first = 0;
10138
10139 vty_out(vty, "\"%s\":",
10140 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10141 ? VRF_DEFAULT_NAME
d62a17ae 10142 : bgp->name);
10143 } else {
10144 vty_out(vty, "\nInstance %s:\n",
10145 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10146 ? VRF_DEFAULT_NAME
d62a17ae 10147 : bgp->name);
10148 }
3577f1c5 10149 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10150 show_established, use_json);
d62a17ae 10151 }
10152
10153 if (use_json)
10154 vty_out(vty, "}\n");
9f049418
DS
10155 else if (!nbr_output)
10156 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10157}
10158
10159int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
10160 safi_t safi, bool show_failed, bool show_established,
10161 bool use_json)
d62a17ae 10162{
10163 struct bgp *bgp;
10164
10165 if (name) {
10166 if (strmatch(name, "all")) {
10b49f14
DA
10167 bgp_show_all_instances_summary_vty(
10168 vty, afi, safi, show_failed, show_established,
10169 use_json);
d62a17ae 10170 return CMD_SUCCESS;
10171 } else {
10172 bgp = bgp_lookup_by_name(name);
10173
10174 if (!bgp) {
10175 if (use_json)
10176 vty_out(vty, "{}\n");
10177 else
10178 vty_out(vty,
ca61fd25 10179 "%% BGP instance not found\n");
d62a17ae 10180 return CMD_WARNING;
10181 }
10182
f86897b9 10183 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
10184 show_failed, show_established,
10185 use_json);
d62a17ae 10186 return CMD_SUCCESS;
10187 }
10188 }
10189
10190 bgp = bgp_get_default();
10191
10192 if (bgp)
3577f1c5 10193 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10194 show_established, use_json);
9f049418 10195 else {
ca61fd25
DS
10196 if (use_json)
10197 vty_out(vty, "{}\n");
10198 else
10199 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
10200 return CMD_WARNING;
10201 }
d62a17ae 10202
10203 return CMD_SUCCESS;
4fb25c53
DW
10204}
10205
716b2d8a 10206/* `show [ip] bgp summary' commands. */
96f3485c 10207DEFPY (show_ip_bgp_summary,
718e3744 10208 show_ip_bgp_summary_cmd,
96f3485c 10209 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 10210 SHOW_STR
10211 IP_STR
10212 BGP_STR
8386ac43 10213 BGP_INSTANCE_HELP_STR
46f296b4 10214 BGP_AFI_HELP_STR
dd6bd0f1 10215 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 10216 "Display the entries for all address families\n"
b05a1c8b 10217 "Summary of BGP neighbor status\n"
10b49f14 10218 "Show only sessions in Established state\n"
3577f1c5 10219 "Show only sessions not in Established state\n"
9973d184 10220 JSON_STR)
718e3744 10221{
d62a17ae 10222 char *vrf = NULL;
10223 afi_t afi = AFI_MAX;
10224 safi_t safi = SAFI_MAX;
3577f1c5 10225 bool show_failed = false;
10b49f14 10226 bool show_established = false;
d62a17ae 10227
10228 int idx = 0;
10229
10230 /* show [ip] bgp */
96f3485c 10231 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 10232 afi = AFI_IP;
9a8bdf1c
PG
10233 /* [<vrf> VIEWVRFNAME] */
10234 if (argv_find(argv, argc, "vrf", &idx)) {
10235 vrf = argv[idx + 1]->arg;
10236 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10237 vrf = NULL;
10238 } else if (argv_find(argv, argc, "view", &idx))
10239 /* [<view> VIEWVRFNAME] */
10240 vrf = argv[idx + 1]->arg;
d62a17ae 10241 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10242 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10243 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10244 }
10245
3577f1c5
DD
10246 if (argv_find(argv, argc, "failed", &idx))
10247 show_failed = true;
10b49f14
DA
10248 if (argv_find(argv, argc, "established", &idx))
10249 show_established = true;
3577f1c5 10250
10b49f14
DA
10251 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
10252 show_established, uj);
d62a17ae 10253}
10254
5cb5f4d0 10255const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 10256{
5cb5f4d0
DD
10257 if (for_json)
10258 return get_afi_safi_json_str(afi, safi);
d62a17ae 10259 else
5cb5f4d0 10260 return get_afi_safi_vty_str(afi, safi);
27162734
LB
10261}
10262
d62a17ae 10263
10264static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10265 afi_t afi, safi_t safi,
d7c0a89a
QY
10266 uint16_t adv_smcap, uint16_t adv_rmcap,
10267 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 10268 bool use_json, json_object *json_pref)
d62a17ae 10269{
10270 /* Send-Mode */
10271 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10272 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10273 if (use_json) {
10274 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10275 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10276 json_object_string_add(json_pref, "sendMode",
10277 "advertisedAndReceived");
10278 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10279 json_object_string_add(json_pref, "sendMode",
10280 "advertised");
10281 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10282 json_object_string_add(json_pref, "sendMode",
10283 "received");
10284 } else {
10285 vty_out(vty, " Send-mode: ");
10286 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10287 vty_out(vty, "advertised");
10288 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10289 vty_out(vty, "%sreceived",
10290 CHECK_FLAG(p->af_cap[afi][safi],
10291 adv_smcap)
10292 ? ", "
10293 : "");
10294 vty_out(vty, "\n");
10295 }
10296 }
10297
10298 /* Receive-Mode */
10299 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10300 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10301 if (use_json) {
10302 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10303 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10304 json_object_string_add(json_pref, "recvMode",
10305 "advertisedAndReceived");
10306 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10307 json_object_string_add(json_pref, "recvMode",
10308 "advertised");
10309 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10310 json_object_string_add(json_pref, "recvMode",
10311 "received");
10312 } else {
10313 vty_out(vty, " Receive-mode: ");
10314 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10315 vty_out(vty, "advertised");
10316 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10317 vty_out(vty, "%sreceived",
10318 CHECK_FLAG(p->af_cap[afi][safi],
10319 adv_rmcap)
10320 ? ", "
10321 : "");
10322 vty_out(vty, "\n");
10323 }
10324 }
10325}
10326
13909c4f
DS
10327static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10328 struct peer *p,
10329 bool use_json,
10330 json_object *json)
2986cac2 10331{
08c2d52a 10332 bool rbit_status = false;
2986cac2 10333
10334 if (!use_json)
a53ca37b 10335 vty_out(vty, "\n R bit: ");
2986cac2 10336
13909c4f
DS
10337 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10338 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10339 && (p->status == Established)) {
2986cac2 10340
10341 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 10342 rbit_status = true;
2986cac2 10343 else
08c2d52a 10344 rbit_status = false;
2986cac2 10345 }
10346
10347 if (rbit_status) {
10348 if (use_json)
13909c4f 10349 json_object_boolean_true_add(json, "rBit");
2986cac2 10350 else
10351 vty_out(vty, "True\n");
10352 } else {
10353 if (use_json)
13909c4f 10354 json_object_boolean_false_add(json, "rBit");
2986cac2 10355 else
10356 vty_out(vty, "False\n");
10357 }
10358}
10359
13909c4f
DS
10360static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10361 struct peer *peer,
10362 bool use_json,
10363 json_object *json)
2986cac2 10364{
2bb5d39b 10365 const char *mode = "NotApplicable";
2986cac2 10366
10367 if (!use_json)
a53ca37b 10368 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 10369
13909c4f
DS
10370 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10371 && (peer->status == Established)) {
2986cac2 10372
13909c4f
DS
10373 if ((peer->nsf_af_count == 0)
10374 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10375
2986cac2 10376 mode = "Disable";
10377
13909c4f
DS
10378 } else if (peer->nsf_af_count == 0
10379 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10380
2986cac2 10381 mode = "Helper";
10382
13909c4f
DS
10383 } else if (peer->nsf_af_count != 0
10384 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10385
2986cac2 10386 mode = "Restart";
2986cac2 10387 }
10388 }
10389
10390 if (use_json) {
13909c4f 10391 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 10392 } else
10393 vty_out(vty, mode, "\n");
10394}
10395
13909c4f
DS
10396static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
10397 struct peer *p,
10398 bool use_json,
10399 json_object *json)
2986cac2 10400{
10401 const char *mode = "Invalid";
10402
10403 if (!use_json)
a53ca37b 10404 vty_out(vty, " Local GR Mode: ");
2986cac2 10405
10406 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
10407 mode = "Helper";
10408 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
10409 mode = "Restart";
10410 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
10411 mode = "Disable";
2ba1fe69 10412 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 10413 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
10414 mode = "Helper*";
10415 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
10416 mode = "Restart*";
10417 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
10418 mode = "Disable*";
10419 else
10420 mode = "Invalid*";
2ba1fe69 10421 }
2986cac2 10422
10423 if (use_json) {
13909c4f 10424 json_object_string_add(json, "localGrMode", mode);
2986cac2 10425 } else {
10426 vty_out(vty, mode, "\n");
10427 }
10428}
10429
13909c4f
DS
10430static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
10431 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 10432{
2ba1fe69 10433 afi_t afi;
10434 safi_t safi;
2986cac2 10435 json_object *json_afi_safi = NULL;
10436 json_object *json_timer = NULL;
10437 json_object *json_endofrib_status = NULL;
9e3b51a7 10438 bool eor_flag = false;
2986cac2 10439
10440 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10441 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
10442 if (!peer->afc[afi][safi])
10443 continue;
2986cac2 10444
13909c4f
DS
10445 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10446 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
10447 continue;
9e3b51a7 10448
13909c4f
DS
10449 if (use_json) {
10450 json_afi_safi = json_object_new_object();
10451 json_endofrib_status = json_object_new_object();
10452 json_timer = json_object_new_object();
10453 }
2986cac2 10454
13909c4f
DS
10455 if (peer->eor_stime[afi][safi]
10456 >= peer->pkt_stime[afi][safi])
10457 eor_flag = true;
10458 else
10459 eor_flag = false;
2986cac2 10460
13909c4f 10461 if (!use_json) {
a53ca37b 10462 vty_out(vty, " %s:\n",
13909c4f 10463 get_afi_safi_str(afi, safi, false));
2986cac2 10464
a53ca37b 10465 vty_out(vty, " F bit: ");
698ba8d0 10466 }
2986cac2 10467
13909c4f
DS
10468 if (peer->nsf[afi][safi]
10469 && CHECK_FLAG(peer->af_cap[afi][safi],
10470 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 10471
13909c4f
DS
10472 if (use_json) {
10473 json_object_boolean_true_add(
2986cac2 10474 json_afi_safi, "fBit");
13909c4f
DS
10475 } else
10476 vty_out(vty, "True\n");
10477 } else {
10478 if (use_json)
10479 json_object_boolean_false_add(
10480 json_afi_safi, "fBit");
10481 else
10482 vty_out(vty, "False\n");
10483 }
2986cac2 10484
13909c4f 10485 if (!use_json)
a53ca37b 10486 vty_out(vty, " End-of-RIB sent: ");
2986cac2 10487
13909c4f
DS
10488 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10489 PEER_STATUS_EOR_SEND)) {
10490 if (use_json) {
10491 json_object_boolean_true_add(
2986cac2 10492 json_endofrib_status,
13909c4f 10493 "endOfRibSend");
9e3b51a7 10494
13909c4f
DS
10495 PRINT_EOR_JSON(eor_flag);
10496 } else {
10497 vty_out(vty, "Yes\n");
10498 vty_out(vty,
a53ca37b 10499 " End-of-RIB sent after update: ");
2986cac2 10500
13909c4f
DS
10501 PRINT_EOR(eor_flag);
10502 }
10503 } else {
10504 if (use_json) {
10505 json_object_boolean_false_add(
2986cac2 10506 json_endofrib_status,
13909c4f
DS
10507 "endOfRibSend");
10508 json_object_boolean_false_add(
9e3b51a7 10509 json_endofrib_status,
13909c4f
DS
10510 "endOfRibSentAfterUpdate");
10511 } else {
10512 vty_out(vty, "No\n");
10513 vty_out(vty,
a53ca37b 10514 " End-of-RIB sent after update: ");
13909c4f 10515 vty_out(vty, "No\n");
2986cac2 10516 }
13909c4f 10517 }
2986cac2 10518
a53ca37b
DA
10519 if (!use_json)
10520 vty_out(vty, " End-of-RIB received: ");
10521
10522 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10523 PEER_STATUS_EOR_RECEIVED)) {
10524 if (use_json)
10525 json_object_boolean_true_add(
10526 json_endofrib_status,
10527 "endOfRibRecv");
10528 else
10529 vty_out(vty, "Yes\n");
10530 } else {
10531 if (use_json)
10532 json_object_boolean_false_add(
10533 json_endofrib_status,
10534 "endOfRibRecv");
10535 else
10536 vty_out(vty, "No\n");
10537 }
10538
13909c4f
DS
10539 if (use_json) {
10540 json_object_int_add(json_timer,
10541 "stalePathTimer",
10542 peer->bgp->stalepath_time);
2986cac2 10543
13909c4f
DS
10544 if (peer->t_gr_stale != NULL) {
10545 json_object_int_add(
2986cac2 10546 json_timer,
10547 "stalePathTimerRemaining",
10548 thread_timer_remain_second(
13909c4f
DS
10549 peer->t_gr_stale));
10550 }
3a75afa4 10551
13909c4f
DS
10552 /* Display Configured Selection
10553 * Deferral only when when
10554 * Gr mode is enabled.
10555 */
10556 if (CHECK_FLAG(peer->flags,
10557 PEER_FLAG_GRACEFUL_RESTART)) {
10558 json_object_int_add(
3a75afa4 10559 json_timer,
2986cac2 10560 "selectionDeferralTimer",
10561 peer->bgp->stalepath_time);
13909c4f 10562 }
2986cac2 10563
13909c4f
DS
10564 if (peer->bgp->gr_info[afi][safi]
10565 .t_select_deferral
10566 != NULL) {
2986cac2 10567
13909c4f 10568 json_object_int_add(
2986cac2 10569 json_timer,
10570 "selectionDeferralTimerRemaining",
10571 thread_timer_remain_second(
13909c4f
DS
10572 peer->bgp
10573 ->gr_info[afi]
10574 [safi]
10575 .t_select_deferral));
10576 }
10577 } else {
a53ca37b 10578 vty_out(vty, " Timers:\n");
13909c4f 10579 vty_out(vty,
a53ca37b
DA
10580 " Configured Stale Path Time(sec): %u\n",
10581 peer->bgp->stalepath_time);
2986cac2 10582
a53ca37b 10583 if (peer->t_gr_stale != NULL)
2986cac2 10584 vty_out(vty,
a53ca37b 10585 " Stale Path Remaining(sec): %ld\n",
2986cac2 10586 thread_timer_remain_second(
13909c4f 10587 peer->t_gr_stale));
13909c4f
DS
10588 /* Display Configured Selection
10589 * Deferral only when when
10590 * Gr mode is enabled.
10591 */
10592 if (CHECK_FLAG(peer->flags,
a53ca37b 10593 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10594 vty_out(vty,
a53ca37b 10595 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10596 peer->bgp->select_defer_time);
2986cac2 10597
13909c4f
DS
10598 if (peer->bgp->gr_info[afi][safi]
10599 .t_select_deferral
a53ca37b 10600 != NULL)
13909c4f 10601 vty_out(vty,
a53ca37b 10602 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10603 thread_timer_remain_second(
13909c4f
DS
10604 peer->bgp
10605 ->gr_info[afi]
10606 [safi]
10607 .t_select_deferral));
2986cac2 10608 }
13909c4f
DS
10609 if (use_json) {
10610 json_object_object_add(json_afi_safi,
10611 "endOfRibStatus",
10612 json_endofrib_status);
10613 json_object_object_add(json_afi_safi, "timers",
10614 json_timer);
10615 json_object_object_add(
10616 json, get_afi_safi_str(afi, safi, true),
10617 json_afi_safi);
10618 }
2986cac2 10619 }
10620 }
10621}
10622
36235319
QY
10623static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10624 struct peer *p,
10625 bool use_json,
10626 json_object *json)
2986cac2 10627{
10628 if (use_json) {
10629 json_object *json_timer = NULL;
10630
10631 json_timer = json_object_new_object();
10632
13909c4f
DS
10633 json_object_int_add(json_timer, "configuredRestartTimer",
10634 p->bgp->restart_time);
2986cac2 10635
13909c4f
DS
10636 json_object_int_add(json_timer, "receivedRestartTimer",
10637 p->v_gr_restart);
2986cac2 10638
13909c4f
DS
10639 if (p->t_gr_restart != NULL)
10640 json_object_int_add(
10641 json_timer, "restartTimerRemaining",
10642 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10643
10644 json_object_object_add(json, "timers", json_timer);
10645 } else {
10646
a53ca37b
DA
10647 vty_out(vty, " Timers:\n");
10648 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10649 p->bgp->restart_time);
2986cac2 10650
a53ca37b 10651 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10652 p->v_gr_restart);
10653 if (p->t_gr_restart != NULL)
a53ca37b 10654 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10655 thread_timer_remain_second(p->t_gr_restart));
36235319 10656 if (p->t_gr_restart != NULL) {
a53ca37b 10657 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10658 thread_timer_remain_second(p->t_gr_restart));
10659 }
2986cac2 10660 }
10661}
10662
10663static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10664 bool use_json, json_object *json)
2986cac2 10665{
10666 char buf[SU_ADDRSTRLEN] = {0};
10667 char dn_flag[2] = {0};
2b7165e7
QY
10668 /* '*' + v6 address of neighbor */
10669 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10670
2986cac2 10671 if (!p->conf_if && peer_dynamic_neighbor(p))
10672 dn_flag[0] = '*';
10673
10674 if (p->conf_if) {
10675 if (use_json)
13909c4f
DS
10676 json_object_string_add(
10677 json, "neighborAddr",
2986cac2 10678 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10679 ? "none"
10680 : sockunion2str(&p->su, buf,
10681 SU_ADDRSTRLEN));
2986cac2 10682 else
13909c4f 10683 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10684 BGP_PEER_SU_UNSPEC(p)
10685 ? "none"
10686 : sockunion2str(&p->su, buf,
10687 SU_ADDRSTRLEN));
10688 } else {
772270f3
QY
10689 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10690 p->host);
2986cac2 10691
10692 if (use_json)
36235319
QY
10693 json_object_string_add(json, "neighborAddr",
10694 neighborAddr);
2986cac2 10695 else
36235319 10696 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10697 }
10698
10699 /* more gr info in new format */
10700 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10701}
10702
d62a17ae 10703static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10704 safi_t safi, bool use_json,
d62a17ae 10705 json_object *json_neigh)
10706{
0291c246
MK
10707 struct bgp_filter *filter;
10708 struct peer_af *paf;
10709 char orf_pfx_name[BUFSIZ];
10710 int orf_pfx_count;
10711 json_object *json_af = NULL;
10712 json_object *json_prefA = NULL;
10713 json_object *json_prefB = NULL;
10714 json_object *json_addr = NULL;
d62a17ae 10715
10716 if (use_json) {
10717 json_addr = json_object_new_object();
10718 json_af = json_object_new_object();
10719 filter = &p->filter[afi][safi];
10720
10721 if (peer_group_active(p))
10722 json_object_string_add(json_addr, "peerGroupMember",
10723 p->group->name);
10724
10725 paf = peer_af_find(p, afi, safi);
10726 if (paf && PAF_SUBGRP(paf)) {
10727 json_object_int_add(json_addr, "updateGroupId",
10728 PAF_UPDGRP(paf)->id);
10729 json_object_int_add(json_addr, "subGroupId",
10730 PAF_SUBGRP(paf)->id);
10731 json_object_int_add(json_addr, "packetQueueLength",
10732 bpacket_queue_virtual_length(paf));
10733 }
10734
10735 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10736 || CHECK_FLAG(p->af_cap[afi][safi],
10737 PEER_CAP_ORF_PREFIX_SM_RCV)
10738 || CHECK_FLAG(p->af_cap[afi][safi],
10739 PEER_CAP_ORF_PREFIX_RM_ADV)
10740 || CHECK_FLAG(p->af_cap[afi][safi],
10741 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10742 json_object_int_add(json_af, "orfType",
10743 ORF_TYPE_PREFIX);
10744 json_prefA = json_object_new_object();
10745 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10746 PEER_CAP_ORF_PREFIX_SM_ADV,
10747 PEER_CAP_ORF_PREFIX_RM_ADV,
10748 PEER_CAP_ORF_PREFIX_SM_RCV,
10749 PEER_CAP_ORF_PREFIX_RM_RCV,
10750 use_json, json_prefA);
10751 json_object_object_add(json_af, "orfPrefixList",
10752 json_prefA);
10753 }
10754
10755 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10756 || CHECK_FLAG(p->af_cap[afi][safi],
10757 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10758 || CHECK_FLAG(p->af_cap[afi][safi],
10759 PEER_CAP_ORF_PREFIX_RM_ADV)
10760 || CHECK_FLAG(p->af_cap[afi][safi],
10761 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10762 json_object_int_add(json_af, "orfOldType",
10763 ORF_TYPE_PREFIX_OLD);
10764 json_prefB = json_object_new_object();
10765 bgp_show_peer_afi_orf_cap(
10766 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10767 PEER_CAP_ORF_PREFIX_RM_ADV,
10768 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10769 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10770 json_prefB);
10771 json_object_object_add(json_af, "orfOldPrefixList",
10772 json_prefB);
10773 }
10774
10775 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10776 || CHECK_FLAG(p->af_cap[afi][safi],
10777 PEER_CAP_ORF_PREFIX_SM_RCV)
10778 || CHECK_FLAG(p->af_cap[afi][safi],
10779 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10780 || CHECK_FLAG(p->af_cap[afi][safi],
10781 PEER_CAP_ORF_PREFIX_RM_ADV)
10782 || CHECK_FLAG(p->af_cap[afi][safi],
10783 PEER_CAP_ORF_PREFIX_RM_RCV)
10784 || CHECK_FLAG(p->af_cap[afi][safi],
10785 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10786 json_object_object_add(json_addr, "afDependentCap",
10787 json_af);
10788 else
10789 json_object_free(json_af);
10790
772270f3
QY
10791 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10792 p->host, afi, safi);
d62a17ae 10793 orf_pfx_count = prefix_bgp_show_prefix_list(
10794 NULL, afi, orf_pfx_name, use_json);
10795
10796 if (CHECK_FLAG(p->af_sflags[afi][safi],
10797 PEER_STATUS_ORF_PREFIX_SEND)
10798 || orf_pfx_count) {
10799 if (CHECK_FLAG(p->af_sflags[afi][safi],
10800 PEER_STATUS_ORF_PREFIX_SEND))
10801 json_object_boolean_true_add(json_neigh,
10802 "orfSent");
10803 if (orf_pfx_count)
10804 json_object_int_add(json_addr, "orfRecvCounter",
10805 orf_pfx_count);
10806 }
10807 if (CHECK_FLAG(p->af_sflags[afi][safi],
10808 PEER_STATUS_ORF_WAIT_REFRESH))
10809 json_object_string_add(
10810 json_addr, "orfFirstUpdate",
10811 "deferredUntilORFOrRouteRefreshRecvd");
10812
10813 if (CHECK_FLAG(p->af_flags[afi][safi],
10814 PEER_FLAG_REFLECTOR_CLIENT))
10815 json_object_boolean_true_add(json_addr,
10816 "routeReflectorClient");
10817 if (CHECK_FLAG(p->af_flags[afi][safi],
10818 PEER_FLAG_RSERVER_CLIENT))
10819 json_object_boolean_true_add(json_addr,
10820 "routeServerClient");
10821 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10822 json_object_boolean_true_add(json_addr,
10823 "inboundSoftConfigPermit");
10824
10825 if (CHECK_FLAG(p->af_flags[afi][safi],
10826 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10827 json_object_boolean_true_add(
10828 json_addr,
10829 "privateAsNumsAllReplacedInUpdatesToNbr");
10830 else if (CHECK_FLAG(p->af_flags[afi][safi],
10831 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10832 json_object_boolean_true_add(
10833 json_addr,
10834 "privateAsNumsReplacedInUpdatesToNbr");
10835 else if (CHECK_FLAG(p->af_flags[afi][safi],
10836 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10837 json_object_boolean_true_add(
10838 json_addr,
10839 "privateAsNumsAllRemovedInUpdatesToNbr");
10840 else if (CHECK_FLAG(p->af_flags[afi][safi],
10841 PEER_FLAG_REMOVE_PRIVATE_AS))
10842 json_object_boolean_true_add(
10843 json_addr,
10844 "privateAsNumsRemovedInUpdatesToNbr");
10845
dcc68b5e
MS
10846 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10847 json_object_boolean_true_add(
10848 json_addr,
10849 bgp_addpath_names(p->addpath_type[afi][safi])
10850 ->type_json_name);
d62a17ae 10851
10852 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10853 json_object_string_add(json_addr,
10854 "overrideASNsInOutboundUpdates",
10855 "ifAspathEqualRemoteAs");
10856
10857 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10858 || CHECK_FLAG(p->af_flags[afi][safi],
10859 PEER_FLAG_FORCE_NEXTHOP_SELF))
10860 json_object_boolean_true_add(json_addr,
10861 "routerAlwaysNextHop");
10862 if (CHECK_FLAG(p->af_flags[afi][safi],
10863 PEER_FLAG_AS_PATH_UNCHANGED))
10864 json_object_boolean_true_add(
10865 json_addr, "unchangedAsPathPropogatedToNbr");
10866 if (CHECK_FLAG(p->af_flags[afi][safi],
10867 PEER_FLAG_NEXTHOP_UNCHANGED))
10868 json_object_boolean_true_add(
10869 json_addr, "unchangedNextHopPropogatedToNbr");
10870 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10871 json_object_boolean_true_add(
10872 json_addr, "unchangedMedPropogatedToNbr");
10873 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10874 || CHECK_FLAG(p->af_flags[afi][safi],
10875 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10876 if (CHECK_FLAG(p->af_flags[afi][safi],
10877 PEER_FLAG_SEND_COMMUNITY)
10878 && CHECK_FLAG(p->af_flags[afi][safi],
10879 PEER_FLAG_SEND_EXT_COMMUNITY))
10880 json_object_string_add(json_addr,
10881 "commAttriSentToNbr",
10882 "extendedAndStandard");
10883 else if (CHECK_FLAG(p->af_flags[afi][safi],
10884 PEER_FLAG_SEND_EXT_COMMUNITY))
10885 json_object_string_add(json_addr,
10886 "commAttriSentToNbr",
10887 "extended");
10888 else
10889 json_object_string_add(json_addr,
10890 "commAttriSentToNbr",
10891 "standard");
10892 }
10893 if (CHECK_FLAG(p->af_flags[afi][safi],
10894 PEER_FLAG_DEFAULT_ORIGINATE)) {
10895 if (p->default_rmap[afi][safi].name)
10896 json_object_string_add(
10897 json_addr, "defaultRouteMap",
10898 p->default_rmap[afi][safi].name);
10899
10900 if (paf && PAF_SUBGRP(paf)
10901 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10902 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10903 json_object_boolean_true_add(json_addr,
10904 "defaultSent");
10905 else
10906 json_object_boolean_true_add(json_addr,
10907 "defaultNotSent");
10908 }
10909
dff8f48d 10910 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10911 if (is_evpn_enabled())
60466a63
QY
10912 json_object_boolean_true_add(
10913 json_addr, "advertiseAllVnis");
dff8f48d
MK
10914 }
10915
d62a17ae 10916 if (filter->plist[FILTER_IN].name
10917 || filter->dlist[FILTER_IN].name
10918 || filter->aslist[FILTER_IN].name
10919 || filter->map[RMAP_IN].name)
10920 json_object_boolean_true_add(json_addr,
10921 "inboundPathPolicyConfig");
10922 if (filter->plist[FILTER_OUT].name
10923 || filter->dlist[FILTER_OUT].name
10924 || filter->aslist[FILTER_OUT].name
10925 || filter->map[RMAP_OUT].name || filter->usmap.name)
10926 json_object_boolean_true_add(
10927 json_addr, "outboundPathPolicyConfig");
10928
10929 /* prefix-list */
10930 if (filter->plist[FILTER_IN].name)
10931 json_object_string_add(json_addr,
10932 "incomingUpdatePrefixFilterList",
10933 filter->plist[FILTER_IN].name);
10934 if (filter->plist[FILTER_OUT].name)
10935 json_object_string_add(json_addr,
10936 "outgoingUpdatePrefixFilterList",
10937 filter->plist[FILTER_OUT].name);
10938
10939 /* distribute-list */
10940 if (filter->dlist[FILTER_IN].name)
10941 json_object_string_add(
10942 json_addr, "incomingUpdateNetworkFilterList",
10943 filter->dlist[FILTER_IN].name);
10944 if (filter->dlist[FILTER_OUT].name)
10945 json_object_string_add(
10946 json_addr, "outgoingUpdateNetworkFilterList",
10947 filter->dlist[FILTER_OUT].name);
10948
10949 /* filter-list. */
10950 if (filter->aslist[FILTER_IN].name)
10951 json_object_string_add(json_addr,
10952 "incomingUpdateAsPathFilterList",
10953 filter->aslist[FILTER_IN].name);
10954 if (filter->aslist[FILTER_OUT].name)
10955 json_object_string_add(json_addr,
10956 "outgoingUpdateAsPathFilterList",
10957 filter->aslist[FILTER_OUT].name);
10958
10959 /* route-map. */
10960 if (filter->map[RMAP_IN].name)
10961 json_object_string_add(
10962 json_addr, "routeMapForIncomingAdvertisements",
10963 filter->map[RMAP_IN].name);
10964 if (filter->map[RMAP_OUT].name)
10965 json_object_string_add(
10966 json_addr, "routeMapForOutgoingAdvertisements",
10967 filter->map[RMAP_OUT].name);
10968
9dac9fc8 10969 /* ebgp-requires-policy (inbound) */
1d3fdccf 10970 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10971 && !bgp_inbound_policy_exists(p, filter))
10972 json_object_string_add(
10973 json_addr, "inboundEbgpRequiresPolicy",
10974 "Inbound updates discarded due to missing policy");
10975
10976 /* ebgp-requires-policy (outbound) */
1d3fdccf 10977 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10978 && (!bgp_outbound_policy_exists(p, filter)))
10979 json_object_string_add(
10980 json_addr, "outboundEbgpRequiresPolicy",
10981 "Outbound updates discarded due to missing policy");
10982
d62a17ae 10983 /* unsuppress-map */
10984 if (filter->usmap.name)
10985 json_object_string_add(json_addr,
10986 "selectiveUnsuppressRouteMap",
10987 filter->usmap.name);
10988
10989 /* Receive prefix count */
10990 json_object_int_add(json_addr, "acceptedPrefixCounter",
10991 p->pcount[afi][safi]);
50e05855
AD
10992 if (paf && PAF_SUBGRP(paf))
10993 json_object_int_add(json_addr, "sentPrefixCounter",
10994 (PAF_SUBGRP(paf))->scount);
d62a17ae 10995
fde246e8
DA
10996 /* Maximum prefix */
10997 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10998 json_object_int_add(json_addr, "prefixOutAllowedMax",
10999 p->pmax_out[afi][safi]);
11000
d62a17ae 11001 /* Maximum prefix */
11002 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11003 json_object_int_add(json_addr, "prefixAllowedMax",
11004 p->pmax[afi][safi]);
11005 if (CHECK_FLAG(p->af_flags[afi][safi],
11006 PEER_FLAG_MAX_PREFIX_WARNING))
11007 json_object_boolean_true_add(
11008 json_addr, "prefixAllowedMaxWarning");
11009 json_object_int_add(json_addr,
11010 "prefixAllowedWarningThresh",
11011 p->pmax_threshold[afi][safi]);
11012 if (p->pmax_restart[afi][safi])
11013 json_object_int_add(
11014 json_addr,
11015 "prefixAllowedRestartIntervalMsecs",
11016 p->pmax_restart[afi][safi] * 60000);
11017 }
2986cac2 11018 json_object_object_add(json_neigh,
36235319 11019 get_afi_safi_str(afi, safi, true),
d62a17ae 11020 json_addr);
11021
11022 } else {
11023 filter = &p->filter[afi][safi];
11024
11025 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11026 get_afi_safi_str(afi, safi, false));
d62a17ae 11027
11028 if (peer_group_active(p))
11029 vty_out(vty, " %s peer-group member\n",
11030 p->group->name);
11031
11032 paf = peer_af_find(p, afi, safi);
11033 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11034 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11035 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11036 vty_out(vty, " Packet Queue length %d\n",
11037 bpacket_queue_virtual_length(paf));
11038 } else {
11039 vty_out(vty, " Not part of any update group\n");
11040 }
11041 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11042 || CHECK_FLAG(p->af_cap[afi][safi],
11043 PEER_CAP_ORF_PREFIX_SM_RCV)
11044 || CHECK_FLAG(p->af_cap[afi][safi],
11045 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11046 || CHECK_FLAG(p->af_cap[afi][safi],
11047 PEER_CAP_ORF_PREFIX_RM_ADV)
11048 || CHECK_FLAG(p->af_cap[afi][safi],
11049 PEER_CAP_ORF_PREFIX_RM_RCV)
11050 || CHECK_FLAG(p->af_cap[afi][safi],
11051 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11052 vty_out(vty, " AF-dependant capabilities:\n");
11053
11054 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11055 || CHECK_FLAG(p->af_cap[afi][safi],
11056 PEER_CAP_ORF_PREFIX_SM_RCV)
11057 || CHECK_FLAG(p->af_cap[afi][safi],
11058 PEER_CAP_ORF_PREFIX_RM_ADV)
11059 || CHECK_FLAG(p->af_cap[afi][safi],
11060 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11061 vty_out(vty,
11062 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11063 ORF_TYPE_PREFIX);
11064 bgp_show_peer_afi_orf_cap(
11065 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11066 PEER_CAP_ORF_PREFIX_RM_ADV,
11067 PEER_CAP_ORF_PREFIX_SM_RCV,
11068 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11069 }
11070 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11071 || CHECK_FLAG(p->af_cap[afi][safi],
11072 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11073 || CHECK_FLAG(p->af_cap[afi][safi],
11074 PEER_CAP_ORF_PREFIX_RM_ADV)
11075 || CHECK_FLAG(p->af_cap[afi][safi],
11076 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11077 vty_out(vty,
11078 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11079 ORF_TYPE_PREFIX_OLD);
11080 bgp_show_peer_afi_orf_cap(
11081 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11082 PEER_CAP_ORF_PREFIX_RM_ADV,
11083 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11084 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11085 }
11086
772270f3
QY
11087 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11088 p->host, afi, safi);
d62a17ae 11089 orf_pfx_count = prefix_bgp_show_prefix_list(
11090 NULL, afi, orf_pfx_name, use_json);
11091
11092 if (CHECK_FLAG(p->af_sflags[afi][safi],
11093 PEER_STATUS_ORF_PREFIX_SEND)
11094 || orf_pfx_count) {
11095 vty_out(vty, " Outbound Route Filter (ORF):");
11096 if (CHECK_FLAG(p->af_sflags[afi][safi],
11097 PEER_STATUS_ORF_PREFIX_SEND))
11098 vty_out(vty, " sent;");
11099 if (orf_pfx_count)
11100 vty_out(vty, " received (%d entries)",
11101 orf_pfx_count);
11102 vty_out(vty, "\n");
11103 }
11104 if (CHECK_FLAG(p->af_sflags[afi][safi],
11105 PEER_STATUS_ORF_WAIT_REFRESH))
11106 vty_out(vty,
11107 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11108
11109 if (CHECK_FLAG(p->af_flags[afi][safi],
11110 PEER_FLAG_REFLECTOR_CLIENT))
11111 vty_out(vty, " Route-Reflector Client\n");
11112 if (CHECK_FLAG(p->af_flags[afi][safi],
11113 PEER_FLAG_RSERVER_CLIENT))
11114 vty_out(vty, " Route-Server Client\n");
11115 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11116 vty_out(vty,
11117 " Inbound soft reconfiguration allowed\n");
11118
11119 if (CHECK_FLAG(p->af_flags[afi][safi],
11120 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11121 vty_out(vty,
11122 " Private AS numbers (all) replaced in updates to this neighbor\n");
11123 else if (CHECK_FLAG(p->af_flags[afi][safi],
11124 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11125 vty_out(vty,
11126 " Private AS numbers replaced in updates to this neighbor\n");
11127 else if (CHECK_FLAG(p->af_flags[afi][safi],
11128 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11129 vty_out(vty,
11130 " Private AS numbers (all) removed in updates to this neighbor\n");
11131 else if (CHECK_FLAG(p->af_flags[afi][safi],
11132 PEER_FLAG_REMOVE_PRIVATE_AS))
11133 vty_out(vty,
11134 " Private AS numbers removed in updates to this neighbor\n");
11135
dcc68b5e
MS
11136 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11137 vty_out(vty, " %s\n",
11138 bgp_addpath_names(p->addpath_type[afi][safi])
11139 ->human_description);
d62a17ae 11140
11141 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11142 vty_out(vty,
11143 " Override ASNs in outbound updates if aspath equals remote-as\n");
11144
11145 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11146 || CHECK_FLAG(p->af_flags[afi][safi],
11147 PEER_FLAG_FORCE_NEXTHOP_SELF))
11148 vty_out(vty, " NEXT_HOP is always this router\n");
11149 if (CHECK_FLAG(p->af_flags[afi][safi],
11150 PEER_FLAG_AS_PATH_UNCHANGED))
11151 vty_out(vty,
11152 " AS_PATH is propagated unchanged to this neighbor\n");
11153 if (CHECK_FLAG(p->af_flags[afi][safi],
11154 PEER_FLAG_NEXTHOP_UNCHANGED))
11155 vty_out(vty,
11156 " NEXT_HOP is propagated unchanged to this neighbor\n");
11157 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11158 vty_out(vty,
11159 " MED is propagated unchanged to this neighbor\n");
11160 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11161 || CHECK_FLAG(p->af_flags[afi][safi],
11162 PEER_FLAG_SEND_EXT_COMMUNITY)
11163 || CHECK_FLAG(p->af_flags[afi][safi],
11164 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11165 vty_out(vty,
11166 " Community attribute sent to this neighbor");
11167 if (CHECK_FLAG(p->af_flags[afi][safi],
11168 PEER_FLAG_SEND_COMMUNITY)
11169 && CHECK_FLAG(p->af_flags[afi][safi],
11170 PEER_FLAG_SEND_EXT_COMMUNITY)
11171 && CHECK_FLAG(p->af_flags[afi][safi],
11172 PEER_FLAG_SEND_LARGE_COMMUNITY))
11173 vty_out(vty, "(all)\n");
11174 else if (CHECK_FLAG(p->af_flags[afi][safi],
11175 PEER_FLAG_SEND_LARGE_COMMUNITY))
11176 vty_out(vty, "(large)\n");
11177 else if (CHECK_FLAG(p->af_flags[afi][safi],
11178 PEER_FLAG_SEND_EXT_COMMUNITY))
11179 vty_out(vty, "(extended)\n");
11180 else
11181 vty_out(vty, "(standard)\n");
11182 }
11183 if (CHECK_FLAG(p->af_flags[afi][safi],
11184 PEER_FLAG_DEFAULT_ORIGINATE)) {
11185 vty_out(vty, " Default information originate,");
11186
11187 if (p->default_rmap[afi][safi].name)
11188 vty_out(vty, " default route-map %s%s,",
11189 p->default_rmap[afi][safi].map ? "*"
11190 : "",
11191 p->default_rmap[afi][safi].name);
11192 if (paf && PAF_SUBGRP(paf)
11193 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11194 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11195 vty_out(vty, " default sent\n");
11196 else
11197 vty_out(vty, " default not sent\n");
11198 }
11199
dff8f48d
MK
11200 /* advertise-vni-all */
11201 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11202 if (is_evpn_enabled())
dff8f48d
MK
11203 vty_out(vty, " advertise-all-vni\n");
11204 }
11205
d62a17ae 11206 if (filter->plist[FILTER_IN].name
11207 || filter->dlist[FILTER_IN].name
11208 || filter->aslist[FILTER_IN].name
11209 || filter->map[RMAP_IN].name)
11210 vty_out(vty, " Inbound path policy configured\n");
11211 if (filter->plist[FILTER_OUT].name
11212 || filter->dlist[FILTER_OUT].name
11213 || filter->aslist[FILTER_OUT].name
11214 || filter->map[RMAP_OUT].name || filter->usmap.name)
11215 vty_out(vty, " Outbound path policy configured\n");
11216
11217 /* prefix-list */
11218 if (filter->plist[FILTER_IN].name)
11219 vty_out(vty,
11220 " Incoming update prefix filter list is %s%s\n",
11221 filter->plist[FILTER_IN].plist ? "*" : "",
11222 filter->plist[FILTER_IN].name);
11223 if (filter->plist[FILTER_OUT].name)
11224 vty_out(vty,
11225 " Outgoing update prefix filter list is %s%s\n",
11226 filter->plist[FILTER_OUT].plist ? "*" : "",
11227 filter->plist[FILTER_OUT].name);
11228
11229 /* distribute-list */
11230 if (filter->dlist[FILTER_IN].name)
11231 vty_out(vty,
11232 " Incoming update network filter list is %s%s\n",
11233 filter->dlist[FILTER_IN].alist ? "*" : "",
11234 filter->dlist[FILTER_IN].name);
11235 if (filter->dlist[FILTER_OUT].name)
11236 vty_out(vty,
11237 " Outgoing update network filter list is %s%s\n",
11238 filter->dlist[FILTER_OUT].alist ? "*" : "",
11239 filter->dlist[FILTER_OUT].name);
11240
11241 /* filter-list. */
11242 if (filter->aslist[FILTER_IN].name)
11243 vty_out(vty,
11244 " Incoming update AS path filter list is %s%s\n",
11245 filter->aslist[FILTER_IN].aslist ? "*" : "",
11246 filter->aslist[FILTER_IN].name);
11247 if (filter->aslist[FILTER_OUT].name)
11248 vty_out(vty,
11249 " Outgoing update AS path filter list is %s%s\n",
11250 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11251 filter->aslist[FILTER_OUT].name);
11252
11253 /* route-map. */
11254 if (filter->map[RMAP_IN].name)
11255 vty_out(vty,
11256 " Route map for incoming advertisements is %s%s\n",
11257 filter->map[RMAP_IN].map ? "*" : "",
11258 filter->map[RMAP_IN].name);
11259 if (filter->map[RMAP_OUT].name)
11260 vty_out(vty,
11261 " Route map for outgoing advertisements is %s%s\n",
11262 filter->map[RMAP_OUT].map ? "*" : "",
11263 filter->map[RMAP_OUT].name);
11264
9dac9fc8 11265 /* ebgp-requires-policy (inbound) */
1d3fdccf 11266 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11267 && !bgp_inbound_policy_exists(p, filter))
11268 vty_out(vty,
11269 " Inbound updates discarded due to missing policy\n");
11270
11271 /* ebgp-requires-policy (outbound) */
1d3fdccf 11272 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11273 && !bgp_outbound_policy_exists(p, filter))
11274 vty_out(vty,
11275 " Outbound updates discarded due to missing policy\n");
11276
d62a17ae 11277 /* unsuppress-map */
11278 if (filter->usmap.name)
11279 vty_out(vty,
11280 " Route map for selective unsuppress is %s%s\n",
11281 filter->usmap.map ? "*" : "",
11282 filter->usmap.name);
11283
11284 /* Receive prefix count */
6cde4b45 11285 vty_out(vty, " %u accepted prefixes\n",
a0a87037 11286 p->pcount[afi][safi]);
d62a17ae 11287
fde246e8
DA
11288 /* maximum-prefix-out */
11289 if (CHECK_FLAG(p->af_flags[afi][safi],
11290 PEER_FLAG_MAX_PREFIX_OUT))
11291 vty_out(vty,
6cde4b45 11292 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
11293 p->pmax_out[afi][safi]);
11294
d62a17ae 11295 /* Maximum prefix */
11296 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 11297 vty_out(vty,
6cde4b45 11298 " Maximum prefixes allowed %u%s\n",
d62a17ae 11299 p->pmax[afi][safi],
11300 CHECK_FLAG(p->af_flags[afi][safi],
11301 PEER_FLAG_MAX_PREFIX_WARNING)
11302 ? " (warning-only)"
11303 : "");
11304 vty_out(vty, " Threshold for warning message %d%%",
11305 p->pmax_threshold[afi][safi]);
11306 if (p->pmax_restart[afi][safi])
11307 vty_out(vty, ", restart interval %d min",
11308 p->pmax_restart[afi][safi]);
11309 vty_out(vty, "\n");
11310 }
11311
11312 vty_out(vty, "\n");
11313 }
11314}
11315
9f049418 11316static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 11317 json_object *json)
718e3744 11318{
d62a17ae 11319 struct bgp *bgp;
11320 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11321 char timebuf[BGP_UPTIME_LEN];
11322 char dn_flag[2];
d62a17ae 11323 afi_t afi;
11324 safi_t safi;
d7c0a89a
QY
11325 uint16_t i;
11326 uint8_t *msg;
d62a17ae 11327 json_object *json_neigh = NULL;
11328 time_t epoch_tbuf;
718e3744 11329
d62a17ae 11330 bgp = p->bgp;
11331
11332 if (use_json)
11333 json_neigh = json_object_new_object();
11334
11335 memset(dn_flag, '\0', sizeof(dn_flag));
11336 if (!p->conf_if && peer_dynamic_neighbor(p))
11337 dn_flag[0] = '*';
11338
11339 if (!use_json) {
11340 if (p->conf_if) /* Configured interface name. */
11341 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11342 BGP_PEER_SU_UNSPEC(p)
11343 ? "None"
11344 : sockunion2str(&p->su, buf,
11345 SU_ADDRSTRLEN));
11346 else /* Configured IP address. */
11347 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11348 p->host);
11349 }
11350
11351 if (use_json) {
11352 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
11353 json_object_string_add(json_neigh, "bgpNeighborAddr",
11354 "none");
11355 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
11356 json_object_string_add(
11357 json_neigh, "bgpNeighborAddr",
11358 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
11359
11360 json_object_int_add(json_neigh, "remoteAs", p->as);
11361
11362 if (p->change_local_as)
11363 json_object_int_add(json_neigh, "localAs",
11364 p->change_local_as);
11365 else
11366 json_object_int_add(json_neigh, "localAs", p->local_as);
11367
11368 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
11369 json_object_boolean_true_add(json_neigh,
11370 "localAsNoPrepend");
11371
11372 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
11373 json_object_boolean_true_add(json_neigh,
11374 "localAsReplaceAs");
11375 } else {
11376 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
11377 || (p->as_type == AS_INTERNAL))
11378 vty_out(vty, "remote AS %u, ", p->as);
11379 else
11380 vty_out(vty, "remote AS Unspecified, ");
11381 vty_out(vty, "local AS %u%s%s, ",
11382 p->change_local_as ? p->change_local_as : p->local_as,
11383 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
11384 ? " no-prepend"
11385 : "",
11386 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
11387 ? " replace-as"
11388 : "");
11389 }
faa16034
DS
11390 /* peer type internal or confed-internal */
11391 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 11392 if (use_json) {
11393 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11394 json_object_boolean_true_add(
11395 json_neigh, "nbrConfedInternalLink");
11396 else
11397 json_object_boolean_true_add(json_neigh,
11398 "nbrInternalLink");
11399 } else {
11400 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11401 vty_out(vty, "confed-internal link\n");
11402 else
11403 vty_out(vty, "internal link\n");
11404 }
faa16034
DS
11405 /* peer type external or confed-external */
11406 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 11407 if (use_json) {
11408 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11409 json_object_boolean_true_add(
11410 json_neigh, "nbrConfedExternalLink");
11411 else
11412 json_object_boolean_true_add(json_neigh,
11413 "nbrExternalLink");
11414 } else {
11415 if (bgp_confederation_peers_check(bgp, p->as))
11416 vty_out(vty, "confed-external link\n");
11417 else
11418 vty_out(vty, "external link\n");
11419 }
faa16034
DS
11420 } else {
11421 if (use_json)
11422 json_object_boolean_true_add(json_neigh,
11423 "nbrUnspecifiedLink");
11424 else
11425 vty_out(vty, "unspecified link\n");
d62a17ae 11426 }
11427
11428 /* Description. */
11429 if (p->desc) {
11430 if (use_json)
11431 json_object_string_add(json_neigh, "nbrDesc", p->desc);
11432 else
11433 vty_out(vty, " Description: %s\n", p->desc);
11434 }
11435
11436 if (p->hostname) {
11437 if (use_json) {
11438 if (p->hostname)
11439 json_object_string_add(json_neigh, "hostname",
11440 p->hostname);
11441
11442 if (p->domainname)
11443 json_object_string_add(json_neigh, "domainname",
11444 p->domainname);
11445 } else {
11446 if (p->domainname && (p->domainname[0] != '\0'))
11447 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
11448 p->domainname);
11449 else
11450 vty_out(vty, "Hostname: %s\n", p->hostname);
11451 }
11452 }
11453
11454 /* Peer-group */
11455 if (p->group) {
11456 if (use_json) {
11457 json_object_string_add(json_neigh, "peerGroup",
11458 p->group->name);
11459
11460 if (dn_flag[0]) {
11461 struct prefix prefix, *range = NULL;
11462
11463 sockunion2hostprefix(&(p->su), &prefix);
11464 range = peer_group_lookup_dynamic_neighbor_range(
11465 p->group, &prefix);
11466
11467 if (range) {
11468 prefix2str(range, buf1, sizeof(buf1));
11469 json_object_string_add(
11470 json_neigh,
11471 "peerSubnetRangeGroup", buf1);
11472 }
11473 }
11474 } else {
11475 vty_out(vty,
11476 " Member of peer-group %s for session parameters\n",
11477 p->group->name);
11478
11479 if (dn_flag[0]) {
11480 struct prefix prefix, *range = NULL;
11481
11482 sockunion2hostprefix(&(p->su), &prefix);
11483 range = peer_group_lookup_dynamic_neighbor_range(
11484 p->group, &prefix);
11485
11486 if (range) {
d62a17ae 11487 vty_out(vty,
1b78780b
DL
11488 " Belongs to the subnet range group: %pFX\n",
11489 range);
d62a17ae 11490 }
11491 }
11492 }
11493 }
11494
11495 if (use_json) {
11496 /* Administrative shutdown. */
cb9196e7
DS
11497 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11498 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11499 json_object_boolean_true_add(json_neigh,
11500 "adminShutDown");
11501
11502 /* BGP Version. */
11503 json_object_int_add(json_neigh, "bgpVersion", 4);
11504 json_object_string_add(
11505 json_neigh, "remoteRouterId",
11506 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
11507 json_object_string_add(
11508 json_neigh, "localRouterId",
11509 inet_ntop(AF_INET, &bgp->router_id, buf1,
11510 sizeof(buf1)));
d62a17ae 11511
11512 /* Confederation */
11513 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11514 && bgp_confederation_peers_check(bgp, p->as))
11515 json_object_boolean_true_add(json_neigh,
11516 "nbrCommonAdmin");
11517
11518 /* Status. */
11519 json_object_string_add(
11520 json_neigh, "bgpState",
11521 lookup_msg(bgp_status_msg, p->status, NULL));
11522
11523 if (p->status == Established) {
11524 time_t uptime;
d62a17ae 11525
11526 uptime = bgp_clock();
11527 uptime -= p->uptime;
d62a17ae 11528 epoch_tbuf = time(NULL) - uptime;
11529
d3c7efed
DS
11530 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11531 uptime * 1000);
d62a17ae 11532 json_object_string_add(json_neigh, "bgpTimerUpString",
11533 peer_uptime(p->uptime, timebuf,
11534 BGP_UPTIME_LEN, 0,
11535 NULL));
11536 json_object_int_add(json_neigh,
11537 "bgpTimerUpEstablishedEpoch",
11538 epoch_tbuf);
11539 }
11540
11541 else if (p->status == Active) {
11542 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11543 json_object_string_add(json_neigh, "bgpStateIs",
11544 "passive");
11545 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11546 json_object_string_add(json_neigh, "bgpStateIs",
11547 "passiveNSF");
11548 }
11549
11550 /* read timer */
11551 time_t uptime;
a2700b50 11552 struct tm tm;
d62a17ae 11553
11554 uptime = bgp_clock();
11555 uptime -= p->readtime;
a2700b50
MS
11556 gmtime_r(&uptime, &tm);
11557
d62a17ae 11558 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11559 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11560 + (tm.tm_hour * 3600000));
d62a17ae 11561
11562 uptime = bgp_clock();
11563 uptime -= p->last_write;
a2700b50
MS
11564 gmtime_r(&uptime, &tm);
11565
d62a17ae 11566 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11567 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11568 + (tm.tm_hour * 3600000));
d62a17ae 11569
11570 uptime = bgp_clock();
11571 uptime -= p->update_time;
a2700b50
MS
11572 gmtime_r(&uptime, &tm);
11573
d62a17ae 11574 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11575 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11576 + (tm.tm_hour * 3600000));
d62a17ae 11577
11578 /* Configured timer values. */
11579 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11580 p->v_holdtime * 1000);
11581 json_object_int_add(json_neigh,
11582 "bgpTimerKeepAliveIntervalMsecs",
11583 p->v_keepalive * 1000);
b90a8e13 11584 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11585 json_object_int_add(json_neigh,
11586 "bgpTimerConfiguredHoldTimeMsecs",
11587 p->holdtime * 1000);
11588 json_object_int_add(
11589 json_neigh,
11590 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11591 p->keepalive * 1000);
5d5393b9
DL
11592 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11593 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11594 json_object_int_add(json_neigh,
11595 "bgpTimerConfiguredHoldTimeMsecs",
11596 bgp->default_holdtime);
11597 json_object_int_add(
11598 json_neigh,
11599 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11600 bgp->default_keepalive);
d62a17ae 11601 }
11602 } else {
11603 /* Administrative shutdown. */
cb9196e7
DS
11604 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11605 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11606 vty_out(vty, " Administratively shut down\n");
11607
11608 /* BGP Version. */
11609 vty_out(vty, " BGP version 4");
0e38aeb4 11610 vty_out(vty, ", remote router ID %s",
d62a17ae 11611 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11612 vty_out(vty, ", local router ID %s\n",
11613 inet_ntop(AF_INET, &bgp->router_id, buf1,
11614 sizeof(buf1)));
d62a17ae 11615
11616 /* Confederation */
11617 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11618 && bgp_confederation_peers_check(bgp, p->as))
11619 vty_out(vty,
11620 " Neighbor under common administration\n");
11621
11622 /* Status. */
11623 vty_out(vty, " BGP state = %s",
11624 lookup_msg(bgp_status_msg, p->status, NULL));
11625
11626 if (p->status == Established)
11627 vty_out(vty, ", up for %8s",
11628 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11629 0, NULL));
11630
11631 else if (p->status == Active) {
11632 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11633 vty_out(vty, " (passive)");
11634 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11635 vty_out(vty, " (NSF passive)");
11636 }
11637 vty_out(vty, "\n");
11638
11639 /* read timer */
11640 vty_out(vty, " Last read %s",
11641 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11642 NULL));
11643 vty_out(vty, ", Last write %s\n",
11644 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11645 NULL));
11646
11647 /* Configured timer values. */
11648 vty_out(vty,
11649 " Hold time is %d, keepalive interval is %d seconds\n",
11650 p->v_holdtime, p->v_keepalive);
b90a8e13 11651 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11652 vty_out(vty, " Configured hold time is %d",
11653 p->holdtime);
11654 vty_out(vty, ", keepalive interval is %d seconds\n",
11655 p->keepalive);
5d5393b9
DL
11656 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11657 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11658 vty_out(vty, " Configured hold time is %d",
11659 bgp->default_holdtime);
11660 vty_out(vty, ", keepalive interval is %d seconds\n",
11661 bgp->default_keepalive);
d62a17ae 11662 }
11663 }
11664 /* Capability. */
11665 if (p->status == Established) {
11666 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11667 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11668 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11669 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11670 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11671 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11672 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11673 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11674 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11675 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11676 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11677 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11678 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11679 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11680 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11681 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11682 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11683 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11684 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11685 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11686 if (use_json) {
11687 json_object *json_cap = NULL;
11688
11689 json_cap = json_object_new_object();
11690
11691 /* AS4 */
11692 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11693 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11694 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11695 && CHECK_FLAG(p->cap,
11696 PEER_CAP_AS4_RCV))
11697 json_object_string_add(
11698 json_cap, "4byteAs",
11699 "advertisedAndReceived");
11700 else if (CHECK_FLAG(p->cap,
11701 PEER_CAP_AS4_ADV))
11702 json_object_string_add(
11703 json_cap, "4byteAs",
11704 "advertised");
11705 else if (CHECK_FLAG(p->cap,
11706 PEER_CAP_AS4_RCV))
11707 json_object_string_add(
11708 json_cap, "4byteAs",
11709 "received");
11710 }
11711
11712 /* AddPath */
11713 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11714 || CHECK_FLAG(p->cap,
11715 PEER_CAP_ADDPATH_ADV)) {
11716 json_object *json_add = NULL;
11717 const char *print_store;
11718
11719 json_add = json_object_new_object();
11720
05c7a1cc
QY
11721 FOREACH_AFI_SAFI (afi, safi) {
11722 json_object *json_sub = NULL;
11723 json_sub =
11724 json_object_new_object();
5cb5f4d0
DD
11725 print_store = get_afi_safi_str(
11726 afi, safi, true);
d62a17ae 11727
05c7a1cc
QY
11728 if (CHECK_FLAG(
11729 p->af_cap[afi]
11730 [safi],
11731 PEER_CAP_ADDPATH_AF_TX_ADV)
11732 || CHECK_FLAG(
11733 p->af_cap[afi]
11734 [safi],
11735 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 11736 if (CHECK_FLAG(
11737 p->af_cap
11738 [afi]
11739 [safi],
11740 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 11741 && CHECK_FLAG(
d62a17ae 11742 p->af_cap
11743 [afi]
11744 [safi],
05c7a1cc
QY
11745 PEER_CAP_ADDPATH_AF_TX_RCV))
11746 json_object_boolean_true_add(
11747 json_sub,
11748 "txAdvertisedAndReceived");
11749 else if (
11750 CHECK_FLAG(
11751 p->af_cap
11752 [afi]
11753 [safi],
11754 PEER_CAP_ADDPATH_AF_TX_ADV))
11755 json_object_boolean_true_add(
11756 json_sub,
11757 "txAdvertised");
11758 else if (
11759 CHECK_FLAG(
11760 p->af_cap
11761 [afi]
11762 [safi],
11763 PEER_CAP_ADDPATH_AF_TX_RCV))
11764 json_object_boolean_true_add(
11765 json_sub,
11766 "txReceived");
11767 }
d62a17ae 11768
05c7a1cc
QY
11769 if (CHECK_FLAG(
11770 p->af_cap[afi]
11771 [safi],
11772 PEER_CAP_ADDPATH_AF_RX_ADV)
11773 || CHECK_FLAG(
11774 p->af_cap[afi]
11775 [safi],
11776 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 11777 if (CHECK_FLAG(
11778 p->af_cap
11779 [afi]
11780 [safi],
11781 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 11782 && CHECK_FLAG(
d62a17ae 11783 p->af_cap
11784 [afi]
11785 [safi],
11786 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
11787 json_object_boolean_true_add(
11788 json_sub,
11789 "rxAdvertisedAndReceived");
11790 else if (
11791 CHECK_FLAG(
11792 p->af_cap
11793 [afi]
11794 [safi],
11795 PEER_CAP_ADDPATH_AF_RX_ADV))
11796 json_object_boolean_true_add(
11797 json_sub,
11798 "rxAdvertised");
11799 else if (
11800 CHECK_FLAG(
11801 p->af_cap
11802 [afi]
11803 [safi],
11804 PEER_CAP_ADDPATH_AF_RX_RCV))
11805 json_object_boolean_true_add(
11806 json_sub,
11807 "rxReceived");
d62a17ae 11808 }
11809
05c7a1cc
QY
11810 if (CHECK_FLAG(
11811 p->af_cap[afi]
11812 [safi],
11813 PEER_CAP_ADDPATH_AF_TX_ADV)
11814 || CHECK_FLAG(
11815 p->af_cap[afi]
11816 [safi],
11817 PEER_CAP_ADDPATH_AF_TX_RCV)
11818 || CHECK_FLAG(
11819 p->af_cap[afi]
11820 [safi],
11821 PEER_CAP_ADDPATH_AF_RX_ADV)
11822 || CHECK_FLAG(
11823 p->af_cap[afi]
11824 [safi],
11825 PEER_CAP_ADDPATH_AF_RX_RCV))
11826 json_object_object_add(
11827 json_add,
11828 print_store,
11829 json_sub);
11830 else
11831 json_object_free(
11832 json_sub);
11833 }
11834
d62a17ae 11835 json_object_object_add(
11836 json_cap, "addPath", json_add);
11837 }
11838
11839 /* Dynamic */
11840 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11841 || CHECK_FLAG(p->cap,
11842 PEER_CAP_DYNAMIC_ADV)) {
11843 if (CHECK_FLAG(p->cap,
11844 PEER_CAP_DYNAMIC_ADV)
11845 && CHECK_FLAG(p->cap,
11846 PEER_CAP_DYNAMIC_RCV))
11847 json_object_string_add(
11848 json_cap, "dynamic",
11849 "advertisedAndReceived");
11850 else if (CHECK_FLAG(
11851 p->cap,
11852 PEER_CAP_DYNAMIC_ADV))
11853 json_object_string_add(
11854 json_cap, "dynamic",
11855 "advertised");
11856 else if (CHECK_FLAG(
11857 p->cap,
11858 PEER_CAP_DYNAMIC_RCV))
11859 json_object_string_add(
11860 json_cap, "dynamic",
11861 "received");
11862 }
11863
11864 /* Extended nexthop */
11865 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11866 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11867 json_object *json_nxt = NULL;
11868 const char *print_store;
11869
11870
11871 if (CHECK_FLAG(p->cap,
11872 PEER_CAP_ENHE_ADV)
11873 && CHECK_FLAG(p->cap,
11874 PEER_CAP_ENHE_RCV))
11875 json_object_string_add(
11876 json_cap,
11877 "extendedNexthop",
11878 "advertisedAndReceived");
11879 else if (CHECK_FLAG(p->cap,
11880 PEER_CAP_ENHE_ADV))
11881 json_object_string_add(
11882 json_cap,
11883 "extendedNexthop",
11884 "advertised");
11885 else if (CHECK_FLAG(p->cap,
11886 PEER_CAP_ENHE_RCV))
11887 json_object_string_add(
11888 json_cap,
11889 "extendedNexthop",
11890 "received");
11891
11892 if (CHECK_FLAG(p->cap,
11893 PEER_CAP_ENHE_RCV)) {
11894 json_nxt =
11895 json_object_new_object();
11896
11897 for (safi = SAFI_UNICAST;
11898 safi < SAFI_MAX; safi++) {
11899 if (CHECK_FLAG(
11900 p->af_cap
11901 [AFI_IP]
11902 [safi],
11903 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11904 print_store = get_afi_safi_str(
d62a17ae 11905 AFI_IP,
5cb5f4d0 11906 safi, true);
d62a17ae 11907 json_object_string_add(
11908 json_nxt,
11909 print_store,
54f29523 11910 "recieved"); /* misspelled for compatibility */
d62a17ae 11911 }
11912 }
11913 json_object_object_add(
11914 json_cap,
11915 "extendedNexthopFamililesByPeer",
11916 json_nxt);
11917 }
11918 }
11919
11920 /* Route Refresh */
11921 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11922 || CHECK_FLAG(p->cap,
11923 PEER_CAP_REFRESH_NEW_RCV)
11924 || CHECK_FLAG(p->cap,
11925 PEER_CAP_REFRESH_OLD_RCV)) {
11926 if (CHECK_FLAG(p->cap,
11927 PEER_CAP_REFRESH_ADV)
11928 && (CHECK_FLAG(
11929 p->cap,
11930 PEER_CAP_REFRESH_NEW_RCV)
11931 || CHECK_FLAG(
11932 p->cap,
11933 PEER_CAP_REFRESH_OLD_RCV))) {
11934 if (CHECK_FLAG(
11935 p->cap,
11936 PEER_CAP_REFRESH_OLD_RCV)
11937 && CHECK_FLAG(
11938 p->cap,
11939 PEER_CAP_REFRESH_NEW_RCV))
11940 json_object_string_add(
11941 json_cap,
11942 "routeRefresh",
11943 "advertisedAndReceivedOldNew");
11944 else {
11945 if (CHECK_FLAG(
11946 p->cap,
11947 PEER_CAP_REFRESH_OLD_RCV))
11948 json_object_string_add(
11949 json_cap,
11950 "routeRefresh",
11951 "advertisedAndReceivedOld");
11952 else
11953 json_object_string_add(
11954 json_cap,
11955 "routeRefresh",
11956 "advertisedAndReceivedNew");
11957 }
11958 } else if (
11959 CHECK_FLAG(
11960 p->cap,
11961 PEER_CAP_REFRESH_ADV))
11962 json_object_string_add(
11963 json_cap,
11964 "routeRefresh",
11965 "advertised");
11966 else if (
11967 CHECK_FLAG(
11968 p->cap,
11969 PEER_CAP_REFRESH_NEW_RCV)
11970 || CHECK_FLAG(
11971 p->cap,
11972 PEER_CAP_REFRESH_OLD_RCV))
11973 json_object_string_add(
11974 json_cap,
11975 "routeRefresh",
11976 "received");
11977 }
11978
11979 /* Multiprotocol Extensions */
11980 json_object *json_multi = NULL;
11981 json_multi = json_object_new_object();
11982
05c7a1cc
QY
11983 FOREACH_AFI_SAFI (afi, safi) {
11984 if (p->afc_adv[afi][safi]
11985 || p->afc_recv[afi][safi]) {
11986 json_object *json_exten = NULL;
11987 json_exten =
11988 json_object_new_object();
11989
d62a17ae 11990 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11991 && p->afc_recv[afi][safi])
11992 json_object_boolean_true_add(
11993 json_exten,
11994 "advertisedAndReceived");
11995 else if (p->afc_adv[afi][safi])
11996 json_object_boolean_true_add(
11997 json_exten,
11998 "advertised");
11999 else if (p->afc_recv[afi][safi])
12000 json_object_boolean_true_add(
12001 json_exten,
12002 "received");
d62a17ae 12003
05c7a1cc
QY
12004 json_object_object_add(
12005 json_multi,
5cb5f4d0
DD
12006 get_afi_safi_str(afi,
12007 safi,
12008 true),
05c7a1cc 12009 json_exten);
d62a17ae 12010 }
12011 }
12012 json_object_object_add(
12013 json_cap, "multiprotocolExtensions",
12014 json_multi);
12015
d77114b7 12016 /* Hostname capabilities */
60466a63 12017 json_object *json_hname = NULL;
d77114b7
MK
12018
12019 json_hname = json_object_new_object();
12020
12021 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12022 json_object_string_add(
60466a63
QY
12023 json_hname, "advHostName",
12024 bgp->peer_self->hostname
12025 ? bgp->peer_self
12026 ->hostname
d77114b7
MK
12027 : "n/a");
12028 json_object_string_add(
60466a63
QY
12029 json_hname, "advDomainName",
12030 bgp->peer_self->domainname
12031 ? bgp->peer_self
12032 ->domainname
d77114b7
MK
12033 : "n/a");
12034 }
12035
12036
12037 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12038 json_object_string_add(
60466a63
QY
12039 json_hname, "rcvHostName",
12040 p->hostname ? p->hostname
12041 : "n/a");
d77114b7 12042 json_object_string_add(
60466a63
QY
12043 json_hname, "rcvDomainName",
12044 p->domainname ? p->domainname
12045 : "n/a");
d77114b7
MK
12046 }
12047
60466a63 12048 json_object_object_add(json_cap, "hostName",
d77114b7
MK
12049 json_hname);
12050
d62a17ae 12051 /* Gracefull Restart */
12052 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12053 || CHECK_FLAG(p->cap,
12054 PEER_CAP_RESTART_ADV)) {
12055 if (CHECK_FLAG(p->cap,
12056 PEER_CAP_RESTART_ADV)
12057 && CHECK_FLAG(p->cap,
12058 PEER_CAP_RESTART_RCV))
12059 json_object_string_add(
12060 json_cap,
12061 "gracefulRestart",
12062 "advertisedAndReceived");
12063 else if (CHECK_FLAG(
12064 p->cap,
12065 PEER_CAP_RESTART_ADV))
12066 json_object_string_add(
12067 json_cap,
12068 "gracefulRestartCapability",
12069 "advertised");
12070 else if (CHECK_FLAG(
12071 p->cap,
12072 PEER_CAP_RESTART_RCV))
12073 json_object_string_add(
12074 json_cap,
12075 "gracefulRestartCapability",
12076 "received");
12077
12078 if (CHECK_FLAG(p->cap,
12079 PEER_CAP_RESTART_RCV)) {
12080 int restart_af_count = 0;
12081 json_object *json_restart =
12082 NULL;
12083 json_restart =
12084 json_object_new_object();
12085
12086 json_object_int_add(
12087 json_cap,
12088 "gracefulRestartRemoteTimerMsecs",
12089 p->v_gr_restart * 1000);
12090
05c7a1cc
QY
12091 FOREACH_AFI_SAFI (afi, safi) {
12092 if (CHECK_FLAG(
12093 p->af_cap
12094 [afi]
12095 [safi],
12096 PEER_CAP_RESTART_AF_RCV)) {
12097 json_object *
12098 json_sub =
12099 NULL;
12100 json_sub =
12101 json_object_new_object();
12102
d62a17ae 12103 if (CHECK_FLAG(
12104 p->af_cap
12105 [afi]
12106 [safi],
05c7a1cc
QY
12107 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12108 json_object_boolean_true_add(
12109 json_sub,
12110 "preserved");
12111 restart_af_count++;
12112 json_object_object_add(
12113 json_restart,
5cb5f4d0 12114 get_afi_safi_str(
05c7a1cc 12115 afi,
5cb5f4d0
DD
12116 safi,
12117 true),
05c7a1cc 12118 json_sub);
d62a17ae 12119 }
12120 }
12121 if (!restart_af_count) {
12122 json_object_string_add(
12123 json_cap,
12124 "addressFamiliesByPeer",
12125 "none");
12126 json_object_free(
12127 json_restart);
12128 } else
12129 json_object_object_add(
12130 json_cap,
12131 "addressFamiliesByPeer",
12132 json_restart);
12133 }
12134 }
12135 json_object_object_add(json_neigh,
12136 "neighborCapabilities",
12137 json_cap);
12138 } else {
12139 vty_out(vty, " Neighbor capabilities:\n");
12140
12141 /* AS4 */
12142 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12143 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12144 vty_out(vty, " 4 Byte AS:");
12145 if (CHECK_FLAG(p->cap,
12146 PEER_CAP_AS4_ADV))
12147 vty_out(vty, " advertised");
12148 if (CHECK_FLAG(p->cap,
12149 PEER_CAP_AS4_RCV))
12150 vty_out(vty, " %sreceived",
12151 CHECK_FLAG(
12152 p->cap,
12153 PEER_CAP_AS4_ADV)
12154 ? "and "
12155 : "");
12156 vty_out(vty, "\n");
12157 }
12158
12159 /* AddPath */
12160 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12161 || CHECK_FLAG(p->cap,
12162 PEER_CAP_ADDPATH_ADV)) {
12163 vty_out(vty, " AddPath:\n");
12164
05c7a1cc
QY
12165 FOREACH_AFI_SAFI (afi, safi) {
12166 if (CHECK_FLAG(
12167 p->af_cap[afi]
12168 [safi],
12169 PEER_CAP_ADDPATH_AF_TX_ADV)
12170 || CHECK_FLAG(
12171 p->af_cap[afi]
12172 [safi],
12173 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12174 vty_out(vty,
12175 " %s: TX ",
5cb5f4d0 12176 get_afi_safi_str(
05c7a1cc 12177 afi,
5cb5f4d0
DD
12178 safi,
12179 false));
05c7a1cc 12180
d62a17ae 12181 if (CHECK_FLAG(
12182 p->af_cap
12183 [afi]
12184 [safi],
05c7a1cc 12185 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 12186 vty_out(vty,
05c7a1cc 12187 "advertised %s",
5cb5f4d0 12188 get_afi_safi_str(
d62a17ae 12189 afi,
5cb5f4d0
DD
12190 safi,
12191 false));
d62a17ae 12192
05c7a1cc
QY
12193 if (CHECK_FLAG(
12194 p->af_cap
12195 [afi]
12196 [safi],
12197 PEER_CAP_ADDPATH_AF_TX_RCV))
12198 vty_out(vty,
12199 "%sreceived",
12200 CHECK_FLAG(
12201 p->af_cap
12202 [afi]
12203 [safi],
12204 PEER_CAP_ADDPATH_AF_TX_ADV)
12205 ? " and "
12206 : "");
d62a17ae 12207
05c7a1cc
QY
12208 vty_out(vty, "\n");
12209 }
d62a17ae 12210
05c7a1cc
QY
12211 if (CHECK_FLAG(
12212 p->af_cap[afi]
12213 [safi],
12214 PEER_CAP_ADDPATH_AF_RX_ADV)
12215 || CHECK_FLAG(
12216 p->af_cap[afi]
12217 [safi],
12218 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12219 vty_out(vty,
12220 " %s: RX ",
5cb5f4d0 12221 get_afi_safi_str(
05c7a1cc 12222 afi,
5cb5f4d0
DD
12223 safi,
12224 false));
d62a17ae 12225
12226 if (CHECK_FLAG(
12227 p->af_cap
12228 [afi]
12229 [safi],
05c7a1cc 12230 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 12231 vty_out(vty,
05c7a1cc 12232 "advertised %s",
5cb5f4d0 12233 get_afi_safi_str(
d62a17ae 12234 afi,
5cb5f4d0
DD
12235 safi,
12236 false));
d62a17ae 12237
05c7a1cc
QY
12238 if (CHECK_FLAG(
12239 p->af_cap
12240 [afi]
12241 [safi],
12242 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 12243 vty_out(vty,
05c7a1cc
QY
12244 "%sreceived",
12245 CHECK_FLAG(
12246 p->af_cap
12247 [afi]
12248 [safi],
12249 PEER_CAP_ADDPATH_AF_RX_ADV)
12250 ? " and "
12251 : "");
12252
12253 vty_out(vty, "\n");
d62a17ae 12254 }
05c7a1cc 12255 }
d62a17ae 12256 }
12257
12258 /* Dynamic */
12259 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12260 || CHECK_FLAG(p->cap,
12261 PEER_CAP_DYNAMIC_ADV)) {
12262 vty_out(vty, " Dynamic:");
12263 if (CHECK_FLAG(p->cap,
12264 PEER_CAP_DYNAMIC_ADV))
12265 vty_out(vty, " advertised");
12266 if (CHECK_FLAG(p->cap,
12267 PEER_CAP_DYNAMIC_RCV))
12268 vty_out(vty, " %sreceived",
12269 CHECK_FLAG(
12270 p->cap,
12271 PEER_CAP_DYNAMIC_ADV)
12272 ? "and "
12273 : "");
12274 vty_out(vty, "\n");
12275 }
12276
12277 /* Extended nexthop */
12278 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12279 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12280 vty_out(vty, " Extended nexthop:");
12281 if (CHECK_FLAG(p->cap,
12282 PEER_CAP_ENHE_ADV))
12283 vty_out(vty, " advertised");
12284 if (CHECK_FLAG(p->cap,
12285 PEER_CAP_ENHE_RCV))
12286 vty_out(vty, " %sreceived",
12287 CHECK_FLAG(
12288 p->cap,
12289 PEER_CAP_ENHE_ADV)
12290 ? "and "
12291 : "");
12292 vty_out(vty, "\n");
12293
12294 if (CHECK_FLAG(p->cap,
12295 PEER_CAP_ENHE_RCV)) {
12296 vty_out(vty,
12297 " Address families by peer:\n ");
12298 for (safi = SAFI_UNICAST;
12299 safi < SAFI_MAX; safi++)
12300 if (CHECK_FLAG(
12301 p->af_cap
12302 [AFI_IP]
12303 [safi],
12304 PEER_CAP_ENHE_AF_RCV))
12305 vty_out(vty,
12306 " %s\n",
5cb5f4d0 12307 get_afi_safi_str(
d62a17ae 12308 AFI_IP,
5cb5f4d0
DD
12309 safi,
12310 false));
d62a17ae 12311 }
12312 }
12313
12314 /* Route Refresh */
12315 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12316 || CHECK_FLAG(p->cap,
12317 PEER_CAP_REFRESH_NEW_RCV)
12318 || CHECK_FLAG(p->cap,
12319 PEER_CAP_REFRESH_OLD_RCV)) {
12320 vty_out(vty, " Route refresh:");
12321 if (CHECK_FLAG(p->cap,
12322 PEER_CAP_REFRESH_ADV))
12323 vty_out(vty, " advertised");
12324 if (CHECK_FLAG(p->cap,
12325 PEER_CAP_REFRESH_NEW_RCV)
12326 || CHECK_FLAG(
12327 p->cap,
12328 PEER_CAP_REFRESH_OLD_RCV))
12329 vty_out(vty, " %sreceived(%s)",
12330 CHECK_FLAG(
12331 p->cap,
12332 PEER_CAP_REFRESH_ADV)
12333 ? "and "
12334 : "",
12335 (CHECK_FLAG(
12336 p->cap,
12337 PEER_CAP_REFRESH_OLD_RCV)
12338 && CHECK_FLAG(
12339 p->cap,
12340 PEER_CAP_REFRESH_NEW_RCV))
12341 ? "old & new"
12342 : CHECK_FLAG(
12343 p->cap,
12344 PEER_CAP_REFRESH_OLD_RCV)
12345 ? "old"
12346 : "new");
12347
12348 vty_out(vty, "\n");
12349 }
12350
12351 /* Multiprotocol Extensions */
05c7a1cc
QY
12352 FOREACH_AFI_SAFI (afi, safi)
12353 if (p->afc_adv[afi][safi]
12354 || p->afc_recv[afi][safi]) {
12355 vty_out(vty,
12356 " Address Family %s:",
5cb5f4d0
DD
12357 get_afi_safi_str(
12358 afi,
12359 safi,
12360 false));
05c7a1cc 12361 if (p->afc_adv[afi][safi])
d62a17ae 12362 vty_out(vty,
05c7a1cc
QY
12363 " advertised");
12364 if (p->afc_recv[afi][safi])
12365 vty_out(vty,
12366 " %sreceived",
12367 p->afc_adv[afi]
12368 [safi]
12369 ? "and "
12370 : "");
12371 vty_out(vty, "\n");
12372 }
d62a17ae 12373
12374 /* Hostname capability */
60466a63 12375 vty_out(vty, " Hostname Capability:");
d77114b7
MK
12376
12377 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
12378 vty_out(vty,
12379 " advertised (name: %s,domain name: %s)",
60466a63
QY
12380 bgp->peer_self->hostname
12381 ? bgp->peer_self
12382 ->hostname
d77114b7 12383 : "n/a",
60466a63
QY
12384 bgp->peer_self->domainname
12385 ? bgp->peer_self
12386 ->domainname
d77114b7
MK
12387 : "n/a");
12388 } else {
12389 vty_out(vty, " not advertised");
d62a17ae 12390 }
12391
d77114b7 12392 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
12393 vty_out(vty,
12394 " received (name: %s,domain name: %s)",
60466a63
QY
12395 p->hostname ? p->hostname
12396 : "n/a",
12397 p->domainname ? p->domainname
12398 : "n/a");
d77114b7
MK
12399 } else {
12400 vty_out(vty, " not received");
12401 }
12402
12403 vty_out(vty, "\n");
12404
61bfbd51 12405 /* Graceful Restart */
d62a17ae 12406 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12407 || CHECK_FLAG(p->cap,
12408 PEER_CAP_RESTART_ADV)) {
12409 vty_out(vty,
61bfbd51 12410 " Graceful Restart Capability:");
d62a17ae 12411 if (CHECK_FLAG(p->cap,
12412 PEER_CAP_RESTART_ADV))
12413 vty_out(vty, " advertised");
12414 if (CHECK_FLAG(p->cap,
12415 PEER_CAP_RESTART_RCV))
12416 vty_out(vty, " %sreceived",
12417 CHECK_FLAG(
12418 p->cap,
12419 PEER_CAP_RESTART_ADV)
12420 ? "and "
12421 : "");
12422 vty_out(vty, "\n");
12423
12424 if (CHECK_FLAG(p->cap,
12425 PEER_CAP_RESTART_RCV)) {
12426 int restart_af_count = 0;
12427
12428 vty_out(vty,
12429 " Remote Restart timer is %d seconds\n",
12430 p->v_gr_restart);
12431 vty_out(vty,
12432 " Address families by peer:\n ");
12433
05c7a1cc
QY
12434 FOREACH_AFI_SAFI (afi, safi)
12435 if (CHECK_FLAG(
12436 p->af_cap
12437 [afi]
12438 [safi],
12439 PEER_CAP_RESTART_AF_RCV)) {
12440 vty_out(vty,
12441 "%s%s(%s)",
12442 restart_af_count
12443 ? ", "
12444 : "",
5cb5f4d0 12445 get_afi_safi_str(
05c7a1cc 12446 afi,
5cb5f4d0
DD
12447 safi,
12448 false),
05c7a1cc
QY
12449 CHECK_FLAG(
12450 p->af_cap
12451 [afi]
12452 [safi],
12453 PEER_CAP_RESTART_AF_PRESERVE_RCV)
12454 ? "preserved"
12455 : "not preserved");
12456 restart_af_count++;
12457 }
d62a17ae 12458 if (!restart_af_count)
12459 vty_out(vty, "none");
12460 vty_out(vty, "\n");
12461 }
2986cac2 12462 } /* Gracefull Restart */
d62a17ae 12463 }
12464 }
12465 }
12466
12467 /* graceful restart information */
d62a17ae 12468 json_object *json_grace = NULL;
12469 json_object *json_grace_send = NULL;
12470 json_object *json_grace_recv = NULL;
12471 int eor_send_af_count = 0;
12472 int eor_receive_af_count = 0;
12473
12474 if (use_json) {
12475 json_grace = json_object_new_object();
12476 json_grace_send = json_object_new_object();
12477 json_grace_recv = json_object_new_object();
12478
36235319
QY
12479 if ((p->status == Established)
12480 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
12481 FOREACH_AFI_SAFI (afi, safi) {
12482 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 12483 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
12484 json_object_boolean_true_add(
12485 json_grace_send,
5cb5f4d0
DD
12486 get_afi_safi_str(afi,
12487 safi,
12488 true));
05c7a1cc 12489 eor_send_af_count++;
d62a17ae 12490 }
12491 }
05c7a1cc
QY
12492 FOREACH_AFI_SAFI (afi, safi) {
12493 if (CHECK_FLAG(
36235319
QY
12494 p->af_sflags[afi][safi],
12495 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
12496 json_object_boolean_true_add(
12497 json_grace_recv,
5cb5f4d0
DD
12498 get_afi_safi_str(afi,
12499 safi,
12500 true));
05c7a1cc 12501 eor_receive_af_count++;
d62a17ae 12502 }
12503 }
12504 }
36235319
QY
12505 json_object_object_add(json_grace, "endOfRibSend",
12506 json_grace_send);
12507 json_object_object_add(json_grace, "endOfRibRecv",
12508 json_grace_recv);
d62a17ae 12509
d62a17ae 12510
12511 if (p->t_gr_restart)
12512 json_object_int_add(json_grace,
12513 "gracefulRestartTimerMsecs",
12514 thread_timer_remain_second(
12515 p->t_gr_restart)
12516 * 1000);
12517
12518 if (p->t_gr_stale)
12519 json_object_int_add(
12520 json_grace,
12521 "gracefulStalepathTimerMsecs",
12522 thread_timer_remain_second(
12523 p->t_gr_stale)
12524 * 1000);
2986cac2 12525 /* more gr info in new format */
12526 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 12527 json_grace);
d62a17ae 12528 json_object_object_add(
12529 json_neigh, "gracefulRestartInfo", json_grace);
12530 } else {
2089dd80 12531 vty_out(vty, " Graceful restart information:\n");
36235319
QY
12532 if ((p->status == Established)
12533 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12534
d62a17ae 12535 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
12536 FOREACH_AFI_SAFI (afi, safi) {
12537 if (CHECK_FLAG(p->af_sflags[afi][safi],
12538 PEER_STATUS_EOR_SEND)) {
12539 vty_out(vty, "%s%s",
12540 eor_send_af_count ? ", "
12541 : "",
36235319
QY
12542 get_afi_safi_str(
12543 afi, safi,
12544 false));
05c7a1cc 12545 eor_send_af_count++;
d62a17ae 12546 }
12547 }
12548 vty_out(vty, "\n");
12549 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
12550 FOREACH_AFI_SAFI (afi, safi) {
12551 if (CHECK_FLAG(
12552 p->af_sflags[afi][safi],
12553 PEER_STATUS_EOR_RECEIVED)) {
12554 vty_out(vty, "%s%s",
12555 eor_receive_af_count
12556 ? ", "
12557 : "",
5cb5f4d0
DD
12558 get_afi_safi_str(afi,
12559 safi,
12560 false));
05c7a1cc 12561 eor_receive_af_count++;
d62a17ae 12562 }
12563 }
12564 vty_out(vty, "\n");
12565 }
12566
12567 if (p->t_gr_restart)
12568 vty_out(vty,
12569 " The remaining time of restart timer is %ld\n",
12570 thread_timer_remain_second(
12571 p->t_gr_restart));
12572
12573 if (p->t_gr_stale)
12574 vty_out(vty,
12575 " The remaining time of stalepath timer is %ld\n",
12576 thread_timer_remain_second(
12577 p->t_gr_stale));
2986cac2 12578
12579 /* more gr info in new format */
12580 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12581 }
2986cac2 12582
d62a17ae 12583 if (use_json) {
12584 json_object *json_stat = NULL;
12585 json_stat = json_object_new_object();
12586 /* Packet counts. */
43aa5965
QY
12587
12588 atomic_size_t outq_count, inq_count;
12589 outq_count = atomic_load_explicit(&p->obuf->count,
12590 memory_order_relaxed);
12591 inq_count = atomic_load_explicit(&p->ibuf->count,
12592 memory_order_relaxed);
12593
12594 json_object_int_add(json_stat, "depthInq",
12595 (unsigned long)inq_count);
d62a17ae 12596 json_object_int_add(json_stat, "depthOutq",
43aa5965 12597 (unsigned long)outq_count);
0112e9e0
QY
12598 json_object_int_add(json_stat, "opensSent",
12599 atomic_load_explicit(&p->open_out,
12600 memory_order_relaxed));
12601 json_object_int_add(json_stat, "opensRecv",
12602 atomic_load_explicit(&p->open_in,
12603 memory_order_relaxed));
d62a17ae 12604 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12605 atomic_load_explicit(&p->notify_out,
12606 memory_order_relaxed));
d62a17ae 12607 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12608 atomic_load_explicit(&p->notify_in,
12609 memory_order_relaxed));
12610 json_object_int_add(json_stat, "updatesSent",
12611 atomic_load_explicit(&p->update_out,
12612 memory_order_relaxed));
12613 json_object_int_add(json_stat, "updatesRecv",
12614 atomic_load_explicit(&p->update_in,
12615 memory_order_relaxed));
d62a17ae 12616 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12617 atomic_load_explicit(&p->keepalive_out,
12618 memory_order_relaxed));
d62a17ae 12619 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12620 atomic_load_explicit(&p->keepalive_in,
12621 memory_order_relaxed));
d62a17ae 12622 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12623 atomic_load_explicit(&p->refresh_out,
12624 memory_order_relaxed));
d62a17ae 12625 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12626 atomic_load_explicit(&p->refresh_in,
12627 memory_order_relaxed));
d62a17ae 12628 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12629 atomic_load_explicit(&p->dynamic_cap_out,
12630 memory_order_relaxed));
d62a17ae 12631 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12632 atomic_load_explicit(&p->dynamic_cap_in,
12633 memory_order_relaxed));
12634 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12635 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12636 json_object_object_add(json_neigh, "messageStats", json_stat);
12637 } else {
43aa5965
QY
12638 atomic_size_t outq_count, inq_count;
12639 outq_count = atomic_load_explicit(&p->obuf->count,
12640 memory_order_relaxed);
12641 inq_count = atomic_load_explicit(&p->ibuf->count,
12642 memory_order_relaxed);
12643
d62a17ae 12644 /* Packet counts. */
12645 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12646 vty_out(vty, " Inq depth is %zu\n", inq_count);
12647 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12648 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12649 vty_out(vty, " Opens: %10d %10d\n",
12650 atomic_load_explicit(&p->open_out,
12651 memory_order_relaxed),
12652 atomic_load_explicit(&p->open_in,
12653 memory_order_relaxed));
12654 vty_out(vty, " Notifications: %10d %10d\n",
12655 atomic_load_explicit(&p->notify_out,
12656 memory_order_relaxed),
12657 atomic_load_explicit(&p->notify_in,
12658 memory_order_relaxed));
12659 vty_out(vty, " Updates: %10d %10d\n",
12660 atomic_load_explicit(&p->update_out,
12661 memory_order_relaxed),
12662 atomic_load_explicit(&p->update_in,
12663 memory_order_relaxed));
12664 vty_out(vty, " Keepalives: %10d %10d\n",
12665 atomic_load_explicit(&p->keepalive_out,
12666 memory_order_relaxed),
12667 atomic_load_explicit(&p->keepalive_in,
12668 memory_order_relaxed));
12669 vty_out(vty, " Route Refresh: %10d %10d\n",
12670 atomic_load_explicit(&p->refresh_out,
12671 memory_order_relaxed),
12672 atomic_load_explicit(&p->refresh_in,
12673 memory_order_relaxed));
d62a17ae 12674 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12675 atomic_load_explicit(&p->dynamic_cap_out,
12676 memory_order_relaxed),
12677 atomic_load_explicit(&p->dynamic_cap_in,
12678 memory_order_relaxed));
12679 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12680 PEER_TOTAL_RX(p));
d62a17ae 12681 }
12682
12683 if (use_json) {
12684 /* advertisement-interval */
12685 json_object_int_add(json_neigh,
12686 "minBtwnAdvertisementRunsTimerMsecs",
12687 p->v_routeadv * 1000);
12688
12689 /* Update-source. */
12690 if (p->update_if || p->update_source) {
12691 if (p->update_if)
12692 json_object_string_add(json_neigh,
12693 "updateSource",
12694 p->update_if);
12695 else if (p->update_source)
12696 json_object_string_add(
12697 json_neigh, "updateSource",
12698 sockunion2str(p->update_source, buf1,
12699 SU_ADDRSTRLEN));
12700 }
12701 } else {
12702 /* advertisement-interval */
12703 vty_out(vty,
12704 " Minimum time between advertisement runs is %d seconds\n",
12705 p->v_routeadv);
12706
12707 /* Update-source. */
12708 if (p->update_if || p->update_source) {
12709 vty_out(vty, " Update source is ");
12710 if (p->update_if)
12711 vty_out(vty, "%s", p->update_if);
12712 else if (p->update_source)
12713 vty_out(vty, "%s",
12714 sockunion2str(p->update_source, buf1,
12715 SU_ADDRSTRLEN));
12716 vty_out(vty, "\n");
12717 }
12718
12719 vty_out(vty, "\n");
12720 }
12721
12722 /* Address Family Information */
12723 json_object *json_hold = NULL;
12724
12725 if (use_json)
12726 json_hold = json_object_new_object();
12727
05c7a1cc
QY
12728 FOREACH_AFI_SAFI (afi, safi)
12729 if (p->afc[afi][safi])
12730 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12731 json_hold);
d62a17ae 12732
12733 if (use_json) {
12734 json_object_object_add(json_neigh, "addressFamilyInfo",
12735 json_hold);
12736 json_object_int_add(json_neigh, "connectionsEstablished",
12737 p->established);
12738 json_object_int_add(json_neigh, "connectionsDropped",
12739 p->dropped);
12740 } else
12741 vty_out(vty, " Connections established %d; dropped %d\n",
12742 p->established, p->dropped);
12743
12744 if (!p->last_reset) {
12745 if (use_json)
12746 json_object_string_add(json_neigh, "lastReset",
12747 "never");
12748 else
12749 vty_out(vty, " Last reset never\n");
12750 } else {
12751 if (use_json) {
12752 time_t uptime;
a2700b50 12753 struct tm tm;
d62a17ae 12754
12755 uptime = bgp_clock();
12756 uptime -= p->resettime;
a2700b50
MS
12757 gmtime_r(&uptime, &tm);
12758
d62a17ae 12759 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
12760 (tm.tm_sec * 1000)
12761 + (tm.tm_min * 60000)
12762 + (tm.tm_hour * 3600000));
3577f1c5 12763 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 12764 } else {
12765 vty_out(vty, " Last reset %s, ",
12766 peer_uptime(p->resettime, timebuf,
12767 BGP_UPTIME_LEN, 0, NULL));
12768
3577f1c5 12769 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 12770 if (p->last_reset_cause_size) {
12771 msg = p->last_reset_cause;
12772 vty_out(vty,
12773 " Message received that caused BGP to send a NOTIFICATION:\n ");
12774 for (i = 1; i <= p->last_reset_cause_size;
12775 i++) {
12776 vty_out(vty, "%02X", *msg++);
12777
12778 if (i != p->last_reset_cause_size) {
12779 if (i % 16 == 0) {
12780 vty_out(vty, "\n ");
12781 } else if (i % 4 == 0) {
12782 vty_out(vty, " ");
12783 }
12784 }
12785 }
12786 vty_out(vty, "\n");
12787 }
12788 }
12789 }
12790
12791 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12792 if (use_json)
12793 json_object_boolean_true_add(json_neigh,
12794 "prefixesConfigExceedMax");
12795 else
12796 vty_out(vty,
12797 " Peer had exceeded the max. no. of prefixes configured.\n");
12798
12799 if (p->t_pmax_restart) {
12800 if (use_json) {
12801 json_object_boolean_true_add(
12802 json_neigh, "reducePrefixNumFrom");
12803 json_object_int_add(json_neigh,
12804 "restartInTimerMsec",
12805 thread_timer_remain_second(
12806 p->t_pmax_restart)
12807 * 1000);
12808 } else
12809 vty_out(vty,
12810 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
12811 p->host, thread_timer_remain_second(
12812 p->t_pmax_restart));
d62a17ae 12813 } else {
12814 if (use_json)
12815 json_object_boolean_true_add(
12816 json_neigh,
12817 "reducePrefixNumAndClearIpBgp");
12818 else
12819 vty_out(vty,
12820 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12821 p->host);
12822 }
12823 }
12824
12825 /* EBGP Multihop and GTSM */
12826 if (p->sort != BGP_PEER_IBGP) {
12827 if (use_json) {
e2521429 12828 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12829 json_object_int_add(json_neigh,
12830 "externalBgpNbrMaxHopsAway",
12831 p->gtsm_hops);
c8d6f0d6 12832 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12833 json_object_int_add(json_neigh,
12834 "externalBgpNbrMaxHopsAway",
12835 p->ttl);
12836 } else {
e2521429 12837 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12838 vty_out(vty,
12839 " External BGP neighbor may be up to %d hops away.\n",
12840 p->gtsm_hops);
c8d6f0d6 12841 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12842 vty_out(vty,
12843 " External BGP neighbor may be up to %d hops away.\n",
12844 p->ttl);
12845 }
12846 } else {
e2521429 12847 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12848 if (use_json)
12849 json_object_int_add(json_neigh,
12850 "internalBgpNbrMaxHopsAway",
12851 p->gtsm_hops);
12852 else
12853 vty_out(vty,
12854 " Internal BGP neighbor may be up to %d hops away.\n",
12855 p->gtsm_hops);
12856 }
12857 }
12858
12859 /* Local address. */
12860 if (p->su_local) {
12861 if (use_json) {
12862 json_object_string_add(json_neigh, "hostLocal",
12863 sockunion2str(p->su_local, buf1,
12864 SU_ADDRSTRLEN));
12865 json_object_int_add(json_neigh, "portLocal",
12866 ntohs(p->su_local->sin.sin_port));
12867 } else
12868 vty_out(vty, "Local host: %s, Local port: %d\n",
12869 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12870 ntohs(p->su_local->sin.sin_port));
12871 }
12872
12873 /* Remote address. */
12874 if (p->su_remote) {
12875 if (use_json) {
12876 json_object_string_add(json_neigh, "hostForeign",
12877 sockunion2str(p->su_remote, buf1,
12878 SU_ADDRSTRLEN));
12879 json_object_int_add(json_neigh, "portForeign",
12880 ntohs(p->su_remote->sin.sin_port));
12881 } else
12882 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12883 sockunion2str(p->su_remote, buf1,
12884 SU_ADDRSTRLEN),
12885 ntohs(p->su_remote->sin.sin_port));
12886 }
12887
12888 /* Nexthop display. */
12889 if (p->su_local) {
12890 if (use_json) {
12891 json_object_string_add(json_neigh, "nexthop",
12892 inet_ntop(AF_INET,
12893 &p->nexthop.v4, buf1,
12894 sizeof(buf1)));
12895 json_object_string_add(json_neigh, "nexthopGlobal",
12896 inet_ntop(AF_INET6,
12897 &p->nexthop.v6_global,
12898 buf1, sizeof(buf1)));
12899 json_object_string_add(json_neigh, "nexthopLocal",
12900 inet_ntop(AF_INET6,
12901 &p->nexthop.v6_local,
12902 buf1, sizeof(buf1)));
12903 if (p->shared_network)
12904 json_object_string_add(json_neigh,
12905 "bgpConnection",
12906 "sharedNetwork");
12907 else
12908 json_object_string_add(json_neigh,
12909 "bgpConnection",
12910 "nonSharedNetwork");
12911 } else {
12912 vty_out(vty, "Nexthop: %s\n",
12913 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12914 sizeof(buf1)));
12915 vty_out(vty, "Nexthop global: %s\n",
12916 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12917 sizeof(buf1)));
12918 vty_out(vty, "Nexthop local: %s\n",
12919 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12920 sizeof(buf1)));
12921 vty_out(vty, "BGP connection: %s\n",
12922 p->shared_network ? "shared network"
12923 : "non shared network");
12924 }
12925 }
12926
12927 /* Timer information. */
12928 if (use_json) {
12929 json_object_int_add(json_neigh, "connectRetryTimer",
12930 p->v_connect);
12931 if (p->status == Established && p->rtt)
12932 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12933 p->rtt);
12934 if (p->t_start)
12935 json_object_int_add(
12936 json_neigh, "nextStartTimerDueInMsecs",
12937 thread_timer_remain_second(p->t_start) * 1000);
12938 if (p->t_connect)
12939 json_object_int_add(
12940 json_neigh, "nextConnectTimerDueInMsecs",
12941 thread_timer_remain_second(p->t_connect)
12942 * 1000);
12943 if (p->t_routeadv) {
12944 json_object_int_add(json_neigh, "mraiInterval",
12945 p->v_routeadv);
12946 json_object_int_add(
12947 json_neigh, "mraiTimerExpireInMsecs",
12948 thread_timer_remain_second(p->t_routeadv)
12949 * 1000);
12950 }
12951 if (p->password)
12952 json_object_int_add(json_neigh, "authenticationEnabled",
12953 1);
12954
12955 if (p->t_read)
12956 json_object_string_add(json_neigh, "readThread", "on");
12957 else
12958 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12959
12960 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12961 json_object_string_add(json_neigh, "writeThread", "on");
12962 else
12963 json_object_string_add(json_neigh, "writeThread",
12964 "off");
12965 } else {
12966 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12967 p->v_connect);
12968 if (p->status == Established && p->rtt)
12969 vty_out(vty, "Estimated round trip time: %d ms\n",
12970 p->rtt);
12971 if (p->t_start)
12972 vty_out(vty, "Next start timer due in %ld seconds\n",
12973 thread_timer_remain_second(p->t_start));
12974 if (p->t_connect)
12975 vty_out(vty, "Next connect timer due in %ld seconds\n",
12976 thread_timer_remain_second(p->t_connect));
12977 if (p->t_routeadv)
12978 vty_out(vty,
12979 "MRAI (interval %u) timer expires in %ld seconds\n",
12980 p->v_routeadv,
12981 thread_timer_remain_second(p->t_routeadv));
12982 if (p->password)
12983 vty_out(vty, "Peer Authentication Enabled\n");
12984
cac9e917 12985 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12986 p->t_read ? "on" : "off",
12987 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12988 ? "on"
cac9e917 12989 : "off", p->fd);
d62a17ae 12990 }
12991
12992 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12993 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12994 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12995
12996 if (!use_json)
12997 vty_out(vty, "\n");
12998
12999 /* BFD information. */
13000 bgp_bfd_show_info(vty, p, use_json, json_neigh);
13001
13002 if (use_json) {
13003 if (p->conf_if) /* Configured interface name. */
13004 json_object_object_add(json, p->conf_if, json_neigh);
13005 else /* Configured IP address. */
13006 json_object_object_add(json, p->host, json_neigh);
13007 }
13008}
13009
36235319
QY
13010static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13011 enum show_type type,
13012 union sockunion *su,
13013 const char *conf_if, afi_t afi,
74a630b6 13014 bool use_json)
2986cac2 13015{
13016 struct listnode *node, *nnode;
13017 struct peer *peer;
13018 int find = 0;
13019 safi_t safi = SAFI_UNICAST;
74a630b6 13020 json_object *json = NULL;
2986cac2 13021 json_object *json_neighbor = NULL;
13022
74a630b6
NT
13023 if (use_json) {
13024 json = json_object_new_object();
13025 json_neighbor = json_object_new_object();
13026 }
13027
2986cac2 13028 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13029
13030 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13031 continue;
13032
13033 if ((peer->afc[afi][safi]) == 0)
13034 continue;
13035
2ba1fe69 13036 if (type == show_all) {
2986cac2 13037 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13038 json_neighbor);
2986cac2 13039
74a630b6 13040 if (use_json) {
13909c4f
DS
13041 json_object_object_add(json, peer->host,
13042 json_neighbor);
74a630b6
NT
13043 json_neighbor = NULL;
13044 }
2986cac2 13045
2ba1fe69 13046 } else if (type == show_peer) {
2986cac2 13047 if (conf_if) {
13048 if ((peer->conf_if
13909c4f
DS
13049 && !strcmp(peer->conf_if, conf_if))
13050 || (peer->hostname
2986cac2 13051 && !strcmp(peer->hostname, conf_if))) {
13052 find = 1;
13909c4f
DS
13053 bgp_show_peer_gr_status(vty, peer,
13054 use_json,
13055 json_neighbor);
2986cac2 13056 }
13057 } else {
13058 if (sockunion_same(&peer->su, su)) {
13059 find = 1;
13909c4f
DS
13060 bgp_show_peer_gr_status(vty, peer,
13061 use_json,
13062 json_neighbor);
2986cac2 13063 }
13064 }
13909c4f
DS
13065 if (use_json && find)
13066 json_object_object_add(json, peer->host,
13067 json_neighbor);
2986cac2 13068 }
13069
74a630b6
NT
13070 if (find) {
13071 json_neighbor = NULL;
2986cac2 13072 break;
74a630b6 13073 }
2986cac2 13074 }
13075
13076 if (type == show_peer && !find) {
13077 if (use_json)
13909c4f 13078 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 13079 else
13080 vty_out(vty, "%% No such neighbor\n");
13081 }
13082 if (use_json) {
13909c4f
DS
13083 vty_out(vty, "%s\n",
13084 json_object_to_json_string_ext(
13085 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
13086
13087 if (json_neighbor)
13088 json_object_free(json_neighbor);
13089 json_object_free(json);
2986cac2 13090 } else {
13091 vty_out(vty, "\n");
13092 }
13093
13094 return CMD_SUCCESS;
13095}
13096
d62a17ae 13097static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13098 enum show_type type, union sockunion *su,
9f049418 13099 const char *conf_if, bool use_json,
d62a17ae 13100 json_object *json)
13101{
13102 struct listnode *node, *nnode;
13103 struct peer *peer;
13104 int find = 0;
9f049418 13105 bool nbr_output = false;
d1927ebe
AS
13106 afi_t afi = AFI_MAX;
13107 safi_t safi = SAFI_MAX;
13108
13109 if (type == show_ipv4_peer || type == show_ipv4_all) {
13110 afi = AFI_IP;
13111 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13112 afi = AFI_IP6;
13113 }
d62a17ae 13114
13115 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13116 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13117 continue;
13118
13119 switch (type) {
13120 case show_all:
13121 bgp_show_peer(vty, peer, use_json, json);
9f049418 13122 nbr_output = true;
d62a17ae 13123 break;
13124 case show_peer:
13125 if (conf_if) {
13126 if ((peer->conf_if
13127 && !strcmp(peer->conf_if, conf_if))
13128 || (peer->hostname
13129 && !strcmp(peer->hostname, conf_if))) {
13130 find = 1;
13131 bgp_show_peer(vty, peer, use_json,
13132 json);
13133 }
13134 } else {
13135 if (sockunion_same(&peer->su, su)) {
13136 find = 1;
13137 bgp_show_peer(vty, peer, use_json,
13138 json);
13139 }
13140 }
13141 break;
d1927ebe
AS
13142 case show_ipv4_peer:
13143 case show_ipv6_peer:
13144 FOREACH_SAFI (safi) {
13145 if (peer->afc[afi][safi]) {
13146 if (conf_if) {
13147 if ((peer->conf_if
13148 && !strcmp(peer->conf_if, conf_if))
13149 || (peer->hostname
13150 && !strcmp(peer->hostname, conf_if))) {
13151 find = 1;
13152 bgp_show_peer(vty, peer, use_json,
13153 json);
13154 break;
13155 }
13156 } else {
13157 if (sockunion_same(&peer->su, su)) {
13158 find = 1;
13159 bgp_show_peer(vty, peer, use_json,
13160 json);
13161 break;
13162 }
13163 }
13164 }
13165 }
13166 break;
13167 case show_ipv4_all:
13168 case show_ipv6_all:
13169 FOREACH_SAFI (safi) {
13170 if (peer->afc[afi][safi]) {
13171 bgp_show_peer(vty, peer, use_json, json);
13172 nbr_output = true;
13173 break;
13174 }
13175 }
13176 break;
d62a17ae 13177 }
13178 }
13179
d1927ebe
AS
13180 if ((type == show_peer || type == show_ipv4_peer ||
13181 type == show_ipv6_peer) && !find) {
d62a17ae 13182 if (use_json)
13183 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13184 else
88b7d255 13185 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 13186 }
13187
d1927ebe
AS
13188 if (type != show_peer && type != show_ipv4_peer &&
13189 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 13190 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 13191
d62a17ae 13192 if (use_json) {
996c9314
LB
13193 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13194 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 13195 } else {
13196 vty_out(vty, "\n");
13197 }
13198
13199 return CMD_SUCCESS;
13200}
13201
36235319
QY
13202static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13203 enum show_type type,
13204 const char *ip_str,
13205 afi_t afi, bool use_json)
2986cac2 13206{
13207
13208 int ret;
13209 struct bgp *bgp;
13210 union sockunion su;
2986cac2 13211
13212 bgp = bgp_get_default();
13213
13909c4f
DS
13214 if (!bgp)
13215 return;
2986cac2 13216
13909c4f
DS
13217 if (!use_json)
13218 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13219 NULL);
2986cac2 13220
13909c4f
DS
13221 if (ip_str) {
13222 ret = str2sockunion(ip_str, &su);
13223 if (ret < 0)
13909c4f 13224 bgp_show_neighbor_graceful_restart(
74a630b6
NT
13225 vty, bgp, type, NULL, ip_str, afi, use_json);
13226 else
13227 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
13228 NULL, afi, use_json);
13909c4f
DS
13229 } else
13230 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 13231 afi, use_json);
2986cac2 13232}
13233
d62a17ae 13234static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
13235 enum show_type type,
13236 const char *ip_str,
9f049418 13237 bool use_json)
d62a17ae 13238{
0291c246
MK
13239 struct listnode *node, *nnode;
13240 struct bgp *bgp;
71aedaa3 13241 union sockunion su;
0291c246 13242 json_object *json = NULL;
71aedaa3 13243 int ret, is_first = 1;
9f049418 13244 bool nbr_output = false;
d62a17ae 13245
13246 if (use_json)
13247 vty_out(vty, "{\n");
13248
13249 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 13250 nbr_output = true;
d62a17ae 13251 if (use_json) {
13252 if (!(json = json_object_new_object())) {
af4c2728 13253 flog_err(
e50f7cfd 13254 EC_BGP_JSON_MEM_ERROR,
d62a17ae 13255 "Unable to allocate memory for JSON object");
13256 vty_out(vty,
13257 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
13258 return;
13259 }
13260
13261 json_object_int_add(json, "vrfId",
13262 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
13263 ? -1
13264 : (int64_t)bgp->vrf_id);
d62a17ae 13265 json_object_string_add(
13266 json, "vrfName",
13267 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13268 ? VRF_DEFAULT_NAME
d62a17ae 13269 : bgp->name);
13270
13271 if (!is_first)
13272 vty_out(vty, ",\n");
13273 else
13274 is_first = 0;
13275
13276 vty_out(vty, "\"%s\":",
13277 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13278 ? VRF_DEFAULT_NAME
d62a17ae 13279 : bgp->name);
13280 } else {
13281 vty_out(vty, "\nInstance %s:\n",
13282 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13283 ? VRF_DEFAULT_NAME
d62a17ae 13284 : bgp->name);
13285 }
71aedaa3 13286
d1927ebe
AS
13287 if (type == show_peer || type == show_ipv4_peer ||
13288 type == show_ipv6_peer) {
71aedaa3
DS
13289 ret = str2sockunion(ip_str, &su);
13290 if (ret < 0)
13291 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13292 use_json, json);
13293 else
13294 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13295 use_json, json);
13296 } else {
d1927ebe 13297 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
13298 use_json, json);
13299 }
b77004d6 13300 json_object_free(json);
121067e9 13301 json = NULL;
d62a17ae 13302 }
13303
3e78a6ce 13304 if (use_json)
d62a17ae 13305 vty_out(vty, "}\n");
9f049418
DS
13306 else if (!nbr_output)
13307 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13308}
13309
13310static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
13311 enum show_type type, const char *ip_str,
9f049418 13312 bool use_json)
d62a17ae 13313{
13314 int ret;
13315 struct bgp *bgp;
13316 union sockunion su;
13317 json_object *json = NULL;
13318
13319 if (name) {
13320 if (strmatch(name, "all")) {
71aedaa3
DS
13321 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
13322 use_json);
d62a17ae 13323 return CMD_SUCCESS;
13324 } else {
13325 bgp = bgp_lookup_by_name(name);
13326 if (!bgp) {
13327 if (use_json) {
13328 json = json_object_new_object();
d62a17ae 13329 vty_out(vty, "%s\n",
13330 json_object_to_json_string_ext(
13331 json,
13332 JSON_C_TO_STRING_PRETTY));
13333 json_object_free(json);
13334 } else
13335 vty_out(vty,
9f049418 13336 "%% BGP instance not found\n");
d62a17ae 13337
13338 return CMD_WARNING;
13339 }
13340 }
13341 } else {
13342 bgp = bgp_get_default();
13343 }
13344
13345 if (bgp) {
13346 json = json_object_new_object();
13347 if (ip_str) {
13348 ret = str2sockunion(ip_str, &su);
13349 if (ret < 0)
13350 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13351 use_json, json);
13352 else
13353 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13354 use_json, json);
13355 } else {
13356 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
13357 json);
13358 }
13359 json_object_free(json);
ca61fd25
DS
13360 } else {
13361 if (use_json)
13362 vty_out(vty, "{}\n");
13363 else
13364 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13365 }
13366
13367 return CMD_SUCCESS;
4fb25c53
DW
13368}
13369
2986cac2 13370
13371
13372/* "show [ip] bgp neighbors graceful-restart" commands. */
13373DEFUN (show_ip_bgp_neighbors_gracrful_restart,
13374 show_ip_bgp_neighbors_graceful_restart_cmd,
13375 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
13376 SHOW_STR
13377 BGP_STR
13378 IP_STR
13379 IPV6_STR
13380 NEIGHBOR_STR
13381 "Neighbor to display information about\n"
13382 "Neighbor to display information about\n"
13383 "Neighbor on BGP configured interface\n"
13384 GR_SHOW
13385 JSON_STR)
13386{
13387 char *sh_arg = NULL;
13388 enum show_type sh_type;
13389 int idx = 0;
13390 afi_t afi = AFI_MAX;
2986cac2 13391 bool uj = use_json(argc, argv);
13392
36235319 13393 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 13394 afi = AFI_MAX;
13395
13396 idx++;
13397
13398 if (argv_find(argv, argc, "A.B.C.D", &idx)
13399 || argv_find(argv, argc, "X:X::X:X", &idx)
13400 || argv_find(argv, argc, "WORD", &idx)) {
13401 sh_type = show_peer;
13402 sh_arg = argv[idx]->arg;
13403 } else
13404 sh_type = show_all;
13405
13406 if (!argv_find(argv, argc, "graceful-restart", &idx))
13407 return CMD_SUCCESS;
13408
13409
36235319
QY
13410 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
13411 afi, uj);
2986cac2 13412}
13413
716b2d8a 13414/* "show [ip] bgp neighbors" commands. */
718e3744 13415DEFUN (show_ip_bgp_neighbors,
13416 show_ip_bgp_neighbors_cmd,
24345e82 13417 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 13418 SHOW_STR
13419 IP_STR
13420 BGP_STR
f2a8972b 13421 BGP_INSTANCE_HELP_STR
8c3deaae
QY
13422 "Address Family\n"
13423 "Address Family\n"
718e3744 13424 "Detailed information on TCP and BGP neighbor connections\n"
13425 "Neighbor to display information about\n"
a80beece 13426 "Neighbor to display information about\n"
91d37724 13427 "Neighbor on BGP configured interface\n"
9973d184 13428 JSON_STR)
718e3744 13429{
d62a17ae 13430 char *vrf = NULL;
13431 char *sh_arg = NULL;
13432 enum show_type sh_type;
d1927ebe 13433 afi_t afi = AFI_MAX;
718e3744 13434
9f049418 13435 bool uj = use_json(argc, argv);
718e3744 13436
d62a17ae 13437 int idx = 0;
718e3744 13438
9a8bdf1c
PG
13439 /* [<vrf> VIEWVRFNAME] */
13440 if (argv_find(argv, argc, "vrf", &idx)) {
13441 vrf = argv[idx + 1]->arg;
13442 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13443 vrf = NULL;
13444 } else if (argv_find(argv, argc, "view", &idx))
13445 /* [<view> VIEWVRFNAME] */
d62a17ae 13446 vrf = argv[idx + 1]->arg;
718e3744 13447
d62a17ae 13448 idx++;
d1927ebe
AS
13449
13450 if (argv_find(argv, argc, "ipv4", &idx)) {
13451 sh_type = show_ipv4_all;
13452 afi = AFI_IP;
13453 } else if (argv_find(argv, argc, "ipv6", &idx)) {
13454 sh_type = show_ipv6_all;
13455 afi = AFI_IP6;
13456 } else {
13457 sh_type = show_all;
13458 }
13459
d62a17ae 13460 if (argv_find(argv, argc, "A.B.C.D", &idx)
13461 || argv_find(argv, argc, "X:X::X:X", &idx)
13462 || argv_find(argv, argc, "WORD", &idx)) {
13463 sh_type = show_peer;
13464 sh_arg = argv[idx]->arg;
d1927ebe
AS
13465 }
13466
13467 if (sh_type == show_peer && afi == AFI_IP) {
13468 sh_type = show_ipv4_peer;
13469 } else if (sh_type == show_peer && afi == AFI_IP6) {
13470 sh_type = show_ipv6_peer;
13471 }
856ca177 13472
d62a17ae 13473 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 13474}
13475
716b2d8a 13476/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 13477 paths' and `show ip mbgp paths'. Those functions results are the
13478 same.*/
f412b39a 13479DEFUN (show_ip_bgp_paths,
718e3744 13480 show_ip_bgp_paths_cmd,
46f296b4 13481 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 13482 SHOW_STR
13483 IP_STR
13484 BGP_STR
46f296b4 13485 BGP_SAFI_HELP_STR
718e3744 13486 "Path information\n")
13487{
d62a17ae 13488 vty_out(vty, "Address Refcnt Path\n");
13489 aspath_print_all_vty(vty);
13490 return CMD_SUCCESS;
718e3744 13491}
13492
718e3744 13493#include "hash.h"
13494
e3b78da8 13495static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13496 struct vty *vty)
718e3744 13497{
d62a17ae 13498 struct community *com;
718e3744 13499
e3b78da8 13500 com = (struct community *)bucket->data;
3f65c5b1 13501 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 13502 community_str(com, false));
718e3744 13503}
13504
13505/* Show BGP's community internal data. */
f412b39a 13506DEFUN (show_ip_bgp_community_info,
718e3744 13507 show_ip_bgp_community_info_cmd,
bec37ba5 13508 "show [ip] bgp community-info",
718e3744 13509 SHOW_STR
13510 IP_STR
13511 BGP_STR
13512 "List all bgp community information\n")
13513{
d62a17ae 13514 vty_out(vty, "Address Refcnt Community\n");
718e3744 13515
d62a17ae 13516 hash_iterate(community_hash(),
e3b78da8 13517 (void (*)(struct hash_bucket *,
d62a17ae 13518 void *))community_show_all_iterator,
13519 vty);
718e3744 13520
d62a17ae 13521 return CMD_SUCCESS;
718e3744 13522}
13523
e3b78da8 13524static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13525 struct vty *vty)
57d187bc 13526{
d62a17ae 13527 struct lcommunity *lcom;
57d187bc 13528
e3b78da8 13529 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 13530 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 13531 lcommunity_str(lcom, false));
57d187bc
JS
13532}
13533
13534/* Show BGP's community internal data. */
13535DEFUN (show_ip_bgp_lcommunity_info,
13536 show_ip_bgp_lcommunity_info_cmd,
13537 "show ip bgp large-community-info",
13538 SHOW_STR
13539 IP_STR
13540 BGP_STR
13541 "List all bgp large-community information\n")
13542{
d62a17ae 13543 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 13544
d62a17ae 13545 hash_iterate(lcommunity_hash(),
e3b78da8 13546 (void (*)(struct hash_bucket *,
d62a17ae 13547 void *))lcommunity_show_all_iterator,
13548 vty);
57d187bc 13549
d62a17ae 13550 return CMD_SUCCESS;
57d187bc 13551}
2986cac2 13552/* Graceful Restart */
13553
13554static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13555 struct bgp *bgp,
13556 bool use_json,
13557 json_object *json)
2986cac2 13558{
57d187bc
JS
13559
13560
2986cac2 13561 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13562
7318ae88 13563 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13564
13565 switch (bgp_global_gr_mode) {
13566
13567 case GLOBAL_HELPER:
13909c4f 13568 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13569 break;
13570
13571 case GLOBAL_GR:
13909c4f 13572 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13573 break;
13574
13575 case GLOBAL_DISABLE:
13909c4f 13576 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13577 break;
13578
13579 case GLOBAL_INVALID:
2986cac2 13580 vty_out(vty,
2ba1fe69 13581 "Global BGP GR Mode Invalid\n");
2986cac2 13582 break;
13583 }
13584 vty_out(vty, "\n");
13585}
13586
36235319
QY
13587static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13588 enum show_type type,
13589 const char *ip_str,
13590 afi_t afi, bool use_json)
2986cac2 13591{
13592 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13593 afi = AFI_IP;
13594
13595 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13596
36235319
QY
13597 bgp_show_neighbor_graceful_restart_vty(
13598 vty, type, ip_str, afi, use_json);
2986cac2 13599 afi++;
13600 }
13601 } else if (afi != AFI_MAX) {
36235319
QY
13602 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13603 use_json);
2986cac2 13604 } else {
13605 return CMD_ERR_INCOMPLETE;
13606 }
13607
13608 return CMD_SUCCESS;
13609}
13610/* Graceful Restart */
13611
f412b39a 13612DEFUN (show_ip_bgp_attr_info,
718e3744 13613 show_ip_bgp_attr_info_cmd,
bec37ba5 13614 "show [ip] bgp attribute-info",
718e3744 13615 SHOW_STR
13616 IP_STR
13617 BGP_STR
13618 "List all bgp attribute information\n")
13619{
d62a17ae 13620 attr_show_all(vty);
13621 return CMD_SUCCESS;
718e3744 13622}
6b0655a2 13623
03915806
CS
13624static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13625 afi_t afi, safi_t safi,
13626 bool use_json, json_object *json)
53089bec 13627{
13628 struct bgp *bgp;
13629 struct listnode *node;
13630 char *vname;
13631 char buf1[INET6_ADDRSTRLEN];
13632 char *ecom_str;
13633 vpn_policy_direction_t dir;
13634
03915806 13635 if (json) {
b46dfd20
DS
13636 json_object *json_import_vrfs = NULL;
13637 json_object *json_export_vrfs = NULL;
13638
b46dfd20
DS
13639 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13640
53089bec 13641 if (!bgp) {
b46dfd20
DS
13642 vty_out(vty, "%s\n",
13643 json_object_to_json_string_ext(
13644 json,
13645 JSON_C_TO_STRING_PRETTY));
13646 json_object_free(json);
13647
53089bec 13648 return CMD_WARNING;
13649 }
b46dfd20 13650
94d4c685
DS
13651 /* Provide context for the block */
13652 json_object_string_add(json, "vrf", name ? name : "default");
13653 json_object_string_add(json, "afiSafi",
5cb5f4d0 13654 get_afi_safi_str(afi, safi, true));
94d4c685 13655
b46dfd20
DS
13656 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13657 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13658 json_object_string_add(json, "importFromVrfs", "none");
13659 json_object_string_add(json, "importRts", "none");
13660 } else {
6ce24e52
DS
13661 json_import_vrfs = json_object_new_array();
13662
b46dfd20
DS
13663 for (ALL_LIST_ELEMENTS_RO(
13664 bgp->vpn_policy[afi].import_vrf,
13665 node, vname))
13666 json_object_array_add(json_import_vrfs,
13667 json_object_new_string(vname));
13668
b20875ea
CS
13669 json_object_object_add(json, "importFromVrfs",
13670 json_import_vrfs);
b46dfd20 13671 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13672 if (bgp->vpn_policy[afi].rtlist[dir]) {
13673 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13674 bgp->vpn_policy[afi].rtlist[dir],
13675 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13676 json_object_string_add(json, "importRts",
13677 ecom_str);
13678 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13679 } else
13680 json_object_string_add(json, "importRts",
13681 "none");
b46dfd20
DS
13682 }
13683
13684 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13685 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13686 json_object_string_add(json, "exportToVrfs", "none");
13687 json_object_string_add(json, "routeDistinguisher",
13688 "none");
13689 json_object_string_add(json, "exportRts", "none");
13690 } else {
6ce24e52
DS
13691 json_export_vrfs = json_object_new_array();
13692
b46dfd20
DS
13693 for (ALL_LIST_ELEMENTS_RO(
13694 bgp->vpn_policy[afi].export_vrf,
13695 node, vname))
13696 json_object_array_add(json_export_vrfs,
13697 json_object_new_string(vname));
13698 json_object_object_add(json, "exportToVrfs",
13699 json_export_vrfs);
13700 json_object_string_add(json, "routeDistinguisher",
13701 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13702 buf1, RD_ADDRSTRLEN));
13703
13704 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13705 if (bgp->vpn_policy[afi].rtlist[dir]) {
13706 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13707 bgp->vpn_policy[afi].rtlist[dir],
13708 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13709 json_object_string_add(json, "exportRts",
13710 ecom_str);
13711 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13712 } else
13713 json_object_string_add(json, "exportRts",
13714 "none");
b46dfd20
DS
13715 }
13716
03915806
CS
13717 if (use_json) {
13718 vty_out(vty, "%s\n",
13719 json_object_to_json_string_ext(json,
b46dfd20 13720 JSON_C_TO_STRING_PRETTY));
03915806
CS
13721 json_object_free(json);
13722 }
53089bec 13723 } else {
b46dfd20
DS
13724 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13725
53089bec 13726 if (!bgp) {
b46dfd20 13727 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13728 return CMD_WARNING;
13729 }
53089bec 13730
b46dfd20
DS
13731 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13732 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13733 vty_out(vty,
13734 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13735 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13736 else {
13737 vty_out(vty,
13738 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 13739 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13740
13741 for (ALL_LIST_ELEMENTS_RO(
13742 bgp->vpn_policy[afi].import_vrf,
13743 node, vname))
13744 vty_out(vty, " %s\n", vname);
13745
13746 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13747 ecom_str = NULL;
13748 if (bgp->vpn_policy[afi].rtlist[dir]) {
13749 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13750 bgp->vpn_policy[afi].rtlist[dir],
13751 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 13752 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 13753
b20875ea
CS
13754 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13755 } else
13756 vty_out(vty, "Import RT(s):\n");
53089bec 13757 }
53089bec 13758
b46dfd20
DS
13759 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13760 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13761 vty_out(vty,
13762 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 13763 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13764 else {
13765 vty_out(vty,
04c9077f 13766 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 13767 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13768
13769 for (ALL_LIST_ELEMENTS_RO(
13770 bgp->vpn_policy[afi].export_vrf,
13771 node, vname))
13772 vty_out(vty, " %s\n", vname);
13773
13774 vty_out(vty, "RD: %s\n",
13775 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13776 buf1, RD_ADDRSTRLEN));
13777
13778 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13779 if (bgp->vpn_policy[afi].rtlist[dir]) {
13780 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13781 bgp->vpn_policy[afi].rtlist[dir],
13782 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13783 vty_out(vty, "Export RT: %s\n", ecom_str);
13784 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13785 } else
13786 vty_out(vty, "Import RT(s):\n");
53089bec 13787 }
53089bec 13788 }
13789
13790 return CMD_SUCCESS;
13791}
13792
03915806
CS
13793static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13794 safi_t safi, bool use_json)
13795{
13796 struct listnode *node, *nnode;
13797 struct bgp *bgp;
13798 char *vrf_name = NULL;
13799 json_object *json = NULL;
13800 json_object *json_vrf = NULL;
13801 json_object *json_vrfs = NULL;
13802
13803 if (use_json) {
13804 json = json_object_new_object();
13805 json_vrfs = json_object_new_object();
13806 }
13807
13808 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13809
13810 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13811 vrf_name = bgp->name;
13812
13813 if (use_json) {
13814 json_vrf = json_object_new_object();
13815 } else {
13816 vty_out(vty, "\nInstance %s:\n",
13817 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13818 ? VRF_DEFAULT_NAME : bgp->name);
13819 }
13820 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13821 if (use_json) {
13822 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13823 json_object_object_add(json_vrfs,
13824 VRF_DEFAULT_NAME, json_vrf);
13825 else
13826 json_object_object_add(json_vrfs, vrf_name,
13827 json_vrf);
13828 }
13829 }
13830
13831 if (use_json) {
13832 json_object_object_add(json, "vrfs", json_vrfs);
13833 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13834 JSON_C_TO_STRING_PRETTY));
13835 json_object_free(json);
13836 }
13837
13838 return CMD_SUCCESS;
13839}
13840
53089bec 13841/* "show [ip] bgp route-leak" command. */
13842DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13843 show_ip_bgp_route_leak_cmd,
13844 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13845 SHOW_STR
13846 IP_STR
13847 BGP_STR
13848 BGP_INSTANCE_HELP_STR
13849 BGP_AFI_HELP_STR
13850 BGP_SAFI_HELP_STR
13851 "Route leaking information\n"
13852 JSON_STR)
53089bec 13853{
13854 char *vrf = NULL;
13855 afi_t afi = AFI_MAX;
13856 safi_t safi = SAFI_MAX;
13857
9f049418 13858 bool uj = use_json(argc, argv);
53089bec 13859 int idx = 0;
03915806 13860 json_object *json = NULL;
53089bec 13861
13862 /* show [ip] bgp */
13863 if (argv_find(argv, argc, "ip", &idx)) {
13864 afi = AFI_IP;
13865 safi = SAFI_UNICAST;
13866 }
13867 /* [vrf VIEWVRFNAME] */
13868 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13869 vty_out(vty,
13870 "%% This command is not applicable to BGP views\n");
53089bec 13871 return CMD_WARNING;
13872 }
13873
9a8bdf1c
PG
13874 if (argv_find(argv, argc, "vrf", &idx)) {
13875 vrf = argv[idx + 1]->arg;
13876 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13877 vrf = NULL;
13878 }
53089bec 13879 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13880 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13881 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13882 }
13883
13884 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13885 vty_out(vty,
13886 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13887 return CMD_WARNING;
13888 }
13889
03915806
CS
13890 if (vrf && strmatch(vrf, "all"))
13891 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13892
13893 if (uj)
13894 json = json_object_new_object();
13895
13896 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13897}
13898
d62a17ae 13899static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13900 safi_t safi)
f186de26 13901{
d62a17ae 13902 struct listnode *node, *nnode;
13903 struct bgp *bgp;
f186de26 13904
d62a17ae 13905 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13906 vty_out(vty, "\nInstance %s:\n",
13907 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13908 ? VRF_DEFAULT_NAME
d62a17ae 13909 : bgp->name);
13910 update_group_show(bgp, afi, safi, vty, 0);
13911 }
f186de26 13912}
13913
d62a17ae 13914static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13915 int safi, uint64_t subgrp_id)
4fb25c53 13916{
d62a17ae 13917 struct bgp *bgp;
4fb25c53 13918
d62a17ae 13919 if (name) {
13920 if (strmatch(name, "all")) {
13921 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13922 return CMD_SUCCESS;
13923 } else {
13924 bgp = bgp_lookup_by_name(name);
13925 }
13926 } else {
13927 bgp = bgp_get_default();
13928 }
4fb25c53 13929
d62a17ae 13930 if (bgp)
13931 update_group_show(bgp, afi, safi, vty, subgrp_id);
13932 return CMD_SUCCESS;
4fb25c53
DW
13933}
13934
8fe8a7f6
DS
13935DEFUN (show_ip_bgp_updgrps,
13936 show_ip_bgp_updgrps_cmd,
c1a44e43 13937 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13938 SHOW_STR
13939 IP_STR
13940 BGP_STR
13941 BGP_INSTANCE_HELP_STR
c9e571b4 13942 BGP_AFI_HELP_STR
9bedbb1e 13943 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13944 "Detailed info about dynamic update groups\n"
13945 "Specific subgroup to display detailed info for\n")
8386ac43 13946{
d62a17ae 13947 char *vrf = NULL;
13948 afi_t afi = AFI_IP6;
13949 safi_t safi = SAFI_UNICAST;
13950 uint64_t subgrp_id = 0;
13951
13952 int idx = 0;
13953
13954 /* show [ip] bgp */
13955 if (argv_find(argv, argc, "ip", &idx))
13956 afi = AFI_IP;
9a8bdf1c
PG
13957 /* [<vrf> VIEWVRFNAME] */
13958 if (argv_find(argv, argc, "vrf", &idx)) {
13959 vrf = argv[idx + 1]->arg;
13960 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13961 vrf = NULL;
13962 } else if (argv_find(argv, argc, "view", &idx))
13963 /* [<view> VIEWVRFNAME] */
13964 vrf = argv[idx + 1]->arg;
d62a17ae 13965 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13966 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13967 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13968 }
5bf15956 13969
d62a17ae 13970 /* get subgroup id, if provided */
13971 idx = argc - 1;
13972 if (argv[idx]->type == VARIABLE_TKN)
13973 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13974
d62a17ae 13975 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13976}
13977
f186de26 13978DEFUN (show_bgp_instance_all_ipv6_updgrps,
13979 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13980 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13981 SHOW_STR
716b2d8a 13982 IP_STR
f186de26 13983 BGP_STR
13984 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13985 "Detailed info about dynamic update groups\n")
f186de26 13986{
d62a17ae 13987 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13988 return CMD_SUCCESS;
f186de26 13989}
13990
43d3f4fc
DS
13991DEFUN (show_bgp_l2vpn_evpn_updgrps,
13992 show_bgp_l2vpn_evpn_updgrps_cmd,
13993 "show [ip] bgp l2vpn evpn update-groups",
13994 SHOW_STR
13995 IP_STR
13996 BGP_STR
13997 "l2vpn address family\n"
13998 "evpn sub-address family\n"
13999 "Detailed info about dynamic update groups\n")
14000{
14001 char *vrf = NULL;
14002 uint64_t subgrp_id = 0;
14003
14004 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14005 return CMD_SUCCESS;
14006}
14007
5bf15956
DW
14008DEFUN (show_bgp_updgrps_stats,
14009 show_bgp_updgrps_stats_cmd,
716b2d8a 14010 "show [ip] bgp update-groups statistics",
3f9c7369 14011 SHOW_STR
716b2d8a 14012 IP_STR
3f9c7369 14013 BGP_STR
0c7b1b01 14014 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14015 "Statistics\n")
14016{
d62a17ae 14017 struct bgp *bgp;
3f9c7369 14018
d62a17ae 14019 bgp = bgp_get_default();
14020 if (bgp)
14021 update_group_show_stats(bgp, vty);
3f9c7369 14022
d62a17ae 14023 return CMD_SUCCESS;
3f9c7369
DS
14024}
14025
8386ac43 14026DEFUN (show_bgp_instance_updgrps_stats,
14027 show_bgp_instance_updgrps_stats_cmd,
18c57037 14028 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14029 SHOW_STR
716b2d8a 14030 IP_STR
8386ac43 14031 BGP_STR
14032 BGP_INSTANCE_HELP_STR
0c7b1b01 14033 "Detailed info about dynamic update groups\n"
8386ac43 14034 "Statistics\n")
14035{
d62a17ae 14036 int idx_word = 3;
14037 struct bgp *bgp;
8386ac43 14038
d62a17ae 14039 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14040 if (bgp)
14041 update_group_show_stats(bgp, vty);
8386ac43 14042
d62a17ae 14043 return CMD_SUCCESS;
8386ac43 14044}
14045
d62a17ae 14046static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14047 afi_t afi, safi_t safi,
14048 const char *what, uint64_t subgrp_id)
3f9c7369 14049{
d62a17ae 14050 struct bgp *bgp;
8386ac43 14051
d62a17ae 14052 if (name)
14053 bgp = bgp_lookup_by_name(name);
14054 else
14055 bgp = bgp_get_default();
8386ac43 14056
d62a17ae 14057 if (bgp) {
14058 if (!strcmp(what, "advertise-queue"))
14059 update_group_show_adj_queue(bgp, afi, safi, vty,
14060 subgrp_id);
14061 else if (!strcmp(what, "advertised-routes"))
14062 update_group_show_advertised(bgp, afi, safi, vty,
14063 subgrp_id);
14064 else if (!strcmp(what, "packet-queue"))
14065 update_group_show_packet_queue(bgp, afi, safi, vty,
14066 subgrp_id);
14067 }
3f9c7369
DS
14068}
14069
dc64bdec
QY
14070DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14071 show_ip_bgp_instance_updgrps_adj_s_cmd,
14072 "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",
14073 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14074 BGP_SAFI_HELP_STR
14075 "Detailed info about dynamic update groups\n"
14076 "Specific subgroup to display info for\n"
14077 "Advertisement queue\n"
14078 "Announced routes\n"
14079 "Packet queue\n")
3f9c7369 14080{
dc64bdec
QY
14081 uint64_t subgrp_id = 0;
14082 afi_t afiz;
14083 safi_t safiz;
14084 if (sgid)
14085 subgrp_id = strtoull(sgid, NULL, 10);
14086
14087 if (!ip && !afi)
14088 afiz = AFI_IP6;
14089 if (!ip && afi)
14090 afiz = bgp_vty_afi_from_str(afi);
14091 if (ip && !afi)
14092 afiz = AFI_IP;
14093 if (ip && afi) {
14094 afiz = bgp_vty_afi_from_str(afi);
14095 if (afiz != AFI_IP)
14096 vty_out(vty,
14097 "%% Cannot specify both 'ip' and 'ipv6'\n");
14098 return CMD_WARNING;
14099 }
d62a17ae 14100
dc64bdec 14101 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 14102
dc64bdec 14103 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 14104 return CMD_SUCCESS;
14105}
14106
d62a17ae 14107static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
14108{
14109 struct listnode *node, *nnode;
14110 struct prefix *range;
14111 struct peer *conf;
14112 struct peer *peer;
d62a17ae 14113 afi_t afi;
14114 safi_t safi;
14115 const char *peer_status;
14116 const char *af_str;
14117 int lr_count;
14118 int dynamic;
14119 int af_cfgd;
14120
14121 conf = group->conf;
14122
14123 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 14124 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14125 group->name, conf->as);
d62a17ae 14126 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 14127 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14128 group->name, group->bgp->as);
d62a17ae 14129 } else {
14130 vty_out(vty, "\nBGP peer-group %s\n", group->name);
14131 }
f14e6fdb 14132
d62a17ae 14133 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
14134 vty_out(vty, " Peer-group type is internal\n");
14135 else
14136 vty_out(vty, " Peer-group type is external\n");
14137
14138 /* Display AFs configured. */
14139 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
14140 FOREACH_AFI_SAFI (afi, safi) {
14141 if (conf->afc[afi][safi]) {
14142 af_cfgd = 1;
5cb5f4d0 14143 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 14144 }
05c7a1cc 14145 }
d62a17ae 14146 if (!af_cfgd)
14147 vty_out(vty, " none\n");
14148 else
14149 vty_out(vty, "\n");
14150
14151 /* Display listen ranges (for dynamic neighbors), if any */
14152 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
14153 if (afi == AFI_IP)
14154 af_str = "IPv4";
14155 else if (afi == AFI_IP6)
14156 af_str = "IPv6";
14157 else
14158 af_str = "???";
14159 lr_count = listcount(group->listen_range[afi]);
14160 if (lr_count) {
14161 vty_out(vty, " %d %s listen range(s)\n", lr_count,
14162 af_str);
14163
14164
14165 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
2dbe669b
DA
14166 nnode, range))
14167 vty_out(vty, " %pFX\n", range);
d62a17ae 14168 }
14169 }
f14e6fdb 14170
d62a17ae 14171 /* Display group members and their status */
14172 if (listcount(group->peer)) {
14173 vty_out(vty, " Peer-group members:\n");
14174 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
14175 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
14176 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 14177 peer_status = "Idle (Admin)";
14178 else if (CHECK_FLAG(peer->sflags,
14179 PEER_STATUS_PREFIX_OVERFLOW))
14180 peer_status = "Idle (PfxCt)";
14181 else
14182 peer_status = lookup_msg(bgp_status_msg,
14183 peer->status, NULL);
14184
14185 dynamic = peer_dynamic_neighbor(peer);
14186 vty_out(vty, " %s %s %s \n", peer->host,
14187 dynamic ? "(dynamic)" : "", peer_status);
14188 }
14189 }
f14e6fdb 14190
d62a17ae 14191 return CMD_SUCCESS;
14192}
14193
ff9959b0
QY
14194static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
14195 const char *group_name)
d62a17ae 14196{
ff9959b0 14197 struct bgp *bgp;
d62a17ae 14198 struct listnode *node, *nnode;
14199 struct peer_group *group;
ff9959b0
QY
14200 bool found = false;
14201
14202 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14203
14204 if (!bgp) {
9f049418 14205 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
14206 return CMD_WARNING;
14207 }
d62a17ae 14208
14209 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
14210 if (group_name) {
14211 if (strmatch(group->name, group_name)) {
d62a17ae 14212 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
14213 found = true;
14214 break;
d62a17ae 14215 }
ff9959b0
QY
14216 } else {
14217 bgp_show_one_peer_group(vty, group);
d62a17ae 14218 }
f14e6fdb 14219 }
f14e6fdb 14220
ff9959b0 14221 if (group_name && !found)
d62a17ae 14222 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 14223
d62a17ae 14224 return CMD_SUCCESS;
f14e6fdb
DS
14225}
14226
f14e6fdb
DS
14227DEFUN (show_ip_bgp_peer_groups,
14228 show_ip_bgp_peer_groups_cmd,
18c57037 14229 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
14230 SHOW_STR
14231 IP_STR
14232 BGP_STR
8386ac43 14233 BGP_INSTANCE_HELP_STR
d6e3c605
QY
14234 "Detailed information on BGP peer groups\n"
14235 "Peer group name\n")
f14e6fdb 14236{
d62a17ae 14237 char *vrf, *pg;
d62a17ae 14238 int idx = 0;
f14e6fdb 14239
a4d82a8a
PZ
14240 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
14241 : NULL;
d62a17ae 14242 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 14243
ff9959b0 14244 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 14245}
3f9c7369 14246
d6e3c605 14247
718e3744 14248/* Redistribute VTY commands. */
14249
718e3744 14250DEFUN (bgp_redistribute_ipv4,
14251 bgp_redistribute_ipv4_cmd,
40d1cbfb 14252 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 14253 "Redistribute information from another routing protocol\n"
ab0181ee 14254 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 14255{
d62a17ae 14256 VTY_DECLVAR_CONTEXT(bgp, bgp);
14257 int idx_protocol = 1;
14258 int type;
718e3744 14259
d62a17ae 14260 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14261 if (type < 0) {
14262 vty_out(vty, "%% Invalid route type\n");
14263 return CMD_WARNING_CONFIG_FAILED;
14264 }
7f323236 14265
d62a17ae 14266 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14267 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 14268}
14269
d62a17ae 14270ALIAS_HIDDEN(
14271 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
14272 "redistribute " FRR_IP_REDIST_STR_BGPD,
14273 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 14274
718e3744 14275DEFUN (bgp_redistribute_ipv4_rmap,
14276 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 14277 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 14278 "Redistribute information from another routing protocol\n"
ab0181ee 14279 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14280 "Route map reference\n"
14281 "Pointer to route-map entries\n")
14282{
d62a17ae 14283 VTY_DECLVAR_CONTEXT(bgp, bgp);
14284 int idx_protocol = 1;
14285 int idx_word = 3;
14286 int type;
14287 struct bgp_redist *red;
e923dd62 14288 bool changed;
1de27621
DA
14289 struct route_map *route_map = route_map_lookup_warn_noexist(
14290 vty, argv[idx_word]->arg);
718e3744 14291
d62a17ae 14292 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14293 if (type < 0) {
14294 vty_out(vty, "%% Invalid route type\n");
14295 return CMD_WARNING_CONFIG_FAILED;
14296 }
718e3744 14297
d62a17ae 14298 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14299 changed =
14300 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14301 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 14302}
14303
d62a17ae 14304ALIAS_HIDDEN(
14305 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
14306 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14307 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14308 "Route map reference\n"
14309 "Pointer to route-map entries\n")
596c17ba 14310
718e3744 14311DEFUN (bgp_redistribute_ipv4_metric,
14312 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 14313 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14314 "Redistribute information from another routing protocol\n"
ab0181ee 14315 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14316 "Metric for redistributed routes\n"
14317 "Default metric\n")
14318{
d62a17ae 14319 VTY_DECLVAR_CONTEXT(bgp, bgp);
14320 int idx_protocol = 1;
14321 int idx_number = 3;
14322 int type;
d7c0a89a 14323 uint32_t metric;
d62a17ae 14324 struct bgp_redist *red;
e923dd62 14325 bool changed;
d62a17ae 14326
14327 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14328 if (type < 0) {
14329 vty_out(vty, "%% Invalid route type\n");
14330 return CMD_WARNING_CONFIG_FAILED;
14331 }
14332 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14333
14334 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14335 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14336 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14337}
14338
14339ALIAS_HIDDEN(
14340 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
14341 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14342 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14343 "Metric for redistributed routes\n"
14344 "Default metric\n")
596c17ba 14345
718e3744 14346DEFUN (bgp_redistribute_ipv4_rmap_metric,
14347 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 14348 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14349 "Redistribute information from another routing protocol\n"
ab0181ee 14350 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14351 "Route map reference\n"
14352 "Pointer to route-map entries\n"
14353 "Metric for redistributed routes\n"
14354 "Default metric\n")
14355{
d62a17ae 14356 VTY_DECLVAR_CONTEXT(bgp, bgp);
14357 int idx_protocol = 1;
14358 int idx_word = 3;
14359 int idx_number = 5;
14360 int type;
d7c0a89a 14361 uint32_t metric;
d62a17ae 14362 struct bgp_redist *red;
e923dd62 14363 bool changed;
1de27621
DA
14364 struct route_map *route_map =
14365 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14366
14367 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14368 if (type < 0) {
14369 vty_out(vty, "%% Invalid route type\n");
14370 return CMD_WARNING_CONFIG_FAILED;
14371 }
14372 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14373
14374 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14375 changed =
14376 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14377 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14378 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14379}
14380
14381ALIAS_HIDDEN(
14382 bgp_redistribute_ipv4_rmap_metric,
14383 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
14384 "redistribute " FRR_IP_REDIST_STR_BGPD
14385 " route-map WORD metric (0-4294967295)",
14386 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14387 "Route map reference\n"
14388 "Pointer to route-map entries\n"
14389 "Metric for redistributed routes\n"
14390 "Default metric\n")
596c17ba 14391
718e3744 14392DEFUN (bgp_redistribute_ipv4_metric_rmap,
14393 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 14394 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14395 "Redistribute information from another routing protocol\n"
ab0181ee 14396 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14397 "Metric for redistributed routes\n"
14398 "Default metric\n"
14399 "Route map reference\n"
14400 "Pointer to route-map entries\n")
14401{
d62a17ae 14402 VTY_DECLVAR_CONTEXT(bgp, bgp);
14403 int idx_protocol = 1;
14404 int idx_number = 3;
14405 int idx_word = 5;
14406 int type;
d7c0a89a 14407 uint32_t metric;
d62a17ae 14408 struct bgp_redist *red;
e923dd62 14409 bool changed;
1de27621
DA
14410 struct route_map *route_map =
14411 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14412
14413 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14414 if (type < 0) {
14415 vty_out(vty, "%% Invalid route type\n");
14416 return CMD_WARNING_CONFIG_FAILED;
14417 }
14418 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14419
14420 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14421 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
14422 changed |=
14423 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14424 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14425}
14426
14427ALIAS_HIDDEN(
14428 bgp_redistribute_ipv4_metric_rmap,
14429 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
14430 "redistribute " FRR_IP_REDIST_STR_BGPD
14431 " metric (0-4294967295) route-map WORD",
14432 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14433 "Metric for redistributed routes\n"
14434 "Default metric\n"
14435 "Route map reference\n"
14436 "Pointer to route-map entries\n")
596c17ba 14437
7c8ff89e
DS
14438DEFUN (bgp_redistribute_ipv4_ospf,
14439 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 14440 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
14441 "Redistribute information from another routing protocol\n"
14442 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14443 "Non-main Kernel Routing Table\n"
14444 "Instance ID/Table ID\n")
7c8ff89e 14445{
d62a17ae 14446 VTY_DECLVAR_CONTEXT(bgp, bgp);
14447 int idx_ospf_table = 1;
14448 int idx_number = 2;
d7c0a89a
QY
14449 unsigned short instance;
14450 unsigned short protocol;
7c8ff89e 14451
d62a17ae 14452 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 14453
d62a17ae 14454 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14455 protocol = ZEBRA_ROUTE_OSPF;
14456 else
14457 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 14458
d62a17ae 14459 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14460 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
14461}
14462
d62a17ae 14463ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
14464 "redistribute <ospf|table> (1-65535)",
14465 "Redistribute information from another routing protocol\n"
14466 "Open Shortest Path First (OSPFv2)\n"
14467 "Non-main Kernel Routing Table\n"
14468 "Instance ID/Table ID\n")
596c17ba 14469
7c8ff89e
DS
14470DEFUN (bgp_redistribute_ipv4_ospf_rmap,
14471 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 14472 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
14473 "Redistribute information from another routing protocol\n"
14474 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14475 "Non-main Kernel Routing Table\n"
14476 "Instance ID/Table ID\n"
7c8ff89e
DS
14477 "Route map reference\n"
14478 "Pointer to route-map entries\n")
14479{
d62a17ae 14480 VTY_DECLVAR_CONTEXT(bgp, bgp);
14481 int idx_ospf_table = 1;
14482 int idx_number = 2;
14483 int idx_word = 4;
14484 struct bgp_redist *red;
d7c0a89a 14485 unsigned short instance;
d62a17ae 14486 int protocol;
e923dd62 14487 bool changed;
1de27621
DA
14488 struct route_map *route_map =
14489 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14490
14491 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14492 protocol = ZEBRA_ROUTE_OSPF;
14493 else
14494 protocol = ZEBRA_ROUTE_TABLE;
14495
14496 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14497 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14498 changed =
14499 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14500 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14501}
14502
14503ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14504 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14505 "redistribute <ospf|table> (1-65535) route-map WORD",
14506 "Redistribute information from another routing protocol\n"
14507 "Open Shortest Path First (OSPFv2)\n"
14508 "Non-main Kernel Routing Table\n"
14509 "Instance ID/Table ID\n"
14510 "Route map reference\n"
14511 "Pointer to route-map entries\n")
596c17ba 14512
7c8ff89e
DS
14513DEFUN (bgp_redistribute_ipv4_ospf_metric,
14514 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 14515 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
14516 "Redistribute information from another routing protocol\n"
14517 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14518 "Non-main Kernel Routing Table\n"
14519 "Instance ID/Table ID\n"
7c8ff89e
DS
14520 "Metric for redistributed routes\n"
14521 "Default metric\n")
14522{
d62a17ae 14523 VTY_DECLVAR_CONTEXT(bgp, bgp);
14524 int idx_ospf_table = 1;
14525 int idx_number = 2;
14526 int idx_number_2 = 4;
d7c0a89a 14527 uint32_t metric;
d62a17ae 14528 struct bgp_redist *red;
d7c0a89a 14529 unsigned short instance;
d62a17ae 14530 int protocol;
e923dd62 14531 bool changed;
d62a17ae 14532
14533 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14534 protocol = ZEBRA_ROUTE_OSPF;
14535 else
14536 protocol = ZEBRA_ROUTE_TABLE;
14537
14538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14539 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14540
14541 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14542 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14543 metric);
14544 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14545}
14546
14547ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14548 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14549 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14550 "Redistribute information from another routing protocol\n"
14551 "Open Shortest Path First (OSPFv2)\n"
14552 "Non-main Kernel Routing Table\n"
14553 "Instance ID/Table ID\n"
14554 "Metric for redistributed routes\n"
14555 "Default metric\n")
596c17ba 14556
7c8ff89e
DS
14557DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14558 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 14559 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
14560 "Redistribute information from another routing protocol\n"
14561 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14562 "Non-main Kernel Routing Table\n"
14563 "Instance ID/Table ID\n"
7c8ff89e
DS
14564 "Route map reference\n"
14565 "Pointer to route-map entries\n"
14566 "Metric for redistributed routes\n"
14567 "Default metric\n")
14568{
d62a17ae 14569 VTY_DECLVAR_CONTEXT(bgp, bgp);
14570 int idx_ospf_table = 1;
14571 int idx_number = 2;
14572 int idx_word = 4;
14573 int idx_number_2 = 6;
d7c0a89a 14574 uint32_t metric;
d62a17ae 14575 struct bgp_redist *red;
d7c0a89a 14576 unsigned short instance;
d62a17ae 14577 int protocol;
e923dd62 14578 bool changed;
1de27621
DA
14579 struct route_map *route_map =
14580 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14581
14582 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14583 protocol = ZEBRA_ROUTE_OSPF;
14584 else
14585 protocol = ZEBRA_ROUTE_TABLE;
14586
14587 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14588 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14589
14590 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14591 changed =
14592 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14593 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14594 metric);
14595 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14596}
14597
14598ALIAS_HIDDEN(
14599 bgp_redistribute_ipv4_ospf_rmap_metric,
14600 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14601 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14602 "Redistribute information from another routing protocol\n"
14603 "Open Shortest Path First (OSPFv2)\n"
14604 "Non-main Kernel Routing Table\n"
14605 "Instance ID/Table ID\n"
14606 "Route map reference\n"
14607 "Pointer to route-map entries\n"
14608 "Metric for redistributed routes\n"
14609 "Default metric\n")
596c17ba 14610
7c8ff89e
DS
14611DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14612 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 14613 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
14614 "Redistribute information from another routing protocol\n"
14615 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14616 "Non-main Kernel Routing Table\n"
14617 "Instance ID/Table ID\n"
7c8ff89e
DS
14618 "Metric for redistributed routes\n"
14619 "Default metric\n"
14620 "Route map reference\n"
14621 "Pointer to route-map entries\n")
14622{
d62a17ae 14623 VTY_DECLVAR_CONTEXT(bgp, bgp);
14624 int idx_ospf_table = 1;
14625 int idx_number = 2;
14626 int idx_number_2 = 4;
14627 int idx_word = 6;
d7c0a89a 14628 uint32_t metric;
d62a17ae 14629 struct bgp_redist *red;
d7c0a89a 14630 unsigned short instance;
d62a17ae 14631 int protocol;
e923dd62 14632 bool changed;
1de27621
DA
14633 struct route_map *route_map =
14634 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14635
14636 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14637 protocol = ZEBRA_ROUTE_OSPF;
14638 else
14639 protocol = ZEBRA_ROUTE_TABLE;
14640
14641 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14642 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14643
14644 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14645 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14646 metric);
1de27621
DA
14647 changed |=
14648 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14649 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14650}
14651
14652ALIAS_HIDDEN(
14653 bgp_redistribute_ipv4_ospf_metric_rmap,
14654 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14655 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14656 "Redistribute information from another routing protocol\n"
14657 "Open Shortest Path First (OSPFv2)\n"
14658 "Non-main Kernel Routing Table\n"
14659 "Instance ID/Table ID\n"
14660 "Metric for redistributed routes\n"
14661 "Default metric\n"
14662 "Route map reference\n"
14663 "Pointer to route-map entries\n")
596c17ba 14664
7c8ff89e
DS
14665DEFUN (no_bgp_redistribute_ipv4_ospf,
14666 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 14667 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
14668 NO_STR
14669 "Redistribute information from another routing protocol\n"
14670 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 14671 "Non-main Kernel Routing Table\n"
31500417
DW
14672 "Instance ID/Table ID\n"
14673 "Metric for redistributed routes\n"
14674 "Default metric\n"
14675 "Route map reference\n"
14676 "Pointer to route-map entries\n")
7c8ff89e 14677{
d62a17ae 14678 VTY_DECLVAR_CONTEXT(bgp, bgp);
14679 int idx_ospf_table = 2;
14680 int idx_number = 3;
d7c0a89a 14681 unsigned short instance;
d62a17ae 14682 int protocol;
14683
14684 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14685 protocol = ZEBRA_ROUTE_OSPF;
14686 else
14687 protocol = ZEBRA_ROUTE_TABLE;
14688
14689 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14690 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14691}
14692
14693ALIAS_HIDDEN(
14694 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14695 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14696 NO_STR
14697 "Redistribute information from another routing protocol\n"
14698 "Open Shortest Path First (OSPFv2)\n"
14699 "Non-main Kernel Routing Table\n"
14700 "Instance ID/Table ID\n"
14701 "Metric for redistributed routes\n"
14702 "Default metric\n"
14703 "Route map reference\n"
14704 "Pointer to route-map entries\n")
596c17ba 14705
718e3744 14706DEFUN (no_bgp_redistribute_ipv4,
14707 no_bgp_redistribute_ipv4_cmd,
e27957c0 14708 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14709 NO_STR
14710 "Redistribute information from another routing protocol\n"
3b14d86e 14711 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
14712 "Metric for redistributed routes\n"
14713 "Default metric\n"
14714 "Route map reference\n"
14715 "Pointer to route-map entries\n")
718e3744 14716{
d62a17ae 14717 VTY_DECLVAR_CONTEXT(bgp, bgp);
14718 int idx_protocol = 2;
14719 int type;
14720
14721 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14722 if (type < 0) {
14723 vty_out(vty, "%% Invalid route type\n");
14724 return CMD_WARNING_CONFIG_FAILED;
14725 }
14726 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14727}
14728
14729ALIAS_HIDDEN(
14730 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14731 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14732 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14733 NO_STR
14734 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14735 "Metric for redistributed routes\n"
14736 "Default metric\n"
14737 "Route map reference\n"
14738 "Pointer to route-map entries\n")
596c17ba 14739
718e3744 14740DEFUN (bgp_redistribute_ipv6,
14741 bgp_redistribute_ipv6_cmd,
40d1cbfb 14742 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 14743 "Redistribute information from another routing protocol\n"
ab0181ee 14744 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14745{
d62a17ae 14746 VTY_DECLVAR_CONTEXT(bgp, bgp);
14747 int idx_protocol = 1;
14748 int type;
718e3744 14749
d62a17ae 14750 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14751 if (type < 0) {
14752 vty_out(vty, "%% Invalid route type\n");
14753 return CMD_WARNING_CONFIG_FAILED;
14754 }
718e3744 14755
d62a17ae 14756 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14757 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 14758}
14759
14760DEFUN (bgp_redistribute_ipv6_rmap,
14761 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 14762 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 14763 "Redistribute information from another routing protocol\n"
ab0181ee 14764 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14765 "Route map reference\n"
14766 "Pointer to route-map entries\n")
14767{
d62a17ae 14768 VTY_DECLVAR_CONTEXT(bgp, bgp);
14769 int idx_protocol = 1;
14770 int idx_word = 3;
14771 int type;
14772 struct bgp_redist *red;
e923dd62 14773 bool changed;
1de27621
DA
14774 struct route_map *route_map =
14775 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 14776
d62a17ae 14777 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14778 if (type < 0) {
14779 vty_out(vty, "%% Invalid route type\n");
14780 return CMD_WARNING_CONFIG_FAILED;
14781 }
718e3744 14782
d62a17ae 14783 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14784 changed =
14785 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14786 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14787}
14788
14789DEFUN (bgp_redistribute_ipv6_metric,
14790 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 14791 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14792 "Redistribute information from another routing protocol\n"
ab0181ee 14793 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14794 "Metric for redistributed routes\n"
14795 "Default metric\n")
14796{
d62a17ae 14797 VTY_DECLVAR_CONTEXT(bgp, bgp);
14798 int idx_protocol = 1;
14799 int idx_number = 3;
14800 int type;
d7c0a89a 14801 uint32_t metric;
d62a17ae 14802 struct bgp_redist *red;
e923dd62 14803 bool changed;
d62a17ae 14804
14805 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14806 if (type < 0) {
14807 vty_out(vty, "%% Invalid route type\n");
14808 return CMD_WARNING_CONFIG_FAILED;
14809 }
14810 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14811
d62a17ae 14812 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14813 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14814 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14815}
14816
14817DEFUN (bgp_redistribute_ipv6_rmap_metric,
14818 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14819 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14820 "Redistribute information from another routing protocol\n"
ab0181ee 14821 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14822 "Route map reference\n"
14823 "Pointer to route-map entries\n"
14824 "Metric for redistributed routes\n"
14825 "Default metric\n")
14826{
d62a17ae 14827 VTY_DECLVAR_CONTEXT(bgp, bgp);
14828 int idx_protocol = 1;
14829 int idx_word = 3;
14830 int idx_number = 5;
14831 int type;
d7c0a89a 14832 uint32_t metric;
d62a17ae 14833 struct bgp_redist *red;
e923dd62 14834 bool changed;
1de27621
DA
14835 struct route_map *route_map =
14836 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14837
14838 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14839 if (type < 0) {
14840 vty_out(vty, "%% Invalid route type\n");
14841 return CMD_WARNING_CONFIG_FAILED;
14842 }
14843 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14844
d62a17ae 14845 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14846 changed =
14847 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14848 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14849 metric);
14850 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14851}
14852
14853DEFUN (bgp_redistribute_ipv6_metric_rmap,
14854 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14855 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14856 "Redistribute information from another routing protocol\n"
ab0181ee 14857 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14858 "Metric for redistributed routes\n"
14859 "Default metric\n"
14860 "Route map reference\n"
14861 "Pointer to route-map entries\n")
14862{
d62a17ae 14863 VTY_DECLVAR_CONTEXT(bgp, bgp);
14864 int idx_protocol = 1;
14865 int idx_number = 3;
14866 int idx_word = 5;
14867 int type;
d7c0a89a 14868 uint32_t metric;
d62a17ae 14869 struct bgp_redist *red;
e923dd62 14870 bool changed;
1de27621
DA
14871 struct route_map *route_map =
14872 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14873
14874 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14875 if (type < 0) {
14876 vty_out(vty, "%% Invalid route type\n");
14877 return CMD_WARNING_CONFIG_FAILED;
14878 }
14879 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14880
d62a17ae 14881 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14882 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14883 metric);
1de27621
DA
14884 changed |=
14885 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14886 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14887}
14888
14889DEFUN (no_bgp_redistribute_ipv6,
14890 no_bgp_redistribute_ipv6_cmd,
e27957c0 14891 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14892 NO_STR
14893 "Redistribute information from another routing protocol\n"
3b14d86e 14894 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14895 "Metric for redistributed routes\n"
14896 "Default metric\n"
14897 "Route map reference\n"
14898 "Pointer to route-map entries\n")
718e3744 14899{
d62a17ae 14900 VTY_DECLVAR_CONTEXT(bgp, bgp);
14901 int idx_protocol = 2;
14902 int type;
718e3744 14903
d62a17ae 14904 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14905 if (type < 0) {
14906 vty_out(vty, "%% Invalid route type\n");
14907 return CMD_WARNING_CONFIG_FAILED;
14908 }
718e3744 14909
d62a17ae 14910 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14911}
14912
dd65f45e
DL
14913static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14914 afi_t afi, safi_t safi)
d62a17ae 14915{
14916 int i;
14917
14918 /* Unicast redistribution only. */
14919 if (safi != SAFI_UNICAST)
2b791107 14920 return;
d62a17ae 14921
14922 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14923 /* Redistribute BGP does not make sense. */
14924 if (i != ZEBRA_ROUTE_BGP) {
14925 struct list *red_list;
14926 struct listnode *node;
14927 struct bgp_redist *red;
14928
14929 red_list = bgp->redist[afi][i];
14930 if (!red_list)
14931 continue;
14932
14933 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14934 /* "redistribute" configuration. */
14935 vty_out(vty, " redistribute %s",
14936 zebra_route_string(i));
14937 if (red->instance)
14938 vty_out(vty, " %d", red->instance);
14939 if (red->redist_metric_flag)
14940 vty_out(vty, " metric %u",
14941 red->redist_metric);
14942 if (red->rmap.name)
14943 vty_out(vty, " route-map %s",
14944 red->rmap.name);
14945 vty_out(vty, "\n");
14946 }
14947 }
14948 }
718e3744 14949}
6b0655a2 14950
dd65f45e
DL
14951/* peer-group helpers for config-write */
14952
14953static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14954{
14955 if (!peer_group_active(peer)) {
14956 if (CHECK_FLAG(peer->flags_invert, flag))
14957 return !CHECK_FLAG(peer->flags, flag);
14958 else
14959 return !!CHECK_FLAG(peer->flags, flag);
14960 }
14961
14962 return !!CHECK_FLAG(peer->flags_override, flag);
14963}
14964
14965static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14966 uint32_t flag)
14967{
14968 if (!peer_group_active(peer)) {
14969 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14970 return !peer_af_flag_check(peer, afi, safi, flag);
14971 else
14972 return !!peer_af_flag_check(peer, afi, safi, flag);
14973 }
14974
14975 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14976}
14977
14978static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14979 uint8_t type, int direct)
14980{
14981 struct bgp_filter *filter;
14982
14983 if (peer_group_active(peer))
14984 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14985 type);
14986
14987 filter = &peer->filter[afi][safi];
14988 switch (type) {
14989 case PEER_FT_DISTRIBUTE_LIST:
14990 return !!(filter->dlist[direct].name);
14991 case PEER_FT_FILTER_LIST:
14992 return !!(filter->aslist[direct].name);
14993 case PEER_FT_PREFIX_LIST:
14994 return !!(filter->plist[direct].name);
14995 case PEER_FT_ROUTE_MAP:
14996 return !!(filter->map[direct].name);
14997 case PEER_FT_UNSUPPRESS_MAP:
14998 return !!(filter->usmap.name);
14999 default:
15000 return false;
15001 }
15002}
15003
15004/* Return true if the addpath type is set for peer and different from
15005 * peer-group.
15006 */
3dc339cd
DA
15007static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15008 safi_t safi)
dd65f45e
DL
15009{
15010 enum bgp_addpath_strat type, g_type;
15011
15012 type = peer->addpath_type[afi][safi];
15013
15014 if (type != BGP_ADDPATH_NONE) {
15015 if (peer_group_active(peer)) {
15016 g_type = peer->group->conf->addpath_type[afi][safi];
15017
15018 if (type != g_type)
3dc339cd 15019 return true;
dd65f45e 15020 else
3dc339cd 15021 return false;
dd65f45e
DL
15022 }
15023
3dc339cd 15024 return true;
dd65f45e
DL
15025 }
15026
3dc339cd 15027 return false;
dd65f45e
DL
15028}
15029
b9c7bc5a 15030/* This is part of the address-family block (unicast only) */
dd65f45e 15031static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
15032 afi_t afi)
15033{
b9c7bc5a 15034 int indent = 2;
ddb5b488 15035
8a066a70 15036 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
15037 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15038 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
15039 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15040 bgp->vpn_policy[afi]
bb4f6190 15041 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
15042 else
15043 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15044 bgp->vpn_policy[afi]
15045 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15046 }
12a844a5
DS
15047 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15048 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15049 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15050 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15051 return;
15052
e70e9f8e
PZ
15053 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15054 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
15055
15056 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
15057
15058 } else {
15059 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
15060 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
15061 bgp->vpn_policy[afi].tovpn_label);
15062 }
ddb5b488
PZ
15063 }
15064 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15065 BGP_VPN_POLICY_TOVPN_RD_SET)) {
15066 char buf[RD_ADDRSTRLEN];
b9c7bc5a 15067 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
15068 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
15069 sizeof(buf)));
15070 }
15071 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15072 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
15073
15074 char buf[PREFIX_STRLEN];
15075 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
15076 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
15077 sizeof(buf))) {
15078
b9c7bc5a
PZ
15079 vty_out(vty, "%*snexthop vpn export %s\n",
15080 indent, "", buf);
ddb5b488
PZ
15081 }
15082 }
15083 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
15084 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
15085 && ecommunity_cmp(
15086 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15087 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
15088
15089 char *b = ecommunity_ecom2str(
15090 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15091 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15092 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
15093 XFREE(MTYPE_ECOMMUNITY_STR, b);
15094 } else {
15095 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
15096 char *b = ecommunity_ecom2str(
15097 bgp->vpn_policy[afi]
15098 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15099 ECOMMUNITY_FORMAT_ROUTE_MAP,
15100 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15101 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
15102 XFREE(MTYPE_ECOMMUNITY_STR, b);
15103 }
15104 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
15105 char *b = ecommunity_ecom2str(
15106 bgp->vpn_policy[afi]
15107 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15108 ECOMMUNITY_FORMAT_ROUTE_MAP,
15109 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15110 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
15111 XFREE(MTYPE_ECOMMUNITY_STR, b);
15112 }
15113 }
bb4f6190
DS
15114
15115 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 15116 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
15117 bgp->vpn_policy[afi]
15118 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 15119
301ad80a
PG
15120 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
15121 char *b = ecommunity_ecom2str(
15122 bgp->vpn_policy[afi]
15123 .import_redirect_rtlist,
15124 ECOMMUNITY_FORMAT_ROUTE_MAP,
15125 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 15126
9a659715
PG
15127 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
15128 != ECOMMUNITY_SIZE)
c6423c31 15129 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
15130 indent, "", b);
15131 else
15132 vty_out(vty, "%*srt redirect import %s\n",
15133 indent, "", b);
301ad80a
PG
15134 XFREE(MTYPE_ECOMMUNITY_STR, b);
15135 }
ddb5b488
PZ
15136}
15137
dd65f45e
DL
15138static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
15139 afi_t afi, safi_t safi)
15140{
15141 struct bgp_filter *filter;
15142 char *addr;
15143
15144 addr = peer->host;
15145 filter = &peer->filter[afi][safi];
15146
15147 /* distribute-list. */
15148 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15149 FILTER_IN))
15150 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
15151 filter->dlist[FILTER_IN].name);
15152
15153 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15154 FILTER_OUT))
15155 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
15156 filter->dlist[FILTER_OUT].name);
15157
15158 /* prefix-list. */
15159 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15160 FILTER_IN))
15161 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
15162 filter->plist[FILTER_IN].name);
15163
15164 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15165 FILTER_OUT))
15166 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
15167 filter->plist[FILTER_OUT].name);
15168
15169 /* route-map. */
15170 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
15171 vty_out(vty, " neighbor %s route-map %s in\n", addr,
15172 filter->map[RMAP_IN].name);
15173
15174 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
15175 RMAP_OUT))
15176 vty_out(vty, " neighbor %s route-map %s out\n", addr,
15177 filter->map[RMAP_OUT].name);
15178
15179 /* unsuppress-map */
15180 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
15181 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
15182 filter->usmap.name);
15183
15184 /* filter-list. */
15185 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15186 FILTER_IN))
15187 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
15188 filter->aslist[FILTER_IN].name);
15189
15190 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15191 FILTER_OUT))
15192 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
15193 filter->aslist[FILTER_OUT].name);
15194}
15195
15196/* BGP peer configuration display function. */
15197static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
15198 struct peer *peer)
15199{
15200 struct peer *g_peer = NULL;
15201 char buf[SU_ADDRSTRLEN];
15202 char *addr;
15203 int if_pg_printed = false;
15204 int if_ras_printed = false;
15205
15206 /* Skip dynamic neighbors. */
15207 if (peer_dynamic_neighbor(peer))
15208 return;
15209
15210 if (peer->conf_if)
15211 addr = peer->conf_if;
15212 else
15213 addr = peer->host;
15214
15215 /************************************
15216 ****** Global to the neighbor ******
15217 ************************************/
15218 if (peer->conf_if) {
15219 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
15220 vty_out(vty, " neighbor %s interface v6only", addr);
15221 else
15222 vty_out(vty, " neighbor %s interface", addr);
15223
15224 if (peer_group_active(peer)) {
15225 vty_out(vty, " peer-group %s", peer->group->name);
15226 if_pg_printed = true;
15227 } else if (peer->as_type == AS_SPECIFIED) {
15228 vty_out(vty, " remote-as %u", peer->as);
15229 if_ras_printed = true;
15230 } else if (peer->as_type == AS_INTERNAL) {
15231 vty_out(vty, " remote-as internal");
15232 if_ras_printed = true;
15233 } else if (peer->as_type == AS_EXTERNAL) {
15234 vty_out(vty, " remote-as external");
15235 if_ras_printed = true;
15236 }
15237
15238 vty_out(vty, "\n");
15239 }
15240
15241 /* remote-as and peer-group */
15242 /* peer is a member of a peer-group */
15243 if (peer_group_active(peer)) {
15244 g_peer = peer->group->conf;
15245
15246 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
15247 if (peer->as_type == AS_SPECIFIED) {
15248 vty_out(vty, " neighbor %s remote-as %u\n",
15249 addr, peer->as);
15250 } else if (peer->as_type == AS_INTERNAL) {
15251 vty_out(vty,
15252 " neighbor %s remote-as internal\n",
15253 addr);
15254 } else if (peer->as_type == AS_EXTERNAL) {
15255 vty_out(vty,
15256 " neighbor %s remote-as external\n",
15257 addr);
15258 }
15259 }
15260
15261 /* For swpX peers we displayed the peer-group
15262 * via 'neighbor swpX interface peer-group PGNAME' */
15263 if (!if_pg_printed)
15264 vty_out(vty, " neighbor %s peer-group %s\n", addr,
15265 peer->group->name);
15266 }
15267
15268 /* peer is NOT a member of a peer-group */
15269 else {
15270 /* peer is a peer-group, declare the peer-group */
15271 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
15272 vty_out(vty, " neighbor %s peer-group\n", addr);
15273 }
15274
15275 if (!if_ras_printed) {
15276 if (peer->as_type == AS_SPECIFIED) {
15277 vty_out(vty, " neighbor %s remote-as %u\n",
15278 addr, peer->as);
15279 } else if (peer->as_type == AS_INTERNAL) {
15280 vty_out(vty,
15281 " neighbor %s remote-as internal\n",
15282 addr);
15283 } else if (peer->as_type == AS_EXTERNAL) {
15284 vty_out(vty,
15285 " neighbor %s remote-as external\n",
15286 addr);
15287 }
15288 }
15289 }
15290
15291 /* local-as */
15292 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
15293 vty_out(vty, " neighbor %s local-as %u", addr,
15294 peer->change_local_as);
15295 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
15296 vty_out(vty, " no-prepend");
15297 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
15298 vty_out(vty, " replace-as");
15299 vty_out(vty, "\n");
15300 }
15301
15302 /* description */
15303 if (peer->desc) {
15304 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
15305 }
15306
15307 /* shutdown */
15308 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
15309 if (peer->tx_shutdown_message)
15310 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
15311 peer->tx_shutdown_message);
15312 else
15313 vty_out(vty, " neighbor %s shutdown\n", addr);
15314 }
15315
8336c896
DA
15316 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
15317 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
15318 peer->rtt_expected, peer->rtt_keepalive_conf);
15319
dd65f45e
DL
15320 /* bfd */
15321 if (peer->bfd_info) {
15322 if (!peer_group_active(peer) || !g_peer->bfd_info) {
15323 bgp_bfd_peer_config_write(vty, peer, addr);
15324 }
15325 }
15326
15327 /* password */
15328 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
15329 vty_out(vty, " neighbor %s password %s\n", addr,
15330 peer->password);
15331
15332 /* neighbor solo */
15333 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
15334 if (!peer_group_active(peer)) {
15335 vty_out(vty, " neighbor %s solo\n", addr);
15336 }
15337 }
15338
15339 /* BGP port */
15340 if (peer->port != BGP_PORT_DEFAULT) {
15341 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
15342 }
15343
15344 /* Local interface name */
15345 if (peer->ifname) {
15346 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
15347 }
15348
15349 /* passive */
15350 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
15351 vty_out(vty, " neighbor %s passive\n", addr);
15352
15353 /* ebgp-multihop */
15354 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
15355 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
15356 && peer->ttl == MAXTTL)) {
dd65f45e
DL
15357 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
15358 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
15359 peer->ttl);
15360 }
15361 }
15362
15363 /* ttl-security hops */
e2521429 15364 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
15365 if (!peer_group_active(peer)
15366 || g_peer->gtsm_hops != peer->gtsm_hops) {
15367 vty_out(vty, " neighbor %s ttl-security hops %d\n",
15368 addr, peer->gtsm_hops);
15369 }
15370 }
15371
15372 /* disable-connected-check */
15373 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
15374 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
15375
15376 /* enforce-first-as */
15377 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
15378 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
15379
15380 /* update-source */
15381 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
15382 if (peer->update_source)
15383 vty_out(vty, " neighbor %s update-source %s\n", addr,
15384 sockunion2str(peer->update_source, buf,
15385 SU_ADDRSTRLEN));
15386 else if (peer->update_if)
15387 vty_out(vty, " neighbor %s update-source %s\n", addr,
15388 peer->update_if);
15389 }
15390
15391 /* advertisement-interval */
15392 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
15393 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
15394 peer->routeadv);
15395
15396 /* timers */
15397 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
15398 vty_out(vty, " neighbor %s timers %u %u\n", addr,
15399 peer->keepalive, peer->holdtime);
15400
15401 /* timers connect */
15402 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
15403 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15404 peer->connect);
5d5393b9
DL
15405 /* need special-case handling for changed default values due to
15406 * config profile / version (because there is no "timers bgp connect"
15407 * command, we need to save this per-peer :/)
15408 */
15409 else if (!peer_group_active(peer) && !peer->connect &&
15410 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
15411 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15412 peer->bgp->default_connect_retry);
dd65f45e
DL
15413
15414 /* capability dynamic */
15415 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
15416 vty_out(vty, " neighbor %s capability dynamic\n", addr);
15417
15418 /* capability extended-nexthop */
15419 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
15420 if (!peer->conf_if) {
15421 if (CHECK_FLAG(peer->flags_invert,
15422 PEER_FLAG_CAPABILITY_ENHE))
15423 vty_out(vty,
15424 " no neighbor %s capability extended-nexthop\n",
15425 addr);
15426 else
15427 vty_out(vty,
15428 " neighbor %s capability extended-nexthop\n",
15429 addr);
15430 }
15431 }
15432
15433 /* dont-capability-negotiation */
15434 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
15435 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
15436
15437 /* override-capability */
15438 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
15439 vty_out(vty, " neighbor %s override-capability\n", addr);
15440
15441 /* strict-capability-match */
15442 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
15443 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
15444
15445 /* Sender side AS path loop detection. */
15446 if (peer->as_path_loop_detection)
15447 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
15448 addr);
cfd47646 15449
15450 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15451 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 15452
15453 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15454 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 15455 vty_out(vty,
15456 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
15457 } else if (CHECK_FLAG(
15458 peer->peer_gr_new_status_flag,
15459 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 15460 vty_out(vty,
15461 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
15462 } else if (
15463 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
15464 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
15465 && !(CHECK_FLAG(
15466 peer->peer_gr_new_status_flag,
15467 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
15468 vty_out(vty, " neighbor %s graceful-restart-disable\n",
15469 addr);
cfd47646 15470 }
15471 }
dd65f45e
DL
15472}
15473
15474/* BGP peer configuration display function. */
15475static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
15476 struct peer *peer, afi_t afi, safi_t safi)
15477{
15478 struct peer *g_peer = NULL;
15479 char *addr;
15480 bool flag_scomm, flag_secomm, flag_slcomm;
15481
15482 /* Skip dynamic neighbors. */
15483 if (peer_dynamic_neighbor(peer))
15484 return;
15485
15486 if (peer->conf_if)
15487 addr = peer->conf_if;
15488 else
15489 addr = peer->host;
15490
15491 /************************************
15492 ****** Per AF to the neighbor ******
15493 ************************************/
15494 if (peer_group_active(peer)) {
15495 g_peer = peer->group->conf;
15496
15497 /* If the peer-group is active but peer is not, print a 'no
15498 * activate' */
15499 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15500 vty_out(vty, " no neighbor %s activate\n", addr);
15501 }
15502
15503 /* If the peer-group is not active but peer is, print an
15504 'activate' */
15505 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15506 vty_out(vty, " neighbor %s activate\n", addr);
15507 }
15508 } else {
15509 if (peer->afc[afi][safi]) {
15510 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15511 if (CHECK_FLAG(bgp->flags,
15512 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15513 vty_out(vty, " neighbor %s activate\n",
15514 addr);
15515 }
15516 } else
15517 vty_out(vty, " neighbor %s activate\n", addr);
15518 } else {
15519 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15520 if (!CHECK_FLAG(bgp->flags,
15521 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15522 vty_out(vty,
15523 " no neighbor %s activate\n",
15524 addr);
15525 }
15526 }
15527 }
15528 }
15529
15530 /* addpath TX knobs */
15531 if (peergroup_af_addpath_check(peer, afi, safi)) {
15532 switch (peer->addpath_type[afi][safi]) {
15533 case BGP_ADDPATH_ALL:
15534 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15535 addr);
15536 break;
15537 case BGP_ADDPATH_BEST_PER_AS:
15538 vty_out(vty,
15539 " neighbor %s addpath-tx-bestpath-per-AS\n",
15540 addr);
15541 break;
15542 case BGP_ADDPATH_MAX:
15543 case BGP_ADDPATH_NONE:
15544 break;
15545 }
15546 }
15547
15548 /* ORF capability. */
15549 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15550 || peergroup_af_flag_check(peer, afi, safi,
15551 PEER_FLAG_ORF_PREFIX_RM)) {
15552 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15553
15554 if (peergroup_af_flag_check(peer, afi, safi,
15555 PEER_FLAG_ORF_PREFIX_SM)
15556 && peergroup_af_flag_check(peer, afi, safi,
15557 PEER_FLAG_ORF_PREFIX_RM))
15558 vty_out(vty, " both");
15559 else if (peergroup_af_flag_check(peer, afi, safi,
15560 PEER_FLAG_ORF_PREFIX_SM))
15561 vty_out(vty, " send");
15562 else
15563 vty_out(vty, " receive");
15564 vty_out(vty, "\n");
15565 }
15566
dd65f45e
DL
15567 /* Route reflector client. */
15568 if (peergroup_af_flag_check(peer, afi, safi,
15569 PEER_FLAG_REFLECTOR_CLIENT)) {
15570 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15571 }
15572
15573 /* next-hop-self force */
15574 if (peergroup_af_flag_check(peer, afi, safi,
15575 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15576 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15577 }
15578
15579 /* next-hop-self */
15580 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15581 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15582 }
15583
15584 /* remove-private-AS */
15585 if (peergroup_af_flag_check(peer, afi, safi,
15586 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15587 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15588 addr);
15589 }
15590
15591 else if (peergroup_af_flag_check(peer, afi, safi,
15592 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15593 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15594 addr);
15595 }
15596
15597 else if (peergroup_af_flag_check(peer, afi, safi,
15598 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15599 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15600 }
15601
15602 else if (peergroup_af_flag_check(peer, afi, safi,
15603 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15604 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15605 }
15606
15607 /* as-override */
15608 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15609 vty_out(vty, " neighbor %s as-override\n", addr);
15610 }
15611
15612 /* send-community print. */
15613 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15614 PEER_FLAG_SEND_COMMUNITY);
15615 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15616 PEER_FLAG_SEND_EXT_COMMUNITY);
15617 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15618 PEER_FLAG_SEND_LARGE_COMMUNITY);
15619
15620 if (flag_scomm && flag_secomm && flag_slcomm) {
15621 vty_out(vty, " no neighbor %s send-community all\n", addr);
15622 } else {
15623 if (flag_scomm)
15624 vty_out(vty, " no neighbor %s send-community\n", addr);
15625 if (flag_secomm)
15626 vty_out(vty,
15627 " no neighbor %s send-community extended\n",
15628 addr);
15629
15630 if (flag_slcomm)
15631 vty_out(vty, " no neighbor %s send-community large\n",
15632 addr);
15633 }
15634
15635 /* Default information */
15636 if (peergroup_af_flag_check(peer, afi, safi,
15637 PEER_FLAG_DEFAULT_ORIGINATE)) {
15638 vty_out(vty, " neighbor %s default-originate", addr);
15639
15640 if (peer->default_rmap[afi][safi].name)
15641 vty_out(vty, " route-map %s",
15642 peer->default_rmap[afi][safi].name);
15643
15644 vty_out(vty, "\n");
15645 }
15646
15647 /* Soft reconfiguration inbound. */
15648 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15649 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15650 addr);
15651 }
15652
15653 /* maximum-prefix. */
15654 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15655 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15656 peer->pmax[afi][safi]);
15657
15658 if (peer->pmax_threshold[afi][safi]
15659 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15660 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15661 if (peer_af_flag_check(peer, afi, safi,
15662 PEER_FLAG_MAX_PREFIX_WARNING))
15663 vty_out(vty, " warning-only");
15664 if (peer->pmax_restart[afi][safi])
15665 vty_out(vty, " restart %u",
15666 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15667 if (peer_af_flag_check(peer, afi, safi,
15668 PEER_FLAG_MAX_PREFIX_FORCE))
15669 vty_out(vty, " force");
dd65f45e
DL
15670
15671 vty_out(vty, "\n");
15672 }
15673
fde246e8
DA
15674 /* maximum-prefix-out */
15675 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15676 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15677 addr, peer->pmax_out[afi][safi]);
15678
dd65f45e
DL
15679 /* Route server client. */
15680 if (peergroup_af_flag_check(peer, afi, safi,
15681 PEER_FLAG_RSERVER_CLIENT)) {
15682 vty_out(vty, " neighbor %s route-server-client\n", addr);
15683 }
15684
15685 /* Nexthop-local unchanged. */
15686 if (peergroup_af_flag_check(peer, afi, safi,
15687 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15688 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15689 }
15690
15691 /* allowas-in <1-10> */
15692 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15693 if (peer_af_flag_check(peer, afi, safi,
15694 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15695 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15696 } else if (peer->allowas_in[afi][safi] == 3) {
15697 vty_out(vty, " neighbor %s allowas-in\n", addr);
15698 } else {
15699 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15700 peer->allowas_in[afi][safi]);
15701 }
15702 }
15703
15704 /* weight */
15705 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15706 vty_out(vty, " neighbor %s weight %lu\n", addr,
15707 peer->weight[afi][safi]);
15708
15709 /* Filter. */
15710 bgp_config_write_filter(vty, peer, afi, safi);
15711
15712 /* atribute-unchanged. */
15713 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15714 || (safi != SAFI_EVPN
15715 && peer_af_flag_check(peer, afi, safi,
15716 PEER_FLAG_NEXTHOP_UNCHANGED))
15717 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15718
15719 if (!peer_group_active(peer)
15720 || peergroup_af_flag_check(peer, afi, safi,
15721 PEER_FLAG_AS_PATH_UNCHANGED)
15722 || peergroup_af_flag_check(peer, afi, safi,
15723 PEER_FLAG_NEXTHOP_UNCHANGED)
15724 || peergroup_af_flag_check(peer, afi, safi,
15725 PEER_FLAG_MED_UNCHANGED)) {
15726
15727 vty_out(vty,
15728 " neighbor %s attribute-unchanged%s%s%s\n",
15729 addr,
15730 peer_af_flag_check(peer, afi, safi,
15731 PEER_FLAG_AS_PATH_UNCHANGED)
15732 ? " as-path"
15733 : "",
15734 peer_af_flag_check(peer, afi, safi,
15735 PEER_FLAG_NEXTHOP_UNCHANGED)
15736 ? " next-hop"
15737 : "",
15738 peer_af_flag_check(peer, afi, safi,
15739 PEER_FLAG_MED_UNCHANGED)
15740 ? " med"
15741 : "");
15742 }
15743 }
15744}
15745
15746/* Address family based peer configuration display. */
15747static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15748 safi_t safi)
15749{
15750 struct peer *peer;
15751 struct peer_group *group;
15752 struct listnode *node, *nnode;
15753
15754
15755 vty_frame(vty, " !\n address-family ");
15756 if (afi == AFI_IP) {
15757 if (safi == SAFI_UNICAST)
15758 vty_frame(vty, "ipv4 unicast");
15759 else if (safi == SAFI_LABELED_UNICAST)
15760 vty_frame(vty, "ipv4 labeled-unicast");
15761 else if (safi == SAFI_MULTICAST)
15762 vty_frame(vty, "ipv4 multicast");
15763 else if (safi == SAFI_MPLS_VPN)
15764 vty_frame(vty, "ipv4 vpn");
15765 else if (safi == SAFI_ENCAP)
15766 vty_frame(vty, "ipv4 encap");
15767 else if (safi == SAFI_FLOWSPEC)
15768 vty_frame(vty, "ipv4 flowspec");
15769 } else if (afi == AFI_IP6) {
15770 if (safi == SAFI_UNICAST)
15771 vty_frame(vty, "ipv6 unicast");
15772 else if (safi == SAFI_LABELED_UNICAST)
15773 vty_frame(vty, "ipv6 labeled-unicast");
15774 else if (safi == SAFI_MULTICAST)
15775 vty_frame(vty, "ipv6 multicast");
15776 else if (safi == SAFI_MPLS_VPN)
15777 vty_frame(vty, "ipv6 vpn");
15778 else if (safi == SAFI_ENCAP)
15779 vty_frame(vty, "ipv6 encap");
15780 else if (safi == SAFI_FLOWSPEC)
15781 vty_frame(vty, "ipv6 flowspec");
15782 } else if (afi == AFI_L2VPN) {
15783 if (safi == SAFI_EVPN)
15784 vty_frame(vty, "l2vpn evpn");
15785 }
15786 vty_frame(vty, "\n");
15787
15788 bgp_config_write_distance(vty, bgp, afi, safi);
15789
15790 bgp_config_write_network(vty, bgp, afi, safi);
15791
15792 bgp_config_write_redistribute(vty, bgp, afi, safi);
15793
8a4e7fe6
DA
15794 /* BGP flag dampening. */
15795 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15796 bgp_config_write_damp(vty, afi, safi);
15797
dd65f45e
DL
15798 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15799 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15800
15801 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15802 /* Skip dynamic neighbors. */
15803 if (peer_dynamic_neighbor(peer))
15804 continue;
15805
15806 /* Do not display doppelganger peers */
15807 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15808 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15809 }
15810
15811 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15812 bgp_config_write_table_map(vty, bgp, afi, safi);
15813
15814 if (safi == SAFI_EVPN)
15815 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15816
15817 if (safi == SAFI_FLOWSPEC)
15818 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15819
15820 if (safi == SAFI_UNICAST) {
15821 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15822 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15823 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15824
15825 vty_out(vty, " export vpn\n");
15826 }
15827 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15828 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15829
15830 vty_out(vty, " import vpn\n");
15831 }
15832 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15833 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15834 char *name;
15835
15836 for (ALL_LIST_ELEMENTS_RO(
15837 bgp->vpn_policy[afi].import_vrf, node,
15838 name))
15839 vty_out(vty, " import vrf %s\n", name);
15840 }
15841 }
15842
15843 vty_endframe(vty, " exit-address-family\n");
15844}
15845
15846int bgp_config_write(struct vty *vty)
15847{
15848 struct bgp *bgp;
15849 struct peer_group *group;
15850 struct peer *peer;
15851 struct listnode *node, *nnode;
15852 struct listnode *mnode, *mnnode;
15853
15854 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15855 vty_out(vty, "bgp route-map delay-timer %u\n",
15856 bm->rmap_update_timer);
15857
d70583f7
D
15858 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
15859 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
15860 if (bm->v_update_delay != bm->v_establish_wait)
15861 vty_out(vty, " %d", bm->v_establish_wait);
15862 vty_out(vty, "\n");
15863 }
15864
05bd726c 15865 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
15866 vty_out(vty, "bgp graceful-shutdown\n");
15867
c163f297
DS
15868 /* No-RIB (Zebra) option flag configuration */
15869 if (bgp_option_check(BGP_OPT_NO_FIB))
15870 vty_out(vty, "bgp no-rib\n");
15871
dd65f45e
DL
15872 /* BGP configuration. */
15873 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15874
15875 /* skip all auto created vrf as they dont have user config */
15876 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15877 continue;
15878
15879 /* Router bgp ASN */
15880 vty_out(vty, "router bgp %u", bgp->as);
15881
15882 if (bgp->name)
15883 vty_out(vty, " %s %s",
15884 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15885 ? "view" : "vrf", bgp->name);
15886 vty_out(vty, "\n");
15887
15888 /* BGP fast-external-failover. */
15889 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15890 vty_out(vty, " no bgp fast-external-failover\n");
15891
15892 /* BGP router ID. */
15893 if (bgp->router_id_static.s_addr != 0)
23d0a753
DA
15894 vty_out(vty, " bgp router-id %pI4\n",
15895 &bgp->router_id_static);
dd65f45e
DL
15896
15897 /* BGP log-neighbor-changes. */
892fedb6 15898 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15899 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15900 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15901 CHECK_FLAG(bgp->flags,
15902 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15903 ? ""
15904 : "no ");
15905
15906 /* BGP configuration. */
892fedb6 15907 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15908 vty_out(vty, " bgp always-compare-med\n");
15909
15910 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
15911 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15912 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15913 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15914 CHECK_FLAG(bgp->flags,
15915 BGP_FLAG_EBGP_REQUIRES_POLICY)
15916 ? ""
15917 : "no ");
dd65f45e
DL
15918
15919 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 15920 if (bgp->reject_as_sets)
dd65f45e
DL
15921 vty_out(vty, " bgp reject-as-sets\n");
15922
15923 /* BGP default ipv4-unicast. */
892fedb6 15924 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15925 vty_out(vty, " no bgp default ipv4-unicast\n");
15926
15927 /* BGP default local-preference. */
15928 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15929 vty_out(vty, " bgp default local-preference %u\n",
15930 bgp->default_local_pref);
15931
15932 /* BGP default show-hostname */
892fedb6 15933 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15934 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15935 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15936 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15937 ? ""
15938 : "no ");
15939
aef999a2
DA
15940 /* BGP default show-nexthop-hostname */
15941 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15942 != SAVE_BGP_SHOW_HOSTNAME)
15943 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15944 CHECK_FLAG(bgp->flags,
15945 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15946 ? ""
15947 : "no ");
15948
dd65f45e
DL
15949 /* BGP default subgroup-pkt-queue-max. */
15950 if (bgp->default_subgroup_pkt_queue_max
15951 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15952 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15953 bgp->default_subgroup_pkt_queue_max);
15954
15955 /* BGP client-to-client reflection. */
892fedb6 15956 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15957 vty_out(vty, " no bgp client-to-client reflection\n");
15958
15959 /* BGP cluster ID. */
15960 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
15961 vty_out(vty, " bgp cluster-id %pI4\n",
15962 &bgp->cluster_id);
dd65f45e
DL
15963
15964 /* Disable ebgp connected nexthop check */
892fedb6 15965 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15966 vty_out(vty,
15967 " bgp disable-ebgp-connected-route-check\n");
15968
15969 /* Confederation identifier*/
15970 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15971 vty_out(vty, " bgp confederation identifier %u\n",
15972 bgp->confed_id);
15973
15974 /* Confederation peer */
15975 if (bgp->confed_peers_cnt > 0) {
15976 int i;
15977
15978 vty_out(vty, " bgp confederation peers");
15979
15980 for (i = 0; i < bgp->confed_peers_cnt; i++)
15981 vty_out(vty, " %u", bgp->confed_peers[i]);
15982
15983 vty_out(vty, "\n");
15984 }
15985
15986 /* BGP deterministic-med. */
892fedb6 15987 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15988 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15989 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15990 CHECK_FLAG(bgp->flags,
15991 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15992 ? ""
15993 : "no ");
15994
15995 /* BGP update-delay. */
15996 bgp_config_write_update_delay(vty, bgp);
15997
15998 if (bgp->v_maxmed_onstartup
15999 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16000 vty_out(vty, " bgp max-med on-startup %u",
16001 bgp->v_maxmed_onstartup);
16002 if (bgp->maxmed_onstartup_value
16003 != BGP_MAXMED_VALUE_DEFAULT)
16004 vty_out(vty, " %u",
16005 bgp->maxmed_onstartup_value);
16006 vty_out(vty, "\n");
16007 }
16008 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16009 vty_out(vty, " bgp max-med administrative");
16010 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16011 vty_out(vty, " %u", bgp->maxmed_admin_value);
16012 vty_out(vty, "\n");
16013 }
16014
16015 /* write quanta */
16016 bgp_config_write_wpkt_quanta(vty, bgp);
16017 /* read quanta */
16018 bgp_config_write_rpkt_quanta(vty, bgp);
16019
16020 /* coalesce time */
16021 bgp_config_write_coalesce_time(vty, bgp);
16022
05bd726c 16023 /* BGP per-instance graceful-shutdown */
16024 /* BGP-wide settings and per-instance settings are mutually
16025 * exclusive.
16026 */
16027 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16028 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
16029 vty_out(vty, " bgp graceful-shutdown\n");
16030
dd65f45e
DL
16031 /* BGP graceful-restart. */
16032 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
16033 vty_out(vty,
16034 " bgp graceful-restart stalepath-time %u\n",
16035 bgp->stalepath_time);
cfd47646 16036
dd65f45e
DL
16037 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
16038 vty_out(vty, " bgp graceful-restart restart-time %u\n",
16039 bgp->restart_time);
cfd47646 16040
16041 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
16042 vty_out(vty,
16043 " bgp graceful-restart select-defer-time %u\n",
16044 bgp->select_defer_time);
16045
16046 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
16047 vty_out(vty, " bgp graceful-restart\n");
16048
cfd47646 16049 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
16050 vty_out(vty, " bgp graceful-restart-disable\n");
16051
dd65f45e 16052 /* BGP graceful-restart Preserve State F bit. */
892fedb6 16053 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
16054 vty_out(vty,
16055 " bgp graceful-restart preserve-fw-state\n");
16056
dc95985f 16057 /* Stale timer for RIB */
16058 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
16059 vty_out(vty,
16060 " bgp graceful-restart rib-stale-time %u\n",
16061 bgp->rib_stale_time);
16062
dd65f45e 16063 /* BGP bestpath method. */
892fedb6 16064 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 16065 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 16066 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
16067 vty_out(vty, " bgp bestpath as-path confed\n");
16068
892fedb6
DA
16069 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
16070 if (CHECK_FLAG(bgp->flags,
16071 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
16072 vty_out(vty,
16073 " bgp bestpath as-path multipath-relax as-set\n");
16074 } else {
16075 vty_out(vty,
16076 " bgp bestpath as-path multipath-relax\n");
16077 }
16078 }
16079
892fedb6 16080 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
16081 vty_out(vty,
16082 " bgp route-reflector allow-outbound-policy\n");
16083 }
892fedb6 16084 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 16085 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
16086 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
16087 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 16088 vty_out(vty, " bgp bestpath med");
892fedb6 16089 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 16090 vty_out(vty, " confed");
892fedb6
DA
16091 if (CHECK_FLAG(bgp->flags,
16092 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
16093 vty_out(vty, " missing-as-worst");
16094 vty_out(vty, "\n");
16095 }
16096
f7e1c681 16097 /* Link bandwidth handling. */
16098 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
16099 vty_out(vty, " bgp bestpath bandwidth ignore\n");
16100 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
16101 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
16102 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
16103 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
16104
dd65f45e 16105 /* BGP network import check. */
892fedb6 16106 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 16107 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 16108 vty_out(vty, " %sbgp network import-check\n",
892fedb6 16109 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
16110 ? ""
16111 : "no ");
16112
16113 /* BGP timers configuration. */
5d5393b9
DL
16114 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
16115 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
16116 vty_out(vty, " timers bgp %u %u\n",
16117 bgp->default_keepalive, bgp->default_holdtime);
16118
16119 /* peer-group */
16120 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16121 bgp_config_write_peer_global(vty, bgp, group->conf);
16122 }
16123
16124 /* Normal neighbor configuration. */
16125 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16126 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16127 bgp_config_write_peer_global(vty, bgp, peer);
16128 }
16129
16130 /* listen range and limit for dynamic BGP neighbors */
16131 bgp_config_write_listen(vty, bgp);
16132
16133 /*
16134 * BGP default autoshutdown neighbors
16135 *
16136 * This must be placed after any peer and peer-group
16137 * configuration, to avoid setting all peers to shutdown after
16138 * a daemon restart, which is undesired behavior. (see #2286)
16139 */
16140 if (bgp->autoshutdown)
16141 vty_out(vty, " bgp default shutdown\n");
16142
9cf59432
DS
16143 /* BGP instance administrative shutdown */
16144 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
16145 vty_out(vty, " bgp shutdown\n");
16146
dd65f45e
DL
16147 /* IPv4 unicast configuration. */
16148 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
16149
16150 /* IPv4 multicast configuration. */
16151 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
16152
16153 /* IPv4 labeled-unicast configuration. */
16154 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
16155
16156 /* IPv4 VPN configuration. */
16157 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
16158
16159 /* ENCAPv4 configuration. */
16160 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
16161
16162 /* FLOWSPEC v4 configuration. */
16163 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
16164
16165 /* IPv6 unicast configuration. */
16166 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
16167
16168 /* IPv6 multicast configuration. */
16169 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
16170
16171 /* IPv6 labeled-unicast configuration. */
16172 bgp_config_write_family(vty, bgp, AFI_IP6,
16173 SAFI_LABELED_UNICAST);
16174
16175 /* IPv6 VPN configuration. */
16176 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
16177
16178 /* ENCAPv6 configuration. */
16179 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
16180
16181 /* FLOWSPEC v6 configuration. */
16182 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
16183
16184 /* EVPN configuration. */
16185 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
16186
16187 hook_call(bgp_inst_config_write, bgp, vty);
16188
49e5a4a0 16189#ifdef ENABLE_BGP_VNC
dd65f45e
DL
16190 bgp_rfapi_cfg_write(vty, bgp);
16191#endif
16192
16193 vty_out(vty, "!\n");
16194 }
16195 return 0;
16196}
16197
ddb5b488 16198
718e3744 16199/* BGP node structure. */
d62a17ae 16200static struct cmd_node bgp_node = {
f4b8291f 16201 .name = "bgp",
62b346ee 16202 .node = BGP_NODE,
24389580 16203 .parent_node = CONFIG_NODE,
62b346ee 16204 .prompt = "%s(config-router)# ",
612c2c15 16205 .config_write = bgp_config_write,
718e3744 16206};
16207
d62a17ae 16208static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 16209 .name = "bgp ipv4 unicast",
62b346ee 16210 .node = BGP_IPV4_NODE,
24389580 16211 .parent_node = BGP_NODE,
62b346ee 16212 .prompt = "%s(config-router-af)# ",
718e3744 16213};
16214
d62a17ae 16215static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 16216 .name = "bgp ipv4 multicast",
62b346ee 16217 .node = BGP_IPV4M_NODE,
24389580 16218 .parent_node = BGP_NODE,
62b346ee 16219 .prompt = "%s(config-router-af)# ",
718e3744 16220};
16221
d62a17ae 16222static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 16223 .name = "bgp ipv4 labeled unicast",
62b346ee 16224 .node = BGP_IPV4L_NODE,
24389580 16225 .parent_node = BGP_NODE,
62b346ee 16226 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16227};
16228
d62a17ae 16229static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 16230 .name = "bgp ipv6",
62b346ee 16231 .node = BGP_IPV6_NODE,
24389580 16232 .parent_node = BGP_NODE,
62b346ee 16233 .prompt = "%s(config-router-af)# ",
718e3744 16234};
16235
d62a17ae 16236static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 16237 .name = "bgp ipv6 multicast",
62b346ee 16238 .node = BGP_IPV6M_NODE,
24389580 16239 .parent_node = BGP_NODE,
62b346ee 16240 .prompt = "%s(config-router-af)# ",
25ffbdc1 16241};
16242
d62a17ae 16243static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 16244 .name = "bgp ipv6 labeled unicast",
62b346ee 16245 .node = BGP_IPV6L_NODE,
24389580 16246 .parent_node = BGP_NODE,
62b346ee 16247 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16248};
16249
62b346ee 16250static struct cmd_node bgp_vpnv4_node = {
f4b8291f 16251 .name = "bgp vpnv4",
62b346ee 16252 .node = BGP_VPNV4_NODE,
24389580 16253 .parent_node = BGP_NODE,
62b346ee 16254 .prompt = "%s(config-router-af)# ",
62b346ee 16255};
6b0655a2 16256
62b346ee 16257static struct cmd_node bgp_vpnv6_node = {
f4b8291f 16258 .name = "bgp vpnv6",
62b346ee 16259 .node = BGP_VPNV6_NODE,
24389580 16260 .parent_node = BGP_NODE,
62b346ee 16261 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16262};
8ecd3266 16263
62b346ee 16264static struct cmd_node bgp_evpn_node = {
f4b8291f 16265 .name = "bgp evpn",
62b346ee 16266 .node = BGP_EVPN_NODE,
24389580 16267 .parent_node = BGP_NODE,
62b346ee 16268 .prompt = "%s(config-router-evpn)# ",
62b346ee 16269};
4e0b7b6d 16270
62b346ee 16271static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 16272 .name = "bgp evpn vni",
62b346ee 16273 .node = BGP_EVPN_VNI_NODE,
24389580 16274 .parent_node = BGP_EVPN_NODE,
62b346ee 16275 .prompt = "%s(config-router-af-vni)# ",
62b346ee 16276};
90e60aa7 16277
62b346ee 16278static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 16279 .name = "bgp ipv4 flowspec",
62b346ee 16280 .node = BGP_FLOWSPECV4_NODE,
24389580 16281 .parent_node = BGP_NODE,
62b346ee 16282 .prompt = "%s(config-router-af)# ",
62b346ee 16283};
7c40bf39 16284
62b346ee 16285static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 16286 .name = "bgp ipv6 flowspec",
62b346ee 16287 .node = BGP_FLOWSPECV6_NODE,
24389580 16288 .parent_node = BGP_NODE,
62b346ee 16289 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16290};
7c40bf39 16291
d62a17ae 16292static void community_list_vty(void);
1f8ae70b 16293
d62a17ae 16294static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 16295{
d62a17ae 16296 struct bgp *bgp;
16297 struct peer *peer;
d62a17ae 16298 struct listnode *lnbgp, *lnpeer;
b8a815e5 16299
d62a17ae 16300 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16301 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
16302 /* only provide suggestions on the appropriate input
16303 * token type,
16304 * they'll otherwise show up multiple times */
16305 enum cmd_token_type match_type;
16306 char *name = peer->host;
d48ed3e0 16307
d62a17ae 16308 if (peer->conf_if) {
16309 match_type = VARIABLE_TKN;
16310 name = peer->conf_if;
16311 } else if (strchr(peer->host, ':'))
16312 match_type = IPV6_TKN;
16313 else
16314 match_type = IPV4_TKN;
d48ed3e0 16315
d62a17ae 16316 if (token->type != match_type)
16317 continue;
d48ed3e0 16318
d62a17ae 16319 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
16320 }
d62a17ae 16321 }
b8a815e5
DL
16322}
16323
16324static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 16325 {.varname = "neighbor", .completions = bgp_ac_neighbor},
16326 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 16327 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 16328 {.completions = NULL}};
16329
47a306a0
DS
16330static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
16331{
16332 struct bgp *bgp;
16333 struct peer_group *group;
16334 struct listnode *lnbgp, *lnpeer;
16335
16336 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16337 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
16338 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
16339 group->name));
16340 }
16341}
16342
16343static const struct cmd_variable_handler bgp_var_peergroup[] = {
16344 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
16345 {.completions = NULL} };
16346
d62a17ae 16347void bgp_vty_init(void)
16348{
16349 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 16350 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 16351
16352 /* Install bgp top node. */
612c2c15
DL
16353 install_node(&bgp_node);
16354 install_node(&bgp_ipv4_unicast_node);
16355 install_node(&bgp_ipv4_multicast_node);
16356 install_node(&bgp_ipv4_labeled_unicast_node);
16357 install_node(&bgp_ipv6_unicast_node);
16358 install_node(&bgp_ipv6_multicast_node);
16359 install_node(&bgp_ipv6_labeled_unicast_node);
16360 install_node(&bgp_vpnv4_node);
16361 install_node(&bgp_vpnv6_node);
16362 install_node(&bgp_evpn_node);
16363 install_node(&bgp_evpn_vni_node);
16364 install_node(&bgp_flowspecv4_node);
16365 install_node(&bgp_flowspecv6_node);
d62a17ae 16366
16367 /* Install default VTY commands to new nodes. */
16368 install_default(BGP_NODE);
16369 install_default(BGP_IPV4_NODE);
16370 install_default(BGP_IPV4M_NODE);
16371 install_default(BGP_IPV4L_NODE);
16372 install_default(BGP_IPV6_NODE);
16373 install_default(BGP_IPV6M_NODE);
16374 install_default(BGP_IPV6L_NODE);
16375 install_default(BGP_VPNV4_NODE);
16376 install_default(BGP_VPNV6_NODE);
7c40bf39 16377 install_default(BGP_FLOWSPECV4_NODE);
16378 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 16379 install_default(BGP_EVPN_NODE);
16380 install_default(BGP_EVPN_VNI_NODE);
16381
8029b216
AK
16382 /* "bgp local-mac" hidden commands. */
16383 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
16384 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
16385
d62a17ae 16386 /* bgp route-map delay-timer commands. */
16387 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
16388 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16389
d70583f7
D
16390 /* global bgp update-delay command */
16391 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
16392 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
16393
05bd726c 16394 /* global bgp graceful-shutdown command */
16395 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
16396 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
16397
d62a17ae 16398 /* Dummy commands (Currently not supported) */
16399 install_element(BGP_NODE, &no_synchronization_cmd);
16400 install_element(BGP_NODE, &no_auto_summary_cmd);
16401
16402 /* "router bgp" commands. */
16403 install_element(CONFIG_NODE, &router_bgp_cmd);
16404
16405 /* "no router bgp" commands. */
16406 install_element(CONFIG_NODE, &no_router_bgp_cmd);
16407
16408 /* "bgp router-id" commands. */
16409 install_element(BGP_NODE, &bgp_router_id_cmd);
16410 install_element(BGP_NODE, &no_bgp_router_id_cmd);
16411
16412 /* "bgp cluster-id" commands. */
16413 install_element(BGP_NODE, &bgp_cluster_id_cmd);
16414 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
16415
c163f297
DS
16416 /* "bgp no-rib" commands. */
16417 install_element(CONFIG_NODE, &bgp_norib_cmd);
16418 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
16419
d62a17ae 16420 /* "bgp confederation" commands. */
16421 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
16422 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
16423
16424 /* "bgp confederation peers" commands. */
16425 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
16426 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
16427
16428 /* bgp max-med command */
16429 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
16430 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
16431 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
16432 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
16433 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
16434
16435 /* bgp disable-ebgp-connected-nh-check */
16436 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
16437 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
16438
16439 /* bgp update-delay command */
16440 install_element(BGP_NODE, &bgp_update_delay_cmd);
16441 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 16442
16443 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 16444 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 16445
16446 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
16447 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
16448
16449 /* "maximum-paths" commands. */
16450 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
16451 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
16452 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
16453 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
16454 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
16455 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
16456 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
16457 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
16458 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
16459 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
16460 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16461 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
16462 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
16463 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16464 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
16465
39edabac
PG
16466 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
16467 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
16468 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
16469 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16470 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 16471 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
16472 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
16473 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
16474 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16475 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16476
16477 /* "timers bgp" commands. */
16478 install_element(BGP_NODE, &bgp_timers_cmd);
16479 install_element(BGP_NODE, &no_bgp_timers_cmd);
16480
16481 /* route-map delay-timer commands - per instance for backwards compat.
16482 */
16483 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
16484 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16485
16486 /* "bgp client-to-client reflection" commands */
16487 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
16488 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
16489
16490 /* "bgp always-compare-med" commands */
16491 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
16492 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
16493
9dac9fc8
DA
16494 /* bgp ebgp-requires-policy */
16495 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
16496 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
16497
fb29348a
DA
16498 /* bgp reject-as-sets */
16499 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
16500 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
16501
d62a17ae 16502 /* "bgp deterministic-med" commands */
16503 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
16504 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
16505
055679e9 16506 /* "bgp graceful-restart" command */
36235319
QY
16507 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
16508 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 16509
16510 /* "bgp graceful-restart-disable" command */
36235319
QY
16511 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
16512 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 16513
16514 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
16515 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
16516 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 16517
16518 /* "neighbor a:b:c:d graceful-restart-disable" command */
16519 install_element(BGP_NODE,
16520 &bgp_neighbor_graceful_restart_disable_set_cmd);
16521 install_element(BGP_NODE,
16522 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
16523
16524 /* "neighbor a:b:c:d graceful-restart-helper" command */
16525 install_element(BGP_NODE,
16526 &bgp_neighbor_graceful_restart_helper_set_cmd);
16527 install_element(BGP_NODE,
16528 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16529
d62a17ae 16530 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16531 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16532 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16533 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 16534 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 16535 install_element(BGP_NODE,
16536 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 16537 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16538 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16539
d6e3c15b 16540 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16541 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 16542 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16543 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 16544
7f323236
DW
16545 /* "bgp graceful-shutdown" commands */
16546 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16547 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16548
d62a17ae 16549 /* "bgp fast-external-failover" commands */
16550 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16551 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16552
d62a17ae 16553 /* "bgp bestpath compare-routerid" commands */
16554 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16555 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16556
16557 /* "bgp bestpath as-path ignore" commands */
16558 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16559 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16560
16561 /* "bgp bestpath as-path confed" commands */
16562 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16563 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16564
16565 /* "bgp bestpath as-path multipath-relax" commands */
16566 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16567 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16568
16569 /* "bgp log-neighbor-changes" commands */
16570 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16571 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16572
16573 /* "bgp bestpath med" commands */
16574 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16575 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16576
f7e1c681 16577 /* "bgp bestpath bandwidth" commands */
16578 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 16579 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 16580
d62a17ae 16581 /* "no bgp default ipv4-unicast" commands. */
16582 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16583 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16584
16585 /* "bgp network import-check" commands. */
16586 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16587 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16588 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16589
16590 /* "bgp default local-preference" commands. */
16591 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16592 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16593
16594 /* bgp default show-hostname */
16595 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16596 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16597
aef999a2
DA
16598 /* bgp default show-nexthop-hostname */
16599 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16600 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16601
d62a17ae 16602 /* "bgp default subgroup-pkt-queue-max" commands. */
16603 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16604 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16605
16606 /* bgp ibgp-allow-policy-mods command */
16607 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16608 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16609
16610 /* "bgp listen limit" commands. */
16611 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16612 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16613
16614 /* "bgp listen range" commands. */
16615 install_element(BGP_NODE, &bgp_listen_range_cmd);
16616 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16617
8175f54a 16618 /* "bgp default shutdown" command */
f26845f9 16619 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
16620
16621 /* "bgp shutdown" commands */
16622 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 16623 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 16624 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 16625 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 16626
d62a17ae 16627 /* "neighbor remote-as" commands. */
16628 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16629 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16630 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16631 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16632 install_element(BGP_NODE,
16633 &neighbor_interface_v6only_config_remote_as_cmd);
16634 install_element(BGP_NODE, &no_neighbor_cmd);
16635 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16636
16637 /* "neighbor peer-group" commands. */
16638 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16639 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16640 install_element(BGP_NODE,
16641 &no_neighbor_interface_peer_group_remote_as_cmd);
16642
16643 /* "neighbor local-as" commands. */
16644 install_element(BGP_NODE, &neighbor_local_as_cmd);
16645 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16646 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16647 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16648
16649 /* "neighbor solo" commands. */
16650 install_element(BGP_NODE, &neighbor_solo_cmd);
16651 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16652
16653 /* "neighbor password" commands. */
16654 install_element(BGP_NODE, &neighbor_password_cmd);
16655 install_element(BGP_NODE, &no_neighbor_password_cmd);
16656
16657 /* "neighbor activate" commands. */
16658 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16659 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16660 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16661 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16662 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16663 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16664 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16665 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16666 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16667 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16668 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16669 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16670
16671 /* "no neighbor activate" commands. */
16672 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16673 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16674 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16675 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16676 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16677 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16678 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16679 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16680 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16681 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16682 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16683 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16684
16685 /* "neighbor peer-group" set commands. */
16686 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16687 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16688 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16689 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16690 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16691 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16692 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16693 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16694 install_element(BGP_FLOWSPECV4_NODE,
16695 &neighbor_set_peer_group_hidden_cmd);
16696 install_element(BGP_FLOWSPECV6_NODE,
16697 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16698
16699 /* "no neighbor peer-group unset" commands. */
16700 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16701 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16702 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16703 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16704 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16705 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16706 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16707 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16708 install_element(BGP_FLOWSPECV4_NODE,
16709 &no_neighbor_set_peer_group_hidden_cmd);
16710 install_element(BGP_FLOWSPECV6_NODE,
16711 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16712
16713 /* "neighbor softreconfiguration inbound" commands.*/
16714 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16715 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16716 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16717 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16718 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16719 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16720 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16721 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16722 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16723 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16724 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16725 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16726 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16727 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16728 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16729 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16730 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16731 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16732 install_element(BGP_FLOWSPECV4_NODE,
16733 &neighbor_soft_reconfiguration_cmd);
16734 install_element(BGP_FLOWSPECV4_NODE,
16735 &no_neighbor_soft_reconfiguration_cmd);
16736 install_element(BGP_FLOWSPECV6_NODE,
16737 &neighbor_soft_reconfiguration_cmd);
16738 install_element(BGP_FLOWSPECV6_NODE,
16739 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16740 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16741 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16742
16743 /* "neighbor attribute-unchanged" commands. */
16744 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16745 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16746 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16747 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16748 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16749 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16750 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16751 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16752 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16753 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16754 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16755 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16756 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16757 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16758 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16759 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16760 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16761 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16762
16763 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16764 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16765
16766 /* "nexthop-local unchanged" commands */
16767 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16768 install_element(BGP_IPV6_NODE,
16769 &no_neighbor_nexthop_local_unchanged_cmd);
16770
16771 /* "neighbor next-hop-self" commands. */
16772 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16773 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16774 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16775 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16776 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16777 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16778 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16779 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16780 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16781 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16782 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16783 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16784 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16785 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16786 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16787 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16788 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16789 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
16790 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16791 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 16792
16793 /* "neighbor next-hop-self force" commands. */
16794 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16795 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
16796 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16797 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16798 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16799 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16800 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16801 install_element(BGP_IPV4_NODE,
16802 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16803 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16804 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16805 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16806 install_element(BGP_IPV4M_NODE,
16807 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16808 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16809 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16810 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16811 install_element(BGP_IPV4L_NODE,
16812 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16813 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16814 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16815 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16816 install_element(BGP_IPV6_NODE,
16817 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16818 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16819 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16820 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16821 install_element(BGP_IPV6M_NODE,
16822 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16823 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16824 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16825 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16826 install_element(BGP_IPV6L_NODE,
16827 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16828 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16829 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16830 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16831 install_element(BGP_VPNV4_NODE,
16832 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16833 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16834 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16835 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16836 install_element(BGP_VPNV6_NODE,
16837 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
16838 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16839 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 16840
16841 /* "neighbor as-override" commands. */
16842 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16843 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16844 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16845 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16846 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16847 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16848 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16849 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16850 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16851 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16852 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16853 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16854 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16855 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16856 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16857 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16858 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16859 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16860
16861 /* "neighbor remove-private-AS" commands. */
16862 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16863 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16864 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16865 install_element(BGP_NODE,
16866 &no_neighbor_remove_private_as_all_hidden_cmd);
16867 install_element(BGP_NODE,
16868 &neighbor_remove_private_as_replace_as_hidden_cmd);
16869 install_element(BGP_NODE,
16870 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16871 install_element(BGP_NODE,
16872 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16873 install_element(
16874 BGP_NODE,
16875 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16876 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16877 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16878 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16879 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16880 install_element(BGP_IPV4_NODE,
16881 &neighbor_remove_private_as_replace_as_cmd);
16882 install_element(BGP_IPV4_NODE,
16883 &no_neighbor_remove_private_as_replace_as_cmd);
16884 install_element(BGP_IPV4_NODE,
16885 &neighbor_remove_private_as_all_replace_as_cmd);
16886 install_element(BGP_IPV4_NODE,
16887 &no_neighbor_remove_private_as_all_replace_as_cmd);
16888 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16889 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16890 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16891 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16892 install_element(BGP_IPV4M_NODE,
16893 &neighbor_remove_private_as_replace_as_cmd);
16894 install_element(BGP_IPV4M_NODE,
16895 &no_neighbor_remove_private_as_replace_as_cmd);
16896 install_element(BGP_IPV4M_NODE,
16897 &neighbor_remove_private_as_all_replace_as_cmd);
16898 install_element(BGP_IPV4M_NODE,
16899 &no_neighbor_remove_private_as_all_replace_as_cmd);
16900 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16901 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16902 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16903 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16904 install_element(BGP_IPV4L_NODE,
16905 &neighbor_remove_private_as_replace_as_cmd);
16906 install_element(BGP_IPV4L_NODE,
16907 &no_neighbor_remove_private_as_replace_as_cmd);
16908 install_element(BGP_IPV4L_NODE,
16909 &neighbor_remove_private_as_all_replace_as_cmd);
16910 install_element(BGP_IPV4L_NODE,
16911 &no_neighbor_remove_private_as_all_replace_as_cmd);
16912 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16913 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16914 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16915 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16916 install_element(BGP_IPV6_NODE,
16917 &neighbor_remove_private_as_replace_as_cmd);
16918 install_element(BGP_IPV6_NODE,
16919 &no_neighbor_remove_private_as_replace_as_cmd);
16920 install_element(BGP_IPV6_NODE,
16921 &neighbor_remove_private_as_all_replace_as_cmd);
16922 install_element(BGP_IPV6_NODE,
16923 &no_neighbor_remove_private_as_all_replace_as_cmd);
16924 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16925 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16926 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16927 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16928 install_element(BGP_IPV6M_NODE,
16929 &neighbor_remove_private_as_replace_as_cmd);
16930 install_element(BGP_IPV6M_NODE,
16931 &no_neighbor_remove_private_as_replace_as_cmd);
16932 install_element(BGP_IPV6M_NODE,
16933 &neighbor_remove_private_as_all_replace_as_cmd);
16934 install_element(BGP_IPV6M_NODE,
16935 &no_neighbor_remove_private_as_all_replace_as_cmd);
16936 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16937 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16938 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16939 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16940 install_element(BGP_IPV6L_NODE,
16941 &neighbor_remove_private_as_replace_as_cmd);
16942 install_element(BGP_IPV6L_NODE,
16943 &no_neighbor_remove_private_as_replace_as_cmd);
16944 install_element(BGP_IPV6L_NODE,
16945 &neighbor_remove_private_as_all_replace_as_cmd);
16946 install_element(BGP_IPV6L_NODE,
16947 &no_neighbor_remove_private_as_all_replace_as_cmd);
16948 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16949 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16950 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16951 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16952 install_element(BGP_VPNV4_NODE,
16953 &neighbor_remove_private_as_replace_as_cmd);
16954 install_element(BGP_VPNV4_NODE,
16955 &no_neighbor_remove_private_as_replace_as_cmd);
16956 install_element(BGP_VPNV4_NODE,
16957 &neighbor_remove_private_as_all_replace_as_cmd);
16958 install_element(BGP_VPNV4_NODE,
16959 &no_neighbor_remove_private_as_all_replace_as_cmd);
16960 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16961 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16962 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16963 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16964 install_element(BGP_VPNV6_NODE,
16965 &neighbor_remove_private_as_replace_as_cmd);
16966 install_element(BGP_VPNV6_NODE,
16967 &no_neighbor_remove_private_as_replace_as_cmd);
16968 install_element(BGP_VPNV6_NODE,
16969 &neighbor_remove_private_as_all_replace_as_cmd);
16970 install_element(BGP_VPNV6_NODE,
16971 &no_neighbor_remove_private_as_all_replace_as_cmd);
16972
16973 /* "neighbor send-community" commands.*/
16974 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16975 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16976 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16977 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16978 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16979 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16980 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16981 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16982 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16983 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16984 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16985 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16986 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16987 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16988 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16989 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16990 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16991 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16992 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16993 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16994 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16995 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16996 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16997 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16998 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
16999 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17000 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17001 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17002 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17003 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17004 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17005 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17006 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17007 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17008 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
17009 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
17010
17011 /* "neighbor route-reflector" commands.*/
17012 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
17013 install_element(BGP_NODE,
17014 &no_neighbor_route_reflector_client_hidden_cmd);
17015 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
17016 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
17017 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
17018 install_element(BGP_IPV4M_NODE,
17019 &no_neighbor_route_reflector_client_cmd);
17020 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
17021 install_element(BGP_IPV4L_NODE,
17022 &no_neighbor_route_reflector_client_cmd);
17023 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
17024 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
17025 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
17026 install_element(BGP_IPV6M_NODE,
17027 &no_neighbor_route_reflector_client_cmd);
17028 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
17029 install_element(BGP_IPV6L_NODE,
17030 &no_neighbor_route_reflector_client_cmd);
17031 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
17032 install_element(BGP_VPNV4_NODE,
17033 &no_neighbor_route_reflector_client_cmd);
17034 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
17035 install_element(BGP_VPNV6_NODE,
17036 &no_neighbor_route_reflector_client_cmd);
7c40bf39 17037 install_element(BGP_FLOWSPECV4_NODE,
17038 &neighbor_route_reflector_client_cmd);
17039 install_element(BGP_FLOWSPECV4_NODE,
17040 &no_neighbor_route_reflector_client_cmd);
17041 install_element(BGP_FLOWSPECV6_NODE,
17042 &neighbor_route_reflector_client_cmd);
17043 install_element(BGP_FLOWSPECV6_NODE,
17044 &no_neighbor_route_reflector_client_cmd);
d62a17ae 17045 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
17046 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
17047
17048 /* "neighbor route-server" commands.*/
17049 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
17050 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
17051 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
17052 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
17053 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
17054 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
17055 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
17056 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
17057 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
17058 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
17059 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
17060 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
17061 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
17062 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
17063 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
17064 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
17065 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
17066 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
17067 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
17068 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 17069 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
17070 install_element(BGP_FLOWSPECV4_NODE,
17071 &no_neighbor_route_server_client_cmd);
17072 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
17073 install_element(BGP_FLOWSPECV6_NODE,
17074 &no_neighbor_route_server_client_cmd);
d62a17ae 17075
17076 /* "neighbor addpath-tx-all-paths" commands.*/
17077 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
17078 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
17079 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17080 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17081 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17082 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17083 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17084 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17085 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17086 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17087 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17088 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17089 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17090 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17091 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17092 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17093 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17094 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17095
17096 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
17097 install_element(BGP_NODE,
17098 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17099 install_element(BGP_NODE,
17100 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17101 install_element(BGP_IPV4_NODE,
17102 &neighbor_addpath_tx_bestpath_per_as_cmd);
17103 install_element(BGP_IPV4_NODE,
17104 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17105 install_element(BGP_IPV4M_NODE,
17106 &neighbor_addpath_tx_bestpath_per_as_cmd);
17107 install_element(BGP_IPV4M_NODE,
17108 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17109 install_element(BGP_IPV4L_NODE,
17110 &neighbor_addpath_tx_bestpath_per_as_cmd);
17111 install_element(BGP_IPV4L_NODE,
17112 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17113 install_element(BGP_IPV6_NODE,
17114 &neighbor_addpath_tx_bestpath_per_as_cmd);
17115 install_element(BGP_IPV6_NODE,
17116 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17117 install_element(BGP_IPV6M_NODE,
17118 &neighbor_addpath_tx_bestpath_per_as_cmd);
17119 install_element(BGP_IPV6M_NODE,
17120 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17121 install_element(BGP_IPV6L_NODE,
17122 &neighbor_addpath_tx_bestpath_per_as_cmd);
17123 install_element(BGP_IPV6L_NODE,
17124 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17125 install_element(BGP_VPNV4_NODE,
17126 &neighbor_addpath_tx_bestpath_per_as_cmd);
17127 install_element(BGP_VPNV4_NODE,
17128 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17129 install_element(BGP_VPNV6_NODE,
17130 &neighbor_addpath_tx_bestpath_per_as_cmd);
17131 install_element(BGP_VPNV6_NODE,
17132 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17133
2b31007c
RZ
17134 /* "neighbor sender-as-path-loop-detection" commands. */
17135 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
17136 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
17137
d62a17ae 17138 /* "neighbor passive" commands. */
17139 install_element(BGP_NODE, &neighbor_passive_cmd);
17140 install_element(BGP_NODE, &no_neighbor_passive_cmd);
17141
17142
17143 /* "neighbor shutdown" commands. */
17144 install_element(BGP_NODE, &neighbor_shutdown_cmd);
17145 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
17146 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
17147 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
17148 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
17149 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 17150
17151 /* "neighbor capability extended-nexthop" commands.*/
17152 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
17153 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
17154
17155 /* "neighbor capability orf prefix-list" commands.*/
17156 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
17157 install_element(BGP_NODE,
17158 &no_neighbor_capability_orf_prefix_hidden_cmd);
17159 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
17160 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
17161 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
17162 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17163 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
17164 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17165 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
17166 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
17167 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
17168 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17169 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
17170 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17171
17172 /* "neighbor capability dynamic" commands.*/
17173 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
17174 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
17175
17176 /* "neighbor dont-capability-negotiate" commands. */
17177 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
17178 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
17179
17180 /* "neighbor ebgp-multihop" commands. */
17181 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
17182 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
17183 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
17184
17185 /* "neighbor disable-connected-check" commands. */
17186 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
17187 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
17188
47cbc09b
PM
17189 /* "neighbor enforce-first-as" commands. */
17190 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
17191 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
17192
d62a17ae 17193 /* "neighbor description" commands. */
17194 install_element(BGP_NODE, &neighbor_description_cmd);
17195 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 17196 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 17197
17198 /* "neighbor update-source" commands. "*/
17199 install_element(BGP_NODE, &neighbor_update_source_cmd);
17200 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
17201
17202 /* "neighbor default-originate" commands. */
17203 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
17204 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
17205 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
17206 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
17207 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
17208 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
17209 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
17210 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
17211 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
17212 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
17213 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
17214 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
17215 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
17216 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
17217 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
17218 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
17219 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
17220 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
17221 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
17222 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
17223 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
17224
17225 /* "neighbor port" commands. */
17226 install_element(BGP_NODE, &neighbor_port_cmd);
17227 install_element(BGP_NODE, &no_neighbor_port_cmd);
17228
17229 /* "neighbor weight" commands. */
17230 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
17231 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
17232
17233 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
17234 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
17235 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
17236 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
17237 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
17238 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
17239 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
17240 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
17241 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
17242 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
17243 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
17244 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
17245 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
17246 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
17247 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
17248 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
17249
17250 /* "neighbor override-capability" commands. */
17251 install_element(BGP_NODE, &neighbor_override_capability_cmd);
17252 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
17253
17254 /* "neighbor strict-capability-match" commands. */
17255 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
17256 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
17257
17258 /* "neighbor timers" commands. */
17259 install_element(BGP_NODE, &neighbor_timers_cmd);
17260 install_element(BGP_NODE, &no_neighbor_timers_cmd);
17261
17262 /* "neighbor timers connect" commands. */
17263 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
17264 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
17265
17266 /* "neighbor advertisement-interval" commands. */
17267 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
17268 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
17269
17270 /* "neighbor interface" commands. */
17271 install_element(BGP_NODE, &neighbor_interface_cmd);
17272 install_element(BGP_NODE, &no_neighbor_interface_cmd);
17273
17274 /* "neighbor distribute" commands. */
17275 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
17276 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
17277 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
17278 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
17279 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
17280 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
17281 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
17282 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
17283 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
17284 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
17285 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
17286 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
17287 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
17288 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
17289 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
17290 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
17291 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
17292 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
17293
17294 /* "neighbor prefix-list" commands. */
17295 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
17296 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
17297 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
17298 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
17299 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
17300 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
17301 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
17302 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
17303 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
17304 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
17305 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
17306 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
17307 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
17308 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
17309 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
17310 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
17311 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
17312 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 17313 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
17314 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
17315 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
17316 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 17317
17318 /* "neighbor filter-list" commands. */
17319 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
17320 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
17321 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
17322 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
17323 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
17324 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
17325 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
17326 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
17327 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
17328 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
17329 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
17330 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
17331 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
17332 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
17333 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
17334 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
17335 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
17336 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 17337 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
17338 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
17339 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
17340 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 17341
17342 /* "neighbor route-map" commands. */
17343 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
17344 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
17345 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
17346 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
17347 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
17348 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
17349 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
17350 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
17351 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
17352 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
17353 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
17354 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
17355 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
17356 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
17357 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
17358 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
17359 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
17360 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 17361 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
17362 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
17363 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
17364 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
17365 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
17366 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 17367
17368 /* "neighbor unsuppress-map" commands. */
17369 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
17370 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
17371 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
17372 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
17373 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
17374 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
17375 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
17376 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
17377 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
17378 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
17379 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
17380 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
17381 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
17382 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
17383 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
17384 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
17385 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
17386 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
17387
fde246e8
DA
17388 /* neighbor maximum-prefix-out commands. */
17389 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
17390 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
17391 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
17392 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17393 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
17394 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17395 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
17396 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17397 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
17398 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17399 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
17400 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17401 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
17402 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17403 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
17404 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17405 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
17406 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17407
d62a17ae 17408 /* "neighbor maximum-prefix" commands. */
17409 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
17410 install_element(BGP_NODE,
17411 &neighbor_maximum_prefix_threshold_hidden_cmd);
17412 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
17413 install_element(BGP_NODE,
17414 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
17415 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
17416 install_element(BGP_NODE,
17417 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
17418 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
17419 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
17420 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17421 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17422 install_element(BGP_IPV4_NODE,
17423 &neighbor_maximum_prefix_threshold_warning_cmd);
17424 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17425 install_element(BGP_IPV4_NODE,
17426 &neighbor_maximum_prefix_threshold_restart_cmd);
17427 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
17428 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
17429 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17430 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
17431 install_element(BGP_IPV4M_NODE,
17432 &neighbor_maximum_prefix_threshold_warning_cmd);
17433 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
17434 install_element(BGP_IPV4M_NODE,
17435 &neighbor_maximum_prefix_threshold_restart_cmd);
17436 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
17437 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
17438 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17439 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
17440 install_element(BGP_IPV4L_NODE,
17441 &neighbor_maximum_prefix_threshold_warning_cmd);
17442 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
17443 install_element(BGP_IPV4L_NODE,
17444 &neighbor_maximum_prefix_threshold_restart_cmd);
17445 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
17446 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
17447 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17448 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17449 install_element(BGP_IPV6_NODE,
17450 &neighbor_maximum_prefix_threshold_warning_cmd);
17451 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17452 install_element(BGP_IPV6_NODE,
17453 &neighbor_maximum_prefix_threshold_restart_cmd);
17454 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
17455 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
17456 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17457 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
17458 install_element(BGP_IPV6M_NODE,
17459 &neighbor_maximum_prefix_threshold_warning_cmd);
17460 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
17461 install_element(BGP_IPV6M_NODE,
17462 &neighbor_maximum_prefix_threshold_restart_cmd);
17463 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
17464 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
17465 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17466 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
17467 install_element(BGP_IPV6L_NODE,
17468 &neighbor_maximum_prefix_threshold_warning_cmd);
17469 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
17470 install_element(BGP_IPV6L_NODE,
17471 &neighbor_maximum_prefix_threshold_restart_cmd);
17472 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
17473 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
17474 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17475 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17476 install_element(BGP_VPNV4_NODE,
17477 &neighbor_maximum_prefix_threshold_warning_cmd);
17478 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17479 install_element(BGP_VPNV4_NODE,
17480 &neighbor_maximum_prefix_threshold_restart_cmd);
17481 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
17482 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
17483 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17484 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17485 install_element(BGP_VPNV6_NODE,
17486 &neighbor_maximum_prefix_threshold_warning_cmd);
17487 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17488 install_element(BGP_VPNV6_NODE,
17489 &neighbor_maximum_prefix_threshold_restart_cmd);
17490 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
17491
17492 /* "neighbor allowas-in" */
17493 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
17494 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
17495 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
17496 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
17497 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
17498 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
17499 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
17500 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
17501 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
17502 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
17503 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
17504 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
17505 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
17506 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
17507 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
17508 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
17509 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
17510 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
17511 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
17512 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
17513
17514 /* address-family commands. */
17515 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
17516 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 17517#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 17518 install_element(BGP_NODE, &address_family_vpnv4_cmd);
17519 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 17520#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 17521
d62a17ae 17522 install_element(BGP_NODE, &address_family_evpn_cmd);
17523
17524 /* "exit-address-family" command. */
17525 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
17526 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
17527 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
17528 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
17529 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
17530 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17531 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17532 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 17533 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17534 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 17535 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17536
17537 /* "clear ip bgp commands" */
17538 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17539
17540 /* clear ip bgp prefix */
17541 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17542 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17543 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17544
17545 /* "show [ip] bgp summary" commands. */
17546 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 17547 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 17548 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 17549 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 17550 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17551 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 17552 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17553
17554 /* "show [ip] bgp neighbors" commands. */
17555 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17556
36235319 17557 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 17558
d62a17ae 17559 /* "show [ip] bgp peer-group" commands. */
17560 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17561
17562 /* "show [ip] bgp paths" commands. */
17563 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17564
17565 /* "show [ip] bgp community" commands. */
17566 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17567
17568 /* "show ip bgp large-community" commands. */
17569 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17570 /* "show [ip] bgp attribute-info" commands. */
17571 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 17572 /* "show [ip] bgp route-leak" command */
17573 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 17574
17575 /* "redistribute" commands. */
17576 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17577 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17578 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17579 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17580 install_element(BGP_NODE,
17581 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17582 install_element(BGP_NODE,
17583 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17584 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17585 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17586 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17587 install_element(BGP_NODE,
17588 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17589 install_element(BGP_NODE,
17590 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17591 install_element(BGP_NODE,
17592 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17593 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17594 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17595 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17596 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17600 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17601 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17602 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17603 install_element(BGP_IPV4_NODE,
17604 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17605 install_element(BGP_IPV4_NODE,
17606 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17607 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17608 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17609 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17610 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17612 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17613
b9c7bc5a
PZ
17614 /* import|export vpn [route-map WORD] */
17615 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17616 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17617
12a844a5
DS
17618 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17619 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17620
d62a17ae 17621 /* ttl_security commands */
17622 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17623 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17624
17625 /* "show [ip] bgp memory" commands. */
17626 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17627
acf71666
MK
17628 /* "show bgp martian next-hop" */
17629 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17630
48ecf8f5
DS
17631 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17632
d62a17ae 17633 /* "show [ip] bgp views" commands. */
17634 install_element(VIEW_NODE, &show_bgp_views_cmd);
17635
17636 /* "show [ip] bgp vrfs" commands. */
17637 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17638
17639 /* Community-list. */
17640 community_list_vty();
ddb5b488
PZ
17641
17642 /* vpn-policy commands */
b9c7bc5a
PZ
17643 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17644 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17645 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17646 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17647 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17648 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17649 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17650 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17651 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17652 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17653 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17654 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17655
301ad80a
PG
17656 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17657 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17658
b9c7bc5a
PZ
17659 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17660 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17661 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17662 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17663 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17664 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17665 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17666 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17667 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17668 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17669}
6b0655a2 17670
718e3744 17671#include "memory.h"
17672#include "bgp_regex.h"
17673#include "bgp_clist.h"
17674#include "bgp_ecommunity.h"
17675
17676/* VTY functions. */
17677
17678/* Direction value to string conversion. */
d62a17ae 17679static const char *community_direct_str(int direct)
17680{
17681 switch (direct) {
17682 case COMMUNITY_DENY:
17683 return "deny";
17684 case COMMUNITY_PERMIT:
17685 return "permit";
17686 default:
17687 return "unknown";
17688 }
718e3744 17689}
17690
17691/* Display error string. */
d62a17ae 17692static void community_list_perror(struct vty *vty, int ret)
17693{
17694 switch (ret) {
17695 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17696 vty_out(vty, "%% Can't find community-list\n");
17697 break;
17698 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17699 vty_out(vty, "%% Malformed community-list value\n");
17700 break;
17701 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17702 vty_out(vty,
17703 "%% Community name conflict, previously defined as standard community\n");
17704 break;
17705 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17706 vty_out(vty,
17707 "%% Community name conflict, previously defined as expanded community\n");
17708 break;
17709 }
718e3744 17710}
17711
5bf15956
DW
17712/* "community-list" keyword help string. */
17713#define COMMUNITY_LIST_STR "Add a community list entry\n"
17714
7336e101
SP
17715/*community-list standard */
17716DEFUN (community_list_standard,
17717 bgp_community_list_standard_cmd,
2f8cc0e5 17718 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17719 BGP_STR
718e3744 17720 COMMUNITY_LIST_STR
17721 "Community list number (standard)\n"
5bf15956 17722 "Add an standard community-list entry\n"
718e3744 17723 "Community list name\n"
2f8cc0e5
DA
17724 "Sequence number of an entry\n"
17725 "Sequence number\n"
718e3744 17726 "Specify community to reject\n"
17727 "Specify community to accept\n"
17728 COMMUNITY_VAL_STR)
17729{
d62a17ae 17730 char *cl_name_or_number = NULL;
2f8cc0e5 17731 char *seq = NULL;
d62a17ae 17732 int direct = 0;
17733 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17734 int idx = 0;
7336e101 17735
2f8cc0e5
DA
17736 argv_find(argv, argc, "(1-4294967295)", &idx);
17737 if (idx)
17738 seq = argv[idx]->arg;
17739
17740 idx = 0;
d62a17ae 17741 argv_find(argv, argc, "(1-99)", &idx);
17742 argv_find(argv, argc, "WORD", &idx);
17743 cl_name_or_number = argv[idx]->arg;
17744 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17745 : COMMUNITY_DENY;
17746 argv_find(argv, argc, "AA:NN", &idx);
17747 char *str = argv_concat(argv, argc, idx);
42f914d4 17748
2f8cc0e5
DA
17749 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17750 direct, style);
42f914d4 17751
d62a17ae 17752 XFREE(MTYPE_TMP, str);
42f914d4 17753
d62a17ae 17754 if (ret < 0) {
17755 /* Display error string. */
17756 community_list_perror(vty, ret);
17757 return CMD_WARNING_CONFIG_FAILED;
17758 }
42f914d4 17759
d62a17ae 17760 return CMD_SUCCESS;
718e3744 17761}
17762
7336e101
SP
17763DEFUN (no_community_list_standard_all,
17764 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 17765 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17766 NO_STR
17767 BGP_STR
17768 COMMUNITY_LIST_STR
17769 "Community list number (standard)\n"
17770 "Add an standard community-list entry\n"
17771 "Community list name\n"
2f8cc0e5
DA
17772 "Sequence number of an entry\n"
17773 "Sequence number\n"
7336e101
SP
17774 "Specify community to reject\n"
17775 "Specify community to accept\n"
17776 COMMUNITY_VAL_STR)
718e3744 17777{
d62a17ae 17778 char *cl_name_or_number = NULL;
174b5cb9 17779 char *str = NULL;
d62a17ae 17780 int direct = 0;
17781 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 17782 char *seq = NULL;
d62a17ae 17783 int idx = 0;
7336e101 17784
2f8cc0e5
DA
17785 argv_find(argv, argc, "(1-4294967295)", &idx);
17786 if (idx)
17787 seq = argv[idx]->arg;
17788
17789 idx = 0;
174b5cb9
DA
17790 argv_find(argv, argc, "permit", &idx);
17791 argv_find(argv, argc, "deny", &idx);
17792
17793 if (idx) {
17794 direct = argv_find(argv, argc, "permit", &idx)
17795 ? COMMUNITY_PERMIT
17796 : COMMUNITY_DENY;
17797
17798 idx = 0;
17799 argv_find(argv, argc, "AA:NN", &idx);
17800 str = argv_concat(argv, argc, idx);
17801 }
17802
17803 idx = 0;
d62a17ae 17804 argv_find(argv, argc, "(1-99)", &idx);
17805 argv_find(argv, argc, "WORD", &idx);
17806 cl_name_or_number = argv[idx]->arg;
42f914d4 17807
2f8cc0e5 17808 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17809 direct, style);
42f914d4 17810
d62a17ae 17811 XFREE(MTYPE_TMP, str);
daf9ddbb 17812
d62a17ae 17813 if (ret < 0) {
17814 community_list_perror(vty, ret);
17815 return CMD_WARNING_CONFIG_FAILED;
17816 }
42f914d4 17817
d62a17ae 17818 return CMD_SUCCESS;
718e3744 17819}
7336e101 17820
174b5cb9
DA
17821ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17822 "no bgp community-list <(1-99)|standard WORD>",
17823 NO_STR BGP_STR COMMUNITY_LIST_STR
17824 "Community list number (standard)\n"
17825 "Add an standard community-list entry\n"
17826 "Community list name\n")
17827
7336e101
SP
17828/*community-list expanded */
17829DEFUN (community_list_expanded_all,
17830 bgp_community_list_expanded_all_cmd,
2f8cc0e5 17831 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17832 BGP_STR
17833 COMMUNITY_LIST_STR
718e3744 17834 "Community list number (expanded)\n"
5bf15956 17835 "Add an expanded community-list entry\n"
718e3744 17836 "Community list name\n"
2f8cc0e5
DA
17837 "Sequence number of an entry\n"
17838 "Sequence number\n"
718e3744 17839 "Specify community to reject\n"
17840 "Specify community to accept\n"
17841 COMMUNITY_VAL_STR)
17842{
d62a17ae 17843 char *cl_name_or_number = NULL;
2f8cc0e5 17844 char *seq = NULL;
d62a17ae 17845 int direct = 0;
17846 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17847 int idx = 0;
7b9a4750 17848
2f8cc0e5
DA
17849 argv_find(argv, argc, "(1-4294967295)", &idx);
17850 if (idx)
17851 seq = argv[idx]->arg;
17852
17853 idx = 0;
17854
d62a17ae 17855 argv_find(argv, argc, "(100-500)", &idx);
17856 argv_find(argv, argc, "WORD", &idx);
17857 cl_name_or_number = argv[idx]->arg;
17858 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17859 : COMMUNITY_DENY;
17860 argv_find(argv, argc, "AA:NN", &idx);
17861 char *str = argv_concat(argv, argc, idx);
42f914d4 17862
2f8cc0e5
DA
17863 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17864 direct, style);
42f914d4 17865
d62a17ae 17866 XFREE(MTYPE_TMP, str);
42f914d4 17867
d62a17ae 17868 if (ret < 0) {
17869 /* Display error string. */
17870 community_list_perror(vty, ret);
17871 return CMD_WARNING_CONFIG_FAILED;
17872 }
42f914d4 17873
d62a17ae 17874 return CMD_SUCCESS;
718e3744 17875}
17876
7336e101
SP
17877DEFUN (no_community_list_expanded_all,
17878 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 17879 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17880 NO_STR
17881 BGP_STR
17882 COMMUNITY_LIST_STR
17883 "Community list number (expanded)\n"
17884 "Add an expanded community-list entry\n"
17885 "Community list name\n"
2f8cc0e5
DA
17886 "Sequence number of an entry\n"
17887 "Sequence number\n"
7336e101
SP
17888 "Specify community to reject\n"
17889 "Specify community to accept\n"
17890 COMMUNITY_VAL_STR)
718e3744 17891{
d62a17ae 17892 char *cl_name_or_number = NULL;
2f8cc0e5 17893 char *seq = NULL;
174b5cb9 17894 char *str = NULL;
d62a17ae 17895 int direct = 0;
17896 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17897 int idx = 0;
174b5cb9 17898
2f8cc0e5
DA
17899 argv_find(argv, argc, "(1-4294967295)", &idx);
17900 if (idx)
17901 seq = argv[idx]->arg;
17902
17903 idx = 0;
174b5cb9
DA
17904 argv_find(argv, argc, "permit", &idx);
17905 argv_find(argv, argc, "deny", &idx);
17906
17907 if (idx) {
17908 direct = argv_find(argv, argc, "permit", &idx)
17909 ? COMMUNITY_PERMIT
17910 : COMMUNITY_DENY;
17911
17912 idx = 0;
17913 argv_find(argv, argc, "AA:NN", &idx);
17914 str = argv_concat(argv, argc, idx);
7336e101 17915 }
174b5cb9
DA
17916
17917 idx = 0;
d62a17ae 17918 argv_find(argv, argc, "(100-500)", &idx);
17919 argv_find(argv, argc, "WORD", &idx);
17920 cl_name_or_number = argv[idx]->arg;
42f914d4 17921
2f8cc0e5 17922 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17923 direct, style);
42f914d4 17924
d62a17ae 17925 XFREE(MTYPE_TMP, str);
daf9ddbb 17926
d62a17ae 17927 if (ret < 0) {
17928 community_list_perror(vty, ret);
17929 return CMD_WARNING_CONFIG_FAILED;
17930 }
42f914d4 17931
d62a17ae 17932 return CMD_SUCCESS;
718e3744 17933}
17934
174b5cb9
DA
17935ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17936 "no bgp community-list <(100-500)|expanded WORD>",
17937 NO_STR IP_STR COMMUNITY_LIST_STR
17938 "Community list number (expanded)\n"
17939 "Add an expanded community-list entry\n"
17940 "Community list name\n")
17941
8d9b8ed9
PM
17942/* Return configuration string of community-list entry. */
17943static const char *community_list_config_str(struct community_entry *entry)
17944{
17945 const char *str;
17946
17947 if (entry->any)
17948 str = "";
17949 else {
17950 if (entry->style == COMMUNITY_LIST_STANDARD)
17951 str = community_str(entry->u.com, false);
17952 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17953 str = lcommunity_str(entry->u.lcom, false);
17954 else
17955 str = entry->config;
17956 }
17957 return str;
17958}
17959
d62a17ae 17960static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17961{
d62a17ae 17962 struct community_entry *entry;
718e3744 17963
d62a17ae 17964 for (entry = list->head; entry; entry = entry->next) {
17965 if (entry == list->head) {
17966 if (all_digit(list->name))
17967 vty_out(vty, "Community %s list %s\n",
17968 entry->style == COMMUNITY_LIST_STANDARD
17969 ? "standard"
17970 : "(expanded) access",
17971 list->name);
17972 else
17973 vty_out(vty, "Named Community %s list %s\n",
17974 entry->style == COMMUNITY_LIST_STANDARD
17975 ? "standard"
17976 : "expanded",
17977 list->name);
17978 }
17979 if (entry->any)
17980 vty_out(vty, " %s\n",
17981 community_direct_str(entry->direct));
17982 else
17983 vty_out(vty, " %s %s\n",
17984 community_direct_str(entry->direct),
8d9b8ed9 17985 community_list_config_str(entry));
d62a17ae 17986 }
718e3744 17987}
17988
7336e101
SP
17989DEFUN (show_community_list,
17990 show_bgp_community_list_cmd,
17991 "show bgp community-list",
718e3744 17992 SHOW_STR
7336e101 17993 BGP_STR
718e3744 17994 "List community-list\n")
17995{
d62a17ae 17996 struct community_list *list;
17997 struct community_list_master *cm;
718e3744 17998
d62a17ae 17999 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18000 if (!cm)
18001 return CMD_SUCCESS;
718e3744 18002
d62a17ae 18003 for (list = cm->num.head; list; list = list->next)
18004 community_list_show(vty, list);
718e3744 18005
d62a17ae 18006 for (list = cm->str.head; list; list = list->next)
18007 community_list_show(vty, list);
718e3744 18008
d62a17ae 18009 return CMD_SUCCESS;
718e3744 18010}
18011
7336e101
SP
18012DEFUN (show_community_list_arg,
18013 show_bgp_community_list_arg_cmd,
960b69b9 18014 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
18015 SHOW_STR
18016 BGP_STR
718e3744 18017 "List community-list\n"
18018 "Community-list number\n"
960b69b9 18019 "Community-list name\n"
18020 "Detailed information on community-list\n")
718e3744 18021{
d62a17ae 18022 int idx_comm_list = 3;
18023 struct community_list *list;
718e3744 18024
e237b0d2 18025 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18026 COMMUNITY_LIST_MASTER);
18027 if (!list) {
18028 vty_out(vty, "%% Can't find community-list\n");
18029 return CMD_WARNING;
18030 }
718e3744 18031
d62a17ae 18032 community_list_show(vty, list);
718e3744 18033
d62a17ae 18034 return CMD_SUCCESS;
718e3744 18035}
6b0655a2 18036
57d187bc
JS
18037/*
18038 * Large Community code.
18039 */
d62a17ae 18040static int lcommunity_list_set_vty(struct vty *vty, int argc,
18041 struct cmd_token **argv, int style,
18042 int reject_all_digit_name)
18043{
18044 int ret;
18045 int direct;
18046 char *str;
18047 int idx = 0;
18048 char *cl_name;
2f8cc0e5
DA
18049 char *seq = NULL;
18050
947073e3 18051 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18052 seq = argv[idx]->arg;
d62a17ae 18053
2f8cc0e5 18054 idx = 0;
d62a17ae 18055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18056 : COMMUNITY_DENY;
18057
18058 /* All digit name check. */
18059 idx = 0;
18060 argv_find(argv, argc, "WORD", &idx);
18061 argv_find(argv, argc, "(1-99)", &idx);
18062 argv_find(argv, argc, "(100-500)", &idx);
18063 cl_name = argv[idx]->arg;
18064 if (reject_all_digit_name && all_digit(cl_name)) {
18065 vty_out(vty, "%% Community name cannot have all digits\n");
18066 return CMD_WARNING_CONFIG_FAILED;
18067 }
18068
18069 idx = 0;
18070 argv_find(argv, argc, "AA:BB:CC", &idx);
18071 argv_find(argv, argc, "LINE", &idx);
18072 /* Concat community string argument. */
18073 if (idx)
18074 str = argv_concat(argv, argc, idx);
18075 else
18076 str = NULL;
18077
2f8cc0e5 18078 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 18079
18080 /* Free temporary community list string allocated by
18081 argv_concat(). */
0a22ddfb 18082 XFREE(MTYPE_TMP, str);
d62a17ae 18083
18084 if (ret < 0) {
18085 community_list_perror(vty, ret);
18086 return CMD_WARNING_CONFIG_FAILED;
18087 }
18088 return CMD_SUCCESS;
18089}
18090
18091static int lcommunity_list_unset_vty(struct vty *vty, int argc,
18092 struct cmd_token **argv, int style)
18093{
18094 int ret;
18095 int direct = 0;
18096 char *str = NULL;
18097 int idx = 0;
2f8cc0e5 18098 char *seq = NULL;
d62a17ae 18099
947073e3 18100 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18101 seq = argv[idx]->arg;
d62a17ae 18102
2f8cc0e5 18103 idx = 0;
d62a17ae 18104 argv_find(argv, argc, "permit", &idx);
18105 argv_find(argv, argc, "deny", &idx);
18106
18107 if (idx) {
18108 /* Check the list direct. */
18109 if (strncmp(argv[idx]->arg, "p", 1) == 0)
18110 direct = COMMUNITY_PERMIT;
18111 else
18112 direct = COMMUNITY_DENY;
18113
18114 idx = 0;
18115 argv_find(argv, argc, "LINE", &idx);
18116 argv_find(argv, argc, "AA:AA:NN", &idx);
18117 /* Concat community string argument. */
18118 str = argv_concat(argv, argc, idx);
18119 }
18120
18121 idx = 0;
18122 argv_find(argv, argc, "(1-99)", &idx);
18123 argv_find(argv, argc, "(100-500)", &idx);
18124 argv_find(argv, argc, "WORD", &idx);
18125
18126 /* Unset community list. */
2f8cc0e5 18127 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 18128 style);
18129
18130 /* Free temporary community list string allocated by
18131 argv_concat(). */
0a22ddfb 18132 XFREE(MTYPE_TMP, str);
d62a17ae 18133
18134 if (ret < 0) {
18135 community_list_perror(vty, ret);
18136 return CMD_WARNING_CONFIG_FAILED;
18137 }
18138
18139 return CMD_SUCCESS;
57d187bc
JS
18140}
18141
18142/* "large-community-list" keyword help string. */
18143#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
18144#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
18145
7336e101
SP
18146DEFUN (lcommunity_list_standard,
18147 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18148 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18149 BGP_STR
18150 LCOMMUNITY_LIST_STR
18151 "Large Community list number (standard)\n"
2f8cc0e5
DA
18152 "Sequence number of an entry\n"
18153 "Sequence number\n"
7336e101
SP
18154 "Specify large community to reject\n"
18155 "Specify large community to accept\n"
18156 LCOMMUNITY_VAL_STR)
52951b63 18157{
d62a17ae 18158 return lcommunity_list_set_vty(vty, argc, argv,
18159 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
18160}
18161
7336e101
SP
18162DEFUN (lcommunity_list_expanded,
18163 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18164 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18165 BGP_STR
18166 LCOMMUNITY_LIST_STR
18167 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18168 "Sequence number of an entry\n"
18169 "Sequence number\n"
7336e101
SP
18170 "Specify large community to reject\n"
18171 "Specify large community to accept\n"
18172 "An ordered list as a regular-expression\n")
57d187bc 18173{
d62a17ae 18174 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18175 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
18176}
18177
7336e101
SP
18178DEFUN (lcommunity_list_name_standard,
18179 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18180 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18181 BGP_STR
18182 LCOMMUNITY_LIST_STR
18183 "Specify standard large-community-list\n"
18184 "Large Community list name\n"
2f8cc0e5
DA
18185 "Sequence number of an entry\n"
18186 "Sequence number\n"
7336e101
SP
18187 "Specify large community to reject\n"
18188 "Specify large community to accept\n"
18189 LCOMMUNITY_VAL_STR)
52951b63 18190{
d62a17ae 18191 return lcommunity_list_set_vty(vty, argc, argv,
18192 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
18193}
18194
7336e101
SP
18195DEFUN (lcommunity_list_name_expanded,
18196 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18197 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18198 BGP_STR
18199 LCOMMUNITY_LIST_STR
18200 "Specify expanded large-community-list\n"
18201 "Large Community list name\n"
2f8cc0e5
DA
18202 "Sequence number of an entry\n"
18203 "Sequence number\n"
7336e101
SP
18204 "Specify large community to reject\n"
18205 "Specify large community to accept\n"
18206 "An ordered list as a regular-expression\n")
57d187bc 18207{
d62a17ae 18208 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18209 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
18210}
18211
4378f57c
DA
18212DEFUN (no_lcommunity_list_all,
18213 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
18214 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
18215 NO_STR
18216 BGP_STR
18217 LCOMMUNITY_LIST_STR
18218 "Large Community list number (standard)\n"
18219 "Large Community list number (expanded)\n"
18220 "Large Community list name\n")
57d187bc 18221{
7336e101
SP
18222 return lcommunity_list_unset_vty(vty, argc, argv,
18223 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18224}
18225
4378f57c
DA
18226DEFUN (no_lcommunity_list_name_standard_all,
18227 no_bgp_lcommunity_list_name_standard_all_cmd,
18228 "no bgp large-community-list standard WORD",
18229 NO_STR
18230 BGP_STR
18231 LCOMMUNITY_LIST_STR
18232 "Specify standard large-community-list\n"
18233 "Large Community list name\n")
18234{
18235 return lcommunity_list_unset_vty(vty, argc, argv,
18236 LARGE_COMMUNITY_LIST_STANDARD);
18237}
18238
7336e101
SP
18239DEFUN (no_lcommunity_list_name_expanded_all,
18240 no_bgp_lcommunity_list_name_expanded_all_cmd,
18241 "no bgp large-community-list expanded WORD",
18242 NO_STR
18243 BGP_STR
18244 LCOMMUNITY_LIST_STR
18245 "Specify expanded large-community-list\n"
18246 "Large Community list name\n")
57d187bc 18247{
d62a17ae 18248 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18249 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18250}
18251
7336e101
SP
18252DEFUN (no_lcommunity_list_standard,
18253 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18254 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18255 NO_STR
18256 BGP_STR
18257 LCOMMUNITY_LIST_STR
18258 "Large Community list number (standard)\n"
2f8cc0e5
DA
18259 "Sequence number of an entry\n"
18260 "Sequence number\n"
7336e101
SP
18261 "Specify large community to reject\n"
18262 "Specify large community to accept\n"
18263 LCOMMUNITY_VAL_STR)
57d187bc 18264{
d62a17ae 18265 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18266 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18267}
18268
7336e101
SP
18269DEFUN (no_lcommunity_list_expanded,
18270 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18271 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18272 NO_STR
18273 BGP_STR
18274 LCOMMUNITY_LIST_STR
18275 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18276 "Sequence number of an entry\n"
18277 "Sequence number\n"
7336e101
SP
18278 "Specify large community to reject\n"
18279 "Specify large community to accept\n"
18280 "An ordered list as a regular-expression\n")
57d187bc 18281{
d62a17ae 18282 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18283 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18284}
18285
7336e101
SP
18286DEFUN (no_lcommunity_list_name_standard,
18287 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18288 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18289 NO_STR
18290 BGP_STR
18291 LCOMMUNITY_LIST_STR
18292 "Specify standard large-community-list\n"
18293 "Large Community list name\n"
2f8cc0e5
DA
18294 "Sequence number of an entry\n"
18295 "Sequence number\n"
7336e101
SP
18296 "Specify large community to reject\n"
18297 "Specify large community to accept\n"
18298 LCOMMUNITY_VAL_STR)
57d187bc 18299{
d62a17ae 18300 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18301 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18302}
18303
7336e101
SP
18304DEFUN (no_lcommunity_list_name_expanded,
18305 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18306 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18307 NO_STR
18308 BGP_STR
18309 LCOMMUNITY_LIST_STR
18310 "Specify expanded large-community-list\n"
18311 "Large community list name\n"
2f8cc0e5
DA
18312 "Sequence number of an entry\n"
18313 "Sequence number\n"
7336e101
SP
18314 "Specify large community to reject\n"
18315 "Specify large community to accept\n"
18316 "An ordered list as a regular-expression\n")
57d187bc 18317{
d62a17ae 18318 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18319 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18320}
18321
d62a17ae 18322static void lcommunity_list_show(struct vty *vty, struct community_list *list)
18323{
18324 struct community_entry *entry;
18325
18326 for (entry = list->head; entry; entry = entry->next) {
18327 if (entry == list->head) {
18328 if (all_digit(list->name))
18329 vty_out(vty, "Large community %s list %s\n",
169b72c8 18330 entry->style ==
18331 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18332 ? "standard"
18333 : "(expanded) access",
18334 list->name);
18335 else
18336 vty_out(vty,
18337 "Named large community %s list %s\n",
169b72c8 18338 entry->style ==
18339 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18340 ? "standard"
18341 : "expanded",
18342 list->name);
18343 }
18344 if (entry->any)
18345 vty_out(vty, " %s\n",
18346 community_direct_str(entry->direct));
18347 else
18348 vty_out(vty, " %s %s\n",
18349 community_direct_str(entry->direct),
8d9b8ed9 18350 community_list_config_str(entry));
d62a17ae 18351 }
57d187bc
JS
18352}
18353
7336e101
SP
18354DEFUN (show_lcommunity_list,
18355 show_bgp_lcommunity_list_cmd,
18356 "show bgp large-community-list",
57d187bc 18357 SHOW_STR
7336e101 18358 BGP_STR
57d187bc
JS
18359 "List large-community list\n")
18360{
d62a17ae 18361 struct community_list *list;
18362 struct community_list_master *cm;
57d187bc 18363
d62a17ae 18364 cm = community_list_master_lookup(bgp_clist,
18365 LARGE_COMMUNITY_LIST_MASTER);
18366 if (!cm)
18367 return CMD_SUCCESS;
57d187bc 18368
d62a17ae 18369 for (list = cm->num.head; list; list = list->next)
18370 lcommunity_list_show(vty, list);
57d187bc 18371
d62a17ae 18372 for (list = cm->str.head; list; list = list->next)
18373 lcommunity_list_show(vty, list);
57d187bc 18374
d62a17ae 18375 return CMD_SUCCESS;
57d187bc
JS
18376}
18377
7336e101
SP
18378DEFUN (show_lcommunity_list_arg,
18379 show_bgp_lcommunity_list_arg_cmd,
960b69b9 18380 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
18381 SHOW_STR
18382 BGP_STR
57d187bc 18383 "List large-community list\n"
960b69b9 18384 "Large-community-list number\n"
18385 "Large-community-list name\n"
18386 "Detailed information on large-community-list\n")
57d187bc 18387{
d62a17ae 18388 struct community_list *list;
57d187bc 18389
e237b0d2 18390 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 18391 LARGE_COMMUNITY_LIST_MASTER);
18392 if (!list) {
960b69b9 18393 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 18394 return CMD_WARNING;
18395 }
57d187bc 18396
d62a17ae 18397 lcommunity_list_show(vty, list);
57d187bc 18398
d62a17ae 18399 return CMD_SUCCESS;
57d187bc
JS
18400}
18401
718e3744 18402/* "extcommunity-list" keyword help string. */
18403#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
18404#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
18405
7336e101
SP
18406DEFUN (extcommunity_list_standard,
18407 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 18408 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18409 BGP_STR
718e3744 18410 EXTCOMMUNITY_LIST_STR
18411 "Extended Community list number (standard)\n"
718e3744 18412 "Specify standard extcommunity-list\n"
5bf15956 18413 "Community list name\n"
2f8cc0e5
DA
18414 "Sequence number of an entry\n"
18415 "Sequence number\n"
718e3744 18416 "Specify community to reject\n"
18417 "Specify community to accept\n"
18418 EXTCOMMUNITY_VAL_STR)
18419{
d62a17ae 18420 int style = EXTCOMMUNITY_LIST_STANDARD;
18421 int direct = 0;
18422 char *cl_number_or_name = NULL;
2f8cc0e5 18423 char *seq = NULL;
42f914d4 18424
d62a17ae 18425 int idx = 0;
7b9a4750 18426
d62a17ae 18427 argv_find(argv, argc, "(1-99)", &idx);
18428 argv_find(argv, argc, "WORD", &idx);
18429 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18430
409148f6 18431 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18432 seq = argv[idx]->arg;
18433
d62a17ae 18434 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18435 : COMMUNITY_DENY;
18436 argv_find(argv, argc, "AA:NN", &idx);
18437 char *str = argv_concat(argv, argc, idx);
42f914d4 18438
2f8cc0e5 18439 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18440 direct, style);
42f914d4 18441
d62a17ae 18442 XFREE(MTYPE_TMP, str);
42f914d4 18443
d62a17ae 18444 if (ret < 0) {
18445 community_list_perror(vty, ret);
18446 return CMD_WARNING_CONFIG_FAILED;
18447 }
42f914d4 18448
d62a17ae 18449 return CMD_SUCCESS;
718e3744 18450}
18451
7336e101
SP
18452DEFUN (extcommunity_list_name_expanded,
18453 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 18454 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18455 BGP_STR
18456 EXTCOMMUNITY_LIST_STR
5bf15956 18457 "Extended Community list number (expanded)\n"
718e3744 18458 "Specify expanded extcommunity-list\n"
18459 "Extended Community list name\n"
2f8cc0e5
DA
18460 "Sequence number of an entry\n"
18461 "Sequence number\n"
718e3744 18462 "Specify community to reject\n"
18463 "Specify community to accept\n"
18464 "An ordered list as a regular-expression\n")
18465{
d62a17ae 18466 int style = EXTCOMMUNITY_LIST_EXPANDED;
18467 int direct = 0;
18468 char *cl_number_or_name = NULL;
2f8cc0e5 18469 char *seq = NULL;
d62a17ae 18470 int idx = 0;
7336e101 18471
d62a17ae 18472 argv_find(argv, argc, "(100-500)", &idx);
18473 argv_find(argv, argc, "WORD", &idx);
18474 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18475
409148f6 18476 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18477 seq = argv[idx]->arg;
18478
d62a17ae 18479 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18480 : COMMUNITY_DENY;
18481 argv_find(argv, argc, "LINE", &idx);
18482 char *str = argv_concat(argv, argc, idx);
42f914d4 18483
2f8cc0e5 18484 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18485 direct, style);
42f914d4 18486
d62a17ae 18487 XFREE(MTYPE_TMP, str);
42f914d4 18488
d62a17ae 18489 if (ret < 0) {
18490 community_list_perror(vty, ret);
18491 return CMD_WARNING_CONFIG_FAILED;
18492 }
42f914d4 18493
d62a17ae 18494 return CMD_SUCCESS;
718e3744 18495}
18496
7336e101
SP
18497DEFUN (no_extcommunity_list_standard_all,
18498 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 18499 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18500 NO_STR
18501 BGP_STR
18502 EXTCOMMUNITY_LIST_STR
813d4307 18503 "Extended Community list number (standard)\n"
718e3744 18504 "Specify standard extcommunity-list\n"
5bf15956 18505 "Community list name\n"
2f8cc0e5
DA
18506 "Sequence number of an entry\n"
18507 "Sequence number\n"
718e3744 18508 "Specify community to reject\n"
18509 "Specify community to accept\n"
18510 EXTCOMMUNITY_VAL_STR)
18511{
d62a17ae 18512 int style = EXTCOMMUNITY_LIST_STANDARD;
18513 int direct = 0;
18514 char *cl_number_or_name = NULL;
d4455c89 18515 char *str = NULL;
2f8cc0e5 18516 char *seq = NULL;
d62a17ae 18517 int idx = 0;
d4455c89 18518
409148f6 18519 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18520 seq = argv[idx]->arg;
18521
18522 idx = 0;
d4455c89
DA
18523 argv_find(argv, argc, "permit", &idx);
18524 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
18525 if (idx) {
18526 direct = argv_find(argv, argc, "permit", &idx)
18527 ? COMMUNITY_PERMIT
18528 : COMMUNITY_DENY;
18529
18530 idx = 0;
18531 argv_find(argv, argc, "AA:NN", &idx);
18532 str = argv_concat(argv, argc, idx);
18533 }
18534
18535 idx = 0;
d62a17ae 18536 argv_find(argv, argc, "(1-99)", &idx);
18537 argv_find(argv, argc, "WORD", &idx);
18538 cl_number_or_name = argv[idx]->arg;
42f914d4 18539
d62a17ae 18540 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18541 seq, direct, style);
42f914d4 18542
d62a17ae 18543 XFREE(MTYPE_TMP, str);
42f914d4 18544
d62a17ae 18545 if (ret < 0) {
18546 community_list_perror(vty, ret);
18547 return CMD_WARNING_CONFIG_FAILED;
18548 }
42f914d4 18549
d62a17ae 18550 return CMD_SUCCESS;
718e3744 18551}
18552
d4455c89
DA
18553ALIAS(no_extcommunity_list_standard_all,
18554 no_bgp_extcommunity_list_standard_all_list_cmd,
18555 "no bgp extcommunity-list <(1-99)|standard WORD>",
18556 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18557 "Extended Community list number (standard)\n"
18558 "Specify standard extcommunity-list\n"
18559 "Community list name\n")
18560
7336e101
SP
18561DEFUN (no_extcommunity_list_expanded_all,
18562 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 18563 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18564 NO_STR
18565 BGP_STR
18566 EXTCOMMUNITY_LIST_STR
718e3744 18567 "Extended Community list number (expanded)\n"
718e3744 18568 "Specify expanded extcommunity-list\n"
5bf15956 18569 "Extended Community list name\n"
2f8cc0e5
DA
18570 "Sequence number of an entry\n"
18571 "Sequence number\n"
718e3744 18572 "Specify community to reject\n"
18573 "Specify community to accept\n"
18574 "An ordered list as a regular-expression\n")
18575{
d62a17ae 18576 int style = EXTCOMMUNITY_LIST_EXPANDED;
18577 int direct = 0;
18578 char *cl_number_or_name = NULL;
d4455c89 18579 char *str = NULL;
2f8cc0e5 18580 char *seq = NULL;
d62a17ae 18581 int idx = 0;
d4455c89 18582
409148f6 18583 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18584 seq = argv[idx]->arg;
18585
18586 idx = 0;
d4455c89
DA
18587 argv_find(argv, argc, "permit", &idx);
18588 argv_find(argv, argc, "deny", &idx);
18589
18590 if (idx) {
18591 direct = argv_find(argv, argc, "permit", &idx)
18592 ? COMMUNITY_PERMIT
18593 : COMMUNITY_DENY;
18594
18595 idx = 0;
18596 argv_find(argv, argc, "LINE", &idx);
18597 str = argv_concat(argv, argc, idx);
18598 }
18599
18600 idx = 0;
d62a17ae 18601 argv_find(argv, argc, "(100-500)", &idx);
18602 argv_find(argv, argc, "WORD", &idx);
18603 cl_number_or_name = argv[idx]->arg;
42f914d4 18604
d62a17ae 18605 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18606 seq, direct, style);
42f914d4 18607
d62a17ae 18608 XFREE(MTYPE_TMP, str);
42f914d4 18609
d62a17ae 18610 if (ret < 0) {
18611 community_list_perror(vty, ret);
18612 return CMD_WARNING_CONFIG_FAILED;
18613 }
42f914d4 18614
d62a17ae 18615 return CMD_SUCCESS;
718e3744 18616}
18617
d4455c89
DA
18618ALIAS(no_extcommunity_list_expanded_all,
18619 no_bgp_extcommunity_list_expanded_all_list_cmd,
18620 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18621 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18622 "Extended Community list number (expanded)\n"
18623 "Specify expanded extcommunity-list\n"
18624 "Extended Community list name\n")
18625
d62a17ae 18626static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18627{
d62a17ae 18628 struct community_entry *entry;
718e3744 18629
d62a17ae 18630 for (entry = list->head; entry; entry = entry->next) {
18631 if (entry == list->head) {
18632 if (all_digit(list->name))
18633 vty_out(vty, "Extended community %s list %s\n",
18634 entry->style == EXTCOMMUNITY_LIST_STANDARD
18635 ? "standard"
18636 : "(expanded) access",
18637 list->name);
18638 else
18639 vty_out(vty,
18640 "Named extended community %s list %s\n",
18641 entry->style == EXTCOMMUNITY_LIST_STANDARD
18642 ? "standard"
18643 : "expanded",
18644 list->name);
18645 }
18646 if (entry->any)
18647 vty_out(vty, " %s\n",
18648 community_direct_str(entry->direct));
18649 else
18650 vty_out(vty, " %s %s\n",
18651 community_direct_str(entry->direct),
8d9b8ed9 18652 community_list_config_str(entry));
d62a17ae 18653 }
718e3744 18654}
18655
7336e101
SP
18656DEFUN (show_extcommunity_list,
18657 show_bgp_extcommunity_list_cmd,
18658 "show bgp extcommunity-list",
718e3744 18659 SHOW_STR
7336e101 18660 BGP_STR
718e3744 18661 "List extended-community list\n")
18662{
d62a17ae 18663 struct community_list *list;
18664 struct community_list_master *cm;
718e3744 18665
d62a17ae 18666 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18667 if (!cm)
18668 return CMD_SUCCESS;
718e3744 18669
d62a17ae 18670 for (list = cm->num.head; list; list = list->next)
18671 extcommunity_list_show(vty, list);
718e3744 18672
d62a17ae 18673 for (list = cm->str.head; list; list = list->next)
18674 extcommunity_list_show(vty, list);
718e3744 18675
d62a17ae 18676 return CMD_SUCCESS;
718e3744 18677}
18678
7336e101
SP
18679DEFUN (show_extcommunity_list_arg,
18680 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18681 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18682 SHOW_STR
18683 BGP_STR
718e3744 18684 "List extended-community list\n"
18685 "Extcommunity-list number\n"
960b69b9 18686 "Extcommunity-list name\n"
18687 "Detailed information on extcommunity-list\n")
718e3744 18688{
d62a17ae 18689 int idx_comm_list = 3;
18690 struct community_list *list;
718e3744 18691
e237b0d2 18692 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18693 EXTCOMMUNITY_LIST_MASTER);
18694 if (!list) {
18695 vty_out(vty, "%% Can't find extcommunity-list\n");
18696 return CMD_WARNING;
18697 }
718e3744 18698
d62a17ae 18699 extcommunity_list_show(vty, list);
718e3744 18700
d62a17ae 18701 return CMD_SUCCESS;
718e3744 18702}
6b0655a2 18703
718e3744 18704/* Display community-list and extcommunity-list configuration. */
d62a17ae 18705static int community_list_config_write(struct vty *vty)
18706{
18707 struct community_list *list;
18708 struct community_entry *entry;
18709 struct community_list_master *cm;
18710 int write = 0;
18711
18712 /* Community-list. */
18713 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18714
18715 for (list = cm->num.head; list; list = list->next)
18716 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18717 vty_out(vty,
18718 "bgp community-list %s seq %" PRId64 " %s %s\n",
18719 list->name, entry->seq,
d62a17ae 18720 community_direct_str(entry->direct),
18721 community_list_config_str(entry));
18722 write++;
18723 }
18724 for (list = cm->str.head; list; list = list->next)
18725 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18726 vty_out(vty,
18727 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18728 entry->style == COMMUNITY_LIST_STANDARD
18729 ? "standard"
18730 : "expanded",
2f8cc0e5
DA
18731 list->name, entry->seq,
18732 community_direct_str(entry->direct),
d62a17ae 18733 community_list_config_str(entry));
18734 write++;
18735 }
18736
18737 /* Extcommunity-list. */
18738 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18739
18740 for (list = cm->num.head; list; list = list->next)
18741 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18742 vty_out(vty,
18743 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18744 list->name, entry->seq,
18745 community_direct_str(entry->direct),
d62a17ae 18746 community_list_config_str(entry));
18747 write++;
18748 }
18749 for (list = cm->str.head; list; list = list->next)
18750 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18751 vty_out(vty,
6cde4b45 18752 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18753 entry->style == EXTCOMMUNITY_LIST_STANDARD
18754 ? "standard"
18755 : "expanded",
2f8cc0e5
DA
18756 list->name, entry->seq,
18757 community_direct_str(entry->direct),
d62a17ae 18758 community_list_config_str(entry));
18759 write++;
18760 }
18761
18762
18763 /* lcommunity-list. */
18764 cm = community_list_master_lookup(bgp_clist,
18765 LARGE_COMMUNITY_LIST_MASTER);
18766
18767 for (list = cm->num.head; list; list = list->next)
18768 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18769 vty_out(vty,
6cde4b45 18770 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
18771 list->name, entry->seq,
18772 community_direct_str(entry->direct),
d62a17ae 18773 community_list_config_str(entry));
18774 write++;
18775 }
18776 for (list = cm->str.head; list; list = list->next)
18777 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18778 vty_out(vty,
6cde4b45 18779 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 18780
d62a17ae 18781 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18782 ? "standard"
18783 : "expanded",
2f8cc0e5 18784 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 18785 community_list_config_str(entry));
18786 write++;
18787 }
18788
18789 return write;
18790}
18791
612c2c15 18792static int community_list_config_write(struct vty *vty);
d62a17ae 18793static struct cmd_node community_list_node = {
f4b8291f 18794 .name = "community list",
62b346ee
DL
18795 .node = COMMUNITY_LIST_NODE,
18796 .prompt = "",
612c2c15 18797 .config_write = community_list_config_write,
718e3744 18798};
18799
d62a17ae 18800static void community_list_vty(void)
18801{
612c2c15 18802 install_node(&community_list_node);
d62a17ae 18803
18804 /* Community-list. */
7336e101
SP
18805 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18806 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18807 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 18808 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 18809 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 18810 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
18811 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18812 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 18813
18814 /* Extcommunity-list. */
7336e101
SP
18815 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18816 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18817 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
18818 install_element(CONFIG_NODE,
18819 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 18820 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
18821 install_element(CONFIG_NODE,
18822 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
18823 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18824 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 18825
18826 /* Large Community List */
7336e101 18827 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
18828 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18829 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 18830 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
18831 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18832 install_element(CONFIG_NODE,
18833 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
18834 install_element(CONFIG_NODE,
18835 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18836 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18837 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18838 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18839 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18840 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18841 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 18842}