]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #7267 from donaldsharp/plist_relaxer
[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;
3886 char buf[PREFIX2STR_BUFFER];
3887
3888 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
3889 vty_out(vty, " bgp listen limit %d\n",
3890 bgp->dynamic_neighbors_limit);
3891
3892 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
3893 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
3894 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
3895 nrnode, range)) {
3896 prefix2str(range, buf, sizeof(buf));
3897 vty_out(vty,
3898 " bgp listen range %s peer-group %s\n",
3899 buf, group->name);
3900 }
3901 }
3902 }
f14e6fdb
DS
3903}
3904
3905
ff8a8a7a
CS
3906DEFUN_YANG(bgp_disable_connected_route_check,
3907 bgp_disable_connected_route_check_cmd,
3908 "bgp disable-ebgp-connected-route-check",
3909 "BGP specific commands\n"
3910 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 3911{
87ce2564
CS
3912 nb_cli_enqueue_change(vty,
3913 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 3914 NB_OP_MODIFY, "true");
7aafcaca 3915
ff8a8a7a 3916 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
3917}
3918
ff8a8a7a
CS
3919DEFUN_YANG(no_bgp_disable_connected_route_check,
3920 no_bgp_disable_connected_route_check_cmd,
3921 "no bgp disable-ebgp-connected-route-check",
3922 NO_STR
3923 "BGP specific commands\n"
3924 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 3925{
87ce2564
CS
3926 nb_cli_enqueue_change(vty,
3927 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 3928 NB_OP_MODIFY, "false");
d62a17ae 3929
ff8a8a7a 3930 return nb_cli_apply_changes(vty, NULL);
d62a17ae 3931}
3932
ff8a8a7a
CS
3933void cli_show_router_global_ebgp_multihop_connected_route_check(
3934 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3935{
3936 if (yang_dnode_get_bool(dnode, NULL))
3937 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
3938}
d62a17ae 3939
3940static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
3941 const char *as_str, afi_t afi, safi_t safi)
3942{
3943 VTY_DECLVAR_CONTEXT(bgp, bgp);
3944 int ret;
3945 as_t as;
3946 int as_type = AS_SPECIFIED;
3947 union sockunion su;
3948
3949 if (as_str[0] == 'i') {
3950 as = 0;
3951 as_type = AS_INTERNAL;
3952 } else if (as_str[0] == 'e') {
3953 as = 0;
3954 as_type = AS_EXTERNAL;
3955 } else {
3956 /* Get AS number. */
3957 as = strtoul(as_str, NULL, 10);
3958 }
3959
390485fd 3960 /* If peer is peer group or interface peer, call proper function. */
d62a17ae 3961 ret = str2sockunion(peer_str, &su);
3962 if (ret < 0) {
390485fd
DS
3963 struct peer *peer;
3964
3965 /* Check if existing interface peer */
3966 peer = peer_lookup_by_conf_if(bgp, peer_str);
3967
d62a17ae 3968 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
3969 safi);
390485fd
DS
3970
3971 /* if not interface peer, check peer-group settings */
3972 if (ret < 0 && !peer) {
d62a17ae 3973 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
3974 if (ret < 0) {
3975 vty_out(vty,
390485fd 3976 "%% Create the peer-group or interface first\n");
d62a17ae 3977 return CMD_WARNING_CONFIG_FAILED;
3978 }
3979 return CMD_SUCCESS;
3980 }
3981 } else {
3982 if (peer_address_self_check(bgp, &su)) {
3983 vty_out(vty,
3984 "%% Can not configure the local system as neighbor\n");
3985 return CMD_WARNING_CONFIG_FAILED;
3986 }
3987 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
3988 }
3989
3990 /* This peer belongs to peer group. */
3991 switch (ret) {
3992 case BGP_ERR_PEER_GROUP_MEMBER:
3993 vty_out(vty,
faa16034 3994 "%% Peer-group member cannot override remote-as of peer-group\n");
d62a17ae 3995 return CMD_WARNING_CONFIG_FAILED;
3996 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
3997 vty_out(vty,
faa16034 3998 "%% Peer-group members must be all internal or all external\n");
d62a17ae 3999 return CMD_WARNING_CONFIG_FAILED;
4000 }
4001 return bgp_vty_return(vty, ret);
718e3744 4002}
4003
ff8a8a7a
CS
4004DEFUN_YANG(bgp_default_shutdown,
4005 bgp_default_shutdown_cmd,
4006 "[no] bgp default shutdown",
4007 NO_STR BGP_STR
4008 "Configure BGP defaults\n"
4009 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4010{
87ce2564 4011 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4012 strmatch(argv[0]->text, "no") ? "false" : "true");
4013
4014 return nb_cli_apply_changes(vty, NULL);
4015}
4016
4017void cli_show_router_bgp_default_shutdown(struct vty *vty,
4018 struct lyd_node *dnode,
4019 bool show_defaults)
4020{
4021 if (yang_dnode_get_bool(dnode, NULL))
4022 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4023}
4024
736b68f3
DS
4025DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4026 BGP_STR
9ddf4b81 4027 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4028 "Add a shutdown message (RFC 8203)\n"
4029 "Shutdown message\n")
9cf59432 4030{
736b68f3 4031 char *msgstr = NULL;
8389c83a 4032
9cf59432
DS
4033 VTY_DECLVAR_CONTEXT(bgp, bgp);
4034
8389c83a 4035 if (argc > 3)
f80e35b6 4036 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4037
4038 bgp_shutdown_enable(bgp, msgstr);
4039 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4040
4041 return CMD_SUCCESS;
4042}
4043
736b68f3 4044DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4045 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4046{
4047 VTY_DECLVAR_CONTEXT(bgp, bgp);
4048
4049 bgp_shutdown_enable(bgp, NULL);
4050
4051 return CMD_SUCCESS;
4052}
8389c83a 4053
736b68f3 4054DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4055 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4056{
4057 VTY_DECLVAR_CONTEXT(bgp, bgp);
4058
4059 bgp_shutdown_disable(bgp);
4060
4061 return CMD_SUCCESS;
4062}
4063
9ddf4b81 4064ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4065 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4066 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4067 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4068
718e3744 4069DEFUN (neighbor_remote_as,
4070 neighbor_remote_as_cmd,
3a2d747c 4071 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 4072 NEIGHBOR_STR
4073 NEIGHBOR_ADDR_STR2
4074 "Specify a BGP neighbor\n"
d7fa34c1 4075 AS_STR
3a2d747c
QY
4076 "Internal BGP peer\n"
4077 "External BGP peer\n")
718e3744 4078{
d62a17ae 4079 int idx_peer = 1;
4080 int idx_remote_as = 3;
4081 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
4082 argv[idx_remote_as]->arg, AFI_IP,
4083 SAFI_UNICAST);
4084}
4085
4086static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
4087 afi_t afi, safi_t safi, int v6only,
4088 const char *peer_group_name,
4089 const char *as_str)
4090{
4091 VTY_DECLVAR_CONTEXT(bgp, bgp);
4092 as_t as = 0;
4093 int as_type = AS_UNSPECIFIED;
4094 struct peer *peer;
4095 struct peer_group *group;
4096 int ret = 0;
4097 union sockunion su;
4098
4099 group = peer_group_lookup(bgp, conf_if);
4100
4101 if (group) {
4102 vty_out(vty, "%% Name conflict with peer-group \n");
4103 return CMD_WARNING_CONFIG_FAILED;
4104 }
4105
4106 if (as_str) {
4107 if (as_str[0] == 'i') {
4108 as_type = AS_INTERNAL;
4109 } else if (as_str[0] == 'e') {
4110 as_type = AS_EXTERNAL;
4111 } else {
4112 /* Get AS number. */
4113 as = strtoul(as_str, NULL, 10);
4114 as_type = AS_SPECIFIED;
4115 }
4116 }
4117
4118 peer = peer_lookup_by_conf_if(bgp, conf_if);
4119 if (peer) {
4120 if (as_str)
cc4d4ce8 4121 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
d62a17ae 4122 afi, safi);
4123 } else {
892fedb6 4124 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
d62a17ae 4125 && afi == AFI_IP && safi == SAFI_UNICAST)
4126 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4127 as_type, 0, 0, NULL);
4128 else
4129 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4130 as_type, afi, safi, NULL);
4131
4132 if (!peer) {
4133 vty_out(vty, "%% BGP failed to create peer\n");
4134 return CMD_WARNING_CONFIG_FAILED;
4135 }
4136
4137 if (v6only)
527de3dc 4138 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4139
4140 /* Request zebra to initiate IPv6 RAs on this interface. We do
4141 * this
4142 * any unnumbered peer in order to not worry about run-time
4143 * transitions
4144 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4145 * address
4146 * gets deleted later etc.)
4147 */
4148 if (peer->ifp)
4149 bgp_zebra_initiate_radv(bgp, peer);
4150 }
4151
4152 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4153 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4154 if (v6only)
527de3dc 4155 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4156 else
527de3dc 4157 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4158
4159 /* v6only flag changed. Reset bgp seesion */
4160 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4161 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4162 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4163 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4164 } else
4165 bgp_session_reset(peer);
4166 }
4167
9fb964de
PM
4168 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4169 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4170 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4171 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4172 }
d62a17ae 4173
4174 if (peer_group_name) {
4175 group = peer_group_lookup(bgp, peer_group_name);
4176 if (!group) {
4177 vty_out(vty, "%% Configure the peer-group first\n");
4178 return CMD_WARNING_CONFIG_FAILED;
4179 }
4180
4181 ret = peer_group_bind(bgp, &su, peer, group, &as);
4182 }
4183
4184 return bgp_vty_return(vty, ret);
a80beece
DS
4185}
4186
4c48cf63
DW
4187DEFUN (neighbor_interface_config,
4188 neighbor_interface_config_cmd,
d7b9898c 4189 "neighbor WORD interface [peer-group PGNAME]",
4c48cf63
DW
4190 NEIGHBOR_STR
4191 "Interface name or neighbor tag\n"
31500417
DW
4192 "Enable BGP on interface\n"
4193 "Member of the peer-group\n"
16cedbb0 4194 "Peer-group name\n")
4c48cf63 4195{
d62a17ae 4196 int idx_word = 1;
4197 int idx_peer_group_word = 4;
31500417 4198
d62a17ae 4199 if (argc > idx_peer_group_word)
4200 return peer_conf_interface_get(
4201 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
4202 argv[idx_peer_group_word]->arg, NULL);
4203 else
4204 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4205 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
4206}
4207
4c48cf63
DW
4208DEFUN (neighbor_interface_config_v6only,
4209 neighbor_interface_config_v6only_cmd,
d7b9898c 4210 "neighbor WORD interface v6only [peer-group PGNAME]",
4c48cf63
DW
4211 NEIGHBOR_STR
4212 "Interface name or neighbor tag\n"
4213 "Enable BGP on interface\n"
31500417
DW
4214 "Enable BGP with v6 link-local only\n"
4215 "Member of the peer-group\n"
16cedbb0 4216 "Peer-group name\n")
4c48cf63 4217{
d62a17ae 4218 int idx_word = 1;
4219 int idx_peer_group_word = 5;
31500417 4220
d62a17ae 4221 if (argc > idx_peer_group_word)
4222 return peer_conf_interface_get(
4223 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
4224 argv[idx_peer_group_word]->arg, NULL);
31500417 4225
d62a17ae 4226 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4227 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
4228}
4229
a80beece 4230
b3a39dc5
DD
4231DEFUN (neighbor_interface_config_remote_as,
4232 neighbor_interface_config_remote_as_cmd,
3a2d747c 4233 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4234 NEIGHBOR_STR
4235 "Interface name or neighbor tag\n"
4236 "Enable BGP on interface\n"
3a2d747c 4237 "Specify a BGP neighbor\n"
d7fa34c1 4238 AS_STR
3a2d747c
QY
4239 "Internal BGP peer\n"
4240 "External BGP peer\n")
b3a39dc5 4241{
d62a17ae 4242 int idx_word = 1;
4243 int idx_remote_as = 4;
4244 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4245 SAFI_UNICAST, 0, NULL,
4246 argv[idx_remote_as]->arg);
b3a39dc5
DD
4247}
4248
4249DEFUN (neighbor_interface_v6only_config_remote_as,
4250 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 4251 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
4252 NEIGHBOR_STR
4253 "Interface name or neighbor tag\n"
3a2d747c 4254 "Enable BGP with v6 link-local only\n"
b3a39dc5 4255 "Enable BGP on interface\n"
3a2d747c 4256 "Specify a BGP neighbor\n"
d7fa34c1 4257 AS_STR
3a2d747c
QY
4258 "Internal BGP peer\n"
4259 "External BGP peer\n")
b3a39dc5 4260{
d62a17ae 4261 int idx_word = 1;
4262 int idx_remote_as = 5;
4263 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
4264 SAFI_UNICAST, 1, NULL,
4265 argv[idx_remote_as]->arg);
b3a39dc5
DD
4266}
4267
718e3744 4268DEFUN (neighbor_peer_group,
4269 neighbor_peer_group_cmd,
4270 "neighbor WORD peer-group",
4271 NEIGHBOR_STR
a80beece 4272 "Interface name or neighbor tag\n"
718e3744 4273 "Configure peer-group\n")
4274{
d62a17ae 4275 VTY_DECLVAR_CONTEXT(bgp, bgp);
4276 int idx_word = 1;
4277 struct peer *peer;
4278 struct peer_group *group;
718e3744 4279
d62a17ae 4280 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4281 if (peer) {
4282 vty_out(vty, "%% Name conflict with interface: \n");
4283 return CMD_WARNING_CONFIG_FAILED;
4284 }
718e3744 4285
d62a17ae 4286 group = peer_group_get(bgp, argv[idx_word]->arg);
4287 if (!group) {
4288 vty_out(vty, "%% BGP failed to find or create peer-group\n");
4289 return CMD_WARNING_CONFIG_FAILED;
4290 }
718e3744 4291
d62a17ae 4292 return CMD_SUCCESS;
718e3744 4293}
4294
4295DEFUN (no_neighbor,
4296 no_neighbor_cmd,
dab8cd00 4297 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 4298 NO_STR
4299 NEIGHBOR_STR
3a2d747c
QY
4300 NEIGHBOR_ADDR_STR2
4301 "Specify a BGP neighbor\n"
4302 AS_STR
4303 "Internal BGP peer\n"
4304 "External BGP peer\n")
718e3744 4305{
d62a17ae 4306 VTY_DECLVAR_CONTEXT(bgp, bgp);
4307 int idx_peer = 2;
4308 int ret;
4309 union sockunion su;
4310 struct peer_group *group;
4311 struct peer *peer;
4312 struct peer *other;
4313
4314 ret = str2sockunion(argv[idx_peer]->arg, &su);
4315 if (ret < 0) {
4316 /* look up for neighbor by interface name config. */
4317 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4318 if (peer) {
4319 /* Request zebra to terminate IPv6 RAs on this
4320 * interface. */
4321 if (peer->ifp)
4322 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4323 peer_notify_unconfig(peer);
d62a17ae 4324 peer_delete(peer);
4325 return CMD_SUCCESS;
4326 }
f14e6fdb 4327
d62a17ae 4328 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
4e2786df
DA
4329 if (group) {
4330 peer_group_notify_unconfig(group);
d62a17ae 4331 peer_group_delete(group);
4e2786df 4332 } else {
d62a17ae 4333 vty_out(vty, "%% Create the peer-group first\n");
4334 return CMD_WARNING_CONFIG_FAILED;
4335 }
4336 } else {
4337 peer = peer_lookup(bgp, &su);
4338 if (peer) {
4339 if (peer_dynamic_neighbor(peer)) {
4340 vty_out(vty,
4341 "%% Operation not allowed on a dynamic neighbor\n");
4342 return CMD_WARNING_CONFIG_FAILED;
4343 }
4344
4345 other = peer->doppelganger;
b3a3290e
DS
4346
4347 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4348 bgp_zebra_terminate_radv(peer->bgp, peer);
4349
4e2786df 4350 peer_notify_unconfig(peer);
d62a17ae 4351 peer_delete(peer);
4e2786df
DA
4352 if (other && other->status != Deleted) {
4353 peer_notify_unconfig(other);
d62a17ae 4354 peer_delete(other);
4e2786df 4355 }
d62a17ae 4356 }
1ff9a340 4357 }
718e3744 4358
d62a17ae 4359 return CMD_SUCCESS;
718e3744 4360}
4361
a80beece
DS
4362DEFUN (no_neighbor_interface_config,
4363 no_neighbor_interface_config_cmd,
d7b9898c 4364 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
4365 NO_STR
4366 NEIGHBOR_STR
4367 "Interface name\n"
31500417
DW
4368 "Configure BGP on interface\n"
4369 "Enable BGP with v6 link-local only\n"
4370 "Member of the peer-group\n"
16cedbb0 4371 "Peer-group name\n"
3a2d747c
QY
4372 "Specify a BGP neighbor\n"
4373 AS_STR
4374 "Internal BGP peer\n"
4375 "External BGP peer\n")
a80beece 4376{
d62a17ae 4377 VTY_DECLVAR_CONTEXT(bgp, bgp);
4378 int idx_word = 2;
4379 struct peer *peer;
4380
4381 /* look up for neighbor by interface name config. */
4382 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4383 if (peer) {
4384 /* Request zebra to terminate IPv6 RAs on this interface. */
4385 if (peer->ifp)
4386 bgp_zebra_terminate_radv(peer->bgp, peer);
4e2786df 4387 peer_notify_unconfig(peer);
d62a17ae 4388 peer_delete(peer);
4389 } else {
4390 vty_out(vty, "%% Create the bgp interface first\n");
4391 return CMD_WARNING_CONFIG_FAILED;
4392 }
4393 return CMD_SUCCESS;
a80beece
DS
4394}
4395
718e3744 4396DEFUN (no_neighbor_peer_group,
4397 no_neighbor_peer_group_cmd,
4398 "no neighbor WORD peer-group",
4399 NO_STR
4400 NEIGHBOR_STR
4401 "Neighbor tag\n"
4402 "Configure peer-group\n")
4403{
d62a17ae 4404 VTY_DECLVAR_CONTEXT(bgp, bgp);
4405 int idx_word = 2;
4406 struct peer_group *group;
718e3744 4407
d62a17ae 4408 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4e2786df
DA
4409 if (group) {
4410 peer_group_notify_unconfig(group);
d62a17ae 4411 peer_group_delete(group);
4e2786df 4412 } else {
d62a17ae 4413 vty_out(vty, "%% Create the peer-group first\n");
4414 return CMD_WARNING_CONFIG_FAILED;
4415 }
4416 return CMD_SUCCESS;
718e3744 4417}
4418
a80beece
DS
4419DEFUN (no_neighbor_interface_peer_group_remote_as,
4420 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 4421 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 4422 NO_STR
4423 NEIGHBOR_STR
a80beece 4424 "Interface name or neighbor tag\n"
718e3744 4425 "Specify a BGP neighbor\n"
3a2d747c
QY
4426 AS_STR
4427 "Internal BGP peer\n"
4428 "External BGP peer\n")
718e3744 4429{
d62a17ae 4430 VTY_DECLVAR_CONTEXT(bgp, bgp);
4431 int idx_word = 2;
4432 struct peer_group *group;
4433 struct peer *peer;
4434
4435 /* look up for neighbor by interface name config. */
4436 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
4437 if (peer) {
390485fd 4438 peer_as_change(peer, 0, AS_UNSPECIFIED);
d62a17ae 4439 return CMD_SUCCESS;
4440 }
4441
4442 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4443 if (group)
4444 peer_group_remote_as_delete(group);
4445 else {
4446 vty_out(vty, "%% Create the peer-group or interface first\n");
4447 return CMD_WARNING_CONFIG_FAILED;
4448 }
4449 return CMD_SUCCESS;
718e3744 4450}
6b0655a2 4451
718e3744 4452DEFUN (neighbor_local_as,
4453 neighbor_local_as_cmd,
9ccf14f7 4454 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 4455 NEIGHBOR_STR
4456 NEIGHBOR_ADDR_STR2
4457 "Specify a local-as number\n"
4458 "AS number used as local AS\n")
4459{
d62a17ae 4460 int idx_peer = 1;
4461 int idx_number = 3;
4462 struct peer *peer;
4463 int ret;
4464 as_t as;
718e3744 4465
d62a17ae 4466 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4467 if (!peer)
4468 return CMD_WARNING_CONFIG_FAILED;
718e3744 4469
d62a17ae 4470 as = strtoul(argv[idx_number]->arg, NULL, 10);
4471 ret = peer_local_as_set(peer, as, 0, 0);
4472 return bgp_vty_return(vty, ret);
718e3744 4473}
4474
4475DEFUN (neighbor_local_as_no_prepend,
4476 neighbor_local_as_no_prepend_cmd,
9ccf14f7 4477 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "Specify a local-as number\n"
4481 "AS number used as local AS\n"
4482 "Do not prepend local-as to updates from ebgp peers\n")
4483{
d62a17ae 4484 int idx_peer = 1;
4485 int idx_number = 3;
4486 struct peer *peer;
4487 int ret;
4488 as_t as;
718e3744 4489
d62a17ae 4490 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4491 if (!peer)
4492 return CMD_WARNING_CONFIG_FAILED;
718e3744 4493
d62a17ae 4494 as = strtoul(argv[idx_number]->arg, NULL, 10);
4495 ret = peer_local_as_set(peer, as, 1, 0);
4496 return bgp_vty_return(vty, ret);
718e3744 4497}
4498
9d3f9705
AC
4499DEFUN (neighbor_local_as_no_prepend_replace_as,
4500 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 4501 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
4502 NEIGHBOR_STR
4503 NEIGHBOR_ADDR_STR2
4504 "Specify a local-as number\n"
4505 "AS number used as local AS\n"
4506 "Do not prepend local-as to updates from ebgp peers\n"
4507 "Do not prepend local-as to updates from ibgp peers\n")
4508{
d62a17ae 4509 int idx_peer = 1;
4510 int idx_number = 3;
4511 struct peer *peer;
4512 int ret;
4513 as_t as;
9d3f9705 4514
d62a17ae 4515 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4516 if (!peer)
4517 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4518
d62a17ae 4519 as = strtoul(argv[idx_number]->arg, NULL, 10);
4520 ret = peer_local_as_set(peer, as, 1, 1);
4521 return bgp_vty_return(vty, ret);
9d3f9705
AC
4522}
4523
718e3744 4524DEFUN (no_neighbor_local_as,
4525 no_neighbor_local_as_cmd,
a636c635 4526 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 4527 NO_STR
4528 NEIGHBOR_STR
4529 NEIGHBOR_ADDR_STR2
a636c635
DW
4530 "Specify a local-as number\n"
4531 "AS number used as local AS\n"
4532 "Do not prepend local-as to updates from ebgp peers\n"
4533 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4534{
d62a17ae 4535 int idx_peer = 2;
4536 struct peer *peer;
4537 int ret;
718e3744 4538
d62a17ae 4539 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4540 if (!peer)
4541 return CMD_WARNING_CONFIG_FAILED;
718e3744 4542
d62a17ae 4543 ret = peer_local_as_unset(peer);
4544 return bgp_vty_return(vty, ret);
718e3744 4545}
4546
718e3744 4547
3f9c7369
DS
4548DEFUN (neighbor_solo,
4549 neighbor_solo_cmd,
9ccf14f7 4550 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4551 NEIGHBOR_STR
4552 NEIGHBOR_ADDR_STR2
4553 "Solo peer - part of its own update group\n")
4554{
d62a17ae 4555 int idx_peer = 1;
4556 struct peer *peer;
4557 int ret;
3f9c7369 4558
d62a17ae 4559 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4560 if (!peer)
4561 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4562
d62a17ae 4563 ret = update_group_adjust_soloness(peer, 1);
4564 return bgp_vty_return(vty, ret);
3f9c7369
DS
4565}
4566
4567DEFUN (no_neighbor_solo,
4568 no_neighbor_solo_cmd,
9ccf14f7 4569 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4570 NO_STR
4571 NEIGHBOR_STR
4572 NEIGHBOR_ADDR_STR2
4573 "Solo peer - part of its own update group\n")
4574{
d62a17ae 4575 int idx_peer = 2;
4576 struct peer *peer;
4577 int ret;
3f9c7369 4578
d62a17ae 4579 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4580 if (!peer)
4581 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4582
d62a17ae 4583 ret = update_group_adjust_soloness(peer, 0);
4584 return bgp_vty_return(vty, ret);
3f9c7369
DS
4585}
4586
0df7c91f
PJ
4587DEFUN (neighbor_password,
4588 neighbor_password_cmd,
9ccf14f7 4589 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
4590 NEIGHBOR_STR
4591 NEIGHBOR_ADDR_STR2
4592 "Set a password\n"
4593 "The password\n")
4594{
d62a17ae 4595 int idx_peer = 1;
4596 int idx_line = 3;
4597 struct peer *peer;
4598 int ret;
0df7c91f 4599
d62a17ae 4600 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4601 if (!peer)
4602 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4603
d62a17ae 4604 ret = peer_password_set(peer, argv[idx_line]->arg);
4605 return bgp_vty_return(vty, ret);
0df7c91f
PJ
4606}
4607
4608DEFUN (no_neighbor_password,
4609 no_neighbor_password_cmd,
a636c635 4610 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
4611 NO_STR
4612 NEIGHBOR_STR
4613 NEIGHBOR_ADDR_STR2
16cedbb0
QY
4614 "Set a password\n"
4615 "The password\n")
0df7c91f 4616{
d62a17ae 4617 int idx_peer = 2;
4618 struct peer *peer;
4619 int ret;
0df7c91f 4620
d62a17ae 4621 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4622 if (!peer)
4623 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4624
d62a17ae 4625 ret = peer_password_unset(peer);
4626 return bgp_vty_return(vty, ret);
0df7c91f 4627}
6b0655a2 4628
718e3744 4629DEFUN (neighbor_activate,
4630 neighbor_activate_cmd,
9ccf14f7 4631 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4632 NEIGHBOR_STR
4633 NEIGHBOR_ADDR_STR2
4634 "Enable the Address Family for this Neighbor\n")
4635{
d62a17ae 4636 int idx_peer = 1;
4637 int ret;
4638 struct peer *peer;
718e3744 4639
d62a17ae 4640 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4641 if (!peer)
4642 return CMD_WARNING_CONFIG_FAILED;
718e3744 4643
d62a17ae 4644 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4645 return bgp_vty_return(vty, ret);
718e3744 4646}
4647
d62a17ae 4648ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4649 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4650 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4651 "Enable the Address Family for this Neighbor\n")
596c17ba 4652
718e3744 4653DEFUN (no_neighbor_activate,
4654 no_neighbor_activate_cmd,
9ccf14f7 4655 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 4656 NO_STR
4657 NEIGHBOR_STR
4658 NEIGHBOR_ADDR_STR2
4659 "Enable the Address Family for this Neighbor\n")
4660{
d62a17ae 4661 int idx_peer = 2;
4662 int ret;
4663 struct peer *peer;
718e3744 4664
d62a17ae 4665 /* Lookup peer. */
4666 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
718e3744 4669
d62a17ae 4670 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
4671 return bgp_vty_return(vty, ret);
718e3744 4672}
6b0655a2 4673
d62a17ae 4674ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4675 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4676 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4677 "Enable the Address Family for this Neighbor\n")
596c17ba 4678
718e3744 4679DEFUN (neighbor_set_peer_group,
4680 neighbor_set_peer_group_cmd,
d7b9898c 4681 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4682 NEIGHBOR_STR
a80beece 4683 NEIGHBOR_ADDR_STR2
718e3744 4684 "Member of the peer-group\n"
16cedbb0 4685 "Peer-group name\n")
718e3744 4686{
d62a17ae 4687 VTY_DECLVAR_CONTEXT(bgp, bgp);
4688 int idx_peer = 1;
4689 int idx_word = 3;
4690 int ret;
4691 as_t as;
4692 union sockunion su;
4693 struct peer *peer;
4694 struct peer_group *group;
4695
d62a17ae 4696 ret = str2sockunion(argv[idx_peer]->arg, &su);
4697 if (ret < 0) {
4698 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4699 if (!peer) {
4700 vty_out(vty, "%% Malformed address or name: %s\n",
4701 argv[idx_peer]->arg);
4702 return CMD_WARNING_CONFIG_FAILED;
4703 }
4704 } else {
4705 if (peer_address_self_check(bgp, &su)) {
4706 vty_out(vty,
4707 "%% Can not configure the local system as neighbor\n");
4708 return CMD_WARNING_CONFIG_FAILED;
4709 }
4710
4711 /* Disallow for dynamic neighbor. */
4712 peer = peer_lookup(bgp, &su);
4713 if (peer && peer_dynamic_neighbor(peer)) {
4714 vty_out(vty,
4715 "%% Operation not allowed on a dynamic neighbor\n");
4716 return CMD_WARNING_CONFIG_FAILED;
4717 }
4718 }
4719
4720 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4721 if (!group) {
4722 vty_out(vty, "%% Configure the peer-group first\n");
4723 return CMD_WARNING_CONFIG_FAILED;
4724 }
4725
4726 ret = peer_group_bind(bgp, &su, peer, group, &as);
4727
4728 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
4729 vty_out(vty,
4730 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
4731 as);
4732 return CMD_WARNING_CONFIG_FAILED;
4733 }
4734
4735 return bgp_vty_return(vty, ret);
4736}
4737
4738ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 4739 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4740 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4741 "Member of the peer-group\n"
4742 "Peer-group name\n")
596c17ba 4743
718e3744 4744DEFUN (no_neighbor_set_peer_group,
4745 no_neighbor_set_peer_group_cmd,
d7b9898c 4746 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
718e3744 4747 NO_STR
4748 NEIGHBOR_STR
a80beece 4749 NEIGHBOR_ADDR_STR2
718e3744 4750 "Member of the peer-group\n"
16cedbb0 4751 "Peer-group name\n")
718e3744 4752{
d62a17ae 4753 VTY_DECLVAR_CONTEXT(bgp, bgp);
4754 int idx_peer = 2;
4755 int idx_word = 4;
4756 int ret;
4757 struct peer *peer;
4758 struct peer_group *group;
4759
4760 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
4761 if (!peer)
4762 return CMD_WARNING_CONFIG_FAILED;
4763
4764 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4765 if (!group) {
4766 vty_out(vty, "%% Configure the peer-group first\n");
4767 return CMD_WARNING_CONFIG_FAILED;
4768 }
718e3744 4769
b3a3290e
DS
4770 if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
4771 bgp_zebra_terminate_radv(peer->bgp, peer);
4772
4e2786df 4773 peer_notify_unconfig(peer);
827ed707 4774 ret = peer_delete(peer);
718e3744 4775
d62a17ae 4776 return bgp_vty_return(vty, ret);
718e3744 4777}
6b0655a2 4778
d62a17ae 4779ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
d7b9898c 4780 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 4781 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4782 "Member of the peer-group\n"
4783 "Peer-group name\n")
596c17ba 4784
d62a17ae 4785static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 4786 uint32_t flag, int set)
718e3744 4787{
d62a17ae 4788 int ret;
4789 struct peer *peer;
718e3744 4790
d62a17ae 4791 peer = peer_and_group_lookup_vty(vty, ip_str);
4792 if (!peer)
4793 return CMD_WARNING_CONFIG_FAILED;
718e3744 4794
7ebe625c
QY
4795 /*
4796 * If 'neighbor <interface>', then this is for directly connected peers,
4797 * we should not accept disable-connected-check.
4798 */
4799 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
4800 vty_out(vty,
3efd0893 4801 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
4802 ip_str);
4803 return CMD_WARNING_CONFIG_FAILED;
4804 }
4805
d62a17ae 4806 if (!set && flag == PEER_FLAG_SHUTDOWN)
4807 peer_tx_shutdown_message_unset(peer);
ae9b0e11 4808
d62a17ae 4809 if (set)
4810 ret = peer_flag_set(peer, flag);
4811 else
4812 ret = peer_flag_unset(peer, flag);
718e3744 4813
d62a17ae 4814 return bgp_vty_return(vty, ret);
718e3744 4815}
4816
47cbc09b 4817static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 4818{
d62a17ae 4819 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 4820}
4821
d62a17ae 4822static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 4823 uint32_t flag)
718e3744 4824{
d62a17ae 4825 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 4826}
4827
4828/* neighbor passive. */
4829DEFUN (neighbor_passive,
4830 neighbor_passive_cmd,
9ccf14f7 4831 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "Don't send open messages to this neighbor\n")
4835{
d62a17ae 4836 int idx_peer = 1;
4837 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4838}
4839
4840DEFUN (no_neighbor_passive,
4841 no_neighbor_passive_cmd,
9ccf14f7 4842 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 4843 NO_STR
4844 NEIGHBOR_STR
4845 NEIGHBOR_ADDR_STR2
4846 "Don't send open messages to this neighbor\n")
4847{
d62a17ae 4848 int idx_peer = 2;
4849 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 4850}
6b0655a2 4851
718e3744 4852/* neighbor shutdown. */
73d70fa6
DL
4853DEFUN (neighbor_shutdown_msg,
4854 neighbor_shutdown_msg_cmd,
4855 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
73d70fa6 4858 "Administratively shut down this neighbor\n"
70335e0a 4859 "Add a shutdown message (RFC 8203)\n"
73d70fa6 4860 "Shutdown message\n")
718e3744 4861{
d62a17ae 4862 int idx_peer = 1;
73d70fa6 4863
d62a17ae 4864 if (argc >= 5) {
4865 struct peer *peer =
4866 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4867 char *message;
73d70fa6 4868
d62a17ae 4869 if (!peer)
4870 return CMD_WARNING_CONFIG_FAILED;
4871 message = argv_concat(argv, argc, 4);
4872 peer_tx_shutdown_message_set(peer, message);
4873 XFREE(MTYPE_TMP, message);
4874 }
73d70fa6 4875
d62a17ae 4876 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 4877}
4878
d62a17ae 4879ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
4880 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4882 "Administratively shut down this neighbor\n")
73d70fa6
DL
4883
4884DEFUN (no_neighbor_shutdown_msg,
4885 no_neighbor_shutdown_msg_cmd,
4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Administratively shut down this neighbor\n"
70335e0a 4891 "Remove a shutdown message (RFC 8203)\n"
73d70fa6 4892 "Shutdown message\n")
718e3744 4893{
d62a17ae 4894 int idx_peer = 2;
73d70fa6 4895
d62a17ae 4896 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4897 PEER_FLAG_SHUTDOWN);
718e3744 4898}
6b0655a2 4899
d62a17ae 4900ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
4901 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
4902 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4903 "Administratively shut down this neighbor\n")
73d70fa6 4904
8336c896
DA
4905DEFUN(neighbor_shutdown_rtt,
4906 neighbor_shutdown_rtt_cmd,
4907 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
4908 NEIGHBOR_STR
4909 NEIGHBOR_ADDR_STR2
4910 "Administratively shut down this neighbor\n"
4911 "Shutdown if round-trip-time is higher than expected\n"
4912 "Round-trip-time in milliseconds\n"
4913 "Specify the number of keepalives before shutdown\n"
4914 "The number of keepalives with higher RTT to shutdown\n")
4915{
4916 int idx_peer = 1;
4917 int idx_rtt = 4;
4918 int idx_count = 0;
4919 struct peer *peer;
4920
4921 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4922
4923 if (!peer)
4924 return CMD_WARNING_CONFIG_FAILED;
4925
4926 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
4927
4928 if (argv_find(argv, argc, "count", &idx_count))
4929 peer->rtt_keepalive_conf =
4930 strtol(argv[idx_count + 1]->arg, NULL, 10);
4931
4932 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4933 PEER_FLAG_RTT_SHUTDOWN);
4934}
4935
4936DEFUN(no_neighbor_shutdown_rtt,
4937 no_neighbor_shutdown_rtt_cmd,
4938 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
4939 NO_STR
4940 NEIGHBOR_STR
4941 NEIGHBOR_ADDR_STR2
4942 "Administratively shut down this neighbor\n"
4943 "Shutdown if round-trip-time is higher than expected\n"
4944 "Round-trip-time in milliseconds\n"
4945 "Specify the number of keepalives before shutdown\n"
4946 "The number of keepalives with higher RTT to shutdown\n")
4947{
4948 int idx_peer = 2;
4949 struct peer *peer;
4950
4951 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4952
4953 if (!peer)
4954 return CMD_WARNING_CONFIG_FAILED;
4955
4956 peer->rtt_expected = 0;
4957 peer->rtt_keepalive_conf = 1;
4958
4959 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4960 PEER_FLAG_RTT_SHUTDOWN);
4961}
4962
718e3744 4963/* neighbor capability dynamic. */
4964DEFUN (neighbor_capability_dynamic,
4965 neighbor_capability_dynamic_cmd,
9ccf14f7 4966 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
4969 "Advertise capability to the peer\n"
4970 "Advertise dynamic capability to this neighbor\n")
4971{
d62a17ae 4972 int idx_peer = 1;
4973 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4974 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4975}
4976
4977DEFUN (no_neighbor_capability_dynamic,
4978 no_neighbor_capability_dynamic_cmd,
9ccf14f7 4979 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 4980 NO_STR
4981 NEIGHBOR_STR
4982 NEIGHBOR_ADDR_STR2
4983 "Advertise capability to the peer\n"
4984 "Advertise dynamic capability to this neighbor\n")
4985{
d62a17ae 4986 int idx_peer = 2;
4987 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 4989}
6b0655a2 4990
718e3744 4991/* neighbor dont-capability-negotiate */
4992DEFUN (neighbor_dont_capability_negotiate,
4993 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 4994 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Do not perform capability negotiation\n")
4998{
d62a17ae 4999 int idx_peer = 1;
5000 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5001 PEER_FLAG_DONT_CAPABILITY);
718e3744 5002}
5003
5004DEFUN (no_neighbor_dont_capability_negotiate,
5005 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5006 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR2
5010 "Do not perform capability negotiation\n")
5011{
d62a17ae 5012 int idx_peer = 2;
5013 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5014 PEER_FLAG_DONT_CAPABILITY);
718e3744 5015}
6b0655a2 5016
8a92a8a0
DS
5017/* neighbor capability extended next hop encoding */
5018DEFUN (neighbor_capability_enhe,
5019 neighbor_capability_enhe_cmd,
9ccf14f7 5020 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5021 NEIGHBOR_STR
5022 NEIGHBOR_ADDR_STR2
5023 "Advertise capability to the peer\n"
5024 "Advertise extended next-hop capability to the peer\n")
5025{
d62a17ae 5026 int idx_peer = 1;
5027 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5028 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5029}
5030
5031DEFUN (no_neighbor_capability_enhe,
5032 no_neighbor_capability_enhe_cmd,
9ccf14f7 5033 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
5034 NO_STR
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "Advertise capability to the peer\n"
5038 "Advertise extended next-hop capability to the peer\n")
5039{
d62a17ae 5040 int idx_peer = 2;
5041 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5042 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
5043}
5044
d62a17ae 5045static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5046 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5047 int set)
718e3744 5048{
d62a17ae 5049 int ret;
5050 struct peer *peer;
718e3744 5051
d62a17ae 5052 peer = peer_and_group_lookup_vty(vty, peer_str);
5053 if (!peer)
5054 return CMD_WARNING_CONFIG_FAILED;
718e3744 5055
d62a17ae 5056 if (set)
5057 ret = peer_af_flag_set(peer, afi, safi, flag);
5058 else
5059 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5060
d62a17ae 5061 return bgp_vty_return(vty, ret);
718e3744 5062}
5063
d62a17ae 5064static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5065 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5066{
d62a17ae 5067 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5068}
5069
d62a17ae 5070static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5071 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5072{
d62a17ae 5073 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5074}
6b0655a2 5075
718e3744 5076/* neighbor capability orf prefix-list. */
5077DEFUN (neighbor_capability_orf_prefix,
5078 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5079 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Advertise capability to the peer\n"
5083 "Advertise ORF capability to the peer\n"
5084 "Advertise prefixlist ORF capability to this neighbor\n"
5085 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5086 "Capability to RECEIVE the ORF from this neighbor\n"
5087 "Capability to SEND the ORF to this neighbor\n")
5088{
d62a17ae 5089 int idx_send_recv = 5;
db45f64d
DS
5090 char *peer_str = argv[1]->arg;
5091 struct peer *peer;
5092 afi_t afi = bgp_node_afi(vty);
5093 safi_t safi = bgp_node_safi(vty);
d62a17ae 5094
db45f64d
DS
5095 peer = peer_and_group_lookup_vty(vty, peer_str);
5096 if (!peer)
d62a17ae 5097 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5098
db45f64d
DS
5099 if (strmatch(argv[idx_send_recv]->text, "send"))
5100 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5101 PEER_FLAG_ORF_PREFIX_SM);
5102
5103 if (strmatch(argv[idx_send_recv]->text, "receive"))
5104 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5105 PEER_FLAG_ORF_PREFIX_RM);
5106
5107 if (strmatch(argv[idx_send_recv]->text, "both"))
5108 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5109 PEER_FLAG_ORF_PREFIX_SM)
5110 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5111 PEER_FLAG_ORF_PREFIX_RM);
5112
5113 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5114}
5115
5116ALIAS_HIDDEN(
5117 neighbor_capability_orf_prefix,
5118 neighbor_capability_orf_prefix_hidden_cmd,
5119 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5120 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5121 "Advertise capability to the peer\n"
5122 "Advertise ORF capability to the peer\n"
5123 "Advertise prefixlist ORF capability to this neighbor\n"
5124 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5125 "Capability to RECEIVE the ORF from this neighbor\n"
5126 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5127
718e3744 5128DEFUN (no_neighbor_capability_orf_prefix,
5129 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5130 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5131 NO_STR
5132 NEIGHBOR_STR
5133 NEIGHBOR_ADDR_STR2
5134 "Advertise capability to the peer\n"
5135 "Advertise ORF capability to the peer\n"
5136 "Advertise prefixlist ORF capability to this neighbor\n"
5137 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5138 "Capability to RECEIVE the ORF from this neighbor\n"
5139 "Capability to SEND the ORF to this neighbor\n")
5140{
d62a17ae 5141 int idx_send_recv = 6;
db45f64d
DS
5142 char *peer_str = argv[2]->arg;
5143 struct peer *peer;
5144 afi_t afi = bgp_node_afi(vty);
5145 safi_t safi = bgp_node_safi(vty);
d62a17ae 5146
db45f64d
DS
5147 peer = peer_and_group_lookup_vty(vty, peer_str);
5148 if (!peer)
d62a17ae 5149 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5150
db45f64d
DS
5151 if (strmatch(argv[idx_send_recv]->text, "send"))
5152 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5153 PEER_FLAG_ORF_PREFIX_SM);
5154
5155 if (strmatch(argv[idx_send_recv]->text, "receive"))
5156 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5157 PEER_FLAG_ORF_PREFIX_RM);
5158
5159 if (strmatch(argv[idx_send_recv]->text, "both"))
5160 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5161 PEER_FLAG_ORF_PREFIX_SM)
5162 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5163 PEER_FLAG_ORF_PREFIX_RM);
5164
5165 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5166}
5167
5168ALIAS_HIDDEN(
5169 no_neighbor_capability_orf_prefix,
5170 no_neighbor_capability_orf_prefix_hidden_cmd,
5171 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5173 "Advertise capability to the peer\n"
5174 "Advertise ORF capability to the peer\n"
5175 "Advertise prefixlist ORF capability to this neighbor\n"
5176 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5177 "Capability to RECEIVE the ORF from this neighbor\n"
5178 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5179
718e3744 5180/* neighbor next-hop-self. */
5181DEFUN (neighbor_nexthop_self,
5182 neighbor_nexthop_self_cmd,
9ccf14f7 5183 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5184 NEIGHBOR_STR
5185 NEIGHBOR_ADDR_STR2
a538debe 5186 "Disable the next hop calculation for this neighbor\n")
718e3744 5187{
d62a17ae 5188 int idx_peer = 1;
5189 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5190 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 5191}
9e7a53c1 5192
d62a17ae 5193ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5194 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5195 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5196 "Disable the next hop calculation for this neighbor\n")
596c17ba 5197
a538debe
DS
5198/* neighbor next-hop-self. */
5199DEFUN (neighbor_nexthop_self_force,
5200 neighbor_nexthop_self_force_cmd,
9ccf14f7 5201 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5202 NEIGHBOR_STR
5203 NEIGHBOR_ADDR_STR2
5204 "Disable the next hop calculation for this neighbor\n"
5205 "Set the next hop to self for reflected routes\n")
5206{
d62a17ae 5207 int idx_peer = 1;
5208 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5209 bgp_node_safi(vty),
5210 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 5211}
5212
d62a17ae 5213ALIAS_HIDDEN(neighbor_nexthop_self_force,
5214 neighbor_nexthop_self_force_hidden_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5216 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5217 "Disable the next hop calculation for this neighbor\n"
5218 "Set the next hop to self for reflected routes\n")
596c17ba 5219
1bc4e531
DA
5220ALIAS_HIDDEN(neighbor_nexthop_self_force,
5221 neighbor_nexthop_self_all_hidden_cmd,
5222 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5223 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5224 "Disable the next hop calculation for this neighbor\n"
5225 "Set the next hop to self for reflected routes\n")
5226
718e3744 5227DEFUN (no_neighbor_nexthop_self,
5228 no_neighbor_nexthop_self_cmd,
9ccf14f7 5229 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 5230 NO_STR
5231 NEIGHBOR_STR
5232 NEIGHBOR_ADDR_STR2
a538debe 5233 "Disable the next hop calculation for this neighbor\n")
718e3744 5234{
d62a17ae 5235 int idx_peer = 2;
5236 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5237 bgp_node_afi(vty), bgp_node_safi(vty),
5238 PEER_FLAG_NEXTHOP_SELF);
718e3744 5239}
6b0655a2 5240
d62a17ae 5241ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5242 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5243 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5244 "Disable the next hop calculation for this neighbor\n")
596c17ba 5245
88b8ed8d 5246DEFUN (no_neighbor_nexthop_self_force,
a538debe 5247 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
5249 NO_STR
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "Disable the next hop calculation for this neighbor\n"
5253 "Set the next hop to self for reflected routes\n")
88b8ed8d 5254{
d62a17ae 5255 int idx_peer = 2;
5256 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5257 bgp_node_afi(vty), bgp_node_safi(vty),
5258 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 5259}
a538debe 5260
d62a17ae 5261ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5262 no_neighbor_nexthop_self_force_hidden_cmd,
5263 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5265 "Disable the next hop calculation for this neighbor\n"
5266 "Set the next hop to self for reflected routes\n")
596c17ba 5267
1bc4e531
DA
5268ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5269 no_neighbor_nexthop_self_all_hidden_cmd,
5270 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5271 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5272 "Disable the next hop calculation for this neighbor\n"
5273 "Set the next hop to self for reflected routes\n")
5274
c7122e14
DS
5275/* neighbor as-override */
5276DEFUN (neighbor_as_override,
5277 neighbor_as_override_cmd,
9ccf14f7 5278 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Override ASNs in outbound updates if aspath equals remote-as\n")
5282{
d62a17ae 5283 int idx_peer = 1;
5284 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5285 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5286}
5287
d62a17ae 5288ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5289 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5291 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5292
c7122e14
DS
5293DEFUN (no_neighbor_as_override,
5294 no_neighbor_as_override_cmd,
9ccf14f7 5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Override ASNs in outbound updates if aspath equals remote-as\n")
5300{
d62a17ae 5301 int idx_peer = 2;
5302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5303 bgp_node_afi(vty), bgp_node_safi(vty),
5304 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
5305}
5306
d62a17ae 5307ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5308 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5310 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5311
718e3744 5312/* neighbor remove-private-AS. */
5313DEFUN (neighbor_remove_private_as,
5314 neighbor_remove_private_as_cmd,
9ccf14f7 5315 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5316 NEIGHBOR_STR
5317 NEIGHBOR_ADDR_STR2
5000f21c 5318 "Remove private ASNs in outbound updates\n")
718e3744 5319{
d62a17ae 5320 int idx_peer = 1;
5321 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5322 bgp_node_safi(vty),
5323 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5324}
5325
d62a17ae 5326ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5327 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5328 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5329 "Remove private ASNs in outbound updates\n")
596c17ba 5330
5000f21c
DS
5331DEFUN (neighbor_remove_private_as_all,
5332 neighbor_remove_private_as_all_cmd,
9ccf14f7 5333 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5334 NEIGHBOR_STR
5335 NEIGHBOR_ADDR_STR2
5336 "Remove private ASNs in outbound updates\n"
efd7904e 5337 "Apply to all AS numbers\n")
5000f21c 5338{
d62a17ae 5339 int idx_peer = 1;
5340 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5341 bgp_node_safi(vty),
5342 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
5343}
5344
d62a17ae 5345ALIAS_HIDDEN(neighbor_remove_private_as_all,
5346 neighbor_remove_private_as_all_hidden_cmd,
5347 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5348 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5349 "Remove private ASNs in outbound updates\n"
5350 "Apply to all AS numbers")
596c17ba 5351
5000f21c
DS
5352DEFUN (neighbor_remove_private_as_replace_as,
5353 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5354 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5355 NEIGHBOR_STR
5356 NEIGHBOR_ADDR_STR2
5357 "Remove private ASNs in outbound updates\n"
5358 "Replace private ASNs with our ASN in outbound updates\n")
5359{
d62a17ae 5360 int idx_peer = 1;
5361 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5362 bgp_node_safi(vty),
5363 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
5364}
5365
d62a17ae 5366ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5367 neighbor_remove_private_as_replace_as_hidden_cmd,
5368 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5369 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5370 "Remove private ASNs in outbound updates\n"
5371 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5372
5000f21c
DS
5373DEFUN (neighbor_remove_private_as_all_replace_as,
5374 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5375 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5376 NEIGHBOR_STR
5377 NEIGHBOR_ADDR_STR2
5378 "Remove private ASNs in outbound updates\n"
16cedbb0 5379 "Apply to all AS numbers\n"
5000f21c
DS
5380 "Replace private ASNs with our ASN in outbound updates\n")
5381{
d62a17ae 5382 int idx_peer = 1;
5383 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5384 bgp_node_safi(vty),
5385 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
5386}
5387
d62a17ae 5388ALIAS_HIDDEN(
5389 neighbor_remove_private_as_all_replace_as,
5390 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5391 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5393 "Remove private ASNs in outbound updates\n"
5394 "Apply to all AS numbers\n"
5395 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5396
718e3744 5397DEFUN (no_neighbor_remove_private_as,
5398 no_neighbor_remove_private_as_cmd,
9ccf14f7 5399 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 5400 NO_STR
5401 NEIGHBOR_STR
5402 NEIGHBOR_ADDR_STR2
5000f21c 5403 "Remove private ASNs in outbound updates\n")
718e3744 5404{
d62a17ae 5405 int idx_peer = 2;
5406 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5407 bgp_node_afi(vty), bgp_node_safi(vty),
5408 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 5409}
6b0655a2 5410
d62a17ae 5411ALIAS_HIDDEN(no_neighbor_remove_private_as,
5412 no_neighbor_remove_private_as_hidden_cmd,
5413 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5414 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5415 "Remove private ASNs in outbound updates\n")
596c17ba 5416
88b8ed8d 5417DEFUN (no_neighbor_remove_private_as_all,
5000f21c 5418 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 5419 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
5420 NO_STR
5421 NEIGHBOR_STR
5422 NEIGHBOR_ADDR_STR2
5423 "Remove private ASNs in outbound updates\n"
16cedbb0 5424 "Apply to all AS numbers\n")
88b8ed8d 5425{
d62a17ae 5426 int idx_peer = 2;
5427 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5428 bgp_node_afi(vty), bgp_node_safi(vty),
5429 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 5430}
5000f21c 5431
d62a17ae 5432ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
5433 no_neighbor_remove_private_as_all_hidden_cmd,
5434 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5435 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5436 "Remove private ASNs in outbound updates\n"
5437 "Apply to all AS numbers\n")
596c17ba 5438
88b8ed8d 5439DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 5440 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 5441 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
5442 NO_STR
5443 NEIGHBOR_STR
5444 NEIGHBOR_ADDR_STR2
5445 "Remove private ASNs in outbound updates\n"
5446 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5447{
d62a17ae 5448 int idx_peer = 2;
5449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5450 bgp_node_afi(vty), bgp_node_safi(vty),
5451 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 5452}
5000f21c 5453
d62a17ae 5454ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
5455 no_neighbor_remove_private_as_replace_as_hidden_cmd,
5456 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5458 "Remove private ASNs in outbound updates\n"
5459 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5460
88b8ed8d 5461DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 5462 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 5463 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
5464 NO_STR
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Remove private ASNs in outbound updates\n"
16cedbb0 5468 "Apply to all AS numbers\n"
5000f21c 5469 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 5470{
d62a17ae 5471 int idx_peer = 2;
5472 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5473 bgp_node_afi(vty), bgp_node_safi(vty),
5474 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 5475}
5000f21c 5476
d62a17ae 5477ALIAS_HIDDEN(
5478 no_neighbor_remove_private_as_all_replace_as,
5479 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
5480 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5482 "Remove private ASNs in outbound updates\n"
5483 "Apply to all AS numbers\n"
5484 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5485
5000f21c 5486
718e3744 5487/* neighbor send-community. */
5488DEFUN (neighbor_send_community,
5489 neighbor_send_community_cmd,
9ccf14f7 5490 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Send Community attribute to this neighbor\n")
5494{
d62a17ae 5495 int idx_peer = 1;
27c05d4d 5496
d62a17ae 5497 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5498 bgp_node_safi(vty),
5499 PEER_FLAG_SEND_COMMUNITY);
718e3744 5500}
5501
d62a17ae 5502ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
5503 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5504 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5505 "Send Community attribute to this neighbor\n")
596c17ba 5506
718e3744 5507DEFUN (no_neighbor_send_community,
5508 no_neighbor_send_community_cmd,
9ccf14f7 5509 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 5510 NO_STR
5511 NEIGHBOR_STR
5512 NEIGHBOR_ADDR_STR2
5513 "Send Community attribute to this neighbor\n")
5514{
d62a17ae 5515 int idx_peer = 2;
27c05d4d 5516
d62a17ae 5517 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5518 bgp_node_afi(vty), bgp_node_safi(vty),
5519 PEER_FLAG_SEND_COMMUNITY);
718e3744 5520}
6b0655a2 5521
d62a17ae 5522ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
5523 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
5524 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5525 "Send Community attribute to this neighbor\n")
596c17ba 5526
718e3744 5527/* neighbor send-community extended. */
5528DEFUN (neighbor_send_community_type,
5529 neighbor_send_community_type_cmd,
57d187bc 5530 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Send Community attribute to this neighbor\n"
5534 "Send Standard and Extended Community attributes\n"
57d187bc 5535 "Send Standard, Large and Extended Community attributes\n"
718e3744 5536 "Send Extended Community attributes\n"
57d187bc
JS
5537 "Send Standard Community attributes\n"
5538 "Send Large Community attributes\n")
718e3744 5539{
27c05d4d 5540 const char *type = argv[argc - 1]->text;
db45f64d
DS
5541 char *peer_str = argv[1]->arg;
5542 struct peer *peer;
5543 afi_t afi = bgp_node_afi(vty);
5544 safi_t safi = bgp_node_safi(vty);
d62a17ae 5545
db45f64d
DS
5546 peer = peer_and_group_lookup_vty(vty, peer_str);
5547 if (!peer)
5548 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5549
db45f64d
DS
5550 if (strmatch(type, "standard"))
5551 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5552 PEER_FLAG_SEND_COMMUNITY);
5553
5554 if (strmatch(type, "extended"))
5555 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5556 PEER_FLAG_SEND_EXT_COMMUNITY);
5557
5558 if (strmatch(type, "large"))
5559 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5560 PEER_FLAG_SEND_LARGE_COMMUNITY);
5561
5562 if (strmatch(type, "both")) {
5563 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5564 PEER_FLAG_SEND_COMMUNITY)
5565 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5566 PEER_FLAG_SEND_EXT_COMMUNITY);
5567 }
5568 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5569 PEER_FLAG_SEND_COMMUNITY)
5570 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5571 PEER_FLAG_SEND_EXT_COMMUNITY)
5572 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5573 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5574}
5575
5576ALIAS_HIDDEN(
5577 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
5578 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5579 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5580 "Send Community attribute to this neighbor\n"
5581 "Send Standard and Extended Community attributes\n"
5582 "Send Standard, Large and Extended Community attributes\n"
5583 "Send Extended Community attributes\n"
5584 "Send Standard Community attributes\n"
5585 "Send Large Community attributes\n")
596c17ba 5586
718e3744 5587DEFUN (no_neighbor_send_community_type,
5588 no_neighbor_send_community_type_cmd,
57d187bc 5589 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 5590 NO_STR
5591 NEIGHBOR_STR
5592 NEIGHBOR_ADDR_STR2
5593 "Send Community attribute to this neighbor\n"
5594 "Send Standard and Extended Community attributes\n"
57d187bc 5595 "Send Standard, Large and Extended Community attributes\n"
718e3744 5596 "Send Extended Community attributes\n"
57d187bc
JS
5597 "Send Standard Community attributes\n"
5598 "Send Large Community attributes\n")
718e3744 5599{
d62a17ae 5600 const char *type = argv[argc - 1]->text;
db45f64d
DS
5601 char *peer_str = argv[2]->arg;
5602 struct peer *peer;
5603 afi_t afi = bgp_node_afi(vty);
5604 safi_t safi = bgp_node_safi(vty);
5605
5606 peer = peer_and_group_lookup_vty(vty, peer_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 if (strmatch(type, "standard"))
5611 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5612 PEER_FLAG_SEND_COMMUNITY);
5613
5614 if (strmatch(type, "extended"))
5615 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5616 PEER_FLAG_SEND_EXT_COMMUNITY);
5617
5618 if (strmatch(type, "large"))
5619 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5620 PEER_FLAG_SEND_LARGE_COMMUNITY);
5621
5622 if (strmatch(type, "both")) {
d62a17ae 5623
db45f64d
DS
5624 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5625 PEER_FLAG_SEND_COMMUNITY)
5626 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5627 PEER_FLAG_SEND_EXT_COMMUNITY);
27c05d4d
PM
5628 }
5629
db45f64d
DS
5630 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5631 PEER_FLAG_SEND_COMMUNITY)
5632 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5633 PEER_FLAG_SEND_EXT_COMMUNITY)
5634 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5635 PEER_FLAG_SEND_LARGE_COMMUNITY);
d62a17ae 5636}
5637
5638ALIAS_HIDDEN(
5639 no_neighbor_send_community_type,
5640 no_neighbor_send_community_type_hidden_cmd,
5641 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
5642 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Send Community attribute to this neighbor\n"
5644 "Send Standard and Extended Community attributes\n"
5645 "Send Standard, Large and Extended Community attributes\n"
5646 "Send Extended Community attributes\n"
5647 "Send Standard Community attributes\n"
5648 "Send Large Community attributes\n")
596c17ba 5649
718e3744 5650/* neighbor soft-reconfig. */
5651DEFUN (neighbor_soft_reconfiguration,
5652 neighbor_soft_reconfiguration_cmd,
9ccf14f7 5653 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5654 NEIGHBOR_STR
5655 NEIGHBOR_ADDR_STR2
5656 "Per neighbor soft reconfiguration\n"
5657 "Allow inbound soft reconfiguration for this neighbor\n")
5658{
d62a17ae 5659 int idx_peer = 1;
5660 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5661 bgp_node_safi(vty),
5662 PEER_FLAG_SOFT_RECONFIG);
718e3744 5663}
5664
d62a17ae 5665ALIAS_HIDDEN(neighbor_soft_reconfiguration,
5666 neighbor_soft_reconfiguration_hidden_cmd,
5667 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5668 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Per neighbor soft reconfiguration\n"
5670 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5671
718e3744 5672DEFUN (no_neighbor_soft_reconfiguration,
5673 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 5674 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 5675 NO_STR
5676 NEIGHBOR_STR
5677 NEIGHBOR_ADDR_STR2
5678 "Per neighbor soft reconfiguration\n"
5679 "Allow inbound soft reconfiguration for this neighbor\n")
5680{
d62a17ae 5681 int idx_peer = 2;
5682 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5683 bgp_node_afi(vty), bgp_node_safi(vty),
5684 PEER_FLAG_SOFT_RECONFIG);
718e3744 5685}
6b0655a2 5686
d62a17ae 5687ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
5688 no_neighbor_soft_reconfiguration_hidden_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
5690 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5691 "Per neighbor soft reconfiguration\n"
5692 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 5693
718e3744 5694DEFUN (neighbor_route_reflector_client,
5695 neighbor_route_reflector_client_cmd,
9ccf14f7 5696 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Configure a neighbor as Route Reflector client\n")
5700{
d62a17ae 5701 int idx_peer = 1;
5702 struct peer *peer;
718e3744 5703
5704
d62a17ae 5705 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5706 if (!peer)
5707 return CMD_WARNING_CONFIG_FAILED;
718e3744 5708
d62a17ae 5709 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5710 bgp_node_safi(vty),
5711 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5712}
5713
d62a17ae 5714ALIAS_HIDDEN(neighbor_route_reflector_client,
5715 neighbor_route_reflector_client_hidden_cmd,
5716 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5718 "Configure a neighbor as Route Reflector client\n")
596c17ba 5719
718e3744 5720DEFUN (no_neighbor_route_reflector_client,
5721 no_neighbor_route_reflector_client_cmd,
9ccf14f7 5722 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 5723 NO_STR
5724 NEIGHBOR_STR
5725 NEIGHBOR_ADDR_STR2
5726 "Configure a neighbor as Route Reflector client\n")
5727{
d62a17ae 5728 int idx_peer = 2;
5729 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5730 bgp_node_afi(vty), bgp_node_safi(vty),
5731 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 5732}
6b0655a2 5733
d62a17ae 5734ALIAS_HIDDEN(no_neighbor_route_reflector_client,
5735 no_neighbor_route_reflector_client_hidden_cmd,
5736 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
5737 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Configure a neighbor as Route Reflector client\n")
596c17ba 5739
718e3744 5740/* neighbor route-server-client. */
5741DEFUN (neighbor_route_server_client,
5742 neighbor_route_server_client_cmd,
9ccf14f7 5743 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Configure a neighbor as Route Server client\n")
5747{
d62a17ae 5748 int idx_peer = 1;
5749 struct peer *peer;
2a3d5731 5750
d62a17ae 5751 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5752 if (!peer)
5753 return CMD_WARNING_CONFIG_FAILED;
5754 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5755 bgp_node_safi(vty),
5756 PEER_FLAG_RSERVER_CLIENT);
718e3744 5757}
5758
d62a17ae 5759ALIAS_HIDDEN(neighbor_route_server_client,
5760 neighbor_route_server_client_hidden_cmd,
5761 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5762 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5763 "Configure a neighbor as Route Server client\n")
596c17ba 5764
718e3744 5765DEFUN (no_neighbor_route_server_client,
5766 no_neighbor_route_server_client_cmd,
9ccf14f7 5767 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 5768 NO_STR
5769 NEIGHBOR_STR
5770 NEIGHBOR_ADDR_STR2
5771 "Configure a neighbor as Route Server client\n")
fee0f4c6 5772{
d62a17ae 5773 int idx_peer = 2;
5774 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5775 bgp_node_afi(vty), bgp_node_safi(vty),
5776 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 5777}
6b0655a2 5778
d62a17ae 5779ALIAS_HIDDEN(no_neighbor_route_server_client,
5780 no_neighbor_route_server_client_hidden_cmd,
5781 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
5782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5783 "Configure a neighbor as Route Server client\n")
596c17ba 5784
fee0f4c6 5785DEFUN (neighbor_nexthop_local_unchanged,
5786 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5787 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5788 NEIGHBOR_STR
5789 NEIGHBOR_ADDR_STR2
5790 "Configure treatment of outgoing link-local nexthop attribute\n"
5791 "Leave link-local nexthop unchanged for this peer\n")
5792{
d62a17ae 5793 int idx_peer = 1;
5794 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5795 bgp_node_safi(vty),
5796 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 5797}
6b0655a2 5798
fee0f4c6 5799DEFUN (no_neighbor_nexthop_local_unchanged,
5800 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 5801 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 5802 NO_STR
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Configure treatment of outgoing link-local-nexthop attribute\n"
5806 "Leave link-local nexthop unchanged for this peer\n")
718e3744 5807{
d62a17ae 5808 int idx_peer = 2;
5809 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5810 bgp_node_afi(vty), bgp_node_safi(vty),
5811 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 5812}
6b0655a2 5813
718e3744 5814DEFUN (neighbor_attr_unchanged,
5815 neighbor_attr_unchanged_cmd,
a8206004 5816 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 5817 NEIGHBOR_STR
5818 NEIGHBOR_ADDR_STR2
5819 "BGP attribute is propagated unchanged to this neighbor\n"
5820 "As-path attribute\n"
5821 "Nexthop attribute\n"
a8206004 5822 "Med attribute\n")
718e3744 5823{
d62a17ae 5824 int idx = 0;
8eeb0335
DW
5825 char *peer_str = argv[1]->arg;
5826 struct peer *peer;
db45f64d
DS
5827 bool aspath = false;
5828 bool nexthop = false;
5829 bool med = false;
8eeb0335
DW
5830 afi_t afi = bgp_node_afi(vty);
5831 safi_t safi = bgp_node_safi(vty);
db45f64d 5832 int ret = 0;
8eeb0335
DW
5833
5834 peer = peer_and_group_lookup_vty(vty, peer_str);
5835 if (!peer)
5836 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5837
5838 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5839 aspath = true;
5840
d62a17ae 5841 idx = 0;
5842 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5843 nexthop = true;
5844
d62a17ae 5845 idx = 0;
5846 if (argv_find(argv, argc, "med", &idx))
db45f64d 5847 med = true;
d62a17ae 5848
8eeb0335 5849 /* no flags means all of them! */
db45f64d
DS
5850 if (!aspath && !nexthop && !med) {
5851 ret = peer_af_flag_set_vty(vty, peer_str, afi, safi,
5852 PEER_FLAG_AS_PATH_UNCHANGED);
5853 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5854 PEER_FLAG_NEXTHOP_UNCHANGED);
5855 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5856 PEER_FLAG_MED_UNCHANGED);
8eeb0335 5857 } else {
db45f64d
DS
5858 if (!aspath) {
5859 if (peer_af_flag_check(peer, afi, safi,
5860 PEER_FLAG_AS_PATH_UNCHANGED)) {
5861 ret |= peer_af_flag_unset_vty(
5862 vty, peer_str, afi, safi,
5863 PEER_FLAG_AS_PATH_UNCHANGED);
5864 }
5865 } else
5866 ret |= peer_af_flag_set_vty(
5867 vty, peer_str, afi, safi,
5868 PEER_FLAG_AS_PATH_UNCHANGED);
5869
5870 if (!nexthop) {
5871 if (peer_af_flag_check(peer, afi, safi,
5872 PEER_FLAG_NEXTHOP_UNCHANGED)) {
5873 ret |= peer_af_flag_unset_vty(
5874 vty, peer_str, afi, safi,
5875 PEER_FLAG_NEXTHOP_UNCHANGED);
5876 }
5877 } else
5878 ret |= peer_af_flag_set_vty(
5879 vty, peer_str, afi, safi,
5880 PEER_FLAG_NEXTHOP_UNCHANGED);
5881
5882 if (!med) {
5883 if (peer_af_flag_check(peer, afi, safi,
5884 PEER_FLAG_MED_UNCHANGED)) {
5885 ret |= peer_af_flag_unset_vty(
5886 vty, peer_str, afi, safi,
5887 PEER_FLAG_MED_UNCHANGED);
5888 }
5889 } else
5890 ret |= peer_af_flag_set_vty(vty, peer_str, afi, safi,
5891 PEER_FLAG_MED_UNCHANGED);
d62a17ae 5892 }
5893
db45f64d 5894 return ret;
d62a17ae 5895}
5896
5897ALIAS_HIDDEN(
5898 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
5899 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5900 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "BGP attribute is propagated unchanged to this neighbor\n"
5902 "As-path attribute\n"
5903 "Nexthop attribute\n"
5904 "Med attribute\n")
596c17ba 5905
718e3744 5906DEFUN (no_neighbor_attr_unchanged,
5907 no_neighbor_attr_unchanged_cmd,
a8206004 5908 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 5909 NO_STR
718e3744 5910 NEIGHBOR_STR
5911 NEIGHBOR_ADDR_STR2
31500417
DW
5912 "BGP attribute is propagated unchanged to this neighbor\n"
5913 "As-path attribute\n"
40e718b5 5914 "Nexthop attribute\n"
a8206004 5915 "Med attribute\n")
718e3744 5916{
d62a17ae 5917 int idx = 0;
db45f64d
DS
5918 char *peer_str = argv[2]->arg;
5919 struct peer *peer;
5920 bool aspath = false;
5921 bool nexthop = false;
5922 bool med = false;
5923 afi_t afi = bgp_node_afi(vty);
5924 safi_t safi = bgp_node_safi(vty);
5925 int ret = 0;
5926
5927 peer = peer_and_group_lookup_vty(vty, peer_str);
5928 if (!peer)
5929 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5930
5931 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
5932 aspath = true;
5933
d62a17ae 5934 idx = 0;
5935 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
5936 nexthop = true;
5937
d62a17ae 5938 idx = 0;
5939 if (argv_find(argv, argc, "med", &idx))
db45f64d 5940 med = true;
d62a17ae 5941
db45f64d
DS
5942 if (!aspath && !nexthop && !med) // no flags means all of them!
5943 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5944 PEER_FLAG_AS_PATH_UNCHANGED)
5945 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5946 PEER_FLAG_NEXTHOP_UNCHANGED)
5947 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5948 PEER_FLAG_MED_UNCHANGED);
5949
5950 if (aspath)
5951 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5952 PEER_FLAG_AS_PATH_UNCHANGED);
5953
5954 if (nexthop)
5955 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5956 PEER_FLAG_NEXTHOP_UNCHANGED);
d62a17ae 5957
db45f64d
DS
5958 if (med)
5959 ret |= peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5960 PEER_FLAG_MED_UNCHANGED);
5961
5962 return ret;
d62a17ae 5963}
5964
5965ALIAS_HIDDEN(
5966 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
5968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "BGP attribute is propagated unchanged to this neighbor\n"
5970 "As-path attribute\n"
5971 "Nexthop attribute\n"
5972 "Med attribute\n")
718e3744 5973
718e3744 5974/* EBGP multihop configuration. */
d62a17ae 5975static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
5976 const char *ttl_str)
718e3744 5977{
d62a17ae 5978 struct peer *peer;
5979 unsigned int ttl;
718e3744 5980
d62a17ae 5981 peer = peer_and_group_lookup_vty(vty, ip_str);
5982 if (!peer)
5983 return CMD_WARNING_CONFIG_FAILED;
718e3744 5984
d62a17ae 5985 if (peer->conf_if)
5986 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 5987
d62a17ae 5988 if (!ttl_str)
5989 ttl = MAXTTL;
5990 else
5991 ttl = strtoul(ttl_str, NULL, 10);
718e3744 5992
d62a17ae 5993 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 5994}
5995
d62a17ae 5996static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5997{
d62a17ae 5998 struct peer *peer;
718e3744 5999
d62a17ae 6000 peer = peer_and_group_lookup_vty(vty, ip_str);
6001 if (!peer)
6002 return CMD_WARNING_CONFIG_FAILED;
718e3744 6003
d62a17ae 6004 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 6005}
6006
6007/* neighbor ebgp-multihop. */
6008DEFUN (neighbor_ebgp_multihop,
6009 neighbor_ebgp_multihop_cmd,
9ccf14f7 6010 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "Allow EBGP neighbors not on directly connected networks\n")
6014{
d62a17ae 6015 int idx_peer = 1;
6016 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6017}
6018
6019DEFUN (neighbor_ebgp_multihop_ttl,
6020 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 6021 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 6022 NEIGHBOR_STR
6023 NEIGHBOR_ADDR_STR2
6024 "Allow EBGP neighbors not on directly connected networks\n"
6025 "maximum hop count\n")
6026{
d62a17ae 6027 int idx_peer = 1;
6028 int idx_number = 3;
6029 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
6030 argv[idx_number]->arg);
718e3744 6031}
6032
6033DEFUN (no_neighbor_ebgp_multihop,
6034 no_neighbor_ebgp_multihop_cmd,
a636c635 6035 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 6036 NO_STR
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
a636c635
DW
6039 "Allow EBGP neighbors not on directly connected networks\n"
6040 "maximum hop count\n")
718e3744 6041{
d62a17ae 6042 int idx_peer = 2;
6043 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6044}
6045
6b0655a2 6046
6ffd2079 6047/* disable-connected-check */
6048DEFUN (neighbor_disable_connected_check,
6049 neighbor_disable_connected_check_cmd,
7ebe625c 6050 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6051 NEIGHBOR_STR
7ebe625c 6052 NEIGHBOR_ADDR_STR2
a636c635
DW
6053 "one-hop away EBGP peer using loopback address\n"
6054 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6055{
d62a17ae 6056 int idx_peer = 1;
6057 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6058 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6059}
6060
6061DEFUN (no_neighbor_disable_connected_check,
6062 no_neighbor_disable_connected_check_cmd,
7ebe625c 6063 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 6064 NO_STR
6065 NEIGHBOR_STR
7ebe625c 6066 NEIGHBOR_ADDR_STR2
a636c635
DW
6067 "one-hop away EBGP peer using loopback address\n"
6068 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6069{
d62a17ae 6070 int idx_peer = 2;
6071 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6072 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 6073}
6074
47cbc09b
PM
6075
6076/* enforce-first-as */
6077DEFUN (neighbor_enforce_first_as,
6078 neighbor_enforce_first_as_cmd,
6079 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6080 NEIGHBOR_STR
6081 NEIGHBOR_ADDR_STR2
6082 "Enforce the first AS for EBGP routes\n")
6083{
6084 int idx_peer = 1;
6085
6086 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6087 PEER_FLAG_ENFORCE_FIRST_AS);
6088}
6089
6090DEFUN (no_neighbor_enforce_first_as,
6091 no_neighbor_enforce_first_as_cmd,
6092 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6093 NO_STR
6094 NEIGHBOR_STR
6095 NEIGHBOR_ADDR_STR2
6096 "Enforce the first AS for EBGP routes\n")
6097{
6098 int idx_peer = 2;
6099
6100 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6101 PEER_FLAG_ENFORCE_FIRST_AS);
6102}
6103
6104
718e3744 6105DEFUN (neighbor_description,
6106 neighbor_description_cmd,
e961923c 6107 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 6108 NEIGHBOR_STR
6109 NEIGHBOR_ADDR_STR2
6110 "Neighbor specific description\n"
6111 "Up to 80 characters describing this neighbor\n")
6112{
d62a17ae 6113 int idx_peer = 1;
6114 int idx_line = 3;
6115 struct peer *peer;
6116 char *str;
718e3744 6117
d62a17ae 6118 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6119 if (!peer)
6120 return CMD_WARNING_CONFIG_FAILED;
718e3744 6121
d62a17ae 6122 str = argv_concat(argv, argc, idx_line);
718e3744 6123
d62a17ae 6124 peer_description_set(peer, str);
718e3744 6125
d62a17ae 6126 XFREE(MTYPE_TMP, str);
718e3744 6127
d62a17ae 6128 return CMD_SUCCESS;
718e3744 6129}
6130
6131DEFUN (no_neighbor_description,
6132 no_neighbor_description_cmd,
a14810f4 6133 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
718e3744 6134 NO_STR
6135 NEIGHBOR_STR
6136 NEIGHBOR_ADDR_STR2
a14810f4 6137 "Neighbor specific description\n")
718e3744 6138{
d62a17ae 6139 int idx_peer = 2;
6140 struct peer *peer;
718e3744 6141
d62a17ae 6142 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6143 if (!peer)
6144 return CMD_WARNING_CONFIG_FAILED;
718e3744 6145
d62a17ae 6146 peer_description_unset(peer);
718e3744 6147
d62a17ae 6148 return CMD_SUCCESS;
718e3744 6149}
6150
a14810f4
PM
6151ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
6152 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6153 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6154 "Neighbor specific description\n"
6155 "Up to 80 characters describing this neighbor\n")
6b0655a2 6156
718e3744 6157/* Neighbor update-source. */
d62a17ae 6158static int peer_update_source_vty(struct vty *vty, const char *peer_str,
6159 const char *source_str)
6160{
6161 struct peer *peer;
6162 struct prefix p;
a14810f4 6163 union sockunion su;
d62a17ae 6164
6165 peer = peer_and_group_lookup_vty(vty, peer_str);
6166 if (!peer)
6167 return CMD_WARNING_CONFIG_FAILED;
6168
6169 if (peer->conf_if)
6170 return CMD_WARNING;
6171
6172 if (source_str) {
a14810f4 6173 if (str2sockunion(source_str, &su) == 0)
d62a17ae 6174 peer_update_source_addr_set(peer, &su);
6175 else {
6176 if (str2prefix(source_str, &p)) {
6177 vty_out(vty,
6178 "%% Invalid update-source, remove prefix length \n");
6179 return CMD_WARNING_CONFIG_FAILED;
6180 } else
6181 peer_update_source_if_set(peer, source_str);
6182 }
6183 } else
6184 peer_update_source_unset(peer);
6185
6186 return CMD_SUCCESS;
6187}
6188
6189#define BGP_UPDATE_SOURCE_HELP_STR \
6190 "IPv4 address\n" \
6191 "IPv6 address\n" \
6192 "Interface name (requires zebra to be running)\n"
369688c0 6193
718e3744 6194DEFUN (neighbor_update_source,
6195 neighbor_update_source_cmd,
9ccf14f7 6196 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 6197 NEIGHBOR_STR
6198 NEIGHBOR_ADDR_STR2
6199 "Source of routing updates\n"
369688c0 6200 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6201{
d62a17ae 6202 int idx_peer = 1;
6203 int idx_peer_2 = 3;
6204 return peer_update_source_vty(vty, argv[idx_peer]->arg,
6205 argv[idx_peer_2]->arg);
718e3744 6206}
6207
6208DEFUN (no_neighbor_update_source,
6209 no_neighbor_update_source_cmd,
c7178fe7 6210 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 6211 NO_STR
6212 NEIGHBOR_STR
6213 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
6214 "Source of routing updates\n"
6215 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 6216{
d62a17ae 6217 int idx_peer = 2;
6218 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6219}
6b0655a2 6220
d62a17ae 6221static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
6222 afi_t afi, safi_t safi,
6223 const char *rmap, int set)
718e3744 6224{
d62a17ae 6225 int ret;
6226 struct peer *peer;
80912664 6227 struct route_map *route_map = NULL;
718e3744 6228
d62a17ae 6229 peer = peer_and_group_lookup_vty(vty, peer_str);
6230 if (!peer)
6231 return CMD_WARNING_CONFIG_FAILED;
718e3744 6232
1de27621 6233 if (set) {
80912664
DS
6234 if (rmap)
6235 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
6236 ret = peer_default_originate_set(peer, afi, safi,
6237 rmap, route_map);
6238 } else
d62a17ae 6239 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 6240
d62a17ae 6241 return bgp_vty_return(vty, ret);
718e3744 6242}
6243
6244/* neighbor default-originate. */
6245DEFUN (neighbor_default_originate,
6246 neighbor_default_originate_cmd,
9ccf14f7 6247 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 6248 NEIGHBOR_STR
6249 NEIGHBOR_ADDR_STR2
6250 "Originate default route to this neighbor\n")
6251{
d62a17ae 6252 int idx_peer = 1;
6253 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6254 bgp_node_afi(vty),
6255 bgp_node_safi(vty), NULL, 1);
718e3744 6256}
6257
d62a17ae 6258ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
6259 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
6260 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6261 "Originate default route to this neighbor\n")
596c17ba 6262
718e3744 6263DEFUN (neighbor_default_originate_rmap,
6264 neighbor_default_originate_rmap_cmd,
9ccf14f7 6265 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 6266 NEIGHBOR_STR
6267 NEIGHBOR_ADDR_STR2
6268 "Originate default route to this neighbor\n"
6269 "Route-map to specify criteria to originate default\n"
6270 "route-map name\n")
6271{
d62a17ae 6272 int idx_peer = 1;
6273 int idx_word = 4;
6274 return peer_default_originate_set_vty(
6275 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6276 argv[idx_word]->arg, 1);
718e3744 6277}
6278
d62a17ae 6279ALIAS_HIDDEN(
6280 neighbor_default_originate_rmap,
6281 neighbor_default_originate_rmap_hidden_cmd,
6282 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
6283 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Originate default route to this neighbor\n"
6285 "Route-map to specify criteria to originate default\n"
6286 "route-map name\n")
596c17ba 6287
718e3744 6288DEFUN (no_neighbor_default_originate,
6289 no_neighbor_default_originate_cmd,
a636c635 6290 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 6291 NO_STR
6292 NEIGHBOR_STR
6293 NEIGHBOR_ADDR_STR2
a636c635
DW
6294 "Originate default route to this neighbor\n"
6295 "Route-map to specify criteria to originate default\n"
6296 "route-map name\n")
718e3744 6297{
d62a17ae 6298 int idx_peer = 2;
6299 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
6300 bgp_node_afi(vty),
6301 bgp_node_safi(vty), NULL, 0);
718e3744 6302}
6303
d62a17ae 6304ALIAS_HIDDEN(
6305 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "Originate default route to this neighbor\n"
6309 "Route-map to specify criteria to originate default\n"
6310 "route-map name\n")
596c17ba 6311
6b0655a2 6312
718e3744 6313/* Set neighbor's BGP port. */
d62a17ae 6314static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
6315 const char *port_str)
6316{
6317 struct peer *peer;
d7c0a89a 6318 uint16_t port;
d62a17ae 6319 struct servent *sp;
6320
6321 peer = peer_lookup_vty(vty, ip_str);
6322 if (!peer)
6323 return CMD_WARNING_CONFIG_FAILED;
6324
6325 if (!port_str) {
6326 sp = getservbyname("bgp", "tcp");
6327 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
6328 } else {
6329 port = strtoul(port_str, NULL, 10);
6330 }
718e3744 6331
d62a17ae 6332 peer_port_set(peer, port);
718e3744 6333
d62a17ae 6334 return CMD_SUCCESS;
718e3744 6335}
6336
f418446b 6337/* Set specified peer's BGP port. */
718e3744 6338DEFUN (neighbor_port,
6339 neighbor_port_cmd,
9ccf14f7 6340 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 6341 NEIGHBOR_STR
6342 NEIGHBOR_ADDR_STR
6343 "Neighbor's BGP port\n"
6344 "TCP port number\n")
6345{
d62a17ae 6346 int idx_ip = 1;
6347 int idx_number = 3;
6348 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
6349 argv[idx_number]->arg);
718e3744 6350}
6351
6352DEFUN (no_neighbor_port,
6353 no_neighbor_port_cmd,
9ccf14f7 6354 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 6355 NO_STR
6356 NEIGHBOR_STR
6357 NEIGHBOR_ADDR_STR
8334fd5a
DW
6358 "Neighbor's BGP port\n"
6359 "TCP port number\n")
718e3744 6360{
d62a17ae 6361 int idx_ip = 2;
6362 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 6363}
6364
6b0655a2 6365
718e3744 6366/* neighbor weight. */
d62a17ae 6367static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6368 safi_t safi, const char *weight_str)
718e3744 6369{
d62a17ae 6370 int ret;
6371 struct peer *peer;
6372 unsigned long weight;
718e3744 6373
d62a17ae 6374 peer = peer_and_group_lookup_vty(vty, ip_str);
6375 if (!peer)
6376 return CMD_WARNING_CONFIG_FAILED;
718e3744 6377
d62a17ae 6378 weight = strtoul(weight_str, NULL, 10);
718e3744 6379
d62a17ae 6380 ret = peer_weight_set(peer, afi, safi, weight);
6381 return bgp_vty_return(vty, ret);
718e3744 6382}
6383
d62a17ae 6384static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6385 safi_t safi)
718e3744 6386{
d62a17ae 6387 int ret;
6388 struct peer *peer;
718e3744 6389
d62a17ae 6390 peer = peer_and_group_lookup_vty(vty, ip_str);
6391 if (!peer)
6392 return CMD_WARNING_CONFIG_FAILED;
718e3744 6393
d62a17ae 6394 ret = peer_weight_unset(peer, afi, safi);
6395 return bgp_vty_return(vty, ret);
718e3744 6396}
6397
6398DEFUN (neighbor_weight,
6399 neighbor_weight_cmd,
9ccf14f7 6400 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 6401 NEIGHBOR_STR
6402 NEIGHBOR_ADDR_STR2
6403 "Set default weight for routes from this neighbor\n"
6404 "default weight\n")
6405{
d62a17ae 6406 int idx_peer = 1;
6407 int idx_number = 3;
6408 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6409 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 6410}
6411
d62a17ae 6412ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
6413 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
6414 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6415 "Set default weight for routes from this neighbor\n"
6416 "default weight\n")
596c17ba 6417
718e3744 6418DEFUN (no_neighbor_weight,
6419 no_neighbor_weight_cmd,
9ccf14f7 6420 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 6421 NO_STR
6422 NEIGHBOR_STR
6423 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6424 "Set default weight for routes from this neighbor\n"
6425 "default weight\n")
718e3744 6426{
d62a17ae 6427 int idx_peer = 2;
6428 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
6429 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 6430}
6431
d62a17ae 6432ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
6433 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
6434 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6435 "Set default weight for routes from this neighbor\n"
6436 "default weight\n")
596c17ba 6437
6b0655a2 6438
718e3744 6439/* Override capability negotiation. */
6440DEFUN (neighbor_override_capability,
6441 neighbor_override_capability_cmd,
9ccf14f7 6442 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6443 NEIGHBOR_STR
6444 NEIGHBOR_ADDR_STR2
6445 "Override capability negotiation result\n")
6446{
d62a17ae 6447 int idx_peer = 1;
6448 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
6449 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6450}
6451
6452DEFUN (no_neighbor_override_capability,
6453 no_neighbor_override_capability_cmd,
9ccf14f7 6454 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 6455 NO_STR
6456 NEIGHBOR_STR
6457 NEIGHBOR_ADDR_STR2
6458 "Override capability negotiation result\n")
6459{
d62a17ae 6460 int idx_peer = 2;
6461 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
6462 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 6463}
6b0655a2 6464
718e3744 6465DEFUN (neighbor_strict_capability,
6466 neighbor_strict_capability_cmd,
9fb964de 6467 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6468 NEIGHBOR_STR
9fb964de 6469 NEIGHBOR_ADDR_STR2
718e3744 6470 "Strict capability negotiation match\n")
6471{
9fb964de
PM
6472 int idx_peer = 1;
6473
6474 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
d62a17ae 6475 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6476}
6477
6478DEFUN (no_neighbor_strict_capability,
6479 no_neighbor_strict_capability_cmd,
9fb964de 6480 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
718e3744 6481 NO_STR
6482 NEIGHBOR_STR
9fb964de 6483 NEIGHBOR_ADDR_STR2
718e3744 6484 "Strict capability negotiation match\n")
6485{
9fb964de
PM
6486 int idx_peer = 2;
6487
6488 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
d62a17ae 6489 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 6490}
6b0655a2 6491
d62a17ae 6492static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
6493 const char *keep_str, const char *hold_str)
718e3744 6494{
d62a17ae 6495 int ret;
6496 struct peer *peer;
d7c0a89a
QY
6497 uint32_t keepalive;
6498 uint32_t holdtime;
718e3744 6499
d62a17ae 6500 peer = peer_and_group_lookup_vty(vty, ip_str);
6501 if (!peer)
6502 return CMD_WARNING_CONFIG_FAILED;
718e3744 6503
d62a17ae 6504 keepalive = strtoul(keep_str, NULL, 10);
6505 holdtime = strtoul(hold_str, NULL, 10);
718e3744 6506
d62a17ae 6507 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 6508
d62a17ae 6509 return bgp_vty_return(vty, ret);
718e3744 6510}
6b0655a2 6511
d62a17ae 6512static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6513{
d62a17ae 6514 int ret;
6515 struct peer *peer;
718e3744 6516
d62a17ae 6517 peer = peer_and_group_lookup_vty(vty, ip_str);
6518 if (!peer)
6519 return CMD_WARNING_CONFIG_FAILED;
718e3744 6520
d62a17ae 6521 ret = peer_timers_unset(peer);
718e3744 6522
d62a17ae 6523 return bgp_vty_return(vty, ret);
718e3744 6524}
6525
6526DEFUN (neighbor_timers,
6527 neighbor_timers_cmd,
9ccf14f7 6528 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 6529 NEIGHBOR_STR
6530 NEIGHBOR_ADDR_STR2
6531 "BGP per neighbor timers\n"
6532 "Keepalive interval\n"
6533 "Holdtime\n")
6534{
d62a17ae 6535 int idx_peer = 1;
6536 int idx_number = 3;
6537 int idx_number_2 = 4;
6538 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
6539 argv[idx_number]->arg,
6540 argv[idx_number_2]->arg);
718e3744 6541}
6542
6543DEFUN (no_neighbor_timers,
6544 no_neighbor_timers_cmd,
9ccf14f7 6545 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 6546 NO_STR
6547 NEIGHBOR_STR
6548 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6549 "BGP per neighbor timers\n"
6550 "Keepalive interval\n"
6551 "Holdtime\n")
718e3744 6552{
d62a17ae 6553 int idx_peer = 2;
6554 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6555}
6b0655a2 6556
813d4307 6557
d62a17ae 6558static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
6559 const char *time_str)
718e3744 6560{
d62a17ae 6561 int ret;
6562 struct peer *peer;
d7c0a89a 6563 uint32_t connect;
718e3744 6564
d62a17ae 6565 peer = peer_and_group_lookup_vty(vty, ip_str);
6566 if (!peer)
6567 return CMD_WARNING_CONFIG_FAILED;
718e3744 6568
d62a17ae 6569 connect = strtoul(time_str, NULL, 10);
718e3744 6570
d62a17ae 6571 ret = peer_timers_connect_set(peer, connect);
718e3744 6572
d62a17ae 6573 return bgp_vty_return(vty, ret);
718e3744 6574}
6575
d62a17ae 6576static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 6577{
d62a17ae 6578 int ret;
6579 struct peer *peer;
718e3744 6580
d62a17ae 6581 peer = peer_and_group_lookup_vty(vty, ip_str);
6582 if (!peer)
6583 return CMD_WARNING_CONFIG_FAILED;
718e3744 6584
d62a17ae 6585 ret = peer_timers_connect_unset(peer);
718e3744 6586
d62a17ae 6587 return bgp_vty_return(vty, ret);
718e3744 6588}
6589
6590DEFUN (neighbor_timers_connect,
6591 neighbor_timers_connect_cmd,
9ccf14f7 6592 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 6593 NEIGHBOR_STR
966f821c 6594 NEIGHBOR_ADDR_STR2
718e3744 6595 "BGP per neighbor timers\n"
6596 "BGP connect timer\n"
6597 "Connect timer\n")
6598{
d62a17ae 6599 int idx_peer = 1;
6600 int idx_number = 4;
6601 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
6602 argv[idx_number]->arg);
718e3744 6603}
6604
6605DEFUN (no_neighbor_timers_connect,
6606 no_neighbor_timers_connect_cmd,
9ccf14f7 6607 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 6608 NO_STR
6609 NEIGHBOR_STR
966f821c 6610 NEIGHBOR_ADDR_STR2
718e3744 6611 "BGP per neighbor timers\n"
8334fd5a
DW
6612 "BGP connect timer\n"
6613 "Connect timer\n")
718e3744 6614{
d62a17ae 6615 int idx_peer = 2;
6616 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 6617}
6618
6b0655a2 6619
d62a17ae 6620static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
6621 const char *time_str, int set)
718e3744 6622{
d62a17ae 6623 int ret;
6624 struct peer *peer;
d7c0a89a 6625 uint32_t routeadv = 0;
718e3744 6626
d62a17ae 6627 peer = peer_and_group_lookup_vty(vty, ip_str);
6628 if (!peer)
6629 return CMD_WARNING_CONFIG_FAILED;
718e3744 6630
d62a17ae 6631 if (time_str)
6632 routeadv = strtoul(time_str, NULL, 10);
718e3744 6633
d62a17ae 6634 if (set)
6635 ret = peer_advertise_interval_set(peer, routeadv);
6636 else
6637 ret = peer_advertise_interval_unset(peer);
718e3744 6638
d62a17ae 6639 return bgp_vty_return(vty, ret);
718e3744 6640}
6641
6642DEFUN (neighbor_advertise_interval,
6643 neighbor_advertise_interval_cmd,
9ccf14f7 6644 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 6645 NEIGHBOR_STR
966f821c 6646 NEIGHBOR_ADDR_STR2
718e3744 6647 "Minimum interval between sending BGP routing updates\n"
6648 "time in seconds\n")
6649{
d62a17ae 6650 int idx_peer = 1;
6651 int idx_number = 3;
6652 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
6653 argv[idx_number]->arg, 1);
718e3744 6654}
6655
6656DEFUN (no_neighbor_advertise_interval,
6657 no_neighbor_advertise_interval_cmd,
9ccf14f7 6658 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 6659 NO_STR
6660 NEIGHBOR_STR
966f821c 6661 NEIGHBOR_ADDR_STR2
8334fd5a
DW
6662 "Minimum interval between sending BGP routing updates\n"
6663 "time in seconds\n")
718e3744 6664{
d62a17ae 6665 int idx_peer = 2;
6666 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 6667}
6668
6b0655a2 6669
518f0eb1
DS
6670/* Time to wait before processing route-map updates */
6671DEFUN (bgp_set_route_map_delay_timer,
6672 bgp_set_route_map_delay_timer_cmd,
6147e2c6 6673 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
6674 SET_STR
6675 "BGP route-map delay timer\n"
6676 "Time in secs to wait before processing route-map changes\n"
f414725f 6677 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6678{
d62a17ae 6679 int idx_number = 3;
d7c0a89a 6680 uint32_t rmap_delay_timer;
d62a17ae 6681
6682 if (argv[idx_number]->arg) {
6683 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
6684 bm->rmap_update_timer = rmap_delay_timer;
6685
6686 /* if the dynamic update handling is being disabled, and a timer
6687 * is
6688 * running, stop the timer and act as if the timer has already
6689 * fired.
6690 */
6691 if (!rmap_delay_timer && bm->t_rmap_update) {
6692 BGP_TIMER_OFF(bm->t_rmap_update);
6693 thread_execute(bm->master, bgp_route_map_update_timer,
6694 NULL, 0);
6695 }
6696 return CMD_SUCCESS;
6697 } else {
6698 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
6699 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 6700 }
518f0eb1
DS
6701}
6702
6703DEFUN (no_bgp_set_route_map_delay_timer,
6704 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 6705 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 6706 NO_STR
3a2d747c 6707 BGP_STR
518f0eb1 6708 "Default BGP route-map delay timer\n"
8334fd5a
DW
6709 "Reset to default time to wait for processing route-map changes\n"
6710 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 6711{
518f0eb1 6712
d62a17ae 6713 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 6714
d62a17ae 6715 return CMD_SUCCESS;
518f0eb1
DS
6716}
6717
718e3744 6718/* neighbor interface */
d62a17ae 6719static int peer_interface_vty(struct vty *vty, const char *ip_str,
6720 const char *str)
718e3744 6721{
d62a17ae 6722 struct peer *peer;
718e3744 6723
d62a17ae 6724 peer = peer_lookup_vty(vty, ip_str);
6725 if (!peer || peer->conf_if) {
6726 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
6727 return CMD_WARNING_CONFIG_FAILED;
6728 }
718e3744 6729
d62a17ae 6730 if (str)
6731 peer_interface_set(peer, str);
6732 else
6733 peer_interface_unset(peer);
718e3744 6734
d62a17ae 6735 return CMD_SUCCESS;
718e3744 6736}
6737
6738DEFUN (neighbor_interface,
6739 neighbor_interface_cmd,
9ccf14f7 6740 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 6741 NEIGHBOR_STR
6742 NEIGHBOR_ADDR_STR
6743 "Interface\n"
6744 "Interface name\n")
6745{
d62a17ae 6746 int idx_ip = 1;
6747 int idx_word = 3;
6748 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 6749}
6750
6751DEFUN (no_neighbor_interface,
6752 no_neighbor_interface_cmd,
9ccf14f7 6753 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 6754 NO_STR
6755 NEIGHBOR_STR
16cedbb0 6756 NEIGHBOR_ADDR_STR2
718e3744 6757 "Interface\n"
6758 "Interface name\n")
6759{
d62a17ae 6760 int idx_peer = 2;
6761 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 6762}
6b0655a2 6763
718e3744 6764DEFUN (neighbor_distribute_list,
6765 neighbor_distribute_list_cmd,
9ccf14f7 6766 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6767 NEIGHBOR_STR
6768 NEIGHBOR_ADDR_STR2
6769 "Filter updates to/from this neighbor\n"
6770 "IP access-list number\n"
6771 "IP access-list number (expanded range)\n"
6772 "IP Access-list name\n"
6773 "Filter incoming updates\n"
6774 "Filter outgoing updates\n")
6775{
d62a17ae 6776 int idx_peer = 1;
6777 int idx_acl = 3;
6778 int direct, ret;
6779 struct peer *peer;
a8206004 6780
d62a17ae 6781 const char *pstr = argv[idx_peer]->arg;
6782 const char *acl = argv[idx_acl]->arg;
6783 const char *inout = argv[argc - 1]->text;
a8206004 6784
d62a17ae 6785 peer = peer_and_group_lookup_vty(vty, pstr);
6786 if (!peer)
6787 return CMD_WARNING_CONFIG_FAILED;
a8206004 6788
d62a17ae 6789 /* Check filter direction. */
6790 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6791 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6792 direct, acl);
a8206004 6793
d62a17ae 6794 return bgp_vty_return(vty, ret);
718e3744 6795}
6796
d62a17ae 6797ALIAS_HIDDEN(
6798 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
6799 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6801 "Filter updates to/from this neighbor\n"
6802 "IP access-list number\n"
6803 "IP access-list number (expanded range)\n"
6804 "IP Access-list name\n"
6805 "Filter incoming updates\n"
6806 "Filter outgoing updates\n")
596c17ba 6807
718e3744 6808DEFUN (no_neighbor_distribute_list,
6809 no_neighbor_distribute_list_cmd,
9ccf14f7 6810 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 6811 NO_STR
6812 NEIGHBOR_STR
6813 NEIGHBOR_ADDR_STR2
6814 "Filter updates to/from this neighbor\n"
6815 "IP access-list number\n"
6816 "IP access-list number (expanded range)\n"
6817 "IP Access-list name\n"
6818 "Filter incoming updates\n"
6819 "Filter outgoing updates\n")
6820{
d62a17ae 6821 int idx_peer = 2;
6822 int direct, ret;
6823 struct peer *peer;
a8206004 6824
d62a17ae 6825 const char *pstr = argv[idx_peer]->arg;
6826 const char *inout = argv[argc - 1]->text;
a8206004 6827
d62a17ae 6828 peer = peer_and_group_lookup_vty(vty, pstr);
6829 if (!peer)
6830 return CMD_WARNING_CONFIG_FAILED;
a8206004 6831
d62a17ae 6832 /* Check filter direction. */
6833 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
6834 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6835 direct);
a8206004 6836
d62a17ae 6837 return bgp_vty_return(vty, ret);
718e3744 6838}
6b0655a2 6839
d62a17ae 6840ALIAS_HIDDEN(
6841 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
6842 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
6843 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6844 "Filter updates to/from this neighbor\n"
6845 "IP access-list number\n"
6846 "IP access-list number (expanded range)\n"
6847 "IP Access-list name\n"
6848 "Filter incoming updates\n"
6849 "Filter outgoing updates\n")
596c17ba 6850
718e3744 6851/* Set prefix list to the peer. */
d62a17ae 6852static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
6853 afi_t afi, safi_t safi,
6854 const char *name_str,
6855 const char *direct_str)
718e3744 6856{
d62a17ae 6857 int ret;
d62a17ae 6858 int direct = FILTER_IN;
cf9ac8bf 6859 struct peer *peer;
718e3744 6860
d62a17ae 6861 peer = peer_and_group_lookup_vty(vty, ip_str);
6862 if (!peer)
6863 return CMD_WARNING_CONFIG_FAILED;
718e3744 6864
d62a17ae 6865 /* Check filter direction. */
6866 if (strncmp(direct_str, "i", 1) == 0)
6867 direct = FILTER_IN;
6868 else if (strncmp(direct_str, "o", 1) == 0)
6869 direct = FILTER_OUT;
718e3744 6870
d62a17ae 6871 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 6872
d62a17ae 6873 return bgp_vty_return(vty, ret);
718e3744 6874}
6875
d62a17ae 6876static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
6877 afi_t afi, safi_t safi,
6878 const char *direct_str)
718e3744 6879{
d62a17ae 6880 int ret;
6881 struct peer *peer;
6882 int direct = FILTER_IN;
718e3744 6883
d62a17ae 6884 peer = peer_and_group_lookup_vty(vty, ip_str);
6885 if (!peer)
6886 return CMD_WARNING_CONFIG_FAILED;
e52702f2 6887
d62a17ae 6888 /* Check filter direction. */
6889 if (strncmp(direct_str, "i", 1) == 0)
6890 direct = FILTER_IN;
6891 else if (strncmp(direct_str, "o", 1) == 0)
6892 direct = FILTER_OUT;
718e3744 6893
d62a17ae 6894 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 6895
d62a17ae 6896 return bgp_vty_return(vty, ret);
718e3744 6897}
6898
6899DEFUN (neighbor_prefix_list,
6900 neighbor_prefix_list_cmd,
9ccf14f7 6901 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6902 NEIGHBOR_STR
6903 NEIGHBOR_ADDR_STR2
6904 "Filter updates to/from this neighbor\n"
6905 "Name of a prefix list\n"
6906 "Filter incoming updates\n"
6907 "Filter outgoing updates\n")
6908{
d62a17ae 6909 int idx_peer = 1;
6910 int idx_word = 3;
6911 int idx_in_out = 4;
6912 return peer_prefix_list_set_vty(
6913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6914 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 6915}
6916
d62a17ae 6917ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
6918 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6920 "Filter updates to/from this neighbor\n"
6921 "Name of a prefix list\n"
6922 "Filter incoming updates\n"
6923 "Filter outgoing updates\n")
596c17ba 6924
718e3744 6925DEFUN (no_neighbor_prefix_list,
6926 no_neighbor_prefix_list_cmd,
9ccf14f7 6927 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 6928 NO_STR
6929 NEIGHBOR_STR
6930 NEIGHBOR_ADDR_STR2
6931 "Filter updates to/from this neighbor\n"
6932 "Name of a prefix list\n"
6933 "Filter incoming updates\n"
6934 "Filter outgoing updates\n")
6935{
d62a17ae 6936 int idx_peer = 2;
6937 int idx_in_out = 5;
6938 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
6939 bgp_node_afi(vty), bgp_node_safi(vty),
6940 argv[idx_in_out]->arg);
718e3744 6941}
6b0655a2 6942
d62a17ae 6943ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
6944 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
6945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6946 "Filter updates to/from this neighbor\n"
6947 "Name of a prefix list\n"
6948 "Filter incoming updates\n"
6949 "Filter outgoing updates\n")
596c17ba 6950
d62a17ae 6951static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
6952 safi_t safi, const char *name_str,
6953 const char *direct_str)
718e3744 6954{
d62a17ae 6955 int ret;
6956 struct peer *peer;
6957 int direct = FILTER_IN;
718e3744 6958
d62a17ae 6959 peer = peer_and_group_lookup_vty(vty, ip_str);
6960 if (!peer)
6961 return CMD_WARNING_CONFIG_FAILED;
718e3744 6962
d62a17ae 6963 /* Check filter direction. */
6964 if (strncmp(direct_str, "i", 1) == 0)
6965 direct = FILTER_IN;
6966 else if (strncmp(direct_str, "o", 1) == 0)
6967 direct = FILTER_OUT;
718e3744 6968
d62a17ae 6969 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 6970
d62a17ae 6971 return bgp_vty_return(vty, ret);
718e3744 6972}
6973
d62a17ae 6974static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
6975 safi_t safi, const char *direct_str)
718e3744 6976{
d62a17ae 6977 int ret;
6978 struct peer *peer;
6979 int direct = FILTER_IN;
718e3744 6980
d62a17ae 6981 peer = peer_and_group_lookup_vty(vty, ip_str);
6982 if (!peer)
6983 return CMD_WARNING_CONFIG_FAILED;
718e3744 6984
d62a17ae 6985 /* Check filter direction. */
6986 if (strncmp(direct_str, "i", 1) == 0)
6987 direct = FILTER_IN;
6988 else if (strncmp(direct_str, "o", 1) == 0)
6989 direct = FILTER_OUT;
718e3744 6990
d62a17ae 6991 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 6992
d62a17ae 6993 return bgp_vty_return(vty, ret);
718e3744 6994}
6995
6996DEFUN (neighbor_filter_list,
6997 neighbor_filter_list_cmd,
9ccf14f7 6998 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 6999 NEIGHBOR_STR
7000 NEIGHBOR_ADDR_STR2
7001 "Establish BGP filters\n"
7002 "AS path access-list name\n"
7003 "Filter incoming routes\n"
7004 "Filter outgoing routes\n")
7005{
d62a17ae 7006 int idx_peer = 1;
7007 int idx_word = 3;
7008 int idx_in_out = 4;
7009 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7010 bgp_node_safi(vty), argv[idx_word]->arg,
7011 argv[idx_in_out]->arg);
718e3744 7012}
7013
d62a17ae 7014ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7015 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7017 "Establish BGP filters\n"
7018 "AS path access-list name\n"
7019 "Filter incoming routes\n"
7020 "Filter outgoing routes\n")
596c17ba 7021
718e3744 7022DEFUN (no_neighbor_filter_list,
7023 no_neighbor_filter_list_cmd,
9ccf14f7 7024 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7025 NO_STR
7026 NEIGHBOR_STR
7027 NEIGHBOR_ADDR_STR2
7028 "Establish BGP filters\n"
7029 "AS path access-list name\n"
7030 "Filter incoming routes\n"
7031 "Filter outgoing routes\n")
7032{
d62a17ae 7033 int idx_peer = 2;
7034 int idx_in_out = 5;
7035 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7036 bgp_node_afi(vty), bgp_node_safi(vty),
7037 argv[idx_in_out]->arg);
718e3744 7038}
6b0655a2 7039
d62a17ae 7040ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7041 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7042 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7043 "Establish BGP filters\n"
7044 "AS path access-list name\n"
7045 "Filter incoming routes\n"
7046 "Filter outgoing routes\n")
596c17ba 7047
718e3744 7048/* Set route-map to the peer. */
d62a17ae 7049static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
7050 afi_t afi, safi_t safi, const char *name_str,
7051 const char *direct_str)
718e3744 7052{
d62a17ae 7053 int ret;
7054 struct peer *peer;
7055 int direct = RMAP_IN;
1de27621 7056 struct route_map *route_map;
718e3744 7057
d62a17ae 7058 peer = peer_and_group_lookup_vty(vty, ip_str);
7059 if (!peer)
7060 return CMD_WARNING_CONFIG_FAILED;
718e3744 7061
d62a17ae 7062 /* Check filter direction. */
7063 if (strncmp(direct_str, "in", 2) == 0)
7064 direct = RMAP_IN;
7065 else if (strncmp(direct_str, "o", 1) == 0)
7066 direct = RMAP_OUT;
718e3744 7067
1de27621
DA
7068 route_map = route_map_lookup_warn_noexist(vty, name_str);
7069 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
718e3744 7070
d62a17ae 7071 return bgp_vty_return(vty, ret);
718e3744 7072}
7073
d62a17ae 7074static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
7075 afi_t afi, safi_t safi,
7076 const char *direct_str)
718e3744 7077{
d62a17ae 7078 int ret;
7079 struct peer *peer;
7080 int direct = RMAP_IN;
718e3744 7081
d62a17ae 7082 peer = peer_and_group_lookup_vty(vty, ip_str);
7083 if (!peer)
7084 return CMD_WARNING_CONFIG_FAILED;
718e3744 7085
d62a17ae 7086 /* Check filter direction. */
7087 if (strncmp(direct_str, "in", 2) == 0)
7088 direct = RMAP_IN;
7089 else if (strncmp(direct_str, "o", 1) == 0)
7090 direct = RMAP_OUT;
718e3744 7091
d62a17ae 7092 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 7093
d62a17ae 7094 return bgp_vty_return(vty, ret);
718e3744 7095}
7096
7097DEFUN (neighbor_route_map,
7098 neighbor_route_map_cmd,
9ccf14f7 7099 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7100 NEIGHBOR_STR
7101 NEIGHBOR_ADDR_STR2
7102 "Apply route map to neighbor\n"
7103 "Name of route map\n"
7104 "Apply map to incoming routes\n"
2a3d5731 7105 "Apply map to outbound routes\n")
718e3744 7106{
d62a17ae 7107 int idx_peer = 1;
7108 int idx_word = 3;
7109 int idx_in_out = 4;
7110 return peer_route_map_set_vty(
7111 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7112 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 7113}
7114
d62a17ae 7115ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
7116 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7117 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7118 "Apply route map to neighbor\n"
7119 "Name of route map\n"
7120 "Apply map to incoming routes\n"
7121 "Apply map to outbound routes\n")
596c17ba 7122
718e3744 7123DEFUN (no_neighbor_route_map,
7124 no_neighbor_route_map_cmd,
9ccf14f7 7125 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 7126 NO_STR
7127 NEIGHBOR_STR
7128 NEIGHBOR_ADDR_STR2
7129 "Apply route map to neighbor\n"
7130 "Name of route map\n"
7131 "Apply map to incoming routes\n"
2a3d5731 7132 "Apply map to outbound routes\n")
718e3744 7133{
d62a17ae 7134 int idx_peer = 2;
7135 int idx_in_out = 5;
7136 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
7137 bgp_node_afi(vty), bgp_node_safi(vty),
7138 argv[idx_in_out]->arg);
718e3744 7139}
6b0655a2 7140
d62a17ae 7141ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
7142 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
7143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7144 "Apply route map to neighbor\n"
7145 "Name of route map\n"
7146 "Apply map to incoming routes\n"
7147 "Apply map to outbound routes\n")
596c17ba 7148
718e3744 7149/* Set unsuppress-map to the peer. */
d62a17ae 7150static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
7151 afi_t afi, safi_t safi,
7152 const char *name_str)
718e3744 7153{
d62a17ae 7154 int ret;
7155 struct peer *peer;
1de27621 7156 struct route_map *route_map;
718e3744 7157
d62a17ae 7158 peer = peer_and_group_lookup_vty(vty, ip_str);
7159 if (!peer)
7160 return CMD_WARNING_CONFIG_FAILED;
718e3744 7161
1de27621
DA
7162 route_map = route_map_lookup_warn_noexist(vty, name_str);
7163 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 7164
d62a17ae 7165 return bgp_vty_return(vty, ret);
718e3744 7166}
7167
7168/* Unset route-map from the peer. */
d62a17ae 7169static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
7170 afi_t afi, safi_t safi)
718e3744 7171{
d62a17ae 7172 int ret;
7173 struct peer *peer;
718e3744 7174
d62a17ae 7175 peer = peer_and_group_lookup_vty(vty, ip_str);
7176 if (!peer)
7177 return CMD_WARNING_CONFIG_FAILED;
718e3744 7178
d62a17ae 7179 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 7180
d62a17ae 7181 return bgp_vty_return(vty, ret);
718e3744 7182}
7183
7184DEFUN (neighbor_unsuppress_map,
7185 neighbor_unsuppress_map_cmd,
9ccf14f7 7186 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7187 NEIGHBOR_STR
7188 NEIGHBOR_ADDR_STR2
7189 "Route-map to selectively unsuppress suppressed routes\n"
7190 "Name of route map\n")
7191{
d62a17ae 7192 int idx_peer = 1;
7193 int idx_word = 3;
7194 return peer_unsuppress_map_set_vty(
7195 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7196 argv[idx_word]->arg);
718e3744 7197}
7198
d62a17ae 7199ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
7200 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7202 "Route-map to selectively unsuppress suppressed routes\n"
7203 "Name of route map\n")
596c17ba 7204
718e3744 7205DEFUN (no_neighbor_unsuppress_map,
7206 no_neighbor_unsuppress_map_cmd,
9ccf14f7 7207 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 7208 NO_STR
7209 NEIGHBOR_STR
7210 NEIGHBOR_ADDR_STR2
7211 "Route-map to selectively unsuppress suppressed routes\n"
7212 "Name of route map\n")
7213{
d62a17ae 7214 int idx_peer = 2;
7215 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
7216 bgp_node_afi(vty),
7217 bgp_node_safi(vty));
718e3744 7218}
6b0655a2 7219
d62a17ae 7220ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
7221 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
7222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7223 "Route-map to selectively unsuppress suppressed routes\n"
7224 "Name of route map\n")
596c17ba 7225
d62a17ae 7226static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
7227 afi_t afi, safi_t safi,
7228 const char *num_str,
7229 const char *threshold_str, int warning,
9cbd06e0
DA
7230 const char *restart_str,
7231 const char *force_str)
718e3744 7232{
d62a17ae 7233 int ret;
7234 struct peer *peer;
d7c0a89a
QY
7235 uint32_t max;
7236 uint8_t threshold;
7237 uint16_t restart;
718e3744 7238
d62a17ae 7239 peer = peer_and_group_lookup_vty(vty, ip_str);
7240 if (!peer)
7241 return CMD_WARNING_CONFIG_FAILED;
718e3744 7242
d62a17ae 7243 max = strtoul(num_str, NULL, 10);
7244 if (threshold_str)
7245 threshold = atoi(threshold_str);
7246 else
7247 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 7248
d62a17ae 7249 if (restart_str)
7250 restart = atoi(restart_str);
7251 else
7252 restart = 0;
0a486e5f 7253
d62a17ae 7254 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
9cbd06e0 7255 restart, force_str ? true : false);
718e3744 7256
d62a17ae 7257 return bgp_vty_return(vty, ret);
718e3744 7258}
7259
d62a17ae 7260static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
7261 afi_t afi, safi_t safi)
718e3744 7262{
d62a17ae 7263 int ret;
7264 struct peer *peer;
718e3744 7265
d62a17ae 7266 peer = peer_and_group_lookup_vty(vty, ip_str);
7267 if (!peer)
7268 return CMD_WARNING_CONFIG_FAILED;
718e3744 7269
d62a17ae 7270 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 7271
d62a17ae 7272 return bgp_vty_return(vty, ret);
718e3744 7273}
7274
fde246e8
DA
7275/* Maximum number of prefix to be sent to the neighbor. */
7276DEFUN(neighbor_maximum_prefix_out,
7277 neighbor_maximum_prefix_out_cmd,
7278 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
7279 NEIGHBOR_STR
7280 NEIGHBOR_ADDR_STR2
7281 "Maximum number of prefixes to be sent to this peer\n"
7282 "Maximum no. of prefix limit\n")
7283{
7284 int idx_peer = 1;
7285 int idx_number = 3;
7286 struct peer *peer;
7287 uint32_t max;
7288 afi_t afi = bgp_node_afi(vty);
7289 safi_t safi = bgp_node_safi(vty);
7290
7291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7292 if (!peer)
7293 return CMD_WARNING_CONFIG_FAILED;
7294
7295 max = strtoul(argv[idx_number]->arg, NULL, 10);
7296
7297 SET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
7298 peer->pmax_out[afi][safi] = max;
7299
7300 return CMD_SUCCESS;
7301}
7302
7303DEFUN(no_neighbor_maximum_prefix_out,
7304 no_neighbor_maximum_prefix_out_cmd,
7305 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
7306 NO_STR
7307 NEIGHBOR_STR
7308 NEIGHBOR_ADDR_STR2
7309 "Maximum number of prefixes to be sent to this peer\n")
7310{
7311 int idx_peer = 2;
7312 struct peer *peer;
7313 afi_t afi = bgp_node_afi(vty);
7314 safi_t safi = bgp_node_safi(vty);
7315
7316 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7317 if (!peer)
7318 return CMD_WARNING_CONFIG_FAILED;
7319
ae00326a 7320 UNSET_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT);
fde246e8
DA
7321 peer->pmax_out[afi][safi] = 0;
7322
7323 return CMD_SUCCESS;
7324}
7325
9cbd06e0
DA
7326/* Maximum number of prefix configuration. Prefix count is different
7327 for each peer configuration. So this configuration can be set for
718e3744 7328 each peer configuration. */
7329DEFUN (neighbor_maximum_prefix,
7330 neighbor_maximum_prefix_cmd,
9cbd06e0 7331 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
718e3744 7332 NEIGHBOR_STR
7333 NEIGHBOR_ADDR_STR2
7334 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7335 "maximum no. of prefix limit\n"
7336 "Force checking all received routes not only accepted\n")
718e3744 7337{
d62a17ae 7338 int idx_peer = 1;
7339 int idx_number = 3;
9cbd06e0
DA
7340 int idx_force = 0;
7341 char *force = NULL;
7342
7343 if (argv_find(argv, argc, "force", &idx_force))
7344 force = argv[idx_force]->arg;
7345
d62a17ae 7346 return peer_maximum_prefix_set_vty(
7347 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7348 argv[idx_number]->arg, NULL, 0, NULL, force);
718e3744 7349}
7350
d62a17ae 7351ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7352 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 7353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7354 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
7355 "maximum no. of prefix limit\n"
7356 "Force checking all received routes not only accepted\n")
596c17ba 7357
e0701b79 7358DEFUN (neighbor_maximum_prefix_threshold,
7359 neighbor_maximum_prefix_threshold_cmd,
9cbd06e0 7360 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
e0701b79 7361 NEIGHBOR_STR
7362 NEIGHBOR_ADDR_STR2
7363 "Maximum number of prefix accept from this peer\n"
7364 "maximum no. of prefix limit\n"
9cbd06e0
DA
7365 "Threshold value (%) at which to generate a warning msg\n"
7366 "Force checking all received routes not only accepted\n")
e0701b79 7367{
d62a17ae 7368 int idx_peer = 1;
7369 int idx_number = 3;
7370 int idx_number_2 = 4;
9cbd06e0
DA
7371 int idx_force = 0;
7372 char *force = NULL;
7373
7374 if (argv_find(argv, argc, "force", &idx_force))
7375 force = argv[idx_force]->arg;
7376
d62a17ae 7377 return peer_maximum_prefix_set_vty(
7378 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7379 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL, force);
0a486e5f 7380}
e0701b79 7381
d62a17ae 7382ALIAS_HIDDEN(
7383 neighbor_maximum_prefix_threshold,
7384 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 7385 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 7386 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7387 "Maximum number of prefix accept from this peer\n"
7388 "maximum no. of prefix limit\n"
9cbd06e0
DA
7389 "Threshold value (%) at which to generate a warning msg\n"
7390 "Force checking all received routes not only accepted\n")
596c17ba 7391
718e3744 7392DEFUN (neighbor_maximum_prefix_warning,
7393 neighbor_maximum_prefix_warning_cmd,
9cbd06e0 7394 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
718e3744 7395 NEIGHBOR_STR
7396 NEIGHBOR_ADDR_STR2
7397 "Maximum number of prefix accept from this peer\n"
7398 "maximum no. of prefix limit\n"
9cbd06e0
DA
7399 "Only give warning message when limit is exceeded\n"
7400 "Force checking all received routes not only accepted\n")
718e3744 7401{
d62a17ae 7402 int idx_peer = 1;
7403 int idx_number = 3;
9cbd06e0
DA
7404 int idx_force = 0;
7405 char *force = NULL;
7406
7407 if (argv_find(argv, argc, "force", &idx_force))
7408 force = argv[idx_force]->arg;
7409
d62a17ae 7410 return peer_maximum_prefix_set_vty(
7411 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7412 argv[idx_number]->arg, NULL, 1, NULL, force);
718e3744 7413}
7414
d62a17ae 7415ALIAS_HIDDEN(
7416 neighbor_maximum_prefix_warning,
7417 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 7418 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 7419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7420 "Maximum number of prefix accept from this peer\n"
7421 "maximum no. of prefix limit\n"
9cbd06e0
DA
7422 "Only give warning message when limit is exceeded\n"
7423 "Force checking all received routes not only accepted\n")
596c17ba 7424
e0701b79 7425DEFUN (neighbor_maximum_prefix_threshold_warning,
7426 neighbor_maximum_prefix_threshold_warning_cmd,
9cbd06e0 7427 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
e0701b79 7428 NEIGHBOR_STR
7429 NEIGHBOR_ADDR_STR2
7430 "Maximum number of prefix accept from this peer\n"
7431 "maximum no. of prefix limit\n"
7432 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7433 "Only give warning message when limit is exceeded\n"
7434 "Force checking all received routes not only accepted\n")
e0701b79 7435{
d62a17ae 7436 int idx_peer = 1;
7437 int idx_number = 3;
7438 int idx_number_2 = 4;
9cbd06e0
DA
7439 int idx_force = 0;
7440 char *force = NULL;
7441
7442 if (argv_find(argv, argc, "force", &idx_force))
7443 force = argv[idx_force]->arg;
7444
d62a17ae 7445 return peer_maximum_prefix_set_vty(
7446 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7447 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL, force);
0a486e5f 7448}
7449
d62a17ae 7450ALIAS_HIDDEN(
7451 neighbor_maximum_prefix_threshold_warning,
7452 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 7453 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 7454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7455 "Maximum number of prefix accept from this peer\n"
7456 "maximum no. of prefix limit\n"
7457 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
7458 "Only give warning message when limit is exceeded\n"
7459 "Force checking all received routes not only accepted\n")
596c17ba 7460
0a486e5f 7461DEFUN (neighbor_maximum_prefix_restart,
7462 neighbor_maximum_prefix_restart_cmd,
9cbd06e0 7463 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
0a486e5f 7464 NEIGHBOR_STR
7465 NEIGHBOR_ADDR_STR2
7466 "Maximum number of prefix accept from this peer\n"
7467 "maximum no. of prefix limit\n"
7468 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7469 "Restart interval in minutes\n"
7470 "Force checking all received routes not only accepted\n")
0a486e5f 7471{
d62a17ae 7472 int idx_peer = 1;
7473 int idx_number = 3;
7474 int idx_number_2 = 5;
9cbd06e0
DA
7475 int idx_force = 0;
7476 char *force = NULL;
7477
7478 if (argv_find(argv, argc, "force", &idx_force))
7479 force = argv[idx_force]->arg;
7480
d62a17ae 7481 return peer_maximum_prefix_set_vty(
7482 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
9cbd06e0 7483 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg, force);
0a486e5f 7484}
7485
d62a17ae 7486ALIAS_HIDDEN(
7487 neighbor_maximum_prefix_restart,
7488 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 7489 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 7490 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7491 "Maximum number of prefix accept from this peer\n"
7492 "maximum no. of prefix limit\n"
7493 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7494 "Restart interval in minutes\n"
7495 "Force checking all received routes not only accepted\n")
596c17ba 7496
0a486e5f 7497DEFUN (neighbor_maximum_prefix_threshold_restart,
7498 neighbor_maximum_prefix_threshold_restart_cmd,
9cbd06e0 7499 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
0a486e5f 7500 NEIGHBOR_STR
7501 NEIGHBOR_ADDR_STR2
16cedbb0 7502 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 7503 "maximum no. of prefix limit\n"
7504 "Threshold value (%) at which to generate a warning msg\n"
7505 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7506 "Restart interval in minutes\n"
7507 "Force checking all received routes not only accepted\n")
0a486e5f 7508{
d62a17ae 7509 int idx_peer = 1;
7510 int idx_number = 3;
7511 int idx_number_2 = 4;
7512 int idx_number_3 = 6;
9cbd06e0
DA
7513 int idx_force = 0;
7514 char *force = NULL;
7515
7516 if (argv_find(argv, argc, "force", &idx_force))
7517 force = argv[idx_force]->arg;
7518
d62a17ae 7519 return peer_maximum_prefix_set_vty(
7520 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7521 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
9cbd06e0 7522 argv[idx_number_3]->arg, force);
d62a17ae 7523}
7524
7525ALIAS_HIDDEN(
7526 neighbor_maximum_prefix_threshold_restart,
7527 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 7528 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 7529 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7530 "Maximum number of prefixes to accept from this peer\n"
7531 "maximum no. of prefix limit\n"
7532 "Threshold value (%) at which to generate a warning msg\n"
7533 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
7534 "Restart interval in minutes\n"
7535 "Force checking all received routes not only accepted\n")
596c17ba 7536
718e3744 7537DEFUN (no_neighbor_maximum_prefix,
7538 no_neighbor_maximum_prefix_cmd,
9cbd06e0 7539 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
718e3744 7540 NO_STR
7541 NEIGHBOR_STR
7542 NEIGHBOR_ADDR_STR2
16cedbb0 7543 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
7544 "maximum no. of prefix limit\n"
7545 "Threshold value (%) at which to generate a warning msg\n"
7546 "Restart bgp connection after limit is exceeded\n"
16cedbb0 7547 "Restart interval in minutes\n"
9cbd06e0
DA
7548 "Only give warning message when limit is exceeded\n"
7549 "Force checking all received routes not only accepted\n")
718e3744 7550{
d62a17ae 7551 int idx_peer = 2;
7552 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
7553 bgp_node_afi(vty),
7554 bgp_node_safi(vty));
718e3744 7555}
e52702f2 7556
d62a17ae 7557ALIAS_HIDDEN(
7558 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 7559 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 7560 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7561 "Maximum number of prefixes to accept from this peer\n"
7562 "maximum no. of prefix limit\n"
7563 "Threshold value (%) at which to generate a warning msg\n"
7564 "Restart bgp connection after limit is exceeded\n"
7565 "Restart interval in minutes\n"
9cbd06e0
DA
7566 "Only give warning message when limit is exceeded\n"
7567 "Force checking all received routes not only accepted\n")
596c17ba 7568
718e3744 7569
718e3744 7570/* "neighbor allowas-in" */
7571DEFUN (neighbor_allowas_in,
7572 neighbor_allowas_in_cmd,
fd8503f5 7573 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7574 NEIGHBOR_STR
7575 NEIGHBOR_ADDR_STR2
31500417 7576 "Accept as-path with my AS present in it\n"
f79f7a7b 7577 "Number of occurrences of AS number\n"
fd8503f5 7578 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7579{
d62a17ae 7580 int idx_peer = 1;
7581 int idx_number_origin = 3;
7582 int ret;
7583 int origin = 0;
7584 struct peer *peer;
7585 int allow_num = 0;
7586
7587 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7588 if (!peer)
7589 return CMD_WARNING_CONFIG_FAILED;
7590
7591 if (argc <= idx_number_origin)
7592 allow_num = 3;
7593 else {
7594 if (argv[idx_number_origin]->type == WORD_TKN)
7595 origin = 1;
7596 else
7597 allow_num = atoi(argv[idx_number_origin]->arg);
7598 }
7599
7600 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7601 allow_num, origin);
7602
7603 return bgp_vty_return(vty, ret);
7604}
7605
7606ALIAS_HIDDEN(
7607 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
7608 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7609 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7610 "Accept as-path with my AS present in it\n"
f79f7a7b 7611 "Number of occurrences of AS number\n"
d62a17ae 7612 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7613
718e3744 7614DEFUN (no_neighbor_allowas_in,
7615 no_neighbor_allowas_in_cmd,
fd8503f5 7616 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 7617 NO_STR
7618 NEIGHBOR_STR
7619 NEIGHBOR_ADDR_STR2
8334fd5a 7620 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7621 "Number of occurrences of AS number\n"
fd8503f5 7622 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 7623{
d62a17ae 7624 int idx_peer = 2;
7625 int ret;
7626 struct peer *peer;
718e3744 7627
d62a17ae 7628 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7629 if (!peer)
7630 return CMD_WARNING_CONFIG_FAILED;
718e3744 7631
d62a17ae 7632 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
7633 bgp_node_safi(vty));
718e3744 7634
d62a17ae 7635 return bgp_vty_return(vty, ret);
718e3744 7636}
6b0655a2 7637
d62a17ae 7638ALIAS_HIDDEN(
7639 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
7640 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
7641 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7642 "allow local ASN appears in aspath attribute\n"
f79f7a7b 7643 "Number of occurrences of AS number\n"
d62a17ae 7644 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 7645
fa411a21
NH
7646DEFUN (neighbor_ttl_security,
7647 neighbor_ttl_security_cmd,
7ebe625c 7648 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 7649 NEIGHBOR_STR
7ebe625c 7650 NEIGHBOR_ADDR_STR2
16cedbb0 7651 "BGP ttl-security parameters\n"
d7fa34c1
QY
7652 "Specify the maximum number of hops to the BGP peer\n"
7653 "Number of hops to BGP peer\n")
fa411a21 7654{
d62a17ae 7655 int idx_peer = 1;
7656 int idx_number = 4;
7657 struct peer *peer;
7658 int gtsm_hops;
7659
7660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7661 if (!peer)
7662 return CMD_WARNING_CONFIG_FAILED;
7663
7664 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
7665
7ebe625c
QY
7666 /*
7667 * If 'neighbor swpX', then this is for directly connected peers,
7668 * we should not accept a ttl-security hops value greater than 1.
7669 */
e2521429 7670 if (peer->conf_if && (gtsm_hops > BGP_GTSM_HOPS_CONNECTED)) {
7ebe625c
QY
7671 vty_out(vty,
7672 "%s is directly connected peer, hops cannot exceed 1\n",
7673 argv[idx_peer]->arg);
7674 return CMD_WARNING_CONFIG_FAILED;
7675 }
7676
d62a17ae 7677 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
7678}
7679
7680DEFUN (no_neighbor_ttl_security,
7681 no_neighbor_ttl_security_cmd,
7ebe625c 7682 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
7683 NO_STR
7684 NEIGHBOR_STR
7ebe625c 7685 NEIGHBOR_ADDR_STR2
16cedbb0 7686 "BGP ttl-security parameters\n"
3a2d747c
QY
7687 "Specify the maximum number of hops to the BGP peer\n"
7688 "Number of hops to BGP peer\n")
fa411a21 7689{
d62a17ae 7690 int idx_peer = 2;
7691 struct peer *peer;
fa411a21 7692
d62a17ae 7693 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7694 if (!peer)
7695 return CMD_WARNING_CONFIG_FAILED;
fa411a21 7696
d62a17ae 7697 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 7698}
6b0655a2 7699
adbac85e
DW
7700DEFUN (neighbor_addpath_tx_all_paths,
7701 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7702 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7703 NEIGHBOR_STR
7704 NEIGHBOR_ADDR_STR2
7705 "Use addpath to advertise all paths to a neighbor\n")
7706{
d62a17ae 7707 int idx_peer = 1;
7708 struct peer *peer;
adbac85e 7709
d62a17ae 7710 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7711 if (!peer)
7712 return CMD_WARNING_CONFIG_FAILED;
adbac85e 7713
dcc68b5e
MS
7714 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7715 BGP_ADDPATH_ALL);
7716 return CMD_SUCCESS;
adbac85e
DW
7717}
7718
d62a17ae 7719ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
7720 neighbor_addpath_tx_all_paths_hidden_cmd,
7721 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7722 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7723 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7724
adbac85e
DW
7725DEFUN (no_neighbor_addpath_tx_all_paths,
7726 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 7727 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
7728 NO_STR
7729 NEIGHBOR_STR
7730 NEIGHBOR_ADDR_STR2
7731 "Use addpath to advertise all paths to a neighbor\n")
7732{
d62a17ae 7733 int idx_peer = 2;
dcc68b5e
MS
7734 struct peer *peer;
7735
7736 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7737 if (!peer)
7738 return CMD_WARNING_CONFIG_FAILED;
7739
7740 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7741 != BGP_ADDPATH_ALL) {
7742 vty_out(vty,
7743 "%% Peer not currently configured to transmit all paths.");
7744 return CMD_WARNING_CONFIG_FAILED;
7745 }
7746
7747 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7748 BGP_ADDPATH_NONE);
7749
7750 return CMD_SUCCESS;
adbac85e
DW
7751}
7752
d62a17ae 7753ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
7754 no_neighbor_addpath_tx_all_paths_hidden_cmd,
7755 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
7756 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7757 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 7758
06370dac
DW
7759DEFUN (neighbor_addpath_tx_bestpath_per_as,
7760 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7761 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7762 NEIGHBOR_STR
7763 NEIGHBOR_ADDR_STR2
7764 "Use addpath to advertise the bestpath per each neighboring AS\n")
7765{
d62a17ae 7766 int idx_peer = 1;
7767 struct peer *peer;
06370dac 7768
d62a17ae 7769 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7770 if (!peer)
7771 return CMD_WARNING_CONFIG_FAILED;
06370dac 7772
dcc68b5e
MS
7773 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7774 BGP_ADDPATH_BEST_PER_AS);
7775
7776 return CMD_SUCCESS;
06370dac
DW
7777}
7778
d62a17ae 7779ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
7780 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7781 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7782 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7783 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7784
06370dac
DW
7785DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
7786 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 7787 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
7788 NO_STR
7789 NEIGHBOR_STR
7790 NEIGHBOR_ADDR_STR2
7791 "Use addpath to advertise the bestpath per each neighboring AS\n")
7792{
d62a17ae 7793 int idx_peer = 2;
dcc68b5e
MS
7794 struct peer *peer;
7795
7796 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
7797 if (!peer)
7798 return CMD_WARNING_CONFIG_FAILED;
7799
7800 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
7801 != BGP_ADDPATH_BEST_PER_AS) {
7802 vty_out(vty,
7803 "%% Peer not currently configured to transmit all best path per as.");
7804 return CMD_WARNING_CONFIG_FAILED;
7805 }
7806
7807 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7808 BGP_ADDPATH_NONE);
7809
7810 return CMD_SUCCESS;
06370dac
DW
7811}
7812
d62a17ae 7813ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
7814 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
7815 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
7816 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7817 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 7818
2b31007c
RZ
7819DEFPY(
7820 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
7821 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7822 NEIGHBOR_STR
7823 NEIGHBOR_ADDR_STR2
7824 "Detect AS loops before sending to neighbor\n")
7825{
7826 struct peer *peer;
7827
7828 peer = peer_and_group_lookup_vty(vty, neighbor);
7829 if (!peer)
7830 return CMD_WARNING_CONFIG_FAILED;
7831
7832 peer->as_path_loop_detection = true;
7833
7834 return CMD_SUCCESS;
7835}
7836
7837DEFPY(
7838 no_neighbor_aspath_loop_detection,
7839 no_neighbor_aspath_loop_detection_cmd,
7840 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
7841 NO_STR
7842 NEIGHBOR_STR
7843 NEIGHBOR_ADDR_STR2
7844 "Detect AS loops before sending to neighbor\n")
7845{
7846 struct peer *peer;
7847
7848 peer = peer_and_group_lookup_vty(vty, neighbor);
7849 if (!peer)
7850 return CMD_WARNING_CONFIG_FAILED;
7851
7852 peer->as_path_loop_detection = false;
7853
7854 return CMD_SUCCESS;
7855}
7856
b9c7bc5a 7857static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 7858 struct ecommunity **list, bool is_rt6)
ddb5b488 7859{
b9c7bc5a
PZ
7860 struct ecommunity *ecom = NULL;
7861 struct ecommunity *ecomadd;
ddb5b488 7862
b9c7bc5a 7863 for (; argc; --argc, ++argv) {
9a659715
PG
7864 if (is_rt6)
7865 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
7866 ECOMMUNITY_ROUTE_TARGET,
7867 0);
7868 else
7869 ecomadd = ecommunity_str2com(argv[0]->arg,
7870 ECOMMUNITY_ROUTE_TARGET,
7871 0);
b9c7bc5a
PZ
7872 if (!ecomadd) {
7873 vty_out(vty, "Malformed community-list value\n");
7874 if (ecom)
7875 ecommunity_free(&ecom);
7876 return CMD_WARNING_CONFIG_FAILED;
7877 }
ddb5b488 7878
b9c7bc5a
PZ
7879 if (ecom) {
7880 ecommunity_merge(ecom, ecomadd);
7881 ecommunity_free(&ecomadd);
7882 } else {
7883 ecom = ecomadd;
7884 }
7885 }
7886
7887 if (*list) {
7888 ecommunity_free(&*list);
ddb5b488 7889 }
b9c7bc5a
PZ
7890 *list = ecom;
7891
7892 return CMD_SUCCESS;
ddb5b488
PZ
7893}
7894
0ca70ba5
DS
7895/*
7896 * v2vimport is true if we are handling a `import vrf ...` command
7897 */
7898static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 7899{
0ca70ba5
DS
7900 afi_t afi;
7901
ddb5b488 7902 switch (vty->node) {
b9c7bc5a 7903 case BGP_IPV4_NODE:
0ca70ba5
DS
7904 afi = AFI_IP;
7905 break;
b9c7bc5a 7906 case BGP_IPV6_NODE:
0ca70ba5
DS
7907 afi = AFI_IP6;
7908 break;
ddb5b488
PZ
7909 default:
7910 vty_out(vty,
b9c7bc5a 7911 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 7912 return AFI_MAX;
ddb5b488 7913 }
69b07479 7914
0ca70ba5
DS
7915 if (!v2vimport) {
7916 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7917 BGP_CONFIG_VRF_TO_VRF_IMPORT)
7918 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7919 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
7920 vty_out(vty,
7921 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
7922 return AFI_MAX;
7923 }
7924 } else {
7925 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7926 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
7927 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
7928 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
7929 vty_out(vty,
7930 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
7931 return AFI_MAX;
7932 }
7933 }
7934 return afi;
ddb5b488
PZ
7935}
7936
b9c7bc5a
PZ
7937DEFPY (af_rd_vpn_export,
7938 af_rd_vpn_export_cmd,
7939 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
7940 NO_STR
ddb5b488 7941 "Specify route distinguisher\n"
b9c7bc5a
PZ
7942 "Between current address-family and vpn\n"
7943 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
7944 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
7945{
7946 VTY_DECLVAR_CONTEXT(bgp, bgp);
7947 struct prefix_rd prd;
7948 int ret;
ddb5b488 7949 afi_t afi;
b9c7bc5a 7950 int idx = 0;
c6423c31 7951 bool yes = true;
ddb5b488 7952
b9c7bc5a 7953 if (argv_find(argv, argc, "no", &idx))
c6423c31 7954 yes = false;
b9c7bc5a
PZ
7955
7956 if (yes) {
7957 ret = str2prefix_rd(rd_str, &prd);
7958 if (!ret) {
7959 vty_out(vty, "%% Malformed rd\n");
7960 return CMD_WARNING_CONFIG_FAILED;
7961 }
ddb5b488
PZ
7962 }
7963
0ca70ba5 7964 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
7965 if (afi == AFI_MAX)
7966 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 7967
69b07479
DS
7968 /*
7969 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
7970 */
7971 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7972 bgp_get_default(), bgp);
ddb5b488 7973
69b07479
DS
7974 if (yes) {
7975 bgp->vpn_policy[afi].tovpn_rd = prd;
7976 SET_FLAG(bgp->vpn_policy[afi].flags,
7977 BGP_VPN_POLICY_TOVPN_RD_SET);
7978 } else {
7979 UNSET_FLAG(bgp->vpn_policy[afi].flags,
7980 BGP_VPN_POLICY_TOVPN_RD_SET);
ddb5b488
PZ
7981 }
7982
69b07479
DS
7983 /* post-change: re-export vpn routes */
7984 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
7985 bgp_get_default(), bgp);
7986
ddb5b488
PZ
7987 return CMD_SUCCESS;
7988}
7989
b9c7bc5a
PZ
7990ALIAS (af_rd_vpn_export,
7991 af_no_rd_vpn_export_cmd,
7992 "no rd vpn export",
ddb5b488 7993 NO_STR
b9c7bc5a
PZ
7994 "Specify route distinguisher\n"
7995 "Between current address-family and vpn\n"
7996 "For routes leaked from current address-family to vpn\n")
ddb5b488 7997
b9c7bc5a
PZ
7998DEFPY (af_label_vpn_export,
7999 af_label_vpn_export_cmd,
e70e9f8e 8000 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 8001 NO_STR
ddb5b488 8002 "label value for VRF\n"
b9c7bc5a
PZ
8003 "Between current address-family and vpn\n"
8004 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
8005 "Label Value <0-1048575>\n"
8006 "Automatically assign a label\n")
ddb5b488
PZ
8007{
8008 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8009 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 8010 afi_t afi;
b9c7bc5a 8011 int idx = 0;
c6423c31 8012 bool yes = true;
b9c7bc5a
PZ
8013
8014 if (argv_find(argv, argc, "no", &idx))
c6423c31 8015 yes = false;
ddb5b488 8016
21a16cc2
PZ
8017 /* If "no ...", squash trailing parameter */
8018 if (!yes)
8019 label_auto = NULL;
8020
e70e9f8e
PZ
8021 if (yes) {
8022 if (!label_auto)
8023 label = label_val; /* parser should force unsigned */
8024 }
ddb5b488 8025
0ca70ba5 8026 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8027 if (afi == AFI_MAX)
8028 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 8029
e70e9f8e 8030
69b07479
DS
8031 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8032 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
8033 /* no change */
8034 return CMD_SUCCESS;
e70e9f8e 8035
69b07479
DS
8036 /*
8037 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8038 */
8039 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8040 bgp_get_default(), bgp);
8041
8042 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
8043 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
8044
8045 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
8046
8047 /*
8048 * label has previously been automatically
8049 * assigned by labelpool: release it
8050 *
8051 * NB if tovpn_label == MPLS_LABEL_NONE it
8052 * means the automatic assignment is in flight
8053 * and therefore the labelpool callback must
8054 * detect that the auto label is not needed.
8055 */
8056
8057 bgp_lp_release(LP_TYPE_VRF,
8058 &bgp->vpn_policy[afi],
8059 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 8060 }
69b07479
DS
8061 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8062 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8063 }
ddb5b488 8064
69b07479
DS
8065 bgp->vpn_policy[afi].tovpn_label = label;
8066 if (label_auto) {
8067 SET_FLAG(bgp->vpn_policy[afi].flags,
8068 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
8069 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
8070 vpn_leak_label_callback);
ddb5b488
PZ
8071 }
8072
69b07479
DS
8073 /* post-change: re-export vpn routes */
8074 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8075 bgp_get_default(), bgp);
8076
ddb5b488
PZ
8077 return CMD_SUCCESS;
8078}
8079
b9c7bc5a
PZ
8080ALIAS (af_label_vpn_export,
8081 af_no_label_vpn_export_cmd,
8082 "no label vpn export",
8083 NO_STR
8084 "label value for VRF\n"
8085 "Between current address-family and vpn\n"
8086 "For routes leaked from current address-family to vpn\n")
ddb5b488 8087
b9c7bc5a
PZ
8088DEFPY (af_nexthop_vpn_export,
8089 af_nexthop_vpn_export_cmd,
8c85ca28 8090 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 8091 NO_STR
ddb5b488 8092 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
8093 "Between current address-family and vpn\n"
8094 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8095 "IPv4 prefix\n"
8096 "IPv6 prefix\n")
8097{
8098 VTY_DECLVAR_CONTEXT(bgp, bgp);
ddb5b488 8099 afi_t afi;
ddb5b488
PZ
8100 struct prefix p;
8101
8c85ca28
QY
8102 if (!no) {
8103 if (!nexthop_su) {
8104 vty_out(vty, "%% Nexthop required\n");
8105 return CMD_WARNING_CONFIG_FAILED;
8106 }
8c85ca28 8107 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
8108 return CMD_WARNING_CONFIG_FAILED;
8109 }
ddb5b488 8110
0ca70ba5 8111 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8112 if (afi == AFI_MAX)
8113 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8114
69b07479
DS
8115 /*
8116 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
8117 */
8118 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8119 bgp_get_default(), bgp);
ddb5b488 8120
8c85ca28 8121 if (!no) {
69b07479
DS
8122 bgp->vpn_policy[afi].tovpn_nexthop = p;
8123 SET_FLAG(bgp->vpn_policy[afi].flags,
8124 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
8125 } else {
8126 UNSET_FLAG(bgp->vpn_policy[afi].flags,
8127 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
ddb5b488
PZ
8128 }
8129
69b07479
DS
8130 /* post-change: re-export vpn routes */
8131 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
8132 bgp_get_default(), bgp);
8133
ddb5b488
PZ
8134 return CMD_SUCCESS;
8135}
8136
b9c7bc5a 8137static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 8138{
b9c7bc5a
PZ
8139 if (!strcmp(dstr, "import")) {
8140 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8141 } else if (!strcmp(dstr, "export")) {
8142 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8143 } else if (!strcmp(dstr, "both")) {
8144 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
8145 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
8146 } else {
8147 vty_out(vty, "%% direction parse error\n");
8148 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8149 }
ddb5b488
PZ
8150 return CMD_SUCCESS;
8151}
8152
b9c7bc5a
PZ
8153DEFPY (af_rt_vpn_imexport,
8154 af_rt_vpn_imexport_cmd,
8155 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
8156 NO_STR
8157 "Specify route target list\n"
ddb5b488 8158 "Specify route target list\n"
b9c7bc5a
PZ
8159 "Between current address-family and vpn\n"
8160 "For routes leaked from vpn to current address-family: match any\n"
8161 "For routes leaked from current address-family to vpn: set\n"
8162 "both import: match any and export: set\n"
ddb5b488
PZ
8163 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
8164{
8165 VTY_DECLVAR_CONTEXT(bgp, bgp);
8166 int ret;
8167 struct ecommunity *ecom = NULL;
8168 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8169 vpn_policy_direction_t dir;
8170 afi_t afi;
8171 int idx = 0;
c6423c31 8172 bool yes = true;
ddb5b488 8173
b9c7bc5a 8174 if (argv_find(argv, argc, "no", &idx))
c6423c31 8175 yes = false;
b9c7bc5a 8176
0ca70ba5 8177 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8178 if (afi == AFI_MAX)
8179 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8180
b9c7bc5a 8181 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8182 if (ret != CMD_SUCCESS)
8183 return ret;
8184
b9c7bc5a
PZ
8185 if (yes) {
8186 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8187 vty_out(vty, "%% Missing RTLIST\n");
8188 return CMD_WARNING_CONFIG_FAILED;
8189 }
c6423c31 8190 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
8191 if (ret != CMD_SUCCESS) {
8192 return ret;
8193 }
ddb5b488
PZ
8194 }
8195
69b07479
DS
8196 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8197 if (!dodir[dir])
ddb5b488 8198 continue;
ddb5b488 8199
69b07479 8200 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8201
69b07479
DS
8202 if (yes) {
8203 if (bgp->vpn_policy[afi].rtlist[dir])
8204 ecommunity_free(
8205 &bgp->vpn_policy[afi].rtlist[dir]);
8206 bgp->vpn_policy[afi].rtlist[dir] =
8207 ecommunity_dup(ecom);
8208 } else {
8209 if (bgp->vpn_policy[afi].rtlist[dir])
8210 ecommunity_free(
8211 &bgp->vpn_policy[afi].rtlist[dir]);
8212 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 8213 }
69b07479
DS
8214
8215 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8216 }
69b07479 8217
d555f3e9
PZ
8218 if (ecom)
8219 ecommunity_free(&ecom);
ddb5b488
PZ
8220
8221 return CMD_SUCCESS;
8222}
8223
b9c7bc5a
PZ
8224ALIAS (af_rt_vpn_imexport,
8225 af_no_rt_vpn_imexport_cmd,
8226 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
8227 NO_STR
8228 "Specify route target list\n"
b9c7bc5a
PZ
8229 "Specify route target list\n"
8230 "Between current address-family and vpn\n"
8231 "For routes leaked from vpn to current address-family\n"
8232 "For routes leaked from current address-family to vpn\n"
8233 "both import and export\n")
8234
8235DEFPY (af_route_map_vpn_imexport,
8236 af_route_map_vpn_imexport_cmd,
8237/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
8238 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
8239 NO_STR
ddb5b488 8240 "Specify route map\n"
b9c7bc5a
PZ
8241 "Between current address-family and vpn\n"
8242 "For routes leaked from vpn to current address-family\n"
8243 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
8244 "name of route-map\n")
8245{
8246 VTY_DECLVAR_CONTEXT(bgp, bgp);
8247 int ret;
8248 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
8249 vpn_policy_direction_t dir;
8250 afi_t afi;
ddb5b488 8251 int idx = 0;
c6423c31 8252 bool yes = true;
ddb5b488 8253
b9c7bc5a 8254 if (argv_find(argv, argc, "no", &idx))
c6423c31 8255 yes = false;
b9c7bc5a 8256
0ca70ba5 8257 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8258 if (afi == AFI_MAX)
8259 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 8260
b9c7bc5a 8261 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
8262 if (ret != CMD_SUCCESS)
8263 return ret;
8264
69b07479
DS
8265 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
8266 if (!dodir[dir])
ddb5b488 8267 continue;
ddb5b488 8268
69b07479 8269 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 8270
69b07479
DS
8271 if (yes) {
8272 if (bgp->vpn_policy[afi].rmap_name[dir])
8273 XFREE(MTYPE_ROUTE_MAP_NAME,
8274 bgp->vpn_policy[afi].rmap_name[dir]);
8275 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
8276 MTYPE_ROUTE_MAP_NAME, rmap_str);
8277 bgp->vpn_policy[afi].rmap[dir] =
1de27621 8278 route_map_lookup_warn_noexist(vty, rmap_str);
69b07479
DS
8279 if (!bgp->vpn_policy[afi].rmap[dir])
8280 return CMD_SUCCESS;
8281 } else {
8282 if (bgp->vpn_policy[afi].rmap_name[dir])
8283 XFREE(MTYPE_ROUTE_MAP_NAME,
8284 bgp->vpn_policy[afi].rmap_name[dir]);
8285 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8286 bgp->vpn_policy[afi].rmap[dir] = NULL;
ddb5b488 8287 }
69b07479
DS
8288
8289 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488
PZ
8290 }
8291
8292 return CMD_SUCCESS;
8293}
8294
b9c7bc5a
PZ
8295ALIAS (af_route_map_vpn_imexport,
8296 af_no_route_map_vpn_imexport_cmd,
8297 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
8298 NO_STR
8299 "Specify route map\n"
b9c7bc5a
PZ
8300 "Between current address-family and vpn\n"
8301 "For routes leaked from vpn to current address-family\n"
8302 "For routes leaked from current address-family to vpn\n")
8303
bb4f6190 8304DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 8305 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
8306 "Import routes from another VRF\n"
8307 "Vrf routes being filtered\n"
8308 "Specify route map\n"
8309 "name of route-map\n")
8310{
8311 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
8312 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8313 afi_t afi;
bb4f6190
DS
8314 struct bgp *bgp_default;
8315
0ca70ba5 8316 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
8317 if (afi == AFI_MAX)
8318 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
8319
8320 bgp_default = bgp_get_default();
8321 if (!bgp_default) {
8322 int32_t ret;
8323 as_t as = bgp->as;
8324
8325 /* Auto-create assuming the same AS */
5d5393b9
DL
8326 ret = bgp_get_vty(&bgp_default, &as, NULL,
8327 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
8328
8329 if (ret) {
8330 vty_out(vty,
8331 "VRF default is not configured as a bgp instance\n");
8332 return CMD_WARNING;
8333 }
8334 }
8335
69b07479 8336 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 8337
ae6a6fb4
DS
8338 if (bgp->vpn_policy[afi].rmap_name[dir])
8339 XFREE(MTYPE_ROUTE_MAP_NAME,
8340 bgp->vpn_policy[afi].rmap_name[dir]);
8341 bgp->vpn_policy[afi].rmap_name[dir] =
8342 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
8343 bgp->vpn_policy[afi].rmap[dir] =
8344 route_map_lookup_warn_noexist(vty, rmap_str);
8345 if (!bgp->vpn_policy[afi].rmap[dir])
8346 return CMD_SUCCESS;
8347
8348 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8349 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 8350
69b07479
DS
8351 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8352
bb4f6190
DS
8353 return CMD_SUCCESS;
8354}
8355
ae6a6fb4
DS
8356DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
8357 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
8358 NO_STR
8359 "Import routes from another VRF\n"
8360 "Vrf routes being filtered\n"
ae6a6fb4
DS
8361 "Specify route map\n"
8362 "name of route-map\n")
8363{
8364 VTY_DECLVAR_CONTEXT(bgp, bgp);
8365 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
8366 afi_t afi;
8367
8368 afi = vpn_policy_getafi(vty, bgp, true);
8369 if (afi == AFI_MAX)
8370 return CMD_WARNING_CONFIG_FAILED;
8371
8372 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8373
8374 if (bgp->vpn_policy[afi].rmap_name[dir])
8375 XFREE(MTYPE_ROUTE_MAP_NAME,
8376 bgp->vpn_policy[afi].rmap_name[dir]);
8377 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
8378 bgp->vpn_policy[afi].rmap[dir] = NULL;
8379
8380 if (bgp->vpn_policy[afi].import_vrf->count == 0)
8381 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8382 BGP_CONFIG_VRF_TO_VRF_IMPORT);
8383
8384 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8385
8386 return CMD_SUCCESS;
8387}
bb4f6190 8388
4d1b335c
DA
8389DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
8390 "[no] import vrf VIEWVRFNAME$import_name",
8391 NO_STR
8392 "Import routes from another VRF\n"
8393 "VRF to import from\n"
8394 "The name of the VRF\n")
12a844a5
DS
8395{
8396 VTY_DECLVAR_CONTEXT(bgp, bgp);
8397 struct listnode *node;
79ef8664
DS
8398 struct bgp *vrf_bgp, *bgp_default;
8399 int32_t ret = 0;
8400 as_t as = bgp->as;
12a844a5
DS
8401 bool remove = false;
8402 int32_t idx = 0;
8403 char *vname;
a8dadcf6 8404 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
12a844a5
DS
8405 safi_t safi;
8406 afi_t afi;
8407
867f0cca 8408 if (import_name == NULL) {
8409 vty_out(vty, "%% Missing import name\n");
8410 return CMD_WARNING;
8411 }
8412
ae6a6fb4
DS
8413 if (strcmp(import_name, "route-map") == 0) {
8414 vty_out(vty, "%% Must include route-map name\n");
8415 return CMD_WARNING;
8416 }
8417
12a844a5
DS
8418 if (argv_find(argv, argc, "no", &idx))
8419 remove = true;
8420
0ca70ba5
DS
8421 afi = vpn_policy_getafi(vty, bgp, true);
8422 if (afi == AFI_MAX)
8423 return CMD_WARNING_CONFIG_FAILED;
8424
12a844a5
DS
8425 safi = bgp_node_safi(vty);
8426
25679caa 8427 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
5742e42b 8428 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
25679caa
DS
8429 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
8430 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
8431 remove ? "unimport" : "import", import_name);
8432 return CMD_WARNING;
8433 }
8434
79ef8664
DS
8435 bgp_default = bgp_get_default();
8436 if (!bgp_default) {
8437 /* Auto-create assuming the same AS */
5d5393b9
DL
8438 ret = bgp_get_vty(&bgp_default, &as, NULL,
8439 BGP_INSTANCE_TYPE_DEFAULT);
79ef8664
DS
8440
8441 if (ret) {
8442 vty_out(vty,
8443 "VRF default is not configured as a bgp instance\n");
8444 return CMD_WARNING;
8445 }
8446 }
8447
12a844a5
DS
8448 vrf_bgp = bgp_lookup_by_name(import_name);
8449 if (!vrf_bgp) {
5742e42b 8450 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
79ef8664
DS
8451 vrf_bgp = bgp_default;
8452 else
0fb8d6e6 8453 /* Auto-create assuming the same AS */
5d5393b9 8454 ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
a8dadcf6 8455
6e2c7fe6 8456 if (ret) {
020a3f60
DS
8457 vty_out(vty,
8458 "VRF %s is not configured as a bgp instance\n",
6e2c7fe6
DS
8459 import_name);
8460 return CMD_WARNING;
8461 }
12a844a5
DS
8462 }
8463
12a844a5 8464 if (remove) {
44338987 8465 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5 8466 } else {
44338987 8467 /* Already importing from "import_vrf"? */
12a844a5
DS
8468 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
8469 vname)) {
8470 if (strcmp(vname, import_name) == 0)
8471 return CMD_WARNING;
8472 }
8473
44338987 8474 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
12a844a5
DS
8475 }
8476
8477 return CMD_SUCCESS;
8478}
8479
b9c7bc5a
PZ
8480/* This command is valid only in a bgp vrf instance or the default instance */
8481DEFPY (bgp_imexport_vpn,
8482 bgp_imexport_vpn_cmd,
8483 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
8484 NO_STR
8485 "Import routes to this address-family\n"
8486 "Export routes from this address-family\n"
8487 "to/from default instance VPN RIB\n")
ddb5b488
PZ
8488{
8489 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 8490 int previous_state;
ddb5b488 8491 afi_t afi;
b9c7bc5a 8492 safi_t safi;
ddb5b488 8493 int idx = 0;
c6423c31 8494 bool yes = true;
b9c7bc5a
PZ
8495 int flag;
8496 vpn_policy_direction_t dir;
ddb5b488 8497
b9c7bc5a 8498 if (argv_find(argv, argc, "no", &idx))
c6423c31 8499 yes = false;
ddb5b488 8500
b9c7bc5a
PZ
8501 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
8502 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 8503
b9c7bc5a
PZ
8504 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
8505 return CMD_WARNING_CONFIG_FAILED;
8506 }
ddb5b488 8507
b9c7bc5a
PZ
8508 afi = bgp_node_afi(vty);
8509 safi = bgp_node_safi(vty);
8510 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
8511 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
8512 return CMD_WARNING_CONFIG_FAILED;
8513 }
ddb5b488 8514
b9c7bc5a
PZ
8515 if (!strcmp(direction_str, "import")) {
8516 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
8517 dir = BGP_VPN_POLICY_DIR_FROMVPN;
8518 } else if (!strcmp(direction_str, "export")) {
8519 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
8520 dir = BGP_VPN_POLICY_DIR_TOVPN;
8521 } else {
8522 vty_out(vty, "%% unknown direction %s\n", direction_str);
8523 return CMD_WARNING_CONFIG_FAILED;
8524 }
8525
8526 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 8527
b9c7bc5a
PZ
8528 if (yes) {
8529 SET_FLAG(bgp->af_flags[afi][safi], flag);
8530 if (!previous_state) {
8531 /* trigger export current vrf */
ddb5b488
PZ
8532 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
8533 }
b9c7bc5a
PZ
8534 } else {
8535 if (previous_state) {
8536 /* trigger un-export current vrf */
8537 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
8538 }
8539 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
8540 }
8541
8542 return CMD_SUCCESS;
8543}
8544
301ad80a
PG
8545DEFPY (af_routetarget_import,
8546 af_routetarget_import_cmd,
9a659715 8547 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
8548 NO_STR
8549 "Specify route target list\n"
8550 "Specify route target list\n"
9a659715
PG
8551 "Specify route target list\n"
8552 "Specify route target list\n"
301ad80a
PG
8553 "Flow-spec redirect type route target\n"
8554 "Import routes to this address-family\n"
9a659715 8555 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
8556{
8557 VTY_DECLVAR_CONTEXT(bgp, bgp);
8558 int ret;
8559 struct ecommunity *ecom = NULL;
301ad80a 8560 afi_t afi;
9a659715 8561 int idx = 0, idx_unused = 0;
c6423c31
PG
8562 bool yes = true;
8563 bool rt6 = false;
301ad80a
PG
8564
8565 if (argv_find(argv, argc, "no", &idx))
c6423c31 8566 yes = false;
301ad80a 8567
9a659715
PG
8568 if (argv_find(argv, argc, "rt6", &idx_unused) ||
8569 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 8570 rt6 = true;
301ad80a 8571
0ca70ba5 8572 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
8573 if (afi == AFI_MAX)
8574 return CMD_WARNING_CONFIG_FAILED;
8575
9a659715
PG
8576 if (rt6 && afi != AFI_IP6)
8577 return CMD_WARNING_CONFIG_FAILED;
8578
301ad80a
PG
8579 if (yes) {
8580 if (!argv_find(argv, argc, "RTLIST", &idx)) {
8581 vty_out(vty, "%% Missing RTLIST\n");
8582 return CMD_WARNING_CONFIG_FAILED;
8583 }
9a659715 8584 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
8585 if (ret != CMD_SUCCESS)
8586 return ret;
8587 }
69b07479
DS
8588
8589 if (yes) {
8590 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8591 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8592 .import_redirect_rtlist);
69b07479
DS
8593 bgp->vpn_policy[afi].import_redirect_rtlist =
8594 ecommunity_dup(ecom);
8595 } else {
8596 if (bgp->vpn_policy[afi].import_redirect_rtlist)
8597 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 8598 .import_redirect_rtlist);
69b07479 8599 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 8600 }
69b07479 8601
301ad80a
PG
8602 if (ecom)
8603 ecommunity_free(&ecom);
8604
8605 return CMD_SUCCESS;
8606}
8607
505e5056 8608DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 8609 address_family_ipv4_safi_cmd,
8610 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8611 "Enter Address Family command mode\n"
8612 "Address Family\n"
8613 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 8614{
f51bae9c 8615
d62a17ae 8616 if (argc == 3) {
2131d5cf 8617 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8618 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8619 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8620 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8621 && safi != SAFI_EVPN) {
31947174
MK
8622 vty_out(vty,
8623 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8624 return CMD_WARNING_CONFIG_FAILED;
8625 }
d62a17ae 8626 vty->node = bgp_node_type(AFI_IP, safi);
8627 } else
8628 vty->node = BGP_IPV4_NODE;
718e3744 8629
d62a17ae 8630 return CMD_SUCCESS;
718e3744 8631}
8632
505e5056 8633DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 8634 address_family_ipv6_safi_cmd,
8635 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
8636 "Enter Address Family command mode\n"
8637 "Address Family\n"
8638 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 8639{
d62a17ae 8640 if (argc == 3) {
2131d5cf 8641 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8642 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
8643 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
8644 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 8645 && safi != SAFI_EVPN) {
31947174
MK
8646 vty_out(vty,
8647 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
8648 return CMD_WARNING_CONFIG_FAILED;
8649 }
d62a17ae 8650 vty->node = bgp_node_type(AFI_IP6, safi);
8651 } else
8652 vty->node = BGP_IPV6_NODE;
25ffbdc1 8653
d62a17ae 8654 return CMD_SUCCESS;
25ffbdc1 8655}
718e3744 8656
d6902373 8657#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 8658DEFUN_NOSH (address_family_vpnv4,
718e3744 8659 address_family_vpnv4_cmd,
8334fd5a 8660 "address-family vpnv4 [unicast]",
718e3744 8661 "Enter Address Family command mode\n"
8c3deaae 8662 "Address Family\n"
3a2d747c 8663 "Address Family modifier\n")
718e3744 8664{
d62a17ae 8665 vty->node = BGP_VPNV4_NODE;
8666 return CMD_SUCCESS;
718e3744 8667}
8668
505e5056 8669DEFUN_NOSH (address_family_vpnv6,
8ecd3266 8670 address_family_vpnv6_cmd,
8334fd5a 8671 "address-family vpnv6 [unicast]",
8ecd3266 8672 "Enter Address Family command mode\n"
8c3deaae 8673 "Address Family\n"
3a2d747c 8674 "Address Family modifier\n")
8ecd3266 8675{
d62a17ae 8676 vty->node = BGP_VPNV6_NODE;
8677 return CMD_SUCCESS;
8ecd3266 8678}
64e4a6c5 8679#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 8680
505e5056 8681DEFUN_NOSH (address_family_evpn,
4e0b7b6d 8682 address_family_evpn_cmd,
7111c1a0 8683 "address-family l2vpn evpn",
4e0b7b6d 8684 "Enter Address Family command mode\n"
7111c1a0
QY
8685 "Address Family\n"
8686 "Address Family modifier\n")
4e0b7b6d 8687{
2131d5cf 8688 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 8689 vty->node = BGP_EVPN_NODE;
8690 return CMD_SUCCESS;
4e0b7b6d
PG
8691}
8692
505e5056 8693DEFUN_NOSH (exit_address_family,
718e3744 8694 exit_address_family_cmd,
8695 "exit-address-family",
8696 "Exit from Address Family configuration mode\n")
8697{
d62a17ae 8698 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
8699 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
8700 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
8701 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
8702 || vty->node == BGP_EVPN_NODE
8703 || vty->node == BGP_FLOWSPECV4_NODE
8704 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 8705 vty->node = BGP_NODE;
8706 return CMD_SUCCESS;
718e3744 8707}
6b0655a2 8708
8ad7271d 8709/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 8710static int bgp_clear_prefix(struct vty *vty, const char *view_name,
8711 const char *ip_str, afi_t afi, safi_t safi,
8712 struct prefix_rd *prd)
8713{
8714 int ret;
8715 struct prefix match;
9bcb3eef
DS
8716 struct bgp_dest *dest;
8717 struct bgp_dest *rm;
d62a17ae 8718 struct bgp *bgp;
8719 struct bgp_table *table;
8720 struct bgp_table *rib;
8721
8722 /* BGP structure lookup. */
8723 if (view_name) {
8724 bgp = bgp_lookup_by_name(view_name);
8725 if (bgp == NULL) {
8726 vty_out(vty, "%% Can't find BGP instance %s\n",
8727 view_name);
8728 return CMD_WARNING;
8729 }
8730 } else {
8731 bgp = bgp_get_default();
8732 if (bgp == NULL) {
8733 vty_out(vty, "%% No BGP process is configured\n");
8734 return CMD_WARNING;
8735 }
8736 }
8737
8738 /* Check IP address argument. */
8739 ret = str2prefix(ip_str, &match);
8740 if (!ret) {
8741 vty_out(vty, "%% address is malformed\n");
8742 return CMD_WARNING;
8743 }
8744
8745 match.family = afi2family(afi);
8746 rib = bgp->rib[afi][safi];
8747
8748 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
8749 for (dest = bgp_table_top(rib); dest;
8750 dest = bgp_route_next(dest)) {
8751 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8752
9bcb3eef 8753 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 8754 continue;
8755
9bcb3eef 8756 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
8757 if (table == NULL)
8758 continue;
8759
8760 if ((rm = bgp_node_match(table, &match)) != NULL) {
8761 const struct prefix *rm_p =
9bcb3eef 8762 bgp_dest_get_prefix(rm);
b54892e0
DS
8763
8764 if (rm_p->prefixlen == match.prefixlen) {
8765 SET_FLAG(rm->flags,
8766 BGP_NODE_USER_CLEAR);
8767 bgp_process(bgp, rm, afi, safi);
d62a17ae 8768 }
9bcb3eef 8769 bgp_dest_unlock_node(rm);
d62a17ae 8770 }
8771 }
8772 } else {
9bcb3eef
DS
8773 if ((dest = bgp_node_match(rib, &match)) != NULL) {
8774 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 8775
9bcb3eef
DS
8776 if (dest_p->prefixlen == match.prefixlen) {
8777 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
8778 bgp_process(bgp, dest, afi, safi);
d62a17ae 8779 }
9bcb3eef 8780 bgp_dest_unlock_node(dest);
d62a17ae 8781 }
8782 }
8783
8784 return CMD_SUCCESS;
8ad7271d
DS
8785}
8786
b09b5ae0 8787/* one clear bgp command to rule them all */
718e3744 8788DEFUN (clear_ip_bgp_all,
8789 clear_ip_bgp_all_cmd,
453c92f6 8790 "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 8791 CLEAR_STR
8792 IP_STR
8793 BGP_STR
838758ac 8794 BGP_INSTANCE_HELP_STR
510afcd6 8795 BGP_AFI_HELP_STR
fd5e7b70 8796 "Address Family\n"
510afcd6 8797 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 8798 "Address Family modifier\n"
b09b5ae0 8799 "Clear all peers\n"
453c92f6 8800 "BGP IPv4 neighbor to clear\n"
a80beece 8801 "BGP IPv6 neighbor to clear\n"
838758ac 8802 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
8803 "Clear peers with the AS number\n"
8804 "Clear all external peers\n"
718e3744 8805 "Clear all members of peer-group\n"
b09b5ae0 8806 "BGP peer-group name\n"
b09b5ae0
DW
8807 BGP_SOFT_STR
8808 BGP_SOFT_IN_STR
b09b5ae0
DW
8809 BGP_SOFT_OUT_STR
8810 BGP_SOFT_IN_STR
8811 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 8812 BGP_SOFT_OUT_STR)
718e3744 8813{
d62a17ae 8814 char *vrf = NULL;
8815
dc912615
DS
8816 afi_t afi = AFI_UNSPEC;
8817 safi_t safi = SAFI_UNSPEC;
d62a17ae 8818 enum clear_sort clr_sort = clear_peer;
8819 enum bgp_clear_type clr_type;
8820 char *clr_arg = NULL;
8821
8822 int idx = 0;
ff8a8a7a
CS
8823 char errmsg[BUFSIZ] = {'\0'};
8824 int ret;
d62a17ae 8825
8826 /* clear [ip] bgp */
8827 if (argv_find(argv, argc, "ip", &idx))
8828 afi = AFI_IP;
8829
9a8bdf1c
PG
8830 /* [<vrf> VIEWVRFNAME] */
8831 if (argv_find(argv, argc, "vrf", &idx)) {
8832 vrf = argv[idx + 1]->arg;
8833 idx += 2;
8834 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8835 vrf = NULL;
8836 } else if (argv_find(argv, argc, "view", &idx)) {
8837 /* [<view> VIEWVRFNAME] */
d62a17ae 8838 vrf = argv[idx + 1]->arg;
8839 idx += 2;
8840 }
d62a17ae 8841 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8842 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
8843 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8844
d7b9898c 8845 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 8846 if (argv_find(argv, argc, "*", &idx)) {
8847 clr_sort = clear_all;
8848 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8849 clr_sort = clear_peer;
8850 clr_arg = argv[idx]->arg;
8851 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
8852 clr_sort = clear_peer;
8853 clr_arg = argv[idx]->arg;
8854 } else if (argv_find(argv, argc, "peer-group", &idx)) {
8855 clr_sort = clear_group;
8856 idx++;
8857 clr_arg = argv[idx]->arg;
d7b9898c 8858 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 8859 clr_sort = clear_peer;
8860 clr_arg = argv[idx]->arg;
8fa7d444
DS
8861 } else if (argv_find(argv, argc, "WORD", &idx)) {
8862 clr_sort = clear_peer;
8863 clr_arg = argv[idx]->arg;
d62a17ae 8864 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
8865 clr_sort = clear_as;
8866 clr_arg = argv[idx]->arg;
8867 } else if (argv_find(argv, argc, "external", &idx)) {
8868 clr_sort = clear_external;
8869 }
8870
8871 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
8872 if (argv_find(argv, argc, "soft", &idx)) {
8873 if (argv_find(argv, argc, "in", &idx)
8874 || argv_find(argv, argc, "out", &idx))
8875 clr_type = strmatch(argv[idx]->text, "in")
8876 ? BGP_CLEAR_SOFT_IN
8877 : BGP_CLEAR_SOFT_OUT;
8878 else
8879 clr_type = BGP_CLEAR_SOFT_BOTH;
8880 } else if (argv_find(argv, argc, "in", &idx)) {
8881 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
8882 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
8883 : BGP_CLEAR_SOFT_IN;
8884 } else if (argv_find(argv, argc, "out", &idx)) {
8885 clr_type = BGP_CLEAR_SOFT_OUT;
8886 } else
8887 clr_type = BGP_CLEAR_SOFT_NONE;
8888
ff8a8a7a
CS
8889 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
8890 sizeof(errmsg));
8891 if (ret != NB_OK)
8892 vty_out(vty, "Error description: %s\n", errmsg);
8893
8894 return ret;
838758ac 8895}
01080f7c 8896
8ad7271d
DS
8897DEFUN (clear_ip_bgp_prefix,
8898 clear_ip_bgp_prefix_cmd,
18c57037 8899 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
8900 CLEAR_STR
8901 IP_STR
8902 BGP_STR
838758ac 8903 BGP_INSTANCE_HELP_STR
8ad7271d 8904 "Clear bestpath and re-advertise\n"
0c7b1b01 8905 "IPv4 prefix\n")
8ad7271d 8906{
d62a17ae 8907 char *vrf = NULL;
8908 char *prefix = NULL;
8ad7271d 8909
d62a17ae 8910 int idx = 0;
01080f7c 8911
d62a17ae 8912 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
8913 if (argv_find(argv, argc, "vrf", &idx)) {
8914 vrf = argv[idx + 1]->arg;
8915 idx += 2;
8916 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8917 vrf = NULL;
8918 } else if (argv_find(argv, argc, "view", &idx)) {
8919 /* [<view> VIEWVRFNAME] */
8920 vrf = argv[idx + 1]->arg;
8921 idx += 2;
8922 }
0c7b1b01 8923
d62a17ae 8924 prefix = argv[argc - 1]->arg;
8ad7271d 8925
d62a17ae 8926 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 8927}
8ad7271d 8928
b09b5ae0
DW
8929DEFUN (clear_bgp_ipv6_safi_prefix,
8930 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 8931 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8932 CLEAR_STR
3a2d747c 8933 IP_STR
718e3744 8934 BGP_STR
8c3deaae 8935 "Address Family\n"
46f296b4 8936 BGP_SAFI_HELP_STR
b09b5ae0 8937 "Clear bestpath and re-advertise\n"
0c7b1b01 8938 "IPv6 prefix\n")
718e3744 8939{
9b475e76
PG
8940 int idx_safi = 0;
8941 int idx_ipv6_prefix = 0;
8942 safi_t safi = SAFI_UNICAST;
8943 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8944 argv[idx_ipv6_prefix]->arg : NULL;
8945
8946 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 8947 return bgp_clear_prefix(
9b475e76
PG
8948 vty, NULL, prefix, AFI_IP6,
8949 safi, NULL);
838758ac 8950}
01080f7c 8951
b09b5ae0
DW
8952DEFUN (clear_bgp_instance_ipv6_safi_prefix,
8953 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 8954 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 8955 CLEAR_STR
3a2d747c 8956 IP_STR
718e3744 8957 BGP_STR
838758ac 8958 BGP_INSTANCE_HELP_STR
8c3deaae 8959 "Address Family\n"
46f296b4 8960 BGP_SAFI_HELP_STR
b09b5ae0 8961 "Clear bestpath and re-advertise\n"
0c7b1b01 8962 "IPv6 prefix\n")
718e3744 8963{
9b475e76 8964 int idx_safi = 0;
9a8bdf1c 8965 int idx_vrfview = 0;
9b475e76
PG
8966 int idx_ipv6_prefix = 0;
8967 safi_t safi = SAFI_UNICAST;
8968 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
8969 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 8970 char *vrfview = NULL;
9b475e76 8971
9a8bdf1c
PG
8972 /* [<view|vrf> VIEWVRFNAME] */
8973 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
8974 vrfview = argv[idx_vrfview + 1]->arg;
8975 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
8976 vrfview = NULL;
8977 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
8978 /* [<view> VIEWVRFNAME] */
8979 vrfview = argv[idx_vrfview + 1]->arg;
8980 }
9b475e76
PG
8981 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
8982
d62a17ae 8983 return bgp_clear_prefix(
9b475e76
PG
8984 vty, vrfview, prefix,
8985 AFI_IP6, safi, NULL);
718e3744 8986}
8987
b09b5ae0
DW
8988DEFUN (show_bgp_views,
8989 show_bgp_views_cmd,
d6e3c605 8990 "show [ip] bgp views",
b09b5ae0 8991 SHOW_STR
d6e3c605 8992 IP_STR
01080f7c 8993 BGP_STR
b09b5ae0 8994 "Show the defined BGP views\n")
01080f7c 8995{
d62a17ae 8996 struct list *inst = bm->bgp;
8997 struct listnode *node;
8998 struct bgp *bgp;
01080f7c 8999
d62a17ae 9000 vty_out(vty, "Defined BGP views:\n");
9001 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9002 /* Skip VRFs. */
9003 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
9004 continue;
9005 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
9006 bgp->as);
9007 }
e52702f2 9008
d62a17ae 9009 return CMD_SUCCESS;
e0081f70
ML
9010}
9011
8386ac43 9012DEFUN (show_bgp_vrfs,
9013 show_bgp_vrfs_cmd,
d6e3c605 9014 "show [ip] bgp vrfs [json]",
8386ac43 9015 SHOW_STR
d6e3c605 9016 IP_STR
8386ac43 9017 BGP_STR
9018 "Show BGP VRFs\n"
9973d184 9019 JSON_STR)
8386ac43 9020{
fe1dc5a3 9021 char buf[ETHER_ADDR_STRLEN];
d62a17ae 9022 struct list *inst = bm->bgp;
9023 struct listnode *node;
9024 struct bgp *bgp;
9f049418 9025 bool uj = use_json(argc, argv);
d62a17ae 9026 json_object *json = NULL;
9027 json_object *json_vrfs = NULL;
9028 int count = 0;
d62a17ae 9029
d62a17ae 9030 if (uj) {
9031 json = json_object_new_object();
9032 json_vrfs = json_object_new_object();
9033 }
9034
9035 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
9036 const char *name, *type;
9037 struct peer *peer;
7fe96307 9038 struct listnode *node2, *nnode2;
d62a17ae 9039 int peers_cfg, peers_estb;
9040 json_object *json_vrf = NULL;
d62a17ae 9041
9042 /* Skip Views. */
9043 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
9044 continue;
9045
9046 count++;
efb4077a 9047 if (!uj && count == 1) {
fe1dc5a3 9048 vty_out(vty,
efb4077a 9049 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 9050 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
9051 "#PeersEstb", "Name");
9052 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
9053 "L3-VNI", "RouterMAC", "Interface");
9054 }
d62a17ae 9055
9056 peers_cfg = peers_estb = 0;
9057 if (uj)
9058 json_vrf = json_object_new_object();
9059
9060
7fe96307 9061 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 9062 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9063 continue;
9064 peers_cfg++;
9065 if (peer->status == Established)
9066 peers_estb++;
9067 }
9068
9069 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 9070 name = VRF_DEFAULT_NAME;
d62a17ae 9071 type = "DFLT";
9072 } else {
9073 name = bgp->name;
9074 type = "VRF";
9075 }
9076
a8bf7d9c 9077
d62a17ae 9078 if (uj) {
a4d82a8a
PZ
9079 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9080 ? -1
9081 : (int64_t)bgp->vrf_id;
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",
9085 inet_ntoa(bgp->router_id));
9086 json_object_int_add(json_vrf, "numConfiguredPeers",
9087 peers_cfg);
9088 json_object_int_add(json_vrf, "numEstablishedPeers",
9089 peers_estb);
9090
fe1dc5a3 9091 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
9092 json_object_string_add(
9093 json_vrf, "rmac",
9094 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
9095 json_object_string_add(json_vrf, "interface",
9096 ifindex2ifname(bgp->l3vni_svi_ifindex,
9097 bgp->vrf_id));
d62a17ae 9098 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 9099 } else {
fe1dc5a3 9100 vty_out(vty,
efb4077a 9101 "%4s %-5d %-16s %-9u %-10u %-37s\n",
a4d82a8a
PZ
9102 type,
9103 bgp->vrf_id == VRF_UNKNOWN ? -1
9104 : (int)bgp->vrf_id,
9105 inet_ntoa(bgp->router_id), peers_cfg,
efb4077a
CS
9106 peers_estb, name);
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
60466a63 9151 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
9152 tip->refcnt);
9153}
9154
9155static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
9156{
9157 vty_out(vty, "self nexthop database:\n");
af97a18b 9158 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
9159
9160 vty_out(vty, "Tunnel-ip database:\n");
9161 hash_iterate(bgp->tip_hash,
e3b78da8 9162 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
9163 vty);
9164}
9165
15c81ca4
DS
9166DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
9167 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
9168 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
9169 "martian next-hops\n"
9170 "martian next-hop database\n")
acf71666 9171{
0291c246 9172 struct bgp *bgp = NULL;
15c81ca4 9173 int idx = 0;
9a8bdf1c
PG
9174 char *name = NULL;
9175
9176 /* [<vrf> VIEWVRFNAME] */
9177 if (argv_find(argv, argc, "vrf", &idx)) {
9178 name = argv[idx + 1]->arg;
9179 if (name && strmatch(name, VRF_DEFAULT_NAME))
9180 name = NULL;
9181 } else if (argv_find(argv, argc, "view", &idx))
9182 /* [<view> VIEWVRFNAME] */
9183 name = argv[idx + 1]->arg;
9184 if (name)
9185 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
9186 else
9187 bgp = bgp_get_default();
acf71666 9188
acf71666
MK
9189 if (!bgp) {
9190 vty_out(vty, "%% No BGP process is configured\n");
9191 return CMD_WARNING;
9192 }
9193 bgp_show_martian_nexthops(vty, bgp);
9194
9195 return CMD_SUCCESS;
9196}
9197
f412b39a 9198DEFUN (show_bgp_memory,
4bf6a362 9199 show_bgp_memory_cmd,
7fa12b13 9200 "show [ip] bgp memory",
4bf6a362 9201 SHOW_STR
3a2d747c 9202 IP_STR
4bf6a362
PJ
9203 BGP_STR
9204 "Global BGP memory statistics\n")
9205{
d62a17ae 9206 char memstrbuf[MTYPE_MEMSTR_LEN];
9207 unsigned long count;
9208
9209 /* RIB related usage stats */
9210 count = mtype_stats_alloc(MTYPE_BGP_NODE);
9211 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
9212 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 9213 count * sizeof(struct bgp_dest)));
d62a17ae 9214
9215 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
9216 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
9217 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 9218 count * sizeof(struct bgp_path_info)));
d62a17ae 9219 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
9220 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
9221 count,
4b7e6066
DS
9222 mtype_memstr(
9223 memstrbuf, sizeof(memstrbuf),
9224 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 9225
9226 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
9227 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
9228 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9229 count * sizeof(struct bgp_static)));
9230
9231 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
9232 vty_out(vty, "%ld Packets, using %s of memory\n", count,
9233 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9234 count * sizeof(struct bpacket)));
9235
9236 /* Adj-In/Out */
9237 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
9238 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
9239 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9240 count * sizeof(struct bgp_adj_in)));
9241 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
9242 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
9243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9244 count * sizeof(struct bgp_adj_out)));
9245
9246 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
9247 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
9248 count,
9249 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9250 count * sizeof(struct bgp_nexthop_cache)));
9251
9252 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
9253 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
9254 count,
9255 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9256 count * sizeof(struct bgp_damp_info)));
9257
9258 /* Attributes */
9259 count = attr_count();
9260 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
9261 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9262 count * sizeof(struct attr)));
9263
9264 if ((count = attr_unknown_count()))
9265 vty_out(vty, "%ld unknown attributes\n", count);
9266
9267 /* AS_PATH attributes */
9268 count = aspath_count();
9269 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
9270 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9271 count * sizeof(struct aspath)));
9272
9273 count = mtype_stats_alloc(MTYPE_AS_SEG);
9274 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
9275 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9276 count * sizeof(struct assegment)));
9277
9278 /* Other attributes */
9279 if ((count = community_count()))
9280 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9281 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9282 count * sizeof(struct community)));
d62a17ae 9283 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
9284 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
9285 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9286 count * sizeof(struct ecommunity)));
d62a17ae 9287 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
9288 vty_out(vty,
9289 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
9290 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9291 count * sizeof(struct lcommunity)));
d62a17ae 9292
9293 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
9294 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
9295 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9296 count * sizeof(struct cluster_list)));
9297
9298 /* Peer related usage */
9299 count = mtype_stats_alloc(MTYPE_BGP_PEER);
9300 vty_out(vty, "%ld peers, using %s of memory\n", count,
9301 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9302 count * sizeof(struct peer)));
9303
9304 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
9305 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
9306 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9307 count * sizeof(struct peer_group)));
9308
9309 /* Other */
d62a17ae 9310 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
9311 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
9312 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
9313 count * sizeof(regex_t)));
d62a17ae 9314 return CMD_SUCCESS;
4bf6a362 9315}
fee0f4c6 9316
57a9c8a8
DS
9317static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
9318{
9319 json_object *bestpath = json_object_new_object();
9320
892fedb6 9321 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
9322 json_object_string_add(bestpath, "asPath", "ignore");
9323
892fedb6 9324 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
9325 json_object_string_add(bestpath, "asPath", "confed");
9326
892fedb6
DA
9327 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
9328 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 9329 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9330 "as-set");
9331 else
a4d82a8a 9332 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
9333 "true");
9334 } else
a4d82a8a 9335 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 9336
892fedb6 9337 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 9338 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
9339 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
9340 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
9341 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 9342 json_object_string_add(bestpath, "med", "confed");
892fedb6 9343 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
9344 json_object_string_add(bestpath, "med",
9345 "missing-as-worst");
9346 else
9347 json_object_string_add(bestpath, "med", "true");
9348 }
9349
9350 json_object_object_add(json, "bestPath", bestpath);
9351}
9352
3577f1c5
DD
9353/* Print the error code/subcode for why the peer is down */
9354static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
9355 json_object *json_peer, bool use_json)
9356{
9357 const char *code_str;
9358 const char *subcode_str;
9359
9360 if (use_json) {
9361 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9362 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9363 char errorcodesubcode_hexstr[5];
9364 char errorcodesubcode_str[256];
9365
9366 code_str = bgp_notify_code_str(peer->notify.code);
9367 subcode_str = bgp_notify_subcode_str(
9368 peer->notify.code,
9369 peer->notify.subcode);
9370
772270f3
QY
9371 snprintf(errorcodesubcode_hexstr,
9372 sizeof(errorcodesubcode_hexstr), "%02X%02X",
9373 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
9374 json_object_string_add(json_peer,
9375 "lastErrorCodeSubcode",
9376 errorcodesubcode_hexstr);
9377 snprintf(errorcodesubcode_str, 255, "%s%s",
9378 code_str, subcode_str);
9379 json_object_string_add(json_peer,
9380 "lastNotificationReason",
9381 errorcodesubcode_str);
9382 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9383 && peer->notify.code == BGP_NOTIFY_CEASE
9384 && (peer->notify.subcode
9385 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9386 || peer->notify.subcode
9387 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9388 && peer->notify.length) {
9389 char msgbuf[1024];
9390 const char *msg_str;
9391
9392 msg_str = bgp_notify_admin_message(
9393 msgbuf, sizeof(msgbuf),
9394 (uint8_t *)peer->notify.data,
9395 peer->notify.length);
9396 if (msg_str)
9397 json_object_string_add(
9398 json_peer,
9399 "lastShutdownDescription",
9400 msg_str);
9401 }
9402
c258527b 9403 }
3577f1c5
DD
9404 json_object_string_add(json_peer, "lastResetDueTo",
9405 peer_down_str[(int)peer->last_reset]);
05912a17
DD
9406 json_object_int_add(json_peer, "lastResetCode",
9407 peer->last_reset);
3577f1c5
DD
9408 } else {
9409 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
9410 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9411 code_str = bgp_notify_code_str(peer->notify.code);
9412 subcode_str =
9413 bgp_notify_subcode_str(peer->notify.code,
9414 peer->notify.subcode);
9415 vty_out(vty, " Notification %s (%s%s)\n",
9416 peer->last_reset == PEER_DOWN_NOTIFY_SEND
9417 ? "sent"
9418 : "received",
9419 code_str, subcode_str);
9420 } else {
e91c24c8 9421 vty_out(vty, " %s\n",
3577f1c5
DD
9422 peer_down_str[(int)peer->last_reset]);
9423 }
9424 }
9425}
9426
9427static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
9428 safi_t safi)
9429{
9430 return ((peer->status != Established) ||
9431 !peer->afc_recv[afi][safi]);
9432}
9433
9434static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
9435 struct peer *peer, json_object *json_peer,
9436 int max_neighbor_width, bool use_json)
9437{
9438 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9439 int len;
9440
9441 if (use_json) {
9442 if (peer_dynamic_neighbor(peer))
9443 json_object_boolean_true_add(json_peer,
9444 "dynamicPeer");
9445 if (peer->hostname)
9446 json_object_string_add(json_peer, "hostname",
9447 peer->hostname);
9448
9449 if (peer->domainname)
9450 json_object_string_add(json_peer, "domainname",
9451 peer->domainname);
9452 json_object_int_add(json_peer, "connectionsEstablished",
9453 peer->established);
9454 json_object_int_add(json_peer, "connectionsDropped",
9455 peer->dropped);
9456 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9457 use_json, json_peer);
9458 if (peer->status == Established)
9459 json_object_string_add(json_peer, "lastResetDueTo",
9460 "AFI/SAFI Not Negotiated");
9461 else
9462 bgp_show_peer_reset(NULL, peer, json_peer, true);
9463 } else {
9464 dn_flag[1] = '\0';
9465 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
9466 if (peer->hostname
892fedb6 9467 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
9468 len = vty_out(vty, "%s%s(%s)", dn_flag,
9469 peer->hostname, peer->host);
9470 else
9471 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9472
9473 /* pad the neighbor column with spaces */
9474 if (len < max_neighbor_width)
9475 vty_out(vty, "%*s", max_neighbor_width - len,
9476 " ");
e91c24c8 9477 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
9478 peer->dropped,
9479 peer_uptime(peer->uptime, timebuf,
9480 BGP_UPTIME_LEN, 0, NULL));
9481 if (peer->status == Established)
9482 vty_out(vty, " AFI/SAFI Not Negotiated\n");
9483 else
9484 bgp_show_peer_reset(vty, peer, NULL,
9485 false);
9486 }
9487}
c258527b 9488
3577f1c5 9489
718e3744 9490/* Show BGP peer's summary information. */
d62a17ae 9491static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10b49f14
DA
9492 bool show_failed, bool show_established,
9493 bool use_json)
d62a17ae 9494{
9495 struct peer *peer;
9496 struct listnode *node, *nnode;
9497 unsigned int count = 0, dn_count = 0;
9498 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
9499 char neighbor_buf[VTY_BUFSIZ];
9500 int neighbor_col_default_width = 16;
3577f1c5 9501 int len, failed_count = 0;
d62a17ae 9502 int max_neighbor_width = 0;
9503 int pfx_rcd_safi;
3c13337d 9504 json_object *json = NULL;
d62a17ae 9505 json_object *json_peer = NULL;
9506 json_object *json_peers = NULL;
50e05855 9507 struct peer_af *paf;
d3ada366 9508 struct bgp_filter *filter;
d62a17ae 9509
9510 /* labeled-unicast routes are installed in the unicast table so in order
9511 * to
9512 * display the correct PfxRcd value we must look at SAFI_UNICAST
9513 */
3577f1c5 9514
d62a17ae 9515 if (safi == SAFI_LABELED_UNICAST)
9516 pfx_rcd_safi = SAFI_UNICAST;
9517 else
9518 pfx_rcd_safi = safi;
9519
9520 if (use_json) {
3c13337d 9521 json = json_object_new_object();
d62a17ae 9522 json_peers = json_object_new_object();
3577f1c5
DD
9523 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9524 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9525 continue;
9526
9527 if (peer->afc[afi][safi]) {
9528 /* See if we have at least a single failed peer */
9529 if (bgp_has_peer_failed(peer, afi, safi))
9530 failed_count++;
9531 count++;
9532 }
9533 if (peer_dynamic_neighbor(peer))
9534 dn_count++;
9535 }
c258527b 9536
d62a17ae 9537 } else {
9538 /* Loop over all neighbors that will be displayed to determine
9539 * how many
9540 * characters are needed for the Neighbor column
9541 */
9542 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9543 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9544 continue;
9545
9546 if (peer->afc[afi][safi]) {
9547 memset(dn_flag, '\0', sizeof(dn_flag));
9548 if (peer_dynamic_neighbor(peer))
9549 dn_flag[0] = '*';
9550
9551 if (peer->hostname
892fedb6
DA
9552 && CHECK_FLAG(bgp->flags,
9553 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
9554 snprintf(neighbor_buf,
9555 sizeof(neighbor_buf),
9556 "%s%s(%s) ", dn_flag,
9557 peer->hostname, peer->host);
d62a17ae 9558 else
772270f3
QY
9559 snprintf(neighbor_buf,
9560 sizeof(neighbor_buf), "%s%s ",
9561 dn_flag, peer->host);
d62a17ae 9562
9563 len = strlen(neighbor_buf);
9564
9565 if (len > max_neighbor_width)
9566 max_neighbor_width = len;
c258527b 9567
3577f1c5
DD
9568 /* See if we have at least a single failed peer */
9569 if (bgp_has_peer_failed(peer, afi, safi))
9570 failed_count++;
9571 count++;
d62a17ae 9572 }
9573 }
f933309e 9574
d62a17ae 9575 /* Originally we displayed the Neighbor column as 16
9576 * characters wide so make that the default
9577 */
9578 if (max_neighbor_width < neighbor_col_default_width)
9579 max_neighbor_width = neighbor_col_default_width;
9580 }
f933309e 9581
3577f1c5
DD
9582 if (show_failed && !failed_count) {
9583 if (use_json) {
9584 json_object_int_add(json, "failedPeersCount", 0);
9585 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 9586 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
9587
9588 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9589 json, JSON_C_TO_STRING_PRETTY));
9590 json_object_free(json);
9591 } else {
9592 vty_out(vty, "%% No failed BGP neighbors found\n");
9593 vty_out(vty, "\nTotal number of neighbors %d\n", count);
9594 }
9595 return CMD_SUCCESS;
9596 }
c258527b 9597
3577f1c5 9598 count = 0; /* Reset the value as its used again */
d62a17ae 9599 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9600 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9601 continue;
9602
ea47320b
DL
9603 if (!peer->afc[afi][safi])
9604 continue;
d62a17ae 9605
ea47320b
DL
9606 if (!count) {
9607 unsigned long ents;
9608 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 9609 int64_t vrf_id_ui;
d62a17ae 9610
a4d82a8a
PZ
9611 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
9612 ? -1
9613 : (int64_t)bgp->vrf_id;
ea47320b
DL
9614
9615 /* Usage summary and header */
9616 if (use_json) {
9617 json_object_string_add(
9618 json, "routerId",
9619 inet_ntoa(bgp->router_id));
60466a63
QY
9620 json_object_int_add(json, "as", bgp->as);
9621 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
9622 json_object_string_add(
9623 json, "vrfName",
9624 (bgp->inst_type
9625 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 9626 ? VRF_DEFAULT_NAME
ea47320b
DL
9627 : bgp->name);
9628 } else {
9629 vty_out(vty,
9630 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 9631 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
9632 bgp->vrf_id == VRF_UNKNOWN
9633 ? -1
9634 : (int)bgp->vrf_id);
ea47320b
DL
9635 vty_out(vty, "\n");
9636 }
d62a17ae 9637
ea47320b 9638 if (bgp_update_delay_configured(bgp)) {
d62a17ae 9639 if (use_json) {
ea47320b 9640 json_object_int_add(
60466a63 9641 json, "updateDelayLimit",
ea47320b 9642 bgp->v_update_delay);
d62a17ae 9643
ea47320b
DL
9644 if (bgp->v_update_delay
9645 != bgp->v_establish_wait)
d62a17ae 9646 json_object_int_add(
9647 json,
ea47320b
DL
9648 "updateDelayEstablishWait",
9649 bgp->v_establish_wait);
d62a17ae 9650
60466a63 9651 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9652 json_object_string_add(
9653 json,
9654 "updateDelayFirstNeighbor",
9655 bgp->update_delay_begin_time);
9656 json_object_boolean_true_add(
9657 json,
9658 "updateDelayInProgress");
9659 } else {
9660 if (bgp->update_delay_over) {
d62a17ae 9661 json_object_string_add(
9662 json,
9663 "updateDelayFirstNeighbor",
9664 bgp->update_delay_begin_time);
ea47320b 9665 json_object_string_add(
d62a17ae 9666 json,
ea47320b
DL
9667 "updateDelayBestpathResumed",
9668 bgp->update_delay_end_time);
9669 json_object_string_add(
d62a17ae 9670 json,
ea47320b
DL
9671 "updateDelayZebraUpdateResume",
9672 bgp->update_delay_zebra_resume_time);
9673 json_object_string_add(
9674 json,
9675 "updateDelayPeerUpdateResume",
9676 bgp->update_delay_peers_resume_time);
d62a17ae 9677 }
ea47320b
DL
9678 }
9679 } else {
9680 vty_out(vty,
9681 "Read-only mode update-delay limit: %d seconds\n",
9682 bgp->v_update_delay);
9683 if (bgp->v_update_delay
9684 != bgp->v_establish_wait)
d62a17ae 9685 vty_out(vty,
ea47320b
DL
9686 " Establish wait: %d seconds\n",
9687 bgp->v_establish_wait);
d62a17ae 9688
60466a63 9689 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
9690 vty_out(vty,
9691 " First neighbor established: %s\n",
9692 bgp->update_delay_begin_time);
9693 vty_out(vty,
9694 " Delay in progress\n");
9695 } else {
9696 if (bgp->update_delay_over) {
d62a17ae 9697 vty_out(vty,
9698 " First neighbor established: %s\n",
9699 bgp->update_delay_begin_time);
9700 vty_out(vty,
ea47320b
DL
9701 " Best-paths resumed: %s\n",
9702 bgp->update_delay_end_time);
9703 vty_out(vty,
9704 " zebra update resumed: %s\n",
9705 bgp->update_delay_zebra_resume_time);
9706 vty_out(vty,
9707 " peers update resumed: %s\n",
9708 bgp->update_delay_peers_resume_time);
d62a17ae 9709 }
9710 }
9711 }
ea47320b 9712 }
d62a17ae 9713
ea47320b
DL
9714 if (use_json) {
9715 if (bgp_maxmed_onstartup_configured(bgp)
9716 && bgp->maxmed_active)
9717 json_object_boolean_true_add(
60466a63 9718 json, "maxMedOnStartup");
ea47320b
DL
9719 if (bgp->v_maxmed_admin)
9720 json_object_boolean_true_add(
60466a63 9721 json, "maxMedAdministrative");
d62a17ae 9722
ea47320b
DL
9723 json_object_int_add(
9724 json, "tableVersion",
60466a63 9725 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 9726
60466a63
QY
9727 ents = bgp_table_count(bgp->rib[afi][safi]);
9728 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
9729 json_object_int_add(
9730 json, "ribMemory",
9bcb3eef 9731 ents * sizeof(struct bgp_dest));
d62a17ae 9732
210ec2a0 9733 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
9734 json_object_int_add(json, "peerCount", ents);
9735 json_object_int_add(json, "peerMemory",
9736 ents * sizeof(struct peer));
d62a17ae 9737
ea47320b
DL
9738 if ((ents = listcount(bgp->group))) {
9739 json_object_int_add(
60466a63 9740 json, "peerGroupCount", ents);
ea47320b
DL
9741 json_object_int_add(
9742 json, "peerGroupMemory",
996c9314
LB
9743 ents * sizeof(struct
9744 peer_group));
ea47320b 9745 }
d62a17ae 9746
ea47320b
DL
9747 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9748 BGP_CONFIG_DAMPENING))
9749 json_object_boolean_true_add(
60466a63 9750 json, "dampeningEnabled");
ea47320b
DL
9751 } else {
9752 if (bgp_maxmed_onstartup_configured(bgp)
9753 && bgp->maxmed_active)
d62a17ae 9754 vty_out(vty,
ea47320b
DL
9755 "Max-med on-startup active\n");
9756 if (bgp->v_maxmed_admin)
d62a17ae 9757 vty_out(vty,
ea47320b 9758 "Max-med administrative active\n");
d62a17ae 9759
60466a63
QY
9760 vty_out(vty, "BGP table version %" PRIu64 "\n",
9761 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 9762
60466a63 9763 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
9764 vty_out(vty,
9765 "RIB entries %ld, using %s of memory\n",
9766 ents,
9bcb3eef
DS
9767 mtype_memstr(
9768 memstrbuf, sizeof(memstrbuf),
9769 ents
9770 * sizeof(struct
9771 bgp_dest)));
ea47320b
DL
9772
9773 /* Peer related usage */
210ec2a0 9774 ents = bgp->af_peer_count[afi][safi];
60466a63 9775 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
9776 ents,
9777 mtype_memstr(
60466a63
QY
9778 memstrbuf, sizeof(memstrbuf),
9779 ents * sizeof(struct peer)));
ea47320b
DL
9780
9781 if ((ents = listcount(bgp->group)))
d62a17ae 9782 vty_out(vty,
ea47320b 9783 "Peer groups %ld, using %s of memory\n",
d62a17ae 9784 ents,
9785 mtype_memstr(
9786 memstrbuf,
9787 sizeof(memstrbuf),
996c9314
LB
9788 ents * sizeof(struct
9789 peer_group)));
d62a17ae 9790
ea47320b
DL
9791 if (CHECK_FLAG(bgp->af_flags[afi][safi],
9792 BGP_CONFIG_DAMPENING))
60466a63 9793 vty_out(vty, "Dampening enabled.\n");
ea47320b 9794 vty_out(vty, "\n");
d62a17ae 9795
ea47320b
DL
9796 /* Subtract 8 here because 'Neighbor' is
9797 * 8 characters */
9798 vty_out(vty, "Neighbor");
60466a63
QY
9799 vty_out(vty, "%*s", max_neighbor_width - 8,
9800 " ");
3577f1c5
DD
9801 if (show_failed)
9802 vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n");
9803 else
9804 vty_out(vty,
db92d226 9805 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt\n");
d62a17ae 9806 }
ea47320b 9807 }
d62a17ae 9808
d55811cc 9809 paf = peer_af_find(peer, afi, safi);
d3ada366 9810 filter = &peer->filter[afi][safi];
db92d226 9811
ea47320b 9812 count++;
3577f1c5
DD
9813 /* Works for both failed & successful cases */
9814 if (peer_dynamic_neighbor(peer))
9815 dn_count++;
d62a17ae 9816
ea47320b 9817 if (use_json) {
3577f1c5
DD
9818 json_peer = NULL;
9819
9820 if (show_failed &&
9821 bgp_has_peer_failed(peer, afi, safi)) {
9822 json_peer = json_object_new_object();
9823 bgp_show_failed_summary(vty, bgp, peer,
9824 json_peer, 0, use_json);
9825 } else if (!show_failed) {
10b49f14
DA
9826 if (show_established
9827 && bgp_has_peer_failed(peer, afi, safi))
9828 continue;
9829
3577f1c5
DD
9830 json_peer = json_object_new_object();
9831 if (peer_dynamic_neighbor(peer)) {
9832 json_object_boolean_true_add(json_peer,
9833 "dynamicPeer");
9834 }
d62a17ae 9835
3577f1c5
DD
9836 if (peer->hostname)
9837 json_object_string_add(json_peer, "hostname",
9838 peer->hostname);
9839
9840 if (peer->domainname)
9841 json_object_string_add(json_peer, "domainname",
9842 peer->domainname);
9843
9844 json_object_int_add(json_peer, "remoteAs", peer->as);
9845 json_object_int_add(json_peer, "version", 4);
9846 json_object_int_add(json_peer, "msgRcvd",
9847 PEER_TOTAL_RX(peer));
9848 json_object_int_add(json_peer, "msgSent",
9849 PEER_TOTAL_TX(peer));
9850
43aa5965
QY
9851 atomic_size_t outq_count, inq_count;
9852 outq_count = atomic_load_explicit(
9853 &peer->obuf->count,
9854 memory_order_relaxed);
9855 inq_count = atomic_load_explicit(
9856 &peer->ibuf->count,
9857 memory_order_relaxed);
9858
3577f1c5
DD
9859 json_object_int_add(json_peer, "tableVersion",
9860 peer->version[afi][safi]);
9861 json_object_int_add(json_peer, "outq",
43aa5965
QY
9862 outq_count);
9863 json_object_int_add(json_peer, "inq",
9864 inq_count);
3577f1c5
DD
9865 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
9866 use_json, json_peer);
9867
3577f1c5
DD
9868 json_object_int_add(json_peer, "pfxRcd",
9869 peer->pcount[afi][pfx_rcd_safi]);
9870
3577f1c5
DD
9871 if (paf && PAF_SUBGRP(paf))
9872 json_object_int_add(json_peer,
9873 "pfxSnt",
9874 (PAF_SUBGRP(paf))->scount);
cb9196e7 9875 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
9876 || CHECK_FLAG(peer->bgp->flags,
9877 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
9878 json_object_string_add(json_peer, "state",
9879 "Idle (Admin)");
9880 else if (peer->afc_recv[afi][safi])
9881 json_object_string_add(
9882 json_peer, "state",
9883 lookup_msg(bgp_status_msg, peer->status,
9884 NULL));
9885 else if (CHECK_FLAG(peer->sflags,
9886 PEER_STATUS_PREFIX_OVERFLOW))
9887 json_object_string_add(json_peer, "state",
9888 "Idle (PfxCt)");
9889 else
9890 json_object_string_add(
9891 json_peer, "state",
9892 lookup_msg(bgp_status_msg, peer->status,
9893 NULL));
200116db
DD
9894 json_object_int_add(json_peer, "connectionsEstablished",
9895 peer->established);
9896 json_object_int_add(json_peer, "connectionsDropped",
9897 peer->dropped);
b4e9dcba 9898 }
3577f1c5
DD
9899 /* Avoid creating empty peer dicts in JSON */
9900 if (json_peer == NULL)
9901 continue;
ea47320b
DL
9902
9903 if (peer->conf_if)
60466a63 9904 json_object_string_add(json_peer, "idType",
ea47320b
DL
9905 "interface");
9906 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
9907 json_object_string_add(json_peer, "idType",
9908 "ipv4");
ea47320b 9909 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
9910 json_object_string_add(json_peer, "idType",
9911 "ipv6");
ea47320b
DL
9912 json_object_object_add(json_peers, peer->host,
9913 json_peer);
9914 } else {
3577f1c5
DD
9915 if (show_failed &&
9916 bgp_has_peer_failed(peer, afi, safi)) {
9917 bgp_show_failed_summary(vty, bgp, peer, NULL,
9918 max_neighbor_width,
9919 use_json);
9920 } else if (!show_failed) {
10b49f14
DA
9921 if (show_established
9922 && bgp_has_peer_failed(peer, afi, safi))
9923 continue;
9924
3577f1c5
DD
9925 memset(dn_flag, '\0', sizeof(dn_flag));
9926 if (peer_dynamic_neighbor(peer)) {
9927 dn_flag[0] = '*';
9928 }
d62a17ae 9929
3577f1c5 9930 if (peer->hostname
892fedb6
DA
9931 && CHECK_FLAG(bgp->flags,
9932 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 9933 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
9934 peer->hostname,
9935 peer->host);
d62a17ae 9936 else
3577f1c5
DD
9937 len = vty_out(vty, "%s%s", dn_flag, peer->host);
9938
9939 /* pad the neighbor column with spaces */
9940 if (len < max_neighbor_width)
9941 vty_out(vty, "%*s", max_neighbor_width - len,
9942 " ");
9943
43aa5965
QY
9944 atomic_size_t outq_count, inq_count;
9945 outq_count = atomic_load_explicit(
9946 &peer->obuf->count,
9947 memory_order_relaxed);
9948 inq_count = atomic_load_explicit(
9949 &peer->ibuf->count,
9950 memory_order_relaxed);
9951
566bdaf6 9952 vty_out(vty,
6cde4b45 9953 "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s",
3577f1c5 9954 peer->as, PEER_TOTAL_RX(peer),
566bdaf6 9955 PEER_TOTAL_TX(peer),
43aa5965
QY
9956 peer->version[afi][safi], inq_count,
9957 outq_count,
3577f1c5
DD
9958 peer_uptime(peer->uptime, timebuf,
9959 BGP_UPTIME_LEN, 0, NULL));
9960
db92d226 9961 if (peer->status == Established) {
d3ada366
DA
9962 if (peer->afc_recv[afi][safi]) {
9963 if (CHECK_FLAG(
9964 bgp->flags,
9965 BGP_FLAG_EBGP_REQUIRES_POLICY)
9966 && !bgp_inbound_policy_exists(
9967 peer, filter))
9968 vty_out(vty, " %12s",
9969 "(Policy)");
9970 else
9971 vty_out(vty,
6cde4b45 9972 " %12u",
d3ada366
DA
9973 peer->pcount
9974 [afi]
9975 [pfx_rcd_safi]);
9976 } else {
3577f1c5 9977 vty_out(vty, " NoNeg");
d3ada366 9978 }
db92d226 9979
d3ada366
DA
9980 if (paf && PAF_SUBGRP(paf)) {
9981 if (CHECK_FLAG(
9982 bgp->flags,
9983 BGP_FLAG_EBGP_REQUIRES_POLICY)
9984 && !bgp_outbound_policy_exists(
9985 peer, filter))
9986 vty_out(vty, " %8s",
9987 "(Policy)");
9988 else
9989 vty_out(vty,
6cde4b45 9990 " %8u",
d3ada366
DA
9991 (PAF_SUBGRP(
9992 paf))
9993 ->scount);
9994 }
db92d226 9995 } else {
736b68f3
DS
9996 if (CHECK_FLAG(peer->flags,
9997 PEER_FLAG_SHUTDOWN)
9998 || CHECK_FLAG(peer->bgp->flags,
9999 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
10000 vty_out(vty, " Idle (Admin)");
10001 else if (CHECK_FLAG(
10002 peer->sflags,
10003 PEER_STATUS_PREFIX_OVERFLOW))
10004 vty_out(vty, " Idle (PfxCt)");
10005 else
10006 vty_out(vty, " %12s",
10007 lookup_msg(bgp_status_msg,
10008 peer->status, NULL));
db92d226 10009
6cde4b45 10010 vty_out(vty, " %8u", 0);
3577f1c5
DD
10011 }
10012 vty_out(vty, "\n");
d62a17ae 10013 }
3577f1c5 10014
d62a17ae 10015 }
10016 }
f933309e 10017
d62a17ae 10018 if (use_json) {
10019 json_object_object_add(json, "peers", json_peers);
3577f1c5 10020 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 10021 json_object_int_add(json, "totalPeers", count);
10022 json_object_int_add(json, "dynamicPeers", dn_count);
10023
3577f1c5
DD
10024 if (!show_failed)
10025 bgp_show_bestpath_json(bgp, json);
57a9c8a8 10026
996c9314
LB
10027 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10028 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10029 json_object_free(json);
10030 } else {
10031 if (count)
10032 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10033 else {
d6ceaca3 10034 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 10035 get_afi_safi_str(afi, safi, false));
d62a17ae 10036 }
b05a1c8b 10037
d6ceaca3 10038 if (dn_count) {
d62a17ae 10039 vty_out(vty, "* - dynamic neighbor\n");
10040 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
10041 dn_count, bgp->dynamic_neighbors_limit);
10042 }
10043 }
1ff9a340 10044
d62a17ae 10045 return CMD_SUCCESS;
718e3744 10046}
10047
d62a17ae 10048static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
10b49f14
DA
10049 int safi, bool show_failed,
10050 bool show_established, bool use_json)
d62a17ae 10051{
10052 int is_first = 1;
10053 int afi_wildcard = (afi == AFI_MAX);
10054 int safi_wildcard = (safi == SAFI_MAX);
10055 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 10056 bool nbr_output = false;
d62a17ae 10057
10058 if (use_json && is_wildcard)
10059 vty_out(vty, "{\n");
10060 if (afi_wildcard)
10061 afi = 1; /* AFI_IP */
10062 while (afi < AFI_MAX) {
10063 if (safi_wildcard)
10064 safi = 1; /* SAFI_UNICAST */
10065 while (safi < SAFI_MAX) {
318cac96 10066 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 10067 nbr_output = true;
f86897b9 10068
d62a17ae 10069 if (is_wildcard) {
10070 /*
10071 * So limit output to those afi/safi
10072 * pairs that
10073 * actualy have something interesting in
10074 * them
10075 */
10076 if (use_json) {
d62a17ae 10077 if (!is_first)
10078 vty_out(vty, ",\n");
10079 else
10080 is_first = 0;
10081
10082 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
10083 get_afi_safi_str(afi,
10084 safi,
10085 true));
d62a17ae 10086 } else {
10087 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
10088 get_afi_safi_str(afi,
10089 safi,
10090 false));
d62a17ae 10091 }
10092 }
10b49f14
DA
10093 bgp_show_summary(vty, bgp, afi, safi,
10094 show_failed, show_established,
3577f1c5 10095 use_json);
d62a17ae 10096 }
10097 safi++;
d62a17ae 10098 if (!safi_wildcard)
10099 safi = SAFI_MAX;
10100 }
10101 afi++;
ee851c8c 10102 if (!afi_wildcard)
d62a17ae 10103 afi = AFI_MAX;
10104 }
10105
10106 if (use_json && is_wildcard)
10107 vty_out(vty, "}\n");
ca61fd25
DS
10108 else if (!nbr_output) {
10109 if (use_json)
10110 vty_out(vty, "{}\n");
10111 else
10112 vty_out(vty, "%% No BGP neighbors found\n");
10113 }
d62a17ae 10114}
10115
10116static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
3577f1c5 10117 safi_t safi, bool show_failed,
10b49f14 10118 bool show_established,
3577f1c5 10119 bool use_json)
d62a17ae 10120{
10121 struct listnode *node, *nnode;
10122 struct bgp *bgp;
d62a17ae 10123 int is_first = 1;
9f049418 10124 bool nbr_output = false;
d62a17ae 10125
10126 if (use_json)
10127 vty_out(vty, "{\n");
10128
10129 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 10130 nbr_output = true;
d62a17ae 10131 if (use_json) {
d62a17ae 10132 if (!is_first)
10133 vty_out(vty, ",\n");
10134 else
10135 is_first = 0;
10136
10137 vty_out(vty, "\"%s\":",
10138 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10139 ? VRF_DEFAULT_NAME
d62a17ae 10140 : bgp->name);
10141 } else {
10142 vty_out(vty, "\nInstance %s:\n",
10143 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10144 ? VRF_DEFAULT_NAME
d62a17ae 10145 : bgp->name);
10146 }
3577f1c5 10147 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10148 show_established, use_json);
d62a17ae 10149 }
10150
10151 if (use_json)
10152 vty_out(vty, "}\n");
9f049418
DS
10153 else if (!nbr_output)
10154 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 10155}
10156
10157int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
10b49f14
DA
10158 safi_t safi, bool show_failed, bool show_established,
10159 bool use_json)
d62a17ae 10160{
10161 struct bgp *bgp;
10162
10163 if (name) {
10164 if (strmatch(name, "all")) {
10b49f14
DA
10165 bgp_show_all_instances_summary_vty(
10166 vty, afi, safi, show_failed, show_established,
10167 use_json);
d62a17ae 10168 return CMD_SUCCESS;
10169 } else {
10170 bgp = bgp_lookup_by_name(name);
10171
10172 if (!bgp) {
10173 if (use_json)
10174 vty_out(vty, "{}\n");
10175 else
10176 vty_out(vty,
ca61fd25 10177 "%% BGP instance not found\n");
d62a17ae 10178 return CMD_WARNING;
10179 }
10180
f86897b9 10181 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
10b49f14
DA
10182 show_failed, show_established,
10183 use_json);
d62a17ae 10184 return CMD_SUCCESS;
10185 }
10186 }
10187
10188 bgp = bgp_get_default();
10189
10190 if (bgp)
3577f1c5 10191 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
10b49f14 10192 show_established, use_json);
9f049418 10193 else {
ca61fd25
DS
10194 if (use_json)
10195 vty_out(vty, "{}\n");
10196 else
10197 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
10198 return CMD_WARNING;
10199 }
d62a17ae 10200
10201 return CMD_SUCCESS;
4fb25c53
DW
10202}
10203
716b2d8a 10204/* `show [ip] bgp summary' commands. */
96f3485c 10205DEFPY (show_ip_bgp_summary,
718e3744 10206 show_ip_bgp_summary_cmd,
96f3485c 10207 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
718e3744 10208 SHOW_STR
10209 IP_STR
10210 BGP_STR
8386ac43 10211 BGP_INSTANCE_HELP_STR
46f296b4 10212 BGP_AFI_HELP_STR
dd6bd0f1 10213 BGP_SAFI_WITH_LABEL_HELP_STR
96f3485c 10214 "Display the entries for all address families\n"
b05a1c8b 10215 "Summary of BGP neighbor status\n"
10b49f14 10216 "Show only sessions in Established state\n"
3577f1c5 10217 "Show only sessions not in Established state\n"
9973d184 10218 JSON_STR)
718e3744 10219{
d62a17ae 10220 char *vrf = NULL;
10221 afi_t afi = AFI_MAX;
10222 safi_t safi = SAFI_MAX;
3577f1c5 10223 bool show_failed = false;
10b49f14 10224 bool show_established = false;
d62a17ae 10225
10226 int idx = 0;
10227
10228 /* show [ip] bgp */
96f3485c 10229 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 10230 afi = AFI_IP;
9a8bdf1c
PG
10231 /* [<vrf> VIEWVRFNAME] */
10232 if (argv_find(argv, argc, "vrf", &idx)) {
10233 vrf = argv[idx + 1]->arg;
10234 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10235 vrf = NULL;
10236 } else if (argv_find(argv, argc, "view", &idx))
10237 /* [<view> VIEWVRFNAME] */
10238 vrf = argv[idx + 1]->arg;
d62a17ae 10239 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10240 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10241 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10242 }
10243
3577f1c5
DD
10244 if (argv_find(argv, argc, "failed", &idx))
10245 show_failed = true;
10b49f14
DA
10246 if (argv_find(argv, argc, "established", &idx))
10247 show_established = true;
3577f1c5 10248
10b49f14
DA
10249 return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
10250 show_established, uj);
d62a17ae 10251}
10252
5cb5f4d0 10253const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 10254{
5cb5f4d0
DD
10255 if (for_json)
10256 return get_afi_safi_json_str(afi, safi);
d62a17ae 10257 else
5cb5f4d0 10258 return get_afi_safi_vty_str(afi, safi);
27162734
LB
10259}
10260
d62a17ae 10261
10262static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
10263 afi_t afi, safi_t safi,
d7c0a89a
QY
10264 uint16_t adv_smcap, uint16_t adv_rmcap,
10265 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 10266 bool use_json, json_object *json_pref)
d62a17ae 10267{
10268 /* Send-Mode */
10269 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10270 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
10271 if (use_json) {
10272 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
10273 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10274 json_object_string_add(json_pref, "sendMode",
10275 "advertisedAndReceived");
10276 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10277 json_object_string_add(json_pref, "sendMode",
10278 "advertised");
10279 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10280 json_object_string_add(json_pref, "sendMode",
10281 "received");
10282 } else {
10283 vty_out(vty, " Send-mode: ");
10284 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
10285 vty_out(vty, "advertised");
10286 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
10287 vty_out(vty, "%sreceived",
10288 CHECK_FLAG(p->af_cap[afi][safi],
10289 adv_smcap)
10290 ? ", "
10291 : "");
10292 vty_out(vty, "\n");
10293 }
10294 }
10295
10296 /* Receive-Mode */
10297 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10298 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
10299 if (use_json) {
10300 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
10301 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10302 json_object_string_add(json_pref, "recvMode",
10303 "advertisedAndReceived");
10304 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10305 json_object_string_add(json_pref, "recvMode",
10306 "advertised");
10307 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10308 json_object_string_add(json_pref, "recvMode",
10309 "received");
10310 } else {
10311 vty_out(vty, " Receive-mode: ");
10312 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
10313 vty_out(vty, "advertised");
10314 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
10315 vty_out(vty, "%sreceived",
10316 CHECK_FLAG(p->af_cap[afi][safi],
10317 adv_rmcap)
10318 ? ", "
10319 : "");
10320 vty_out(vty, "\n");
10321 }
10322 }
10323}
10324
13909c4f
DS
10325static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
10326 struct peer *p,
10327 bool use_json,
10328 json_object *json)
2986cac2 10329{
08c2d52a 10330 bool rbit_status = false;
2986cac2 10331
10332 if (!use_json)
a53ca37b 10333 vty_out(vty, "\n R bit: ");
2986cac2 10334
13909c4f
DS
10335 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
10336 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
10337 && (p->status == Established)) {
2986cac2 10338
10339 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 10340 rbit_status = true;
2986cac2 10341 else
08c2d52a 10342 rbit_status = false;
2986cac2 10343 }
10344
10345 if (rbit_status) {
10346 if (use_json)
13909c4f 10347 json_object_boolean_true_add(json, "rBit");
2986cac2 10348 else
10349 vty_out(vty, "True\n");
10350 } else {
10351 if (use_json)
13909c4f 10352 json_object_boolean_false_add(json, "rBit");
2986cac2 10353 else
10354 vty_out(vty, "False\n");
10355 }
10356}
10357
13909c4f
DS
10358static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
10359 struct peer *peer,
10360 bool use_json,
10361 json_object *json)
2986cac2 10362{
2bb5d39b 10363 const char *mode = "NotApplicable";
2986cac2 10364
10365 if (!use_json)
a53ca37b 10366 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 10367
13909c4f
DS
10368 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10369 && (peer->status == Established)) {
2986cac2 10370
13909c4f
DS
10371 if ((peer->nsf_af_count == 0)
10372 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10373
2986cac2 10374 mode = "Disable";
10375
13909c4f
DS
10376 } else if (peer->nsf_af_count == 0
10377 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10378
2986cac2 10379 mode = "Helper";
10380
13909c4f
DS
10381 } else if (peer->nsf_af_count != 0
10382 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 10383
2986cac2 10384 mode = "Restart";
2986cac2 10385 }
10386 }
10387
10388 if (use_json) {
13909c4f 10389 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 10390 } else
10391 vty_out(vty, mode, "\n");
10392}
10393
13909c4f
DS
10394static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
10395 struct peer *p,
10396 bool use_json,
10397 json_object *json)
2986cac2 10398{
10399 const char *mode = "Invalid";
10400
10401 if (!use_json)
a53ca37b 10402 vty_out(vty, " Local GR Mode: ");
2986cac2 10403
10404 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
10405 mode = "Helper";
10406 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
10407 mode = "Restart";
10408 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
10409 mode = "Disable";
2ba1fe69 10410 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 10411 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
10412 mode = "Helper*";
10413 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
10414 mode = "Restart*";
10415 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
10416 mode = "Disable*";
10417 else
10418 mode = "Invalid*";
2ba1fe69 10419 }
2986cac2 10420
10421 if (use_json) {
13909c4f 10422 json_object_string_add(json, "localGrMode", mode);
2986cac2 10423 } else {
10424 vty_out(vty, mode, "\n");
10425 }
10426}
10427
13909c4f
DS
10428static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
10429 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 10430{
2ba1fe69 10431 afi_t afi;
10432 safi_t safi;
2986cac2 10433 json_object *json_afi_safi = NULL;
10434 json_object *json_timer = NULL;
10435 json_object *json_endofrib_status = NULL;
9e3b51a7 10436 bool eor_flag = false;
2986cac2 10437
10438 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10439 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
10440 if (!peer->afc[afi][safi])
10441 continue;
2986cac2 10442
13909c4f
DS
10443 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
10444 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
10445 continue;
9e3b51a7 10446
13909c4f
DS
10447 if (use_json) {
10448 json_afi_safi = json_object_new_object();
10449 json_endofrib_status = json_object_new_object();
10450 json_timer = json_object_new_object();
10451 }
2986cac2 10452
13909c4f
DS
10453 if (peer->eor_stime[afi][safi]
10454 >= peer->pkt_stime[afi][safi])
10455 eor_flag = true;
10456 else
10457 eor_flag = false;
2986cac2 10458
13909c4f 10459 if (!use_json) {
a53ca37b 10460 vty_out(vty, " %s:\n",
13909c4f 10461 get_afi_safi_str(afi, safi, false));
2986cac2 10462
a53ca37b 10463 vty_out(vty, " F bit: ");
698ba8d0 10464 }
2986cac2 10465
13909c4f
DS
10466 if (peer->nsf[afi][safi]
10467 && CHECK_FLAG(peer->af_cap[afi][safi],
10468 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 10469
13909c4f
DS
10470 if (use_json) {
10471 json_object_boolean_true_add(
2986cac2 10472 json_afi_safi, "fBit");
13909c4f
DS
10473 } else
10474 vty_out(vty, "True\n");
10475 } else {
10476 if (use_json)
10477 json_object_boolean_false_add(
10478 json_afi_safi, "fBit");
10479 else
10480 vty_out(vty, "False\n");
10481 }
2986cac2 10482
13909c4f 10483 if (!use_json)
a53ca37b 10484 vty_out(vty, " End-of-RIB sent: ");
2986cac2 10485
13909c4f
DS
10486 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10487 PEER_STATUS_EOR_SEND)) {
10488 if (use_json) {
10489 json_object_boolean_true_add(
2986cac2 10490 json_endofrib_status,
13909c4f 10491 "endOfRibSend");
9e3b51a7 10492
13909c4f
DS
10493 PRINT_EOR_JSON(eor_flag);
10494 } else {
10495 vty_out(vty, "Yes\n");
10496 vty_out(vty,
a53ca37b 10497 " End-of-RIB sent after update: ");
2986cac2 10498
13909c4f
DS
10499 PRINT_EOR(eor_flag);
10500 }
10501 } else {
10502 if (use_json) {
10503 json_object_boolean_false_add(
2986cac2 10504 json_endofrib_status,
13909c4f
DS
10505 "endOfRibSend");
10506 json_object_boolean_false_add(
9e3b51a7 10507 json_endofrib_status,
13909c4f
DS
10508 "endOfRibSentAfterUpdate");
10509 } else {
10510 vty_out(vty, "No\n");
10511 vty_out(vty,
a53ca37b 10512 " End-of-RIB sent after update: ");
13909c4f 10513 vty_out(vty, "No\n");
2986cac2 10514 }
13909c4f 10515 }
2986cac2 10516
a53ca37b
DA
10517 if (!use_json)
10518 vty_out(vty, " End-of-RIB received: ");
10519
10520 if (CHECK_FLAG(peer->af_sflags[afi][safi],
10521 PEER_STATUS_EOR_RECEIVED)) {
10522 if (use_json)
10523 json_object_boolean_true_add(
10524 json_endofrib_status,
10525 "endOfRibRecv");
10526 else
10527 vty_out(vty, "Yes\n");
10528 } else {
10529 if (use_json)
10530 json_object_boolean_false_add(
10531 json_endofrib_status,
10532 "endOfRibRecv");
10533 else
10534 vty_out(vty, "No\n");
10535 }
10536
13909c4f
DS
10537 if (use_json) {
10538 json_object_int_add(json_timer,
10539 "stalePathTimer",
10540 peer->bgp->stalepath_time);
2986cac2 10541
13909c4f
DS
10542 if (peer->t_gr_stale != NULL) {
10543 json_object_int_add(
2986cac2 10544 json_timer,
10545 "stalePathTimerRemaining",
10546 thread_timer_remain_second(
13909c4f
DS
10547 peer->t_gr_stale));
10548 }
3a75afa4 10549
13909c4f
DS
10550 /* Display Configured Selection
10551 * Deferral only when when
10552 * Gr mode is enabled.
10553 */
10554 if (CHECK_FLAG(peer->flags,
10555 PEER_FLAG_GRACEFUL_RESTART)) {
10556 json_object_int_add(
3a75afa4 10557 json_timer,
2986cac2 10558 "selectionDeferralTimer",
10559 peer->bgp->stalepath_time);
13909c4f 10560 }
2986cac2 10561
13909c4f
DS
10562 if (peer->bgp->gr_info[afi][safi]
10563 .t_select_deferral
10564 != NULL) {
2986cac2 10565
13909c4f 10566 json_object_int_add(
2986cac2 10567 json_timer,
10568 "selectionDeferralTimerRemaining",
10569 thread_timer_remain_second(
13909c4f
DS
10570 peer->bgp
10571 ->gr_info[afi]
10572 [safi]
10573 .t_select_deferral));
10574 }
10575 } else {
a53ca37b 10576 vty_out(vty, " Timers:\n");
13909c4f 10577 vty_out(vty,
a53ca37b
DA
10578 " Configured Stale Path Time(sec): %u\n",
10579 peer->bgp->stalepath_time);
2986cac2 10580
a53ca37b 10581 if (peer->t_gr_stale != NULL)
2986cac2 10582 vty_out(vty,
a53ca37b 10583 " Stale Path Remaining(sec): %ld\n",
2986cac2 10584 thread_timer_remain_second(
13909c4f 10585 peer->t_gr_stale));
13909c4f
DS
10586 /* Display Configured Selection
10587 * Deferral only when when
10588 * Gr mode is enabled.
10589 */
10590 if (CHECK_FLAG(peer->flags,
a53ca37b 10591 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 10592 vty_out(vty,
a53ca37b 10593 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 10594 peer->bgp->select_defer_time);
2986cac2 10595
13909c4f
DS
10596 if (peer->bgp->gr_info[afi][safi]
10597 .t_select_deferral
a53ca37b 10598 != NULL)
13909c4f 10599 vty_out(vty,
a53ca37b 10600 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 10601 thread_timer_remain_second(
13909c4f
DS
10602 peer->bgp
10603 ->gr_info[afi]
10604 [safi]
10605 .t_select_deferral));
2986cac2 10606 }
13909c4f
DS
10607 if (use_json) {
10608 json_object_object_add(json_afi_safi,
10609 "endOfRibStatus",
10610 json_endofrib_status);
10611 json_object_object_add(json_afi_safi, "timers",
10612 json_timer);
10613 json_object_object_add(
10614 json, get_afi_safi_str(afi, safi, true),
10615 json_afi_safi);
10616 }
2986cac2 10617 }
10618 }
10619}
10620
36235319
QY
10621static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
10622 struct peer *p,
10623 bool use_json,
10624 json_object *json)
2986cac2 10625{
10626 if (use_json) {
10627 json_object *json_timer = NULL;
10628
10629 json_timer = json_object_new_object();
10630
13909c4f
DS
10631 json_object_int_add(json_timer, "configuredRestartTimer",
10632 p->bgp->restart_time);
2986cac2 10633
13909c4f
DS
10634 json_object_int_add(json_timer, "receivedRestartTimer",
10635 p->v_gr_restart);
2986cac2 10636
13909c4f
DS
10637 if (p->t_gr_restart != NULL)
10638 json_object_int_add(
10639 json_timer, "restartTimerRemaining",
10640 thread_timer_remain_second(p->t_gr_restart));
2986cac2 10641
10642 json_object_object_add(json, "timers", json_timer);
10643 } else {
10644
a53ca37b
DA
10645 vty_out(vty, " Timers:\n");
10646 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 10647 p->bgp->restart_time);
2986cac2 10648
a53ca37b 10649 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
10650 p->v_gr_restart);
10651 if (p->t_gr_restart != NULL)
a53ca37b 10652 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 10653 thread_timer_remain_second(p->t_gr_restart));
36235319 10654 if (p->t_gr_restart != NULL) {
a53ca37b 10655 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
10656 thread_timer_remain_second(p->t_gr_restart));
10657 }
2986cac2 10658 }
10659}
10660
10661static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 10662 bool use_json, json_object *json)
2986cac2 10663{
10664 char buf[SU_ADDRSTRLEN] = {0};
10665 char dn_flag[2] = {0};
2b7165e7
QY
10666 /* '*' + v6 address of neighbor */
10667 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 10668
2986cac2 10669 if (!p->conf_if && peer_dynamic_neighbor(p))
10670 dn_flag[0] = '*';
10671
10672 if (p->conf_if) {
10673 if (use_json)
13909c4f
DS
10674 json_object_string_add(
10675 json, "neighborAddr",
2986cac2 10676 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
10677 ? "none"
10678 : sockunion2str(&p->su, buf,
10679 SU_ADDRSTRLEN));
2986cac2 10680 else
13909c4f 10681 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 10682 BGP_PEER_SU_UNSPEC(p)
10683 ? "none"
10684 : sockunion2str(&p->su, buf,
10685 SU_ADDRSTRLEN));
10686 } else {
772270f3
QY
10687 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
10688 p->host);
2986cac2 10689
10690 if (use_json)
36235319
QY
10691 json_object_string_add(json, "neighborAddr",
10692 neighborAddr);
2986cac2 10693 else
36235319 10694 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 10695 }
10696
10697 /* more gr info in new format */
10698 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
10699}
10700
d62a17ae 10701static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 10702 safi_t safi, bool use_json,
d62a17ae 10703 json_object *json_neigh)
10704{
0291c246
MK
10705 struct bgp_filter *filter;
10706 struct peer_af *paf;
10707 char orf_pfx_name[BUFSIZ];
10708 int orf_pfx_count;
10709 json_object *json_af = NULL;
10710 json_object *json_prefA = NULL;
10711 json_object *json_prefB = NULL;
10712 json_object *json_addr = NULL;
d62a17ae 10713
10714 if (use_json) {
10715 json_addr = json_object_new_object();
10716 json_af = json_object_new_object();
10717 filter = &p->filter[afi][safi];
10718
10719 if (peer_group_active(p))
10720 json_object_string_add(json_addr, "peerGroupMember",
10721 p->group->name);
10722
10723 paf = peer_af_find(p, afi, safi);
10724 if (paf && PAF_SUBGRP(paf)) {
10725 json_object_int_add(json_addr, "updateGroupId",
10726 PAF_UPDGRP(paf)->id);
10727 json_object_int_add(json_addr, "subGroupId",
10728 PAF_SUBGRP(paf)->id);
10729 json_object_int_add(json_addr, "packetQueueLength",
10730 bpacket_queue_virtual_length(paf));
10731 }
10732
10733 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10734 || CHECK_FLAG(p->af_cap[afi][safi],
10735 PEER_CAP_ORF_PREFIX_SM_RCV)
10736 || CHECK_FLAG(p->af_cap[afi][safi],
10737 PEER_CAP_ORF_PREFIX_RM_ADV)
10738 || CHECK_FLAG(p->af_cap[afi][safi],
10739 PEER_CAP_ORF_PREFIX_RM_RCV)) {
10740 json_object_int_add(json_af, "orfType",
10741 ORF_TYPE_PREFIX);
10742 json_prefA = json_object_new_object();
10743 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
10744 PEER_CAP_ORF_PREFIX_SM_ADV,
10745 PEER_CAP_ORF_PREFIX_RM_ADV,
10746 PEER_CAP_ORF_PREFIX_SM_RCV,
10747 PEER_CAP_ORF_PREFIX_RM_RCV,
10748 use_json, json_prefA);
10749 json_object_object_add(json_af, "orfPrefixList",
10750 json_prefA);
10751 }
10752
10753 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10754 || CHECK_FLAG(p->af_cap[afi][safi],
10755 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10756 || CHECK_FLAG(p->af_cap[afi][safi],
10757 PEER_CAP_ORF_PREFIX_RM_ADV)
10758 || CHECK_FLAG(p->af_cap[afi][safi],
10759 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
10760 json_object_int_add(json_af, "orfOldType",
10761 ORF_TYPE_PREFIX_OLD);
10762 json_prefB = json_object_new_object();
10763 bgp_show_peer_afi_orf_cap(
10764 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
10765 PEER_CAP_ORF_PREFIX_RM_ADV,
10766 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
10767 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
10768 json_prefB);
10769 json_object_object_add(json_af, "orfOldPrefixList",
10770 json_prefB);
10771 }
10772
10773 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
10774 || CHECK_FLAG(p->af_cap[afi][safi],
10775 PEER_CAP_ORF_PREFIX_SM_RCV)
10776 || CHECK_FLAG(p->af_cap[afi][safi],
10777 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
10778 || CHECK_FLAG(p->af_cap[afi][safi],
10779 PEER_CAP_ORF_PREFIX_RM_ADV)
10780 || CHECK_FLAG(p->af_cap[afi][safi],
10781 PEER_CAP_ORF_PREFIX_RM_RCV)
10782 || CHECK_FLAG(p->af_cap[afi][safi],
10783 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
10784 json_object_object_add(json_addr, "afDependentCap",
10785 json_af);
10786 else
10787 json_object_free(json_af);
10788
772270f3
QY
10789 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
10790 p->host, afi, safi);
d62a17ae 10791 orf_pfx_count = prefix_bgp_show_prefix_list(
10792 NULL, afi, orf_pfx_name, use_json);
10793
10794 if (CHECK_FLAG(p->af_sflags[afi][safi],
10795 PEER_STATUS_ORF_PREFIX_SEND)
10796 || orf_pfx_count) {
10797 if (CHECK_FLAG(p->af_sflags[afi][safi],
10798 PEER_STATUS_ORF_PREFIX_SEND))
10799 json_object_boolean_true_add(json_neigh,
10800 "orfSent");
10801 if (orf_pfx_count)
10802 json_object_int_add(json_addr, "orfRecvCounter",
10803 orf_pfx_count);
10804 }
10805 if (CHECK_FLAG(p->af_sflags[afi][safi],
10806 PEER_STATUS_ORF_WAIT_REFRESH))
10807 json_object_string_add(
10808 json_addr, "orfFirstUpdate",
10809 "deferredUntilORFOrRouteRefreshRecvd");
10810
10811 if (CHECK_FLAG(p->af_flags[afi][safi],
10812 PEER_FLAG_REFLECTOR_CLIENT))
10813 json_object_boolean_true_add(json_addr,
10814 "routeReflectorClient");
10815 if (CHECK_FLAG(p->af_flags[afi][safi],
10816 PEER_FLAG_RSERVER_CLIENT))
10817 json_object_boolean_true_add(json_addr,
10818 "routeServerClient");
10819 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10820 json_object_boolean_true_add(json_addr,
10821 "inboundSoftConfigPermit");
10822
10823 if (CHECK_FLAG(p->af_flags[afi][safi],
10824 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
10825 json_object_boolean_true_add(
10826 json_addr,
10827 "privateAsNumsAllReplacedInUpdatesToNbr");
10828 else if (CHECK_FLAG(p->af_flags[afi][safi],
10829 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
10830 json_object_boolean_true_add(
10831 json_addr,
10832 "privateAsNumsReplacedInUpdatesToNbr");
10833 else if (CHECK_FLAG(p->af_flags[afi][safi],
10834 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
10835 json_object_boolean_true_add(
10836 json_addr,
10837 "privateAsNumsAllRemovedInUpdatesToNbr");
10838 else if (CHECK_FLAG(p->af_flags[afi][safi],
10839 PEER_FLAG_REMOVE_PRIVATE_AS))
10840 json_object_boolean_true_add(
10841 json_addr,
10842 "privateAsNumsRemovedInUpdatesToNbr");
10843
dcc68b5e
MS
10844 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
10845 json_object_boolean_true_add(
10846 json_addr,
10847 bgp_addpath_names(p->addpath_type[afi][safi])
10848 ->type_json_name);
d62a17ae 10849
10850 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
10851 json_object_string_add(json_addr,
10852 "overrideASNsInOutboundUpdates",
10853 "ifAspathEqualRemoteAs");
10854
10855 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
10856 || CHECK_FLAG(p->af_flags[afi][safi],
10857 PEER_FLAG_FORCE_NEXTHOP_SELF))
10858 json_object_boolean_true_add(json_addr,
10859 "routerAlwaysNextHop");
10860 if (CHECK_FLAG(p->af_flags[afi][safi],
10861 PEER_FLAG_AS_PATH_UNCHANGED))
10862 json_object_boolean_true_add(
10863 json_addr, "unchangedAsPathPropogatedToNbr");
10864 if (CHECK_FLAG(p->af_flags[afi][safi],
10865 PEER_FLAG_NEXTHOP_UNCHANGED))
10866 json_object_boolean_true_add(
10867 json_addr, "unchangedNextHopPropogatedToNbr");
10868 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
10869 json_object_boolean_true_add(
10870 json_addr, "unchangedMedPropogatedToNbr");
10871 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
10872 || CHECK_FLAG(p->af_flags[afi][safi],
10873 PEER_FLAG_SEND_EXT_COMMUNITY)) {
10874 if (CHECK_FLAG(p->af_flags[afi][safi],
10875 PEER_FLAG_SEND_COMMUNITY)
10876 && CHECK_FLAG(p->af_flags[afi][safi],
10877 PEER_FLAG_SEND_EXT_COMMUNITY))
10878 json_object_string_add(json_addr,
10879 "commAttriSentToNbr",
10880 "extendedAndStandard");
10881 else if (CHECK_FLAG(p->af_flags[afi][safi],
10882 PEER_FLAG_SEND_EXT_COMMUNITY))
10883 json_object_string_add(json_addr,
10884 "commAttriSentToNbr",
10885 "extended");
10886 else
10887 json_object_string_add(json_addr,
10888 "commAttriSentToNbr",
10889 "standard");
10890 }
10891 if (CHECK_FLAG(p->af_flags[afi][safi],
10892 PEER_FLAG_DEFAULT_ORIGINATE)) {
10893 if (p->default_rmap[afi][safi].name)
10894 json_object_string_add(
10895 json_addr, "defaultRouteMap",
10896 p->default_rmap[afi][safi].name);
10897
10898 if (paf && PAF_SUBGRP(paf)
10899 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
10900 SUBGRP_STATUS_DEFAULT_ORIGINATE))
10901 json_object_boolean_true_add(json_addr,
10902 "defaultSent");
10903 else
10904 json_object_boolean_true_add(json_addr,
10905 "defaultNotSent");
10906 }
10907
dff8f48d 10908 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 10909 if (is_evpn_enabled())
60466a63
QY
10910 json_object_boolean_true_add(
10911 json_addr, "advertiseAllVnis");
dff8f48d
MK
10912 }
10913
d62a17ae 10914 if (filter->plist[FILTER_IN].name
10915 || filter->dlist[FILTER_IN].name
10916 || filter->aslist[FILTER_IN].name
10917 || filter->map[RMAP_IN].name)
10918 json_object_boolean_true_add(json_addr,
10919 "inboundPathPolicyConfig");
10920 if (filter->plist[FILTER_OUT].name
10921 || filter->dlist[FILTER_OUT].name
10922 || filter->aslist[FILTER_OUT].name
10923 || filter->map[RMAP_OUT].name || filter->usmap.name)
10924 json_object_boolean_true_add(
10925 json_addr, "outboundPathPolicyConfig");
10926
10927 /* prefix-list */
10928 if (filter->plist[FILTER_IN].name)
10929 json_object_string_add(json_addr,
10930 "incomingUpdatePrefixFilterList",
10931 filter->plist[FILTER_IN].name);
10932 if (filter->plist[FILTER_OUT].name)
10933 json_object_string_add(json_addr,
10934 "outgoingUpdatePrefixFilterList",
10935 filter->plist[FILTER_OUT].name);
10936
10937 /* distribute-list */
10938 if (filter->dlist[FILTER_IN].name)
10939 json_object_string_add(
10940 json_addr, "incomingUpdateNetworkFilterList",
10941 filter->dlist[FILTER_IN].name);
10942 if (filter->dlist[FILTER_OUT].name)
10943 json_object_string_add(
10944 json_addr, "outgoingUpdateNetworkFilterList",
10945 filter->dlist[FILTER_OUT].name);
10946
10947 /* filter-list. */
10948 if (filter->aslist[FILTER_IN].name)
10949 json_object_string_add(json_addr,
10950 "incomingUpdateAsPathFilterList",
10951 filter->aslist[FILTER_IN].name);
10952 if (filter->aslist[FILTER_OUT].name)
10953 json_object_string_add(json_addr,
10954 "outgoingUpdateAsPathFilterList",
10955 filter->aslist[FILTER_OUT].name);
10956
10957 /* route-map. */
10958 if (filter->map[RMAP_IN].name)
10959 json_object_string_add(
10960 json_addr, "routeMapForIncomingAdvertisements",
10961 filter->map[RMAP_IN].name);
10962 if (filter->map[RMAP_OUT].name)
10963 json_object_string_add(
10964 json_addr, "routeMapForOutgoingAdvertisements",
10965 filter->map[RMAP_OUT].name);
10966
9dac9fc8 10967 /* ebgp-requires-policy (inbound) */
1d3fdccf 10968 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10969 && !bgp_inbound_policy_exists(p, filter))
10970 json_object_string_add(
10971 json_addr, "inboundEbgpRequiresPolicy",
10972 "Inbound updates discarded due to missing policy");
10973
10974 /* ebgp-requires-policy (outbound) */
1d3fdccf 10975 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
10976 && (!bgp_outbound_policy_exists(p, filter)))
10977 json_object_string_add(
10978 json_addr, "outboundEbgpRequiresPolicy",
10979 "Outbound updates discarded due to missing policy");
10980
d62a17ae 10981 /* unsuppress-map */
10982 if (filter->usmap.name)
10983 json_object_string_add(json_addr,
10984 "selectiveUnsuppressRouteMap",
10985 filter->usmap.name);
10986
10987 /* Receive prefix count */
10988 json_object_int_add(json_addr, "acceptedPrefixCounter",
10989 p->pcount[afi][safi]);
50e05855
AD
10990 if (paf && PAF_SUBGRP(paf))
10991 json_object_int_add(json_addr, "sentPrefixCounter",
10992 (PAF_SUBGRP(paf))->scount);
d62a17ae 10993
fde246e8
DA
10994 /* Maximum prefix */
10995 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
10996 json_object_int_add(json_addr, "prefixOutAllowedMax",
10997 p->pmax_out[afi][safi]);
10998
d62a17ae 10999 /* Maximum prefix */
11000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
11001 json_object_int_add(json_addr, "prefixAllowedMax",
11002 p->pmax[afi][safi]);
11003 if (CHECK_FLAG(p->af_flags[afi][safi],
11004 PEER_FLAG_MAX_PREFIX_WARNING))
11005 json_object_boolean_true_add(
11006 json_addr, "prefixAllowedMaxWarning");
11007 json_object_int_add(json_addr,
11008 "prefixAllowedWarningThresh",
11009 p->pmax_threshold[afi][safi]);
11010 if (p->pmax_restart[afi][safi])
11011 json_object_int_add(
11012 json_addr,
11013 "prefixAllowedRestartIntervalMsecs",
11014 p->pmax_restart[afi][safi] * 60000);
11015 }
2986cac2 11016 json_object_object_add(json_neigh,
36235319 11017 get_afi_safi_str(afi, safi, true),
d62a17ae 11018 json_addr);
11019
11020 } else {
11021 filter = &p->filter[afi][safi];
11022
11023 vty_out(vty, " For address family: %s\n",
5cb5f4d0 11024 get_afi_safi_str(afi, safi, false));
d62a17ae 11025
11026 if (peer_group_active(p))
11027 vty_out(vty, " %s peer-group member\n",
11028 p->group->name);
11029
11030 paf = peer_af_find(p, afi, safi);
11031 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 11032 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 11033 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
11034 vty_out(vty, " Packet Queue length %d\n",
11035 bpacket_queue_virtual_length(paf));
11036 } else {
11037 vty_out(vty, " Not part of any update group\n");
11038 }
11039 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11040 || CHECK_FLAG(p->af_cap[afi][safi],
11041 PEER_CAP_ORF_PREFIX_SM_RCV)
11042 || CHECK_FLAG(p->af_cap[afi][safi],
11043 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11044 || CHECK_FLAG(p->af_cap[afi][safi],
11045 PEER_CAP_ORF_PREFIX_RM_ADV)
11046 || CHECK_FLAG(p->af_cap[afi][safi],
11047 PEER_CAP_ORF_PREFIX_RM_RCV)
11048 || CHECK_FLAG(p->af_cap[afi][safi],
11049 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11050 vty_out(vty, " AF-dependant capabilities:\n");
11051
11052 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11053 || CHECK_FLAG(p->af_cap[afi][safi],
11054 PEER_CAP_ORF_PREFIX_SM_RCV)
11055 || CHECK_FLAG(p->af_cap[afi][safi],
11056 PEER_CAP_ORF_PREFIX_RM_ADV)
11057 || CHECK_FLAG(p->af_cap[afi][safi],
11058 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11059 vty_out(vty,
11060 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11061 ORF_TYPE_PREFIX);
11062 bgp_show_peer_afi_orf_cap(
11063 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11064 PEER_CAP_ORF_PREFIX_RM_ADV,
11065 PEER_CAP_ORF_PREFIX_SM_RCV,
11066 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
11067 }
11068 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11069 || CHECK_FLAG(p->af_cap[afi][safi],
11070 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11071 || CHECK_FLAG(p->af_cap[afi][safi],
11072 PEER_CAP_ORF_PREFIX_RM_ADV)
11073 || CHECK_FLAG(p->af_cap[afi][safi],
11074 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11075 vty_out(vty,
11076 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
11077 ORF_TYPE_PREFIX_OLD);
11078 bgp_show_peer_afi_orf_cap(
11079 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11080 PEER_CAP_ORF_PREFIX_RM_ADV,
11081 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11082 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
11083 }
11084
772270f3
QY
11085 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11086 p->host, afi, safi);
d62a17ae 11087 orf_pfx_count = prefix_bgp_show_prefix_list(
11088 NULL, afi, orf_pfx_name, use_json);
11089
11090 if (CHECK_FLAG(p->af_sflags[afi][safi],
11091 PEER_STATUS_ORF_PREFIX_SEND)
11092 || orf_pfx_count) {
11093 vty_out(vty, " Outbound Route Filter (ORF):");
11094 if (CHECK_FLAG(p->af_sflags[afi][safi],
11095 PEER_STATUS_ORF_PREFIX_SEND))
11096 vty_out(vty, " sent;");
11097 if (orf_pfx_count)
11098 vty_out(vty, " received (%d entries)",
11099 orf_pfx_count);
11100 vty_out(vty, "\n");
11101 }
11102 if (CHECK_FLAG(p->af_sflags[afi][safi],
11103 PEER_STATUS_ORF_WAIT_REFRESH))
11104 vty_out(vty,
11105 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
11106
11107 if (CHECK_FLAG(p->af_flags[afi][safi],
11108 PEER_FLAG_REFLECTOR_CLIENT))
11109 vty_out(vty, " Route-Reflector Client\n");
11110 if (CHECK_FLAG(p->af_flags[afi][safi],
11111 PEER_FLAG_RSERVER_CLIENT))
11112 vty_out(vty, " Route-Server Client\n");
11113 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
11114 vty_out(vty,
11115 " Inbound soft reconfiguration allowed\n");
11116
11117 if (CHECK_FLAG(p->af_flags[afi][safi],
11118 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
11119 vty_out(vty,
11120 " Private AS numbers (all) replaced in updates to this neighbor\n");
11121 else if (CHECK_FLAG(p->af_flags[afi][safi],
11122 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
11123 vty_out(vty,
11124 " Private AS numbers replaced in updates to this neighbor\n");
11125 else if (CHECK_FLAG(p->af_flags[afi][safi],
11126 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
11127 vty_out(vty,
11128 " Private AS numbers (all) removed in updates to this neighbor\n");
11129 else if (CHECK_FLAG(p->af_flags[afi][safi],
11130 PEER_FLAG_REMOVE_PRIVATE_AS))
11131 vty_out(vty,
11132 " Private AS numbers removed in updates to this neighbor\n");
11133
dcc68b5e
MS
11134 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
11135 vty_out(vty, " %s\n",
11136 bgp_addpath_names(p->addpath_type[afi][safi])
11137 ->human_description);
d62a17ae 11138
11139 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
11140 vty_out(vty,
11141 " Override ASNs in outbound updates if aspath equals remote-as\n");
11142
11143 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
11144 || CHECK_FLAG(p->af_flags[afi][safi],
11145 PEER_FLAG_FORCE_NEXTHOP_SELF))
11146 vty_out(vty, " NEXT_HOP is always this router\n");
11147 if (CHECK_FLAG(p->af_flags[afi][safi],
11148 PEER_FLAG_AS_PATH_UNCHANGED))
11149 vty_out(vty,
11150 " AS_PATH is propagated unchanged to this neighbor\n");
11151 if (CHECK_FLAG(p->af_flags[afi][safi],
11152 PEER_FLAG_NEXTHOP_UNCHANGED))
11153 vty_out(vty,
11154 " NEXT_HOP is propagated unchanged to this neighbor\n");
11155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
11156 vty_out(vty,
11157 " MED is propagated unchanged to this neighbor\n");
11158 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
11159 || CHECK_FLAG(p->af_flags[afi][safi],
11160 PEER_FLAG_SEND_EXT_COMMUNITY)
11161 || CHECK_FLAG(p->af_flags[afi][safi],
11162 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
11163 vty_out(vty,
11164 " Community attribute sent to this neighbor");
11165 if (CHECK_FLAG(p->af_flags[afi][safi],
11166 PEER_FLAG_SEND_COMMUNITY)
11167 && CHECK_FLAG(p->af_flags[afi][safi],
11168 PEER_FLAG_SEND_EXT_COMMUNITY)
11169 && CHECK_FLAG(p->af_flags[afi][safi],
11170 PEER_FLAG_SEND_LARGE_COMMUNITY))
11171 vty_out(vty, "(all)\n");
11172 else if (CHECK_FLAG(p->af_flags[afi][safi],
11173 PEER_FLAG_SEND_LARGE_COMMUNITY))
11174 vty_out(vty, "(large)\n");
11175 else if (CHECK_FLAG(p->af_flags[afi][safi],
11176 PEER_FLAG_SEND_EXT_COMMUNITY))
11177 vty_out(vty, "(extended)\n");
11178 else
11179 vty_out(vty, "(standard)\n");
11180 }
11181 if (CHECK_FLAG(p->af_flags[afi][safi],
11182 PEER_FLAG_DEFAULT_ORIGINATE)) {
11183 vty_out(vty, " Default information originate,");
11184
11185 if (p->default_rmap[afi][safi].name)
11186 vty_out(vty, " default route-map %s%s,",
11187 p->default_rmap[afi][safi].map ? "*"
11188 : "",
11189 p->default_rmap[afi][safi].name);
11190 if (paf && PAF_SUBGRP(paf)
11191 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
11192 SUBGRP_STATUS_DEFAULT_ORIGINATE))
11193 vty_out(vty, " default sent\n");
11194 else
11195 vty_out(vty, " default not sent\n");
11196 }
11197
dff8f48d
MK
11198 /* advertise-vni-all */
11199 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 11200 if (is_evpn_enabled())
dff8f48d
MK
11201 vty_out(vty, " advertise-all-vni\n");
11202 }
11203
d62a17ae 11204 if (filter->plist[FILTER_IN].name
11205 || filter->dlist[FILTER_IN].name
11206 || filter->aslist[FILTER_IN].name
11207 || filter->map[RMAP_IN].name)
11208 vty_out(vty, " Inbound path policy configured\n");
11209 if (filter->plist[FILTER_OUT].name
11210 || filter->dlist[FILTER_OUT].name
11211 || filter->aslist[FILTER_OUT].name
11212 || filter->map[RMAP_OUT].name || filter->usmap.name)
11213 vty_out(vty, " Outbound path policy configured\n");
11214
11215 /* prefix-list */
11216 if (filter->plist[FILTER_IN].name)
11217 vty_out(vty,
11218 " Incoming update prefix filter list is %s%s\n",
11219 filter->plist[FILTER_IN].plist ? "*" : "",
11220 filter->plist[FILTER_IN].name);
11221 if (filter->plist[FILTER_OUT].name)
11222 vty_out(vty,
11223 " Outgoing update prefix filter list is %s%s\n",
11224 filter->plist[FILTER_OUT].plist ? "*" : "",
11225 filter->plist[FILTER_OUT].name);
11226
11227 /* distribute-list */
11228 if (filter->dlist[FILTER_IN].name)
11229 vty_out(vty,
11230 " Incoming update network filter list is %s%s\n",
11231 filter->dlist[FILTER_IN].alist ? "*" : "",
11232 filter->dlist[FILTER_IN].name);
11233 if (filter->dlist[FILTER_OUT].name)
11234 vty_out(vty,
11235 " Outgoing update network filter list is %s%s\n",
11236 filter->dlist[FILTER_OUT].alist ? "*" : "",
11237 filter->dlist[FILTER_OUT].name);
11238
11239 /* filter-list. */
11240 if (filter->aslist[FILTER_IN].name)
11241 vty_out(vty,
11242 " Incoming update AS path filter list is %s%s\n",
11243 filter->aslist[FILTER_IN].aslist ? "*" : "",
11244 filter->aslist[FILTER_IN].name);
11245 if (filter->aslist[FILTER_OUT].name)
11246 vty_out(vty,
11247 " Outgoing update AS path filter list is %s%s\n",
11248 filter->aslist[FILTER_OUT].aslist ? "*" : "",
11249 filter->aslist[FILTER_OUT].name);
11250
11251 /* route-map. */
11252 if (filter->map[RMAP_IN].name)
11253 vty_out(vty,
11254 " Route map for incoming advertisements is %s%s\n",
11255 filter->map[RMAP_IN].map ? "*" : "",
11256 filter->map[RMAP_IN].name);
11257 if (filter->map[RMAP_OUT].name)
11258 vty_out(vty,
11259 " Route map for outgoing advertisements is %s%s\n",
11260 filter->map[RMAP_OUT].map ? "*" : "",
11261 filter->map[RMAP_OUT].name);
11262
9dac9fc8 11263 /* ebgp-requires-policy (inbound) */
1d3fdccf 11264 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11265 && !bgp_inbound_policy_exists(p, filter))
11266 vty_out(vty,
11267 " Inbound updates discarded due to missing policy\n");
11268
11269 /* ebgp-requires-policy (outbound) */
1d3fdccf 11270 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
11271 && !bgp_outbound_policy_exists(p, filter))
11272 vty_out(vty,
11273 " Outbound updates discarded due to missing policy\n");
11274
d62a17ae 11275 /* unsuppress-map */
11276 if (filter->usmap.name)
11277 vty_out(vty,
11278 " Route map for selective unsuppress is %s%s\n",
11279 filter->usmap.map ? "*" : "",
11280 filter->usmap.name);
11281
11282 /* Receive prefix count */
6cde4b45 11283 vty_out(vty, " %u accepted prefixes\n",
a0a87037 11284 p->pcount[afi][safi]);
d62a17ae 11285
fde246e8
DA
11286 /* maximum-prefix-out */
11287 if (CHECK_FLAG(p->af_flags[afi][safi],
11288 PEER_FLAG_MAX_PREFIX_OUT))
11289 vty_out(vty,
6cde4b45 11290 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
11291 p->pmax_out[afi][safi]);
11292
d62a17ae 11293 /* Maximum prefix */
11294 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 11295 vty_out(vty,
6cde4b45 11296 " Maximum prefixes allowed %u%s\n",
d62a17ae 11297 p->pmax[afi][safi],
11298 CHECK_FLAG(p->af_flags[afi][safi],
11299 PEER_FLAG_MAX_PREFIX_WARNING)
11300 ? " (warning-only)"
11301 : "");
11302 vty_out(vty, " Threshold for warning message %d%%",
11303 p->pmax_threshold[afi][safi]);
11304 if (p->pmax_restart[afi][safi])
11305 vty_out(vty, ", restart interval %d min",
11306 p->pmax_restart[afi][safi]);
11307 vty_out(vty, "\n");
11308 }
11309
11310 vty_out(vty, "\n");
11311 }
11312}
11313
9f049418 11314static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 11315 json_object *json)
718e3744 11316{
d62a17ae 11317 struct bgp *bgp;
11318 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
11319 char timebuf[BGP_UPTIME_LEN];
11320 char dn_flag[2];
d62a17ae 11321 afi_t afi;
11322 safi_t safi;
d7c0a89a
QY
11323 uint16_t i;
11324 uint8_t *msg;
d62a17ae 11325 json_object *json_neigh = NULL;
11326 time_t epoch_tbuf;
718e3744 11327
d62a17ae 11328 bgp = p->bgp;
11329
11330 if (use_json)
11331 json_neigh = json_object_new_object();
11332
11333 memset(dn_flag, '\0', sizeof(dn_flag));
11334 if (!p->conf_if && peer_dynamic_neighbor(p))
11335 dn_flag[0] = '*';
11336
11337 if (!use_json) {
11338 if (p->conf_if) /* Configured interface name. */
11339 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
11340 BGP_PEER_SU_UNSPEC(p)
11341 ? "None"
11342 : sockunion2str(&p->su, buf,
11343 SU_ADDRSTRLEN));
11344 else /* Configured IP address. */
11345 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
11346 p->host);
11347 }
11348
11349 if (use_json) {
11350 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
11351 json_object_string_add(json_neigh, "bgpNeighborAddr",
11352 "none");
11353 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
11354 json_object_string_add(
11355 json_neigh, "bgpNeighborAddr",
11356 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
11357
11358 json_object_int_add(json_neigh, "remoteAs", p->as);
11359
11360 if (p->change_local_as)
11361 json_object_int_add(json_neigh, "localAs",
11362 p->change_local_as);
11363 else
11364 json_object_int_add(json_neigh, "localAs", p->local_as);
11365
11366 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
11367 json_object_boolean_true_add(json_neigh,
11368 "localAsNoPrepend");
11369
11370 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
11371 json_object_boolean_true_add(json_neigh,
11372 "localAsReplaceAs");
11373 } else {
11374 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
11375 || (p->as_type == AS_INTERNAL))
11376 vty_out(vty, "remote AS %u, ", p->as);
11377 else
11378 vty_out(vty, "remote AS Unspecified, ");
11379 vty_out(vty, "local AS %u%s%s, ",
11380 p->change_local_as ? p->change_local_as : p->local_as,
11381 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
11382 ? " no-prepend"
11383 : "",
11384 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
11385 ? " replace-as"
11386 : "");
11387 }
faa16034
DS
11388 /* peer type internal or confed-internal */
11389 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 11390 if (use_json) {
11391 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11392 json_object_boolean_true_add(
11393 json_neigh, "nbrConfedInternalLink");
11394 else
11395 json_object_boolean_true_add(json_neigh,
11396 "nbrInternalLink");
11397 } else {
11398 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11399 vty_out(vty, "confed-internal link\n");
11400 else
11401 vty_out(vty, "internal link\n");
11402 }
faa16034
DS
11403 /* peer type external or confed-external */
11404 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 11405 if (use_json) {
11406 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
11407 json_object_boolean_true_add(
11408 json_neigh, "nbrConfedExternalLink");
11409 else
11410 json_object_boolean_true_add(json_neigh,
11411 "nbrExternalLink");
11412 } else {
11413 if (bgp_confederation_peers_check(bgp, p->as))
11414 vty_out(vty, "confed-external link\n");
11415 else
11416 vty_out(vty, "external link\n");
11417 }
faa16034
DS
11418 } else {
11419 if (use_json)
11420 json_object_boolean_true_add(json_neigh,
11421 "nbrUnspecifiedLink");
11422 else
11423 vty_out(vty, "unspecified link\n");
d62a17ae 11424 }
11425
11426 /* Description. */
11427 if (p->desc) {
11428 if (use_json)
11429 json_object_string_add(json_neigh, "nbrDesc", p->desc);
11430 else
11431 vty_out(vty, " Description: %s\n", p->desc);
11432 }
11433
11434 if (p->hostname) {
11435 if (use_json) {
11436 if (p->hostname)
11437 json_object_string_add(json_neigh, "hostname",
11438 p->hostname);
11439
11440 if (p->domainname)
11441 json_object_string_add(json_neigh, "domainname",
11442 p->domainname);
11443 } else {
11444 if (p->domainname && (p->domainname[0] != '\0'))
11445 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
11446 p->domainname);
11447 else
11448 vty_out(vty, "Hostname: %s\n", p->hostname);
11449 }
11450 }
11451
11452 /* Peer-group */
11453 if (p->group) {
11454 if (use_json) {
11455 json_object_string_add(json_neigh, "peerGroup",
11456 p->group->name);
11457
11458 if (dn_flag[0]) {
11459 struct prefix prefix, *range = NULL;
11460
11461 sockunion2hostprefix(&(p->su), &prefix);
11462 range = peer_group_lookup_dynamic_neighbor_range(
11463 p->group, &prefix);
11464
11465 if (range) {
11466 prefix2str(range, buf1, sizeof(buf1));
11467 json_object_string_add(
11468 json_neigh,
11469 "peerSubnetRangeGroup", buf1);
11470 }
11471 }
11472 } else {
11473 vty_out(vty,
11474 " Member of peer-group %s for session parameters\n",
11475 p->group->name);
11476
11477 if (dn_flag[0]) {
11478 struct prefix prefix, *range = NULL;
11479
11480 sockunion2hostprefix(&(p->su), &prefix);
11481 range = peer_group_lookup_dynamic_neighbor_range(
11482 p->group, &prefix);
11483
11484 if (range) {
d62a17ae 11485 vty_out(vty,
1b78780b
DL
11486 " Belongs to the subnet range group: %pFX\n",
11487 range);
d62a17ae 11488 }
11489 }
11490 }
11491 }
11492
11493 if (use_json) {
11494 /* Administrative shutdown. */
cb9196e7
DS
11495 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11496 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11497 json_object_boolean_true_add(json_neigh,
11498 "adminShutDown");
11499
11500 /* BGP Version. */
11501 json_object_int_add(json_neigh, "bgpVersion", 4);
11502 json_object_string_add(
11503 json_neigh, "remoteRouterId",
11504 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
11505 json_object_string_add(
11506 json_neigh, "localRouterId",
11507 inet_ntop(AF_INET, &bgp->router_id, buf1,
11508 sizeof(buf1)));
d62a17ae 11509
11510 /* Confederation */
11511 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11512 && bgp_confederation_peers_check(bgp, p->as))
11513 json_object_boolean_true_add(json_neigh,
11514 "nbrCommonAdmin");
11515
11516 /* Status. */
11517 json_object_string_add(
11518 json_neigh, "bgpState",
11519 lookup_msg(bgp_status_msg, p->status, NULL));
11520
11521 if (p->status == Established) {
11522 time_t uptime;
d62a17ae 11523
11524 uptime = bgp_clock();
11525 uptime -= p->uptime;
d62a17ae 11526 epoch_tbuf = time(NULL) - uptime;
11527
d3c7efed
DS
11528 json_object_int_add(json_neigh, "bgpTimerUpMsec",
11529 uptime * 1000);
d62a17ae 11530 json_object_string_add(json_neigh, "bgpTimerUpString",
11531 peer_uptime(p->uptime, timebuf,
11532 BGP_UPTIME_LEN, 0,
11533 NULL));
11534 json_object_int_add(json_neigh,
11535 "bgpTimerUpEstablishedEpoch",
11536 epoch_tbuf);
11537 }
11538
11539 else if (p->status == Active) {
11540 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11541 json_object_string_add(json_neigh, "bgpStateIs",
11542 "passive");
11543 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11544 json_object_string_add(json_neigh, "bgpStateIs",
11545 "passiveNSF");
11546 }
11547
11548 /* read timer */
11549 time_t uptime;
a2700b50 11550 struct tm tm;
d62a17ae 11551
11552 uptime = bgp_clock();
11553 uptime -= p->readtime;
a2700b50
MS
11554 gmtime_r(&uptime, &tm);
11555
d62a17ae 11556 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
11557 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11558 + (tm.tm_hour * 3600000));
d62a17ae 11559
11560 uptime = bgp_clock();
11561 uptime -= p->last_write;
a2700b50
MS
11562 gmtime_r(&uptime, &tm);
11563
d62a17ae 11564 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
11565 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11566 + (tm.tm_hour * 3600000));
d62a17ae 11567
11568 uptime = bgp_clock();
11569 uptime -= p->update_time;
a2700b50
MS
11570 gmtime_r(&uptime, &tm);
11571
d62a17ae 11572 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
11573 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
11574 + (tm.tm_hour * 3600000));
d62a17ae 11575
11576 /* Configured timer values. */
11577 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
11578 p->v_holdtime * 1000);
11579 json_object_int_add(json_neigh,
11580 "bgpTimerKeepAliveIntervalMsecs",
11581 p->v_keepalive * 1000);
b90a8e13 11582 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11583 json_object_int_add(json_neigh,
11584 "bgpTimerConfiguredHoldTimeMsecs",
11585 p->holdtime * 1000);
11586 json_object_int_add(
11587 json_neigh,
11588 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11589 p->keepalive * 1000);
5d5393b9
DL
11590 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11591 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11592 json_object_int_add(json_neigh,
11593 "bgpTimerConfiguredHoldTimeMsecs",
11594 bgp->default_holdtime);
11595 json_object_int_add(
11596 json_neigh,
11597 "bgpTimerConfiguredKeepAliveIntervalMsecs",
11598 bgp->default_keepalive);
d62a17ae 11599 }
11600 } else {
11601 /* Administrative shutdown. */
cb9196e7
DS
11602 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
11603 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 11604 vty_out(vty, " Administratively shut down\n");
11605
11606 /* BGP Version. */
11607 vty_out(vty, " BGP version 4");
0e38aeb4 11608 vty_out(vty, ", remote router ID %s",
d62a17ae 11609 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
11610 vty_out(vty, ", local router ID %s\n",
11611 inet_ntop(AF_INET, &bgp->router_id, buf1,
11612 sizeof(buf1)));
d62a17ae 11613
11614 /* Confederation */
11615 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
11616 && bgp_confederation_peers_check(bgp, p->as))
11617 vty_out(vty,
11618 " Neighbor under common administration\n");
11619
11620 /* Status. */
11621 vty_out(vty, " BGP state = %s",
11622 lookup_msg(bgp_status_msg, p->status, NULL));
11623
11624 if (p->status == Established)
11625 vty_out(vty, ", up for %8s",
11626 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
11627 0, NULL));
11628
11629 else if (p->status == Active) {
11630 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
11631 vty_out(vty, " (passive)");
11632 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
11633 vty_out(vty, " (NSF passive)");
11634 }
11635 vty_out(vty, "\n");
11636
11637 /* read timer */
11638 vty_out(vty, " Last read %s",
11639 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
11640 NULL));
11641 vty_out(vty, ", Last write %s\n",
11642 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
11643 NULL));
11644
11645 /* Configured timer values. */
11646 vty_out(vty,
11647 " Hold time is %d, keepalive interval is %d seconds\n",
11648 p->v_holdtime, p->v_keepalive);
b90a8e13 11649 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 11650 vty_out(vty, " Configured hold time is %d",
11651 p->holdtime);
11652 vty_out(vty, ", keepalive interval is %d seconds\n",
11653 p->keepalive);
5d5393b9
DL
11654 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
11655 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
11656 vty_out(vty, " Configured hold time is %d",
11657 bgp->default_holdtime);
11658 vty_out(vty, ", keepalive interval is %d seconds\n",
11659 bgp->default_keepalive);
d62a17ae 11660 }
11661 }
11662 /* Capability. */
11663 if (p->status == Established) {
11664 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
11665 || p->afc_recv[AFI_IP][SAFI_UNICAST]
11666 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
11667 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
11668 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
11669 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
11670 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
11671 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
11672 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
11673 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
11674 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
11675 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 11676 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
11677 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 11678 || p->afc_adv[AFI_IP][SAFI_ENCAP]
11679 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 11680 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
11681 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 11682 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
11683 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
11684 if (use_json) {
11685 json_object *json_cap = NULL;
11686
11687 json_cap = json_object_new_object();
11688
11689 /* AS4 */
11690 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
11691 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
11692 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
11693 && CHECK_FLAG(p->cap,
11694 PEER_CAP_AS4_RCV))
11695 json_object_string_add(
11696 json_cap, "4byteAs",
11697 "advertisedAndReceived");
11698 else if (CHECK_FLAG(p->cap,
11699 PEER_CAP_AS4_ADV))
11700 json_object_string_add(
11701 json_cap, "4byteAs",
11702 "advertised");
11703 else if (CHECK_FLAG(p->cap,
11704 PEER_CAP_AS4_RCV))
11705 json_object_string_add(
11706 json_cap, "4byteAs",
11707 "received");
11708 }
11709
11710 /* AddPath */
11711 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
11712 || CHECK_FLAG(p->cap,
11713 PEER_CAP_ADDPATH_ADV)) {
11714 json_object *json_add = NULL;
11715 const char *print_store;
11716
11717 json_add = json_object_new_object();
11718
05c7a1cc
QY
11719 FOREACH_AFI_SAFI (afi, safi) {
11720 json_object *json_sub = NULL;
11721 json_sub =
11722 json_object_new_object();
5cb5f4d0
DD
11723 print_store = get_afi_safi_str(
11724 afi, safi, true);
d62a17ae 11725
05c7a1cc
QY
11726 if (CHECK_FLAG(
11727 p->af_cap[afi]
11728 [safi],
11729 PEER_CAP_ADDPATH_AF_TX_ADV)
11730 || CHECK_FLAG(
11731 p->af_cap[afi]
11732 [safi],
11733 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 11734 if (CHECK_FLAG(
11735 p->af_cap
11736 [afi]
11737 [safi],
11738 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 11739 && CHECK_FLAG(
d62a17ae 11740 p->af_cap
11741 [afi]
11742 [safi],
05c7a1cc
QY
11743 PEER_CAP_ADDPATH_AF_TX_RCV))
11744 json_object_boolean_true_add(
11745 json_sub,
11746 "txAdvertisedAndReceived");
11747 else if (
11748 CHECK_FLAG(
11749 p->af_cap
11750 [afi]
11751 [safi],
11752 PEER_CAP_ADDPATH_AF_TX_ADV))
11753 json_object_boolean_true_add(
11754 json_sub,
11755 "txAdvertised");
11756 else if (
11757 CHECK_FLAG(
11758 p->af_cap
11759 [afi]
11760 [safi],
11761 PEER_CAP_ADDPATH_AF_TX_RCV))
11762 json_object_boolean_true_add(
11763 json_sub,
11764 "txReceived");
11765 }
d62a17ae 11766
05c7a1cc
QY
11767 if (CHECK_FLAG(
11768 p->af_cap[afi]
11769 [safi],
11770 PEER_CAP_ADDPATH_AF_RX_ADV)
11771 || CHECK_FLAG(
11772 p->af_cap[afi]
11773 [safi],
11774 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 11775 if (CHECK_FLAG(
11776 p->af_cap
11777 [afi]
11778 [safi],
11779 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 11780 && CHECK_FLAG(
d62a17ae 11781 p->af_cap
11782 [afi]
11783 [safi],
11784 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
11785 json_object_boolean_true_add(
11786 json_sub,
11787 "rxAdvertisedAndReceived");
11788 else if (
11789 CHECK_FLAG(
11790 p->af_cap
11791 [afi]
11792 [safi],
11793 PEER_CAP_ADDPATH_AF_RX_ADV))
11794 json_object_boolean_true_add(
11795 json_sub,
11796 "rxAdvertised");
11797 else if (
11798 CHECK_FLAG(
11799 p->af_cap
11800 [afi]
11801 [safi],
11802 PEER_CAP_ADDPATH_AF_RX_RCV))
11803 json_object_boolean_true_add(
11804 json_sub,
11805 "rxReceived");
d62a17ae 11806 }
11807
05c7a1cc
QY
11808 if (CHECK_FLAG(
11809 p->af_cap[afi]
11810 [safi],
11811 PEER_CAP_ADDPATH_AF_TX_ADV)
11812 || CHECK_FLAG(
11813 p->af_cap[afi]
11814 [safi],
11815 PEER_CAP_ADDPATH_AF_TX_RCV)
11816 || CHECK_FLAG(
11817 p->af_cap[afi]
11818 [safi],
11819 PEER_CAP_ADDPATH_AF_RX_ADV)
11820 || CHECK_FLAG(
11821 p->af_cap[afi]
11822 [safi],
11823 PEER_CAP_ADDPATH_AF_RX_RCV))
11824 json_object_object_add(
11825 json_add,
11826 print_store,
11827 json_sub);
11828 else
11829 json_object_free(
11830 json_sub);
11831 }
11832
d62a17ae 11833 json_object_object_add(
11834 json_cap, "addPath", json_add);
11835 }
11836
11837 /* Dynamic */
11838 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
11839 || CHECK_FLAG(p->cap,
11840 PEER_CAP_DYNAMIC_ADV)) {
11841 if (CHECK_FLAG(p->cap,
11842 PEER_CAP_DYNAMIC_ADV)
11843 && CHECK_FLAG(p->cap,
11844 PEER_CAP_DYNAMIC_RCV))
11845 json_object_string_add(
11846 json_cap, "dynamic",
11847 "advertisedAndReceived");
11848 else if (CHECK_FLAG(
11849 p->cap,
11850 PEER_CAP_DYNAMIC_ADV))
11851 json_object_string_add(
11852 json_cap, "dynamic",
11853 "advertised");
11854 else if (CHECK_FLAG(
11855 p->cap,
11856 PEER_CAP_DYNAMIC_RCV))
11857 json_object_string_add(
11858 json_cap, "dynamic",
11859 "received");
11860 }
11861
11862 /* Extended nexthop */
11863 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
11864 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
11865 json_object *json_nxt = NULL;
11866 const char *print_store;
11867
11868
11869 if (CHECK_FLAG(p->cap,
11870 PEER_CAP_ENHE_ADV)
11871 && CHECK_FLAG(p->cap,
11872 PEER_CAP_ENHE_RCV))
11873 json_object_string_add(
11874 json_cap,
11875 "extendedNexthop",
11876 "advertisedAndReceived");
11877 else if (CHECK_FLAG(p->cap,
11878 PEER_CAP_ENHE_ADV))
11879 json_object_string_add(
11880 json_cap,
11881 "extendedNexthop",
11882 "advertised");
11883 else if (CHECK_FLAG(p->cap,
11884 PEER_CAP_ENHE_RCV))
11885 json_object_string_add(
11886 json_cap,
11887 "extendedNexthop",
11888 "received");
11889
11890 if (CHECK_FLAG(p->cap,
11891 PEER_CAP_ENHE_RCV)) {
11892 json_nxt =
11893 json_object_new_object();
11894
11895 for (safi = SAFI_UNICAST;
11896 safi < SAFI_MAX; safi++) {
11897 if (CHECK_FLAG(
11898 p->af_cap
11899 [AFI_IP]
11900 [safi],
11901 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 11902 print_store = get_afi_safi_str(
d62a17ae 11903 AFI_IP,
5cb5f4d0 11904 safi, true);
d62a17ae 11905 json_object_string_add(
11906 json_nxt,
11907 print_store,
54f29523 11908 "recieved"); /* misspelled for compatibility */
d62a17ae 11909 }
11910 }
11911 json_object_object_add(
11912 json_cap,
11913 "extendedNexthopFamililesByPeer",
11914 json_nxt);
11915 }
11916 }
11917
11918 /* Route Refresh */
11919 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
11920 || CHECK_FLAG(p->cap,
11921 PEER_CAP_REFRESH_NEW_RCV)
11922 || CHECK_FLAG(p->cap,
11923 PEER_CAP_REFRESH_OLD_RCV)) {
11924 if (CHECK_FLAG(p->cap,
11925 PEER_CAP_REFRESH_ADV)
11926 && (CHECK_FLAG(
11927 p->cap,
11928 PEER_CAP_REFRESH_NEW_RCV)
11929 || CHECK_FLAG(
11930 p->cap,
11931 PEER_CAP_REFRESH_OLD_RCV))) {
11932 if (CHECK_FLAG(
11933 p->cap,
11934 PEER_CAP_REFRESH_OLD_RCV)
11935 && CHECK_FLAG(
11936 p->cap,
11937 PEER_CAP_REFRESH_NEW_RCV))
11938 json_object_string_add(
11939 json_cap,
11940 "routeRefresh",
11941 "advertisedAndReceivedOldNew");
11942 else {
11943 if (CHECK_FLAG(
11944 p->cap,
11945 PEER_CAP_REFRESH_OLD_RCV))
11946 json_object_string_add(
11947 json_cap,
11948 "routeRefresh",
11949 "advertisedAndReceivedOld");
11950 else
11951 json_object_string_add(
11952 json_cap,
11953 "routeRefresh",
11954 "advertisedAndReceivedNew");
11955 }
11956 } else if (
11957 CHECK_FLAG(
11958 p->cap,
11959 PEER_CAP_REFRESH_ADV))
11960 json_object_string_add(
11961 json_cap,
11962 "routeRefresh",
11963 "advertised");
11964 else if (
11965 CHECK_FLAG(
11966 p->cap,
11967 PEER_CAP_REFRESH_NEW_RCV)
11968 || CHECK_FLAG(
11969 p->cap,
11970 PEER_CAP_REFRESH_OLD_RCV))
11971 json_object_string_add(
11972 json_cap,
11973 "routeRefresh",
11974 "received");
11975 }
11976
11977 /* Multiprotocol Extensions */
11978 json_object *json_multi = NULL;
11979 json_multi = json_object_new_object();
11980
05c7a1cc
QY
11981 FOREACH_AFI_SAFI (afi, safi) {
11982 if (p->afc_adv[afi][safi]
11983 || p->afc_recv[afi][safi]) {
11984 json_object *json_exten = NULL;
11985 json_exten =
11986 json_object_new_object();
11987
d62a17ae 11988 if (p->afc_adv[afi][safi]
05c7a1cc
QY
11989 && p->afc_recv[afi][safi])
11990 json_object_boolean_true_add(
11991 json_exten,
11992 "advertisedAndReceived");
11993 else if (p->afc_adv[afi][safi])
11994 json_object_boolean_true_add(
11995 json_exten,
11996 "advertised");
11997 else if (p->afc_recv[afi][safi])
11998 json_object_boolean_true_add(
11999 json_exten,
12000 "received");
d62a17ae 12001
05c7a1cc
QY
12002 json_object_object_add(
12003 json_multi,
5cb5f4d0
DD
12004 get_afi_safi_str(afi,
12005 safi,
12006 true),
05c7a1cc 12007 json_exten);
d62a17ae 12008 }
12009 }
12010 json_object_object_add(
12011 json_cap, "multiprotocolExtensions",
12012 json_multi);
12013
d77114b7 12014 /* Hostname capabilities */
60466a63 12015 json_object *json_hname = NULL;
d77114b7
MK
12016
12017 json_hname = json_object_new_object();
12018
12019 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
12020 json_object_string_add(
60466a63
QY
12021 json_hname, "advHostName",
12022 bgp->peer_self->hostname
12023 ? bgp->peer_self
12024 ->hostname
d77114b7
MK
12025 : "n/a");
12026 json_object_string_add(
60466a63
QY
12027 json_hname, "advDomainName",
12028 bgp->peer_self->domainname
12029 ? bgp->peer_self
12030 ->domainname
d77114b7
MK
12031 : "n/a");
12032 }
12033
12034
12035 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
12036 json_object_string_add(
60466a63
QY
12037 json_hname, "rcvHostName",
12038 p->hostname ? p->hostname
12039 : "n/a");
d77114b7 12040 json_object_string_add(
60466a63
QY
12041 json_hname, "rcvDomainName",
12042 p->domainname ? p->domainname
12043 : "n/a");
d77114b7
MK
12044 }
12045
60466a63 12046 json_object_object_add(json_cap, "hostName",
d77114b7
MK
12047 json_hname);
12048
d62a17ae 12049 /* Gracefull Restart */
12050 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12051 || CHECK_FLAG(p->cap,
12052 PEER_CAP_RESTART_ADV)) {
12053 if (CHECK_FLAG(p->cap,
12054 PEER_CAP_RESTART_ADV)
12055 && CHECK_FLAG(p->cap,
12056 PEER_CAP_RESTART_RCV))
12057 json_object_string_add(
12058 json_cap,
12059 "gracefulRestart",
12060 "advertisedAndReceived");
12061 else if (CHECK_FLAG(
12062 p->cap,
12063 PEER_CAP_RESTART_ADV))
12064 json_object_string_add(
12065 json_cap,
12066 "gracefulRestartCapability",
12067 "advertised");
12068 else if (CHECK_FLAG(
12069 p->cap,
12070 PEER_CAP_RESTART_RCV))
12071 json_object_string_add(
12072 json_cap,
12073 "gracefulRestartCapability",
12074 "received");
12075
12076 if (CHECK_FLAG(p->cap,
12077 PEER_CAP_RESTART_RCV)) {
12078 int restart_af_count = 0;
12079 json_object *json_restart =
12080 NULL;
12081 json_restart =
12082 json_object_new_object();
12083
12084 json_object_int_add(
12085 json_cap,
12086 "gracefulRestartRemoteTimerMsecs",
12087 p->v_gr_restart * 1000);
12088
05c7a1cc
QY
12089 FOREACH_AFI_SAFI (afi, safi) {
12090 if (CHECK_FLAG(
12091 p->af_cap
12092 [afi]
12093 [safi],
12094 PEER_CAP_RESTART_AF_RCV)) {
12095 json_object *
12096 json_sub =
12097 NULL;
12098 json_sub =
12099 json_object_new_object();
12100
d62a17ae 12101 if (CHECK_FLAG(
12102 p->af_cap
12103 [afi]
12104 [safi],
05c7a1cc
QY
12105 PEER_CAP_RESTART_AF_PRESERVE_RCV))
12106 json_object_boolean_true_add(
12107 json_sub,
12108 "preserved");
12109 restart_af_count++;
12110 json_object_object_add(
12111 json_restart,
5cb5f4d0 12112 get_afi_safi_str(
05c7a1cc 12113 afi,
5cb5f4d0
DD
12114 safi,
12115 true),
05c7a1cc 12116 json_sub);
d62a17ae 12117 }
12118 }
12119 if (!restart_af_count) {
12120 json_object_string_add(
12121 json_cap,
12122 "addressFamiliesByPeer",
12123 "none");
12124 json_object_free(
12125 json_restart);
12126 } else
12127 json_object_object_add(
12128 json_cap,
12129 "addressFamiliesByPeer",
12130 json_restart);
12131 }
12132 }
12133 json_object_object_add(json_neigh,
12134 "neighborCapabilities",
12135 json_cap);
12136 } else {
12137 vty_out(vty, " Neighbor capabilities:\n");
12138
12139 /* AS4 */
12140 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12141 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12142 vty_out(vty, " 4 Byte AS:");
12143 if (CHECK_FLAG(p->cap,
12144 PEER_CAP_AS4_ADV))
12145 vty_out(vty, " advertised");
12146 if (CHECK_FLAG(p->cap,
12147 PEER_CAP_AS4_RCV))
12148 vty_out(vty, " %sreceived",
12149 CHECK_FLAG(
12150 p->cap,
12151 PEER_CAP_AS4_ADV)
12152 ? "and "
12153 : "");
12154 vty_out(vty, "\n");
12155 }
12156
12157 /* AddPath */
12158 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12159 || CHECK_FLAG(p->cap,
12160 PEER_CAP_ADDPATH_ADV)) {
12161 vty_out(vty, " AddPath:\n");
12162
05c7a1cc
QY
12163 FOREACH_AFI_SAFI (afi, safi) {
12164 if (CHECK_FLAG(
12165 p->af_cap[afi]
12166 [safi],
12167 PEER_CAP_ADDPATH_AF_TX_ADV)
12168 || CHECK_FLAG(
12169 p->af_cap[afi]
12170 [safi],
12171 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12172 vty_out(vty,
12173 " %s: TX ",
5cb5f4d0 12174 get_afi_safi_str(
05c7a1cc 12175 afi,
5cb5f4d0
DD
12176 safi,
12177 false));
05c7a1cc 12178
d62a17ae 12179 if (CHECK_FLAG(
12180 p->af_cap
12181 [afi]
12182 [safi],
05c7a1cc 12183 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 12184 vty_out(vty,
05c7a1cc 12185 "advertised %s",
5cb5f4d0 12186 get_afi_safi_str(
d62a17ae 12187 afi,
5cb5f4d0
DD
12188 safi,
12189 false));
d62a17ae 12190
05c7a1cc
QY
12191 if (CHECK_FLAG(
12192 p->af_cap
12193 [afi]
12194 [safi],
12195 PEER_CAP_ADDPATH_AF_TX_RCV))
12196 vty_out(vty,
12197 "%sreceived",
12198 CHECK_FLAG(
12199 p->af_cap
12200 [afi]
12201 [safi],
12202 PEER_CAP_ADDPATH_AF_TX_ADV)
12203 ? " and "
12204 : "");
d62a17ae 12205
05c7a1cc
QY
12206 vty_out(vty, "\n");
12207 }
d62a17ae 12208
05c7a1cc
QY
12209 if (CHECK_FLAG(
12210 p->af_cap[afi]
12211 [safi],
12212 PEER_CAP_ADDPATH_AF_RX_ADV)
12213 || CHECK_FLAG(
12214 p->af_cap[afi]
12215 [safi],
12216 PEER_CAP_ADDPATH_AF_RX_RCV)) {
12217 vty_out(vty,
12218 " %s: RX ",
5cb5f4d0 12219 get_afi_safi_str(
05c7a1cc 12220 afi,
5cb5f4d0
DD
12221 safi,
12222 false));
d62a17ae 12223
12224 if (CHECK_FLAG(
12225 p->af_cap
12226 [afi]
12227 [safi],
05c7a1cc 12228 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 12229 vty_out(vty,
05c7a1cc 12230 "advertised %s",
5cb5f4d0 12231 get_afi_safi_str(
d62a17ae 12232 afi,
5cb5f4d0
DD
12233 safi,
12234 false));
d62a17ae 12235
05c7a1cc
QY
12236 if (CHECK_FLAG(
12237 p->af_cap
12238 [afi]
12239 [safi],
12240 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 12241 vty_out(vty,
05c7a1cc
QY
12242 "%sreceived",
12243 CHECK_FLAG(
12244 p->af_cap
12245 [afi]
12246 [safi],
12247 PEER_CAP_ADDPATH_AF_RX_ADV)
12248 ? " and "
12249 : "");
12250
12251 vty_out(vty, "\n");
d62a17ae 12252 }
05c7a1cc 12253 }
d62a17ae 12254 }
12255
12256 /* Dynamic */
12257 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
12258 || CHECK_FLAG(p->cap,
12259 PEER_CAP_DYNAMIC_ADV)) {
12260 vty_out(vty, " Dynamic:");
12261 if (CHECK_FLAG(p->cap,
12262 PEER_CAP_DYNAMIC_ADV))
12263 vty_out(vty, " advertised");
12264 if (CHECK_FLAG(p->cap,
12265 PEER_CAP_DYNAMIC_RCV))
12266 vty_out(vty, " %sreceived",
12267 CHECK_FLAG(
12268 p->cap,
12269 PEER_CAP_DYNAMIC_ADV)
12270 ? "and "
12271 : "");
12272 vty_out(vty, "\n");
12273 }
12274
12275 /* Extended nexthop */
12276 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
12277 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
12278 vty_out(vty, " Extended nexthop:");
12279 if (CHECK_FLAG(p->cap,
12280 PEER_CAP_ENHE_ADV))
12281 vty_out(vty, " advertised");
12282 if (CHECK_FLAG(p->cap,
12283 PEER_CAP_ENHE_RCV))
12284 vty_out(vty, " %sreceived",
12285 CHECK_FLAG(
12286 p->cap,
12287 PEER_CAP_ENHE_ADV)
12288 ? "and "
12289 : "");
12290 vty_out(vty, "\n");
12291
12292 if (CHECK_FLAG(p->cap,
12293 PEER_CAP_ENHE_RCV)) {
12294 vty_out(vty,
12295 " Address families by peer:\n ");
12296 for (safi = SAFI_UNICAST;
12297 safi < SAFI_MAX; safi++)
12298 if (CHECK_FLAG(
12299 p->af_cap
12300 [AFI_IP]
12301 [safi],
12302 PEER_CAP_ENHE_AF_RCV))
12303 vty_out(vty,
12304 " %s\n",
5cb5f4d0 12305 get_afi_safi_str(
d62a17ae 12306 AFI_IP,
5cb5f4d0
DD
12307 safi,
12308 false));
d62a17ae 12309 }
12310 }
12311
12312 /* Route Refresh */
12313 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
12314 || CHECK_FLAG(p->cap,
12315 PEER_CAP_REFRESH_NEW_RCV)
12316 || CHECK_FLAG(p->cap,
12317 PEER_CAP_REFRESH_OLD_RCV)) {
12318 vty_out(vty, " Route refresh:");
12319 if (CHECK_FLAG(p->cap,
12320 PEER_CAP_REFRESH_ADV))
12321 vty_out(vty, " advertised");
12322 if (CHECK_FLAG(p->cap,
12323 PEER_CAP_REFRESH_NEW_RCV)
12324 || CHECK_FLAG(
12325 p->cap,
12326 PEER_CAP_REFRESH_OLD_RCV))
12327 vty_out(vty, " %sreceived(%s)",
12328 CHECK_FLAG(
12329 p->cap,
12330 PEER_CAP_REFRESH_ADV)
12331 ? "and "
12332 : "",
12333 (CHECK_FLAG(
12334 p->cap,
12335 PEER_CAP_REFRESH_OLD_RCV)
12336 && CHECK_FLAG(
12337 p->cap,
12338 PEER_CAP_REFRESH_NEW_RCV))
12339 ? "old & new"
12340 : CHECK_FLAG(
12341 p->cap,
12342 PEER_CAP_REFRESH_OLD_RCV)
12343 ? "old"
12344 : "new");
12345
12346 vty_out(vty, "\n");
12347 }
12348
12349 /* Multiprotocol Extensions */
05c7a1cc
QY
12350 FOREACH_AFI_SAFI (afi, safi)
12351 if (p->afc_adv[afi][safi]
12352 || p->afc_recv[afi][safi]) {
12353 vty_out(vty,
12354 " Address Family %s:",
5cb5f4d0
DD
12355 get_afi_safi_str(
12356 afi,
12357 safi,
12358 false));
05c7a1cc 12359 if (p->afc_adv[afi][safi])
d62a17ae 12360 vty_out(vty,
05c7a1cc
QY
12361 " advertised");
12362 if (p->afc_recv[afi][safi])
12363 vty_out(vty,
12364 " %sreceived",
12365 p->afc_adv[afi]
12366 [safi]
12367 ? "and "
12368 : "");
12369 vty_out(vty, "\n");
12370 }
d62a17ae 12371
12372 /* Hostname capability */
60466a63 12373 vty_out(vty, " Hostname Capability:");
d77114b7
MK
12374
12375 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
12376 vty_out(vty,
12377 " advertised (name: %s,domain name: %s)",
60466a63
QY
12378 bgp->peer_self->hostname
12379 ? bgp->peer_self
12380 ->hostname
d77114b7 12381 : "n/a",
60466a63
QY
12382 bgp->peer_self->domainname
12383 ? bgp->peer_self
12384 ->domainname
d77114b7
MK
12385 : "n/a");
12386 } else {
12387 vty_out(vty, " not advertised");
d62a17ae 12388 }
12389
d77114b7 12390 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
12391 vty_out(vty,
12392 " received (name: %s,domain name: %s)",
60466a63
QY
12393 p->hostname ? p->hostname
12394 : "n/a",
12395 p->domainname ? p->domainname
12396 : "n/a");
d77114b7
MK
12397 } else {
12398 vty_out(vty, " not received");
12399 }
12400
12401 vty_out(vty, "\n");
12402
61bfbd51 12403 /* Graceful Restart */
d62a17ae 12404 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
12405 || CHECK_FLAG(p->cap,
12406 PEER_CAP_RESTART_ADV)) {
12407 vty_out(vty,
61bfbd51 12408 " Graceful Restart Capability:");
d62a17ae 12409 if (CHECK_FLAG(p->cap,
12410 PEER_CAP_RESTART_ADV))
12411 vty_out(vty, " advertised");
12412 if (CHECK_FLAG(p->cap,
12413 PEER_CAP_RESTART_RCV))
12414 vty_out(vty, " %sreceived",
12415 CHECK_FLAG(
12416 p->cap,
12417 PEER_CAP_RESTART_ADV)
12418 ? "and "
12419 : "");
12420 vty_out(vty, "\n");
12421
12422 if (CHECK_FLAG(p->cap,
12423 PEER_CAP_RESTART_RCV)) {
12424 int restart_af_count = 0;
12425
12426 vty_out(vty,
12427 " Remote Restart timer is %d seconds\n",
12428 p->v_gr_restart);
12429 vty_out(vty,
12430 " Address families by peer:\n ");
12431
05c7a1cc
QY
12432 FOREACH_AFI_SAFI (afi, safi)
12433 if (CHECK_FLAG(
12434 p->af_cap
12435 [afi]
12436 [safi],
12437 PEER_CAP_RESTART_AF_RCV)) {
12438 vty_out(vty,
12439 "%s%s(%s)",
12440 restart_af_count
12441 ? ", "
12442 : "",
5cb5f4d0 12443 get_afi_safi_str(
05c7a1cc 12444 afi,
5cb5f4d0
DD
12445 safi,
12446 false),
05c7a1cc
QY
12447 CHECK_FLAG(
12448 p->af_cap
12449 [afi]
12450 [safi],
12451 PEER_CAP_RESTART_AF_PRESERVE_RCV)
12452 ? "preserved"
12453 : "not preserved");
12454 restart_af_count++;
12455 }
d62a17ae 12456 if (!restart_af_count)
12457 vty_out(vty, "none");
12458 vty_out(vty, "\n");
12459 }
2986cac2 12460 } /* Gracefull Restart */
d62a17ae 12461 }
12462 }
12463 }
12464
12465 /* graceful restart information */
d62a17ae 12466 json_object *json_grace = NULL;
12467 json_object *json_grace_send = NULL;
12468 json_object *json_grace_recv = NULL;
12469 int eor_send_af_count = 0;
12470 int eor_receive_af_count = 0;
12471
12472 if (use_json) {
12473 json_grace = json_object_new_object();
12474 json_grace_send = json_object_new_object();
12475 json_grace_recv = json_object_new_object();
12476
36235319
QY
12477 if ((p->status == Established)
12478 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
12479 FOREACH_AFI_SAFI (afi, safi) {
12480 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 12481 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
12482 json_object_boolean_true_add(
12483 json_grace_send,
5cb5f4d0
DD
12484 get_afi_safi_str(afi,
12485 safi,
12486 true));
05c7a1cc 12487 eor_send_af_count++;
d62a17ae 12488 }
12489 }
05c7a1cc
QY
12490 FOREACH_AFI_SAFI (afi, safi) {
12491 if (CHECK_FLAG(
36235319
QY
12492 p->af_sflags[afi][safi],
12493 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
12494 json_object_boolean_true_add(
12495 json_grace_recv,
5cb5f4d0
DD
12496 get_afi_safi_str(afi,
12497 safi,
12498 true));
05c7a1cc 12499 eor_receive_af_count++;
d62a17ae 12500 }
12501 }
12502 }
36235319
QY
12503 json_object_object_add(json_grace, "endOfRibSend",
12504 json_grace_send);
12505 json_object_object_add(json_grace, "endOfRibRecv",
12506 json_grace_recv);
d62a17ae 12507
d62a17ae 12508
12509 if (p->t_gr_restart)
12510 json_object_int_add(json_grace,
12511 "gracefulRestartTimerMsecs",
12512 thread_timer_remain_second(
12513 p->t_gr_restart)
12514 * 1000);
12515
12516 if (p->t_gr_stale)
12517 json_object_int_add(
12518 json_grace,
12519 "gracefulStalepathTimerMsecs",
12520 thread_timer_remain_second(
12521 p->t_gr_stale)
12522 * 1000);
2986cac2 12523 /* more gr info in new format */
12524 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 12525 json_grace);
d62a17ae 12526 json_object_object_add(
12527 json_neigh, "gracefulRestartInfo", json_grace);
12528 } else {
2089dd80 12529 vty_out(vty, " Graceful restart information:\n");
36235319
QY
12530 if ((p->status == Established)
12531 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 12532
d62a17ae 12533 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
12534 FOREACH_AFI_SAFI (afi, safi) {
12535 if (CHECK_FLAG(p->af_sflags[afi][safi],
12536 PEER_STATUS_EOR_SEND)) {
12537 vty_out(vty, "%s%s",
12538 eor_send_af_count ? ", "
12539 : "",
36235319
QY
12540 get_afi_safi_str(
12541 afi, safi,
12542 false));
05c7a1cc 12543 eor_send_af_count++;
d62a17ae 12544 }
12545 }
12546 vty_out(vty, "\n");
12547 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
12548 FOREACH_AFI_SAFI (afi, safi) {
12549 if (CHECK_FLAG(
12550 p->af_sflags[afi][safi],
12551 PEER_STATUS_EOR_RECEIVED)) {
12552 vty_out(vty, "%s%s",
12553 eor_receive_af_count
12554 ? ", "
12555 : "",
5cb5f4d0
DD
12556 get_afi_safi_str(afi,
12557 safi,
12558 false));
05c7a1cc 12559 eor_receive_af_count++;
d62a17ae 12560 }
12561 }
12562 vty_out(vty, "\n");
12563 }
12564
12565 if (p->t_gr_restart)
12566 vty_out(vty,
12567 " The remaining time of restart timer is %ld\n",
12568 thread_timer_remain_second(
12569 p->t_gr_restart));
12570
12571 if (p->t_gr_stale)
12572 vty_out(vty,
12573 " The remaining time of stalepath timer is %ld\n",
12574 thread_timer_remain_second(
12575 p->t_gr_stale));
2986cac2 12576
12577 /* more gr info in new format */
12578 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 12579 }
2986cac2 12580
d62a17ae 12581 if (use_json) {
12582 json_object *json_stat = NULL;
12583 json_stat = json_object_new_object();
12584 /* Packet counts. */
43aa5965
QY
12585
12586 atomic_size_t outq_count, inq_count;
12587 outq_count = atomic_load_explicit(&p->obuf->count,
12588 memory_order_relaxed);
12589 inq_count = atomic_load_explicit(&p->ibuf->count,
12590 memory_order_relaxed);
12591
12592 json_object_int_add(json_stat, "depthInq",
12593 (unsigned long)inq_count);
d62a17ae 12594 json_object_int_add(json_stat, "depthOutq",
43aa5965 12595 (unsigned long)outq_count);
0112e9e0
QY
12596 json_object_int_add(json_stat, "opensSent",
12597 atomic_load_explicit(&p->open_out,
12598 memory_order_relaxed));
12599 json_object_int_add(json_stat, "opensRecv",
12600 atomic_load_explicit(&p->open_in,
12601 memory_order_relaxed));
d62a17ae 12602 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
12603 atomic_load_explicit(&p->notify_out,
12604 memory_order_relaxed));
d62a17ae 12605 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
12606 atomic_load_explicit(&p->notify_in,
12607 memory_order_relaxed));
12608 json_object_int_add(json_stat, "updatesSent",
12609 atomic_load_explicit(&p->update_out,
12610 memory_order_relaxed));
12611 json_object_int_add(json_stat, "updatesRecv",
12612 atomic_load_explicit(&p->update_in,
12613 memory_order_relaxed));
d62a17ae 12614 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
12615 atomic_load_explicit(&p->keepalive_out,
12616 memory_order_relaxed));
d62a17ae 12617 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
12618 atomic_load_explicit(&p->keepalive_in,
12619 memory_order_relaxed));
d62a17ae 12620 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
12621 atomic_load_explicit(&p->refresh_out,
12622 memory_order_relaxed));
d62a17ae 12623 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
12624 atomic_load_explicit(&p->refresh_in,
12625 memory_order_relaxed));
d62a17ae 12626 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
12627 atomic_load_explicit(&p->dynamic_cap_out,
12628 memory_order_relaxed));
d62a17ae 12629 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
12630 atomic_load_explicit(&p->dynamic_cap_in,
12631 memory_order_relaxed));
12632 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
12633 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 12634 json_object_object_add(json_neigh, "messageStats", json_stat);
12635 } else {
43aa5965
QY
12636 atomic_size_t outq_count, inq_count;
12637 outq_count = atomic_load_explicit(&p->obuf->count,
12638 memory_order_relaxed);
12639 inq_count = atomic_load_explicit(&p->ibuf->count,
12640 memory_order_relaxed);
12641
d62a17ae 12642 /* Packet counts. */
12643 vty_out(vty, " Message statistics:\n");
43aa5965
QY
12644 vty_out(vty, " Inq depth is %zu\n", inq_count);
12645 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 12646 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
12647 vty_out(vty, " Opens: %10d %10d\n",
12648 atomic_load_explicit(&p->open_out,
12649 memory_order_relaxed),
12650 atomic_load_explicit(&p->open_in,
12651 memory_order_relaxed));
12652 vty_out(vty, " Notifications: %10d %10d\n",
12653 atomic_load_explicit(&p->notify_out,
12654 memory_order_relaxed),
12655 atomic_load_explicit(&p->notify_in,
12656 memory_order_relaxed));
12657 vty_out(vty, " Updates: %10d %10d\n",
12658 atomic_load_explicit(&p->update_out,
12659 memory_order_relaxed),
12660 atomic_load_explicit(&p->update_in,
12661 memory_order_relaxed));
12662 vty_out(vty, " Keepalives: %10d %10d\n",
12663 atomic_load_explicit(&p->keepalive_out,
12664 memory_order_relaxed),
12665 atomic_load_explicit(&p->keepalive_in,
12666 memory_order_relaxed));
12667 vty_out(vty, " Route Refresh: %10d %10d\n",
12668 atomic_load_explicit(&p->refresh_out,
12669 memory_order_relaxed),
12670 atomic_load_explicit(&p->refresh_in,
12671 memory_order_relaxed));
d62a17ae 12672 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
12673 atomic_load_explicit(&p->dynamic_cap_out,
12674 memory_order_relaxed),
12675 atomic_load_explicit(&p->dynamic_cap_in,
12676 memory_order_relaxed));
12677 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
12678 PEER_TOTAL_RX(p));
d62a17ae 12679 }
12680
12681 if (use_json) {
12682 /* advertisement-interval */
12683 json_object_int_add(json_neigh,
12684 "minBtwnAdvertisementRunsTimerMsecs",
12685 p->v_routeadv * 1000);
12686
12687 /* Update-source. */
12688 if (p->update_if || p->update_source) {
12689 if (p->update_if)
12690 json_object_string_add(json_neigh,
12691 "updateSource",
12692 p->update_if);
12693 else if (p->update_source)
12694 json_object_string_add(
12695 json_neigh, "updateSource",
12696 sockunion2str(p->update_source, buf1,
12697 SU_ADDRSTRLEN));
12698 }
12699 } else {
12700 /* advertisement-interval */
12701 vty_out(vty,
12702 " Minimum time between advertisement runs is %d seconds\n",
12703 p->v_routeadv);
12704
12705 /* Update-source. */
12706 if (p->update_if || p->update_source) {
12707 vty_out(vty, " Update source is ");
12708 if (p->update_if)
12709 vty_out(vty, "%s", p->update_if);
12710 else if (p->update_source)
12711 vty_out(vty, "%s",
12712 sockunion2str(p->update_source, buf1,
12713 SU_ADDRSTRLEN));
12714 vty_out(vty, "\n");
12715 }
12716
12717 vty_out(vty, "\n");
12718 }
12719
12720 /* Address Family Information */
12721 json_object *json_hold = NULL;
12722
12723 if (use_json)
12724 json_hold = json_object_new_object();
12725
05c7a1cc
QY
12726 FOREACH_AFI_SAFI (afi, safi)
12727 if (p->afc[afi][safi])
12728 bgp_show_peer_afi(vty, p, afi, safi, use_json,
12729 json_hold);
d62a17ae 12730
12731 if (use_json) {
12732 json_object_object_add(json_neigh, "addressFamilyInfo",
12733 json_hold);
12734 json_object_int_add(json_neigh, "connectionsEstablished",
12735 p->established);
12736 json_object_int_add(json_neigh, "connectionsDropped",
12737 p->dropped);
12738 } else
12739 vty_out(vty, " Connections established %d; dropped %d\n",
12740 p->established, p->dropped);
12741
12742 if (!p->last_reset) {
12743 if (use_json)
12744 json_object_string_add(json_neigh, "lastReset",
12745 "never");
12746 else
12747 vty_out(vty, " Last reset never\n");
12748 } else {
12749 if (use_json) {
12750 time_t uptime;
a2700b50 12751 struct tm tm;
d62a17ae 12752
12753 uptime = bgp_clock();
12754 uptime -= p->resettime;
a2700b50
MS
12755 gmtime_r(&uptime, &tm);
12756
d62a17ae 12757 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
12758 (tm.tm_sec * 1000)
12759 + (tm.tm_min * 60000)
12760 + (tm.tm_hour * 3600000));
3577f1c5 12761 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 12762 } else {
12763 vty_out(vty, " Last reset %s, ",
12764 peer_uptime(p->resettime, timebuf,
12765 BGP_UPTIME_LEN, 0, NULL));
12766
3577f1c5 12767 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 12768 if (p->last_reset_cause_size) {
12769 msg = p->last_reset_cause;
12770 vty_out(vty,
12771 " Message received that caused BGP to send a NOTIFICATION:\n ");
12772 for (i = 1; i <= p->last_reset_cause_size;
12773 i++) {
12774 vty_out(vty, "%02X", *msg++);
12775
12776 if (i != p->last_reset_cause_size) {
12777 if (i % 16 == 0) {
12778 vty_out(vty, "\n ");
12779 } else if (i % 4 == 0) {
12780 vty_out(vty, " ");
12781 }
12782 }
12783 }
12784 vty_out(vty, "\n");
12785 }
12786 }
12787 }
12788
12789 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
12790 if (use_json)
12791 json_object_boolean_true_add(json_neigh,
12792 "prefixesConfigExceedMax");
12793 else
12794 vty_out(vty,
12795 " Peer had exceeded the max. no. of prefixes configured.\n");
12796
12797 if (p->t_pmax_restart) {
12798 if (use_json) {
12799 json_object_boolean_true_add(
12800 json_neigh, "reducePrefixNumFrom");
12801 json_object_int_add(json_neigh,
12802 "restartInTimerMsec",
12803 thread_timer_remain_second(
12804 p->t_pmax_restart)
12805 * 1000);
12806 } else
12807 vty_out(vty,
12808 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
12809 p->host, thread_timer_remain_second(
12810 p->t_pmax_restart));
d62a17ae 12811 } else {
12812 if (use_json)
12813 json_object_boolean_true_add(
12814 json_neigh,
12815 "reducePrefixNumAndClearIpBgp");
12816 else
12817 vty_out(vty,
12818 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
12819 p->host);
12820 }
12821 }
12822
12823 /* EBGP Multihop and GTSM */
12824 if (p->sort != BGP_PEER_IBGP) {
12825 if (use_json) {
e2521429 12826 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12827 json_object_int_add(json_neigh,
12828 "externalBgpNbrMaxHopsAway",
12829 p->gtsm_hops);
c8d6f0d6 12830 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12831 json_object_int_add(json_neigh,
12832 "externalBgpNbrMaxHopsAway",
12833 p->ttl);
12834 } else {
e2521429 12835 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 12836 vty_out(vty,
12837 " External BGP neighbor may be up to %d hops away.\n",
12838 p->gtsm_hops);
c8d6f0d6 12839 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 12840 vty_out(vty,
12841 " External BGP neighbor may be up to %d hops away.\n",
12842 p->ttl);
12843 }
12844 } else {
e2521429 12845 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 12846 if (use_json)
12847 json_object_int_add(json_neigh,
12848 "internalBgpNbrMaxHopsAway",
12849 p->gtsm_hops);
12850 else
12851 vty_out(vty,
12852 " Internal BGP neighbor may be up to %d hops away.\n",
12853 p->gtsm_hops);
12854 }
12855 }
12856
12857 /* Local address. */
12858 if (p->su_local) {
12859 if (use_json) {
12860 json_object_string_add(json_neigh, "hostLocal",
12861 sockunion2str(p->su_local, buf1,
12862 SU_ADDRSTRLEN));
12863 json_object_int_add(json_neigh, "portLocal",
12864 ntohs(p->su_local->sin.sin_port));
12865 } else
12866 vty_out(vty, "Local host: %s, Local port: %d\n",
12867 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
12868 ntohs(p->su_local->sin.sin_port));
12869 }
12870
12871 /* Remote address. */
12872 if (p->su_remote) {
12873 if (use_json) {
12874 json_object_string_add(json_neigh, "hostForeign",
12875 sockunion2str(p->su_remote, buf1,
12876 SU_ADDRSTRLEN));
12877 json_object_int_add(json_neigh, "portForeign",
12878 ntohs(p->su_remote->sin.sin_port));
12879 } else
12880 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
12881 sockunion2str(p->su_remote, buf1,
12882 SU_ADDRSTRLEN),
12883 ntohs(p->su_remote->sin.sin_port));
12884 }
12885
12886 /* Nexthop display. */
12887 if (p->su_local) {
12888 if (use_json) {
12889 json_object_string_add(json_neigh, "nexthop",
12890 inet_ntop(AF_INET,
12891 &p->nexthop.v4, buf1,
12892 sizeof(buf1)));
12893 json_object_string_add(json_neigh, "nexthopGlobal",
12894 inet_ntop(AF_INET6,
12895 &p->nexthop.v6_global,
12896 buf1, sizeof(buf1)));
12897 json_object_string_add(json_neigh, "nexthopLocal",
12898 inet_ntop(AF_INET6,
12899 &p->nexthop.v6_local,
12900 buf1, sizeof(buf1)));
12901 if (p->shared_network)
12902 json_object_string_add(json_neigh,
12903 "bgpConnection",
12904 "sharedNetwork");
12905 else
12906 json_object_string_add(json_neigh,
12907 "bgpConnection",
12908 "nonSharedNetwork");
12909 } else {
12910 vty_out(vty, "Nexthop: %s\n",
12911 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
12912 sizeof(buf1)));
12913 vty_out(vty, "Nexthop global: %s\n",
12914 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
12915 sizeof(buf1)));
12916 vty_out(vty, "Nexthop local: %s\n",
12917 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
12918 sizeof(buf1)));
12919 vty_out(vty, "BGP connection: %s\n",
12920 p->shared_network ? "shared network"
12921 : "non shared network");
12922 }
12923 }
12924
12925 /* Timer information. */
12926 if (use_json) {
12927 json_object_int_add(json_neigh, "connectRetryTimer",
12928 p->v_connect);
12929 if (p->status == Established && p->rtt)
12930 json_object_int_add(json_neigh, "estimatedRttInMsecs",
12931 p->rtt);
12932 if (p->t_start)
12933 json_object_int_add(
12934 json_neigh, "nextStartTimerDueInMsecs",
12935 thread_timer_remain_second(p->t_start) * 1000);
12936 if (p->t_connect)
12937 json_object_int_add(
12938 json_neigh, "nextConnectTimerDueInMsecs",
12939 thread_timer_remain_second(p->t_connect)
12940 * 1000);
12941 if (p->t_routeadv) {
12942 json_object_int_add(json_neigh, "mraiInterval",
12943 p->v_routeadv);
12944 json_object_int_add(
12945 json_neigh, "mraiTimerExpireInMsecs",
12946 thread_timer_remain_second(p->t_routeadv)
12947 * 1000);
12948 }
12949 if (p->password)
12950 json_object_int_add(json_neigh, "authenticationEnabled",
12951 1);
12952
12953 if (p->t_read)
12954 json_object_string_add(json_neigh, "readThread", "on");
12955 else
12956 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
12957
12958 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 12959 json_object_string_add(json_neigh, "writeThread", "on");
12960 else
12961 json_object_string_add(json_neigh, "writeThread",
12962 "off");
12963 } else {
12964 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
12965 p->v_connect);
12966 if (p->status == Established && p->rtt)
12967 vty_out(vty, "Estimated round trip time: %d ms\n",
12968 p->rtt);
12969 if (p->t_start)
12970 vty_out(vty, "Next start timer due in %ld seconds\n",
12971 thread_timer_remain_second(p->t_start));
12972 if (p->t_connect)
12973 vty_out(vty, "Next connect timer due in %ld seconds\n",
12974 thread_timer_remain_second(p->t_connect));
12975 if (p->t_routeadv)
12976 vty_out(vty,
12977 "MRAI (interval %u) timer expires in %ld seconds\n",
12978 p->v_routeadv,
12979 thread_timer_remain_second(p->t_routeadv));
12980 if (p->password)
12981 vty_out(vty, "Peer Authentication Enabled\n");
12982
cac9e917 12983 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
12984 p->t_read ? "on" : "off",
12985 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
12986 ? "on"
cac9e917 12987 : "off", p->fd);
d62a17ae 12988 }
12989
12990 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
12991 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
12992 bgp_capability_vty_out(vty, p, use_json, json_neigh);
12993
12994 if (!use_json)
12995 vty_out(vty, "\n");
12996
12997 /* BFD information. */
12998 bgp_bfd_show_info(vty, p, use_json, json_neigh);
12999
13000 if (use_json) {
13001 if (p->conf_if) /* Configured interface name. */
13002 json_object_object_add(json, p->conf_if, json_neigh);
13003 else /* Configured IP address. */
13004 json_object_object_add(json, p->host, json_neigh);
13005 }
13006}
13007
36235319
QY
13008static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
13009 enum show_type type,
13010 union sockunion *su,
13011 const char *conf_if, afi_t afi,
74a630b6 13012 bool use_json)
2986cac2 13013{
13014 struct listnode *node, *nnode;
13015 struct peer *peer;
13016 int find = 0;
13017 safi_t safi = SAFI_UNICAST;
74a630b6 13018 json_object *json = NULL;
2986cac2 13019 json_object *json_neighbor = NULL;
13020
74a630b6
NT
13021 if (use_json) {
13022 json = json_object_new_object();
13023 json_neighbor = json_object_new_object();
13024 }
13025
2986cac2 13026 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13027
13028 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13029 continue;
13030
13031 if ((peer->afc[afi][safi]) == 0)
13032 continue;
13033
2ba1fe69 13034 if (type == show_all) {
2986cac2 13035 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 13036 json_neighbor);
2986cac2 13037
74a630b6 13038 if (use_json) {
13909c4f
DS
13039 json_object_object_add(json, peer->host,
13040 json_neighbor);
74a630b6
NT
13041 json_neighbor = NULL;
13042 }
2986cac2 13043
2ba1fe69 13044 } else if (type == show_peer) {
2986cac2 13045 if (conf_if) {
13046 if ((peer->conf_if
13909c4f
DS
13047 && !strcmp(peer->conf_if, conf_if))
13048 || (peer->hostname
2986cac2 13049 && !strcmp(peer->hostname, conf_if))) {
13050 find = 1;
13909c4f
DS
13051 bgp_show_peer_gr_status(vty, peer,
13052 use_json,
13053 json_neighbor);
2986cac2 13054 }
13055 } else {
13056 if (sockunion_same(&peer->su, su)) {
13057 find = 1;
13909c4f
DS
13058 bgp_show_peer_gr_status(vty, peer,
13059 use_json,
13060 json_neighbor);
2986cac2 13061 }
13062 }
13909c4f
DS
13063 if (use_json && find)
13064 json_object_object_add(json, peer->host,
13065 json_neighbor);
2986cac2 13066 }
13067
74a630b6
NT
13068 if (find) {
13069 json_neighbor = NULL;
2986cac2 13070 break;
74a630b6 13071 }
2986cac2 13072 }
13073
13074 if (type == show_peer && !find) {
13075 if (use_json)
13909c4f 13076 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 13077 else
13078 vty_out(vty, "%% No such neighbor\n");
13079 }
13080 if (use_json) {
13909c4f
DS
13081 vty_out(vty, "%s\n",
13082 json_object_to_json_string_ext(
13083 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
13084
13085 if (json_neighbor)
13086 json_object_free(json_neighbor);
13087 json_object_free(json);
2986cac2 13088 } else {
13089 vty_out(vty, "\n");
13090 }
13091
13092 return CMD_SUCCESS;
13093}
13094
d62a17ae 13095static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
13096 enum show_type type, union sockunion *su,
9f049418 13097 const char *conf_if, bool use_json,
d62a17ae 13098 json_object *json)
13099{
13100 struct listnode *node, *nnode;
13101 struct peer *peer;
13102 int find = 0;
9f049418 13103 bool nbr_output = false;
d1927ebe
AS
13104 afi_t afi = AFI_MAX;
13105 safi_t safi = SAFI_MAX;
13106
13107 if (type == show_ipv4_peer || type == show_ipv4_all) {
13108 afi = AFI_IP;
13109 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
13110 afi = AFI_IP6;
13111 }
d62a17ae 13112
13113 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
13114 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
13115 continue;
13116
13117 switch (type) {
13118 case show_all:
13119 bgp_show_peer(vty, peer, use_json, json);
9f049418 13120 nbr_output = true;
d62a17ae 13121 break;
13122 case show_peer:
13123 if (conf_if) {
13124 if ((peer->conf_if
13125 && !strcmp(peer->conf_if, conf_if))
13126 || (peer->hostname
13127 && !strcmp(peer->hostname, conf_if))) {
13128 find = 1;
13129 bgp_show_peer(vty, peer, use_json,
13130 json);
13131 }
13132 } else {
13133 if (sockunion_same(&peer->su, su)) {
13134 find = 1;
13135 bgp_show_peer(vty, peer, use_json,
13136 json);
13137 }
13138 }
13139 break;
d1927ebe
AS
13140 case show_ipv4_peer:
13141 case show_ipv6_peer:
13142 FOREACH_SAFI (safi) {
13143 if (peer->afc[afi][safi]) {
13144 if (conf_if) {
13145 if ((peer->conf_if
13146 && !strcmp(peer->conf_if, conf_if))
13147 || (peer->hostname
13148 && !strcmp(peer->hostname, conf_if))) {
13149 find = 1;
13150 bgp_show_peer(vty, peer, use_json,
13151 json);
13152 break;
13153 }
13154 } else {
13155 if (sockunion_same(&peer->su, su)) {
13156 find = 1;
13157 bgp_show_peer(vty, peer, use_json,
13158 json);
13159 break;
13160 }
13161 }
13162 }
13163 }
13164 break;
13165 case show_ipv4_all:
13166 case show_ipv6_all:
13167 FOREACH_SAFI (safi) {
13168 if (peer->afc[afi][safi]) {
13169 bgp_show_peer(vty, peer, use_json, json);
13170 nbr_output = true;
13171 break;
13172 }
13173 }
13174 break;
d62a17ae 13175 }
13176 }
13177
d1927ebe
AS
13178 if ((type == show_peer || type == show_ipv4_peer ||
13179 type == show_ipv6_peer) && !find) {
d62a17ae 13180 if (use_json)
13181 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
13182 else
88b7d255 13183 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 13184 }
13185
d1927ebe
AS
13186 if (type != show_peer && type != show_ipv4_peer &&
13187 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 13188 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 13189
d62a17ae 13190 if (use_json) {
996c9314
LB
13191 vty_out(vty, "%s\n", json_object_to_json_string_ext(
13192 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 13193 } else {
13194 vty_out(vty, "\n");
13195 }
13196
13197 return CMD_SUCCESS;
13198}
13199
36235319
QY
13200static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
13201 enum show_type type,
13202 const char *ip_str,
13203 afi_t afi, bool use_json)
2986cac2 13204{
13205
13206 int ret;
13207 struct bgp *bgp;
13208 union sockunion su;
2986cac2 13209
13210 bgp = bgp_get_default();
13211
13909c4f
DS
13212 if (!bgp)
13213 return;
2986cac2 13214
13909c4f
DS
13215 if (!use_json)
13216 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
13217 NULL);
2986cac2 13218
13909c4f
DS
13219 if (ip_str) {
13220 ret = str2sockunion(ip_str, &su);
13221 if (ret < 0)
13909c4f 13222 bgp_show_neighbor_graceful_restart(
74a630b6
NT
13223 vty, bgp, type, NULL, ip_str, afi, use_json);
13224 else
13225 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
13226 NULL, afi, use_json);
13909c4f
DS
13227 } else
13228 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 13229 afi, use_json);
2986cac2 13230}
13231
d62a17ae 13232static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
13233 enum show_type type,
13234 const char *ip_str,
9f049418 13235 bool use_json)
d62a17ae 13236{
0291c246
MK
13237 struct listnode *node, *nnode;
13238 struct bgp *bgp;
71aedaa3 13239 union sockunion su;
0291c246 13240 json_object *json = NULL;
71aedaa3 13241 int ret, is_first = 1;
9f049418 13242 bool nbr_output = false;
d62a17ae 13243
13244 if (use_json)
13245 vty_out(vty, "{\n");
13246
13247 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 13248 nbr_output = true;
d62a17ae 13249 if (use_json) {
13250 if (!(json = json_object_new_object())) {
af4c2728 13251 flog_err(
e50f7cfd 13252 EC_BGP_JSON_MEM_ERROR,
d62a17ae 13253 "Unable to allocate memory for JSON object");
13254 vty_out(vty,
13255 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
13256 return;
13257 }
13258
13259 json_object_int_add(json, "vrfId",
13260 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
13261 ? -1
13262 : (int64_t)bgp->vrf_id);
d62a17ae 13263 json_object_string_add(
13264 json, "vrfName",
13265 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13266 ? VRF_DEFAULT_NAME
d62a17ae 13267 : bgp->name);
13268
13269 if (!is_first)
13270 vty_out(vty, ",\n");
13271 else
13272 is_first = 0;
13273
13274 vty_out(vty, "\"%s\":",
13275 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13276 ? VRF_DEFAULT_NAME
d62a17ae 13277 : bgp->name);
13278 } else {
13279 vty_out(vty, "\nInstance %s:\n",
13280 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13281 ? VRF_DEFAULT_NAME
d62a17ae 13282 : bgp->name);
13283 }
71aedaa3 13284
d1927ebe
AS
13285 if (type == show_peer || type == show_ipv4_peer ||
13286 type == show_ipv6_peer) {
71aedaa3
DS
13287 ret = str2sockunion(ip_str, &su);
13288 if (ret < 0)
13289 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13290 use_json, json);
13291 else
13292 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13293 use_json, json);
13294 } else {
d1927ebe 13295 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
13296 use_json, json);
13297 }
b77004d6 13298 json_object_free(json);
121067e9 13299 json = NULL;
d62a17ae 13300 }
13301
3e78a6ce 13302 if (use_json)
d62a17ae 13303 vty_out(vty, "}\n");
9f049418
DS
13304 else if (!nbr_output)
13305 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13306}
13307
13308static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
13309 enum show_type type, const char *ip_str,
9f049418 13310 bool use_json)
d62a17ae 13311{
13312 int ret;
13313 struct bgp *bgp;
13314 union sockunion su;
13315 json_object *json = NULL;
13316
13317 if (name) {
13318 if (strmatch(name, "all")) {
71aedaa3
DS
13319 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
13320 use_json);
d62a17ae 13321 return CMD_SUCCESS;
13322 } else {
13323 bgp = bgp_lookup_by_name(name);
13324 if (!bgp) {
13325 if (use_json) {
13326 json = json_object_new_object();
d62a17ae 13327 vty_out(vty, "%s\n",
13328 json_object_to_json_string_ext(
13329 json,
13330 JSON_C_TO_STRING_PRETTY));
13331 json_object_free(json);
13332 } else
13333 vty_out(vty,
9f049418 13334 "%% BGP instance not found\n");
d62a17ae 13335
13336 return CMD_WARNING;
13337 }
13338 }
13339 } else {
13340 bgp = bgp_get_default();
13341 }
13342
13343 if (bgp) {
13344 json = json_object_new_object();
13345 if (ip_str) {
13346 ret = str2sockunion(ip_str, &su);
13347 if (ret < 0)
13348 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
13349 use_json, json);
13350 else
13351 bgp_show_neighbor(vty, bgp, type, &su, NULL,
13352 use_json, json);
13353 } else {
13354 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
13355 json);
13356 }
13357 json_object_free(json);
ca61fd25
DS
13358 } else {
13359 if (use_json)
13360 vty_out(vty, "{}\n");
13361 else
13362 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 13363 }
13364
13365 return CMD_SUCCESS;
4fb25c53
DW
13366}
13367
2986cac2 13368
13369
13370/* "show [ip] bgp neighbors graceful-restart" commands. */
13371DEFUN (show_ip_bgp_neighbors_gracrful_restart,
13372 show_ip_bgp_neighbors_graceful_restart_cmd,
13373 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
13374 SHOW_STR
13375 BGP_STR
13376 IP_STR
13377 IPV6_STR
13378 NEIGHBOR_STR
13379 "Neighbor to display information about\n"
13380 "Neighbor to display information about\n"
13381 "Neighbor on BGP configured interface\n"
13382 GR_SHOW
13383 JSON_STR)
13384{
13385 char *sh_arg = NULL;
13386 enum show_type sh_type;
13387 int idx = 0;
13388 afi_t afi = AFI_MAX;
2986cac2 13389 bool uj = use_json(argc, argv);
13390
36235319 13391 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 13392 afi = AFI_MAX;
13393
13394 idx++;
13395
13396 if (argv_find(argv, argc, "A.B.C.D", &idx)
13397 || argv_find(argv, argc, "X:X::X:X", &idx)
13398 || argv_find(argv, argc, "WORD", &idx)) {
13399 sh_type = show_peer;
13400 sh_arg = argv[idx]->arg;
13401 } else
13402 sh_type = show_all;
13403
13404 if (!argv_find(argv, argc, "graceful-restart", &idx))
13405 return CMD_SUCCESS;
13406
13407
36235319
QY
13408 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
13409 afi, uj);
2986cac2 13410}
13411
716b2d8a 13412/* "show [ip] bgp neighbors" commands. */
718e3744 13413DEFUN (show_ip_bgp_neighbors,
13414 show_ip_bgp_neighbors_cmd,
24345e82 13415 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 13416 SHOW_STR
13417 IP_STR
13418 BGP_STR
f2a8972b 13419 BGP_INSTANCE_HELP_STR
8c3deaae
QY
13420 "Address Family\n"
13421 "Address Family\n"
718e3744 13422 "Detailed information on TCP and BGP neighbor connections\n"
13423 "Neighbor to display information about\n"
a80beece 13424 "Neighbor to display information about\n"
91d37724 13425 "Neighbor on BGP configured interface\n"
9973d184 13426 JSON_STR)
718e3744 13427{
d62a17ae 13428 char *vrf = NULL;
13429 char *sh_arg = NULL;
13430 enum show_type sh_type;
d1927ebe 13431 afi_t afi = AFI_MAX;
718e3744 13432
9f049418 13433 bool uj = use_json(argc, argv);
718e3744 13434
d62a17ae 13435 int idx = 0;
718e3744 13436
9a8bdf1c
PG
13437 /* [<vrf> VIEWVRFNAME] */
13438 if (argv_find(argv, argc, "vrf", &idx)) {
13439 vrf = argv[idx + 1]->arg;
13440 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13441 vrf = NULL;
13442 } else if (argv_find(argv, argc, "view", &idx))
13443 /* [<view> VIEWVRFNAME] */
d62a17ae 13444 vrf = argv[idx + 1]->arg;
718e3744 13445
d62a17ae 13446 idx++;
d1927ebe
AS
13447
13448 if (argv_find(argv, argc, "ipv4", &idx)) {
13449 sh_type = show_ipv4_all;
13450 afi = AFI_IP;
13451 } else if (argv_find(argv, argc, "ipv6", &idx)) {
13452 sh_type = show_ipv6_all;
13453 afi = AFI_IP6;
13454 } else {
13455 sh_type = show_all;
13456 }
13457
d62a17ae 13458 if (argv_find(argv, argc, "A.B.C.D", &idx)
13459 || argv_find(argv, argc, "X:X::X:X", &idx)
13460 || argv_find(argv, argc, "WORD", &idx)) {
13461 sh_type = show_peer;
13462 sh_arg = argv[idx]->arg;
d1927ebe
AS
13463 }
13464
13465 if (sh_type == show_peer && afi == AFI_IP) {
13466 sh_type = show_ipv4_peer;
13467 } else if (sh_type == show_peer && afi == AFI_IP6) {
13468 sh_type = show_ipv6_peer;
13469 }
856ca177 13470
d62a17ae 13471 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 13472}
13473
716b2d8a 13474/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 13475 paths' and `show ip mbgp paths'. Those functions results are the
13476 same.*/
f412b39a 13477DEFUN (show_ip_bgp_paths,
718e3744 13478 show_ip_bgp_paths_cmd,
46f296b4 13479 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 13480 SHOW_STR
13481 IP_STR
13482 BGP_STR
46f296b4 13483 BGP_SAFI_HELP_STR
718e3744 13484 "Path information\n")
13485{
d62a17ae 13486 vty_out(vty, "Address Refcnt Path\n");
13487 aspath_print_all_vty(vty);
13488 return CMD_SUCCESS;
718e3744 13489}
13490
718e3744 13491#include "hash.h"
13492
e3b78da8 13493static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13494 struct vty *vty)
718e3744 13495{
d62a17ae 13496 struct community *com;
718e3744 13497
e3b78da8 13498 com = (struct community *)bucket->data;
3f65c5b1 13499 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 13500 community_str(com, false));
718e3744 13501}
13502
13503/* Show BGP's community internal data. */
f412b39a 13504DEFUN (show_ip_bgp_community_info,
718e3744 13505 show_ip_bgp_community_info_cmd,
bec37ba5 13506 "show [ip] bgp community-info",
718e3744 13507 SHOW_STR
13508 IP_STR
13509 BGP_STR
13510 "List all bgp community information\n")
13511{
d62a17ae 13512 vty_out(vty, "Address Refcnt Community\n");
718e3744 13513
d62a17ae 13514 hash_iterate(community_hash(),
e3b78da8 13515 (void (*)(struct hash_bucket *,
d62a17ae 13516 void *))community_show_all_iterator,
13517 vty);
718e3744 13518
d62a17ae 13519 return CMD_SUCCESS;
718e3744 13520}
13521
e3b78da8 13522static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 13523 struct vty *vty)
57d187bc 13524{
d62a17ae 13525 struct lcommunity *lcom;
57d187bc 13526
e3b78da8 13527 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 13528 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 13529 lcommunity_str(lcom, false));
57d187bc
JS
13530}
13531
13532/* Show BGP's community internal data. */
13533DEFUN (show_ip_bgp_lcommunity_info,
13534 show_ip_bgp_lcommunity_info_cmd,
13535 "show ip bgp large-community-info",
13536 SHOW_STR
13537 IP_STR
13538 BGP_STR
13539 "List all bgp large-community information\n")
13540{
d62a17ae 13541 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 13542
d62a17ae 13543 hash_iterate(lcommunity_hash(),
e3b78da8 13544 (void (*)(struct hash_bucket *,
d62a17ae 13545 void *))lcommunity_show_all_iterator,
13546 vty);
57d187bc 13547
d62a17ae 13548 return CMD_SUCCESS;
57d187bc 13549}
2986cac2 13550/* Graceful Restart */
13551
13552static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
13553 struct bgp *bgp,
13554 bool use_json,
13555 json_object *json)
2986cac2 13556{
57d187bc
JS
13557
13558
2986cac2 13559 vty_out(vty, "\n%s", SHOW_GR_HEADER);
13560
7318ae88 13561 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 13562
13563 switch (bgp_global_gr_mode) {
13564
13565 case GLOBAL_HELPER:
13909c4f 13566 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 13567 break;
13568
13569 case GLOBAL_GR:
13909c4f 13570 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 13571 break;
13572
13573 case GLOBAL_DISABLE:
13909c4f 13574 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 13575 break;
13576
13577 case GLOBAL_INVALID:
2986cac2 13578 vty_out(vty,
2ba1fe69 13579 "Global BGP GR Mode Invalid\n");
2986cac2 13580 break;
13581 }
13582 vty_out(vty, "\n");
13583}
13584
36235319
QY
13585static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
13586 enum show_type type,
13587 const char *ip_str,
13588 afi_t afi, bool use_json)
2986cac2 13589{
13590 if ((afi == AFI_MAX) && (ip_str == NULL)) {
13591 afi = AFI_IP;
13592
13593 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
13594
36235319
QY
13595 bgp_show_neighbor_graceful_restart_vty(
13596 vty, type, ip_str, afi, use_json);
2986cac2 13597 afi++;
13598 }
13599 } else if (afi != AFI_MAX) {
36235319
QY
13600 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
13601 use_json);
2986cac2 13602 } else {
13603 return CMD_ERR_INCOMPLETE;
13604 }
13605
13606 return CMD_SUCCESS;
13607}
13608/* Graceful Restart */
13609
f412b39a 13610DEFUN (show_ip_bgp_attr_info,
718e3744 13611 show_ip_bgp_attr_info_cmd,
bec37ba5 13612 "show [ip] bgp attribute-info",
718e3744 13613 SHOW_STR
13614 IP_STR
13615 BGP_STR
13616 "List all bgp attribute information\n")
13617{
d62a17ae 13618 attr_show_all(vty);
13619 return CMD_SUCCESS;
718e3744 13620}
6b0655a2 13621
03915806
CS
13622static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
13623 afi_t afi, safi_t safi,
13624 bool use_json, json_object *json)
53089bec 13625{
13626 struct bgp *bgp;
13627 struct listnode *node;
13628 char *vname;
13629 char buf1[INET6_ADDRSTRLEN];
13630 char *ecom_str;
13631 vpn_policy_direction_t dir;
13632
03915806 13633 if (json) {
b46dfd20
DS
13634 json_object *json_import_vrfs = NULL;
13635 json_object *json_export_vrfs = NULL;
13636
b46dfd20
DS
13637 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13638
53089bec 13639 if (!bgp) {
b46dfd20
DS
13640 vty_out(vty, "%s\n",
13641 json_object_to_json_string_ext(
13642 json,
13643 JSON_C_TO_STRING_PRETTY));
13644 json_object_free(json);
13645
53089bec 13646 return CMD_WARNING;
13647 }
b46dfd20 13648
94d4c685
DS
13649 /* Provide context for the block */
13650 json_object_string_add(json, "vrf", name ? name : "default");
13651 json_object_string_add(json, "afiSafi",
5cb5f4d0 13652 get_afi_safi_str(afi, safi, true));
94d4c685 13653
b46dfd20
DS
13654 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13655 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
13656 json_object_string_add(json, "importFromVrfs", "none");
13657 json_object_string_add(json, "importRts", "none");
13658 } else {
6ce24e52
DS
13659 json_import_vrfs = json_object_new_array();
13660
b46dfd20
DS
13661 for (ALL_LIST_ELEMENTS_RO(
13662 bgp->vpn_policy[afi].import_vrf,
13663 node, vname))
13664 json_object_array_add(json_import_vrfs,
13665 json_object_new_string(vname));
13666
b20875ea
CS
13667 json_object_object_add(json, "importFromVrfs",
13668 json_import_vrfs);
b46dfd20 13669 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13670 if (bgp->vpn_policy[afi].rtlist[dir]) {
13671 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13672 bgp->vpn_policy[afi].rtlist[dir],
13673 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13674 json_object_string_add(json, "importRts",
13675 ecom_str);
13676 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13677 } else
13678 json_object_string_add(json, "importRts",
13679 "none");
b46dfd20
DS
13680 }
13681
13682 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13683 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
13684 json_object_string_add(json, "exportToVrfs", "none");
13685 json_object_string_add(json, "routeDistinguisher",
13686 "none");
13687 json_object_string_add(json, "exportRts", "none");
13688 } else {
6ce24e52
DS
13689 json_export_vrfs = json_object_new_array();
13690
b46dfd20
DS
13691 for (ALL_LIST_ELEMENTS_RO(
13692 bgp->vpn_policy[afi].export_vrf,
13693 node, vname))
13694 json_object_array_add(json_export_vrfs,
13695 json_object_new_string(vname));
13696 json_object_object_add(json, "exportToVrfs",
13697 json_export_vrfs);
13698 json_object_string_add(json, "routeDistinguisher",
13699 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13700 buf1, RD_ADDRSTRLEN));
13701
13702 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13703 if (bgp->vpn_policy[afi].rtlist[dir]) {
13704 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13705 bgp->vpn_policy[afi].rtlist[dir],
13706 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13707 json_object_string_add(json, "exportRts",
13708 ecom_str);
13709 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13710 } else
13711 json_object_string_add(json, "exportRts",
13712 "none");
b46dfd20
DS
13713 }
13714
03915806
CS
13715 if (use_json) {
13716 vty_out(vty, "%s\n",
13717 json_object_to_json_string_ext(json,
b46dfd20 13718 JSON_C_TO_STRING_PRETTY));
03915806
CS
13719 json_object_free(json);
13720 }
53089bec 13721 } else {
b46dfd20
DS
13722 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
13723
53089bec 13724 if (!bgp) {
b46dfd20 13725 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 13726 return CMD_WARNING;
13727 }
53089bec 13728
b46dfd20
DS
13729 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13730 BGP_CONFIG_VRF_TO_VRF_IMPORT))
13731 vty_out(vty,
13732 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 13733 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13734 else {
13735 vty_out(vty,
13736 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 13737 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13738
13739 for (ALL_LIST_ELEMENTS_RO(
13740 bgp->vpn_policy[afi].import_vrf,
13741 node, vname))
13742 vty_out(vty, " %s\n", vname);
13743
13744 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
13745 ecom_str = NULL;
13746 if (bgp->vpn_policy[afi].rtlist[dir]) {
13747 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13748 bgp->vpn_policy[afi].rtlist[dir],
13749 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 13750 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 13751
b20875ea
CS
13752 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13753 } else
13754 vty_out(vty, "Import RT(s):\n");
53089bec 13755 }
53089bec 13756
b46dfd20
DS
13757 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
13758 BGP_CONFIG_VRF_TO_VRF_EXPORT))
13759 vty_out(vty,
13760 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 13761 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13762 else {
13763 vty_out(vty,
04c9077f 13764 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 13765 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
13766
13767 for (ALL_LIST_ELEMENTS_RO(
13768 bgp->vpn_policy[afi].export_vrf,
13769 node, vname))
13770 vty_out(vty, " %s\n", vname);
13771
13772 vty_out(vty, "RD: %s\n",
13773 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
13774 buf1, RD_ADDRSTRLEN));
13775
13776 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
13777 if (bgp->vpn_policy[afi].rtlist[dir]) {
13778 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
13779 bgp->vpn_policy[afi].rtlist[dir],
13780 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
13781 vty_out(vty, "Export RT: %s\n", ecom_str);
13782 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
13783 } else
13784 vty_out(vty, "Import RT(s):\n");
53089bec 13785 }
53089bec 13786 }
13787
13788 return CMD_SUCCESS;
13789}
13790
03915806
CS
13791static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
13792 safi_t safi, bool use_json)
13793{
13794 struct listnode *node, *nnode;
13795 struct bgp *bgp;
13796 char *vrf_name = NULL;
13797 json_object *json = NULL;
13798 json_object *json_vrf = NULL;
13799 json_object *json_vrfs = NULL;
13800
13801 if (use_json) {
13802 json = json_object_new_object();
13803 json_vrfs = json_object_new_object();
13804 }
13805
13806 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13807
13808 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
13809 vrf_name = bgp->name;
13810
13811 if (use_json) {
13812 json_vrf = json_object_new_object();
13813 } else {
13814 vty_out(vty, "\nInstance %s:\n",
13815 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13816 ? VRF_DEFAULT_NAME : bgp->name);
13817 }
13818 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
13819 if (use_json) {
13820 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
13821 json_object_object_add(json_vrfs,
13822 VRF_DEFAULT_NAME, json_vrf);
13823 else
13824 json_object_object_add(json_vrfs, vrf_name,
13825 json_vrf);
13826 }
13827 }
13828
13829 if (use_json) {
13830 json_object_object_add(json, "vrfs", json_vrfs);
13831 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
13832 JSON_C_TO_STRING_PRETTY));
13833 json_object_free(json);
13834 }
13835
13836 return CMD_SUCCESS;
13837}
13838
53089bec 13839/* "show [ip] bgp route-leak" command. */
13840DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
13841 show_ip_bgp_route_leak_cmd,
13842 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
13843 SHOW_STR
13844 IP_STR
13845 BGP_STR
13846 BGP_INSTANCE_HELP_STR
13847 BGP_AFI_HELP_STR
13848 BGP_SAFI_HELP_STR
13849 "Route leaking information\n"
13850 JSON_STR)
53089bec 13851{
13852 char *vrf = NULL;
13853 afi_t afi = AFI_MAX;
13854 safi_t safi = SAFI_MAX;
13855
9f049418 13856 bool uj = use_json(argc, argv);
53089bec 13857 int idx = 0;
03915806 13858 json_object *json = NULL;
53089bec 13859
13860 /* show [ip] bgp */
13861 if (argv_find(argv, argc, "ip", &idx)) {
13862 afi = AFI_IP;
13863 safi = SAFI_UNICAST;
13864 }
13865 /* [vrf VIEWVRFNAME] */
13866 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
13867 vty_out(vty,
13868 "%% This command is not applicable to BGP views\n");
53089bec 13869 return CMD_WARNING;
13870 }
13871
9a8bdf1c
PG
13872 if (argv_find(argv, argc, "vrf", &idx)) {
13873 vrf = argv[idx + 1]->arg;
13874 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13875 vrf = NULL;
13876 }
53089bec 13877 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13878 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13879 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13880 }
13881
13882 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
13883 vty_out(vty,
13884 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 13885 return CMD_WARNING;
13886 }
13887
03915806
CS
13888 if (vrf && strmatch(vrf, "all"))
13889 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
13890
13891 if (uj)
13892 json = json_object_new_object();
13893
13894 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 13895}
13896
d62a17ae 13897static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
13898 safi_t safi)
f186de26 13899{
d62a17ae 13900 struct listnode *node, *nnode;
13901 struct bgp *bgp;
f186de26 13902
d62a17ae 13903 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
13904 vty_out(vty, "\nInstance %s:\n",
13905 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 13906 ? VRF_DEFAULT_NAME
d62a17ae 13907 : bgp->name);
13908 update_group_show(bgp, afi, safi, vty, 0);
13909 }
f186de26 13910}
13911
d62a17ae 13912static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
13913 int safi, uint64_t subgrp_id)
4fb25c53 13914{
d62a17ae 13915 struct bgp *bgp;
4fb25c53 13916
d62a17ae 13917 if (name) {
13918 if (strmatch(name, "all")) {
13919 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
13920 return CMD_SUCCESS;
13921 } else {
13922 bgp = bgp_lookup_by_name(name);
13923 }
13924 } else {
13925 bgp = bgp_get_default();
13926 }
4fb25c53 13927
d62a17ae 13928 if (bgp)
13929 update_group_show(bgp, afi, safi, vty, subgrp_id);
13930 return CMD_SUCCESS;
4fb25c53
DW
13931}
13932
8fe8a7f6
DS
13933DEFUN (show_ip_bgp_updgrps,
13934 show_ip_bgp_updgrps_cmd,
c1a44e43 13935 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 13936 SHOW_STR
13937 IP_STR
13938 BGP_STR
13939 BGP_INSTANCE_HELP_STR
c9e571b4 13940 BGP_AFI_HELP_STR
9bedbb1e 13941 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
13942 "Detailed info about dynamic update groups\n"
13943 "Specific subgroup to display detailed info for\n")
8386ac43 13944{
d62a17ae 13945 char *vrf = NULL;
13946 afi_t afi = AFI_IP6;
13947 safi_t safi = SAFI_UNICAST;
13948 uint64_t subgrp_id = 0;
13949
13950 int idx = 0;
13951
13952 /* show [ip] bgp */
13953 if (argv_find(argv, argc, "ip", &idx))
13954 afi = AFI_IP;
9a8bdf1c
PG
13955 /* [<vrf> VIEWVRFNAME] */
13956 if (argv_find(argv, argc, "vrf", &idx)) {
13957 vrf = argv[idx + 1]->arg;
13958 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
13959 vrf = NULL;
13960 } else if (argv_find(argv, argc, "view", &idx))
13961 /* [<view> VIEWVRFNAME] */
13962 vrf = argv[idx + 1]->arg;
d62a17ae 13963 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
13964 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
13965 argv_find_and_parse_safi(argv, argc, &idx, &safi);
13966 }
5bf15956 13967
d62a17ae 13968 /* get subgroup id, if provided */
13969 idx = argc - 1;
13970 if (argv[idx]->type == VARIABLE_TKN)
13971 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 13972
d62a17ae 13973 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
13974}
13975
f186de26 13976DEFUN (show_bgp_instance_all_ipv6_updgrps,
13977 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 13978 "show [ip] bgp <view|vrf> all update-groups",
f186de26 13979 SHOW_STR
716b2d8a 13980 IP_STR
f186de26 13981 BGP_STR
13982 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 13983 "Detailed info about dynamic update groups\n")
f186de26 13984{
d62a17ae 13985 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
13986 return CMD_SUCCESS;
f186de26 13987}
13988
43d3f4fc
DS
13989DEFUN (show_bgp_l2vpn_evpn_updgrps,
13990 show_bgp_l2vpn_evpn_updgrps_cmd,
13991 "show [ip] bgp l2vpn evpn update-groups",
13992 SHOW_STR
13993 IP_STR
13994 BGP_STR
13995 "l2vpn address family\n"
13996 "evpn sub-address family\n"
13997 "Detailed info about dynamic update groups\n")
13998{
13999 char *vrf = NULL;
14000 uint64_t subgrp_id = 0;
14001
14002 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
14003 return CMD_SUCCESS;
14004}
14005
5bf15956
DW
14006DEFUN (show_bgp_updgrps_stats,
14007 show_bgp_updgrps_stats_cmd,
716b2d8a 14008 "show [ip] bgp update-groups statistics",
3f9c7369 14009 SHOW_STR
716b2d8a 14010 IP_STR
3f9c7369 14011 BGP_STR
0c7b1b01 14012 "Detailed info about dynamic update groups\n"
3f9c7369
DS
14013 "Statistics\n")
14014{
d62a17ae 14015 struct bgp *bgp;
3f9c7369 14016
d62a17ae 14017 bgp = bgp_get_default();
14018 if (bgp)
14019 update_group_show_stats(bgp, vty);
3f9c7369 14020
d62a17ae 14021 return CMD_SUCCESS;
3f9c7369
DS
14022}
14023
8386ac43 14024DEFUN (show_bgp_instance_updgrps_stats,
14025 show_bgp_instance_updgrps_stats_cmd,
18c57037 14026 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 14027 SHOW_STR
716b2d8a 14028 IP_STR
8386ac43 14029 BGP_STR
14030 BGP_INSTANCE_HELP_STR
0c7b1b01 14031 "Detailed info about dynamic update groups\n"
8386ac43 14032 "Statistics\n")
14033{
d62a17ae 14034 int idx_word = 3;
14035 struct bgp *bgp;
8386ac43 14036
d62a17ae 14037 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
14038 if (bgp)
14039 update_group_show_stats(bgp, vty);
8386ac43 14040
d62a17ae 14041 return CMD_SUCCESS;
8386ac43 14042}
14043
d62a17ae 14044static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
14045 afi_t afi, safi_t safi,
14046 const char *what, uint64_t subgrp_id)
3f9c7369 14047{
d62a17ae 14048 struct bgp *bgp;
8386ac43 14049
d62a17ae 14050 if (name)
14051 bgp = bgp_lookup_by_name(name);
14052 else
14053 bgp = bgp_get_default();
8386ac43 14054
d62a17ae 14055 if (bgp) {
14056 if (!strcmp(what, "advertise-queue"))
14057 update_group_show_adj_queue(bgp, afi, safi, vty,
14058 subgrp_id);
14059 else if (!strcmp(what, "advertised-routes"))
14060 update_group_show_advertised(bgp, afi, safi, vty,
14061 subgrp_id);
14062 else if (!strcmp(what, "packet-queue"))
14063 update_group_show_packet_queue(bgp, afi, safi, vty,
14064 subgrp_id);
14065 }
3f9c7369
DS
14066}
14067
dc64bdec
QY
14068DEFPY(show_ip_bgp_instance_updgrps_adj_s,
14069 show_ip_bgp_instance_updgrps_adj_s_cmd,
14070 "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",
14071 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
14072 BGP_SAFI_HELP_STR
14073 "Detailed info about dynamic update groups\n"
14074 "Specific subgroup to display info for\n"
14075 "Advertisement queue\n"
14076 "Announced routes\n"
14077 "Packet queue\n")
3f9c7369 14078{
dc64bdec
QY
14079 uint64_t subgrp_id = 0;
14080 afi_t afiz;
14081 safi_t safiz;
14082 if (sgid)
14083 subgrp_id = strtoull(sgid, NULL, 10);
14084
14085 if (!ip && !afi)
14086 afiz = AFI_IP6;
14087 if (!ip && afi)
14088 afiz = bgp_vty_afi_from_str(afi);
14089 if (ip && !afi)
14090 afiz = AFI_IP;
14091 if (ip && afi) {
14092 afiz = bgp_vty_afi_from_str(afi);
14093 if (afiz != AFI_IP)
14094 vty_out(vty,
14095 "%% Cannot specify both 'ip' and 'ipv6'\n");
14096 return CMD_WARNING;
14097 }
d62a17ae 14098
dc64bdec 14099 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 14100
dc64bdec 14101 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 14102 return CMD_SUCCESS;
14103}
14104
d62a17ae 14105static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
14106{
14107 struct listnode *node, *nnode;
14108 struct prefix *range;
14109 struct peer *conf;
14110 struct peer *peer;
14111 char buf[PREFIX2STR_BUFFER];
14112 afi_t afi;
14113 safi_t safi;
14114 const char *peer_status;
14115 const char *af_str;
14116 int lr_count;
14117 int dynamic;
14118 int af_cfgd;
14119
14120 conf = group->conf;
14121
14122 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6cde4b45 14123 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14124 group->name, conf->as);
d62a17ae 14125 } else if (conf->as_type == AS_INTERNAL) {
6cde4b45 14126 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
3b61f610 14127 group->name, group->bgp->as);
d62a17ae 14128 } else {
14129 vty_out(vty, "\nBGP peer-group %s\n", group->name);
14130 }
f14e6fdb 14131
d62a17ae 14132 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
14133 vty_out(vty, " Peer-group type is internal\n");
14134 else
14135 vty_out(vty, " Peer-group type is external\n");
14136
14137 /* Display AFs configured. */
14138 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
14139 FOREACH_AFI_SAFI (afi, safi) {
14140 if (conf->afc[afi][safi]) {
14141 af_cfgd = 1;
5cb5f4d0 14142 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
d62a17ae 14143 }
05c7a1cc 14144 }
d62a17ae 14145 if (!af_cfgd)
14146 vty_out(vty, " none\n");
14147 else
14148 vty_out(vty, "\n");
14149
14150 /* Display listen ranges (for dynamic neighbors), if any */
14151 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
14152 if (afi == AFI_IP)
14153 af_str = "IPv4";
14154 else if (afi == AFI_IP6)
14155 af_str = "IPv6";
14156 else
14157 af_str = "???";
14158 lr_count = listcount(group->listen_range[afi]);
14159 if (lr_count) {
14160 vty_out(vty, " %d %s listen range(s)\n", lr_count,
14161 af_str);
14162
14163
14164 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
14165 nnode, range)) {
14166 prefix2str(range, buf, sizeof(buf));
14167 vty_out(vty, " %s\n", buf);
14168 }
14169 }
14170 }
f14e6fdb 14171
d62a17ae 14172 /* Display group members and their status */
14173 if (listcount(group->peer)) {
14174 vty_out(vty, " Peer-group members:\n");
14175 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
14176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
14177 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 14178 peer_status = "Idle (Admin)";
14179 else if (CHECK_FLAG(peer->sflags,
14180 PEER_STATUS_PREFIX_OVERFLOW))
14181 peer_status = "Idle (PfxCt)";
14182 else
14183 peer_status = lookup_msg(bgp_status_msg,
14184 peer->status, NULL);
14185
14186 dynamic = peer_dynamic_neighbor(peer);
14187 vty_out(vty, " %s %s %s \n", peer->host,
14188 dynamic ? "(dynamic)" : "", peer_status);
14189 }
14190 }
f14e6fdb 14191
d62a17ae 14192 return CMD_SUCCESS;
14193}
14194
ff9959b0
QY
14195static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
14196 const char *group_name)
d62a17ae 14197{
ff9959b0 14198 struct bgp *bgp;
d62a17ae 14199 struct listnode *node, *nnode;
14200 struct peer_group *group;
ff9959b0
QY
14201 bool found = false;
14202
14203 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14204
14205 if (!bgp) {
9f049418 14206 vty_out(vty, "%% BGP instance not found\n");
ff9959b0
QY
14207 return CMD_WARNING;
14208 }
d62a17ae 14209
14210 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
14211 if (group_name) {
14212 if (strmatch(group->name, group_name)) {
d62a17ae 14213 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
14214 found = true;
14215 break;
d62a17ae 14216 }
ff9959b0
QY
14217 } else {
14218 bgp_show_one_peer_group(vty, group);
d62a17ae 14219 }
f14e6fdb 14220 }
f14e6fdb 14221
ff9959b0 14222 if (group_name && !found)
d62a17ae 14223 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 14224
d62a17ae 14225 return CMD_SUCCESS;
f14e6fdb
DS
14226}
14227
f14e6fdb
DS
14228DEFUN (show_ip_bgp_peer_groups,
14229 show_ip_bgp_peer_groups_cmd,
18c57037 14230 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
14231 SHOW_STR
14232 IP_STR
14233 BGP_STR
8386ac43 14234 BGP_INSTANCE_HELP_STR
d6e3c605
QY
14235 "Detailed information on BGP peer groups\n"
14236 "Peer group name\n")
f14e6fdb 14237{
d62a17ae 14238 char *vrf, *pg;
d62a17ae 14239 int idx = 0;
f14e6fdb 14240
a4d82a8a
PZ
14241 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
14242 : NULL;
d62a17ae 14243 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 14244
ff9959b0 14245 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 14246}
3f9c7369 14247
d6e3c605 14248
718e3744 14249/* Redistribute VTY commands. */
14250
718e3744 14251DEFUN (bgp_redistribute_ipv4,
14252 bgp_redistribute_ipv4_cmd,
40d1cbfb 14253 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 14254 "Redistribute information from another routing protocol\n"
ab0181ee 14255 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 14256{
d62a17ae 14257 VTY_DECLVAR_CONTEXT(bgp, bgp);
14258 int idx_protocol = 1;
14259 int type;
718e3744 14260
d62a17ae 14261 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14262 if (type < 0) {
14263 vty_out(vty, "%% Invalid route type\n");
14264 return CMD_WARNING_CONFIG_FAILED;
14265 }
7f323236 14266
d62a17ae 14267 bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14268 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
718e3744 14269}
14270
d62a17ae 14271ALIAS_HIDDEN(
14272 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
14273 "redistribute " FRR_IP_REDIST_STR_BGPD,
14274 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 14275
718e3744 14276DEFUN (bgp_redistribute_ipv4_rmap,
14277 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 14278 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 14279 "Redistribute information from another routing protocol\n"
ab0181ee 14280 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14281 "Route map reference\n"
14282 "Pointer to route-map entries\n")
14283{
d62a17ae 14284 VTY_DECLVAR_CONTEXT(bgp, bgp);
14285 int idx_protocol = 1;
14286 int idx_word = 3;
14287 int type;
14288 struct bgp_redist *red;
e923dd62 14289 bool changed;
1de27621
DA
14290 struct route_map *route_map = route_map_lookup_warn_noexist(
14291 vty, argv[idx_word]->arg);
718e3744 14292
d62a17ae 14293 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14294 if (type < 0) {
14295 vty_out(vty, "%% Invalid route type\n");
14296 return CMD_WARNING_CONFIG_FAILED;
14297 }
718e3744 14298
d62a17ae 14299 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14300 changed =
14301 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14302 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
718e3744 14303}
14304
d62a17ae 14305ALIAS_HIDDEN(
14306 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
14307 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
14308 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14309 "Route map reference\n"
14310 "Pointer to route-map entries\n")
596c17ba 14311
718e3744 14312DEFUN (bgp_redistribute_ipv4_metric,
14313 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 14314 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14315 "Redistribute information from another routing protocol\n"
ab0181ee 14316 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14317 "Metric for redistributed routes\n"
14318 "Default metric\n")
14319{
d62a17ae 14320 VTY_DECLVAR_CONTEXT(bgp, bgp);
14321 int idx_protocol = 1;
14322 int idx_number = 3;
14323 int type;
d7c0a89a 14324 uint32_t metric;
d62a17ae 14325 struct bgp_redist *red;
e923dd62 14326 bool changed;
d62a17ae 14327
14328 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14329 if (type < 0) {
14330 vty_out(vty, "%% Invalid route type\n");
14331 return CMD_WARNING_CONFIG_FAILED;
14332 }
14333 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14334
14335 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14336 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14337 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14338}
14339
14340ALIAS_HIDDEN(
14341 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
14342 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
14343 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14344 "Metric for redistributed routes\n"
14345 "Default metric\n")
596c17ba 14346
718e3744 14347DEFUN (bgp_redistribute_ipv4_rmap_metric,
14348 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 14349 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14350 "Redistribute information from another routing protocol\n"
ab0181ee 14351 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14352 "Route map reference\n"
14353 "Pointer to route-map entries\n"
14354 "Metric for redistributed routes\n"
14355 "Default metric\n")
14356{
d62a17ae 14357 VTY_DECLVAR_CONTEXT(bgp, bgp);
14358 int idx_protocol = 1;
14359 int idx_word = 3;
14360 int idx_number = 5;
14361 int type;
d7c0a89a 14362 uint32_t metric;
d62a17ae 14363 struct bgp_redist *red;
e923dd62 14364 bool changed;
1de27621
DA
14365 struct route_map *route_map =
14366 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14367
14368 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14369 if (type < 0) {
14370 vty_out(vty, "%% Invalid route type\n");
14371 return CMD_WARNING_CONFIG_FAILED;
14372 }
14373 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14374
14375 red = bgp_redist_add(bgp, AFI_IP, type, 0);
1de27621
DA
14376 changed =
14377 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14378 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
14379 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14380}
14381
14382ALIAS_HIDDEN(
14383 bgp_redistribute_ipv4_rmap_metric,
14384 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
14385 "redistribute " FRR_IP_REDIST_STR_BGPD
14386 " route-map WORD metric (0-4294967295)",
14387 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14388 "Route map reference\n"
14389 "Pointer to route-map entries\n"
14390 "Metric for redistributed routes\n"
14391 "Default metric\n")
596c17ba 14392
718e3744 14393DEFUN (bgp_redistribute_ipv4_metric_rmap,
14394 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 14395 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14396 "Redistribute information from another routing protocol\n"
ab0181ee 14397 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 14398 "Metric for redistributed routes\n"
14399 "Default metric\n"
14400 "Route map reference\n"
14401 "Pointer to route-map entries\n")
14402{
d62a17ae 14403 VTY_DECLVAR_CONTEXT(bgp, bgp);
14404 int idx_protocol = 1;
14405 int idx_number = 3;
14406 int idx_word = 5;
14407 int type;
d7c0a89a 14408 uint32_t metric;
d62a17ae 14409 struct bgp_redist *red;
e923dd62 14410 bool changed;
1de27621
DA
14411 struct route_map *route_map =
14412 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14413
14414 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14415 if (type < 0) {
14416 vty_out(vty, "%% Invalid route type\n");
14417 return CMD_WARNING_CONFIG_FAILED;
14418 }
14419 metric = strtoul(argv[idx_number]->arg, NULL, 10);
14420
14421 red = bgp_redist_add(bgp, AFI_IP, type, 0);
e923dd62 14422 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
1de27621
DA
14423 changed |=
14424 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14425 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
d62a17ae 14426}
14427
14428ALIAS_HIDDEN(
14429 bgp_redistribute_ipv4_metric_rmap,
14430 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
14431 "redistribute " FRR_IP_REDIST_STR_BGPD
14432 " metric (0-4294967295) route-map WORD",
14433 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14434 "Metric for redistributed routes\n"
14435 "Default metric\n"
14436 "Route map reference\n"
14437 "Pointer to route-map entries\n")
596c17ba 14438
7c8ff89e
DS
14439DEFUN (bgp_redistribute_ipv4_ospf,
14440 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 14441 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
14442 "Redistribute information from another routing protocol\n"
14443 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14444 "Non-main Kernel Routing Table\n"
14445 "Instance ID/Table ID\n")
7c8ff89e 14446{
d62a17ae 14447 VTY_DECLVAR_CONTEXT(bgp, bgp);
14448 int idx_ospf_table = 1;
14449 int idx_number = 2;
d7c0a89a
QY
14450 unsigned short instance;
14451 unsigned short protocol;
7c8ff89e 14452
d62a17ae 14453 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 14454
d62a17ae 14455 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14456 protocol = ZEBRA_ROUTE_OSPF;
14457 else
14458 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 14459
d62a17ae 14460 bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14461 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
7c8ff89e
DS
14462}
14463
d62a17ae 14464ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
14465 "redistribute <ospf|table> (1-65535)",
14466 "Redistribute information from another routing protocol\n"
14467 "Open Shortest Path First (OSPFv2)\n"
14468 "Non-main Kernel Routing Table\n"
14469 "Instance ID/Table ID\n")
596c17ba 14470
7c8ff89e
DS
14471DEFUN (bgp_redistribute_ipv4_ospf_rmap,
14472 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 14473 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
14474 "Redistribute information from another routing protocol\n"
14475 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14476 "Non-main Kernel Routing Table\n"
14477 "Instance ID/Table ID\n"
7c8ff89e
DS
14478 "Route map reference\n"
14479 "Pointer to route-map entries\n")
14480{
d62a17ae 14481 VTY_DECLVAR_CONTEXT(bgp, bgp);
14482 int idx_ospf_table = 1;
14483 int idx_number = 2;
14484 int idx_word = 4;
14485 struct bgp_redist *red;
d7c0a89a 14486 unsigned short instance;
d62a17ae 14487 int protocol;
e923dd62 14488 bool changed;
1de27621
DA
14489 struct route_map *route_map =
14490 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14491
14492 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14493 protocol = ZEBRA_ROUTE_OSPF;
14494 else
14495 protocol = ZEBRA_ROUTE_TABLE;
14496
14497 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14498 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14499 changed =
14500 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14501 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14502}
14503
14504ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
14505 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
14506 "redistribute <ospf|table> (1-65535) route-map WORD",
14507 "Redistribute information from another routing protocol\n"
14508 "Open Shortest Path First (OSPFv2)\n"
14509 "Non-main Kernel Routing Table\n"
14510 "Instance ID/Table ID\n"
14511 "Route map reference\n"
14512 "Pointer to route-map entries\n")
596c17ba 14513
7c8ff89e
DS
14514DEFUN (bgp_redistribute_ipv4_ospf_metric,
14515 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 14516 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
14517 "Redistribute information from another routing protocol\n"
14518 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14519 "Non-main Kernel Routing Table\n"
14520 "Instance ID/Table ID\n"
7c8ff89e
DS
14521 "Metric for redistributed routes\n"
14522 "Default metric\n")
14523{
d62a17ae 14524 VTY_DECLVAR_CONTEXT(bgp, bgp);
14525 int idx_ospf_table = 1;
14526 int idx_number = 2;
14527 int idx_number_2 = 4;
d7c0a89a 14528 uint32_t metric;
d62a17ae 14529 struct bgp_redist *red;
d7c0a89a 14530 unsigned short instance;
d62a17ae 14531 int protocol;
e923dd62 14532 bool changed;
d62a17ae 14533
14534 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14535 protocol = ZEBRA_ROUTE_OSPF;
14536 else
14537 protocol = ZEBRA_ROUTE_TABLE;
14538
14539 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14540 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14541
14542 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14543 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14544 metric);
14545 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14546}
14547
14548ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
14549 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
14550 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
14551 "Redistribute information from another routing protocol\n"
14552 "Open Shortest Path First (OSPFv2)\n"
14553 "Non-main Kernel Routing Table\n"
14554 "Instance ID/Table ID\n"
14555 "Metric for redistributed routes\n"
14556 "Default metric\n")
596c17ba 14557
7c8ff89e
DS
14558DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
14559 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 14560 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
14561 "Redistribute information from another routing protocol\n"
14562 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14563 "Non-main Kernel Routing Table\n"
14564 "Instance ID/Table ID\n"
7c8ff89e
DS
14565 "Route map reference\n"
14566 "Pointer to route-map entries\n"
14567 "Metric for redistributed routes\n"
14568 "Default metric\n")
14569{
d62a17ae 14570 VTY_DECLVAR_CONTEXT(bgp, bgp);
14571 int idx_ospf_table = 1;
14572 int idx_number = 2;
14573 int idx_word = 4;
14574 int idx_number_2 = 6;
d7c0a89a 14575 uint32_t metric;
d62a17ae 14576 struct bgp_redist *red;
d7c0a89a 14577 unsigned short instance;
d62a17ae 14578 int protocol;
e923dd62 14579 bool changed;
1de27621
DA
14580 struct route_map *route_map =
14581 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14582
14583 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14584 protocol = ZEBRA_ROUTE_OSPF;
14585 else
14586 protocol = ZEBRA_ROUTE_TABLE;
14587
14588 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14589 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14590
14591 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
1de27621
DA
14592 changed =
14593 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14594 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14595 metric);
14596 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14597}
14598
14599ALIAS_HIDDEN(
14600 bgp_redistribute_ipv4_ospf_rmap_metric,
14601 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
14602 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
14603 "Redistribute information from another routing protocol\n"
14604 "Open Shortest Path First (OSPFv2)\n"
14605 "Non-main Kernel Routing Table\n"
14606 "Instance ID/Table ID\n"
14607 "Route map reference\n"
14608 "Pointer to route-map entries\n"
14609 "Metric for redistributed routes\n"
14610 "Default metric\n")
596c17ba 14611
7c8ff89e
DS
14612DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
14613 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 14614 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
14615 "Redistribute information from another routing protocol\n"
14616 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
14617 "Non-main Kernel Routing Table\n"
14618 "Instance ID/Table ID\n"
7c8ff89e
DS
14619 "Metric for redistributed routes\n"
14620 "Default metric\n"
14621 "Route map reference\n"
14622 "Pointer to route-map entries\n")
14623{
d62a17ae 14624 VTY_DECLVAR_CONTEXT(bgp, bgp);
14625 int idx_ospf_table = 1;
14626 int idx_number = 2;
14627 int idx_number_2 = 4;
14628 int idx_word = 6;
d7c0a89a 14629 uint32_t metric;
d62a17ae 14630 struct bgp_redist *red;
d7c0a89a 14631 unsigned short instance;
d62a17ae 14632 int protocol;
e923dd62 14633 bool changed;
1de27621
DA
14634 struct route_map *route_map =
14635 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14636
14637 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14638 protocol = ZEBRA_ROUTE_OSPF;
14639 else
14640 protocol = ZEBRA_ROUTE_TABLE;
14641
14642 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14643 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
14644
14645 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
e923dd62 14646 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
14647 metric);
1de27621
DA
14648 changed |=
14649 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14650 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
d62a17ae 14651}
14652
14653ALIAS_HIDDEN(
14654 bgp_redistribute_ipv4_ospf_metric_rmap,
14655 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
14656 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
14657 "Redistribute information from another routing protocol\n"
14658 "Open Shortest Path First (OSPFv2)\n"
14659 "Non-main Kernel Routing Table\n"
14660 "Instance ID/Table ID\n"
14661 "Metric for redistributed routes\n"
14662 "Default metric\n"
14663 "Route map reference\n"
14664 "Pointer to route-map entries\n")
596c17ba 14665
7c8ff89e
DS
14666DEFUN (no_bgp_redistribute_ipv4_ospf,
14667 no_bgp_redistribute_ipv4_ospf_cmd,
e27957c0 14668 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
7c8ff89e
DS
14669 NO_STR
14670 "Redistribute information from another routing protocol\n"
14671 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 14672 "Non-main Kernel Routing Table\n"
31500417
DW
14673 "Instance ID/Table ID\n"
14674 "Metric for redistributed routes\n"
14675 "Default metric\n"
14676 "Route map reference\n"
14677 "Pointer to route-map entries\n")
7c8ff89e 14678{
d62a17ae 14679 VTY_DECLVAR_CONTEXT(bgp, bgp);
14680 int idx_ospf_table = 2;
14681 int idx_number = 3;
d7c0a89a 14682 unsigned short instance;
d62a17ae 14683 int protocol;
14684
14685 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
14686 protocol = ZEBRA_ROUTE_OSPF;
14687 else
14688 protocol = ZEBRA_ROUTE_TABLE;
14689
14690 instance = strtoul(argv[idx_number]->arg, NULL, 10);
14691 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
14692}
14693
14694ALIAS_HIDDEN(
14695 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 14696 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14697 NO_STR
14698 "Redistribute information from another routing protocol\n"
14699 "Open Shortest Path First (OSPFv2)\n"
14700 "Non-main Kernel Routing Table\n"
14701 "Instance ID/Table ID\n"
14702 "Metric for redistributed routes\n"
14703 "Default metric\n"
14704 "Route map reference\n"
14705 "Pointer to route-map entries\n")
596c17ba 14706
718e3744 14707DEFUN (no_bgp_redistribute_ipv4,
14708 no_bgp_redistribute_ipv4_cmd,
e27957c0 14709 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14710 NO_STR
14711 "Redistribute information from another routing protocol\n"
3b14d86e 14712 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
14713 "Metric for redistributed routes\n"
14714 "Default metric\n"
14715 "Route map reference\n"
14716 "Pointer to route-map entries\n")
718e3744 14717{
d62a17ae 14718 VTY_DECLVAR_CONTEXT(bgp, bgp);
14719 int idx_protocol = 2;
14720 int type;
14721
14722 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
14723 if (type < 0) {
14724 vty_out(vty, "%% Invalid route type\n");
14725 return CMD_WARNING_CONFIG_FAILED;
14726 }
14727 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
14728}
14729
14730ALIAS_HIDDEN(
14731 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
14732 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 14733 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 14734 NO_STR
14735 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
14736 "Metric for redistributed routes\n"
14737 "Default metric\n"
14738 "Route map reference\n"
14739 "Pointer to route-map entries\n")
596c17ba 14740
718e3744 14741DEFUN (bgp_redistribute_ipv6,
14742 bgp_redistribute_ipv6_cmd,
40d1cbfb 14743 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 14744 "Redistribute information from another routing protocol\n"
ab0181ee 14745 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 14746{
d62a17ae 14747 VTY_DECLVAR_CONTEXT(bgp, bgp);
14748 int idx_protocol = 1;
14749 int type;
718e3744 14750
d62a17ae 14751 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14752 if (type < 0) {
14753 vty_out(vty, "%% Invalid route type\n");
14754 return CMD_WARNING_CONFIG_FAILED;
14755 }
718e3744 14756
d62a17ae 14757 bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14758 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
718e3744 14759}
14760
14761DEFUN (bgp_redistribute_ipv6_rmap,
14762 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 14763 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 14764 "Redistribute information from another routing protocol\n"
ab0181ee 14765 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14766 "Route map reference\n"
14767 "Pointer to route-map entries\n")
14768{
d62a17ae 14769 VTY_DECLVAR_CONTEXT(bgp, bgp);
14770 int idx_protocol = 1;
14771 int idx_word = 3;
14772 int type;
14773 struct bgp_redist *red;
e923dd62 14774 bool changed;
1de27621
DA
14775 struct route_map *route_map =
14776 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
718e3744 14777
d62a17ae 14778 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14779 if (type < 0) {
14780 vty_out(vty, "%% Invalid route type\n");
14781 return CMD_WARNING_CONFIG_FAILED;
14782 }
718e3744 14783
d62a17ae 14784 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14785 changed =
14786 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14787 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14788}
14789
14790DEFUN (bgp_redistribute_ipv6_metric,
14791 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 14792 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 14793 "Redistribute information from another routing protocol\n"
ab0181ee 14794 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14795 "Metric for redistributed routes\n"
14796 "Default metric\n")
14797{
d62a17ae 14798 VTY_DECLVAR_CONTEXT(bgp, bgp);
14799 int idx_protocol = 1;
14800 int idx_number = 3;
14801 int type;
d7c0a89a 14802 uint32_t metric;
d62a17ae 14803 struct bgp_redist *red;
e923dd62 14804 bool changed;
d62a17ae 14805
14806 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14807 if (type < 0) {
14808 vty_out(vty, "%% Invalid route type\n");
14809 return CMD_WARNING_CONFIG_FAILED;
14810 }
14811 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14812
d62a17ae 14813 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14814 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
14815 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14816}
14817
14818DEFUN (bgp_redistribute_ipv6_rmap_metric,
14819 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 14820 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 14821 "Redistribute information from another routing protocol\n"
ab0181ee 14822 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14823 "Route map reference\n"
14824 "Pointer to route-map entries\n"
14825 "Metric for redistributed routes\n"
14826 "Default metric\n")
14827{
d62a17ae 14828 VTY_DECLVAR_CONTEXT(bgp, bgp);
14829 int idx_protocol = 1;
14830 int idx_word = 3;
14831 int idx_number = 5;
14832 int type;
d7c0a89a 14833 uint32_t metric;
d62a17ae 14834 struct bgp_redist *red;
e923dd62 14835 bool changed;
1de27621
DA
14836 struct route_map *route_map =
14837 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14838
14839 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14840 if (type < 0) {
14841 vty_out(vty, "%% Invalid route type\n");
14842 return CMD_WARNING_CONFIG_FAILED;
14843 }
14844 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14845
d62a17ae 14846 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
1de27621
DA
14847 changed =
14848 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14849 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
14850 metric);
14851 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14852}
14853
14854DEFUN (bgp_redistribute_ipv6_metric_rmap,
14855 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 14856 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 14857 "Redistribute information from another routing protocol\n"
ab0181ee 14858 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 14859 "Metric for redistributed routes\n"
14860 "Default metric\n"
14861 "Route map reference\n"
14862 "Pointer to route-map entries\n")
14863{
d62a17ae 14864 VTY_DECLVAR_CONTEXT(bgp, bgp);
14865 int idx_protocol = 1;
14866 int idx_number = 3;
14867 int idx_word = 5;
14868 int type;
d7c0a89a 14869 uint32_t metric;
d62a17ae 14870 struct bgp_redist *red;
e923dd62 14871 bool changed;
1de27621
DA
14872 struct route_map *route_map =
14873 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
d62a17ae 14874
14875 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14876 if (type < 0) {
14877 vty_out(vty, "%% Invalid route type\n");
14878 return CMD_WARNING_CONFIG_FAILED;
14879 }
14880 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 14881
d62a17ae 14882 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
e923dd62 14883 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
14884 metric);
1de27621
DA
14885 changed |=
14886 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
e923dd62 14887 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
718e3744 14888}
14889
14890DEFUN (no_bgp_redistribute_ipv6,
14891 no_bgp_redistribute_ipv6_cmd,
e27957c0 14892 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
718e3744 14893 NO_STR
14894 "Redistribute information from another routing protocol\n"
3b14d86e 14895 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
14896 "Metric for redistributed routes\n"
14897 "Default metric\n"
14898 "Route map reference\n"
14899 "Pointer to route-map entries\n")
718e3744 14900{
d62a17ae 14901 VTY_DECLVAR_CONTEXT(bgp, bgp);
14902 int idx_protocol = 2;
14903 int type;
718e3744 14904
d62a17ae 14905 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
14906 if (type < 0) {
14907 vty_out(vty, "%% Invalid route type\n");
14908 return CMD_WARNING_CONFIG_FAILED;
14909 }
718e3744 14910
d62a17ae 14911 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
14912}
14913
dd65f45e
DL
14914static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
14915 afi_t afi, safi_t safi)
d62a17ae 14916{
14917 int i;
14918
14919 /* Unicast redistribution only. */
14920 if (safi != SAFI_UNICAST)
2b791107 14921 return;
d62a17ae 14922
14923 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
14924 /* Redistribute BGP does not make sense. */
14925 if (i != ZEBRA_ROUTE_BGP) {
14926 struct list *red_list;
14927 struct listnode *node;
14928 struct bgp_redist *red;
14929
14930 red_list = bgp->redist[afi][i];
14931 if (!red_list)
14932 continue;
14933
14934 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 14935 /* "redistribute" configuration. */
14936 vty_out(vty, " redistribute %s",
14937 zebra_route_string(i));
14938 if (red->instance)
14939 vty_out(vty, " %d", red->instance);
14940 if (red->redist_metric_flag)
14941 vty_out(vty, " metric %u",
14942 red->redist_metric);
14943 if (red->rmap.name)
14944 vty_out(vty, " route-map %s",
14945 red->rmap.name);
14946 vty_out(vty, "\n");
14947 }
14948 }
14949 }
718e3744 14950}
6b0655a2 14951
dd65f45e
DL
14952/* peer-group helpers for config-write */
14953
14954static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
14955{
14956 if (!peer_group_active(peer)) {
14957 if (CHECK_FLAG(peer->flags_invert, flag))
14958 return !CHECK_FLAG(peer->flags, flag);
14959 else
14960 return !!CHECK_FLAG(peer->flags, flag);
14961 }
14962
14963 return !!CHECK_FLAG(peer->flags_override, flag);
14964}
14965
14966static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
14967 uint32_t flag)
14968{
14969 if (!peer_group_active(peer)) {
14970 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
14971 return !peer_af_flag_check(peer, afi, safi, flag);
14972 else
14973 return !!peer_af_flag_check(peer, afi, safi, flag);
14974 }
14975
14976 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
14977}
14978
14979static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
14980 uint8_t type, int direct)
14981{
14982 struct bgp_filter *filter;
14983
14984 if (peer_group_active(peer))
14985 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
14986 type);
14987
14988 filter = &peer->filter[afi][safi];
14989 switch (type) {
14990 case PEER_FT_DISTRIBUTE_LIST:
14991 return !!(filter->dlist[direct].name);
14992 case PEER_FT_FILTER_LIST:
14993 return !!(filter->aslist[direct].name);
14994 case PEER_FT_PREFIX_LIST:
14995 return !!(filter->plist[direct].name);
14996 case PEER_FT_ROUTE_MAP:
14997 return !!(filter->map[direct].name);
14998 case PEER_FT_UNSUPPRESS_MAP:
14999 return !!(filter->usmap.name);
15000 default:
15001 return false;
15002 }
15003}
15004
15005/* Return true if the addpath type is set for peer and different from
15006 * peer-group.
15007 */
3dc339cd
DA
15008static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
15009 safi_t safi)
dd65f45e
DL
15010{
15011 enum bgp_addpath_strat type, g_type;
15012
15013 type = peer->addpath_type[afi][safi];
15014
15015 if (type != BGP_ADDPATH_NONE) {
15016 if (peer_group_active(peer)) {
15017 g_type = peer->group->conf->addpath_type[afi][safi];
15018
15019 if (type != g_type)
3dc339cd 15020 return true;
dd65f45e 15021 else
3dc339cd 15022 return false;
dd65f45e
DL
15023 }
15024
3dc339cd 15025 return true;
dd65f45e
DL
15026 }
15027
3dc339cd 15028 return false;
dd65f45e
DL
15029}
15030
b9c7bc5a 15031/* This is part of the address-family block (unicast only) */
dd65f45e 15032static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
15033 afi_t afi)
15034{
b9c7bc5a 15035 int indent = 2;
ddb5b488 15036
8a066a70 15037 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
15038 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15039 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
15040 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
15041 bgp->vpn_policy[afi]
bb4f6190 15042 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
15043 else
15044 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
15045 bgp->vpn_policy[afi]
15046 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
15047 }
12a844a5
DS
15048 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15049 BGP_CONFIG_VRF_TO_VRF_IMPORT)
15050 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
15051 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15052 return;
15053
e70e9f8e
PZ
15054 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15055 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
15056
15057 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
15058
15059 } else {
15060 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
15061 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
15062 bgp->vpn_policy[afi].tovpn_label);
15063 }
ddb5b488
PZ
15064 }
15065 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15066 BGP_VPN_POLICY_TOVPN_RD_SET)) {
15067 char buf[RD_ADDRSTRLEN];
b9c7bc5a 15068 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
15069 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
15070 sizeof(buf)));
15071 }
15072 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
15073 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
15074
15075 char buf[PREFIX_STRLEN];
15076 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
15077 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
15078 sizeof(buf))) {
15079
b9c7bc5a
PZ
15080 vty_out(vty, "%*snexthop vpn export %s\n",
15081 indent, "", buf);
ddb5b488
PZ
15082 }
15083 }
15084 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
15085 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
15086 && ecommunity_cmp(
15087 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15088 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
15089
15090 char *b = ecommunity_ecom2str(
15091 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15092 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15093 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
15094 XFREE(MTYPE_ECOMMUNITY_STR, b);
15095 } else {
15096 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
15097 char *b = ecommunity_ecom2str(
15098 bgp->vpn_policy[afi]
15099 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
15100 ECOMMUNITY_FORMAT_ROUTE_MAP,
15101 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15102 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
15103 XFREE(MTYPE_ECOMMUNITY_STR, b);
15104 }
15105 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
15106 char *b = ecommunity_ecom2str(
15107 bgp->vpn_policy[afi]
15108 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
15109 ECOMMUNITY_FORMAT_ROUTE_MAP,
15110 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 15111 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
15112 XFREE(MTYPE_ECOMMUNITY_STR, b);
15113 }
15114 }
bb4f6190
DS
15115
15116 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 15117 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
15118 bgp->vpn_policy[afi]
15119 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 15120
301ad80a
PG
15121 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
15122 char *b = ecommunity_ecom2str(
15123 bgp->vpn_policy[afi]
15124 .import_redirect_rtlist,
15125 ECOMMUNITY_FORMAT_ROUTE_MAP,
15126 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 15127
9a659715
PG
15128 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
15129 != ECOMMUNITY_SIZE)
c6423c31 15130 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
15131 indent, "", b);
15132 else
15133 vty_out(vty, "%*srt redirect import %s\n",
15134 indent, "", b);
301ad80a
PG
15135 XFREE(MTYPE_ECOMMUNITY_STR, b);
15136 }
ddb5b488
PZ
15137}
15138
dd65f45e
DL
15139static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
15140 afi_t afi, safi_t safi)
15141{
15142 struct bgp_filter *filter;
15143 char *addr;
15144
15145 addr = peer->host;
15146 filter = &peer->filter[afi][safi];
15147
15148 /* distribute-list. */
15149 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15150 FILTER_IN))
15151 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
15152 filter->dlist[FILTER_IN].name);
15153
15154 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
15155 FILTER_OUT))
15156 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
15157 filter->dlist[FILTER_OUT].name);
15158
15159 /* prefix-list. */
15160 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15161 FILTER_IN))
15162 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
15163 filter->plist[FILTER_IN].name);
15164
15165 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
15166 FILTER_OUT))
15167 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
15168 filter->plist[FILTER_OUT].name);
15169
15170 /* route-map. */
15171 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
15172 vty_out(vty, " neighbor %s route-map %s in\n", addr,
15173 filter->map[RMAP_IN].name);
15174
15175 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
15176 RMAP_OUT))
15177 vty_out(vty, " neighbor %s route-map %s out\n", addr,
15178 filter->map[RMAP_OUT].name);
15179
15180 /* unsuppress-map */
15181 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
15182 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
15183 filter->usmap.name);
15184
15185 /* filter-list. */
15186 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15187 FILTER_IN))
15188 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
15189 filter->aslist[FILTER_IN].name);
15190
15191 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
15192 FILTER_OUT))
15193 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
15194 filter->aslist[FILTER_OUT].name);
15195}
15196
15197/* BGP peer configuration display function. */
15198static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
15199 struct peer *peer)
15200{
15201 struct peer *g_peer = NULL;
15202 char buf[SU_ADDRSTRLEN];
15203 char *addr;
15204 int if_pg_printed = false;
15205 int if_ras_printed = false;
15206
15207 /* Skip dynamic neighbors. */
15208 if (peer_dynamic_neighbor(peer))
15209 return;
15210
15211 if (peer->conf_if)
15212 addr = peer->conf_if;
15213 else
15214 addr = peer->host;
15215
15216 /************************************
15217 ****** Global to the neighbor ******
15218 ************************************/
15219 if (peer->conf_if) {
15220 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
15221 vty_out(vty, " neighbor %s interface v6only", addr);
15222 else
15223 vty_out(vty, " neighbor %s interface", addr);
15224
15225 if (peer_group_active(peer)) {
15226 vty_out(vty, " peer-group %s", peer->group->name);
15227 if_pg_printed = true;
15228 } else if (peer->as_type == AS_SPECIFIED) {
15229 vty_out(vty, " remote-as %u", peer->as);
15230 if_ras_printed = true;
15231 } else if (peer->as_type == AS_INTERNAL) {
15232 vty_out(vty, " remote-as internal");
15233 if_ras_printed = true;
15234 } else if (peer->as_type == AS_EXTERNAL) {
15235 vty_out(vty, " remote-as external");
15236 if_ras_printed = true;
15237 }
15238
15239 vty_out(vty, "\n");
15240 }
15241
15242 /* remote-as and peer-group */
15243 /* peer is a member of a peer-group */
15244 if (peer_group_active(peer)) {
15245 g_peer = peer->group->conf;
15246
15247 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
15248 if (peer->as_type == AS_SPECIFIED) {
15249 vty_out(vty, " neighbor %s remote-as %u\n",
15250 addr, peer->as);
15251 } else if (peer->as_type == AS_INTERNAL) {
15252 vty_out(vty,
15253 " neighbor %s remote-as internal\n",
15254 addr);
15255 } else if (peer->as_type == AS_EXTERNAL) {
15256 vty_out(vty,
15257 " neighbor %s remote-as external\n",
15258 addr);
15259 }
15260 }
15261
15262 /* For swpX peers we displayed the peer-group
15263 * via 'neighbor swpX interface peer-group PGNAME' */
15264 if (!if_pg_printed)
15265 vty_out(vty, " neighbor %s peer-group %s\n", addr,
15266 peer->group->name);
15267 }
15268
15269 /* peer is NOT a member of a peer-group */
15270 else {
15271 /* peer is a peer-group, declare the peer-group */
15272 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
15273 vty_out(vty, " neighbor %s peer-group\n", addr);
15274 }
15275
15276 if (!if_ras_printed) {
15277 if (peer->as_type == AS_SPECIFIED) {
15278 vty_out(vty, " neighbor %s remote-as %u\n",
15279 addr, peer->as);
15280 } else if (peer->as_type == AS_INTERNAL) {
15281 vty_out(vty,
15282 " neighbor %s remote-as internal\n",
15283 addr);
15284 } else if (peer->as_type == AS_EXTERNAL) {
15285 vty_out(vty,
15286 " neighbor %s remote-as external\n",
15287 addr);
15288 }
15289 }
15290 }
15291
15292 /* local-as */
15293 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
15294 vty_out(vty, " neighbor %s local-as %u", addr,
15295 peer->change_local_as);
15296 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
15297 vty_out(vty, " no-prepend");
15298 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
15299 vty_out(vty, " replace-as");
15300 vty_out(vty, "\n");
15301 }
15302
15303 /* description */
15304 if (peer->desc) {
15305 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
15306 }
15307
15308 /* shutdown */
15309 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
15310 if (peer->tx_shutdown_message)
15311 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
15312 peer->tx_shutdown_message);
15313 else
15314 vty_out(vty, " neighbor %s shutdown\n", addr);
15315 }
15316
8336c896
DA
15317 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
15318 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
15319 peer->rtt_expected, peer->rtt_keepalive_conf);
15320
dd65f45e
DL
15321 /* bfd */
15322 if (peer->bfd_info) {
15323 if (!peer_group_active(peer) || !g_peer->bfd_info) {
15324 bgp_bfd_peer_config_write(vty, peer, addr);
15325 }
15326 }
15327
15328 /* password */
15329 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
15330 vty_out(vty, " neighbor %s password %s\n", addr,
15331 peer->password);
15332
15333 /* neighbor solo */
15334 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
15335 if (!peer_group_active(peer)) {
15336 vty_out(vty, " neighbor %s solo\n", addr);
15337 }
15338 }
15339
15340 /* BGP port */
15341 if (peer->port != BGP_PORT_DEFAULT) {
15342 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
15343 }
15344
15345 /* Local interface name */
15346 if (peer->ifname) {
15347 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
15348 }
15349
15350 /* passive */
15351 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
15352 vty_out(vty, " neighbor %s passive\n", addr);
15353
15354 /* ebgp-multihop */
15355 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
15356 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
15357 && peer->ttl == MAXTTL)) {
dd65f45e
DL
15358 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
15359 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
15360 peer->ttl);
15361 }
15362 }
15363
15364 /* ttl-security hops */
e2521429 15365 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
15366 if (!peer_group_active(peer)
15367 || g_peer->gtsm_hops != peer->gtsm_hops) {
15368 vty_out(vty, " neighbor %s ttl-security hops %d\n",
15369 addr, peer->gtsm_hops);
15370 }
15371 }
15372
15373 /* disable-connected-check */
15374 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
15375 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
15376
15377 /* enforce-first-as */
15378 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
15379 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
15380
15381 /* update-source */
15382 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
15383 if (peer->update_source)
15384 vty_out(vty, " neighbor %s update-source %s\n", addr,
15385 sockunion2str(peer->update_source, buf,
15386 SU_ADDRSTRLEN));
15387 else if (peer->update_if)
15388 vty_out(vty, " neighbor %s update-source %s\n", addr,
15389 peer->update_if);
15390 }
15391
15392 /* advertisement-interval */
15393 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
15394 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
15395 peer->routeadv);
15396
15397 /* timers */
15398 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
15399 vty_out(vty, " neighbor %s timers %u %u\n", addr,
15400 peer->keepalive, peer->holdtime);
15401
15402 /* timers connect */
15403 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
15404 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15405 peer->connect);
5d5393b9
DL
15406 /* need special-case handling for changed default values due to
15407 * config profile / version (because there is no "timers bgp connect"
15408 * command, we need to save this per-peer :/)
15409 */
15410 else if (!peer_group_active(peer) && !peer->connect &&
15411 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
15412 vty_out(vty, " neighbor %s timers connect %u\n", addr,
15413 peer->bgp->default_connect_retry);
dd65f45e
DL
15414
15415 /* capability dynamic */
15416 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
15417 vty_out(vty, " neighbor %s capability dynamic\n", addr);
15418
15419 /* capability extended-nexthop */
15420 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
15421 if (!peer->conf_if) {
15422 if (CHECK_FLAG(peer->flags_invert,
15423 PEER_FLAG_CAPABILITY_ENHE))
15424 vty_out(vty,
15425 " no neighbor %s capability extended-nexthop\n",
15426 addr);
15427 else
15428 vty_out(vty,
15429 " neighbor %s capability extended-nexthop\n",
15430 addr);
15431 }
15432 }
15433
15434 /* dont-capability-negotiation */
15435 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
15436 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
15437
15438 /* override-capability */
15439 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
15440 vty_out(vty, " neighbor %s override-capability\n", addr);
15441
15442 /* strict-capability-match */
15443 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
15444 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
15445
15446 /* Sender side AS path loop detection. */
15447 if (peer->as_path_loop_detection)
15448 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
15449 addr);
cfd47646 15450
15451 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15452 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 15453
15454 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 15455 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 15456 vty_out(vty,
15457 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
15458 } else if (CHECK_FLAG(
15459 peer->peer_gr_new_status_flag,
15460 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 15461 vty_out(vty,
15462 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
15463 } else if (
15464 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
15465 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
15466 && !(CHECK_FLAG(
15467 peer->peer_gr_new_status_flag,
15468 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
15469 vty_out(vty, " neighbor %s graceful-restart-disable\n",
15470 addr);
cfd47646 15471 }
15472 }
dd65f45e
DL
15473}
15474
15475/* BGP peer configuration display function. */
15476static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
15477 struct peer *peer, afi_t afi, safi_t safi)
15478{
15479 struct peer *g_peer = NULL;
15480 char *addr;
15481 bool flag_scomm, flag_secomm, flag_slcomm;
15482
15483 /* Skip dynamic neighbors. */
15484 if (peer_dynamic_neighbor(peer))
15485 return;
15486
15487 if (peer->conf_if)
15488 addr = peer->conf_if;
15489 else
15490 addr = peer->host;
15491
15492 /************************************
15493 ****** Per AF to the neighbor ******
15494 ************************************/
15495 if (peer_group_active(peer)) {
15496 g_peer = peer->group->conf;
15497
15498 /* If the peer-group is active but peer is not, print a 'no
15499 * activate' */
15500 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
15501 vty_out(vty, " no neighbor %s activate\n", addr);
15502 }
15503
15504 /* If the peer-group is not active but peer is, print an
15505 'activate' */
15506 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
15507 vty_out(vty, " neighbor %s activate\n", addr);
15508 }
15509 } else {
15510 if (peer->afc[afi][safi]) {
15511 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15512 if (CHECK_FLAG(bgp->flags,
15513 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15514 vty_out(vty, " neighbor %s activate\n",
15515 addr);
15516 }
15517 } else
15518 vty_out(vty, " neighbor %s activate\n", addr);
15519 } else {
15520 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
892fedb6
DA
15521 if (!CHECK_FLAG(bgp->flags,
15522 BGP_FLAG_NO_DEFAULT_IPV4)) {
dd65f45e
DL
15523 vty_out(vty,
15524 " no neighbor %s activate\n",
15525 addr);
15526 }
15527 }
15528 }
15529 }
15530
15531 /* addpath TX knobs */
15532 if (peergroup_af_addpath_check(peer, afi, safi)) {
15533 switch (peer->addpath_type[afi][safi]) {
15534 case BGP_ADDPATH_ALL:
15535 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
15536 addr);
15537 break;
15538 case BGP_ADDPATH_BEST_PER_AS:
15539 vty_out(vty,
15540 " neighbor %s addpath-tx-bestpath-per-AS\n",
15541 addr);
15542 break;
15543 case BGP_ADDPATH_MAX:
15544 case BGP_ADDPATH_NONE:
15545 break;
15546 }
15547 }
15548
15549 /* ORF capability. */
15550 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
15551 || peergroup_af_flag_check(peer, afi, safi,
15552 PEER_FLAG_ORF_PREFIX_RM)) {
15553 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
15554
15555 if (peergroup_af_flag_check(peer, afi, safi,
15556 PEER_FLAG_ORF_PREFIX_SM)
15557 && peergroup_af_flag_check(peer, afi, safi,
15558 PEER_FLAG_ORF_PREFIX_RM))
15559 vty_out(vty, " both");
15560 else if (peergroup_af_flag_check(peer, afi, safi,
15561 PEER_FLAG_ORF_PREFIX_SM))
15562 vty_out(vty, " send");
15563 else
15564 vty_out(vty, " receive");
15565 vty_out(vty, "\n");
15566 }
15567
dd65f45e
DL
15568 /* Route reflector client. */
15569 if (peergroup_af_flag_check(peer, afi, safi,
15570 PEER_FLAG_REFLECTOR_CLIENT)) {
15571 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
15572 }
15573
15574 /* next-hop-self force */
15575 if (peergroup_af_flag_check(peer, afi, safi,
15576 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
15577 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
15578 }
15579
15580 /* next-hop-self */
15581 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
15582 vty_out(vty, " neighbor %s next-hop-self\n", addr);
15583 }
15584
15585 /* remove-private-AS */
15586 if (peergroup_af_flag_check(peer, afi, safi,
15587 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
15588 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
15589 addr);
15590 }
15591
15592 else if (peergroup_af_flag_check(peer, afi, safi,
15593 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
15594 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
15595 addr);
15596 }
15597
15598 else if (peergroup_af_flag_check(peer, afi, safi,
15599 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
15600 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
15601 }
15602
15603 else if (peergroup_af_flag_check(peer, afi, safi,
15604 PEER_FLAG_REMOVE_PRIVATE_AS)) {
15605 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
15606 }
15607
15608 /* as-override */
15609 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
15610 vty_out(vty, " neighbor %s as-override\n", addr);
15611 }
15612
15613 /* send-community print. */
15614 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
15615 PEER_FLAG_SEND_COMMUNITY);
15616 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
15617 PEER_FLAG_SEND_EXT_COMMUNITY);
15618 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
15619 PEER_FLAG_SEND_LARGE_COMMUNITY);
15620
15621 if (flag_scomm && flag_secomm && flag_slcomm) {
15622 vty_out(vty, " no neighbor %s send-community all\n", addr);
15623 } else {
15624 if (flag_scomm)
15625 vty_out(vty, " no neighbor %s send-community\n", addr);
15626 if (flag_secomm)
15627 vty_out(vty,
15628 " no neighbor %s send-community extended\n",
15629 addr);
15630
15631 if (flag_slcomm)
15632 vty_out(vty, " no neighbor %s send-community large\n",
15633 addr);
15634 }
15635
15636 /* Default information */
15637 if (peergroup_af_flag_check(peer, afi, safi,
15638 PEER_FLAG_DEFAULT_ORIGINATE)) {
15639 vty_out(vty, " neighbor %s default-originate", addr);
15640
15641 if (peer->default_rmap[afi][safi].name)
15642 vty_out(vty, " route-map %s",
15643 peer->default_rmap[afi][safi].name);
15644
15645 vty_out(vty, "\n");
15646 }
15647
15648 /* Soft reconfiguration inbound. */
15649 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
15650 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
15651 addr);
15652 }
15653
15654 /* maximum-prefix. */
15655 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 15656 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
15657 peer->pmax[afi][safi]);
15658
15659 if (peer->pmax_threshold[afi][safi]
15660 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
15661 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
15662 if (peer_af_flag_check(peer, afi, safi,
15663 PEER_FLAG_MAX_PREFIX_WARNING))
15664 vty_out(vty, " warning-only");
15665 if (peer->pmax_restart[afi][safi])
15666 vty_out(vty, " restart %u",
15667 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
15668 if (peer_af_flag_check(peer, afi, safi,
15669 PEER_FLAG_MAX_PREFIX_FORCE))
15670 vty_out(vty, " force");
dd65f45e
DL
15671
15672 vty_out(vty, "\n");
15673 }
15674
fde246e8
DA
15675 /* maximum-prefix-out */
15676 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 15677 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
15678 addr, peer->pmax_out[afi][safi]);
15679
dd65f45e
DL
15680 /* Route server client. */
15681 if (peergroup_af_flag_check(peer, afi, safi,
15682 PEER_FLAG_RSERVER_CLIENT)) {
15683 vty_out(vty, " neighbor %s route-server-client\n", addr);
15684 }
15685
15686 /* Nexthop-local unchanged. */
15687 if (peergroup_af_flag_check(peer, afi, safi,
15688 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
15689 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
15690 }
15691
15692 /* allowas-in <1-10> */
15693 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
15694 if (peer_af_flag_check(peer, afi, safi,
15695 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
15696 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
15697 } else if (peer->allowas_in[afi][safi] == 3) {
15698 vty_out(vty, " neighbor %s allowas-in\n", addr);
15699 } else {
15700 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
15701 peer->allowas_in[afi][safi]);
15702 }
15703 }
15704
15705 /* weight */
15706 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
15707 vty_out(vty, " neighbor %s weight %lu\n", addr,
15708 peer->weight[afi][safi]);
15709
15710 /* Filter. */
15711 bgp_config_write_filter(vty, peer, afi, safi);
15712
15713 /* atribute-unchanged. */
15714 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
15715 || (safi != SAFI_EVPN
15716 && peer_af_flag_check(peer, afi, safi,
15717 PEER_FLAG_NEXTHOP_UNCHANGED))
15718 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
15719
15720 if (!peer_group_active(peer)
15721 || peergroup_af_flag_check(peer, afi, safi,
15722 PEER_FLAG_AS_PATH_UNCHANGED)
15723 || peergroup_af_flag_check(peer, afi, safi,
15724 PEER_FLAG_NEXTHOP_UNCHANGED)
15725 || peergroup_af_flag_check(peer, afi, safi,
15726 PEER_FLAG_MED_UNCHANGED)) {
15727
15728 vty_out(vty,
15729 " neighbor %s attribute-unchanged%s%s%s\n",
15730 addr,
15731 peer_af_flag_check(peer, afi, safi,
15732 PEER_FLAG_AS_PATH_UNCHANGED)
15733 ? " as-path"
15734 : "",
15735 peer_af_flag_check(peer, afi, safi,
15736 PEER_FLAG_NEXTHOP_UNCHANGED)
15737 ? " next-hop"
15738 : "",
15739 peer_af_flag_check(peer, afi, safi,
15740 PEER_FLAG_MED_UNCHANGED)
15741 ? " med"
15742 : "");
15743 }
15744 }
15745}
15746
15747/* Address family based peer configuration display. */
15748static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
15749 safi_t safi)
15750{
15751 struct peer *peer;
15752 struct peer_group *group;
15753 struct listnode *node, *nnode;
15754
15755
15756 vty_frame(vty, " !\n address-family ");
15757 if (afi == AFI_IP) {
15758 if (safi == SAFI_UNICAST)
15759 vty_frame(vty, "ipv4 unicast");
15760 else if (safi == SAFI_LABELED_UNICAST)
15761 vty_frame(vty, "ipv4 labeled-unicast");
15762 else if (safi == SAFI_MULTICAST)
15763 vty_frame(vty, "ipv4 multicast");
15764 else if (safi == SAFI_MPLS_VPN)
15765 vty_frame(vty, "ipv4 vpn");
15766 else if (safi == SAFI_ENCAP)
15767 vty_frame(vty, "ipv4 encap");
15768 else if (safi == SAFI_FLOWSPEC)
15769 vty_frame(vty, "ipv4 flowspec");
15770 } else if (afi == AFI_IP6) {
15771 if (safi == SAFI_UNICAST)
15772 vty_frame(vty, "ipv6 unicast");
15773 else if (safi == SAFI_LABELED_UNICAST)
15774 vty_frame(vty, "ipv6 labeled-unicast");
15775 else if (safi == SAFI_MULTICAST)
15776 vty_frame(vty, "ipv6 multicast");
15777 else if (safi == SAFI_MPLS_VPN)
15778 vty_frame(vty, "ipv6 vpn");
15779 else if (safi == SAFI_ENCAP)
15780 vty_frame(vty, "ipv6 encap");
15781 else if (safi == SAFI_FLOWSPEC)
15782 vty_frame(vty, "ipv6 flowspec");
15783 } else if (afi == AFI_L2VPN) {
15784 if (safi == SAFI_EVPN)
15785 vty_frame(vty, "l2vpn evpn");
15786 }
15787 vty_frame(vty, "\n");
15788
15789 bgp_config_write_distance(vty, bgp, afi, safi);
15790
15791 bgp_config_write_network(vty, bgp, afi, safi);
15792
15793 bgp_config_write_redistribute(vty, bgp, afi, safi);
15794
8a4e7fe6
DA
15795 /* BGP flag dampening. */
15796 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
15797 bgp_config_write_damp(vty, afi, safi);
15798
dd65f45e
DL
15799 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
15800 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
15801
15802 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
15803 /* Skip dynamic neighbors. */
15804 if (peer_dynamic_neighbor(peer))
15805 continue;
15806
15807 /* Do not display doppelganger peers */
15808 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
15809 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
15810 }
15811
15812 bgp_config_write_maxpaths(vty, bgp, afi, safi);
15813 bgp_config_write_table_map(vty, bgp, afi, safi);
15814
15815 if (safi == SAFI_EVPN)
15816 bgp_config_write_evpn_info(vty, bgp, afi, safi);
15817
15818 if (safi == SAFI_FLOWSPEC)
15819 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
15820
15821 if (safi == SAFI_UNICAST) {
15822 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
15823 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15824 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
15825
15826 vty_out(vty, " export vpn\n");
15827 }
15828 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15829 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
15830
15831 vty_out(vty, " import vpn\n");
15832 }
15833 if (CHECK_FLAG(bgp->af_flags[afi][safi],
15834 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15835 char *name;
15836
15837 for (ALL_LIST_ELEMENTS_RO(
15838 bgp->vpn_policy[afi].import_vrf, node,
15839 name))
15840 vty_out(vty, " import vrf %s\n", name);
15841 }
15842 }
15843
15844 vty_endframe(vty, " exit-address-family\n");
15845}
15846
15847int bgp_config_write(struct vty *vty)
15848{
15849 struct bgp *bgp;
15850 struct peer_group *group;
15851 struct peer *peer;
15852 struct listnode *node, *nnode;
15853 struct listnode *mnode, *mnnode;
15854
15855 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
15856 vty_out(vty, "bgp route-map delay-timer %u\n",
15857 bm->rmap_update_timer);
15858
d70583f7
D
15859 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
15860 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
15861 if (bm->v_update_delay != bm->v_establish_wait)
15862 vty_out(vty, " %d", bm->v_establish_wait);
15863 vty_out(vty, "\n");
15864 }
15865
05bd726c 15866 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
15867 vty_out(vty, "bgp graceful-shutdown\n");
15868
c163f297
DS
15869 /* No-RIB (Zebra) option flag configuration */
15870 if (bgp_option_check(BGP_OPT_NO_FIB))
15871 vty_out(vty, "bgp no-rib\n");
15872
dd65f45e
DL
15873 /* BGP configuration. */
15874 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
15875
15876 /* skip all auto created vrf as they dont have user config */
15877 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
15878 continue;
15879
15880 /* Router bgp ASN */
15881 vty_out(vty, "router bgp %u", bgp->as);
15882
15883 if (bgp->name)
15884 vty_out(vty, " %s %s",
15885 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
15886 ? "view" : "vrf", bgp->name);
15887 vty_out(vty, "\n");
15888
15889 /* BGP fast-external-failover. */
15890 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
15891 vty_out(vty, " no bgp fast-external-failover\n");
15892
15893 /* BGP router ID. */
15894 if (bgp->router_id_static.s_addr != 0)
15895 vty_out(vty, " bgp router-id %s\n",
15896 inet_ntoa(bgp->router_id_static));
15897
15898 /* BGP log-neighbor-changes. */
892fedb6 15899 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 15900 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 15901 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
15902 CHECK_FLAG(bgp->flags,
15903 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
15904 ? ""
15905 : "no ");
15906
15907 /* BGP configuration. */
892fedb6 15908 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
15909 vty_out(vty, " bgp always-compare-med\n");
15910
15911 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
15912 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
15913 != SAVE_BGP_EBGP_REQUIRES_POLICY)
15914 vty_out(vty, " %sbgp ebgp-requires-policy\n",
15915 CHECK_FLAG(bgp->flags,
15916 BGP_FLAG_EBGP_REQUIRES_POLICY)
15917 ? ""
15918 : "no ");
dd65f45e
DL
15919
15920 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 15921 if (bgp->reject_as_sets)
dd65f45e
DL
15922 vty_out(vty, " bgp reject-as-sets\n");
15923
15924 /* BGP default ipv4-unicast. */
892fedb6 15925 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
15926 vty_out(vty, " no bgp default ipv4-unicast\n");
15927
15928 /* BGP default local-preference. */
15929 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
15930 vty_out(vty, " bgp default local-preference %u\n",
15931 bgp->default_local_pref);
15932
15933 /* BGP default show-hostname */
892fedb6 15934 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 15935 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 15936 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 15937 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
15938 ? ""
15939 : "no ");
15940
aef999a2
DA
15941 /* BGP default show-nexthop-hostname */
15942 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15943 != SAVE_BGP_SHOW_HOSTNAME)
15944 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
15945 CHECK_FLAG(bgp->flags,
15946 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
15947 ? ""
15948 : "no ");
15949
dd65f45e
DL
15950 /* BGP default subgroup-pkt-queue-max. */
15951 if (bgp->default_subgroup_pkt_queue_max
15952 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
15953 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
15954 bgp->default_subgroup_pkt_queue_max);
15955
15956 /* BGP client-to-client reflection. */
892fedb6 15957 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
15958 vty_out(vty, " no bgp client-to-client reflection\n");
15959
15960 /* BGP cluster ID. */
15961 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
15962 vty_out(vty, " bgp cluster-id %s\n",
15963 inet_ntoa(bgp->cluster_id));
15964
15965 /* Disable ebgp connected nexthop check */
892fedb6 15966 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
15967 vty_out(vty,
15968 " bgp disable-ebgp-connected-route-check\n");
15969
15970 /* Confederation identifier*/
15971 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
15972 vty_out(vty, " bgp confederation identifier %u\n",
15973 bgp->confed_id);
15974
15975 /* Confederation peer */
15976 if (bgp->confed_peers_cnt > 0) {
15977 int i;
15978
15979 vty_out(vty, " bgp confederation peers");
15980
15981 for (i = 0; i < bgp->confed_peers_cnt; i++)
15982 vty_out(vty, " %u", bgp->confed_peers[i]);
15983
15984 vty_out(vty, "\n");
15985 }
15986
15987 /* BGP deterministic-med. */
892fedb6 15988 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 15989 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 15990 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
15991 CHECK_FLAG(bgp->flags,
15992 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
15993 ? ""
15994 : "no ");
15995
15996 /* BGP update-delay. */
15997 bgp_config_write_update_delay(vty, bgp);
15998
15999 if (bgp->v_maxmed_onstartup
16000 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
16001 vty_out(vty, " bgp max-med on-startup %u",
16002 bgp->v_maxmed_onstartup);
16003 if (bgp->maxmed_onstartup_value
16004 != BGP_MAXMED_VALUE_DEFAULT)
16005 vty_out(vty, " %u",
16006 bgp->maxmed_onstartup_value);
16007 vty_out(vty, "\n");
16008 }
16009 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
16010 vty_out(vty, " bgp max-med administrative");
16011 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
16012 vty_out(vty, " %u", bgp->maxmed_admin_value);
16013 vty_out(vty, "\n");
16014 }
16015
16016 /* write quanta */
16017 bgp_config_write_wpkt_quanta(vty, bgp);
16018 /* read quanta */
16019 bgp_config_write_rpkt_quanta(vty, bgp);
16020
16021 /* coalesce time */
16022 bgp_config_write_coalesce_time(vty, bgp);
16023
05bd726c 16024 /* BGP per-instance graceful-shutdown */
16025 /* BGP-wide settings and per-instance settings are mutually
16026 * exclusive.
16027 */
16028 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
16029 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
16030 vty_out(vty, " bgp graceful-shutdown\n");
16031
dd65f45e
DL
16032 /* BGP graceful-restart. */
16033 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
16034 vty_out(vty,
16035 " bgp graceful-restart stalepath-time %u\n",
16036 bgp->stalepath_time);
cfd47646 16037
dd65f45e
DL
16038 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
16039 vty_out(vty, " bgp graceful-restart restart-time %u\n",
16040 bgp->restart_time);
cfd47646 16041
16042 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
16043 vty_out(vty,
16044 " bgp graceful-restart select-defer-time %u\n",
16045 bgp->select_defer_time);
16046
16047 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
16048 vty_out(vty, " bgp graceful-restart\n");
16049
cfd47646 16050 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
16051 vty_out(vty, " bgp graceful-restart-disable\n");
16052
dd65f45e 16053 /* BGP graceful-restart Preserve State F bit. */
892fedb6 16054 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
16055 vty_out(vty,
16056 " bgp graceful-restart preserve-fw-state\n");
16057
dc95985f 16058 /* Stale timer for RIB */
16059 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
16060 vty_out(vty,
16061 " bgp graceful-restart rib-stale-time %u\n",
16062 bgp->rib_stale_time);
16063
dd65f45e 16064 /* BGP bestpath method. */
892fedb6 16065 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 16066 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 16067 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
16068 vty_out(vty, " bgp bestpath as-path confed\n");
16069
892fedb6
DA
16070 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
16071 if (CHECK_FLAG(bgp->flags,
16072 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
16073 vty_out(vty,
16074 " bgp bestpath as-path multipath-relax as-set\n");
16075 } else {
16076 vty_out(vty,
16077 " bgp bestpath as-path multipath-relax\n");
16078 }
16079 }
16080
892fedb6 16081 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
16082 vty_out(vty,
16083 " bgp route-reflector allow-outbound-policy\n");
16084 }
892fedb6 16085 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 16086 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
16087 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
16088 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 16089 vty_out(vty, " bgp bestpath med");
892fedb6 16090 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 16091 vty_out(vty, " confed");
892fedb6
DA
16092 if (CHECK_FLAG(bgp->flags,
16093 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
16094 vty_out(vty, " missing-as-worst");
16095 vty_out(vty, "\n");
16096 }
16097
f7e1c681 16098 /* Link bandwidth handling. */
16099 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
16100 vty_out(vty, " bgp bestpath bandwidth ignore\n");
16101 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
16102 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
16103 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
16104 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
16105
dd65f45e 16106 /* BGP network import check. */
892fedb6 16107 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 16108 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 16109 vty_out(vty, " %sbgp network import-check\n",
892fedb6 16110 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
16111 ? ""
16112 : "no ");
16113
16114 /* BGP timers configuration. */
5d5393b9
DL
16115 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
16116 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
16117 vty_out(vty, " timers bgp %u %u\n",
16118 bgp->default_keepalive, bgp->default_holdtime);
16119
16120 /* peer-group */
16121 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
16122 bgp_config_write_peer_global(vty, bgp, group->conf);
16123 }
16124
16125 /* Normal neighbor configuration. */
16126 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
16127 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
16128 bgp_config_write_peer_global(vty, bgp, peer);
16129 }
16130
16131 /* listen range and limit for dynamic BGP neighbors */
16132 bgp_config_write_listen(vty, bgp);
16133
16134 /*
16135 * BGP default autoshutdown neighbors
16136 *
16137 * This must be placed after any peer and peer-group
16138 * configuration, to avoid setting all peers to shutdown after
16139 * a daemon restart, which is undesired behavior. (see #2286)
16140 */
16141 if (bgp->autoshutdown)
16142 vty_out(vty, " bgp default shutdown\n");
16143
9cf59432
DS
16144 /* BGP instance administrative shutdown */
16145 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
16146 vty_out(vty, " bgp shutdown\n");
16147
dd65f45e
DL
16148 /* IPv4 unicast configuration. */
16149 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
16150
16151 /* IPv4 multicast configuration. */
16152 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
16153
16154 /* IPv4 labeled-unicast configuration. */
16155 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
16156
16157 /* IPv4 VPN configuration. */
16158 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
16159
16160 /* ENCAPv4 configuration. */
16161 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
16162
16163 /* FLOWSPEC v4 configuration. */
16164 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
16165
16166 /* IPv6 unicast configuration. */
16167 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
16168
16169 /* IPv6 multicast configuration. */
16170 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
16171
16172 /* IPv6 labeled-unicast configuration. */
16173 bgp_config_write_family(vty, bgp, AFI_IP6,
16174 SAFI_LABELED_UNICAST);
16175
16176 /* IPv6 VPN configuration. */
16177 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
16178
16179 /* ENCAPv6 configuration. */
16180 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
16181
16182 /* FLOWSPEC v6 configuration. */
16183 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
16184
16185 /* EVPN configuration. */
16186 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
16187
16188 hook_call(bgp_inst_config_write, bgp, vty);
16189
49e5a4a0 16190#ifdef ENABLE_BGP_VNC
dd65f45e
DL
16191 bgp_rfapi_cfg_write(vty, bgp);
16192#endif
16193
16194 vty_out(vty, "!\n");
16195 }
16196 return 0;
16197}
16198
ddb5b488 16199
718e3744 16200/* BGP node structure. */
d62a17ae 16201static struct cmd_node bgp_node = {
f4b8291f 16202 .name = "bgp",
62b346ee 16203 .node = BGP_NODE,
24389580 16204 .parent_node = CONFIG_NODE,
62b346ee 16205 .prompt = "%s(config-router)# ",
612c2c15 16206 .config_write = bgp_config_write,
718e3744 16207};
16208
d62a17ae 16209static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 16210 .name = "bgp ipv4 unicast",
62b346ee 16211 .node = BGP_IPV4_NODE,
24389580 16212 .parent_node = BGP_NODE,
62b346ee 16213 .prompt = "%s(config-router-af)# ",
718e3744 16214};
16215
d62a17ae 16216static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 16217 .name = "bgp ipv4 multicast",
62b346ee 16218 .node = BGP_IPV4M_NODE,
24389580 16219 .parent_node = BGP_NODE,
62b346ee 16220 .prompt = "%s(config-router-af)# ",
718e3744 16221};
16222
d62a17ae 16223static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 16224 .name = "bgp ipv4 labeled unicast",
62b346ee 16225 .node = BGP_IPV4L_NODE,
24389580 16226 .parent_node = BGP_NODE,
62b346ee 16227 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16228};
16229
d62a17ae 16230static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 16231 .name = "bgp ipv6",
62b346ee 16232 .node = BGP_IPV6_NODE,
24389580 16233 .parent_node = BGP_NODE,
62b346ee 16234 .prompt = "%s(config-router-af)# ",
718e3744 16235};
16236
d62a17ae 16237static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 16238 .name = "bgp ipv6 multicast",
62b346ee 16239 .node = BGP_IPV6M_NODE,
24389580 16240 .parent_node = BGP_NODE,
62b346ee 16241 .prompt = "%s(config-router-af)# ",
25ffbdc1 16242};
16243
d62a17ae 16244static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 16245 .name = "bgp ipv6 labeled unicast",
62b346ee 16246 .node = BGP_IPV6L_NODE,
24389580 16247 .parent_node = BGP_NODE,
62b346ee 16248 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
16249};
16250
62b346ee 16251static struct cmd_node bgp_vpnv4_node = {
f4b8291f 16252 .name = "bgp vpnv4",
62b346ee 16253 .node = BGP_VPNV4_NODE,
24389580 16254 .parent_node = BGP_NODE,
62b346ee 16255 .prompt = "%s(config-router-af)# ",
62b346ee 16256};
6b0655a2 16257
62b346ee 16258static struct cmd_node bgp_vpnv6_node = {
f4b8291f 16259 .name = "bgp vpnv6",
62b346ee 16260 .node = BGP_VPNV6_NODE,
24389580 16261 .parent_node = BGP_NODE,
62b346ee 16262 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16263};
8ecd3266 16264
62b346ee 16265static struct cmd_node bgp_evpn_node = {
f4b8291f 16266 .name = "bgp evpn",
62b346ee 16267 .node = BGP_EVPN_NODE,
24389580 16268 .parent_node = BGP_NODE,
62b346ee 16269 .prompt = "%s(config-router-evpn)# ",
62b346ee 16270};
4e0b7b6d 16271
62b346ee 16272static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 16273 .name = "bgp evpn vni",
62b346ee 16274 .node = BGP_EVPN_VNI_NODE,
24389580 16275 .parent_node = BGP_EVPN_NODE,
62b346ee 16276 .prompt = "%s(config-router-af-vni)# ",
62b346ee 16277};
90e60aa7 16278
62b346ee 16279static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 16280 .name = "bgp ipv4 flowspec",
62b346ee 16281 .node = BGP_FLOWSPECV4_NODE,
24389580 16282 .parent_node = BGP_NODE,
62b346ee 16283 .prompt = "%s(config-router-af)# ",
62b346ee 16284};
7c40bf39 16285
62b346ee 16286static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 16287 .name = "bgp ipv6 flowspec",
62b346ee 16288 .node = BGP_FLOWSPECV6_NODE,
24389580 16289 .parent_node = BGP_NODE,
62b346ee 16290 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 16291};
7c40bf39 16292
d62a17ae 16293static void community_list_vty(void);
1f8ae70b 16294
d62a17ae 16295static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 16296{
d62a17ae 16297 struct bgp *bgp;
16298 struct peer *peer;
d62a17ae 16299 struct listnode *lnbgp, *lnpeer;
b8a815e5 16300
d62a17ae 16301 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16302 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
16303 /* only provide suggestions on the appropriate input
16304 * token type,
16305 * they'll otherwise show up multiple times */
16306 enum cmd_token_type match_type;
16307 char *name = peer->host;
d48ed3e0 16308
d62a17ae 16309 if (peer->conf_if) {
16310 match_type = VARIABLE_TKN;
16311 name = peer->conf_if;
16312 } else if (strchr(peer->host, ':'))
16313 match_type = IPV6_TKN;
16314 else
16315 match_type = IPV4_TKN;
d48ed3e0 16316
d62a17ae 16317 if (token->type != match_type)
16318 continue;
d48ed3e0 16319
d62a17ae 16320 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
16321 }
d62a17ae 16322 }
b8a815e5
DL
16323}
16324
16325static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 16326 {.varname = "neighbor", .completions = bgp_ac_neighbor},
16327 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 16328 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 16329 {.completions = NULL}};
16330
47a306a0
DS
16331static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
16332{
16333 struct bgp *bgp;
16334 struct peer_group *group;
16335 struct listnode *lnbgp, *lnpeer;
16336
16337 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
16338 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
16339 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
16340 group->name));
16341 }
16342}
16343
16344static const struct cmd_variable_handler bgp_var_peergroup[] = {
16345 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
16346 {.completions = NULL} };
16347
d62a17ae 16348void bgp_vty_init(void)
16349{
16350 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 16351 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 16352
16353 /* Install bgp top node. */
612c2c15
DL
16354 install_node(&bgp_node);
16355 install_node(&bgp_ipv4_unicast_node);
16356 install_node(&bgp_ipv4_multicast_node);
16357 install_node(&bgp_ipv4_labeled_unicast_node);
16358 install_node(&bgp_ipv6_unicast_node);
16359 install_node(&bgp_ipv6_multicast_node);
16360 install_node(&bgp_ipv6_labeled_unicast_node);
16361 install_node(&bgp_vpnv4_node);
16362 install_node(&bgp_vpnv6_node);
16363 install_node(&bgp_evpn_node);
16364 install_node(&bgp_evpn_vni_node);
16365 install_node(&bgp_flowspecv4_node);
16366 install_node(&bgp_flowspecv6_node);
d62a17ae 16367
16368 /* Install default VTY commands to new nodes. */
16369 install_default(BGP_NODE);
16370 install_default(BGP_IPV4_NODE);
16371 install_default(BGP_IPV4M_NODE);
16372 install_default(BGP_IPV4L_NODE);
16373 install_default(BGP_IPV6_NODE);
16374 install_default(BGP_IPV6M_NODE);
16375 install_default(BGP_IPV6L_NODE);
16376 install_default(BGP_VPNV4_NODE);
16377 install_default(BGP_VPNV6_NODE);
7c40bf39 16378 install_default(BGP_FLOWSPECV4_NODE);
16379 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 16380 install_default(BGP_EVPN_NODE);
16381 install_default(BGP_EVPN_VNI_NODE);
16382
8029b216
AK
16383 /* "bgp local-mac" hidden commands. */
16384 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
16385 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
16386
d62a17ae 16387 /* bgp route-map delay-timer commands. */
16388 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
16389 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16390
d70583f7
D
16391 /* global bgp update-delay command */
16392 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
16393 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
16394
05bd726c 16395 /* global bgp graceful-shutdown command */
16396 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
16397 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
16398
d62a17ae 16399 /* Dummy commands (Currently not supported) */
16400 install_element(BGP_NODE, &no_synchronization_cmd);
16401 install_element(BGP_NODE, &no_auto_summary_cmd);
16402
16403 /* "router bgp" commands. */
16404 install_element(CONFIG_NODE, &router_bgp_cmd);
16405
16406 /* "no router bgp" commands. */
16407 install_element(CONFIG_NODE, &no_router_bgp_cmd);
16408
16409 /* "bgp router-id" commands. */
16410 install_element(BGP_NODE, &bgp_router_id_cmd);
16411 install_element(BGP_NODE, &no_bgp_router_id_cmd);
16412
16413 /* "bgp cluster-id" commands. */
16414 install_element(BGP_NODE, &bgp_cluster_id_cmd);
16415 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
16416
c163f297
DS
16417 /* "bgp no-rib" commands. */
16418 install_element(CONFIG_NODE, &bgp_norib_cmd);
16419 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
16420
d62a17ae 16421 /* "bgp confederation" commands. */
16422 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
16423 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
16424
16425 /* "bgp confederation peers" commands. */
16426 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
16427 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
16428
16429 /* bgp max-med command */
16430 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
16431 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
16432 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
16433 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
16434 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
16435
16436 /* bgp disable-ebgp-connected-nh-check */
16437 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
16438 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
16439
16440 /* bgp update-delay command */
16441 install_element(BGP_NODE, &bgp_update_delay_cmd);
16442 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 16443
16444 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 16445 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 16446
16447 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
16448 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
16449
16450 /* "maximum-paths" commands. */
16451 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
16452 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
16453 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
16454 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
16455 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
16456 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
16457 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
16458 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
16459 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
16460 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
16461 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16462 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
16463 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
16464 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16465 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
16466
39edabac
PG
16467 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
16468 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
16469 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
16470 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16471 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 16472 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
16473 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
16474 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
16475 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
16476 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
16477
16478 /* "timers bgp" commands. */
16479 install_element(BGP_NODE, &bgp_timers_cmd);
16480 install_element(BGP_NODE, &no_bgp_timers_cmd);
16481
16482 /* route-map delay-timer commands - per instance for backwards compat.
16483 */
16484 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
16485 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
16486
16487 /* "bgp client-to-client reflection" commands */
16488 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
16489 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
16490
16491 /* "bgp always-compare-med" commands */
16492 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
16493 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
16494
9dac9fc8
DA
16495 /* bgp ebgp-requires-policy */
16496 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
16497 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
16498
fb29348a
DA
16499 /* bgp reject-as-sets */
16500 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
16501 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
16502
d62a17ae 16503 /* "bgp deterministic-med" commands */
16504 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
16505 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
16506
055679e9 16507 /* "bgp graceful-restart" command */
36235319
QY
16508 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
16509 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 16510
16511 /* "bgp graceful-restart-disable" command */
36235319
QY
16512 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
16513 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 16514
16515 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
16516 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
16517 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 16518
16519 /* "neighbor a:b:c:d graceful-restart-disable" command */
16520 install_element(BGP_NODE,
16521 &bgp_neighbor_graceful_restart_disable_set_cmd);
16522 install_element(BGP_NODE,
16523 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
16524
16525 /* "neighbor a:b:c:d graceful-restart-helper" command */
16526 install_element(BGP_NODE,
16527 &bgp_neighbor_graceful_restart_helper_set_cmd);
16528 install_element(BGP_NODE,
16529 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
16530
d62a17ae 16531 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
16532 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
16533 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
16534 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 16535 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 16536 install_element(BGP_NODE,
16537 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 16538 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
16539 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
16540
d6e3c15b 16541 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
16542 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 16543 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
16544 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 16545
7f323236
DW
16546 /* "bgp graceful-shutdown" commands */
16547 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
16548 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
16549
d62a17ae 16550 /* "bgp fast-external-failover" commands */
16551 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
16552 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
16553
d62a17ae 16554 /* "bgp bestpath compare-routerid" commands */
16555 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
16556 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
16557
16558 /* "bgp bestpath as-path ignore" commands */
16559 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
16560 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
16561
16562 /* "bgp bestpath as-path confed" commands */
16563 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
16564 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
16565
16566 /* "bgp bestpath as-path multipath-relax" commands */
16567 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
16568 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
16569
16570 /* "bgp log-neighbor-changes" commands */
16571 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
16572 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
16573
16574 /* "bgp bestpath med" commands */
16575 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
16576 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
16577
f7e1c681 16578 /* "bgp bestpath bandwidth" commands */
16579 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 16580 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 16581
d62a17ae 16582 /* "no bgp default ipv4-unicast" commands. */
16583 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
16584 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
16585
16586 /* "bgp network import-check" commands. */
16587 install_element(BGP_NODE, &bgp_network_import_check_cmd);
16588 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
16589 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
16590
16591 /* "bgp default local-preference" commands. */
16592 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
16593 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
16594
16595 /* bgp default show-hostname */
16596 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
16597 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
16598
aef999a2
DA
16599 /* bgp default show-nexthop-hostname */
16600 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
16601 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
16602
d62a17ae 16603 /* "bgp default subgroup-pkt-queue-max" commands. */
16604 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
16605 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
16606
16607 /* bgp ibgp-allow-policy-mods command */
16608 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
16609 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
16610
16611 /* "bgp listen limit" commands. */
16612 install_element(BGP_NODE, &bgp_listen_limit_cmd);
16613 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
16614
16615 /* "bgp listen range" commands. */
16616 install_element(BGP_NODE, &bgp_listen_range_cmd);
16617 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
16618
8175f54a 16619 /* "bgp default shutdown" command */
f26845f9 16620 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
16621
16622 /* "bgp shutdown" commands */
16623 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 16624 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 16625 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 16626 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 16627
d62a17ae 16628 /* "neighbor remote-as" commands. */
16629 install_element(BGP_NODE, &neighbor_remote_as_cmd);
16630 install_element(BGP_NODE, &neighbor_interface_config_cmd);
16631 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
16632 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
16633 install_element(BGP_NODE,
16634 &neighbor_interface_v6only_config_remote_as_cmd);
16635 install_element(BGP_NODE, &no_neighbor_cmd);
16636 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
16637
16638 /* "neighbor peer-group" commands. */
16639 install_element(BGP_NODE, &neighbor_peer_group_cmd);
16640 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
16641 install_element(BGP_NODE,
16642 &no_neighbor_interface_peer_group_remote_as_cmd);
16643
16644 /* "neighbor local-as" commands. */
16645 install_element(BGP_NODE, &neighbor_local_as_cmd);
16646 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
16647 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
16648 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
16649
16650 /* "neighbor solo" commands. */
16651 install_element(BGP_NODE, &neighbor_solo_cmd);
16652 install_element(BGP_NODE, &no_neighbor_solo_cmd);
16653
16654 /* "neighbor password" commands. */
16655 install_element(BGP_NODE, &neighbor_password_cmd);
16656 install_element(BGP_NODE, &no_neighbor_password_cmd);
16657
16658 /* "neighbor activate" commands. */
16659 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
16660 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
16661 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
16662 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
16663 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
16664 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
16665 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
16666 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
16667 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 16668 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
16669 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 16670 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
16671
16672 /* "no neighbor activate" commands. */
16673 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
16674 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
16675 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
16676 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
16677 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
16678 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
16679 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
16680 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
16681 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 16682 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
16683 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 16684 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
16685
16686 /* "neighbor peer-group" set commands. */
16687 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
16688 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16689 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
16690 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
16691 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
16692 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
16693 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
16694 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 16695 install_element(BGP_FLOWSPECV4_NODE,
16696 &neighbor_set_peer_group_hidden_cmd);
16697 install_element(BGP_FLOWSPECV6_NODE,
16698 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 16699
16700 /* "no neighbor peer-group unset" commands. */
16701 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
16702 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16703 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16704 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16705 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16706 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16707 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
16708 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 16709 install_element(BGP_FLOWSPECV4_NODE,
16710 &no_neighbor_set_peer_group_hidden_cmd);
16711 install_element(BGP_FLOWSPECV6_NODE,
16712 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 16713
16714 /* "neighbor softreconfiguration inbound" commands.*/
16715 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
16716 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
16717 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
16718 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16719 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
16720 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16721 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
16722 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16723 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
16724 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
16725 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
16726 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
16727 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
16728 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
16729 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
16730 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
16731 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
16732 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 16733 install_element(BGP_FLOWSPECV4_NODE,
16734 &neighbor_soft_reconfiguration_cmd);
16735 install_element(BGP_FLOWSPECV4_NODE,
16736 &no_neighbor_soft_reconfiguration_cmd);
16737 install_element(BGP_FLOWSPECV6_NODE,
16738 &neighbor_soft_reconfiguration_cmd);
16739 install_element(BGP_FLOWSPECV6_NODE,
16740 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
16741 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
16742 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 16743
16744 /* "neighbor attribute-unchanged" commands. */
16745 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
16746 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
16747 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
16748 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
16749 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
16750 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
16751 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
16752 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
16753 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
16754 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
16755 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
16756 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
16757 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
16758 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
16759 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
16760 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
16761 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
16762 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
16763
16764 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
16765 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
16766
16767 /* "nexthop-local unchanged" commands */
16768 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
16769 install_element(BGP_IPV6_NODE,
16770 &no_neighbor_nexthop_local_unchanged_cmd);
16771
16772 /* "neighbor next-hop-self" commands. */
16773 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
16774 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
16775 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
16776 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
16777 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
16778 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
16779 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
16780 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
16781 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
16782 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
16783 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
16784 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
16785 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
16786 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
16787 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
16788 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
16789 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
16790 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
16791 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
16792 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 16793
16794 /* "neighbor next-hop-self force" commands. */
16795 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
16796 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
16797 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16798 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16799 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
16800 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16801 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16802 install_element(BGP_IPV4_NODE,
16803 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16804 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
16805 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16806 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16807 install_element(BGP_IPV4M_NODE,
16808 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16809 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
16810 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16811 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16812 install_element(BGP_IPV4L_NODE,
16813 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16814 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
16815 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16816 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16817 install_element(BGP_IPV6_NODE,
16818 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16819 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
16820 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16821 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16822 install_element(BGP_IPV6M_NODE,
16823 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16824 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
16825 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16826 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16827 install_element(BGP_IPV6L_NODE,
16828 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16829 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
16830 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16831 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16832 install_element(BGP_VPNV4_NODE,
16833 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 16834 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
16835 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
16836 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
16837 install_element(BGP_VPNV6_NODE,
16838 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
16839 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
16840 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 16841
16842 /* "neighbor as-override" commands. */
16843 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
16844 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
16845 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
16846 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
16847 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
16848 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
16849 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
16850 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
16851 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
16852 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
16853 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
16854 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
16855 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
16856 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
16857 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
16858 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
16859 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
16860 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
16861
16862 /* "neighbor remove-private-AS" commands. */
16863 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
16864 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
16865 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
16866 install_element(BGP_NODE,
16867 &no_neighbor_remove_private_as_all_hidden_cmd);
16868 install_element(BGP_NODE,
16869 &neighbor_remove_private_as_replace_as_hidden_cmd);
16870 install_element(BGP_NODE,
16871 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
16872 install_element(BGP_NODE,
16873 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
16874 install_element(
16875 BGP_NODE,
16876 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
16877 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
16878 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
16879 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
16880 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16881 install_element(BGP_IPV4_NODE,
16882 &neighbor_remove_private_as_replace_as_cmd);
16883 install_element(BGP_IPV4_NODE,
16884 &no_neighbor_remove_private_as_replace_as_cmd);
16885 install_element(BGP_IPV4_NODE,
16886 &neighbor_remove_private_as_all_replace_as_cmd);
16887 install_element(BGP_IPV4_NODE,
16888 &no_neighbor_remove_private_as_all_replace_as_cmd);
16889 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
16890 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
16891 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
16892 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
16893 install_element(BGP_IPV4M_NODE,
16894 &neighbor_remove_private_as_replace_as_cmd);
16895 install_element(BGP_IPV4M_NODE,
16896 &no_neighbor_remove_private_as_replace_as_cmd);
16897 install_element(BGP_IPV4M_NODE,
16898 &neighbor_remove_private_as_all_replace_as_cmd);
16899 install_element(BGP_IPV4M_NODE,
16900 &no_neighbor_remove_private_as_all_replace_as_cmd);
16901 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
16902 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
16903 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
16904 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
16905 install_element(BGP_IPV4L_NODE,
16906 &neighbor_remove_private_as_replace_as_cmd);
16907 install_element(BGP_IPV4L_NODE,
16908 &no_neighbor_remove_private_as_replace_as_cmd);
16909 install_element(BGP_IPV4L_NODE,
16910 &neighbor_remove_private_as_all_replace_as_cmd);
16911 install_element(BGP_IPV4L_NODE,
16912 &no_neighbor_remove_private_as_all_replace_as_cmd);
16913 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
16914 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
16915 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
16916 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16917 install_element(BGP_IPV6_NODE,
16918 &neighbor_remove_private_as_replace_as_cmd);
16919 install_element(BGP_IPV6_NODE,
16920 &no_neighbor_remove_private_as_replace_as_cmd);
16921 install_element(BGP_IPV6_NODE,
16922 &neighbor_remove_private_as_all_replace_as_cmd);
16923 install_element(BGP_IPV6_NODE,
16924 &no_neighbor_remove_private_as_all_replace_as_cmd);
16925 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
16926 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
16927 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
16928 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
16929 install_element(BGP_IPV6M_NODE,
16930 &neighbor_remove_private_as_replace_as_cmd);
16931 install_element(BGP_IPV6M_NODE,
16932 &no_neighbor_remove_private_as_replace_as_cmd);
16933 install_element(BGP_IPV6M_NODE,
16934 &neighbor_remove_private_as_all_replace_as_cmd);
16935 install_element(BGP_IPV6M_NODE,
16936 &no_neighbor_remove_private_as_all_replace_as_cmd);
16937 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
16938 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
16939 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
16940 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
16941 install_element(BGP_IPV6L_NODE,
16942 &neighbor_remove_private_as_replace_as_cmd);
16943 install_element(BGP_IPV6L_NODE,
16944 &no_neighbor_remove_private_as_replace_as_cmd);
16945 install_element(BGP_IPV6L_NODE,
16946 &neighbor_remove_private_as_all_replace_as_cmd);
16947 install_element(BGP_IPV6L_NODE,
16948 &no_neighbor_remove_private_as_all_replace_as_cmd);
16949 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
16950 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
16951 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
16952 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
16953 install_element(BGP_VPNV4_NODE,
16954 &neighbor_remove_private_as_replace_as_cmd);
16955 install_element(BGP_VPNV4_NODE,
16956 &no_neighbor_remove_private_as_replace_as_cmd);
16957 install_element(BGP_VPNV4_NODE,
16958 &neighbor_remove_private_as_all_replace_as_cmd);
16959 install_element(BGP_VPNV4_NODE,
16960 &no_neighbor_remove_private_as_all_replace_as_cmd);
16961 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
16962 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
16963 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
16964 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
16965 install_element(BGP_VPNV6_NODE,
16966 &neighbor_remove_private_as_replace_as_cmd);
16967 install_element(BGP_VPNV6_NODE,
16968 &no_neighbor_remove_private_as_replace_as_cmd);
16969 install_element(BGP_VPNV6_NODE,
16970 &neighbor_remove_private_as_all_replace_as_cmd);
16971 install_element(BGP_VPNV6_NODE,
16972 &no_neighbor_remove_private_as_all_replace_as_cmd);
16973
16974 /* "neighbor send-community" commands.*/
16975 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
16976 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
16977 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
16978 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
16979 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
16980 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
16981 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
16982 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
16983 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
16984 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
16985 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
16986 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
16987 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
16988 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
16989 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
16990 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
16991 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
16992 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
16993 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
16994 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
16995 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
16996 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
16997 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
16998 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
16999 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
17000 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
17001 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
17002 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
17003 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
17004 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
17005 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
17006 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
17007 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
17008 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
17009 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
17010 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
17011
17012 /* "neighbor route-reflector" commands.*/
17013 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
17014 install_element(BGP_NODE,
17015 &no_neighbor_route_reflector_client_hidden_cmd);
17016 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
17017 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
17018 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
17019 install_element(BGP_IPV4M_NODE,
17020 &no_neighbor_route_reflector_client_cmd);
17021 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
17022 install_element(BGP_IPV4L_NODE,
17023 &no_neighbor_route_reflector_client_cmd);
17024 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
17025 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
17026 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
17027 install_element(BGP_IPV6M_NODE,
17028 &no_neighbor_route_reflector_client_cmd);
17029 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
17030 install_element(BGP_IPV6L_NODE,
17031 &no_neighbor_route_reflector_client_cmd);
17032 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
17033 install_element(BGP_VPNV4_NODE,
17034 &no_neighbor_route_reflector_client_cmd);
17035 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
17036 install_element(BGP_VPNV6_NODE,
17037 &no_neighbor_route_reflector_client_cmd);
7c40bf39 17038 install_element(BGP_FLOWSPECV4_NODE,
17039 &neighbor_route_reflector_client_cmd);
17040 install_element(BGP_FLOWSPECV4_NODE,
17041 &no_neighbor_route_reflector_client_cmd);
17042 install_element(BGP_FLOWSPECV6_NODE,
17043 &neighbor_route_reflector_client_cmd);
17044 install_element(BGP_FLOWSPECV6_NODE,
17045 &no_neighbor_route_reflector_client_cmd);
d62a17ae 17046 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
17047 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
17048
17049 /* "neighbor route-server" commands.*/
17050 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
17051 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
17052 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
17053 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
17054 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
17055 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
17056 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
17057 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
17058 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
17059 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
17060 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
17061 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
17062 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
17063 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
17064 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
17065 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
17066 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
17067 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
17068 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
17069 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 17070 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
17071 install_element(BGP_FLOWSPECV4_NODE,
17072 &no_neighbor_route_server_client_cmd);
17073 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
17074 install_element(BGP_FLOWSPECV6_NODE,
17075 &no_neighbor_route_server_client_cmd);
d62a17ae 17076
17077 /* "neighbor addpath-tx-all-paths" commands.*/
17078 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
17079 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
17080 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17081 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17082 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17083 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17084 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17085 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17086 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17087 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17088 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
17089 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17090 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
17091 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17092 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
17093 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17094 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
17095 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
17096
17097 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
17098 install_element(BGP_NODE,
17099 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17100 install_element(BGP_NODE,
17101 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
17102 install_element(BGP_IPV4_NODE,
17103 &neighbor_addpath_tx_bestpath_per_as_cmd);
17104 install_element(BGP_IPV4_NODE,
17105 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17106 install_element(BGP_IPV4M_NODE,
17107 &neighbor_addpath_tx_bestpath_per_as_cmd);
17108 install_element(BGP_IPV4M_NODE,
17109 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17110 install_element(BGP_IPV4L_NODE,
17111 &neighbor_addpath_tx_bestpath_per_as_cmd);
17112 install_element(BGP_IPV4L_NODE,
17113 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17114 install_element(BGP_IPV6_NODE,
17115 &neighbor_addpath_tx_bestpath_per_as_cmd);
17116 install_element(BGP_IPV6_NODE,
17117 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17118 install_element(BGP_IPV6M_NODE,
17119 &neighbor_addpath_tx_bestpath_per_as_cmd);
17120 install_element(BGP_IPV6M_NODE,
17121 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17122 install_element(BGP_IPV6L_NODE,
17123 &neighbor_addpath_tx_bestpath_per_as_cmd);
17124 install_element(BGP_IPV6L_NODE,
17125 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17126 install_element(BGP_VPNV4_NODE,
17127 &neighbor_addpath_tx_bestpath_per_as_cmd);
17128 install_element(BGP_VPNV4_NODE,
17129 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17130 install_element(BGP_VPNV6_NODE,
17131 &neighbor_addpath_tx_bestpath_per_as_cmd);
17132 install_element(BGP_VPNV6_NODE,
17133 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
17134
2b31007c
RZ
17135 /* "neighbor sender-as-path-loop-detection" commands. */
17136 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
17137 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
17138
d62a17ae 17139 /* "neighbor passive" commands. */
17140 install_element(BGP_NODE, &neighbor_passive_cmd);
17141 install_element(BGP_NODE, &no_neighbor_passive_cmd);
17142
17143
17144 /* "neighbor shutdown" commands. */
17145 install_element(BGP_NODE, &neighbor_shutdown_cmd);
17146 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
17147 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
17148 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
17149 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
17150 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 17151
17152 /* "neighbor capability extended-nexthop" commands.*/
17153 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
17154 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
17155
17156 /* "neighbor capability orf prefix-list" commands.*/
17157 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
17158 install_element(BGP_NODE,
17159 &no_neighbor_capability_orf_prefix_hidden_cmd);
17160 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
17161 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
17162 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
17163 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17164 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
17165 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17166 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
17167 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
17168 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
17169 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
17170 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
17171 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
17172
17173 /* "neighbor capability dynamic" commands.*/
17174 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
17175 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
17176
17177 /* "neighbor dont-capability-negotiate" commands. */
17178 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
17179 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
17180
17181 /* "neighbor ebgp-multihop" commands. */
17182 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
17183 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
17184 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
17185
17186 /* "neighbor disable-connected-check" commands. */
17187 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
17188 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
17189
47cbc09b
PM
17190 /* "neighbor enforce-first-as" commands. */
17191 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
17192 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
17193
d62a17ae 17194 /* "neighbor description" commands. */
17195 install_element(BGP_NODE, &neighbor_description_cmd);
17196 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 17197 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 17198
17199 /* "neighbor update-source" commands. "*/
17200 install_element(BGP_NODE, &neighbor_update_source_cmd);
17201 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
17202
17203 /* "neighbor default-originate" commands. */
17204 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
17205 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
17206 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
17207 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
17208 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
17209 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
17210 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
17211 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
17212 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
17213 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
17214 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
17215 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
17216 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
17217 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
17218 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
17219 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
17220 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
17221 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
17222 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
17223 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
17224 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
17225
17226 /* "neighbor port" commands. */
17227 install_element(BGP_NODE, &neighbor_port_cmd);
17228 install_element(BGP_NODE, &no_neighbor_port_cmd);
17229
17230 /* "neighbor weight" commands. */
17231 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
17232 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
17233
17234 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
17235 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
17236 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
17237 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
17238 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
17239 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
17240 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
17241 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
17242 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
17243 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
17244 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
17245 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
17246 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
17247 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
17248 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
17249 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
17250
17251 /* "neighbor override-capability" commands. */
17252 install_element(BGP_NODE, &neighbor_override_capability_cmd);
17253 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
17254
17255 /* "neighbor strict-capability-match" commands. */
17256 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
17257 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
17258
17259 /* "neighbor timers" commands. */
17260 install_element(BGP_NODE, &neighbor_timers_cmd);
17261 install_element(BGP_NODE, &no_neighbor_timers_cmd);
17262
17263 /* "neighbor timers connect" commands. */
17264 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
17265 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
17266
17267 /* "neighbor advertisement-interval" commands. */
17268 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
17269 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
17270
17271 /* "neighbor interface" commands. */
17272 install_element(BGP_NODE, &neighbor_interface_cmd);
17273 install_element(BGP_NODE, &no_neighbor_interface_cmd);
17274
17275 /* "neighbor distribute" commands. */
17276 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
17277 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
17278 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
17279 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
17280 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
17281 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
17282 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
17283 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
17284 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
17285 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
17286 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
17287 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
17288 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
17289 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
17290 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
17291 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
17292 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
17293 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
17294
17295 /* "neighbor prefix-list" commands. */
17296 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
17297 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
17298 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
17299 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
17300 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
17301 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
17302 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
17303 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
17304 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
17305 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
17306 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
17307 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
17308 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
17309 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
17310 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
17311 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
17312 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
17313 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
7c40bf39 17314 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
17315 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
17316 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
17317 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
d62a17ae 17318
17319 /* "neighbor filter-list" commands. */
17320 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
17321 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
17322 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
17323 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
17324 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
17325 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
17326 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
17327 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
17328 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
17329 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
17330 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
17331 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
17332 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
17333 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
17334 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
17335 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
17336 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
17337 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 17338 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
17339 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
17340 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
17341 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 17342
17343 /* "neighbor route-map" commands. */
17344 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
17345 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
17346 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
17347 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
17348 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
17349 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
17350 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
17351 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
17352 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
17353 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
17354 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
17355 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
17356 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
17357 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
17358 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
17359 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
17360 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
17361 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
7c40bf39 17362 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
17363 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
17364 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
17365 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
17366 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
17367 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 17368
17369 /* "neighbor unsuppress-map" commands. */
17370 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
17371 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
17372 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
17373 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
17374 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
17375 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
17376 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
17377 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
17378 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
17379 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
17380 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
17381 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
17382 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
17383 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
17384 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
17385 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
17386 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
17387 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
17388
fde246e8
DA
17389 /* neighbor maximum-prefix-out commands. */
17390 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
17391 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
17392 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
17393 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17394 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
17395 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17396 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
17397 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17398 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
17399 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17400 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
17401 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
17402 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
17403 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
17404 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
17405 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
17406 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
17407 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
17408
d62a17ae 17409 /* "neighbor maximum-prefix" commands. */
17410 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
17411 install_element(BGP_NODE,
17412 &neighbor_maximum_prefix_threshold_hidden_cmd);
17413 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
17414 install_element(BGP_NODE,
17415 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
17416 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
17417 install_element(BGP_NODE,
17418 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
17419 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
17420 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
17421 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17422 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17423 install_element(BGP_IPV4_NODE,
17424 &neighbor_maximum_prefix_threshold_warning_cmd);
17425 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17426 install_element(BGP_IPV4_NODE,
17427 &neighbor_maximum_prefix_threshold_restart_cmd);
17428 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
17429 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
17430 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17431 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
17432 install_element(BGP_IPV4M_NODE,
17433 &neighbor_maximum_prefix_threshold_warning_cmd);
17434 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
17435 install_element(BGP_IPV4M_NODE,
17436 &neighbor_maximum_prefix_threshold_restart_cmd);
17437 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
17438 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
17439 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17440 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
17441 install_element(BGP_IPV4L_NODE,
17442 &neighbor_maximum_prefix_threshold_warning_cmd);
17443 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
17444 install_element(BGP_IPV4L_NODE,
17445 &neighbor_maximum_prefix_threshold_restart_cmd);
17446 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
17447 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
17448 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17449 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17450 install_element(BGP_IPV6_NODE,
17451 &neighbor_maximum_prefix_threshold_warning_cmd);
17452 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17453 install_element(BGP_IPV6_NODE,
17454 &neighbor_maximum_prefix_threshold_restart_cmd);
17455 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
17456 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
17457 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
17458 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
17459 install_element(BGP_IPV6M_NODE,
17460 &neighbor_maximum_prefix_threshold_warning_cmd);
17461 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
17462 install_element(BGP_IPV6M_NODE,
17463 &neighbor_maximum_prefix_threshold_restart_cmd);
17464 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
17465 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
17466 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
17467 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
17468 install_element(BGP_IPV6L_NODE,
17469 &neighbor_maximum_prefix_threshold_warning_cmd);
17470 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
17471 install_element(BGP_IPV6L_NODE,
17472 &neighbor_maximum_prefix_threshold_restart_cmd);
17473 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
17474 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
17475 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
17476 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
17477 install_element(BGP_VPNV4_NODE,
17478 &neighbor_maximum_prefix_threshold_warning_cmd);
17479 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
17480 install_element(BGP_VPNV4_NODE,
17481 &neighbor_maximum_prefix_threshold_restart_cmd);
17482 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
17483 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
17484 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
17485 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
17486 install_element(BGP_VPNV6_NODE,
17487 &neighbor_maximum_prefix_threshold_warning_cmd);
17488 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
17489 install_element(BGP_VPNV6_NODE,
17490 &neighbor_maximum_prefix_threshold_restart_cmd);
17491 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
17492
17493 /* "neighbor allowas-in" */
17494 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
17495 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
17496 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
17497 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
17498 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
17499 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
17500 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
17501 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
17502 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
17503 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
17504 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
17505 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
17506 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
17507 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
17508 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
17509 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
17510 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
17511 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
17512 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
17513 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
17514
17515 /* address-family commands. */
17516 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
17517 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 17518#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 17519 install_element(BGP_NODE, &address_family_vpnv4_cmd);
17520 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 17521#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 17522
d62a17ae 17523 install_element(BGP_NODE, &address_family_evpn_cmd);
17524
17525 /* "exit-address-family" command. */
17526 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
17527 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
17528 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
17529 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
17530 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
17531 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
17532 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
17533 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 17534 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
17535 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 17536 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
17537
17538 /* "clear ip bgp commands" */
17539 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
17540
17541 /* clear ip bgp prefix */
17542 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
17543 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
17544 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
17545
17546 /* "show [ip] bgp summary" commands. */
17547 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 17548 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 17549 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 17550 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 17551 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
17552 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 17553 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
17554
17555 /* "show [ip] bgp neighbors" commands. */
17556 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
17557
36235319 17558 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 17559
d62a17ae 17560 /* "show [ip] bgp peer-group" commands. */
17561 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
17562
17563 /* "show [ip] bgp paths" commands. */
17564 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
17565
17566 /* "show [ip] bgp community" commands. */
17567 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
17568
17569 /* "show ip bgp large-community" commands. */
17570 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
17571 /* "show [ip] bgp attribute-info" commands. */
17572 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 17573 /* "show [ip] bgp route-leak" command */
17574 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 17575
17576 /* "redistribute" commands. */
17577 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
17578 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
17579 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
17580 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
17581 install_element(BGP_NODE,
17582 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
17583 install_element(BGP_NODE,
17584 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
17585 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
17586 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
17587 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
17588 install_element(BGP_NODE,
17589 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
17590 install_element(BGP_NODE,
17591 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
17592 install_element(BGP_NODE,
17593 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
17594 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
17595 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
17596 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
17597 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
17598 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
17599 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
17600 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
17601 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
17602 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
17603 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
17604 install_element(BGP_IPV4_NODE,
17605 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
17606 install_element(BGP_IPV4_NODE,
17607 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
17608 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
17609 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
17610 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
17611 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
17612 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
17613 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
17614
b9c7bc5a
PZ
17615 /* import|export vpn [route-map WORD] */
17616 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
17617 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 17618
12a844a5
DS
17619 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
17620 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
17621
d62a17ae 17622 /* ttl_security commands */
17623 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
17624 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
17625
17626 /* "show [ip] bgp memory" commands. */
17627 install_element(VIEW_NODE, &show_bgp_memory_cmd);
17628
acf71666
MK
17629 /* "show bgp martian next-hop" */
17630 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
17631
48ecf8f5
DS
17632 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
17633
d62a17ae 17634 /* "show [ip] bgp views" commands. */
17635 install_element(VIEW_NODE, &show_bgp_views_cmd);
17636
17637 /* "show [ip] bgp vrfs" commands. */
17638 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
17639
17640 /* Community-list. */
17641 community_list_vty();
ddb5b488
PZ
17642
17643 /* vpn-policy commands */
b9c7bc5a
PZ
17644 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
17645 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
17646 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
17647 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
17648 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
17649 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
17650 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
17651 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
17652 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
17653 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
17654 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
17655 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 17656
301ad80a
PG
17657 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
17658 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
17659
b9c7bc5a
PZ
17660 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
17661 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
17662 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
17663 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
17664 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
17665 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
17666 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
17667 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
17668 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
17669 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
718e3744 17670}
6b0655a2 17671
718e3744 17672#include "memory.h"
17673#include "bgp_regex.h"
17674#include "bgp_clist.h"
17675#include "bgp_ecommunity.h"
17676
17677/* VTY functions. */
17678
17679/* Direction value to string conversion. */
d62a17ae 17680static const char *community_direct_str(int direct)
17681{
17682 switch (direct) {
17683 case COMMUNITY_DENY:
17684 return "deny";
17685 case COMMUNITY_PERMIT:
17686 return "permit";
17687 default:
17688 return "unknown";
17689 }
718e3744 17690}
17691
17692/* Display error string. */
d62a17ae 17693static void community_list_perror(struct vty *vty, int ret)
17694{
17695 switch (ret) {
17696 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
17697 vty_out(vty, "%% Can't find community-list\n");
17698 break;
17699 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
17700 vty_out(vty, "%% Malformed community-list value\n");
17701 break;
17702 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
17703 vty_out(vty,
17704 "%% Community name conflict, previously defined as standard community\n");
17705 break;
17706 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
17707 vty_out(vty,
17708 "%% Community name conflict, previously defined as expanded community\n");
17709 break;
17710 }
718e3744 17711}
17712
5bf15956
DW
17713/* "community-list" keyword help string. */
17714#define COMMUNITY_LIST_STR "Add a community list entry\n"
17715
7336e101
SP
17716/*community-list standard */
17717DEFUN (community_list_standard,
17718 bgp_community_list_standard_cmd,
2f8cc0e5 17719 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 17720 BGP_STR
718e3744 17721 COMMUNITY_LIST_STR
17722 "Community list number (standard)\n"
5bf15956 17723 "Add an standard community-list entry\n"
718e3744 17724 "Community list name\n"
2f8cc0e5
DA
17725 "Sequence number of an entry\n"
17726 "Sequence number\n"
718e3744 17727 "Specify community to reject\n"
17728 "Specify community to accept\n"
17729 COMMUNITY_VAL_STR)
17730{
d62a17ae 17731 char *cl_name_or_number = NULL;
2f8cc0e5 17732 char *seq = NULL;
d62a17ae 17733 int direct = 0;
17734 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 17735 int idx = 0;
7336e101 17736
2f8cc0e5
DA
17737 argv_find(argv, argc, "(1-4294967295)", &idx);
17738 if (idx)
17739 seq = argv[idx]->arg;
17740
17741 idx = 0;
d62a17ae 17742 argv_find(argv, argc, "(1-99)", &idx);
17743 argv_find(argv, argc, "WORD", &idx);
17744 cl_name_or_number = argv[idx]->arg;
17745 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17746 : COMMUNITY_DENY;
17747 argv_find(argv, argc, "AA:NN", &idx);
17748 char *str = argv_concat(argv, argc, idx);
42f914d4 17749
2f8cc0e5
DA
17750 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17751 direct, style);
42f914d4 17752
d62a17ae 17753 XFREE(MTYPE_TMP, str);
42f914d4 17754
d62a17ae 17755 if (ret < 0) {
17756 /* Display error string. */
17757 community_list_perror(vty, ret);
17758 return CMD_WARNING_CONFIG_FAILED;
17759 }
42f914d4 17760
d62a17ae 17761 return CMD_SUCCESS;
718e3744 17762}
17763
7336e101
SP
17764DEFUN (no_community_list_standard_all,
17765 no_bgp_community_list_standard_all_cmd,
2f8cc0e5 17766 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17767 NO_STR
17768 BGP_STR
17769 COMMUNITY_LIST_STR
17770 "Community list number (standard)\n"
17771 "Add an standard community-list entry\n"
17772 "Community list name\n"
2f8cc0e5
DA
17773 "Sequence number of an entry\n"
17774 "Sequence number\n"
7336e101
SP
17775 "Specify community to reject\n"
17776 "Specify community to accept\n"
17777 COMMUNITY_VAL_STR)
718e3744 17778{
d62a17ae 17779 char *cl_name_or_number = NULL;
174b5cb9 17780 char *str = NULL;
d62a17ae 17781 int direct = 0;
17782 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 17783 char *seq = NULL;
d62a17ae 17784 int idx = 0;
7336e101 17785
2f8cc0e5
DA
17786 argv_find(argv, argc, "(1-4294967295)", &idx);
17787 if (idx)
17788 seq = argv[idx]->arg;
17789
17790 idx = 0;
174b5cb9
DA
17791 argv_find(argv, argc, "permit", &idx);
17792 argv_find(argv, argc, "deny", &idx);
17793
17794 if (idx) {
17795 direct = argv_find(argv, argc, "permit", &idx)
17796 ? COMMUNITY_PERMIT
17797 : COMMUNITY_DENY;
17798
17799 idx = 0;
17800 argv_find(argv, argc, "AA:NN", &idx);
17801 str = argv_concat(argv, argc, idx);
17802 }
17803
17804 idx = 0;
d62a17ae 17805 argv_find(argv, argc, "(1-99)", &idx);
17806 argv_find(argv, argc, "WORD", &idx);
17807 cl_name_or_number = argv[idx]->arg;
42f914d4 17808
2f8cc0e5 17809 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17810 direct, style);
42f914d4 17811
d62a17ae 17812 XFREE(MTYPE_TMP, str);
daf9ddbb 17813
d62a17ae 17814 if (ret < 0) {
17815 community_list_perror(vty, ret);
17816 return CMD_WARNING_CONFIG_FAILED;
17817 }
42f914d4 17818
d62a17ae 17819 return CMD_SUCCESS;
718e3744 17820}
7336e101 17821
174b5cb9
DA
17822ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
17823 "no bgp community-list <(1-99)|standard WORD>",
17824 NO_STR BGP_STR COMMUNITY_LIST_STR
17825 "Community list number (standard)\n"
17826 "Add an standard community-list entry\n"
17827 "Community list name\n")
17828
7336e101
SP
17829/*community-list expanded */
17830DEFUN (community_list_expanded_all,
17831 bgp_community_list_expanded_all_cmd,
2f8cc0e5 17832 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17833 BGP_STR
17834 COMMUNITY_LIST_STR
718e3744 17835 "Community list number (expanded)\n"
5bf15956 17836 "Add an expanded community-list entry\n"
718e3744 17837 "Community list name\n"
2f8cc0e5
DA
17838 "Sequence number of an entry\n"
17839 "Sequence number\n"
718e3744 17840 "Specify community to reject\n"
17841 "Specify community to accept\n"
17842 COMMUNITY_VAL_STR)
17843{
d62a17ae 17844 char *cl_name_or_number = NULL;
2f8cc0e5 17845 char *seq = NULL;
d62a17ae 17846 int direct = 0;
17847 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17848 int idx = 0;
7b9a4750 17849
2f8cc0e5
DA
17850 argv_find(argv, argc, "(1-4294967295)", &idx);
17851 if (idx)
17852 seq = argv[idx]->arg;
17853
17854 idx = 0;
17855
d62a17ae 17856 argv_find(argv, argc, "(100-500)", &idx);
17857 argv_find(argv, argc, "WORD", &idx);
17858 cl_name_or_number = argv[idx]->arg;
17859 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
17860 : COMMUNITY_DENY;
17861 argv_find(argv, argc, "AA:NN", &idx);
17862 char *str = argv_concat(argv, argc, idx);
42f914d4 17863
2f8cc0e5
DA
17864 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
17865 direct, style);
42f914d4 17866
d62a17ae 17867 XFREE(MTYPE_TMP, str);
42f914d4 17868
d62a17ae 17869 if (ret < 0) {
17870 /* Display error string. */
17871 community_list_perror(vty, ret);
17872 return CMD_WARNING_CONFIG_FAILED;
17873 }
42f914d4 17874
d62a17ae 17875 return CMD_SUCCESS;
718e3744 17876}
17877
7336e101
SP
17878DEFUN (no_community_list_expanded_all,
17879 no_bgp_community_list_expanded_all_cmd,
2f8cc0e5 17880 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
17881 NO_STR
17882 BGP_STR
17883 COMMUNITY_LIST_STR
17884 "Community list number (expanded)\n"
17885 "Add an expanded community-list entry\n"
17886 "Community list name\n"
2f8cc0e5
DA
17887 "Sequence number of an entry\n"
17888 "Sequence number\n"
7336e101
SP
17889 "Specify community to reject\n"
17890 "Specify community to accept\n"
17891 COMMUNITY_VAL_STR)
718e3744 17892{
d62a17ae 17893 char *cl_name_or_number = NULL;
2f8cc0e5 17894 char *seq = NULL;
174b5cb9 17895 char *str = NULL;
d62a17ae 17896 int direct = 0;
17897 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 17898 int idx = 0;
174b5cb9 17899
2f8cc0e5
DA
17900 argv_find(argv, argc, "(1-4294967295)", &idx);
17901 if (idx)
17902 seq = argv[idx]->arg;
17903
17904 idx = 0;
174b5cb9
DA
17905 argv_find(argv, argc, "permit", &idx);
17906 argv_find(argv, argc, "deny", &idx);
17907
17908 if (idx) {
17909 direct = argv_find(argv, argc, "permit", &idx)
17910 ? COMMUNITY_PERMIT
17911 : COMMUNITY_DENY;
17912
17913 idx = 0;
17914 argv_find(argv, argc, "AA:NN", &idx);
17915 str = argv_concat(argv, argc, idx);
7336e101 17916 }
174b5cb9
DA
17917
17918 idx = 0;
d62a17ae 17919 argv_find(argv, argc, "(100-500)", &idx);
17920 argv_find(argv, argc, "WORD", &idx);
17921 cl_name_or_number = argv[idx]->arg;
42f914d4 17922
2f8cc0e5 17923 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 17924 direct, style);
42f914d4 17925
d62a17ae 17926 XFREE(MTYPE_TMP, str);
daf9ddbb 17927
d62a17ae 17928 if (ret < 0) {
17929 community_list_perror(vty, ret);
17930 return CMD_WARNING_CONFIG_FAILED;
17931 }
42f914d4 17932
d62a17ae 17933 return CMD_SUCCESS;
718e3744 17934}
17935
174b5cb9
DA
17936ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
17937 "no bgp community-list <(100-500)|expanded WORD>",
17938 NO_STR IP_STR COMMUNITY_LIST_STR
17939 "Community list number (expanded)\n"
17940 "Add an expanded community-list entry\n"
17941 "Community list name\n")
17942
8d9b8ed9
PM
17943/* Return configuration string of community-list entry. */
17944static const char *community_list_config_str(struct community_entry *entry)
17945{
17946 const char *str;
17947
17948 if (entry->any)
17949 str = "";
17950 else {
17951 if (entry->style == COMMUNITY_LIST_STANDARD)
17952 str = community_str(entry->u.com, false);
17953 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
17954 str = lcommunity_str(entry->u.lcom, false);
17955 else
17956 str = entry->config;
17957 }
17958 return str;
17959}
17960
d62a17ae 17961static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 17962{
d62a17ae 17963 struct community_entry *entry;
718e3744 17964
d62a17ae 17965 for (entry = list->head; entry; entry = entry->next) {
17966 if (entry == list->head) {
17967 if (all_digit(list->name))
17968 vty_out(vty, "Community %s list %s\n",
17969 entry->style == COMMUNITY_LIST_STANDARD
17970 ? "standard"
17971 : "(expanded) access",
17972 list->name);
17973 else
17974 vty_out(vty, "Named Community %s list %s\n",
17975 entry->style == COMMUNITY_LIST_STANDARD
17976 ? "standard"
17977 : "expanded",
17978 list->name);
17979 }
17980 if (entry->any)
17981 vty_out(vty, " %s\n",
17982 community_direct_str(entry->direct));
17983 else
17984 vty_out(vty, " %s %s\n",
17985 community_direct_str(entry->direct),
8d9b8ed9 17986 community_list_config_str(entry));
d62a17ae 17987 }
718e3744 17988}
17989
7336e101
SP
17990DEFUN (show_community_list,
17991 show_bgp_community_list_cmd,
17992 "show bgp community-list",
718e3744 17993 SHOW_STR
7336e101 17994 BGP_STR
718e3744 17995 "List community-list\n")
17996{
d62a17ae 17997 struct community_list *list;
17998 struct community_list_master *cm;
718e3744 17999
d62a17ae 18000 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18001 if (!cm)
18002 return CMD_SUCCESS;
718e3744 18003
d62a17ae 18004 for (list = cm->num.head; list; list = list->next)
18005 community_list_show(vty, list);
718e3744 18006
d62a17ae 18007 for (list = cm->str.head; list; list = list->next)
18008 community_list_show(vty, list);
718e3744 18009
d62a17ae 18010 return CMD_SUCCESS;
718e3744 18011}
18012
7336e101
SP
18013DEFUN (show_community_list_arg,
18014 show_bgp_community_list_arg_cmd,
960b69b9 18015 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
18016 SHOW_STR
18017 BGP_STR
718e3744 18018 "List community-list\n"
18019 "Community-list number\n"
960b69b9 18020 "Community-list name\n"
18021 "Detailed information on community-list\n")
718e3744 18022{
d62a17ae 18023 int idx_comm_list = 3;
18024 struct community_list *list;
718e3744 18025
e237b0d2 18026 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18027 COMMUNITY_LIST_MASTER);
18028 if (!list) {
18029 vty_out(vty, "%% Can't find community-list\n");
18030 return CMD_WARNING;
18031 }
718e3744 18032
d62a17ae 18033 community_list_show(vty, list);
718e3744 18034
d62a17ae 18035 return CMD_SUCCESS;
718e3744 18036}
6b0655a2 18037
57d187bc
JS
18038/*
18039 * Large Community code.
18040 */
d62a17ae 18041static int lcommunity_list_set_vty(struct vty *vty, int argc,
18042 struct cmd_token **argv, int style,
18043 int reject_all_digit_name)
18044{
18045 int ret;
18046 int direct;
18047 char *str;
18048 int idx = 0;
18049 char *cl_name;
2f8cc0e5
DA
18050 char *seq = NULL;
18051
947073e3 18052 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18053 seq = argv[idx]->arg;
d62a17ae 18054
2f8cc0e5 18055 idx = 0;
d62a17ae 18056 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18057 : COMMUNITY_DENY;
18058
18059 /* All digit name check. */
18060 idx = 0;
18061 argv_find(argv, argc, "WORD", &idx);
18062 argv_find(argv, argc, "(1-99)", &idx);
18063 argv_find(argv, argc, "(100-500)", &idx);
18064 cl_name = argv[idx]->arg;
18065 if (reject_all_digit_name && all_digit(cl_name)) {
18066 vty_out(vty, "%% Community name cannot have all digits\n");
18067 return CMD_WARNING_CONFIG_FAILED;
18068 }
18069
18070 idx = 0;
18071 argv_find(argv, argc, "AA:BB:CC", &idx);
18072 argv_find(argv, argc, "LINE", &idx);
18073 /* Concat community string argument. */
18074 if (idx)
18075 str = argv_concat(argv, argc, idx);
18076 else
18077 str = NULL;
18078
2f8cc0e5 18079 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 18080
18081 /* Free temporary community list string allocated by
18082 argv_concat(). */
0a22ddfb 18083 XFREE(MTYPE_TMP, str);
d62a17ae 18084
18085 if (ret < 0) {
18086 community_list_perror(vty, ret);
18087 return CMD_WARNING_CONFIG_FAILED;
18088 }
18089 return CMD_SUCCESS;
18090}
18091
18092static int lcommunity_list_unset_vty(struct vty *vty, int argc,
18093 struct cmd_token **argv, int style)
18094{
18095 int ret;
18096 int direct = 0;
18097 char *str = NULL;
18098 int idx = 0;
2f8cc0e5 18099 char *seq = NULL;
d62a17ae 18100
947073e3 18101 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5 18102 seq = argv[idx]->arg;
d62a17ae 18103
2f8cc0e5 18104 idx = 0;
d62a17ae 18105 argv_find(argv, argc, "permit", &idx);
18106 argv_find(argv, argc, "deny", &idx);
18107
18108 if (idx) {
18109 /* Check the list direct. */
18110 if (strncmp(argv[idx]->arg, "p", 1) == 0)
18111 direct = COMMUNITY_PERMIT;
18112 else
18113 direct = COMMUNITY_DENY;
18114
18115 idx = 0;
18116 argv_find(argv, argc, "LINE", &idx);
18117 argv_find(argv, argc, "AA:AA:NN", &idx);
18118 /* Concat community string argument. */
18119 str = argv_concat(argv, argc, idx);
18120 }
18121
18122 idx = 0;
18123 argv_find(argv, argc, "(1-99)", &idx);
18124 argv_find(argv, argc, "(100-500)", &idx);
18125 argv_find(argv, argc, "WORD", &idx);
18126
18127 /* Unset community list. */
2f8cc0e5 18128 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 18129 style);
18130
18131 /* Free temporary community list string allocated by
18132 argv_concat(). */
0a22ddfb 18133 XFREE(MTYPE_TMP, str);
d62a17ae 18134
18135 if (ret < 0) {
18136 community_list_perror(vty, ret);
18137 return CMD_WARNING_CONFIG_FAILED;
18138 }
18139
18140 return CMD_SUCCESS;
57d187bc
JS
18141}
18142
18143/* "large-community-list" keyword help string. */
18144#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
18145#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
18146
7336e101
SP
18147DEFUN (lcommunity_list_standard,
18148 bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18149 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18150 BGP_STR
18151 LCOMMUNITY_LIST_STR
18152 "Large Community list number (standard)\n"
2f8cc0e5
DA
18153 "Sequence number of an entry\n"
18154 "Sequence number\n"
7336e101
SP
18155 "Specify large community to reject\n"
18156 "Specify large community to accept\n"
18157 LCOMMUNITY_VAL_STR)
52951b63 18158{
d62a17ae 18159 return lcommunity_list_set_vty(vty, argc, argv,
18160 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
18161}
18162
7336e101
SP
18163DEFUN (lcommunity_list_expanded,
18164 bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18165 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18166 BGP_STR
18167 LCOMMUNITY_LIST_STR
18168 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18169 "Sequence number of an entry\n"
18170 "Sequence number\n"
7336e101
SP
18171 "Specify large community to reject\n"
18172 "Specify large community to accept\n"
18173 "An ordered list as a regular-expression\n")
57d187bc 18174{
d62a17ae 18175 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18176 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
18177}
18178
7336e101
SP
18179DEFUN (lcommunity_list_name_standard,
18180 bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18181 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
18182 BGP_STR
18183 LCOMMUNITY_LIST_STR
18184 "Specify standard large-community-list\n"
18185 "Large Community list name\n"
2f8cc0e5
DA
18186 "Sequence number of an entry\n"
18187 "Sequence number\n"
7336e101
SP
18188 "Specify large community to reject\n"
18189 "Specify large community to accept\n"
18190 LCOMMUNITY_VAL_STR)
52951b63 18191{
d62a17ae 18192 return lcommunity_list_set_vty(vty, argc, argv,
18193 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
18194}
18195
7336e101
SP
18196DEFUN (lcommunity_list_name_expanded,
18197 bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18198 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18199 BGP_STR
18200 LCOMMUNITY_LIST_STR
18201 "Specify expanded large-community-list\n"
18202 "Large Community list name\n"
2f8cc0e5
DA
18203 "Sequence number of an entry\n"
18204 "Sequence number\n"
7336e101
SP
18205 "Specify large community to reject\n"
18206 "Specify large community to accept\n"
18207 "An ordered list as a regular-expression\n")
57d187bc 18208{
d62a17ae 18209 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 18210 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
18211}
18212
4378f57c
DA
18213DEFUN (no_lcommunity_list_all,
18214 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
18215 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
18216 NO_STR
18217 BGP_STR
18218 LCOMMUNITY_LIST_STR
18219 "Large Community list number (standard)\n"
18220 "Large Community list number (expanded)\n"
18221 "Large Community list name\n")
57d187bc 18222{
7336e101
SP
18223 return lcommunity_list_unset_vty(vty, argc, argv,
18224 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18225}
18226
4378f57c
DA
18227DEFUN (no_lcommunity_list_name_standard_all,
18228 no_bgp_lcommunity_list_name_standard_all_cmd,
18229 "no bgp large-community-list standard WORD",
18230 NO_STR
18231 BGP_STR
18232 LCOMMUNITY_LIST_STR
18233 "Specify standard large-community-list\n"
18234 "Large Community list name\n")
18235{
18236 return lcommunity_list_unset_vty(vty, argc, argv,
18237 LARGE_COMMUNITY_LIST_STANDARD);
18238}
18239
7336e101
SP
18240DEFUN (no_lcommunity_list_name_expanded_all,
18241 no_bgp_lcommunity_list_name_expanded_all_cmd,
18242 "no bgp large-community-list expanded WORD",
18243 NO_STR
18244 BGP_STR
18245 LCOMMUNITY_LIST_STR
18246 "Specify expanded large-community-list\n"
18247 "Large Community list name\n")
57d187bc 18248{
d62a17ae 18249 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18250 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18251}
18252
7336e101
SP
18253DEFUN (no_lcommunity_list_standard,
18254 no_bgp_lcommunity_list_standard_cmd,
2f8cc0e5 18255 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18256 NO_STR
18257 BGP_STR
18258 LCOMMUNITY_LIST_STR
18259 "Large Community list number (standard)\n"
2f8cc0e5
DA
18260 "Sequence number of an entry\n"
18261 "Sequence number\n"
7336e101
SP
18262 "Specify large community to reject\n"
18263 "Specify large community to accept\n"
18264 LCOMMUNITY_VAL_STR)
57d187bc 18265{
d62a17ae 18266 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18267 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18268}
18269
7336e101
SP
18270DEFUN (no_lcommunity_list_expanded,
18271 no_bgp_lcommunity_list_expanded_cmd,
2f8cc0e5 18272 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18273 NO_STR
18274 BGP_STR
18275 LCOMMUNITY_LIST_STR
18276 "Large Community list number (expanded)\n"
2f8cc0e5
DA
18277 "Sequence number of an entry\n"
18278 "Sequence number\n"
7336e101
SP
18279 "Specify large community to reject\n"
18280 "Specify large community to accept\n"
18281 "An ordered list as a regular-expression\n")
57d187bc 18282{
d62a17ae 18283 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18284 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18285}
18286
7336e101
SP
18287DEFUN (no_lcommunity_list_name_standard,
18288 no_bgp_lcommunity_list_name_standard_cmd,
2f8cc0e5 18289 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
18290 NO_STR
18291 BGP_STR
18292 LCOMMUNITY_LIST_STR
18293 "Specify standard large-community-list\n"
18294 "Large Community list name\n"
2f8cc0e5
DA
18295 "Sequence number of an entry\n"
18296 "Sequence number\n"
7336e101
SP
18297 "Specify large community to reject\n"
18298 "Specify large community to accept\n"
18299 LCOMMUNITY_VAL_STR)
57d187bc 18300{
d62a17ae 18301 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18302 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
18303}
18304
7336e101
SP
18305DEFUN (no_lcommunity_list_name_expanded,
18306 no_bgp_lcommunity_list_name_expanded_cmd,
2f8cc0e5 18307 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18308 NO_STR
18309 BGP_STR
18310 LCOMMUNITY_LIST_STR
18311 "Specify expanded large-community-list\n"
18312 "Large community list name\n"
2f8cc0e5
DA
18313 "Sequence number of an entry\n"
18314 "Sequence number\n"
7336e101
SP
18315 "Specify large community to reject\n"
18316 "Specify large community to accept\n"
18317 "An ordered list as a regular-expression\n")
57d187bc 18318{
d62a17ae 18319 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 18320 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
18321}
18322
d62a17ae 18323static void lcommunity_list_show(struct vty *vty, struct community_list *list)
18324{
18325 struct community_entry *entry;
18326
18327 for (entry = list->head; entry; entry = entry->next) {
18328 if (entry == list->head) {
18329 if (all_digit(list->name))
18330 vty_out(vty, "Large community %s list %s\n",
169b72c8 18331 entry->style ==
18332 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18333 ? "standard"
18334 : "(expanded) access",
18335 list->name);
18336 else
18337 vty_out(vty,
18338 "Named large community %s list %s\n",
169b72c8 18339 entry->style ==
18340 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 18341 ? "standard"
18342 : "expanded",
18343 list->name);
18344 }
18345 if (entry->any)
18346 vty_out(vty, " %s\n",
18347 community_direct_str(entry->direct));
18348 else
18349 vty_out(vty, " %s %s\n",
18350 community_direct_str(entry->direct),
8d9b8ed9 18351 community_list_config_str(entry));
d62a17ae 18352 }
57d187bc
JS
18353}
18354
7336e101
SP
18355DEFUN (show_lcommunity_list,
18356 show_bgp_lcommunity_list_cmd,
18357 "show bgp large-community-list",
57d187bc 18358 SHOW_STR
7336e101 18359 BGP_STR
57d187bc
JS
18360 "List large-community list\n")
18361{
d62a17ae 18362 struct community_list *list;
18363 struct community_list_master *cm;
57d187bc 18364
d62a17ae 18365 cm = community_list_master_lookup(bgp_clist,
18366 LARGE_COMMUNITY_LIST_MASTER);
18367 if (!cm)
18368 return CMD_SUCCESS;
57d187bc 18369
d62a17ae 18370 for (list = cm->num.head; list; list = list->next)
18371 lcommunity_list_show(vty, list);
57d187bc 18372
d62a17ae 18373 for (list = cm->str.head; list; list = list->next)
18374 lcommunity_list_show(vty, list);
57d187bc 18375
d62a17ae 18376 return CMD_SUCCESS;
57d187bc
JS
18377}
18378
7336e101
SP
18379DEFUN (show_lcommunity_list_arg,
18380 show_bgp_lcommunity_list_arg_cmd,
960b69b9 18381 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
18382 SHOW_STR
18383 BGP_STR
57d187bc 18384 "List large-community list\n"
960b69b9 18385 "Large-community-list number\n"
18386 "Large-community-list name\n"
18387 "Detailed information on large-community-list\n")
57d187bc 18388{
d62a17ae 18389 struct community_list *list;
57d187bc 18390
e237b0d2 18391 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 18392 LARGE_COMMUNITY_LIST_MASTER);
18393 if (!list) {
960b69b9 18394 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 18395 return CMD_WARNING;
18396 }
57d187bc 18397
d62a17ae 18398 lcommunity_list_show(vty, list);
57d187bc 18399
d62a17ae 18400 return CMD_SUCCESS;
57d187bc
JS
18401}
18402
718e3744 18403/* "extcommunity-list" keyword help string. */
18404#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
18405#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
18406
7336e101
SP
18407DEFUN (extcommunity_list_standard,
18408 bgp_extcommunity_list_standard_cmd,
2f8cc0e5 18409 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101 18410 BGP_STR
718e3744 18411 EXTCOMMUNITY_LIST_STR
18412 "Extended Community list number (standard)\n"
718e3744 18413 "Specify standard extcommunity-list\n"
5bf15956 18414 "Community list name\n"
2f8cc0e5
DA
18415 "Sequence number of an entry\n"
18416 "Sequence number\n"
718e3744 18417 "Specify community to reject\n"
18418 "Specify community to accept\n"
18419 EXTCOMMUNITY_VAL_STR)
18420{
d62a17ae 18421 int style = EXTCOMMUNITY_LIST_STANDARD;
18422 int direct = 0;
18423 char *cl_number_or_name = NULL;
2f8cc0e5 18424 char *seq = NULL;
42f914d4 18425
d62a17ae 18426 int idx = 0;
7b9a4750 18427
d62a17ae 18428 argv_find(argv, argc, "(1-99)", &idx);
18429 argv_find(argv, argc, "WORD", &idx);
18430 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18431
409148f6 18432 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18433 seq = argv[idx]->arg;
18434
d62a17ae 18435 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18436 : COMMUNITY_DENY;
18437 argv_find(argv, argc, "AA:NN", &idx);
18438 char *str = argv_concat(argv, argc, idx);
42f914d4 18439
2f8cc0e5 18440 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18441 direct, style);
42f914d4 18442
d62a17ae 18443 XFREE(MTYPE_TMP, str);
42f914d4 18444
d62a17ae 18445 if (ret < 0) {
18446 community_list_perror(vty, ret);
18447 return CMD_WARNING_CONFIG_FAILED;
18448 }
42f914d4 18449
d62a17ae 18450 return CMD_SUCCESS;
718e3744 18451}
18452
7336e101
SP
18453DEFUN (extcommunity_list_name_expanded,
18454 bgp_extcommunity_list_name_expanded_cmd,
2f8cc0e5 18455 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18456 BGP_STR
18457 EXTCOMMUNITY_LIST_STR
5bf15956 18458 "Extended Community list number (expanded)\n"
718e3744 18459 "Specify expanded extcommunity-list\n"
18460 "Extended Community list name\n"
2f8cc0e5
DA
18461 "Sequence number of an entry\n"
18462 "Sequence number\n"
718e3744 18463 "Specify community to reject\n"
18464 "Specify community to accept\n"
18465 "An ordered list as a regular-expression\n")
18466{
d62a17ae 18467 int style = EXTCOMMUNITY_LIST_EXPANDED;
18468 int direct = 0;
18469 char *cl_number_or_name = NULL;
2f8cc0e5 18470 char *seq = NULL;
d62a17ae 18471 int idx = 0;
7336e101 18472
d62a17ae 18473 argv_find(argv, argc, "(100-500)", &idx);
18474 argv_find(argv, argc, "WORD", &idx);
18475 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 18476
409148f6 18477 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18478 seq = argv[idx]->arg;
18479
d62a17ae 18480 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
18481 : COMMUNITY_DENY;
18482 argv_find(argv, argc, "LINE", &idx);
18483 char *str = argv_concat(argv, argc, idx);
42f914d4 18484
2f8cc0e5 18485 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 18486 direct, style);
42f914d4 18487
d62a17ae 18488 XFREE(MTYPE_TMP, str);
42f914d4 18489
d62a17ae 18490 if (ret < 0) {
18491 community_list_perror(vty, ret);
18492 return CMD_WARNING_CONFIG_FAILED;
18493 }
42f914d4 18494
d62a17ae 18495 return CMD_SUCCESS;
718e3744 18496}
18497
7336e101
SP
18498DEFUN (no_extcommunity_list_standard_all,
18499 no_bgp_extcommunity_list_standard_all_cmd,
2f8cc0e5 18500 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
18501 NO_STR
18502 BGP_STR
18503 EXTCOMMUNITY_LIST_STR
813d4307 18504 "Extended Community list number (standard)\n"
718e3744 18505 "Specify standard extcommunity-list\n"
5bf15956 18506 "Community list name\n"
2f8cc0e5
DA
18507 "Sequence number of an entry\n"
18508 "Sequence number\n"
718e3744 18509 "Specify community to reject\n"
18510 "Specify community to accept\n"
18511 EXTCOMMUNITY_VAL_STR)
18512{
d62a17ae 18513 int style = EXTCOMMUNITY_LIST_STANDARD;
18514 int direct = 0;
18515 char *cl_number_or_name = NULL;
d4455c89 18516 char *str = NULL;
2f8cc0e5 18517 char *seq = NULL;
d62a17ae 18518 int idx = 0;
d4455c89 18519
409148f6 18520 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18521 seq = argv[idx]->arg;
18522
18523 idx = 0;
d4455c89
DA
18524 argv_find(argv, argc, "permit", &idx);
18525 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
18526 if (idx) {
18527 direct = argv_find(argv, argc, "permit", &idx)
18528 ? COMMUNITY_PERMIT
18529 : COMMUNITY_DENY;
18530
18531 idx = 0;
18532 argv_find(argv, argc, "AA:NN", &idx);
18533 str = argv_concat(argv, argc, idx);
18534 }
18535
18536 idx = 0;
d62a17ae 18537 argv_find(argv, argc, "(1-99)", &idx);
18538 argv_find(argv, argc, "WORD", &idx);
18539 cl_number_or_name = argv[idx]->arg;
42f914d4 18540
d62a17ae 18541 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18542 seq, direct, style);
42f914d4 18543
d62a17ae 18544 XFREE(MTYPE_TMP, str);
42f914d4 18545
d62a17ae 18546 if (ret < 0) {
18547 community_list_perror(vty, ret);
18548 return CMD_WARNING_CONFIG_FAILED;
18549 }
42f914d4 18550
d62a17ae 18551 return CMD_SUCCESS;
718e3744 18552}
18553
d4455c89
DA
18554ALIAS(no_extcommunity_list_standard_all,
18555 no_bgp_extcommunity_list_standard_all_list_cmd,
18556 "no bgp extcommunity-list <(1-99)|standard WORD>",
18557 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18558 "Extended Community list number (standard)\n"
18559 "Specify standard extcommunity-list\n"
18560 "Community list name\n")
18561
7336e101
SP
18562DEFUN (no_extcommunity_list_expanded_all,
18563 no_bgp_extcommunity_list_expanded_all_cmd,
2f8cc0e5 18564 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
7336e101
SP
18565 NO_STR
18566 BGP_STR
18567 EXTCOMMUNITY_LIST_STR
718e3744 18568 "Extended Community list number (expanded)\n"
718e3744 18569 "Specify expanded extcommunity-list\n"
5bf15956 18570 "Extended Community list name\n"
2f8cc0e5
DA
18571 "Sequence number of an entry\n"
18572 "Sequence number\n"
718e3744 18573 "Specify community to reject\n"
18574 "Specify community to accept\n"
18575 "An ordered list as a regular-expression\n")
18576{
d62a17ae 18577 int style = EXTCOMMUNITY_LIST_EXPANDED;
18578 int direct = 0;
18579 char *cl_number_or_name = NULL;
d4455c89 18580 char *str = NULL;
2f8cc0e5 18581 char *seq = NULL;
d62a17ae 18582 int idx = 0;
d4455c89 18583
409148f6 18584 if (argv_find(argv, argc, "(1-4294967295)", &idx))
2f8cc0e5
DA
18585 seq = argv[idx]->arg;
18586
18587 idx = 0;
d4455c89
DA
18588 argv_find(argv, argc, "permit", &idx);
18589 argv_find(argv, argc, "deny", &idx);
18590
18591 if (idx) {
18592 direct = argv_find(argv, argc, "permit", &idx)
18593 ? COMMUNITY_PERMIT
18594 : COMMUNITY_DENY;
18595
18596 idx = 0;
18597 argv_find(argv, argc, "LINE", &idx);
18598 str = argv_concat(argv, argc, idx);
18599 }
18600
18601 idx = 0;
d62a17ae 18602 argv_find(argv, argc, "(100-500)", &idx);
18603 argv_find(argv, argc, "WORD", &idx);
18604 cl_number_or_name = argv[idx]->arg;
42f914d4 18605
d62a17ae 18606 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 18607 seq, direct, style);
42f914d4 18608
d62a17ae 18609 XFREE(MTYPE_TMP, str);
42f914d4 18610
d62a17ae 18611 if (ret < 0) {
18612 community_list_perror(vty, ret);
18613 return CMD_WARNING_CONFIG_FAILED;
18614 }
42f914d4 18615
d62a17ae 18616 return CMD_SUCCESS;
718e3744 18617}
18618
d4455c89
DA
18619ALIAS(no_extcommunity_list_expanded_all,
18620 no_bgp_extcommunity_list_expanded_all_list_cmd,
18621 "no bgp extcommunity-list <(100-500)|expanded WORD>",
18622 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
18623 "Extended Community list number (expanded)\n"
18624 "Specify expanded extcommunity-list\n"
18625 "Extended Community list name\n")
18626
d62a17ae 18627static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 18628{
d62a17ae 18629 struct community_entry *entry;
718e3744 18630
d62a17ae 18631 for (entry = list->head; entry; entry = entry->next) {
18632 if (entry == list->head) {
18633 if (all_digit(list->name))
18634 vty_out(vty, "Extended community %s list %s\n",
18635 entry->style == EXTCOMMUNITY_LIST_STANDARD
18636 ? "standard"
18637 : "(expanded) access",
18638 list->name);
18639 else
18640 vty_out(vty,
18641 "Named extended community %s list %s\n",
18642 entry->style == EXTCOMMUNITY_LIST_STANDARD
18643 ? "standard"
18644 : "expanded",
18645 list->name);
18646 }
18647 if (entry->any)
18648 vty_out(vty, " %s\n",
18649 community_direct_str(entry->direct));
18650 else
18651 vty_out(vty, " %s %s\n",
18652 community_direct_str(entry->direct),
8d9b8ed9 18653 community_list_config_str(entry));
d62a17ae 18654 }
718e3744 18655}
18656
7336e101
SP
18657DEFUN (show_extcommunity_list,
18658 show_bgp_extcommunity_list_cmd,
18659 "show bgp extcommunity-list",
718e3744 18660 SHOW_STR
7336e101 18661 BGP_STR
718e3744 18662 "List extended-community list\n")
18663{
d62a17ae 18664 struct community_list *list;
18665 struct community_list_master *cm;
718e3744 18666
d62a17ae 18667 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18668 if (!cm)
18669 return CMD_SUCCESS;
718e3744 18670
d62a17ae 18671 for (list = cm->num.head; list; list = list->next)
18672 extcommunity_list_show(vty, list);
718e3744 18673
d62a17ae 18674 for (list = cm->str.head; list; list = list->next)
18675 extcommunity_list_show(vty, list);
718e3744 18676
d62a17ae 18677 return CMD_SUCCESS;
718e3744 18678}
18679
7336e101
SP
18680DEFUN (show_extcommunity_list_arg,
18681 show_bgp_extcommunity_list_arg_cmd,
960b69b9 18682 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
18683 SHOW_STR
18684 BGP_STR
718e3744 18685 "List extended-community list\n"
18686 "Extcommunity-list number\n"
960b69b9 18687 "Extcommunity-list name\n"
18688 "Detailed information on extcommunity-list\n")
718e3744 18689{
d62a17ae 18690 int idx_comm_list = 3;
18691 struct community_list *list;
718e3744 18692
e237b0d2 18693 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 18694 EXTCOMMUNITY_LIST_MASTER);
18695 if (!list) {
18696 vty_out(vty, "%% Can't find extcommunity-list\n");
18697 return CMD_WARNING;
18698 }
718e3744 18699
d62a17ae 18700 extcommunity_list_show(vty, list);
718e3744 18701
d62a17ae 18702 return CMD_SUCCESS;
718e3744 18703}
6b0655a2 18704
718e3744 18705/* Display community-list and extcommunity-list configuration. */
d62a17ae 18706static int community_list_config_write(struct vty *vty)
18707{
18708 struct community_list *list;
18709 struct community_entry *entry;
18710 struct community_list_master *cm;
18711 int write = 0;
18712
18713 /* Community-list. */
18714 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
18715
18716 for (list = cm->num.head; list; list = list->next)
18717 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18718 vty_out(vty,
18719 "bgp community-list %s seq %" PRId64 " %s %s\n",
18720 list->name, entry->seq,
d62a17ae 18721 community_direct_str(entry->direct),
18722 community_list_config_str(entry));
18723 write++;
18724 }
18725 for (list = cm->str.head; list; list = list->next)
18726 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18727 vty_out(vty,
18728 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 18729 entry->style == COMMUNITY_LIST_STANDARD
18730 ? "standard"
18731 : "expanded",
2f8cc0e5
DA
18732 list->name, entry->seq,
18733 community_direct_str(entry->direct),
d62a17ae 18734 community_list_config_str(entry));
18735 write++;
18736 }
18737
18738 /* Extcommunity-list. */
18739 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
18740
18741 for (list = cm->num.head; list; list = list->next)
18742 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
18743 vty_out(vty,
18744 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
18745 list->name, entry->seq,
18746 community_direct_str(entry->direct),
d62a17ae 18747 community_list_config_str(entry));
18748 write++;
18749 }
18750 for (list = cm->str.head; list; list = list->next)
18751 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18752 vty_out(vty,
6cde4b45 18753 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 18754 entry->style == EXTCOMMUNITY_LIST_STANDARD
18755 ? "standard"
18756 : "expanded",
2f8cc0e5
DA
18757 list->name, entry->seq,
18758 community_direct_str(entry->direct),
d62a17ae 18759 community_list_config_str(entry));
18760 write++;
18761 }
18762
18763
18764 /* lcommunity-list. */
18765 cm = community_list_master_lookup(bgp_clist,
18766 LARGE_COMMUNITY_LIST_MASTER);
18767
18768 for (list = cm->num.head; list; list = list->next)
18769 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18770 vty_out(vty,
6cde4b45 18771 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
18772 list->name, entry->seq,
18773 community_direct_str(entry->direct),
d62a17ae 18774 community_list_config_str(entry));
18775 write++;
18776 }
18777 for (list = cm->str.head; list; list = list->next)
18778 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 18779 vty_out(vty,
6cde4b45 18780 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 18781
d62a17ae 18782 entry->style == LARGE_COMMUNITY_LIST_STANDARD
18783 ? "standard"
18784 : "expanded",
2f8cc0e5 18785 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 18786 community_list_config_str(entry));
18787 write++;
18788 }
18789
18790 return write;
18791}
18792
612c2c15 18793static int community_list_config_write(struct vty *vty);
d62a17ae 18794static struct cmd_node community_list_node = {
f4b8291f 18795 .name = "community list",
62b346ee
DL
18796 .node = COMMUNITY_LIST_NODE,
18797 .prompt = "",
612c2c15 18798 .config_write = community_list_config_write,
718e3744 18799};
18800
d62a17ae 18801static void community_list_vty(void)
18802{
612c2c15 18803 install_node(&community_list_node);
d62a17ae 18804
18805 /* Community-list. */
7336e101
SP
18806 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
18807 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
18808 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 18809 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 18810 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 18811 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
18812 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
18813 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 18814
18815 /* Extcommunity-list. */
7336e101
SP
18816 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
18817 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
18818 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
18819 install_element(CONFIG_NODE,
18820 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 18821 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
18822 install_element(CONFIG_NODE,
18823 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
18824 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
18825 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 18826
18827 /* Large Community List */
7336e101 18828 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
18829 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
18830 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 18831 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
18832 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
18833 install_element(CONFIG_NODE,
18834 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
18835 install_element(CONFIG_NODE,
18836 &no_bgp_lcommunity_list_name_expanded_all_cmd);
18837 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
18838 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
18839 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
18840 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
18841 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
18842 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 18843}